Rename the 'obfd' argument to fbsd_nat_target::find_memory_regions.
[deliverable/binutils-gdb.git] / gdb / doc / gdb.texinfo
CommitLineData
c906108c 1\input texinfo @c -*-texinfo-*-
b811d2c2 2@c Copyright (C) 1988--2020 Free Software Foundation, Inc.
c906108c 3@c
5d161b24 4@c %**start of header
c906108c
SS
5@c makeinfo ignores cmds prev to setfilename, so its arg cannot make use
6@c of @set vars. However, you can override filename with makeinfo -o.
7@setfilename gdb.info
8@c
43662968 9@c man begin INCLUDE
c906108c 10@include gdb-cfg.texi
43662968 11@c man end
c906108c 12@c
c906108c 13@settitle Debugging with @value{GDBN}
c906108c
SS
14@setchapternewpage odd
15@c %**end of header
16
17@iftex
18@c @smallbook
19@c @cropmarks
20@end iftex
21
22@finalout
00595b5e
EZ
23@c To avoid file-name clashes between index.html and Index.html, when
24@c the manual is produced on a Posix host and then moved to a
25@c case-insensitive filesystem (e.g., MS-Windows), we separate the
26@c indices into two: Concept Index and all the rest.
27@syncodeindex ky fn
28@syncodeindex tp fn
c906108c 29
41afff9a 30@c readline appendices use @vindex, @findex and @ftable,
48e934c6 31@c annotate.texi and gdbmi use @findex.
00595b5e 32@syncodeindex vr fn
c906108c
SS
33
34@c !!set GDB manual's edition---not the same as GDB version!
9fe8321b 35@c This is updated by GNU Press.
26829f2b 36@set EDITION Tenth
c906108c 37
87885426
FN
38@c !!set GDB edit command default editor
39@set EDITOR /bin/ex
c906108c 40
6c0e9fb3 41@c THIS MANUAL REQUIRES TEXINFO 4.0 OR LATER.
c906108c 42
c906108c 43@c This is a dir.info fragment to support semi-automated addition of
6d2ebf8b 44@c manuals to an info tree.
03727ca6 45@dircategory Software development
96a2c332 46@direntry
03727ca6 47* Gdb: (gdb). The GNU debugger.
6cb999f8 48* gdbserver: (gdb) Server. The GNU debugging server.
96a2c332
SS
49@end direntry
50
a67ec3f4 51@copying
43662968 52@c man begin COPYRIGHT
e5d78223 53Copyright @copyright{} 1988-2020 Free Software Foundation, Inc.
c906108c 54
e9c75b65 55Permission is granted to copy, distribute and/or modify this document
4f5d9f07 56under the terms of the GNU Free Documentation License, Version 1.3 or
e9c75b65 57any later version published by the Free Software Foundation; with the
959acfd1
EZ
58Invariant Sections being ``Free Software'' and ``Free Software Needs
59Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
60and with the Back-Cover Texts as in (a) below.
c906108c 61
b8533aec
DJ
62(a) The FSF's Back-Cover Text is: ``You are free to copy and modify
63this GNU Manual. Buying copies from GNU Press supports the FSF in
64developing GNU and promoting software freedom.''
43662968 65@c man end
a67ec3f4
JM
66@end copying
67
68@ifnottex
69This file documents the @sc{gnu} debugger @value{GDBN}.
70
71This is the @value{EDITION} Edition, of @cite{Debugging with
72@value{GDBN}: the @sc{gnu} Source-Level Debugger} for @value{GDBN}
73@ifset VERSION_PACKAGE
74@value{VERSION_PACKAGE}
75@end ifset
76Version @value{GDBVN}.
77
78@insertcopying
79@end ifnottex
c906108c
SS
80
81@titlepage
82@title Debugging with @value{GDBN}
83@subtitle The @sc{gnu} Source-Level Debugger
c906108c 84@sp 1
c906108c 85@subtitle @value{EDITION} Edition, for @value{GDBN} version @value{GDBVN}
c16158bc
JM
86@ifset VERSION_PACKAGE
87@sp 1
88@subtitle @value{VERSION_PACKAGE}
89@end ifset
9e9c5ae7 90@author Richard Stallman, Roland Pesch, Stan Shebs, et al.
c906108c 91@page
c906108c
SS
92@tex
93{\parskip=0pt
c16158bc 94\hfill (Send bugs and comments on @value{GDBN} to @value{BUGURL}.)\par
c906108c
SS
95\hfill {\it Debugging with @value{GDBN}}\par
96\hfill \TeX{}info \texinfoversion\par
97}
98@end tex
53a5351d 99
c906108c 100@vskip 0pt plus 1filll
c906108c 101Published by the Free Software Foundation @*
c02a867d
EZ
10251 Franklin Street, Fifth Floor,
103Boston, MA 02110-1301, USA@*
26829f2b 104ISBN 978-0-9831592-3-0 @*
e9c75b65 105
a67ec3f4 106@insertcopying
c906108c
SS
107@end titlepage
108@page
109
6c0e9fb3 110@ifnottex
c5a6a07f 111@node Top, Summary
6d2ebf8b 112
c906108c
SS
113@top Debugging with @value{GDBN}
114
115This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
116
c16158bc
JM
117This is the @value{EDITION} Edition, for @value{GDBN}
118@ifset VERSION_PACKAGE
119@value{VERSION_PACKAGE}
120@end ifset
121Version @value{GDBVN}.
c906108c 122
e5d78223 123Copyright (C) 1988-2020 Free Software Foundation, Inc.
6d2ebf8b 124
3fb6a982
JB
125This edition of the GDB manual is dedicated to the memory of Fred
126Fish. Fred was a long-standing contributor to GDB and to Free
127software in general. We will miss him.
128
6d2ebf8b
SS
129@menu
130* Summary:: Summary of @value{GDBN}
131* Sample Session:: A sample @value{GDBN} session
132
133* Invocation:: Getting in and out of @value{GDBN}
134* Commands:: @value{GDBN} commands
135* Running:: Running programs under @value{GDBN}
136* Stopping:: Stopping and continuing
bacec72f 137* Reverse Execution:: Running programs backward
a2311334 138* Process Record and Replay:: Recording inferior's execution and replaying it
6d2ebf8b
SS
139* Stack:: Examining the stack
140* Source:: Examining source files
141* Data:: Examining data
edb3359d 142* Optimized Code:: Debugging optimized code
e2e0bcd1 143* Macros:: Preprocessor Macros
b37052ae 144* Tracepoints:: Debugging remote targets non-intrusively
df0cd8c5 145* Overlays:: Debugging programs that use overlays
6d2ebf8b
SS
146
147* Languages:: Using @value{GDBN} with different languages
148
149* Symbols:: Examining the symbol table
150* Altering:: Altering execution
151* GDB Files:: @value{GDBN} files
152* Targets:: Specifying a debugging target
6b2f586d 153* Remote Debugging:: Debugging remote programs
6d2ebf8b
SS
154* Configurations:: Configuration-specific information
155* Controlling GDB:: Controlling @value{GDBN}
d57a3c85 156* Extending GDB:: Extending @value{GDBN}
21c294e6 157* Interpreters:: Command Interpreters
c8f4133a 158* TUI:: @value{GDBN} Text User Interface
6d2ebf8b 159* Emacs:: Using @value{GDBN} under @sc{gnu} Emacs
7162c0ca 160* GDB/MI:: @value{GDBN}'s Machine Interface.
c8f4133a 161* Annotations:: @value{GDBN}'s annotation interface.
4efc6507 162* JIT Interface:: Using the JIT debugging interface.
d1feda86 163* In-Process Agent:: In-Process Agent
6d2ebf8b
SS
164
165* GDB Bugs:: Reporting bugs in @value{GDBN}
6d2ebf8b 166
39037522
TT
167@ifset SYSTEM_READLINE
168* Command Line Editing: (rluserman). Command Line Editing
169* Using History Interactively: (history). Using History Interactively
170@end ifset
171@ifclear SYSTEM_READLINE
6d2ebf8b
SS
172* Command Line Editing:: Command Line Editing
173* Using History Interactively:: Using History Interactively
39037522 174@end ifclear
4ceed123 175* In Memoriam:: In Memoriam
0869d01b 176* Formatting Documentation:: How to format and print @value{GDBN} documentation
6d2ebf8b 177* Installing GDB:: Installing GDB
eb12ee30 178* Maintenance Commands:: Maintenance Commands
e0ce93ac 179* Remote Protocol:: GDB Remote Serial Protocol
f418dd93 180* Agent Expressions:: The GDB Agent Expression Mechanism
23181151
DJ
181* Target Descriptions:: How targets can describe themselves to
182 @value{GDBN}
07e059b5
VP
183* Operating System Information:: Getting additional information from
184 the operating system
00bf0b85 185* Trace File Format:: GDB trace file format
90476074 186* Index Section Format:: .gdb_index section format
43662968 187* Man Pages:: Manual pages
aab4e0ec
AC
188* Copying:: GNU General Public License says
189 how you can copy and share GDB
6826cf00 190* GNU Free Documentation License:: The license for this documentation
00595b5e
EZ
191* Concept Index:: Index of @value{GDBN} concepts
192* Command and Variable Index:: Index of @value{GDBN} commands, variables,
193 functions, and Python data types
6d2ebf8b
SS
194@end menu
195
6c0e9fb3 196@end ifnottex
c906108c 197
449f3b6c 198@contents
449f3b6c 199
6d2ebf8b 200@node Summary
c906108c
SS
201@unnumbered Summary of @value{GDBN}
202
203The purpose of a debugger such as @value{GDBN} is to allow you to see what is
204going on ``inside'' another program while it executes---or what another
205program was doing at the moment it crashed.
206
207@value{GDBN} can do four main kinds of things (plus other things in support of
208these) to help you catch bugs in the act:
209
210@itemize @bullet
211@item
212Start your program, specifying anything that might affect its behavior.
213
214@item
215Make your program stop on specified conditions.
216
217@item
218Examine what has happened, when your program has stopped.
219
220@item
221Change things in your program, so you can experiment with correcting the
222effects of one bug and go on to learn about another.
223@end itemize
224
49efadf5 225You can use @value{GDBN} to debug programs written in C and C@t{++}.
79a6e687 226For more information, see @ref{Supported Languages,,Supported Languages}.
c906108c
SS
227For more information, see @ref{C,,C and C++}.
228
6aecb9c2
JB
229Support for D is partial. For information on D, see
230@ref{D,,D}.
231
cce74817 232@cindex Modula-2
e632838e
AC
233Support for Modula-2 is partial. For information on Modula-2, see
234@ref{Modula-2,,Modula-2}.
c906108c 235
f4b8a18d
KW
236Support for OpenCL C is partial. For information on OpenCL C, see
237@ref{OpenCL C,,OpenCL C}.
238
cce74817
JM
239@cindex Pascal
240Debugging Pascal programs which use sets, subranges, file variables, or
241nested functions does not currently work. @value{GDBN} does not support
242entering expressions, printing values, or similar features using Pascal
243syntax.
c906108c 244
c906108c
SS
245@cindex Fortran
246@value{GDBN} can be used to debug programs written in Fortran, although
53a5351d 247it may be necessary to refer to some variables with a trailing
cce74817 248underscore.
c906108c 249
b37303ee
AF
250@value{GDBN} can be used to debug programs written in Objective-C,
251using either the Apple/NeXT or the GNU Objective-C runtime.
252
c906108c
SS
253@menu
254* Free Software:: Freely redistributable software
984359d2 255* Free Documentation:: Free Software Needs Free Documentation
c906108c
SS
256* Contributors:: Contributors to GDB
257@end menu
258
6d2ebf8b 259@node Free Software
79a6e687 260@unnumberedsec Free Software
c906108c 261
5d161b24 262@value{GDBN} is @dfn{free software}, protected by the @sc{gnu}
c906108c
SS
263General Public License
264(GPL). The GPL gives you the freedom to copy or adapt a licensed
265program---but every person getting a copy also gets with it the
266freedom to modify that copy (which means that they must get access to
267the source code), and the freedom to distribute further copies.
268Typical software companies use copyrights to limit your freedoms; the
269Free Software Foundation uses the GPL to preserve these freedoms.
270
271Fundamentally, the General Public License is a license which says that
272you have these freedoms and that you cannot take these freedoms away
273from anyone else.
274
984359d2 275@node Free Documentation
2666264b 276@unnumberedsec Free Software Needs Free Documentation
959acfd1
EZ
277
278The biggest deficiency in the free software community today is not in
279the software---it is the lack of good free documentation that we can
280include with the free software. Many of our most important
281programs do not come with free reference manuals and free introductory
282texts. Documentation is an essential part of any software package;
283when an important free software package does not come with a free
284manual and a free tutorial, that is a major gap. We have many such
285gaps today.
286
287Consider Perl, for instance. The tutorial manuals that people
288normally use are non-free. How did this come about? Because the
289authors of those manuals published them with restrictive terms---no
290copying, no modification, source files not available---which exclude
291them from the free software world.
292
293That wasn't the first time this sort of thing happened, and it was far
294from the last. Many times we have heard a GNU user eagerly describe a
295manual that he is writing, his intended contribution to the community,
296only to learn that he had ruined everything by signing a publication
297contract to make it non-free.
298
299Free documentation, like free software, is a matter of freedom, not
300price. The problem with the non-free manual is not that publishers
301charge a price for printed copies---that in itself is fine. (The Free
302Software Foundation sells printed copies of manuals, too.) The
303problem is the restrictions on the use of the manual. Free manuals
304are available in source code form, and give you permission to copy and
305modify. Non-free manuals do not allow this.
306
307The criteria of freedom for a free manual are roughly the same as for
308free software. Redistribution (including the normal kinds of
309commercial redistribution) must be permitted, so that the manual can
310accompany every copy of the program, both on-line and on paper.
311
312Permission for modification of the technical content is crucial too.
313When people modify the software, adding or changing features, if they
314are conscientious they will change the manual too---so they can
315provide accurate and clear documentation for the modified program. A
316manual that leaves you no choice but to write a new manual to document
317a changed version of the program is not really available to our
318community.
319
320Some kinds of limits on the way modification is handled are
321acceptable. For example, requirements to preserve the original
322author's copyright notice, the distribution terms, or the list of
323authors, are ok. It is also no problem to require modified versions
324to include notice that they were modified. Even entire sections that
325may not be deleted or changed are acceptable, as long as they deal
326with nontechnical topics (like this one). These kinds of restrictions
327are acceptable because they don't obstruct the community's normal use
328of the manual.
329
330However, it must be possible to modify all the @emph{technical}
331content of the manual, and then distribute the result in all the usual
332media, through all the usual channels. Otherwise, the restrictions
333obstruct the use of the manual, it is not free, and we need another
334manual to replace it.
335
336Please spread the word about this issue. Our community continues to
337lose manuals to proprietary publishing. If we spread the word that
338free software needs free reference manuals and free tutorials, perhaps
339the next person who wants to contribute by writing documentation will
340realize, before it is too late, that only free manuals contribute to
341the free software community.
342
343If you are writing documentation, please insist on publishing it under
344the GNU Free Documentation License or another free documentation
345license. Remember that this decision requires your approval---you
346don't have to let the publisher decide. Some commercial publishers
347will use a free license if you insist, but they will not propose the
348option; it is up to you to raise the issue and say firmly that this is
349what you want. If the publisher you are dealing with refuses, please
350try other publishers. If you're not sure whether a proposed license
42584a72 351is free, write to @email{licensing@@gnu.org}.
959acfd1
EZ
352
353You can encourage commercial publishers to sell more free, copylefted
354manuals and tutorials by buying them, and particularly by buying
355copies from the publishers that paid for their writing or for major
356improvements. Meanwhile, try to avoid buying non-free documentation
357at all. Check the distribution terms of a manual before you buy it,
358and insist that whoever seeks your business must respect your freedom.
72c9928d
EZ
359Check the history of the book, and try to reward the publishers that
360have paid or pay the authors to work on it.
959acfd1
EZ
361
362The Free Software Foundation maintains a list of free documentation
363published by other publishers, at
364@url{http://www.fsf.org/doc/other-free-books.html}.
365
6d2ebf8b 366@node Contributors
96a2c332
SS
367@unnumberedsec Contributors to @value{GDBN}
368
369Richard Stallman was the original author of @value{GDBN}, and of many
370other @sc{gnu} programs. Many others have contributed to its
371development. This section attempts to credit major contributors. One
372of the virtues of free software is that everyone is free to contribute
373to it; with regret, we cannot actually acknowledge everyone here. The
374file @file{ChangeLog} in the @value{GDBN} distribution approximates a
c906108c
SS
375blow-by-blow account.
376
377Changes much prior to version 2.0 are lost in the mists of time.
378
379@quotation
380@emph{Plea:} Additions to this section are particularly welcome. If you
381or your friends (or enemies, to be evenhanded) have been unfairly
382omitted from this list, we would like to add your names!
383@end quotation
384
385So that they may not regard their many labors as thankless, we
386particularly thank those who shepherded @value{GDBN} through major
387releases:
7ba3cf9c 388Andrew Cagney (releases 6.3, 6.2, 6.1, 6.0, 5.3, 5.2, 5.1 and 5.0);
c906108c
SS
389Jim Blandy (release 4.18);
390Jason Molenda (release 4.17);
391Stan Shebs (release 4.14);
392Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9);
393Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4);
394John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9);
395Jim Kingdon (releases 3.5, 3.4, and 3.3);
396and Randy Smith (releases 3.2, 3.1, and 3.0).
397
398Richard Stallman, assisted at various times by Peter TerMaat, Chris
399Hanson, and Richard Mlynarik, handled releases through 2.8.
400
b37052ae
EZ
401Michael Tiemann is the author of most of the @sc{gnu} C@t{++} support
402in @value{GDBN}, with significant additional contributions from Per
403Bothner and Daniel Berlin. James Clark wrote the @sc{gnu} C@t{++}
404demangler. Early work on C@t{++} was by Peter TerMaat (who also did
405much general update work leading to release 3.0).
c906108c 406
b37052ae 407@value{GDBN} uses the BFD subroutine library to examine multiple
c906108c
SS
408object-file formats; BFD was a joint project of David V.
409Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
410
411David Johnson wrote the original COFF support; Pace Willison did
412the original support for encapsulated COFF.
413
0179ffac 414Brent Benson of Harris Computer Systems contributed DWARF 2 support.
c906108c
SS
415
416Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
417Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
418support.
419Jean-Daniel Fekete contributed Sun 386i support.
420Chris Hanson improved the HP9000 support.
421Noboyuki Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support.
422David Johnson contributed Encore Umax support.
423Jyrki Kuoppala contributed Altos 3068 support.
424Jeff Law contributed HP PA and SOM support.
425Keith Packard contributed NS32K support.
426Doug Rabson contributed Acorn Risc Machine support.
427Bob Rusk contributed Harris Nighthawk CX-UX support.
428Chris Smith contributed Convex support (and Fortran debugging).
429Jonathan Stone contributed Pyramid support.
430Michael Tiemann contributed SPARC support.
431Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
432Pace Willison contributed Intel 386 support.
433Jay Vosburgh contributed Symmetry support.
a37295f9 434Marko Mlinar contributed OpenRISC 1000 support.
c906108c 435
1104b9e7 436Andreas Schwab contributed M68K @sc{gnu}/Linux support.
c906108c
SS
437
438Rich Schaefer and Peter Schauer helped with support of SunOS shared
439libraries.
440
441Jay Fenlason and Roland McGrath ensured that @value{GDBN} and GAS agree
442about several machine instruction sets.
443
444Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop
445remote debugging. Intel Corporation, Wind River Systems, AMD, and ARM
446contributed remote debugging modules for the i960, VxWorks, A29K UDI,
447and RDI targets, respectively.
448
449Brian Fox is the author of the readline libraries providing
450command-line editing and command history.
451
7a292a7a
SS
452Andrew Beers of SUNY Buffalo wrote the language-switching code, the
453Modula-2 support, and contributed the Languages chapter of this manual.
c906108c 454
5d161b24 455Fred Fish wrote most of the support for Unix System Vr4.
b37052ae 456He also enhanced the command-completion support to cover C@t{++} overloaded
c906108c 457symbols.
c906108c 458
f24c5e49
KI
459Hitachi America (now Renesas America), Ltd. sponsored the support for
460H8/300, H8/500, and Super-H processors.
c906108c
SS
461
462NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
463
f24c5e49
KI
464Mitsubishi (now Renesas) sponsored the support for D10V, D30V, and M32R/D
465processors.
c906108c
SS
466
467Toshiba sponsored the support for the TX39 Mips processor.
468
469Matsushita sponsored the support for the MN10200 and MN10300 processors.
470
96a2c332 471Fujitsu sponsored the support for SPARClite and FR30 processors.
c906108c
SS
472
473Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
474watchpoints.
475
476Michael Snyder added support for tracepoints.
477
478Stu Grossman wrote gdbserver.
479
480Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made
96a2c332 481nearly innumerable bug fixes and cleanups throughout @value{GDBN}.
c906108c
SS
482
483The following people at the Hewlett-Packard Company contributed
484support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
b37052ae 485(narrow mode), HP's implementation of kernel threads, HP's aC@t{++}
d0d5df6f
AC
486compiler, and the Text User Interface (nee Terminal User Interface):
487Ben Krepp, Richard Title, John Bishop, Susan Macchia, Kathy Mann,
488Satish Pai, India Paul, Steve Rehrauer, and Elena Zannoni. Kim Haase
489provided HP-specific information in this manual.
c906108c 490
b37052ae
EZ
491DJ Delorie ported @value{GDBN} to MS-DOS, for the DJGPP project.
492Robert Hoehne made significant contributions to the DJGPP port.
493
96a2c332
SS
494Cygnus Solutions has sponsored @value{GDBN} maintenance and much of its
495development since 1991. Cygnus engineers who have worked on @value{GDBN}
2df3850c
JM
496fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
497Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
498Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
499Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
500Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni. In
501addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
502JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
503Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
504Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
505Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
506Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
507Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
508Zuhn have made contributions both large and small.
c906108c 509
ffed4509
AC
510Andrew Cagney, Fernando Nasser, and Elena Zannoni, while working for
511Cygnus Solutions, implemented the original @sc{gdb/mi} interface.
512
e2e0bcd1
JB
513Jim Blandy added support for preprocessor macros, while working for Red
514Hat.
c906108c 515
a9967aef
AC
516Andrew Cagney designed @value{GDBN}'s architecture vector. Many
517people including Andrew Cagney, Stephane Carrez, Randolph Chung, Nick
518Duffek, Richard Henderson, Mark Kettenis, Grace Sainsbury, Kei
519Sakamoto, Yoshinori Sato, Michael Snyder, Andreas Schwab, Jason
520Thorpe, Corinna Vinschen, Ulrich Weigand, and Elena Zannoni, helped
521with the migration of old architectures to this new framework.
522
c5e30d01
AC
523Andrew Cagney completely re-designed and re-implemented @value{GDBN}'s
524unwinder framework, this consisting of a fresh new design featuring
525frame IDs, independent frame sniffers, and the sentinel frame. Mark
526Kettenis implemented the @sc{dwarf 2} unwinder, Jeff Johnston the
527libunwind unwinder, and Andrew Cagney the dummy, sentinel, tramp, and
db2e3e2e 528trad unwinders. The architecture-specific changes, each involving a
c5e30d01
AC
529complete rewrite of the architecture's frame code, were carried out by
530Jim Blandy, Joel Brobecker, Kevin Buettner, Andrew Cagney, Stephane
531Carrez, Randolph Chung, Orjan Friberg, Richard Henderson, Daniel
532Jacobowitz, Jeff Johnston, Mark Kettenis, Theodore A. Roth, Kei
533Sakamoto, Yoshinori Sato, Michael Snyder, Corinna Vinschen, and Ulrich
534Weigand.
535
ca3bf3bd
DJ
536Christian Zankel, Ross Morley, Bob Wilson, and Maxim Grigoriev from
537Tensilica, Inc.@: contributed support for Xtensa processors. Others
538who have worked on the Xtensa port of @value{GDBN} in the past include
539Steve Tjiang, John Newlin, and Scott Foehner.
540
08be9d71
ME
541Michael Eager and staff of Xilinx, Inc., contributed support for the
542Xilinx MicroBlaze architecture.
543
387360da
JB
544Initial support for the FreeBSD/mips target and native configuration
545was developed by SRI International and the University of Cambridge
546Computer Laboratory under DARPA/AFRL contract FA8750-10-C-0237
547("CTSRD"), as part of the DARPA CRASH research programme.
548
74792ff7
JB
549Initial support for the FreeBSD/riscv target and native configuration
550was developed by SRI International and the University of Cambridge
551Computer Laboratory (Department of Computer Science and Technology)
552under DARPA contract HR0011-18-C-0016 ("ECATS"), as part of the DARPA
553SSITH research programme.
554
a994fec4
FJ
555The original port to the OpenRISC 1000 is believed to be due to
556Alessandro Forin and Per Bothner. More recent ports have been the work
557of Jeremy Bennett, Franck Jullien, Stefan Wallentowitz and
558Stafford Horne.
559
6d2ebf8b 560@node Sample Session
c906108c
SS
561@chapter A Sample @value{GDBN} Session
562
563You can use this manual at your leisure to read all about @value{GDBN}.
564However, a handful of commands are enough to get started using the
565debugger. This chapter illustrates those commands.
566
567@iftex
568In this sample session, we emphasize user input like this: @b{input},
569to make it easier to pick out from the surrounding output.
570@end iftex
571
572@c FIXME: this example may not be appropriate for some configs, where
573@c FIXME...primary interest is in remote use.
574
575One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
576processor) exhibits the following bug: sometimes, when we change its
577quote strings from the default, the commands used to capture one macro
578definition within another stop working. In the following short @code{m4}
579session, we define a macro @code{foo} which expands to @code{0000}; we
580then use the @code{m4} built-in @code{defn} to define @code{bar} as the
581same thing. However, when we change the open quote string to
582@code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
583procedure fails to define a new synonym @code{baz}:
584
585@smallexample
586$ @b{cd gnu/m4}
587$ @b{./m4}
588@b{define(foo,0000)}
589
590@b{foo}
5910000
592@b{define(bar,defn(`foo'))}
593
594@b{bar}
5950000
596@b{changequote(<QUOTE>,<UNQUOTE>)}
597
598@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
599@b{baz}
c8aa23ab 600@b{Ctrl-d}
c906108c
SS
601m4: End of input: 0: fatal error: EOF in string
602@end smallexample
603
604@noindent
605Let us use @value{GDBN} to try to see what is going on.
606
c906108c
SS
607@smallexample
608$ @b{@value{GDBP} m4}
609@c FIXME: this falsifies the exact text played out, to permit smallbook
610@c FIXME... format to come out better.
611@value{GDBN} is free software and you are welcome to distribute copies
5d161b24 612 of it under certain conditions; type "show copying" to see
c906108c 613 the conditions.
5d161b24 614There is absolutely no warranty for @value{GDBN}; type "show warranty"
c906108c
SS
615 for details.
616
617@value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
618(@value{GDBP})
619@end smallexample
c906108c
SS
620
621@noindent
622@value{GDBN} reads only enough symbol data to know where to find the
623rest when needed; as a result, the first prompt comes up very quickly.
624We now tell @value{GDBN} to use a narrower display width than usual, so
625that examples fit in this manual.
626
627@smallexample
628(@value{GDBP}) @b{set width 70}
629@end smallexample
630
631@noindent
632We need to see how the @code{m4} built-in @code{changequote} works.
633Having looked at the source, we know the relevant subroutine is
634@code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
635@code{break} command.
636
637@smallexample
638(@value{GDBP}) @b{break m4_changequote}
639Breakpoint 1 at 0x62f4: file builtin.c, line 879.
640@end smallexample
641
642@noindent
643Using the @code{run} command, we start @code{m4} running under @value{GDBN}
644control; as long as control does not reach the @code{m4_changequote}
645subroutine, the program runs as usual:
646
647@smallexample
648(@value{GDBP}) @b{run}
649Starting program: /work/Editorial/gdb/gnu/m4/m4
650@b{define(foo,0000)}
651
652@b{foo}
6530000
654@end smallexample
655
656@noindent
657To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
658suspends execution of @code{m4}, displaying information about the
659context where it stops.
660
661@smallexample
662@b{changequote(<QUOTE>,<UNQUOTE>)}
663
5d161b24 664Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
665 at builtin.c:879
666879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
667@end smallexample
668
669@noindent
670Now we use the command @code{n} (@code{next}) to advance execution to
671the next line of the current function.
672
673@smallexample
674(@value{GDBP}) @b{n}
675882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
676 : nil,
677@end smallexample
678
679@noindent
680@code{set_quotes} looks like a promising subroutine. We can go into it
681by using the command @code{s} (@code{step}) instead of @code{next}.
682@code{step} goes to the next line to be executed in @emph{any}
683subroutine, so it steps into @code{set_quotes}.
684
685@smallexample
686(@value{GDBP}) @b{s}
687set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
688 at input.c:530
689530 if (lquote != def_lquote)
690@end smallexample
691
692@noindent
693The display that shows the subroutine where @code{m4} is now
694suspended (and its arguments) is called a stack frame display. It
695shows a summary of the stack. We can use the @code{backtrace}
696command (which can also be spelled @code{bt}), to see where we are
697in the stack as a whole: the @code{backtrace} command displays a
698stack frame for each active subroutine.
699
700@smallexample
701(@value{GDBP}) @b{bt}
702#0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
703 at input.c:530
5d161b24 704#1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
705 at builtin.c:882
706#2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
707#3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
708 at macro.c:71
709#4 0x79dc in expand_input () at macro.c:40
710#5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
711@end smallexample
712
713@noindent
714We step through a few more lines to see what happens. The first two
715times, we can use @samp{s}; the next two times we use @code{n} to avoid
716falling into the @code{xstrdup} subroutine.
717
718@smallexample
719(@value{GDBP}) @b{s}
7200x3b5c 532 if (rquote != def_rquote)
721(@value{GDBP}) @b{s}
7220x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
723def_lquote : xstrdup(lq);
724(@value{GDBP}) @b{n}
725536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
726 : xstrdup(rq);
727(@value{GDBP}) @b{n}
728538 len_lquote = strlen(rquote);
729@end smallexample
730
731@noindent
732The last line displayed looks a little odd; we can examine the variables
733@code{lquote} and @code{rquote} to see if they are in fact the new left
734and right quotes we specified. We use the command @code{p}
735(@code{print}) to see their values.
736
737@smallexample
738(@value{GDBP}) @b{p lquote}
739$1 = 0x35d40 "<QUOTE>"
740(@value{GDBP}) @b{p rquote}
741$2 = 0x35d50 "<UNQUOTE>"
742@end smallexample
743
744@noindent
745@code{lquote} and @code{rquote} are indeed the new left and right quotes.
746To look at some context, we can display ten lines of source
747surrounding the current line with the @code{l} (@code{list}) command.
748
749@smallexample
750(@value{GDBP}) @b{l}
751533 xfree(rquote);
752534
753535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
754 : xstrdup (lq);
755536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
756 : xstrdup (rq);
757537
758538 len_lquote = strlen(rquote);
759539 len_rquote = strlen(lquote);
760540 @}
761541
762542 void
763@end smallexample
764
765@noindent
766Let us step past the two lines that set @code{len_lquote} and
767@code{len_rquote}, and then examine the values of those variables.
768
769@smallexample
770(@value{GDBP}) @b{n}
771539 len_rquote = strlen(lquote);
772(@value{GDBP}) @b{n}
773540 @}
774(@value{GDBP}) @b{p len_lquote}
775$3 = 9
776(@value{GDBP}) @b{p len_rquote}
777$4 = 7
778@end smallexample
779
780@noindent
781That certainly looks wrong, assuming @code{len_lquote} and
782@code{len_rquote} are meant to be the lengths of @code{lquote} and
783@code{rquote} respectively. We can set them to better values using
784the @code{p} command, since it can print the value of
785any expression---and that expression can include subroutine calls and
786assignments.
787
788@smallexample
789(@value{GDBP}) @b{p len_lquote=strlen(lquote)}
790$5 = 7
791(@value{GDBP}) @b{p len_rquote=strlen(rquote)}
792$6 = 9
793@end smallexample
794
795@noindent
796Is that enough to fix the problem of using the new quotes with the
797@code{m4} built-in @code{defn}? We can allow @code{m4} to continue
798executing with the @code{c} (@code{continue}) command, and then try the
799example that caused trouble initially:
800
801@smallexample
802(@value{GDBP}) @b{c}
803Continuing.
804
805@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
806
807baz
8080000
809@end smallexample
810
811@noindent
812Success! The new quotes now work just as well as the default ones. The
813problem seems to have been just the two typos defining the wrong
814lengths. We allow @code{m4} exit by giving it an EOF as input:
815
816@smallexample
c8aa23ab 817@b{Ctrl-d}
c906108c
SS
818Program exited normally.
819@end smallexample
820
821@noindent
822The message @samp{Program exited normally.} is from @value{GDBN}; it
823indicates @code{m4} has finished executing. We can end our @value{GDBN}
824session with the @value{GDBN} @code{quit} command.
825
826@smallexample
827(@value{GDBP}) @b{quit}
828@end smallexample
c906108c 829
6d2ebf8b 830@node Invocation
c906108c
SS
831@chapter Getting In and Out of @value{GDBN}
832
833This chapter discusses how to start @value{GDBN}, and how to get out of it.
5d161b24 834The essentials are:
c906108c 835@itemize @bullet
5d161b24 836@item
53a5351d 837type @samp{@value{GDBP}} to start @value{GDBN}.
5d161b24 838@item
c8aa23ab 839type @kbd{quit} or @kbd{Ctrl-d} to exit.
c906108c
SS
840@end itemize
841
842@menu
843* Invoking GDB:: How to start @value{GDBN}
844* Quitting GDB:: How to quit @value{GDBN}
845* Shell Commands:: How to use shell commands inside @value{GDBN}
79a6e687 846* Logging Output:: How to log @value{GDBN}'s output to a file
c906108c
SS
847@end menu
848
6d2ebf8b 849@node Invoking GDB
c906108c
SS
850@section Invoking @value{GDBN}
851
c906108c
SS
852Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
853@value{GDBN} reads commands from the terminal until you tell it to exit.
854
855You can also run @code{@value{GDBP}} with a variety of arguments and options,
856to specify more of your debugging environment at the outset.
857
c906108c
SS
858The command-line options described here are designed
859to cover a variety of situations; in some environments, some of these
5d161b24 860options may effectively be unavailable.
c906108c
SS
861
862The most usual way to start @value{GDBN} is with one argument,
863specifying an executable program:
864
474c8240 865@smallexample
c906108c 866@value{GDBP} @var{program}
474c8240 867@end smallexample
c906108c 868
c906108c
SS
869@noindent
870You can also start with both an executable program and a core file
871specified:
872
474c8240 873@smallexample
c906108c 874@value{GDBP} @var{program} @var{core}
474c8240 875@end smallexample
c906108c 876
4ed4690f
SM
877You can, instead, specify a process ID as a second argument or use option
878@code{-p}, if you want to debug a running process:
c906108c 879
474c8240 880@smallexample
c906108c 881@value{GDBP} @var{program} 1234
4ed4690f 882@value{GDBP} -p 1234
474c8240 883@end smallexample
c906108c
SS
884
885@noindent
4ed4690f
SM
886would attach @value{GDBN} to process @code{1234}. With option @option{-p} you
887can omit the @var{program} filename.
c906108c 888
c906108c 889Taking advantage of the second command-line argument requires a fairly
2df3850c
JM
890complete operating system; when you use @value{GDBN} as a remote
891debugger attached to a bare board, there may not be any notion of
892``process'', and there is often no way to get a core dump. @value{GDBN}
893will warn you if it is unable to attach or to read core dumps.
c906108c 894
aa26fa3a
TT
895You can optionally have @code{@value{GDBP}} pass any arguments after the
896executable file to the inferior using @code{--args}. This option stops
897option processing.
474c8240 898@smallexample
3f94c067 899@value{GDBP} --args gcc -O2 -c foo.c
474c8240 900@end smallexample
aa26fa3a
TT
901This will cause @code{@value{GDBP}} to debug @code{gcc}, and to set
902@code{gcc}'s command-line arguments (@pxref{Arguments}) to @samp{-O2 -c foo.c}.
903
96a2c332 904You can run @code{@value{GDBP}} without printing the front material, which describes
adcc0a31 905@value{GDBN}'s non-warranty, by specifying @code{--silent}
906(or @code{-q}/@code{--quiet}):
c906108c
SS
907
908@smallexample
adcc0a31 909@value{GDBP} --silent
c906108c
SS
910@end smallexample
911
912@noindent
913You can further control how @value{GDBN} starts up by using command-line
914options. @value{GDBN} itself can remind you of the options available.
915
916@noindent
917Type
918
474c8240 919@smallexample
c906108c 920@value{GDBP} -help
474c8240 921@end smallexample
c906108c
SS
922
923@noindent
924to display all available options and briefly describe their use
925(@samp{@value{GDBP} -h} is a shorter equivalent).
926
927All options and command line arguments you give are processed
928in sequential order. The order makes a difference when the
929@samp{-x} option is used.
930
931
932@menu
c906108c
SS
933* File Options:: Choosing files
934* Mode Options:: Choosing modes
6fc08d32 935* Startup:: What @value{GDBN} does during startup
c906108c
SS
936@end menu
937
6d2ebf8b 938@node File Options
79a6e687 939@subsection Choosing Files
c906108c 940
2df3850c 941When @value{GDBN} starts, it reads any arguments other than options as
c906108c
SS
942specifying an executable file and core file (or process ID). This is
943the same as if the arguments were specified by the @samp{-se} and
d52fb0e9 944@samp{-c} (or @samp{-p}) options respectively. (@value{GDBN} reads the
19837790
MS
945first argument that does not have an associated option flag as
946equivalent to the @samp{-se} option followed by that argument; and the
947second argument that does not have an associated option flag, if any, as
948equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
949If the second argument begins with a decimal digit, @value{GDBN} will
950first attempt to attach to it as a process, and if that fails, attempt
951to open it as a corefile. If you have a corefile whose name begins with
b383017d 952a digit, you can prevent @value{GDBN} from treating it as a pid by
c1468174 953prefixing it with @file{./}, e.g.@: @file{./12345}.
7a292a7a
SS
954
955If @value{GDBN} has not been configured to included core file support,
956such as for most embedded targets, then it will complain about a second
957argument and ignore it.
c906108c
SS
958
959Many options have both long and short forms; both are shown in the
960following list. @value{GDBN} also recognizes the long forms if you truncate
961them, so long as enough of the option is present to be unambiguous.
962(If you prefer, you can flag option arguments with @samp{--} rather
963than @samp{-}, though we illustrate the more usual convention.)
964
d700128c
EZ
965@c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
966@c way, both those who look for -foo and --foo in the index, will find
967@c it.
968
c906108c
SS
969@table @code
970@item -symbols @var{file}
971@itemx -s @var{file}
d700128c
EZ
972@cindex @code{--symbols}
973@cindex @code{-s}
c906108c
SS
974Read symbol table from file @var{file}.
975
976@item -exec @var{file}
977@itemx -e @var{file}
d700128c
EZ
978@cindex @code{--exec}
979@cindex @code{-e}
7a292a7a
SS
980Use file @var{file} as the executable file to execute when appropriate,
981and for examining pure data in conjunction with a core dump.
c906108c
SS
982
983@item -se @var{file}
d700128c 984@cindex @code{--se}
c906108c
SS
985Read symbol table from file @var{file} and use it as the executable
986file.
987
c906108c
SS
988@item -core @var{file}
989@itemx -c @var{file}
d700128c
EZ
990@cindex @code{--core}
991@cindex @code{-c}
b383017d 992Use file @var{file} as a core dump to examine.
c906108c 993
19837790
MS
994@item -pid @var{number}
995@itemx -p @var{number}
996@cindex @code{--pid}
997@cindex @code{-p}
998Connect to process ID @var{number}, as with the @code{attach} command.
c906108c
SS
999
1000@item -command @var{file}
1001@itemx -x @var{file}
d700128c
EZ
1002@cindex @code{--command}
1003@cindex @code{-x}
95433b34
JB
1004Execute commands from file @var{file}. The contents of this file is
1005evaluated exactly as the @code{source} command would.
8150ff9c 1006@xref{Command Files,, Command files}.
c906108c 1007
8a5a3c82
AS
1008@item -eval-command @var{command}
1009@itemx -ex @var{command}
1010@cindex @code{--eval-command}
1011@cindex @code{-ex}
1012Execute a single @value{GDBN} command.
1013
1014This option may be used multiple times to call multiple commands. It may
1015also be interleaved with @samp{-command} as required.
1016
1017@smallexample
1018@value{GDBP} -ex 'target sim' -ex 'load' \
1019 -x setbreakpoints -ex 'run' a.out
1020@end smallexample
1021
8320cc4f
JK
1022@item -init-command @var{file}
1023@itemx -ix @var{file}
1024@cindex @code{--init-command}
1025@cindex @code{-ix}
2d7b58e8
JK
1026Execute commands from file @var{file} before loading the inferior (but
1027after loading gdbinit files).
8320cc4f
JK
1028@xref{Startup}.
1029
1030@item -init-eval-command @var{command}
1031@itemx -iex @var{command}
1032@cindex @code{--init-eval-command}
1033@cindex @code{-iex}
2d7b58e8
JK
1034Execute a single @value{GDBN} command before loading the inferior (but
1035after loading gdbinit files).
8320cc4f
JK
1036@xref{Startup}.
1037
c906108c
SS
1038@item -directory @var{directory}
1039@itemx -d @var{directory}
d700128c
EZ
1040@cindex @code{--directory}
1041@cindex @code{-d}
4b505b12 1042Add @var{directory} to the path to search for source and script files.
c906108c 1043
c906108c
SS
1044@item -r
1045@itemx -readnow
d700128c
EZ
1046@cindex @code{--readnow}
1047@cindex @code{-r}
c906108c
SS
1048Read each symbol file's entire symbol table immediately, rather than
1049the default, which is to read it incrementally as it is needed.
1050This makes startup slower, but makes future operations faster.
53a5351d 1051
97cbe998
SDJ
1052@item --readnever
1053@anchor{--readnever}
1054@cindex @code{--readnever}, command-line option
1055Do not read each symbol file's symbolic debug information. This makes
1056startup faster but at the expense of not being able to perform
1057symbolic debugging. DWARF unwind information is also not read,
1058meaning backtraces may become incomplete or inaccurate. One use of
1059this is when a user simply wants to do the following sequence: attach,
1060dump core, detach. Loading the debugging information in this case is
1061an unnecessary cause of delay.
c906108c
SS
1062@end table
1063
6d2ebf8b 1064@node Mode Options
79a6e687 1065@subsection Choosing Modes
c906108c
SS
1066
1067You can run @value{GDBN} in various alternative modes---for example, in
1068batch mode or quiet mode.
1069
1070@table @code
bf88dd68 1071@anchor{-nx}
c906108c
SS
1072@item -nx
1073@itemx -n
d700128c
EZ
1074@cindex @code{--nx}
1075@cindex @code{-n}
07540c15
DE
1076Do not execute commands found in any initialization file.
1077There are three init files, loaded in the following order:
1078
1079@table @code
1080@item @file{system.gdbinit}
1081This is the system-wide init file.
1082Its location is specified with the @code{--with-system-gdbinit}
1083configure option (@pxref{System-wide configuration}).
1084It is loaded first when @value{GDBN} starts, before command line options
1085have been processed.
ed2a2229
CB
1086@item @file{system.gdbinit.d}
1087This is the system-wide init directory.
1088Its location is specified with the @code{--with-system-gdbinit-dir}
1089configure option (@pxref{System-wide configuration}).
1090Files in this directory are loaded in alphabetical order immediately after
1091system.gdbinit (if enabled) when @value{GDBN} starts, before command line
1092options have been processed. Files need to have a recognized scripting
1093language extension (@file{.py}/@file{.scm}) or be named with a @file{.gdb}
1094extension to be interpreted as regular @value{GDBN} commands. @value{GDBN}
1095will not recurse into any subdirectories of this directory.
07540c15
DE
1096@item @file{~/.gdbinit}
1097This is the init file in your home directory.
1098It is loaded next, after @file{system.gdbinit}, and before
1099command options have been processed.
1100@item @file{./.gdbinit}
1101This is the init file in the current directory.
1102It is loaded last, after command line options other than @code{-x} and
1103@code{-ex} have been processed. Command line options @code{-x} and
1104@code{-ex} are processed last, after @file{./.gdbinit} has been loaded.
1105@end table
1106
1107For further documentation on startup processing, @xref{Startup}.
1108For documentation on how to write command files,
1109@xref{Command Files,,Command Files}.
1110
1111@anchor{-nh}
1112@item -nh
1113@cindex @code{--nh}
1114Do not execute commands found in @file{~/.gdbinit}, the init file
1115in your home directory.
1116@xref{Startup}.
c906108c
SS
1117
1118@item -quiet
d700128c 1119@itemx -silent
c906108c 1120@itemx -q
d700128c
EZ
1121@cindex @code{--quiet}
1122@cindex @code{--silent}
1123@cindex @code{-q}
c906108c
SS
1124``Quiet''. Do not print the introductory and copyright messages. These
1125messages are also suppressed in batch mode.
1126
1127@item -batch
d700128c 1128@cindex @code{--batch}
c906108c
SS
1129Run in batch mode. Exit with status @code{0} after processing all the
1130command files specified with @samp{-x} (and all commands from
1131initialization files, if not inhibited with @samp{-n}). Exit with
1132nonzero status if an error occurs in executing the @value{GDBN} commands
5da1313b
JK
1133in the command files. Batch mode also disables pagination, sets unlimited
1134terminal width and height @pxref{Screen Size}, and acts as if @kbd{set confirm
1135off} were in effect (@pxref{Messages/Warnings}).
c906108c 1136
2df3850c
JM
1137Batch mode may be useful for running @value{GDBN} as a filter, for
1138example to download and run a program on another computer; in order to
1139make this more useful, the message
c906108c 1140
474c8240 1141@smallexample
c906108c 1142Program exited normally.
474c8240 1143@end smallexample
c906108c
SS
1144
1145@noindent
2df3850c
JM
1146(which is ordinarily issued whenever a program running under
1147@value{GDBN} control terminates) is not issued when running in batch
1148mode.
1149
1a088d06
AS
1150@item -batch-silent
1151@cindex @code{--batch-silent}
1152Run in batch mode exactly like @samp{-batch}, but totally silently. All
1153@value{GDBN} output to @code{stdout} is prevented (@code{stderr} is
1154unaffected). This is much quieter than @samp{-silent} and would be useless
1155for an interactive session.
1156
1157This is particularly useful when using targets that give @samp{Loading section}
1158messages, for example.
1159
1160Note that targets that give their output via @value{GDBN}, as opposed to
1161writing directly to @code{stdout}, will also be made silent.
1162
4b0ad762
AS
1163@item -return-child-result
1164@cindex @code{--return-child-result}
1165The return code from @value{GDBN} will be the return code from the child
1166process (the process being debugged), with the following exceptions:
1167
1168@itemize @bullet
1169@item
1170@value{GDBN} exits abnormally. E.g., due to an incorrect argument or an
1171internal error. In this case the exit code is the same as it would have been
1172without @samp{-return-child-result}.
1173@item
1174The user quits with an explicit value. E.g., @samp{quit 1}.
1175@item
1176The child process never runs, or is not allowed to terminate, in which case
1177the exit code will be -1.
1178@end itemize
1179
1180This option is useful in conjunction with @samp{-batch} or @samp{-batch-silent},
1181when @value{GDBN} is being used as a remote program loader or simulator
1182interface.
1183
2df3850c
JM
1184@item -nowindows
1185@itemx -nw
d700128c
EZ
1186@cindex @code{--nowindows}
1187@cindex @code{-nw}
2df3850c 1188``No windows''. If @value{GDBN} comes with a graphical user interface
96a2c332 1189(GUI) built in, then this option tells @value{GDBN} to only use the command-line
2df3850c
JM
1190interface. If no GUI is available, this option has no effect.
1191
1192@item -windows
1193@itemx -w
d700128c
EZ
1194@cindex @code{--windows}
1195@cindex @code{-w}
2df3850c
JM
1196If @value{GDBN} includes a GUI, then this option requires it to be
1197used if possible.
c906108c
SS
1198
1199@item -cd @var{directory}
d700128c 1200@cindex @code{--cd}
c906108c
SS
1201Run @value{GDBN} using @var{directory} as its working directory,
1202instead of the current directory.
1203
aae1c79a 1204@item -data-directory @var{directory}
8d551b02 1205@itemx -D @var{directory}
aae1c79a 1206@cindex @code{--data-directory}
8d551b02 1207@cindex @code{-D}
aae1c79a
DE
1208Run @value{GDBN} using @var{directory} as its data directory.
1209The data directory is where @value{GDBN} searches for its
1210auxiliary files. @xref{Data Files}.
1211
c906108c
SS
1212@item -fullname
1213@itemx -f
d700128c
EZ
1214@cindex @code{--fullname}
1215@cindex @code{-f}
7a292a7a
SS
1216@sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1217subprocess. It tells @value{GDBN} to output the full file name and line
1218number in a standard, recognizable fashion each time a stack frame is
1219displayed (which includes each time your program stops). This
1220recognizable format looks like two @samp{\032} characters, followed by
1221the file name, line number and character position separated by colons,
1222and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1223@samp{\032} characters as a signal to display the source code for the
1224frame.
c906108c 1225
d700128c
EZ
1226@item -annotate @var{level}
1227@cindex @code{--annotate}
1228This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1229effect is identical to using @samp{set annotate @var{level}}
086432e2
AC
1230(@pxref{Annotations}). The annotation @var{level} controls how much
1231information @value{GDBN} prints together with its prompt, values of
1232expressions, source lines, and other types of output. Level 0 is the
1233normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1234@sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1235that control @value{GDBN}, and level 2 has been deprecated.
1236
265eeb58 1237The annotation mechanism has largely been superseded by @sc{gdb/mi}
086432e2 1238(@pxref{GDB/MI}).
d700128c 1239
aa26fa3a
TT
1240@item --args
1241@cindex @code{--args}
1242Change interpretation of command line so that arguments following the
1243executable file are passed as command line arguments to the inferior.
1244This option stops option processing.
1245
2df3850c
JM
1246@item -baud @var{bps}
1247@itemx -b @var{bps}
d700128c
EZ
1248@cindex @code{--baud}
1249@cindex @code{-b}
c906108c
SS
1250Set the line speed (baud rate or bits per second) of any serial
1251interface used by @value{GDBN} for remote debugging.
c906108c 1252
f47b1503
AS
1253@item -l @var{timeout}
1254@cindex @code{-l}
1255Set the timeout (in seconds) of any communication used by @value{GDBN}
1256for remote debugging.
1257
c906108c 1258@item -tty @var{device}
d700128c
EZ
1259@itemx -t @var{device}
1260@cindex @code{--tty}
1261@cindex @code{-t}
c906108c
SS
1262Run using @var{device} for your program's standard input and output.
1263@c FIXME: kingdon thinks there is more to -tty. Investigate.
c906108c 1264
53a5351d 1265@c resolve the situation of these eventually
c4555f82
SC
1266@item -tui
1267@cindex @code{--tui}
d0d5df6f
AC
1268Activate the @dfn{Text User Interface} when starting. The Text User
1269Interface manages several text windows on the terminal, showing
1270source, assembly, registers and @value{GDBN} command outputs
217bff3e
JK
1271(@pxref{TUI, ,@value{GDBN} Text User Interface}). Do not use this
1272option if you run @value{GDBN} from Emacs (@pxref{Emacs, ,
1273Using @value{GDBN} under @sc{gnu} Emacs}).
53a5351d 1274
d700128c
EZ
1275@item -interpreter @var{interp}
1276@cindex @code{--interpreter}
1277Use the interpreter @var{interp} for interface with the controlling
1278program or device. This option is meant to be set by programs which
94bbb2c0 1279communicate with @value{GDBN} using it as a back end.
21c294e6 1280@xref{Interpreters, , Command Interpreters}.
94bbb2c0 1281
b4be1b06
SM
1282@samp{--interpreter=mi} (or @samp{--interpreter=mi3}) causes
1283@value{GDBN} to use the @dfn{@sc{gdb/mi} interface} version 3 (@pxref{GDB/MI, ,
1284The @sc{gdb/mi} Interface}) included since @value{GDBN} version 9.1. @sc{gdb/mi}
1285version 2 (@code{mi2}), included in @value{GDBN} 6.0 and version 1 (@code{mi1}),
1286included in @value{GDBN} 5.3, are also available. Earlier @sc{gdb/mi}
1287interfaces are no longer supported.
d700128c
EZ
1288
1289@item -write
1290@cindex @code{--write}
1291Open the executable and core files for both reading and writing. This
1292is equivalent to the @samp{set write on} command inside @value{GDBN}
1293(@pxref{Patching}).
1294
1295@item -statistics
1296@cindex @code{--statistics}
1297This option causes @value{GDBN} to print statistics about time and
1298memory usage after it completes each command and returns to the prompt.
1299
1300@item -version
1301@cindex @code{--version}
1302This option causes @value{GDBN} to print its version number and
1303no-warranty blurb, and exit.
1304
6eaaf48b
EZ
1305@item -configuration
1306@cindex @code{--configuration}
1307This option causes @value{GDBN} to print details about its build-time
1308configuration parameters, and then exit. These details can be
1309important when reporting @value{GDBN} bugs (@pxref{GDB Bugs}).
1310
c906108c
SS
1311@end table
1312
6fc08d32 1313@node Startup
79a6e687 1314@subsection What @value{GDBN} Does During Startup
6fc08d32
EZ
1315@cindex @value{GDBN} startup
1316
1317Here's the description of what @value{GDBN} does during session startup:
1318
1319@enumerate
1320@item
1321Sets up the command interpreter as specified by the command line
1322(@pxref{Mode Options, interpreter}).
1323
1324@item
1325@cindex init file
098b41a6
JG
1326Reads the system-wide @dfn{init file} (if @option{--with-system-gdbinit} was
1327used when building @value{GDBN}; @pxref{System-wide configuration,
ed2a2229
CB
1328 ,System-wide configuration and settings}) and the files in the system-wide
1329gdbinit directory (if @option{--with-system-gdbinit-dir} was used) and executes
1330all the commands in those files. The files need to be named with a @file{.gdb}
1331extension to be interpreted as @value{GDBN} commands, or they can be written
1332in a supported scripting language with an appropriate file extension.
098b41a6 1333
bf88dd68 1334@anchor{Home Directory Init File}
098b41a6
JG
1335@item
1336Reads the init file (if any) in your home directory@footnote{On
6fc08d32
EZ
1337DOS/Windows systems, the home directory is the one pointed to by the
1338@code{HOME} environment variable.} and executes all the commands in
1339that file.
1340
2d7b58e8
JK
1341@anchor{Option -init-eval-command}
1342@item
1343Executes commands and command files specified by the @samp{-iex} and
1344@samp{-ix} options in their specified order. Usually you should use the
1345@samp{-ex} and @samp{-x} options instead, but this way you can apply
1346settings before @value{GDBN} init files get executed and before inferior
1347gets loaded.
1348
6fc08d32
EZ
1349@item
1350Processes command line options and operands.
1351
bf88dd68 1352@anchor{Init File in the Current Directory during Startup}
6fc08d32
EZ
1353@item
1354Reads and executes the commands from init file (if any) in the current
bf88dd68
JK
1355working directory as long as @samp{set auto-load local-gdbinit} is set to
1356@samp{on} (@pxref{Init File in the Current Directory}).
1357This is only done if the current directory is
119b882a
EZ
1358different from your home directory. Thus, you can have more than one
1359init file, one generic in your home directory, and another, specific
1360to the program you are debugging, in the directory where you invoke
6fc08d32
EZ
1361@value{GDBN}.
1362
a86caf66
DE
1363@item
1364If the command line specified a program to debug, or a process to
1365attach to, or a core file, @value{GDBN} loads any auto-loaded
1366scripts provided for the program or for its loaded shared libraries.
1367@xref{Auto-loading}.
1368
1369If you wish to disable the auto-loading during startup,
1370you must do something like the following:
1371
1372@smallexample
bf88dd68 1373$ gdb -iex "set auto-load python-scripts off" myprogram
a86caf66
DE
1374@end smallexample
1375
8320cc4f
JK
1376Option @samp{-ex} does not work because the auto-loading is then turned
1377off too late.
a86caf66 1378
6fc08d32 1379@item
6fe37d23
JK
1380Executes commands and command files specified by the @samp{-ex} and
1381@samp{-x} options in their specified order. @xref{Command Files}, for
1382more details about @value{GDBN} command files.
6fc08d32
EZ
1383
1384@item
1385Reads the command history recorded in the @dfn{history file}.
d620b259 1386@xref{Command History}, for more details about the command history and the
6fc08d32
EZ
1387files where @value{GDBN} records it.
1388@end enumerate
1389
1390Init files use the same syntax as @dfn{command files} (@pxref{Command
1391Files}) and are processed by @value{GDBN} in the same way. The init
1392file in your home directory can set options (such as @samp{set
1393complaints}) that affect subsequent processing of command line options
1394and operands. Init files are not executed if you use the @samp{-nx}
79a6e687 1395option (@pxref{Mode Options, ,Choosing Modes}).
6fc08d32 1396
098b41a6
JG
1397To display the list of init files loaded by gdb at startup, you
1398can use @kbd{gdb --help}.
1399
6fc08d32
EZ
1400@cindex init file name
1401@cindex @file{.gdbinit}
119b882a 1402@cindex @file{gdb.ini}
8807d78b 1403The @value{GDBN} init files are normally called @file{.gdbinit}.
119b882a
EZ
1404The DJGPP port of @value{GDBN} uses the name @file{gdb.ini}, due to
1405the limitations of file names imposed by DOS filesystems. The Windows
4d3f93a2
JB
1406port of @value{GDBN} uses the standard name, but if it finds a
1407@file{gdb.ini} file in your home directory, it warns you about that
1408and suggests to rename the file to the standard name.
119b882a 1409
6fc08d32 1410
6d2ebf8b 1411@node Quitting GDB
c906108c
SS
1412@section Quitting @value{GDBN}
1413@cindex exiting @value{GDBN}
1414@cindex leaving @value{GDBN}
1415
1416@table @code
1417@kindex quit @r{[}@var{expression}@r{]}
41afff9a 1418@kindex q @r{(@code{quit})}
96a2c332
SS
1419@item quit @r{[}@var{expression}@r{]}
1420@itemx q
1421To exit @value{GDBN}, use the @code{quit} command (abbreviated
c8aa23ab 1422@code{q}), or type an end-of-file character (usually @kbd{Ctrl-d}). If you
96a2c332
SS
1423do not supply @var{expression}, @value{GDBN} will terminate normally;
1424otherwise it will terminate using the result of @var{expression} as the
1425error code.
c906108c
SS
1426@end table
1427
1428@cindex interrupt
c8aa23ab 1429An interrupt (often @kbd{Ctrl-c}) does not exit from @value{GDBN}, but rather
c906108c
SS
1430terminates the action of any @value{GDBN} command that is in progress and
1431returns to @value{GDBN} command level. It is safe to type the interrupt
1432character at any time because @value{GDBN} does not allow it to take effect
1433until a time when it is safe.
1434
c906108c
SS
1435If you have been using @value{GDBN} to control an attached process or
1436device, you can release it with the @code{detach} command
79a6e687 1437(@pxref{Attach, ,Debugging an Already-running Process}).
c906108c 1438
6d2ebf8b 1439@node Shell Commands
79a6e687 1440@section Shell Commands
c906108c
SS
1441
1442If you need to execute occasional shell commands during your
1443debugging session, there is no need to leave or suspend @value{GDBN}; you can
1444just use the @code{shell} command.
1445
1446@table @code
1447@kindex shell
ed59ded5 1448@kindex !
c906108c 1449@cindex shell escape
ed59ded5
DE
1450@item shell @var{command-string}
1451@itemx !@var{command-string}
1452Invoke a standard shell to execute @var{command-string}.
1453Note that no space is needed between @code{!} and @var{command-string}.
edf92af0
EZ
1454On GNU and Unix systems, the environment variable @code{SHELL}, if it
1455exists, determines which shell to run. Otherwise @value{GDBN} uses
1456the default shell (@file{/bin/sh} on GNU and Unix systems,
1457@file{cmd.exe} on MS-Windows, @file{COMMAND.COM} on MS-DOS, etc.).
c906108c
SS
1458@end table
1459
1460The utility @code{make} is often needed in development environments.
1461You do not have to use the @code{shell} command for this purpose in
1462@value{GDBN}:
1463
1464@table @code
1465@kindex make
1466@cindex calling make
1467@item make @var{make-args}
1468Execute the @code{make} program with the specified
1469arguments. This is equivalent to @samp{shell make @var{make-args}}.
1470@end table
1471
e2c52041
PW
1472@table @code
1473@kindex pipe
1474@kindex |
1475@cindex send the output of a gdb command to a shell command
1476@anchor{pipe}
1477@item pipe [@var{command}] | @var{shell_command}
1478@itemx | [@var{command}] | @var{shell_command}
1479@itemx pipe -d @var{delim} @var{command} @var{delim} @var{shell_command}
1480@itemx | -d @var{delim} @var{command} @var{delim} @var{shell_command}
1481Executes @var{command} and sends its output to @var{shell_command}.
1482Note that no space is needed around @code{|}.
1483If no @var{command} is provided, the last command executed is repeated.
1484
1485In case the @var{command} contains a @code{|}, the option @code{-d @var{delim}}
1486can be used to specify an alternate delimiter string @var{delim} that separates
1487the @var{command} from the @var{shell_command}.
1488
1489Example:
1490@smallexample
1491@group
1492(gdb) p var
1493$1 = @{
1494 black = 144,
1495 red = 233,
1496 green = 377,
1497 blue = 610,
1498 white = 987
1499@}
1500@end group
1501@group
1502(gdb) pipe p var|wc
1503 7 19 80
1504(gdb) |p var|wc -l
15057
1506@end group
1507@group
1508(gdb) p /x var
1509$4 = @{
1510 black = 0x90,
1511 red = 0xe9,
1512 green = 0x179,
1513 blue = 0x262,
1514 white = 0x3db
1515@}
1516(gdb) ||grep red
1517 red => 0xe9,
1518@end group
1519@group
1520(gdb) | -d ! echo this contains a | char\n ! sed -e 's/|/PIPE/'
1521this contains a PIPE char
1522(gdb) | -d xxx echo this contains a | char!\n xxx sed -e 's/|/PIPE/'
1523this contains a PIPE char!
1524(gdb)
1525@end group
1526@end smallexample
1527@end table
1528
1529The convenience variables @code{$_shell_exitcode} and @code{$_shell_exitsignal}
1530can be used to examine the exit status of the last shell command launched
1531by @code{shell}, @code{make}, @code{pipe} and @code{|}.
1532@xref{Convenience Vars,, Convenience Variables}.
1533
79a6e687
BW
1534@node Logging Output
1535@section Logging Output
0fac0b41 1536@cindex logging @value{GDBN} output
9c16f35a 1537@cindex save @value{GDBN} output to a file
0fac0b41
DJ
1538
1539You may want to save the output of @value{GDBN} commands to a file.
1540There are several commands to control @value{GDBN}'s logging.
1541
1542@table @code
1543@kindex set logging
1544@item set logging on
1545Enable logging.
1546@item set logging off
1547Disable logging.
9c16f35a 1548@cindex logging file name
0fac0b41
DJ
1549@item set logging file @var{file}
1550Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1551@item set logging overwrite [on|off]
1552By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1553you want @code{set logging on} to overwrite the logfile instead.
1554@item set logging redirect [on|off]
1555By default, @value{GDBN} output will go to both the terminal and the logfile.
1556Set @code{redirect} if you want output to go only to the log file.
b7060614
AH
1557@item set logging debugredirect [on|off]
1558By default, @value{GDBN} debug output will go to both the terminal and the logfile.
1559Set @code{debugredirect} if you want debug output to go only to the log file.
0fac0b41
DJ
1560@kindex show logging
1561@item show logging
1562Show the current values of the logging settings.
1563@end table
1564
e2c52041
PW
1565You can also redirect the output of a @value{GDBN} command to a
1566shell command. @xref{pipe}.
6d2ebf8b 1567@node Commands
c906108c
SS
1568@chapter @value{GDBN} Commands
1569
1570You can abbreviate a @value{GDBN} command to the first few letters of the command
1571name, if that abbreviation is unambiguous; and you can repeat certain
1572@value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1573key to get @value{GDBN} to fill out the rest of a word in a command (or to
1574show you the alternatives available, if there is more than one possibility).
1575
1576@menu
1577* Command Syntax:: How to give commands to @value{GDBN}
fdbc9870 1578* Command Settings:: How to change default behavior of commands
c906108c 1579* Completion:: Command completion
3345721a 1580* Command Options:: Command options
5b860c93 1581* Command aliases default args:: Automatically prepend default arguments to user-defined aliases
c906108c
SS
1582* Help:: How to ask @value{GDBN} for help
1583@end menu
1584
6d2ebf8b 1585@node Command Syntax
79a6e687 1586@section Command Syntax
c906108c
SS
1587
1588A @value{GDBN} command is a single line of input. There is no limit on
1589how long it can be. It starts with a command name, which is followed by
1590arguments whose meaning depends on the command name. For example, the
1591command @code{step} accepts an argument which is the number of times to
1592step, as in @samp{step 5}. You can also use the @code{step} command
96a2c332 1593with no arguments. Some commands do not allow any arguments.
c906108c
SS
1594
1595@cindex abbreviation
1596@value{GDBN} command names may always be truncated if that abbreviation is
1597unambiguous. Other possible command abbreviations are listed in the
1598documentation for individual commands. In some cases, even ambiguous
1599abbreviations are allowed; for example, @code{s} is specially defined as
1600equivalent to @code{step} even though there are other commands whose
1601names start with @code{s}. You can test abbreviations by using them as
1602arguments to the @code{help} command.
1603
1604@cindex repeating commands
41afff9a 1605@kindex RET @r{(repeat last command)}
c906108c 1606A blank line as input to @value{GDBN} (typing just @key{RET}) means to
96a2c332 1607repeat the previous command. Certain commands (for example, @code{run})
c906108c
SS
1608will not repeat this way; these are commands whose unintentional
1609repetition might cause trouble and which you are unlikely to want to
c45da7e6
EZ
1610repeat. User-defined commands can disable this feature; see
1611@ref{Define, dont-repeat}.
c906108c
SS
1612
1613The @code{list} and @code{x} commands, when you repeat them with
1614@key{RET}, construct new arguments rather than repeating
1615exactly as typed. This permits easy scanning of source or memory.
1616
1617@value{GDBN} can also use @key{RET} in another way: to partition lengthy
1618output, in a way similar to the common utility @code{more}
79a6e687 1619(@pxref{Screen Size,,Screen Size}). Since it is easy to press one
c906108c
SS
1620@key{RET} too many in this situation, @value{GDBN} disables command
1621repetition after any command that generates this sort of display.
1622
41afff9a 1623@kindex # @r{(a comment)}
c906108c
SS
1624@cindex comment
1625Any text from a @kbd{#} to the end of the line is a comment; it does
1626nothing. This is useful mainly in command files (@pxref{Command
79a6e687 1627Files,,Command Files}).
c906108c 1628
88118b3a 1629@cindex repeating command sequences
c8aa23ab
EZ
1630@kindex Ctrl-o @r{(operate-and-get-next)}
1631The @kbd{Ctrl-o} binding is useful for repeating a complex sequence of
7f9087cb 1632commands. This command accepts the current line, like @key{RET}, and
88118b3a
TT
1633then fetches the next line relative to the current line from the history
1634for editing.
1635
fdbc9870
PA
1636
1637@node Command Settings
1638@section Command Settings
1639@cindex default behavior of commands, changing
1640@cindex default settings, changing
1641
1642Many commands change their behavior according to command-specific
1643variables or settings. These settings can be changed with the
1644@code{set} subcommands. For example, the @code{print} command
1645(@pxref{Data, ,Examining Data}) prints arrays differently depending on
1646settings changeable with the commands @code{set print elements
1647NUMBER-OF-ELEMENTS} and @code{set print array-indexes}, among others.
1648
1649You can change these settings to your preference in the gdbinit files
1650loaded at @value{GDBN} startup. @xref{Startup}.
1651
1652The settings can also be changed interactively during the debugging
1653session. For example, to change the limit of array elements to print,
1654you can do the following:
1655@smallexample
1656(@value{GDBN}) set print elements 10
1657(@value{GDBN}) print some_array
1658$1 = @{0, 10, 20, 30, 40, 50, 60, 70, 80, 90...@}
1659@end smallexample
1660
1661The above @code{set print elements 10} command changes the number of
1662elements to print from the default of 200 to 10. If you only intend
1663this limit of 10 to be used for printing @code{some_array}, then you
1664must restore the limit back to 200, with @code{set print elements
1665200}.
1666
1667Some commands allow overriding settings with command options. For
1668example, the @code{print} command supports a number of options that
1669allow overriding relevant global print settings as set by @code{set
1670print} subcommands. @xref{print options}. The example above could be
1671rewritten as:
1672@smallexample
1673(@value{GDBN}) print -elements 10 -- some_array
1674$1 = @{0, 10, 20, 30, 40, 50, 60, 70, 80, 90...@}
1675@end smallexample
1676
1677Alternatively, you can use the @code{with} command to change a setting
1678temporarily, for the duration of a command invocation.
1679
1680@table @code
1681@kindex with command
1682@kindex w @r{(@code{with})}
1683@cindex settings
1684@cindex temporarily change settings
1685@item with @var{setting} [@var{value}] [-- @var{command}]
1686@itemx w @var{setting} [@var{value}] [-- @var{command}]
1687Temporarily set @var{setting} to @var{value} for the duration of
1688@var{command}.
1689
1690@var{setting} is any setting you can change with the @code{set}
1691subcommands. @var{value} is the value to assign to @code{setting}
1692while running @code{command}.
1693
1694If no @var{command} is provided, the last command executed is
1695repeated.
1696
1697If a @var{command} is provided, it must be preceded by a double dash
1698(@code{--}) separator. This is required because some settings accept
1699free-form arguments, such as expressions or filenames.
1700
1701For example, the command
1702@smallexample
1703(@value{GDBN}) with print array on -- print some_array
1704@end smallexample
1705@noindent
1706is equivalent to the following 3 commands:
1707@smallexample
1708(@value{GDBN}) set print array on
1709(@value{GDBN}) print some_array
1710(@value{GDBN}) set print array off
1711@end smallexample
1712
1713The @code{with} command is particularly useful when you want to
1714override a setting while running user-defined commands, or commands
1715defined in Python or Guile. @xref{Extending GDB,, Extending GDB}.
1716
1717@smallexample
1718(@value{GDBN}) with print pretty on -- my_complex_command
1719@end smallexample
1720
1721To change several settings for the same command, you can nest
1722@code{with} commands. For example, @code{with language ada -- with
1723print elements 10} temporarily changes the language to Ada and sets a
1724limit of 10 elements to print for arrays and strings.
1725
1726@end table
1727
6d2ebf8b 1728@node Completion
79a6e687 1729@section Command Completion
c906108c
SS
1730
1731@cindex completion
1732@cindex word completion
1733@value{GDBN} can fill in the rest of a word in a command for you, if there is
1734only one possibility; it can also show you what the valid possibilities
1735are for the next word in a command, at any time. This works for @value{GDBN}
3345721a
PA
1736commands, @value{GDBN} subcommands, command options, and the names of symbols
1737in your program.
c906108c
SS
1738
1739Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1740of a word. If there is only one possibility, @value{GDBN} fills in the
1741word, and waits for you to finish the command (or press @key{RET} to
1742enter it). For example, if you type
1743
1744@c FIXME "@key" does not distinguish its argument sufficiently to permit
1745@c complete accuracy in these examples; space introduced for clarity.
1746@c If texinfo enhancements make it unnecessary, it would be nice to
1747@c replace " @key" by "@key" in the following...
474c8240 1748@smallexample
c906108c 1749(@value{GDBP}) info bre @key{TAB}
474c8240 1750@end smallexample
c906108c
SS
1751
1752@noindent
1753@value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1754the only @code{info} subcommand beginning with @samp{bre}:
1755
474c8240 1756@smallexample
c906108c 1757(@value{GDBP}) info breakpoints
474c8240 1758@end smallexample
c906108c
SS
1759
1760@noindent
1761You can either press @key{RET} at this point, to run the @code{info
1762breakpoints} command, or backspace and enter something else, if
1763@samp{breakpoints} does not look like the command you expected. (If you
1764were sure you wanted @code{info breakpoints} in the first place, you
1765might as well just type @key{RET} immediately after @samp{info bre},
1766to exploit command abbreviations rather than command completion).
1767
1768If there is more than one possibility for the next word when you press
1769@key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1770characters and try again, or just press @key{TAB} a second time;
1771@value{GDBN} displays all the possible completions for that word. For
1772example, you might want to set a breakpoint on a subroutine whose name
1773begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1774just sounds the bell. Typing @key{TAB} again displays all the
1775function names in your program that begin with those characters, for
1776example:
1777
474c8240 1778@smallexample
c906108c
SS
1779(@value{GDBP}) b make_ @key{TAB}
1780@exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
5d161b24
DB
1781make_a_section_from_file make_environ
1782make_abs_section make_function_type
1783make_blockvector make_pointer_type
1784make_cleanup make_reference_type
c906108c
SS
1785make_command make_symbol_completion_list
1786(@value{GDBP}) b make_
474c8240 1787@end smallexample
c906108c
SS
1788
1789@noindent
1790After displaying the available possibilities, @value{GDBN} copies your
1791partial input (@samp{b make_} in the example) so you can finish the
1792command.
1793
1794If you just want to see the list of alternatives in the first place, you
b37052ae 1795can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
7a292a7a 1796means @kbd{@key{META} ?}. You can type this either by holding down a
c906108c 1797key designated as the @key{META} shift on your keyboard (if there is
7a292a7a 1798one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
c906108c 1799
ef0b411a
GB
1800If the number of possible completions is large, @value{GDBN} will
1801print as much of the list as it has collected, as well as a message
1802indicating that the list may be truncated.
1803
1804@smallexample
1805(@value{GDBP}) b m@key{TAB}@key{TAB}
1806main
1807<... the rest of the possible completions ...>
1808*** List may be truncated, max-completions reached. ***
1809(@value{GDBP}) b m
1810@end smallexample
1811
1812@noindent
1813This behavior can be controlled with the following commands:
1814
1815@table @code
1816@kindex set max-completions
1817@item set max-completions @var{limit}
1818@itemx set max-completions unlimited
1819Set the maximum number of completion candidates. @value{GDBN} will
1820stop looking for more completions once it collects this many candidates.
1821This is useful when completing on things like function names as collecting
1822all the possible candidates can be time consuming.
1823The default value is 200. A value of zero disables tab-completion.
1824Note that setting either no limit or a very large limit can make
1825completion slow.
1826@kindex show max-completions
1827@item show max-completions
1828Show the maximum number of candidates that @value{GDBN} will collect and show
1829during completion.
1830@end table
1831
c906108c
SS
1832@cindex quotes in commands
1833@cindex completion of quoted strings
1834Sometimes the string you need, while logically a ``word'', may contain
7a292a7a
SS
1835parentheses or other characters that @value{GDBN} normally excludes from
1836its notion of a word. To permit word completion to work in this
1837situation, you may enclose words in @code{'} (single quote marks) in
1838@value{GDBN} commands.
c906108c 1839
d044bac8
PA
1840A likely situation where you might need this is in typing an
1841expression that involves a C@t{++} symbol name with template
1842parameters. This is because when completing expressions, GDB treats
1843the @samp{<} character as word delimiter, assuming that it's the
1844less-than comparison operator (@pxref{C Operators, , C and C@t{++}
1845Operators}).
1846
1847For example, when you want to call a C@t{++} template function
1848interactively using the @code{print} or @code{call} commands, you may
1849need to distinguish whether you mean the version of @code{name} that
1850was specialized for @code{int}, @code{name<int>()}, or the version
1851that was specialized for @code{float}, @code{name<float>()}. To use
1852the word-completion facilities in this situation, type a single quote
b37052ae
EZ
1853@code{'} at the beginning of the function name. This alerts
1854@value{GDBN} that it may need to consider more information than usual
1855when you press @key{TAB} or @kbd{M-?} to request word completion:
c906108c 1856
474c8240 1857@smallexample
d044bac8
PA
1858(@value{GDBP}) p 'func< @kbd{M-?}
1859func<int>() func<float>()
1860(@value{GDBP}) p 'func<
474c8240 1861@end smallexample
c906108c 1862
d044bac8
PA
1863When setting breakpoints however (@pxref{Specify Location}), you don't
1864usually need to type a quote before the function name, because
1865@value{GDBN} understands that you want to set a breakpoint on a
1866function:
c906108c 1867
474c8240 1868@smallexample
d044bac8
PA
1869(@value{GDBP}) b func< @kbd{M-?}
1870func<int>() func<float>()
1871(@value{GDBP}) b func<
474c8240 1872@end smallexample
c906108c 1873
d044bac8
PA
1874This is true even in the case of typing the name of C@t{++} overloaded
1875functions (multiple definitions of the same function, distinguished by
1876argument type). For example, when you want to set a breakpoint you
1877don't need to distinguish whether you mean the version of @code{name}
1878that takes an @code{int} parameter, @code{name(int)}, or the version
1879that takes a @code{float} parameter, @code{name(float)}.
1880
1881@smallexample
1882(@value{GDBP}) b bubble( @kbd{M-?}
1883bubble(int) bubble(double)
1884(@value{GDBP}) b bubble(dou @kbd{M-?}
1885bubble(double)
1886@end smallexample
1887
1888See @ref{quoting names} for a description of other scenarios that
1889require quoting.
c906108c 1890
79a6e687
BW
1891For more information about overloaded functions, see @ref{C Plus Plus
1892Expressions, ,C@t{++} Expressions}. You can use the command @code{set
c906108c 1893overload-resolution off} to disable overload resolution;
79a6e687 1894see @ref{Debugging C Plus Plus, ,@value{GDBN} Features for C@t{++}}.
c906108c 1895
65d12d83
TT
1896@cindex completion of structure field names
1897@cindex structure field name completion
1898@cindex completion of union field names
1899@cindex union field name completion
1900When completing in an expression which looks up a field in a
1901structure, @value{GDBN} also tries@footnote{The completer can be
1902confused by certain kinds of invalid expressions. Also, it only
1903examines the static type of the expression, not the dynamic type.} to
1904limit completions to the field names available in the type of the
1905left-hand-side:
1906
1907@smallexample
1908(@value{GDBP}) p gdb_stdout.@kbd{M-?}
01124a23
DE
1909magic to_fputs to_rewind
1910to_data to_isatty to_write
1911to_delete to_put to_write_async_safe
1912to_flush to_read
65d12d83
TT
1913@end smallexample
1914
1915@noindent
1916This is because the @code{gdb_stdout} is a variable of the type
1917@code{struct ui_file} that is defined in @value{GDBN} sources as
1918follows:
1919
1920@smallexample
1921struct ui_file
1922@{
1923 int *magic;
1924 ui_file_flush_ftype *to_flush;
1925 ui_file_write_ftype *to_write;
01124a23 1926 ui_file_write_async_safe_ftype *to_write_async_safe;
65d12d83
TT
1927 ui_file_fputs_ftype *to_fputs;
1928 ui_file_read_ftype *to_read;
1929 ui_file_delete_ftype *to_delete;
1930 ui_file_isatty_ftype *to_isatty;
1931 ui_file_rewind_ftype *to_rewind;
1932 ui_file_put_ftype *to_put;
1933 void *to_data;
1934@}
1935@end smallexample
1936
3345721a
PA
1937@node Command Options
1938@section Command options
1939
1940@cindex command options
1941Some commands accept options starting with a leading dash. For
1942example, @code{print -pretty}. Similarly to command names, you can
1943abbreviate a @value{GDBN} option to the first few letters of the
1944option name, if that abbreviation is unambiguous, and you can also use
1945the @key{TAB} key to get @value{GDBN} to fill out the rest of a word
1946in an option (or to show you the alternatives available, if there is
1947more than one possibility).
1948
1949@cindex command options, raw input
1950Some commands take raw input as argument. For example, the print
1951command processes arbitrary expressions in any of the languages
1952supported by @value{GDBN}. With such commands, because raw input may
1953start with a leading dash that would be confused with an option or any
d8edc8b7
PW
1954of its abbreviations, e.g.@: @code{print -p} (short for @code{print
1955-pretty} or printing negative @code{p}?), if you specify any command
3345721a
PA
1956option, then you must use a double-dash (@code{--}) delimiter to
1957indicate the end of options.
1958
1959@cindex command options, boolean
1960
1961Some options are described as accepting an argument which can be
1962either @code{on} or @code{off}. These are known as @dfn{boolean
1963options}. Similarly to boolean settings commands---@code{on} and
1964@code{off} are the typical values, but any of @code{1}, @code{yes} and
1965@code{enable} can also be used as ``true'' value, and any of @code{0},
1966@code{no} and @code{disable} can also be used as ``false'' value. You
1967can also omit a ``true'' value, as it is implied by default.
1968
1969For example, these are equivalent:
1970
1971@smallexample
1972(@value{GDBP}) print -object on -pretty off -element unlimited -- *myptr
1973(@value{GDBP}) p -o -p 0 -e u -- *myptr
1974@end smallexample
1975
1976You can discover the set of options some command accepts by completing
1977on @code{-} after the command name. For example:
1978
1979@smallexample
1980(@value{GDBP}) print -@key{TAB}@key{TAB}
d8edc8b7
PW
1981-address -max-depth -raw-values -union
1982-array -null-stop -repeats -vtbl
1983-array-indexes -object -static-members
1984-elements -pretty -symbol
3345721a
PA
1985@end smallexample
1986
1987Completion will in some cases guide you with a suggestion of what kind
1988of argument an option expects. For example:
1989
1990@smallexample
1991(@value{GDBP}) print -elements @key{TAB}@key{TAB}
1992NUMBER unlimited
1993@end smallexample
1994
1995Here, the option expects a number (e.g., @code{100}), not literal
1996@code{NUMBER}. Such metasyntactical arguments are always presented in
1997uppercase.
1998
1999(For more on using the @code{print} command, see @ref{Data, ,Examining
2000Data}.)
c906108c 2001
5b860c93
PW
2002@node Command aliases default args
2003@section Automatically prepend default arguments to user-defined aliases
2004
2005You can tell @value{GDBN} to always prepend some default arguments to
2006the list of arguments provided explicitly by the user when using a
2007user-defined alias.
2008
2009If you repeatedly use the same arguments or options for a command, you
2010can define an alias for this command and tell @value{GDBN} to
2011automatically prepend these arguments or options to the list of
2012arguments you type explicitly when using the alias@footnote{@value{GDBN}
2013could easily accept default arguments for pre-defined commands and aliases,
2014but it was deemed this would be confusing, and so is not allowed.}.
2015
2016For example, if you often use the command @code{thread apply all}
2017specifying to work on the threads in ascending order and to continue in case it
2018encounters an error, you can tell @value{GDBN} to automatically preprend
2019the @code{-ascending} and @code{-c} options by using:
2020
2021@smallexample
2022(@value{GDBP}) alias thread apply asc-all = thread apply all -ascending -c
2023@end smallexample
2024
2025Once you have defined this alias with its default args, any time you type
2026the @code{thread apply asc-all} followed by @code{some arguments},
2027@value{GDBN} will execute @code{thread apply all -ascending -c some arguments}.
2028
2029To have even less to type, you can also define a one word alias:
2030@smallexample
2031(@value{GDBP}) alias t_a_c = thread apply all -ascending -c
2032@end smallexample
2033
2034As usual, unambiguous abbreviations can be used for @var{alias}
2035and @var{default-args}.
2036
2037The different aliases of a command do not share their default args.
2038For example, you define a new alias @code{bt_ALL} showing all possible
2039information and another alias @code{bt_SMALL} showing very limited information
2040using:
2041@smallexample
2042(@value{GDBP}) alias bt_ALL = backtrace -entry-values both -frame-arg all \
2043 -past-main -past-entry -full
2044(@value{GDBP}) alias bt_SMALL = backtrace -entry-values no -frame-arg none \
2045 -past-main off -past-entry off
2046@end smallexample
2047
2048(For more on using the @code{alias} command, see @ref{Aliases}.)
2049
2050Default args are not limited to the arguments and options of @var{command},
2051but can specify nested commands if @var{command} accepts such a nested command
2052as argument.
2053For example, the below defines @code{faalocalsoftype} that lists the
2054frames having locals of a certain type, together with the matching
2055local vars:
2056@smallexample
2057(@value{GDBP}) alias faalocalsoftype = frame apply all info locals -q -t
2058(@value{GDBP}) faalocalsoftype int
2059#1 0x55554f5e in sleeper_or_burner (v=0xdf50) at sleepers.c:86
2060i = 0
2061ret = 21845
2062@end smallexample
2063
2064This is also very useful to define an alias for a set of nested @code{with}
2065commands to have a particular combination of temporary settings. For example,
2066the below defines the alias @code{pp10} that pretty prints an expression
2067argument, with a maximum of 10 elements if the expression is a string or
2068an array:
2069@smallexample
2070(@value{GDBP}) alias pp10 = with print pretty -- with print elements 10 -- print
2071@end smallexample
2072This defines the alias @code{pp10} as being a sequence of 3 commands.
2073The first part @code{with print pretty --} temporarily activates the setting
2074@code{set print pretty}, then launches the command that follows the separator
2075@code{--}.
2076The command following the first part is also a @code{with} command that
2077temporarily changes the setting @code{set print elements} to 10, then
2078launches the command that follows the second separator @code{--}.
2079The third part @code{print} is the command the @code{pp10} alias will launch,
2080using the temporary values of the settings and the arguments explicitly given
2081by the user.
2082For more information about the @code{with} command usage,
2083see @ref{Command Settings}.
2084
6d2ebf8b 2085@node Help
79a6e687 2086@section Getting Help
c906108c
SS
2087@cindex online documentation
2088@kindex help
2089
5d161b24 2090You can always ask @value{GDBN} itself for information on its commands,
c906108c
SS
2091using the command @code{help}.
2092
2093@table @code
41afff9a 2094@kindex h @r{(@code{help})}
c906108c
SS
2095@item help
2096@itemx h
2097You can use @code{help} (abbreviated @code{h}) with no arguments to
2098display a short list of named classes of commands:
2099
2100@smallexample
2101(@value{GDBP}) help
2102List of classes of commands:
2103
5b860c93 2104aliases -- User-defined aliases of other commands
c906108c 2105breakpoints -- Making program stop at certain points
2df3850c 2106data -- Examining data
c906108c 2107files -- Specifying and examining files
2df3850c
JM
2108internals -- Maintenance commands
2109obscure -- Obscure features
2110running -- Running the program
2111stack -- Examining the stack
c906108c
SS
2112status -- Status inquiries
2113support -- Support facilities
12c27660 2114tracepoints -- Tracing of program execution without
96a2c332 2115 stopping the program
c906108c 2116user-defined -- User-defined commands
c906108c 2117
5d161b24 2118Type "help" followed by a class name for a list of
c906108c 2119commands in that class.
5d161b24 2120Type "help" followed by command name for full
c906108c
SS
2121documentation.
2122Command name abbreviations are allowed if unambiguous.
2123(@value{GDBP})
2124@end smallexample
96a2c332 2125@c the above line break eliminates huge line overfull...
c906108c
SS
2126
2127@item help @var{class}
2128Using one of the general help classes as an argument, you can get a
5b4a1a8d
PW
2129list of the individual commands in that class. If a command has
2130aliases, the aliases are given after the command name, separated by
5b860c93
PW
2131commas. If an alias has default arguments, the full definition of
2132the alias is given after the first line.
2133For example, here is the help display for the class @code{status}:
c906108c
SS
2134
2135@smallexample
2136(@value{GDBP}) help status
2137Status inquiries.
2138
2139List of commands:
2140
2141@c Line break in "show" line falsifies real output, but needed
2142@c to fit in smallbook page size.
5b4a1a8d 2143info, inf, i -- Generic command for showing things
12c27660 2144 about the program being debugged
5b860c93
PW
2145info address, iamain -- Describe where symbol SYM is stored.
2146 alias iamain = info address main
2147info all-registers -- List of all registers and their contents,
2148 for selected stack frame.
5b4a1a8d
PW
2149...
2150show, info set -- Generic command for showing things
12c27660 2151 about the debugger
c906108c 2152
5d161b24 2153Type "help" followed by command name for full
c906108c
SS
2154documentation.
2155Command name abbreviations are allowed if unambiguous.
2156(@value{GDBP})
2157@end smallexample
2158
2159@item help @var{command}
2160With a command name as @code{help} argument, @value{GDBN} displays a
5b4a1a8d
PW
2161short paragraph on how to use that command. If that command has
2162one or more aliases, @value{GDBN} will display a first line with
2163the command name and all its aliases separated by commas.
5b860c93
PW
2164This first line will be followed by the full definition of all aliases
2165having default arguments.
c906108c 2166
6837a0a2 2167@kindex apropos
e664d728 2168@item apropos [-v] @var{regexp}
09d4efe1 2169The @code{apropos} command searches through all of the @value{GDBN}
6837a0a2 2170commands, and their documentation, for the regular expression specified in
e664d728
PW
2171@var{args}. It prints out all matches found. The optional flag @samp{-v},
2172which stands for @samp{verbose}, indicates to output the full documentation
2173of the matching commands and highlight the parts of the documentation
2174matching @var{regexp}. For example:
6837a0a2
DB
2175
2176@smallexample
16899756 2177apropos alias
6837a0a2
DB
2178@end smallexample
2179
b37052ae
EZ
2180@noindent
2181results in:
6837a0a2
DB
2182
2183@smallexample
e664d728 2184@group
16899756 2185alias -- Define a new command that is an alias of an existing command
5b860c93 2186aliases -- User-defined aliases of other commands
e664d728
PW
2187@end group
2188@end smallexample
2189
2190@noindent
2191while
2192
2193@smallexample
2194apropos -v cut.*thread apply
2195@end smallexample
2196
2197@noindent
2198results in the below output, where @samp{cut for 'thread apply}
2199is highlighted if styling is enabled.
2200
2201@smallexample
2202@group
2203taas -- Apply a command to all threads (ignoring errors
2204and empty output).
2205Usage: taas COMMAND
2206shortcut for 'thread apply all -s COMMAND'
2207
2208tfaas -- Apply a command to all frames of all threads
2209(ignoring errors and empty output).
2210Usage: tfaas COMMAND
2211shortcut for 'thread apply all -s frame apply all -s COMMAND'
2212@end group
6837a0a2
DB
2213@end smallexample
2214
c906108c
SS
2215@kindex complete
2216@item complete @var{args}
2217The @code{complete @var{args}} command lists all the possible completions
2218for the beginning of a command. Use @var{args} to specify the beginning of the
2219command you want completed. For example:
2220
2221@smallexample
2222complete i
2223@end smallexample
2224
2225@noindent results in:
2226
2227@smallexample
2228@group
2df3850c
JM
2229if
2230ignore
c906108c
SS
2231info
2232inspect
c906108c
SS
2233@end group
2234@end smallexample
2235
2236@noindent This is intended for use by @sc{gnu} Emacs.
2237@end table
2238
2239In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
2240and @code{show} to inquire about the state of your program, or the state
2241of @value{GDBN} itself. Each command supports many topics of inquiry; this
2242manual introduces each of them in the appropriate context. The listings
00595b5e
EZ
2243under @code{info} and under @code{show} in the Command, Variable, and
2244Function Index point to all the sub-commands. @xref{Command and Variable
2245Index}.
c906108c
SS
2246
2247@c @group
2248@table @code
2249@kindex info
41afff9a 2250@kindex i @r{(@code{info})}
c906108c
SS
2251@item info
2252This command (abbreviated @code{i}) is for describing the state of your
cda4ce5a 2253program. For example, you can show the arguments passed to a function
c906108c
SS
2254with @code{info args}, list the registers currently in use with @code{info
2255registers}, or list the breakpoints you have set with @code{info breakpoints}.
2256You can get a complete list of the @code{info} sub-commands with
2257@w{@code{help info}}.
2258
2259@kindex set
2260@item set
5d161b24 2261You can assign the result of an expression to an environment variable with
c906108c
SS
2262@code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
2263@code{set prompt $}.
2264
2265@kindex show
2266@item show
5d161b24 2267In contrast to @code{info}, @code{show} is for describing the state of
c906108c
SS
2268@value{GDBN} itself.
2269You can change most of the things you can @code{show}, by using the
2270related command @code{set}; for example, you can control what number
2271system is used for displays with @code{set radix}, or simply inquire
2272which is currently in use with @code{show radix}.
2273
2274@kindex info set
2275To display all the settable parameters and their current
2276values, you can use @code{show} with no arguments; you may also use
2277@code{info set}. Both commands produce the same display.
2278@c FIXME: "info set" violates the rule that "info" is for state of
2279@c FIXME...program. Ck w/ GNU: "info set" to be called something else,
2280@c FIXME...or change desc of rule---eg "state of prog and debugging session"?
2281@end table
2282@c @end group
2283
6eaaf48b 2284Here are several miscellaneous @code{show} subcommands, all of which are
c906108c
SS
2285exceptional in lacking corresponding @code{set} commands:
2286
2287@table @code
2288@kindex show version
9c16f35a 2289@cindex @value{GDBN} version number
c906108c
SS
2290@item show version
2291Show what version of @value{GDBN} is running. You should include this
2df3850c
JM
2292information in @value{GDBN} bug-reports. If multiple versions of
2293@value{GDBN} are in use at your site, you may need to determine which
2294version of @value{GDBN} you are running; as @value{GDBN} evolves, new
2295commands are introduced, and old ones may wither away. Also, many
2296system vendors ship variant versions of @value{GDBN}, and there are
96a2c332 2297variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2df3850c
JM
2298The version number is the same as the one announced when you start
2299@value{GDBN}.
c906108c
SS
2300
2301@kindex show copying
09d4efe1 2302@kindex info copying
9c16f35a 2303@cindex display @value{GDBN} copyright
c906108c 2304@item show copying
09d4efe1 2305@itemx info copying
c906108c
SS
2306Display information about permission for copying @value{GDBN}.
2307
2308@kindex show warranty
09d4efe1 2309@kindex info warranty
c906108c 2310@item show warranty
09d4efe1 2311@itemx info warranty
2df3850c 2312Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
96a2c332 2313if your version of @value{GDBN} comes with one.
2df3850c 2314
6eaaf48b
EZ
2315@kindex show configuration
2316@item show configuration
2317Display detailed information about the way @value{GDBN} was configured
2318when it was built. This displays the optional arguments passed to the
2319@file{configure} script and also configuration parameters detected
2320automatically by @command{configure}. When reporting a @value{GDBN}
2321bug (@pxref{GDB Bugs}), it is important to include this information in
2322your report.
2323
c906108c
SS
2324@end table
2325
6d2ebf8b 2326@node Running
c906108c
SS
2327@chapter Running Programs Under @value{GDBN}
2328
2329When you run a program under @value{GDBN}, you must first generate
2330debugging information when you compile it.
7a292a7a
SS
2331
2332You may start @value{GDBN} with its arguments, if any, in an environment
2333of your choice. If you are doing native debugging, you may redirect
2334your program's input and output, debug an already running process, or
2335kill a child process.
c906108c
SS
2336
2337@menu
2338* Compilation:: Compiling for debugging
2339* Starting:: Starting your program
c906108c
SS
2340* Arguments:: Your program's arguments
2341* Environment:: Your program's environment
c906108c
SS
2342
2343* Working Directory:: Your program's working directory
2344* Input/Output:: Your program's input and output
2345* Attach:: Debugging an already-running process
2346* Kill Process:: Killing the child process
65c574f6
PA
2347* Inferiors Connections and Programs:: Debugging multiple inferiors
2348 connections and programs
c906108c 2349* Threads:: Debugging programs with multiple threads
6c95b8df 2350* Forks:: Debugging forks
5c95884b 2351* Checkpoint/Restart:: Setting a @emph{bookmark} to return to later
c906108c
SS
2352@end menu
2353
6d2ebf8b 2354@node Compilation
79a6e687 2355@section Compiling for Debugging
c906108c
SS
2356
2357In order to debug a program effectively, you need to generate
2358debugging information when you compile it. This debugging information
2359is stored in the object file; it describes the data type of each
2360variable or function and the correspondence between source line numbers
2361and addresses in the executable code.
2362
2363To request debugging information, specify the @samp{-g} option when you run
2364the compiler.
2365
514c4d71 2366Programs that are to be shipped to your customers are compiled with
edb3359d 2367optimizations, using the @samp{-O} compiler option. However, some
514c4d71
EZ
2368compilers are unable to handle the @samp{-g} and @samp{-O} options
2369together. Using those compilers, you cannot generate optimized
c906108c
SS
2370executables containing debugging information.
2371
514c4d71 2372@value{NGCC}, the @sc{gnu} C/C@t{++} compiler, supports @samp{-g} with or
53a5351d
JM
2373without @samp{-O}, making it possible to debug optimized code. We
2374recommend that you @emph{always} use @samp{-g} whenever you compile a
2375program. You may think your program is correct, but there is no sense
edb3359d 2376in pushing your luck. For more information, see @ref{Optimized Code}.
c906108c
SS
2377
2378Older versions of the @sc{gnu} C compiler permitted a variant option
2379@w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
2380format; if your @sc{gnu} C compiler has this option, do not use it.
2381
514c4d71
EZ
2382@value{GDBN} knows about preprocessor macros and can show you their
2383expansion (@pxref{Macros}). Most compilers do not include information
2384about preprocessor macros in the debugging information if you specify
e0f8f636
TT
2385the @option{-g} flag alone. Version 3.1 and later of @value{NGCC},
2386the @sc{gnu} C compiler, provides macro information if you are using
2387the DWARF debugging format, and specify the option @option{-g3}.
2388
2389@xref{Debugging Options,,Options for Debugging Your Program or GCC,
f5a476a7 2390gcc, Using the @sc{gnu} Compiler Collection (GCC)}, for more
e0f8f636
TT
2391information on @value{NGCC} options affecting debug information.
2392
2393You will have the best debugging experience if you use the latest
2394version of the DWARF debugging format that your compiler supports.
2395DWARF is currently the most expressive and best supported debugging
2396format in @value{GDBN}.
514c4d71 2397
c906108c 2398@need 2000
6d2ebf8b 2399@node Starting
79a6e687 2400@section Starting your Program
c906108c
SS
2401@cindex starting
2402@cindex running
2403
2404@table @code
2405@kindex run
41afff9a 2406@kindex r @r{(@code{run})}
c906108c
SS
2407@item run
2408@itemx r
7a292a7a 2409Use the @code{run} command to start your program under @value{GDBN}.
deb8ff2b
PA
2410You must first specify the program name with an argument to
2411@value{GDBN} (@pxref{Invocation, ,Getting In and Out of
2412@value{GDBN}}), or by using the @code{file} or @code{exec-file}
2413command (@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
2414
2415@end table
2416
c906108c
SS
2417If you are running your program in an execution environment that
2418supports processes, @code{run} creates an inferior process and makes
8edfe269
DJ
2419that process run your program. In some environments without processes,
2420@code{run} jumps to the start of your program. Other targets,
2421like @samp{remote}, are always running. If you get an error
2422message like this one:
2423
2424@smallexample
2425The "remote" target does not support "run".
2426Try "help target" or "continue".
2427@end smallexample
2428
2429@noindent
2430then use @code{continue} to run your program. You may need @code{load}
2431first (@pxref{load}).
c906108c
SS
2432
2433The execution of a program is affected by certain information it
2434receives from its superior. @value{GDBN} provides ways to specify this
2435information, which you must do @emph{before} starting your program. (You
2436can change it after starting your program, but such changes only affect
2437your program the next time you start it.) This information may be
2438divided into four categories:
2439
2440@table @asis
2441@item The @emph{arguments.}
2442Specify the arguments to give your program as the arguments of the
2443@code{run} command. If a shell is available on your target, the shell
2444is used to pass the arguments, so that you may use normal conventions
2445(such as wildcard expansion or variable substitution) in describing
2446the arguments.
2447In Unix systems, you can control which shell is used with the
98882a26
PA
2448@code{SHELL} environment variable. If you do not define @code{SHELL},
2449@value{GDBN} uses the default shell (@file{/bin/sh}). You can disable
2450use of any shell with the @code{set startup-with-shell} command (see
2451below for details).
c906108c
SS
2452
2453@item The @emph{environment.}
2454Your program normally inherits its environment from @value{GDBN}, but you can
2455use the @value{GDBN} commands @code{set environment} and @code{unset
2456environment} to change parts of the environment that affect
79a6e687 2457your program. @xref{Environment, ,Your Program's Environment}.
c906108c
SS
2458
2459@item The @emph{working directory.}
d092c5a2
SDJ
2460You can set your program's working directory with the command
2461@kbd{set cwd}. If you do not set any working directory with this
bc3b087d
SDJ
2462command, your program will inherit @value{GDBN}'s working directory if
2463native debugging, or the remote server's working directory if remote
2464debugging. @xref{Working Directory, ,Your Program's Working
2465Directory}.
c906108c
SS
2466
2467@item The @emph{standard input and output.}
2468Your program normally uses the same device for standard input and
2469standard output as @value{GDBN} is using. You can redirect input and output
2470in the @code{run} command line, or you can use the @code{tty} command to
2471set a different device for your program.
79a6e687 2472@xref{Input/Output, ,Your Program's Input and Output}.
c906108c
SS
2473
2474@cindex pipes
2475@emph{Warning:} While input and output redirection work, you cannot use
2476pipes to pass the output of the program you are debugging to another
2477program; if you attempt this, @value{GDBN} is likely to wind up debugging the
2478wrong program.
2479@end table
c906108c
SS
2480
2481When you issue the @code{run} command, your program begins to execute
79a6e687 2482immediately. @xref{Stopping, ,Stopping and Continuing}, for discussion
c906108c
SS
2483of how to arrange for your program to stop. Once your program has
2484stopped, you may call functions in your program, using the @code{print}
2485or @code{call} commands. @xref{Data, ,Examining Data}.
2486
2487If the modification time of your symbol file has changed since the last
2488time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
2489table, and reads it again. When it does this, @value{GDBN} tries to retain
2490your current breakpoints.
2491
4e8b0763
JB
2492@table @code
2493@kindex start
2494@item start
2495@cindex run to main procedure
2496The name of the main procedure can vary from language to language.
2497With C or C@t{++}, the main procedure name is always @code{main}, but
2498other languages such as Ada do not require a specific name for their
2499main procedure. The debugger provides a convenient way to start the
2500execution of the program and to stop at the beginning of the main
2501procedure, depending on the language used.
2502
2503The @samp{start} command does the equivalent of setting a temporary
2504breakpoint at the beginning of the main procedure and then invoking
2505the @samp{run} command.
2506
f018e82f
EZ
2507@cindex elaboration phase
2508Some programs contain an @dfn{elaboration} phase where some startup code is
2509executed before the main procedure is called. This depends on the
2510languages used to write your program. In C@t{++}, for instance,
4e8b0763
JB
2511constructors for static and global objects are executed before
2512@code{main} is called. It is therefore possible that the debugger stops
2513before reaching the main procedure. However, the temporary breakpoint
2514will remain to halt execution.
2515
2516Specify the arguments to give to your program as arguments to the
2517@samp{start} command. These arguments will be given verbatim to the
2518underlying @samp{run} command. Note that the same arguments will be
2519reused if no argument is provided during subsequent calls to
2520@samp{start} or @samp{run}.
2521
2522It is sometimes necessary to debug the program during elaboration. In
4e5a4f58
JB
2523these cases, using the @code{start} command would stop the execution
2524of your program too late, as the program would have already completed
2525the elaboration phase. Under these circumstances, either insert
2526breakpoints in your elaboration code before running your program or
2527use the @code{starti} command.
2528
2529@kindex starti
2530@item starti
2531@cindex run to first instruction
2532The @samp{starti} command does the equivalent of setting a temporary
2533breakpoint at the first instruction of a program's execution and then
2534invoking the @samp{run} command. For programs containing an
2535elaboration phase, the @code{starti} command will stop execution at
2536the start of the elaboration phase.
ccd213ac 2537
41ef2965 2538@anchor{set exec-wrapper}
ccd213ac
DJ
2539@kindex set exec-wrapper
2540@item set exec-wrapper @var{wrapper}
2541@itemx show exec-wrapper
2542@itemx unset exec-wrapper
2543When @samp{exec-wrapper} is set, the specified wrapper is used to
2544launch programs for debugging. @value{GDBN} starts your program
2545with a shell command of the form @kbd{exec @var{wrapper}
2546@var{program}}. Quoting is added to @var{program} and its
2547arguments, but not to @var{wrapper}, so you should add quotes if
2548appropriate for your shell. The wrapper runs until it executes
2549your program, and then @value{GDBN} takes control.
2550
2551You can use any program that eventually calls @code{execve} with
2552its arguments as a wrapper. Several standard Unix utilities do
2553this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
2554with @code{exec "$@@"} will also work.
2555
2556For example, you can use @code{env} to pass an environment variable to
2557the debugged program, without setting the variable in your shell's
2558environment:
2559
2560@smallexample
2561(@value{GDBP}) set exec-wrapper env 'LD_PRELOAD=libtest.so'
2562(@value{GDBP}) run
2563@end smallexample
2564
2565This command is available when debugging locally on most targets, excluding
2566@sc{djgpp}, Cygwin, MS Windows, and QNX Neutrino.
2567
98882a26 2568@kindex set startup-with-shell
aefd8b33 2569@anchor{set startup-with-shell}
98882a26
PA
2570@item set startup-with-shell
2571@itemx set startup-with-shell on
2572@itemx set startup-with-shell off
ca145713 2573@itemx show startup-with-shell
98882a26
PA
2574On Unix systems, by default, if a shell is available on your target,
2575@value{GDBN}) uses it to start your program. Arguments of the
2576@code{run} command are passed to the shell, which does variable
2577substitution, expands wildcard characters and performs redirection of
2578I/O. In some circumstances, it may be useful to disable such use of a
2579shell, for example, when debugging the shell itself or diagnosing
2580startup failures such as:
2581
2582@smallexample
2583(@value{GDBP}) run
2584Starting program: ./a.out
2585During startup program terminated with signal SIGSEGV, Segmentation fault.
2586@end smallexample
2587
2588@noindent
2589which indicates the shell or the wrapper specified with
2590@samp{exec-wrapper} crashed, not your program. Most often, this is
afa332ce
PA
2591caused by something odd in your shell's non-interactive mode
2592initialization file---such as @file{.cshrc} for C-shell,
2593$@file{.zshenv} for the Z shell, or the file specified in the
2594@samp{BASH_ENV} environment variable for BASH.
98882a26 2595
6a3cb8e8
PA
2596@anchor{set auto-connect-native-target}
2597@kindex set auto-connect-native-target
2598@item set auto-connect-native-target
2599@itemx set auto-connect-native-target on
2600@itemx set auto-connect-native-target off
2601@itemx show auto-connect-native-target
2602
65c574f6
PA
2603By default, if the current inferior is not connected to any target yet
2604(e.g., with @code{target remote}), the @code{run} command starts your
2605program as a native process under @value{GDBN}, on your local machine.
2606If you're sure you don't want to debug programs on your local machine,
2607you can tell @value{GDBN} to not connect to the native target
2608automatically with the @code{set auto-connect-native-target off}
2609command.
6a3cb8e8 2610
65c574f6 2611If @code{on}, which is the default, and if the current inferior is not
6a3cb8e8
PA
2612connected to a target already, the @code{run} command automaticaly
2613connects to the native target, if one is available.
2614
65c574f6
PA
2615If @code{off}, and if the current inferior is not connected to a
2616target already, the @code{run} command fails with an error:
6a3cb8e8
PA
2617
2618@smallexample
2619(@value{GDBP}) run
2620Don't know how to run. Try "help target".
2621@end smallexample
2622
65c574f6
PA
2623If the current inferior is already connected to a target, @value{GDBN}
2624always uses it with the @code{run} command.
6a3cb8e8
PA
2625
2626In any case, you can explicitly connect to the native target with the
2627@code{target native} command. For example,
2628
2629@smallexample
2630(@value{GDBP}) set auto-connect-native-target off
2631(@value{GDBP}) run
2632Don't know how to run. Try "help target".
2633(@value{GDBP}) target native
2634(@value{GDBP}) run
2635Starting program: ./a.out
2636[Inferior 1 (process 10421) exited normally]
2637@end smallexample
2638
2639In case you connected explicitly to the @code{native} target,
2640@value{GDBN} remains connected even if all inferiors exit, ready for
2641the next @code{run} command. Use the @code{disconnect} command to
2642disconnect.
2643
2644Examples of other commands that likewise respect the
2645@code{auto-connect-native-target} setting: @code{attach}, @code{info
2646proc}, @code{info os}.
2647
10568435
JK
2648@kindex set disable-randomization
2649@item set disable-randomization
2650@itemx set disable-randomization on
2651This option (enabled by default in @value{GDBN}) will turn off the native
2652randomization of the virtual address space of the started program. This option
2653is useful for multiple debugging sessions to make the execution better
2654reproducible and memory addresses reusable across debugging sessions.
2655
03583c20
UW
2656This feature is implemented only on certain targets, including @sc{gnu}/Linux.
2657On @sc{gnu}/Linux you can get the same behavior using
10568435
JK
2658
2659@smallexample
2660(@value{GDBP}) set exec-wrapper setarch `uname -m` -R
2661@end smallexample
2662
2663@item set disable-randomization off
2664Leave the behavior of the started executable unchanged. Some bugs rear their
2665ugly heads only when the program is loaded at certain addresses. If your bug
2666disappears when you run the program under @value{GDBN}, that might be because
2667@value{GDBN} by default disables the address randomization on platforms, such
2668as @sc{gnu}/Linux, which do that for stand-alone programs. Use @kbd{set
2669disable-randomization off} to try to reproduce such elusive bugs.
2670
03583c20
UW
2671On targets where it is available, virtual address space randomization
2672protects the programs against certain kinds of security attacks. In these
10568435
JK
2673cases the attacker needs to know the exact location of a concrete executable
2674code. Randomizing its location makes it impossible to inject jumps misusing
2675a code at its expected addresses.
2676
2677Prelinking shared libraries provides a startup performance advantage but it
2678makes addresses in these libraries predictable for privileged processes by
2679having just unprivileged access at the target system. Reading the shared
2680library binary gives enough information for assembling the malicious code
2681misusing it. Still even a prelinked shared library can get loaded at a new
2682random address just requiring the regular relocation process during the
2683startup. Shared libraries not already prelinked are always loaded at
2684a randomly chosen address.
2685
2686Position independent executables (PIE) contain position independent code
2687similar to the shared libraries and therefore such executables get loaded at
2688a randomly chosen address upon startup. PIE executables always load even
2689already prelinked shared libraries at a random address. You can build such
2690executable using @command{gcc -fPIE -pie}.
2691
2692Heap (malloc storage), stack and custom mmap areas are always placed randomly
2693(as long as the randomization is enabled).
2694
2695@item show disable-randomization
2696Show the current setting of the explicit disable of the native randomization of
2697the virtual address space of the started program.
2698
4e8b0763
JB
2699@end table
2700
6d2ebf8b 2701@node Arguments
79a6e687 2702@section Your Program's Arguments
c906108c
SS
2703
2704@cindex arguments (to your program)
2705The arguments to your program can be specified by the arguments of the
5d161b24 2706@code{run} command.
c906108c
SS
2707They are passed to a shell, which expands wildcard characters and
2708performs redirection of I/O, and thence to your program. Your
2709@code{SHELL} environment variable (if it exists) specifies what shell
2710@value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
d4f3574e
SS
2711the default shell (@file{/bin/sh} on Unix).
2712
2713On non-Unix systems, the program is usually invoked directly by
2714@value{GDBN}, which emulates I/O redirection via the appropriate system
2715calls, and the wildcard characters are expanded by the startup code of
2716the program, not by the shell.
c906108c
SS
2717
2718@code{run} with no arguments uses the same arguments used by the previous
2719@code{run}, or those set by the @code{set args} command.
2720
c906108c 2721@table @code
41afff9a 2722@kindex set args
c906108c
SS
2723@item set args
2724Specify the arguments to be used the next time your program is run. If
2725@code{set args} has no arguments, @code{run} executes your program
2726with no arguments. Once you have run your program with arguments,
2727using @code{set args} before the next @code{run} is the only way to run
2728it again without arguments.
2729
2730@kindex show args
2731@item show args
2732Show the arguments to give your program when it is started.
2733@end table
2734
6d2ebf8b 2735@node Environment
79a6e687 2736@section Your Program's Environment
c906108c
SS
2737
2738@cindex environment (of your program)
2739The @dfn{environment} consists of a set of environment variables and
2740their values. Environment variables conventionally record such things as
2741your user name, your home directory, your terminal type, and your search
2742path for programs to run. Usually you set up environment variables with
2743the shell and they are inherited by all the other programs you run. When
2744debugging, it can be useful to try running your program with a modified
2745environment without having to start @value{GDBN} over again.
2746
2747@table @code
2748@kindex path
2749@item path @var{directory}
2750Add @var{directory} to the front of the @code{PATH} environment variable
17cc6a06
EZ
2751(the search path for executables) that will be passed to your program.
2752The value of @code{PATH} used by @value{GDBN} does not change.
d4f3574e
SS
2753You may specify several directory names, separated by whitespace or by a
2754system-dependent separator character (@samp{:} on Unix, @samp{;} on
2755MS-DOS and MS-Windows). If @var{directory} is already in the path, it
2756is moved to the front, so it is searched sooner.
c906108c
SS
2757
2758You can use the string @samp{$cwd} to refer to whatever is the current
2759working directory at the time @value{GDBN} searches the path. If you
2760use @samp{.} instead, it refers to the directory where you executed the
2761@code{path} command. @value{GDBN} replaces @samp{.} in the
2762@var{directory} argument (with the current path) before adding
2763@var{directory} to the search path.
2764@c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
2765@c document that, since repeating it would be a no-op.
2766
2767@kindex show paths
2768@item show paths
2769Display the list of search paths for executables (the @code{PATH}
2770environment variable).
2771
2772@kindex show environment
2773@item show environment @r{[}@var{varname}@r{]}
2774Print the value of environment variable @var{varname} to be given to
2775your program when it starts. If you do not supply @var{varname},
2776print the names and values of all environment variables to be given to
2777your program. You can abbreviate @code{environment} as @code{env}.
2778
2779@kindex set environment
0a2dde4a 2780@anchor{set environment}
53a5351d 2781@item set environment @var{varname} @r{[}=@var{value}@r{]}
c906108c 2782Set environment variable @var{varname} to @var{value}. The value
41ef2965 2783changes for your program (and the shell @value{GDBN} uses to launch
697aa1b7 2784it), not for @value{GDBN} itself. The @var{value} may be any string; the
41ef2965
PA
2785values of environment variables are just strings, and any
2786interpretation is supplied by your program itself. The @var{value}
c906108c
SS
2787parameter is optional; if it is eliminated, the variable is set to a
2788null value.
2789@c "any string" here does not include leading, trailing
2790@c blanks. Gnu asks: does anyone care?
2791
2792For example, this command:
2793
474c8240 2794@smallexample
c906108c 2795set env USER = foo
474c8240 2796@end smallexample
c906108c
SS
2797
2798@noindent
d4f3574e 2799tells the debugged program, when subsequently run, that its user is named
c906108c
SS
2800@samp{foo}. (The spaces around @samp{=} are used for clarity here; they
2801are not actually required.)
2802
41ef2965
PA
2803Note that on Unix systems, @value{GDBN} runs your program via a shell,
2804which also inherits the environment set with @code{set environment}.
2805If necessary, you can avoid that by using the @samp{env} program as a
2806wrapper instead of using @code{set environment}. @xref{set
2807exec-wrapper}, for an example doing just that.
2808
0a2dde4a
SDJ
2809Environment variables that are set by the user are also transmitted to
2810@command{gdbserver} to be used when starting the remote inferior.
2811@pxref{QEnvironmentHexEncoded}.
2812
c906108c 2813@kindex unset environment
0a2dde4a 2814@anchor{unset environment}
c906108c
SS
2815@item unset environment @var{varname}
2816Remove variable @var{varname} from the environment to be passed to your
2817program. This is different from @samp{set env @var{varname} =};
2818@code{unset environment} removes the variable from the environment,
2819rather than assigning it an empty value.
0a2dde4a
SDJ
2820
2821Environment variables that are unset by the user are also unset on
2822@command{gdbserver} when starting the remote inferior.
2823@pxref{QEnvironmentUnset}.
c906108c
SS
2824@end table
2825
d4f3574e 2826@emph{Warning:} On Unix systems, @value{GDBN} runs your program using
afa332ce
PA
2827the shell indicated by your @code{SHELL} environment variable if it
2828exists (or @code{/bin/sh} if not). If your @code{SHELL} variable
2829names a shell that runs an initialization file when started
2830non-interactively---such as @file{.cshrc} for C-shell, $@file{.zshenv}
2831for the Z shell, or the file specified in the @samp{BASH_ENV}
2832environment variable for BASH---any variables you set in that file
2833affect your program. You may wish to move setting of environment
2834variables to files that are only run when you sign on, such as
2835@file{.login} or @file{.profile}.
c906108c 2836
6d2ebf8b 2837@node Working Directory
79a6e687 2838@section Your Program's Working Directory
c906108c
SS
2839
2840@cindex working directory (of your program)
d092c5a2
SDJ
2841Each time you start your program with @code{run}, the inferior will be
2842initialized with the current working directory specified by the
2843@kbd{set cwd} command. If no directory has been specified by this
2844command, then the inferior will inherit @value{GDBN}'s current working
bc3b087d
SDJ
2845directory as its working directory if native debugging, or it will
2846inherit the remote server's current working directory if remote
2847debugging.
c906108c
SS
2848
2849@table @code
d092c5a2
SDJ
2850@kindex set cwd
2851@cindex change inferior's working directory
2852@anchor{set cwd command}
2853@item set cwd @r{[}@var{directory}@r{]}
2854Set the inferior's working directory to @var{directory}, which will be
2855@code{glob}-expanded in order to resolve tildes (@file{~}). If no
2856argument has been specified, the command clears the setting and resets
2857it to an empty state. This setting has no effect on @value{GDBN}'s
2858working directory, and it only takes effect the next time you start
2859the inferior. The @file{~} in @var{directory} is a short for the
2860@dfn{home directory}, usually pointed to by the @env{HOME} environment
2861variable. On MS-Windows, if @env{HOME} is not defined, @value{GDBN}
2862uses the concatenation of @env{HOMEDRIVE} and @env{HOMEPATH} as
2863fallback.
2864
2865You can also change @value{GDBN}'s current working directory by using
2866the @code{cd} command.
dbfa4523 2867@xref{cd command}.
d092c5a2
SDJ
2868
2869@kindex show cwd
2870@cindex show inferior's working directory
2871@item show cwd
2872Show the inferior's working directory. If no directory has been
2873specified by @kbd{set cwd}, then the default inferior's working
2874directory is the same as @value{GDBN}'s working directory.
2875
c906108c 2876@kindex cd
d092c5a2
SDJ
2877@cindex change @value{GDBN}'s working directory
2878@anchor{cd command}
f3c8a52a
JK
2879@item cd @r{[}@var{directory}@r{]}
2880Set the @value{GDBN} working directory to @var{directory}. If not
2881given, @var{directory} uses @file{'~'}.
c906108c 2882
d092c5a2
SDJ
2883The @value{GDBN} working directory serves as a default for the
2884commands that specify files for @value{GDBN} to operate on.
2885@xref{Files, ,Commands to Specify Files}.
dbfa4523 2886@xref{set cwd command}.
d092c5a2 2887
c906108c
SS
2888@kindex pwd
2889@item pwd
2890Print the @value{GDBN} working directory.
2891@end table
2892
60bf7e09
EZ
2893It is generally impossible to find the current working directory of
2894the process being debugged (since a program can change its directory
2d97a5d9 2895during its run). If you work on a system where @value{GDBN} supports
754452f0 2896the @code{info proc} command (@pxref{Process Information}), you can
2d97a5d9 2897use the @code{info proc} command to find out the
60bf7e09
EZ
2898current working directory of the debuggee.
2899
6d2ebf8b 2900@node Input/Output
79a6e687 2901@section Your Program's Input and Output
c906108c
SS
2902
2903@cindex redirection
2904@cindex i/o
2905@cindex terminal
2906By default, the program you run under @value{GDBN} does input and output to
5d161b24 2907the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
c906108c
SS
2908to its own terminal modes to interact with you, but it records the terminal
2909modes your program was using and switches back to them when you continue
2910running your program.
2911
2912@table @code
2913@kindex info terminal
2914@item info terminal
2915Displays information recorded by @value{GDBN} about the terminal modes your
2916program is using.
2917@end table
2918
2919You can redirect your program's input and/or output using shell
2920redirection with the @code{run} command. For example,
2921
474c8240 2922@smallexample
c906108c 2923run > outfile
474c8240 2924@end smallexample
c906108c
SS
2925
2926@noindent
2927starts your program, diverting its output to the file @file{outfile}.
2928
2929@kindex tty
2930@cindex controlling terminal
2931Another way to specify where your program should do input and output is
2932with the @code{tty} command. This command accepts a file name as
2933argument, and causes this file to be the default for future @code{run}
2934commands. It also resets the controlling terminal for the child
2935process, for future @code{run} commands. For example,
2936
474c8240 2937@smallexample
c906108c 2938tty /dev/ttyb
474c8240 2939@end smallexample
c906108c
SS
2940
2941@noindent
2942directs that processes started with subsequent @code{run} commands
2943default to do input and output on the terminal @file{/dev/ttyb} and have
2944that as their controlling terminal.
2945
2946An explicit redirection in @code{run} overrides the @code{tty} command's
2947effect on the input/output device, but not its effect on the controlling
2948terminal.
2949
2950When you use the @code{tty} command or redirect input in the @code{run}
2951command, only the input @emph{for your program} is affected. The input
3cb3b8df
BR
2952for @value{GDBN} still comes from your terminal. @code{tty} is an alias
2953for @code{set inferior-tty}.
2954
2955@cindex inferior tty
2956@cindex set inferior controlling terminal
2957You can use the @code{show inferior-tty} command to tell @value{GDBN} to
2958display the name of the terminal that will be used for future runs of your
2959program.
2960
2961@table @code
0a1ddfa6 2962@item set inferior-tty [ @var{tty} ]
3cb3b8df 2963@kindex set inferior-tty
0a1ddfa6
SM
2964Set the tty for the program being debugged to @var{tty}. Omitting @var{tty}
2965restores the default behavior, which is to use the same terminal as
2966@value{GDBN}.
3cb3b8df
BR
2967
2968@item show inferior-tty
2969@kindex show inferior-tty
2970Show the current tty for the program being debugged.
2971@end table
c906108c 2972
6d2ebf8b 2973@node Attach
79a6e687 2974@section Debugging an Already-running Process
c906108c
SS
2975@kindex attach
2976@cindex attach
2977
2978@table @code
2979@item attach @var{process-id}
2980This command attaches to a running process---one that was started
2981outside @value{GDBN}. (@code{info files} shows your active
2982targets.) The command takes as argument a process ID. The usual way to
09d4efe1 2983find out the @var{process-id} of a Unix process is with the @code{ps} utility,
c906108c
SS
2984or with the @samp{jobs -l} shell command.
2985
2986@code{attach} does not repeat if you press @key{RET} a second time after
2987executing the command.
2988@end table
2989
2990To use @code{attach}, your program must be running in an environment
2991which supports processes; for example, @code{attach} does not work for
2992programs on bare-board targets that lack an operating system. You must
2993also have permission to send the process a signal.
2994
2995When you use @code{attach}, the debugger finds the program running in
2996the process first by looking in the current working directory, then (if
2997the program is not found) by using the source file search path
79a6e687 2998(@pxref{Source Path, ,Specifying Source Directories}). You can also use
c906108c
SS
2999the @code{file} command to load the program. @xref{Files, ,Commands to
3000Specify Files}.
3001
e47e48f6 3002@anchor{set exec-file-mismatch}
98c59b52
PA
3003If the debugger can determine that the executable file running in the
3004process it is attaching to does not match the current exec-file loaded
3005by @value{GDBN}, the option @code{exec-file-mismatch} specifies how to
3006handle the mismatch. @value{GDBN} tries to compare the files by
3007comparing their build IDs (@pxref{build ID}), if available.
e47e48f6
PW
3008
3009@table @code
3010@kindex exec-file-mismatch
3011@cindex set exec-file-mismatch
3012@item set exec-file-mismatch @samp{ask|warn|off}
3013
98c59b52
PA
3014Whether to detect mismatch between the current executable file loaded
3015by @value{GDBN} and the executable file used to start the process. If
3016@samp{ask}, the default, display a warning and ask the user whether to
3017load the process executable file; if @samp{warn}, just display a
3018warning; if @samp{off}, don't attempt to detect a mismatch.
e47e48f6
PW
3019
3020@cindex show exec-file-mismatch
3021@item show exec-file-mismatch
3022Show the current value of @code{exec-file-mismatch}.
3023
3024@end table
3025
c906108c
SS
3026The first thing @value{GDBN} does after arranging to debug the specified
3027process is to stop it. You can examine and modify an attached process
53a5351d
JM
3028with all the @value{GDBN} commands that are ordinarily available when
3029you start processes with @code{run}. You can insert breakpoints; you
3030can step and continue; you can modify storage. If you would rather the
3031process continue running, you may use the @code{continue} command after
c906108c
SS
3032attaching @value{GDBN} to the process.
3033
3034@table @code
3035@kindex detach
3036@item detach
3037When you have finished debugging the attached process, you can use the
3038@code{detach} command to release it from @value{GDBN} control. Detaching
3039the process continues its execution. After the @code{detach} command,
3040that process and @value{GDBN} become completely independent once more, and you
3041are ready to @code{attach} another process or start one with @code{run}.
3042@code{detach} does not repeat if you press @key{RET} again after
3043executing the command.
3044@end table
3045
159fcc13
JK
3046If you exit @value{GDBN} while you have an attached process, you detach
3047that process. If you use the @code{run} command, you kill that process.
3048By default, @value{GDBN} asks for confirmation if you try to do either of these
3049things; you can control whether or not you need to confirm by using the
3050@code{set confirm} command (@pxref{Messages/Warnings, ,Optional Warnings and
79a6e687 3051Messages}).
c906108c 3052
6d2ebf8b 3053@node Kill Process
79a6e687 3054@section Killing the Child Process
c906108c
SS
3055
3056@table @code
3057@kindex kill
3058@item kill
3059Kill the child process in which your program is running under @value{GDBN}.
3060@end table
3061
3062This command is useful if you wish to debug a core dump instead of a
3063running process. @value{GDBN} ignores any core dump file while your program
3064is running.
3065
3066On some operating systems, a program cannot be executed outside @value{GDBN}
3067while you have breakpoints set on it inside @value{GDBN}. You can use the
3068@code{kill} command in this situation to permit running your program
3069outside the debugger.
3070
3071The @code{kill} command is also useful if you wish to recompile and
3072relink your program, since on many systems it is impossible to modify an
3073executable file while it is running in a process. In this case, when you
3074next type @code{run}, @value{GDBN} notices that the file has changed, and
3075reads the symbol table again (while trying to preserve your current
3076breakpoint settings).
3077
65c574f6
PA
3078@node Inferiors Connections and Programs
3079@section Debugging Multiple Inferiors Connections and Programs
b77209e0 3080
6c95b8df
PA
3081@value{GDBN} lets you run and debug multiple programs in a single
3082session. In addition, @value{GDBN} on some systems may let you run
3083several programs simultaneously (otherwise you have to exit from one
65c574f6
PA
3084before starting another). On some systems @value{GDBN} may even let
3085you debug several programs simultaneously on different remote systems.
3086In the most general case, you can have multiple threads of execution
3087in each of multiple processes, launched from multiple executables,
3088running on different machines.
b77209e0
PA
3089
3090@cindex inferior
3091@value{GDBN} represents the state of each program execution with an
3092object called an @dfn{inferior}. An inferior typically corresponds to
3093a process, but is more general and applies also to targets that do not
3094have processes. Inferiors may be created before a process runs, and
6c95b8df
PA
3095may be retained after a process exits. Inferiors have unique
3096identifiers that are different from process ids. Usually each
3097inferior will also have its own distinct address space, although some
3098embedded targets may have several inferiors running in different parts
3099of a single address space. Each inferior may in turn have multiple
3100threads running in it.
b77209e0 3101
6c95b8df
PA
3102To find out what inferiors exist at any moment, use @w{@code{info
3103inferiors}}:
b77209e0
PA
3104
3105@table @code
a3c25011 3106@kindex info inferiors [ @var{id}@dots{} ]
b77209e0
PA
3107@item info inferiors
3108Print a list of all inferiors currently being managed by @value{GDBN}.
a3c25011
TT
3109By default all inferiors are printed, but the argument @var{id}@dots{}
3110-- a space separated list of inferior numbers -- can be used to limit
3111the display to just the requested inferiors.
3a1ff0b6
PA
3112
3113@value{GDBN} displays for each inferior (in this order):
3114
3115@enumerate
3116@item
3117the inferior number assigned by @value{GDBN}
3118
3119@item
3120the target system's inferior identifier
6c95b8df 3121
65c574f6
PA
3122@item
3123the target connection the inferior is bound to, including the unique
3124connection number assigned by @value{GDBN}, and the protocol used by
3125the connection.
3126
6c95b8df
PA
3127@item
3128the name of the executable the inferior is running.
3129
3a1ff0b6
PA
3130@end enumerate
3131
3132@noindent
3133An asterisk @samp{*} preceding the @value{GDBN} inferior number
3134indicates the current inferior.
3135
3136For example,
2277426b 3137@end table
3a1ff0b6
PA
3138@c end table here to get a little more width for example
3139
3140@smallexample
3141(@value{GDBP}) info inferiors
65c574f6
PA
3142 Num Description Connection Executable
3143* 1 process 3401 1 (native) goodbye
3144 2 process 2307 2 (extended-remote host:10000) hello
3145@end smallexample
3146
3147To find out what open target connections exist at any moment, use
3148@w{@code{info connections}}:
3149
3150@table @code
3151@kindex info connections [ @var{id}@dots{} ]
3152@item info connections
3153Print a list of all open target connections currently being managed by
3154@value{GDBN}. By default all connections are printed, but the
3155argument @var{id}@dots{} -- a space separated list of connections
3156numbers -- can be used to limit the display to just the requested
3157connections.
3158
3159@value{GDBN} displays for each connection (in this order):
3160
3161@enumerate
3162@item
3163the connection number assigned by @value{GDBN}.
3164
3165@item
3166the protocol used by the connection.
3167
3168@item
3169a textual description of the protocol used by the connection.
3170
3171@end enumerate
3172
3173@noindent
3174An asterisk @samp{*} preceding the connection number indicates the
3175connection of the current inferior.
3176
3177For example,
3178@end table
3179@c end table here to get a little more width for example
3180
3181@smallexample
3182(@value{GDBP}) info connections
3183 Num What Description
3184* 1 extended-remote host:10000 Extended remote serial target in gdb-specific protocol
3185 2 native Native process
3186 3 core Local core dump file
3a1ff0b6 3187@end smallexample
2277426b
PA
3188
3189To switch focus between inferiors, use the @code{inferior} command:
3190
3191@table @code
3a1ff0b6
PA
3192@kindex inferior @var{infno}
3193@item inferior @var{infno}
3194Make inferior number @var{infno} the current inferior. The argument
3195@var{infno} is the inferior number assigned by @value{GDBN}, as shown
3196in the first field of the @samp{info inferiors} display.
2277426b
PA
3197@end table
3198
e3940304
PA
3199@vindex $_inferior@r{, convenience variable}
3200The debugger convenience variable @samp{$_inferior} contains the
3201number of the current inferior. You may find this useful in writing
3202breakpoint conditional expressions, command scripts, and so forth.
3203@xref{Convenience Vars,, Convenience Variables}, for general
3204information on convenience variables.
6c95b8df
PA
3205
3206You can get multiple executables into a debugging session via the
3207@code{add-inferior} and @w{@code{clone-inferior}} commands. On some
3208systems @value{GDBN} can add inferiors to the debug session
3209automatically by following calls to @code{fork} and @code{exec}. To
3210remove inferiors from the debugging session use the
af624141 3211@w{@code{remove-inferiors}} command.
6c95b8df
PA
3212
3213@table @code
3214@kindex add-inferior
65c574f6 3215@item add-inferior [ -copies @var{n} ] [ -exec @var{executable} ] [-no-connection ]
6c95b8df 3216Adds @var{n} inferiors to be run using @var{executable} as the
697aa1b7 3217executable; @var{n} defaults to 1. If no executable is specified,
6c95b8df
PA
3218the inferiors begins empty, with no program. You can still assign or
3219change the program assigned to the inferior at any time by using the
3220@code{file} command with the executable name as its argument.
3221
65c574f6
PA
3222By default, the new inferior begins connected to the same target
3223connection as the current inferior. For example, if the current
3224inferior was connected to @code{gdbserver} with @code{target remote},
3225then the new inferior will be connected to the same @code{gdbserver}
3226instance. The @samp{-no-connection} option starts the new inferior
3227with no connection yet. You can then for example use the @code{target
3228remote} command to connect to some other @code{gdbserver} instance,
3229use @code{run} to spawn a local program, etc.
3230
6c95b8df
PA
3231@kindex clone-inferior
3232@item clone-inferior [ -copies @var{n} ] [ @var{infno} ]
3233Adds @var{n} inferiors ready to execute the same program as inferior
697aa1b7 3234@var{infno}; @var{n} defaults to 1, and @var{infno} defaults to the
6c95b8df
PA
3235number of the current inferior. This is a convenient command when you
3236want to run another instance of the inferior you are debugging.
3237
3238@smallexample
3239(@value{GDBP}) info inferiors
65c574f6
PA
3240 Num Description Connection Executable
3241* 1 process 29964 1 (native) helloworld
6c95b8df
PA
3242(@value{GDBP}) clone-inferior
3243Added inferior 2.
32441 inferiors added.
3245(@value{GDBP}) info inferiors
65c574f6
PA
3246 Num Description Connection Executable
3247* 1 process 29964 1 (native) helloworld
3248 2 <null> 1 (native) helloworld
6c95b8df
PA
3249@end smallexample
3250
3251You can now simply switch focus to inferior 2 and run it.
3252
af624141
MS
3253@kindex remove-inferiors
3254@item remove-inferiors @var{infno}@dots{}
3255Removes the inferior or inferiors @var{infno}@dots{}. It is not
3256possible to remove an inferior that is running with this command. For
3257those, use the @code{kill} or @code{detach} command first.
6c95b8df
PA
3258
3259@end table
3260
3261To quit debugging one of the running inferiors that is not the current
3262inferior, you can either detach from it by using the @w{@code{detach
3263inferior}} command (allowing it to run independently), or kill it
af624141 3264using the @w{@code{kill inferiors}} command:
2277426b
PA
3265
3266@table @code
af624141
MS
3267@kindex detach inferiors @var{infno}@dots{}
3268@item detach inferior @var{infno}@dots{}
3269Detach from the inferior or inferiors identified by @value{GDBN}
5e30da2c 3270inferior number(s) @var{infno}@dots{}. Note that the inferior's entry
af624141
MS
3271still stays on the list of inferiors shown by @code{info inferiors},
3272but its Description will show @samp{<null>}.
3273
3274@kindex kill inferiors @var{infno}@dots{}
3275@item kill inferiors @var{infno}@dots{}
3276Kill the inferior or inferiors identified by @value{GDBN} inferior
3277number(s) @var{infno}@dots{}. Note that the inferior's entry still
3278stays on the list of inferiors shown by @code{info inferiors}, but its
3279Description will show @samp{<null>}.
2277426b
PA
3280@end table
3281
6c95b8df 3282After the successful completion of a command such as @code{detach},
af624141 3283@code{detach inferiors}, @code{kill} or @code{kill inferiors}, or after
6c95b8df
PA
3284a normal process exit, the inferior is still valid and listed with
3285@code{info inferiors}, ready to be restarted.
3286
3287
2277426b
PA
3288To be notified when inferiors are started or exit under @value{GDBN}'s
3289control use @w{@code{set print inferior-events}}:
b77209e0 3290
2277426b 3291@table @code
b77209e0
PA
3292@kindex set print inferior-events
3293@cindex print messages on inferior start and exit
3294@item set print inferior-events
3295@itemx set print inferior-events on
3296@itemx set print inferior-events off
3297The @code{set print inferior-events} command allows you to enable or
3298disable printing of messages when @value{GDBN} notices that new
3299inferiors have started or that inferiors have exited or have been
3300detached. By default, these messages will not be printed.
3301
3302@kindex show print inferior-events
3303@item show print inferior-events
3304Show whether messages will be printed when @value{GDBN} detects that
3305inferiors have started, exited or have been detached.
3306@end table
3307
6c95b8df
PA
3308Many commands will work the same with multiple programs as with a
3309single program: e.g., @code{print myglobal} will simply display the
3310value of @code{myglobal} in the current inferior.
3311
3312
6b92c0d3 3313Occasionally, when debugging @value{GDBN} itself, it may be useful to
6c95b8df
PA
3314get more info about the relationship of inferiors, programs, address
3315spaces in a debug session. You can do that with the @w{@code{maint
3316info program-spaces}} command.
3317
3318@table @code
3319@kindex maint info program-spaces
3320@item maint info program-spaces
3321Print a list of all program spaces currently being managed by
3322@value{GDBN}.
3323
3324@value{GDBN} displays for each program space (in this order):
3325
3326@enumerate
3327@item
3328the program space number assigned by @value{GDBN}
3329
3330@item
3331the name of the executable loaded into the program space, with e.g.,
3332the @code{file} command.
3333
3334@end enumerate
3335
3336@noindent
3337An asterisk @samp{*} preceding the @value{GDBN} program space number
3338indicates the current program space.
3339
3340In addition, below each program space line, @value{GDBN} prints extra
3341information that isn't suitable to display in tabular form. For
3342example, the list of inferiors bound to the program space.
3343
3344@smallexample
3345(@value{GDBP}) maint info program-spaces
3346 Id Executable
b05b1202 3347* 1 hello
6c95b8df
PA
3348 2 goodbye
3349 Bound inferiors: ID 1 (process 21561)
6c95b8df
PA
3350@end smallexample
3351
3352Here we can see that no inferior is running the program @code{hello},
3353while @code{process 21561} is running the program @code{goodbye}. On
3354some targets, it is possible that multiple inferiors are bound to the
3355same program space. The most common example is that of debugging both
3356the parent and child processes of a @code{vfork} call. For example,
3357
3358@smallexample
3359(@value{GDBP}) maint info program-spaces
3360 Id Executable
3361* 1 vfork-test
3362 Bound inferiors: ID 2 (process 18050), ID 1 (process 18045)
3363@end smallexample
3364
3365Here, both inferior 2 and inferior 1 are running in the same program
3366space as a result of inferior 1 having executed a @code{vfork} call.
3367@end table
3368
6d2ebf8b 3369@node Threads
79a6e687 3370@section Debugging Programs with Multiple Threads
c906108c
SS
3371
3372@cindex threads of execution
3373@cindex multiple threads
3374@cindex switching threads
b1236ac3 3375In some operating systems, such as GNU/Linux and Solaris, a single program
c906108c
SS
3376may have more than one @dfn{thread} of execution. The precise semantics
3377of threads differ from one operating system to another, but in general
3378the threads of a single program are akin to multiple processes---except
3379that they share one address space (that is, they can all examine and
3380modify the same variables). On the other hand, each thread has its own
3381registers and execution stack, and perhaps private memory.
3382
3383@value{GDBN} provides these facilities for debugging multi-thread
3384programs:
3385
3386@itemize @bullet
3387@item automatic notification of new threads
5d5658a1 3388@item @samp{thread @var{thread-id}}, a command to switch among threads
c906108c 3389@item @samp{info threads}, a command to inquire about existing threads
0a232300 3390@item @samp{thread apply [@var{thread-id-list} | all] @var{args}},
c906108c
SS
3391a command to apply a command to a list of threads
3392@item thread-specific breakpoints
93815fbf
VP
3393@item @samp{set print thread-events}, which controls printing of
3394messages on thread start and exit.
17a37d48
PP
3395@item @samp{set libthread-db-search-path @var{path}}, which lets
3396the user specify which @code{libthread_db} to use if the default choice
3397isn't compatible with the program.
c906108c
SS
3398@end itemize
3399
c906108c
SS
3400@cindex focus of debugging
3401@cindex current thread
3402The @value{GDBN} thread debugging facility allows you to observe all
3403threads while your program runs---but whenever @value{GDBN} takes
3404control, one thread in particular is always the focus of debugging.
3405This thread is called the @dfn{current thread}. Debugging commands show
3406program information from the perspective of the current thread.
3407
41afff9a 3408@cindex @code{New} @var{systag} message
c906108c
SS
3409@cindex thread identifier (system)
3410@c FIXME-implementors!! It would be more helpful if the [New...] message
3411@c included GDB's numeric thread handle, so you could just go to that
3412@c thread without first checking `info threads'.
3413Whenever @value{GDBN} detects a new thread in your program, it displays
3414the target system's identification for the thread with a message in the
697aa1b7 3415form @samp{[New @var{systag}]}, where @var{systag} is a thread identifier
c906108c 3416whose form varies depending on the particular system. For example, on
8807d78b 3417@sc{gnu}/Linux, you might see
c906108c 3418
474c8240 3419@smallexample
08e796bc 3420[New Thread 0x41e02940 (LWP 25582)]
474c8240 3421@end smallexample
c906108c
SS
3422
3423@noindent
b1236ac3 3424when @value{GDBN} notices a new thread. In contrast, on other systems,
c906108c
SS
3425the @var{systag} is simply something like @samp{process 368}, with no
3426further qualifier.
3427
3428@c FIXME!! (1) Does the [New...] message appear even for the very first
3429@c thread of a program, or does it only appear for the
6ca652b0 3430@c second---i.e.@: when it becomes obvious we have a multithread
c906108c
SS
3431@c program?
3432@c (2) *Is* there necessarily a first thread always? Or do some
3433@c multithread systems permit starting a program with multiple
5d161b24 3434@c threads ab initio?
c906108c 3435
5d5658a1
PA
3436@anchor{thread numbers}
3437@cindex thread number, per inferior
c906108c 3438@cindex thread identifier (GDB)
5d5658a1
PA
3439For debugging purposes, @value{GDBN} associates its own thread number
3440---always a single integer---with each thread of an inferior. This
3441number is unique between all threads of an inferior, but not unique
3442between threads of different inferiors.
3443
3444@cindex qualified thread ID
3445You can refer to a given thread in an inferior using the qualified
3446@var{inferior-num}.@var{thread-num} syntax, also known as
3447@dfn{qualified thread ID}, with @var{inferior-num} being the inferior
3448number and @var{thread-num} being the thread number of the given
3449inferior. For example, thread @code{2.3} refers to thread number 3 of
3450inferior 2. If you omit @var{inferior-num} (e.g., @code{thread 3}),
3451then @value{GDBN} infers you're referring to a thread of the current
3452inferior.
3453
3454Until you create a second inferior, @value{GDBN} does not show the
3455@var{inferior-num} part of thread IDs, even though you can always use
3456the full @var{inferior-num}.@var{thread-num} form to refer to threads
3457of inferior 1, the initial inferior.
3458
3459@anchor{thread ID lists}
3460@cindex thread ID lists
3461Some commands accept a space-separated @dfn{thread ID list} as
71ef29a8
PA
3462argument. A list element can be:
3463
3464@enumerate
3465@item
3466A thread ID as shown in the first field of the @samp{info threads}
3467display, with or without an inferior qualifier. E.g., @samp{2.1} or
3468@samp{1}.
3469
3470@item
3471A range of thread numbers, again with or without an inferior
3472qualifier, as in @var{inf}.@var{thr1}-@var{thr2} or
3473@var{thr1}-@var{thr2}. E.g., @samp{1.2-4} or @samp{2-4}.
3474
3475@item
3476All threads of an inferior, specified with a star wildcard, with or
3477without an inferior qualifier, as in @var{inf}.@code{*} (e.g.,
3478@samp{1.*}) or @code{*}. The former refers to all threads of the
3479given inferior, and the latter form without an inferior qualifier
3480refers to all threads of the current inferior.
3481
3482@end enumerate
3483
3484For example, if the current inferior is 1, and inferior 7 has one
3485thread with ID 7.1, the thread list @samp{1 2-3 4.5 6.7-9 7.*}
3486includes threads 1 to 3 of inferior 1, thread 5 of inferior 4, threads
34877 to 9 of inferior 6 and all threads of inferior 7. That is, in
3488expanded qualified form, the same as @samp{1.1 1.2 1.3 4.5 6.7 6.8 6.9
34897.1}.
3490
5d5658a1
PA
3491
3492@anchor{global thread numbers}
3493@cindex global thread number
3494@cindex global thread identifier (GDB)
3495In addition to a @emph{per-inferior} number, each thread is also
3496assigned a unique @emph{global} number, also known as @dfn{global
3497thread ID}, a single integer. Unlike the thread number component of
3498the thread ID, no two threads have the same global ID, even when
3499you're debugging multiple inferiors.
c906108c 3500
f4f4330e
PA
3501From @value{GDBN}'s perspective, a process always has at least one
3502thread. In other words, @value{GDBN} assigns a thread number to the
3503program's ``main thread'' even if the program is not multi-threaded.
3504
5d5658a1 3505@vindex $_thread@r{, convenience variable}
663f6d42
PA
3506@vindex $_gthread@r{, convenience variable}
3507The debugger convenience variables @samp{$_thread} and
3508@samp{$_gthread} contain, respectively, the per-inferior thread number
3509and the global thread number of the current thread. You may find this
5d5658a1
PA
3510useful in writing breakpoint conditional expressions, command scripts,
3511and so forth. @xref{Convenience Vars,, Convenience Variables}, for
3512general information on convenience variables.
3513
f303dbd6
PA
3514If @value{GDBN} detects the program is multi-threaded, it augments the
3515usual message about stopping at a breakpoint with the ID and name of
3516the thread that hit the breakpoint.
3517
3518@smallexample
3519Thread 2 "client" hit Breakpoint 1, send_message () at client.c:68
3520@end smallexample
3521
3522Likewise when the program receives a signal:
3523
3524@smallexample
3525Thread 1 "main" received signal SIGINT, Interrupt.
3526@end smallexample
3527
c906108c
SS
3528@table @code
3529@kindex info threads
5d5658a1
PA
3530@item info threads @r{[}@var{thread-id-list}@r{]}
3531
3532Display information about one or more threads. With no arguments
3533displays information about all threads. You can specify the list of
3534threads that you want to display using the thread ID list syntax
3535(@pxref{thread ID lists}).
3536
60f98dde 3537@value{GDBN} displays for each thread (in this order):
c906108c
SS
3538
3539@enumerate
09d4efe1 3540@item
5d5658a1 3541the per-inferior thread number assigned by @value{GDBN}
c906108c 3542
c84f6bbf
PA
3543@item
3544the global thread number assigned by @value{GDBN}, if the @samp{-gid}
3545option was specified
3546
09d4efe1
EZ
3547@item
3548the target system's thread identifier (@var{systag})
c906108c 3549
4694da01
TT
3550@item
3551the thread's name, if one is known. A thread can either be named by
3552the user (see @code{thread name}, below), or, in some cases, by the
3553program itself.
3554
09d4efe1
EZ
3555@item
3556the current stack frame summary for that thread
c906108c
SS
3557@end enumerate
3558
3559@noindent
3560An asterisk @samp{*} to the left of the @value{GDBN} thread number
3561indicates the current thread.
3562
5d161b24 3563For example,
c906108c
SS
3564@end table
3565@c end table here to get a little more width for example
3566
3567@smallexample
3568(@value{GDBP}) info threads
e56d7f1e 3569 Id Target Id Frame
c0ecb95f 3570* 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
b05b1202
PA
3571 2 process 35 thread 23 0x34e5 in sigpause ()
3572 3 process 35 thread 27 0x34e5 in sigpause ()
c906108c
SS
3573 at threadtest.c:68
3574@end smallexample
53a5351d 3575
5d5658a1
PA
3576If you're debugging multiple inferiors, @value{GDBN} displays thread
3577IDs using the qualified @var{inferior-num}.@var{thread-num} format.
c84f6bbf
PA
3578Otherwise, only @var{thread-num} is shown.
3579
3580If you specify the @samp{-gid} option, @value{GDBN} displays a column
3581indicating each thread's global thread ID:
5d5658a1
PA
3582
3583@smallexample
3584(@value{GDBP}) info threads
c84f6bbf
PA
3585 Id GId Target Id Frame
3586 1.1 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
3587 1.2 3 process 35 thread 23 0x34e5 in sigpause ()
3588 1.3 4 process 35 thread 27 0x34e5 in sigpause ()
3589* 2.1 2 process 65 thread 1 main (argc=1, argv=0x7ffffff8)
5d5658a1
PA
3590@end smallexample
3591
c45da7e6
EZ
3592On Solaris, you can display more information about user threads with a
3593Solaris-specific command:
3594
3595@table @code
3596@item maint info sol-threads
3597@kindex maint info sol-threads
3598@cindex thread info (Solaris)
3599Display info on Solaris user threads.
3600@end table
3601
c906108c 3602@table @code
5d5658a1
PA
3603@kindex thread @var{thread-id}
3604@item thread @var{thread-id}
3605Make thread ID @var{thread-id} the current thread. The command
3606argument @var{thread-id} is the @value{GDBN} thread ID, as shown in
3607the first field of the @samp{info threads} display, with or without an
3608inferior qualifier (e.g., @samp{2.1} or @samp{1}).
3609
3610@value{GDBN} responds by displaying the system identifier of the
3611thread you selected, and its current stack frame summary:
c906108c
SS
3612
3613@smallexample
c906108c 3614(@value{GDBP}) thread 2
13fd8b81
TT
3615[Switching to thread 2 (Thread 0xb7fdab70 (LWP 12747))]
3616#0 some_function (ignore=0x0) at example.c:8
36178 printf ("hello\n");
c906108c
SS
3618@end smallexample
3619
3620@noindent
3621As with the @samp{[New @dots{}]} message, the form of the text after
3622@samp{Switching to} depends on your system's conventions for identifying
5d161b24 3623threads.
c906108c 3624
3345721a 3625@anchor{thread apply all}
9c16f35a 3626@kindex thread apply
638ac427 3627@cindex apply command to several threads
0a232300 3628@item thread apply [@var{thread-id-list} | all [-ascending]] [@var{flag}]@dots{} @var{command}
839c27b7 3629The @code{thread apply} command allows you to apply the named
5d5658a1
PA
3630@var{command} to one or more threads. Specify the threads that you
3631want affected using the thread ID list syntax (@pxref{thread ID
3632lists}), or specify @code{all} to apply to all threads. To apply a
3633command to all threads in descending order, type @kbd{thread apply all
253828f1
JK
3634@var{command}}. To apply a command to all threads in ascending order,
3635type @kbd{thread apply all -ascending @var{command}}.
3636
0a232300
PW
3637The @var{flag} arguments control what output to produce and how to handle
3638errors raised when applying @var{command} to a thread. @var{flag}
3639must start with a @code{-} directly followed by one letter in
3640@code{qcs}. If several flags are provided, they must be given
3641individually, such as @code{-c -q}.
3642
3643By default, @value{GDBN} displays some thread information before the
3644output produced by @var{command}, and an error raised during the
3645execution of a @var{command} will abort @code{thread apply}. The
3646following flags can be used to fine-tune this behavior:
3647
3648@table @code
3649@item -c
3650The flag @code{-c}, which stands for @samp{continue}, causes any
3651errors in @var{command} to be displayed, and the execution of
3652@code{thread apply} then continues.
3653@item -s
3654The flag @code{-s}, which stands for @samp{silent}, causes any errors
3655or empty output produced by a @var{command} to be silently ignored.
3656That is, the execution continues, but the thread information and errors
3657are not printed.
3658@item -q
3659The flag @code{-q} (@samp{quiet}) disables printing the thread
3660information.
3661@end table
3662
3663Flags @code{-c} and @code{-s} cannot be used together.
3664
3665@kindex taas
3666@cindex apply command to all threads (ignoring errors and empty output)
3345721a
PA
3667@item taas [@var{option}]@dots{} @var{command}
3668Shortcut for @code{thread apply all -s [@var{option}]@dots{} @var{command}}.
0a232300
PW
3669Applies @var{command} on all threads, ignoring errors and empty output.
3670
3345721a
PA
3671The @code{taas} command accepts the same options as the @code{thread
3672apply all} command. @xref{thread apply all}.
3673
0a232300
PW
3674@kindex tfaas
3675@cindex apply a command to all frames of all threads (ignoring errors and empty output)
3345721a
PA
3676@item tfaas [@var{option}]@dots{} @var{command}
3677Shortcut for @code{thread apply all -s -- frame apply all -s [@var{option}]@dots{} @var{command}}.
0a232300
PW
3678Applies @var{command} on all frames of all threads, ignoring errors
3679and empty output. Note that the flag @code{-s} is specified twice:
3680The first @code{-s} ensures that @code{thread apply} only shows the thread
3681information of the threads for which @code{frame apply} produces
3682some output. The second @code{-s} is needed to ensure that @code{frame
3683apply} shows the frame information of a frame only if the
3684@var{command} successfully produced some output.
3685
3686It can for example be used to print a local variable or a function
3687argument without knowing the thread or frame where this variable or argument
3688is, using:
3689@smallexample
3690(@value{GDBP}) tfaas p some_local_var_i_do_not_remember_where_it_is
3691@end smallexample
3692
3345721a
PA
3693The @code{tfaas} command accepts the same options as the @code{frame
3694apply} command. @xref{frame apply}.
93815fbf 3695
4694da01
TT
3696@kindex thread name
3697@cindex name a thread
3698@item thread name [@var{name}]
3699This command assigns a name to the current thread. If no argument is
3700given, any existing user-specified name is removed. The thread name
3701appears in the @samp{info threads} display.
3702
3703On some systems, such as @sc{gnu}/Linux, @value{GDBN} is able to
3704determine the name of the thread as given by the OS. On these
3705systems, a name specified with @samp{thread name} will override the
3706system-give name, and removing the user-specified name will cause
3707@value{GDBN} to once again display the system-specified name.
3708
60f98dde
MS
3709@kindex thread find
3710@cindex search for a thread
3711@item thread find [@var{regexp}]
3712Search for and display thread ids whose name or @var{systag}
3713matches the supplied regular expression.
3714
3715As well as being the complement to the @samp{thread name} command,
3716this command also allows you to identify a thread by its target
3717@var{systag}. For instance, on @sc{gnu}/Linux, the target @var{systag}
3718is the LWP id.
3719
3720@smallexample
3721(@value{GDBN}) thread find 26688
3722Thread 4 has target id 'Thread 0x41e02940 (LWP 26688)'
3723(@value{GDBN}) info thread 4
3724 Id Target Id Frame
3725 4 Thread 0x41e02940 (LWP 26688) 0x00000031ca6cd372 in select ()
3726@end smallexample
3727
93815fbf
VP
3728@kindex set print thread-events
3729@cindex print messages on thread start and exit
3730@item set print thread-events
3731@itemx set print thread-events on
3732@itemx set print thread-events off
3733The @code{set print thread-events} command allows you to enable or
3734disable printing of messages when @value{GDBN} notices that new threads have
3735started or that threads have exited. By default, these messages will
3736be printed if detection of these events is supported by the target.
3737Note that these messages cannot be disabled on all targets.
3738
3739@kindex show print thread-events
3740@item show print thread-events
3741Show whether messages will be printed when @value{GDBN} detects that threads
3742have started and exited.
c906108c
SS
3743@end table
3744
79a6e687 3745@xref{Thread Stops,,Stopping and Starting Multi-thread Programs}, for
c906108c
SS
3746more information about how @value{GDBN} behaves when you stop and start
3747programs with multiple threads.
3748
79a6e687 3749@xref{Set Watchpoints,,Setting Watchpoints}, for information about
c906108c 3750watchpoints in programs with multiple threads.
c906108c 3751
bf88dd68 3752@anchor{set libthread-db-search-path}
17a37d48
PP
3753@table @code
3754@kindex set libthread-db-search-path
3755@cindex search path for @code{libthread_db}
3756@item set libthread-db-search-path @r{[}@var{path}@r{]}
3757If this variable is set, @var{path} is a colon-separated list of
3758directories @value{GDBN} will use to search for @code{libthread_db}.
3759If you omit @var{path}, @samp{libthread-db-search-path} will be reset to
98a5dd13 3760its default value (@code{$sdir:$pdir} on @sc{gnu}/Linux and Solaris systems).
7e0396aa
DE
3761Internally, the default value comes from the @code{LIBTHREAD_DB_SEARCH_PATH}
3762macro.
17a37d48
PP
3763
3764On @sc{gnu}/Linux and Solaris systems, @value{GDBN} uses a ``helper''
3765@code{libthread_db} library to obtain information about threads in the
3766inferior process. @value{GDBN} will use @samp{libthread-db-search-path}
bf88dd68
JK
3767to find @code{libthread_db}. @value{GDBN} also consults first if inferior
3768specific thread debugging library loading is enabled
3769by @samp{set auto-load libthread-db} (@pxref{libthread_db.so.1 file}).
98a5dd13
DE
3770
3771A special entry @samp{$sdir} for @samp{libthread-db-search-path}
3772refers to the default system directories that are
bf88dd68
JK
3773normally searched for loading shared libraries. The @samp{$sdir} entry
3774is the only kind not needing to be enabled by @samp{set auto-load libthread-db}
3775(@pxref{libthread_db.so.1 file}).
98a5dd13
DE
3776
3777A special entry @samp{$pdir} for @samp{libthread-db-search-path}
3778refers to the directory from which @code{libpthread}
3779was loaded in the inferior process.
17a37d48
PP
3780
3781For any @code{libthread_db} library @value{GDBN} finds in above directories,
3782@value{GDBN} attempts to initialize it with the current inferior process.
3783If this initialization fails (which could happen because of a version
3784mismatch between @code{libthread_db} and @code{libpthread}), @value{GDBN}
3785will unload @code{libthread_db}, and continue with the next directory.
3786If none of @code{libthread_db} libraries initialize successfully,
3787@value{GDBN} will issue a warning and thread debugging will be disabled.
3788
3789Setting @code{libthread-db-search-path} is currently implemented
3790only on some platforms.
3791
3792@kindex show libthread-db-search-path
3793@item show libthread-db-search-path
3794Display current libthread_db search path.
02d868e8
PP
3795
3796@kindex set debug libthread-db
3797@kindex show debug libthread-db
3798@cindex debugging @code{libthread_db}
3799@item set debug libthread-db
3800@itemx show debug libthread-db
3801Turns on or off display of @code{libthread_db}-related events.
3802Use @code{1} to enable, @code{0} to disable.
17a37d48
PP
3803@end table
3804
6c95b8df
PA
3805@node Forks
3806@section Debugging Forks
c906108c
SS
3807
3808@cindex fork, debugging programs which call
3809@cindex multiple processes
3810@cindex processes, multiple
53a5351d
JM
3811On most systems, @value{GDBN} has no special support for debugging
3812programs which create additional processes using the @code{fork}
3813function. When a program forks, @value{GDBN} will continue to debug the
3814parent process and the child process will run unimpeded. If you have
3815set a breakpoint in any code which the child then executes, the child
3816will get a @code{SIGTRAP} signal which (unless it catches the signal)
3817will cause it to terminate.
c906108c
SS
3818
3819However, if you want to debug the child process there is a workaround
3820which isn't too painful. Put a call to @code{sleep} in the code which
3821the child process executes after the fork. It may be useful to sleep
3822only if a certain environment variable is set, or a certain file exists,
3823so that the delay need not occur when you don't want to run @value{GDBN}
3824on the child. While the child is sleeping, use the @code{ps} program to
3825get its process ID. Then tell @value{GDBN} (a new invocation of
3826@value{GDBN} if you are also debugging the parent process) to attach to
d4f3574e 3827the child process (@pxref{Attach}). From that point on you can debug
c906108c 3828the child process just like any other process which you attached to.
c906108c 3829
b1236ac3
PA
3830On some systems, @value{GDBN} provides support for debugging programs
3831that create additional processes using the @code{fork} or @code{vfork}
3832functions. On @sc{gnu}/Linux platforms, this feature is supported
19d9d4ef 3833with kernel version 2.5.46 and later.
c906108c 3834
19d9d4ef
DB
3835The fork debugging commands are supported in native mode and when
3836connected to @code{gdbserver} in either @code{target remote} mode or
3837@code{target extended-remote} mode.
0d71eef5 3838
c906108c
SS
3839By default, when a program forks, @value{GDBN} will continue to debug
3840the parent process and the child process will run unimpeded.
3841
3842If you want to follow the child process instead of the parent process,
3843use the command @w{@code{set follow-fork-mode}}.
3844
3845@table @code
3846@kindex set follow-fork-mode
3847@item set follow-fork-mode @var{mode}
3848Set the debugger response to a program call of @code{fork} or
3849@code{vfork}. A call to @code{fork} or @code{vfork} creates a new
9c16f35a 3850process. The @var{mode} argument can be:
c906108c
SS
3851
3852@table @code
3853@item parent
3854The original process is debugged after a fork. The child process runs
2df3850c 3855unimpeded. This is the default.
c906108c
SS
3856
3857@item child
3858The new process is debugged after a fork. The parent process runs
3859unimpeded.
3860
c906108c
SS
3861@end table
3862
9c16f35a 3863@kindex show follow-fork-mode
c906108c 3864@item show follow-fork-mode
2df3850c 3865Display the current debugger response to a @code{fork} or @code{vfork} call.
c906108c
SS
3866@end table
3867
5c95884b
MS
3868@cindex debugging multiple processes
3869On Linux, if you want to debug both the parent and child processes, use the
3870command @w{@code{set detach-on-fork}}.
3871
3872@table @code
3873@kindex set detach-on-fork
3874@item set detach-on-fork @var{mode}
3875Tells gdb whether to detach one of the processes after a fork, or
3876retain debugger control over them both.
3877
3878@table @code
3879@item on
3880The child process (or parent process, depending on the value of
3881@code{follow-fork-mode}) will be detached and allowed to run
3882independently. This is the default.
3883
3884@item off
3885Both processes will be held under the control of @value{GDBN}.
3886One process (child or parent, depending on the value of
3887@code{follow-fork-mode}) is debugged as usual, while the other
3888is held suspended.
3889
3890@end table
3891
11310833
NR
3892@kindex show detach-on-fork
3893@item show detach-on-fork
3894Show whether detach-on-fork mode is on/off.
5c95884b
MS
3895@end table
3896
2277426b
PA
3897If you choose to set @samp{detach-on-fork} mode off, then @value{GDBN}
3898will retain control of all forked processes (including nested forks).
3899You can list the forked processes under the control of @value{GDBN} by
3900using the @w{@code{info inferiors}} command, and switch from one fork
65c574f6
PA
3901to another by using the @code{inferior} command (@pxref{Inferiors Connections and
3902Programs, ,Debugging Multiple Inferiors Connections and Programs}).
5c95884b
MS
3903
3904To quit debugging one of the forked processes, you can either detach
af624141
MS
3905from it by using the @w{@code{detach inferiors}} command (allowing it
3906to run independently), or kill it using the @w{@code{kill inferiors}}
65c574f6
PA
3907command. @xref{Inferiors Connections and Programs, ,Debugging
3908Multiple Inferiors Connections and Programs}.
5c95884b 3909
c906108c
SS
3910If you ask to debug a child process and a @code{vfork} is followed by an
3911@code{exec}, @value{GDBN} executes the new target up to the first
3912breakpoint in the new target. If you have a breakpoint set on
3913@code{main} in your original program, the breakpoint will also be set on
3914the child process's @code{main}.
3915
2277426b
PA
3916On some systems, when a child process is spawned by @code{vfork}, you
3917cannot debug the child or parent until an @code{exec} call completes.
c906108c
SS
3918
3919If you issue a @code{run} command to @value{GDBN} after an @code{exec}
6c95b8df
PA
3920call executes, the new target restarts. To restart the parent
3921process, use the @code{file} command with the parent executable name
3922as its argument. By default, after an @code{exec} call executes,
3923@value{GDBN} discards the symbols of the previous executable image.
3924You can change this behaviour with the @w{@code{set follow-exec-mode}}
3925command.
3926
3927@table @code
3928@kindex set follow-exec-mode
3929@item set follow-exec-mode @var{mode}
3930
3931Set debugger response to a program call of @code{exec}. An
3932@code{exec} call replaces the program image of a process.
3933
3934@code{follow-exec-mode} can be:
3935
3936@table @code
3937@item new
3938@value{GDBN} creates a new inferior and rebinds the process to this
3939new inferior. The program the process was running before the
3940@code{exec} call can be restarted afterwards by restarting the
3941original inferior.
3942
3943For example:
3944
3945@smallexample
3946(@value{GDBP}) info inferiors
3947(gdb) info inferior
3948 Id Description Executable
3949* 1 <null> prog1
3950(@value{GDBP}) run
3951process 12020 is executing new program: prog2
3952Program exited normally.
3953(@value{GDBP}) info inferiors
3954 Id Description Executable
c0ecb95f 3955 1 <null> prog1
b05b1202 3956* 2 <null> prog2
6c95b8df
PA
3957@end smallexample
3958
3959@item same
3960@value{GDBN} keeps the process bound to the same inferior. The new
3961executable image replaces the previous executable loaded in the
3962inferior. Restarting the inferior after the @code{exec} call, with
3963e.g., the @code{run} command, restarts the executable the process was
3964running after the @code{exec} call. This is the default mode.
3965
3966For example:
3967
3968@smallexample
3969(@value{GDBP}) info inferiors
3970 Id Description Executable
3971* 1 <null> prog1
3972(@value{GDBP}) run
3973process 12020 is executing new program: prog2
3974Program exited normally.
3975(@value{GDBP}) info inferiors
3976 Id Description Executable
3977* 1 <null> prog2
3978@end smallexample
3979
3980@end table
3981@end table
c906108c 3982
19d9d4ef
DB
3983@code{follow-exec-mode} is supported in native mode and
3984@code{target extended-remote} mode.
3985
c906108c
SS
3986You can use the @code{catch} command to make @value{GDBN} stop whenever
3987a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
79a6e687 3988Catchpoints, ,Setting Catchpoints}.
c906108c 3989
5c95884b 3990@node Checkpoint/Restart
79a6e687 3991@section Setting a @emph{Bookmark} to Return to Later
5c95884b
MS
3992
3993@cindex checkpoint
3994@cindex restart
3995@cindex bookmark
3996@cindex snapshot of a process
3997@cindex rewind program state
3998
3999On certain operating systems@footnote{Currently, only
4000@sc{gnu}/Linux.}, @value{GDBN} is able to save a @dfn{snapshot} of a
4001program's state, called a @dfn{checkpoint}, and come back to it
4002later.
4003
4004Returning to a checkpoint effectively undoes everything that has
4005happened in the program since the @code{checkpoint} was saved. This
4006includes changes in memory, registers, and even (within some limits)
4007system state. Effectively, it is like going back in time to the
4008moment when the checkpoint was saved.
4009
4010Thus, if you're stepping thru a program and you think you're
4011getting close to the point where things go wrong, you can save
4012a checkpoint. Then, if you accidentally go too far and miss
4013the critical statement, instead of having to restart your program
4014from the beginning, you can just go back to the checkpoint and
4015start again from there.
4016
4017This can be especially useful if it takes a lot of time or
4018steps to reach the point where you think the bug occurs.
4019
4020To use the @code{checkpoint}/@code{restart} method of debugging:
4021
4022@table @code
4023@kindex checkpoint
4024@item checkpoint
4025Save a snapshot of the debugged program's current execution state.
4026The @code{checkpoint} command takes no arguments, but each checkpoint
4027is assigned a small integer id, similar to a breakpoint id.
4028
4029@kindex info checkpoints
4030@item info checkpoints
4031List the checkpoints that have been saved in the current debugging
4032session. For each checkpoint, the following information will be
4033listed:
4034
4035@table @code
4036@item Checkpoint ID
4037@item Process ID
4038@item Code Address
4039@item Source line, or label
4040@end table
4041
4042@kindex restart @var{checkpoint-id}
4043@item restart @var{checkpoint-id}
4044Restore the program state that was saved as checkpoint number
4045@var{checkpoint-id}. All program variables, registers, stack frames
4046etc.@: will be returned to the values that they had when the checkpoint
4047was saved. In essence, gdb will ``wind back the clock'' to the point
4048in time when the checkpoint was saved.
4049
4050Note that breakpoints, @value{GDBN} variables, command history etc.
4051are not affected by restoring a checkpoint. In general, a checkpoint
4052only restores things that reside in the program being debugged, not in
4053the debugger.
4054
b8db102d
MS
4055@kindex delete checkpoint @var{checkpoint-id}
4056@item delete checkpoint @var{checkpoint-id}
5c95884b
MS
4057Delete the previously-saved checkpoint identified by @var{checkpoint-id}.
4058
4059@end table
4060
4061Returning to a previously saved checkpoint will restore the user state
4062of the program being debugged, plus a significant subset of the system
4063(OS) state, including file pointers. It won't ``un-write'' data from
4064a file, but it will rewind the file pointer to the previous location,
4065so that the previously written data can be overwritten. For files
4066opened in read mode, the pointer will also be restored so that the
4067previously read data can be read again.
4068
4069Of course, characters that have been sent to a printer (or other
4070external device) cannot be ``snatched back'', and characters received
4071from eg.@: a serial device can be removed from internal program buffers,
4072but they cannot be ``pushed back'' into the serial pipeline, ready to
4073be received again. Similarly, the actual contents of files that have
4074been changed cannot be restored (at this time).
4075
4076However, within those constraints, you actually can ``rewind'' your
4077program to a previously saved point in time, and begin debugging it
4078again --- and you can change the course of events so as to debug a
4079different execution path this time.
4080
4081@cindex checkpoints and process id
4082Finally, there is one bit of internal program state that will be
4083different when you return to a checkpoint --- the program's process
4084id. Each checkpoint will have a unique process id (or @var{pid}),
4085and each will be different from the program's original @var{pid}.
4086If your program has saved a local copy of its process id, this could
4087potentially pose a problem.
4088
79a6e687 4089@subsection A Non-obvious Benefit of Using Checkpoints
5c95884b
MS
4090
4091On some systems such as @sc{gnu}/Linux, address space randomization
4092is performed on new processes for security reasons. This makes it
4093difficult or impossible to set a breakpoint, or watchpoint, on an
4094absolute address if you have to restart the program, since the
4095absolute location of a symbol will change from one execution to the
4096next.
4097
4098A checkpoint, however, is an @emph{identical} copy of a process.
4099Therefore if you create a checkpoint at (eg.@:) the start of main,
4100and simply return to that checkpoint instead of restarting the
4101process, you can avoid the effects of address randomization and
4102your symbols will all stay in the same place.
4103
6d2ebf8b 4104@node Stopping
c906108c
SS
4105@chapter Stopping and Continuing
4106
4107The principal purposes of using a debugger are so that you can stop your
4108program before it terminates; or so that, if your program runs into
4109trouble, you can investigate and find out why.
4110
7a292a7a
SS
4111Inside @value{GDBN}, your program may stop for any of several reasons,
4112such as a signal, a breakpoint, or reaching a new line after a
4113@value{GDBN} command such as @code{step}. You may then examine and
4114change variables, set new breakpoints or remove old ones, and then
4115continue execution. Usually, the messages shown by @value{GDBN} provide
4116ample explanation of the status of your program---but you can also
4117explicitly request this information at any time.
c906108c
SS
4118
4119@table @code
4120@kindex info program
4121@item info program
4122Display information about the status of your program: whether it is
7a292a7a 4123running or not, what process it is, and why it stopped.
c906108c
SS
4124@end table
4125
4126@menu
4127* Breakpoints:: Breakpoints, watchpoints, and catchpoints
4128* Continuing and Stepping:: Resuming execution
aad1c02c
TT
4129* Skipping Over Functions and Files::
4130 Skipping over functions and files
c906108c 4131* Signals:: Signals
c906108c 4132* Thread Stops:: Stopping and starting multi-thread programs
c906108c
SS
4133@end menu
4134
6d2ebf8b 4135@node Breakpoints
79a6e687 4136@section Breakpoints, Watchpoints, and Catchpoints
c906108c
SS
4137
4138@cindex breakpoints
4139A @dfn{breakpoint} makes your program stop whenever a certain point in
4140the program is reached. For each breakpoint, you can add conditions to
4141control in finer detail whether your program stops. You can set
4142breakpoints with the @code{break} command and its variants (@pxref{Set
79a6e687 4143Breaks, ,Setting Breakpoints}), to specify the place where your program
c906108c
SS
4144should stop by line number, function name or exact address in the
4145program.
4146
09d4efe1 4147On some systems, you can set breakpoints in shared libraries before
b1236ac3 4148the executable is run.
c906108c
SS
4149
4150@cindex watchpoints
fd60e0df 4151@cindex data breakpoints
c906108c
SS
4152@cindex memory tracing
4153@cindex breakpoint on memory address
4154@cindex breakpoint on variable modification
4155A @dfn{watchpoint} is a special breakpoint that stops your program
fd60e0df 4156when the value of an expression changes. The expression may be a value
0ced0c34 4157of a variable, or it could involve values of one or more variables
fd60e0df
EZ
4158combined by operators, such as @samp{a + b}. This is sometimes called
4159@dfn{data breakpoints}. You must use a different command to set
79a6e687 4160watchpoints (@pxref{Set Watchpoints, ,Setting Watchpoints}), but aside
fd60e0df
EZ
4161from that, you can manage a watchpoint like any other breakpoint: you
4162enable, disable, and delete both breakpoints and watchpoints using the
4163same commands.
c906108c
SS
4164
4165You can arrange to have values from your program displayed automatically
4166whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
79a6e687 4167Automatic Display}.
c906108c
SS
4168
4169@cindex catchpoints
4170@cindex breakpoint on events
4171A @dfn{catchpoint} is another special breakpoint that stops your program
b37052ae 4172when a certain kind of event occurs, such as the throwing of a C@t{++}
c906108c
SS
4173exception or the loading of a library. As with watchpoints, you use a
4174different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
79a6e687 4175Catchpoints}), but aside from that, you can manage a catchpoint like any
c906108c 4176other breakpoint. (To stop when your program receives a signal, use the
d4f3574e 4177@code{handle} command; see @ref{Signals, ,Signals}.)
c906108c
SS
4178
4179@cindex breakpoint numbers
4180@cindex numbers for breakpoints
4181@value{GDBN} assigns a number to each breakpoint, watchpoint, or
4182catchpoint when you create it; these numbers are successive integers
4183starting with one. In many of the commands for controlling various
4184features of breakpoints you use the breakpoint number to say which
4185breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
4186@dfn{disabled}; if disabled, it has no effect on your program until you
4187enable it again.
4188
c5394b80 4189@cindex breakpoint ranges
18da0c51 4190@cindex breakpoint lists
c5394b80 4191@cindex ranges of breakpoints
18da0c51
MG
4192@cindex lists of breakpoints
4193Some @value{GDBN} commands accept a space-separated list of breakpoints
4194on which to operate. A list element can be either a single breakpoint number,
4195like @samp{5}, or a range of such numbers, like @samp{5-7}.
4196When a breakpoint list is given to a command, all breakpoints in that list
4197are operated on.
c5394b80 4198
c906108c
SS
4199@menu
4200* Set Breaks:: Setting breakpoints
4201* Set Watchpoints:: Setting watchpoints
4202* Set Catchpoints:: Setting catchpoints
4203* Delete Breaks:: Deleting breakpoints
4204* Disabling:: Disabling breakpoints
4205* Conditions:: Break conditions
4206* Break Commands:: Breakpoint command lists
e7e0cddf 4207* Dynamic Printf:: Dynamic printf
6149aea9 4208* Save Breakpoints:: How to save breakpoints in a file
62e5f89c 4209* Static Probe Points:: Listing static probe points
d4f3574e 4210* Error in Breakpoints:: ``Cannot insert breakpoints''
79a6e687 4211* Breakpoint-related Warnings:: ``Breakpoint address adjusted...''
c906108c
SS
4212@end menu
4213
6d2ebf8b 4214@node Set Breaks
79a6e687 4215@subsection Setting Breakpoints
c906108c 4216
5d161b24 4217@c FIXME LMB what does GDB do if no code on line of breakpt?
c906108c
SS
4218@c consider in particular declaration with/without initialization.
4219@c
4220@c FIXME 2 is there stuff on this already? break at fun start, already init?
4221
4222@kindex break
41afff9a
EZ
4223@kindex b @r{(@code{break})}
4224@vindex $bpnum@r{, convenience variable}
c906108c
SS
4225@cindex latest breakpoint
4226Breakpoints are set with the @code{break} command (abbreviated
5d161b24 4227@code{b}). The debugger convenience variable @samp{$bpnum} records the
f3b28801 4228number of the breakpoint you've set most recently; see @ref{Convenience
79a6e687 4229Vars,, Convenience Variables}, for a discussion of what you can do with
c906108c
SS
4230convenience variables.
4231
c906108c 4232@table @code
2a25a5ba
EZ
4233@item break @var{location}
4234Set a breakpoint at the given @var{location}, which can specify a
4235function name, a line number, or an address of an instruction.
4236(@xref{Specify Location}, for a list of all the possible ways to
4237specify a @var{location}.) The breakpoint will stop your program just
4238before it executes any of the code in the specified @var{location}.
4239
c906108c 4240When using source languages that permit overloading of symbols, such as
2a25a5ba 4241C@t{++}, a function name may refer to more than one possible place to break.
6ba66d6a
JB
4242@xref{Ambiguous Expressions,,Ambiguous Expressions}, for a discussion of
4243that situation.
c906108c 4244
45ac276d 4245It is also possible to insert a breakpoint that will stop the program
2c88c651
JB
4246only if a specific thread (@pxref{Thread-Specific Breakpoints})
4247or a specific task (@pxref{Ada Tasks}) hits that breakpoint.
45ac276d 4248
c906108c
SS
4249@item break
4250When called without any arguments, @code{break} sets a breakpoint at
4251the next instruction to be executed in the selected stack frame
4252(@pxref{Stack, ,Examining the Stack}). In any selected frame but the
4253innermost, this makes your program stop as soon as control
4254returns to that frame. This is similar to the effect of a
4255@code{finish} command in the frame inside the selected frame---except
4256that @code{finish} does not leave an active breakpoint. If you use
4257@code{break} without an argument in the innermost frame, @value{GDBN} stops
4258the next time it reaches the current location; this may be useful
4259inside loops.
4260
4261@value{GDBN} normally ignores breakpoints when it resumes execution, until at
4262least one instruction has been executed. If it did not do this, you
4263would be unable to proceed past a breakpoint without first disabling the
4264breakpoint. This rule applies whether or not the breakpoint already
4265existed when your program stopped.
4266
4267@item break @dots{} if @var{cond}
4268Set a breakpoint with condition @var{cond}; evaluate the expression
4269@var{cond} each time the breakpoint is reached, and stop only if the
4270value is nonzero---that is, if @var{cond} evaluates as true.
4271@samp{@dots{}} stands for one of the possible arguments described
4272above (or no argument) specifying where to break. @xref{Conditions,
79a6e687 4273,Break Conditions}, for more information on breakpoint conditions.
c906108c
SS
4274
4275@kindex tbreak
4276@item tbreak @var{args}
697aa1b7 4277Set a breakpoint enabled only for one stop. The @var{args} are the
c906108c
SS
4278same as for the @code{break} command, and the breakpoint is set in the same
4279way, but the breakpoint is automatically deleted after the first time your
79a6e687 4280program stops there. @xref{Disabling, ,Disabling Breakpoints}.
c906108c 4281
c906108c 4282@kindex hbreak
ba04e063 4283@cindex hardware breakpoints
c906108c 4284@item hbreak @var{args}
697aa1b7 4285Set a hardware-assisted breakpoint. The @var{args} are the same as for the
d4f3574e 4286@code{break} command and the breakpoint is set in the same way, but the
c906108c
SS
4287breakpoint requires hardware support and some target hardware may not
4288have this support. The main purpose of this is EPROM/ROM code
d4f3574e
SS
4289debugging, so you can set a breakpoint at an instruction without
4290changing the instruction. This can be used with the new trap-generation
09d4efe1 4291provided by SPARClite DSU and most x86-based targets. These targets
d4f3574e
SS
4292will generate traps when a program accesses some data or instruction
4293address that is assigned to the debug registers. However the hardware
4294breakpoint registers can take a limited number of breakpoints. For
4295example, on the DSU, only two data breakpoints can be set at a time, and
4296@value{GDBN} will reject this command if more than two are used. Delete
4297or disable unused hardware breakpoints before setting new ones
79a6e687
BW
4298(@pxref{Disabling, ,Disabling Breakpoints}).
4299@xref{Conditions, ,Break Conditions}.
9c16f35a
EZ
4300For remote targets, you can restrict the number of hardware
4301breakpoints @value{GDBN} will use, see @ref{set remote
4302hardware-breakpoint-limit}.
501eef12 4303
c906108c
SS
4304@kindex thbreak
4305@item thbreak @var{args}
697aa1b7 4306Set a hardware-assisted breakpoint enabled only for one stop. The @var{args}
c906108c 4307are the same as for the @code{hbreak} command and the breakpoint is set in
5d161b24 4308the same way. However, like the @code{tbreak} command,
c906108c
SS
4309the breakpoint is automatically deleted after the
4310first time your program stops there. Also, like the @code{hbreak}
5d161b24 4311command, the breakpoint requires hardware support and some target hardware
79a6e687
BW
4312may not have this support. @xref{Disabling, ,Disabling Breakpoints}.
4313See also @ref{Conditions, ,Break Conditions}.
c906108c
SS
4314
4315@kindex rbreak
4316@cindex regular expression
8bd10a10 4317@cindex breakpoints at functions matching a regexp
c45da7e6 4318@cindex set breakpoints in many functions
c906108c 4319@item rbreak @var{regex}
c906108c 4320Set breakpoints on all functions matching the regular expression
11cf8741
JM
4321@var{regex}. This command sets an unconditional breakpoint on all
4322matches, printing a list of all breakpoints it set. Once these
4323breakpoints are set, they are treated just like the breakpoints set with
4324the @code{break} command. You can delete them, disable them, or make
4325them conditional the same way as any other breakpoint.
4326
20813a0b
PW
4327In programs using different languages, @value{GDBN} chooses the syntax
4328to print the list of all breakpoints it sets according to the
4329@samp{set language} value: using @samp{set language auto}
4330(see @ref{Automatically, ,Set Language Automatically}) means to use the
4331language of the breakpoint's function, other values mean to use
4332the manually specified language (see @ref{Manually, ,Set Language Manually}).
4333
11cf8741
JM
4334The syntax of the regular expression is the standard one used with tools
4335like @file{grep}. Note that this is different from the syntax used by
4336shells, so for instance @code{foo*} matches all functions that include
4337an @code{fo} followed by zero or more @code{o}s. There is an implicit
4338@code{.*} leading and trailing the regular expression you supply, so to
4339match only functions that begin with @code{foo}, use @code{^foo}.
c906108c 4340
f7dc1244 4341@cindex non-member C@t{++} functions, set breakpoint in
b37052ae 4342When debugging C@t{++} programs, @code{rbreak} is useful for setting
c906108c
SS
4343breakpoints on overloaded functions that are not members of any special
4344classes.
c906108c 4345
f7dc1244
EZ
4346@cindex set breakpoints on all functions
4347The @code{rbreak} command can be used to set breakpoints in
4348@strong{all} the functions in a program, like this:
4349
4350@smallexample
4351(@value{GDBP}) rbreak .
4352@end smallexample
4353
8bd10a10
CM
4354@item rbreak @var{file}:@var{regex}
4355If @code{rbreak} is called with a filename qualification, it limits
4356the search for functions matching the given regular expression to the
4357specified @var{file}. This can be used, for example, to set breakpoints on
4358every function in a given file:
4359
4360@smallexample
4361(@value{GDBP}) rbreak file.c:.
4362@end smallexample
4363
4364The colon separating the filename qualifier from the regex may
4365optionally be surrounded by spaces.
4366
c906108c
SS
4367@kindex info breakpoints
4368@cindex @code{$_} and @code{info breakpoints}
18da0c51
MG
4369@item info breakpoints @r{[}@var{list}@dots{}@r{]}
4370@itemx info break @r{[}@var{list}@dots{}@r{]}
c906108c 4371Print a table of all breakpoints, watchpoints, and catchpoints set and
45ac1734 4372not deleted. Optional argument @var{n} means print information only
e5a67952
MS
4373about the specified breakpoint(s) (or watchpoint(s) or catchpoint(s)).
4374For each breakpoint, following columns are printed:
c906108c
SS
4375
4376@table @emph
4377@item Breakpoint Numbers
4378@item Type
4379Breakpoint, watchpoint, or catchpoint.
4380@item Disposition
4381Whether the breakpoint is marked to be disabled or deleted when hit.
4382@item Enabled or Disabled
4383Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
b3db7447 4384that are not enabled.
c906108c 4385@item Address
fe6fbf8b 4386Where the breakpoint is in your program, as a memory address. For a
b3db7447
NR
4387pending breakpoint whose address is not yet known, this field will
4388contain @samp{<PENDING>}. Such breakpoint won't fire until a shared
4389library that has the symbol or line referred by breakpoint is loaded.
4390See below for details. A breakpoint with several locations will
3b784c4f 4391have @samp{<MULTIPLE>} in this field---see below for details.
c906108c
SS
4392@item What
4393Where the breakpoint is in the source for your program, as a file and
2650777c
JJ
4394line number. For a pending breakpoint, the original string passed to
4395the breakpoint command will be listed as it cannot be resolved until
4396the appropriate shared library is loaded in the future.
c906108c
SS
4397@end table
4398
4399@noindent
83364271
LM
4400If a breakpoint is conditional, there are two evaluation modes: ``host'' and
4401``target''. If mode is ``host'', breakpoint condition evaluation is done by
4402@value{GDBN} on the host's side. If it is ``target'', then the condition
4403is evaluated by the target. The @code{info break} command shows
4404the condition on the line following the affected breakpoint, together with
4405its condition evaluation mode in between parentheses.
4406
4407Breakpoint commands, if any, are listed after that. A pending breakpoint is
4408allowed to have a condition specified for it. The condition is not parsed for
4409validity until a shared library is loaded that allows the pending
4410breakpoint to resolve to a valid location.
c906108c
SS
4411
4412@noindent
4413@code{info break} with a breakpoint
4414number @var{n} as argument lists only that breakpoint. The
4415convenience variable @code{$_} and the default examining-address for
4416the @code{x} command are set to the address of the last breakpoint
79a6e687 4417listed (@pxref{Memory, ,Examining Memory}).
c906108c
SS
4418
4419@noindent
4420@code{info break} displays a count of the number of times the breakpoint
4421has been hit. This is especially useful in conjunction with the
4422@code{ignore} command. You can ignore a large number of breakpoint
4423hits, look at the breakpoint info to see how many times the breakpoint
4424was hit, and then run again, ignoring one less than that number. This
4425will get you quickly to the last hit of that breakpoint.
816338b5
SS
4426
4427@noindent
4428For a breakpoints with an enable count (xref) greater than 1,
4429@code{info break} also displays that count.
4430
c906108c
SS
4431@end table
4432
4433@value{GDBN} allows you to set any number of breakpoints at the same place in
4434your program. There is nothing silly or meaningless about this. When
4435the breakpoints are conditional, this is even useful
79a6e687 4436(@pxref{Conditions, ,Break Conditions}).
c906108c 4437
2e9132cc
EZ
4438@cindex multiple locations, breakpoints
4439@cindex breakpoints, multiple locations
fcda367b 4440It is possible that a breakpoint corresponds to several locations
fe6fbf8b
VP
4441in your program. Examples of this situation are:
4442
4443@itemize @bullet
f8eba3c6
TT
4444@item
4445Multiple functions in the program may have the same name.
4446
fe6fbf8b
VP
4447@item
4448For a C@t{++} constructor, the @value{NGCC} compiler generates several
4449instances of the function body, used in different cases.
4450
4451@item
4452For a C@t{++} template function, a given line in the function can
4453correspond to any number of instantiations.
4454
4455@item
4456For an inlined function, a given source line can correspond to
4457several places where that function is inlined.
fe6fbf8b
VP
4458@end itemize
4459
4460In all those cases, @value{GDBN} will insert a breakpoint at all
f8eba3c6 4461the relevant locations.
fe6fbf8b 4462
3b784c4f
EZ
4463A breakpoint with multiple locations is displayed in the breakpoint
4464table using several rows---one header row, followed by one row for
4465each breakpoint location. The header row has @samp{<MULTIPLE>} in the
4466address column. The rows for individual locations contain the actual
4467addresses for locations, and show the functions to which those
4468locations belong. The number column for a location is of the form
fe6fbf8b
VP
4469@var{breakpoint-number}.@var{location-number}.
4470
4471For example:
3b784c4f 4472
fe6fbf8b
VP
4473@smallexample
4474Num Type Disp Enb Address What
44751 breakpoint keep y <MULTIPLE>
4476 stop only if i==1
4477 breakpoint already hit 1 time
44781.1 y 0x080486a2 in void foo<int>() at t.cc:8
44791.2 y 0x080486ca in void foo<double>() at t.cc:8
4480@end smallexample
4481
d0fe4701
XR
4482You cannot delete the individual locations from a breakpoint. However,
4483each location can be individually enabled or disabled by passing
fe6fbf8b 4484@var{breakpoint-number}.@var{location-number} as argument to the
d0fe4701
XR
4485@code{enable} and @code{disable} commands. It's also possible to
4486@code{enable} and @code{disable} a range of @var{location-number}
4487locations using a @var{breakpoint-number} and two @var{location-number}s,
4488in increasing order, separated by a hyphen, like
4489@kbd{@var{breakpoint-number}.@var{location-number1}-@var{location-number2}},
4490in which case @value{GDBN} acts on all the locations in the range (inclusive).
4491Disabling or enabling the parent breakpoint (@pxref{Disabling}) affects
4492all of the locations that belong to that breakpoint.
fe6fbf8b 4493
2650777c 4494@cindex pending breakpoints
fe6fbf8b 4495It's quite common to have a breakpoint inside a shared library.
3b784c4f 4496Shared libraries can be loaded and unloaded explicitly,
fe6fbf8b
VP
4497and possibly repeatedly, as the program is executed. To support
4498this use case, @value{GDBN} updates breakpoint locations whenever
4499any shared library is loaded or unloaded. Typically, you would
fcda367b 4500set a breakpoint in a shared library at the beginning of your
fe6fbf8b
VP
4501debugging session, when the library is not loaded, and when the
4502symbols from the library are not available. When you try to set
4503breakpoint, @value{GDBN} will ask you if you want to set
3b784c4f 4504a so called @dfn{pending breakpoint}---breakpoint whose address
fe6fbf8b
VP
4505is not yet resolved.
4506
4507After the program is run, whenever a new shared library is loaded,
4508@value{GDBN} reevaluates all the breakpoints. When a newly loaded
4509shared library contains the symbol or line referred to by some
4510pending breakpoint, that breakpoint is resolved and becomes an
4511ordinary breakpoint. When a library is unloaded, all breakpoints
4512that refer to its symbols or source lines become pending again.
4513
4514This logic works for breakpoints with multiple locations, too. For
4515example, if you have a breakpoint in a C@t{++} template function, and
4516a newly loaded shared library has an instantiation of that template,
4517a new location is added to the list of locations for the breakpoint.
4518
4519Except for having unresolved address, pending breakpoints do not
4520differ from regular breakpoints. You can set conditions or commands,
4521enable and disable them and perform other breakpoint operations.
4522
4523@value{GDBN} provides some additional commands for controlling what
4524happens when the @samp{break} command cannot resolve breakpoint
4525address specification to an address:
dd79a6cf
JJ
4526
4527@kindex set breakpoint pending
4528@kindex show breakpoint pending
4529@table @code
4530@item set breakpoint pending auto
4531This is the default behavior. When @value{GDBN} cannot find the breakpoint
4532location, it queries you whether a pending breakpoint should be created.
4533
4534@item set breakpoint pending on
4535This indicates that an unrecognized breakpoint location should automatically
4536result in a pending breakpoint being created.
4537
4538@item set breakpoint pending off
4539This indicates that pending breakpoints are not to be created. Any
4540unrecognized breakpoint location results in an error. This setting does
4541not affect any pending breakpoints previously created.
4542
4543@item show breakpoint pending
4544Show the current behavior setting for creating pending breakpoints.
4545@end table
2650777c 4546
fe6fbf8b
VP
4547The settings above only affect the @code{break} command and its
4548variants. Once breakpoint is set, it will be automatically updated
4549as shared libraries are loaded and unloaded.
2650777c 4550
765dc015
VP
4551@cindex automatic hardware breakpoints
4552For some targets, @value{GDBN} can automatically decide if hardware or
4553software breakpoints should be used, depending on whether the
4554breakpoint address is read-only or read-write. This applies to
4555breakpoints set with the @code{break} command as well as to internal
4556breakpoints set by commands like @code{next} and @code{finish}. For
fcda367b 4557breakpoints set with @code{hbreak}, @value{GDBN} will always use hardware
765dc015
VP
4558breakpoints.
4559
18da0c51 4560You can control this automatic behaviour with the following commands:
765dc015
VP
4561
4562@kindex set breakpoint auto-hw
4563@kindex show breakpoint auto-hw
4564@table @code
4565@item set breakpoint auto-hw on
4566This is the default behavior. When @value{GDBN} sets a breakpoint, it
4567will try to use the target memory map to decide if software or hardware
4568breakpoint must be used.
4569
4570@item set breakpoint auto-hw off
4571This indicates @value{GDBN} should not automatically select breakpoint
4572type. If the target provides a memory map, @value{GDBN} will warn when
4573trying to set software breakpoint at a read-only address.
4574@end table
4575
74960c60
VP
4576@value{GDBN} normally implements breakpoints by replacing the program code
4577at the breakpoint address with a special instruction, which, when
4578executed, given control to the debugger. By default, the program
4579code is so modified only when the program is resumed. As soon as
4580the program stops, @value{GDBN} restores the original instructions. This
4581behaviour guards against leaving breakpoints inserted in the
4582target should gdb abrubptly disconnect. However, with slow remote
4583targets, inserting and removing breakpoint can reduce the performance.
4584This behavior can be controlled with the following commands::
4585
4586@kindex set breakpoint always-inserted
4587@kindex show breakpoint always-inserted
4588@table @code
4589@item set breakpoint always-inserted off
33e5cbd6
PA
4590All breakpoints, including newly added by the user, are inserted in
4591the target only when the target is resumed. All breakpoints are
a25a5a45 4592removed from the target when it stops. This is the default mode.
74960c60
VP
4593
4594@item set breakpoint always-inserted on
4595Causes all breakpoints to be inserted in the target at all times. If
4596the user adds a new breakpoint, or changes an existing breakpoint, the
4597breakpoints in the target are updated immediately. A breakpoint is
a25a5a45 4598removed from the target only when breakpoint itself is deleted.
342cc091 4599@end table
765dc015 4600
83364271
LM
4601@value{GDBN} handles conditional breakpoints by evaluating these conditions
4602when a breakpoint breaks. If the condition is true, then the process being
4603debugged stops, otherwise the process is resumed.
4604
4605If the target supports evaluating conditions on its end, @value{GDBN} may
4606download the breakpoint, together with its conditions, to it.
4607
4608This feature can be controlled via the following commands:
4609
4610@kindex set breakpoint condition-evaluation
4611@kindex show breakpoint condition-evaluation
4612@table @code
4613@item set breakpoint condition-evaluation host
4614This option commands @value{GDBN} to evaluate the breakpoint
4615conditions on the host's side. Unconditional breakpoints are sent to
4616the target which in turn receives the triggers and reports them back to GDB
4617for condition evaluation. This is the standard evaluation mode.
4618
4619@item set breakpoint condition-evaluation target
4620This option commands @value{GDBN} to download breakpoint conditions
4621to the target at the moment of their insertion. The target
4622is responsible for evaluating the conditional expression and reporting
4623breakpoint stop events back to @value{GDBN} whenever the condition
4624is true. Due to limitations of target-side evaluation, some conditions
4625cannot be evaluated there, e.g., conditions that depend on local data
4626that is only known to the host. Examples include
4627conditional expressions involving convenience variables, complex types
4628that cannot be handled by the agent expression parser and expressions
4629that are too long to be sent over to the target, specially when the
4630target is a remote system. In these cases, the conditions will be
4631evaluated by @value{GDBN}.
4632
4633@item set breakpoint condition-evaluation auto
4634This is the default mode. If the target supports evaluating breakpoint
4635conditions on its end, @value{GDBN} will download breakpoint conditions to
4636the target (limitations mentioned previously apply). If the target does
4637not support breakpoint condition evaluation, then @value{GDBN} will fallback
4638to evaluating all these conditions on the host's side.
4639@end table
4640
4641
c906108c
SS
4642@cindex negative breakpoint numbers
4643@cindex internal @value{GDBN} breakpoints
eb12ee30
AC
4644@value{GDBN} itself sometimes sets breakpoints in your program for
4645special purposes, such as proper handling of @code{longjmp} (in C
4646programs). These internal breakpoints are assigned negative numbers,
4647starting with @code{-1}; @samp{info breakpoints} does not display them.
c906108c 4648You can see these breakpoints with the @value{GDBN} maintenance command
eb12ee30 4649@samp{maint info breakpoints} (@pxref{maint info breakpoints}).
c906108c
SS
4650
4651
6d2ebf8b 4652@node Set Watchpoints
79a6e687 4653@subsection Setting Watchpoints
c906108c
SS
4654
4655@cindex setting watchpoints
c906108c
SS
4656You can use a watchpoint to stop execution whenever the value of an
4657expression changes, without having to predict a particular place where
fd60e0df
EZ
4658this may happen. (This is sometimes called a @dfn{data breakpoint}.)
4659The expression may be as simple as the value of a single variable, or
4660as complex as many variables combined by operators. Examples include:
4661
4662@itemize @bullet
4663@item
4664A reference to the value of a single variable.
4665
4666@item
4667An address cast to an appropriate data type. For example,
4668@samp{*(int *)0x12345678} will watch a 4-byte region at the specified
4669address (assuming an @code{int} occupies 4 bytes).
4670
4671@item
4672An arbitrarily complex expression, such as @samp{a*b + c/d}. The
4673expression can use any operators valid in the program's native
4674language (@pxref{Languages}).
4675@end itemize
c906108c 4676
fa4727a6
DJ
4677You can set a watchpoint on an expression even if the expression can
4678not be evaluated yet. For instance, you can set a watchpoint on
4679@samp{*global_ptr} before @samp{global_ptr} is initialized.
4680@value{GDBN} will stop when your program sets @samp{global_ptr} and
4681the expression produces a valid value. If the expression becomes
4682valid in some other way than changing a variable (e.g.@: if the memory
4683pointed to by @samp{*global_ptr} becomes readable as the result of a
4684@code{malloc} call), @value{GDBN} may not stop until the next time
4685the expression changes.
4686
82f2d802
EZ
4687@cindex software watchpoints
4688@cindex hardware watchpoints
c906108c 4689Depending on your system, watchpoints may be implemented in software or
2df3850c 4690hardware. @value{GDBN} does software watchpointing by single-stepping your
c906108c
SS
4691program and testing the variable's value each time, which is hundreds of
4692times slower than normal execution. (But this may still be worth it, to
4693catch errors where you have no clue what part of your program is the
4694culprit.)
4695
b1236ac3
PA
4696On some systems, such as most PowerPC or x86-based targets,
4697@value{GDBN} includes support for hardware watchpoints, which do not
4698slow down the running of your program.
c906108c
SS
4699
4700@table @code
4701@kindex watch
5d5658a1 4702@item watch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
fd60e0df
EZ
4703Set a watchpoint for an expression. @value{GDBN} will break when the
4704expression @var{expr} is written into by the program and its value
4705changes. The simplest (and the most popular) use of this command is
4706to watch the value of a single variable:
4707
4708@smallexample
4709(@value{GDBP}) watch foo
4710@end smallexample
c906108c 4711
5d5658a1 4712If the command includes a @code{@r{[}thread @var{thread-id}@r{]}}
9c06b0b4 4713argument, @value{GDBN} breaks only when the thread identified by
5d5658a1 4714@var{thread-id} changes the value of @var{expr}. If any other threads
d8b2a693
JB
4715change the value of @var{expr}, @value{GDBN} will not break. Note
4716that watchpoints restricted to a single thread in this way only work
4717with Hardware Watchpoints.
4718
06a64a0b
TT
4719Ordinarily a watchpoint respects the scope of variables in @var{expr}
4720(see below). The @code{-location} argument tells @value{GDBN} to
4721instead watch the memory referred to by @var{expr}. In this case,
4722@value{GDBN} will evaluate @var{expr}, take the address of the result,
4723and watch the memory at that address. The type of the result is used
4724to determine the size of the watched memory. If the expression's
4725result does not have an address, then @value{GDBN} will print an
4726error.
4727
9c06b0b4
TJB
4728The @code{@r{[}mask @var{maskvalue}@r{]}} argument allows creation
4729of masked watchpoints, if the current architecture supports this
4730feature (e.g., PowerPC Embedded architecture, see @ref{PowerPC
4731Embedded}.) A @dfn{masked watchpoint} specifies a mask in addition
4732to an address to watch. The mask specifies that some bits of an address
4733(the bits which are reset in the mask) should be ignored when matching
4734the address accessed by the inferior against the watchpoint address.
4735Thus, a masked watchpoint watches many addresses simultaneously---those
4736addresses whose unmasked bits are identical to the unmasked bits in the
4737watchpoint address. The @code{mask} argument implies @code{-location}.
4738Examples:
4739
4740@smallexample
4741(@value{GDBP}) watch foo mask 0xffff00ff
4742(@value{GDBP}) watch *0xdeadbeef mask 0xffffff00
4743@end smallexample
4744
c906108c 4745@kindex rwatch
5d5658a1 4746@item rwatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
09d4efe1
EZ
4747Set a watchpoint that will break when the value of @var{expr} is read
4748by the program.
c906108c
SS
4749
4750@kindex awatch
5d5658a1 4751@item awatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
09d4efe1
EZ
4752Set a watchpoint that will break when @var{expr} is either read from
4753or written into by the program.
c906108c 4754
18da0c51
MG
4755@kindex info watchpoints @r{[}@var{list}@dots{}@r{]}
4756@item info watchpoints @r{[}@var{list}@dots{}@r{]}
d77f58be
SS
4757This command prints a list of watchpoints, using the same format as
4758@code{info break} (@pxref{Set Breaks}).
c906108c
SS
4759@end table
4760
65d79d4b
SDJ
4761If you watch for a change in a numerically entered address you need to
4762dereference it, as the address itself is just a constant number which will
4763never change. @value{GDBN} refuses to create a watchpoint that watches
4764a never-changing value:
4765
4766@smallexample
4767(@value{GDBP}) watch 0x600850
4768Cannot watch constant value 0x600850.
4769(@value{GDBP}) watch *(int *) 0x600850
4770Watchpoint 1: *(int *) 6293584
4771@end smallexample
4772
c906108c
SS
4773@value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
4774watchpoints execute very quickly, and the debugger reports a change in
4775value at the exact instruction where the change occurs. If @value{GDBN}
4776cannot set a hardware watchpoint, it sets a software watchpoint, which
4777executes more slowly and reports the change in value at the next
82f2d802
EZ
4778@emph{statement}, not the instruction, after the change occurs.
4779
82f2d802
EZ
4780@cindex use only software watchpoints
4781You can force @value{GDBN} to use only software watchpoints with the
4782@kbd{set can-use-hw-watchpoints 0} command. With this variable set to
4783zero, @value{GDBN} will never try to use hardware watchpoints, even if
4784the underlying system supports them. (Note that hardware-assisted
4785watchpoints that were set @emph{before} setting
4786@code{can-use-hw-watchpoints} to zero will still use the hardware
d3e8051b 4787mechanism of watching expression values.)
c906108c 4788
9c16f35a
EZ
4789@table @code
4790@item set can-use-hw-watchpoints
4791@kindex set can-use-hw-watchpoints
4792Set whether or not to use hardware watchpoints.
4793
4794@item show can-use-hw-watchpoints
4795@kindex show can-use-hw-watchpoints
4796Show the current mode of using hardware watchpoints.
4797@end table
4798
4799For remote targets, you can restrict the number of hardware
4800watchpoints @value{GDBN} will use, see @ref{set remote
4801hardware-breakpoint-limit}.
4802
c906108c
SS
4803When you issue the @code{watch} command, @value{GDBN} reports
4804
474c8240 4805@smallexample
c906108c 4806Hardware watchpoint @var{num}: @var{expr}
474c8240 4807@end smallexample
c906108c
SS
4808
4809@noindent
4810if it was able to set a hardware watchpoint.
4811
7be570e7
JM
4812Currently, the @code{awatch} and @code{rwatch} commands can only set
4813hardware watchpoints, because accesses to data that don't change the
4814value of the watched expression cannot be detected without examining
4815every instruction as it is being executed, and @value{GDBN} does not do
4816that currently. If @value{GDBN} finds that it is unable to set a
4817hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
4818will print a message like this:
4819
4820@smallexample
4821Expression cannot be implemented with read/access watchpoint.
4822@end smallexample
4823
4824Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
4825data type of the watched expression is wider than what a hardware
4826watchpoint on the target machine can handle. For example, some systems
4827can only watch regions that are up to 4 bytes wide; on such systems you
4828cannot set hardware watchpoints for an expression that yields a
4829double-precision floating-point number (which is typically 8 bytes
4830wide). As a work-around, it might be possible to break the large region
4831into a series of smaller ones and watch them with separate watchpoints.
4832
4833If you set too many hardware watchpoints, @value{GDBN} might be unable
4834to insert all of them when you resume the execution of your program.
4835Since the precise number of active watchpoints is unknown until such
4836time as the program is about to be resumed, @value{GDBN} might not be
4837able to warn you about this when you set the watchpoints, and the
4838warning will be printed only when the program is resumed:
4839
4840@smallexample
4841Hardware watchpoint @var{num}: Could not insert watchpoint
4842@end smallexample
4843
4844@noindent
4845If this happens, delete or disable some of the watchpoints.
4846
fd60e0df
EZ
4847Watching complex expressions that reference many variables can also
4848exhaust the resources available for hardware-assisted watchpoints.
4849That's because @value{GDBN} needs to watch every variable in the
4850expression with separately allocated resources.
4851
c906108c 4852If you call a function interactively using @code{print} or @code{call},
2df3850c 4853any watchpoints you have set will be inactive until @value{GDBN} reaches another
c906108c
SS
4854kind of breakpoint or the call completes.
4855
7be570e7
JM
4856@value{GDBN} automatically deletes watchpoints that watch local
4857(automatic) variables, or expressions that involve such variables, when
4858they go out of scope, that is, when the execution leaves the block in
4859which these variables were defined. In particular, when the program
4860being debugged terminates, @emph{all} local variables go out of scope,
4861and so only watchpoints that watch global variables remain set. If you
4862rerun the program, you will need to set all such watchpoints again. One
4863way of doing that would be to set a code breakpoint at the entry to the
4864@code{main} function and when it breaks, set all the watchpoints.
4865
c906108c
SS
4866@cindex watchpoints and threads
4867@cindex threads and watchpoints
d983da9c
DJ
4868In multi-threaded programs, watchpoints will detect changes to the
4869watched expression from every thread.
4870
4871@quotation
4872@emph{Warning:} In multi-threaded programs, software watchpoints
53a5351d
JM
4873have only limited usefulness. If @value{GDBN} creates a software
4874watchpoint, it can only watch the value of an expression @emph{in a
4875single thread}. If you are confident that the expression can only
4876change due to the current thread's activity (and if you are also
4877confident that no other thread can become current), then you can use
4878software watchpoints as usual. However, @value{GDBN} may not notice
4879when a non-current thread's activity changes the expression. (Hardware
4880watchpoints, in contrast, watch an expression in all threads.)
c906108c 4881@end quotation
c906108c 4882
501eef12
AC
4883@xref{set remote hardware-watchpoint-limit}.
4884
6d2ebf8b 4885@node Set Catchpoints
79a6e687 4886@subsection Setting Catchpoints
d4f3574e 4887@cindex catchpoints, setting
c906108c
SS
4888@cindex exception handlers
4889@cindex event handling
4890
4891You can use @dfn{catchpoints} to cause the debugger to stop for certain
b37052ae 4892kinds of program events, such as C@t{++} exceptions or the loading of a
c906108c
SS
4893shared library. Use the @code{catch} command to set a catchpoint.
4894
4895@table @code
4896@kindex catch
4897@item catch @var{event}
697aa1b7 4898Stop when @var{event} occurs. The @var{event} can be any of the following:
591f19e8 4899
c906108c 4900@table @code
cc16e6c9
TT
4901@item throw @r{[}@var{regexp}@r{]}
4902@itemx rethrow @r{[}@var{regexp}@r{]}
4903@itemx catch @r{[}@var{regexp}@r{]}
1a4f73eb
TT
4904@kindex catch throw
4905@kindex catch rethrow
4906@kindex catch catch
4644b6e3 4907@cindex stop on C@t{++} exceptions
591f19e8
TT
4908The throwing, re-throwing, or catching of a C@t{++} exception.
4909
cc16e6c9
TT
4910If @var{regexp} is given, then only exceptions whose type matches the
4911regular expression will be caught.
4912
72f1fe8a
TT
4913@vindex $_exception@r{, convenience variable}
4914The convenience variable @code{$_exception} is available at an
4915exception-related catchpoint, on some systems. This holds the
4916exception being thrown.
4917
591f19e8
TT
4918There are currently some limitations to C@t{++} exception handling in
4919@value{GDBN}:
c906108c 4920
591f19e8
TT
4921@itemize @bullet
4922@item
4923The support for these commands is system-dependent. Currently, only
4924systems using the @samp{gnu-v3} C@t{++} ABI (@pxref{ABI}) are
4925supported.
4926
72f1fe8a 4927@item
cc16e6c9
TT
4928The regular expression feature and the @code{$_exception} convenience
4929variable rely on the presence of some SDT probes in @code{libstdc++}.
4930If these probes are not present, then these features cannot be used.
dee368d3
TT
4931These probes were first available in the GCC 4.8 release, but whether
4932or not they are available in your GCC also depends on how it was
4933built.
72f1fe8a
TT
4934
4935@item
4936The @code{$_exception} convenience variable is only valid at the
4937instruction at which an exception-related catchpoint is set.
4938
591f19e8
TT
4939@item
4940When an exception-related catchpoint is hit, @value{GDBN} stops at a
4941location in the system library which implements runtime exception
4942support for C@t{++}, usually @code{libstdc++}. You can use @code{up}
4943(@pxref{Selection}) to get to your code.
4944
4945@item
4946If you call a function interactively, @value{GDBN} normally returns
4947control to you when the function has finished executing. If the call
4948raises an exception, however, the call may bypass the mechanism that
4949returns control to you and cause your program either to abort or to
4950simply continue running until it hits a breakpoint, catches a signal
4951that @value{GDBN} is listening for, or exits. This is the case even if
4952you set a catchpoint for the exception; catchpoints on exceptions are
4953disabled within interactive calls. @xref{Calling}, for information on
4954controlling this with @code{set unwind-on-terminating-exception}.
4955
4956@item
4957You cannot raise an exception interactively.
4958
4959@item
4960You cannot install an exception handler interactively.
4961@end itemize
c906108c 4962
b8e07335 4963@item exception @r{[}@var{name}@r{]}
1a4f73eb 4964@kindex catch exception
8936fcda
JB
4965@cindex Ada exception catching
4966@cindex catch Ada exceptions
4967An Ada exception being raised. If an exception name is specified
4968at the end of the command (eg @code{catch exception Program_Error}),
4969the debugger will stop only when this specific exception is raised.
4970Otherwise, the debugger stops execution when any Ada exception is raised.
4971
87f67dba
JB
4972When inserting an exception catchpoint on a user-defined exception whose
4973name is identical to one of the exceptions defined by the language, the
4974fully qualified name must be used as the exception name. Otherwise,
4975@value{GDBN} will assume that it should stop on the pre-defined exception
4976rather than the user-defined one. For instance, assuming an exception
4977called @code{Constraint_Error} is defined in package @code{Pck}, then
4978the command to use to catch such exceptions is @kbd{catch exception
4979Pck.Constraint_Error}.
4980
37f6a7f4
TT
4981@vindex $_ada_exception@r{, convenience variable}
4982The convenience variable @code{$_ada_exception} holds the address of
4983the exception being thrown. This can be useful when setting a
4984condition for such a catchpoint.
4985
b8e07335
TT
4986@item exception unhandled
4987@kindex catch exception unhandled
37f6a7f4
TT
4988An exception that was raised but is not handled by the program. The
4989convenience variable @code{$_ada_exception} is set as for @code{catch
4990exception}.
b8e07335
TT
4991
4992@item handlers @r{[}@var{name}@r{]}
9f757bf7
XR
4993@kindex catch handlers
4994@cindex Ada exception handlers catching
4995@cindex catch Ada exceptions when handled
4996An Ada exception being handled. If an exception name is
4997specified at the end of the command
4998 (eg @kbd{catch handlers Program_Error}), the debugger will stop
4999only when this specific exception is handled.
5000Otherwise, the debugger stops execution when any Ada exception is handled.
5001
5002When inserting a handlers catchpoint on a user-defined
5003exception whose name is identical to one of the exceptions
5004defined by the language, the fully qualified name must be used
5005as the exception name. Otherwise, @value{GDBN} will assume that it
5006should stop on the pre-defined exception rather than the
5007user-defined one. For instance, assuming an exception called
5008 @code{Constraint_Error} is defined in package @code{Pck}, then the
5009command to use to catch such exceptions handling is
5010@kbd{catch handlers Pck.Constraint_Error}.
5011
37f6a7f4
TT
5012The convenience variable @code{$_ada_exception} is set as for
5013@code{catch exception}.
5014
8936fcda 5015@item assert
1a4f73eb 5016@kindex catch assert
37f6a7f4
TT
5017A failed Ada assertion. Note that the convenience variable
5018@code{$_ada_exception} is @emph{not} set by this catchpoint.
8936fcda 5019
c906108c 5020@item exec
1a4f73eb 5021@kindex catch exec
4644b6e3 5022@cindex break on fork/exec
b1236ac3 5023A call to @code{exec}.
c906108c 5024
e9076973 5025@anchor{catch syscall}
a96d9b2e 5026@item syscall
e3487908 5027@itemx syscall @r{[}@var{name} @r{|} @var{number} @r{|} @r{group:}@var{groupname} @r{|} @r{g:}@var{groupname}@r{]} @dots{}
1a4f73eb 5028@kindex catch syscall
a96d9b2e
SDJ
5029@cindex break on a system call.
5030A call to or return from a system call, a.k.a.@: @dfn{syscall}. A
5031syscall is a mechanism for application programs to request a service
5032from the operating system (OS) or one of the OS system services.
5033@value{GDBN} can catch some or all of the syscalls issued by the
5034debuggee, and show the related information for each syscall. If no
5035argument is specified, calls to and returns from all system calls
5036will be caught.
5037
5038@var{name} can be any system call name that is valid for the
5039underlying OS. Just what syscalls are valid depends on the OS. On
5040GNU and Unix systems, you can find the full list of valid syscall
5041names on @file{/usr/include/asm/unistd.h}.
5042
5043@c For MS-Windows, the syscall names and the corresponding numbers
5044@c can be found, e.g., on this URL:
5045@c http://www.metasploit.com/users/opcode/syscalls.html
5046@c but we don't support Windows syscalls yet.
5047
5048Normally, @value{GDBN} knows in advance which syscalls are valid for
5049each OS, so you can use the @value{GDBN} command-line completion
5050facilities (@pxref{Completion,, command completion}) to list the
5051available choices.
5052
5053You may also specify the system call numerically. A syscall's
5054number is the value passed to the OS's syscall dispatcher to
5055identify the requested service. When you specify the syscall by its
5056name, @value{GDBN} uses its database of syscalls to convert the name
5057into the corresponding numeric code, but using the number directly
5058may be useful if @value{GDBN}'s database does not have the complete
5059list of syscalls on your system (e.g., because @value{GDBN} lags
5060behind the OS upgrades).
5061
e3487908
GKB
5062You may specify a group of related syscalls to be caught at once using
5063the @code{group:} syntax (@code{g:} is a shorter equivalent). For
5064instance, on some platforms @value{GDBN} allows you to catch all
5065network related syscalls, by passing the argument @code{group:network}
5066to @code{catch syscall}. Note that not all syscall groups are
5067available in every system. You can use the command completion
5068facilities (@pxref{Completion,, command completion}) to list the
5069syscall groups available on your environment.
5070
a96d9b2e
SDJ
5071The example below illustrates how this command works if you don't provide
5072arguments to it:
5073
5074@smallexample
5075(@value{GDBP}) catch syscall
5076Catchpoint 1 (syscall)
5077(@value{GDBP}) r
5078Starting program: /tmp/catch-syscall
5079
5080Catchpoint 1 (call to syscall 'close'), \
5081 0xffffe424 in __kernel_vsyscall ()
5082(@value{GDBP}) c
5083Continuing.
5084
5085Catchpoint 1 (returned from syscall 'close'), \
5086 0xffffe424 in __kernel_vsyscall ()
5087(@value{GDBP})
5088@end smallexample
5089
5090Here is an example of catching a system call by name:
5091
5092@smallexample
5093(@value{GDBP}) catch syscall chroot
5094Catchpoint 1 (syscall 'chroot' [61])
5095(@value{GDBP}) r
5096Starting program: /tmp/catch-syscall
5097
5098Catchpoint 1 (call to syscall 'chroot'), \
5099 0xffffe424 in __kernel_vsyscall ()
5100(@value{GDBP}) c
5101Continuing.
5102
5103Catchpoint 1 (returned from syscall 'chroot'), \
5104 0xffffe424 in __kernel_vsyscall ()
5105(@value{GDBP})
5106@end smallexample
5107
5108An example of specifying a system call numerically. In the case
5109below, the syscall number has a corresponding entry in the XML
5110file, so @value{GDBN} finds its name and prints it:
5111
5112@smallexample
5113(@value{GDBP}) catch syscall 252
5114Catchpoint 1 (syscall(s) 'exit_group')
5115(@value{GDBP}) r
5116Starting program: /tmp/catch-syscall
5117
5118Catchpoint 1 (call to syscall 'exit_group'), \
5119 0xffffe424 in __kernel_vsyscall ()
5120(@value{GDBP}) c
5121Continuing.
5122
5123Program exited normally.
5124(@value{GDBP})
5125@end smallexample
5126
e3487908
GKB
5127Here is an example of catching a syscall group:
5128
5129@smallexample
5130(@value{GDBP}) catch syscall group:process
5131Catchpoint 1 (syscalls 'exit' [1] 'fork' [2] 'waitpid' [7]
5132'execve' [11] 'wait4' [114] 'clone' [120] 'vfork' [190]
5133'exit_group' [252] 'waitid' [284] 'unshare' [310])
5134(@value{GDBP}) r
5135Starting program: /tmp/catch-syscall
5136
5137Catchpoint 1 (call to syscall fork), 0x00007ffff7df4e27 in open64 ()
5138 from /lib64/ld-linux-x86-64.so.2
5139
5140(@value{GDBP}) c
5141Continuing.
5142@end smallexample
5143
a96d9b2e
SDJ
5144However, there can be situations when there is no corresponding name
5145in XML file for that syscall number. In this case, @value{GDBN} prints
5146a warning message saying that it was not able to find the syscall name,
5147but the catchpoint will be set anyway. See the example below:
5148
5149@smallexample
5150(@value{GDBP}) catch syscall 764
5151warning: The number '764' does not represent a known syscall.
5152Catchpoint 2 (syscall 764)
5153(@value{GDBP})
5154@end smallexample
5155
5156If you configure @value{GDBN} using the @samp{--without-expat} option,
5157it will not be able to display syscall names. Also, if your
5158architecture does not have an XML file describing its system calls,
5159you will not be able to see the syscall names. It is important to
5160notice that these two features are used for accessing the syscall
5161name database. In either case, you will see a warning like this:
5162
5163@smallexample
5164(@value{GDBP}) catch syscall
5165warning: Could not open "syscalls/i386-linux.xml"
5166warning: Could not load the syscall XML file 'syscalls/i386-linux.xml'.
5167GDB will not be able to display syscall names.
5168Catchpoint 1 (syscall)
5169(@value{GDBP})
5170@end smallexample
5171
5172Of course, the file name will change depending on your architecture and system.
5173
5174Still using the example above, you can also try to catch a syscall by its
5175number. In this case, you would see something like:
5176
5177@smallexample
5178(@value{GDBP}) catch syscall 252
5179Catchpoint 1 (syscall(s) 252)
5180@end smallexample
5181
5182Again, in this case @value{GDBN} would not be able to display syscall's names.
5183
c906108c 5184@item fork
1a4f73eb 5185@kindex catch fork
b1236ac3 5186A call to @code{fork}.
c906108c
SS
5187
5188@item vfork
1a4f73eb 5189@kindex catch vfork
b1236ac3 5190A call to @code{vfork}.
c906108c 5191
b8e07335
TT
5192@item load @r{[}@var{regexp}@r{]}
5193@itemx unload @r{[}@var{regexp}@r{]}
1a4f73eb
TT
5194@kindex catch load
5195@kindex catch unload
edcc5120
TT
5196The loading or unloading of a shared library. If @var{regexp} is
5197given, then the catchpoint will stop only if the regular expression
5198matches one of the affected libraries.
5199
ab04a2af 5200@item signal @r{[}@var{signal}@dots{} @r{|} @samp{all}@r{]}
1a4f73eb 5201@kindex catch signal
ab04a2af
TT
5202The delivery of a signal.
5203
5204With no arguments, this catchpoint will catch any signal that is not
5205used internally by @value{GDBN}, specifically, all signals except
5206@samp{SIGTRAP} and @samp{SIGINT}.
5207
5208With the argument @samp{all}, all signals, including those used by
5209@value{GDBN}, will be caught. This argument cannot be used with other
5210signal names.
5211
5212Otherwise, the arguments are a list of signal names as given to
5213@code{handle} (@pxref{Signals}). Only signals specified in this list
5214will be caught.
5215
5216One reason that @code{catch signal} can be more useful than
5217@code{handle} is that you can attach commands and conditions to the
5218catchpoint.
5219
5220When a signal is caught by a catchpoint, the signal's @code{stop} and
5221@code{print} settings, as specified by @code{handle}, are ignored.
5222However, whether the signal is still delivered to the inferior depends
5223on the @code{pass} setting; this can be changed in the catchpoint's
5224commands.
5225
c906108c
SS
5226@end table
5227
5228@item tcatch @var{event}
1a4f73eb 5229@kindex tcatch
c906108c
SS
5230Set a catchpoint that is enabled only for one stop. The catchpoint is
5231automatically deleted after the first time the event is caught.
5232
5233@end table
5234
5235Use the @code{info break} command to list the current catchpoints.
5236
c906108c 5237
6d2ebf8b 5238@node Delete Breaks
79a6e687 5239@subsection Deleting Breakpoints
c906108c
SS
5240
5241@cindex clearing breakpoints, watchpoints, catchpoints
5242@cindex deleting breakpoints, watchpoints, catchpoints
5243It is often necessary to eliminate a breakpoint, watchpoint, or
5244catchpoint once it has done its job and you no longer want your program
5245to stop there. This is called @dfn{deleting} the breakpoint. A
5246breakpoint that has been deleted no longer exists; it is forgotten.
5247
5248With the @code{clear} command you can delete breakpoints according to
5249where they are in your program. With the @code{delete} command you can
5250delete individual breakpoints, watchpoints, or catchpoints by specifying
5251their breakpoint numbers.
5252
5253It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
5254automatically ignores breakpoints on the first instruction to be executed
5255when you continue execution without changing the execution address.
5256
5257@table @code
5258@kindex clear
5259@item clear
5260Delete any breakpoints at the next instruction to be executed in the
79a6e687 5261selected stack frame (@pxref{Selection, ,Selecting a Frame}). When
c906108c
SS
5262the innermost frame is selected, this is a good way to delete a
5263breakpoint where your program just stopped.
5264
2a25a5ba
EZ
5265@item clear @var{location}
5266Delete any breakpoints set at the specified @var{location}.
5267@xref{Specify Location}, for the various forms of @var{location}; the
5268most useful ones are listed below:
5269
5270@table @code
c906108c
SS
5271@item clear @var{function}
5272@itemx clear @var{filename}:@var{function}
09d4efe1 5273Delete any breakpoints set at entry to the named @var{function}.
c906108c
SS
5274
5275@item clear @var{linenum}
5276@itemx clear @var{filename}:@var{linenum}
09d4efe1
EZ
5277Delete any breakpoints set at or within the code of the specified
5278@var{linenum} of the specified @var{filename}.
2a25a5ba 5279@end table
c906108c
SS
5280
5281@cindex delete breakpoints
5282@kindex delete
41afff9a 5283@kindex d @r{(@code{delete})}
18da0c51 5284@item delete @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
c5394b80 5285Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
18da0c51 5286list specified as argument. If no argument is specified, delete all
c906108c
SS
5287breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
5288confirm off}). You can abbreviate this command as @code{d}.
5289@end table
5290
6d2ebf8b 5291@node Disabling
79a6e687 5292@subsection Disabling Breakpoints
c906108c 5293
4644b6e3 5294@cindex enable/disable a breakpoint
c906108c
SS
5295Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
5296prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
5297it had been deleted, but remembers the information on the breakpoint so
5298that you can @dfn{enable} it again later.
5299
5300You disable and enable breakpoints, watchpoints, and catchpoints with
d77f58be
SS
5301the @code{enable} and @code{disable} commands, optionally specifying
5302one or more breakpoint numbers as arguments. Use @code{info break} to
5303print a list of all breakpoints, watchpoints, and catchpoints if you
5304do not know which numbers to use.
c906108c 5305
3b784c4f
EZ
5306Disabling and enabling a breakpoint that has multiple locations
5307affects all of its locations.
5308
816338b5
SS
5309A breakpoint, watchpoint, or catchpoint can have any of several
5310different states of enablement:
c906108c
SS
5311
5312@itemize @bullet
5313@item
5314Enabled. The breakpoint stops your program. A breakpoint set
5315with the @code{break} command starts out in this state.
5316@item
5317Disabled. The breakpoint has no effect on your program.
5318@item
5319Enabled once. The breakpoint stops your program, but then becomes
d4f3574e 5320disabled.
c906108c 5321@item
816338b5
SS
5322Enabled for a count. The breakpoint stops your program for the next
5323N times, then becomes disabled.
5324@item
c906108c 5325Enabled for deletion. The breakpoint stops your program, but
d4f3574e
SS
5326immediately after it does so it is deleted permanently. A breakpoint
5327set with the @code{tbreak} command starts out in this state.
c906108c
SS
5328@end itemize
5329
5330You can use the following commands to enable or disable breakpoints,
5331watchpoints, and catchpoints:
5332
5333@table @code
c906108c 5334@kindex disable
41afff9a 5335@kindex dis @r{(@code{disable})}
18da0c51 5336@item disable @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
c906108c
SS
5337Disable the specified breakpoints---or all breakpoints, if none are
5338listed. A disabled breakpoint has no effect but is not forgotten. All
5339options such as ignore-counts, conditions and commands are remembered in
5340case the breakpoint is enabled again later. You may abbreviate
5341@code{disable} as @code{dis}.
5342
c906108c 5343@kindex enable
18da0c51 5344@item enable @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
c906108c
SS
5345Enable the specified breakpoints (or all defined breakpoints). They
5346become effective once again in stopping your program.
5347
18da0c51 5348@item enable @r{[}breakpoints@r{]} once @var{list}@dots{}
c906108c
SS
5349Enable the specified breakpoints temporarily. @value{GDBN} disables any
5350of these breakpoints immediately after stopping your program.
5351
18da0c51 5352@item enable @r{[}breakpoints@r{]} count @var{count} @var{list}@dots{}
816338b5
SS
5353Enable the specified breakpoints temporarily. @value{GDBN} records
5354@var{count} with each of the specified breakpoints, and decrements a
5355breakpoint's count when it is hit. When any count reaches 0,
5356@value{GDBN} disables that breakpoint. If a breakpoint has an ignore
5357count (@pxref{Conditions, ,Break Conditions}), that will be
5358decremented to 0 before @var{count} is affected.
5359
18da0c51 5360@item enable @r{[}breakpoints@r{]} delete @var{list}@dots{}
c906108c
SS
5361Enable the specified breakpoints to work once, then die. @value{GDBN}
5362deletes any of these breakpoints as soon as your program stops there.
09d4efe1 5363Breakpoints set by the @code{tbreak} command start out in this state.
c906108c
SS
5364@end table
5365
d4f3574e
SS
5366@c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
5367@c confusing: tbreak is also initially enabled.
c906108c 5368Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
79a6e687 5369,Setting Breakpoints}), breakpoints that you set are initially enabled;
c906108c
SS
5370subsequently, they become disabled or enabled only when you use one of
5371the commands above. (The command @code{until} can set and delete a
5372breakpoint of its own, but it does not change the state of your other
5373breakpoints; see @ref{Continuing and Stepping, ,Continuing and
79a6e687 5374Stepping}.)
c906108c 5375
6d2ebf8b 5376@node Conditions
79a6e687 5377@subsection Break Conditions
c906108c
SS
5378@cindex conditional breakpoints
5379@cindex breakpoint conditions
5380
5381@c FIXME what is scope of break condition expr? Context where wanted?
5d161b24 5382@c in particular for a watchpoint?
c906108c
SS
5383The simplest sort of breakpoint breaks every time your program reaches a
5384specified place. You can also specify a @dfn{condition} for a
5385breakpoint. A condition is just a Boolean expression in your
5386programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
5387a condition evaluates the expression each time your program reaches it,
5388and your program stops only if the condition is @emph{true}.
5389
5390This is the converse of using assertions for program validation; in that
5391situation, you want to stop when the assertion is violated---that is,
5392when the condition is false. In C, if you want to test an assertion expressed
5393by the condition @var{assert}, you should set the condition
5394@samp{! @var{assert}} on the appropriate breakpoint.
5395
5396Conditions are also accepted for watchpoints; you may not need them,
5397since a watchpoint is inspecting the value of an expression anyhow---but
5398it might be simpler, say, to just set a watchpoint on a variable name,
5399and specify a condition that tests whether the new value is an interesting
5400one.
5401
5402Break conditions can have side effects, and may even call functions in
5403your program. This can be useful, for example, to activate functions
5404that log program progress, or to use your own print functions to
99e008fe 5405format special data structures. The effects are completely predictable
c906108c
SS
5406unless there is another enabled breakpoint at the same address. (In
5407that case, @value{GDBN} might see the other breakpoint first and stop your
5408program without checking the condition of this one.) Note that
d4f3574e
SS
5409breakpoint commands are usually more convenient and flexible than break
5410conditions for the
c906108c 5411purpose of performing side effects when a breakpoint is reached
79a6e687 5412(@pxref{Break Commands, ,Breakpoint Command Lists}).
c906108c 5413
83364271
LM
5414Breakpoint conditions can also be evaluated on the target's side if
5415the target supports it. Instead of evaluating the conditions locally,
5416@value{GDBN} encodes the expression into an agent expression
5417(@pxref{Agent Expressions}) suitable for execution on the target,
5418independently of @value{GDBN}. Global variables become raw memory
5419locations, locals become stack accesses, and so forth.
5420
5421In this case, @value{GDBN} will only be notified of a breakpoint trigger
5422when its condition evaluates to true. This mechanism may provide faster
5423response times depending on the performance characteristics of the target
5424since it does not need to keep @value{GDBN} informed about
5425every breakpoint trigger, even those with false conditions.
5426
c906108c
SS
5427Break conditions can be specified when a breakpoint is set, by using
5428@samp{if} in the arguments to the @code{break} command. @xref{Set
79a6e687 5429Breaks, ,Setting Breakpoints}. They can also be changed at any time
c906108c 5430with the @code{condition} command.
53a5351d 5431
c906108c
SS
5432You can also use the @code{if} keyword with the @code{watch} command.
5433The @code{catch} command does not recognize the @code{if} keyword;
5434@code{condition} is the only way to impose a further condition on a
5435catchpoint.
c906108c
SS
5436
5437@table @code
5438@kindex condition
5439@item condition @var{bnum} @var{expression}
5440Specify @var{expression} as the break condition for breakpoint,
5441watchpoint, or catchpoint number @var{bnum}. After you set a condition,
5442breakpoint @var{bnum} stops your program only if the value of
5443@var{expression} is true (nonzero, in C). When you use
5444@code{condition}, @value{GDBN} checks @var{expression} immediately for
5445syntactic correctness, and to determine whether symbols in it have
d4f3574e
SS
5446referents in the context of your breakpoint. If @var{expression} uses
5447symbols not referenced in the context of the breakpoint, @value{GDBN}
5448prints an error message:
5449
474c8240 5450@smallexample
d4f3574e 5451No symbol "foo" in current context.
474c8240 5452@end smallexample
d4f3574e
SS
5453
5454@noindent
c906108c
SS
5455@value{GDBN} does
5456not actually evaluate @var{expression} at the time the @code{condition}
d4f3574e
SS
5457command (or a command that sets a breakpoint with a condition, like
5458@code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
c906108c
SS
5459
5460@item condition @var{bnum}
5461Remove the condition from breakpoint number @var{bnum}. It becomes
5462an ordinary unconditional breakpoint.
5463@end table
5464
5465@cindex ignore count (of breakpoint)
5466A special case of a breakpoint condition is to stop only when the
5467breakpoint has been reached a certain number of times. This is so
5468useful that there is a special way to do it, using the @dfn{ignore
5469count} of the breakpoint. Every breakpoint has an ignore count, which
5470is an integer. Most of the time, the ignore count is zero, and
5471therefore has no effect. But if your program reaches a breakpoint whose
5472ignore count is positive, then instead of stopping, it just decrements
5473the ignore count by one and continues. As a result, if the ignore count
5474value is @var{n}, the breakpoint does not stop the next @var{n} times
5475your program reaches it.
5476
5477@table @code
5478@kindex ignore
5479@item ignore @var{bnum} @var{count}
5480Set the ignore count of breakpoint number @var{bnum} to @var{count}.
5481The next @var{count} times the breakpoint is reached, your program's
5482execution does not stop; other than to decrement the ignore count, @value{GDBN}
5483takes no action.
5484
5485To make the breakpoint stop the next time it is reached, specify
5486a count of zero.
5487
5488When you use @code{continue} to resume execution of your program from a
5489breakpoint, you can specify an ignore count directly as an argument to
5490@code{continue}, rather than using @code{ignore}. @xref{Continuing and
79a6e687 5491Stepping,,Continuing and Stepping}.
c906108c
SS
5492
5493If a breakpoint has a positive ignore count and a condition, the
5494condition is not checked. Once the ignore count reaches zero,
5495@value{GDBN} resumes checking the condition.
5496
5497You could achieve the effect of the ignore count with a condition such
5498as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
5499is decremented each time. @xref{Convenience Vars, ,Convenience
79a6e687 5500Variables}.
c906108c
SS
5501@end table
5502
5503Ignore counts apply to breakpoints, watchpoints, and catchpoints.
5504
5505
6d2ebf8b 5506@node Break Commands
79a6e687 5507@subsection Breakpoint Command Lists
c906108c
SS
5508
5509@cindex breakpoint commands
5510You can give any breakpoint (or watchpoint or catchpoint) a series of
5511commands to execute when your program stops due to that breakpoint. For
5512example, you might want to print the values of certain expressions, or
5513enable other breakpoints.
5514
5515@table @code
5516@kindex commands
ca91424e 5517@kindex end@r{ (breakpoint commands)}
18da0c51 5518@item commands @r{[}@var{list}@dots{}@r{]}
c906108c
SS
5519@itemx @dots{} @var{command-list} @dots{}
5520@itemx end
95a42b64 5521Specify a list of commands for the given breakpoints. The commands
c906108c
SS
5522themselves appear on the following lines. Type a line containing just
5523@code{end} to terminate the commands.
5524
5525To remove all commands from a breakpoint, type @code{commands} and
5526follow it immediately with @code{end}; that is, give no commands.
5527
95a42b64
TT
5528With no argument, @code{commands} refers to the last breakpoint,
5529watchpoint, or catchpoint set (not to the breakpoint most recently
5530encountered). If the most recent breakpoints were set with a single
5531command, then the @code{commands} will apply to all the breakpoints
5532set by that command. This applies to breakpoints set by
86b17b60
PA
5533@code{rbreak}, and also applies when a single @code{break} command
5534creates multiple breakpoints (@pxref{Ambiguous Expressions,,Ambiguous
5535Expressions}).
c906108c
SS
5536@end table
5537
5538Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
5539disabled within a @var{command-list}.
5540
5541You can use breakpoint commands to start your program up again. Simply
5542use the @code{continue} command, or @code{step}, or any other command
5543that resumes execution.
5544
5545Any other commands in the command list, after a command that resumes
5546execution, are ignored. This is because any time you resume execution
5547(even with a simple @code{next} or @code{step}), you may encounter
5548another breakpoint---which could have its own command list, leading to
5549ambiguities about which list to execute.
5550
5551@kindex silent
5552If the first command you specify in a command list is @code{silent}, the
5553usual message about stopping at a breakpoint is not printed. This may
5554be desirable for breakpoints that are to print a specific message and
5555then continue. If none of the remaining commands print anything, you
5556see no sign that the breakpoint was reached. @code{silent} is
5557meaningful only at the beginning of a breakpoint command list.
5558
5559The commands @code{echo}, @code{output}, and @code{printf} allow you to
5560print precisely controlled output, and are often useful in silent
79a6e687 5561breakpoints. @xref{Output, ,Commands for Controlled Output}.
c906108c
SS
5562
5563For example, here is how you could use breakpoint commands to print the
5564value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
5565
474c8240 5566@smallexample
c906108c
SS
5567break foo if x>0
5568commands
5569silent
5570printf "x is %d\n",x
5571cont
5572end
474c8240 5573@end smallexample
c906108c
SS
5574
5575One application for breakpoint commands is to compensate for one bug so
5576you can test for another. Put a breakpoint just after the erroneous line
5577of code, give it a condition to detect the case in which something
5578erroneous has been done, and give it commands to assign correct values
5579to any variables that need them. End with the @code{continue} command
5580so that your program does not stop, and start with the @code{silent}
5581command so that no output is produced. Here is an example:
5582
474c8240 5583@smallexample
c906108c
SS
5584break 403
5585commands
5586silent
5587set x = y + 4
5588cont
5589end
474c8240 5590@end smallexample
c906108c 5591
e7e0cddf
SS
5592@node Dynamic Printf
5593@subsection Dynamic Printf
5594
5595@cindex dynamic printf
5596@cindex dprintf
5597The dynamic printf command @code{dprintf} combines a breakpoint with
5598formatted printing of your program's data to give you the effect of
5599inserting @code{printf} calls into your program on-the-fly, without
5600having to recompile it.
5601
5602In its most basic form, the output goes to the GDB console. However,
5603you can set the variable @code{dprintf-style} for alternate handling.
5604For instance, you can ask to format the output by calling your
5605program's @code{printf} function. This has the advantage that the
5606characters go to the program's output device, so they can recorded in
5607redirects to files and so forth.
5608
d3ce09f5
SS
5609If you are doing remote debugging with a stub or agent, you can also
5610ask to have the printf handled by the remote agent. In addition to
5611ensuring that the output goes to the remote program's device along
5612with any other output the program might produce, you can also ask that
5613the dprintf remain active even after disconnecting from the remote
5614target. Using the stub/agent is also more efficient, as it can do
5615everything without needing to communicate with @value{GDBN}.
5616
e7e0cddf
SS
5617@table @code
5618@kindex dprintf
5619@item dprintf @var{location},@var{template},@var{expression}[,@var{expression}@dots{}]
5620Whenever execution reaches @var{location}, print the values of one or
5621more @var{expressions} under the control of the string @var{template}.
5622To print several values, separate them with commas.
5623
5624@item set dprintf-style @var{style}
5625Set the dprintf output to be handled in one of several different
5626styles enumerated below. A change of style affects all existing
5627dynamic printfs immediately. (If you need individual control over the
5628print commands, simply define normal breakpoints with
5629explicitly-supplied command lists.)
5630
18da0c51 5631@table @code
e7e0cddf
SS
5632@item gdb
5633@kindex dprintf-style gdb
5634Handle the output using the @value{GDBN} @code{printf} command.
5635
5636@item call
5637@kindex dprintf-style call
5638Handle the output by calling a function in your program (normally
5639@code{printf}).
5640
d3ce09f5
SS
5641@item agent
5642@kindex dprintf-style agent
5643Have the remote debugging agent (such as @code{gdbserver}) handle
5644the output itself. This style is only available for agents that
5645support running commands on the target.
18da0c51 5646@end table
d3ce09f5 5647
e7e0cddf
SS
5648@item set dprintf-function @var{function}
5649Set the function to call if the dprintf style is @code{call}. By
5650default its value is @code{printf}. You may set it to any expression.
5651that @value{GDBN} can evaluate to a function, as per the @code{call}
5652command.
5653
5654@item set dprintf-channel @var{channel}
5655Set a ``channel'' for dprintf. If set to a non-empty value,
5656@value{GDBN} will evaluate it as an expression and pass the result as
5657a first argument to the @code{dprintf-function}, in the manner of
5658@code{fprintf} and similar functions. Otherwise, the dprintf format
5659string will be the first argument, in the manner of @code{printf}.
5660
5661As an example, if you wanted @code{dprintf} output to go to a logfile
5662that is a standard I/O stream assigned to the variable @code{mylog},
5663you could do the following:
5664
5665@example
5666(gdb) set dprintf-style call
5667(gdb) set dprintf-function fprintf
5668(gdb) set dprintf-channel mylog
5669(gdb) dprintf 25,"at line 25, glob=%d\n",glob
5670Dprintf 1 at 0x123456: file main.c, line 25.
5671(gdb) info break
56721 dprintf keep y 0x00123456 in main at main.c:25
5673 call (void) fprintf (mylog,"at line 25, glob=%d\n",glob)
5674 continue
5675(gdb)
5676@end example
5677
5678Note that the @code{info break} displays the dynamic printf commands
5679as normal breakpoint commands; you can thus easily see the effect of
5680the variable settings.
5681
d3ce09f5
SS
5682@item set disconnected-dprintf on
5683@itemx set disconnected-dprintf off
5684@kindex set disconnected-dprintf
5685Choose whether @code{dprintf} commands should continue to run if
5686@value{GDBN} has disconnected from the target. This only applies
5687if the @code{dprintf-style} is @code{agent}.
5688
5689@item show disconnected-dprintf off
5690@kindex show disconnected-dprintf
5691Show the current choice for disconnected @code{dprintf}.
5692
e7e0cddf
SS
5693@end table
5694
5695@value{GDBN} does not check the validity of function and channel,
5696relying on you to supply values that are meaningful for the contexts
5697in which they are being used. For instance, the function and channel
5698may be the values of local variables, but if that is the case, then
5699all enabled dynamic prints must be at locations within the scope of
5700those locals. If evaluation fails, @value{GDBN} will report an error.
5701
6149aea9
PA
5702@node Save Breakpoints
5703@subsection How to save breakpoints to a file
5704
5705To save breakpoint definitions to a file use the @w{@code{save
5706breakpoints}} command.
5707
5708@table @code
5709@kindex save breakpoints
5710@cindex save breakpoints to a file for future sessions
5711@item save breakpoints [@var{filename}]
5712This command saves all current breakpoint definitions together with
5713their commands and ignore counts, into a file @file{@var{filename}}
5714suitable for use in a later debugging session. This includes all
5715types of breakpoints (breakpoints, watchpoints, catchpoints,
5716tracepoints). To read the saved breakpoint definitions, use the
5717@code{source} command (@pxref{Command Files}). Note that watchpoints
5718with expressions involving local variables may fail to be recreated
5719because it may not be possible to access the context where the
5720watchpoint is valid anymore. Because the saved breakpoint definitions
5721are simply a sequence of @value{GDBN} commands that recreate the
5722breakpoints, you can edit the file in your favorite editing program,
5723and remove the breakpoint definitions you're not interested in, or
5724that can no longer be recreated.
5725@end table
5726
62e5f89c
SDJ
5727@node Static Probe Points
5728@subsection Static Probe Points
5729
5730@cindex static probe point, SystemTap
3133f8c1 5731@cindex static probe point, DTrace
62e5f89c
SDJ
5732@value{GDBN} supports @dfn{SDT} probes in the code. @acronym{SDT} stands
5733for Statically Defined Tracing, and the probes are designed to have a tiny
3133f8c1
JM
5734runtime code and data footprint, and no dynamic relocations.
5735
5736Currently, the following types of probes are supported on
5737ELF-compatible systems:
5738
5739@itemize @bullet
62e5f89c 5740
3133f8c1
JM
5741@item @code{SystemTap} (@uref{http://sourceware.org/systemtap/})
5742@acronym{SDT} probes@footnote{See
62e5f89c 5743@uref{http://sourceware.org/systemtap/wiki/AddingUserSpaceProbingToApps}
3133f8c1
JM
5744for more information on how to add @code{SystemTap} @acronym{SDT}
5745probes in your applications.}. @code{SystemTap} probes are usable
5746from assembly, C and C@t{++} languages@footnote{See
5747@uref{http://sourceware.org/systemtap/wiki/UserSpaceProbeImplementation}
5748for a good reference on how the @acronym{SDT} probes are implemented.}.
5749
5750@item @code{DTrace} (@uref{http://oss.oracle.com/projects/DTrace})
5751@acronym{USDT} probes. @code{DTrace} probes are usable from C and
5752C@t{++} languages.
5753@end itemize
62e5f89c
SDJ
5754
5755@cindex semaphores on static probe points
3133f8c1
JM
5756Some @code{SystemTap} probes have an associated semaphore variable;
5757for instance, this happens automatically if you defined your probe
5758using a DTrace-style @file{.d} file. If your probe has a semaphore,
5759@value{GDBN} will automatically enable it when you specify a
5760breakpoint using the @samp{-probe-stap} notation. But, if you put a
5761breakpoint at a probe's location by some other method (e.g.,
5762@code{break file:line}), then @value{GDBN} will not automatically set
5763the semaphore. @code{DTrace} probes do not support semaphores.
62e5f89c
SDJ
5764
5765You can examine the available static static probes using @code{info
5766probes}, with optional arguments:
5767
5768@table @code
5769@kindex info probes
3133f8c1
JM
5770@item info probes @r{[}@var{type}@r{]} @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5771If given, @var{type} is either @code{stap} for listing
5772@code{SystemTap} probes or @code{dtrace} for listing @code{DTrace}
5773probes. If omitted all probes are listed regardless of their types.
5774
62e5f89c
SDJ
5775If given, @var{provider} is a regular expression used to match against provider
5776names when selecting which probes to list. If omitted, probes by all
5777probes from all providers are listed.
5778
5779If given, @var{name} is a regular expression to match against probe names
5780when selecting which probes to list. If omitted, probe names are not
5781considered when deciding whether to display them.
5782
5783If given, @var{objfile} is a regular expression used to select which
5784object files (executable or shared libraries) to examine. If not
5785given, all object files are considered.
5786
5787@item info probes all
5788List the available static probes, from all types.
5789@end table
5790
9aca2ff8
JM
5791@cindex enabling and disabling probes
5792Some probe points can be enabled and/or disabled. The effect of
5793enabling or disabling a probe depends on the type of probe being
3133f8c1
JM
5794handled. Some @code{DTrace} probes can be enabled or
5795disabled, but @code{SystemTap} probes cannot be disabled.
9aca2ff8
JM
5796
5797You can enable (or disable) one or more probes using the following
5798commands, with optional arguments:
5799
5800@table @code
5801@kindex enable probes
5802@item enable probes @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5803If given, @var{provider} is a regular expression used to match against
5804provider names when selecting which probes to enable. If omitted,
5805all probes from all providers are enabled.
5806
5807If given, @var{name} is a regular expression to match against probe
5808names when selecting which probes to enable. If omitted, probe names
5809are not considered when deciding whether to enable them.
5810
5811If given, @var{objfile} is a regular expression used to select which
5812object files (executable or shared libraries) to examine. If not
5813given, all object files are considered.
5814
5815@kindex disable probes
5816@item disable probes @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5817See the @code{enable probes} command above for a description of the
5818optional arguments accepted by this command.
5819@end table
5820
62e5f89c
SDJ
5821@vindex $_probe_arg@r{, convenience variable}
5822A probe may specify up to twelve arguments. These are available at the
5823point at which the probe is defined---that is, when the current PC is
5824at the probe's location. The arguments are available using the
5825convenience variables (@pxref{Convenience Vars})
3133f8c1
JM
5826@code{$_probe_arg0}@dots{}@code{$_probe_arg11}. In @code{SystemTap}
5827probes each probe argument is an integer of the appropriate size;
5828types are not preserved. In @code{DTrace} probes types are preserved
5829provided that they are recognized as such by @value{GDBN}; otherwise
5830the value of the probe argument will be a long integer. The
62e5f89c
SDJ
5831convenience variable @code{$_probe_argc} holds the number of arguments
5832at the current probe point.
5833
5834These variables are always available, but attempts to access them at
5835any location other than a probe point will cause @value{GDBN} to give
5836an error message.
5837
5838
c906108c 5839@c @ifclear BARETARGET
6d2ebf8b 5840@node Error in Breakpoints
d4f3574e 5841@subsection ``Cannot insert breakpoints''
c906108c 5842
fa3a767f
PA
5843If you request too many active hardware-assisted breakpoints and
5844watchpoints, you will see this error message:
d4f3574e
SS
5845
5846@c FIXME: the precise wording of this message may change; the relevant
5847@c source change is not committed yet (Sep 3, 1999).
5848@smallexample
5849Stopped; cannot insert breakpoints.
5850You may have requested too many hardware breakpoints and watchpoints.
5851@end smallexample
5852
5853@noindent
5854This message is printed when you attempt to resume the program, since
5855only then @value{GDBN} knows exactly how many hardware breakpoints and
5856watchpoints it needs to insert.
5857
5858When this message is printed, you need to disable or remove some of the
5859hardware-assisted breakpoints and watchpoints, and then continue.
5860
79a6e687 5861@node Breakpoint-related Warnings
1485d690
KB
5862@subsection ``Breakpoint address adjusted...''
5863@cindex breakpoint address adjusted
5864
5865Some processor architectures place constraints on the addresses at
5866which breakpoints may be placed. For architectures thus constrained,
5867@value{GDBN} will attempt to adjust the breakpoint's address to comply
5868with the constraints dictated by the architecture.
5869
5870One example of such an architecture is the Fujitsu FR-V. The FR-V is
5871a VLIW architecture in which a number of RISC-like instructions may be
5872bundled together for parallel execution. The FR-V architecture
5873constrains the location of a breakpoint instruction within such a
5874bundle to the instruction with the lowest address. @value{GDBN}
5875honors this constraint by adjusting a breakpoint's address to the
5876first in the bundle.
5877
5878It is not uncommon for optimized code to have bundles which contain
5879instructions from different source statements, thus it may happen that
5880a breakpoint's address will be adjusted from one source statement to
5881another. Since this adjustment may significantly alter @value{GDBN}'s
5882breakpoint related behavior from what the user expects, a warning is
5883printed when the breakpoint is first set and also when the breakpoint
5884is hit.
5885
5886A warning like the one below is printed when setting a breakpoint
5887that's been subject to address adjustment:
5888
5889@smallexample
5890warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
5891@end smallexample
5892
5893Such warnings are printed both for user settable and @value{GDBN}'s
5894internal breakpoints. If you see one of these warnings, you should
5895verify that a breakpoint set at the adjusted address will have the
5896desired affect. If not, the breakpoint in question may be removed and
b383017d 5897other breakpoints may be set which will have the desired behavior.
1485d690
KB
5898E.g., it may be sufficient to place the breakpoint at a later
5899instruction. A conditional breakpoint may also be useful in some
5900cases to prevent the breakpoint from triggering too often.
5901
5902@value{GDBN} will also issue a warning when stopping at one of these
5903adjusted breakpoints:
5904
5905@smallexample
5906warning: Breakpoint 1 address previously adjusted from 0x00010414
5907to 0x00010410.
5908@end smallexample
5909
5910When this warning is encountered, it may be too late to take remedial
5911action except in cases where the breakpoint is hit earlier or more
5912frequently than expected.
d4f3574e 5913
6d2ebf8b 5914@node Continuing and Stepping
79a6e687 5915@section Continuing and Stepping
c906108c
SS
5916
5917@cindex stepping
5918@cindex continuing
5919@cindex resuming execution
5920@dfn{Continuing} means resuming program execution until your program
5921completes normally. In contrast, @dfn{stepping} means executing just
5922one more ``step'' of your program, where ``step'' may mean either one
5923line of source code, or one machine instruction (depending on what
7a292a7a
SS
5924particular command you use). Either when continuing or when stepping,
5925your program may stop even sooner, due to a breakpoint or a signal. (If
d4f3574e 5926it stops due to a signal, you may want to use @code{handle}, or use
e5f8a7cc
PA
5927@samp{signal 0} to resume execution (@pxref{Signals, ,Signals}),
5928or you may step into the signal's handler (@pxref{stepping and signal
5929handlers}).)
c906108c
SS
5930
5931@table @code
5932@kindex continue
41afff9a
EZ
5933@kindex c @r{(@code{continue})}
5934@kindex fg @r{(resume foreground execution)}
c906108c
SS
5935@item continue @r{[}@var{ignore-count}@r{]}
5936@itemx c @r{[}@var{ignore-count}@r{]}
5937@itemx fg @r{[}@var{ignore-count}@r{]}
5938Resume program execution, at the address where your program last stopped;
5939any breakpoints set at that address are bypassed. The optional argument
5940@var{ignore-count} allows you to specify a further number of times to
5941ignore a breakpoint at this location; its effect is like that of
79a6e687 5942@code{ignore} (@pxref{Conditions, ,Break Conditions}).
c906108c
SS
5943
5944The argument @var{ignore-count} is meaningful only when your program
5945stopped due to a breakpoint. At other times, the argument to
5946@code{continue} is ignored.
5947
d4f3574e
SS
5948The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
5949debugged program is deemed to be the foreground program) are provided
5950purely for convenience, and have exactly the same behavior as
5951@code{continue}.
c906108c
SS
5952@end table
5953
5954To resume execution at a different place, you can use @code{return}
79a6e687 5955(@pxref{Returning, ,Returning from a Function}) to go back to the
c906108c 5956calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
79a6e687 5957Different Address}) to go to an arbitrary location in your program.
c906108c
SS
5958
5959A typical technique for using stepping is to set a breakpoint
79a6e687 5960(@pxref{Breakpoints, ,Breakpoints; Watchpoints; and Catchpoints}) at the
c906108c
SS
5961beginning of the function or the section of your program where a problem
5962is believed to lie, run your program until it stops at that breakpoint,
5963and then step through the suspect area, examining the variables that are
5964interesting, until you see the problem happen.
5965
5966@table @code
5967@kindex step
41afff9a 5968@kindex s @r{(@code{step})}
c906108c
SS
5969@item step
5970Continue running your program until control reaches a different source
5971line, then stop it and return control to @value{GDBN}. This command is
5972abbreviated @code{s}.
5973
5974@quotation
5975@c "without debugging information" is imprecise; actually "without line
5976@c numbers in the debugging information". (gcc -g1 has debugging info but
5977@c not line numbers). But it seems complex to try to make that
5978@c distinction here.
5979@emph{Warning:} If you use the @code{step} command while control is
5980within a function that was compiled without debugging information,
5981execution proceeds until control reaches a function that does have
5982debugging information. Likewise, it will not step into a function which
5983is compiled without debugging information. To step through functions
5984without debugging information, use the @code{stepi} command, described
5985below.
5986@end quotation
5987
4a92d011
EZ
5988The @code{step} command only stops at the first instruction of a source
5989line. This prevents the multiple stops that could otherwise occur in
5990@code{switch} statements, @code{for} loops, etc. @code{step} continues
5991to stop if a function that has debugging information is called within
5992the line. In other words, @code{step} @emph{steps inside} any functions
5993called within the line.
c906108c 5994
d4f3574e
SS
5995Also, the @code{step} command only enters a function if there is line
5996number information for the function. Otherwise it acts like the
5d161b24 5997@code{next} command. This avoids problems when using @code{cc -gl}
eb17f351 5998on @acronym{MIPS} machines. Previously, @code{step} entered subroutines if there
5d161b24 5999was any debugging information about the routine.
c906108c
SS
6000
6001@item step @var{count}
6002Continue running as in @code{step}, but do so @var{count} times. If a
7a292a7a
SS
6003breakpoint is reached, or a signal not related to stepping occurs before
6004@var{count} steps, stepping stops right away.
c906108c
SS
6005
6006@kindex next
41afff9a 6007@kindex n @r{(@code{next})}
c906108c
SS
6008@item next @r{[}@var{count}@r{]}
6009Continue to the next source line in the current (innermost) stack frame.
7a292a7a
SS
6010This is similar to @code{step}, but function calls that appear within
6011the line of code are executed without stopping. Execution stops when
6012control reaches a different line of code at the original stack level
6013that was executing when you gave the @code{next} command. This command
6014is abbreviated @code{n}.
c906108c
SS
6015
6016An argument @var{count} is a repeat count, as for @code{step}.
6017
6018
6019@c FIX ME!! Do we delete this, or is there a way it fits in with
6020@c the following paragraph? --- Vctoria
6021@c
6022@c @code{next} within a function that lacks debugging information acts like
6023@c @code{step}, but any function calls appearing within the code of the
6024@c function are executed without stopping.
6025
d4f3574e
SS
6026The @code{next} command only stops at the first instruction of a
6027source line. This prevents multiple stops that could otherwise occur in
4a92d011 6028@code{switch} statements, @code{for} loops, etc.
c906108c 6029
b90a5f51
CF
6030@kindex set step-mode
6031@item set step-mode
6032@cindex functions without line info, and stepping
6033@cindex stepping into functions with no line info
6034@itemx set step-mode on
4a92d011 6035The @code{set step-mode on} command causes the @code{step} command to
b90a5f51
CF
6036stop at the first instruction of a function which contains no debug line
6037information rather than stepping over it.
6038
4a92d011
EZ
6039This is useful in cases where you may be interested in inspecting the
6040machine instructions of a function which has no symbolic info and do not
6041want @value{GDBN} to automatically skip over this function.
b90a5f51
CF
6042
6043@item set step-mode off
4a92d011 6044Causes the @code{step} command to step over any functions which contains no
b90a5f51
CF
6045debug information. This is the default.
6046
9c16f35a
EZ
6047@item show step-mode
6048Show whether @value{GDBN} will stop in or step over functions without
6049source line debug information.
6050
c906108c 6051@kindex finish
8dfa32fc 6052@kindex fin @r{(@code{finish})}
c906108c
SS
6053@item finish
6054Continue running until just after function in the selected stack frame
8dfa32fc
JB
6055returns. Print the returned value (if any). This command can be
6056abbreviated as @code{fin}.
c906108c
SS
6057
6058Contrast this with the @code{return} command (@pxref{Returning,
79a6e687 6059,Returning from a Function}).
c906108c 6060
000439d5
TT
6061@kindex set print finish
6062@kindex show print finish
6063@item set print finish @r{[}on|off@r{]}
6064@itemx show print finish
6065By default the @code{finish} command will show the value that is
6066returned by the function. This can be disabled using @code{set print
6067finish off}. When disabled, the value is still entered into the value
6068history (@pxref{Value History}), but not displayed.
6069
c906108c 6070@kindex until
41afff9a 6071@kindex u @r{(@code{until})}
09d4efe1 6072@cindex run until specified location
c906108c
SS
6073@item until
6074@itemx u
6075Continue running until a source line past the current line, in the
6076current stack frame, is reached. This command is used to avoid single
6077stepping through a loop more than once. It is like the @code{next}
6078command, except that when @code{until} encounters a jump, it
6079automatically continues execution until the program counter is greater
6080than the address of the jump.
6081
6082This means that when you reach the end of a loop after single stepping
6083though it, @code{until} makes your program continue execution until it
6084exits the loop. In contrast, a @code{next} command at the end of a loop
6085simply steps back to the beginning of the loop, which forces you to step
6086through the next iteration.
6087
6088@code{until} always stops your program if it attempts to exit the current
6089stack frame.
6090
6091@code{until} may produce somewhat counterintuitive results if the order
6092of machine code does not match the order of the source lines. For
6093example, in the following excerpt from a debugging session, the @code{f}
6094(@code{frame}) command shows that execution is stopped at line
6095@code{206}; yet when we use @code{until}, we get to line @code{195}:
6096
474c8240 6097@smallexample
c906108c
SS
6098(@value{GDBP}) f
6099#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
6100206 expand_input();
6101(@value{GDBP}) until
6102195 for ( ; argc > 0; NEXTARG) @{
474c8240 6103@end smallexample
c906108c
SS
6104
6105This happened because, for execution efficiency, the compiler had
6106generated code for the loop closure test at the end, rather than the
6107start, of the loop---even though the test in a C @code{for}-loop is
6108written before the body of the loop. The @code{until} command appeared
6109to step back to the beginning of the loop when it advanced to this
6110expression; however, it has not really gone to an earlier
6111statement---not in terms of the actual machine code.
6112
6113@code{until} with no argument works by means of single
6114instruction stepping, and hence is slower than @code{until} with an
6115argument.
6116
6117@item until @var{location}
6118@itemx u @var{location}
697aa1b7
EZ
6119Continue running your program until either the specified @var{location} is
6120reached, or the current stack frame returns. The location is any of
2a25a5ba
EZ
6121the forms described in @ref{Specify Location}.
6122This form of the command uses temporary breakpoints, and
c60eb6f1
EZ
6123hence is quicker than @code{until} without an argument. The specified
6124location is actually reached only if it is in the current frame. This
6125implies that @code{until} can be used to skip over recursive function
6126invocations. For instance in the code below, if the current location is
6127line @code{96}, issuing @code{until 99} will execute the program up to
db2e3e2e 6128line @code{99} in the same invocation of factorial, i.e., after the inner
c60eb6f1
EZ
6129invocations have returned.
6130
6131@smallexample
613294 int factorial (int value)
613395 @{
613496 if (value > 1) @{
613597 value *= factorial (value - 1);
613698 @}
613799 return (value);
6138100 @}
6139@end smallexample
6140
6141
6142@kindex advance @var{location}
984359d2 6143@item advance @var{location}
09d4efe1 6144Continue running the program up to the given @var{location}. An argument is
2a25a5ba
EZ
6145required, which should be of one of the forms described in
6146@ref{Specify Location}.
6147Execution will also stop upon exit from the current stack
c60eb6f1
EZ
6148frame. This command is similar to @code{until}, but @code{advance} will
6149not skip over recursive function calls, and the target location doesn't
6150have to be in the same frame as the current one.
6151
c906108c
SS
6152
6153@kindex stepi
41afff9a 6154@kindex si @r{(@code{stepi})}
c906108c 6155@item stepi
96a2c332 6156@itemx stepi @var{arg}
c906108c
SS
6157@itemx si
6158Execute one machine instruction, then stop and return to the debugger.
6159
6160It is often useful to do @samp{display/i $pc} when stepping by machine
6161instructions. This makes @value{GDBN} automatically display the next
6162instruction to be executed, each time your program stops. @xref{Auto
79a6e687 6163Display,, Automatic Display}.
c906108c
SS
6164
6165An argument is a repeat count, as in @code{step}.
6166
6167@need 750
6168@kindex nexti
41afff9a 6169@kindex ni @r{(@code{nexti})}
c906108c 6170@item nexti
96a2c332 6171@itemx nexti @var{arg}
c906108c
SS
6172@itemx ni
6173Execute one machine instruction, but if it is a function call,
6174proceed until the function returns.
6175
6176An argument is a repeat count, as in @code{next}.
c1e36e3e
PA
6177
6178@end table
6179
6180@anchor{range stepping}
6181@cindex range stepping
6182@cindex target-assisted range stepping
6183By default, and if available, @value{GDBN} makes use of
6184target-assisted @dfn{range stepping}. In other words, whenever you
6185use a stepping command (e.g., @code{step}, @code{next}), @value{GDBN}
6186tells the target to step the corresponding range of instruction
6187addresses instead of issuing multiple single-steps. This speeds up
6188line stepping, particularly for remote targets. Ideally, there should
6189be no reason you would want to turn range stepping off. However, it's
6190possible that a bug in the debug info, a bug in the remote stub (for
6191remote targets), or even a bug in @value{GDBN} could make line
6192stepping behave incorrectly when target-assisted range stepping is
6193enabled. You can use the following command to turn off range stepping
6194if necessary:
6195
6196@table @code
6197@kindex set range-stepping
6198@kindex show range-stepping
6199@item set range-stepping
6200@itemx show range-stepping
6201Control whether range stepping is enabled.
6202
6203If @code{on}, and the target supports it, @value{GDBN} tells the
6204target to step a range of addresses itself, instead of issuing
6205multiple single-steps. If @code{off}, @value{GDBN} always issues
6206single-steps, even if range stepping is supported by the target. The
6207default is @code{on}.
6208
c906108c
SS
6209@end table
6210
aad1c02c
TT
6211@node Skipping Over Functions and Files
6212@section Skipping Over Functions and Files
1bfeeb0f
JL
6213@cindex skipping over functions and files
6214
6215The program you are debugging may contain some functions which are
8244c20d 6216uninteresting to debug. The @code{skip} command lets you tell @value{GDBN} to
cce0e923
DE
6217skip a function, all functions in a file or a particular function in
6218a particular file when stepping.
1bfeeb0f
JL
6219
6220For example, consider the following C function:
6221
6222@smallexample
6223101 int func()
6224102 @{
6225103 foo(boring());
6226104 bar(boring());
6227105 @}
6228@end smallexample
6229
6230@noindent
6231Suppose you wish to step into the functions @code{foo} and @code{bar}, but you
6232are not interested in stepping through @code{boring}. If you run @code{step}
6233at line 103, you'll enter @code{boring()}, but if you run @code{next}, you'll
6234step over both @code{foo} and @code{boring}!
6235
6236One solution is to @code{step} into @code{boring} and use the @code{finish}
6237command to immediately exit it. But this can become tedious if @code{boring}
6238is called from many places.
6239
6240A more flexible solution is to execute @kbd{skip boring}. This instructs
6241@value{GDBN} never to step into @code{boring}. Now when you execute
6242@code{step} at line 103, you'll step over @code{boring} and directly into
6243@code{foo}.
6244
cce0e923
DE
6245Functions may be skipped by providing either a function name, linespec
6246(@pxref{Specify Location}), regular expression that matches the function's
6247name, file name or a @code{glob}-style pattern that matches the file name.
6248
6249On Posix systems the form of the regular expression is
6250``Extended Regular Expressions''. See for example @samp{man 7 regex}
6251on @sc{gnu}/Linux systems. On non-Posix systems the form of the regular
6252expression is whatever is provided by the @code{regcomp} function of
6253the underlying system.
6254See for example @samp{man 7 glob} on @sc{gnu}/Linux systems for a
6255description of @code{glob}-style patterns.
6256
6257@table @code
6258@kindex skip
6259@item skip @r{[}@var{options}@r{]}
6260The basic form of the @code{skip} command takes zero or more options
6261that specify what to skip.
6262The @var{options} argument is any useful combination of the following:
1bfeeb0f
JL
6263
6264@table @code
cce0e923
DE
6265@item -file @var{file}
6266@itemx -fi @var{file}
6267Functions in @var{file} will be skipped over when stepping.
6268
6269@item -gfile @var{file-glob-pattern}
6270@itemx -gfi @var{file-glob-pattern}
6271@cindex skipping over files via glob-style patterns
6272Functions in files matching @var{file-glob-pattern} will be skipped
6273over when stepping.
6274
6275@smallexample
6276(gdb) skip -gfi utils/*.c
6277@end smallexample
6278
6279@item -function @var{linespec}
6280@itemx -fu @var{linespec}
6281Functions named by @var{linespec} or the function containing the line
6282named by @var{linespec} will be skipped over when stepping.
6283@xref{Specify Location}.
6284
6285@item -rfunction @var{regexp}
6286@itemx -rfu @var{regexp}
6287@cindex skipping over functions via regular expressions
6288Functions whose name matches @var{regexp} will be skipped over when stepping.
6289
6290This form is useful for complex function names.
6291For example, there is generally no need to step into C@t{++} @code{std::string}
6292constructors or destructors. Plus with C@t{++} templates it can be hard to
6293write out the full name of the function, and often it doesn't matter what
6294the template arguments are. Specifying the function to be skipped as a
6295regular expression makes this easier.
6296
6297@smallexample
6298(gdb) skip -rfu ^std::(allocator|basic_string)<.*>::~?\1 *\(
6299@end smallexample
6300
6301If you want to skip every templated C@t{++} constructor and destructor
6302in the @code{std} namespace you can do:
6303
6304@smallexample
6305(gdb) skip -rfu ^std::([a-zA-z0-9_]+)<.*>::~?\1 *\(
6306@end smallexample
6307@end table
6308
6309If no options are specified, the function you're currently debugging
6310will be skipped.
6311
1bfeeb0f 6312@kindex skip function
cce0e923 6313@item skip function @r{[}@var{linespec}@r{]}
1bfeeb0f
JL
6314After running this command, the function named by @var{linespec} or the
6315function containing the line named by @var{linespec} will be skipped over when
983fb131 6316stepping. @xref{Specify Location}.
1bfeeb0f
JL
6317
6318If you do not specify @var{linespec}, the function you're currently debugging
6319will be skipped.
6320
6321(If you have a function called @code{file} that you want to skip, use
6322@kbd{skip function file}.)
6323
6324@kindex skip file
6325@item skip file @r{[}@var{filename}@r{]}
6326After running this command, any function whose source lives in @var{filename}
6327will be skipped over when stepping.
6328
cce0e923
DE
6329@smallexample
6330(gdb) skip file boring.c
6331File boring.c will be skipped when stepping.
6332@end smallexample
6333
1bfeeb0f
JL
6334If you do not specify @var{filename}, functions whose source lives in the file
6335you're currently debugging will be skipped.
6336@end table
6337
6338Skips can be listed, deleted, disabled, and enabled, much like breakpoints.
6339These are the commands for managing your list of skips:
6340
6341@table @code
6342@kindex info skip
6343@item info skip @r{[}@var{range}@r{]}
6344Print details about the specified skip(s). If @var{range} is not specified,
6345print a table with details about all functions and files marked for skipping.
6346@code{info skip} prints the following information about each skip:
6347
6348@table @emph
6349@item Identifier
6350A number identifying this skip.
1bfeeb0f 6351@item Enabled or Disabled
cce0e923
DE
6352Enabled skips are marked with @samp{y}.
6353Disabled skips are marked with @samp{n}.
6354@item Glob
6355If the file name is a @samp{glob} pattern this is @samp{y}.
6356Otherwise it is @samp{n}.
6357@item File
6358The name or @samp{glob} pattern of the file to be skipped.
6359If no file is specified this is @samp{<none>}.
6360@item RE
6361If the function name is a @samp{regular expression} this is @samp{y}.
6362Otherwise it is @samp{n}.
6363@item Function
6364The name or regular expression of the function to skip.
6365If no function is specified this is @samp{<none>}.
1bfeeb0f
JL
6366@end table
6367
6368@kindex skip delete
6369@item skip delete @r{[}@var{range}@r{]}
6370Delete the specified skip(s). If @var{range} is not specified, delete all
6371skips.
6372
6373@kindex skip enable
6374@item skip enable @r{[}@var{range}@r{]}
6375Enable the specified skip(s). If @var{range} is not specified, enable all
6376skips.
6377
6378@kindex skip disable
6379@item skip disable @r{[}@var{range}@r{]}
6380Disable the specified skip(s). If @var{range} is not specified, disable all
6381skips.
6382
3e68067f
SM
6383@kindex set debug skip
6384@item set debug skip @r{[}on|off@r{]}
6385Set whether to print the debug output about skipping files and functions.
6386
6387@kindex show debug skip
6388@item show debug skip
6389Show whether the debug output about skipping files and functions is printed.
6390
1bfeeb0f
JL
6391@end table
6392
6d2ebf8b 6393@node Signals
c906108c
SS
6394@section Signals
6395@cindex signals
6396
6397A signal is an asynchronous event that can happen in a program. The
6398operating system defines the possible kinds of signals, and gives each
6399kind a name and a number. For example, in Unix @code{SIGINT} is the
c8aa23ab 6400signal a program gets when you type an interrupt character (often @kbd{Ctrl-c});
c906108c
SS
6401@code{SIGSEGV} is the signal a program gets from referencing a place in
6402memory far away from all the areas in use; @code{SIGALRM} occurs when
6403the alarm clock timer goes off (which happens only if your program has
6404requested an alarm).
6405
6406@cindex fatal signals
6407Some signals, including @code{SIGALRM}, are a normal part of the
6408functioning of your program. Others, such as @code{SIGSEGV}, indicate
d4f3574e 6409errors; these signals are @dfn{fatal} (they kill your program immediately) if the
c906108c
SS
6410program has not specified in advance some other way to handle the signal.
6411@code{SIGINT} does not indicate an error in your program, but it is normally
6412fatal so it can carry out the purpose of the interrupt: to kill the program.
6413
6414@value{GDBN} has the ability to detect any occurrence of a signal in your
6415program. You can tell @value{GDBN} in advance what to do for each kind of
6416signal.
6417
6418@cindex handling signals
24f93129
EZ
6419Normally, @value{GDBN} is set up to let the non-erroneous signals like
6420@code{SIGALRM} be silently passed to your program
6421(so as not to interfere with their role in the program's functioning)
c906108c
SS
6422but to stop your program immediately whenever an error signal happens.
6423You can change these settings with the @code{handle} command.
6424
6425@table @code
6426@kindex info signals
09d4efe1 6427@kindex info handle
c906108c 6428@item info signals
96a2c332 6429@itemx info handle
c906108c
SS
6430Print a table of all the kinds of signals and how @value{GDBN} has been told to
6431handle each one. You can use this to see the signal numbers of all
6432the defined types of signals.
6433
45ac1734
EZ
6434@item info signals @var{sig}
6435Similar, but print information only about the specified signal number.
6436
d4f3574e 6437@code{info handle} is an alias for @code{info signals}.
c906108c 6438
ab04a2af
TT
6439@item catch signal @r{[}@var{signal}@dots{} @r{|} @samp{all}@r{]}
6440Set a catchpoint for the indicated signals. @xref{Set Catchpoints},
6441for details about this command.
6442
c906108c 6443@kindex handle
45ac1734 6444@item handle @var{signal} @r{[}@var{keywords}@dots{}@r{]}
697aa1b7 6445Change the way @value{GDBN} handles signal @var{signal}. The @var{signal}
5ece1a18 6446can be the number of a signal or its name (with or without the
24f93129 6447@samp{SIG} at the beginning); a list of signal numbers of the form
5ece1a18 6448@samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
45ac1734
EZ
6449known signals. Optional arguments @var{keywords}, described below,
6450say what change to make.
c906108c
SS
6451@end table
6452
6453@c @group
6454The keywords allowed by the @code{handle} command can be abbreviated.
6455Their full names are:
6456
6457@table @code
6458@item nostop
6459@value{GDBN} should not stop your program when this signal happens. It may
6460still print a message telling you that the signal has come in.
6461
6462@item stop
6463@value{GDBN} should stop your program when this signal happens. This implies
6464the @code{print} keyword as well.
6465
6466@item print
6467@value{GDBN} should print a message when this signal happens.
6468
6469@item noprint
6470@value{GDBN} should not mention the occurrence of the signal at all. This
6471implies the @code{nostop} keyword as well.
6472
6473@item pass
5ece1a18 6474@itemx noignore
c906108c
SS
6475@value{GDBN} should allow your program to see this signal; your program
6476can handle the signal, or else it may terminate if the signal is fatal
5ece1a18 6477and not handled. @code{pass} and @code{noignore} are synonyms.
c906108c
SS
6478
6479@item nopass
5ece1a18 6480@itemx ignore
c906108c 6481@value{GDBN} should not allow your program to see this signal.
5ece1a18 6482@code{nopass} and @code{ignore} are synonyms.
c906108c
SS
6483@end table
6484@c @end group
6485
d4f3574e
SS
6486When a signal stops your program, the signal is not visible to the
6487program until you
c906108c
SS
6488continue. Your program sees the signal then, if @code{pass} is in
6489effect for the signal in question @emph{at that time}. In other words,
6490after @value{GDBN} reports a signal, you can use the @code{handle}
6491command with @code{pass} or @code{nopass} to control whether your
6492program sees that signal when you continue.
6493
24f93129
EZ
6494The default is set to @code{nostop}, @code{noprint}, @code{pass} for
6495non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
6496@code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
6497erroneous signals.
6498
c906108c
SS
6499You can also use the @code{signal} command to prevent your program from
6500seeing a signal, or cause it to see a signal it normally would not see,
6501or to give it any signal at any time. For example, if your program stopped
6502due to some sort of memory reference error, you might store correct
6503values into the erroneous variables and continue, hoping to see more
6504execution; but your program would probably terminate immediately as
6505a result of the fatal signal once it saw the signal. To prevent this,
6506you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
79a6e687 6507Program a Signal}.
c906108c 6508
e5f8a7cc
PA
6509@cindex stepping and signal handlers
6510@anchor{stepping and signal handlers}
6511
6512@value{GDBN} optimizes for stepping the mainline code. If a signal
6513that has @code{handle nostop} and @code{handle pass} set arrives while
6514a stepping command (e.g., @code{stepi}, @code{step}, @code{next}) is
6515in progress, @value{GDBN} lets the signal handler run and then resumes
6516stepping the mainline code once the signal handler returns. In other
6517words, @value{GDBN} steps over the signal handler. This prevents
6518signals that you've specified as not interesting (with @code{handle
6519nostop}) from changing the focus of debugging unexpectedly. Note that
6520the signal handler itself may still hit a breakpoint, stop for another
6521signal that has @code{handle stop} in effect, or for any other event
6522that normally results in stopping the stepping command sooner. Also
6523note that @value{GDBN} still informs you that the program received a
6524signal if @code{handle print} is set.
6525
6526@anchor{stepping into signal handlers}
6527
6528If you set @code{handle pass} for a signal, and your program sets up a
6529handler for it, then issuing a stepping command, such as @code{step}
6530or @code{stepi}, when your program is stopped due to the signal will
6531step @emph{into} the signal handler (if the target supports that).
6532
6533Likewise, if you use the @code{queue-signal} command to queue a signal
6534to be delivered to the current thread when execution of the thread
6535resumes (@pxref{Signaling, ,Giving your Program a Signal}), then a
6536stepping command will step into the signal handler.
6537
6538Here's an example, using @code{stepi} to step to the first instruction
6539of @code{SIGUSR1}'s handler:
6540
6541@smallexample
6542(@value{GDBP}) handle SIGUSR1
6543Signal Stop Print Pass to program Description
6544SIGUSR1 Yes Yes Yes User defined signal 1
6545(@value{GDBP}) c
6546Continuing.
6547
6548Program received signal SIGUSR1, User defined signal 1.
6549main () sigusr1.c:28
655028 p = 0;
6551(@value{GDBP}) si
6552sigusr1_handler () at sigusr1.c:9
65539 @{
6554@end smallexample
6555
6556The same, but using @code{queue-signal} instead of waiting for the
6557program to receive the signal first:
6558
6559@smallexample
6560(@value{GDBP}) n
656128 p = 0;
6562(@value{GDBP}) queue-signal SIGUSR1
6563(@value{GDBP}) si
6564sigusr1_handler () at sigusr1.c:9
65659 @{
6566(@value{GDBP})
6567@end smallexample
6568
4aa995e1
PA
6569@cindex extra signal information
6570@anchor{extra signal information}
6571
6572On some targets, @value{GDBN} can inspect extra signal information
6573associated with the intercepted signal, before it is actually
6574delivered to the program being debugged. This information is exported
6575by the convenience variable @code{$_siginfo}, and consists of data
6576that is passed by the kernel to the signal handler at the time of the
6577receipt of a signal. The data type of the information itself is
6578target dependent. You can see the data type using the @code{ptype
6579$_siginfo} command. On Unix systems, it typically corresponds to the
6580standard @code{siginfo_t} type, as defined in the @file{signal.h}
6581system header.
6582
6583Here's an example, on a @sc{gnu}/Linux system, printing the stray
6584referenced address that raised a segmentation fault.
6585
6586@smallexample
6587@group
6588(@value{GDBP}) continue
6589Program received signal SIGSEGV, Segmentation fault.
65900x0000000000400766 in main ()
659169 *(int *)p = 0;
6592(@value{GDBP}) ptype $_siginfo
6593type = struct @{
6594 int si_signo;
6595 int si_errno;
6596 int si_code;
6597 union @{
6598 int _pad[28];
6599 struct @{...@} _kill;
6600 struct @{...@} _timer;
6601 struct @{...@} _rt;
6602 struct @{...@} _sigchld;
6603 struct @{...@} _sigfault;
6604 struct @{...@} _sigpoll;
6605 @} _sifields;
6606@}
6607(@value{GDBP}) ptype $_siginfo._sifields._sigfault
6608type = struct @{
6609 void *si_addr;
6610@}
6611(@value{GDBP}) p $_siginfo._sifields._sigfault.si_addr
6612$1 = (void *) 0x7ffff7ff7000
6613@end group
6614@end smallexample
6615
6616Depending on target support, @code{$_siginfo} may also be writable.
6617
012b3a21
WT
6618@cindex Intel MPX boundary violations
6619@cindex boundary violations, Intel MPX
6620On some targets, a @code{SIGSEGV} can be caused by a boundary
6621violation, i.e., accessing an address outside of the allowed range.
6622In those cases @value{GDBN} may displays additional information,
6623depending on how @value{GDBN} has been told to handle the signal.
6624With @code{handle stop SIGSEGV}, @value{GDBN} displays the violation
6625kind: "Upper" or "Lower", the memory address accessed and the
6626bounds, while with @code{handle nostop SIGSEGV} no additional
6627information is displayed.
6628
6629The usual output of a segfault is:
6630@smallexample
6631Program received signal SIGSEGV, Segmentation fault
66320x0000000000400d7c in upper () at i386-mpx-sigsegv.c:68
663368 value = *(p + len);
6634@end smallexample
6635
6636While a bound violation is presented as:
6637@smallexample
6638Program received signal SIGSEGV, Segmentation fault
6639Upper bound violation while accessing address 0x7fffffffc3b3
6640Bounds: [lower = 0x7fffffffc390, upper = 0x7fffffffc3a3]
66410x0000000000400d7c in upper () at i386-mpx-sigsegv.c:68
664268 value = *(p + len);
6643@end smallexample
6644
6d2ebf8b 6645@node Thread Stops
79a6e687 6646@section Stopping and Starting Multi-thread Programs
c906108c 6647
0606b73b
SL
6648@cindex stopped threads
6649@cindex threads, stopped
6650
6651@cindex continuing threads
6652@cindex threads, continuing
6653
6654@value{GDBN} supports debugging programs with multiple threads
6655(@pxref{Threads,, Debugging Programs with Multiple Threads}). There
6656are two modes of controlling execution of your program within the
6657debugger. In the default mode, referred to as @dfn{all-stop mode},
6658when any thread in your program stops (for example, at a breakpoint
6659or while being stepped), all other threads in the program are also stopped by
6660@value{GDBN}. On some targets, @value{GDBN} also supports
6661@dfn{non-stop mode}, in which other threads can continue to run freely while
6662you examine the stopped thread in the debugger.
6663
6664@menu
6665* All-Stop Mode:: All threads stop when GDB takes control
6666* Non-Stop Mode:: Other threads continue to execute
6667* Background Execution:: Running your program asynchronously
6668* Thread-Specific Breakpoints:: Controlling breakpoints
6669* Interrupted System Calls:: GDB may interfere with system calls
d914c394 6670* Observer Mode:: GDB does not alter program behavior
0606b73b
SL
6671@end menu
6672
6673@node All-Stop Mode
6674@subsection All-Stop Mode
6675
6676@cindex all-stop mode
6677
6678In all-stop mode, whenever your program stops under @value{GDBN} for any reason,
6679@emph{all} threads of execution stop, not just the current thread. This
6680allows you to examine the overall state of the program, including
6681switching between threads, without worrying that things may change
6682underfoot.
6683
6684Conversely, whenever you restart the program, @emph{all} threads start
6685executing. @emph{This is true even when single-stepping} with commands
6686like @code{step} or @code{next}.
6687
6688In particular, @value{GDBN} cannot single-step all threads in lockstep.
6689Since thread scheduling is up to your debugging target's operating
6690system (not controlled by @value{GDBN}), other threads may
6691execute more than one statement while the current thread completes a
6692single step. Moreover, in general other threads stop in the middle of a
6693statement, rather than at a clean statement boundary, when the program
6694stops.
6695
6696You might even find your program stopped in another thread after
6697continuing or even single-stepping. This happens whenever some other
6698thread runs into a breakpoint, a signal, or an exception before the
6699first thread completes whatever you requested.
6700
6701@cindex automatic thread selection
6702@cindex switching threads automatically
6703@cindex threads, automatic switching
6704Whenever @value{GDBN} stops your program, due to a breakpoint or a
6705signal, it automatically selects the thread where that breakpoint or
6706signal happened. @value{GDBN} alerts you to the context switch with a
6707message such as @samp{[Switching to Thread @var{n}]} to identify the
6708thread.
6709
6710On some OSes, you can modify @value{GDBN}'s default behavior by
6711locking the OS scheduler to allow only a single thread to run.
6712
6713@table @code
6714@item set scheduler-locking @var{mode}
6715@cindex scheduler locking mode
6716@cindex lock scheduler
f2665db5
MM
6717Set the scheduler locking mode. It applies to normal execution,
6718record mode, and replay mode. If it is @code{off}, then there is no
6719locking and any thread may run at any time. If @code{on}, then only
6720the current thread may run when the inferior is resumed. The
6721@code{step} mode optimizes for single-stepping; it prevents other
6722threads from preempting the current thread while you are stepping, so
6723that the focus of debugging does not change unexpectedly. Other
6724threads never get a chance to run when you step, and they are
6725completely free to run when you use commands like @samp{continue},
6726@samp{until}, or @samp{finish}. However, unless another thread hits a
6727breakpoint during its timeslice, @value{GDBN} does not change the
6728current thread away from the thread that you are debugging. The
6729@code{replay} mode behaves like @code{off} in record mode and like
6730@code{on} in replay mode.
0606b73b
SL
6731
6732@item show scheduler-locking
6733Display the current scheduler locking mode.
6734@end table
6735
d4db2f36
PA
6736@cindex resume threads of multiple processes simultaneously
6737By default, when you issue one of the execution commands such as
6738@code{continue}, @code{next} or @code{step}, @value{GDBN} allows only
6739threads of the current inferior to run. For example, if @value{GDBN}
6740is attached to two inferiors, each with two threads, the
6741@code{continue} command resumes only the two threads of the current
6742inferior. This is useful, for example, when you debug a program that
6743forks and you want to hold the parent stopped (so that, for instance,
6744it doesn't run to exit), while you debug the child. In other
6745situations, you may not be interested in inspecting the current state
6746of any of the processes @value{GDBN} is attached to, and you may want
6747to resume them all until some breakpoint is hit. In the latter case,
6748you can instruct @value{GDBN} to allow all threads of all the
6749inferiors to run with the @w{@code{set schedule-multiple}} command.
6750
6751@table @code
6752@kindex set schedule-multiple
6753@item set schedule-multiple
6754Set the mode for allowing threads of multiple processes to be resumed
6755when an execution command is issued. When @code{on}, all threads of
6756all processes are allowed to run. When @code{off}, only the threads
6757of the current process are resumed. The default is @code{off}. The
6758@code{scheduler-locking} mode takes precedence when set to @code{on},
6759or while you are stepping and set to @code{step}.
6760
6761@item show schedule-multiple
6762Display the current mode for resuming the execution of threads of
6763multiple processes.
6764@end table
6765
0606b73b
SL
6766@node Non-Stop Mode
6767@subsection Non-Stop Mode
6768
6769@cindex non-stop mode
6770
6771@c This section is really only a place-holder, and needs to be expanded
97d8f0ee 6772@c with more details.
0606b73b
SL
6773
6774For some multi-threaded targets, @value{GDBN} supports an optional
6775mode of operation in which you can examine stopped program threads in
6776the debugger while other threads continue to execute freely. This
97d8f0ee
DE
6777minimizes intrusion when debugging live systems, such as programs
6778where some threads have real-time constraints or must continue to
0606b73b
SL
6779respond to external events. This is referred to as @dfn{non-stop} mode.
6780
6781In non-stop mode, when a thread stops to report a debugging event,
6782@emph{only} that thread is stopped; @value{GDBN} does not stop other
6783threads as well, in contrast to the all-stop mode behavior. Additionally,
6784execution commands such as @code{continue} and @code{step} apply by default
6785only to the current thread in non-stop mode, rather than all threads as
6786in all-stop mode. This allows you to control threads explicitly in
97d8f0ee 6787ways that are not possible in all-stop mode --- for example, stepping
0606b73b 6788one thread while allowing others to run freely, stepping
97d8f0ee 6789one thread while holding all others stopped, or stepping several threads
0606b73b
SL
6790independently and simultaneously.
6791
6792To enter non-stop mode, use this sequence of commands before you run
6793or attach to your program:
6794
0606b73b 6795@smallexample
0606b73b
SL
6796# If using the CLI, pagination breaks non-stop.
6797set pagination off
6798
6799# Finally, turn it on!
6800set non-stop on
6801@end smallexample
6802
6803You can use these commands to manipulate the non-stop mode setting:
6804
6805@table @code
6806@kindex set non-stop
6807@item set non-stop on
6808Enable selection of non-stop mode.
6809@item set non-stop off
6810Disable selection of non-stop mode.
6811@kindex show non-stop
6812@item show non-stop
6813Show the current non-stop enablement setting.
6814@end table
6815
6816Note these commands only reflect whether non-stop mode is enabled,
97d8f0ee 6817not whether the currently-executing program is being run in non-stop mode.
0606b73b 6818In particular, the @code{set non-stop} preference is only consulted when
97d8f0ee 6819@value{GDBN} starts or connects to the target program, and it is generally
0606b73b
SL
6820not possible to switch modes once debugging has started. Furthermore,
6821since not all targets support non-stop mode, even when you have enabled
6822non-stop mode, @value{GDBN} may still fall back to all-stop operation by
6823default.
6824
6825In non-stop mode, all execution commands apply only to the current thread
97d8f0ee 6826by default. That is, @code{continue} only continues one thread.
0606b73b
SL
6827To continue all threads, issue @code{continue -a} or @code{c -a}.
6828
97d8f0ee 6829You can use @value{GDBN}'s background execution commands
0606b73b 6830(@pxref{Background Execution}) to run some threads in the background
97d8f0ee 6831while you continue to examine or step others from @value{GDBN}.
0606b73b
SL
6832The MI execution commands (@pxref{GDB/MI Program Execution}) are
6833always executed asynchronously in non-stop mode.
6834
6835Suspending execution is done with the @code{interrupt} command when
97d8f0ee
DE
6836running in the background, or @kbd{Ctrl-c} during foreground execution.
6837In all-stop mode, this stops the whole process;
6838but in non-stop mode the interrupt applies only to the current thread.
0606b73b
SL
6839To stop the whole program, use @code{interrupt -a}.
6840
6841Other execution commands do not currently support the @code{-a} option.
6842
6843In non-stop mode, when a thread stops, @value{GDBN} doesn't automatically make
6844that thread current, as it does in all-stop mode. This is because the
97d8f0ee 6845thread stop notifications are asynchronous with respect to @value{GDBN}'s
0606b73b
SL
6846command interpreter, and it would be confusing if @value{GDBN} unexpectedly
6847changed to a different thread just as you entered a command to operate on the
6848previously current thread.
6849
6850@node Background Execution
6851@subsection Background Execution
6852
6853@cindex foreground execution
6854@cindex background execution
6855@cindex asynchronous execution
6856@cindex execution, foreground, background and asynchronous
6857
6858@value{GDBN}'s execution commands have two variants: the normal
6859foreground (synchronous) behavior, and a background
97d8f0ee 6860(asynchronous) behavior. In foreground execution, @value{GDBN} waits for
0606b73b
SL
6861the program to report that some thread has stopped before prompting for
6862another command. In background execution, @value{GDBN} immediately gives
6863a command prompt so that you can issue other commands while your program runs.
6864
32fc0df9
PA
6865If the target doesn't support async mode, @value{GDBN} issues an error
6866message if you attempt to use the background execution commands.
6867
74fdb8ff 6868@cindex @code{&}, background execution of commands
0606b73b
SL
6869To specify background execution, add a @code{&} to the command. For example,
6870the background form of the @code{continue} command is @code{continue&}, or
6871just @code{c&}. The execution commands that accept background execution
6872are:
6873
6874@table @code
6875@kindex run&
6876@item run
6877@xref{Starting, , Starting your Program}.
6878
6879@item attach
6880@kindex attach&
6881@xref{Attach, , Debugging an Already-running Process}.
6882
6883@item step
6884@kindex step&
6885@xref{Continuing and Stepping, step}.
6886
6887@item stepi
6888@kindex stepi&
6889@xref{Continuing and Stepping, stepi}.
6890
6891@item next
6892@kindex next&
6893@xref{Continuing and Stepping, next}.
6894
7ce58dd2
DE
6895@item nexti
6896@kindex nexti&
6897@xref{Continuing and Stepping, nexti}.
6898
0606b73b
SL
6899@item continue
6900@kindex continue&
6901@xref{Continuing and Stepping, continue}.
6902
6903@item finish
6904@kindex finish&
6905@xref{Continuing and Stepping, finish}.
6906
6907@item until
6908@kindex until&
6909@xref{Continuing and Stepping, until}.
6910
6911@end table
6912
6913Background execution is especially useful in conjunction with non-stop
6914mode for debugging programs with multiple threads; see @ref{Non-Stop Mode}.
6915However, you can also use these commands in the normal all-stop mode with
6916the restriction that you cannot issue another execution command until the
6917previous one finishes. Examples of commands that are valid in all-stop
6918mode while the program is running include @code{help} and @code{info break}.
6919
6920You can interrupt your program while it is running in the background by
6921using the @code{interrupt} command.
6922
6923@table @code
6924@kindex interrupt
6925@item interrupt
6926@itemx interrupt -a
6927
97d8f0ee 6928Suspend execution of the running program. In all-stop mode,
0606b73b 6929@code{interrupt} stops the whole process, but in non-stop mode, it stops
97d8f0ee 6930only the current thread. To stop the whole program in non-stop mode,
0606b73b
SL
6931use @code{interrupt -a}.
6932@end table
6933
0606b73b
SL
6934@node Thread-Specific Breakpoints
6935@subsection Thread-Specific Breakpoints
6936
c906108c 6937When your program has multiple threads (@pxref{Threads,, Debugging
79a6e687 6938Programs with Multiple Threads}), you can choose whether to set
c906108c
SS
6939breakpoints on all threads, or on a particular thread.
6940
6941@table @code
6942@cindex breakpoints and threads
6943@cindex thread breakpoints
5d5658a1
PA
6944@kindex break @dots{} thread @var{thread-id}
6945@item break @var{location} thread @var{thread-id}
6946@itemx break @var{location} thread @var{thread-id} if @dots{}
629500fa 6947@var{location} specifies source lines; there are several ways of
2a25a5ba
EZ
6948writing them (@pxref{Specify Location}), but the effect is always to
6949specify some source line.
c906108c 6950
5d5658a1 6951Use the qualifier @samp{thread @var{thread-id}} with a breakpoint command
c906108c 6952to specify that you only want @value{GDBN} to stop the program when a
5d5658a1
PA
6953particular thread reaches this breakpoint. The @var{thread-id} specifier
6954is one of the thread identifiers assigned by @value{GDBN}, shown
697aa1b7 6955in the first column of the @samp{info threads} display.
c906108c 6956
5d5658a1 6957If you do not specify @samp{thread @var{thread-id}} when you set a
c906108c
SS
6958breakpoint, the breakpoint applies to @emph{all} threads of your
6959program.
6960
6961You can use the @code{thread} qualifier on conditional breakpoints as
5d5658a1 6962well; in this case, place @samp{thread @var{thread-id}} before or
b6199126 6963after the breakpoint condition, like this:
c906108c
SS
6964
6965@smallexample
2df3850c 6966(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
c906108c
SS
6967@end smallexample
6968
6969@end table
6970
f4fb82a1
PA
6971Thread-specific breakpoints are automatically deleted when
6972@value{GDBN} detects the corresponding thread is no longer in the
6973thread list. For example:
6974
6975@smallexample
6976(@value{GDBP}) c
6977Thread-specific breakpoint 3 deleted - thread 28 no longer in the thread list.
6978@end smallexample
6979
6980There are several ways for a thread to disappear, such as a regular
6981thread exit, but also when you detach from the process with the
6982@code{detach} command (@pxref{Attach, ,Debugging an Already-running
6983Process}), or if @value{GDBN} loses the remote connection
6984(@pxref{Remote Debugging}), etc. Note that with some targets,
6985@value{GDBN} is only able to detect a thread has exited when the user
6986explictly asks for the thread list with the @code{info threads}
6987command.
6988
0606b73b
SL
6989@node Interrupted System Calls
6990@subsection Interrupted System Calls
c906108c 6991
36d86913
MC
6992@cindex thread breakpoints and system calls
6993@cindex system calls and thread breakpoints
6994@cindex premature return from system calls
0606b73b
SL
6995There is an unfortunate side effect when using @value{GDBN} to debug
6996multi-threaded programs. If one thread stops for a
36d86913
MC
6997breakpoint, or for some other reason, and another thread is blocked in a
6998system call, then the system call may return prematurely. This is a
6999consequence of the interaction between multiple threads and the signals
7000that @value{GDBN} uses to implement breakpoints and other events that
7001stop execution.
7002
7003To handle this problem, your program should check the return value of
7004each system call and react appropriately. This is good programming
7005style anyways.
7006
7007For example, do not write code like this:
7008
7009@smallexample
7010 sleep (10);
7011@end smallexample
7012
7013The call to @code{sleep} will return early if a different thread stops
7014at a breakpoint or for some other reason.
7015
7016Instead, write this:
7017
7018@smallexample
7019 int unslept = 10;
7020 while (unslept > 0)
7021 unslept = sleep (unslept);
7022@end smallexample
7023
7024A system call is allowed to return early, so the system is still
7025conforming to its specification. But @value{GDBN} does cause your
7026multi-threaded program to behave differently than it would without
7027@value{GDBN}.
7028
7029Also, @value{GDBN} uses internal breakpoints in the thread library to
7030monitor certain events such as thread creation and thread destruction.
7031When such an event happens, a system call in another thread may return
7032prematurely, even though your program does not appear to stop.
7033
d914c394
SS
7034@node Observer Mode
7035@subsection Observer Mode
7036
7037If you want to build on non-stop mode and observe program behavior
7038without any chance of disruption by @value{GDBN}, you can set
7039variables to disable all of the debugger's attempts to modify state,
7040whether by writing memory, inserting breakpoints, etc. These operate
7041at a low level, intercepting operations from all commands.
7042
7043When all of these are set to @code{off}, then @value{GDBN} is said to
7044be @dfn{observer mode}. As a convenience, the variable
7045@code{observer} can be set to disable these, plus enable non-stop
7046mode.
7047
7048Note that @value{GDBN} will not prevent you from making nonsensical
7049combinations of these settings. For instance, if you have enabled
7050@code{may-insert-breakpoints} but disabled @code{may-write-memory},
7051then breakpoints that work by writing trap instructions into the code
7052stream will still not be able to be placed.
7053
7054@table @code
7055
7056@kindex observer
7057@item set observer on
7058@itemx set observer off
7059When set to @code{on}, this disables all the permission variables
7060below (except for @code{insert-fast-tracepoints}), plus enables
7061non-stop debugging. Setting this to @code{off} switches back to
7062normal debugging, though remaining in non-stop mode.
7063
7064@item show observer
7065Show whether observer mode is on or off.
7066
7067@kindex may-write-registers
7068@item set may-write-registers on
7069@itemx set may-write-registers off
7070This controls whether @value{GDBN} will attempt to alter the values of
7071registers, such as with assignment expressions in @code{print}, or the
7072@code{jump} command. It defaults to @code{on}.
7073
7074@item show may-write-registers
7075Show the current permission to write registers.
7076
7077@kindex may-write-memory
7078@item set may-write-memory on
7079@itemx set may-write-memory off
7080This controls whether @value{GDBN} will attempt to alter the contents
7081of memory, such as with assignment expressions in @code{print}. It
7082defaults to @code{on}.
7083
7084@item show may-write-memory
7085Show the current permission to write memory.
7086
7087@kindex may-insert-breakpoints
7088@item set may-insert-breakpoints on
7089@itemx set may-insert-breakpoints off
7090This controls whether @value{GDBN} will attempt to insert breakpoints.
7091This affects all breakpoints, including internal breakpoints defined
7092by @value{GDBN}. It defaults to @code{on}.
7093
7094@item show may-insert-breakpoints
7095Show the current permission to insert breakpoints.
7096
7097@kindex may-insert-tracepoints
7098@item set may-insert-tracepoints on
7099@itemx set may-insert-tracepoints off
7100This controls whether @value{GDBN} will attempt to insert (regular)
7101tracepoints at the beginning of a tracing experiment. It affects only
7102non-fast tracepoints, fast tracepoints being under the control of
7103@code{may-insert-fast-tracepoints}. It defaults to @code{on}.
7104
7105@item show may-insert-tracepoints
7106Show the current permission to insert tracepoints.
7107
7108@kindex may-insert-fast-tracepoints
7109@item set may-insert-fast-tracepoints on
7110@itemx set may-insert-fast-tracepoints off
7111This controls whether @value{GDBN} will attempt to insert fast
7112tracepoints at the beginning of a tracing experiment. It affects only
7113fast tracepoints, regular (non-fast) tracepoints being under the
7114control of @code{may-insert-tracepoints}. It defaults to @code{on}.
7115
7116@item show may-insert-fast-tracepoints
7117Show the current permission to insert fast tracepoints.
7118
7119@kindex may-interrupt
7120@item set may-interrupt on
7121@itemx set may-interrupt off
7122This controls whether @value{GDBN} will attempt to interrupt or stop
7123program execution. When this variable is @code{off}, the
7124@code{interrupt} command will have no effect, nor will
7125@kbd{Ctrl-c}. It defaults to @code{on}.
7126
7127@item show may-interrupt
7128Show the current permission to interrupt or stop the program.
7129
7130@end table
c906108c 7131
bacec72f
MS
7132@node Reverse Execution
7133@chapter Running programs backward
7134@cindex reverse execution
7135@cindex running programs backward
7136
7137When you are debugging a program, it is not unusual to realize that
7138you have gone too far, and some event of interest has already happened.
7139If the target environment supports it, @value{GDBN} can allow you to
7140``rewind'' the program by running it backward.
7141
7142A target environment that supports reverse execution should be able
7143to ``undo'' the changes in machine state that have taken place as the
7144program was executing normally. Variables, registers etc.@: should
7145revert to their previous values. Obviously this requires a great
7146deal of sophistication on the part of the target environment; not
7147all target environments can support reverse execution.
7148
7149When a program is executed in reverse, the instructions that
7150have most recently been executed are ``un-executed'', in reverse
7151order. The program counter runs backward, following the previous
7152thread of execution in reverse. As each instruction is ``un-executed'',
7153the values of memory and/or registers that were changed by that
7154instruction are reverted to their previous states. After executing
7155a piece of source code in reverse, all side effects of that code
7156should be ``undone'', and all variables should be returned to their
7157prior values@footnote{
7158Note that some side effects are easier to undo than others. For instance,
7159memory and registers are relatively easy, but device I/O is hard. Some
7160targets may be able undo things like device I/O, and some may not.
7161
7162The contract between @value{GDBN} and the reverse executing target
7163requires only that the target do something reasonable when
7164@value{GDBN} tells it to execute backwards, and then report the
7165results back to @value{GDBN}. Whatever the target reports back to
7166@value{GDBN}, @value{GDBN} will report back to the user. @value{GDBN}
7167assumes that the memory and registers that the target reports are in a
6b92c0d3 7168consistent state, but @value{GDBN} accepts whatever it is given.
bacec72f
MS
7169}.
7170
73f8a590
PA
7171On some platforms, @value{GDBN} has built-in support for reverse
7172execution, activated with the @code{record} or @code{record btrace}
7173commands. @xref{Process Record and Replay}. Some remote targets,
7174typically full system emulators, support reverse execution directly
7175without requiring any special command.
7176
bacec72f
MS
7177If you are debugging in a target environment that supports
7178reverse execution, @value{GDBN} provides the following commands.
7179
7180@table @code
7181@kindex reverse-continue
7182@kindex rc @r{(@code{reverse-continue})}
7183@item reverse-continue @r{[}@var{ignore-count}@r{]}
7184@itemx rc @r{[}@var{ignore-count}@r{]}
7185Beginning at the point where your program last stopped, start executing
7186in reverse. Reverse execution will stop for breakpoints and synchronous
7187exceptions (signals), just like normal execution. Behavior of
7188asynchronous signals depends on the target environment.
7189
7190@kindex reverse-step
7191@kindex rs @r{(@code{step})}
7192@item reverse-step @r{[}@var{count}@r{]}
7193Run the program backward until control reaches the start of a
7194different source line; then stop it, and return control to @value{GDBN}.
7195
7196Like the @code{step} command, @code{reverse-step} will only stop
7197at the beginning of a source line. It ``un-executes'' the previously
7198executed source line. If the previous source line included calls to
7199debuggable functions, @code{reverse-step} will step (backward) into
7200the called function, stopping at the beginning of the @emph{last}
7201statement in the called function (typically a return statement).
7202
7203Also, as with the @code{step} command, if non-debuggable functions are
7204called, @code{reverse-step} will run thru them backward without stopping.
7205
7206@kindex reverse-stepi
7207@kindex rsi @r{(@code{reverse-stepi})}
7208@item reverse-stepi @r{[}@var{count}@r{]}
7209Reverse-execute one machine instruction. Note that the instruction
7210to be reverse-executed is @emph{not} the one pointed to by the program
7211counter, but the instruction executed prior to that one. For instance,
7212if the last instruction was a jump, @code{reverse-stepi} will take you
7213back from the destination of the jump to the jump instruction itself.
7214
7215@kindex reverse-next
7216@kindex rn @r{(@code{reverse-next})}
7217@item reverse-next @r{[}@var{count}@r{]}
7218Run backward to the beginning of the previous line executed in
7219the current (innermost) stack frame. If the line contains function
7220calls, they will be ``un-executed'' without stopping. Starting from
7221the first line of a function, @code{reverse-next} will take you back
7222to the caller of that function, @emph{before} the function was called,
7223just as the normal @code{next} command would take you from the last
7224line of a function back to its return to its caller
16af530a 7225@footnote{Unless the code is too heavily optimized.}.
bacec72f
MS
7226
7227@kindex reverse-nexti
7228@kindex rni @r{(@code{reverse-nexti})}
7229@item reverse-nexti @r{[}@var{count}@r{]}
7230Like @code{nexti}, @code{reverse-nexti} executes a single instruction
7231in reverse, except that called functions are ``un-executed'' atomically.
7232That is, if the previously executed instruction was a return from
540aa8e7 7233another function, @code{reverse-nexti} will continue to execute
bacec72f
MS
7234in reverse until the call to that function (from the current stack
7235frame) is reached.
7236
7237@kindex reverse-finish
7238@item reverse-finish
7239Just as the @code{finish} command takes you to the point where the
7240current function returns, @code{reverse-finish} takes you to the point
7241where it was called. Instead of ending up at the end of the current
7242function invocation, you end up at the beginning.
7243
7244@kindex set exec-direction
7245@item set exec-direction
7246Set the direction of target execution.
984359d2 7247@item set exec-direction reverse
bacec72f
MS
7248@cindex execute forward or backward in time
7249@value{GDBN} will perform all execution commands in reverse, until the
7250exec-direction mode is changed to ``forward''. Affected commands include
7251@code{step, stepi, next, nexti, continue, and finish}. The @code{return}
7252command cannot be used in reverse mode.
7253@item set exec-direction forward
7254@value{GDBN} will perform all execution commands in the normal fashion.
7255This is the default.
7256@end table
7257
c906108c 7258
a2311334
EZ
7259@node Process Record and Replay
7260@chapter Recording Inferior's Execution and Replaying It
53cc454a
HZ
7261@cindex process record and replay
7262@cindex recording inferior's execution and replaying it
7263
8e05493c
EZ
7264On some platforms, @value{GDBN} provides a special @dfn{process record
7265and replay} target that can record a log of the process execution, and
7266replay it later with both forward and reverse execution commands.
a2311334
EZ
7267
7268@cindex replay mode
7269When this target is in use, if the execution log includes the record
7270for the next instruction, @value{GDBN} will debug in @dfn{replay
7271mode}. In the replay mode, the inferior does not really execute code
7272instructions. Instead, all the events that normally happen during
7273code execution are taken from the execution log. While code is not
7274really executed in replay mode, the values of registers (including the
7275program counter register) and the memory of the inferior are still
8e05493c
EZ
7276changed as they normally would. Their contents are taken from the
7277execution log.
a2311334
EZ
7278
7279@cindex record mode
7280If the record for the next instruction is not in the execution log,
7281@value{GDBN} will debug in @dfn{record mode}. In this mode, the
7282inferior executes normally, and @value{GDBN} records the execution log
7283for future replay.
7284
8e05493c
EZ
7285The process record and replay target supports reverse execution
7286(@pxref{Reverse Execution}), even if the platform on which the
7287inferior runs does not. However, the reverse execution is limited in
7288this case by the range of the instructions recorded in the execution
7289log. In other words, reverse execution on platforms that don't
7290support it directly can only be done in the replay mode.
7291
7292When debugging in the reverse direction, @value{GDBN} will work in
7293replay mode as long as the execution log includes the record for the
7294previous instruction; otherwise, it will work in record mode, if the
7295platform supports reverse execution, or stop if not.
7296
73f8a590
PA
7297Currently, process record and replay is supported on ARM, Aarch64,
7298Moxie, PowerPC, PowerPC64, S/390, and x86 (i386/amd64) running
7299GNU/Linux. Process record and replay can be used both when native
7300debugging, and when remote debugging via @code{gdbserver}.
7301
a2311334
EZ
7302For architecture environments that support process record and replay,
7303@value{GDBN} provides the following commands:
53cc454a
HZ
7304
7305@table @code
7306@kindex target record
59ea5688
MM
7307@kindex target record-full
7308@kindex target record-btrace
53cc454a 7309@kindex record
59ea5688
MM
7310@kindex record full
7311@kindex record btrace
f4abbc16 7312@kindex record btrace bts
b20a6524 7313@kindex record btrace pt
f4abbc16 7314@kindex record bts
b20a6524 7315@kindex record pt
53cc454a 7316@kindex rec
59ea5688
MM
7317@kindex rec full
7318@kindex rec btrace
f4abbc16 7319@kindex rec btrace bts
b20a6524 7320@kindex rec btrace pt
f4abbc16 7321@kindex rec bts
b20a6524 7322@kindex rec pt
59ea5688
MM
7323@item record @var{method}
7324This command starts the process record and replay target. The
7325recording method can be specified as parameter. Without a parameter
7326the command uses the @code{full} recording method. The following
7327recording methods are available:
a2311334 7328
59ea5688
MM
7329@table @code
7330@item full
7331Full record/replay recording using @value{GDBN}'s software record and
7332replay implementation. This method allows replaying and reverse
7333execution.
7334
f4abbc16 7335@item btrace @var{format}
73f8a590
PA
7336Hardware-supported instruction recording, supported on Intel
7337processors. This method does not record data. Further, the data is
7338collected in a ring buffer so old data will be overwritten when the
7339buffer is full. It allows limited reverse execution. Variables and
7340registers are not available during reverse execution. In remote
7341debugging, recording continues on disconnect. Recorded data can be
7342inspected after reconnecting. The recording may be stopped using
7343@code{record stop}.
59ea5688 7344
f4abbc16
MM
7345The recording format can be specified as parameter. Without a parameter
7346the command chooses the recording format. The following recording
7347formats are available:
7348
7349@table @code
7350@item bts
7351@cindex branch trace store
7352Use the @dfn{Branch Trace Store} (@acronym{BTS}) recording format. In
7353this format, the processor stores a from/to record for each executed
7354branch in the btrace ring buffer.
b20a6524
MM
7355
7356@item pt
bc504a31
PA
7357@cindex Intel Processor Trace
7358Use the @dfn{Intel Processor Trace} recording format. In this
b20a6524
MM
7359format, the processor stores the execution trace in a compressed form
7360that is afterwards decoded by @value{GDBN}.
7361
7362The trace can be recorded with very low overhead. The compressed
7363trace format also allows small trace buffers to already contain a big
7364number of instructions compared to @acronym{BTS}.
7365
7366Decoding the recorded execution trace, on the other hand, is more
7367expensive than decoding @acronym{BTS} trace. This is mostly due to the
7368increased number of instructions to process. You should increase the
7369buffer-size with care.
f4abbc16
MM
7370@end table
7371
7372Not all recording formats may be available on all processors.
59ea5688
MM
7373@end table
7374
7375The process record and replay target can only debug a process that is
7376already running. Therefore, you need first to start the process with
7377the @kbd{run} or @kbd{start} commands, and then start the recording
7378with the @kbd{record @var{method}} command.
7379
a2311334
EZ
7380@cindex displaced stepping, and process record and replay
7381Displaced stepping (@pxref{Maintenance Commands,, displaced stepping})
7382will be automatically disabled when process record and replay target
7383is started. That's because the process record and replay target
7384doesn't support displaced stepping.
7385
7386@cindex non-stop mode, and process record and replay
7387@cindex asynchronous execution, and process record and replay
7388If the inferior is in the non-stop mode (@pxref{Non-Stop Mode}) or in
59ea5688
MM
7389the asynchronous execution mode (@pxref{Background Execution}), not
7390all recording methods are available. The @code{full} recording method
7391does not support these two modes.
53cc454a
HZ
7392
7393@kindex record stop
7394@kindex rec s
7395@item record stop
a2311334
EZ
7396Stop the process record and replay target. When process record and
7397replay target stops, the entire execution log will be deleted and the
7398inferior will either be terminated, or will remain in its final state.
53cc454a 7399
a2311334
EZ
7400When you stop the process record and replay target in record mode (at
7401the end of the execution log), the inferior will be stopped at the
7402next instruction that would have been recorded. In other words, if
7403you record for a while and then stop recording, the inferior process
7404will be left in the same state as if the recording never happened.
53cc454a 7405
a2311334
EZ
7406On the other hand, if the process record and replay target is stopped
7407while in replay mode (that is, not at the end of the execution log,
7408but at some earlier point), the inferior process will become ``live''
7409at that earlier state, and it will then be possible to continue the
7410usual ``live'' debugging of the process from that state.
53cc454a 7411
a2311334
EZ
7412When the inferior process exits, or @value{GDBN} detaches from it,
7413process record and replay target will automatically stop itself.
53cc454a 7414
742ce053
MM
7415@kindex record goto
7416@item record goto
7417Go to a specific location in the execution log. There are several
7418ways to specify the location to go to:
7419
7420@table @code
7421@item record goto begin
7422@itemx record goto start
7423Go to the beginning of the execution log.
7424
7425@item record goto end
7426Go to the end of the execution log.
7427
7428@item record goto @var{n}
7429Go to instruction number @var{n} in the execution log.
7430@end table
7431
24e933df
HZ
7432@kindex record save
7433@item record save @var{filename}
7434Save the execution log to a file @file{@var{filename}}.
7435Default filename is @file{gdb_record.@var{process_id}}, where
7436@var{process_id} is the process ID of the inferior.
7437
59ea5688
MM
7438This command may not be available for all recording methods.
7439
24e933df
HZ
7440@kindex record restore
7441@item record restore @var{filename}
7442Restore the execution log from a file @file{@var{filename}}.
7443File must have been created with @code{record save}.
7444
59ea5688
MM
7445@kindex set record full
7446@item set record full insn-number-max @var{limit}
f81d1120 7447@itemx set record full insn-number-max unlimited
59ea5688
MM
7448Set the limit of instructions to be recorded for the @code{full}
7449recording method. Default value is 200000.
53cc454a 7450
a2311334
EZ
7451If @var{limit} is a positive number, then @value{GDBN} will start
7452deleting instructions from the log once the number of the record
7453instructions becomes greater than @var{limit}. For every new recorded
7454instruction, @value{GDBN} will delete the earliest recorded
7455instruction to keep the number of recorded instructions at the limit.
7456(Since deleting recorded instructions loses information, @value{GDBN}
7457lets you control what happens when the limit is reached, by means of
7458the @code{stop-at-limit} option, described below.)
53cc454a 7459
f81d1120
PA
7460If @var{limit} is @code{unlimited} or zero, @value{GDBN} will never
7461delete recorded instructions from the execution log. The number of
7462recorded instructions is limited only by the available memory.
53cc454a 7463
59ea5688
MM
7464@kindex show record full
7465@item show record full insn-number-max
7466Show the limit of instructions to be recorded with the @code{full}
7467recording method.
53cc454a 7468
59ea5688
MM
7469@item set record full stop-at-limit
7470Control the behavior of the @code{full} recording method when the
7471number of recorded instructions reaches the limit. If ON (the
7472default), @value{GDBN} will stop when the limit is reached for the
7473first time and ask you whether you want to stop the inferior or
7474continue running it and recording the execution log. If you decide
7475to continue recording, each new recorded instruction will cause the
7476oldest one to be deleted.
53cc454a 7477
a2311334
EZ
7478If this option is OFF, @value{GDBN} will automatically delete the
7479oldest record to make room for each new one, without asking.
53cc454a 7480
59ea5688 7481@item show record full stop-at-limit
a2311334 7482Show the current setting of @code{stop-at-limit}.
53cc454a 7483
59ea5688 7484@item set record full memory-query
bb08c432 7485Control the behavior when @value{GDBN} is unable to record memory
59ea5688
MM
7486changes caused by an instruction for the @code{full} recording method.
7487If ON, @value{GDBN} will query whether to stop the inferior in that
7488case.
bb08c432
HZ
7489
7490If this option is OFF (the default), @value{GDBN} will automatically
7491ignore the effect of such instructions on memory. Later, when
7492@value{GDBN} replays this execution log, it will mark the log of this
7493instruction as not accessible, and it will not affect the replay
7494results.
7495
59ea5688 7496@item show record full memory-query
bb08c432
HZ
7497Show the current setting of @code{memory-query}.
7498
67b5c0c1
MM
7499@kindex set record btrace
7500The @code{btrace} record target does not trace data. As a
7501convenience, when replaying, @value{GDBN} reads read-only memory off
7502the live program directly, assuming that the addresses of the
7503read-only areas don't change. This for example makes it possible to
7504disassemble code while replaying, but not to print variables.
7505In some cases, being able to inspect variables might be useful.
7506You can use the following command for that:
7507
7508@item set record btrace replay-memory-access
7509Control the behavior of the @code{btrace} recording method when
7510accessing memory during replay. If @code{read-only} (the default),
7511@value{GDBN} will only allow accesses to read-only memory.
7512If @code{read-write}, @value{GDBN} will allow accesses to read-only
7513and to read-write memory. Beware that the accessed memory corresponds
7514to the live target and not necessarily to the current replay
7515position.
7516
4a4495d6
MM
7517@item set record btrace cpu @var{identifier}
7518Set the processor to be used for enabling workarounds for processor
7519errata when decoding the trace.
7520
7521Processor errata are defects in processor operation, caused by its
7522design or manufacture. They can cause a trace not to match the
7523specification. This, in turn, may cause trace decode to fail.
7524@value{GDBN} can detect erroneous trace packets and correct them, thus
7525avoiding the decoding failures. These corrections are known as
7526@dfn{errata workarounds}, and are enabled based on the processor on
7527which the trace was recorded.
7528
7529By default, @value{GDBN} attempts to detect the processor
7530automatically, and apply the necessary workarounds for it. However,
7531you may need to specify the processor if @value{GDBN} does not yet
7532support it. This command allows you to do that, and also allows to
7533disable the workarounds.
7534
7535The argument @var{identifier} identifies the @sc{cpu} and is of the
6b92c0d3 7536form: @code{@var{vendor}:@var{processor identifier}}. In addition,
4a4495d6
MM
7537there are two special identifiers, @code{none} and @code{auto}
7538(default).
7539
7540The following vendor identifiers and corresponding processor
7541identifiers are currently supported:
7542
7543@multitable @columnfractions .1 .9
7544
7545@item @code{intel}
7546@tab @var{family}/@var{model}[/@var{stepping}]
7547
7548@end multitable
7549
7550On GNU/Linux systems, the processor @var{family}, @var{model}, and
7551@var{stepping} can be obtained from @code{/proc/cpuinfo}.
7552
7553If @var{identifier} is @code{auto}, enable errata workarounds for the
7554processor on which the trace was recorded. If @var{identifier} is
7555@code{none}, errata workarounds are disabled.
7556
7557For example, when using an old @value{GDBN} on a new system, decode
7558may fail because @value{GDBN} does not support the new processor. It
7559often suffices to specify an older processor that @value{GDBN}
7560supports.
7561
7562@smallexample
7563(gdb) info record
7564Active record target: record-btrace
7565Recording format: Intel Processor Trace.
7566Buffer size: 16kB.
7567Failed to configure the Intel Processor Trace decoder: unknown cpu.
7568(gdb) set record btrace cpu intel:6/158
7569(gdb) info record
7570Active record target: record-btrace
7571Recording format: Intel Processor Trace.
7572Buffer size: 16kB.
7573Recorded 84872 instructions in 3189 functions (0 gaps) for thread 1 (...).
7574@end smallexample
7575
67b5c0c1
MM
7576@kindex show record btrace
7577@item show record btrace replay-memory-access
7578Show the current setting of @code{replay-memory-access}.
7579
4a4495d6
MM
7580@item show record btrace cpu
7581Show the processor to be used for enabling trace decode errata
7582workarounds.
7583
d33501a5
MM
7584@kindex set record btrace bts
7585@item set record btrace bts buffer-size @var{size}
7586@itemx set record btrace bts buffer-size unlimited
7587Set the requested ring buffer size for branch tracing in @acronym{BTS}
7588format. Default is 64KB.
7589
7590If @var{size} is a positive number, then @value{GDBN} will try to
7591allocate a buffer of at least @var{size} bytes for each new thread
7592that uses the btrace recording method and the @acronym{BTS} format.
7593The actually obtained buffer size may differ from the requested
7594@var{size}. Use the @code{info record} command to see the actual
7595buffer size for each thread that uses the btrace recording method and
7596the @acronym{BTS} format.
7597
7598If @var{limit} is @code{unlimited} or zero, @value{GDBN} will try to
7599allocate a buffer of 4MB.
7600
7601Bigger buffers mean longer traces. On the other hand, @value{GDBN} will
7602also need longer to process the branch trace data before it can be used.
7603
7604@item show record btrace bts buffer-size @var{size}
7605Show the current setting of the requested ring buffer size for branch
7606tracing in @acronym{BTS} format.
7607
b20a6524
MM
7608@kindex set record btrace pt
7609@item set record btrace pt buffer-size @var{size}
7610@itemx set record btrace pt buffer-size unlimited
bc504a31 7611Set the requested ring buffer size for branch tracing in Intel
b20a6524
MM
7612Processor Trace format. Default is 16KB.
7613
7614If @var{size} is a positive number, then @value{GDBN} will try to
7615allocate a buffer of at least @var{size} bytes for each new thread
bc504a31 7616that uses the btrace recording method and the Intel Processor Trace
b20a6524
MM
7617format. The actually obtained buffer size may differ from the
7618requested @var{size}. Use the @code{info record} command to see the
7619actual buffer size for each thread.
7620
7621If @var{limit} is @code{unlimited} or zero, @value{GDBN} will try to
7622allocate a buffer of 4MB.
7623
7624Bigger buffers mean longer traces. On the other hand, @value{GDBN} will
7625also need longer to process the branch trace data before it can be used.
7626
7627@item show record btrace pt buffer-size @var{size}
7628Show the current setting of the requested ring buffer size for branch
bc504a31 7629tracing in Intel Processor Trace format.
b20a6524 7630
29153c24
MS
7631@kindex info record
7632@item info record
59ea5688
MM
7633Show various statistics about the recording depending on the recording
7634method:
7635
7636@table @code
7637@item full
7638For the @code{full} recording method, it shows the state of process
7639record and its in-memory execution log buffer, including:
29153c24
MS
7640
7641@itemize @bullet
7642@item
7643Whether in record mode or replay mode.
7644@item
7645Lowest recorded instruction number (counting from when the current execution log started recording instructions).
7646@item
7647Highest recorded instruction number.
7648@item
7649Current instruction about to be replayed (if in replay mode).
7650@item
7651Number of instructions contained in the execution log.
7652@item
7653Maximum number of instructions that may be contained in the execution log.
7654@end itemize
53cc454a 7655
59ea5688 7656@item btrace
d33501a5
MM
7657For the @code{btrace} recording method, it shows:
7658
7659@itemize @bullet
7660@item
7661Recording format.
7662@item
7663Number of instructions that have been recorded.
7664@item
7665Number of blocks of sequential control-flow formed by the recorded
7666instructions.
7667@item
7668Whether in record mode or replay mode.
7669@end itemize
7670
7671For the @code{bts} recording format, it also shows:
7672@itemize @bullet
7673@item
7674Size of the perf ring buffer.
7675@end itemize
b20a6524
MM
7676
7677For the @code{pt} recording format, it also shows:
7678@itemize @bullet
7679@item
7680Size of the perf ring buffer.
7681@end itemize
59ea5688
MM
7682@end table
7683
53cc454a
HZ
7684@kindex record delete
7685@kindex rec del
7686@item record delete
a2311334 7687When record target runs in replay mode (``in the past''), delete the
53cc454a 7688subsequent execution log and begin to record a new execution log starting
a2311334 7689from the current address. This means you will abandon the previously
53cc454a 7690recorded ``future'' and begin recording a new ``future''.
59ea5688
MM
7691
7692@kindex record instruction-history
7693@kindex rec instruction-history
7694@item record instruction-history
7695Disassembles instructions from the recorded execution log. By
7696default, ten instructions are disassembled. This can be changed using
7697the @code{set record instruction-history-size} command. Instructions
da8c46d2
MM
7698are printed in execution order.
7699
0c532a29
MM
7700It can also print mixed source+disassembly if you specify the the
7701@code{/m} or @code{/s} modifier, and print the raw instructions in hex
7702as well as in symbolic form by specifying the @code{/r} modifier.
7703
7704The current position marker is printed for the instruction at the
7705current program counter value. This instruction can appear multiple
7706times in the trace and the current position marker will be printed
7707every time. To omit the current position marker, specify the
7708@code{/p} modifier.
7709
7710To better align the printed instructions when the trace contains
7711instructions from more than one function, the function name may be
7712omitted by specifying the @code{/f} modifier.
7713
da8c46d2
MM
7714Speculatively executed instructions are prefixed with @samp{?}. This
7715feature is not available for all recording formats.
7716
7717There are several ways to specify what part of the execution log to
7718disassemble:
59ea5688
MM
7719
7720@table @code
7721@item record instruction-history @var{insn}
7722Disassembles ten instructions starting from instruction number
7723@var{insn}.
7724
7725@item record instruction-history @var{insn}, +/-@var{n}
7726Disassembles @var{n} instructions around instruction number
7727@var{insn}. If @var{n} is preceded with @code{+}, disassembles
7728@var{n} instructions after instruction number @var{insn}. If
7729@var{n} is preceded with @code{-}, disassembles @var{n}
7730instructions before instruction number @var{insn}.
7731
7732@item record instruction-history
7733Disassembles ten more instructions after the last disassembly.
7734
7735@item record instruction-history -
7736Disassembles ten more instructions before the last disassembly.
7737
792005b0 7738@item record instruction-history @var{begin}, @var{end}
59ea5688
MM
7739Disassembles instructions beginning with instruction number
7740@var{begin} until instruction number @var{end}. The instruction
0688d04e 7741number @var{end} is included.
59ea5688
MM
7742@end table
7743
7744This command may not be available for all recording methods.
7745
7746@kindex set record
f81d1120
PA
7747@item set record instruction-history-size @var{size}
7748@itemx set record instruction-history-size unlimited
59ea5688
MM
7749Define how many instructions to disassemble in the @code{record
7750instruction-history} command. The default value is 10.
f81d1120 7751A @var{size} of @code{unlimited} means unlimited instructions.
59ea5688
MM
7752
7753@kindex show record
7754@item show record instruction-history-size
7755Show how many instructions to disassemble in the @code{record
7756instruction-history} command.
7757
7758@kindex record function-call-history
7759@kindex rec function-call-history
7760@item record function-call-history
7761Prints the execution history at function granularity. It prints one
7762line for each sequence of instructions that belong to the same
7763function giving the name of that function, the source lines
7764for this instruction sequence (if the @code{/l} modifier is
7765specified), and the instructions numbers that form the sequence (if
8710b709
MM
7766the @code{/i} modifier is specified). The function names are indented
7767to reflect the call stack depth if the @code{/c} modifier is
7768specified. The @code{/l}, @code{/i}, and @code{/c} modifiers can be
7769given together.
59ea5688
MM
7770
7771@smallexample
7772(@value{GDBP}) @b{list 1, 10}
77731 void foo (void)
77742 @{
77753 @}
77764
77775 void bar (void)
77786 @{
77797 ...
77808 foo ();
77819 ...
778210 @}
8710b709
MM
7783(@value{GDBP}) @b{record function-call-history /ilc}
77841 bar inst 1,4 at foo.c:6,8
77852 foo inst 5,10 at foo.c:2,3
77863 bar inst 11,13 at foo.c:9,10
59ea5688
MM
7787@end smallexample
7788
7789By default, ten lines are printed. This can be changed using the
7790@code{set record function-call-history-size} command. Functions are
7791printed in execution order. There are several ways to specify what
7792to print:
7793
7794@table @code
7795@item record function-call-history @var{func}
7796Prints ten functions starting from function number @var{func}.
7797
7798@item record function-call-history @var{func}, +/-@var{n}
7799Prints @var{n} functions around function number @var{func}. If
7800@var{n} is preceded with @code{+}, prints @var{n} functions after
7801function number @var{func}. If @var{n} is preceded with @code{-},
7802prints @var{n} functions before function number @var{func}.
7803
7804@item record function-call-history
7805Prints ten more functions after the last ten-line print.
7806
7807@item record function-call-history -
7808Prints ten more functions before the last ten-line print.
7809
792005b0 7810@item record function-call-history @var{begin}, @var{end}
59ea5688 7811Prints functions beginning with function number @var{begin} until
0688d04e 7812function number @var{end}. The function number @var{end} is included.
59ea5688
MM
7813@end table
7814
7815This command may not be available for all recording methods.
7816
f81d1120
PA
7817@item set record function-call-history-size @var{size}
7818@itemx set record function-call-history-size unlimited
59ea5688
MM
7819Define how many lines to print in the
7820@code{record function-call-history} command. The default value is 10.
f81d1120 7821A size of @code{unlimited} means unlimited lines.
59ea5688
MM
7822
7823@item show record function-call-history-size
7824Show how many lines to print in the
7825@code{record function-call-history} command.
53cc454a
HZ
7826@end table
7827
7828
6d2ebf8b 7829@node Stack
c906108c
SS
7830@chapter Examining the Stack
7831
7832When your program has stopped, the first thing you need to know is where it
7833stopped and how it got there.
7834
7835@cindex call stack
5d161b24
DB
7836Each time your program performs a function call, information about the call
7837is generated.
7838That information includes the location of the call in your program,
7839the arguments of the call,
c906108c 7840and the local variables of the function being called.
5d161b24 7841The information is saved in a block of data called a @dfn{stack frame}.
c906108c
SS
7842The stack frames are allocated in a region of memory called the @dfn{call
7843stack}.
7844
7845When your program stops, the @value{GDBN} commands for examining the
7846stack allow you to see all of this information.
7847
7848@cindex selected frame
7849One of the stack frames is @dfn{selected} by @value{GDBN} and many
7850@value{GDBN} commands refer implicitly to the selected frame. In
7851particular, whenever you ask @value{GDBN} for the value of a variable in
7852your program, the value is found in the selected frame. There are
7853special @value{GDBN} commands to select whichever frame you are
79a6e687 7854interested in. @xref{Selection, ,Selecting a Frame}.
c906108c
SS
7855
7856When your program stops, @value{GDBN} automatically selects the
5d161b24 7857currently executing frame and describes it briefly, similar to the
79a6e687 7858@code{frame} command (@pxref{Frame Info, ,Information about a Frame}).
c906108c
SS
7859
7860@menu
7861* Frames:: Stack frames
7862* Backtrace:: Backtraces
7863* Selection:: Selecting a frame
7864* Frame Info:: Information on a frame
0a232300 7865* Frame Apply:: Applying a command to several frames
0f59c28f 7866* Frame Filter Management:: Managing frame filters
c906108c
SS
7867
7868@end menu
7869
6d2ebf8b 7870@node Frames
79a6e687 7871@section Stack Frames
c906108c 7872
d4f3574e 7873@cindex frame, definition
c906108c
SS
7874@cindex stack frame
7875The call stack is divided up into contiguous pieces called @dfn{stack
7876frames}, or @dfn{frames} for short; each frame is the data associated
7877with one call to one function. The frame contains the arguments given
7878to the function, the function's local variables, and the address at
7879which the function is executing.
7880
7881@cindex initial frame
7882@cindex outermost frame
7883@cindex innermost frame
7884When your program is started, the stack has only one frame, that of the
7885function @code{main}. This is called the @dfn{initial} frame or the
7886@dfn{outermost} frame. Each time a function is called, a new frame is
7887made. Each time a function returns, the frame for that function invocation
7888is eliminated. If a function is recursive, there can be many frames for
7889the same function. The frame for the function in which execution is
7890actually occurring is called the @dfn{innermost} frame. This is the most
7891recently created of all the stack frames that still exist.
7892
7893@cindex frame pointer
7894Inside your program, stack frames are identified by their addresses. A
7895stack frame consists of many bytes, each of which has its own address; each
7896kind of computer has a convention for choosing one byte whose
7897address serves as the address of the frame. Usually this address is kept
e09f16f9
EZ
7898in a register called the @dfn{frame pointer register}
7899(@pxref{Registers, $fp}) while execution is going on in that frame.
c906108c 7900
f67ffa6a 7901@cindex frame level
c906108c 7902@cindex frame number
f67ffa6a
AB
7903@value{GDBN} labels each existing stack frame with a @dfn{level}, a
7904number that is zero for the innermost frame, one for the frame that
7905called it, and so on upward. These level numbers give you a way of
7906designating stack frames in @value{GDBN} commands. The terms
7907@dfn{frame number} and @dfn{frame level} can be used interchangeably to
7908describe this number.
c906108c 7909
6d2ebf8b
SS
7910@c The -fomit-frame-pointer below perennially causes hbox overflow
7911@c underflow problems.
c906108c
SS
7912@cindex frameless execution
7913Some compilers provide a way to compile functions so that they operate
e22ea452 7914without stack frames. (For example, the @value{NGCC} option
474c8240 7915@smallexample
6d2ebf8b 7916@samp{-fomit-frame-pointer}
474c8240 7917@end smallexample
6d2ebf8b 7918generates functions without a frame.)
c906108c
SS
7919This is occasionally done with heavily used library functions to save
7920the frame setup time. @value{GDBN} has limited facilities for dealing
7921with these function invocations. If the innermost function invocation
7922has no stack frame, @value{GDBN} nevertheless regards it as though
7923it had a separate frame, which is numbered zero as usual, allowing
7924correct tracing of the function call chain. However, @value{GDBN} has
7925no provision for frameless functions elsewhere in the stack.
7926
6d2ebf8b 7927@node Backtrace
c906108c
SS
7928@section Backtraces
7929
09d4efe1
EZ
7930@cindex traceback
7931@cindex call stack traces
c906108c
SS
7932A backtrace is a summary of how your program got where it is. It shows one
7933line per frame, for many frames, starting with the currently executing
7934frame (frame zero), followed by its caller (frame one), and on up the
7935stack.
7936
1e611234 7937@anchor{backtrace-command}
c906108c 7938@kindex backtrace
41afff9a 7939@kindex bt @r{(@code{backtrace})}
ea3b0687
TT
7940To print a backtrace of the entire stack, use the @code{backtrace}
7941command, or its alias @code{bt}. This command will print one line per
7942frame for frames in the stack. By default, all stack frames are
7943printed. You can stop the backtrace at any time by typing the system
7944interrupt character, normally @kbd{Ctrl-c}.
7945
7946@table @code
3345721a
PA
7947@item backtrace [@var{option}]@dots{} [@var{qualifier}]@dots{} [@var{count}]
7948@itemx bt [@var{option}]@dots{} [@var{qualifier}]@dots{} [@var{count}]
7949Print the backtrace of the entire stack.
7950
7951The optional @var{count} can be one of the following:
ea3b0687
TT
7952
7953@table @code
7954@item @var{n}
7955@itemx @var{n}
7956Print only the innermost @var{n} frames, where @var{n} is a positive
7957number.
7958
7959@item -@var{n}
7960@itemx -@var{n}
7961Print only the outermost @var{n} frames, where @var{n} is a positive
7962number.
3345721a 7963@end table
ea3b0687 7964
3345721a
PA
7965Options:
7966
7967@table @code
7968@item -full
ea3b0687 7969Print the values of the local variables also. This can be combined
3345721a 7970with the optional @var{count} to limit the number of frames shown.
ea3b0687 7971
3345721a 7972@item -no-filters
1e611234
PM
7973Do not run Python frame filters on this backtrace. @xref{Frame
7974Filter API}, for more information. Additionally use @ref{disable
7975frame-filter all} to turn off all frame filters. This is only
7976relevant when @value{GDBN} has been configured with @code{Python}
7977support.
978d6c75 7978
3345721a 7979@item -hide
978d6c75
TT
7980A Python frame filter might decide to ``elide'' some frames. Normally
7981such elided frames are still printed, but they are indented relative
3345721a 7982to the filtered frames that cause them to be elided. The @code{-hide}
978d6c75 7983option causes elided frames to not be printed at all.
c906108c 7984@end table
3345721a
PA
7985
7986The @code{backtrace} command also supports a number of options that
7987allow overriding relevant global print settings as set by @code{set
7988backtrace} and @code{set print} subcommands:
7989
7990@table @code
7991@item -past-main [@code{on}|@code{off}]
7992Set whether backtraces should continue past @code{main}. Related setting:
7993@ref{set backtrace past-main}.
7994
7995@item -past-entry [@code{on}|@code{off}]
7996Set whether backtraces should continue past the entry point of a program.
7997Related setting: @ref{set backtrace past-entry}.
7998
7999@item -entry-values @code{no}|@code{only}|@code{preferred}|@code{if-needed}|@code{both}|@code{compact}|@code{default}
8000Set printing of function arguments at function entry.
8001Related setting: @ref{set print entry-values}.
8002
8003@item -frame-arguments @code{all}|@code{scalars}|@code{none}
8004Set printing of non-scalar frame arguments.
8005Related setting: @ref{set print frame-arguments}.
8006
8007@item -raw-frame-arguments [@code{on}|@code{off}]
8008Set whether to print frame arguments in raw form.
8009Related setting: @ref{set print raw-frame-arguments}.
bc4268a5
PW
8010
8011@item -frame-info @code{auto}|@code{source-line}|@code{location}|@code{source-and-location}|@code{location-and-address}|@code{short-location}
8012Set printing of frame information.
8013Related setting: @ref{set print frame-info}.
3345721a
PA
8014@end table
8015
8016The optional @var{qualifier} is maintained for backward compatibility.
8017It can be one of the following:
8018
8019@table @code
8020@item full
8021Equivalent to the @code{-full} option.
8022
8023@item no-filters
8024Equivalent to the @code{-no-filters} option.
8025
8026@item hide
8027Equivalent to the @code{-hide} option.
8028@end table
8029
ea3b0687 8030@end table
c906108c
SS
8031
8032@kindex where
8033@kindex info stack
c906108c
SS
8034The names @code{where} and @code{info stack} (abbreviated @code{info s})
8035are additional aliases for @code{backtrace}.
8036
839c27b7
EZ
8037@cindex multiple threads, backtrace
8038In a multi-threaded program, @value{GDBN} by default shows the
8039backtrace only for the current thread. To display the backtrace for
8040several or all of the threads, use the command @code{thread apply}
8041(@pxref{Threads, thread apply}). For example, if you type @kbd{thread
8042apply all backtrace}, @value{GDBN} will display the backtrace for all
8043the threads; this is handy when you debug a core dump of a
8044multi-threaded program.
8045
c906108c
SS
8046Each line in the backtrace shows the frame number and the function name.
8047The program counter value is also shown---unless you use @code{set
8048print address off}. The backtrace also shows the source file name and
8049line number, as well as the arguments to the function. The program
8050counter value is omitted if it is at the beginning of the code for that
8051line number.
8052
8053Here is an example of a backtrace. It was made with the command
8054@samp{bt 3}, so it shows the innermost three frames.
8055
8056@smallexample
8057@group
5d161b24 8058#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
c906108c 8059 at builtin.c:993
4f5376b2 8060#1 0x6e38 in expand_macro (sym=0x2b600, data=...) at macro.c:242
c906108c
SS
8061#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
8062 at macro.c:71
8063(More stack frames follow...)
8064@end group
8065@end smallexample
8066
8067@noindent
8068The display for frame zero does not begin with a program counter
8069value, indicating that your program has stopped at the beginning of the
8070code for line @code{993} of @code{builtin.c}.
8071
4f5376b2
JB
8072@noindent
8073The value of parameter @code{data} in frame 1 has been replaced by
8074@code{@dots{}}. By default, @value{GDBN} prints the value of a parameter
8075only if it is a scalar (integer, pointer, enumeration, etc). See command
8076@kbd{set print frame-arguments} in @ref{Print Settings} for more details
8077on how to configure the way function parameter values are printed.
bc4268a5
PW
8078The command @kbd{set print frame-info} (@pxref{Print Settings}) controls
8079what frame information is printed.
4f5376b2 8080
585fdaa1 8081@cindex optimized out, in backtrace
18999be5
EZ
8082@cindex function call arguments, optimized out
8083If your program was compiled with optimizations, some compilers will
8084optimize away arguments passed to functions if those arguments are
8085never used after the call. Such optimizations generate code that
8086passes arguments through registers, but doesn't store those arguments
8087in the stack frame. @value{GDBN} has no way of displaying such
8088arguments in stack frames other than the innermost one. Here's what
8089such a backtrace might look like:
8090
8091@smallexample
8092@group
8093#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
8094 at builtin.c:993
585fdaa1
PA
8095#1 0x6e38 in expand_macro (sym=<optimized out>) at macro.c:242
8096#2 0x6840 in expand_token (obs=0x0, t=<optimized out>, td=0xf7fffb08)
18999be5
EZ
8097 at macro.c:71
8098(More stack frames follow...)
8099@end group
8100@end smallexample
8101
8102@noindent
8103The values of arguments that were not saved in their stack frames are
585fdaa1 8104shown as @samp{<optimized out>}.
18999be5
EZ
8105
8106If you need to display the values of such optimized-out arguments,
8107either deduce that from other variables whose values depend on the one
8108you are interested in, or recompile without optimizations.
8109
a8f24a35
EZ
8110@cindex backtrace beyond @code{main} function
8111@cindex program entry point
8112@cindex startup code, and backtrace
25d29d70
AC
8113Most programs have a standard user entry point---a place where system
8114libraries and startup code transition into user code. For C this is
d416eeec
EZ
8115@code{main}@footnote{
8116Note that embedded programs (the so-called ``free-standing''
8117environment) are not required to have a @code{main} function as the
8118entry point. They could even have multiple entry points.}.
8119When @value{GDBN} finds the entry function in a backtrace
25d29d70
AC
8120it will terminate the backtrace, to avoid tracing into highly
8121system-specific (and generally uninteresting) code.
8122
8123If you need to examine the startup code, or limit the number of levels
8124in a backtrace, you can change this behavior:
95f90d25
DJ
8125
8126@table @code
25d29d70
AC
8127@item set backtrace past-main
8128@itemx set backtrace past-main on
3345721a 8129@anchor{set backtrace past-main}
4644b6e3 8130@kindex set backtrace
25d29d70
AC
8131Backtraces will continue past the user entry point.
8132
8133@item set backtrace past-main off
95f90d25
DJ
8134Backtraces will stop when they encounter the user entry point. This is the
8135default.
8136
25d29d70 8137@item show backtrace past-main
4644b6e3 8138@kindex show backtrace
25d29d70
AC
8139Display the current user entry point backtrace policy.
8140
2315ffec
RC
8141@item set backtrace past-entry
8142@itemx set backtrace past-entry on
3345721a 8143@anchor{set backtrace past-entry}
a8f24a35 8144Backtraces will continue past the internal entry point of an application.
2315ffec
RC
8145This entry point is encoded by the linker when the application is built,
8146and is likely before the user entry point @code{main} (or equivalent) is called.
8147
8148@item set backtrace past-entry off
d3e8051b 8149Backtraces will stop when they encounter the internal entry point of an
2315ffec
RC
8150application. This is the default.
8151
8152@item show backtrace past-entry
8153Display the current internal entry point backtrace policy.
8154
25d29d70
AC
8155@item set backtrace limit @var{n}
8156@itemx set backtrace limit 0
f81d1120 8157@itemx set backtrace limit unlimited
3345721a 8158@anchor{set backtrace limit}
25d29d70 8159@cindex backtrace limit
f81d1120
PA
8160Limit the backtrace to @var{n} levels. A value of @code{unlimited}
8161or zero means unlimited levels.
95f90d25 8162
25d29d70
AC
8163@item show backtrace limit
8164Display the current limit on backtrace levels.
95f90d25
DJ
8165@end table
8166
1b56eb55
JK
8167You can control how file names are displayed.
8168
8169@table @code
8170@item set filename-display
8171@itemx set filename-display relative
8172@cindex filename-display
8173Display file names relative to the compilation directory. This is the default.
8174
8175@item set filename-display basename
8176Display only basename of a filename.
8177
8178@item set filename-display absolute
8179Display an absolute filename.
8180
8181@item show filename-display
8182Show the current way to display filenames.
8183@end table
8184
6d2ebf8b 8185@node Selection
79a6e687 8186@section Selecting a Frame
c906108c
SS
8187
8188Most commands for examining the stack and other data in your program work on
8189whichever stack frame is selected at the moment. Here are the commands for
8190selecting a stack frame; all of them finish by printing a brief description
8191of the stack frame just selected.
8192
8193@table @code
d4f3574e 8194@kindex frame@r{, selecting}
41afff9a 8195@kindex f @r{(@code{frame})}
f67ffa6a
AB
8196@item frame @r{[} @var{frame-selection-spec} @r{]}
8197@item f @r{[} @var{frame-selection-spec} @r{]}
8198The @command{frame} command allows different stack frames to be
8199selected. The @var{frame-selection-spec} can be any of the following:
8200
8201@table @code
8202@kindex frame level
8203@item @var{num}
8204@item level @var{num}
8205Select frame level @var{num}. Recall that frame zero is the innermost
c906108c 8206(currently executing) frame, frame one is the frame that called the
f67ffa6a
AB
8207innermost one, and so on. The highest level frame is usually the one
8208for @code{main}.
8209
8210As this is the most common method of navigating the frame stack, the
8211string @command{level} can be omitted. For example, the following two
8212commands are equivalent:
8213
8214@smallexample
8215(@value{GDBP}) frame 3
8216(@value{GDBP}) frame level 3
8217@end smallexample
8218
8219@kindex frame address
8220@item address @var{stack-address}
8221Select the frame with stack address @var{stack-address}. The
8222@var{stack-address} for a frame can be seen in the output of
8223@command{info frame}, for example:
8224
8225@smallexample
8226(gdb) info frame
8227Stack level 1, frame at 0x7fffffffda30:
8228 rip = 0x40066d in b (amd64-entry-value.cc:59); saved rip 0x4004c5
8229 tail call frame, caller of frame at 0x7fffffffda30
8230 source language c++.
8231 Arglist at unknown address.
8232 Locals at unknown address, Previous frame's sp is 0x7fffffffda30
8233@end smallexample
8234
8235The @var{stack-address} for this frame is @code{0x7fffffffda30} as
8236indicated by the line:
8237
8238@smallexample
8239Stack level 1, frame at 0x7fffffffda30:
8240@end smallexample
8241
8242@kindex frame function
8243@item function @var{function-name}
8244Select the stack frame for function @var{function-name}. If there are
8245multiple stack frames for function @var{function-name} then the inner
8246most stack frame is selected.
8247
8248@kindex frame view
8249@item view @var{stack-address} @r{[} @var{pc-addr} @r{]}
8250View a frame that is not part of @value{GDBN}'s backtrace. The frame
8251viewed has stack address @var{stack-addr}, and optionally, a program
8252counter address of @var{pc-addr}.
8253
8254This is useful mainly if the chaining of stack frames has been
8255damaged by a bug, making it impossible for @value{GDBN} to assign
8256numbers properly to all frames. In addition, this can be useful
8257when your program has multiple stacks and switches between them.
8258
8259When viewing a frame outside the current backtrace using
8260@command{frame view} then you can always return to the original
8261stack using one of the previous stack frame selection instructions,
8262for example @command{frame level 0}.
8263
8264@end table
c906108c
SS
8265
8266@kindex up
8267@item up @var{n}
697aa1b7
EZ
8268Move @var{n} frames up the stack; @var{n} defaults to 1. For positive
8269numbers @var{n}, this advances toward the outermost frame, to higher
8270frame numbers, to frames that have existed longer.
c906108c
SS
8271
8272@kindex down
41afff9a 8273@kindex do @r{(@code{down})}
c906108c 8274@item down @var{n}
697aa1b7
EZ
8275Move @var{n} frames down the stack; @var{n} defaults to 1. For
8276positive numbers @var{n}, this advances toward the innermost frame, to
8277lower frame numbers, to frames that were created more recently.
8278You may abbreviate @code{down} as @code{do}.
c906108c
SS
8279@end table
8280
8281All of these commands end by printing two lines of output describing the
8282frame. The first line shows the frame number, the function name, the
8283arguments, and the source file and line number of execution in that
5d161b24 8284frame. The second line shows the text of that source line.
c906108c
SS
8285
8286@need 1000
8287For example:
8288
8289@smallexample
8290@group
8291(@value{GDBP}) up
8292#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
8293 at env.c:10
829410 read_input_file (argv[i]);
8295@end group
8296@end smallexample
8297
8298After such a printout, the @code{list} command with no arguments
8299prints ten lines centered on the point of execution in the frame.
87885426
FN
8300You can also edit the program at the point of execution with your favorite
8301editing program by typing @code{edit}.
79a6e687 8302@xref{List, ,Printing Source Lines},
87885426 8303for details.
c906108c
SS
8304
8305@table @code
fc58fa65 8306@kindex select-frame
f67ffa6a 8307@item select-frame @r{[} @var{frame-selection-spec} @r{]}
fc58fa65
AB
8308The @code{select-frame} command is a variant of @code{frame} that does
8309not display the new frame after selecting it. This command is
8310intended primarily for use in @value{GDBN} command scripts, where the
f67ffa6a
AB
8311output might be unnecessary and distracting. The
8312@var{frame-selection-spec} is as for the @command{frame} command
8313described in @ref{Selection, ,Selecting a Frame}.
fc58fa65 8314
c906108c
SS
8315@kindex down-silently
8316@kindex up-silently
8317@item up-silently @var{n}
8318@itemx down-silently @var{n}
8319These two commands are variants of @code{up} and @code{down},
8320respectively; they differ in that they do their work silently, without
8321causing display of the new frame. They are intended primarily for use
8322in @value{GDBN} command scripts, where the output might be unnecessary and
8323distracting.
8324@end table
8325
6d2ebf8b 8326@node Frame Info
79a6e687 8327@section Information About a Frame
c906108c
SS
8328
8329There are several other commands to print information about the selected
8330stack frame.
8331
8332@table @code
8333@item frame
8334@itemx f
8335When used without any argument, this command does not change which
8336frame is selected, but prints a brief description of the currently
8337selected stack frame. It can be abbreviated @code{f}. With an
8338argument, this command is used to select a stack frame.
79a6e687 8339@xref{Selection, ,Selecting a Frame}.
c906108c
SS
8340
8341@kindex info frame
41afff9a 8342@kindex info f @r{(@code{info frame})}
c906108c
SS
8343@item info frame
8344@itemx info f
8345This command prints a verbose description of the selected stack frame,
8346including:
8347
8348@itemize @bullet
5d161b24
DB
8349@item
8350the address of the frame
c906108c
SS
8351@item
8352the address of the next frame down (called by this frame)
8353@item
8354the address of the next frame up (caller of this frame)
8355@item
8356the language in which the source code corresponding to this frame is written
8357@item
8358the address of the frame's arguments
8359@item
d4f3574e
SS
8360the address of the frame's local variables
8361@item
c906108c
SS
8362the program counter saved in it (the address of execution in the caller frame)
8363@item
8364which registers were saved in the frame
8365@end itemize
8366
8367@noindent The verbose description is useful when
8368something has gone wrong that has made the stack format fail to fit
8369the usual conventions.
8370
f67ffa6a
AB
8371@item info frame @r{[} @var{frame-selection-spec} @r{]}
8372@itemx info f @r{[} @var{frame-selection-spec} @r{]}
8373Print a verbose description of the frame selected by
8374@var{frame-selection-spec}. The @var{frame-selection-spec} is the
8375same as for the @command{frame} command (@pxref{Selection, ,Selecting
8376a Frame}). The selected frame remains unchanged by this command.
c906108c
SS
8377
8378@kindex info args
d321477b 8379@item info args [-q]
c906108c
SS
8380Print the arguments of the selected frame, each on a separate line.
8381
d321477b
PW
8382The optional flag @samp{-q}, which stands for @samp{quiet}, disables
8383printing header information and messages explaining why no argument
8384have been printed.
8385
8386@item info args [-q] [-t @var{type_regexp}] [@var{regexp}]
8387Like @kbd{info args}, but only print the arguments selected
8388with the provided regexp(s).
8389
8390If @var{regexp} is provided, print only the arguments whose names
8391match the regular expression @var{regexp}.
8392
8393If @var{type_regexp} is provided, print only the arguments whose
8394types, as printed by the @code{whatis} command, match
8395the regular expression @var{type_regexp}.
8396If @var{type_regexp} contains space(s), it should be enclosed in
8397quote characters. If needed, use backslash to escape the meaning
8398of special characters or quotes.
8399
8400If both @var{regexp} and @var{type_regexp} are provided, an argument
8401is printed only if its name matches @var{regexp} and its type matches
8402@var{type_regexp}.
8403
8404@item info locals [-q]
c906108c
SS
8405@kindex info locals
8406Print the local variables of the selected frame, each on a separate
8407line. These are all variables (declared either static or automatic)
8408accessible at the point of execution of the selected frame.
8409
d321477b
PW
8410The optional flag @samp{-q}, which stands for @samp{quiet}, disables
8411printing header information and messages explaining why no local variables
8412have been printed.
8413
8414@item info locals [-q] [-t @var{type_regexp}] [@var{regexp}]
8415Like @kbd{info locals}, but only print the local variables selected
8416with the provided regexp(s).
8417
8418If @var{regexp} is provided, print only the local variables whose names
8419match the regular expression @var{regexp}.
8420
8421If @var{type_regexp} is provided, print only the local variables whose
8422types, as printed by the @code{whatis} command, match
8423the regular expression @var{type_regexp}.
8424If @var{type_regexp} contains space(s), it should be enclosed in
8425quote characters. If needed, use backslash to escape the meaning
8426of special characters or quotes.
8427
8428If both @var{regexp} and @var{type_regexp} are provided, a local variable
8429is printed only if its name matches @var{regexp} and its type matches
8430@var{type_regexp}.
8431
8432The command @kbd{info locals -q -t @var{type_regexp}} can usefully be
8433combined with the commands @kbd{frame apply} and @kbd{thread apply}.
8434For example, your program might use Resource Acquisition Is
8435Initialization types (RAII) such as @code{lock_something_t}: each
8436local variable of type @code{lock_something_t} automatically places a
8437lock that is destroyed when the variable goes out of scope. You can
8438then list all acquired locks in your program by doing
8439@smallexample
8440thread apply all -s frame apply all -s info locals -q -t lock_something_t
8441@end smallexample
8442@noindent
8443or the equivalent shorter form
8444@smallexample
8445tfaas i lo -q -t lock_something_t
8446@end smallexample
8447
c906108c
SS
8448@end table
8449
0a232300
PW
8450@node Frame Apply
8451@section Applying a Command to Several Frames.
3345721a 8452@anchor{frame apply}
0a232300
PW
8453@kindex frame apply
8454@cindex apply command to several frames
8455@table @code
3345721a 8456@item frame apply [all | @var{count} | @var{-count} | level @var{level}@dots{}] [@var{option}]@dots{} @var{command}
0a232300
PW
8457The @code{frame apply} command allows you to apply the named
8458@var{command} to one or more frames.
8459
8460@table @code
8461@item @code{all}
8462Specify @code{all} to apply @var{command} to all frames.
8463
8464@item @var{count}
8465Use @var{count} to apply @var{command} to the innermost @var{count}
8466frames, where @var{count} is a positive number.
8467
8468@item @var{-count}
8469Use @var{-count} to apply @var{command} to the outermost @var{count}
8470frames, where @var{count} is a positive number.
8471
8472@item @code{level}
8473Use @code{level} to apply @var{command} to the set of frames identified
8474by the @var{level} list. @var{level} is a frame level or a range of frame
8475levels as @var{level1}-@var{level2}. The frame level is the number shown
8476in the first field of the @samp{backtrace} command output.
8477E.g., @samp{2-4 6-8 3} indicates to apply @var{command} for the frames
8478at levels 2, 3, 4, 6, 7, 8, and then again on frame at level 3.
8479
8480@end table
8481
0a232300
PW
8482Note that the frames on which @code{frame apply} applies a command are
8483also influenced by the @code{set backtrace} settings such as @code{set
3345721a 8484backtrace past-main} and @code{set backtrace limit N}.
0a232300
PW
8485@xref{Backtrace,,Backtraces}.
8486
3345721a
PA
8487The @code{frame apply} command also supports a number of options that
8488allow overriding relevant @code{set backtrace} settings:
8489
8490@table @code
8491@item -past-main [@code{on}|@code{off}]
8492Whether backtraces should continue past @code{main}.
8493Related setting: @ref{set backtrace past-main}.
8494
8495@item -past-entry [@code{on}|@code{off}]
8496Whether backtraces should continue past the entry point of a program.
8497Related setting: @ref{set backtrace past-entry}.
8498@end table
0a232300
PW
8499
8500By default, @value{GDBN} displays some frame information before the
8501output produced by @var{command}, and an error raised during the
8502execution of a @var{command} will abort @code{frame apply}. The
3345721a 8503following options can be used to fine-tune these behaviors:
0a232300
PW
8504
8505@table @code
8506@item -c
8507The flag @code{-c}, which stands for @samp{continue}, causes any
8508errors in @var{command} to be displayed, and the execution of
8509@code{frame apply} then continues.
8510@item -s
8511The flag @code{-s}, which stands for @samp{silent}, causes any errors
8512or empty output produced by a @var{command} to be silently ignored.
8513That is, the execution continues, but the frame information and errors
8514are not printed.
8515@item -q
8516The flag @code{-q} (@samp{quiet}) disables printing the frame
8517information.
8518@end table
8519
8520The following example shows how the flags @code{-c} and @code{-s} are
8521working when applying the command @code{p j} to all frames, where
8522variable @code{j} can only be successfully printed in the outermost
8523@code{#1 main} frame.
8524
8525@smallexample
8526@group
8527(gdb) frame apply all p j
8528#0 some_function (i=5) at fun.c:4
8529No symbol "j" in current context.
8530(gdb) frame apply all -c p j
8531#0 some_function (i=5) at fun.c:4
8532No symbol "j" in current context.
8533#1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8534$1 = 5
8535(gdb) frame apply all -s p j
8536#1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8537$2 = 5
8538(gdb)
8539@end group
8540@end smallexample
8541
8542By default, @samp{frame apply}, prints the frame location
8543information before the command output:
8544
8545@smallexample
8546@group
8547(gdb) frame apply all p $sp
8548#0 some_function (i=5) at fun.c:4
8549$4 = (void *) 0xffffd1e0
8550#1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8551$5 = (void *) 0xffffd1f0
8552(gdb)
8553@end group
8554@end smallexample
8555
3345721a 8556If the flag @code{-q} is given, no frame information is printed:
0a232300
PW
8557@smallexample
8558@group
8559(gdb) frame apply all -q p $sp
8560$12 = (void *) 0xffffd1e0
8561$13 = (void *) 0xffffd1f0
8562(gdb)
8563@end group
8564@end smallexample
8565
3345721a
PA
8566@end table
8567
0a232300
PW
8568@table @code
8569
8570@kindex faas
8571@cindex apply a command to all frames (ignoring errors and empty output)
8572@item faas @var{command}
8573Shortcut for @code{frame apply all -s @var{command}}.
8574Applies @var{command} on all frames, ignoring errors and empty output.
8575
8576It can for example be used to print a local variable or a function
8577argument without knowing the frame where this variable or argument
8578is, using:
8579@smallexample
8580(@value{GDBP}) faas p some_local_var_i_do_not_remember_where_it_is
8581@end smallexample
8582
3345721a
PA
8583The @code{faas} command accepts the same options as the @code{frame
8584apply} command. @xref{frame apply}.
8585
0a232300
PW
8586Note that the command @code{tfaas @var{command}} applies @var{command}
8587on all frames of all threads. See @xref{Threads,,Threads}.
8588@end table
8589
8590
fc58fa65
AB
8591@node Frame Filter Management
8592@section Management of Frame Filters.
8593@cindex managing frame filters
8594
8595Frame filters are Python based utilities to manage and decorate the
8596output of frames. @xref{Frame Filter API}, for further information.
8597
8598Managing frame filters is performed by several commands available
8599within @value{GDBN}, detailed here.
8600
8601@table @code
8602@kindex info frame-filter
8603@item info frame-filter
8604Print a list of installed frame filters from all dictionaries, showing
8605their name, priority and enabled status.
8606
8607@kindex disable frame-filter
8608@anchor{disable frame-filter all}
8609@item disable frame-filter @var{filter-dictionary} @var{filter-name}
8610Disable a frame filter in the dictionary matching
8611@var{filter-dictionary} and @var{filter-name}. The
8612@var{filter-dictionary} may be @code{all}, @code{global},
8613@code{progspace}, or the name of the object file where the frame filter
8614dictionary resides. When @code{all} is specified, all frame filters
8615across all dictionaries are disabled. The @var{filter-name} is the name
8616of the frame filter and is used when @code{all} is not the option for
8617@var{filter-dictionary}. A disabled frame-filter is not deleted, it
8618may be enabled again later.
8619
8620@kindex enable frame-filter
8621@item enable frame-filter @var{filter-dictionary} @var{filter-name}
8622Enable a frame filter in the dictionary matching
8623@var{filter-dictionary} and @var{filter-name}. The
8624@var{filter-dictionary} may be @code{all}, @code{global},
8625@code{progspace} or the name of the object file where the frame filter
8626dictionary resides. When @code{all} is specified, all frame filters across
8627all dictionaries are enabled. The @var{filter-name} is the name of the frame
8628filter and is used when @code{all} is not the option for
8629@var{filter-dictionary}.
8630
8631Example:
8632
8633@smallexample
8634(gdb) info frame-filter
8635
8636global frame-filters:
8637 Priority Enabled Name
8638 1000 No PrimaryFunctionFilter
8639 100 Yes Reverse
8640
8641progspace /build/test frame-filters:
8642 Priority Enabled Name
8643 100 Yes ProgspaceFilter
8644
8645objfile /build/test frame-filters:
8646 Priority Enabled Name
6b92c0d3 8647 999 Yes BuildProgramFilter
fc58fa65
AB
8648
8649(gdb) disable frame-filter /build/test BuildProgramFilter
8650(gdb) info frame-filter
8651
8652global frame-filters:
8653 Priority Enabled Name
8654 1000 No PrimaryFunctionFilter
8655 100 Yes Reverse
8656
8657progspace /build/test frame-filters:
8658 Priority Enabled Name
8659 100 Yes ProgspaceFilter
8660
8661objfile /build/test frame-filters:
8662 Priority Enabled Name
8663 999 No BuildProgramFilter
8664
8665(gdb) enable frame-filter global PrimaryFunctionFilter
8666(gdb) info frame-filter
8667
8668global frame-filters:
8669 Priority Enabled Name
8670 1000 Yes PrimaryFunctionFilter
8671 100 Yes Reverse
8672
8673progspace /build/test frame-filters:
8674 Priority Enabled Name
8675 100 Yes ProgspaceFilter
8676
8677objfile /build/test frame-filters:
8678 Priority Enabled Name
8679 999 No BuildProgramFilter
8680@end smallexample
8681
8682@kindex set frame-filter priority
8683@item set frame-filter priority @var{filter-dictionary} @var{filter-name} @var{priority}
8684Set the @var{priority} of a frame filter in the dictionary matching
8685@var{filter-dictionary}, and the frame filter name matching
8686@var{filter-name}. The @var{filter-dictionary} may be @code{global},
8687@code{progspace} or the name of the object file where the frame filter
8688dictionary resides. The @var{priority} is an integer.
8689
8690@kindex show frame-filter priority
8691@item show frame-filter priority @var{filter-dictionary} @var{filter-name}
8692Show the @var{priority} of a frame filter in the dictionary matching
8693@var{filter-dictionary}, and the frame filter name matching
8694@var{filter-name}. The @var{filter-dictionary} may be @code{global},
8695@code{progspace} or the name of the object file where the frame filter
8696dictionary resides.
8697
8698Example:
8699
8700@smallexample
8701(gdb) info frame-filter
8702
8703global frame-filters:
8704 Priority Enabled Name
8705 1000 Yes PrimaryFunctionFilter
8706 100 Yes Reverse
8707
8708progspace /build/test frame-filters:
8709 Priority Enabled Name
8710 100 Yes ProgspaceFilter
8711
8712objfile /build/test frame-filters:
8713 Priority Enabled Name
8714 999 No BuildProgramFilter
8715
8716(gdb) set frame-filter priority global Reverse 50
8717(gdb) info frame-filter
8718
8719global frame-filters:
8720 Priority Enabled Name
8721 1000 Yes PrimaryFunctionFilter
8722 50 Yes Reverse
8723
8724progspace /build/test frame-filters:
8725 Priority Enabled Name
8726 100 Yes ProgspaceFilter
8727
8728objfile /build/test frame-filters:
8729 Priority Enabled Name
8730 999 No BuildProgramFilter
8731@end smallexample
8732@end table
c906108c 8733
6d2ebf8b 8734@node Source
c906108c
SS
8735@chapter Examining Source Files
8736
8737@value{GDBN} can print parts of your program's source, since the debugging
8738information recorded in the program tells @value{GDBN} what source files were
8739used to build it. When your program stops, @value{GDBN} spontaneously prints
8740the line where it stopped. Likewise, when you select a stack frame
79a6e687 8741(@pxref{Selection, ,Selecting a Frame}), @value{GDBN} prints the line where
c906108c
SS
8742execution in that frame has stopped. You can print other portions of
8743source files by explicit command.
8744
7a292a7a 8745If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
d4f3574e 8746prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
7a292a7a 8747@value{GDBN} under @sc{gnu} Emacs}.
c906108c
SS
8748
8749@menu
8750* List:: Printing source lines
2a25a5ba 8751* Specify Location:: How to specify code locations
87885426 8752* Edit:: Editing source files
c906108c 8753* Search:: Searching source files
c906108c
SS
8754* Source Path:: Specifying source directories
8755* Machine Code:: Source and machine code
8756@end menu
8757
6d2ebf8b 8758@node List
79a6e687 8759@section Printing Source Lines
c906108c
SS
8760
8761@kindex list
41afff9a 8762@kindex l @r{(@code{list})}
c906108c 8763To print lines from a source file, use the @code{list} command
5d161b24 8764(abbreviated @code{l}). By default, ten lines are printed.
2a25a5ba
EZ
8765There are several ways to specify what part of the file you want to
8766print; see @ref{Specify Location}, for the full list.
c906108c
SS
8767
8768Here are the forms of the @code{list} command most commonly used:
8769
8770@table @code
8771@item list @var{linenum}
8772Print lines centered around line number @var{linenum} in the
8773current source file.
8774
8775@item list @var{function}
8776Print lines centered around the beginning of function
8777@var{function}.
8778
8779@item list
8780Print more lines. If the last lines printed were printed with a
8781@code{list} command, this prints lines following the last lines
8782printed; however, if the last line printed was a solitary line printed
8783as part of displaying a stack frame (@pxref{Stack, ,Examining the
8784Stack}), this prints lines centered around that line.
8785
8786@item list -
8787Print lines just before the lines last printed.
8788@end table
8789
9c16f35a 8790@cindex @code{list}, how many lines to display
c906108c
SS
8791By default, @value{GDBN} prints ten source lines with any of these forms of
8792the @code{list} command. You can change this using @code{set listsize}:
8793
8794@table @code
8795@kindex set listsize
8796@item set listsize @var{count}
f81d1120 8797@itemx set listsize unlimited
c906108c
SS
8798Make the @code{list} command display @var{count} source lines (unless
8799the @code{list} argument explicitly specifies some other number).
f81d1120 8800Setting @var{count} to @code{unlimited} or 0 means there's no limit.
c906108c
SS
8801
8802@kindex show listsize
8803@item show listsize
8804Display the number of lines that @code{list} prints.
8805@end table
8806
8807Repeating a @code{list} command with @key{RET} discards the argument,
8808so it is equivalent to typing just @code{list}. This is more useful
8809than listing the same lines again. An exception is made for an
8810argument of @samp{-}; that argument is preserved in repetition so that
8811each repetition moves up in the source file.
8812
c906108c 8813In general, the @code{list} command expects you to supply zero, one or two
629500fa 8814@dfn{locations}. Locations specify source lines; there are several ways
2a25a5ba
EZ
8815of writing them (@pxref{Specify Location}), but the effect is always
8816to specify some source line.
8817
c906108c
SS
8818Here is a complete description of the possible arguments for @code{list}:
8819
8820@table @code
629500fa
KS
8821@item list @var{location}
8822Print lines centered around the line specified by @var{location}.
c906108c
SS
8823
8824@item list @var{first},@var{last}
8825Print lines from @var{first} to @var{last}. Both arguments are
629500fa
KS
8826locations. When a @code{list} command has two locations, and the
8827source file of the second location is omitted, this refers to
8828the same source file as the first location.
c906108c
SS
8829
8830@item list ,@var{last}
8831Print lines ending with @var{last}.
8832
8833@item list @var{first},
8834Print lines starting with @var{first}.
8835
8836@item list +
8837Print lines just after the lines last printed.
8838
8839@item list -
8840Print lines just before the lines last printed.
8841
8842@item list
8843As described in the preceding table.
8844@end table
8845
2a25a5ba
EZ
8846@node Specify Location
8847@section Specifying a Location
8848@cindex specifying location
629500fa
KS
8849@cindex location
8850@cindex source location
8851
8852@menu
8853* Linespec Locations:: Linespec locations
8854* Explicit Locations:: Explicit locations
8855* Address Locations:: Address locations
8856@end menu
c906108c 8857
2a25a5ba
EZ
8858Several @value{GDBN} commands accept arguments that specify a location
8859of your program's code. Since @value{GDBN} is a source-level
629500fa
KS
8860debugger, a location usually specifies some line in the source code.
8861Locations may be specified using three different formats:
8862linespec locations, explicit locations, or address locations.
c906108c 8863
629500fa
KS
8864@node Linespec Locations
8865@subsection Linespec Locations
8866@cindex linespec locations
8867
8868A @dfn{linespec} is a colon-separated list of source location parameters such
8869as file name, function name, etc. Here are all the different ways of
8870specifying a linespec:
c906108c 8871
2a25a5ba
EZ
8872@table @code
8873@item @var{linenum}
8874Specifies the line number @var{linenum} of the current source file.
c906108c 8875
2a25a5ba
EZ
8876@item -@var{offset}
8877@itemx +@var{offset}
8878Specifies the line @var{offset} lines before or after the @dfn{current
8879line}. For the @code{list} command, the current line is the last one
8880printed; for the breakpoint commands, this is the line at which
8881execution stopped in the currently selected @dfn{stack frame}
8882(@pxref{Frames, ,Frames}, for a description of stack frames.) When
8883used as the second of the two linespecs in a @code{list} command,
8884this specifies the line @var{offset} lines up or down from the first
8885linespec.
8886
8887@item @var{filename}:@var{linenum}
8888Specifies the line @var{linenum} in the source file @var{filename}.
4aac40c8
TT
8889If @var{filename} is a relative file name, then it will match any
8890source file name with the same trailing components. For example, if
8891@var{filename} is @samp{gcc/expr.c}, then it will match source file
8892name of @file{/build/trunk/gcc/expr.c}, but not
8893@file{/build/trunk/libcpp/expr.c} or @file{/build/trunk/gcc/x-expr.c}.
c906108c
SS
8894
8895@item @var{function}
8896Specifies the line that begins the body of the function @var{function}.
2a25a5ba 8897For example, in C, this is the line with the open brace.
c906108c 8898
a20714ff
PA
8899By default, in C@t{++} and Ada, @var{function} is interpreted as
8900specifying all functions named @var{function} in all scopes. For
8901C@t{++}, this means in all namespaces and classes. For Ada, this
8902means in all packages.
8903
8904For example, assuming a program with C@t{++} symbols named
8905@code{A::B::func} and @code{B::func}, both commands @w{@kbd{break
8906func}} and @w{@kbd{break B::func}} set a breakpoint on both symbols.
8907
8908Commands that accept a linespec let you override this with the
8909@code{-qualified} option. For example, @w{@kbd{break -qualified
8910func}} sets a breakpoint on a free-function named @code{func} ignoring
8911any C@t{++} class methods and namespace functions called @code{func}.
8912
8913@xref{Explicit Locations}.
8914
9ef07c8c
TT
8915@item @var{function}:@var{label}
8916Specifies the line where @var{label} appears in @var{function}.
8917
c906108c 8918@item @var{filename}:@var{function}
2a25a5ba
EZ
8919Specifies the line that begins the body of the function @var{function}
8920in the file @var{filename}. You only need the file name with a
8921function name to avoid ambiguity when there are identically named
8922functions in different source files.
c906108c 8923
0f5238ed 8924@item @var{label}
629500fa
KS
8925Specifies the line at which the label named @var{label} appears
8926in the function corresponding to the currently selected stack frame.
8927If there is no current selected stack frame (for instance, if the inferior
8928is not running), then @value{GDBN} will not search for a label.
8929
8930@cindex breakpoint at static probe point
8931@item -pstap|-probe-stap @r{[}@var{objfile}:@r{[}@var{provider}:@r{]}@r{]}@var{name}
8932The @sc{gnu}/Linux tool @code{SystemTap} provides a way for
8933applications to embed static probes. @xref{Static Probe Points}, for more
8934information on finding and using static probes. This form of linespec
8935specifies the location of such a static probe.
8936
8937If @var{objfile} is given, only probes coming from that shared library
8938or executable matching @var{objfile} as a regular expression are considered.
8939If @var{provider} is given, then only probes from that provider are considered.
8940If several probes match the spec, @value{GDBN} will insert a breakpoint at
8941each one of those probes.
8942@end table
8943
8944@node Explicit Locations
8945@subsection Explicit Locations
8946@cindex explicit locations
8947
8948@dfn{Explicit locations} allow the user to directly specify the source
8949location's parameters using option-value pairs.
8950
8951Explicit locations are useful when several functions, labels, or
8952file names have the same name (base name for files) in the program's
8953sources. In these cases, explicit locations point to the source
8954line you meant more accurately and unambiguously. Also, using
8955explicit locations might be faster in large programs.
8956
8957For example, the linespec @samp{foo:bar} may refer to a function @code{bar}
8958defined in the file named @file{foo} or the label @code{bar} in a function
8959named @code{foo}. @value{GDBN} must search either the file system or
8960the symbol table to know.
8961
8962The list of valid explicit location options is summarized in the
8963following table:
8964
8965@table @code
8966@item -source @var{filename}
8967The value specifies the source file name. To differentiate between
8968files with the same base name, prepend as many directories as is necessary
8969to uniquely identify the desired file, e.g., @file{foo/bar/baz.c}. Otherwise
8970@value{GDBN} will use the first file it finds with the given base
8971name. This option requires the use of either @code{-function} or @code{-line}.
8972
8973@item -function @var{function}
8974The value specifies the name of a function. Operations
8975on function locations unmodified by other options (such as @code{-label}
8976or @code{-line}) refer to the line that begins the body of the function.
8977In C, for example, this is the line with the open brace.
8978
a20714ff
PA
8979By default, in C@t{++} and Ada, @var{function} is interpreted as
8980specifying all functions named @var{function} in all scopes. For
8981C@t{++}, this means in all namespaces and classes. For Ada, this
8982means in all packages.
8983
8984For example, assuming a program with C@t{++} symbols named
8985@code{A::B::func} and @code{B::func}, both commands @w{@kbd{break
8986-function func}} and @w{@kbd{break -function B::func}} set a
8987breakpoint on both symbols.
8988
8989You can use the @kbd{-qualified} flag to override this (see below).
8990
8991@item -qualified
8992
8993This flag makes @value{GDBN} interpret a function name specified with
8994@kbd{-function} as a complete fully-qualified name.
8995
8996For example, assuming a C@t{++} program with symbols named
8997@code{A::B::func} and @code{B::func}, the @w{@kbd{break -qualified
8998-function B::func}} command sets a breakpoint on @code{B::func}, only.
8999
9000(Note: the @kbd{-qualified} option can precede a linespec as well
9001(@pxref{Linespec Locations}), so the particular example above could be
9002simplified as @w{@kbd{break -qualified B::func}}.)
9003
629500fa
KS
9004@item -label @var{label}
9005The value specifies the name of a label. When the function
9006name is not specified, the label is searched in the function of the currently
9007selected stack frame.
9008
9009@item -line @var{number}
9010The value specifies a line offset for the location. The offset may either
9011be absolute (@code{-line 3}) or relative (@code{-line +3}), depending on
9012the command. When specified without any other options, the line offset is
9013relative to the current line.
9014@end table
9015
9016Explicit location options may be abbreviated by omitting any non-unique
a20714ff 9017trailing characters from the option name, e.g., @w{@kbd{break -s main.c -li 3}}.
629500fa
KS
9018
9019@node Address Locations
9020@subsection Address Locations
9021@cindex address locations
9022
9023@dfn{Address locations} indicate a specific program address. They have
9024the generalized form *@var{address}.
9025
9026For line-oriented commands, such as @code{list} and @code{edit}, this
9027specifies a source line that contains @var{address}. For @code{break} and
9028other breakpoint-oriented commands, this can be used to set breakpoints in
2a25a5ba
EZ
9029parts of your program which do not have debugging information or
9030source files.
9031
9032Here @var{address} may be any expression valid in the current working
9033language (@pxref{Languages, working language}) that specifies a code
5fa54e5d 9034address. In addition, as a convenience, @value{GDBN} extends the
629500fa
KS
9035semantics of expressions used in locations to cover several situations
9036that frequently occur during debugging. Here are the various forms
5fa54e5d 9037of @var{address}:
2a25a5ba
EZ
9038
9039@table @code
9040@item @var{expression}
9041Any expression valid in the current working language.
9042
9043@item @var{funcaddr}
9044An address of a function or procedure derived from its name. In C,
9c37b5ae 9045C@t{++}, Objective-C, Fortran, minimal, and assembly, this is
2a25a5ba
EZ
9046simply the function's name @var{function} (and actually a special case
9047of a valid expression). In Pascal and Modula-2, this is
9048@code{&@var{function}}. In Ada, this is @code{@var{function}'Address}
9049(although the Pascal form also works).
9050
9051This form specifies the address of the function's first instruction,
9052before the stack frame and arguments have been set up.
9053
9a284c97 9054@item '@var{filename}':@var{funcaddr}
2a25a5ba
EZ
9055Like @var{funcaddr} above, but also specifies the name of the source
9056file explicitly. This is useful if the name of the function does not
9057specify the function unambiguously, e.g., if there are several
9058functions with identical names in different source files.
c906108c
SS
9059@end table
9060
87885426 9061@node Edit
79a6e687 9062@section Editing Source Files
87885426
FN
9063@cindex editing source files
9064
9065@kindex edit
9066@kindex e @r{(@code{edit})}
9067To edit the lines in a source file, use the @code{edit} command.
9068The editing program of your choice
9069is invoked with the current line set to
9070the active line in the program.
9071Alternatively, there are several ways to specify what part of the file you
2a25a5ba 9072want to print if you want to see other parts of the program:
87885426
FN
9073
9074@table @code
2a25a5ba
EZ
9075@item edit @var{location}
9076Edit the source file specified by @code{location}. Editing starts at
9077that @var{location}, e.g., at the specified source line of the
9078specified file. @xref{Specify Location}, for all the possible forms
9079of the @var{location} argument; here are the forms of the @code{edit}
9080command most commonly used:
87885426 9081
2a25a5ba 9082@table @code
87885426
FN
9083@item edit @var{number}
9084Edit the current source file with @var{number} as the active line number.
9085
9086@item edit @var{function}
9087Edit the file containing @var{function} at the beginning of its definition.
2a25a5ba 9088@end table
87885426 9089
87885426
FN
9090@end table
9091
79a6e687 9092@subsection Choosing your Editor
87885426
FN
9093You can customize @value{GDBN} to use any editor you want
9094@footnote{
9095The only restriction is that your editor (say @code{ex}), recognizes the
9096following command-line syntax:
10998722 9097@smallexample
87885426 9098ex +@var{number} file
10998722 9099@end smallexample
15387254
EZ
9100The optional numeric value +@var{number} specifies the number of the line in
9101the file where to start editing.}.
9102By default, it is @file{@value{EDITOR}}, but you can change this
10998722
AC
9103by setting the environment variable @code{EDITOR} before using
9104@value{GDBN}. For example, to configure @value{GDBN} to use the
9105@code{vi} editor, you could use these commands with the @code{sh} shell:
9106@smallexample
87885426
FN
9107EDITOR=/usr/bin/vi
9108export EDITOR
15387254 9109gdb @dots{}
10998722 9110@end smallexample
87885426 9111or in the @code{csh} shell,
10998722 9112@smallexample
87885426 9113setenv EDITOR /usr/bin/vi
15387254 9114gdb @dots{}
10998722 9115@end smallexample
87885426 9116
6d2ebf8b 9117@node Search
79a6e687 9118@section Searching Source Files
15387254 9119@cindex searching source files
c906108c
SS
9120
9121There are two commands for searching through the current source file for a
9122regular expression.
9123
9124@table @code
9125@kindex search
9126@kindex forward-search
1e96de83 9127@kindex fo @r{(@code{forward-search})}
c906108c
SS
9128@item forward-search @var{regexp}
9129@itemx search @var{regexp}
9130The command @samp{forward-search @var{regexp}} checks each line,
9131starting with the one following the last line listed, for a match for
5d161b24 9132@var{regexp}. It lists the line that is found. You can use the
c906108c
SS
9133synonym @samp{search @var{regexp}} or abbreviate the command name as
9134@code{fo}.
9135
09d4efe1 9136@kindex reverse-search
c906108c
SS
9137@item reverse-search @var{regexp}
9138The command @samp{reverse-search @var{regexp}} checks each line, starting
9139with the one before the last line listed and going backward, for a match
9140for @var{regexp}. It lists the line that is found. You can abbreviate
9141this command as @code{rev}.
9142@end table
c906108c 9143
6d2ebf8b 9144@node Source Path
79a6e687 9145@section Specifying Source Directories
c906108c
SS
9146
9147@cindex source path
9148@cindex directories for source files
9149Executable programs sometimes do not record the directories of the source
9150files from which they were compiled, just the names. Even when they do,
9151the directories could be moved between the compilation and your debugging
9152session. @value{GDBN} has a list of directories to search for source files;
9153this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
9154it tries all the directories in the list, in the order they are present
0b66e38c
EZ
9155in the list, until it finds a file with the desired name.
9156
9157For example, suppose an executable references the file
f1b620e9
MG
9158@file{/usr/src/foo-1.0/lib/foo.c}, does not record a compilation
9159directory, and the @dfn{source path} is @file{/mnt/cross}.
9160@value{GDBN} would look for the source file in the following
9161locations:
9162
9163@enumerate
9164
9165@item @file{/usr/src/foo-1.0/lib/foo.c}
9166@item @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c}
9167@item @file{/mnt/cross/foo.c}
9168
9169@end enumerate
9170
9171If the source file is not present at any of the above locations then
9172an error is printed. @value{GDBN} does not look up the parts of the
0b66e38c
EZ
9173source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
9174Likewise, the subdirectories of the source path are not searched: if
9175the source path is @file{/mnt/cross}, and the binary refers to
9176@file{foo.c}, @value{GDBN} would not find it under
9177@file{/mnt/cross/usr/src/foo-1.0/lib}.
9178
9179Plain file names, relative file names with leading directories, file
f1b620e9
MG
9180names containing dots, etc.@: are all treated as described above,
9181except that non-absolute file names are not looked up literally. If
9182the @dfn{source path} is @file{/mnt/cross}, the source file is
9183recorded as @file{../lib/foo.c}, and no compilation directory is
9184recorded, then @value{GDBN} will search in the following locations:
9185
9186@enumerate
9187
9188@item @file{/mnt/cross/../lib/foo.c}
9189@item @file{/mnt/cross/foo.c}
9190
9191@end enumerate
9192
9193@kindex cdir
9194@kindex cwd
9195@vindex $cdir@r{, convenience variable}
9196@vindex $cwd@r{, convenience variable}
9197@cindex compilation directory
9198@cindex current directory
9199@cindex working directory
9200@cindex directory, current
9201@cindex directory, compilation
9202The @dfn{source path} will always include two special entries
9203@samp{$cdir} and @samp{$cwd}, these refer to the compilation directory
9204(if one is recorded) and the current working directory respectively.
9205
9206@samp{$cdir} causes @value{GDBN} to search within the compilation
9207directory, if one is recorded in the debug information. If no
9208compilation directory is recorded in the debug information then
9209@samp{$cdir} is ignored.
9210
9211@samp{$cwd} is not the same as @samp{.}---the former tracks the
9212current working directory as it changes during your @value{GDBN}
9213session, while the latter is immediately expanded to the current
9214directory at the time you add an entry to the source path.
9215
9216If a compilation directory is recorded in the debug information, and
9217@value{GDBN} has not found the source file after the first search
9218using @dfn{source path}, then @value{GDBN} will combine the
9219compilation directory and the filename, and then search for the source
9220file again using the @dfn{source path}.
9221
9222For example, if the executable records the source file as
9223@file{/usr/src/foo-1.0/lib/foo.c}, the compilation directory is
9224recorded as @file{/project/build}, and the @dfn{source path} is
9225@file{/mnt/cross:$cdir:$cwd} while the current working directory of
9226the @value{GDBN} session is @file{/home/user}, then @value{GDBN} will
6b92c0d3 9227search for the source file in the following locations:
f1b620e9
MG
9228
9229@enumerate
9230
9231@item @file{/usr/src/foo-1.0/lib/foo.c}
9232@item @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c}
9233@item @file{/project/build/usr/src/foo-1.0/lib/foo.c}
9234@item @file{/home/user/usr/src/foo-1.0/lib/foo.c}
9235@item @file{/mnt/cross/project/build/usr/src/foo-1.0/lib/foo.c}
9236@item @file{/project/build/project/build/usr/src/foo-1.0/lib/foo.c}
9237@item @file{/home/user/project/build/usr/src/foo-1.0/lib/foo.c}
9238@item @file{/mnt/cross/foo.c}
9239@item @file{/project/build/foo.c}
9240@item @file{/home/user/foo.c}
9241
9242@end enumerate
9243
9244If the file name in the previous example had been recorded in the
9245executable as a relative path rather than an absolute path, then the
9246first look up would not have occurred, but all of the remaining steps
9247would be similar.
9248
9249When searching for source files on MS-DOS and MS-Windows, where
9250absolute paths start with a drive letter (e.g.
9251@file{C:/project/foo.c}), @value{GDBN} will remove the drive letter
9252from the file name before appending it to a search directory from
9253@dfn{source path}; for instance if the executable references the
9254source file @file{C:/project/foo.c} and @dfn{source path} is set to
9255@file{D:/mnt/cross}, then @value{GDBN} will search in the following
9256locations for the source file:
9257
9258@enumerate
9259
9260@item @file{C:/project/foo.c}
9261@item @file{D:/mnt/cross/project/foo.c}
9262@item @file{D:/mnt/cross/foo.c}
9263
9264@end enumerate
0b66e38c
EZ
9265
9266Note that the executable search path is @emph{not} used to locate the
cd852561 9267source files.
c906108c
SS
9268
9269Whenever you reset or rearrange the source path, @value{GDBN} clears out
9270any information it has cached about where source files are found and where
9271each line is in the file.
9272
9273@kindex directory
9274@kindex dir
f1b620e9
MG
9275When you start @value{GDBN}, its source path includes only @samp{$cdir}
9276and @samp{$cwd}, in that order.
c906108c
SS
9277To add other directories, use the @code{directory} command.
9278
4b505b12
AS
9279The search path is used to find both program source files and @value{GDBN}
9280script files (read using the @samp{-command} option and @samp{source} command).
9281
30daae6c
JB
9282In addition to the source path, @value{GDBN} provides a set of commands
9283that manage a list of source path substitution rules. A @dfn{substitution
9284rule} specifies how to rewrite source directories stored in the program's
9285debug information in case the sources were moved to a different
9286directory between compilation and debugging. A rule is made of
9287two strings, the first specifying what needs to be rewritten in
9288the path, and the second specifying how it should be rewritten.
9289In @ref{set substitute-path}, we name these two parts @var{from} and
9290@var{to} respectively. @value{GDBN} does a simple string replacement
9291of @var{from} with @var{to} at the start of the directory part of the
9292source file name, and uses that result instead of the original file
9293name to look up the sources.
9294
9295Using the previous example, suppose the @file{foo-1.0} tree has been
9296moved from @file{/usr/src} to @file{/mnt/cross}, then you can tell
3f94c067 9297@value{GDBN} to replace @file{/usr/src} in all source path names with
30daae6c
JB
9298@file{/mnt/cross}. The first lookup will then be
9299@file{/mnt/cross/foo-1.0/lib/foo.c} in place of the original location
9300of @file{/usr/src/foo-1.0/lib/foo.c}. To define a source path
9301substitution rule, use the @code{set substitute-path} command
9302(@pxref{set substitute-path}).
9303
9304To avoid unexpected substitution results, a rule is applied only if the
9305@var{from} part of the directory name ends at a directory separator.
9306For instance, a rule substituting @file{/usr/source} into
9307@file{/mnt/cross} will be applied to @file{/usr/source/foo-1.0} but
9308not to @file{/usr/sourceware/foo-2.0}. And because the substitution
d3e8051b 9309is applied only at the beginning of the directory name, this rule will
30daae6c
JB
9310not be applied to @file{/root/usr/source/baz.c} either.
9311
9312In many cases, you can achieve the same result using the @code{directory}
9313command. However, @code{set substitute-path} can be more efficient in
9314the case where the sources are organized in a complex tree with multiple
9315subdirectories. With the @code{directory} command, you need to add each
9316subdirectory of your project. If you moved the entire tree while
9317preserving its internal organization, then @code{set substitute-path}
9318allows you to direct the debugger to all the sources with one single
9319command.
9320
9321@code{set substitute-path} is also more than just a shortcut command.
9322The source path is only used if the file at the original location no
9323longer exists. On the other hand, @code{set substitute-path} modifies
9324the debugger behavior to look at the rewritten location instead. So, if
9325for any reason a source file that is not relevant to your executable is
9326located at the original location, a substitution rule is the only
3f94c067 9327method available to point @value{GDBN} at the new location.
30daae6c 9328
29b0e8a2
JM
9329@cindex @samp{--with-relocated-sources}
9330@cindex default source path substitution
9331You can configure a default source path substitution rule by
9332configuring @value{GDBN} with the
9333@samp{--with-relocated-sources=@var{dir}} option. The @var{dir}
9334should be the name of a directory under @value{GDBN}'s configured
9335prefix (set with @samp{--prefix} or @samp{--exec-prefix}), and
9336directory names in debug information under @var{dir} will be adjusted
9337automatically if the installed @value{GDBN} is moved to a new
9338location. This is useful if @value{GDBN}, libraries or executables
9339with debug information and corresponding source code are being moved
9340together.
9341
c906108c
SS
9342@table @code
9343@item directory @var{dirname} @dots{}
9344@item dir @var{dirname} @dots{}
9345Add directory @var{dirname} to the front of the source path. Several
d4f3574e
SS
9346directory names may be given to this command, separated by @samp{:}
9347(@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
9348part of absolute file names) or
c906108c
SS
9349whitespace. You may specify a directory that is already in the source
9350path; this moves it forward, so @value{GDBN} searches it sooner.
9351
f1b620e9
MG
9352The special strings @samp{$cdir} (to refer to the compilation
9353directory, if one is recorded), and @samp{$cwd} (to refer to the
9354current working directory) can also be included in the list of
9355directories @var{dirname}. Though these will already be in the source
9356path they will be moved forward in the list so @value{GDBN} searches
9357them sooner.
c906108c
SS
9358
9359@item directory
cd852561 9360Reset the source path to its default value (@samp{$cdir:$cwd} on Unix systems). This requires confirmation.
c906108c
SS
9361
9362@c RET-repeat for @code{directory} is explicitly disabled, but since
9363@c repeating it would be a no-op we do not say that. (thanks to RMS)
9364
99e7ae30
DE
9365@item set directories @var{path-list}
9366@kindex set directories
9367Set the source path to @var{path-list}.
9368@samp{$cdir:$cwd} are added if missing.
9369
c906108c
SS
9370@item show directories
9371@kindex show directories
9372Print the source path: show which directories it contains.
30daae6c
JB
9373
9374@anchor{set substitute-path}
9375@item set substitute-path @var{from} @var{to}
9376@kindex set substitute-path
9377Define a source path substitution rule, and add it at the end of the
9378current list of existing substitution rules. If a rule with the same
9379@var{from} was already defined, then the old rule is also deleted.
9380
9381For example, if the file @file{/foo/bar/baz.c} was moved to
9382@file{/mnt/cross/baz.c}, then the command
9383
9384@smallexample
c58b006b 9385(@value{GDBP}) set substitute-path /foo/bar /mnt/cross
30daae6c
JB
9386@end smallexample
9387
9388@noindent
c58b006b 9389will tell @value{GDBN} to replace @samp{/foo/bar} with
30daae6c
JB
9390@samp{/mnt/cross}, which will allow @value{GDBN} to find the file
9391@file{baz.c} even though it was moved.
9392
9393In the case when more than one substitution rule have been defined,
9394the rules are evaluated one by one in the order where they have been
9395defined. The first one matching, if any, is selected to perform
9396the substitution.
9397
9398For instance, if we had entered the following commands:
9399
9400@smallexample
9401(@value{GDBP}) set substitute-path /usr/src/include /mnt/include
9402(@value{GDBP}) set substitute-path /usr/src /mnt/src
9403@end smallexample
9404
9405@noindent
9406@value{GDBN} would then rewrite @file{/usr/src/include/defs.h} into
9407@file{/mnt/include/defs.h} by using the first rule. However, it would
9408use the second rule to rewrite @file{/usr/src/lib/foo.c} into
9409@file{/mnt/src/lib/foo.c}.
9410
9411
9412@item unset substitute-path [path]
9413@kindex unset substitute-path
9414If a path is specified, search the current list of substitution rules
9415for a rule that would rewrite that path. Delete that rule if found.
9416A warning is emitted by the debugger if no rule could be found.
9417
9418If no path is specified, then all substitution rules are deleted.
9419
9420@item show substitute-path [path]
9421@kindex show substitute-path
9422If a path is specified, then print the source path substitution rule
9423which would rewrite that path, if any.
9424
9425If no path is specified, then print all existing source path substitution
9426rules.
9427
c906108c
SS
9428@end table
9429
9430If your source path is cluttered with directories that are no longer of
9431interest, @value{GDBN} may sometimes cause confusion by finding the wrong
9432versions of source. You can correct the situation as follows:
9433
9434@enumerate
9435@item
cd852561 9436Use @code{directory} with no argument to reset the source path to its default value.
c906108c
SS
9437
9438@item
9439Use @code{directory} with suitable arguments to reinstall the
9440directories you want in the source path. You can add all the
9441directories in one command.
9442@end enumerate
9443
6d2ebf8b 9444@node Machine Code
79a6e687 9445@section Source and Machine Code
15387254 9446@cindex source line and its code address
c906108c
SS
9447
9448You can use the command @code{info line} to map source lines to program
9449addresses (and vice versa), and the command @code{disassemble} to display
91440f57
HZ
9450a range of addresses as machine instructions. You can use the command
9451@code{set disassemble-next-line} to set whether to disassemble next
9452source line when execution stops. When run under @sc{gnu} Emacs
d4f3574e 9453mode, the @code{info line} command causes the arrow to point to the
5d161b24 9454line specified. Also, @code{info line} prints addresses in symbolic form as
c906108c
SS
9455well as hex.
9456
9457@table @code
9458@kindex info line
db1ae9c5
AB
9459@item info line
9460@itemx info line @var{location}
c906108c 9461Print the starting and ending addresses of the compiled code for
629500fa 9462source line @var{location}. You can specify source lines in any of
db1ae9c5
AB
9463the ways documented in @ref{Specify Location}. With no @var{location}
9464information about the current source line is printed.
c906108c
SS
9465@end table
9466
9467For example, we can use @code{info line} to discover the location of
9468the object code for the first line of function
9469@code{m4_changequote}:
9470
9471@smallexample
96a2c332 9472(@value{GDBP}) info line m4_changequote
db1ae9c5
AB
9473Line 895 of "builtin.c" starts at pc 0x634c <m4_changequote> and \
9474 ends at 0x6350 <m4_changequote+4>.
c906108c
SS
9475@end smallexample
9476
9477@noindent
15387254 9478@cindex code address and its source line
c906108c 9479We can also inquire (using @code{*@var{addr}} as the form for
629500fa 9480@var{location}) what source line covers a particular address:
c906108c
SS
9481@smallexample
9482(@value{GDBP}) info line *0x63ff
db1ae9c5
AB
9483Line 926 of "builtin.c" starts at pc 0x63e4 <m4_changequote+152> and \
9484 ends at 0x6404 <m4_changequote+184>.
c906108c
SS
9485@end smallexample
9486
9487@cindex @code{$_} and @code{info line}
15387254 9488@cindex @code{x} command, default address
41afff9a 9489@kindex x@r{(examine), and} info line
c906108c
SS
9490After @code{info line}, the default address for the @code{x} command
9491is changed to the starting address of the line, so that @samp{x/i} is
9492sufficient to begin examining the machine code (@pxref{Memory,
79a6e687 9493,Examining Memory}). Also, this address is saved as the value of the
c906108c 9494convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
79a6e687 9495Variables}).
c906108c 9496
db1ae9c5
AB
9497@cindex info line, repeated calls
9498After @code{info line}, using @code{info line} again without
9499specifying a location will display information about the next source
9500line.
9501
c906108c
SS
9502@table @code
9503@kindex disassemble
9504@cindex assembly instructions
9505@cindex instructions, assembly
9506@cindex machine instructions
9507@cindex listing machine instructions
9508@item disassemble
d14508fe 9509@itemx disassemble /m
6ff0ba5f 9510@itemx disassemble /s
9b117ef3 9511@itemx disassemble /r
c906108c 9512This specialized command dumps a range of memory as machine
d14508fe 9513instructions. It can also print mixed source+disassembly by specifying
6ff0ba5f
DE
9514the @code{/m} or @code{/s} modifier and print the raw instructions in hex
9515as well as in symbolic form by specifying the @code{/r} modifier.
d14508fe 9516The default memory range is the function surrounding the
c906108c
SS
9517program counter of the selected frame. A single argument to this
9518command is a program counter value; @value{GDBN} dumps the function
21a0512e
PP
9519surrounding this value. When two arguments are given, they should
9520be separated by a comma, possibly surrounded by whitespace. The
53a71c06
CR
9521arguments specify a range of addresses to dump, in one of two forms:
9522
9523@table @code
9524@item @var{start},@var{end}
9525the addresses from @var{start} (inclusive) to @var{end} (exclusive)
9526@item @var{start},+@var{length}
9527the addresses from @var{start} (inclusive) to
9528@code{@var{start}+@var{length}} (exclusive).
9529@end table
9530
9531@noindent
9532When 2 arguments are specified, the name of the function is also
9533printed (since there could be several functions in the given range).
21a0512e
PP
9534
9535The argument(s) can be any expression yielding a numeric value, such as
9536@samp{0x32c4}, @samp{&main+10} or @samp{$pc - 8}.
2b28d209
PP
9537
9538If the range of memory being disassembled contains current program counter,
9539the instruction at that location is shown with a @code{=>} marker.
c906108c
SS
9540@end table
9541
c906108c
SS
9542The following example shows the disassembly of a range of addresses of
9543HP PA-RISC 2.0 code:
9544
9545@smallexample
21a0512e 9546(@value{GDBP}) disas 0x32c4, 0x32e4
c906108c 9547Dump of assembler code from 0x32c4 to 0x32e4:
2b28d209
PP
9548 0x32c4 <main+204>: addil 0,dp
9549 0x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
9550 0x32cc <main+212>: ldil 0x3000,r31
9551 0x32d0 <main+216>: ble 0x3f8(sr4,r31)
9552 0x32d4 <main+220>: ldo 0(r31),rp
9553 0x32d8 <main+224>: addil -0x800,dp
9554 0x32dc <main+228>: ldo 0x588(r1),r26
9555 0x32e0 <main+232>: ldil 0x3000,r31
c906108c
SS
9556End of assembler dump.
9557@end smallexample
c906108c 9558
6ff0ba5f
DE
9559Here is an example showing mixed source+assembly for Intel x86
9560with @code{/m} or @code{/s}, when the program is stopped just after
9561function prologue in a non-optimized function with no inline code.
d14508fe
DE
9562
9563@smallexample
9564(@value{GDBP}) disas /m main
9565Dump of assembler code for function main:
95665 @{
9c419145
PP
9567 0x08048330 <+0>: push %ebp
9568 0x08048331 <+1>: mov %esp,%ebp
9569 0x08048333 <+3>: sub $0x8,%esp
9570 0x08048336 <+6>: and $0xfffffff0,%esp
9571 0x08048339 <+9>: sub $0x10,%esp
d14508fe
DE
9572
95736 printf ("Hello.\n");
9c419145
PP
9574=> 0x0804833c <+12>: movl $0x8048440,(%esp)
9575 0x08048343 <+19>: call 0x8048284 <puts@@plt>
d14508fe
DE
9576
95777 return 0;
95788 @}
9c419145
PP
9579 0x08048348 <+24>: mov $0x0,%eax
9580 0x0804834d <+29>: leave
9581 0x0804834e <+30>: ret
d14508fe
DE
9582
9583End of assembler dump.
9584@end smallexample
9585
6ff0ba5f
DE
9586The @code{/m} option is deprecated as its output is not useful when
9587there is either inlined code or re-ordered code.
9588The @code{/s} option is the preferred choice.
9589Here is an example for AMD x86-64 showing the difference between
9590@code{/m} output and @code{/s} output.
9591This example has one inline function defined in a header file,
9592and the code is compiled with @samp{-O2} optimization.
9593Note how the @code{/m} output is missing the disassembly of
9594several instructions that are present in the @code{/s} output.
9595
9596@file{foo.h}:
9597
9598@smallexample
9599int
9600foo (int a)
9601@{
9602 if (a < 0)
9603 return a * 2;
9604 if (a == 0)
9605 return 1;
9606 return a + 10;
9607@}
9608@end smallexample
9609
9610@file{foo.c}:
9611
9612@smallexample
9613#include "foo.h"
9614volatile int x, y;
9615int
9616main ()
9617@{
9618 x = foo (y);
9619 return 0;
9620@}
9621@end smallexample
9622
9623@smallexample
9624(@value{GDBP}) disas /m main
9625Dump of assembler code for function main:
96265 @{
9627
96286 x = foo (y);
9629 0x0000000000400400 <+0>: mov 0x200c2e(%rip),%eax # 0x601034 <y>
9630 0x0000000000400417 <+23>: mov %eax,0x200c13(%rip) # 0x601030 <x>
9631
96327 return 0;
96338 @}
9634 0x000000000040041d <+29>: xor %eax,%eax
9635 0x000000000040041f <+31>: retq
9636 0x0000000000400420 <+32>: add %eax,%eax
9637 0x0000000000400422 <+34>: jmp 0x400417 <main+23>
9638
9639End of assembler dump.
9640(@value{GDBP}) disas /s main
9641Dump of assembler code for function main:
9642foo.c:
96435 @{
96446 x = foo (y);
9645 0x0000000000400400 <+0>: mov 0x200c2e(%rip),%eax # 0x601034 <y>
9646
9647foo.h:
96484 if (a < 0)
9649 0x0000000000400406 <+6>: test %eax,%eax
9650 0x0000000000400408 <+8>: js 0x400420 <main+32>
9651
96526 if (a == 0)
96537 return 1;
96548 return a + 10;
9655 0x000000000040040a <+10>: lea 0xa(%rax),%edx
9656 0x000000000040040d <+13>: test %eax,%eax
9657 0x000000000040040f <+15>: mov $0x1,%eax
9658 0x0000000000400414 <+20>: cmovne %edx,%eax
9659
9660foo.c:
96616 x = foo (y);
9662 0x0000000000400417 <+23>: mov %eax,0x200c13(%rip) # 0x601030 <x>
9663
96647 return 0;
96658 @}
9666 0x000000000040041d <+29>: xor %eax,%eax
9667 0x000000000040041f <+31>: retq
9668
9669foo.h:
96705 return a * 2;
9671 0x0000000000400420 <+32>: add %eax,%eax
9672 0x0000000000400422 <+34>: jmp 0x400417 <main+23>
9673End of assembler dump.
9674@end smallexample
9675
53a71c06
CR
9676Here is another example showing raw instructions in hex for AMD x86-64,
9677
9678@smallexample
9679(gdb) disas /r 0x400281,+10
9680Dump of assembler code from 0x400281 to 0x40028b:
9681 0x0000000000400281: 38 36 cmp %dh,(%rsi)
9682 0x0000000000400283: 2d 36 34 2e 73 sub $0x732e3436,%eax
9683 0x0000000000400288: 6f outsl %ds:(%rsi),(%dx)
9684 0x0000000000400289: 2e 32 00 xor %cs:(%rax),%al
9685End of assembler dump.
9686@end smallexample
9687
629500fa 9688Addresses cannot be specified as a location (@pxref{Specify Location}).
7e1e0340
DE
9689So, for example, if you want to disassemble function @code{bar}
9690in file @file{foo.c}, you must type @samp{disassemble 'foo.c'::bar}
9691and not @samp{disassemble foo.c:bar}.
9692
c906108c
SS
9693Some architectures have more than one commonly-used set of instruction
9694mnemonics or other syntax.
9695
76d17f34
EZ
9696For programs that were dynamically linked and use shared libraries,
9697instructions that call functions or branch to locations in the shared
9698libraries might show a seemingly bogus location---it's actually a
9699location of the relocation table. On some architectures, @value{GDBN}
9700might be able to resolve these to actual function names.
9701
65b48a81
PB
9702@table @code
9703@kindex set disassembler-options
9704@cindex disassembler options
9705@item set disassembler-options @var{option1}[,@var{option2}@dots{}]
9706This command controls the passing of target specific information to
9707the disassembler. For a list of valid options, please refer to the
9708@code{-M}/@code{--disassembler-options} section of the @samp{objdump}
9709manual and/or the output of @kbd{objdump --help}
f5a476a7 9710(@pxref{objdump,,objdump,binutils,The GNU Binary Utilities}).
65b48a81
PB
9711The default value is the empty string.
9712
9713If it is necessary to specify more than one disassembler option, then
9714multiple options can be placed together into a comma separated list.
471b9d15 9715Currently this command is only supported on targets ARM, MIPS, PowerPC
65b48a81
PB
9716and S/390.
9717
9718@kindex show disassembler-options
9719@item show disassembler-options
9720Show the current setting of the disassembler options.
9721@end table
9722
c906108c 9723@table @code
d4f3574e 9724@kindex set disassembly-flavor
d4f3574e
SS
9725@cindex Intel disassembly flavor
9726@cindex AT&T disassembly flavor
9727@item set disassembly-flavor @var{instruction-set}
c906108c
SS
9728Select the instruction set to use when disassembling the
9729program via the @code{disassemble} or @code{x/i} commands.
9730
9731Currently this command is only defined for the Intel x86 family. You
d4f3574e
SS
9732can set @var{instruction-set} to either @code{intel} or @code{att}.
9733The default is @code{att}, the AT&T flavor used by default by Unix
9734assemblers for x86-based targets.
9c16f35a
EZ
9735
9736@kindex show disassembly-flavor
9737@item show disassembly-flavor
9738Show the current setting of the disassembly flavor.
c906108c
SS
9739@end table
9740
91440f57
HZ
9741@table @code
9742@kindex set disassemble-next-line
9743@kindex show disassemble-next-line
9744@item set disassemble-next-line
9745@itemx show disassemble-next-line
32ae1842
EZ
9746Control whether or not @value{GDBN} will disassemble the next source
9747line or instruction when execution stops. If ON, @value{GDBN} will
9748display disassembly of the next source line when execution of the
9749program being debugged stops. This is @emph{in addition} to
9750displaying the source line itself, which @value{GDBN} always does if
9751possible. If the next source line cannot be displayed for some reason
9752(e.g., if @value{GDBN} cannot find the source file, or there's no line
9753info in the debug info), @value{GDBN} will display disassembly of the
9754next @emph{instruction} instead of showing the next source line. If
9755AUTO, @value{GDBN} will display disassembly of next instruction only
9756if the source line cannot be displayed. This setting causes
9757@value{GDBN} to display some feedback when you step through a function
9758with no line info or whose source file is unavailable. The default is
9759OFF, which means never display the disassembly of the next line or
9760instruction.
91440f57
HZ
9761@end table
9762
c906108c 9763
6d2ebf8b 9764@node Data
c906108c
SS
9765@chapter Examining Data
9766
9767@cindex printing data
9768@cindex examining data
9769@kindex print
9770@kindex inspect
c906108c 9771The usual way to examine data in your program is with the @code{print}
7a292a7a
SS
9772command (abbreviated @code{p}), or its synonym @code{inspect}. It
9773evaluates and prints the value of an expression of the language your
9774program is written in (@pxref{Languages, ,Using @value{GDBN} with
78e2826b
TT
9775Different Languages}). It may also print the expression using a
9776Python-based pretty-printer (@pxref{Pretty Printing}).
c906108c
SS
9777
9778@table @code
3345721a
PA
9779@item print [[@var{options}] --] @var{expr}
9780@itemx print [[@var{options}] --] /@var{f} @var{expr}
d4f3574e
SS
9781@var{expr} is an expression (in the source language). By default the
9782value of @var{expr} is printed in a format appropriate to its data type;
c906108c 9783you can choose a different format by specifying @samp{/@var{f}}, where
d4f3574e 9784@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
79a6e687 9785Formats}.
c906108c 9786
3345721a
PA
9787@anchor{print options}
9788The @code{print} command supports a number of options that allow
9789overriding relevant global print settings as set by @code{set print}
9790subcommands:
9791
9792@table @code
9793@item -address [@code{on}|@code{off}]
9794Set printing of addresses.
9795Related setting: @ref{set print address}.
9796
9797@item -array [@code{on}|@code{off}]
9798Pretty formatting of arrays.
9799Related setting: @ref{set print array}.
9800
9801@item -array-indexes [@code{on}|@code{off}]
9802Set printing of array indexes.
9803Related setting: @ref{set print array-indexes}.
9804
9805@item -elements @var{number-of-elements}|@code{unlimited}
9806Set limit on string chars or array elements to print. The value
9807@code{unlimited} causes there to be no limit. Related setting:
9808@ref{set print elements}.
9809
9810@item -max-depth @var{depth}|@code{unlimited}
9811Set the threshold after which nested structures are replaced with
9812ellipsis. Related setting: @ref{set print max-depth}.
9813
9814@item -null-stop [@code{on}|@code{off}]
9815Set printing of char arrays to stop at first null char. Related
9816setting: @ref{set print null-stop}.
9817
9818@item -object [@code{on}|@code{off}]
9819Set printing C@t{++} virtual function tables. Related setting:
9820@ref{set print object}.
9821
9822@item -pretty [@code{on}|@code{off}]
9823Set pretty formatting of structures. Related setting: @ref{set print
9824pretty}.
9825
d8edc8b7
PW
9826@item -raw-values [@code{on}|@code{off}]
9827Set whether to print values in raw form, bypassing any
9828pretty-printers for that value. Related setting: @ref{set print
9829raw-values}.
9830
3345721a
PA
9831@item -repeats @var{number-of-repeats}|@code{unlimited}
9832Set threshold for repeated print elements. @code{unlimited} causes
9833all elements to be individually printed. Related setting: @ref{set
9834print repeats}.
9835
9836@item -static-members [@code{on}|@code{off}]
9837Set printing C@t{++} static members. Related setting: @ref{set print
9838static-members}.
9839
9840@item -symbol [@code{on}|@code{off}]
9841Set printing of symbol names when printing pointers. Related setting:
9842@ref{set print symbol}.
9843
9844@item -union [@code{on}|@code{off}]
9845Set printing of unions interior to structures. Related setting:
9846@ref{set print union}.
9847
9848@item -vtbl [@code{on}|@code{off}]
9849Set printing of C++ virtual function tables. Related setting:
9850@ref{set print vtbl}.
9851@end table
9852
9853Because the @code{print} command accepts arbitrary expressions which
9854may look like options (including abbreviations), if you specify any
9855command option, then you must use a double dash (@code{--}) to mark
9856the end of option processing.
9857
d8edc8b7 9858For example, this prints the value of the @code{-p} expression:
3345721a
PA
9859
9860@smallexample
d8edc8b7 9861(@value{GDBP}) print -p
3345721a
PA
9862@end smallexample
9863
9864While this repeats the last value in the value history (see below)
d8edc8b7 9865with the @code{-pretty} option in effect:
3345721a
PA
9866
9867@smallexample
d8edc8b7 9868(@value{GDBP}) print -p --
3345721a
PA
9869@end smallexample
9870
9871Here is an example including both on option and an expression:
9872
9873@smallexample
9874@group
9875(@value{GDBP}) print -pretty -- *myptr
9876$1 = @{
9877 next = 0x0,
9878 flags = @{
9879 sweet = 1,
9880 sour = 1
9881 @},
9882 meat = 0x54 "Pork"
9883@}
9884@end group
9885@end smallexample
9886
9887@item print [@var{options}]
9888@itemx print [@var{options}] /@var{f}
15387254 9889@cindex reprint the last value
d4f3574e 9890If you omit @var{expr}, @value{GDBN} displays the last value again (from the
79a6e687 9891@dfn{value history}; @pxref{Value History, ,Value History}). This allows you to
c906108c
SS
9892conveniently inspect the same value in an alternative format.
9893@end table
9894
9895A more low-level way of examining data is with the @code{x} command.
9896It examines data in memory at a specified address and prints it in a
79a6e687 9897specified format. @xref{Memory, ,Examining Memory}.
c906108c 9898
7a292a7a 9899If you are interested in information about types, or about how the
d4f3574e
SS
9900fields of a struct or a class are declared, use the @code{ptype @var{exp}}
9901command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
7a292a7a 9902Table}.
c906108c 9903
06fc020f
SCR
9904@cindex exploring hierarchical data structures
9905@kindex explore
9906Another way of examining values of expressions and type information is
9907through the Python extension command @code{explore} (available only if
9908the @value{GDBN} build is configured with @code{--with-python}). It
9909offers an interactive way to start at the highest level (or, the most
9910abstract level) of the data type of an expression (or, the data type
9911itself) and explore all the way down to leaf scalar values/fields
9912embedded in the higher level data types.
9913
9914@table @code
9915@item explore @var{arg}
9916@var{arg} is either an expression (in the source language), or a type
9917visible in the current context of the program being debugged.
9918@end table
9919
9920The working of the @code{explore} command can be illustrated with an
9921example. If a data type @code{struct ComplexStruct} is defined in your
9922C program as
9923
9924@smallexample
9925struct SimpleStruct
9926@{
9927 int i;
9928 double d;
9929@};
9930
9931struct ComplexStruct
9932@{
9933 struct SimpleStruct *ss_p;
9934 int arr[10];
9935@};
9936@end smallexample
9937
9938@noindent
9939followed by variable declarations as
9940
9941@smallexample
9942struct SimpleStruct ss = @{ 10, 1.11 @};
9943struct ComplexStruct cs = @{ &ss, @{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 @} @};
9944@end smallexample
9945
9946@noindent
9947then, the value of the variable @code{cs} can be explored using the
9948@code{explore} command as follows.
9949
9950@smallexample
9951(gdb) explore cs
9952The value of `cs' is a struct/class of type `struct ComplexStruct' with
9953the following fields:
9954
9955 ss_p = <Enter 0 to explore this field of type `struct SimpleStruct *'>
9956 arr = <Enter 1 to explore this field of type `int [10]'>
9957
9958Enter the field number of choice:
9959@end smallexample
9960
9961@noindent
9962Since the fields of @code{cs} are not scalar values, you are being
9963prompted to chose the field you want to explore. Let's say you choose
9964the field @code{ss_p} by entering @code{0}. Then, since this field is a
9965pointer, you will be asked if it is pointing to a single value. From
9966the declaration of @code{cs} above, it is indeed pointing to a single
9967value, hence you enter @code{y}. If you enter @code{n}, then you will
9968be asked if it were pointing to an array of values, in which case this
9969field will be explored as if it were an array.
9970
9971@smallexample
9972`cs.ss_p' is a pointer to a value of type `struct SimpleStruct'
9973Continue exploring it as a pointer to a single value [y/n]: y
9974The value of `*(cs.ss_p)' is a struct/class of type `struct
9975SimpleStruct' with the following fields:
9976
9977 i = 10 .. (Value of type `int')
9978 d = 1.1100000000000001 .. (Value of type `double')
9979
9980Press enter to return to parent value:
9981@end smallexample
9982
9983@noindent
9984If the field @code{arr} of @code{cs} was chosen for exploration by
9985entering @code{1} earlier, then since it is as array, you will be
9986prompted to enter the index of the element in the array that you want
9987to explore.
9988
9989@smallexample
9990`cs.arr' is an array of `int'.
9991Enter the index of the element you want to explore in `cs.arr': 5
9992
9993`(cs.arr)[5]' is a scalar value of type `int'.
9994
9995(cs.arr)[5] = 4
9996
9997Press enter to return to parent value:
9998@end smallexample
9999
10000In general, at any stage of exploration, you can go deeper towards the
10001leaf values by responding to the prompts appropriately, or hit the
10002return key to return to the enclosing data structure (the @i{higher}
10003level data structure).
10004
10005Similar to exploring values, you can use the @code{explore} command to
10006explore types. Instead of specifying a value (which is typically a
10007variable name or an expression valid in the current context of the
10008program being debugged), you specify a type name. If you consider the
10009same example as above, your can explore the type
10010@code{struct ComplexStruct} by passing the argument
10011@code{struct ComplexStruct} to the @code{explore} command.
10012
10013@smallexample
10014(gdb) explore struct ComplexStruct
10015@end smallexample
10016
10017@noindent
10018By responding to the prompts appropriately in the subsequent interactive
10019session, you can explore the type @code{struct ComplexStruct} in a
10020manner similar to how the value @code{cs} was explored in the above
10021example.
10022
10023The @code{explore} command also has two sub-commands,
10024@code{explore value} and @code{explore type}. The former sub-command is
10025a way to explicitly specify that value exploration of the argument is
10026being invoked, while the latter is a way to explicitly specify that type
10027exploration of the argument is being invoked.
10028
10029@table @code
10030@item explore value @var{expr}
10031@cindex explore value
10032This sub-command of @code{explore} explores the value of the
10033expression @var{expr} (if @var{expr} is an expression valid in the
10034current context of the program being debugged). The behavior of this
10035command is identical to that of the behavior of the @code{explore}
10036command being passed the argument @var{expr}.
10037
10038@item explore type @var{arg}
10039@cindex explore type
10040This sub-command of @code{explore} explores the type of @var{arg} (if
10041@var{arg} is a type visible in the current context of program being
10042debugged), or the type of the value/expression @var{arg} (if @var{arg}
10043is an expression valid in the current context of the program being
10044debugged). If @var{arg} is a type, then the behavior of this command is
10045identical to that of the @code{explore} command being passed the
10046argument @var{arg}. If @var{arg} is an expression, then the behavior of
10047this command will be identical to that of the @code{explore} command
10048being passed the type of @var{arg} as the argument.
10049@end table
10050
c906108c
SS
10051@menu
10052* Expressions:: Expressions
6ba66d6a 10053* Ambiguous Expressions:: Ambiguous Expressions
c906108c
SS
10054* Variables:: Program variables
10055* Arrays:: Artificial arrays
10056* Output Formats:: Output formats
10057* Memory:: Examining memory
10058* Auto Display:: Automatic display
10059* Print Settings:: Print settings
4c374409 10060* Pretty Printing:: Python pretty printing
c906108c
SS
10061* Value History:: Value history
10062* Convenience Vars:: Convenience variables
a72c3253 10063* Convenience Funs:: Convenience functions
c906108c 10064* Registers:: Registers
c906108c 10065* Floating Point Hardware:: Floating point hardware
53c69bd7 10066* Vector Unit:: Vector Unit
721c2651 10067* OS Information:: Auxiliary data provided by operating system
29e57380 10068* Memory Region Attributes:: Memory region attributes
16d9dec6 10069* Dump/Restore Files:: Copy between memory and a file
384ee23f 10070* Core File Generation:: Cause a program dump its core
a0eb71c5
KB
10071* Character Sets:: Debugging programs that use a different
10072 character set than GDB does
b12039c6 10073* Caching Target Data:: Data caching for targets
08388c79 10074* Searching Memory:: Searching memory for a sequence of bytes
5fdf6324 10075* Value Sizes:: Managing memory allocated for values
c906108c
SS
10076@end menu
10077
6d2ebf8b 10078@node Expressions
c906108c
SS
10079@section Expressions
10080
10081@cindex expressions
10082@code{print} and many other @value{GDBN} commands accept an expression and
10083compute its value. Any kind of constant, variable or operator defined
10084by the programming language you are using is valid in an expression in
e2e0bcd1
JB
10085@value{GDBN}. This includes conditional expressions, function calls,
10086casts, and string constants. It also includes preprocessor macros, if
10087you compiled your program to include this information; see
10088@ref{Compilation}.
c906108c 10089
15387254 10090@cindex arrays in expressions
d4f3574e
SS
10091@value{GDBN} supports array constants in expressions input by
10092the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
63092375
DJ
10093you can use the command @code{print @{1, 2, 3@}} to create an array
10094of three integers. If you pass an array to a function or assign it
10095to a program variable, @value{GDBN} copies the array to memory that
10096is @code{malloc}ed in the target program.
c906108c 10097
c906108c
SS
10098Because C is so widespread, most of the expressions shown in examples in
10099this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
10100Languages}, for information on how to use expressions in other
10101languages.
10102
10103In this section, we discuss operators that you can use in @value{GDBN}
10104expressions regardless of your programming language.
10105
15387254 10106@cindex casts, in expressions
c906108c
SS
10107Casts are supported in all languages, not just in C, because it is so
10108useful to cast a number into a pointer in order to examine a structure
10109at that address in memory.
10110@c FIXME: casts supported---Mod2 true?
c906108c
SS
10111
10112@value{GDBN} supports these operators, in addition to those common
10113to programming languages:
10114
10115@table @code
10116@item @@
10117@samp{@@} is a binary operator for treating parts of memory as arrays.
79a6e687 10118@xref{Arrays, ,Artificial Arrays}, for more information.
c906108c
SS
10119
10120@item ::
10121@samp{::} allows you to specify a variable in terms of the file or
79a6e687 10122function where it is defined. @xref{Variables, ,Program Variables}.
c906108c
SS
10123
10124@cindex @{@var{type}@}
10125@cindex type casting memory
10126@cindex memory, viewing as typed object
10127@cindex casts, to view memory
10128@item @{@var{type}@} @var{addr}
10129Refers to an object of type @var{type} stored at address @var{addr} in
697aa1b7
EZ
10130memory. The address @var{addr} may be any expression whose value is
10131an integer or pointer (but parentheses are required around binary
10132operators, just as in a cast). This construct is allowed regardless
10133of what kind of data is normally supposed to reside at @var{addr}.
c906108c
SS
10134@end table
10135
6ba66d6a
JB
10136@node Ambiguous Expressions
10137@section Ambiguous Expressions
10138@cindex ambiguous expressions
10139
10140Expressions can sometimes contain some ambiguous elements. For instance,
10141some programming languages (notably Ada, C@t{++} and Objective-C) permit
10142a single function name to be defined several times, for application in
10143different contexts. This is called @dfn{overloading}. Another example
10144involving Ada is generics. A @dfn{generic package} is similar to C@t{++}
10145templates and is typically instantiated several times, resulting in
10146the same function name being defined in different contexts.
10147
10148In some cases and depending on the language, it is possible to adjust
10149the expression to remove the ambiguity. For instance in C@t{++}, you
10150can specify the signature of the function you want to break on, as in
10151@kbd{break @var{function}(@var{types})}. In Ada, using the fully
10152qualified name of your function often makes the expression unambiguous
10153as well.
10154
10155When an ambiguity that needs to be resolved is detected, the debugger
10156has the capability to display a menu of numbered choices for each
10157possibility, and then waits for the selection with the prompt @samp{>}.
10158The first option is always @samp{[0] cancel}, and typing @kbd{0 @key{RET}}
10159aborts the current command. If the command in which the expression was
10160used allows more than one choice to be selected, the next option in the
10161menu is @samp{[1] all}, and typing @kbd{1 @key{RET}} selects all possible
10162choices.
10163
10164For example, the following session excerpt shows an attempt to set a
10165breakpoint at the overloaded symbol @code{String::after}.
10166We choose three particular definitions of that function name:
10167
10168@c FIXME! This is likely to change to show arg type lists, at least
10169@smallexample
10170@group
10171(@value{GDBP}) b String::after
10172[0] cancel
10173[1] all
10174[2] file:String.cc; line number:867
10175[3] file:String.cc; line number:860
10176[4] file:String.cc; line number:875
10177[5] file:String.cc; line number:853
10178[6] file:String.cc; line number:846
10179[7] file:String.cc; line number:735
10180> 2 4 6
10181Breakpoint 1 at 0xb26c: file String.cc, line 867.
10182Breakpoint 2 at 0xb344: file String.cc, line 875.
10183Breakpoint 3 at 0xafcc: file String.cc, line 846.
10184Multiple breakpoints were set.
10185Use the "delete" command to delete unwanted
10186 breakpoints.
10187(@value{GDBP})
10188@end group
10189@end smallexample
10190
10191@table @code
10192@kindex set multiple-symbols
10193@item set multiple-symbols @var{mode}
10194@cindex multiple-symbols menu
10195
10196This option allows you to adjust the debugger behavior when an expression
10197is ambiguous.
10198
10199By default, @var{mode} is set to @code{all}. If the command with which
10200the expression is used allows more than one choice, then @value{GDBN}
10201automatically selects all possible choices. For instance, inserting
10202a breakpoint on a function using an ambiguous name results in a breakpoint
10203inserted on each possible match. However, if a unique choice must be made,
10204then @value{GDBN} uses the menu to help you disambiguate the expression.
10205For instance, printing the address of an overloaded function will result
10206in the use of the menu.
10207
10208When @var{mode} is set to @code{ask}, the debugger always uses the menu
10209when an ambiguity is detected.
10210
10211Finally, when @var{mode} is set to @code{cancel}, the debugger reports
10212an error due to the ambiguity and the command is aborted.
10213
10214@kindex show multiple-symbols
10215@item show multiple-symbols
10216Show the current value of the @code{multiple-symbols} setting.
10217@end table
10218
6d2ebf8b 10219@node Variables
79a6e687 10220@section Program Variables
c906108c
SS
10221
10222The most common kind of expression to use is the name of a variable
10223in your program.
10224
10225Variables in expressions are understood in the selected stack frame
79a6e687 10226(@pxref{Selection, ,Selecting a Frame}); they must be either:
c906108c
SS
10227
10228@itemize @bullet
10229@item
10230global (or file-static)
10231@end itemize
10232
5d161b24 10233@noindent or
c906108c
SS
10234
10235@itemize @bullet
10236@item
10237visible according to the scope rules of the
10238programming language from the point of execution in that frame
5d161b24 10239@end itemize
c906108c
SS
10240
10241@noindent This means that in the function
10242
474c8240 10243@smallexample
c906108c
SS
10244foo (a)
10245 int a;
10246@{
10247 bar (a);
10248 @{
10249 int b = test ();
10250 bar (b);
10251 @}
10252@}
474c8240 10253@end smallexample
c906108c
SS
10254
10255@noindent
10256you can examine and use the variable @code{a} whenever your program is
10257executing within the function @code{foo}, but you can only use or
10258examine the variable @code{b} while your program is executing inside
10259the block where @code{b} is declared.
10260
10261@cindex variable name conflict
10262There is an exception: you can refer to a variable or function whose
10263scope is a single source file even if the current execution point is not
10264in this file. But it is possible to have more than one such variable or
10265function with the same name (in different source files). If that
10266happens, referring to that name has unpredictable effects. If you wish,
72384ba3 10267you can specify a static variable in a particular function or file by
15387254 10268using the colon-colon (@code{::}) notation:
c906108c 10269
d4f3574e 10270@cindex colon-colon, context for variables/functions
12c27660 10271@ifnotinfo
c906108c 10272@c info cannot cope with a :: index entry, but why deprive hard copy readers?
41afff9a 10273@cindex @code{::}, context for variables/functions
12c27660 10274@end ifnotinfo
474c8240 10275@smallexample
c906108c
SS
10276@var{file}::@var{variable}
10277@var{function}::@var{variable}
474c8240 10278@end smallexample
c906108c
SS
10279
10280@noindent
10281Here @var{file} or @var{function} is the name of the context for the
10282static @var{variable}. In the case of file names, you can use quotes to
10283make sure @value{GDBN} parses the file name as a single word---for example,
10284to print a global value of @code{x} defined in @file{f2.c}:
10285
474c8240 10286@smallexample
c906108c 10287(@value{GDBP}) p 'f2.c'::x
474c8240 10288@end smallexample
c906108c 10289
72384ba3
PH
10290The @code{::} notation is normally used for referring to
10291static variables, since you typically disambiguate uses of local variables
10292in functions by selecting the appropriate frame and using the
10293simple name of the variable. However, you may also use this notation
10294to refer to local variables in frames enclosing the selected frame:
10295
10296@smallexample
10297void
10298foo (int a)
10299@{
10300 if (a < 10)
10301 bar (a);
10302 else
10303 process (a); /* Stop here */
10304@}
10305
10306int
10307bar (int a)
10308@{
10309 foo (a + 5);
10310@}
10311@end smallexample
10312
10313@noindent
10314For example, if there is a breakpoint at the commented line,
10315here is what you might see
10316when the program stops after executing the call @code{bar(0)}:
10317
10318@smallexample
10319(@value{GDBP}) p a
10320$1 = 10
10321(@value{GDBP}) p bar::a
10322$2 = 5
10323(@value{GDBP}) up 2
10324#2 0x080483d0 in foo (a=5) at foobar.c:12
10325(@value{GDBP}) p a
10326$3 = 5
10327(@value{GDBP}) p bar::a
10328$4 = 0
10329@end smallexample
10330
b37052ae 10331@cindex C@t{++} scope resolution
805e1f19
TT
10332These uses of @samp{::} are very rarely in conflict with the very
10333similar use of the same notation in C@t{++}. When they are in
10334conflict, the C@t{++} meaning takes precedence; however, this can be
10335overridden by quoting the file or function name with single quotes.
10336
10337For example, suppose the program is stopped in a method of a class
10338that has a field named @code{includefile}, and there is also an
10339include file named @file{includefile} that defines a variable,
10340@code{some_global}.
10341
10342@smallexample
10343(@value{GDBP}) p includefile
10344$1 = 23
10345(@value{GDBP}) p includefile::some_global
10346A syntax error in expression, near `'.
10347(@value{GDBP}) p 'includefile'::some_global
10348$2 = 27
10349@end smallexample
c906108c
SS
10350
10351@cindex wrong values
10352@cindex variable values, wrong
15387254
EZ
10353@cindex function entry/exit, wrong values of variables
10354@cindex optimized code, wrong values of variables
c906108c
SS
10355@quotation
10356@emph{Warning:} Occasionally, a local variable may appear to have the
10357wrong value at certain points in a function---just after entry to a new
10358scope, and just before exit.
10359@end quotation
10360You may see this problem when you are stepping by machine instructions.
10361This is because, on most machines, it takes more than one instruction to
10362set up a stack frame (including local variable definitions); if you are
10363stepping by machine instructions, variables may appear to have the wrong
10364values until the stack frame is completely built. On exit, it usually
10365also takes more than one machine instruction to destroy a stack frame;
10366after you begin stepping through that group of instructions, local
10367variable definitions may be gone.
10368
10369This may also happen when the compiler does significant optimizations.
10370To be sure of always seeing accurate values, turn off all optimization
10371when compiling.
10372
d4f3574e
SS
10373@cindex ``No symbol "foo" in current context''
10374Another possible effect of compiler optimizations is to optimize
10375unused variables out of existence, or assign variables to registers (as
10376opposed to memory addresses). Depending on the support for such cases
10377offered by the debug info format used by the compiler, @value{GDBN}
10378might not be able to display values for such local variables. If that
10379happens, @value{GDBN} will print a message like this:
10380
474c8240 10381@smallexample
d4f3574e 10382No symbol "foo" in current context.
474c8240 10383@end smallexample
d4f3574e
SS
10384
10385To solve such problems, either recompile without optimizations, or use a
10386different debug info format, if the compiler supports several such
e0f8f636
TT
10387formats. @xref{Compilation}, for more information on choosing compiler
10388options. @xref{C, ,C and C@t{++}}, for more information about debug
10389info formats that are best suited to C@t{++} programs.
d4f3574e 10390
ab1adacd
EZ
10391If you ask to print an object whose contents are unknown to
10392@value{GDBN}, e.g., because its data type is not completely specified
10393by the debug information, @value{GDBN} will say @samp{<incomplete
10394type>}. @xref{Symbols, incomplete type}, for more about this.
10395
d69cf9b2
PA
10396@cindex no debug info variables
10397If you try to examine or use the value of a (global) variable for
10398which @value{GDBN} has no type information, e.g., because the program
10399includes no debug information, @value{GDBN} displays an error message.
10400@xref{Symbols, unknown type}, for more about unknown types. If you
10401cast the variable to its declared type, @value{GDBN} gets the
10402variable's value using the cast-to type as the variable's type. For
10403example, in a C program:
10404
10405@smallexample
10406 (@value{GDBP}) p var
10407 'var' has unknown type; cast it to its declared type
10408 (@value{GDBP}) p (float) var
10409 $1 = 3.14
10410@end smallexample
10411
36b11add
JK
10412If you append @kbd{@@entry} string to a function parameter name you get its
10413value at the time the function got called. If the value is not available an
10414error message is printed. Entry values are available only with some compilers.
10415Entry values are normally also printed at the function parameter list according
10416to @ref{set print entry-values}.
10417
10418@smallexample
10419Breakpoint 1, d (i=30) at gdb.base/entry-value.c:29
1042029 i++;
10421(gdb) next
1042230 e (i);
10423(gdb) print i
10424$1 = 31
10425(gdb) print i@@entry
10426$2 = 30
10427@end smallexample
10428
3a60f64e
JK
10429Strings are identified as arrays of @code{char} values without specified
10430signedness. Arrays of either @code{signed char} or @code{unsigned char} get
10431printed as arrays of 1 byte sized integers. @code{-fsigned-char} or
10432@code{-funsigned-char} @value{NGCC} options have no effect as @value{GDBN}
10433defines literal string type @code{"char"} as @code{char} without a sign.
10434For program code
10435
10436@smallexample
10437char var0[] = "A";
10438signed char var1[] = "A";
10439@end smallexample
10440
10441You get during debugging
10442@smallexample
10443(gdb) print var0
10444$1 = "A"
10445(gdb) print var1
10446$2 = @{65 'A', 0 '\0'@}
10447@end smallexample
10448
6d2ebf8b 10449@node Arrays
79a6e687 10450@section Artificial Arrays
c906108c
SS
10451
10452@cindex artificial array
15387254 10453@cindex arrays
41afff9a 10454@kindex @@@r{, referencing memory as an array}
c906108c
SS
10455It is often useful to print out several successive objects of the
10456same type in memory; a section of an array, or an array of
10457dynamically determined size for which only a pointer exists in the
10458program.
10459
10460You can do this by referring to a contiguous span of memory as an
10461@dfn{artificial array}, using the binary operator @samp{@@}. The left
10462operand of @samp{@@} should be the first element of the desired array
10463and be an individual object. The right operand should be the desired length
10464of the array. The result is an array value whose elements are all of
10465the type of the left argument. The first element is actually the left
10466argument; the second element comes from bytes of memory immediately
10467following those that hold the first element, and so on. Here is an
10468example. If a program says
10469
474c8240 10470@smallexample
c906108c 10471int *array = (int *) malloc (len * sizeof (int));
474c8240 10472@end smallexample
c906108c
SS
10473
10474@noindent
10475you can print the contents of @code{array} with
10476
474c8240 10477@smallexample
c906108c 10478p *array@@len
474c8240 10479@end smallexample
c906108c
SS
10480
10481The left operand of @samp{@@} must reside in memory. Array values made
10482with @samp{@@} in this way behave just like other arrays in terms of
10483subscripting, and are coerced to pointers when used in expressions.
10484Artificial arrays most often appear in expressions via the value history
79a6e687 10485(@pxref{Value History, ,Value History}), after printing one out.
c906108c
SS
10486
10487Another way to create an artificial array is to use a cast.
10488This re-interprets a value as if it were an array.
10489The value need not be in memory:
474c8240 10490@smallexample
c906108c
SS
10491(@value{GDBP}) p/x (short[2])0x12345678
10492$1 = @{0x1234, 0x5678@}
474c8240 10493@end smallexample
c906108c
SS
10494
10495As a convenience, if you leave the array length out (as in
c3f6f71d 10496@samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
c906108c 10497the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
474c8240 10498@smallexample
c906108c
SS
10499(@value{GDBP}) p/x (short[])0x12345678
10500$2 = @{0x1234, 0x5678@}
474c8240 10501@end smallexample
c906108c
SS
10502
10503Sometimes the artificial array mechanism is not quite enough; in
10504moderately complex data structures, the elements of interest may not
10505actually be adjacent---for example, if you are interested in the values
10506of pointers in an array. One useful work-around in this situation is
10507to use a convenience variable (@pxref{Convenience Vars, ,Convenience
79a6e687 10508Variables}) as a counter in an expression that prints the first
c906108c
SS
10509interesting value, and then repeat that expression via @key{RET}. For
10510instance, suppose you have an array @code{dtab} of pointers to
10511structures, and you are interested in the values of a field @code{fv}
10512in each structure. Here is an example of what you might type:
10513
474c8240 10514@smallexample
c906108c
SS
10515set $i = 0
10516p dtab[$i++]->fv
10517@key{RET}
10518@key{RET}
10519@dots{}
474c8240 10520@end smallexample
c906108c 10521
6d2ebf8b 10522@node Output Formats
79a6e687 10523@section Output Formats
c906108c
SS
10524
10525@cindex formatted output
10526@cindex output formats
10527By default, @value{GDBN} prints a value according to its data type. Sometimes
10528this is not what you want. For example, you might want to print a number
10529in hex, or a pointer in decimal. Or you might want to view data in memory
10530at a certain address as a character string or as an instruction. To do
10531these things, specify an @dfn{output format} when you print a value.
10532
10533The simplest use of output formats is to say how to print a value
10534already computed. This is done by starting the arguments of the
10535@code{print} command with a slash and a format letter. The format
10536letters supported are:
10537
10538@table @code
10539@item x
10540Regard the bits of the value as an integer, and print the integer in
10541hexadecimal.
10542
10543@item d
10544Print as integer in signed decimal.
10545
10546@item u
10547Print as integer in unsigned decimal.
10548
10549@item o
10550Print as integer in octal.
10551
10552@item t
10553Print as integer in binary. The letter @samp{t} stands for ``two''.
10554@footnote{@samp{b} cannot be used because these format letters are also
10555used with the @code{x} command, where @samp{b} stands for ``byte'';
79a6e687 10556see @ref{Memory,,Examining Memory}.}
c906108c
SS
10557
10558@item a
10559@cindex unknown address, locating
3d67e040 10560@cindex locate address
c906108c
SS
10561Print as an address, both absolute in hexadecimal and as an offset from
10562the nearest preceding symbol. You can use this format used to discover
10563where (in what function) an unknown address is located:
10564
474c8240 10565@smallexample
c906108c
SS
10566(@value{GDBP}) p/a 0x54320
10567$3 = 0x54320 <_initialize_vx+396>
474c8240 10568@end smallexample
c906108c 10569
3d67e040
EZ
10570@noindent
10571The command @code{info symbol 0x54320} yields similar results.
10572@xref{Symbols, info symbol}.
10573
c906108c 10574@item c
51274035
EZ
10575Regard as an integer and print it as a character constant. This
10576prints both the numerical value and its character representation. The
10577character representation is replaced with the octal escape @samp{\nnn}
10578for characters outside the 7-bit @sc{ascii} range.
c906108c 10579
ea37ba09
DJ
10580Without this format, @value{GDBN} displays @code{char},
10581@w{@code{unsigned char}}, and @w{@code{signed char}} data as character
10582constants. Single-byte members of vectors are displayed as integer
10583data.
10584
c906108c
SS
10585@item f
10586Regard the bits of the value as a floating point number and print
10587using typical floating point syntax.
ea37ba09
DJ
10588
10589@item s
10590@cindex printing strings
10591@cindex printing byte arrays
10592Regard as a string, if possible. With this format, pointers to single-byte
10593data are displayed as null-terminated strings and arrays of single-byte data
10594are displayed as fixed-length strings. Other values are displayed in their
10595natural types.
10596
10597Without this format, @value{GDBN} displays pointers to and arrays of
10598@code{char}, @w{@code{unsigned char}}, and @w{@code{signed char}} as
10599strings. Single-byte members of a vector are displayed as an integer
10600array.
a6bac58e 10601
6fbe845e
AB
10602@item z
10603Like @samp{x} formatting, the value is treated as an integer and
10604printed as hexadecimal, but leading zeros are printed to pad the value
10605to the size of the integer type.
10606
a6bac58e
TT
10607@item r
10608@cindex raw printing
10609Print using the @samp{raw} formatting. By default, @value{GDBN} will
78e2826b
TT
10610use a Python-based pretty-printer, if one is available (@pxref{Pretty
10611Printing}). This typically results in a higher-level display of the
10612value's contents. The @samp{r} format bypasses any Python
10613pretty-printer which might exist.
c906108c
SS
10614@end table
10615
10616For example, to print the program counter in hex (@pxref{Registers}), type
10617
474c8240 10618@smallexample
c906108c 10619p/x $pc
474c8240 10620@end smallexample
c906108c
SS
10621
10622@noindent
10623Note that no space is required before the slash; this is because command
10624names in @value{GDBN} cannot contain a slash.
10625
10626To reprint the last value in the value history with a different format,
10627you can use the @code{print} command with just a format and no
10628expression. For example, @samp{p/x} reprints the last value in hex.
10629
6d2ebf8b 10630@node Memory
79a6e687 10631@section Examining Memory
c906108c
SS
10632
10633You can use the command @code{x} (for ``examine'') to examine memory in
10634any of several formats, independently of your program's data types.
10635
10636@cindex examining memory
10637@table @code
41afff9a 10638@kindex x @r{(examine memory)}
c906108c
SS
10639@item x/@var{nfu} @var{addr}
10640@itemx x @var{addr}
10641@itemx x
10642Use the @code{x} command to examine memory.
10643@end table
10644
10645@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
10646much memory to display and how to format it; @var{addr} is an
10647expression giving the address where you want to start displaying memory.
10648If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
10649Several commands set convenient defaults for @var{addr}.
10650
10651@table @r
10652@item @var{n}, the repeat count
10653The repeat count is a decimal integer; the default is 1. It specifies
bb556f1f
TK
10654how much memory (counting by units @var{u}) to display. If a negative
10655number is specified, memory is examined backward from @var{addr}.
c906108c
SS
10656@c This really is **decimal**; unaffected by 'set radix' as of GDB
10657@c 4.1.2.
10658
10659@item @var{f}, the display format
51274035
EZ
10660The display format is one of the formats used by @code{print}
10661(@samp{x}, @samp{d}, @samp{u}, @samp{o}, @samp{t}, @samp{a}, @samp{c},
ea37ba09
DJ
10662@samp{f}, @samp{s}), and in addition @samp{i} (for machine instructions).
10663The default is @samp{x} (hexadecimal) initially. The default changes
10664each time you use either @code{x} or @code{print}.
c906108c
SS
10665
10666@item @var{u}, the unit size
10667The unit size is any of
10668
10669@table @code
10670@item b
10671Bytes.
10672@item h
10673Halfwords (two bytes).
10674@item w
10675Words (four bytes). This is the initial default.
10676@item g
10677Giant words (eight bytes).
10678@end table
10679
10680Each time you specify a unit size with @code{x}, that size becomes the
9a22f0d0
PM
10681default unit the next time you use @code{x}. For the @samp{i} format,
10682the unit size is ignored and is normally not written. For the @samp{s} format,
10683the unit size defaults to @samp{b}, unless it is explicitly given.
10684Use @kbd{x /hs} to display 16-bit char strings and @kbd{x /ws} to display
1068532-bit strings. The next use of @kbd{x /s} will again display 8-bit strings.
10686Note that the results depend on the programming language of the
10687current compilation unit. If the language is C, the @samp{s}
10688modifier will use the UTF-16 encoding while @samp{w} will use
10689UTF-32. The encoding is set by the programming language and cannot
10690be altered.
c906108c
SS
10691
10692@item @var{addr}, starting display address
10693@var{addr} is the address where you want @value{GDBN} to begin displaying
10694memory. The expression need not have a pointer value (though it may);
10695it is always interpreted as an integer address of a byte of memory.
10696@xref{Expressions, ,Expressions}, for more information on expressions. The default for
10697@var{addr} is usually just after the last address examined---but several
10698other commands also set the default address: @code{info breakpoints} (to
10699the address of the last breakpoint listed), @code{info line} (to the
10700starting address of a line), and @code{print} (if you use it to display
10701a value from memory).
10702@end table
10703
10704For example, @samp{x/3uh 0x54320} is a request to display three halfwords
10705(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
10706starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
10707words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
d4f3574e 10708@pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
c906108c 10709
bb556f1f
TK
10710You can also specify a negative repeat count to examine memory backward
10711from the given address. For example, @samp{x/-3uh 0x54320} prints three
10712halfwords (@code{h}) at @code{0x54314}, @code{0x54328}, and @code{0x5431c}.
10713
c906108c
SS
10714Since the letters indicating unit sizes are all distinct from the
10715letters specifying output formats, you do not have to remember whether
10716unit size or format comes first; either order works. The output
10717specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
10718(However, the count @var{n} must come first; @samp{wx4} does not work.)
10719
10720Even though the unit size @var{u} is ignored for the formats @samp{s}
10721and @samp{i}, you might still want to use a count @var{n}; for example,
10722@samp{3i} specifies that you want to see three machine instructions,
a4642986
MR
10723including any operands. For convenience, especially when used with
10724the @code{display} command, the @samp{i} format also prints branch delay
10725slot instructions, if any, beyond the count specified, which immediately
10726follow the last instruction that is within the count. The command
10727@code{disassemble} gives an alternative way of inspecting machine
10728instructions; see @ref{Machine Code,,Source and Machine Code}.
c906108c 10729
bb556f1f
TK
10730If a negative repeat count is specified for the formats @samp{s} or @samp{i},
10731the command displays null-terminated strings or instructions before the given
10732address as many as the absolute value of the given number. For the @samp{i}
10733format, we use line number information in the debug info to accurately locate
10734instruction boundaries while disassembling backward. If line info is not
10735available, the command stops examining memory with an error message.
10736
c906108c
SS
10737All the defaults for the arguments to @code{x} are designed to make it
10738easy to continue scanning memory with minimal specifications each time
10739you use @code{x}. For example, after you have inspected three machine
10740instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
10741with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
10742the repeat count @var{n} is used again; the other arguments default as
10743for successive uses of @code{x}.
10744
2b28d209
PP
10745When examining machine instructions, the instruction at current program
10746counter is shown with a @code{=>} marker. For example:
10747
10748@smallexample
10749(@value{GDBP}) x/5i $pc-6
10750 0x804837f <main+11>: mov %esp,%ebp
10751 0x8048381 <main+13>: push %ecx
10752 0x8048382 <main+14>: sub $0x4,%esp
10753=> 0x8048385 <main+17>: movl $0x8048460,(%esp)
10754 0x804838c <main+24>: call 0x80482d4 <puts@@plt>
10755@end smallexample
10756
c906108c
SS
10757@cindex @code{$_}, @code{$__}, and value history
10758The addresses and contents printed by the @code{x} command are not saved
10759in the value history because there is often too much of them and they
10760would get in the way. Instead, @value{GDBN} makes these values available for
10761subsequent use in expressions as values of the convenience variables
10762@code{$_} and @code{$__}. After an @code{x} command, the last address
10763examined is available for use in expressions in the convenience variable
10764@code{$_}. The contents of that address, as examined, are available in
10765the convenience variable @code{$__}.
10766
10767If the @code{x} command has a repeat count, the address and contents saved
10768are from the last memory unit printed; this is not the same as the last
10769address printed if several units were printed on the last line of output.
10770
a86c90e6
SM
10771@anchor{addressable memory unit}
10772@cindex addressable memory unit
10773Most targets have an addressable memory unit size of 8 bits. This means
10774that to each memory address are associated 8 bits of data. Some
10775targets, however, have other addressable memory unit sizes.
10776Within @value{GDBN} and this document, the term
10777@dfn{addressable memory unit} (or @dfn{memory unit} for short) is used
10778when explicitly referring to a chunk of data of that size. The word
10779@dfn{byte} is used to refer to a chunk of data of 8 bits, regardless of
10780the addressable memory unit size of the target. For most systems,
10781addressable memory unit is a synonym of byte.
10782
09d4efe1 10783@cindex remote memory comparison
936d2992 10784@cindex target memory comparison
09d4efe1 10785@cindex verify remote memory image
936d2992 10786@cindex verify target memory image
09d4efe1 10787When you are debugging a program running on a remote target machine
936d2992
PA
10788(@pxref{Remote Debugging}), you may wish to verify the program's image
10789in the remote machine's memory against the executable file you
10790downloaded to the target. Or, on any target, you may want to check
10791whether the program has corrupted its own read-only sections. The
10792@code{compare-sections} command is provided for such situations.
09d4efe1
EZ
10793
10794@table @code
10795@kindex compare-sections
95cf3b38 10796@item compare-sections @r{[}@var{section-name}@r{|}@code{-r}@r{]}
09d4efe1
EZ
10797Compare the data of a loadable section @var{section-name} in the
10798executable file of the program being debugged with the same section in
936d2992 10799the target machine's memory, and report any mismatches. With no
95cf3b38 10800arguments, compares all loadable sections. With an argument of
936d2992
PA
10801@code{-r}, compares all loadable read-only sections.
10802
10803Note: for remote targets, this command can be accelerated if the
10804target supports computing the CRC checksum of a block of memory
10805(@pxref{qCRC packet}).
09d4efe1
EZ
10806@end table
10807
6d2ebf8b 10808@node Auto Display
79a6e687 10809@section Automatic Display
c906108c
SS
10810@cindex automatic display
10811@cindex display of expressions
10812
10813If you find that you want to print the value of an expression frequently
10814(to see how it changes), you might want to add it to the @dfn{automatic
10815display list} so that @value{GDBN} prints its value each time your program stops.
10816Each expression added to the list is given a number to identify it;
10817to remove an expression from the list, you specify that number.
10818The automatic display looks like this:
10819
474c8240 10820@smallexample
c906108c
SS
108212: foo = 38
108223: bar[5] = (struct hack *) 0x3804
474c8240 10823@end smallexample
c906108c
SS
10824
10825@noindent
10826This display shows item numbers, expressions and their current values. As with
10827displays you request manually using @code{x} or @code{print}, you can
10828specify the output format you prefer; in fact, @code{display} decides
ea37ba09
DJ
10829whether to use @code{print} or @code{x} depending your format
10830specification---it uses @code{x} if you specify either the @samp{i}
10831or @samp{s} format, or a unit size; otherwise it uses @code{print}.
c906108c
SS
10832
10833@table @code
10834@kindex display
d4f3574e
SS
10835@item display @var{expr}
10836Add the expression @var{expr} to the list of expressions to display
c906108c
SS
10837each time your program stops. @xref{Expressions, ,Expressions}.
10838
10839@code{display} does not repeat if you press @key{RET} again after using it.
10840
d4f3574e 10841@item display/@var{fmt} @var{expr}
c906108c 10842For @var{fmt} specifying only a display format and not a size or
d4f3574e 10843count, add the expression @var{expr} to the auto-display list but
c906108c 10844arrange to display it each time in the specified format @var{fmt}.
79a6e687 10845@xref{Output Formats,,Output Formats}.
c906108c
SS
10846
10847@item display/@var{fmt} @var{addr}
10848For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
10849number of units, add the expression @var{addr} as a memory address to
10850be examined each time your program stops. Examining means in effect
79a6e687 10851doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining Memory}.
c906108c
SS
10852@end table
10853
10854For example, @samp{display/i $pc} can be helpful, to see the machine
10855instruction about to be executed each time execution stops (@samp{$pc}
d4f3574e 10856is a common name for the program counter; @pxref{Registers, ,Registers}).
c906108c
SS
10857
10858@table @code
10859@kindex delete display
10860@kindex undisplay
10861@item undisplay @var{dnums}@dots{}
10862@itemx delete display @var{dnums}@dots{}
c9174737
PA
10863Remove items from the list of expressions to display. Specify the
10864numbers of the displays that you want affected with the command
10865argument @var{dnums}. It can be a single display number, one of the
10866numbers shown in the first field of the @samp{info display} display;
10867or it could be a range of display numbers, as in @code{2-4}.
c906108c
SS
10868
10869@code{undisplay} does not repeat if you press @key{RET} after using it.
10870(Otherwise you would just get the error @samp{No display number @dots{}}.)
10871
10872@kindex disable display
10873@item disable display @var{dnums}@dots{}
10874Disable the display of item numbers @var{dnums}. A disabled display
10875item is not printed automatically, but is not forgotten. It may be
c9174737
PA
10876enabled again later. Specify the numbers of the displays that you
10877want affected with the command argument @var{dnums}. It can be a
10878single display number, one of the numbers shown in the first field of
10879the @samp{info display} display; or it could be a range of display
10880numbers, as in @code{2-4}.
c906108c
SS
10881
10882@kindex enable display
10883@item enable display @var{dnums}@dots{}
10884Enable display of item numbers @var{dnums}. It becomes effective once
10885again in auto display of its expression, until you specify otherwise.
c9174737
PA
10886Specify the numbers of the displays that you want affected with the
10887command argument @var{dnums}. It can be a single display number, one
10888of the numbers shown in the first field of the @samp{info display}
10889display; or it could be a range of display numbers, as in @code{2-4}.
c906108c
SS
10890
10891@item display
10892Display the current values of the expressions on the list, just as is
10893done when your program stops.
10894
10895@kindex info display
10896@item info display
10897Print the list of expressions previously set up to display
10898automatically, each one with its item number, but without showing the
10899values. This includes disabled expressions, which are marked as such.
10900It also includes expressions which would not be displayed right now
10901because they refer to automatic variables not currently available.
10902@end table
10903
15387254 10904@cindex display disabled out of scope
c906108c
SS
10905If a display expression refers to local variables, then it does not make
10906sense outside the lexical context for which it was set up. Such an
10907expression is disabled when execution enters a context where one of its
10908variables is not defined. For example, if you give the command
10909@code{display last_char} while inside a function with an argument
10910@code{last_char}, @value{GDBN} displays this argument while your program
10911continues to stop inside that function. When it stops elsewhere---where
10912there is no variable @code{last_char}---the display is disabled
10913automatically. The next time your program stops where @code{last_char}
10914is meaningful, you can enable the display expression once again.
10915
6d2ebf8b 10916@node Print Settings
79a6e687 10917@section Print Settings
c906108c
SS
10918
10919@cindex format options
10920@cindex print settings
10921@value{GDBN} provides the following ways to control how arrays, structures,
10922and symbols are printed.
10923
10924@noindent
10925These settings are useful for debugging programs in any language:
10926
10927@table @code
4644b6e3 10928@kindex set print
3345721a 10929@anchor{set print address}
c906108c
SS
10930@item set print address
10931@itemx set print address on
4644b6e3 10932@cindex print/don't print memory addresses
c906108c
SS
10933@value{GDBN} prints memory addresses showing the location of stack
10934traces, structure values, pointer values, breakpoints, and so forth,
10935even when it also displays the contents of those addresses. The default
10936is @code{on}. For example, this is what a stack frame display looks like with
10937@code{set print address on}:
10938
10939@smallexample
10940@group
10941(@value{GDBP}) f
10942#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
10943 at input.c:530
10944530 if (lquote != def_lquote)
10945@end group
10946@end smallexample
10947
10948@item set print address off
10949Do not print addresses when displaying their contents. For example,
10950this is the same stack frame displayed with @code{set print address off}:
10951
10952@smallexample
10953@group
10954(@value{GDBP}) set print addr off
10955(@value{GDBP}) f
10956#0 set_quotes (lq="<<", rq=">>") at input.c:530
10957530 if (lquote != def_lquote)
10958@end group
10959@end smallexample
10960
10961You can use @samp{set print address off} to eliminate all machine
10962dependent displays from the @value{GDBN} interface. For example, with
10963@code{print address off}, you should get the same text for backtraces on
10964all machines---whether or not they involve pointer arguments.
10965
4644b6e3 10966@kindex show print
c906108c
SS
10967@item show print address
10968Show whether or not addresses are to be printed.
10969@end table
10970
10971When @value{GDBN} prints a symbolic address, it normally prints the
10972closest earlier symbol plus an offset. If that symbol does not uniquely
10973identify the address (for example, it is a name whose scope is a single
10974source file), you may need to clarify. One way to do this is with
10975@code{info line}, for example @samp{info line *0x4537}. Alternately,
10976you can set @value{GDBN} to print the source file and line number when
10977it prints a symbolic address:
10978
10979@table @code
c906108c 10980@item set print symbol-filename on
9c16f35a
EZ
10981@cindex source file and line of a symbol
10982@cindex symbol, source file and line
c906108c
SS
10983Tell @value{GDBN} to print the source file name and line number of a
10984symbol in the symbolic form of an address.
10985
10986@item set print symbol-filename off
10987Do not print source file name and line number of a symbol. This is the
10988default.
10989
c906108c
SS
10990@item show print symbol-filename
10991Show whether or not @value{GDBN} will print the source file name and
10992line number of a symbol in the symbolic form of an address.
10993@end table
10994
10995Another situation where it is helpful to show symbol filenames and line
10996numbers is when disassembling code; @value{GDBN} shows you the line
10997number and source file that corresponds to each instruction.
10998
10999Also, you may wish to see the symbolic form only if the address being
11000printed is reasonably close to the closest earlier symbol:
11001
11002@table @code
c906108c 11003@item set print max-symbolic-offset @var{max-offset}
f81d1120 11004@itemx set print max-symbolic-offset unlimited
4644b6e3 11005@cindex maximum value for offset of closest symbol
c906108c
SS
11006Tell @value{GDBN} to only display the symbolic form of an address if the
11007offset between the closest earlier symbol and the address is less than
f81d1120
PA
11008@var{max-offset}. The default is @code{unlimited}, which tells @value{GDBN}
11009to always print the symbolic form of an address if any symbol precedes
11010it. Zero is equivalent to @code{unlimited}.
c906108c 11011
c906108c
SS
11012@item show print max-symbolic-offset
11013Ask how large the maximum offset is that @value{GDBN} prints in a
11014symbolic address.
11015@end table
11016
11017@cindex wild pointer, interpreting
11018@cindex pointer, finding referent
11019If you have a pointer and you are not sure where it points, try
11020@samp{set print symbol-filename on}. Then you can determine the name
11021and source file location of the variable where it points, using
11022@samp{p/a @var{pointer}}. This interprets the address in symbolic form.
11023For example, here @value{GDBN} shows that a variable @code{ptt} points
11024at another variable @code{t}, defined in @file{hi2.c}:
11025
474c8240 11026@smallexample
c906108c
SS
11027(@value{GDBP}) set print symbol-filename on
11028(@value{GDBP}) p/a ptt
11029$4 = 0xe008 <t in hi2.c>
474c8240 11030@end smallexample
c906108c
SS
11031
11032@quotation
11033@emph{Warning:} For pointers that point to a local variable, @samp{p/a}
11034does not show the symbol name and filename of the referent, even with
11035the appropriate @code{set print} options turned on.
11036@end quotation
11037
9cb709b6
TT
11038You can also enable @samp{/a}-like formatting all the time using
11039@samp{set print symbol on}:
11040
3345721a 11041@anchor{set print symbol}
9cb709b6
TT
11042@table @code
11043@item set print symbol on
11044Tell @value{GDBN} to print the symbol corresponding to an address, if
11045one exists.
11046
11047@item set print symbol off
11048Tell @value{GDBN} not to print the symbol corresponding to an
11049address. In this mode, @value{GDBN} will still print the symbol
11050corresponding to pointers to functions. This is the default.
11051
11052@item show print symbol
11053Show whether @value{GDBN} will display the symbol corresponding to an
11054address.
11055@end table
11056
c906108c
SS
11057Other settings control how different kinds of objects are printed:
11058
11059@table @code
3345721a 11060@anchor{set print array}
c906108c
SS
11061@item set print array
11062@itemx set print array on
4644b6e3 11063@cindex pretty print arrays
c906108c
SS
11064Pretty print arrays. This format is more convenient to read,
11065but uses more space. The default is off.
11066
11067@item set print array off
11068Return to compressed format for arrays.
11069
c906108c
SS
11070@item show print array
11071Show whether compressed or pretty format is selected for displaying
11072arrays.
11073
3c9c013a 11074@cindex print array indexes
3345721a 11075@anchor{set print array-indexes}
3c9c013a
JB
11076@item set print array-indexes
11077@itemx set print array-indexes on
11078Print the index of each element when displaying arrays. May be more
11079convenient to locate a given element in the array or quickly find the
11080index of a given element in that printed array. The default is off.
11081
11082@item set print array-indexes off
11083Stop printing element indexes when displaying arrays.
11084
11085@item show print array-indexes
11086Show whether the index of each element is printed when displaying
11087arrays.
11088
3345721a 11089@anchor{set print elements}
c906108c 11090@item set print elements @var{number-of-elements}
f81d1120 11091@itemx set print elements unlimited
4644b6e3 11092@cindex number of array elements to print
9c16f35a 11093@cindex limit on number of printed array elements
c906108c
SS
11094Set a limit on how many elements of an array @value{GDBN} will print.
11095If @value{GDBN} is printing a large array, it stops printing after it has
11096printed the number of elements set by the @code{set print elements} command.
11097This limit also applies to the display of strings.
d4f3574e 11098When @value{GDBN} starts, this limit is set to 200.
f81d1120
PA
11099Setting @var{number-of-elements} to @code{unlimited} or zero means
11100that the number of elements to print is unlimited.
c906108c 11101
c906108c
SS
11102@item show print elements
11103Display the number of elements of a large array that @value{GDBN} will print.
11104If the number is 0, then the printing is unlimited.
11105
3345721a 11106@anchor{set print frame-arguments}
b4740add 11107@item set print frame-arguments @var{value}
a0381d3a 11108@kindex set print frame-arguments
b4740add
JB
11109@cindex printing frame argument values
11110@cindex print all frame argument values
11111@cindex print frame argument values for scalars only
bc4268a5 11112@cindex do not print frame arguments
b4740add
JB
11113This command allows to control how the values of arguments are printed
11114when the debugger prints a frame (@pxref{Frames}). The possible
11115values are:
11116
11117@table @code
11118@item all
4f5376b2 11119The values of all arguments are printed.
b4740add
JB
11120
11121@item scalars
11122Print the value of an argument only if it is a scalar. The value of more
11123complex arguments such as arrays, structures, unions, etc, is replaced
4f5376b2
JB
11124by @code{@dots{}}. This is the default. Here is an example where
11125only scalar arguments are shown:
b4740add
JB
11126
11127@smallexample
11128#1 0x08048361 in call_me (i=3, s=@dots{}, ss=0xbf8d508c, u=@dots{}, e=green)
11129 at frame-args.c:23
11130@end smallexample
11131
11132@item none
11133None of the argument values are printed. Instead, the value of each argument
11134is replaced by @code{@dots{}}. In this case, the example above now becomes:
11135
11136@smallexample
11137#1 0x08048361 in call_me (i=@dots{}, s=@dots{}, ss=@dots{}, u=@dots{}, e=@dots{})
11138 at frame-args.c:23
11139@end smallexample
bc4268a5
PW
11140
11141@item presence
11142Only the presence of arguments is indicated by @code{@dots{}}.
11143The @code{@dots{}} are not printed for function without any arguments.
11144None of the argument names and values are printed.
11145In this case, the example above now becomes:
11146
11147@smallexample
11148#1 0x08048361 in call_me (@dots{}) at frame-args.c:23
11149@end smallexample
11150
b4740add
JB
11151@end table
11152
4f5376b2
JB
11153By default, only scalar arguments are printed. This command can be used
11154to configure the debugger to print the value of all arguments, regardless
11155of their type. However, it is often advantageous to not print the value
11156of more complex parameters. For instance, it reduces the amount of
11157information printed in each frame, making the backtrace more readable.
11158Also, it improves performance when displaying Ada frames, because
11159the computation of large arguments can sometimes be CPU-intensive,
11160especially in large applications. Setting @code{print frame-arguments}
bc4268a5
PW
11161to @code{scalars} (the default), @code{none} or @code{presence} avoids
11162this computation, thus speeding up the display of each Ada frame.
b4740add
JB
11163
11164@item show print frame-arguments
11165Show how the value of arguments should be displayed when printing a frame.
11166
3345721a 11167@anchor{set print raw-frame-arguments}
2daf894e 11168@item set print raw-frame-arguments on
e7045703
DE
11169Print frame arguments in raw, non pretty-printed, form.
11170
2daf894e 11171@item set print raw-frame-arguments off
e7045703
DE
11172Print frame arguments in pretty-printed form, if there is a pretty-printer
11173for the value (@pxref{Pretty Printing}),
11174otherwise print the value in raw form.
11175This is the default.
11176
2daf894e 11177@item show print raw-frame-arguments
e7045703
DE
11178Show whether to print frame arguments in raw form.
11179
36b11add 11180@anchor{set print entry-values}
e18b2753
JK
11181@item set print entry-values @var{value}
11182@kindex set print entry-values
11183Set printing of frame argument values at function entry. In some cases
11184@value{GDBN} can determine the value of function argument which was passed by
11185the function caller, even if the value was modified inside the called function
11186and therefore is different. With optimized code, the current value could be
11187unavailable, but the entry value may still be known.
11188
11189The default value is @code{default} (see below for its description). Older
11190@value{GDBN} behaved as with the setting @code{no}. Compilers not supporting
11191this feature will behave in the @code{default} setting the same way as with the
11192@code{no} setting.
11193
11194This functionality is currently supported only by DWARF 2 debugging format and
216f72a1 11195the compiler has to produce @samp{DW_TAG_call_site} tags. With
e18b2753
JK
11196@value{NGCC}, you need to specify @option{-O -g} during compilation, to get
11197this information.
11198
11199The @var{value} parameter can be one of the following:
11200
11201@table @code
11202@item no
11203Print only actual parameter values, never print values from function entry
11204point.
11205@smallexample
11206#0 equal (val=5)
11207#0 different (val=6)
11208#0 lost (val=<optimized out>)
11209#0 born (val=10)
11210#0 invalid (val=<optimized out>)
11211@end smallexample
11212
11213@item only
11214Print only parameter values from function entry point. The actual parameter
11215values are never printed.
11216@smallexample
11217#0 equal (val@@entry=5)
11218#0 different (val@@entry=5)
11219#0 lost (val@@entry=5)
11220#0 born (val@@entry=<optimized out>)
11221#0 invalid (val@@entry=<optimized out>)
11222@end smallexample
11223
11224@item preferred
11225Print only parameter values from function entry point. If value from function
11226entry point is not known while the actual value is known, print the actual
11227value for such parameter.
11228@smallexample
11229#0 equal (val@@entry=5)
11230#0 different (val@@entry=5)
11231#0 lost (val@@entry=5)
11232#0 born (val=10)
11233#0 invalid (val@@entry=<optimized out>)
11234@end smallexample
11235
11236@item if-needed
11237Print actual parameter values. If actual parameter value is not known while
11238value from function entry point is known, print the entry point value for such
11239parameter.
11240@smallexample
11241#0 equal (val=5)
11242#0 different (val=6)
11243#0 lost (val@@entry=5)
11244#0 born (val=10)
11245#0 invalid (val=<optimized out>)
11246@end smallexample
11247
11248@item both
11249Always print both the actual parameter value and its value from function entry
11250point, even if values of one or both are not available due to compiler
11251optimizations.
11252@smallexample
11253#0 equal (val=5, val@@entry=5)
11254#0 different (val=6, val@@entry=5)
11255#0 lost (val=<optimized out>, val@@entry=5)
11256#0 born (val=10, val@@entry=<optimized out>)
11257#0 invalid (val=<optimized out>, val@@entry=<optimized out>)
11258@end smallexample
11259
11260@item compact
11261Print the actual parameter value if it is known and also its value from
11262function entry point if it is known. If neither is known, print for the actual
11263value @code{<optimized out>}. If not in MI mode (@pxref{GDB/MI}) and if both
11264values are known and identical, print the shortened
11265@code{param=param@@entry=VALUE} notation.
11266@smallexample
11267#0 equal (val=val@@entry=5)
11268#0 different (val=6, val@@entry=5)
11269#0 lost (val@@entry=5)
11270#0 born (val=10)
11271#0 invalid (val=<optimized out>)
11272@end smallexample
11273
11274@item default
11275Always print the actual parameter value. Print also its value from function
11276entry point, but only if it is known. If not in MI mode (@pxref{GDB/MI}) and
11277if both values are known and identical, print the shortened
11278@code{param=param@@entry=VALUE} notation.
11279@smallexample
11280#0 equal (val=val@@entry=5)
11281#0 different (val=6, val@@entry=5)
11282#0 lost (val=<optimized out>, val@@entry=5)
11283#0 born (val=10)
11284#0 invalid (val=<optimized out>)
11285@end smallexample
11286@end table
11287
11288For analysis messages on possible failures of frame argument values at function
11289entry resolution see @ref{set debug entry-values}.
11290
11291@item show print entry-values
11292Show the method being used for printing of frame argument values at function
11293entry.
11294
bc4268a5
PW
11295@anchor{set print frame-info}
11296@item set print frame-info @var{value}
11297@kindex set print frame-info
11298@cindex printing frame information
11299@cindex frame information, printing
11300This command allows to control the information printed when
11301the debugger prints a frame. See @ref{Frames}, @ref{Backtrace},
11302for a general explanation about frames and frame information.
11303Note that some other settings (such as @code{set print frame-arguments}
11304and @code{set print address}) are also influencing if and how some frame
11305information is displayed. In particular, the frame program counter is never
11306printed if @code{set print address} is off.
11307
11308The possible values for @code{set print frame-info} are:
11309@table @code
11310@item short-location
11311Print the frame level, the program counter (if not at the
11312beginning of the location source line), the function, the function
11313arguments.
11314@item location
11315Same as @code{short-location} but also print the source file and source line
11316number.
11317@item location-and-address
11318Same as @code{location} but print the program counter even if located at the
11319beginning of the location source line.
11320@item source-line
11321Print the program counter (if not at the beginning of the location
11322source line), the line number and the source line.
11323@item source-and-location
11324Print what @code{location} and @code{source-line} are printing.
11325@item auto
11326The information printed for a frame is decided automatically
11327by the @value{GDBN} command that prints a frame.
11328For example, @code{frame} prints the information printed by
11329@code{source-and-location} while @code{stepi} will switch between
11330@code{source-line} and @code{source-and-location} depending on the program
11331counter.
11332The default value is @code{auto}.
11333@end table
11334
3345721a 11335@anchor{set print repeats}
f81d1120
PA
11336@item set print repeats @var{number-of-repeats}
11337@itemx set print repeats unlimited
9c16f35a
EZ
11338@cindex repeated array elements
11339Set the threshold for suppressing display of repeated array
d3e8051b 11340elements. When the number of consecutive identical elements of an
9c16f35a
EZ
11341array exceeds the threshold, @value{GDBN} prints the string
11342@code{"<repeats @var{n} times>"}, where @var{n} is the number of
11343identical repetitions, instead of displaying the identical elements
f81d1120
PA
11344themselves. Setting the threshold to @code{unlimited} or zero will
11345cause all elements to be individually printed. The default threshold
11346is 10.
9c16f35a
EZ
11347
11348@item show print repeats
11349Display the current threshold for printing repeated identical
11350elements.
11351
3345721a 11352@anchor{set print max-depth}
2e62ab40
AB
11353@item set print max-depth @var{depth}
11354@item set print max-depth unlimited
11355@cindex printing nested structures
11356Set the threshold after which nested structures are replaced with
11357ellipsis, this can make visualising deeply nested structures easier.
11358
11359For example, given this C code
11360
11361@smallexample
11362typedef struct s1 @{ int a; @} s1;
11363typedef struct s2 @{ s1 b; @} s2;
11364typedef struct s3 @{ s2 c; @} s3;
11365typedef struct s4 @{ s3 d; @} s4;
11366
11367s4 var = @{ @{ @{ @{ 3 @} @} @} @};
11368@end smallexample
11369
11370The following table shows how different values of @var{depth} will
11371effect how @code{var} is printed by @value{GDBN}:
11372
11373@multitable @columnfractions .3 .7
11374@headitem @var{depth} setting @tab Result of @samp{p var}
11375@item unlimited
11376@tab @code{$1 = @{d = @{c = @{b = @{a = 3@}@}@}@}}
11377@item @code{0}
11378@tab @code{$1 = @{...@}}
11379@item @code{1}
11380@tab @code{$1 = @{d = @{...@}@}}
11381@item @code{2}
11382@tab @code{$1 = @{d = @{c = @{...@}@}@}}
11383@item @code{3}
11384@tab @code{$1 = @{d = @{c = @{b = @{...@}@}@}@}}
11385@item @code{4}
11386@tab @code{$1 = @{d = @{c = @{b = @{a = 3@}@}@}@}}
11387@end multitable
11388
11389To see the contents of structures that have been hidden the user can
11390either increase the print max-depth, or they can print the elements of
11391the structure that are visible, for example
11392
11393@smallexample
11394(gdb) set print max-depth 2
11395(gdb) p var
11396$1 = @{d = @{c = @{...@}@}@}
11397(gdb) p var.d
11398$2 = @{c = @{b = @{...@}@}@}
11399(gdb) p var.d.c
11400$3 = @{b = @{a = 3@}@}
11401@end smallexample
11402
11403The pattern used to replace nested structures varies based on
11404language, for most languages @code{@{...@}} is used, but Fortran uses
11405@code{(...)}.
11406
11407@item show print max-depth
11408Display the current threshold after which nested structures are
11409replaces with ellipsis.
11410
3345721a 11411@anchor{set print null-stop}
c906108c 11412@item set print null-stop
4644b6e3 11413@cindex @sc{null} elements in arrays
c906108c 11414Cause @value{GDBN} to stop printing the characters of an array when the first
d4f3574e 11415@sc{null} is encountered. This is useful when large arrays actually
c906108c 11416contain only short strings.
d4f3574e 11417The default is off.
c906108c 11418
9c16f35a
EZ
11419@item show print null-stop
11420Show whether @value{GDBN} stops printing an array on the first
11421@sc{null} character.
11422
3345721a 11423@anchor{set print pretty}
c906108c 11424@item set print pretty on
9c16f35a
EZ
11425@cindex print structures in indented form
11426@cindex indentation in structure display
5d161b24 11427Cause @value{GDBN} to print structures in an indented format with one member
c906108c
SS
11428per line, like this:
11429
11430@smallexample
11431@group
11432$1 = @{
11433 next = 0x0,
11434 flags = @{
11435 sweet = 1,
11436 sour = 1
11437 @},
11438 meat = 0x54 "Pork"
11439@}
11440@end group
11441@end smallexample
11442
11443@item set print pretty off
11444Cause @value{GDBN} to print structures in a compact format, like this:
11445
11446@smallexample
11447@group
11448$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
11449meat = 0x54 "Pork"@}
11450@end group
11451@end smallexample
11452
11453@noindent
11454This is the default format.
11455
c906108c
SS
11456@item show print pretty
11457Show which format @value{GDBN} is using to print structures.
11458
d8edc8b7
PW
11459@anchor{set print raw-values}
11460@item set print raw-values on
11461Print values in raw form, without applying the pretty
11462printers for the value.
11463
11464@item set print raw-values off
11465Print values in pretty-printed form, if there is a pretty-printer
11466for the value (@pxref{Pretty Printing}),
11467otherwise print the value in raw form.
11468
11469The default setting is ``off''.
11470
11471@item show print raw-values
11472Show whether to print values in raw form.
11473
c906108c 11474@item set print sevenbit-strings on
4644b6e3
EZ
11475@cindex eight-bit characters in strings
11476@cindex octal escapes in strings
c906108c
SS
11477Print using only seven-bit characters; if this option is set,
11478@value{GDBN} displays any eight-bit characters (in strings or
11479character values) using the notation @code{\}@var{nnn}. This setting is
11480best if you are working in English (@sc{ascii}) and you use the
11481high-order bit of characters as a marker or ``meta'' bit.
11482
11483@item set print sevenbit-strings off
11484Print full eight-bit characters. This allows the use of more
11485international character sets, and is the default.
11486
c906108c
SS
11487@item show print sevenbit-strings
11488Show whether or not @value{GDBN} is printing only seven-bit characters.
11489
3345721a 11490@anchor{set print union}
c906108c 11491@item set print union on
4644b6e3 11492@cindex unions in structures, printing
9c16f35a
EZ
11493Tell @value{GDBN} to print unions which are contained in structures
11494and other unions. This is the default setting.
c906108c
SS
11495
11496@item set print union off
9c16f35a
EZ
11497Tell @value{GDBN} not to print unions which are contained in
11498structures and other unions. @value{GDBN} will print @code{"@{...@}"}
11499instead.
c906108c 11500
c906108c
SS
11501@item show print union
11502Ask @value{GDBN} whether or not it will print unions which are contained in
9c16f35a 11503structures and other unions.
c906108c
SS
11504
11505For example, given the declarations
11506
11507@smallexample
11508typedef enum @{Tree, Bug@} Species;
11509typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5d161b24 11510typedef enum @{Caterpillar, Cocoon, Butterfly@}
c906108c
SS
11511 Bug_forms;
11512
11513struct thing @{
11514 Species it;
11515 union @{
11516 Tree_forms tree;
11517 Bug_forms bug;
11518 @} form;
11519@};
11520
11521struct thing foo = @{Tree, @{Acorn@}@};
11522@end smallexample
11523
11524@noindent
11525with @code{set print union on} in effect @samp{p foo} would print
11526
11527@smallexample
11528$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
11529@end smallexample
11530
11531@noindent
11532and with @code{set print union off} in effect it would print
11533
11534@smallexample
11535$1 = @{it = Tree, form = @{...@}@}
11536@end smallexample
9c16f35a
EZ
11537
11538@noindent
11539@code{set print union} affects programs written in C-like languages
11540and in Pascal.
c906108c
SS
11541@end table
11542
c906108c
SS
11543@need 1000
11544@noindent
b37052ae 11545These settings are of interest when debugging C@t{++} programs:
c906108c
SS
11546
11547@table @code
4644b6e3 11548@cindex demangling C@t{++} names
c906108c
SS
11549@item set print demangle
11550@itemx set print demangle on
b37052ae 11551Print C@t{++} names in their source form rather than in the encoded
c906108c 11552(``mangled'') form passed to the assembler and linker for type-safe
d4f3574e 11553linkage. The default is on.
c906108c 11554
c906108c 11555@item show print demangle
b37052ae 11556Show whether C@t{++} names are printed in mangled or demangled form.
c906108c 11557
c906108c
SS
11558@item set print asm-demangle
11559@itemx set print asm-demangle on
b37052ae 11560Print C@t{++} names in their source form rather than their mangled form, even
c906108c
SS
11561in assembler code printouts such as instruction disassemblies.
11562The default is off.
11563
c906108c 11564@item show print asm-demangle
b37052ae 11565Show whether C@t{++} names in assembly listings are printed in mangled
c906108c
SS
11566or demangled form.
11567
b37052ae
EZ
11568@cindex C@t{++} symbol decoding style
11569@cindex symbol decoding style, C@t{++}
a8f24a35 11570@kindex set demangle-style
c906108c 11571@item set demangle-style @var{style}
041be526
SM
11572Choose among several encoding schemes used by different compilers to represent
11573C@t{++} names. If you omit @var{style}, you will see a list of possible
11574formats. The default value is @var{auto}, which lets @value{GDBN} choose a
11575decoding style by inspecting your program.
c906108c 11576
c906108c 11577@item show demangle-style
b37052ae 11578Display the encoding style currently in use for decoding C@t{++} symbols.
c906108c 11579
3345721a 11580@anchor{set print object}
c906108c
SS
11581@item set print object
11582@itemx set print object on
4644b6e3 11583@cindex derived type of an object, printing
9c16f35a 11584@cindex display derived types
c906108c
SS
11585When displaying a pointer to an object, identify the @emph{actual}
11586(derived) type of the object rather than the @emph{declared} type, using
625c0d47
TT
11587the virtual function table. Note that the virtual function table is
11588required---this feature can only work for objects that have run-time
11589type identification; a single virtual method in the object's declared
8264ba82
AG
11590type is sufficient. Note that this setting is also taken into account when
11591working with variable objects via MI (@pxref{GDB/MI}).
c906108c
SS
11592
11593@item set print object off
11594Display only the declared type of objects, without reference to the
11595virtual function table. This is the default setting.
11596
c906108c
SS
11597@item show print object
11598Show whether actual, or declared, object types are displayed.
11599
3345721a 11600@anchor{set print static-members}
c906108c
SS
11601@item set print static-members
11602@itemx set print static-members on
4644b6e3 11603@cindex static members of C@t{++} objects
b37052ae 11604Print static members when displaying a C@t{++} object. The default is on.
c906108c
SS
11605
11606@item set print static-members off
b37052ae 11607Do not print static members when displaying a C@t{++} object.
c906108c 11608
c906108c 11609@item show print static-members
9c16f35a
EZ
11610Show whether C@t{++} static members are printed or not.
11611
11612@item set print pascal_static-members
11613@itemx set print pascal_static-members on
d3e8051b
EZ
11614@cindex static members of Pascal objects
11615@cindex Pascal objects, static members display
9c16f35a
EZ
11616Print static members when displaying a Pascal object. The default is on.
11617
11618@item set print pascal_static-members off
11619Do not print static members when displaying a Pascal object.
11620
11621@item show print pascal_static-members
11622Show whether Pascal static members are printed or not.
c906108c
SS
11623
11624@c These don't work with HP ANSI C++ yet.
3345721a 11625@anchor{set print vtbl}
c906108c
SS
11626@item set print vtbl
11627@itemx set print vtbl on
4644b6e3 11628@cindex pretty print C@t{++} virtual function tables
9c16f35a
EZ
11629@cindex virtual functions (C@t{++}) display
11630@cindex VTBL display
b37052ae 11631Pretty print C@t{++} virtual function tables. The default is off.
c906108c 11632(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 11633ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
11634
11635@item set print vtbl off
b37052ae 11636Do not pretty print C@t{++} virtual function tables.
c906108c 11637
c906108c 11638@item show print vtbl
b37052ae 11639Show whether C@t{++} virtual function tables are pretty printed, or not.
c906108c 11640@end table
c906108c 11641
4c374409
JK
11642@node Pretty Printing
11643@section Pretty Printing
11644
11645@value{GDBN} provides a mechanism to allow pretty-printing of values using
11646Python code. It greatly simplifies the display of complex objects. This
11647mechanism works for both MI and the CLI.
11648
7b51bc51
DE
11649@menu
11650* Pretty-Printer Introduction:: Introduction to pretty-printers
11651* Pretty-Printer Example:: An example pretty-printer
11652* Pretty-Printer Commands:: Pretty-printer commands
11653@end menu
11654
11655@node Pretty-Printer Introduction
11656@subsection Pretty-Printer Introduction
11657
11658When @value{GDBN} prints a value, it first sees if there is a pretty-printer
11659registered for the value. If there is then @value{GDBN} invokes the
11660pretty-printer to print the value. Otherwise the value is printed normally.
11661
11662Pretty-printers are normally named. This makes them easy to manage.
11663The @samp{info pretty-printer} command will list all the installed
11664pretty-printers with their names.
11665If a pretty-printer can handle multiple data types, then its
11666@dfn{subprinters} are the printers for the individual data types.
11667Each such subprinter has its own name.
4e04c971 11668The format of the name is @var{printer-name};@var{subprinter-name}.
7b51bc51
DE
11669
11670Pretty-printers are installed by @dfn{registering} them with @value{GDBN}.
11671Typically they are automatically loaded and registered when the corresponding
11672debug information is loaded, thus making them available without having to
11673do anything special.
11674
11675There are three places where a pretty-printer can be registered.
11676
11677@itemize @bullet
11678@item
11679Pretty-printers registered globally are available when debugging
11680all inferiors.
11681
11682@item
11683Pretty-printers registered with a program space are available only
11684when debugging that program.
11685@xref{Progspaces In Python}, for more details on program spaces in Python.
11686
11687@item
11688Pretty-printers registered with an objfile are loaded and unloaded
11689with the corresponding objfile (e.g., shared library).
11690@xref{Objfiles In Python}, for more details on objfiles in Python.
11691@end itemize
11692
11693@xref{Selecting Pretty-Printers}, for further information on how
11694pretty-printers are selected,
11695
11696@xref{Writing a Pretty-Printer}, for implementing pretty printers
11697for new types.
11698
11699@node Pretty-Printer Example
11700@subsection Pretty-Printer Example
11701
11702Here is how a C@t{++} @code{std::string} looks without a pretty-printer:
4c374409
JK
11703
11704@smallexample
11705(@value{GDBP}) print s
11706$1 = @{
11707 static npos = 4294967295,
11708 _M_dataplus = @{
11709 <std::allocator<char>> = @{
11710 <__gnu_cxx::new_allocator<char>> = @{
11711 <No data fields>@}, <No data fields>
11712 @},
11713 members of std::basic_string<char, std::char_traits<char>,
11714 std::allocator<char> >::_Alloc_hider:
11715 _M_p = 0x804a014 "abcd"
11716 @}
11717@}
11718@end smallexample
11719
11720With a pretty-printer for @code{std::string} only the contents are printed:
11721
11722@smallexample
11723(@value{GDBP}) print s
11724$2 = "abcd"
11725@end smallexample
11726
7b51bc51
DE
11727@node Pretty-Printer Commands
11728@subsection Pretty-Printer Commands
11729@cindex pretty-printer commands
11730
11731@table @code
11732@kindex info pretty-printer
11733@item info pretty-printer [@var{object-regexp} [@var{name-regexp}]]
11734Print the list of installed pretty-printers.
11735This includes disabled pretty-printers, which are marked as such.
11736
11737@var{object-regexp} is a regular expression matching the objects
11738whose pretty-printers to list.
11739Objects can be @code{global}, the program space's file
11740(@pxref{Progspaces In Python}),
11741and the object files within that program space (@pxref{Objfiles In Python}).
11742@xref{Selecting Pretty-Printers}, for details on how @value{GDBN}
11743looks up a printer from these three objects.
11744
11745@var{name-regexp} is a regular expression matching the name of the printers
11746to list.
11747
11748@kindex disable pretty-printer
11749@item disable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
11750Disable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
11751A disabled pretty-printer is not forgotten, it may be enabled again later.
11752
11753@kindex enable pretty-printer
11754@item enable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
11755Enable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
11756@end table
11757
11758Example:
11759
11760Suppose we have three pretty-printers installed: one from library1.so
11761named @code{foo} that prints objects of type @code{foo}, and
11762another from library2.so named @code{bar} that prints two types of objects,
11763@code{bar1} and @code{bar2}.
11764
11765@smallexample
11766(gdb) info pretty-printer
11767library1.so:
11768 foo
11769library2.so:
11770 bar
11771 bar1
11772 bar2
11773(gdb) info pretty-printer library2
11774library2.so:
11775 bar
11776 bar1
11777 bar2
11778(gdb) disable pretty-printer library1
117791 printer disabled
117802 of 3 printers enabled
11781(gdb) info pretty-printer
11782library1.so:
11783 foo [disabled]
11784library2.so:
11785 bar
11786 bar1
11787 bar2
088a96da 11788(gdb) disable pretty-printer library2 bar;bar1
7b51bc51
DE
117891 printer disabled
117901 of 3 printers enabled
11791(gdb) info pretty-printer library2
11792library1.so:
11793 foo [disabled]
11794library2.so:
11795 bar
11796 bar1 [disabled]
11797 bar2
11798(gdb) disable pretty-printer library2 bar
117991 printer disabled
118000 of 3 printers enabled
11801(gdb) info pretty-printer library2
11802library1.so:
11803 foo [disabled]
11804library2.so:
11805 bar [disabled]
11806 bar1 [disabled]
11807 bar2
11808@end smallexample
11809
11810Note that for @code{bar} the entire printer can be disabled,
11811as can each individual subprinter.
4c374409 11812
d8edc8b7
PW
11813Printing values and frame arguments is done by default using
11814the enabled pretty printers.
11815
11816The print option @code{-raw-values} and @value{GDBN} setting
11817@code{set print raw-values} (@pxref{set print raw-values}) can be
11818used to print values without applying the enabled pretty printers.
11819
11820Similarly, the backtrace option @code{-raw-frame-arguments} and
11821@value{GDBN} setting @code{set print raw-frame-arguments}
11822(@pxref{set print raw-frame-arguments}) can be used to ignore the
11823enabled pretty printers when printing frame argument values.
11824
6d2ebf8b 11825@node Value History
79a6e687 11826@section Value History
c906108c
SS
11827
11828@cindex value history
9c16f35a 11829@cindex history of values printed by @value{GDBN}
5d161b24
DB
11830Values printed by the @code{print} command are saved in the @value{GDBN}
11831@dfn{value history}. This allows you to refer to them in other expressions.
11832Values are kept until the symbol table is re-read or discarded
11833(for example with the @code{file} or @code{symbol-file} commands).
11834When the symbol table changes, the value history is discarded,
11835since the values may contain pointers back to the types defined in the
c906108c
SS
11836symbol table.
11837
11838@cindex @code{$}
11839@cindex @code{$$}
11840@cindex history number
11841The values printed are given @dfn{history numbers} by which you can
11842refer to them. These are successive integers starting with one.
11843@code{print} shows you the history number assigned to a value by
11844printing @samp{$@var{num} = } before the value; here @var{num} is the
11845history number.
11846
11847To refer to any previous value, use @samp{$} followed by the value's
11848history number. The way @code{print} labels its output is designed to
11849remind you of this. Just @code{$} refers to the most recent value in
11850the history, and @code{$$} refers to the value before that.
11851@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
11852is the value just prior to @code{$$}, @code{$$1} is equivalent to
11853@code{$$}, and @code{$$0} is equivalent to @code{$}.
11854
11855For example, suppose you have just printed a pointer to a structure and
11856want to see the contents of the structure. It suffices to type
11857
474c8240 11858@smallexample
c906108c 11859p *$
474c8240 11860@end smallexample
c906108c
SS
11861
11862If you have a chain of structures where the component @code{next} points
11863to the next one, you can print the contents of the next one with this:
11864
474c8240 11865@smallexample
c906108c 11866p *$.next
474c8240 11867@end smallexample
c906108c
SS
11868
11869@noindent
11870You can print successive links in the chain by repeating this
11871command---which you can do by just typing @key{RET}.
11872
11873Note that the history records values, not expressions. If the value of
11874@code{x} is 4 and you type these commands:
11875
474c8240 11876@smallexample
c906108c
SS
11877print x
11878set x=5
474c8240 11879@end smallexample
c906108c
SS
11880
11881@noindent
11882then the value recorded in the value history by the @code{print} command
11883remains 4 even though the value of @code{x} has changed.
11884
11885@table @code
11886@kindex show values
11887@item show values
11888Print the last ten values in the value history, with their item numbers.
11889This is like @samp{p@ $$9} repeated ten times, except that @code{show
11890values} does not change the history.
11891
11892@item show values @var{n}
11893Print ten history values centered on history item number @var{n}.
11894
11895@item show values +
11896Print ten history values just after the values last printed. If no more
11897values are available, @code{show values +} produces no display.
11898@end table
11899
11900Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
11901same effect as @samp{show values +}.
11902
6d2ebf8b 11903@node Convenience Vars
79a6e687 11904@section Convenience Variables
c906108c
SS
11905
11906@cindex convenience variables
9c16f35a 11907@cindex user-defined variables
c906108c
SS
11908@value{GDBN} provides @dfn{convenience variables} that you can use within
11909@value{GDBN} to hold on to a value and refer to it later. These variables
11910exist entirely within @value{GDBN}; they are not part of your program, and
11911setting a convenience variable has no direct effect on further execution
11912of your program. That is why you can use them freely.
11913
11914Convenience variables are prefixed with @samp{$}. Any name preceded by
11915@samp{$} can be used for a convenience variable, unless it is one of
d4f3574e 11916the predefined machine-specific register names (@pxref{Registers, ,Registers}).
c906108c 11917(Value history references, in contrast, are @emph{numbers} preceded
79a6e687 11918by @samp{$}. @xref{Value History, ,Value History}.)
c906108c
SS
11919
11920You can save a value in a convenience variable with an assignment
11921expression, just as you would set a variable in your program.
11922For example:
11923
474c8240 11924@smallexample
c906108c 11925set $foo = *object_ptr
474c8240 11926@end smallexample
c906108c
SS
11927
11928@noindent
11929would save in @code{$foo} the value contained in the object pointed to by
11930@code{object_ptr}.
11931
11932Using a convenience variable for the first time creates it, but its
11933value is @code{void} until you assign a new value. You can alter the
11934value with another assignment at any time.
11935
11936Convenience variables have no fixed types. You can assign a convenience
11937variable any type of value, including structures and arrays, even if
11938that variable already has a value of a different type. The convenience
11939variable, when used as an expression, has the type of its current value.
11940
11941@table @code
11942@kindex show convenience
f47f77df 11943@cindex show all user variables and functions
c906108c 11944@item show convenience
f47f77df
DE
11945Print a list of convenience variables used so far, and their values,
11946as well as a list of the convenience functions.
d4f3574e 11947Abbreviated @code{show conv}.
53e5f3cf
AS
11948
11949@kindex init-if-undefined
11950@cindex convenience variables, initializing
11951@item init-if-undefined $@var{variable} = @var{expression}
11952Set a convenience variable if it has not already been set. This is useful
11953for user-defined commands that keep some state. It is similar, in concept,
11954to using local static variables with initializers in C (except that
11955convenience variables are global). It can also be used to allow users to
11956override default values used in a command script.
11957
11958If the variable is already defined then the expression is not evaluated so
11959any side-effects do not occur.
c906108c
SS
11960@end table
11961
11962One of the ways to use a convenience variable is as a counter to be
11963incremented or a pointer to be advanced. For example, to print
11964a field from successive elements of an array of structures:
11965
474c8240 11966@smallexample
c906108c
SS
11967set $i = 0
11968print bar[$i++]->contents
474c8240 11969@end smallexample
c906108c 11970
d4f3574e
SS
11971@noindent
11972Repeat that command by typing @key{RET}.
c906108c
SS
11973
11974Some convenience variables are created automatically by @value{GDBN} and given
11975values likely to be useful.
11976
11977@table @code
41afff9a 11978@vindex $_@r{, convenience variable}
c906108c
SS
11979@item $_
11980The variable @code{$_} is automatically set by the @code{x} command to
79a6e687 11981the last address examined (@pxref{Memory, ,Examining Memory}). Other
c906108c
SS
11982commands which provide a default address for @code{x} to examine also
11983set @code{$_} to that address; these commands include @code{info line}
11984and @code{info breakpoint}. The type of @code{$_} is @code{void *}
11985except when set by the @code{x} command, in which case it is a pointer
11986to the type of @code{$__}.
11987
41afff9a 11988@vindex $__@r{, convenience variable}
c906108c
SS
11989@item $__
11990The variable @code{$__} is automatically set by the @code{x} command
11991to the value found in the last address examined. Its type is chosen
11992to match the format in which the data was printed.
11993
11994@item $_exitcode
41afff9a 11995@vindex $_exitcode@r{, convenience variable}
0c557179
SDJ
11996When the program being debugged terminates normally, @value{GDBN}
11997automatically sets this variable to the exit code of the program, and
11998resets @code{$_exitsignal} to @code{void}.
11999
12000@item $_exitsignal
12001@vindex $_exitsignal@r{, convenience variable}
12002When the program being debugged dies due to an uncaught signal,
12003@value{GDBN} automatically sets this variable to that signal's number,
12004and resets @code{$_exitcode} to @code{void}.
12005
12006To distinguish between whether the program being debugged has exited
12007(i.e., @code{$_exitcode} is not @code{void}) or signalled (i.e.,
12008@code{$_exitsignal} is not @code{void}), the convenience function
12009@code{$_isvoid} can be used (@pxref{Convenience Funs,, Convenience
12010Functions}). For example, considering the following source code:
12011
12012@smallexample
12013#include <signal.h>
12014
12015int
12016main (int argc, char *argv[])
12017@{
12018 raise (SIGALRM);
12019 return 0;
12020@}
12021@end smallexample
12022
12023A valid way of telling whether the program being debugged has exited
12024or signalled would be:
12025
12026@smallexample
12027(@value{GDBP}) define has_exited_or_signalled
12028Type commands for definition of ``has_exited_or_signalled''.
12029End with a line saying just ``end''.
12030>if $_isvoid ($_exitsignal)
12031 >echo The program has exited\n
12032 >else
12033 >echo The program has signalled\n
12034 >end
12035>end
12036(@value{GDBP}) run
12037Starting program:
12038
12039Program terminated with signal SIGALRM, Alarm clock.
12040The program no longer exists.
12041(@value{GDBP}) has_exited_or_signalled
12042The program has signalled
12043@end smallexample
12044
12045As can be seen, @value{GDBN} correctly informs that the program being
12046debugged has signalled, since it calls @code{raise} and raises a
12047@code{SIGALRM} signal. If the program being debugged had not called
12048@code{raise}, then @value{GDBN} would report a normal exit:
12049
12050@smallexample
12051(@value{GDBP}) has_exited_or_signalled
12052The program has exited
12053@end smallexample
4aa995e1 12054
72f1fe8a
TT
12055@item $_exception
12056The variable @code{$_exception} is set to the exception object being
12057thrown at an exception-related catchpoint. @xref{Set Catchpoints}.
12058
37f6a7f4
TT
12059@item $_ada_exception
12060The variable @code{$_ada_exception} is set to the address of the
12061exception being caught or thrown at an Ada exception-related
12062catchpoint. @xref{Set Catchpoints}.
12063
62e5f89c
SDJ
12064@item $_probe_argc
12065@itemx $_probe_arg0@dots{}$_probe_arg11
12066Arguments to a static probe. @xref{Static Probe Points}.
12067
0fb4aa4b
PA
12068@item $_sdata
12069@vindex $_sdata@r{, inspect, convenience variable}
12070The variable @code{$_sdata} contains extra collected static tracepoint
12071data. @xref{Tracepoint Actions,,Tracepoint Action Lists}. Note that
12072@code{$_sdata} could be empty, if not inspecting a trace buffer, or
12073if extra static tracepoint data has not been collected.
12074
4aa995e1
PA
12075@item $_siginfo
12076@vindex $_siginfo@r{, convenience variable}
ec7e75e7
PP
12077The variable @code{$_siginfo} contains extra signal information
12078(@pxref{extra signal information}). Note that @code{$_siginfo}
12079could be empty, if the application has not yet received any signals.
12080For example, it will be empty before you execute the @code{run} command.
711e434b
PM
12081
12082@item $_tlb
12083@vindex $_tlb@r{, convenience variable}
12084The variable @code{$_tlb} is automatically set when debugging
12085applications running on MS-Windows in native mode or connected to
7734102d 12086gdbserver that supports the @code{qGetTIBAddr} request.
711e434b
PM
12087@xref{General Query Packets}.
12088This variable contains the address of the thread information block.
12089
e3940304 12090@item $_inferior
65c574f6
PA
12091The number of the current inferior. @xref{Inferiors Connections and
12092Programs, ,Debugging Multiple Inferiors Connections and Programs}.
e3940304 12093
5d5658a1
PA
12094@item $_thread
12095The thread number of the current thread. @xref{thread numbers}.
12096
663f6d42
PA
12097@item $_gthread
12098The global number of the current thread. @xref{global thread numbers}.
12099
7734102d
EZ
12100@item $_gdb_major
12101@itemx $_gdb_minor
12102@vindex $_gdb_major@r{, convenience variable}
12103@vindex $_gdb_minor@r{, convenience variable}
12104The major and minor version numbers of the running @value{GDBN}.
12105Development snapshots and pretest versions have their minor version
12106incremented by one; thus, @value{GDBN} pretest 9.11.90 will produce
12107the value 12 for @code{$_gdb_minor}. These variables allow you to
12108write scripts that work with different versions of @value{GDBN}
12109without errors caused by features unavailable in some of those
12110versions.
e2c52041
PW
12111
12112@item $_shell_exitcode
12113@itemx $_shell_exitsignal
12114@vindex $_shell_exitcode@r{, convenience variable}
12115@vindex $_shell_exitsignal@r{, convenience variable}
12116@cindex shell command, exit code
12117@cindex shell command, exit signal
12118@cindex exit status of shell commands
12119@value{GDBN} commands such as @code{shell} and @code{|} are launching
12120shell commands. When a launched command terminates, @value{GDBN}
12121automatically maintains the variables @code{$_shell_exitcode}
12122and @code{$_shell_exitsignal} according to the exit status of the last
12123launched command. These variables are set and used similarly to
12124the variables @code{$_exitcode} and @code{$_exitsignal}.
12125
c906108c
SS
12126@end table
12127
a72c3253
DE
12128@node Convenience Funs
12129@section Convenience Functions
12130
bc3b79fd
TJB
12131@cindex convenience functions
12132@value{GDBN} also supplies some @dfn{convenience functions}. These
12133have a syntax similar to convenience variables. A convenience
12134function can be used in an expression just like an ordinary function;
12135however, a convenience function is implemented internally to
12136@value{GDBN}.
12137
a280dbd1
SDJ
12138These functions do not require @value{GDBN} to be configured with
12139@code{Python} support, which means that they are always available.
12140
12141@table @code
12142
12143@item $_isvoid (@var{expr})
12144@findex $_isvoid@r{, convenience function}
12145Return one if the expression @var{expr} is @code{void}. Otherwise it
12146returns zero.
12147
12148A @code{void} expression is an expression where the type of the result
12149is @code{void}. For example, you can examine a convenience variable
12150(see @ref{Convenience Vars,, Convenience Variables}) to check whether
12151it is @code{void}:
12152
12153@smallexample
12154(@value{GDBP}) print $_exitcode
12155$1 = void
12156(@value{GDBP}) print $_isvoid ($_exitcode)
12157$2 = 1
12158(@value{GDBP}) run
12159Starting program: ./a.out
12160[Inferior 1 (process 29572) exited normally]
12161(@value{GDBP}) print $_exitcode
12162$3 = 0
12163(@value{GDBP}) print $_isvoid ($_exitcode)
12164$4 = 0
12165@end smallexample
12166
12167In the example above, we used @code{$_isvoid} to check whether
12168@code{$_exitcode} is @code{void} before and after the execution of the
12169program being debugged. Before the execution there is no exit code to
12170be examined, therefore @code{$_exitcode} is @code{void}. After the
12171execution the program being debugged returned zero, therefore
12172@code{$_exitcode} is zero, which means that it is not @code{void}
12173anymore.
12174
12175The @code{void} expression can also be a call of a function from the
12176program being debugged. For example, given the following function:
12177
12178@smallexample
12179void
12180foo (void)
12181@{
12182@}
12183@end smallexample
12184
12185The result of calling it inside @value{GDBN} is @code{void}:
12186
12187@smallexample
12188(@value{GDBP}) print foo ()
12189$1 = void
12190(@value{GDBP}) print $_isvoid (foo ())
12191$2 = 1
12192(@value{GDBP}) set $v = foo ()
12193(@value{GDBP}) print $v
12194$3 = void
12195(@value{GDBP}) print $_isvoid ($v)
12196$4 = 1
12197@end smallexample
12198
aed61d02
PW
12199@item $_gdb_setting_str (@var{setting})
12200@findex $_gdb_setting_str@r{, convenience function}
12201Return the value of the @value{GDBN} @var{setting} as a string.
12202@var{setting} is any setting that can be used in a @code{set} or
12203@code{show} command (@pxref{Controlling GDB}).
12204
12205@smallexample
12206(@value{GDBP}) show print frame-arguments
12207Printing of non-scalar frame arguments is "scalars".
12208(@value{GDBP}) p $_gdb_setting_str("print frame-arguments")
12209$1 = "scalars"
12210(@value{GDBP}) p $_gdb_setting_str("height")
12211$2 = "30"
12212(@value{GDBP})
12213@end smallexample
12214
12215@item $_gdb_setting (@var{setting})
12216@findex $_gdb_setting@r{, convenience function}
12217Return the value of the @value{GDBN} @var{setting}.
12218The type of the returned value depends on the setting.
12219
12220The value type for boolean and auto boolean settings is @code{int}.
12221The boolean values @code{off} and @code{on} are converted to
12222the integer values @code{0} and @code{1}. The value @code{auto} is
12223converted to the value @code{-1}.
12224
12225The value type for integer settings is either @code{unsigned int}
12226or @code{int}, depending on the setting.
12227
12228Some integer settings accept an @code{unlimited} value.
12229Depending on the setting, the @code{set} command also accepts
12230the value @code{0} or the value @code{@minus{}1} as a synonym for
12231@code{unlimited}.
12232For example, @code{set height unlimited} is equivalent to
12233@code{set height 0}.
12234
12235Some other settings that accept the @code{unlimited} value
12236use the value @code{0} to literally mean zero.
12237For example, @code{set history size 0} indicates to not
12238record any @value{GDBN} commands in the command history.
12239For such settings, @code{@minus{}1} is the synonym
12240for @code{unlimited}.
12241
12242See the documentation of the corresponding @code{set} command for
12243the numerical value equivalent to @code{unlimited}.
12244
12245The @code{$_gdb_setting} function converts the unlimited value
12246to a @code{0} or a @code{@minus{}1} value according to what the
12247@code{set} command uses.
12248
12249@smallexample
12250@group
12251(@value{GDBP}) p $_gdb_setting_str("height")
12252$1 = "30"
12253(@value{GDBP}) p $_gdb_setting("height")
12254$2 = 30
12255(@value{GDBP}) set height unlimited
12256(@value{GDBP}) p $_gdb_setting_str("height")
12257$3 = "unlimited"
12258(@value{GDBP}) p $_gdb_setting("height")
12259$4 = 0
12260@end group
12261@group
12262(@value{GDBP}) p $_gdb_setting_str("history size")
12263$5 = "unlimited"
12264(@value{GDBP}) p $_gdb_setting("history size")
12265$6 = -1
12266(@value{GDBP}) p $_gdb_setting_str("disassemble-next-line")
12267$7 = "auto"
12268(@value{GDBP}) p $_gdb_setting("disassemble-next-line")
12269$8 = -1
12270(@value{GDBP})
12271@end group
12272@end smallexample
12273
12274Other setting types (enum, filename, optional filename, string, string noescape)
12275are returned as string values.
12276
12277
12278@item $_gdb_maint_setting_str (@var{setting})
12279@findex $_gdb_maint_setting_str@r{, convenience function}
12280Like the @code{$_gdb_setting_str} function, but works with
12281@code{maintenance set} variables.
12282
12283@item $_gdb_maint_setting (@var{setting})
12284@findex $_gdb_maint_setting@r{, convenience function}
12285Like the @code{$_gdb_setting} function, but works with
12286@code{maintenance set} variables.
12287
a280dbd1
SDJ
12288@end table
12289
aed61d02 12290The following functions require @value{GDBN} to be configured with
a72c3253
DE
12291@code{Python} support.
12292
12293@table @code
12294
12295@item $_memeq(@var{buf1}, @var{buf2}, @var{length})
12296@findex $_memeq@r{, convenience function}
12297Returns one if the @var{length} bytes at the addresses given by
12298@var{buf1} and @var{buf2} are equal.
12299Otherwise it returns zero.
12300
12301@item $_regex(@var{str}, @var{regex})
12302@findex $_regex@r{, convenience function}
12303Returns one if the string @var{str} matches the regular expression
12304@var{regex}. Otherwise it returns zero.
12305The syntax of the regular expression is that specified by @code{Python}'s
12306regular expression support.
12307
12308@item $_streq(@var{str1}, @var{str2})
12309@findex $_streq@r{, convenience function}
12310Returns one if the strings @var{str1} and @var{str2} are equal.
12311Otherwise it returns zero.
12312
12313@item $_strlen(@var{str})
12314@findex $_strlen@r{, convenience function}
12315Returns the length of string @var{str}.
12316
faa42425
DE
12317@item $_caller_is(@var{name}@r{[}, @var{number_of_frames}@r{]})
12318@findex $_caller_is@r{, convenience function}
12319Returns one if the calling function's name is equal to @var{name}.
12320Otherwise it returns zero.
12321
12322If the optional argument @var{number_of_frames} is provided,
12323it is the number of frames up in the stack to look.
12324The default is 1.
12325
12326Example:
12327
12328@smallexample
12329(gdb) backtrace
12330#0 bottom_func ()
12331 at testsuite/gdb.python/py-caller-is.c:21
12332#1 0x00000000004005a0 in middle_func ()
12333 at testsuite/gdb.python/py-caller-is.c:27
12334#2 0x00000000004005ab in top_func ()
12335 at testsuite/gdb.python/py-caller-is.c:33
12336#3 0x00000000004005b6 in main ()
12337 at testsuite/gdb.python/py-caller-is.c:39
12338(gdb) print $_caller_is ("middle_func")
12339$1 = 1
12340(gdb) print $_caller_is ("top_func", 2)
12341$1 = 1
12342@end smallexample
12343
12344@item $_caller_matches(@var{regexp}@r{[}, @var{number_of_frames}@r{]})
12345@findex $_caller_matches@r{, convenience function}
12346Returns one if the calling function's name matches the regular expression
12347@var{regexp}. Otherwise it returns zero.
12348
12349If the optional argument @var{number_of_frames} is provided,
12350it is the number of frames up in the stack to look.
12351The default is 1.
12352
12353@item $_any_caller_is(@var{name}@r{[}, @var{number_of_frames}@r{]})
12354@findex $_any_caller_is@r{, convenience function}
12355Returns one if any calling function's name is equal to @var{name}.
12356Otherwise it returns zero.
12357
12358If the optional argument @var{number_of_frames} is provided,
12359it is the number of frames up in the stack to look.
12360The default is 1.
12361
12362This function differs from @code{$_caller_is} in that this function
12363checks all stack frames from the immediate caller to the frame specified
12364by @var{number_of_frames}, whereas @code{$_caller_is} only checks the
12365frame specified by @var{number_of_frames}.
12366
12367@item $_any_caller_matches(@var{regexp}@r{[}, @var{number_of_frames}@r{]})
12368@findex $_any_caller_matches@r{, convenience function}
12369Returns one if any calling function's name matches the regular expression
12370@var{regexp}. Otherwise it returns zero.
12371
12372If the optional argument @var{number_of_frames} is provided,
12373it is the number of frames up in the stack to look.
12374The default is 1.
12375
12376This function differs from @code{$_caller_matches} in that this function
12377checks all stack frames from the immediate caller to the frame specified
12378by @var{number_of_frames}, whereas @code{$_caller_matches} only checks the
12379frame specified by @var{number_of_frames}.
12380
f2f3ccb9
SM
12381@item $_as_string(@var{value})
12382@findex $_as_string@r{, convenience function}
12383Return the string representation of @var{value}.
12384
12385This function is useful to obtain the textual label (enumerator) of an
12386enumeration value. For example, assuming the variable @var{node} is of
12387an enumerated type:
12388
12389@smallexample
12390(gdb) printf "Visiting node of type %s\n", $_as_string(node)
12391Visiting node of type NODE_INTEGER
12392@end smallexample
12393
8bdc1658
AB
12394@item $_cimag(@var{value})
12395@itemx $_creal(@var{value})
12396@findex $_cimag@r{, convenience function}
12397@findex $_creal@r{, convenience function}
12398Return the imaginary (@code{$_cimag}) or real (@code{$_creal}) part of
12399the complex number @var{value}.
12400
12401The type of the imaginary or real part depends on the type of the
12402complex number, e.g., using @code{$_cimag} on a @code{float complex}
12403will return an imaginary part of type @code{float}.
12404
a72c3253
DE
12405@end table
12406
12407@value{GDBN} provides the ability to list and get help on
12408convenience functions.
12409
bc3b79fd
TJB
12410@table @code
12411@item help function
12412@kindex help function
12413@cindex show all convenience functions
12414Print a list of all convenience functions.
12415@end table
12416
6d2ebf8b 12417@node Registers
c906108c
SS
12418@section Registers
12419
12420@cindex registers
12421You can refer to machine register contents, in expressions, as variables
12422with names starting with @samp{$}. The names of registers are different
12423for each machine; use @code{info registers} to see the names used on
12424your machine.
12425
12426@table @code
12427@kindex info registers
12428@item info registers
12429Print the names and values of all registers except floating-point
c85508ee 12430and vector registers (in the selected stack frame).
c906108c
SS
12431
12432@kindex info all-registers
12433@cindex floating point registers
12434@item info all-registers
12435Print the names and values of all registers, including floating-point
c85508ee 12436and vector registers (in the selected stack frame).
c906108c 12437
64cb3757 12438@anchor{info_registers_reggroup}
b67d92b0
SH
12439@item info registers @var{reggroup} @dots{}
12440Print the name and value of the registers in each of the specified
6b92c0d3 12441@var{reggroup}s. The @var{reggroup} can be any of those returned by
b67d92b0
SH
12442@code{maint print reggroups} (@pxref{Maintenance Commands}).
12443
c906108c
SS
12444@item info registers @var{regname} @dots{}
12445Print the @dfn{relativized} value of each specified register @var{regname}.
5d161b24 12446As discussed in detail below, register values are normally relative to
697aa1b7 12447the selected stack frame. The @var{regname} may be any register name valid on
c906108c
SS
12448the machine you are using, with or without the initial @samp{$}.
12449@end table
12450
f5b95c01 12451@anchor{standard registers}
e09f16f9
EZ
12452@cindex stack pointer register
12453@cindex program counter register
12454@cindex process status register
12455@cindex frame pointer register
12456@cindex standard registers
c906108c
SS
12457@value{GDBN} has four ``standard'' register names that are available (in
12458expressions) on most machines---whenever they do not conflict with an
12459architecture's canonical mnemonics for registers. The register names
12460@code{$pc} and @code{$sp} are used for the program counter register and
12461the stack pointer. @code{$fp} is used for a register that contains a
12462pointer to the current stack frame, and @code{$ps} is used for a
12463register that contains the processor status. For example,
12464you could print the program counter in hex with
12465
474c8240 12466@smallexample
c906108c 12467p/x $pc
474c8240 12468@end smallexample
c906108c
SS
12469
12470@noindent
12471or print the instruction to be executed next with
12472
474c8240 12473@smallexample
c906108c 12474x/i $pc
474c8240 12475@end smallexample
c906108c
SS
12476
12477@noindent
12478or add four to the stack pointer@footnote{This is a way of removing
12479one word from the stack, on machines where stacks grow downward in
12480memory (most machines, nowadays). This assumes that the innermost
12481stack frame is selected; setting @code{$sp} is not allowed when other
12482stack frames are selected. To pop entire frames off the stack,
12483regardless of machine architecture, use @code{return};
79a6e687 12484see @ref{Returning, ,Returning from a Function}.} with
c906108c 12485
474c8240 12486@smallexample
c906108c 12487set $sp += 4
474c8240 12488@end smallexample
c906108c
SS
12489
12490Whenever possible, these four standard register names are available on
12491your machine even though the machine has different canonical mnemonics,
12492so long as there is no conflict. The @code{info registers} command
12493shows the canonical names. For example, on the SPARC, @code{info
12494registers} displays the processor status register as @code{$psr} but you
d4f3574e
SS
12495can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
12496is an alias for the @sc{eflags} register.
c906108c
SS
12497
12498@value{GDBN} always considers the contents of an ordinary register as an
12499integer when the register is examined in this way. Some machines have
12500special registers which can hold nothing but floating point; these
12501registers are considered to have floating point values. There is no way
12502to refer to the contents of an ordinary register as floating point value
12503(although you can @emph{print} it as a floating point value with
12504@samp{print/f $@var{regname}}).
12505
12506Some registers have distinct ``raw'' and ``virtual'' data formats. This
12507means that the data format in which the register contents are saved by
12508the operating system is not the same one that your program normally
12509sees. For example, the registers of the 68881 floating point
12510coprocessor are always saved in ``extended'' (raw) format, but all C
12511programs expect to work with ``double'' (virtual) format. In such
5d161b24 12512cases, @value{GDBN} normally works with the virtual format only (the format
c906108c
SS
12513that makes sense for your program), but the @code{info registers} command
12514prints the data in both formats.
12515
36b80e65
EZ
12516@cindex SSE registers (x86)
12517@cindex MMX registers (x86)
12518Some machines have special registers whose contents can be interpreted
12519in several different ways. For example, modern x86-based machines
12520have SSE and MMX registers that can hold several values packed
12521together in several different formats. @value{GDBN} refers to such
12522registers in @code{struct} notation:
12523
12524@smallexample
12525(@value{GDBP}) print $xmm1
12526$1 = @{
12527 v4_float = @{0, 3.43859137e-038, 1.54142831e-044, 1.821688e-044@},
12528 v2_double = @{9.92129282474342e-303, 2.7585945287983262e-313@},
12529 v16_int8 = "\000\000\000\000\3706;\001\v\000\000\000\r\000\000",
12530 v8_int16 = @{0, 0, 14072, 315, 11, 0, 13, 0@},
12531 v4_int32 = @{0, 20657912, 11, 13@},
12532 v2_int64 = @{88725056443645952, 55834574859@},
12533 uint128 = 0x0000000d0000000b013b36f800000000
12534@}
12535@end smallexample
12536
12537@noindent
12538To set values of such registers, you need to tell @value{GDBN} which
12539view of the register you wish to change, as if you were assigning
12540value to a @code{struct} member:
12541
12542@smallexample
12543 (@value{GDBP}) set $xmm1.uint128 = 0x000000000000000000000000FFFFFFFF
12544@end smallexample
12545
c906108c 12546Normally, register values are relative to the selected stack frame
79a6e687 12547(@pxref{Selection, ,Selecting a Frame}). This means that you get the
c906108c
SS
12548value that the register would contain if all stack frames farther in
12549were exited and their saved registers restored. In order to see the
12550true contents of hardware registers, you must select the innermost
12551frame (with @samp{frame 0}).
12552
901461f8
PA
12553@cindex caller-saved registers
12554@cindex call-clobbered registers
12555@cindex volatile registers
12556@cindex <not saved> values
12557Usually ABIs reserve some registers as not needed to be saved by the
12558callee (a.k.a.: ``caller-saved'', ``call-clobbered'' or ``volatile''
12559registers). It may therefore not be possible for @value{GDBN} to know
12560the value a register had before the call (in other words, in the outer
12561frame), if the register value has since been changed by the callee.
12562@value{GDBN} tries to deduce where the inner frame saved
12563(``callee-saved'') registers, from the debug info, unwind info, or the
12564machine code generated by your compiler. If some register is not
12565saved, and @value{GDBN} knows the register is ``caller-saved'' (via
12566its own knowledge of the ABI, or because the debug/unwind info
12567explicitly says the register's value is undefined), @value{GDBN}
12568displays @w{@samp{<not saved>}} as the register's value. With targets
12569that @value{GDBN} has no knowledge of the register saving convention,
12570if a register was not saved by the callee, then its value and location
12571in the outer frame are assumed to be the same of the inner frame.
12572This is usually harmless, because if the register is call-clobbered,
12573the caller either does not care what is in the register after the
12574call, or has code to restore the value that it does care about. Note,
12575however, that if you change such a register in the outer frame, you
12576may also be affecting the inner frame. Also, the more ``outer'' the
12577frame is you're looking at, the more likely a call-clobbered
12578register's value is to be wrong, in the sense that it doesn't actually
12579represent the value the register had just before the call.
c906108c 12580
6d2ebf8b 12581@node Floating Point Hardware
79a6e687 12582@section Floating Point Hardware
c906108c
SS
12583@cindex floating point
12584
12585Depending on the configuration, @value{GDBN} may be able to give
12586you more information about the status of the floating point hardware.
12587
12588@table @code
12589@kindex info float
12590@item info float
12591Display hardware-dependent information about the floating
12592point unit. The exact contents and layout vary depending on the
12593floating point chip. Currently, @samp{info float} is supported on
12594the ARM and x86 machines.
12595@end table
c906108c 12596
e76f1f2e
AC
12597@node Vector Unit
12598@section Vector Unit
12599@cindex vector unit
12600
12601Depending on the configuration, @value{GDBN} may be able to give you
12602more information about the status of the vector unit.
12603
12604@table @code
12605@kindex info vector
12606@item info vector
12607Display information about the vector unit. The exact contents and
12608layout vary depending on the hardware.
12609@end table
12610
721c2651 12611@node OS Information
79a6e687 12612@section Operating System Auxiliary Information
721c2651
EZ
12613@cindex OS information
12614
12615@value{GDBN} provides interfaces to useful OS facilities that can help
12616you debug your program.
12617
b383017d
RM
12618@cindex auxiliary vector
12619@cindex vector, auxiliary
b383017d
RM
12620Some operating systems supply an @dfn{auxiliary vector} to programs at
12621startup. This is akin to the arguments and environment that you
12622specify for a program, but contains a system-dependent variety of
12623binary values that tell system libraries important details about the
12624hardware, operating system, and process. Each value's purpose is
12625identified by an integer tag; the meanings are well-known but system-specific.
12626Depending on the configuration and operating system facilities,
9c16f35a
EZ
12627@value{GDBN} may be able to show you this information. For remote
12628targets, this functionality may further depend on the remote stub's
427c3a89
DJ
12629support of the @samp{qXfer:auxv:read} packet, see
12630@ref{qXfer auxiliary vector read}.
b383017d
RM
12631
12632@table @code
12633@kindex info auxv
12634@item info auxv
12635Display the auxiliary vector of the inferior, which can be either a
e4937fc1 12636live process or a core dump file. @value{GDBN} prints each tag value
b383017d
RM
12637numerically, and also shows names and text descriptions for recognized
12638tags. Some values in the vector are numbers, some bit masks, and some
e4937fc1 12639pointers to strings or other data. @value{GDBN} displays each value in the
b383017d
RM
12640most appropriate form for a recognized tag, and in hexadecimal for
12641an unrecognized tag.
12642@end table
12643
85d4a676
SS
12644On some targets, @value{GDBN} can access operating system-specific
12645information and show it to you. The types of information available
12646will differ depending on the type of operating system running on the
12647target. The mechanism used to fetch the data is described in
12648@ref{Operating System Information}. For remote targets, this
12649functionality depends on the remote stub's support of the
07e059b5
VP
12650@samp{qXfer:osdata:read} packet, see @ref{qXfer osdata read}.
12651
12652@table @code
a61408f8 12653@kindex info os
85d4a676
SS
12654@item info os @var{infotype}
12655
12656Display OS information of the requested type.
a61408f8 12657
85d4a676
SS
12658On @sc{gnu}/Linux, the following values of @var{infotype} are valid:
12659
12660@anchor{linux info os infotypes}
12661@table @code
d33279b3
AT
12662@kindex info os cpus
12663@item cpus
12664Display the list of all CPUs/cores. For each CPU/core, @value{GDBN} prints
12665the available fields from /proc/cpuinfo. For each supported architecture
12666different fields are available. Two common entries are processor which gives
12667CPU number and bogomips; a system constant that is calculated during
12668kernel initialization.
12669
12670@kindex info os files
12671@item files
12672Display the list of open file descriptors on the target. For each
12673file descriptor, @value{GDBN} prints the identifier of the process
12674owning the descriptor, the command of the owning process, the value
12675of the descriptor, and the target of the descriptor.
12676
12677@kindex info os modules
12678@item modules
12679Display the list of all loaded kernel modules on the target. For each
12680module, @value{GDBN} prints the module name, the size of the module in
12681bytes, the number of times the module is used, the dependencies of the
12682module, the status of the module, and the address of the loaded module
12683in memory.
12684
12685@kindex info os msg
12686@item msg
12687Display the list of all System V message queues on the target. For each
12688message queue, @value{GDBN} prints the message queue key, the message
12689queue identifier, the access permissions, the current number of bytes
12690on the queue, the current number of messages on the queue, the processes
12691that last sent and received a message on the queue, the user and group
12692of the owner and creator of the message queue, the times at which a
12693message was last sent and received on the queue, and the time at which
12694the message queue was last changed.
12695
07e059b5 12696@kindex info os processes
85d4a676 12697@item processes
07e059b5 12698Display the list of processes on the target. For each process,
85d4a676
SS
12699@value{GDBN} prints the process identifier, the name of the user, the
12700command corresponding to the process, and the list of processor cores
12701that the process is currently running on. (To understand what these
12702properties mean, for this and the following info types, please consult
12703the general @sc{gnu}/Linux documentation.)
12704
12705@kindex info os procgroups
12706@item procgroups
12707Display the list of process groups on the target. For each process,
12708@value{GDBN} prints the identifier of the process group that it belongs
12709to, the command corresponding to the process group leader, the process
12710identifier, and the command line of the process. The list is sorted
12711first by the process group identifier, then by the process identifier,
12712so that processes belonging to the same process group are grouped together
12713and the process group leader is listed first.
12714
d33279b3
AT
12715@kindex info os semaphores
12716@item semaphores
12717Display the list of all System V semaphore sets on the target. For each
12718semaphore set, @value{GDBN} prints the semaphore set key, the semaphore
12719set identifier, the access permissions, the number of semaphores in the
12720set, the user and group of the owner and creator of the semaphore set,
12721and the times at which the semaphore set was operated upon and changed.
85d4a676
SS
12722
12723@kindex info os shm
12724@item shm
12725Display the list of all System V shared-memory regions on the target.
12726For each shared-memory region, @value{GDBN} prints the region key,
12727the shared-memory identifier, the access permissions, the size of the
12728region, the process that created the region, the process that last
12729attached to or detached from the region, the current number of live
12730attaches to the region, and the times at which the region was last
12731attached to, detach from, and changed.
12732
d33279b3
AT
12733@kindex info os sockets
12734@item sockets
12735Display the list of Internet-domain sockets on the target. For each
12736socket, @value{GDBN} prints the address and port of the local and
12737remote endpoints, the current state of the connection, the creator of
12738the socket, the IP address family of the socket, and the type of the
12739connection.
85d4a676 12740
d33279b3
AT
12741@kindex info os threads
12742@item threads
12743Display the list of threads running on the target. For each thread,
12744@value{GDBN} prints the identifier of the process that the thread
12745belongs to, the command of the process, the thread identifier, and the
12746processor core that it is currently running on. The main thread of a
12747process is not listed.
85d4a676
SS
12748@end table
12749
12750@item info os
12751If @var{infotype} is omitted, then list the possible values for
12752@var{infotype} and the kind of OS information available for each
12753@var{infotype}. If the target does not return a list of possible
12754types, this command will report an error.
07e059b5 12755@end table
721c2651 12756
29e57380 12757@node Memory Region Attributes
79a6e687 12758@section Memory Region Attributes
29e57380
C
12759@cindex memory region attributes
12760
b383017d 12761@dfn{Memory region attributes} allow you to describe special handling
fd79ecee
DJ
12762required by regions of your target's memory. @value{GDBN} uses
12763attributes to determine whether to allow certain types of memory
12764accesses; whether to use specific width accesses; and whether to cache
12765target memory. By default the description of memory regions is
12766fetched from the target (if the current target supports this), but the
12767user can override the fetched regions.
29e57380
C
12768
12769Defined memory regions can be individually enabled and disabled. When a
12770memory region is disabled, @value{GDBN} uses the default attributes when
12771accessing memory in that region. Similarly, if no memory regions have
12772been defined, @value{GDBN} uses the default attributes when accessing
12773all memory.
12774
b383017d 12775When a memory region is defined, it is given a number to identify it;
29e57380
C
12776to enable, disable, or remove a memory region, you specify that number.
12777
12778@table @code
12779@kindex mem
bfac230e 12780@item mem @var{lower} @var{upper} @var{attributes}@dots{}
09d4efe1
EZ
12781Define a memory region bounded by @var{lower} and @var{upper} with
12782attributes @var{attributes}@dots{}, and add it to the list of regions
12783monitored by @value{GDBN}. Note that @var{upper} == 0 is a special
d3e8051b 12784case: it is treated as the target's maximum memory address.
bfac230e 12785(0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
29e57380 12786
fd79ecee
DJ
12787@item mem auto
12788Discard any user changes to the memory regions and use target-supplied
12789regions, if available, or no regions if the target does not support.
12790
29e57380
C
12791@kindex delete mem
12792@item delete mem @var{nums}@dots{}
09d4efe1
EZ
12793Remove memory regions @var{nums}@dots{} from the list of regions
12794monitored by @value{GDBN}.
29e57380
C
12795
12796@kindex disable mem
12797@item disable mem @var{nums}@dots{}
09d4efe1 12798Disable monitoring of memory regions @var{nums}@dots{}.
b383017d 12799A disabled memory region is not forgotten.
29e57380
C
12800It may be enabled again later.
12801
12802@kindex enable mem
12803@item enable mem @var{nums}@dots{}
09d4efe1 12804Enable monitoring of memory regions @var{nums}@dots{}.
29e57380
C
12805
12806@kindex info mem
12807@item info mem
12808Print a table of all defined memory regions, with the following columns
09d4efe1 12809for each region:
29e57380
C
12810
12811@table @emph
12812@item Memory Region Number
12813@item Enabled or Disabled.
b383017d 12814Enabled memory regions are marked with @samp{y}.
29e57380
C
12815Disabled memory regions are marked with @samp{n}.
12816
12817@item Lo Address
12818The address defining the inclusive lower bound of the memory region.
12819
12820@item Hi Address
12821The address defining the exclusive upper bound of the memory region.
12822
12823@item Attributes
12824The list of attributes set for this memory region.
12825@end table
12826@end table
12827
12828
12829@subsection Attributes
12830
b383017d 12831@subsubsection Memory Access Mode
29e57380
C
12832The access mode attributes set whether @value{GDBN} may make read or
12833write accesses to a memory region.
12834
12835While these attributes prevent @value{GDBN} from performing invalid
12836memory accesses, they do nothing to prevent the target system, I/O DMA,
359df76b 12837etc.@: from accessing memory.
29e57380
C
12838
12839@table @code
12840@item ro
12841Memory is read only.
12842@item wo
12843Memory is write only.
12844@item rw
6ca652b0 12845Memory is read/write. This is the default.
29e57380
C
12846@end table
12847
12848@subsubsection Memory Access Size
d3e8051b 12849The access size attribute tells @value{GDBN} to use specific sized
29e57380
C
12850accesses in the memory region. Often memory mapped device registers
12851require specific sized accesses. If no access size attribute is
12852specified, @value{GDBN} may use accesses of any size.
12853
12854@table @code
12855@item 8
12856Use 8 bit memory accesses.
12857@item 16
12858Use 16 bit memory accesses.
12859@item 32
12860Use 32 bit memory accesses.
12861@item 64
12862Use 64 bit memory accesses.
12863@end table
12864
12865@c @subsubsection Hardware/Software Breakpoints
12866@c The hardware/software breakpoint attributes set whether @value{GDBN}
12867@c will use hardware or software breakpoints for the internal breakpoints
12868@c used by the step, next, finish, until, etc. commands.
12869@c
12870@c @table @code
12871@c @item hwbreak
b383017d 12872@c Always use hardware breakpoints
29e57380
C
12873@c @item swbreak (default)
12874@c @end table
12875
12876@subsubsection Data Cache
12877The data cache attributes set whether @value{GDBN} will cache target
12878memory. While this generally improves performance by reducing debug
12879protocol overhead, it can lead to incorrect results because @value{GDBN}
12880does not know about volatile variables or memory mapped device
12881registers.
12882
12883@table @code
12884@item cache
b383017d 12885Enable @value{GDBN} to cache target memory.
6ca652b0
EZ
12886@item nocache
12887Disable @value{GDBN} from caching target memory. This is the default.
29e57380
C
12888@end table
12889
4b5752d0
VP
12890@subsection Memory Access Checking
12891@value{GDBN} can be instructed to refuse accesses to memory that is
12892not explicitly described. This can be useful if accessing such
12893regions has undesired effects for a specific target, or to provide
12894better error checking. The following commands control this behaviour.
12895
12896@table @code
12897@kindex set mem inaccessible-by-default
12898@item set mem inaccessible-by-default [on|off]
12899If @code{on} is specified, make @value{GDBN} treat memory not
12900explicitly described by the memory ranges as non-existent and refuse accesses
12901to such memory. The checks are only performed if there's at least one
12902memory range defined. If @code{off} is specified, make @value{GDBN}
12903treat the memory not explicitly described by the memory ranges as RAM.
56cf5405 12904The default value is @code{on}.
4b5752d0
VP
12905@kindex show mem inaccessible-by-default
12906@item show mem inaccessible-by-default
12907Show the current handling of accesses to unknown memory.
12908@end table
12909
12910
29e57380 12911@c @subsubsection Memory Write Verification
b383017d 12912@c The memory write verification attributes set whether @value{GDBN}
29e57380
C
12913@c will re-reads data after each write to verify the write was successful.
12914@c
12915@c @table @code
12916@c @item verify
12917@c @item noverify (default)
12918@c @end table
12919
16d9dec6 12920@node Dump/Restore Files
79a6e687 12921@section Copy Between Memory and a File
16d9dec6
MS
12922@cindex dump/restore files
12923@cindex append data to a file
12924@cindex dump data to a file
12925@cindex restore data from a file
16d9dec6 12926
df5215a6
JB
12927You can use the commands @code{dump}, @code{append}, and
12928@code{restore} to copy data between target memory and a file. The
12929@code{dump} and @code{append} commands write data to a file, and the
12930@code{restore} command reads data from a file back into the inferior's
cf75d6c3
AB
12931memory. Files may be in binary, Motorola S-record, Intel hex,
12932Tektronix Hex, or Verilog Hex format; however, @value{GDBN} can only
12933append to binary files, and cannot read from Verilog Hex files.
df5215a6
JB
12934
12935@table @code
12936
12937@kindex dump
12938@item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
12939@itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
12940Dump the contents of memory from @var{start_addr} to @var{end_addr},
12941or the value of @var{expr}, to @var{filename} in the given format.
16d9dec6 12942
df5215a6 12943The @var{format} parameter may be any one of:
16d9dec6 12944@table @code
df5215a6
JB
12945@item binary
12946Raw binary form.
12947@item ihex
12948Intel hex format.
12949@item srec
12950Motorola S-record format.
12951@item tekhex
12952Tektronix Hex format.
cf75d6c3
AB
12953@item verilog
12954Verilog Hex format.
df5215a6
JB
12955@end table
12956
12957@value{GDBN} uses the same definitions of these formats as the
12958@sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
12959@var{format} is omitted, @value{GDBN} dumps the data in raw binary
12960form.
12961
12962@kindex append
12963@item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
12964@itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
12965Append the contents of memory from @var{start_addr} to @var{end_addr},
09d4efe1 12966or the value of @var{expr}, to the file @var{filename}, in raw binary form.
df5215a6
JB
12967(@value{GDBN} can only append data to files in raw binary form.)
12968
12969@kindex restore
12970@item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
12971Restore the contents of file @var{filename} into memory. The
12972@code{restore} command can automatically recognize any known @sc{bfd}
12973file format, except for raw binary. To restore a raw binary file you
12974must specify the optional keyword @code{binary} after the filename.
16d9dec6 12975
b383017d 12976If @var{bias} is non-zero, its value will be added to the addresses
16d9dec6
MS
12977contained in the file. Binary files always start at address zero, so
12978they will be restored at address @var{bias}. Other bfd files have
12979a built-in location; they will be restored at offset @var{bias}
12980from that location.
12981
12982If @var{start} and/or @var{end} are non-zero, then only data between
12983file offset @var{start} and file offset @var{end} will be restored.
b383017d 12984These offsets are relative to the addresses in the file, before
16d9dec6
MS
12985the @var{bias} argument is applied.
12986
12987@end table
12988
384ee23f
EZ
12989@node Core File Generation
12990@section How to Produce a Core File from Your Program
12991@cindex dump core from inferior
12992
12993A @dfn{core file} or @dfn{core dump} is a file that records the memory
12994image of a running process and its process status (register values
12995etc.). Its primary use is post-mortem debugging of a program that
12996crashed while it ran outside a debugger. A program that crashes
12997automatically produces a core file, unless this feature is disabled by
12998the user. @xref{Files}, for information on invoking @value{GDBN} in
12999the post-mortem debugging mode.
13000
13001Occasionally, you may wish to produce a core file of the program you
13002are debugging in order to preserve a snapshot of its state.
13003@value{GDBN} has a special command for that.
13004
13005@table @code
13006@kindex gcore
13007@kindex generate-core-file
13008@item generate-core-file [@var{file}]
13009@itemx gcore [@var{file}]
13010Produce a core dump of the inferior process. The optional argument
13011@var{file} specifies the file name where to put the core dump. If not
13012specified, the file name defaults to @file{core.@var{pid}}, where
13013@var{pid} is the inferior process ID.
13014
13015Note that this command is implemented only for some systems (as of
05b4bd79 13016this writing, @sc{gnu}/Linux, FreeBSD, Solaris, and S390).
df8411da
SDJ
13017
13018On @sc{gnu}/Linux, this command can take into account the value of the
13019file @file{/proc/@var{pid}/coredump_filter} when generating the core
1e52e849
SL
13020dump (@pxref{set use-coredump-filter}), and by default honors the
13021@code{VM_DONTDUMP} flag for mappings where it is present in the file
13022@file{/proc/@var{pid}/smaps} (@pxref{set dump-excluded-mappings}).
df8411da
SDJ
13023
13024@kindex set use-coredump-filter
13025@anchor{set use-coredump-filter}
13026@item set use-coredump-filter on
13027@itemx set use-coredump-filter off
13028Enable or disable the use of the file
13029@file{/proc/@var{pid}/coredump_filter} when generating core dump
13030files. This file is used by the Linux kernel to decide what types of
13031memory mappings will be dumped or ignored when generating a core dump
13032file. @var{pid} is the process ID of a currently running process.
13033
13034To make use of this feature, you have to write in the
13035@file{/proc/@var{pid}/coredump_filter} file a value, in hexadecimal,
13036which is a bit mask representing the memory mapping types. If a bit
13037is set in the bit mask, then the memory mappings of the corresponding
13038types will be dumped; otherwise, they will be ignored. This
13039configuration is inherited by child processes. For more information
13040about the bits that can be set in the
13041@file{/proc/@var{pid}/coredump_filter} file, please refer to the
13042manpage of @code{core(5)}.
13043
13044By default, this option is @code{on}. If this option is turned
13045@code{off}, @value{GDBN} does not read the @file{coredump_filter} file
13046and instead uses the same default value as the Linux kernel in order
13047to decide which pages will be dumped in the core dump file. This
13048value is currently @code{0x33}, which means that bits @code{0}
13049(anonymous private mappings), @code{1} (anonymous shared mappings),
13050@code{4} (ELF headers) and @code{5} (private huge pages) are active.
13051This will cause these memory mappings to be dumped automatically.
1e52e849
SL
13052
13053@kindex set dump-excluded-mappings
13054@anchor{set dump-excluded-mappings}
13055@item set dump-excluded-mappings on
13056@itemx set dump-excluded-mappings off
13057If @code{on} is specified, @value{GDBN} will dump memory mappings
13058marked with the @code{VM_DONTDUMP} flag. This flag is represented in
13059the file @file{/proc/@var{pid}/smaps} with the acronym @code{dd}.
13060
13061The default value is @code{off}.
384ee23f
EZ
13062@end table
13063
a0eb71c5
KB
13064@node Character Sets
13065@section Character Sets
13066@cindex character sets
13067@cindex charset
13068@cindex translating between character sets
13069@cindex host character set
13070@cindex target character set
13071
13072If the program you are debugging uses a different character set to
13073represent characters and strings than the one @value{GDBN} uses itself,
13074@value{GDBN} can automatically translate between the character sets for
13075you. The character set @value{GDBN} uses we call the @dfn{host
13076character set}; the one the inferior program uses we call the
13077@dfn{target character set}.
13078
13079For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
13080uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
ea35711c 13081remote protocol (@pxref{Remote Debugging}) to debug a program
a0eb71c5
KB
13082running on an IBM mainframe, which uses the @sc{ebcdic} character set,
13083then the host character set is Latin-1, and the target character set is
13084@sc{ebcdic}. If you give @value{GDBN} the command @code{set
e33d66ec 13085target-charset EBCDIC-US}, then @value{GDBN} translates between
a0eb71c5
KB
13086@sc{ebcdic} and Latin 1 as you print character or string values, or use
13087character and string literals in expressions.
13088
13089@value{GDBN} has no way to automatically recognize which character set
13090the inferior program uses; you must tell it, using the @code{set
13091target-charset} command, described below.
13092
13093Here are the commands for controlling @value{GDBN}'s character set
13094support:
13095
13096@table @code
13097@item set target-charset @var{charset}
13098@kindex set target-charset
10af6951
EZ
13099Set the current target character set to @var{charset}. To display the
13100list of supported target character sets, type
13101@kbd{@w{set target-charset @key{TAB}@key{TAB}}}.
a0eb71c5 13102
a0eb71c5
KB
13103@item set host-charset @var{charset}
13104@kindex set host-charset
13105Set the current host character set to @var{charset}.
13106
13107By default, @value{GDBN} uses a host character set appropriate to the
13108system it is running on; you can override that default using the
732f6a93
TT
13109@code{set host-charset} command. On some systems, @value{GDBN} cannot
13110automatically determine the appropriate host character set. In this
13111case, @value{GDBN} uses @samp{UTF-8}.
a0eb71c5
KB
13112
13113@value{GDBN} can only use certain character sets as its host character
c1b6b909 13114set. If you type @kbd{@w{set host-charset @key{TAB}@key{TAB}}},
10af6951 13115@value{GDBN} will list the host character sets it supports.
a0eb71c5
KB
13116
13117@item set charset @var{charset}
13118@kindex set charset
e33d66ec 13119Set the current host and target character sets to @var{charset}. As
10af6951
EZ
13120above, if you type @kbd{@w{set charset @key{TAB}@key{TAB}}},
13121@value{GDBN} will list the names of the character sets that can be used
e33d66ec
EZ
13122for both host and target.
13123
a0eb71c5 13124@item show charset
a0eb71c5 13125@kindex show charset
10af6951 13126Show the names of the current host and target character sets.
e33d66ec 13127
10af6951 13128@item show host-charset
a0eb71c5 13129@kindex show host-charset
10af6951 13130Show the name of the current host character set.
e33d66ec 13131
10af6951 13132@item show target-charset
a0eb71c5 13133@kindex show target-charset
10af6951 13134Show the name of the current target character set.
a0eb71c5 13135
10af6951
EZ
13136@item set target-wide-charset @var{charset}
13137@kindex set target-wide-charset
13138Set the current target's wide character set to @var{charset}. This is
13139the character set used by the target's @code{wchar_t} type. To
13140display the list of supported wide character sets, type
13141@kbd{@w{set target-wide-charset @key{TAB}@key{TAB}}}.
13142
13143@item show target-wide-charset
13144@kindex show target-wide-charset
13145Show the name of the current target's wide character set.
a0eb71c5
KB
13146@end table
13147
a0eb71c5
KB
13148Here is an example of @value{GDBN}'s character set support in action.
13149Assume that the following source code has been placed in the file
13150@file{charset-test.c}:
13151
13152@smallexample
13153#include <stdio.h>
13154
13155char ascii_hello[]
13156 = @{72, 101, 108, 108, 111, 44, 32, 119,
13157 111, 114, 108, 100, 33, 10, 0@};
13158char ibm1047_hello[]
13159 = @{200, 133, 147, 147, 150, 107, 64, 166,
13160 150, 153, 147, 132, 90, 37, 0@};
13161
13162main ()
13163@{
13164 printf ("Hello, world!\n");
13165@}
10998722 13166@end smallexample
a0eb71c5
KB
13167
13168In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
13169containing the string @samp{Hello, world!} followed by a newline,
13170encoded in the @sc{ascii} and @sc{ibm1047} character sets.
13171
13172We compile the program, and invoke the debugger on it:
13173
13174@smallexample
13175$ gcc -g charset-test.c -o charset-test
13176$ gdb -nw charset-test
13177GNU gdb 2001-12-19-cvs
13178Copyright 2001 Free Software Foundation, Inc.
13179@dots{}
f7dc1244 13180(@value{GDBP})
10998722 13181@end smallexample
a0eb71c5
KB
13182
13183We can use the @code{show charset} command to see what character sets
13184@value{GDBN} is currently using to interpret and display characters and
13185strings:
13186
13187@smallexample
f7dc1244 13188(@value{GDBP}) show charset
e33d66ec 13189The current host and target character set is `ISO-8859-1'.
f7dc1244 13190(@value{GDBP})
10998722 13191@end smallexample
a0eb71c5
KB
13192
13193For the sake of printing this manual, let's use @sc{ascii} as our
13194initial character set:
13195@smallexample
f7dc1244
EZ
13196(@value{GDBP}) set charset ASCII
13197(@value{GDBP}) show charset
e33d66ec 13198The current host and target character set is `ASCII'.
f7dc1244 13199(@value{GDBP})
10998722 13200@end smallexample
a0eb71c5
KB
13201
13202Let's assume that @sc{ascii} is indeed the correct character set for our
13203host system --- in other words, let's assume that if @value{GDBN} prints
13204characters using the @sc{ascii} character set, our terminal will display
13205them properly. Since our current target character set is also
13206@sc{ascii}, the contents of @code{ascii_hello} print legibly:
13207
13208@smallexample
f7dc1244 13209(@value{GDBP}) print ascii_hello
a0eb71c5 13210$1 = 0x401698 "Hello, world!\n"
f7dc1244 13211(@value{GDBP}) print ascii_hello[0]
a0eb71c5 13212$2 = 72 'H'
f7dc1244 13213(@value{GDBP})
10998722 13214@end smallexample
a0eb71c5
KB
13215
13216@value{GDBN} uses the target character set for character and string
13217literals you use in expressions:
13218
13219@smallexample
f7dc1244 13220(@value{GDBP}) print '+'
a0eb71c5 13221$3 = 43 '+'
f7dc1244 13222(@value{GDBP})
10998722 13223@end smallexample
a0eb71c5
KB
13224
13225The @sc{ascii} character set uses the number 43 to encode the @samp{+}
13226character.
13227
13228@value{GDBN} relies on the user to tell it which character set the
13229target program uses. If we print @code{ibm1047_hello} while our target
13230character set is still @sc{ascii}, we get jibberish:
13231
13232@smallexample
f7dc1244 13233(@value{GDBP}) print ibm1047_hello
a0eb71c5 13234$4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
f7dc1244 13235(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 13236$5 = 200 '\310'
f7dc1244 13237(@value{GDBP})
10998722 13238@end smallexample
a0eb71c5 13239
e33d66ec 13240If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
a0eb71c5
KB
13241@value{GDBN} tells us the character sets it supports:
13242
13243@smallexample
f7dc1244 13244(@value{GDBP}) set target-charset
b383017d 13245ASCII EBCDIC-US IBM1047 ISO-8859-1
f7dc1244 13246(@value{GDBP}) set target-charset
10998722 13247@end smallexample
a0eb71c5
KB
13248
13249We can select @sc{ibm1047} as our target character set, and examine the
13250program's strings again. Now the @sc{ascii} string is wrong, but
13251@value{GDBN} translates the contents of @code{ibm1047_hello} from the
13252target character set, @sc{ibm1047}, to the host character set,
13253@sc{ascii}, and they display correctly:
13254
13255@smallexample
f7dc1244
EZ
13256(@value{GDBP}) set target-charset IBM1047
13257(@value{GDBP}) show charset
e33d66ec
EZ
13258The current host character set is `ASCII'.
13259The current target character set is `IBM1047'.
f7dc1244 13260(@value{GDBP}) print ascii_hello
a0eb71c5 13261$6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
f7dc1244 13262(@value{GDBP}) print ascii_hello[0]
a0eb71c5 13263$7 = 72 '\110'
f7dc1244 13264(@value{GDBP}) print ibm1047_hello
a0eb71c5 13265$8 = 0x4016a8 "Hello, world!\n"
f7dc1244 13266(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 13267$9 = 200 'H'
f7dc1244 13268(@value{GDBP})
10998722 13269@end smallexample
a0eb71c5
KB
13270
13271As above, @value{GDBN} uses the target character set for character and
13272string literals you use in expressions:
13273
13274@smallexample
f7dc1244 13275(@value{GDBP}) print '+'
a0eb71c5 13276$10 = 78 '+'
f7dc1244 13277(@value{GDBP})
10998722 13278@end smallexample
a0eb71c5 13279
e33d66ec 13280The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
a0eb71c5
KB
13281character.
13282
b12039c6
YQ
13283@node Caching Target Data
13284@section Caching Data of Targets
13285@cindex caching data of targets
13286
13287@value{GDBN} caches data exchanged between the debugger and a target.
b26dfc9a 13288Each cache is associated with the address space of the inferior.
65c574f6 13289@xref{Inferiors Connections and Programs}, about inferior and address space.
b12039c6
YQ
13290Such caching generally improves performance in remote debugging
13291(@pxref{Remote Debugging}), because it reduces the overhead of the
13292remote protocol by bundling memory reads and writes into large chunks.
13293Unfortunately, simply caching everything would lead to incorrect results,
13294since @value{GDBN} does not necessarily know anything about volatile
13295values, memory-mapped I/O addresses, etc. Furthermore, in non-stop mode
13296(@pxref{Non-Stop Mode}) memory can be changed @emph{while} a gdb command
13297is executing.
29b090c0
DE
13298Therefore, by default, @value{GDBN} only caches data
13299known to be on the stack@footnote{In non-stop mode, it is moderately
13300rare for a running thread to modify the stack of a stopped thread
13301in a way that would interfere with a backtrace, and caching of
29453a14
YQ
13302stack reads provides a significant speed up of remote backtraces.} or
13303in the code segment.
29b090c0 13304Other regions of memory can be explicitly marked as
27b81af3 13305cacheable; @pxref{Memory Region Attributes}.
09d4efe1
EZ
13306
13307@table @code
13308@kindex set remotecache
13309@item set remotecache on
13310@itemx set remotecache off
4e5d721f
DE
13311This option no longer does anything; it exists for compatibility
13312with old scripts.
09d4efe1
EZ
13313
13314@kindex show remotecache
13315@item show remotecache
4e5d721f
DE
13316Show the current state of the obsolete remotecache flag.
13317
13318@kindex set stack-cache
13319@item set stack-cache on
13320@itemx set stack-cache off
6dd315ba
YQ
13321Enable or disable caching of stack accesses. When @code{on}, use
13322caching. By default, this option is @code{on}.
4e5d721f
DE
13323
13324@kindex show stack-cache
13325@item show stack-cache
13326Show the current state of data caching for memory accesses.
09d4efe1 13327
29453a14
YQ
13328@kindex set code-cache
13329@item set code-cache on
13330@itemx set code-cache off
13331Enable or disable caching of code segment accesses. When @code{on},
13332use caching. By default, this option is @code{on}. This improves
13333performance of disassembly in remote debugging.
13334
13335@kindex show code-cache
13336@item show code-cache
13337Show the current state of target memory cache for code segment
13338accesses.
13339
09d4efe1 13340@kindex info dcache
4e5d721f 13341@item info dcache @r{[}line@r{]}
b26dfc9a
YQ
13342Print the information about the performance of data cache of the
13343current inferior's address space. The information displayed
13344includes the dcache width and depth, and for each cache line, its
13345number, address, and how many times it was referenced. This
13346command is useful for debugging the data cache operation.
4e5d721f
DE
13347
13348If a line number is specified, the contents of that line will be
13349printed in hex.
1a532630
PP
13350
13351@item set dcache size @var{size}
13352@cindex dcache size
13353@kindex set dcache size
13354Set maximum number of entries in dcache (dcache depth above).
13355
13356@item set dcache line-size @var{line-size}
13357@cindex dcache line-size
13358@kindex set dcache line-size
13359Set number of bytes each dcache entry caches (dcache width above).
13360Must be a power of 2.
13361
13362@item show dcache size
13363@kindex show dcache size
b12039c6 13364Show maximum number of dcache entries. @xref{Caching Target Data, info dcache}.
1a532630
PP
13365
13366@item show dcache line-size
13367@kindex show dcache line-size
b12039c6 13368Show default size of dcache lines.
1a532630 13369
09d4efe1
EZ
13370@end table
13371
08388c79
DE
13372@node Searching Memory
13373@section Search Memory
13374@cindex searching memory
13375
13376Memory can be searched for a particular sequence of bytes with the
13377@code{find} command.
13378
13379@table @code
13380@kindex find
13381@item find @r{[}/@var{sn}@r{]} @var{start_addr}, +@var{len}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
13382@itemx find @r{[}/@var{sn}@r{]} @var{start_addr}, @var{end_addr}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
13383Search memory for the sequence of bytes specified by @var{val1}, @var{val2},
13384etc. The search begins at address @var{start_addr} and continues for either
13385@var{len} bytes or through to @var{end_addr} inclusive.
13386@end table
13387
13388@var{s} and @var{n} are optional parameters.
13389They may be specified in either order, apart or together.
13390
13391@table @r
13392@item @var{s}, search query size
13393The size of each search query value.
13394
13395@table @code
13396@item b
13397bytes
13398@item h
13399halfwords (two bytes)
13400@item w
13401words (four bytes)
13402@item g
13403giant words (eight bytes)
13404@end table
13405
13406All values are interpreted in the current language.
13407This means, for example, that if the current source language is C/C@t{++}
13408then searching for the string ``hello'' includes the trailing '\0'.
ee9a09e9
DC
13409The null terminator can be removed from searching by using casts,
13410e.g.: @samp{@{char[5]@}"hello"}.
08388c79
DE
13411
13412If the value size is not specified, it is taken from the
13413value's type in the current language.
13414This is useful when one wants to specify the search
13415pattern as a mixture of types.
13416Note that this means, for example, that in the case of C-like languages
13417a search for an untyped 0x42 will search for @samp{(int) 0x42}
13418which is typically four bytes.
13419
13420@item @var{n}, maximum number of finds
13421The maximum number of matches to print. The default is to print all finds.
13422@end table
13423
13424You can use strings as search values. Quote them with double-quotes
13425 (@code{"}).
13426The string value is copied into the search pattern byte by byte,
13427regardless of the endianness of the target and the size specification.
13428
13429The address of each match found is printed as well as a count of the
13430number of matches found.
13431
13432The address of the last value found is stored in convenience variable
13433@samp{$_}.
13434A count of the number of matches is stored in @samp{$numfound}.
13435
13436For example, if stopped at the @code{printf} in this function:
13437
13438@smallexample
13439void
13440hello ()
13441@{
13442 static char hello[] = "hello-hello";
13443 static struct @{ char c; short s; int i; @}
13444 __attribute__ ((packed)) mixed
13445 = @{ 'c', 0x1234, 0x87654321 @};
13446 printf ("%s\n", hello);
13447@}
13448@end smallexample
13449
13450@noindent
13451you get during debugging:
13452
13453@smallexample
13454(gdb) find &hello[0], +sizeof(hello), "hello"
134550x804956d <hello.1620+6>
134561 pattern found
13457(gdb) find &hello[0], +sizeof(hello), 'h', 'e', 'l', 'l', 'o'
134580x8049567 <hello.1620>
134590x804956d <hello.1620+6>
ee9a09e9
DC
134602 patterns found.
13461(gdb) find &hello[0], +sizeof(hello), @{char[5]@}"hello"
134620x8049567 <hello.1620>
134630x804956d <hello.1620+6>
134642 patterns found.
08388c79
DE
13465(gdb) find /b1 &hello[0], +sizeof(hello), 'h', 0x65, 'l'
134660x8049567 <hello.1620>
134671 pattern found
13468(gdb) find &mixed, +sizeof(mixed), (char) 'c', (short) 0x1234, (int) 0x87654321
134690x8049560 <mixed.1625>
134701 pattern found
13471(gdb) print $numfound
13472$1 = 1
13473(gdb) print $_
13474$2 = (void *) 0x8049560
13475@end smallexample
a0eb71c5 13476
5fdf6324
AB
13477@node Value Sizes
13478@section Value Sizes
13479
13480Whenever @value{GDBN} prints a value memory will be allocated within
13481@value{GDBN} to hold the contents of the value. It is possible in
13482some languages with dynamic typing systems, that an invalid program
13483may indicate a value that is incorrectly large, this in turn may cause
6b92c0d3 13484@value{GDBN} to try and allocate an overly large amount of memory.
5fdf6324
AB
13485
13486@table @code
13487@kindex set max-value-size
713cdcbf 13488@item set max-value-size @var{bytes}
5fdf6324
AB
13489@itemx set max-value-size unlimited
13490Set the maximum size of memory that @value{GDBN} will allocate for the
13491contents of a value to @var{bytes}, trying to display a value that
13492requires more memory than that will result in an error.
13493
13494Setting this variable does not effect values that have already been
13495allocated within @value{GDBN}, only future allocations.
13496
13497There's a minimum size that @code{max-value-size} can be set to in
13498order that @value{GDBN} can still operate correctly, this minimum is
13499currently 16 bytes.
13500
13501The limit applies to the results of some subexpressions as well as to
13502complete expressions. For example, an expression denoting a simple
13503integer component, such as @code{x.y.z}, may fail if the size of
13504@var{x.y} is dynamic and exceeds @var{bytes}. On the other hand,
13505@value{GDBN} is sometimes clever; the expression @code{A[i]}, where
13506@var{A} is an array variable with non-constant size, will generally
13507succeed regardless of the bounds on @var{A}, as long as the component
13508size is less than @var{bytes}.
13509
13510The default value of @code{max-value-size} is currently 64k.
13511
13512@kindex show max-value-size
13513@item show max-value-size
13514Show the maximum size of memory, in bytes, that @value{GDBN} will
13515allocate for the contents of a value.
13516@end table
13517
edb3359d
DJ
13518@node Optimized Code
13519@chapter Debugging Optimized Code
13520@cindex optimized code, debugging
13521@cindex debugging optimized code
13522
13523Almost all compilers support optimization. With optimization
13524disabled, the compiler generates assembly code that corresponds
13525directly to your source code, in a simplistic way. As the compiler
13526applies more powerful optimizations, the generated assembly code
13527diverges from your original source code. With help from debugging
13528information generated by the compiler, @value{GDBN} can map from
13529the running program back to constructs from your original source.
13530
13531@value{GDBN} is more accurate with optimization disabled. If you
13532can recompile without optimization, it is easier to follow the
13533progress of your program during debugging. But, there are many cases
13534where you may need to debug an optimized version.
13535
13536When you debug a program compiled with @samp{-g -O}, remember that the
13537optimizer has rearranged your code; the debugger shows you what is
13538really there. Do not be too surprised when the execution path does not
13539exactly match your source file! An extreme example: if you define a
13540variable, but never use it, @value{GDBN} never sees that
13541variable---because the compiler optimizes it out of existence.
13542
13543Some things do not work as well with @samp{-g -O} as with just
13544@samp{-g}, particularly on machines with instruction scheduling. If in
13545doubt, recompile with @samp{-g} alone, and if this fixes the problem,
13546please report it to us as a bug (including a test case!).
13547@xref{Variables}, for more information about debugging optimized code.
13548
13549@menu
13550* Inline Functions:: How @value{GDBN} presents inlining
111c6489 13551* Tail Call Frames:: @value{GDBN} analysis of jumps to functions
edb3359d
DJ
13552@end menu
13553
13554@node Inline Functions
13555@section Inline Functions
13556@cindex inline functions, debugging
13557
13558@dfn{Inlining} is an optimization that inserts a copy of the function
13559body directly at each call site, instead of jumping to a shared
13560routine. @value{GDBN} displays inlined functions just like
13561non-inlined functions. They appear in backtraces. You can view their
13562arguments and local variables, step into them with @code{step}, skip
13563them with @code{next}, and escape from them with @code{finish}.
13564You can check whether a function was inlined by using the
13565@code{info frame} command.
13566
13567For @value{GDBN} to support inlined functions, the compiler must
13568record information about inlining in the debug information ---
13569@value{NGCC} using the @sc{dwarf 2} format does this, and several
13570other compilers do also. @value{GDBN} only supports inlined functions
13571when using @sc{dwarf 2}. Versions of @value{NGCC} before 4.1
13572do not emit two required attributes (@samp{DW_AT_call_file} and
13573@samp{DW_AT_call_line}); @value{GDBN} does not display inlined
13574function calls with earlier versions of @value{NGCC}. It instead
13575displays the arguments and local variables of inlined functions as
13576local variables in the caller.
13577
13578The body of an inlined function is directly included at its call site;
13579unlike a non-inlined function, there are no instructions devoted to
13580the call. @value{GDBN} still pretends that the call site and the
13581start of the inlined function are different instructions. Stepping to
13582the call site shows the call site, and then stepping again shows
13583the first line of the inlined function, even though no additional
13584instructions are executed.
13585
13586This makes source-level debugging much clearer; you can see both the
13587context of the call and then the effect of the call. Only stepping by
13588a single instruction using @code{stepi} or @code{nexti} does not do
13589this; single instruction steps always show the inlined body.
13590
13591There are some ways that @value{GDBN} does not pretend that inlined
13592function calls are the same as normal calls:
13593
13594@itemize @bullet
edb3359d
DJ
13595@item
13596Setting breakpoints at the call site of an inlined function may not
13597work, because the call site does not contain any code. @value{GDBN}
13598may incorrectly move the breakpoint to the next line of the enclosing
13599function, after the call. This limitation will be removed in a future
13600version of @value{GDBN}; until then, set a breakpoint on an earlier line
13601or inside the inlined function instead.
13602
13603@item
13604@value{GDBN} cannot locate the return value of inlined calls after
13605using the @code{finish} command. This is a limitation of compiler-generated
13606debugging information; after @code{finish}, you can step to the next line
13607and print a variable where your program stored the return value.
13608
13609@end itemize
13610
111c6489
JK
13611@node Tail Call Frames
13612@section Tail Call Frames
13613@cindex tail call frames, debugging
13614
13615Function @code{B} can call function @code{C} in its very last statement. In
13616unoptimized compilation the call of @code{C} is immediately followed by return
13617instruction at the end of @code{B} code. Optimizing compiler may replace the
13618call and return in function @code{B} into one jump to function @code{C}
13619instead. Such use of a jump instruction is called @dfn{tail call}.
13620
13621During execution of function @code{C}, there will be no indication in the
13622function call stack frames that it was tail-called from @code{B}. If function
13623@code{A} regularly calls function @code{B} which tail-calls function @code{C},
13624then @value{GDBN} will see @code{A} as the caller of @code{C}. However, in
13625some cases @value{GDBN} can determine that @code{C} was tail-called from
13626@code{B}, and it will then create fictitious call frame for that, with the
13627return address set up as if @code{B} called @code{C} normally.
13628
13629This functionality is currently supported only by DWARF 2 debugging format and
216f72a1 13630the compiler has to produce @samp{DW_TAG_call_site} tags. With
111c6489
JK
13631@value{NGCC}, you need to specify @option{-O -g} during compilation, to get
13632this information.
13633
13634@kbd{info frame} command (@pxref{Frame Info}) will indicate the tail call frame
13635kind by text @code{tail call frame} such as in this sample @value{GDBN} output:
13636
13637@smallexample
13638(gdb) x/i $pc - 2
13639 0x40066b <b(int, double)+11>: jmp 0x400640 <c(int, double)>
13640(gdb) info frame
13641Stack level 1, frame at 0x7fffffffda30:
13642 rip = 0x40066d in b (amd64-entry-value.cc:59); saved rip 0x4004c5
13643 tail call frame, caller of frame at 0x7fffffffda30
13644 source language c++.
13645 Arglist at unknown address.
13646 Locals at unknown address, Previous frame's sp is 0x7fffffffda30
13647@end smallexample
13648
13649The detection of all the possible code path executions can find them ambiguous.
13650There is no execution history stored (possible @ref{Reverse Execution} is never
13651used for this purpose) and the last known caller could have reached the known
13652callee by multiple different jump sequences. In such case @value{GDBN} still
13653tries to show at least all the unambiguous top tail callers and all the
13654unambiguous bottom tail calees, if any.
13655
13656@table @code
e18b2753 13657@anchor{set debug entry-values}
111c6489
JK
13658@item set debug entry-values
13659@kindex set debug entry-values
13660When set to on, enables printing of analysis messages for both frame argument
13661values at function entry and tail calls. It will show all the possible valid
13662tail calls code paths it has considered. It will also print the intersection
13663of them with the final unambiguous (possibly partial or even empty) code path
13664result.
13665
13666@item show debug entry-values
13667@kindex show debug entry-values
13668Show the current state of analysis messages printing for both frame argument
13669values at function entry and tail calls.
13670@end table
13671
13672The analysis messages for tail calls can for example show why the virtual tail
13673call frame for function @code{c} has not been recognized (due to the indirect
13674reference by variable @code{x}):
13675
13676@smallexample
13677static void __attribute__((noinline, noclone)) c (void);
13678void (*x) (void) = c;
13679static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
13680static void __attribute__((noinline, noclone)) c (void) @{ a (); @}
13681int main (void) @{ x (); return 0; @}
13682
216f72a1
JK
13683Breakpoint 1, DW_OP_entry_value resolving cannot find
13684DW_TAG_call_site 0x40039a in main
111c6489
JK
13685a () at t.c:3
136863 static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
13687(gdb) bt
13688#0 a () at t.c:3
13689#1 0x000000000040039a in main () at t.c:5
13690@end smallexample
13691
13692Another possibility is an ambiguous virtual tail call frames resolution:
13693
13694@smallexample
13695int i;
13696static void __attribute__((noinline, noclone)) f (void) @{ i++; @}
13697static void __attribute__((noinline, noclone)) e (void) @{ f (); @}
13698static void __attribute__((noinline, noclone)) d (void) @{ f (); @}
13699static void __attribute__((noinline, noclone)) c (void) @{ d (); @}
13700static void __attribute__((noinline, noclone)) b (void)
13701@{ if (i) c (); else e (); @}
13702static void __attribute__((noinline, noclone)) a (void) @{ b (); @}
13703int main (void) @{ a (); return 0; @}
13704
13705tailcall: initial: 0x4004d2(a) 0x4004ce(b) 0x4004b2(c) 0x4004a2(d)
13706tailcall: compare: 0x4004d2(a) 0x4004cc(b) 0x400492(e)
13707tailcall: reduced: 0x4004d2(a) |
13708(gdb) bt
13709#0 f () at t.c:2
13710#1 0x00000000004004d2 in a () at t.c:8
13711#2 0x0000000000400395 in main () at t.c:9
13712@end smallexample
13713
5048e516
JK
13714@set CALLSEQ1A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}c@value{ARROW}d@value{ARROW}f}
13715@set CALLSEQ2A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}e@value{ARROW}f}
13716
13717@c Convert CALLSEQ#A to CALLSEQ#B depending on HAVE_MAKEINFO_CLICK.
13718@ifset HAVE_MAKEINFO_CLICK
13719@set ARROW @click{}
13720@set CALLSEQ1B @clicksequence{@value{CALLSEQ1A}}
13721@set CALLSEQ2B @clicksequence{@value{CALLSEQ2A}}
13722@end ifset
13723@ifclear HAVE_MAKEINFO_CLICK
13724@set ARROW ->
13725@set CALLSEQ1B @value{CALLSEQ1A}
13726@set CALLSEQ2B @value{CALLSEQ2A}
13727@end ifclear
13728
13729Frames #0 and #2 are real, #1 is a virtual tail call frame.
13730The code can have possible execution paths @value{CALLSEQ1B} or
13731@value{CALLSEQ2B}, @value{GDBN} cannot find which one from the inferior state.
111c6489
JK
13732
13733@code{initial:} state shows some random possible calling sequence @value{GDBN}
6b92c0d3 13734has found. It then finds another possible calling sequence - that one is
111c6489
JK
13735prefixed by @code{compare:}. The non-ambiguous intersection of these two is
13736printed as the @code{reduced:} calling sequence. That one could have many
6b92c0d3 13737further @code{compare:} and @code{reduced:} statements as long as there remain
111c6489
JK
13738any non-ambiguous sequence entries.
13739
13740For the frame of function @code{b} in both cases there are different possible
13741@code{$pc} values (@code{0x4004cc} or @code{0x4004ce}), therefore this frame is
6b92c0d3 13742also ambiguous. The only non-ambiguous frame is the one for function @code{a},
111c6489
JK
13743therefore this one is displayed to the user while the ambiguous frames are
13744omitted.
edb3359d 13745
e18b2753
JK
13746There can be also reasons why printing of frame argument values at function
13747entry may fail:
13748
13749@smallexample
13750int v;
13751static void __attribute__((noinline, noclone)) c (int i) @{ v++; @}
13752static void __attribute__((noinline, noclone)) a (int i);
13753static void __attribute__((noinline, noclone)) b (int i) @{ a (i); @}
13754static void __attribute__((noinline, noclone)) a (int i)
13755@{ if (i) b (i - 1); else c (0); @}
13756int main (void) @{ a (5); return 0; @}
13757
13758(gdb) bt
13759#0 c (i=i@@entry=0) at t.c:2
216f72a1 13760#1 0x0000000000400428 in a (DW_OP_entry_value resolving has found
e18b2753
JK
13761function "a" at 0x400420 can call itself via tail calls
13762i=<optimized out>) at t.c:6
13763#2 0x000000000040036e in main () at t.c:7
13764@end smallexample
13765
13766@value{GDBN} cannot find out from the inferior state if and how many times did
13767function @code{a} call itself (via function @code{b}) as these calls would be
6b92c0d3 13768tail calls. Such tail calls would modify the @code{i} variable, therefore
e18b2753
JK
13769@value{GDBN} cannot be sure the value it knows would be right - @value{GDBN}
13770prints @code{<optimized out>} instead.
13771
e2e0bcd1
JB
13772@node Macros
13773@chapter C Preprocessor Macros
13774
49efadf5 13775Some languages, such as C and C@t{++}, provide a way to define and invoke
e2e0bcd1
JB
13776``preprocessor macros'' which expand into strings of tokens.
13777@value{GDBN} can evaluate expressions containing macro invocations, show
13778the result of macro expansion, and show a macro's definition, including
13779where it was defined.
13780
13781You may need to compile your program specially to provide @value{GDBN}
13782with information about preprocessor macros. Most compilers do not
13783include macros in their debugging information, even when you compile
13784with the @option{-g} flag. @xref{Compilation}.
13785
13786A program may define a macro at one point, remove that definition later,
13787and then provide a different definition after that. Thus, at different
13788points in the program, a macro may have different definitions, or have
13789no definition at all. If there is a current stack frame, @value{GDBN}
13790uses the macros in scope at that frame's source code line. Otherwise,
13791@value{GDBN} uses the macros in scope at the current listing location;
13792see @ref{List}.
13793
e2e0bcd1
JB
13794Whenever @value{GDBN} evaluates an expression, it always expands any
13795macro invocations present in the expression. @value{GDBN} also provides
13796the following commands for working with macros explicitly.
13797
13798@table @code
13799
13800@kindex macro expand
13801@cindex macro expansion, showing the results of preprocessor
13802@cindex preprocessor macro expansion, showing the results of
13803@cindex expanding preprocessor macros
13804@item macro expand @var{expression}
13805@itemx macro exp @var{expression}
13806Show the results of expanding all preprocessor macro invocations in
13807@var{expression}. Since @value{GDBN} simply expands macros, but does
13808not parse the result, @var{expression} need not be a valid expression;
13809it can be any string of tokens.
13810
09d4efe1 13811@kindex macro exp1
e2e0bcd1
JB
13812@item macro expand-once @var{expression}
13813@itemx macro exp1 @var{expression}
4644b6e3 13814@cindex expand macro once
e2e0bcd1
JB
13815@i{(This command is not yet implemented.)} Show the results of
13816expanding those preprocessor macro invocations that appear explicitly in
13817@var{expression}. Macro invocations appearing in that expansion are
13818left unchanged. This command allows you to see the effect of a
13819particular macro more clearly, without being confused by further
13820expansions. Since @value{GDBN} simply expands macros, but does not
13821parse the result, @var{expression} need not be a valid expression; it
13822can be any string of tokens.
13823
475b0867 13824@kindex info macro
e2e0bcd1 13825@cindex macro definition, showing
9b158ba0 13826@cindex definition of a macro, showing
13827@cindex macros, from debug info
71eba9c2 13828@item info macro [-a|-all] [--] @var{macro}
13829Show the current definition or all definitions of the named @var{macro},
13830and describe the source location or compiler command-line where that
13831definition was established. The optional double dash is to signify the end of
13832argument processing and the beginning of @var{macro} for non C-like macros where
13833the macro may begin with a hyphen.
e2e0bcd1 13834
9b158ba0 13835@kindex info macros
629500fa 13836@item info macros @var{location}
9b158ba0 13837Show all macro definitions that are in effect at the location specified
629500fa 13838by @var{location}, and describe the source location or compiler
9b158ba0 13839command-line where those definitions were established.
13840
e2e0bcd1
JB
13841@kindex macro define
13842@cindex user-defined macros
13843@cindex defining macros interactively
13844@cindex macros, user-defined
13845@item macro define @var{macro} @var{replacement-list}
13846@itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
d7d9f01e
TT
13847Introduce a definition for a preprocessor macro named @var{macro},
13848invocations of which are replaced by the tokens given in
13849@var{replacement-list}. The first form of this command defines an
13850``object-like'' macro, which takes no arguments; the second form
13851defines a ``function-like'' macro, which takes the arguments given in
13852@var{arglist}.
13853
13854A definition introduced by this command is in scope in every
13855expression evaluated in @value{GDBN}, until it is removed with the
13856@code{macro undef} command, described below. The definition overrides
13857all definitions for @var{macro} present in the program being debugged,
13858as well as any previous user-supplied definition.
e2e0bcd1
JB
13859
13860@kindex macro undef
13861@item macro undef @var{macro}
d7d9f01e
TT
13862Remove any user-supplied definition for the macro named @var{macro}.
13863This command only affects definitions provided with the @code{macro
13864define} command, described above; it cannot remove definitions present
13865in the program being debugged.
e2e0bcd1 13866
09d4efe1
EZ
13867@kindex macro list
13868@item macro list
d7d9f01e 13869List all the macros defined using the @code{macro define} command.
e2e0bcd1
JB
13870@end table
13871
13872@cindex macros, example of debugging with
13873Here is a transcript showing the above commands in action. First, we
13874show our source files:
13875
13876@smallexample
13877$ cat sample.c
13878#include <stdio.h>
13879#include "sample.h"
13880
13881#define M 42
13882#define ADD(x) (M + x)
13883
13884main ()
13885@{
13886#define N 28
13887 printf ("Hello, world!\n");
13888#undef N
13889 printf ("We're so creative.\n");
13890#define N 1729
13891 printf ("Goodbye, world!\n");
13892@}
13893$ cat sample.h
13894#define Q <
13895$
13896@end smallexample
13897
e0f8f636
TT
13898Now, we compile the program using the @sc{gnu} C compiler,
13899@value{NGCC}. We pass the @option{-gdwarf-2}@footnote{This is the
13900minimum. Recent versions of @value{NGCC} support @option{-gdwarf-3}
13901and @option{-gdwarf-4}; we recommend always choosing the most recent
13902version of DWARF.} @emph{and} @option{-g3} flags to ensure the compiler
13903includes information about preprocessor macros in the debugging
e2e0bcd1
JB
13904information.
13905
13906@smallexample
13907$ gcc -gdwarf-2 -g3 sample.c -o sample
13908$
13909@end smallexample
13910
13911Now, we start @value{GDBN} on our sample program:
13912
13913@smallexample
13914$ gdb -nw sample
13915GNU gdb 2002-05-06-cvs
13916Copyright 2002 Free Software Foundation, Inc.
13917GDB is free software, @dots{}
f7dc1244 13918(@value{GDBP})
e2e0bcd1
JB
13919@end smallexample
13920
13921We can expand macros and examine their definitions, even when the
13922program is not running. @value{GDBN} uses the current listing position
13923to decide which macro definitions are in scope:
13924
13925@smallexample
f7dc1244 13926(@value{GDBP}) list main
e2e0bcd1
JB
139273
139284 #define M 42
139295 #define ADD(x) (M + x)
139306
139317 main ()
139328 @{
139339 #define N 28
1393410 printf ("Hello, world!\n");
1393511 #undef N
1393612 printf ("We're so creative.\n");
f7dc1244 13937(@value{GDBP}) info macro ADD
e2e0bcd1
JB
13938Defined at /home/jimb/gdb/macros/play/sample.c:5
13939#define ADD(x) (M + x)
f7dc1244 13940(@value{GDBP}) info macro Q
e2e0bcd1
JB
13941Defined at /home/jimb/gdb/macros/play/sample.h:1
13942 included at /home/jimb/gdb/macros/play/sample.c:2
13943#define Q <
f7dc1244 13944(@value{GDBP}) macro expand ADD(1)
e2e0bcd1 13945expands to: (42 + 1)
f7dc1244 13946(@value{GDBP}) macro expand-once ADD(1)
e2e0bcd1 13947expands to: once (M + 1)
f7dc1244 13948(@value{GDBP})
e2e0bcd1
JB
13949@end smallexample
13950
d7d9f01e 13951In the example above, note that @code{macro expand-once} expands only
e2e0bcd1
JB
13952the macro invocation explicit in the original text --- the invocation of
13953@code{ADD} --- but does not expand the invocation of the macro @code{M},
13954which was introduced by @code{ADD}.
13955
3f94c067
BW
13956Once the program is running, @value{GDBN} uses the macro definitions in
13957force at the source line of the current stack frame:
e2e0bcd1
JB
13958
13959@smallexample
f7dc1244 13960(@value{GDBP}) break main
e2e0bcd1 13961Breakpoint 1 at 0x8048370: file sample.c, line 10.
f7dc1244 13962(@value{GDBP}) run
b383017d 13963Starting program: /home/jimb/gdb/macros/play/sample
e2e0bcd1
JB
13964
13965Breakpoint 1, main () at sample.c:10
1396610 printf ("Hello, world!\n");
f7dc1244 13967(@value{GDBP})
e2e0bcd1
JB
13968@end smallexample
13969
13970At line 10, the definition of the macro @code{N} at line 9 is in force:
13971
13972@smallexample
f7dc1244 13973(@value{GDBP}) info macro N
e2e0bcd1
JB
13974Defined at /home/jimb/gdb/macros/play/sample.c:9
13975#define N 28
f7dc1244 13976(@value{GDBP}) macro expand N Q M
e2e0bcd1 13977expands to: 28 < 42
f7dc1244 13978(@value{GDBP}) print N Q M
e2e0bcd1 13979$1 = 1
f7dc1244 13980(@value{GDBP})
e2e0bcd1
JB
13981@end smallexample
13982
13983As we step over directives that remove @code{N}'s definition, and then
13984give it a new definition, @value{GDBN} finds the definition (or lack
13985thereof) in force at each point:
13986
13987@smallexample
f7dc1244 13988(@value{GDBP}) next
e2e0bcd1
JB
13989Hello, world!
1399012 printf ("We're so creative.\n");
f7dc1244 13991(@value{GDBP}) info macro N
e2e0bcd1
JB
13992The symbol `N' has no definition as a C/C++ preprocessor macro
13993at /home/jimb/gdb/macros/play/sample.c:12
f7dc1244 13994(@value{GDBP}) next
e2e0bcd1
JB
13995We're so creative.
1399614 printf ("Goodbye, world!\n");
f7dc1244 13997(@value{GDBP}) info macro N
e2e0bcd1
JB
13998Defined at /home/jimb/gdb/macros/play/sample.c:13
13999#define N 1729
f7dc1244 14000(@value{GDBP}) macro expand N Q M
e2e0bcd1 14001expands to: 1729 < 42
f7dc1244 14002(@value{GDBP}) print N Q M
e2e0bcd1 14003$2 = 0
f7dc1244 14004(@value{GDBP})
e2e0bcd1
JB
14005@end smallexample
14006
484086b7
JK
14007In addition to source files, macros can be defined on the compilation command
14008line using the @option{-D@var{name}=@var{value}} syntax. For macros defined in
14009such a way, @value{GDBN} displays the location of their definition as line zero
14010of the source file submitted to the compiler.
14011
14012@smallexample
14013(@value{GDBP}) info macro __STDC__
14014Defined at /home/jimb/gdb/macros/play/sample.c:0
14015-D__STDC__=1
14016(@value{GDBP})
14017@end smallexample
14018
e2e0bcd1 14019
b37052ae
EZ
14020@node Tracepoints
14021@chapter Tracepoints
14022@c This chapter is based on the documentation written by Michael
14023@c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
14024
14025@cindex tracepoints
14026In some applications, it is not feasible for the debugger to interrupt
14027the program's execution long enough for the developer to learn
14028anything helpful about its behavior. If the program's correctness
14029depends on its real-time behavior, delays introduced by a debugger
14030might cause the program to change its behavior drastically, or perhaps
14031fail, even when the code itself is correct. It is useful to be able
14032to observe the program's behavior without interrupting it.
14033
14034Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
14035specify locations in the program, called @dfn{tracepoints}, and
14036arbitrary expressions to evaluate when those tracepoints are reached.
14037Later, using the @code{tfind} command, you can examine the values
14038those expressions had when the program hit the tracepoints. The
14039expressions may also denote objects in memory---structures or arrays,
14040for example---whose values @value{GDBN} should record; while visiting
14041a particular tracepoint, you may inspect those objects as if they were
14042in memory at that moment. However, because @value{GDBN} records these
14043values without interacting with you, it can do so quickly and
14044unobtrusively, hopefully not disturbing the program's behavior.
14045
14046The tracepoint facility is currently available only for remote
9d29849a
JB
14047targets. @xref{Targets}. In addition, your remote target must know
14048how to collect trace data. This functionality is implemented in the
14049remote stub; however, none of the stubs distributed with @value{GDBN}
14050support tracepoints as of this writing. The format of the remote
14051packets used to implement tracepoints are described in @ref{Tracepoint
14052Packets}.
b37052ae 14053
00bf0b85
SS
14054It is also possible to get trace data from a file, in a manner reminiscent
14055of corefiles; you specify the filename, and use @code{tfind} to search
14056through the file. @xref{Trace Files}, for more details.
14057
b37052ae
EZ
14058This chapter describes the tracepoint commands and features.
14059
14060@menu
b383017d
RM
14061* Set Tracepoints::
14062* Analyze Collected Data::
14063* Tracepoint Variables::
00bf0b85 14064* Trace Files::
b37052ae
EZ
14065@end menu
14066
14067@node Set Tracepoints
14068@section Commands to Set Tracepoints
14069
14070Before running such a @dfn{trace experiment}, an arbitrary number of
1042e4c0
SS
14071tracepoints can be set. A tracepoint is actually a special type of
14072breakpoint (@pxref{Set Breaks}), so you can manipulate it using
14073standard breakpoint commands. For instance, as with breakpoints,
14074tracepoint numbers are successive integers starting from one, and many
14075of the commands associated with tracepoints take the tracepoint number
14076as their argument, to identify which tracepoint to work on.
b37052ae
EZ
14077
14078For each tracepoint, you can specify, in advance, some arbitrary set
14079of data that you want the target to collect in the trace buffer when
14080it hits that tracepoint. The collected data can include registers,
14081local variables, or global data. Later, you can use @value{GDBN}
14082commands to examine the values these data had at the time the
14083tracepoint was hit.
14084
7d13fe92
SS
14085Tracepoints do not support every breakpoint feature. Ignore counts on
14086tracepoints have no effect, and tracepoints cannot run @value{GDBN}
14087commands when they are hit. Tracepoints may not be thread-specific
14088either.
1042e4c0 14089
7a697b8d
SS
14090@cindex fast tracepoints
14091Some targets may support @dfn{fast tracepoints}, which are inserted in
14092a different way (such as with a jump instead of a trap), that is
14093faster but possibly restricted in where they may be installed.
14094
0fb4aa4b
PA
14095@cindex static tracepoints
14096@cindex markers, static tracepoints
14097@cindex probing markers, static tracepoints
14098Regular and fast tracepoints are dynamic tracing facilities, meaning
14099that they can be used to insert tracepoints at (almost) any location
14100in the target. Some targets may also support controlling @dfn{static
14101tracepoints} from @value{GDBN}. With static tracing, a set of
14102instrumentation points, also known as @dfn{markers}, are embedded in
14103the target program, and can be activated or deactivated by name or
14104address. These are usually placed at locations which facilitate
14105investigating what the target is actually doing. @value{GDBN}'s
14106support for static tracing includes being able to list instrumentation
14107points, and attach them with @value{GDBN} defined high level
14108tracepoints that expose the whole range of convenience of
8786b2bd 14109@value{GDBN}'s tracepoints support. Namely, support for collecting
0fb4aa4b
PA
14110registers values and values of global or local (to the instrumentation
14111point) variables; tracepoint conditions and trace state variables.
14112The act of installing a @value{GDBN} static tracepoint on an
14113instrumentation point, or marker, is referred to as @dfn{probing} a
14114static tracepoint marker.
14115
fa593d66
PA
14116@code{gdbserver} supports tracepoints on some target systems.
14117@xref{Server,,Tracepoints support in @code{gdbserver}}.
14118
b37052ae
EZ
14119This section describes commands to set tracepoints and associated
14120conditions and actions.
14121
14122@menu
b383017d
RM
14123* Create and Delete Tracepoints::
14124* Enable and Disable Tracepoints::
14125* Tracepoint Passcounts::
782b2b07 14126* Tracepoint Conditions::
f61e138d 14127* Trace State Variables::
b383017d
RM
14128* Tracepoint Actions::
14129* Listing Tracepoints::
0fb4aa4b 14130* Listing Static Tracepoint Markers::
79a6e687 14131* Starting and Stopping Trace Experiments::
c9429232 14132* Tracepoint Restrictions::
b37052ae
EZ
14133@end menu
14134
14135@node Create and Delete Tracepoints
14136@subsection Create and Delete Tracepoints
14137
14138@table @code
14139@cindex set tracepoint
14140@kindex trace
1042e4c0 14141@item trace @var{location}
b37052ae 14142The @code{trace} command is very similar to the @code{break} command.
629500fa
KS
14143Its argument @var{location} can be any valid location.
14144@xref{Specify Location}. The @code{trace} command defines a tracepoint,
14145which is a point in the target program where the debugger will briefly stop,
14146collect some data, and then allow the program to continue. Setting a tracepoint
14147or changing its actions takes effect immediately if the remote stub
1e4d1764
YQ
14148supports the @samp{InstallInTrace} feature (@pxref{install tracepoint
14149in tracing}).
14150If remote stub doesn't support the @samp{InstallInTrace} feature, all
14151these changes don't take effect until the next @code{tstart}
1042e4c0 14152command, and once a trace experiment is running, further changes will
bfccc43c
YQ
14153not have any effect until the next trace experiment starts. In addition,
14154@value{GDBN} supports @dfn{pending tracepoints}---tracepoints whose
14155address is not yet resolved. (This is similar to pending breakpoints.)
14156Pending tracepoints are not downloaded to the target and not installed
14157until they are resolved. The resolution of pending tracepoints requires
14158@value{GDBN} support---when debugging with the remote target, and
14159@value{GDBN} disconnects from the remote stub (@pxref{disconnected
14160tracing}), pending tracepoints can not be resolved (and downloaded to
14161the remote stub) while @value{GDBN} is disconnected.
b37052ae
EZ
14162
14163Here are some examples of using the @code{trace} command:
14164
14165@smallexample
14166(@value{GDBP}) @b{trace foo.c:121} // a source file and line number
14167
14168(@value{GDBP}) @b{trace +2} // 2 lines forward
14169
14170(@value{GDBP}) @b{trace my_function} // first source line of function
14171
14172(@value{GDBP}) @b{trace *my_function} // EXACT start address of function
14173
14174(@value{GDBP}) @b{trace *0x2117c4} // an address
14175@end smallexample
14176
14177@noindent
14178You can abbreviate @code{trace} as @code{tr}.
14179
782b2b07
SS
14180@item trace @var{location} if @var{cond}
14181Set a tracepoint with condition @var{cond}; evaluate the expression
14182@var{cond} each time the tracepoint is reached, and collect data only
14183if the value is nonzero---that is, if @var{cond} evaluates as true.
14184@xref{Tracepoint Conditions, ,Tracepoint Conditions}, for more
14185information on tracepoint conditions.
14186
7a697b8d
SS
14187@item ftrace @var{location} [ if @var{cond} ]
14188@cindex set fast tracepoint
74c761c1 14189@cindex fast tracepoints, setting
7a697b8d
SS
14190@kindex ftrace
14191The @code{ftrace} command sets a fast tracepoint. For targets that
14192support them, fast tracepoints will use a more efficient but possibly
14193less general technique to trigger data collection, such as a jump
14194instruction instead of a trap, or some sort of hardware support. It
14195may not be possible to create a fast tracepoint at the desired
14196location, in which case the command will exit with an explanatory
14197message.
14198
14199@value{GDBN} handles arguments to @code{ftrace} exactly as for
14200@code{trace}.
14201
405f8e94
SS
14202On 32-bit x86-architecture systems, fast tracepoints normally need to
14203be placed at an instruction that is 5 bytes or longer, but can be
14204placed at 4-byte instructions if the low 64K of memory of the target
14205program is available to install trampolines. Some Unix-type systems,
14206such as @sc{gnu}/Linux, exclude low addresses from the program's
14207address space; but for instance with the Linux kernel it is possible
14208to let @value{GDBN} use this area by doing a @command{sysctl} command
14209to set the @code{mmap_min_addr} kernel parameter, as in
14210
14211@example
14212sudo sysctl -w vm.mmap_min_addr=32768
14213@end example
14214
14215@noindent
14216which sets the low address to 32K, which leaves plenty of room for
14217trampolines. The minimum address should be set to a page boundary.
14218
0fb4aa4b 14219@item strace @var{location} [ if @var{cond} ]
74c761c1
PA
14220@cindex set static tracepoint
14221@cindex static tracepoints, setting
14222@cindex probe static tracepoint marker
0fb4aa4b
PA
14223@kindex strace
14224The @code{strace} command sets a static tracepoint. For targets that
14225support it, setting a static tracepoint probes a static
14226instrumentation point, or marker, found at @var{location}. It may not
14227be possible to set a static tracepoint at the desired location, in
14228which case the command will exit with an explanatory message.
14229
14230@value{GDBN} handles arguments to @code{strace} exactly as for
14231@code{trace}, with the addition that the user can also specify
14232@code{-m @var{marker}} as @var{location}. This probes the marker
14233identified by the @var{marker} string identifier. This identifier
14234depends on the static tracepoint backend library your program is
14235using. You can find all the marker identifiers in the @samp{ID} field
14236of the @code{info static-tracepoint-markers} command output.
14237@xref{Listing Static Tracepoint Markers,,Listing Static Tracepoint
14238Markers}. For example, in the following small program using the UST
14239tracing engine:
14240
14241@smallexample
14242main ()
14243@{
14244 trace_mark(ust, bar33, "str %s", "FOOBAZ");
14245@}
14246@end smallexample
14247
14248@noindent
14249the marker id is composed of joining the first two arguments to the
14250@code{trace_mark} call with a slash, which translates to:
14251
14252@smallexample
14253(@value{GDBP}) info static-tracepoint-markers
14254Cnt Enb ID Address What
142551 n ust/bar33 0x0000000000400ddc in main at stexample.c:22
14256 Data: "str %s"
14257[etc...]
14258@end smallexample
14259
14260@noindent
14261so you may probe the marker above with:
14262
14263@smallexample
14264(@value{GDBP}) strace -m ust/bar33
14265@end smallexample
14266
14267Static tracepoints accept an extra collect action --- @code{collect
14268$_sdata}. This collects arbitrary user data passed in the probe point
14269call to the tracing library. In the UST example above, you'll see
14270that the third argument to @code{trace_mark} is a printf-like format
6b92c0d3 14271string. The user data is then the result of running that formatting
0fb4aa4b
PA
14272string against the following arguments. Note that @code{info
14273static-tracepoint-markers} command output lists that format string in
14274the @samp{Data:} field.
14275
14276You can inspect this data when analyzing the trace buffer, by printing
14277the $_sdata variable like any other variable available to
14278@value{GDBN}. @xref{Tracepoint Actions,,Tracepoint Action Lists}.
14279
b37052ae
EZ
14280@vindex $tpnum
14281@cindex last tracepoint number
14282@cindex recent tracepoint number
14283@cindex tracepoint number
14284The convenience variable @code{$tpnum} records the tracepoint number
14285of the most recently set tracepoint.
14286
14287@kindex delete tracepoint
14288@cindex tracepoint deletion
14289@item delete tracepoint @r{[}@var{num}@r{]}
14290Permanently delete one or more tracepoints. With no argument, the
1042e4c0
SS
14291default is to delete all tracepoints. Note that the regular
14292@code{delete} command can remove tracepoints also.
b37052ae
EZ
14293
14294Examples:
14295
14296@smallexample
14297(@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
14298
14299(@value{GDBP}) @b{delete trace} // remove all tracepoints
14300@end smallexample
14301
14302@noindent
14303You can abbreviate this command as @code{del tr}.
14304@end table
14305
14306@node Enable and Disable Tracepoints
14307@subsection Enable and Disable Tracepoints
14308
1042e4c0
SS
14309These commands are deprecated; they are equivalent to plain @code{disable} and @code{enable}.
14310
b37052ae
EZ
14311@table @code
14312@kindex disable tracepoint
14313@item disable tracepoint @r{[}@var{num}@r{]}
14314Disable tracepoint @var{num}, or all tracepoints if no argument
14315@var{num} is given. A disabled tracepoint will have no effect during
d248b706 14316a trace experiment, but it is not forgotten. You can re-enable
b37052ae 14317a disabled tracepoint using the @code{enable tracepoint} command.
d248b706
KY
14318If the command is issued during a trace experiment and the debug target
14319has support for disabling tracepoints during a trace experiment, then the
14320change will be effective immediately. Otherwise, it will be applied to the
14321next trace experiment.
b37052ae
EZ
14322
14323@kindex enable tracepoint
14324@item enable tracepoint @r{[}@var{num}@r{]}
d248b706
KY
14325Enable tracepoint @var{num}, or all tracepoints. If this command is
14326issued during a trace experiment and the debug target supports enabling
14327tracepoints during a trace experiment, then the enabled tracepoints will
14328become effective immediately. Otherwise, they will become effective the
14329next time a trace experiment is run.
b37052ae
EZ
14330@end table
14331
14332@node Tracepoint Passcounts
14333@subsection Tracepoint Passcounts
14334
14335@table @code
14336@kindex passcount
14337@cindex tracepoint pass count
14338@item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
14339Set the @dfn{passcount} of a tracepoint. The passcount is a way to
14340automatically stop a trace experiment. If a tracepoint's passcount is
14341@var{n}, then the trace experiment will be automatically stopped on
14342the @var{n}'th time that tracepoint is hit. If the tracepoint number
14343@var{num} is not specified, the @code{passcount} command sets the
14344passcount of the most recently defined tracepoint. If no passcount is
14345given, the trace experiment will run until stopped explicitly by the
14346user.
14347
14348Examples:
14349
14350@smallexample
b383017d 14351(@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
6826cf00 14352@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
b37052ae
EZ
14353
14354(@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
6826cf00 14355@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
b37052ae
EZ
14356(@value{GDBP}) @b{trace foo}
14357(@value{GDBP}) @b{pass 3}
14358(@value{GDBP}) @b{trace bar}
14359(@value{GDBP}) @b{pass 2}
14360(@value{GDBP}) @b{trace baz}
14361(@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
6826cf00
EZ
14362@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
14363@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
14364@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
b37052ae
EZ
14365@end smallexample
14366@end table
14367
782b2b07
SS
14368@node Tracepoint Conditions
14369@subsection Tracepoint Conditions
14370@cindex conditional tracepoints
14371@cindex tracepoint conditions
14372
14373The simplest sort of tracepoint collects data every time your program
14374reaches a specified place. You can also specify a @dfn{condition} for
14375a tracepoint. A condition is just a Boolean expression in your
14376programming language (@pxref{Expressions, ,Expressions}). A
14377tracepoint with a condition evaluates the expression each time your
14378program reaches it, and data collection happens only if the condition
14379is true.
14380
14381Tracepoint conditions can be specified when a tracepoint is set, by
14382using @samp{if} in the arguments to the @code{trace} command.
14383@xref{Create and Delete Tracepoints, ,Setting Tracepoints}. They can
14384also be set or changed at any time with the @code{condition} command,
14385just as with breakpoints.
14386
14387Unlike breakpoint conditions, @value{GDBN} does not actually evaluate
14388the conditional expression itself. Instead, @value{GDBN} encodes the
6dcd5565 14389expression into an agent expression (@pxref{Agent Expressions})
782b2b07
SS
14390suitable for execution on the target, independently of @value{GDBN}.
14391Global variables become raw memory locations, locals become stack
14392accesses, and so forth.
14393
14394For instance, suppose you have a function that is usually called
14395frequently, but should not be called after an error has occurred. You
14396could use the following tracepoint command to collect data about calls
14397of that function that happen while the error code is propagating
14398through the program; an unconditional tracepoint could end up
14399collecting thousands of useless trace frames that you would have to
14400search through.
14401
14402@smallexample
14403(@value{GDBP}) @kbd{trace normal_operation if errcode > 0}
14404@end smallexample
14405
f61e138d
SS
14406@node Trace State Variables
14407@subsection Trace State Variables
14408@cindex trace state variables
14409
14410A @dfn{trace state variable} is a special type of variable that is
14411created and managed by target-side code. The syntax is the same as
14412that for GDB's convenience variables (a string prefixed with ``$''),
14413but they are stored on the target. They must be created explicitly,
14414using a @code{tvariable} command. They are always 64-bit signed
14415integers.
14416
14417Trace state variables are remembered by @value{GDBN}, and downloaded
14418to the target along with tracepoint information when the trace
14419experiment starts. There are no intrinsic limits on the number of
14420trace state variables, beyond memory limitations of the target.
14421
14422@cindex convenience variables, and trace state variables
14423Although trace state variables are managed by the target, you can use
14424them in print commands and expressions as if they were convenience
14425variables; @value{GDBN} will get the current value from the target
14426while the trace experiment is running. Trace state variables share
14427the same namespace as other ``$'' variables, which means that you
14428cannot have trace state variables with names like @code{$23} or
14429@code{$pc}, nor can you have a trace state variable and a convenience
14430variable with the same name.
14431
14432@table @code
14433
14434@item tvariable $@var{name} [ = @var{expression} ]
14435@kindex tvariable
14436The @code{tvariable} command creates a new trace state variable named
14437@code{$@var{name}}, and optionally gives it an initial value of
697aa1b7 14438@var{expression}. The @var{expression} is evaluated when this command is
f61e138d
SS
14439entered; the result will be converted to an integer if possible,
14440otherwise @value{GDBN} will report an error. A subsequent
14441@code{tvariable} command specifying the same name does not create a
14442variable, but instead assigns the supplied initial value to the
14443existing variable of that name, overwriting any previous initial
14444value. The default initial value is 0.
14445
14446@item info tvariables
14447@kindex info tvariables
14448List all the trace state variables along with their initial values.
14449Their current values may also be displayed, if the trace experiment is
14450currently running.
14451
14452@item delete tvariable @r{[} $@var{name} @dots{} @r{]}
14453@kindex delete tvariable
14454Delete the given trace state variables, or all of them if no arguments
14455are specified.
14456
14457@end table
14458
b37052ae
EZ
14459@node Tracepoint Actions
14460@subsection Tracepoint Action Lists
14461
14462@table @code
14463@kindex actions
14464@cindex tracepoint actions
14465@item actions @r{[}@var{num}@r{]}
14466This command will prompt for a list of actions to be taken when the
14467tracepoint is hit. If the tracepoint number @var{num} is not
14468specified, this command sets the actions for the one that was most
14469recently defined (so that you can define a tracepoint and then say
14470@code{actions} without bothering about its number). You specify the
14471actions themselves on the following lines, one action at a time, and
14472terminate the actions list with a line containing just @code{end}. So
7d13fe92 14473far, the only defined actions are @code{collect}, @code{teval}, and
b37052ae
EZ
14474@code{while-stepping}.
14475
5a9351ae
SS
14476@code{actions} is actually equivalent to @code{commands} (@pxref{Break
14477Commands, ,Breakpoint Command Lists}), except that only the defined
14478actions are allowed; any other @value{GDBN} command is rejected.
14479
b37052ae
EZ
14480@cindex remove actions from a tracepoint
14481To remove all actions from a tracepoint, type @samp{actions @var{num}}
14482and follow it immediately with @samp{end}.
14483
14484@smallexample
14485(@value{GDBP}) @b{collect @var{data}} // collect some data
14486
6826cf00 14487(@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
b37052ae 14488
6826cf00 14489(@value{GDBP}) @b{end} // signals the end of actions.
b37052ae
EZ
14490@end smallexample
14491
14492In the following example, the action list begins with @code{collect}
14493commands indicating the things to be collected when the tracepoint is
14494hit. Then, in order to single-step and collect additional data
14495following the tracepoint, a @code{while-stepping} command is used,
7d13fe92
SS
14496followed by the list of things to be collected after each step in a
14497sequence of single steps. The @code{while-stepping} command is
14498terminated by its own separate @code{end} command. Lastly, the action
14499list is terminated by an @code{end} command.
b37052ae
EZ
14500
14501@smallexample
14502(@value{GDBP}) @b{trace foo}
14503(@value{GDBP}) @b{actions}
14504Enter actions for tracepoint 1, one per line:
14505> collect bar,baz
14506> collect $regs
14507> while-stepping 12
5a9351ae 14508 > collect $pc, arr[i]
b37052ae
EZ
14509 > end
14510end
14511@end smallexample
14512
14513@kindex collect @r{(tracepoints)}
3065dfb6 14514@item collect@r{[}/@var{mods}@r{]} @var{expr1}, @var{expr2}, @dots{}
b37052ae
EZ
14515Collect values of the given expressions when the tracepoint is hit.
14516This command accepts a comma-separated list of any valid expressions.
14517In addition to global, static, or local variables, the following
14518special arguments are supported:
14519
14520@table @code
14521@item $regs
0fb4aa4b 14522Collect all registers.
b37052ae
EZ
14523
14524@item $args
0fb4aa4b 14525Collect all function arguments.
b37052ae
EZ
14526
14527@item $locals
0fb4aa4b
PA
14528Collect all local variables.
14529
6710bf39
SS
14530@item $_ret
14531Collect the return address. This is helpful if you want to see more
14532of a backtrace.
14533
2a60e18f 14534@emph{Note:} The return address location can not always be reliably
45fa2529
PA
14535determined up front, and the wrong address / registers may end up
14536collected instead. On some architectures the reliability is higher
14537for tracepoints at function entry, while on others it's the opposite.
14538When this happens, backtracing will stop because the return address is
14539found unavailable (unless another collect rule happened to match it).
14540
62e5f89c
SDJ
14541@item $_probe_argc
14542Collects the number of arguments from the static probe at which the
14543tracepoint is located.
14544@xref{Static Probe Points}.
14545
14546@item $_probe_arg@var{n}
14547@var{n} is an integer between 0 and 11. Collects the @var{n}th argument
14548from the static probe at which the tracepoint is located.
14549@xref{Static Probe Points}.
14550
0fb4aa4b
PA
14551@item $_sdata
14552@vindex $_sdata@r{, collect}
14553Collect static tracepoint marker specific data. Only available for
14554static tracepoints. @xref{Tracepoint Actions,,Tracepoint Action
14555Lists}. On the UST static tracepoints library backend, an
14556instrumentation point resembles a @code{printf} function call. The
14557tracing library is able to collect user specified data formatted to a
14558character string using the format provided by the programmer that
14559instrumented the program. Other backends have similar mechanisms.
14560Here's an example of a UST marker call:
14561
14562@smallexample
14563 const char master_name[] = "$your_name";
14564 trace_mark(channel1, marker1, "hello %s", master_name)
14565@end smallexample
14566
14567In this case, collecting @code{$_sdata} collects the string
14568@samp{hello $yourname}. When analyzing the trace buffer, you can
14569inspect @samp{$_sdata} like any other variable available to
14570@value{GDBN}.
b37052ae
EZ
14571@end table
14572
14573You can give several consecutive @code{collect} commands, each one
14574with a single argument, or one @code{collect} command with several
5a9351ae 14575arguments separated by commas; the effect is the same.
b37052ae 14576
3065dfb6
SS
14577The optional @var{mods} changes the usual handling of the arguments.
14578@code{s} requests that pointers to chars be handled as strings, in
14579particular collecting the contents of the memory being pointed at, up
14580to the first zero. The upper bound is by default the value of the
14581@code{print elements} variable; if @code{s} is followed by a decimal
14582number, that is the upper bound instead. So for instance
14583@samp{collect/s25 mystr} collects as many as 25 characters at
14584@samp{mystr}.
14585
f5c37c66
EZ
14586The command @code{info scope} (@pxref{Symbols, info scope}) is
14587particularly useful for figuring out what data to collect.
14588
6da95a67
SS
14589@kindex teval @r{(tracepoints)}
14590@item teval @var{expr1}, @var{expr2}, @dots{}
14591Evaluate the given expressions when the tracepoint is hit. This
14592command accepts a comma-separated list of expressions. The results
14593are discarded, so this is mainly useful for assigning values to trace
14594state variables (@pxref{Trace State Variables}) without adding those
14595values to the trace buffer, as would be the case if the @code{collect}
14596action were used.
14597
b37052ae
EZ
14598@kindex while-stepping @r{(tracepoints)}
14599@item while-stepping @var{n}
c9429232 14600Perform @var{n} single-step instruction traces after the tracepoint,
7d13fe92 14601collecting new data after each step. The @code{while-stepping}
c9429232
SS
14602command is followed by the list of what to collect while stepping
14603(followed by its own @code{end} command):
b37052ae
EZ
14604
14605@smallexample
14606> while-stepping 12
14607 > collect $regs, myglobal
14608 > end
14609>
14610@end smallexample
14611
14612@noindent
7d13fe92
SS
14613Note that @code{$pc} is not automatically collected by
14614@code{while-stepping}; you need to explicitly collect that register if
14615you need it. You may abbreviate @code{while-stepping} as @code{ws} or
b37052ae 14616@code{stepping}.
236f1d4d
SS
14617
14618@item set default-collect @var{expr1}, @var{expr2}, @dots{}
14619@kindex set default-collect
14620@cindex default collection action
14621This variable is a list of expressions to collect at each tracepoint
14622hit. It is effectively an additional @code{collect} action prepended
14623to every tracepoint action list. The expressions are parsed
14624individually for each tracepoint, so for instance a variable named
14625@code{xyz} may be interpreted as a global for one tracepoint, and a
14626local for another, as appropriate to the tracepoint's location.
14627
14628@item show default-collect
14629@kindex show default-collect
14630Show the list of expressions that are collected by default at each
14631tracepoint hit.
14632
b37052ae
EZ
14633@end table
14634
14635@node Listing Tracepoints
14636@subsection Listing Tracepoints
14637
14638@table @code
e5a67952
MS
14639@kindex info tracepoints @r{[}@var{n}@dots{}@r{]}
14640@kindex info tp @r{[}@var{n}@dots{}@r{]}
b37052ae 14641@cindex information about tracepoints
e5a67952 14642@item info tracepoints @r{[}@var{num}@dots{}@r{]}
1042e4c0
SS
14643Display information about the tracepoint @var{num}. If you don't
14644specify a tracepoint number, displays information about all the
14645tracepoints defined so far. The format is similar to that used for
14646@code{info breakpoints}; in fact, @code{info tracepoints} is the same
14647command, simply restricting itself to tracepoints.
14648
14649A tracepoint's listing may include additional information specific to
14650tracing:
b37052ae
EZ
14651
14652@itemize @bullet
14653@item
b37052ae 14654its passcount as given by the @code{passcount @var{n}} command
f2a8bc8a
YQ
14655
14656@item
14657the state about installed on target of each location
b37052ae
EZ
14658@end itemize
14659
14660@smallexample
14661(@value{GDBP}) @b{info trace}
1042e4c0
SS
14662Num Type Disp Enb Address What
146631 tracepoint keep y 0x0804ab57 in foo() at main.cxx:7
5a9351ae
SS
14664 while-stepping 20
14665 collect globfoo, $regs
14666 end
14667 collect globfoo2
14668 end
1042e4c0 14669 pass count 1200
f2a8bc8a
YQ
146702 tracepoint keep y <MULTIPLE>
14671 collect $eip
146722.1 y 0x0804859c in func4 at change-loc.h:35
14673 installed on target
146742.2 y 0xb7ffc480 in func4 at change-loc.h:35
14675 installed on target
146762.3 y <PENDING> set_tracepoint
146773 tracepoint keep y 0x080485b1 in foo at change-loc.c:29
14678 not installed on target
b37052ae
EZ
14679(@value{GDBP})
14680@end smallexample
14681
14682@noindent
14683This command can be abbreviated @code{info tp}.
14684@end table
14685
0fb4aa4b
PA
14686@node Listing Static Tracepoint Markers
14687@subsection Listing Static Tracepoint Markers
14688
14689@table @code
14690@kindex info static-tracepoint-markers
14691@cindex information about static tracepoint markers
14692@item info static-tracepoint-markers
14693Display information about all static tracepoint markers defined in the
14694program.
14695
14696For each marker, the following columns are printed:
14697
14698@table @emph
14699@item Count
14700An incrementing counter, output to help readability. This is not a
14701stable identifier.
14702@item ID
14703The marker ID, as reported by the target.
14704@item Enabled or Disabled
14705Probed markers are tagged with @samp{y}. @samp{n} identifies marks
14706that are not enabled.
14707@item Address
14708Where the marker is in your program, as a memory address.
14709@item What
14710Where the marker is in the source for your program, as a file and line
14711number. If the debug information included in the program does not
14712allow @value{GDBN} to locate the source of the marker, this column
14713will be left blank.
14714@end table
14715
14716@noindent
14717In addition, the following information may be printed for each marker:
14718
14719@table @emph
14720@item Data
14721User data passed to the tracing library by the marker call. In the
14722UST backend, this is the format string passed as argument to the
14723marker call.
14724@item Static tracepoints probing the marker
14725The list of static tracepoints attached to the marker.
14726@end table
14727
14728@smallexample
14729(@value{GDBP}) info static-tracepoint-markers
14730Cnt ID Enb Address What
147311 ust/bar2 y 0x0000000000400e1a in main at stexample.c:25
14732 Data: number1 %d number2 %d
14733 Probed by static tracepoints: #2
147342 ust/bar33 n 0x0000000000400c87 in main at stexample.c:24
14735 Data: str %s
14736(@value{GDBP})
14737@end smallexample
14738@end table
14739
79a6e687
BW
14740@node Starting and Stopping Trace Experiments
14741@subsection Starting and Stopping Trace Experiments
b37052ae
EZ
14742
14743@table @code
f196051f 14744@kindex tstart [ @var{notes} ]
b37052ae
EZ
14745@cindex start a new trace experiment
14746@cindex collected data discarded
14747@item tstart
f196051f
SS
14748This command starts the trace experiment, and begins collecting data.
14749It has the side effect of discarding all the data collected in the
14750trace buffer during the previous trace experiment. If any arguments
14751are supplied, they are taken as a note and stored with the trace
14752experiment's state. The notes may be arbitrary text, and are
14753especially useful with disconnected tracing in a multi-user context;
14754the notes can explain what the trace is doing, supply user contact
14755information, and so forth.
14756
14757@kindex tstop [ @var{notes} ]
b37052ae
EZ
14758@cindex stop a running trace experiment
14759@item tstop
f196051f
SS
14760This command stops the trace experiment. If any arguments are
14761supplied, they are recorded with the experiment as a note. This is
14762useful if you are stopping a trace started by someone else, for
14763instance if the trace is interfering with the system's behavior and
14764needs to be stopped quickly.
b37052ae 14765
68c71a2e 14766@strong{Note}: a trace experiment and data collection may stop
b37052ae
EZ
14767automatically if any tracepoint's passcount is reached
14768(@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
14769
14770@kindex tstatus
14771@cindex status of trace data collection
14772@cindex trace experiment, status of
14773@item tstatus
14774This command displays the status of the current trace data
14775collection.
14776@end table
14777
14778Here is an example of the commands we described so far:
14779
14780@smallexample
14781(@value{GDBP}) @b{trace gdb_c_test}
14782(@value{GDBP}) @b{actions}
14783Enter actions for tracepoint #1, one per line.
14784> collect $regs,$locals,$args
14785> while-stepping 11
14786 > collect $regs
14787 > end
14788> end
14789(@value{GDBP}) @b{tstart}
14790 [time passes @dots{}]
14791(@value{GDBP}) @b{tstop}
14792@end smallexample
14793
03f2bd59 14794@anchor{disconnected tracing}
d5551862
SS
14795@cindex disconnected tracing
14796You can choose to continue running the trace experiment even if
14797@value{GDBN} disconnects from the target, voluntarily or
14798involuntarily. For commands such as @code{detach}, the debugger will
14799ask what you want to do with the trace. But for unexpected
14800terminations (@value{GDBN} crash, network outage), it would be
14801unfortunate to lose hard-won trace data, so the variable
14802@code{disconnected-tracing} lets you decide whether the trace should
14803continue running without @value{GDBN}.
14804
14805@table @code
14806@item set disconnected-tracing on
14807@itemx set disconnected-tracing off
14808@kindex set disconnected-tracing
14809Choose whether a tracing run should continue to run if @value{GDBN}
14810has disconnected from the target. Note that @code{detach} or
14811@code{quit} will ask you directly what to do about a running trace no
14812matter what this variable's setting, so the variable is mainly useful
14813for handling unexpected situations, such as loss of the network.
14814
14815@item show disconnected-tracing
14816@kindex show disconnected-tracing
14817Show the current choice for disconnected tracing.
14818
14819@end table
14820
14821When you reconnect to the target, the trace experiment may or may not
14822still be running; it might have filled the trace buffer in the
14823meantime, or stopped for one of the other reasons. If it is running,
14824it will continue after reconnection.
14825
14826Upon reconnection, the target will upload information about the
14827tracepoints in effect. @value{GDBN} will then compare that
14828information to the set of tracepoints currently defined, and attempt
14829to match them up, allowing for the possibility that the numbers may
14830have changed due to creation and deletion in the meantime. If one of
14831the target's tracepoints does not match any in @value{GDBN}, the
14832debugger will create a new tracepoint, so that you have a number with
14833which to specify that tracepoint. This matching-up process is
14834necessarily heuristic, and it may result in useless tracepoints being
14835created; you may simply delete them if they are of no use.
b37052ae 14836
4daf5ac0
SS
14837@cindex circular trace buffer
14838If your target agent supports a @dfn{circular trace buffer}, then you
14839can run a trace experiment indefinitely without filling the trace
14840buffer; when space runs out, the agent deletes already-collected trace
14841frames, oldest first, until there is enough room to continue
14842collecting. This is especially useful if your tracepoints are being
14843hit too often, and your trace gets terminated prematurely because the
14844buffer is full. To ask for a circular trace buffer, simply set
81896e36 14845@samp{circular-trace-buffer} to on. You can set this at any time,
4daf5ac0
SS
14846including during tracing; if the agent can do it, it will change
14847buffer handling on the fly, otherwise it will not take effect until
14848the next run.
14849
14850@table @code
14851@item set circular-trace-buffer on
14852@itemx set circular-trace-buffer off
14853@kindex set circular-trace-buffer
14854Choose whether a tracing run should use a linear or circular buffer
14855for trace data. A linear buffer will not lose any trace data, but may
14856fill up prematurely, while a circular buffer will discard old trace
14857data, but it will have always room for the latest tracepoint hits.
14858
14859@item show circular-trace-buffer
14860@kindex show circular-trace-buffer
14861Show the current choice for the trace buffer. Note that this may not
14862match the agent's current buffer handling, nor is it guaranteed to
14863match the setting that might have been in effect during a past run,
14864for instance if you are looking at frames from a trace file.
14865
14866@end table
14867
f6f899bf
HAQ
14868@table @code
14869@item set trace-buffer-size @var{n}
f81d1120 14870@itemx set trace-buffer-size unlimited
f6f899bf
HAQ
14871@kindex set trace-buffer-size
14872Request that the target use a trace buffer of @var{n} bytes. Not all
14873targets will honor the request; they may have a compiled-in size for
14874the trace buffer, or some other limitation. Set to a value of
f81d1120
PA
14875@code{unlimited} or @code{-1} to let the target use whatever size it
14876likes. This is also the default.
f6f899bf
HAQ
14877
14878@item show trace-buffer-size
14879@kindex show trace-buffer-size
14880Show the current requested size for the trace buffer. Note that this
14881will only match the actual size if the target supports size-setting,
14882and was able to handle the requested size. For instance, if the
14883target can only change buffer size between runs, this variable will
14884not reflect the change until the next run starts. Use @code{tstatus}
14885to get a report of the actual buffer size.
14886@end table
14887
f196051f
SS
14888@table @code
14889@item set trace-user @var{text}
14890@kindex set trace-user
14891
14892@item show trace-user
14893@kindex show trace-user
14894
14895@item set trace-notes @var{text}
14896@kindex set trace-notes
14897Set the trace run's notes.
14898
14899@item show trace-notes
14900@kindex show trace-notes
14901Show the trace run's notes.
14902
14903@item set trace-stop-notes @var{text}
14904@kindex set trace-stop-notes
14905Set the trace run's stop notes. The handling of the note is as for
14906@code{tstop} arguments; the set command is convenient way to fix a
14907stop note that is mistaken or incomplete.
14908
14909@item show trace-stop-notes
14910@kindex show trace-stop-notes
14911Show the trace run's stop notes.
14912
14913@end table
14914
c9429232
SS
14915@node Tracepoint Restrictions
14916@subsection Tracepoint Restrictions
14917
14918@cindex tracepoint restrictions
14919There are a number of restrictions on the use of tracepoints. As
14920described above, tracepoint data gathering occurs on the target
14921without interaction from @value{GDBN}. Thus the full capabilities of
14922the debugger are not available during data gathering, and then at data
14923examination time, you will be limited by only having what was
14924collected. The following items describe some common problems, but it
14925is not exhaustive, and you may run into additional difficulties not
14926mentioned here.
14927
14928@itemize @bullet
14929
14930@item
14931Tracepoint expressions are intended to gather objects (lvalues). Thus
14932the full flexibility of GDB's expression evaluator is not available.
14933You cannot call functions, cast objects to aggregate types, access
14934convenience variables or modify values (except by assignment to trace
14935state variables). Some language features may implicitly call
14936functions (for instance Objective-C fields with accessors), and therefore
14937cannot be collected either.
14938
14939@item
14940Collection of local variables, either individually or in bulk with
14941@code{$locals} or @code{$args}, during @code{while-stepping} may
14942behave erratically. The stepping action may enter a new scope (for
14943instance by stepping into a function), or the location of the variable
14944may change (for instance it is loaded into a register). The
14945tracepoint data recorded uses the location information for the
14946variables that is correct for the tracepoint location. When the
14947tracepoint is created, it is not possible, in general, to determine
14948where the steps of a @code{while-stepping} sequence will advance the
14949program---particularly if a conditional branch is stepped.
14950
14951@item
14952Collection of an incompletely-initialized or partially-destroyed object
14953may result in something that @value{GDBN} cannot display, or displays
14954in a misleading way.
14955
14956@item
14957When @value{GDBN} displays a pointer to character it automatically
14958dereferences the pointer to also display characters of the string
14959being pointed to. However, collecting the pointer during tracing does
14960not automatically collect the string. You need to explicitly
14961dereference the pointer and provide size information if you want to
14962collect not only the pointer, but the memory pointed to. For example,
14963@code{*ptr@@50} can be used to collect the 50 element array pointed to
14964by @code{ptr}.
14965
14966@item
14967It is not possible to collect a complete stack backtrace at a
14968tracepoint. Instead, you may collect the registers and a few hundred
d99f7e48 14969bytes from the stack pointer with something like @code{*(unsigned char *)$esp@@300}
c9429232
SS
14970(adjust to use the name of the actual stack pointer register on your
14971target architecture, and the amount of stack you wish to capture).
14972Then the @code{backtrace} command will show a partial backtrace when
14973using a trace frame. The number of stack frames that can be examined
14974depends on the sizes of the frames in the collected stack. Note that
14975if you ask for a block so large that it goes past the bottom of the
14976stack, the target agent may report an error trying to read from an
14977invalid address.
14978
af54718e
SS
14979@item
14980If you do not collect registers at a tracepoint, @value{GDBN} can
14981infer that the value of @code{$pc} must be the same as the address of
14982the tracepoint and use that when you are looking at a trace frame
14983for that tracepoint. However, this cannot work if the tracepoint has
14984multiple locations (for instance if it was set in a function that was
14985inlined), or if it has a @code{while-stepping} loop. In those cases
14986@value{GDBN} will warn you that it can't infer @code{$pc}, and default
14987it to zero.
14988
c9429232
SS
14989@end itemize
14990
b37052ae 14991@node Analyze Collected Data
79a6e687 14992@section Using the Collected Data
b37052ae
EZ
14993
14994After the tracepoint experiment ends, you use @value{GDBN} commands
14995for examining the trace data. The basic idea is that each tracepoint
14996collects a trace @dfn{snapshot} every time it is hit and another
14997snapshot every time it single-steps. All these snapshots are
14998consecutively numbered from zero and go into a buffer, and you can
14999examine them later. The way you examine them is to @dfn{focus} on a
15000specific trace snapshot. When the remote stub is focused on a trace
15001snapshot, it will respond to all @value{GDBN} requests for memory and
15002registers by reading from the buffer which belongs to that snapshot,
15003rather than from @emph{real} memory or registers of the program being
15004debugged. This means that @strong{all} @value{GDBN} commands
15005(@code{print}, @code{info registers}, @code{backtrace}, etc.) will
15006behave as if we were currently debugging the program state as it was
15007when the tracepoint occurred. Any requests for data that are not in
15008the buffer will fail.
15009
15010@menu
15011* tfind:: How to select a trace snapshot
15012* tdump:: How to display all data for a snapshot
6149aea9 15013* save tracepoints:: How to save tracepoints for a future run
b37052ae
EZ
15014@end menu
15015
15016@node tfind
15017@subsection @code{tfind @var{n}}
15018
15019@kindex tfind
15020@cindex select trace snapshot
15021@cindex find trace snapshot
15022The basic command for selecting a trace snapshot from the buffer is
15023@code{tfind @var{n}}, which finds trace snapshot number @var{n},
15024counting from zero. If no argument @var{n} is given, the next
15025snapshot is selected.
15026
15027Here are the various forms of using the @code{tfind} command.
15028
15029@table @code
15030@item tfind start
15031Find the first snapshot in the buffer. This is a synonym for
15032@code{tfind 0} (since 0 is the number of the first snapshot).
15033
15034@item tfind none
15035Stop debugging trace snapshots, resume @emph{live} debugging.
15036
15037@item tfind end
15038Same as @samp{tfind none}.
15039
15040@item tfind
310cdbb6
YQ
15041No argument means find the next trace snapshot or find the first
15042one if no trace snapshot is selected.
b37052ae
EZ
15043
15044@item tfind -
15045Find the previous trace snapshot before the current one. This permits
15046retracing earlier steps.
15047
15048@item tfind tracepoint @var{num}
15049Find the next snapshot associated with tracepoint @var{num}. Search
15050proceeds forward from the last examined trace snapshot. If no
15051argument @var{num} is given, it means find the next snapshot collected
15052for the same tracepoint as the current snapshot.
15053
15054@item tfind pc @var{addr}
15055Find the next snapshot associated with the value @var{addr} of the
15056program counter. Search proceeds forward from the last examined trace
15057snapshot. If no argument @var{addr} is given, it means find the next
15058snapshot with the same value of PC as the current snapshot.
15059
15060@item tfind outside @var{addr1}, @var{addr2}
15061Find the next snapshot whose PC is outside the given range of
081dfbf7 15062addresses (exclusive).
b37052ae
EZ
15063
15064@item tfind range @var{addr1}, @var{addr2}
15065Find the next snapshot whose PC is between @var{addr1} and
081dfbf7 15066@var{addr2} (inclusive).
b37052ae
EZ
15067
15068@item tfind line @r{[}@var{file}:@r{]}@var{n}
15069Find the next snapshot associated with the source line @var{n}. If
15070the optional argument @var{file} is given, refer to line @var{n} in
15071that source file. Search proceeds forward from the last examined
15072trace snapshot. If no argument @var{n} is given, it means find the
15073next line other than the one currently being examined; thus saying
15074@code{tfind line} repeatedly can appear to have the same effect as
15075stepping from line to line in a @emph{live} debugging session.
15076@end table
15077
15078The default arguments for the @code{tfind} commands are specifically
15079designed to make it easy to scan through the trace buffer. For
15080instance, @code{tfind} with no argument selects the next trace
15081snapshot, and @code{tfind -} with no argument selects the previous
15082trace snapshot. So, by giving one @code{tfind} command, and then
15083simply hitting @key{RET} repeatedly you can examine all the trace
15084snapshots in order. Or, by saying @code{tfind -} and then hitting
15085@key{RET} repeatedly you can examine the snapshots in reverse order.
15086The @code{tfind line} command with no argument selects the snapshot
15087for the next source line executed. The @code{tfind pc} command with
15088no argument selects the next snapshot with the same program counter
15089(PC) as the current frame. The @code{tfind tracepoint} command with
15090no argument selects the next trace snapshot collected by the same
15091tracepoint as the current one.
15092
15093In addition to letting you scan through the trace buffer manually,
15094these commands make it easy to construct @value{GDBN} scripts that
15095scan through the trace buffer and print out whatever collected data
15096you are interested in. Thus, if we want to examine the PC, FP, and SP
15097registers from each trace frame in the buffer, we can say this:
15098
15099@smallexample
15100(@value{GDBP}) @b{tfind start}
15101(@value{GDBP}) @b{while ($trace_frame != -1)}
15102> printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
15103 $trace_frame, $pc, $sp, $fp
15104> tfind
15105> end
15106
15107Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
15108Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
15109Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
15110Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
15111Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
15112Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
15113Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
15114Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
15115Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
15116Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
15117Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
15118@end smallexample
15119
15120Or, if we want to examine the variable @code{X} at each source line in
15121the buffer:
15122
15123@smallexample
15124(@value{GDBP}) @b{tfind start}
15125(@value{GDBP}) @b{while ($trace_frame != -1)}
15126> printf "Frame %d, X == %d\n", $trace_frame, X
15127> tfind line
15128> end
15129
15130Frame 0, X = 1
15131Frame 7, X = 2
15132Frame 13, X = 255
15133@end smallexample
15134
15135@node tdump
15136@subsection @code{tdump}
15137@kindex tdump
15138@cindex dump all data collected at tracepoint
15139@cindex tracepoint data, display
15140
15141This command takes no arguments. It prints all the data collected at
15142the current trace snapshot.
15143
15144@smallexample
15145(@value{GDBP}) @b{trace 444}
15146(@value{GDBP}) @b{actions}
15147Enter actions for tracepoint #2, one per line:
15148> collect $regs, $locals, $args, gdb_long_test
15149> end
15150
15151(@value{GDBP}) @b{tstart}
15152
15153(@value{GDBP}) @b{tfind line 444}
15154#0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
15155at gdb_test.c:444
15156444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
15157
15158(@value{GDBP}) @b{tdump}
15159Data collected at tracepoint 2, trace frame 1:
15160d0 0xc4aa0085 -995491707
15161d1 0x18 24
15162d2 0x80 128
15163d3 0x33 51
15164d4 0x71aea3d 119204413
15165d5 0x22 34
15166d6 0xe0 224
15167d7 0x380035 3670069
15168a0 0x19e24a 1696330
15169a1 0x3000668 50333288
15170a2 0x100 256
15171a3 0x322000 3284992
15172a4 0x3000698 50333336
15173a5 0x1ad3cc 1758156
15174fp 0x30bf3c 0x30bf3c
15175sp 0x30bf34 0x30bf34
15176ps 0x0 0
15177pc 0x20b2c8 0x20b2c8
15178fpcontrol 0x0 0
15179fpstatus 0x0 0
15180fpiaddr 0x0 0
15181p = 0x20e5b4 "gdb-test"
15182p1 = (void *) 0x11
15183p2 = (void *) 0x22
15184p3 = (void *) 0x33
15185p4 = (void *) 0x44
15186p5 = (void *) 0x55
15187p6 = (void *) 0x66
15188gdb_long_test = 17 '\021'
15189
15190(@value{GDBP})
15191@end smallexample
15192
af54718e
SS
15193@code{tdump} works by scanning the tracepoint's current collection
15194actions and printing the value of each expression listed. So
15195@code{tdump} can fail, if after a run, you change the tracepoint's
15196actions to mention variables that were not collected during the run.
15197
15198Also, for tracepoints with @code{while-stepping} loops, @code{tdump}
15199uses the collected value of @code{$pc} to distinguish between trace
15200frames that were collected at the tracepoint hit, and frames that were
15201collected while stepping. This allows it to correctly choose whether
15202to display the basic list of collections, or the collections from the
15203body of the while-stepping loop. However, if @code{$pc} was not collected,
15204then @code{tdump} will always attempt to dump using the basic collection
15205list, and may fail if a while-stepping frame does not include all the
15206same data that is collected at the tracepoint hit.
15207@c This is getting pretty arcane, example would be good.
15208
6149aea9
PA
15209@node save tracepoints
15210@subsection @code{save tracepoints @var{filename}}
15211@kindex save tracepoints
b37052ae
EZ
15212@kindex save-tracepoints
15213@cindex save tracepoints for future sessions
15214
15215This command saves all current tracepoint definitions together with
15216their actions and passcounts, into a file @file{@var{filename}}
15217suitable for use in a later debugging session. To read the saved
15218tracepoint definitions, use the @code{source} command (@pxref{Command
6149aea9
PA
15219Files}). The @w{@code{save-tracepoints}} command is a deprecated
15220alias for @w{@code{save tracepoints}}
b37052ae
EZ
15221
15222@node Tracepoint Variables
15223@section Convenience Variables for Tracepoints
15224@cindex tracepoint variables
15225@cindex convenience variables for tracepoints
15226
15227@table @code
15228@vindex $trace_frame
15229@item (int) $trace_frame
15230The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
15231snapshot is selected.
15232
15233@vindex $tracepoint
15234@item (int) $tracepoint
15235The tracepoint for the current trace snapshot.
15236
15237@vindex $trace_line
15238@item (int) $trace_line
15239The line number for the current trace snapshot.
15240
15241@vindex $trace_file
15242@item (char []) $trace_file
15243The source file for the current trace snapshot.
15244
15245@vindex $trace_func
15246@item (char []) $trace_func
15247The name of the function containing @code{$tracepoint}.
15248@end table
15249
15250Note: @code{$trace_file} is not suitable for use in @code{printf},
15251use @code{output} instead.
15252
15253Here's a simple example of using these convenience variables for
15254stepping through all the trace snapshots and printing some of their
f61e138d
SS
15255data. Note that these are not the same as trace state variables,
15256which are managed by the target.
b37052ae
EZ
15257
15258@smallexample
15259(@value{GDBP}) @b{tfind start}
15260
15261(@value{GDBP}) @b{while $trace_frame != -1}
15262> output $trace_file
15263> printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
15264> tfind
15265> end
15266@end smallexample
15267
00bf0b85
SS
15268@node Trace Files
15269@section Using Trace Files
15270@cindex trace files
15271
15272In some situations, the target running a trace experiment may no
15273longer be available; perhaps it crashed, or the hardware was needed
15274for a different activity. To handle these cases, you can arrange to
15275dump the trace data into a file, and later use that file as a source
15276of trace data, via the @code{target tfile} command.
15277
15278@table @code
15279
15280@kindex tsave
15281@item tsave [ -r ] @var{filename}
d0353e76 15282@itemx tsave [-ctf] @var{dirname}
00bf0b85
SS
15283Save the trace data to @var{filename}. By default, this command
15284assumes that @var{filename} refers to the host filesystem, so if
15285necessary @value{GDBN} will copy raw trace data up from the target and
15286then save it. If the target supports it, you can also supply the
15287optional argument @code{-r} (``remote'') to direct the target to save
15288the data directly into @var{filename} in its own filesystem, which may be
15289more efficient if the trace buffer is very large. (Note, however, that
15290@code{target tfile} can only read from files accessible to the host.)
d0353e76 15291By default, this command will save trace frame in tfile format.
be06ba8c 15292You can supply the optional argument @code{-ctf} to save data in CTF
d0353e76
YQ
15293format. The @dfn{Common Trace Format} (CTF) is proposed as a trace format
15294that can be shared by multiple debugging and tracing tools. Please go to
15295@indicateurl{http://www.efficios.com/ctf} to get more information.
00bf0b85
SS
15296
15297@kindex target tfile
15298@kindex tfile
393fd4c3
YQ
15299@kindex target ctf
15300@kindex ctf
00bf0b85 15301@item target tfile @var{filename}
393fd4c3
YQ
15302@itemx target ctf @var{dirname}
15303Use the file named @var{filename} or directory named @var{dirname} as
15304a source of trace data. Commands that examine data work as they do with
15305a live target, but it is not possible to run any new trace experiments.
15306@code{tstatus} will report the state of the trace run at the moment
15307the data was saved, as well as the current trace frame you are examining.
697aa1b7 15308Both @var{filename} and @var{dirname} must be on a filesystem accessible to
393fd4c3
YQ
15309the host.
15310
15311@smallexample
15312(@value{GDBP}) target ctf ctf.ctf
15313(@value{GDBP}) tfind
15314Found trace frame 0, tracepoint 2
1531539 ++a; /* set tracepoint 1 here */
15316(@value{GDBP}) tdump
15317Data collected at tracepoint 2, trace frame 0:
15318i = 0
15319a = 0
15320b = 1 '\001'
15321c = @{"123", "456", "789", "123", "456", "789"@}
15322d = @{@{@{a = 1, b = 2@}, @{a = 3, b = 4@}@}, @{@{a = 5, b = 6@}, @{a = 7, b = 8@}@}@}
15323(@value{GDBP}) p b
15324$1 = 1
15325@end smallexample
00bf0b85
SS
15326
15327@end table
15328
df0cd8c5
JB
15329@node Overlays
15330@chapter Debugging Programs That Use Overlays
15331@cindex overlays
15332
15333If your program is too large to fit completely in your target system's
15334memory, you can sometimes use @dfn{overlays} to work around this
15335problem. @value{GDBN} provides some support for debugging programs that
15336use overlays.
15337
15338@menu
15339* How Overlays Work:: A general explanation of overlays.
15340* Overlay Commands:: Managing overlays in @value{GDBN}.
15341* Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
15342 mapped by asking the inferior.
15343* Overlay Sample Program:: A sample program using overlays.
15344@end menu
15345
15346@node How Overlays Work
15347@section How Overlays Work
15348@cindex mapped overlays
15349@cindex unmapped overlays
15350@cindex load address, overlay's
15351@cindex mapped address
15352@cindex overlay area
15353
15354Suppose you have a computer whose instruction address space is only 64
15355kilobytes long, but which has much more memory which can be accessed by
15356other means: special instructions, segment registers, or memory
15357management hardware, for example. Suppose further that you want to
15358adapt a program which is larger than 64 kilobytes to run on this system.
15359
15360One solution is to identify modules of your program which are relatively
15361independent, and need not call each other directly; call these modules
15362@dfn{overlays}. Separate the overlays from the main program, and place
15363their machine code in the larger memory. Place your main program in
15364instruction memory, but leave at least enough space there to hold the
15365largest overlay as well.
15366
15367Now, to call a function located in an overlay, you must first copy that
15368overlay's machine code from the large memory into the space set aside
15369for it in the instruction memory, and then jump to its entry point
15370there.
15371
c928edc0
AC
15372@c NB: In the below the mapped area's size is greater or equal to the
15373@c size of all overlays. This is intentional to remind the developer
15374@c that overlays don't necessarily need to be the same size.
15375
474c8240 15376@smallexample
df0cd8c5 15377@group
c928edc0
AC
15378 Data Instruction Larger
15379Address Space Address Space Address Space
15380+-----------+ +-----------+ +-----------+
15381| | | | | |
15382+-----------+ +-----------+ +-----------+<-- overlay 1
15383| program | | main | .----| overlay 1 | load address
15384| variables | | program | | +-----------+
15385| and heap | | | | | |
15386+-----------+ | | | +-----------+<-- overlay 2
15387| | +-----------+ | | | load address
15388+-----------+ | | | .-| overlay 2 |
15389 | | | | | |
15390 mapped --->+-----------+ | | +-----------+
15391 address | | | | | |
15392 | overlay | <-' | | |
15393 | area | <---' +-----------+<-- overlay 3
15394 | | <---. | | load address
15395 +-----------+ `--| overlay 3 |
15396 | | | |
15397 +-----------+ | |
15398 +-----------+
15399 | |
15400 +-----------+
15401
15402 @anchor{A code overlay}A code overlay
df0cd8c5 15403@end group
474c8240 15404@end smallexample
df0cd8c5 15405
c928edc0
AC
15406The diagram (@pxref{A code overlay}) shows a system with separate data
15407and instruction address spaces. To map an overlay, the program copies
15408its code from the larger address space to the instruction address space.
15409Since the overlays shown here all use the same mapped address, only one
15410may be mapped at a time. For a system with a single address space for
15411data and instructions, the diagram would be similar, except that the
15412program variables and heap would share an address space with the main
15413program and the overlay area.
df0cd8c5
JB
15414
15415An overlay loaded into instruction memory and ready for use is called a
15416@dfn{mapped} overlay; its @dfn{mapped address} is its address in the
15417instruction memory. An overlay not present (or only partially present)
15418in instruction memory is called @dfn{unmapped}; its @dfn{load address}
15419is its address in the larger memory. The mapped address is also called
15420the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
15421called the @dfn{load memory address}, or @dfn{LMA}.
15422
15423Unfortunately, overlays are not a completely transparent way to adapt a
15424program to limited instruction memory. They introduce a new set of
15425global constraints you must keep in mind as you design your program:
15426
15427@itemize @bullet
15428
15429@item
15430Before calling or returning to a function in an overlay, your program
15431must make sure that overlay is actually mapped. Otherwise, the call or
15432return will transfer control to the right address, but in the wrong
15433overlay, and your program will probably crash.
15434
15435@item
15436If the process of mapping an overlay is expensive on your system, you
15437will need to choose your overlays carefully to minimize their effect on
15438your program's performance.
15439
15440@item
15441The executable file you load onto your system must contain each
15442overlay's instructions, appearing at the overlay's load address, not its
15443mapped address. However, each overlay's instructions must be relocated
15444and its symbols defined as if the overlay were at its mapped address.
15445You can use GNU linker scripts to specify different load and relocation
15446addresses for pieces of your program; see @ref{Overlay Description,,,
15447ld.info, Using ld: the GNU linker}.
15448
15449@item
15450The procedure for loading executable files onto your system must be able
15451to load their contents into the larger address space as well as the
15452instruction and data spaces.
15453
15454@end itemize
15455
15456The overlay system described above is rather simple, and could be
15457improved in many ways:
15458
15459@itemize @bullet
15460
15461@item
15462If your system has suitable bank switch registers or memory management
15463hardware, you could use those facilities to make an overlay's load area
15464contents simply appear at their mapped address in instruction space.
15465This would probably be faster than copying the overlay to its mapped
15466area in the usual way.
15467
15468@item
15469If your overlays are small enough, you could set aside more than one
15470overlay area, and have more than one overlay mapped at a time.
15471
15472@item
15473You can use overlays to manage data, as well as instructions. In
15474general, data overlays are even less transparent to your design than
15475code overlays: whereas code overlays only require care when you call or
15476return to functions, data overlays require care every time you access
15477the data. Also, if you change the contents of a data overlay, you
15478must copy its contents back out to its load address before you can copy a
15479different data overlay into the same mapped area.
15480
15481@end itemize
15482
15483
15484@node Overlay Commands
15485@section Overlay Commands
15486
15487To use @value{GDBN}'s overlay support, each overlay in your program must
15488correspond to a separate section of the executable file. The section's
15489virtual memory address and load memory address must be the overlay's
15490mapped and load addresses. Identifying overlays with sections allows
15491@value{GDBN} to determine the appropriate address of a function or
15492variable, depending on whether the overlay is mapped or not.
15493
15494@value{GDBN}'s overlay commands all start with the word @code{overlay};
15495you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
15496
15497@table @code
15498@item overlay off
4644b6e3 15499@kindex overlay
df0cd8c5
JB
15500Disable @value{GDBN}'s overlay support. When overlay support is
15501disabled, @value{GDBN} assumes that all functions and variables are
15502always present at their mapped addresses. By default, @value{GDBN}'s
15503overlay support is disabled.
15504
15505@item overlay manual
df0cd8c5
JB
15506@cindex manual overlay debugging
15507Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
15508relies on you to tell it which overlays are mapped, and which are not,
15509using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
15510commands described below.
15511
15512@item overlay map-overlay @var{overlay}
15513@itemx overlay map @var{overlay}
df0cd8c5
JB
15514@cindex map an overlay
15515Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
15516be the name of the object file section containing the overlay. When an
15517overlay is mapped, @value{GDBN} assumes it can find the overlay's
15518functions and variables at their mapped addresses. @value{GDBN} assumes
15519that any other overlays whose mapped ranges overlap that of
15520@var{overlay} are now unmapped.
15521
15522@item overlay unmap-overlay @var{overlay}
15523@itemx overlay unmap @var{overlay}
df0cd8c5
JB
15524@cindex unmap an overlay
15525Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
15526must be the name of the object file section containing the overlay.
15527When an overlay is unmapped, @value{GDBN} assumes it can find the
15528overlay's functions and variables at their load addresses.
15529
15530@item overlay auto
df0cd8c5
JB
15531Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
15532consults a data structure the overlay manager maintains in the inferior
15533to see which overlays are mapped. For details, see @ref{Automatic
15534Overlay Debugging}.
15535
15536@item overlay load-target
15537@itemx overlay load
df0cd8c5
JB
15538@cindex reloading the overlay table
15539Re-read the overlay table from the inferior. Normally, @value{GDBN}
15540re-reads the table @value{GDBN} automatically each time the inferior
15541stops, so this command should only be necessary if you have changed the
15542overlay mapping yourself using @value{GDBN}. This command is only
15543useful when using automatic overlay debugging.
15544
15545@item overlay list-overlays
15546@itemx overlay list
15547@cindex listing mapped overlays
15548Display a list of the overlays currently mapped, along with their mapped
15549addresses, load addresses, and sizes.
15550
15551@end table
15552
15553Normally, when @value{GDBN} prints a code address, it includes the name
15554of the function the address falls in:
15555
474c8240 15556@smallexample
f7dc1244 15557(@value{GDBP}) print main
df0cd8c5 15558$3 = @{int ()@} 0x11a0 <main>
474c8240 15559@end smallexample
df0cd8c5
JB
15560@noindent
15561When overlay debugging is enabled, @value{GDBN} recognizes code in
15562unmapped overlays, and prints the names of unmapped functions with
15563asterisks around them. For example, if @code{foo} is a function in an
15564unmapped overlay, @value{GDBN} prints it this way:
15565
474c8240 15566@smallexample
f7dc1244 15567(@value{GDBP}) overlay list
df0cd8c5 15568No sections are mapped.
f7dc1244 15569(@value{GDBP}) print foo
df0cd8c5 15570$5 = @{int (int)@} 0x100000 <*foo*>
474c8240 15571@end smallexample
df0cd8c5
JB
15572@noindent
15573When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
15574name normally:
15575
474c8240 15576@smallexample
f7dc1244 15577(@value{GDBP}) overlay list
b383017d 15578Section .ov.foo.text, loaded at 0x100000 - 0x100034,
df0cd8c5 15579 mapped at 0x1016 - 0x104a
f7dc1244 15580(@value{GDBP}) print foo
df0cd8c5 15581$6 = @{int (int)@} 0x1016 <foo>
474c8240 15582@end smallexample
df0cd8c5
JB
15583
15584When overlay debugging is enabled, @value{GDBN} can find the correct
15585address for functions and variables in an overlay, whether or not the
15586overlay is mapped. This allows most @value{GDBN} commands, like
15587@code{break} and @code{disassemble}, to work normally, even on unmapped
15588code. However, @value{GDBN}'s breakpoint support has some limitations:
15589
15590@itemize @bullet
15591@item
15592@cindex breakpoints in overlays
15593@cindex overlays, setting breakpoints in
15594You can set breakpoints in functions in unmapped overlays, as long as
15595@value{GDBN} can write to the overlay at its load address.
15596@item
15597@value{GDBN} can not set hardware or simulator-based breakpoints in
15598unmapped overlays. However, if you set a breakpoint at the end of your
15599overlay manager (and tell @value{GDBN} which overlays are now mapped, if
15600you are using manual overlay management), @value{GDBN} will re-set its
15601breakpoints properly.
15602@end itemize
15603
15604
15605@node Automatic Overlay Debugging
15606@section Automatic Overlay Debugging
15607@cindex automatic overlay debugging
15608
15609@value{GDBN} can automatically track which overlays are mapped and which
15610are not, given some simple co-operation from the overlay manager in the
15611inferior. If you enable automatic overlay debugging with the
15612@code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
15613looks in the inferior's memory for certain variables describing the
15614current state of the overlays.
15615
15616Here are the variables your overlay manager must define to support
15617@value{GDBN}'s automatic overlay debugging:
15618
15619@table @asis
15620
15621@item @code{_ovly_table}:
15622This variable must be an array of the following structures:
15623
474c8240 15624@smallexample
df0cd8c5
JB
15625struct
15626@{
15627 /* The overlay's mapped address. */
15628 unsigned long vma;
15629
15630 /* The size of the overlay, in bytes. */
15631 unsigned long size;
15632
15633 /* The overlay's load address. */
15634 unsigned long lma;
15635
15636 /* Non-zero if the overlay is currently mapped;
15637 zero otherwise. */
15638 unsigned long mapped;
15639@}
474c8240 15640@end smallexample
df0cd8c5
JB
15641
15642@item @code{_novlys}:
15643This variable must be a four-byte signed integer, holding the total
15644number of elements in @code{_ovly_table}.
15645
15646@end table
15647
15648To decide whether a particular overlay is mapped or not, @value{GDBN}
15649looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
15650@code{lma} members equal the VMA and LMA of the overlay's section in the
15651executable file. When @value{GDBN} finds a matching entry, it consults
15652the entry's @code{mapped} member to determine whether the overlay is
15653currently mapped.
15654
81d46470 15655In addition, your overlay manager may define a function called
def71bfa 15656@code{_ovly_debug_event}. If this function is defined, @value{GDBN}
81d46470
MS
15657will silently set a breakpoint there. If the overlay manager then
15658calls this function whenever it has changed the overlay table, this
15659will enable @value{GDBN} to accurately keep track of which overlays
15660are in program memory, and update any breakpoints that may be set
b383017d 15661in overlays. This will allow breakpoints to work even if the
81d46470
MS
15662overlays are kept in ROM or other non-writable memory while they
15663are not being executed.
df0cd8c5
JB
15664
15665@node Overlay Sample Program
15666@section Overlay Sample Program
15667@cindex overlay example program
15668
15669When linking a program which uses overlays, you must place the overlays
15670at their load addresses, while relocating them to run at their mapped
15671addresses. To do this, you must write a linker script (@pxref{Overlay
15672Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
15673since linker scripts are specific to a particular host system, target
15674architecture, and target memory layout, this manual cannot provide
15675portable sample code demonstrating @value{GDBN}'s overlay support.
15676
15677However, the @value{GDBN} source distribution does contain an overlaid
15678program, with linker scripts for a few systems, as part of its test
15679suite. The program consists of the following files from
15680@file{gdb/testsuite/gdb.base}:
15681
15682@table @file
15683@item overlays.c
15684The main program file.
15685@item ovlymgr.c
15686A simple overlay manager, used by @file{overlays.c}.
15687@item foo.c
15688@itemx bar.c
15689@itemx baz.c
15690@itemx grbx.c
15691Overlay modules, loaded and used by @file{overlays.c}.
15692@item d10v.ld
15693@itemx m32r.ld
15694Linker scripts for linking the test program on the @code{d10v-elf}
15695and @code{m32r-elf} targets.
15696@end table
15697
15698You can build the test program using the @code{d10v-elf} GCC
15699cross-compiler like this:
15700
474c8240 15701@smallexample
df0cd8c5
JB
15702$ d10v-elf-gcc -g -c overlays.c
15703$ d10v-elf-gcc -g -c ovlymgr.c
15704$ d10v-elf-gcc -g -c foo.c
15705$ d10v-elf-gcc -g -c bar.c
15706$ d10v-elf-gcc -g -c baz.c
15707$ d10v-elf-gcc -g -c grbx.c
15708$ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
15709 baz.o grbx.o -Wl,-Td10v.ld -o overlays
474c8240 15710@end smallexample
df0cd8c5
JB
15711
15712The build process is identical for any other architecture, except that
15713you must substitute the appropriate compiler and linker script for the
15714target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
15715
15716
6d2ebf8b 15717@node Languages
c906108c
SS
15718@chapter Using @value{GDBN} with Different Languages
15719@cindex languages
15720
c906108c
SS
15721Although programming languages generally have common aspects, they are
15722rarely expressed in the same manner. For instance, in ANSI C,
15723dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
15724Modula-2, it is accomplished by @code{p^}. Values can also be
5d161b24 15725represented (and displayed) differently. Hex numbers in C appear as
c906108c 15726@samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
c906108c
SS
15727
15728@cindex working language
15729Language-specific information is built into @value{GDBN} for some languages,
15730allowing you to express operations like the above in your program's
15731native language, and allowing @value{GDBN} to output values in a manner
15732consistent with the syntax of your program's native language. The
15733language you use to build expressions is called the @dfn{working
15734language}.
15735
15736@menu
15737* Setting:: Switching between source languages
15738* Show:: Displaying the language
c906108c 15739* Checks:: Type and range checks
79a6e687
BW
15740* Supported Languages:: Supported languages
15741* Unsupported Languages:: Unsupported languages
c906108c
SS
15742@end menu
15743
6d2ebf8b 15744@node Setting
79a6e687 15745@section Switching Between Source Languages
c906108c
SS
15746
15747There are two ways to control the working language---either have @value{GDBN}
15748set it automatically, or select it manually yourself. You can use the
15749@code{set language} command for either purpose. On startup, @value{GDBN}
15750defaults to setting the language automatically. The working language is
15751used to determine how expressions you type are interpreted, how values
15752are printed, etc.
15753
15754In addition to the working language, every source file that
15755@value{GDBN} knows about has its own working language. For some object
15756file formats, the compiler might indicate which language a particular
15757source file is in. However, most of the time @value{GDBN} infers the
15758language from the name of the file. The language of a source file
b37052ae 15759controls whether C@t{++} names are demangled---this way @code{backtrace} can
c906108c 15760show each frame appropriately for its own language. There is no way to
d4f3574e
SS
15761set the language of a source file from within @value{GDBN}, but you can
15762set the language associated with a filename extension. @xref{Show, ,
79a6e687 15763Displaying the Language}.
c906108c
SS
15764
15765This is most commonly a problem when you use a program, such
5d161b24 15766as @code{cfront} or @code{f2c}, that generates C but is written in
c906108c
SS
15767another language. In that case, make the
15768program use @code{#line} directives in its C output; that way
15769@value{GDBN} will know the correct language of the source code of the original
15770program, and will display that source code, not the generated C code.
15771
15772@menu
15773* Filenames:: Filename extensions and languages.
15774* Manually:: Setting the working language manually
15775* Automatically:: Having @value{GDBN} infer the source language
15776@end menu
15777
6d2ebf8b 15778@node Filenames
79a6e687 15779@subsection List of Filename Extensions and Languages
c906108c
SS
15780
15781If a source file name ends in one of the following extensions, then
15782@value{GDBN} infers that its language is the one indicated.
15783
15784@table @file
e07c999f
PH
15785@item .ada
15786@itemx .ads
15787@itemx .adb
15788@itemx .a
15789Ada source file.
c906108c
SS
15790
15791@item .c
15792C source file
15793
15794@item .C
15795@itemx .cc
15796@itemx .cp
15797@itemx .cpp
15798@itemx .cxx
15799@itemx .c++
b37052ae 15800C@t{++} source file
c906108c 15801
6aecb9c2
JB
15802@item .d
15803D source file
15804
b37303ee
AF
15805@item .m
15806Objective-C source file
15807
c906108c
SS
15808@item .f
15809@itemx .F
15810Fortran source file
15811
c906108c
SS
15812@item .mod
15813Modula-2 source file
c906108c
SS
15814
15815@item .s
15816@itemx .S
15817Assembler source file. This actually behaves almost like C, but
15818@value{GDBN} does not skip over function prologues when stepping.
15819@end table
15820
15821In addition, you may set the language associated with a filename
79a6e687 15822extension. @xref{Show, , Displaying the Language}.
c906108c 15823
6d2ebf8b 15824@node Manually
79a6e687 15825@subsection Setting the Working Language
c906108c
SS
15826
15827If you allow @value{GDBN} to set the language automatically,
15828expressions are interpreted the same way in your debugging session and
15829your program.
15830
15831@kindex set language
15832If you wish, you may set the language manually. To do this, issue the
15833command @samp{set language @var{lang}}, where @var{lang} is the name of
5d161b24 15834a language, such as
c906108c 15835@code{c} or @code{modula-2}.
c906108c
SS
15836For a list of the supported languages, type @samp{set language}.
15837
c906108c
SS
15838Setting the language manually prevents @value{GDBN} from updating the working
15839language automatically. This can lead to confusion if you try
15840to debug a program when the working language is not the same as the
15841source language, when an expression is acceptable to both
15842languages---but means different things. For instance, if the current
15843source file were written in C, and @value{GDBN} was parsing Modula-2, a
15844command such as:
15845
474c8240 15846@smallexample
c906108c 15847print a = b + c
474c8240 15848@end smallexample
c906108c
SS
15849
15850@noindent
15851might not have the effect you intended. In C, this means to add
15852@code{b} and @code{c} and place the result in @code{a}. The result
15853printed would be the value of @code{a}. In Modula-2, this means to compare
15854@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
c906108c 15855
6d2ebf8b 15856@node Automatically
79a6e687 15857@subsection Having @value{GDBN} Infer the Source Language
c906108c
SS
15858
15859To have @value{GDBN} set the working language automatically, use
15860@samp{set language local} or @samp{set language auto}. @value{GDBN}
15861then infers the working language. That is, when your program stops in a
15862frame (usually by encountering a breakpoint), @value{GDBN} sets the
15863working language to the language recorded for the function in that
15864frame. If the language for a frame is unknown (that is, if the function
15865or block corresponding to the frame was defined in a source file that
15866does not have a recognized extension), the current working language is
15867not changed, and @value{GDBN} issues a warning.
15868
15869This may not seem necessary for most programs, which are written
15870entirely in one source language. However, program modules and libraries
15871written in one source language can be used by a main program written in
15872a different source language. Using @samp{set language auto} in this
15873case frees you from having to set the working language manually.
15874
6d2ebf8b 15875@node Show
79a6e687 15876@section Displaying the Language
c906108c
SS
15877
15878The following commands help you find out which language is the
15879working language, and also what language source files were written in.
15880
c906108c
SS
15881@table @code
15882@item show language
403cb6b1 15883@anchor{show language}
9c16f35a 15884@kindex show language
c906108c
SS
15885Display the current working language. This is the
15886language you can use with commands such as @code{print} to
15887build and compute expressions that may involve variables in your program.
15888
15889@item info frame
4644b6e3 15890@kindex info frame@r{, show the source language}
5d161b24 15891Display the source language for this frame. This language becomes the
c906108c 15892working language if you use an identifier from this frame.
79a6e687 15893@xref{Frame Info, ,Information about a Frame}, to identify the other
c906108c
SS
15894information listed here.
15895
15896@item info source
4644b6e3 15897@kindex info source@r{, show the source language}
c906108c 15898Display the source language of this source file.
5d161b24 15899@xref{Symbols, ,Examining the Symbol Table}, to identify the other
c906108c
SS
15900information listed here.
15901@end table
15902
15903In unusual circumstances, you may have source files with extensions
15904not in the standard list. You can then set the extension associated
15905with a language explicitly:
15906
c906108c 15907@table @code
09d4efe1 15908@item set extension-language @var{ext} @var{language}
9c16f35a 15909@kindex set extension-language
09d4efe1
EZ
15910Tell @value{GDBN} that source files with extension @var{ext} are to be
15911assumed as written in the source language @var{language}.
c906108c
SS
15912
15913@item info extensions
9c16f35a 15914@kindex info extensions
c906108c
SS
15915List all the filename extensions and the associated languages.
15916@end table
15917
6d2ebf8b 15918@node Checks
79a6e687 15919@section Type and Range Checking
c906108c 15920
c906108c
SS
15921Some languages are designed to guard you against making seemingly common
15922errors through a series of compile- and run-time checks. These include
a451cb65 15923checking the type of arguments to functions and operators and making
c906108c
SS
15924sure mathematical overflows are caught at run time. Checks such as
15925these help to ensure a program's correctness once it has been compiled
a451cb65 15926by eliminating type mismatches and providing active checks for range
c906108c
SS
15927errors when your program is running.
15928
a451cb65
KS
15929By default @value{GDBN} checks for these errors according to the
15930rules of the current source language. Although @value{GDBN} does not check
15931the statements in your program, it can check expressions entered directly
15932into @value{GDBN} for evaluation via the @code{print} command, for example.
c906108c
SS
15933
15934@menu
15935* Type Checking:: An overview of type checking
15936* Range Checking:: An overview of range checking
15937@end menu
15938
15939@cindex type checking
15940@cindex checks, type
6d2ebf8b 15941@node Type Checking
79a6e687 15942@subsection An Overview of Type Checking
c906108c 15943
a451cb65 15944Some languages, such as C and C@t{++}, are strongly typed, meaning that the
c906108c
SS
15945arguments to operators and functions have to be of the correct type,
15946otherwise an error occurs. These checks prevent type mismatch
15947errors from ever causing any run-time problems. For example,
15948
15949@smallexample
a451cb65
KS
15950int klass::my_method(char *b) @{ return b ? 1 : 2; @}
15951
15952(@value{GDBP}) print obj.my_method (0)
15953$1 = 2
c906108c 15954@exdent but
a451cb65
KS
15955(@value{GDBP}) print obj.my_method (0x1234)
15956Cannot resolve method klass::my_method to any overloaded instance
c906108c
SS
15957@end smallexample
15958
a451cb65
KS
15959The second example fails because in C@t{++} the integer constant
15960@samp{0x1234} is not type-compatible with the pointer parameter type.
c906108c 15961
a451cb65
KS
15962For the expressions you use in @value{GDBN} commands, you can tell
15963@value{GDBN} to not enforce strict type checking or
5d161b24 15964to treat any mismatches as errors and abandon the expression;
a451cb65
KS
15965When type checking is disabled, @value{GDBN} successfully evaluates
15966expressions like the second example above.
c906108c 15967
a451cb65 15968Even if type checking is off, there may be other reasons
5d161b24
DB
15969related to type that prevent @value{GDBN} from evaluating an expression.
15970For instance, @value{GDBN} does not know how to add an @code{int} and
15971a @code{struct foo}. These particular type errors have nothing to do
a451cb65
KS
15972with the language in use and usually arise from expressions which make
15973little sense to evaluate anyway.
c906108c 15974
a451cb65 15975@value{GDBN} provides some additional commands for controlling type checking:
c906108c 15976
c906108c
SS
15977@kindex set check type
15978@kindex show check type
15979@table @code
c906108c
SS
15980@item set check type on
15981@itemx set check type off
a451cb65 15982Set strict type checking on or off. If any type mismatches occur in
d4f3574e 15983evaluating an expression while type checking is on, @value{GDBN} prints a
c906108c
SS
15984message and aborts evaluation of the expression.
15985
a451cb65
KS
15986@item show check type
15987Show the current setting of type checking and whether @value{GDBN}
15988is enforcing strict type checking rules.
c906108c
SS
15989@end table
15990
15991@cindex range checking
15992@cindex checks, range
6d2ebf8b 15993@node Range Checking
79a6e687 15994@subsection An Overview of Range Checking
c906108c
SS
15995
15996In some languages (such as Modula-2), it is an error to exceed the
15997bounds of a type; this is enforced with run-time checks. Such range
15998checking is meant to ensure program correctness by making sure
15999computations do not overflow, or indices on an array element access do
16000not exceed the bounds of the array.
16001
16002For expressions you use in @value{GDBN} commands, you can tell
16003@value{GDBN} to treat range errors in one of three ways: ignore them,
16004always treat them as errors and abandon the expression, or issue
16005warnings but evaluate the expression anyway.
16006
16007A range error can result from numerical overflow, from exceeding an
16008array index bound, or when you type a constant that is not a member
16009of any type. Some languages, however, do not treat overflows as an
16010error. In many implementations of C, mathematical overflow causes the
16011result to ``wrap around'' to lower values---for example, if @var{m} is
16012the largest integer value, and @var{s} is the smallest, then
16013
474c8240 16014@smallexample
c906108c 16015@var{m} + 1 @result{} @var{s}
474c8240 16016@end smallexample
c906108c
SS
16017
16018This, too, is specific to individual languages, and in some cases
79a6e687
BW
16019specific to individual compilers or machines. @xref{Supported Languages, ,
16020Supported Languages}, for further details on specific languages.
c906108c
SS
16021
16022@value{GDBN} provides some additional commands for controlling the range checker:
16023
c906108c
SS
16024@kindex set check range
16025@kindex show check range
16026@table @code
16027@item set check range auto
16028Set range checking on or off based on the current working language.
79a6e687 16029@xref{Supported Languages, ,Supported Languages}, for the default settings for
c906108c
SS
16030each language.
16031
16032@item set check range on
16033@itemx set check range off
16034Set range checking on or off, overriding the default setting for the
16035current working language. A warning is issued if the setting does not
c3f6f71d
JM
16036match the language default. If a range error occurs and range checking is on,
16037then a message is printed and evaluation of the expression is aborted.
c906108c
SS
16038
16039@item set check range warn
16040Output messages when the @value{GDBN} range checker detects a range error,
16041but attempt to evaluate the expression anyway. Evaluating the
16042expression may still be impossible for other reasons, such as accessing
16043memory that the process does not own (a typical example from many Unix
16044systems).
16045
16046@item show range
16047Show the current setting of the range checker, and whether or not it is
16048being set automatically by @value{GDBN}.
16049@end table
c906108c 16050
79a6e687
BW
16051@node Supported Languages
16052@section Supported Languages
c906108c 16053
9c37b5ae 16054@value{GDBN} supports C, C@t{++}, D, Go, Objective-C, Fortran,
0bdfa368 16055OpenCL C, Pascal, Rust, assembly, Modula-2, and Ada.
cce74817 16056@c This is false ...
c906108c
SS
16057Some @value{GDBN} features may be used in expressions regardless of the
16058language you use: the @value{GDBN} @code{@@} and @code{::} operators,
16059and the @samp{@{type@}addr} construct (@pxref{Expressions,
16060,Expressions}) can be used with the constructs of any supported
16061language.
16062
16063The following sections detail to what degree each source language is
16064supported by @value{GDBN}. These sections are not meant to be language
16065tutorials or references, but serve only as a reference guide to what the
16066@value{GDBN} expression parser accepts, and what input and output
16067formats should look like for different languages. There are many good
16068books written on each of these languages; please look to these for a
16069language reference or tutorial.
16070
c906108c 16071@menu
b37303ee 16072* C:: C and C@t{++}
6aecb9c2 16073* D:: D
a766d390 16074* Go:: Go
b383017d 16075* Objective-C:: Objective-C
f4b8a18d 16076* OpenCL C:: OpenCL C
09d4efe1 16077* Fortran:: Fortran
9c16f35a 16078* Pascal:: Pascal
0bdfa368 16079* Rust:: Rust
b37303ee 16080* Modula-2:: Modula-2
e07c999f 16081* Ada:: Ada
c906108c
SS
16082@end menu
16083
6d2ebf8b 16084@node C
b37052ae 16085@subsection C and C@t{++}
7a292a7a 16086
b37052ae
EZ
16087@cindex C and C@t{++}
16088@cindex expressions in C or C@t{++}
c906108c 16089
b37052ae 16090Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
c906108c
SS
16091to both languages. Whenever this is the case, we discuss those languages
16092together.
16093
41afff9a
EZ
16094@cindex C@t{++}
16095@cindex @code{g++}, @sc{gnu} C@t{++} compiler
b37052ae
EZ
16096@cindex @sc{gnu} C@t{++}
16097The C@t{++} debugging facilities are jointly implemented by the C@t{++}
16098compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
16099effectively, you must compile your C@t{++} programs with a supported
16100C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
c906108c
SS
16101compiler (@code{aCC}).
16102
c906108c 16103@menu
b37052ae
EZ
16104* C Operators:: C and C@t{++} operators
16105* C Constants:: C and C@t{++} constants
79a6e687 16106* C Plus Plus Expressions:: C@t{++} expressions
b37052ae
EZ
16107* C Defaults:: Default settings for C and C@t{++}
16108* C Checks:: C and C@t{++} type and range checks
c906108c 16109* Debugging C:: @value{GDBN} and C
79a6e687 16110* Debugging C Plus Plus:: @value{GDBN} features for C@t{++}
febe4383 16111* Decimal Floating Point:: Numbers in Decimal Floating Point format
c906108c 16112@end menu
c906108c 16113
6d2ebf8b 16114@node C Operators
79a6e687 16115@subsubsection C and C@t{++} Operators
7a292a7a 16116
b37052ae 16117@cindex C and C@t{++} operators
c906108c
SS
16118
16119Operators must be defined on values of specific types. For instance,
16120@code{+} is defined on numbers, but not on structures. Operators are
5d161b24 16121often defined on groups of types.
c906108c 16122
b37052ae 16123For the purposes of C and C@t{++}, the following definitions hold:
c906108c
SS
16124
16125@itemize @bullet
53a5351d 16126
c906108c 16127@item
c906108c 16128@emph{Integral types} include @code{int} with any of its storage-class
b37052ae 16129specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
c906108c
SS
16130
16131@item
d4f3574e
SS
16132@emph{Floating-point types} include @code{float}, @code{double}, and
16133@code{long double} (if supported by the target platform).
c906108c
SS
16134
16135@item
53a5351d 16136@emph{Pointer types} include all types defined as @code{(@var{type} *)}.
c906108c
SS
16137
16138@item
16139@emph{Scalar types} include all of the above.
53a5351d 16140
c906108c
SS
16141@end itemize
16142
16143@noindent
16144The following operators are supported. They are listed here
16145in order of increasing precedence:
16146
16147@table @code
16148@item ,
16149The comma or sequencing operator. Expressions in a comma-separated list
16150are evaluated from left to right, with the result of the entire
16151expression being the last expression evaluated.
16152
16153@item =
16154Assignment. The value of an assignment expression is the value
16155assigned. Defined on scalar types.
16156
16157@item @var{op}=
16158Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
16159and translated to @w{@code{@var{a} = @var{a op b}}}.
697aa1b7 16160@w{@code{@var{op}=}} and @code{=} have the same precedence. The operator
c906108c
SS
16161@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
16162@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
16163
16164@item ?:
16165The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
697aa1b7
EZ
16166of as: if @var{a} then @var{b} else @var{c}. The argument @var{a}
16167should be of an integral type.
c906108c
SS
16168
16169@item ||
16170Logical @sc{or}. Defined on integral types.
16171
16172@item &&
16173Logical @sc{and}. Defined on integral types.
16174
16175@item |
16176Bitwise @sc{or}. Defined on integral types.
16177
16178@item ^
16179Bitwise exclusive-@sc{or}. Defined on integral types.
16180
16181@item &
16182Bitwise @sc{and}. Defined on integral types.
16183
16184@item ==@r{, }!=
16185Equality and inequality. Defined on scalar types. The value of these
16186expressions is 0 for false and non-zero for true.
16187
16188@item <@r{, }>@r{, }<=@r{, }>=
16189Less than, greater than, less than or equal, greater than or equal.
16190Defined on scalar types. The value of these expressions is 0 for false
16191and non-zero for true.
16192
16193@item <<@r{, }>>
16194left shift, and right shift. Defined on integral types.
16195
16196@item @@
16197The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
16198
16199@item +@r{, }-
16200Addition and subtraction. Defined on integral types, floating-point types and
16201pointer types.
16202
16203@item *@r{, }/@r{, }%
16204Multiplication, division, and modulus. Multiplication and division are
16205defined on integral and floating-point types. Modulus is defined on
16206integral types.
16207
16208@item ++@r{, }--
16209Increment and decrement. When appearing before a variable, the
16210operation is performed before the variable is used in an expression;
16211when appearing after it, the variable's value is used before the
16212operation takes place.
16213
16214@item *
16215Pointer dereferencing. Defined on pointer types. Same precedence as
16216@code{++}.
16217
16218@item &
16219Address operator. Defined on variables. Same precedence as @code{++}.
16220
b37052ae
EZ
16221For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
16222allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
b17828ca 16223to examine the address
b37052ae 16224where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
c906108c 16225stored.
c906108c
SS
16226
16227@item -
16228Negative. Defined on integral and floating-point types. Same
16229precedence as @code{++}.
16230
16231@item !
16232Logical negation. Defined on integral types. Same precedence as
16233@code{++}.
16234
16235@item ~
16236Bitwise complement operator. Defined on integral types. Same precedence as
16237@code{++}.
16238
16239
16240@item .@r{, }->
16241Structure member, and pointer-to-structure member. For convenience,
16242@value{GDBN} regards the two as equivalent, choosing whether to dereference a
16243pointer based on the stored type information.
16244Defined on @code{struct} and @code{union} data.
16245
c906108c
SS
16246@item .*@r{, }->*
16247Dereferences of pointers to members.
c906108c
SS
16248
16249@item []
16250Array indexing. @code{@var{a}[@var{i}]} is defined as
16251@code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
16252
16253@item ()
16254Function parameter list. Same precedence as @code{->}.
16255
c906108c 16256@item ::
b37052ae 16257C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
7a292a7a 16258and @code{class} types.
c906108c
SS
16259
16260@item ::
7a292a7a
SS
16261Doubled colons also represent the @value{GDBN} scope operator
16262(@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
16263above.
c906108c
SS
16264@end table
16265
c906108c
SS
16266If an operator is redefined in the user code, @value{GDBN} usually
16267attempts to invoke the redefined version instead of using the operator's
16268predefined meaning.
c906108c 16269
6d2ebf8b 16270@node C Constants
79a6e687 16271@subsubsection C and C@t{++} Constants
c906108c 16272
b37052ae 16273@cindex C and C@t{++} constants
c906108c 16274
b37052ae 16275@value{GDBN} allows you to express the constants of C and C@t{++} in the
c906108c 16276following ways:
c906108c
SS
16277
16278@itemize @bullet
16279@item
16280Integer constants are a sequence of digits. Octal constants are
6ca652b0
EZ
16281specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
16282by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
c906108c
SS
16283@samp{l}, specifying that the constant should be treated as a
16284@code{long} value.
16285
16286@item
16287Floating point constants are a sequence of digits, followed by a decimal
16288point, followed by a sequence of digits, and optionally followed by an
16289exponent. An exponent is of the form:
16290@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
16291sequence of digits. The @samp{+} is optional for positive exponents.
d4f3574e
SS
16292A floating-point constant may also end with a letter @samp{f} or
16293@samp{F}, specifying that the constant should be treated as being of
16294the @code{float} (as opposed to the default @code{double}) type; or with
16295a letter @samp{l} or @samp{L}, which specifies a @code{long double}
16296constant.
c906108c
SS
16297
16298@item
16299Enumerated constants consist of enumerated identifiers, or their
16300integral equivalents.
16301
16302@item
16303Character constants are a single character surrounded by single quotes
16304(@code{'}), or a number---the ordinal value of the corresponding character
d4f3574e 16305(usually its @sc{ascii} value). Within quotes, the single character may
c906108c
SS
16306be represented by a letter or by @dfn{escape sequences}, which are of
16307the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
16308of the character's ordinal value; or of the form @samp{\@var{x}}, where
16309@samp{@var{x}} is a predefined special character---for example,
16310@samp{\n} for newline.
16311
e0f8f636
TT
16312Wide character constants can be written by prefixing a character
16313constant with @samp{L}, as in C. For example, @samp{L'x'} is the wide
16314form of @samp{x}. The target wide character set is used when
16315computing the value of this constant (@pxref{Character Sets}).
16316
c906108c 16317@item
96a2c332
SS
16318String constants are a sequence of character constants surrounded by
16319double quotes (@code{"}). Any valid character constant (as described
16320above) may appear. Double quotes within the string must be preceded by
16321a backslash, so for instance @samp{"a\"b'c"} is a string of five
16322characters.
c906108c 16323
e0f8f636
TT
16324Wide string constants can be written by prefixing a string constant
16325with @samp{L}, as in C. The target wide character set is used when
16326computing the value of this constant (@pxref{Character Sets}).
16327
c906108c
SS
16328@item
16329Pointer constants are an integral value. You can also write pointers
16330to constants using the C operator @samp{&}.
16331
16332@item
16333Array constants are comma-separated lists surrounded by braces @samp{@{}
16334and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
16335integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
16336and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
16337@end itemize
16338
79a6e687
BW
16339@node C Plus Plus Expressions
16340@subsubsection C@t{++} Expressions
b37052ae
EZ
16341
16342@cindex expressions in C@t{++}
16343@value{GDBN} expression handling can interpret most C@t{++} expressions.
16344
0179ffac
DC
16345@cindex debugging C@t{++} programs
16346@cindex C@t{++} compilers
16347@cindex debug formats and C@t{++}
16348@cindex @value{NGCC} and C@t{++}
c906108c 16349@quotation
e0f8f636
TT
16350@emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use
16351the proper compiler and the proper debug format. Currently,
16352@value{GDBN} works best when debugging C@t{++} code that is compiled
16353with the most recent version of @value{NGCC} possible. The DWARF
16354debugging format is preferred; @value{NGCC} defaults to this on most
16355popular platforms. Other compilers and/or debug formats are likely to
16356work badly or not at all when using @value{GDBN} to debug C@t{++}
16357code. @xref{Compilation}.
c906108c 16358@end quotation
c906108c
SS
16359
16360@enumerate
16361
16362@cindex member functions
16363@item
16364Member function calls are allowed; you can use expressions like
16365
474c8240 16366@smallexample
c906108c 16367count = aml->GetOriginal(x, y)
474c8240 16368@end smallexample
c906108c 16369
41afff9a 16370@vindex this@r{, inside C@t{++} member functions}
b37052ae 16371@cindex namespace in C@t{++}
c906108c
SS
16372@item
16373While a member function is active (in the selected stack frame), your
16374expressions have the same namespace available as the member function;
16375that is, @value{GDBN} allows implicit references to the class instance
e0f8f636
TT
16376pointer @code{this} following the same rules as C@t{++}. @code{using}
16377declarations in the current scope are also respected by @value{GDBN}.
c906108c 16378
c906108c 16379@cindex call overloaded functions
d4f3574e 16380@cindex overloaded functions, calling
b37052ae 16381@cindex type conversions in C@t{++}
c906108c
SS
16382@item
16383You can call overloaded functions; @value{GDBN} resolves the function
d4f3574e 16384call to the right definition, with some restrictions. @value{GDBN} does not
c906108c
SS
16385perform overload resolution involving user-defined type conversions,
16386calls to constructors, or instantiations of templates that do not exist
16387in the program. It also cannot handle ellipsis argument lists or
16388default arguments.
16389
16390It does perform integral conversions and promotions, floating-point
16391promotions, arithmetic conversions, pointer conversions, conversions of
16392class objects to base classes, and standard conversions such as those of
16393functions or arrays to pointers; it requires an exact match on the
16394number of function arguments.
16395
16396Overload resolution is always performed, unless you have specified
79a6e687
BW
16397@code{set overload-resolution off}. @xref{Debugging C Plus Plus,
16398,@value{GDBN} Features for C@t{++}}.
c906108c 16399
d4f3574e 16400You must specify @code{set overload-resolution off} in order to use an
c906108c
SS
16401explicit function signature to call an overloaded function, as in
16402@smallexample
16403p 'foo(char,int)'('x', 13)
16404@end smallexample
d4f3574e 16405
c906108c 16406The @value{GDBN} command-completion facility can simplify this;
79a6e687 16407see @ref{Completion, ,Command Completion}.
c906108c 16408
c906108c
SS
16409@cindex reference declarations
16410@item
c0f55cc6
AV
16411@value{GDBN} understands variables declared as C@t{++} lvalue or rvalue
16412references; you can use them in expressions just as you do in C@t{++}
16413source---they are automatically dereferenced.
c906108c
SS
16414
16415In the parameter list shown when @value{GDBN} displays a frame, the values of
16416reference variables are not displayed (unlike other variables); this
16417avoids clutter, since references are often used for large structures.
16418The @emph{address} of a reference variable is always shown, unless
16419you have specified @samp{set print address off}.
16420
16421@item
b37052ae 16422@value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
c906108c
SS
16423expressions can use it just as expressions in your program do. Since
16424one scope may be defined in another, you can use @code{::} repeatedly if
16425necessary, for example in an expression like
16426@samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
b37052ae 16427resolving name scope by reference to source files, in both C and C@t{++}
79a6e687 16428debugging (@pxref{Variables, ,Program Variables}).
c906108c 16429
e0f8f636
TT
16430@item
16431@value{GDBN} performs argument-dependent lookup, following the C@t{++}
16432specification.
16433@end enumerate
c906108c 16434
6d2ebf8b 16435@node C Defaults
79a6e687 16436@subsubsection C and C@t{++} Defaults
7a292a7a 16437
b37052ae 16438@cindex C and C@t{++} defaults
c906108c 16439
a451cb65
KS
16440If you allow @value{GDBN} to set range checking automatically, it
16441defaults to @code{off} whenever the working language changes to
b37052ae 16442C or C@t{++}. This happens regardless of whether you or @value{GDBN}
c906108c 16443selects the working language.
c906108c
SS
16444
16445If you allow @value{GDBN} to set the language automatically, it
16446recognizes source files whose names end with @file{.c}, @file{.C}, or
16447@file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
b37052ae 16448these files, it sets the working language to C or C@t{++}.
79a6e687 16449@xref{Automatically, ,Having @value{GDBN} Infer the Source Language},
c906108c
SS
16450for further details.
16451
6d2ebf8b 16452@node C Checks
79a6e687 16453@subsubsection C and C@t{++} Type and Range Checks
7a292a7a 16454
b37052ae 16455@cindex C and C@t{++} checks
c906108c 16456
a451cb65
KS
16457By default, when @value{GDBN} parses C or C@t{++} expressions, strict type
16458checking is used. However, if you turn type checking off, @value{GDBN}
16459will allow certain non-standard conversions, such as promoting integer
16460constants to pointers.
c906108c
SS
16461
16462Range checking, if turned on, is done on mathematical operations. Array
16463indices are not checked, since they are often used to index a pointer
16464that is not itself an array.
c906108c 16465
6d2ebf8b 16466@node Debugging C
c906108c 16467@subsubsection @value{GDBN} and C
c906108c
SS
16468
16469The @code{set print union} and @code{show print union} commands apply to
16470the @code{union} type. When set to @samp{on}, any @code{union} that is
7a292a7a
SS
16471inside a @code{struct} or @code{class} is also printed. Otherwise, it
16472appears as @samp{@{...@}}.
c906108c
SS
16473
16474The @code{@@} operator aids in the debugging of dynamic arrays, formed
16475with pointers and a memory allocation function. @xref{Expressions,
16476,Expressions}.
16477
79a6e687
BW
16478@node Debugging C Plus Plus
16479@subsubsection @value{GDBN} Features for C@t{++}
c906108c 16480
b37052ae 16481@cindex commands for C@t{++}
7a292a7a 16482
b37052ae
EZ
16483Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
16484designed specifically for use with C@t{++}. Here is a summary:
c906108c
SS
16485
16486@table @code
16487@cindex break in overloaded functions
16488@item @r{breakpoint menus}
16489When you want a breakpoint in a function whose name is overloaded,
6ba66d6a
JB
16490@value{GDBN} has the capability to display a menu of possible breakpoint
16491locations to help you specify which function definition you want.
16492@xref{Ambiguous Expressions,,Ambiguous Expressions}.
c906108c 16493
b37052ae 16494@cindex overloading in C@t{++}
c906108c
SS
16495@item rbreak @var{regex}
16496Setting breakpoints using regular expressions is helpful for setting
16497breakpoints on overloaded functions that are not members of any special
16498classes.
79a6e687 16499@xref{Set Breaks, ,Setting Breakpoints}.
c906108c 16500
b37052ae 16501@cindex C@t{++} exception handling
c906108c 16502@item catch throw
591f19e8 16503@itemx catch rethrow
c906108c 16504@itemx catch catch
b37052ae 16505Debug C@t{++} exception handling using these commands. @xref{Set
79a6e687 16506Catchpoints, , Setting Catchpoints}.
c906108c
SS
16507
16508@cindex inheritance
16509@item ptype @var{typename}
16510Print inheritance relationships as well as other information for type
16511@var{typename}.
16512@xref{Symbols, ,Examining the Symbol Table}.
16513
c4aeac85
TT
16514@item info vtbl @var{expression}.
16515The @code{info vtbl} command can be used to display the virtual
16516method tables of the object computed by @var{expression}. This shows
16517one entry per virtual table; there may be multiple virtual tables when
16518multiple inheritance is in use.
16519
439250fb
DE
16520@cindex C@t{++} demangling
16521@item demangle @var{name}
16522Demangle @var{name}.
16523@xref{Symbols}, for a more complete description of the @code{demangle} command.
16524
b37052ae 16525@cindex C@t{++} symbol display
c906108c
SS
16526@item set print demangle
16527@itemx show print demangle
16528@itemx set print asm-demangle
16529@itemx show print asm-demangle
b37052ae
EZ
16530Control whether C@t{++} symbols display in their source form, both when
16531displaying code as C@t{++} source and when displaying disassemblies.
79a6e687 16532@xref{Print Settings, ,Print Settings}.
c906108c
SS
16533
16534@item set print object
16535@itemx show print object
16536Choose whether to print derived (actual) or declared types of objects.
79a6e687 16537@xref{Print Settings, ,Print Settings}.
c906108c
SS
16538
16539@item set print vtbl
16540@itemx show print vtbl
16541Control the format for printing virtual function tables.
79a6e687 16542@xref{Print Settings, ,Print Settings}.
c906108c 16543(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 16544ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
16545
16546@kindex set overload-resolution
d4f3574e 16547@cindex overloaded functions, overload resolution
c906108c 16548@item set overload-resolution on
b37052ae 16549Enable overload resolution for C@t{++} expression evaluation. The default
c906108c
SS
16550is on. For overloaded functions, @value{GDBN} evaluates the arguments
16551and searches for a function whose signature matches the argument types,
79a6e687
BW
16552using the standard C@t{++} conversion rules (see @ref{C Plus Plus
16553Expressions, ,C@t{++} Expressions}, for details).
16554If it cannot find a match, it emits a message.
c906108c
SS
16555
16556@item set overload-resolution off
b37052ae 16557Disable overload resolution for C@t{++} expression evaluation. For
c906108c
SS
16558overloaded functions that are not class member functions, @value{GDBN}
16559chooses the first function of the specified name that it finds in the
16560symbol table, whether or not its arguments are of the correct type. For
16561overloaded functions that are class member functions, @value{GDBN}
16562searches for a function whose signature @emph{exactly} matches the
16563argument types.
c906108c 16564
9c16f35a
EZ
16565@kindex show overload-resolution
16566@item show overload-resolution
16567Show the current setting of overload resolution.
16568
c906108c
SS
16569@item @r{Overloaded symbol names}
16570You can specify a particular definition of an overloaded symbol, using
b37052ae 16571the same notation that is used to declare such symbols in C@t{++}: type
c906108c
SS
16572@code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
16573also use the @value{GDBN} command-line word completion facilities to list the
16574available choices, or to finish the type list for you.
79a6e687 16575@xref{Completion,, Command Completion}, for details on how to do this.
bd69330d
PA
16576
16577@item @r{Breakpoints in functions with ABI tags}
16578
16579The GNU C@t{++} compiler introduced the notion of ABI ``tags'', which
16580correspond to changes in the ABI of a type, function, or variable that
16581would not otherwise be reflected in a mangled name. See
16582@url{https://developers.redhat.com/blog/2015/02/05/gcc5-and-the-c11-abi/}
16583for more detail.
16584
16585The ABI tags are visible in C@t{++} demangled names. For example, a
16586function that returns a std::string:
16587
16588@smallexample
16589std::string function(int);
16590@end smallexample
16591
16592@noindent
16593when compiled for the C++11 ABI is marked with the @code{cxx11} ABI
16594tag, and @value{GDBN} displays the symbol like this:
16595
16596@smallexample
16597function[abi:cxx11](int)
16598@end smallexample
16599
16600You can set a breakpoint on such functions simply as if they had no
16601tag. For example:
16602
16603@smallexample
16604(gdb) b function(int)
16605Breakpoint 2 at 0x40060d: file main.cc, line 10.
16606(gdb) info breakpoints
16607Num Type Disp Enb Address What
166081 breakpoint keep y 0x0040060d in function[abi:cxx11](int)
16609 at main.cc:10
16610@end smallexample
16611
16612On the rare occasion you need to disambiguate between different ABI
16613tags, you can do so by simply including the ABI tag in the function
16614name, like:
16615
16616@smallexample
16617(@value{GDBP}) b ambiguous[abi:other_tag](int)
16618@end smallexample
c906108c 16619@end table
c906108c 16620
febe4383
TJB
16621@node Decimal Floating Point
16622@subsubsection Decimal Floating Point format
16623@cindex decimal floating point format
16624
16625@value{GDBN} can examine, set and perform computations with numbers in
16626decimal floating point format, which in the C language correspond to the
16627@code{_Decimal32}, @code{_Decimal64} and @code{_Decimal128} types as
16628specified by the extension to support decimal floating-point arithmetic.
16629
16630There are two encodings in use, depending on the architecture: BID (Binary
16631Integer Decimal) for x86 and x86-64, and DPD (Densely Packed Decimal) for
4ac33720
UW
16632PowerPC and S/390. @value{GDBN} will use the appropriate encoding for the
16633configured target.
febe4383
TJB
16634
16635Because of a limitation in @file{libdecnumber}, the library used by @value{GDBN}
16636to manipulate decimal floating point numbers, it is not possible to convert
16637(using a cast, for example) integers wider than 32-bit to decimal float.
16638
16639In addition, in order to imitate @value{GDBN}'s behaviour with binary floating
16640point computations, error checking in decimal float operations ignores
16641underflow, overflow and divide by zero exceptions.
16642
4acd40f3 16643In the PowerPC architecture, @value{GDBN} provides a set of pseudo-registers
99e008fe
EZ
16644to inspect @code{_Decimal128} values stored in floating point registers.
16645See @ref{PowerPC,,PowerPC} for more details.
4acd40f3 16646
6aecb9c2
JB
16647@node D
16648@subsection D
16649
16650@cindex D
16651@value{GDBN} can be used to debug programs written in D and compiled with
16652GDC, LDC or DMD compilers. Currently @value{GDBN} supports only one D
16653specific feature --- dynamic arrays.
16654
a766d390
DE
16655@node Go
16656@subsection Go
16657
16658@cindex Go (programming language)
16659@value{GDBN} can be used to debug programs written in Go and compiled with
16660@file{gccgo} or @file{6g} compilers.
16661
16662Here is a summary of the Go-specific features and restrictions:
16663
16664@table @code
16665@cindex current Go package
16666@item The current Go package
16667The name of the current package does not need to be specified when
16668specifying global variables and functions.
16669
16670For example, given the program:
16671
16672@example
16673package main
16674var myglob = "Shall we?"
16675func main () @{
16676 // ...
16677@}
16678@end example
16679
16680When stopped inside @code{main} either of these work:
16681
16682@example
16683(gdb) p myglob
16684(gdb) p main.myglob
16685@end example
16686
16687@cindex builtin Go types
16688@item Builtin Go types
16689The @code{string} type is recognized by @value{GDBN} and is printed
16690as a string.
16691
16692@cindex builtin Go functions
16693@item Builtin Go functions
16694The @value{GDBN} expression parser recognizes the @code{unsafe.Sizeof}
16695function and handles it internally.
a766d390
DE
16696
16697@cindex restrictions on Go expressions
16698@item Restrictions on Go expressions
16699All Go operators are supported except @code{&^}.
16700The Go @code{_} ``blank identifier'' is not supported.
16701Automatic dereferencing of pointers is not supported.
50f042b9 16702@end table
a766d390 16703
b37303ee
AF
16704@node Objective-C
16705@subsection Objective-C
16706
16707@cindex Objective-C
16708This section provides information about some commands and command
721c2651
EZ
16709options that are useful for debugging Objective-C code. See also
16710@ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
16711few more commands specific to Objective-C support.
b37303ee
AF
16712
16713@menu
b383017d
RM
16714* Method Names in Commands::
16715* The Print Command with Objective-C::
b37303ee
AF
16716@end menu
16717
c8f4133a 16718@node Method Names in Commands
b37303ee
AF
16719@subsubsection Method Names in Commands
16720
16721The following commands have been extended to accept Objective-C method
16722names as line specifications:
16723
16724@kindex clear@r{, and Objective-C}
16725@kindex break@r{, and Objective-C}
16726@kindex info line@r{, and Objective-C}
16727@kindex jump@r{, and Objective-C}
16728@kindex list@r{, and Objective-C}
16729@itemize
16730@item @code{clear}
16731@item @code{break}
16732@item @code{info line}
16733@item @code{jump}
16734@item @code{list}
16735@end itemize
16736
16737A fully qualified Objective-C method name is specified as
16738
16739@smallexample
16740-[@var{Class} @var{methodName}]
16741@end smallexample
16742
c552b3bb
JM
16743where the minus sign is used to indicate an instance method and a
16744plus sign (not shown) is used to indicate a class method. The class
16745name @var{Class} and method name @var{methodName} are enclosed in
16746brackets, similar to the way messages are specified in Objective-C
16747source code. For example, to set a breakpoint at the @code{create}
16748instance method of class @code{Fruit} in the program currently being
16749debugged, enter:
b37303ee
AF
16750
16751@smallexample
16752break -[Fruit create]
16753@end smallexample
16754
16755To list ten program lines around the @code{initialize} class method,
16756enter:
16757
16758@smallexample
16759list +[NSText initialize]
16760@end smallexample
16761
c552b3bb
JM
16762In the current version of @value{GDBN}, the plus or minus sign is
16763required. In future versions of @value{GDBN}, the plus or minus
16764sign will be optional, but you can use it to narrow the search. It
16765is also possible to specify just a method name:
b37303ee
AF
16766
16767@smallexample
16768break create
16769@end smallexample
16770
16771You must specify the complete method name, including any colons. If
16772your program's source files contain more than one @code{create} method,
16773you'll be presented with a numbered list of classes that implement that
16774method. Indicate your choice by number, or type @samp{0} to exit if
16775none apply.
16776
16777As another example, to clear a breakpoint established at the
16778@code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
16779
16780@smallexample
16781clear -[NSWindow makeKeyAndOrderFront:]
16782@end smallexample
16783
16784@node The Print Command with Objective-C
16785@subsubsection The Print Command With Objective-C
721c2651 16786@cindex Objective-C, print objects
c552b3bb
JM
16787@kindex print-object
16788@kindex po @r{(@code{print-object})}
b37303ee 16789
c552b3bb 16790The print command has also been extended to accept methods. For example:
b37303ee
AF
16791
16792@smallexample
c552b3bb 16793print -[@var{object} hash]
b37303ee
AF
16794@end smallexample
16795
16796@cindex print an Objective-C object description
c552b3bb
JM
16797@cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
16798@noindent
16799will tell @value{GDBN} to send the @code{hash} message to @var{object}
16800and print the result. Also, an additional command has been added,
16801@code{print-object} or @code{po} for short, which is meant to print
16802the description of an object. However, this command may only work
16803with certain Objective-C libraries that have a particular hook
16804function, @code{_NSPrintForDebugger}, defined.
b37303ee 16805
f4b8a18d
KW
16806@node OpenCL C
16807@subsection OpenCL C
16808
16809@cindex OpenCL C
16810This section provides information about @value{GDBN}s OpenCL C support.
16811
16812@menu
16813* OpenCL C Datatypes::
16814* OpenCL C Expressions::
16815* OpenCL C Operators::
16816@end menu
16817
16818@node OpenCL C Datatypes
16819@subsubsection OpenCL C Datatypes
16820
16821@cindex OpenCL C Datatypes
16822@value{GDBN} supports the builtin scalar and vector datatypes specified
16823by OpenCL 1.1. In addition the half- and double-precision floating point
16824data types of the @code{cl_khr_fp16} and @code{cl_khr_fp64} OpenCL
16825extensions are also known to @value{GDBN}.
16826
16827@node OpenCL C Expressions
16828@subsubsection OpenCL C Expressions
16829
16830@cindex OpenCL C Expressions
16831@value{GDBN} supports accesses to vector components including the access as
16832lvalue where possible. Since OpenCL C is based on C99 most C expressions
16833supported by @value{GDBN} can be used as well.
16834
16835@node OpenCL C Operators
16836@subsubsection OpenCL C Operators
16837
16838@cindex OpenCL C Operators
16839@value{GDBN} supports the operators specified by OpenCL 1.1 for scalar and
16840vector data types.
16841
09d4efe1
EZ
16842@node Fortran
16843@subsection Fortran
16844@cindex Fortran-specific support in @value{GDBN}
16845
814e32d7
WZ
16846@value{GDBN} can be used to debug programs written in Fortran, but it
16847currently supports only the features of Fortran 77 language.
16848
16849@cindex trailing underscore, in Fortran symbols
16850Some Fortran compilers (@sc{gnu} Fortran 77 and Fortran 95 compilers
16851among them) append an underscore to the names of variables and
16852functions. When you debug programs compiled by those compilers, you
16853will need to refer to variables and functions with a trailing
16854underscore.
16855
16856@menu
16857* Fortran Operators:: Fortran operators and expressions
16858* Fortran Defaults:: Default settings for Fortran
79a6e687 16859* Special Fortran Commands:: Special @value{GDBN} commands for Fortran
814e32d7
WZ
16860@end menu
16861
16862@node Fortran Operators
79a6e687 16863@subsubsection Fortran Operators and Expressions
814e32d7
WZ
16864
16865@cindex Fortran operators and expressions
16866
16867Operators must be defined on values of specific types. For instance,
16868@code{+} is defined on numbers, but not on characters or other non-
ff2587ec 16869arithmetic types. Operators are often defined on groups of types.
814e32d7
WZ
16870
16871@table @code
16872@item **
99e008fe 16873The exponentiation operator. It raises the first operand to the power
814e32d7
WZ
16874of the second one.
16875
16876@item :
16877The range operator. Normally used in the form of array(low:high) to
16878represent a section of array.
68837c9d
MD
16879
16880@item %
16881The access component operator. Normally used to access elements in derived
16882types. Also suitable for unions. As unions aren't part of regular Fortran,
16883this can only happen when accessing a register that uses a gdbarch-defined
16884union type.
0a4b0913
AB
16885@item ::
16886The scope operator. Normally used to access variables in modules or
16887to set breakpoints on subroutines nested in modules or in other
16888subroutines (internal subroutines).
814e32d7
WZ
16889@end table
16890
16891@node Fortran Defaults
16892@subsubsection Fortran Defaults
16893
16894@cindex Fortran Defaults
16895
16896Fortran symbols are usually case-insensitive, so @value{GDBN} by
16897default uses case-insensitive matches for Fortran symbols. You can
16898change that with the @samp{set case-insensitive} command, see
16899@ref{Symbols}, for the details.
16900
79a6e687
BW
16901@node Special Fortran Commands
16902@subsubsection Special Fortran Commands
814e32d7
WZ
16903
16904@cindex Special Fortran commands
16905
db2e3e2e
BW
16906@value{GDBN} has some commands to support Fortran-specific features,
16907such as displaying common blocks.
814e32d7 16908
09d4efe1
EZ
16909@table @code
16910@cindex @code{COMMON} blocks, Fortran
16911@kindex info common
16912@item info common @r{[}@var{common-name}@r{]}
16913This command prints the values contained in the Fortran @code{COMMON}
16914block whose name is @var{common-name}. With no argument, the names of
d52fb0e9 16915all @code{COMMON} blocks visible at the current program location are
09d4efe1
EZ
16916printed.
16917@end table
16918
9c16f35a
EZ
16919@node Pascal
16920@subsection Pascal
16921
16922@cindex Pascal support in @value{GDBN}, limitations
16923Debugging Pascal programs which use sets, subranges, file variables, or
16924nested functions does not currently work. @value{GDBN} does not support
16925entering expressions, printing values, or similar features using Pascal
16926syntax.
16927
16928The Pascal-specific command @code{set print pascal_static-members}
16929controls whether static members of Pascal objects are displayed.
16930@xref{Print Settings, pascal_static-members}.
16931
0bdfa368
TT
16932@node Rust
16933@subsection Rust
16934
16935@value{GDBN} supports the @url{https://www.rust-lang.org/, Rust
16936Programming Language}. Type- and value-printing, and expression
16937parsing, are reasonably complete. However, there are a few
16938peculiarities and holes to be aware of.
16939
16940@itemize @bullet
16941@item
16942Linespecs (@pxref{Specify Location}) are never relative to the current
16943crate. Instead, they act as if there were a global namespace of
16944crates, somewhat similar to the way @code{extern crate} behaves.
16945
16946That is, if @value{GDBN} is stopped at a breakpoint in a function in
16947crate @samp{A}, module @samp{B}, then @code{break B::f} will attempt
16948to set a breakpoint in a function named @samp{f} in a crate named
16949@samp{B}.
16950
16951As a consequence of this approach, linespecs also cannot refer to
16952items using @samp{self::} or @samp{super::}.
16953
16954@item
16955Because @value{GDBN} implements Rust name-lookup semantics in
16956expressions, it will sometimes prepend the current crate to a name.
16957For example, if @value{GDBN} is stopped at a breakpoint in the crate
16958@samp{K}, then @code{print ::x::y} will try to find the symbol
16959@samp{K::x::y}.
16960
16961However, since it is useful to be able to refer to other crates when
16962debugging, @value{GDBN} provides the @code{extern} extension to
16963circumvent this. To use the extension, just put @code{extern} before
16964a path expression to refer to the otherwise unavailable ``global''
16965scope.
16966
16967In the above example, if you wanted to refer to the symbol @samp{y} in
16968the crate @samp{x}, you would use @code{print extern x::y}.
16969
16970@item
16971The Rust expression evaluator does not support ``statement-like''
16972expressions such as @code{if} or @code{match}, or lambda expressions.
16973
16974@item
16975Tuple expressions are not implemented.
16976
16977@item
16978The Rust expression evaluator does not currently implement the
16979@code{Drop} trait. Objects that may be created by the evaluator will
16980never be destroyed.
16981
16982@item
16983@value{GDBN} does not implement type inference for generics. In order
16984to call generic functions or otherwise refer to generic items, you
16985will have to specify the type parameters manually.
16986
16987@item
16988@value{GDBN} currently uses the C@t{++} demangler for Rust. In most
16989cases this does not cause any problems. However, in an expression
16990context, completing a generic function name will give syntactically
16991invalid results. This happens because Rust requires the @samp{::}
16992operator between the function name and its generic arguments. For
16993example, @value{GDBN} might provide a completion like
16994@code{crate::f<u32>}, where the parser would require
16995@code{crate::f::<u32>}.
16996
16997@item
16998As of this writing, the Rust compiler (version 1.8) has a few holes in
16999the debugging information it generates. These holes prevent certain
17000features from being implemented by @value{GDBN}:
17001@itemize @bullet
17002
17003@item
17004Method calls cannot be made via traits.
17005
0bdfa368
TT
17006@item
17007Operator overloading is not implemented.
17008
17009@item
17010When debugging in a monomorphized function, you cannot use the generic
17011type names.
17012
17013@item
17014The type @code{Self} is not available.
17015
17016@item
17017@code{use} statements are not available, so some names may not be
17018available in the crate.
17019@end itemize
17020@end itemize
17021
09d4efe1 17022@node Modula-2
c906108c 17023@subsection Modula-2
7a292a7a 17024
d4f3574e 17025@cindex Modula-2, @value{GDBN} support
c906108c
SS
17026
17027The extensions made to @value{GDBN} to support Modula-2 only support
17028output from the @sc{gnu} Modula-2 compiler (which is currently being
17029developed). Other Modula-2 compilers are not currently supported, and
17030attempting to debug executables produced by them is most likely
17031to give an error as @value{GDBN} reads in the executable's symbol
17032table.
17033
17034@cindex expressions in Modula-2
17035@menu
17036* M2 Operators:: Built-in operators
17037* Built-In Func/Proc:: Built-in functions and procedures
17038* M2 Constants:: Modula-2 constants
72019c9c 17039* M2 Types:: Modula-2 types
c906108c
SS
17040* M2 Defaults:: Default settings for Modula-2
17041* Deviations:: Deviations from standard Modula-2
17042* M2 Checks:: Modula-2 type and range checks
17043* M2 Scope:: The scope operators @code{::} and @code{.}
17044* GDB/M2:: @value{GDBN} and Modula-2
17045@end menu
17046
6d2ebf8b 17047@node M2 Operators
c906108c
SS
17048@subsubsection Operators
17049@cindex Modula-2 operators
17050
17051Operators must be defined on values of specific types. For instance,
17052@code{+} is defined on numbers, but not on structures. Operators are
17053often defined on groups of types. For the purposes of Modula-2, the
17054following definitions hold:
17055
17056@itemize @bullet
17057
17058@item
17059@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
17060their subranges.
17061
17062@item
17063@emph{Character types} consist of @code{CHAR} and its subranges.
17064
17065@item
17066@emph{Floating-point types} consist of @code{REAL}.
17067
17068@item
17069@emph{Pointer types} consist of anything declared as @code{POINTER TO
17070@var{type}}.
17071
17072@item
17073@emph{Scalar types} consist of all of the above.
17074
17075@item
17076@emph{Set types} consist of @code{SET} and @code{BITSET} types.
17077
17078@item
17079@emph{Boolean types} consist of @code{BOOLEAN}.
17080@end itemize
17081
17082@noindent
17083The following operators are supported, and appear in order of
17084increasing precedence:
17085
17086@table @code
17087@item ,
17088Function argument or array index separator.
17089
17090@item :=
17091Assignment. The value of @var{var} @code{:=} @var{value} is
17092@var{value}.
17093
17094@item <@r{, }>
17095Less than, greater than on integral, floating-point, or enumerated
17096types.
17097
17098@item <=@r{, }>=
96a2c332 17099Less than or equal to, greater than or equal to
c906108c
SS
17100on integral, floating-point and enumerated types, or set inclusion on
17101set types. Same precedence as @code{<}.
17102
17103@item =@r{, }<>@r{, }#
17104Equality and two ways of expressing inequality, valid on scalar types.
17105Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
17106available for inequality, since @code{#} conflicts with the script
17107comment character.
17108
17109@item IN
17110Set membership. Defined on set types and the types of their members.
17111Same precedence as @code{<}.
17112
17113@item OR
17114Boolean disjunction. Defined on boolean types.
17115
17116@item AND@r{, }&
d4f3574e 17117Boolean conjunction. Defined on boolean types.
c906108c
SS
17118
17119@item @@
17120The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
17121
17122@item +@r{, }-
17123Addition and subtraction on integral and floating-point types, or union
17124and difference on set types.
17125
17126@item *
17127Multiplication on integral and floating-point types, or set intersection
17128on set types.
17129
17130@item /
17131Division on floating-point types, or symmetric set difference on set
17132types. Same precedence as @code{*}.
17133
17134@item DIV@r{, }MOD
17135Integer division and remainder. Defined on integral types. Same
17136precedence as @code{*}.
17137
17138@item -
99e008fe 17139Negative. Defined on @code{INTEGER} and @code{REAL} data.
c906108c
SS
17140
17141@item ^
17142Pointer dereferencing. Defined on pointer types.
17143
17144@item NOT
17145Boolean negation. Defined on boolean types. Same precedence as
17146@code{^}.
17147
17148@item .
17149@code{RECORD} field selector. Defined on @code{RECORD} data. Same
17150precedence as @code{^}.
17151
17152@item []
17153Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
17154
17155@item ()
17156Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
17157as @code{^}.
17158
17159@item ::@r{, }.
17160@value{GDBN} and Modula-2 scope operators.
17161@end table
17162
17163@quotation
72019c9c 17164@emph{Warning:} Set expressions and their operations are not yet supported, so @value{GDBN}
c906108c
SS
17165treats the use of the operator @code{IN}, or the use of operators
17166@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
17167@code{<=}, and @code{>=} on sets as an error.
17168@end quotation
17169
cb51c4e0 17170
6d2ebf8b 17171@node Built-In Func/Proc
79a6e687 17172@subsubsection Built-in Functions and Procedures
cb51c4e0 17173@cindex Modula-2 built-ins
c906108c
SS
17174
17175Modula-2 also makes available several built-in procedures and functions.
17176In describing these, the following metavariables are used:
17177
17178@table @var
17179
17180@item a
17181represents an @code{ARRAY} variable.
17182
17183@item c
17184represents a @code{CHAR} constant or variable.
17185
17186@item i
17187represents a variable or constant of integral type.
17188
17189@item m
17190represents an identifier that belongs to a set. Generally used in the
17191same function with the metavariable @var{s}. The type of @var{s} should
17192be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
17193
17194@item n
17195represents a variable or constant of integral or floating-point type.
17196
17197@item r
17198represents a variable or constant of floating-point type.
17199
17200@item t
17201represents a type.
17202
17203@item v
17204represents a variable.
17205
17206@item x
17207represents a variable or constant of one of many types. See the
17208explanation of the function for details.
17209@end table
17210
17211All Modula-2 built-in procedures also return a result, described below.
17212
17213@table @code
17214@item ABS(@var{n})
17215Returns the absolute value of @var{n}.
17216
17217@item CAP(@var{c})
17218If @var{c} is a lower case letter, it returns its upper case
c3f6f71d 17219equivalent, otherwise it returns its argument.
c906108c
SS
17220
17221@item CHR(@var{i})
17222Returns the character whose ordinal value is @var{i}.
17223
17224@item DEC(@var{v})
c3f6f71d 17225Decrements the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
17226
17227@item DEC(@var{v},@var{i})
17228Decrements the value in the variable @var{v} by @var{i}. Returns the
17229new value.
17230
17231@item EXCL(@var{m},@var{s})
17232Removes the element @var{m} from the set @var{s}. Returns the new
17233set.
17234
17235@item FLOAT(@var{i})
17236Returns the floating point equivalent of the integer @var{i}.
17237
17238@item HIGH(@var{a})
17239Returns the index of the last member of @var{a}.
17240
17241@item INC(@var{v})
c3f6f71d 17242Increments the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
17243
17244@item INC(@var{v},@var{i})
17245Increments the value in the variable @var{v} by @var{i}. Returns the
17246new value.
17247
17248@item INCL(@var{m},@var{s})
17249Adds the element @var{m} to the set @var{s} if it is not already
17250there. Returns the new set.
17251
17252@item MAX(@var{t})
17253Returns the maximum value of the type @var{t}.
17254
17255@item MIN(@var{t})
17256Returns the minimum value of the type @var{t}.
17257
17258@item ODD(@var{i})
17259Returns boolean TRUE if @var{i} is an odd number.
17260
17261@item ORD(@var{x})
17262Returns the ordinal value of its argument. For example, the ordinal
697aa1b7
EZ
17263value of a character is its @sc{ascii} value (on machines supporting
17264the @sc{ascii} character set). The argument @var{x} must be of an
17265ordered type, which include integral, character and enumerated types.
c906108c
SS
17266
17267@item SIZE(@var{x})
697aa1b7
EZ
17268Returns the size of its argument. The argument @var{x} can be a
17269variable or a type.
c906108c
SS
17270
17271@item TRUNC(@var{r})
17272Returns the integral part of @var{r}.
17273
844781a1 17274@item TSIZE(@var{x})
697aa1b7
EZ
17275Returns the size of its argument. The argument @var{x} can be a
17276variable or a type.
844781a1 17277
c906108c
SS
17278@item VAL(@var{t},@var{i})
17279Returns the member of the type @var{t} whose ordinal value is @var{i}.
17280@end table
17281
17282@quotation
17283@emph{Warning:} Sets and their operations are not yet supported, so
17284@value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
17285an error.
17286@end quotation
17287
17288@cindex Modula-2 constants
6d2ebf8b 17289@node M2 Constants
c906108c
SS
17290@subsubsection Constants
17291
17292@value{GDBN} allows you to express the constants of Modula-2 in the following
17293ways:
17294
17295@itemize @bullet
17296
17297@item
17298Integer constants are simply a sequence of digits. When used in an
17299expression, a constant is interpreted to be type-compatible with the
17300rest of the expression. Hexadecimal integers are specified by a
17301trailing @samp{H}, and octal integers by a trailing @samp{B}.
17302
17303@item
17304Floating point constants appear as a sequence of digits, followed by a
17305decimal point and another sequence of digits. An optional exponent can
17306then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
17307@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
17308digits of the floating point constant must be valid decimal (base 10)
17309digits.
17310
17311@item
17312Character constants consist of a single character enclosed by a pair of
17313like quotes, either single (@code{'}) or double (@code{"}). They may
c3f6f71d 17314also be expressed by their ordinal value (their @sc{ascii} value, usually)
c906108c
SS
17315followed by a @samp{C}.
17316
17317@item
17318String constants consist of a sequence of characters enclosed by a
17319pair of like quotes, either single (@code{'}) or double (@code{"}).
17320Escape sequences in the style of C are also allowed. @xref{C
79a6e687 17321Constants, ,C and C@t{++} Constants}, for a brief explanation of escape
c906108c
SS
17322sequences.
17323
17324@item
17325Enumerated constants consist of an enumerated identifier.
17326
17327@item
17328Boolean constants consist of the identifiers @code{TRUE} and
17329@code{FALSE}.
17330
17331@item
17332Pointer constants consist of integral values only.
17333
17334@item
17335Set constants are not yet supported.
17336@end itemize
17337
72019c9c
GM
17338@node M2 Types
17339@subsubsection Modula-2 Types
17340@cindex Modula-2 types
17341
17342Currently @value{GDBN} can print the following data types in Modula-2
17343syntax: array types, record types, set types, pointer types, procedure
17344types, enumerated types, subrange types and base types. You can also
17345print the contents of variables declared using these type.
17346This section gives a number of simple source code examples together with
17347sample @value{GDBN} sessions.
17348
17349The first example contains the following section of code:
17350
17351@smallexample
17352VAR
17353 s: SET OF CHAR ;
17354 r: [20..40] ;
17355@end smallexample
17356
17357@noindent
17358and you can request @value{GDBN} to interrogate the type and value of
17359@code{r} and @code{s}.
17360
17361@smallexample
17362(@value{GDBP}) print s
17363@{'A'..'C', 'Z'@}
17364(@value{GDBP}) ptype s
17365SET OF CHAR
17366(@value{GDBP}) print r
1736721
17368(@value{GDBP}) ptype r
17369[20..40]
17370@end smallexample
17371
17372@noindent
17373Likewise if your source code declares @code{s} as:
17374
17375@smallexample
17376VAR
17377 s: SET ['A'..'Z'] ;
17378@end smallexample
17379
17380@noindent
17381then you may query the type of @code{s} by:
17382
17383@smallexample
17384(@value{GDBP}) ptype s
17385type = SET ['A'..'Z']
17386@end smallexample
17387
17388@noindent
17389Note that at present you cannot interactively manipulate set
17390expressions using the debugger.
17391
17392The following example shows how you might declare an array in Modula-2
17393and how you can interact with @value{GDBN} to print its type and contents:
17394
17395@smallexample
17396VAR
17397 s: ARRAY [-10..10] OF CHAR ;
17398@end smallexample
17399
17400@smallexample
17401(@value{GDBP}) ptype s
17402ARRAY [-10..10] OF CHAR
17403@end smallexample
17404
17405Note that the array handling is not yet complete and although the type
17406is printed correctly, expression handling still assumes that all
17407arrays have a lower bound of zero and not @code{-10} as in the example
844781a1 17408above.
72019c9c
GM
17409
17410Here are some more type related Modula-2 examples:
17411
17412@smallexample
17413TYPE
17414 colour = (blue, red, yellow, green) ;
17415 t = [blue..yellow] ;
17416VAR
17417 s: t ;
17418BEGIN
17419 s := blue ;
17420@end smallexample
17421
17422@noindent
17423The @value{GDBN} interaction shows how you can query the data type
17424and value of a variable.
17425
17426@smallexample
17427(@value{GDBP}) print s
17428$1 = blue
17429(@value{GDBP}) ptype t
17430type = [blue..yellow]
17431@end smallexample
17432
17433@noindent
17434In this example a Modula-2 array is declared and its contents
17435displayed. Observe that the contents are written in the same way as
17436their @code{C} counterparts.
17437
17438@smallexample
17439VAR
17440 s: ARRAY [1..5] OF CARDINAL ;
17441BEGIN
17442 s[1] := 1 ;
17443@end smallexample
17444
17445@smallexample
17446(@value{GDBP}) print s
17447$1 = @{1, 0, 0, 0, 0@}
17448(@value{GDBP}) ptype s
17449type = ARRAY [1..5] OF CARDINAL
17450@end smallexample
17451
17452The Modula-2 language interface to @value{GDBN} also understands
17453pointer types as shown in this example:
17454
17455@smallexample
17456VAR
17457 s: POINTER TO ARRAY [1..5] OF CARDINAL ;
17458BEGIN
17459 NEW(s) ;
17460 s^[1] := 1 ;
17461@end smallexample
17462
17463@noindent
17464and you can request that @value{GDBN} describes the type of @code{s}.
17465
17466@smallexample
17467(@value{GDBP}) ptype s
17468type = POINTER TO ARRAY [1..5] OF CARDINAL
17469@end smallexample
17470
17471@value{GDBN} handles compound types as we can see in this example.
17472Here we combine array types, record types, pointer types and subrange
17473types:
17474
17475@smallexample
17476TYPE
17477 foo = RECORD
17478 f1: CARDINAL ;
17479 f2: CHAR ;
17480 f3: myarray ;
17481 END ;
17482
17483 myarray = ARRAY myrange OF CARDINAL ;
17484 myrange = [-2..2] ;
17485VAR
17486 s: POINTER TO ARRAY myrange OF foo ;
17487@end smallexample
17488
17489@noindent
17490and you can ask @value{GDBN} to describe the type of @code{s} as shown
17491below.
17492
17493@smallexample
17494(@value{GDBP}) ptype s
17495type = POINTER TO ARRAY [-2..2] OF foo = RECORD
17496 f1 : CARDINAL;
17497 f2 : CHAR;
17498 f3 : ARRAY [-2..2] OF CARDINAL;
17499END
17500@end smallexample
17501
6d2ebf8b 17502@node M2 Defaults
79a6e687 17503@subsubsection Modula-2 Defaults
c906108c
SS
17504@cindex Modula-2 defaults
17505
17506If type and range checking are set automatically by @value{GDBN}, they
17507both default to @code{on} whenever the working language changes to
d4f3574e 17508Modula-2. This happens regardless of whether you or @value{GDBN}
c906108c
SS
17509selected the working language.
17510
17511If you allow @value{GDBN} to set the language automatically, then entering
17512code compiled from a file whose name ends with @file{.mod} sets the
79a6e687
BW
17513working language to Modula-2. @xref{Automatically, ,Having @value{GDBN}
17514Infer the Source Language}, for further details.
c906108c 17515
6d2ebf8b 17516@node Deviations
79a6e687 17517@subsubsection Deviations from Standard Modula-2
c906108c
SS
17518@cindex Modula-2, deviations from
17519
17520A few changes have been made to make Modula-2 programs easier to debug.
17521This is done primarily via loosening its type strictness:
17522
17523@itemize @bullet
17524@item
17525Unlike in standard Modula-2, pointer constants can be formed by
17526integers. This allows you to modify pointer variables during
17527debugging. (In standard Modula-2, the actual address contained in a
17528pointer variable is hidden from you; it can only be modified
17529through direct assignment to another pointer variable or expression that
17530returned a pointer.)
17531
17532@item
17533C escape sequences can be used in strings and characters to represent
17534non-printable characters. @value{GDBN} prints out strings with these
17535escape sequences embedded. Single non-printable characters are
17536printed using the @samp{CHR(@var{nnn})} format.
17537
17538@item
17539The assignment operator (@code{:=}) returns the value of its right-hand
17540argument.
17541
17542@item
17543All built-in procedures both modify @emph{and} return their argument.
17544@end itemize
17545
6d2ebf8b 17546@node M2 Checks
79a6e687 17547@subsubsection Modula-2 Type and Range Checks
c906108c
SS
17548@cindex Modula-2 checks
17549
17550@quotation
17551@emph{Warning:} in this release, @value{GDBN} does not yet perform type or
17552range checking.
17553@end quotation
17554@c FIXME remove warning when type/range checks added
17555
17556@value{GDBN} considers two Modula-2 variables type equivalent if:
17557
17558@itemize @bullet
17559@item
17560They are of types that have been declared equivalent via a @code{TYPE
17561@var{t1} = @var{t2}} statement
17562
17563@item
17564They have been declared on the same line. (Note: This is true of the
17565@sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
17566@end itemize
17567
17568As long as type checking is enabled, any attempt to combine variables
17569whose types are not equivalent is an error.
17570
17571Range checking is done on all mathematical operations, assignment, array
17572index bounds, and all built-in functions and procedures.
17573
6d2ebf8b 17574@node M2 Scope
79a6e687 17575@subsubsection The Scope Operators @code{::} and @code{.}
c906108c 17576@cindex scope
41afff9a 17577@cindex @code{.}, Modula-2 scope operator
c906108c
SS
17578@cindex colon, doubled as scope operator
17579@ifinfo
41afff9a 17580@vindex colon-colon@r{, in Modula-2}
c906108c
SS
17581@c Info cannot handle :: but TeX can.
17582@end ifinfo
a67ec3f4 17583@ifnotinfo
41afff9a 17584@vindex ::@r{, in Modula-2}
a67ec3f4 17585@end ifnotinfo
c906108c
SS
17586
17587There are a few subtle differences between the Modula-2 scope operator
17588(@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
17589similar syntax:
17590
474c8240 17591@smallexample
c906108c
SS
17592
17593@var{module} . @var{id}
17594@var{scope} :: @var{id}
474c8240 17595@end smallexample
c906108c
SS
17596
17597@noindent
17598where @var{scope} is the name of a module or a procedure,
17599@var{module} the name of a module, and @var{id} is any declared
17600identifier within your program, except another module.
17601
17602Using the @code{::} operator makes @value{GDBN} search the scope
17603specified by @var{scope} for the identifier @var{id}. If it is not
17604found in the specified scope, then @value{GDBN} searches all scopes
17605enclosing the one specified by @var{scope}.
17606
17607Using the @code{.} operator makes @value{GDBN} search the current scope for
17608the identifier specified by @var{id} that was imported from the
17609definition module specified by @var{module}. With this operator, it is
17610an error if the identifier @var{id} was not imported from definition
17611module @var{module}, or if @var{id} is not an identifier in
17612@var{module}.
17613
6d2ebf8b 17614@node GDB/M2
c906108c
SS
17615@subsubsection @value{GDBN} and Modula-2
17616
17617Some @value{GDBN} commands have little use when debugging Modula-2 programs.
17618Five subcommands of @code{set print} and @code{show print} apply
b37052ae 17619specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
c906108c 17620@samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
b37052ae 17621apply to C@t{++}, and the last to the C @code{union} type, which has no direct
c906108c
SS
17622analogue in Modula-2.
17623
17624The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
d4f3574e 17625with any language, is not useful with Modula-2. Its
c906108c 17626intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
b37052ae 17627created in Modula-2 as they can in C or C@t{++}. However, because an
c906108c 17628address can be specified by an integral constant, the construct
d4f3574e 17629@samp{@{@var{type}@}@var{adrexp}} is still useful.
c906108c
SS
17630
17631@cindex @code{#} in Modula-2
17632In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
17633interpreted as the beginning of a comment. Use @code{<>} instead.
c906108c 17634
e07c999f
PH
17635@node Ada
17636@subsection Ada
17637@cindex Ada
17638
17639The extensions made to @value{GDBN} for Ada only support
17640output from the @sc{gnu} Ada (GNAT) compiler.
17641Other Ada compilers are not currently supported, and
17642attempting to debug executables produced by them is most likely
17643to be difficult.
17644
17645
17646@cindex expressions in Ada
17647@menu
17648* Ada Mode Intro:: General remarks on the Ada syntax
17649 and semantics supported by Ada mode
17650 in @value{GDBN}.
17651* Omissions from Ada:: Restrictions on the Ada expression syntax.
17652* Additions to Ada:: Extensions of the Ada expression syntax.
3685b09f
PMR
17653* Overloading support for Ada:: Support for expressions involving overloaded
17654 subprograms.
e07c999f 17655* Stopping Before Main Program:: Debugging the program during elaboration.
58d06528 17656* Ada Exceptions:: Ada Exceptions
20924a55
JB
17657* Ada Tasks:: Listing and setting breakpoints in tasks.
17658* Ada Tasks and Core Files:: Tasking Support when Debugging Core Files
6e1bb179
JB
17659* Ravenscar Profile:: Tasking Support when using the Ravenscar
17660 Profile
3fcded8f 17661* Ada Settings:: New settable GDB parameters for Ada.
e07c999f
PH
17662* Ada Glitches:: Known peculiarities of Ada mode.
17663@end menu
17664
17665@node Ada Mode Intro
17666@subsubsection Introduction
17667@cindex Ada mode, general
17668
17669The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
17670syntax, with some extensions.
17671The philosophy behind the design of this subset is
17672
17673@itemize @bullet
17674@item
17675That @value{GDBN} should provide basic literals and access to operations for
17676arithmetic, dereferencing, field selection, indexing, and subprogram calls,
17677leaving more sophisticated computations to subprograms written into the
17678program (which therefore may be called from @value{GDBN}).
17679
17680@item
17681That type safety and strict adherence to Ada language restrictions
17682are not particularly important to the @value{GDBN} user.
17683
17684@item
17685That brevity is important to the @value{GDBN} user.
17686@end itemize
17687
f3a2dd1a
JB
17688Thus, for brevity, the debugger acts as if all names declared in
17689user-written packages are directly visible, even if they are not visible
17690according to Ada rules, thus making it unnecessary to fully qualify most
17691names with their packages, regardless of context. Where this causes
17692ambiguity, @value{GDBN} asks the user's intent.
e07c999f
PH
17693
17694The debugger will start in Ada mode if it detects an Ada main program.
17695As for other languages, it will enter Ada mode when stopped in a program that
17696was translated from an Ada source file.
17697
17698While in Ada mode, you may use `@t{--}' for comments. This is useful
17699mostly for documenting command files. The standard @value{GDBN} comment
17700(@samp{#}) still works at the beginning of a line in Ada mode, but not in the
17701middle (to allow based literals).
17702
e07c999f
PH
17703@node Omissions from Ada
17704@subsubsection Omissions from Ada
17705@cindex Ada, omissions from
17706
17707Here are the notable omissions from the subset:
17708
17709@itemize @bullet
17710@item
17711Only a subset of the attributes are supported:
17712
17713@itemize @minus
17714@item
17715@t{'First}, @t{'Last}, and @t{'Length}
17716 on array objects (not on types and subtypes).
17717
17718@item
17719@t{'Min} and @t{'Max}.
17720
17721@item
17722@t{'Pos} and @t{'Val}.
17723
17724@item
17725@t{'Tag}.
17726
17727@item
17728@t{'Range} on array objects (not subtypes), but only as the right
17729operand of the membership (@code{in}) operator.
17730
17731@item
17732@t{'Access}, @t{'Unchecked_Access}, and
17733@t{'Unrestricted_Access} (a GNAT extension).
17734
17735@item
17736@t{'Address}.
17737@end itemize
17738
17739@item
17740The names in
17741@code{Characters.Latin_1} are not available and
17742concatenation is not implemented. Thus, escape characters in strings are
17743not currently available.
17744
17745@item
17746Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
17747equality of representations. They will generally work correctly
17748for strings and arrays whose elements have integer or enumeration types.
17749They may not work correctly for arrays whose element
17750types have user-defined equality, for arrays of real values
17751(in particular, IEEE-conformant floating point, because of negative
17752zeroes and NaNs), and for arrays whose elements contain unused bits with
17753indeterminate values.
17754
17755@item
17756The other component-by-component array operations (@code{and}, @code{or},
17757@code{xor}, @code{not}, and relational tests other than equality)
17758are not implemented.
17759
17760@item
860701dc
PH
17761@cindex array aggregates (Ada)
17762@cindex record aggregates (Ada)
17763@cindex aggregates (Ada)
17764There is limited support for array and record aggregates. They are
17765permitted only on the right sides of assignments, as in these examples:
17766
17767@smallexample
077e0a52
JB
17768(@value{GDBP}) set An_Array := (1, 2, 3, 4, 5, 6)
17769(@value{GDBP}) set An_Array := (1, others => 0)
17770(@value{GDBP}) set An_Array := (0|4 => 1, 1..3 => 2, 5 => 6)
17771(@value{GDBP}) set A_2D_Array := ((1, 2, 3), (4, 5, 6), (7, 8, 9))
17772(@value{GDBP}) set A_Record := (1, "Peter", True);
17773(@value{GDBP}) set A_Record := (Name => "Peter", Id => 1, Alive => True)
860701dc
PH
17774@end smallexample
17775
17776Changing a
17777discriminant's value by assigning an aggregate has an
17778undefined effect if that discriminant is used within the record.
17779However, you can first modify discriminants by directly assigning to
17780them (which normally would not be allowed in Ada), and then performing an
17781aggregate assignment. For example, given a variable @code{A_Rec}
17782declared to have a type such as:
17783
17784@smallexample
17785type Rec (Len : Small_Integer := 0) is record
17786 Id : Integer;
17787 Vals : IntArray (1 .. Len);
17788end record;
17789@end smallexample
17790
17791you can assign a value with a different size of @code{Vals} with two
17792assignments:
17793
17794@smallexample
077e0a52
JB
17795(@value{GDBP}) set A_Rec.Len := 4
17796(@value{GDBP}) set A_Rec := (Id => 42, Vals => (1, 2, 3, 4))
860701dc
PH
17797@end smallexample
17798
17799As this example also illustrates, @value{GDBN} is very loose about the usual
17800rules concerning aggregates. You may leave out some of the
17801components of an array or record aggregate (such as the @code{Len}
17802component in the assignment to @code{A_Rec} above); they will retain their
17803original values upon assignment. You may freely use dynamic values as
17804indices in component associations. You may even use overlapping or
17805redundant component associations, although which component values are
17806assigned in such cases is not defined.
e07c999f
PH
17807
17808@item
17809Calls to dispatching subprograms are not implemented.
17810
17811@item
17812The overloading algorithm is much more limited (i.e., less selective)
ae21e955
BW
17813than that of real Ada. It makes only limited use of the context in
17814which a subexpression appears to resolve its meaning, and it is much
17815looser in its rules for allowing type matches. As a result, some
17816function calls will be ambiguous, and the user will be asked to choose
17817the proper resolution.
e07c999f
PH
17818
17819@item
17820The @code{new} operator is not implemented.
17821
17822@item
17823Entry calls are not implemented.
17824
17825@item
17826Aside from printing, arithmetic operations on the native VAX floating-point
17827formats are not supported.
17828
17829@item
17830It is not possible to slice a packed array.
158c7665
PH
17831
17832@item
17833The names @code{True} and @code{False}, when not part of a qualified name,
17834are interpreted as if implicitly prefixed by @code{Standard}, regardless of
17835context.
17836Should your program
17837redefine these names in a package or procedure (at best a dubious practice),
17838you will have to use fully qualified names to access their new definitions.
e07c999f
PH
17839@end itemize
17840
17841@node Additions to Ada
17842@subsubsection Additions to Ada
17843@cindex Ada, deviations from
17844
17845As it does for other languages, @value{GDBN} makes certain generic
17846extensions to Ada (@pxref{Expressions}):
17847
17848@itemize @bullet
17849@item
ae21e955
BW
17850If the expression @var{E} is a variable residing in memory (typically
17851a local variable or array element) and @var{N} is a positive integer,
17852then @code{@var{E}@@@var{N}} displays the values of @var{E} and the
17853@var{N}-1 adjacent variables following it in memory as an array. In
17854Ada, this operator is generally not necessary, since its prime use is
17855in displaying parts of an array, and slicing will usually do this in
17856Ada. However, there are occasional uses when debugging programs in
17857which certain debugging information has been optimized away.
e07c999f
PH
17858
17859@item
ae21e955
BW
17860@code{@var{B}::@var{var}} means ``the variable named @var{var} that
17861appears in function or file @var{B}.'' When @var{B} is a file name,
17862you must typically surround it in single quotes.
e07c999f
PH
17863
17864@item
17865The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
17866@var{type} that appears at address @var{addr}.''
17867
17868@item
17869A name starting with @samp{$} is a convenience variable
17870(@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
17871@end itemize
17872
ae21e955
BW
17873In addition, @value{GDBN} provides a few other shortcuts and outright
17874additions specific to Ada:
e07c999f
PH
17875
17876@itemize @bullet
17877@item
17878The assignment statement is allowed as an expression, returning
17879its right-hand operand as its value. Thus, you may enter
17880
17881@smallexample
077e0a52
JB
17882(@value{GDBP}) set x := y + 3
17883(@value{GDBP}) print A(tmp := y + 1)
e07c999f
PH
17884@end smallexample
17885
17886@item
17887The semicolon is allowed as an ``operator,'' returning as its value
17888the value of its right-hand operand.
17889This allows, for example,
17890complex conditional breaks:
17891
17892@smallexample
077e0a52
JB
17893(@value{GDBP}) break f
17894(@value{GDBP}) condition 1 (report(i); k += 1; A(k) > 100)
e07c999f
PH
17895@end smallexample
17896
17897@item
17898Rather than use catenation and symbolic character names to introduce special
17899characters into strings, one may instead use a special bracket notation,
17900which is also used to print strings. A sequence of characters of the form
17901@samp{["@var{XX}"]} within a string or character literal denotes the
17902(single) character whose numeric encoding is @var{XX} in hexadecimal. The
17903sequence of characters @samp{["""]} also denotes a single quotation mark
17904in strings. For example,
17905@smallexample
17906 "One line.["0a"]Next line.["0a"]"
17907@end smallexample
17908@noindent
ae21e955
BW
17909contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF})
17910after each period.
e07c999f
PH
17911
17912@item
17913The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
17914@t{'Max} is optional (and is ignored in any case). For example, it is valid
17915to write
17916
17917@smallexample
077e0a52 17918(@value{GDBP}) print 'max(x, y)
e07c999f
PH
17919@end smallexample
17920
17921@item
17922When printing arrays, @value{GDBN} uses positional notation when the
17923array has a lower bound of 1, and uses a modified named notation otherwise.
ae21e955
BW
17924For example, a one-dimensional array of three integers with a lower bound
17925of 3 might print as
e07c999f
PH
17926
17927@smallexample
17928(3 => 10, 17, 1)
17929@end smallexample
17930
17931@noindent
17932That is, in contrast to valid Ada, only the first component has a @code{=>}
17933clause.
17934
17935@item
17936You may abbreviate attributes in expressions with any unique,
17937multi-character subsequence of
17938their names (an exact match gets preference).
17939For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
17940in place of @t{a'length}.
17941
17942@item
17943@cindex quoting Ada internal identifiers
17944Since Ada is case-insensitive, the debugger normally maps identifiers you type
17945to lower case. The GNAT compiler uses upper-case characters for
17946some of its internal identifiers, which are normally of no interest to users.
17947For the rare occasions when you actually have to look at them,
17948enclose them in angle brackets to avoid the lower-case mapping.
17949For example,
17950@smallexample
077e0a52 17951(@value{GDBP}) print <JMPBUF_SAVE>[0]
e07c999f
PH
17952@end smallexample
17953
17954@item
17955Printing an object of class-wide type or dereferencing an
17956access-to-class-wide value will display all the components of the object's
17957specific type (as indicated by its run-time tag). Likewise, component
17958selection on such a value will operate on the specific type of the
17959object.
17960
17961@end itemize
17962
3685b09f
PMR
17963@node Overloading support for Ada
17964@subsubsection Overloading support for Ada
17965@cindex overloading, Ada
17966
17967The debugger supports limited overloading. Given a subprogram call in which
17968the function symbol has multiple definitions, it will use the number of
17969actual parameters and some information about their types to attempt to narrow
17970the set of definitions. It also makes very limited use of context, preferring
17971procedures to functions in the context of the @code{call} command, and
17972functions to procedures elsewhere.
17973
17974If, after narrowing, the set of matching definitions still contains more than
17975one definition, @value{GDBN} will display a menu to query which one it should
17976use, for instance:
17977
17978@smallexample
17979(@value{GDBP}) print f(1)
17980Multiple matches for f
17981[0] cancel
17982[1] foo.f (integer) return boolean at foo.adb:23
17983[2] foo.f (foo.new_integer) return boolean at foo.adb:28
17984>
17985@end smallexample
17986
17987In this case, just select one menu entry either to cancel expression evaluation
17988(type @kbd{0} and press @key{RET}) or to continue evaluation with a specific
17989instance (type the corresponding number and press @key{RET}).
17990
17991Here are a couple of commands to customize @value{GDBN}'s behavior in this
17992case:
17993
17994@table @code
17995
17996@kindex set ada print-signatures
17997@item set ada print-signatures
17998Control whether parameter types and return types are displayed in overloads
17999selection menus. It is @code{on} by default.
18000@xref{Overloading support for Ada}.
18001
18002@kindex show ada print-signatures
18003@item show ada print-signatures
18004Show the current setting for displaying parameter types and return types in
18005overloads selection menu.
18006@xref{Overloading support for Ada}.
18007
18008@end table
18009
e07c999f
PH
18010@node Stopping Before Main Program
18011@subsubsection Stopping at the Very Beginning
18012
18013@cindex breakpointing Ada elaboration code
18014It is sometimes necessary to debug the program during elaboration, and
18015before reaching the main procedure.
18016As defined in the Ada Reference
18017Manual, the elaboration code is invoked from a procedure called
18018@code{adainit}. To run your program up to the beginning of
18019elaboration, simply use the following two commands:
18020@code{tbreak adainit} and @code{run}.
18021
58d06528
JB
18022@node Ada Exceptions
18023@subsubsection Ada Exceptions
18024
18025A command is provided to list all Ada exceptions:
18026
18027@table @code
18028@kindex info exceptions
18029@item info exceptions
18030@itemx info exceptions @var{regexp}
18031The @code{info exceptions} command allows you to list all Ada exceptions
18032defined within the program being debugged, as well as their addresses.
18033With a regular expression, @var{regexp}, as argument, only those exceptions
18034whose names match @var{regexp} are listed.
18035@end table
18036
18037Below is a small example, showing how the command can be used, first
18038without argument, and next with a regular expression passed as an
18039argument.
18040
18041@smallexample
18042(@value{GDBP}) info exceptions
18043All defined Ada exceptions:
18044constraint_error: 0x613da0
18045program_error: 0x613d20
18046storage_error: 0x613ce0
18047tasking_error: 0x613ca0
18048const.aint_global_e: 0x613b00
18049(@value{GDBP}) info exceptions const.aint
18050All Ada exceptions matching regular expression "const.aint":
18051constraint_error: 0x613da0
18052const.aint_global_e: 0x613b00
18053@end smallexample
18054
18055It is also possible to ask @value{GDBN} to stop your program's execution
18056when an exception is raised. For more details, see @ref{Set Catchpoints}.
18057
20924a55
JB
18058@node Ada Tasks
18059@subsubsection Extensions for Ada Tasks
18060@cindex Ada, tasking
18061
18062Support for Ada tasks is analogous to that for threads (@pxref{Threads}).
18063@value{GDBN} provides the following task-related commands:
18064
18065@table @code
18066@kindex info tasks
18067@item info tasks
18068This command shows a list of current Ada tasks, as in the following example:
18069
18070
18071@smallexample
18072@iftex
18073@leftskip=0.5cm
18074@end iftex
18075(@value{GDBP}) info tasks
18076 ID TID P-ID Pri State Name
18077 1 8088000 0 15 Child Activation Wait main_task
18078 2 80a4000 1 15 Accept Statement b
18079 3 809a800 1 15 Child Activation Wait a
32cd1edc 18080* 4 80ae800 3 15 Runnable c
20924a55
JB
18081
18082@end smallexample
18083
18084@noindent
18085In this listing, the asterisk before the last task indicates it to be the
18086task currently being inspected.
18087
18088@table @asis
18089@item ID
18090Represents @value{GDBN}'s internal task number.
18091
18092@item TID
18093The Ada task ID.
18094
18095@item P-ID
18096The parent's task ID (@value{GDBN}'s internal task number).
18097
18098@item Pri
18099The base priority of the task.
18100
18101@item State
18102Current state of the task.
18103
18104@table @code
18105@item Unactivated
18106The task has been created but has not been activated. It cannot be
18107executing.
18108
20924a55
JB
18109@item Runnable
18110The task is not blocked for any reason known to Ada. (It may be waiting
18111for a mutex, though.) It is conceptually "executing" in normal mode.
18112
18113@item Terminated
18114The task is terminated, in the sense of ARM 9.3 (5). Any dependents
18115that were waiting on terminate alternatives have been awakened and have
18116terminated themselves.
18117
18118@item Child Activation Wait
18119The task is waiting for created tasks to complete activation.
18120
18121@item Accept Statement
18122The task is waiting on an accept or selective wait statement.
18123
18124@item Waiting on entry call
18125The task is waiting on an entry call.
18126
18127@item Async Select Wait
18128The task is waiting to start the abortable part of an asynchronous
18129select statement.
18130
18131@item Delay Sleep
18132The task is waiting on a select statement with only a delay
18133alternative open.
18134
18135@item Child Termination Wait
18136The task is sleeping having completed a master within itself, and is
18137waiting for the tasks dependent on that master to become terminated or
18138waiting on a terminate Phase.
18139
18140@item Wait Child in Term Alt
18141The task is sleeping waiting for tasks on terminate alternatives to
18142finish terminating.
18143
18144@item Accepting RV with @var{taskno}
18145The task is accepting a rendez-vous with the task @var{taskno}.
18146@end table
18147
18148@item Name
18149Name of the task in the program.
18150
18151@end table
18152
18153@kindex info task @var{taskno}
18154@item info task @var{taskno}
6b92c0d3 18155This command shows detailed informations on the specified task, as in
20924a55
JB
18156the following example:
18157@smallexample
18158@iftex
18159@leftskip=0.5cm
18160@end iftex
18161(@value{GDBP}) info tasks
18162 ID TID P-ID Pri State Name
18163 1 8077880 0 15 Child Activation Wait main_task
32cd1edc 18164* 2 807c468 1 15 Runnable task_1
20924a55
JB
18165(@value{GDBP}) info task 2
18166Ada Task: 0x807c468
4993045d 18167Name: "task_1"
87f7ab7b
JB
18168Thread: 0
18169LWP: 0x1fac
4993045d 18170Parent: 1 ("main_task")
20924a55
JB
18171Base Priority: 15
18172State: Runnable
18173@end smallexample
18174
18175@item task
18176@kindex task@r{ (Ada)}
18177@cindex current Ada task ID
4993045d 18178This command prints the ID and name of the current task.
20924a55
JB
18179
18180@smallexample
18181@iftex
18182@leftskip=0.5cm
18183@end iftex
18184(@value{GDBP}) info tasks
18185 ID TID P-ID Pri State Name
18186 1 8077870 0 15 Child Activation Wait main_task
4993045d 18187* 2 807c458 1 15 Runnable some_task
20924a55 18188(@value{GDBP}) task
4993045d 18189[Current task is 2 "some_task"]
20924a55
JB
18190@end smallexample
18191
18192@item task @var{taskno}
18193@cindex Ada task switching
5d5658a1 18194This command is like the @code{thread @var{thread-id}}
20924a55
JB
18195command (@pxref{Threads}). It switches the context of debugging
18196from the current task to the given task.
18197
18198@smallexample
18199@iftex
18200@leftskip=0.5cm
18201@end iftex
18202(@value{GDBP}) info tasks
18203 ID TID P-ID Pri State Name
18204 1 8077870 0 15 Child Activation Wait main_task
4993045d 18205* 2 807c458 1 15 Runnable some_task
20924a55 18206(@value{GDBP}) task 1
4993045d 18207[Switching to task 1 "main_task"]
20924a55
JB
18208#0 0x8067726 in pthread_cond_wait ()
18209(@value{GDBP}) bt
18210#0 0x8067726 in pthread_cond_wait ()
18211#1 0x8056714 in system.os_interface.pthread_cond_wait ()
18212#2 0x805cb63 in system.task_primitives.operations.sleep ()
18213#3 0x806153e in system.tasking.stages.activate_tasks ()
18214#4 0x804aacc in un () at un.adb:5
18215@end smallexample
18216
629500fa
KS
18217@item break @var{location} task @var{taskno}
18218@itemx break @var{location} task @var{taskno} if @dots{}
45ac276d
JB
18219@cindex breakpoints and tasks, in Ada
18220@cindex task breakpoints, in Ada
18221@kindex break @dots{} task @var{taskno}@r{ (Ada)}
18222These commands are like the @code{break @dots{} thread @dots{}}
697aa1b7 18223command (@pxref{Thread Stops}). The
629500fa 18224@var{location} argument specifies source lines, as described
45ac276d
JB
18225in @ref{Specify Location}.
18226
18227Use the qualifier @samp{task @var{taskno}} with a breakpoint command
18228to specify that you only want @value{GDBN} to stop the program when a
697aa1b7 18229particular Ada task reaches this breakpoint. The @var{taskno} is one of the
45ac276d
JB
18230numeric task identifiers assigned by @value{GDBN}, shown in the first
18231column of the @samp{info tasks} display.
18232
18233If you do not specify @samp{task @var{taskno}} when you set a
18234breakpoint, the breakpoint applies to @emph{all} tasks of your
18235program.
18236
18237You can use the @code{task} qualifier on conditional breakpoints as
18238well; in this case, place @samp{task @var{taskno}} before the
18239breakpoint condition (before the @code{if}).
18240
18241For example,
18242
18243@smallexample
18244@iftex
18245@leftskip=0.5cm
18246@end iftex
18247(@value{GDBP}) info tasks
18248 ID TID P-ID Pri State Name
18249 1 140022020 0 15 Child Activation Wait main_task
18250 2 140045060 1 15 Accept/Select Wait t2
18251 3 140044840 1 15 Runnable t1
18252* 4 140056040 1 15 Runnable t3
18253(@value{GDBP}) b 15 task 2
18254Breakpoint 5 at 0x120044cb0: file test_task_debug.adb, line 15.
18255(@value{GDBP}) cont
18256Continuing.
18257task # 1 running
18258task # 2 running
18259
18260Breakpoint 5, test_task_debug () at test_task_debug.adb:15
1826115 flush;
18262(@value{GDBP}) info tasks
18263 ID TID P-ID Pri State Name
18264 1 140022020 0 15 Child Activation Wait main_task
18265* 2 140045060 1 15 Runnable t2
18266 3 140044840 1 15 Runnable t1
18267 4 140056040 1 15 Delay Sleep t3
18268@end smallexample
20924a55
JB
18269@end table
18270
18271@node Ada Tasks and Core Files
18272@subsubsection Tasking Support when Debugging Core Files
18273@cindex Ada tasking and core file debugging
18274
18275When inspecting a core file, as opposed to debugging a live program,
18276tasking support may be limited or even unavailable, depending on
18277the platform being used.
18278For instance, on x86-linux, the list of tasks is available, but task
32a8097b 18279switching is not supported.
20924a55 18280
32a8097b 18281On certain platforms, the debugger needs to perform some
20924a55
JB
18282memory writes in order to provide Ada tasking support. When inspecting
18283a core file, this means that the core file must be opened with read-write
18284privileges, using the command @samp{"set write on"} (@pxref{Patching}).
18285Under these circumstances, you should make a backup copy of the core
18286file before inspecting it with @value{GDBN}.
18287
6e1bb179
JB
18288@node Ravenscar Profile
18289@subsubsection Tasking Support when using the Ravenscar Profile
18290@cindex Ravenscar Profile
18291
18292The @dfn{Ravenscar Profile} is a subset of the Ada tasking features,
18293specifically designed for systems with safety-critical real-time
18294requirements.
18295
18296@table @code
18297@kindex set ravenscar task-switching on
18298@cindex task switching with program using Ravenscar Profile
18299@item set ravenscar task-switching on
18300Allows task switching when debugging a program that uses the Ravenscar
18301Profile. This is the default.
18302
18303@kindex set ravenscar task-switching off
18304@item set ravenscar task-switching off
18305Turn off task switching when debugging a program that uses the Ravenscar
18306Profile. This is mostly intended to disable the code that adds support
18307for the Ravenscar Profile, in case a bug in either @value{GDBN} or in
18308the Ravenscar runtime is preventing @value{GDBN} from working properly.
18309To be effective, this command should be run before the program is started.
18310
18311@kindex show ravenscar task-switching
18312@item show ravenscar task-switching
18313Show whether it is possible to switch from task to task in a program
18314using the Ravenscar Profile.
18315
18316@end table
18317
3fcded8f
JB
18318@node Ada Settings
18319@subsubsection Ada Settings
18320@cindex Ada settings
18321
18322@table @code
18323@kindex set varsize-limit
18324@item set varsize-limit @var{size}
18325Prevent @value{GDBN} from attempting to evaluate objects whose size
18326is above the given limit (@var{size}) when those sizes are computed
18327from run-time quantities. This is typically the case when the object
18328has a variable size, such as an array whose bounds are not known at
18329compile time for example. Setting @var{size} to @code{unlimited}
18330removes the size limitation. By default, the limit is about 65KB.
18331
18332The purpose of having such a limit is to prevent @value{GDBN} from
18333trying to grab enormous chunks of virtual memory when asked to evaluate
18334a quantity whose bounds have been corrupted or have not yet been fully
18335initialized. The limit applies to the results of some subexpressions
18336as well as to complete expressions. For example, an expression denoting
18337a simple integer component, such as @code{x.y.z}, may fail if the size of
18338@code{x.y} is variable and exceeds @code{size}. On the other hand,
18339@value{GDBN} is sometimes clever; the expression @code{A(i)}, where
18340@code{A} is an array variable with non-constant size, will generally
18341succeed regardless of the bounds on @code{A}, as long as the component
18342size is less than @var{size}.
18343
18344@kindex show varsize-limit
18345@item show varsize-limit
18346Show the limit on types whose size is determined by run-time quantities.
18347@end table
18348
e07c999f
PH
18349@node Ada Glitches
18350@subsubsection Known Peculiarities of Ada Mode
18351@cindex Ada, problems
18352
18353Besides the omissions listed previously (@pxref{Omissions from Ada}),
18354we know of several problems with and limitations of Ada mode in
18355@value{GDBN},
18356some of which will be fixed with planned future releases of the debugger
18357and the GNU Ada compiler.
18358
18359@itemize @bullet
e07c999f
PH
18360@item
18361Static constants that the compiler chooses not to materialize as objects in
18362storage are invisible to the debugger.
18363
18364@item
18365Named parameter associations in function argument lists are ignored (the
18366argument lists are treated as positional).
18367
18368@item
18369Many useful library packages are currently invisible to the debugger.
18370
18371@item
18372Fixed-point arithmetic, conversions, input, and output is carried out using
18373floating-point arithmetic, and may give results that only approximate those on
18374the host machine.
18375
e07c999f
PH
18376@item
18377The GNAT compiler never generates the prefix @code{Standard} for any of
18378the standard symbols defined by the Ada language. @value{GDBN} knows about
18379this: it will strip the prefix from names when you use it, and will never
18380look for a name you have so qualified among local symbols, nor match against
18381symbols in other packages or subprograms. If you have
18382defined entities anywhere in your program other than parameters and
18383local variables whose simple names match names in @code{Standard},
18384GNAT's lack of qualification here can cause confusion. When this happens,
18385you can usually resolve the confusion
18386by qualifying the problematic names with package
18387@code{Standard} explicitly.
18388@end itemize
18389
95433b34
JB
18390Older versions of the compiler sometimes generate erroneous debugging
18391information, resulting in the debugger incorrectly printing the value
18392of affected entities. In some cases, the debugger is able to work
18393around an issue automatically. In other cases, the debugger is able
18394to work around the issue, but the work-around has to be specifically
18395enabled.
18396
18397@kindex set ada trust-PAD-over-XVS
18398@kindex show ada trust-PAD-over-XVS
18399@table @code
18400
18401@item set ada trust-PAD-over-XVS on
18402Configure GDB to strictly follow the GNAT encoding when computing the
18403value of Ada entities, particularly when @code{PAD} and @code{PAD___XVS}
18404types are involved (see @code{ada/exp_dbug.ads} in the GCC sources for
18405a complete description of the encoding used by the GNAT compiler).
18406This is the default.
18407
18408@item set ada trust-PAD-over-XVS off
18409This is related to the encoding using by the GNAT compiler. If @value{GDBN}
18410sometimes prints the wrong value for certain entities, changing @code{ada
18411trust-PAD-over-XVS} to @code{off} activates a work-around which may fix
18412the issue. It is always safe to set @code{ada trust-PAD-over-XVS} to
18413@code{off}, but this incurs a slight performance penalty, so it is
18414recommended to leave this setting to @code{on} unless necessary.
18415
18416@end table
18417
c6044dd1
JB
18418@cindex GNAT descriptive types
18419@cindex GNAT encoding
18420Internally, the debugger also relies on the compiler following a number
18421of conventions known as the @samp{GNAT Encoding}, all documented in
18422@file{gcc/ada/exp_dbug.ads} in the GCC sources. This encoding describes
18423how the debugging information should be generated for certain types.
18424In particular, this convention makes use of @dfn{descriptive types},
18425which are artificial types generated purely to help the debugger.
18426
18427These encodings were defined at a time when the debugging information
18428format used was not powerful enough to describe some of the more complex
18429types available in Ada. Since DWARF allows us to express nearly all
18430Ada features, the long-term goal is to slowly replace these descriptive
18431types by their pure DWARF equivalent. To facilitate that transition,
18432a new maintenance option is available to force the debugger to ignore
18433those descriptive types. It allows the user to quickly evaluate how
18434well @value{GDBN} works without them.
18435
18436@table @code
18437
18438@kindex maint ada set ignore-descriptive-types
18439@item maintenance ada set ignore-descriptive-types [on|off]
18440Control whether the debugger should ignore descriptive types.
18441The default is not to ignore descriptives types (@code{off}).
18442
18443@kindex maint ada show ignore-descriptive-types
18444@item maintenance ada show ignore-descriptive-types
18445Show if descriptive types are ignored by @value{GDBN}.
18446
18447@end table
18448
79a6e687
BW
18449@node Unsupported Languages
18450@section Unsupported Languages
4e562065
JB
18451
18452@cindex unsupported languages
18453@cindex minimal language
18454In addition to the other fully-supported programming languages,
18455@value{GDBN} also provides a pseudo-language, called @code{minimal}.
18456It does not represent a real programming language, but provides a set
18457of capabilities close to what the C or assembly languages provide.
18458This should allow most simple operations to be performed while debugging
18459an application that uses a language currently not supported by @value{GDBN}.
18460
18461If the language is set to @code{auto}, @value{GDBN} will automatically
18462select this language if the current frame corresponds to an unsupported
18463language.
18464
6d2ebf8b 18465@node Symbols
c906108c
SS
18466@chapter Examining the Symbol Table
18467
d4f3574e 18468The commands described in this chapter allow you to inquire about the
c906108c
SS
18469symbols (names of variables, functions and types) defined in your
18470program. This information is inherent in the text of your program and
18471does not change as your program executes. @value{GDBN} finds it in your
18472program's symbol table, in the file indicated when you started @value{GDBN}
79a6e687
BW
18473(@pxref{File Options, ,Choosing Files}), or by one of the
18474file-management commands (@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
18475
18476@cindex symbol names
18477@cindex names of symbols
18478@cindex quoting names
d044bac8 18479@anchor{quoting names}
c906108c
SS
18480Occasionally, you may need to refer to symbols that contain unusual
18481characters, which @value{GDBN} ordinarily treats as word delimiters. The
18482most frequent case is in referring to static variables in other
79a6e687 18483source files (@pxref{Variables,,Program Variables}). File names
c906108c
SS
18484are recorded in object files as debugging symbols, but @value{GDBN} would
18485ordinarily parse a typical file name, like @file{foo.c}, as the three words
18486@samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
18487@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
18488
474c8240 18489@smallexample
c906108c 18490p 'foo.c'::x
474c8240 18491@end smallexample
c906108c
SS
18492
18493@noindent
18494looks up the value of @code{x} in the scope of the file @file{foo.c}.
18495
18496@table @code
a8f24a35
EZ
18497@cindex case-insensitive symbol names
18498@cindex case sensitivity in symbol names
18499@kindex set case-sensitive
18500@item set case-sensitive on
18501@itemx set case-sensitive off
18502@itemx set case-sensitive auto
18503Normally, when @value{GDBN} looks up symbols, it matches their names
18504with case sensitivity determined by the current source language.
18505Occasionally, you may wish to control that. The command @code{set
18506case-sensitive} lets you do that by specifying @code{on} for
18507case-sensitive matches or @code{off} for case-insensitive ones. If
18508you specify @code{auto}, case sensitivity is reset to the default
18509suitable for the source language. The default is case-sensitive
18510matches for all languages except for Fortran, for which the default is
18511case-insensitive matches.
18512
9c16f35a
EZ
18513@kindex show case-sensitive
18514@item show case-sensitive
a8f24a35
EZ
18515This command shows the current setting of case sensitivity for symbols
18516lookups.
18517
53342f27
TT
18518@kindex set print type methods
18519@item set print type methods
18520@itemx set print type methods on
18521@itemx set print type methods off
18522Normally, when @value{GDBN} prints a class, it displays any methods
18523declared in that class. You can control this behavior either by
18524passing the appropriate flag to @code{ptype}, or using @command{set
18525print type methods}. Specifying @code{on} will cause @value{GDBN} to
18526display the methods; this is the default. Specifying @code{off} will
18527cause @value{GDBN} to omit the methods.
18528
18529@kindex show print type methods
18530@item show print type methods
18531This command shows the current setting of method display when printing
18532classes.
18533
883fd55a
KS
18534@kindex set print type nested-type-limit
18535@item set print type nested-type-limit @var{limit}
18536@itemx set print type nested-type-limit unlimited
18537Set the limit of displayed nested types that the type printer will
18538show. A @var{limit} of @code{unlimited} or @code{-1} will show all
18539nested definitions. By default, the type printer will not show any nested
18540types defined in classes.
18541
18542@kindex show print type nested-type-limit
18543@item show print type nested-type-limit
18544This command shows the current display limit of nested types when
18545printing classes.
18546
53342f27
TT
18547@kindex set print type typedefs
18548@item set print type typedefs
18549@itemx set print type typedefs on
18550@itemx set print type typedefs off
18551
18552Normally, when @value{GDBN} prints a class, it displays any typedefs
18553defined in that class. You can control this behavior either by
18554passing the appropriate flag to @code{ptype}, or using @command{set
18555print type typedefs}. Specifying @code{on} will cause @value{GDBN} to
18556display the typedef definitions; this is the default. Specifying
18557@code{off} will cause @value{GDBN} to omit the typedef definitions.
18558Note that this controls whether the typedef definition itself is
18559printed, not whether typedef names are substituted when printing other
18560types.
18561
18562@kindex show print type typedefs
18563@item show print type typedefs
18564This command shows the current setting of typedef display when
18565printing classes.
18566
c906108c 18567@kindex info address
b37052ae 18568@cindex address of a symbol
c906108c
SS
18569@item info address @var{symbol}
18570Describe where the data for @var{symbol} is stored. For a register
18571variable, this says which register it is kept in. For a non-register
18572local variable, this prints the stack-frame offset at which the variable
18573is always stored.
18574
18575Note the contrast with @samp{print &@var{symbol}}, which does not work
18576at all for a register variable, and for a stack local variable prints
18577the exact address of the current instantiation of the variable.
18578
3d67e040 18579@kindex info symbol
b37052ae 18580@cindex symbol from address
9c16f35a 18581@cindex closest symbol and offset for an address
3d67e040
EZ
18582@item info symbol @var{addr}
18583Print the name of a symbol which is stored at the address @var{addr}.
18584If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
18585nearest symbol and an offset from it:
18586
474c8240 18587@smallexample
3d67e040
EZ
18588(@value{GDBP}) info symbol 0x54320
18589_initialize_vx + 396 in section .text
474c8240 18590@end smallexample
3d67e040
EZ
18591
18592@noindent
18593This is the opposite of the @code{info address} command. You can use
18594it to find out the name of a variable or a function given its address.
18595
c14c28ba
PP
18596For dynamically linked executables, the name of executable or shared
18597library containing the symbol is also printed:
18598
18599@smallexample
18600(@value{GDBP}) info symbol 0x400225
18601_start + 5 in section .text of /tmp/a.out
18602(@value{GDBP}) info symbol 0x2aaaac2811cf
18603__read_nocancel + 6 in section .text of /usr/lib64/libc.so.6
18604@end smallexample
18605
439250fb
DE
18606@kindex demangle
18607@cindex demangle
18608@item demangle @r{[}-l @var{language}@r{]} @r{[}@var{--}@r{]} @var{name}
18609Demangle @var{name}.
18610If @var{language} is provided it is the name of the language to demangle
18611@var{name} in. Otherwise @var{name} is demangled in the current language.
18612
18613The @samp{--} option specifies the end of options,
18614and is useful when @var{name} begins with a dash.
18615
18616The parameter @code{demangle-style} specifies how to interpret the kind
18617of mangling used. @xref{Print Settings}.
18618
c906108c 18619@kindex whatis
53342f27 18620@item whatis[/@var{flags}] [@var{arg}]
177bc839
JK
18621Print the data type of @var{arg}, which can be either an expression
18622or a name of a data type. With no argument, print the data type of
18623@code{$}, the last value in the value history.
18624
18625If @var{arg} is an expression (@pxref{Expressions, ,Expressions}), it
18626is not actually evaluated, and any side-effecting operations (such as
18627assignments or function calls) inside it do not take place.
18628
18629If @var{arg} is a variable or an expression, @code{whatis} prints its
18630literal type as it is used in the source code. If the type was
18631defined using a @code{typedef}, @code{whatis} will @emph{not} print
18632the data type underlying the @code{typedef}. If the type of the
18633variable or the expression is a compound data type, such as
18634@code{struct} or @code{class}, @code{whatis} never prints their
18635fields or methods. It just prints the @code{struct}/@code{class}
18636name (a.k.a.@: its @dfn{tag}). If you want to see the members of
18637such a compound data type, use @code{ptype}.
18638
18639If @var{arg} is a type name that was defined using @code{typedef},
18640@code{whatis} @dfn{unrolls} only one level of that @code{typedef}.
18641Unrolling means that @code{whatis} will show the underlying type used
18642in the @code{typedef} declaration of @var{arg}. However, if that
18643underlying type is also a @code{typedef}, @code{whatis} will not
18644unroll it.
18645
18646For C code, the type names may also have the form @samp{class
18647@var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
18648@var{union-tag}} or @samp{enum @var{enum-tag}}.
c906108c 18649
53342f27
TT
18650@var{flags} can be used to modify how the type is displayed.
18651Available flags are:
18652
18653@table @code
18654@item r
18655Display in ``raw'' form. Normally, @value{GDBN} substitutes template
18656parameters and typedefs defined in a class when printing the class'
18657members. The @code{/r} flag disables this.
18658
18659@item m
18660Do not print methods defined in the class.
18661
18662@item M
18663Print methods defined in the class. This is the default, but the flag
18664exists in case you change the default with @command{set print type methods}.
18665
18666@item t
18667Do not print typedefs defined in the class. Note that this controls
18668whether the typedef definition itself is printed, not whether typedef
18669names are substituted when printing other types.
18670
18671@item T
18672Print typedefs defined in the class. This is the default, but the flag
18673exists in case you change the default with @command{set print type typedefs}.
7c161838
SDJ
18674
18675@item o
18676Print the offsets and sizes of fields in a struct, similar to what the
18677@command{pahole} tool does. This option implies the @code{/tm} flags.
18678
18679For example, given the following declarations:
18680
18681@smallexample
18682struct tuv
18683@{
18684 int a1;
18685 char *a2;
18686 int a3;
18687@};
18688
18689struct xyz
18690@{
18691 int f1;
18692 char f2;
18693 void *f3;
18694 struct tuv f4;
18695@};
18696
18697union qwe
18698@{
18699 struct tuv fff1;
18700 struct xyz fff2;
18701@};
18702
18703struct tyu
18704@{
18705 int a1 : 1;
18706 int a2 : 3;
18707 int a3 : 23;
18708 char a4 : 2;
18709 int64_t a5;
18710 int a6 : 5;
18711 int64_t a7 : 3;
18712@};
18713@end smallexample
18714
18715Issuing a @kbd{ptype /o struct tuv} command would print:
18716
18717@smallexample
18718(@value{GDBP}) ptype /o struct tuv
18719/* offset | size */ type = struct tuv @{
18720/* 0 | 4 */ int a1;
18721/* XXX 4-byte hole */
18722/* 8 | 8 */ char *a2;
18723/* 16 | 4 */ int a3;
18724
18725 /* total size (bytes): 24 */
18726 @}
18727@end smallexample
18728
18729Notice the format of the first column of comments. There, you can
18730find two parts separated by the @samp{|} character: the @emph{offset},
18731which indicates where the field is located inside the struct, in
18732bytes, and the @emph{size} of the field. Another interesting line is
18733the marker of a @emph{hole} in the struct, indicating that it may be
18734possible to pack the struct and make it use less space by reorganizing
18735its fields.
18736
18737It is also possible to print offsets inside an union:
18738
18739@smallexample
18740(@value{GDBP}) ptype /o union qwe
18741/* offset | size */ type = union qwe @{
18742/* 24 */ struct tuv @{
18743/* 0 | 4 */ int a1;
18744/* XXX 4-byte hole */
18745/* 8 | 8 */ char *a2;
18746/* 16 | 4 */ int a3;
18747
18748 /* total size (bytes): 24 */
18749 @} fff1;
18750/* 40 */ struct xyz @{
18751/* 0 | 4 */ int f1;
18752/* 4 | 1 */ char f2;
18753/* XXX 3-byte hole */
18754/* 8 | 8 */ void *f3;
18755/* 16 | 24 */ struct tuv @{
18756/* 16 | 4 */ int a1;
18757/* XXX 4-byte hole */
18758/* 24 | 8 */ char *a2;
18759/* 32 | 4 */ int a3;
18760
18761 /* total size (bytes): 24 */
18762 @} f4;
18763
18764 /* total size (bytes): 40 */
18765 @} fff2;
18766
18767 /* total size (bytes): 40 */
18768 @}
18769@end smallexample
18770
18771In this case, since @code{struct tuv} and @code{struct xyz} occupy the
18772same space (because we are dealing with an union), the offset is not
18773printed for them. However, you can still examine the offset of each
18774of these structures' fields.
18775
18776Another useful scenario is printing the offsets of a struct containing
18777bitfields:
18778
18779@smallexample
18780(@value{GDBP}) ptype /o struct tyu
18781/* offset | size */ type = struct tyu @{
18782/* 0:31 | 4 */ int a1 : 1;
18783/* 0:28 | 4 */ int a2 : 3;
18784/* 0: 5 | 4 */ int a3 : 23;
18785/* 3: 3 | 1 */ signed char a4 : 2;
18786/* XXX 3-bit hole */
18787/* XXX 4-byte hole */
18788/* 8 | 8 */ int64_t a5;
9d3421af
TT
18789/* 16: 0 | 4 */ int a6 : 5;
18790/* 16: 5 | 8 */ int64_t a7 : 3;
18791"/* XXX 7-byte padding */
7c161838
SDJ
18792
18793 /* total size (bytes): 24 */
18794 @}
18795@end smallexample
18796
9d3421af
TT
18797Note how the offset information is now extended to also include the
18798first bit of the bitfield.
53342f27
TT
18799@end table
18800
c906108c 18801@kindex ptype
53342f27 18802@item ptype[/@var{flags}] [@var{arg}]
62f3a2ba
FF
18803@code{ptype} accepts the same arguments as @code{whatis}, but prints a
18804detailed description of the type, instead of just the name of the type.
18805@xref{Expressions, ,Expressions}.
c906108c 18806
177bc839
JK
18807Contrary to @code{whatis}, @code{ptype} always unrolls any
18808@code{typedef}s in its argument declaration, whether the argument is
18809a variable, expression, or a data type. This means that @code{ptype}
18810of a variable or an expression will not print literally its type as
18811present in the source code---use @code{whatis} for that. @code{typedef}s at
18812the pointer or reference targets are also unrolled. Only @code{typedef}s of
18813fields, methods and inner @code{class typedef}s of @code{struct}s,
18814@code{class}es and @code{union}s are not unrolled even with @code{ptype}.
18815
c906108c
SS
18816For example, for this variable declaration:
18817
474c8240 18818@smallexample
177bc839
JK
18819typedef double real_t;
18820struct complex @{ real_t real; double imag; @};
18821typedef struct complex complex_t;
18822complex_t var;
18823real_t *real_pointer_var;
474c8240 18824@end smallexample
c906108c
SS
18825
18826@noindent
18827the two commands give this output:
18828
474c8240 18829@smallexample
c906108c 18830@group
177bc839
JK
18831(@value{GDBP}) whatis var
18832type = complex_t
18833(@value{GDBP}) ptype var
18834type = struct complex @{
18835 real_t real;
18836 double imag;
18837@}
18838(@value{GDBP}) whatis complex_t
18839type = struct complex
18840(@value{GDBP}) whatis struct complex
c906108c 18841type = struct complex
177bc839 18842(@value{GDBP}) ptype struct complex
c906108c 18843type = struct complex @{
177bc839 18844 real_t real;
c906108c
SS
18845 double imag;
18846@}
177bc839
JK
18847(@value{GDBP}) whatis real_pointer_var
18848type = real_t *
18849(@value{GDBP}) ptype real_pointer_var
18850type = double *
c906108c 18851@end group
474c8240 18852@end smallexample
c906108c
SS
18853
18854@noindent
18855As with @code{whatis}, using @code{ptype} without an argument refers to
18856the type of @code{$}, the last value in the value history.
18857
ab1adacd
EZ
18858@cindex incomplete type
18859Sometimes, programs use opaque data types or incomplete specifications
18860of complex data structure. If the debug information included in the
18861program does not allow @value{GDBN} to display a full declaration of
18862the data type, it will say @samp{<incomplete type>}. For example,
18863given these declarations:
18864
18865@smallexample
18866 struct foo;
18867 struct foo *fooptr;
18868@end smallexample
18869
18870@noindent
18871but no definition for @code{struct foo} itself, @value{GDBN} will say:
18872
18873@smallexample
ddb50cd7 18874 (@value{GDBP}) ptype foo
ab1adacd
EZ
18875 $1 = <incomplete type>
18876@end smallexample
18877
18878@noindent
18879``Incomplete type'' is C terminology for data types that are not
18880completely specified.
18881
d69cf9b2
PA
18882@cindex unknown type
18883Othertimes, information about a variable's type is completely absent
18884from the debug information included in the program. This most often
18885happens when the program or library where the variable is defined
18886includes no debug information at all. @value{GDBN} knows the variable
18887exists from inspecting the linker/loader symbol table (e.g., the ELF
18888dynamic symbol table), but such symbols do not contain type
18889information. Inspecting the type of a (global) variable for which
18890@value{GDBN} has no type information shows:
18891
18892@smallexample
18893 (@value{GDBP}) ptype var
18894 type = <data variable, no debug info>
18895@end smallexample
18896
18897@xref{Variables, no debug info variables}, for how to print the values
18898of such variables.
18899
c906108c 18900@kindex info types
a8eab7c6 18901@item info types [-q] [@var{regexp}]
09d4efe1
EZ
18902Print a brief description of all types whose names match the regular
18903expression @var{regexp} (or all types in your program, if you supply
18904no argument). Each complete typename is matched as though it were a
18905complete line; thus, @samp{i type value} gives information on all
18906types in your program whose names include the string @code{value}, but
18907@samp{i type ^value$} gives information only on types whose complete
18908name is @code{value}.
c906108c 18909
20813a0b
PW
18910In programs using different languages, @value{GDBN} chooses the syntax
18911to print the type description according to the
18912@samp{set language} value: using @samp{set language auto}
18913(see @ref{Automatically, ,Set Language Automatically}) means to use the
18914language of the type, other values mean to use
18915the manually specified language (see @ref{Manually, ,Set Language Manually}).
18916
c906108c
SS
18917This command differs from @code{ptype} in two ways: first, like
18918@code{whatis}, it does not print a detailed description; second, it
b744723f 18919lists all source files and line numbers where a type is defined.
c906108c 18920
a8eab7c6
AB
18921The output from @samp{into types} is proceeded with a header line
18922describing what types are being listed. The optional flag @samp{-q},
18923which stands for @samp{quiet}, disables printing this header
18924information.
18925
18a9fc12
TT
18926@kindex info type-printers
18927@item info type-printers
18928Versions of @value{GDBN} that ship with Python scripting enabled may
18929have ``type printers'' available. When using @command{ptype} or
18930@command{whatis}, these printers are consulted when the name of a type
18931is needed. @xref{Type Printing API}, for more information on writing
18932type printers.
18933
18934@code{info type-printers} displays all the available type printers.
18935
18936@kindex enable type-printer
18937@kindex disable type-printer
18938@item enable type-printer @var{name}@dots{}
18939@item disable type-printer @var{name}@dots{}
18940These commands can be used to enable or disable type printers.
18941
b37052ae
EZ
18942@kindex info scope
18943@cindex local variables
09d4efe1 18944@item info scope @var{location}
b37052ae 18945List all the variables local to a particular scope. This command
09d4efe1
EZ
18946accepts a @var{location} argument---a function name, a source line, or
18947an address preceded by a @samp{*}, and prints all the variables local
2a25a5ba
EZ
18948to the scope defined by that location. (@xref{Specify Location}, for
18949details about supported forms of @var{location}.) For example:
b37052ae
EZ
18950
18951@smallexample
18952(@value{GDBP}) @b{info scope command_line_handler}
18953Scope for command_line_handler:
18954Symbol rl is an argument at stack/frame offset 8, length 4.
18955Symbol linebuffer is in static storage at address 0x150a18, length 4.
18956Symbol linelength is in static storage at address 0x150a1c, length 4.
18957Symbol p is a local variable in register $esi, length 4.
18958Symbol p1 is a local variable in register $ebx, length 4.
18959Symbol nline is a local variable in register $edx, length 4.
18960Symbol repeat is a local variable at frame offset -8, length 4.
18961@end smallexample
18962
f5c37c66
EZ
18963@noindent
18964This command is especially useful for determining what data to collect
18965during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
18966collect}.
18967
c906108c
SS
18968@kindex info source
18969@item info source
919d772c
JB
18970Show information about the current source file---that is, the source file for
18971the function containing the current point of execution:
18972@itemize @bullet
18973@item
18974the name of the source file, and the directory containing it,
18975@item
18976the directory it was compiled in,
18977@item
18978its length, in lines,
18979@item
18980which programming language it is written in,
18981@item
b6577aab
DE
18982if the debug information provides it, the program that compiled the file
18983(which may include, e.g., the compiler version and command line arguments),
18984@item
919d772c
JB
18985whether the executable includes debugging information for that file, and
18986if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
18987@item
18988whether the debugging information includes information about
18989preprocessor macros.
18990@end itemize
18991
c906108c
SS
18992
18993@kindex info sources
18994@item info sources
18995Print the names of all source files in your program for which there is
18996debugging information, organized into two lists: files whose symbols
18997have already been read, and files whose symbols will be read when needed.
18998
ae60f04e
PW
18999@item info sources [-dirname | -basename] [--] [@var{regexp}]
19000Like @samp{info sources}, but only print the names of the files
19001matching the provided @var{regexp}.
19002By default, the @var{regexp} is used to match anywhere in the filename.
19003If @code{-dirname}, only files having a dirname matching @var{regexp} are shown.
19004If @code{-basename}, only files having a basename matching @var{regexp}
19005are shown.
19006The matching is case-sensitive, except on operating systems that
19007have case-insensitive filesystem (e.g., MS-Windows).
19008
c906108c 19009@kindex info functions
4acfdd20 19010@item info functions [-q] [-n]
c906108c 19011Print the names and data types of all defined functions.
b744723f
AA
19012Similarly to @samp{info types}, this command groups its output by source
19013files and annotates each function definition with its source line
19014number.
c906108c 19015
20813a0b
PW
19016In programs using different languages, @value{GDBN} chooses the syntax
19017to print the function name and type according to the
19018@samp{set language} value: using @samp{set language auto}
19019(see @ref{Automatically, ,Set Language Automatically}) means to use the
19020language of the function, other values mean to use
19021the manually specified language (see @ref{Manually, ,Set Language Manually}).
19022
4acfdd20
AB
19023The @samp{-n} flag excludes @dfn{non-debugging symbols} from the
19024results. A non-debugging symbol is a symbol that comes from the
19025executable's symbol table, not from the debug information (for
19026example, DWARF) associated with the executable.
19027
d321477b
PW
19028The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19029printing header information and messages explaining why no functions
19030have been printed.
19031
4acfdd20 19032@item info functions [-q] [-n] [-t @var{type_regexp}] [@var{regexp}]
d321477b
PW
19033Like @samp{info functions}, but only print the names and data types
19034of the functions selected with the provided regexp(s).
19035
19036If @var{regexp} is provided, print only the functions whose names
19037match the regular expression @var{regexp}.
19038Thus, @samp{info fun step} finds all functions whose
b744723f
AA
19039names include @code{step}; @samp{info fun ^step} finds those whose names
19040start with @code{step}. If a function name contains characters that
19041conflict with the regular expression language (e.g.@:
1c5dfdad 19042@samp{operator*()}), they may be quoted with a backslash.
c906108c 19043
d321477b
PW
19044If @var{type_regexp} is provided, print only the functions whose
19045types, as printed by the @code{whatis} command, match
19046the regular expression @var{type_regexp}.
19047If @var{type_regexp} contains space(s), it should be enclosed in
19048quote characters. If needed, use backslash to escape the meaning
19049of special characters or quotes.
19050Thus, @samp{info fun -t '^int ('} finds the functions that return
19051an integer; @samp{info fun -t '(.*int.*'} finds the functions that
19052have an argument type containing int; @samp{info fun -t '^int (' ^step}
19053finds the functions whose names start with @code{step} and that return
19054int.
19055
19056If both @var{regexp} and @var{type_regexp} are provided, a function
19057is printed only if its name matches @var{regexp} and its type matches
19058@var{type_regexp}.
19059
19060
c906108c 19061@kindex info variables
4acfdd20 19062@item info variables [-q] [-n]
0fe7935b 19063Print the names and data types of all variables that are defined
6ca652b0 19064outside of functions (i.e.@: excluding local variables).
b744723f
AA
19065The printed variables are grouped by source files and annotated with
19066their respective source line numbers.
c906108c 19067
20813a0b
PW
19068In programs using different languages, @value{GDBN} chooses the syntax
19069to print the variable name and type according to the
19070@samp{set language} value: using @samp{set language auto}
19071(see @ref{Automatically, ,Set Language Automatically}) means to use the
19072language of the variable, other values mean to use
19073the manually specified language (see @ref{Manually, ,Set Language Manually}).
19074
4acfdd20
AB
19075The @samp{-n} flag excludes non-debugging symbols from the results.
19076
d321477b
PW
19077The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19078printing header information and messages explaining why no variables
19079have been printed.
19080
4acfdd20 19081@item info variables [-q] [-n] [-t @var{type_regexp}] [@var{regexp}]
d321477b
PW
19082Like @kbd{info variables}, but only print the variables selected
19083with the provided regexp(s).
19084
19085If @var{regexp} is provided, print only the variables whose names
19086match the regular expression @var{regexp}.
19087
19088If @var{type_regexp} is provided, print only the variables whose
19089types, as printed by the @code{whatis} command, match
19090the regular expression @var{type_regexp}.
19091If @var{type_regexp} contains space(s), it should be enclosed in
19092quote characters. If needed, use backslash to escape the meaning
19093of special characters or quotes.
19094
19095If both @var{regexp} and @var{type_regexp} are provided, an argument
19096is printed only if its name matches @var{regexp} and its type matches
19097@var{type_regexp}.
c906108c 19098
59c35742
AB
19099@kindex info modules
19100@cindex modules
19101@item info modules @r{[}-q@r{]} @r{[}@var{regexp}@r{]}
19102List all Fortran modules in the program, or all modules matching the
19103optional regular expression @var{regexp}.
19104
19105The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19106printing header information and messages explaining why no modules
19107have been printed.
165f8965
AB
19108
19109@kindex info module
19110@cindex Fortran modules, information about
19111@cindex functions and variables by Fortran module
19112@cindex module functions and variables
19113@item info module functions @r{[}-q@r{]} @r{[}-m @var{module-regexp}@r{]} @r{[}-t @var{type-regexp}@r{]} @r{[}@var{regexp}@r{]}
19114@itemx info module variables @r{[}-q@r{]} @r{[}-m @var{module-regexp}@r{]} @r{[}-t @var{type-regexp}@r{]} @r{[}@var{regexp}@r{]}
19115List all functions or variables within all Fortran modules. The set
19116of functions or variables listed can be limited by providing some or
19117all of the optional regular expressions. If @var{module-regexp} is
19118provided, then only Fortran modules matching @var{module-regexp} will
19119be searched. Only functions or variables whose type matches the
19120optional regular expression @var{type-regexp} will be listed. And
19121only functions or variables whose name matches the optional regular
19122expression @var{regexp} will be listed.
19123
19124The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19125printing header information and messages explaining why no functions
19126or variables have been printed.
59c35742 19127
b37303ee 19128@kindex info classes
721c2651 19129@cindex Objective-C, classes and selectors
b37303ee
AF
19130@item info classes
19131@itemx info classes @var{regexp}
19132Display all Objective-C classes in your program, or
19133(with the @var{regexp} argument) all those matching a particular regular
19134expression.
19135
19136@kindex info selectors
19137@item info selectors
19138@itemx info selectors @var{regexp}
19139Display all Objective-C selectors in your program, or
19140(with the @var{regexp} argument) all those matching a particular regular
19141expression.
19142
c906108c
SS
19143@ignore
19144This was never implemented.
19145@kindex info methods
19146@item info methods
19147@itemx info methods @var{regexp}
19148The @code{info methods} command permits the user to examine all defined
b37052ae
EZ
19149methods within C@t{++} program, or (with the @var{regexp} argument) a
19150specific set of methods found in the various C@t{++} classes. Many
19151C@t{++} classes provide a large number of methods. Thus, the output
c906108c
SS
19152from the @code{ptype} command can be overwhelming and hard to use. The
19153@code{info-methods} command filters the methods, printing only those
19154which match the regular-expression @var{regexp}.
19155@end ignore
19156
9c16f35a 19157@cindex opaque data types
c906108c
SS
19158@kindex set opaque-type-resolution
19159@item set opaque-type-resolution on
19160Tell @value{GDBN} to resolve opaque types. An opaque type is a type
19161declared as a pointer to a @code{struct}, @code{class}, or
19162@code{union}---for example, @code{struct MyType *}---that is used in one
19163source file although the full declaration of @code{struct MyType} is in
19164another source file. The default is on.
19165
19166A change in the setting of this subcommand will not take effect until
19167the next time symbols for a file are loaded.
19168
19169@item set opaque-type-resolution off
19170Tell @value{GDBN} not to resolve opaque types. In this case, the type
19171is printed as follows:
19172@smallexample
19173@{<no data fields>@}
19174@end smallexample
19175
19176@kindex show opaque-type-resolution
19177@item show opaque-type-resolution
19178Show whether opaque types are resolved or not.
c906108c 19179
770e7fc7
DE
19180@kindex set print symbol-loading
19181@cindex print messages when symbols are loaded
19182@item set print symbol-loading
19183@itemx set print symbol-loading full
19184@itemx set print symbol-loading brief
19185@itemx set print symbol-loading off
19186The @code{set print symbol-loading} command allows you to control the
19187printing of messages when @value{GDBN} loads symbol information.
19188By default a message is printed for the executable and one for each
19189shared library, and normally this is what you want. However, when
19190debugging apps with large numbers of shared libraries these messages
19191can be annoying.
19192When set to @code{brief} a message is printed for each executable,
19193and when @value{GDBN} loads a collection of shared libraries at once
19194it will only print one message regardless of the number of shared
19195libraries. When set to @code{off} no messages are printed.
19196
19197@kindex show print symbol-loading
19198@item show print symbol-loading
19199Show whether messages will be printed when a @value{GDBN} command
19200entered from the keyboard causes symbol information to be loaded.
19201
c906108c
SS
19202@kindex maint print symbols
19203@cindex symbol dump
19204@kindex maint print psymbols
19205@cindex partial symbol dump
7c57fa1e
YQ
19206@kindex maint print msymbols
19207@cindex minimal symbol dump
34c41c68
DE
19208@item maint print symbols @r{[}-pc @var{address}@r{]} @r{[}@var{filename}@r{]}
19209@itemx maint print symbols @r{[}-objfile @var{objfile}@r{]} @r{[}-source @var{source}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19210@itemx maint print psymbols @r{[}-objfile @var{objfile}@r{]} @r{[}-pc @var{address}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19211@itemx maint print psymbols @r{[}-objfile @var{objfile}@r{]} @r{[}-source @var{source}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19212@itemx maint print msymbols @r{[}-objfile @var{objfile}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19213Write a dump of debugging symbol data into the file @var{filename} or
19214the terminal if @var{filename} is unspecified.
19215If @code{-objfile @var{objfile}} is specified, only dump symbols for
19216that objfile.
19217If @code{-pc @var{address}} is specified, only dump symbols for the file
19218with code at that address. Note that @var{address} may be a symbol like
19219@code{main}.
19220If @code{-source @var{source}} is specified, only dump symbols for that
19221source file.
19222
19223These commands are used to debug the @value{GDBN} symbol-reading code.
19224These commands do not modify internal @value{GDBN} state, therefore
19225@samp{maint print symbols} will only print symbols for already expanded symbol
19226tables.
19227You can use the command @code{info sources} to find out which files these are.
19228If you use @samp{maint print psymbols} instead, the dump shows information
19229about symbols that @value{GDBN} only knows partially---that is, symbols
19230defined in files that @value{GDBN} has skimmed, but not yet read completely.
19231Finally, @samp{maint print msymbols} just dumps ``minimal symbols'', e.g.,
19232``ELF symbols''.
19233
79a6e687 19234@xref{Files, ,Commands to Specify Files}, for a discussion of how
c906108c 19235@value{GDBN} reads symbols (in the description of @code{symbol-file}).
44ea7b70 19236
5e7b2f39
JB
19237@kindex maint info symtabs
19238@kindex maint info psymtabs
44ea7b70
JB
19239@cindex listing @value{GDBN}'s internal symbol tables
19240@cindex symbol tables, listing @value{GDBN}'s internal
19241@cindex full symbol tables, listing @value{GDBN}'s internal
19242@cindex partial symbol tables, listing @value{GDBN}'s internal
5e7b2f39
JB
19243@item maint info symtabs @r{[} @var{regexp} @r{]}
19244@itemx maint info psymtabs @r{[} @var{regexp} @r{]}
44ea7b70
JB
19245
19246List the @code{struct symtab} or @code{struct partial_symtab}
19247structures whose names match @var{regexp}. If @var{regexp} is not
19248given, list them all. The output includes expressions which you can
19249copy into a @value{GDBN} debugging this one to examine a particular
19250structure in more detail. For example:
19251
19252@smallexample
5e7b2f39 19253(@value{GDBP}) maint info psymtabs dwarf2read
44ea7b70
JB
19254@{ objfile /home/gnu/build/gdb/gdb
19255 ((struct objfile *) 0x82e69d0)
b383017d 19256 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
19257 ((struct partial_symtab *) 0x8474b10)
19258 readin no
19259 fullname (null)
19260 text addresses 0x814d3c8 -- 0x8158074
19261 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
19262 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
19263 dependencies (none)
19264 @}
19265@}
5e7b2f39 19266(@value{GDBP}) maint info symtabs
44ea7b70
JB
19267(@value{GDBP})
19268@end smallexample
19269@noindent
19270We see that there is one partial symbol table whose filename contains
19271the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
19272and we see that @value{GDBN} has not read in any symtabs yet at all.
19273If we set a breakpoint on a function, that will cause @value{GDBN} to
19274read the symtab for the compilation unit containing that function:
19275
19276@smallexample
19277(@value{GDBP}) break dwarf2_psymtab_to_symtab
19278Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
19279line 1574.
5e7b2f39 19280(@value{GDBP}) maint info symtabs
b383017d 19281@{ objfile /home/gnu/build/gdb/gdb
44ea7b70 19282 ((struct objfile *) 0x82e69d0)
b383017d 19283 @{ symtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
19284 ((struct symtab *) 0x86c1f38)
19285 dirname (null)
19286 fullname (null)
19287 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
1b39d5c0 19288 linetable ((struct linetable *) 0x8370fa0)
44ea7b70
JB
19289 debugformat DWARF 2
19290 @}
19291@}
b383017d 19292(@value{GDBP})
44ea7b70 19293@end smallexample
44ea7b70 19294
f2403c39
AB
19295@kindex maint info line-table
19296@cindex listing @value{GDBN}'s internal line tables
19297@cindex line tables, listing @value{GDBN}'s internal
19298@item maint info line-table @r{[} @var{regexp} @r{]}
19299
19300List the @code{struct linetable} from all @code{struct symtab}
19301instances whose name matches @var{regexp}. If @var{regexp} is not
19302given, list the @code{struct linetable} from all @code{struct symtab}.
19303
f57d2163
DE
19304@kindex maint set symbol-cache-size
19305@cindex symbol cache size
19306@item maint set symbol-cache-size @var{size}
19307Set the size of the symbol cache to @var{size}.
19308The default size is intended to be good enough for debugging
19309most applications. This option exists to allow for experimenting
19310with different sizes.
19311
19312@kindex maint show symbol-cache-size
19313@item maint show symbol-cache-size
19314Show the size of the symbol cache.
19315
19316@kindex maint print symbol-cache
19317@cindex symbol cache, printing its contents
19318@item maint print symbol-cache
19319Print the contents of the symbol cache.
19320This is useful when debugging symbol cache issues.
19321
19322@kindex maint print symbol-cache-statistics
19323@cindex symbol cache, printing usage statistics
19324@item maint print symbol-cache-statistics
19325Print symbol cache usage statistics.
19326This helps determine how well the cache is being utilized.
19327
19328@kindex maint flush-symbol-cache
19329@cindex symbol cache, flushing
19330@item maint flush-symbol-cache
19331Flush the contents of the symbol cache, all entries are removed.
19332This command is useful when debugging the symbol cache.
19333It is also useful when collecting performance data.
19334
19335@end table
6a3ca067 19336
6d2ebf8b 19337@node Altering
c906108c
SS
19338@chapter Altering Execution
19339
19340Once you think you have found an error in your program, you might want to
19341find out for certain whether correcting the apparent error would lead to
19342correct results in the rest of the run. You can find the answer by
19343experiment, using the @value{GDBN} features for altering execution of the
19344program.
19345
19346For example, you can store new values into variables or memory
7a292a7a
SS
19347locations, give your program a signal, restart it at a different
19348address, or even return prematurely from a function.
c906108c
SS
19349
19350@menu
19351* Assignment:: Assignment to variables
19352* Jumping:: Continuing at a different address
c906108c 19353* Signaling:: Giving your program a signal
c906108c
SS
19354* Returning:: Returning from a function
19355* Calling:: Calling your program's functions
19356* Patching:: Patching your program
bb2ec1b3 19357* Compiling and Injecting Code:: Compiling and injecting code in @value{GDBN}
c906108c
SS
19358@end menu
19359
6d2ebf8b 19360@node Assignment
79a6e687 19361@section Assignment to Variables
c906108c
SS
19362
19363@cindex assignment
19364@cindex setting variables
19365To alter the value of a variable, evaluate an assignment expression.
19366@xref{Expressions, ,Expressions}. For example,
19367
474c8240 19368@smallexample
c906108c 19369print x=4
474c8240 19370@end smallexample
c906108c
SS
19371
19372@noindent
19373stores the value 4 into the variable @code{x}, and then prints the
5d161b24 19374value of the assignment expression (which is 4).
c906108c
SS
19375@xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
19376information on operators in supported languages.
c906108c
SS
19377
19378@kindex set variable
19379@cindex variables, setting
19380If you are not interested in seeing the value of the assignment, use the
19381@code{set} command instead of the @code{print} command. @code{set} is
19382really the same as @code{print} except that the expression's value is
19383not printed and is not put in the value history (@pxref{Value History,
79a6e687 19384,Value History}). The expression is evaluated only for its effects.
c906108c 19385
c906108c
SS
19386If the beginning of the argument string of the @code{set} command
19387appears identical to a @code{set} subcommand, use the @code{set
19388variable} command instead of just @code{set}. This command is identical
19389to @code{set} except for its lack of subcommands. For example, if your
19390program has a variable @code{width}, you get an error if you try to set
19391a new value with just @samp{set width=13}, because @value{GDBN} has the
19392command @code{set width}:
19393
474c8240 19394@smallexample
c906108c
SS
19395(@value{GDBP}) whatis width
19396type = double
19397(@value{GDBP}) p width
19398$4 = 13
19399(@value{GDBP}) set width=47
19400Invalid syntax in expression.
474c8240 19401@end smallexample
c906108c
SS
19402
19403@noindent
19404The invalid expression, of course, is @samp{=47}. In
19405order to actually set the program's variable @code{width}, use
19406
474c8240 19407@smallexample
c906108c 19408(@value{GDBP}) set var width=47
474c8240 19409@end smallexample
53a5351d 19410
c906108c
SS
19411Because the @code{set} command has many subcommands that can conflict
19412with the names of program variables, it is a good idea to use the
19413@code{set variable} command instead of just @code{set}. For example, if
19414your program has a variable @code{g}, you run into problems if you try
19415to set a new value with just @samp{set g=4}, because @value{GDBN} has
19416the command @code{set gnutarget}, abbreviated @code{set g}:
19417
474c8240 19418@smallexample
c906108c
SS
19419@group
19420(@value{GDBP}) whatis g
19421type = double
19422(@value{GDBP}) p g
19423$1 = 1
19424(@value{GDBP}) set g=4
2df3850c 19425(@value{GDBP}) p g
c906108c
SS
19426$2 = 1
19427(@value{GDBP}) r
19428The program being debugged has been started already.
19429Start it from the beginning? (y or n) y
19430Starting program: /home/smith/cc_progs/a.out
6d2ebf8b
SS
19431"/home/smith/cc_progs/a.out": can't open to read symbols:
19432 Invalid bfd target.
c906108c
SS
19433(@value{GDBP}) show g
19434The current BFD target is "=4".
19435@end group
474c8240 19436@end smallexample
c906108c
SS
19437
19438@noindent
19439The program variable @code{g} did not change, and you silently set the
19440@code{gnutarget} to an invalid value. In order to set the variable
19441@code{g}, use
19442
474c8240 19443@smallexample
c906108c 19444(@value{GDBP}) set var g=4
474c8240 19445@end smallexample
c906108c
SS
19446
19447@value{GDBN} allows more implicit conversions in assignments than C; you can
19448freely store an integer value into a pointer variable or vice versa,
19449and you can convert any structure to any other structure that is the
19450same length or shorter.
19451@comment FIXME: how do structs align/pad in these conversions?
19452@comment /doc@cygnus.com 18dec1990
19453
19454To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
19455construct to generate a value of specified type at a specified address
19456(@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
19457to memory location @code{0x83040} as an integer (which implies a certain size
19458and representation in memory), and
19459
474c8240 19460@smallexample
c906108c 19461set @{int@}0x83040 = 4
474c8240 19462@end smallexample
c906108c
SS
19463
19464@noindent
19465stores the value 4 into that memory location.
19466
6d2ebf8b 19467@node Jumping
79a6e687 19468@section Continuing at a Different Address
c906108c
SS
19469
19470Ordinarily, when you continue your program, you do so at the place where
19471it stopped, with the @code{continue} command. You can instead continue at
19472an address of your own choosing, with the following commands:
19473
19474@table @code
19475@kindex jump
c1d780c2 19476@kindex j @r{(@code{jump})}
629500fa 19477@item jump @var{location}
c1d780c2 19478@itemx j @var{location}
629500fa
KS
19479Resume execution at @var{location}. Execution stops again immediately
19480if there is a breakpoint there. @xref{Specify Location}, for a description
19481of the different forms of @var{location}. It is common
2a25a5ba
EZ
19482practice to use the @code{tbreak} command in conjunction with
19483@code{jump}. @xref{Set Breaks, ,Setting Breakpoints}.
c906108c
SS
19484
19485The @code{jump} command does not change the current stack frame, or
19486the stack pointer, or the contents of any memory location or any
629500fa 19487register other than the program counter. If @var{location} is in
c906108c
SS
19488a different function from the one currently executing, the results may
19489be bizarre if the two functions expect different patterns of arguments or
19490of local variables. For this reason, the @code{jump} command requests
19491confirmation if the specified line is not in the function currently
19492executing. However, even bizarre results are predictable if you are
19493well acquainted with the machine-language code of your program.
c906108c
SS
19494@end table
19495
53a5351d
JM
19496On many systems, you can get much the same effect as the @code{jump}
19497command by storing a new value into the register @code{$pc}. The
19498difference is that this does not start your program running; it only
19499changes the address of where it @emph{will} run when you continue. For
19500example,
c906108c 19501
474c8240 19502@smallexample
c906108c 19503set $pc = 0x485
474c8240 19504@end smallexample
c906108c
SS
19505
19506@noindent
19507makes the next @code{continue} command or stepping command execute at
19508address @code{0x485}, rather than at the address where your program stopped.
79a6e687 19509@xref{Continuing and Stepping, ,Continuing and Stepping}.
c906108c
SS
19510
19511The most common occasion to use the @code{jump} command is to back
19512up---perhaps with more breakpoints set---over a portion of a program
19513that has already executed, in order to examine its execution in more
19514detail.
19515
c906108c 19516@c @group
6d2ebf8b 19517@node Signaling
79a6e687 19518@section Giving your Program a Signal
9c16f35a 19519@cindex deliver a signal to a program
c906108c
SS
19520
19521@table @code
19522@kindex signal
19523@item signal @var{signal}
70509625 19524Resume execution where your program is stopped, but immediately give it the
697aa1b7 19525signal @var{signal}. The @var{signal} can be the name or the number of a
c906108c
SS
19526signal. For example, on many systems @code{signal 2} and @code{signal
19527SIGINT} are both ways of sending an interrupt signal.
19528
19529Alternatively, if @var{signal} is zero, continue execution without
19530giving a signal. This is useful when your program stopped on account of
ae606bee 19531a signal and would ordinarily see the signal when resumed with the
c906108c
SS
19532@code{continue} command; @samp{signal 0} causes it to resume without a
19533signal.
19534
70509625
PA
19535@emph{Note:} When resuming a multi-threaded program, @var{signal} is
19536delivered to the currently selected thread, not the thread that last
19537reported a stop. This includes the situation where a thread was
19538stopped due to a signal. So if you want to continue execution
19539suppressing the signal that stopped a thread, you should select that
19540same thread before issuing the @samp{signal 0} command. If you issue
19541the @samp{signal 0} command with another thread as the selected one,
19542@value{GDBN} detects that and asks for confirmation.
19543
c906108c
SS
19544Invoking the @code{signal} command is not the same as invoking the
19545@code{kill} utility from the shell. Sending a signal with @code{kill}
19546causes @value{GDBN} to decide what to do with the signal depending on
19547the signal handling tables (@pxref{Signals}). The @code{signal} command
19548passes the signal directly to your program.
19549
81219e53
DE
19550@code{signal} does not repeat when you press @key{RET} a second time
19551after executing the command.
19552
19553@kindex queue-signal
19554@item queue-signal @var{signal}
19555Queue @var{signal} to be delivered immediately to the current thread
19556when execution of the thread resumes. The @var{signal} can be the name or
19557the number of a signal. For example, on many systems @code{signal 2} and
19558@code{signal SIGINT} are both ways of sending an interrupt signal.
19559The handling of the signal must be set to pass the signal to the program,
19560otherwise @value{GDBN} will report an error.
19561You can control the handling of signals from @value{GDBN} with the
19562@code{handle} command (@pxref{Signals}).
19563
19564Alternatively, if @var{signal} is zero, any currently queued signal
19565for the current thread is discarded and when execution resumes no signal
19566will be delivered. This is useful when your program stopped on account
19567of a signal and would ordinarily see the signal when resumed with the
19568@code{continue} command.
19569
19570This command differs from the @code{signal} command in that the signal
19571is just queued, execution is not resumed. And @code{queue-signal} cannot
19572be used to pass a signal whose handling state has been set to @code{nopass}
19573(@pxref{Signals}).
19574@end table
19575@c @end group
c906108c 19576
e5f8a7cc
PA
19577@xref{stepping into signal handlers}, for information on how stepping
19578commands behave when the thread has a signal queued.
19579
6d2ebf8b 19580@node Returning
79a6e687 19581@section Returning from a Function
c906108c
SS
19582
19583@table @code
19584@cindex returning from a function
19585@kindex return
19586@item return
19587@itemx return @var{expression}
19588You can cancel execution of a function call with the @code{return}
19589command. If you give an
19590@var{expression} argument, its value is used as the function's return
19591value.
19592@end table
19593
19594When you use @code{return}, @value{GDBN} discards the selected stack frame
19595(and all frames within it). You can think of this as making the
19596discarded frame return prematurely. If you wish to specify a value to
19597be returned, give that value as the argument to @code{return}.
19598
19599This pops the selected stack frame (@pxref{Selection, ,Selecting a
79a6e687 19600Frame}), and any other frames inside of it, leaving its caller as the
c906108c
SS
19601innermost remaining frame. That frame becomes selected. The
19602specified value is stored in the registers used for returning values
19603of functions.
19604
19605The @code{return} command does not resume execution; it leaves the
19606program stopped in the state that would exist if the function had just
19607returned. In contrast, the @code{finish} command (@pxref{Continuing
79a6e687 19608and Stepping, ,Continuing and Stepping}) resumes execution until the
c906108c
SS
19609selected stack frame returns naturally.
19610
61ff14c6
JK
19611@value{GDBN} needs to know how the @var{expression} argument should be set for
19612the inferior. The concrete registers assignment depends on the OS ABI and the
19613type being returned by the selected stack frame. For example it is common for
19614OS ABI to return floating point values in FPU registers while integer values in
19615CPU registers. Still some ABIs return even floating point values in CPU
19616registers. Larger integer widths (such as @code{long long int}) also have
19617specific placement rules. @value{GDBN} already knows the OS ABI from its
19618current target so it needs to find out also the type being returned to make the
19619assignment into the right register(s).
19620
19621Normally, the selected stack frame has debug info. @value{GDBN} will always
19622use the debug info instead of the implicit type of @var{expression} when the
19623debug info is available. For example, if you type @kbd{return -1}, and the
19624function in the current stack frame is declared to return a @code{long long
19625int}, @value{GDBN} transparently converts the implicit @code{int} value of -1
19626into a @code{long long int}:
19627
19628@smallexample
19629Breakpoint 1, func () at gdb.base/return-nodebug.c:29
1963029 return 31;
19631(@value{GDBP}) return -1
19632Make func return now? (y or n) y
19633#0 0x004004f6 in main () at gdb.base/return-nodebug.c:43
1963443 printf ("result=%lld\n", func ());
19635(@value{GDBP})
19636@end smallexample
19637
19638However, if the selected stack frame does not have a debug info, e.g., if the
19639function was compiled without debug info, @value{GDBN} has to find out the type
19640to return from user. Specifying a different type by mistake may set the value
19641in different inferior registers than the caller code expects. For example,
19642typing @kbd{return -1} with its implicit type @code{int} would set only a part
19643of a @code{long long int} result for a debug info less function (on 32-bit
19644architectures). Therefore the user is required to specify the return type by
19645an appropriate cast explicitly:
19646
19647@smallexample
19648Breakpoint 2, 0x0040050b in func ()
19649(@value{GDBP}) return -1
19650Return value type not available for selected stack frame.
19651Please use an explicit cast of the value to return.
19652(@value{GDBP}) return (long long int) -1
19653Make selected stack frame return now? (y or n) y
19654#0 0x00400526 in main ()
19655(@value{GDBP})
19656@end smallexample
19657
6d2ebf8b 19658@node Calling
79a6e687 19659@section Calling Program Functions
c906108c 19660
f8568604 19661@table @code
c906108c 19662@cindex calling functions
f8568604
EZ
19663@cindex inferior functions, calling
19664@item print @var{expr}
d3e8051b 19665Evaluate the expression @var{expr} and display the resulting value.
697aa1b7 19666The expression may include calls to functions in the program being
f8568604
EZ
19667debugged.
19668
c906108c 19669@kindex call
c906108c
SS
19670@item call @var{expr}
19671Evaluate the expression @var{expr} without displaying @code{void}
19672returned values.
c906108c
SS
19673
19674You can use this variant of the @code{print} command if you want to
f8568604
EZ
19675execute a function from your program that does not return anything
19676(a.k.a.@: @dfn{a void function}), but without cluttering the output
19677with @code{void} returned values that @value{GDBN} will otherwise
19678print. If the result is not void, it is printed and saved in the
19679value history.
19680@end table
19681
9c16f35a
EZ
19682It is possible for the function you call via the @code{print} or
19683@code{call} command to generate a signal (e.g., if there's a bug in
19684the function, or if you passed it incorrect arguments). What happens
19685in that case is controlled by the @code{set unwindonsignal} command.
19686
7cd1089b
PM
19687Similarly, with a C@t{++} program it is possible for the function you
19688call via the @code{print} or @code{call} command to generate an
19689exception that is not handled due to the constraints of the dummy
19690frame. In this case, any exception that is raised in the frame, but has
19691an out-of-frame exception handler will not be found. GDB builds a
19692dummy-frame for the inferior function call, and the unwinder cannot
19693seek for exception handlers outside of this dummy-frame. What happens
19694in that case is controlled by the
19695@code{set unwind-on-terminating-exception} command.
19696
9c16f35a
EZ
19697@table @code
19698@item set unwindonsignal
19699@kindex set unwindonsignal
19700@cindex unwind stack in called functions
19701@cindex call dummy stack unwinding
19702Set unwinding of the stack if a signal is received while in a function
19703that @value{GDBN} called in the program being debugged. If set to on,
19704@value{GDBN} unwinds the stack it created for the call and restores
19705the context to what it was before the call. If set to off (the
19706default), @value{GDBN} stops in the frame where the signal was
19707received.
19708
19709@item show unwindonsignal
19710@kindex show unwindonsignal
19711Show the current setting of stack unwinding in the functions called by
19712@value{GDBN}.
7cd1089b
PM
19713
19714@item set unwind-on-terminating-exception
19715@kindex set unwind-on-terminating-exception
19716@cindex unwind stack in called functions with unhandled exceptions
19717@cindex call dummy stack unwinding on unhandled exception.
19718Set unwinding of the stack if a C@t{++} exception is raised, but left
19719unhandled while in a function that @value{GDBN} called in the program being
19720debugged. If set to on (the default), @value{GDBN} unwinds the stack
19721it created for the call and restores the context to what it was before
19722the call. If set to off, @value{GDBN} the exception is delivered to
19723the default C@t{++} exception handler and the inferior terminated.
19724
19725@item show unwind-on-terminating-exception
19726@kindex show unwind-on-terminating-exception
19727Show the current setting of stack unwinding in the functions called by
19728@value{GDBN}.
19729
136afab8
PW
19730@item set may-call-functions
19731@kindex set may-call-functions
19732@cindex disabling calling functions in the program
19733@cindex calling functions in the program, disabling
19734Set permission to call functions in the program.
19735This controls whether @value{GDBN} will attempt to call functions in
19736the program, such as with expressions in the @code{print} command. It
19737defaults to @code{on}.
19738
19739To call a function in the program, @value{GDBN} has to temporarily
19740modify the state of the inferior. This has potentially undesired side
19741effects. Also, having @value{GDBN} call nested functions is likely to
19742be erroneous and may even crash the program being debugged. You can
19743avoid such hazards by forbidding @value{GDBN} from calling functions
19744in the program being debugged. If calling functions in the program
19745is forbidden, GDB will throw an error when a command (such as printing
19746an expression) starts a function call in the program.
19747
19748@item show may-call-functions
19749@kindex show may-call-functions
19750Show permission to call functions in the program.
19751
9c16f35a
EZ
19752@end table
19753
d69cf9b2
PA
19754@subsection Calling functions with no debug info
19755
19756@cindex no debug info functions
19757Sometimes, a function you wish to call is missing debug information.
19758In such case, @value{GDBN} does not know the type of the function,
19759including the types of the function's parameters. To avoid calling
19760the inferior function incorrectly, which could result in the called
19761function functioning erroneously and even crash, @value{GDBN} refuses
19762to call the function unless you tell it the type of the function.
19763
19764For prototyped (i.e.@: ANSI/ISO style) functions, there are two ways
19765to do that. The simplest is to cast the call to the function's
19766declared return type. For example:
19767
19768@smallexample
19769(@value{GDBP}) p getenv ("PATH")
19770'getenv' has unknown return type; cast the call to its declared return type
19771(@value{GDBP}) p (char *) getenv ("PATH")
19772$1 = 0x7fffffffe7ba "/usr/local/bin:/"...
19773@end smallexample
19774
19775Casting the return type of a no-debug function is equivalent to
19776casting the function to a pointer to a prototyped function that has a
19777prototype that matches the types of the passed-in arguments, and
19778calling that. I.e., the call above is equivalent to:
19779
19780@smallexample
19781(@value{GDBP}) p ((char * (*) (const char *)) getenv) ("PATH")
19782@end smallexample
19783
19784@noindent
19785and given this prototyped C or C++ function with float parameters:
19786
19787@smallexample
19788float multiply (float v1, float v2) @{ return v1 * v2; @}
19789@end smallexample
19790
19791@noindent
19792these calls are equivalent:
19793
19794@smallexample
19795(@value{GDBP}) p (float) multiply (2.0f, 3.0f)
19796(@value{GDBP}) p ((float (*) (float, float)) multiply) (2.0f, 3.0f)
19797@end smallexample
19798
19799If the function you wish to call is declared as unprototyped (i.e.@:
19800old K&R style), you must use the cast-to-function-pointer syntax, so
19801that @value{GDBN} knows that it needs to apply default argument
19802promotions (promote float arguments to double). @xref{ABI, float
19803promotion}. For example, given this unprototyped C function with
19804float parameters, and no debug info:
19805
19806@smallexample
19807float
19808multiply_noproto (v1, v2)
19809 float v1, v2;
19810@{
19811 return v1 * v2;
19812@}
19813@end smallexample
19814
19815@noindent
19816you call it like this:
19817
19818@smallexample
19819 (@value{GDBP}) p ((float (*) ()) multiply_noproto) (2.0f, 3.0f)
19820@end smallexample
c906108c 19821
6d2ebf8b 19822@node Patching
79a6e687 19823@section Patching Programs
7a292a7a 19824
c906108c
SS
19825@cindex patching binaries
19826@cindex writing into executables
c906108c 19827@cindex writing into corefiles
c906108c 19828
7a292a7a
SS
19829By default, @value{GDBN} opens the file containing your program's
19830executable code (or the corefile) read-only. This prevents accidental
19831alterations to machine code; but it also prevents you from intentionally
19832patching your program's binary.
c906108c
SS
19833
19834If you'd like to be able to patch the binary, you can specify that
19835explicitly with the @code{set write} command. For example, you might
19836want to turn on internal debugging flags, or even to make emergency
19837repairs.
19838
19839@table @code
19840@kindex set write
19841@item set write on
19842@itemx set write off
7a292a7a 19843If you specify @samp{set write on}, @value{GDBN} opens executable and
20924a55 19844core files for both reading and writing; if you specify @kbd{set write
c906108c
SS
19845off} (the default), @value{GDBN} opens them read-only.
19846
19847If you have already loaded a file, you must load it again (using the
7a292a7a
SS
19848@code{exec-file} or @code{core-file} command) after changing @code{set
19849write}, for your new setting to take effect.
c906108c
SS
19850
19851@item show write
19852@kindex show write
7a292a7a
SS
19853Display whether executable files and core files are opened for writing
19854as well as reading.
c906108c
SS
19855@end table
19856
bb2ec1b3
TT
19857@node Compiling and Injecting Code
19858@section Compiling and injecting code in @value{GDBN}
19859@cindex injecting code
19860@cindex writing into executables
19861@cindex compiling code
19862
19863@value{GDBN} supports on-demand compilation and code injection into
19864programs running under @value{GDBN}. GCC 5.0 or higher built with
19865@file{libcc1.so} must be installed for this functionality to be enabled.
19866This functionality is implemented with the following commands.
19867
19868@table @code
19869@kindex compile code
19870@item compile code @var{source-code}
19871@itemx compile code -raw @var{--} @var{source-code}
19872Compile @var{source-code} with the compiler language found as the current
19873language in @value{GDBN} (@pxref{Languages}). If compilation and
19874injection is not supported with the current language specified in
19875@value{GDBN}, or the compiler does not support this feature, an error
19876message will be printed. If @var{source-code} compiles and links
19877successfully, @value{GDBN} will load the object-code emitted,
19878and execute it within the context of the currently selected inferior.
19879It is important to note that the compiled code is executed immediately.
19880After execution, the compiled code is removed from @value{GDBN} and any
19881new types or variables you have defined will be deleted.
19882
19883The command allows you to specify @var{source-code} in two ways.
19884The simplest method is to provide a single line of code to the command.
19885E.g.:
19886
19887@smallexample
19888compile code printf ("hello world\n");
19889@end smallexample
19890
19891If you specify options on the command line as well as source code, they
19892may conflict. The @samp{--} delimiter can be used to separate options
19893from actual source code. E.g.:
19894
19895@smallexample
19896compile code -r -- printf ("hello world\n");
19897@end smallexample
19898
19899Alternatively you can enter source code as multiple lines of text. To
19900enter this mode, invoke the @samp{compile code} command without any text
19901following the command. This will start the multiple-line editor and
19902allow you to type as many lines of source code as required. When you
19903have completed typing, enter @samp{end} on its own line to exit the
19904editor.
19905
19906@smallexample
19907compile code
19908>printf ("hello\n");
19909>printf ("world\n");
19910>end
19911@end smallexample
19912
19913Specifying @samp{-raw}, prohibits @value{GDBN} from wrapping the
19914provided @var{source-code} in a callable scope. In this case, you must
19915specify the entry point of the code by defining a function named
19916@code{_gdb_expr_}. The @samp{-raw} code cannot access variables of the
19917inferior. Using @samp{-raw} option may be needed for example when
19918@var{source-code} requires @samp{#include} lines which may conflict with
19919inferior symbols otherwise.
19920
19921@kindex compile file
19922@item compile file @var{filename}
19923@itemx compile file -raw @var{filename}
19924Like @code{compile code}, but take the source code from @var{filename}.
19925
19926@smallexample
19927compile file /home/user/example.c
19928@end smallexample
19929@end table
19930
36de76f9 19931@table @code
3345721a
PA
19932@item compile print [[@var{options}] --] @var{expr}
19933@itemx compile print [[@var{options}] --] /@var{f} @var{expr}
36de76f9
JK
19934Compile and execute @var{expr} with the compiler language found as the
19935current language in @value{GDBN} (@pxref{Languages}). By default the
19936value of @var{expr} is printed in a format appropriate to its data type;
19937you can choose a different format by specifying @samp{/@var{f}}, where
19938@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
3345721a
PA
19939Formats}. The @code{compile print} command accepts the same options
19940as the @code{print} command; see @ref{print options}.
36de76f9 19941
3345721a
PA
19942@item compile print [[@var{options}] --]
19943@itemx compile print [[@var{options}] --] /@var{f}
36de76f9
JK
19944@cindex reprint the last value
19945Alternatively you can enter the expression (source code producing it) as
19946multiple lines of text. To enter this mode, invoke the @samp{compile print}
19947command without any text following the command. This will start the
19948multiple-line editor.
19949@end table
19950
e7a8570f
JK
19951@noindent
19952The process of compiling and injecting the code can be inspected using:
19953
19954@table @code
19955@anchor{set debug compile}
19956@item set debug compile
19957@cindex compile command debugging info
19958Turns on or off display of @value{GDBN} process of compiling and
19959injecting the code. The default is off.
19960
19961@item show debug compile
19962Displays the current state of displaying @value{GDBN} process of
19963compiling and injecting the code.
078a0207
KS
19964
19965@anchor{set debug compile-cplus-types}
19966@item set debug compile-cplus-types
19967@cindex compile C@t{++} type conversion
19968Turns on or off the display of C@t{++} type conversion debugging information.
19969The default is off.
19970
19971@item show debug compile-cplus-types
19972Displays the current state of displaying debugging information for
19973C@t{++} type conversion.
e7a8570f
JK
19974@end table
19975
19976@subsection Compilation options for the @code{compile} command
19977
19978@value{GDBN} needs to specify the right compilation options for the code
19979to be injected, in part to make its ABI compatible with the inferior
19980and in part to make the injected code compatible with @value{GDBN}'s
19981injecting process.
19982
19983@noindent
19984The options used, in increasing precedence:
19985
19986@table @asis
19987@item target architecture and OS options (@code{gdbarch})
19988These options depend on target processor type and target operating
19989system, usually they specify at least 32-bit (@code{-m32}) or 64-bit
19990(@code{-m64}) compilation option.
19991
19992@item compilation options recorded in the target
19993@value{NGCC} (since version 4.7) stores the options used for compilation
19994into @code{DW_AT_producer} part of DWARF debugging information according
19995to the @value{NGCC} option @code{-grecord-gcc-switches}. One has to
19996explicitly specify @code{-g} during inferior compilation otherwise
19997@value{NGCC} produces no DWARF. This feature is only relevant for
19998platforms where @code{-g} produces DWARF by default, otherwise one may
19999try to enforce DWARF by using @code{-gdwarf-4}.
20000
20001@item compilation options set by @code{set compile-args}
20002@end table
20003
20004@noindent
20005You can override compilation options using the following command:
20006
20007@table @code
20008@item set compile-args
20009@cindex compile command options override
20010Set compilation options used for compiling and injecting code with the
20011@code{compile} commands. These options override any conflicting ones
20012from the target architecture and/or options stored during inferior
20013compilation.
20014
20015@item show compile-args
20016Displays the current state of compilation options override.
20017This does not show all the options actually used during compilation,
20018use @ref{set debug compile} for that.
20019@end table
20020
bb2ec1b3
TT
20021@subsection Caveats when using the @code{compile} command
20022
20023There are a few caveats to keep in mind when using the @code{compile}
20024command. As the caveats are different per language, the table below
20025highlights specific issues on a per language basis.
20026
20027@table @asis
20028@item C code examples and caveats
20029When the language in @value{GDBN} is set to @samp{C}, the compiler will
20030attempt to compile the source code with a @samp{C} compiler. The source
20031code provided to the @code{compile} command will have much the same
20032access to variables and types as it normally would if it were part of
20033the program currently being debugged in @value{GDBN}.
20034
20035Below is a sample program that forms the basis of the examples that
20036follow. This program has been compiled and loaded into @value{GDBN},
20037much like any other normal debugging session.
20038
20039@smallexample
20040void function1 (void)
20041@{
20042 int i = 42;
20043 printf ("function 1\n");
20044@}
20045
20046void function2 (void)
20047@{
20048 int j = 12;
20049 function1 ();
20050@}
20051
20052int main(void)
20053@{
20054 int k = 6;
20055 int *p;
20056 function2 ();
20057 return 0;
20058@}
20059@end smallexample
20060
20061For the purposes of the examples in this section, the program above has
20062been compiled, loaded into @value{GDBN}, stopped at the function
20063@code{main}, and @value{GDBN} is awaiting input from the user.
20064
20065To access variables and types for any program in @value{GDBN}, the
20066program must be compiled and packaged with debug information. The
20067@code{compile} command is not an exception to this rule. Without debug
20068information, you can still use the @code{compile} command, but you will
20069be very limited in what variables and types you can access.
20070
20071So with that in mind, the example above has been compiled with debug
20072information enabled. The @code{compile} command will have access to
20073all variables and types (except those that may have been optimized
20074out). Currently, as @value{GDBN} has stopped the program in the
20075@code{main} function, the @code{compile} command would have access to
20076the variable @code{k}. You could invoke the @code{compile} command
20077and type some source code to set the value of @code{k}. You can also
20078read it, or do anything with that variable you would normally do in
20079@code{C}. Be aware that changes to inferior variables in the
20080@code{compile} command are persistent. In the following example:
20081
20082@smallexample
20083compile code k = 3;
20084@end smallexample
20085
20086@noindent
20087the variable @code{k} is now 3. It will retain that value until
20088something else in the example program changes it, or another
20089@code{compile} command changes it.
20090
20091Normal scope and access rules apply to source code compiled and
20092injected by the @code{compile} command. In the example, the variables
20093@code{j} and @code{k} are not accessible yet, because the program is
20094currently stopped in the @code{main} function, where these variables
20095are not in scope. Therefore, the following command
20096
20097@smallexample
20098compile code j = 3;
20099@end smallexample
20100
20101@noindent
20102will result in a compilation error message.
20103
20104Once the program is continued, execution will bring these variables in
20105scope, and they will become accessible; then the code you specify via
20106the @code{compile} command will be able to access them.
20107
20108You can create variables and types with the @code{compile} command as
20109part of your source code. Variables and types that are created as part
20110of the @code{compile} command are not visible to the rest of the program for
20111the duration of its run. This example is valid:
20112
20113@smallexample
20114compile code int ff = 5; printf ("ff is %d\n", ff);
20115@end smallexample
20116
20117However, if you were to type the following into @value{GDBN} after that
20118command has completed:
20119
20120@smallexample
20121compile code printf ("ff is %d\n'', ff);
20122@end smallexample
20123
20124@noindent
20125a compiler error would be raised as the variable @code{ff} no longer
20126exists. Object code generated and injected by the @code{compile}
20127command is removed when its execution ends. Caution is advised
20128when assigning to program variables values of variables created by the
20129code submitted to the @code{compile} command. This example is valid:
20130
20131@smallexample
20132compile code int ff = 5; k = ff;
20133@end smallexample
20134
20135The value of the variable @code{ff} is assigned to @code{k}. The variable
20136@code{k} does not require the existence of @code{ff} to maintain the value
20137it has been assigned. However, pointers require particular care in
20138assignment. If the source code compiled with the @code{compile} command
20139changed the address of a pointer in the example program, perhaps to a
20140variable created in the @code{compile} command, that pointer would point
20141to an invalid location when the command exits. The following example
20142would likely cause issues with your debugged program:
20143
20144@smallexample
20145compile code int ff = 5; p = &ff;
20146@end smallexample
20147
20148In this example, @code{p} would point to @code{ff} when the
20149@code{compile} command is executing the source code provided to it.
20150However, as variables in the (example) program persist with their
20151assigned values, the variable @code{p} would point to an invalid
20152location when the command exists. A general rule should be followed
20153in that you should either assign @code{NULL} to any assigned pointers,
20154or restore a valid location to the pointer before the command exits.
20155
20156Similar caution must be exercised with any structs, unions, and typedefs
20157defined in @code{compile} command. Types defined in the @code{compile}
20158command will no longer be available in the next @code{compile} command.
20159Therefore, if you cast a variable to a type defined in the
20160@code{compile} command, care must be taken to ensure that any future
20161need to resolve the type can be achieved.
20162
20163@smallexample
20164(gdb) compile code static struct a @{ int a; @} v = @{ 42 @}; argv = &v;
20165(gdb) compile code printf ("%d\n", ((struct a *) argv)->a);
20166gdb command line:1:36: error: dereferencing pointer to incomplete type ‘struct a’
20167Compilation failed.
20168(gdb) compile code struct a @{ int a; @}; printf ("%d\n", ((struct a *) argv)->a);
2016942
20170@end smallexample
20171
20172Variables that have been optimized away by the compiler are not
20173accessible to the code submitted to the @code{compile} command.
20174Access to those variables will generate a compiler error which @value{GDBN}
20175will print to the console.
20176@end table
20177
e7a8570f
JK
20178@subsection Compiler search for the @code{compile} command
20179
6e41ddec
JK
20180@value{GDBN} needs to find @value{NGCC} for the inferior being debugged
20181which may not be obvious for remote targets of different architecture
20182than where @value{GDBN} is running. Environment variable @code{PATH} on
e7a8570f 20183@value{GDBN} host is searched for @value{NGCC} binary matching the
6e41ddec
JK
20184target architecture and operating system. This search can be overriden
20185by @code{set compile-gcc} @value{GDBN} command below. @code{PATH} is
20186taken from shell that executed @value{GDBN}, it is not the value set by
20187@value{GDBN} command @code{set environment}). @xref{Environment}.
20188
e7a8570f
JK
20189
20190Specifically @code{PATH} is searched for binaries matching regular expression
20191@code{@var{arch}(-[^-]*)?-@var{os}-gcc} according to the inferior target being
20192debugged. @var{arch} is processor name --- multiarch is supported, so for
20193example both @code{i386} and @code{x86_64} targets look for pattern
20194@code{(x86_64|i.86)} and both @code{s390} and @code{s390x} targets look
20195for pattern @code{s390x?}. @var{os} is currently supported only for
20196pattern @code{linux(-gnu)?}.
20197
6e41ddec
JK
20198On Posix hosts the compiler driver @value{GDBN} needs to find also
20199shared library @file{libcc1.so} from the compiler. It is searched in
20200default shared library search path (overridable with usual environment
20201variable @code{LD_LIBRARY_PATH}), unrelated to @code{PATH} or @code{set
20202compile-gcc} settings. Contrary to it @file{libcc1plugin.so} is found
20203according to the installation of the found compiler --- as possibly
20204specified by the @code{set compile-gcc} command.
20205
20206@table @code
20207@item set compile-gcc
20208@cindex compile command driver filename override
20209Set compilation command used for compiling and injecting code with the
20210@code{compile} commands. If this option is not set (it is set to
20211an empty string), the search described above will occur --- that is the
20212default.
20213
20214@item show compile-gcc
20215Displays the current compile command @value{NGCC} driver filename.
20216If set, it is the main command @command{gcc}, found usually for example
20217under name @file{x86_64-linux-gnu-gcc}.
20218@end table
20219
6d2ebf8b 20220@node GDB Files
c906108c
SS
20221@chapter @value{GDBN} Files
20222
7a292a7a
SS
20223@value{GDBN} needs to know the file name of the program to be debugged,
20224both in order to read its symbol table and in order to start your
20225program. To debug a core dump of a previous run, you must also tell
20226@value{GDBN} the name of the core dump file.
c906108c
SS
20227
20228@menu
20229* Files:: Commands to specify files
2b4bf6af 20230* File Caching:: Information about @value{GDBN}'s file caching
5b5d99cf 20231* Separate Debug Files:: Debugging information in separate files
608e2dbb 20232* MiniDebugInfo:: Debugging information in a special section
9291a0cd 20233* Index Files:: Index files speed up GDB
c906108c 20234* Symbol Errors:: Errors reading symbol files
b14b1491 20235* Data Files:: GDB data files
c906108c
SS
20236@end menu
20237
6d2ebf8b 20238@node Files
79a6e687 20239@section Commands to Specify Files
c906108c 20240
7a292a7a 20241@cindex symbol table
c906108c 20242@cindex core dump file
7a292a7a
SS
20243
20244You may want to specify executable and core dump file names. The usual
20245way to do this is at start-up time, using the arguments to
20246@value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
20247Out of @value{GDBN}}).
c906108c
SS
20248
20249Occasionally it is necessary to change to a different file during a
397ca115
EZ
20250@value{GDBN} session. Or you may run @value{GDBN} and forget to
20251specify a file you want to use. Or you are debugging a remote target
79a6e687
BW
20252via @code{gdbserver} (@pxref{Server, file, Using the @code{gdbserver}
20253Program}). In these situations the @value{GDBN} commands to specify
0869d01b 20254new files are useful.
c906108c
SS
20255
20256@table @code
20257@cindex executable file
20258@kindex file
20259@item file @var{filename}
20260Use @var{filename} as the program to be debugged. It is read for its
20261symbols and for the contents of pure memory. It is also the program
20262executed when you use the @code{run} command. If you do not specify a
5d161b24
DB
20263directory and the file is not found in the @value{GDBN} working directory,
20264@value{GDBN} uses the environment variable @code{PATH} as a list of
20265directories to search, just as the shell does when looking for a program
20266to run. You can change the value of this variable, for both @value{GDBN}
c906108c
SS
20267and your program, using the @code{path} command.
20268
fc8be69e
EZ
20269@cindex unlinked object files
20270@cindex patching object files
20271You can load unlinked object @file{.o} files into @value{GDBN} using
20272the @code{file} command. You will not be able to ``run'' an object
20273file, but you can disassemble functions and inspect variables. Also,
20274if the underlying BFD functionality supports it, you could use
20275@kbd{gdb -write} to patch object files using this technique. Note
20276that @value{GDBN} can neither interpret nor modify relocations in this
20277case, so branches and some initialized variables will appear to go to
20278the wrong place. But this feature is still handy from time to time.
20279
c906108c
SS
20280@item file
20281@code{file} with no argument makes @value{GDBN} discard any information it
20282has on both executable file and the symbol table.
20283
20284@kindex exec-file
20285@item exec-file @r{[} @var{filename} @r{]}
20286Specify that the program to be run (but not the symbol table) is found
20287in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
20288if necessary to locate your program. Omitting @var{filename} means to
20289discard information on the executable file.
20290
20291@kindex symbol-file
d4d429d5 20292@item symbol-file @r{[} @var{filename} @r{[} -o @var{offset} @r{]]}
c906108c
SS
20293Read symbol table information from file @var{filename}. @code{PATH} is
20294searched when necessary. Use the @code{file} command to get both symbol
20295table and program to run from the same file.
20296
d4d429d5
PT
20297If an optional @var{offset} is specified, it is added to the start
20298address of each section in the symbol file. This is useful if the
20299program is relocated at runtime, such as the Linux kernel with kASLR
20300enabled.
20301
c906108c
SS
20302@code{symbol-file} with no argument clears out @value{GDBN} information on your
20303program's symbol table.
20304
ae5a43e0
DJ
20305The @code{symbol-file} command causes @value{GDBN} to forget the contents of
20306some breakpoints and auto-display expressions. This is because they may
20307contain pointers to the internal data recording symbols and data types,
20308which are part of the old symbol table data being discarded inside
20309@value{GDBN}.
c906108c
SS
20310
20311@code{symbol-file} does not repeat if you press @key{RET} again after
20312executing it once.
20313
20314When @value{GDBN} is configured for a particular environment, it
20315understands debugging information in whatever format is the standard
20316generated for that environment; you may use either a @sc{gnu} compiler, or
20317other compilers that adhere to the local conventions.
c906108c 20318Best results are usually obtained from @sc{gnu} compilers; for example,
e22ea452 20319using @code{@value{NGCC}} you can generate debugging information for
c906108c 20320optimized code.
c906108c
SS
20321
20322For most kinds of object files, with the exception of old SVR3 systems
20323using COFF, the @code{symbol-file} command does not normally read the
20324symbol table in full right away. Instead, it scans the symbol table
20325quickly to find which source files and which symbols are present. The
20326details are read later, one source file at a time, as they are needed.
20327
20328The purpose of this two-stage reading strategy is to make @value{GDBN}
20329start up faster. For the most part, it is invisible except for
20330occasional pauses while the symbol table details for a particular source
20331file are being read. (The @code{set verbose} command can turn these
20332pauses into messages if desired. @xref{Messages/Warnings, ,Optional
79a6e687 20333Warnings and Messages}.)
c906108c 20334
c906108c
SS
20335We have not implemented the two-stage strategy for COFF yet. When the
20336symbol table is stored in COFF format, @code{symbol-file} reads the
20337symbol table data in full right away. Note that ``stabs-in-COFF''
20338still does the two-stage strategy, since the debug info is actually
20339in stabs format.
20340
20341@kindex readnow
20342@cindex reading symbols immediately
20343@cindex symbols, reading immediately
6ac33a4e
TT
20344@item symbol-file @r{[} -readnow @r{]} @var{filename}
20345@itemx file @r{[} -readnow @r{]} @var{filename}
c906108c
SS
20346You can override the @value{GDBN} two-stage strategy for reading symbol
20347tables by using the @samp{-readnow} option with any of the commands that
20348load symbol table information, if you want to be sure @value{GDBN} has the
5d161b24 20349entire symbol table available.
c906108c 20350
97cbe998
SDJ
20351@cindex @code{-readnever}, option for symbol-file command
20352@cindex never read symbols
20353@cindex symbols, never read
20354@item symbol-file @r{[} -readnever @r{]} @var{filename}
20355@itemx file @r{[} -readnever @r{]} @var{filename}
20356You can instruct @value{GDBN} to never read the symbolic information
20357contained in @var{filename} by using the @samp{-readnever} option.
20358@xref{--readnever}.
20359
c906108c
SS
20360@c FIXME: for now no mention of directories, since this seems to be in
20361@c flux. 13mar1992 status is that in theory GDB would look either in
20362@c current dir or in same dir as myprog; but issues like competing
20363@c GDB's, or clutter in system dirs, mean that in practice right now
20364@c only current dir is used. FFish says maybe a special GDB hierarchy
20365@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
20366@c files.
20367
c906108c 20368@kindex core-file
09d4efe1 20369@item core-file @r{[}@var{filename}@r{]}
4644b6e3 20370@itemx core
c906108c
SS
20371Specify the whereabouts of a core dump file to be used as the ``contents
20372of memory''. Traditionally, core files contain only some parts of the
20373address space of the process that generated them; @value{GDBN} can access the
20374executable file itself for other parts.
20375
20376@code{core-file} with no argument specifies that no core file is
20377to be used.
20378
20379Note that the core file is ignored when your program is actually running
7a292a7a
SS
20380under @value{GDBN}. So, if you have been running your program and you
20381wish to debug a core file instead, you must kill the subprocess in which
20382the program is running. To do this, use the @code{kill} command
79a6e687 20383(@pxref{Kill Process, ,Killing the Child Process}).
c906108c 20384
c906108c
SS
20385@kindex add-symbol-file
20386@cindex dynamic linking
291f9a96 20387@item add-symbol-file @var{filename} @r{[} -readnow @r{|} -readnever @r{]} @r{[} -o @var{offset} @r{]} @r{[} @var{textaddress} @r{]} @r{[} -s @var{section} @var{address} @dots{} @r{]}
96a2c332
SS
20388The @code{add-symbol-file} command reads additional symbol table
20389information from the file @var{filename}. You would use this command
20390when @var{filename} has been dynamically loaded (by some other means)
ed6dfe51
PT
20391into the program that is running. The @var{textaddress} parameter gives
20392the memory address at which the file's text section has been loaded.
20393You can additionally specify the base address of other sections using
20394an arbitrary number of @samp{-s @var{section} @var{address}} pairs.
20395If a section is omitted, @value{GDBN} will use its default addresses
20396as found in @var{filename}. Any @var{address} or @var{textaddress}
20397can be given as an expression.
c906108c 20398
291f9a96
PT
20399If an optional @var{offset} is specified, it is added to the start
20400address of each section, except those for which the address was
20401specified explicitly.
20402
c906108c
SS
20403The symbol table of the file @var{filename} is added to the symbol table
20404originally read with the @code{symbol-file} command. You can use the
96a2c332 20405@code{add-symbol-file} command any number of times; the new symbol data
98297bf6
NB
20406thus read is kept in addition to the old.
20407
20408Changes can be reverted using the command @code{remove-symbol-file}.
c906108c 20409
17d9d558
JB
20410@cindex relocatable object files, reading symbols from
20411@cindex object files, relocatable, reading symbols from
20412@cindex reading symbols from relocatable object files
20413@cindex symbols, reading from relocatable object files
20414@cindex @file{.o} files, reading symbols from
20415Although @var{filename} is typically a shared library file, an
20416executable file, or some other object file which has been fully
20417relocated for loading into a process, you can also load symbolic
20418information from relocatable @file{.o} files, as long as:
20419
20420@itemize @bullet
20421@item
20422the file's symbolic information refers only to linker symbols defined in
20423that file, not to symbols defined by other object files,
20424@item
20425every section the file's symbolic information refers to has actually
20426been loaded into the inferior, as it appears in the file, and
20427@item
20428you can determine the address at which every section was loaded, and
20429provide these to the @code{add-symbol-file} command.
20430@end itemize
20431
20432@noindent
20433Some embedded operating systems, like Sun Chorus and VxWorks, can load
20434relocatable files into an already running program; such systems
20435typically make the requirements above easy to meet. However, it's
20436important to recognize that many native systems use complex link
49efadf5 20437procedures (@code{.linkonce} section factoring and C@t{++} constructor table
17d9d558
JB
20438assembly, for example) that make the requirements difficult to meet. In
20439general, one cannot assume that using @code{add-symbol-file} to read a
20440relocatable object file's symbolic information will have the same effect
20441as linking the relocatable object file into the program in the normal
20442way.
20443
c906108c
SS
20444@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
20445
98297bf6
NB
20446@kindex remove-symbol-file
20447@item remove-symbol-file @var{filename}
20448@item remove-symbol-file -a @var{address}
20449Remove a symbol file added via the @code{add-symbol-file} command. The
20450file to remove can be identified by its @var{filename} or by an @var{address}
20451that lies within the boundaries of this symbol file in memory. Example:
20452
20453@smallexample
20454(gdb) add-symbol-file /home/user/gdb/mylib.so 0x7ffff7ff9480
20455add symbol table from file "/home/user/gdb/mylib.so" at
20456 .text_addr = 0x7ffff7ff9480
20457(y or n) y
0bab6cf1 20458Reading symbols from /home/user/gdb/mylib.so...
98297bf6
NB
20459(gdb) remove-symbol-file -a 0x7ffff7ff9480
20460Remove symbol table from file "/home/user/gdb/mylib.so"? (y or n) y
20461(gdb)
20462@end smallexample
20463
20464
20465@code{remove-symbol-file} does not repeat if you press @key{RET} after using it.
20466
c45da7e6
EZ
20467@kindex add-symbol-file-from-memory
20468@cindex @code{syscall DSO}
20469@cindex load symbols from memory
20470@item add-symbol-file-from-memory @var{address}
20471Load symbols from the given @var{address} in a dynamically loaded
20472object file whose image is mapped directly into the inferior's memory.
20473For example, the Linux kernel maps a @code{syscall DSO} into each
20474process's address space; this DSO provides kernel-specific code for
20475some system calls. The argument can be any expression whose
20476evaluation yields the address of the file's shared object file header.
20477For this command to work, you must have used @code{symbol-file} or
20478@code{exec-file} commands in advance.
20479
c906108c 20480@kindex section
09d4efe1
EZ
20481@item section @var{section} @var{addr}
20482The @code{section} command changes the base address of the named
20483@var{section} of the exec file to @var{addr}. This can be used if the
20484exec file does not contain section addresses, (such as in the
20485@code{a.out} format), or when the addresses specified in the file
20486itself are wrong. Each section must be changed separately. The
20487@code{info files} command, described below, lists all the sections and
20488their addresses.
c906108c
SS
20489
20490@kindex info files
20491@kindex info target
20492@item info files
20493@itemx info target
7a292a7a
SS
20494@code{info files} and @code{info target} are synonymous; both print the
20495current target (@pxref{Targets, ,Specifying a Debugging Target}),
20496including the names of the executable and core dump files currently in
20497use by @value{GDBN}, and the files from which symbols were loaded. The
20498command @code{help target} lists all possible targets rather than
20499current ones.
20500
fe95c787
MS
20501@kindex maint info sections
20502@item maint info sections
20503Another command that can give you extra information about program sections
20504is @code{maint info sections}. In addition to the section information
20505displayed by @code{info files}, this command displays the flags and file
20506offset of each section in the executable and core dump files. In addition,
20507@code{maint info sections} provides the following command options (which
20508may be arbitrarily combined):
20509
20510@table @code
20511@item ALLOBJ
20512Display sections for all loaded object files, including shared libraries.
20513@item @var{sections}
6600abed 20514Display info only for named @var{sections}.
fe95c787
MS
20515@item @var{section-flags}
20516Display info only for sections for which @var{section-flags} are true.
20517The section flags that @value{GDBN} currently knows about are:
20518@table @code
20519@item ALLOC
20520Section will have space allocated in the process when loaded.
20521Set for all sections except those containing debug information.
20522@item LOAD
20523Section will be loaded from the file into the child process memory.
20524Set for pre-initialized code and data, clear for @code{.bss} sections.
20525@item RELOC
20526Section needs to be relocated before loading.
20527@item READONLY
20528Section cannot be modified by the child process.
20529@item CODE
20530Section contains executable code only.
6600abed 20531@item DATA
fe95c787
MS
20532Section contains data only (no executable code).
20533@item ROM
20534Section will reside in ROM.
20535@item CONSTRUCTOR
20536Section contains data for constructor/destructor lists.
20537@item HAS_CONTENTS
20538Section is not empty.
20539@item NEVER_LOAD
20540An instruction to the linker to not output the section.
20541@item COFF_SHARED_LIBRARY
20542A notification to the linker that the section contains
20543COFF shared library information.
20544@item IS_COMMON
20545Section contains common symbols.
20546@end table
20547@end table
6763aef9 20548@kindex set trust-readonly-sections
9c16f35a 20549@cindex read-only sections
6763aef9
MS
20550@item set trust-readonly-sections on
20551Tell @value{GDBN} that readonly sections in your object file
6ca652b0 20552really are read-only (i.e.@: that their contents will not change).
6763aef9
MS
20553In that case, @value{GDBN} can fetch values from these sections
20554out of the object file, rather than from the target program.
20555For some targets (notably embedded ones), this can be a significant
20556enhancement to debugging performance.
20557
20558The default is off.
20559
20560@item set trust-readonly-sections off
15110bc3 20561Tell @value{GDBN} not to trust readonly sections. This means that
6763aef9
MS
20562the contents of the section might change while the program is running,
20563and must therefore be fetched from the target when needed.
9c16f35a
EZ
20564
20565@item show trust-readonly-sections
20566Show the current setting of trusting readonly sections.
c906108c
SS
20567@end table
20568
20569All file-specifying commands allow both absolute and relative file names
20570as arguments. @value{GDBN} always converts the file name to an absolute file
20571name and remembers it that way.
20572
c906108c 20573@cindex shared libraries
9cceb671 20574@anchor{Shared Libraries}
b1236ac3
PA
20575@value{GDBN} supports @sc{gnu}/Linux, MS-Windows, SunOS,
20576Darwin/Mach-O, SVr4, IBM RS/6000 AIX, QNX Neutrino, FDPIC (FR-V), and
20577DSBT (TIC6X) shared libraries.
53a5351d 20578
9cceb671
DJ
20579On MS-Windows @value{GDBN} must be linked with the Expat library to support
20580shared libraries. @xref{Expat}.
20581
c906108c
SS
20582@value{GDBN} automatically loads symbol definitions from shared libraries
20583when you use the @code{run} command, or when you examine a core file.
20584(Before you issue the @code{run} command, @value{GDBN} does not understand
20585references to a function in a shared library, however---unless you are
20586debugging a core file).
53a5351d 20587
c906108c
SS
20588@c FIXME: some @value{GDBN} release may permit some refs to undef
20589@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
20590@c FIXME...lib; check this from time to time when updating manual
20591
b7209cb4
FF
20592There are times, however, when you may wish to not automatically load
20593symbol definitions from shared libraries, such as when they are
20594particularly large or there are many of them.
20595
20596To control the automatic loading of shared library symbols, use the
20597commands:
20598
20599@table @code
20600@kindex set auto-solib-add
20601@item set auto-solib-add @var{mode}
20602If @var{mode} is @code{on}, symbols from all shared object libraries
20603will be loaded automatically when the inferior begins execution, you
20604attach to an independently started inferior, or when the dynamic linker
20605informs @value{GDBN} that a new library has been loaded. If @var{mode}
20606is @code{off}, symbols must be loaded manually, using the
20607@code{sharedlibrary} command. The default value is @code{on}.
20608
dcaf7c2c
EZ
20609@cindex memory used for symbol tables
20610If your program uses lots of shared libraries with debug info that
20611takes large amounts of memory, you can decrease the @value{GDBN}
20612memory footprint by preventing it from automatically loading the
20613symbols from shared libraries. To that end, type @kbd{set
20614auto-solib-add off} before running the inferior, then load each
20615library whose debug symbols you do need with @kbd{sharedlibrary
d3e8051b 20616@var{regexp}}, where @var{regexp} is a regular expression that matches
dcaf7c2c
EZ
20617the libraries whose symbols you want to be loaded.
20618
b7209cb4
FF
20619@kindex show auto-solib-add
20620@item show auto-solib-add
20621Display the current autoloading mode.
20622@end table
20623
c45da7e6 20624@cindex load shared library
b7209cb4
FF
20625To explicitly load shared library symbols, use the @code{sharedlibrary}
20626command:
20627
c906108c
SS
20628@table @code
20629@kindex info sharedlibrary
20630@kindex info share
55333a84
DE
20631@item info share @var{regex}
20632@itemx info sharedlibrary @var{regex}
20633Print the names of the shared libraries which are currently loaded
20634that match @var{regex}. If @var{regex} is omitted then print
20635all shared libraries that are loaded.
c906108c 20636
b30a0bc3
JB
20637@kindex info dll
20638@item info dll @var{regex}
20639This is an alias of @code{info sharedlibrary}.
20640
c906108c
SS
20641@kindex sharedlibrary
20642@kindex share
20643@item sharedlibrary @var{regex}
20644@itemx share @var{regex}
c906108c
SS
20645Load shared object library symbols for files matching a
20646Unix regular expression.
20647As with files loaded automatically, it only loads shared libraries
20648required by your program for a core file or after typing @code{run}. If
20649@var{regex} is omitted all shared libraries required by your program are
20650loaded.
c45da7e6
EZ
20651
20652@item nosharedlibrary
20653@kindex nosharedlibrary
20654@cindex unload symbols from shared libraries
20655Unload all shared object library symbols. This discards all symbols
20656that have been loaded from all shared libraries. Symbols from shared
20657libraries that were loaded by explicit user requests are not
20658discarded.
c906108c
SS
20659@end table
20660
721c2651 20661Sometimes you may wish that @value{GDBN} stops and gives you control
edcc5120
TT
20662when any of shared library events happen. The best way to do this is
20663to use @code{catch load} and @code{catch unload} (@pxref{Set
20664Catchpoints}).
20665
09f2921c 20666@value{GDBN} also supports the @code{set stop-on-solib-events}
edcc5120
TT
20667command for this. This command exists for historical reasons. It is
20668less useful than setting a catchpoint, because it does not allow for
20669conditions or commands as a catchpoint does.
721c2651
EZ
20670
20671@table @code
20672@item set stop-on-solib-events
20673@kindex set stop-on-solib-events
20674This command controls whether @value{GDBN} should give you control
20675when the dynamic linker notifies it about some shared library event.
20676The most common event of interest is loading or unloading of a new
20677shared library.
20678
20679@item show stop-on-solib-events
20680@kindex show stop-on-solib-events
20681Show whether @value{GDBN} stops and gives you control when shared
20682library events happen.
20683@end table
20684
f5ebfba0 20685Shared libraries are also supported in many cross or remote debugging
f1838a98
UW
20686configurations. @value{GDBN} needs to have access to the target's libraries;
20687this can be accomplished either by providing copies of the libraries
20688on the host system, or by asking @value{GDBN} to automatically retrieve the
20689libraries from the target. If copies of the target libraries are
20690provided, they need to be the same as the target libraries, although the
f5ebfba0
DJ
20691copies on the target can be stripped as long as the copies on the host are
20692not.
20693
59b7b46f
EZ
20694@cindex where to look for shared libraries
20695For remote debugging, you need to tell @value{GDBN} where the target
20696libraries are, so that it can load the correct copies---otherwise, it
20697may try to load the host's libraries. @value{GDBN} has two variables
20698to specify the search directories for target libraries.
f5ebfba0
DJ
20699
20700@table @code
a9a5a3d1 20701@cindex prefix for executable and shared library file names
f822c95b 20702@cindex system root, alternate
f5ebfba0 20703@kindex set solib-absolute-prefix
f822c95b
DJ
20704@kindex set sysroot
20705@item set sysroot @var{path}
20706Use @var{path} as the system root for the program being debugged. Any
20707absolute shared library paths will be prefixed with @var{path}; many
20708runtime loaders store the absolute paths to the shared library in the
a9a5a3d1
GB
20709target program's memory. When starting processes remotely, and when
20710attaching to already-running processes (local or remote), their
20711executable filenames will be prefixed with @var{path} if reported to
20712@value{GDBN} as absolute by the operating system. If you use
20713@code{set sysroot} to find executables and shared libraries, they need
20714to be laid out in the same way that they are on the target, with
20715e.g.@: a @file{/bin}, @file{/lib} and @file{/usr/lib} hierarchy under
20716@var{path}.
f822c95b 20717
599bd15c
GB
20718If @var{path} starts with the sequence @file{target:} and the target
20719system is remote then @value{GDBN} will retrieve the target binaries
20720from the remote system. This is only supported when using a remote
20721target that supports the @code{remote get} command (@pxref{File
20722Transfer,,Sending files to a remote system}). The part of @var{path}
20723following the initial @file{target:} (if present) is used as system
20724root prefix on the remote file system. If @var{path} starts with the
20725sequence @file{remote:} this is converted to the sequence
20726@file{target:} by @code{set sysroot}@footnote{Historically the
20727functionality to retrieve binaries from the remote system was
20728provided by prefixing @var{path} with @file{remote:}}. If you want
20729to specify a local system root using a directory that happens to be
20730named @file{target:} or @file{remote:}, you need to use some
20731equivalent variant of the name like @file{./target:}.
f1838a98 20732
ab38a727
PA
20733For targets with an MS-DOS based filesystem, such as MS-Windows and
20734SymbianOS, @value{GDBN} tries prefixing a few variants of the target
20735absolute file name with @var{path}. But first, on Unix hosts,
20736@value{GDBN} converts all backslash directory separators into forward
20737slashes, because the backslash is not a directory separator on Unix:
20738
20739@smallexample
20740 c:\foo\bar.dll @result{} c:/foo/bar.dll
20741@end smallexample
20742
20743Then, @value{GDBN} attempts prefixing the target file name with
20744@var{path}, and looks for the resulting file name in the host file
20745system:
20746
20747@smallexample
20748 c:/foo/bar.dll @result{} /path/to/sysroot/c:/foo/bar.dll
20749@end smallexample
20750
a9a5a3d1 20751If that does not find the binary, @value{GDBN} tries removing
ab38a727
PA
20752the @samp{:} character from the drive spec, both for convenience, and,
20753for the case of the host file system not supporting file names with
20754colons:
20755
20756@smallexample
20757 c:/foo/bar.dll @result{} /path/to/sysroot/c/foo/bar.dll
20758@end smallexample
20759
20760This makes it possible to have a system root that mirrors a target
20761with more than one drive. E.g., you may want to setup your local
20762copies of the target system shared libraries like so (note @samp{c} vs
20763@samp{z}):
20764
20765@smallexample
20766 @file{/path/to/sysroot/c/sys/bin/foo.dll}
20767 @file{/path/to/sysroot/c/sys/bin/bar.dll}
20768 @file{/path/to/sysroot/z/sys/bin/bar.dll}
20769@end smallexample
20770
20771@noindent
20772and point the system root at @file{/path/to/sysroot}, so that
20773@value{GDBN} can find the correct copies of both
20774@file{c:\sys\bin\foo.dll}, and @file{z:\sys\bin\bar.dll}.
20775
a9a5a3d1 20776If that still does not find the binary, @value{GDBN} tries
ab38a727
PA
20777removing the whole drive spec from the target file name:
20778
20779@smallexample
20780 c:/foo/bar.dll @result{} /path/to/sysroot/foo/bar.dll
20781@end smallexample
20782
20783This last lookup makes it possible to not care about the drive name,
20784if you don't want or need to.
20785
f822c95b
DJ
20786The @code{set solib-absolute-prefix} command is an alias for @code{set
20787sysroot}.
20788
20789@cindex default system root
59b7b46f 20790@cindex @samp{--with-sysroot}
f822c95b
DJ
20791You can set the default system root by using the configure-time
20792@samp{--with-sysroot} option. If the system root is inside
20793@value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
20794@samp{--exec-prefix}), then the default system root will be updated
20795automatically if the installed @value{GDBN} is moved to a new
20796location.
20797
20798@kindex show sysroot
20799@item show sysroot
a9a5a3d1 20800Display the current executable and shared library prefix.
f5ebfba0
DJ
20801
20802@kindex set solib-search-path
20803@item set solib-search-path @var{path}
f822c95b
DJ
20804If this variable is set, @var{path} is a colon-separated list of
20805directories to search for shared libraries. @samp{solib-search-path}
20806is used after @samp{sysroot} fails to locate the library, or if the
20807path to the library is relative instead of absolute. If you want to
20808use @samp{solib-search-path} instead of @samp{sysroot}, be sure to set
d3e8051b 20809@samp{sysroot} to a nonexistent directory to prevent @value{GDBN} from
f822c95b 20810finding your host's libraries. @samp{sysroot} is preferred; setting
d3e8051b 20811it to a nonexistent directory may interfere with automatic loading
f822c95b 20812of shared library symbols.
f5ebfba0
DJ
20813
20814@kindex show solib-search-path
20815@item show solib-search-path
20816Display the current shared library search path.
ab38a727
PA
20817
20818@cindex DOS file-name semantics of file names.
20819@kindex set target-file-system-kind (unix|dos-based|auto)
20820@kindex show target-file-system-kind
20821@item set target-file-system-kind @var{kind}
20822Set assumed file system kind for target reported file names.
20823
20824Shared library file names as reported by the target system may not
20825make sense as is on the system @value{GDBN} is running on. For
20826example, when remote debugging a target that has MS-DOS based file
20827system semantics, from a Unix host, the target may be reporting to
20828@value{GDBN} a list of loaded shared libraries with file names such as
20829@file{c:\Windows\kernel32.dll}. On Unix hosts, there's no concept of
20830drive letters, so the @samp{c:\} prefix is not normally understood as
20831indicating an absolute file name, and neither is the backslash
20832normally considered a directory separator character. In that case,
20833the native file system would interpret this whole absolute file name
20834as a relative file name with no directory components. This would make
20835it impossible to point @value{GDBN} at a copy of the remote target's
20836shared libraries on the host using @code{set sysroot}, and impractical
20837with @code{set solib-search-path}. Setting
20838@code{target-file-system-kind} to @code{dos-based} tells @value{GDBN}
20839to interpret such file names similarly to how the target would, and to
20840map them to file names valid on @value{GDBN}'s native file system
20841semantics. The value of @var{kind} can be @code{"auto"}, in addition
20842to one of the supported file system kinds. In that case, @value{GDBN}
20843tries to determine the appropriate file system variant based on the
20844current target's operating system (@pxref{ABI, ,Configuring the
20845Current ABI}). The supported file system settings are:
20846
20847@table @code
20848@item unix
20849Instruct @value{GDBN} to assume the target file system is of Unix
20850kind. Only file names starting the forward slash (@samp{/}) character
20851are considered absolute, and the directory separator character is also
20852the forward slash.
20853
20854@item dos-based
20855Instruct @value{GDBN} to assume the target file system is DOS based.
20856File names starting with either a forward slash, or a drive letter
20857followed by a colon (e.g., @samp{c:}), are considered absolute, and
20858both the slash (@samp{/}) and the backslash (@samp{\\}) characters are
20859considered directory separators.
20860
20861@item auto
20862Instruct @value{GDBN} to use the file system kind associated with the
20863target operating system (@pxref{ABI, ,Configuring the Current ABI}).
20864This is the default.
20865@end table
f5ebfba0
DJ
20866@end table
20867
c011a4f4
DE
20868@cindex file name canonicalization
20869@cindex base name differences
20870When processing file names provided by the user, @value{GDBN}
20871frequently needs to compare them to the file names recorded in the
20872program's debug info. Normally, @value{GDBN} compares just the
20873@dfn{base names} of the files as strings, which is reasonably fast
20874even for very large programs. (The base name of a file is the last
20875portion of its name, after stripping all the leading directories.)
20876This shortcut in comparison is based upon the assumption that files
20877cannot have more than one base name. This is usually true, but
20878references to files that use symlinks or similar filesystem
20879facilities violate that assumption. If your program records files
20880using such facilities, or if you provide file names to @value{GDBN}
20881using symlinks etc., you can set @code{basenames-may-differ} to
20882@code{true} to instruct @value{GDBN} to completely canonicalize each
20883pair of file names it needs to compare. This will make file-name
20884comparisons accurate, but at a price of a significant slowdown.
20885
20886@table @code
20887@item set basenames-may-differ
20888@kindex set basenames-may-differ
20889Set whether a source file may have multiple base names.
20890
20891@item show basenames-may-differ
20892@kindex show basenames-may-differ
20893Show whether a source file may have multiple base names.
20894@end table
5b5d99cf 20895
18989b3c
AB
20896@node File Caching
20897@section File Caching
20898@cindex caching of opened files
20899@cindex caching of bfd objects
20900
20901To speed up file loading, and reduce memory usage, @value{GDBN} will
20902reuse the @code{bfd} objects used to track open files. @xref{Top, ,
20903BFD, bfd, The Binary File Descriptor Library}. The following commands
20904allow visibility and control of the caching behavior.
20905
20906@table @code
20907@kindex maint info bfds
20908@item maint info bfds
20909This prints information about each @code{bfd} object that is known to
20910@value{GDBN}.
20911
20912@kindex maint set bfd-sharing
20913@kindex maint show bfd-sharing
20914@kindex bfd caching
20915@item maint set bfd-sharing
20916@item maint show bfd-sharing
20917Control whether @code{bfd} objects can be shared. When sharing is
20918enabled @value{GDBN} reuses already open @code{bfd} objects rather
20919than reopening the same file. Turning sharing off does not cause
20920already shared @code{bfd} objects to be unshared, but all future files
20921that are opened will create a new @code{bfd} object. Similarly,
20922re-enabling sharing does not cause multiple existing @code{bfd}
20923objects to be collapsed into a single shared @code{bfd} object.
566f5e3b
AB
20924
20925@kindex set debug bfd-cache @var{level}
20926@kindex bfd caching
20927@item set debug bfd-cache @var{level}
20928Turns on debugging of the bfd cache, setting the level to @var{level}.
20929
20930@kindex show debug bfd-cache
20931@kindex bfd caching
20932@item show debug bfd-cache
20933Show the current debugging level of the bfd cache.
18989b3c
AB
20934@end table
20935
5b5d99cf
JB
20936@node Separate Debug Files
20937@section Debugging Information in Separate Files
20938@cindex separate debugging information files
20939@cindex debugging information in separate files
20940@cindex @file{.debug} subdirectories
20941@cindex debugging information directory, global
f307c045 20942@cindex global debugging information directories
c7e83d54
EZ
20943@cindex build ID, and separate debugging files
20944@cindex @file{.build-id} directory
5b5d99cf
JB
20945
20946@value{GDBN} allows you to put a program's debugging information in a
20947file separate from the executable itself, in a way that allows
20948@value{GDBN} to find and load the debugging information automatically.
c7e83d54
EZ
20949Since debugging information can be very large---sometimes larger
20950than the executable code itself---some systems distribute debugging
5b5d99cf
JB
20951information for their executables in separate files, which users can
20952install only when they need to debug a problem.
20953
c7e83d54
EZ
20954@value{GDBN} supports two ways of specifying the separate debug info
20955file:
5b5d99cf
JB
20956
20957@itemize @bullet
20958@item
c7e83d54
EZ
20959The executable contains a @dfn{debug link} that specifies the name of
20960the separate debug info file. The separate debug file's name is
20961usually @file{@var{executable}.debug}, where @var{executable} is the
20962name of the corresponding executable file without leading directories
20963(e.g., @file{ls.debug} for @file{/usr/bin/ls}). In addition, the
99e008fe
EZ
20964debug link specifies a 32-bit @dfn{Cyclic Redundancy Check} (CRC)
20965checksum for the debug file, which @value{GDBN} uses to validate that
20966the executable and the debug file came from the same build.
c7e83d54
EZ
20967
20968@item
98c59b52 20969@anchor{build ID}
7e27a47a 20970The executable contains a @dfn{build ID}, a unique bit string that is
c7e83d54 20971also present in the corresponding debug info file. (This is supported
c74f7d1c 20972only on some operating systems, when using the ELF or PE file formats
7e27a47a
EZ
20973for binary files and the @sc{gnu} Binutils.) For more details about
20974this feature, see the description of the @option{--build-id}
f5a476a7 20975command-line option in @ref{Options, , Command Line Options, ld,
7e27a47a
EZ
20976The GNU Linker}. The debug info file's name is not specified
20977explicitly by the build ID, but can be computed from the build ID, see
20978below.
d3750b24
JK
20979@end itemize
20980
c7e83d54
EZ
20981Depending on the way the debug info file is specified, @value{GDBN}
20982uses two different methods of looking for the debug file:
d3750b24
JK
20983
20984@itemize @bullet
20985@item
c7e83d54
EZ
20986For the ``debug link'' method, @value{GDBN} looks up the named file in
20987the directory of the executable file, then in a subdirectory of that
5f2459c2
EZ
20988directory named @file{.debug}, and finally under each one of the
20989global debug directories, in a subdirectory whose name is identical to
20990the leading directories of the executable's absolute file name. (On
20991MS-Windows/MS-DOS, the drive letter of the executable's leading
20992directories is converted to a one-letter subdirectory, i.e.@:
20993@file{d:/usr/bin/} is converted to @file{/d/usr/bin/}, because Windows
20994filesystems disallow colons in file names.)
c7e83d54
EZ
20995
20996@item
83f83d7f 20997For the ``build ID'' method, @value{GDBN} looks in the
f307c045
JK
20998@file{.build-id} subdirectory of each one of the global debug directories for
20999a file named @file{@var{nn}/@var{nnnnnnnn}.debug}, where @var{nn} are the
7e27a47a
EZ
21000first 2 hex characters of the build ID bit string, and @var{nnnnnnnn}
21001are the rest of the bit string. (Real build ID strings are 32 or more
21002hex characters, not 10.)
c7e83d54
EZ
21003@end itemize
21004
21005So, for example, suppose you ask @value{GDBN} to debug
7e27a47a
EZ
21006@file{/usr/bin/ls}, which has a debug link that specifies the
21007file @file{ls.debug}, and a build ID whose value in hex is
f307c045 21008@code{abcdef1234}. If the list of the global debug directories includes
c7e83d54
EZ
21009@file{/usr/lib/debug}, then @value{GDBN} will look for the following
21010debug information files, in the indicated order:
21011
21012@itemize @minus
21013@item
21014@file{/usr/lib/debug/.build-id/ab/cdef1234.debug}
d3750b24 21015@item
c7e83d54 21016@file{/usr/bin/ls.debug}
5b5d99cf 21017@item
c7e83d54 21018@file{/usr/bin/.debug/ls.debug}
5b5d99cf 21019@item
c7e83d54 21020@file{/usr/lib/debug/usr/bin/ls.debug}.
5b5d99cf 21021@end itemize
5b5d99cf 21022
1564a261
JK
21023@anchor{debug-file-directory}
21024Global debugging info directories default to what is set by @value{GDBN}
21025configure option @option{--with-separate-debug-dir}. During @value{GDBN} run
21026you can also set the global debugging info directories, and view the list
21027@value{GDBN} is currently using.
5b5d99cf
JB
21028
21029@table @code
21030
21031@kindex set debug-file-directory
24ddea62
JK
21032@item set debug-file-directory @var{directories}
21033Set the directories which @value{GDBN} searches for separate debugging
d9242c17
JK
21034information files to @var{directory}. Multiple path components can be set
21035concatenating them by a path separator.
5b5d99cf
JB
21036
21037@kindex show debug-file-directory
21038@item show debug-file-directory
24ddea62 21039Show the directories @value{GDBN} searches for separate debugging
5b5d99cf
JB
21040information files.
21041
21042@end table
21043
21044@cindex @code{.gnu_debuglink} sections
c7e83d54 21045@cindex debug link sections
5b5d99cf
JB
21046A debug link is a special section of the executable file named
21047@code{.gnu_debuglink}. The section must contain:
21048
21049@itemize
21050@item
21051A filename, with any leading directory components removed, followed by
21052a zero byte,
21053@item
21054zero to three bytes of padding, as needed to reach the next four-byte
21055boundary within the section, and
21056@item
21057a four-byte CRC checksum, stored in the same endianness used for the
21058executable file itself. The checksum is computed on the debugging
21059information file's full contents by the function given below, passing
21060zero as the @var{crc} argument.
21061@end itemize
21062
21063Any executable file format can carry a debug link, as long as it can
21064contain a section named @code{.gnu_debuglink} with the contents
21065described above.
21066
d3750b24 21067@cindex @code{.note.gnu.build-id} sections
c7e83d54 21068@cindex build ID sections
7e27a47a
EZ
21069The build ID is a special section in the executable file (and in other
21070ELF binary files that @value{GDBN} may consider). This section is
21071often named @code{.note.gnu.build-id}, but that name is not mandatory.
21072It contains unique identification for the built files---the ID remains
21073the same across multiple builds of the same build tree. The default
21074algorithm SHA1 produces 160 bits (40 hexadecimal characters) of the
21075content for the build ID string. The same section with an identical
21076value is present in the original built binary with symbols, in its
21077stripped variant, and in the separate debugging information file.
d3750b24 21078
5b5d99cf
JB
21079The debugging information file itself should be an ordinary
21080executable, containing a full set of linker symbols, sections, and
21081debugging information. The sections of the debugging information file
c7e83d54
EZ
21082should have the same names, addresses, and sizes as the original file,
21083but they need not contain any data---much like a @code{.bss} section
5b5d99cf
JB
21084in an ordinary executable.
21085
7e27a47a 21086The @sc{gnu} binary utilities (Binutils) package includes the
c7e83d54
EZ
21087@samp{objcopy} utility that can produce
21088the separated executable / debugging information file pairs using the
21089following commands:
21090
21091@smallexample
21092@kbd{objcopy --only-keep-debug foo foo.debug}
21093@kbd{strip -g foo}
c7e83d54
EZ
21094@end smallexample
21095
21096@noindent
21097These commands remove the debugging
83f83d7f
JK
21098information from the executable file @file{foo} and place it in the file
21099@file{foo.debug}. You can use the first, second or both methods to link the
21100two files:
21101
21102@itemize @bullet
21103@item
21104The debug link method needs the following additional command to also leave
21105behind a debug link in @file{foo}:
21106
21107@smallexample
21108@kbd{objcopy --add-gnu-debuglink=foo.debug foo}
21109@end smallexample
21110
21111Ulrich Drepper's @file{elfutils} package, starting with version 0.53, contains
d3750b24 21112a version of the @code{strip} command such that the command @kbd{strip foo -f
83f83d7f
JK
21113foo.debug} has the same functionality as the two @code{objcopy} commands and
21114the @code{ln -s} command above, together.
21115
21116@item
21117Build ID gets embedded into the main executable using @code{ld --build-id} or
21118the @value{NGCC} counterpart @code{gcc -Wl,--build-id}. Build ID support plus
21119compatibility fixes for debug files separation are present in @sc{gnu} binary
7e27a47a 21120utilities (Binutils) package since version 2.18.
83f83d7f
JK
21121@end itemize
21122
21123@noindent
d3750b24 21124
99e008fe
EZ
21125@cindex CRC algorithm definition
21126The CRC used in @code{.gnu_debuglink} is the CRC-32 defined in
21127IEEE 802.3 using the polynomial:
21128
21129@c TexInfo requires naked braces for multi-digit exponents for Tex
21130@c output, but this causes HTML output to barf. HTML has to be set using
21131@c raw commands. So we end up having to specify this equation in 2
21132@c different ways!
21133@ifhtml
21134@display
21135@html
21136 <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>
21137 + <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
21138@end html
21139@end display
21140@end ifhtml
21141@ifnothtml
21142@display
21143 @math{x^{32} + x^{26} + x^{23} + x^{22} + x^{16} + x^{12} + x^{11}}
21144 @math{+ x^{10} + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1}
21145@end display
21146@end ifnothtml
21147
21148The function is computed byte at a time, taking the least
21149significant bit of each byte first. The initial pattern
21150@code{0xffffffff} is used, to ensure leading zeros affect the CRC and
21151the final result is inverted to ensure trailing zeros also affect the
21152CRC.
21153
21154@emph{Note:} This is the same CRC polynomial as used in handling the
936d2992
PA
21155@dfn{Remote Serial Protocol} @code{qCRC} packet (@pxref{qCRC packet}).
21156However in the case of the Remote Serial Protocol, the CRC is computed
21157@emph{most} significant bit first, and the result is not inverted, so
21158trailing zeros have no effect on the CRC value.
99e008fe
EZ
21159
21160To complete the description, we show below the code of the function
21161which produces the CRC used in @code{.gnu_debuglink}. Inverting the
21162initially supplied @code{crc} argument means that an initial call to
21163this function passing in zero will start computing the CRC using
21164@code{0xffffffff}.
5b5d99cf 21165
4644b6e3 21166@kindex gnu_debuglink_crc32
5b5d99cf
JB
21167@smallexample
21168unsigned long
21169gnu_debuglink_crc32 (unsigned long crc,
21170 unsigned char *buf, size_t len)
21171@{
21172 static const unsigned long crc32_table[256] =
21173 @{
21174 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
21175 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
21176 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
21177 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
21178 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
21179 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
21180 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
21181 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
21182 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
21183 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
21184 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
21185 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
21186 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
21187 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
21188 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
21189 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
21190 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
21191 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
21192 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
21193 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
21194 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
21195 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
21196 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
21197 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
21198 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
21199 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
21200 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
21201 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
21202 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
21203 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
21204 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
21205 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
21206 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
21207 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
21208 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
21209 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
21210 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
21211 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
21212 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
21213 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
21214 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
21215 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
21216 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
21217 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
21218 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
21219 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
21220 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
21221 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
21222 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
21223 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
21224 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
21225 0x2d02ef8d
21226 @};
21227 unsigned char *end;
21228
21229 crc = ~crc & 0xffffffff;
21230 for (end = buf + len; buf < end; ++buf)
21231 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
e7a3abfc 21232 return ~crc & 0xffffffff;
5b5d99cf
JB
21233@}
21234@end smallexample
21235
c7e83d54
EZ
21236@noindent
21237This computation does not apply to the ``build ID'' method.
21238
608e2dbb
TT
21239@node MiniDebugInfo
21240@section Debugging information in a special section
21241@cindex separate debug sections
21242@cindex @samp{.gnu_debugdata} section
21243
21244Some systems ship pre-built executables and libraries that have a
21245special @samp{.gnu_debugdata} section. This feature is called
21246@dfn{MiniDebugInfo}. This section holds an LZMA-compressed object and
21247is used to supply extra symbols for backtraces.
21248
21249The intent of this section is to provide extra minimal debugging
21250information for use in simple backtraces. It is not intended to be a
21251replacement for full separate debugging information (@pxref{Separate
21252Debug Files}). The example below shows the intended use; however,
21253@value{GDBN} does not currently put restrictions on what sort of
21254debugging information might be included in the section.
21255
21256@value{GDBN} has support for this extension. If the section exists,
21257then it is used provided that no other source of debugging information
21258can be found, and that @value{GDBN} was configured with LZMA support.
21259
21260This section can be easily created using @command{objcopy} and other
21261standard utilities:
21262
21263@smallexample
21264# Extract the dynamic symbols from the main binary, there is no need
5423b017 21265# to also have these in the normal symbol table.
608e2dbb
TT
21266nm -D @var{binary} --format=posix --defined-only \
21267 | awk '@{ print $1 @}' | sort > dynsyms
21268
5423b017 21269# Extract all the text (i.e. function) symbols from the debuginfo.
1d236d23
JK
21270# (Note that we actually also accept "D" symbols, for the benefit
21271# of platforms like PowerPC64 that use function descriptors.)
608e2dbb 21272nm @var{binary} --format=posix --defined-only \
1d236d23 21273 | awk '@{ if ($2 == "T" || $2 == "t" || $2 == "D") print $1 @}' \
608e2dbb
TT
21274 | sort > funcsyms
21275
21276# Keep all the function symbols not already in the dynamic symbol
21277# table.
21278comm -13 dynsyms funcsyms > keep_symbols
21279
edf9f00c
JK
21280# Separate full debug info into debug binary.
21281objcopy --only-keep-debug @var{binary} debug
21282
608e2dbb
TT
21283# Copy the full debuginfo, keeping only a minimal set of symbols and
21284# removing some unnecessary sections.
21285objcopy -S --remove-section .gdb_index --remove-section .comment \
edf9f00c
JK
21286 --keep-symbols=keep_symbols debug mini_debuginfo
21287
21288# Drop the full debug info from the original binary.
21289strip --strip-all -R .comment @var{binary}
608e2dbb
TT
21290
21291# Inject the compressed data into the .gnu_debugdata section of the
21292# original binary.
21293xz mini_debuginfo
21294objcopy --add-section .gnu_debugdata=mini_debuginfo.xz @var{binary}
21295@end smallexample
5b5d99cf 21296
9291a0cd
TT
21297@node Index Files
21298@section Index Files Speed Up @value{GDBN}
21299@cindex index files
21300@cindex @samp{.gdb_index} section
21301
21302When @value{GDBN} finds a symbol file, it scans the symbols in the
21303file in order to construct an internal symbol table. This lets most
21304@value{GDBN} operations work quickly---at the cost of a delay early
21305on. For large programs, this delay can be quite lengthy, so
21306@value{GDBN} provides a way to build an index, which speeds up
21307startup.
21308
ba643918
SDJ
21309For convenience, @value{GDBN} comes with a program,
21310@command{gdb-add-index}, which can be used to add the index to a
21311symbol file. It takes the symbol file as its only argument:
21312
21313@smallexample
21314$ gdb-add-index symfile
21315@end smallexample
21316
21317@xref{gdb-add-index}.
21318
21319It is also possible to do the work manually. Here is what
21320@command{gdb-add-index} does behind the curtains.
21321
9291a0cd
TT
21322The index is stored as a section in the symbol file. @value{GDBN} can
21323write the index to a file, then you can put it into the symbol file
21324using @command{objcopy}.
21325
21326To create an index file, use the @code{save gdb-index} command:
21327
21328@table @code
437afbb8 21329@item save gdb-index [-dwarf-5] @var{directory}
9291a0cd 21330@kindex save gdb-index
437afbb8
JK
21331Create index files for all symbol files currently known by
21332@value{GDBN}. For each known @var{symbol-file}, this command by
21333default creates it produces a single file
21334@file{@var{symbol-file}.gdb-index}. If you invoke this command with
21335the @option{-dwarf-5} option, it produces 2 files:
21336@file{@var{symbol-file}.debug_names} and
21337@file{@var{symbol-file}.debug_str}. The files are created in the
21338given @var{directory}.
9291a0cd
TT
21339@end table
21340
21341Once you have created an index file you can merge it into your symbol
21342file, here named @file{symfile}, using @command{objcopy}:
21343
21344@smallexample
21345$ objcopy --add-section .gdb_index=symfile.gdb-index \
21346 --set-section-flags .gdb_index=readonly symfile symfile
21347@end smallexample
21348
437afbb8
JK
21349Or for @code{-dwarf-5}:
21350
21351@smallexample
21352$ objcopy --dump-section .debug_str=symfile.debug_str.new symfile
21353$ cat symfile.debug_str >>symfile.debug_str.new
21354$ objcopy --add-section .debug_names=symfile.gdb-index \
21355 --set-section-flags .debug_names=readonly \
21356 --update-section .debug_str=symfile.debug_str.new symfile symfile
21357@end smallexample
21358
e615022a
DE
21359@value{GDBN} will normally ignore older versions of @file{.gdb_index}
21360sections that have been deprecated. Usually they are deprecated because
21361they are missing a new feature or have performance issues.
21362To tell @value{GDBN} to use a deprecated index section anyway
21363specify @code{set use-deprecated-index-sections on}.
21364The default is @code{off}.
21365This can speed up startup, but may result in some functionality being lost.
21366@xref{Index Section Format}.
21367
21368@emph{Warning:} Setting @code{use-deprecated-index-sections} to @code{on}
21369must be done before gdb reads the file. The following will not work:
21370
21371@smallexample
21372$ gdb -ex "set use-deprecated-index-sections on" <program>
21373@end smallexample
21374
21375Instead you must do, for example,
21376
21377@smallexample
21378$ gdb -iex "set use-deprecated-index-sections on" <program>
21379@end smallexample
21380
914592f9 21381Indices only work when using DWARF debugging information, not stabs.
9291a0cd 21382
7d11235d
SM
21383@subsection Automatic symbol index cache
21384
a0a3a1e9 21385@cindex automatic symbol index cache
7d11235d
SM
21386It is possible for @value{GDBN} to automatically save a copy of this index in a
21387cache on disk and retrieve it from there when loading the same binary in the
21388future. This feature can be turned on with @kbd{set index-cache on}. The
21389following commands can be used to tweak the behavior of the index cache.
21390
21391@table @code
21392
a0a3a1e9 21393@kindex set index-cache
7d11235d
SM
21394@item set index-cache on
21395@itemx set index-cache off
21396Enable or disable the use of the symbol index cache.
21397
21398@item set index-cache directory @var{directory}
a0a3a1e9 21399@kindex show index-cache
7d11235d 21400@itemx show index-cache directory
e6cd1dc1
TT
21401Set/show the directory where index files will be saved.
21402
21403The default value for this directory depends on the host platform. On
21404most systems, the index is cached in the @file{gdb} subdirectory of
21405the directory pointed to by the @env{XDG_CACHE_HOME} environment
21406variable, if it is defined, else in the @file{.cache/gdb} subdirectory
21407of your home directory. However, on some systems, the default may
21408differ according to local convention.
7d11235d
SM
21409
21410There is no limit on the disk space used by index cache. It is perfectly safe
21411to delete the content of that directory to free up disk space.
21412
21413@item show index-cache stats
21414Print the number of cache hits and misses since the launch of @value{GDBN}.
21415
21416@end table
21417
6d2ebf8b 21418@node Symbol Errors
79a6e687 21419@section Errors Reading Symbol Files
c906108c
SS
21420
21421While reading a symbol file, @value{GDBN} occasionally encounters problems,
21422such as symbol types it does not recognize, or known bugs in compiler
21423output. By default, @value{GDBN} does not notify you of such problems, since
21424they are relatively common and primarily of interest to people
21425debugging compilers. If you are interested in seeing information
21426about ill-constructed symbol tables, you can either ask @value{GDBN} to print
21427only one message about each such type of problem, no matter how many
21428times the problem occurs; or you can ask @value{GDBN} to print more messages,
21429to see how many times the problems occur, with the @code{set
79a6e687
BW
21430complaints} command (@pxref{Messages/Warnings, ,Optional Warnings and
21431Messages}).
c906108c
SS
21432
21433The messages currently printed, and their meanings, include:
21434
21435@table @code
21436@item inner block not inside outer block in @var{symbol}
21437
21438The symbol information shows where symbol scopes begin and end
21439(such as at the start of a function or a block of statements). This
21440error indicates that an inner scope block is not fully contained
21441in its outer scope blocks.
21442
21443@value{GDBN} circumvents the problem by treating the inner block as if it had
21444the same scope as the outer block. In the error message, @var{symbol}
21445may be shown as ``@code{(don't know)}'' if the outer block is not a
21446function.
21447
21448@item block at @var{address} out of order
21449
21450The symbol information for symbol scope blocks should occur in
21451order of increasing addresses. This error indicates that it does not
21452do so.
21453
21454@value{GDBN} does not circumvent this problem, and has trouble
21455locating symbols in the source file whose symbols it is reading. (You
21456can often determine what source file is affected by specifying
79a6e687
BW
21457@code{set verbose on}. @xref{Messages/Warnings, ,Optional Warnings and
21458Messages}.)
c906108c
SS
21459
21460@item bad block start address patched
21461
21462The symbol information for a symbol scope block has a start address
21463smaller than the address of the preceding source line. This is known
21464to occur in the SunOS 4.1.1 (and earlier) C compiler.
21465
21466@value{GDBN} circumvents the problem by treating the symbol scope block as
21467starting on the previous source line.
21468
21469@item bad string table offset in symbol @var{n}
21470
21471@cindex foo
21472Symbol number @var{n} contains a pointer into the string table which is
21473larger than the size of the string table.
21474
21475@value{GDBN} circumvents the problem by considering the symbol to have the
21476name @code{foo}, which may cause other problems if many symbols end up
21477with this name.
21478
21479@item unknown symbol type @code{0x@var{nn}}
21480
7a292a7a
SS
21481The symbol information contains new data types that @value{GDBN} does
21482not yet know how to read. @code{0x@var{nn}} is the symbol type of the
d4f3574e 21483uncomprehended information, in hexadecimal.
c906108c 21484
7a292a7a
SS
21485@value{GDBN} circumvents the error by ignoring this symbol information.
21486This usually allows you to debug your program, though certain symbols
c906108c 21487are not accessible. If you encounter such a problem and feel like
7a292a7a
SS
21488debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
21489on @code{complain}, then go up to the function @code{read_dbx_symtab}
21490and examine @code{*bufp} to see the symbol.
c906108c
SS
21491
21492@item stub type has NULL name
c906108c 21493
7a292a7a 21494@value{GDBN} could not find the full definition for a struct or class.
c906108c 21495
7a292a7a 21496@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
b37052ae 21497The symbol information for a C@t{++} member function is missing some
7a292a7a
SS
21498information that recent versions of the compiler should have output for
21499it.
c906108c
SS
21500
21501@item info mismatch between compiler and debugger
21502
21503@value{GDBN} could not parse a type specification output by the compiler.
7a292a7a 21504
c906108c
SS
21505@end table
21506
b14b1491
TT
21507@node Data Files
21508@section GDB Data Files
21509
21510@cindex prefix for data files
21511@value{GDBN} will sometimes read an auxiliary data file. These files
21512are kept in a directory known as the @dfn{data directory}.
21513
21514You can set the data directory's name, and view the name @value{GDBN}
21515is currently using.
21516
21517@table @code
21518@kindex set data-directory
21519@item set data-directory @var{directory}
21520Set the directory which @value{GDBN} searches for auxiliary data files
21521to @var{directory}.
21522
21523@kindex show data-directory
21524@item show data-directory
21525Show the directory @value{GDBN} searches for auxiliary data files.
21526@end table
21527
21528@cindex default data directory
21529@cindex @samp{--with-gdb-datadir}
21530You can set the default data directory by using the configure-time
21531@samp{--with-gdb-datadir} option. If the data directory is inside
21532@value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
21533@samp{--exec-prefix}), then the default data directory will be updated
21534automatically if the installed @value{GDBN} is moved to a new
21535location.
21536
aae1c79a
DE
21537The data directory may also be specified with the
21538@code{--data-directory} command line option.
21539@xref{Mode Options}.
21540
6d2ebf8b 21541@node Targets
c906108c 21542@chapter Specifying a Debugging Target
7a292a7a 21543
c906108c 21544@cindex debugging target
c906108c 21545A @dfn{target} is the execution environment occupied by your program.
53a5351d
JM
21546
21547Often, @value{GDBN} runs in the same host environment as your program;
21548in that case, the debugging target is specified as a side effect when
21549you use the @code{file} or @code{core} commands. When you need more
c906108c
SS
21550flexibility---for example, running @value{GDBN} on a physically separate
21551host, or controlling a standalone system over a serial port or a
53a5351d
JM
21552realtime system over a TCP/IP connection---you can use the @code{target}
21553command to specify one of the target types configured for @value{GDBN}
79a6e687 21554(@pxref{Target Commands, ,Commands for Managing Targets}).
c906108c 21555
a8f24a35
EZ
21556@cindex target architecture
21557It is possible to build @value{GDBN} for several different @dfn{target
21558architectures}. When @value{GDBN} is built like that, you can choose
21559one of the available architectures with the @kbd{set architecture}
21560command.
21561
21562@table @code
21563@kindex set architecture
21564@kindex show architecture
21565@item set architecture @var{arch}
21566This command sets the current target architecture to @var{arch}. The
21567value of @var{arch} can be @code{"auto"}, in addition to one of the
21568supported architectures.
21569
21570@item show architecture
21571Show the current target architecture.
9c16f35a
EZ
21572
21573@item set processor
21574@itemx processor
21575@kindex set processor
21576@kindex show processor
21577These are alias commands for, respectively, @code{set architecture}
21578and @code{show architecture}.
a8f24a35
EZ
21579@end table
21580
c906108c
SS
21581@menu
21582* Active Targets:: Active targets
21583* Target Commands:: Commands for managing targets
c906108c 21584* Byte Order:: Choosing target byte order
c906108c
SS
21585@end menu
21586
6d2ebf8b 21587@node Active Targets
79a6e687 21588@section Active Targets
7a292a7a 21589
c906108c
SS
21590@cindex stacking targets
21591@cindex active targets
21592@cindex multiple targets
21593
8ea5bce5 21594There are multiple classes of targets such as: processes, executable files or
c0edd9ed
JK
21595recording sessions. Core files belong to the process class, making core file
21596and process mutually exclusive. Otherwise, @value{GDBN} can work concurrently
21597on multiple active targets, one in each class. This allows you to (for
21598example) start a process and inspect its activity, while still having access to
21599the executable file after the process finishes. Or if you start process
21600recording (@pxref{Reverse Execution}) and @code{reverse-step} there, you are
21601presented a virtual layer of the recording target, while the process target
21602remains stopped at the chronologically last point of the process execution.
21603
21604Use the @code{core-file} and @code{exec-file} commands to select a new core
21605file or executable target (@pxref{Files, ,Commands to Specify Files}). To
21606specify as a target a process that is already running, use the @code{attach}
21607command (@pxref{Attach, ,Debugging an Already-running Process}).
c906108c 21608
6d2ebf8b 21609@node Target Commands
79a6e687 21610@section Commands for Managing Targets
c906108c
SS
21611
21612@table @code
21613@item target @var{type} @var{parameters}
7a292a7a
SS
21614Connects the @value{GDBN} host environment to a target machine or
21615process. A target is typically a protocol for talking to debugging
21616facilities. You use the argument @var{type} to specify the type or
21617protocol of the target machine.
c906108c
SS
21618
21619Further @var{parameters} are interpreted by the target protocol, but
21620typically include things like device names or host names to connect
21621with, process numbers, and baud rates.
c906108c
SS
21622
21623The @code{target} command does not repeat if you press @key{RET} again
21624after executing the command.
21625
21626@kindex help target
21627@item help target
21628Displays the names of all targets available. To display targets
21629currently selected, use either @code{info target} or @code{info files}
79a6e687 21630(@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
21631
21632@item help target @var{name}
21633Describe a particular target, including any parameters necessary to
21634select it.
21635
21636@kindex set gnutarget
21637@item set gnutarget @var{args}
5d161b24 21638@value{GDBN} uses its own library BFD to read your files. @value{GDBN}
c906108c 21639knows whether it is reading an @dfn{executable},
5d161b24
DB
21640a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
21641with the @code{set gnutarget} command. Unlike most @code{target} commands,
c906108c
SS
21642with @code{gnutarget} the @code{target} refers to a program, not a machine.
21643
d4f3574e 21644@quotation
c906108c
SS
21645@emph{Warning:} To specify a file format with @code{set gnutarget},
21646you must know the actual BFD name.
d4f3574e 21647@end quotation
c906108c 21648
d4f3574e 21649@noindent
79a6e687 21650@xref{Files, , Commands to Specify Files}.
c906108c 21651
5d161b24 21652@kindex show gnutarget
c906108c
SS
21653@item show gnutarget
21654Use the @code{show gnutarget} command to display what file format
21655@code{gnutarget} is set to read. If you have not set @code{gnutarget},
21656@value{GDBN} will determine the file format for each file automatically,
c4957902 21657and @code{show gnutarget} displays @samp{The current BFD target is "auto"}.
c906108c
SS
21658@end table
21659
4644b6e3 21660@cindex common targets
c906108c
SS
21661Here are some common targets (available, or not, depending on the GDB
21662configuration):
c906108c
SS
21663
21664@table @code
4644b6e3 21665@kindex target
c906108c 21666@item target exec @var{program}
4644b6e3 21667@cindex executable file target
c906108c
SS
21668An executable file. @samp{target exec @var{program}} is the same as
21669@samp{exec-file @var{program}}.
21670
c906108c 21671@item target core @var{filename}
4644b6e3 21672@cindex core dump file target
c906108c
SS
21673A core dump file. @samp{target core @var{filename}} is the same as
21674@samp{core-file @var{filename}}.
c906108c 21675
1a10341b 21676@item target remote @var{medium}
4644b6e3 21677@cindex remote target
1a10341b
JB
21678A remote system connected to @value{GDBN} via a serial line or network
21679connection. This command tells @value{GDBN} to use its own remote
21680protocol over @var{medium} for debugging. @xref{Remote Debugging}.
21681
21682For example, if you have a board connected to @file{/dev/ttya} on the
21683machine running @value{GDBN}, you could say:
21684
21685@smallexample
21686target remote /dev/ttya
21687@end smallexample
21688
21689@code{target remote} supports the @code{load} command. This is only
21690useful if you have some other way of getting the stub to the target
21691system, and you can put it somewhere in memory where it won't get
21692clobbered by the download.
c906108c 21693
ee8e71d4 21694@item target sim @r{[}@var{simargs}@r{]} @dots{}
4644b6e3 21695@cindex built-in simulator target
2df3850c 21696Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
104c1213 21697In general,
474c8240 21698@smallexample
104c1213
JM
21699 target sim
21700 load
21701 run
474c8240 21702@end smallexample
d4f3574e 21703@noindent
104c1213 21704works; however, you cannot assume that a specific memory map, device
d4f3574e 21705drivers, or even basic I/O is available, although some simulators do
104c1213
JM
21706provide these. For info about any processor-specific simulator details,
21707see the appropriate section in @ref{Embedded Processors, ,Embedded
21708Processors}.
21709
6a3cb8e8
PA
21710@item target native
21711@cindex native target
21712Setup for local/native process debugging. Useful to make the
21713@code{run} command spawn native processes (likewise @code{attach},
21714etc.@:) even when @code{set auto-connect-native-target} is @code{off}
21715(@pxref{set auto-connect-native-target}).
21716
c906108c
SS
21717@end table
21718
5d161b24 21719Different targets are available on different configurations of @value{GDBN};
c906108c 21720your configuration may have more or fewer targets.
c906108c 21721
721c2651
EZ
21722Many remote targets require you to download the executable's code once
21723you've successfully established a connection. You may wish to control
3d00d119
DJ
21724various aspects of this process.
21725
21726@table @code
721c2651
EZ
21727
21728@item set hash
21729@kindex set hash@r{, for remote monitors}
21730@cindex hash mark while downloading
21731This command controls whether a hash mark @samp{#} is displayed while
21732downloading a file to the remote monitor. If on, a hash mark is
21733displayed after each S-record is successfully downloaded to the
21734monitor.
21735
21736@item show hash
21737@kindex show hash@r{, for remote monitors}
21738Show the current status of displaying the hash mark.
21739
21740@item set debug monitor
21741@kindex set debug monitor
21742@cindex display remote monitor communications
21743Enable or disable display of communications messages between
21744@value{GDBN} and the remote monitor.
21745
21746@item show debug monitor
21747@kindex show debug monitor
21748Show the current status of displaying communications between
21749@value{GDBN} and the remote monitor.
a8f24a35 21750@end table
c906108c
SS
21751
21752@table @code
21753
5cf30ebf
LM
21754@kindex load @var{filename} @var{offset}
21755@item load @var{filename} @var{offset}
8edfe269 21756@anchor{load}
c906108c
SS
21757Depending on what remote debugging facilities are configured into
21758@value{GDBN}, the @code{load} command may be available. Where it exists, it
21759is meant to make @var{filename} (an executable) available for debugging
21760on the remote system---by downloading, or dynamic linking, for example.
21761@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
21762the @code{add-symbol-file} command.
21763
21764If your @value{GDBN} does not have a @code{load} command, attempting to
21765execute it gets the error message ``@code{You can't do that when your
21766target is @dots{}}''
c906108c
SS
21767
21768The file is loaded at whatever address is specified in the executable.
21769For some object file formats, you can specify the load address when you
21770link the program; for other formats, like a.out, the object file format
21771specifies a fixed address.
21772@c FIXME! This would be a good place for an xref to the GNU linker doc.
21773
5cf30ebf
LM
21774It is also possible to tell @value{GDBN} to load the executable file at a
21775specific offset described by the optional argument @var{offset}. When
21776@var{offset} is provided, @var{filename} must also be provided.
21777
68437a39
DJ
21778Depending on the remote side capabilities, @value{GDBN} may be able to
21779load programs into flash memory.
21780
c906108c
SS
21781@code{load} does not repeat if you press @key{RET} again after using it.
21782@end table
21783
78cbbba8
LM
21784@table @code
21785
21786@kindex flash-erase
21787@item flash-erase
21788@anchor{flash-erase}
21789
21790Erases all known flash memory regions on the target.
21791
21792@end table
21793
6d2ebf8b 21794@node Byte Order
79a6e687 21795@section Choosing Target Byte Order
7a292a7a 21796
c906108c
SS
21797@cindex choosing target byte order
21798@cindex target byte order
c906108c 21799
eb17f351 21800Some types of processors, such as the @acronym{MIPS}, PowerPC, and Renesas SH,
c906108c
SS
21801offer the ability to run either big-endian or little-endian byte
21802orders. Usually the executable or symbol will include a bit to
21803designate the endian-ness, and you will not need to worry about
21804which to use. However, you may still find it useful to adjust
d4f3574e 21805@value{GDBN}'s idea of processor endian-ness manually.
c906108c
SS
21806
21807@table @code
4644b6e3 21808@kindex set endian
c906108c
SS
21809@item set endian big
21810Instruct @value{GDBN} to assume the target is big-endian.
21811
c906108c
SS
21812@item set endian little
21813Instruct @value{GDBN} to assume the target is little-endian.
21814
c906108c
SS
21815@item set endian auto
21816Instruct @value{GDBN} to use the byte order associated with the
21817executable.
21818
21819@item show endian
21820Display @value{GDBN}'s current idea of the target byte order.
21821
21822@end table
21823
4b2dfa9d
MR
21824If the @code{set endian auto} mode is in effect and no executable has
21825been selected, then the endianness used is the last one chosen either
21826by one of the @code{set endian big} and @code{set endian little}
21827commands or by inferring from the last executable used. If no
21828endianness has been previously chosen, then the default for this mode
21829is inferred from the target @value{GDBN} has been built for, and is
21830@code{little} if the name of the target CPU has an @code{el} suffix
21831and @code{big} otherwise.
21832
c906108c
SS
21833Note that these commands merely adjust interpretation of symbolic
21834data on the host, and that they have absolutely no effect on the
21835target system.
21836
ea35711c
DJ
21837
21838@node Remote Debugging
21839@chapter Debugging Remote Programs
c906108c
SS
21840@cindex remote debugging
21841
21842If you are trying to debug a program running on a machine that cannot run
5d161b24
DB
21843@value{GDBN} in the usual way, it is often useful to use remote debugging.
21844For example, you might use remote debugging on an operating system kernel,
c906108c
SS
21845or on a small system which does not have a general purpose operating system
21846powerful enough to run a full-featured debugger.
21847
21848Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
21849to make this work with particular debugging targets. In addition,
5d161b24 21850@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
c906108c
SS
21851but not specific to any particular target system) which you can use if you
21852write the remote stubs---the code that runs on the remote system to
21853communicate with @value{GDBN}.
21854
21855Other remote targets may be available in your
21856configuration of @value{GDBN}; use @code{help target} to list them.
c906108c 21857
6b2f586d 21858@menu
07f31aa6 21859* Connecting:: Connecting to a remote target
a6b151f1 21860* File Transfer:: Sending files to a remote system
6b2f586d 21861* Server:: Using the gdbserver program
79a6e687
BW
21862* Remote Configuration:: Remote configuration
21863* Remote Stub:: Implementing a remote stub
6b2f586d
AC
21864@end menu
21865
07f31aa6 21866@node Connecting
79a6e687 21867@section Connecting to a Remote Target
19d9d4ef
DB
21868@cindex remote debugging, connecting
21869@cindex @code{gdbserver}, connecting
21870@cindex remote debugging, types of connections
21871@cindex @code{gdbserver}, types of connections
21872@cindex @code{gdbserver}, @code{target remote} mode
21873@cindex @code{gdbserver}, @code{target extended-remote} mode
21874
21875This section describes how to connect to a remote target, including the
21876types of connections and their differences, how to set up executable and
21877symbol files on the host and target, and the commands used for
21878connecting to and disconnecting from the remote target.
21879
21880@subsection Types of Remote Connections
21881
21882@value{GDBN} supports two types of remote connections, @code{target remote}
21883mode and @code{target extended-remote} mode. Note that many remote targets
21884support only @code{target remote} mode. There are several major
21885differences between the two types of connections, enumerated here:
21886
21887@table @asis
21888
21889@cindex remote debugging, detach and program exit
21890@item Result of detach or program exit
21891@strong{With target remote mode:} When the debugged program exits or you
21892detach from it, @value{GDBN} disconnects from the target. When using
21893@code{gdbserver}, @code{gdbserver} will exit.
21894
21895@strong{With target extended-remote mode:} When the debugged program exits or
21896you detach from it, @value{GDBN} remains connected to the target, even
21897though no program is running. You can rerun the program, attach to a
21898running program, or use @code{monitor} commands specific to the target.
21899
21900When using @code{gdbserver} in this case, it does not exit unless it was
21901invoked using the @option{--once} option. If the @option{--once} option
21902was not used, you can ask @code{gdbserver} to exit using the
21903@code{monitor exit} command (@pxref{Monitor Commands for gdbserver}).
21904
21905@item Specifying the program to debug
21906For both connection types you use the @code{file} command to specify the
21907program on the host system. If you are using @code{gdbserver} there are
21908some differences in how to specify the location of the program on the
21909target.
21910
21911@strong{With target remote mode:} You must either specify the program to debug
21912on the @code{gdbserver} command line or use the @option{--attach} option
21913(@pxref{Attaching to a program,,Attaching to a Running Program}).
21914
21915@cindex @option{--multi}, @code{gdbserver} option
21916@strong{With target extended-remote mode:} You may specify the program to debug
21917on the @code{gdbserver} command line, or you can load the program or attach
21918to it using @value{GDBN} commands after connecting to @code{gdbserver}.
21919
21920@anchor{--multi Option in Types of Remote Connnections}
21921You can start @code{gdbserver} without supplying an initial command to run
21922or process ID to attach. To do this, use the @option{--multi} command line
21923option. Then you can connect using @code{target extended-remote} and start
21924the program you want to debug (see below for details on using the
21925@code{run} command in this scenario). Note that the conditions under which
21926@code{gdbserver} terminates depend on how @value{GDBN} connects to it
21927(@code{target remote} or @code{target extended-remote}). The
21928@option{--multi} option to @code{gdbserver} has no influence on that.
07f31aa6 21929
19d9d4ef
DB
21930@item The @code{run} command
21931@strong{With target remote mode:} The @code{run} command is not
21932supported. Once a connection has been established, you can use all
21933the usual @value{GDBN} commands to examine and change data. The
21934remote program is already running, so you can use commands like
21935@kbd{step} and @kbd{continue}.
21936
21937@strong{With target extended-remote mode:} The @code{run} command is
21938supported. The @code{run} command uses the value set by
21939@code{set remote exec-file} (@pxref{set remote exec-file}) to select
21940the program to run. Command line arguments are supported, except for
21941wildcard expansion and I/O redirection (@pxref{Arguments}).
21942
21943If you specify the program to debug on the command line, then the
21944@code{run} command is not required to start execution, and you can
21945resume using commands like @kbd{step} and @kbd{continue} as with
21946@code{target remote} mode.
21947
21948@anchor{Attaching in Types of Remote Connections}
21949@item Attaching
21950@strong{With target remote mode:} The @value{GDBN} command @code{attach} is
21951not supported. To attach to a running program using @code{gdbserver}, you
21952must use the @option{--attach} option (@pxref{Running gdbserver}).
21953
21954@strong{With target extended-remote mode:} To attach to a running program,
21955you may use the @code{attach} command after the connection has been
21956established. If you are using @code{gdbserver}, you may also invoke
21957@code{gdbserver} using the @option{--attach} option
21958(@pxref{Running gdbserver}).
21959
e47e48f6
PW
21960Some remote targets allow @value{GDBN} to determine the executable file running
21961in the process the debugger is attaching to. In such a case, @value{GDBN}
21962uses the value of @code{exec-file-mismatch} to handle a possible mismatch
21963between the executable file name running in the process and the name of the
21964current exec-file loaded by @value{GDBN} (@pxref{set exec-file-mismatch}).
21965
19d9d4ef
DB
21966@end table
21967
21968@anchor{Host and target files}
21969@subsection Host and Target Files
21970@cindex remote debugging, symbol files
21971@cindex symbol files, remote debugging
21972
21973@value{GDBN}, running on the host, needs access to symbol and debugging
21974information for your program running on the target. This requires
21975access to an unstripped copy of your program, and possibly any associated
21976symbol files. Note that this section applies equally to both @code{target
21977remote} mode and @code{target extended-remote} mode.
21978
21979Some remote targets (@pxref{qXfer executable filename read}, and
21980@pxref{Host I/O Packets}) allow @value{GDBN} to access program files over
21981the same connection used to communicate with @value{GDBN}. With such a
21982target, if the remote program is unstripped, the only command you need is
21983@code{target remote} (or @code{target extended-remote}).
21984
21985If the remote program is stripped, or the target does not support remote
21986program file access, start up @value{GDBN} using the name of the local
1b6e6f5c 21987unstripped copy of your program as the first argument, or use the
19d9d4ef
DB
21988@code{file} command. Use @code{set sysroot} to specify the location (on
21989the host) of target libraries (unless your @value{GDBN} was compiled with
21990the correct sysroot using @code{--with-sysroot}). Alternatively, you
21991may use @code{set solib-search-path} to specify how @value{GDBN} locates
21992target libraries.
21993
21994The symbol file and target libraries must exactly match the executable
21995and libraries on the target, with one exception: the files on the host
21996system should not be stripped, even if the files on the target system
21997are. Mismatched or missing files will lead to confusing results
21998during debugging. On @sc{gnu}/Linux targets, mismatched or missing
21999files may also prevent @code{gdbserver} from debugging multi-threaded
22000programs.
07f31aa6 22001
19d9d4ef
DB
22002@subsection Remote Connection Commands
22003@cindex remote connection commands
c1168a2f
JD
22004@value{GDBN} can communicate with the target over a serial line, a
22005local Unix domain socket, or
86941c27
JB
22006over an @acronym{IP} network using @acronym{TCP} or @acronym{UDP}. In
22007each case, @value{GDBN} uses the same protocol for debugging your
22008program; only the medium carrying the debugging packets varies. The
19d9d4ef
DB
22009@code{target remote} and @code{target extended-remote} commands
22010establish a connection to the target. Both commands accept the same
22011arguments, which indicate the medium to use:
86941c27
JB
22012
22013@table @code
22014
22015@item target remote @var{serial-device}
19d9d4ef 22016@itemx target extended-remote @var{serial-device}
07f31aa6 22017@cindex serial line, @code{target remote}
86941c27
JB
22018Use @var{serial-device} to communicate with the target. For example,
22019to use a serial line connected to the device named @file{/dev/ttyb}:
22020
22021@smallexample
22022target remote /dev/ttyb
22023@end smallexample
22024
07f31aa6 22025If you're using a serial line, you may want to give @value{GDBN} the
2446f5ea 22026@samp{--baud} option, or use the @code{set serial baud} command
0d12017b 22027(@pxref{Remote Configuration, set serial baud}) before the
9c16f35a 22028@code{target} command.
07f31aa6 22029
c1168a2f
JD
22030@item target remote @var{local-socket}
22031@itemx target extended-remote @var{local-socket}
22032@cindex local socket, @code{target remote}
22033@cindex Unix domain socket
22034Use @var{local-socket} to communicate with the target. For example,
22035to use a local Unix domain socket bound to the file system entry @file{/tmp/gdb-socket0}:
22036
22037@smallexample
22038target remote /tmp/gdb-socket0
22039@end smallexample
22040
22041Note that this command has the same form as the command to connect
22042to a serial line. @value{GDBN} will automatically determine which
22043kind of file you have specified and will make the appropriate kind
22044of connection.
22045This feature is not available if the host system does not support
22046Unix domain sockets.
22047
86941c27 22048@item target remote @code{@var{host}:@var{port}}
0ca4866a 22049@itemx target remote @code{[@var{host}]:@var{port}}
86941c27 22050@itemx target remote @code{tcp:@var{host}:@var{port}}
0ca4866a 22051@itemx target remote @code{tcp:[@var{host}]:@var{port}}
c7ab0aef
SDJ
22052@itemx target remote @code{tcp4:@var{host}:@var{port}}
22053@itemx target remote @code{tcp6:@var{host}:@var{port}}
0ca4866a 22054@itemx target remote @code{tcp6:[@var{host}]:@var{port}}
19d9d4ef 22055@itemx target extended-remote @code{@var{host}:@var{port}}
0ca4866a 22056@itemx target extended-remote @code{[@var{host}]:@var{port}}
19d9d4ef 22057@itemx target extended-remote @code{tcp:@var{host}:@var{port}}
0ca4866a 22058@itemx target extended-remote @code{tcp:[@var{host}]:@var{port}}
c7ab0aef
SDJ
22059@itemx target extended-remote @code{tcp4:@var{host}:@var{port}}
22060@itemx target extended-remote @code{tcp6:@var{host}:@var{port}}
0ca4866a 22061@itemx target extended-remote @code{tcp6:[@var{host}]:@var{port}}
86941c27 22062@cindex @acronym{TCP} port, @code{target remote}
6a0b3457 22063Debug using a @acronym{TCP} connection to @var{port} on @var{host}.
c7ab0aef
SDJ
22064The @var{host} may be either a host name, a numeric @acronym{IPv4}
22065address, or a numeric @acronym{IPv6} address (with or without the
22066square brackets to separate the address from the port); @var{port}
22067must be a decimal number. The @var{host} could be the target machine
22068itself, if it is directly connected to the net, or it might be a
22069terminal server which in turn has a serial line to the target.
07f31aa6 22070
86941c27
JB
22071For example, to connect to port 2828 on a terminal server named
22072@code{manyfarms}:
07f31aa6
DJ
22073
22074@smallexample
22075target remote manyfarms:2828
22076@end smallexample
22077
c7ab0aef
SDJ
22078To connect to port 2828 on a terminal server whose address is
22079@code{2001:0db8:85a3:0000:0000:8a2e:0370:7334}, you can either use the
22080square bracket syntax:
22081
22082@smallexample
22083target remote [2001:0db8:85a3:0000:0000:8a2e:0370:7334]:2828
22084@end smallexample
22085
22086@noindent
22087or explicitly specify the @acronym{IPv6} protocol:
22088
22089@smallexample
22090target remote tcp6:2001:0db8:85a3:0000:0000:8a2e:0370:7334:2828
22091@end smallexample
22092
22093This last example may be confusing to the reader, because there is no
22094visible separation between the hostname and the port number.
22095Therefore, we recommend the user to provide @acronym{IPv6} addresses
22096using square brackets for clarity. However, it is important to
22097mention that for @value{GDBN} there is no ambiguity: the number after
22098the last colon is considered to be the port number.
22099
86941c27
JB
22100If your remote target is actually running on the same machine as your
22101debugger session (e.g.@: a simulator for your target running on the
22102same host), you can omit the hostname. For example, to connect to
22103port 1234 on your local machine:
07f31aa6
DJ
22104
22105@smallexample
22106target remote :1234
22107@end smallexample
22108@noindent
22109
22110Note that the colon is still required here.
22111
86941c27 22112@item target remote @code{udp:@var{host}:@var{port}}
0ca4866a 22113@itemx target remote @code{udp:[@var{host}]:@var{port}}
c7ab0aef 22114@itemx target remote @code{udp4:@var{host}:@var{port}}
0ca4866a 22115@itemx target remote @code{udp6:[@var{host}]:@var{port}}
c7ab0aef 22116@itemx target extended-remote @code{udp:@var{host}:@var{port}}
19d9d4ef 22117@itemx target extended-remote @code{udp:@var{host}:@var{port}}
0ca4866a 22118@itemx target extended-remote @code{udp:[@var{host}]:@var{port}}
c7ab0aef
SDJ
22119@itemx target extended-remote @code{udp4:@var{host}:@var{port}}
22120@itemx target extended-remote @code{udp6:@var{host}:@var{port}}
0ca4866a 22121@itemx target extended-remote @code{udp6:[@var{host}]:@var{port}}
86941c27
JB
22122@cindex @acronym{UDP} port, @code{target remote}
22123Debug using @acronym{UDP} packets to @var{port} on @var{host}. For example, to
22124connect to @acronym{UDP} port 2828 on a terminal server named @code{manyfarms}:
07f31aa6
DJ
22125
22126@smallexample
22127target remote udp:manyfarms:2828
22128@end smallexample
22129
86941c27
JB
22130When using a @acronym{UDP} connection for remote debugging, you should
22131keep in mind that the `U' stands for ``Unreliable''. @acronym{UDP}
22132can silently drop packets on busy or unreliable networks, which will
22133cause havoc with your debugging session.
22134
66b8c7f6 22135@item target remote | @var{command}
19d9d4ef 22136@itemx target extended-remote | @var{command}
66b8c7f6
JB
22137@cindex pipe, @code{target remote} to
22138Run @var{command} in the background and communicate with it using a
22139pipe. The @var{command} is a shell command, to be parsed and expanded
22140by the system's command shell, @code{/bin/sh}; it should expect remote
22141protocol packets on its standard input, and send replies on its
22142standard output. You could use this to run a stand-alone simulator
22143that speaks the remote debugging protocol, to make net connections
22144using programs like @code{ssh}, or for other similar tricks.
22145
22146If @var{command} closes its standard output (perhaps by exiting),
22147@value{GDBN} will try to send it a @code{SIGTERM} signal. (If the
22148program has already exited, this will have no effect.)
22149
86941c27 22150@end table
07f31aa6 22151
07f31aa6
DJ
22152@cindex interrupting remote programs
22153@cindex remote programs, interrupting
22154Whenever @value{GDBN} is waiting for the remote program, if you type the
c8aa23ab 22155interrupt character (often @kbd{Ctrl-c}), @value{GDBN} attempts to stop the
07f31aa6
DJ
22156program. This may or may not succeed, depending in part on the hardware
22157and the serial drivers the remote system uses. If you type the
22158interrupt character once again, @value{GDBN} displays this prompt:
22159
22160@smallexample
22161Interrupted while waiting for the program.
22162Give up (and stop debugging it)? (y or n)
22163@end smallexample
22164
19d9d4ef
DB
22165In @code{target remote} mode, if you type @kbd{y}, @value{GDBN} abandons
22166the remote debugging session. (If you decide you want to try again later,
22167you can use @kbd{target remote} again to connect once more.) If you type
22168@kbd{n}, @value{GDBN} goes back to waiting.
22169
22170In @code{target extended-remote} mode, typing @kbd{n} will leave
22171@value{GDBN} connected to the target.
07f31aa6
DJ
22172
22173@table @code
22174@kindex detach (remote)
22175@item detach
22176When you have finished debugging the remote program, you can use the
22177@code{detach} command to release it from @value{GDBN} control.
22178Detaching from the target normally resumes its execution, but the results
22179will depend on your particular remote stub. After the @code{detach}
19d9d4ef
DB
22180command in @code{target remote} mode, @value{GDBN} is free to connect to
22181another target. In @code{target extended-remote} mode, @value{GDBN} is
22182still connected to the target.
07f31aa6
DJ
22183
22184@kindex disconnect
22185@item disconnect
19d9d4ef 22186The @code{disconnect} command closes the connection to the target, and
07f31aa6
DJ
22187the target is generally not resumed. It will wait for @value{GDBN}
22188(this instance or another one) to connect and continue debugging. After
22189the @code{disconnect} command, @value{GDBN} is again free to connect to
22190another target.
09d4efe1
EZ
22191
22192@cindex send command to remote monitor
fad38dfa
EZ
22193@cindex extend @value{GDBN} for remote targets
22194@cindex add new commands for external monitor
09d4efe1
EZ
22195@kindex monitor
22196@item monitor @var{cmd}
fad38dfa
EZ
22197This command allows you to send arbitrary commands directly to the
22198remote monitor. Since @value{GDBN} doesn't care about the commands it
22199sends like this, this command is the way to extend @value{GDBN}---you
22200can add new commands that only the external monitor will understand
22201and implement.
07f31aa6
DJ
22202@end table
22203
a6b151f1
DJ
22204@node File Transfer
22205@section Sending files to a remote system
22206@cindex remote target, file transfer
22207@cindex file transfer
22208@cindex sending files to remote systems
22209
22210Some remote targets offer the ability to transfer files over the same
22211connection used to communicate with @value{GDBN}. This is convenient
22212for targets accessible through other means, e.g.@: @sc{gnu}/Linux systems
22213running @code{gdbserver} over a network interface. For other targets,
22214e.g.@: embedded devices with only a single serial port, this may be
22215the only way to upload or download files.
22216
22217Not all remote targets support these commands.
22218
22219@table @code
22220@kindex remote put
22221@item remote put @var{hostfile} @var{targetfile}
22222Copy file @var{hostfile} from the host system (the machine running
22223@value{GDBN}) to @var{targetfile} on the target system.
22224
22225@kindex remote get
22226@item remote get @var{targetfile} @var{hostfile}
22227Copy file @var{targetfile} from the target system to @var{hostfile}
22228on the host system.
22229
22230@kindex remote delete
22231@item remote delete @var{targetfile}
22232Delete @var{targetfile} from the target system.
22233
22234@end table
22235
6f05cf9f 22236@node Server
79a6e687 22237@section Using the @code{gdbserver} Program
6f05cf9f
AC
22238
22239@kindex gdbserver
22240@cindex remote connection without stubs
22241@code{gdbserver} is a control program for Unix-like systems, which
22242allows you to connect your program with a remote @value{GDBN} via
19d9d4ef
DB
22243@code{target remote} or @code{target extended-remote}---but without
22244linking in the usual debugging stub.
6f05cf9f
AC
22245
22246@code{gdbserver} is not a complete replacement for the debugging stubs,
22247because it requires essentially the same operating-system facilities
22248that @value{GDBN} itself does. In fact, a system that can run
22249@code{gdbserver} to connect to a remote @value{GDBN} could also run
22250@value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
22251because it is a much smaller program than @value{GDBN} itself. It is
22252also easier to port than all of @value{GDBN}, so you may be able to get
22253started more quickly on a new system by using @code{gdbserver}.
22254Finally, if you develop code for real-time systems, you may find that
22255the tradeoffs involved in real-time operation make it more convenient to
22256do as much development work as possible on another system, for example
22257by cross-compiling. You can use @code{gdbserver} to make a similar
22258choice for debugging.
22259
22260@value{GDBN} and @code{gdbserver} communicate via either a serial line
22261or a TCP connection, using the standard @value{GDBN} remote serial
22262protocol.
22263
2d717e4f
DJ
22264@quotation
22265@emph{Warning:} @code{gdbserver} does not have any built-in security.
22266Do not run @code{gdbserver} connected to any public network; a
22267@value{GDBN} connection to @code{gdbserver} provides access to the
22268target system with the same privileges as the user running
22269@code{gdbserver}.
22270@end quotation
22271
19d9d4ef 22272@anchor{Running gdbserver}
2d717e4f
DJ
22273@subsection Running @code{gdbserver}
22274@cindex arguments, to @code{gdbserver}
d9b1a651 22275@cindex @code{gdbserver}, command-line arguments
2d717e4f
DJ
22276
22277Run @code{gdbserver} on the target system. You need a copy of the
22278program you want to debug, including any libraries it requires.
6f05cf9f
AC
22279@code{gdbserver} does not need your program's symbol table, so you can
22280strip the program if necessary to save space. @value{GDBN} on the host
22281system does all the symbol handling.
22282
22283To use the server, you must tell it how to communicate with @value{GDBN};
56460a61 22284the name of your program; and the arguments for your program. The usual
6f05cf9f
AC
22285syntax is:
22286
22287@smallexample
22288target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
22289@end smallexample
22290
6cf36756
SM
22291@var{comm} is either a device name (to use a serial line), or a TCP
22292hostname and portnumber, or @code{-} or @code{stdio} to use
22293stdin/stdout of @code{gdbserver}.
e0f9f062 22294For example, to debug Emacs with the argument
6f05cf9f
AC
22295@samp{foo.txt} and communicate with @value{GDBN} over the serial port
22296@file{/dev/com1}:
22297
22298@smallexample
22299target> gdbserver /dev/com1 emacs foo.txt
22300@end smallexample
22301
6cf36756
SM
22302@code{gdbserver} waits passively for the host @value{GDBN} to communicate
22303with it.
6f05cf9f
AC
22304
22305To use a TCP connection instead of a serial line:
22306
22307@smallexample
22308target> gdbserver host:2345 emacs foo.txt
22309@end smallexample
22310
22311The only difference from the previous example is the first argument,
22312specifying that you are communicating with the host @value{GDBN} via
22313TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
22314expect a TCP connection from machine @samp{host} to local TCP port 2345.
22315(Currently, the @samp{host} part is ignored.) You can choose any number
22316you want for the port number as long as it does not conflict with any
22317TCP ports already in use on the target system (for example, @code{23} is
22318reserved for @code{telnet}).@footnote{If you choose a port number that
22319conflicts with another service, @code{gdbserver} prints an error message
22320and exits.} You must use the same port number with the host @value{GDBN}
22321@code{target remote} command.
22322
6cf36756
SM
22323The @code{stdio} connection is useful when starting @code{gdbserver}
22324with ssh:
e0f9f062
DE
22325
22326@smallexample
6cf36756 22327(gdb) target remote | ssh -T hostname gdbserver - hello
e0f9f062
DE
22328@end smallexample
22329
6cf36756
SM
22330The @samp{-T} option to ssh is provided because we don't need a remote pty,
22331and we don't want escape-character handling. Ssh does this by default when
22332a command is provided, the flag is provided to make it explicit.
22333You could elide it if you want to.
e0f9f062 22334
6cf36756
SM
22335Programs started with stdio-connected gdbserver have @file{/dev/null} for
22336@code{stdin}, and @code{stdout},@code{stderr} are sent back to gdb for
22337display through a pipe connected to gdbserver.
22338Both @code{stdout} and @code{stderr} use the same pipe.
e0f9f062 22339
19d9d4ef 22340@anchor{Attaching to a program}
2d717e4f 22341@subsubsection Attaching to a Running Program
d9b1a651
EZ
22342@cindex attach to a program, @code{gdbserver}
22343@cindex @option{--attach}, @code{gdbserver} option
2d717e4f 22344
56460a61
DJ
22345On some targets, @code{gdbserver} can also attach to running programs.
22346This is accomplished via the @code{--attach} argument. The syntax is:
22347
22348@smallexample
2d717e4f 22349target> gdbserver --attach @var{comm} @var{pid}
56460a61
DJ
22350@end smallexample
22351
19d9d4ef
DB
22352@var{pid} is the process ID of a currently running process. It isn't
22353necessary to point @code{gdbserver} at a binary for the running process.
22354
22355In @code{target extended-remote} mode, you can also attach using the
22356@value{GDBN} attach command
22357(@pxref{Attaching in Types of Remote Connections}).
56460a61 22358
b1fe9455 22359@pindex pidof
b1fe9455
DJ
22360You can debug processes by name instead of process ID if your target has the
22361@code{pidof} utility:
22362
22363@smallexample
2d717e4f 22364target> gdbserver --attach @var{comm} `pidof @var{program}`
b1fe9455
DJ
22365@end smallexample
22366
f822c95b 22367In case more than one copy of @var{program} is running, or @var{program}
b1fe9455
DJ
22368has multiple threads, most versions of @code{pidof} support the
22369@code{-s} option to only return the first process ID.
22370
03f2bd59
JK
22371@subsubsection TCP port allocation lifecycle of @code{gdbserver}
22372
19d9d4ef
DB
22373This section applies only when @code{gdbserver} is run to listen on a TCP
22374port.
03f2bd59
JK
22375
22376@code{gdbserver} normally terminates after all of its debugged processes have
22377terminated in @kbd{target remote} mode. On the other hand, for @kbd{target
22378extended-remote}, @code{gdbserver} stays running even with no processes left.
22379@value{GDBN} normally terminates the spawned debugged process on its exit,
22380which normally also terminates @code{gdbserver} in the @kbd{target remote}
22381mode. Therefore, when the connection drops unexpectedly, and @value{GDBN}
22382cannot ask @code{gdbserver} to kill its debugged processes, @code{gdbserver}
22383stays running even in the @kbd{target remote} mode.
22384
22385When @code{gdbserver} stays running, @value{GDBN} can connect to it again later.
22386Such reconnecting is useful for features like @ref{disconnected tracing}. For
22387completeness, at most one @value{GDBN} can be connected at a time.
22388
22389@cindex @option{--once}, @code{gdbserver} option
22390By default, @code{gdbserver} keeps the listening TCP port open, so that
6e8c5661 22391subsequent connections are possible. However, if you start @code{gdbserver}
03f2bd59
JK
22392with the @option{--once} option, it will stop listening for any further
22393connection attempts after connecting to the first @value{GDBN} session. This
22394means no further connections to @code{gdbserver} will be possible after the
22395first one. It also means @code{gdbserver} will terminate after the first
22396connection with remote @value{GDBN} has closed, even for unexpectedly closed
22397connections and even in the @kbd{target extended-remote} mode. The
22398@option{--once} option allows reusing the same port number for connecting to
22399multiple instances of @code{gdbserver} running on the same host, since each
22400instance closes its port after the first connection.
2d717e4f 22401
87ce2a04 22402@anchor{Other Command-Line Arguments for gdbserver}
2d717e4f
DJ
22403@subsubsection Other Command-Line Arguments for @code{gdbserver}
22404
19d9d4ef
DB
22405You can use the @option{--multi} option to start @code{gdbserver} without
22406specifying a program to debug or a process to attach to. Then you can
22407attach in @code{target extended-remote} mode and run or attach to a
22408program. For more information,
22409@pxref{--multi Option in Types of Remote Connnections}.
22410
d9b1a651 22411@cindex @option{--debug}, @code{gdbserver} option
62709adf 22412The @option{--debug} option tells @code{gdbserver} to display extra
d9b1a651
EZ
22413status information about the debugging process.
22414@cindex @option{--remote-debug}, @code{gdbserver} option
22415The @option{--remote-debug} option tells @code{gdbserver} to display
aeb2e706
AH
22416remote protocol debug output.
22417@cindex @option{--debug-file}, @code{gdbserver} option
22418@cindex @code{gdbserver}, send all debug output to a single file
22419The @option{--debug-file=@var{filename}} option tells @code{gdbserver} to
22420write any debug output to the given @var{filename}. These options are intended
22421for @code{gdbserver} development and for bug reports to the developers.
2d717e4f 22422
87ce2a04
DE
22423@cindex @option{--debug-format}, @code{gdbserver} option
22424The @option{--debug-format=option1[,option2,...]} option tells
22425@code{gdbserver} to include additional information in each output.
22426Possible options are:
22427
22428@table @code
22429@item none
22430Turn off all extra information in debugging output.
22431@item all
22432Turn on all extra information in debugging output.
22433@item timestamps
22434Include a timestamp in each line of debugging output.
22435@end table
22436
22437Options are processed in order. Thus, for example, if @option{none}
22438appears last then no additional information is added to debugging output.
22439
d9b1a651 22440@cindex @option{--wrapper}, @code{gdbserver} option
ccd213ac
DJ
22441The @option{--wrapper} option specifies a wrapper to launch programs
22442for debugging. The option should be followed by the name of the
22443wrapper, then any command-line arguments to pass to the wrapper, then
22444@kbd{--} indicating the end of the wrapper arguments.
22445
22446@code{gdbserver} runs the specified wrapper program with a combined
22447command line including the wrapper arguments, then the name of the
22448program to debug, then any arguments to the program. The wrapper
22449runs until it executes your program, and then @value{GDBN} gains control.
22450
22451You can use any program that eventually calls @code{execve} with
22452its arguments as a wrapper. Several standard Unix utilities do
22453this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
22454with @code{exec "$@@"} will also work.
22455
22456For example, you can use @code{env} to pass an environment variable to
22457the debugged program, without setting the variable in @code{gdbserver}'s
22458environment:
22459
22460@smallexample
22461$ gdbserver --wrapper env LD_PRELOAD=libtest.so -- :2222 ./testprog
22462@end smallexample
22463
6d580b63
YQ
22464@cindex @option{--selftest}
22465The @option{--selftest} option runs the self tests in @code{gdbserver}:
22466
22467@smallexample
22468$ gdbserver --selftest
22469Ran 2 unit tests, 0 failed
22470@end smallexample
22471
22472These tests are disabled in release.
2d717e4f
DJ
22473@subsection Connecting to @code{gdbserver}
22474
19d9d4ef
DB
22475The basic procedure for connecting to the remote target is:
22476@itemize
2d717e4f 22477
19d9d4ef
DB
22478@item
22479Run @value{GDBN} on the host system.
f822c95b 22480
19d9d4ef
DB
22481@item
22482Make sure you have the necessary symbol files
22483(@pxref{Host and target files}).
22484Load symbols for your application using the @code{file} command before you
22485connect. Use @code{set sysroot} to locate target libraries (unless your
22486@value{GDBN} was compiled with the correct sysroot using
22487@code{--with-sysroot}).
f822c95b 22488
19d9d4ef 22489@item
79a6e687 22490Connect to your target (@pxref{Connecting,,Connecting to a Remote Target}).
6f05cf9f 22491For TCP connections, you must start up @code{gdbserver} prior to using
19d9d4ef 22492the @code{target} command. Otherwise you may get an error whose
6f05cf9f 22493text depends on the host system, but which usually looks something like
2d717e4f 22494@samp{Connection refused}. Don't use the @code{load}
19d9d4ef
DB
22495command in @value{GDBN} when using @code{target remote} mode, since the
22496program is already on the target.
22497
22498@end itemize
07f31aa6 22499
19d9d4ef 22500@anchor{Monitor Commands for gdbserver}
79a6e687 22501@subsection Monitor Commands for @code{gdbserver}
c74d0ad8
DJ
22502@cindex monitor commands, for @code{gdbserver}
22503
22504During a @value{GDBN} session using @code{gdbserver}, you can use the
22505@code{monitor} command to send special requests to @code{gdbserver}.
2d717e4f 22506Here are the available commands.
c74d0ad8
DJ
22507
22508@table @code
22509@item monitor help
22510List the available monitor commands.
22511
22512@item monitor set debug 0
22513@itemx monitor set debug 1
22514Disable or enable general debugging messages.
22515
22516@item monitor set remote-debug 0
22517@itemx monitor set remote-debug 1
22518Disable or enable specific debugging messages associated with the remote
22519protocol (@pxref{Remote Protocol}).
22520
aeb2e706
AH
22521@item monitor set debug-file filename
22522@itemx monitor set debug-file
22523Send any debug output to the given file, or to stderr.
22524
87ce2a04
DE
22525@item monitor set debug-format option1@r{[},option2,...@r{]}
22526Specify additional text to add to debugging messages.
22527Possible options are:
22528
22529@table @code
22530@item none
22531Turn off all extra information in debugging output.
22532@item all
22533Turn on all extra information in debugging output.
22534@item timestamps
22535Include a timestamp in each line of debugging output.
22536@end table
22537
22538Options are processed in order. Thus, for example, if @option{none}
22539appears last then no additional information is added to debugging output.
22540
cdbfd419
PP
22541@item monitor set libthread-db-search-path [PATH]
22542@cindex gdbserver, search path for @code{libthread_db}
22543When this command is issued, @var{path} is a colon-separated list of
22544directories to search for @code{libthread_db} (@pxref{Threads,,set
22545libthread-db-search-path}). If you omit @var{path},
84e578fb 22546@samp{libthread-db-search-path} will be reset to its default value.
cdbfd419 22547
98a5dd13
DE
22548The special entry @samp{$pdir} for @samp{libthread-db-search-path} is
22549not supported in @code{gdbserver}.
22550
2d717e4f
DJ
22551@item monitor exit
22552Tell gdbserver to exit immediately. This command should be followed by
22553@code{disconnect} to close the debugging session. @code{gdbserver} will
22554detach from any attached processes and kill any processes it created.
22555Use @code{monitor exit} to terminate @code{gdbserver} at the end
22556of a multi-process mode debug session.
22557
c74d0ad8
DJ
22558@end table
22559
fa593d66
PA
22560@subsection Tracepoints support in @code{gdbserver}
22561@cindex tracepoints support in @code{gdbserver}
22562
0fb4aa4b
PA
22563On some targets, @code{gdbserver} supports tracepoints, fast
22564tracepoints and static tracepoints.
fa593d66 22565
0fb4aa4b 22566For fast or static tracepoints to work, a special library called the
fa593d66
PA
22567@dfn{in-process agent} (IPA), must be loaded in the inferior process.
22568This library is built and distributed as an integral part of
0fb4aa4b
PA
22569@code{gdbserver}. In addition, support for static tracepoints
22570requires building the in-process agent library with static tracepoints
22571support. At present, the UST (LTTng Userspace Tracer,
22572@url{http://lttng.org/ust}) tracing engine is supported. This support
22573is automatically available if UST development headers are found in the
22574standard include path when @code{gdbserver} is built, or if
22575@code{gdbserver} was explicitly configured using @option{--with-ust}
22576to point at such headers. You can explicitly disable the support
22577using @option{--with-ust=no}.
fa593d66
PA
22578
22579There are several ways to load the in-process agent in your program:
22580
22581@table @code
22582@item Specifying it as dependency at link time
22583
22584You can link your program dynamically with the in-process agent
22585library. On most systems, this is accomplished by adding
22586@code{-linproctrace} to the link command.
22587
22588@item Using the system's preloading mechanisms
22589
22590You can force loading the in-process agent at startup time by using
22591your system's support for preloading shared libraries. Many Unixes
22592support the concept of preloading user defined libraries. In most
22593cases, you do that by specifying @code{LD_PRELOAD=libinproctrace.so}
22594in the environment. See also the description of @code{gdbserver}'s
22595@option{--wrapper} command line option.
22596
22597@item Using @value{GDBN} to force loading the agent at run time
22598
22599On some systems, you can force the inferior to load a shared library,
22600by calling a dynamic loader function in the inferior that takes care
22601of dynamically looking up and loading a shared library. On most Unix
22602systems, the function is @code{dlopen}. You'll use the @code{call}
22603command for that. For example:
22604
22605@smallexample
22606(@value{GDBP}) call dlopen ("libinproctrace.so", ...)
22607@end smallexample
22608
22609Note that on most Unix systems, for the @code{dlopen} function to be
22610available, the program needs to be linked with @code{-ldl}.
22611@end table
22612
22613On systems that have a userspace dynamic loader, like most Unix
22614systems, when you connect to @code{gdbserver} using @code{target
22615remote}, you'll find that the program is stopped at the dynamic
22616loader's entry point, and no shared library has been loaded in the
22617program's address space yet, including the in-process agent. In that
0fb4aa4b
PA
22618case, before being able to use any of the fast or static tracepoints
22619features, you need to let the loader run and load the shared
22620libraries. The simplest way to do that is to run the program to the
22621main procedure. E.g., if debugging a C or C@t{++} program, start
fa593d66
PA
22622@code{gdbserver} like so:
22623
22624@smallexample
22625$ gdbserver :9999 myprogram
22626@end smallexample
22627
22628Start GDB and connect to @code{gdbserver} like so, and run to main:
22629
22630@smallexample
22631$ gdb myprogram
22632(@value{GDBP}) target remote myhost:9999
226330x00007f215893ba60 in ?? () from /lib64/ld-linux-x86-64.so.2
22634(@value{GDBP}) b main
22635(@value{GDBP}) continue
22636@end smallexample
22637
22638The in-process tracing agent library should now be loaded into the
22639process; you can confirm it with the @code{info sharedlibrary}
22640command, which will list @file{libinproctrace.so} as loaded in the
0fb4aa4b
PA
22641process. You are now ready to install fast tracepoints, list static
22642tracepoint markers, probe static tracepoints markers, and start
fa593d66
PA
22643tracing.
22644
79a6e687
BW
22645@node Remote Configuration
22646@section Remote Configuration
501eef12 22647
9c16f35a
EZ
22648@kindex set remote
22649@kindex show remote
22650This section documents the configuration options available when
22651debugging remote programs. For the options related to the File I/O
fc320d37 22652extensions of the remote protocol, see @ref{system,
9c16f35a 22653system-call-allowed}.
501eef12
AC
22654
22655@table @code
9c16f35a 22656@item set remoteaddresssize @var{bits}
d3e8051b 22657@cindex address size for remote targets
9c16f35a
EZ
22658@cindex bits in remote address
22659Set the maximum size of address in a memory packet to the specified
22660number of bits. @value{GDBN} will mask off the address bits above
22661that number, when it passes addresses to the remote target. The
22662default value is the number of bits in the target's address.
22663
22664@item show remoteaddresssize
22665Show the current value of remote address size in bits.
22666
0d12017b 22667@item set serial baud @var{n}
9c16f35a
EZ
22668@cindex baud rate for remote targets
22669Set the baud rate for the remote serial I/O to @var{n} baud. The
22670value is used to set the speed of the serial port used for debugging
22671remote targets.
22672
0d12017b 22673@item show serial baud
9c16f35a
EZ
22674Show the current speed of the remote connection.
22675
236af5e3
YG
22676@item set serial parity @var{parity}
22677Set the parity for the remote serial I/O. Supported values of @var{parity} are:
22678@code{even}, @code{none}, and @code{odd}. The default is @code{none}.
22679
22680@item show serial parity
22681Show the current parity of the serial port.
22682
9c16f35a
EZ
22683@item set remotebreak
22684@cindex interrupt remote programs
22685@cindex BREAK signal instead of Ctrl-C
9a6253be 22686@anchor{set remotebreak}
9c16f35a 22687If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
c8aa23ab 22688when you type @kbd{Ctrl-c} to interrupt the program running
9a7a1b36 22689on the remote. If set to off, @value{GDBN} sends the @samp{Ctrl-C}
9c16f35a
EZ
22690character instead. The default is off, since most remote systems
22691expect to see @samp{Ctrl-C} as the interrupt signal.
22692
22693@item show remotebreak
22694Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
22695interrupt the remote program.
22696
23776285
MR
22697@item set remoteflow on
22698@itemx set remoteflow off
22699@kindex set remoteflow
22700Enable or disable hardware flow control (@code{RTS}/@code{CTS})
22701on the serial port used to communicate to the remote target.
22702
22703@item show remoteflow
22704@kindex show remoteflow
22705Show the current setting of hardware flow control.
22706
9c16f35a
EZ
22707@item set remotelogbase @var{base}
22708Set the base (a.k.a.@: radix) of logging serial protocol
22709communications to @var{base}. Supported values of @var{base} are:
22710@code{ascii}, @code{octal}, and @code{hex}. The default is
22711@code{ascii}.
22712
22713@item show remotelogbase
22714Show the current setting of the radix for logging remote serial
22715protocol.
22716
22717@item set remotelogfile @var{file}
22718@cindex record serial communications on file
22719Record remote serial communications on the named @var{file}. The
22720default is not to record at all.
22721
2d8b6830 22722@item show remotelogfile
9c16f35a
EZ
22723Show the current setting of the file name on which to record the
22724serial communications.
22725
22726@item set remotetimeout @var{num}
22727@cindex timeout for serial communications
22728@cindex remote timeout
22729Set the timeout limit to wait for the remote target to respond to
22730@var{num} seconds. The default is 2 seconds.
22731
22732@item show remotetimeout
22733Show the current number of seconds to wait for the remote target
22734responses.
22735
22736@cindex limit hardware breakpoints and watchpoints
22737@cindex remote target, limit break- and watchpoints
501eef12
AC
22738@anchor{set remote hardware-watchpoint-limit}
22739@anchor{set remote hardware-breakpoint-limit}
22740@item set remote hardware-watchpoint-limit @var{limit}
22741@itemx set remote hardware-breakpoint-limit @var{limit}
055303e2
AB
22742Restrict @value{GDBN} to using @var{limit} remote hardware watchpoints
22743or breakpoints. The @var{limit} can be set to 0 to disable hardware
22744watchpoints or breakpoints, and @code{unlimited} for unlimited
22745watchpoints or breakpoints.
22746
22747@item show remote hardware-watchpoint-limit
22748@itemx show remote hardware-breakpoint-limit
22749Show the current limit for the number of hardware watchpoints or
22750breakpoints that @value{GDBN} can use.
2d717e4f 22751
480a3f21
PW
22752@cindex limit hardware watchpoints length
22753@cindex remote target, limit watchpoints length
22754@anchor{set remote hardware-watchpoint-length-limit}
22755@item set remote hardware-watchpoint-length-limit @var{limit}
055303e2
AB
22756Restrict @value{GDBN} to using @var{limit} bytes for the maximum
22757length of a remote hardware watchpoint. A @var{limit} of 0 disables
22758hardware watchpoints and @code{unlimited} allows watchpoints of any
22759length.
480a3f21
PW
22760
22761@item show remote hardware-watchpoint-length-limit
22762Show the current limit (in bytes) of the maximum length of
22763a remote hardware watchpoint.
22764
2d717e4f
DJ
22765@item set remote exec-file @var{filename}
22766@itemx show remote exec-file
22767@anchor{set remote exec-file}
22768@cindex executable file, for remote target
22769Select the file used for @code{run} with @code{target
22770extended-remote}. This should be set to a filename valid on the
22771target system. If it is not set, the target will use a default
22772filename (e.g.@: the last program run).
84603566 22773
9a7071a8
JB
22774@item set remote interrupt-sequence
22775@cindex interrupt remote programs
22776@cindex select Ctrl-C, BREAK or BREAK-g
22777Allow the user to select one of @samp{Ctrl-C}, a @code{BREAK} or
22778@samp{BREAK-g} as the
22779sequence to the remote target in order to interrupt the execution.
22780@samp{Ctrl-C} is a default. Some system prefers @code{BREAK} which
22781is high level of serial line for some certain time.
22782Linux kernel prefers @samp{BREAK-g}, a.k.a Magic SysRq g.
22783It is @code{BREAK} signal followed by character @code{g}.
22784
22785@item show interrupt-sequence
22786Show which of @samp{Ctrl-C}, @code{BREAK} or @code{BREAK-g}
22787is sent by @value{GDBN} to interrupt the remote program.
22788@code{BREAK-g} is BREAK signal followed by @code{g} and
22789also known as Magic SysRq g.
22790
22791@item set remote interrupt-on-connect
22792@cindex send interrupt-sequence on start
22793Specify whether interrupt-sequence is sent to remote target when
22794@value{GDBN} connects to it. This is mostly needed when you debug
22795Linux kernel. Linux kernel expects @code{BREAK} followed by @code{g}
22796which is known as Magic SysRq g in order to connect @value{GDBN}.
22797
22798@item show interrupt-on-connect
22799Show whether interrupt-sequence is sent
22800to remote target when @value{GDBN} connects to it.
22801
84603566
SL
22802@kindex set tcp
22803@kindex show tcp
22804@item set tcp auto-retry on
22805@cindex auto-retry, for remote TCP target
22806Enable auto-retry for remote TCP connections. This is useful if the remote
22807debugging agent is launched in parallel with @value{GDBN}; there is a race
22808condition because the agent may not become ready to accept the connection
22809before @value{GDBN} attempts to connect. When auto-retry is
22810enabled, if the initial attempt to connect fails, @value{GDBN} reattempts
22811to establish the connection using the timeout specified by
22812@code{set tcp connect-timeout}.
22813
22814@item set tcp auto-retry off
22815Do not auto-retry failed TCP connections.
22816
22817@item show tcp auto-retry
22818Show the current auto-retry setting.
22819
22820@item set tcp connect-timeout @var{seconds}
f81d1120 22821@itemx set tcp connect-timeout unlimited
84603566
SL
22822@cindex connection timeout, for remote TCP target
22823@cindex timeout, for remote target connection
22824Set the timeout for establishing a TCP connection to the remote target to
22825@var{seconds}. The timeout affects both polling to retry failed connections
22826(enabled by @code{set tcp auto-retry on}) and waiting for connections
22827that are merely slow to complete, and represents an approximate cumulative
f81d1120
PA
22828value. If @var{seconds} is @code{unlimited}, there is no timeout and
22829@value{GDBN} will keep attempting to establish a connection forever,
22830unless interrupted with @kbd{Ctrl-c}. The default is 15 seconds.
84603566
SL
22831
22832@item show tcp connect-timeout
22833Show the current connection timeout setting.
501eef12
AC
22834@end table
22835
427c3a89
DJ
22836@cindex remote packets, enabling and disabling
22837The @value{GDBN} remote protocol autodetects the packets supported by
22838your debugging stub. If you need to override the autodetection, you
22839can use these commands to enable or disable individual packets. Each
22840packet can be set to @samp{on} (the remote target supports this
22841packet), @samp{off} (the remote target does not support this packet),
22842or @samp{auto} (detect remote target support for this packet). They
22843all default to @samp{auto}. For more information about each packet,
22844see @ref{Remote Protocol}.
22845
22846During normal use, you should not have to use any of these commands.
22847If you do, that may be a bug in your remote debugging stub, or a bug
22848in @value{GDBN}. You may want to report the problem to the
22849@value{GDBN} developers.
22850
cfa9d6d9
DJ
22851For each packet @var{name}, the command to enable or disable the
22852packet is @code{set remote @var{name}-packet}. The available settings
22853are:
427c3a89 22854
cfa9d6d9 22855@multitable @columnfractions 0.28 0.32 0.25
427c3a89
DJ
22856@item Command Name
22857@tab Remote Packet
22858@tab Related Features
22859
cfa9d6d9 22860@item @code{fetch-register}
427c3a89
DJ
22861@tab @code{p}
22862@tab @code{info registers}
22863
cfa9d6d9 22864@item @code{set-register}
427c3a89
DJ
22865@tab @code{P}
22866@tab @code{set}
22867
cfa9d6d9 22868@item @code{binary-download}
427c3a89
DJ
22869@tab @code{X}
22870@tab @code{load}, @code{set}
22871
cfa9d6d9 22872@item @code{read-aux-vector}
427c3a89
DJ
22873@tab @code{qXfer:auxv:read}
22874@tab @code{info auxv}
22875
cfa9d6d9 22876@item @code{symbol-lookup}
427c3a89
DJ
22877@tab @code{qSymbol}
22878@tab Detecting multiple threads
22879
2d717e4f
DJ
22880@item @code{attach}
22881@tab @code{vAttach}
22882@tab @code{attach}
22883
cfa9d6d9 22884@item @code{verbose-resume}
427c3a89
DJ
22885@tab @code{vCont}
22886@tab Stepping or resuming multiple threads
22887
2d717e4f
DJ
22888@item @code{run}
22889@tab @code{vRun}
22890@tab @code{run}
22891
cfa9d6d9 22892@item @code{software-breakpoint}
427c3a89
DJ
22893@tab @code{Z0}
22894@tab @code{break}
22895
cfa9d6d9 22896@item @code{hardware-breakpoint}
427c3a89
DJ
22897@tab @code{Z1}
22898@tab @code{hbreak}
22899
cfa9d6d9 22900@item @code{write-watchpoint}
427c3a89
DJ
22901@tab @code{Z2}
22902@tab @code{watch}
22903
cfa9d6d9 22904@item @code{read-watchpoint}
427c3a89
DJ
22905@tab @code{Z3}
22906@tab @code{rwatch}
22907
cfa9d6d9 22908@item @code{access-watchpoint}
427c3a89
DJ
22909@tab @code{Z4}
22910@tab @code{awatch}
22911
c78fa86a
GB
22912@item @code{pid-to-exec-file}
22913@tab @code{qXfer:exec-file:read}
22914@tab @code{attach}, @code{run}
22915
cfa9d6d9
DJ
22916@item @code{target-features}
22917@tab @code{qXfer:features:read}
22918@tab @code{set architecture}
22919
22920@item @code{library-info}
22921@tab @code{qXfer:libraries:read}
22922@tab @code{info sharedlibrary}
22923
22924@item @code{memory-map}
22925@tab @code{qXfer:memory-map:read}
22926@tab @code{info mem}
22927
0fb4aa4b
PA
22928@item @code{read-sdata-object}
22929@tab @code{qXfer:sdata:read}
22930@tab @code{print $_sdata}
22931
4aa995e1
PA
22932@item @code{read-siginfo-object}
22933@tab @code{qXfer:siginfo:read}
22934@tab @code{print $_siginfo}
22935
22936@item @code{write-siginfo-object}
22937@tab @code{qXfer:siginfo:write}
22938@tab @code{set $_siginfo}
22939
dc146f7c
VP
22940@item @code{threads}
22941@tab @code{qXfer:threads:read}
22942@tab @code{info threads}
22943
cfa9d6d9 22944@item @code{get-thread-local-@*storage-address}
427c3a89
DJ
22945@tab @code{qGetTLSAddr}
22946@tab Displaying @code{__thread} variables
22947
711e434b
PM
22948@item @code{get-thread-information-block-address}
22949@tab @code{qGetTIBAddr}
22950@tab Display MS-Windows Thread Information Block.
22951
08388c79
DE
22952@item @code{search-memory}
22953@tab @code{qSearch:memory}
22954@tab @code{find}
22955
427c3a89
DJ
22956@item @code{supported-packets}
22957@tab @code{qSupported}
22958@tab Remote communications parameters
22959
82075af2
JS
22960@item @code{catch-syscalls}
22961@tab @code{QCatchSyscalls}
22962@tab @code{catch syscall}
22963
cfa9d6d9 22964@item @code{pass-signals}
89be2091
DJ
22965@tab @code{QPassSignals}
22966@tab @code{handle @var{signal}}
22967
9b224c5e
PA
22968@item @code{program-signals}
22969@tab @code{QProgramSignals}
22970@tab @code{handle @var{signal}}
22971
a6b151f1
DJ
22972@item @code{hostio-close-packet}
22973@tab @code{vFile:close}
22974@tab @code{remote get}, @code{remote put}
22975
22976@item @code{hostio-open-packet}
22977@tab @code{vFile:open}
22978@tab @code{remote get}, @code{remote put}
22979
22980@item @code{hostio-pread-packet}
22981@tab @code{vFile:pread}
22982@tab @code{remote get}, @code{remote put}
22983
22984@item @code{hostio-pwrite-packet}
22985@tab @code{vFile:pwrite}
22986@tab @code{remote get}, @code{remote put}
22987
22988@item @code{hostio-unlink-packet}
22989@tab @code{vFile:unlink}
22990@tab @code{remote delete}
a6f3e723 22991
b9e7b9c3
UW
22992@item @code{hostio-readlink-packet}
22993@tab @code{vFile:readlink}
22994@tab Host I/O
22995
0a93529c
GB
22996@item @code{hostio-fstat-packet}
22997@tab @code{vFile:fstat}
22998@tab Host I/O
22999
15a201c8
GB
23000@item @code{hostio-setfs-packet}
23001@tab @code{vFile:setfs}
23002@tab Host I/O
23003
a6f3e723
SL
23004@item @code{noack-packet}
23005@tab @code{QStartNoAckMode}
23006@tab Packet acknowledgment
07e059b5
VP
23007
23008@item @code{osdata}
23009@tab @code{qXfer:osdata:read}
23010@tab @code{info os}
0b16c5cf
PA
23011
23012@item @code{query-attached}
23013@tab @code{qAttached}
23014@tab Querying remote process attach state.
b3b9301e 23015
a46c1e42
PA
23016@item @code{trace-buffer-size}
23017@tab @code{QTBuffer:size}
23018@tab @code{set trace-buffer-size}
23019
bd3eecc3
PA
23020@item @code{trace-status}
23021@tab @code{qTStatus}
23022@tab @code{tstatus}
23023
b3b9301e
PA
23024@item @code{traceframe-info}
23025@tab @code{qXfer:traceframe-info:read}
23026@tab Traceframe info
03583c20 23027
1e4d1764
YQ
23028@item @code{install-in-trace}
23029@tab @code{InstallInTrace}
23030@tab Install tracepoint in tracing
23031
03583c20
UW
23032@item @code{disable-randomization}
23033@tab @code{QDisableRandomization}
23034@tab @code{set disable-randomization}
83364271 23035
aefd8b33
SDJ
23036@item @code{startup-with-shell}
23037@tab @code{QStartupWithShell}
23038@tab @code{set startup-with-shell}
23039
0a2dde4a
SDJ
23040@item @code{environment-hex-encoded}
23041@tab @code{QEnvironmentHexEncoded}
23042@tab @code{set environment}
23043
23044@item @code{environment-unset}
23045@tab @code{QEnvironmentUnset}
23046@tab @code{unset environment}
23047
23048@item @code{environment-reset}
23049@tab @code{QEnvironmentReset}
23050@tab @code{Reset the inferior environment (i.e., unset user-set variables)}
23051
bc3b087d
SDJ
23052@item @code{set-working-dir}
23053@tab @code{QSetWorkingDir}
23054@tab @code{set cwd}
23055
83364271
LM
23056@item @code{conditional-breakpoints-packet}
23057@tab @code{Z0 and Z1}
23058@tab @code{Support for target-side breakpoint condition evaluation}
f7e6eed5 23059
73b8c1fd
PA
23060@item @code{multiprocess-extensions}
23061@tab @code{multiprocess extensions}
23062@tab Debug multiple processes and remote process PID awareness
23063
f7e6eed5
PA
23064@item @code{swbreak-feature}
23065@tab @code{swbreak stop reason}
23066@tab @code{break}
23067
23068@item @code{hwbreak-feature}
23069@tab @code{hwbreak stop reason}
23070@tab @code{hbreak}
23071
0d71eef5
DB
23072@item @code{fork-event-feature}
23073@tab @code{fork stop reason}
23074@tab @code{fork}
23075
23076@item @code{vfork-event-feature}
23077@tab @code{vfork stop reason}
23078@tab @code{vfork}
23079
b459a59b
DB
23080@item @code{exec-event-feature}
23081@tab @code{exec stop reason}
23082@tab @code{exec}
23083
65706a29
PA
23084@item @code{thread-events}
23085@tab @code{QThreadEvents}
23086@tab Tracking thread lifetime.
23087
f2faf941
PA
23088@item @code{no-resumed-stop-reply}
23089@tab @code{no resumed thread left stop reply}
23090@tab Tracking thread lifetime.
23091
427c3a89
DJ
23092@end multitable
23093
79a6e687
BW
23094@node Remote Stub
23095@section Implementing a Remote Stub
7a292a7a 23096
8e04817f
AC
23097@cindex debugging stub, example
23098@cindex remote stub, example
23099@cindex stub example, remote debugging
23100The stub files provided with @value{GDBN} implement the target side of the
23101communication protocol, and the @value{GDBN} side is implemented in the
23102@value{GDBN} source file @file{remote.c}. Normally, you can simply allow
23103these subroutines to communicate, and ignore the details. (If you're
23104implementing your own stub file, you can still ignore the details: start
23105with one of the existing stub files. @file{sparc-stub.c} is the best
23106organized, and therefore the easiest to read.)
23107
104c1213
JM
23108@cindex remote serial debugging, overview
23109To debug a program running on another machine (the debugging
23110@dfn{target} machine), you must first arrange for all the usual
23111prerequisites for the program to run by itself. For example, for a C
23112program, you need:
c906108c 23113
104c1213
JM
23114@enumerate
23115@item
23116A startup routine to set up the C runtime environment; these usually
23117have a name like @file{crt0}. The startup routine may be supplied by
23118your hardware supplier, or you may have to write your own.
96baa820 23119
5d161b24 23120@item
d4f3574e 23121A C subroutine library to support your program's
104c1213 23122subroutine calls, notably managing input and output.
96baa820 23123
104c1213
JM
23124@item
23125A way of getting your program to the other machine---for example, a
23126download program. These are often supplied by the hardware
23127manufacturer, but you may have to write your own from hardware
23128documentation.
23129@end enumerate
96baa820 23130
104c1213
JM
23131The next step is to arrange for your program to use a serial port to
23132communicate with the machine where @value{GDBN} is running (the @dfn{host}
23133machine). In general terms, the scheme looks like this:
96baa820 23134
104c1213
JM
23135@table @emph
23136@item On the host,
23137@value{GDBN} already understands how to use this protocol; when everything
23138else is set up, you can simply use the @samp{target remote} command
23139(@pxref{Targets,,Specifying a Debugging Target}).
23140
23141@item On the target,
23142you must link with your program a few special-purpose subroutines that
23143implement the @value{GDBN} remote serial protocol. The file containing these
23144subroutines is called a @dfn{debugging stub}.
23145
23146On certain remote targets, you can use an auxiliary program
23147@code{gdbserver} instead of linking a stub into your program.
79a6e687 23148@xref{Server,,Using the @code{gdbserver} Program}, for details.
104c1213 23149@end table
96baa820 23150
104c1213
JM
23151The debugging stub is specific to the architecture of the remote
23152machine; for example, use @file{sparc-stub.c} to debug programs on
23153@sc{sparc} boards.
96baa820 23154
104c1213
JM
23155@cindex remote serial stub list
23156These working remote stubs are distributed with @value{GDBN}:
96baa820 23157
104c1213
JM
23158@table @code
23159
23160@item i386-stub.c
41afff9a 23161@cindex @file{i386-stub.c}
104c1213
JM
23162@cindex Intel
23163@cindex i386
23164For Intel 386 and compatible architectures.
23165
23166@item m68k-stub.c
41afff9a 23167@cindex @file{m68k-stub.c}
104c1213
JM
23168@cindex Motorola 680x0
23169@cindex m680x0
23170For Motorola 680x0 architectures.
23171
23172@item sh-stub.c
41afff9a 23173@cindex @file{sh-stub.c}
172c2a43 23174@cindex Renesas
104c1213 23175@cindex SH
172c2a43 23176For Renesas SH architectures.
104c1213
JM
23177
23178@item sparc-stub.c
41afff9a 23179@cindex @file{sparc-stub.c}
104c1213
JM
23180@cindex Sparc
23181For @sc{sparc} architectures.
23182
23183@item sparcl-stub.c
41afff9a 23184@cindex @file{sparcl-stub.c}
104c1213
JM
23185@cindex Fujitsu
23186@cindex SparcLite
23187For Fujitsu @sc{sparclite} architectures.
23188
23189@end table
23190
23191The @file{README} file in the @value{GDBN} distribution may list other
23192recently added stubs.
23193
23194@menu
23195* Stub Contents:: What the stub can do for you
23196* Bootstrapping:: What you must do for the stub
23197* Debug Session:: Putting it all together
104c1213
JM
23198@end menu
23199
6d2ebf8b 23200@node Stub Contents
79a6e687 23201@subsection What the Stub Can Do for You
104c1213
JM
23202
23203@cindex remote serial stub
23204The debugging stub for your architecture supplies these three
23205subroutines:
23206
23207@table @code
23208@item set_debug_traps
4644b6e3 23209@findex set_debug_traps
104c1213
JM
23210@cindex remote serial stub, initialization
23211This routine arranges for @code{handle_exception} to run when your
2fb860fc
PA
23212program stops. You must call this subroutine explicitly in your
23213program's startup code.
104c1213
JM
23214
23215@item handle_exception
4644b6e3 23216@findex handle_exception
104c1213
JM
23217@cindex remote serial stub, main routine
23218This is the central workhorse, but your program never calls it
23219explicitly---the setup code arranges for @code{handle_exception} to
23220run when a trap is triggered.
23221
23222@code{handle_exception} takes control when your program stops during
23223execution (for example, on a breakpoint), and mediates communications
23224with @value{GDBN} on the host machine. This is where the communications
23225protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
d4f3574e 23226representative on the target machine. It begins by sending summary
104c1213
JM
23227information on the state of your program, then continues to execute,
23228retrieving and transmitting any information @value{GDBN} needs, until you
23229execute a @value{GDBN} command that makes your program resume; at that point,
23230@code{handle_exception} returns control to your own code on the target
5d161b24 23231machine.
104c1213
JM
23232
23233@item breakpoint
23234@cindex @code{breakpoint} subroutine, remote
23235Use this auxiliary subroutine to make your program contain a
23236breakpoint. Depending on the particular situation, this may be the only
23237way for @value{GDBN} to get control. For instance, if your target
23238machine has some sort of interrupt button, you won't need to call this;
23239pressing the interrupt button transfers control to
23240@code{handle_exception}---in effect, to @value{GDBN}. On some machines,
23241simply receiving characters on the serial port may also trigger a trap;
23242again, in that situation, you don't need to call @code{breakpoint} from
23243your own program---simply running @samp{target remote} from the host
5d161b24 23244@value{GDBN} session gets control.
104c1213
JM
23245
23246Call @code{breakpoint} if none of these is true, or if you simply want
23247to make certain your program stops at a predetermined point for the
23248start of your debugging session.
23249@end table
23250
6d2ebf8b 23251@node Bootstrapping
79a6e687 23252@subsection What You Must Do for the Stub
104c1213
JM
23253
23254@cindex remote stub, support routines
23255The debugging stubs that come with @value{GDBN} are set up for a particular
23256chip architecture, but they have no information about the rest of your
23257debugging target machine.
23258
23259First of all you need to tell the stub how to communicate with the
23260serial port.
23261
23262@table @code
23263@item int getDebugChar()
4644b6e3 23264@findex getDebugChar
104c1213
JM
23265Write this subroutine to read a single character from the serial port.
23266It may be identical to @code{getchar} for your target system; a
23267different name is used to allow you to distinguish the two if you wish.
23268
23269@item void putDebugChar(int)
4644b6e3 23270@findex putDebugChar
104c1213 23271Write this subroutine to write a single character to the serial port.
5d161b24 23272It may be identical to @code{putchar} for your target system; a
104c1213
JM
23273different name is used to allow you to distinguish the two if you wish.
23274@end table
23275
23276@cindex control C, and remote debugging
23277@cindex interrupting remote targets
23278If you want @value{GDBN} to be able to stop your program while it is
23279running, you need to use an interrupt-driven serial driver, and arrange
23280for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
23281character). That is the character which @value{GDBN} uses to tell the
23282remote system to stop.
23283
23284Getting the debugging target to return the proper status to @value{GDBN}
23285probably requires changes to the standard stub; one quick and dirty way
23286is to just execute a breakpoint instruction (the ``dirty'' part is that
23287@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
23288
23289Other routines you need to supply are:
23290
23291@table @code
23292@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
4644b6e3 23293@findex exceptionHandler
104c1213
JM
23294Write this function to install @var{exception_address} in the exception
23295handling tables. You need to do this because the stub does not have any
23296way of knowing what the exception handling tables on your target system
23297are like (for example, the processor's table might be in @sc{rom},
23298containing entries which point to a table in @sc{ram}).
697aa1b7 23299The @var{exception_number} specifies the exception which should be changed;
104c1213
JM
23300its meaning is architecture-dependent (for example, different numbers
23301might represent divide by zero, misaligned access, etc). When this
23302exception occurs, control should be transferred directly to
23303@var{exception_address}, and the processor state (stack, registers,
23304and so on) should be just as it is when a processor exception occurs. So if
23305you want to use a jump instruction to reach @var{exception_address}, it
23306should be a simple jump, not a jump to subroutine.
23307
23308For the 386, @var{exception_address} should be installed as an interrupt
23309gate so that interrupts are masked while the handler runs. The gate
23310should be at privilege level 0 (the most privileged level). The
23311@sc{sparc} and 68k stubs are able to mask interrupts themselves without
23312help from @code{exceptionHandler}.
23313
23314@item void flush_i_cache()
4644b6e3 23315@findex flush_i_cache
d4f3574e 23316On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
104c1213
JM
23317instruction cache, if any, on your target machine. If there is no
23318instruction cache, this subroutine may be a no-op.
23319
23320On target machines that have instruction caches, @value{GDBN} requires this
23321function to make certain that the state of your program is stable.
23322@end table
23323
23324@noindent
23325You must also make sure this library routine is available:
23326
23327@table @code
23328@item void *memset(void *, int, int)
4644b6e3 23329@findex memset
104c1213
JM
23330This is the standard library function @code{memset} that sets an area of
23331memory to a known value. If you have one of the free versions of
23332@code{libc.a}, @code{memset} can be found there; otherwise, you must
23333either obtain it from your hardware manufacturer, or write your own.
23334@end table
23335
23336If you do not use the GNU C compiler, you may need other standard
23337library subroutines as well; this varies from one stub to another,
23338but in general the stubs are likely to use any of the common library
e22ea452 23339subroutines which @code{@value{NGCC}} generates as inline code.
104c1213
JM
23340
23341
6d2ebf8b 23342@node Debug Session
79a6e687 23343@subsection Putting it All Together
104c1213
JM
23344
23345@cindex remote serial debugging summary
23346In summary, when your program is ready to debug, you must follow these
23347steps.
23348
23349@enumerate
23350@item
6d2ebf8b 23351Make sure you have defined the supporting low-level routines
79a6e687 23352(@pxref{Bootstrapping,,What You Must Do for the Stub}):
104c1213
JM
23353@display
23354@code{getDebugChar}, @code{putDebugChar},
23355@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
23356@end display
23357
23358@item
2fb860fc
PA
23359Insert these lines in your program's startup code, before the main
23360procedure is called:
104c1213 23361
474c8240 23362@smallexample
104c1213
JM
23363set_debug_traps();
23364breakpoint();
474c8240 23365@end smallexample
104c1213 23366
2fb860fc
PA
23367On some machines, when a breakpoint trap is raised, the hardware
23368automatically makes the PC point to the instruction after the
23369breakpoint. If your machine doesn't do that, you may need to adjust
23370@code{handle_exception} to arrange for it to return to the instruction
23371after the breakpoint on this first invocation, so that your program
23372doesn't keep hitting the initial breakpoint instead of making
23373progress.
23374
104c1213
JM
23375@item
23376For the 680x0 stub only, you need to provide a variable called
23377@code{exceptionHook}. Normally you just use:
23378
474c8240 23379@smallexample
104c1213 23380void (*exceptionHook)() = 0;
474c8240 23381@end smallexample
104c1213 23382
d4f3574e 23383@noindent
104c1213 23384but if before calling @code{set_debug_traps}, you set it to point to a
598ca718 23385function in your program, that function is called when
104c1213
JM
23386@code{@value{GDBN}} continues after stopping on a trap (for example, bus
23387error). The function indicated by @code{exceptionHook} is called with
23388one parameter: an @code{int} which is the exception number.
23389
23390@item
23391Compile and link together: your program, the @value{GDBN} debugging stub for
23392your target architecture, and the supporting subroutines.
23393
23394@item
23395Make sure you have a serial connection between your target machine and
23396the @value{GDBN} host, and identify the serial port on the host.
23397
23398@item
23399@c The "remote" target now provides a `load' command, so we should
23400@c document that. FIXME.
23401Download your program to your target machine (or get it there by
23402whatever means the manufacturer provides), and start it.
23403
23404@item
07f31aa6 23405Start @value{GDBN} on the host, and connect to the target
79a6e687 23406(@pxref{Connecting,,Connecting to a Remote Target}).
9db8d71f 23407
104c1213
JM
23408@end enumerate
23409
8e04817f
AC
23410@node Configurations
23411@chapter Configuration-Specific Information
104c1213 23412
8e04817f
AC
23413While nearly all @value{GDBN} commands are available for all native and
23414cross versions of the debugger, there are some exceptions. This chapter
23415describes things that are only available in certain configurations.
104c1213 23416
8e04817f
AC
23417There are three major categories of configurations: native
23418configurations, where the host and target are the same, embedded
23419operating system configurations, which are usually the same for several
23420different processor architectures, and bare embedded processors, which
23421are quite different from each other.
104c1213 23422
8e04817f
AC
23423@menu
23424* Native::
23425* Embedded OS::
23426* Embedded Processors::
23427* Architectures::
23428@end menu
104c1213 23429
8e04817f
AC
23430@node Native
23431@section Native
104c1213 23432
8e04817f
AC
23433This section describes details specific to particular native
23434configurations.
6cf7e474 23435
8e04817f 23436@menu
7561d450 23437* BSD libkvm Interface:: Debugging BSD kernel memory images
2d97a5d9 23438* Process Information:: Process information
8e04817f 23439* DJGPP Native:: Features specific to the DJGPP port
78c47bea 23440* Cygwin Native:: Features specific to the Cygwin port
14d6dd68 23441* Hurd Native:: Features specific to @sc{gnu} Hurd
a80b95ba 23442* Darwin:: Features specific to Darwin
e9076973 23443* FreeBSD:: Features specific to FreeBSD
8e04817f 23444@end menu
6cf7e474 23445
7561d450
MK
23446@node BSD libkvm Interface
23447@subsection BSD libkvm Interface
23448
23449@cindex libkvm
23450@cindex kernel memory image
23451@cindex kernel crash dump
23452
23453BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
23454interface that provides a uniform interface for accessing kernel virtual
23455memory images, including live systems and crash dumps. @value{GDBN}
23456uses this interface to allow you to debug live kernels and kernel crash
23457dumps on many native BSD configurations. This is implemented as a
23458special @code{kvm} debugging target. For debugging a live system, load
23459the currently running kernel into @value{GDBN} and connect to the
23460@code{kvm} target:
23461
23462@smallexample
23463(@value{GDBP}) @b{target kvm}
23464@end smallexample
23465
23466For debugging crash dumps, provide the file name of the crash dump as an
23467argument:
23468
23469@smallexample
23470(@value{GDBP}) @b{target kvm /var/crash/bsd.0}
23471@end smallexample
23472
23473Once connected to the @code{kvm} target, the following commands are
23474available:
23475
23476@table @code
23477@kindex kvm
23478@item kvm pcb
721c2651 23479Set current context from the @dfn{Process Control Block} (PCB) address.
7561d450
MK
23480
23481@item kvm proc
23482Set current context from proc address. This command isn't available on
23483modern FreeBSD systems.
23484@end table
23485
2d97a5d9
JB
23486@node Process Information
23487@subsection Process Information
60bf7e09
EZ
23488@cindex /proc
23489@cindex examine process image
23490@cindex process info via @file{/proc}
104c1213 23491
2d97a5d9
JB
23492Some operating systems provide interfaces to fetch additional
23493information about running processes beyond memory and per-thread
23494register state. If @value{GDBN} is configured for an operating system
23495with a supported interface, the command @code{info proc} is available
23496to report information about the process running your program, or about
23497any process running on your system.
451b7c33 23498
2d97a5d9
JB
23499One supported interface is a facility called @samp{/proc} that can be
23500used to examine the image of a running process using file-system
23501subroutines. This facility is supported on @sc{gnu}/Linux and Solaris
23502systems.
451b7c33 23503
aa8509b4
KR
23504On FreeBSD and NetBSD systems, system control nodes are used to query
23505process information.
2d97a5d9
JB
23506
23507In addition, some systems may provide additional process information
23508in core files. Note that a core file may include a subset of the
23509information available from a live process. Process information is
6b92c0d3 23510currently available from cores created on @sc{gnu}/Linux and FreeBSD
2d97a5d9 23511systems.
104c1213 23512
8e04817f
AC
23513@table @code
23514@kindex info proc
60bf7e09 23515@cindex process ID
8e04817f 23516@item info proc
60bf7e09 23517@itemx info proc @var{process-id}
73f1bd76 23518Summarize available information about a process. If a
60bf7e09
EZ
23519process ID is specified by @var{process-id}, display information about
23520that process; otherwise display information about the program being
23521debugged. The summary includes the debugged process ID, the command
23522line used to invoke it, its current working directory, and its
23523executable file's absolute file name.
23524
23525On some systems, @var{process-id} can be of the form
23526@samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
23527within a process. If the optional @var{pid} part is missing, it means
23528a thread from the process being debugged (the leading @samp{/} still
23529needs to be present, or else @value{GDBN} will interpret the number as
23530a process ID rather than a thread ID).
6cf7e474 23531
0c631110
TT
23532@item info proc cmdline
23533@cindex info proc cmdline
23534Show the original command line of the process. This command is
aa8509b4 23535supported on @sc{gnu}/Linux, FreeBSD and NetBSD.
0c631110
TT
23536
23537@item info proc cwd
23538@cindex info proc cwd
23539Show the current working directory of the process. This command is
aa8509b4 23540supported on @sc{gnu}/Linux, FreeBSD and NetBSD.
0c631110
TT
23541
23542@item info proc exe
23543@cindex info proc exe
2d97a5d9 23544Show the name of executable of the process. This command is supported
aa8509b4 23545on @sc{gnu}/Linux, FreeBSD and NetBSD.
0c631110 23546
8b113111
JB
23547@item info proc files
23548@cindex info proc files
23549Show the file descriptors open by the process. For each open file
23550descriptor, @value{GDBN} shows its number, type (file, directory,
23551character device, socket), file pointer offset, and the name of the
23552resource open on the descriptor. The resource name can be a file name
23553(for files, directories, and devices) or a protocol followed by socket
23554address (for network connections). This command is supported on
23555FreeBSD.
23556
23557This example shows the open file descriptors for a process using a
23558tty for standard input and output as well as two network sockets:
23559
23560@smallexample
23561(gdb) info proc files 22136
23562process 22136
23563Open files:
23564
23565 FD Type Offset Flags Name
23566 text file - r-------- /usr/bin/ssh
23567 ctty chr - rw------- /dev/pts/20
23568 cwd dir - r-------- /usr/home/john
23569 root dir - r-------- /
23570 0 chr 0x32933a4 rw------- /dev/pts/20
23571 1 chr 0x32933a4 rw------- /dev/pts/20
23572 2 chr 0x32933a4 rw------- /dev/pts/20
23573 3 socket 0x0 rw----n-- tcp4 10.0.1.2:53014 -> 10.0.1.10:22
23574 4 socket 0x0 rw------- unix stream:/tmp/ssh-FIt89oAzOn5f/agent.2456
23575@end smallexample
23576
8e04817f 23577@item info proc mappings
60bf7e09 23578@cindex memory address space mappings
73f1bd76 23579Report the memory address space ranges accessible in a process. On
aa8509b4
KR
23580Solaris, FreeBSD and NetBSD systems, each memory range includes information
23581on whether the process has read, write, or execute access rights to each
23582range. On @sc{gnu}/Linux, FreeBSD and NetBSD systems, each memory range
2d97a5d9 23583includes the object file which is mapped to that range.
60bf7e09
EZ
23584
23585@item info proc stat
23586@itemx info proc status
23587@cindex process detailed status information
2d97a5d9
JB
23588Show additional process-related information, including the user ID and
23589group ID; virtual memory usage; the signals that are pending, blocked,
23590and ignored; its TTY; its consumption of system and user time; its
23591stack size; its @samp{nice} value; etc. These commands are supported
aa8509b4 23592on @sc{gnu}/Linux, FreeBSD and NetBSD.
2d97a5d9
JB
23593
23594For @sc{gnu}/Linux systems, see the @samp{proc} man page for more
23595information (type @kbd{man 5 proc} from your shell prompt).
23596
aa8509b4
KR
23597For FreeBSD and NetBSD systems, @code{info proc stat} is an alias for
23598@code{info proc status}.
60bf7e09
EZ
23599
23600@item info proc all
23601Show all the information about the process described under all of the
23602above @code{info proc} subcommands.
23603
8e04817f
AC
23604@ignore
23605@comment These sub-options of 'info proc' were not included when
23606@comment procfs.c was re-written. Keep their descriptions around
23607@comment against the day when someone finds the time to put them back in.
23608@kindex info proc times
23609@item info proc times
23610Starting time, user CPU time, and system CPU time for your program and
23611its children.
6cf7e474 23612
8e04817f
AC
23613@kindex info proc id
23614@item info proc id
23615Report on the process IDs related to your program: its own process ID,
23616the ID of its parent, the process group ID, and the session ID.
8e04817f 23617@end ignore
721c2651
EZ
23618
23619@item set procfs-trace
23620@kindex set procfs-trace
23621@cindex @code{procfs} API calls
23622This command enables and disables tracing of @code{procfs} API calls.
23623
23624@item show procfs-trace
23625@kindex show procfs-trace
23626Show the current state of @code{procfs} API call tracing.
23627
23628@item set procfs-file @var{file}
23629@kindex set procfs-file
23630Tell @value{GDBN} to write @code{procfs} API trace to the named
23631@var{file}. @value{GDBN} appends the trace info to the previous
23632contents of the file. The default is to display the trace on the
23633standard output.
23634
23635@item show procfs-file
23636@kindex show procfs-file
23637Show the file to which @code{procfs} API trace is written.
23638
23639@item proc-trace-entry
23640@itemx proc-trace-exit
23641@itemx proc-untrace-entry
23642@itemx proc-untrace-exit
23643@kindex proc-trace-entry
23644@kindex proc-trace-exit
23645@kindex proc-untrace-entry
23646@kindex proc-untrace-exit
23647These commands enable and disable tracing of entries into and exits
23648from the @code{syscall} interface.
23649
23650@item info pidlist
23651@kindex info pidlist
23652@cindex process list, QNX Neutrino
23653For QNX Neutrino only, this command displays the list of all the
23654processes and all the threads within each process.
23655
23656@item info meminfo
23657@kindex info meminfo
23658@cindex mapinfo list, QNX Neutrino
23659For QNX Neutrino only, this command displays the list of all mapinfos.
8e04817f 23660@end table
104c1213 23661
8e04817f
AC
23662@node DJGPP Native
23663@subsection Features for Debugging @sc{djgpp} Programs
23664@cindex @sc{djgpp} debugging
23665@cindex native @sc{djgpp} debugging
23666@cindex MS-DOS-specific commands
104c1213 23667
514c4d71
EZ
23668@cindex DPMI
23669@sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
8e04817f
AC
23670MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
23671that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
23672top of real-mode DOS systems and their emulations.
104c1213 23673
8e04817f
AC
23674@value{GDBN} supports native debugging of @sc{djgpp} programs, and
23675defines a few commands specific to the @sc{djgpp} port. This
23676subsection describes those commands.
104c1213 23677
8e04817f
AC
23678@table @code
23679@kindex info dos
23680@item info dos
23681This is a prefix of @sc{djgpp}-specific commands which print
23682information about the target system and important OS structures.
f1251bdd 23683
8e04817f
AC
23684@kindex sysinfo
23685@cindex MS-DOS system info
23686@cindex free memory information (MS-DOS)
23687@item info dos sysinfo
23688This command displays assorted information about the underlying
23689platform: the CPU type and features, the OS version and flavor, the
23690DPMI version, and the available conventional and DPMI memory.
104c1213 23691
8e04817f
AC
23692@cindex GDT
23693@cindex LDT
23694@cindex IDT
23695@cindex segment descriptor tables
23696@cindex descriptor tables display
23697@item info dos gdt
23698@itemx info dos ldt
23699@itemx info dos idt
23700These 3 commands display entries from, respectively, Global, Local,
23701and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
23702tables are data structures which store a descriptor for each segment
23703that is currently in use. The segment's selector is an index into a
23704descriptor table; the table entry for that index holds the
23705descriptor's base address and limit, and its attributes and access
23706rights.
104c1213 23707
8e04817f
AC
23708A typical @sc{djgpp} program uses 3 segments: a code segment, a data
23709segment (used for both data and the stack), and a DOS segment (which
23710allows access to DOS/BIOS data structures and absolute addresses in
23711conventional memory). However, the DPMI host will usually define
23712additional segments in order to support the DPMI environment.
d4f3574e 23713
8e04817f
AC
23714@cindex garbled pointers
23715These commands allow to display entries from the descriptor tables.
23716Without an argument, all entries from the specified table are
23717displayed. An argument, which should be an integer expression, means
23718display a single entry whose index is given by the argument. For
23719example, here's a convenient way to display information about the
23720debugged program's data segment:
104c1213 23721
8e04817f
AC
23722@smallexample
23723@exdent @code{(@value{GDBP}) info dos ldt $ds}
23724@exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
23725@end smallexample
104c1213 23726
8e04817f
AC
23727@noindent
23728This comes in handy when you want to see whether a pointer is outside
23729the data segment's limit (i.e.@: @dfn{garbled}).
104c1213 23730
8e04817f
AC
23731@cindex page tables display (MS-DOS)
23732@item info dos pde
23733@itemx info dos pte
23734These two commands display entries from, respectively, the Page
23735Directory and the Page Tables. Page Directories and Page Tables are
23736data structures which control how virtual memory addresses are mapped
23737into physical addresses. A Page Table includes an entry for every
23738page of memory that is mapped into the program's address space; there
23739may be several Page Tables, each one holding up to 4096 entries. A
23740Page Directory has up to 4096 entries, one each for every Page Table
23741that is currently in use.
104c1213 23742
8e04817f
AC
23743Without an argument, @kbd{info dos pde} displays the entire Page
23744Directory, and @kbd{info dos pte} displays all the entries in all of
23745the Page Tables. An argument, an integer expression, given to the
23746@kbd{info dos pde} command means display only that entry from the Page
23747Directory table. An argument given to the @kbd{info dos pte} command
23748means display entries from a single Page Table, the one pointed to by
23749the specified entry in the Page Directory.
104c1213 23750
8e04817f
AC
23751@cindex direct memory access (DMA) on MS-DOS
23752These commands are useful when your program uses @dfn{DMA} (Direct
23753Memory Access), which needs physical addresses to program the DMA
23754controller.
104c1213 23755
8e04817f 23756These commands are supported only with some DPMI servers.
104c1213 23757
8e04817f
AC
23758@cindex physical address from linear address
23759@item info dos address-pte @var{addr}
23760This command displays the Page Table entry for a specified linear
514c4d71
EZ
23761address. The argument @var{addr} is a linear address which should
23762already have the appropriate segment's base address added to it,
23763because this command accepts addresses which may belong to @emph{any}
23764segment. For example, here's how to display the Page Table entry for
23765the page where a variable @code{i} is stored:
104c1213 23766
b383017d 23767@smallexample
8e04817f
AC
23768@exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
23769@exdent @code{Page Table entry for address 0x11a00d30:}
b383017d 23770@exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
8e04817f 23771@end smallexample
104c1213 23772
8e04817f
AC
23773@noindent
23774This says that @code{i} is stored at offset @code{0xd30} from the page
514c4d71 23775whose physical base address is @code{0x02698000}, and shows all the
8e04817f 23776attributes of that page.
104c1213 23777
8e04817f
AC
23778Note that you must cast the addresses of variables to a @code{char *},
23779since otherwise the value of @code{__djgpp_base_address}, the base
23780address of all variables and functions in a @sc{djgpp} program, will
23781be added using the rules of C pointer arithmetics: if @code{i} is
23782declared an @code{int}, @value{GDBN} will add 4 times the value of
23783@code{__djgpp_base_address} to the address of @code{i}.
104c1213 23784
8e04817f
AC
23785Here's another example, it displays the Page Table entry for the
23786transfer buffer:
104c1213 23787
8e04817f
AC
23788@smallexample
23789@exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
23790@exdent @code{Page Table entry for address 0x29110:}
23791@exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
23792@end smallexample
104c1213 23793
8e04817f
AC
23794@noindent
23795(The @code{+ 3} offset is because the transfer buffer's address is the
514c4d71
EZ
237963rd member of the @code{_go32_info_block} structure.) The output
23797clearly shows that this DPMI server maps the addresses in conventional
23798memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
23799linear (@code{0x29110}) addresses are identical.
104c1213 23800
8e04817f
AC
23801This command is supported only with some DPMI servers.
23802@end table
104c1213 23803
c45da7e6 23804@cindex DOS serial data link, remote debugging
a8f24a35
EZ
23805In addition to native debugging, the DJGPP port supports remote
23806debugging via a serial data link. The following commands are specific
23807to remote serial debugging in the DJGPP port of @value{GDBN}.
23808
23809@table @code
23810@kindex set com1base
23811@kindex set com1irq
23812@kindex set com2base
23813@kindex set com2irq
23814@kindex set com3base
23815@kindex set com3irq
23816@kindex set com4base
23817@kindex set com4irq
23818@item set com1base @var{addr}
23819This command sets the base I/O port address of the @file{COM1} serial
23820port.
23821
23822@item set com1irq @var{irq}
23823This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
23824for the @file{COM1} serial port.
23825
23826There are similar commands @samp{set com2base}, @samp{set com3irq},
23827etc.@: for setting the port address and the @code{IRQ} lines for the
23828other 3 COM ports.
23829
23830@kindex show com1base
23831@kindex show com1irq
23832@kindex show com2base
23833@kindex show com2irq
23834@kindex show com3base
23835@kindex show com3irq
23836@kindex show com4base
23837@kindex show com4irq
23838The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
23839display the current settings of the base address and the @code{IRQ}
23840lines used by the COM ports.
c45da7e6
EZ
23841
23842@item info serial
23843@kindex info serial
23844@cindex DOS serial port status
23845This command prints the status of the 4 DOS serial ports. For each
23846port, it prints whether it's active or not, its I/O base address and
23847IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
23848counts of various errors encountered so far.
a8f24a35
EZ
23849@end table
23850
23851
78c47bea 23852@node Cygwin Native
79a6e687 23853@subsection Features for Debugging MS Windows PE Executables
78c47bea
PM
23854@cindex MS Windows debugging
23855@cindex native Cygwin debugging
23856@cindex Cygwin-specific commands
23857
be448670 23858@value{GDBN} supports native debugging of MS Windows programs, including
cbb8f428
EZ
23859DLLs with and without symbolic debugging information.
23860
23861@cindex Ctrl-BREAK, MS-Windows
23862@cindex interrupt debuggee on MS-Windows
23863MS-Windows programs that call @code{SetConsoleMode} to switch off the
23864special meaning of the @samp{Ctrl-C} keystroke cannot be interrupted
23865by typing @kbd{C-c}. For this reason, @value{GDBN} on MS-Windows
23866supports @kbd{C-@key{BREAK}} as an alternative interrupt key
23867sequence, which can be used to interrupt the debuggee even if it
23868ignores @kbd{C-c}.
23869
23870There are various additional Cygwin-specific commands, described in
23871this section. Working with DLLs that have no debugging symbols is
23872described in @ref{Non-debug DLL Symbols}.
78c47bea
PM
23873
23874@table @code
23875@kindex info w32
23876@item info w32
db2e3e2e 23877This is a prefix of MS Windows-specific commands which print
78c47bea
PM
23878information about the target system and important OS structures.
23879
23880@item info w32 selector
23881This command displays information returned by
23882the Win32 API @code{GetThreadSelectorEntry} function.
23883It takes an optional argument that is evaluated to
23884a long value to give the information about this given selector.
23885Without argument, this command displays information
d3e8051b 23886about the six segment registers.
78c47bea 23887
711e434b
PM
23888@item info w32 thread-information-block
23889This command displays thread specific information stored in the
23890Thread Information Block (readable on the X86 CPU family using @code{$fs}
23891selector for 32-bit programs and @code{$gs} for 64-bit programs).
23892
463888ab
РИ
23893@kindex signal-event
23894@item signal-event @var{id}
23895This command signals an event with user-provided @var{id}. Used to resume
23896crashing process when attached to it using MS-Windows JIT debugging (AeDebug).
23897
23898To use it, create or edit the following keys in
23899@code{HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug} and/or
23900@code{HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\AeDebug}
23901(for x86_64 versions):
23902
23903@itemize @minus
23904@item
23905@code{Debugger} (REG_SZ) --- a command to launch the debugger.
23906Suggested command is: @code{@var{fully-qualified-path-to-gdb.exe} -ex
23907"attach %ld" -ex "signal-event %ld" -ex "continue"}.
23908
23909The first @code{%ld} will be replaced by the process ID of the
23910crashing process, the second @code{%ld} will be replaced by the ID of
23911the event that blocks the crashing process, waiting for @value{GDBN}
23912to attach.
23913
23914@item
23915@code{Auto} (REG_SZ) --- either @code{1} or @code{0}. @code{1} will
23916make the system run debugger specified by the Debugger key
23917automatically, @code{0} will cause a dialog box with ``OK'' and
23918``Cancel'' buttons to appear, which allows the user to either
23919terminate the crashing process (OK) or debug it (Cancel).
23920@end itemize
23921
be90c084 23922@kindex set cygwin-exceptions
e16b02ee
EZ
23923@cindex debugging the Cygwin DLL
23924@cindex Cygwin DLL, debugging
be90c084 23925@item set cygwin-exceptions @var{mode}
e16b02ee
EZ
23926If @var{mode} is @code{on}, @value{GDBN} will break on exceptions that
23927happen inside the Cygwin DLL. If @var{mode} is @code{off},
23928@value{GDBN} will delay recognition of exceptions, and may ignore some
23929exceptions which seem to be caused by internal Cygwin DLL
23930``bookkeeping''. This option is meant primarily for debugging the
23931Cygwin DLL itself; the default value is @code{off} to avoid annoying
23932@value{GDBN} users with false @code{SIGSEGV} signals.
be90c084
CF
23933
23934@kindex show cygwin-exceptions
23935@item show cygwin-exceptions
e16b02ee
EZ
23936Displays whether @value{GDBN} will break on exceptions that happen
23937inside the Cygwin DLL itself.
be90c084 23938
b383017d 23939@kindex set new-console
78c47bea 23940@item set new-console @var{mode}
b383017d 23941If @var{mode} is @code{on} the debuggee will
78c47bea 23942be started in a new console on next start.
e03e5e7b 23943If @var{mode} is @code{off}, the debuggee will
78c47bea
PM
23944be started in the same console as the debugger.
23945
23946@kindex show new-console
23947@item show new-console
23948Displays whether a new console is used
23949when the debuggee is started.
23950
23951@kindex set new-group
23952@item set new-group @var{mode}
23953This boolean value controls whether the debuggee should
23954start a new group or stay in the same group as the debugger.
23955This affects the way the Windows OS handles
c8aa23ab 23956@samp{Ctrl-C}.
78c47bea
PM
23957
23958@kindex show new-group
23959@item show new-group
23960Displays current value of new-group boolean.
23961
23962@kindex set debugevents
23963@item set debugevents
219eec71
EZ
23964This boolean value adds debug output concerning kernel events related
23965to the debuggee seen by the debugger. This includes events that
23966signal thread and process creation and exit, DLL loading and
23967unloading, console interrupts, and debugging messages produced by the
23968Windows @code{OutputDebugString} API call.
78c47bea
PM
23969
23970@kindex set debugexec
23971@item set debugexec
b383017d 23972This boolean value adds debug output concerning execute events
219eec71 23973(such as resume thread) seen by the debugger.
78c47bea
PM
23974
23975@kindex set debugexceptions
23976@item set debugexceptions
219eec71
EZ
23977This boolean value adds debug output concerning exceptions in the
23978debuggee seen by the debugger.
78c47bea
PM
23979
23980@kindex set debugmemory
23981@item set debugmemory
219eec71
EZ
23982This boolean value adds debug output concerning debuggee memory reads
23983and writes by the debugger.
78c47bea
PM
23984
23985@kindex set shell
23986@item set shell
23987This boolean values specifies whether the debuggee is called
23988via a shell or directly (default value is on).
23989
23990@kindex show shell
23991@item show shell
23992Displays if the debuggee will be started with a shell.
23993
23994@end table
23995
be448670 23996@menu
79a6e687 23997* Non-debug DLL Symbols:: Support for DLLs without debugging symbols
be448670
CF
23998@end menu
23999
79a6e687
BW
24000@node Non-debug DLL Symbols
24001@subsubsection Support for DLLs without Debugging Symbols
be448670
CF
24002@cindex DLLs with no debugging symbols
24003@cindex Minimal symbols and DLLs
24004
24005Very often on windows, some of the DLLs that your program relies on do
24006not include symbolic debugging information (for example,
db2e3e2e 24007@file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
be448670 24008symbols in a DLL, it relies on the minimal amount of symbolic
db2e3e2e 24009information contained in the DLL's export table. This section
be448670
CF
24010describes working with such symbols, known internally to @value{GDBN} as
24011``minimal symbols''.
24012
24013Note that before the debugged program has started execution, no DLLs
db2e3e2e 24014will have been loaded. The easiest way around this problem is simply to
be448670 24015start the program --- either by setting a breakpoint or letting the
95060284 24016program run once to completion.
be448670 24017
79a6e687 24018@subsubsection DLL Name Prefixes
be448670
CF
24019
24020In keeping with the naming conventions used by the Microsoft debugging
24021tools, DLL export symbols are made available with a prefix based on the
24022DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
24023also entered into the symbol table, so @code{CreateFileA} is often
99e008fe 24024sufficient. In some cases there will be name clashes within a program
be448670
CF
24025(particularly if the executable itself includes full debugging symbols)
24026necessitating the use of the fully qualified name when referring to the
99e008fe 24027contents of the DLL. Use single-quotes around the name to avoid the
be448670
CF
24028exclamation mark (``!'') being interpreted as a language operator.
24029
24030Note that the internal name of the DLL may be all upper-case, even
99e008fe 24031though the file name of the DLL is lower-case, or vice-versa. Since
be448670
CF
24032symbols within @value{GDBN} are @emph{case-sensitive} this may cause
24033some confusion. If in doubt, try the @code{info functions} and
0869d01b
NR
24034@code{info variables} commands or even @code{maint print msymbols}
24035(@pxref{Symbols}). Here's an example:
be448670
CF
24036
24037@smallexample
f7dc1244 24038(@value{GDBP}) info function CreateFileA
be448670
CF
24039All functions matching regular expression "CreateFileA":
24040
24041Non-debugging symbols:
240420x77e885f4 CreateFileA
240430x77e885f4 KERNEL32!CreateFileA
24044@end smallexample
24045
24046@smallexample
f7dc1244 24047(@value{GDBP}) info function !
be448670
CF
24048All functions matching regular expression "!":
24049
24050Non-debugging symbols:
240510x6100114c cygwin1!__assert
240520x61004034 cygwin1!_dll_crt0@@0
240530x61004240 cygwin1!dll_crt0(per_process *)
24054[etc...]
24055@end smallexample
24056
79a6e687 24057@subsubsection Working with Minimal Symbols
be448670
CF
24058
24059Symbols extracted from a DLL's export table do not contain very much
24060type information. All that @value{GDBN} can do is guess whether a symbol
24061refers to a function or variable depending on the linker section that
24062contains the symbol. Also note that the actual contents of the memory
24063contained in a DLL are not available unless the program is running. This
24064means that you cannot examine the contents of a variable or disassemble
24065a function within a DLL without a running program.
24066
24067Variables are generally treated as pointers and dereferenced
24068automatically. For this reason, it is often necessary to prefix a
24069variable name with the address-of operator (``&'') and provide explicit
24070type information in the command. Here's an example of the type of
24071problem:
24072
24073@smallexample
f7dc1244 24074(@value{GDBP}) print 'cygwin1!__argv'
d69cf9b2 24075'cygwin1!__argv' has unknown type; cast it to its declared type
be448670
CF
24076@end smallexample
24077
24078@smallexample
f7dc1244 24079(@value{GDBP}) x 'cygwin1!__argv'
d69cf9b2 24080'cygwin1!__argv' has unknown type; cast it to its declared type
be448670
CF
24081@end smallexample
24082
24083And two possible solutions:
24084
24085@smallexample
f7dc1244 24086(@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
be448670
CF
24087$2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
24088@end smallexample
24089
24090@smallexample
f7dc1244 24091(@value{GDBP}) x/2x &'cygwin1!__argv'
be448670 240920x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
f7dc1244 24093(@value{GDBP}) x/x 0x10021608
be448670 240940x10021608: 0x0022fd98
f7dc1244 24095(@value{GDBP}) x/s 0x0022fd98
be448670
CF
240960x22fd98: "/cygdrive/c/mydirectory/myprogram"
24097@end smallexample
24098
24099Setting a break point within a DLL is possible even before the program
24100starts execution. However, under these circumstances, @value{GDBN} can't
24101examine the initial instructions of the function in order to skip the
24102function's frame set-up code. You can work around this by using ``*&''
24103to set the breakpoint at a raw memory address:
24104
24105@smallexample
f7dc1244 24106(@value{GDBP}) break *&'python22!PyOS_Readline'
be448670
CF
24107Breakpoint 1 at 0x1e04eff0
24108@end smallexample
24109
24110The author of these extensions is not entirely convinced that setting a
24111break point within a shared DLL like @file{kernel32.dll} is completely
24112safe.
24113
14d6dd68 24114@node Hurd Native
79a6e687 24115@subsection Commands Specific to @sc{gnu} Hurd Systems
14d6dd68
EZ
24116@cindex @sc{gnu} Hurd debugging
24117
24118This subsection describes @value{GDBN} commands specific to the
24119@sc{gnu} Hurd native debugging.
24120
24121@table @code
24122@item set signals
24123@itemx set sigs
24124@kindex set signals@r{, Hurd command}
24125@kindex set sigs@r{, Hurd command}
24126This command toggles the state of inferior signal interception by
24127@value{GDBN}. Mach exceptions, such as breakpoint traps, are not
24128affected by this command. @code{sigs} is a shorthand alias for
24129@code{signals}.
24130
24131@item show signals
24132@itemx show sigs
24133@kindex show signals@r{, Hurd command}
24134@kindex show sigs@r{, Hurd command}
24135Show the current state of intercepting inferior's signals.
24136
24137@item set signal-thread
24138@itemx set sigthread
24139@kindex set signal-thread
24140@kindex set sigthread
24141This command tells @value{GDBN} which thread is the @code{libc} signal
24142thread. That thread is run when a signal is delivered to a running
24143process. @code{set sigthread} is the shorthand alias of @code{set
24144signal-thread}.
24145
24146@item show signal-thread
24147@itemx show sigthread
24148@kindex show signal-thread
24149@kindex show sigthread
24150These two commands show which thread will run when the inferior is
24151delivered a signal.
24152
24153@item set stopped
24154@kindex set stopped@r{, Hurd command}
24155This commands tells @value{GDBN} that the inferior process is stopped,
24156as with the @code{SIGSTOP} signal. The stopped process can be
24157continued by delivering a signal to it.
24158
24159@item show stopped
24160@kindex show stopped@r{, Hurd command}
24161This command shows whether @value{GDBN} thinks the debuggee is
24162stopped.
24163
24164@item set exceptions
24165@kindex set exceptions@r{, Hurd command}
24166Use this command to turn off trapping of exceptions in the inferior.
24167When exception trapping is off, neither breakpoints nor
24168single-stepping will work. To restore the default, set exception
24169trapping on.
24170
24171@item show exceptions
24172@kindex show exceptions@r{, Hurd command}
24173Show the current state of trapping exceptions in the inferior.
24174
24175@item set task pause
24176@kindex set task@r{, Hurd commands}
24177@cindex task attributes (@sc{gnu} Hurd)
24178@cindex pause current task (@sc{gnu} Hurd)
24179This command toggles task suspension when @value{GDBN} has control.
24180Setting it to on takes effect immediately, and the task is suspended
24181whenever @value{GDBN} gets control. Setting it to off will take
24182effect the next time the inferior is continued. If this option is set
24183to off, you can use @code{set thread default pause on} or @code{set
24184thread pause on} (see below) to pause individual threads.
24185
24186@item show task pause
24187@kindex show task@r{, Hurd commands}
24188Show the current state of task suspension.
24189
24190@item set task detach-suspend-count
24191@cindex task suspend count
24192@cindex detach from task, @sc{gnu} Hurd
24193This command sets the suspend count the task will be left with when
24194@value{GDBN} detaches from it.
24195
24196@item show task detach-suspend-count
24197Show the suspend count the task will be left with when detaching.
24198
24199@item set task exception-port
24200@itemx set task excp
24201@cindex task exception port, @sc{gnu} Hurd
24202This command sets the task exception port to which @value{GDBN} will
24203forward exceptions. The argument should be the value of the @dfn{send
24204rights} of the task. @code{set task excp} is a shorthand alias.
24205
24206@item set noninvasive
24207@cindex noninvasive task options
24208This command switches @value{GDBN} to a mode that is the least
24209invasive as far as interfering with the inferior is concerned. This
24210is the same as using @code{set task pause}, @code{set exceptions}, and
24211@code{set signals} to values opposite to the defaults.
24212
24213@item info send-rights
24214@itemx info receive-rights
24215@itemx info port-rights
24216@itemx info port-sets
24217@itemx info dead-names
24218@itemx info ports
24219@itemx info psets
24220@cindex send rights, @sc{gnu} Hurd
24221@cindex receive rights, @sc{gnu} Hurd
24222@cindex port rights, @sc{gnu} Hurd
24223@cindex port sets, @sc{gnu} Hurd
24224@cindex dead names, @sc{gnu} Hurd
24225These commands display information about, respectively, send rights,
24226receive rights, port rights, port sets, and dead names of a task.
24227There are also shorthand aliases: @code{info ports} for @code{info
24228port-rights} and @code{info psets} for @code{info port-sets}.
24229
24230@item set thread pause
24231@kindex set thread@r{, Hurd command}
24232@cindex thread properties, @sc{gnu} Hurd
24233@cindex pause current thread (@sc{gnu} Hurd)
24234This command toggles current thread suspension when @value{GDBN} has
24235control. Setting it to on takes effect immediately, and the current
24236thread is suspended whenever @value{GDBN} gets control. Setting it to
24237off will take effect the next time the inferior is continued.
24238Normally, this command has no effect, since when @value{GDBN} has
24239control, the whole task is suspended. However, if you used @code{set
24240task pause off} (see above), this command comes in handy to suspend
24241only the current thread.
24242
24243@item show thread pause
24244@kindex show thread@r{, Hurd command}
24245This command shows the state of current thread suspension.
24246
24247@item set thread run
d3e8051b 24248This command sets whether the current thread is allowed to run.
14d6dd68
EZ
24249
24250@item show thread run
24251Show whether the current thread is allowed to run.
24252
24253@item set thread detach-suspend-count
24254@cindex thread suspend count, @sc{gnu} Hurd
24255@cindex detach from thread, @sc{gnu} Hurd
24256This command sets the suspend count @value{GDBN} will leave on a
24257thread when detaching. This number is relative to the suspend count
24258found by @value{GDBN} when it notices the thread; use @code{set thread
24259takeover-suspend-count} to force it to an absolute value.
24260
24261@item show thread detach-suspend-count
24262Show the suspend count @value{GDBN} will leave on the thread when
24263detaching.
24264
24265@item set thread exception-port
24266@itemx set thread excp
24267Set the thread exception port to which to forward exceptions. This
24268overrides the port set by @code{set task exception-port} (see above).
24269@code{set thread excp} is the shorthand alias.
24270
24271@item set thread takeover-suspend-count
24272Normally, @value{GDBN}'s thread suspend counts are relative to the
24273value @value{GDBN} finds when it notices each thread. This command
24274changes the suspend counts to be absolute instead.
24275
24276@item set thread default
24277@itemx show thread default
24278@cindex thread default settings, @sc{gnu} Hurd
24279Each of the above @code{set thread} commands has a @code{set thread
24280default} counterpart (e.g., @code{set thread default pause}, @code{set
24281thread default exception-port}, etc.). The @code{thread default}
24282variety of commands sets the default thread properties for all
24283threads; you can then change the properties of individual threads with
24284the non-default commands.
24285@end table
24286
a80b95ba
TG
24287@node Darwin
24288@subsection Darwin
24289@cindex Darwin
24290
24291@value{GDBN} provides the following commands specific to the Darwin target:
24292
24293@table @code
24294@item set debug darwin @var{num}
24295@kindex set debug darwin
24296When set to a non zero value, enables debugging messages specific to
24297the Darwin support. Higher values produce more verbose output.
24298
24299@item show debug darwin
24300@kindex show debug darwin
24301Show the current state of Darwin messages.
24302
24303@item set debug mach-o @var{num}
24304@kindex set debug mach-o
24305When set to a non zero value, enables debugging messages while
24306@value{GDBN} is reading Darwin object files. (@dfn{Mach-O} is the
24307file format used on Darwin for object and executable files.) Higher
24308values produce more verbose output. This is a command to diagnose
24309problems internal to @value{GDBN} and should not be needed in normal
24310usage.
24311
24312@item show debug mach-o
24313@kindex show debug mach-o
24314Show the current state of Mach-O file messages.
24315
24316@item set mach-exceptions on
24317@itemx set mach-exceptions off
24318@kindex set mach-exceptions
24319On Darwin, faults are first reported as a Mach exception and are then
24320mapped to a Posix signal. Use this command to turn on trapping of
24321Mach exceptions in the inferior. This might be sometimes useful to
24322better understand the cause of a fault. The default is off.
24323
24324@item show mach-exceptions
24325@kindex show mach-exceptions
24326Show the current state of exceptions trapping.
24327@end table
24328
e9076973
JB
24329@node FreeBSD
24330@subsection FreeBSD
24331@cindex FreeBSD
24332
24333When the ABI of a system call is changed in the FreeBSD kernel, this
24334is implemented by leaving a compatibility system call using the old
24335ABI at the existing number and allocating a new system call number for
24336the version using the new ABI. As a convenience, when a system call
24337is caught by name (@pxref{catch syscall}), compatibility system calls
24338are also caught.
24339
24340For example, FreeBSD 12 introduced a new variant of the @code{kevent}
24341system call and catching the @code{kevent} system call by name catches
24342both variants:
24343
24344@smallexample
24345(@value{GDBP}) catch syscall kevent
24346Catchpoint 1 (syscalls 'freebsd11_kevent' [363] 'kevent' [560])
24347(@value{GDBP})
24348@end smallexample
24349
a64548ea 24350
8e04817f
AC
24351@node Embedded OS
24352@section Embedded Operating Systems
104c1213 24353
8e04817f
AC
24354This section describes configurations involving the debugging of
24355embedded operating systems that are available for several different
24356architectures.
d4f3574e 24357
8e04817f
AC
24358@value{GDBN} includes the ability to debug programs running on
24359various real-time operating systems.
104c1213 24360
6d2ebf8b 24361@node Embedded Processors
104c1213
JM
24362@section Embedded Processors
24363
24364This section goes into details specific to particular embedded
24365configurations.
24366
c45da7e6
EZ
24367@cindex send command to simulator
24368Whenever a specific embedded processor has a simulator, @value{GDBN}
24369allows to send an arbitrary command to the simulator.
24370
24371@table @code
24372@item sim @var{command}
24373@kindex sim@r{, a command}
24374Send an arbitrary @var{command} string to the simulator. Consult the
24375documentation for the specific simulator in use for information about
24376acceptable commands.
24377@end table
24378
7d86b5d5 24379
104c1213 24380@menu
ad0a504f 24381* ARC:: Synopsys ARC
bb615428 24382* ARM:: ARM
104c1213 24383* M68K:: Motorola M68K
08be9d71 24384* MicroBlaze:: Xilinx MicroBlaze
104c1213 24385* MIPS Embedded:: MIPS Embedded
a994fec4 24386* OpenRISC 1000:: OpenRISC 1000 (or1k)
4acd40f3 24387* PowerPC Embedded:: PowerPC Embedded
a64548ea
EZ
24388* AVR:: Atmel AVR
24389* CRIS:: CRIS
24390* Super-H:: Renesas Super-H
104c1213
JM
24391@end menu
24392
ad0a504f
AK
24393@node ARC
24394@subsection Synopsys ARC
24395@cindex Synopsys ARC
24396@cindex ARC specific commands
24397@cindex ARC600
24398@cindex ARC700
24399@cindex ARC EM
24400@cindex ARC HS
24401
24402@value{GDBN} provides the following ARC-specific commands:
24403
24404@table @code
24405@item set debug arc
24406@kindex set debug arc
24407Control the level of ARC specific debug messages. Use 0 for no messages (the
fe5f7374 24408default), 1 for debug messages, and 2 for even more debug messages.
ad0a504f
AK
24409
24410@item show debug arc
24411@kindex show debug arc
24412Show the level of ARC specific debugging in operation.
24413
eea78757
AK
24414@item maint print arc arc-instruction @var{address}
24415@kindex maint print arc arc-instruction
24416Print internal disassembler information about instruction at a given address.
24417
ad0a504f
AK
24418@end table
24419
6d2ebf8b 24420@node ARM
104c1213 24421@subsection ARM
8e04817f 24422
e2f4edfd
EZ
24423@value{GDBN} provides the following ARM-specific commands:
24424
24425@table @code
24426@item set arm disassembler
24427@kindex set arm
24428This commands selects from a list of disassembly styles. The
24429@code{"std"} style is the standard style.
24430
24431@item show arm disassembler
24432@kindex show arm
24433Show the current disassembly style.
24434
24435@item set arm apcs32
24436@cindex ARM 32-bit mode
24437This command toggles ARM operation mode between 32-bit and 26-bit.
24438
24439@item show arm apcs32
24440Display the current usage of the ARM 32-bit mode.
24441
24442@item set arm fpu @var{fputype}
24443This command sets the ARM floating-point unit (FPU) type. The
24444argument @var{fputype} can be one of these:
24445
24446@table @code
24447@item auto
24448Determine the FPU type by querying the OS ABI.
24449@item softfpa
24450Software FPU, with mixed-endian doubles on little-endian ARM
24451processors.
24452@item fpa
24453GCC-compiled FPA co-processor.
24454@item softvfp
24455Software FPU with pure-endian doubles.
24456@item vfp
24457VFP co-processor.
24458@end table
24459
24460@item show arm fpu
24461Show the current type of the FPU.
24462
24463@item set arm abi
24464This command forces @value{GDBN} to use the specified ABI.
24465
24466@item show arm abi
24467Show the currently used ABI.
24468
0428b8f5
DJ
24469@item set arm fallback-mode (arm|thumb|auto)
24470@value{GDBN} uses the symbol table, when available, to determine
24471whether instructions are ARM or Thumb. This command controls
24472@value{GDBN}'s default behavior when the symbol table is not
24473available. The default is @samp{auto}, which causes @value{GDBN} to
24474use the current execution mode (from the @code{T} bit in the @code{CPSR}
24475register).
24476
24477@item show arm fallback-mode
24478Show the current fallback instruction mode.
24479
24480@item set arm force-mode (arm|thumb|auto)
24481This command overrides use of the symbol table to determine whether
24482instructions are ARM or Thumb. The default is @samp{auto}, which
24483causes @value{GDBN} to use the symbol table and then the setting
24484of @samp{set arm fallback-mode}.
24485
24486@item show arm force-mode
24487Show the current forced instruction mode.
24488
e2f4edfd
EZ
24489@item set debug arm
24490Toggle whether to display ARM-specific debugging messages from the ARM
24491target support subsystem.
24492
24493@item show debug arm
24494Show whether ARM-specific debugging messages are enabled.
24495@end table
24496
ee8e71d4
EZ
24497@table @code
24498@item target sim @r{[}@var{simargs}@r{]} @dots{}
24499The @value{GDBN} ARM simulator accepts the following optional arguments.
24500
24501@table @code
24502@item --swi-support=@var{type}
697aa1b7 24503Tell the simulator which SWI interfaces to support. The argument
ee8e71d4
EZ
24504@var{type} may be a comma separated list of the following values.
24505The default value is @code{all}.
24506
24507@table @code
24508@item none
24509@item demon
24510@item angel
24511@item redboot
24512@item all
24513@end table
24514@end table
24515@end table
e2f4edfd 24516
8e04817f
AC
24517@node M68K
24518@subsection M68k
24519
bb615428 24520The Motorola m68k configuration includes ColdFire support.
8e04817f 24521
08be9d71
ME
24522@node MicroBlaze
24523@subsection MicroBlaze
24524@cindex Xilinx MicroBlaze
24525@cindex XMD, Xilinx Microprocessor Debugger
24526
24527The MicroBlaze is a soft-core processor supported on various Xilinx
24528FPGAs, such as Spartan or Virtex series. Boards with these processors
24529usually have JTAG ports which connect to a host system running the Xilinx
24530Embedded Development Kit (EDK) or Software Development Kit (SDK).
24531This host system is used to download the configuration bitstream to
24532the target FPGA. The Xilinx Microprocessor Debugger (XMD) program
24533communicates with the target board using the JTAG interface and
24534presents a @code{gdbserver} interface to the board. By default
24535@code{xmd} uses port @code{1234}. (While it is possible to change
24536this default port, it requires the use of undocumented @code{xmd}
24537commands. Contact Xilinx support if you need to do this.)
24538
24539Use these GDB commands to connect to the MicroBlaze target processor.
24540
24541@table @code
24542@item target remote :1234
24543Use this command to connect to the target if you are running @value{GDBN}
24544on the same system as @code{xmd}.
24545
24546@item target remote @var{xmd-host}:1234
24547Use this command to connect to the target if it is connected to @code{xmd}
24548running on a different system named @var{xmd-host}.
24549
24550@item load
24551Use this command to download a program to the MicroBlaze target.
24552
24553@item set debug microblaze @var{n}
24554Enable MicroBlaze-specific debugging messages if non-zero.
24555
24556@item show debug microblaze @var{n}
24557Show MicroBlaze-specific debugging level.
24558@end table
24559
8e04817f 24560@node MIPS Embedded
eb17f351 24561@subsection @acronym{MIPS} Embedded
8e04817f 24562
8e04817f 24563@noindent
f7c38292 24564@value{GDBN} supports these special commands for @acronym{MIPS} targets:
104c1213 24565
8e04817f 24566@table @code
8e04817f
AC
24567@item set mipsfpu double
24568@itemx set mipsfpu single
24569@itemx set mipsfpu none
a64548ea 24570@itemx set mipsfpu auto
8e04817f
AC
24571@itemx show mipsfpu
24572@kindex set mipsfpu
24573@kindex show mipsfpu
eb17f351
EZ
24574@cindex @acronym{MIPS} remote floating point
24575@cindex floating point, @acronym{MIPS} remote
24576If your target board does not support the @acronym{MIPS} floating point
8e04817f
AC
24577coprocessor, you should use the command @samp{set mipsfpu none} (if you
24578need this, you may wish to put the command in your @value{GDBN} init
24579file). This tells @value{GDBN} how to find the return value of
24580functions which return floating point values. It also allows
24581@value{GDBN} to avoid saving the floating point registers when calling
24582functions on the board. If you are using a floating point coprocessor
24583with only single precision floating point support, as on the @sc{r4650}
24584processor, use the command @samp{set mipsfpu single}. The default
24585double precision floating point coprocessor may be selected using
24586@samp{set mipsfpu double}.
104c1213 24587
8e04817f
AC
24588In previous versions the only choices were double precision or no
24589floating point, so @samp{set mipsfpu on} will select double precision
24590and @samp{set mipsfpu off} will select no floating point.
104c1213 24591
8e04817f
AC
24592As usual, you can inquire about the @code{mipsfpu} variable with
24593@samp{show mipsfpu}.
8e04817f 24594@end table
104c1213 24595
a994fec4
FJ
24596@node OpenRISC 1000
24597@subsection OpenRISC 1000
24598@cindex OpenRISC 1000
24599
24600@noindent
24601The OpenRISC 1000 provides a free RISC instruction set architecture. It is
24602mainly provided as a soft-core which can run on Xilinx, Altera and other
24603FPGA's.
24604
24605@value{GDBN} for OpenRISC supports the below commands when connecting to
24606a target:
24607
24608@table @code
24609
24610@kindex target sim
24611@item target sim
24612
24613Runs the builtin CPU simulator which can run very basic
24614programs but does not support most hardware functions like MMU.
24615For more complex use cases the user is advised to run an external
24616target, and connect using @samp{target remote}.
24617
24618Example: @code{target sim}
24619
24620@item set debug or1k
24621Toggle whether to display OpenRISC-specific debugging messages from the
24622OpenRISC target support subsystem.
24623
24624@item show debug or1k
24625Show whether OpenRISC-specific debugging messages are enabled.
24626@end table
24627
4acd40f3
TJB
24628@node PowerPC Embedded
24629@subsection PowerPC Embedded
104c1213 24630
66b73624
TJB
24631@cindex DVC register
24632@value{GDBN} supports using the DVC (Data Value Compare) register to
24633implement in hardware simple hardware watchpoint conditions of the form:
24634
24635@smallexample
24636(@value{GDBP}) watch @var{ADDRESS|VARIABLE} \
24637 if @var{ADDRESS|VARIABLE} == @var{CONSTANT EXPRESSION}
24638@end smallexample
24639
e09342b5
TJB
24640The DVC register will be automatically used when @value{GDBN} detects
24641such pattern in a condition expression, and the created watchpoint uses one
24642debug register (either the @code{exact-watchpoints} option is on and the
24643variable is scalar, or the variable has a length of one byte). This feature
24644is available in native @value{GDBN} running on a Linux kernel version 2.6.34
24645or newer.
24646
24647When running on PowerPC embedded processors, @value{GDBN} automatically uses
24648ranged hardware watchpoints, unless the @code{exact-watchpoints} option is on,
24649in which case watchpoints using only one debug register are created when
24650watching variables of scalar types.
24651
24652You can create an artificial array to watch an arbitrary memory
24653region using one of the following commands (@pxref{Expressions}):
24654
24655@smallexample
24656(@value{GDBP}) watch *((char *) @var{address})@@@var{length}
24657(@value{GDBP}) watch @{char[@var{length}]@} @var{address}
24658@end smallexample
66b73624 24659
9c06b0b4
TJB
24660PowerPC embedded processors support masked watchpoints. See the discussion
24661about the @code{mask} argument in @ref{Set Watchpoints}.
24662
f1310107
TJB
24663@cindex ranged breakpoint
24664PowerPC embedded processors support hardware accelerated
24665@dfn{ranged breakpoints}. A ranged breakpoint stops execution of
24666the inferior whenever it executes an instruction at any address within
24667the range it specifies. To set a ranged breakpoint in @value{GDBN},
24668use the @code{break-range} command.
24669
55eddb0f
DJ
24670@value{GDBN} provides the following PowerPC-specific commands:
24671
104c1213 24672@table @code
f1310107
TJB
24673@kindex break-range
24674@item break-range @var{start-location}, @var{end-location}
697aa1b7
EZ
24675Set a breakpoint for an address range given by
24676@var{start-location} and @var{end-location}, which can specify a function name,
f1310107
TJB
24677a line number, an offset of lines from the current line or from the start
24678location, or an address of an instruction (see @ref{Specify Location},
24679for a list of all the possible ways to specify a @var{location}.)
24680The breakpoint will stop execution of the inferior whenever it
24681executes an instruction at any address within the specified range,
24682(including @var{start-location} and @var{end-location}.)
24683
55eddb0f
DJ
24684@kindex set powerpc
24685@item set powerpc soft-float
24686@itemx show powerpc soft-float
24687Force @value{GDBN} to use (or not use) a software floating point calling
24688convention. By default, @value{GDBN} selects the calling convention based
24689on the selected architecture and the provided executable file.
24690
24691@item set powerpc vector-abi
24692@itemx show powerpc vector-abi
24693Force @value{GDBN} to use the specified calling convention for vector
24694arguments and return values. The valid options are @samp{auto};
24695@samp{generic}, to avoid vector registers even if they are present;
24696@samp{altivec}, to use AltiVec registers; and @samp{spe} to use SPE
24697registers. By default, @value{GDBN} selects the calling convention
24698based on the selected architecture and the provided executable file.
24699
e09342b5
TJB
24700@item set powerpc exact-watchpoints
24701@itemx show powerpc exact-watchpoints
24702Allow @value{GDBN} to use only one debug register when watching a variable
24703of scalar type, thus assuming that the variable is accessed through the
24704address of its first byte.
24705
104c1213
JM
24706@end table
24707
a64548ea
EZ
24708@node AVR
24709@subsection Atmel AVR
24710@cindex AVR
24711
24712When configured for debugging the Atmel AVR, @value{GDBN} supports the
24713following AVR-specific commands:
24714
24715@table @code
24716@item info io_registers
24717@kindex info io_registers@r{, AVR}
24718@cindex I/O registers (Atmel AVR)
24719This command displays information about the AVR I/O registers. For
24720each register, @value{GDBN} prints its number and value.
24721@end table
24722
24723@node CRIS
24724@subsection CRIS
24725@cindex CRIS
24726
24727When configured for debugging CRIS, @value{GDBN} provides the
24728following CRIS-specific commands:
24729
24730@table @code
24731@item set cris-version @var{ver}
24732@cindex CRIS version
e22e55c9
OF
24733Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
24734The CRIS version affects register names and sizes. This command is useful in
24735case autodetection of the CRIS version fails.
a64548ea
EZ
24736
24737@item show cris-version
24738Show the current CRIS version.
24739
24740@item set cris-dwarf2-cfi
24741@cindex DWARF-2 CFI and CRIS
e22e55c9
OF
24742Set the usage of DWARF-2 CFI for CRIS debugging. The default is @samp{on}.
24743Change to @samp{off} when using @code{gcc-cris} whose version is below
24744@code{R59}.
a64548ea
EZ
24745
24746@item show cris-dwarf2-cfi
24747Show the current state of using DWARF-2 CFI.
e22e55c9
OF
24748
24749@item set cris-mode @var{mode}
24750@cindex CRIS mode
24751Set the current CRIS mode to @var{mode}. It should only be changed when
24752debugging in guru mode, in which case it should be set to
24753@samp{guru} (the default is @samp{normal}).
24754
24755@item show cris-mode
24756Show the current CRIS mode.
a64548ea
EZ
24757@end table
24758
24759@node Super-H
24760@subsection Renesas Super-H
24761@cindex Super-H
24762
24763For the Renesas Super-H processor, @value{GDBN} provides these
24764commands:
24765
24766@table @code
c055b101
CV
24767@item set sh calling-convention @var{convention}
24768@kindex set sh calling-convention
24769Set the calling-convention used when calling functions from @value{GDBN}.
24770Allowed values are @samp{gcc}, which is the default setting, and @samp{renesas}.
24771With the @samp{gcc} setting, functions are called using the @value{NGCC} calling
24772convention. If the DWARF-2 information of the called function specifies
24773that the function follows the Renesas calling convention, the function
24774is called using the Renesas calling convention. If the calling convention
24775is set to @samp{renesas}, the Renesas calling convention is always used,
24776regardless of the DWARF-2 information. This can be used to override the
24777default of @samp{gcc} if debug information is missing, or the compiler
24778does not emit the DWARF-2 calling convention entry for a function.
24779
24780@item show sh calling-convention
24781@kindex show sh calling-convention
24782Show the current calling convention setting.
24783
a64548ea
EZ
24784@end table
24785
24786
8e04817f
AC
24787@node Architectures
24788@section Architectures
104c1213 24789
8e04817f
AC
24790This section describes characteristics of architectures that affect
24791all uses of @value{GDBN} with the architecture, both native and cross.
104c1213 24792
8e04817f 24793@menu
430ed3f0 24794* AArch64::
9c16f35a 24795* i386::
8e04817f
AC
24796* Alpha::
24797* MIPS::
a64548ea 24798* HPPA:: HP PA architecture
4acd40f3 24799* PowerPC::
a1217d97 24800* Nios II::
58afddc6 24801* Sparc64::
51d21d60 24802* S12Z::
8e04817f 24803@end menu
104c1213 24804
430ed3f0
MS
24805@node AArch64
24806@subsection AArch64
24807@cindex AArch64 support
24808
24809When @value{GDBN} is debugging the AArch64 architecture, it provides the
24810following special commands:
24811
24812@table @code
24813@item set debug aarch64
24814@kindex set debug aarch64
24815This command determines whether AArch64 architecture-specific debugging
24816messages are to be displayed.
24817
24818@item show debug aarch64
24819Show whether AArch64 debugging messages are displayed.
24820
24821@end table
24822
1461bdac
AH
24823@subsubsection AArch64 SVE.
24824@cindex AArch64 SVE.
24825
24826When @value{GDBN} is debugging the AArch64 architecture, if the Scalable Vector
24827Extension (SVE) is present, then @value{GDBN} will provide the vector registers
24828@code{$z0} through @code{$z31}, vector predicate registers @code{$p0} through
24829@code{$p15}, and the @code{$ffr} register. In addition, the pseudo register
24830@code{$vg} will be provided. This is the vector granule for the current thread
24831and represents the number of 64-bit chunks in an SVE @code{z} register.
24832
24833If the vector length changes, then the @code{$vg} register will be updated,
24834but the lengths of the @code{z} and @code{p} registers will not change. This
24835is a known limitation of @value{GDBN} and does not affect the execution of the
24836target process.
24837
3d31bc39
AH
24838@subsubsection AArch64 Pointer Authentication.
24839@cindex AArch64 Pointer Authentication.
24840
24841When @value{GDBN} is debugging the AArch64 architecture, and the program is
24842using the v8.3-A feature Pointer Authentication (PAC), then whenever the link
1ba7cdcd 24843register @code{$lr} is pointing to an PAC function its value will be masked.
3d31bc39 24844When GDB prints a backtrace, any addresses that required unmasking will be
aa7ca1bb
AH
24845postfixed with the marker [PAC]. When using the MI, this is printed as part
24846of the @code{addr_flags} field.
1461bdac 24847
9c16f35a 24848@node i386
db2e3e2e 24849@subsection x86 Architecture-specific Issues
9c16f35a
EZ
24850
24851@table @code
24852@item set struct-convention @var{mode}
24853@kindex set struct-convention
24854@cindex struct return convention
24855@cindex struct/union returned in registers
24856Set the convention used by the inferior to return @code{struct}s and
24857@code{union}s from functions to @var{mode}. Possible values of
24858@var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
24859default). @code{"default"} or @code{"pcc"} means that @code{struct}s
24860are returned on the stack, while @code{"reg"} means that a
24861@code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
24862be returned in a register.
24863
24864@item show struct-convention
24865@kindex show struct-convention
24866Show the current setting of the convention to return @code{struct}s
24867from functions.
966f0aef 24868@end table
29c1c244 24869
ca8941bb 24870
bc504a31
PA
24871@subsubsection Intel @dfn{Memory Protection Extensions} (MPX).
24872@cindex Intel Memory Protection Extensions (MPX).
ca8941bb 24873
ca8941bb
WT
24874Memory Protection Extension (MPX) adds the bound registers @samp{BND0}
24875@footnote{The register named with capital letters represent the architecture
24876registers.} through @samp{BND3}. Bound registers store a pair of 64-bit values
24877which are the lower bound and upper bound. Bounds are effective addresses or
24878memory locations. The upper bounds are architecturally represented in 1's
24879complement form. A bound having lower bound = 0, and upper bound = 0
24880(1's complement of all bits set) will allow access to the entire address space.
24881
24882@samp{BND0} through @samp{BND3} are represented in @value{GDBN} as @samp{bnd0raw}
24883through @samp{bnd3raw}. Pseudo registers @samp{bnd0} through @samp{bnd3}
24884display the upper bound performing the complement of one operation on the
24885upper bound value, i.e.@ when upper bound in @samp{bnd0raw} is 0 in the
24886@value{GDBN} @samp{bnd0} it will be @code{0xfff@dots{}}. In this sense it
24887can also be noted that the upper bounds are inclusive.
24888
24889As an example, assume that the register BND0 holds bounds for a pointer having
24890access allowed for the range between 0x32 and 0x71. The values present on
24891bnd0raw and bnd registers are presented as follows:
24892
24893@smallexample
24894 bnd0raw = @{0x32, 0xffffffff8e@}
24895 bnd0 = @{lbound = 0x32, ubound = 0x71@} : size 64
24896@end smallexample
24897
22f25c9d
EZ
24898This way the raw value can be accessed via bnd0raw@dots{}bnd3raw. Any
24899change on bnd0@dots{}bnd3 or bnd0raw@dots{}bnd3raw is reflect on its
24900counterpart. When the bnd0@dots{}bnd3 registers are displayed via
24901Python, the display includes the memory size, in bits, accessible to
24902the pointer.
9c16f35a 24903
29c1c244
WT
24904Bounds can also be stored in bounds tables, which are stored in
24905application memory. These tables store bounds for pointers by specifying
24906the bounds pointer's value along with its bounds. Evaluating and changing
24907bounds located in bound tables is therefore interesting while investigating
24908bugs on MPX context. @value{GDBN} provides commands for this purpose:
24909
966f0aef 24910@table @code
29c1c244
WT
24911@item show mpx bound @var{pointer}
24912@kindex show mpx bound
24913Display bounds of the given @var{pointer}.
24914
24915@item set mpx bound @var{pointer}, @var{lbound}, @var{ubound}
24916@kindex set mpx bound
24917Set the bounds of a pointer in the bound table.
24918This command takes three parameters: @var{pointer} is the pointers
24919whose bounds are to be changed, @var{lbound} and @var{ubound} are new values
24920for lower and upper bounds respectively.
24921@end table
24922
4a612d6f
WT
24923When you call an inferior function on an Intel MPX enabled program,
24924GDB sets the inferior's bound registers to the init (disabled) state
24925before calling the function. As a consequence, bounds checks for the
24926pointer arguments passed to the function will always pass.
24927
24928This is necessary because when you call an inferior function, the
24929program is usually in the middle of the execution of other function.
24930Since at that point bound registers are in an arbitrary state, not
24931clearing them would lead to random bound violations in the called
24932function.
24933
24934You can still examine the influence of the bound registers on the
24935execution of the called function by stopping the execution of the
24936called function at its prologue, setting bound registers, and
24937continuing the execution. For example:
24938
24939@smallexample
24940 $ break *upper
24941 Breakpoint 2 at 0x4009de: file i386-mpx-call.c, line 47.
24942 $ print upper (a, b, c, d, 1)
24943 Breakpoint 2, upper (a=0x0, b=0x6e0000005b, c=0x0, d=0x0, len=48)....
24944 $ print $bnd0
5cf70512 24945 @{lbound = 0x0, ubound = ffffffff@} : size -1
4a612d6f
WT
24946@end smallexample
24947
24948At this last step the value of bnd0 can be changed for investigation of bound
24949violations caused along the execution of the call. In order to know how to
24950set the bound registers or bound table for the call consult the ABI.
24951
8e04817f
AC
24952@node Alpha
24953@subsection Alpha
104c1213 24954
8e04817f 24955See the following section.
104c1213 24956
8e04817f 24957@node MIPS
eb17f351 24958@subsection @acronym{MIPS}
104c1213 24959
8e04817f 24960@cindex stack on Alpha
eb17f351 24961@cindex stack on @acronym{MIPS}
8e04817f 24962@cindex Alpha stack
eb17f351
EZ
24963@cindex @acronym{MIPS} stack
24964Alpha- and @acronym{MIPS}-based computers use an unusual stack frame, which
8e04817f
AC
24965sometimes requires @value{GDBN} to search backward in the object code to
24966find the beginning of a function.
104c1213 24967
eb17f351 24968@cindex response time, @acronym{MIPS} debugging
8e04817f
AC
24969To improve response time (especially for embedded applications, where
24970@value{GDBN} may be restricted to a slow serial line for this search)
24971you may want to limit the size of this search, using one of these
24972commands:
104c1213 24973
8e04817f 24974@table @code
eb17f351 24975@cindex @code{heuristic-fence-post} (Alpha, @acronym{MIPS})
8e04817f
AC
24976@item set heuristic-fence-post @var{limit}
24977Restrict @value{GDBN} to examining at most @var{limit} bytes in its
24978search for the beginning of a function. A value of @var{0} (the
24979default) means there is no limit. However, except for @var{0}, the
24980larger the limit the more bytes @code{heuristic-fence-post} must search
e2f4edfd
EZ
24981and therefore the longer it takes to run. You should only need to use
24982this command when debugging a stripped executable.
104c1213 24983
8e04817f
AC
24984@item show heuristic-fence-post
24985Display the current limit.
24986@end table
104c1213
JM
24987
24988@noindent
8e04817f 24989These commands are available @emph{only} when @value{GDBN} is configured
eb17f351 24990for debugging programs on Alpha or @acronym{MIPS} processors.
104c1213 24991
eb17f351 24992Several @acronym{MIPS}-specific commands are available when debugging @acronym{MIPS}
a64548ea
EZ
24993programs:
24994
24995@table @code
a64548ea
EZ
24996@item set mips abi @var{arg}
24997@kindex set mips abi
eb17f351
EZ
24998@cindex set ABI for @acronym{MIPS}
24999Tell @value{GDBN} which @acronym{MIPS} ABI is used by the inferior. Possible
a64548ea
EZ
25000values of @var{arg} are:
25001
25002@table @samp
25003@item auto
25004The default ABI associated with the current binary (this is the
25005default).
25006@item o32
25007@item o64
25008@item n32
25009@item n64
25010@item eabi32
25011@item eabi64
a64548ea
EZ
25012@end table
25013
25014@item show mips abi
25015@kindex show mips abi
eb17f351 25016Show the @acronym{MIPS} ABI used by @value{GDBN} to debug the inferior.
a64548ea 25017
4cc0665f
MR
25018@item set mips compression @var{arg}
25019@kindex set mips compression
25020@cindex code compression, @acronym{MIPS}
25021Tell @value{GDBN} which @acronym{MIPS} compressed
25022@acronym{ISA, Instruction Set Architecture} encoding is used by the
25023inferior. @value{GDBN} uses this for code disassembly and other
25024internal interpretation purposes. This setting is only referred to
25025when no executable has been associated with the debugging session or
25026the executable does not provide information about the encoding it uses.
25027Otherwise this setting is automatically updated from information
25028provided by the executable.
25029
25030Possible values of @var{arg} are @samp{mips16} and @samp{micromips}.
25031The default compressed @acronym{ISA} encoding is @samp{mips16}, as
25032executables containing @acronym{MIPS16} code frequently are not
25033identified as such.
25034
25035This setting is ``sticky''; that is, it retains its value across
25036debugging sessions until reset either explicitly with this command or
25037implicitly from an executable.
25038
25039The compiler and/or assembler typically add symbol table annotations to
25040identify functions compiled for the @acronym{MIPS16} or
25041@acronym{microMIPS} @acronym{ISA}s. If these function-scope annotations
25042are present, @value{GDBN} uses them in preference to the global
25043compressed @acronym{ISA} encoding setting.
25044
25045@item show mips compression
25046@kindex show mips compression
25047Show the @acronym{MIPS} compressed @acronym{ISA} encoding used by
25048@value{GDBN} to debug the inferior.
25049
a64548ea
EZ
25050@item set mipsfpu
25051@itemx show mipsfpu
25052@xref{MIPS Embedded, set mipsfpu}.
25053
25054@item set mips mask-address @var{arg}
25055@kindex set mips mask-address
eb17f351 25056@cindex @acronym{MIPS} addresses, masking
a64548ea 25057This command determines whether the most-significant 32 bits of 64-bit
eb17f351 25058@acronym{MIPS} addresses are masked off. The argument @var{arg} can be
a64548ea
EZ
25059@samp{on}, @samp{off}, or @samp{auto}. The latter is the default
25060setting, which lets @value{GDBN} determine the correct value.
25061
25062@item show mips mask-address
25063@kindex show mips mask-address
eb17f351 25064Show whether the upper 32 bits of @acronym{MIPS} addresses are masked off or
a64548ea
EZ
25065not.
25066
25067@item set remote-mips64-transfers-32bit-regs
25068@kindex set remote-mips64-transfers-32bit-regs
eb17f351
EZ
25069This command controls compatibility with 64-bit @acronym{MIPS} targets that
25070transfer data in 32-bit quantities. If you have an old @acronym{MIPS} 64 target
a64548ea
EZ
25071that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
25072and 64 bits for other registers, set this option to @samp{on}.
25073
25074@item show remote-mips64-transfers-32bit-regs
25075@kindex show remote-mips64-transfers-32bit-regs
eb17f351 25076Show the current setting of compatibility with older @acronym{MIPS} 64 targets.
a64548ea
EZ
25077
25078@item set debug mips
25079@kindex set debug mips
eb17f351 25080This command turns on and off debugging messages for the @acronym{MIPS}-specific
a64548ea
EZ
25081target code in @value{GDBN}.
25082
25083@item show debug mips
25084@kindex show debug mips
eb17f351 25085Show the current setting of @acronym{MIPS} debugging messages.
a64548ea
EZ
25086@end table
25087
25088
25089@node HPPA
25090@subsection HPPA
25091@cindex HPPA support
25092
d3e8051b 25093When @value{GDBN} is debugging the HP PA architecture, it provides the
a64548ea
EZ
25094following special commands:
25095
25096@table @code
25097@item set debug hppa
25098@kindex set debug hppa
db2e3e2e 25099This command determines whether HPPA architecture-specific debugging
a64548ea
EZ
25100messages are to be displayed.
25101
25102@item show debug hppa
25103Show whether HPPA debugging messages are displayed.
25104
25105@item maint print unwind @var{address}
25106@kindex maint print unwind@r{, HPPA}
25107This command displays the contents of the unwind table entry at the
25108given @var{address}.
25109
25110@end table
25111
104c1213 25112
4acd40f3
TJB
25113@node PowerPC
25114@subsection PowerPC
25115@cindex PowerPC architecture
25116
25117When @value{GDBN} is debugging the PowerPC architecture, it provides a set of
25118pseudo-registers to enable inspection of 128-bit wide Decimal Floating Point
25119numbers stored in the floating point registers. These values must be stored
25120in two consecutive registers, always starting at an even register like
25121@code{f0} or @code{f2}.
25122
25123The pseudo-registers go from @code{$dl0} through @code{$dl15}, and are formed
25124by joining the even/odd register pairs @code{f0} and @code{f1} for @code{$dl0},
25125@code{f2} and @code{f3} for @code{$dl1} and so on.
25126
aeac0ff9 25127For POWER7 processors, @value{GDBN} provides a set of pseudo-registers, the 64-bit
677c5bb1
LM
25128wide Extended Floating Point Registers (@samp{f32} through @samp{f63}).
25129
a1217d97
SL
25130@node Nios II
25131@subsection Nios II
25132@cindex Nios II architecture
25133
25134When @value{GDBN} is debugging the Nios II architecture,
25135it provides the following special commands:
25136
25137@table @code
25138
25139@item set debug nios2
25140@kindex set debug nios2
25141This command turns on and off debugging messages for the Nios II
25142target code in @value{GDBN}.
25143
25144@item show debug nios2
25145@kindex show debug nios2
25146Show the current setting of Nios II debugging messages.
25147@end table
23d964e7 25148
58afddc6
WP
25149@node Sparc64
25150@subsection Sparc64
25151@cindex Sparc64 support
25152@cindex Application Data Integrity
25153@subsubsection ADI Support
25154
25155The M7 processor supports an Application Data Integrity (ADI) feature that
25156detects invalid data accesses. When software allocates memory and enables
25157ADI on the allocated memory, it chooses a 4-bit version number, sets the
25158version in the upper 4 bits of the 64-bit pointer to that data, and stores
25159the 4-bit version in every cacheline of that data. Hardware saves the latter
25160in spare bits in the cache and memory hierarchy. On each load and store,
25161the processor compares the upper 4 VA (virtual address) bits to the
25162cacheline's version. If there is a mismatch, the processor generates a
25163version mismatch trap which can be either precise or disrupting. The trap
25164is an error condition which the kernel delivers to the process as a SIGSEGV
25165signal.
25166
25167Note that only 64-bit applications can use ADI and need to be built with
25168ADI-enabled.
25169
25170Values of the ADI version tags, which are in granularity of a
25171cacheline (64 bytes), can be viewed or modified.
25172
25173
25174@table @code
25175@kindex adi examine
25176@item adi (examine | x) [ / @var{n} ] @var{addr}
25177
25178The @code{adi examine} command displays the value of one ADI version tag per
25179cacheline.
25180
25181@var{n} is a decimal integer specifying the number in bytes; the default
25182is 1. It specifies how much ADI version information, at the ratio of 1:ADI
25183block size, to display.
25184
25185@var{addr} is the address in user address space where you want @value{GDBN}
25186to begin displaying the ADI version tags.
25187
25188Below is an example of displaying ADI versions of variable "shmaddr".
25189
25190@smallexample
25191(@value{GDBP}) adi x/100 shmaddr
25192 0xfff800010002c000: 0 0
25193@end smallexample
25194
25195@kindex adi assign
25196@item adi (assign | a) [ / @var{n} ] @var{addr} = @var{tag}
25197
25198The @code{adi assign} command is used to assign new ADI version tag
25199to an address.
25200
25201@var{n} is a decimal integer specifying the number in bytes;
25202the default is 1. It specifies how much ADI version information, at the
25203ratio of 1:ADI block size, to modify.
25204
25205@var{addr} is the address in user address space where you want @value{GDBN}
25206to begin modifying the ADI version tags.
25207
25208@var{tag} is the new ADI version tag.
25209
25210For example, do the following to modify then verify ADI versions of
25211variable "shmaddr":
25212
25213@smallexample
25214(@value{GDBP}) adi a/100 shmaddr = 7
25215(@value{GDBP}) adi x/100 shmaddr
25216 0xfff800010002c000: 7 7
25217@end smallexample
25218
25219@end table
25220
51d21d60
JD
25221@node S12Z
25222@subsection S12Z
25223@cindex S12Z support
25224
25225When @value{GDBN} is debugging the S12Z architecture,
25226it provides the following special command:
25227
25228@table @code
25229@item maint info bdccsr
25230@kindex maint info bdccsr@r{, S12Z}
25231This command displays the current value of the microprocessor's
25232BDCCSR register.
25233@end table
25234
25235
8e04817f
AC
25236@node Controlling GDB
25237@chapter Controlling @value{GDBN}
25238
25239You can alter the way @value{GDBN} interacts with you by using the
25240@code{set} command. For commands controlling how @value{GDBN} displays
79a6e687 25241data, see @ref{Print Settings, ,Print Settings}. Other settings are
8e04817f
AC
25242described here.
25243
25244@menu
25245* Prompt:: Prompt
25246* Editing:: Command editing
d620b259 25247* Command History:: Command history
8e04817f 25248* Screen Size:: Screen size
140a4bc0 25249* Output Styling:: Output styling
8e04817f 25250* Numbers:: Numbers
1e698235 25251* ABI:: Configuring the current ABI
bf88dd68 25252* Auto-loading:: Automatically loading associated files
8e04817f
AC
25253* Messages/Warnings:: Optional warnings and messages
25254* Debugging Output:: Optional messages about internal happenings
14fb1bac 25255* Other Misc Settings:: Other Miscellaneous Settings
8e04817f
AC
25256@end menu
25257
25258@node Prompt
25259@section Prompt
104c1213 25260
8e04817f 25261@cindex prompt
104c1213 25262
8e04817f
AC
25263@value{GDBN} indicates its readiness to read a command by printing a string
25264called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
25265can change the prompt string with the @code{set prompt} command. For
25266instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
25267the prompt in one of the @value{GDBN} sessions so that you can always tell
25268which one you are talking to.
104c1213 25269
8e04817f
AC
25270@emph{Note:} @code{set prompt} does not add a space for you after the
25271prompt you set. This allows you to set a prompt which ends in a space
25272or a prompt that does not.
104c1213 25273
8e04817f
AC
25274@table @code
25275@kindex set prompt
25276@item set prompt @var{newprompt}
25277Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
104c1213 25278
8e04817f
AC
25279@kindex show prompt
25280@item show prompt
25281Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
104c1213
JM
25282@end table
25283
fa3a4f15
PM
25284Versions of @value{GDBN} that ship with Python scripting enabled have
25285prompt extensions. The commands for interacting with these extensions
25286are:
25287
25288@table @code
25289@kindex set extended-prompt
25290@item set extended-prompt @var{prompt}
25291Set an extended prompt that allows for substitutions.
25292@xref{gdb.prompt}, for a list of escape sequences that can be used for
25293substitution. Any escape sequences specified as part of the prompt
25294string are replaced with the corresponding strings each time the prompt
25295is displayed.
25296
25297For example:
25298
25299@smallexample
25300set extended-prompt Current working directory: \w (gdb)
25301@end smallexample
25302
25303Note that when an extended-prompt is set, it takes control of the
25304@var{prompt_hook} hook. @xref{prompt_hook}, for further information.
25305
25306@kindex show extended-prompt
25307@item show extended-prompt
25308Prints the extended prompt. Any escape sequences specified as part of
25309the prompt string with @code{set extended-prompt}, are replaced with the
25310corresponding strings each time the prompt is displayed.
25311@end table
25312
8e04817f 25313@node Editing
79a6e687 25314@section Command Editing
8e04817f
AC
25315@cindex readline
25316@cindex command line editing
104c1213 25317
703663ab 25318@value{GDBN} reads its input commands via the @dfn{Readline} interface. This
8e04817f
AC
25319@sc{gnu} library provides consistent behavior for programs which provide a
25320command line interface to the user. Advantages are @sc{gnu} Emacs-style
25321or @dfn{vi}-style inline editing of commands, @code{csh}-like history
25322substitution, and a storage and recall of command history across
25323debugging sessions.
104c1213 25324
8e04817f
AC
25325You may control the behavior of command line editing in @value{GDBN} with the
25326command @code{set}.
104c1213 25327
8e04817f
AC
25328@table @code
25329@kindex set editing
25330@cindex editing
25331@item set editing
25332@itemx set editing on
25333Enable command line editing (enabled by default).
104c1213 25334
8e04817f
AC
25335@item set editing off
25336Disable command line editing.
104c1213 25337
8e04817f
AC
25338@kindex show editing
25339@item show editing
25340Show whether command line editing is enabled.
104c1213
JM
25341@end table
25342
39037522
TT
25343@ifset SYSTEM_READLINE
25344@xref{Command Line Editing, , , rluserman, GNU Readline Library},
25345@end ifset
25346@ifclear SYSTEM_READLINE
25347@xref{Command Line Editing},
25348@end ifclear
25349for more details about the Readline
703663ab
EZ
25350interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
25351encouraged to read that chapter.
25352
11061048
TT
25353@cindex Readline application name
25354@value{GDBN} sets the Readline application name to @samp{gdb}. This
25355is useful for conditions in @file{.inputrc}.
25356
c71acd15
TT
25357@cindex operate-and-get-next
25358@value{GDBN} defines a bindable Readline command,
25359@code{operate-and-get-next}. This is bound to @kbd{C-o} by default.
25360This command accepts the current line for execution and fetches the
25361next line relative to the current line from the history for editing.
25362Any argument is ignored.
25363
d620b259 25364@node Command History
79a6e687 25365@section Command History
703663ab 25366@cindex command history
8e04817f
AC
25367
25368@value{GDBN} can keep track of the commands you type during your
25369debugging sessions, so that you can be certain of precisely what
25370happened. Use these commands to manage the @value{GDBN} command
25371history facility.
104c1213 25372
703663ab 25373@value{GDBN} uses the @sc{gnu} History library, a part of the Readline
39037522
TT
25374package, to provide the history facility.
25375@ifset SYSTEM_READLINE
25376@xref{Using History Interactively, , , history, GNU History Library},
25377@end ifset
25378@ifclear SYSTEM_READLINE
25379@xref{Using History Interactively},
25380@end ifclear
25381for the detailed description of the History library.
703663ab 25382
d620b259 25383To issue a command to @value{GDBN} without affecting certain aspects of
9e6c4bd5
NR
25384the state which is seen by users, prefix it with @samp{server }
25385(@pxref{Server Prefix}). This
d620b259
NR
25386means that this command will not affect the command history, nor will it
25387affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
25388pressed on a line by itself.
25389
25390@cindex @code{server}, command prefix
25391The server prefix does not affect the recording of values into the value
25392history; to print a value without recording it into the value history,
25393use the @code{output} command instead of the @code{print} command.
25394
703663ab
EZ
25395Here is the description of @value{GDBN} commands related to command
25396history.
25397
104c1213 25398@table @code
8e04817f
AC
25399@cindex history substitution
25400@cindex history file
25401@kindex set history filename
4644b6e3 25402@cindex @env{GDBHISTFILE}, environment variable
63e163f2 25403@item set history filename @r{[}@var{fname}@r{]}
8e04817f
AC
25404Set the name of the @value{GDBN} command history file to @var{fname}.
25405This is the file where @value{GDBN} reads an initial command history
25406list, and where it writes the command history from this session when it
25407exits. You can access this list through history expansion or through
25408the history command editing characters listed below. This file defaults
25409to the value of the environment variable @code{GDBHISTFILE}, or to
25410@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
25411is not set.
104c1213 25412
63e163f2
AB
25413The @code{GDBHISTFILE} environment variable is read after processing
25414any @value{GDBN} initialization files (@pxref{Startup}) and after
25415processing any commands passed using command line options (for
25416example, @code{-ex}).
25417
25418If the @var{fname} argument is not given, or if the @code{GDBHISTFILE}
25419is the empty string then @value{GDBN} will neither try to load an
25420existing history file, nor will it try to save the history on exit.
25421
9c16f35a
EZ
25422@cindex save command history
25423@kindex set history save
8e04817f
AC
25424@item set history save
25425@itemx set history save on
25426Record command history in a file, whose name may be specified with the
63e163f2
AB
25427@code{set history filename} command. By default, this option is
25428disabled. The command history will be recorded when @value{GDBN}
25429exits. If @code{set history filename} is set to the empty string then
25430history saving is disabled, even when @code{set history save} is
25431@code{on}.
104c1213 25432
8e04817f 25433@item set history save off
63e163f2
AB
25434Don't record the command history into the file specified by @code{set
25435history filename} when @value{GDBN} exits.
104c1213 25436
8e04817f 25437@cindex history size
9c16f35a 25438@kindex set history size
b58c513b 25439@cindex @env{GDBHISTSIZE}, environment variable
8e04817f 25440@item set history size @var{size}
f81d1120 25441@itemx set history size unlimited
8e04817f 25442Set the number of commands which @value{GDBN} keeps in its history list.
bc460514
PP
25443This defaults to the value of the environment variable @env{GDBHISTSIZE}, or
25444to 256 if this variable is not set. Non-numeric values of @env{GDBHISTSIZE}
0eacb298
PP
25445are ignored. If @var{size} is @code{unlimited} or if @env{GDBHISTSIZE} is
25446either a negative number or the empty string, then the number of commands
25447@value{GDBN} keeps in the history list is unlimited.
fc637f04 25448
63e163f2
AB
25449The @code{GDBHISTSIZE} environment variable is read after processing
25450any @value{GDBN} initialization files (@pxref{Startup}) and after
25451processing any commands passed using command line options (for
25452example, @code{-ex}).
25453
fc637f04
PP
25454@cindex remove duplicate history
25455@kindex set history remove-duplicates
25456@item set history remove-duplicates @var{count}
25457@itemx set history remove-duplicates unlimited
25458Control the removal of duplicate history entries in the command history list.
25459If @var{count} is non-zero, @value{GDBN} will look back at the last @var{count}
25460history entries and remove the first entry that is a duplicate of the current
25461entry being added to the command history list. If @var{count} is
25462@code{unlimited} then this lookbehind is unbounded. If @var{count} is 0, then
25463removal of duplicate history entries is disabled.
25464
25465Only history entries added during the current session are considered for
25466removal. This option is set to 0 by default.
25467
104c1213
JM
25468@end table
25469
8e04817f 25470History expansion assigns special meaning to the character @kbd{!}.
39037522
TT
25471@ifset SYSTEM_READLINE
25472@xref{Event Designators, , , history, GNU History Library},
25473@end ifset
25474@ifclear SYSTEM_READLINE
25475@xref{Event Designators},
25476@end ifclear
25477for more details.
8e04817f 25478
703663ab 25479@cindex history expansion, turn on/off
8e04817f
AC
25480Since @kbd{!} is also the logical not operator in C, history expansion
25481is off by default. If you decide to enable history expansion with the
25482@code{set history expansion on} command, you may sometimes need to
25483follow @kbd{!} (when it is used as logical not, in an expression) with
25484a space or a tab to prevent it from being expanded. The readline
25485history facilities do not attempt substitution on the strings
25486@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
25487
25488The commands to control history expansion are:
104c1213
JM
25489
25490@table @code
8e04817f
AC
25491@item set history expansion on
25492@itemx set history expansion
703663ab 25493@kindex set history expansion
8e04817f 25494Enable history expansion. History expansion is off by default.
104c1213 25495
8e04817f
AC
25496@item set history expansion off
25497Disable history expansion.
104c1213 25498
8e04817f
AC
25499@c @group
25500@kindex show history
25501@item show history
25502@itemx show history filename
25503@itemx show history save
25504@itemx show history size
25505@itemx show history expansion
25506These commands display the state of the @value{GDBN} history parameters.
25507@code{show history} by itself displays all four states.
25508@c @end group
25509@end table
25510
25511@table @code
9c16f35a
EZ
25512@kindex show commands
25513@cindex show last commands
25514@cindex display command history
8e04817f
AC
25515@item show commands
25516Display the last ten commands in the command history.
104c1213 25517
8e04817f
AC
25518@item show commands @var{n}
25519Print ten commands centered on command number @var{n}.
25520
25521@item show commands +
25522Print ten commands just after the commands last printed.
104c1213
JM
25523@end table
25524
8e04817f 25525@node Screen Size
79a6e687 25526@section Screen Size
8e04817f 25527@cindex size of screen
f179cf97
EZ
25528@cindex screen size
25529@cindex pagination
25530@cindex page size
8e04817f 25531@cindex pauses in output
104c1213 25532
8e04817f
AC
25533Certain commands to @value{GDBN} may produce large amounts of
25534information output to the screen. To help you read all of it,
25535@value{GDBN} pauses and asks you for input at the end of each page of
eb6af809
TT
25536output. Type @key{RET} when you want to see one more page of output,
25537@kbd{q} to discard the remaining output, or @kbd{c} to continue
25538without paging for the rest of the current command. Also, the screen
25539width setting determines when to wrap lines of output. Depending on
25540what is being printed, @value{GDBN} tries to break the line at a
25541readable place, rather than simply letting it overflow onto the
25542following line.
8e04817f
AC
25543
25544Normally @value{GDBN} knows the size of the screen from the terminal
25545driver software. For example, on Unix @value{GDBN} uses the termcap data base
25546together with the value of the @code{TERM} environment variable and the
25547@code{stty rows} and @code{stty cols} settings. If this is not correct,
25548you can override it with the @code{set height} and @code{set
25549width} commands:
25550
25551@table @code
25552@kindex set height
25553@kindex set width
25554@kindex show width
25555@kindex show height
25556@item set height @var{lpp}
f81d1120 25557@itemx set height unlimited
8e04817f
AC
25558@itemx show height
25559@itemx set width @var{cpl}
f81d1120 25560@itemx set width unlimited
8e04817f
AC
25561@itemx show width
25562These @code{set} commands specify a screen height of @var{lpp} lines and
25563a screen width of @var{cpl} characters. The associated @code{show}
25564commands display the current settings.
104c1213 25565
f81d1120
PA
25566If you specify a height of either @code{unlimited} or zero lines,
25567@value{GDBN} does not pause during output no matter how long the
25568output is. This is useful if output is to a file or to an editor
25569buffer.
104c1213 25570
f81d1120
PA
25571Likewise, you can specify @samp{set width unlimited} or @samp{set
25572width 0} to prevent @value{GDBN} from wrapping its output.
9c16f35a
EZ
25573
25574@item set pagination on
25575@itemx set pagination off
25576@kindex set pagination
25577Turn the output pagination on or off; the default is on. Turning
f81d1120 25578pagination off is the alternative to @code{set height unlimited}. Note that
7c953934
TT
25579running @value{GDBN} with the @option{--batch} option (@pxref{Mode
25580Options, -batch}) also automatically disables pagination.
9c16f35a
EZ
25581
25582@item show pagination
25583@kindex show pagination
25584Show the current pagination mode.
104c1213
JM
25585@end table
25586
140a4bc0
TT
25587@node Output Styling
25588@section Output Styling
25589@cindex styling
25590@cindex colors
25591
25592@kindex set style
25593@kindex show style
25594@value{GDBN} can style its output on a capable terminal. This is
7557a514
AH
25595enabled by default on most systems, but disabled by default when in
25596batch mode (@pxref{Mode Options}). Various style settings are available;
25597and styles can also be disabled entirely.
140a4bc0
TT
25598
25599@table @code
25600@item set style enabled @samp{on|off}
25601Enable or disable all styling. The default is host-dependent, with
25602most hosts defaulting to @samp{on}.
25603
25604@item show style enabled
25605Show the current state of styling.
d085f989
TT
25606
25607@item set style sources @samp{on|off}
25608Enable or disable source code styling. This affects whether source
25609code, such as the output of the @code{list} command, is styled. Note
25610that source styling only works if styling in general is enabled, and
25611if @value{GDBN} was linked with the GNU Source Highlight library. The
25612default is @samp{on}.
25613
25614@item show style sources
25615Show the current state of source code styling.
140a4bc0
TT
25616@end table
25617
25618Subcommands of @code{set style} control specific forms of styling.
25619These subcommands all follow the same pattern: each style-able object
25620can be styled with a foreground color, a background color, and an
25621intensity.
25622
25623For example, the style of file names can be controlled using the
25624@code{set style filename} group of commands:
25625
25626@table @code
25627@item set style filename background @var{color}
25628Set the background to @var{color}. Valid colors are @samp{none}
25629(meaning the terminal's default color), @samp{black}, @samp{red},
e3624a40 25630@samp{green}, @samp{yellow}, @samp{blue}, @samp{magenta}, @samp{cyan},
140a4bc0
TT
25631and@samp{white}.
25632
25633@item set style filename foreground @var{color}
25634Set the foreground to @var{color}. Valid colors are @samp{none}
25635(meaning the terminal's default color), @samp{black}, @samp{red},
e3624a40 25636@samp{green}, @samp{yellow}, @samp{blue}, @samp{magenta}, @samp{cyan},
140a4bc0
TT
25637and@samp{white}.
25638
25639@item set style filename intensity @var{value}
25640Set the intensity to @var{value}. Valid intensities are @samp{normal}
25641(the default), @samp{bold}, and @samp{dim}.
25642@end table
25643
e664d728
PW
25644The @code{show style} command and its subcommands are styling
25645a style name in their output using its own style.
25646So, use @command{show style} to see the complete list of styles,
25647their characteristics and the visual aspect of each style.
25648
140a4bc0
TT
25649The style-able objects are:
25650@table @code
25651@item filename
e3624a40
EZ
25652Control the styling of file names. By default, this style's
25653foreground color is green.
140a4bc0
TT
25654
25655@item function
25656Control the styling of function names. These are managed with the
e3624a40
EZ
25657@code{set style function} family of commands. By default, this
25658style's foreground color is yellow.
140a4bc0
TT
25659
25660@item variable
25661Control the styling of variable names. These are managed with the
e3624a40
EZ
25662@code{set style variable} family of commands. By default, this style's
25663foreground color is cyan.
140a4bc0
TT
25664
25665@item address
25666Control the styling of addresses. These are managed with the
e3624a40
EZ
25667@code{set style address} family of commands. By default, this style's
25668foreground color is blue.
e664d728
PW
25669
25670@item title
25671Control the styling of titles. These are managed with the
25672@code{set style title} family of commands. By default, this style's
25673intensity is bold. Commands are using the title style to improve
6b92c0d3 25674the readability of large output. For example, the commands
e664d728
PW
25675@command{apropos} and @command{help} are using the title style
25676for the command names.
25677
25678@item highlight
25679Control the styling of highlightings. These are managed with the
25680@code{set style highlight} family of commands. By default, this style's
25681foreground color is red. Commands are using the highlight style to draw
25682the user attention to some specific parts of their output. For example,
25683the command @command{apropos -v REGEXP} uses the highlight style to
25684mark the documentation parts matching @var{regexp}.
25685
a2a7af0c
TT
25686@item tui-border
25687Control the styling of the TUI border. Note that, unlike other
25688styling options, only the color of the border can be controlled via
25689@code{set style}. This was done for compatibility reasons, as TUI
25690controls to set the border's intensity predated the addition of
25691general styling to @value{GDBN}. @xref{TUI Configuration}.
25692
25693@item tui-active-border
25694Control the styling of the active TUI border; that is, the TUI window
25695that has the focus.
25696
140a4bc0
TT
25697@end table
25698
8e04817f
AC
25699@node Numbers
25700@section Numbers
25701@cindex number representation
25702@cindex entering numbers
104c1213 25703
8e04817f
AC
25704You can always enter numbers in octal, decimal, or hexadecimal in
25705@value{GDBN} by the usual conventions: octal numbers begin with
25706@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
eb2dae08
EZ
25707begin with @samp{0x}. Numbers that neither begin with @samp{0} or
25708@samp{0x}, nor end with a @samp{.} are, by default, entered in base
2570910; likewise, the default display for numbers---when no particular
25710format is specified---is base 10. You can change the default base for
25711both input and output with the commands described below.
104c1213 25712
8e04817f
AC
25713@table @code
25714@kindex set input-radix
25715@item set input-radix @var{base}
25716Set the default base for numeric input. Supported choices
697aa1b7 25717for @var{base} are decimal 8, 10, or 16. The base must itself be
eb2dae08 25718specified either unambiguously or using the current input radix; for
8e04817f 25719example, any of
104c1213 25720
8e04817f 25721@smallexample
9c16f35a
EZ
25722set input-radix 012
25723set input-radix 10.
25724set input-radix 0xa
8e04817f 25725@end smallexample
104c1213 25726
8e04817f 25727@noindent
9c16f35a 25728sets the input base to decimal. On the other hand, @samp{set input-radix 10}
eb2dae08
EZ
25729leaves the input radix unchanged, no matter what it was, since
25730@samp{10}, being without any leading or trailing signs of its base, is
25731interpreted in the current radix. Thus, if the current radix is 16,
25732@samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
25733change the radix.
104c1213 25734
8e04817f
AC
25735@kindex set output-radix
25736@item set output-radix @var{base}
25737Set the default base for numeric display. Supported choices
697aa1b7 25738for @var{base} are decimal 8, 10, or 16. The base must itself be
eb2dae08 25739specified either unambiguously or using the current input radix.
104c1213 25740
8e04817f
AC
25741@kindex show input-radix
25742@item show input-radix
25743Display the current default base for numeric input.
104c1213 25744
8e04817f
AC
25745@kindex show output-radix
25746@item show output-radix
25747Display the current default base for numeric display.
9c16f35a
EZ
25748
25749@item set radix @r{[}@var{base}@r{]}
25750@itemx show radix
25751@kindex set radix
25752@kindex show radix
25753These commands set and show the default base for both input and output
25754of numbers. @code{set radix} sets the radix of input and output to
25755the same base; without an argument, it resets the radix back to its
25756default value of 10.
25757
8e04817f 25758@end table
104c1213 25759
1e698235 25760@node ABI
79a6e687 25761@section Configuring the Current ABI
1e698235
DJ
25762
25763@value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
25764application automatically. However, sometimes you need to override its
25765conclusions. Use these commands to manage @value{GDBN}'s view of the
25766current ABI.
25767
98b45e30
DJ
25768@cindex OS ABI
25769@kindex set osabi
b4e9345d 25770@kindex show osabi
430ed3f0 25771@cindex Newlib OS ABI and its influence on the longjmp handling
98b45e30
DJ
25772
25773One @value{GDBN} configuration can debug binaries for multiple operating
b383017d 25774system targets, either via remote debugging or native emulation.
98b45e30
DJ
25775@value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
25776but you can override its conclusion using the @code{set osabi} command.
25777One example where this is useful is in debugging of binaries which use
25778an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
25779not have the same identifying marks that the standard C library for your
25780platform provides.
25781
430ed3f0
MS
25782When @value{GDBN} is debugging the AArch64 architecture, it provides a
25783``Newlib'' OS ABI. This is useful for handling @code{setjmp} and
25784@code{longjmp} when debugging binaries that use the @sc{newlib} C library.
25785The ``Newlib'' OS ABI can be selected by @code{set osabi Newlib}.
25786
98b45e30
DJ
25787@table @code
25788@item show osabi
25789Show the OS ABI currently in use.
25790
25791@item set osabi
25792With no argument, show the list of registered available OS ABI's.
25793
25794@item set osabi @var{abi}
25795Set the current OS ABI to @var{abi}.
25796@end table
25797
1e698235 25798@cindex float promotion
1e698235
DJ
25799
25800Generally, the way that an argument of type @code{float} is passed to a
25801function depends on whether the function is prototyped. For a prototyped
25802(i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
25803according to the architecture's convention for @code{float}. For unprototyped
25804(i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
25805@code{double} and then passed.
25806
25807Unfortunately, some forms of debug information do not reliably indicate whether
25808a function is prototyped. If @value{GDBN} calls a function that is not marked
25809as prototyped, it consults @kbd{set coerce-float-to-double}.
25810
25811@table @code
a8f24a35 25812@kindex set coerce-float-to-double
1e698235
DJ
25813@item set coerce-float-to-double
25814@itemx set coerce-float-to-double on
25815Arguments of type @code{float} will be promoted to @code{double} when passed
25816to an unprototyped function. This is the default setting.
25817
25818@item set coerce-float-to-double off
25819Arguments of type @code{float} will be passed directly to unprototyped
25820functions.
9c16f35a
EZ
25821
25822@kindex show coerce-float-to-double
25823@item show coerce-float-to-double
25824Show the current setting of promoting @code{float} to @code{double}.
1e698235
DJ
25825@end table
25826
f1212245
DJ
25827@kindex set cp-abi
25828@kindex show cp-abi
25829@value{GDBN} needs to know the ABI used for your program's C@t{++}
25830objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
25831used to build your application. @value{GDBN} only fully supports
25832programs with a single C@t{++} ABI; if your program contains code using
25833multiple C@t{++} ABI's or if @value{GDBN} can not identify your
25834program's ABI correctly, you can tell @value{GDBN} which ABI to use.
25835Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
25836before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
25837``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
25838use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
25839``auto''.
25840
25841@table @code
25842@item show cp-abi
25843Show the C@t{++} ABI currently in use.
25844
25845@item set cp-abi
25846With no argument, show the list of supported C@t{++} ABI's.
25847
25848@item set cp-abi @var{abi}
25849@itemx set cp-abi auto
25850Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
25851@end table
25852
bf88dd68
JK
25853@node Auto-loading
25854@section Automatically loading associated files
25855@cindex auto-loading
25856
25857@value{GDBN} sometimes reads files with commands and settings automatically,
25858without being explicitly told so by the user. We call this feature
25859@dfn{auto-loading}. While auto-loading is useful for automatically adapting
25860@value{GDBN} to the needs of your project, it can sometimes produce unexpected
25861results or introduce security risks (e.g., if the file comes from untrusted
25862sources).
25863
71b8c845
DE
25864@menu
25865* Init File in the Current Directory:: @samp{set/show/info auto-load local-gdbinit}
25866* libthread_db.so.1 file:: @samp{set/show/info auto-load libthread-db}
25867
25868* Auto-loading safe path:: @samp{set/show/info auto-load safe-path}
25869* Auto-loading verbose mode:: @samp{set/show debug auto-load}
25870@end menu
25871
25872There are various kinds of files @value{GDBN} can automatically load.
25873In addition to these files, @value{GDBN} supports auto-loading code written
25874in various extension languages. @xref{Auto-loading extensions}.
25875
c1668e4e
JK
25876Note that loading of these associated files (including the local @file{.gdbinit}
25877file) requires accordingly configured @code{auto-load safe-path}
25878(@pxref{Auto-loading safe path}).
25879
bf88dd68
JK
25880For these reasons, @value{GDBN} includes commands and options to let you
25881control when to auto-load files and which files should be auto-loaded.
25882
25883@table @code
25884@anchor{set auto-load off}
25885@kindex set auto-load off
25886@item set auto-load off
25887Globally disable loading of all auto-loaded files.
25888You may want to use this command with the @samp{-iex} option
25889(@pxref{Option -init-eval-command}) such as:
25890@smallexample
25891$ @kbd{gdb -iex "set auto-load off" untrusted-executable corefile}
25892@end smallexample
25893
25894Be aware that system init file (@pxref{System-wide configuration})
25895and init files from your home directory (@pxref{Home Directory Init File})
25896still get read (as they come from generally trusted directories).
25897To prevent @value{GDBN} from auto-loading even those init files, use the
25898@option{-nx} option (@pxref{Mode Options}), in addition to
25899@code{set auto-load no}.
25900
25901@anchor{show auto-load}
25902@kindex show auto-load
25903@item show auto-load
25904Show whether auto-loading of each specific @samp{auto-load} file(s) is enabled
25905or disabled.
25906
25907@smallexample
25908(gdb) show auto-load
25909gdb-scripts: Auto-loading of canned sequences of commands scripts is on.
25910libthread-db: Auto-loading of inferior specific libthread_db is on.
1ccacbcd
JK
25911local-gdbinit: Auto-loading of .gdbinit script from current directory
25912 is on.
bf88dd68 25913python-scripts: Auto-loading of Python scripts is on.
bccbefd2 25914safe-path: List of directories from which it is safe to auto-load files
1564a261 25915 is $debugdir:$datadir/auto-load.
7349ff92 25916scripts-directory: List of directories from which to load auto-loaded scripts
1564a261 25917 is $debugdir:$datadir/auto-load.
bf88dd68
JK
25918@end smallexample
25919
25920@anchor{info auto-load}
25921@kindex info auto-load
25922@item info auto-load
25923Print whether each specific @samp{auto-load} file(s) have been auto-loaded or
25924not.
25925
25926@smallexample
25927(gdb) info auto-load
25928gdb-scripts:
25929Loaded Script
25930Yes /home/user/gdb/gdb-gdb.gdb
25931libthread-db: No auto-loaded libthread-db.
1ccacbcd
JK
25932local-gdbinit: Local .gdbinit file "/home/user/gdb/.gdbinit" has been
25933 loaded.
bf88dd68
JK
25934python-scripts:
25935Loaded Script
25936Yes /home/user/gdb/gdb-gdb.py
25937@end smallexample
25938@end table
25939
bf88dd68
JK
25940These are @value{GDBN} control commands for the auto-loading:
25941
25942@multitable @columnfractions .5 .5
25943@item @xref{set auto-load off}.
25944@tab Disable auto-loading globally.
25945@item @xref{show auto-load}.
25946@tab Show setting of all kinds of files.
25947@item @xref{info auto-load}.
25948@tab Show state of all kinds of files.
25949@item @xref{set auto-load gdb-scripts}.
25950@tab Control for @value{GDBN} command scripts.
25951@item @xref{show auto-load gdb-scripts}.
25952@tab Show setting of @value{GDBN} command scripts.
25953@item @xref{info auto-load gdb-scripts}.
25954@tab Show state of @value{GDBN} command scripts.
25955@item @xref{set auto-load python-scripts}.
25956@tab Control for @value{GDBN} Python scripts.
25957@item @xref{show auto-load python-scripts}.
25958@tab Show setting of @value{GDBN} Python scripts.
25959@item @xref{info auto-load python-scripts}.
25960@tab Show state of @value{GDBN} Python scripts.
ed3ef339
DE
25961@item @xref{set auto-load guile-scripts}.
25962@tab Control for @value{GDBN} Guile scripts.
25963@item @xref{show auto-load guile-scripts}.
25964@tab Show setting of @value{GDBN} Guile scripts.
25965@item @xref{info auto-load guile-scripts}.
25966@tab Show state of @value{GDBN} Guile scripts.
7349ff92
JK
25967@item @xref{set auto-load scripts-directory}.
25968@tab Control for @value{GDBN} auto-loaded scripts location.
25969@item @xref{show auto-load scripts-directory}.
25970@tab Show @value{GDBN} auto-loaded scripts location.
f10c5b19
JK
25971@item @xref{add-auto-load-scripts-directory}.
25972@tab Add directory for auto-loaded scripts location list.
bf88dd68
JK
25973@item @xref{set auto-load local-gdbinit}.
25974@tab Control for init file in the current directory.
25975@item @xref{show auto-load local-gdbinit}.
25976@tab Show setting of init file in the current directory.
25977@item @xref{info auto-load local-gdbinit}.
25978@tab Show state of init file in the current directory.
25979@item @xref{set auto-load libthread-db}.
25980@tab Control for thread debugging library.
25981@item @xref{show auto-load libthread-db}.
25982@tab Show setting of thread debugging library.
25983@item @xref{info auto-load libthread-db}.
25984@tab Show state of thread debugging library.
bccbefd2
JK
25985@item @xref{set auto-load safe-path}.
25986@tab Control directories trusted for automatic loading.
25987@item @xref{show auto-load safe-path}.
25988@tab Show directories trusted for automatic loading.
25989@item @xref{add-auto-load-safe-path}.
25990@tab Add directory trusted for automatic loading.
bf88dd68
JK
25991@end multitable
25992
bf88dd68
JK
25993@node Init File in the Current Directory
25994@subsection Automatically loading init file in the current directory
25995@cindex auto-loading init file in the current directory
25996
25997By default, @value{GDBN} reads and executes the canned sequences of commands
25998from init file (if any) in the current working directory,
25999see @ref{Init File in the Current Directory during Startup}.
26000
c1668e4e
JK
26001Note that loading of this local @file{.gdbinit} file also requires accordingly
26002configured @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
26003
bf88dd68
JK
26004@table @code
26005@anchor{set auto-load local-gdbinit}
26006@kindex set auto-load local-gdbinit
26007@item set auto-load local-gdbinit [on|off]
26008Enable or disable the auto-loading of canned sequences of commands
26009(@pxref{Sequences}) found in init file in the current directory.
26010
26011@anchor{show auto-load local-gdbinit}
26012@kindex show auto-load local-gdbinit
26013@item show auto-load local-gdbinit
26014Show whether auto-loading of canned sequences of commands from init file in the
26015current directory is enabled or disabled.
26016
26017@anchor{info auto-load local-gdbinit}
26018@kindex info auto-load local-gdbinit
26019@item info auto-load local-gdbinit
26020Print whether canned sequences of commands from init file in the
26021current directory have been auto-loaded.
26022@end table
26023
26024@node libthread_db.so.1 file
26025@subsection Automatically loading thread debugging library
26026@cindex auto-loading libthread_db.so.1
26027
26028This feature is currently present only on @sc{gnu}/Linux native hosts.
26029
26030@value{GDBN} reads in some cases thread debugging library from places specific
26031to the inferior (@pxref{set libthread-db-search-path}).
26032
26033The special @samp{libthread-db-search-path} entry @samp{$sdir} is processed
26034without checking this @samp{set auto-load libthread-db} switch as system
26035libraries have to be trusted in general. In all other cases of
26036@samp{libthread-db-search-path} entries @value{GDBN} checks first if @samp{set
26037auto-load libthread-db} is enabled before trying to open such thread debugging
26038library.
26039
c1668e4e
JK
26040Note that loading of this debugging library also requires accordingly configured
26041@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
26042
bf88dd68
JK
26043@table @code
26044@anchor{set auto-load libthread-db}
26045@kindex set auto-load libthread-db
26046@item set auto-load libthread-db [on|off]
26047Enable or disable the auto-loading of inferior specific thread debugging library.
26048
26049@anchor{show auto-load libthread-db}
26050@kindex show auto-load libthread-db
26051@item show auto-load libthread-db
26052Show whether auto-loading of inferior specific thread debugging library is
26053enabled or disabled.
26054
26055@anchor{info auto-load libthread-db}
26056@kindex info auto-load libthread-db
26057@item info auto-load libthread-db
26058Print the list of all loaded inferior specific thread debugging libraries and
26059for each such library print list of inferior @var{pid}s using it.
26060@end table
26061
bccbefd2
JK
26062@node Auto-loading safe path
26063@subsection Security restriction for auto-loading
26064@cindex auto-loading safe-path
26065
26066As the files of inferior can come from untrusted source (such as submitted by
26067an application user) @value{GDBN} does not always load any files automatically.
26068@value{GDBN} provides the @samp{set auto-load safe-path} setting to list
26069directories trusted for loading files not explicitly requested by user.
202cbf1c 26070Each directory can also be a shell wildcard pattern.
bccbefd2
JK
26071
26072If the path is not set properly you will see a warning and the file will not
26073get loaded:
26074
26075@smallexample
26076$ ./gdb -q ./gdb
0bab6cf1 26077Reading symbols from /home/user/gdb/gdb...
bccbefd2 26078warning: File "/home/user/gdb/gdb-gdb.gdb" auto-loading has been
1564a261
JK
26079 declined by your `auto-load safe-path' set
26080 to "$debugdir:$datadir/auto-load".
bccbefd2 26081warning: File "/home/user/gdb/gdb-gdb.py" auto-loading has been
1564a261
JK
26082 declined by your `auto-load safe-path' set
26083 to "$debugdir:$datadir/auto-load".
bccbefd2
JK
26084@end smallexample
26085
2c91021c
JK
26086@noindent
26087To instruct @value{GDBN} to go ahead and use the init files anyway,
26088invoke @value{GDBN} like this:
26089
26090@smallexample
26091$ gdb -q -iex "set auto-load safe-path /home/user/gdb" ./gdb
26092@end smallexample
26093
bccbefd2
JK
26094The list of trusted directories is controlled by the following commands:
26095
26096@table @code
26097@anchor{set auto-load safe-path}
26098@kindex set auto-load safe-path
af2c1515 26099@item set auto-load safe-path @r{[}@var{directories}@r{]}
bccbefd2
JK
26100Set the list of directories (and their subdirectories) trusted for automatic
26101loading and execution of scripts. You can also enter a specific trusted file.
202cbf1c
JK
26102Each directory can also be a shell wildcard pattern; wildcards do not match
26103directory separator - see @code{FNM_PATHNAME} for system function @code{fnmatch}
26104(@pxref{Wildcard Matching, fnmatch, , libc, GNU C Library Reference Manual}).
af2c1515
JK
26105If you omit @var{directories}, @samp{auto-load safe-path} will be reset to
26106its default value as specified during @value{GDBN} compilation.
26107
d9242c17 26108The list of directories uses path separator (@samp{:} on GNU and Unix
bccbefd2
JK
26109systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
26110to the @env{PATH} environment variable.
26111
26112@anchor{show auto-load safe-path}
26113@kindex show auto-load safe-path
26114@item show auto-load safe-path
26115Show the list of directories trusted for automatic loading and execution of
26116scripts.
26117
26118@anchor{add-auto-load-safe-path}
26119@kindex add-auto-load-safe-path
26120@item add-auto-load-safe-path
413b59ae
JK
26121Add an entry (or list of entries) to the list of directories trusted for
26122automatic loading and execution of scripts. Multiple entries may be delimited
26123by the host platform path separator in use.
bccbefd2
JK
26124@end table
26125
7349ff92 26126This variable defaults to what @code{--with-auto-load-dir} has been configured
1564a261
JK
26127to (@pxref{with-auto-load-dir}). @file{$debugdir} and @file{$datadir}
26128substitution applies the same as for @ref{set auto-load scripts-directory}.
26129The default @code{set auto-load safe-path} value can be also overriden by
26130@value{GDBN} configuration option @option{--with-auto-load-safe-path}.
6dea1fbd 26131
6dea1fbd
JK
26132Setting this variable to @file{/} disables this security protection,
26133corresponding @value{GDBN} configuration option is
26134@option{--without-auto-load-safe-path}.
bccbefd2
JK
26135This variable is supposed to be set to the system directories writable by the
26136system superuser only. Users can add their source directories in init files in
26137their home directories (@pxref{Home Directory Init File}). See also deprecated
26138init file in the current directory
26139(@pxref{Init File in the Current Directory during Startup}).
26140
26141To force @value{GDBN} to load the files it declined to load in the previous
26142example, you could use one of the following ways:
26143
0511cc75
JK
26144@table @asis
26145@item @file{~/.gdbinit}: @samp{add-auto-load-safe-path ~/src/gdb}
bccbefd2
JK
26146Specify this trusted directory (or a file) as additional component of the list.
26147You have to specify also any existing directories displayed by
26148by @samp{show auto-load safe-path} (such as @samp{/usr:/bin} in this example).
26149
174bb630 26150@item @kbd{gdb -iex "set auto-load safe-path /usr:/bin:~/src/gdb" @dots{}}
bccbefd2
JK
26151Specify this directory as in the previous case but just for a single
26152@value{GDBN} session.
26153
af2c1515 26154@item @kbd{gdb -iex "set auto-load safe-path /" @dots{}}
bccbefd2
JK
26155Disable auto-loading safety for a single @value{GDBN} session.
26156This assumes all the files you debug during this @value{GDBN} session will come
26157from trusted sources.
26158
26159@item @kbd{./configure --without-auto-load-safe-path}
26160During compilation of @value{GDBN} you may disable any auto-loading safety.
26161This assumes all the files you will ever debug with this @value{GDBN} come from
26162trusted sources.
0511cc75 26163@end table
bccbefd2
JK
26164
26165On the other hand you can also explicitly forbid automatic files loading which
26166also suppresses any such warning messages:
26167
0511cc75 26168@table @asis
174bb630 26169@item @kbd{gdb -iex "set auto-load no" @dots{}}
bccbefd2
JK
26170You can use @value{GDBN} command-line option for a single @value{GDBN} session.
26171
0511cc75 26172@item @file{~/.gdbinit}: @samp{set auto-load no}
bccbefd2
JK
26173Disable auto-loading globally for the user
26174(@pxref{Home Directory Init File}). While it is improbable, you could also
26175use system init file instead (@pxref{System-wide configuration}).
0511cc75 26176@end table
bccbefd2
JK
26177
26178This setting applies to the file names as entered by user. If no entry matches
26179@value{GDBN} tries as a last resort to also resolve all the file names into
26180their canonical form (typically resolving symbolic links) and compare the
26181entries again. @value{GDBN} already canonicalizes most of the filenames on its
26182own before starting the comparison so a canonical form of directories is
26183recommended to be entered.
26184
4dc84fd1
JK
26185@node Auto-loading verbose mode
26186@subsection Displaying files tried for auto-load
26187@cindex auto-loading verbose mode
26188
26189For better visibility of all the file locations where you can place scripts to
26190be auto-loaded with inferior --- or to protect yourself against accidental
26191execution of untrusted scripts --- @value{GDBN} provides a feature for printing
26192all the files attempted to be loaded. Both existing and non-existing files may
26193be printed.
26194
26195For example the list of directories from which it is safe to auto-load files
26196(@pxref{Auto-loading safe path}) applies also to canonicalized filenames which
26197may not be too obvious while setting it up.
26198
26199@smallexample
0070f25a 26200(gdb) set debug auto-load on
4dc84fd1
JK
26201(gdb) file ~/src/t/true
26202auto-load: Loading canned sequences of commands script "/tmp/true-gdb.gdb"
26203 for objfile "/tmp/true".
26204auto-load: Updating directories of "/usr:/opt".
26205auto-load: Using directory "/usr".
26206auto-load: Using directory "/opt".
26207warning: File "/tmp/true-gdb.gdb" auto-loading has been declined
26208 by your `auto-load safe-path' set to "/usr:/opt".
26209@end smallexample
26210
26211@table @code
26212@anchor{set debug auto-load}
26213@kindex set debug auto-load
26214@item set debug auto-load [on|off]
26215Set whether to print the filenames attempted to be auto-loaded.
26216
26217@anchor{show debug auto-load}
26218@kindex show debug auto-load
26219@item show debug auto-load
26220Show whether printing of the filenames attempted to be auto-loaded is turned
26221on or off.
26222@end table
26223
8e04817f 26224@node Messages/Warnings
79a6e687 26225@section Optional Warnings and Messages
104c1213 26226
9c16f35a
EZ
26227@cindex verbose operation
26228@cindex optional warnings
8e04817f
AC
26229By default, @value{GDBN} is silent about its inner workings. If you are
26230running on a slow machine, you may want to use the @code{set verbose}
26231command. This makes @value{GDBN} tell you when it does a lengthy
26232internal operation, so you will not think it has crashed.
104c1213 26233
8e04817f
AC
26234Currently, the messages controlled by @code{set verbose} are those
26235which announce that the symbol table for a source file is being read;
79a6e687 26236see @code{symbol-file} in @ref{Files, ,Commands to Specify Files}.
104c1213 26237
8e04817f
AC
26238@table @code
26239@kindex set verbose
26240@item set verbose on
26241Enables @value{GDBN} output of certain informational messages.
104c1213 26242
8e04817f
AC
26243@item set verbose off
26244Disables @value{GDBN} output of certain informational messages.
104c1213 26245
8e04817f
AC
26246@kindex show verbose
26247@item show verbose
26248Displays whether @code{set verbose} is on or off.
26249@end table
104c1213 26250
8e04817f
AC
26251By default, if @value{GDBN} encounters bugs in the symbol table of an
26252object file, it is silent; but if you are debugging a compiler, you may
79a6e687
BW
26253find this information useful (@pxref{Symbol Errors, ,Errors Reading
26254Symbol Files}).
104c1213 26255
8e04817f 26256@table @code
104c1213 26257
8e04817f
AC
26258@kindex set complaints
26259@item set complaints @var{limit}
26260Permits @value{GDBN} to output @var{limit} complaints about each type of
26261unusual symbols before becoming silent about the problem. Set
26262@var{limit} to zero to suppress all complaints; set it to a large number
26263to prevent complaints from being suppressed.
104c1213 26264
8e04817f
AC
26265@kindex show complaints
26266@item show complaints
26267Displays how many symbol complaints @value{GDBN} is permitted to produce.
104c1213 26268
8e04817f 26269@end table
104c1213 26270
d837706a 26271@anchor{confirmation requests}
8e04817f
AC
26272By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
26273lot of stupid questions to confirm certain commands. For example, if
26274you try to run a program which is already running:
104c1213 26275
474c8240 26276@smallexample
8e04817f
AC
26277(@value{GDBP}) run
26278The program being debugged has been started already.
26279Start it from the beginning? (y or n)
474c8240 26280@end smallexample
104c1213 26281
8e04817f
AC
26282If you are willing to unflinchingly face the consequences of your own
26283commands, you can disable this ``feature'':
104c1213 26284
8e04817f 26285@table @code
104c1213 26286
8e04817f
AC
26287@kindex set confirm
26288@cindex flinching
26289@cindex confirmation
26290@cindex stupid questions
26291@item set confirm off
7c953934
TT
26292Disables confirmation requests. Note that running @value{GDBN} with
26293the @option{--batch} option (@pxref{Mode Options, -batch}) also
26294automatically disables confirmation requests.
104c1213 26295
8e04817f
AC
26296@item set confirm on
26297Enables confirmation requests (the default).
104c1213 26298
8e04817f
AC
26299@kindex show confirm
26300@item show confirm
26301Displays state of confirmation requests.
26302
26303@end table
104c1213 26304
16026cd7
AS
26305@cindex command tracing
26306If you need to debug user-defined commands or sourced files you may find it
26307useful to enable @dfn{command tracing}. In this mode each command will be
26308printed as it is executed, prefixed with one or more @samp{+} symbols, the
26309quantity denoting the call depth of each command.
26310
26311@table @code
26312@kindex set trace-commands
26313@cindex command scripts, debugging
26314@item set trace-commands on
26315Enable command tracing.
26316@item set trace-commands off
26317Disable command tracing.
26318@item show trace-commands
26319Display the current state of command tracing.
26320@end table
26321
8e04817f 26322@node Debugging Output
79a6e687 26323@section Optional Messages about Internal Happenings
4644b6e3
EZ
26324@cindex optional debugging messages
26325
da316a69
EZ
26326@value{GDBN} has commands that enable optional debugging messages from
26327various @value{GDBN} subsystems; normally these commands are of
26328interest to @value{GDBN} maintainers, or when reporting a bug. This
26329section documents those commands.
26330
104c1213 26331@table @code
a8f24a35
EZ
26332@kindex set exec-done-display
26333@item set exec-done-display
26334Turns on or off the notification of asynchronous commands'
26335completion. When on, @value{GDBN} will print a message when an
26336asynchronous command finishes its execution. The default is off.
26337@kindex show exec-done-display
26338@item show exec-done-display
26339Displays the current setting of asynchronous command completion
26340notification.
4644b6e3 26341@kindex set debug
be9a8770
PA
26342@cindex ARM AArch64
26343@item set debug aarch64
26344Turns on or off display of debugging messages related to ARM AArch64.
26345The default is off.
26346@kindex show debug
26347@item show debug aarch64
26348Displays the current state of displaying debugging messages related to
26349ARM AArch64.
4644b6e3 26350@cindex gdbarch debugging info
a8f24a35 26351@cindex architecture debugging info
8e04817f 26352@item set debug arch
a8f24a35 26353Turns on or off display of gdbarch debugging info. The default is off
8e04817f
AC
26354@item show debug arch
26355Displays the current state of displaying gdbarch debugging info.
9a005eb9
JB
26356@item set debug aix-solib
26357@cindex AIX shared library debugging
26358Control display of debugging messages from the AIX shared library
26359support module. The default is off.
26360@item show debug aix-thread
26361Show the current state of displaying AIX shared library debugging messages.
721c2651
EZ
26362@item set debug aix-thread
26363@cindex AIX threads
26364Display debugging messages about inner workings of the AIX thread
26365module.
26366@item show debug aix-thread
26367Show the current state of AIX thread debugging info display.
900e11f9
JK
26368@item set debug check-physname
26369@cindex physname
26370Check the results of the ``physname'' computation. When reading DWARF
26371debugging information for C@t{++}, @value{GDBN} attempts to compute
26372each entity's name. @value{GDBN} can do this computation in two
26373different ways, depending on exactly what information is present.
26374When enabled, this setting causes @value{GDBN} to compute the names
26375both ways and display any discrepancies.
26376@item show debug check-physname
26377Show the current state of ``physname'' checking.
be9a8770
PA
26378@item set debug coff-pe-read
26379@cindex COFF/PE exported symbols
26380Control display of debugging messages related to reading of COFF/PE
26381exported symbols. The default is off.
26382@item show debug coff-pe-read
26383Displays the current state of displaying debugging messages related to
26384reading of COFF/PE exported symbols.
b4f54984
DE
26385@item set debug dwarf-die
26386@cindex DWARF DIEs
26387Dump DWARF DIEs after they are read in.
d97bc12b
DE
26388The value is the number of nesting levels to print.
26389A value of zero turns off the display.
b4f54984
DE
26390@item show debug dwarf-die
26391Show the current state of DWARF DIE debugging.
27e0867f
DE
26392@item set debug dwarf-line
26393@cindex DWARF Line Tables
26394Turns on or off display of debugging messages related to reading
26395DWARF line tables. The default is 0 (off).
26396A value of 1 provides basic information.
26397A value greater than 1 provides more verbose information.
26398@item show debug dwarf-line
26399Show the current state of DWARF line table debugging.
b4f54984
DE
26400@item set debug dwarf-read
26401@cindex DWARF Reading
45cfd468 26402Turns on or off display of debugging messages related to reading
73be47f5
DE
26403DWARF debug info. The default is 0 (off).
26404A value of 1 provides basic information.
26405A value greater than 1 provides more verbose information.
b4f54984
DE
26406@item show debug dwarf-read
26407Show the current state of DWARF reader debugging.
237fc4c9
PA
26408@item set debug displaced
26409@cindex displaced stepping debugging info
26410Turns on or off display of @value{GDBN} debugging info for the
26411displaced stepping support. The default is off.
26412@item show debug displaced
26413Displays the current state of displaying @value{GDBN} debugging info
26414related to displaced stepping.
8e04817f 26415@item set debug event
4644b6e3 26416@cindex event debugging info
a8f24a35 26417Turns on or off display of @value{GDBN} event debugging info. The
8e04817f 26418default is off.
8e04817f
AC
26419@item show debug event
26420Displays the current state of displaying @value{GDBN} event debugging
26421info.
8e04817f 26422@item set debug expression
4644b6e3 26423@cindex expression debugging info
721c2651
EZ
26424Turns on or off display of debugging info about @value{GDBN}
26425expression parsing. The default is off.
8e04817f 26426@item show debug expression
721c2651
EZ
26427Displays the current state of displaying debugging info about
26428@value{GDBN} expression parsing.
6e9567fe
JB
26429@item set debug fbsd-lwp
26430@cindex FreeBSD LWP debug messages
26431Turns on or off debugging messages from the FreeBSD LWP debug support.
26432@item show debug fbsd-lwp
26433Show the current state of FreeBSD LWP debugging messages.
386a8676
JB
26434@item set debug fbsd-nat
26435@cindex FreeBSD native target debug messages
26436Turns on or off debugging messages from the FreeBSD native target.
26437@item show debug fbsd-nat
26438Show the current state of FreeBSD native target debugging messages.
7453dc06 26439@item set debug frame
4644b6e3 26440@cindex frame debugging info
7453dc06
AC
26441Turns on or off display of @value{GDBN} frame debugging info. The
26442default is off.
7453dc06
AC
26443@item show debug frame
26444Displays the current state of displaying @value{GDBN} frame debugging
26445info.
cbe54154
PA
26446@item set debug gnu-nat
26447@cindex @sc{gnu}/Hurd debug messages
67ebd9cb 26448Turn on or off debugging messages from the @sc{gnu}/Hurd debug support.
cbe54154
PA
26449@item show debug gnu-nat
26450Show the current state of @sc{gnu}/Hurd debugging messages.
30e91e0b
RC
26451@item set debug infrun
26452@cindex inferior debugging info
26453Turns on or off display of @value{GDBN} debugging info for running the inferior.
26454The default is off. @file{infrun.c} contains GDB's runtime state machine used
26455for implementing operations such as single-stepping the inferior.
26456@item show debug infrun
26457Displays the current state of @value{GDBN} inferior debugging.
a255712f
PP
26458@item set debug jit
26459@cindex just-in-time compilation, debugging messages
67ebd9cb 26460Turn on or off debugging messages from JIT debug support.
a255712f
PP
26461@item show debug jit
26462Displays the current state of @value{GDBN} JIT debugging.
da316a69
EZ
26463@item set debug lin-lwp
26464@cindex @sc{gnu}/Linux LWP debug messages
26465@cindex Linux lightweight processes
67ebd9cb 26466Turn on or off debugging messages from the Linux LWP debug support.
da316a69
EZ
26467@item show debug lin-lwp
26468Show the current state of Linux LWP debugging messages.
7a6a1731
GB
26469@item set debug linux-namespaces
26470@cindex @sc{gnu}/Linux namespaces debug messages
67ebd9cb 26471Turn on or off debugging messages from the Linux namespaces debug support.
7a6a1731
GB
26472@item show debug linux-namespaces
26473Show the current state of Linux namespaces debugging messages.
be9a8770
PA
26474@item set debug mach-o
26475@cindex Mach-O symbols processing
26476Control display of debugging messages related to Mach-O symbols
26477processing. The default is off.
26478@item show debug mach-o
26479Displays the current state of displaying debugging messages related to
26480reading of COFF/PE exported symbols.
c9b6281a
YQ
26481@item set debug notification
26482@cindex remote async notification debugging info
67ebd9cb 26483Turn on or off debugging messages about remote async notification.
c9b6281a
YQ
26484The default is off.
26485@item show debug notification
26486Displays the current state of remote async notification debugging messages.
2b4855ab 26487@item set debug observer
4644b6e3 26488@cindex observer debugging info
2b4855ab
AC
26489Turns on or off display of @value{GDBN} observer debugging. This
26490includes info such as the notification of observable events.
2b4855ab
AC
26491@item show debug observer
26492Displays the current state of observer debugging.
8e04817f 26493@item set debug overload
4644b6e3 26494@cindex C@t{++} overload debugging info
8e04817f 26495Turns on or off display of @value{GDBN} C@t{++} overload debugging
359df76b 26496info. This includes info such as ranking of functions, etc. The default
8e04817f 26497is off.
8e04817f
AC
26498@item show debug overload
26499Displays the current state of displaying @value{GDBN} C@t{++} overload
26500debugging info.
92981e24
TT
26501@cindex expression parser, debugging info
26502@cindex debug expression parser
26503@item set debug parser
26504Turns on or off the display of expression parser debugging output.
26505Internally, this sets the @code{yydebug} variable in the expression
26506parser. @xref{Tracing, , Tracing Your Parser, bison, Bison}, for
26507details. The default is off.
26508@item show debug parser
26509Show the current state of expression parser debugging.
8e04817f
AC
26510@cindex packets, reporting on stdout
26511@cindex serial connections, debugging
605a56cb
DJ
26512@cindex debug remote protocol
26513@cindex remote protocol debugging
26514@cindex display remote packets
8e04817f
AC
26515@item set debug remote
26516Turns on or off display of reports on all packets sent back and forth across
26517the serial line to the remote machine. The info is printed on the
26518@value{GDBN} standard output stream. The default is off.
8e04817f
AC
26519@item show debug remote
26520Displays the state of display of remote packets.
c4dcb155 26521
6cc8564b
LM
26522@item set debug remote-packet-max-chars
26523Sets the maximum number of characters to display for each remote packet when
26524@code{set debug remote} is on. This is useful to prevent @value{GDBN} from
26525displaying lengthy remote packets and polluting the console.
26526
26527The default value is @code{512}, which means @value{GDBN} will truncate each
26528remote packet after 512 bytes.
26529
26530Setting this option to @code{unlimited} will disable truncation and will output
26531the full length of the remote packets.
26532@item show debug remote-packet-max-chars
26533Displays the number of bytes to output for remote packet debugging.
26534
c4dcb155
SM
26535@item set debug separate-debug-file
26536Turns on or off display of debug output about separate debug file search.
26537@item show debug separate-debug-file
26538Displays the state of separate debug file search debug output.
26539
8e04817f
AC
26540@item set debug serial
26541Turns on or off display of @value{GDBN} serial debugging info. The
26542default is off.
8e04817f
AC
26543@item show debug serial
26544Displays the current state of displaying @value{GDBN} serial debugging
26545info.
c45da7e6
EZ
26546@item set debug solib-frv
26547@cindex FR-V shared-library debugging
67ebd9cb 26548Turn on or off debugging messages for FR-V shared-library code.
c45da7e6
EZ
26549@item show debug solib-frv
26550Display the current state of FR-V shared-library code debugging
26551messages.
cc485e62
DE
26552@item set debug symbol-lookup
26553@cindex symbol lookup
26554Turns on or off display of debugging messages related to symbol lookup.
26555The default is 0 (off).
26556A value of 1 provides basic information.
26557A value greater than 1 provides more verbose information.
26558@item show debug symbol-lookup
26559Show the current state of symbol lookup debugging messages.
8fb8eb5c
DE
26560@item set debug symfile
26561@cindex symbol file functions
26562Turns on or off display of debugging messages related to symbol file functions.
26563The default is off. @xref{Files}.
26564@item show debug symfile
26565Show the current state of symbol file debugging messages.
45cfd468
DE
26566@item set debug symtab-create
26567@cindex symbol table creation
26568Turns on or off display of debugging messages related to symbol table creation.
db0fec5c
DE
26569The default is 0 (off).
26570A value of 1 provides basic information.
26571A value greater than 1 provides more verbose information.
45cfd468
DE
26572@item show debug symtab-create
26573Show the current state of symbol table creation debugging.
8e04817f 26574@item set debug target
4644b6e3 26575@cindex target debugging info
8e04817f
AC
26576Turns on or off display of @value{GDBN} target debugging info. This info
26577includes what is going on at the target level of GDB, as it happens. The
701b08bb 26578default is 0. Set it to 1 to track events, and to 2 to also track the
3cecbbbe 26579value of large memory transfers.
8e04817f
AC
26580@item show debug target
26581Displays the current state of displaying @value{GDBN} target debugging
26582info.
75feb17d 26583@item set debug timestamp
6b92c0d3 26584@cindex timestamping debugging info
75feb17d
DJ
26585Turns on or off display of timestamps with @value{GDBN} debugging info.
26586When enabled, seconds and microseconds are displayed before each debugging
26587message.
26588@item show debug timestamp
26589Displays the current state of displaying timestamps with @value{GDBN}
26590debugging info.
f989a1c8 26591@item set debug varobj
4644b6e3 26592@cindex variable object debugging info
8e04817f
AC
26593Turns on or off display of @value{GDBN} variable object debugging
26594info. The default is off.
f989a1c8 26595@item show debug varobj
8e04817f
AC
26596Displays the current state of displaying @value{GDBN} variable object
26597debugging info.
e776119f
DJ
26598@item set debug xml
26599@cindex XML parser debugging
67ebd9cb 26600Turn on or off debugging messages for built-in XML parsers.
e776119f
DJ
26601@item show debug xml
26602Displays the current state of XML debugging messages.
8e04817f 26603@end table
104c1213 26604
14fb1bac
JB
26605@node Other Misc Settings
26606@section Other Miscellaneous Settings
26607@cindex miscellaneous settings
26608
26609@table @code
26610@kindex set interactive-mode
26611@item set interactive-mode
7bfc9434
JB
26612If @code{on}, forces @value{GDBN} to assume that GDB was started
26613in a terminal. In practice, this means that @value{GDBN} should wait
26614for the user to answer queries generated by commands entered at
26615the command prompt. If @code{off}, forces @value{GDBN} to operate
26616in the opposite mode, and it uses the default answers to all queries.
26617If @code{auto} (the default), @value{GDBN} tries to determine whether
26618its standard input is a terminal, and works in interactive-mode if it
26619is, non-interactively otherwise.
14fb1bac
JB
26620
26621In the vast majority of cases, the debugger should be able to guess
26622correctly which mode should be used. But this setting can be useful
26623in certain specific cases, such as running a MinGW @value{GDBN}
26624inside a cygwin window.
26625
26626@kindex show interactive-mode
26627@item show interactive-mode
26628Displays whether the debugger is operating in interactive mode or not.
26629@end table
26630
d57a3c85
TJB
26631@node Extending GDB
26632@chapter Extending @value{GDBN}
26633@cindex extending GDB
26634
71b8c845
DE
26635@value{GDBN} provides several mechanisms for extension.
26636@value{GDBN} also provides the ability to automatically load
26637extensions when it reads a file for debugging. This allows the
26638user to automatically customize @value{GDBN} for the program
26639being debugged.
d57a3c85 26640
71b8c845
DE
26641@menu
26642* Sequences:: Canned Sequences of @value{GDBN} Commands
26643* Python:: Extending @value{GDBN} using Python
ed3ef339 26644* Guile:: Extending @value{GDBN} using Guile
71b8c845 26645* Auto-loading extensions:: Automatically loading extensions
ed3ef339 26646* Multiple Extension Languages:: Working with multiple extension languages
71b8c845
DE
26647* Aliases:: Creating new spellings of existing commands
26648@end menu
26649
26650To facilitate the use of extension languages, @value{GDBN} is capable
95433b34 26651of evaluating the contents of a file. When doing so, @value{GDBN}
71b8c845 26652can recognize which extension language is being used by looking at
95433b34
JB
26653the filename extension. Files with an unrecognized filename extension
26654are always treated as a @value{GDBN} Command Files.
26655@xref{Command Files,, Command files}.
26656
26657You can control how @value{GDBN} evaluates these files with the following
26658setting:
26659
26660@table @code
26661@kindex set script-extension
26662@kindex show script-extension
26663@item set script-extension off
26664All scripts are always evaluated as @value{GDBN} Command Files.
26665
26666@item set script-extension soft
26667The debugger determines the scripting language based on filename
26668extension. If this scripting language is supported, @value{GDBN}
26669evaluates the script using that language. Otherwise, it evaluates
26670the file as a @value{GDBN} Command File.
26671
26672@item set script-extension strict
26673The debugger determines the scripting language based on filename
26674extension, and evaluates the script using that language. If the
26675language is not supported, then the evaluation fails.
26676
26677@item show script-extension
26678Display the current value of the @code{script-extension} option.
26679
26680@end table
26681
ed2a2229
CB
26682@ifset SYSTEM_GDBINIT_DIR
26683This setting is not used for files in the system-wide gdbinit directory.
26684Files in that directory must have an extension matching their language,
26685or have a @file{.gdb} extension to be interpreted as regular @value{GDBN}
26686commands. @xref{Startup}.
26687@end ifset
26688
8e04817f 26689@node Sequences
d57a3c85 26690@section Canned Sequences of Commands
104c1213 26691
8e04817f 26692Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
79a6e687 26693Command Lists}), @value{GDBN} provides two ways to store sequences of
8e04817f
AC
26694commands for execution as a unit: user-defined commands and command
26695files.
104c1213 26696
8e04817f 26697@menu
fcc73fe3
EZ
26698* Define:: How to define your own commands
26699* Hooks:: Hooks for user-defined commands
26700* Command Files:: How to write scripts of commands to be stored in a file
26701* Output:: Commands for controlled output
71b8c845 26702* Auto-loading sequences:: Controlling auto-loaded command files
8e04817f 26703@end menu
104c1213 26704
8e04817f 26705@node Define
d57a3c85 26706@subsection User-defined Commands
104c1213 26707
8e04817f 26708@cindex user-defined command
fcc73fe3 26709@cindex arguments, to user-defined commands
8e04817f
AC
26710A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
26711which you assign a new name as a command. This is done with the
df3ee9ca 26712@code{define} command. User commands may accept an unlimited number of arguments
8e04817f 26713separated by whitespace. Arguments are accessed within the user command
df3ee9ca 26714via @code{$arg0@dots{}$argN}. A trivial example:
104c1213 26715
8e04817f
AC
26716@smallexample
26717define adder
26718 print $arg0 + $arg1 + $arg2
c03c782f 26719end
8e04817f 26720@end smallexample
104c1213
JM
26721
26722@noindent
8e04817f 26723To execute the command use:
104c1213 26724
8e04817f
AC
26725@smallexample
26726adder 1 2 3
26727@end smallexample
104c1213 26728
8e04817f
AC
26729@noindent
26730This defines the command @code{adder}, which prints the sum of
26731its three arguments. Note the arguments are text substitutions, so they may
26732reference variables, use complex expressions, or even perform inferior
26733functions calls.
104c1213 26734
fcc73fe3
EZ
26735@cindex argument count in user-defined commands
26736@cindex how many arguments (user-defined commands)
c03c782f 26737In addition, @code{$argc} may be used to find out how many arguments have
df3ee9ca 26738been passed.
c03c782f
AS
26739
26740@smallexample
26741define adder
26742 if $argc == 2
26743 print $arg0 + $arg1
26744 end
26745 if $argc == 3
26746 print $arg0 + $arg1 + $arg2
26747 end
26748end
26749@end smallexample
26750
01770bbd
PA
26751Combining with the @code{eval} command (@pxref{eval}) makes it easier
26752to process a variable number of arguments:
26753
26754@smallexample
26755define adder
26756 set $i = 0
26757 set $sum = 0
26758 while $i < $argc
26759 eval "set $sum = $sum + $arg%d", $i
26760 set $i = $i + 1
26761 end
26762 print $sum
26763end
26764@end smallexample
26765
104c1213 26766@table @code
104c1213 26767
8e04817f
AC
26768@kindex define
26769@item define @var{commandname}
26770Define a command named @var{commandname}. If there is already a command
26771by that name, you are asked to confirm that you want to redefine it.
697aa1b7 26772The argument @var{commandname} may be a bare command name consisting of letters,
bf498525
PW
26773numbers, dashes, dots, and underscores. It may also start with any
26774predefined or user-defined prefix command.
26775For example, @samp{define target my-target} creates
adb483fe 26776a user-defined @samp{target my-target} command.
104c1213 26777
8e04817f
AC
26778The definition of the command is made up of other @value{GDBN} command lines,
26779which are given following the @code{define} command. The end of these
26780commands is marked by a line containing @code{end}.
104c1213 26781
8e04817f 26782@kindex document
ca91424e 26783@kindex end@r{ (user-defined commands)}
8e04817f
AC
26784@item document @var{commandname}
26785Document the user-defined command @var{commandname}, so that it can be
26786accessed by @code{help}. The command @var{commandname} must already be
26787defined. This command reads lines of documentation just as @code{define}
26788reads the lines of the command definition, ending with @code{end}.
26789After the @code{document} command is finished, @code{help} on command
26790@var{commandname} displays the documentation you have written.
104c1213 26791
8e04817f
AC
26792You may use the @code{document} command again to change the
26793documentation of a command. Redefining the command with @code{define}
26794does not change the documentation.
104c1213 26795
bf498525
PW
26796@kindex define-prefix
26797@item define-prefix @var{commandname}
26798Define or mark the command @var{commandname} as a user-defined prefix
26799command. Once marked, @var{commandname} can be used as prefix command
26800by the @code{define} command.
26801Note that @code{define-prefix} can be used with a not yet defined
26802@var{commandname}. In such a case, @var{commandname} is defined as
26803an empty user-defined command.
26804In case you redefine a command that was marked as a user-defined
26805prefix command, the subcommands of the redefined command are kept
26806(and @value{GDBN} indicates so to the user).
26807
26808Example:
26809@example
26810(gdb) define-prefix abc
26811(gdb) define-prefix abc def
26812(gdb) define abc def
26813Type commands for definition of "abc def".
26814End with a line saying just "end".
26815>echo command initial def\n
26816>end
26817(gdb) define abc def ghi
26818Type commands for definition of "abc def ghi".
26819End with a line saying just "end".
26820>echo command ghi\n
26821>end
26822(gdb) define abc def
26823Keeping subcommands of prefix command "def".
26824Redefine command "def"? (y or n) y
26825Type commands for definition of "abc def".
26826End with a line saying just "end".
26827>echo command def\n
26828>end
26829(gdb) abc def ghi
26830command ghi
26831(gdb) abc def
26832command def
26833(gdb)
26834@end example
26835
c45da7e6
EZ
26836@kindex dont-repeat
26837@cindex don't repeat command
26838@item dont-repeat
26839Used inside a user-defined command, this tells @value{GDBN} that this
26840command should not be repeated when the user hits @key{RET}
26841(@pxref{Command Syntax, repeat last command}).
26842
8e04817f
AC
26843@kindex help user-defined
26844@item help user-defined
7d74f244 26845List all user-defined commands and all python commands defined in class
6b92c0d3 26846COMMAND_USER. The first line of the documentation or docstring is
7d74f244 26847included (if any).
104c1213 26848
8e04817f
AC
26849@kindex show user
26850@item show user
26851@itemx show user @var{commandname}
26852Display the @value{GDBN} commands used to define @var{commandname} (but
26853not its documentation). If no @var{commandname} is given, display the
26854definitions for all user-defined commands.
7d74f244 26855This does not work for user-defined python commands.
104c1213 26856
fcc73fe3 26857@cindex infinite recursion in user-defined commands
20f01a46
DH
26858@kindex show max-user-call-depth
26859@kindex set max-user-call-depth
26860@item show max-user-call-depth
5ca0cb28
DH
26861@itemx set max-user-call-depth
26862The value of @code{max-user-call-depth} controls how many recursion
3f94c067 26863levels are allowed in user-defined commands before @value{GDBN} suspects an
5ca0cb28 26864infinite recursion and aborts the command.
7d74f244 26865This does not apply to user-defined python commands.
104c1213
JM
26866@end table
26867
fcc73fe3
EZ
26868In addition to the above commands, user-defined commands frequently
26869use control flow commands, described in @ref{Command Files}.
26870
8e04817f
AC
26871When user-defined commands are executed, the
26872commands of the definition are not printed. An error in any command
26873stops execution of the user-defined command.
104c1213 26874
8e04817f
AC
26875If used interactively, commands that would ask for confirmation proceed
26876without asking when used inside a user-defined command. Many @value{GDBN}
26877commands that normally print messages to say what they are doing omit the
26878messages when used in a user-defined command.
104c1213 26879
8e04817f 26880@node Hooks
d57a3c85 26881@subsection User-defined Command Hooks
8e04817f
AC
26882@cindex command hooks
26883@cindex hooks, for commands
26884@cindex hooks, pre-command
104c1213 26885
8e04817f 26886@kindex hook
8e04817f
AC
26887You may define @dfn{hooks}, which are a special kind of user-defined
26888command. Whenever you run the command @samp{foo}, if the user-defined
26889command @samp{hook-foo} exists, it is executed (with no arguments)
26890before that command.
104c1213 26891
8e04817f
AC
26892@cindex hooks, post-command
26893@kindex hookpost
8e04817f
AC
26894A hook may also be defined which is run after the command you executed.
26895Whenever you run the command @samp{foo}, if the user-defined command
26896@samp{hookpost-foo} exists, it is executed (with no arguments) after
26897that command. Post-execution hooks may exist simultaneously with
26898pre-execution hooks, for the same command.
104c1213 26899
8e04817f 26900It is valid for a hook to call the command which it hooks. If this
9f1c6395 26901occurs, the hook is not re-executed, thereby avoiding infinite recursion.
104c1213 26902
8e04817f
AC
26903@c It would be nice if hookpost could be passed a parameter indicating
26904@c if the command it hooks executed properly or not. FIXME!
104c1213 26905
8e04817f
AC
26906@kindex stop@r{, a pseudo-command}
26907In addition, a pseudo-command, @samp{stop} exists. Defining
26908(@samp{hook-stop}) makes the associated commands execute every time
26909execution stops in your program: before breakpoint commands are run,
26910displays are printed, or the stack frame is printed.
104c1213 26911
8e04817f
AC
26912For example, to ignore @code{SIGALRM} signals while
26913single-stepping, but treat them normally during normal execution,
26914you could define:
104c1213 26915
474c8240 26916@smallexample
8e04817f
AC
26917define hook-stop
26918handle SIGALRM nopass
26919end
104c1213 26920
8e04817f
AC
26921define hook-run
26922handle SIGALRM pass
26923end
104c1213 26924
8e04817f 26925define hook-continue
d3e8051b 26926handle SIGALRM pass
8e04817f 26927end
474c8240 26928@end smallexample
104c1213 26929
d3e8051b 26930As a further example, to hook at the beginning and end of the @code{echo}
b383017d 26931command, and to add extra text to the beginning and end of the message,
8e04817f 26932you could define:
104c1213 26933
474c8240 26934@smallexample
8e04817f
AC
26935define hook-echo
26936echo <<<---
26937end
104c1213 26938
8e04817f
AC
26939define hookpost-echo
26940echo --->>>\n
26941end
104c1213 26942
8e04817f
AC
26943(@value{GDBP}) echo Hello World
26944<<<---Hello World--->>>
26945(@value{GDBP})
104c1213 26946
474c8240 26947@end smallexample
104c1213 26948
8e04817f
AC
26949You can define a hook for any single-word command in @value{GDBN}, but
26950not for command aliases; you should define a hook for the basic command
c1468174 26951name, e.g.@: @code{backtrace} rather than @code{bt}.
8e04817f
AC
26952@c FIXME! So how does Joe User discover whether a command is an alias
26953@c or not?
adb483fe
DJ
26954You can hook a multi-word command by adding @code{hook-} or
26955@code{hookpost-} to the last word of the command, e.g.@:
26956@samp{define target hook-remote} to add a hook to @samp{target remote}.
26957
8e04817f
AC
26958If an error occurs during the execution of your hook, execution of
26959@value{GDBN} commands stops and @value{GDBN} issues a prompt
26960(before the command that you actually typed had a chance to run).
104c1213 26961
8e04817f
AC
26962If you try to define a hook which does not match any known command, you
26963get a warning from the @code{define} command.
c906108c 26964
8e04817f 26965@node Command Files
d57a3c85 26966@subsection Command Files
c906108c 26967
8e04817f 26968@cindex command files
fcc73fe3 26969@cindex scripting commands
6fc08d32
EZ
26970A command file for @value{GDBN} is a text file made of lines that are
26971@value{GDBN} commands. Comments (lines starting with @kbd{#}) may
26972also be included. An empty line in a command file does nothing; it
26973does not mean to repeat the last command, as it would from the
26974terminal.
c906108c 26975
6fc08d32 26976You can request the execution of a command file with the @code{source}
95433b34
JB
26977command. Note that the @code{source} command is also used to evaluate
26978scripts that are not Command Files. The exact behavior can be configured
26979using the @code{script-extension} setting.
26980@xref{Extending GDB,, Extending GDB}.
c906108c 26981
8e04817f
AC
26982@table @code
26983@kindex source
ca91424e 26984@cindex execute commands from a file
3f7b2faa 26985@item source [-s] [-v] @var{filename}
8e04817f 26986Execute the command file @var{filename}.
c906108c
SS
26987@end table
26988
fcc73fe3
EZ
26989The lines in a command file are generally executed sequentially,
26990unless the order of execution is changed by one of the
26991@emph{flow-control commands} described below. The commands are not
a71ec265
DH
26992printed as they are executed. An error in any command terminates
26993execution of the command file and control is returned to the console.
c906108c 26994
08001717
DE
26995@value{GDBN} first searches for @var{filename} in the current directory.
26996If the file is not found there, and @var{filename} does not specify a
26997directory, then @value{GDBN} also looks for the file on the source search path
26998(specified with the @samp{directory} command);
26999except that @file{$cdir} is not searched because the compilation directory
27000is not relevant to scripts.
4b505b12 27001
3f7b2faa
DE
27002If @code{-s} is specified, then @value{GDBN} searches for @var{filename}
27003on the search path even if @var{filename} specifies a directory.
27004The search is done by appending @var{filename} to each element of the
27005search path. So, for example, if @var{filename} is @file{mylib/myscript}
27006and the search path contains @file{/home/user} then @value{GDBN} will
27007look for the script @file{/home/user/mylib/myscript}.
27008The search is also done if @var{filename} is an absolute path.
27009For example, if @var{filename} is @file{/tmp/myscript} and
27010the search path contains @file{/home/user} then @value{GDBN} will
27011look for the script @file{/home/user/tmp/myscript}.
27012For DOS-like systems, if @var{filename} contains a drive specification,
27013it is stripped before concatenation. For example, if @var{filename} is
27014@file{d:myscript} and the search path contains @file{c:/tmp} then @value{GDBN}
27015will look for the script @file{c:/tmp/myscript}.
27016
16026cd7
AS
27017If @code{-v}, for verbose mode, is given then @value{GDBN} displays
27018each command as it is executed. The option must be given before
27019@var{filename}, and is interpreted as part of the filename anywhere else.
27020
8e04817f
AC
27021Commands that would ask for confirmation if used interactively proceed
27022without asking when used in a command file. Many @value{GDBN} commands that
27023normally print messages to say what they are doing omit the messages
27024when called from command files.
c906108c 27025
8e04817f
AC
27026@value{GDBN} also accepts command input from standard input. In this
27027mode, normal output goes to standard output and error output goes to
27028standard error. Errors in a command file supplied on standard input do
6fc08d32 27029not terminate execution of the command file---execution continues with
8e04817f 27030the next command.
c906108c 27031
474c8240 27032@smallexample
8e04817f 27033gdb < cmds > log 2>&1
474c8240 27034@end smallexample
c906108c 27035
8e04817f
AC
27036(The syntax above will vary depending on the shell used.) This example
27037will execute commands from the file @file{cmds}. All output and errors
27038would be directed to @file{log}.
c906108c 27039
fcc73fe3
EZ
27040Since commands stored on command files tend to be more general than
27041commands typed interactively, they frequently need to deal with
27042complicated situations, such as different or unexpected values of
27043variables and symbols, changes in how the program being debugged is
27044built, etc. @value{GDBN} provides a set of flow-control commands to
27045deal with these complexities. Using these commands, you can write
27046complex scripts that loop over data structures, execute commands
27047conditionally, etc.
27048
27049@table @code
27050@kindex if
27051@kindex else
27052@item if
27053@itemx else
27054This command allows to include in your script conditionally executed
27055commands. The @code{if} command takes a single argument, which is an
27056expression to evaluate. It is followed by a series of commands that
27057are executed only if the expression is true (its value is nonzero).
27058There can then optionally be an @code{else} line, followed by a series
27059of commands that are only executed if the expression was false. The
27060end of the list is marked by a line containing @code{end}.
27061
27062@kindex while
27063@item while
27064This command allows to write loops. Its syntax is similar to
27065@code{if}: the command takes a single argument, which is an expression
27066to evaluate, and must be followed by the commands to execute, one per
27067line, terminated by an @code{end}. These commands are called the
27068@dfn{body} of the loop. The commands in the body of @code{while} are
27069executed repeatedly as long as the expression evaluates to true.
27070
27071@kindex loop_break
27072@item loop_break
27073This command exits the @code{while} loop in whose body it is included.
27074Execution of the script continues after that @code{while}s @code{end}
27075line.
27076
27077@kindex loop_continue
27078@item loop_continue
27079This command skips the execution of the rest of the body of commands
27080in the @code{while} loop in whose body it is included. Execution
27081branches to the beginning of the @code{while} loop, where it evaluates
27082the controlling expression.
ca91424e
EZ
27083
27084@kindex end@r{ (if/else/while commands)}
27085@item end
27086Terminate the block of commands that are the body of @code{if},
27087@code{else}, or @code{while} flow-control commands.
fcc73fe3
EZ
27088@end table
27089
27090
8e04817f 27091@node Output
d57a3c85 27092@subsection Commands for Controlled Output
c906108c 27093
8e04817f
AC
27094During the execution of a command file or a user-defined command, normal
27095@value{GDBN} output is suppressed; the only output that appears is what is
27096explicitly printed by the commands in the definition. This section
27097describes three commands useful for generating exactly the output you
27098want.
c906108c
SS
27099
27100@table @code
8e04817f
AC
27101@kindex echo
27102@item echo @var{text}
27103@c I do not consider backslash-space a standard C escape sequence
27104@c because it is not in ANSI.
27105Print @var{text}. Nonprinting characters can be included in
27106@var{text} using C escape sequences, such as @samp{\n} to print a
27107newline. @strong{No newline is printed unless you specify one.}
27108In addition to the standard C escape sequences, a backslash followed
27109by a space stands for a space. This is useful for displaying a
27110string with spaces at the beginning or the end, since leading and
27111trailing spaces are otherwise trimmed from all arguments.
27112To print @samp{@w{ }and foo =@w{ }}, use the command
27113@samp{echo \@w{ }and foo = \@w{ }}.
c906108c 27114
8e04817f
AC
27115A backslash at the end of @var{text} can be used, as in C, to continue
27116the command onto subsequent lines. For example,
c906108c 27117
474c8240 27118@smallexample
8e04817f
AC
27119echo This is some text\n\
27120which is continued\n\
27121onto several lines.\n
474c8240 27122@end smallexample
c906108c 27123
8e04817f 27124produces the same output as
c906108c 27125
474c8240 27126@smallexample
8e04817f
AC
27127echo This is some text\n
27128echo which is continued\n
27129echo onto several lines.\n
474c8240 27130@end smallexample
c906108c 27131
8e04817f
AC
27132@kindex output
27133@item output @var{expression}
27134Print the value of @var{expression} and nothing but that value: no
27135newlines, no @samp{$@var{nn} = }. The value is not entered in the
27136value history either. @xref{Expressions, ,Expressions}, for more information
27137on expressions.
c906108c 27138
8e04817f
AC
27139@item output/@var{fmt} @var{expression}
27140Print the value of @var{expression} in format @var{fmt}. You can use
27141the same formats as for @code{print}. @xref{Output Formats,,Output
79a6e687 27142Formats}, for more information.
c906108c 27143
8e04817f 27144@kindex printf
82160952
EZ
27145@item printf @var{template}, @var{expressions}@dots{}
27146Print the values of one or more @var{expressions} under the control of
27147the string @var{template}. To print several values, make
27148@var{expressions} be a comma-separated list of individual expressions,
27149which may be either numbers or pointers. Their values are printed as
27150specified by @var{template}, exactly as a C program would do by
27151executing the code below:
c906108c 27152
474c8240 27153@smallexample
82160952 27154printf (@var{template}, @var{expressions}@dots{});
474c8240 27155@end smallexample
c906108c 27156
82160952
EZ
27157As in @code{C} @code{printf}, ordinary characters in @var{template}
27158are printed verbatim, while @dfn{conversion specification} introduced
27159by the @samp{%} character cause subsequent @var{expressions} to be
27160evaluated, their values converted and formatted according to type and
27161style information encoded in the conversion specifications, and then
27162printed.
27163
8e04817f 27164For example, you can print two values in hex like this:
c906108c 27165
8e04817f
AC
27166@smallexample
27167printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
27168@end smallexample
c906108c 27169
82160952
EZ
27170@code{printf} supports all the standard @code{C} conversion
27171specifications, including the flags and modifiers between the @samp{%}
27172character and the conversion letter, with the following exceptions:
27173
27174@itemize @bullet
27175@item
27176The argument-ordering modifiers, such as @samp{2$}, are not supported.
27177
27178@item
27179The modifier @samp{*} is not supported for specifying precision or
27180width.
27181
27182@item
27183The @samp{'} flag (for separation of digits into groups according to
27184@code{LC_NUMERIC'}) is not supported.
27185
27186@item
27187The type modifiers @samp{hh}, @samp{j}, @samp{t}, and @samp{z} are not
27188supported.
27189
27190@item
27191The conversion letter @samp{n} (as in @samp{%n}) is not supported.
27192
27193@item
27194The conversion letters @samp{a} and @samp{A} are not supported.
27195@end itemize
27196
27197@noindent
27198Note that the @samp{ll} type modifier is supported only if the
27199underlying @code{C} implementation used to build @value{GDBN} supports
27200the @code{long long int} type, and the @samp{L} type modifier is
27201supported only if @code{long double} type is available.
27202
27203As in @code{C}, @code{printf} supports simple backslash-escape
27204sequences, such as @code{\n}, @samp{\t}, @samp{\\}, @samp{\"},
27205@samp{\a}, and @samp{\f}, that consist of backslash followed by a
27206single character. Octal and hexadecimal escape sequences are not
27207supported.
1a619819
LM
27208
27209Additionally, @code{printf} supports conversion specifications for DFP
0aea4bf3
LM
27210(@dfn{Decimal Floating Point}) types using the following length modifiers
27211together with a floating point specifier.
1a619819
LM
27212letters:
27213
27214@itemize @bullet
27215@item
27216@samp{H} for printing @code{Decimal32} types.
27217
27218@item
27219@samp{D} for printing @code{Decimal64} types.
27220
27221@item
27222@samp{DD} for printing @code{Decimal128} types.
27223@end itemize
27224
27225If the underlying @code{C} implementation used to build @value{GDBN} has
0aea4bf3 27226support for the three length modifiers for DFP types, other modifiers
3b784c4f 27227such as width and precision will also be available for @value{GDBN} to use.
1a619819
LM
27228
27229In case there is no such @code{C} support, no additional modifiers will be
27230available and the value will be printed in the standard way.
27231
27232Here's an example of printing DFP types using the above conversion letters:
27233@smallexample
0aea4bf3 27234printf "D32: %Hf - D64: %Df - D128: %DDf\n",1.2345df,1.2E10dd,1.2E1dl
1a619819
LM
27235@end smallexample
27236
01770bbd 27237@anchor{eval}
f1421989
HZ
27238@kindex eval
27239@item eval @var{template}, @var{expressions}@dots{}
27240Convert the values of one or more @var{expressions} under the control of
27241the string @var{template} to a command line, and call it.
27242
c906108c
SS
27243@end table
27244
71b8c845
DE
27245@node Auto-loading sequences
27246@subsection Controlling auto-loading native @value{GDBN} scripts
27247@cindex native script auto-loading
27248
27249When a new object file is read (for example, due to the @code{file}
27250command, or because the inferior has loaded a shared library),
27251@value{GDBN} will look for the command file @file{@var{objfile}-gdb.gdb}.
27252@xref{Auto-loading extensions}.
27253
27254Auto-loading can be enabled or disabled,
27255and the list of auto-loaded scripts can be printed.
27256
27257@table @code
27258@anchor{set auto-load gdb-scripts}
27259@kindex set auto-load gdb-scripts
27260@item set auto-load gdb-scripts [on|off]
27261Enable or disable the auto-loading of canned sequences of commands scripts.
27262
27263@anchor{show auto-load gdb-scripts}
27264@kindex show auto-load gdb-scripts
27265@item show auto-load gdb-scripts
27266Show whether auto-loading of canned sequences of commands scripts is enabled or
27267disabled.
27268
27269@anchor{info auto-load gdb-scripts}
27270@kindex info auto-load gdb-scripts
27271@cindex print list of auto-loaded canned sequences of commands scripts
27272@item info auto-load gdb-scripts [@var{regexp}]
27273Print the list of all canned sequences of commands scripts that @value{GDBN}
27274auto-loaded.
27275@end table
27276
27277If @var{regexp} is supplied only canned sequences of commands scripts with
27278matching names are printed.
27279
329baa95
DE
27280@c Python docs live in a separate file.
27281@include python.texi
0e3509db 27282
ed3ef339
DE
27283@c Guile docs live in a separate file.
27284@include guile.texi
27285
71b8c845
DE
27286@node Auto-loading extensions
27287@section Auto-loading extensions
27288@cindex auto-loading extensions
27289
27290@value{GDBN} provides two mechanisms for automatically loading extensions
27291when a new object file is read (for example, due to the @code{file}
27292command, or because the inferior has loaded a shared library):
27293@file{@var{objfile}-gdb.@var{ext}} and the @code{.debug_gdb_scripts}
27294section of modern file formats like ELF.
27295
27296@menu
27297* objfile-gdb.ext file: objfile-gdbdotext file. The @file{@var{objfile}-gdb.@var{ext}} file
27298* .debug_gdb_scripts section: dotdebug_gdb_scripts section. The @code{.debug_gdb_scripts} section
27299* Which flavor to choose?::
27300@end menu
27301
27302The auto-loading feature is useful for supplying application-specific
27303debugging commands and features.
27304
27305Auto-loading can be enabled or disabled,
27306and the list of auto-loaded scripts can be printed.
27307See the @samp{auto-loading} section of each extension language
27308for more information.
27309For @value{GDBN} command files see @ref{Auto-loading sequences}.
27310For Python files see @ref{Python Auto-loading}.
27311
27312Note that loading of this script file also requires accordingly configured
27313@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27314
27315@node objfile-gdbdotext file
27316@subsection The @file{@var{objfile}-gdb.@var{ext}} file
27317@cindex @file{@var{objfile}-gdb.gdb}
27318@cindex @file{@var{objfile}-gdb.py}
27319@cindex @file{@var{objfile}-gdb.scm}
27320
27321When a new object file is read, @value{GDBN} looks for a file named
27322@file{@var{objfile}-gdb.@var{ext}} (we call it @var{script-name} below),
27323where @var{objfile} is the object file's name and
27324where @var{ext} is the file extension for the extension language:
27325
27326@table @code
27327@item @file{@var{objfile}-gdb.gdb}
27328GDB's own command language
27329@item @file{@var{objfile}-gdb.py}
27330Python
ed3ef339
DE
27331@item @file{@var{objfile}-gdb.scm}
27332Guile
71b8c845
DE
27333@end table
27334
27335@var{script-name} is formed by ensuring that the file name of @var{objfile}
27336is absolute, following all symlinks, and resolving @code{.} and @code{..}
27337components, and appending the @file{-gdb.@var{ext}} suffix.
27338If this file exists and is readable, @value{GDBN} will evaluate it as a
27339script in the specified extension language.
27340
27341If this file does not exist, then @value{GDBN} will look for
27342@var{script-name} file in all of the directories as specified below.
27343
27344Note that loading of these files requires an accordingly configured
27345@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27346
27347For object files using @file{.exe} suffix @value{GDBN} tries to load first the
27348scripts normally according to its @file{.exe} filename. But if no scripts are
27349found @value{GDBN} also tries script filenames matching the object file without
27350its @file{.exe} suffix. This @file{.exe} stripping is case insensitive and it
27351is attempted on any platform. This makes the script filenames compatible
27352between Unix and MS-Windows hosts.
27353
27354@table @code
27355@anchor{set auto-load scripts-directory}
27356@kindex set auto-load scripts-directory
27357@item set auto-load scripts-directory @r{[}@var{directories}@r{]}
27358Control @value{GDBN} auto-loaded scripts location. Multiple directory entries
27359may be delimited by the host platform path separator in use
27360(@samp{:} on Unix, @samp{;} on MS-Windows and MS-DOS).
27361
27362Each entry here needs to be covered also by the security setting
27363@code{set auto-load safe-path} (@pxref{set auto-load safe-path}).
27364
27365@anchor{with-auto-load-dir}
27366This variable defaults to @file{$debugdir:$datadir/auto-load}. The default
27367@code{set auto-load safe-path} value can be also overriden by @value{GDBN}
27368configuration option @option{--with-auto-load-dir}.
27369
27370Any reference to @file{$debugdir} will get replaced by
27371@var{debug-file-directory} value (@pxref{Separate Debug Files}) and any
27372reference to @file{$datadir} will get replaced by @var{data-directory} which is
27373determined at @value{GDBN} startup (@pxref{Data Files}). @file{$debugdir} and
27374@file{$datadir} must be placed as a directory component --- either alone or
27375delimited by @file{/} or @file{\} directory separators, depending on the host
27376platform.
27377
27378The list of directories uses path separator (@samp{:} on GNU and Unix
27379systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
27380to the @env{PATH} environment variable.
27381
27382@anchor{show auto-load scripts-directory}
27383@kindex show auto-load scripts-directory
27384@item show auto-load scripts-directory
27385Show @value{GDBN} auto-loaded scripts location.
f10c5b19
JK
27386
27387@anchor{add-auto-load-scripts-directory}
27388@kindex add-auto-load-scripts-directory
27389@item add-auto-load-scripts-directory @r{[}@var{directories}@dots{}@r{]}
27390Add an entry (or list of entries) to the list of auto-loaded scripts locations.
27391Multiple entries may be delimited by the host platform path separator in use.
71b8c845
DE
27392@end table
27393
27394@value{GDBN} does not track which files it has already auto-loaded this way.
27395@value{GDBN} will load the associated script every time the corresponding
27396@var{objfile} is opened.
27397So your @file{-gdb.@var{ext}} file should be careful to avoid errors if it
27398is evaluated more than once.
27399
27400@node dotdebug_gdb_scripts section
27401@subsection The @code{.debug_gdb_scripts} section
27402@cindex @code{.debug_gdb_scripts} section
27403
27404For systems using file formats like ELF and COFF,
27405when @value{GDBN} loads a new object file
27406it will look for a special section named @code{.debug_gdb_scripts}.
9f050062
DE
27407If this section exists, its contents is a list of null-terminated entries
27408specifying scripts to load. Each entry begins with a non-null prefix byte that
27409specifies the kind of entry, typically the extension language and whether the
27410script is in a file or inlined in @code{.debug_gdb_scripts}.
71b8c845 27411
9f050062
DE
27412The following entries are supported:
27413
27414@table @code
27415@item SECTION_SCRIPT_ID_PYTHON_FILE = 1
27416@item SECTION_SCRIPT_ID_SCHEME_FILE = 3
27417@item SECTION_SCRIPT_ID_PYTHON_TEXT = 4
27418@item SECTION_SCRIPT_ID_SCHEME_TEXT = 6
27419@end table
27420
27421@subsubsection Script File Entries
27422
27423If the entry specifies a file, @value{GDBN} will look for the file first
27424in the current directory and then along the source search path
71b8c845
DE
27425(@pxref{Source Path, ,Specifying Source Directories}),
27426except that @file{$cdir} is not searched, since the compilation
27427directory is not relevant to scripts.
27428
9f050062 27429File entries can be placed in section @code{.debug_gdb_scripts} with,
71b8c845
DE
27430for example, this GCC macro for Python scripts.
27431
27432@example
27433/* Note: The "MS" section flags are to remove duplicates. */
27434#define DEFINE_GDB_PY_SCRIPT(script_name) \
27435 asm("\
27436.pushsection \".debug_gdb_scripts\", \"MS\",@@progbits,1\n\
27437.byte 1 /* Python */\n\
27438.asciz \"" script_name "\"\n\
27439.popsection \n\
27440");
27441@end example
27442
27443@noindent
ed3ef339 27444For Guile scripts, replace @code{.byte 1} with @code{.byte 3}.
71b8c845
DE
27445Then one can reference the macro in a header or source file like this:
27446
27447@example
27448DEFINE_GDB_PY_SCRIPT ("my-app-scripts.py")
27449@end example
27450
27451The script name may include directories if desired.
27452
27453Note that loading of this script file also requires accordingly configured
27454@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27455
27456If the macro invocation is put in a header, any application or library
27457using this header will get a reference to the specified script,
27458and with the use of @code{"MS"} attributes on the section, the linker
27459will remove duplicates.
27460
9f050062
DE
27461@subsubsection Script Text Entries
27462
27463Script text entries allow to put the executable script in the entry
27464itself instead of loading it from a file.
27465The first line of the entry, everything after the prefix byte and up to
27466the first newline (@code{0xa}) character, is the script name, and must not
27467contain any kind of space character, e.g., spaces or tabs.
27468The rest of the entry, up to the trailing null byte, is the script to
27469execute in the specified language. The name needs to be unique among
27470all script names, as @value{GDBN} executes each script only once based
27471on its name.
27472
27473Here is an example from file @file{py-section-script.c} in the @value{GDBN}
27474testsuite.
27475
27476@example
27477#include "symcat.h"
27478#include "gdb/section-scripts.h"
27479asm(
27480".pushsection \".debug_gdb_scripts\", \"MS\",@@progbits,1\n"
27481".byte " XSTRING (SECTION_SCRIPT_ID_PYTHON_TEXT) "\n"
27482".ascii \"gdb.inlined-script\\n\"\n"
27483".ascii \"class test_cmd (gdb.Command):\\n\"\n"
27484".ascii \" def __init__ (self):\\n\"\n"
27485".ascii \" super (test_cmd, self).__init__ ("
27486 "\\\"test-cmd\\\", gdb.COMMAND_OBSCURE)\\n\"\n"
27487".ascii \" def invoke (self, arg, from_tty):\\n\"\n"
27488".ascii \" print (\\\"test-cmd output, arg = %s\\\" % arg)\\n\"\n"
27489".ascii \"test_cmd ()\\n\"\n"
27490".byte 0\n"
27491".popsection\n"
27492);
27493@end example
27494
27495Loading of inlined scripts requires a properly configured
27496@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27497The path to specify in @code{auto-load safe-path} is the path of the file
27498containing the @code{.debug_gdb_scripts} section.
27499
71b8c845
DE
27500@node Which flavor to choose?
27501@subsection Which flavor to choose?
27502
27503Given the multiple ways of auto-loading extensions, it might not always
27504be clear which one to choose. This section provides some guidance.
27505
27506@noindent
27507Benefits of the @file{-gdb.@var{ext}} way:
27508
27509@itemize @bullet
27510@item
27511Can be used with file formats that don't support multiple sections.
27512
27513@item
27514Ease of finding scripts for public libraries.
27515
27516Scripts specified in the @code{.debug_gdb_scripts} section are searched for
27517in the source search path.
27518For publicly installed libraries, e.g., @file{libstdc++}, there typically
27519isn't a source directory in which to find the script.
27520
27521@item
27522Doesn't require source code additions.
27523@end itemize
27524
27525@noindent
27526Benefits of the @code{.debug_gdb_scripts} way:
27527
27528@itemize @bullet
27529@item
27530Works with static linking.
27531
27532Scripts for libraries done the @file{-gdb.@var{ext}} way require an objfile to
27533trigger their loading. When an application is statically linked the only
27534objfile available is the executable, and it is cumbersome to attach all the
27535scripts from all the input libraries to the executable's
27536@file{-gdb.@var{ext}} script.
27537
27538@item
27539Works with classes that are entirely inlined.
27540
27541Some classes can be entirely inlined, and thus there may not be an associated
27542shared library to attach a @file{-gdb.@var{ext}} script to.
27543
27544@item
27545Scripts needn't be copied out of the source tree.
27546
27547In some circumstances, apps can be built out of large collections of internal
27548libraries, and the build infrastructure necessary to install the
27549@file{-gdb.@var{ext}} scripts in a place where @value{GDBN} can find them is
27550cumbersome. It may be easier to specify the scripts in the
27551@code{.debug_gdb_scripts} section as relative paths, and add a path to the
27552top of the source tree to the source search path.
27553@end itemize
27554
ed3ef339
DE
27555@node Multiple Extension Languages
27556@section Multiple Extension Languages
27557
27558The Guile and Python extension languages do not share any state,
27559and generally do not interfere with each other.
27560There are some things to be aware of, however.
27561
27562@subsection Python comes first
27563
27564Python was @value{GDBN}'s first extension language, and to avoid breaking
27565existing behaviour Python comes first. This is generally solved by the
27566``first one wins'' principle. @value{GDBN} maintains a list of enabled
27567extension languages, and when it makes a call to an extension language,
27568(say to pretty-print a value), it tries each in turn until an extension
27569language indicates it has performed the request (e.g., has returned the
27570pretty-printed form of a value).
27571This extends to errors while performing such requests: If an error happens
27572while, for example, trying to pretty-print an object then the error is
27573reported and any following extension languages are not tried.
27574
5a56e9c5
DE
27575@node Aliases
27576@section Creating new spellings of existing commands
27577@cindex aliases for commands
27578
27579It is often useful to define alternate spellings of existing commands.
27580For example, if a new @value{GDBN} command defined in Python has
27581a long name to type, it is handy to have an abbreviated version of it
27582that involves less typing.
27583
27584@value{GDBN} itself uses aliases. For example @samp{s} is an alias
27585of the @samp{step} command even though it is otherwise an ambiguous
27586abbreviation of other commands like @samp{set} and @samp{show}.
27587
27588Aliases are also used to provide shortened or more common versions
27589of multi-word commands. For example, @value{GDBN} provides the
27590@samp{tty} alias of the @samp{set inferior-tty} command.
27591
27592You can define a new alias with the @samp{alias} command.
27593
27594@table @code
27595
27596@kindex alias
5b860c93 27597@item alias [-a] [--] @var{ALIAS} = @var{COMMAND} [DEFAULT-ARGS...]
5a56e9c5
DE
27598
27599@end table
27600
27601@var{ALIAS} specifies the name of the new alias.
27602Each word of @var{ALIAS} must consist of letters, numbers, dashes and
27603underscores.
27604
27605@var{COMMAND} specifies the name of an existing command
27606that is being aliased.
27607
5b860c93
PW
27608@var{COMMAND} can also be the name of an existing alias. In this case,
27609@var{COMMAND} cannot be an alias that has default arguments.
27610
5a56e9c5 27611The @samp{-a} option specifies that the new alias is an abbreviation
5b4a1a8d 27612of the command. Abbreviations are not used in command completion.
5a56e9c5
DE
27613
27614The @samp{--} option specifies the end of options,
27615and is useful when @var{ALIAS} begins with a dash.
27616
5b860c93
PW
27617You can specify @var{default-args} for your alias.
27618These @var{default-args} will be automatically added before the alias
27619arguments typed explicitly on the command line.
27620
27621For example, the below defines an alias @code{btfullall} that shows all local
27622variables and all frame arguments:
27623@smallexample
27624(@value{GDBP}) alias btfullall = backtrace -full -frame-arguments all
27625@end smallexample
27626
27627For more information about @var{default-args}, see @ref{Command aliases default args,
27628,Automatically prepend default arguments to user-defined aliases}.
27629
5a56e9c5
DE
27630Here is a simple example showing how to make an abbreviation
27631of a command so that there is less to type.
27632Suppose you were tired of typing @samp{disas}, the current
27633shortest unambiguous abbreviation of the @samp{disassemble} command
27634and you wanted an even shorter version named @samp{di}.
27635The following will accomplish this.
27636
27637@smallexample
27638(gdb) alias -a di = disas
27639@end smallexample
27640
27641Note that aliases are different from user-defined commands.
27642With a user-defined command, you also need to write documentation
27643for it with the @samp{document} command.
27644An alias automatically picks up the documentation of the existing command.
27645
27646Here is an example where we make @samp{elms} an abbreviation of
27647@samp{elements} in the @samp{set print elements} command.
27648This is to show that you can make an abbreviation of any part
27649of a command.
27650
27651@smallexample
27652(gdb) alias -a set print elms = set print elements
27653(gdb) alias -a show print elms = show print elements
27654(gdb) set p elms 20
27655(gdb) show p elms
27656Limit on string chars or array elements to print is 200.
27657@end smallexample
27658
27659Note that if you are defining an alias of a @samp{set} command,
27660and you want to have an alias for the corresponding @samp{show}
27661command, then you need to define the latter separately.
27662
27663Unambiguously abbreviated commands are allowed in @var{COMMAND} and
27664@var{ALIAS}, just as they are normally.
27665
27666@smallexample
27667(gdb) alias -a set pr elms = set p ele
27668@end smallexample
27669
27670Finally, here is an example showing the creation of a one word
27671alias for a more complex command.
27672This creates alias @samp{spe} of the command @samp{set print elements}.
27673
27674@smallexample
27675(gdb) alias spe = set print elements
27676(gdb) spe 20
27677@end smallexample
27678
21c294e6
AC
27679@node Interpreters
27680@chapter Command Interpreters
27681@cindex command interpreters
27682
27683@value{GDBN} supports multiple command interpreters, and some command
27684infrastructure to allow users or user interface writers to switch
27685between interpreters or run commands in other interpreters.
27686
27687@value{GDBN} currently supports two command interpreters, the console
27688interpreter (sometimes called the command-line interpreter or @sc{cli})
27689and the machine interface interpreter (or @sc{gdb/mi}). This manual
27690describes both of these interfaces in great detail.
27691
27692By default, @value{GDBN} will start with the console interpreter.
27693However, the user may choose to start @value{GDBN} with another
27694interpreter by specifying the @option{-i} or @option{--interpreter}
27695startup options. Defined interpreters include:
27696
27697@table @code
27698@item console
27699@cindex console interpreter
27700The traditional console or command-line interpreter. This is the most often
27701used interpreter with @value{GDBN}. With no interpreter specified at runtime,
27702@value{GDBN} will use this interpreter.
27703
27704@item mi
27705@cindex mi interpreter
b4be1b06 27706The newest @sc{gdb/mi} interface (currently @code{mi3}). Used primarily
21c294e6
AC
27707by programs wishing to use @value{GDBN} as a backend for a debugger GUI
27708or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
27709Interface}.
27710
b4be1b06
SM
27711@item mi3
27712@cindex mi3 interpreter
27713The @sc{gdb/mi} interface introduced in @value{GDBN} 9.1.
27714
21c294e6
AC
27715@item mi2
27716@cindex mi2 interpreter
b4be1b06 27717The @sc{gdb/mi} interface introduced in @value{GDBN} 6.0.
21c294e6
AC
27718
27719@item mi1
27720@cindex mi1 interpreter
b4be1b06 27721The @sc{gdb/mi} interface introduced in @value{GDBN} 5.1.
21c294e6
AC
27722
27723@end table
27724
27725@cindex invoke another interpreter
21c294e6
AC
27726
27727@kindex interpreter-exec
86f78169
PA
27728You may execute commands in any interpreter from the current
27729interpreter using the appropriate command. If you are running the
27730console interpreter, simply use the @code{interpreter-exec} command:
21c294e6
AC
27731
27732@smallexample
27733interpreter-exec mi "-data-list-register-names"
27734@end smallexample
27735
27736@sc{gdb/mi} has a similar command, although it is only available in versions of
27737@value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
27738
86f78169
PA
27739Note that @code{interpreter-exec} only changes the interpreter for the
27740duration of the specified command. It does not change the interpreter
27741permanently.
27742
27743@cindex start a new independent interpreter
27744
27745Although you may only choose a single interpreter at startup, it is
27746possible to run an independent interpreter on a specified input/output
27747device (usually a tty).
27748
27749For example, consider a debugger GUI or IDE that wants to provide a
27750@value{GDBN} console view. It may do so by embedding a terminal
27751emulator widget in its GUI, starting @value{GDBN} in the traditional
27752command-line mode with stdin/stdout/stderr redirected to that
27753terminal, and then creating an MI interpreter running on a specified
27754input/output device. The console interpreter created by @value{GDBN}
27755at startup handles commands the user types in the terminal widget,
27756while the GUI controls and synchronizes state with @value{GDBN} using
27757the separate MI interpreter.
27758
27759To start a new secondary @dfn{user interface} running MI, use the
27760@code{new-ui} command:
27761
27762@kindex new-ui
27763@cindex new user interface
27764@smallexample
27765new-ui @var{interpreter} @var{tty}
27766@end smallexample
27767
27768The @var{interpreter} parameter specifies the interpreter to run.
27769This accepts the same values as the @code{interpreter-exec} command.
27770For example, @samp{console}, @samp{mi}, @samp{mi2}, etc. The
27771@var{tty} parameter specifies the name of the bidirectional file the
27772interpreter uses for input/output, usually the name of a
27773pseudoterminal slave on Unix systems. For example:
27774
27775@smallexample
27776(@value{GDBP}) new-ui mi /dev/pts/9
27777@end smallexample
27778
27779@noindent
27780runs an MI interpreter on @file{/dev/pts/9}.
27781
8e04817f
AC
27782@node TUI
27783@chapter @value{GDBN} Text User Interface
27784@cindex TUI
d0d5df6f 27785@cindex Text User Interface
c906108c 27786
8e04817f
AC
27787@menu
27788* TUI Overview:: TUI overview
27789* TUI Keys:: TUI key bindings
7cf36c78 27790* TUI Single Key Mode:: TUI single key mode
db2e3e2e 27791* TUI Commands:: TUI-specific commands
8e04817f
AC
27792* TUI Configuration:: TUI configuration variables
27793@end menu
c906108c 27794
46ba6afa 27795The @value{GDBN} Text User Interface (TUI) is a terminal
d0d5df6f
AC
27796interface which uses the @code{curses} library to show the source
27797file, the assembly output, the program registers and @value{GDBN}
46ba6afa
BW
27798commands in separate text windows. The TUI mode is supported only
27799on platforms where a suitable version of the @code{curses} library
27800is available.
d0d5df6f 27801
46ba6afa 27802The TUI mode is enabled by default when you invoke @value{GDBN} as
217bff3e 27803@samp{@value{GDBP} -tui}.
46ba6afa 27804You can also switch in and out of TUI mode while @value{GDBN} runs by
a4ea0946 27805using various TUI commands and key bindings, such as @command{tui
bcd8537c 27806enable} or @kbd{C-x C-a}. @xref{TUI Commands, ,TUI Commands}, and
a4ea0946 27807@ref{TUI Keys, ,TUI Key Bindings}.
c906108c 27808
8e04817f 27809@node TUI Overview
79a6e687 27810@section TUI Overview
c906108c 27811
46ba6afa 27812In TUI mode, @value{GDBN} can display several text windows:
c906108c 27813
8e04817f
AC
27814@table @emph
27815@item command
27816This window is the @value{GDBN} command window with the @value{GDBN}
46ba6afa
BW
27817prompt and the @value{GDBN} output. The @value{GDBN} input is still
27818managed using readline.
c906108c 27819
8e04817f
AC
27820@item source
27821The source window shows the source file of the program. The current
46ba6afa 27822line and active breakpoints are displayed in this window.
c906108c 27823
8e04817f
AC
27824@item assembly
27825The assembly window shows the disassembly output of the program.
c906108c 27826
8e04817f 27827@item register
46ba6afa
BW
27828This window shows the processor registers. Registers are highlighted
27829when their values change.
c906108c
SS
27830@end table
27831
269c21fe 27832The source and assembly windows show the current program position
46ba6afa
BW
27833by highlighting the current line and marking it with a @samp{>} marker.
27834Breakpoints are indicated with two markers. The first marker
269c21fe
SC
27835indicates the breakpoint type:
27836
27837@table @code
27838@item B
27839Breakpoint which was hit at least once.
27840
27841@item b
27842Breakpoint which was never hit.
27843
27844@item H
27845Hardware breakpoint which was hit at least once.
27846
27847@item h
27848Hardware breakpoint which was never hit.
269c21fe
SC
27849@end table
27850
27851The second marker indicates whether the breakpoint is enabled or not:
27852
27853@table @code
27854@item +
27855Breakpoint is enabled.
27856
27857@item -
27858Breakpoint is disabled.
269c21fe
SC
27859@end table
27860
46ba6afa
BW
27861The source, assembly and register windows are updated when the current
27862thread changes, when the frame changes, or when the program counter
27863changes.
27864
27865These windows are not all visible at the same time. The command
27866window is always visible. The others can be arranged in several
27867layouts:
c906108c 27868
8e04817f
AC
27869@itemize @bullet
27870@item
46ba6afa 27871source only,
2df3850c 27872
8e04817f 27873@item
46ba6afa 27874assembly only,
8e04817f
AC
27875
27876@item
46ba6afa 27877source and assembly,
8e04817f
AC
27878
27879@item
46ba6afa 27880source and registers, or
c906108c 27881
8e04817f 27882@item
46ba6afa 27883assembly and registers.
8e04817f 27884@end itemize
c906108c 27885
ee325b61
TT
27886These are the standard layouts, but other layouts can be defined.
27887
46ba6afa 27888A status line above the command window shows the following information:
b7bb15bc
SC
27889
27890@table @emph
27891@item target
46ba6afa 27892Indicates the current @value{GDBN} target.
b7bb15bc
SC
27893(@pxref{Targets, ,Specifying a Debugging Target}).
27894
27895@item process
46ba6afa 27896Gives the current process or thread number.
b7bb15bc
SC
27897When no process is being debugged, this field is set to @code{No process}.
27898
27899@item function
27900Gives the current function name for the selected frame.
27901The name is demangled if demangling is turned on (@pxref{Print Settings}).
46ba6afa 27902When there is no symbol corresponding to the current program counter,
b7bb15bc
SC
27903the string @code{??} is displayed.
27904
27905@item line
27906Indicates the current line number for the selected frame.
46ba6afa 27907When the current line number is not known, the string @code{??} is displayed.
b7bb15bc
SC
27908
27909@item pc
27910Indicates the current program counter address.
b7bb15bc
SC
27911@end table
27912
8e04817f
AC
27913@node TUI Keys
27914@section TUI Key Bindings
27915@cindex TUI key bindings
c906108c 27916
8e04817f 27917The TUI installs several key bindings in the readline keymaps
39037522
TT
27918@ifset SYSTEM_READLINE
27919(@pxref{Command Line Editing, , , rluserman, GNU Readline Library}).
27920@end ifset
27921@ifclear SYSTEM_READLINE
27922(@pxref{Command Line Editing}).
27923@end ifclear
27924The following key bindings are installed for both TUI mode and the
27925@value{GDBN} standard mode.
c906108c 27926
8e04817f
AC
27927@table @kbd
27928@kindex C-x C-a
27929@item C-x C-a
27930@kindex C-x a
27931@itemx C-x a
27932@kindex C-x A
27933@itemx C-x A
46ba6afa
BW
27934Enter or leave the TUI mode. When leaving the TUI mode,
27935the curses window management stops and @value{GDBN} operates using
27936its standard mode, writing on the terminal directly. When reentering
27937the TUI mode, control is given back to the curses windows.
8e04817f 27938The screen is then refreshed.
c906108c 27939
c86d74cc
TT
27940This key binding uses the bindable Readline function
27941@code{tui-switch-mode}.
27942
8e04817f
AC
27943@kindex C-x 1
27944@item C-x 1
27945Use a TUI layout with only one window. The layout will
27946either be @samp{source} or @samp{assembly}. When the TUI mode
27947is not active, it will switch to the TUI mode.
2df3850c 27948
8e04817f 27949Think of this key binding as the Emacs @kbd{C-x 1} binding.
c906108c 27950
c86d74cc
TT
27951This key binding uses the bindable Readline function
27952@code{tui-delete-other-windows}.
27953
8e04817f
AC
27954@kindex C-x 2
27955@item C-x 2
27956Use a TUI layout with at least two windows. When the current
46ba6afa 27957layout already has two windows, the next layout with two windows is used.
8e04817f
AC
27958When a new layout is chosen, one window will always be common to the
27959previous layout and the new one.
c906108c 27960
8e04817f 27961Think of it as the Emacs @kbd{C-x 2} binding.
2df3850c 27962
c86d74cc
TT
27963This key binding uses the bindable Readline function
27964@code{tui-change-windows}.
27965
72ffddc9
SC
27966@kindex C-x o
27967@item C-x o
27968Change the active window. The TUI associates several key bindings
46ba6afa 27969(like scrolling and arrow keys) with the active window. This command
72ffddc9
SC
27970gives the focus to the next TUI window.
27971
27972Think of it as the Emacs @kbd{C-x o} binding.
27973
c86d74cc
TT
27974This key binding uses the bindable Readline function
27975@code{tui-other-window}.
27976
7cf36c78
SC
27977@kindex C-x s
27978@item C-x s
46ba6afa
BW
27979Switch in and out of the TUI SingleKey mode that binds single
27980keys to @value{GDBN} commands (@pxref{TUI Single Key Mode}).
c86d74cc
TT
27981
27982This key binding uses the bindable Readline function
27983@code{next-keymap}.
c906108c
SS
27984@end table
27985
46ba6afa 27986The following key bindings only work in the TUI mode:
5d161b24 27987
46ba6afa 27988@table @asis
8e04817f 27989@kindex PgUp
46ba6afa 27990@item @key{PgUp}
8e04817f 27991Scroll the active window one page up.
c906108c 27992
8e04817f 27993@kindex PgDn
46ba6afa 27994@item @key{PgDn}
8e04817f 27995Scroll the active window one page down.
c906108c 27996
8e04817f 27997@kindex Up
46ba6afa 27998@item @key{Up}
8e04817f 27999Scroll the active window one line up.
c906108c 28000
8e04817f 28001@kindex Down
46ba6afa 28002@item @key{Down}
8e04817f 28003Scroll the active window one line down.
c906108c 28004
8e04817f 28005@kindex Left
46ba6afa 28006@item @key{Left}
8e04817f 28007Scroll the active window one column left.
c906108c 28008
8e04817f 28009@kindex Right
46ba6afa 28010@item @key{Right}
8e04817f 28011Scroll the active window one column right.
c906108c 28012
8e04817f 28013@kindex C-L
46ba6afa 28014@item @kbd{C-L}
8e04817f 28015Refresh the screen.
8e04817f 28016@end table
c906108c 28017
46ba6afa
BW
28018Because the arrow keys scroll the active window in the TUI mode, they
28019are not available for their normal use by readline unless the command
28020window has the focus. When another window is active, you must use
28021other readline key bindings such as @kbd{C-p}, @kbd{C-n}, @kbd{C-b}
28022and @kbd{C-f} to control the command window.
8e04817f 28023
7cf36c78
SC
28024@node TUI Single Key Mode
28025@section TUI Single Key Mode
28026@cindex TUI single key mode
28027
46ba6afa
BW
28028The TUI also provides a @dfn{SingleKey} mode, which binds several
28029frequently used @value{GDBN} commands to single keys. Type @kbd{C-x s} to
28030switch into this mode, where the following key bindings are used:
7cf36c78
SC
28031
28032@table @kbd
28033@kindex c @r{(SingleKey TUI key)}
28034@item c
28035continue
28036
28037@kindex d @r{(SingleKey TUI key)}
28038@item d
28039down
28040
28041@kindex f @r{(SingleKey TUI key)}
28042@item f
28043finish
28044
28045@kindex n @r{(SingleKey TUI key)}
28046@item n
28047next
28048
a5afdb16
RK
28049@kindex o @r{(SingleKey TUI key)}
28050@item o
28051nexti. The shortcut letter @samp{o} stands for ``step Over''.
28052
7cf36c78
SC
28053@kindex q @r{(SingleKey TUI key)}
28054@item q
46ba6afa 28055exit the SingleKey mode.
7cf36c78
SC
28056
28057@kindex r @r{(SingleKey TUI key)}
28058@item r
28059run
28060
28061@kindex s @r{(SingleKey TUI key)}
28062@item s
28063step
28064
a5afdb16
RK
28065@kindex i @r{(SingleKey TUI key)}
28066@item i
28067stepi. The shortcut letter @samp{i} stands for ``step Into''.
28068
7cf36c78
SC
28069@kindex u @r{(SingleKey TUI key)}
28070@item u
28071up
28072
28073@kindex v @r{(SingleKey TUI key)}
28074@item v
28075info locals
28076
28077@kindex w @r{(SingleKey TUI key)}
28078@item w
28079where
7cf36c78
SC
28080@end table
28081
28082Other keys temporarily switch to the @value{GDBN} command prompt.
28083The key that was pressed is inserted in the editing buffer so that
28084it is possible to type most @value{GDBN} commands without interaction
46ba6afa
BW
28085with the TUI SingleKey mode. Once the command is entered the TUI
28086SingleKey mode is restored. The only way to permanently leave
7f9087cb 28087this mode is by typing @kbd{q} or @kbd{C-x s}.
7cf36c78 28088
11061048
TT
28089@cindex SingleKey keymap name
28090If @value{GDBN} was built with Readline 8.0 or later, the TUI
28091SingleKey keymap will be named @samp{SingleKey}. This can be used in
28092@file{.inputrc} to add additional bindings to this keymap.
7cf36c78 28093
8e04817f 28094@node TUI Commands
db2e3e2e 28095@section TUI-specific Commands
8e04817f
AC
28096@cindex TUI commands
28097
28098The TUI has specific commands to control the text windows.
46ba6afa
BW
28099These commands are always available, even when @value{GDBN} is not in
28100the TUI mode. When @value{GDBN} is in the standard mode, most
28101of these commands will automatically switch to the TUI mode.
c906108c 28102
ff12863f
PA
28103Note that if @value{GDBN}'s @code{stdout} is not connected to a
28104terminal, or @value{GDBN} has been started with the machine interface
28105interpreter (@pxref{GDB/MI, ,The @sc{gdb/mi} Interface}), most of
28106these commands will fail with an error, because it would not be
28107possible or desirable to enable curses window management.
28108
c906108c 28109@table @code
a4ea0946
AB
28110@item tui enable
28111@kindex tui enable
28112Activate TUI mode. The last active TUI window layout will be used if
760f7560 28113TUI mode has previously been used in the current debugging session,
a4ea0946
AB
28114otherwise a default layout is used.
28115
28116@item tui disable
28117@kindex tui disable
28118Disable TUI mode, returning to the console interpreter.
28119
3d757584
SC
28120@item info win
28121@kindex info win
28122List and give the size of all displayed windows.
28123
ee325b61
TT
28124@item tui new-layout @var{name} @var{window} @var{weight} @r{[}@var{window} @var{weight}@dots{}@r{]}
28125@kindex tui new-layout
28126Create a new TUI layout. The new layout will be named @var{name}, and
28127can be accessed using the @code{layout} command (see below).
28128
7c043ba6
TT
28129Each @var{window} parameter is either the name of a window to display,
28130or a window description. The windows will be displayed from top to
28131bottom in the order listed.
28132
28133The names of the windows are the same as the ones given to the
ee325b61 28134@code{focus} command (see below); additional, the @code{status}
7c043ba6
TT
28135window can be specified. Note that, because it is of fixed height,
28136the weight assigned to the status window is of no importance. It is
28137conventional to use @samp{0} here.
28138
28139A window description looks a bit like an invocation of @code{tui
28140new-layout}, and is of the form
28141@{@r{[}@code{-horizontal}@r{]}@var{window} @var{weight} @r{[}@var{window} @var{weight}@dots{}@r{]}@}.
28142
28143This specifies a sub-layout. If @code{-horizontal} is given, the
28144windows in this description will be arranged side-by-side, rather than
28145top-to-bottom.
ee325b61
TT
28146
28147Each @var{weight} is an integer. It is the weight of this window
28148relative to all the other windows in the layout. These numbers are
28149used to calculate how much of the screen is given to each window.
28150
28151For example:
28152
28153@example
28154(gdb) tui new-layout example src 1 regs 1 status 0 cmd 1
28155@end example
28156
28157Here, the new layout is called @samp{example}. It shows the source
28158and register windows, followed by the status window, and then finally
28159the command window. The non-status windows all have the same weight,
28160so the terminal will be split into three roughly equal sections.
28161
7c043ba6
TT
28162Here is a more complex example, showing a horizontal layout:
28163
28164@example
28165(gdb) tui new-layout example @{-horizontal src 1 asm 1@} 2 status 0 cmd 1
28166@end example
28167
28168This will result in side-by-side source and assembly windows; with the
28169status and command window being beneath these, filling the entire
28170width of the terminal. Because they have weight 2, the source and
28171assembly windows will be twice the height of the command window.
28172
6008fc5f 28173@item layout @var{name}
4644b6e3 28174@kindex layout
ee325b61
TT
28175Changes which TUI windows are displayed. The @var{name} parameter
28176controls which layout is shown. It can be either one of the built-in
28177layout names, or the name of a layout defined by the user using
28178@code{tui new-layout}.
28179
28180The built-in layouts are as follows:
6008fc5f
AB
28181
28182@table @code
28183@item next
8e04817f 28184Display the next layout.
2df3850c 28185
6008fc5f 28186@item prev
8e04817f 28187Display the previous layout.
c906108c 28188
6008fc5f
AB
28189@item src
28190Display the source and command windows.
c906108c 28191
6008fc5f
AB
28192@item asm
28193Display the assembly and command windows.
c906108c 28194
6008fc5f
AB
28195@item split
28196Display the source, assembly, and command windows.
c906108c 28197
6008fc5f
AB
28198@item regs
28199When in @code{src} layout display the register, source, and command
28200windows. When in @code{asm} or @code{split} layout display the
28201register, assembler, and command windows.
28202@end table
8e04817f 28203
6008fc5f 28204@item focus @var{name}
8e04817f 28205@kindex focus
6008fc5f
AB
28206Changes which TUI window is currently active for scrolling. The
28207@var{name} parameter can be any of the following:
28208
28209@table @code
28210@item next
46ba6afa
BW
28211Make the next window active for scrolling.
28212
6008fc5f 28213@item prev
46ba6afa
BW
28214Make the previous window active for scrolling.
28215
6008fc5f 28216@item src
46ba6afa
BW
28217Make the source window active for scrolling.
28218
6008fc5f 28219@item asm
46ba6afa
BW
28220Make the assembly window active for scrolling.
28221
6008fc5f 28222@item regs
46ba6afa
BW
28223Make the register window active for scrolling.
28224
6008fc5f 28225@item cmd
46ba6afa 28226Make the command window active for scrolling.
6008fc5f 28227@end table
c906108c 28228
8e04817f
AC
28229@item refresh
28230@kindex refresh
7f9087cb 28231Refresh the screen. This is similar to typing @kbd{C-L}.
c906108c 28232
51f0e40d 28233@item tui reg @var{group}
6a1b180d 28234@kindex tui reg
51f0e40d
AB
28235Changes the register group displayed in the tui register window to
28236@var{group}. If the register window is not currently displayed this
28237command will cause the register window to be displayed. The list of
28238register groups, as well as their order is target specific. The
28239following groups are available on most targets:
28240@table @code
28241@item next
28242Repeatedly selecting this group will cause the display to cycle
28243through all of the available register groups.
28244
28245@item prev
28246Repeatedly selecting this group will cause the display to cycle
28247through all of the available register groups in the reverse order to
28248@var{next}.
28249
28250@item general
28251Display the general registers.
28252@item float
28253Display the floating point registers.
28254@item system
28255Display the system registers.
28256@item vector
28257Display the vector registers.
28258@item all
28259Display all registers.
28260@end table
6a1b180d 28261
8e04817f
AC
28262@item update
28263@kindex update
28264Update the source window and the current execution point.
c906108c 28265
8e04817f
AC
28266@item winheight @var{name} +@var{count}
28267@itemx winheight @var{name} -@var{count}
28268@kindex winheight
28269Change the height of the window @var{name} by @var{count}
28270lines. Positive counts increase the height, while negative counts
bf555842
EZ
28271decrease it. The @var{name} parameter can be one of @code{src} (the
28272source window), @code{cmd} (the command window), @code{asm} (the
28273disassembly window), or @code{regs} (the register display window).
d6677607 28274@end table
2df3850c 28275
8e04817f 28276@node TUI Configuration
79a6e687 28277@section TUI Configuration Variables
8e04817f 28278@cindex TUI configuration variables
c906108c 28279
46ba6afa 28280Several configuration variables control the appearance of TUI windows.
c906108c 28281
8e04817f
AC
28282@table @code
28283@item set tui border-kind @var{kind}
28284@kindex set tui border-kind
28285Select the border appearance for the source, assembly and register windows.
28286The possible values are the following:
28287@table @code
28288@item space
28289Use a space character to draw the border.
c906108c 28290
8e04817f 28291@item ascii
46ba6afa 28292Use @sc{ascii} characters @samp{+}, @samp{-} and @samp{|} to draw the border.
c906108c 28293
8e04817f
AC
28294@item acs
28295Use the Alternate Character Set to draw the border. The border is
28296drawn using character line graphics if the terminal supports them.
8e04817f 28297@end table
c78b4128 28298
8e04817f
AC
28299@item set tui border-mode @var{mode}
28300@kindex set tui border-mode
46ba6afa
BW
28301@itemx set tui active-border-mode @var{mode}
28302@kindex set tui active-border-mode
28303Select the display attributes for the borders of the inactive windows
28304or the active window. The @var{mode} can be one of the following:
8e04817f
AC
28305@table @code
28306@item normal
28307Use normal attributes to display the border.
c906108c 28308
8e04817f
AC
28309@item standout
28310Use standout mode.
c906108c 28311
8e04817f
AC
28312@item reverse
28313Use reverse video mode.
c906108c 28314
8e04817f
AC
28315@item half
28316Use half bright mode.
c906108c 28317
8e04817f
AC
28318@item half-standout
28319Use half bright and standout mode.
c906108c 28320
8e04817f
AC
28321@item bold
28322Use extra bright or bold mode.
c78b4128 28323
8e04817f
AC
28324@item bold-standout
28325Use extra bright or bold and standout mode.
8e04817f 28326@end table
7806cea7
TT
28327
28328@item set tui tab-width @var{nchars}
28329@kindex set tui tab-width
28330@kindex tabset
28331Set the width of tab stops to be @var{nchars} characters. This
28332setting affects the display of TAB characters in the source and
28333assembly windows.
d1da6b01
TT
28334
28335@item set tui compact-source @r{[}on@r{|}off@r{]}
28336@kindex set tui compact-source
28337Set whether the TUI source window is displayed in ``compact'' form.
28338The default display uses more space for line numbers and starts the
28339source text at the next tab stop; the compact display uses only as
28340much space as is needed for the line numbers in the current file, and
28341only a single space to separate the line numbers from the source.
7806cea7 28342@end table
c78b4128 28343
a2a7af0c
TT
28344Note that the colors of the TUI borders can be controlled using the
28345appropriate @code{set style} commands. @xref{Output Styling}.
28346
8e04817f
AC
28347@node Emacs
28348@chapter Using @value{GDBN} under @sc{gnu} Emacs
c78b4128 28349
8e04817f
AC
28350@cindex Emacs
28351@cindex @sc{gnu} Emacs
28352A special interface allows you to use @sc{gnu} Emacs to view (and
28353edit) the source files for the program you are debugging with
28354@value{GDBN}.
c906108c 28355
8e04817f
AC
28356To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
28357executable file you want to debug as an argument. This command starts
28358@value{GDBN} as a subprocess of Emacs, with input and output through a newly
28359created Emacs buffer.
28360@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
c906108c 28361
5e252a2e 28362Running @value{GDBN} under Emacs can be just like running @value{GDBN} normally except for two
8e04817f 28363things:
c906108c 28364
8e04817f
AC
28365@itemize @bullet
28366@item
5e252a2e
NR
28367All ``terminal'' input and output goes through an Emacs buffer, called
28368the GUD buffer.
c906108c 28369
8e04817f
AC
28370This applies both to @value{GDBN} commands and their output, and to the input
28371and output done by the program you are debugging.
bf0184be 28372
8e04817f
AC
28373This is useful because it means that you can copy the text of previous
28374commands and input them again; you can even use parts of the output
28375in this way.
bf0184be 28376
8e04817f
AC
28377All the facilities of Emacs' Shell mode are available for interacting
28378with your program. In particular, you can send signals the usual
28379way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
28380stop.
bf0184be
ND
28381
28382@item
8e04817f 28383@value{GDBN} displays source code through Emacs.
bf0184be 28384
8e04817f
AC
28385Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
28386source file for that frame and puts an arrow (@samp{=>}) at the
28387left margin of the current line. Emacs uses a separate buffer for
28388source display, and splits the screen to show both your @value{GDBN} session
28389and the source.
bf0184be 28390
8e04817f
AC
28391Explicit @value{GDBN} @code{list} or search commands still produce output as
28392usual, but you probably have no reason to use them from Emacs.
5e252a2e
NR
28393@end itemize
28394
28395We call this @dfn{text command mode}. Emacs 22.1, and later, also uses
28396a graphical mode, enabled by default, which provides further buffers
28397that can control the execution and describe the state of your program.
28398@xref{GDB Graphical Interface,,, Emacs, The @sc{gnu} Emacs Manual}.
c906108c 28399
64fabec2
AC
28400If you specify an absolute file name when prompted for the @kbd{M-x
28401gdb} argument, then Emacs sets your current working directory to where
28402your program resides. If you only specify the file name, then Emacs
7a9dd1b2 28403sets your current working directory to the directory associated
64fabec2
AC
28404with the previous buffer. In this case, @value{GDBN} may find your
28405program by searching your environment's @code{PATH} variable, but on
28406some operating systems it might not find the source. So, although the
28407@value{GDBN} input and output session proceeds normally, the auxiliary
28408buffer does not display the current source and line of execution.
28409
28410The initial working directory of @value{GDBN} is printed on the top
5e252a2e
NR
28411line of the GUD buffer and this serves as a default for the commands
28412that specify files for @value{GDBN} to operate on. @xref{Files,
28413,Commands to Specify Files}.
64fabec2
AC
28414
28415By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
28416need to call @value{GDBN} by a different name (for example, if you
28417keep several configurations around, with different names) you can
28418customize the Emacs variable @code{gud-gdb-command-name} to run the
28419one you want.
8e04817f 28420
5e252a2e 28421In the GUD buffer, you can use these special Emacs commands in
8e04817f 28422addition to the standard Shell mode commands:
c906108c 28423
8e04817f
AC
28424@table @kbd
28425@item C-h m
5e252a2e 28426Describe the features of Emacs' GUD Mode.
c906108c 28427
64fabec2 28428@item C-c C-s
8e04817f
AC
28429Execute to another source line, like the @value{GDBN} @code{step} command; also
28430update the display window to show the current file and location.
c906108c 28431
64fabec2 28432@item C-c C-n
8e04817f
AC
28433Execute to next source line in this function, skipping all function
28434calls, like the @value{GDBN} @code{next} command. Then update the display window
28435to show the current file and location.
c906108c 28436
64fabec2 28437@item C-c C-i
8e04817f
AC
28438Execute one instruction, like the @value{GDBN} @code{stepi} command; update
28439display window accordingly.
c906108c 28440
8e04817f
AC
28441@item C-c C-f
28442Execute until exit from the selected stack frame, like the @value{GDBN}
28443@code{finish} command.
c906108c 28444
64fabec2 28445@item C-c C-r
8e04817f
AC
28446Continue execution of your program, like the @value{GDBN} @code{continue}
28447command.
b433d00b 28448
64fabec2 28449@item C-c <
8e04817f
AC
28450Go up the number of frames indicated by the numeric argument
28451(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
28452like the @value{GDBN} @code{up} command.
b433d00b 28453
64fabec2 28454@item C-c >
8e04817f
AC
28455Go down the number of frames indicated by the numeric argument, like the
28456@value{GDBN} @code{down} command.
8e04817f 28457@end table
c906108c 28458
7f9087cb 28459In any source file, the Emacs command @kbd{C-x @key{SPC}} (@code{gud-break})
8e04817f 28460tells @value{GDBN} to set a breakpoint on the source line point is on.
c906108c 28461
5e252a2e
NR
28462In text command mode, if you type @kbd{M-x speedbar}, Emacs displays a
28463separate frame which shows a backtrace when the GUD buffer is current.
28464Move point to any frame in the stack and type @key{RET} to make it
28465become the current frame and display the associated source in the
28466source buffer. Alternatively, click @kbd{Mouse-2} to make the
28467selected frame become the current one. In graphical mode, the
28468speedbar displays watch expressions.
64fabec2 28469
8e04817f
AC
28470If you accidentally delete the source-display buffer, an easy way to get
28471it back is to type the command @code{f} in the @value{GDBN} buffer, to
28472request a frame display; when you run under Emacs, this recreates
28473the source buffer if necessary to show you the context of the current
28474frame.
c906108c 28475
8e04817f
AC
28476The source files displayed in Emacs are in ordinary Emacs buffers
28477which are visiting the source files in the usual way. You can edit
28478the files with these buffers if you wish; but keep in mind that @value{GDBN}
28479communicates with Emacs in terms of line numbers. If you add or
28480delete lines from the text, the line numbers that @value{GDBN} knows cease
28481to correspond properly with the code.
b383017d 28482
5e252a2e
NR
28483A more detailed description of Emacs' interaction with @value{GDBN} is
28484given in the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu}
28485Emacs Manual}).
c906108c 28486
922fbb7b
AC
28487@node GDB/MI
28488@chapter The @sc{gdb/mi} Interface
28489
28490@unnumberedsec Function and Purpose
28491
28492@cindex @sc{gdb/mi}, its purpose
6b5e8c01
NR
28493@sc{gdb/mi} is a line based machine oriented text interface to
28494@value{GDBN} and is activated by specifying using the
28495@option{--interpreter} command line option (@pxref{Mode Options}). It
28496is specifically intended to support the development of systems which
28497use the debugger as just one small component of a larger system.
922fbb7b
AC
28498
28499This chapter is a specification of the @sc{gdb/mi} interface. It is written
28500in the form of a reference manual.
28501
28502Note that @sc{gdb/mi} is still under construction, so some of the
af6eff6f
NR
28503features described below are incomplete and subject to change
28504(@pxref{GDB/MI Development and Front Ends, , @sc{gdb/mi} Development and Front Ends}).
922fbb7b
AC
28505
28506@unnumberedsec Notation and Terminology
28507
28508@cindex notational conventions, for @sc{gdb/mi}
28509This chapter uses the following notation:
28510
28511@itemize @bullet
28512@item
28513@code{|} separates two alternatives.
28514
28515@item
28516@code{[ @var{something} ]} indicates that @var{something} is optional:
28517it may or may not be given.
28518
28519@item
28520@code{( @var{group} )*} means that @var{group} inside the parentheses
28521may repeat zero or more times.
28522
28523@item
28524@code{( @var{group} )+} means that @var{group} inside the parentheses
28525may repeat one or more times.
28526
28527@item
28528@code{"@var{string}"} means a literal @var{string}.
28529@end itemize
28530
28531@ignore
28532@heading Dependencies
28533@end ignore
28534
922fbb7b 28535@menu
c3b108f7 28536* GDB/MI General Design::
922fbb7b
AC
28537* GDB/MI Command Syntax::
28538* GDB/MI Compatibility with CLI::
af6eff6f 28539* GDB/MI Development and Front Ends::
922fbb7b 28540* GDB/MI Output Records::
ef21caaf 28541* GDB/MI Simple Examples::
922fbb7b 28542* GDB/MI Command Description Format::
ef21caaf 28543* GDB/MI Breakpoint Commands::
3fa7bf06 28544* GDB/MI Catchpoint Commands::
a2c02241
NR
28545* GDB/MI Program Context::
28546* GDB/MI Thread Commands::
5d77fe44 28547* GDB/MI Ada Tasking Commands::
a2c02241
NR
28548* GDB/MI Program Execution::
28549* GDB/MI Stack Manipulation::
28550* GDB/MI Variable Objects::
922fbb7b 28551* GDB/MI Data Manipulation::
a2c02241
NR
28552* GDB/MI Tracepoint Commands::
28553* GDB/MI Symbol Query::
351ff01a 28554* GDB/MI File Commands::
922fbb7b
AC
28555@ignore
28556* GDB/MI Kod Commands::
28557* GDB/MI Memory Overlay Commands::
28558* GDB/MI Signal Handling Commands::
28559@end ignore
922fbb7b 28560* GDB/MI Target Manipulation::
a6b151f1 28561* GDB/MI File Transfer Commands::
58d06528 28562* GDB/MI Ada Exceptions Commands::
d192b373 28563* GDB/MI Support Commands::
ef21caaf 28564* GDB/MI Miscellaneous Commands::
922fbb7b
AC
28565@end menu
28566
c3b108f7
VP
28567@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28568@node GDB/MI General Design
28569@section @sc{gdb/mi} General Design
28570@cindex GDB/MI General Design
28571
28572Interaction of a @sc{GDB/MI} frontend with @value{GDBN} involves three
28573parts---commands sent to @value{GDBN}, responses to those commands
28574and notifications. Each command results in exactly one response,
28575indicating either successful completion of the command, or an error.
28576For the commands that do not resume the target, the response contains the
28577requested information. For the commands that resume the target, the
28578response only indicates whether the target was successfully resumed.
28579Notifications is the mechanism for reporting changes in the state of the
28580target, or in @value{GDBN} state, that cannot conveniently be associated with
28581a command and reported as part of that command response.
28582
28583The important examples of notifications are:
28584@itemize @bullet
28585
28586@item
28587Exec notifications. These are used to report changes in
28588target state---when a target is resumed, or stopped. It would not
28589be feasible to include this information in response of resuming
28590commands, because one resume commands can result in multiple events in
28591different threads. Also, quite some time may pass before any event
28592happens in the target, while a frontend needs to know whether the resuming
28593command itself was successfully executed.
28594
28595@item
28596Console output, and status notifications. Console output
28597notifications are used to report output of CLI commands, as well as
28598diagnostics for other commands. Status notifications are used to
28599report the progress of a long-running operation. Naturally, including
28600this information in command response would mean no output is produced
28601until the command is finished, which is undesirable.
28602
28603@item
28604General notifications. Commands may have various side effects on
28605the @value{GDBN} or target state beyond their official purpose. For example,
28606a command may change the selected thread. Although such changes can
28607be included in command response, using notification allows for more
28608orthogonal frontend design.
28609
28610@end itemize
28611
28612There's no guarantee that whenever an MI command reports an error,
28613@value{GDBN} or the target are in any specific state, and especially,
28614the state is not reverted to the state before the MI command was
28615processed. Therefore, whenever an MI command results in an error,
28616we recommend that the frontend refreshes all the information shown in
28617the user interface.
28618
508094de
NR
28619
28620@menu
28621* Context management::
28622* Asynchronous and non-stop modes::
28623* Thread groups::
28624@end menu
28625
28626@node Context management
c3b108f7
VP
28627@subsection Context management
28628
403cb6b1
JB
28629@subsubsection Threads and Frames
28630
c3b108f7
VP
28631In most cases when @value{GDBN} accesses the target, this access is
28632done in context of a specific thread and frame (@pxref{Frames}).
28633Often, even when accessing global data, the target requires that a thread
28634be specified. The CLI interface maintains the selected thread and frame,
28635and supplies them to target on each command. This is convenient,
28636because a command line user would not want to specify that information
28637explicitly on each command, and because user interacts with
28638@value{GDBN} via a single terminal, so no confusion is possible as
28639to what thread and frame are the current ones.
28640
28641In the case of MI, the concept of selected thread and frame is less
28642useful. First, a frontend can easily remember this information
28643itself. Second, a graphical frontend can have more than one window,
28644each one used for debugging a different thread, and the frontend might
28645want to access additional threads for internal purposes. This
28646increases the risk that by relying on implicitly selected thread, the
28647frontend may be operating on a wrong one. Therefore, each MI command
28648should explicitly specify which thread and frame to operate on. To
28649make it possible, each MI command accepts the @samp{--thread} and
5d5658a1
PA
28650@samp{--frame} options, the value to each is @value{GDBN} global
28651identifier for thread and frame to operate on.
c3b108f7
VP
28652
28653Usually, each top-level window in a frontend allows the user to select
28654a thread and a frame, and remembers the user selection for further
28655operations. However, in some cases @value{GDBN} may suggest that the
4034d0ff
AT
28656current thread or frame be changed. For example, when stopping on a
28657breakpoint it is reasonable to switch to the thread where breakpoint is
28658hit. For another example, if the user issues the CLI @samp{thread} or
28659@samp{frame} commands via the frontend, it is desirable to change the
28660frontend's selection to the one specified by user. @value{GDBN}
28661communicates the suggestion to change current thread and frame using the
28662@samp{=thread-selected} notification.
c3b108f7
VP
28663
28664Note that historically, MI shares the selected thread with CLI, so
28665frontends used the @code{-thread-select} to execute commands in the
28666right context. However, getting this to work right is cumbersome. The
28667simplest way is for frontend to emit @code{-thread-select} command
28668before every command. This doubles the number of commands that need
28669to be sent. The alternative approach is to suppress @code{-thread-select}
28670if the selected thread in @value{GDBN} is supposed to be identical to the
28671thread the frontend wants to operate on. However, getting this
28672optimization right can be tricky. In particular, if the frontend
28673sends several commands to @value{GDBN}, and one of the commands changes the
28674selected thread, then the behaviour of subsequent commands will
28675change. So, a frontend should either wait for response from such
28676problematic commands, or explicitly add @code{-thread-select} for
28677all subsequent commands. No frontend is known to do this exactly
28678right, so it is suggested to just always pass the @samp{--thread} and
28679@samp{--frame} options.
28680
403cb6b1
JB
28681@subsubsection Language
28682
28683The execution of several commands depends on which language is selected.
28684By default, the current language (@pxref{show language}) is used.
28685But for commands known to be language-sensitive, it is recommended
28686to use the @samp{--language} option. This option takes one argument,
28687which is the name of the language to use while executing the command.
28688For instance:
28689
28690@smallexample
28691-data-evaluate-expression --language c "sizeof (void*)"
28692^done,value="4"
28693(gdb)
28694@end smallexample
28695
28696The valid language names are the same names accepted by the
28697@samp{set language} command (@pxref{Manually}), excluding @samp{auto},
28698@samp{local} or @samp{unknown}.
28699
508094de 28700@node Asynchronous and non-stop modes
c3b108f7
VP
28701@subsection Asynchronous command execution and non-stop mode
28702
28703On some targets, @value{GDBN} is capable of processing MI commands
28704even while the target is running. This is called @dfn{asynchronous
28705command execution} (@pxref{Background Execution}). The frontend may
6b92c0d3 28706specify a preference for asynchronous execution using the
329ea579 28707@code{-gdb-set mi-async 1} command, which should be emitted before
c3b108f7
VP
28708either running the executable or attaching to the target. After the
28709frontend has started the executable or attached to the target, it can
28710find if asynchronous execution is enabled using the
28711@code{-list-target-features} command.
28712
329ea579
PA
28713@table @code
28714@item -gdb-set mi-async on
28715@item -gdb-set mi-async off
28716Set whether MI is in asynchronous mode.
28717
28718When @code{off}, which is the default, MI execution commands (e.g.,
28719@code{-exec-continue}) are foreground commands, and @value{GDBN} waits
28720for the program to stop before processing further commands.
28721
28722When @code{on}, MI execution commands are background execution
28723commands (e.g., @code{-exec-continue} becomes the equivalent of the
28724@code{c&} CLI command), and so @value{GDBN} is capable of processing
28725MI commands even while the target is running.
28726
28727@item -gdb-show mi-async
28728Show whether MI asynchronous mode is enabled.
28729@end table
28730
28731Note: In @value{GDBN} version 7.7 and earlier, this option was called
28732@code{target-async} instead of @code{mi-async}, and it had the effect
28733of both putting MI in asynchronous mode and making CLI background
28734commands possible. CLI background commands are now always possible
28735``out of the box'' if the target supports them. The old spelling is
28736kept as a deprecated alias for backwards compatibility.
28737
c3b108f7
VP
28738Even if @value{GDBN} can accept a command while target is running,
28739many commands that access the target do not work when the target is
28740running. Therefore, asynchronous command execution is most useful
28741when combined with non-stop mode (@pxref{Non-Stop Mode}). Then,
28742it is possible to examine the state of one thread, while other threads
28743are running.
28744
28745When a given thread is running, MI commands that try to access the
28746target in the context of that thread may not work, or may work only on
28747some targets. In particular, commands that try to operate on thread's
28748stack will not work, on any target. Commands that read memory, or
28749modify breakpoints, may work or not work, depending on the target. Note
28750that even commands that operate on global state, such as @code{print},
28751@code{set}, and breakpoint commands, still access the target in the
28752context of a specific thread, so frontend should try to find a
28753stopped thread and perform the operation on that thread (using the
28754@samp{--thread} option).
28755
28756Which commands will work in the context of a running thread is
28757highly target dependent. However, the two commands
28758@code{-exec-interrupt}, to stop a thread, and @code{-thread-info},
28759to find the state of a thread, will always work.
28760
508094de 28761@node Thread groups
c3b108f7
VP
28762@subsection Thread groups
28763@value{GDBN} may be used to debug several processes at the same time.
6b92c0d3 28764On some platforms, @value{GDBN} may support debugging of several
c3b108f7
VP
28765hardware systems, each one having several cores with several different
28766processes running on each core. This section describes the MI
28767mechanism to support such debugging scenarios.
28768
28769The key observation is that regardless of the structure of the
28770target, MI can have a global list of threads, because most commands that
28771accept the @samp{--thread} option do not need to know what process that
28772thread belongs to. Therefore, it is not necessary to introduce
28773neither additional @samp{--process} option, nor an notion of the
28774current process in the MI interface. The only strictly new feature
28775that is required is the ability to find how the threads are grouped
28776into processes.
28777
28778To allow the user to discover such grouping, and to support arbitrary
28779hierarchy of machines/cores/processes, MI introduces the concept of a
28780@dfn{thread group}. Thread group is a collection of threads and other
28781thread groups. A thread group always has a string identifier, a type,
28782and may have additional attributes specific to the type. A new
28783command, @code{-list-thread-groups}, returns the list of top-level
28784thread groups, which correspond to processes that @value{GDBN} is
28785debugging at the moment. By passing an identifier of a thread group
28786to the @code{-list-thread-groups} command, it is possible to obtain
28787the members of specific thread group.
28788
28789To allow the user to easily discover processes, and other objects, he
28790wishes to debug, a concept of @dfn{available thread group} is
28791introduced. Available thread group is an thread group that
28792@value{GDBN} is not debugging, but that can be attached to, using the
28793@code{-target-attach} command. The list of available top-level thread
28794groups can be obtained using @samp{-list-thread-groups --available}.
28795In general, the content of a thread group may be only retrieved only
28796after attaching to that thread group.
28797
65c574f6 28798Thread groups are related to inferiors (@pxref{Inferiors Connections and
a79b8f6e
VP
28799Programs}). Each inferior corresponds to a thread group of a special
28800type @samp{process}, and some additional operations are permitted on
28801such thread groups.
28802
922fbb7b
AC
28803@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28804@node GDB/MI Command Syntax
28805@section @sc{gdb/mi} Command Syntax
28806
28807@menu
28808* GDB/MI Input Syntax::
28809* GDB/MI Output Syntax::
922fbb7b
AC
28810@end menu
28811
28812@node GDB/MI Input Syntax
28813@subsection @sc{gdb/mi} Input Syntax
28814
28815@cindex input syntax for @sc{gdb/mi}
28816@cindex @sc{gdb/mi}, input syntax
28817@table @code
28818@item @var{command} @expansion{}
28819@code{@var{cli-command} | @var{mi-command}}
28820
28821@item @var{cli-command} @expansion{}
28822@code{[ @var{token} ] @var{cli-command} @var{nl}}, where
28823@var{cli-command} is any existing @value{GDBN} CLI command.
28824
28825@item @var{mi-command} @expansion{}
28826@code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
28827@code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
28828
28829@item @var{token} @expansion{}
28830"any sequence of digits"
28831
28832@item @var{option} @expansion{}
28833@code{"-" @var{parameter} [ " " @var{parameter} ]}
28834
28835@item @var{parameter} @expansion{}
28836@code{@var{non-blank-sequence} | @var{c-string}}
28837
28838@item @var{operation} @expansion{}
28839@emph{any of the operations described in this chapter}
28840
28841@item @var{non-blank-sequence} @expansion{}
28842@emph{anything, provided it doesn't contain special characters such as
28843"-", @var{nl}, """ and of course " "}
28844
28845@item @var{c-string} @expansion{}
28846@code{""" @var{seven-bit-iso-c-string-content} """}
28847
28848@item @var{nl} @expansion{}
28849@code{CR | CR-LF}
28850@end table
28851
28852@noindent
28853Notes:
28854
28855@itemize @bullet
28856@item
28857The CLI commands are still handled by the @sc{mi} interpreter; their
28858output is described below.
28859
28860@item
28861The @code{@var{token}}, when present, is passed back when the command
28862finishes.
28863
28864@item
28865Some @sc{mi} commands accept optional arguments as part of the parameter
28866list. Each option is identified by a leading @samp{-} (dash) and may be
28867followed by an optional argument parameter. Options occur first in the
28868parameter list and can be delimited from normal parameters using
28869@samp{--} (this is useful when some parameters begin with a dash).
28870@end itemize
28871
28872Pragmatics:
28873
28874@itemize @bullet
28875@item
28876We want easy access to the existing CLI syntax (for debugging).
28877
28878@item
28879We want it to be easy to spot a @sc{mi} operation.
28880@end itemize
28881
28882@node GDB/MI Output Syntax
28883@subsection @sc{gdb/mi} Output Syntax
28884
28885@cindex output syntax of @sc{gdb/mi}
28886@cindex @sc{gdb/mi}, output syntax
28887The output from @sc{gdb/mi} consists of zero or more out-of-band records
28888followed, optionally, by a single result record. This result record
28889is for the most recent command. The sequence of output records is
594fe323 28890terminated by @samp{(gdb)}.
922fbb7b
AC
28891
28892If an input command was prefixed with a @code{@var{token}} then the
28893corresponding output for that command will also be prefixed by that same
28894@var{token}.
28895
28896@table @code
28897@item @var{output} @expansion{}
594fe323 28898@code{( @var{out-of-band-record} )* [ @var{result-record} ] "(gdb)" @var{nl}}
922fbb7b
AC
28899
28900@item @var{result-record} @expansion{}
28901@code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
28902
28903@item @var{out-of-band-record} @expansion{}
28904@code{@var{async-record} | @var{stream-record}}
28905
28906@item @var{async-record} @expansion{}
28907@code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
28908
28909@item @var{exec-async-output} @expansion{}
dcf106f3 28910@code{[ @var{token} ] "*" @var{async-output nl}}
922fbb7b
AC
28911
28912@item @var{status-async-output} @expansion{}
dcf106f3 28913@code{[ @var{token} ] "+" @var{async-output nl}}
922fbb7b
AC
28914
28915@item @var{notify-async-output} @expansion{}
dcf106f3 28916@code{[ @var{token} ] "=" @var{async-output nl}}
922fbb7b
AC
28917
28918@item @var{async-output} @expansion{}
dcf106f3 28919@code{@var{async-class} ( "," @var{result} )*}
922fbb7b
AC
28920
28921@item @var{result-class} @expansion{}
28922@code{"done" | "running" | "connected" | "error" | "exit"}
28923
28924@item @var{async-class} @expansion{}
28925@code{"stopped" | @var{others}} (where @var{others} will be added
28926depending on the needs---this is still in development).
28927
28928@item @var{result} @expansion{}
28929@code{ @var{variable} "=" @var{value}}
28930
28931@item @var{variable} @expansion{}
28932@code{ @var{string} }
28933
28934@item @var{value} @expansion{}
28935@code{ @var{const} | @var{tuple} | @var{list} }
28936
28937@item @var{const} @expansion{}
28938@code{@var{c-string}}
28939
28940@item @var{tuple} @expansion{}
28941@code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
28942
28943@item @var{list} @expansion{}
28944@code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
28945@var{result} ( "," @var{result} )* "]" }
28946
28947@item @var{stream-record} @expansion{}
28948@code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
28949
28950@item @var{console-stream-output} @expansion{}
dcf106f3 28951@code{"~" @var{c-string nl}}
922fbb7b
AC
28952
28953@item @var{target-stream-output} @expansion{}
dcf106f3 28954@code{"@@" @var{c-string nl}}
922fbb7b
AC
28955
28956@item @var{log-stream-output} @expansion{}
dcf106f3 28957@code{"&" @var{c-string nl}}
922fbb7b
AC
28958
28959@item @var{nl} @expansion{}
28960@code{CR | CR-LF}
28961
28962@item @var{token} @expansion{}
28963@emph{any sequence of digits}.
28964@end table
28965
28966@noindent
28967Notes:
28968
28969@itemize @bullet
28970@item
28971All output sequences end in a single line containing a period.
28972
28973@item
721c02de
VP
28974The @code{@var{token}} is from the corresponding request. Note that
28975for all async output, while the token is allowed by the grammar and
28976may be output by future versions of @value{GDBN} for select async
28977output messages, it is generally omitted. Frontends should treat
28978all async output as reporting general changes in the state of the
28979target and there should be no need to associate async output to any
28980prior command.
922fbb7b
AC
28981
28982@item
28983@cindex status output in @sc{gdb/mi}
28984@var{status-async-output} contains on-going status information about the
28985progress of a slow operation. It can be discarded. All status output is
28986prefixed by @samp{+}.
28987
28988@item
28989@cindex async output in @sc{gdb/mi}
28990@var{exec-async-output} contains asynchronous state change on the target
28991(stopped, started, disappeared). All async output is prefixed by
28992@samp{*}.
28993
28994@item
28995@cindex notify output in @sc{gdb/mi}
28996@var{notify-async-output} contains supplementary information that the
28997client should handle (e.g., a new breakpoint information). All notify
28998output is prefixed by @samp{=}.
28999
29000@item
29001@cindex console output in @sc{gdb/mi}
29002@var{console-stream-output} is output that should be displayed as is in the
29003console. It is the textual response to a CLI command. All the console
29004output is prefixed by @samp{~}.
29005
29006@item
29007@cindex target output in @sc{gdb/mi}
29008@var{target-stream-output} is the output produced by the target program.
29009All the target output is prefixed by @samp{@@}.
29010
29011@item
29012@cindex log output in @sc{gdb/mi}
29013@var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
29014instance messages that should be displayed as part of an error log. All
29015the log output is prefixed by @samp{&}.
29016
29017@item
29018@cindex list output in @sc{gdb/mi}
29019New @sc{gdb/mi} commands should only output @var{lists} containing
29020@var{values}.
29021
29022
29023@end itemize
29024
29025@xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
29026details about the various output records.
29027
922fbb7b
AC
29028@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29029@node GDB/MI Compatibility with CLI
29030@section @sc{gdb/mi} Compatibility with CLI
29031
29032@cindex compatibility, @sc{gdb/mi} and CLI
29033@cindex @sc{gdb/mi}, compatibility with CLI
922fbb7b 29034
a2c02241
NR
29035For the developers convenience CLI commands can be entered directly,
29036but there may be some unexpected behaviour. For example, commands
29037that query the user will behave as if the user replied yes, breakpoint
29038command lists are not executed and some CLI commands, such as
29039@code{if}, @code{when} and @code{define}, prompt for further input with
29040@samp{>}, which is not valid MI output.
ef21caaf
NR
29041
29042This feature may be removed at some stage in the future and it is
a2c02241
NR
29043recommended that front ends use the @code{-interpreter-exec} command
29044(@pxref{-interpreter-exec}).
922fbb7b 29045
af6eff6f
NR
29046@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29047@node GDB/MI Development and Front Ends
29048@section @sc{gdb/mi} Development and Front Ends
29049@cindex @sc{gdb/mi} development
29050
29051The application which takes the MI output and presents the state of the
29052program being debugged to the user is called a @dfn{front end}.
29053
1fea0d53
SM
29054Since @sc{gdb/mi} is used by a variety of front ends to @value{GDBN}, changes
29055to the MI interface may break existing usage. This section describes how the
29056protocol changes and how to request previous version of the protocol when it
29057does.
af6eff6f
NR
29058
29059Some changes in MI need not break a carefully designed front end, and
29060for these the MI version will remain unchanged. The following is a
29061list of changes that may occur within one level, so front ends should
29062parse MI output in a way that can handle them:
29063
29064@itemize @bullet
29065@item
29066New MI commands may be added.
29067
29068@item
29069New fields may be added to the output of any MI command.
29070
36ece8b3
NR
29071@item
29072The range of values for fields with specified values, e.g.,
9f708cb2 29073@code{in_scope} (@pxref{-var-update}) may be extended.
36ece8b3 29074
af6eff6f
NR
29075@c The format of field's content e.g type prefix, may change so parse it
29076@c at your own risk. Yes, in general?
29077
29078@c The order of fields may change? Shouldn't really matter but it might
29079@c resolve inconsistencies.
29080@end itemize
29081
29082If the changes are likely to break front ends, the MI version level
1fea0d53
SM
29083will be increased by one. The new versions of the MI protocol are not compatible
29084with the old versions. Old versions of MI remain available, allowing front ends
29085to keep using them until they are modified to use the latest MI version.
af6eff6f 29086
1fea0d53
SM
29087Since @code{--interpreter=mi} always points to the latest MI version, it is
29088recommended that front ends request a specific version of MI when launching
29089@value{GDBN} (e.g. @code{--interpreter=mi2}) to make sure they get an
29090interpreter with the MI version they expect.
29091
09f2921c 29092The following table gives a summary of the released versions of the MI
1fea0d53
SM
29093interface: the version number, the version of GDB in which it first appeared
29094and the breaking changes compared to the previous version.
29095
29096@multitable @columnfractions .05 .05 .9
29097@headitem MI version @tab GDB version @tab Breaking changes
29098
29099@item
29100@center 1
29101@tab
29102@center 5.1
29103@tab
29104None
29105
29106@item
29107@center 2
29108@tab
29109@center 6.0
29110@tab
29111
29112@itemize
29113@item
29114The @code{-environment-pwd}, @code{-environment-directory} and
29115@code{-environment-path} commands now returns values using the MI output
29116syntax, rather than CLI output syntax.
29117
29118@item
29119@code{-var-list-children}'s @code{children} result field is now a list, rather
29120than a tuple.
29121
29122@item
29123@code{-var-update}'s @code{changelist} result field is now a list, rather than
29124a tuple.
29125@end itemize
29126
b4be1b06
SM
29127@item
29128@center 3
29129@tab
29130@center 9.1
29131@tab
29132
29133@itemize
29134@item
29135The output of information about multi-location breakpoints has changed in the
29136responses to the @code{-break-insert} and @code{-break-info} commands, as well
29137as in the @code{=breakpoint-created} and @code{=breakpoint-modified} events.
29138The multiple locations are now placed in a @code{locations} field, whose value
29139is a list.
29140@end itemize
29141
1fea0d53 29142@end multitable
af6eff6f 29143
b4be1b06
SM
29144If your front end cannot yet migrate to a more recent version of the
29145MI protocol, you can nevertheless selectively enable specific features
29146available in those recent MI versions, using the following commands:
29147
29148@table @code
29149
29150@item -fix-multi-location-breakpoint-output
29151Use the output for multi-location breakpoints which was introduced by
29152MI 3, even when using MI versions 2 or 1. This command has no
29153effect when using MI version 3 or later.
29154
5c85e20d 29155@end table
b4be1b06 29156
af6eff6f
NR
29157The best way to avoid unexpected changes in MI that might break your front
29158end is to make your project known to @value{GDBN} developers and
7a9a6b69 29159follow development on @email{gdb@@sourceware.org} and
fa0f268d 29160@email{gdb-patches@@sourceware.org}.
af6eff6f
NR
29161@cindex mailing lists
29162
922fbb7b
AC
29163@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29164@node GDB/MI Output Records
29165@section @sc{gdb/mi} Output Records
29166
29167@menu
29168* GDB/MI Result Records::
29169* GDB/MI Stream Records::
82f68b1c 29170* GDB/MI Async Records::
54516a0b 29171* GDB/MI Breakpoint Information::
c3b108f7 29172* GDB/MI Frame Information::
dc146f7c 29173* GDB/MI Thread Information::
4368ebeb 29174* GDB/MI Ada Exception Information::
922fbb7b
AC
29175@end menu
29176
29177@node GDB/MI Result Records
29178@subsection @sc{gdb/mi} Result Records
29179
29180@cindex result records in @sc{gdb/mi}
29181@cindex @sc{gdb/mi}, result records
29182In addition to a number of out-of-band notifications, the response to a
29183@sc{gdb/mi} command includes one of the following result indications:
29184
29185@table @code
29186@findex ^done
29187@item "^done" [ "," @var{results} ]
29188The synchronous operation was successful, @code{@var{results}} are the return
29189values.
29190
29191@item "^running"
29192@findex ^running
8e9c5e02
VP
29193This result record is equivalent to @samp{^done}. Historically, it
29194was output instead of @samp{^done} if the command has resumed the
29195target. This behaviour is maintained for backward compatibility, but
29196all frontends should treat @samp{^done} and @samp{^running}
29197identically and rely on the @samp{*running} output record to determine
29198which threads are resumed.
922fbb7b 29199
ef21caaf
NR
29200@item "^connected"
29201@findex ^connected
3f94c067 29202@value{GDBN} has connected to a remote target.
ef21caaf 29203
2ea126fa 29204@item "^error" "," "msg=" @var{c-string} [ "," "code=" @var{c-string} ]
922fbb7b 29205@findex ^error
2ea126fa
JB
29206The operation failed. The @code{msg=@var{c-string}} variable contains
29207the corresponding error message.
29208
29209If present, the @code{code=@var{c-string}} variable provides an error
29210code on which consumers can rely on to detect the corresponding
29211error condition. At present, only one error code is defined:
29212
29213@table @samp
29214@item "undefined-command"
29215Indicates that the command causing the error does not exist.
29216@end table
ef21caaf
NR
29217
29218@item "^exit"
29219@findex ^exit
3f94c067 29220@value{GDBN} has terminated.
ef21caaf 29221
922fbb7b
AC
29222@end table
29223
29224@node GDB/MI Stream Records
29225@subsection @sc{gdb/mi} Stream Records
29226
29227@cindex @sc{gdb/mi}, stream records
29228@cindex stream records in @sc{gdb/mi}
29229@value{GDBN} internally maintains a number of output streams: the console, the
29230target, and the log. The output intended for each of these streams is
29231funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
29232
29233Each stream record begins with a unique @dfn{prefix character} which
29234identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
29235Syntax}). In addition to the prefix, each stream record contains a
29236@code{@var{string-output}}. This is either raw text (with an implicit new
29237line) or a quoted C string (which does not contain an implicit newline).
29238
29239@table @code
29240@item "~" @var{string-output}
29241The console output stream contains text that should be displayed in the
29242CLI console window. It contains the textual responses to CLI commands.
29243
29244@item "@@" @var{string-output}
29245The target output stream contains any textual output from the running
ef21caaf
NR
29246target. This is only present when GDB's event loop is truly
29247asynchronous, which is currently only the case for remote targets.
922fbb7b
AC
29248
29249@item "&" @var{string-output}
29250The log stream contains debugging messages being produced by @value{GDBN}'s
29251internals.
29252@end table
29253
82f68b1c
VP
29254@node GDB/MI Async Records
29255@subsection @sc{gdb/mi} Async Records
922fbb7b 29256
82f68b1c
VP
29257@cindex async records in @sc{gdb/mi}
29258@cindex @sc{gdb/mi}, async records
29259@dfn{Async} records are used to notify the @sc{gdb/mi} client of
922fbb7b 29260additional changes that have occurred. Those changes can either be a
82f68b1c 29261consequence of @sc{gdb/mi} commands (e.g., a breakpoint modified) or a result of
922fbb7b
AC
29262target activity (e.g., target stopped).
29263
8eb41542 29264The following is the list of possible async records:
922fbb7b
AC
29265
29266@table @code
034dad6f 29267
e1ac3328 29268@item *running,thread-id="@var{thread}"
5d5658a1 29269The target is now running. The @var{thread} field can be the global
09f2921c 29270thread ID of the thread that is now running, and it can be
5d5658a1
PA
29271@samp{all} if all threads are running. The frontend should assume
29272that no interaction with a running thread is possible after this
29273notification is produced. The frontend should not assume that this
29274notification is output only once for any command. @value{GDBN} may
29275emit this notification several times, either for different threads,
29276because it cannot resume all threads together, or even for a single
29277thread, if the thread must be stepped though some code before letting
29278it run freely.
e1ac3328 29279
dc146f7c 29280@item *stopped,reason="@var{reason}",thread-id="@var{id}",stopped-threads="@var{stopped}",core="@var{core}"
82f68b1c
VP
29281The target has stopped. The @var{reason} field can have one of the
29282following values:
034dad6f
BR
29283
29284@table @code
29285@item breakpoint-hit
29286A breakpoint was reached.
29287@item watchpoint-trigger
29288A watchpoint was triggered.
29289@item read-watchpoint-trigger
29290A read watchpoint was triggered.
29291@item access-watchpoint-trigger
29292An access watchpoint was triggered.
29293@item function-finished
29294An -exec-finish or similar CLI command was accomplished.
29295@item location-reached
29296An -exec-until or similar CLI command was accomplished.
29297@item watchpoint-scope
29298A watchpoint has gone out of scope.
29299@item end-stepping-range
29300An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or
29301similar CLI command was accomplished.
29302@item exited-signalled
29303The inferior exited because of a signal.
29304@item exited
29305The inferior exited.
29306@item exited-normally
29307The inferior exited normally.
29308@item signal-received
29309A signal was received by the inferior.
36dfb11c
TT
29310@item solib-event
29311The inferior has stopped due to a library being loaded or unloaded.
edcc5120
TT
29312This can happen when @code{stop-on-solib-events} (@pxref{Files}) is
29313set or when a @code{catch load} or @code{catch unload} catchpoint is
29314in use (@pxref{Set Catchpoints}).
36dfb11c
TT
29315@item fork
29316The inferior has forked. This is reported when @code{catch fork}
29317(@pxref{Set Catchpoints}) has been used.
29318@item vfork
29319The inferior has vforked. This is reported in when @code{catch vfork}
29320(@pxref{Set Catchpoints}) has been used.
29321@item syscall-entry
29322The inferior entered a system call. This is reported when @code{catch
29323syscall} (@pxref{Set Catchpoints}) has been used.
a64c9f7b 29324@item syscall-return
36dfb11c
TT
29325The inferior returned from a system call. This is reported when
29326@code{catch syscall} (@pxref{Set Catchpoints}) has been used.
29327@item exec
29328The inferior called @code{exec}. This is reported when @code{catch exec}
29329(@pxref{Set Catchpoints}) has been used.
922fbb7b
AC
29330@end table
29331
5d5658a1
PA
29332The @var{id} field identifies the global thread ID of the thread
29333that directly caused the stop -- for example by hitting a breakpoint.
29334Depending on whether all-stop
c3b108f7
VP
29335mode is in effect (@pxref{All-Stop Mode}), @value{GDBN} may either
29336stop all threads, or only the thread that directly triggered the stop.
29337If all threads are stopped, the @var{stopped} field will have the
29338value of @code{"all"}. Otherwise, the value of the @var{stopped}
29339field will be a list of thread identifiers. Presently, this list will
29340always include a single thread, but frontend should be prepared to see
dc146f7c
VP
29341several threads in the list. The @var{core} field reports the
29342processor core on which the stop event has happened. This field may be absent
29343if such information is not available.
c3b108f7 29344
a79b8f6e
VP
29345@item =thread-group-added,id="@var{id}"
29346@itemx =thread-group-removed,id="@var{id}"
29347A thread group was either added or removed. The @var{id} field
29348contains the @value{GDBN} identifier of the thread group. When a thread
29349group is added, it generally might not be associated with a running
29350process. When a thread group is removed, its id becomes invalid and
29351cannot be used in any way.
29352
29353@item =thread-group-started,id="@var{id}",pid="@var{pid}"
29354A thread group became associated with a running program,
29355either because the program was just started or the thread group
29356was attached to a program. The @var{id} field contains the
29357@value{GDBN} identifier of the thread group. The @var{pid} field
29358contains process identifier, specific to the operating system.
29359
8cf64490 29360@item =thread-group-exited,id="@var{id}"[,exit-code="@var{code}"]
a79b8f6e
VP
29361A thread group is no longer associated with a running program,
29362either because the program has exited, or because it was detached
c3b108f7 29363from. The @var{id} field contains the @value{GDBN} identifier of the
697aa1b7 29364thread group. The @var{code} field is the exit code of the inferior; it exists
8cf64490 29365only when the inferior exited with some code.
c3b108f7
VP
29366
29367@item =thread-created,id="@var{id}",group-id="@var{gid}"
29368@itemx =thread-exited,id="@var{id}",group-id="@var{gid}"
82f68b1c 29369A thread either was created, or has exited. The @var{id} field
5d5658a1 29370contains the global @value{GDBN} identifier of the thread. The @var{gid}
c3b108f7 29371field identifies the thread group this thread belongs to.
66bb093b 29372
4034d0ff
AT
29373@item =thread-selected,id="@var{id}"[,frame="@var{frame}"]
29374Informs that the selected thread or frame were changed. This notification
29375is not emitted as result of the @code{-thread-select} or
29376@code{-stack-select-frame} commands, but is emitted whenever an MI command
29377that is not documented to change the selected thread and frame actually
29378changes them. In particular, invoking, directly or indirectly
29379(via user-defined command), the CLI @code{thread} or @code{frame} commands,
29380will generate this notification. Changing the thread or frame from another
29381user interface (see @ref{Interpreters}) will also generate this notification.
29382
29383The @var{frame} field is only present if the newly selected thread is
29384stopped. See @ref{GDB/MI Frame Information} for the format of its value.
66bb093b
VP
29385
29386We suggest that in response to this notification, front ends
29387highlight the selected thread and cause subsequent commands to apply to
29388that thread.
29389
c86cf029
VP
29390@item =library-loaded,...
29391Reports that a new library file was loaded by the program. This
51457a05
MAL
29392notification has 5 fields---@var{id}, @var{target-name},
29393@var{host-name}, @var{symbols-loaded} and @var{ranges}. The @var{id} field is an
c86cf029
VP
29394opaque identifier of the library. For remote debugging case,
29395@var{target-name} and @var{host-name} fields give the name of the
134eb42c
VP
29396library file on the target, and on the host respectively. For native
29397debugging, both those fields have the same value. The
f1cbe1d3
TT
29398@var{symbols-loaded} field is emitted only for backward compatibility
29399and should not be relied on to convey any useful information. The
29400@var{thread-group} field, if present, specifies the id of the thread
29401group in whose context the library was loaded. If the field is
29402absent, it means the library was loaded in the context of all present
51457a05
MAL
29403thread groups. The @var{ranges} field specifies the ranges of addresses belonging
29404to this library.
c86cf029
VP
29405
29406@item =library-unloaded,...
134eb42c 29407Reports that a library was unloaded by the program. This notification
c86cf029 29408has 3 fields---@var{id}, @var{target-name} and @var{host-name} with
a79b8f6e
VP
29409the same meaning as for the @code{=library-loaded} notification.
29410The @var{thread-group} field, if present, specifies the id of the
29411thread group in whose context the library was unloaded. If the field is
29412absent, it means the library was unloaded in the context of all present
29413thread groups.
c86cf029 29414
201b4506
YQ
29415@item =traceframe-changed,num=@var{tfnum},tracepoint=@var{tpnum}
29416@itemx =traceframe-changed,end
29417Reports that the trace frame was changed and its new number is
29418@var{tfnum}. The number of the tracepoint associated with this trace
29419frame is @var{tpnum}.
29420
134a2066 29421@item =tsv-created,name=@var{name},initial=@var{initial}
bb25a15c 29422Reports that the new trace state variable @var{name} is created with
134a2066 29423initial value @var{initial}.
bb25a15c
YQ
29424
29425@item =tsv-deleted,name=@var{name}
29426@itemx =tsv-deleted
29427Reports that the trace state variable @var{name} is deleted or all
29428trace state variables are deleted.
29429
134a2066
YQ
29430@item =tsv-modified,name=@var{name},initial=@var{initial}[,current=@var{current}]
29431Reports that the trace state variable @var{name} is modified with
29432the initial value @var{initial}. The current value @var{current} of
29433trace state variable is optional and is reported if the current
29434value of trace state variable is known.
29435
8d3788bd
VP
29436@item =breakpoint-created,bkpt=@{...@}
29437@itemx =breakpoint-modified,bkpt=@{...@}
d9f08f52 29438@itemx =breakpoint-deleted,id=@var{number}
8d3788bd
VP
29439Reports that a breakpoint was created, modified, or deleted,
29440respectively. Only user-visible breakpoints are reported to the MI
29441user.
29442
29443The @var{bkpt} argument is of the same form as returned by the various
d9f08f52
YQ
29444breakpoint commands; @xref{GDB/MI Breakpoint Commands}. The
29445@var{number} is the ordinal number of the breakpoint.
8d3788bd
VP
29446
29447Note that if a breakpoint is emitted in the result record of a
29448command, then it will not also be emitted in an async record.
29449
38b022b4 29450@item =record-started,thread-group="@var{id}",method="@var{method}"[,format="@var{format}"]
82a90ccf
YQ
29451@itemx =record-stopped,thread-group="@var{id}"
29452Execution log recording was either started or stopped on an
29453inferior. The @var{id} is the @value{GDBN} identifier of the thread
29454group corresponding to the affected inferior.
29455
38b022b4
SM
29456The @var{method} field indicates the method used to record execution. If the
29457method in use supports multiple recording formats, @var{format} will be present
8504e097 29458and contain the currently used format. @xref{Process Record and Replay},
38b022b4
SM
29459for existing method and format values.
29460
5b9afe8a
YQ
29461@item =cmd-param-changed,param=@var{param},value=@var{value}
29462Reports that a parameter of the command @code{set @var{param}} is
29463changed to @var{value}. In the multi-word @code{set} command,
29464the @var{param} is the whole parameter list to @code{set} command.
29465For example, In command @code{set check type on}, @var{param}
29466is @code{check type} and @var{value} is @code{on}.
8de0566d
YQ
29467
29468@item =memory-changed,thread-group=@var{id},addr=@var{addr},len=@var{len}[,type="code"]
29469Reports that bytes from @var{addr} to @var{data} + @var{len} were
29470written in an inferior. The @var{id} is the identifier of the
29471thread group corresponding to the affected inferior. The optional
29472@code{type="code"} part is reported if the memory written to holds
29473executable code.
82f68b1c
VP
29474@end table
29475
54516a0b
TT
29476@node GDB/MI Breakpoint Information
29477@subsection @sc{gdb/mi} Breakpoint Information
29478
29479When @value{GDBN} reports information about a breakpoint, a
29480tracepoint, a watchpoint, or a catchpoint, it uses a tuple with the
29481following fields:
29482
29483@table @code
29484@item number
b4be1b06 29485The breakpoint number.
54516a0b
TT
29486
29487@item type
29488The type of the breakpoint. For ordinary breakpoints this will be
29489@samp{breakpoint}, but many values are possible.
29490
8ac3646f
TT
29491@item catch-type
29492If the type of the breakpoint is @samp{catchpoint}, then this
29493indicates the exact type of catchpoint.
29494
54516a0b
TT
29495@item disp
29496This is the breakpoint disposition---either @samp{del}, meaning that
29497the breakpoint will be deleted at the next stop, or @samp{keep},
29498meaning that the breakpoint will not be deleted.
29499
29500@item enabled
29501This indicates whether the breakpoint is enabled, in which case the
29502value is @samp{y}, or disabled, in which case the value is @samp{n}.
29503Note that this is not the same as the field @code{enable}.
29504
29505@item addr
29506The address of the breakpoint. This may be a hexidecimal number,
29507giving the address; or the string @samp{<PENDING>}, for a pending
29508breakpoint; or the string @samp{<MULTIPLE>}, for a breakpoint with
29509multiple locations. This field will not be present if no address can
29510be determined. For example, a watchpoint does not have an address.
29511
aa7ca1bb
AH
29512@item addr_flags
29513Optional field containing any flags related to the address. These flags are
29514architecture-dependent; see @ref{Architectures} for their meaning for a
29515particular CPU.
29516
54516a0b
TT
29517@item func
29518If known, the function in which the breakpoint appears.
29519If not known, this field is not present.
29520
29521@item filename
29522The name of the source file which contains this function, if known.
29523If not known, this field is not present.
29524
29525@item fullname
29526The full file name of the source file which contains this function, if
29527known. If not known, this field is not present.
29528
29529@item line
29530The line number at which this breakpoint appears, if known.
29531If not known, this field is not present.
29532
29533@item at
29534If the source file is not known, this field may be provided. If
29535provided, this holds the address of the breakpoint, possibly followed
29536by a symbol name.
29537
29538@item pending
29539If this breakpoint is pending, this field is present and holds the
29540text used to set the breakpoint, as entered by the user.
29541
29542@item evaluated-by
29543Where this breakpoint's condition is evaluated, either @samp{host} or
29544@samp{target}.
29545
29546@item thread
29547If this is a thread-specific breakpoint, then this identifies the
29548thread in which the breakpoint can trigger.
29549
29550@item task
29551If this breakpoint is restricted to a particular Ada task, then this
29552field will hold the task identifier.
29553
29554@item cond
29555If the breakpoint is conditional, this is the condition expression.
29556
29557@item ignore
29558The ignore count of the breakpoint.
29559
29560@item enable
29561The enable count of the breakpoint.
29562
29563@item traceframe-usage
29564FIXME.
29565
29566@item static-tracepoint-marker-string-id
29567For a static tracepoint, the name of the static tracepoint marker.
29568
29569@item mask
29570For a masked watchpoint, this is the mask.
29571
29572@item pass
29573A tracepoint's pass count.
29574
29575@item original-location
29576The location of the breakpoint as originally specified by the user.
29577This field is optional.
29578
29579@item times
29580The number of times the breakpoint has been hit.
29581
29582@item installed
29583This field is only given for tracepoints. This is either @samp{y},
29584meaning that the tracepoint is installed, or @samp{n}, meaning that it
29585is not.
29586
29587@item what
29588Some extra data, the exact contents of which are type-dependent.
29589
b4be1b06
SM
29590@item locations
29591This field is present if the breakpoint has multiple locations. It is also
29592exceptionally present if the breakpoint is enabled and has a single, disabled
29593location.
29594
6b92c0d3 29595The value is a list of locations. The format of a location is described below.
b4be1b06
SM
29596
29597@end table
29598
29599A location in a multi-location breakpoint is represented as a tuple with the
29600following fields:
29601
29602@table @code
29603
29604@item number
29605The location number as a dotted pair, like @samp{1.2}. The first digit is the
29606number of the parent breakpoint. The second digit is the number of the
29607location within that breakpoint.
29608
29609@item enabled
29610This indicates whether the location is enabled, in which case the
29611value is @samp{y}, or disabled, in which case the value is @samp{n}.
29612Note that this is not the same as the field @code{enable}.
29613
29614@item addr
29615The address of this location as an hexidecimal number.
29616
aa7ca1bb
AH
29617@item addr_flags
29618Optional field containing any flags related to the address. These flags are
29619architecture-dependent; see @ref{Architectures} for their meaning for a
29620particular CPU.
29621
b4be1b06
SM
29622@item func
29623If known, the function in which the location appears.
29624If not known, this field is not present.
29625
29626@item file
29627The name of the source file which contains this location, if known.
29628If not known, this field is not present.
29629
29630@item fullname
29631The full file name of the source file which contains this location, if
29632known. If not known, this field is not present.
29633
29634@item line
29635The line number at which this location appears, if known.
29636If not known, this field is not present.
29637
29638@item thread-groups
29639The thread groups this location is in.
29640
54516a0b
TT
29641@end table
29642
29643For example, here is what the output of @code{-break-insert}
29644(@pxref{GDB/MI Breakpoint Commands}) might be:
29645
29646@smallexample
29647-> -break-insert main
29648<- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
29649 enabled="y",addr="0x08048564",func="main",file="myprog.c",
998580f1
MK
29650 fullname="/home/nickrob/myprog.c",line="68",thread-groups=["i1"],
29651 times="0"@}
54516a0b
TT
29652<- (gdb)
29653@end smallexample
29654
c3b108f7
VP
29655@node GDB/MI Frame Information
29656@subsection @sc{gdb/mi} Frame Information
29657
29658Response from many MI commands includes an information about stack
29659frame. This information is a tuple that may have the following
29660fields:
29661
29662@table @code
29663@item level
29664The level of the stack frame. The innermost frame has the level of
29665zero. This field is always present.
29666
29667@item func
29668The name of the function corresponding to the frame. This field may
29669be absent if @value{GDBN} is unable to determine the function name.
29670
29671@item addr
29672The code address for the frame. This field is always present.
29673
aa7ca1bb
AH
29674@item addr_flags
29675Optional field containing any flags related to the address. These flags are
29676architecture-dependent; see @ref{Architectures} for their meaning for a
29677particular CPU.
29678
c3b108f7
VP
29679@item file
29680The name of the source files that correspond to the frame's code
29681address. This field may be absent.
29682
29683@item line
29684The source line corresponding to the frames' code address. This field
29685may be absent.
29686
29687@item from
29688The name of the binary file (either executable or shared library) the
29689corresponds to the frame's code address. This field may be absent.
29690
29691@end table
82f68b1c 29692
dc146f7c
VP
29693@node GDB/MI Thread Information
29694@subsection @sc{gdb/mi} Thread Information
29695
29696Whenever @value{GDBN} has to report an information about a thread, it
ebe553db
SM
29697uses a tuple with the following fields. The fields are always present unless
29698stated otherwise.
dc146f7c
VP
29699
29700@table @code
29701@item id
ebe553db 29702The global numeric id assigned to the thread by @value{GDBN}.
dc146f7c
VP
29703
29704@item target-id
ebe553db 29705The target-specific string identifying the thread.
dc146f7c
VP
29706
29707@item details
29708Additional information about the thread provided by the target.
29709It is supposed to be human-readable and not interpreted by the
29710frontend. This field is optional.
29711
ebe553db
SM
29712@item name
29713The name of the thread. If the user specified a name using the
29714@code{thread name} command, then this name is given. Otherwise, if
29715@value{GDBN} can extract the thread name from the target, then that
29716name is given. If @value{GDBN} cannot find the thread name, then this
29717field is omitted.
29718
dc146f7c 29719@item state
ebe553db
SM
29720The execution state of the thread, either @samp{stopped} or @samp{running},
29721depending on whether the thread is presently running.
29722
29723@item frame
29724The stack frame currently executing in the thread. This field is only present
29725if the thread is stopped. Its format is documented in
29726@ref{GDB/MI Frame Information}.
dc146f7c
VP
29727
29728@item core
29729The value of this field is an integer number of the processor core the
29730thread was last seen on. This field is optional.
29731@end table
29732
956a9fb9
JB
29733@node GDB/MI Ada Exception Information
29734@subsection @sc{gdb/mi} Ada Exception Information
29735
29736Whenever a @code{*stopped} record is emitted because the program
29737stopped after hitting an exception catchpoint (@pxref{Set Catchpoints}),
29738@value{GDBN} provides the name of the exception that was raised via
e547c119
JB
29739the @code{exception-name} field. Also, for exceptions that were raised
29740with an exception message, @value{GDBN} provides that message via
29741the @code{exception-message} field.
922fbb7b 29742
ef21caaf
NR
29743@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29744@node GDB/MI Simple Examples
29745@section Simple Examples of @sc{gdb/mi} Interaction
29746@cindex @sc{gdb/mi}, simple examples
29747
29748This subsection presents several simple examples of interaction using
29749the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
29750following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
29751the output received from @sc{gdb/mi}.
29752
d3e8051b 29753Note the line breaks shown in the examples are here only for
ef21caaf
NR
29754readability, they don't appear in the real output.
29755
79a6e687 29756@subheading Setting a Breakpoint
ef21caaf
NR
29757
29758Setting a breakpoint generates synchronous output which contains detailed
29759information of the breakpoint.
29760
29761@smallexample
29762-> -break-insert main
29763<- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
29764 enabled="y",addr="0x08048564",func="main",file="myprog.c",
998580f1
MK
29765 fullname="/home/nickrob/myprog.c",line="68",thread-groups=["i1"],
29766 times="0"@}
ef21caaf
NR
29767<- (gdb)
29768@end smallexample
29769
29770@subheading Program Execution
29771
29772Program execution generates asynchronous records and MI gives the
29773reason that execution stopped.
29774
29775@smallexample
29776-> -exec-run
29777<- ^running
29778<- (gdb)
a47ec5fe 29779<- *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
ef21caaf
NR
29780 frame=@{addr="0x08048564",func="main",
29781 args=[@{name="argc",value="1"@},@{name="argv",value="0xbfc4d4d4"@}],
6d52907e
JV
29782 file="myprog.c",fullname="/home/nickrob/myprog.c",line="68",
29783 arch="i386:x86_64"@}
ef21caaf
NR
29784<- (gdb)
29785-> -exec-continue
29786<- ^running
29787<- (gdb)
29788<- *stopped,reason="exited-normally"
29789<- (gdb)
29790@end smallexample
29791
3f94c067 29792@subheading Quitting @value{GDBN}
ef21caaf 29793
3f94c067 29794Quitting @value{GDBN} just prints the result class @samp{^exit}.
ef21caaf
NR
29795
29796@smallexample
29797-> (gdb)
29798<- -gdb-exit
29799<- ^exit
29800@end smallexample
29801
a6b29f87
VP
29802Please note that @samp{^exit} is printed immediately, but it might
29803take some time for @value{GDBN} to actually exit. During that time, @value{GDBN}
29804performs necessary cleanups, including killing programs being debugged
29805or disconnecting from debug hardware, so the frontend should wait till
29806@value{GDBN} exits and should only forcibly kill @value{GDBN} if it
29807fails to exit in reasonable time.
29808
a2c02241 29809@subheading A Bad Command
ef21caaf
NR
29810
29811Here's what happens if you pass a non-existent command:
29812
29813@smallexample
29814-> -rubbish
29815<- ^error,msg="Undefined MI command: rubbish"
594fe323 29816<- (gdb)
ef21caaf
NR
29817@end smallexample
29818
29819
922fbb7b
AC
29820@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29821@node GDB/MI Command Description Format
29822@section @sc{gdb/mi} Command Description Format
29823
29824The remaining sections describe blocks of commands. Each block of
29825commands is laid out in a fashion similar to this section.
29826
922fbb7b
AC
29827@subheading Motivation
29828
29829The motivation for this collection of commands.
29830
29831@subheading Introduction
29832
29833A brief introduction to this collection of commands as a whole.
29834
29835@subheading Commands
29836
29837For each command in the block, the following is described:
29838
29839@subsubheading Synopsis
29840
29841@smallexample
29842 -command @var{args}@dots{}
29843@end smallexample
29844
922fbb7b
AC
29845@subsubheading Result
29846
265eeb58 29847@subsubheading @value{GDBN} Command
922fbb7b 29848
265eeb58 29849The corresponding @value{GDBN} CLI command(s), if any.
922fbb7b
AC
29850
29851@subsubheading Example
29852
ef21caaf
NR
29853Example(s) formatted for readability. Some of the described commands have
29854not been implemented yet and these are labeled N.A.@: (not available).
29855
29856
922fbb7b 29857@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ef21caaf
NR
29858@node GDB/MI Breakpoint Commands
29859@section @sc{gdb/mi} Breakpoint Commands
922fbb7b
AC
29860
29861@cindex breakpoint commands for @sc{gdb/mi}
29862@cindex @sc{gdb/mi}, breakpoint commands
29863This section documents @sc{gdb/mi} commands for manipulating
29864breakpoints.
29865
29866@subheading The @code{-break-after} Command
29867@findex -break-after
29868
29869@subsubheading Synopsis
29870
29871@smallexample
29872 -break-after @var{number} @var{count}
29873@end smallexample
29874
29875The breakpoint number @var{number} is not in effect until it has been
29876hit @var{count} times. To see how this is reflected in the output of
29877the @samp{-break-list} command, see the description of the
29878@samp{-break-list} command below.
29879
29880@subsubheading @value{GDBN} Command
29881
29882The corresponding @value{GDBN} command is @samp{ignore}.
29883
29884@subsubheading Example
29885
29886@smallexample
594fe323 29887(gdb)
922fbb7b 29888-break-insert main
a47ec5fe
AR
29889^done,bkpt=@{number="1",type="breakpoint",disp="keep",
29890enabled="y",addr="0x000100d0",func="main",file="hello.c",
998580f1
MK
29891fullname="/home/foo/hello.c",line="5",thread-groups=["i1"],
29892times="0"@}
594fe323 29893(gdb)
922fbb7b
AC
29894-break-after 1 3
29895~
29896^done
594fe323 29897(gdb)
922fbb7b
AC
29898-break-list
29899^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
29900hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
29901@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
29902@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
29903@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
29904@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
29905@{width="40",alignment="2",col_name="what",colhdr="What"@}],
29906body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102 29907addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
998580f1 29908line="5",thread-groups=["i1"],times="0",ignore="3"@}]@}
594fe323 29909(gdb)
922fbb7b
AC
29910@end smallexample
29911
29912@ignore
29913@subheading The @code{-break-catch} Command
29914@findex -break-catch
48cb2d85 29915@end ignore
922fbb7b
AC
29916
29917@subheading The @code{-break-commands} Command
29918@findex -break-commands
922fbb7b 29919
48cb2d85
VP
29920@subsubheading Synopsis
29921
29922@smallexample
29923 -break-commands @var{number} [ @var{command1} ... @var{commandN} ]
29924@end smallexample
29925
29926Specifies the CLI commands that should be executed when breakpoint
29927@var{number} is hit. The parameters @var{command1} to @var{commandN}
29928are the commands. If no command is specified, any previously-set
29929commands are cleared. @xref{Break Commands}. Typical use of this
29930functionality is tracing a program, that is, printing of values of
29931some variables whenever breakpoint is hit and then continuing.
29932
29933@subsubheading @value{GDBN} Command
29934
29935The corresponding @value{GDBN} command is @samp{commands}.
29936
29937@subsubheading Example
29938
29939@smallexample
29940(gdb)
29941-break-insert main
29942^done,bkpt=@{number="1",type="breakpoint",disp="keep",
29943enabled="y",addr="0x000100d0",func="main",file="hello.c",
998580f1
MK
29944fullname="/home/foo/hello.c",line="5",thread-groups=["i1"],
29945times="0"@}
48cb2d85
VP
29946(gdb)
29947-break-commands 1 "print v" "continue"
29948^done
29949(gdb)
29950@end smallexample
922fbb7b
AC
29951
29952@subheading The @code{-break-condition} Command
29953@findex -break-condition
29954
29955@subsubheading Synopsis
29956
29957@smallexample
29958 -break-condition @var{number} @var{expr}
29959@end smallexample
29960
29961Breakpoint @var{number} will stop the program only if the condition in
29962@var{expr} is true. The condition becomes part of the
29963@samp{-break-list} output (see the description of the @samp{-break-list}
29964command below).
29965
29966@subsubheading @value{GDBN} Command
29967
29968The corresponding @value{GDBN} command is @samp{condition}.
29969
29970@subsubheading Example
29971
29972@smallexample
594fe323 29973(gdb)
922fbb7b
AC
29974-break-condition 1 1
29975^done
594fe323 29976(gdb)
922fbb7b
AC
29977-break-list
29978^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
29979hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
29980@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
29981@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
29982@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
29983@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
29984@{width="40",alignment="2",col_name="what",colhdr="What"@}],
29985body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102 29986addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
998580f1 29987line="5",cond="1",thread-groups=["i1"],times="0",ignore="3"@}]@}
594fe323 29988(gdb)
922fbb7b
AC
29989@end smallexample
29990
29991@subheading The @code{-break-delete} Command
29992@findex -break-delete
29993
29994@subsubheading Synopsis
29995
29996@smallexample
29997 -break-delete ( @var{breakpoint} )+
29998@end smallexample
29999
30000Delete the breakpoint(s) whose number(s) are specified in the argument
30001list. This is obviously reflected in the breakpoint list.
30002
79a6e687 30003@subsubheading @value{GDBN} Command
922fbb7b
AC
30004
30005The corresponding @value{GDBN} command is @samp{delete}.
30006
30007@subsubheading Example
30008
30009@smallexample
594fe323 30010(gdb)
922fbb7b
AC
30011-break-delete 1
30012^done
594fe323 30013(gdb)
922fbb7b
AC
30014-break-list
30015^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
30016hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30017@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30018@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30019@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30020@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30021@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30022body=[]@}
594fe323 30023(gdb)
922fbb7b
AC
30024@end smallexample
30025
30026@subheading The @code{-break-disable} Command
30027@findex -break-disable
30028
30029@subsubheading Synopsis
30030
30031@smallexample
30032 -break-disable ( @var{breakpoint} )+
30033@end smallexample
30034
30035Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
30036break list is now set to @samp{n} for the named @var{breakpoint}(s).
30037
30038@subsubheading @value{GDBN} Command
30039
30040The corresponding @value{GDBN} command is @samp{disable}.
30041
30042@subsubheading Example
30043
30044@smallexample
594fe323 30045(gdb)
922fbb7b
AC
30046-break-disable 2
30047^done
594fe323 30048(gdb)
922fbb7b
AC
30049-break-list
30050^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
30051hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30052@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30053@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30054@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30055@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30056@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30057body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
948d5102 30058addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
998580f1 30059line="5",thread-groups=["i1"],times="0"@}]@}
594fe323 30060(gdb)
922fbb7b
AC
30061@end smallexample
30062
30063@subheading The @code{-break-enable} Command
30064@findex -break-enable
30065
30066@subsubheading Synopsis
30067
30068@smallexample
30069 -break-enable ( @var{breakpoint} )+
30070@end smallexample
30071
30072Enable (previously disabled) @var{breakpoint}(s).
30073
30074@subsubheading @value{GDBN} Command
30075
30076The corresponding @value{GDBN} command is @samp{enable}.
30077
30078@subsubheading Example
30079
30080@smallexample
594fe323 30081(gdb)
922fbb7b
AC
30082-break-enable 2
30083^done
594fe323 30084(gdb)
922fbb7b
AC
30085-break-list
30086^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
30087hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30088@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30089@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30090@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30091@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30092@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30093body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
948d5102 30094addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
998580f1 30095line="5",thread-groups=["i1"],times="0"@}]@}
594fe323 30096(gdb)
922fbb7b
AC
30097@end smallexample
30098
30099@subheading The @code{-break-info} Command
30100@findex -break-info
30101
30102@subsubheading Synopsis
30103
30104@smallexample
30105 -break-info @var{breakpoint}
30106@end smallexample
30107
30108@c REDUNDANT???
30109Get information about a single breakpoint.
30110
54516a0b
TT
30111The result is a table of breakpoints. @xref{GDB/MI Breakpoint
30112Information}, for details on the format of each breakpoint in the
30113table.
30114
79a6e687 30115@subsubheading @value{GDBN} Command
922fbb7b
AC
30116
30117The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
30118
30119@subsubheading Example
30120N.A.
30121
30122@subheading The @code{-break-insert} Command
30123@findex -break-insert
629500fa 30124@anchor{-break-insert}
922fbb7b
AC
30125
30126@subsubheading Synopsis
30127
30128@smallexample
18148017 30129 -break-insert [ -t ] [ -h ] [ -f ] [ -d ] [ -a ]
922fbb7b 30130 [ -c @var{condition} ] [ -i @var{ignore-count} ]
472a2379 30131 [ -p @var{thread-id} ] [ @var{location} ]
922fbb7b
AC
30132@end smallexample
30133
30134@noindent
afe8ab22 30135If specified, @var{location}, can be one of:
922fbb7b 30136
629500fa
KS
30137@table @var
30138@item linespec location
30139A linespec location. @xref{Linespec Locations}.
30140
30141@item explicit location
30142An explicit location. @sc{gdb/mi} explicit locations are
30143analogous to the CLI's explicit locations using the option names
30144listed below. @xref{Explicit Locations}.
30145
30146@table @samp
30147@item --source @var{filename}
30148The source file name of the location. This option requires the use
30149of either @samp{--function} or @samp{--line}.
30150
30151@item --function @var{function}
30152The name of a function or method.
922fbb7b 30153
629500fa
KS
30154@item --label @var{label}
30155The name of a label.
30156
30157@item --line @var{lineoffset}
30158An absolute or relative line offset from the start of the location.
30159@end table
30160
30161@item address location
30162An address location, *@var{address}. @xref{Address Locations}.
30163@end table
30164
30165@noindent
922fbb7b
AC
30166The possible optional parameters of this command are:
30167
30168@table @samp
30169@item -t
948d5102 30170Insert a temporary breakpoint.
922fbb7b
AC
30171@item -h
30172Insert a hardware breakpoint.
afe8ab22
VP
30173@item -f
30174If @var{location} cannot be parsed (for example if it
30175refers to unknown files or functions), create a pending
30176breakpoint. Without this flag, @value{GDBN} will report
30177an error, and won't create a breakpoint, if @var{location}
30178cannot be parsed.
41447f92
VP
30179@item -d
30180Create a disabled breakpoint.
18148017
VP
30181@item -a
30182Create a tracepoint. @xref{Tracepoints}. When this parameter
30183is used together with @samp{-h}, a fast tracepoint is created.
472a2379
KS
30184@item -c @var{condition}
30185Make the breakpoint conditional on @var{condition}.
30186@item -i @var{ignore-count}
30187Initialize the @var{ignore-count}.
30188@item -p @var{thread-id}
5d5658a1
PA
30189Restrict the breakpoint to the thread with the specified global
30190@var{thread-id}.
922fbb7b
AC
30191@end table
30192
30193@subsubheading Result
30194
54516a0b
TT
30195@xref{GDB/MI Breakpoint Information}, for details on the format of the
30196resulting breakpoint.
922fbb7b
AC
30197
30198Note: this format is open to change.
30199@c An out-of-band breakpoint instead of part of the result?
30200
30201@subsubheading @value{GDBN} Command
30202
30203The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
496ee73e 30204@samp{hbreak}, and @samp{thbreak}. @c and @samp{rbreak}.
922fbb7b
AC
30205
30206@subsubheading Example
30207
30208@smallexample
594fe323 30209(gdb)
922fbb7b 30210-break-insert main
948d5102 30211^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",
998580f1
MK
30212fullname="/home/foo/recursive2.c,line="4",thread-groups=["i1"],
30213times="0"@}
594fe323 30214(gdb)
922fbb7b 30215-break-insert -t foo
948d5102 30216^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",
998580f1
MK
30217fullname="/home/foo/recursive2.c,line="11",thread-groups=["i1"],
30218times="0"@}
594fe323 30219(gdb)
922fbb7b
AC
30220-break-list
30221^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30222hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30223@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30224@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30225@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30226@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30227@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30228body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102 30229addr="0x0001072c", func="main",file="recursive2.c",
998580f1
MK
30230fullname="/home/foo/recursive2.c,"line="4",thread-groups=["i1"],
30231times="0"@},
922fbb7b 30232bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
948d5102 30233addr="0x00010774",func="foo",file="recursive2.c",
998580f1
MK
30234fullname="/home/foo/recursive2.c",line="11",thread-groups=["i1"],
30235times="0"@}]@}
594fe323 30236(gdb)
496ee73e
KS
30237@c -break-insert -r foo.*
30238@c ~int foo(int, int);
30239@c ^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c,
998580f1
MK
30240@c "fullname="/home/foo/recursive2.c",line="11",thread-groups=["i1"],
30241@c times="0"@}
496ee73e 30242@c (gdb)
922fbb7b
AC
30243@end smallexample
30244
c5867ab6
HZ
30245@subheading The @code{-dprintf-insert} Command
30246@findex -dprintf-insert
30247
30248@subsubheading Synopsis
30249
30250@smallexample
30251 -dprintf-insert [ -t ] [ -f ] [ -d ]
30252 [ -c @var{condition} ] [ -i @var{ignore-count} ]
30253 [ -p @var{thread-id} ] [ @var{location} ] [ @var{format} ]
30254 [ @var{argument} ]
30255@end smallexample
30256
30257@noindent
629500fa
KS
30258If supplied, @var{location} may be specified the same way as for
30259the @code{-break-insert} command. @xref{-break-insert}.
c5867ab6
HZ
30260
30261The possible optional parameters of this command are:
30262
30263@table @samp
30264@item -t
30265Insert a temporary breakpoint.
30266@item -f
30267If @var{location} cannot be parsed (for example, if it
30268refers to unknown files or functions), create a pending
30269breakpoint. Without this flag, @value{GDBN} will report
30270an error, and won't create a breakpoint, if @var{location}
30271cannot be parsed.
30272@item -d
30273Create a disabled breakpoint.
30274@item -c @var{condition}
30275Make the breakpoint conditional on @var{condition}.
30276@item -i @var{ignore-count}
30277Set the ignore count of the breakpoint (@pxref{Conditions, ignore count})
30278to @var{ignore-count}.
30279@item -p @var{thread-id}
5d5658a1
PA
30280Restrict the breakpoint to the thread with the specified global
30281@var{thread-id}.
c5867ab6
HZ
30282@end table
30283
30284@subsubheading Result
30285
30286@xref{GDB/MI Breakpoint Information}, for details on the format of the
30287resulting breakpoint.
30288
30289@c An out-of-band breakpoint instead of part of the result?
30290
30291@subsubheading @value{GDBN} Command
30292
30293The corresponding @value{GDBN} command is @samp{dprintf}.
30294
30295@subsubheading Example
30296
30297@smallexample
30298(gdb)
302994-dprintf-insert foo "At foo entry\n"
303004^done,bkpt=@{number="1",type="dprintf",disp="keep",enabled="y",
30301addr="0x000000000040061b",func="foo",file="mi-dprintf.c",
30302fullname="mi-dprintf.c",line="25",thread-groups=["i1"],
30303times="0",script=@{"printf \"At foo entry\\n\"","continue"@},
30304original-location="foo"@}
30305(gdb)
303065-dprintf-insert 26 "arg=%d, g=%d\n" arg g
303075^done,bkpt=@{number="2",type="dprintf",disp="keep",enabled="y",
30308addr="0x000000000040062a",func="foo",file="mi-dprintf.c",
30309fullname="mi-dprintf.c",line="26",thread-groups=["i1"],
30310times="0",script=@{"printf \"arg=%d, g=%d\\n\", arg, g","continue"@},
30311original-location="mi-dprintf.c:26"@}
30312(gdb)
30313@end smallexample
30314
922fbb7b
AC
30315@subheading The @code{-break-list} Command
30316@findex -break-list
30317
30318@subsubheading Synopsis
30319
30320@smallexample
30321 -break-list
30322@end smallexample
30323
30324Displays the list of inserted breakpoints, showing the following fields:
30325
30326@table @samp
30327@item Number
30328number of the breakpoint
30329@item Type
30330type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
30331@item Disposition
30332should the breakpoint be deleted or disabled when it is hit: @samp{keep}
30333or @samp{nokeep}
30334@item Enabled
30335is the breakpoint enabled or no: @samp{y} or @samp{n}
30336@item Address
30337memory location at which the breakpoint is set
30338@item What
30339logical location of the breakpoint, expressed by function name, file
30340name, line number
998580f1
MK
30341@item Thread-groups
30342list of thread groups to which this breakpoint applies
922fbb7b
AC
30343@item Times
30344number of times the breakpoint has been hit
30345@end table
30346
30347If there are no breakpoints or watchpoints, the @code{BreakpointTable}
30348@code{body} field is an empty list.
30349
30350@subsubheading @value{GDBN} Command
30351
30352The corresponding @value{GDBN} command is @samp{info break}.
30353
30354@subsubheading Example
30355
30356@smallexample
594fe323 30357(gdb)
922fbb7b
AC
30358-break-list
30359^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30360hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30361@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30362@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30363@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30364@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30365@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30366body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
998580f1
MK
30367addr="0x000100d0",func="main",file="hello.c",line="5",thread-groups=["i1"],
30368times="0"@},
922fbb7b 30369bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
948d5102 30370addr="0x00010114",func="foo",file="hello.c",fullname="/home/foo/hello.c",
998580f1 30371line="13",thread-groups=["i1"],times="0"@}]@}
594fe323 30372(gdb)
922fbb7b
AC
30373@end smallexample
30374
30375Here's an example of the result when there are no breakpoints:
30376
30377@smallexample
594fe323 30378(gdb)
922fbb7b
AC
30379-break-list
30380^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
30381hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30382@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30383@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30384@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30385@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30386@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30387body=[]@}
594fe323 30388(gdb)
922fbb7b
AC
30389@end smallexample
30390
18148017
VP
30391@subheading The @code{-break-passcount} Command
30392@findex -break-passcount
30393
30394@subsubheading Synopsis
30395
30396@smallexample
30397 -break-passcount @var{tracepoint-number} @var{passcount}
30398@end smallexample
30399
30400Set the passcount for tracepoint @var{tracepoint-number} to
30401@var{passcount}. If the breakpoint referred to by @var{tracepoint-number}
30402is not a tracepoint, error is emitted. This corresponds to CLI
30403command @samp{passcount}.
30404
922fbb7b
AC
30405@subheading The @code{-break-watch} Command
30406@findex -break-watch
30407
30408@subsubheading Synopsis
30409
30410@smallexample
30411 -break-watch [ -a | -r ]
30412@end smallexample
30413
30414Create a watchpoint. With the @samp{-a} option it will create an
d3e8051b 30415@dfn{access} watchpoint, i.e., a watchpoint that triggers either on a
922fbb7b 30416read from or on a write to the memory location. With the @samp{-r}
d3e8051b 30417option, the watchpoint created is a @dfn{read} watchpoint, i.e., it will
922fbb7b
AC
30418trigger only when the memory location is accessed for reading. Without
30419either of the options, the watchpoint created is a regular watchpoint,
d3e8051b 30420i.e., it will trigger when the memory location is accessed for writing.
79a6e687 30421@xref{Set Watchpoints, , Setting Watchpoints}.
922fbb7b
AC
30422
30423Note that @samp{-break-list} will report a single list of watchpoints and
30424breakpoints inserted.
30425
30426@subsubheading @value{GDBN} Command
30427
30428The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
30429@samp{rwatch}.
30430
30431@subsubheading Example
30432
30433Setting a watchpoint on a variable in the @code{main} function:
30434
30435@smallexample
594fe323 30436(gdb)
922fbb7b
AC
30437-break-watch x
30438^done,wpt=@{number="2",exp="x"@}
594fe323 30439(gdb)
922fbb7b
AC
30440-exec-continue
30441^running
0869d01b
NR
30442(gdb)
30443*stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
922fbb7b 30444value=@{old="-268439212",new="55"@},
76ff342d 30445frame=@{func="main",args=[],file="recursive2.c",
6d52907e 30446fullname="/home/foo/bar/recursive2.c",line="5",arch="i386:x86_64"@}
594fe323 30447(gdb)
922fbb7b
AC
30448@end smallexample
30449
30450Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
30451the program execution twice: first for the variable changing value, then
30452for the watchpoint going out of scope.
30453
30454@smallexample
594fe323 30455(gdb)
922fbb7b
AC
30456-break-watch C
30457^done,wpt=@{number="5",exp="C"@}
594fe323 30458(gdb)
922fbb7b
AC
30459-exec-continue
30460^running
0869d01b
NR
30461(gdb)
30462*stopped,reason="watchpoint-trigger",
922fbb7b
AC
30463wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
30464frame=@{func="callee4",args=[],
76ff342d 30465file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
30466fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13",
30467arch="i386:x86_64"@}
594fe323 30468(gdb)
922fbb7b
AC
30469-exec-continue
30470^running
0869d01b
NR
30471(gdb)
30472*stopped,reason="watchpoint-scope",wpnum="5",
922fbb7b
AC
30473frame=@{func="callee3",args=[@{name="strarg",
30474value="0x11940 \"A string argument.\""@}],
76ff342d 30475file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
30476fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
30477arch="i386:x86_64"@}
594fe323 30478(gdb)
922fbb7b
AC
30479@end smallexample
30480
30481Listing breakpoints and watchpoints, at different points in the program
30482execution. Note that once the watchpoint goes out of scope, it is
30483deleted.
30484
30485@smallexample
594fe323 30486(gdb)
922fbb7b
AC
30487-break-watch C
30488^done,wpt=@{number="2",exp="C"@}
594fe323 30489(gdb)
922fbb7b
AC
30490-break-list
30491^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30492hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30493@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30494@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30495@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30496@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30497@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30498body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30499addr="0x00010734",func="callee4",
948d5102 30500file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
998580f1
MK
30501fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c"line="8",thread-groups=["i1"],
30502times="1"@},
922fbb7b 30503bkpt=@{number="2",type="watchpoint",disp="keep",
998580f1 30504enabled="y",addr="",what="C",thread-groups=["i1"],times="0"@}]@}
594fe323 30505(gdb)
922fbb7b
AC
30506-exec-continue
30507^running
0869d01b
NR
30508(gdb)
30509*stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
922fbb7b
AC
30510value=@{old="-276895068",new="3"@},
30511frame=@{func="callee4",args=[],
76ff342d 30512file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
30513fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13",
30514arch="i386:x86_64"@}
594fe323 30515(gdb)
922fbb7b
AC
30516-break-list
30517^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30518hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30519@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30520@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30521@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30522@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30523@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30524body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30525addr="0x00010734",func="callee4",
948d5102 30526file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
998580f1
MK
30527fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",thread-groups=["i1"],
30528times="1"@},
922fbb7b 30529bkpt=@{number="2",type="watchpoint",disp="keep",
998580f1 30530enabled="y",addr="",what="C",thread-groups=["i1"],times="-5"@}]@}
594fe323 30531(gdb)
922fbb7b
AC
30532-exec-continue
30533^running
30534^done,reason="watchpoint-scope",wpnum="2",
30535frame=@{func="callee3",args=[@{name="strarg",
30536value="0x11940 \"A string argument.\""@}],
76ff342d 30537file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
30538fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
30539arch="i386:x86_64"@}
594fe323 30540(gdb)
922fbb7b
AC
30541-break-list
30542^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
30543hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30544@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30545@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30546@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30547@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30548@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30549body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30550addr="0x00010734",func="callee4",
948d5102
NR
30551file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30552fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
998580f1 30553thread-groups=["i1"],times="1"@}]@}
594fe323 30554(gdb)
922fbb7b
AC
30555@end smallexample
30556
3fa7bf06
MG
30557
30558@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30559@node GDB/MI Catchpoint Commands
30560@section @sc{gdb/mi} Catchpoint Commands
30561
30562This section documents @sc{gdb/mi} commands for manipulating
30563catchpoints.
30564
40555925
JB
30565@menu
30566* Shared Library GDB/MI Catchpoint Commands::
30567* Ada Exception GDB/MI Catchpoint Commands::
30056ea0 30568* C++ Exception GDB/MI Catchpoint Commands::
40555925
JB
30569@end menu
30570
30571@node Shared Library GDB/MI Catchpoint Commands
30572@subsection Shared Library @sc{gdb/mi} Catchpoints
30573
3fa7bf06
MG
30574@subheading The @code{-catch-load} Command
30575@findex -catch-load
30576
30577@subsubheading Synopsis
30578
30579@smallexample
30580 -catch-load [ -t ] [ -d ] @var{regexp}
30581@end smallexample
30582
30583Add a catchpoint for library load events. If the @samp{-t} option is used,
30584the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
30585Breakpoints}). If the @samp{-d} option is used, the catchpoint is created
30586in a disabled state. The @samp{regexp} argument is a regular
30587expression used to match the name of the loaded library.
30588
30589
30590@subsubheading @value{GDBN} Command
30591
30592The corresponding @value{GDBN} command is @samp{catch load}.
30593
30594@subsubheading Example
30595
30596@smallexample
30597-catch-load -t foo.so
30598^done,bkpt=@{number="1",type="catchpoint",disp="del",enabled="y",
8ac3646f 30599what="load of library matching foo.so",catch-type="load",times="0"@}
3fa7bf06
MG
30600(gdb)
30601@end smallexample
30602
30603
30604@subheading The @code{-catch-unload} Command
30605@findex -catch-unload
30606
30607@subsubheading Synopsis
30608
30609@smallexample
30610 -catch-unload [ -t ] [ -d ] @var{regexp}
30611@end smallexample
30612
30613Add a catchpoint for library unload events. If the @samp{-t} option is
30614used, the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
30615Breakpoints}). If the @samp{-d} option is used, the catchpoint is
30616created in a disabled state. The @samp{regexp} argument is a regular
30617expression used to match the name of the unloaded library.
30618
30619@subsubheading @value{GDBN} Command
30620
30621The corresponding @value{GDBN} command is @samp{catch unload}.
30622
30623@subsubheading Example
30624
30625@smallexample
30626-catch-unload -d bar.so
30627^done,bkpt=@{number="2",type="catchpoint",disp="keep",enabled="n",
8ac3646f 30628what="load of library matching bar.so",catch-type="unload",times="0"@}
3fa7bf06
MG
30629(gdb)
30630@end smallexample
30631
40555925
JB
30632@node Ada Exception GDB/MI Catchpoint Commands
30633@subsection Ada Exception @sc{gdb/mi} Catchpoints
30634
30635The following @sc{gdb/mi} commands can be used to create catchpoints
30636that stop the execution when Ada exceptions are being raised.
30637
30638@subheading The @code{-catch-assert} Command
30639@findex -catch-assert
30640
30641@subsubheading Synopsis
30642
30643@smallexample
30644 -catch-assert [ -c @var{condition}] [ -d ] [ -t ]
30645@end smallexample
30646
30647Add a catchpoint for failed Ada assertions.
30648
30649The possible optional parameters for this command are:
30650
30651@table @samp
30652@item -c @var{condition}
30653Make the catchpoint conditional on @var{condition}.
30654@item -d
30655Create a disabled catchpoint.
30656@item -t
30657Create a temporary catchpoint.
30658@end table
30659
30660@subsubheading @value{GDBN} Command
30661
30662The corresponding @value{GDBN} command is @samp{catch assert}.
30663
30664@subsubheading Example
30665
30666@smallexample
30667-catch-assert
30668^done,bkptno="5",bkpt=@{number="5",type="breakpoint",disp="keep",
30669enabled="y",addr="0x0000000000404888",what="failed Ada assertions",
30670thread-groups=["i1"],times="0",
30671original-location="__gnat_debug_raise_assert_failure"@}
30672(gdb)
30673@end smallexample
30674
30675@subheading The @code{-catch-exception} Command
30676@findex -catch-exception
30677
30678@subsubheading Synopsis
30679
30680@smallexample
30681 -catch-exception [ -c @var{condition}] [ -d ] [ -e @var{exception-name} ]
30682 [ -t ] [ -u ]
30683@end smallexample
30684
30685Add a catchpoint stopping when Ada exceptions are raised.
30686By default, the command stops the program when any Ada exception
30687gets raised. But it is also possible, by using some of the
30688optional parameters described below, to create more selective
30689catchpoints.
30690
30691The possible optional parameters for this command are:
30692
30693@table @samp
30694@item -c @var{condition}
30695Make the catchpoint conditional on @var{condition}.
30696@item -d
30697Create a disabled catchpoint.
30698@item -e @var{exception-name}
30699Only stop when @var{exception-name} is raised. This option cannot
30700be used combined with @samp{-u}.
30701@item -t
30702Create a temporary catchpoint.
30703@item -u
30704Stop only when an unhandled exception gets raised. This option
30705cannot be used combined with @samp{-e}.
30706@end table
30707
30708@subsubheading @value{GDBN} Command
30709
30710The corresponding @value{GDBN} commands are @samp{catch exception}
30711and @samp{catch exception unhandled}.
30712
30713@subsubheading Example
30714
30715@smallexample
30716-catch-exception -e Program_Error
30717^done,bkptno="4",bkpt=@{number="4",type="breakpoint",disp="keep",
30718enabled="y",addr="0x0000000000404874",
30719what="`Program_Error' Ada exception", thread-groups=["i1"],
30720times="0",original-location="__gnat_debug_raise_exception"@}
30721(gdb)
30722@end smallexample
3fa7bf06 30723
bea298f9
XR
30724@subheading The @code{-catch-handlers} Command
30725@findex -catch-handlers
30726
30727@subsubheading Synopsis
30728
30729@smallexample
30730 -catch-handlers [ -c @var{condition}] [ -d ] [ -e @var{exception-name} ]
30731 [ -t ]
30732@end smallexample
30733
30734Add a catchpoint stopping when Ada exceptions are handled.
30735By default, the command stops the program when any Ada exception
30736gets handled. But it is also possible, by using some of the
30737optional parameters described below, to create more selective
30738catchpoints.
30739
30740The possible optional parameters for this command are:
30741
30742@table @samp
30743@item -c @var{condition}
30744Make the catchpoint conditional on @var{condition}.
30745@item -d
30746Create a disabled catchpoint.
30747@item -e @var{exception-name}
30748Only stop when @var{exception-name} is handled.
30749@item -t
30750Create a temporary catchpoint.
30751@end table
30752
30753@subsubheading @value{GDBN} Command
30754
30755The corresponding @value{GDBN} command is @samp{catch handlers}.
30756
30757@subsubheading Example
30758
30759@smallexample
30760-catch-handlers -e Constraint_Error
30761^done,bkptno="4",bkpt=@{number="4",type="breakpoint",disp="keep",
30762enabled="y",addr="0x0000000000402f68",
30763what="`Constraint_Error' Ada exception handlers",thread-groups=["i1"],
30764times="0",original-location="__gnat_begin_handler"@}
30765(gdb)
30766@end smallexample
30767
30056ea0
AB
30768@node C++ Exception GDB/MI Catchpoint Commands
30769@subsection C@t{++} Exception @sc{gdb/mi} Catchpoints
30770
30771The following @sc{gdb/mi} commands can be used to create catchpoints
30772that stop the execution when C@t{++} exceptions are being throw, rethrown,
30773or caught.
30774
30775@subheading The @code{-catch-throw} Command
30776@findex -catch-throw
30777
30778@subsubheading Synopsis
30779
30780@smallexample
30781 -catch-throw [ -t ] [ -r @var{regexp}]
30782@end smallexample
30783
30784Stop when the debuggee throws a C@t{++} exception. If @var{regexp} is
30785given, then only exceptions whose type matches the regular expression
30786will be caught.
30787
30788If @samp{-t} is given, then the catchpoint is enabled only for one
30789stop, the catchpoint is automatically deleted after stopping once for
30790the event.
30791
30792@subsubheading @value{GDBN} Command
30793
30794The corresponding @value{GDBN} commands are @samp{catch throw}
30795and @samp{tcatch throw} (@pxref{Set Catchpoints}).
30796
30797@subsubheading Example
30798
30799@smallexample
30800-catch-throw -r exception_type
cb1e4e32
PA
30801^done,bkpt=@{number="1",type="catchpoint",disp="keep",enabled="y",
30802 what="exception throw",catch-type="throw",
30803 thread-groups=["i1"],
30056ea0
AB
30804 regexp="exception_type",times="0"@}
30805(gdb)
30806-exec-run
30807^running
30808(gdb)
30809~"\n"
30810~"Catchpoint 1 (exception thrown), 0x00007ffff7ae00ed
30811 in __cxa_throw () from /lib64/libstdc++.so.6\n"
30812*stopped,bkptno="1",reason="breakpoint-hit",disp="keep",
30813 frame=@{addr="0x00007ffff7ae00ed",func="__cxa_throw",
30814 args=[],from="/lib64/libstdc++.so.6",arch="i386:x86-64"@},
30815 thread-id="1",stopped-threads="all",core="6"
30816(gdb)
30817@end smallexample
30818
30819@subheading The @code{-catch-rethrow} Command
30820@findex -catch-rethrow
30821
30822@subsubheading Synopsis
30823
30824@smallexample
30825 -catch-rethrow [ -t ] [ -r @var{regexp}]
30826@end smallexample
30827
30828Stop when a C@t{++} exception is re-thrown. If @var{regexp} is given,
30829then only exceptions whose type matches the regular expression will be
30830caught.
30831
30832If @samp{-t} is given, then the catchpoint is enabled only for one
30833stop, the catchpoint is automatically deleted after the first event is
30834caught.
30835
30836@subsubheading @value{GDBN} Command
30837
30838The corresponding @value{GDBN} commands are @samp{catch rethrow}
30839and @samp{tcatch rethrow} (@pxref{Set Catchpoints}).
30840
30841@subsubheading Example
30842
30843@smallexample
30844-catch-rethrow -r exception_type
cb1e4e32
PA
30845^done,bkpt=@{number="1",type="catchpoint",disp="keep",enabled="y",
30846 what="exception rethrow",catch-type="rethrow",
30847 thread-groups=["i1"],
30056ea0
AB
30848 regexp="exception_type",times="0"@}
30849(gdb)
30850-exec-run
30851^running
30852(gdb)
30853~"\n"
30854~"Catchpoint 1 (exception rethrown), 0x00007ffff7ae00ed
30855 in __cxa_rethrow () from /lib64/libstdc++.so.6\n"
30856*stopped,bkptno="1",reason="breakpoint-hit",disp="keep",
30857 frame=@{addr="0x00007ffff7ae00ed",func="__cxa_rethrow",
30858 args=[],from="/lib64/libstdc++.so.6",arch="i386:x86-64"@},
30859 thread-id="1",stopped-threads="all",core="6"
30860(gdb)
30861@end smallexample
30862
30863@subheading The @code{-catch-catch} Command
30864@findex -catch-catch
30865
30866@subsubheading Synopsis
30867
30868@smallexample
30869 -catch-catch [ -t ] [ -r @var{regexp}]
30870@end smallexample
30871
30872Stop when the debuggee catches a C@t{++} exception. If @var{regexp}
30873is given, then only exceptions whose type matches the regular
30874expression will be caught.
30875
30876If @samp{-t} is given, then the catchpoint is enabled only for one
30877stop, the catchpoint is automatically deleted after the first event is
30878caught.
30879
30880@subsubheading @value{GDBN} Command
30881
30882The corresponding @value{GDBN} commands are @samp{catch catch}
30883and @samp{tcatch catch} (@pxref{Set Catchpoints}).
30884
30885@subsubheading Example
30886
30887@smallexample
30888-catch-catch -r exception_type
cb1e4e32
PA
30889^done,bkpt=@{number="1",type="catchpoint",disp="keep",enabled="y",
30890 what="exception catch",catch-type="catch",
30891 thread-groups=["i1"],
30056ea0
AB
30892 regexp="exception_type",times="0"@}
30893(gdb)
30894-exec-run
30895^running
30896(gdb)
30897~"\n"
30898~"Catchpoint 1 (exception caught), 0x00007ffff7ae00ed
30899 in __cxa_begin_catch () from /lib64/libstdc++.so.6\n"
30900*stopped,bkptno="1",reason="breakpoint-hit",disp="keep",
30901 frame=@{addr="0x00007ffff7ae00ed",func="__cxa_begin_catch",
30902 args=[],from="/lib64/libstdc++.so.6",arch="i386:x86-64"@},
30903 thread-id="1",stopped-threads="all",core="6"
30904(gdb)
30905@end smallexample
30906
922fbb7b 30907@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
30908@node GDB/MI Program Context
30909@section @sc{gdb/mi} Program Context
922fbb7b 30910
a2c02241
NR
30911@subheading The @code{-exec-arguments} Command
30912@findex -exec-arguments
922fbb7b 30913
922fbb7b
AC
30914
30915@subsubheading Synopsis
30916
30917@smallexample
a2c02241 30918 -exec-arguments @var{args}
922fbb7b
AC
30919@end smallexample
30920
a2c02241
NR
30921Set the inferior program arguments, to be used in the next
30922@samp{-exec-run}.
922fbb7b 30923
a2c02241 30924@subsubheading @value{GDBN} Command
922fbb7b 30925
a2c02241 30926The corresponding @value{GDBN} command is @samp{set args}.
922fbb7b 30927
a2c02241 30928@subsubheading Example
922fbb7b 30929
fbc5282e
MK
30930@smallexample
30931(gdb)
30932-exec-arguments -v word
30933^done
30934(gdb)
30935@end smallexample
922fbb7b 30936
a2c02241 30937
9901a55b 30938@ignore
a2c02241
NR
30939@subheading The @code{-exec-show-arguments} Command
30940@findex -exec-show-arguments
30941
30942@subsubheading Synopsis
30943
30944@smallexample
30945 -exec-show-arguments
30946@end smallexample
30947
30948Print the arguments of the program.
922fbb7b
AC
30949
30950@subsubheading @value{GDBN} Command
30951
a2c02241 30952The corresponding @value{GDBN} command is @samp{show args}.
922fbb7b
AC
30953
30954@subsubheading Example
a2c02241 30955N.A.
9901a55b 30956@end ignore
922fbb7b 30957
922fbb7b 30958
a2c02241
NR
30959@subheading The @code{-environment-cd} Command
30960@findex -environment-cd
922fbb7b 30961
a2c02241 30962@subsubheading Synopsis
922fbb7b
AC
30963
30964@smallexample
a2c02241 30965 -environment-cd @var{pathdir}
922fbb7b
AC
30966@end smallexample
30967
a2c02241 30968Set @value{GDBN}'s working directory.
922fbb7b 30969
a2c02241 30970@subsubheading @value{GDBN} Command
922fbb7b 30971
a2c02241
NR
30972The corresponding @value{GDBN} command is @samp{cd}.
30973
30974@subsubheading Example
922fbb7b
AC
30975
30976@smallexample
594fe323 30977(gdb)
a2c02241
NR
30978-environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
30979^done
594fe323 30980(gdb)
922fbb7b
AC
30981@end smallexample
30982
30983
a2c02241
NR
30984@subheading The @code{-environment-directory} Command
30985@findex -environment-directory
922fbb7b
AC
30986
30987@subsubheading Synopsis
30988
30989@smallexample
a2c02241 30990 -environment-directory [ -r ] [ @var{pathdir} ]+
922fbb7b
AC
30991@end smallexample
30992
a2c02241
NR
30993Add directories @var{pathdir} to beginning of search path for source files.
30994If the @samp{-r} option is used, the search path is reset to the default
30995search path. If directories @var{pathdir} are supplied in addition to the
30996@samp{-r} option, the search path is first reset and then addition
30997occurs as normal.
30998Multiple directories may be specified, separated by blanks. Specifying
30999multiple directories in a single command
31000results in the directories added to the beginning of the
31001search path in the same order they were presented in the command.
31002If blanks are needed as
31003part of a directory name, double-quotes should be used around
31004the name. In the command output, the path will show up separated
d3e8051b 31005by the system directory-separator character. The directory-separator
a2c02241
NR
31006character must not be used
31007in any directory name.
31008If no directories are specified, the current search path is displayed.
922fbb7b
AC
31009
31010@subsubheading @value{GDBN} Command
31011
a2c02241 31012The corresponding @value{GDBN} command is @samp{dir}.
922fbb7b
AC
31013
31014@subsubheading Example
31015
922fbb7b 31016@smallexample
594fe323 31017(gdb)
a2c02241
NR
31018-environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
31019^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
594fe323 31020(gdb)
a2c02241
NR
31021-environment-directory ""
31022^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
594fe323 31023(gdb)
a2c02241
NR
31024-environment-directory -r /home/jjohnstn/src/gdb /usr/src
31025^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
594fe323 31026(gdb)
a2c02241
NR
31027-environment-directory -r
31028^done,source-path="$cdir:$cwd"
594fe323 31029(gdb)
922fbb7b
AC
31030@end smallexample
31031
31032
a2c02241
NR
31033@subheading The @code{-environment-path} Command
31034@findex -environment-path
922fbb7b
AC
31035
31036@subsubheading Synopsis
31037
31038@smallexample
a2c02241 31039 -environment-path [ -r ] [ @var{pathdir} ]+
922fbb7b
AC
31040@end smallexample
31041
a2c02241
NR
31042Add directories @var{pathdir} to beginning of search path for object files.
31043If the @samp{-r} option is used, the search path is reset to the original
31044search path that existed at gdb start-up. If directories @var{pathdir} are
31045supplied in addition to the
31046@samp{-r} option, the search path is first reset and then addition
31047occurs as normal.
31048Multiple directories may be specified, separated by blanks. Specifying
31049multiple directories in a single command
31050results in the directories added to the beginning of the
31051search path in the same order they were presented in the command.
31052If blanks are needed as
31053part of a directory name, double-quotes should be used around
31054the name. In the command output, the path will show up separated
d3e8051b 31055by the system directory-separator character. The directory-separator
a2c02241
NR
31056character must not be used
31057in any directory name.
31058If no directories are specified, the current path is displayed.
31059
922fbb7b
AC
31060
31061@subsubheading @value{GDBN} Command
31062
a2c02241 31063The corresponding @value{GDBN} command is @samp{path}.
922fbb7b
AC
31064
31065@subsubheading Example
31066
922fbb7b 31067@smallexample
594fe323 31068(gdb)
a2c02241
NR
31069-environment-path
31070^done,path="/usr/bin"
594fe323 31071(gdb)
a2c02241
NR
31072-environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
31073^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
594fe323 31074(gdb)
a2c02241
NR
31075-environment-path -r /usr/local/bin
31076^done,path="/usr/local/bin:/usr/bin"
594fe323 31077(gdb)
922fbb7b
AC
31078@end smallexample
31079
31080
a2c02241
NR
31081@subheading The @code{-environment-pwd} Command
31082@findex -environment-pwd
922fbb7b
AC
31083
31084@subsubheading Synopsis
31085
31086@smallexample
a2c02241 31087 -environment-pwd
922fbb7b
AC
31088@end smallexample
31089
a2c02241 31090Show the current working directory.
922fbb7b 31091
79a6e687 31092@subsubheading @value{GDBN} Command
922fbb7b 31093
a2c02241 31094The corresponding @value{GDBN} command is @samp{pwd}.
922fbb7b
AC
31095
31096@subsubheading Example
31097
922fbb7b 31098@smallexample
594fe323 31099(gdb)
a2c02241
NR
31100-environment-pwd
31101^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
594fe323 31102(gdb)
922fbb7b
AC
31103@end smallexample
31104
a2c02241
NR
31105@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31106@node GDB/MI Thread Commands
31107@section @sc{gdb/mi} Thread Commands
31108
31109
31110@subheading The @code{-thread-info} Command
31111@findex -thread-info
922fbb7b
AC
31112
31113@subsubheading Synopsis
31114
31115@smallexample
8e8901c5 31116 -thread-info [ @var{thread-id} ]
922fbb7b
AC
31117@end smallexample
31118
5d5658a1
PA
31119Reports information about either a specific thread, if the
31120@var{thread-id} parameter is present, or about all threads.
31121@var{thread-id} is the thread's global thread ID. When printing
31122information about all threads, also reports the global ID of the
31123current thread.
8e8901c5 31124
79a6e687 31125@subsubheading @value{GDBN} Command
922fbb7b 31126
8e8901c5
VP
31127The @samp{info thread} command prints the same information
31128about all threads.
922fbb7b 31129
4694da01 31130@subsubheading Result
922fbb7b 31131
ebe553db 31132The result contains the following attributes:
4694da01
TT
31133
31134@table @samp
ebe553db
SM
31135@item threads
31136A list of threads. The format of the elements of the list is described in
31137@ref{GDB/MI Thread Information}.
31138
31139@item current-thread-id
31140The global id of the currently selected thread. This field is omitted if there
31141is no selected thread (for example, when the selected inferior is not running,
31142and therefore has no threads) or if a @var{thread-id} argument was passed to
31143the command.
4694da01
TT
31144
31145@end table
31146
31147@subsubheading Example
31148
31149@smallexample
31150-thread-info
31151^done,threads=[
31152@{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
31153 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",
31154 args=[]@},state="running"@},
31155@{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
31156 frame=@{level="0",addr="0x0804891f",func="foo",
31157 args=[@{name="i",value="10"@}],
6d52907e 31158 file="/tmp/a.c",fullname="/tmp/a.c",line="158",arch="i386:x86_64"@},
4694da01
TT
31159 state="running"@}],
31160current-thread-id="1"
31161(gdb)
31162@end smallexample
31163
a2c02241
NR
31164@subheading The @code{-thread-list-ids} Command
31165@findex -thread-list-ids
922fbb7b 31166
a2c02241 31167@subsubheading Synopsis
922fbb7b 31168
a2c02241
NR
31169@smallexample
31170 -thread-list-ids
31171@end smallexample
922fbb7b 31172
5d5658a1
PA
31173Produces a list of the currently known global @value{GDBN} thread ids.
31174At the end of the list it also prints the total number of such
31175threads.
922fbb7b 31176
c3b108f7
VP
31177This command is retained for historical reasons, the
31178@code{-thread-info} command should be used instead.
31179
922fbb7b
AC
31180@subsubheading @value{GDBN} Command
31181
a2c02241 31182Part of @samp{info threads} supplies the same information.
922fbb7b
AC
31183
31184@subsubheading Example
31185
922fbb7b 31186@smallexample
594fe323 31187(gdb)
a2c02241
NR
31188-thread-list-ids
31189^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
592375cd 31190current-thread-id="1",number-of-threads="3"
594fe323 31191(gdb)
922fbb7b
AC
31192@end smallexample
31193
a2c02241
NR
31194
31195@subheading The @code{-thread-select} Command
31196@findex -thread-select
922fbb7b
AC
31197
31198@subsubheading Synopsis
31199
31200@smallexample
5d5658a1 31201 -thread-select @var{thread-id}
922fbb7b
AC
31202@end smallexample
31203
5d5658a1
PA
31204Make thread with global thread number @var{thread-id} the current
31205thread. It prints the number of the new current thread, and the
31206topmost frame for that thread.
922fbb7b 31207
c3b108f7
VP
31208This command is deprecated in favor of explicitly using the
31209@samp{--thread} option to each command.
31210
922fbb7b
AC
31211@subsubheading @value{GDBN} Command
31212
a2c02241 31213The corresponding @value{GDBN} command is @samp{thread}.
922fbb7b
AC
31214
31215@subsubheading Example
922fbb7b
AC
31216
31217@smallexample
594fe323 31218(gdb)
a2c02241
NR
31219-exec-next
31220^running
594fe323 31221(gdb)
a2c02241
NR
31222*stopped,reason="end-stepping-range",thread-id="2",line="187",
31223file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
594fe323 31224(gdb)
a2c02241
NR
31225-thread-list-ids
31226^done,
31227thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
31228number-of-threads="3"
594fe323 31229(gdb)
a2c02241
NR
31230-thread-select 3
31231^done,new-thread-id="3",
31232frame=@{level="0",func="vprintf",
31233args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
6d52907e 31234@{name="arg",value="0x2"@}],file="vprintf.c",line="31",arch="i386:x86_64"@}
594fe323 31235(gdb)
922fbb7b
AC
31236@end smallexample
31237
5d77fe44
JB
31238@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31239@node GDB/MI Ada Tasking Commands
31240@section @sc{gdb/mi} Ada Tasking Commands
31241
31242@subheading The @code{-ada-task-info} Command
31243@findex -ada-task-info
31244
31245@subsubheading Synopsis
31246
31247@smallexample
31248 -ada-task-info [ @var{task-id} ]
31249@end smallexample
31250
31251Reports information about either a specific Ada task, if the
31252@var{task-id} parameter is present, or about all Ada tasks.
31253
31254@subsubheading @value{GDBN} Command
31255
31256The @samp{info tasks} command prints the same information
31257about all Ada tasks (@pxref{Ada Tasks}).
31258
31259@subsubheading Result
31260
31261The result is a table of Ada tasks. The following columns are
31262defined for each Ada task:
31263
31264@table @samp
31265@item current
31266This field exists only for the current thread. It has the value @samp{*}.
31267
31268@item id
31269The identifier that @value{GDBN} uses to refer to the Ada task.
31270
31271@item task-id
31272The identifier that the target uses to refer to the Ada task.
31273
31274@item thread-id
5d5658a1
PA
31275The global thread identifier of the thread corresponding to the Ada
31276task.
5d77fe44
JB
31277
31278This field should always exist, as Ada tasks are always implemented
31279on top of a thread. But if @value{GDBN} cannot find this corresponding
31280thread for any reason, the field is omitted.
31281
31282@item parent-id
31283This field exists only when the task was created by another task.
31284In this case, it provides the ID of the parent task.
31285
31286@item priority
31287The base priority of the task.
31288
31289@item state
31290The current state of the task. For a detailed description of the
31291possible states, see @ref{Ada Tasks}.
31292
31293@item name
31294The name of the task.
31295
31296@end table
31297
31298@subsubheading Example
31299
31300@smallexample
31301-ada-task-info
31302^done,tasks=@{nr_rows="3",nr_cols="8",
31303hdr=[@{width="1",alignment="-1",col_name="current",colhdr=""@},
31304@{width="3",alignment="1",col_name="id",colhdr="ID"@},
31305@{width="9",alignment="1",col_name="task-id",colhdr="TID"@},
31306@{width="4",alignment="1",col_name="thread-id",colhdr=""@},
31307@{width="4",alignment="1",col_name="parent-id",colhdr="P-ID"@},
31308@{width="3",alignment="1",col_name="priority",colhdr="Pri"@},
31309@{width="22",alignment="-1",col_name="state",colhdr="State"@},
31310@{width="1",alignment="2",col_name="name",colhdr="Name"@}],
31311body=[@{current="*",id="1",task-id=" 644010",thread-id="1",priority="48",
31312state="Child Termination Wait",name="main_task"@}]@}
31313(gdb)
31314@end smallexample
31315
a2c02241
NR
31316@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31317@node GDB/MI Program Execution
31318@section @sc{gdb/mi} Program Execution
922fbb7b 31319
ef21caaf 31320These are the asynchronous commands which generate the out-of-band
3f94c067 31321record @samp{*stopped}. Currently @value{GDBN} only really executes
ef21caaf
NR
31322asynchronously with remote targets and this interaction is mimicked in
31323other cases.
922fbb7b 31324
922fbb7b
AC
31325@subheading The @code{-exec-continue} Command
31326@findex -exec-continue
31327
31328@subsubheading Synopsis
31329
31330@smallexample
540aa8e7 31331 -exec-continue [--reverse] [--all|--thread-group N]
922fbb7b
AC
31332@end smallexample
31333
540aa8e7
MS
31334Resumes the execution of the inferior program, which will continue
31335to execute until it reaches a debugger stop event. If the
31336@samp{--reverse} option is specified, execution resumes in reverse until
31337it reaches a stop event. Stop events may include
31338@itemize @bullet
31339@item
31340breakpoints or watchpoints
31341@item
31342signals or exceptions
31343@item
31344the end of the process (or its beginning under @samp{--reverse})
31345@item
31346the end or beginning of a replay log if one is being used.
31347@end itemize
31348In all-stop mode (@pxref{All-Stop
31349Mode}), may resume only one thread, or all threads, depending on the
31350value of the @samp{scheduler-locking} variable. If @samp{--all} is
a79b8f6e 31351specified, all threads (in all inferiors) will be resumed. The @samp{--all} option is
540aa8e7
MS
31352ignored in all-stop mode. If the @samp{--thread-group} options is
31353specified, then all threads in that thread group are resumed.
922fbb7b
AC
31354
31355@subsubheading @value{GDBN} Command
31356
31357The corresponding @value{GDBN} corresponding is @samp{continue}.
31358
31359@subsubheading Example
31360
31361@smallexample
31362-exec-continue
31363^running
594fe323 31364(gdb)
922fbb7b 31365@@Hello world
a47ec5fe
AR
31366*stopped,reason="breakpoint-hit",disp="keep",bkptno="2",frame=@{
31367func="foo",args=[],file="hello.c",fullname="/home/foo/bar/hello.c",
6d52907e 31368line="13",arch="i386:x86_64"@}
594fe323 31369(gdb)
922fbb7b
AC
31370@end smallexample
31371
31372
31373@subheading The @code{-exec-finish} Command
31374@findex -exec-finish
31375
31376@subsubheading Synopsis
31377
31378@smallexample
540aa8e7 31379 -exec-finish [--reverse]
922fbb7b
AC
31380@end smallexample
31381
ef21caaf
NR
31382Resumes the execution of the inferior program until the current
31383function is exited. Displays the results returned by the function.
540aa8e7
MS
31384If the @samp{--reverse} option is specified, resumes the reverse
31385execution of the inferior program until the point where current
31386function was called.
922fbb7b
AC
31387
31388@subsubheading @value{GDBN} Command
31389
31390The corresponding @value{GDBN} command is @samp{finish}.
31391
31392@subsubheading Example
31393
31394Function returning @code{void}.
31395
31396@smallexample
31397-exec-finish
31398^running
594fe323 31399(gdb)
922fbb7b
AC
31400@@hello from foo
31401*stopped,reason="function-finished",frame=@{func="main",args=[],
6d52907e 31402file="hello.c",fullname="/home/foo/bar/hello.c",line="7",arch="i386:x86_64"@}
594fe323 31403(gdb)
922fbb7b
AC
31404@end smallexample
31405
31406Function returning other than @code{void}. The name of the internal
31407@value{GDBN} variable storing the result is printed, together with the
31408value itself.
31409
31410@smallexample
31411-exec-finish
31412^running
594fe323 31413(gdb)
922fbb7b
AC
31414*stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
31415args=[@{name="a",value="1"],@{name="b",value="9"@}@},
6d52907e
JV
31416file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31417arch="i386:x86_64"@},
922fbb7b 31418gdb-result-var="$1",return-value="0"
594fe323 31419(gdb)
922fbb7b
AC
31420@end smallexample
31421
31422
31423@subheading The @code{-exec-interrupt} Command
31424@findex -exec-interrupt
31425
31426@subsubheading Synopsis
31427
31428@smallexample
c3b108f7 31429 -exec-interrupt [--all|--thread-group N]
922fbb7b
AC
31430@end smallexample
31431
ef21caaf
NR
31432Interrupts the background execution of the target. Note how the token
31433associated with the stop message is the one for the execution command
31434that has been interrupted. The token for the interrupt itself only
31435appears in the @samp{^done} output. If the user is trying to
922fbb7b
AC
31436interrupt a non-running program, an error message will be printed.
31437
c3b108f7
VP
31438Note that when asynchronous execution is enabled, this command is
31439asynchronous just like other execution commands. That is, first the
31440@samp{^done} response will be printed, and the target stop will be
31441reported after that using the @samp{*stopped} notification.
31442
31443In non-stop mode, only the context thread is interrupted by default.
a79b8f6e
VP
31444All threads (in all inferiors) will be interrupted if the
31445@samp{--all} option is specified. If the @samp{--thread-group}
31446option is specified, all threads in that group will be interrupted.
c3b108f7 31447
922fbb7b
AC
31448@subsubheading @value{GDBN} Command
31449
31450The corresponding @value{GDBN} command is @samp{interrupt}.
31451
31452@subsubheading Example
31453
31454@smallexample
594fe323 31455(gdb)
922fbb7b
AC
31456111-exec-continue
31457111^running
31458
594fe323 31459(gdb)
922fbb7b
AC
31460222-exec-interrupt
31461222^done
594fe323 31462(gdb)
922fbb7b 31463111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
76ff342d 31464frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
6d52907e 31465fullname="/home/foo/bar/try.c",line="13",arch="i386:x86_64"@}
594fe323 31466(gdb)
922fbb7b 31467
594fe323 31468(gdb)
922fbb7b
AC
31469-exec-interrupt
31470^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
594fe323 31471(gdb)
922fbb7b
AC
31472@end smallexample
31473
83eba9b7
VP
31474@subheading The @code{-exec-jump} Command
31475@findex -exec-jump
31476
31477@subsubheading Synopsis
31478
31479@smallexample
31480 -exec-jump @var{location}
31481@end smallexample
31482
31483Resumes execution of the inferior program at the location specified by
31484parameter. @xref{Specify Location}, for a description of the
31485different forms of @var{location}.
31486
31487@subsubheading @value{GDBN} Command
31488
31489The corresponding @value{GDBN} command is @samp{jump}.
31490
31491@subsubheading Example
31492
31493@smallexample
31494-exec-jump foo.c:10
31495*running,thread-id="all"
31496^running
31497@end smallexample
31498
922fbb7b
AC
31499
31500@subheading The @code{-exec-next} Command
31501@findex -exec-next
31502
31503@subsubheading Synopsis
31504
31505@smallexample
540aa8e7 31506 -exec-next [--reverse]
922fbb7b
AC
31507@end smallexample
31508
ef21caaf
NR
31509Resumes execution of the inferior program, stopping when the beginning
31510of the next source line is reached.
922fbb7b 31511
540aa8e7
MS
31512If the @samp{--reverse} option is specified, resumes reverse execution
31513of the inferior program, stopping at the beginning of the previous
31514source line. If you issue this command on the first line of a
31515function, it will take you back to the caller of that function, to the
31516source line where the function was called.
31517
31518
922fbb7b
AC
31519@subsubheading @value{GDBN} Command
31520
31521The corresponding @value{GDBN} command is @samp{next}.
31522
31523@subsubheading Example
31524
31525@smallexample
31526-exec-next
31527^running
594fe323 31528(gdb)
922fbb7b 31529*stopped,reason="end-stepping-range",line="8",file="hello.c"
594fe323 31530(gdb)
922fbb7b
AC
31531@end smallexample
31532
31533
31534@subheading The @code{-exec-next-instruction} Command
31535@findex -exec-next-instruction
31536
31537@subsubheading Synopsis
31538
31539@smallexample
540aa8e7 31540 -exec-next-instruction [--reverse]
922fbb7b
AC
31541@end smallexample
31542
ef21caaf
NR
31543Executes one machine instruction. If the instruction is a function
31544call, continues until the function returns. If the program stops at an
31545instruction in the middle of a source line, the address will be
31546printed as well.
922fbb7b 31547
540aa8e7
MS
31548If the @samp{--reverse} option is specified, resumes reverse execution
31549of the inferior program, stopping at the previous instruction. If the
31550previously executed instruction was a return from another function,
31551it will continue to execute in reverse until the call to that function
31552(from the current stack frame) is reached.
31553
922fbb7b
AC
31554@subsubheading @value{GDBN} Command
31555
31556The corresponding @value{GDBN} command is @samp{nexti}.
31557
31558@subsubheading Example
31559
31560@smallexample
594fe323 31561(gdb)
922fbb7b
AC
31562-exec-next-instruction
31563^running
31564
594fe323 31565(gdb)
922fbb7b
AC
31566*stopped,reason="end-stepping-range",
31567addr="0x000100d4",line="5",file="hello.c"
594fe323 31568(gdb)
922fbb7b
AC
31569@end smallexample
31570
31571
31572@subheading The @code{-exec-return} Command
31573@findex -exec-return
31574
31575@subsubheading Synopsis
31576
31577@smallexample
31578 -exec-return
31579@end smallexample
31580
31581Makes current function return immediately. Doesn't execute the inferior.
31582Displays the new current frame.
31583
31584@subsubheading @value{GDBN} Command
31585
31586The corresponding @value{GDBN} command is @samp{return}.
31587
31588@subsubheading Example
31589
31590@smallexample
594fe323 31591(gdb)
922fbb7b
AC
31592200-break-insert callee4
31593200^done,bkpt=@{number="1",addr="0x00010734",
31594file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
594fe323 31595(gdb)
922fbb7b
AC
31596000-exec-run
31597000^running
594fe323 31598(gdb)
a47ec5fe 31599000*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
922fbb7b 31600frame=@{func="callee4",args=[],
76ff342d 31601file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
31602fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
31603arch="i386:x86_64"@}
594fe323 31604(gdb)
922fbb7b
AC
31605205-break-delete
31606205^done
594fe323 31607(gdb)
922fbb7b
AC
31608111-exec-return
31609111^done,frame=@{level="0",func="callee3",
31610args=[@{name="strarg",
31611value="0x11940 \"A string argument.\""@}],
76ff342d 31612file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
31613fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
31614arch="i386:x86_64"@}
594fe323 31615(gdb)
922fbb7b
AC
31616@end smallexample
31617
31618
31619@subheading The @code{-exec-run} Command
31620@findex -exec-run
31621
31622@subsubheading Synopsis
31623
31624@smallexample
5713b9b5 31625 -exec-run [ --all | --thread-group N ] [ --start ]
922fbb7b
AC
31626@end smallexample
31627
ef21caaf
NR
31628Starts execution of the inferior from the beginning. The inferior
31629executes until either a breakpoint is encountered or the program
31630exits. In the latter case the output will include an exit code, if
31631the program has exited exceptionally.
922fbb7b 31632
5713b9b5
JB
31633When neither the @samp{--all} nor the @samp{--thread-group} option
31634is specified, the current inferior is started. If the
a79b8f6e
VP
31635@samp{--thread-group} option is specified, it should refer to a thread
31636group of type @samp{process}, and that thread group will be started.
31637If the @samp{--all} option is specified, then all inferiors will be started.
31638
5713b9b5
JB
31639Using the @samp{--start} option instructs the debugger to stop
31640the execution at the start of the inferior's main subprogram,
31641following the same behavior as the @code{start} command
31642(@pxref{Starting}).
31643
922fbb7b
AC
31644@subsubheading @value{GDBN} Command
31645
31646The corresponding @value{GDBN} command is @samp{run}.
31647
ef21caaf 31648@subsubheading Examples
922fbb7b
AC
31649
31650@smallexample
594fe323 31651(gdb)
922fbb7b
AC
31652-break-insert main
31653^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
594fe323 31654(gdb)
922fbb7b
AC
31655-exec-run
31656^running
594fe323 31657(gdb)
a47ec5fe 31658*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
76ff342d 31659frame=@{func="main",args=[],file="recursive2.c",
6d52907e 31660fullname="/home/foo/bar/recursive2.c",line="4",arch="i386:x86_64"@}
594fe323 31661(gdb)
922fbb7b
AC
31662@end smallexample
31663
ef21caaf
NR
31664@noindent
31665Program exited normally:
31666
31667@smallexample
594fe323 31668(gdb)
ef21caaf
NR
31669-exec-run
31670^running
594fe323 31671(gdb)
ef21caaf
NR
31672x = 55
31673*stopped,reason="exited-normally"
594fe323 31674(gdb)
ef21caaf
NR
31675@end smallexample
31676
31677@noindent
31678Program exited exceptionally:
31679
31680@smallexample
594fe323 31681(gdb)
ef21caaf
NR
31682-exec-run
31683^running
594fe323 31684(gdb)
ef21caaf
NR
31685x = 55
31686*stopped,reason="exited",exit-code="01"
594fe323 31687(gdb)
ef21caaf
NR
31688@end smallexample
31689
31690Another way the program can terminate is if it receives a signal such as
31691@code{SIGINT}. In this case, @sc{gdb/mi} displays this:
31692
31693@smallexample
594fe323 31694(gdb)
ef21caaf
NR
31695*stopped,reason="exited-signalled",signal-name="SIGINT",
31696signal-meaning="Interrupt"
31697@end smallexample
31698
922fbb7b 31699
a2c02241
NR
31700@c @subheading -exec-signal
31701
31702
31703@subheading The @code{-exec-step} Command
31704@findex -exec-step
922fbb7b
AC
31705
31706@subsubheading Synopsis
31707
31708@smallexample
540aa8e7 31709 -exec-step [--reverse]
922fbb7b
AC
31710@end smallexample
31711
a2c02241
NR
31712Resumes execution of the inferior program, stopping when the beginning
31713of the next source line is reached, if the next source line is not a
31714function call. If it is, stop at the first instruction of the called
540aa8e7
MS
31715function. If the @samp{--reverse} option is specified, resumes reverse
31716execution of the inferior program, stopping at the beginning of the
31717previously executed source line.
922fbb7b
AC
31718
31719@subsubheading @value{GDBN} Command
31720
a2c02241 31721The corresponding @value{GDBN} command is @samp{step}.
922fbb7b
AC
31722
31723@subsubheading Example
31724
31725Stepping into a function:
31726
31727@smallexample
31728-exec-step
31729^running
594fe323 31730(gdb)
922fbb7b
AC
31731*stopped,reason="end-stepping-range",
31732frame=@{func="foo",args=[@{name="a",value="10"@},
76ff342d 31733@{name="b",value="0"@}],file="recursive2.c",
6d52907e 31734fullname="/home/foo/bar/recursive2.c",line="11",arch="i386:x86_64"@}
594fe323 31735(gdb)
922fbb7b
AC
31736@end smallexample
31737
31738Regular stepping:
31739
31740@smallexample
31741-exec-step
31742^running
594fe323 31743(gdb)
922fbb7b 31744*stopped,reason="end-stepping-range",line="14",file="recursive2.c"
594fe323 31745(gdb)
922fbb7b
AC
31746@end smallexample
31747
31748
31749@subheading The @code{-exec-step-instruction} Command
31750@findex -exec-step-instruction
31751
31752@subsubheading Synopsis
31753
31754@smallexample
540aa8e7 31755 -exec-step-instruction [--reverse]
922fbb7b
AC
31756@end smallexample
31757
540aa8e7
MS
31758Resumes the inferior which executes one machine instruction. If the
31759@samp{--reverse} option is specified, resumes reverse execution of the
31760inferior program, stopping at the previously executed instruction.
31761The output, once @value{GDBN} has stopped, will vary depending on
31762whether we have stopped in the middle of a source line or not. In the
31763former case, the address at which the program stopped will be printed
31764as well.
922fbb7b
AC
31765
31766@subsubheading @value{GDBN} Command
31767
31768The corresponding @value{GDBN} command is @samp{stepi}.
31769
31770@subsubheading Example
31771
31772@smallexample
594fe323 31773(gdb)
922fbb7b
AC
31774-exec-step-instruction
31775^running
31776
594fe323 31777(gdb)
922fbb7b 31778*stopped,reason="end-stepping-range",
76ff342d 31779frame=@{func="foo",args=[],file="try.c",
6d52907e 31780fullname="/home/foo/bar/try.c",line="10",arch="i386:x86_64"@}
594fe323 31781(gdb)
922fbb7b
AC
31782-exec-step-instruction
31783^running
31784
594fe323 31785(gdb)
922fbb7b 31786*stopped,reason="end-stepping-range",
76ff342d 31787frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
6d52907e 31788fullname="/home/foo/bar/try.c",line="10",arch="i386:x86_64"@}
594fe323 31789(gdb)
922fbb7b
AC
31790@end smallexample
31791
31792
31793@subheading The @code{-exec-until} Command
31794@findex -exec-until
31795
31796@subsubheading Synopsis
31797
31798@smallexample
31799 -exec-until [ @var{location} ]
31800@end smallexample
31801
ef21caaf
NR
31802Executes the inferior until the @var{location} specified in the
31803argument is reached. If there is no argument, the inferior executes
31804until a source line greater than the current one is reached. The
31805reason for stopping in this case will be @samp{location-reached}.
922fbb7b
AC
31806
31807@subsubheading @value{GDBN} Command
31808
31809The corresponding @value{GDBN} command is @samp{until}.
31810
31811@subsubheading Example
31812
31813@smallexample
594fe323 31814(gdb)
922fbb7b
AC
31815-exec-until recursive2.c:6
31816^running
594fe323 31817(gdb)
922fbb7b
AC
31818x = 55
31819*stopped,reason="location-reached",frame=@{func="main",args=[],
6d52907e
JV
31820file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="6",
31821arch="i386:x86_64"@}
594fe323 31822(gdb)
922fbb7b
AC
31823@end smallexample
31824
31825@ignore
31826@subheading -file-clear
31827Is this going away????
31828@end ignore
31829
351ff01a 31830@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
31831@node GDB/MI Stack Manipulation
31832@section @sc{gdb/mi} Stack Manipulation Commands
351ff01a 31833
1e611234
PM
31834@subheading The @code{-enable-frame-filters} Command
31835@findex -enable-frame-filters
31836
31837@smallexample
31838-enable-frame-filters
31839@end smallexample
31840
31841@value{GDBN} allows Python-based frame filters to affect the output of
31842the MI commands relating to stack traces. As there is no way to
31843implement this in a fully backward-compatible way, a front end must
31844request that this functionality be enabled.
31845
31846Once enabled, this feature cannot be disabled.
31847
31848Note that if Python support has not been compiled into @value{GDBN},
31849this command will still succeed (and do nothing).
922fbb7b 31850
a2c02241
NR
31851@subheading The @code{-stack-info-frame} Command
31852@findex -stack-info-frame
922fbb7b
AC
31853
31854@subsubheading Synopsis
31855
31856@smallexample
a2c02241 31857 -stack-info-frame
922fbb7b
AC
31858@end smallexample
31859
a2c02241 31860Get info on the selected frame.
922fbb7b
AC
31861
31862@subsubheading @value{GDBN} Command
31863
a2c02241
NR
31864The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
31865(without arguments).
922fbb7b
AC
31866
31867@subsubheading Example
31868
31869@smallexample
594fe323 31870(gdb)
a2c02241
NR
31871-stack-info-frame
31872^done,frame=@{level="1",addr="0x0001076c",func="callee3",
31873file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
31874fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17",
31875arch="i386:x86_64"@}
594fe323 31876(gdb)
922fbb7b
AC
31877@end smallexample
31878
a2c02241
NR
31879@subheading The @code{-stack-info-depth} Command
31880@findex -stack-info-depth
922fbb7b
AC
31881
31882@subsubheading Synopsis
31883
31884@smallexample
a2c02241 31885 -stack-info-depth [ @var{max-depth} ]
922fbb7b
AC
31886@end smallexample
31887
a2c02241
NR
31888Return the depth of the stack. If the integer argument @var{max-depth}
31889is specified, do not count beyond @var{max-depth} frames.
922fbb7b
AC
31890
31891@subsubheading @value{GDBN} Command
31892
a2c02241 31893There's no equivalent @value{GDBN} command.
922fbb7b
AC
31894
31895@subsubheading Example
31896
a2c02241
NR
31897For a stack with frame levels 0 through 11:
31898
922fbb7b 31899@smallexample
594fe323 31900(gdb)
a2c02241
NR
31901-stack-info-depth
31902^done,depth="12"
594fe323 31903(gdb)
a2c02241
NR
31904-stack-info-depth 4
31905^done,depth="4"
594fe323 31906(gdb)
a2c02241
NR
31907-stack-info-depth 12
31908^done,depth="12"
594fe323 31909(gdb)
a2c02241
NR
31910-stack-info-depth 11
31911^done,depth="11"
594fe323 31912(gdb)
a2c02241
NR
31913-stack-info-depth 13
31914^done,depth="12"
594fe323 31915(gdb)
922fbb7b
AC
31916@end smallexample
31917
1e611234 31918@anchor{-stack-list-arguments}
a2c02241
NR
31919@subheading The @code{-stack-list-arguments} Command
31920@findex -stack-list-arguments
922fbb7b
AC
31921
31922@subsubheading Synopsis
31923
31924@smallexample
6211c335 31925 -stack-list-arguments [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
a2c02241 31926 [ @var{low-frame} @var{high-frame} ]
922fbb7b
AC
31927@end smallexample
31928
a2c02241
NR
31929Display a list of the arguments for the frames between @var{low-frame}
31930and @var{high-frame} (inclusive). If @var{low-frame} and
2f1acb09
VP
31931@var{high-frame} are not provided, list the arguments for the whole
31932call stack. If the two arguments are equal, show the single frame
31933at the corresponding level. It is an error if @var{low-frame} is
31934larger than the actual number of frames. On the other hand,
31935@var{high-frame} may be larger than the actual number of frames, in
31936which case only existing frames will be returned.
a2c02241 31937
3afae151
VP
31938If @var{print-values} is 0 or @code{--no-values}, print only the names of
31939the variables; if it is 1 or @code{--all-values}, print also their
31940values; and if it is 2 or @code{--simple-values}, print the name,
31941type and value for simple data types, and the name and type for arrays,
1e611234
PM
31942structures and unions. If the option @code{--no-frame-filters} is
31943supplied, then Python frame filters will not be executed.
31944
6211c335
YQ
31945If the @code{--skip-unavailable} option is specified, arguments that
31946are not available are not listed. Partially available arguments
31947are still displayed, however.
922fbb7b 31948
b3372f91
VP
31949Use of this command to obtain arguments in a single frame is
31950deprecated in favor of the @samp{-stack-list-variables} command.
31951
922fbb7b
AC
31952@subsubheading @value{GDBN} Command
31953
a2c02241
NR
31954@value{GDBN} does not have an equivalent command. @code{gdbtk} has a
31955@samp{gdb_get_args} command which partially overlaps with the
31956functionality of @samp{-stack-list-arguments}.
922fbb7b
AC
31957
31958@subsubheading Example
922fbb7b 31959
a2c02241 31960@smallexample
594fe323 31961(gdb)
a2c02241
NR
31962-stack-list-frames
31963^done,
31964stack=[
31965frame=@{level="0",addr="0x00010734",func="callee4",
31966file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
31967fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
31968arch="i386:x86_64"@},
a2c02241
NR
31969frame=@{level="1",addr="0x0001076c",func="callee3",
31970file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
31971fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17",
31972arch="i386:x86_64"@},
a2c02241
NR
31973frame=@{level="2",addr="0x0001078c",func="callee2",
31974file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
31975fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22",
31976arch="i386:x86_64"@},
a2c02241
NR
31977frame=@{level="3",addr="0x000107b4",func="callee1",
31978file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
31979fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27",
31980arch="i386:x86_64"@},
a2c02241
NR
31981frame=@{level="4",addr="0x000107e0",func="main",
31982file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
31983fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32",
31984arch="i386:x86_64"@}]
594fe323 31985(gdb)
a2c02241
NR
31986-stack-list-arguments 0
31987^done,
31988stack-args=[
31989frame=@{level="0",args=[]@},
31990frame=@{level="1",args=[name="strarg"]@},
31991frame=@{level="2",args=[name="intarg",name="strarg"]@},
31992frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
31993frame=@{level="4",args=[]@}]
594fe323 31994(gdb)
a2c02241
NR
31995-stack-list-arguments 1
31996^done,
31997stack-args=[
31998frame=@{level="0",args=[]@},
31999frame=@{level="1",
32000 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
32001frame=@{level="2",args=[
32002@{name="intarg",value="2"@},
32003@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
32004@{frame=@{level="3",args=[
32005@{name="intarg",value="2"@},
32006@{name="strarg",value="0x11940 \"A string argument.\""@},
32007@{name="fltarg",value="3.5"@}]@},
32008frame=@{level="4",args=[]@}]
594fe323 32009(gdb)
a2c02241
NR
32010-stack-list-arguments 0 2 2
32011^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
594fe323 32012(gdb)
a2c02241
NR
32013-stack-list-arguments 1 2 2
32014^done,stack-args=[frame=@{level="2",
32015args=[@{name="intarg",value="2"@},
32016@{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
594fe323 32017(gdb)
a2c02241
NR
32018@end smallexample
32019
32020@c @subheading -stack-list-exception-handlers
922fbb7b 32021
a2c02241 32022
1e611234 32023@anchor{-stack-list-frames}
a2c02241
NR
32024@subheading The @code{-stack-list-frames} Command
32025@findex -stack-list-frames
1abaf70c
BR
32026
32027@subsubheading Synopsis
32028
32029@smallexample
1e611234 32030 -stack-list-frames [ --no-frame-filters @var{low-frame} @var{high-frame} ]
1abaf70c
BR
32031@end smallexample
32032
a2c02241
NR
32033List the frames currently on the stack. For each frame it displays the
32034following info:
32035
32036@table @samp
32037@item @var{level}
d3e8051b 32038The frame number, 0 being the topmost frame, i.e., the innermost function.
a2c02241
NR
32039@item @var{addr}
32040The @code{$pc} value for that frame.
32041@item @var{func}
32042Function name.
32043@item @var{file}
32044File name of the source file where the function lives.
7d288aaa
TT
32045@item @var{fullname}
32046The full file name of the source file where the function lives.
a2c02241
NR
32047@item @var{line}
32048Line number corresponding to the @code{$pc}.
7d288aaa
TT
32049@item @var{from}
32050The shared library where this function is defined. This is only given
32051if the frame's function is not known.
6d52907e
JV
32052@item @var{arch}
32053Frame's architecture.
a2c02241
NR
32054@end table
32055
32056If invoked without arguments, this command prints a backtrace for the
32057whole stack. If given two integer arguments, it shows the frames whose
32058levels are between the two arguments (inclusive). If the two arguments
2ab1eb7a
VP
32059are equal, it shows the single frame at the corresponding level. It is
32060an error if @var{low-frame} is larger than the actual number of
a5451f4e 32061frames. On the other hand, @var{high-frame} may be larger than the
1e611234
PM
32062actual number of frames, in which case only existing frames will be
32063returned. If the option @code{--no-frame-filters} is supplied, then
32064Python frame filters will not be executed.
1abaf70c
BR
32065
32066@subsubheading @value{GDBN} Command
32067
a2c02241 32068The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
1abaf70c
BR
32069
32070@subsubheading Example
32071
a2c02241
NR
32072Full stack backtrace:
32073
1abaf70c 32074@smallexample
594fe323 32075(gdb)
a2c02241
NR
32076-stack-list-frames
32077^done,stack=
32078[frame=@{level="0",addr="0x0001076c",func="foo",
6d52907e
JV
32079 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="11",
32080 arch="i386:x86_64"@},
a2c02241 32081frame=@{level="1",addr="0x000107a4",func="foo",
6d52907e
JV
32082 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32083 arch="i386:x86_64"@},
a2c02241 32084frame=@{level="2",addr="0x000107a4",func="foo",
6d52907e
JV
32085 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32086 arch="i386:x86_64"@},
a2c02241 32087frame=@{level="3",addr="0x000107a4",func="foo",
6d52907e
JV
32088 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32089 arch="i386:x86_64"@},
a2c02241 32090frame=@{level="4",addr="0x000107a4",func="foo",
6d52907e
JV
32091 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32092 arch="i386:x86_64"@},
a2c02241 32093frame=@{level="5",addr="0x000107a4",func="foo",
6d52907e
JV
32094 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32095 arch="i386:x86_64"@},
a2c02241 32096frame=@{level="6",addr="0x000107a4",func="foo",
6d52907e
JV
32097 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32098 arch="i386:x86_64"@},
a2c02241 32099frame=@{level="7",addr="0x000107a4",func="foo",
6d52907e
JV
32100 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32101 arch="i386:x86_64"@},
a2c02241 32102frame=@{level="8",addr="0x000107a4",func="foo",
6d52907e
JV
32103 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32104 arch="i386:x86_64"@},
a2c02241 32105frame=@{level="9",addr="0x000107a4",func="foo",
6d52907e
JV
32106 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32107 arch="i386:x86_64"@},
a2c02241 32108frame=@{level="10",addr="0x000107a4",func="foo",
6d52907e
JV
32109 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32110 arch="i386:x86_64"@},
a2c02241 32111frame=@{level="11",addr="0x00010738",func="main",
6d52907e
JV
32112 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="4",
32113 arch="i386:x86_64"@}]
594fe323 32114(gdb)
1abaf70c
BR
32115@end smallexample
32116
a2c02241 32117Show frames between @var{low_frame} and @var{high_frame}:
1abaf70c 32118
a2c02241 32119@smallexample
594fe323 32120(gdb)
a2c02241
NR
32121-stack-list-frames 3 5
32122^done,stack=
32123[frame=@{level="3",addr="0x000107a4",func="foo",
6d52907e
JV
32124 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32125 arch="i386:x86_64"@},
a2c02241 32126frame=@{level="4",addr="0x000107a4",func="foo",
6d52907e
JV
32127 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32128 arch="i386:x86_64"@},
a2c02241 32129frame=@{level="5",addr="0x000107a4",func="foo",
6d52907e
JV
32130 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32131 arch="i386:x86_64"@}]
594fe323 32132(gdb)
a2c02241 32133@end smallexample
922fbb7b 32134
a2c02241 32135Show a single frame:
922fbb7b
AC
32136
32137@smallexample
594fe323 32138(gdb)
a2c02241
NR
32139-stack-list-frames 3 3
32140^done,stack=
32141[frame=@{level="3",addr="0x000107a4",func="foo",
6d52907e
JV
32142 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32143 arch="i386:x86_64"@}]
594fe323 32144(gdb)
922fbb7b
AC
32145@end smallexample
32146
922fbb7b 32147
a2c02241
NR
32148@subheading The @code{-stack-list-locals} Command
32149@findex -stack-list-locals
1e611234 32150@anchor{-stack-list-locals}
57c22c6c 32151
a2c02241 32152@subsubheading Synopsis
922fbb7b
AC
32153
32154@smallexample
6211c335 32155 -stack-list-locals [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
922fbb7b
AC
32156@end smallexample
32157
a2c02241
NR
32158Display the local variable names for the selected frame. If
32159@var{print-values} is 0 or @code{--no-values}, print only the names of
32160the variables; if it is 1 or @code{--all-values}, print also their
32161values; and if it is 2 or @code{--simple-values}, print the name,
3afae151 32162type and value for simple data types, and the name and type for arrays,
a2c02241
NR
32163structures and unions. In this last case, a frontend can immediately
32164display the value of simple data types and create variable objects for
d3e8051b 32165other data types when the user wishes to explore their values in
1e611234
PM
32166more detail. If the option @code{--no-frame-filters} is supplied, then
32167Python frame filters will not be executed.
922fbb7b 32168
6211c335
YQ
32169If the @code{--skip-unavailable} option is specified, local variables
32170that are not available are not listed. Partially available local
32171variables are still displayed, however.
32172
b3372f91
VP
32173This command is deprecated in favor of the
32174@samp{-stack-list-variables} command.
32175
922fbb7b
AC
32176@subsubheading @value{GDBN} Command
32177
a2c02241 32178@samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
922fbb7b
AC
32179
32180@subsubheading Example
922fbb7b
AC
32181
32182@smallexample
594fe323 32183(gdb)
a2c02241
NR
32184-stack-list-locals 0
32185^done,locals=[name="A",name="B",name="C"]
594fe323 32186(gdb)
a2c02241
NR
32187-stack-list-locals --all-values
32188^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
32189 @{name="C",value="@{1, 2, 3@}"@}]
32190-stack-list-locals --simple-values
32191^done,locals=[@{name="A",type="int",value="1"@},
32192 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
594fe323 32193(gdb)
922fbb7b
AC
32194@end smallexample
32195
1e611234 32196@anchor{-stack-list-variables}
b3372f91
VP
32197@subheading The @code{-stack-list-variables} Command
32198@findex -stack-list-variables
32199
32200@subsubheading Synopsis
32201
32202@smallexample
6211c335 32203 -stack-list-variables [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
b3372f91
VP
32204@end smallexample
32205
32206Display the names of local variables and function arguments for the selected frame. If
32207@var{print-values} is 0 or @code{--no-values}, print only the names of
32208the variables; if it is 1 or @code{--all-values}, print also their
32209values; and if it is 2 or @code{--simple-values}, print the name,
3afae151 32210type and value for simple data types, and the name and type for arrays,
1e611234
PM
32211structures and unions. If the option @code{--no-frame-filters} is
32212supplied, then Python frame filters will not be executed.
b3372f91 32213
6211c335
YQ
32214If the @code{--skip-unavailable} option is specified, local variables
32215and arguments that are not available are not listed. Partially
32216available arguments and local variables are still displayed, however.
32217
b3372f91
VP
32218@subsubheading Example
32219
32220@smallexample
32221(gdb)
32222-stack-list-variables --thread 1 --frame 0 --all-values
4f412fd0 32223^done,variables=[@{name="x",value="11"@},@{name="s",value="@{a = 1, b = 2@}"@}]
b3372f91
VP
32224(gdb)
32225@end smallexample
32226
922fbb7b 32227
a2c02241
NR
32228@subheading The @code{-stack-select-frame} Command
32229@findex -stack-select-frame
922fbb7b
AC
32230
32231@subsubheading Synopsis
32232
32233@smallexample
a2c02241 32234 -stack-select-frame @var{framenum}
922fbb7b
AC
32235@end smallexample
32236
a2c02241
NR
32237Change the selected frame. Select a different frame @var{framenum} on
32238the stack.
922fbb7b 32239
c3b108f7
VP
32240This command in deprecated in favor of passing the @samp{--frame}
32241option to every command.
32242
922fbb7b
AC
32243@subsubheading @value{GDBN} Command
32244
a2c02241
NR
32245The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
32246@samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
922fbb7b
AC
32247
32248@subsubheading Example
32249
32250@smallexample
594fe323 32251(gdb)
a2c02241 32252-stack-select-frame 2
922fbb7b 32253^done
594fe323 32254(gdb)
922fbb7b
AC
32255@end smallexample
32256
32257@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
32258@node GDB/MI Variable Objects
32259@section @sc{gdb/mi} Variable Objects
922fbb7b 32260
a1b5960f 32261@ignore
922fbb7b 32262
a2c02241 32263@subheading Motivation for Variable Objects in @sc{gdb/mi}
922fbb7b 32264
a2c02241
NR
32265For the implementation of a variable debugger window (locals, watched
32266expressions, etc.), we are proposing the adaptation of the existing code
32267used by @code{Insight}.
922fbb7b 32268
a2c02241 32269The two main reasons for that are:
922fbb7b 32270
a2c02241
NR
32271@enumerate 1
32272@item
32273It has been proven in practice (it is already on its second generation).
922fbb7b 32274
a2c02241
NR
32275@item
32276It will shorten development time (needless to say how important it is
32277now).
32278@end enumerate
922fbb7b 32279
a2c02241
NR
32280The original interface was designed to be used by Tcl code, so it was
32281slightly changed so it could be used through @sc{gdb/mi}. This section
32282describes the @sc{gdb/mi} operations that will be available and gives some
32283hints about their use.
922fbb7b 32284
a2c02241
NR
32285@emph{Note}: In addition to the set of operations described here, we
32286expect the @sc{gui} implementation of a variable window to require, at
32287least, the following operations:
922fbb7b 32288
a2c02241
NR
32289@itemize @bullet
32290@item @code{-gdb-show} @code{output-radix}
32291@item @code{-stack-list-arguments}
32292@item @code{-stack-list-locals}
32293@item @code{-stack-select-frame}
32294@end itemize
922fbb7b 32295
a1b5960f
VP
32296@end ignore
32297
c8b2f53c 32298@subheading Introduction to Variable Objects
922fbb7b 32299
a2c02241 32300@cindex variable objects in @sc{gdb/mi}
c8b2f53c
VP
32301
32302Variable objects are "object-oriented" MI interface for examining and
32303changing values of expressions. Unlike some other MI interfaces that
32304work with expressions, variable objects are specifically designed for
32305simple and efficient presentation in the frontend. A variable object
32306is identified by string name. When a variable object is created, the
32307frontend specifies the expression for that variable object. The
32308expression can be a simple variable, or it can be an arbitrary complex
32309expression, and can even involve CPU registers. After creating a
32310variable object, the frontend can invoke other variable object
32311operations---for example to obtain or change the value of a variable
32312object, or to change display format.
32313
32314Variable objects have hierarchical tree structure. Any variable object
32315that corresponds to a composite type, such as structure in C, has
32316a number of child variable objects, for example corresponding to each
32317element of a structure. A child variable object can itself have
32318children, recursively. Recursion ends when we reach
25d5ea92
VP
32319leaf variable objects, which always have built-in types. Child variable
32320objects are created only by explicit request, so if a frontend
32321is not interested in the children of a particular variable object, no
32322child will be created.
c8b2f53c
VP
32323
32324For a leaf variable object it is possible to obtain its value as a
32325string, or set the value from a string. String value can be also
32326obtained for a non-leaf variable object, but it's generally a string
32327that only indicates the type of the object, and does not list its
32328contents. Assignment to a non-leaf variable object is not allowed.
32329
32330A frontend does not need to read the values of all variable objects each time
32331the program stops. Instead, MI provides an update command that lists all
32332variable objects whose values has changed since the last update
32333operation. This considerably reduces the amount of data that must
25d5ea92
VP
32334be transferred to the frontend. As noted above, children variable
32335objects are created on demand, and only leaf variable objects have a
32336real value. As result, gdb will read target memory only for leaf
32337variables that frontend has created.
32338
32339The automatic update is not always desirable. For example, a frontend
32340might want to keep a value of some expression for future reference,
32341and never update it. For another example, fetching memory is
32342relatively slow for embedded targets, so a frontend might want
32343to disable automatic update for the variables that are either not
32344visible on the screen, or ``closed''. This is possible using so
32345called ``frozen variable objects''. Such variable objects are never
32346implicitly updated.
922fbb7b 32347
c3b108f7
VP
32348Variable objects can be either @dfn{fixed} or @dfn{floating}. For the
32349fixed variable object, the expression is parsed when the variable
32350object is created, including associating identifiers to specific
32351variables. The meaning of expression never changes. For a floating
32352variable object the values of variables whose names appear in the
32353expressions are re-evaluated every time in the context of the current
32354frame. Consider this example:
32355
32356@smallexample
32357void do_work(...)
32358@{
32359 struct work_state state;
32360
32361 if (...)
32362 do_work(...);
32363@}
32364@end smallexample
32365
32366If a fixed variable object for the @code{state} variable is created in
7a9dd1b2 32367this function, and we enter the recursive call, the variable
c3b108f7
VP
32368object will report the value of @code{state} in the top-level
32369@code{do_work} invocation. On the other hand, a floating variable
32370object will report the value of @code{state} in the current frame.
32371
32372If an expression specified when creating a fixed variable object
32373refers to a local variable, the variable object becomes bound to the
32374thread and frame in which the variable object is created. When such
32375variable object is updated, @value{GDBN} makes sure that the
32376thread/frame combination the variable object is bound to still exists,
32377and re-evaluates the variable object in context of that thread/frame.
32378
a2c02241
NR
32379The following is the complete set of @sc{gdb/mi} operations defined to
32380access this functionality:
922fbb7b 32381
a2c02241
NR
32382@multitable @columnfractions .4 .6
32383@item @strong{Operation}
32384@tab @strong{Description}
922fbb7b 32385
0cc7d26f
TT
32386@item @code{-enable-pretty-printing}
32387@tab enable Python-based pretty-printing
a2c02241
NR
32388@item @code{-var-create}
32389@tab create a variable object
32390@item @code{-var-delete}
22d8a470 32391@tab delete the variable object and/or its children
a2c02241
NR
32392@item @code{-var-set-format}
32393@tab set the display format of this variable
32394@item @code{-var-show-format}
32395@tab show the display format of this variable
32396@item @code{-var-info-num-children}
32397@tab tells how many children this object has
32398@item @code{-var-list-children}
32399@tab return a list of the object's children
32400@item @code{-var-info-type}
32401@tab show the type of this variable object
32402@item @code{-var-info-expression}
02142340
VP
32403@tab print parent-relative expression that this variable object represents
32404@item @code{-var-info-path-expression}
32405@tab print full expression that this variable object represents
a2c02241
NR
32406@item @code{-var-show-attributes}
32407@tab is this variable editable? does it exist here?
32408@item @code{-var-evaluate-expression}
32409@tab get the value of this variable
32410@item @code{-var-assign}
32411@tab set the value of this variable
32412@item @code{-var-update}
32413@tab update the variable and its children
25d5ea92 32414@item @code{-var-set-frozen}
6b92c0d3 32415@tab set frozenness attribute
0cc7d26f
TT
32416@item @code{-var-set-update-range}
32417@tab set range of children to display on update
a2c02241 32418@end multitable
922fbb7b 32419
a2c02241
NR
32420In the next subsection we describe each operation in detail and suggest
32421how it can be used.
922fbb7b 32422
a2c02241 32423@subheading Description And Use of Operations on Variable Objects
922fbb7b 32424
0cc7d26f
TT
32425@subheading The @code{-enable-pretty-printing} Command
32426@findex -enable-pretty-printing
32427
32428@smallexample
32429-enable-pretty-printing
32430@end smallexample
32431
32432@value{GDBN} allows Python-based visualizers to affect the output of the
32433MI variable object commands. However, because there was no way to
32434implement this in a fully backward-compatible way, a front end must
32435request that this functionality be enabled.
32436
32437Once enabled, this feature cannot be disabled.
32438
32439Note that if Python support has not been compiled into @value{GDBN},
32440this command will still succeed (and do nothing).
32441
f43030c4
TT
32442This feature is currently (as of @value{GDBN} 7.0) experimental, and
32443may work differently in future versions of @value{GDBN}.
32444
a2c02241
NR
32445@subheading The @code{-var-create} Command
32446@findex -var-create
ef21caaf 32447
a2c02241 32448@subsubheading Synopsis
ef21caaf 32449
a2c02241
NR
32450@smallexample
32451 -var-create @{@var{name} | "-"@}
c3b108f7 32452 @{@var{frame-addr} | "*" | "@@"@} @var{expression}
a2c02241
NR
32453@end smallexample
32454
32455This operation creates a variable object, which allows the monitoring of
32456a variable, the result of an expression, a memory cell or a CPU
32457register.
ef21caaf 32458
a2c02241
NR
32459The @var{name} parameter is the string by which the object can be
32460referenced. It must be unique. If @samp{-} is specified, the varobj
32461system will generate a string ``varNNNNNN'' automatically. It will be
c3b108f7 32462unique provided that one does not specify @var{name} of that format.
a2c02241 32463The command fails if a duplicate name is found.
ef21caaf 32464
a2c02241
NR
32465The frame under which the expression should be evaluated can be
32466specified by @var{frame-addr}. A @samp{*} indicates that the current
c3b108f7
VP
32467frame should be used. A @samp{@@} indicates that a floating variable
32468object must be created.
922fbb7b 32469
a2c02241
NR
32470@var{expression} is any expression valid on the current language set (must not
32471begin with a @samp{*}), or one of the following:
922fbb7b 32472
a2c02241
NR
32473@itemize @bullet
32474@item
32475@samp{*@var{addr}}, where @var{addr} is the address of a memory cell
922fbb7b 32476
a2c02241
NR
32477@item
32478@samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
922fbb7b 32479
a2c02241
NR
32480@item
32481@samp{$@var{regname}} --- a CPU register name
32482@end itemize
922fbb7b 32483
0cc7d26f
TT
32484@cindex dynamic varobj
32485A varobj's contents may be provided by a Python-based pretty-printer. In this
32486case the varobj is known as a @dfn{dynamic varobj}. Dynamic varobjs
32487have slightly different semantics in some cases. If the
32488@code{-enable-pretty-printing} command is not sent, then @value{GDBN}
32489will never create a dynamic varobj. This ensures backward
32490compatibility for existing clients.
32491
a2c02241 32492@subsubheading Result
922fbb7b 32493
0cc7d26f
TT
32494This operation returns attributes of the newly-created varobj. These
32495are:
32496
32497@table @samp
32498@item name
32499The name of the varobj.
32500
32501@item numchild
32502The number of children of the varobj. This number is not necessarily
32503reliable for a dynamic varobj. Instead, you must examine the
32504@samp{has_more} attribute.
32505
32506@item value
32507The varobj's scalar value. For a varobj whose type is some sort of
32508aggregate (e.g., a @code{struct}), or for a dynamic varobj, this value
32509will not be interesting.
32510
32511@item type
32512The varobj's type. This is a string representation of the type, as
8264ba82
AG
32513would be printed by the @value{GDBN} CLI. If @samp{print object}
32514(@pxref{Print Settings, set print object}) is set to @code{on}, the
32515@emph{actual} (derived) type of the object is shown rather than the
32516@emph{declared} one.
0cc7d26f
TT
32517
32518@item thread-id
32519If a variable object is bound to a specific thread, then this is the
5d5658a1 32520thread's global identifier.
0cc7d26f
TT
32521
32522@item has_more
32523For a dynamic varobj, this indicates whether there appear to be any
32524children available. For a non-dynamic varobj, this will be 0.
32525
32526@item dynamic
32527This attribute will be present and have the value @samp{1} if the
32528varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
32529then this attribute will not be present.
32530
32531@item displayhint
32532A dynamic varobj can supply a display hint to the front end. The
32533value comes directly from the Python pretty-printer object's
4c374409 32534@code{display_hint} method. @xref{Pretty Printing API}.
0cc7d26f
TT
32535@end table
32536
32537Typical output will look like this:
922fbb7b
AC
32538
32539@smallexample
0cc7d26f
TT
32540 name="@var{name}",numchild="@var{N}",type="@var{type}",thread-id="@var{M}",
32541 has_more="@var{has_more}"
dcaaae04
NR
32542@end smallexample
32543
a2c02241
NR
32544
32545@subheading The @code{-var-delete} Command
32546@findex -var-delete
922fbb7b
AC
32547
32548@subsubheading Synopsis
32549
32550@smallexample
22d8a470 32551 -var-delete [ -c ] @var{name}
922fbb7b
AC
32552@end smallexample
32553
a2c02241 32554Deletes a previously created variable object and all of its children.
22d8a470 32555With the @samp{-c} option, just deletes the children.
922fbb7b 32556
a2c02241 32557Returns an error if the object @var{name} is not found.
922fbb7b 32558
922fbb7b 32559
a2c02241
NR
32560@subheading The @code{-var-set-format} Command
32561@findex -var-set-format
922fbb7b 32562
a2c02241 32563@subsubheading Synopsis
922fbb7b
AC
32564
32565@smallexample
a2c02241 32566 -var-set-format @var{name} @var{format-spec}
922fbb7b
AC
32567@end smallexample
32568
a2c02241
NR
32569Sets the output format for the value of the object @var{name} to be
32570@var{format-spec}.
32571
de051565 32572@anchor{-var-set-format}
a2c02241
NR
32573The syntax for the @var{format-spec} is as follows:
32574
32575@smallexample
32576 @var{format-spec} @expansion{}
1c35a88f 32577 @{binary | decimal | hexadecimal | octal | natural | zero-hexadecimal@}
a2c02241
NR
32578@end smallexample
32579
c8b2f53c
VP
32580The natural format is the default format choosen automatically
32581based on the variable type (like decimal for an @code{int}, hex
32582for pointers, etc.).
32583
1c35a88f
LM
32584The zero-hexadecimal format has a representation similar to hexadecimal
32585but with padding zeroes to the left of the value. For example, a 32-bit
32586hexadecimal value of 0x1234 would be represented as 0x00001234 in the
32587zero-hexadecimal format.
32588
c8b2f53c
VP
32589For a variable with children, the format is set only on the
32590variable itself, and the children are not affected.
a2c02241
NR
32591
32592@subheading The @code{-var-show-format} Command
32593@findex -var-show-format
922fbb7b
AC
32594
32595@subsubheading Synopsis
32596
32597@smallexample
a2c02241 32598 -var-show-format @var{name}
922fbb7b
AC
32599@end smallexample
32600
a2c02241 32601Returns the format used to display the value of the object @var{name}.
922fbb7b 32602
a2c02241
NR
32603@smallexample
32604 @var{format} @expansion{}
32605 @var{format-spec}
32606@end smallexample
922fbb7b 32607
922fbb7b 32608
a2c02241
NR
32609@subheading The @code{-var-info-num-children} Command
32610@findex -var-info-num-children
32611
32612@subsubheading Synopsis
32613
32614@smallexample
32615 -var-info-num-children @var{name}
32616@end smallexample
32617
32618Returns the number of children of a variable object @var{name}:
32619
32620@smallexample
32621 numchild=@var{n}
32622@end smallexample
32623
0cc7d26f
TT
32624Note that this number is not completely reliable for a dynamic varobj.
32625It will return the current number of children, but more children may
32626be available.
32627
a2c02241
NR
32628
32629@subheading The @code{-var-list-children} Command
32630@findex -var-list-children
32631
32632@subsubheading Synopsis
32633
32634@smallexample
0cc7d26f 32635 -var-list-children [@var{print-values}] @var{name} [@var{from} @var{to}]
a2c02241 32636@end smallexample
b569d230 32637@anchor{-var-list-children}
a2c02241
NR
32638
32639Return a list of the children of the specified variable object and
32640create variable objects for them, if they do not already exist. With
f5011d11 32641a single argument or if @var{print-values} has a value of 0 or
a2c02241
NR
32642@code{--no-values}, print only the names of the variables; if
32643@var{print-values} is 1 or @code{--all-values}, also print their
32644values; and if it is 2 or @code{--simple-values} print the name and
32645value for simple data types and just the name for arrays, structures
32646and unions.
922fbb7b 32647
0cc7d26f
TT
32648@var{from} and @var{to}, if specified, indicate the range of children
32649to report. If @var{from} or @var{to} is less than zero, the range is
32650reset and all children will be reported. Otherwise, children starting
32651at @var{from} (zero-based) and up to and excluding @var{to} will be
32652reported.
32653
32654If a child range is requested, it will only affect the current call to
32655@code{-var-list-children}, but not future calls to @code{-var-update}.
32656For this, you must instead use @code{-var-set-update-range}. The
32657intent of this approach is to enable a front end to implement any
32658update approach it likes; for example, scrolling a view may cause the
32659front end to request more children with @code{-var-list-children}, and
32660then the front end could call @code{-var-set-update-range} with a
32661different range to ensure that future updates are restricted to just
32662the visible items.
32663
b569d230
EZ
32664For each child the following results are returned:
32665
32666@table @var
32667
32668@item name
32669Name of the variable object created for this child.
32670
32671@item exp
32672The expression to be shown to the user by the front end to designate this child.
32673For example this may be the name of a structure member.
32674
0cc7d26f
TT
32675For a dynamic varobj, this value cannot be used to form an
32676expression. There is no way to do this at all with a dynamic varobj.
32677
b569d230
EZ
32678For C/C@t{++} structures there are several pseudo children returned to
32679designate access qualifiers. For these pseudo children @var{exp} is
32680@samp{public}, @samp{private}, or @samp{protected}. In this case the
32681type and value are not present.
32682
0cc7d26f
TT
32683A dynamic varobj will not report the access qualifying
32684pseudo-children, regardless of the language. This information is not
32685available at all with a dynamic varobj.
32686
b569d230 32687@item numchild
0cc7d26f
TT
32688Number of children this child has. For a dynamic varobj, this will be
326890.
b569d230
EZ
32690
32691@item type
8264ba82
AG
32692The type of the child. If @samp{print object}
32693(@pxref{Print Settings, set print object}) is set to @code{on}, the
32694@emph{actual} (derived) type of the object is shown rather than the
32695@emph{declared} one.
b569d230
EZ
32696
32697@item value
32698If values were requested, this is the value.
32699
32700@item thread-id
5d5658a1
PA
32701If this variable object is associated with a thread, this is the
32702thread's global thread id. Otherwise this result is not present.
b569d230
EZ
32703
32704@item frozen
32705If the variable object is frozen, this variable will be present with a value of 1.
c78feb39 32706
9df9dbe0
YQ
32707@item displayhint
32708A dynamic varobj can supply a display hint to the front end. The
32709value comes directly from the Python pretty-printer object's
32710@code{display_hint} method. @xref{Pretty Printing API}.
32711
c78feb39
YQ
32712@item dynamic
32713This attribute will be present and have the value @samp{1} if the
32714varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
32715then this attribute will not be present.
32716
b569d230
EZ
32717@end table
32718
0cc7d26f
TT
32719The result may have its own attributes:
32720
32721@table @samp
32722@item displayhint
32723A dynamic varobj can supply a display hint to the front end. The
32724value comes directly from the Python pretty-printer object's
4c374409 32725@code{display_hint} method. @xref{Pretty Printing API}.
0cc7d26f
TT
32726
32727@item has_more
32728This is an integer attribute which is nonzero if there are children
32729remaining after the end of the selected range.
32730@end table
32731
922fbb7b
AC
32732@subsubheading Example
32733
32734@smallexample
594fe323 32735(gdb)
a2c02241 32736 -var-list-children n
b569d230 32737 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
a2c02241 32738 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
594fe323 32739(gdb)
a2c02241 32740 -var-list-children --all-values n
b569d230 32741 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
a2c02241 32742 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
922fbb7b
AC
32743@end smallexample
32744
922fbb7b 32745
a2c02241
NR
32746@subheading The @code{-var-info-type} Command
32747@findex -var-info-type
922fbb7b 32748
a2c02241
NR
32749@subsubheading Synopsis
32750
32751@smallexample
32752 -var-info-type @var{name}
32753@end smallexample
32754
32755Returns the type of the specified variable @var{name}. The type is
32756returned as a string in the same format as it is output by the
32757@value{GDBN} CLI:
32758
32759@smallexample
32760 type=@var{typename}
32761@end smallexample
32762
32763
32764@subheading The @code{-var-info-expression} Command
32765@findex -var-info-expression
922fbb7b
AC
32766
32767@subsubheading Synopsis
32768
32769@smallexample
a2c02241 32770 -var-info-expression @var{name}
922fbb7b
AC
32771@end smallexample
32772
02142340
VP
32773Returns a string that is suitable for presenting this
32774variable object in user interface. The string is generally
32775not valid expression in the current language, and cannot be evaluated.
32776
32777For example, if @code{a} is an array, and variable object
32778@code{A} was created for @code{a}, then we'll get this output:
922fbb7b 32779
a2c02241 32780@smallexample
02142340
VP
32781(gdb) -var-info-expression A.1
32782^done,lang="C",exp="1"
a2c02241 32783@end smallexample
922fbb7b 32784
a2c02241 32785@noindent
fa4d0c40
YQ
32786Here, the value of @code{lang} is the language name, which can be
32787found in @ref{Supported Languages}.
02142340
VP
32788
32789Note that the output of the @code{-var-list-children} command also
32790includes those expressions, so the @code{-var-info-expression} command
32791is of limited use.
32792
32793@subheading The @code{-var-info-path-expression} Command
32794@findex -var-info-path-expression
32795
32796@subsubheading Synopsis
32797
32798@smallexample
32799 -var-info-path-expression @var{name}
32800@end smallexample
32801
32802Returns an expression that can be evaluated in the current
32803context and will yield the same value that a variable object has.
32804Compare this with the @code{-var-info-expression} command, which
32805result can be used only for UI presentation. Typical use of
32806the @code{-var-info-path-expression} command is creating a
32807watchpoint from a variable object.
32808
0cc7d26f
TT
32809This command is currently not valid for children of a dynamic varobj,
32810and will give an error when invoked on one.
32811
02142340
VP
32812For example, suppose @code{C} is a C@t{++} class, derived from class
32813@code{Base}, and that the @code{Base} class has a member called
32814@code{m_size}. Assume a variable @code{c} is has the type of
32815@code{C} and a variable object @code{C} was created for variable
32816@code{c}. Then, we'll get this output:
32817@smallexample
32818(gdb) -var-info-path-expression C.Base.public.m_size
32819^done,path_expr=((Base)c).m_size)
32820@end smallexample
922fbb7b 32821
a2c02241
NR
32822@subheading The @code{-var-show-attributes} Command
32823@findex -var-show-attributes
922fbb7b 32824
a2c02241 32825@subsubheading Synopsis
922fbb7b 32826
a2c02241
NR
32827@smallexample
32828 -var-show-attributes @var{name}
32829@end smallexample
922fbb7b 32830
a2c02241 32831List attributes of the specified variable object @var{name}:
922fbb7b
AC
32832
32833@smallexample
a2c02241 32834 status=@var{attr} [ ( ,@var{attr} )* ]
922fbb7b
AC
32835@end smallexample
32836
a2c02241
NR
32837@noindent
32838where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
32839
32840@subheading The @code{-var-evaluate-expression} Command
32841@findex -var-evaluate-expression
32842
32843@subsubheading Synopsis
32844
32845@smallexample
de051565 32846 -var-evaluate-expression [-f @var{format-spec}] @var{name}
a2c02241
NR
32847@end smallexample
32848
32849Evaluates the expression that is represented by the specified variable
de051565
MK
32850object and returns its value as a string. The format of the string
32851can be specified with the @samp{-f} option. The possible values of
32852this option are the same as for @code{-var-set-format}
32853(@pxref{-var-set-format}). If the @samp{-f} option is not specified,
32854the current display format will be used. The current display format
32855can be changed using the @code{-var-set-format} command.
a2c02241
NR
32856
32857@smallexample
32858 value=@var{value}
32859@end smallexample
32860
32861Note that one must invoke @code{-var-list-children} for a variable
32862before the value of a child variable can be evaluated.
32863
32864@subheading The @code{-var-assign} Command
32865@findex -var-assign
32866
32867@subsubheading Synopsis
32868
32869@smallexample
32870 -var-assign @var{name} @var{expression}
32871@end smallexample
32872
32873Assigns the value of @var{expression} to the variable object specified
32874by @var{name}. The object must be @samp{editable}. If the variable's
32875value is altered by the assign, the variable will show up in any
32876subsequent @code{-var-update} list.
32877
32878@subsubheading Example
922fbb7b
AC
32879
32880@smallexample
594fe323 32881(gdb)
a2c02241
NR
32882-var-assign var1 3
32883^done,value="3"
594fe323 32884(gdb)
a2c02241
NR
32885-var-update *
32886^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
594fe323 32887(gdb)
922fbb7b
AC
32888@end smallexample
32889
a2c02241
NR
32890@subheading The @code{-var-update} Command
32891@findex -var-update
32892
32893@subsubheading Synopsis
32894
32895@smallexample
32896 -var-update [@var{print-values}] @{@var{name} | "*"@}
32897@end smallexample
32898
c8b2f53c
VP
32899Reevaluate the expressions corresponding to the variable object
32900@var{name} and all its direct and indirect children, and return the
36ece8b3
NR
32901list of variable objects whose values have changed; @var{name} must
32902be a root variable object. Here, ``changed'' means that the result of
32903@code{-var-evaluate-expression} before and after the
32904@code{-var-update} is different. If @samp{*} is used as the variable
9f708cb2
VP
32905object names, all existing variable objects are updated, except
32906for frozen ones (@pxref{-var-set-frozen}). The option
36ece8b3 32907@var{print-values} determines whether both names and values, or just
de051565 32908names are printed. The possible values of this option are the same
36ece8b3
NR
32909as for @code{-var-list-children} (@pxref{-var-list-children}). It is
32910recommended to use the @samp{--all-values} option, to reduce the
32911number of MI commands needed on each program stop.
c8b2f53c 32912
c3b108f7
VP
32913With the @samp{*} parameter, if a variable object is bound to a
32914currently running thread, it will not be updated, without any
32915diagnostic.
a2c02241 32916
0cc7d26f
TT
32917If @code{-var-set-update-range} was previously used on a varobj, then
32918only the selected range of children will be reported.
922fbb7b 32919
0cc7d26f
TT
32920@code{-var-update} reports all the changed varobjs in a tuple named
32921@samp{changelist}.
32922
32923Each item in the change list is itself a tuple holding:
32924
32925@table @samp
32926@item name
32927The name of the varobj.
32928
32929@item value
32930If values were requested for this update, then this field will be
32931present and will hold the value of the varobj.
922fbb7b 32932
0cc7d26f 32933@item in_scope
9f708cb2 32934@anchor{-var-update}
0cc7d26f 32935This field is a string which may take one of three values:
36ece8b3
NR
32936
32937@table @code
32938@item "true"
32939The variable object's current value is valid.
32940
32941@item "false"
32942The variable object does not currently hold a valid value but it may
32943hold one in the future if its associated expression comes back into
32944scope.
32945
32946@item "invalid"
32947The variable object no longer holds a valid value.
32948This can occur when the executable file being debugged has changed,
32949either through recompilation or by using the @value{GDBN} @code{file}
32950command. The front end should normally choose to delete these variable
32951objects.
32952@end table
32953
32954In the future new values may be added to this list so the front should
32955be prepared for this possibility. @xref{GDB/MI Development and Front Ends, ,@sc{GDB/MI} Development and Front Ends}.
32956
0cc7d26f
TT
32957@item type_changed
32958This is only present if the varobj is still valid. If the type
32959changed, then this will be the string @samp{true}; otherwise it will
32960be @samp{false}.
32961
7191c139
JB
32962When a varobj's type changes, its children are also likely to have
32963become incorrect. Therefore, the varobj's children are automatically
32964deleted when this attribute is @samp{true}. Also, the varobj's update
32965range, when set using the @code{-var-set-update-range} command, is
32966unset.
32967
0cc7d26f
TT
32968@item new_type
32969If the varobj's type changed, then this field will be present and will
32970hold the new type.
32971
32972@item new_num_children
32973For a dynamic varobj, if the number of children changed, or if the
32974type changed, this will be the new number of children.
32975
32976The @samp{numchild} field in other varobj responses is generally not
32977valid for a dynamic varobj -- it will show the number of children that
32978@value{GDBN} knows about, but because dynamic varobjs lazily
32979instantiate their children, this will not reflect the number of
32980children which may be available.
32981
32982The @samp{new_num_children} attribute only reports changes to the
32983number of children known by @value{GDBN}. This is the only way to
32984detect whether an update has removed children (which necessarily can
32985only happen at the end of the update range).
32986
32987@item displayhint
32988The display hint, if any.
32989
32990@item has_more
32991This is an integer value, which will be 1 if there are more children
32992available outside the varobj's update range.
32993
32994@item dynamic
32995This attribute will be present and have the value @samp{1} if the
32996varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
32997then this attribute will not be present.
32998
32999@item new_children
33000If new children were added to a dynamic varobj within the selected
33001update range (as set by @code{-var-set-update-range}), then they will
33002be listed in this attribute.
33003@end table
33004
33005@subsubheading Example
33006
33007@smallexample
33008(gdb)
33009-var-assign var1 3
33010^done,value="3"
33011(gdb)
33012-var-update --all-values var1
33013^done,changelist=[@{name="var1",value="3",in_scope="true",
33014type_changed="false"@}]
33015(gdb)
33016@end smallexample
33017
25d5ea92
VP
33018@subheading The @code{-var-set-frozen} Command
33019@findex -var-set-frozen
9f708cb2 33020@anchor{-var-set-frozen}
25d5ea92
VP
33021
33022@subsubheading Synopsis
33023
33024@smallexample
9f708cb2 33025 -var-set-frozen @var{name} @var{flag}
25d5ea92
VP
33026@end smallexample
33027
9f708cb2 33028Set the frozenness flag on the variable object @var{name}. The
25d5ea92 33029@var{flag} parameter should be either @samp{1} to make the variable
9f708cb2 33030frozen or @samp{0} to make it unfrozen. If a variable object is
25d5ea92 33031frozen, then neither itself, nor any of its children, are
9f708cb2 33032implicitly updated by @code{-var-update} of
25d5ea92
VP
33033a parent variable or by @code{-var-update *}. Only
33034@code{-var-update} of the variable itself will update its value and
33035values of its children. After a variable object is unfrozen, it is
33036implicitly updated by all subsequent @code{-var-update} operations.
33037Unfreezing a variable does not update it, only subsequent
33038@code{-var-update} does.
33039
33040@subsubheading Example
33041
33042@smallexample
33043(gdb)
33044-var-set-frozen V 1
33045^done
33046(gdb)
33047@end smallexample
33048
0cc7d26f
TT
33049@subheading The @code{-var-set-update-range} command
33050@findex -var-set-update-range
33051@anchor{-var-set-update-range}
33052
33053@subsubheading Synopsis
33054
33055@smallexample
33056 -var-set-update-range @var{name} @var{from} @var{to}
33057@end smallexample
33058
33059Set the range of children to be returned by future invocations of
33060@code{-var-update}.
33061
33062@var{from} and @var{to} indicate the range of children to report. If
33063@var{from} or @var{to} is less than zero, the range is reset and all
33064children will be reported. Otherwise, children starting at @var{from}
33065(zero-based) and up to and excluding @var{to} will be reported.
33066
33067@subsubheading Example
33068
33069@smallexample
33070(gdb)
33071-var-set-update-range V 1 2
33072^done
33073@end smallexample
33074
b6313243
TT
33075@subheading The @code{-var-set-visualizer} command
33076@findex -var-set-visualizer
33077@anchor{-var-set-visualizer}
33078
33079@subsubheading Synopsis
33080
33081@smallexample
33082 -var-set-visualizer @var{name} @var{visualizer}
33083@end smallexample
33084
33085Set a visualizer for the variable object @var{name}.
33086
33087@var{visualizer} is the visualizer to use. The special value
33088@samp{None} means to disable any visualizer in use.
33089
33090If not @samp{None}, @var{visualizer} must be a Python expression.
33091This expression must evaluate to a callable object which accepts a
33092single argument. @value{GDBN} will call this object with the value of
33093the varobj @var{name} as an argument (this is done so that the same
33094Python pretty-printing code can be used for both the CLI and MI).
33095When called, this object must return an object which conforms to the
4c374409 33096pretty-printing interface (@pxref{Pretty Printing API}).
b6313243
TT
33097
33098The pre-defined function @code{gdb.default_visualizer} may be used to
33099select a visualizer by following the built-in process
33100(@pxref{Selecting Pretty-Printers}). This is done automatically when
33101a varobj is created, and so ordinarily is not needed.
33102
33103This feature is only available if Python support is enabled. The MI
d192b373 33104command @code{-list-features} (@pxref{GDB/MI Support Commands})
b6313243
TT
33105can be used to check this.
33106
33107@subsubheading Example
33108
33109Resetting the visualizer:
33110
33111@smallexample
33112(gdb)
33113-var-set-visualizer V None
33114^done
33115@end smallexample
33116
33117Reselecting the default (type-based) visualizer:
33118
33119@smallexample
33120(gdb)
33121-var-set-visualizer V gdb.default_visualizer
33122^done
33123@end smallexample
33124
33125Suppose @code{SomeClass} is a visualizer class. A lambda expression
33126can be used to instantiate this class for a varobj:
33127
33128@smallexample
33129(gdb)
33130-var-set-visualizer V "lambda val: SomeClass()"
33131^done
33132@end smallexample
25d5ea92 33133
a2c02241
NR
33134@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33135@node GDB/MI Data Manipulation
33136@section @sc{gdb/mi} Data Manipulation
922fbb7b 33137
a2c02241
NR
33138@cindex data manipulation, in @sc{gdb/mi}
33139@cindex @sc{gdb/mi}, data manipulation
33140This section describes the @sc{gdb/mi} commands that manipulate data:
33141examine memory and registers, evaluate expressions, etc.
33142
a86c90e6
SM
33143For details about what an addressable memory unit is,
33144@pxref{addressable memory unit}.
33145
a2c02241
NR
33146@c REMOVED FROM THE INTERFACE.
33147@c @subheading -data-assign
33148@c Change the value of a program variable. Plenty of side effects.
79a6e687 33149@c @subsubheading GDB Command
a2c02241
NR
33150@c set variable
33151@c @subsubheading Example
33152@c N.A.
33153
33154@subheading The @code{-data-disassemble} Command
33155@findex -data-disassemble
922fbb7b
AC
33156
33157@subsubheading Synopsis
33158
33159@smallexample
a2c02241
NR
33160 -data-disassemble
33161 [ -s @var{start-addr} -e @var{end-addr} ]
26fb3983 33162 | [ -a @var{addr} ]
a2c02241
NR
33163 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
33164 -- @var{mode}
922fbb7b
AC
33165@end smallexample
33166
a2c02241
NR
33167@noindent
33168Where:
33169
33170@table @samp
33171@item @var{start-addr}
33172is the beginning address (or @code{$pc})
33173@item @var{end-addr}
33174is the end address
26fb3983
JV
33175@item @var{addr}
33176is an address anywhere within (or the name of) the function to
33177disassemble. If an address is specified, the whole function
33178surrounding that address will be disassembled. If a name is
33179specified, the whole function with that name will be disassembled.
a2c02241
NR
33180@item @var{filename}
33181is the name of the file to disassemble
33182@item @var{linenum}
33183is the line number to disassemble around
33184@item @var{lines}
d3e8051b 33185is the number of disassembly lines to be produced. If it is -1,
a2c02241
NR
33186the whole function will be disassembled, in case no @var{end-addr} is
33187specified. If @var{end-addr} is specified as a non-zero value, and
33188@var{lines} is lower than the number of disassembly lines between
33189@var{start-addr} and @var{end-addr}, only @var{lines} lines are
33190displayed; if @var{lines} is higher than the number of lines between
33191@var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
33192are displayed.
33193@item @var{mode}
6ff0ba5f
DE
33194is one of:
33195@itemize @bullet
33196@item 0 disassembly only
33197@item 1 mixed source and disassembly (deprecated)
33198@item 2 disassembly with raw opcodes
33199@item 3 mixed source and disassembly with raw opcodes (deprecated)
33200@item 4 mixed source and disassembly
33201@item 5 mixed source and disassembly with raw opcodes
33202@end itemize
33203
33204Modes 1 and 3 are deprecated. The output is ``source centric''
33205which hasn't proved useful in practice.
33206@xref{Machine Code}, for a discussion of the difference between
33207@code{/m} and @code{/s} output of the @code{disassemble} command.
a2c02241
NR
33208@end table
33209
33210@subsubheading Result
33211
ed8a1c2d
AB
33212The result of the @code{-data-disassemble} command will be a list named
33213@samp{asm_insns}, the contents of this list depend on the @var{mode}
33214used with the @code{-data-disassemble} command.
a2c02241 33215
ed8a1c2d
AB
33216For modes 0 and 2 the @samp{asm_insns} list contains tuples with the
33217following fields:
33218
33219@table @code
33220@item address
33221The address at which this instruction was disassembled.
33222
33223@item func-name
33224The name of the function this instruction is within.
33225
33226@item offset
33227The decimal offset in bytes from the start of @samp{func-name}.
33228
33229@item inst
33230The text disassembly for this @samp{address}.
33231
33232@item opcodes
6ff0ba5f 33233This field is only present for modes 2, 3 and 5. This contains the raw opcode
ed8a1c2d
AB
33234bytes for the @samp{inst} field.
33235
33236@end table
33237
6ff0ba5f 33238For modes 1, 3, 4 and 5 the @samp{asm_insns} list contains tuples named
ed8a1c2d 33239@samp{src_and_asm_line}, each of which has the following fields:
a2c02241 33240
ed8a1c2d
AB
33241@table @code
33242@item line
33243The line number within @samp{file}.
33244
33245@item file
33246The file name from the compilation unit. This might be an absolute
33247file name or a relative file name depending on the compile command
33248used.
33249
33250@item fullname
f35a17b5
JK
33251Absolute file name of @samp{file}. It is converted to a canonical form
33252using the source file search path
33253(@pxref{Source Path, ,Specifying Source Directories})
33254and after resolving all the symbolic links.
33255
33256If the source file is not found this field will contain the path as
33257present in the debug information.
ed8a1c2d
AB
33258
33259@item line_asm_insn
33260This is a list of tuples containing the disassembly for @samp{line} in
33261@samp{file}. The fields of each tuple are the same as for
33262@code{-data-disassemble} in @var{mode} 0 and 2, so @samp{address},
33263@samp{func-name}, @samp{offset}, @samp{inst}, and optionally
33264@samp{opcodes}.
33265
33266@end table
33267
33268Note that whatever included in the @samp{inst} field, is not
33269manipulated directly by @sc{gdb/mi}, i.e., it is not possible to
33270adjust its format.
922fbb7b
AC
33271
33272@subsubheading @value{GDBN} Command
33273
ed8a1c2d 33274The corresponding @value{GDBN} command is @samp{disassemble}.
922fbb7b
AC
33275
33276@subsubheading Example
33277
a2c02241
NR
33278Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
33279
922fbb7b 33280@smallexample
594fe323 33281(gdb)
a2c02241
NR
33282-data-disassemble -s $pc -e "$pc + 20" -- 0
33283^done,
33284asm_insns=[
33285@{address="0x000107c0",func-name="main",offset="4",
33286inst="mov 2, %o0"@},
33287@{address="0x000107c4",func-name="main",offset="8",
33288inst="sethi %hi(0x11800), %o2"@},
33289@{address="0x000107c8",func-name="main",offset="12",
33290inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
33291@{address="0x000107cc",func-name="main",offset="16",
33292inst="sethi %hi(0x11800), %o2"@},
33293@{address="0x000107d0",func-name="main",offset="20",
33294inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
594fe323 33295(gdb)
a2c02241
NR
33296@end smallexample
33297
33298Disassemble the whole @code{main} function. Line 32 is part of
33299@code{main}.
33300
33301@smallexample
33302-data-disassemble -f basics.c -l 32 -- 0
33303^done,asm_insns=[
33304@{address="0x000107bc",func-name="main",offset="0",
33305inst="save %sp, -112, %sp"@},
33306@{address="0x000107c0",func-name="main",offset="4",
33307inst="mov 2, %o0"@},
33308@{address="0x000107c4",func-name="main",offset="8",
33309inst="sethi %hi(0x11800), %o2"@},
33310[@dots{}]
33311@{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
33312@{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
594fe323 33313(gdb)
922fbb7b
AC
33314@end smallexample
33315
a2c02241 33316Disassemble 3 instructions from the start of @code{main}:
922fbb7b 33317
a2c02241 33318@smallexample
594fe323 33319(gdb)
a2c02241
NR
33320-data-disassemble -f basics.c -l 32 -n 3 -- 0
33321^done,asm_insns=[
33322@{address="0x000107bc",func-name="main",offset="0",
33323inst="save %sp, -112, %sp"@},
33324@{address="0x000107c0",func-name="main",offset="4",
33325inst="mov 2, %o0"@},
33326@{address="0x000107c4",func-name="main",offset="8",
33327inst="sethi %hi(0x11800), %o2"@}]
594fe323 33328(gdb)
a2c02241
NR
33329@end smallexample
33330
33331Disassemble 3 instructions from the start of @code{main} in mixed mode:
33332
33333@smallexample
594fe323 33334(gdb)
a2c02241
NR
33335-data-disassemble -f basics.c -l 32 -n 3 -- 1
33336^done,asm_insns=[
33337src_and_asm_line=@{line="31",
ed8a1c2d
AB
33338file="../../../src/gdb/testsuite/gdb.mi/basics.c",
33339fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
33340line_asm_insn=[@{address="0x000107bc",
33341func-name="main",offset="0",inst="save %sp, -112, %sp"@}]@},
a2c02241 33342src_and_asm_line=@{line="32",
ed8a1c2d
AB
33343file="../../../src/gdb/testsuite/gdb.mi/basics.c",
33344fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
33345line_asm_insn=[@{address="0x000107c0",
33346func-name="main",offset="4",inst="mov 2, %o0"@},
a2c02241
NR
33347@{address="0x000107c4",func-name="main",offset="8",
33348inst="sethi %hi(0x11800), %o2"@}]@}]
594fe323 33349(gdb)
a2c02241
NR
33350@end smallexample
33351
33352
33353@subheading The @code{-data-evaluate-expression} Command
33354@findex -data-evaluate-expression
922fbb7b
AC
33355
33356@subsubheading Synopsis
33357
33358@smallexample
a2c02241 33359 -data-evaluate-expression @var{expr}
922fbb7b
AC
33360@end smallexample
33361
a2c02241
NR
33362Evaluate @var{expr} as an expression. The expression could contain an
33363inferior function call. The function call will execute synchronously.
33364If the expression contains spaces, it must be enclosed in double quotes.
922fbb7b
AC
33365
33366@subsubheading @value{GDBN} Command
33367
a2c02241
NR
33368The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
33369@samp{call}. In @code{gdbtk} only, there's a corresponding
33370@samp{gdb_eval} command.
922fbb7b
AC
33371
33372@subsubheading Example
33373
a2c02241
NR
33374In the following example, the numbers that precede the commands are the
33375@dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
33376Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
33377output.
33378
922fbb7b 33379@smallexample
a2c02241
NR
33380211-data-evaluate-expression A
33381211^done,value="1"
594fe323 33382(gdb)
a2c02241
NR
33383311-data-evaluate-expression &A
33384311^done,value="0xefffeb7c"
594fe323 33385(gdb)
a2c02241
NR
33386411-data-evaluate-expression A+3
33387411^done,value="4"
594fe323 33388(gdb)
a2c02241
NR
33389511-data-evaluate-expression "A + 3"
33390511^done,value="4"
594fe323 33391(gdb)
a2c02241 33392@end smallexample
922fbb7b
AC
33393
33394
a2c02241
NR
33395@subheading The @code{-data-list-changed-registers} Command
33396@findex -data-list-changed-registers
922fbb7b
AC
33397
33398@subsubheading Synopsis
33399
33400@smallexample
a2c02241 33401 -data-list-changed-registers
922fbb7b
AC
33402@end smallexample
33403
a2c02241 33404Display a list of the registers that have changed.
922fbb7b
AC
33405
33406@subsubheading @value{GDBN} Command
33407
a2c02241
NR
33408@value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
33409has the corresponding command @samp{gdb_changed_register_list}.
922fbb7b
AC
33410
33411@subsubheading Example
922fbb7b 33412
a2c02241 33413On a PPC MBX board:
922fbb7b
AC
33414
33415@smallexample
594fe323 33416(gdb)
a2c02241
NR
33417-exec-continue
33418^running
922fbb7b 33419
594fe323 33420(gdb)
a47ec5fe
AR
33421*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",frame=@{
33422func="main",args=[],file="try.c",fullname="/home/foo/bar/try.c",
6d52907e 33423line="5",arch="powerpc"@}
594fe323 33424(gdb)
a2c02241
NR
33425-data-list-changed-registers
33426^done,changed-registers=["0","1","2","4","5","6","7","8","9",
33427"10","11","13","14","15","16","17","18","19","20","21","22","23",
33428"24","25","26","27","28","30","31","64","65","66","67","69"]
594fe323 33429(gdb)
a2c02241 33430@end smallexample
922fbb7b
AC
33431
33432
a2c02241
NR
33433@subheading The @code{-data-list-register-names} Command
33434@findex -data-list-register-names
922fbb7b
AC
33435
33436@subsubheading Synopsis
33437
33438@smallexample
a2c02241 33439 -data-list-register-names [ ( @var{regno} )+ ]
922fbb7b
AC
33440@end smallexample
33441
a2c02241
NR
33442Show a list of register names for the current target. If no arguments
33443are given, it shows a list of the names of all the registers. If
33444integer numbers are given as arguments, it will print a list of the
33445names of the registers corresponding to the arguments. To ensure
33446consistency between a register name and its number, the output list may
33447include empty register names.
922fbb7b
AC
33448
33449@subsubheading @value{GDBN} Command
33450
a2c02241
NR
33451@value{GDBN} does not have a command which corresponds to
33452@samp{-data-list-register-names}. In @code{gdbtk} there is a
33453corresponding command @samp{gdb_regnames}.
922fbb7b
AC
33454
33455@subsubheading Example
922fbb7b 33456
a2c02241
NR
33457For the PPC MBX board:
33458@smallexample
594fe323 33459(gdb)
a2c02241
NR
33460-data-list-register-names
33461^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
33462"r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
33463"r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
33464"r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
33465"f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
33466"f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
33467"", "pc","ps","cr","lr","ctr","xer"]
594fe323 33468(gdb)
a2c02241
NR
33469-data-list-register-names 1 2 3
33470^done,register-names=["r1","r2","r3"]
594fe323 33471(gdb)
a2c02241 33472@end smallexample
922fbb7b 33473
a2c02241
NR
33474@subheading The @code{-data-list-register-values} Command
33475@findex -data-list-register-values
922fbb7b
AC
33476
33477@subsubheading Synopsis
33478
33479@smallexample
c898adb7
YQ
33480 -data-list-register-values
33481 [ @code{--skip-unavailable} ] @var{fmt} [ ( @var{regno} )*]
922fbb7b
AC
33482@end smallexample
33483
697aa1b7
EZ
33484Display the registers' contents. The format according to which the
33485registers' contents are to be returned is given by @var{fmt}, followed
33486by an optional list of numbers specifying the registers to display. A
33487missing list of numbers indicates that the contents of all the
33488registers must be returned. The @code{--skip-unavailable} option
33489indicates that only the available registers are to be returned.
a2c02241
NR
33490
33491Allowed formats for @var{fmt} are:
33492
33493@table @code
33494@item x
33495Hexadecimal
33496@item o
33497Octal
33498@item t
33499Binary
33500@item d
33501Decimal
33502@item r
33503Raw
33504@item N
33505Natural
33506@end table
922fbb7b
AC
33507
33508@subsubheading @value{GDBN} Command
33509
a2c02241
NR
33510The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
33511all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
922fbb7b
AC
33512
33513@subsubheading Example
922fbb7b 33514
a2c02241
NR
33515For a PPC MBX board (note: line breaks are for readability only, they
33516don't appear in the actual output):
33517
33518@smallexample
594fe323 33519(gdb)
a2c02241
NR
33520-data-list-register-values r 64 65
33521^done,register-values=[@{number="64",value="0xfe00a300"@},
33522@{number="65",value="0x00029002"@}]
594fe323 33523(gdb)
a2c02241
NR
33524-data-list-register-values x
33525^done,register-values=[@{number="0",value="0xfe0043c8"@},
33526@{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
33527@{number="3",value="0x0"@},@{number="4",value="0xa"@},
33528@{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
33529@{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
33530@{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
33531@{number="11",value="0x1"@},@{number="12",value="0x0"@},
33532@{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
33533@{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
33534@{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
33535@{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
33536@{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
33537@{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
33538@{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
33539@{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
33540@{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
33541@{number="31",value="0x0"@},@{number="32",value="0x0"@},
33542@{number="33",value="0x0"@},@{number="34",value="0x0"@},
33543@{number="35",value="0x0"@},@{number="36",value="0x0"@},
33544@{number="37",value="0x0"@},@{number="38",value="0x0"@},
33545@{number="39",value="0x0"@},@{number="40",value="0x0"@},
33546@{number="41",value="0x0"@},@{number="42",value="0x0"@},
33547@{number="43",value="0x0"@},@{number="44",value="0x0"@},
33548@{number="45",value="0x0"@},@{number="46",value="0x0"@},
33549@{number="47",value="0x0"@},@{number="48",value="0x0"@},
33550@{number="49",value="0x0"@},@{number="50",value="0x0"@},
33551@{number="51",value="0x0"@},@{number="52",value="0x0"@},
33552@{number="53",value="0x0"@},@{number="54",value="0x0"@},
33553@{number="55",value="0x0"@},@{number="56",value="0x0"@},
33554@{number="57",value="0x0"@},@{number="58",value="0x0"@},
33555@{number="59",value="0x0"@},@{number="60",value="0x0"@},
33556@{number="61",value="0x0"@},@{number="62",value="0x0"@},
33557@{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
33558@{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
33559@{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
33560@{number="69",value="0x20002b03"@}]
594fe323 33561(gdb)
a2c02241 33562@end smallexample
922fbb7b 33563
a2c02241
NR
33564
33565@subheading The @code{-data-read-memory} Command
33566@findex -data-read-memory
922fbb7b 33567
8dedea02
VP
33568This command is deprecated, use @code{-data-read-memory-bytes} instead.
33569
922fbb7b
AC
33570@subsubheading Synopsis
33571
33572@smallexample
a2c02241
NR
33573 -data-read-memory [ -o @var{byte-offset} ]
33574 @var{address} @var{word-format} @var{word-size}
33575 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
922fbb7b
AC
33576@end smallexample
33577
a2c02241
NR
33578@noindent
33579where:
922fbb7b 33580
a2c02241
NR
33581@table @samp
33582@item @var{address}
33583An expression specifying the address of the first memory word to be
33584read. Complex expressions containing embedded white space should be
33585quoted using the C convention.
922fbb7b 33586
a2c02241
NR
33587@item @var{word-format}
33588The format to be used to print the memory words. The notation is the
33589same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
79a6e687 33590,Output Formats}).
922fbb7b 33591
a2c02241
NR
33592@item @var{word-size}
33593The size of each memory word in bytes.
922fbb7b 33594
a2c02241
NR
33595@item @var{nr-rows}
33596The number of rows in the output table.
922fbb7b 33597
a2c02241
NR
33598@item @var{nr-cols}
33599The number of columns in the output table.
922fbb7b 33600
a2c02241
NR
33601@item @var{aschar}
33602If present, indicates that each row should include an @sc{ascii} dump. The
33603value of @var{aschar} is used as a padding character when a byte is not a
33604member of the printable @sc{ascii} character set (printable @sc{ascii}
33605characters are those whose code is between 32 and 126, inclusively).
922fbb7b 33606
a2c02241
NR
33607@item @var{byte-offset}
33608An offset to add to the @var{address} before fetching memory.
33609@end table
922fbb7b 33610
a2c02241
NR
33611This command displays memory contents as a table of @var{nr-rows} by
33612@var{nr-cols} words, each word being @var{word-size} bytes. In total,
33613@code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
33614(returned as @samp{total-bytes}). Should less than the requested number
33615of bytes be returned by the target, the missing words are identified
33616using @samp{N/A}. The number of bytes read from the target is returned
33617in @samp{nr-bytes} and the starting address used to read memory in
33618@samp{addr}.
33619
33620The address of the next/previous row or page is available in
33621@samp{next-row} and @samp{prev-row}, @samp{next-page} and
33622@samp{prev-page}.
922fbb7b
AC
33623
33624@subsubheading @value{GDBN} Command
33625
a2c02241
NR
33626The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
33627@samp{gdb_get_mem} memory read command.
922fbb7b
AC
33628
33629@subsubheading Example
32e7087d 33630
a2c02241
NR
33631Read six bytes of memory starting at @code{bytes+6} but then offset by
33632@code{-6} bytes. Format as three rows of two columns. One byte per
33633word. Display each word in hex.
32e7087d
JB
33634
33635@smallexample
594fe323 33636(gdb)
a2c02241
NR
336379-data-read-memory -o -6 -- bytes+6 x 1 3 2
336389^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
33639next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
33640prev-page="0x0000138a",memory=[
33641@{addr="0x00001390",data=["0x00","0x01"]@},
33642@{addr="0x00001392",data=["0x02","0x03"]@},
33643@{addr="0x00001394",data=["0x04","0x05"]@}]
594fe323 33644(gdb)
32e7087d
JB
33645@end smallexample
33646
a2c02241
NR
33647Read two bytes of memory starting at address @code{shorts + 64} and
33648display as a single word formatted in decimal.
32e7087d 33649
32e7087d 33650@smallexample
594fe323 33651(gdb)
a2c02241
NR
336525-data-read-memory shorts+64 d 2 1 1
336535^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
33654next-row="0x00001512",prev-row="0x0000150e",
33655next-page="0x00001512",prev-page="0x0000150e",memory=[
33656@{addr="0x00001510",data=["128"]@}]
594fe323 33657(gdb)
32e7087d
JB
33658@end smallexample
33659
a2c02241
NR
33660Read thirty two bytes of memory starting at @code{bytes+16} and format
33661as eight rows of four columns. Include a string encoding with @samp{x}
33662used as the non-printable character.
922fbb7b
AC
33663
33664@smallexample
594fe323 33665(gdb)
a2c02241
NR
336664-data-read-memory bytes+16 x 1 8 4 x
336674^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
33668next-row="0x000013c0",prev-row="0x0000139c",
33669next-page="0x000013c0",prev-page="0x00001380",memory=[
33670@{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
33671@{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
33672@{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
33673@{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
33674@{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
33675@{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
33676@{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
33677@{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
594fe323 33678(gdb)
922fbb7b
AC
33679@end smallexample
33680
8dedea02
VP
33681@subheading The @code{-data-read-memory-bytes} Command
33682@findex -data-read-memory-bytes
33683
33684@subsubheading Synopsis
33685
33686@smallexample
a86c90e6 33687 -data-read-memory-bytes [ -o @var{offset} ]
8dedea02
VP
33688 @var{address} @var{count}
33689@end smallexample
33690
33691@noindent
33692where:
33693
33694@table @samp
33695@item @var{address}
a86c90e6
SM
33696An expression specifying the address of the first addressable memory unit
33697to be read. Complex expressions containing embedded white space should be
8dedea02
VP
33698quoted using the C convention.
33699
33700@item @var{count}
a86c90e6
SM
33701The number of addressable memory units to read. This should be an integer
33702literal.
8dedea02 33703
a86c90e6
SM
33704@item @var{offset}
33705The offset relative to @var{address} at which to start reading. This
33706should be an integer literal. This option is provided so that a frontend
33707is not required to first evaluate address and then perform address
33708arithmetics itself.
8dedea02
VP
33709
33710@end table
33711
33712This command attempts to read all accessible memory regions in the
33713specified range. First, all regions marked as unreadable in the memory
33714map (if one is defined) will be skipped. @xref{Memory Region
33715Attributes}. Second, @value{GDBN} will attempt to read the remaining
33716regions. For each one, if reading full region results in an errors,
33717@value{GDBN} will try to read a subset of the region.
33718
a86c90e6
SM
33719In general, every single memory unit in the region may be readable or not,
33720and the only way to read every readable unit is to try a read at
8dedea02 33721every address, which is not practical. Therefore, @value{GDBN} will
a86c90e6 33722attempt to read all accessible memory units at either beginning or the end
8dedea02 33723of the region, using a binary division scheme. This heuristic works
6b92c0d3 33724well for reading across a memory map boundary. Note that if a region
8dedea02
VP
33725has a readable range that is neither at the beginning or the end,
33726@value{GDBN} will not read it.
33727
33728The result record (@pxref{GDB/MI Result Records}) that is output of
33729the command includes a field named @samp{memory} whose content is a
33730list of tuples. Each tuple represent a successfully read memory block
33731and has the following fields:
33732
33733@table @code
33734@item begin
33735The start address of the memory block, as hexadecimal literal.
33736
33737@item end
33738The end address of the memory block, as hexadecimal literal.
33739
33740@item offset
33741The offset of the memory block, as hexadecimal literal, relative to
33742the start address passed to @code{-data-read-memory-bytes}.
33743
33744@item contents
33745The contents of the memory block, in hex.
33746
33747@end table
33748
33749
33750
33751@subsubheading @value{GDBN} Command
33752
33753The corresponding @value{GDBN} command is @samp{x}.
33754
33755@subsubheading Example
33756
33757@smallexample
33758(gdb)
33759-data-read-memory-bytes &a 10
33760^done,memory=[@{begin="0xbffff154",offset="0x00000000",
33761 end="0xbffff15e",
33762 contents="01000000020000000300"@}]
33763(gdb)
33764@end smallexample
33765
33766
33767@subheading The @code{-data-write-memory-bytes} Command
33768@findex -data-write-memory-bytes
33769
33770@subsubheading Synopsis
33771
33772@smallexample
33773 -data-write-memory-bytes @var{address} @var{contents}
62747a60 33774 -data-write-memory-bytes @var{address} @var{contents} @r{[}@var{count}@r{]}
8dedea02
VP
33775@end smallexample
33776
33777@noindent
33778where:
33779
33780@table @samp
33781@item @var{address}
a86c90e6
SM
33782An expression specifying the address of the first addressable memory unit
33783to be written. Complex expressions containing embedded white space should
33784be quoted using the C convention.
8dedea02
VP
33785
33786@item @var{contents}
a86c90e6
SM
33787The hex-encoded data to write. It is an error if @var{contents} does
33788not represent an integral number of addressable memory units.
8dedea02 33789
62747a60 33790@item @var{count}
a86c90e6
SM
33791Optional argument indicating the number of addressable memory units to be
33792written. If @var{count} is greater than @var{contents}' length,
33793@value{GDBN} will repeatedly write @var{contents} until it fills
33794@var{count} memory units.
62747a60 33795
8dedea02
VP
33796@end table
33797
33798@subsubheading @value{GDBN} Command
33799
33800There's no corresponding @value{GDBN} command.
33801
33802@subsubheading Example
33803
33804@smallexample
33805(gdb)
33806-data-write-memory-bytes &a "aabbccdd"
33807^done
33808(gdb)
33809@end smallexample
33810
62747a60
TT
33811@smallexample
33812(gdb)
33813-data-write-memory-bytes &a "aabbccdd" 16e
33814^done
33815(gdb)
33816@end smallexample
8dedea02 33817
a2c02241
NR
33818@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33819@node GDB/MI Tracepoint Commands
33820@section @sc{gdb/mi} Tracepoint Commands
922fbb7b 33821
18148017
VP
33822The commands defined in this section implement MI support for
33823tracepoints. For detailed introduction, see @ref{Tracepoints}.
33824
33825@subheading The @code{-trace-find} Command
33826@findex -trace-find
33827
33828@subsubheading Synopsis
33829
33830@smallexample
33831 -trace-find @var{mode} [@var{parameters}@dots{}]
33832@end smallexample
33833
33834Find a trace frame using criteria defined by @var{mode} and
33835@var{parameters}. The following table lists permissible
33836modes and their parameters. For details of operation, see @ref{tfind}.
33837
33838@table @samp
33839
33840@item none
33841No parameters are required. Stops examining trace frames.
33842
33843@item frame-number
33844An integer is required as parameter. Selects tracepoint frame with
33845that index.
33846
33847@item tracepoint-number
33848An integer is required as parameter. Finds next
33849trace frame that corresponds to tracepoint with the specified number.
33850
33851@item pc
33852An address is required as parameter. Finds
33853next trace frame that corresponds to any tracepoint at the specified
33854address.
33855
33856@item pc-inside-range
33857Two addresses are required as parameters. Finds next trace
33858frame that corresponds to a tracepoint at an address inside the
33859specified range. Both bounds are considered to be inside the range.
33860
33861@item pc-outside-range
33862Two addresses are required as parameters. Finds
33863next trace frame that corresponds to a tracepoint at an address outside
33864the specified range. Both bounds are considered to be inside the range.
33865
33866@item line
33867Line specification is required as parameter. @xref{Specify Location}.
33868Finds next trace frame that corresponds to a tracepoint at
33869the specified location.
33870
33871@end table
33872
33873If @samp{none} was passed as @var{mode}, the response does not
33874have fields. Otherwise, the response may have the following fields:
33875
33876@table @samp
33877@item found
33878This field has either @samp{0} or @samp{1} as the value, depending
33879on whether a matching tracepoint was found.
33880
33881@item traceframe
33882The index of the found traceframe. This field is present iff
33883the @samp{found} field has value of @samp{1}.
33884
33885@item tracepoint
33886The index of the found tracepoint. This field is present iff
33887the @samp{found} field has value of @samp{1}.
33888
33889@item frame
33890The information about the frame corresponding to the found trace
33891frame. This field is present only if a trace frame was found.
cd64ee31 33892@xref{GDB/MI Frame Information}, for description of this field.
18148017
VP
33893
33894@end table
33895
7d13fe92
SS
33896@subsubheading @value{GDBN} Command
33897
33898The corresponding @value{GDBN} command is @samp{tfind}.
33899
18148017
VP
33900@subheading -trace-define-variable
33901@findex -trace-define-variable
33902
33903@subsubheading Synopsis
33904
33905@smallexample
33906 -trace-define-variable @var{name} [ @var{value} ]
33907@end smallexample
33908
33909Create trace variable @var{name} if it does not exist. If
33910@var{value} is specified, sets the initial value of the specified
33911trace variable to that value. Note that the @var{name} should start
33912with the @samp{$} character.
33913
7d13fe92
SS
33914@subsubheading @value{GDBN} Command
33915
33916The corresponding @value{GDBN} command is @samp{tvariable}.
33917
dc673c81
YQ
33918@subheading The @code{-trace-frame-collected} Command
33919@findex -trace-frame-collected
33920
33921@subsubheading Synopsis
33922
33923@smallexample
33924 -trace-frame-collected
33925 [--var-print-values @var{var_pval}]
33926 [--comp-print-values @var{comp_pval}]
33927 [--registers-format @var{regformat}]
33928 [--memory-contents]
33929@end smallexample
33930
33931This command returns the set of collected objects, register names,
33932trace state variable names, memory ranges and computed expressions
33933that have been collected at a particular trace frame. The optional
33934parameters to the command affect the output format in different ways.
33935See the output description table below for more details.
33936
33937The reported names can be used in the normal manner to create
33938varobjs and inspect the objects themselves. The items returned by
33939this command are categorized so that it is clear which is a variable,
33940which is a register, which is a trace state variable, which is a
33941memory range and which is a computed expression.
33942
33943For instance, if the actions were
33944@smallexample
33945collect myVar, myArray[myIndex], myObj.field, myPtr->field, myCount + 2
33946collect *(int*)0xaf02bef0@@40
33947@end smallexample
33948
33949@noindent
33950the object collected in its entirety would be @code{myVar}. The
33951object @code{myArray} would be partially collected, because only the
33952element at index @code{myIndex} would be collected. The remaining
33953objects would be computed expressions.
33954
33955An example output would be:
33956
33957@smallexample
33958(gdb)
33959-trace-frame-collected
33960^done,
33961 explicit-variables=[@{name="myVar",value="1"@}],
33962 computed-expressions=[@{name="myArray[myIndex]",value="0"@},
33963 @{name="myObj.field",value="0"@},
33964 @{name="myPtr->field",value="1"@},
33965 @{name="myCount + 2",value="3"@},
33966 @{name="$tvar1 + 1",value="43970027"@}],
33967 registers=[@{number="0",value="0x7fe2c6e79ec8"@},
33968 @{number="1",value="0x0"@},
33969 @{number="2",value="0x4"@},
33970 ...
33971 @{number="125",value="0x0"@}],
33972 tvars=[@{name="$tvar1",current="43970026"@}],
33973 memory=[@{address="0x0000000000602264",length="4"@},
33974 @{address="0x0000000000615bc0",length="4"@}]
33975(gdb)
33976@end smallexample
33977
33978Where:
33979
33980@table @code
33981@item explicit-variables
33982The set of objects that have been collected in their entirety (as
33983opposed to collecting just a few elements of an array or a few struct
33984members). For each object, its name and value are printed.
33985The @code{--var-print-values} option affects how or whether the value
33986field is output. If @var{var_pval} is 0, then print only the names;
33987if it is 1, print also their values; and if it is 2, print the name,
33988type and value for simple data types, and the name and type for
33989arrays, structures and unions.
33990
33991@item computed-expressions
33992The set of computed expressions that have been collected at the
33993current trace frame. The @code{--comp-print-values} option affects
33994this set like the @code{--var-print-values} option affects the
33995@code{explicit-variables} set. See above.
33996
33997@item registers
33998The registers that have been collected at the current trace frame.
33999For each register collected, the name and current value are returned.
34000The value is formatted according to the @code{--registers-format}
34001option. See the @command{-data-list-register-values} command for a
34002list of the allowed formats. The default is @samp{x}.
34003
34004@item tvars
34005The trace state variables that have been collected at the current
34006trace frame. For each trace state variable collected, the name and
34007current value are returned.
34008
34009@item memory
34010The set of memory ranges that have been collected at the current trace
34011frame. Its content is a list of tuples. Each tuple represents a
34012collected memory range and has the following fields:
34013
34014@table @code
34015@item address
34016The start address of the memory range, as hexadecimal literal.
34017
34018@item length
34019The length of the memory range, as decimal literal.
34020
34021@item contents
34022The contents of the memory block, in hex. This field is only present
34023if the @code{--memory-contents} option is specified.
34024
34025@end table
34026
34027@end table
34028
34029@subsubheading @value{GDBN} Command
34030
34031There is no corresponding @value{GDBN} command.
34032
34033@subsubheading Example
34034
18148017
VP
34035@subheading -trace-list-variables
34036@findex -trace-list-variables
922fbb7b 34037
18148017 34038@subsubheading Synopsis
922fbb7b 34039
18148017
VP
34040@smallexample
34041 -trace-list-variables
34042@end smallexample
922fbb7b 34043
18148017
VP
34044Return a table of all defined trace variables. Each element of the
34045table has the following fields:
922fbb7b 34046
18148017
VP
34047@table @samp
34048@item name
34049The name of the trace variable. This field is always present.
922fbb7b 34050
18148017
VP
34051@item initial
34052The initial value. This is a 64-bit signed integer. This
34053field is always present.
922fbb7b 34054
18148017
VP
34055@item current
34056The value the trace variable has at the moment. This is a 64-bit
34057signed integer. This field is absent iff current value is
34058not defined, for example if the trace was never run, or is
34059presently running.
922fbb7b 34060
18148017 34061@end table
922fbb7b 34062
7d13fe92
SS
34063@subsubheading @value{GDBN} Command
34064
34065The corresponding @value{GDBN} command is @samp{tvariables}.
34066
18148017 34067@subsubheading Example
922fbb7b 34068
18148017
VP
34069@smallexample
34070(gdb)
34071-trace-list-variables
34072^done,trace-variables=@{nr_rows="1",nr_cols="3",
34073hdr=[@{width="15",alignment="-1",col_name="name",colhdr="Name"@},
34074 @{width="11",alignment="-1",col_name="initial",colhdr="Initial"@},
34075 @{width="11",alignment="-1",col_name="current",colhdr="Current"@}],
34076body=[variable=@{name="$trace_timestamp",initial="0"@}
34077 variable=@{name="$foo",initial="10",current="15"@}]@}
34078(gdb)
34079@end smallexample
922fbb7b 34080
18148017
VP
34081@subheading -trace-save
34082@findex -trace-save
922fbb7b 34083
18148017
VP
34084@subsubheading Synopsis
34085
34086@smallexample
99e61eda 34087 -trace-save [ -r ] [ -ctf ] @var{filename}
18148017
VP
34088@end smallexample
34089
34090Saves the collected trace data to @var{filename}. Without the
34091@samp{-r} option, the data is downloaded from the target and saved
34092in a local file. With the @samp{-r} option the target is asked
34093to perform the save.
34094
99e61eda
SM
34095By default, this command will save the trace in the tfile format. You can
34096supply the optional @samp{-ctf} argument to save it the CTF format. See
34097@ref{Trace Files} for more information about CTF.
34098
7d13fe92
SS
34099@subsubheading @value{GDBN} Command
34100
34101The corresponding @value{GDBN} command is @samp{tsave}.
34102
18148017
VP
34103
34104@subheading -trace-start
34105@findex -trace-start
34106
34107@subsubheading Synopsis
34108
34109@smallexample
34110 -trace-start
34111@end smallexample
922fbb7b 34112
be06ba8c 34113Starts a tracing experiment. The result of this command does not
18148017 34114have any fields.
922fbb7b 34115
7d13fe92
SS
34116@subsubheading @value{GDBN} Command
34117
34118The corresponding @value{GDBN} command is @samp{tstart}.
34119
18148017
VP
34120@subheading -trace-status
34121@findex -trace-status
922fbb7b 34122
18148017
VP
34123@subsubheading Synopsis
34124
34125@smallexample
34126 -trace-status
34127@end smallexample
34128
a97153c7 34129Obtains the status of a tracing experiment. The result may include
18148017
VP
34130the following fields:
34131
34132@table @samp
34133
34134@item supported
34135May have a value of either @samp{0}, when no tracing operations are
34136supported, @samp{1}, when all tracing operations are supported, or
34137@samp{file} when examining trace file. In the latter case, examining
34138of trace frame is possible but new tracing experiement cannot be
34139started. This field is always present.
34140
34141@item running
34142May have a value of either @samp{0} or @samp{1} depending on whether
34143tracing experiement is in progress on target. This field is present
34144if @samp{supported} field is not @samp{0}.
34145
34146@item stop-reason
34147Report the reason why the tracing was stopped last time. This field
34148may be absent iff tracing was never stopped on target yet. The
34149value of @samp{request} means the tracing was stopped as result of
34150the @code{-trace-stop} command. The value of @samp{overflow} means
34151the tracing buffer is full. The value of @samp{disconnection} means
34152tracing was automatically stopped when @value{GDBN} has disconnected.
34153The value of @samp{passcount} means tracing was stopped when a
34154tracepoint was passed a maximal number of times for that tracepoint.
34155This field is present if @samp{supported} field is not @samp{0}.
34156
34157@item stopping-tracepoint
34158The number of tracepoint whose passcount as exceeded. This field is
34159present iff the @samp{stop-reason} field has the value of
34160@samp{passcount}.
34161
34162@item frames
87290684
SS
34163@itemx frames-created
34164The @samp{frames} field is a count of the total number of trace frames
34165in the trace buffer, while @samp{frames-created} is the total created
34166during the run, including ones that were discarded, such as when a
34167circular trace buffer filled up. Both fields are optional.
18148017
VP
34168
34169@item buffer-size
34170@itemx buffer-free
34171These fields tell the current size of the tracing buffer and the
87290684 34172remaining space. These fields are optional.
18148017 34173
a97153c7
PA
34174@item circular
34175The value of the circular trace buffer flag. @code{1} means that the
34176trace buffer is circular and old trace frames will be discarded if
34177necessary to make room, @code{0} means that the trace buffer is linear
34178and may fill up.
34179
34180@item disconnected
34181The value of the disconnected tracing flag. @code{1} means that
34182tracing will continue after @value{GDBN} disconnects, @code{0} means
34183that the trace run will stop.
34184
f5911ea1
HAQ
34185@item trace-file
34186The filename of the trace file being examined. This field is
34187optional, and only present when examining a trace file.
34188
18148017
VP
34189@end table
34190
7d13fe92
SS
34191@subsubheading @value{GDBN} Command
34192
34193The corresponding @value{GDBN} command is @samp{tstatus}.
34194
18148017
VP
34195@subheading -trace-stop
34196@findex -trace-stop
34197
34198@subsubheading Synopsis
34199
34200@smallexample
34201 -trace-stop
34202@end smallexample
922fbb7b 34203
18148017
VP
34204Stops a tracing experiment. The result of this command has the same
34205fields as @code{-trace-status}, except that the @samp{supported} and
34206@samp{running} fields are not output.
922fbb7b 34207
7d13fe92
SS
34208@subsubheading @value{GDBN} Command
34209
34210The corresponding @value{GDBN} command is @samp{tstop}.
34211
922fbb7b 34212
a2c02241
NR
34213@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34214@node GDB/MI Symbol Query
34215@section @sc{gdb/mi} Symbol Query Commands
922fbb7b
AC
34216
34217
9901a55b 34218@ignore
a2c02241
NR
34219@subheading The @code{-symbol-info-address} Command
34220@findex -symbol-info-address
922fbb7b
AC
34221
34222@subsubheading Synopsis
34223
34224@smallexample
a2c02241 34225 -symbol-info-address @var{symbol}
922fbb7b
AC
34226@end smallexample
34227
a2c02241 34228Describe where @var{symbol} is stored.
922fbb7b
AC
34229
34230@subsubheading @value{GDBN} Command
34231
a2c02241 34232The corresponding @value{GDBN} command is @samp{info address}.
922fbb7b
AC
34233
34234@subsubheading Example
34235N.A.
34236
34237
a2c02241
NR
34238@subheading The @code{-symbol-info-file} Command
34239@findex -symbol-info-file
922fbb7b
AC
34240
34241@subsubheading Synopsis
34242
34243@smallexample
a2c02241 34244 -symbol-info-file
922fbb7b
AC
34245@end smallexample
34246
a2c02241 34247Show the file for the symbol.
922fbb7b 34248
a2c02241 34249@subsubheading @value{GDBN} Command
922fbb7b 34250
a2c02241
NR
34251There's no equivalent @value{GDBN} command. @code{gdbtk} has
34252@samp{gdb_find_file}.
922fbb7b
AC
34253
34254@subsubheading Example
34255N.A.
7dc42066
AB
34256@end ignore
34257
34258@subheading The @code{-symbol-info-functions} Command
34259@findex -symbol-info-functions
34260@anchor{-symbol-info-functions}
34261
34262@subsubheading Synopsis
34263
34264@smallexample
34265 -symbol-info-functions [--include-nondebug]
34266 [--type @var{type_regexp}]
34267 [--name @var{name_regexp}]
c2512106 34268 [--max-results @var{limit}]
7dc42066
AB
34269@end smallexample
34270
34271@noindent
34272Return a list containing the names and types for all global functions
34273taken from the debug information. The functions are grouped by source
34274file, and shown with the line number on which each function is
34275defined.
922fbb7b 34276
7dc42066
AB
34277The @code{--include-nondebug} option causes the output to include
34278code symbols from the symbol table.
922fbb7b 34279
7dc42066
AB
34280The options @code{--type} and @code{--name} allow the symbols returned
34281to be filtered based on either the name of the function, or the type
34282signature of the function.
34283
c2512106
AB
34284The option @code{--max-results} restricts the command to return no
34285more than @var{limit} results. If exactly @var{limit} results are
34286returned then there might be additional results available if a higher
34287limit is used.
34288
7dc42066
AB
34289@subsubheading @value{GDBN} Command
34290
34291The corresponding @value{GDBN} command is @samp{info functions}.
34292
34293@subsubheading Example
34294@smallexample
34295@group
34296(gdb)
34297-symbol-info-functions
34298^done,symbols=
34299 @{debug=
34300 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34301 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34302 symbols=[@{line="36", name="f4", type="void (int *)",
34303 description="void f4(int *);"@},
34304 @{line="42", name="main", type="int ()",
34305 description="int main();"@},
34306 @{line="30", name="f1", type="my_int_t (int, int)",
34307 description="static my_int_t f1(int, int);"@}]@},
34308 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34309 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34310 symbols=[@{line="33", name="f2", type="float (another_float_t)",
34311 description="float f2(another_float_t);"@},
34312 @{line="39", name="f3", type="int (another_int_t)",
34313 description="int f3(another_int_t);"@},
34314 @{line="27", name="f1", type="another_float_t (int)",
34315 description="static another_float_t f1(int);"@}]@}]@}
34316@end group
34317@group
34318(gdb)
34319-symbol-info-functions --name f1
34320^done,symbols=
34321 @{debug=
34322 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34323 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34324 symbols=[@{line="30", name="f1", type="my_int_t (int, int)",
34325 description="static my_int_t f1(int, int);"@}]@},
34326 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34327 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34328 symbols=[@{line="27", name="f1", type="another_float_t (int)",
34329 description="static another_float_t f1(int);"@}]@}]@}
34330@end group
34331@group
34332(gdb)
34333-symbol-info-functions --type void
34334^done,symbols=
34335 @{debug=
34336 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34337 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34338 symbols=[@{line="36", name="f4", type="void (int *)",
34339 description="void f4(int *);"@}]@}]@}
34340@end group
34341@group
34342(gdb)
34343-symbol-info-functions --include-nondebug
34344^done,symbols=
34345 @{debug=
34346 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34347 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34348 symbols=[@{line="36", name="f4", type="void (int *)",
34349 description="void f4(int *);"@},
34350 @{line="42", name="main", type="int ()",
34351 description="int main();"@},
34352 @{line="30", name="f1", type="my_int_t (int, int)",
34353 description="static my_int_t f1(int, int);"@}]@},
34354 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34355 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34356 symbols=[@{line="33", name="f2", type="float (another_float_t)",
34357 description="float f2(another_float_t);"@},
34358 @{line="39", name="f3", type="int (another_int_t)",
34359 description="int f3(another_int_t);"@},
34360 @{line="27", name="f1", type="another_float_t (int)",
34361 description="static another_float_t f1(int);"@}]@}],
34362 nondebug=
34363 [@{address="0x0000000000400398",name="_init"@},
34364 @{address="0x00000000004003b0",name="_start"@},
34365 ...
34366 ]@}
34367@end group
34368@end smallexample
34369
293b38d6
AB
34370@subheading The @code{-symbol-info-module-functions} Command
34371@findex -symbol-info-module-functions
34372@anchor{-symbol-info-module-functions}
34373
34374@subsubheading Synopsis
34375
34376@smallexample
34377 -symbol-info-module-functions [--module @var{module_regexp}]
34378 [--name @var{name_regexp}]
34379 [--type @var{type_regexp}]
34380@end smallexample
34381
34382@noindent
34383Return a list containing the names of all known functions within all
34384know Fortran modules. The functions are grouped by source file and
34385containing module, and shown with the line number on which each
34386function is defined.
34387
34388The option @code{--module} only returns results for modules matching
34389@var{module_regexp}. The option @code{--name} only returns functions
34390whose name matches @var{name_regexp}, and @code{--type} only returns
34391functions whose type matches @var{type_regexp}.
34392
34393@subsubheading @value{GDBN} Command
34394
34395The corresponding @value{GDBN} command is @samp{info module functions}.
34396
34397@subsubheading Example
34398
34399@smallexample
34400@group
34401(gdb)
34402-symbol-info-module-functions
34403^done,symbols=
34404 [@{module="mod1",
34405 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34406 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34407 symbols=[@{line="21",name="mod1::check_all",type="void (void)",
34408 description="void mod1::check_all(void);"@}]@}]@},
34409 @{module="mod2",
34410 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34411 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34412 symbols=[@{line="30",name="mod2::check_var_i",type="void (void)",
34413 description="void mod2::check_var_i(void);"@}]@}]@},
34414 @{module="mod3",
34415 files=[@{filename="/projec/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34416 fullname="/projec/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34417 symbols=[@{line="21",name="mod3::check_all",type="void (void)",
34418 description="void mod3::check_all(void);"@},
34419 @{line="27",name="mod3::check_mod2",type="void (void)",
34420 description="void mod3::check_mod2(void);"@}]@}]@},
34421 @{module="modmany",
34422 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34423 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34424 symbols=[@{line="35",name="modmany::check_some",type="void (void)",
34425 description="void modmany::check_some(void);"@}]@}]@},
34426 @{module="moduse",
34427 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34428 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34429 symbols=[@{line="44",name="moduse::check_all",type="void (void)",
34430 description="void moduse::check_all(void);"@},
34431 @{line="49",name="moduse::check_var_x",type="void (void)",
34432 description="void moduse::check_var_x(void);"@}]@}]@}]
34433@end group
34434@end smallexample
34435
34436@subheading The @code{-symbol-info-module-variables} Command
34437@findex -symbol-info-module-variables
34438@anchor{-symbol-info-module-variables}
34439
34440@subsubheading Synopsis
34441
34442@smallexample
34443 -symbol-info-module-variables [--module @var{module_regexp}]
34444 [--name @var{name_regexp}]
34445 [--type @var{type_regexp}]
34446@end smallexample
34447
34448@noindent
34449Return a list containing the names of all known variables within all
34450know Fortran modules. The variables are grouped by source file and
34451containing module, and shown with the line number on which each
34452variable is defined.
34453
34454The option @code{--module} only returns results for modules matching
34455@var{module_regexp}. The option @code{--name} only returns variables
34456whose name matches @var{name_regexp}, and @code{--type} only returns
34457variables whose type matches @var{type_regexp}.
34458
34459@subsubheading @value{GDBN} Command
34460
34461The corresponding @value{GDBN} command is @samp{info module variables}.
34462
34463@subsubheading Example
34464
34465@smallexample
34466@group
34467(gdb)
34468-symbol-info-module-variables
34469^done,symbols=
34470 [@{module="mod1",
34471 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34472 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34473 symbols=[@{line="18",name="mod1::var_const",type="integer(kind=4)",
34474 description="integer(kind=4) mod1::var_const;"@},
34475 @{line="17",name="mod1::var_i",type="integer(kind=4)",
34476 description="integer(kind=4) mod1::var_i;"@}]@}]@},
34477 @{module="mod2",
34478 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34479 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34480 symbols=[@{line="28",name="mod2::var_i",type="integer(kind=4)",
34481 description="integer(kind=4) mod2::var_i;"@}]@}]@},
34482 @{module="mod3",
34483 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34484 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34485 symbols=[@{line="18",name="mod3::mod1",type="integer(kind=4)",
34486 description="integer(kind=4) mod3::mod1;"@},
34487 @{line="17",name="mod3::mod2",type="integer(kind=4)",
34488 description="integer(kind=4) mod3::mod2;"@},
34489 @{line="19",name="mod3::var_i",type="integer(kind=4)",
34490 description="integer(kind=4) mod3::var_i;"@}]@}]@},
34491 @{module="modmany",
34492 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34493 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34494 symbols=[@{line="33",name="modmany::var_a",type="integer(kind=4)",
34495 description="integer(kind=4) modmany::var_a;"@},
34496 @{line="33",name="modmany::var_b",type="integer(kind=4)",
34497 description="integer(kind=4) modmany::var_b;"@},
34498 @{line="33",name="modmany::var_c",type="integer(kind=4)",
34499 description="integer(kind=4) modmany::var_c;"@},
34500 @{line="33",name="modmany::var_i",type="integer(kind=4)",
34501 description="integer(kind=4) modmany::var_i;"@}]@}]@},
34502 @{module="moduse",
34503 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34504 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34505 symbols=[@{line="42",name="moduse::var_x",type="integer(kind=4)",
34506 description="integer(kind=4) moduse::var_x;"@},
34507 @{line="42",name="moduse::var_y",type="integer(kind=4)",
34508 description="integer(kind=4) moduse::var_y;"@}]@}]@}]
34509@end group
34510@end smallexample
34511
db5960b4
AB
34512@subheading The @code{-symbol-info-modules} Command
34513@findex -symbol-info-modules
34514@anchor{-symbol-info-modules}
34515
34516@subsubheading Synopsis
34517
34518@smallexample
34519 -symbol-info-modules [--name @var{name_regexp}]
c2512106
AB
34520 [--max-results @var{limit}]
34521
db5960b4
AB
34522@end smallexample
34523
34524@noindent
34525Return a list containing the names of all known Fortran modules. The
34526modules are grouped by source file, and shown with the line number on
34527which each modules is defined.
34528
34529The option @code{--name} allows the modules returned to be filtered
34530based the name of the module.
34531
c2512106
AB
34532The option @code{--max-results} restricts the command to return no
34533more than @var{limit} results. If exactly @var{limit} results are
34534returned then there might be additional results available if a higher
34535limit is used.
34536
db5960b4
AB
34537@subsubheading @value{GDBN} Command
34538
34539The corresponding @value{GDBN} command is @samp{info modules}.
34540
34541@subsubheading Example
34542@smallexample
34543@group
34544(gdb)
34545-symbol-info-modules
34546^done,symbols=
34547 @{debug=
34548 [@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34549 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34550 symbols=[@{line="16",name="mod1"@},
34551 @{line="22",name="mod2"@}]@},
34552 @{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34553 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34554 symbols=[@{line="16",name="mod3"@},
34555 @{line="22",name="modmany"@},
34556 @{line="26",name="moduse"@}]@}]@}
34557@end group
34558@group
34559(gdb)
34560-symbol-info-modules --name mod[123]
34561^done,symbols=
34562 @{debug=
34563 [@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34564 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34565 symbols=[@{line="16",name="mod1"@},
34566 @{line="22",name="mod2"@}]@},
34567 @{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34568 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34569 symbols=[@{line="16",name="mod3"@}]@}]@}
34570@end group
34571@end smallexample
34572
7dc42066
AB
34573@subheading The @code{-symbol-info-types} Command
34574@findex -symbol-info-types
34575@anchor{-symbol-info-types}
922fbb7b
AC
34576
34577@subsubheading Synopsis
34578
34579@smallexample
7dc42066 34580 -symbol-info-types [--name @var{name_regexp}]
c2512106
AB
34581 [--max-results @var{limit}]
34582
922fbb7b
AC
34583@end smallexample
34584
7dc42066
AB
34585@noindent
34586Return a list of all defined types. The types are grouped by source
34587file, and shown with the line number on which each user defined type
34588is defined. Some base types are not defined in the source code but
34589are added to the debug information by the compiler, for example
34590@code{int}, @code{float}, etc.; these types do not have an associated
34591line number.
34592
34593The option @code{--name} allows the list of types returned to be
34594filtered by name.
922fbb7b 34595
c2512106
AB
34596The option @code{--max-results} restricts the command to return no
34597more than @var{limit} results. If exactly @var{limit} results are
34598returned then there might be additional results available if a higher
34599limit is used.
34600
922fbb7b
AC
34601@subsubheading @value{GDBN} Command
34602
7dc42066 34603The corresponding @value{GDBN} command is @samp{info types}.
922fbb7b
AC
34604
34605@subsubheading Example
7dc42066
AB
34606@smallexample
34607@group
34608(gdb)
34609-symbol-info-types
34610^done,symbols=
34611 @{debug=
34612 [@{filename="gdb.mi/mi-sym-info-1.c",
34613 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34614 symbols=[@{name="float"@},
34615 @{name="int"@},
34616 @{line="27",name="typedef int my_int_t;"@}]@},
34617 @{filename="gdb.mi/mi-sym-info-2.c",
34618 fullname="/project/gdb.mi/mi-sym-info-2.c",
34619 symbols=[@{line="24",name="typedef float another_float_t;"@},
34620 @{line="23",name="typedef int another_int_t;"@},
34621 @{name="float"@},
34622 @{name="int"@}]@}]@}
34623@end group
34624@group
34625(gdb)
34626-symbol-info-types --name _int_
34627^done,symbols=
34628 @{debug=
34629 [@{filename="gdb.mi/mi-sym-info-1.c",
34630 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34631 symbols=[@{line="27",name="typedef int my_int_t;"@}]@},
34632 @{filename="gdb.mi/mi-sym-info-2.c",
34633 fullname="/project/gdb.mi/mi-sym-info-2.c",
34634 symbols=[@{line="23",name="typedef int another_int_t;"@}]@}]@}
34635@end group
34636@end smallexample
34637
34638@subheading The @code{-symbol-info-variables} Command
34639@findex -symbol-info-variables
34640@anchor{-symbol-info-variables}
34641
34642@subsubheading Synopsis
34643
34644@smallexample
34645 -symbol-info-variables [--include-nondebug]
34646 [--type @var{type_regexp}]
34647 [--name @var{name_regexp}]
c2512106
AB
34648 [--max-results @var{limit}]
34649
7dc42066
AB
34650@end smallexample
34651
34652@noindent
34653Return a list containing the names and types for all global variables
34654taken from the debug information. The variables are grouped by source
34655file, and shown with the line number on which each variable is
34656defined.
34657
34658The @code{--include-nondebug} option causes the output to include
34659data symbols from the symbol table.
34660
34661The options @code{--type} and @code{--name} allow the symbols returned
34662to be filtered based on either the name of the variable, or the type
34663of the variable.
34664
c2512106
AB
34665The option @code{--max-results} restricts the command to return no
34666more than @var{limit} results. If exactly @var{limit} results are
34667returned then there might be additional results available if a higher
34668limit is used.
34669
7dc42066 34670@subsubheading @value{GDBN} Command
922fbb7b 34671
7dc42066 34672The corresponding @value{GDBN} command is @samp{info variables}.
922fbb7b 34673
7dc42066
AB
34674@subsubheading Example
34675@smallexample
34676@group
34677(gdb)
34678-symbol-info-variables
34679^done,symbols=
34680 @{debug=
34681 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34682 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34683 symbols=[@{line="25",name="global_f1",type="float",
34684 description="static float global_f1;"@},
34685 @{line="24",name="global_i1",type="int",
34686 description="static int global_i1;"@}]@},
34687 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34688 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34689 symbols=[@{line="21",name="global_f2",type="int",
34690 description="int global_f2;"@},
34691 @{line="20",name="global_i2",type="int",
34692 description="int global_i2;"@},
34693 @{line="19",name="global_f1",type="float",
34694 description="static float global_f1;"@},
34695 @{line="18",name="global_i1",type="int",
34696 description="static int global_i1;"@}]@}]@}
34697@end group
34698@group
34699(gdb)
34700-symbol-info-variables --name f1
34701^done,symbols=
34702 @{debug=
34703 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34704 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34705 symbols=[@{line="25",name="global_f1",type="float",
34706 description="static float global_f1;"@}]@},
34707 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34708 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34709 symbols=[@{line="19",name="global_f1",type="float",
34710 description="static float global_f1;"@}]@}]@}
34711@end group
34712@group
34713(gdb)
34714-symbol-info-variables --type float
34715^done,symbols=
34716 @{debug=
34717 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34718 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34719 symbols=[@{line="25",name="global_f1",type="float",
34720 description="static float global_f1;"@}]@},
34721 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34722 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34723 symbols=[@{line="19",name="global_f1",type="float",
34724 description="static float global_f1;"@}]@}]@}
34725@end group
34726@group
34727(gdb)
34728-symbol-info-variables --include-nondebug
34729^done,symbols=
34730 @{debug=
34731 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34732 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34733 symbols=[@{line="25",name="global_f1",type="float",
34734 description="static float global_f1;"@},
34735 @{line="24",name="global_i1",type="int",
34736 description="static int global_i1;"@}]@},
34737 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34738 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34739 symbols=[@{line="21",name="global_f2",type="int",
34740 description="int global_f2;"@},
34741 @{line="20",name="global_i2",type="int",
34742 description="int global_i2;"@},
34743 @{line="19",name="global_f1",type="float",
34744 description="static float global_f1;"@},
34745 @{line="18",name="global_i1",type="int",
34746 description="static int global_i1;"@}]@}],
34747 nondebug=
34748 [@{address="0x00000000004005d0",name="_IO_stdin_used"@},
34749 @{address="0x00000000004005d8",name="__dso_handle"@}
34750 ...
34751 ]@}
34752@end group
34753@end smallexample
34754
34755@ignore
a2c02241
NR
34756@subheading The @code{-symbol-info-line} Command
34757@findex -symbol-info-line
922fbb7b
AC
34758
34759@subsubheading Synopsis
34760
34761@smallexample
a2c02241 34762 -symbol-info-line
922fbb7b
AC
34763@end smallexample
34764
a2c02241 34765Show the core addresses of the code for a source line.
922fbb7b 34766
a2c02241 34767@subsubheading @value{GDBN} Command
922fbb7b 34768
a2c02241
NR
34769The corresponding @value{GDBN} command is @samp{info line}.
34770@code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
922fbb7b
AC
34771
34772@subsubheading Example
a2c02241 34773N.A.
922fbb7b
AC
34774
34775
a2c02241
NR
34776@subheading The @code{-symbol-info-symbol} Command
34777@findex -symbol-info-symbol
07f31aa6
DJ
34778
34779@subsubheading Synopsis
34780
a2c02241
NR
34781@smallexample
34782 -symbol-info-symbol @var{addr}
34783@end smallexample
07f31aa6 34784
a2c02241 34785Describe what symbol is at location @var{addr}.
07f31aa6 34786
a2c02241 34787@subsubheading @value{GDBN} Command
07f31aa6 34788
a2c02241 34789The corresponding @value{GDBN} command is @samp{info symbol}.
07f31aa6
DJ
34790
34791@subsubheading Example
a2c02241 34792N.A.
07f31aa6
DJ
34793
34794
a2c02241
NR
34795@subheading The @code{-symbol-list-functions} Command
34796@findex -symbol-list-functions
922fbb7b
AC
34797
34798@subsubheading Synopsis
34799
34800@smallexample
a2c02241 34801 -symbol-list-functions
922fbb7b
AC
34802@end smallexample
34803
a2c02241 34804List the functions in the executable.
922fbb7b
AC
34805
34806@subsubheading @value{GDBN} Command
34807
a2c02241
NR
34808@samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
34809@samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
34810
34811@subsubheading Example
a2c02241 34812N.A.
9901a55b 34813@end ignore
922fbb7b
AC
34814
34815
a2c02241
NR
34816@subheading The @code{-symbol-list-lines} Command
34817@findex -symbol-list-lines
922fbb7b
AC
34818
34819@subsubheading Synopsis
34820
34821@smallexample
a2c02241 34822 -symbol-list-lines @var{filename}
922fbb7b
AC
34823@end smallexample
34824
a2c02241
NR
34825Print the list of lines that contain code and their associated program
34826addresses for the given source filename. The entries are sorted in
34827ascending PC order.
922fbb7b
AC
34828
34829@subsubheading @value{GDBN} Command
34830
a2c02241 34831There is no corresponding @value{GDBN} command.
922fbb7b
AC
34832
34833@subsubheading Example
a2c02241 34834@smallexample
594fe323 34835(gdb)
a2c02241
NR
34836-symbol-list-lines basics.c
34837^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
594fe323 34838(gdb)
a2c02241 34839@end smallexample
922fbb7b
AC
34840
34841
9901a55b 34842@ignore
a2c02241
NR
34843@subheading The @code{-symbol-list-types} Command
34844@findex -symbol-list-types
922fbb7b
AC
34845
34846@subsubheading Synopsis
34847
34848@smallexample
a2c02241 34849 -symbol-list-types
922fbb7b
AC
34850@end smallexample
34851
a2c02241 34852List all the type names.
922fbb7b
AC
34853
34854@subsubheading @value{GDBN} Command
34855
a2c02241
NR
34856The corresponding commands are @samp{info types} in @value{GDBN},
34857@samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
34858
34859@subsubheading Example
34860N.A.
34861
34862
a2c02241
NR
34863@subheading The @code{-symbol-list-variables} Command
34864@findex -symbol-list-variables
922fbb7b
AC
34865
34866@subsubheading Synopsis
34867
34868@smallexample
a2c02241 34869 -symbol-list-variables
922fbb7b
AC
34870@end smallexample
34871
a2c02241 34872List all the global and static variable names.
922fbb7b
AC
34873
34874@subsubheading @value{GDBN} Command
34875
a2c02241 34876@samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
34877
34878@subsubheading Example
34879N.A.
34880
34881
a2c02241
NR
34882@subheading The @code{-symbol-locate} Command
34883@findex -symbol-locate
922fbb7b
AC
34884
34885@subsubheading Synopsis
34886
34887@smallexample
a2c02241 34888 -symbol-locate
922fbb7b
AC
34889@end smallexample
34890
922fbb7b
AC
34891@subsubheading @value{GDBN} Command
34892
a2c02241 34893@samp{gdb_loc} in @code{gdbtk}.
922fbb7b
AC
34894
34895@subsubheading Example
34896N.A.
34897
34898
a2c02241
NR
34899@subheading The @code{-symbol-type} Command
34900@findex -symbol-type
922fbb7b
AC
34901
34902@subsubheading Synopsis
34903
34904@smallexample
a2c02241 34905 -symbol-type @var{variable}
922fbb7b
AC
34906@end smallexample
34907
a2c02241 34908Show type of @var{variable}.
922fbb7b 34909
a2c02241 34910@subsubheading @value{GDBN} Command
922fbb7b 34911
a2c02241
NR
34912The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
34913@samp{gdb_obj_variable}.
34914
34915@subsubheading Example
34916N.A.
9901a55b 34917@end ignore
a2c02241
NR
34918
34919
34920@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34921@node GDB/MI File Commands
34922@section @sc{gdb/mi} File Commands
34923
34924This section describes the GDB/MI commands to specify executable file names
34925and to read in and obtain symbol table information.
34926
34927@subheading The @code{-file-exec-and-symbols} Command
34928@findex -file-exec-and-symbols
34929
34930@subsubheading Synopsis
922fbb7b
AC
34931
34932@smallexample
a2c02241 34933 -file-exec-and-symbols @var{file}
922fbb7b
AC
34934@end smallexample
34935
a2c02241
NR
34936Specify the executable file to be debugged. This file is the one from
34937which the symbol table is also read. If no file is specified, the
34938command clears the executable and symbol information. If breakpoints
34939are set when using this command with no arguments, @value{GDBN} will produce
34940error messages. Otherwise, no output is produced, except a completion
34941notification.
34942
922fbb7b
AC
34943@subsubheading @value{GDBN} Command
34944
a2c02241 34945The corresponding @value{GDBN} command is @samp{file}.
922fbb7b
AC
34946
34947@subsubheading Example
34948
34949@smallexample
594fe323 34950(gdb)
a2c02241
NR
34951-file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
34952^done
594fe323 34953(gdb)
922fbb7b
AC
34954@end smallexample
34955
922fbb7b 34956
a2c02241
NR
34957@subheading The @code{-file-exec-file} Command
34958@findex -file-exec-file
922fbb7b
AC
34959
34960@subsubheading Synopsis
34961
34962@smallexample
a2c02241 34963 -file-exec-file @var{file}
922fbb7b
AC
34964@end smallexample
34965
a2c02241
NR
34966Specify the executable file to be debugged. Unlike
34967@samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
34968from this file. If used without argument, @value{GDBN} clears the information
34969about the executable file. No output is produced, except a completion
34970notification.
922fbb7b 34971
a2c02241
NR
34972@subsubheading @value{GDBN} Command
34973
34974The corresponding @value{GDBN} command is @samp{exec-file}.
922fbb7b
AC
34975
34976@subsubheading Example
a2c02241
NR
34977
34978@smallexample
594fe323 34979(gdb)
a2c02241
NR
34980-file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
34981^done
594fe323 34982(gdb)
a2c02241 34983@end smallexample
922fbb7b
AC
34984
34985
9901a55b 34986@ignore
a2c02241
NR
34987@subheading The @code{-file-list-exec-sections} Command
34988@findex -file-list-exec-sections
922fbb7b
AC
34989
34990@subsubheading Synopsis
34991
34992@smallexample
a2c02241 34993 -file-list-exec-sections
922fbb7b
AC
34994@end smallexample
34995
a2c02241
NR
34996List the sections of the current executable file.
34997
922fbb7b
AC
34998@subsubheading @value{GDBN} Command
34999
a2c02241
NR
35000The @value{GDBN} command @samp{info file} shows, among the rest, the same
35001information as this command. @code{gdbtk} has a corresponding command
35002@samp{gdb_load_info}.
922fbb7b
AC
35003
35004@subsubheading Example
35005N.A.
9901a55b 35006@end ignore
922fbb7b
AC
35007
35008
a2c02241
NR
35009@subheading The @code{-file-list-exec-source-file} Command
35010@findex -file-list-exec-source-file
922fbb7b
AC
35011
35012@subsubheading Synopsis
35013
35014@smallexample
a2c02241 35015 -file-list-exec-source-file
922fbb7b
AC
35016@end smallexample
35017
a2c02241 35018List the line number, the current source file, and the absolute path
44288b44
NR
35019to the current source file for the current executable. The macro
35020information field has a value of @samp{1} or @samp{0} depending on
35021whether or not the file includes preprocessor macro information.
922fbb7b
AC
35022
35023@subsubheading @value{GDBN} Command
35024
a2c02241 35025The @value{GDBN} equivalent is @samp{info source}
922fbb7b
AC
35026
35027@subsubheading Example
35028
922fbb7b 35029@smallexample
594fe323 35030(gdb)
a2c02241 35031123-file-list-exec-source-file
44288b44 35032123^done,line="1",file="foo.c",fullname="/home/bar/foo.c,macro-info="1"
594fe323 35033(gdb)
922fbb7b
AC
35034@end smallexample
35035
35036
a2c02241
NR
35037@subheading The @code{-file-list-exec-source-files} Command
35038@findex -file-list-exec-source-files
922fbb7b
AC
35039
35040@subsubheading Synopsis
35041
35042@smallexample
a2c02241 35043 -file-list-exec-source-files
922fbb7b
AC
35044@end smallexample
35045
a2c02241
NR
35046List the source files for the current executable.
35047
f35a17b5
JK
35048It will always output both the filename and fullname (absolute file
35049name) of a source file.
922fbb7b
AC
35050
35051@subsubheading @value{GDBN} Command
35052
a2c02241
NR
35053The @value{GDBN} equivalent is @samp{info sources}.
35054@code{gdbtk} has an analogous command @samp{gdb_listfiles}.
922fbb7b
AC
35055
35056@subsubheading Example
922fbb7b 35057@smallexample
594fe323 35058(gdb)
a2c02241
NR
35059-file-list-exec-source-files
35060^done,files=[
35061@{file=foo.c,fullname=/home/foo.c@},
35062@{file=/home/bar.c,fullname=/home/bar.c@},
35063@{file=gdb_could_not_find_fullpath.c@}]
594fe323 35064(gdb)
922fbb7b
AC
35065@end smallexample
35066
a2c02241
NR
35067@subheading The @code{-file-list-shared-libraries} Command
35068@findex -file-list-shared-libraries
922fbb7b 35069
a2c02241 35070@subsubheading Synopsis
922fbb7b 35071
a2c02241 35072@smallexample
51457a05 35073 -file-list-shared-libraries [ @var{regexp} ]
a2c02241 35074@end smallexample
922fbb7b 35075
a2c02241 35076List the shared libraries in the program.
51457a05
MAL
35077With a regular expression @var{regexp}, only those libraries whose
35078names match @var{regexp} are listed.
922fbb7b 35079
a2c02241 35080@subsubheading @value{GDBN} Command
922fbb7b 35081
51457a05
MAL
35082The corresponding @value{GDBN} command is @samp{info shared}. The fields
35083have a similar meaning to the @code{=library-loaded} notification.
35084The @code{ranges} field specifies the multiple segments belonging to this
35085library. Each range has the following fields:
35086
35087@table @samp
35088@item from
35089The address defining the inclusive lower bound of the segment.
35090@item to
35091The address defining the exclusive upper bound of the segment.
35092@end table
922fbb7b 35093
a2c02241 35094@subsubheading Example
51457a05
MAL
35095@smallexample
35096(gdb)
35097-file-list-exec-source-files
35098^done,shared-libraries=[
35099@{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"@}]@},
35100@{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"@}]@}]
35101(gdb)
35102@end smallexample
922fbb7b
AC
35103
35104
51457a05 35105@ignore
a2c02241
NR
35106@subheading The @code{-file-list-symbol-files} Command
35107@findex -file-list-symbol-files
922fbb7b 35108
a2c02241 35109@subsubheading Synopsis
922fbb7b 35110
a2c02241
NR
35111@smallexample
35112 -file-list-symbol-files
35113@end smallexample
922fbb7b 35114
a2c02241 35115List symbol files.
922fbb7b 35116
a2c02241 35117@subsubheading @value{GDBN} Command
922fbb7b 35118
a2c02241 35119The corresponding @value{GDBN} command is @samp{info file} (part of it).
922fbb7b 35120
a2c02241
NR
35121@subsubheading Example
35122N.A.
9901a55b 35123@end ignore
922fbb7b 35124
922fbb7b 35125
a2c02241
NR
35126@subheading The @code{-file-symbol-file} Command
35127@findex -file-symbol-file
922fbb7b 35128
a2c02241 35129@subsubheading Synopsis
922fbb7b 35130
a2c02241
NR
35131@smallexample
35132 -file-symbol-file @var{file}
35133@end smallexample
922fbb7b 35134
a2c02241
NR
35135Read symbol table info from the specified @var{file} argument. When
35136used without arguments, clears @value{GDBN}'s symbol table info. No output is
35137produced, except for a completion notification.
922fbb7b 35138
a2c02241 35139@subsubheading @value{GDBN} Command
922fbb7b 35140
a2c02241 35141The corresponding @value{GDBN} command is @samp{symbol-file}.
922fbb7b 35142
a2c02241 35143@subsubheading Example
922fbb7b 35144
a2c02241 35145@smallexample
594fe323 35146(gdb)
a2c02241
NR
35147-file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
35148^done
594fe323 35149(gdb)
a2c02241 35150@end smallexample
922fbb7b 35151
a2c02241 35152@ignore
a2c02241
NR
35153@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35154@node GDB/MI Memory Overlay Commands
35155@section @sc{gdb/mi} Memory Overlay Commands
922fbb7b 35156
a2c02241 35157The memory overlay commands are not implemented.
922fbb7b 35158
a2c02241 35159@c @subheading -overlay-auto
922fbb7b 35160
a2c02241 35161@c @subheading -overlay-list-mapping-state
922fbb7b 35162
a2c02241 35163@c @subheading -overlay-list-overlays
922fbb7b 35164
a2c02241 35165@c @subheading -overlay-map
922fbb7b 35166
a2c02241 35167@c @subheading -overlay-off
922fbb7b 35168
a2c02241 35169@c @subheading -overlay-on
922fbb7b 35170
a2c02241 35171@c @subheading -overlay-unmap
922fbb7b 35172
a2c02241
NR
35173@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35174@node GDB/MI Signal Handling Commands
35175@section @sc{gdb/mi} Signal Handling Commands
922fbb7b 35176
a2c02241 35177Signal handling commands are not implemented.
922fbb7b 35178
a2c02241 35179@c @subheading -signal-handle
922fbb7b 35180
a2c02241 35181@c @subheading -signal-list-handle-actions
922fbb7b 35182
a2c02241
NR
35183@c @subheading -signal-list-signal-types
35184@end ignore
922fbb7b 35185
922fbb7b 35186
a2c02241
NR
35187@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35188@node GDB/MI Target Manipulation
35189@section @sc{gdb/mi} Target Manipulation Commands
922fbb7b
AC
35190
35191
a2c02241
NR
35192@subheading The @code{-target-attach} Command
35193@findex -target-attach
922fbb7b
AC
35194
35195@subsubheading Synopsis
35196
35197@smallexample
c3b108f7 35198 -target-attach @var{pid} | @var{gid} | @var{file}
922fbb7b
AC
35199@end smallexample
35200
c3b108f7
VP
35201Attach to a process @var{pid} or a file @var{file} outside of
35202@value{GDBN}, or a thread group @var{gid}. If attaching to a thread
35203group, the id previously returned by
35204@samp{-list-thread-groups --available} must be used.
922fbb7b 35205
79a6e687 35206@subsubheading @value{GDBN} Command
922fbb7b 35207
a2c02241 35208The corresponding @value{GDBN} command is @samp{attach}.
922fbb7b 35209
a2c02241 35210@subsubheading Example
b56e7235
VP
35211@smallexample
35212(gdb)
35213-target-attach 34
35214=thread-created,id="1"
5ae4183a 35215*stopped,thread-id="1",frame=@{addr="0xb7f7e410",func="bar",args=[]@}
b56e7235
VP
35216^done
35217(gdb)
35218@end smallexample
a2c02241 35219
9901a55b 35220@ignore
a2c02241
NR
35221@subheading The @code{-target-compare-sections} Command
35222@findex -target-compare-sections
922fbb7b
AC
35223
35224@subsubheading Synopsis
35225
35226@smallexample
a2c02241 35227 -target-compare-sections [ @var{section} ]
922fbb7b
AC
35228@end smallexample
35229
a2c02241
NR
35230Compare data of section @var{section} on target to the exec file.
35231Without the argument, all sections are compared.
922fbb7b 35232
a2c02241 35233@subsubheading @value{GDBN} Command
922fbb7b 35234
a2c02241 35235The @value{GDBN} equivalent is @samp{compare-sections}.
922fbb7b 35236
a2c02241
NR
35237@subsubheading Example
35238N.A.
9901a55b 35239@end ignore
a2c02241
NR
35240
35241
35242@subheading The @code{-target-detach} Command
35243@findex -target-detach
922fbb7b
AC
35244
35245@subsubheading Synopsis
35246
35247@smallexample
c3b108f7 35248 -target-detach [ @var{pid} | @var{gid} ]
922fbb7b
AC
35249@end smallexample
35250
a2c02241 35251Detach from the remote target which normally resumes its execution.
c3b108f7
VP
35252If either @var{pid} or @var{gid} is specified, detaches from either
35253the specified process, or specified thread group. There's no output.
a2c02241 35254
79a6e687 35255@subsubheading @value{GDBN} Command
a2c02241
NR
35256
35257The corresponding @value{GDBN} command is @samp{detach}.
35258
35259@subsubheading Example
922fbb7b
AC
35260
35261@smallexample
594fe323 35262(gdb)
a2c02241
NR
35263-target-detach
35264^done
594fe323 35265(gdb)
922fbb7b
AC
35266@end smallexample
35267
35268
a2c02241
NR
35269@subheading The @code{-target-disconnect} Command
35270@findex -target-disconnect
922fbb7b
AC
35271
35272@subsubheading Synopsis
35273
123dc839 35274@smallexample
a2c02241 35275 -target-disconnect
123dc839 35276@end smallexample
922fbb7b 35277
a2c02241
NR
35278Disconnect from the remote target. There's no output and the target is
35279generally not resumed.
35280
79a6e687 35281@subsubheading @value{GDBN} Command
a2c02241
NR
35282
35283The corresponding @value{GDBN} command is @samp{disconnect}.
bc8ced35
NR
35284
35285@subsubheading Example
922fbb7b
AC
35286
35287@smallexample
594fe323 35288(gdb)
a2c02241
NR
35289-target-disconnect
35290^done
594fe323 35291(gdb)
922fbb7b
AC
35292@end smallexample
35293
35294
a2c02241
NR
35295@subheading The @code{-target-download} Command
35296@findex -target-download
922fbb7b
AC
35297
35298@subsubheading Synopsis
35299
35300@smallexample
a2c02241 35301 -target-download
922fbb7b
AC
35302@end smallexample
35303
a2c02241
NR
35304Loads the executable onto the remote target.
35305It prints out an update message every half second, which includes the fields:
35306
35307@table @samp
35308@item section
35309The name of the section.
35310@item section-sent
35311The size of what has been sent so far for that section.
35312@item section-size
35313The size of the section.
35314@item total-sent
35315The total size of what was sent so far (the current and the previous sections).
35316@item total-size
35317The size of the overall executable to download.
35318@end table
35319
35320@noindent
35321Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
35322@sc{gdb/mi} Output Syntax}).
35323
35324In addition, it prints the name and size of the sections, as they are
35325downloaded. These messages include the following fields:
35326
35327@table @samp
35328@item section
35329The name of the section.
35330@item section-size
35331The size of the section.
35332@item total-size
35333The size of the overall executable to download.
35334@end table
35335
35336@noindent
35337At the end, a summary is printed.
35338
35339@subsubheading @value{GDBN} Command
35340
35341The corresponding @value{GDBN} command is @samp{load}.
35342
35343@subsubheading Example
35344
35345Note: each status message appears on a single line. Here the messages
35346have been broken down so that they can fit onto a page.
922fbb7b
AC
35347
35348@smallexample
594fe323 35349(gdb)
a2c02241
NR
35350-target-download
35351+download,@{section=".text",section-size="6668",total-size="9880"@}
35352+download,@{section=".text",section-sent="512",section-size="6668",
35353total-sent="512",total-size="9880"@}
35354+download,@{section=".text",section-sent="1024",section-size="6668",
35355total-sent="1024",total-size="9880"@}
35356+download,@{section=".text",section-sent="1536",section-size="6668",
35357total-sent="1536",total-size="9880"@}
35358+download,@{section=".text",section-sent="2048",section-size="6668",
35359total-sent="2048",total-size="9880"@}
35360+download,@{section=".text",section-sent="2560",section-size="6668",
35361total-sent="2560",total-size="9880"@}
35362+download,@{section=".text",section-sent="3072",section-size="6668",
35363total-sent="3072",total-size="9880"@}
35364+download,@{section=".text",section-sent="3584",section-size="6668",
35365total-sent="3584",total-size="9880"@}
35366+download,@{section=".text",section-sent="4096",section-size="6668",
35367total-sent="4096",total-size="9880"@}
35368+download,@{section=".text",section-sent="4608",section-size="6668",
35369total-sent="4608",total-size="9880"@}
35370+download,@{section=".text",section-sent="5120",section-size="6668",
35371total-sent="5120",total-size="9880"@}
35372+download,@{section=".text",section-sent="5632",section-size="6668",
35373total-sent="5632",total-size="9880"@}
35374+download,@{section=".text",section-sent="6144",section-size="6668",
35375total-sent="6144",total-size="9880"@}
35376+download,@{section=".text",section-sent="6656",section-size="6668",
35377total-sent="6656",total-size="9880"@}
35378+download,@{section=".init",section-size="28",total-size="9880"@}
35379+download,@{section=".fini",section-size="28",total-size="9880"@}
35380+download,@{section=".data",section-size="3156",total-size="9880"@}
35381+download,@{section=".data",section-sent="512",section-size="3156",
35382total-sent="7236",total-size="9880"@}
35383+download,@{section=".data",section-sent="1024",section-size="3156",
35384total-sent="7748",total-size="9880"@}
35385+download,@{section=".data",section-sent="1536",section-size="3156",
35386total-sent="8260",total-size="9880"@}
35387+download,@{section=".data",section-sent="2048",section-size="3156",
35388total-sent="8772",total-size="9880"@}
35389+download,@{section=".data",section-sent="2560",section-size="3156",
35390total-sent="9284",total-size="9880"@}
35391+download,@{section=".data",section-sent="3072",section-size="3156",
35392total-sent="9796",total-size="9880"@}
35393^done,address="0x10004",load-size="9880",transfer-rate="6586",
35394write-rate="429"
594fe323 35395(gdb)
922fbb7b
AC
35396@end smallexample
35397
35398
9901a55b 35399@ignore
a2c02241
NR
35400@subheading The @code{-target-exec-status} Command
35401@findex -target-exec-status
922fbb7b
AC
35402
35403@subsubheading Synopsis
35404
35405@smallexample
a2c02241 35406 -target-exec-status
922fbb7b
AC
35407@end smallexample
35408
a2c02241
NR
35409Provide information on the state of the target (whether it is running or
35410not, for instance).
922fbb7b 35411
a2c02241 35412@subsubheading @value{GDBN} Command
922fbb7b 35413
a2c02241
NR
35414There's no equivalent @value{GDBN} command.
35415
35416@subsubheading Example
35417N.A.
922fbb7b 35418
a2c02241
NR
35419
35420@subheading The @code{-target-list-available-targets} Command
35421@findex -target-list-available-targets
922fbb7b
AC
35422
35423@subsubheading Synopsis
35424
35425@smallexample
a2c02241 35426 -target-list-available-targets
922fbb7b
AC
35427@end smallexample
35428
a2c02241 35429List the possible targets to connect to.
922fbb7b 35430
a2c02241 35431@subsubheading @value{GDBN} Command
922fbb7b 35432
a2c02241 35433The corresponding @value{GDBN} command is @samp{help target}.
922fbb7b 35434
a2c02241
NR
35435@subsubheading Example
35436N.A.
35437
35438
35439@subheading The @code{-target-list-current-targets} Command
35440@findex -target-list-current-targets
922fbb7b
AC
35441
35442@subsubheading Synopsis
35443
35444@smallexample
a2c02241 35445 -target-list-current-targets
922fbb7b
AC
35446@end smallexample
35447
a2c02241 35448Describe the current target.
922fbb7b 35449
a2c02241 35450@subsubheading @value{GDBN} Command
922fbb7b 35451
a2c02241
NR
35452The corresponding information is printed by @samp{info file} (among
35453other things).
922fbb7b 35454
a2c02241
NR
35455@subsubheading Example
35456N.A.
35457
35458
35459@subheading The @code{-target-list-parameters} Command
35460@findex -target-list-parameters
922fbb7b
AC
35461
35462@subsubheading Synopsis
35463
35464@smallexample
a2c02241 35465 -target-list-parameters
922fbb7b
AC
35466@end smallexample
35467
a2c02241 35468@c ????
9901a55b 35469@end ignore
a2c02241
NR
35470
35471@subsubheading @value{GDBN} Command
35472
35473No equivalent.
922fbb7b
AC
35474
35475@subsubheading Example
a2c02241
NR
35476N.A.
35477
78cbbba8
LM
35478@subheading The @code{-target-flash-erase} Command
35479@findex -target-flash-erase
35480
35481@subsubheading Synopsis
35482
35483@smallexample
35484 -target-flash-erase
35485@end smallexample
35486
35487Erases all known flash memory regions on the target.
35488
35489The corresponding @value{GDBN} command is @samp{flash-erase}.
35490
35491The output is a list of flash regions that have been erased, with starting
35492addresses and memory region sizes.
35493
35494@smallexample
35495(gdb)
35496-target-flash-erase
35497^done,erased-regions=@{address="0x0",size="0x40000"@}
35498(gdb)
35499@end smallexample
a2c02241
NR
35500
35501@subheading The @code{-target-select} Command
35502@findex -target-select
35503
35504@subsubheading Synopsis
922fbb7b
AC
35505
35506@smallexample
a2c02241 35507 -target-select @var{type} @var{parameters @dots{}}
922fbb7b
AC
35508@end smallexample
35509
a2c02241 35510Connect @value{GDBN} to the remote target. This command takes two args:
922fbb7b 35511
a2c02241
NR
35512@table @samp
35513@item @var{type}
75c99385 35514The type of target, for instance @samp{remote}, etc.
a2c02241
NR
35515@item @var{parameters}
35516Device names, host names and the like. @xref{Target Commands, ,
79a6e687 35517Commands for Managing Targets}, for more details.
a2c02241
NR
35518@end table
35519
35520The output is a connection notification, followed by the address at
35521which the target program is, in the following form:
922fbb7b
AC
35522
35523@smallexample
a2c02241
NR
35524^connected,addr="@var{address}",func="@var{function name}",
35525 args=[@var{arg list}]
922fbb7b
AC
35526@end smallexample
35527
a2c02241
NR
35528@subsubheading @value{GDBN} Command
35529
35530The corresponding @value{GDBN} command is @samp{target}.
265eeb58
NR
35531
35532@subsubheading Example
922fbb7b 35533
265eeb58 35534@smallexample
594fe323 35535(gdb)
75c99385 35536-target-select remote /dev/ttya
a2c02241 35537^connected,addr="0xfe00a300",func="??",args=[]
594fe323 35538(gdb)
265eeb58 35539@end smallexample
ef21caaf 35540
a6b151f1
DJ
35541@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35542@node GDB/MI File Transfer Commands
35543@section @sc{gdb/mi} File Transfer Commands
35544
35545
35546@subheading The @code{-target-file-put} Command
35547@findex -target-file-put
35548
35549@subsubheading Synopsis
35550
35551@smallexample
35552 -target-file-put @var{hostfile} @var{targetfile}
35553@end smallexample
35554
35555Copy file @var{hostfile} from the host system (the machine running
35556@value{GDBN}) to @var{targetfile} on the target system.
35557
35558@subsubheading @value{GDBN} Command
35559
35560The corresponding @value{GDBN} command is @samp{remote put}.
35561
35562@subsubheading Example
35563
35564@smallexample
35565(gdb)
35566-target-file-put localfile remotefile
35567^done
35568(gdb)
35569@end smallexample
35570
35571
1763a388 35572@subheading The @code{-target-file-get} Command
a6b151f1
DJ
35573@findex -target-file-get
35574
35575@subsubheading Synopsis
35576
35577@smallexample
35578 -target-file-get @var{targetfile} @var{hostfile}
35579@end smallexample
35580
35581Copy file @var{targetfile} from the target system to @var{hostfile}
35582on the host system.
35583
35584@subsubheading @value{GDBN} Command
35585
35586The corresponding @value{GDBN} command is @samp{remote get}.
35587
35588@subsubheading Example
35589
35590@smallexample
35591(gdb)
35592-target-file-get remotefile localfile
35593^done
35594(gdb)
35595@end smallexample
35596
35597
35598@subheading The @code{-target-file-delete} Command
35599@findex -target-file-delete
35600
35601@subsubheading Synopsis
35602
35603@smallexample
35604 -target-file-delete @var{targetfile}
35605@end smallexample
35606
35607Delete @var{targetfile} from the target system.
35608
35609@subsubheading @value{GDBN} Command
35610
35611The corresponding @value{GDBN} command is @samp{remote delete}.
35612
35613@subsubheading Example
35614
35615@smallexample
35616(gdb)
35617-target-file-delete remotefile
35618^done
35619(gdb)
35620@end smallexample
35621
35622
58d06528
JB
35623@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35624@node GDB/MI Ada Exceptions Commands
35625@section Ada Exceptions @sc{gdb/mi} Commands
35626
35627@subheading The @code{-info-ada-exceptions} Command
35628@findex -info-ada-exceptions
35629
35630@subsubheading Synopsis
35631
35632@smallexample
35633 -info-ada-exceptions [ @var{regexp}]
35634@end smallexample
35635
35636List all Ada exceptions defined within the program being debugged.
35637With a regular expression @var{regexp}, only those exceptions whose
35638names match @var{regexp} are listed.
35639
35640@subsubheading @value{GDBN} Command
35641
35642The corresponding @value{GDBN} command is @samp{info exceptions}.
35643
35644@subsubheading Result
35645
35646The result is a table of Ada exceptions. The following columns are
35647defined for each exception:
35648
35649@table @samp
35650@item name
35651The name of the exception.
35652
35653@item address
35654The address of the exception.
35655
35656@end table
35657
35658@subsubheading Example
35659
35660@smallexample
35661-info-ada-exceptions aint
35662^done,ada-exceptions=@{nr_rows="2",nr_cols="2",
35663hdr=[@{width="1",alignment="-1",col_name="name",colhdr="Name"@},
35664@{width="1",alignment="-1",col_name="address",colhdr="Address"@}],
35665body=[@{name="constraint_error",address="0x0000000000613da0"@},
35666@{name="const.aint_global_e",address="0x0000000000613b00"@}]@}
35667@end smallexample
35668
35669@subheading Catching Ada Exceptions
35670
35671The commands describing how to ask @value{GDBN} to stop when a program
35672raises an exception are described at @ref{Ada Exception GDB/MI
35673Catchpoint Commands}.
35674
35675
ef21caaf 35676@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d192b373
JB
35677@node GDB/MI Support Commands
35678@section @sc{gdb/mi} Support Commands
ef21caaf 35679
d192b373
JB
35680Since new commands and features get regularly added to @sc{gdb/mi},
35681some commands are available to help front-ends query the debugger
35682about support for these capabilities. Similarly, it is also possible
35683to query @value{GDBN} about target support of certain features.
ef21caaf 35684
6b7cbff1
JB
35685@subheading The @code{-info-gdb-mi-command} Command
35686@cindex @code{-info-gdb-mi-command}
35687@findex -info-gdb-mi-command
35688
35689@subsubheading Synopsis
35690
35691@smallexample
35692 -info-gdb-mi-command @var{cmd_name}
35693@end smallexample
35694
35695Query support for the @sc{gdb/mi} command named @var{cmd_name}.
35696
35697Note that the dash (@code{-}) starting all @sc{gdb/mi} commands
35698is technically not part of the command name (@pxref{GDB/MI Input
35699Syntax}), and thus should be omitted in @var{cmd_name}. However,
35700for ease of use, this command also accepts the form with the leading
35701dash.
35702
35703@subsubheading @value{GDBN} Command
35704
35705There is no corresponding @value{GDBN} command.
35706
35707@subsubheading Result
35708
35709The result is a tuple. There is currently only one field:
35710
35711@table @samp
35712@item exists
35713This field is equal to @code{"true"} if the @sc{gdb/mi} command exists,
35714@code{"false"} otherwise.
35715
35716@end table
35717
35718@subsubheading Example
35719
35720Here is an example where the @sc{gdb/mi} command does not exist:
35721
35722@smallexample
35723-info-gdb-mi-command unsupported-command
35724^done,command=@{exists="false"@}
35725@end smallexample
35726
35727@noindent
35728And here is an example where the @sc{gdb/mi} command is known
35729to the debugger:
35730
35731@smallexample
35732-info-gdb-mi-command symbol-list-lines
35733^done,command=@{exists="true"@}
35734@end smallexample
35735
084344da
VP
35736@subheading The @code{-list-features} Command
35737@findex -list-features
9b26f0fb 35738@cindex supported @sc{gdb/mi} features, list
084344da
VP
35739
35740Returns a list of particular features of the MI protocol that
35741this version of gdb implements. A feature can be a command,
35742or a new field in an output of some command, or even an
35743important bugfix. While a frontend can sometimes detect presence
35744of a feature at runtime, it is easier to perform detection at debugger
d192b373 35745startup.
084344da
VP
35746
35747The command returns a list of strings, with each string naming an
35748available feature. Each returned string is just a name, it does not
d192b373 35749have any internal structure. The list of possible feature names
084344da
VP
35750is given below.
35751
35752Example output:
35753
35754@smallexample
35755(gdb) -list-features
35756^done,result=["feature1","feature2"]
35757@end smallexample
35758
35759The current list of features is:
35760
edef6000 35761@ftable @samp
30e026bb 35762@item frozen-varobjs
a05336a1 35763Indicates support for the @code{-var-set-frozen} command, as well
6b92c0d3 35764as possible presence of the @code{frozen} field in the output
30e026bb
VP
35765of @code{-varobj-create}.
35766@item pending-breakpoints
a05336a1
JB
35767Indicates support for the @option{-f} option to the @code{-break-insert}
35768command.
b6313243 35769@item python
a05336a1 35770Indicates Python scripting support, Python-based
b6313243
TT
35771pretty-printing commands, and possible presence of the
35772@samp{display_hint} field in the output of @code{-var-list-children}
30e026bb 35773@item thread-info
a05336a1 35774Indicates support for the @code{-thread-info} command.
8dedea02 35775@item data-read-memory-bytes
a05336a1 35776Indicates support for the @code{-data-read-memory-bytes} and the
8dedea02 35777@code{-data-write-memory-bytes} commands.
39c4d40a
TT
35778@item breakpoint-notifications
35779Indicates that changes to breakpoints and breakpoints created via the
35780CLI will be announced via async records.
5d77fe44 35781@item ada-task-info
6adcee18 35782Indicates support for the @code{-ada-task-info} command.
422ad5c2
JB
35783@item language-option
35784Indicates that all @sc{gdb/mi} commands accept the @option{--language}
35785option (@pxref{Context management}).
6b7cbff1
JB
35786@item info-gdb-mi-command
35787Indicates support for the @code{-info-gdb-mi-command} command.
2ea126fa
JB
35788@item undefined-command-error-code
35789Indicates support for the "undefined-command" error code in error result
35790records, produced when trying to execute an undefined @sc{gdb/mi} command
35791(@pxref{GDB/MI Result Records}).
72bfa06c
JB
35792@item exec-run-start-option
35793Indicates that the @code{-exec-run} command supports the @option{--start}
35794option (@pxref{GDB/MI Program Execution}).
26fb3983
JV
35795@item data-disassemble-a-option
35796Indicates that the @code{-data-disassemble} command supports the @option{-a}
35797option (@pxref{GDB/MI Data Manipulation}).
edef6000 35798@end ftable
084344da 35799
c6ebd6cf
VP
35800@subheading The @code{-list-target-features} Command
35801@findex -list-target-features
35802
35803Returns a list of particular features that are supported by the
35804target. Those features affect the permitted MI commands, but
35805unlike the features reported by the @code{-list-features} command, the
35806features depend on which target GDB is using at the moment. Whenever
35807a target can change, due to commands such as @code{-target-select},
35808@code{-target-attach} or @code{-exec-run}, the list of target features
35809may change, and the frontend should obtain it again.
35810Example output:
35811
35812@smallexample
b3d3b4bd 35813(gdb) -list-target-features
c6ebd6cf
VP
35814^done,result=["async"]
35815@end smallexample
35816
35817The current list of features is:
35818
35819@table @samp
35820@item async
35821Indicates that the target is capable of asynchronous command
35822execution, which means that @value{GDBN} will accept further commands
35823while the target is running.
35824
f75d858b
MK
35825@item reverse
35826Indicates that the target is capable of reverse execution.
35827@xref{Reverse Execution}, for more information.
35828
c6ebd6cf
VP
35829@end table
35830
d192b373
JB
35831@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35832@node GDB/MI Miscellaneous Commands
35833@section Miscellaneous @sc{gdb/mi} Commands
35834
35835@c @subheading -gdb-complete
35836
35837@subheading The @code{-gdb-exit} Command
35838@findex -gdb-exit
35839
35840@subsubheading Synopsis
35841
35842@smallexample
35843 -gdb-exit
35844@end smallexample
35845
35846Exit @value{GDBN} immediately.
35847
35848@subsubheading @value{GDBN} Command
35849
35850Approximately corresponds to @samp{quit}.
35851
35852@subsubheading Example
35853
35854@smallexample
35855(gdb)
35856-gdb-exit
35857^exit
35858@end smallexample
35859
35860
35861@ignore
35862@subheading The @code{-exec-abort} Command
35863@findex -exec-abort
35864
35865@subsubheading Synopsis
35866
35867@smallexample
35868 -exec-abort
35869@end smallexample
35870
35871Kill the inferior running program.
35872
35873@subsubheading @value{GDBN} Command
35874
35875The corresponding @value{GDBN} command is @samp{kill}.
35876
35877@subsubheading Example
35878N.A.
35879@end ignore
35880
35881
35882@subheading The @code{-gdb-set} Command
35883@findex -gdb-set
35884
35885@subsubheading Synopsis
35886
35887@smallexample
35888 -gdb-set
35889@end smallexample
35890
35891Set an internal @value{GDBN} variable.
35892@c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
35893
35894@subsubheading @value{GDBN} Command
35895
35896The corresponding @value{GDBN} command is @samp{set}.
35897
35898@subsubheading Example
35899
35900@smallexample
35901(gdb)
35902-gdb-set $foo=3
35903^done
35904(gdb)
35905@end smallexample
35906
35907
35908@subheading The @code{-gdb-show} Command
35909@findex -gdb-show
35910
35911@subsubheading Synopsis
35912
35913@smallexample
35914 -gdb-show
35915@end smallexample
35916
35917Show the current value of a @value{GDBN} variable.
35918
35919@subsubheading @value{GDBN} Command
35920
35921The corresponding @value{GDBN} command is @samp{show}.
35922
35923@subsubheading Example
35924
35925@smallexample
35926(gdb)
35927-gdb-show annotate
35928^done,value="0"
35929(gdb)
35930@end smallexample
35931
35932@c @subheading -gdb-source
35933
35934
35935@subheading The @code{-gdb-version} Command
35936@findex -gdb-version
35937
35938@subsubheading Synopsis
35939
35940@smallexample
35941 -gdb-version
35942@end smallexample
35943
35944Show version information for @value{GDBN}. Used mostly in testing.
35945
35946@subsubheading @value{GDBN} Command
35947
35948The @value{GDBN} equivalent is @samp{show version}. @value{GDBN} by
35949default shows this information when you start an interactive session.
35950
35951@subsubheading Example
35952
35953@c This example modifies the actual output from GDB to avoid overfull
35954@c box in TeX.
35955@smallexample
35956(gdb)
35957-gdb-version
35958~GNU gdb 5.2.1
35959~Copyright 2000 Free Software Foundation, Inc.
35960~GDB is free software, covered by the GNU General Public License, and
35961~you are welcome to change it and/or distribute copies of it under
35962~ certain conditions.
35963~Type "show copying" to see the conditions.
35964~There is absolutely no warranty for GDB. Type "show warranty" for
35965~ details.
35966~This GDB was configured as
35967 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
35968^done
35969(gdb)
35970@end smallexample
35971
c3b108f7
VP
35972@subheading The @code{-list-thread-groups} Command
35973@findex -list-thread-groups
35974
35975@subheading Synopsis
35976
35977@smallexample
dc146f7c 35978-list-thread-groups [ --available ] [ --recurse 1 ] [ @var{group} ... ]
c3b108f7
VP
35979@end smallexample
35980
dc146f7c
VP
35981Lists thread groups (@pxref{Thread groups}). When a single thread
35982group is passed as the argument, lists the children of that group.
35983When several thread group are passed, lists information about those
35984thread groups. Without any parameters, lists information about all
35985top-level thread groups.
35986
35987Normally, thread groups that are being debugged are reported.
35988With the @samp{--available} option, @value{GDBN} reports thread groups
35989available on the target.
35990
35991The output of this command may have either a @samp{threads} result or
35992a @samp{groups} result. The @samp{thread} result has a list of tuples
35993as value, with each tuple describing a thread (@pxref{GDB/MI Thread
35994Information}). The @samp{groups} result has a list of tuples as value,
35995each tuple describing a thread group. If top-level groups are
35996requested (that is, no parameter is passed), or when several groups
35997are passed, the output always has a @samp{groups} result. The format
35998of the @samp{group} result is described below.
35999
36000To reduce the number of roundtrips it's possible to list thread groups
36001together with their children, by passing the @samp{--recurse} option
36002and the recursion depth. Presently, only recursion depth of 1 is
36003permitted. If this option is present, then every reported thread group
36004will also include its children, either as @samp{group} or
36005@samp{threads} field.
36006
36007In general, any combination of option and parameters is permitted, with
36008the following caveats:
36009
36010@itemize @bullet
36011@item
36012When a single thread group is passed, the output will typically
36013be the @samp{threads} result. Because threads may not contain
36014anything, the @samp{recurse} option will be ignored.
36015
36016@item
36017When the @samp{--available} option is passed, limited information may
36018be available. In particular, the list of threads of a process might
36019be inaccessible. Further, specifying specific thread groups might
36020not give any performance advantage over listing all thread groups.
36021The frontend should assume that @samp{-list-thread-groups --available}
36022is always an expensive operation and cache the results.
36023
36024@end itemize
36025
36026The @samp{groups} result is a list of tuples, where each tuple may
36027have the following fields:
36028
36029@table @code
36030@item id
36031Identifier of the thread group. This field is always present.
a79b8f6e
VP
36032The identifier is an opaque string; frontends should not try to
36033convert it to an integer, even though it might look like one.
dc146f7c
VP
36034
36035@item type
36036The type of the thread group. At present, only @samp{process} is a
36037valid type.
36038
36039@item pid
36040The target-specific process identifier. This field is only present
a79b8f6e 36041for thread groups of type @samp{process} and only if the process exists.
c3b108f7 36042
2ddf4301
SM
36043@item exit-code
36044The exit code of this group's last exited thread, formatted in octal.
36045This field is only present for thread groups of type @samp{process} and
36046only if the process is not running.
36047
dc146f7c
VP
36048@item num_children
36049The number of children this thread group has. This field may be
36050absent for an available thread group.
36051
36052@item threads
36053This field has a list of tuples as value, each tuple describing a
36054thread. It may be present if the @samp{--recurse} option is
36055specified, and it's actually possible to obtain the threads.
36056
36057@item cores
36058This field is a list of integers, each identifying a core that one
36059thread of the group is running on. This field may be absent if
36060such information is not available.
36061
a79b8f6e
VP
36062@item executable
36063The name of the executable file that corresponds to this thread group.
36064The field is only present for thread groups of type @samp{process},
36065and only if there is a corresponding executable file.
36066
dc146f7c 36067@end table
c3b108f7
VP
36068
36069@subheading Example
36070
36071@smallexample
36072@value{GDBP}
36073-list-thread-groups
36074^done,groups=[@{id="17",type="process",pid="yyy",num_children="2"@}]
36075-list-thread-groups 17
36076^done,threads=[@{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
36077 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",args=[]@},state="running"@},
36078@{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
36079 frame=@{level="0",addr="0x0804891f",func="foo",args=[@{name="i",value="10"@}],
6d52907e 36080 file="/tmp/a.c",fullname="/tmp/a.c",line="158",arch="i386:x86_64"@},state="running"@}]]
dc146f7c
VP
36081-list-thread-groups --available
36082^done,groups=[@{id="17",type="process",pid="yyy",num_children="2",cores=[1,2]@}]
36083-list-thread-groups --available --recurse 1
36084 ^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
36085 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
36086 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},..]
36087-list-thread-groups --available --recurse 1 17 18
36088^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
36089 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
36090 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},...]
c3b108f7 36091@end smallexample
c6ebd6cf 36092
f3e0e960
SS
36093@subheading The @code{-info-os} Command
36094@findex -info-os
36095
36096@subsubheading Synopsis
36097
36098@smallexample
36099-info-os [ @var{type} ]
36100@end smallexample
36101
36102If no argument is supplied, the command returns a table of available
36103operating-system-specific information types. If one of these types is
36104supplied as an argument @var{type}, then the command returns a table
36105of data of that type.
36106
36107The types of information available depend on the target operating
36108system.
36109
36110@subsubheading @value{GDBN} Command
36111
36112The corresponding @value{GDBN} command is @samp{info os}.
36113
36114@subsubheading Example
36115
36116When run on a @sc{gnu}/Linux system, the output will look something
36117like this:
36118
36119@smallexample
36120@value{GDBP}
36121-info-os
d33279b3 36122^done,OSDataTable=@{nr_rows="10",nr_cols="3",
f3e0e960 36123hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="Type"@},
71caed83
SS
36124 @{width="10",alignment="-1",col_name="col1",colhdr="Description"@},
36125 @{width="10",alignment="-1",col_name="col2",colhdr="Title"@}],
d33279b3
AT
36126body=[item=@{col0="cpus",col1="Listing of all cpus/cores on the system",
36127 col2="CPUs"@},
36128 item=@{col0="files",col1="Listing of all file descriptors",
36129 col2="File descriptors"@},
36130 item=@{col0="modules",col1="Listing of all loaded kernel modules",
36131 col2="Kernel modules"@},
36132 item=@{col0="msg",col1="Listing of all message queues",
36133 col2="Message queues"@},
36134 item=@{col0="processes",col1="Listing of all processes",
71caed83
SS
36135 col2="Processes"@},
36136 item=@{col0="procgroups",col1="Listing of all process groups",
36137 col2="Process groups"@},
71caed83
SS
36138 item=@{col0="semaphores",col1="Listing of all semaphores",
36139 col2="Semaphores"@},
d33279b3
AT
36140 item=@{col0="shm",col1="Listing of all shared-memory regions",
36141 col2="Shared-memory regions"@},
36142 item=@{col0="sockets",col1="Listing of all internet-domain sockets",
36143 col2="Sockets"@},
36144 item=@{col0="threads",col1="Listing of all threads",
36145 col2="Threads"@}]
f3e0e960
SS
36146@value{GDBP}
36147-info-os processes
36148^done,OSDataTable=@{nr_rows="190",nr_cols="4",
36149hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="pid"@},
36150 @{width="10",alignment="-1",col_name="col1",colhdr="user"@},
36151 @{width="10",alignment="-1",col_name="col2",colhdr="command"@},
36152 @{width="10",alignment="-1",col_name="col3",colhdr="cores"@}],
36153body=[item=@{col0="1",col1="root",col2="/sbin/init",col3="0"@},
36154 item=@{col0="2",col1="root",col2="[kthreadd]",col3="1"@},
36155 item=@{col0="3",col1="root",col2="[ksoftirqd/0]",col3="0"@},
36156 ...
36157 item=@{col0="26446",col1="stan",col2="bash",col3="0"@},
36158 item=@{col0="28152",col1="stan",col2="bash",col3="1"@}]@}
36159(gdb)
36160@end smallexample
a79b8f6e 36161
71caed83
SS
36162(Note that the MI output here includes a @code{"Title"} column that
36163does not appear in command-line @code{info os}; this column is useful
36164for MI clients that want to enumerate the types of data, such as in a
36165popup menu, but is needless clutter on the command line, and
36166@code{info os} omits it.)
36167
a79b8f6e
VP
36168@subheading The @code{-add-inferior} Command
36169@findex -add-inferior
36170
36171@subheading Synopsis
36172
36173@smallexample
36174-add-inferior
36175@end smallexample
36176
65c574f6 36177Creates a new inferior (@pxref{Inferiors Connections and Programs}). The created
a79b8f6e
VP
36178inferior is not associated with any executable. Such association may
36179be established with the @samp{-file-exec-and-symbols} command
36180(@pxref{GDB/MI File Commands}). The command response has a single
b7742092 36181field, @samp{inferior}, whose value is the identifier of the
a79b8f6e
VP
36182thread group corresponding to the new inferior.
36183
36184@subheading Example
36185
36186@smallexample
36187@value{GDBP}
36188-add-inferior
b7742092 36189^done,inferior="i3"
a79b8f6e
VP
36190@end smallexample
36191
ef21caaf
NR
36192@subheading The @code{-interpreter-exec} Command
36193@findex -interpreter-exec
36194
36195@subheading Synopsis
36196
36197@smallexample
36198-interpreter-exec @var{interpreter} @var{command}
36199@end smallexample
a2c02241 36200@anchor{-interpreter-exec}
ef21caaf
NR
36201
36202Execute the specified @var{command} in the given @var{interpreter}.
36203
36204@subheading @value{GDBN} Command
36205
36206The corresponding @value{GDBN} command is @samp{interpreter-exec}.
36207
36208@subheading Example
36209
36210@smallexample
594fe323 36211(gdb)
ef21caaf
NR
36212-interpreter-exec console "break main"
36213&"During symbol reading, couldn't parse type; debugger out of date?.\n"
36214&"During symbol reading, bad structure-type format.\n"
36215~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
36216^done
594fe323 36217(gdb)
ef21caaf
NR
36218@end smallexample
36219
36220@subheading The @code{-inferior-tty-set} Command
36221@findex -inferior-tty-set
36222
36223@subheading Synopsis
36224
36225@smallexample
36226-inferior-tty-set /dev/pts/1
36227@end smallexample
36228
36229Set terminal for future runs of the program being debugged.
36230
36231@subheading @value{GDBN} Command
36232
36233The corresponding @value{GDBN} command is @samp{set inferior-tty} /dev/pts/1.
36234
36235@subheading Example
36236
36237@smallexample
594fe323 36238(gdb)
ef21caaf
NR
36239-inferior-tty-set /dev/pts/1
36240^done
594fe323 36241(gdb)
ef21caaf
NR
36242@end smallexample
36243
36244@subheading The @code{-inferior-tty-show} Command
36245@findex -inferior-tty-show
36246
36247@subheading Synopsis
36248
36249@smallexample
36250-inferior-tty-show
36251@end smallexample
36252
36253Show terminal for future runs of program being debugged.
36254
36255@subheading @value{GDBN} Command
36256
36257The corresponding @value{GDBN} command is @samp{show inferior-tty}.
36258
36259@subheading Example
36260
36261@smallexample
594fe323 36262(gdb)
ef21caaf
NR
36263-inferior-tty-set /dev/pts/1
36264^done
594fe323 36265(gdb)
ef21caaf
NR
36266-inferior-tty-show
36267^done,inferior_tty_terminal="/dev/pts/1"
594fe323 36268(gdb)
ef21caaf 36269@end smallexample
922fbb7b 36270
a4eefcd8
NR
36271@subheading The @code{-enable-timings} Command
36272@findex -enable-timings
36273
36274@subheading Synopsis
36275
36276@smallexample
36277-enable-timings [yes | no]
36278@end smallexample
36279
36280Toggle the printing of the wallclock, user and system times for an MI
36281command as a field in its output. This command is to help frontend
36282developers optimize the performance of their code. No argument is
36283equivalent to @samp{yes}.
36284
36285@subheading @value{GDBN} Command
36286
36287No equivalent.
36288
36289@subheading Example
36290
36291@smallexample
36292(gdb)
36293-enable-timings
36294^done
36295(gdb)
36296-break-insert main
36297^done,bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
36298addr="0x080484ed",func="main",file="myprog.c",
998580f1
MK
36299fullname="/home/nickrob/myprog.c",line="73",thread-groups=["i1"],
36300times="0"@},
a4eefcd8
NR
36301time=@{wallclock="0.05185",user="0.00800",system="0.00000"@}
36302(gdb)
36303-enable-timings no
36304^done
36305(gdb)
36306-exec-run
36307^running
36308(gdb)
a47ec5fe 36309*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
a4eefcd8
NR
36310frame=@{addr="0x080484ed",func="main",args=[@{name="argc",value="1"@},
36311@{name="argv",value="0xbfb60364"@}],file="myprog.c",
6d52907e 36312fullname="/home/nickrob/myprog.c",line="73",arch="i386:x86_64"@}
a4eefcd8
NR
36313(gdb)
36314@end smallexample
36315
26648588
JV
36316@subheading The @code{-complete} Command
36317@findex -complete
36318
36319@subheading Synopsis
36320
36321@smallexample
36322-complete @var{command}
36323@end smallexample
36324
36325Show a list of completions for partially typed CLI @var{command}.
36326
36327This command is intended for @sc{gdb/mi} frontends that cannot use two separate
7166f90a 36328CLI and MI channels --- for example: because of lack of PTYs like on Windows or
26648588
JV
36329because @value{GDBN} is used remotely via a SSH connection.
36330
36331@subheading Result
36332
36333The result consists of two or three fields:
36334
36335@table @samp
36336@item completion
36337This field contains the completed @var{command}. If @var{command}
36338has no known completions, this field is omitted.
36339
36340@item matches
36341This field contains a (possibly empty) array of matches. It is always present.
36342
36343@item max_completions_reached
36344This field contains @code{1} if number of known completions is above
7166f90a 36345@code{max-completions} limit (@pxref{Completion}), otherwise it contains
26648588
JV
36346@code{0}. It is always present.
36347
36348@end table
36349
36350@subheading @value{GDBN} Command
36351
36352The corresponding @value{GDBN} command is @samp{complete}.
36353
36354@subheading Example
36355
36356@smallexample
36357(gdb)
36358-complete br
36359^done,completion="break",
36360 matches=["break","break-range"],
36361 max_completions_reached="0"
36362(gdb)
36363-complete "b ma"
36364^done,completion="b ma",
36365 matches=["b madvise","b main"],max_completions_reached="0"
36366(gdb)
36367-complete "b push_b"
36368^done,completion="b push_back(",
36369 matches=[
36370 "b A::push_back(void*)",
36371 "b std::string::push_back(char)",
36372 "b std::vector<int, std::allocator<int> >::push_back(int&&)"],
36373 max_completions_reached="0"
36374(gdb)
36375-complete "nonexist"
36376^done,matches=[],max_completions_reached="0"
36377(gdb)
36378
36379@end smallexample
36380
922fbb7b
AC
36381@node Annotations
36382@chapter @value{GDBN} Annotations
36383
086432e2
AC
36384This chapter describes annotations in @value{GDBN}. Annotations were
36385designed to interface @value{GDBN} to graphical user interfaces or other
36386similar programs which want to interact with @value{GDBN} at a
922fbb7b
AC
36387relatively high level.
36388
d3e8051b 36389The annotation mechanism has largely been superseded by @sc{gdb/mi}
086432e2
AC
36390(@pxref{GDB/MI}).
36391
922fbb7b
AC
36392@ignore
36393This is Edition @value{EDITION}, @value{DATE}.
36394@end ignore
36395
36396@menu
36397* Annotations Overview:: What annotations are; the general syntax.
9e6c4bd5 36398* Server Prefix:: Issuing a command without affecting user state.
922fbb7b
AC
36399* Prompting:: Annotations marking @value{GDBN}'s need for input.
36400* Errors:: Annotations for error messages.
922fbb7b
AC
36401* Invalidation:: Some annotations describe things now invalid.
36402* Annotations for Running::
36403 Whether the program is running, how it stopped, etc.
36404* Source Annotations:: Annotations describing source code.
922fbb7b
AC
36405@end menu
36406
36407@node Annotations Overview
36408@section What is an Annotation?
36409@cindex annotations
36410
922fbb7b
AC
36411Annotations start with a newline character, two @samp{control-z}
36412characters, and the name of the annotation. If there is no additional
36413information associated with this annotation, the name of the annotation
36414is followed immediately by a newline. If there is additional
36415information, the name of the annotation is followed by a space, the
36416additional information, and a newline. The additional information
36417cannot contain newline characters.
36418
36419Any output not beginning with a newline and two @samp{control-z}
36420characters denotes literal output from @value{GDBN}. Currently there is
36421no need for @value{GDBN} to output a newline followed by two
36422@samp{control-z} characters, but if there was such a need, the
36423annotations could be extended with an @samp{escape} annotation which
36424means those three characters as output.
36425
086432e2
AC
36426The annotation @var{level}, which is specified using the
36427@option{--annotate} command line option (@pxref{Mode Options}), controls
36428how much information @value{GDBN} prints together with its prompt,
36429values of expressions, source lines, and other types of output. Level 0
d3e8051b 36430is for no annotations, level 1 is for use when @value{GDBN} is run as a
086432e2
AC
36431subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
36432for programs that control @value{GDBN}, and level 2 annotations have
36433been made obsolete (@pxref{Limitations, , Limitations of the Annotation
09d4efe1
EZ
36434Interface, annotate, GDB's Obsolete Annotations}).
36435
36436@table @code
36437@kindex set annotate
36438@item set annotate @var{level}
e09f16f9 36439The @value{GDBN} command @code{set annotate} sets the level of
09d4efe1 36440annotations to the specified @var{level}.
9c16f35a
EZ
36441
36442@item show annotate
36443@kindex show annotate
36444Show the current annotation level.
09d4efe1
EZ
36445@end table
36446
36447This chapter describes level 3 annotations.
086432e2 36448
922fbb7b
AC
36449A simple example of starting up @value{GDBN} with annotations is:
36450
36451@smallexample
086432e2
AC
36452$ @kbd{gdb --annotate=3}
36453GNU gdb 6.0
36454Copyright 2003 Free Software Foundation, Inc.
922fbb7b
AC
36455GDB is free software, covered by the GNU General Public License,
36456and you are welcome to change it and/or distribute copies of it
36457under certain conditions.
36458Type "show copying" to see the conditions.
36459There is absolutely no warranty for GDB. Type "show warranty"
36460for details.
086432e2 36461This GDB was configured as "i386-pc-linux-gnu"
922fbb7b
AC
36462
36463^Z^Zpre-prompt
f7dc1244 36464(@value{GDBP})
922fbb7b 36465^Z^Zprompt
086432e2 36466@kbd{quit}
922fbb7b
AC
36467
36468^Z^Zpost-prompt
b383017d 36469$
922fbb7b
AC
36470@end smallexample
36471
36472Here @samp{quit} is input to @value{GDBN}; the rest is output from
36473@value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
36474denotes a @samp{control-z} character) are annotations; the rest is
36475output from @value{GDBN}.
36476
9e6c4bd5
NR
36477@node Server Prefix
36478@section The Server Prefix
36479@cindex server prefix
36480
36481If you prefix a command with @samp{server } then it will not affect
36482the command history, nor will it affect @value{GDBN}'s notion of which
36483command to repeat if @key{RET} is pressed on a line by itself. This
36484means that commands can be run behind a user's back by a front-end in
36485a transparent manner.
36486
d837706a
NR
36487The @code{server } prefix does not affect the recording of values into
36488the value history; to print a value without recording it into the
36489value history, use the @code{output} command instead of the
36490@code{print} command.
36491
36492Using this prefix also disables confirmation requests
36493(@pxref{confirmation requests}).
9e6c4bd5 36494
922fbb7b
AC
36495@node Prompting
36496@section Annotation for @value{GDBN} Input
36497
36498@cindex annotations for prompts
36499When @value{GDBN} prompts for input, it annotates this fact so it is possible
36500to know when to send output, when the output from a given command is
36501over, etc.
36502
36503Different kinds of input each have a different @dfn{input type}. Each
36504input type has three annotations: a @code{pre-} annotation, which
36505denotes the beginning of any prompt which is being output, a plain
36506annotation, which denotes the end of the prompt, and then a @code{post-}
36507annotation which denotes the end of any echo which may (or may not) be
36508associated with the input. For example, the @code{prompt} input type
36509features the following annotations:
36510
36511@smallexample
36512^Z^Zpre-prompt
36513^Z^Zprompt
36514^Z^Zpost-prompt
36515@end smallexample
36516
36517The input types are
36518
36519@table @code
e5ac9b53
EZ
36520@findex pre-prompt annotation
36521@findex prompt annotation
36522@findex post-prompt annotation
922fbb7b
AC
36523@item prompt
36524When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
36525
e5ac9b53
EZ
36526@findex pre-commands annotation
36527@findex commands annotation
36528@findex post-commands annotation
922fbb7b
AC
36529@item commands
36530When @value{GDBN} prompts for a set of commands, like in the @code{commands}
36531command. The annotations are repeated for each command which is input.
36532
e5ac9b53
EZ
36533@findex pre-overload-choice annotation
36534@findex overload-choice annotation
36535@findex post-overload-choice annotation
922fbb7b
AC
36536@item overload-choice
36537When @value{GDBN} wants the user to select between various overloaded functions.
36538
e5ac9b53
EZ
36539@findex pre-query annotation
36540@findex query annotation
36541@findex post-query annotation
922fbb7b
AC
36542@item query
36543When @value{GDBN} wants the user to confirm a potentially dangerous operation.
36544
e5ac9b53
EZ
36545@findex pre-prompt-for-continue annotation
36546@findex prompt-for-continue annotation
36547@findex post-prompt-for-continue annotation
922fbb7b
AC
36548@item prompt-for-continue
36549When @value{GDBN} is asking the user to press return to continue. Note: Don't
36550expect this to work well; instead use @code{set height 0} to disable
36551prompting. This is because the counting of lines is buggy in the
36552presence of annotations.
36553@end table
36554
36555@node Errors
36556@section Errors
36557@cindex annotations for errors, warnings and interrupts
36558
e5ac9b53 36559@findex quit annotation
922fbb7b
AC
36560@smallexample
36561^Z^Zquit
36562@end smallexample
36563
36564This annotation occurs right before @value{GDBN} responds to an interrupt.
36565
e5ac9b53 36566@findex error annotation
922fbb7b
AC
36567@smallexample
36568^Z^Zerror
36569@end smallexample
36570
36571This annotation occurs right before @value{GDBN} responds to an error.
36572
36573Quit and error annotations indicate that any annotations which @value{GDBN} was
36574in the middle of may end abruptly. For example, if a
36575@code{value-history-begin} annotation is followed by a @code{error}, one
36576cannot expect to receive the matching @code{value-history-end}. One
36577cannot expect not to receive it either, however; an error annotation
36578does not necessarily mean that @value{GDBN} is immediately returning all the way
36579to the top level.
36580
e5ac9b53 36581@findex error-begin annotation
922fbb7b
AC
36582A quit or error annotation may be preceded by
36583
36584@smallexample
36585^Z^Zerror-begin
36586@end smallexample
36587
36588Any output between that and the quit or error annotation is the error
36589message.
36590
36591Warning messages are not yet annotated.
36592@c If we want to change that, need to fix warning(), type_error(),
36593@c range_error(), and possibly other places.
36594
922fbb7b
AC
36595@node Invalidation
36596@section Invalidation Notices
36597
36598@cindex annotations for invalidation messages
36599The following annotations say that certain pieces of state may have
36600changed.
36601
36602@table @code
e5ac9b53 36603@findex frames-invalid annotation
922fbb7b
AC
36604@item ^Z^Zframes-invalid
36605
36606The frames (for example, output from the @code{backtrace} command) may
36607have changed.
36608
e5ac9b53 36609@findex breakpoints-invalid annotation
922fbb7b
AC
36610@item ^Z^Zbreakpoints-invalid
36611
36612The breakpoints may have changed. For example, the user just added or
36613deleted a breakpoint.
36614@end table
36615
36616@node Annotations for Running
36617@section Running the Program
36618@cindex annotations for running programs
36619
e5ac9b53
EZ
36620@findex starting annotation
36621@findex stopping annotation
922fbb7b 36622When the program starts executing due to a @value{GDBN} command such as
b383017d 36623@code{step} or @code{continue},
922fbb7b
AC
36624
36625@smallexample
36626^Z^Zstarting
36627@end smallexample
36628
b383017d 36629is output. When the program stops,
922fbb7b
AC
36630
36631@smallexample
36632^Z^Zstopped
36633@end smallexample
36634
36635is output. Before the @code{stopped} annotation, a variety of
36636annotations describe how the program stopped.
36637
36638@table @code
e5ac9b53 36639@findex exited annotation
922fbb7b
AC
36640@item ^Z^Zexited @var{exit-status}
36641The program exited, and @var{exit-status} is the exit status (zero for
36642successful exit, otherwise nonzero).
36643
e5ac9b53
EZ
36644@findex signalled annotation
36645@findex signal-name annotation
36646@findex signal-name-end annotation
36647@findex signal-string annotation
36648@findex signal-string-end annotation
922fbb7b
AC
36649@item ^Z^Zsignalled
36650The program exited with a signal. After the @code{^Z^Zsignalled}, the
36651annotation continues:
36652
36653@smallexample
36654@var{intro-text}
36655^Z^Zsignal-name
36656@var{name}
36657^Z^Zsignal-name-end
36658@var{middle-text}
36659^Z^Zsignal-string
36660@var{string}
36661^Z^Zsignal-string-end
36662@var{end-text}
36663@end smallexample
36664
36665@noindent
36666where @var{name} is the name of the signal, such as @code{SIGILL} or
36667@code{SIGSEGV}, and @var{string} is the explanation of the signal, such
697aa1b7 36668as @code{Illegal Instruction} or @code{Segmentation fault}. The arguments
922fbb7b
AC
36669@var{intro-text}, @var{middle-text}, and @var{end-text} are for the
36670user's benefit and have no particular format.
36671
e5ac9b53 36672@findex signal annotation
922fbb7b
AC
36673@item ^Z^Zsignal
36674The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
36675just saying that the program received the signal, not that it was
36676terminated with it.
36677
e5ac9b53 36678@findex breakpoint annotation
922fbb7b
AC
36679@item ^Z^Zbreakpoint @var{number}
36680The program hit breakpoint number @var{number}.
36681
e5ac9b53 36682@findex watchpoint annotation
922fbb7b
AC
36683@item ^Z^Zwatchpoint @var{number}
36684The program hit watchpoint number @var{number}.
36685@end table
36686
36687@node Source Annotations
36688@section Displaying Source
36689@cindex annotations for source display
36690
e5ac9b53 36691@findex source annotation
922fbb7b
AC
36692The following annotation is used instead of displaying source code:
36693
36694@smallexample
36695^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
36696@end smallexample
36697
36698where @var{filename} is an absolute file name indicating which source
36699file, @var{line} is the line number within that file (where 1 is the
36700first line in the file), @var{character} is the character position
36701within the file (where 0 is the first character in the file) (for most
36702debug formats this will necessarily point to the beginning of a line),
36703@var{middle} is @samp{middle} if @var{addr} is in the middle of the
36704line, or @samp{beg} if @var{addr} is at the beginning of the line, and
36705@var{addr} is the address in the target program associated with the
697aa1b7 36706source which is being displayed. The @var{addr} is in the form @samp{0x}
922fbb7b
AC
36707followed by one or more lowercase hex digits (note that this does not
36708depend on the language).
36709
4efc6507
DE
36710@node JIT Interface
36711@chapter JIT Compilation Interface
36712@cindex just-in-time compilation
36713@cindex JIT compilation interface
36714
36715This chapter documents @value{GDBN}'s @dfn{just-in-time} (JIT) compilation
36716interface. A JIT compiler is a program or library that generates native
36717executable code at runtime and executes it, usually in order to achieve good
36718performance while maintaining platform independence.
36719
36720Programs that use JIT compilation are normally difficult to debug because
36721portions of their code are generated at runtime, instead of being loaded from
36722object files, which is where @value{GDBN} normally finds the program's symbols
36723and debug information. In order to debug programs that use JIT compilation,
36724@value{GDBN} has an interface that allows the program to register in-memory
36725symbol files with @value{GDBN} at runtime.
36726
36727If you are using @value{GDBN} to debug a program that uses this interface, then
36728it should work transparently so long as you have not stripped the binary. If
36729you are developing a JIT compiler, then the interface is documented in the rest
36730of this chapter. At this time, the only known client of this interface is the
36731LLVM JIT.
36732
36733Broadly speaking, the JIT interface mirrors the dynamic loader interface. The
36734JIT compiler communicates with @value{GDBN} by writing data into a global
6b92c0d3 36735variable and calling a function at a well-known symbol. When @value{GDBN}
4efc6507
DE
36736attaches, it reads a linked list of symbol files from the global variable to
36737find existing code, and puts a breakpoint in the function so that it can find
36738out about additional code.
36739
36740@menu
36741* Declarations:: Relevant C struct declarations
36742* Registering Code:: Steps to register code
36743* Unregistering Code:: Steps to unregister code
f85b53f8 36744* Custom Debug Info:: Emit debug information in a custom format
4efc6507
DE
36745@end menu
36746
36747@node Declarations
36748@section JIT Declarations
36749
36750These are the relevant struct declarations that a C program should include to
36751implement the interface:
36752
36753@smallexample
36754typedef enum
36755@{
36756 JIT_NOACTION = 0,
36757 JIT_REGISTER_FN,
36758 JIT_UNREGISTER_FN
36759@} jit_actions_t;
36760
36761struct jit_code_entry
36762@{
36763 struct jit_code_entry *next_entry;
36764 struct jit_code_entry *prev_entry;
36765 const char *symfile_addr;
36766 uint64_t symfile_size;
36767@};
36768
36769struct jit_descriptor
36770@{
36771 uint32_t version;
36772 /* This type should be jit_actions_t, but we use uint32_t
36773 to be explicit about the bitwidth. */
36774 uint32_t action_flag;
36775 struct jit_code_entry *relevant_entry;
36776 struct jit_code_entry *first_entry;
36777@};
36778
36779/* GDB puts a breakpoint in this function. */
36780void __attribute__((noinline)) __jit_debug_register_code() @{ @};
36781
36782/* Make sure to specify the version statically, because the
36783 debugger may check the version before we can set it. */
36784struct jit_descriptor __jit_debug_descriptor = @{ 1, 0, 0, 0 @};
36785@end smallexample
36786
36787If the JIT is multi-threaded, then it is important that the JIT synchronize any
36788modifications to this global data properly, which can easily be done by putting
36789a global mutex around modifications to these structures.
36790
36791@node Registering Code
36792@section Registering Code
36793
36794To register code with @value{GDBN}, the JIT should follow this protocol:
36795
36796@itemize @bullet
36797@item
36798Generate an object file in memory with symbols and other desired debug
36799information. The file must include the virtual addresses of the sections.
36800
36801@item
36802Create a code entry for the file, which gives the start and size of the symbol
36803file.
36804
36805@item
36806Add it to the linked list in the JIT descriptor.
36807
36808@item
36809Point the relevant_entry field of the descriptor at the entry.
36810
36811@item
36812Set @code{action_flag} to @code{JIT_REGISTER} and call
36813@code{__jit_debug_register_code}.
36814@end itemize
36815
36816When @value{GDBN} is attached and the breakpoint fires, @value{GDBN} uses the
36817@code{relevant_entry} pointer so it doesn't have to walk the list looking for
36818new code. However, the linked list must still be maintained in order to allow
36819@value{GDBN} to attach to a running process and still find the symbol files.
36820
36821@node Unregistering Code
36822@section Unregistering Code
36823
36824If code is freed, then the JIT should use the following protocol:
36825
36826@itemize @bullet
36827@item
36828Remove the code entry corresponding to the code from the linked list.
36829
36830@item
36831Point the @code{relevant_entry} field of the descriptor at the code entry.
36832
36833@item
36834Set @code{action_flag} to @code{JIT_UNREGISTER} and call
36835@code{__jit_debug_register_code}.
36836@end itemize
36837
36838If the JIT frees or recompiles code without unregistering it, then @value{GDBN}
36839and the JIT will leak the memory used for the associated symbol files.
36840
f85b53f8
SD
36841@node Custom Debug Info
36842@section Custom Debug Info
36843@cindex custom JIT debug info
36844@cindex JIT debug info reader
36845
36846Generating debug information in platform-native file formats (like ELF
36847or COFF) may be an overkill for JIT compilers; especially if all the
36848debug info is used for is displaying a meaningful backtrace. The
36849issue can be resolved by having the JIT writers decide on a debug info
36850format and also provide a reader that parses the debug info generated
36851by the JIT compiler. This section gives a brief overview on writing
36852such a parser. More specific details can be found in the source file
36853@file{gdb/jit-reader.in}, which is also installed as a header at
36854@file{@var{includedir}/gdb/jit-reader.h} for easy inclusion.
36855
36856The reader is implemented as a shared object (so this functionality is
36857not available on platforms which don't allow loading shared objects at
36858runtime). Two @value{GDBN} commands, @code{jit-reader-load} and
36859@code{jit-reader-unload} are provided, to be used to load and unload
36860the readers from a preconfigured directory. Once loaded, the shared
36861object is used the parse the debug information emitted by the JIT
36862compiler.
36863
36864@menu
36865* Using JIT Debug Info Readers:: How to use supplied readers correctly
36866* Writing JIT Debug Info Readers:: Creating a debug-info reader
36867@end menu
36868
36869@node Using JIT Debug Info Readers
36870@subsection Using JIT Debug Info Readers
36871@kindex jit-reader-load
36872@kindex jit-reader-unload
36873
36874Readers can be loaded and unloaded using the @code{jit-reader-load}
36875and @code{jit-reader-unload} commands.
36876
36877@table @code
c9fb1240 36878@item jit-reader-load @var{reader}
697aa1b7 36879Load the JIT reader named @var{reader}, which is a shared
c9fb1240
SD
36880object specified as either an absolute or a relative file name. In
36881the latter case, @value{GDBN} will try to load the reader from a
36882pre-configured directory, usually @file{@var{libdir}/gdb/} on a UNIX
36883system (here @var{libdir} is the system library directory, often
36884@file{/usr/local/lib}).
36885
36886Only one reader can be active at a time; trying to load a second
36887reader when one is already loaded will result in @value{GDBN}
36888reporting an error. A new JIT reader can be loaded by first unloading
36889the current one using @code{jit-reader-unload} and then invoking
36890@code{jit-reader-load}.
f85b53f8
SD
36891
36892@item jit-reader-unload
36893Unload the currently loaded JIT reader.
36894
36895@end table
36896
36897@node Writing JIT Debug Info Readers
36898@subsection Writing JIT Debug Info Readers
36899@cindex writing JIT debug info readers
36900
36901As mentioned, a reader is essentially a shared object conforming to a
36902certain ABI. This ABI is described in @file{jit-reader.h}.
36903
36904@file{jit-reader.h} defines the structures, macros and functions
36905required to write a reader. It is installed (along with
36906@value{GDBN}), in @file{@var{includedir}/gdb} where @var{includedir} is
36907the system include directory.
36908
36909Readers need to be released under a GPL compatible license. A reader
36910can be declared as released under such a license by placing the macro
36911@code{GDB_DECLARE_GPL_COMPATIBLE_READER} in a source file.
36912
36913The entry point for readers is the symbol @code{gdb_init_reader},
36914which is expected to be a function with the prototype
36915
36916@findex gdb_init_reader
36917@smallexample
36918extern struct gdb_reader_funcs *gdb_init_reader (void);
36919@end smallexample
36920
36921@cindex @code{struct gdb_reader_funcs}
36922
36923@code{struct gdb_reader_funcs} contains a set of pointers to callback
36924functions. These functions are executed to read the debug info
36925generated by the JIT compiler (@code{read}), to unwind stack frames
36926(@code{unwind}) and to create canonical frame IDs
27f7b2f6 36927(@code{get_frame_id}). It also has a callback that is called when the
f85b53f8
SD
36928reader is being unloaded (@code{destroy}). The struct looks like this
36929
36930@smallexample
36931struct gdb_reader_funcs
36932@{
36933 /* Must be set to GDB_READER_INTERFACE_VERSION. */
36934 int reader_version;
36935
36936 /* For use by the reader. */
36937 void *priv_data;
36938
36939 gdb_read_debug_info *read;
36940 gdb_unwind_frame *unwind;
36941 gdb_get_frame_id *get_frame_id;
36942 gdb_destroy_reader *destroy;
36943@};
36944@end smallexample
36945
36946@cindex @code{struct gdb_symbol_callbacks}
36947@cindex @code{struct gdb_unwind_callbacks}
36948
36949The callbacks are provided with another set of callbacks by
36950@value{GDBN} to do their job. For @code{read}, these callbacks are
36951passed in a @code{struct gdb_symbol_callbacks} and for @code{unwind}
36952and @code{get_frame_id}, in a @code{struct gdb_unwind_callbacks}.
36953@code{struct gdb_symbol_callbacks} has callbacks to create new object
36954files and new symbol tables inside those object files. @code{struct
36955gdb_unwind_callbacks} has callbacks to read registers off the current
36956frame and to write out the values of the registers in the previous
36957frame. Both have a callback (@code{target_read}) to read bytes off the
36958target's address space.
36959
d1feda86
YQ
36960@node In-Process Agent
36961@chapter In-Process Agent
36962@cindex debugging agent
36963The traditional debugging model is conceptually low-speed, but works fine,
36964because most bugs can be reproduced in debugging-mode execution. However,
36965as multi-core or many-core processors are becoming mainstream, and
36966multi-threaded programs become more and more popular, there should be more
36967and more bugs that only manifest themselves at normal-mode execution, for
36968example, thread races, because debugger's interference with the program's
36969timing may conceal the bugs. On the other hand, in some applications,
36970it is not feasible for the debugger to interrupt the program's execution
36971long enough for the developer to learn anything helpful about its behavior.
36972If the program's correctness depends on its real-time behavior, delays
36973introduced by a debugger might cause the program to fail, even when the
36974code itself is correct. It is useful to be able to observe the program's
36975behavior without interrupting it.
36976
36977Therefore, traditional debugging model is too intrusive to reproduce
36978some bugs. In order to reduce the interference with the program, we can
36979reduce the number of operations performed by debugger. The
36980@dfn{In-Process Agent}, a shared library, is running within the same
36981process with inferior, and is able to perform some debugging operations
36982itself. As a result, debugger is only involved when necessary, and
36983performance of debugging can be improved accordingly. Note that
36984interference with program can be reduced but can't be removed completely,
36985because the in-process agent will still stop or slow down the program.
36986
36987The in-process agent can interpret and execute Agent Expressions
36988(@pxref{Agent Expressions}) during performing debugging operations. The
36989agent expressions can be used for different purposes, such as collecting
36990data in tracepoints, and condition evaluation in breakpoints.
36991
36992@anchor{Control Agent}
36993You can control whether the in-process agent is used as an aid for
36994debugging with the following commands:
36995
36996@table @code
36997@kindex set agent on
36998@item set agent on
36999Causes the in-process agent to perform some operations on behalf of the
37000debugger. Just which operations requested by the user will be done
37001by the in-process agent depends on the its capabilities. For example,
37002if you request to evaluate breakpoint conditions in the in-process agent,
37003and the in-process agent has such capability as well, then breakpoint
37004conditions will be evaluated in the in-process agent.
37005
37006@kindex set agent off
37007@item set agent off
37008Disables execution of debugging operations by the in-process agent. All
37009of the operations will be performed by @value{GDBN}.
37010
37011@kindex show agent
37012@item show agent
37013Display the current setting of execution of debugging operations by
37014the in-process agent.
37015@end table
37016
16bdd41f
YQ
37017@menu
37018* In-Process Agent Protocol::
37019@end menu
37020
37021@node In-Process Agent Protocol
37022@section In-Process Agent Protocol
37023@cindex in-process agent protocol
37024
37025The in-process agent is able to communicate with both @value{GDBN} and
37026GDBserver (@pxref{In-Process Agent}). This section documents the protocol
37027used for communications between @value{GDBN} or GDBserver and the IPA.
37028In general, @value{GDBN} or GDBserver sends commands
37029(@pxref{IPA Protocol Commands}) and data to in-process agent, and then
37030in-process agent replies back with the return result of the command, or
37031some other information. The data sent to in-process agent is composed
37032of primitive data types, such as 4-byte or 8-byte type, and composite
37033types, which are called objects (@pxref{IPA Protocol Objects}).
37034
37035@menu
37036* IPA Protocol Objects::
37037* IPA Protocol Commands::
37038@end menu
37039
37040@node IPA Protocol Objects
37041@subsection IPA Protocol Objects
37042@cindex ipa protocol objects
37043
37044The commands sent to and results received from agent may contain some
37045complex data types called @dfn{objects}.
37046
37047The in-process agent is running on the same machine with @value{GDBN}
37048or GDBserver, so it doesn't have to handle as much differences between
37049two ends as remote protocol (@pxref{Remote Protocol}) tries to handle.
37050However, there are still some differences of two ends in two processes:
37051
37052@enumerate
37053@item
37054word size. On some 64-bit machines, @value{GDBN} or GDBserver can be
37055compiled as a 64-bit executable, while in-process agent is a 32-bit one.
37056@item
37057ABI. Some machines may have multiple types of ABI, @value{GDBN} or
37058GDBserver is compiled with one, and in-process agent is compiled with
37059the other one.
37060@end enumerate
37061
37062Here are the IPA Protocol Objects:
37063
37064@enumerate
37065@item
37066agent expression object. It represents an agent expression
37067(@pxref{Agent Expressions}).
37068@anchor{agent expression object}
37069@item
37070tracepoint action object. It represents a tracepoint action
37071(@pxref{Tracepoint Actions,,Tracepoint Action Lists}) to collect registers,
37072memory, static trace data and to evaluate expression.
37073@anchor{tracepoint action object}
37074@item
37075tracepoint object. It represents a tracepoint (@pxref{Tracepoints}).
37076@anchor{tracepoint object}
37077
37078@end enumerate
37079
37080The following table describes important attributes of each IPA protocol
37081object:
37082
37083@multitable @columnfractions .30 .20 .50
37084@headitem Name @tab Size @tab Description
37085@item @emph{agent expression object} @tab @tab
37086@item length @tab 4 @tab length of bytes code
37087@item byte code @tab @var{length} @tab contents of byte code
37088@item @emph{tracepoint action for collecting memory} @tab @tab
37089@item 'M' @tab 1 @tab type of tracepoint action
37090@item addr @tab 8 @tab if @var{basereg} is @samp{-1}, @var{addr} is the
37091address of the lowest byte to collect, otherwise @var{addr} is the offset
37092of @var{basereg} for memory collecting.
37093@item len @tab 8 @tab length of memory for collecting
37094@item basereg @tab 4 @tab the register number containing the starting
37095memory address for collecting.
37096@item @emph{tracepoint action for collecting registers} @tab @tab
37097@item 'R' @tab 1 @tab type of tracepoint action
37098@item @emph{tracepoint action for collecting static trace data} @tab @tab
37099@item 'L' @tab 1 @tab type of tracepoint action
37100@item @emph{tracepoint action for expression evaluation} @tab @tab
37101@item 'X' @tab 1 @tab type of tracepoint action
37102@item agent expression @tab length of @tab @ref{agent expression object}
37103@item @emph{tracepoint object} @tab @tab
37104@item number @tab 4 @tab number of tracepoint
37105@item address @tab 8 @tab address of tracepoint inserted on
37106@item type @tab 4 @tab type of tracepoint
37107@item enabled @tab 1 @tab enable or disable of tracepoint
37108@item step_count @tab 8 @tab step
37109@item pass_count @tab 8 @tab pass
37110@item numactions @tab 4 @tab number of tracepoint actions
37111@item hit count @tab 8 @tab hit count
37112@item trace frame usage @tab 8 @tab trace frame usage
37113@item compiled_cond @tab 8 @tab compiled condition
37114@item orig_size @tab 8 @tab orig size
37115@item condition @tab 4 if condition is NULL otherwise length of
37116@ref{agent expression object}
37117@tab zero if condition is NULL, otherwise is
37118@ref{agent expression object}
37119@item actions @tab variable
37120@tab numactions number of @ref{tracepoint action object}
37121@end multitable
37122
37123@node IPA Protocol Commands
37124@subsection IPA Protocol Commands
37125@cindex ipa protocol commands
37126
37127The spaces in each command are delimiters to ease reading this commands
37128specification. They don't exist in real commands.
37129
37130@table @samp
37131
37132@item FastTrace:@var{tracepoint_object} @var{gdb_jump_pad_head}
37133Installs a new fast tracepoint described by @var{tracepoint_object}
697aa1b7 37134(@pxref{tracepoint object}). The @var{gdb_jump_pad_head}, 8-byte long, is the
16bdd41f
YQ
37135head of @dfn{jumppad}, which is used to jump to data collection routine
37136in IPA finally.
37137
37138Replies:
37139@table @samp
37140@item OK @var{target_address} @var{gdb_jump_pad_head} @var{fjump_size} @var{fjump}
37141@var{target_address} is address of tracepoint in the inferior.
697aa1b7 37142The @var{gdb_jump_pad_head} is updated head of jumppad. Both of
16bdd41f 37143@var{target_address} and @var{gdb_jump_pad_head} are 8-byte long.
697aa1b7
EZ
37144The @var{fjump} contains a sequence of instructions jump to jumppad entry.
37145The @var{fjump_size}, 4-byte long, is the size of @var{fjump}.
16bdd41f
YQ
37146@item E @var{NN}
37147for an error
37148
37149@end table
37150
7255706c
YQ
37151@item close
37152Closes the in-process agent. This command is sent when @value{GDBN} or GDBserver
37153is about to kill inferiors.
37154
16bdd41f
YQ
37155@item qTfSTM
37156@xref{qTfSTM}.
37157@item qTsSTM
37158@xref{qTsSTM}.
37159@item qTSTMat
37160@xref{qTSTMat}.
37161@item probe_marker_at:@var{address}
37162Asks in-process agent to probe the marker at @var{address}.
37163
37164Replies:
37165@table @samp
37166@item E @var{NN}
37167for an error
37168@end table
37169@item unprobe_marker_at:@var{address}
37170Asks in-process agent to unprobe the marker at @var{address}.
37171@end table
37172
8e04817f
AC
37173@node GDB Bugs
37174@chapter Reporting Bugs in @value{GDBN}
37175@cindex bugs in @value{GDBN}
37176@cindex reporting bugs in @value{GDBN}
c906108c 37177
8e04817f 37178Your bug reports play an essential role in making @value{GDBN} reliable.
c906108c 37179
8e04817f
AC
37180Reporting a bug may help you by bringing a solution to your problem, or it
37181may not. But in any case the principal function of a bug report is to help
37182the entire community by making the next version of @value{GDBN} work better. Bug
37183reports are your contribution to the maintenance of @value{GDBN}.
c906108c 37184
8e04817f
AC
37185In order for a bug report to serve its purpose, you must include the
37186information that enables us to fix the bug.
c4555f82
SC
37187
37188@menu
8e04817f
AC
37189* Bug Criteria:: Have you found a bug?
37190* Bug Reporting:: How to report bugs
c4555f82
SC
37191@end menu
37192
8e04817f 37193@node Bug Criteria
79a6e687 37194@section Have You Found a Bug?
8e04817f 37195@cindex bug criteria
c4555f82 37196
8e04817f 37197If you are not sure whether you have found a bug, here are some guidelines:
c4555f82
SC
37198
37199@itemize @bullet
8e04817f
AC
37200@cindex fatal signal
37201@cindex debugger crash
37202@cindex crash of debugger
c4555f82 37203@item
8e04817f
AC
37204If the debugger gets a fatal signal, for any input whatever, that is a
37205@value{GDBN} bug. Reliable debuggers never crash.
37206
37207@cindex error on valid input
37208@item
37209If @value{GDBN} produces an error message for valid input, that is a
37210bug. (Note that if you're cross debugging, the problem may also be
37211somewhere in the connection to the target.)
c4555f82 37212
8e04817f 37213@cindex invalid input
c4555f82 37214@item
8e04817f
AC
37215If @value{GDBN} does not produce an error message for invalid input,
37216that is a bug. However, you should note that your idea of
37217``invalid input'' might be our idea of ``an extension'' or ``support
37218for traditional practice''.
37219
37220@item
37221If you are an experienced user of debugging tools, your suggestions
37222for improvement of @value{GDBN} are welcome in any case.
c4555f82
SC
37223@end itemize
37224
8e04817f 37225@node Bug Reporting
79a6e687 37226@section How to Report Bugs
8e04817f
AC
37227@cindex bug reports
37228@cindex @value{GDBN} bugs, reporting
37229
37230A number of companies and individuals offer support for @sc{gnu} products.
37231If you obtained @value{GDBN} from a support organization, we recommend you
37232contact that organization first.
37233
37234You can find contact information for many support companies and
37235individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
37236distribution.
37237@c should add a web page ref...
37238
c16158bc
JM
37239@ifset BUGURL
37240@ifset BUGURL_DEFAULT
129188f6 37241In any event, we also recommend that you submit bug reports for
d3e8051b 37242@value{GDBN}. The preferred method is to submit them directly using
129188f6
AC
37243@uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
37244page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
37245be used.
8e04817f
AC
37246
37247@strong{Do not send bug reports to @samp{info-gdb}, or to
37248@samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
37249not want to receive bug reports. Those that do have arranged to receive
37250@samp{bug-gdb}.
37251
37252The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
37253serves as a repeater. The mailing list and the newsgroup carry exactly
37254the same messages. Often people think of posting bug reports to the
37255newsgroup instead of mailing them. This appears to work, but it has one
37256problem which can be crucial: a newsgroup posting often lacks a mail
37257path back to the sender. Thus, if we need to ask for more information,
37258we may be unable to reach you. For this reason, it is better to send
37259bug reports to the mailing list.
c16158bc
JM
37260@end ifset
37261@ifclear BUGURL_DEFAULT
37262In any event, we also recommend that you submit bug reports for
37263@value{GDBN} to @value{BUGURL}.
37264@end ifclear
37265@end ifset
c4555f82 37266
8e04817f
AC
37267The fundamental principle of reporting bugs usefully is this:
37268@strong{report all the facts}. If you are not sure whether to state a
37269fact or leave it out, state it!
c4555f82 37270
8e04817f
AC
37271Often people omit facts because they think they know what causes the
37272problem and assume that some details do not matter. Thus, you might
37273assume that the name of the variable you use in an example does not matter.
37274Well, probably it does not, but one cannot be sure. Perhaps the bug is a
37275stray memory reference which happens to fetch from the location where that
37276name is stored in memory; perhaps, if the name were different, the contents
37277of that location would fool the debugger into doing the right thing despite
37278the bug. Play it safe and give a specific, complete example. That is the
37279easiest thing for you to do, and the most helpful.
c4555f82 37280
8e04817f
AC
37281Keep in mind that the purpose of a bug report is to enable us to fix the
37282bug. It may be that the bug has been reported previously, but neither
37283you nor we can know that unless your bug report is complete and
37284self-contained.
c4555f82 37285
8e04817f
AC
37286Sometimes people give a few sketchy facts and ask, ``Does this ring a
37287bell?'' Those bug reports are useless, and we urge everyone to
37288@emph{refuse to respond to them} except to chide the sender to report
37289bugs properly.
37290
37291To enable us to fix the bug, you should include all these things:
c4555f82
SC
37292
37293@itemize @bullet
37294@item
8e04817f
AC
37295The version of @value{GDBN}. @value{GDBN} announces it if you start
37296with no arguments; you can also print it at any time using @code{show
37297version}.
c4555f82 37298
8e04817f
AC
37299Without this, we will not know whether there is any point in looking for
37300the bug in the current version of @value{GDBN}.
c4555f82
SC
37301
37302@item
8e04817f
AC
37303The type of machine you are using, and the operating system name and
37304version number.
c4555f82 37305
6eaaf48b
EZ
37306@item
37307The details of the @value{GDBN} build-time configuration.
37308@value{GDBN} shows these details if you invoke it with the
37309@option{--configuration} command-line option, or if you type
37310@code{show configuration} at @value{GDBN}'s prompt.
37311
c4555f82 37312@item
c1468174 37313What compiler (and its version) was used to compile @value{GDBN}---e.g.@:
8e04817f 37314``@value{GCC}--2.8.1''.
c4555f82
SC
37315
37316@item
8e04817f 37317What compiler (and its version) was used to compile the program you are
c1468174 37318debugging---e.g.@: ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
3f94c067
BW
37319C Compiler''. For @value{NGCC}, you can say @kbd{@value{GCC} --version}
37320to get this information; for other compilers, see the documentation for
37321those compilers.
c4555f82 37322
8e04817f
AC
37323@item
37324The command arguments you gave the compiler to compile your example and
37325observe the bug. For example, did you use @samp{-O}? To guarantee
37326you will not omit something important, list them all. A copy of the
37327Makefile (or the output from make) is sufficient.
c4555f82 37328
8e04817f
AC
37329If we were to try to guess the arguments, we would probably guess wrong
37330and then we might not encounter the bug.
c4555f82 37331
8e04817f
AC
37332@item
37333A complete input script, and all necessary source files, that will
37334reproduce the bug.
c4555f82 37335
8e04817f
AC
37336@item
37337A description of what behavior you observe that you believe is
37338incorrect. For example, ``It gets a fatal signal.''
c4555f82 37339
8e04817f
AC
37340Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
37341will certainly notice it. But if the bug is incorrect output, we might
37342not notice unless it is glaringly wrong. You might as well not give us
37343a chance to make a mistake.
c4555f82 37344
8e04817f
AC
37345Even if the problem you experience is a fatal signal, you should still
37346say so explicitly. Suppose something strange is going on, such as, your
37347copy of @value{GDBN} is out of synch, or you have encountered a bug in
37348the C library on your system. (This has happened!) Your copy might
37349crash and ours would not. If you told us to expect a crash, then when
37350ours fails to crash, we would know that the bug was not happening for
37351us. If you had not told us to expect a crash, then we would not be able
37352to draw any conclusion from our observations.
c4555f82 37353
e0c07bf0
MC
37354@pindex script
37355@cindex recording a session script
37356To collect all this information, you can use a session recording program
37357such as @command{script}, which is available on many Unix systems.
37358Just run your @value{GDBN} session inside @command{script} and then
37359include the @file{typescript} file with your bug report.
37360
37361Another way to record a @value{GDBN} session is to run @value{GDBN}
37362inside Emacs and then save the entire buffer to a file.
37363
8e04817f
AC
37364@item
37365If you wish to suggest changes to the @value{GDBN} source, send us context
37366diffs. If you even discuss something in the @value{GDBN} source, refer to
37367it by context, not by line number.
c4555f82 37368
8e04817f
AC
37369The line numbers in our development sources will not match those in your
37370sources. Your line numbers would convey no useful information to us.
c4555f82 37371
8e04817f 37372@end itemize
c4555f82 37373
8e04817f 37374Here are some things that are not necessary:
c4555f82 37375
8e04817f
AC
37376@itemize @bullet
37377@item
37378A description of the envelope of the bug.
c4555f82 37379
8e04817f
AC
37380Often people who encounter a bug spend a lot of time investigating
37381which changes to the input file will make the bug go away and which
37382changes will not affect it.
c4555f82 37383
8e04817f
AC
37384This is often time consuming and not very useful, because the way we
37385will find the bug is by running a single example under the debugger
37386with breakpoints, not by pure deduction from a series of examples.
37387We recommend that you save your time for something else.
c4555f82 37388
8e04817f
AC
37389Of course, if you can find a simpler example to report @emph{instead}
37390of the original one, that is a convenience for us. Errors in the
37391output will be easier to spot, running under the debugger will take
37392less time, and so on.
c4555f82 37393
8e04817f
AC
37394However, simplification is not vital; if you do not want to do this,
37395report the bug anyway and send us the entire test case you used.
c4555f82 37396
8e04817f
AC
37397@item
37398A patch for the bug.
c4555f82 37399
8e04817f
AC
37400A patch for the bug does help us if it is a good one. But do not omit
37401the necessary information, such as the test case, on the assumption that
37402a patch is all we need. We might see problems with your patch and decide
37403to fix the problem another way, or we might not understand it at all.
c4555f82 37404
8e04817f
AC
37405Sometimes with a program as complicated as @value{GDBN} it is very hard to
37406construct an example that will make the program follow a certain path
37407through the code. If you do not send us the example, we will not be able
37408to construct one, so we will not be able to verify that the bug is fixed.
c4555f82 37409
8e04817f
AC
37410And if we cannot understand what bug you are trying to fix, or why your
37411patch should be an improvement, we will not install it. A test case will
37412help us to understand.
c4555f82 37413
8e04817f
AC
37414@item
37415A guess about what the bug is or what it depends on.
c4555f82 37416
8e04817f
AC
37417Such guesses are usually wrong. Even we cannot guess right about such
37418things without first using the debugger to find the facts.
37419@end itemize
c4555f82 37420
8e04817f
AC
37421@c The readline documentation is distributed with the readline code
37422@c and consists of the two following files:
cc88a640
JK
37423@c rluser.texi
37424@c hsuser.texi
8e04817f
AC
37425@c Use -I with makeinfo to point to the appropriate directory,
37426@c environment var TEXINPUTS with TeX.
39037522 37427@ifclear SYSTEM_READLINE
5bdf8622 37428@include rluser.texi
cc88a640 37429@include hsuser.texi
39037522 37430@end ifclear
c4555f82 37431
4ceed123
JB
37432@node In Memoriam
37433@appendix In Memoriam
37434
9ed350ad
JB
37435The @value{GDBN} project mourns the loss of the following long-time
37436contributors:
4ceed123
JB
37437
37438@table @code
37439@item Fred Fish
9ed350ad
JB
37440Fred was a long-standing contributor to @value{GDBN} (1991-2006), and
37441to Free Software in general. Outside of @value{GDBN}, he was known in
37442the Amiga world for his series of Fish Disks, and the GeekGadget project.
4ceed123
JB
37443
37444@item Michael Snyder
9ed350ad
JB
37445Michael was one of the Global Maintainers of the @value{GDBN} project,
37446with contributions recorded as early as 1996, until 2011. In addition
37447to his day to day participation, he was a large driving force behind
37448adding Reverse Debugging to @value{GDBN}.
4ceed123
JB
37449@end table
37450
37451Beyond their technical contributions to the project, they were also
37452enjoyable members of the Free Software Community. We will miss them.
c4555f82 37453
8e04817f
AC
37454@node Formatting Documentation
37455@appendix Formatting Documentation
c4555f82 37456
8e04817f
AC
37457@cindex @value{GDBN} reference card
37458@cindex reference card
37459The @value{GDBN} 4 release includes an already-formatted reference card, ready
37460for printing with PostScript or Ghostscript, in the @file{gdb}
37461subdirectory of the main source directory@footnote{In
37462@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
37463release.}. If you can use PostScript or Ghostscript with your printer,
37464you can print the reference card immediately with @file{refcard.ps}.
c4555f82 37465
8e04817f
AC
37466The release also includes the source for the reference card. You
37467can format it, using @TeX{}, by typing:
c4555f82 37468
474c8240 37469@smallexample
8e04817f 37470make refcard.dvi
474c8240 37471@end smallexample
c4555f82 37472
8e04817f
AC
37473The @value{GDBN} reference card is designed to print in @dfn{landscape}
37474mode on US ``letter'' size paper;
37475that is, on a sheet 11 inches wide by 8.5 inches
37476high. You will need to specify this form of printing as an option to
37477your @sc{dvi} output program.
c4555f82 37478
8e04817f 37479@cindex documentation
c4555f82 37480
8e04817f
AC
37481All the documentation for @value{GDBN} comes as part of the machine-readable
37482distribution. The documentation is written in Texinfo format, which is
37483a documentation system that uses a single source file to produce both
37484on-line information and a printed manual. You can use one of the Info
37485formatting commands to create the on-line version of the documentation
37486and @TeX{} (or @code{texi2roff}) to typeset the printed version.
c4555f82 37487
8e04817f
AC
37488@value{GDBN} includes an already formatted copy of the on-line Info
37489version of this manual in the @file{gdb} subdirectory. The main Info
37490file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
37491subordinate files matching @samp{gdb.info*} in the same directory. If
37492necessary, you can print out these files, or read them with any editor;
37493but they are easier to read using the @code{info} subsystem in @sc{gnu}
37494Emacs or the standalone @code{info} program, available as part of the
37495@sc{gnu} Texinfo distribution.
c4555f82 37496
8e04817f
AC
37497If you want to format these Info files yourself, you need one of the
37498Info formatting programs, such as @code{texinfo-format-buffer} or
37499@code{makeinfo}.
c4555f82 37500
8e04817f
AC
37501If you have @code{makeinfo} installed, and are in the top level
37502@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
37503version @value{GDBVN}), you can make the Info file by typing:
c4555f82 37504
474c8240 37505@smallexample
8e04817f
AC
37506cd gdb
37507make gdb.info
474c8240 37508@end smallexample
c4555f82 37509
8e04817f
AC
37510If you want to typeset and print copies of this manual, you need @TeX{},
37511a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
37512Texinfo definitions file.
c4555f82 37513
8e04817f
AC
37514@TeX{} is a typesetting program; it does not print files directly, but
37515produces output files called @sc{dvi} files. To print a typeset
37516document, you need a program to print @sc{dvi} files. If your system
37517has @TeX{} installed, chances are it has such a program. The precise
37518command to use depends on your system; @kbd{lpr -d} is common; another
37519(for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
37520require a file name without any extension or a @samp{.dvi} extension.
c4555f82 37521
8e04817f
AC
37522@TeX{} also requires a macro definitions file called
37523@file{texinfo.tex}. This file tells @TeX{} how to typeset a document
37524written in Texinfo format. On its own, @TeX{} cannot either read or
37525typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
37526and is located in the @file{gdb-@var{version-number}/texinfo}
37527directory.
c4555f82 37528
8e04817f 37529If you have @TeX{} and a @sc{dvi} printer program installed, you can
d3e8051b 37530typeset and print this manual. First switch to the @file{gdb}
8e04817f
AC
37531subdirectory of the main source directory (for example, to
37532@file{gdb-@value{GDBVN}/gdb}) and type:
c4555f82 37533
474c8240 37534@smallexample
8e04817f 37535make gdb.dvi
474c8240 37536@end smallexample
c4555f82 37537
8e04817f 37538Then give @file{gdb.dvi} to your @sc{dvi} printing program.
c4555f82 37539
8e04817f
AC
37540@node Installing GDB
37541@appendix Installing @value{GDBN}
8e04817f 37542@cindex installation
c4555f82 37543
7fa2210b
DJ
37544@menu
37545* Requirements:: Requirements for building @value{GDBN}
db2e3e2e 37546* Running Configure:: Invoking the @value{GDBN} @file{configure} script
7fa2210b
DJ
37547* Separate Objdir:: Compiling @value{GDBN} in another directory
37548* Config Names:: Specifying names for hosts and targets
37549* Configure Options:: Summary of options for configure
098b41a6 37550* System-wide configuration:: Having a system-wide init file
7fa2210b
DJ
37551@end menu
37552
37553@node Requirements
79a6e687 37554@section Requirements for Building @value{GDBN}
7fa2210b
DJ
37555@cindex building @value{GDBN}, requirements for
37556
37557Building @value{GDBN} requires various tools and packages to be available.
37558Other packages will be used only if they are found.
37559
79a6e687 37560@heading Tools/Packages Necessary for Building @value{GDBN}
7fa2210b 37561@table @asis
7f0bd420
TT
37562@item C@t{++}11 compiler
37563@value{GDBN} is written in C@t{++}11. It should be buildable with any
37564recent C@t{++}11 compiler, e.g.@: GCC.
7fa2210b 37565
7f0bd420
TT
37566@item GNU make
37567@value{GDBN}'s build system relies on features only found in the GNU
37568make program. Other variants of @code{make} will not work.
7fa2210b
DJ
37569@end table
37570
79a6e687 37571@heading Tools/Packages Optional for Building @value{GDBN}
7fa2210b
DJ
37572@table @asis
37573@item Expat
123dc839 37574@anchor{Expat}
7fa2210b
DJ
37575@value{GDBN} can use the Expat XML parsing library. This library may be
37576included with your operating system distribution; if it is not, you
37577can get the latest version from @url{http://expat.sourceforge.net}.
db2e3e2e 37578The @file{configure} script will search for this library in several
7fa2210b
DJ
37579standard locations; if it is installed in an unusual path, you can
37580use the @option{--with-libexpat-prefix} option to specify its location.
37581
9cceb671
DJ
37582Expat is used for:
37583
37584@itemize @bullet
37585@item
37586Remote protocol memory maps (@pxref{Memory Map Format})
37587@item
37588Target descriptions (@pxref{Target Descriptions})
37589@item
2268b414
JK
37590Remote shared library lists (@xref{Library List Format},
37591or alternatively @pxref{Library List Format for SVR4 Targets})
9cceb671
DJ
37592@item
37593MS-Windows shared libraries (@pxref{Shared Libraries})
b3b9301e
PA
37594@item
37595Traceframe info (@pxref{Traceframe Info Format})
2ae8c8e7 37596@item
f4abbc16
MM
37597Branch trace (@pxref{Branch Trace Format},
37598@pxref{Branch Trace Configuration Format})
9cceb671 37599@end itemize
7fa2210b 37600
7f0bd420
TT
37601@item Guile
37602@value{GDBN} can be scripted using GNU Guile. @xref{Guile}. By
37603default, @value{GDBN} will be compiled if the Guile libraries are
37604installed and are found by @file{configure}. You can use the
37605@code{--with-guile} option to request Guile, and pass either the Guile
37606version number or the file name of the relevant @code{pkg-config}
37607program to choose a particular version of Guile.
37608
37609@item iconv
37610@value{GDBN}'s features related to character sets (@pxref{Character
37611Sets}) require a functioning @code{iconv} implementation. If you are
37612on a GNU system, then this is provided by the GNU C Library. Some
37613other systems also provide a working @code{iconv}.
37614
37615If @value{GDBN} is using the @code{iconv} program which is installed
37616in a non-standard place, you will need to tell @value{GDBN} where to
37617find it. This is done with @option{--with-iconv-bin} which specifies
37618the directory that contains the @code{iconv} program. This program is
37619run in order to make a list of the available character sets.
37620
37621On systems without @code{iconv}, you can install GNU Libiconv. If
37622Libiconv is installed in a standard place, @value{GDBN} will
37623automatically use it if it is needed. If you have previously
37624installed Libiconv in a non-standard place, you can use the
37625@option{--with-libiconv-prefix} option to @file{configure}.
37626
37627@value{GDBN}'s top-level @file{configure} and @file{Makefile} will
37628arrange to build Libiconv if a directory named @file{libiconv} appears
37629in the top-most source directory. If Libiconv is built this way, and
37630if the operating system does not provide a suitable @code{iconv}
37631implementation, then the just-built library will automatically be used
37632by @value{GDBN}. One easy way to set this up is to download GNU
37633Libiconv, unpack it inside the top-level directory of the @value{GDBN}
37634source tree, and then rename the directory holding the Libiconv source
37635code to @samp{libiconv}.
37636
37637@item lzma
37638@value{GDBN} can support debugging sections that are compressed with
37639the LZMA library. @xref{MiniDebugInfo}. If this library is not
37640included with your operating system, you can find it in the xz package
37641at @url{http://tukaani.org/xz/}. If the LZMA library is available in
37642the usual place, then the @file{configure} script will use it
37643automatically. If it is installed in an unusual path, you can use the
37644@option{--with-lzma-prefix} option to specify its location.
37645
2400729e
UW
37646@item MPFR
37647@anchor{MPFR}
37648@value{GDBN} can use the GNU MPFR multiple-precision floating-point
37649library. This library may be included with your operating system
37650distribution; if it is not, you can get the latest version from
37651@url{http://www.mpfr.org}. The @file{configure} script will search
37652for this library in several standard locations; if it is installed
37653in an unusual path, you can use the @option{--with-libmpfr-prefix}
37654option to specify its location.
37655
37656GNU MPFR is used to emulate target floating-point arithmetic during
37657expression evaluation when the target uses different floating-point
37658formats than the host. If GNU MPFR it is not available, @value{GDBN}
37659will fall back to using host floating-point arithmetic.
37660
7f0bd420
TT
37661@item Python
37662@value{GDBN} can be scripted using Python language. @xref{Python}.
37663By default, @value{GDBN} will be compiled if the Python libraries are
37664installed and are found by @file{configure}. You can use the
37665@code{--with-python} option to request Python, and pass either the
37666file name of the relevant @code{python} executable, or the name of the
37667directory in which Python is installed, to choose a particular
37668installation of Python.
37669
31fffb02
CS
37670@item zlib
37671@cindex compressed debug sections
37672@value{GDBN} will use the @samp{zlib} library, if available, to read
37673compressed debug sections. Some linkers, such as GNU gold, are capable
37674of producing binaries with compressed debug sections. If @value{GDBN}
37675is compiled with @samp{zlib}, it will be able to read the debug
37676information in such binaries.
37677
37678The @samp{zlib} library is likely included with your operating system
37679distribution; if it is not, you can get the latest version from
37680@url{http://zlib.net}.
7fa2210b
DJ
37681@end table
37682
37683@node Running Configure
db2e3e2e 37684@section Invoking the @value{GDBN} @file{configure} Script
7fa2210b 37685@cindex configuring @value{GDBN}
db2e3e2e 37686@value{GDBN} comes with a @file{configure} script that automates the process
8e04817f
AC
37687of preparing @value{GDBN} for installation; you can then use @code{make} to
37688build the @code{gdb} program.
37689@iftex
37690@c irrelevant in info file; it's as current as the code it lives with.
37691@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
37692look at the @file{README} file in the sources; we may have improved the
37693installation procedures since publishing this manual.}
37694@end iftex
c4555f82 37695
8e04817f
AC
37696The @value{GDBN} distribution includes all the source code you need for
37697@value{GDBN} in a single directory, whose name is usually composed by
37698appending the version number to @samp{gdb}.
c4555f82 37699
8e04817f
AC
37700For example, the @value{GDBN} version @value{GDBVN} distribution is in the
37701@file{gdb-@value{GDBVN}} directory. That directory contains:
c4555f82 37702
8e04817f
AC
37703@table @code
37704@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
37705script for configuring @value{GDBN} and all its supporting libraries
c4555f82 37706
8e04817f
AC
37707@item gdb-@value{GDBVN}/gdb
37708the source specific to @value{GDBN} itself
c4555f82 37709
8e04817f
AC
37710@item gdb-@value{GDBVN}/bfd
37711source for the Binary File Descriptor library
c906108c 37712
8e04817f
AC
37713@item gdb-@value{GDBVN}/include
37714@sc{gnu} include files
c906108c 37715
8e04817f
AC
37716@item gdb-@value{GDBVN}/libiberty
37717source for the @samp{-liberty} free software library
c906108c 37718
8e04817f
AC
37719@item gdb-@value{GDBVN}/opcodes
37720source for the library of opcode tables and disassemblers
c906108c 37721
8e04817f
AC
37722@item gdb-@value{GDBVN}/readline
37723source for the @sc{gnu} command-line interface
8e04817f 37724@end table
c906108c 37725
7f0bd420
TT
37726There may be other subdirectories as well.
37727
db2e3e2e 37728The simplest way to configure and build @value{GDBN} is to run @file{configure}
8e04817f
AC
37729from the @file{gdb-@var{version-number}} source directory, which in
37730this example is the @file{gdb-@value{GDBVN}} directory.
c906108c 37731
8e04817f 37732First switch to the @file{gdb-@var{version-number}} source directory
db2e3e2e 37733if you are not already in it; then run @file{configure}. Pass the
8e04817f
AC
37734identifier for the platform on which @value{GDBN} will run as an
37735argument.
c906108c 37736
8e04817f 37737For example:
c906108c 37738
474c8240 37739@smallexample
8e04817f 37740cd gdb-@value{GDBVN}
7f0bd420 37741./configure
8e04817f 37742make
474c8240 37743@end smallexample
c906108c 37744
7f0bd420
TT
37745Running @samp{configure} and then running @code{make} builds the
37746included supporting libraries, then @code{gdb} itself. The configured
37747source files, and the binaries, are left in the corresponding source
37748directories.
c906108c 37749
8e04817f 37750@need 750
db2e3e2e 37751@file{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
8e04817f
AC
37752system does not recognize this automatically when you run a different
37753shell, you may need to run @code{sh} on it explicitly:
c906108c 37754
474c8240 37755@smallexample
7f0bd420 37756sh configure
474c8240 37757@end smallexample
c906108c 37758
db2e3e2e 37759You should run the @file{configure} script from the top directory in the
94e91d6d 37760source tree, the @file{gdb-@var{version-number}} directory. If you run
db2e3e2e 37761@file{configure} from one of the subdirectories, you will configure only
94e91d6d 37762that subdirectory. That is usually not what you want. In particular,
db2e3e2e 37763if you run the first @file{configure} from the @file{gdb} subdirectory
94e91d6d
MC
37764of the @file{gdb-@var{version-number}} directory, you will omit the
37765configuration of @file{bfd}, @file{readline}, and other sibling
37766directories of the @file{gdb} subdirectory. This leads to build errors
37767about missing include files such as @file{bfd/bfd.h}.
c906108c 37768
7f0bd420
TT
37769You can install @code{@value{GDBN}} anywhere. The best way to do this
37770is to pass the @code{--prefix} option to @code{configure}, and then
37771install it with @code{make install}.
c906108c 37772
8e04817f 37773@node Separate Objdir
79a6e687 37774@section Compiling @value{GDBN} in Another Directory
c906108c 37775
8e04817f
AC
37776If you want to run @value{GDBN} versions for several host or target machines,
37777you need a different @code{gdb} compiled for each combination of
db2e3e2e 37778host and target. @file{configure} is designed to make this easy by
8e04817f
AC
37779allowing you to generate each configuration in a separate subdirectory,
37780rather than in the source directory. If your @code{make} program
37781handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
37782@code{make} in each of these directories builds the @code{gdb}
37783program specified there.
c906108c 37784
db2e3e2e 37785To build @code{gdb} in a separate directory, run @file{configure}
8e04817f 37786with the @samp{--srcdir} option to specify where to find the source.
db2e3e2e
BW
37787(You also need to specify a path to find @file{configure}
37788itself from your working directory. If the path to @file{configure}
8e04817f
AC
37789would be the same as the argument to @samp{--srcdir}, you can leave out
37790the @samp{--srcdir} option; it is assumed.)
c906108c 37791
8e04817f
AC
37792For example, with version @value{GDBVN}, you can build @value{GDBN} in a
37793separate directory for a Sun 4 like this:
c906108c 37794
474c8240 37795@smallexample
8e04817f
AC
37796@group
37797cd gdb-@value{GDBVN}
37798mkdir ../gdb-sun4
37799cd ../gdb-sun4
7f0bd420 37800../gdb-@value{GDBVN}/configure
8e04817f
AC
37801make
37802@end group
474c8240 37803@end smallexample
c906108c 37804
db2e3e2e 37805When @file{configure} builds a configuration using a remote source
8e04817f
AC
37806directory, it creates a tree for the binaries with the same structure
37807(and using the same names) as the tree under the source directory. In
37808the example, you'd find the Sun 4 library @file{libiberty.a} in the
37809directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
37810@file{gdb-sun4/gdb}.
c906108c 37811
94e91d6d
MC
37812Make sure that your path to the @file{configure} script has just one
37813instance of @file{gdb} in it. If your path to @file{configure} looks
37814like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
37815one subdirectory of @value{GDBN}, not the whole package. This leads to
37816build errors about missing include files such as @file{bfd/bfd.h}.
37817
8e04817f
AC
37818One popular reason to build several @value{GDBN} configurations in separate
37819directories is to configure @value{GDBN} for cross-compiling (where
37820@value{GDBN} runs on one machine---the @dfn{host}---while debugging
37821programs that run on another machine---the @dfn{target}).
37822You specify a cross-debugging target by
db2e3e2e 37823giving the @samp{--target=@var{target}} option to @file{configure}.
c906108c 37824
8e04817f
AC
37825When you run @code{make} to build a program or library, you must run
37826it in a configured directory---whatever directory you were in when you
db2e3e2e 37827called @file{configure} (or one of its subdirectories).
c906108c 37828
db2e3e2e 37829The @code{Makefile} that @file{configure} generates in each source
8e04817f
AC
37830directory also runs recursively. If you type @code{make} in a source
37831directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
37832directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
37833will build all the required libraries, and then build GDB.
c906108c 37834
8e04817f
AC
37835When you have multiple hosts or targets configured in separate
37836directories, you can run @code{make} on them in parallel (for example,
37837if they are NFS-mounted on each of the hosts); they will not interfere
37838with each other.
c906108c 37839
8e04817f 37840@node Config Names
79a6e687 37841@section Specifying Names for Hosts and Targets
c906108c 37842
db2e3e2e 37843The specifications used for hosts and targets in the @file{configure}
8e04817f
AC
37844script are based on a three-part naming scheme, but some short predefined
37845aliases are also supported. The full naming scheme encodes three pieces
37846of information in the following pattern:
c906108c 37847
474c8240 37848@smallexample
8e04817f 37849@var{architecture}-@var{vendor}-@var{os}
474c8240 37850@end smallexample
c906108c 37851
8e04817f
AC
37852For example, you can use the alias @code{sun4} as a @var{host} argument,
37853or as the value for @var{target} in a @code{--target=@var{target}}
37854option. The equivalent full name is @samp{sparc-sun-sunos4}.
c906108c 37855
db2e3e2e 37856The @file{configure} script accompanying @value{GDBN} does not provide
8e04817f 37857any query facility to list all supported host and target names or
db2e3e2e 37858aliases. @file{configure} calls the Bourne shell script
8e04817f
AC
37859@code{config.sub} to map abbreviations to full names; you can read the
37860script, if you wish, or you can use it to test your guesses on
37861abbreviations---for example:
c906108c 37862
8e04817f
AC
37863@smallexample
37864% sh config.sub i386-linux
37865i386-pc-linux-gnu
37866% sh config.sub alpha-linux
37867alpha-unknown-linux-gnu
37868% sh config.sub hp9k700
37869hppa1.1-hp-hpux
37870% sh config.sub sun4
37871sparc-sun-sunos4.1.1
37872% sh config.sub sun3
37873m68k-sun-sunos4.1.1
37874% sh config.sub i986v
37875Invalid configuration `i986v': machine `i986v' not recognized
37876@end smallexample
c906108c 37877
8e04817f
AC
37878@noindent
37879@code{config.sub} is also distributed in the @value{GDBN} source
37880directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
d700128c 37881
8e04817f 37882@node Configure Options
db2e3e2e 37883@section @file{configure} Options
c906108c 37884
db2e3e2e 37885Here is a summary of the @file{configure} options and arguments that
7f0bd420
TT
37886are most often useful for building @value{GDBN}. @file{configure}
37887also has several other options not listed here. @inforef{Running
37888configure scripts,,autoconf.info}, for a full
37889explanation of @file{configure}.
c906108c 37890
474c8240 37891@smallexample
8e04817f
AC
37892configure @r{[}--help@r{]}
37893 @r{[}--prefix=@var{dir}@r{]}
37894 @r{[}--exec-prefix=@var{dir}@r{]}
37895 @r{[}--srcdir=@var{dirname}@r{]}
8e04817f 37896 @r{[}--target=@var{target}@r{]}
474c8240 37897@end smallexample
c906108c 37898
8e04817f
AC
37899@noindent
37900You may introduce options with a single @samp{-} rather than
37901@samp{--} if you prefer; but you may abbreviate option names if you use
37902@samp{--}.
c906108c 37903
8e04817f
AC
37904@table @code
37905@item --help
db2e3e2e 37906Display a quick summary of how to invoke @file{configure}.
c906108c 37907
8e04817f
AC
37908@item --prefix=@var{dir}
37909Configure the source to install programs and files under directory
37910@file{@var{dir}}.
c906108c 37911
8e04817f
AC
37912@item --exec-prefix=@var{dir}
37913Configure the source to install programs under directory
37914@file{@var{dir}}.
c906108c 37915
8e04817f
AC
37916@c avoid splitting the warning from the explanation:
37917@need 2000
37918@item --srcdir=@var{dirname}
8e04817f
AC
37919Use this option to make configurations in directories separate from the
37920@value{GDBN} source directories. Among other things, you can use this to
37921build (or maintain) several configurations simultaneously, in separate
db2e3e2e 37922directories. @file{configure} writes configuration-specific files in
8e04817f 37923the current directory, but arranges for them to use the source in the
db2e3e2e 37924directory @var{dirname}. @file{configure} creates directories under
8e04817f
AC
37925the working directory in parallel to the source directories below
37926@var{dirname}.
c906108c 37927
8e04817f
AC
37928@item --target=@var{target}
37929Configure @value{GDBN} for cross-debugging programs running on the specified
37930@var{target}. Without this option, @value{GDBN} is configured to debug
37931programs that run on the same machine (@var{host}) as @value{GDBN} itself.
c906108c 37932
a95746f9
TT
37933There is no convenient way to generate a list of all available
37934targets. Also see the @code{--enable-targets} option, below.
8e04817f 37935@end table
c906108c 37936
a95746f9
TT
37937There are many other options that are specific to @value{GDBN}. This
37938lists just the most common ones; there are some very specialized
37939options not described here.
37940
37941@table @code
37942@item --enable-targets=@r{[}@var{target}@r{]}@dots{}
37943@itemx --enable-targets=all
37944Configure @value{GDBN} for cross-debugging programs running on the
37945specified list of targets. The special value @samp{all} configures
37946@value{GDBN} for debugging programs running on any target it supports.
37947
37948@item --with-gdb-datadir=@var{path}
37949Set the @value{GDBN}-specific data directory. @value{GDBN} will look
37950here for certain supporting files or scripts. This defaults to the
6b92c0d3 37951@file{gdb} subdirectory of @samp{datadir} (which can be set using
a95746f9
TT
37952@code{--datadir}).
37953
37954@item --with-relocated-sources=@var{dir}
37955Sets up the default source path substitution rule so that directory
37956names recorded in debug information will be automatically adjusted for
37957any directory under @var{dir}. @var{dir} should be a subdirectory of
37958@value{GDBN}'s configured prefix, the one mentioned in the
37959@code{--prefix} or @code{--exec-prefix} options to configure. This
37960option is useful if GDB is supposed to be moved to a different place
37961after it is built.
37962
37963@item --enable-64-bit-bfd
37964Enable 64-bit support in BFD on 32-bit hosts.
37965
37966@item --disable-gdbmi
37967Build @value{GDBN} without the GDB/MI machine interface
37968(@pxref{GDB/MI}).
37969
37970@item --enable-tui
37971Build @value{GDBN} with the text-mode full-screen user interface
37972(TUI). Requires a curses library (ncurses and cursesX are also
37973supported).
37974
37975@item --with-curses
37976Use the curses library instead of the termcap library, for text-mode
37977terminal operations.
37978
0d79cdc4
AM
37979@item --with-debuginfod
37980Build @value{GDBN} with libdebuginfod, the debuginfod client library.
37981Used to automatically fetch source files and separate debug files from
37982debuginfod servers using the associated executable's build ID. Enabled
37983by default if libdebuginfod is installed and found at configure time.
37984debuginfod is packaged with elfutils, starting with version 0.178. You
37985can get the latest version from `https://sourceware.org/elfutils/'.
37986
a95746f9
TT
37987@item --with-libunwind-ia64
37988Use the libunwind library for unwinding function call stack on ia64
37989target platforms. See http://www.nongnu.org/libunwind/index.html for
37990details.
37991
37992@item --with-system-readline
37993Use the readline library installed on the host, rather than the
86c6b807
TT
37994library supplied as part of @value{GDBN}. Readline 7 or newer is
37995required; this is enforced by the build system.
a95746f9
TT
37996
37997@item --with-system-zlib
37998Use the zlib library installed on the host, rather than the library
37999supplied as part of @value{GDBN}.
38000
38001@item --with-expat
38002Build @value{GDBN} with Expat, a library for XML parsing. (Done by
38003default if libexpat is installed and found at configure time.) This
38004library is used to read XML files supplied with @value{GDBN}. If it
38005is unavailable, some features, such as remote protocol memory maps,
38006target descriptions, and shared library lists, that are based on XML
38007files, will not be available in @value{GDBN}. If your host does not
38008have libexpat installed, you can get the latest version from
38009`http://expat.sourceforge.net'.
38010
38011@item --with-libiconv-prefix@r{[}=@var{dir}@r{]}
38012
38013Build @value{GDBN} with GNU libiconv, a character set encoding
38014conversion library. This is not done by default, as on GNU systems
38015the @code{iconv} that is built in to the C library is sufficient. If
38016your host does not have a working @code{iconv}, you can get the latest
38017version of GNU iconv from `https://www.gnu.org/software/libiconv/'.
38018
38019@value{GDBN}'s build system also supports building GNU libiconv as
38020part of the overall build. @xref{Requirements}.
38021
38022@item --with-lzma
38023Build @value{GDBN} with LZMA, a compression library. (Done by default
38024if liblzma is installed and found at configure time.) LZMA is used by
38025@value{GDBN}'s "mini debuginfo" feature, which is only useful on
38026platforms using the ELF object file format. If your host does not
38027have liblzma installed, you can get the latest version from
38028`https://tukaani.org/xz/'.
38029
38030@item --with-mpfr
38031Build @value{GDBN} with GNU MPFR, a library for multiple-precision
38032floating-point computation with correct rounding. (Done by default if
38033GNU MPFR is installed and found at configure time.) This library is
38034used to emulate target floating-point arithmetic during expression
38035evaluation when the target uses different floating-point formats than
38036the host. If GNU MPFR is not available, @value{GDBN} will fall back
38037to using host floating-point arithmetic. If your host does not have
38038GNU MPFR installed, you can get the latest version from
38039`http://www.mpfr.org'.
38040
38041@item --with-python@r{[}=@var{python}@r{]}
38042Build @value{GDBN} with Python scripting support. (Done by default if
38043libpython is present and found at configure time.) Python makes
38044@value{GDBN} scripting much more powerful than the restricted CLI
38045scripting language. If your host does not have Python installed, you
38046can find it on `http://www.python.org/download/'. The oldest version
2c3fc25d 38047of Python supported by GDB is 2.6. The optional argument @var{python}
a95746f9
TT
38048is used to find the Python headers and libraries. It can be either
38049the name of a Python executable, or the name of the directory in which
38050Python is installed.
38051
38052@item --with-guile[=GUILE]'
38053Build @value{GDBN} with GNU Guile scripting support. (Done by default
38054if libguile is present and found at configure time.) If your host
38055does not have Guile installed, you can find it at
38056`https://www.gnu.org/software/guile/'. The optional argument GUILE
38057can be a version number, which will cause @code{configure} to try to
38058use that version of Guile; or the file name of a @code{pkg-config}
38059executable, which will be queried to find the information needed to
38060compile and link against Guile.
38061
38062@item --without-included-regex
38063Don't use the regex library included with @value{GDBN} (as part of the
38064libiberty library). This is the default on hosts with version 2 of
38065the GNU C library.
38066
38067@item --with-sysroot=@var{dir}
38068Use @var{dir} as the default system root directory for libraries whose
38069file names begin with @file{/lib}' or @file{/usr/lib'}. (The value of
38070@var{dir} can be modified at run time by using the @command{set
38071sysroot} command.) If @var{dir} is under the @value{GDBN} configured
38072prefix (set with @code{--prefix} or @code{--exec-prefix options}, the
38073default system root will be automatically adjusted if and when
38074@value{GDBN} is moved to a different location.
38075
38076@item --with-system-gdbinit=@var{file}
38077Configure @value{GDBN} to automatically load a system-wide init file.
38078@var{file} should be an absolute file name. If @var{file} is in a
38079directory under the configured prefix, and @value{GDBN} is moved to
38080another location after being built, the location of the system-wide
38081init file will be adjusted accordingly.
38082
ed2a2229
CB
38083@item --with-system-gdbinit-dir=@var{directory}
38084Configure @value{GDBN} to automatically load init files from a
38085system-wide directory. @var{directory} should be an absolute directory
38086name. If @var{directory} is in a directory under the configured
38087prefix, and @value{GDBN} is moved to another location after being
38088built, the location of the system-wide init directory will be
38089adjusted accordingly.
38090
a95746f9
TT
38091@item --enable-build-warnings
38092When building the @value{GDBN} sources, ask the compiler to warn about
38093any code which looks even vaguely suspicious. It passes many
38094different warning flags, depending on the exact version of the
38095compiler you are using.
38096
38097@item --enable-werror
38098Treat compiler warnings as werrors. It adds the @code{-Werror} flag
38099to the compiler, which will fail the compilation if the compiler
38100outputs any warning messages.
f35d5ade
TT
38101
38102@item --enable-ubsan
eff98030
TT
38103Enable the GCC undefined behavior sanitizer. This is disabled by
38104default, but passing @code{--enable-ubsan=yes} or
38105@code{--enable-ubsan=auto} to @code{configure} will enable it. The
38106undefined behavior sanitizer checks for C@t{++} undefined behavior.
38107It has a performance cost, so if you are looking at @value{GDBN}'s
38108performance, you should disable it. The undefined behavior sanitizer
38109was first introduced in GCC 4.9.
a95746f9 38110@end table
c906108c 38111
098b41a6
JG
38112@node System-wide configuration
38113@section System-wide configuration and settings
38114@cindex system-wide init file
38115
ed2a2229
CB
38116@value{GDBN} can be configured to have a system-wide init file and a
38117system-wide init file directory; this file and files in that directory
38118(if they have a recognized file extension) will be read and executed at
38119startup (@pxref{Startup, , What @value{GDBN} does during startup}).
098b41a6 38120
ed2a2229 38121Here are the corresponding configure options:
098b41a6
JG
38122
38123@table @code
38124@item --with-system-gdbinit=@var{file}
38125Specify that the default location of the system-wide init file is
38126@var{file}.
ed2a2229
CB
38127@item --with-system-gdbinit-dir=@var{directory}
38128Specify that the default location of the system-wide init file directory
38129is @var{directory}.
098b41a6
JG
38130@end table
38131
38132If @value{GDBN} has been configured with the option @option{--prefix=$prefix},
ed2a2229 38133they may be subject to relocation. Two possible cases:
098b41a6
JG
38134
38135@itemize @bullet
38136@item
ed2a2229 38137If the default location of this init file/directory contains @file{$prefix},
098b41a6
JG
38138it will be subject to relocation. Suppose that the configure options
38139are @option{--prefix=$prefix --with-system-gdbinit=$prefix/etc/gdbinit};
38140if @value{GDBN} is moved from @file{$prefix} to @file{$install}, the system
38141init file is looked for as @file{$install/etc/gdbinit} instead of
38142@file{$prefix/etc/gdbinit}.
38143
38144@item
38145By contrast, if the default location does not contain the prefix,
38146it will not be relocated. E.g.@: if @value{GDBN} has been configured with
38147@option{--prefix=/usr/local --with-system-gdbinit=/usr/share/gdb/gdbinit},
38148then @value{GDBN} will always look for @file{/usr/share/gdb/gdbinit},
38149wherever @value{GDBN} is installed.
38150@end itemize
38151
e64e0392
DE
38152If the configured location of the system-wide init file (as given by the
38153@option{--with-system-gdbinit} option at configure time) is in the
38154data-directory (as specified by @option{--with-gdb-datadir} at configure
38155time) or in one of its subdirectories, then @value{GDBN} will look for the
38156system-wide init file in the directory specified by the
38157@option{--data-directory} command-line option.
38158Note that the system-wide init file is only read once, during @value{GDBN}
38159initialization. If the data-directory is changed after @value{GDBN} has
38160started with the @code{set data-directory} command, the file will not be
38161reread.
38162
ed2a2229
CB
38163This applies similarly to the system-wide directory specified in
38164@option{--with-system-gdbinit-dir}.
38165
38166Any supported scripting language can be used for these init files, as long
38167as the file extension matches the scripting language. To be interpreted
38168as regular @value{GDBN} commands, the files needs to have a @file{.gdb}
38169extension.
38170
5901af59
JB
38171@menu
38172* System-wide Configuration Scripts:: Installed System-wide Configuration Scripts
38173@end menu
38174
38175@node System-wide Configuration Scripts
0201faac
JB
38176@subsection Installed System-wide Configuration Scripts
38177@cindex system-wide configuration scripts
38178
38179The @file{system-gdbinit} directory, located inside the data-directory
38180(as specified by @option{--with-gdb-datadir} at configure time) contains
38181a number of scripts which can be used as system-wide init files. To
38182automatically source those scripts at startup, @value{GDBN} should be
38183configured with @option{--with-system-gdbinit}. Otherwise, any user
38184should be able to source them by hand as needed.
38185
38186The following scripts are currently available:
38187@itemize @bullet
38188
38189@item @file{elinos.py}
38190@pindex elinos.py
38191@cindex ELinOS system-wide configuration script
38192This script is useful when debugging a program on an ELinOS target.
38193It takes advantage of the environment variables defined in a standard
38194ELinOS environment in order to determine the location of the system
38195shared libraries, and then sets the @samp{solib-absolute-prefix}
38196and @samp{solib-search-path} variables appropriately.
38197
38198@item @file{wrs-linux.py}
38199@pindex wrs-linux.py
38200@cindex Wind River Linux system-wide configuration script
38201This script is useful when debugging a program on a target running
38202Wind River Linux. It expects the @env{ENV_PREFIX} to be set to
38203the host-side sysroot used by the target system.
38204
38205@end itemize
38206
8e04817f
AC
38207@node Maintenance Commands
38208@appendix Maintenance Commands
38209@cindex maintenance commands
38210@cindex internal commands
c906108c 38211
8e04817f 38212In addition to commands intended for @value{GDBN} users, @value{GDBN}
09d4efe1
EZ
38213includes a number of commands intended for @value{GDBN} developers,
38214that are not documented elsewhere in this manual. These commands are
da316a69
EZ
38215provided here for reference. (For commands that turn on debugging
38216messages, see @ref{Debugging Output}.)
c906108c 38217
8e04817f 38218@table @code
09d4efe1 38219@kindex maint agent
782b2b07 38220@kindex maint agent-eval
f77cc5f0
HZ
38221@item maint agent @r{[}-at @var{location}@r{,}@r{]} @var{expression}
38222@itemx maint agent-eval @r{[}-at @var{location}@r{,}@r{]} @var{expression}
09d4efe1
EZ
38223Translate the given @var{expression} into remote agent bytecodes.
38224This command is useful for debugging the Agent Expression mechanism
782b2b07
SS
38225(@pxref{Agent Expressions}). The @samp{agent} version produces an
38226expression useful for data collection, such as by tracepoints, while
38227@samp{maint agent-eval} produces an expression that evaluates directly
38228to a result. For instance, a collection expression for @code{globa +
38229globb} will include bytecodes to record four bytes of memory at each
38230of the addresses of @code{globa} and @code{globb}, while discarding
38231the result of the addition, while an evaluation expression will do the
38232addition and return the sum.
f77cc5f0
HZ
38233If @code{-at} is given, generate remote agent bytecode for @var{location}.
38234If not, generate remote agent bytecode for current frame PC address.
09d4efe1 38235
d3ce09f5
SS
38236@kindex maint agent-printf
38237@item maint agent-printf @var{format},@var{expr},...
38238Translate the given format string and list of argument expressions
38239into remote agent bytecodes and display them as a disassembled list.
38240This command is useful for debugging the agent version of dynamic
6dd24dfa 38241printf (@pxref{Dynamic Printf}).
d3ce09f5 38242
8e04817f
AC
38243@kindex maint info breakpoints
38244@item @anchor{maint info breakpoints}maint info breakpoints
38245Using the same format as @samp{info breakpoints}, display both the
38246breakpoints you've set explicitly, and those @value{GDBN} is using for
38247internal purposes. Internal breakpoints are shown with negative
38248breakpoint numbers. The type column identifies what kind of breakpoint
38249is shown:
c906108c 38250
8e04817f
AC
38251@table @code
38252@item breakpoint
38253Normal, explicitly set breakpoint.
c906108c 38254
8e04817f
AC
38255@item watchpoint
38256Normal, explicitly set watchpoint.
c906108c 38257
8e04817f
AC
38258@item longjmp
38259Internal breakpoint, used to handle correctly stepping through
38260@code{longjmp} calls.
c906108c 38261
8e04817f
AC
38262@item longjmp resume
38263Internal breakpoint at the target of a @code{longjmp}.
c906108c 38264
8e04817f
AC
38265@item until
38266Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
c906108c 38267
8e04817f
AC
38268@item finish
38269Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
c906108c 38270
8e04817f
AC
38271@item shlib events
38272Shared library events.
c906108c 38273
8e04817f 38274@end table
c906108c 38275
b0627500
MM
38276@kindex maint info btrace
38277@item maint info btrace
38278Pint information about raw branch tracing data.
38279
38280@kindex maint btrace packet-history
38281@item maint btrace packet-history
38282Print the raw branch trace packets that are used to compute the
38283execution history for the @samp{record btrace} command. Both the
38284information and the format in which it is printed depend on the btrace
38285recording format.
38286
38287@table @code
38288@item bts
38289For the BTS recording format, print a list of blocks of sequential
38290code. For each block, the following information is printed:
38291
38292@table @asis
38293@item Block number
38294Newer blocks have higher numbers. The oldest block has number zero.
38295@item Lowest @samp{PC}
38296@item Highest @samp{PC}
38297@end table
38298
38299@item pt
bc504a31
PA
38300For the Intel Processor Trace recording format, print a list of
38301Intel Processor Trace packets. For each packet, the following
b0627500
MM
38302information is printed:
38303
38304@table @asis
38305@item Packet number
38306Newer packets have higher numbers. The oldest packet has number zero.
38307@item Trace offset
38308The packet's offset in the trace stream.
38309@item Packet opcode and payload
38310@end table
38311@end table
38312
38313@kindex maint btrace clear-packet-history
38314@item maint btrace clear-packet-history
38315Discards the cached packet history printed by the @samp{maint btrace
38316packet-history} command. The history will be computed again when
38317needed.
38318
38319@kindex maint btrace clear
38320@item maint btrace clear
38321Discard the branch trace data. The data will be fetched anew and the
38322branch trace will be recomputed when needed.
38323
38324This implicitly truncates the branch trace to a single branch trace
38325buffer. When updating branch trace incrementally, the branch trace
38326available to @value{GDBN} may be bigger than a single branch trace
38327buffer.
38328
38329@kindex maint set btrace pt skip-pad
38330@item maint set btrace pt skip-pad
38331@kindex maint show btrace pt skip-pad
38332@item maint show btrace pt skip-pad
38333Control whether @value{GDBN} will skip PAD packets when computing the
38334packet history.
38335
fff08868
HZ
38336@kindex set displaced-stepping
38337@kindex show displaced-stepping
237fc4c9
PA
38338@cindex displaced stepping support
38339@cindex out-of-line single-stepping
fff08868
HZ
38340@item set displaced-stepping
38341@itemx show displaced-stepping
237fc4c9 38342Control whether or not @value{GDBN} will do @dfn{displaced stepping}
fff08868
HZ
38343if the target supports it. Displaced stepping is a way to single-step
38344over breakpoints without removing them from the inferior, by executing
38345an out-of-line copy of the instruction that was originally at the
38346breakpoint location. It is also known as out-of-line single-stepping.
38347
38348@table @code
38349@item set displaced-stepping on
38350If the target architecture supports it, @value{GDBN} will use
38351displaced stepping to step over breakpoints.
38352
38353@item set displaced-stepping off
38354@value{GDBN} will not use displaced stepping to step over breakpoints,
38355even if such is supported by the target architecture.
38356
38357@cindex non-stop mode, and @samp{set displaced-stepping}
38358@item set displaced-stepping auto
38359This is the default mode. @value{GDBN} will use displaced stepping
38360only if non-stop mode is active (@pxref{Non-Stop Mode}) and the target
38361architecture supports displaced stepping.
38362@end table
237fc4c9 38363
7d0c9981
DE
38364@kindex maint check-psymtabs
38365@item maint check-psymtabs
38366Check the consistency of currently expanded psymtabs versus symtabs.
38367Use this to check, for example, whether a symbol is in one but not the other.
38368
09d4efe1
EZ
38369@kindex maint check-symtabs
38370@item maint check-symtabs
7d0c9981
DE
38371Check the consistency of currently expanded symtabs.
38372
38373@kindex maint expand-symtabs
38374@item maint expand-symtabs [@var{regexp}]
38375Expand symbol tables.
38376If @var{regexp} is specified, only expand symbol tables for file
38377names matching @var{regexp}.
09d4efe1 38378
992c7d70
GB
38379@kindex maint set catch-demangler-crashes
38380@kindex maint show catch-demangler-crashes
38381@cindex demangler crashes
38382@item maint set catch-demangler-crashes [on|off]
38383@itemx maint show catch-demangler-crashes
38384Control whether @value{GDBN} should attempt to catch crashes in the
38385symbol name demangler. The default is to attempt to catch crashes.
38386If enabled, the first time a crash is caught, a core file is created,
38387the offending symbol is displayed and the user is presented with the
38388option to terminate the current session.
38389
09d4efe1
EZ
38390@kindex maint cplus first_component
38391@item maint cplus first_component @var{name}
38392Print the first C@t{++} class/namespace component of @var{name}.
38393
38394@kindex maint cplus namespace
38395@item maint cplus namespace
38396Print the list of possible C@t{++} namespaces.
38397
09d4efe1
EZ
38398@kindex maint deprecate
38399@kindex maint undeprecate
38400@cindex deprecated commands
38401@item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
38402@itemx maint undeprecate @var{command}
38403Deprecate or undeprecate the named @var{command}. Deprecated commands
38404cause @value{GDBN} to issue a warning when you use them. The optional
38405argument @var{replacement} says which newer command should be used in
38406favor of the deprecated one; if it is given, @value{GDBN} will mention
38407the replacement as part of the warning.
38408
38409@kindex maint dump-me
38410@item maint dump-me
721c2651 38411@cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
09d4efe1 38412Cause a fatal signal in the debugger and force it to dump its core.
721c2651
EZ
38413This is supported only on systems which support aborting a program
38414with the @code{SIGQUIT} signal.
09d4efe1 38415
8d30a00d
AC
38416@kindex maint internal-error
38417@kindex maint internal-warning
57fcfb1b
GB
38418@kindex maint demangler-warning
38419@cindex demangler crashes
09d4efe1
EZ
38420@item maint internal-error @r{[}@var{message-text}@r{]}
38421@itemx maint internal-warning @r{[}@var{message-text}@r{]}
57fcfb1b
GB
38422@itemx maint demangler-warning @r{[}@var{message-text}@r{]}
38423
38424Cause @value{GDBN} to call the internal function @code{internal_error},
38425@code{internal_warning} or @code{demangler_warning} and hence behave
7ee67ee4 38426as though an internal problem has been detected. In addition to
57fcfb1b
GB
38427reporting the internal problem, these functions give the user the
38428opportunity to either quit @value{GDBN} or (for @code{internal_error}
38429and @code{internal_warning}) create a core file of the current
8d30a00d
AC
38430@value{GDBN} session.
38431
09d4efe1
EZ
38432These commands take an optional parameter @var{message-text} that is
38433used as the text of the error or warning message.
38434
d3e8051b 38435Here's an example of using @code{internal-error}:
09d4efe1 38436
8d30a00d 38437@smallexample
f7dc1244 38438(@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
8d30a00d
AC
38439@dots{}/maint.c:121: internal-error: testing, 1, 2
38440A problem internal to GDB has been detected. Further
38441debugging may prove unreliable.
38442Quit this debugging session? (y or n) @kbd{n}
38443Create a core file? (y or n) @kbd{n}
f7dc1244 38444(@value{GDBP})
8d30a00d
AC
38445@end smallexample
38446
3c16cced
PA
38447@cindex @value{GDBN} internal error
38448@cindex internal errors, control of @value{GDBN} behavior
57fcfb1b 38449@cindex demangler crashes
3c16cced
PA
38450
38451@kindex maint set internal-error
38452@kindex maint show internal-error
38453@kindex maint set internal-warning
38454@kindex maint show internal-warning
57fcfb1b
GB
38455@kindex maint set demangler-warning
38456@kindex maint show demangler-warning
3c16cced
PA
38457@item maint set internal-error @var{action} [ask|yes|no]
38458@itemx maint show internal-error @var{action}
38459@itemx maint set internal-warning @var{action} [ask|yes|no]
38460@itemx maint show internal-warning @var{action}
57fcfb1b
GB
38461@itemx maint set demangler-warning @var{action} [ask|yes|no]
38462@itemx maint show demangler-warning @var{action}
3c16cced
PA
38463When @value{GDBN} reports an internal problem (error or warning) it
38464gives the user the opportunity to both quit @value{GDBN} and create a
38465core file of the current @value{GDBN} session. These commands let you
38466override the default behaviour for each particular @var{action},
38467described in the table below.
38468
38469@table @samp
38470@item quit
38471You can specify that @value{GDBN} should always (yes) or never (no)
38472quit. The default is to ask the user what to do.
38473
38474@item corefile
38475You can specify that @value{GDBN} should always (yes) or never (no)
57fcfb1b
GB
38476create a core file. The default is to ask the user what to do. Note
38477that there is no @code{corefile} option for @code{demangler-warning}:
38478demangler warnings always create a core file and this cannot be
38479disabled.
3c16cced
PA
38480@end table
38481
09d4efe1
EZ
38482@kindex maint packet
38483@item maint packet @var{text}
38484If @value{GDBN} is talking to an inferior via the serial protocol,
38485then this command sends the string @var{text} to the inferior, and
38486displays the response packet. @value{GDBN} supplies the initial
38487@samp{$} character, the terminating @samp{#} character, and the
38488checksum.
38489
38490@kindex maint print architecture
38491@item maint print architecture @r{[}@var{file}@r{]}
38492Print the entire architecture configuration. The optional argument
38493@var{file} names the file where the output goes.
8d30a00d 38494
8e2141c6 38495@kindex maint print c-tdesc @r{[}@var{file}@r{]}
81adfced 38496@item maint print c-tdesc
8e2141c6
YQ
38497Print the target description (@pxref{Target Descriptions}) as
38498a C source file. By default, the target description is for the current
38499target, but if the optional argument @var{file} is provided, that file
38500is used to produce the description. The @var{file} should be an XML
38501document, of the form described in @ref{Target Description Format}.
38502The created source file is built into @value{GDBN} when @value{GDBN} is
38503built again. This command is used by developers after they add or
38504modify XML target descriptions.
81adfced 38505
caa7fd04
AB
38506@kindex maint print xml-tdesc
38507@item maint print xml-tdesc @r{[}@var{file}@r{]}
38508Print the target description (@pxref{Target Descriptions}) as an XML
38509file. By default print the target description for the current target,
38510but if the optional argument @var{file} is provided, then that file is
38511read in by GDB and then used to produce the description. The
38512@var{file} should be an XML document, of the form described in
38513@ref{Target Description Format}.
38514
27d41eac
YQ
38515@kindex maint check xml-descriptions
38516@item maint check xml-descriptions @var{dir}
38517Check that the target descriptions dynamically created by @value{GDBN}
38518equal the descriptions created from XML files found in @var{dir}.
38519
41fc26a2 38520@anchor{maint check libthread-db}
5045b3d7
GB
38521@kindex maint check libthread-db
38522@item maint check libthread-db
38523Run integrity checks on the current inferior's thread debugging
38524library. This exercises all @code{libthread_db} functionality used by
38525@value{GDBN} on GNU/Linux systems, and by extension also exercises the
38526@code{proc_service} functions provided by @value{GDBN} that
38527@code{libthread_db} uses. Note that parts of the test may be skipped
38528on some platforms when debugging core files.
38529
00905d52
AC
38530@kindex maint print dummy-frames
38531@item maint print dummy-frames
00905d52
AC
38532Prints the contents of @value{GDBN}'s internal dummy-frame stack.
38533
38534@smallexample
f7dc1244 38535(@value{GDBP}) @kbd{b add}
00905d52 38536@dots{}
f7dc1244 38537(@value{GDBP}) @kbd{print add(2,3)}
00905d52
AC
38538Breakpoint 2, add (a=2, b=3) at @dots{}
3853958 return (a + b);
38540The program being debugged stopped while in a function called from GDB.
38541@dots{}
f7dc1244 38542(@value{GDBP}) @kbd{maint print dummy-frames}
b67a2c6f 385430xa8206d8: id=@{stack=0xbfffe734,code=0xbfffe73f,!special@}, ptid=process 9353
f7dc1244 38544(@value{GDBP})
00905d52
AC
38545@end smallexample
38546
38547Takes an optional file parameter.
38548
0680b120
AC
38549@kindex maint print registers
38550@kindex maint print raw-registers
38551@kindex maint print cooked-registers
617073a9 38552@kindex maint print register-groups
c21236dc 38553@kindex maint print remote-registers
09d4efe1
EZ
38554@item maint print registers @r{[}@var{file}@r{]}
38555@itemx maint print raw-registers @r{[}@var{file}@r{]}
38556@itemx maint print cooked-registers @r{[}@var{file}@r{]}
38557@itemx maint print register-groups @r{[}@var{file}@r{]}
c21236dc 38558@itemx maint print remote-registers @r{[}@var{file}@r{]}
0680b120
AC
38559Print @value{GDBN}'s internal register data structures.
38560
617073a9 38561The command @code{maint print raw-registers} includes the contents of
c21236dc
PA
38562the raw register cache; the command @code{maint print
38563cooked-registers} includes the (cooked) value of all registers,
38564including registers which aren't available on the target nor visible
38565to user; the command @code{maint print register-groups} includes the
38566groups that each register is a member of; and the command @code{maint
38567print remote-registers} includes the remote target's register numbers
0a7cfe2c 38568and offsets in the `G' packets.
0680b120 38569
09d4efe1
EZ
38570These commands take an optional parameter, a file name to which to
38571write the information.
0680b120 38572
617073a9 38573@kindex maint print reggroups
09d4efe1
EZ
38574@item maint print reggroups @r{[}@var{file}@r{]}
38575Print @value{GDBN}'s internal register group data structures. The
38576optional argument @var{file} tells to what file to write the
38577information.
617073a9 38578
09d4efe1 38579The register groups info looks like this:
617073a9
AC
38580
38581@smallexample
f7dc1244 38582(@value{GDBP}) @kbd{maint print reggroups}
b383017d
RM
38583 Group Type
38584 general user
38585 float user
38586 all user
38587 vector user
38588 system user
38589 save internal
38590 restore internal
617073a9
AC
38591@end smallexample
38592
09d4efe1
EZ
38593@kindex flushregs
38594@item flushregs
38595This command forces @value{GDBN} to flush its internal register cache.
38596
38597@kindex maint print objfiles
38598@cindex info for known object files
52e260a3
DE
38599@item maint print objfiles @r{[}@var{regexp}@r{]}
38600Print a dump of all known object files.
38601If @var{regexp} is specified, only print object files whose names
38602match @var{regexp}. For each object file, this command prints its name,
38603address in memory, and all of its psymtabs and symtabs.
09d4efe1 38604
f5b95c01
AA
38605@kindex maint print user-registers
38606@cindex user registers
38607@item maint print user-registers
38608List all currently available @dfn{user registers}. User registers
38609typically provide alternate names for actual hardware registers. They
38610include the four ``standard'' registers @code{$fp}, @code{$pc},
38611@code{$sp}, and @code{$ps}. @xref{standard registers}. User
38612registers can be used in expressions in the same way as the canonical
38613register names, but only the latter are listed by the @code{info
38614registers} and @code{maint print registers} commands.
38615
8a1ea21f
DE
38616@kindex maint print section-scripts
38617@cindex info for known .debug_gdb_scripts-loaded scripts
38618@item maint print section-scripts [@var{regexp}]
38619Print a dump of scripts specified in the @code{.debug_gdb_section} section.
38620If @var{regexp} is specified, only print scripts loaded by object files
38621matching @var{regexp}.
38622For each script, this command prints its name as specified in the objfile,
38623and the full path if known.
8e0583c8 38624@xref{dotdebug_gdb_scripts section}.
8a1ea21f 38625
09d4efe1
EZ
38626@kindex maint print statistics
38627@cindex bcache statistics
38628@item maint print statistics
38629This command prints, for each object file in the program, various data
38630about that object file followed by the byte cache (@dfn{bcache})
38631statistics for the object file. The objfile data includes the number
d3e8051b 38632of minimal, partial, full, and stabs symbols, the number of types
09d4efe1
EZ
38633defined by the objfile, the number of as yet unexpanded psym tables,
38634the number of line tables and string tables, and the amount of memory
38635used by the various tables. The bcache statistics include the counts,
38636sizes, and counts of duplicates of all and unique objects, max,
38637average, and median entry size, total memory used and its overhead and
38638savings, and various measures of the hash table size and chain
38639lengths.
38640
c7ba131e
JB
38641@kindex maint print target-stack
38642@cindex target stack description
38643@item maint print target-stack
38644A @dfn{target} is an interface between the debugger and a particular
38645kind of file or process. Targets can be stacked in @dfn{strata},
38646so that more than one target can potentially respond to a request.
38647In particular, memory accesses will walk down the stack of targets
38648until they find a target that is interested in handling that particular
38649address.
38650
38651This command prints a short description of each layer that was pushed on
38652the @dfn{target stack}, starting from the top layer down to the bottom one.
38653
09d4efe1
EZ
38654@kindex maint print type
38655@cindex type chain of a data type
38656@item maint print type @var{expr}
38657Print the type chain for a type specified by @var{expr}. The argument
38658can be either a type name or a symbol. If it is a symbol, the type of
38659that symbol is described. The type chain produced by this command is
38660a recursive definition of the data type as stored in @value{GDBN}'s
38661data structures, including its flags and contained types.
38662
dcd1f979
TT
38663@kindex maint selftest
38664@cindex self tests
1526853e 38665@item maint selftest @r{[}@var{filter}@r{]}
dcd1f979
TT
38666Run any self tests that were compiled in to @value{GDBN}. This will
38667print a message showing how many tests were run, and how many failed.
1526853e
SM
38668If a @var{filter} is passed, only the tests with @var{filter} in their
38669name will by ran.
38670
3c2fcaf9 38671@kindex maint info selftests
1526853e
SM
38672@cindex self tests
38673@item maint info selftests
38674List the selftests compiled in to @value{GDBN}.
dcd1f979 38675
b4f54984
DE
38676@kindex maint set dwarf always-disassemble
38677@kindex maint show dwarf always-disassemble
38678@item maint set dwarf always-disassemble
38679@item maint show dwarf always-disassemble
9eae7c52
TT
38680Control the behavior of @code{info address} when using DWARF debugging
38681information.
38682
38683The default is @code{off}, which means that @value{GDBN} should try to
38684describe a variable's location in an easily readable format. When
38685@code{on}, @value{GDBN} will instead display the DWARF location
38686expression in an assembly-like format. Note that some locations are
38687too complex for @value{GDBN} to describe simply; in this case you will
38688always see the disassembly form.
38689
38690Here is an example of the resulting disassembly:
38691
38692@smallexample
38693(gdb) info addr argc
38694Symbol "argc" is a complex DWARF expression:
38695 1: DW_OP_fbreg 0
38696@end smallexample
38697
38698For more information on these expressions, see
38699@uref{http://www.dwarfstd.org/, the DWARF standard}.
38700
b4f54984
DE
38701@kindex maint set dwarf max-cache-age
38702@kindex maint show dwarf max-cache-age
38703@item maint set dwarf max-cache-age
38704@itemx maint show dwarf max-cache-age
38705Control the DWARF compilation unit cache.
09d4efe1 38706
b4f54984 38707@cindex DWARF compilation units cache
09d4efe1 38708In object files with inter-compilation-unit references, such as those
b4f54984 38709produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF
09d4efe1
EZ
38710reader needs to frequently refer to previously read compilation units.
38711This setting controls how long a compilation unit will remain in the
38712cache if it is not referenced. A higher limit means that cached
38713compilation units will be stored in memory longer, and more total
38714memory will be used. Setting it to zero disables caching, which will
38715slow down @value{GDBN} startup, but reduce memory consumption.
38716
3c3bb058
AB
38717@kindex maint set dwarf unwinders
38718@kindex maint show dwarf unwinders
38719@item maint set dwarf unwinders
38720@itemx maint show dwarf unwinders
38721Control use of the DWARF frame unwinders.
38722
38723@cindex DWARF frame unwinders
38724Many targets that support DWARF debugging use @value{GDBN}'s DWARF
38725frame unwinders to build the backtrace. Many of these targets will
38726also have a second mechanism for building the backtrace for use in
38727cases where DWARF information is not available, this second mechanism
38728is often an analysis of a function's prologue.
38729
38730In order to extend testing coverage of the second level stack
38731unwinding mechanisms it is helpful to be able to disable the DWARF
38732stack unwinders, this can be done with this switch.
38733
38734In normal use of @value{GDBN} disabling the DWARF unwinders is not
38735advisable, there are cases that are better handled through DWARF than
38736prologue analysis, and the debug experience is likely to be better
38737with the DWARF frame unwinders enabled.
38738
38739If DWARF frame unwinders are not supported for a particular target
38740architecture, then enabling this flag does not cause them to be used.
22138db6
TT
38741
38742@kindex maint set worker-threads
38743@kindex maint show worker-threads
38744@item maint set worker-threads
38745@item maint show worker-threads
38746Control the number of worker threads that may be used by @value{GDBN}.
38747On capable hosts, @value{GDBN} may use multiple threads to speed up
38748certain CPU-intensive operations, such as demangling symbol names.
38749While the number of threads used by @value{GDBN} may vary, this
38750command can be used to set an upper bound on this number. The default
38751is @code{unlimited}, which lets @value{GDBN} choose a reasonable
38752number. Note that this only controls worker threads started by
38753@value{GDBN} itself; libraries used by @value{GDBN} may start threads
38754of their own.
38755
e7ba9c65
DJ
38756@kindex maint set profile
38757@kindex maint show profile
38758@cindex profiling GDB
38759@item maint set profile
38760@itemx maint show profile
38761Control profiling of @value{GDBN}.
38762
38763Profiling will be disabled until you use the @samp{maint set profile}
38764command to enable it. When you enable profiling, the system will begin
38765collecting timing and execution count data; when you disable profiling or
38766exit @value{GDBN}, the results will be written to a log file. Remember that
38767if you use profiling, @value{GDBN} will overwrite the profiling log file
38768(often called @file{gmon.out}). If you have a record of important profiling
38769data in a @file{gmon.out} file, be sure to move it to a safe location.
38770
38771Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
b383017d 38772compiled with the @samp{-pg} compiler option.
e7ba9c65 38773
cbe54154
PA
38774@kindex maint set show-debug-regs
38775@kindex maint show show-debug-regs
eac35c4e 38776@cindex hardware debug registers
cbe54154
PA
38777@item maint set show-debug-regs
38778@itemx maint show show-debug-regs
eac35c4e 38779Control whether to show variables that mirror the hardware debug
6dd315ba 38780registers. Use @code{on} to enable, @code{off} to disable. If
3f94c067 38781enabled, the debug registers values are shown when @value{GDBN} inserts or
09d4efe1
EZ
38782removes a hardware breakpoint or watchpoint, and when the inferior
38783triggers a hardware-assisted breakpoint or watchpoint.
38784
711e434b
PM
38785@kindex maint set show-all-tib
38786@kindex maint show show-all-tib
38787@item maint set show-all-tib
38788@itemx maint show show-all-tib
38789Control whether to show all non zero areas within a 1k block starting
38790at thread local base, when using the @samp{info w32 thread-information-block}
38791command.
38792
329ea579
PA
38793@kindex maint set target-async
38794@kindex maint show target-async
38795@item maint set target-async
38796@itemx maint show target-async
38797This controls whether @value{GDBN} targets operate in synchronous or
38798asynchronous mode (@pxref{Background Execution}). Normally the
38799default is asynchronous, if it is available; but this can be changed
38800to more easily debug problems occurring only in synchronous mode.
38801
fbea99ea
PA
38802@kindex maint set target-non-stop @var{mode} [on|off|auto]
38803@kindex maint show target-non-stop
38804@item maint set target-non-stop
38805@itemx maint show target-non-stop
38806
38807This controls whether @value{GDBN} targets always operate in non-stop
38808mode even if @code{set non-stop} is @code{off} (@pxref{Non-Stop
38809Mode}). The default is @code{auto}, meaning non-stop mode is enabled
38810if supported by the target.
38811
38812@table @code
38813@item maint set target-non-stop auto
38814This is the default mode. @value{GDBN} controls the target in
38815non-stop mode if the target supports it.
38816
38817@item maint set target-non-stop on
38818@value{GDBN} controls the target in non-stop mode even if the target
38819does not indicate support.
38820
38821@item maint set target-non-stop off
38822@value{GDBN} does not control the target in non-stop mode even if the
38823target supports it.
38824@end table
38825
45e42163
TT
38826@kindex maint set tui-resize-message
38827@kindex maint show tui-resize-message
38828@item maint set tui-resize-message
38829@item maint show tui-resize-message
38830Control whether @value{GDBN} displays a message each time the terminal
38831is resized when in TUI mode. The default is @code{off}, which means
38832that @value{GDBN} is silent during resizes. When @code{on},
38833@value{GDBN} will display a message after a resize is completed; the
38834message will include a number indicating how many times the terminal
38835has been resized. This setting is intended for use by the test suite,
38836where it would otherwise be difficult to determine when a resize and
38837refresh has been completed.
38838
bd712aed
DE
38839@kindex maint set per-command
38840@kindex maint show per-command
38841@item maint set per-command
38842@itemx maint show per-command
38843@cindex resources used by commands
09d4efe1 38844
bd712aed
DE
38845@value{GDBN} can display the resources used by each command.
38846This is useful in debugging performance problems.
38847
38848@table @code
38849@item maint set per-command space [on|off]
38850@itemx maint show per-command space
38851Enable or disable the printing of the memory used by GDB for each command.
38852If enabled, @value{GDBN} will display how much memory each command
38853took, following the command's own output.
38854This can also be requested by invoking @value{GDBN} with the
38855@option{--statistics} command-line switch (@pxref{Mode Options}).
38856
38857@item maint set per-command time [on|off]
38858@itemx maint show per-command time
38859Enable or disable the printing of the execution time of @value{GDBN}
38860for each command.
38861If enabled, @value{GDBN} will display how much time it
09d4efe1 38862took to execute each command, following the command's own output.
0a1c4d10
DE
38863Both CPU time and wallclock time are printed.
38864Printing both is useful when trying to determine whether the cost is
bd712aed 38865CPU or, e.g., disk/network latency.
0a1c4d10
DE
38866Note that the CPU time printed is for @value{GDBN} only, it does not include
38867the execution time of the inferior because there's no mechanism currently
38868to compute how much time was spent by @value{GDBN} and how much time was
38869spent by the program been debugged.
09d4efe1
EZ
38870This can also be requested by invoking @value{GDBN} with the
38871@option{--statistics} command-line switch (@pxref{Mode Options}).
38872
bd712aed
DE
38873@item maint set per-command symtab [on|off]
38874@itemx maint show per-command symtab
38875Enable or disable the printing of basic symbol table statistics
38876for each command.
38877If enabled, @value{GDBN} will display the following information:
38878
215b9f98
EZ
38879@enumerate a
38880@item
38881number of symbol tables
38882@item
38883number of primary symbol tables
38884@item
38885number of blocks in the blockvector
38886@end enumerate
bd712aed
DE
38887@end table
38888
5045b3d7
GB
38889@kindex maint set check-libthread-db
38890@kindex maint show check-libthread-db
38891@item maint set check-libthread-db [on|off]
38892@itemx maint show check-libthread-db
38893Control whether @value{GDBN} should run integrity checks on inferior
38894specific thread debugging libraries as they are loaded. The default
38895is not to perform such checks. If any check fails @value{GDBN} will
38896unload the library and continue searching for a suitable candidate as
38897described in @ref{set libthread-db-search-path}. For more information
38898about the tests, see @ref{maint check libthread-db}.
38899
bd712aed
DE
38900@kindex maint space
38901@cindex memory used by commands
38902@item maint space @var{value}
38903An alias for @code{maint set per-command space}.
38904A non-zero value enables it, zero disables it.
38905
38906@kindex maint time
38907@cindex time of command execution
38908@item maint time @var{value}
38909An alias for @code{maint set per-command time}.
38910A non-zero value enables it, zero disables it.
38911
09d4efe1
EZ
38912@kindex maint translate-address
38913@item maint translate-address @r{[}@var{section}@r{]} @var{addr}
38914Find the symbol stored at the location specified by the address
38915@var{addr} and an optional section name @var{section}. If found,
38916@value{GDBN} prints the name of the closest symbol and an offset from
38917the symbol's location to the specified address. This is similar to
38918the @code{info address} command (@pxref{Symbols}), except that this
38919command also allows to find symbols in other sections.
ae038cb0 38920
c14c28ba
PP
38921If section was not specified, the section in which the symbol was found
38922is also printed. For dynamically linked executables, the name of
38923executable or shared library containing the symbol is printed as well.
38924
3345721a
PA
38925@kindex maint test-options
38926@item maint test-options require-delimiter
38927@itemx maint test-options unknown-is-error
38928@itemx maint test-options unknown-is-operand
38929These commands are used by the testsuite to validate the command
38930options framework. The @code{require-delimiter} variant requires a
38931double-dash delimiter to indicate end of options. The
38932@code{unknown-is-error} and @code{unknown-is-operand} do not. The
38933@code{unknown-is-error} variant throws an error on unknown option,
38934while @code{unknown-is-operand} treats unknown options as the start of
38935the command's operands. When run, the commands output the result of
38936the processed options. When completed, the commands store the
38937internal result of completion in a variable exposed by the @code{maint
38938show test-options-completion-result} command.
38939
38940@kindex maint show test-options-completion-result
38941@item maint show test-options-completion-result
38942Shows the result of completing the @code{maint test-options}
38943subcommands. This is used by the testsuite to validate completion
38944support in the command options framework.
38945
c6ac8931
PA
38946@kindex maint set test-settings
38947@kindex maint show test-settings
38948@item maint set test-settings @var{kind}
38949@itemx maint show test-settings @var{kind}
dca0f6c0
PA
38950These are representative commands for each @var{kind} of setting type
38951@value{GDBN} supports. They are used by the testsuite for exercising
38952the settings infrastructure.
fdbc9870
PA
38953
38954@kindex maint with
38955@item maint with @var{setting} [@var{value}] [-- @var{command}]
38956Like the @code{with} command, but works with @code{maintenance set}
38957variables. This is used by the testsuite to exercise the @code{with}
38958command's infrastructure.
38959
8e04817f 38960@end table
c906108c 38961
9c16f35a
EZ
38962The following command is useful for non-interactive invocations of
38963@value{GDBN}, such as in the test suite.
38964
38965@table @code
38966@item set watchdog @var{nsec}
38967@kindex set watchdog
38968@cindex watchdog timer
38969@cindex timeout for commands
38970Set the maximum number of seconds @value{GDBN} will wait for the
38971target operation to finish. If this time expires, @value{GDBN}
38972reports and error and the command is aborted.
38973
38974@item show watchdog
38975Show the current setting of the target wait timeout.
38976@end table
c906108c 38977
e0ce93ac 38978@node Remote Protocol
8e04817f 38979@appendix @value{GDBN} Remote Serial Protocol
c906108c 38980
ee2d5c50
AC
38981@menu
38982* Overview::
38983* Packets::
38984* Stop Reply Packets::
38985* General Query Packets::
a1dcb23a 38986* Architecture-Specific Protocol Details::
9d29849a 38987* Tracepoint Packets::
a6b151f1 38988* Host I/O Packets::
9a6253be 38989* Interrupts::
8b23ecc4
SL
38990* Notification Packets::
38991* Remote Non-Stop::
a6f3e723 38992* Packet Acknowledgment::
ee2d5c50 38993* Examples::
79a6e687 38994* File-I/O Remote Protocol Extension::
cfa9d6d9 38995* Library List Format::
2268b414 38996* Library List Format for SVR4 Targets::
79a6e687 38997* Memory Map Format::
dc146f7c 38998* Thread List Format::
b3b9301e 38999* Traceframe Info Format::
2ae8c8e7 39000* Branch Trace Format::
f4abbc16 39001* Branch Trace Configuration Format::
ee2d5c50
AC
39002@end menu
39003
39004@node Overview
39005@section Overview
39006
8e04817f
AC
39007There may be occasions when you need to know something about the
39008protocol---for example, if there is only one serial port to your target
39009machine, you might want your program to do something special if it
39010recognizes a packet meant for @value{GDBN}.
c906108c 39011
d2c6833e 39012In the examples below, @samp{->} and @samp{<-} are used to indicate
bf06d120 39013transmitted and received data, respectively.
c906108c 39014
8e04817f
AC
39015@cindex protocol, @value{GDBN} remote serial
39016@cindex serial protocol, @value{GDBN} remote
39017@cindex remote serial protocol
8b23ecc4
SL
39018All @value{GDBN} commands and responses (other than acknowledgments
39019and notifications, see @ref{Notification Packets}) are sent as a
39020@var{packet}. A @var{packet} is introduced with the character
8e04817f
AC
39021@samp{$}, the actual @var{packet-data}, and the terminating character
39022@samp{#} followed by a two-digit @var{checksum}:
c906108c 39023
474c8240 39024@smallexample
8e04817f 39025@code{$}@var{packet-data}@code{#}@var{checksum}
474c8240 39026@end smallexample
8e04817f 39027@noindent
c906108c 39028
8e04817f
AC
39029@cindex checksum, for @value{GDBN} remote
39030@noindent
39031The two-digit @var{checksum} is computed as the modulo 256 sum of all
39032characters between the leading @samp{$} and the trailing @samp{#} (an
39033eight bit unsigned checksum).
c906108c 39034
8e04817f
AC
39035Implementors should note that prior to @value{GDBN} 5.0 the protocol
39036specification also included an optional two-digit @var{sequence-id}:
c906108c 39037
474c8240 39038@smallexample
8e04817f 39039@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
474c8240 39040@end smallexample
c906108c 39041
8e04817f
AC
39042@cindex sequence-id, for @value{GDBN} remote
39043@noindent
39044That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
39045has never output @var{sequence-id}s. Stubs that handle packets added
39046since @value{GDBN} 5.0 must not accept @var{sequence-id}.
c906108c 39047
8e04817f
AC
39048When either the host or the target machine receives a packet, the first
39049response expected is an acknowledgment: either @samp{+} (to indicate
39050the package was received correctly) or @samp{-} (to request
39051retransmission):
c906108c 39052
474c8240 39053@smallexample
d2c6833e
AC
39054-> @code{$}@var{packet-data}@code{#}@var{checksum}
39055<- @code{+}
474c8240 39056@end smallexample
8e04817f 39057@noindent
53a5351d 39058
a6f3e723
SL
39059The @samp{+}/@samp{-} acknowledgments can be disabled
39060once a connection is established.
39061@xref{Packet Acknowledgment}, for details.
39062
8e04817f
AC
39063The host (@value{GDBN}) sends @var{command}s, and the target (the
39064debugging stub incorporated in your program) sends a @var{response}. In
39065the case of step and continue @var{command}s, the response is only sent
8b23ecc4
SL
39066when the operation has completed, and the target has again stopped all
39067threads in all attached processes. This is the default all-stop mode
39068behavior, but the remote protocol also supports @value{GDBN}'s non-stop
39069execution mode; see @ref{Remote Non-Stop}, for details.
c906108c 39070
8e04817f
AC
39071@var{packet-data} consists of a sequence of characters with the
39072exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
39073exceptions).
c906108c 39074
ee2d5c50 39075@cindex remote protocol, field separator
0876f84a 39076Fields within the packet should be separated using @samp{,} @samp{;} or
8e04817f 39077@samp{:}. Except where otherwise noted all numbers are represented in
ee2d5c50 39078@sc{hex} with leading zeros suppressed.
c906108c 39079
8e04817f
AC
39080Implementors should note that prior to @value{GDBN} 5.0, the character
39081@samp{:} could not appear as the third character in a packet (as it
39082would potentially conflict with the @var{sequence-id}).
c906108c 39083
0876f84a
DJ
39084@cindex remote protocol, binary data
39085@anchor{Binary Data}
39086Binary data in most packets is encoded either as two hexadecimal
39087digits per byte of binary data. This allowed the traditional remote
39088protocol to work over connections which were only seven-bit clean.
39089Some packets designed more recently assume an eight-bit clean
39090connection, and use a more efficient encoding to send and receive
39091binary data.
39092
39093The binary data representation uses @code{7d} (@sc{ascii} @samp{@}})
39094as an escape character. Any escaped byte is transmitted as the escape
39095character followed by the original character XORed with @code{0x20}.
39096For example, the byte @code{0x7d} would be transmitted as the two
39097bytes @code{0x7d 0x5d}. The bytes @code{0x23} (@sc{ascii} @samp{#}),
39098@code{0x24} (@sc{ascii} @samp{$}), and @code{0x7d} (@sc{ascii}
39099@samp{@}}) must always be escaped. Responses sent by the stub
39100must also escape @code{0x2a} (@sc{ascii} @samp{*}), so that it
39101is not interpreted as the start of a run-length encoded sequence
39102(described next).
39103
1d3811f6
DJ
39104Response @var{data} can be run-length encoded to save space.
39105Run-length encoding replaces runs of identical characters with one
39106instance of the repeated character, followed by a @samp{*} and a
39107repeat count. The repeat count is itself sent encoded, to avoid
39108binary characters in @var{data}: a value of @var{n} is sent as
39109@code{@var{n}+29}. For a repeat count greater or equal to 3, this
39110produces a printable @sc{ascii} character, e.g.@: a space (@sc{ascii}
39111code 32) for a repeat count of 3. (This is because run-length
39112encoding starts to win for counts 3 or more.) Thus, for example,
39113@samp{0* } is a run-length encoding of ``0000'': the space character
39114after @samp{*} means repeat the leading @code{0} @w{@code{32 - 29 =
391153}} more times.
39116
39117The printable characters @samp{#} and @samp{$} or with a numeric value
39118greater than 126 must not be used. Runs of six repeats (@samp{#}) or
39119seven repeats (@samp{$}) can be expanded using a repeat count of only
39120five (@samp{"}). For example, @samp{00000000} can be encoded as
39121@samp{0*"00}.
c906108c 39122
8e04817f
AC
39123The error response returned for some packets includes a two character
39124error number. That number is not well defined.
c906108c 39125
f8da2bff 39126@cindex empty response, for unsupported packets
8e04817f
AC
39127For any @var{command} not supported by the stub, an empty response
39128(@samp{$#00}) should be returned. That way it is possible to extend the
39129protocol. A newer @value{GDBN} can tell if a packet is supported based
39130on that response.
c906108c 39131
393eab54
PA
39132At a minimum, a stub is required to support the @samp{g} and @samp{G}
39133commands for register access, and the @samp{m} and @samp{M} commands
39134for memory access. Stubs that only control single-threaded targets
39135can implement run control with the @samp{c} (continue), and @samp{s}
39136(step) commands. Stubs that support multi-threading targets should
39137support the @samp{vCont} command. All other commands are optional.
c906108c 39138
ee2d5c50
AC
39139@node Packets
39140@section Packets
39141
39142The following table provides a complete list of all currently defined
39143@var{command}s and their corresponding response @var{data}.
79a6e687 39144@xref{File-I/O Remote Protocol Extension}, for details about the File
9c16f35a 39145I/O extension of the remote protocol.
ee2d5c50 39146
b8ff78ce
JB
39147Each packet's description has a template showing the packet's overall
39148syntax, followed by an explanation of the packet's meaning. We
39149include spaces in some of the templates for clarity; these are not
39150part of the packet's syntax. No @value{GDBN} packet uses spaces to
39151separate its components. For example, a template like @samp{foo
39152@var{bar} @var{baz}} describes a packet beginning with the three ASCII
39153bytes @samp{foo}, followed by a @var{bar}, followed directly by a
3f94c067 39154@var{baz}. @value{GDBN} does not transmit a space character between the
b8ff78ce
JB
39155@samp{foo} and the @var{bar}, or between the @var{bar} and the
39156@var{baz}.
39157
b90a069a
SL
39158@cindex @var{thread-id}, in remote protocol
39159@anchor{thread-id syntax}
39160Several packets and replies include a @var{thread-id} field to identify
39161a thread. Normally these are positive numbers with a target-specific
39162interpretation, formatted as big-endian hex strings. A @var{thread-id}
39163can also be a literal @samp{-1} to indicate all threads, or @samp{0} to
39164pick any thread.
39165
39166In addition, the remote protocol supports a multiprocess feature in
39167which the @var{thread-id} syntax is extended to optionally include both
39168process and thread ID fields, as @samp{p@var{pid}.@var{tid}}.
39169The @var{pid} (process) and @var{tid} (thread) components each have the
39170format described above: a positive number with target-specific
39171interpretation formatted as a big-endian hex string, literal @samp{-1}
39172to indicate all processes or threads (respectively), or @samp{0} to
39173indicate an arbitrary process or thread. Specifying just a process, as
39174@samp{p@var{pid}}, is equivalent to @samp{p@var{pid}.-1}. It is an
39175error to specify all processes but a specific thread, such as
39176@samp{p-1.@var{tid}}. Note that the @samp{p} prefix is @emph{not} used
39177for those packets and replies explicitly documented to include a process
39178ID, rather than a @var{thread-id}.
39179
39180The multiprocess @var{thread-id} syntax extensions are only used if both
39181@value{GDBN} and the stub report support for the @samp{multiprocess}
39182feature using @samp{qSupported}. @xref{multiprocess extensions}, for
39183more information.
39184
8ffe2530
JB
39185Note that all packet forms beginning with an upper- or lower-case
39186letter, other than those described here, are reserved for future use.
39187
b8ff78ce 39188Here are the packet descriptions.
ee2d5c50 39189
b8ff78ce 39190@table @samp
ee2d5c50 39191
b8ff78ce
JB
39192@item !
39193@cindex @samp{!} packet
2d717e4f 39194@anchor{extended mode}
8e04817f
AC
39195Enable extended mode. In extended mode, the remote server is made
39196persistent. The @samp{R} packet is used to restart the program being
39197debugged.
ee2d5c50
AC
39198
39199Reply:
39200@table @samp
39201@item OK
8e04817f 39202The remote target both supports and has enabled extended mode.
ee2d5c50 39203@end table
c906108c 39204
b8ff78ce
JB
39205@item ?
39206@cindex @samp{?} packet
36cb1214 39207@anchor{? packet}
ee2d5c50 39208Indicate the reason the target halted. The reply is the same as for
8b23ecc4
SL
39209step and continue. This packet has a special interpretation when the
39210target is in non-stop mode; see @ref{Remote Non-Stop}.
c906108c 39211
ee2d5c50
AC
39212Reply:
39213@xref{Stop Reply Packets}, for the reply specifications.
39214
b8ff78ce
JB
39215@item A @var{arglen},@var{argnum},@var{arg},@dots{}
39216@cindex @samp{A} packet
39217Initialized @code{argv[]} array passed into program. @var{arglen}
39218specifies the number of bytes in the hex encoded byte stream
39219@var{arg}. See @code{gdbserver} for more details.
ee2d5c50
AC
39220
39221Reply:
39222@table @samp
39223@item OK
b8ff78ce
JB
39224The arguments were set.
39225@item E @var{NN}
39226An error occurred.
ee2d5c50
AC
39227@end table
39228
b8ff78ce
JB
39229@item b @var{baud}
39230@cindex @samp{b} packet
39231(Don't use this packet; its behavior is not well-defined.)
ee2d5c50
AC
39232Change the serial line speed to @var{baud}.
39233
39234JTC: @emph{When does the transport layer state change? When it's
39235received, or after the ACK is transmitted. In either case, there are
39236problems if the command or the acknowledgment packet is dropped.}
39237
39238Stan: @emph{If people really wanted to add something like this, and get
39239it working for the first time, they ought to modify ser-unix.c to send
39240some kind of out-of-band message to a specially-setup stub and have the
39241switch happen "in between" packets, so that from remote protocol's point
39242of view, nothing actually happened.}
39243
b8ff78ce
JB
39244@item B @var{addr},@var{mode}
39245@cindex @samp{B} packet
8e04817f 39246Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
2f870471
AC
39247breakpoint at @var{addr}.
39248
b8ff78ce 39249Don't use this packet. Use the @samp{Z} and @samp{z} packets instead
2f870471 39250(@pxref{insert breakpoint or watchpoint packet}).
c906108c 39251
bacec72f 39252@cindex @samp{bc} packet
0d772ac9
MS
39253@anchor{bc}
39254@item bc
bacec72f
MS
39255Backward continue. Execute the target system in reverse. No parameter.
39256@xref{Reverse Execution}, for more information.
39257
39258Reply:
39259@xref{Stop Reply Packets}, for the reply specifications.
39260
bacec72f 39261@cindex @samp{bs} packet
0d772ac9
MS
39262@anchor{bs}
39263@item bs
bacec72f
MS
39264Backward single step. Execute one instruction in reverse. No parameter.
39265@xref{Reverse Execution}, for more information.
39266
39267Reply:
39268@xref{Stop Reply Packets}, for the reply specifications.
39269
4f553f88 39270@item c @r{[}@var{addr}@r{]}
b8ff78ce 39271@cindex @samp{c} packet
697aa1b7
EZ
39272Continue at @var{addr}, which is the address to resume. If @var{addr}
39273is omitted, resume at current address.
c906108c 39274
393eab54
PA
39275This packet is deprecated for multi-threading support. @xref{vCont
39276packet}.
39277
ee2d5c50
AC
39278Reply:
39279@xref{Stop Reply Packets}, for the reply specifications.
39280
4f553f88 39281@item C @var{sig}@r{[};@var{addr}@r{]}
b8ff78ce 39282@cindex @samp{C} packet
8e04817f 39283Continue with signal @var{sig} (hex signal number). If
b8ff78ce 39284@samp{;@var{addr}} is omitted, resume at same address.
c906108c 39285
393eab54
PA
39286This packet is deprecated for multi-threading support. @xref{vCont
39287packet}.
39288
ee2d5c50
AC
39289Reply:
39290@xref{Stop Reply Packets}, for the reply specifications.
c906108c 39291
b8ff78ce
JB
39292@item d
39293@cindex @samp{d} packet
ee2d5c50
AC
39294Toggle debug flag.
39295
b8ff78ce
JB
39296Don't use this packet; instead, define a general set packet
39297(@pxref{General Query Packets}).
ee2d5c50 39298
b8ff78ce 39299@item D
b90a069a 39300@itemx D;@var{pid}
b8ff78ce 39301@cindex @samp{D} packet
b90a069a
SL
39302The first form of the packet is used to detach @value{GDBN} from the
39303remote system. It is sent to the remote target
07f31aa6 39304before @value{GDBN} disconnects via the @code{detach} command.
ee2d5c50 39305
b90a069a
SL
39306The second form, including a process ID, is used when multiprocess
39307protocol extensions are enabled (@pxref{multiprocess extensions}), to
39308detach only a specific process. The @var{pid} is specified as a
39309big-endian hex string.
39310
ee2d5c50
AC
39311Reply:
39312@table @samp
10fac096
NW
39313@item OK
39314for success
b8ff78ce 39315@item E @var{NN}
10fac096 39316for an error
ee2d5c50 39317@end table
c906108c 39318
b8ff78ce
JB
39319@item F @var{RC},@var{EE},@var{CF};@var{XX}
39320@cindex @samp{F} packet
39321A reply from @value{GDBN} to an @samp{F} packet sent by the target.
39322This is part of the File-I/O protocol extension. @xref{File-I/O
79a6e687 39323Remote Protocol Extension}, for the specification.
ee2d5c50 39324
b8ff78ce 39325@item g
ee2d5c50 39326@anchor{read registers packet}
b8ff78ce 39327@cindex @samp{g} packet
ee2d5c50
AC
39328Read general registers.
39329
39330Reply:
39331@table @samp
39332@item @var{XX@dots{}}
8e04817f
AC
39333Each byte of register data is described by two hex digits. The bytes
39334with the register are transmitted in target byte order. The size of
b8ff78ce 39335each register and their position within the @samp{g} packet are
4a9bb1df 39336determined by the @value{GDBN} internal gdbarch functions
4435e1cc 39337@code{DEPRECATED_REGISTER_RAW_SIZE} and @code{gdbarch_register_name}.
ad196637
PA
39338
39339When reading registers from a trace frame (@pxref{Analyze Collected
39340Data,,Using the Collected Data}), the stub may also return a string of
39341literal @samp{x}'s in place of the register data digits, to indicate
39342that the corresponding register has not been collected, thus its value
39343is unavailable. For example, for an architecture with 4 registers of
393444 bytes each, the following reply indicates to @value{GDBN} that
39345registers 0 and 2 have not been collected, while registers 1 and 3
39346have been collected, and both have zero value:
39347
39348@smallexample
39349-> @code{g}
39350<- @code{xxxxxxxx00000000xxxxxxxx00000000}
39351@end smallexample
39352
b8ff78ce 39353@item E @var{NN}
ee2d5c50
AC
39354for an error.
39355@end table
c906108c 39356
b8ff78ce
JB
39357@item G @var{XX@dots{}}
39358@cindex @samp{G} packet
39359Write general registers. @xref{read registers packet}, for a
39360description of the @var{XX@dots{}} data.
ee2d5c50
AC
39361
39362Reply:
39363@table @samp
39364@item OK
39365for success
b8ff78ce 39366@item E @var{NN}
ee2d5c50
AC
39367for an error
39368@end table
39369
393eab54 39370@item H @var{op} @var{thread-id}
b8ff78ce 39371@cindex @samp{H} packet
8e04817f 39372Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
697aa1b7
EZ
39373@samp{G}, et.al.). Depending on the operation to be performed, @var{op}
39374should be @samp{c} for step and continue operations (note that this
393eab54 39375is deprecated, supporting the @samp{vCont} command is a better
697aa1b7 39376option), and @samp{g} for other operations. The thread designator
393eab54
PA
39377@var{thread-id} has the format and interpretation described in
39378@ref{thread-id syntax}.
ee2d5c50
AC
39379
39380Reply:
39381@table @samp
39382@item OK
39383for success
b8ff78ce 39384@item E @var{NN}
ee2d5c50
AC
39385for an error
39386@end table
c906108c 39387
8e04817f
AC
39388@c FIXME: JTC:
39389@c 'H': How restrictive (or permissive) is the thread model. If a
39390@c thread is selected and stopped, are other threads allowed
39391@c to continue to execute? As I mentioned above, I think the
39392@c semantics of each command when a thread is selected must be
39393@c described. For example:
39394@c
39395@c 'g': If the stub supports threads and a specific thread is
39396@c selected, returns the register block from that thread;
39397@c otherwise returns current registers.
39398@c
39399@c 'G' If the stub supports threads and a specific thread is
39400@c selected, sets the registers of the register block of
39401@c that thread; otherwise sets current registers.
c906108c 39402
b8ff78ce 39403@item i @r{[}@var{addr}@r{[},@var{nnn}@r{]]}
ee2d5c50 39404@anchor{cycle step packet}
b8ff78ce
JB
39405@cindex @samp{i} packet
39406Step the remote target by a single clock cycle. If @samp{,@var{nnn}} is
8e04817f
AC
39407present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
39408step starting at that address.
c906108c 39409
b8ff78ce
JB
39410@item I
39411@cindex @samp{I} packet
39412Signal, then cycle step. @xref{step with signal packet}. @xref{cycle
39413step packet}.
ee2d5c50 39414
b8ff78ce
JB
39415@item k
39416@cindex @samp{k} packet
39417Kill request.
c906108c 39418
36cb1214
HZ
39419The exact effect of this packet is not specified.
39420
39421For a bare-metal target, it may power cycle or reset the target
39422system. For that reason, the @samp{k} packet has no reply.
39423
39424For a single-process target, it may kill that process if possible.
39425
39426A multiple-process target may choose to kill just one process, or all
39427that are under @value{GDBN}'s control. For more precise control, use
39428the vKill packet (@pxref{vKill packet}).
39429
39430If the target system immediately closes the connection in response to
39431@samp{k}, @value{GDBN} does not consider the lack of packet
39432acknowledgment to be an error, and assumes the kill was successful.
39433
39434If connected using @kbd{target extended-remote}, and the target does
39435not close the connection in response to a kill request, @value{GDBN}
39436probes the target state as if a new connection was opened
39437(@pxref{? packet}).
c906108c 39438
b8ff78ce
JB
39439@item m @var{addr},@var{length}
39440@cindex @samp{m} packet
a86c90e6
SM
39441Read @var{length} addressable memory units starting at address @var{addr}
39442(@pxref{addressable memory unit}). Note that @var{addr} may not be aligned to
39443any particular boundary.
fb031cdf
JB
39444
39445The stub need not use any particular size or alignment when gathering
39446data from memory for the response; even if @var{addr} is word-aligned
39447and @var{length} is a multiple of the word size, the stub is free to
39448use byte accesses, or not. For this reason, this packet may not be
39449suitable for accessing memory-mapped I/O devices.
c43c5473
JB
39450@cindex alignment of remote memory accesses
39451@cindex size of remote memory accesses
39452@cindex memory, alignment and size of remote accesses
c906108c 39453
ee2d5c50
AC
39454Reply:
39455@table @samp
39456@item @var{XX@dots{}}
a86c90e6
SM
39457Memory contents; each byte is transmitted as a two-digit hexadecimal number.
39458The reply may contain fewer addressable memory units than requested if the
b8ff78ce
JB
39459server was able to read only part of the region of memory.
39460@item E @var{NN}
ee2d5c50
AC
39461@var{NN} is errno
39462@end table
39463
b8ff78ce
JB
39464@item M @var{addr},@var{length}:@var{XX@dots{}}
39465@cindex @samp{M} packet
a86c90e6
SM
39466Write @var{length} addressable memory units starting at address @var{addr}
39467(@pxref{addressable memory unit}). The data is given by @var{XX@dots{}}; each
39468byte is transmitted as a two-digit hexadecimal number.
ee2d5c50
AC
39469
39470Reply:
39471@table @samp
39472@item OK
39473for success
b8ff78ce 39474@item E @var{NN}
8e04817f
AC
39475for an error (this includes the case where only part of the data was
39476written).
ee2d5c50 39477@end table
c906108c 39478
b8ff78ce
JB
39479@item p @var{n}
39480@cindex @samp{p} packet
39481Read the value of register @var{n}; @var{n} is in hex.
2e868123
AC
39482@xref{read registers packet}, for a description of how the returned
39483register value is encoded.
ee2d5c50
AC
39484
39485Reply:
39486@table @samp
2e868123
AC
39487@item @var{XX@dots{}}
39488the register's value
b8ff78ce 39489@item E @var{NN}
2e868123 39490for an error
d57350ea 39491@item @w{}
2e868123 39492Indicating an unrecognized @var{query}.
ee2d5c50
AC
39493@end table
39494
b8ff78ce 39495@item P @var{n@dots{}}=@var{r@dots{}}
ee2d5c50 39496@anchor{write register packet}
b8ff78ce
JB
39497@cindex @samp{P} packet
39498Write register @var{n@dots{}} with value @var{r@dots{}}. The register
599b237a 39499number @var{n} is in hexadecimal, and @var{r@dots{}} contains two hex
8e04817f 39500digits for each byte in the register (target byte order).
c906108c 39501
ee2d5c50
AC
39502Reply:
39503@table @samp
39504@item OK
39505for success
b8ff78ce 39506@item E @var{NN}
ee2d5c50
AC
39507for an error
39508@end table
39509
5f3bebba
JB
39510@item q @var{name} @var{params}@dots{}
39511@itemx Q @var{name} @var{params}@dots{}
b8ff78ce 39512@cindex @samp{q} packet
b8ff78ce 39513@cindex @samp{Q} packet
5f3bebba
JB
39514General query (@samp{q}) and set (@samp{Q}). These packets are
39515described fully in @ref{General Query Packets}.
c906108c 39516
b8ff78ce
JB
39517@item r
39518@cindex @samp{r} packet
8e04817f 39519Reset the entire system.
c906108c 39520
b8ff78ce 39521Don't use this packet; use the @samp{R} packet instead.
ee2d5c50 39522
b8ff78ce
JB
39523@item R @var{XX}
39524@cindex @samp{R} packet
697aa1b7 39525Restart the program being debugged. The @var{XX}, while needed, is ignored.
2d717e4f 39526This packet is only available in extended mode (@pxref{extended mode}).
ee2d5c50 39527
8e04817f 39528The @samp{R} packet has no reply.
ee2d5c50 39529
4f553f88 39530@item s @r{[}@var{addr}@r{]}
b8ff78ce 39531@cindex @samp{s} packet
697aa1b7 39532Single step, resuming at @var{addr}. If
b8ff78ce 39533@var{addr} is omitted, resume at same address.
c906108c 39534
393eab54
PA
39535This packet is deprecated for multi-threading support. @xref{vCont
39536packet}.
39537
ee2d5c50
AC
39538Reply:
39539@xref{Stop Reply Packets}, for the reply specifications.
39540
4f553f88 39541@item S @var{sig}@r{[};@var{addr}@r{]}
ee2d5c50 39542@anchor{step with signal packet}
b8ff78ce
JB
39543@cindex @samp{S} packet
39544Step with signal. This is analogous to the @samp{C} packet, but
39545requests a single-step, rather than a normal resumption of execution.
c906108c 39546
393eab54
PA
39547This packet is deprecated for multi-threading support. @xref{vCont
39548packet}.
39549
ee2d5c50
AC
39550Reply:
39551@xref{Stop Reply Packets}, for the reply specifications.
39552
b8ff78ce
JB
39553@item t @var{addr}:@var{PP},@var{MM}
39554@cindex @samp{t} packet
8e04817f 39555Search backwards starting at address @var{addr} for a match with pattern
697aa1b7
EZ
39556@var{PP} and mask @var{MM}, both of which are are 4 byte long.
39557There must be at least 3 digits in @var{addr}.
c906108c 39558
b90a069a 39559@item T @var{thread-id}
b8ff78ce 39560@cindex @samp{T} packet
b90a069a 39561Find out if the thread @var{thread-id} is alive. @xref{thread-id syntax}.
c906108c 39562
ee2d5c50
AC
39563Reply:
39564@table @samp
39565@item OK
39566thread is still alive
b8ff78ce 39567@item E @var{NN}
ee2d5c50
AC
39568thread is dead
39569@end table
39570
b8ff78ce
JB
39571@item v
39572Packets starting with @samp{v} are identified by a multi-letter name,
39573up to the first @samp{;} or @samp{?} (or the end of the packet).
86d30acc 39574
2d717e4f
DJ
39575@item vAttach;@var{pid}
39576@cindex @samp{vAttach} packet
8b23ecc4
SL
39577Attach to a new process with the specified process ID @var{pid}.
39578The process ID is a
39579hexadecimal integer identifying the process. In all-stop mode, all
39580threads in the attached process are stopped; in non-stop mode, it may be
39581attached without being stopped if that is supported by the target.
39582
39583@c In non-stop mode, on a successful vAttach, the stub should set the
39584@c current thread to a thread of the newly-attached process. After
39585@c attaching, GDB queries for the attached process's thread ID with qC.
39586@c Also note that, from a user perspective, whether or not the
39587@c target is stopped on attach in non-stop mode depends on whether you
39588@c use the foreground or background version of the attach command, not
39589@c on what vAttach does; GDB does the right thing with respect to either
39590@c stopping or restarting threads.
2d717e4f
DJ
39591
39592This packet is only available in extended mode (@pxref{extended mode}).
39593
39594Reply:
39595@table @samp
39596@item E @var{nn}
39597for an error
39598@item @r{Any stop packet}
8b23ecc4
SL
39599for success in all-stop mode (@pxref{Stop Reply Packets})
39600@item OK
39601for success in non-stop mode (@pxref{Remote Non-Stop})
2d717e4f
DJ
39602@end table
39603
b90a069a 39604@item vCont@r{[};@var{action}@r{[}:@var{thread-id}@r{]]}@dots{}
b8ff78ce 39605@cindex @samp{vCont} packet
393eab54 39606@anchor{vCont packet}
b8ff78ce 39607Resume the inferior, specifying different actions for each thread.
ca6eff59
PA
39608
39609For each inferior thread, the leftmost action with a matching
39610@var{thread-id} is applied. Threads that don't match any action
39611remain in their current state. Thread IDs are specified using the
39612syntax described in @ref{thread-id syntax}. If multiprocess
39613extensions (@pxref{multiprocess extensions}) are supported, actions
39614can be specified to match all threads in a process by using the
39615@samp{p@var{pid}.-1} form of the @var{thread-id}. An action with no
39402e6c
PA
39616@var{thread-id} matches all threads. Specifying no actions is an
39617error.
b90a069a
SL
39618
39619Currently supported actions are:
86d30acc 39620
b8ff78ce 39621@table @samp
86d30acc
DJ
39622@item c
39623Continue.
b8ff78ce 39624@item C @var{sig}
8b23ecc4 39625Continue with signal @var{sig}. The signal @var{sig} should be two hex digits.
86d30acc
DJ
39626@item s
39627Step.
b8ff78ce 39628@item S @var{sig}
8b23ecc4
SL
39629Step with signal @var{sig}. The signal @var{sig} should be two hex digits.
39630@item t
39631Stop.
c1e36e3e
PA
39632@item r @var{start},@var{end}
39633Step once, and then keep stepping as long as the thread stops at
39634addresses between @var{start} (inclusive) and @var{end} (exclusive).
39635The remote stub reports a stop reply when either the thread goes out
39636of the range or is stopped due to an unrelated reason, such as hitting
39637a breakpoint. @xref{range stepping}.
39638
39639If the range is empty (@var{start} == @var{end}), then the action
39640becomes equivalent to the @samp{s} action. In other words,
39641single-step once, and report the stop (even if the stepped instruction
39642jumps to @var{start}).
39643
39644(A stop reply may be sent at any point even if the PC is still within
39645the stepping range; for example, it is valid to implement this packet
39646in a degenerate way as a single instruction step operation.)
39647
86d30acc
DJ
39648@end table
39649
8b23ecc4
SL
39650The optional argument @var{addr} normally associated with the
39651@samp{c}, @samp{C}, @samp{s}, and @samp{S} packets is
b8ff78ce 39652not supported in @samp{vCont}.
86d30acc 39653
08a0efd0
PA
39654The @samp{t} action is only relevant in non-stop mode
39655(@pxref{Remote Non-Stop}) and may be ignored by the stub otherwise.
8b23ecc4
SL
39656A stop reply should be generated for any affected thread not already stopped.
39657When a thread is stopped by means of a @samp{t} action,
39658the corresponding stop reply should indicate that the thread has stopped with
39659signal @samp{0}, regardless of whether the target uses some other signal
39660as an implementation detail.
39661
ca6eff59
PA
39662The server must ignore @samp{c}, @samp{C}, @samp{s}, @samp{S}, and
39663@samp{r} actions for threads that are already running. Conversely,
39664the server must ignore @samp{t} actions for threads that are already
39665stopped.
39666
39667@emph{Note:} In non-stop mode, a thread is considered running until
6b92c0d3 39668@value{GDBN} acknowledges an asynchronous stop notification for it with
ca6eff59
PA
39669the @samp{vStopped} packet (@pxref{Remote Non-Stop}).
39670
4220b2f8 39671The stub must support @samp{vCont} if it reports support for
ca6eff59 39672multiprocess extensions (@pxref{multiprocess extensions}).
4220b2f8 39673
86d30acc
DJ
39674Reply:
39675@xref{Stop Reply Packets}, for the reply specifications.
39676
b8ff78ce
JB
39677@item vCont?
39678@cindex @samp{vCont?} packet
d3e8051b 39679Request a list of actions supported by the @samp{vCont} packet.
86d30acc
DJ
39680
39681Reply:
39682@table @samp
b8ff78ce
JB
39683@item vCont@r{[};@var{action}@dots{}@r{]}
39684The @samp{vCont} packet is supported. Each @var{action} is a supported
39685command in the @samp{vCont} packet.
d57350ea 39686@item @w{}
b8ff78ce 39687The @samp{vCont} packet is not supported.
86d30acc 39688@end table
ee2d5c50 39689
de979965
PA
39690@anchor{vCtrlC packet}
39691@item vCtrlC
39692@cindex @samp{vCtrlC} packet
39693Interrupt remote target as if a control-C was pressed on the remote
39694terminal. This is the equivalent to reacting to the @code{^C}
39695(@samp{\003}, the control-C character) character in all-stop mode
39696while the target is running, except this works in non-stop mode.
39697@xref{interrupting remote targets}, for more info on the all-stop
39698variant.
39699
39700Reply:
39701@table @samp
39702@item E @var{nn}
39703for an error
39704@item OK
39705for success
39706@end table
39707
a6b151f1
DJ
39708@item vFile:@var{operation}:@var{parameter}@dots{}
39709@cindex @samp{vFile} packet
39710Perform a file operation on the target system. For details,
39711see @ref{Host I/O Packets}.
39712
68437a39
DJ
39713@item vFlashErase:@var{addr},@var{length}
39714@cindex @samp{vFlashErase} packet
39715Direct the stub to erase @var{length} bytes of flash starting at
39716@var{addr}. The region may enclose any number of flash blocks, but
39717its start and end must fall on block boundaries, as indicated by the
79a6e687
BW
39718flash block size appearing in the memory map (@pxref{Memory Map
39719Format}). @value{GDBN} groups flash memory programming operations
68437a39
DJ
39720together, and sends a @samp{vFlashDone} request after each group; the
39721stub is allowed to delay erase operation until the @samp{vFlashDone}
39722packet is received.
39723
39724Reply:
39725@table @samp
39726@item OK
39727for success
39728@item E @var{NN}
39729for an error
39730@end table
39731
39732@item vFlashWrite:@var{addr}:@var{XX@dots{}}
39733@cindex @samp{vFlashWrite} packet
39734Direct the stub to write data to flash address @var{addr}. The data
39735is passed in binary form using the same encoding as for the @samp{X}
39736packet (@pxref{Binary Data}). The memory ranges specified by
39737@samp{vFlashWrite} packets preceding a @samp{vFlashDone} packet must
39738not overlap, and must appear in order of increasing addresses
39739(although @samp{vFlashErase} packets for higher addresses may already
39740have been received; the ordering is guaranteed only between
39741@samp{vFlashWrite} packets). If a packet writes to an address that was
39742neither erased by a preceding @samp{vFlashErase} packet nor by some other
39743target-specific method, the results are unpredictable.
39744
39745
39746Reply:
39747@table @samp
39748@item OK
39749for success
39750@item E.memtype
39751for vFlashWrite addressing non-flash memory
39752@item E @var{NN}
39753for an error
39754@end table
39755
39756@item vFlashDone
39757@cindex @samp{vFlashDone} packet
39758Indicate to the stub that flash programming operation is finished.
39759The stub is permitted to delay or batch the effects of a group of
39760@samp{vFlashErase} and @samp{vFlashWrite} packets until a
39761@samp{vFlashDone} packet is received. The contents of the affected
39762regions of flash memory are unpredictable until the @samp{vFlashDone}
39763request is completed.
39764
b90a069a
SL
39765@item vKill;@var{pid}
39766@cindex @samp{vKill} packet
36cb1214 39767@anchor{vKill packet}
697aa1b7 39768Kill the process with the specified process ID @var{pid}, which is a
b90a069a
SL
39769hexadecimal integer identifying the process. This packet is used in
39770preference to @samp{k} when multiprocess protocol extensions are
39771supported; see @ref{multiprocess extensions}.
39772
39773Reply:
39774@table @samp
39775@item E @var{nn}
39776for an error
39777@item OK
39778for success
39779@end table
39780
176efed1
AB
39781@item vMustReplyEmpty
39782@cindex @samp{vMustReplyEmpty} packet
39783The correct reply to an unknown @samp{v} packet is to return the empty
39784string, however, some older versions of @command{gdbserver} would
39785incorrectly return @samp{OK} for unknown @samp{v} packets.
39786
39787The @samp{vMustReplyEmpty} is used as a feature test to check how
39788@command{gdbserver} handles unknown packets, it is important that this
39789packet be handled in the same way as other unknown @samp{v} packets.
39790If this packet is handled differently to other unknown @samp{v}
6b92c0d3 39791packets then it is possible that @value{GDBN} may run into problems in
176efed1
AB
39792other areas, specifically around use of @samp{vFile:setfs:}.
39793
2d717e4f
DJ
39794@item vRun;@var{filename}@r{[};@var{argument}@r{]}@dots{}
39795@cindex @samp{vRun} packet
39796Run the program @var{filename}, passing it each @var{argument} on its
39797command line. The file and arguments are hex-encoded strings. If
39798@var{filename} is an empty string, the stub may use a default program
39799(e.g.@: the last program run). The program is created in the stopped
9b562ab8 39800state.
2d717e4f 39801
8b23ecc4
SL
39802@c FIXME: What about non-stop mode?
39803
2d717e4f
DJ
39804This packet is only available in extended mode (@pxref{extended mode}).
39805
39806Reply:
39807@table @samp
39808@item E @var{nn}
39809for an error
39810@item @r{Any stop packet}
39811for success (@pxref{Stop Reply Packets})
39812@end table
39813
8b23ecc4 39814@item vStopped
8b23ecc4 39815@cindex @samp{vStopped} packet
8dbe8ece 39816@xref{Notification Packets}.
8b23ecc4 39817
b8ff78ce 39818@item X @var{addr},@var{length}:@var{XX@dots{}}
9a6253be 39819@anchor{X packet}
b8ff78ce
JB
39820@cindex @samp{X} packet
39821Write data to memory, where the data is transmitted in binary.
a86c90e6
SM
39822Memory is specified by its address @var{addr} and number of addressable memory
39823units @var{length} (@pxref{addressable memory unit});
0876f84a 39824@samp{@var{XX}@dots{}} is binary data (@pxref{Binary Data}).
c906108c 39825
ee2d5c50
AC
39826Reply:
39827@table @samp
39828@item OK
39829for success
b8ff78ce 39830@item E @var{NN}
ee2d5c50
AC
39831for an error
39832@end table
39833
a1dcb23a
DJ
39834@item z @var{type},@var{addr},@var{kind}
39835@itemx Z @var{type},@var{addr},@var{kind}
2f870471 39836@anchor{insert breakpoint or watchpoint packet}
b8ff78ce
JB
39837@cindex @samp{z} packet
39838@cindex @samp{Z} packets
39839Insert (@samp{Z}) or remove (@samp{z}) a @var{type} breakpoint or
a1dcb23a 39840watchpoint starting at address @var{address} of kind @var{kind}.
ee2d5c50 39841
2f870471
AC
39842Each breakpoint and watchpoint packet @var{type} is documented
39843separately.
39844
512217c7
AC
39845@emph{Implementation notes: A remote target shall return an empty string
39846for an unrecognized breakpoint or watchpoint packet @var{type}. A
39847remote target shall support either both or neither of a given
b8ff78ce 39848@samp{Z@var{type}@dots{}} and @samp{z@var{type}@dots{}} packet pair. To
2f870471
AC
39849avoid potential problems with duplicate packets, the operations should
39850be implemented in an idempotent way.}
39851
a1dcb23a 39852@item z0,@var{addr},@var{kind}
d3ce09f5 39853@itemx Z0,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}@r{[};cmds:@var{persist},@var{cmd_list}@dots{}@r{]}
b8ff78ce
JB
39854@cindex @samp{z0} packet
39855@cindex @samp{Z0} packet
4435e1cc 39856Insert (@samp{Z0}) or remove (@samp{z0}) a software breakpoint at address
a1dcb23a 39857@var{addr} of type @var{kind}.
2f870471 39858
4435e1cc 39859A software breakpoint is implemented by replacing the instruction at
2f870471 39860@var{addr} with a software breakpoint or trap instruction. The
4435e1cc
TT
39861@var{kind} is target-specific and typically indicates the size of the
39862breakpoint in bytes that should be inserted. E.g., the @sc{arm} and
39863@sc{mips} can insert either a 2 or 4 byte breakpoint. Some
39864architectures have additional meanings for @var{kind}
39865(@pxref{Architecture-Specific Protocol Details}); if no
39866architecture-specific value is being used, it should be @samp{0}.
39867@var{kind} is hex-encoded. @var{cond_list} is an optional list of
39868conditional expressions in bytecode form that should be evaluated on
39869the target's side. These are the conditions that should be taken into
39870consideration when deciding if the breakpoint trigger should be
39871reported back to @value{GDBN}.
83364271 39872
f7e6eed5 39873See also the @samp{swbreak} stop reason (@pxref{swbreak stop reason})
4435e1cc 39874for how to best report a software breakpoint event to @value{GDBN}.
f7e6eed5 39875
83364271
LM
39876The @var{cond_list} parameter is comprised of a series of expressions,
39877concatenated without separators. Each expression has the following form:
39878
39879@table @samp
39880
39881@item X @var{len},@var{expr}
39882@var{len} is the length of the bytecode expression and @var{expr} is the
39883actual conditional expression in bytecode form.
39884
39885@end table
39886
d3ce09f5
SS
39887The optional @var{cmd_list} parameter introduces commands that may be
39888run on the target, rather than being reported back to @value{GDBN}.
39889The parameter starts with a numeric flag @var{persist}; if the flag is
39890nonzero, then the breakpoint may remain active and the commands
39891continue to be run even when @value{GDBN} disconnects from the target.
39892Following this flag is a series of expressions concatenated with no
39893separators. Each expression has the following form:
39894
39895@table @samp
39896
39897@item X @var{len},@var{expr}
39898@var{len} is the length of the bytecode expression and @var{expr} is the
0968fbae 39899actual commands expression in bytecode form.
d3ce09f5
SS
39900
39901@end table
39902
2f870471 39903@emph{Implementation note: It is possible for a target to copy or move
4435e1cc 39904code that contains software breakpoints (e.g., when implementing
2f870471
AC
39905overlays). The behavior of this packet, in the presence of such a
39906target, is not defined.}
c906108c 39907
ee2d5c50
AC
39908Reply:
39909@table @samp
2f870471
AC
39910@item OK
39911success
d57350ea 39912@item @w{}
2f870471 39913not supported
b8ff78ce 39914@item E @var{NN}
ee2d5c50 39915for an error
2f870471
AC
39916@end table
39917
a1dcb23a 39918@item z1,@var{addr},@var{kind}
4435e1cc 39919@itemx Z1,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}@r{[};cmds:@var{persist},@var{cmd_list}@dots{}@r{]}
b8ff78ce
JB
39920@cindex @samp{z1} packet
39921@cindex @samp{Z1} packet
39922Insert (@samp{Z1}) or remove (@samp{z1}) a hardware breakpoint at
a1dcb23a 39923address @var{addr}.
2f870471
AC
39924
39925A hardware breakpoint is implemented using a mechanism that is not
4435e1cc
TT
39926dependent on being able to modify the target's memory. The
39927@var{kind}, @var{cond_list}, and @var{cmd_list} arguments have the
39928same meaning as in @samp{Z0} packets.
2f870471
AC
39929
39930@emph{Implementation note: A hardware breakpoint is not affected by code
39931movement.}
39932
39933Reply:
39934@table @samp
ee2d5c50 39935@item OK
2f870471 39936success
d57350ea 39937@item @w{}
2f870471 39938not supported
b8ff78ce 39939@item E @var{NN}
2f870471
AC
39940for an error
39941@end table
39942
a1dcb23a
DJ
39943@item z2,@var{addr},@var{kind}
39944@itemx Z2,@var{addr},@var{kind}
b8ff78ce
JB
39945@cindex @samp{z2} packet
39946@cindex @samp{Z2} packet
a1dcb23a 39947Insert (@samp{Z2}) or remove (@samp{z2}) a write watchpoint at @var{addr}.
697aa1b7 39948The number of bytes to watch is specified by @var{kind}.
2f870471
AC
39949
39950Reply:
39951@table @samp
39952@item OK
39953success
d57350ea 39954@item @w{}
2f870471 39955not supported
b8ff78ce 39956@item E @var{NN}
2f870471
AC
39957for an error
39958@end table
39959
a1dcb23a
DJ
39960@item z3,@var{addr},@var{kind}
39961@itemx Z3,@var{addr},@var{kind}
b8ff78ce
JB
39962@cindex @samp{z3} packet
39963@cindex @samp{Z3} packet
a1dcb23a 39964Insert (@samp{Z3}) or remove (@samp{z3}) a read watchpoint at @var{addr}.
697aa1b7 39965The number of bytes to watch is specified by @var{kind}.
2f870471
AC
39966
39967Reply:
39968@table @samp
39969@item OK
39970success
d57350ea 39971@item @w{}
2f870471 39972not supported
b8ff78ce 39973@item E @var{NN}
2f870471
AC
39974for an error
39975@end table
39976
a1dcb23a
DJ
39977@item z4,@var{addr},@var{kind}
39978@itemx Z4,@var{addr},@var{kind}
b8ff78ce
JB
39979@cindex @samp{z4} packet
39980@cindex @samp{Z4} packet
a1dcb23a 39981Insert (@samp{Z4}) or remove (@samp{z4}) an access watchpoint at @var{addr}.
697aa1b7 39982The number of bytes to watch is specified by @var{kind}.
2f870471
AC
39983
39984Reply:
39985@table @samp
39986@item OK
39987success
d57350ea 39988@item @w{}
2f870471 39989not supported
b8ff78ce 39990@item E @var{NN}
2f870471 39991for an error
ee2d5c50
AC
39992@end table
39993
39994@end table
c906108c 39995
ee2d5c50
AC
39996@node Stop Reply Packets
39997@section Stop Reply Packets
39998@cindex stop reply packets
c906108c 39999
8b23ecc4
SL
40000The @samp{C}, @samp{c}, @samp{S}, @samp{s}, @samp{vCont},
40001@samp{vAttach}, @samp{vRun}, @samp{vStopped}, and @samp{?} packets can
40002receive any of the below as a reply. Except for @samp{?}
40003and @samp{vStopped}, that reply is only returned
b8ff78ce 40004when the target halts. In the below the exact meaning of @dfn{signal
89be2091
DJ
40005number} is defined by the header @file{include/gdb/signals.h} in the
40006@value{GDBN} source code.
c906108c 40007
4435e1cc
TT
40008In non-stop mode, the server will simply reply @samp{OK} to commands
40009such as @samp{vCont}; any stop will be the subject of a future
40010notification. @xref{Remote Non-Stop}.
40011
b8ff78ce
JB
40012As in the description of request packets, we include spaces in the
40013reply templates for clarity; these are not part of the reply packet's
40014syntax. No @value{GDBN} stop reply packet uses spaces to separate its
40015components.
c906108c 40016
b8ff78ce 40017@table @samp
ee2d5c50 40018
b8ff78ce 40019@item S @var{AA}
599b237a 40020The program received signal number @var{AA} (a two-digit hexadecimal
940178d3
JB
40021number). This is equivalent to a @samp{T} response with no
40022@var{n}:@var{r} pairs.
c906108c 40023
b8ff78ce
JB
40024@item T @var{AA} @var{n1}:@var{r1};@var{n2}:@var{r2};@dots{}
40025@cindex @samp{T} packet reply
599b237a 40026The program received signal number @var{AA} (a two-digit hexadecimal
940178d3
JB
40027number). This is equivalent to an @samp{S} response, except that the
40028@samp{@var{n}:@var{r}} pairs can carry values of important registers
40029and other information directly in the stop reply packet, reducing
40030round-trip latency. Single-step and breakpoint traps are reported
40031this way. Each @samp{@var{n}:@var{r}} pair is interpreted as follows:
cfa9d6d9
DJ
40032
40033@itemize @bullet
b8ff78ce 40034@item
599b237a 40035If @var{n} is a hexadecimal number, it is a register number, and the
697aa1b7 40036corresponding @var{r} gives that register's value. The data @var{r} is a
b8ff78ce
JB
40037series of bytes in target byte order, with each byte given by a
40038two-digit hex number.
cfa9d6d9 40039
b8ff78ce 40040@item
b90a069a
SL
40041If @var{n} is @samp{thread}, then @var{r} is the @var{thread-id} of
40042the stopped thread, as specified in @ref{thread-id syntax}.
cfa9d6d9 40043
dc146f7c
VP
40044@item
40045If @var{n} is @samp{core}, then @var{r} is the hexadecimal number of
40046the core on which the stop event was detected.
40047
b8ff78ce 40048@item
cfa9d6d9
DJ
40049If @var{n} is a recognized @dfn{stop reason}, it describes a more
40050specific event that stopped the target. The currently defined stop
697aa1b7 40051reasons are listed below. The @var{aa} should be @samp{05}, the trap
cfa9d6d9
DJ
40052signal. At most one stop reason should be present.
40053
b8ff78ce
JB
40054@item
40055Otherwise, @value{GDBN} should ignore this @samp{@var{n}:@var{r}} pair
40056and go on to the next; this allows us to extend the protocol in the
40057future.
cfa9d6d9
DJ
40058@end itemize
40059
40060The currently defined stop reasons are:
40061
40062@table @samp
40063@item watch
40064@itemx rwatch
40065@itemx awatch
40066The packet indicates a watchpoint hit, and @var{r} is the data address, in
40067hex.
40068
82075af2
JS
40069@item syscall_entry
40070@itemx syscall_return
40071The packet indicates a syscall entry or return, and @var{r} is the
40072syscall number, in hex.
40073
cfa9d6d9
DJ
40074@cindex shared library events, remote reply
40075@item library
40076The packet indicates that the loaded libraries have changed.
40077@value{GDBN} should use @samp{qXfer:libraries:read} to fetch a new
697aa1b7 40078list of loaded libraries. The @var{r} part is ignored.
bacec72f
MS
40079
40080@cindex replay log events, remote reply
40081@item replaylog
40082The packet indicates that the target cannot continue replaying
40083logged execution events, because it has reached the end (or the
40084beginning when executing backward) of the log. The value of @var{r}
40085will be either @samp{begin} or @samp{end}. @xref{Reverse Execution},
40086for more information.
f7e6eed5
PA
40087
40088@item swbreak
40089@anchor{swbreak stop reason}
4435e1cc 40090The packet indicates a software breakpoint instruction was executed,
f7e6eed5
PA
40091irrespective of whether it was @value{GDBN} that planted the
40092breakpoint or the breakpoint is hardcoded in the program. The @var{r}
40093part must be left empty.
40094
40095On some architectures, such as x86, at the architecture level, when a
40096breakpoint instruction executes the program counter points at the
40097breakpoint address plus an offset. On such targets, the stub is
40098responsible for adjusting the PC to point back at the breakpoint
40099address.
40100
40101This packet should not be sent by default; older @value{GDBN} versions
40102did not support it. @value{GDBN} requests it, by supplying an
40103appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40104remote stub must also supply the appropriate @samp{qSupported} feature
40105indicating support.
40106
40107This packet is required for correct non-stop mode operation.
40108
40109@item hwbreak
40110The packet indicates the target stopped for a hardware breakpoint.
40111The @var{r} part must be left empty.
40112
40113The same remarks about @samp{qSupported} and non-stop mode above
40114apply.
0d71eef5
DB
40115
40116@cindex fork events, remote reply
40117@item fork
40118The packet indicates that @code{fork} was called, and @var{r}
40119is the thread ID of the new child process. Refer to
40120@ref{thread-id syntax} for the format of the @var{thread-id}
40121field. This packet is only applicable to targets that support
40122fork events.
40123
40124This packet should not be sent by default; older @value{GDBN} versions
40125did not support it. @value{GDBN} requests it, by supplying an
40126appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40127remote stub must also supply the appropriate @samp{qSupported} feature
40128indicating support.
40129
40130@cindex vfork events, remote reply
40131@item vfork
40132The packet indicates that @code{vfork} was called, and @var{r}
40133is the thread ID of the new child process. Refer to
40134@ref{thread-id syntax} for the format of the @var{thread-id}
40135field. This packet is only applicable to targets that support
40136vfork events.
40137
40138This packet should not be sent by default; older @value{GDBN} versions
40139did not support it. @value{GDBN} requests it, by supplying an
40140appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40141remote stub must also supply the appropriate @samp{qSupported} feature
40142indicating support.
40143
40144@cindex vforkdone events, remote reply
40145@item vforkdone
e68fa6f0
PA
40146The packet indicates that a child process created by a vfork
40147has either called @code{exec} or terminated, so that the
40148address spaces of the parent and child process are no longer
40149shared. The @var{r} part is ignored. This packet is only
40150applicable to targets that support vforkdone events.
0d71eef5
DB
40151
40152This packet should not be sent by default; older @value{GDBN} versions
40153did not support it. @value{GDBN} requests it, by supplying an
40154appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40155remote stub must also supply the appropriate @samp{qSupported} feature
40156indicating support.
40157
b459a59b
DB
40158@cindex exec events, remote reply
40159@item exec
40160The packet indicates that @code{execve} was called, and @var{r}
40161is the absolute pathname of the file that was executed, in hex.
40162This packet is only applicable to targets that support exec events.
40163
40164This packet should not be sent by default; older @value{GDBN} versions
40165did not support it. @value{GDBN} requests it, by supplying an
40166appropriate @samp{qSupported} feature (@pxref{qSupported}). The
40167remote stub must also supply the appropriate @samp{qSupported} feature
40168indicating support.
40169
65706a29
PA
40170@cindex thread create event, remote reply
40171@anchor{thread create event}
40172@item create
40173The packet indicates that the thread was just created. The new thread
40174is stopped until @value{GDBN} sets it running with a resumption packet
40175(@pxref{vCont packet}). This packet should not be sent by default;
40176@value{GDBN} requests it with the @ref{QThreadEvents} packet. See
4435e1cc
TT
40177also the @samp{w} (@pxref{thread exit event}) remote reply below. The
40178@var{r} part is ignored.
65706a29 40179
cfa9d6d9 40180@end table
ee2d5c50 40181
b8ff78ce 40182@item W @var{AA}
b90a069a 40183@itemx W @var{AA} ; process:@var{pid}
8e04817f 40184The process exited, and @var{AA} is the exit status. This is only
ee2d5c50
AC
40185applicable to certain targets.
40186
4435e1cc
TT
40187The second form of the response, including the process ID of the
40188exited process, can be used only when @value{GDBN} has reported
40189support for multiprocess protocol extensions; see @ref{multiprocess
40190extensions}. Both @var{AA} and @var{pid} are formatted as big-endian
40191hex strings.
b90a069a 40192
b8ff78ce 40193@item X @var{AA}
b90a069a 40194@itemx X @var{AA} ; process:@var{pid}
8e04817f 40195The process terminated with signal @var{AA}.
c906108c 40196
b90a069a
SL
40197The second form of the response, including the process ID of the
40198terminated process, can be used only when @value{GDBN} has reported
40199support for multiprocess protocol extensions; see @ref{multiprocess
4435e1cc
TT
40200extensions}. Both @var{AA} and @var{pid} are formatted as big-endian
40201hex strings.
b90a069a 40202
65706a29
PA
40203@anchor{thread exit event}
40204@cindex thread exit event, remote reply
40205@item w @var{AA} ; @var{tid}
40206
40207The thread exited, and @var{AA} is the exit status. This response
40208should not be sent by default; @value{GDBN} requests it with the
40209@ref{QThreadEvents} packet. See also @ref{thread create event} above.
4435e1cc 40210@var{AA} is formatted as a big-endian hex string.
65706a29 40211
f2faf941
PA
40212@item N
40213There are no resumed threads left in the target. In other words, even
40214though the process is alive, the last resumed thread has exited. For
40215example, say the target process has two threads: thread 1 and thread
402162. The client leaves thread 1 stopped, and resumes thread 2, which
40217subsequently exits. At this point, even though the process is still
40218alive, and thus no @samp{W} stop reply is sent, no thread is actually
40219executing either. The @samp{N} stop reply thus informs the client
40220that it can stop waiting for stop replies. This packet should not be
40221sent by default; older @value{GDBN} versions did not support it.
40222@value{GDBN} requests it, by supplying an appropriate
40223@samp{qSupported} feature (@pxref{qSupported}). The remote stub must
40224also supply the appropriate @samp{qSupported} feature indicating
40225support.
40226
b8ff78ce
JB
40227@item O @var{XX}@dots{}
40228@samp{@var{XX}@dots{}} is hex encoding of @sc{ascii} data, to be
40229written as the program's console output. This can happen at any time
40230while the program is running and the debugger should continue to wait
8b23ecc4 40231for @samp{W}, @samp{T}, etc. This reply is not permitted in non-stop mode.
0ce1b118 40232
b8ff78ce 40233@item F @var{call-id},@var{parameter}@dots{}
0ce1b118
CV
40234@var{call-id} is the identifier which says which host system call should
40235be called. This is just the name of the function. Translation into the
40236correct system call is only applicable as it's defined in @value{GDBN}.
79a6e687 40237@xref{File-I/O Remote Protocol Extension}, for a list of implemented
0ce1b118
CV
40238system calls.
40239
b8ff78ce
JB
40240@samp{@var{parameter}@dots{}} is a list of parameters as defined for
40241this very system call.
0ce1b118 40242
b8ff78ce
JB
40243The target replies with this packet when it expects @value{GDBN} to
40244call a host system call on behalf of the target. @value{GDBN} replies
40245with an appropriate @samp{F} packet and keeps up waiting for the next
40246reply packet from the target. The latest @samp{C}, @samp{c}, @samp{S}
79a6e687
BW
40247or @samp{s} action is expected to be continued. @xref{File-I/O Remote
40248Protocol Extension}, for more details.
0ce1b118 40249
ee2d5c50
AC
40250@end table
40251
40252@node General Query Packets
40253@section General Query Packets
9c16f35a 40254@cindex remote query requests
c906108c 40255
5f3bebba
JB
40256Packets starting with @samp{q} are @dfn{general query packets};
40257packets starting with @samp{Q} are @dfn{general set packets}. General
40258query and set packets are a semi-unified form for retrieving and
40259sending information to and from the stub.
40260
40261The initial letter of a query or set packet is followed by a name
40262indicating what sort of thing the packet applies to. For example,
40263@value{GDBN} may use a @samp{qSymbol} packet to exchange symbol
40264definitions with the stub. These packet names follow some
40265conventions:
40266
40267@itemize @bullet
40268@item
40269The name must not contain commas, colons or semicolons.
40270@item
40271Most @value{GDBN} query and set packets have a leading upper case
40272letter.
40273@item
40274The names of custom vendor packets should use a company prefix, in
40275lower case, followed by a period. For example, packets designed at
40276the Acme Corporation might begin with @samp{qacme.foo} (for querying
40277foos) or @samp{Qacme.bar} (for setting bars).
40278@end itemize
40279
aa56d27a
JB
40280The name of a query or set packet should be separated from any
40281parameters by a @samp{:}; the parameters themselves should be
40282separated by @samp{,} or @samp{;}. Stubs must be careful to match the
369af7bd
DJ
40283full packet name, and check for a separator or the end of the packet,
40284in case two packet names share a common prefix. New packets should not begin
40285with @samp{qC}, @samp{qP}, or @samp{qL}@footnote{The @samp{qP} and @samp{qL}
40286packets predate these conventions, and have arguments without any terminator
40287for the packet name; we suspect they are in widespread use in places that
40288are difficult to upgrade. The @samp{qC} packet has no arguments, but some
40289existing stubs (e.g.@: RedBoot) are known to not check for the end of the
40290packet.}.
c906108c 40291
b8ff78ce
JB
40292Like the descriptions of the other packets, each description here
40293has a template showing the packet's overall syntax, followed by an
40294explanation of the packet's meaning. We include spaces in some of the
40295templates for clarity; these are not part of the packet's syntax. No
40296@value{GDBN} packet uses spaces to separate its components.
40297
5f3bebba
JB
40298Here are the currently defined query and set packets:
40299
b8ff78ce 40300@table @samp
c906108c 40301
d1feda86 40302@item QAgent:1
af4238e5 40303@itemx QAgent:0
d1feda86
YQ
40304Turn on or off the agent as a helper to perform some debugging operations
40305delegated from @value{GDBN} (@pxref{Control Agent}).
40306
d914c394
SS
40307@item QAllow:@var{op}:@var{val}@dots{}
40308@cindex @samp{QAllow} packet
40309Specify which operations @value{GDBN} expects to request of the
40310target, as a semicolon-separated list of operation name and value
40311pairs. Possible values for @var{op} include @samp{WriteReg},
40312@samp{WriteMem}, @samp{InsertBreak}, @samp{InsertTrace},
40313@samp{InsertFastTrace}, and @samp{Stop}. @var{val} is either 0,
40314indicating that @value{GDBN} will not request the operation, or 1,
40315indicating that it may. (The target can then use this to set up its
40316own internals optimally, for instance if the debugger never expects to
40317insert breakpoints, it may not need to install its own trap handler.)
40318
b8ff78ce 40319@item qC
9c16f35a 40320@cindex current thread, remote request
b8ff78ce 40321@cindex @samp{qC} packet
b90a069a 40322Return the current thread ID.
ee2d5c50
AC
40323
40324Reply:
40325@table @samp
b90a069a
SL
40326@item QC @var{thread-id}
40327Where @var{thread-id} is a thread ID as documented in
40328@ref{thread-id syntax}.
b8ff78ce 40329@item @r{(anything else)}
b90a069a 40330Any other reply implies the old thread ID.
ee2d5c50
AC
40331@end table
40332
b8ff78ce 40333@item qCRC:@var{addr},@var{length}
ff2587ec 40334@cindex CRC of memory block, remote request
b8ff78ce 40335@cindex @samp{qCRC} packet
936d2992 40336@anchor{qCRC packet}
99e008fe
EZ
40337Compute the CRC checksum of a block of memory using CRC-32 defined in
40338IEEE 802.3. The CRC is computed byte at a time, taking the most
40339significant bit of each byte first. The initial pattern code
40340@code{0xffffffff} is used to ensure leading zeros affect the CRC.
40341
40342@emph{Note:} This is the same CRC used in validating separate debug
40343files (@pxref{Separate Debug Files, , Debugging Information in Separate
40344Files}). However the algorithm is slightly different. When validating
40345separate debug files, the CRC is computed taking the @emph{least}
40346significant bit of each byte first, and the final result is inverted to
40347detect trailing zeros.
40348
ff2587ec
WZ
40349Reply:
40350@table @samp
b8ff78ce 40351@item E @var{NN}
ff2587ec 40352An error (such as memory fault)
b8ff78ce
JB
40353@item C @var{crc32}
40354The specified memory region's checksum is @var{crc32}.
ff2587ec
WZ
40355@end table
40356
03583c20
UW
40357@item QDisableRandomization:@var{value}
40358@cindex disable address space randomization, remote request
40359@cindex @samp{QDisableRandomization} packet
40360Some target operating systems will randomize the virtual address space
40361of the inferior process as a security feature, but provide a feature
40362to disable such randomization, e.g.@: to allow for a more deterministic
40363debugging experience. On such systems, this packet with a @var{value}
40364of 1 directs the target to disable address space randomization for
40365processes subsequently started via @samp{vRun} packets, while a packet
40366with a @var{value} of 0 tells the target to enable address space
40367randomization.
40368
40369This packet is only available in extended mode (@pxref{extended mode}).
40370
40371Reply:
40372@table @samp
40373@item OK
40374The request succeeded.
40375
40376@item E @var{nn}
697aa1b7 40377An error occurred. The error number @var{nn} is given as hex digits.
03583c20 40378
d57350ea 40379@item @w{}
03583c20
UW
40380An empty reply indicates that @samp{QDisableRandomization} is not supported
40381by the stub.
40382@end table
40383
40384This packet is not probed by default; the remote stub must request it,
40385by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40386This should only be done on targets that actually support disabling
40387address space randomization.
40388
aefd8b33
SDJ
40389@item QStartupWithShell:@var{value}
40390@cindex startup with shell, remote request
40391@cindex @samp{QStartupWithShell} packet
40392On UNIX-like targets, it is possible to start the inferior using a
40393shell program. This is the default behavior on both @value{GDBN} and
40394@command{gdbserver} (@pxref{set startup-with-shell}). This packet is
40395used to inform @command{gdbserver} whether it should start the
40396inferior using a shell or not.
40397
40398If @var{value} is @samp{0}, @command{gdbserver} will not use a shell
40399to start the inferior. If @var{value} is @samp{1},
40400@command{gdbserver} will use a shell to start the inferior. All other
40401values are considered an error.
40402
40403This packet is only available in extended mode (@pxref{extended
40404mode}).
40405
40406Reply:
40407@table @samp
40408@item OK
40409The request succeeded.
40410
40411@item E @var{nn}
40412An error occurred. The error number @var{nn} is given as hex digits.
40413@end table
40414
40415This packet is not probed by default; the remote stub must request it,
40416by supplying an appropriate @samp{qSupported} response
40417(@pxref{qSupported}). This should only be done on targets that
40418actually support starting the inferior using a shell.
40419
40420Use of this packet is controlled by the @code{set startup-with-shell}
40421command; @pxref{set startup-with-shell}.
40422
0a2dde4a
SDJ
40423@item QEnvironmentHexEncoded:@var{hex-value}
40424@anchor{QEnvironmentHexEncoded}
40425@cindex set environment variable, remote request
40426@cindex @samp{QEnvironmentHexEncoded} packet
40427On UNIX-like targets, it is possible to set environment variables that
40428will be passed to the inferior during the startup process. This
40429packet is used to inform @command{gdbserver} of an environment
40430variable that has been defined by the user on @value{GDBN} (@pxref{set
40431environment}).
40432
40433The packet is composed by @var{hex-value}, an hex encoded
40434representation of the @var{name=value} format representing an
40435environment variable. The name of the environment variable is
40436represented by @var{name}, and the value to be assigned to the
40437environment variable is represented by @var{value}. If the variable
40438has no value (i.e., the value is @code{null}), then @var{value} will
40439not be present.
40440
40441This packet is only available in extended mode (@pxref{extended
40442mode}).
40443
40444Reply:
40445@table @samp
40446@item OK
40447The request succeeded.
40448@end table
40449
40450This packet is not probed by default; the remote stub must request it,
40451by supplying an appropriate @samp{qSupported} response
40452(@pxref{qSupported}). This should only be done on targets that
40453actually support passing environment variables to the starting
40454inferior.
40455
40456This packet is related to the @code{set environment} command;
40457@pxref{set environment}.
40458
40459@item QEnvironmentUnset:@var{hex-value}
40460@anchor{QEnvironmentUnset}
40461@cindex unset environment variable, remote request
40462@cindex @samp{QEnvironmentUnset} packet
40463On UNIX-like targets, it is possible to unset environment variables
40464before starting the inferior in the remote target. This packet is
40465used to inform @command{gdbserver} of an environment variable that has
40466been unset by the user on @value{GDBN} (@pxref{unset environment}).
40467
40468The packet is composed by @var{hex-value}, an hex encoded
40469representation of the name of the environment variable to be unset.
40470
40471This packet is only available in extended mode (@pxref{extended
40472mode}).
40473
40474Reply:
40475@table @samp
40476@item OK
40477The request succeeded.
40478@end table
40479
40480This packet is not probed by default; the remote stub must request it,
40481by supplying an appropriate @samp{qSupported} response
40482(@pxref{qSupported}). This should only be done on targets that
40483actually support passing environment variables to the starting
40484inferior.
40485
40486This packet is related to the @code{unset environment} command;
40487@pxref{unset environment}.
40488
40489@item QEnvironmentReset
40490@anchor{QEnvironmentReset}
40491@cindex reset environment, remote request
40492@cindex @samp{QEnvironmentReset} packet
40493On UNIX-like targets, this packet is used to reset the state of
40494environment variables in the remote target before starting the
40495inferior. In this context, reset means unsetting all environment
40496variables that were previously set by the user (i.e., were not
40497initially present in the environment). It is sent to
40498@command{gdbserver} before the @samp{QEnvironmentHexEncoded}
40499(@pxref{QEnvironmentHexEncoded}) and the @samp{QEnvironmentUnset}
40500(@pxref{QEnvironmentUnset}) packets.
40501
40502This packet is only available in extended mode (@pxref{extended
40503mode}).
40504
40505Reply:
40506@table @samp
40507@item OK
40508The request succeeded.
40509@end table
40510
40511This packet is not probed by default; the remote stub must request it,
40512by supplying an appropriate @samp{qSupported} response
40513(@pxref{qSupported}). This should only be done on targets that
40514actually support passing environment variables to the starting
40515inferior.
40516
bc3b087d
SDJ
40517@item QSetWorkingDir:@r{[}@var{directory}@r{]}
40518@anchor{QSetWorkingDir packet}
40519@cindex set working directory, remote request
40520@cindex @samp{QSetWorkingDir} packet
40521This packet is used to inform the remote server of the intended
40522current working directory for programs that are going to be executed.
40523
40524The packet is composed by @var{directory}, an hex encoded
40525representation of the directory that the remote inferior will use as
40526its current working directory. If @var{directory} is an empty string,
40527the remote server should reset the inferior's current working
40528directory to its original, empty value.
40529
40530This packet is only available in extended mode (@pxref{extended
40531mode}).
40532
40533Reply:
40534@table @samp
40535@item OK
40536The request succeeded.
40537@end table
40538
b8ff78ce
JB
40539@item qfThreadInfo
40540@itemx qsThreadInfo
9c16f35a 40541@cindex list active threads, remote request
b8ff78ce
JB
40542@cindex @samp{qfThreadInfo} packet
40543@cindex @samp{qsThreadInfo} packet
b90a069a 40544Obtain a list of all active thread IDs from the target (OS). Since there
8e04817f
AC
40545may be too many active threads to fit into one reply packet, this query
40546works iteratively: it may require more than one query/reply sequence to
40547obtain the entire list of threads. The first query of the sequence will
b8ff78ce
JB
40548be the @samp{qfThreadInfo} query; subsequent queries in the
40549sequence will be the @samp{qsThreadInfo} query.
ee2d5c50 40550
b8ff78ce 40551NOTE: This packet replaces the @samp{qL} query (see below).
ee2d5c50
AC
40552
40553Reply:
40554@table @samp
b90a069a
SL
40555@item m @var{thread-id}
40556A single thread ID
40557@item m @var{thread-id},@var{thread-id}@dots{}
40558a comma-separated list of thread IDs
b8ff78ce
JB
40559@item l
40560(lower case letter @samp{L}) denotes end of list.
ee2d5c50
AC
40561@end table
40562
40563In response to each query, the target will reply with a list of one or
b90a069a 40564more thread IDs, separated by commas.
e1aac25b 40565@value{GDBN} will respond to each reply with a request for more thread
b8ff78ce 40566ids (using the @samp{qs} form of the query), until the target responds
501994c0 40567with @samp{l} (lower-case ell, for @dfn{last}).
b90a069a
SL
40568Refer to @ref{thread-id syntax}, for the format of the @var{thread-id}
40569fields.
c906108c 40570
8dfcab11
DT
40571@emph{Note: @value{GDBN} will send the @code{qfThreadInfo} query during the
40572initial connection with the remote target, and the very first thread ID
40573mentioned in the reply will be stopped by @value{GDBN} in a subsequent
40574message. Therefore, the stub should ensure that the first thread ID in
40575the @code{qfThreadInfo} reply is suitable for being stopped by @value{GDBN}.}
40576
b8ff78ce 40577@item qGetTLSAddr:@var{thread-id},@var{offset},@var{lm}
ff2587ec 40578@cindex get thread-local storage address, remote request
b8ff78ce 40579@cindex @samp{qGetTLSAddr} packet
ff2587ec
WZ
40580Fetch the address associated with thread local storage specified
40581by @var{thread-id}, @var{offset}, and @var{lm}.
40582
b90a069a
SL
40583@var{thread-id} is the thread ID associated with the
40584thread for which to fetch the TLS address. @xref{thread-id syntax}.
ff2587ec
WZ
40585
40586@var{offset} is the (big endian, hex encoded) offset associated with the
40587thread local variable. (This offset is obtained from the debug
40588information associated with the variable.)
40589
db2e3e2e 40590@var{lm} is the (big endian, hex encoded) OS/ABI-specific encoding of the
7a9dd1b2 40591load module associated with the thread local storage. For example,
ff2587ec
WZ
40592a @sc{gnu}/Linux system will pass the link map address of the shared
40593object associated with the thread local storage under consideration.
40594Other operating environments may choose to represent the load module
40595differently, so the precise meaning of this parameter will vary.
ee2d5c50
AC
40596
40597Reply:
b8ff78ce
JB
40598@table @samp
40599@item @var{XX}@dots{}
ff2587ec
WZ
40600Hex encoded (big endian) bytes representing the address of the thread
40601local storage requested.
40602
b8ff78ce 40603@item E @var{nn}
697aa1b7 40604An error occurred. The error number @var{nn} is given as hex digits.
ff2587ec 40605
d57350ea 40606@item @w{}
b8ff78ce 40607An empty reply indicates that @samp{qGetTLSAddr} is not supported by the stub.
ee2d5c50
AC
40608@end table
40609
711e434b
PM
40610@item qGetTIBAddr:@var{thread-id}
40611@cindex get thread information block address
40612@cindex @samp{qGetTIBAddr} packet
40613Fetch address of the Windows OS specific Thread Information Block.
40614
40615@var{thread-id} is the thread ID associated with the thread.
40616
40617Reply:
40618@table @samp
40619@item @var{XX}@dots{}
40620Hex encoded (big endian) bytes representing the linear address of the
40621thread information block.
40622
40623@item E @var{nn}
40624An error occured. This means that either the thread was not found, or the
40625address could not be retrieved.
40626
d57350ea 40627@item @w{}
711e434b
PM
40628An empty reply indicates that @samp{qGetTIBAddr} is not supported by the stub.
40629@end table
40630
b8ff78ce 40631@item qL @var{startflag} @var{threadcount} @var{nextthread}
8e04817f
AC
40632Obtain thread information from RTOS. Where: @var{startflag} (one hex
40633digit) is one to indicate the first query and zero to indicate a
40634subsequent query; @var{threadcount} (two hex digits) is the maximum
40635number of threads the response packet can contain; and @var{nextthread}
40636(eight hex digits), for subsequent queries (@var{startflag} is zero), is
40637returned in the response as @var{argthread}.
ee2d5c50 40638
b8ff78ce 40639Don't use this packet; use the @samp{qfThreadInfo} query instead (see above).
ee2d5c50
AC
40640
40641Reply:
40642@table @samp
b8ff78ce 40643@item qM @var{count} @var{done} @var{argthread} @var{thread}@dots{}
8e04817f
AC
40644Where: @var{count} (two hex digits) is the number of threads being
40645returned; @var{done} (one hex digit) is zero to indicate more threads
40646and one indicates no further threads; @var{argthreadid} (eight hex
b8ff78ce 40647digits) is @var{nextthread} from the request packet; @var{thread}@dots{}
697aa1b7
EZ
40648is a sequence of thread IDs, @var{threadid} (eight hex
40649digits), from the target. See @code{remote.c:parse_threadlist_response()}.
ee2d5c50 40650@end table
c906108c 40651
b8ff78ce 40652@item qOffsets
9c16f35a 40653@cindex section offsets, remote request
b8ff78ce 40654@cindex @samp{qOffsets} packet
31d99776
DJ
40655Get section offsets that the target used when relocating the downloaded
40656image.
c906108c 40657
ee2d5c50
AC
40658Reply:
40659@table @samp
31d99776
DJ
40660@item Text=@var{xxx};Data=@var{yyy}@r{[};Bss=@var{zzz}@r{]}
40661Relocate the @code{Text} section by @var{xxx} from its original address.
40662Relocate the @code{Data} section by @var{yyy} from its original address.
40663If the object file format provides segment information (e.g.@: @sc{elf}
40664@samp{PT_LOAD} program headers), @value{GDBN} will relocate entire
40665segments by the supplied offsets.
40666
40667@emph{Note: while a @code{Bss} offset may be included in the response,
40668@value{GDBN} ignores this and instead applies the @code{Data} offset
40669to the @code{Bss} section.}
40670
40671@item TextSeg=@var{xxx}@r{[};DataSeg=@var{yyy}@r{]}
40672Relocate the first segment of the object file, which conventionally
40673contains program code, to a starting address of @var{xxx}. If
40674@samp{DataSeg} is specified, relocate the second segment, which
40675conventionally contains modifiable data, to a starting address of
40676@var{yyy}. @value{GDBN} will report an error if the object file
40677does not contain segment information, or does not contain at least
40678as many segments as mentioned in the reply. Extra segments are
40679kept at fixed offsets relative to the last relocated segment.
ee2d5c50
AC
40680@end table
40681
b90a069a 40682@item qP @var{mode} @var{thread-id}
9c16f35a 40683@cindex thread information, remote request
b8ff78ce 40684@cindex @samp{qP} packet
b90a069a
SL
40685Returns information on @var{thread-id}. Where: @var{mode} is a hex
40686encoded 32 bit mode; @var{thread-id} is a thread ID
40687(@pxref{thread-id syntax}).
ee2d5c50 40688
aa56d27a
JB
40689Don't use this packet; use the @samp{qThreadExtraInfo} query instead
40690(see below).
40691
b8ff78ce 40692Reply: see @code{remote.c:remote_unpack_thread_info_response()}.
c906108c 40693
8b23ecc4 40694@item QNonStop:1
687e43a4 40695@itemx QNonStop:0
8b23ecc4
SL
40696@cindex non-stop mode, remote request
40697@cindex @samp{QNonStop} packet
40698@anchor{QNonStop}
40699Enter non-stop (@samp{QNonStop:1}) or all-stop (@samp{QNonStop:0}) mode.
40700@xref{Remote Non-Stop}, for more information.
40701
40702Reply:
40703@table @samp
40704@item OK
40705The request succeeded.
40706
40707@item E @var{nn}
697aa1b7 40708An error occurred. The error number @var{nn} is given as hex digits.
8b23ecc4 40709
d57350ea 40710@item @w{}
8b23ecc4
SL
40711An empty reply indicates that @samp{QNonStop} is not supported by
40712the stub.
40713@end table
40714
40715This packet is not probed by default; the remote stub must request it,
40716by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40717Use of this packet is controlled by the @code{set non-stop} command;
40718@pxref{Non-Stop Mode}.
40719
82075af2
JS
40720@item QCatchSyscalls:1 @r{[};@var{sysno}@r{]}@dots{}
40721@itemx QCatchSyscalls:0
40722@cindex catch syscalls from inferior, remote request
40723@cindex @samp{QCatchSyscalls} packet
40724@anchor{QCatchSyscalls}
40725Enable (@samp{QCatchSyscalls:1}) or disable (@samp{QCatchSyscalls:0})
40726catching syscalls from the inferior process.
40727
40728For @samp{QCatchSyscalls:1}, each listed syscall @var{sysno} (encoded
40729in hex) should be reported to @value{GDBN}. If no syscall @var{sysno}
40730is listed, every system call should be reported.
40731
40732Note that if a syscall not in the list is reported, @value{GDBN} will
40733still filter the event according to its own list from all corresponding
40734@code{catch syscall} commands. However, it is more efficient to only
40735report the requested syscalls.
40736
40737Multiple @samp{QCatchSyscalls:1} packets do not combine; any earlier
40738@samp{QCatchSyscalls:1} list is completely replaced by the new list.
40739
40740If the inferior process execs, the state of @samp{QCatchSyscalls} is
40741kept for the new process too. On targets where exec may affect syscall
40742numbers, for example with exec between 32 and 64-bit processes, the
40743client should send a new packet with the new syscall list.
40744
40745Reply:
40746@table @samp
40747@item OK
40748The request succeeded.
40749
40750@item E @var{nn}
40751An error occurred. @var{nn} are hex digits.
40752
40753@item @w{}
40754An empty reply indicates that @samp{QCatchSyscalls} is not supported by
40755the stub.
40756@end table
40757
40758Use of this packet is controlled by the @code{set remote catch-syscalls}
40759command (@pxref{Remote Configuration, set remote catch-syscalls}).
40760This packet is not probed by default; the remote stub must request it,
40761by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40762
89be2091
DJ
40763@item QPassSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
40764@cindex pass signals to inferior, remote request
40765@cindex @samp{QPassSignals} packet
23181151 40766@anchor{QPassSignals}
89be2091
DJ
40767Each listed @var{signal} should be passed directly to the inferior process.
40768Signals are numbered identically to continue packets and stop replies
40769(@pxref{Stop Reply Packets}). Each @var{signal} list item should be
40770strictly greater than the previous item. These signals do not need to stop
40771the inferior, or be reported to @value{GDBN}. All other signals should be
40772reported to @value{GDBN}. Multiple @samp{QPassSignals} packets do not
40773combine; any earlier @samp{QPassSignals} list is completely replaced by the
40774new list. This packet improves performance when using @samp{handle
40775@var{signal} nostop noprint pass}.
40776
40777Reply:
40778@table @samp
40779@item OK
40780The request succeeded.
40781
40782@item E @var{nn}
697aa1b7 40783An error occurred. The error number @var{nn} is given as hex digits.
89be2091 40784
d57350ea 40785@item @w{}
89be2091
DJ
40786An empty reply indicates that @samp{QPassSignals} is not supported by
40787the stub.
40788@end table
40789
40790Use of this packet is controlled by the @code{set remote pass-signals}
79a6e687 40791command (@pxref{Remote Configuration, set remote pass-signals}).
89be2091
DJ
40792This packet is not probed by default; the remote stub must request it,
40793by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40794
9b224c5e
PA
40795@item QProgramSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
40796@cindex signals the inferior may see, remote request
40797@cindex @samp{QProgramSignals} packet
40798@anchor{QProgramSignals}
40799Each listed @var{signal} may be delivered to the inferior process.
40800Others should be silently discarded.
40801
40802In some cases, the remote stub may need to decide whether to deliver a
40803signal to the program or not without @value{GDBN} involvement. One
40804example of that is while detaching --- the program's threads may have
40805stopped for signals that haven't yet had a chance of being reported to
40806@value{GDBN}, and so the remote stub can use the signal list specified
40807by this packet to know whether to deliver or ignore those pending
40808signals.
40809
40810This does not influence whether to deliver a signal as requested by a
40811resumption packet (@pxref{vCont packet}).
40812
40813Signals are numbered identically to continue packets and stop replies
40814(@pxref{Stop Reply Packets}). Each @var{signal} list item should be
40815strictly greater than the previous item. Multiple
40816@samp{QProgramSignals} packets do not combine; any earlier
40817@samp{QProgramSignals} list is completely replaced by the new list.
40818
40819Reply:
40820@table @samp
40821@item OK
40822The request succeeded.
40823
40824@item E @var{nn}
697aa1b7 40825An error occurred. The error number @var{nn} is given as hex digits.
9b224c5e 40826
d57350ea 40827@item @w{}
9b224c5e
PA
40828An empty reply indicates that @samp{QProgramSignals} is not supported
40829by the stub.
40830@end table
40831
40832Use of this packet is controlled by the @code{set remote program-signals}
40833command (@pxref{Remote Configuration, set remote program-signals}).
40834This packet is not probed by default; the remote stub must request it,
40835by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40836
65706a29
PA
40837@anchor{QThreadEvents}
40838@item QThreadEvents:1
40839@itemx QThreadEvents:0
40840@cindex thread create/exit events, remote request
40841@cindex @samp{QThreadEvents} packet
40842
40843Enable (@samp{QThreadEvents:1}) or disable (@samp{QThreadEvents:0})
40844reporting of thread create and exit events. @xref{thread create
40845event}, for the reply specifications. For example, this is used in
40846non-stop mode when @value{GDBN} stops a set of threads and
40847synchronously waits for the their corresponding stop replies. Without
40848exit events, if one of the threads exits, @value{GDBN} would hang
40849forever not knowing that it should no longer expect a stop for that
40850same thread. @value{GDBN} does not enable this feature unless the
40851stub reports that it supports it by including @samp{QThreadEvents+} in
40852its @samp{qSupported} reply.
40853
40854Reply:
40855@table @samp
40856@item OK
40857The request succeeded.
40858
40859@item E @var{nn}
40860An error occurred. The error number @var{nn} is given as hex digits.
40861
40862@item @w{}
40863An empty reply indicates that @samp{QThreadEvents} is not supported by
40864the stub.
40865@end table
40866
40867Use of this packet is controlled by the @code{set remote thread-events}
40868command (@pxref{Remote Configuration, set remote thread-events}).
40869
b8ff78ce 40870@item qRcmd,@var{command}
ff2587ec 40871@cindex execute remote command, remote request
b8ff78ce 40872@cindex @samp{qRcmd} packet
ff2587ec 40873@var{command} (hex encoded) is passed to the local interpreter for
b8ff78ce
JB
40874execution. Invalid commands should be reported using the output
40875string. Before the final result packet, the target may also respond
40876with a number of intermediate @samp{O@var{output}} console output
40877packets. @emph{Implementors should note that providing access to a
40878stubs's interpreter may have security implications}.
fa93a9d8 40879
ff2587ec
WZ
40880Reply:
40881@table @samp
40882@item OK
40883A command response with no output.
40884@item @var{OUTPUT}
40885A command response with the hex encoded output string @var{OUTPUT}.
b8ff78ce 40886@item E @var{NN}
ff2587ec 40887Indicate a badly formed request.
d57350ea 40888@item @w{}
b8ff78ce 40889An empty reply indicates that @samp{qRcmd} is not recognized.
ff2587ec 40890@end table
fa93a9d8 40891
aa56d27a
JB
40892(Note that the @code{qRcmd} packet's name is separated from the
40893command by a @samp{,}, not a @samp{:}, contrary to the naming
40894conventions above. Please don't use this packet as a model for new
40895packets.)
40896
08388c79
DE
40897@item qSearch:memory:@var{address};@var{length};@var{search-pattern}
40898@cindex searching memory, in remote debugging
5c4808ca 40899@ifnotinfo
08388c79 40900@cindex @samp{qSearch:memory} packet
5c4808ca
EZ
40901@end ifnotinfo
40902@cindex @samp{qSearch memory} packet
08388c79
DE
40903@anchor{qSearch memory}
40904Search @var{length} bytes at @var{address} for @var{search-pattern}.
697aa1b7
EZ
40905Both @var{address} and @var{length} are encoded in hex;
40906@var{search-pattern} is a sequence of bytes, also hex encoded.
08388c79
DE
40907
40908Reply:
40909@table @samp
40910@item 0
40911The pattern was not found.
40912@item 1,address
40913The pattern was found at @var{address}.
40914@item E @var{NN}
40915A badly formed request or an error was encountered while searching memory.
d57350ea 40916@item @w{}
08388c79
DE
40917An empty reply indicates that @samp{qSearch:memory} is not recognized.
40918@end table
40919
a6f3e723
SL
40920@item QStartNoAckMode
40921@cindex @samp{QStartNoAckMode} packet
40922@anchor{QStartNoAckMode}
40923Request that the remote stub disable the normal @samp{+}/@samp{-}
40924protocol acknowledgments (@pxref{Packet Acknowledgment}).
40925
40926Reply:
40927@table @samp
40928@item OK
40929The stub has switched to no-acknowledgment mode.
6b92c0d3 40930@value{GDBN} acknowledges this response,
a6f3e723
SL
40931but neither the stub nor @value{GDBN} shall send or expect further
40932@samp{+}/@samp{-} acknowledgments in the current connection.
d57350ea 40933@item @w{}
a6f3e723
SL
40934An empty reply indicates that the stub does not support no-acknowledgment mode.
40935@end table
40936
be2a5f71
DJ
40937@item qSupported @r{[}:@var{gdbfeature} @r{[};@var{gdbfeature}@r{]}@dots{} @r{]}
40938@cindex supported packets, remote query
40939@cindex features of the remote protocol
40940@cindex @samp{qSupported} packet
0876f84a 40941@anchor{qSupported}
be2a5f71
DJ
40942Tell the remote stub about features supported by @value{GDBN}, and
40943query the stub for features it supports. This packet allows
40944@value{GDBN} and the remote stub to take advantage of each others'
40945features. @samp{qSupported} also consolidates multiple feature probes
40946at startup, to improve @value{GDBN} performance---a single larger
40947packet performs better than multiple smaller probe packets on
40948high-latency links. Some features may enable behavior which must not
40949be on by default, e.g.@: because it would confuse older clients or
40950stubs. Other features may describe packets which could be
40951automatically probed for, but are not. These features must be
40952reported before @value{GDBN} will use them. This ``default
40953unsupported'' behavior is not appropriate for all packets, but it
40954helps to keep the initial connection time under control with new
40955versions of @value{GDBN} which support increasing numbers of packets.
40956
40957Reply:
40958@table @samp
40959@item @var{stubfeature} @r{[};@var{stubfeature}@r{]}@dots{}
40960The stub supports or does not support each returned @var{stubfeature},
40961depending on the form of each @var{stubfeature} (see below for the
40962possible forms).
d57350ea 40963@item @w{}
be2a5f71
DJ
40964An empty reply indicates that @samp{qSupported} is not recognized,
40965or that no features needed to be reported to @value{GDBN}.
40966@end table
40967
40968The allowed forms for each feature (either a @var{gdbfeature} in the
40969@samp{qSupported} packet, or a @var{stubfeature} in the response)
40970are:
40971
40972@table @samp
40973@item @var{name}=@var{value}
40974The remote protocol feature @var{name} is supported, and associated
40975with the specified @var{value}. The format of @var{value} depends
40976on the feature, but it must not include a semicolon.
40977@item @var{name}+
40978The remote protocol feature @var{name} is supported, and does not
40979need an associated value.
40980@item @var{name}-
40981The remote protocol feature @var{name} is not supported.
40982@item @var{name}?
40983The remote protocol feature @var{name} may be supported, and
40984@value{GDBN} should auto-detect support in some other way when it is
40985needed. This form will not be used for @var{gdbfeature} notifications,
40986but may be used for @var{stubfeature} responses.
40987@end table
40988
40989Whenever the stub receives a @samp{qSupported} request, the
40990supplied set of @value{GDBN} features should override any previous
40991request. This allows @value{GDBN} to put the stub in a known
40992state, even if the stub had previously been communicating with
40993a different version of @value{GDBN}.
40994
b90a069a
SL
40995The following values of @var{gdbfeature} (for the packet sent by @value{GDBN})
40996are defined:
40997
40998@table @samp
40999@item multiprocess
41000This feature indicates whether @value{GDBN} supports multiprocess
41001extensions to the remote protocol. @value{GDBN} does not use such
41002extensions unless the stub also reports that it supports them by
41003including @samp{multiprocess+} in its @samp{qSupported} reply.
41004@xref{multiprocess extensions}, for details.
c8d5aac9
L
41005
41006@item xmlRegisters
41007This feature indicates that @value{GDBN} supports the XML target
41008description. If the stub sees @samp{xmlRegisters=} with target
41009specific strings separated by a comma, it will report register
41010description.
dde08ee1
PA
41011
41012@item qRelocInsn
41013This feature indicates whether @value{GDBN} supports the
41014@samp{qRelocInsn} packet (@pxref{Tracepoint Packets,,Relocate
41015instruction reply packet}).
f7e6eed5
PA
41016
41017@item swbreak
41018This feature indicates whether @value{GDBN} supports the swbreak stop
41019reason in stop replies. @xref{swbreak stop reason}, for details.
41020
41021@item hwbreak
41022This feature indicates whether @value{GDBN} supports the hwbreak stop
41023reason in stop replies. @xref{swbreak stop reason}, for details.
0d71eef5
DB
41024
41025@item fork-events
41026This feature indicates whether @value{GDBN} supports fork event
41027extensions to the remote protocol. @value{GDBN} does not use such
41028extensions unless the stub also reports that it supports them by
41029including @samp{fork-events+} in its @samp{qSupported} reply.
41030
41031@item vfork-events
41032This feature indicates whether @value{GDBN} supports vfork event
41033extensions to the remote protocol. @value{GDBN} does not use such
41034extensions unless the stub also reports that it supports them by
41035including @samp{vfork-events+} in its @samp{qSupported} reply.
b459a59b
DB
41036
41037@item exec-events
41038This feature indicates whether @value{GDBN} supports exec event
41039extensions to the remote protocol. @value{GDBN} does not use such
41040extensions unless the stub also reports that it supports them by
41041including @samp{exec-events+} in its @samp{qSupported} reply.
750ce8d1
YQ
41042
41043@item vContSupported
41044This feature indicates whether @value{GDBN} wants to know the
41045supported actions in the reply to @samp{vCont?} packet.
b90a069a
SL
41046@end table
41047
41048Stubs should ignore any unknown values for
be2a5f71
DJ
41049@var{gdbfeature}. Any @value{GDBN} which sends a @samp{qSupported}
41050packet supports receiving packets of unlimited length (earlier
b90a069a 41051versions of @value{GDBN} may reject overly long responses). Additional values
be2a5f71
DJ
41052for @var{gdbfeature} may be defined in the future to let the stub take
41053advantage of new features in @value{GDBN}, e.g.@: incompatible
b90a069a
SL
41054improvements in the remote protocol---the @samp{multiprocess} feature is
41055an example of such a feature. The stub's reply should be independent
be2a5f71
DJ
41056of the @var{gdbfeature} entries sent by @value{GDBN}; first @value{GDBN}
41057describes all the features it supports, and then the stub replies with
41058all the features it supports.
41059
41060Similarly, @value{GDBN} will silently ignore unrecognized stub feature
41061responses, as long as each response uses one of the standard forms.
41062
41063Some features are flags. A stub which supports a flag feature
41064should respond with a @samp{+} form response. Other features
41065require values, and the stub should respond with an @samp{=}
41066form response.
41067
41068Each feature has a default value, which @value{GDBN} will use if
41069@samp{qSupported} is not available or if the feature is not mentioned
41070in the @samp{qSupported} response. The default values are fixed; a
41071stub is free to omit any feature responses that match the defaults.
41072
41073Not all features can be probed, but for those which can, the probing
41074mechanism is useful: in some cases, a stub's internal
41075architecture may not allow the protocol layer to know some information
41076about the underlying target in advance. This is especially common in
41077stubs which may be configured for multiple targets.
41078
41079These are the currently defined stub features and their properties:
41080
cfa9d6d9 41081@multitable @columnfractions 0.35 0.2 0.12 0.2
be2a5f71
DJ
41082@c NOTE: The first row should be @headitem, but we do not yet require
41083@c a new enough version of Texinfo (4.7) to use @headitem.
0876f84a 41084@item Feature Name
be2a5f71
DJ
41085@tab Value Required
41086@tab Default
41087@tab Probe Allowed
41088
41089@item @samp{PacketSize}
41090@tab Yes
41091@tab @samp{-}
41092@tab No
41093
0876f84a
DJ
41094@item @samp{qXfer:auxv:read}
41095@tab No
41096@tab @samp{-}
41097@tab Yes
41098
2ae8c8e7
MM
41099@item @samp{qXfer:btrace:read}
41100@tab No
41101@tab @samp{-}
41102@tab Yes
41103
f4abbc16
MM
41104@item @samp{qXfer:btrace-conf:read}
41105@tab No
41106@tab @samp{-}
41107@tab Yes
41108
c78fa86a
GB
41109@item @samp{qXfer:exec-file:read}
41110@tab No
41111@tab @samp{-}
41112@tab Yes
41113
23181151
DJ
41114@item @samp{qXfer:features:read}
41115@tab No
41116@tab @samp{-}
41117@tab Yes
41118
cfa9d6d9
DJ
41119@item @samp{qXfer:libraries:read}
41120@tab No
41121@tab @samp{-}
41122@tab Yes
41123
85dc5a12
GB
41124@item @samp{qXfer:libraries-svr4:read}
41125@tab No
41126@tab @samp{-}
41127@tab Yes
41128
41129@item @samp{augmented-libraries-svr4-read}
41130@tab No
41131@tab @samp{-}
41132@tab No
41133
68437a39
DJ
41134@item @samp{qXfer:memory-map:read}
41135@tab No
41136@tab @samp{-}
41137@tab Yes
41138
0fb4aa4b
PA
41139@item @samp{qXfer:sdata:read}
41140@tab No
41141@tab @samp{-}
41142@tab Yes
41143
4aa995e1
PA
41144@item @samp{qXfer:siginfo:read}
41145@tab No
41146@tab @samp{-}
41147@tab Yes
41148
41149@item @samp{qXfer:siginfo:write}
41150@tab No
41151@tab @samp{-}
41152@tab Yes
41153
dc146f7c
VP
41154@item @samp{qXfer:threads:read}
41155@tab No
41156@tab @samp{-}
41157@tab Yes
41158
b3b9301e
PA
41159@item @samp{qXfer:traceframe-info:read}
41160@tab No
41161@tab @samp{-}
41162@tab Yes
41163
169081d0
TG
41164@item @samp{qXfer:uib:read}
41165@tab No
41166@tab @samp{-}
41167@tab Yes
41168
78d85199
YQ
41169@item @samp{qXfer:fdpic:read}
41170@tab No
41171@tab @samp{-}
41172@tab Yes
dc146f7c 41173
2ae8c8e7
MM
41174@item @samp{Qbtrace:off}
41175@tab Yes
41176@tab @samp{-}
41177@tab Yes
41178
41179@item @samp{Qbtrace:bts}
41180@tab Yes
41181@tab @samp{-}
41182@tab Yes
41183
b20a6524
MM
41184@item @samp{Qbtrace:pt}
41185@tab Yes
41186@tab @samp{-}
41187@tab Yes
41188
d33501a5
MM
41189@item @samp{Qbtrace-conf:bts:size}
41190@tab Yes
41191@tab @samp{-}
41192@tab Yes
41193
b20a6524
MM
41194@item @samp{Qbtrace-conf:pt:size}
41195@tab Yes
41196@tab @samp{-}
41197@tab Yes
41198
8b23ecc4
SL
41199@item @samp{QNonStop}
41200@tab No
41201@tab @samp{-}
41202@tab Yes
41203
82075af2
JS
41204@item @samp{QCatchSyscalls}
41205@tab No
41206@tab @samp{-}
41207@tab Yes
41208
89be2091
DJ
41209@item @samp{QPassSignals}
41210@tab No
41211@tab @samp{-}
41212@tab Yes
41213
a6f3e723
SL
41214@item @samp{QStartNoAckMode}
41215@tab No
41216@tab @samp{-}
41217@tab Yes
41218
b90a069a
SL
41219@item @samp{multiprocess}
41220@tab No
41221@tab @samp{-}
41222@tab No
41223
83364271
LM
41224@item @samp{ConditionalBreakpoints}
41225@tab No
41226@tab @samp{-}
41227@tab No
41228
782b2b07
SS
41229@item @samp{ConditionalTracepoints}
41230@tab No
41231@tab @samp{-}
41232@tab No
41233
0d772ac9
MS
41234@item @samp{ReverseContinue}
41235@tab No
2f8132f3 41236@tab @samp{-}
0d772ac9
MS
41237@tab No
41238
41239@item @samp{ReverseStep}
41240@tab No
2f8132f3 41241@tab @samp{-}
0d772ac9
MS
41242@tab No
41243
409873ef
SS
41244@item @samp{TracepointSource}
41245@tab No
41246@tab @samp{-}
41247@tab No
41248
d1feda86
YQ
41249@item @samp{QAgent}
41250@tab No
41251@tab @samp{-}
41252@tab No
41253
d914c394
SS
41254@item @samp{QAllow}
41255@tab No
41256@tab @samp{-}
41257@tab No
41258
03583c20
UW
41259@item @samp{QDisableRandomization}
41260@tab No
41261@tab @samp{-}
41262@tab No
41263
d248b706
KY
41264@item @samp{EnableDisableTracepoints}
41265@tab No
41266@tab @samp{-}
41267@tab No
41268
f6f899bf
HAQ
41269@item @samp{QTBuffer:size}
41270@tab No
41271@tab @samp{-}
41272@tab No
41273
3065dfb6
SS
41274@item @samp{tracenz}
41275@tab No
41276@tab @samp{-}
41277@tab No
41278
d3ce09f5
SS
41279@item @samp{BreakpointCommands}
41280@tab No
41281@tab @samp{-}
41282@tab No
41283
f7e6eed5
PA
41284@item @samp{swbreak}
41285@tab No
41286@tab @samp{-}
41287@tab No
41288
41289@item @samp{hwbreak}
41290@tab No
41291@tab @samp{-}
41292@tab No
41293
0d71eef5
DB
41294@item @samp{fork-events}
41295@tab No
41296@tab @samp{-}
41297@tab No
41298
41299@item @samp{vfork-events}
41300@tab No
41301@tab @samp{-}
41302@tab No
41303
b459a59b
DB
41304@item @samp{exec-events}
41305@tab No
41306@tab @samp{-}
41307@tab No
41308
65706a29
PA
41309@item @samp{QThreadEvents}
41310@tab No
41311@tab @samp{-}
41312@tab No
41313
f2faf941
PA
41314@item @samp{no-resumed}
41315@tab No
41316@tab @samp{-}
41317@tab No
41318
be2a5f71
DJ
41319@end multitable
41320
41321These are the currently defined stub features, in more detail:
41322
41323@table @samp
41324@cindex packet size, remote protocol
41325@item PacketSize=@var{bytes}
41326The remote stub can accept packets up to at least @var{bytes} in
41327length. @value{GDBN} will send packets up to this size for bulk
41328transfers, and will never send larger packets. This is a limit on the
41329data characters in the packet, including the frame and checksum.
41330There is no trailing NUL byte in a remote protocol packet; if the stub
41331stores packets in a NUL-terminated format, it should allow an extra
41332byte in its buffer for the NUL. If this stub feature is not supported,
41333@value{GDBN} guesses based on the size of the @samp{g} packet response.
41334
0876f84a
DJ
41335@item qXfer:auxv:read
41336The remote stub understands the @samp{qXfer:auxv:read} packet
41337(@pxref{qXfer auxiliary vector read}).
41338
2ae8c8e7
MM
41339@item qXfer:btrace:read
41340The remote stub understands the @samp{qXfer:btrace:read}
41341packet (@pxref{qXfer btrace read}).
41342
f4abbc16
MM
41343@item qXfer:btrace-conf:read
41344The remote stub understands the @samp{qXfer:btrace-conf:read}
41345packet (@pxref{qXfer btrace-conf read}).
41346
c78fa86a
GB
41347@item qXfer:exec-file:read
41348The remote stub understands the @samp{qXfer:exec-file:read} packet
41349(@pxref{qXfer executable filename read}).
41350
23181151
DJ
41351@item qXfer:features:read
41352The remote stub understands the @samp{qXfer:features:read} packet
41353(@pxref{qXfer target description read}).
41354
cfa9d6d9
DJ
41355@item qXfer:libraries:read
41356The remote stub understands the @samp{qXfer:libraries:read} packet
41357(@pxref{qXfer library list read}).
41358
2268b414
JK
41359@item qXfer:libraries-svr4:read
41360The remote stub understands the @samp{qXfer:libraries-svr4:read} packet
41361(@pxref{qXfer svr4 library list read}).
41362
85dc5a12
GB
41363@item augmented-libraries-svr4-read
41364The remote stub understands the augmented form of the
41365@samp{qXfer:libraries-svr4:read} packet
41366(@pxref{qXfer svr4 library list read}).
41367
23181151
DJ
41368@item qXfer:memory-map:read
41369The remote stub understands the @samp{qXfer:memory-map:read} packet
41370(@pxref{qXfer memory map read}).
41371
0fb4aa4b
PA
41372@item qXfer:sdata:read
41373The remote stub understands the @samp{qXfer:sdata:read} packet
41374(@pxref{qXfer sdata read}).
41375
4aa995e1
PA
41376@item qXfer:siginfo:read
41377The remote stub understands the @samp{qXfer:siginfo:read} packet
41378(@pxref{qXfer siginfo read}).
41379
41380@item qXfer:siginfo:write
41381The remote stub understands the @samp{qXfer:siginfo:write} packet
41382(@pxref{qXfer siginfo write}).
41383
dc146f7c
VP
41384@item qXfer:threads:read
41385The remote stub understands the @samp{qXfer:threads:read} packet
41386(@pxref{qXfer threads read}).
41387
b3b9301e
PA
41388@item qXfer:traceframe-info:read
41389The remote stub understands the @samp{qXfer:traceframe-info:read}
41390packet (@pxref{qXfer traceframe info read}).
41391
169081d0
TG
41392@item qXfer:uib:read
41393The remote stub understands the @samp{qXfer:uib:read}
41394packet (@pxref{qXfer unwind info block}).
41395
78d85199
YQ
41396@item qXfer:fdpic:read
41397The remote stub understands the @samp{qXfer:fdpic:read}
41398packet (@pxref{qXfer fdpic loadmap read}).
41399
8b23ecc4
SL
41400@item QNonStop
41401The remote stub understands the @samp{QNonStop} packet
41402(@pxref{QNonStop}).
41403
82075af2
JS
41404@item QCatchSyscalls
41405The remote stub understands the @samp{QCatchSyscalls} packet
41406(@pxref{QCatchSyscalls}).
41407
23181151
DJ
41408@item QPassSignals
41409The remote stub understands the @samp{QPassSignals} packet
41410(@pxref{QPassSignals}).
41411
a6f3e723
SL
41412@item QStartNoAckMode
41413The remote stub understands the @samp{QStartNoAckMode} packet and
41414prefers to operate in no-acknowledgment mode. @xref{Packet Acknowledgment}.
41415
b90a069a
SL
41416@item multiprocess
41417@anchor{multiprocess extensions}
41418@cindex multiprocess extensions, in remote protocol
41419The remote stub understands the multiprocess extensions to the remote
41420protocol syntax. The multiprocess extensions affect the syntax of
41421thread IDs in both packets and replies (@pxref{thread-id syntax}), and
41422add process IDs to the @samp{D} packet and @samp{W} and @samp{X}
41423replies. Note that reporting this feature indicates support for the
41424syntactic extensions only, not that the stub necessarily supports
41425debugging of more than one process at a time. The stub must not use
41426multiprocess extensions in packet replies unless @value{GDBN} has also
41427indicated it supports them in its @samp{qSupported} request.
41428
07e059b5
VP
41429@item qXfer:osdata:read
41430The remote stub understands the @samp{qXfer:osdata:read} packet
41431((@pxref{qXfer osdata read}).
41432
83364271
LM
41433@item ConditionalBreakpoints
41434The target accepts and implements evaluation of conditional expressions
41435defined for breakpoints. The target will only report breakpoint triggers
41436when such conditions are true (@pxref{Conditions, ,Break Conditions}).
41437
782b2b07
SS
41438@item ConditionalTracepoints
41439The remote stub accepts and implements conditional expressions defined
41440for tracepoints (@pxref{Tracepoint Conditions}).
41441
0d772ac9
MS
41442@item ReverseContinue
41443The remote stub accepts and implements the reverse continue packet
41444(@pxref{bc}).
41445
41446@item ReverseStep
41447The remote stub accepts and implements the reverse step packet
41448(@pxref{bs}).
41449
409873ef
SS
41450@item TracepointSource
41451The remote stub understands the @samp{QTDPsrc} packet that supplies
41452the source form of tracepoint definitions.
41453
d1feda86
YQ
41454@item QAgent
41455The remote stub understands the @samp{QAgent} packet.
41456
d914c394
SS
41457@item QAllow
41458The remote stub understands the @samp{QAllow} packet.
41459
03583c20
UW
41460@item QDisableRandomization
41461The remote stub understands the @samp{QDisableRandomization} packet.
41462
0fb4aa4b
PA
41463@item StaticTracepoint
41464@cindex static tracepoints, in remote protocol
41465The remote stub supports static tracepoints.
41466
1e4d1764
YQ
41467@item InstallInTrace
41468@anchor{install tracepoint in tracing}
41469The remote stub supports installing tracepoint in tracing.
41470
d248b706
KY
41471@item EnableDisableTracepoints
41472The remote stub supports the @samp{QTEnable} (@pxref{QTEnable}) and
41473@samp{QTDisable} (@pxref{QTDisable}) packets that allow tracepoints
41474to be enabled and disabled while a trace experiment is running.
41475
f6f899bf 41476@item QTBuffer:size
28abe188 41477The remote stub supports the @samp{QTBuffer:size} (@pxref{QTBuffer-size})
f6f899bf
HAQ
41478packet that allows to change the size of the trace buffer.
41479
3065dfb6
SS
41480@item tracenz
41481@cindex string tracing, in remote protocol
41482The remote stub supports the @samp{tracenz} bytecode for collecting strings.
41483See @ref{Bytecode Descriptions} for details about the bytecode.
41484
d3ce09f5
SS
41485@item BreakpointCommands
41486@cindex breakpoint commands, in remote protocol
41487The remote stub supports running a breakpoint's command list itself,
41488rather than reporting the hit to @value{GDBN}.
41489
2ae8c8e7
MM
41490@item Qbtrace:off
41491The remote stub understands the @samp{Qbtrace:off} packet.
41492
41493@item Qbtrace:bts
41494The remote stub understands the @samp{Qbtrace:bts} packet.
41495
b20a6524
MM
41496@item Qbtrace:pt
41497The remote stub understands the @samp{Qbtrace:pt} packet.
41498
d33501a5
MM
41499@item Qbtrace-conf:bts:size
41500The remote stub understands the @samp{Qbtrace-conf:bts:size} packet.
41501
b20a6524
MM
41502@item Qbtrace-conf:pt:size
41503The remote stub understands the @samp{Qbtrace-conf:pt:size} packet.
41504
f7e6eed5
PA
41505@item swbreak
41506The remote stub reports the @samp{swbreak} stop reason for memory
41507breakpoints.
41508
41509@item hwbreak
41510The remote stub reports the @samp{hwbreak} stop reason for hardware
41511breakpoints.
41512
0d71eef5
DB
41513@item fork-events
41514The remote stub reports the @samp{fork} stop reason for fork events.
41515
41516@item vfork-events
41517The remote stub reports the @samp{vfork} stop reason for vfork events
41518and vforkdone events.
41519
b459a59b
DB
41520@item exec-events
41521The remote stub reports the @samp{exec} stop reason for exec events.
41522
750ce8d1
YQ
41523@item vContSupported
41524The remote stub reports the supported actions in the reply to
41525@samp{vCont?} packet.
41526
65706a29
PA
41527@item QThreadEvents
41528The remote stub understands the @samp{QThreadEvents} packet.
41529
f2faf941
PA
41530@item no-resumed
41531The remote stub reports the @samp{N} stop reply.
41532
be2a5f71
DJ
41533@end table
41534
b8ff78ce 41535@item qSymbol::
ff2587ec 41536@cindex symbol lookup, remote request
b8ff78ce 41537@cindex @samp{qSymbol} packet
ff2587ec
WZ
41538Notify the target that @value{GDBN} is prepared to serve symbol lookup
41539requests. Accept requests from the target for the values of symbols.
fa93a9d8
JB
41540
41541Reply:
ff2587ec 41542@table @samp
b8ff78ce 41543@item OK
ff2587ec 41544The target does not need to look up any (more) symbols.
b8ff78ce 41545@item qSymbol:@var{sym_name}
ff2587ec
WZ
41546The target requests the value of symbol @var{sym_name} (hex encoded).
41547@value{GDBN} may provide the value by using the
b8ff78ce
JB
41548@samp{qSymbol:@var{sym_value}:@var{sym_name}} message, described
41549below.
ff2587ec 41550@end table
83761cbd 41551
b8ff78ce 41552@item qSymbol:@var{sym_value}:@var{sym_name}
ff2587ec
WZ
41553Set the value of @var{sym_name} to @var{sym_value}.
41554
41555@var{sym_name} (hex encoded) is the name of a symbol whose value the
41556target has previously requested.
41557
41558@var{sym_value} (hex) is the value for symbol @var{sym_name}. If
41559@value{GDBN} cannot supply a value for @var{sym_name}, then this field
41560will be empty.
41561
41562Reply:
41563@table @samp
b8ff78ce 41564@item OK
ff2587ec 41565The target does not need to look up any (more) symbols.
b8ff78ce 41566@item qSymbol:@var{sym_name}
ff2587ec
WZ
41567The target requests the value of a new symbol @var{sym_name} (hex
41568encoded). @value{GDBN} will continue to supply the values of symbols
41569(if available), until the target ceases to request them.
fa93a9d8 41570@end table
0abb7bc7 41571
00bf0b85 41572@item qTBuffer
687e43a4
TT
41573@itemx QTBuffer
41574@itemx QTDisconnected
d5551862 41575@itemx QTDP
409873ef 41576@itemx QTDPsrc
d5551862 41577@itemx QTDV
00bf0b85
SS
41578@itemx qTfP
41579@itemx qTfV
9d29849a 41580@itemx QTFrame
405f8e94
SS
41581@itemx qTMinFTPILen
41582
9d29849a
JB
41583@xref{Tracepoint Packets}.
41584
b90a069a 41585@item qThreadExtraInfo,@var{thread-id}
ff2587ec 41586@cindex thread attributes info, remote request
b8ff78ce 41587@cindex @samp{qThreadExtraInfo} packet
697aa1b7
EZ
41588Obtain from the target OS a printable string description of thread
41589attributes for the thread @var{thread-id}; see @ref{thread-id syntax},
41590for the forms of @var{thread-id}. This
b8ff78ce
JB
41591string may contain anything that the target OS thinks is interesting
41592for @value{GDBN} to tell the user about the thread. The string is
41593displayed in @value{GDBN}'s @code{info threads} display. Some
41594examples of possible thread extra info strings are @samp{Runnable}, or
41595@samp{Blocked on Mutex}.
ff2587ec
WZ
41596
41597Reply:
41598@table @samp
b8ff78ce
JB
41599@item @var{XX}@dots{}
41600Where @samp{@var{XX}@dots{}} is a hex encoding of @sc{ascii} data,
41601comprising the printable string containing the extra information about
41602the thread's attributes.
ff2587ec 41603@end table
814e32d7 41604
aa56d27a
JB
41605(Note that the @code{qThreadExtraInfo} packet's name is separated from
41606the command by a @samp{,}, not a @samp{:}, contrary to the naming
41607conventions above. Please don't use this packet as a model for new
41608packets.)
41609
f196051f 41610@item QTNotes
687e43a4
TT
41611@itemx qTP
41612@itemx QTSave
41613@itemx qTsP
41614@itemx qTsV
d5551862 41615@itemx QTStart
9d29849a 41616@itemx QTStop
d248b706
KY
41617@itemx QTEnable
41618@itemx QTDisable
9d29849a
JB
41619@itemx QTinit
41620@itemx QTro
41621@itemx qTStatus
d5551862 41622@itemx qTV
0fb4aa4b
PA
41623@itemx qTfSTM
41624@itemx qTsSTM
41625@itemx qTSTMat
9d29849a
JB
41626@xref{Tracepoint Packets}.
41627
0876f84a
DJ
41628@item qXfer:@var{object}:read:@var{annex}:@var{offset},@var{length}
41629@cindex read special object, remote request
41630@cindex @samp{qXfer} packet
68437a39 41631@anchor{qXfer read}
0876f84a
DJ
41632Read uninterpreted bytes from the target's special data area
41633identified by the keyword @var{object}. Request @var{length} bytes
41634starting at @var{offset} bytes into the data. The content and
0e7f50da 41635encoding of @var{annex} is specific to @var{object}; it can supply
0876f84a
DJ
41636additional details about what data to access.
41637
c185ba27
EZ
41638Reply:
41639@table @samp
41640@item m @var{data}
41641Data @var{data} (@pxref{Binary Data}) has been read from the
41642target. There may be more data at a higher address (although
41643it is permitted to return @samp{m} even for the last valid
41644block of data, as long as at least one byte of data was read).
41645It is possible for @var{data} to have fewer bytes than the @var{length} in the
41646request.
41647
41648@item l @var{data}
41649Data @var{data} (@pxref{Binary Data}) has been read from the target.
41650There is no more data to be read. It is possible for @var{data} to
41651have fewer bytes than the @var{length} in the request.
41652
41653@item l
41654The @var{offset} in the request is at the end of the data.
41655There is no more data to be read.
41656
41657@item E00
41658The request was malformed, or @var{annex} was invalid.
41659
41660@item E @var{nn}
41661The offset was invalid, or there was an error encountered reading the data.
41662The @var{nn} part is a hex-encoded @code{errno} value.
41663
41664@item @w{}
41665An empty reply indicates the @var{object} string was not recognized by
41666the stub, or that the object does not support reading.
41667@end table
41668
41669Here are the specific requests of this form defined so far. All the
0876f84a 41670@samp{qXfer:@var{object}:read:@dots{}} requests use the same reply
c185ba27 41671formats, listed above.
0876f84a
DJ
41672
41673@table @samp
41674@item qXfer:auxv:read::@var{offset},@var{length}
41675@anchor{qXfer auxiliary vector read}
41676Access the target's @dfn{auxiliary vector}. @xref{OS Information,
427c3a89 41677auxiliary vector}. Note @var{annex} must be empty.
0876f84a
DJ
41678
41679This packet is not probed by default; the remote stub must request it,
89be2091 41680by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
0876f84a 41681
2ae8c8e7
MM
41682@item qXfer:btrace:read:@var{annex}:@var{offset},@var{length}
41683@anchor{qXfer btrace read}
41684
41685Return a description of the current branch trace.
41686@xref{Branch Trace Format}. The annex part of the generic @samp{qXfer}
41687packet may have one of the following values:
41688
41689@table @code
41690@item all
41691Returns all available branch trace.
41692
41693@item new
41694Returns all available branch trace if the branch trace changed since
41695the last read request.
969c39fb
MM
41696
41697@item delta
41698Returns the new branch trace since the last read request. Adds a new
41699block to the end of the trace that begins at zero and ends at the source
41700location of the first branch in the trace buffer. This extra block is
41701used to stitch traces together.
41702
41703If the trace buffer overflowed, returns an error indicating the overflow.
2ae8c8e7
MM
41704@end table
41705
41706This packet is not probed by default; the remote stub must request it
41707by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41708
f4abbc16
MM
41709@item qXfer:btrace-conf:read::@var{offset},@var{length}
41710@anchor{qXfer btrace-conf read}
41711
41712Return a description of the current branch trace configuration.
41713@xref{Branch Trace Configuration Format}.
41714
41715This packet is not probed by default; the remote stub must request it
41716by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
c78fa86a
GB
41717
41718@item qXfer:exec-file:read:@var{annex}:@var{offset},@var{length}
41719@anchor{qXfer executable filename read}
41720Return the full absolute name of the file that was executed to create
41721a process running on the remote system. The annex specifies the
41722numeric process ID of the process to query, encoded as a hexadecimal
835205d0
GB
41723number. If the annex part is empty the remote stub should return the
41724filename corresponding to the currently executing process.
c78fa86a
GB
41725
41726This packet is not probed by default; the remote stub must request it,
41727by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
f4abbc16 41728
23181151
DJ
41729@item qXfer:features:read:@var{annex}:@var{offset},@var{length}
41730@anchor{qXfer target description read}
41731Access the @dfn{target description}. @xref{Target Descriptions}. The
41732annex specifies which XML document to access. The main description is
41733always loaded from the @samp{target.xml} annex.
41734
41735This packet is not probed by default; the remote stub must request it,
41736by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41737
cfa9d6d9
DJ
41738@item qXfer:libraries:read:@var{annex}:@var{offset},@var{length}
41739@anchor{qXfer library list read}
41740Access the target's list of loaded libraries. @xref{Library List Format}.
41741The annex part of the generic @samp{qXfer} packet must be empty
41742(@pxref{qXfer read}).
41743
41744Targets which maintain a list of libraries in the program's memory do
41745not need to implement this packet; it is designed for platforms where
41746the operating system manages the list of loaded libraries.
41747
41748This packet is not probed by default; the remote stub must request it,
41749by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41750
2268b414
JK
41751@item qXfer:libraries-svr4:read:@var{annex}:@var{offset},@var{length}
41752@anchor{qXfer svr4 library list read}
41753Access the target's list of loaded libraries when the target is an SVR4
41754platform. @xref{Library List Format for SVR4 Targets}. The annex part
85dc5a12
GB
41755of the generic @samp{qXfer} packet must be empty unless the remote
41756stub indicated it supports the augmented form of this packet
41757by supplying an appropriate @samp{qSupported} response
41758(@pxref{qXfer read}, @ref{qSupported}).
2268b414
JK
41759
41760This packet is optional for better performance on SVR4 targets.
41761@value{GDBN} uses memory read packets to read the SVR4 library list otherwise.
41762
41763This packet is not probed by default; the remote stub must request it,
41764by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41765
85dc5a12
GB
41766If the remote stub indicates it supports the augmented form of this
41767packet then the annex part of the generic @samp{qXfer} packet may
41768contain a semicolon-separated list of @samp{@var{name}=@var{value}}
41769arguments. The currently supported arguments are:
41770
41771@table @code
41772@item start=@var{address}
41773A hexadecimal number specifying the address of the @samp{struct
41774link_map} to start reading the library list from. If unset or zero
41775then the first @samp{struct link_map} in the library list will be
41776chosen as the starting point.
41777
41778@item prev=@var{address}
41779A hexadecimal number specifying the address of the @samp{struct
41780link_map} immediately preceding the @samp{struct link_map}
41781specified by the @samp{start} argument. If unset or zero then
41782the remote stub will expect that no @samp{struct link_map}
41783exists prior to the starting point.
41784
41785@end table
41786
41787Arguments that are not understood by the remote stub will be silently
41788ignored.
41789
68437a39
DJ
41790@item qXfer:memory-map:read::@var{offset},@var{length}
41791@anchor{qXfer memory map read}
79a6e687 41792Access the target's @dfn{memory-map}. @xref{Memory Map Format}. The
68437a39
DJ
41793annex part of the generic @samp{qXfer} packet must be empty
41794(@pxref{qXfer read}).
41795
0e7f50da
UW
41796This packet is not probed by default; the remote stub must request it,
41797by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41798
0fb4aa4b
PA
41799@item qXfer:sdata:read::@var{offset},@var{length}
41800@anchor{qXfer sdata read}
41801
41802Read contents of the extra collected static tracepoint marker
41803information. The annex part of the generic @samp{qXfer} packet must
41804be empty (@pxref{qXfer read}). @xref{Tracepoint Actions,,Tracepoint
41805Action Lists}.
41806
41807This packet is not probed by default; the remote stub must request it,
41808by supplying an appropriate @samp{qSupported} response
41809(@pxref{qSupported}).
41810
4aa995e1
PA
41811@item qXfer:siginfo:read::@var{offset},@var{length}
41812@anchor{qXfer siginfo read}
41813Read contents of the extra signal information on the target
41814system. The annex part of the generic @samp{qXfer} packet must be
41815empty (@pxref{qXfer read}).
41816
41817This packet is not probed by default; the remote stub must request it,
41818by supplying an appropriate @samp{qSupported} response
41819(@pxref{qSupported}).
41820
dc146f7c
VP
41821@item qXfer:threads:read::@var{offset},@var{length}
41822@anchor{qXfer threads read}
41823Access the list of threads on target. @xref{Thread List Format}. The
41824annex part of the generic @samp{qXfer} packet must be empty
41825(@pxref{qXfer read}).
41826
41827This packet is not probed by default; the remote stub must request it,
41828by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41829
b3b9301e
PA
41830@item qXfer:traceframe-info:read::@var{offset},@var{length}
41831@anchor{qXfer traceframe info read}
41832
41833Return a description of the current traceframe's contents.
41834@xref{Traceframe Info Format}. The annex part of the generic
41835@samp{qXfer} packet must be empty (@pxref{qXfer read}).
41836
41837This packet is not probed by default; the remote stub must request it,
41838by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41839
169081d0
TG
41840@item qXfer:uib:read:@var{pc}:@var{offset},@var{length}
41841@anchor{qXfer unwind info block}
41842
41843Return the unwind information block for @var{pc}. This packet is used
41844on OpenVMS/ia64 to ask the kernel unwind information.
41845
41846This packet is not probed by default.
41847
78d85199
YQ
41848@item qXfer:fdpic:read:@var{annex}:@var{offset},@var{length}
41849@anchor{qXfer fdpic loadmap read}
41850Read contents of @code{loadmap}s on the target system. The
41851annex, either @samp{exec} or @samp{interp}, specifies which @code{loadmap},
41852executable @code{loadmap} or interpreter @code{loadmap} to read.
41853
41854This packet is not probed by default; the remote stub must request it,
41855by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41856
07e059b5
VP
41857@item qXfer:osdata:read::@var{offset},@var{length}
41858@anchor{qXfer osdata read}
697aa1b7 41859Access the target's @dfn{operating system information}.
07e059b5
VP
41860@xref{Operating System Information}.
41861
68437a39
DJ
41862@end table
41863
c185ba27
EZ
41864@item qXfer:@var{object}:write:@var{annex}:@var{offset}:@var{data}@dots{}
41865@cindex write data into object, remote request
41866@anchor{qXfer write}
41867Write uninterpreted bytes into the target's special data area
41868identified by the keyword @var{object}, starting at @var{offset} bytes
41869into the data. The binary-encoded data (@pxref{Binary Data}) to be
41870written is given by @var{data}@dots{}. The content and encoding of @var{annex}
41871is specific to @var{object}; it can supply additional details about what data
41872to access.
41873
0876f84a
DJ
41874Reply:
41875@table @samp
c185ba27
EZ
41876@item @var{nn}
41877@var{nn} (hex encoded) is the number of bytes written.
41878This may be fewer bytes than supplied in the request.
0876f84a
DJ
41879
41880@item E00
41881The request was malformed, or @var{annex} was invalid.
41882
41883@item E @var{nn}
c185ba27 41884The offset was invalid, or there was an error encountered writing the data.
697aa1b7 41885The @var{nn} part is a hex-encoded @code{errno} value.
0876f84a 41886
d57350ea 41887@item @w{}
c185ba27
EZ
41888An empty reply indicates the @var{object} string was not
41889recognized by the stub, or that the object does not support writing.
0876f84a
DJ
41890@end table
41891
c185ba27 41892Here are the specific requests of this form defined so far. All the
0e7f50da 41893@samp{qXfer:@var{object}:write:@dots{}} requests use the same reply
c185ba27 41894formats, listed above.
0e7f50da
UW
41895
41896@table @samp
4aa995e1
PA
41897@item qXfer:siginfo:write::@var{offset}:@var{data}@dots{}
41898@anchor{qXfer siginfo write}
41899Write @var{data} to the extra signal information on the target system.
41900The annex part of the generic @samp{qXfer} packet must be
41901empty (@pxref{qXfer write}).
41902
41903This packet is not probed by default; the remote stub must request it,
41904by supplying an appropriate @samp{qSupported} response
41905(@pxref{qSupported}).
0e7f50da 41906@end table
0876f84a 41907
0876f84a
DJ
41908@item qXfer:@var{object}:@var{operation}:@dots{}
41909Requests of this form may be added in the future. When a stub does
41910not recognize the @var{object} keyword, or its support for
41911@var{object} does not recognize the @var{operation} keyword, the stub
41912must respond with an empty packet.
41913
0b16c5cf
PA
41914@item qAttached:@var{pid}
41915@cindex query attached, remote request
41916@cindex @samp{qAttached} packet
41917Return an indication of whether the remote server attached to an
41918existing process or created a new process. When the multiprocess
41919protocol extensions are supported (@pxref{multiprocess extensions}),
41920@var{pid} is an integer in hexadecimal format identifying the target
41921process. Otherwise, @value{GDBN} will omit the @var{pid} field and
41922the query packet will be simplified as @samp{qAttached}.
41923
41924This query is used, for example, to know whether the remote process
41925should be detached or killed when a @value{GDBN} session is ended with
41926the @code{quit} command.
41927
41928Reply:
41929@table @samp
41930@item 1
41931The remote server attached to an existing process.
41932@item 0
41933The remote server created a new process.
41934@item E @var{NN}
41935A badly formed request or an error was encountered.
41936@end table
41937
2ae8c8e7 41938@item Qbtrace:bts
b20a6524
MM
41939Enable branch tracing for the current thread using Branch Trace Store.
41940
41941Reply:
41942@table @samp
41943@item OK
41944Branch tracing has been enabled.
41945@item E.errtext
41946A badly formed request or an error was encountered.
41947@end table
41948
41949@item Qbtrace:pt
bc504a31 41950Enable branch tracing for the current thread using Intel Processor Trace.
2ae8c8e7
MM
41951
41952Reply:
41953@table @samp
41954@item OK
41955Branch tracing has been enabled.
41956@item E.errtext
41957A badly formed request or an error was encountered.
41958@end table
41959
41960@item Qbtrace:off
41961Disable branch tracing for the current thread.
41962
41963Reply:
41964@table @samp
41965@item OK
41966Branch tracing has been disabled.
41967@item E.errtext
41968A badly formed request or an error was encountered.
41969@end table
41970
d33501a5
MM
41971@item Qbtrace-conf:bts:size=@var{value}
41972Set the requested ring buffer size for new threads that use the
41973btrace recording method in bts format.
41974
41975Reply:
41976@table @samp
41977@item OK
41978The ring buffer size has been set.
41979@item E.errtext
41980A badly formed request or an error was encountered.
41981@end table
41982
b20a6524
MM
41983@item Qbtrace-conf:pt:size=@var{value}
41984Set the requested ring buffer size for new threads that use the
41985btrace recording method in pt format.
41986
41987Reply:
41988@table @samp
41989@item OK
41990The ring buffer size has been set.
41991@item E.errtext
41992A badly formed request or an error was encountered.
41993@end table
41994
ee2d5c50
AC
41995@end table
41996
a1dcb23a
DJ
41997@node Architecture-Specific Protocol Details
41998@section Architecture-Specific Protocol Details
41999
42000This section describes how the remote protocol is applied to specific
42001target architectures. Also see @ref{Standard Target Features}, for
42002details of XML target descriptions for each architecture.
42003
02b67415
MR
42004@menu
42005* ARM-Specific Protocol Details::
42006* MIPS-Specific Protocol Details::
42007@end menu
42008
42009@node ARM-Specific Protocol Details
42010@subsection @acronym{ARM}-specific Protocol Details
42011
42012@menu
42013* ARM Breakpoint Kinds::
42014@end menu
a1dcb23a 42015
02b67415
MR
42016@node ARM Breakpoint Kinds
42017@subsubsection @acronym{ARM} Breakpoint Kinds
42018@cindex breakpoint kinds, @acronym{ARM}
a1dcb23a
DJ
42019
42020These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
42021
42022@table @r
42023
42024@item 2
4202516-bit Thumb mode breakpoint.
42026
42027@item 3
4202832-bit Thumb mode (Thumb-2) breakpoint.
42029
42030@item 4
02b67415 4203132-bit @acronym{ARM} mode breakpoint.
a1dcb23a
DJ
42032
42033@end table
42034
02b67415
MR
42035@node MIPS-Specific Protocol Details
42036@subsection @acronym{MIPS}-specific Protocol Details
42037
42038@menu
42039* MIPS Register packet Format::
4cc0665f 42040* MIPS Breakpoint Kinds::
02b67415 42041@end menu
a1dcb23a 42042
02b67415
MR
42043@node MIPS Register packet Format
42044@subsubsection @acronym{MIPS} Register Packet Format
eb17f351 42045@cindex register packet format, @acronym{MIPS}
eb12ee30 42046
b8ff78ce 42047The following @code{g}/@code{G} packets have previously been defined.
ee2d5c50
AC
42048In the below, some thirty-two bit registers are transferred as
42049sixty-four bits. Those registers should be zero/sign extended (which?)
599b237a
BW
42050to fill the space allocated. Register bytes are transferred in target
42051byte order. The two nibbles within a register byte are transferred
02b67415 42052most-significant -- least-significant.
eb12ee30 42053
ee2d5c50 42054@table @r
eb12ee30 42055
8e04817f 42056@item MIPS32
599b237a 42057All registers are transferred as thirty-two bit quantities in the order:
8e04817f
AC
4205832 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
42059registers; fsr; fir; fp.
eb12ee30 42060
8e04817f 42061@item MIPS64
599b237a 42062All registers are transferred as sixty-four bit quantities (including
8e04817f
AC
42063thirty-two bit registers such as @code{sr}). The ordering is the same
42064as @code{MIPS32}.
eb12ee30 42065
ee2d5c50
AC
42066@end table
42067
4cc0665f
MR
42068@node MIPS Breakpoint Kinds
42069@subsubsection @acronym{MIPS} Breakpoint Kinds
42070@cindex breakpoint kinds, @acronym{MIPS}
42071
42072These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
42073
42074@table @r
42075
42076@item 2
4207716-bit @acronym{MIPS16} mode breakpoint.
42078
42079@item 3
4208016-bit @acronym{microMIPS} mode breakpoint.
42081
42082@item 4
4208332-bit standard @acronym{MIPS} mode breakpoint.
42084
42085@item 5
4208632-bit @acronym{microMIPS} mode breakpoint.
42087
42088@end table
42089
9d29849a
JB
42090@node Tracepoint Packets
42091@section Tracepoint Packets
42092@cindex tracepoint packets
42093@cindex packets, tracepoint
42094
42095Here we describe the packets @value{GDBN} uses to implement
42096tracepoints (@pxref{Tracepoints}).
42097
42098@table @samp
42099
7a697b8d 42100@item QTDP:@var{n}:@var{addr}:@var{ena}:@var{step}:@var{pass}[:F@var{flen}][:X@var{len},@var{bytes}]@r{[}-@r{]}
c614397c 42101@cindex @samp{QTDP} packet
9d29849a
JB
42102Create a new tracepoint, number @var{n}, at @var{addr}. If @var{ena}
42103is @samp{E}, then the tracepoint is enabled; if it is @samp{D}, then
697aa1b7
EZ
42104the tracepoint is disabled. The @var{step} gives the tracepoint's step
42105count, and @var{pass} gives its pass count. If an @samp{F} is present,
7a697b8d
SS
42106then the tracepoint is to be a fast tracepoint, and the @var{flen} is
42107the number of bytes that the target should copy elsewhere to make room
42108for the tracepoint. If an @samp{X} is present, it introduces a
42109tracepoint condition, which consists of a hexadecimal length, followed
42110by a comma and hex-encoded bytes, in a manner similar to action
42111encodings as described below. If the trailing @samp{-} is present,
42112further @samp{QTDP} packets will follow to specify this tracepoint's
42113actions.
9d29849a
JB
42114
42115Replies:
42116@table @samp
42117@item OK
42118The packet was understood and carried out.
dde08ee1
PA
42119@item qRelocInsn
42120@xref{Tracepoint Packets,,Relocate instruction reply packet}.
d57350ea 42121@item @w{}
9d29849a
JB
42122The packet was not recognized.
42123@end table
42124
42125@item QTDP:-@var{n}:@var{addr}:@r{[}S@r{]}@var{action}@dots{}@r{[}-@r{]}
697aa1b7 42126Define actions to be taken when a tracepoint is hit. The @var{n} and
9d29849a
JB
42127@var{addr} must be the same as in the initial @samp{QTDP} packet for
42128this tracepoint. This packet may only be sent immediately after
42129another @samp{QTDP} packet that ended with a @samp{-}. If the
42130trailing @samp{-} is present, further @samp{QTDP} packets will follow,
42131specifying more actions for this tracepoint.
42132
42133In the series of action packets for a given tracepoint, at most one
42134can have an @samp{S} before its first @var{action}. If such a packet
42135is sent, it and the following packets define ``while-stepping''
42136actions. Any prior packets define ordinary actions --- that is, those
42137taken when the tracepoint is first hit. If no action packet has an
42138@samp{S}, then all the packets in the series specify ordinary
42139tracepoint actions.
42140
42141The @samp{@var{action}@dots{}} portion of the packet is a series of
42142actions, concatenated without separators. Each action has one of the
42143following forms:
42144
42145@table @samp
42146
42147@item R @var{mask}
697aa1b7 42148Collect the registers whose bits are set in @var{mask},
599b237a 42149a hexadecimal number whose @var{i}'th bit is set if register number
9d29849a
JB
42150@var{i} should be collected. (The least significant bit is numbered
42151zero.) Note that @var{mask} may be any number of digits long; it may
42152not fit in a 32-bit word.
42153
42154@item M @var{basereg},@var{offset},@var{len}
42155Collect @var{len} bytes of memory starting at the address in register
42156number @var{basereg}, plus @var{offset}. If @var{basereg} is
42157@samp{-1}, then the range has a fixed address: @var{offset} is the
42158address of the lowest byte to collect. The @var{basereg},
599b237a 42159@var{offset}, and @var{len} parameters are all unsigned hexadecimal
9d29849a
JB
42160values (the @samp{-1} value for @var{basereg} is a special case).
42161
42162@item X @var{len},@var{expr}
42163Evaluate @var{expr}, whose length is @var{len}, and collect memory as
697aa1b7 42164it directs. The agent expression @var{expr} is as described in
9d29849a
JB
42165@ref{Agent Expressions}. Each byte of the expression is encoded as a
42166two-digit hex number in the packet; @var{len} is the number of bytes
42167in the expression (and thus one-half the number of hex digits in the
42168packet).
42169
42170@end table
42171
42172Any number of actions may be packed together in a single @samp{QTDP}
42173packet, as long as the packet does not exceed the maximum packet
c1947b85
JB
42174length (400 bytes, for many stubs). There may be only one @samp{R}
42175action per tracepoint, and it must precede any @samp{M} or @samp{X}
42176actions. Any registers referred to by @samp{M} and @samp{X} actions
42177must be collected by a preceding @samp{R} action. (The
42178``while-stepping'' actions are treated as if they were attached to a
42179separate tracepoint, as far as these restrictions are concerned.)
9d29849a
JB
42180
42181Replies:
42182@table @samp
42183@item OK
42184The packet was understood and carried out.
dde08ee1
PA
42185@item qRelocInsn
42186@xref{Tracepoint Packets,,Relocate instruction reply packet}.
d57350ea 42187@item @w{}
9d29849a
JB
42188The packet was not recognized.
42189@end table
42190
409873ef
SS
42191@item QTDPsrc:@var{n}:@var{addr}:@var{type}:@var{start}:@var{slen}:@var{bytes}
42192@cindex @samp{QTDPsrc} packet
42193Specify a source string of tracepoint @var{n} at address @var{addr}.
42194This is useful to get accurate reproduction of the tracepoints
697aa1b7 42195originally downloaded at the beginning of the trace run. The @var{type}
409873ef
SS
42196is the name of the tracepoint part, such as @samp{cond} for the
42197tracepoint's conditional expression (see below for a list of types), while
42198@var{bytes} is the string, encoded in hexadecimal.
42199
42200@var{start} is the offset of the @var{bytes} within the overall source
42201string, while @var{slen} is the total length of the source string.
42202This is intended for handling source strings that are longer than will
42203fit in a single packet.
42204@c Add detailed example when this info is moved into a dedicated
42205@c tracepoint descriptions section.
42206
42207The available string types are @samp{at} for the location,
42208@samp{cond} for the conditional, and @samp{cmd} for an action command.
42209@value{GDBN} sends a separate packet for each command in the action
42210list, in the same order in which the commands are stored in the list.
42211
42212The target does not need to do anything with source strings except
42213report them back as part of the replies to the @samp{qTfP}/@samp{qTsP}
42214query packets.
42215
42216Although this packet is optional, and @value{GDBN} will only send it
42217if the target replies with @samp{TracepointSource} @xref{General
42218Query Packets}, it makes both disconnected tracing and trace files
42219much easier to use. Otherwise the user must be careful that the
42220tracepoints in effect while looking at trace frames are identical to
42221the ones in effect during the trace run; even a small discrepancy
42222could cause @samp{tdump} not to work, or a particular trace frame not
42223be found.
42224
fa3f8d5a 42225@item QTDV:@var{n}:@var{value}:@var{builtin}:@var{name}
f61e138d
SS
42226@cindex define trace state variable, remote request
42227@cindex @samp{QTDV} packet
42228Create a new trace state variable, number @var{n}, with an initial
42229value of @var{value}, which is a 64-bit signed integer. Both @var{n}
42230and @var{value} are encoded as hexadecimal values. @value{GDBN} has
42231the option of not using this packet for initial values of zero; the
42232target should simply create the trace state variables as they are
fa3f8d5a
DT
42233mentioned in expressions. The value @var{builtin} should be 1 (one)
42234if the trace state variable is builtin and 0 (zero) if it is not builtin.
42235@value{GDBN} only sets @var{builtin} to 1 if a previous @samp{qTfV} or
42236@samp{qTsV} packet had it set. The contents of @var{name} is the
42237hex-encoded name (without the leading @samp{$}) of the trace state
42238variable.
f61e138d 42239
9d29849a 42240@item QTFrame:@var{n}
c614397c 42241@cindex @samp{QTFrame} packet
9d29849a
JB
42242Select the @var{n}'th tracepoint frame from the buffer, and use the
42243register and memory contents recorded there to answer subsequent
42244request packets from @value{GDBN}.
42245
42246A successful reply from the stub indicates that the stub has found the
42247requested frame. The response is a series of parts, concatenated
42248without separators, describing the frame we selected. Each part has
42249one of the following forms:
42250
42251@table @samp
42252@item F @var{f}
42253The selected frame is number @var{n} in the trace frame buffer;
599b237a 42254@var{f} is a hexadecimal number. If @var{f} is @samp{-1}, then there
9d29849a
JB
42255was no frame matching the criteria in the request packet.
42256
42257@item T @var{t}
42258The selected trace frame records a hit of tracepoint number @var{t};
599b237a 42259@var{t} is a hexadecimal number.
9d29849a
JB
42260
42261@end table
42262
42263@item QTFrame:pc:@var{addr}
42264Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
42265currently selected frame whose PC is @var{addr};
599b237a 42266@var{addr} is a hexadecimal number.
9d29849a
JB
42267
42268@item QTFrame:tdp:@var{t}
42269Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
42270currently selected frame that is a hit of tracepoint @var{t}; @var{t}
599b237a 42271is a hexadecimal number.
9d29849a
JB
42272
42273@item QTFrame:range:@var{start}:@var{end}
42274Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
42275currently selected frame whose PC is between @var{start} (inclusive)
081dfbf7 42276and @var{end} (inclusive); @var{start} and @var{end} are hexadecimal
9d29849a
JB
42277numbers.
42278
42279@item QTFrame:outside:@var{start}:@var{end}
42280Like @samp{QTFrame:range:@var{start}:@var{end}}, but select the first
081dfbf7 42281frame @emph{outside} the given range of addresses (exclusive).
9d29849a 42282
405f8e94 42283@item qTMinFTPILen
c614397c 42284@cindex @samp{qTMinFTPILen} packet
405f8e94
SS
42285This packet requests the minimum length of instruction at which a fast
42286tracepoint (@pxref{Set Tracepoints}) may be placed. For instance, on
42287the 32-bit x86 architecture, it is possible to use a 4-byte jump, but
42288it depends on the target system being able to create trampolines in
42289the first 64K of memory, which might or might not be possible for that
42290system. So the reply to this packet will be 4 if it is able to
42291arrange for that.
42292
42293Replies:
42294
42295@table @samp
42296@item 0
42297The minimum instruction length is currently unknown.
42298@item @var{length}
697aa1b7
EZ
42299The minimum instruction length is @var{length}, where @var{length}
42300is a hexadecimal number greater or equal to 1. A reply
42301of 1 means that a fast tracepoint may be placed on any instruction
42302regardless of size.
405f8e94
SS
42303@item E
42304An error has occurred.
d57350ea 42305@item @w{}
405f8e94
SS
42306An empty reply indicates that the request is not supported by the stub.
42307@end table
42308
9d29849a 42309@item QTStart
c614397c 42310@cindex @samp{QTStart} packet
dde08ee1
PA
42311Begin the tracepoint experiment. Begin collecting data from
42312tracepoint hits in the trace frame buffer. This packet supports the
42313@samp{qRelocInsn} reply (@pxref{Tracepoint Packets,,Relocate
42314instruction reply packet}).
9d29849a
JB
42315
42316@item QTStop
c614397c 42317@cindex @samp{QTStop} packet
9d29849a
JB
42318End the tracepoint experiment. Stop collecting trace frames.
42319
d248b706
KY
42320@item QTEnable:@var{n}:@var{addr}
42321@anchor{QTEnable}
c614397c 42322@cindex @samp{QTEnable} packet
d248b706
KY
42323Enable tracepoint @var{n} at address @var{addr} in a started tracepoint
42324experiment. If the tracepoint was previously disabled, then collection
42325of data from it will resume.
42326
42327@item QTDisable:@var{n}:@var{addr}
42328@anchor{QTDisable}
c614397c 42329@cindex @samp{QTDisable} packet
d248b706
KY
42330Disable tracepoint @var{n} at address @var{addr} in a started tracepoint
42331experiment. No more data will be collected from the tracepoint unless
42332@samp{QTEnable:@var{n}:@var{addr}} is subsequently issued.
42333
9d29849a 42334@item QTinit
c614397c 42335@cindex @samp{QTinit} packet
9d29849a
JB
42336Clear the table of tracepoints, and empty the trace frame buffer.
42337
42338@item QTro:@var{start1},@var{end1}:@var{start2},@var{end2}:@dots{}
c614397c 42339@cindex @samp{QTro} packet
9d29849a
JB
42340Establish the given ranges of memory as ``transparent''. The stub
42341will answer requests for these ranges from memory's current contents,
42342if they were not collected as part of the tracepoint hit.
42343
42344@value{GDBN} uses this to mark read-only regions of memory, like those
42345containing program code. Since these areas never change, they should
42346still have the same contents they did when the tracepoint was hit, so
42347there's no reason for the stub to refuse to provide their contents.
42348
d5551862 42349@item QTDisconnected:@var{value}
c614397c 42350@cindex @samp{QTDisconnected} packet
d5551862
SS
42351Set the choice to what to do with the tracing run when @value{GDBN}
42352disconnects from the target. A @var{value} of 1 directs the target to
42353continue the tracing run, while 0 tells the target to stop tracing if
42354@value{GDBN} is no longer in the picture.
42355
9d29849a 42356@item qTStatus
c614397c 42357@cindex @samp{qTStatus} packet
9d29849a
JB
42358Ask the stub if there is a trace experiment running right now.
42359
4daf5ac0
SS
42360The reply has the form:
42361
42362@table @samp
42363
42364@item T@var{running}@r{[};@var{field}@r{]}@dots{}
42365@var{running} is a single digit @code{1} if the trace is presently
42366running, or @code{0} if not. It is followed by semicolon-separated
42367optional fields that an agent may use to report additional status.
42368
42369@end table
42370
42371If the trace is not running, the agent may report any of several
42372explanations as one of the optional fields:
42373
42374@table @samp
42375
42376@item tnotrun:0
42377No trace has been run yet.
42378
f196051f
SS
42379@item tstop[:@var{text}]:0
42380The trace was stopped by a user-originated stop command. The optional
42381@var{text} field is a user-supplied string supplied as part of the
42382stop command (for instance, an explanation of why the trace was
42383stopped manually). It is hex-encoded.
4daf5ac0
SS
42384
42385@item tfull:0
42386The trace stopped because the trace buffer filled up.
42387
42388@item tdisconnected:0
42389The trace stopped because @value{GDBN} disconnected from the target.
42390
42391@item tpasscount:@var{tpnum}
42392The trace stopped because tracepoint @var{tpnum} exceeded its pass count.
42393
6c28cbf2
SS
42394@item terror:@var{text}:@var{tpnum}
42395The trace stopped because tracepoint @var{tpnum} had an error. The
42396string @var{text} is available to describe the nature of the error
697aa1b7
EZ
42397(for instance, a divide by zero in the condition expression); it
42398is hex encoded.
6c28cbf2 42399
4daf5ac0
SS
42400@item tunknown:0
42401The trace stopped for some other reason.
42402
42403@end table
42404
33da3f1c
SS
42405Additional optional fields supply statistical and other information.
42406Although not required, they are extremely useful for users monitoring
42407the progress of a trace run. If a trace has stopped, and these
42408numbers are reported, they must reflect the state of the just-stopped
42409trace.
4daf5ac0 42410
9d29849a 42411@table @samp
4daf5ac0
SS
42412
42413@item tframes:@var{n}
42414The number of trace frames in the buffer.
42415
42416@item tcreated:@var{n}
42417The total number of trace frames created during the run. This may
42418be larger than the trace frame count, if the buffer is circular.
42419
42420@item tsize:@var{n}
42421The total size of the trace buffer, in bytes.
42422
42423@item tfree:@var{n}
42424The number of bytes still unused in the buffer.
42425
33da3f1c
SS
42426@item circular:@var{n}
42427The value of the circular trace buffer flag. @code{1} means that the
42428trace buffer is circular and old trace frames will be discarded if
42429necessary to make room, @code{0} means that the trace buffer is linear
42430and may fill up.
42431
42432@item disconn:@var{n}
42433The value of the disconnected tracing flag. @code{1} means that
42434tracing will continue after @value{GDBN} disconnects, @code{0} means
42435that the trace run will stop.
42436
9d29849a
JB
42437@end table
42438
f196051f
SS
42439@item qTP:@var{tp}:@var{addr}
42440@cindex tracepoint status, remote request
42441@cindex @samp{qTP} packet
42442Ask the stub for the current state of tracepoint number @var{tp} at
42443address @var{addr}.
42444
42445Replies:
42446@table @samp
42447@item V@var{hits}:@var{usage}
42448The tracepoint has been hit @var{hits} times so far during the trace
42449run, and accounts for @var{usage} in the trace buffer. Note that
42450@code{while-stepping} steps are not counted as separate hits, but the
42451steps' space consumption is added into the usage number.
42452
42453@end table
42454
f61e138d
SS
42455@item qTV:@var{var}
42456@cindex trace state variable value, remote request
42457@cindex @samp{qTV} packet
42458Ask the stub for the value of the trace state variable number @var{var}.
42459
42460Replies:
42461@table @samp
42462@item V@var{value}
42463The value of the variable is @var{value}. This will be the current
42464value of the variable if the user is examining a running target, or a
42465saved value if the variable was collected in the trace frame that the
42466user is looking at. Note that multiple requests may result in
42467different reply values, such as when requesting values while the
42468program is running.
42469
42470@item U
42471The value of the variable is unknown. This would occur, for example,
42472if the user is examining a trace frame in which the requested variable
42473was not collected.
9d29849a
JB
42474@end table
42475
d5551862 42476@item qTfP
c614397c 42477@cindex @samp{qTfP} packet
d5551862 42478@itemx qTsP
c614397c 42479@cindex @samp{qTsP} packet
d5551862
SS
42480These packets request data about tracepoints that are being used by
42481the target. @value{GDBN} sends @code{qTfP} to get the first piece
42482of data, and multiple @code{qTsP} to get additional pieces. Replies
42483to these packets generally take the form of the @code{QTDP} packets
42484that define tracepoints. (FIXME add detailed syntax)
42485
00bf0b85 42486@item qTfV
c614397c 42487@cindex @samp{qTfV} packet
00bf0b85 42488@itemx qTsV
c614397c 42489@cindex @samp{qTsV} packet
00bf0b85
SS
42490These packets request data about trace state variables that are on the
42491target. @value{GDBN} sends @code{qTfV} to get the first vari of data,
42492and multiple @code{qTsV} to get additional variables. Replies to
42493these packets follow the syntax of the @code{QTDV} packets that define
42494trace state variables.
42495
0fb4aa4b
PA
42496@item qTfSTM
42497@itemx qTsSTM
16bdd41f
YQ
42498@anchor{qTfSTM}
42499@anchor{qTsSTM}
c614397c
YQ
42500@cindex @samp{qTfSTM} packet
42501@cindex @samp{qTsSTM} packet
0fb4aa4b
PA
42502These packets request data about static tracepoint markers that exist
42503in the target program. @value{GDBN} sends @code{qTfSTM} to get the
42504first piece of data, and multiple @code{qTsSTM} to get additional
42505pieces. Replies to these packets take the following form:
42506
42507Reply:
42508@table @samp
42509@item m @var{address}:@var{id}:@var{extra}
42510A single marker
42511@item m @var{address}:@var{id}:@var{extra},@var{address}:@var{id}:@var{extra}@dots{}
42512a comma-separated list of markers
42513@item l
42514(lower case letter @samp{L}) denotes end of list.
42515@item E @var{nn}
697aa1b7 42516An error occurred. The error number @var{nn} is given as hex digits.
d57350ea 42517@item @w{}
0fb4aa4b
PA
42518An empty reply indicates that the request is not supported by the
42519stub.
42520@end table
42521
697aa1b7 42522The @var{address} is encoded in hex;
0fb4aa4b
PA
42523@var{id} and @var{extra} are strings encoded in hex.
42524
42525In response to each query, the target will reply with a list of one or
42526more markers, separated by commas. @value{GDBN} will respond to each
42527reply with a request for more markers (using the @samp{qs} form of the
42528query), until the target responds with @samp{l} (lower-case ell, for
42529@dfn{last}).
42530
42531@item qTSTMat:@var{address}
16bdd41f 42532@anchor{qTSTMat}
c614397c 42533@cindex @samp{qTSTMat} packet
0fb4aa4b
PA
42534This packets requests data about static tracepoint markers in the
42535target program at @var{address}. Replies to this packet follow the
42536syntax of the @samp{qTfSTM} and @code{qTsSTM} packets that list static
42537tracepoint markers.
42538
00bf0b85 42539@item QTSave:@var{filename}
c614397c 42540@cindex @samp{QTSave} packet
00bf0b85 42541This packet directs the target to save trace data to the file name
697aa1b7 42542@var{filename} in the target's filesystem. The @var{filename} is encoded
00bf0b85
SS
42543as a hex string; the interpretation of the file name (relative vs
42544absolute, wild cards, etc) is up to the target.
42545
42546@item qTBuffer:@var{offset},@var{len}
c614397c 42547@cindex @samp{qTBuffer} packet
00bf0b85
SS
42548Return up to @var{len} bytes of the current contents of trace buffer,
42549starting at @var{offset}. The trace buffer is treated as if it were
42550a contiguous collection of traceframes, as per the trace file format.
42551The reply consists as many hex-encoded bytes as the target can deliver
42552in a packet; it is not an error to return fewer than were asked for.
42553A reply consisting of just @code{l} indicates that no bytes are
42554available.
42555
4daf5ac0
SS
42556@item QTBuffer:circular:@var{value}
42557This packet directs the target to use a circular trace buffer if
42558@var{value} is 1, or a linear buffer if the value is 0.
42559
f6f899bf 42560@item QTBuffer:size:@var{size}
28abe188
EZ
42561@anchor{QTBuffer-size}
42562@cindex @samp{QTBuffer size} packet
f6f899bf
HAQ
42563This packet directs the target to make the trace buffer be of size
42564@var{size} if possible. A value of @code{-1} tells the target to
42565use whatever size it prefers.
42566
f196051f 42567@item QTNotes:@r{[}@var{type}:@var{text}@r{]}@r{[};@var{type}:@var{text}@r{]}@dots{}
c614397c 42568@cindex @samp{QTNotes} packet
f196051f
SS
42569This packet adds optional textual notes to the trace run. Allowable
42570types include @code{user}, @code{notes}, and @code{tstop}, the
42571@var{text} fields are arbitrary strings, hex-encoded.
42572
f61e138d 42573@end table
9d29849a 42574
dde08ee1
PA
42575@subsection Relocate instruction reply packet
42576When installing fast tracepoints in memory, the target may need to
42577relocate the instruction currently at the tracepoint address to a
42578different address in memory. For most instructions, a simple copy is
42579enough, but, for example, call instructions that implicitly push the
42580return address on the stack, and relative branches or other
42581PC-relative instructions require offset adjustment, so that the effect
42582of executing the instruction at a different address is the same as if
42583it had executed in the original location.
42584
42585In response to several of the tracepoint packets, the target may also
42586respond with a number of intermediate @samp{qRelocInsn} request
42587packets before the final result packet, to have @value{GDBN} handle
42588this relocation operation. If a packet supports this mechanism, its
42589documentation will explicitly say so. See for example the above
42590descriptions for the @samp{QTStart} and @samp{QTDP} packets. The
42591format of the request is:
42592
42593@table @samp
42594@item qRelocInsn:@var{from};@var{to}
42595
42596This requests @value{GDBN} to copy instruction at address @var{from}
42597to address @var{to}, possibly adjusted so that executing the
42598instruction at @var{to} has the same effect as executing it at
42599@var{from}. @value{GDBN} writes the adjusted instruction to target
42600memory starting at @var{to}.
42601@end table
42602
42603Replies:
42604@table @samp
42605@item qRelocInsn:@var{adjusted_size}
697aa1b7 42606Informs the stub the relocation is complete. The @var{adjusted_size} is
dde08ee1
PA
42607the length in bytes of resulting relocated instruction sequence.
42608@item E @var{NN}
42609A badly formed request was detected, or an error was encountered while
42610relocating the instruction.
42611@end table
42612
a6b151f1
DJ
42613@node Host I/O Packets
42614@section Host I/O Packets
42615@cindex Host I/O, remote protocol
42616@cindex file transfer, remote protocol
42617
42618The @dfn{Host I/O} packets allow @value{GDBN} to perform I/O
42619operations on the far side of a remote link. For example, Host I/O is
42620used to upload and download files to a remote target with its own
42621filesystem. Host I/O uses the same constant values and data structure
42622layout as the target-initiated File-I/O protocol. However, the
42623Host I/O packets are structured differently. The target-initiated
42624protocol relies on target memory to store parameters and buffers.
42625Host I/O requests are initiated by @value{GDBN}, and the
42626target's memory is not involved. @xref{File-I/O Remote Protocol
42627Extension}, for more details on the target-initiated protocol.
42628
42629The Host I/O request packets all encode a single operation along with
42630its arguments. They have this format:
42631
42632@table @samp
42633
42634@item vFile:@var{operation}: @var{parameter}@dots{}
42635@var{operation} is the name of the particular request; the target
42636should compare the entire packet name up to the second colon when checking
42637for a supported operation. The format of @var{parameter} depends on
42638the operation. Numbers are always passed in hexadecimal. Negative
42639numbers have an explicit minus sign (i.e.@: two's complement is not
42640used). Strings (e.g.@: filenames) are encoded as a series of
42641hexadecimal bytes. The last argument to a system call may be a
42642buffer of escaped binary data (@pxref{Binary Data}).
42643
42644@end table
42645
42646The valid responses to Host I/O packets are:
42647
42648@table @samp
42649
42650@item F @var{result} [, @var{errno}] [; @var{attachment}]
42651@var{result} is the integer value returned by this operation, usually
42652non-negative for success and -1 for errors. If an error has occured,
697aa1b7 42653@var{errno} will be included in the result specifying a
a6b151f1
DJ
42654value defined by the File-I/O protocol (@pxref{Errno Values}). For
42655operations which return data, @var{attachment} supplies the data as a
42656binary buffer. Binary buffers in response packets are escaped in the
42657normal way (@pxref{Binary Data}). See the individual packet
42658documentation for the interpretation of @var{result} and
42659@var{attachment}.
42660
d57350ea 42661@item @w{}
a6b151f1
DJ
42662An empty response indicates that this operation is not recognized.
42663
42664@end table
42665
42666These are the supported Host I/O operations:
42667
42668@table @samp
697aa1b7
EZ
42669@item vFile:open: @var{filename}, @var{flags}, @var{mode}
42670Open a file at @var{filename} and return a file descriptor for it, or
42671return -1 if an error occurs. The @var{filename} is a string,
a6b151f1
DJ
42672@var{flags} is an integer indicating a mask of open flags
42673(@pxref{Open Flags}), and @var{mode} is an integer indicating a mask
42674of mode bits to use if the file is created (@pxref{mode_t Values}).
c1c25a1a 42675@xref{open}, for details of the open flags and mode values.
a6b151f1
DJ
42676
42677@item vFile:close: @var{fd}
42678Close the open file corresponding to @var{fd} and return 0, or
42679-1 if an error occurs.
42680
42681@item vFile:pread: @var{fd}, @var{count}, @var{offset}
42682Read data from the open file corresponding to @var{fd}. Up to
42683@var{count} bytes will be read from the file, starting at @var{offset}
42684relative to the start of the file. The target may read fewer bytes;
42685common reasons include packet size limits and an end-of-file
42686condition. The number of bytes read is returned. Zero should only be
42687returned for a successful read at the end of the file, or if
42688@var{count} was zero.
42689
42690The data read should be returned as a binary attachment on success.
42691If zero bytes were read, the response should include an empty binary
42692attachment (i.e.@: a trailing semicolon). The return value is the
42693number of target bytes read; the binary attachment may be longer if
42694some characters were escaped.
42695
42696@item vFile:pwrite: @var{fd}, @var{offset}, @var{data}
42697Write @var{data} (a binary buffer) to the open file corresponding
42698to @var{fd}. Start the write at @var{offset} from the start of the
42699file. Unlike many @code{write} system calls, there is no
42700separate @var{count} argument; the length of @var{data} in the
fb092e09 42701packet is used. @samp{vFile:pwrite} returns the number of bytes written,
a6b151f1
DJ
42702which may be shorter than the length of @var{data}, or -1 if an
42703error occurred.
42704
0a93529c
GB
42705@item vFile:fstat: @var{fd}
42706Get information about the open file corresponding to @var{fd}.
42707On success the information is returned as a binary attachment
42708and the return value is the size of this attachment in bytes.
42709If an error occurs the return value is -1. The format of the
42710returned binary attachment is as described in @ref{struct stat}.
42711
697aa1b7
EZ
42712@item vFile:unlink: @var{filename}
42713Delete the file at @var{filename} on the target. Return 0,
42714or -1 if an error occurs. The @var{filename} is a string.
a6b151f1 42715
b9e7b9c3
UW
42716@item vFile:readlink: @var{filename}
42717Read value of symbolic link @var{filename} on the target. Return
42718the number of bytes read, or -1 if an error occurs.
42719
42720The data read should be returned as a binary attachment on success.
42721If zero bytes were read, the response should include an empty binary
42722attachment (i.e.@: a trailing semicolon). The return value is the
42723number of target bytes read; the binary attachment may be longer if
42724some characters were escaped.
42725
15a201c8
GB
42726@item vFile:setfs: @var{pid}
42727Select the filesystem on which @code{vFile} operations with
42728@var{filename} arguments will operate. This is required for
42729@value{GDBN} to be able to access files on remote targets where
42730the remote stub does not share a common filesystem with the
42731inferior(s).
42732
42733If @var{pid} is nonzero, select the filesystem as seen by process
42734@var{pid}. If @var{pid} is zero, select the filesystem as seen by
42735the remote stub. Return 0 on success, or -1 if an error occurs.
42736If @code{vFile:setfs:} indicates success, the selected filesystem
42737remains selected until the next successful @code{vFile:setfs:}
42738operation.
42739
a6b151f1
DJ
42740@end table
42741
9a6253be
KB
42742@node Interrupts
42743@section Interrupts
42744@cindex interrupts (remote protocol)
de979965 42745@anchor{interrupting remote targets}
9a6253be 42746
de979965
PA
42747In all-stop mode, when a program on the remote target is running,
42748@value{GDBN} may attempt to interrupt it by sending a @samp{Ctrl-C},
42749@code{BREAK} or a @code{BREAK} followed by @code{g}, control of which
42750is specified via @value{GDBN}'s @samp{interrupt-sequence}.
9a6253be
KB
42751
42752The precise meaning of @code{BREAK} is defined by the transport
8775bb90
MS
42753mechanism and may, in fact, be undefined. @value{GDBN} does not
42754currently define a @code{BREAK} mechanism for any of the network
42755interfaces except for TCP, in which case @value{GDBN} sends the
42756@code{telnet} BREAK sequence.
9a6253be
KB
42757
42758@samp{Ctrl-C}, on the other hand, is defined and implemented for all
42759transport mechanisms. It is represented by sending the single byte
42760@code{0x03} without any of the usual packet overhead described in
42761the Overview section (@pxref{Overview}). When a @code{0x03} byte is
42762transmitted as part of a packet, it is considered to be packet data
42763and does @emph{not} represent an interrupt. E.g., an @samp{X} packet
0876f84a 42764(@pxref{X packet}), used for binary downloads, may include an unescaped
9a6253be
KB
42765@code{0x03} as part of its packet.
42766
9a7071a8
JB
42767@code{BREAK} followed by @code{g} is also known as Magic SysRq g.
42768When Linux kernel receives this sequence from serial port,
42769it stops execution and connects to gdb.
42770
de979965
PA
42771In non-stop mode, because packet resumptions are asynchronous
42772(@pxref{vCont packet}), @value{GDBN} is always free to send a remote
42773command to the remote stub, even when the target is running. For that
42774reason, @value{GDBN} instead sends a regular packet (@pxref{vCtrlC
42775packet}) with the usual packet framing instead of the single byte
42776@code{0x03}.
42777
9a6253be
KB
42778Stubs are not required to recognize these interrupt mechanisms and the
42779precise meaning associated with receipt of the interrupt is
8b23ecc4
SL
42780implementation defined. If the target supports debugging of multiple
42781threads and/or processes, it should attempt to interrupt all
42782currently-executing threads and processes.
42783If the stub is successful at interrupting the
42784running program, it should send one of the stop
42785reply packets (@pxref{Stop Reply Packets}) to @value{GDBN} as a result
42786of successfully stopping the program in all-stop mode, and a stop reply
42787for each stopped thread in non-stop mode.
42788Interrupts received while the
cde67b27
YQ
42789program is stopped are queued and the program will be interrupted when
42790it is resumed next time.
8b23ecc4
SL
42791
42792@node Notification Packets
42793@section Notification Packets
42794@cindex notification packets
42795@cindex packets, notification
42796
42797The @value{GDBN} remote serial protocol includes @dfn{notifications},
42798packets that require no acknowledgment. Both the GDB and the stub
42799may send notifications (although the only notifications defined at
42800present are sent by the stub). Notifications carry information
42801without incurring the round-trip latency of an acknowledgment, and so
42802are useful for low-impact communications where occasional packet loss
42803is not a problem.
42804
42805A notification packet has the form @samp{% @var{data} #
42806@var{checksum}}, where @var{data} is the content of the notification,
42807and @var{checksum} is a checksum of @var{data}, computed and formatted
42808as for ordinary @value{GDBN} packets. A notification's @var{data}
42809never contains @samp{$}, @samp{%} or @samp{#} characters. Upon
42810receiving a notification, the recipient sends no @samp{+} or @samp{-}
42811to acknowledge the notification's receipt or to report its corruption.
42812
42813Every notification's @var{data} begins with a name, which contains no
42814colon characters, followed by a colon character.
42815
42816Recipients should silently ignore corrupted notifications and
42817notifications they do not understand. Recipients should restart
42818timeout periods on receipt of a well-formed notification, whether or
42819not they understand it.
42820
42821Senders should only send the notifications described here when this
42822protocol description specifies that they are permitted. In the
42823future, we may extend the protocol to permit existing notifications in
42824new contexts; this rule helps older senders avoid confusing newer
42825recipients.
42826
42827(Older versions of @value{GDBN} ignore bytes received until they see
42828the @samp{$} byte that begins an ordinary packet, so new stubs may
42829transmit notifications without fear of confusing older clients. There
42830are no notifications defined for @value{GDBN} to send at the moment, but we
42831assume that most older stubs would ignore them, as well.)
42832
8dbe8ece 42833Each notification is comprised of three parts:
8b23ecc4 42834@table @samp
8dbe8ece
YQ
42835@item @var{name}:@var{event}
42836The notification packet is sent by the side that initiates the
42837exchange (currently, only the stub does that), with @var{event}
697aa1b7
EZ
42838carrying the specific information about the notification, and
42839@var{name} specifying the name of the notification.
8dbe8ece
YQ
42840@item @var{ack}
42841The acknowledge sent by the other side, usually @value{GDBN}, to
42842acknowledge the exchange and request the event.
42843@end table
42844
42845The purpose of an asynchronous notification mechanism is to report to
42846@value{GDBN} that something interesting happened in the remote stub.
42847
42848The remote stub may send notification @var{name}:@var{event}
42849at any time, but @value{GDBN} acknowledges the notification when
42850appropriate. The notification event is pending before @value{GDBN}
42851acknowledges. Only one notification at a time may be pending; if
42852additional events occur before @value{GDBN} has acknowledged the
42853previous notification, they must be queued by the stub for later
42854synchronous transmission in response to @var{ack} packets from
42855@value{GDBN}. Because the notification mechanism is unreliable,
42856the stub is permitted to resend a notification if it believes
42857@value{GDBN} may not have received it.
42858
42859Specifically, notifications may appear when @value{GDBN} is not
42860otherwise reading input from the stub, or when @value{GDBN} is
42861expecting to read a normal synchronous response or a
42862@samp{+}/@samp{-} acknowledgment to a packet it has sent.
42863Notification packets are distinct from any other communication from
42864the stub so there is no ambiguity.
42865
42866After receiving a notification, @value{GDBN} shall acknowledge it by
42867sending a @var{ack} packet as a regular, synchronous request to the
42868stub. Such acknowledgment is not required to happen immediately, as
42869@value{GDBN} is permitted to send other, unrelated packets to the
42870stub first, which the stub should process normally.
42871
42872Upon receiving a @var{ack} packet, if the stub has other queued
42873events to report to @value{GDBN}, it shall respond by sending a
42874normal @var{event}. @value{GDBN} shall then send another @var{ack}
42875packet to solicit further responses; again, it is permitted to send
42876other, unrelated packets as well which the stub should process
42877normally.
42878
42879If the stub receives a @var{ack} packet and there are no additional
42880@var{event} to report, the stub shall return an @samp{OK} response.
42881At this point, @value{GDBN} has finished processing a notification
42882and the stub has completed sending any queued events. @value{GDBN}
42883won't accept any new notifications until the final @samp{OK} is
42884received . If further notification events occur, the stub shall send
42885a new notification, @value{GDBN} shall accept the notification, and
42886the process shall be repeated.
42887
42888The process of asynchronous notification can be illustrated by the
42889following example:
42890@smallexample
4435e1cc 42891<- @code{%Stop:T0505:98e7ffbf;04:4ce6ffbf;08:b1b6e54c;thread:p7526.7526;core:0;}
8dbe8ece
YQ
42892@code{...}
42893-> @code{vStopped}
42894<- @code{T0505:68f37db7;04:40f37db7;08:63850408;thread:p7526.7528;core:0;}
42895-> @code{vStopped}
42896<- @code{T0505:68e3fdb6;04:40e3fdb6;08:63850408;thread:p7526.7529;core:0;}
42897-> @code{vStopped}
42898<- @code{OK}
42899@end smallexample
42900
42901The following notifications are defined:
42902@multitable @columnfractions 0.12 0.12 0.38 0.38
42903
42904@item Notification
42905@tab Ack
42906@tab Event
42907@tab Description
42908
42909@item Stop
42910@tab vStopped
42911@tab @var{reply}. The @var{reply} has the form of a stop reply, as
8b23ecc4
SL
42912described in @ref{Stop Reply Packets}. Refer to @ref{Remote Non-Stop},
42913for information on how these notifications are acknowledged by
42914@value{GDBN}.
8dbe8ece
YQ
42915@tab Report an asynchronous stop event in non-stop mode.
42916
42917@end multitable
8b23ecc4
SL
42918
42919@node Remote Non-Stop
42920@section Remote Protocol Support for Non-Stop Mode
42921
42922@value{GDBN}'s remote protocol supports non-stop debugging of
42923multi-threaded programs, as described in @ref{Non-Stop Mode}. If the stub
42924supports non-stop mode, it should report that to @value{GDBN} by including
42925@samp{QNonStop+} in its @samp{qSupported} response (@pxref{qSupported}).
42926
42927@value{GDBN} typically sends a @samp{QNonStop} packet only when
42928establishing a new connection with the stub. Entering non-stop mode
42929does not alter the state of any currently-running threads, but targets
42930must stop all threads in any already-attached processes when entering
42931all-stop mode. @value{GDBN} uses the @samp{?} packet as necessary to
42932probe the target state after a mode change.
42933
42934In non-stop mode, when an attached process encounters an event that
42935would otherwise be reported with a stop reply, it uses the
42936asynchronous notification mechanism (@pxref{Notification Packets}) to
42937inform @value{GDBN}. In contrast to all-stop mode, where all threads
42938in all processes are stopped when a stop reply is sent, in non-stop
42939mode only the thread reporting the stop event is stopped. That is,
42940when reporting a @samp{S} or @samp{T} response to indicate completion
42941of a step operation, hitting a breakpoint, or a fault, only the
42942affected thread is stopped; any other still-running threads continue
42943to run. When reporting a @samp{W} or @samp{X} response, all running
42944threads belonging to other attached processes continue to run.
42945
8b23ecc4
SL
42946In non-stop mode, the target shall respond to the @samp{?} packet as
42947follows. First, any incomplete stop reply notification/@samp{vStopped}
42948sequence in progress is abandoned. The target must begin a new
42949sequence reporting stop events for all stopped threads, whether or not
42950it has previously reported those events to @value{GDBN}. The first
42951stop reply is sent as a synchronous reply to the @samp{?} packet, and
42952subsequent stop replies are sent as responses to @samp{vStopped} packets
42953using the mechanism described above. The target must not send
42954asynchronous stop reply notifications until the sequence is complete.
42955If all threads are running when the target receives the @samp{?} packet,
42956or if the target is not attached to any process, it shall respond
42957@samp{OK}.
9a6253be 42958
f7e6eed5
PA
42959If the stub supports non-stop mode, it should also support the
42960@samp{swbreak} stop reason if software breakpoints are supported, and
42961the @samp{hwbreak} stop reason if hardware breakpoints are supported
42962(@pxref{swbreak stop reason}). This is because given the asynchronous
42963nature of non-stop mode, between the time a thread hits a breakpoint
42964and the time the event is finally processed by @value{GDBN}, the
42965breakpoint may have already been removed from the target. Due to
42966this, @value{GDBN} needs to be able to tell whether a trap stop was
42967caused by a delayed breakpoint event, which should be ignored, as
42968opposed to a random trap signal, which should be reported to the user.
42969Note the @samp{swbreak} feature implies that the target is responsible
42970for adjusting the PC when a software breakpoint triggers, if
42971necessary, such as on the x86 architecture.
42972
a6f3e723
SL
42973@node Packet Acknowledgment
42974@section Packet Acknowledgment
42975
42976@cindex acknowledgment, for @value{GDBN} remote
42977@cindex packet acknowledgment, for @value{GDBN} remote
42978By default, when either the host or the target machine receives a packet,
42979the first response expected is an acknowledgment: either @samp{+} (to indicate
42980the package was received correctly) or @samp{-} (to request retransmission).
42981This mechanism allows the @value{GDBN} remote protocol to operate over
42982unreliable transport mechanisms, such as a serial line.
42983
42984In cases where the transport mechanism is itself reliable (such as a pipe or
42985TCP connection), the @samp{+}/@samp{-} acknowledgments are redundant.
42986It may be desirable to disable them in that case to reduce communication
42987overhead, or for other reasons. This can be accomplished by means of the
42988@samp{QStartNoAckMode} packet; @pxref{QStartNoAckMode}.
42989
42990When in no-acknowledgment mode, neither the stub nor @value{GDBN} shall send or
42991expect @samp{+}/@samp{-} protocol acknowledgments. The packet
42992and response format still includes the normal checksum, as described in
42993@ref{Overview}, but the checksum may be ignored by the receiver.
42994
42995If the stub supports @samp{QStartNoAckMode} and prefers to operate in
42996no-acknowledgment mode, it should report that to @value{GDBN}
42997by including @samp{QStartNoAckMode+} in its response to @samp{qSupported};
42998@pxref{qSupported}.
42999If @value{GDBN} also supports @samp{QStartNoAckMode} and it has not been
43000disabled via the @code{set remote noack-packet off} command
43001(@pxref{Remote Configuration}),
43002@value{GDBN} may then send a @samp{QStartNoAckMode} packet to the stub.
43003Only then may the stub actually turn off packet acknowledgments.
43004@value{GDBN} sends a final @samp{+} acknowledgment of the stub's @samp{OK}
43005response, which can be safely ignored by the stub.
43006
43007Note that @code{set remote noack-packet} command only affects negotiation
43008between @value{GDBN} and the stub when subsequent connections are made;
43009it does not affect the protocol acknowledgment state for any current
43010connection.
43011Since @samp{+}/@samp{-} acknowledgments are enabled by default when a
43012new connection is established,
43013there is also no protocol request to re-enable the acknowledgments
43014for the current connection, once disabled.
43015
ee2d5c50
AC
43016@node Examples
43017@section Examples
eb12ee30 43018
8e04817f
AC
43019Example sequence of a target being re-started. Notice how the restart
43020does not get any direct output:
eb12ee30 43021
474c8240 43022@smallexample
d2c6833e
AC
43023-> @code{R00}
43024<- @code{+}
8e04817f 43025@emph{target restarts}
d2c6833e 43026-> @code{?}
8e04817f 43027<- @code{+}
d2c6833e
AC
43028<- @code{T001:1234123412341234}
43029-> @code{+}
474c8240 43030@end smallexample
eb12ee30 43031
8e04817f 43032Example sequence of a target being stepped by a single instruction:
eb12ee30 43033
474c8240 43034@smallexample
d2c6833e 43035-> @code{G1445@dots{}}
8e04817f 43036<- @code{+}
d2c6833e
AC
43037-> @code{s}
43038<- @code{+}
43039@emph{time passes}
43040<- @code{T001:1234123412341234}
8e04817f 43041-> @code{+}
d2c6833e 43042-> @code{g}
8e04817f 43043<- @code{+}
d2c6833e
AC
43044<- @code{1455@dots{}}
43045-> @code{+}
474c8240 43046@end smallexample
eb12ee30 43047
79a6e687
BW
43048@node File-I/O Remote Protocol Extension
43049@section File-I/O Remote Protocol Extension
0ce1b118
CV
43050@cindex File-I/O remote protocol extension
43051
43052@menu
43053* File-I/O Overview::
79a6e687
BW
43054* Protocol Basics::
43055* The F Request Packet::
43056* The F Reply Packet::
43057* The Ctrl-C Message::
0ce1b118 43058* Console I/O::
79a6e687 43059* List of Supported Calls::
db2e3e2e 43060* Protocol-specific Representation of Datatypes::
0ce1b118
CV
43061* Constants::
43062* File-I/O Examples::
43063@end menu
43064
43065@node File-I/O Overview
43066@subsection File-I/O Overview
43067@cindex file-i/o overview
43068
9c16f35a 43069The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
fc320d37 43070target to use the host's file system and console I/O to perform various
0ce1b118 43071system calls. System calls on the target system are translated into a
fc320d37
SL
43072remote protocol packet to the host system, which then performs the needed
43073actions and returns a response packet to the target system.
0ce1b118
CV
43074This simulates file system operations even on targets that lack file systems.
43075
fc320d37
SL
43076The protocol is defined to be independent of both the host and target systems.
43077It uses its own internal representation of datatypes and values. Both
0ce1b118 43078@value{GDBN} and the target's @value{GDBN} stub are responsible for
fc320d37
SL
43079translating the system-dependent value representations into the internal
43080protocol representations when data is transmitted.
0ce1b118 43081
fc320d37
SL
43082The communication is synchronous. A system call is possible only when
43083@value{GDBN} is waiting for a response from the @samp{C}, @samp{c}, @samp{S}
43084or @samp{s} packets. While @value{GDBN} handles the request for a system call,
0ce1b118 43085the target is stopped to allow deterministic access to the target's
fc320d37
SL
43086memory. Therefore File-I/O is not interruptible by target signals. On
43087the other hand, it is possible to interrupt File-I/O by a user interrupt
c8aa23ab 43088(@samp{Ctrl-C}) within @value{GDBN}.
0ce1b118
CV
43089
43090The target's request to perform a host system call does not finish
43091the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
43092after finishing the system call, the target returns to continuing the
43093previous activity (continue, step). No additional continue or step
43094request from @value{GDBN} is required.
43095
43096@smallexample
f7dc1244 43097(@value{GDBP}) continue
0ce1b118
CV
43098 <- target requests 'system call X'
43099 target is stopped, @value{GDBN} executes system call
3f94c067
BW
43100 -> @value{GDBN} returns result
43101 ... target continues, @value{GDBN} returns to wait for the target
0ce1b118
CV
43102 <- target hits breakpoint and sends a Txx packet
43103@end smallexample
43104
fc320d37
SL
43105The protocol only supports I/O on the console and to regular files on
43106the host file system. Character or block special devices, pipes,
43107named pipes, sockets or any other communication method on the host
0ce1b118
CV
43108system are not supported by this protocol.
43109
8b23ecc4
SL
43110File I/O is not supported in non-stop mode.
43111
79a6e687
BW
43112@node Protocol Basics
43113@subsection Protocol Basics
0ce1b118
CV
43114@cindex protocol basics, file-i/o
43115
fc320d37
SL
43116The File-I/O protocol uses the @code{F} packet as the request as well
43117as reply packet. Since a File-I/O system call can only occur when
43118@value{GDBN} is waiting for a response from the continuing or stepping target,
43119the File-I/O request is a reply that @value{GDBN} has to expect as a result
43120of a previous @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
0ce1b118
CV
43121This @code{F} packet contains all information needed to allow @value{GDBN}
43122to call the appropriate host system call:
43123
43124@itemize @bullet
b383017d 43125@item
0ce1b118
CV
43126A unique identifier for the requested system call.
43127
43128@item
43129All parameters to the system call. Pointers are given as addresses
43130in the target memory address space. Pointers to strings are given as
b383017d 43131pointer/length pair. Numerical values are given as they are.
db2e3e2e 43132Numerical control flags are given in a protocol-specific representation.
0ce1b118
CV
43133
43134@end itemize
43135
fc320d37 43136At this point, @value{GDBN} has to perform the following actions.
0ce1b118
CV
43137
43138@itemize @bullet
b383017d 43139@item
fc320d37
SL
43140If the parameters include pointer values to data needed as input to a
43141system call, @value{GDBN} requests this data from the target with a
0ce1b118
CV
43142standard @code{m} packet request. This additional communication has to be
43143expected by the target implementation and is handled as any other @code{m}
43144packet.
43145
43146@item
43147@value{GDBN} translates all value from protocol representation to host
43148representation as needed. Datatypes are coerced into the host types.
43149
43150@item
fc320d37 43151@value{GDBN} calls the system call.
0ce1b118
CV
43152
43153@item
43154It then coerces datatypes back to protocol representation.
43155
43156@item
fc320d37
SL
43157If the system call is expected to return data in buffer space specified
43158by pointer parameters to the call, the data is transmitted to the
0ce1b118
CV
43159target using a @code{M} or @code{X} packet. This packet has to be expected
43160by the target implementation and is handled as any other @code{M} or @code{X}
43161packet.
43162
43163@end itemize
43164
43165Eventually @value{GDBN} replies with another @code{F} packet which contains all
43166necessary information for the target to continue. This at least contains
43167
43168@itemize @bullet
43169@item
43170Return value.
43171
43172@item
43173@code{errno}, if has been changed by the system call.
43174
43175@item
43176``Ctrl-C'' flag.
43177
43178@end itemize
43179
43180After having done the needed type and value coercion, the target continues
43181the latest continue or step action.
43182
79a6e687
BW
43183@node The F Request Packet
43184@subsection The @code{F} Request Packet
0ce1b118
CV
43185@cindex file-i/o request packet
43186@cindex @code{F} request packet
43187
43188The @code{F} request packet has the following format:
43189
43190@table @samp
fc320d37 43191@item F@var{call-id},@var{parameter@dots{}}
0ce1b118
CV
43192
43193@var{call-id} is the identifier to indicate the host system call to be called.
43194This is just the name of the function.
43195
fc320d37
SL
43196@var{parameter@dots{}} are the parameters to the system call.
43197Parameters are hexadecimal integer values, either the actual values in case
43198of scalar datatypes, pointers to target buffer space in case of compound
43199datatypes and unspecified memory areas, or pointer/length pairs in case
43200of string parameters. These are appended to the @var{call-id} as a
43201comma-delimited list. All values are transmitted in ASCII
43202string representation, pointer/length pairs separated by a slash.
0ce1b118 43203
b383017d 43204@end table
0ce1b118 43205
fc320d37 43206
0ce1b118 43207
79a6e687
BW
43208@node The F Reply Packet
43209@subsection The @code{F} Reply Packet
0ce1b118
CV
43210@cindex file-i/o reply packet
43211@cindex @code{F} reply packet
43212
43213The @code{F} reply packet has the following format:
43214
43215@table @samp
43216
d3bdde98 43217@item F@var{retcode},@var{errno},@var{Ctrl-C flag};@var{call-specific attachment}
0ce1b118
CV
43218
43219@var{retcode} is the return code of the system call as hexadecimal value.
43220
db2e3e2e
BW
43221@var{errno} is the @code{errno} set by the call, in protocol-specific
43222representation.
0ce1b118
CV
43223This parameter can be omitted if the call was successful.
43224
fc320d37
SL
43225@var{Ctrl-C flag} is only sent if the user requested a break. In this
43226case, @var{errno} must be sent as well, even if the call was successful.
43227The @var{Ctrl-C flag} itself consists of the character @samp{C}:
0ce1b118
CV
43228
43229@smallexample
43230F0,0,C
43231@end smallexample
43232
43233@noindent
fc320d37 43234or, if the call was interrupted before the host call has been performed:
0ce1b118
CV
43235
43236@smallexample
43237F-1,4,C
43238@end smallexample
43239
43240@noindent
db2e3e2e 43241assuming 4 is the protocol-specific representation of @code{EINTR}.
0ce1b118
CV
43242
43243@end table
43244
0ce1b118 43245
79a6e687
BW
43246@node The Ctrl-C Message
43247@subsection The @samp{Ctrl-C} Message
0ce1b118
CV
43248@cindex ctrl-c message, in file-i/o protocol
43249
c8aa23ab 43250If the @samp{Ctrl-C} flag is set in the @value{GDBN}
79a6e687 43251reply packet (@pxref{The F Reply Packet}),
fc320d37 43252the target should behave as if it had
0ce1b118 43253gotten a break message. The meaning for the target is ``system call
fc320d37 43254interrupted by @code{SIGINT}''. Consequentially, the target should actually stop
0ce1b118 43255(as with a break message) and return to @value{GDBN} with a @code{T02}
c8aa23ab 43256packet.
fc320d37
SL
43257
43258It's important for the target to know in which
43259state the system call was interrupted. There are two possible cases:
0ce1b118
CV
43260
43261@itemize @bullet
43262@item
43263The system call hasn't been performed on the host yet.
43264
43265@item
43266The system call on the host has been finished.
43267
43268@end itemize
43269
43270These two states can be distinguished by the target by the value of the
43271returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
43272call hasn't been performed. This is equivalent to the @code{EINTR} handling
43273on POSIX systems. In any other case, the target may presume that the
fc320d37 43274system call has been finished --- successfully or not --- and should behave
0ce1b118
CV
43275as if the break message arrived right after the system call.
43276
fc320d37 43277@value{GDBN} must behave reliably. If the system call has not been called
0ce1b118
CV
43278yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
43279@code{errno} in the packet. If the system call on the host has been finished
fc320d37
SL
43280before the user requests a break, the full action must be finished by
43281@value{GDBN}. This requires sending @code{M} or @code{X} packets as necessary.
43282The @code{F} packet may only be sent when either nothing has happened
0ce1b118
CV
43283or the full action has been completed.
43284
43285@node Console I/O
43286@subsection Console I/O
43287@cindex console i/o as part of file-i/o
43288
d3e8051b 43289By default and if not explicitly closed by the target system, the file
0ce1b118
CV
43290descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
43291on the @value{GDBN} console is handled as any other file output operation
43292(@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
43293by @value{GDBN} so that after the target read request from file descriptor
432940 all following typing is buffered until either one of the following
43295conditions is met:
43296
43297@itemize @bullet
43298@item
c8aa23ab 43299The user types @kbd{Ctrl-c}. The behaviour is as explained above, and the
0ce1b118
CV
43300@code{read}
43301system call is treated as finished.
43302
43303@item
7f9087cb 43304The user presses @key{RET}. This is treated as end of input with a trailing
fc320d37 43305newline.
0ce1b118
CV
43306
43307@item
c8aa23ab
EZ
43308The user types @kbd{Ctrl-d}. This is treated as end of input. No trailing
43309character (neither newline nor @samp{Ctrl-D}) is appended to the input.
0ce1b118
CV
43310
43311@end itemize
43312
fc320d37
SL
43313If the user has typed more characters than fit in the buffer given to
43314the @code{read} call, the trailing characters are buffered in @value{GDBN} until
43315either another @code{read(0, @dots{})} is requested by the target, or debugging
43316is stopped at the user's request.
0ce1b118 43317
0ce1b118 43318
79a6e687
BW
43319@node List of Supported Calls
43320@subsection List of Supported Calls
0ce1b118
CV
43321@cindex list of supported file-i/o calls
43322
43323@menu
43324* open::
43325* close::
43326* read::
43327* write::
43328* lseek::
43329* rename::
43330* unlink::
43331* stat/fstat::
43332* gettimeofday::
43333* isatty::
43334* system::
43335@end menu
43336
43337@node open
43338@unnumberedsubsubsec open
43339@cindex open, file-i/o system call
43340
fc320d37
SL
43341@table @asis
43342@item Synopsis:
0ce1b118 43343@smallexample
0ce1b118
CV
43344int open(const char *pathname, int flags);
43345int open(const char *pathname, int flags, mode_t mode);
0ce1b118
CV
43346@end smallexample
43347
fc320d37
SL
43348@item Request:
43349@samp{Fopen,@var{pathptr}/@var{len},@var{flags},@var{mode}}
43350
0ce1b118 43351@noindent
fc320d37 43352@var{flags} is the bitwise @code{OR} of the following values:
0ce1b118
CV
43353
43354@table @code
b383017d 43355@item O_CREAT
0ce1b118
CV
43356If the file does not exist it will be created. The host
43357rules apply as far as file ownership and time stamps
43358are concerned.
43359
b383017d 43360@item O_EXCL
fc320d37 43361When used with @code{O_CREAT}, if the file already exists it is
0ce1b118
CV
43362an error and open() fails.
43363
b383017d 43364@item O_TRUNC
0ce1b118 43365If the file already exists and the open mode allows
fc320d37
SL
43366writing (@code{O_RDWR} or @code{O_WRONLY} is given) it will be
43367truncated to zero length.
0ce1b118 43368
b383017d 43369@item O_APPEND
0ce1b118
CV
43370The file is opened in append mode.
43371
b383017d 43372@item O_RDONLY
0ce1b118
CV
43373The file is opened for reading only.
43374
b383017d 43375@item O_WRONLY
0ce1b118
CV
43376The file is opened for writing only.
43377
b383017d 43378@item O_RDWR
0ce1b118 43379The file is opened for reading and writing.
fc320d37 43380@end table
0ce1b118
CV
43381
43382@noindent
fc320d37 43383Other bits are silently ignored.
0ce1b118 43384
0ce1b118
CV
43385
43386@noindent
fc320d37 43387@var{mode} is the bitwise @code{OR} of the following values:
0ce1b118
CV
43388
43389@table @code
b383017d 43390@item S_IRUSR
0ce1b118
CV
43391User has read permission.
43392
b383017d 43393@item S_IWUSR
0ce1b118
CV
43394User has write permission.
43395
b383017d 43396@item S_IRGRP
0ce1b118
CV
43397Group has read permission.
43398
b383017d 43399@item S_IWGRP
0ce1b118
CV
43400Group has write permission.
43401
b383017d 43402@item S_IROTH
0ce1b118
CV
43403Others have read permission.
43404
b383017d 43405@item S_IWOTH
0ce1b118 43406Others have write permission.
fc320d37 43407@end table
0ce1b118
CV
43408
43409@noindent
fc320d37 43410Other bits are silently ignored.
0ce1b118 43411
0ce1b118 43412
fc320d37
SL
43413@item Return value:
43414@code{open} returns the new file descriptor or -1 if an error
43415occurred.
0ce1b118 43416
fc320d37 43417@item Errors:
0ce1b118
CV
43418
43419@table @code
b383017d 43420@item EEXIST
fc320d37 43421@var{pathname} already exists and @code{O_CREAT} and @code{O_EXCL} were used.
0ce1b118 43422
b383017d 43423@item EISDIR
fc320d37 43424@var{pathname} refers to a directory.
0ce1b118 43425
b383017d 43426@item EACCES
0ce1b118
CV
43427The requested access is not allowed.
43428
43429@item ENAMETOOLONG
fc320d37 43430@var{pathname} was too long.
0ce1b118 43431
b383017d 43432@item ENOENT
fc320d37 43433A directory component in @var{pathname} does not exist.
0ce1b118 43434
b383017d 43435@item ENODEV
fc320d37 43436@var{pathname} refers to a device, pipe, named pipe or socket.
0ce1b118 43437
b383017d 43438@item EROFS
fc320d37 43439@var{pathname} refers to a file on a read-only filesystem and
0ce1b118
CV
43440write access was requested.
43441
b383017d 43442@item EFAULT
fc320d37 43443@var{pathname} is an invalid pointer value.
0ce1b118 43444
b383017d 43445@item ENOSPC
0ce1b118
CV
43446No space on device to create the file.
43447
b383017d 43448@item EMFILE
0ce1b118
CV
43449The process already has the maximum number of files open.
43450
b383017d 43451@item ENFILE
0ce1b118
CV
43452The limit on the total number of files open on the system
43453has been reached.
43454
b383017d 43455@item EINTR
0ce1b118
CV
43456The call was interrupted by the user.
43457@end table
43458
fc320d37
SL
43459@end table
43460
0ce1b118
CV
43461@node close
43462@unnumberedsubsubsec close
43463@cindex close, file-i/o system call
43464
fc320d37
SL
43465@table @asis
43466@item Synopsis:
0ce1b118 43467@smallexample
0ce1b118 43468int close(int fd);
fc320d37 43469@end smallexample
0ce1b118 43470
fc320d37
SL
43471@item Request:
43472@samp{Fclose,@var{fd}}
0ce1b118 43473
fc320d37
SL
43474@item Return value:
43475@code{close} returns zero on success, or -1 if an error occurred.
0ce1b118 43476
fc320d37 43477@item Errors:
0ce1b118
CV
43478
43479@table @code
b383017d 43480@item EBADF
fc320d37 43481@var{fd} isn't a valid open file descriptor.
0ce1b118 43482
b383017d 43483@item EINTR
0ce1b118
CV
43484The call was interrupted by the user.
43485@end table
43486
fc320d37
SL
43487@end table
43488
0ce1b118
CV
43489@node read
43490@unnumberedsubsubsec read
43491@cindex read, file-i/o system call
43492
fc320d37
SL
43493@table @asis
43494@item Synopsis:
0ce1b118 43495@smallexample
0ce1b118 43496int read(int fd, void *buf, unsigned int count);
fc320d37 43497@end smallexample
0ce1b118 43498
fc320d37
SL
43499@item Request:
43500@samp{Fread,@var{fd},@var{bufptr},@var{count}}
0ce1b118 43501
fc320d37 43502@item Return value:
0ce1b118
CV
43503On success, the number of bytes read is returned.
43504Zero indicates end of file. If count is zero, read
b383017d 43505returns zero as well. On error, -1 is returned.
0ce1b118 43506
fc320d37 43507@item Errors:
0ce1b118
CV
43508
43509@table @code
b383017d 43510@item EBADF
fc320d37 43511@var{fd} is not a valid file descriptor or is not open for
0ce1b118
CV
43512reading.
43513
b383017d 43514@item EFAULT
fc320d37 43515@var{bufptr} is an invalid pointer value.
0ce1b118 43516
b383017d 43517@item EINTR
0ce1b118
CV
43518The call was interrupted by the user.
43519@end table
43520
fc320d37
SL
43521@end table
43522
0ce1b118
CV
43523@node write
43524@unnumberedsubsubsec write
43525@cindex write, file-i/o system call
43526
fc320d37
SL
43527@table @asis
43528@item Synopsis:
0ce1b118 43529@smallexample
0ce1b118 43530int write(int fd, const void *buf, unsigned int count);
fc320d37 43531@end smallexample
0ce1b118 43532
fc320d37
SL
43533@item Request:
43534@samp{Fwrite,@var{fd},@var{bufptr},@var{count}}
0ce1b118 43535
fc320d37 43536@item Return value:
0ce1b118
CV
43537On success, the number of bytes written are returned.
43538Zero indicates nothing was written. On error, -1
43539is returned.
43540
fc320d37 43541@item Errors:
0ce1b118
CV
43542
43543@table @code
b383017d 43544@item EBADF
fc320d37 43545@var{fd} is not a valid file descriptor or is not open for
0ce1b118
CV
43546writing.
43547
b383017d 43548@item EFAULT
fc320d37 43549@var{bufptr} is an invalid pointer value.
0ce1b118 43550
b383017d 43551@item EFBIG
0ce1b118 43552An attempt was made to write a file that exceeds the
db2e3e2e 43553host-specific maximum file size allowed.
0ce1b118 43554
b383017d 43555@item ENOSPC
0ce1b118
CV
43556No space on device to write the data.
43557
b383017d 43558@item EINTR
0ce1b118
CV
43559The call was interrupted by the user.
43560@end table
43561
fc320d37
SL
43562@end table
43563
0ce1b118
CV
43564@node lseek
43565@unnumberedsubsubsec lseek
43566@cindex lseek, file-i/o system call
43567
fc320d37
SL
43568@table @asis
43569@item Synopsis:
0ce1b118 43570@smallexample
0ce1b118 43571long lseek (int fd, long offset, int flag);
0ce1b118
CV
43572@end smallexample
43573
fc320d37
SL
43574@item Request:
43575@samp{Flseek,@var{fd},@var{offset},@var{flag}}
43576
43577@var{flag} is one of:
0ce1b118
CV
43578
43579@table @code
b383017d 43580@item SEEK_SET
fc320d37 43581The offset is set to @var{offset} bytes.
0ce1b118 43582
b383017d 43583@item SEEK_CUR
fc320d37 43584The offset is set to its current location plus @var{offset}
0ce1b118
CV
43585bytes.
43586
b383017d 43587@item SEEK_END
fc320d37 43588The offset is set to the size of the file plus @var{offset}
0ce1b118
CV
43589bytes.
43590@end table
43591
fc320d37 43592@item Return value:
0ce1b118
CV
43593On success, the resulting unsigned offset in bytes from
43594the beginning of the file is returned. Otherwise, a
43595value of -1 is returned.
43596
fc320d37 43597@item Errors:
0ce1b118
CV
43598
43599@table @code
b383017d 43600@item EBADF
fc320d37 43601@var{fd} is not a valid open file descriptor.
0ce1b118 43602
b383017d 43603@item ESPIPE
fc320d37 43604@var{fd} is associated with the @value{GDBN} console.
0ce1b118 43605
b383017d 43606@item EINVAL
fc320d37 43607@var{flag} is not a proper value.
0ce1b118 43608
b383017d 43609@item EINTR
0ce1b118
CV
43610The call was interrupted by the user.
43611@end table
43612
fc320d37
SL
43613@end table
43614
0ce1b118
CV
43615@node rename
43616@unnumberedsubsubsec rename
43617@cindex rename, file-i/o system call
43618
fc320d37
SL
43619@table @asis
43620@item Synopsis:
0ce1b118 43621@smallexample
0ce1b118 43622int rename(const char *oldpath, const char *newpath);
fc320d37 43623@end smallexample
0ce1b118 43624
fc320d37
SL
43625@item Request:
43626@samp{Frename,@var{oldpathptr}/@var{len},@var{newpathptr}/@var{len}}
0ce1b118 43627
fc320d37 43628@item Return value:
0ce1b118
CV
43629On success, zero is returned. On error, -1 is returned.
43630
fc320d37 43631@item Errors:
0ce1b118
CV
43632
43633@table @code
b383017d 43634@item EISDIR
fc320d37 43635@var{newpath} is an existing directory, but @var{oldpath} is not a
0ce1b118
CV
43636directory.
43637
b383017d 43638@item EEXIST
fc320d37 43639@var{newpath} is a non-empty directory.
0ce1b118 43640
b383017d 43641@item EBUSY
fc320d37 43642@var{oldpath} or @var{newpath} is a directory that is in use by some
0ce1b118
CV
43643process.
43644
b383017d 43645@item EINVAL
0ce1b118
CV
43646An attempt was made to make a directory a subdirectory
43647of itself.
43648
b383017d 43649@item ENOTDIR
fc320d37
SL
43650A component used as a directory in @var{oldpath} or new
43651path is not a directory. Or @var{oldpath} is a directory
43652and @var{newpath} exists but is not a directory.
0ce1b118 43653
b383017d 43654@item EFAULT
fc320d37 43655@var{oldpathptr} or @var{newpathptr} are invalid pointer values.
0ce1b118 43656
b383017d 43657@item EACCES
0ce1b118
CV
43658No access to the file or the path of the file.
43659
43660@item ENAMETOOLONG
b383017d 43661
fc320d37 43662@var{oldpath} or @var{newpath} was too long.
0ce1b118 43663
b383017d 43664@item ENOENT
fc320d37 43665A directory component in @var{oldpath} or @var{newpath} does not exist.
0ce1b118 43666
b383017d 43667@item EROFS
0ce1b118
CV
43668The file is on a read-only filesystem.
43669
b383017d 43670@item ENOSPC
0ce1b118
CV
43671The device containing the file has no room for the new
43672directory entry.
43673
b383017d 43674@item EINTR
0ce1b118
CV
43675The call was interrupted by the user.
43676@end table
43677
fc320d37
SL
43678@end table
43679
0ce1b118
CV
43680@node unlink
43681@unnumberedsubsubsec unlink
43682@cindex unlink, file-i/o system call
43683
fc320d37
SL
43684@table @asis
43685@item Synopsis:
0ce1b118 43686@smallexample
0ce1b118 43687int unlink(const char *pathname);
fc320d37 43688@end smallexample
0ce1b118 43689
fc320d37
SL
43690@item Request:
43691@samp{Funlink,@var{pathnameptr}/@var{len}}
0ce1b118 43692
fc320d37 43693@item Return value:
0ce1b118
CV
43694On success, zero is returned. On error, -1 is returned.
43695
fc320d37 43696@item Errors:
0ce1b118
CV
43697
43698@table @code
b383017d 43699@item EACCES
0ce1b118
CV
43700No access to the file or the path of the file.
43701
b383017d 43702@item EPERM
0ce1b118
CV
43703The system does not allow unlinking of directories.
43704
b383017d 43705@item EBUSY
fc320d37 43706The file @var{pathname} cannot be unlinked because it's
0ce1b118
CV
43707being used by another process.
43708
b383017d 43709@item EFAULT
fc320d37 43710@var{pathnameptr} is an invalid pointer value.
0ce1b118
CV
43711
43712@item ENAMETOOLONG
fc320d37 43713@var{pathname} was too long.
0ce1b118 43714
b383017d 43715@item ENOENT
fc320d37 43716A directory component in @var{pathname} does not exist.
0ce1b118 43717
b383017d 43718@item ENOTDIR
0ce1b118
CV
43719A component of the path is not a directory.
43720
b383017d 43721@item EROFS
0ce1b118
CV
43722The file is on a read-only filesystem.
43723
b383017d 43724@item EINTR
0ce1b118
CV
43725The call was interrupted by the user.
43726@end table
43727
fc320d37
SL
43728@end table
43729
0ce1b118
CV
43730@node stat/fstat
43731@unnumberedsubsubsec stat/fstat
43732@cindex fstat, file-i/o system call
43733@cindex stat, file-i/o system call
43734
fc320d37
SL
43735@table @asis
43736@item Synopsis:
0ce1b118 43737@smallexample
0ce1b118
CV
43738int stat(const char *pathname, struct stat *buf);
43739int fstat(int fd, struct stat *buf);
fc320d37 43740@end smallexample
0ce1b118 43741
fc320d37
SL
43742@item Request:
43743@samp{Fstat,@var{pathnameptr}/@var{len},@var{bufptr}}@*
43744@samp{Ffstat,@var{fd},@var{bufptr}}
0ce1b118 43745
fc320d37 43746@item Return value:
0ce1b118
CV
43747On success, zero is returned. On error, -1 is returned.
43748
fc320d37 43749@item Errors:
0ce1b118
CV
43750
43751@table @code
b383017d 43752@item EBADF
fc320d37 43753@var{fd} is not a valid open file.
0ce1b118 43754
b383017d 43755@item ENOENT
fc320d37 43756A directory component in @var{pathname} does not exist or the
0ce1b118
CV
43757path is an empty string.
43758
b383017d 43759@item ENOTDIR
0ce1b118
CV
43760A component of the path is not a directory.
43761
b383017d 43762@item EFAULT
fc320d37 43763@var{pathnameptr} is an invalid pointer value.
0ce1b118 43764
b383017d 43765@item EACCES
0ce1b118
CV
43766No access to the file or the path of the file.
43767
43768@item ENAMETOOLONG
fc320d37 43769@var{pathname} was too long.
0ce1b118 43770
b383017d 43771@item EINTR
0ce1b118
CV
43772The call was interrupted by the user.
43773@end table
43774
fc320d37
SL
43775@end table
43776
0ce1b118
CV
43777@node gettimeofday
43778@unnumberedsubsubsec gettimeofday
43779@cindex gettimeofday, file-i/o system call
43780
fc320d37
SL
43781@table @asis
43782@item Synopsis:
0ce1b118 43783@smallexample
0ce1b118 43784int gettimeofday(struct timeval *tv, void *tz);
fc320d37 43785@end smallexample
0ce1b118 43786
fc320d37
SL
43787@item Request:
43788@samp{Fgettimeofday,@var{tvptr},@var{tzptr}}
0ce1b118 43789
fc320d37 43790@item Return value:
0ce1b118
CV
43791On success, 0 is returned, -1 otherwise.
43792
fc320d37 43793@item Errors:
0ce1b118
CV
43794
43795@table @code
b383017d 43796@item EINVAL
fc320d37 43797@var{tz} is a non-NULL pointer.
0ce1b118 43798
b383017d 43799@item EFAULT
fc320d37
SL
43800@var{tvptr} and/or @var{tzptr} is an invalid pointer value.
43801@end table
43802
0ce1b118
CV
43803@end table
43804
43805@node isatty
43806@unnumberedsubsubsec isatty
43807@cindex isatty, file-i/o system call
43808
fc320d37
SL
43809@table @asis
43810@item Synopsis:
0ce1b118 43811@smallexample
0ce1b118 43812int isatty(int fd);
fc320d37 43813@end smallexample
0ce1b118 43814
fc320d37
SL
43815@item Request:
43816@samp{Fisatty,@var{fd}}
0ce1b118 43817
fc320d37
SL
43818@item Return value:
43819Returns 1 if @var{fd} refers to the @value{GDBN} console, 0 otherwise.
0ce1b118 43820
fc320d37 43821@item Errors:
0ce1b118
CV
43822
43823@table @code
b383017d 43824@item EINTR
0ce1b118
CV
43825The call was interrupted by the user.
43826@end table
43827
fc320d37
SL
43828@end table
43829
43830Note that the @code{isatty} call is treated as a special case: it returns
438311 to the target if the file descriptor is attached
43832to the @value{GDBN} console, 0 otherwise. Implementing through system calls
43833would require implementing @code{ioctl} and would be more complex than
43834needed.
43835
43836
0ce1b118
CV
43837@node system
43838@unnumberedsubsubsec system
43839@cindex system, file-i/o system call
43840
fc320d37
SL
43841@table @asis
43842@item Synopsis:
0ce1b118 43843@smallexample
0ce1b118 43844int system(const char *command);
fc320d37 43845@end smallexample
0ce1b118 43846
fc320d37
SL
43847@item Request:
43848@samp{Fsystem,@var{commandptr}/@var{len}}
0ce1b118 43849
fc320d37 43850@item Return value:
5600ea19
NS
43851If @var{len} is zero, the return value indicates whether a shell is
43852available. A zero return value indicates a shell is not available.
43853For non-zero @var{len}, the value returned is -1 on error and the
43854return status of the command otherwise. Only the exit status of the
43855command is returned, which is extracted from the host's @code{system}
43856return value by calling @code{WEXITSTATUS(retval)}. In case
43857@file{/bin/sh} could not be executed, 127 is returned.
0ce1b118 43858
fc320d37 43859@item Errors:
0ce1b118
CV
43860
43861@table @code
b383017d 43862@item EINTR
0ce1b118
CV
43863The call was interrupted by the user.
43864@end table
43865
fc320d37
SL
43866@end table
43867
43868@value{GDBN} takes over the full task of calling the necessary host calls
43869to perform the @code{system} call. The return value of @code{system} on
43870the host is simplified before it's returned
43871to the target. Any termination signal information from the child process
43872is discarded, and the return value consists
43873entirely of the exit status of the called command.
43874
43875Due to security concerns, the @code{system} call is by default refused
43876by @value{GDBN}. The user has to allow this call explicitly with the
43877@code{set remote system-call-allowed 1} command.
43878
43879@table @code
43880@item set remote system-call-allowed
43881@kindex set remote system-call-allowed
43882Control whether to allow the @code{system} calls in the File I/O
43883protocol for the remote target. The default is zero (disabled).
43884
43885@item show remote system-call-allowed
43886@kindex show remote system-call-allowed
43887Show whether the @code{system} calls are allowed in the File I/O
43888protocol.
43889@end table
43890
db2e3e2e
BW
43891@node Protocol-specific Representation of Datatypes
43892@subsection Protocol-specific Representation of Datatypes
43893@cindex protocol-specific representation of datatypes, in file-i/o protocol
0ce1b118
CV
43894
43895@menu
79a6e687
BW
43896* Integral Datatypes::
43897* Pointer Values::
43898* Memory Transfer::
0ce1b118
CV
43899* struct stat::
43900* struct timeval::
43901@end menu
43902
79a6e687
BW
43903@node Integral Datatypes
43904@unnumberedsubsubsec Integral Datatypes
0ce1b118
CV
43905@cindex integral datatypes, in file-i/o protocol
43906
fc320d37
SL
43907The integral datatypes used in the system calls are @code{int},
43908@code{unsigned int}, @code{long}, @code{unsigned long},
43909@code{mode_t}, and @code{time_t}.
0ce1b118 43910
fc320d37 43911@code{int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
0ce1b118
CV
43912implemented as 32 bit values in this protocol.
43913
fc320d37 43914@code{long} and @code{unsigned long} are implemented as 64 bit types.
b383017d 43915
0ce1b118
CV
43916@xref{Limits}, for corresponding MIN and MAX values (similar to those
43917in @file{limits.h}) to allow range checking on host and target.
43918
43919@code{time_t} datatypes are defined as seconds since the Epoch.
43920
43921All integral datatypes transferred as part of a memory read or write of a
43922structured datatype e.g.@: a @code{struct stat} have to be given in big endian
43923byte order.
43924
79a6e687
BW
43925@node Pointer Values
43926@unnumberedsubsubsec Pointer Values
0ce1b118
CV
43927@cindex pointer values, in file-i/o protocol
43928
43929Pointers to target data are transmitted as they are. An exception
43930is made for pointers to buffers for which the length isn't
43931transmitted as part of the function call, namely strings. Strings
43932are transmitted as a pointer/length pair, both as hex values, e.g.@:
43933
43934@smallexample
43935@code{1aaf/12}
43936@end smallexample
43937
43938@noindent
43939which is a pointer to data of length 18 bytes at position 0x1aaf.
43940The length is defined as the full string length in bytes, including
fc320d37
SL
43941the trailing null byte. For example, the string @code{"hello world"}
43942at address 0x123456 is transmitted as
0ce1b118
CV
43943
43944@smallexample
fc320d37 43945@code{123456/d}
0ce1b118
CV
43946@end smallexample
43947
79a6e687
BW
43948@node Memory Transfer
43949@unnumberedsubsubsec Memory Transfer
fc320d37
SL
43950@cindex memory transfer, in file-i/o protocol
43951
43952Structured data which is transferred using a memory read or write (for
db2e3e2e 43953example, a @code{struct stat}) is expected to be in a protocol-specific format
fc320d37
SL
43954with all scalar multibyte datatypes being big endian. Translation to
43955this representation needs to be done both by the target before the @code{F}
43956packet is sent, and by @value{GDBN} before
43957it transfers memory to the target. Transferred pointers to structured
43958data should point to the already-coerced data at any time.
0ce1b118 43959
0ce1b118
CV
43960
43961@node struct stat
43962@unnumberedsubsubsec struct stat
43963@cindex struct stat, in file-i/o protocol
43964
fc320d37
SL
43965The buffer of type @code{struct stat} used by the target and @value{GDBN}
43966is defined as follows:
0ce1b118
CV
43967
43968@smallexample
43969struct stat @{
43970 unsigned int st_dev; /* device */
43971 unsigned int st_ino; /* inode */
43972 mode_t st_mode; /* protection */
43973 unsigned int st_nlink; /* number of hard links */
43974 unsigned int st_uid; /* user ID of owner */
43975 unsigned int st_gid; /* group ID of owner */
43976 unsigned int st_rdev; /* device type (if inode device) */
43977 unsigned long st_size; /* total size, in bytes */
43978 unsigned long st_blksize; /* blocksize for filesystem I/O */
43979 unsigned long st_blocks; /* number of blocks allocated */
43980 time_t st_atime; /* time of last access */
43981 time_t st_mtime; /* time of last modification */
43982 time_t st_ctime; /* time of last change */
43983@};
43984@end smallexample
43985
fc320d37 43986The integral datatypes conform to the definitions given in the
79a6e687 43987appropriate section (see @ref{Integral Datatypes}, for details) so this
0ce1b118
CV
43988structure is of size 64 bytes.
43989
43990The values of several fields have a restricted meaning and/or
43991range of values.
43992
fc320d37 43993@table @code
0ce1b118 43994
fc320d37
SL
43995@item st_dev
43996A value of 0 represents a file, 1 the console.
0ce1b118 43997
fc320d37
SL
43998@item st_ino
43999No valid meaning for the target. Transmitted unchanged.
0ce1b118 44000
fc320d37
SL
44001@item st_mode
44002Valid mode bits are described in @ref{Constants}. Any other
44003bits have currently no meaning for the target.
0ce1b118 44004
fc320d37
SL
44005@item st_uid
44006@itemx st_gid
44007@itemx st_rdev
44008No valid meaning for the target. Transmitted unchanged.
0ce1b118 44009
fc320d37
SL
44010@item st_atime
44011@itemx st_mtime
44012@itemx st_ctime
44013These values have a host and file system dependent
44014accuracy. Especially on Windows hosts, the file system may not
44015support exact timing values.
44016@end table
0ce1b118 44017
fc320d37
SL
44018The target gets a @code{struct stat} of the above representation and is
44019responsible for coercing it to the target representation before
0ce1b118
CV
44020continuing.
44021
fc320d37
SL
44022Note that due to size differences between the host, target, and protocol
44023representations of @code{struct stat} members, these members could eventually
0ce1b118
CV
44024get truncated on the target.
44025
44026@node struct timeval
44027@unnumberedsubsubsec struct timeval
44028@cindex struct timeval, in file-i/o protocol
44029
fc320d37 44030The buffer of type @code{struct timeval} used by the File-I/O protocol
0ce1b118
CV
44031is defined as follows:
44032
44033@smallexample
b383017d 44034struct timeval @{
0ce1b118
CV
44035 time_t tv_sec; /* second */
44036 long tv_usec; /* microsecond */
44037@};
44038@end smallexample
44039
fc320d37 44040The integral datatypes conform to the definitions given in the
79a6e687 44041appropriate section (see @ref{Integral Datatypes}, for details) so this
0ce1b118
CV
44042structure is of size 8 bytes.
44043
44044@node Constants
44045@subsection Constants
44046@cindex constants, in file-i/o protocol
44047
44048The following values are used for the constants inside of the
fc320d37 44049protocol. @value{GDBN} and target are responsible for translating these
0ce1b118
CV
44050values before and after the call as needed.
44051
44052@menu
79a6e687
BW
44053* Open Flags::
44054* mode_t Values::
44055* Errno Values::
44056* Lseek Flags::
0ce1b118
CV
44057* Limits::
44058@end menu
44059
79a6e687
BW
44060@node Open Flags
44061@unnumberedsubsubsec Open Flags
0ce1b118
CV
44062@cindex open flags, in file-i/o protocol
44063
44064All values are given in hexadecimal representation.
44065
44066@smallexample
44067 O_RDONLY 0x0
44068 O_WRONLY 0x1
44069 O_RDWR 0x2
44070 O_APPEND 0x8
44071 O_CREAT 0x200
44072 O_TRUNC 0x400
44073 O_EXCL 0x800
44074@end smallexample
44075
79a6e687
BW
44076@node mode_t Values
44077@unnumberedsubsubsec mode_t Values
0ce1b118
CV
44078@cindex mode_t values, in file-i/o protocol
44079
44080All values are given in octal representation.
44081
44082@smallexample
44083 S_IFREG 0100000
44084 S_IFDIR 040000
44085 S_IRUSR 0400
44086 S_IWUSR 0200
44087 S_IXUSR 0100
44088 S_IRGRP 040
44089 S_IWGRP 020
44090 S_IXGRP 010
44091 S_IROTH 04
44092 S_IWOTH 02
44093 S_IXOTH 01
44094@end smallexample
44095
79a6e687
BW
44096@node Errno Values
44097@unnumberedsubsubsec Errno Values
0ce1b118
CV
44098@cindex errno values, in file-i/o protocol
44099
44100All values are given in decimal representation.
44101
44102@smallexample
44103 EPERM 1
44104 ENOENT 2
44105 EINTR 4
44106 EBADF 9
44107 EACCES 13
44108 EFAULT 14
44109 EBUSY 16
44110 EEXIST 17
44111 ENODEV 19
44112 ENOTDIR 20
44113 EISDIR 21
44114 EINVAL 22
44115 ENFILE 23
44116 EMFILE 24
44117 EFBIG 27
44118 ENOSPC 28
44119 ESPIPE 29
44120 EROFS 30
44121 ENAMETOOLONG 91
44122 EUNKNOWN 9999
44123@end smallexample
44124
fc320d37 44125 @code{EUNKNOWN} is used as a fallback error value if a host system returns
0ce1b118
CV
44126 any error value not in the list of supported error numbers.
44127
79a6e687
BW
44128@node Lseek Flags
44129@unnumberedsubsubsec Lseek Flags
0ce1b118
CV
44130@cindex lseek flags, in file-i/o protocol
44131
44132@smallexample
44133 SEEK_SET 0
44134 SEEK_CUR 1
44135 SEEK_END 2
44136@end smallexample
44137
44138@node Limits
44139@unnumberedsubsubsec Limits
44140@cindex limits, in file-i/o protocol
44141
44142All values are given in decimal representation.
44143
44144@smallexample
44145 INT_MIN -2147483648
44146 INT_MAX 2147483647
44147 UINT_MAX 4294967295
44148 LONG_MIN -9223372036854775808
44149 LONG_MAX 9223372036854775807
44150 ULONG_MAX 18446744073709551615
44151@end smallexample
44152
44153@node File-I/O Examples
44154@subsection File-I/O Examples
44155@cindex file-i/o examples
44156
44157Example sequence of a write call, file descriptor 3, buffer is at target
44158address 0x1234, 6 bytes should be written:
44159
44160@smallexample
44161<- @code{Fwrite,3,1234,6}
44162@emph{request memory read from target}
44163-> @code{m1234,6}
44164<- XXXXXX
44165@emph{return "6 bytes written"}
44166-> @code{F6}
44167@end smallexample
44168
44169Example sequence of a read call, file descriptor 3, buffer is at target
44170address 0x1234, 6 bytes should be read:
44171
44172@smallexample
44173<- @code{Fread,3,1234,6}
44174@emph{request memory write to target}
44175-> @code{X1234,6:XXXXXX}
44176@emph{return "6 bytes read"}
44177-> @code{F6}
44178@end smallexample
44179
44180Example sequence of a read call, call fails on the host due to invalid
fc320d37 44181file descriptor (@code{EBADF}):
0ce1b118
CV
44182
44183@smallexample
44184<- @code{Fread,3,1234,6}
44185-> @code{F-1,9}
44186@end smallexample
44187
c8aa23ab 44188Example sequence of a read call, user presses @kbd{Ctrl-c} before syscall on
0ce1b118
CV
44189host is called:
44190
44191@smallexample
44192<- @code{Fread,3,1234,6}
44193-> @code{F-1,4,C}
44194<- @code{T02}
44195@end smallexample
44196
c8aa23ab 44197Example sequence of a read call, user presses @kbd{Ctrl-c} after syscall on
0ce1b118
CV
44198host is called:
44199
44200@smallexample
44201<- @code{Fread,3,1234,6}
44202-> @code{X1234,6:XXXXXX}
44203<- @code{T02}
44204@end smallexample
44205
cfa9d6d9
DJ
44206@node Library List Format
44207@section Library List Format
44208@cindex library list format, remote protocol
44209
44210On some platforms, a dynamic loader (e.g.@: @file{ld.so}) runs in the
44211same process as your application to manage libraries. In this case,
44212@value{GDBN} can use the loader's symbol table and normal memory
44213operations to maintain a list of shared libraries. On other
44214platforms, the operating system manages loaded libraries.
44215@value{GDBN} can not retrieve the list of currently loaded libraries
44216through memory operations, so it uses the @samp{qXfer:libraries:read}
44217packet (@pxref{qXfer library list read}) instead. The remote stub
44218queries the target's operating system and reports which libraries
44219are loaded.
44220
44221The @samp{qXfer:libraries:read} packet returns an XML document which
44222lists loaded libraries and their offsets. Each library has an
1fddbabb
PA
44223associated name and one or more segment or section base addresses,
44224which report where the library was loaded in memory.
44225
44226For the common case of libraries that are fully linked binaries, the
44227library should have a list of segments. If the target supports
44228dynamic linking of a relocatable object file, its library XML element
44229should instead include a list of allocated sections. The segment or
44230section bases are start addresses, not relocation offsets; they do not
44231depend on the library's link-time base addresses.
cfa9d6d9 44232
9cceb671
DJ
44233@value{GDBN} must be linked with the Expat library to support XML
44234library lists. @xref{Expat}.
44235
cfa9d6d9
DJ
44236A simple memory map, with one loaded library relocated by a single
44237offset, looks like this:
44238
44239@smallexample
44240<library-list>
44241 <library name="/lib/libc.so.6">
44242 <segment address="0x10000000"/>
44243 </library>
44244</library-list>
44245@end smallexample
44246
1fddbabb
PA
44247Another simple memory map, with one loaded library with three
44248allocated sections (.text, .data, .bss), looks like this:
44249
44250@smallexample
44251<library-list>
44252 <library name="sharedlib.o">
44253 <section address="0x10000000"/>
44254 <section address="0x20000000"/>
44255 <section address="0x30000000"/>
44256 </library>
44257</library-list>
44258@end smallexample
44259
cfa9d6d9
DJ
44260The format of a library list is described by this DTD:
44261
44262@smallexample
44263<!-- library-list: Root element with versioning -->
44264<!ELEMENT library-list (library)*>
44265<!ATTLIST library-list version CDATA #FIXED "1.0">
1fddbabb 44266<!ELEMENT library (segment*, section*)>
cfa9d6d9
DJ
44267<!ATTLIST library name CDATA #REQUIRED>
44268<!ELEMENT segment EMPTY>
44269<!ATTLIST segment address CDATA #REQUIRED>
1fddbabb
PA
44270<!ELEMENT section EMPTY>
44271<!ATTLIST section address CDATA #REQUIRED>
cfa9d6d9
DJ
44272@end smallexample
44273
1fddbabb
PA
44274In addition, segments and section descriptors cannot be mixed within a
44275single library element, and you must supply at least one segment or
44276section for each library.
44277
2268b414
JK
44278@node Library List Format for SVR4 Targets
44279@section Library List Format for SVR4 Targets
44280@cindex library list format, remote protocol
44281
44282On SVR4 platforms @value{GDBN} can use the symbol table of a dynamic loader
44283(e.g.@: @file{ld.so}) and normal memory operations to maintain a list of
44284shared libraries. Still a special library list provided by this packet is
44285more efficient for the @value{GDBN} remote protocol.
44286
44287The @samp{qXfer:libraries-svr4:read} packet returns an XML document which lists
44288loaded libraries and their SVR4 linker parameters. For each library on SVR4
44289target, the following parameters are reported:
44290
44291@itemize @minus
44292@item
44293@code{name}, the absolute file name from the @code{l_name} field of
44294@code{struct link_map}.
44295@item
44296@code{lm} with address of @code{struct link_map} used for TLS
44297(Thread Local Storage) access.
44298@item
44299@code{l_addr}, the displacement as read from the field @code{l_addr} of
44300@code{struct link_map}. For prelinked libraries this is not an absolute
44301memory address. It is a displacement of absolute memory address against
44302address the file was prelinked to during the library load.
44303@item
44304@code{l_ld}, which is memory address of the @code{PT_DYNAMIC} segment
44305@end itemize
44306
44307Additionally the single @code{main-lm} attribute specifies address of
44308@code{struct link_map} used for the main executable. This parameter is used
44309for TLS access and its presence is optional.
44310
44311@value{GDBN} must be linked with the Expat library to support XML
44312SVR4 library lists. @xref{Expat}.
44313
44314A simple memory map, with two loaded libraries (which do not use prelink),
44315looks like this:
44316
44317@smallexample
44318<library-list-svr4 version="1.0" main-lm="0xe4f8f8">
44319 <library name="/lib/ld-linux.so.2" lm="0xe4f51c" l_addr="0xe2d000"
44320 l_ld="0xe4eefc"/>
44321 <library name="/lib/libc.so.6" lm="0xe4fbe8" l_addr="0x154000"
db1ff28b 44322 l_ld="0x152350"/>
2268b414
JK
44323</library-list-svr>
44324@end smallexample
44325
44326The format of an SVR4 library list is described by this DTD:
44327
44328@smallexample
44329<!-- library-list-svr4: Root element with versioning -->
44330<!ELEMENT library-list-svr4 (library)*>
db1ff28b
JK
44331<!ATTLIST library-list-svr4 version CDATA #FIXED "1.0">
44332<!ATTLIST library-list-svr4 main-lm CDATA #IMPLIED>
2268b414 44333<!ELEMENT library EMPTY>
db1ff28b
JK
44334<!ATTLIST library name CDATA #REQUIRED>
44335<!ATTLIST library lm CDATA #REQUIRED>
44336<!ATTLIST library l_addr CDATA #REQUIRED>
44337<!ATTLIST library l_ld CDATA #REQUIRED>
2268b414
JK
44338@end smallexample
44339
79a6e687
BW
44340@node Memory Map Format
44341@section Memory Map Format
68437a39
DJ
44342@cindex memory map format
44343
44344To be able to write into flash memory, @value{GDBN} needs to obtain a
44345memory map from the target. This section describes the format of the
44346memory map.
44347
44348The memory map is obtained using the @samp{qXfer:memory-map:read}
44349(@pxref{qXfer memory map read}) packet and is an XML document that
9cceb671
DJ
44350lists memory regions.
44351
44352@value{GDBN} must be linked with the Expat library to support XML
44353memory maps. @xref{Expat}.
44354
44355The top-level structure of the document is shown below:
68437a39
DJ
44356
44357@smallexample
44358<?xml version="1.0"?>
44359<!DOCTYPE memory-map
44360 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
44361 "http://sourceware.org/gdb/gdb-memory-map.dtd">
44362<memory-map>
44363 region...
44364</memory-map>
44365@end smallexample
44366
44367Each region can be either:
44368
44369@itemize
44370
44371@item
44372A region of RAM starting at @var{addr} and extending for @var{length}
44373bytes from there:
44374
44375@smallexample
44376<memory type="ram" start="@var{addr}" length="@var{length}"/>
44377@end smallexample
44378
44379
44380@item
44381A region of read-only memory:
44382
44383@smallexample
44384<memory type="rom" start="@var{addr}" length="@var{length}"/>
44385@end smallexample
44386
44387
44388@item
44389A region of flash memory, with erasure blocks @var{blocksize}
44390bytes in length:
44391
44392@smallexample
44393<memory type="flash" start="@var{addr}" length="@var{length}">
44394 <property name="blocksize">@var{blocksize}</property>
44395</memory>
44396@end smallexample
44397
44398@end itemize
44399
44400Regions must not overlap. @value{GDBN} assumes that areas of memory not covered
44401by the memory map are RAM, and uses the ordinary @samp{M} and @samp{X}
44402packets to write to addresses in such ranges.
44403
44404The formal DTD for memory map format is given below:
44405
44406@smallexample
44407<!-- ................................................... -->
44408<!-- Memory Map XML DTD ................................ -->
44409<!-- File: memory-map.dtd .............................. -->
44410<!-- .................................... .............. -->
44411<!-- memory-map.dtd -->
44412<!-- memory-map: Root element with versioning -->
5f1ca24a 44413<!ELEMENT memory-map (memory)*>
68437a39 44414<!ATTLIST memory-map version CDATA #FIXED "1.0.0">
5f1ca24a 44415<!ELEMENT memory (property)*>
68437a39
DJ
44416<!-- memory: Specifies a memory region,
44417 and its type, or device. -->
5f1ca24a 44418<!ATTLIST memory type (ram|rom|flash) #REQUIRED
68437a39 44419 start CDATA #REQUIRED
5f1ca24a 44420 length CDATA #REQUIRED>
68437a39
DJ
44421<!-- property: Generic attribute tag -->
44422<!ELEMENT property (#PCDATA | property)*>
5f1ca24a 44423<!ATTLIST property name (blocksize) #REQUIRED>
68437a39
DJ
44424@end smallexample
44425
dc146f7c
VP
44426@node Thread List Format
44427@section Thread List Format
44428@cindex thread list format
44429
44430To efficiently update the list of threads and their attributes,
44431@value{GDBN} issues the @samp{qXfer:threads:read} packet
44432(@pxref{qXfer threads read}) and obtains the XML document with
44433the following structure:
44434
44435@smallexample
44436<?xml version="1.0"?>
44437<threads>
79efa585 44438 <thread id="id" core="0" name="name">
dc146f7c
VP
44439 ... description ...
44440 </thread>
44441</threads>
44442@end smallexample
44443
44444Each @samp{thread} element must have the @samp{id} attribute that
44445identifies the thread (@pxref{thread-id syntax}). The
44446@samp{core} attribute, if present, specifies which processor core
79efa585
SM
44447the thread was last executing on. The @samp{name} attribute, if
44448present, specifies the human-readable name of the thread. The content
44449of the of @samp{thread} element is interpreted as human-readable
f2ff95c5
KB
44450auxiliary information. The @samp{handle} attribute, if present,
44451is a hex encoded representation of the thread handle.
44452
dc146f7c 44453
b3b9301e
PA
44454@node Traceframe Info Format
44455@section Traceframe Info Format
44456@cindex traceframe info format
44457
44458To be able to know which objects in the inferior can be examined when
44459inspecting a tracepoint hit, @value{GDBN} needs to obtain the list of
44460memory ranges, registers and trace state variables that have been
44461collected in a traceframe.
44462
44463This list is obtained using the @samp{qXfer:traceframe-info:read}
44464(@pxref{qXfer traceframe info read}) packet and is an XML document.
44465
44466@value{GDBN} must be linked with the Expat library to support XML
44467traceframe info discovery. @xref{Expat}.
44468
44469The top-level structure of the document is shown below:
44470
44471@smallexample
44472<?xml version="1.0"?>
44473<!DOCTYPE traceframe-info
44474 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
44475 "http://sourceware.org/gdb/gdb-traceframe-info.dtd">
44476<traceframe-info>
44477 block...
44478</traceframe-info>
44479@end smallexample
44480
44481Each traceframe block can be either:
44482
44483@itemize
44484
44485@item
44486A region of collected memory starting at @var{addr} and extending for
44487@var{length} bytes from there:
44488
44489@smallexample
44490<memory start="@var{addr}" length="@var{length}"/>
44491@end smallexample
44492
28a93511
YQ
44493@item
44494A block indicating trace state variable numbered @var{number} has been
44495collected:
44496
44497@smallexample
44498<tvar id="@var{number}"/>
44499@end smallexample
44500
b3b9301e
PA
44501@end itemize
44502
44503The formal DTD for the traceframe info format is given below:
44504
44505@smallexample
28a93511 44506<!ELEMENT traceframe-info (memory | tvar)* >
b3b9301e
PA
44507<!ATTLIST traceframe-info version CDATA #FIXED "1.0">
44508
44509<!ELEMENT memory EMPTY>
44510<!ATTLIST memory start CDATA #REQUIRED
44511 length CDATA #REQUIRED>
28a93511
YQ
44512<!ELEMENT tvar>
44513<!ATTLIST tvar id CDATA #REQUIRED>
b3b9301e
PA
44514@end smallexample
44515
2ae8c8e7
MM
44516@node Branch Trace Format
44517@section Branch Trace Format
44518@cindex branch trace format
44519
44520In order to display the branch trace of an inferior thread,
44521@value{GDBN} needs to obtain the list of branches. This list is
44522represented as list of sequential code blocks that are connected via
44523branches. The code in each block has been executed sequentially.
44524
44525This list is obtained using the @samp{qXfer:btrace:read}
44526(@pxref{qXfer btrace read}) packet and is an XML document.
44527
44528@value{GDBN} must be linked with the Expat library to support XML
44529traceframe info discovery. @xref{Expat}.
44530
44531The top-level structure of the document is shown below:
44532
44533@smallexample
44534<?xml version="1.0"?>
44535<!DOCTYPE btrace
44536 PUBLIC "+//IDN gnu.org//DTD GDB Branch Trace V1.0//EN"
44537 "http://sourceware.org/gdb/gdb-btrace.dtd">
44538<btrace>
44539 block...
44540</btrace>
44541@end smallexample
44542
44543@itemize
44544
44545@item
44546A block of sequentially executed instructions starting at @var{begin}
44547and ending at @var{end}:
44548
44549@smallexample
44550<block begin="@var{begin}" end="@var{end}"/>
44551@end smallexample
44552
44553@end itemize
44554
44555The formal DTD for the branch trace format is given below:
44556
44557@smallexample
b20a6524 44558<!ELEMENT btrace (block* | pt) >
2ae8c8e7
MM
44559<!ATTLIST btrace version CDATA #FIXED "1.0">
44560
44561<!ELEMENT block EMPTY>
44562<!ATTLIST block begin CDATA #REQUIRED
44563 end CDATA #REQUIRED>
b20a6524
MM
44564
44565<!ELEMENT pt (pt-config?, raw?)>
44566
44567<!ELEMENT pt-config (cpu?)>
44568
44569<!ELEMENT cpu EMPTY>
44570<!ATTLIST cpu vendor CDATA #REQUIRED
44571 family CDATA #REQUIRED
44572 model CDATA #REQUIRED
44573 stepping CDATA #REQUIRED>
44574
44575<!ELEMENT raw (#PCDATA)>
2ae8c8e7
MM
44576@end smallexample
44577
f4abbc16
MM
44578@node Branch Trace Configuration Format
44579@section Branch Trace Configuration Format
44580@cindex branch trace configuration format
44581
44582For each inferior thread, @value{GDBN} can obtain the branch trace
44583configuration using the @samp{qXfer:btrace-conf:read}
44584(@pxref{qXfer btrace-conf read}) packet.
44585
44586The configuration describes the branch trace format and configuration
d33501a5
MM
44587settings for that format. The following information is described:
44588
44589@table @code
44590@item bts
44591This thread uses the @dfn{Branch Trace Store} (@acronym{BTS}) format.
44592@table @code
44593@item size
44594The size of the @acronym{BTS} ring buffer in bytes.
44595@end table
b20a6524 44596@item pt
bc504a31 44597This thread uses the @dfn{Intel Processor Trace} (@acronym{Intel
b20a6524
MM
44598PT}) format.
44599@table @code
44600@item size
bc504a31 44601The size of the @acronym{Intel PT} ring buffer in bytes.
b20a6524 44602@end table
d33501a5 44603@end table
f4abbc16
MM
44604
44605@value{GDBN} must be linked with the Expat library to support XML
44606branch trace configuration discovery. @xref{Expat}.
44607
44608The formal DTD for the branch trace configuration format is given below:
44609
44610@smallexample
b20a6524 44611<!ELEMENT btrace-conf (bts?, pt?)>
f4abbc16
MM
44612<!ATTLIST btrace-conf version CDATA #FIXED "1.0">
44613
44614<!ELEMENT bts EMPTY>
d33501a5 44615<!ATTLIST bts size CDATA #IMPLIED>
b20a6524
MM
44616
44617<!ELEMENT pt EMPTY>
44618<!ATTLIST pt size CDATA #IMPLIED>
f4abbc16
MM
44619@end smallexample
44620
f418dd93
DJ
44621@include agentexpr.texi
44622
23181151
DJ
44623@node Target Descriptions
44624@appendix Target Descriptions
44625@cindex target descriptions
44626
23181151
DJ
44627One of the challenges of using @value{GDBN} to debug embedded systems
44628is that there are so many minor variants of each processor
44629architecture in use. It is common practice for vendors to start with
eb17f351 44630a standard processor core --- ARM, PowerPC, or @acronym{MIPS}, for example ---
23181151
DJ
44631and then make changes to adapt it to a particular market niche. Some
44632architectures have hundreds of variants, available from dozens of
44633vendors. This leads to a number of problems:
44634
44635@itemize @bullet
44636@item
44637With so many different customized processors, it is difficult for
44638the @value{GDBN} maintainers to keep up with the changes.
44639@item
44640Since individual variants may have short lifetimes or limited
44641audiences, it may not be worthwhile to carry information about every
44642variant in the @value{GDBN} source tree.
44643@item
44644When @value{GDBN} does support the architecture of the embedded system
44645at hand, the task of finding the correct architecture name to give the
44646@command{set architecture} command can be error-prone.
44647@end itemize
44648
44649To address these problems, the @value{GDBN} remote protocol allows a
44650target system to not only identify itself to @value{GDBN}, but to
44651actually describe its own features. This lets @value{GDBN} support
44652processor variants it has never seen before --- to the extent that the
44653descriptions are accurate, and that @value{GDBN} understands them.
44654
9cceb671
DJ
44655@value{GDBN} must be linked with the Expat library to support XML
44656target descriptions. @xref{Expat}.
123dc839 44657
23181151
DJ
44658@menu
44659* Retrieving Descriptions:: How descriptions are fetched from a target.
44660* Target Description Format:: The contents of a target description.
123dc839
DJ
44661* Predefined Target Types:: Standard types available for target
44662 descriptions.
81516450 44663* Enum Target Types:: How to define enum target types.
123dc839 44664* Standard Target Features:: Features @value{GDBN} knows about.
23181151
DJ
44665@end menu
44666
44667@node Retrieving Descriptions
44668@section Retrieving Descriptions
44669
44670Target descriptions can be read from the target automatically, or
44671specified by the user manually. The default behavior is to read the
44672description from the target. @value{GDBN} retrieves it via the remote
44673protocol using @samp{qXfer} requests (@pxref{General Query Packets,
44674qXfer}). The @var{annex} in the @samp{qXfer} packet will be
44675@samp{target.xml}. The contents of the @samp{target.xml} annex are an
44676XML document, of the form described in @ref{Target Description
44677Format}.
44678
44679Alternatively, you can specify a file to read for the target description.
44680If a file is set, the target will not be queried. The commands to
44681specify a file are:
44682
44683@table @code
44684@cindex set tdesc filename
44685@item set tdesc filename @var{path}
44686Read the target description from @var{path}.
44687
44688@cindex unset tdesc filename
44689@item unset tdesc filename
44690Do not read the XML target description from a file. @value{GDBN}
44691will use the description supplied by the current target.
44692
44693@cindex show tdesc filename
44694@item show tdesc filename
44695Show the filename to read for a target description, if any.
44696@end table
44697
44698
44699@node Target Description Format
44700@section Target Description Format
44701@cindex target descriptions, XML format
44702
44703A target description annex is an @uref{http://www.w3.org/XML/, XML}
44704document which complies with the Document Type Definition provided in
44705the @value{GDBN} sources in @file{gdb/features/gdb-target.dtd}. This
44706means you can use generally available tools like @command{xmllint} to
44707check that your feature descriptions are well-formed and valid.
44708However, to help people unfamiliar with XML write descriptions for
44709their targets, we also describe the grammar here.
44710
123dc839
DJ
44711Target descriptions can identify the architecture of the remote target
44712and (for some architectures) provide information about custom register
08d16641
PA
44713sets. They can also identify the OS ABI of the remote target.
44714@value{GDBN} can use this information to autoconfigure for your
123dc839 44715target, or to warn you if you connect to an unsupported target.
23181151
DJ
44716
44717Here is a simple target description:
44718
123dc839 44719@smallexample
1780a0ed 44720<target version="1.0">
23181151
DJ
44721 <architecture>i386:x86-64</architecture>
44722</target>
123dc839 44723@end smallexample
23181151
DJ
44724
44725@noindent
44726This minimal description only says that the target uses
44727the x86-64 architecture.
44728
123dc839
DJ
44729A target description has the following overall form, with [ ] marking
44730optional elements and @dots{} marking repeatable elements. The elements
44731are explained further below.
23181151 44732
123dc839 44733@smallexample
23181151
DJ
44734<?xml version="1.0"?>
44735<!DOCTYPE target SYSTEM "gdb-target.dtd">
1780a0ed 44736<target version="1.0">
123dc839 44737 @r{[}@var{architecture}@r{]}
08d16641 44738 @r{[}@var{osabi}@r{]}
e35359c5 44739 @r{[}@var{compatible}@r{]}
123dc839 44740 @r{[}@var{feature}@dots{}@r{]}
23181151 44741</target>
123dc839 44742@end smallexample
23181151
DJ
44743
44744@noindent
44745The description is generally insensitive to whitespace and line
44746breaks, under the usual common-sense rules. The XML version
44747declaration and document type declaration can generally be omitted
44748(@value{GDBN} does not require them), but specifying them may be
1780a0ed
DJ
44749useful for XML validation tools. The @samp{version} attribute for
44750@samp{<target>} may also be omitted, but we recommend
44751including it; if future versions of @value{GDBN} use an incompatible
44752revision of @file{gdb-target.dtd}, they will detect and report
44753the version mismatch.
23181151 44754
108546a0
DJ
44755@subsection Inclusion
44756@cindex target descriptions, inclusion
44757@cindex XInclude
44758@ifnotinfo
44759@cindex <xi:include>
44760@end ifnotinfo
44761
44762It can sometimes be valuable to split a target description up into
44763several different annexes, either for organizational purposes, or to
44764share files between different possible target descriptions. You can
44765divide a description into multiple files by replacing any element of
44766the target description with an inclusion directive of the form:
44767
123dc839 44768@smallexample
108546a0 44769<xi:include href="@var{document}"/>
123dc839 44770@end smallexample
108546a0
DJ
44771
44772@noindent
44773When @value{GDBN} encounters an element of this form, it will retrieve
44774the named XML @var{document}, and replace the inclusion directive with
44775the contents of that document. If the current description was read
44776using @samp{qXfer}, then so will be the included document;
44777@var{document} will be interpreted as the name of an annex. If the
44778current description was read from a file, @value{GDBN} will look for
44779@var{document} as a file in the same directory where it found the
44780original description.
44781
123dc839
DJ
44782@subsection Architecture
44783@cindex <architecture>
44784
44785An @samp{<architecture>} element has this form:
44786
44787@smallexample
44788 <architecture>@var{arch}</architecture>
44789@end smallexample
44790
e35359c5
UW
44791@var{arch} is one of the architectures from the set accepted by
44792@code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
123dc839 44793
08d16641
PA
44794@subsection OS ABI
44795@cindex @code{<osabi>}
44796
44797This optional field was introduced in @value{GDBN} version 7.0.
44798Previous versions of @value{GDBN} ignore it.
44799
44800An @samp{<osabi>} element has this form:
44801
44802@smallexample
44803 <osabi>@var{abi-name}</osabi>
44804@end smallexample
44805
44806@var{abi-name} is an OS ABI name from the same selection accepted by
44807@w{@code{set osabi}} (@pxref{ABI, ,Configuring the Current ABI}).
44808
e35359c5
UW
44809@subsection Compatible Architecture
44810@cindex @code{<compatible>}
44811
44812This optional field was introduced in @value{GDBN} version 7.0.
44813Previous versions of @value{GDBN} ignore it.
44814
44815A @samp{<compatible>} element has this form:
44816
44817@smallexample
44818 <compatible>@var{arch}</compatible>
44819@end smallexample
44820
44821@var{arch} is one of the architectures from the set accepted by
44822@code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
44823
44824A @samp{<compatible>} element is used to specify that the target
44825is able to run binaries in some other than the main target architecture
44826given by the @samp{<architecture>} element. For example, on the
44827Cell Broadband Engine, the main architecture is @code{powerpc:common}
44828or @code{powerpc:common64}, but the system is able to run binaries
44829in the @code{spu} architecture as well. The way to describe this
44830capability with @samp{<compatible>} is as follows:
44831
44832@smallexample
44833 <architecture>powerpc:common</architecture>
44834 <compatible>spu</compatible>
44835@end smallexample
44836
123dc839
DJ
44837@subsection Features
44838@cindex <feature>
44839
44840Each @samp{<feature>} describes some logical portion of the target
44841system. Features are currently used to describe available CPU
44842registers and the types of their contents. A @samp{<feature>} element
44843has this form:
44844
44845@smallexample
44846<feature name="@var{name}">
44847 @r{[}@var{type}@dots{}@r{]}
44848 @var{reg}@dots{}
44849</feature>
44850@end smallexample
44851
44852@noindent
44853Each feature's name should be unique within the description. The name
44854of a feature does not matter unless @value{GDBN} has some special
44855knowledge of the contents of that feature; if it does, the feature
44856should have its standard name. @xref{Standard Target Features}.
44857
44858@subsection Types
44859
44860Any register's value is a collection of bits which @value{GDBN} must
44861interpret. The default interpretation is a two's complement integer,
44862but other types can be requested by name in the register description.
44863Some predefined types are provided by @value{GDBN} (@pxref{Predefined
81516450
DE
44864Target Types}), and the description can define additional composite
44865and enum types.
123dc839
DJ
44866
44867Each type element must have an @samp{id} attribute, which gives
44868a unique (within the containing @samp{<feature>}) name to the type.
44869Types must be defined before they are used.
44870
44871@cindex <vector>
44872Some targets offer vector registers, which can be treated as arrays
44873of scalar elements. These types are written as @samp{<vector>} elements,
44874specifying the array element type, @var{type}, and the number of elements,
44875@var{count}:
44876
44877@smallexample
44878<vector id="@var{id}" type="@var{type}" count="@var{count}"/>
44879@end smallexample
44880
44881@cindex <union>
44882If a register's value is usefully viewed in multiple ways, define it
44883with a union type containing the useful representations. The
44884@samp{<union>} element contains one or more @samp{<field>} elements,
44885each of which has a @var{name} and a @var{type}:
44886
44887@smallexample
44888<union id="@var{id}">
44889 <field name="@var{name}" type="@var{type}"/>
44890 @dots{}
44891</union>
44892@end smallexample
44893
f5dff777 44894@cindex <struct>
81516450 44895@cindex <flags>
f5dff777 44896If a register's value is composed from several separate values, define
81516450
DE
44897it with either a structure type or a flags type.
44898A flags type may only contain bitfields.
44899A structure type may either contain only bitfields or contain no bitfields.
44900If the value contains only bitfields, its total size in bytes must be
44901specified.
44902
44903Non-bitfield values have a @var{name} and @var{type}.
f5dff777
DJ
44904
44905@smallexample
81516450
DE
44906<struct id="@var{id}">
44907 <field name="@var{name}" type="@var{type}"/>
f5dff777
DJ
44908 @dots{}
44909</struct>
44910@end smallexample
44911
81516450
DE
44912Both @var{name} and @var{type} values are required.
44913No implicit padding is added.
44914
44915Bitfield values have a @var{name}, @var{start}, @var{end} and @var{type}.
f5dff777
DJ
44916
44917@smallexample
81516450
DE
44918<struct id="@var{id}" size="@var{size}">
44919 <field name="@var{name}" start="@var{start}" end="@var{end}" type="@var{type}"/>
f5dff777
DJ
44920 @dots{}
44921</struct>
44922@end smallexample
44923
f5dff777
DJ
44924@smallexample
44925<flags id="@var{id}" size="@var{size}">
81516450 44926 <field name="@var{name}" start="@var{start}" end="@var{end}" type="@var{type}"/>
f5dff777
DJ
44927 @dots{}
44928</flags>
44929@end smallexample
44930
81516450
DE
44931The @var{name} value is required.
44932Bitfield values may be named with the empty string, @samp{""},
44933in which case the field is ``filler'' and its value is not printed.
44934Not all bits need to be specified, so ``filler'' fields are optional.
44935
ee8da4b8
DE
44936The @var{start} and @var{end} values are required, and @var{type}
44937is optional.
81516450
DE
44938The field's @var{start} must be less than or equal to its @var{end},
44939and zero represents the least significant bit.
81516450 44940
ee8da4b8
DE
44941The default value of @var{type} is @code{bool} for single bit fields,
44942and an unsigned integer otherwise.
81516450
DE
44943
44944Which to choose? Structures or flags?
44945
44946Registers defined with @samp{flags} have these advantages over
44947defining them with @samp{struct}:
44948
44949@itemize @bullet
44950@item
44951Arithmetic may be performed on them as if they were integers.
44952@item
44953They are printed in a more readable fashion.
44954@end itemize
44955
44956Registers defined with @samp{struct} have one advantage over
44957defining them with @samp{flags}:
44958
44959@itemize @bullet
44960@item
44961One can fetch individual fields like in @samp{C}.
44962
44963@smallexample
44964(gdb) print $my_struct_reg.field3
44965$1 = 42
44966@end smallexample
44967
44968@end itemize
44969
123dc839
DJ
44970@subsection Registers
44971@cindex <reg>
44972
44973Each register is represented as an element with this form:
44974
44975@smallexample
44976<reg name="@var{name}"
44977 bitsize="@var{size}"
44978 @r{[}regnum="@var{num}"@r{]}
44979 @r{[}save-restore="@var{save-restore}"@r{]}
44980 @r{[}type="@var{type}"@r{]}
44981 @r{[}group="@var{group}"@r{]}/>
44982@end smallexample
44983
44984@noindent
44985The components are as follows:
44986
44987@table @var
44988
44989@item name
44990The register's name; it must be unique within the target description.
44991
44992@item bitsize
44993The register's size, in bits.
44994
44995@item regnum
44996The register's number. If omitted, a register's number is one greater
44997than that of the previous register (either in the current feature or in
177b42fe 44998a preceding feature); the first register in the target description
123dc839
DJ
44999defaults to zero. This register number is used to read or write
45000the register; e.g.@: it is used in the remote @code{p} and @code{P}
45001packets, and registers appear in the @code{g} and @code{G} packets
45002in order of increasing register number.
45003
45004@item save-restore
45005Whether the register should be preserved across inferior function
45006calls; this must be either @code{yes} or @code{no}. The default is
45007@code{yes}, which is appropriate for most registers except for
45008some system control registers; this is not related to the target's
45009ABI.
45010
45011@item type
697aa1b7 45012The type of the register. It may be a predefined type, a type
123dc839
DJ
45013defined in the current feature, or one of the special types @code{int}
45014and @code{float}. @code{int} is an integer type of the correct size
45015for @var{bitsize}, and @code{float} is a floating point type (in the
45016architecture's normal floating point format) of the correct size for
45017@var{bitsize}. The default is @code{int}.
45018
45019@item group
cef0f868
SH
45020The register group to which this register belongs. It can be one of the
45021standard register groups @code{general}, @code{float}, @code{vector} or an
45022arbitrary string. Group names should be limited to alphanumeric characters.
45023If a group name is made up of multiple words the words may be separated by
45024hyphens; e.g.@: @code{special-group} or @code{ultra-special-group}. If no
45025@var{group} is specified, @value{GDBN} will not display the register in
45026@code{info registers}.
123dc839
DJ
45027
45028@end table
45029
45030@node Predefined Target Types
45031@section Predefined Target Types
45032@cindex target descriptions, predefined types
45033
45034Type definitions in the self-description can build up composite types
45035from basic building blocks, but can not define fundamental types. Instead,
45036standard identifiers are provided by @value{GDBN} for the fundamental
45037types. The currently supported types are:
45038
45039@table @code
45040
81516450
DE
45041@item bool
45042Boolean type, occupying a single bit.
45043
123dc839
DJ
45044@item int8
45045@itemx int16
d1908f2d 45046@itemx int24
123dc839
DJ
45047@itemx int32
45048@itemx int64
7cc46491 45049@itemx int128
123dc839
DJ
45050Signed integer types holding the specified number of bits.
45051
45052@item uint8
45053@itemx uint16
d1908f2d 45054@itemx uint24
123dc839
DJ
45055@itemx uint32
45056@itemx uint64
7cc46491 45057@itemx uint128
123dc839
DJ
45058Unsigned integer types holding the specified number of bits.
45059
45060@item code_ptr
45061@itemx data_ptr
45062Pointers to unspecified code and data. The program counter and
45063any dedicated return address register may be marked as code
45064pointers; printing a code pointer converts it into a symbolic
45065address. The stack pointer and any dedicated address registers
45066may be marked as data pointers.
45067
6e3bbd1a
PB
45068@item ieee_single
45069Single precision IEEE floating point.
45070
45071@item ieee_double
45072Double precision IEEE floating point.
45073
123dc839
DJ
45074@item arm_fpa_ext
45075The 12-byte extended precision format used by ARM FPA registers.
45076
075b51b7
L
45077@item i387_ext
45078The 10-byte extended precision format used by x87 registers.
45079
45080@item i386_eflags
4508132bit @sc{eflags} register used by x86.
45082
45083@item i386_mxcsr
4508432bit @sc{mxcsr} register used by x86.
45085
123dc839
DJ
45086@end table
45087
81516450
DE
45088@node Enum Target Types
45089@section Enum Target Types
45090@cindex target descriptions, enum types
45091
45092Enum target types are useful in @samp{struct} and @samp{flags}
45093register descriptions. @xref{Target Description Format}.
45094
45095Enum types have a name, size and a list of name/value pairs.
45096
45097@smallexample
45098<enum id="@var{id}" size="@var{size}">
45099 <evalue name="@var{name}" value="@var{value}"/>
45100 @dots{}
45101</enum>
45102@end smallexample
45103
45104Enums must be defined before they are used.
45105
45106@smallexample
45107<enum id="levels_type" size="4">
45108 <evalue name="low" value="0"/>
45109 <evalue name="high" value="1"/>
45110</enum>
45111<flags id="flags_type" size="4">
45112 <field name="X" start="0"/>
45113 <field name="LEVEL" start="1" end="1" type="levels_type"/>
45114</flags>
45115<reg name="flags" bitsize="32" type="flags_type"/>
45116@end smallexample
45117
45118Given that description, a value of 3 for the @samp{flags} register
45119would be printed as:
45120
45121@smallexample
45122(gdb) info register flags
45123flags 0x3 [ X LEVEL=high ]
45124@end smallexample
45125
123dc839
DJ
45126@node Standard Target Features
45127@section Standard Target Features
45128@cindex target descriptions, standard features
45129
45130A target description must contain either no registers or all the
45131target's registers. If the description contains no registers, then
45132@value{GDBN} will assume a default register layout, selected based on
45133the architecture. If the description contains any registers, the
45134default layout will not be used; the standard registers must be
45135described in the target description, in such a way that @value{GDBN}
45136can recognize them.
45137
45138This is accomplished by giving specific names to feature elements
45139which contain standard registers. @value{GDBN} will look for features
45140with those names and verify that they contain the expected registers;
45141if any known feature is missing required registers, or if any required
45142feature is missing, @value{GDBN} will reject the target
45143description. You can add additional registers to any of the
45144standard features --- @value{GDBN} will display them just as if
45145they were added to an unrecognized feature.
45146
45147This section lists the known features and their expected contents.
45148Sample XML documents for these features are included in the
45149@value{GDBN} source tree, in the directory @file{gdb/features}.
45150
45151Names recognized by @value{GDBN} should include the name of the
45152company or organization which selected the name, and the overall
45153architecture to which the feature applies; so e.g.@: the feature
45154containing ARM core registers is named @samp{org.gnu.gdb.arm.core}.
45155
ff6f572f
DJ
45156The names of registers are not case sensitive for the purpose
45157of recognizing standard features, but @value{GDBN} will only display
45158registers using the capitalization used in the description.
45159
e9c17194 45160@menu
430ed3f0 45161* AArch64 Features::
ad0a504f 45162* ARC Features::
e9c17194 45163* ARM Features::
3bb8d5c3 45164* i386 Features::
164224e9 45165* MicroBlaze Features::
1e26b4f8 45166* MIPS Features::
e9c17194 45167* M68K Features::
a28d8e50 45168* NDS32 Features::
a1217d97 45169* Nios II Features::
a994fec4 45170* OpenRISC 1000 Features::
1e26b4f8 45171* PowerPC Features::
b5ffee31 45172* RISC-V Features::
e3ec872f 45173* RX Features::
4ac33720 45174* S/390 and System z Features::
3f7b46f2 45175* Sparc Features::
224bbe49 45176* TIC6x Features::
e9c17194
VP
45177@end menu
45178
45179
430ed3f0
MS
45180@node AArch64 Features
45181@subsection AArch64 Features
45182@cindex target descriptions, AArch64 features
45183
45184The @samp{org.gnu.gdb.aarch64.core} feature is required for AArch64
45185targets. It should contain registers @samp{x0} through @samp{x30},
45186@samp{sp}, @samp{pc}, and @samp{cpsr}.
45187
45188The @samp{org.gnu.gdb.aarch64.fpu} feature is optional. If present,
45189it should contain registers @samp{v0} through @samp{v31}, @samp{fpsr},
45190and @samp{fpcr}.
45191
95228a0d
AH
45192The @samp{org.gnu.gdb.aarch64.sve} feature is optional. If present,
45193it should contain registers @samp{z0} through @samp{z31}, @samp{p0}
45194through @samp{p15}, @samp{ffr} and @samp{vg}.
45195
6dc0ebde
AH
45196The @samp{org.gnu.gdb.aarch64.pauth} feature is optional. If present,
45197it should contain registers @samp{pauth_dmask} and @samp{pauth_cmask}.
45198
ad0a504f
AK
45199@node ARC Features
45200@subsection ARC Features
45201@cindex target descriptions, ARC Features
45202
45203ARC processors are highly configurable, so even core registers and their number
45204are not completely predetermined. In addition flags and PC registers which are
45205important to @value{GDBN} are not ``core'' registers in ARC. It is required
45206that one of the core registers features is present.
45207@samp{org.gnu.gdb.arc.aux-minimal} feature is mandatory.
45208
45209The @samp{org.gnu.gdb.arc.core.v2} feature is required for ARC EM and ARC HS
45210targets with a normal register file. It should contain registers @samp{r0}
45211through @samp{r25}, @samp{gp}, @samp{fp}, @samp{sp}, @samp{r30}, @samp{blink},
45212@samp{lp_count} and @samp{pcl}. This feature may contain register @samp{ilink}
45213and any of extension core registers @samp{r32} through @samp{r59/acch}.
45214@samp{ilink} and extension core registers are not available to read/write, when
45215debugging GNU/Linux applications, thus @samp{ilink} is made optional.
45216
45217The @samp{org.gnu.gdb.arc.core-reduced.v2} feature is required for ARC EM and
45218ARC HS targets with a reduced register file. It should contain registers
45219@samp{r0} through @samp{r3}, @samp{r10} through @samp{r15}, @samp{gp},
45220@samp{fp}, @samp{sp}, @samp{r30}, @samp{blink}, @samp{lp_count} and @samp{pcl}.
45221This feature may contain register @samp{ilink} and any of extension core
45222registers @samp{r32} through @samp{r59/acch}.
45223
45224The @samp{org.gnu.gdb.arc.core.arcompact} feature is required for ARCompact
45225targets with a normal register file. It should contain registers @samp{r0}
45226through @samp{r25}, @samp{gp}, @samp{fp}, @samp{sp}, @samp{r30}, @samp{blink},
45227@samp{lp_count} and @samp{pcl}. This feature may contain registers
45228@samp{ilink1}, @samp{ilink2} and any of extension core registers @samp{r32}
45229through @samp{r59/acch}. @samp{ilink1} and @samp{ilink2} and extension core
45230registers are not available when debugging GNU/Linux applications. The only
45231difference with @samp{org.gnu.gdb.arc.core.v2} feature is in the names of
45232@samp{ilink1} and @samp{ilink2} registers and that @samp{r30} is mandatory in
45233ARC v2, but @samp{ilink2} is optional on ARCompact.
45234
45235The @samp{org.gnu.gdb.arc.aux-minimal} feature is required for all ARC
45236targets. It should contain registers @samp{pc} and @samp{status32}.
45237
e9c17194 45238@node ARM Features
123dc839
DJ
45239@subsection ARM Features
45240@cindex target descriptions, ARM features
45241
9779414d
DJ
45242The @samp{org.gnu.gdb.arm.core} feature is required for non-M-profile
45243ARM targets.
123dc839
DJ
45244It should contain registers @samp{r0} through @samp{r13}, @samp{sp},
45245@samp{lr}, @samp{pc}, and @samp{cpsr}.
45246
9779414d
DJ
45247For M-profile targets (e.g. Cortex-M3), the @samp{org.gnu.gdb.arm.core}
45248feature is replaced by @samp{org.gnu.gdb.arm.m-profile}. It should contain
45249registers @samp{r0} through @samp{r13}, @samp{sp}, @samp{lr}, @samp{pc},
45250and @samp{xpsr}.
45251
123dc839
DJ
45252The @samp{org.gnu.gdb.arm.fpa} feature is optional. If present, it
45253should contain registers @samp{f0} through @samp{f7} and @samp{fps}.
45254
ff6f572f
DJ
45255The @samp{org.gnu.gdb.xscale.iwmmxt} feature is optional. If present,
45256it should contain at least registers @samp{wR0} through @samp{wR15} and
45257@samp{wCGR0} through @samp{wCGR3}. The @samp{wCID}, @samp{wCon},
45258@samp{wCSSF}, and @samp{wCASF} registers are optional.
23181151 45259
58d6951d
DJ
45260The @samp{org.gnu.gdb.arm.vfp} feature is optional. If present, it
45261should contain at least registers @samp{d0} through @samp{d15}. If
45262they are present, @samp{d16} through @samp{d31} should also be included.
45263@value{GDBN} will synthesize the single-precision registers from
45264halves of the double-precision registers.
45265
45266The @samp{org.gnu.gdb.arm.neon} feature is optional. It does not
45267need to contain registers; it instructs @value{GDBN} to display the
45268VFP double-precision registers as vectors and to synthesize the
45269quad-precision registers from pairs of double-precision registers.
45270If this feature is present, @samp{org.gnu.gdb.arm.vfp} must also
45271be present and include 32 double-precision registers.
45272
3bb8d5c3
L
45273@node i386 Features
45274@subsection i386 Features
45275@cindex target descriptions, i386 features
45276
45277The @samp{org.gnu.gdb.i386.core} feature is required for i386/amd64
45278targets. It should describe the following registers:
45279
45280@itemize @minus
45281@item
45282@samp{eax} through @samp{edi} plus @samp{eip} for i386
45283@item
45284@samp{rax} through @samp{r15} plus @samp{rip} for amd64
45285@item
45286@samp{eflags}, @samp{cs}, @samp{ss}, @samp{ds}, @samp{es},
45287@samp{fs}, @samp{gs}
45288@item
45289@samp{st0} through @samp{st7}
45290@item
45291@samp{fctrl}, @samp{fstat}, @samp{ftag}, @samp{fiseg}, @samp{fioff},
45292@samp{foseg}, @samp{fooff} and @samp{fop}
45293@end itemize
45294
45295The register sets may be different, depending on the target.
45296
3a13a53b 45297The @samp{org.gnu.gdb.i386.sse} feature is optional. It should
3bb8d5c3
L
45298describe registers:
45299
45300@itemize @minus
45301@item
45302@samp{xmm0} through @samp{xmm7} for i386
45303@item
45304@samp{xmm0} through @samp{xmm15} for amd64
45305@item
45306@samp{mxcsr}
45307@end itemize
45308
3a13a53b
L
45309The @samp{org.gnu.gdb.i386.avx} feature is optional and requires the
45310@samp{org.gnu.gdb.i386.sse} feature. It should
f68eb612
L
45311describe the upper 128 bits of @sc{ymm} registers:
45312
45313@itemize @minus
45314@item
45315@samp{ymm0h} through @samp{ymm7h} for i386
45316@item
45317@samp{ymm0h} through @samp{ymm15h} for amd64
f68eb612
L
45318@end itemize
45319
bc504a31 45320The @samp{org.gnu.gdb.i386.mpx} is an optional feature representing Intel
ca8941bb
WT
45321Memory Protection Extension (MPX). It should describe the following registers:
45322
45323@itemize @minus
45324@item
45325@samp{bnd0raw} through @samp{bnd3raw} for i386 and amd64.
45326@item
45327@samp{bndcfgu} and @samp{bndstatus} for i386 and amd64.
45328@end itemize
45329
3bb8d5c3
L
45330The @samp{org.gnu.gdb.i386.linux} feature is optional. It should
45331describe a single register, @samp{orig_eax}.
45332
2735833d
WT
45333The @samp{org.gnu.gdb.i386.segments} feature is optional. It should
45334describe two system registers: @samp{fs_base} and @samp{gs_base}.
45335
01f9f808
MS
45336The @samp{org.gnu.gdb.i386.avx512} feature is optional and requires the
45337@samp{org.gnu.gdb.i386.avx} feature. It should
45338describe additional @sc{xmm} registers:
45339
45340@itemize @minus
45341@item
45342@samp{xmm16h} through @samp{xmm31h}, only valid for amd64.
45343@end itemize
45344
45345It should describe the upper 128 bits of additional @sc{ymm} registers:
45346
45347@itemize @minus
45348@item
45349@samp{ymm16h} through @samp{ymm31h}, only valid for amd64.
45350@end itemize
45351
45352It should
45353describe the upper 256 bits of @sc{zmm} registers:
45354
45355@itemize @minus
45356@item
45357@samp{zmm0h} through @samp{zmm7h} for i386.
45358@item
45359@samp{zmm0h} through @samp{zmm15h} for amd64.
45360@end itemize
45361
45362It should
45363describe the additional @sc{zmm} registers:
45364
45365@itemize @minus
45366@item
45367@samp{zmm16h} through @samp{zmm31h}, only valid for amd64.
45368@end itemize
45369
51547df6
MS
45370The @samp{org.gnu.gdb.i386.pkeys} feature is optional. It should
45371describe a single register, @samp{pkru}. It is a 32-bit register
45372valid for i386 and amd64.
45373
164224e9
ME
45374@node MicroBlaze Features
45375@subsection MicroBlaze Features
45376@cindex target descriptions, MicroBlaze features
45377
45378The @samp{org.gnu.gdb.microblaze.core} feature is required for MicroBlaze
45379targets. It should contain registers @samp{r0} through @samp{r31},
45380@samp{rpc}, @samp{rmsr}, @samp{rear}, @samp{resr}, @samp{rfsr}, @samp{rbtr},
45381@samp{rpvr}, @samp{rpvr1} through @samp{rpvr11}, @samp{redr}, @samp{rpid},
45382@samp{rzpr}, @samp{rtlbx}, @samp{rtlbsx}, @samp{rtlblo}, and @samp{rtlbhi}.
45383
45384The @samp{org.gnu.gdb.microblaze.stack-protect} feature is optional.
45385If present, it should contain registers @samp{rshr} and @samp{rslr}
45386
1e26b4f8 45387@node MIPS Features
eb17f351
EZ
45388@subsection @acronym{MIPS} Features
45389@cindex target descriptions, @acronym{MIPS} features
f8b73d13 45390
eb17f351 45391The @samp{org.gnu.gdb.mips.cpu} feature is required for @acronym{MIPS} targets.
f8b73d13
DJ
45392It should contain registers @samp{r0} through @samp{r31}, @samp{lo},
45393@samp{hi}, and @samp{pc}. They may be 32-bit or 64-bit depending
45394on the target.
45395
45396The @samp{org.gnu.gdb.mips.cp0} feature is also required. It should
45397contain at least the @samp{status}, @samp{badvaddr}, and @samp{cause}
45398registers. They may be 32-bit or 64-bit depending on the target.
45399
45400The @samp{org.gnu.gdb.mips.fpu} feature is currently required, though
45401it may be optional in a future version of @value{GDBN}. It should
45402contain registers @samp{f0} through @samp{f31}, @samp{fcsr}, and
45403@samp{fir}. They may be 32-bit or 64-bit depending on the target.
45404
1faeff08
MR
45405The @samp{org.gnu.gdb.mips.dsp} feature is optional. It should
45406contain registers @samp{hi1} through @samp{hi3}, @samp{lo1} through
45407@samp{lo3}, and @samp{dspctl}. The @samp{dspctl} register should
45408be 32-bit and the rest may be 32-bit or 64-bit depending on the target.
45409
822b6570
DJ
45410The @samp{org.gnu.gdb.mips.linux} feature is optional. It should
45411contain a single register, @samp{restart}, which is used by the
45412Linux kernel to control restartable syscalls.
45413
e9c17194
VP
45414@node M68K Features
45415@subsection M68K Features
45416@cindex target descriptions, M68K features
45417
45418@table @code
45419@item @samp{org.gnu.gdb.m68k.core}
45420@itemx @samp{org.gnu.gdb.coldfire.core}
45421@itemx @samp{org.gnu.gdb.fido.core}
45422One of those features must be always present.
249e1128 45423The feature that is present determines which flavor of m68k is
e9c17194
VP
45424used. The feature that is present should contain registers
45425@samp{d0} through @samp{d7}, @samp{a0} through @samp{a5}, @samp{fp},
45426@samp{sp}, @samp{ps} and @samp{pc}.
45427
45428@item @samp{org.gnu.gdb.coldfire.fp}
45429This feature is optional. If present, it should contain registers
45430@samp{fp0} through @samp{fp7}, @samp{fpcontrol}, @samp{fpstatus} and
45431@samp{fpiaddr}.
b7d2fe14
TT
45432
45433Note that, despite the fact that this feature's name says
45434@samp{coldfire}, it is used to describe any floating point registers.
45435The size of the registers must match the main m68k flavor; so, for
45436example, if the primary feature is reported as @samp{coldfire}, then
4543764-bit floating point registers are required.
e9c17194
VP
45438@end table
45439
a28d8e50
YTL
45440@node NDS32 Features
45441@subsection NDS32 Features
45442@cindex target descriptions, NDS32 features
45443
45444The @samp{org.gnu.gdb.nds32.core} feature is required for NDS32
45445targets. It should contain at least registers @samp{r0} through
45446@samp{r10}, @samp{r15}, @samp{fp}, @samp{gp}, @samp{lp}, @samp{sp},
45447and @samp{pc}.
45448
45449The @samp{org.gnu.gdb.nds32.fpu} feature is optional. If present,
45450it should contain 64-bit double-precision floating-point registers
45451@samp{fd0} through @emph{fdN}, which should be @samp{fd3}, @samp{fd7},
45452@samp{fd15}, or @samp{fd31} based on the FPU configuration implemented.
45453
45454@emph{Note:} The first sixteen 64-bit double-precision floating-point
45455registers are overlapped with the thirty-two 32-bit single-precision
45456floating-point registers. The 32-bit single-precision registers, if
45457not being listed explicitly, will be synthesized from halves of the
45458overlapping 64-bit double-precision registers. Listing 32-bit
45459single-precision registers explicitly is deprecated, and the
45460support to it could be totally removed some day.
45461
a1217d97
SL
45462@node Nios II Features
45463@subsection Nios II Features
45464@cindex target descriptions, Nios II features
45465
45466The @samp{org.gnu.gdb.nios2.cpu} feature is required for Nios II
45467targets. It should contain the 32 core registers (@samp{zero},
45468@samp{at}, @samp{r2} through @samp{r23}, @samp{et} through @samp{ra}),
45469@samp{pc}, and the 16 control registers (@samp{status} through
45470@samp{mpuacc}).
45471
a994fec4
FJ
45472@node OpenRISC 1000 Features
45473@subsection Openrisc 1000 Features
45474@cindex target descriptions, OpenRISC 1000 features
45475
45476The @samp{org.gnu.gdb.or1k.group0} feature is required for OpenRISC 1000
45477targets. It should contain the 32 general purpose registers (@samp{r0}
45478through @samp{r31}), @samp{ppc}, @samp{npc} and @samp{sr}.
45479
1e26b4f8 45480@node PowerPC Features
7cc46491
DJ
45481@subsection PowerPC Features
45482@cindex target descriptions, PowerPC features
45483
45484The @samp{org.gnu.gdb.power.core} feature is required for PowerPC
45485targets. It should contain registers @samp{r0} through @samp{r31},
45486@samp{pc}, @samp{msr}, @samp{cr}, @samp{lr}, @samp{ctr}, and
45487@samp{xer}. They may be 32-bit or 64-bit depending on the target.
45488
45489The @samp{org.gnu.gdb.power.fpu} feature is optional. It should
45490contain registers @samp{f0} through @samp{f31} and @samp{fpscr}.
45491
45492The @samp{org.gnu.gdb.power.altivec} feature is optional. It should
6f072a10
PFC
45493contain registers @samp{vr0} through @samp{vr31}, @samp{vscr}, and
45494@samp{vrsave}. @value{GDBN} will define pseudo-registers @samp{v0}
45495through @samp{v31} as aliases for the corresponding @samp{vrX}
45496registers.
7cc46491 45497
677c5bb1 45498The @samp{org.gnu.gdb.power.vsx} feature is optional. It should
4b905ae1
PFC
45499contain registers @samp{vs0h} through @samp{vs31h}. @value{GDBN} will
45500combine these registers with the floating point registers (@samp{f0}
45501through @samp{f31}) and the altivec registers (@samp{vr0} through
45502@samp{vr31}) to present the 128-bit wide registers @samp{vs0} through
45503@samp{vs63}, the set of vector-scalar registers for POWER7.
45504Therefore, this feature requires both @samp{org.gnu.gdb.power.fpu} and
45505@samp{org.gnu.gdb.power.altivec}.
677c5bb1 45506
7cc46491
DJ
45507The @samp{org.gnu.gdb.power.spe} feature is optional. It should
45508contain registers @samp{ev0h} through @samp{ev31h}, @samp{acc}, and
45509@samp{spefscr}. SPE targets should provide 32-bit registers in
45510@samp{org.gnu.gdb.power.core} and provide the upper halves in
45511@samp{ev0h} through @samp{ev31h}. @value{GDBN} will combine
45512these to present registers @samp{ev0} through @samp{ev31} to the
45513user.
45514
7ca18ed6
EBM
45515The @samp{org.gnu.gdb.power.ppr} feature is optional. It should
45516contain the 64-bit register @samp{ppr}.
45517
45518The @samp{org.gnu.gdb.power.dscr} feature is optional. It should
45519contain the 64-bit register @samp{dscr}.
45520
f2cf6173
EBM
45521The @samp{org.gnu.gdb.power.tar} feature is optional. It should
45522contain the 64-bit register @samp{tar}.
45523
232bfb86
EBM
45524The @samp{org.gnu.gdb.power.ebb} feature is optional. It should
45525contain registers @samp{bescr}, @samp{ebbhr} and @samp{ebbrr}, all
4552664-bit wide.
45527
45528The @samp{org.gnu.gdb.power.linux.pmu} feature is optional. It should
45529contain registers @samp{mmcr0}, @samp{mmcr2}, @samp{siar}, @samp{sdar}
45530and @samp{sier}, all 64-bit wide. This is the subset of the isa 2.07
45531server PMU registers provided by @sc{gnu}/Linux.
45532
8d619c01
EBM
45533The @samp{org.gnu.gdb.power.htm.spr} feature is optional. It should
45534contain registers @samp{tfhar}, @samp{texasr} and @samp{tfiar}, all
4553564-bit wide.
45536
45537The @samp{org.gnu.gdb.power.htm.core} feature is optional. It should
45538contain the checkpointed general-purpose registers @samp{cr0} through
45539@samp{cr31}, as well as the checkpointed registers @samp{clr} and
45540@samp{cctr}. These registers may all be either 32-bit or 64-bit
45541depending on the target. It should also contain the checkpointed
45542registers @samp{ccr} and @samp{cxer}, which should both be 32-bit
45543wide.
45544
45545The @samp{org.gnu.gdb.power.htm.fpu} feature is optional. It should
45546contain the checkpointed 64-bit floating-point registers @samp{cf0}
45547through @samp{cf31}, as well as the checkpointed 64-bit register
45548@samp{cfpscr}.
45549
45550The @samp{org.gnu.gdb.power.htm.altivec} feature is optional. It
45551should contain the checkpointed altivec registers @samp{cvr0} through
45552@samp{cvr31}, all 128-bit wide. It should also contain the
45553checkpointed registers @samp{cvscr} and @samp{cvrsave}, both 32-bit
45554wide.
45555
45556The @samp{org.gnu.gdb.power.htm.vsx} feature is optional. It should
45557contain registers @samp{cvs0h} through @samp{cvs31h}. @value{GDBN}
45558will combine these registers with the checkpointed floating point
45559registers (@samp{cf0} through @samp{cf31}) and the checkpointed
45560altivec registers (@samp{cvr0} through @samp{cvr31}) to present the
45561128-bit wide checkpointed vector-scalar registers @samp{cvs0} through
45562@samp{cvs63}. Therefore, this feature requires both
45563@samp{org.gnu.gdb.power.htm.altivec} and
45564@samp{org.gnu.gdb.power.htm.fpu}.
45565
45566The @samp{org.gnu.gdb.power.htm.ppr} feature is optional. It should
45567contain the 64-bit checkpointed register @samp{cppr}.
45568
45569The @samp{org.gnu.gdb.power.htm.dscr} feature is optional. It should
45570contain the 64-bit checkpointed register @samp{cdscr}.
45571
45572The @samp{org.gnu.gdb.power.htm.tar} feature is optional. It should
45573contain the 64-bit checkpointed register @samp{ctar}.
45574
b5ffee31
AB
45575
45576@node RISC-V Features
45577@subsection RISC-V Features
45578@cindex target descriptions, RISC-V Features
45579
45580The @samp{org.gnu.gdb.riscv.cpu} feature is required for RISC-V
45581targets. It should contain the registers @samp{x0} through
45582@samp{x31}, and @samp{pc}. Either the architectural names (@samp{x0},
45583@samp{x1}, etc) can be used, or the ABI names (@samp{zero}, @samp{ra},
45584etc).
45585
45586The @samp{org.gnu.gdb.riscv.fpu} feature is optional. If present, it
45587should contain registers @samp{f0} through @samp{f31}, @samp{fflags},
45588@samp{frm}, and @samp{fcsr}. As with the cpu feature, either the
45589architectural register names, or the ABI names can be used.
45590
45591The @samp{org.gnu.gdb.riscv.virtual} feature is optional. If present,
45592it should contain registers that are not backed by real registers on
45593the target, but are instead virtual, where the register value is
45594derived from other target state. In many ways these are like
45595@value{GDBN}s pseudo-registers, except implemented by the target.
45596Currently the only register expected in this set is the one byte
45597@samp{priv} register that contains the target's privilege level in the
45598least significant two bits.
45599
45600The @samp{org.gnu.gdb.riscv.csr} feature is optional. If present, it
45601should contain all of the target's standard CSRs. Standard CSRs are
45602those defined in the RISC-V specification documents. There is some
45603overlap between this feature and the fpu feature; the @samp{fflags},
45604@samp{frm}, and @samp{fcsr} registers could be in either feature. The
45605expectation is that these registers will be in the fpu feature if the
45606target has floating point hardware, but can be moved into the csr
45607feature if the target has the floating point control registers, but no
45608other floating point hardware.
45609
e3ec872f
YS
45610@node RX Features
45611@subsection RX Features
45612@cindex target descriptions, RX Features
45613
45614The @samp{org.gnu.gdb.rx.core} feature is required for RX
45615targets. It should contain the registers @samp{r0} through
45616@samp{r15}, @samp{usp}, @samp{isp}, @samp{psw}, @samp{pc}, @samp{intb},
45617@samp{bpsw}, @samp{bpc}, @samp{fintv}, @samp{fpsw}, and @samp{acc}.
45618
4ac33720
UW
45619@node S/390 and System z Features
45620@subsection S/390 and System z Features
45621@cindex target descriptions, S/390 features
45622@cindex target descriptions, System z features
45623
45624The @samp{org.gnu.gdb.s390.core} feature is required for S/390 and
45625System z targets. It should contain the PSW and the 16 general
45626registers. In particular, System z targets should provide the 64-bit
45627registers @samp{pswm}, @samp{pswa}, and @samp{r0} through @samp{r15}.
45628S/390 targets should provide the 32-bit versions of these registers.
45629A System z target that runs in 31-bit addressing mode should provide
4563032-bit versions of @samp{pswm} and @samp{pswa}, as well as the general
45631register's upper halves @samp{r0h} through @samp{r15h}, and their
45632lower halves @samp{r0l} through @samp{r15l}.
45633
45634The @samp{org.gnu.gdb.s390.fpr} feature is required. It should
45635contain the 64-bit registers @samp{f0} through @samp{f15}, and
45636@samp{fpc}.
45637
45638The @samp{org.gnu.gdb.s390.acr} feature is required. It should
45639contain the 32-bit registers @samp{acr0} through @samp{acr15}.
45640
45641The @samp{org.gnu.gdb.s390.linux} feature is optional. It should
45642contain the register @samp{orig_r2}, which is 64-bit wide on System z
45643targets and 32-bit otherwise. In addition, the feature may contain
45644the @samp{last_break} register, whose width depends on the addressing
45645mode, as well as the @samp{system_call} register, which is always
4564632-bit wide.
45647
45648The @samp{org.gnu.gdb.s390.tdb} feature is optional. It should
45649contain the 64-bit registers @samp{tdb0}, @samp{tac}, @samp{tct},
45650@samp{atia}, and @samp{tr0} through @samp{tr15}.
45651
446899e4
AA
45652The @samp{org.gnu.gdb.s390.vx} feature is optional. It should contain
4565364-bit wide registers @samp{v0l} through @samp{v15l}, which will be
45654combined by @value{GDBN} with the floating point registers @samp{f0}
45655through @samp{f15} to present the 128-bit wide vector registers
45656@samp{v0} through @samp{v15}. In addition, this feature should
45657contain the 128-bit wide vector registers @samp{v16} through
45658@samp{v31}.
45659
289e23aa
AA
45660The @samp{org.gnu.gdb.s390.gs} feature is optional. It should contain
45661the 64-bit wide guarded-storage-control registers @samp{gsd},
45662@samp{gssm}, and @samp{gsepla}.
45663
45664The @samp{org.gnu.gdb.s390.gsbc} feature is optional. It should contain
45665the 64-bit wide guarded-storage broadcast control registers
45666@samp{bc_gsd}, @samp{bc_gssm}, and @samp{bc_gsepla}.
45667
3f7b46f2
IR
45668@node Sparc Features
45669@subsection Sparc Features
45670@cindex target descriptions, sparc32 features
45671@cindex target descriptions, sparc64 features
45672The @samp{org.gnu.gdb.sparc.cpu} feature is required for sparc32/sparc64
45673targets. It should describe the following registers:
45674
45675@itemize @minus
45676@item
45677@samp{g0} through @samp{g7}
45678@item
45679@samp{o0} through @samp{o7}
45680@item
45681@samp{l0} through @samp{l7}
45682@item
45683@samp{i0} through @samp{i7}
45684@end itemize
45685
45686They may be 32-bit or 64-bit depending on the target.
45687
45688Also the @samp{org.gnu.gdb.sparc.fpu} feature is required for sparc32/sparc64
45689targets. It should describe the following registers:
45690
45691@itemize @minus
45692@item
45693@samp{f0} through @samp{f31}
45694@item
45695@samp{f32} through @samp{f62} for sparc64
45696@end itemize
45697
45698The @samp{org.gnu.gdb.sparc.cp0} feature is required for sparc32/sparc64
45699targets. It should describe the following registers:
45700
45701@itemize @minus
45702@item
45703@samp{y}, @samp{psr}, @samp{wim}, @samp{tbr}, @samp{pc}, @samp{npc},
45704@samp{fsr}, and @samp{csr} for sparc32
45705@item
45706@samp{pc}, @samp{npc}, @samp{state}, @samp{fsr}, @samp{fprs}, and @samp{y}
45707for sparc64
45708@end itemize
45709
224bbe49
YQ
45710@node TIC6x Features
45711@subsection TMS320C6x Features
45712@cindex target descriptions, TIC6x features
45713@cindex target descriptions, TMS320C6x features
45714The @samp{org.gnu.gdb.tic6x.core} feature is required for TMS320C6x
45715targets. It should contain registers @samp{A0} through @samp{A15},
45716registers @samp{B0} through @samp{B15}, @samp{CSR} and @samp{PC}.
45717
45718The @samp{org.gnu.gdb.tic6x.gp} feature is optional. It should
45719contain registers @samp{A16} through @samp{A31} and @samp{B16}
45720through @samp{B31}.
45721
45722The @samp{org.gnu.gdb.tic6x.c6xp} feature is optional. It should
45723contain registers @samp{TSR}, @samp{ILC} and @samp{RILC}.
45724
07e059b5
VP
45725@node Operating System Information
45726@appendix Operating System Information
45727@cindex operating system information
45728
45729@menu
45730* Process list::
45731@end menu
45732
45733Users of @value{GDBN} often wish to obtain information about the state of
45734the operating system running on the target---for example the list of
45735processes, or the list of open files. This section describes the
45736mechanism that makes it possible. This mechanism is similar to the
45737target features mechanism (@pxref{Target Descriptions}), but focuses
45738on a different aspect of target.
45739
6b92c0d3 45740Operating system information is retrieved from the target via the
07e059b5
VP
45741remote protocol, using @samp{qXfer} requests (@pxref{qXfer osdata
45742read}). The object name in the request should be @samp{osdata}, and
45743the @var{annex} identifies the data to be fetched.
45744
45745@node Process list
45746@appendixsection Process list
45747@cindex operating system information, process list
45748
45749When requesting the process list, the @var{annex} field in the
45750@samp{qXfer} request should be @samp{processes}. The returned data is
45751an XML document. The formal syntax of this document is defined in
45752@file{gdb/features/osdata.dtd}.
45753
45754An example document is:
45755
45756@smallexample
45757<?xml version="1.0"?>
45758<!DOCTYPE target SYSTEM "osdata.dtd">
45759<osdata type="processes">
45760 <item>
45761 <column name="pid">1</column>
45762 <column name="user">root</column>
45763 <column name="command">/sbin/init</column>
dc146f7c 45764 <column name="cores">1,2,3</column>
07e059b5
VP
45765 </item>
45766</osdata>
45767@end smallexample
45768
45769Each item should include a column whose name is @samp{pid}. The value
45770of that column should identify the process on the target. The
45771@samp{user} and @samp{command} columns are optional, and will be
dc146f7c
VP
45772displayed by @value{GDBN}. The @samp{cores} column, if present,
45773should contain a comma-separated list of cores that this process
45774is running on. Target may provide additional columns,
07e059b5
VP
45775which @value{GDBN} currently ignores.
45776
05c8c3f5
TT
45777@node Trace File Format
45778@appendix Trace File Format
45779@cindex trace file format
45780
45781The trace file comes in three parts: a header, a textual description
45782section, and a trace frame section with binary data.
45783
45784The header has the form @code{\x7fTRACE0\n}. The first byte is
45785@code{0x7f} so as to indicate that the file contains binary data,
45786while the @code{0} is a version number that may have different values
45787in the future.
45788
45789The description section consists of multiple lines of @sc{ascii} text
45790separated by newline characters (@code{0xa}). The lines may include a
45791variety of optional descriptive or context-setting information, such
45792as tracepoint definitions or register set size. @value{GDBN} will
45793ignore any line that it does not recognize. An empty line marks the end
45794of this section.
45795
0748bf3e
MK
45796@table @code
45797@item R @var{size}
45798Specifies the size of a register block in bytes. This is equal to the
45799size of a @code{g} packet payload in the remote protocol. @var{size}
45800is an ascii decimal number. There should be only one such line in
45801a single trace file.
45802
45803@item status @var{status}
45804Trace status. @var{status} has the same format as a @code{qTStatus}
45805remote packet reply. There should be only one such line in a single trace
45806file.
45807
45808@item tp @var{payload}
45809Tracepoint definition. The @var{payload} has the same format as
45810@code{qTfP}/@code{qTsP} remote packet reply payload. A single tracepoint
45811may take multiple lines of definition, corresponding to the multiple
45812reply packets.
45813
45814@item tsv @var{payload}
45815Trace state variable definition. The @var{payload} has the same format as
45816@code{qTfV}/@code{qTsV} remote packet reply payload. A single variable
45817may take multiple lines of definition, corresponding to the multiple
45818reply packets.
45819
45820@item tdesc @var{payload}
45821Target description in XML format. The @var{payload} is a single line of
45822the XML file. All such lines should be concatenated together to get
45823the original XML file. This file is in the same format as @code{qXfer}
45824@code{features} payload, and corresponds to the main @code{target.xml}
45825file. Includes are not allowed.
45826
45827@end table
05c8c3f5
TT
45828
45829The trace frame section consists of a number of consecutive frames.
45830Each frame begins with a two-byte tracepoint number, followed by a
45831four-byte size giving the amount of data in the frame. The data in
45832the frame consists of a number of blocks, each introduced by a
45833character indicating its type (at least register, memory, and trace
45834state variable). The data in this section is raw binary, not a
45835hexadecimal or other encoding; its endianness matches the target's
45836endianness.
45837
45838@c FIXME bi-arch may require endianness/arch info in description section
45839
45840@table @code
45841@item R @var{bytes}
45842Register block. The number and ordering of bytes matches that of a
45843@code{g} packet in the remote protocol. Note that these are the
e909d859 45844actual bytes, in target order, not a hexadecimal encoding.
05c8c3f5
TT
45845
45846@item M @var{address} @var{length} @var{bytes}...
45847Memory block. This is a contiguous block of memory, at the 8-byte
45848address @var{address}, with a 2-byte length @var{length}, followed by
45849@var{length} bytes.
45850
45851@item V @var{number} @var{value}
45852Trace state variable block. This records the 8-byte signed value
45853@var{value} of trace state variable numbered @var{number}.
45854
45855@end table
45856
45857Future enhancements of the trace file format may include additional types
45858of blocks.
45859
90476074
TT
45860@node Index Section Format
45861@appendix @code{.gdb_index} section format
45862@cindex .gdb_index section format
45863@cindex index section format
45864
45865This section documents the index section that is created by @code{save
45866gdb-index} (@pxref{Index Files}). The index section is
45867DWARF-specific; some knowledge of DWARF is assumed in this
45868description.
45869
45870The mapped index file format is designed to be directly
45871@code{mmap}able on any architecture. In most cases, a datum is
45872represented using a little-endian 32-bit integer value, called an
45873@code{offset_type}. Big endian machines must byte-swap the values
45874before using them. Exceptions to this rule are noted. The data is
45875laid out such that alignment is always respected.
45876
45877A mapped index consists of several areas, laid out in order.
45878
45879@enumerate
45880@item
45881The file header. This is a sequence of values, of @code{offset_type}
45882unless otherwise noted:
45883
45884@enumerate
45885@item
796a7ff8 45886The version number, currently 8. Versions 1, 2 and 3 are obsolete.
481860b3 45887Version 4 uses a different hashing function from versions 5 and 6.
b6ba681c
TT
45888Version 6 includes symbols for inlined functions, whereas versions 4
45889and 5 do not. Version 7 adds attributes to the CU indices in the
796a7ff8
DE
45890symbol table. Version 8 specifies that symbols from DWARF type units
45891(@samp{DW_TAG_type_unit}) refer to the type unit's symbol table and not the
45892compilation unit (@samp{DW_TAG_comp_unit}) using the type.
45893
45894@value{GDBN} will only read version 4, 5, or 6 indices
e615022a 45895by specifying @code{set use-deprecated-index-sections on}.
796a7ff8
DE
45896GDB has a workaround for potentially broken version 7 indices so it is
45897currently not flagged as deprecated.
90476074
TT
45898
45899@item
45900The offset, from the start of the file, of the CU list.
45901
45902@item
45903The offset, from the start of the file, of the types CU list. Note
45904that this area can be empty, in which case this offset will be equal
45905to the next offset.
45906
45907@item
45908The offset, from the start of the file, of the address area.
45909
45910@item
45911The offset, from the start of the file, of the symbol table.
45912
45913@item
45914The offset, from the start of the file, of the constant pool.
45915@end enumerate
45916
45917@item
45918The CU list. This is a sequence of pairs of 64-bit little-endian
45919values, sorted by the CU offset. The first element in each pair is
45920the offset of a CU in the @code{.debug_info} section. The second
45921element in each pair is the length of that CU. References to a CU
45922elsewhere in the map are done using a CU index, which is just the
459230-based index into this table. Note that if there are type CUs, then
45924conceptually CUs and type CUs form a single list for the purposes of
45925CU indices.
45926
45927@item
45928The types CU list. This is a sequence of triplets of 64-bit
45929little-endian values. In a triplet, the first value is the CU offset,
45930the second value is the type offset in the CU, and the third value is
45931the type signature. The types CU list is not sorted.
45932
45933@item
45934The address area. The address area consists of a sequence of address
45935entries. Each address entry has three elements:
45936
45937@enumerate
45938@item
45939The low address. This is a 64-bit little-endian value.
45940
45941@item
45942The high address. This is a 64-bit little-endian value. Like
45943@code{DW_AT_high_pc}, the value is one byte beyond the end.
45944
45945@item
45946The CU index. This is an @code{offset_type} value.
45947@end enumerate
45948
45949@item
45950The symbol table. This is an open-addressed hash table. The size of
45951the hash table is always a power of 2.
45952
45953Each slot in the hash table consists of a pair of @code{offset_type}
45954values. The first value is the offset of the symbol's name in the
45955constant pool. The second value is the offset of the CU vector in the
45956constant pool.
45957
45958If both values are 0, then this slot in the hash table is empty. This
45959is ok because while 0 is a valid constant pool index, it cannot be a
45960valid index for both a string and a CU vector.
45961
45962The hash value for a table entry is computed by applying an
45963iterative hash function to the symbol's name. Starting with an
45964initial value of @code{r = 0}, each (unsigned) character @samp{c} in
559a7a62
JK
45965the string is incorporated into the hash using the formula depending on the
45966index version:
45967
45968@table @asis
45969@item Version 4
45970The formula is @code{r = r * 67 + c - 113}.
45971
156942c7 45972@item Versions 5 to 7
559a7a62
JK
45973The formula is @code{r = r * 67 + tolower (c) - 113}.
45974@end table
45975
45976The terminating @samp{\0} is not incorporated into the hash.
90476074
TT
45977
45978The step size used in the hash table is computed via
45979@code{((hash * 17) & (size - 1)) | 1}, where @samp{hash} is the hash
45980value, and @samp{size} is the size of the hash table. The step size
45981is used to find the next candidate slot when handling a hash
45982collision.
45983
45984The names of C@t{++} symbols in the hash table are canonicalized. We
45985don't currently have a simple description of the canonicalization
45986algorithm; if you intend to create new index sections, you must read
45987the code.
45988
45989@item
45990The constant pool. This is simply a bunch of bytes. It is organized
45991so that alignment is correct: CU vectors are stored first, followed by
45992strings.
45993
45994A CU vector in the constant pool is a sequence of @code{offset_type}
45995values. The first value is the number of CU indices in the vector.
156942c7
DE
45996Each subsequent value is the index and symbol attributes of a CU in
45997the CU list. This element in the hash table is used to indicate which
45998CUs define the symbol and how the symbol is used.
45999See below for the format of each CU index+attributes entry.
90476074
TT
46000
46001A string in the constant pool is zero-terminated.
46002@end enumerate
46003
156942c7
DE
46004Attributes were added to CU index values in @code{.gdb_index} version 7.
46005If a symbol has multiple uses within a CU then there is one
46006CU index+attributes value for each use.
46007
46008The format of each CU index+attributes entry is as follows
46009(bit 0 = LSB):
46010
46011@table @asis
46012
46013@item Bits 0-23
46014This is the index of the CU in the CU list.
46015@item Bits 24-27
46016These bits are reserved for future purposes and must be zero.
46017@item Bits 28-30
46018The kind of the symbol in the CU.
46019
46020@table @asis
46021@item 0
46022This value is reserved and should not be used.
46023By reserving zero the full @code{offset_type} value is backwards compatible
46024with previous versions of the index.
46025@item 1
46026The symbol is a type.
46027@item 2
46028The symbol is a variable or an enum value.
46029@item 3
46030The symbol is a function.
46031@item 4
46032Any other kind of symbol.
46033@item 5,6,7
46034These values are reserved.
46035@end table
46036
46037@item Bit 31
46038This bit is zero if the value is global and one if it is static.
46039
46040The determination of whether a symbol is global or static is complicated.
46041The authorative reference is the file @file{dwarf2read.c} in
46042@value{GDBN} sources.
46043
46044@end table
46045
46046This pseudo-code describes the computation of a symbol's kind and
46047global/static attributes in the index.
46048
46049@smallexample
46050is_external = get_attribute (die, DW_AT_external);
46051language = get_attribute (cu_die, DW_AT_language);
46052switch (die->tag)
46053 @{
46054 case DW_TAG_typedef:
46055 case DW_TAG_base_type:
46056 case DW_TAG_subrange_type:
46057 kind = TYPE;
46058 is_static = 1;
46059 break;
46060 case DW_TAG_enumerator:
46061 kind = VARIABLE;
9c37b5ae 46062 is_static = language != CPLUS;
156942c7
DE
46063 break;
46064 case DW_TAG_subprogram:
46065 kind = FUNCTION;
46066 is_static = ! (is_external || language == ADA);
46067 break;
46068 case DW_TAG_constant:
46069 kind = VARIABLE;
46070 is_static = ! is_external;
46071 break;
46072 case DW_TAG_variable:
46073 kind = VARIABLE;
46074 is_static = ! is_external;
46075 break;
46076 case DW_TAG_namespace:
46077 kind = TYPE;
46078 is_static = 0;
46079 break;
46080 case DW_TAG_class_type:
46081 case DW_TAG_interface_type:
46082 case DW_TAG_structure_type:
46083 case DW_TAG_union_type:
46084 case DW_TAG_enumeration_type:
46085 kind = TYPE;
9c37b5ae 46086 is_static = language != CPLUS;
156942c7
DE
46087 break;
46088 default:
46089 assert (0);
46090 @}
46091@end smallexample
46092
43662968
JK
46093@node Man Pages
46094@appendix Manual pages
46095@cindex Man pages
46096
46097@menu
46098* gdb man:: The GNU Debugger man page
46099* gdbserver man:: Remote Server for the GNU Debugger man page
b292c783 46100* gcore man:: Generate a core file of a running program
43662968 46101* gdbinit man:: gdbinit scripts
ba643918 46102* gdb-add-index man:: Add index files to speed up GDB
43662968
JK
46103@end menu
46104
46105@node gdb man
46106@heading gdb man
46107
46108@c man title gdb The GNU Debugger
46109
46110@c man begin SYNOPSIS gdb
46111gdb [@option{-help}] [@option{-nh}] [@option{-nx}] [@option{-q}]
46112[@option{-batch}] [@option{-cd=}@var{dir}] [@option{-f}]
46113[@option{-b}@w{ }@var{bps}]
46114 [@option{-tty=}@var{dev}] [@option{-s} @var{symfile}]
46115[@option{-e}@w{ }@var{prog}] [@option{-se}@w{ }@var{prog}]
906ccdf0
JK
46116[@option{-c}@w{ }@var{core}] [@option{-p}@w{ }@var{procID}]
46117 [@option{-x}@w{ }@var{cmds}] [@option{-d}@w{ }@var{dir}]
46118[@var{prog}|@var{prog} @var{procID}|@var{prog} @var{core}]
43662968
JK
46119@c man end
46120
46121@c man begin DESCRIPTION gdb
46122The purpose of a debugger such as @value{GDBN} is to allow you to see what is
46123going on ``inside'' another program while it executes -- or what another
46124program was doing at the moment it crashed.
46125
46126@value{GDBN} can do four main kinds of things (plus other things in support of
46127these) to help you catch bugs in the act:
46128
46129@itemize @bullet
46130@item
46131Start your program, specifying anything that might affect its behavior.
46132
46133@item
46134Make your program stop on specified conditions.
46135
46136@item
46137Examine what has happened, when your program has stopped.
46138
46139@item
46140Change things in your program, so you can experiment with correcting the
46141effects of one bug and go on to learn about another.
46142@end itemize
46143
906ccdf0
JK
46144You can use @value{GDBN} to debug programs written in C, C@t{++}, Fortran and
46145Modula-2.
43662968
JK
46146
46147@value{GDBN} is invoked with the shell command @code{gdb}. Once started, it reads
46148commands from the terminal until you tell it to exit with the @value{GDBN}
46149command @code{quit}. You can get online help from @value{GDBN} itself
46150by using the command @code{help}.
46151
46152You can run @code{gdb} with no arguments or options; but the most
46153usual way to start @value{GDBN} is with one argument or two, specifying an
46154executable program as the argument:
46155
46156@smallexample
46157gdb program
46158@end smallexample
46159
46160You can also start with both an executable program and a core file specified:
46161
46162@smallexample
46163gdb program core
46164@end smallexample
46165
4ed4690f
SM
46166You can, instead, specify a process ID as a second argument or use option
46167@code{-p}, if you want to debug a running process:
43662968
JK
46168
46169@smallexample
46170gdb program 1234
906ccdf0 46171gdb -p 1234
43662968
JK
46172@end smallexample
46173
46174@noindent
4ed4690f
SM
46175would attach @value{GDBN} to process @code{1234}. With option @option{-p} you
46176can omit the @var{program} filename.
43662968
JK
46177
46178Here are some of the most frequently needed @value{GDBN} commands:
46179
46180@c pod2man highlights the right hand side of the @item lines.
46181@table @env
224f10c1 46182@item break [@var{file}:]@var{function}
43662968
JK
46183Set a breakpoint at @var{function} (in @var{file}).
46184
46185@item run [@var{arglist}]
46186Start your program (with @var{arglist}, if specified).
46187
46188@item bt
46189Backtrace: display the program stack.
46190
46191@item print @var{expr}
46192Display the value of an expression.
46193
46194@item c
46195Continue running your program (after stopping, e.g. at a breakpoint).
46196
46197@item next
46198Execute next program line (after stopping); step @emph{over} any
46199function calls in the line.
46200
46201@item edit [@var{file}:]@var{function}
46202look at the program line where it is presently stopped.
46203
46204@item list [@var{file}:]@var{function}
46205type the text of the program in the vicinity of where it is presently stopped.
46206
46207@item step
46208Execute next program line (after stopping); step @emph{into} any
46209function calls in the line.
46210
46211@item help [@var{name}]
46212Show information about @value{GDBN} command @var{name}, or general information
46213about using @value{GDBN}.
46214
46215@item quit
46216Exit from @value{GDBN}.
46217@end table
46218
46219@ifset man
46220For full details on @value{GDBN},
46221see @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46222by Richard M. Stallman and Roland H. Pesch. The same text is available online
46223as the @code{gdb} entry in the @code{info} program.
46224@end ifset
46225@c man end
46226
46227@c man begin OPTIONS gdb
46228Any arguments other than options specify an executable
46229file and core file (or process ID); that is, the first argument
46230encountered with no
46231associated option flag is equivalent to a @option{-se} option, and the second,
46232if any, is equivalent to a @option{-c} option if it's the name of a file.
46233Many options have
46234both long and short forms; both are shown here. The long forms are also
46235recognized if you truncate them, so long as enough of the option is
46236present to be unambiguous. (If you prefer, you can flag option
46237arguments with @option{+} rather than @option{-}, though we illustrate the
46238more usual convention.)
46239
46240All the options and command line arguments you give are processed
46241in sequential order. The order makes a difference when the @option{-x}
46242option is used.
46243
46244@table @env
46245@item -help
46246@itemx -h
46247List all options, with brief explanations.
46248
46249@item -symbols=@var{file}
46250@itemx -s @var{file}
46251Read symbol table from file @var{file}.
46252
46253@item -write
46254Enable writing into executable and core files.
46255
46256@item -exec=@var{file}
46257@itemx -e @var{file}
46258Use file @var{file} as the executable file to execute when
46259appropriate, and for examining pure data in conjunction with a core
46260dump.
46261
46262@item -se=@var{file}
46263Read symbol table from file @var{file} and use it as the executable
46264file.
46265
46266@item -core=@var{file}
46267@itemx -c @var{file}
46268Use file @var{file} as a core dump to examine.
46269
46270@item -command=@var{file}
46271@itemx -x @var{file}
46272Execute @value{GDBN} commands from file @var{file}.
46273
46274@item -ex @var{command}
46275Execute given @value{GDBN} @var{command}.
46276
46277@item -directory=@var{directory}
46278@itemx -d @var{directory}
46279Add @var{directory} to the path to search for source files.
46280
46281@item -nh
46282Do not execute commands from @file{~/.gdbinit}.
46283
46284@item -nx
46285@itemx -n
46286Do not execute commands from any @file{.gdbinit} initialization files.
46287
46288@item -quiet
46289@itemx -q
46290``Quiet''. Do not print the introductory and copyright messages. These
46291messages are also suppressed in batch mode.
46292
46293@item -batch
46294Run in batch mode. Exit with status @code{0} after processing all the command
46295files specified with @option{-x} (and @file{.gdbinit}, if not inhibited).
46296Exit with nonzero status if an error occurs in executing the @value{GDBN}
46297commands in the command files.
46298
46299Batch mode may be useful for running @value{GDBN} as a filter, for example to
46300download and run a program on another computer; in order to make this
46301more useful, the message
46302
46303@smallexample
46304Program exited normally.
46305@end smallexample
46306
46307@noindent
46308(which is ordinarily issued whenever a program running under @value{GDBN} control
46309terminates) is not issued when running in batch mode.
46310
46311@item -cd=@var{directory}
46312Run @value{GDBN} using @var{directory} as its working directory,
46313instead of the current directory.
46314
46315@item -fullname
46316@itemx -f
46317Emacs sets this option when it runs @value{GDBN} as a subprocess. It tells
46318@value{GDBN} to output the full file name and line number in a standard,
46319recognizable fashion each time a stack frame is displayed (which
46320includes each time the program stops). This recognizable format looks
46321like two @samp{\032} characters, followed by the file name, line number
46322and character position separated by colons, and a newline. The
46323Emacs-to-@value{GDBN} interface program uses the two @samp{\032}
46324characters as a signal to display the source code for the frame.
46325
46326@item -b @var{bps}
46327Set the line speed (baud rate or bits per second) of any serial
46328interface used by @value{GDBN} for remote debugging.
46329
46330@item -tty=@var{device}
46331Run using @var{device} for your program's standard input and output.
46332@end table
46333@c man end
46334
46335@c man begin SEEALSO gdb
46336@ifset man
46337The full documentation for @value{GDBN} is maintained as a Texinfo manual.
46338If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
46339documentation are properly installed at your site, the command
46340
46341@smallexample
46342info gdb
46343@end smallexample
46344
46345@noindent
46346should give you access to the complete manual.
46347
46348@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46349Richard M. Stallman and Roland H. Pesch, July 1991.
46350@end ifset
46351@c man end
46352
46353@node gdbserver man
46354@heading gdbserver man
46355
46356@c man title gdbserver Remote Server for the GNU Debugger
46357@format
46358@c man begin SYNOPSIS gdbserver
5b8b6385 46359gdbserver @var{comm} @var{prog} [@var{args}@dots{}]
43662968 46360
5b8b6385
JK
46361gdbserver --attach @var{comm} @var{pid}
46362
46363gdbserver --multi @var{comm}
43662968
JK
46364@c man end
46365@end format
46366
46367@c man begin DESCRIPTION gdbserver
46368@command{gdbserver} is a program that allows you to run @value{GDBN} on a different machine
46369than the one which is running the program being debugged.
46370
46371@ifclear man
46372@subheading Usage (server (target) side)
46373@end ifclear
46374@ifset man
46375Usage (server (target) side):
46376@end ifset
46377
46378First, you need to have a copy of the program you want to debug put onto
46379the target system. The program can be stripped to save space if needed, as
46380@command{gdbserver} doesn't care about symbols. All symbol handling is taken care of by
46381the @value{GDBN} running on the host system.
46382
46383To use the server, you log on to the target system, and run the @command{gdbserver}
46384program. You must tell it (a) how to communicate with @value{GDBN}, (b) the name of
46385your program, and (c) its arguments. The general syntax is:
46386
46387@smallexample
46388target> gdbserver @var{comm} @var{program} [@var{args} ...]
46389@end smallexample
46390
46391For example, using a serial port, you might say:
46392
46393@smallexample
46394@ifset man
46395@c @file would wrap it as F</dev/com1>.
46396target> gdbserver /dev/com1 emacs foo.txt
46397@end ifset
46398@ifclear man
46399target> gdbserver @file{/dev/com1} emacs foo.txt
46400@end ifclear
46401@end smallexample
46402
46403This tells @command{gdbserver} to debug emacs with an argument of foo.txt, and
46404to communicate with @value{GDBN} via @file{/dev/com1}. @command{gdbserver} now
46405waits patiently for the host @value{GDBN} to communicate with it.
46406
46407To use a TCP connection, you could say:
46408
46409@smallexample
46410target> gdbserver host:2345 emacs foo.txt
46411@end smallexample
46412
46413This says pretty much the same thing as the last example, except that we are
46414going to communicate with the @code{host} @value{GDBN} via TCP. The @code{host:2345} argument means
46415that we are expecting to see a TCP connection from @code{host} to local TCP port
464162345. (Currently, the @code{host} part is ignored.) You can choose any number you
46417want for the port number as long as it does not conflict with any existing TCP
46418ports on the target system. This same port number must be used in the host
46419@value{GDBN}s @code{target remote} command, which will be described shortly. Note that if
46420you chose a port number that conflicts with another service, @command{gdbserver} will
46421print an error message and exit.
46422
5b8b6385 46423@command{gdbserver} can also attach to running programs.
43662968
JK
46424This is accomplished via the @option{--attach} argument. The syntax is:
46425
46426@smallexample
5b8b6385 46427target> gdbserver --attach @var{comm} @var{pid}
43662968
JK
46428@end smallexample
46429
46430@var{pid} is the process ID of a currently running process. It isn't
46431necessary to point @command{gdbserver} at a binary for the running process.
46432
5b8b6385
JK
46433To start @code{gdbserver} without supplying an initial command to run
46434or process ID to attach, use the @option{--multi} command line option.
46435In such case you should connect using @kbd{target extended-remote} to start
46436the program you want to debug.
46437
46438@smallexample
46439target> gdbserver --multi @var{comm}
46440@end smallexample
46441
43662968
JK
46442@ifclear man
46443@subheading Usage (host side)
46444@end ifclear
46445@ifset man
46446Usage (host side):
46447@end ifset
46448
46449You need an unstripped copy of the target program on your host system, since
1a088a2e 46450@value{GDBN} needs to examine its symbol tables and such. Start up @value{GDBN} as you normally
43662968
JK
46451would, with the target program as the first argument. (You may need to use the
46452@option{--baud} option if the serial line is running at anything except 9600 baud.)
46453That is @code{gdb TARGET-PROG}, or @code{gdb --baud BAUD TARGET-PROG}. After that, the only
5b8b6385
JK
46454new command you need to know about is @code{target remote}
46455(or @code{target extended-remote}). Its argument is either
43662968
JK
46456a device name (usually a serial device, like @file{/dev/ttyb}), or a @code{HOST:PORT}
46457descriptor. For example:
46458
46459@smallexample
46460@ifset man
46461@c @file would wrap it as F</dev/ttyb>.
46462(gdb) target remote /dev/ttyb
46463@end ifset
46464@ifclear man
46465(gdb) target remote @file{/dev/ttyb}
46466@end ifclear
46467@end smallexample
46468
46469@noindent
46470communicates with the server via serial line @file{/dev/ttyb}, and:
46471
46472@smallexample
46473(gdb) target remote the-target:2345
46474@end smallexample
46475
46476@noindent
46477communicates via a TCP connection to port 2345 on host `the-target', where
46478you previously started up @command{gdbserver} with the same port number. Note that for
46479TCP connections, you must start up @command{gdbserver} prior to using the `target remote'
46480command, otherwise you may get an error that looks something like
46481`Connection refused'.
5b8b6385
JK
46482
46483@command{gdbserver} can also debug multiple inferiors at once,
46484described in
46485@ifset man
65c574f6
PA
46486the @value{GDBN} manual in node @code{Inferiors Connections and Programs}
46487-- shell command @code{info -f gdb -n 'Inferiors Connections and Programs'}.
5b8b6385
JK
46488@end ifset
46489@ifclear man
65c574f6 46490@ref{Inferiors Connections and Programs}.
5b8b6385
JK
46491@end ifclear
46492In such case use the @code{extended-remote} @value{GDBN} command variant:
46493
46494@smallexample
46495(gdb) target extended-remote the-target:2345
46496@end smallexample
46497
46498The @command{gdbserver} option @option{--multi} may or may not be used in such
46499case.
43662968
JK
46500@c man end
46501
46502@c man begin OPTIONS gdbserver
5b8b6385
JK
46503There are three different modes for invoking @command{gdbserver}:
46504
46505@itemize @bullet
46506
46507@item
46508Debug a specific program specified by its program name:
46509
46510@smallexample
46511gdbserver @var{comm} @var{prog} [@var{args}@dots{}]
46512@end smallexample
46513
46514The @var{comm} parameter specifies how should the server communicate
46515with @value{GDBN}; it is either a device name (to use a serial line),
46516a TCP port number (@code{:1234}), or @code{-} or @code{stdio} to use
46517stdin/stdout of @code{gdbserver}. Specify the name of the program to
46518debug in @var{prog}. Any remaining arguments will be passed to the
46519program verbatim. When the program exits, @value{GDBN} will close the
46520connection, and @code{gdbserver} will exit.
46521
46522@item
46523Debug a specific program by specifying the process ID of a running
46524program:
46525
46526@smallexample
46527gdbserver --attach @var{comm} @var{pid}
46528@end smallexample
46529
46530The @var{comm} parameter is as described above. Supply the process ID
46531of a running program in @var{pid}; @value{GDBN} will do everything
46532else. Like with the previous mode, when the process @var{pid} exits,
46533@value{GDBN} will close the connection, and @code{gdbserver} will exit.
46534
46535@item
46536Multi-process mode -- debug more than one program/process:
46537
46538@smallexample
46539gdbserver --multi @var{comm}
46540@end smallexample
46541
46542In this mode, @value{GDBN} can instruct @command{gdbserver} which
46543command(s) to run. Unlike the other 2 modes, @value{GDBN} will not
46544close the connection when a process being debugged exits, so you can
46545debug several processes in the same session.
46546@end itemize
46547
46548In each of the modes you may specify these options:
46549
46550@table @env
46551
46552@item --help
46553List all options, with brief explanations.
46554
46555@item --version
46556This option causes @command{gdbserver} to print its version number and exit.
46557
46558@item --attach
46559@command{gdbserver} will attach to a running program. The syntax is:
46560
46561@smallexample
46562target> gdbserver --attach @var{comm} @var{pid}
46563@end smallexample
46564
46565@var{pid} is the process ID of a currently running process. It isn't
46566necessary to point @command{gdbserver} at a binary for the running process.
46567
46568@item --multi
46569To start @code{gdbserver} without supplying an initial command to run
46570or process ID to attach, use this command line option.
46571Then you can connect using @kbd{target extended-remote} and start
46572the program you want to debug. The syntax is:
46573
46574@smallexample
46575target> gdbserver --multi @var{comm}
46576@end smallexample
46577
46578@item --debug
46579Instruct @code{gdbserver} to display extra status information about the debugging
46580process.
46581This option is intended for @code{gdbserver} development and for bug reports to
46582the developers.
46583
46584@item --remote-debug
46585Instruct @code{gdbserver} to display remote protocol debug output.
46586This option is intended for @code{gdbserver} development and for bug reports to
46587the developers.
46588
aeb2e706
AH
46589@item --debug-file=@var{filename}
46590Instruct @code{gdbserver} to send any debug output to the given @var{filename}.
46591This option is intended for @code{gdbserver} development and for bug reports to
46592the developers.
46593
87ce2a04
DE
46594@item --debug-format=option1@r{[},option2,...@r{]}
46595Instruct @code{gdbserver} to include extra information in each line
46596of debugging output.
46597@xref{Other Command-Line Arguments for gdbserver}.
46598
5b8b6385
JK
46599@item --wrapper
46600Specify a wrapper to launch programs
46601for debugging. The option should be followed by the name of the
46602wrapper, then any command-line arguments to pass to the wrapper, then
46603@kbd{--} indicating the end of the wrapper arguments.
46604
46605@item --once
46606By default, @command{gdbserver} keeps the listening TCP port open, so that
46607additional connections are possible. However, if you start @code{gdbserver}
46608with the @option{--once} option, it will stop listening for any further
46609connection attempts after connecting to the first @value{GDBN} session.
46610
46611@c --disable-packet is not documented for users.
46612
46613@c --disable-randomization and --no-disable-randomization are superseded by
46614@c QDisableRandomization.
46615
46616@end table
43662968
JK
46617@c man end
46618
46619@c man begin SEEALSO gdbserver
46620@ifset man
46621The full documentation for @value{GDBN} is maintained as a Texinfo manual.
46622If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
46623documentation are properly installed at your site, the command
46624
46625@smallexample
46626info gdb
46627@end smallexample
46628
46629should give you access to the complete manual.
46630
46631@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46632Richard M. Stallman and Roland H. Pesch, July 1991.
46633@end ifset
46634@c man end
46635
b292c783
JK
46636@node gcore man
46637@heading gcore
46638
46639@c man title gcore Generate a core file of a running program
46640
46641@format
46642@c man begin SYNOPSIS gcore
129eb0f1 46643gcore [-a] [-o @var{prefix}] @var{pid1} [@var{pid2}...@var{pidN}]
b292c783
JK
46644@c man end
46645@end format
46646
46647@c man begin DESCRIPTION gcore
129eb0f1
SDJ
46648Generate core dumps of one or more running programs with process IDs
46649@var{pid1}, @var{pid2}, etc. A core file produced by @command{gcore}
46650is equivalent to one produced by the kernel when the process crashes
46651(and when @kbd{ulimit -c} was used to set up an appropriate core dump
46652limit). However, unlike after a crash, after @command{gcore} finishes
46653its job the program remains running without any change.
b292c783
JK
46654@c man end
46655
46656@c man begin OPTIONS gcore
46657@table @env
c179febe
SL
46658@item -a
46659Dump all memory mappings. The actual effect of this option depends on
46660the Operating System. On @sc{gnu}/Linux, it will disable
46661@code{use-coredump-filter} (@pxref{set use-coredump-filter}) and
46662enable @code{dump-excluded-mappings} (@pxref{set
46663dump-excluded-mappings}).
46664
129eb0f1
SDJ
46665@item -o @var{prefix}
46666The optional argument @var{prefix} specifies the prefix to be used
46667when composing the file names of the core dumps. The file name is
46668composed as @file{@var{prefix}.@var{pid}}, where @var{pid} is the
46669process ID of the running program being analyzed by @command{gcore}.
46670If not specified, @var{prefix} defaults to @var{gcore}.
b292c783
JK
46671@end table
46672@c man end
46673
46674@c man begin SEEALSO gcore
46675@ifset man
46676The full documentation for @value{GDBN} is maintained as a Texinfo manual.
46677If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
46678documentation are properly installed at your site, the command
46679
46680@smallexample
46681info gdb
46682@end smallexample
46683
46684@noindent
46685should give you access to the complete manual.
46686
46687@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46688Richard M. Stallman and Roland H. Pesch, July 1991.
46689@end ifset
46690@c man end
46691
43662968
JK
46692@node gdbinit man
46693@heading gdbinit
46694
46695@c man title gdbinit GDB initialization scripts
46696
46697@format
46698@c man begin SYNOPSIS gdbinit
46699@ifset SYSTEM_GDBINIT
46700@value{SYSTEM_GDBINIT}
46701@end ifset
46702
ed2a2229
CB
46703@ifset SYSTEM_GDBINIT_DIR
46704@value{SYSTEM_GDBINIT_DIR}/*
46705@end ifset
46706
43662968
JK
46707~/.gdbinit
46708
46709./.gdbinit
46710@c man end
46711@end format
46712
46713@c man begin DESCRIPTION gdbinit
46714These files contain @value{GDBN} commands to automatically execute during
46715@value{GDBN} startup. The lines of contents are canned sequences of commands,
46716described in
46717@ifset man
46718the @value{GDBN} manual in node @code{Sequences}
46719-- shell command @code{info -f gdb -n Sequences}.
46720@end ifset
46721@ifclear man
46722@ref{Sequences}.
46723@end ifclear
46724
46725Please read more in
46726@ifset man
46727the @value{GDBN} manual in node @code{Startup}
46728-- shell command @code{info -f gdb -n Startup}.
46729@end ifset
46730@ifclear man
46731@ref{Startup}.
46732@end ifclear
46733
46734@table @env
46735@ifset SYSTEM_GDBINIT
46736@item @value{SYSTEM_GDBINIT}
46737@end ifset
46738@ifclear SYSTEM_GDBINIT
46739@item (not enabled with @code{--with-system-gdbinit} during compilation)
46740@end ifclear
46741System-wide initialization file. It is executed unless user specified
46742@value{GDBN} option @code{-nx} or @code{-n}.
46743See more in
46744@ifset man
46745the @value{GDBN} manual in node @code{System-wide configuration}
46746-- shell command @code{info -f gdb -n 'System-wide configuration'}.
46747@end ifset
ed2a2229
CB
46748@ifset SYSTEM_GDBINIT_DIR
46749@item @value{SYSTEM_GDBINIT_DIR}
46750@end ifset
46751@ifclear SYSTEM_GDBINIT_DIR
46752@item (not enabled with @code{--with-system-gdbinit-dir} during compilation)
46753@end ifclear
46754System-wide initialization directory. All files in this directory are
46755executed on startup unless user specified @value{GDBN} option @code{-nx} or
46756@code{-n}, as long as they have a recognized file extension.
46757See more in
46758@ifset man
46759the @value{GDBN} manual in node @code{System-wide configuration}
46760-- shell command @code{info -f gdb -n 'System-wide configuration'}.
46761@end ifset
43662968
JK
46762@ifclear man
46763@ref{System-wide configuration}.
46764@end ifclear
46765
46766@item ~/.gdbinit
46767User initialization file. It is executed unless user specified
46768@value{GDBN} options @code{-nx}, @code{-n} or @code{-nh}.
46769
46770@item ./.gdbinit
46771Initialization file for current directory. It may need to be enabled with
46772@value{GDBN} security command @code{set auto-load local-gdbinit}.
46773See more in
46774@ifset man
46775the @value{GDBN} manual in node @code{Init File in the Current Directory}
46776-- shell command @code{info -f gdb -n 'Init File in the Current Directory'}.
46777@end ifset
46778@ifclear man
46779@ref{Init File in the Current Directory}.
46780@end ifclear
46781@end table
46782@c man end
46783
46784@c man begin SEEALSO gdbinit
46785@ifset man
46786gdb(1), @code{info -f gdb -n Startup}
46787
46788The full documentation for @value{GDBN} is maintained as a Texinfo manual.
46789If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
46790documentation are properly installed at your site, the command
ba643918
SDJ
46791
46792@smallexample
46793info gdb
46794@end smallexample
46795
46796should give you access to the complete manual.
46797
46798@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46799Richard M. Stallman and Roland H. Pesch, July 1991.
46800@end ifset
46801@c man end
46802
46803@node gdb-add-index man
ba643918 46804@heading gdb-add-index
d726cb5d 46805@pindex gdb-add-index
dbfa4523 46806@anchor{gdb-add-index}
ba643918
SDJ
46807
46808@c man title gdb-add-index Add index files to speed up GDB
46809
46810@c man begin SYNOPSIS gdb-add-index
46811gdb-add-index @var{filename}
46812@c man end
46813
46814@c man begin DESCRIPTION gdb-add-index
46815When @value{GDBN} finds a symbol file, it scans the symbols in the
46816file in order to construct an internal symbol table. This lets most
46817@value{GDBN} operations work quickly--at the cost of a delay early on.
46818For large programs, this delay can be quite lengthy, so @value{GDBN}
46819provides a way to build an index, which speeds up startup.
46820
46821To determine whether a file contains such an index, use the command
46822@kbd{readelf -S filename}: the index is stored in a section named
46823@code{.gdb_index}. The index file can only be produced on systems
46824which use ELF binaries and DWARF debug information (i.e., sections
46825named @code{.debug_*}).
46826
46827@command{gdb-add-index} uses @value{GDBN} and @command{objdump} found
46828in the @env{PATH} environment variable. If you want to use different
46829versions of these programs, you can specify them through the
46830@env{GDB} and @env{OBJDUMP} environment variables.
46831
46832See more in
46833@ifset man
46834the @value{GDBN} manual in node @code{Index Files}
46835-- shell command @kbd{info -f gdb -n "Index Files"}.
46836@end ifset
46837@ifclear man
46838@ref{Index Files}.
46839@end ifclear
46840@c man end
46841
46842@c man begin SEEALSO gdb-add-index
46843@ifset man
46844The full documentation for @value{GDBN} is maintained as a Texinfo manual.
46845If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
46846documentation are properly installed at your site, the command
43662968
JK
46847
46848@smallexample
46849info gdb
46850@end smallexample
46851
46852should give you access to the complete manual.
46853
46854@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46855Richard M. Stallman and Roland H. Pesch, July 1991.
46856@end ifset
46857@c man end
46858
aab4e0ec 46859@include gpl.texi
eb12ee30 46860
e4c0cfae
SS
46861@node GNU Free Documentation License
46862@appendix GNU Free Documentation License
6826cf00
EZ
46863@include fdl.texi
46864
00595b5e
EZ
46865@node Concept Index
46866@unnumbered Concept Index
c906108c
SS
46867
46868@printindex cp
46869
00595b5e
EZ
46870@node Command and Variable Index
46871@unnumbered Command, Variable, and Function Index
46872
46873@printindex fn
46874
c906108c 46875@tex
984359d2 46876% I think something like @@colophon should be in texinfo. In the
c906108c
SS
46877% meantime:
46878\long\def\colophon{\hbox to0pt{}\vfill
46879\centerline{The body of this manual is set in}
46880\centerline{\fontname\tenrm,}
46881\centerline{with headings in {\bf\fontname\tenbf}}
46882\centerline{and examples in {\tt\fontname\tentt}.}
46883\centerline{{\it\fontname\tenit\/},}
46884\centerline{{\bf\fontname\tenbf}, and}
46885\centerline{{\sl\fontname\tensl\/}}
46886\centerline{are used for emphasis.}\vfill}
46887\page\colophon
984359d2 46888% Blame: doc@@cygnus.com, 1991.
c906108c
SS
46889@end tex
46890
c906108c 46891@bye
This page took 8.357783 seconds and 4 git commands to generate.