New set/show testing framework (gdb.base/settings.exp)
[deliverable/binutils-gdb.git] / gdb / doc / gdb.texinfo
CommitLineData
c906108c 1\input texinfo @c -*-texinfo-*-
42a4f53d 2@c Copyright (C) 1988-2019 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
c97a7739 53Copyright @copyright{} 1988-2019 Free Software Foundation, Inc.
c906108c 54
e9c75b65 55Permission is granted to copy, distribute and/or modify this document
4f5d9f07 56under the terms of the GNU Free Documentation License, Version 1.3 or
e9c75b65 57any later version published by the Free Software Foundation; with the
959acfd1
EZ
58Invariant Sections being ``Free Software'' and ``Free Software Needs
59Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
60and with the Back-Cover Texts as in (a) below.
c906108c 61
b8533aec
DJ
62(a) The FSF's Back-Cover Text is: ``You are free to copy and modify
63this GNU Manual. Buying copies from GNU Press supports the FSF in
64developing GNU and promoting software freedom.''
43662968 65@c man end
a67ec3f4
JM
66@end copying
67
68@ifnottex
69This file documents the @sc{gnu} debugger @value{GDBN}.
70
71This is the @value{EDITION} Edition, of @cite{Debugging with
72@value{GDBN}: the @sc{gnu} Source-Level Debugger} for @value{GDBN}
73@ifset VERSION_PACKAGE
74@value{VERSION_PACKAGE}
75@end ifset
76Version @value{GDBVN}.
77
78@insertcopying
79@end ifnottex
c906108c
SS
80
81@titlepage
82@title Debugging with @value{GDBN}
83@subtitle The @sc{gnu} Source-Level Debugger
c906108c 84@sp 1
c906108c 85@subtitle @value{EDITION} Edition, for @value{GDBN} version @value{GDBVN}
c16158bc
JM
86@ifset VERSION_PACKAGE
87@sp 1
88@subtitle @value{VERSION_PACKAGE}
89@end ifset
9e9c5ae7 90@author Richard Stallman, Roland Pesch, Stan Shebs, et al.
c906108c 91@page
c906108c
SS
92@tex
93{\parskip=0pt
c16158bc 94\hfill (Send bugs and comments on @value{GDBN} to @value{BUGURL}.)\par
c906108c
SS
95\hfill {\it Debugging with @value{GDBN}}\par
96\hfill \TeX{}info \texinfoversion\par
97}
98@end tex
53a5351d 99
c906108c 100@vskip 0pt plus 1filll
c906108c 101Published by the Free Software Foundation @*
c02a867d
EZ
10251 Franklin Street, Fifth Floor,
103Boston, MA 02110-1301, USA@*
26829f2b 104ISBN 978-0-9831592-3-0 @*
e9c75b65 105
a67ec3f4 106@insertcopying
c906108c
SS
107@end titlepage
108@page
109
6c0e9fb3 110@ifnottex
6d2ebf8b
SS
111@node Top, Summary, (dir), (dir)
112
c906108c
SS
113@top Debugging with @value{GDBN}
114
115This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
116
c16158bc
JM
117This is the @value{EDITION} Edition, for @value{GDBN}
118@ifset VERSION_PACKAGE
119@value{VERSION_PACKAGE}
120@end ifset
121Version @value{GDBVN}.
c906108c 122
c97a7739 123Copyright (C) 1988-2019 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
SS
876
877You can, instead, specify a process ID as a second argument, if you want
878to debug a running process:
879
474c8240 880@smallexample
c906108c 881@value{GDBP} @var{program} 1234
474c8240 882@end smallexample
c906108c
SS
883
884@noindent
885would attach @value{GDBN} to process @code{1234} (unless you also have a file
886named @file{1234}; @value{GDBN} does check for a core file first).
887
c906108c 888Taking advantage of the second command-line argument requires a fairly
2df3850c
JM
889complete operating system; when you use @value{GDBN} as a remote
890debugger attached to a bare board, there may not be any notion of
891``process'', and there is often no way to get a core dump. @value{GDBN}
892will warn you if it is unable to attach or to read core dumps.
c906108c 893
aa26fa3a
TT
894You can optionally have @code{@value{GDBP}} pass any arguments after the
895executable file to the inferior using @code{--args}. This option stops
896option processing.
474c8240 897@smallexample
3f94c067 898@value{GDBP} --args gcc -O2 -c foo.c
474c8240 899@end smallexample
aa26fa3a
TT
900This will cause @code{@value{GDBP}} to debug @code{gcc}, and to set
901@code{gcc}'s command-line arguments (@pxref{Arguments}) to @samp{-O2 -c foo.c}.
902
96a2c332 903You can run @code{@value{GDBP}} without printing the front material, which describes
adcc0a31 904@value{GDBN}'s non-warranty, by specifying @code{--silent}
905(or @code{-q}/@code{--quiet}):
c906108c
SS
906
907@smallexample
adcc0a31 908@value{GDBP} --silent
c906108c
SS
909@end smallexample
910
911@noindent
912You can further control how @value{GDBN} starts up by using command-line
913options. @value{GDBN} itself can remind you of the options available.
914
915@noindent
916Type
917
474c8240 918@smallexample
c906108c 919@value{GDBP} -help
474c8240 920@end smallexample
c906108c
SS
921
922@noindent
923to display all available options and briefly describe their use
924(@samp{@value{GDBP} -h} is a shorter equivalent).
925
926All options and command line arguments you give are processed
927in sequential order. The order makes a difference when the
928@samp{-x} option is used.
929
930
931@menu
c906108c
SS
932* File Options:: Choosing files
933* Mode Options:: Choosing modes
6fc08d32 934* Startup:: What @value{GDBN} does during startup
c906108c
SS
935@end menu
936
6d2ebf8b 937@node File Options
79a6e687 938@subsection Choosing Files
c906108c 939
2df3850c 940When @value{GDBN} starts, it reads any arguments other than options as
c906108c
SS
941specifying an executable file and core file (or process ID). This is
942the same as if the arguments were specified by the @samp{-se} and
d52fb0e9 943@samp{-c} (or @samp{-p}) options respectively. (@value{GDBN} reads the
19837790
MS
944first argument that does not have an associated option flag as
945equivalent to the @samp{-se} option followed by that argument; and the
946second argument that does not have an associated option flag, if any, as
947equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
948If the second argument begins with a decimal digit, @value{GDBN} will
949first attempt to attach to it as a process, and if that fails, attempt
950to open it as a corefile. If you have a corefile whose name begins with
b383017d 951a digit, you can prevent @value{GDBN} from treating it as a pid by
c1468174 952prefixing it with @file{./}, e.g.@: @file{./12345}.
7a292a7a
SS
953
954If @value{GDBN} has not been configured to included core file support,
955such as for most embedded targets, then it will complain about a second
956argument and ignore it.
c906108c
SS
957
958Many options have both long and short forms; both are shown in the
959following list. @value{GDBN} also recognizes the long forms if you truncate
960them, so long as enough of the option is present to be unambiguous.
961(If you prefer, you can flag option arguments with @samp{--} rather
962than @samp{-}, though we illustrate the more usual convention.)
963
d700128c
EZ
964@c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
965@c way, both those who look for -foo and --foo in the index, will find
966@c it.
967
c906108c
SS
968@table @code
969@item -symbols @var{file}
970@itemx -s @var{file}
d700128c
EZ
971@cindex @code{--symbols}
972@cindex @code{-s}
c906108c
SS
973Read symbol table from file @var{file}.
974
975@item -exec @var{file}
976@itemx -e @var{file}
d700128c
EZ
977@cindex @code{--exec}
978@cindex @code{-e}
7a292a7a
SS
979Use file @var{file} as the executable file to execute when appropriate,
980and for examining pure data in conjunction with a core dump.
c906108c
SS
981
982@item -se @var{file}
d700128c 983@cindex @code{--se}
c906108c
SS
984Read symbol table from file @var{file} and use it as the executable
985file.
986
c906108c
SS
987@item -core @var{file}
988@itemx -c @var{file}
d700128c
EZ
989@cindex @code{--core}
990@cindex @code{-c}
b383017d 991Use file @var{file} as a core dump to examine.
c906108c 992
19837790
MS
993@item -pid @var{number}
994@itemx -p @var{number}
995@cindex @code{--pid}
996@cindex @code{-p}
997Connect to process ID @var{number}, as with the @code{attach} command.
c906108c
SS
998
999@item -command @var{file}
1000@itemx -x @var{file}
d700128c
EZ
1001@cindex @code{--command}
1002@cindex @code{-x}
95433b34
JB
1003Execute commands from file @var{file}. The contents of this file is
1004evaluated exactly as the @code{source} command would.
8150ff9c 1005@xref{Command Files,, Command files}.
c906108c 1006
8a5a3c82
AS
1007@item -eval-command @var{command}
1008@itemx -ex @var{command}
1009@cindex @code{--eval-command}
1010@cindex @code{-ex}
1011Execute a single @value{GDBN} command.
1012
1013This option may be used multiple times to call multiple commands. It may
1014also be interleaved with @samp{-command} as required.
1015
1016@smallexample
1017@value{GDBP} -ex 'target sim' -ex 'load' \
1018 -x setbreakpoints -ex 'run' a.out
1019@end smallexample
1020
8320cc4f
JK
1021@item -init-command @var{file}
1022@itemx -ix @var{file}
1023@cindex @code{--init-command}
1024@cindex @code{-ix}
2d7b58e8
JK
1025Execute commands from file @var{file} before loading the inferior (but
1026after loading gdbinit files).
8320cc4f
JK
1027@xref{Startup}.
1028
1029@item -init-eval-command @var{command}
1030@itemx -iex @var{command}
1031@cindex @code{--init-eval-command}
1032@cindex @code{-iex}
2d7b58e8
JK
1033Execute a single @value{GDBN} command before loading the inferior (but
1034after loading gdbinit files).
8320cc4f
JK
1035@xref{Startup}.
1036
c906108c
SS
1037@item -directory @var{directory}
1038@itemx -d @var{directory}
d700128c
EZ
1039@cindex @code{--directory}
1040@cindex @code{-d}
4b505b12 1041Add @var{directory} to the path to search for source and script files.
c906108c 1042
c906108c
SS
1043@item -r
1044@itemx -readnow
d700128c
EZ
1045@cindex @code{--readnow}
1046@cindex @code{-r}
c906108c
SS
1047Read each symbol file's entire symbol table immediately, rather than
1048the default, which is to read it incrementally as it is needed.
1049This makes startup slower, but makes future operations faster.
53a5351d 1050
97cbe998
SDJ
1051@item --readnever
1052@anchor{--readnever}
1053@cindex @code{--readnever}, command-line option
1054Do not read each symbol file's symbolic debug information. This makes
1055startup faster but at the expense of not being able to perform
1056symbolic debugging. DWARF unwind information is also not read,
1057meaning backtraces may become incomplete or inaccurate. One use of
1058this is when a user simply wants to do the following sequence: attach,
1059dump core, detach. Loading the debugging information in this case is
1060an unnecessary cause of delay.
c906108c
SS
1061@end table
1062
6d2ebf8b 1063@node Mode Options
79a6e687 1064@subsection Choosing Modes
c906108c
SS
1065
1066You can run @value{GDBN} in various alternative modes---for example, in
1067batch mode or quiet mode.
1068
1069@table @code
bf88dd68 1070@anchor{-nx}
c906108c
SS
1071@item -nx
1072@itemx -n
d700128c
EZ
1073@cindex @code{--nx}
1074@cindex @code{-n}
07540c15
DE
1075Do not execute commands found in any initialization file.
1076There are three init files, loaded in the following order:
1077
1078@table @code
1079@item @file{system.gdbinit}
1080This is the system-wide init file.
1081Its location is specified with the @code{--with-system-gdbinit}
1082configure option (@pxref{System-wide configuration}).
1083It is loaded first when @value{GDBN} starts, before command line options
1084have been processed.
1085@item @file{~/.gdbinit}
1086This is the init file in your home directory.
1087It is loaded next, after @file{system.gdbinit}, and before
1088command options have been processed.
1089@item @file{./.gdbinit}
1090This is the init file in the current directory.
1091It is loaded last, after command line options other than @code{-x} and
1092@code{-ex} have been processed. Command line options @code{-x} and
1093@code{-ex} are processed last, after @file{./.gdbinit} has been loaded.
1094@end table
1095
1096For further documentation on startup processing, @xref{Startup}.
1097For documentation on how to write command files,
1098@xref{Command Files,,Command Files}.
1099
1100@anchor{-nh}
1101@item -nh
1102@cindex @code{--nh}
1103Do not execute commands found in @file{~/.gdbinit}, the init file
1104in your home directory.
1105@xref{Startup}.
c906108c
SS
1106
1107@item -quiet
d700128c 1108@itemx -silent
c906108c 1109@itemx -q
d700128c
EZ
1110@cindex @code{--quiet}
1111@cindex @code{--silent}
1112@cindex @code{-q}
c906108c
SS
1113``Quiet''. Do not print the introductory and copyright messages. These
1114messages are also suppressed in batch mode.
1115
1116@item -batch
d700128c 1117@cindex @code{--batch}
c906108c
SS
1118Run in batch mode. Exit with status @code{0} after processing all the
1119command files specified with @samp{-x} (and all commands from
1120initialization files, if not inhibited with @samp{-n}). Exit with
1121nonzero status if an error occurs in executing the @value{GDBN} commands
5da1313b
JK
1122in the command files. Batch mode also disables pagination, sets unlimited
1123terminal width and height @pxref{Screen Size}, and acts as if @kbd{set confirm
1124off} were in effect (@pxref{Messages/Warnings}).
c906108c 1125
2df3850c
JM
1126Batch mode may be useful for running @value{GDBN} as a filter, for
1127example to download and run a program on another computer; in order to
1128make this more useful, the message
c906108c 1129
474c8240 1130@smallexample
c906108c 1131Program exited normally.
474c8240 1132@end smallexample
c906108c
SS
1133
1134@noindent
2df3850c
JM
1135(which is ordinarily issued whenever a program running under
1136@value{GDBN} control terminates) is not issued when running in batch
1137mode.
1138
1a088d06
AS
1139@item -batch-silent
1140@cindex @code{--batch-silent}
1141Run in batch mode exactly like @samp{-batch}, but totally silently. All
1142@value{GDBN} output to @code{stdout} is prevented (@code{stderr} is
1143unaffected). This is much quieter than @samp{-silent} and would be useless
1144for an interactive session.
1145
1146This is particularly useful when using targets that give @samp{Loading section}
1147messages, for example.
1148
1149Note that targets that give their output via @value{GDBN}, as opposed to
1150writing directly to @code{stdout}, will also be made silent.
1151
4b0ad762
AS
1152@item -return-child-result
1153@cindex @code{--return-child-result}
1154The return code from @value{GDBN} will be the return code from the child
1155process (the process being debugged), with the following exceptions:
1156
1157@itemize @bullet
1158@item
1159@value{GDBN} exits abnormally. E.g., due to an incorrect argument or an
1160internal error. In this case the exit code is the same as it would have been
1161without @samp{-return-child-result}.
1162@item
1163The user quits with an explicit value. E.g., @samp{quit 1}.
1164@item
1165The child process never runs, or is not allowed to terminate, in which case
1166the exit code will be -1.
1167@end itemize
1168
1169This option is useful in conjunction with @samp{-batch} or @samp{-batch-silent},
1170when @value{GDBN} is being used as a remote program loader or simulator
1171interface.
1172
2df3850c
JM
1173@item -nowindows
1174@itemx -nw
d700128c
EZ
1175@cindex @code{--nowindows}
1176@cindex @code{-nw}
2df3850c 1177``No windows''. If @value{GDBN} comes with a graphical user interface
96a2c332 1178(GUI) built in, then this option tells @value{GDBN} to only use the command-line
2df3850c
JM
1179interface. If no GUI is available, this option has no effect.
1180
1181@item -windows
1182@itemx -w
d700128c
EZ
1183@cindex @code{--windows}
1184@cindex @code{-w}
2df3850c
JM
1185If @value{GDBN} includes a GUI, then this option requires it to be
1186used if possible.
c906108c
SS
1187
1188@item -cd @var{directory}
d700128c 1189@cindex @code{--cd}
c906108c
SS
1190Run @value{GDBN} using @var{directory} as its working directory,
1191instead of the current directory.
1192
aae1c79a 1193@item -data-directory @var{directory}
8d551b02 1194@itemx -D @var{directory}
aae1c79a 1195@cindex @code{--data-directory}
8d551b02 1196@cindex @code{-D}
aae1c79a
DE
1197Run @value{GDBN} using @var{directory} as its data directory.
1198The data directory is where @value{GDBN} searches for its
1199auxiliary files. @xref{Data Files}.
1200
c906108c
SS
1201@item -fullname
1202@itemx -f
d700128c
EZ
1203@cindex @code{--fullname}
1204@cindex @code{-f}
7a292a7a
SS
1205@sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1206subprocess. It tells @value{GDBN} to output the full file name and line
1207number in a standard, recognizable fashion each time a stack frame is
1208displayed (which includes each time your program stops). This
1209recognizable format looks like two @samp{\032} characters, followed by
1210the file name, line number and character position separated by colons,
1211and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1212@samp{\032} characters as a signal to display the source code for the
1213frame.
c906108c 1214
d700128c
EZ
1215@item -annotate @var{level}
1216@cindex @code{--annotate}
1217This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1218effect is identical to using @samp{set annotate @var{level}}
086432e2
AC
1219(@pxref{Annotations}). The annotation @var{level} controls how much
1220information @value{GDBN} prints together with its prompt, values of
1221expressions, source lines, and other types of output. Level 0 is the
1222normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1223@sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1224that control @value{GDBN}, and level 2 has been deprecated.
1225
265eeb58 1226The annotation mechanism has largely been superseded by @sc{gdb/mi}
086432e2 1227(@pxref{GDB/MI}).
d700128c 1228
aa26fa3a
TT
1229@item --args
1230@cindex @code{--args}
1231Change interpretation of command line so that arguments following the
1232executable file are passed as command line arguments to the inferior.
1233This option stops option processing.
1234
2df3850c
JM
1235@item -baud @var{bps}
1236@itemx -b @var{bps}
d700128c
EZ
1237@cindex @code{--baud}
1238@cindex @code{-b}
c906108c
SS
1239Set the line speed (baud rate or bits per second) of any serial
1240interface used by @value{GDBN} for remote debugging.
c906108c 1241
f47b1503
AS
1242@item -l @var{timeout}
1243@cindex @code{-l}
1244Set the timeout (in seconds) of any communication used by @value{GDBN}
1245for remote debugging.
1246
c906108c 1247@item -tty @var{device}
d700128c
EZ
1248@itemx -t @var{device}
1249@cindex @code{--tty}
1250@cindex @code{-t}
c906108c
SS
1251Run using @var{device} for your program's standard input and output.
1252@c FIXME: kingdon thinks there is more to -tty. Investigate.
c906108c 1253
53a5351d 1254@c resolve the situation of these eventually
c4555f82
SC
1255@item -tui
1256@cindex @code{--tui}
d0d5df6f
AC
1257Activate the @dfn{Text User Interface} when starting. The Text User
1258Interface manages several text windows on the terminal, showing
1259source, assembly, registers and @value{GDBN} command outputs
217bff3e
JK
1260(@pxref{TUI, ,@value{GDBN} Text User Interface}). Do not use this
1261option if you run @value{GDBN} from Emacs (@pxref{Emacs, ,
1262Using @value{GDBN} under @sc{gnu} Emacs}).
53a5351d 1263
d700128c
EZ
1264@item -interpreter @var{interp}
1265@cindex @code{--interpreter}
1266Use the interpreter @var{interp} for interface with the controlling
1267program or device. This option is meant to be set by programs which
94bbb2c0 1268communicate with @value{GDBN} using it as a back end.
21c294e6 1269@xref{Interpreters, , Command Interpreters}.
94bbb2c0 1270
b4be1b06
SM
1271@samp{--interpreter=mi} (or @samp{--interpreter=mi3}) causes
1272@value{GDBN} to use the @dfn{@sc{gdb/mi} interface} version 3 (@pxref{GDB/MI, ,
1273The @sc{gdb/mi} Interface}) included since @value{GDBN} version 9.1. @sc{gdb/mi}
1274version 2 (@code{mi2}), included in @value{GDBN} 6.0 and version 1 (@code{mi1}),
1275included in @value{GDBN} 5.3, are also available. Earlier @sc{gdb/mi}
1276interfaces are no longer supported.
d700128c
EZ
1277
1278@item -write
1279@cindex @code{--write}
1280Open the executable and core files for both reading and writing. This
1281is equivalent to the @samp{set write on} command inside @value{GDBN}
1282(@pxref{Patching}).
1283
1284@item -statistics
1285@cindex @code{--statistics}
1286This option causes @value{GDBN} to print statistics about time and
1287memory usage after it completes each command and returns to the prompt.
1288
1289@item -version
1290@cindex @code{--version}
1291This option causes @value{GDBN} to print its version number and
1292no-warranty blurb, and exit.
1293
6eaaf48b
EZ
1294@item -configuration
1295@cindex @code{--configuration}
1296This option causes @value{GDBN} to print details about its build-time
1297configuration parameters, and then exit. These details can be
1298important when reporting @value{GDBN} bugs (@pxref{GDB Bugs}).
1299
c906108c
SS
1300@end table
1301
6fc08d32 1302@node Startup
79a6e687 1303@subsection What @value{GDBN} Does During Startup
6fc08d32
EZ
1304@cindex @value{GDBN} startup
1305
1306Here's the description of what @value{GDBN} does during session startup:
1307
1308@enumerate
1309@item
1310Sets up the command interpreter as specified by the command line
1311(@pxref{Mode Options, interpreter}).
1312
1313@item
1314@cindex init file
098b41a6
JG
1315Reads the system-wide @dfn{init file} (if @option{--with-system-gdbinit} was
1316used when building @value{GDBN}; @pxref{System-wide configuration,
1317 ,System-wide configuration and settings}) and executes all the commands in
1318that file.
1319
bf88dd68 1320@anchor{Home Directory Init File}
098b41a6
JG
1321@item
1322Reads the init file (if any) in your home directory@footnote{On
6fc08d32
EZ
1323DOS/Windows systems, the home directory is the one pointed to by the
1324@code{HOME} environment variable.} and executes all the commands in
1325that file.
1326
2d7b58e8
JK
1327@anchor{Option -init-eval-command}
1328@item
1329Executes commands and command files specified by the @samp{-iex} and
1330@samp{-ix} options in their specified order. Usually you should use the
1331@samp{-ex} and @samp{-x} options instead, but this way you can apply
1332settings before @value{GDBN} init files get executed and before inferior
1333gets loaded.
1334
6fc08d32
EZ
1335@item
1336Processes command line options and operands.
1337
bf88dd68 1338@anchor{Init File in the Current Directory during Startup}
6fc08d32
EZ
1339@item
1340Reads and executes the commands from init file (if any) in the current
bf88dd68
JK
1341working directory as long as @samp{set auto-load local-gdbinit} is set to
1342@samp{on} (@pxref{Init File in the Current Directory}).
1343This is only done if the current directory is
119b882a
EZ
1344different from your home directory. Thus, you can have more than one
1345init file, one generic in your home directory, and another, specific
1346to the program you are debugging, in the directory where you invoke
6fc08d32
EZ
1347@value{GDBN}.
1348
a86caf66
DE
1349@item
1350If the command line specified a program to debug, or a process to
1351attach to, or a core file, @value{GDBN} loads any auto-loaded
1352scripts provided for the program or for its loaded shared libraries.
1353@xref{Auto-loading}.
1354
1355If you wish to disable the auto-loading during startup,
1356you must do something like the following:
1357
1358@smallexample
bf88dd68 1359$ gdb -iex "set auto-load python-scripts off" myprogram
a86caf66
DE
1360@end smallexample
1361
8320cc4f
JK
1362Option @samp{-ex} does not work because the auto-loading is then turned
1363off too late.
a86caf66 1364
6fc08d32 1365@item
6fe37d23
JK
1366Executes commands and command files specified by the @samp{-ex} and
1367@samp{-x} options in their specified order. @xref{Command Files}, for
1368more details about @value{GDBN} command files.
6fc08d32
EZ
1369
1370@item
1371Reads the command history recorded in the @dfn{history file}.
d620b259 1372@xref{Command History}, for more details about the command history and the
6fc08d32
EZ
1373files where @value{GDBN} records it.
1374@end enumerate
1375
1376Init files use the same syntax as @dfn{command files} (@pxref{Command
1377Files}) and are processed by @value{GDBN} in the same way. The init
1378file in your home directory can set options (such as @samp{set
1379complaints}) that affect subsequent processing of command line options
1380and operands. Init files are not executed if you use the @samp{-nx}
79a6e687 1381option (@pxref{Mode Options, ,Choosing Modes}).
6fc08d32 1382
098b41a6
JG
1383To display the list of init files loaded by gdb at startup, you
1384can use @kbd{gdb --help}.
1385
6fc08d32
EZ
1386@cindex init file name
1387@cindex @file{.gdbinit}
119b882a 1388@cindex @file{gdb.ini}
8807d78b 1389The @value{GDBN} init files are normally called @file{.gdbinit}.
119b882a
EZ
1390The DJGPP port of @value{GDBN} uses the name @file{gdb.ini}, due to
1391the limitations of file names imposed by DOS filesystems. The Windows
4d3f93a2
JB
1392port of @value{GDBN} uses the standard name, but if it finds a
1393@file{gdb.ini} file in your home directory, it warns you about that
1394and suggests to rename the file to the standard name.
119b882a 1395
6fc08d32 1396
6d2ebf8b 1397@node Quitting GDB
c906108c
SS
1398@section Quitting @value{GDBN}
1399@cindex exiting @value{GDBN}
1400@cindex leaving @value{GDBN}
1401
1402@table @code
1403@kindex quit @r{[}@var{expression}@r{]}
41afff9a 1404@kindex q @r{(@code{quit})}
96a2c332
SS
1405@item quit @r{[}@var{expression}@r{]}
1406@itemx q
1407To exit @value{GDBN}, use the @code{quit} command (abbreviated
c8aa23ab 1408@code{q}), or type an end-of-file character (usually @kbd{Ctrl-d}). If you
96a2c332
SS
1409do not supply @var{expression}, @value{GDBN} will terminate normally;
1410otherwise it will terminate using the result of @var{expression} as the
1411error code.
c906108c
SS
1412@end table
1413
1414@cindex interrupt
c8aa23ab 1415An interrupt (often @kbd{Ctrl-c}) does not exit from @value{GDBN}, but rather
c906108c
SS
1416terminates the action of any @value{GDBN} command that is in progress and
1417returns to @value{GDBN} command level. It is safe to type the interrupt
1418character at any time because @value{GDBN} does not allow it to take effect
1419until a time when it is safe.
1420
c906108c
SS
1421If you have been using @value{GDBN} to control an attached process or
1422device, you can release it with the @code{detach} command
79a6e687 1423(@pxref{Attach, ,Debugging an Already-running Process}).
c906108c 1424
6d2ebf8b 1425@node Shell Commands
79a6e687 1426@section Shell Commands
c906108c
SS
1427
1428If you need to execute occasional shell commands during your
1429debugging session, there is no need to leave or suspend @value{GDBN}; you can
1430just use the @code{shell} command.
1431
1432@table @code
1433@kindex shell
ed59ded5 1434@kindex !
c906108c 1435@cindex shell escape
ed59ded5
DE
1436@item shell @var{command-string}
1437@itemx !@var{command-string}
1438Invoke a standard shell to execute @var{command-string}.
1439Note that no space is needed between @code{!} and @var{command-string}.
c906108c 1440If it exists, the environment variable @code{SHELL} determines which
d4f3574e
SS
1441shell to run. Otherwise @value{GDBN} uses the default shell
1442(@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
c906108c
SS
1443@end table
1444
1445The utility @code{make} is often needed in development environments.
1446You do not have to use the @code{shell} command for this purpose in
1447@value{GDBN}:
1448
1449@table @code
1450@kindex make
1451@cindex calling make
1452@item make @var{make-args}
1453Execute the @code{make} program with the specified
1454arguments. This is equivalent to @samp{shell make @var{make-args}}.
1455@end table
1456
e2c52041
PW
1457@table @code
1458@kindex pipe
1459@kindex |
1460@cindex send the output of a gdb command to a shell command
1461@anchor{pipe}
1462@item pipe [@var{command}] | @var{shell_command}
1463@itemx | [@var{command}] | @var{shell_command}
1464@itemx pipe -d @var{delim} @var{command} @var{delim} @var{shell_command}
1465@itemx | -d @var{delim} @var{command} @var{delim} @var{shell_command}
1466Executes @var{command} and sends its output to @var{shell_command}.
1467Note that no space is needed around @code{|}.
1468If no @var{command} is provided, the last command executed is repeated.
1469
1470In case the @var{command} contains a @code{|}, the option @code{-d @var{delim}}
1471can be used to specify an alternate delimiter string @var{delim} that separates
1472the @var{command} from the @var{shell_command}.
1473
1474Example:
1475@smallexample
1476@group
1477(gdb) p var
1478$1 = @{
1479 black = 144,
1480 red = 233,
1481 green = 377,
1482 blue = 610,
1483 white = 987
1484@}
1485@end group
1486@group
1487(gdb) pipe p var|wc
1488 7 19 80
1489(gdb) |p var|wc -l
14907
1491@end group
1492@group
1493(gdb) p /x var
1494$4 = @{
1495 black = 0x90,
1496 red = 0xe9,
1497 green = 0x179,
1498 blue = 0x262,
1499 white = 0x3db
1500@}
1501(gdb) ||grep red
1502 red => 0xe9,
1503@end group
1504@group
1505(gdb) | -d ! echo this contains a | char\n ! sed -e 's/|/PIPE/'
1506this contains a PIPE char
1507(gdb) | -d xxx echo this contains a | char!\n xxx sed -e 's/|/PIPE/'
1508this contains a PIPE char!
1509(gdb)
1510@end group
1511@end smallexample
1512@end table
1513
1514The convenience variables @code{$_shell_exitcode} and @code{$_shell_exitsignal}
1515can be used to examine the exit status of the last shell command launched
1516by @code{shell}, @code{make}, @code{pipe} and @code{|}.
1517@xref{Convenience Vars,, Convenience Variables}.
1518
79a6e687
BW
1519@node Logging Output
1520@section Logging Output
0fac0b41 1521@cindex logging @value{GDBN} output
9c16f35a 1522@cindex save @value{GDBN} output to a file
0fac0b41
DJ
1523
1524You may want to save the output of @value{GDBN} commands to a file.
1525There are several commands to control @value{GDBN}'s logging.
1526
1527@table @code
1528@kindex set logging
1529@item set logging on
1530Enable logging.
1531@item set logging off
1532Disable logging.
9c16f35a 1533@cindex logging file name
0fac0b41
DJ
1534@item set logging file @var{file}
1535Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1536@item set logging overwrite [on|off]
1537By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1538you want @code{set logging on} to overwrite the logfile instead.
1539@item set logging redirect [on|off]
1540By default, @value{GDBN} output will go to both the terminal and the logfile.
1541Set @code{redirect} if you want output to go only to the log file.
b7060614
AH
1542@item set logging debugredirect [on|off]
1543By default, @value{GDBN} debug output will go to both the terminal and the logfile.
1544Set @code{debugredirect} if you want debug output to go only to the log file.
0fac0b41
DJ
1545@kindex show logging
1546@item show logging
1547Show the current values of the logging settings.
1548@end table
1549
e2c52041
PW
1550You can also redirect the output of a @value{GDBN} command to a
1551shell command. @xref{pipe}.
6d2ebf8b 1552@node Commands
c906108c
SS
1553@chapter @value{GDBN} Commands
1554
1555You can abbreviate a @value{GDBN} command to the first few letters of the command
1556name, if that abbreviation is unambiguous; and you can repeat certain
1557@value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1558key to get @value{GDBN} to fill out the rest of a word in a command (or to
1559show you the alternatives available, if there is more than one possibility).
1560
1561@menu
1562* Command Syntax:: How to give commands to @value{GDBN}
1563* Completion:: Command completion
1564* Help:: How to ask @value{GDBN} for help
1565@end menu
1566
6d2ebf8b 1567@node Command Syntax
79a6e687 1568@section Command Syntax
c906108c
SS
1569
1570A @value{GDBN} command is a single line of input. There is no limit on
1571how long it can be. It starts with a command name, which is followed by
1572arguments whose meaning depends on the command name. For example, the
1573command @code{step} accepts an argument which is the number of times to
1574step, as in @samp{step 5}. You can also use the @code{step} command
96a2c332 1575with no arguments. Some commands do not allow any arguments.
c906108c
SS
1576
1577@cindex abbreviation
1578@value{GDBN} command names may always be truncated if that abbreviation is
1579unambiguous. Other possible command abbreviations are listed in the
1580documentation for individual commands. In some cases, even ambiguous
1581abbreviations are allowed; for example, @code{s} is specially defined as
1582equivalent to @code{step} even though there are other commands whose
1583names start with @code{s}. You can test abbreviations by using them as
1584arguments to the @code{help} command.
1585
1586@cindex repeating commands
41afff9a 1587@kindex RET @r{(repeat last command)}
c906108c 1588A blank line as input to @value{GDBN} (typing just @key{RET}) means to
96a2c332 1589repeat the previous command. Certain commands (for example, @code{run})
c906108c
SS
1590will not repeat this way; these are commands whose unintentional
1591repetition might cause trouble and which you are unlikely to want to
c45da7e6
EZ
1592repeat. User-defined commands can disable this feature; see
1593@ref{Define, dont-repeat}.
c906108c
SS
1594
1595The @code{list} and @code{x} commands, when you repeat them with
1596@key{RET}, construct new arguments rather than repeating
1597exactly as typed. This permits easy scanning of source or memory.
1598
1599@value{GDBN} can also use @key{RET} in another way: to partition lengthy
1600output, in a way similar to the common utility @code{more}
79a6e687 1601(@pxref{Screen Size,,Screen Size}). Since it is easy to press one
c906108c
SS
1602@key{RET} too many in this situation, @value{GDBN} disables command
1603repetition after any command that generates this sort of display.
1604
41afff9a 1605@kindex # @r{(a comment)}
c906108c
SS
1606@cindex comment
1607Any text from a @kbd{#} to the end of the line is a comment; it does
1608nothing. This is useful mainly in command files (@pxref{Command
79a6e687 1609Files,,Command Files}).
c906108c 1610
88118b3a 1611@cindex repeating command sequences
c8aa23ab
EZ
1612@kindex Ctrl-o @r{(operate-and-get-next)}
1613The @kbd{Ctrl-o} binding is useful for repeating a complex sequence of
7f9087cb 1614commands. This command accepts the current line, like @key{RET}, and
88118b3a
TT
1615then fetches the next line relative to the current line from the history
1616for editing.
1617
6d2ebf8b 1618@node Completion
79a6e687 1619@section Command Completion
c906108c
SS
1620
1621@cindex completion
1622@cindex word completion
1623@value{GDBN} can fill in the rest of a word in a command for you, if there is
1624only one possibility; it can also show you what the valid possibilities
1625are for the next word in a command, at any time. This works for @value{GDBN}
1626commands, @value{GDBN} subcommands, and the names of symbols in your program.
1627
1628Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1629of a word. If there is only one possibility, @value{GDBN} fills in the
1630word, and waits for you to finish the command (or press @key{RET} to
1631enter it). For example, if you type
1632
1633@c FIXME "@key" does not distinguish its argument sufficiently to permit
1634@c complete accuracy in these examples; space introduced for clarity.
1635@c If texinfo enhancements make it unnecessary, it would be nice to
1636@c replace " @key" by "@key" in the following...
474c8240 1637@smallexample
c906108c 1638(@value{GDBP}) info bre @key{TAB}
474c8240 1639@end smallexample
c906108c
SS
1640
1641@noindent
1642@value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1643the only @code{info} subcommand beginning with @samp{bre}:
1644
474c8240 1645@smallexample
c906108c 1646(@value{GDBP}) info breakpoints
474c8240 1647@end smallexample
c906108c
SS
1648
1649@noindent
1650You can either press @key{RET} at this point, to run the @code{info
1651breakpoints} command, or backspace and enter something else, if
1652@samp{breakpoints} does not look like the command you expected. (If you
1653were sure you wanted @code{info breakpoints} in the first place, you
1654might as well just type @key{RET} immediately after @samp{info bre},
1655to exploit command abbreviations rather than command completion).
1656
1657If there is more than one possibility for the next word when you press
1658@key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1659characters and try again, or just press @key{TAB} a second time;
1660@value{GDBN} displays all the possible completions for that word. For
1661example, you might want to set a breakpoint on a subroutine whose name
1662begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1663just sounds the bell. Typing @key{TAB} again displays all the
1664function names in your program that begin with those characters, for
1665example:
1666
474c8240 1667@smallexample
c906108c
SS
1668(@value{GDBP}) b make_ @key{TAB}
1669@exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
5d161b24
DB
1670make_a_section_from_file make_environ
1671make_abs_section make_function_type
1672make_blockvector make_pointer_type
1673make_cleanup make_reference_type
c906108c
SS
1674make_command make_symbol_completion_list
1675(@value{GDBP}) b make_
474c8240 1676@end smallexample
c906108c
SS
1677
1678@noindent
1679After displaying the available possibilities, @value{GDBN} copies your
1680partial input (@samp{b make_} in the example) so you can finish the
1681command.
1682
1683If you just want to see the list of alternatives in the first place, you
b37052ae 1684can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
7a292a7a 1685means @kbd{@key{META} ?}. You can type this either by holding down a
c906108c 1686key designated as the @key{META} shift on your keyboard (if there is
7a292a7a 1687one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
c906108c 1688
ef0b411a
GB
1689If the number of possible completions is large, @value{GDBN} will
1690print as much of the list as it has collected, as well as a message
1691indicating that the list may be truncated.
1692
1693@smallexample
1694(@value{GDBP}) b m@key{TAB}@key{TAB}
1695main
1696<... the rest of the possible completions ...>
1697*** List may be truncated, max-completions reached. ***
1698(@value{GDBP}) b m
1699@end smallexample
1700
1701@noindent
1702This behavior can be controlled with the following commands:
1703
1704@table @code
1705@kindex set max-completions
1706@item set max-completions @var{limit}
1707@itemx set max-completions unlimited
1708Set the maximum number of completion candidates. @value{GDBN} will
1709stop looking for more completions once it collects this many candidates.
1710This is useful when completing on things like function names as collecting
1711all the possible candidates can be time consuming.
1712The default value is 200. A value of zero disables tab-completion.
1713Note that setting either no limit or a very large limit can make
1714completion slow.
1715@kindex show max-completions
1716@item show max-completions
1717Show the maximum number of candidates that @value{GDBN} will collect and show
1718during completion.
1719@end table
1720
c906108c
SS
1721@cindex quotes in commands
1722@cindex completion of quoted strings
1723Sometimes the string you need, while logically a ``word'', may contain
7a292a7a
SS
1724parentheses or other characters that @value{GDBN} normally excludes from
1725its notion of a word. To permit word completion to work in this
1726situation, you may enclose words in @code{'} (single quote marks) in
1727@value{GDBN} commands.
c906108c 1728
d044bac8
PA
1729A likely situation where you might need this is in typing an
1730expression that involves a C@t{++} symbol name with template
1731parameters. This is because when completing expressions, GDB treats
1732the @samp{<} character as word delimiter, assuming that it's the
1733less-than comparison operator (@pxref{C Operators, , C and C@t{++}
1734Operators}).
1735
1736For example, when you want to call a C@t{++} template function
1737interactively using the @code{print} or @code{call} commands, you may
1738need to distinguish whether you mean the version of @code{name} that
1739was specialized for @code{int}, @code{name<int>()}, or the version
1740that was specialized for @code{float}, @code{name<float>()}. To use
1741the word-completion facilities in this situation, type a single quote
b37052ae
EZ
1742@code{'} at the beginning of the function name. This alerts
1743@value{GDBN} that it may need to consider more information than usual
1744when you press @key{TAB} or @kbd{M-?} to request word completion:
c906108c 1745
474c8240 1746@smallexample
d044bac8
PA
1747(@value{GDBP}) p 'func< @kbd{M-?}
1748func<int>() func<float>()
1749(@value{GDBP}) p 'func<
474c8240 1750@end smallexample
c906108c 1751
d044bac8
PA
1752When setting breakpoints however (@pxref{Specify Location}), you don't
1753usually need to type a quote before the function name, because
1754@value{GDBN} understands that you want to set a breakpoint on a
1755function:
c906108c 1756
474c8240 1757@smallexample
d044bac8
PA
1758(@value{GDBP}) b func< @kbd{M-?}
1759func<int>() func<float>()
1760(@value{GDBP}) b func<
474c8240 1761@end smallexample
c906108c 1762
d044bac8
PA
1763This is true even in the case of typing the name of C@t{++} overloaded
1764functions (multiple definitions of the same function, distinguished by
1765argument type). For example, when you want to set a breakpoint you
1766don't need to distinguish whether you mean the version of @code{name}
1767that takes an @code{int} parameter, @code{name(int)}, or the version
1768that takes a @code{float} parameter, @code{name(float)}.
1769
1770@smallexample
1771(@value{GDBP}) b bubble( @kbd{M-?}
1772bubble(int) bubble(double)
1773(@value{GDBP}) b bubble(dou @kbd{M-?}
1774bubble(double)
1775@end smallexample
1776
1777See @ref{quoting names} for a description of other scenarios that
1778require quoting.
c906108c 1779
79a6e687
BW
1780For more information about overloaded functions, see @ref{C Plus Plus
1781Expressions, ,C@t{++} Expressions}. You can use the command @code{set
c906108c 1782overload-resolution off} to disable overload resolution;
79a6e687 1783see @ref{Debugging C Plus Plus, ,@value{GDBN} Features for C@t{++}}.
c906108c 1784
65d12d83
TT
1785@cindex completion of structure field names
1786@cindex structure field name completion
1787@cindex completion of union field names
1788@cindex union field name completion
1789When completing in an expression which looks up a field in a
1790structure, @value{GDBN} also tries@footnote{The completer can be
1791confused by certain kinds of invalid expressions. Also, it only
1792examines the static type of the expression, not the dynamic type.} to
1793limit completions to the field names available in the type of the
1794left-hand-side:
1795
1796@smallexample
1797(@value{GDBP}) p gdb_stdout.@kbd{M-?}
01124a23
DE
1798magic to_fputs to_rewind
1799to_data to_isatty to_write
1800to_delete to_put to_write_async_safe
1801to_flush to_read
65d12d83
TT
1802@end smallexample
1803
1804@noindent
1805This is because the @code{gdb_stdout} is a variable of the type
1806@code{struct ui_file} that is defined in @value{GDBN} sources as
1807follows:
1808
1809@smallexample
1810struct ui_file
1811@{
1812 int *magic;
1813 ui_file_flush_ftype *to_flush;
1814 ui_file_write_ftype *to_write;
01124a23 1815 ui_file_write_async_safe_ftype *to_write_async_safe;
65d12d83
TT
1816 ui_file_fputs_ftype *to_fputs;
1817 ui_file_read_ftype *to_read;
1818 ui_file_delete_ftype *to_delete;
1819 ui_file_isatty_ftype *to_isatty;
1820 ui_file_rewind_ftype *to_rewind;
1821 ui_file_put_ftype *to_put;
1822 void *to_data;
1823@}
1824@end smallexample
1825
c906108c 1826
6d2ebf8b 1827@node Help
79a6e687 1828@section Getting Help
c906108c
SS
1829@cindex online documentation
1830@kindex help
1831
5d161b24 1832You can always ask @value{GDBN} itself for information on its commands,
c906108c
SS
1833using the command @code{help}.
1834
1835@table @code
41afff9a 1836@kindex h @r{(@code{help})}
c906108c
SS
1837@item help
1838@itemx h
1839You can use @code{help} (abbreviated @code{h}) with no arguments to
1840display a short list of named classes of commands:
1841
1842@smallexample
1843(@value{GDBP}) help
1844List of classes of commands:
1845
2df3850c 1846aliases -- Aliases of other commands
c906108c 1847breakpoints -- Making program stop at certain points
2df3850c 1848data -- Examining data
c906108c 1849files -- Specifying and examining files
2df3850c
JM
1850internals -- Maintenance commands
1851obscure -- Obscure features
1852running -- Running the program
1853stack -- Examining the stack
c906108c
SS
1854status -- Status inquiries
1855support -- Support facilities
12c27660 1856tracepoints -- Tracing of program execution without
96a2c332 1857 stopping the program
c906108c 1858user-defined -- User-defined commands
c906108c 1859
5d161b24 1860Type "help" followed by a class name for a list of
c906108c 1861commands in that class.
5d161b24 1862Type "help" followed by command name for full
c906108c
SS
1863documentation.
1864Command name abbreviations are allowed if unambiguous.
1865(@value{GDBP})
1866@end smallexample
96a2c332 1867@c the above line break eliminates huge line overfull...
c906108c
SS
1868
1869@item help @var{class}
1870Using one of the general help classes as an argument, you can get a
1871list of the individual commands in that class. For example, here is the
1872help display for the class @code{status}:
1873
1874@smallexample
1875(@value{GDBP}) help status
1876Status inquiries.
1877
1878List of commands:
1879
1880@c Line break in "show" line falsifies real output, but needed
1881@c to fit in smallbook page size.
2df3850c 1882info -- Generic command for showing things
12c27660 1883 about the program being debugged
2df3850c 1884show -- Generic command for showing things
12c27660 1885 about the debugger
c906108c 1886
5d161b24 1887Type "help" followed by command name for full
c906108c
SS
1888documentation.
1889Command name abbreviations are allowed if unambiguous.
1890(@value{GDBP})
1891@end smallexample
1892
1893@item help @var{command}
1894With a command name as @code{help} argument, @value{GDBN} displays a
1895short paragraph on how to use that command.
1896
6837a0a2 1897@kindex apropos
e664d728 1898@item apropos [-v] @var{regexp}
09d4efe1 1899The @code{apropos} command searches through all of the @value{GDBN}
6837a0a2 1900commands, and their documentation, for the regular expression specified in
e664d728
PW
1901@var{args}. It prints out all matches found. The optional flag @samp{-v},
1902which stands for @samp{verbose}, indicates to output the full documentation
1903of the matching commands and highlight the parts of the documentation
1904matching @var{regexp}. For example:
6837a0a2
DB
1905
1906@smallexample
16899756 1907apropos alias
6837a0a2
DB
1908@end smallexample
1909
b37052ae
EZ
1910@noindent
1911results in:
6837a0a2
DB
1912
1913@smallexample
e664d728 1914@group
16899756
DE
1915alias -- Define a new command that is an alias of an existing command
1916aliases -- Aliases of other commands
1917d -- Delete some breakpoints or auto-display expressions
1918del -- Delete some breakpoints or auto-display expressions
1919delete -- Delete some breakpoints or auto-display expressions
e664d728
PW
1920@end group
1921@end smallexample
1922
1923@noindent
1924while
1925
1926@smallexample
1927apropos -v cut.*thread apply
1928@end smallexample
1929
1930@noindent
1931results in the below output, where @samp{cut for 'thread apply}
1932is highlighted if styling is enabled.
1933
1934@smallexample
1935@group
1936taas -- Apply a command to all threads (ignoring errors
1937and empty output).
1938Usage: taas COMMAND
1939shortcut for 'thread apply all -s COMMAND'
1940
1941tfaas -- Apply a command to all frames of all threads
1942(ignoring errors and empty output).
1943Usage: tfaas COMMAND
1944shortcut for 'thread apply all -s frame apply all -s COMMAND'
1945@end group
6837a0a2
DB
1946@end smallexample
1947
c906108c
SS
1948@kindex complete
1949@item complete @var{args}
1950The @code{complete @var{args}} command lists all the possible completions
1951for the beginning of a command. Use @var{args} to specify the beginning of the
1952command you want completed. For example:
1953
1954@smallexample
1955complete i
1956@end smallexample
1957
1958@noindent results in:
1959
1960@smallexample
1961@group
2df3850c
JM
1962if
1963ignore
c906108c
SS
1964info
1965inspect
c906108c
SS
1966@end group
1967@end smallexample
1968
1969@noindent This is intended for use by @sc{gnu} Emacs.
1970@end table
1971
1972In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
1973and @code{show} to inquire about the state of your program, or the state
1974of @value{GDBN} itself. Each command supports many topics of inquiry; this
1975manual introduces each of them in the appropriate context. The listings
00595b5e
EZ
1976under @code{info} and under @code{show} in the Command, Variable, and
1977Function Index point to all the sub-commands. @xref{Command and Variable
1978Index}.
c906108c
SS
1979
1980@c @group
1981@table @code
1982@kindex info
41afff9a 1983@kindex i @r{(@code{info})}
c906108c
SS
1984@item info
1985This command (abbreviated @code{i}) is for describing the state of your
cda4ce5a 1986program. For example, you can show the arguments passed to a function
c906108c
SS
1987with @code{info args}, list the registers currently in use with @code{info
1988registers}, or list the breakpoints you have set with @code{info breakpoints}.
1989You can get a complete list of the @code{info} sub-commands with
1990@w{@code{help info}}.
1991
1992@kindex set
1993@item set
5d161b24 1994You can assign the result of an expression to an environment variable with
c906108c
SS
1995@code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
1996@code{set prompt $}.
1997
1998@kindex show
1999@item show
5d161b24 2000In contrast to @code{info}, @code{show} is for describing the state of
c906108c
SS
2001@value{GDBN} itself.
2002You can change most of the things you can @code{show}, by using the
2003related command @code{set}; for example, you can control what number
2004system is used for displays with @code{set radix}, or simply inquire
2005which is currently in use with @code{show radix}.
2006
2007@kindex info set
2008To display all the settable parameters and their current
2009values, you can use @code{show} with no arguments; you may also use
2010@code{info set}. Both commands produce the same display.
2011@c FIXME: "info set" violates the rule that "info" is for state of
2012@c FIXME...program. Ck w/ GNU: "info set" to be called something else,
2013@c FIXME...or change desc of rule---eg "state of prog and debugging session"?
2014@end table
2015@c @end group
2016
6eaaf48b 2017Here are several miscellaneous @code{show} subcommands, all of which are
c906108c
SS
2018exceptional in lacking corresponding @code{set} commands:
2019
2020@table @code
2021@kindex show version
9c16f35a 2022@cindex @value{GDBN} version number
c906108c
SS
2023@item show version
2024Show what version of @value{GDBN} is running. You should include this
2df3850c
JM
2025information in @value{GDBN} bug-reports. If multiple versions of
2026@value{GDBN} are in use at your site, you may need to determine which
2027version of @value{GDBN} you are running; as @value{GDBN} evolves, new
2028commands are introduced, and old ones may wither away. Also, many
2029system vendors ship variant versions of @value{GDBN}, and there are
96a2c332 2030variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2df3850c
JM
2031The version number is the same as the one announced when you start
2032@value{GDBN}.
c906108c
SS
2033
2034@kindex show copying
09d4efe1 2035@kindex info copying
9c16f35a 2036@cindex display @value{GDBN} copyright
c906108c 2037@item show copying
09d4efe1 2038@itemx info copying
c906108c
SS
2039Display information about permission for copying @value{GDBN}.
2040
2041@kindex show warranty
09d4efe1 2042@kindex info warranty
c906108c 2043@item show warranty
09d4efe1 2044@itemx info warranty
2df3850c 2045Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
96a2c332 2046if your version of @value{GDBN} comes with one.
2df3850c 2047
6eaaf48b
EZ
2048@kindex show configuration
2049@item show configuration
2050Display detailed information about the way @value{GDBN} was configured
2051when it was built. This displays the optional arguments passed to the
2052@file{configure} script and also configuration parameters detected
2053automatically by @command{configure}. When reporting a @value{GDBN}
2054bug (@pxref{GDB Bugs}), it is important to include this information in
2055your report.
2056
c906108c
SS
2057@end table
2058
6d2ebf8b 2059@node Running
c906108c
SS
2060@chapter Running Programs Under @value{GDBN}
2061
2062When you run a program under @value{GDBN}, you must first generate
2063debugging information when you compile it.
7a292a7a
SS
2064
2065You may start @value{GDBN} with its arguments, if any, in an environment
2066of your choice. If you are doing native debugging, you may redirect
2067your program's input and output, debug an already running process, or
2068kill a child process.
c906108c
SS
2069
2070@menu
2071* Compilation:: Compiling for debugging
2072* Starting:: Starting your program
c906108c
SS
2073* Arguments:: Your program's arguments
2074* Environment:: Your program's environment
c906108c
SS
2075
2076* Working Directory:: Your program's working directory
2077* Input/Output:: Your program's input and output
2078* Attach:: Debugging an already-running process
2079* Kill Process:: Killing the child process
c906108c 2080
6c95b8df 2081* Inferiors and Programs:: Debugging multiple inferiors and programs
c906108c 2082* Threads:: Debugging programs with multiple threads
6c95b8df 2083* Forks:: Debugging forks
5c95884b 2084* Checkpoint/Restart:: Setting a @emph{bookmark} to return to later
c906108c
SS
2085@end menu
2086
6d2ebf8b 2087@node Compilation
79a6e687 2088@section Compiling for Debugging
c906108c
SS
2089
2090In order to debug a program effectively, you need to generate
2091debugging information when you compile it. This debugging information
2092is stored in the object file; it describes the data type of each
2093variable or function and the correspondence between source line numbers
2094and addresses in the executable code.
2095
2096To request debugging information, specify the @samp{-g} option when you run
2097the compiler.
2098
514c4d71 2099Programs that are to be shipped to your customers are compiled with
edb3359d 2100optimizations, using the @samp{-O} compiler option. However, some
514c4d71
EZ
2101compilers are unable to handle the @samp{-g} and @samp{-O} options
2102together. Using those compilers, you cannot generate optimized
c906108c
SS
2103executables containing debugging information.
2104
514c4d71 2105@value{NGCC}, the @sc{gnu} C/C@t{++} compiler, supports @samp{-g} with or
53a5351d
JM
2106without @samp{-O}, making it possible to debug optimized code. We
2107recommend that you @emph{always} use @samp{-g} whenever you compile a
2108program. You may think your program is correct, but there is no sense
edb3359d 2109in pushing your luck. For more information, see @ref{Optimized Code}.
c906108c
SS
2110
2111Older versions of the @sc{gnu} C compiler permitted a variant option
2112@w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
2113format; if your @sc{gnu} C compiler has this option, do not use it.
2114
514c4d71
EZ
2115@value{GDBN} knows about preprocessor macros and can show you their
2116expansion (@pxref{Macros}). Most compilers do not include information
2117about preprocessor macros in the debugging information if you specify
e0f8f636
TT
2118the @option{-g} flag alone. Version 3.1 and later of @value{NGCC},
2119the @sc{gnu} C compiler, provides macro information if you are using
2120the DWARF debugging format, and specify the option @option{-g3}.
2121
2122@xref{Debugging Options,,Options for Debugging Your Program or GCC,
f5a476a7 2123gcc, Using the @sc{gnu} Compiler Collection (GCC)}, for more
e0f8f636
TT
2124information on @value{NGCC} options affecting debug information.
2125
2126You will have the best debugging experience if you use the latest
2127version of the DWARF debugging format that your compiler supports.
2128DWARF is currently the most expressive and best supported debugging
2129format in @value{GDBN}.
514c4d71 2130
c906108c 2131@need 2000
6d2ebf8b 2132@node Starting
79a6e687 2133@section Starting your Program
c906108c
SS
2134@cindex starting
2135@cindex running
2136
2137@table @code
2138@kindex run
41afff9a 2139@kindex r @r{(@code{run})}
c906108c
SS
2140@item run
2141@itemx r
7a292a7a 2142Use the @code{run} command to start your program under @value{GDBN}.
deb8ff2b
PA
2143You must first specify the program name with an argument to
2144@value{GDBN} (@pxref{Invocation, ,Getting In and Out of
2145@value{GDBN}}), or by using the @code{file} or @code{exec-file}
2146command (@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
2147
2148@end table
2149
c906108c
SS
2150If you are running your program in an execution environment that
2151supports processes, @code{run} creates an inferior process and makes
8edfe269
DJ
2152that process run your program. In some environments without processes,
2153@code{run} jumps to the start of your program. Other targets,
2154like @samp{remote}, are always running. If you get an error
2155message like this one:
2156
2157@smallexample
2158The "remote" target does not support "run".
2159Try "help target" or "continue".
2160@end smallexample
2161
2162@noindent
2163then use @code{continue} to run your program. You may need @code{load}
2164first (@pxref{load}).
c906108c
SS
2165
2166The execution of a program is affected by certain information it
2167receives from its superior. @value{GDBN} provides ways to specify this
2168information, which you must do @emph{before} starting your program. (You
2169can change it after starting your program, but such changes only affect
2170your program the next time you start it.) This information may be
2171divided into four categories:
2172
2173@table @asis
2174@item The @emph{arguments.}
2175Specify the arguments to give your program as the arguments of the
2176@code{run} command. If a shell is available on your target, the shell
2177is used to pass the arguments, so that you may use normal conventions
2178(such as wildcard expansion or variable substitution) in describing
2179the arguments.
2180In Unix systems, you can control which shell is used with the
98882a26
PA
2181@code{SHELL} environment variable. If you do not define @code{SHELL},
2182@value{GDBN} uses the default shell (@file{/bin/sh}). You can disable
2183use of any shell with the @code{set startup-with-shell} command (see
2184below for details).
c906108c
SS
2185
2186@item The @emph{environment.}
2187Your program normally inherits its environment from @value{GDBN}, but you can
2188use the @value{GDBN} commands @code{set environment} and @code{unset
2189environment} to change parts of the environment that affect
79a6e687 2190your program. @xref{Environment, ,Your Program's Environment}.
c906108c
SS
2191
2192@item The @emph{working directory.}
d092c5a2
SDJ
2193You can set your program's working directory with the command
2194@kbd{set cwd}. If you do not set any working directory with this
bc3b087d
SDJ
2195command, your program will inherit @value{GDBN}'s working directory if
2196native debugging, or the remote server's working directory if remote
2197debugging. @xref{Working Directory, ,Your Program's Working
2198Directory}.
c906108c
SS
2199
2200@item The @emph{standard input and output.}
2201Your program normally uses the same device for standard input and
2202standard output as @value{GDBN} is using. You can redirect input and output
2203in the @code{run} command line, or you can use the @code{tty} command to
2204set a different device for your program.
79a6e687 2205@xref{Input/Output, ,Your Program's Input and Output}.
c906108c
SS
2206
2207@cindex pipes
2208@emph{Warning:} While input and output redirection work, you cannot use
2209pipes to pass the output of the program you are debugging to another
2210program; if you attempt this, @value{GDBN} is likely to wind up debugging the
2211wrong program.
2212@end table
c906108c
SS
2213
2214When you issue the @code{run} command, your program begins to execute
79a6e687 2215immediately. @xref{Stopping, ,Stopping and Continuing}, for discussion
c906108c
SS
2216of how to arrange for your program to stop. Once your program has
2217stopped, you may call functions in your program, using the @code{print}
2218or @code{call} commands. @xref{Data, ,Examining Data}.
2219
2220If the modification time of your symbol file has changed since the last
2221time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
2222table, and reads it again. When it does this, @value{GDBN} tries to retain
2223your current breakpoints.
2224
4e8b0763
JB
2225@table @code
2226@kindex start
2227@item start
2228@cindex run to main procedure
2229The name of the main procedure can vary from language to language.
2230With C or C@t{++}, the main procedure name is always @code{main}, but
2231other languages such as Ada do not require a specific name for their
2232main procedure. The debugger provides a convenient way to start the
2233execution of the program and to stop at the beginning of the main
2234procedure, depending on the language used.
2235
2236The @samp{start} command does the equivalent of setting a temporary
2237breakpoint at the beginning of the main procedure and then invoking
2238the @samp{run} command.
2239
f018e82f
EZ
2240@cindex elaboration phase
2241Some programs contain an @dfn{elaboration} phase where some startup code is
2242executed before the main procedure is called. This depends on the
2243languages used to write your program. In C@t{++}, for instance,
4e8b0763
JB
2244constructors for static and global objects are executed before
2245@code{main} is called. It is therefore possible that the debugger stops
2246before reaching the main procedure. However, the temporary breakpoint
2247will remain to halt execution.
2248
2249Specify the arguments to give to your program as arguments to the
2250@samp{start} command. These arguments will be given verbatim to the
2251underlying @samp{run} command. Note that the same arguments will be
2252reused if no argument is provided during subsequent calls to
2253@samp{start} or @samp{run}.
2254
2255It is sometimes necessary to debug the program during elaboration. In
4e5a4f58
JB
2256these cases, using the @code{start} command would stop the execution
2257of your program too late, as the program would have already completed
2258the elaboration phase. Under these circumstances, either insert
2259breakpoints in your elaboration code before running your program or
2260use the @code{starti} command.
2261
2262@kindex starti
2263@item starti
2264@cindex run to first instruction
2265The @samp{starti} command does the equivalent of setting a temporary
2266breakpoint at the first instruction of a program's execution and then
2267invoking the @samp{run} command. For programs containing an
2268elaboration phase, the @code{starti} command will stop execution at
2269the start of the elaboration phase.
ccd213ac 2270
41ef2965 2271@anchor{set exec-wrapper}
ccd213ac
DJ
2272@kindex set exec-wrapper
2273@item set exec-wrapper @var{wrapper}
2274@itemx show exec-wrapper
2275@itemx unset exec-wrapper
2276When @samp{exec-wrapper} is set, the specified wrapper is used to
2277launch programs for debugging. @value{GDBN} starts your program
2278with a shell command of the form @kbd{exec @var{wrapper}
2279@var{program}}. Quoting is added to @var{program} and its
2280arguments, but not to @var{wrapper}, so you should add quotes if
2281appropriate for your shell. The wrapper runs until it executes
2282your program, and then @value{GDBN} takes control.
2283
2284You can use any program that eventually calls @code{execve} with
2285its arguments as a wrapper. Several standard Unix utilities do
2286this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
2287with @code{exec "$@@"} will also work.
2288
2289For example, you can use @code{env} to pass an environment variable to
2290the debugged program, without setting the variable in your shell's
2291environment:
2292
2293@smallexample
2294(@value{GDBP}) set exec-wrapper env 'LD_PRELOAD=libtest.so'
2295(@value{GDBP}) run
2296@end smallexample
2297
2298This command is available when debugging locally on most targets, excluding
2299@sc{djgpp}, Cygwin, MS Windows, and QNX Neutrino.
2300
98882a26 2301@kindex set startup-with-shell
aefd8b33 2302@anchor{set startup-with-shell}
98882a26
PA
2303@item set startup-with-shell
2304@itemx set startup-with-shell on
2305@itemx set startup-with-shell off
ca145713 2306@itemx show startup-with-shell
98882a26
PA
2307On Unix systems, by default, if a shell is available on your target,
2308@value{GDBN}) uses it to start your program. Arguments of the
2309@code{run} command are passed to the shell, which does variable
2310substitution, expands wildcard characters and performs redirection of
2311I/O. In some circumstances, it may be useful to disable such use of a
2312shell, for example, when debugging the shell itself or diagnosing
2313startup failures such as:
2314
2315@smallexample
2316(@value{GDBP}) run
2317Starting program: ./a.out
2318During startup program terminated with signal SIGSEGV, Segmentation fault.
2319@end smallexample
2320
2321@noindent
2322which indicates the shell or the wrapper specified with
2323@samp{exec-wrapper} crashed, not your program. Most often, this is
afa332ce
PA
2324caused by something odd in your shell's non-interactive mode
2325initialization file---such as @file{.cshrc} for C-shell,
2326$@file{.zshenv} for the Z shell, or the file specified in the
2327@samp{BASH_ENV} environment variable for BASH.
98882a26 2328
6a3cb8e8
PA
2329@anchor{set auto-connect-native-target}
2330@kindex set auto-connect-native-target
2331@item set auto-connect-native-target
2332@itemx set auto-connect-native-target on
2333@itemx set auto-connect-native-target off
2334@itemx show auto-connect-native-target
2335
2336By default, if not connected to any target yet (e.g., with
2337@code{target remote}), the @code{run} command starts your program as a
2338native process under @value{GDBN}, on your local machine. If you're
2339sure you don't want to debug programs on your local machine, you can
2340tell @value{GDBN} to not connect to the native target automatically
2341with the @code{set auto-connect-native-target off} command.
2342
2343If @code{on}, which is the default, and if @value{GDBN} is not
2344connected to a target already, the @code{run} command automaticaly
2345connects to the native target, if one is available.
2346
2347If @code{off}, and if @value{GDBN} is not connected to a target
2348already, the @code{run} command fails with an error:
2349
2350@smallexample
2351(@value{GDBP}) run
2352Don't know how to run. Try "help target".
2353@end smallexample
2354
2355If @value{GDBN} is already connected to a target, @value{GDBN} always
2356uses it with the @code{run} command.
2357
2358In any case, you can explicitly connect to the native target with the
2359@code{target native} command. For example,
2360
2361@smallexample
2362(@value{GDBP}) set auto-connect-native-target off
2363(@value{GDBP}) run
2364Don't know how to run. Try "help target".
2365(@value{GDBP}) target native
2366(@value{GDBP}) run
2367Starting program: ./a.out
2368[Inferior 1 (process 10421) exited normally]
2369@end smallexample
2370
2371In case you connected explicitly to the @code{native} target,
2372@value{GDBN} remains connected even if all inferiors exit, ready for
2373the next @code{run} command. Use the @code{disconnect} command to
2374disconnect.
2375
2376Examples of other commands that likewise respect the
2377@code{auto-connect-native-target} setting: @code{attach}, @code{info
2378proc}, @code{info os}.
2379
10568435
JK
2380@kindex set disable-randomization
2381@item set disable-randomization
2382@itemx set disable-randomization on
2383This option (enabled by default in @value{GDBN}) will turn off the native
2384randomization of the virtual address space of the started program. This option
2385is useful for multiple debugging sessions to make the execution better
2386reproducible and memory addresses reusable across debugging sessions.
2387
03583c20
UW
2388This feature is implemented only on certain targets, including @sc{gnu}/Linux.
2389On @sc{gnu}/Linux you can get the same behavior using
10568435
JK
2390
2391@smallexample
2392(@value{GDBP}) set exec-wrapper setarch `uname -m` -R
2393@end smallexample
2394
2395@item set disable-randomization off
2396Leave the behavior of the started executable unchanged. Some bugs rear their
2397ugly heads only when the program is loaded at certain addresses. If your bug
2398disappears when you run the program under @value{GDBN}, that might be because
2399@value{GDBN} by default disables the address randomization on platforms, such
2400as @sc{gnu}/Linux, which do that for stand-alone programs. Use @kbd{set
2401disable-randomization off} to try to reproduce such elusive bugs.
2402
03583c20
UW
2403On targets where it is available, virtual address space randomization
2404protects the programs against certain kinds of security attacks. In these
10568435
JK
2405cases the attacker needs to know the exact location of a concrete executable
2406code. Randomizing its location makes it impossible to inject jumps misusing
2407a code at its expected addresses.
2408
2409Prelinking shared libraries provides a startup performance advantage but it
2410makes addresses in these libraries predictable for privileged processes by
2411having just unprivileged access at the target system. Reading the shared
2412library binary gives enough information for assembling the malicious code
2413misusing it. Still even a prelinked shared library can get loaded at a new
2414random address just requiring the regular relocation process during the
2415startup. Shared libraries not already prelinked are always loaded at
2416a randomly chosen address.
2417
2418Position independent executables (PIE) contain position independent code
2419similar to the shared libraries and therefore such executables get loaded at
2420a randomly chosen address upon startup. PIE executables always load even
2421already prelinked shared libraries at a random address. You can build such
2422executable using @command{gcc -fPIE -pie}.
2423
2424Heap (malloc storage), stack and custom mmap areas are always placed randomly
2425(as long as the randomization is enabled).
2426
2427@item show disable-randomization
2428Show the current setting of the explicit disable of the native randomization of
2429the virtual address space of the started program.
2430
4e8b0763
JB
2431@end table
2432
6d2ebf8b 2433@node Arguments
79a6e687 2434@section Your Program's Arguments
c906108c
SS
2435
2436@cindex arguments (to your program)
2437The arguments to your program can be specified by the arguments of the
5d161b24 2438@code{run} command.
c906108c
SS
2439They are passed to a shell, which expands wildcard characters and
2440performs redirection of I/O, and thence to your program. Your
2441@code{SHELL} environment variable (if it exists) specifies what shell
2442@value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
d4f3574e
SS
2443the default shell (@file{/bin/sh} on Unix).
2444
2445On non-Unix systems, the program is usually invoked directly by
2446@value{GDBN}, which emulates I/O redirection via the appropriate system
2447calls, and the wildcard characters are expanded by the startup code of
2448the program, not by the shell.
c906108c
SS
2449
2450@code{run} with no arguments uses the same arguments used by the previous
2451@code{run}, or those set by the @code{set args} command.
2452
c906108c 2453@table @code
41afff9a 2454@kindex set args
c906108c
SS
2455@item set args
2456Specify the arguments to be used the next time your program is run. If
2457@code{set args} has no arguments, @code{run} executes your program
2458with no arguments. Once you have run your program with arguments,
2459using @code{set args} before the next @code{run} is the only way to run
2460it again without arguments.
2461
2462@kindex show args
2463@item show args
2464Show the arguments to give your program when it is started.
2465@end table
2466
6d2ebf8b 2467@node Environment
79a6e687 2468@section Your Program's Environment
c906108c
SS
2469
2470@cindex environment (of your program)
2471The @dfn{environment} consists of a set of environment variables and
2472their values. Environment variables conventionally record such things as
2473your user name, your home directory, your terminal type, and your search
2474path for programs to run. Usually you set up environment variables with
2475the shell and they are inherited by all the other programs you run. When
2476debugging, it can be useful to try running your program with a modified
2477environment without having to start @value{GDBN} over again.
2478
2479@table @code
2480@kindex path
2481@item path @var{directory}
2482Add @var{directory} to the front of the @code{PATH} environment variable
17cc6a06
EZ
2483(the search path for executables) that will be passed to your program.
2484The value of @code{PATH} used by @value{GDBN} does not change.
d4f3574e
SS
2485You may specify several directory names, separated by whitespace or by a
2486system-dependent separator character (@samp{:} on Unix, @samp{;} on
2487MS-DOS and MS-Windows). If @var{directory} is already in the path, it
2488is moved to the front, so it is searched sooner.
c906108c
SS
2489
2490You can use the string @samp{$cwd} to refer to whatever is the current
2491working directory at the time @value{GDBN} searches the path. If you
2492use @samp{.} instead, it refers to the directory where you executed the
2493@code{path} command. @value{GDBN} replaces @samp{.} in the
2494@var{directory} argument (with the current path) before adding
2495@var{directory} to the search path.
2496@c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
2497@c document that, since repeating it would be a no-op.
2498
2499@kindex show paths
2500@item show paths
2501Display the list of search paths for executables (the @code{PATH}
2502environment variable).
2503
2504@kindex show environment
2505@item show environment @r{[}@var{varname}@r{]}
2506Print the value of environment variable @var{varname} to be given to
2507your program when it starts. If you do not supply @var{varname},
2508print the names and values of all environment variables to be given to
2509your program. You can abbreviate @code{environment} as @code{env}.
2510
2511@kindex set environment
0a2dde4a 2512@anchor{set environment}
53a5351d 2513@item set environment @var{varname} @r{[}=@var{value}@r{]}
c906108c 2514Set environment variable @var{varname} to @var{value}. The value
41ef2965 2515changes for your program (and the shell @value{GDBN} uses to launch
697aa1b7 2516it), not for @value{GDBN} itself. The @var{value} may be any string; the
41ef2965
PA
2517values of environment variables are just strings, and any
2518interpretation is supplied by your program itself. The @var{value}
c906108c
SS
2519parameter is optional; if it is eliminated, the variable is set to a
2520null value.
2521@c "any string" here does not include leading, trailing
2522@c blanks. Gnu asks: does anyone care?
2523
2524For example, this command:
2525
474c8240 2526@smallexample
c906108c 2527set env USER = foo
474c8240 2528@end smallexample
c906108c
SS
2529
2530@noindent
d4f3574e 2531tells the debugged program, when subsequently run, that its user is named
c906108c
SS
2532@samp{foo}. (The spaces around @samp{=} are used for clarity here; they
2533are not actually required.)
2534
41ef2965
PA
2535Note that on Unix systems, @value{GDBN} runs your program via a shell,
2536which also inherits the environment set with @code{set environment}.
2537If necessary, you can avoid that by using the @samp{env} program as a
2538wrapper instead of using @code{set environment}. @xref{set
2539exec-wrapper}, for an example doing just that.
2540
0a2dde4a
SDJ
2541Environment variables that are set by the user are also transmitted to
2542@command{gdbserver} to be used when starting the remote inferior.
2543@pxref{QEnvironmentHexEncoded}.
2544
c906108c 2545@kindex unset environment
0a2dde4a 2546@anchor{unset environment}
c906108c
SS
2547@item unset environment @var{varname}
2548Remove variable @var{varname} from the environment to be passed to your
2549program. This is different from @samp{set env @var{varname} =};
2550@code{unset environment} removes the variable from the environment,
2551rather than assigning it an empty value.
0a2dde4a
SDJ
2552
2553Environment variables that are unset by the user are also unset on
2554@command{gdbserver} when starting the remote inferior.
2555@pxref{QEnvironmentUnset}.
c906108c
SS
2556@end table
2557
d4f3574e 2558@emph{Warning:} On Unix systems, @value{GDBN} runs your program using
afa332ce
PA
2559the shell indicated by your @code{SHELL} environment variable if it
2560exists (or @code{/bin/sh} if not). If your @code{SHELL} variable
2561names a shell that runs an initialization file when started
2562non-interactively---such as @file{.cshrc} for C-shell, $@file{.zshenv}
2563for the Z shell, or the file specified in the @samp{BASH_ENV}
2564environment variable for BASH---any variables you set in that file
2565affect your program. You may wish to move setting of environment
2566variables to files that are only run when you sign on, such as
2567@file{.login} or @file{.profile}.
c906108c 2568
6d2ebf8b 2569@node Working Directory
79a6e687 2570@section Your Program's Working Directory
c906108c
SS
2571
2572@cindex working directory (of your program)
d092c5a2
SDJ
2573Each time you start your program with @code{run}, the inferior will be
2574initialized with the current working directory specified by the
2575@kbd{set cwd} command. If no directory has been specified by this
2576command, then the inferior will inherit @value{GDBN}'s current working
bc3b087d
SDJ
2577directory as its working directory if native debugging, or it will
2578inherit the remote server's current working directory if remote
2579debugging.
c906108c
SS
2580
2581@table @code
d092c5a2
SDJ
2582@kindex set cwd
2583@cindex change inferior's working directory
2584@anchor{set cwd command}
2585@item set cwd @r{[}@var{directory}@r{]}
2586Set the inferior's working directory to @var{directory}, which will be
2587@code{glob}-expanded in order to resolve tildes (@file{~}). If no
2588argument has been specified, the command clears the setting and resets
2589it to an empty state. This setting has no effect on @value{GDBN}'s
2590working directory, and it only takes effect the next time you start
2591the inferior. The @file{~} in @var{directory} is a short for the
2592@dfn{home directory}, usually pointed to by the @env{HOME} environment
2593variable. On MS-Windows, if @env{HOME} is not defined, @value{GDBN}
2594uses the concatenation of @env{HOMEDRIVE} and @env{HOMEPATH} as
2595fallback.
2596
2597You can also change @value{GDBN}'s current working directory by using
2598the @code{cd} command.
dbfa4523 2599@xref{cd command}.
d092c5a2
SDJ
2600
2601@kindex show cwd
2602@cindex show inferior's working directory
2603@item show cwd
2604Show the inferior's working directory. If no directory has been
2605specified by @kbd{set cwd}, then the default inferior's working
2606directory is the same as @value{GDBN}'s working directory.
2607
c906108c 2608@kindex cd
d092c5a2
SDJ
2609@cindex change @value{GDBN}'s working directory
2610@anchor{cd command}
f3c8a52a
JK
2611@item cd @r{[}@var{directory}@r{]}
2612Set the @value{GDBN} working directory to @var{directory}. If not
2613given, @var{directory} uses @file{'~'}.
c906108c 2614
d092c5a2
SDJ
2615The @value{GDBN} working directory serves as a default for the
2616commands that specify files for @value{GDBN} to operate on.
2617@xref{Files, ,Commands to Specify Files}.
dbfa4523 2618@xref{set cwd command}.
d092c5a2 2619
c906108c
SS
2620@kindex pwd
2621@item pwd
2622Print the @value{GDBN} working directory.
2623@end table
2624
60bf7e09
EZ
2625It is generally impossible to find the current working directory of
2626the process being debugged (since a program can change its directory
2d97a5d9 2627during its run). If you work on a system where @value{GDBN} supports
754452f0 2628the @code{info proc} command (@pxref{Process Information}), you can
2d97a5d9 2629use the @code{info proc} command to find out the
60bf7e09
EZ
2630current working directory of the debuggee.
2631
6d2ebf8b 2632@node Input/Output
79a6e687 2633@section Your Program's Input and Output
c906108c
SS
2634
2635@cindex redirection
2636@cindex i/o
2637@cindex terminal
2638By default, the program you run under @value{GDBN} does input and output to
5d161b24 2639the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
c906108c
SS
2640to its own terminal modes to interact with you, but it records the terminal
2641modes your program was using and switches back to them when you continue
2642running your program.
2643
2644@table @code
2645@kindex info terminal
2646@item info terminal
2647Displays information recorded by @value{GDBN} about the terminal modes your
2648program is using.
2649@end table
2650
2651You can redirect your program's input and/or output using shell
2652redirection with the @code{run} command. For example,
2653
474c8240 2654@smallexample
c906108c 2655run > outfile
474c8240 2656@end smallexample
c906108c
SS
2657
2658@noindent
2659starts your program, diverting its output to the file @file{outfile}.
2660
2661@kindex tty
2662@cindex controlling terminal
2663Another way to specify where your program should do input and output is
2664with the @code{tty} command. This command accepts a file name as
2665argument, and causes this file to be the default for future @code{run}
2666commands. It also resets the controlling terminal for the child
2667process, for future @code{run} commands. For example,
2668
474c8240 2669@smallexample
c906108c 2670tty /dev/ttyb
474c8240 2671@end smallexample
c906108c
SS
2672
2673@noindent
2674directs that processes started with subsequent @code{run} commands
2675default to do input and output on the terminal @file{/dev/ttyb} and have
2676that as their controlling terminal.
2677
2678An explicit redirection in @code{run} overrides the @code{tty} command's
2679effect on the input/output device, but not its effect on the controlling
2680terminal.
2681
2682When you use the @code{tty} command or redirect input in the @code{run}
2683command, only the input @emph{for your program} is affected. The input
3cb3b8df
BR
2684for @value{GDBN} still comes from your terminal. @code{tty} is an alias
2685for @code{set inferior-tty}.
2686
2687@cindex inferior tty
2688@cindex set inferior controlling terminal
2689You can use the @code{show inferior-tty} command to tell @value{GDBN} to
2690display the name of the terminal that will be used for future runs of your
2691program.
2692
2693@table @code
0a1ddfa6 2694@item set inferior-tty [ @var{tty} ]
3cb3b8df 2695@kindex set inferior-tty
0a1ddfa6
SM
2696Set the tty for the program being debugged to @var{tty}. Omitting @var{tty}
2697restores the default behavior, which is to use the same terminal as
2698@value{GDBN}.
3cb3b8df
BR
2699
2700@item show inferior-tty
2701@kindex show inferior-tty
2702Show the current tty for the program being debugged.
2703@end table
c906108c 2704
6d2ebf8b 2705@node Attach
79a6e687 2706@section Debugging an Already-running Process
c906108c
SS
2707@kindex attach
2708@cindex attach
2709
2710@table @code
2711@item attach @var{process-id}
2712This command attaches to a running process---one that was started
2713outside @value{GDBN}. (@code{info files} shows your active
2714targets.) The command takes as argument a process ID. The usual way to
09d4efe1 2715find out the @var{process-id} of a Unix process is with the @code{ps} utility,
c906108c
SS
2716or with the @samp{jobs -l} shell command.
2717
2718@code{attach} does not repeat if you press @key{RET} a second time after
2719executing the command.
2720@end table
2721
2722To use @code{attach}, your program must be running in an environment
2723which supports processes; for example, @code{attach} does not work for
2724programs on bare-board targets that lack an operating system. You must
2725also have permission to send the process a signal.
2726
2727When you use @code{attach}, the debugger finds the program running in
2728the process first by looking in the current working directory, then (if
2729the program is not found) by using the source file search path
79a6e687 2730(@pxref{Source Path, ,Specifying Source Directories}). You can also use
c906108c
SS
2731the @code{file} command to load the program. @xref{Files, ,Commands to
2732Specify Files}.
2733
2734The first thing @value{GDBN} does after arranging to debug the specified
2735process is to stop it. You can examine and modify an attached process
53a5351d
JM
2736with all the @value{GDBN} commands that are ordinarily available when
2737you start processes with @code{run}. You can insert breakpoints; you
2738can step and continue; you can modify storage. If you would rather the
2739process continue running, you may use the @code{continue} command after
c906108c
SS
2740attaching @value{GDBN} to the process.
2741
2742@table @code
2743@kindex detach
2744@item detach
2745When you have finished debugging the attached process, you can use the
2746@code{detach} command to release it from @value{GDBN} control. Detaching
2747the process continues its execution. After the @code{detach} command,
2748that process and @value{GDBN} become completely independent once more, and you
2749are ready to @code{attach} another process or start one with @code{run}.
2750@code{detach} does not repeat if you press @key{RET} again after
2751executing the command.
2752@end table
2753
159fcc13
JK
2754If you exit @value{GDBN} while you have an attached process, you detach
2755that process. If you use the @code{run} command, you kill that process.
2756By default, @value{GDBN} asks for confirmation if you try to do either of these
2757things; you can control whether or not you need to confirm by using the
2758@code{set confirm} command (@pxref{Messages/Warnings, ,Optional Warnings and
79a6e687 2759Messages}).
c906108c 2760
6d2ebf8b 2761@node Kill Process
79a6e687 2762@section Killing the Child Process
c906108c
SS
2763
2764@table @code
2765@kindex kill
2766@item kill
2767Kill the child process in which your program is running under @value{GDBN}.
2768@end table
2769
2770This command is useful if you wish to debug a core dump instead of a
2771running process. @value{GDBN} ignores any core dump file while your program
2772is running.
2773
2774On some operating systems, a program cannot be executed outside @value{GDBN}
2775while you have breakpoints set on it inside @value{GDBN}. You can use the
2776@code{kill} command in this situation to permit running your program
2777outside the debugger.
2778
2779The @code{kill} command is also useful if you wish to recompile and
2780relink your program, since on many systems it is impossible to modify an
2781executable file while it is running in a process. In this case, when you
2782next type @code{run}, @value{GDBN} notices that the file has changed, and
2783reads the symbol table again (while trying to preserve your current
2784breakpoint settings).
2785
6c95b8df
PA
2786@node Inferiors and Programs
2787@section Debugging Multiple Inferiors and Programs
b77209e0 2788
6c95b8df
PA
2789@value{GDBN} lets you run and debug multiple programs in a single
2790session. In addition, @value{GDBN} on some systems may let you run
2791several programs simultaneously (otherwise you have to exit from one
2792before starting another). In the most general case, you can have
2793multiple threads of execution in each of multiple processes, launched
2794from multiple executables.
b77209e0
PA
2795
2796@cindex inferior
2797@value{GDBN} represents the state of each program execution with an
2798object called an @dfn{inferior}. An inferior typically corresponds to
2799a process, but is more general and applies also to targets that do not
2800have processes. Inferiors may be created before a process runs, and
6c95b8df
PA
2801may be retained after a process exits. Inferiors have unique
2802identifiers that are different from process ids. Usually each
2803inferior will also have its own distinct address space, although some
2804embedded targets may have several inferiors running in different parts
2805of a single address space. Each inferior may in turn have multiple
2806threads running in it.
b77209e0 2807
6c95b8df
PA
2808To find out what inferiors exist at any moment, use @w{@code{info
2809inferiors}}:
b77209e0
PA
2810
2811@table @code
a3c25011 2812@kindex info inferiors [ @var{id}@dots{} ]
b77209e0
PA
2813@item info inferiors
2814Print a list of all inferiors currently being managed by @value{GDBN}.
a3c25011
TT
2815By default all inferiors are printed, but the argument @var{id}@dots{}
2816-- a space separated list of inferior numbers -- can be used to limit
2817the display to just the requested inferiors.
3a1ff0b6
PA
2818
2819@value{GDBN} displays for each inferior (in this order):
2820
2821@enumerate
2822@item
2823the inferior number assigned by @value{GDBN}
2824
2825@item
2826the target system's inferior identifier
6c95b8df
PA
2827
2828@item
2829the name of the executable the inferior is running.
2830
3a1ff0b6
PA
2831@end enumerate
2832
2833@noindent
2834An asterisk @samp{*} preceding the @value{GDBN} inferior number
2835indicates the current inferior.
2836
2837For example,
2277426b 2838@end table
3a1ff0b6
PA
2839@c end table here to get a little more width for example
2840
2841@smallexample
2842(@value{GDBP}) info inferiors
6c95b8df
PA
2843 Num Description Executable
2844 2 process 2307 hello
2845* 1 process 3401 goodbye
3a1ff0b6 2846@end smallexample
2277426b
PA
2847
2848To switch focus between inferiors, use the @code{inferior} command:
2849
2850@table @code
3a1ff0b6
PA
2851@kindex inferior @var{infno}
2852@item inferior @var{infno}
2853Make inferior number @var{infno} the current inferior. The argument
2854@var{infno} is the inferior number assigned by @value{GDBN}, as shown
2855in the first field of the @samp{info inferiors} display.
2277426b
PA
2856@end table
2857
e3940304
PA
2858@vindex $_inferior@r{, convenience variable}
2859The debugger convenience variable @samp{$_inferior} contains the
2860number of the current inferior. You may find this useful in writing
2861breakpoint conditional expressions, command scripts, and so forth.
2862@xref{Convenience Vars,, Convenience Variables}, for general
2863information on convenience variables.
6c95b8df
PA
2864
2865You can get multiple executables into a debugging session via the
2866@code{add-inferior} and @w{@code{clone-inferior}} commands. On some
2867systems @value{GDBN} can add inferiors to the debug session
2868automatically by following calls to @code{fork} and @code{exec}. To
2869remove inferiors from the debugging session use the
af624141 2870@w{@code{remove-inferiors}} command.
6c95b8df
PA
2871
2872@table @code
2873@kindex add-inferior
2874@item add-inferior [ -copies @var{n} ] [ -exec @var{executable} ]
2875Adds @var{n} inferiors to be run using @var{executable} as the
697aa1b7 2876executable; @var{n} defaults to 1. If no executable is specified,
6c95b8df
PA
2877the inferiors begins empty, with no program. You can still assign or
2878change the program assigned to the inferior at any time by using the
2879@code{file} command with the executable name as its argument.
2880
2881@kindex clone-inferior
2882@item clone-inferior [ -copies @var{n} ] [ @var{infno} ]
2883Adds @var{n} inferiors ready to execute the same program as inferior
697aa1b7 2884@var{infno}; @var{n} defaults to 1, and @var{infno} defaults to the
6c95b8df
PA
2885number of the current inferior. This is a convenient command when you
2886want to run another instance of the inferior you are debugging.
2887
2888@smallexample
2889(@value{GDBP}) info inferiors
2890 Num Description Executable
2891* 1 process 29964 helloworld
2892(@value{GDBP}) clone-inferior
2893Added inferior 2.
28941 inferiors added.
2895(@value{GDBP}) info inferiors
2896 Num Description Executable
2897 2 <null> helloworld
2898* 1 process 29964 helloworld
2899@end smallexample
2900
2901You can now simply switch focus to inferior 2 and run it.
2902
af624141
MS
2903@kindex remove-inferiors
2904@item remove-inferiors @var{infno}@dots{}
2905Removes the inferior or inferiors @var{infno}@dots{}. It is not
2906possible to remove an inferior that is running with this command. For
2907those, use the @code{kill} or @code{detach} command first.
6c95b8df
PA
2908
2909@end table
2910
2911To quit debugging one of the running inferiors that is not the current
2912inferior, you can either detach from it by using the @w{@code{detach
2913inferior}} command (allowing it to run independently), or kill it
af624141 2914using the @w{@code{kill inferiors}} command:
2277426b
PA
2915
2916@table @code
af624141
MS
2917@kindex detach inferiors @var{infno}@dots{}
2918@item detach inferior @var{infno}@dots{}
2919Detach from the inferior or inferiors identified by @value{GDBN}
5e30da2c 2920inferior number(s) @var{infno}@dots{}. Note that the inferior's entry
af624141
MS
2921still stays on the list of inferiors shown by @code{info inferiors},
2922but its Description will show @samp{<null>}.
2923
2924@kindex kill inferiors @var{infno}@dots{}
2925@item kill inferiors @var{infno}@dots{}
2926Kill the inferior or inferiors identified by @value{GDBN} inferior
2927number(s) @var{infno}@dots{}. Note that the inferior's entry still
2928stays on the list of inferiors shown by @code{info inferiors}, but its
2929Description will show @samp{<null>}.
2277426b
PA
2930@end table
2931
6c95b8df 2932After the successful completion of a command such as @code{detach},
af624141 2933@code{detach inferiors}, @code{kill} or @code{kill inferiors}, or after
6c95b8df
PA
2934a normal process exit, the inferior is still valid and listed with
2935@code{info inferiors}, ready to be restarted.
2936
2937
2277426b
PA
2938To be notified when inferiors are started or exit under @value{GDBN}'s
2939control use @w{@code{set print inferior-events}}:
b77209e0 2940
2277426b 2941@table @code
b77209e0
PA
2942@kindex set print inferior-events
2943@cindex print messages on inferior start and exit
2944@item set print inferior-events
2945@itemx set print inferior-events on
2946@itemx set print inferior-events off
2947The @code{set print inferior-events} command allows you to enable or
2948disable printing of messages when @value{GDBN} notices that new
2949inferiors have started or that inferiors have exited or have been
2950detached. By default, these messages will not be printed.
2951
2952@kindex show print inferior-events
2953@item show print inferior-events
2954Show whether messages will be printed when @value{GDBN} detects that
2955inferiors have started, exited or have been detached.
2956@end table
2957
6c95b8df
PA
2958Many commands will work the same with multiple programs as with a
2959single program: e.g., @code{print myglobal} will simply display the
2960value of @code{myglobal} in the current inferior.
2961
2962
2963Occasionaly, when debugging @value{GDBN} itself, it may be useful to
2964get more info about the relationship of inferiors, programs, address
2965spaces in a debug session. You can do that with the @w{@code{maint
2966info program-spaces}} command.
2967
2968@table @code
2969@kindex maint info program-spaces
2970@item maint info program-spaces
2971Print a list of all program spaces currently being managed by
2972@value{GDBN}.
2973
2974@value{GDBN} displays for each program space (in this order):
2975
2976@enumerate
2977@item
2978the program space number assigned by @value{GDBN}
2979
2980@item
2981the name of the executable loaded into the program space, with e.g.,
2982the @code{file} command.
2983
2984@end enumerate
2985
2986@noindent
2987An asterisk @samp{*} preceding the @value{GDBN} program space number
2988indicates the current program space.
2989
2990In addition, below each program space line, @value{GDBN} prints extra
2991information that isn't suitable to display in tabular form. For
2992example, the list of inferiors bound to the program space.
2993
2994@smallexample
2995(@value{GDBP}) maint info program-spaces
2996 Id Executable
b05b1202 2997* 1 hello
6c95b8df
PA
2998 2 goodbye
2999 Bound inferiors: ID 1 (process 21561)
6c95b8df
PA
3000@end smallexample
3001
3002Here we can see that no inferior is running the program @code{hello},
3003while @code{process 21561} is running the program @code{goodbye}. On
3004some targets, it is possible that multiple inferiors are bound to the
3005same program space. The most common example is that of debugging both
3006the parent and child processes of a @code{vfork} call. For example,
3007
3008@smallexample
3009(@value{GDBP}) maint info program-spaces
3010 Id Executable
3011* 1 vfork-test
3012 Bound inferiors: ID 2 (process 18050), ID 1 (process 18045)
3013@end smallexample
3014
3015Here, both inferior 2 and inferior 1 are running in the same program
3016space as a result of inferior 1 having executed a @code{vfork} call.
3017@end table
3018
6d2ebf8b 3019@node Threads
79a6e687 3020@section Debugging Programs with Multiple Threads
c906108c
SS
3021
3022@cindex threads of execution
3023@cindex multiple threads
3024@cindex switching threads
b1236ac3 3025In some operating systems, such as GNU/Linux and Solaris, a single program
c906108c
SS
3026may have more than one @dfn{thread} of execution. The precise semantics
3027of threads differ from one operating system to another, but in general
3028the threads of a single program are akin to multiple processes---except
3029that they share one address space (that is, they can all examine and
3030modify the same variables). On the other hand, each thread has its own
3031registers and execution stack, and perhaps private memory.
3032
3033@value{GDBN} provides these facilities for debugging multi-thread
3034programs:
3035
3036@itemize @bullet
3037@item automatic notification of new threads
5d5658a1 3038@item @samp{thread @var{thread-id}}, a command to switch among threads
c906108c 3039@item @samp{info threads}, a command to inquire about existing threads
0a232300 3040@item @samp{thread apply [@var{thread-id-list} | all] @var{args}},
c906108c
SS
3041a command to apply a command to a list of threads
3042@item thread-specific breakpoints
93815fbf
VP
3043@item @samp{set print thread-events}, which controls printing of
3044messages on thread start and exit.
17a37d48
PP
3045@item @samp{set libthread-db-search-path @var{path}}, which lets
3046the user specify which @code{libthread_db} to use if the default choice
3047isn't compatible with the program.
c906108c
SS
3048@end itemize
3049
c906108c
SS
3050@cindex focus of debugging
3051@cindex current thread
3052The @value{GDBN} thread debugging facility allows you to observe all
3053threads while your program runs---but whenever @value{GDBN} takes
3054control, one thread in particular is always the focus of debugging.
3055This thread is called the @dfn{current thread}. Debugging commands show
3056program information from the perspective of the current thread.
3057
41afff9a 3058@cindex @code{New} @var{systag} message
c906108c
SS
3059@cindex thread identifier (system)
3060@c FIXME-implementors!! It would be more helpful if the [New...] message
3061@c included GDB's numeric thread handle, so you could just go to that
3062@c thread without first checking `info threads'.
3063Whenever @value{GDBN} detects a new thread in your program, it displays
3064the target system's identification for the thread with a message in the
697aa1b7 3065form @samp{[New @var{systag}]}, where @var{systag} is a thread identifier
c906108c 3066whose form varies depending on the particular system. For example, on
8807d78b 3067@sc{gnu}/Linux, you might see
c906108c 3068
474c8240 3069@smallexample
08e796bc 3070[New Thread 0x41e02940 (LWP 25582)]
474c8240 3071@end smallexample
c906108c
SS
3072
3073@noindent
b1236ac3 3074when @value{GDBN} notices a new thread. In contrast, on other systems,
c906108c
SS
3075the @var{systag} is simply something like @samp{process 368}, with no
3076further qualifier.
3077
3078@c FIXME!! (1) Does the [New...] message appear even for the very first
3079@c thread of a program, or does it only appear for the
6ca652b0 3080@c second---i.e.@: when it becomes obvious we have a multithread
c906108c
SS
3081@c program?
3082@c (2) *Is* there necessarily a first thread always? Or do some
3083@c multithread systems permit starting a program with multiple
5d161b24 3084@c threads ab initio?
c906108c 3085
5d5658a1
PA
3086@anchor{thread numbers}
3087@cindex thread number, per inferior
c906108c 3088@cindex thread identifier (GDB)
5d5658a1
PA
3089For debugging purposes, @value{GDBN} associates its own thread number
3090---always a single integer---with each thread of an inferior. This
3091number is unique between all threads of an inferior, but not unique
3092between threads of different inferiors.
3093
3094@cindex qualified thread ID
3095You can refer to a given thread in an inferior using the qualified
3096@var{inferior-num}.@var{thread-num} syntax, also known as
3097@dfn{qualified thread ID}, with @var{inferior-num} being the inferior
3098number and @var{thread-num} being the thread number of the given
3099inferior. For example, thread @code{2.3} refers to thread number 3 of
3100inferior 2. If you omit @var{inferior-num} (e.g., @code{thread 3}),
3101then @value{GDBN} infers you're referring to a thread of the current
3102inferior.
3103
3104Until you create a second inferior, @value{GDBN} does not show the
3105@var{inferior-num} part of thread IDs, even though you can always use
3106the full @var{inferior-num}.@var{thread-num} form to refer to threads
3107of inferior 1, the initial inferior.
3108
3109@anchor{thread ID lists}
3110@cindex thread ID lists
3111Some commands accept a space-separated @dfn{thread ID list} as
71ef29a8
PA
3112argument. A list element can be:
3113
3114@enumerate
3115@item
3116A thread ID as shown in the first field of the @samp{info threads}
3117display, with or without an inferior qualifier. E.g., @samp{2.1} or
3118@samp{1}.
3119
3120@item
3121A range of thread numbers, again with or without an inferior
3122qualifier, as in @var{inf}.@var{thr1}-@var{thr2} or
3123@var{thr1}-@var{thr2}. E.g., @samp{1.2-4} or @samp{2-4}.
3124
3125@item
3126All threads of an inferior, specified with a star wildcard, with or
3127without an inferior qualifier, as in @var{inf}.@code{*} (e.g.,
3128@samp{1.*}) or @code{*}. The former refers to all threads of the
3129given inferior, and the latter form without an inferior qualifier
3130refers to all threads of the current inferior.
3131
3132@end enumerate
3133
3134For example, if the current inferior is 1, and inferior 7 has one
3135thread with ID 7.1, the thread list @samp{1 2-3 4.5 6.7-9 7.*}
3136includes threads 1 to 3 of inferior 1, thread 5 of inferior 4, threads
31377 to 9 of inferior 6 and all threads of inferior 7. That is, in
3138expanded qualified form, the same as @samp{1.1 1.2 1.3 4.5 6.7 6.8 6.9
31397.1}.
3140
5d5658a1
PA
3141
3142@anchor{global thread numbers}
3143@cindex global thread number
3144@cindex global thread identifier (GDB)
3145In addition to a @emph{per-inferior} number, each thread is also
3146assigned a unique @emph{global} number, also known as @dfn{global
3147thread ID}, a single integer. Unlike the thread number component of
3148the thread ID, no two threads have the same global ID, even when
3149you're debugging multiple inferiors.
c906108c 3150
f4f4330e
PA
3151From @value{GDBN}'s perspective, a process always has at least one
3152thread. In other words, @value{GDBN} assigns a thread number to the
3153program's ``main thread'' even if the program is not multi-threaded.
3154
5d5658a1 3155@vindex $_thread@r{, convenience variable}
663f6d42
PA
3156@vindex $_gthread@r{, convenience variable}
3157The debugger convenience variables @samp{$_thread} and
3158@samp{$_gthread} contain, respectively, the per-inferior thread number
3159and the global thread number of the current thread. You may find this
5d5658a1
PA
3160useful in writing breakpoint conditional expressions, command scripts,
3161and so forth. @xref{Convenience Vars,, Convenience Variables}, for
3162general information on convenience variables.
3163
f303dbd6
PA
3164If @value{GDBN} detects the program is multi-threaded, it augments the
3165usual message about stopping at a breakpoint with the ID and name of
3166the thread that hit the breakpoint.
3167
3168@smallexample
3169Thread 2 "client" hit Breakpoint 1, send_message () at client.c:68
3170@end smallexample
3171
3172Likewise when the program receives a signal:
3173
3174@smallexample
3175Thread 1 "main" received signal SIGINT, Interrupt.
3176@end smallexample
3177
c906108c
SS
3178@table @code
3179@kindex info threads
5d5658a1
PA
3180@item info threads @r{[}@var{thread-id-list}@r{]}
3181
3182Display information about one or more threads. With no arguments
3183displays information about all threads. You can specify the list of
3184threads that you want to display using the thread ID list syntax
3185(@pxref{thread ID lists}).
3186
60f98dde 3187@value{GDBN} displays for each thread (in this order):
c906108c
SS
3188
3189@enumerate
09d4efe1 3190@item
5d5658a1 3191the per-inferior thread number assigned by @value{GDBN}
c906108c 3192
c84f6bbf
PA
3193@item
3194the global thread number assigned by @value{GDBN}, if the @samp{-gid}
3195option was specified
3196
09d4efe1
EZ
3197@item
3198the target system's thread identifier (@var{systag})
c906108c 3199
4694da01
TT
3200@item
3201the thread's name, if one is known. A thread can either be named by
3202the user (see @code{thread name}, below), or, in some cases, by the
3203program itself.
3204
09d4efe1
EZ
3205@item
3206the current stack frame summary for that thread
c906108c
SS
3207@end enumerate
3208
3209@noindent
3210An asterisk @samp{*} to the left of the @value{GDBN} thread number
3211indicates the current thread.
3212
5d161b24 3213For example,
c906108c
SS
3214@end table
3215@c end table here to get a little more width for example
3216
3217@smallexample
3218(@value{GDBP}) info threads
13fd8b81 3219 Id Target Id Frame
c0ecb95f 3220* 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
b05b1202
PA
3221 2 process 35 thread 23 0x34e5 in sigpause ()
3222 3 process 35 thread 27 0x34e5 in sigpause ()
c906108c
SS
3223 at threadtest.c:68
3224@end smallexample
53a5351d 3225
5d5658a1
PA
3226If you're debugging multiple inferiors, @value{GDBN} displays thread
3227IDs using the qualified @var{inferior-num}.@var{thread-num} format.
c84f6bbf
PA
3228Otherwise, only @var{thread-num} is shown.
3229
3230If you specify the @samp{-gid} option, @value{GDBN} displays a column
3231indicating each thread's global thread ID:
5d5658a1
PA
3232
3233@smallexample
3234(@value{GDBP}) info threads
c84f6bbf
PA
3235 Id GId Target Id Frame
3236 1.1 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
3237 1.2 3 process 35 thread 23 0x34e5 in sigpause ()
3238 1.3 4 process 35 thread 27 0x34e5 in sigpause ()
3239* 2.1 2 process 65 thread 1 main (argc=1, argv=0x7ffffff8)
5d5658a1
PA
3240@end smallexample
3241
c45da7e6
EZ
3242On Solaris, you can display more information about user threads with a
3243Solaris-specific command:
3244
3245@table @code
3246@item maint info sol-threads
3247@kindex maint info sol-threads
3248@cindex thread info (Solaris)
3249Display info on Solaris user threads.
3250@end table
3251
c906108c 3252@table @code
5d5658a1
PA
3253@kindex thread @var{thread-id}
3254@item thread @var{thread-id}
3255Make thread ID @var{thread-id} the current thread. The command
3256argument @var{thread-id} is the @value{GDBN} thread ID, as shown in
3257the first field of the @samp{info threads} display, with or without an
3258inferior qualifier (e.g., @samp{2.1} or @samp{1}).
3259
3260@value{GDBN} responds by displaying the system identifier of the
3261thread you selected, and its current stack frame summary:
c906108c
SS
3262
3263@smallexample
c906108c 3264(@value{GDBP}) thread 2
13fd8b81
TT
3265[Switching to thread 2 (Thread 0xb7fdab70 (LWP 12747))]
3266#0 some_function (ignore=0x0) at example.c:8
32678 printf ("hello\n");
c906108c
SS
3268@end smallexample
3269
3270@noindent
3271As with the @samp{[New @dots{}]} message, the form of the text after
3272@samp{Switching to} depends on your system's conventions for identifying
5d161b24 3273threads.
c906108c 3274
9c16f35a 3275@kindex thread apply
638ac427 3276@cindex apply command to several threads
0a232300 3277@item thread apply [@var{thread-id-list} | all [-ascending]] [@var{flag}]@dots{} @var{command}
839c27b7 3278The @code{thread apply} command allows you to apply the named
5d5658a1
PA
3279@var{command} to one or more threads. Specify the threads that you
3280want affected using the thread ID list syntax (@pxref{thread ID
3281lists}), or specify @code{all} to apply to all threads. To apply a
3282command to all threads in descending order, type @kbd{thread apply all
253828f1
JK
3283@var{command}}. To apply a command to all threads in ascending order,
3284type @kbd{thread apply all -ascending @var{command}}.
3285
0a232300
PW
3286The @var{flag} arguments control what output to produce and how to handle
3287errors raised when applying @var{command} to a thread. @var{flag}
3288must start with a @code{-} directly followed by one letter in
3289@code{qcs}. If several flags are provided, they must be given
3290individually, such as @code{-c -q}.
3291
3292By default, @value{GDBN} displays some thread information before the
3293output produced by @var{command}, and an error raised during the
3294execution of a @var{command} will abort @code{thread apply}. The
3295following flags can be used to fine-tune this behavior:
3296
3297@table @code
3298@item -c
3299The flag @code{-c}, which stands for @samp{continue}, causes any
3300errors in @var{command} to be displayed, and the execution of
3301@code{thread apply} then continues.
3302@item -s
3303The flag @code{-s}, which stands for @samp{silent}, causes any errors
3304or empty output produced by a @var{command} to be silently ignored.
3305That is, the execution continues, but the thread information and errors
3306are not printed.
3307@item -q
3308The flag @code{-q} (@samp{quiet}) disables printing the thread
3309information.
3310@end table
3311
3312Flags @code{-c} and @code{-s} cannot be used together.
3313
3314@kindex taas
3315@cindex apply command to all threads (ignoring errors and empty output)
3316@item taas @var{command}
3317Shortcut for @code{thread apply all -s @var{command}}.
3318Applies @var{command} on all threads, ignoring errors and empty output.
3319
3320@kindex tfaas
3321@cindex apply a command to all frames of all threads (ignoring errors and empty output)
3322@item tfaas @var{command}
3323Shortcut for @code{thread apply all -s frame apply all -s @var{command}}.
3324Applies @var{command} on all frames of all threads, ignoring errors
3325and empty output. Note that the flag @code{-s} is specified twice:
3326The first @code{-s} ensures that @code{thread apply} only shows the thread
3327information of the threads for which @code{frame apply} produces
3328some output. The second @code{-s} is needed to ensure that @code{frame
3329apply} shows the frame information of a frame only if the
3330@var{command} successfully produced some output.
3331
3332It can for example be used to print a local variable or a function
3333argument without knowing the thread or frame where this variable or argument
3334is, using:
3335@smallexample
3336(@value{GDBP}) tfaas p some_local_var_i_do_not_remember_where_it_is
3337@end smallexample
3338
93815fbf 3339
4694da01
TT
3340@kindex thread name
3341@cindex name a thread
3342@item thread name [@var{name}]
3343This command assigns a name to the current thread. If no argument is
3344given, any existing user-specified name is removed. The thread name
3345appears in the @samp{info threads} display.
3346
3347On some systems, such as @sc{gnu}/Linux, @value{GDBN} is able to
3348determine the name of the thread as given by the OS. On these
3349systems, a name specified with @samp{thread name} will override the
3350system-give name, and removing the user-specified name will cause
3351@value{GDBN} to once again display the system-specified name.
3352
60f98dde
MS
3353@kindex thread find
3354@cindex search for a thread
3355@item thread find [@var{regexp}]
3356Search for and display thread ids whose name or @var{systag}
3357matches the supplied regular expression.
3358
3359As well as being the complement to the @samp{thread name} command,
3360this command also allows you to identify a thread by its target
3361@var{systag}. For instance, on @sc{gnu}/Linux, the target @var{systag}
3362is the LWP id.
3363
3364@smallexample
3365(@value{GDBN}) thread find 26688
3366Thread 4 has target id 'Thread 0x41e02940 (LWP 26688)'
3367(@value{GDBN}) info thread 4
3368 Id Target Id Frame
3369 4 Thread 0x41e02940 (LWP 26688) 0x00000031ca6cd372 in select ()
3370@end smallexample
3371
93815fbf
VP
3372@kindex set print thread-events
3373@cindex print messages on thread start and exit
3374@item set print thread-events
3375@itemx set print thread-events on
3376@itemx set print thread-events off
3377The @code{set print thread-events} command allows you to enable or
3378disable printing of messages when @value{GDBN} notices that new threads have
3379started or that threads have exited. By default, these messages will
3380be printed if detection of these events is supported by the target.
3381Note that these messages cannot be disabled on all targets.
3382
3383@kindex show print thread-events
3384@item show print thread-events
3385Show whether messages will be printed when @value{GDBN} detects that threads
3386have started and exited.
c906108c
SS
3387@end table
3388
79a6e687 3389@xref{Thread Stops,,Stopping and Starting Multi-thread Programs}, for
c906108c
SS
3390more information about how @value{GDBN} behaves when you stop and start
3391programs with multiple threads.
3392
79a6e687 3393@xref{Set Watchpoints,,Setting Watchpoints}, for information about
c906108c 3394watchpoints in programs with multiple threads.
c906108c 3395
bf88dd68 3396@anchor{set libthread-db-search-path}
17a37d48
PP
3397@table @code
3398@kindex set libthread-db-search-path
3399@cindex search path for @code{libthread_db}
3400@item set libthread-db-search-path @r{[}@var{path}@r{]}
3401If this variable is set, @var{path} is a colon-separated list of
3402directories @value{GDBN} will use to search for @code{libthread_db}.
3403If you omit @var{path}, @samp{libthread-db-search-path} will be reset to
98a5dd13 3404its default value (@code{$sdir:$pdir} on @sc{gnu}/Linux and Solaris systems).
7e0396aa
DE
3405Internally, the default value comes from the @code{LIBTHREAD_DB_SEARCH_PATH}
3406macro.
17a37d48
PP
3407
3408On @sc{gnu}/Linux and Solaris systems, @value{GDBN} uses a ``helper''
3409@code{libthread_db} library to obtain information about threads in the
3410inferior process. @value{GDBN} will use @samp{libthread-db-search-path}
bf88dd68
JK
3411to find @code{libthread_db}. @value{GDBN} also consults first if inferior
3412specific thread debugging library loading is enabled
3413by @samp{set auto-load libthread-db} (@pxref{libthread_db.so.1 file}).
98a5dd13
DE
3414
3415A special entry @samp{$sdir} for @samp{libthread-db-search-path}
3416refers to the default system directories that are
bf88dd68
JK
3417normally searched for loading shared libraries. The @samp{$sdir} entry
3418is the only kind not needing to be enabled by @samp{set auto-load libthread-db}
3419(@pxref{libthread_db.so.1 file}).
98a5dd13
DE
3420
3421A special entry @samp{$pdir} for @samp{libthread-db-search-path}
3422refers to the directory from which @code{libpthread}
3423was loaded in the inferior process.
17a37d48
PP
3424
3425For any @code{libthread_db} library @value{GDBN} finds in above directories,
3426@value{GDBN} attempts to initialize it with the current inferior process.
3427If this initialization fails (which could happen because of a version
3428mismatch between @code{libthread_db} and @code{libpthread}), @value{GDBN}
3429will unload @code{libthread_db}, and continue with the next directory.
3430If none of @code{libthread_db} libraries initialize successfully,
3431@value{GDBN} will issue a warning and thread debugging will be disabled.
3432
3433Setting @code{libthread-db-search-path} is currently implemented
3434only on some platforms.
3435
3436@kindex show libthread-db-search-path
3437@item show libthread-db-search-path
3438Display current libthread_db search path.
02d868e8
PP
3439
3440@kindex set debug libthread-db
3441@kindex show debug libthread-db
3442@cindex debugging @code{libthread_db}
3443@item set debug libthread-db
3444@itemx show debug libthread-db
3445Turns on or off display of @code{libthread_db}-related events.
3446Use @code{1} to enable, @code{0} to disable.
17a37d48
PP
3447@end table
3448
6c95b8df
PA
3449@node Forks
3450@section Debugging Forks
c906108c
SS
3451
3452@cindex fork, debugging programs which call
3453@cindex multiple processes
3454@cindex processes, multiple
53a5351d
JM
3455On most systems, @value{GDBN} has no special support for debugging
3456programs which create additional processes using the @code{fork}
3457function. When a program forks, @value{GDBN} will continue to debug the
3458parent process and the child process will run unimpeded. If you have
3459set a breakpoint in any code which the child then executes, the child
3460will get a @code{SIGTRAP} signal which (unless it catches the signal)
3461will cause it to terminate.
c906108c
SS
3462
3463However, if you want to debug the child process there is a workaround
3464which isn't too painful. Put a call to @code{sleep} in the code which
3465the child process executes after the fork. It may be useful to sleep
3466only if a certain environment variable is set, or a certain file exists,
3467so that the delay need not occur when you don't want to run @value{GDBN}
3468on the child. While the child is sleeping, use the @code{ps} program to
3469get its process ID. Then tell @value{GDBN} (a new invocation of
3470@value{GDBN} if you are also debugging the parent process) to attach to
d4f3574e 3471the child process (@pxref{Attach}). From that point on you can debug
c906108c 3472the child process just like any other process which you attached to.
c906108c 3473
b1236ac3
PA
3474On some systems, @value{GDBN} provides support for debugging programs
3475that create additional processes using the @code{fork} or @code{vfork}
3476functions. On @sc{gnu}/Linux platforms, this feature is supported
19d9d4ef 3477with kernel version 2.5.46 and later.
c906108c 3478
19d9d4ef
DB
3479The fork debugging commands are supported in native mode and when
3480connected to @code{gdbserver} in either @code{target remote} mode or
3481@code{target extended-remote} mode.
0d71eef5 3482
c906108c
SS
3483By default, when a program forks, @value{GDBN} will continue to debug
3484the parent process and the child process will run unimpeded.
3485
3486If you want to follow the child process instead of the parent process,
3487use the command @w{@code{set follow-fork-mode}}.
3488
3489@table @code
3490@kindex set follow-fork-mode
3491@item set follow-fork-mode @var{mode}
3492Set the debugger response to a program call of @code{fork} or
3493@code{vfork}. A call to @code{fork} or @code{vfork} creates a new
9c16f35a 3494process. The @var{mode} argument can be:
c906108c
SS
3495
3496@table @code
3497@item parent
3498The original process is debugged after a fork. The child process runs
2df3850c 3499unimpeded. This is the default.
c906108c
SS
3500
3501@item child
3502The new process is debugged after a fork. The parent process runs
3503unimpeded.
3504
c906108c
SS
3505@end table
3506
9c16f35a 3507@kindex show follow-fork-mode
c906108c 3508@item show follow-fork-mode
2df3850c 3509Display the current debugger response to a @code{fork} or @code{vfork} call.
c906108c
SS
3510@end table
3511
5c95884b
MS
3512@cindex debugging multiple processes
3513On Linux, if you want to debug both the parent and child processes, use the
3514command @w{@code{set detach-on-fork}}.
3515
3516@table @code
3517@kindex set detach-on-fork
3518@item set detach-on-fork @var{mode}
3519Tells gdb whether to detach one of the processes after a fork, or
3520retain debugger control over them both.
3521
3522@table @code
3523@item on
3524The child process (or parent process, depending on the value of
3525@code{follow-fork-mode}) will be detached and allowed to run
3526independently. This is the default.
3527
3528@item off
3529Both processes will be held under the control of @value{GDBN}.
3530One process (child or parent, depending on the value of
3531@code{follow-fork-mode}) is debugged as usual, while the other
3532is held suspended.
3533
3534@end table
3535
11310833
NR
3536@kindex show detach-on-fork
3537@item show detach-on-fork
3538Show whether detach-on-fork mode is on/off.
5c95884b
MS
3539@end table
3540
2277426b
PA
3541If you choose to set @samp{detach-on-fork} mode off, then @value{GDBN}
3542will retain control of all forked processes (including nested forks).
3543You can list the forked processes under the control of @value{GDBN} by
3544using the @w{@code{info inferiors}} command, and switch from one fork
6c95b8df
PA
3545to another by using the @code{inferior} command (@pxref{Inferiors and
3546Programs, ,Debugging Multiple Inferiors and Programs}).
5c95884b
MS
3547
3548To quit debugging one of the forked processes, you can either detach
af624141
MS
3549from it by using the @w{@code{detach inferiors}} command (allowing it
3550to run independently), or kill it using the @w{@code{kill inferiors}}
6c95b8df
PA
3551command. @xref{Inferiors and Programs, ,Debugging Multiple Inferiors
3552and Programs}.
5c95884b 3553
c906108c
SS
3554If you ask to debug a child process and a @code{vfork} is followed by an
3555@code{exec}, @value{GDBN} executes the new target up to the first
3556breakpoint in the new target. If you have a breakpoint set on
3557@code{main} in your original program, the breakpoint will also be set on
3558the child process's @code{main}.
3559
2277426b
PA
3560On some systems, when a child process is spawned by @code{vfork}, you
3561cannot debug the child or parent until an @code{exec} call completes.
c906108c
SS
3562
3563If you issue a @code{run} command to @value{GDBN} after an @code{exec}
6c95b8df
PA
3564call executes, the new target restarts. To restart the parent
3565process, use the @code{file} command with the parent executable name
3566as its argument. By default, after an @code{exec} call executes,
3567@value{GDBN} discards the symbols of the previous executable image.
3568You can change this behaviour with the @w{@code{set follow-exec-mode}}
3569command.
3570
3571@table @code
3572@kindex set follow-exec-mode
3573@item set follow-exec-mode @var{mode}
3574
3575Set debugger response to a program call of @code{exec}. An
3576@code{exec} call replaces the program image of a process.
3577
3578@code{follow-exec-mode} can be:
3579
3580@table @code
3581@item new
3582@value{GDBN} creates a new inferior and rebinds the process to this
3583new inferior. The program the process was running before the
3584@code{exec} call can be restarted afterwards by restarting the
3585original inferior.
3586
3587For example:
3588
3589@smallexample
3590(@value{GDBP}) info inferiors
3591(gdb) info inferior
3592 Id Description Executable
3593* 1 <null> prog1
3594(@value{GDBP}) run
3595process 12020 is executing new program: prog2
3596Program exited normally.
3597(@value{GDBP}) info inferiors
3598 Id Description Executable
c0ecb95f 3599 1 <null> prog1
b05b1202 3600* 2 <null> prog2
6c95b8df
PA
3601@end smallexample
3602
3603@item same
3604@value{GDBN} keeps the process bound to the same inferior. The new
3605executable image replaces the previous executable loaded in the
3606inferior. Restarting the inferior after the @code{exec} call, with
3607e.g., the @code{run} command, restarts the executable the process was
3608running after the @code{exec} call. This is the default mode.
3609
3610For example:
3611
3612@smallexample
3613(@value{GDBP}) info inferiors
3614 Id Description Executable
3615* 1 <null> prog1
3616(@value{GDBP}) run
3617process 12020 is executing new program: prog2
3618Program exited normally.
3619(@value{GDBP}) info inferiors
3620 Id Description Executable
3621* 1 <null> prog2
3622@end smallexample
3623
3624@end table
3625@end table
c906108c 3626
19d9d4ef
DB
3627@code{follow-exec-mode} is supported in native mode and
3628@code{target extended-remote} mode.
3629
c906108c
SS
3630You can use the @code{catch} command to make @value{GDBN} stop whenever
3631a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
79a6e687 3632Catchpoints, ,Setting Catchpoints}.
c906108c 3633
5c95884b 3634@node Checkpoint/Restart
79a6e687 3635@section Setting a @emph{Bookmark} to Return to Later
5c95884b
MS
3636
3637@cindex checkpoint
3638@cindex restart
3639@cindex bookmark
3640@cindex snapshot of a process
3641@cindex rewind program state
3642
3643On certain operating systems@footnote{Currently, only
3644@sc{gnu}/Linux.}, @value{GDBN} is able to save a @dfn{snapshot} of a
3645program's state, called a @dfn{checkpoint}, and come back to it
3646later.
3647
3648Returning to a checkpoint effectively undoes everything that has
3649happened in the program since the @code{checkpoint} was saved. This
3650includes changes in memory, registers, and even (within some limits)
3651system state. Effectively, it is like going back in time to the
3652moment when the checkpoint was saved.
3653
3654Thus, if you're stepping thru a program and you think you're
3655getting close to the point where things go wrong, you can save
3656a checkpoint. Then, if you accidentally go too far and miss
3657the critical statement, instead of having to restart your program
3658from the beginning, you can just go back to the checkpoint and
3659start again from there.
3660
3661This can be especially useful if it takes a lot of time or
3662steps to reach the point where you think the bug occurs.
3663
3664To use the @code{checkpoint}/@code{restart} method of debugging:
3665
3666@table @code
3667@kindex checkpoint
3668@item checkpoint
3669Save a snapshot of the debugged program's current execution state.
3670The @code{checkpoint} command takes no arguments, but each checkpoint
3671is assigned a small integer id, similar to a breakpoint id.
3672
3673@kindex info checkpoints
3674@item info checkpoints
3675List the checkpoints that have been saved in the current debugging
3676session. For each checkpoint, the following information will be
3677listed:
3678
3679@table @code
3680@item Checkpoint ID
3681@item Process ID
3682@item Code Address
3683@item Source line, or label
3684@end table
3685
3686@kindex restart @var{checkpoint-id}
3687@item restart @var{checkpoint-id}
3688Restore the program state that was saved as checkpoint number
3689@var{checkpoint-id}. All program variables, registers, stack frames
3690etc.@: will be returned to the values that they had when the checkpoint
3691was saved. In essence, gdb will ``wind back the clock'' to the point
3692in time when the checkpoint was saved.
3693
3694Note that breakpoints, @value{GDBN} variables, command history etc.
3695are not affected by restoring a checkpoint. In general, a checkpoint
3696only restores things that reside in the program being debugged, not in
3697the debugger.
3698
b8db102d
MS
3699@kindex delete checkpoint @var{checkpoint-id}
3700@item delete checkpoint @var{checkpoint-id}
5c95884b
MS
3701Delete the previously-saved checkpoint identified by @var{checkpoint-id}.
3702
3703@end table
3704
3705Returning to a previously saved checkpoint will restore the user state
3706of the program being debugged, plus a significant subset of the system
3707(OS) state, including file pointers. It won't ``un-write'' data from
3708a file, but it will rewind the file pointer to the previous location,
3709so that the previously written data can be overwritten. For files
3710opened in read mode, the pointer will also be restored so that the
3711previously read data can be read again.
3712
3713Of course, characters that have been sent to a printer (or other
3714external device) cannot be ``snatched back'', and characters received
3715from eg.@: a serial device can be removed from internal program buffers,
3716but they cannot be ``pushed back'' into the serial pipeline, ready to
3717be received again. Similarly, the actual contents of files that have
3718been changed cannot be restored (at this time).
3719
3720However, within those constraints, you actually can ``rewind'' your
3721program to a previously saved point in time, and begin debugging it
3722again --- and you can change the course of events so as to debug a
3723different execution path this time.
3724
3725@cindex checkpoints and process id
3726Finally, there is one bit of internal program state that will be
3727different when you return to a checkpoint --- the program's process
3728id. Each checkpoint will have a unique process id (or @var{pid}),
3729and each will be different from the program's original @var{pid}.
3730If your program has saved a local copy of its process id, this could
3731potentially pose a problem.
3732
79a6e687 3733@subsection A Non-obvious Benefit of Using Checkpoints
5c95884b
MS
3734
3735On some systems such as @sc{gnu}/Linux, address space randomization
3736is performed on new processes for security reasons. This makes it
3737difficult or impossible to set a breakpoint, or watchpoint, on an
3738absolute address if you have to restart the program, since the
3739absolute location of a symbol will change from one execution to the
3740next.
3741
3742A checkpoint, however, is an @emph{identical} copy of a process.
3743Therefore if you create a checkpoint at (eg.@:) the start of main,
3744and simply return to that checkpoint instead of restarting the
3745process, you can avoid the effects of address randomization and
3746your symbols will all stay in the same place.
3747
6d2ebf8b 3748@node Stopping
c906108c
SS
3749@chapter Stopping and Continuing
3750
3751The principal purposes of using a debugger are so that you can stop your
3752program before it terminates; or so that, if your program runs into
3753trouble, you can investigate and find out why.
3754
7a292a7a
SS
3755Inside @value{GDBN}, your program may stop for any of several reasons,
3756such as a signal, a breakpoint, or reaching a new line after a
3757@value{GDBN} command such as @code{step}. You may then examine and
3758change variables, set new breakpoints or remove old ones, and then
3759continue execution. Usually, the messages shown by @value{GDBN} provide
3760ample explanation of the status of your program---but you can also
3761explicitly request this information at any time.
c906108c
SS
3762
3763@table @code
3764@kindex info program
3765@item info program
3766Display information about the status of your program: whether it is
7a292a7a 3767running or not, what process it is, and why it stopped.
c906108c
SS
3768@end table
3769
3770@menu
3771* Breakpoints:: Breakpoints, watchpoints, and catchpoints
3772* Continuing and Stepping:: Resuming execution
aad1c02c
TT
3773* Skipping Over Functions and Files::
3774 Skipping over functions and files
c906108c 3775* Signals:: Signals
c906108c 3776* Thread Stops:: Stopping and starting multi-thread programs
c906108c
SS
3777@end menu
3778
6d2ebf8b 3779@node Breakpoints
79a6e687 3780@section Breakpoints, Watchpoints, and Catchpoints
c906108c
SS
3781
3782@cindex breakpoints
3783A @dfn{breakpoint} makes your program stop whenever a certain point in
3784the program is reached. For each breakpoint, you can add conditions to
3785control in finer detail whether your program stops. You can set
3786breakpoints with the @code{break} command and its variants (@pxref{Set
79a6e687 3787Breaks, ,Setting Breakpoints}), to specify the place where your program
c906108c
SS
3788should stop by line number, function name or exact address in the
3789program.
3790
09d4efe1 3791On some systems, you can set breakpoints in shared libraries before
b1236ac3 3792the executable is run.
c906108c
SS
3793
3794@cindex watchpoints
fd60e0df 3795@cindex data breakpoints
c906108c
SS
3796@cindex memory tracing
3797@cindex breakpoint on memory address
3798@cindex breakpoint on variable modification
3799A @dfn{watchpoint} is a special breakpoint that stops your program
fd60e0df 3800when the value of an expression changes. The expression may be a value
0ced0c34 3801of a variable, or it could involve values of one or more variables
fd60e0df
EZ
3802combined by operators, such as @samp{a + b}. This is sometimes called
3803@dfn{data breakpoints}. You must use a different command to set
79a6e687 3804watchpoints (@pxref{Set Watchpoints, ,Setting Watchpoints}), but aside
fd60e0df
EZ
3805from that, you can manage a watchpoint like any other breakpoint: you
3806enable, disable, and delete both breakpoints and watchpoints using the
3807same commands.
c906108c
SS
3808
3809You can arrange to have values from your program displayed automatically
3810whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
79a6e687 3811Automatic Display}.
c906108c
SS
3812
3813@cindex catchpoints
3814@cindex breakpoint on events
3815A @dfn{catchpoint} is another special breakpoint that stops your program
b37052ae 3816when a certain kind of event occurs, such as the throwing of a C@t{++}
c906108c
SS
3817exception or the loading of a library. As with watchpoints, you use a
3818different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
79a6e687 3819Catchpoints}), but aside from that, you can manage a catchpoint like any
c906108c 3820other breakpoint. (To stop when your program receives a signal, use the
d4f3574e 3821@code{handle} command; see @ref{Signals, ,Signals}.)
c906108c
SS
3822
3823@cindex breakpoint numbers
3824@cindex numbers for breakpoints
3825@value{GDBN} assigns a number to each breakpoint, watchpoint, or
3826catchpoint when you create it; these numbers are successive integers
3827starting with one. In many of the commands for controlling various
3828features of breakpoints you use the breakpoint number to say which
3829breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
3830@dfn{disabled}; if disabled, it has no effect on your program until you
3831enable it again.
3832
c5394b80 3833@cindex breakpoint ranges
18da0c51 3834@cindex breakpoint lists
c5394b80 3835@cindex ranges of breakpoints
18da0c51
MG
3836@cindex lists of breakpoints
3837Some @value{GDBN} commands accept a space-separated list of breakpoints
3838on which to operate. A list element can be either a single breakpoint number,
3839like @samp{5}, or a range of such numbers, like @samp{5-7}.
3840When a breakpoint list is given to a command, all breakpoints in that list
3841are operated on.
c5394b80 3842
c906108c
SS
3843@menu
3844* Set Breaks:: Setting breakpoints
3845* Set Watchpoints:: Setting watchpoints
3846* Set Catchpoints:: Setting catchpoints
3847* Delete Breaks:: Deleting breakpoints
3848* Disabling:: Disabling breakpoints
3849* Conditions:: Break conditions
3850* Break Commands:: Breakpoint command lists
e7e0cddf 3851* Dynamic Printf:: Dynamic printf
6149aea9 3852* Save Breakpoints:: How to save breakpoints in a file
62e5f89c 3853* Static Probe Points:: Listing static probe points
d4f3574e 3854* Error in Breakpoints:: ``Cannot insert breakpoints''
79a6e687 3855* Breakpoint-related Warnings:: ``Breakpoint address adjusted...''
c906108c
SS
3856@end menu
3857
6d2ebf8b 3858@node Set Breaks
79a6e687 3859@subsection Setting Breakpoints
c906108c 3860
5d161b24 3861@c FIXME LMB what does GDB do if no code on line of breakpt?
c906108c
SS
3862@c consider in particular declaration with/without initialization.
3863@c
3864@c FIXME 2 is there stuff on this already? break at fun start, already init?
3865
3866@kindex break
41afff9a
EZ
3867@kindex b @r{(@code{break})}
3868@vindex $bpnum@r{, convenience variable}
c906108c
SS
3869@cindex latest breakpoint
3870Breakpoints are set with the @code{break} command (abbreviated
5d161b24 3871@code{b}). The debugger convenience variable @samp{$bpnum} records the
f3b28801 3872number of the breakpoint you've set most recently; see @ref{Convenience
79a6e687 3873Vars,, Convenience Variables}, for a discussion of what you can do with
c906108c
SS
3874convenience variables.
3875
c906108c 3876@table @code
2a25a5ba
EZ
3877@item break @var{location}
3878Set a breakpoint at the given @var{location}, which can specify a
3879function name, a line number, or an address of an instruction.
3880(@xref{Specify Location}, for a list of all the possible ways to
3881specify a @var{location}.) The breakpoint will stop your program just
3882before it executes any of the code in the specified @var{location}.
3883
c906108c 3884When using source languages that permit overloading of symbols, such as
2a25a5ba 3885C@t{++}, a function name may refer to more than one possible place to break.
6ba66d6a
JB
3886@xref{Ambiguous Expressions,,Ambiguous Expressions}, for a discussion of
3887that situation.
c906108c 3888
45ac276d 3889It is also possible to insert a breakpoint that will stop the program
2c88c651
JB
3890only if a specific thread (@pxref{Thread-Specific Breakpoints})
3891or a specific task (@pxref{Ada Tasks}) hits that breakpoint.
45ac276d 3892
c906108c
SS
3893@item break
3894When called without any arguments, @code{break} sets a breakpoint at
3895the next instruction to be executed in the selected stack frame
3896(@pxref{Stack, ,Examining the Stack}). In any selected frame but the
3897innermost, this makes your program stop as soon as control
3898returns to that frame. This is similar to the effect of a
3899@code{finish} command in the frame inside the selected frame---except
3900that @code{finish} does not leave an active breakpoint. If you use
3901@code{break} without an argument in the innermost frame, @value{GDBN} stops
3902the next time it reaches the current location; this may be useful
3903inside loops.
3904
3905@value{GDBN} normally ignores breakpoints when it resumes execution, until at
3906least one instruction has been executed. If it did not do this, you
3907would be unable to proceed past a breakpoint without first disabling the
3908breakpoint. This rule applies whether or not the breakpoint already
3909existed when your program stopped.
3910
3911@item break @dots{} if @var{cond}
3912Set a breakpoint with condition @var{cond}; evaluate the expression
3913@var{cond} each time the breakpoint is reached, and stop only if the
3914value is nonzero---that is, if @var{cond} evaluates as true.
3915@samp{@dots{}} stands for one of the possible arguments described
3916above (or no argument) specifying where to break. @xref{Conditions,
79a6e687 3917,Break Conditions}, for more information on breakpoint conditions.
c906108c
SS
3918
3919@kindex tbreak
3920@item tbreak @var{args}
697aa1b7 3921Set a breakpoint enabled only for one stop. The @var{args} are the
c906108c
SS
3922same as for the @code{break} command, and the breakpoint is set in the same
3923way, but the breakpoint is automatically deleted after the first time your
79a6e687 3924program stops there. @xref{Disabling, ,Disabling Breakpoints}.
c906108c 3925
c906108c 3926@kindex hbreak
ba04e063 3927@cindex hardware breakpoints
c906108c 3928@item hbreak @var{args}
697aa1b7 3929Set a hardware-assisted breakpoint. The @var{args} are the same as for the
d4f3574e 3930@code{break} command and the breakpoint is set in the same way, but the
c906108c
SS
3931breakpoint requires hardware support and some target hardware may not
3932have this support. The main purpose of this is EPROM/ROM code
d4f3574e
SS
3933debugging, so you can set a breakpoint at an instruction without
3934changing the instruction. This can be used with the new trap-generation
09d4efe1 3935provided by SPARClite DSU and most x86-based targets. These targets
d4f3574e
SS
3936will generate traps when a program accesses some data or instruction
3937address that is assigned to the debug registers. However the hardware
3938breakpoint registers can take a limited number of breakpoints. For
3939example, on the DSU, only two data breakpoints can be set at a time, and
3940@value{GDBN} will reject this command if more than two are used. Delete
3941or disable unused hardware breakpoints before setting new ones
79a6e687
BW
3942(@pxref{Disabling, ,Disabling Breakpoints}).
3943@xref{Conditions, ,Break Conditions}.
9c16f35a
EZ
3944For remote targets, you can restrict the number of hardware
3945breakpoints @value{GDBN} will use, see @ref{set remote
3946hardware-breakpoint-limit}.
501eef12 3947
c906108c
SS
3948@kindex thbreak
3949@item thbreak @var{args}
697aa1b7 3950Set a hardware-assisted breakpoint enabled only for one stop. The @var{args}
c906108c 3951are the same as for the @code{hbreak} command and the breakpoint is set in
5d161b24 3952the same way. However, like the @code{tbreak} command,
c906108c
SS
3953the breakpoint is automatically deleted after the
3954first time your program stops there. Also, like the @code{hbreak}
5d161b24 3955command, the breakpoint requires hardware support and some target hardware
79a6e687
BW
3956may not have this support. @xref{Disabling, ,Disabling Breakpoints}.
3957See also @ref{Conditions, ,Break Conditions}.
c906108c
SS
3958
3959@kindex rbreak
3960@cindex regular expression
8bd10a10 3961@cindex breakpoints at functions matching a regexp
c45da7e6 3962@cindex set breakpoints in many functions
c906108c 3963@item rbreak @var{regex}
c906108c 3964Set breakpoints on all functions matching the regular expression
11cf8741
JM
3965@var{regex}. This command sets an unconditional breakpoint on all
3966matches, printing a list of all breakpoints it set. Once these
3967breakpoints are set, they are treated just like the breakpoints set with
3968the @code{break} command. You can delete them, disable them, or make
3969them conditional the same way as any other breakpoint.
3970
20813a0b
PW
3971In programs using different languages, @value{GDBN} chooses the syntax
3972to print the list of all breakpoints it sets according to the
3973@samp{set language} value: using @samp{set language auto}
3974(see @ref{Automatically, ,Set Language Automatically}) means to use the
3975language of the breakpoint's function, other values mean to use
3976the manually specified language (see @ref{Manually, ,Set Language Manually}).
3977
11cf8741
JM
3978The syntax of the regular expression is the standard one used with tools
3979like @file{grep}. Note that this is different from the syntax used by
3980shells, so for instance @code{foo*} matches all functions that include
3981an @code{fo} followed by zero or more @code{o}s. There is an implicit
3982@code{.*} leading and trailing the regular expression you supply, so to
3983match only functions that begin with @code{foo}, use @code{^foo}.
c906108c 3984
f7dc1244 3985@cindex non-member C@t{++} functions, set breakpoint in
b37052ae 3986When debugging C@t{++} programs, @code{rbreak} is useful for setting
c906108c
SS
3987breakpoints on overloaded functions that are not members of any special
3988classes.
c906108c 3989
f7dc1244
EZ
3990@cindex set breakpoints on all functions
3991The @code{rbreak} command can be used to set breakpoints in
3992@strong{all} the functions in a program, like this:
3993
3994@smallexample
3995(@value{GDBP}) rbreak .
3996@end smallexample
3997
8bd10a10
CM
3998@item rbreak @var{file}:@var{regex}
3999If @code{rbreak} is called with a filename qualification, it limits
4000the search for functions matching the given regular expression to the
4001specified @var{file}. This can be used, for example, to set breakpoints on
4002every function in a given file:
4003
4004@smallexample
4005(@value{GDBP}) rbreak file.c:.
4006@end smallexample
4007
4008The colon separating the filename qualifier from the regex may
4009optionally be surrounded by spaces.
4010
c906108c
SS
4011@kindex info breakpoints
4012@cindex @code{$_} and @code{info breakpoints}
18da0c51
MG
4013@item info breakpoints @r{[}@var{list}@dots{}@r{]}
4014@itemx info break @r{[}@var{list}@dots{}@r{]}
c906108c 4015Print a table of all breakpoints, watchpoints, and catchpoints set and
45ac1734 4016not deleted. Optional argument @var{n} means print information only
e5a67952
MS
4017about the specified breakpoint(s) (or watchpoint(s) or catchpoint(s)).
4018For each breakpoint, following columns are printed:
c906108c
SS
4019
4020@table @emph
4021@item Breakpoint Numbers
4022@item Type
4023Breakpoint, watchpoint, or catchpoint.
4024@item Disposition
4025Whether the breakpoint is marked to be disabled or deleted when hit.
4026@item Enabled or Disabled
4027Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
b3db7447 4028that are not enabled.
c906108c 4029@item Address
fe6fbf8b 4030Where the breakpoint is in your program, as a memory address. For a
b3db7447
NR
4031pending breakpoint whose address is not yet known, this field will
4032contain @samp{<PENDING>}. Such breakpoint won't fire until a shared
4033library that has the symbol or line referred by breakpoint is loaded.
4034See below for details. A breakpoint with several locations will
3b784c4f 4035have @samp{<MULTIPLE>} in this field---see below for details.
c906108c
SS
4036@item What
4037Where the breakpoint is in the source for your program, as a file and
2650777c
JJ
4038line number. For a pending breakpoint, the original string passed to
4039the breakpoint command will be listed as it cannot be resolved until
4040the appropriate shared library is loaded in the future.
c906108c
SS
4041@end table
4042
4043@noindent
83364271
LM
4044If a breakpoint is conditional, there are two evaluation modes: ``host'' and
4045``target''. If mode is ``host'', breakpoint condition evaluation is done by
4046@value{GDBN} on the host's side. If it is ``target'', then the condition
4047is evaluated by the target. The @code{info break} command shows
4048the condition on the line following the affected breakpoint, together with
4049its condition evaluation mode in between parentheses.
4050
4051Breakpoint commands, if any, are listed after that. A pending breakpoint is
4052allowed to have a condition specified for it. The condition is not parsed for
4053validity until a shared library is loaded that allows the pending
4054breakpoint to resolve to a valid location.
c906108c
SS
4055
4056@noindent
4057@code{info break} with a breakpoint
4058number @var{n} as argument lists only that breakpoint. The
4059convenience variable @code{$_} and the default examining-address for
4060the @code{x} command are set to the address of the last breakpoint
79a6e687 4061listed (@pxref{Memory, ,Examining Memory}).
c906108c
SS
4062
4063@noindent
4064@code{info break} displays a count of the number of times the breakpoint
4065has been hit. This is especially useful in conjunction with the
4066@code{ignore} command. You can ignore a large number of breakpoint
4067hits, look at the breakpoint info to see how many times the breakpoint
4068was hit, and then run again, ignoring one less than that number. This
4069will get you quickly to the last hit of that breakpoint.
816338b5
SS
4070
4071@noindent
4072For a breakpoints with an enable count (xref) greater than 1,
4073@code{info break} also displays that count.
4074
c906108c
SS
4075@end table
4076
4077@value{GDBN} allows you to set any number of breakpoints at the same place in
4078your program. There is nothing silly or meaningless about this. When
4079the breakpoints are conditional, this is even useful
79a6e687 4080(@pxref{Conditions, ,Break Conditions}).
c906108c 4081
2e9132cc
EZ
4082@cindex multiple locations, breakpoints
4083@cindex breakpoints, multiple locations
fcda367b 4084It is possible that a breakpoint corresponds to several locations
fe6fbf8b
VP
4085in your program. Examples of this situation are:
4086
4087@itemize @bullet
f8eba3c6
TT
4088@item
4089Multiple functions in the program may have the same name.
4090
fe6fbf8b
VP
4091@item
4092For a C@t{++} constructor, the @value{NGCC} compiler generates several
4093instances of the function body, used in different cases.
4094
4095@item
4096For a C@t{++} template function, a given line in the function can
4097correspond to any number of instantiations.
4098
4099@item
4100For an inlined function, a given source line can correspond to
4101several places where that function is inlined.
fe6fbf8b
VP
4102@end itemize
4103
4104In all those cases, @value{GDBN} will insert a breakpoint at all
f8eba3c6 4105the relevant locations.
fe6fbf8b 4106
3b784c4f
EZ
4107A breakpoint with multiple locations is displayed in the breakpoint
4108table using several rows---one header row, followed by one row for
4109each breakpoint location. The header row has @samp{<MULTIPLE>} in the
4110address column. The rows for individual locations contain the actual
4111addresses for locations, and show the functions to which those
4112locations belong. The number column for a location is of the form
fe6fbf8b
VP
4113@var{breakpoint-number}.@var{location-number}.
4114
4115For example:
3b784c4f 4116
fe6fbf8b
VP
4117@smallexample
4118Num Type Disp Enb Address What
41191 breakpoint keep y <MULTIPLE>
4120 stop only if i==1
4121 breakpoint already hit 1 time
41221.1 y 0x080486a2 in void foo<int>() at t.cc:8
41231.2 y 0x080486ca in void foo<double>() at t.cc:8
4124@end smallexample
4125
d0fe4701
XR
4126You cannot delete the individual locations from a breakpoint. However,
4127each location can be individually enabled or disabled by passing
fe6fbf8b 4128@var{breakpoint-number}.@var{location-number} as argument to the
d0fe4701
XR
4129@code{enable} and @code{disable} commands. It's also possible to
4130@code{enable} and @code{disable} a range of @var{location-number}
4131locations using a @var{breakpoint-number} and two @var{location-number}s,
4132in increasing order, separated by a hyphen, like
4133@kbd{@var{breakpoint-number}.@var{location-number1}-@var{location-number2}},
4134in which case @value{GDBN} acts on all the locations in the range (inclusive).
4135Disabling or enabling the parent breakpoint (@pxref{Disabling}) affects
4136all of the locations that belong to that breakpoint.
fe6fbf8b 4137
2650777c 4138@cindex pending breakpoints
fe6fbf8b 4139It's quite common to have a breakpoint inside a shared library.
3b784c4f 4140Shared libraries can be loaded and unloaded explicitly,
fe6fbf8b
VP
4141and possibly repeatedly, as the program is executed. To support
4142this use case, @value{GDBN} updates breakpoint locations whenever
4143any shared library is loaded or unloaded. Typically, you would
fcda367b 4144set a breakpoint in a shared library at the beginning of your
fe6fbf8b
VP
4145debugging session, when the library is not loaded, and when the
4146symbols from the library are not available. When you try to set
4147breakpoint, @value{GDBN} will ask you if you want to set
3b784c4f 4148a so called @dfn{pending breakpoint}---breakpoint whose address
fe6fbf8b
VP
4149is not yet resolved.
4150
4151After the program is run, whenever a new shared library is loaded,
4152@value{GDBN} reevaluates all the breakpoints. When a newly loaded
4153shared library contains the symbol or line referred to by some
4154pending breakpoint, that breakpoint is resolved and becomes an
4155ordinary breakpoint. When a library is unloaded, all breakpoints
4156that refer to its symbols or source lines become pending again.
4157
4158This logic works for breakpoints with multiple locations, too. For
4159example, if you have a breakpoint in a C@t{++} template function, and
4160a newly loaded shared library has an instantiation of that template,
4161a new location is added to the list of locations for the breakpoint.
4162
4163Except for having unresolved address, pending breakpoints do not
4164differ from regular breakpoints. You can set conditions or commands,
4165enable and disable them and perform other breakpoint operations.
4166
4167@value{GDBN} provides some additional commands for controlling what
4168happens when the @samp{break} command cannot resolve breakpoint
4169address specification to an address:
dd79a6cf
JJ
4170
4171@kindex set breakpoint pending
4172@kindex show breakpoint pending
4173@table @code
4174@item set breakpoint pending auto
4175This is the default behavior. When @value{GDBN} cannot find the breakpoint
4176location, it queries you whether a pending breakpoint should be created.
4177
4178@item set breakpoint pending on
4179This indicates that an unrecognized breakpoint location should automatically
4180result in a pending breakpoint being created.
4181
4182@item set breakpoint pending off
4183This indicates that pending breakpoints are not to be created. Any
4184unrecognized breakpoint location results in an error. This setting does
4185not affect any pending breakpoints previously created.
4186
4187@item show breakpoint pending
4188Show the current behavior setting for creating pending breakpoints.
4189@end table
2650777c 4190
fe6fbf8b
VP
4191The settings above only affect the @code{break} command and its
4192variants. Once breakpoint is set, it will be automatically updated
4193as shared libraries are loaded and unloaded.
2650777c 4194
765dc015
VP
4195@cindex automatic hardware breakpoints
4196For some targets, @value{GDBN} can automatically decide if hardware or
4197software breakpoints should be used, depending on whether the
4198breakpoint address is read-only or read-write. This applies to
4199breakpoints set with the @code{break} command as well as to internal
4200breakpoints set by commands like @code{next} and @code{finish}. For
fcda367b 4201breakpoints set with @code{hbreak}, @value{GDBN} will always use hardware
765dc015
VP
4202breakpoints.
4203
18da0c51 4204You can control this automatic behaviour with the following commands:
765dc015
VP
4205
4206@kindex set breakpoint auto-hw
4207@kindex show breakpoint auto-hw
4208@table @code
4209@item set breakpoint auto-hw on
4210This is the default behavior. When @value{GDBN} sets a breakpoint, it
4211will try to use the target memory map to decide if software or hardware
4212breakpoint must be used.
4213
4214@item set breakpoint auto-hw off
4215This indicates @value{GDBN} should not automatically select breakpoint
4216type. If the target provides a memory map, @value{GDBN} will warn when
4217trying to set software breakpoint at a read-only address.
4218@end table
4219
74960c60
VP
4220@value{GDBN} normally implements breakpoints by replacing the program code
4221at the breakpoint address with a special instruction, which, when
4222executed, given control to the debugger. By default, the program
4223code is so modified only when the program is resumed. As soon as
4224the program stops, @value{GDBN} restores the original instructions. This
4225behaviour guards against leaving breakpoints inserted in the
4226target should gdb abrubptly disconnect. However, with slow remote
4227targets, inserting and removing breakpoint can reduce the performance.
4228This behavior can be controlled with the following commands::
4229
4230@kindex set breakpoint always-inserted
4231@kindex show breakpoint always-inserted
4232@table @code
4233@item set breakpoint always-inserted off
33e5cbd6
PA
4234All breakpoints, including newly added by the user, are inserted in
4235the target only when the target is resumed. All breakpoints are
a25a5a45 4236removed from the target when it stops. This is the default mode.
74960c60
VP
4237
4238@item set breakpoint always-inserted on
4239Causes all breakpoints to be inserted in the target at all times. If
4240the user adds a new breakpoint, or changes an existing breakpoint, the
4241breakpoints in the target are updated immediately. A breakpoint is
a25a5a45 4242removed from the target only when breakpoint itself is deleted.
342cc091 4243@end table
765dc015 4244
83364271
LM
4245@value{GDBN} handles conditional breakpoints by evaluating these conditions
4246when a breakpoint breaks. If the condition is true, then the process being
4247debugged stops, otherwise the process is resumed.
4248
4249If the target supports evaluating conditions on its end, @value{GDBN} may
4250download the breakpoint, together with its conditions, to it.
4251
4252This feature can be controlled via the following commands:
4253
4254@kindex set breakpoint condition-evaluation
4255@kindex show breakpoint condition-evaluation
4256@table @code
4257@item set breakpoint condition-evaluation host
4258This option commands @value{GDBN} to evaluate the breakpoint
4259conditions on the host's side. Unconditional breakpoints are sent to
4260the target which in turn receives the triggers and reports them back to GDB
4261for condition evaluation. This is the standard evaluation mode.
4262
4263@item set breakpoint condition-evaluation target
4264This option commands @value{GDBN} to download breakpoint conditions
4265to the target at the moment of their insertion. The target
4266is responsible for evaluating the conditional expression and reporting
4267breakpoint stop events back to @value{GDBN} whenever the condition
4268is true. Due to limitations of target-side evaluation, some conditions
4269cannot be evaluated there, e.g., conditions that depend on local data
4270that is only known to the host. Examples include
4271conditional expressions involving convenience variables, complex types
4272that cannot be handled by the agent expression parser and expressions
4273that are too long to be sent over to the target, specially when the
4274target is a remote system. In these cases, the conditions will be
4275evaluated by @value{GDBN}.
4276
4277@item set breakpoint condition-evaluation auto
4278This is the default mode. If the target supports evaluating breakpoint
4279conditions on its end, @value{GDBN} will download breakpoint conditions to
4280the target (limitations mentioned previously apply). If the target does
4281not support breakpoint condition evaluation, then @value{GDBN} will fallback
4282to evaluating all these conditions on the host's side.
4283@end table
4284
4285
c906108c
SS
4286@cindex negative breakpoint numbers
4287@cindex internal @value{GDBN} breakpoints
eb12ee30
AC
4288@value{GDBN} itself sometimes sets breakpoints in your program for
4289special purposes, such as proper handling of @code{longjmp} (in C
4290programs). These internal breakpoints are assigned negative numbers,
4291starting with @code{-1}; @samp{info breakpoints} does not display them.
c906108c 4292You can see these breakpoints with the @value{GDBN} maintenance command
eb12ee30 4293@samp{maint info breakpoints} (@pxref{maint info breakpoints}).
c906108c
SS
4294
4295
6d2ebf8b 4296@node Set Watchpoints
79a6e687 4297@subsection Setting Watchpoints
c906108c
SS
4298
4299@cindex setting watchpoints
c906108c
SS
4300You can use a watchpoint to stop execution whenever the value of an
4301expression changes, without having to predict a particular place where
fd60e0df
EZ
4302this may happen. (This is sometimes called a @dfn{data breakpoint}.)
4303The expression may be as simple as the value of a single variable, or
4304as complex as many variables combined by operators. Examples include:
4305
4306@itemize @bullet
4307@item
4308A reference to the value of a single variable.
4309
4310@item
4311An address cast to an appropriate data type. For example,
4312@samp{*(int *)0x12345678} will watch a 4-byte region at the specified
4313address (assuming an @code{int} occupies 4 bytes).
4314
4315@item
4316An arbitrarily complex expression, such as @samp{a*b + c/d}. The
4317expression can use any operators valid in the program's native
4318language (@pxref{Languages}).
4319@end itemize
c906108c 4320
fa4727a6
DJ
4321You can set a watchpoint on an expression even if the expression can
4322not be evaluated yet. For instance, you can set a watchpoint on
4323@samp{*global_ptr} before @samp{global_ptr} is initialized.
4324@value{GDBN} will stop when your program sets @samp{global_ptr} and
4325the expression produces a valid value. If the expression becomes
4326valid in some other way than changing a variable (e.g.@: if the memory
4327pointed to by @samp{*global_ptr} becomes readable as the result of a
4328@code{malloc} call), @value{GDBN} may not stop until the next time
4329the expression changes.
4330
82f2d802
EZ
4331@cindex software watchpoints
4332@cindex hardware watchpoints
c906108c 4333Depending on your system, watchpoints may be implemented in software or
2df3850c 4334hardware. @value{GDBN} does software watchpointing by single-stepping your
c906108c
SS
4335program and testing the variable's value each time, which is hundreds of
4336times slower than normal execution. (But this may still be worth it, to
4337catch errors where you have no clue what part of your program is the
4338culprit.)
4339
b1236ac3
PA
4340On some systems, such as most PowerPC or x86-based targets,
4341@value{GDBN} includes support for hardware watchpoints, which do not
4342slow down the running of your program.
c906108c
SS
4343
4344@table @code
4345@kindex watch
5d5658a1 4346@item watch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
fd60e0df
EZ
4347Set a watchpoint for an expression. @value{GDBN} will break when the
4348expression @var{expr} is written into by the program and its value
4349changes. The simplest (and the most popular) use of this command is
4350to watch the value of a single variable:
4351
4352@smallexample
4353(@value{GDBP}) watch foo
4354@end smallexample
c906108c 4355
5d5658a1 4356If the command includes a @code{@r{[}thread @var{thread-id}@r{]}}
9c06b0b4 4357argument, @value{GDBN} breaks only when the thread identified by
5d5658a1 4358@var{thread-id} changes the value of @var{expr}. If any other threads
d8b2a693
JB
4359change the value of @var{expr}, @value{GDBN} will not break. Note
4360that watchpoints restricted to a single thread in this way only work
4361with Hardware Watchpoints.
4362
06a64a0b
TT
4363Ordinarily a watchpoint respects the scope of variables in @var{expr}
4364(see below). The @code{-location} argument tells @value{GDBN} to
4365instead watch the memory referred to by @var{expr}. In this case,
4366@value{GDBN} will evaluate @var{expr}, take the address of the result,
4367and watch the memory at that address. The type of the result is used
4368to determine the size of the watched memory. If the expression's
4369result does not have an address, then @value{GDBN} will print an
4370error.
4371
9c06b0b4
TJB
4372The @code{@r{[}mask @var{maskvalue}@r{]}} argument allows creation
4373of masked watchpoints, if the current architecture supports this
4374feature (e.g., PowerPC Embedded architecture, see @ref{PowerPC
4375Embedded}.) A @dfn{masked watchpoint} specifies a mask in addition
4376to an address to watch. The mask specifies that some bits of an address
4377(the bits which are reset in the mask) should be ignored when matching
4378the address accessed by the inferior against the watchpoint address.
4379Thus, a masked watchpoint watches many addresses simultaneously---those
4380addresses whose unmasked bits are identical to the unmasked bits in the
4381watchpoint address. The @code{mask} argument implies @code{-location}.
4382Examples:
4383
4384@smallexample
4385(@value{GDBP}) watch foo mask 0xffff00ff
4386(@value{GDBP}) watch *0xdeadbeef mask 0xffffff00
4387@end smallexample
4388
c906108c 4389@kindex rwatch
5d5658a1 4390@item rwatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
09d4efe1
EZ
4391Set a watchpoint that will break when the value of @var{expr} is read
4392by the program.
c906108c
SS
4393
4394@kindex awatch
5d5658a1 4395@item awatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
09d4efe1
EZ
4396Set a watchpoint that will break when @var{expr} is either read from
4397or written into by the program.
c906108c 4398
18da0c51
MG
4399@kindex info watchpoints @r{[}@var{list}@dots{}@r{]}
4400@item info watchpoints @r{[}@var{list}@dots{}@r{]}
d77f58be
SS
4401This command prints a list of watchpoints, using the same format as
4402@code{info break} (@pxref{Set Breaks}).
c906108c
SS
4403@end table
4404
65d79d4b
SDJ
4405If you watch for a change in a numerically entered address you need to
4406dereference it, as the address itself is just a constant number which will
4407never change. @value{GDBN} refuses to create a watchpoint that watches
4408a never-changing value:
4409
4410@smallexample
4411(@value{GDBP}) watch 0x600850
4412Cannot watch constant value 0x600850.
4413(@value{GDBP}) watch *(int *) 0x600850
4414Watchpoint 1: *(int *) 6293584
4415@end smallexample
4416
c906108c
SS
4417@value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
4418watchpoints execute very quickly, and the debugger reports a change in
4419value at the exact instruction where the change occurs. If @value{GDBN}
4420cannot set a hardware watchpoint, it sets a software watchpoint, which
4421executes more slowly and reports the change in value at the next
82f2d802
EZ
4422@emph{statement}, not the instruction, after the change occurs.
4423
82f2d802
EZ
4424@cindex use only software watchpoints
4425You can force @value{GDBN} to use only software watchpoints with the
4426@kbd{set can-use-hw-watchpoints 0} command. With this variable set to
4427zero, @value{GDBN} will never try to use hardware watchpoints, even if
4428the underlying system supports them. (Note that hardware-assisted
4429watchpoints that were set @emph{before} setting
4430@code{can-use-hw-watchpoints} to zero will still use the hardware
d3e8051b 4431mechanism of watching expression values.)
c906108c 4432
9c16f35a
EZ
4433@table @code
4434@item set can-use-hw-watchpoints
4435@kindex set can-use-hw-watchpoints
4436Set whether or not to use hardware watchpoints.
4437
4438@item show can-use-hw-watchpoints
4439@kindex show can-use-hw-watchpoints
4440Show the current mode of using hardware watchpoints.
4441@end table
4442
4443For remote targets, you can restrict the number of hardware
4444watchpoints @value{GDBN} will use, see @ref{set remote
4445hardware-breakpoint-limit}.
4446
c906108c
SS
4447When you issue the @code{watch} command, @value{GDBN} reports
4448
474c8240 4449@smallexample
c906108c 4450Hardware watchpoint @var{num}: @var{expr}
474c8240 4451@end smallexample
c906108c
SS
4452
4453@noindent
4454if it was able to set a hardware watchpoint.
4455
7be570e7
JM
4456Currently, the @code{awatch} and @code{rwatch} commands can only set
4457hardware watchpoints, because accesses to data that don't change the
4458value of the watched expression cannot be detected without examining
4459every instruction as it is being executed, and @value{GDBN} does not do
4460that currently. If @value{GDBN} finds that it is unable to set a
4461hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
4462will print a message like this:
4463
4464@smallexample
4465Expression cannot be implemented with read/access watchpoint.
4466@end smallexample
4467
4468Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
4469data type of the watched expression is wider than what a hardware
4470watchpoint on the target machine can handle. For example, some systems
4471can only watch regions that are up to 4 bytes wide; on such systems you
4472cannot set hardware watchpoints for an expression that yields a
4473double-precision floating-point number (which is typically 8 bytes
4474wide). As a work-around, it might be possible to break the large region
4475into a series of smaller ones and watch them with separate watchpoints.
4476
4477If you set too many hardware watchpoints, @value{GDBN} might be unable
4478to insert all of them when you resume the execution of your program.
4479Since the precise number of active watchpoints is unknown until such
4480time as the program is about to be resumed, @value{GDBN} might not be
4481able to warn you about this when you set the watchpoints, and the
4482warning will be printed only when the program is resumed:
4483
4484@smallexample
4485Hardware watchpoint @var{num}: Could not insert watchpoint
4486@end smallexample
4487
4488@noindent
4489If this happens, delete or disable some of the watchpoints.
4490
fd60e0df
EZ
4491Watching complex expressions that reference many variables can also
4492exhaust the resources available for hardware-assisted watchpoints.
4493That's because @value{GDBN} needs to watch every variable in the
4494expression with separately allocated resources.
4495
c906108c 4496If you call a function interactively using @code{print} or @code{call},
2df3850c 4497any watchpoints you have set will be inactive until @value{GDBN} reaches another
c906108c
SS
4498kind of breakpoint or the call completes.
4499
7be570e7
JM
4500@value{GDBN} automatically deletes watchpoints that watch local
4501(automatic) variables, or expressions that involve such variables, when
4502they go out of scope, that is, when the execution leaves the block in
4503which these variables were defined. In particular, when the program
4504being debugged terminates, @emph{all} local variables go out of scope,
4505and so only watchpoints that watch global variables remain set. If you
4506rerun the program, you will need to set all such watchpoints again. One
4507way of doing that would be to set a code breakpoint at the entry to the
4508@code{main} function and when it breaks, set all the watchpoints.
4509
c906108c
SS
4510@cindex watchpoints and threads
4511@cindex threads and watchpoints
d983da9c
DJ
4512In multi-threaded programs, watchpoints will detect changes to the
4513watched expression from every thread.
4514
4515@quotation
4516@emph{Warning:} In multi-threaded programs, software watchpoints
53a5351d
JM
4517have only limited usefulness. If @value{GDBN} creates a software
4518watchpoint, it can only watch the value of an expression @emph{in a
4519single thread}. If you are confident that the expression can only
4520change due to the current thread's activity (and if you are also
4521confident that no other thread can become current), then you can use
4522software watchpoints as usual. However, @value{GDBN} may not notice
4523when a non-current thread's activity changes the expression. (Hardware
4524watchpoints, in contrast, watch an expression in all threads.)
c906108c 4525@end quotation
c906108c 4526
501eef12
AC
4527@xref{set remote hardware-watchpoint-limit}.
4528
6d2ebf8b 4529@node Set Catchpoints
79a6e687 4530@subsection Setting Catchpoints
d4f3574e 4531@cindex catchpoints, setting
c906108c
SS
4532@cindex exception handlers
4533@cindex event handling
4534
4535You can use @dfn{catchpoints} to cause the debugger to stop for certain
b37052ae 4536kinds of program events, such as C@t{++} exceptions or the loading of a
c906108c
SS
4537shared library. Use the @code{catch} command to set a catchpoint.
4538
4539@table @code
4540@kindex catch
4541@item catch @var{event}
697aa1b7 4542Stop when @var{event} occurs. The @var{event} can be any of the following:
591f19e8 4543
c906108c 4544@table @code
cc16e6c9
TT
4545@item throw @r{[}@var{regexp}@r{]}
4546@itemx rethrow @r{[}@var{regexp}@r{]}
4547@itemx catch @r{[}@var{regexp}@r{]}
1a4f73eb
TT
4548@kindex catch throw
4549@kindex catch rethrow
4550@kindex catch catch
4644b6e3 4551@cindex stop on C@t{++} exceptions
591f19e8
TT
4552The throwing, re-throwing, or catching of a C@t{++} exception.
4553
cc16e6c9
TT
4554If @var{regexp} is given, then only exceptions whose type matches the
4555regular expression will be caught.
4556
72f1fe8a
TT
4557@vindex $_exception@r{, convenience variable}
4558The convenience variable @code{$_exception} is available at an
4559exception-related catchpoint, on some systems. This holds the
4560exception being thrown.
4561
591f19e8
TT
4562There are currently some limitations to C@t{++} exception handling in
4563@value{GDBN}:
c906108c 4564
591f19e8
TT
4565@itemize @bullet
4566@item
4567The support for these commands is system-dependent. Currently, only
4568systems using the @samp{gnu-v3} C@t{++} ABI (@pxref{ABI}) are
4569supported.
4570
72f1fe8a 4571@item
cc16e6c9
TT
4572The regular expression feature and the @code{$_exception} convenience
4573variable rely on the presence of some SDT probes in @code{libstdc++}.
4574If these probes are not present, then these features cannot be used.
dee368d3
TT
4575These probes were first available in the GCC 4.8 release, but whether
4576or not they are available in your GCC also depends on how it was
4577built.
72f1fe8a
TT
4578
4579@item
4580The @code{$_exception} convenience variable is only valid at the
4581instruction at which an exception-related catchpoint is set.
4582
591f19e8
TT
4583@item
4584When an exception-related catchpoint is hit, @value{GDBN} stops at a
4585location in the system library which implements runtime exception
4586support for C@t{++}, usually @code{libstdc++}. You can use @code{up}
4587(@pxref{Selection}) to get to your code.
4588
4589@item
4590If you call a function interactively, @value{GDBN} normally returns
4591control to you when the function has finished executing. If the call
4592raises an exception, however, the call may bypass the mechanism that
4593returns control to you and cause your program either to abort or to
4594simply continue running until it hits a breakpoint, catches a signal
4595that @value{GDBN} is listening for, or exits. This is the case even if
4596you set a catchpoint for the exception; catchpoints on exceptions are
4597disabled within interactive calls. @xref{Calling}, for information on
4598controlling this with @code{set unwind-on-terminating-exception}.
4599
4600@item
4601You cannot raise an exception interactively.
4602
4603@item
4604You cannot install an exception handler interactively.
4605@end itemize
c906108c 4606
b8e07335 4607@item exception @r{[}@var{name}@r{]}
1a4f73eb 4608@kindex catch exception
8936fcda
JB
4609@cindex Ada exception catching
4610@cindex catch Ada exceptions
4611An Ada exception being raised. If an exception name is specified
4612at the end of the command (eg @code{catch exception Program_Error}),
4613the debugger will stop only when this specific exception is raised.
4614Otherwise, the debugger stops execution when any Ada exception is raised.
4615
87f67dba
JB
4616When inserting an exception catchpoint on a user-defined exception whose
4617name is identical to one of the exceptions defined by the language, the
4618fully qualified name must be used as the exception name. Otherwise,
4619@value{GDBN} will assume that it should stop on the pre-defined exception
4620rather than the user-defined one. For instance, assuming an exception
4621called @code{Constraint_Error} is defined in package @code{Pck}, then
4622the command to use to catch such exceptions is @kbd{catch exception
4623Pck.Constraint_Error}.
4624
b8e07335
TT
4625@item exception unhandled
4626@kindex catch exception unhandled
4627An exception that was raised but is not handled by the program.
4628
4629@item handlers @r{[}@var{name}@r{]}
9f757bf7
XR
4630@kindex catch handlers
4631@cindex Ada exception handlers catching
4632@cindex catch Ada exceptions when handled
4633An Ada exception being handled. If an exception name is
4634specified at the end of the command
4635 (eg @kbd{catch handlers Program_Error}), the debugger will stop
4636only when this specific exception is handled.
4637Otherwise, the debugger stops execution when any Ada exception is handled.
4638
4639When inserting a handlers catchpoint on a user-defined
4640exception whose name is identical to one of the exceptions
4641defined by the language, the fully qualified name must be used
4642as the exception name. Otherwise, @value{GDBN} will assume that it
4643should stop on the pre-defined exception rather than the
4644user-defined one. For instance, assuming an exception called
4645 @code{Constraint_Error} is defined in package @code{Pck}, then the
4646command to use to catch such exceptions handling is
4647@kbd{catch handlers Pck.Constraint_Error}.
4648
8936fcda 4649@item assert
1a4f73eb 4650@kindex catch assert
8936fcda
JB
4651A failed Ada assertion.
4652
c906108c 4653@item exec
1a4f73eb 4654@kindex catch exec
4644b6e3 4655@cindex break on fork/exec
b1236ac3 4656A call to @code{exec}.
c906108c 4657
e9076973 4658@anchor{catch syscall}
a96d9b2e 4659@item syscall
e3487908 4660@itemx syscall @r{[}@var{name} @r{|} @var{number} @r{|} @r{group:}@var{groupname} @r{|} @r{g:}@var{groupname}@r{]} @dots{}
1a4f73eb 4661@kindex catch syscall
a96d9b2e
SDJ
4662@cindex break on a system call.
4663A call to or return from a system call, a.k.a.@: @dfn{syscall}. A
4664syscall is a mechanism for application programs to request a service
4665from the operating system (OS) or one of the OS system services.
4666@value{GDBN} can catch some or all of the syscalls issued by the
4667debuggee, and show the related information for each syscall. If no
4668argument is specified, calls to and returns from all system calls
4669will be caught.
4670
4671@var{name} can be any system call name that is valid for the
4672underlying OS. Just what syscalls are valid depends on the OS. On
4673GNU and Unix systems, you can find the full list of valid syscall
4674names on @file{/usr/include/asm/unistd.h}.
4675
4676@c For MS-Windows, the syscall names and the corresponding numbers
4677@c can be found, e.g., on this URL:
4678@c http://www.metasploit.com/users/opcode/syscalls.html
4679@c but we don't support Windows syscalls yet.
4680
4681Normally, @value{GDBN} knows in advance which syscalls are valid for
4682each OS, so you can use the @value{GDBN} command-line completion
4683facilities (@pxref{Completion,, command completion}) to list the
4684available choices.
4685
4686You may also specify the system call numerically. A syscall's
4687number is the value passed to the OS's syscall dispatcher to
4688identify the requested service. When you specify the syscall by its
4689name, @value{GDBN} uses its database of syscalls to convert the name
4690into the corresponding numeric code, but using the number directly
4691may be useful if @value{GDBN}'s database does not have the complete
4692list of syscalls on your system (e.g., because @value{GDBN} lags
4693behind the OS upgrades).
4694
e3487908
GKB
4695You may specify a group of related syscalls to be caught at once using
4696the @code{group:} syntax (@code{g:} is a shorter equivalent). For
4697instance, on some platforms @value{GDBN} allows you to catch all
4698network related syscalls, by passing the argument @code{group:network}
4699to @code{catch syscall}. Note that not all syscall groups are
4700available in every system. You can use the command completion
4701facilities (@pxref{Completion,, command completion}) to list the
4702syscall groups available on your environment.
4703
a96d9b2e
SDJ
4704The example below illustrates how this command works if you don't provide
4705arguments to it:
4706
4707@smallexample
4708(@value{GDBP}) catch syscall
4709Catchpoint 1 (syscall)
4710(@value{GDBP}) r
4711Starting program: /tmp/catch-syscall
4712
4713Catchpoint 1 (call to syscall 'close'), \
4714 0xffffe424 in __kernel_vsyscall ()
4715(@value{GDBP}) c
4716Continuing.
4717
4718Catchpoint 1 (returned from syscall 'close'), \
4719 0xffffe424 in __kernel_vsyscall ()
4720(@value{GDBP})
4721@end smallexample
4722
4723Here is an example of catching a system call by name:
4724
4725@smallexample
4726(@value{GDBP}) catch syscall chroot
4727Catchpoint 1 (syscall 'chroot' [61])
4728(@value{GDBP}) r
4729Starting program: /tmp/catch-syscall
4730
4731Catchpoint 1 (call to syscall 'chroot'), \
4732 0xffffe424 in __kernel_vsyscall ()
4733(@value{GDBP}) c
4734Continuing.
4735
4736Catchpoint 1 (returned from syscall 'chroot'), \
4737 0xffffe424 in __kernel_vsyscall ()
4738(@value{GDBP})
4739@end smallexample
4740
4741An example of specifying a system call numerically. In the case
4742below, the syscall number has a corresponding entry in the XML
4743file, so @value{GDBN} finds its name and prints it:
4744
4745@smallexample
4746(@value{GDBP}) catch syscall 252
4747Catchpoint 1 (syscall(s) 'exit_group')
4748(@value{GDBP}) r
4749Starting program: /tmp/catch-syscall
4750
4751Catchpoint 1 (call to syscall 'exit_group'), \
4752 0xffffe424 in __kernel_vsyscall ()
4753(@value{GDBP}) c
4754Continuing.
4755
4756Program exited normally.
4757(@value{GDBP})
4758@end smallexample
4759
e3487908
GKB
4760Here is an example of catching a syscall group:
4761
4762@smallexample
4763(@value{GDBP}) catch syscall group:process
4764Catchpoint 1 (syscalls 'exit' [1] 'fork' [2] 'waitpid' [7]
4765'execve' [11] 'wait4' [114] 'clone' [120] 'vfork' [190]
4766'exit_group' [252] 'waitid' [284] 'unshare' [310])
4767(@value{GDBP}) r
4768Starting program: /tmp/catch-syscall
4769
4770Catchpoint 1 (call to syscall fork), 0x00007ffff7df4e27 in open64 ()
4771 from /lib64/ld-linux-x86-64.so.2
4772
4773(@value{GDBP}) c
4774Continuing.
4775@end smallexample
4776
a96d9b2e
SDJ
4777However, there can be situations when there is no corresponding name
4778in XML file for that syscall number. In this case, @value{GDBN} prints
4779a warning message saying that it was not able to find the syscall name,
4780but the catchpoint will be set anyway. See the example below:
4781
4782@smallexample
4783(@value{GDBP}) catch syscall 764
4784warning: The number '764' does not represent a known syscall.
4785Catchpoint 2 (syscall 764)
4786(@value{GDBP})
4787@end smallexample
4788
4789If you configure @value{GDBN} using the @samp{--without-expat} option,
4790it will not be able to display syscall names. Also, if your
4791architecture does not have an XML file describing its system calls,
4792you will not be able to see the syscall names. It is important to
4793notice that these two features are used for accessing the syscall
4794name database. In either case, you will see a warning like this:
4795
4796@smallexample
4797(@value{GDBP}) catch syscall
4798warning: Could not open "syscalls/i386-linux.xml"
4799warning: Could not load the syscall XML file 'syscalls/i386-linux.xml'.
4800GDB will not be able to display syscall names.
4801Catchpoint 1 (syscall)
4802(@value{GDBP})
4803@end smallexample
4804
4805Of course, the file name will change depending on your architecture and system.
4806
4807Still using the example above, you can also try to catch a syscall by its
4808number. In this case, you would see something like:
4809
4810@smallexample
4811(@value{GDBP}) catch syscall 252
4812Catchpoint 1 (syscall(s) 252)
4813@end smallexample
4814
4815Again, in this case @value{GDBN} would not be able to display syscall's names.
4816
c906108c 4817@item fork
1a4f73eb 4818@kindex catch fork
b1236ac3 4819A call to @code{fork}.
c906108c
SS
4820
4821@item vfork
1a4f73eb 4822@kindex catch vfork
b1236ac3 4823A call to @code{vfork}.
c906108c 4824
b8e07335
TT
4825@item load @r{[}@var{regexp}@r{]}
4826@itemx unload @r{[}@var{regexp}@r{]}
1a4f73eb
TT
4827@kindex catch load
4828@kindex catch unload
edcc5120
TT
4829The loading or unloading of a shared library. If @var{regexp} is
4830given, then the catchpoint will stop only if the regular expression
4831matches one of the affected libraries.
4832
ab04a2af 4833@item signal @r{[}@var{signal}@dots{} @r{|} @samp{all}@r{]}
1a4f73eb 4834@kindex catch signal
ab04a2af
TT
4835The delivery of a signal.
4836
4837With no arguments, this catchpoint will catch any signal that is not
4838used internally by @value{GDBN}, specifically, all signals except
4839@samp{SIGTRAP} and @samp{SIGINT}.
4840
4841With the argument @samp{all}, all signals, including those used by
4842@value{GDBN}, will be caught. This argument cannot be used with other
4843signal names.
4844
4845Otherwise, the arguments are a list of signal names as given to
4846@code{handle} (@pxref{Signals}). Only signals specified in this list
4847will be caught.
4848
4849One reason that @code{catch signal} can be more useful than
4850@code{handle} is that you can attach commands and conditions to the
4851catchpoint.
4852
4853When a signal is caught by a catchpoint, the signal's @code{stop} and
4854@code{print} settings, as specified by @code{handle}, are ignored.
4855However, whether the signal is still delivered to the inferior depends
4856on the @code{pass} setting; this can be changed in the catchpoint's
4857commands.
4858
c906108c
SS
4859@end table
4860
4861@item tcatch @var{event}
1a4f73eb 4862@kindex tcatch
c906108c
SS
4863Set a catchpoint that is enabled only for one stop. The catchpoint is
4864automatically deleted after the first time the event is caught.
4865
4866@end table
4867
4868Use the @code{info break} command to list the current catchpoints.
4869
c906108c 4870
6d2ebf8b 4871@node Delete Breaks
79a6e687 4872@subsection Deleting Breakpoints
c906108c
SS
4873
4874@cindex clearing breakpoints, watchpoints, catchpoints
4875@cindex deleting breakpoints, watchpoints, catchpoints
4876It is often necessary to eliminate a breakpoint, watchpoint, or
4877catchpoint once it has done its job and you no longer want your program
4878to stop there. This is called @dfn{deleting} the breakpoint. A
4879breakpoint that has been deleted no longer exists; it is forgotten.
4880
4881With the @code{clear} command you can delete breakpoints according to
4882where they are in your program. With the @code{delete} command you can
4883delete individual breakpoints, watchpoints, or catchpoints by specifying
4884their breakpoint numbers.
4885
4886It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
4887automatically ignores breakpoints on the first instruction to be executed
4888when you continue execution without changing the execution address.
4889
4890@table @code
4891@kindex clear
4892@item clear
4893Delete any breakpoints at the next instruction to be executed in the
79a6e687 4894selected stack frame (@pxref{Selection, ,Selecting a Frame}). When
c906108c
SS
4895the innermost frame is selected, this is a good way to delete a
4896breakpoint where your program just stopped.
4897
2a25a5ba
EZ
4898@item clear @var{location}
4899Delete any breakpoints set at the specified @var{location}.
4900@xref{Specify Location}, for the various forms of @var{location}; the
4901most useful ones are listed below:
4902
4903@table @code
c906108c
SS
4904@item clear @var{function}
4905@itemx clear @var{filename}:@var{function}
09d4efe1 4906Delete any breakpoints set at entry to the named @var{function}.
c906108c
SS
4907
4908@item clear @var{linenum}
4909@itemx clear @var{filename}:@var{linenum}
09d4efe1
EZ
4910Delete any breakpoints set at or within the code of the specified
4911@var{linenum} of the specified @var{filename}.
2a25a5ba 4912@end table
c906108c
SS
4913
4914@cindex delete breakpoints
4915@kindex delete
41afff9a 4916@kindex d @r{(@code{delete})}
18da0c51 4917@item delete @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
c5394b80 4918Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
18da0c51 4919list specified as argument. If no argument is specified, delete all
c906108c
SS
4920breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
4921confirm off}). You can abbreviate this command as @code{d}.
4922@end table
4923
6d2ebf8b 4924@node Disabling
79a6e687 4925@subsection Disabling Breakpoints
c906108c 4926
4644b6e3 4927@cindex enable/disable a breakpoint
c906108c
SS
4928Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
4929prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
4930it had been deleted, but remembers the information on the breakpoint so
4931that you can @dfn{enable} it again later.
4932
4933You disable and enable breakpoints, watchpoints, and catchpoints with
d77f58be
SS
4934the @code{enable} and @code{disable} commands, optionally specifying
4935one or more breakpoint numbers as arguments. Use @code{info break} to
4936print a list of all breakpoints, watchpoints, and catchpoints if you
4937do not know which numbers to use.
c906108c 4938
3b784c4f
EZ
4939Disabling and enabling a breakpoint that has multiple locations
4940affects all of its locations.
4941
816338b5
SS
4942A breakpoint, watchpoint, or catchpoint can have any of several
4943different states of enablement:
c906108c
SS
4944
4945@itemize @bullet
4946@item
4947Enabled. The breakpoint stops your program. A breakpoint set
4948with the @code{break} command starts out in this state.
4949@item
4950Disabled. The breakpoint has no effect on your program.
4951@item
4952Enabled once. The breakpoint stops your program, but then becomes
d4f3574e 4953disabled.
c906108c 4954@item
816338b5
SS
4955Enabled for a count. The breakpoint stops your program for the next
4956N times, then becomes disabled.
4957@item
c906108c 4958Enabled for deletion. The breakpoint stops your program, but
d4f3574e
SS
4959immediately after it does so it is deleted permanently. A breakpoint
4960set with the @code{tbreak} command starts out in this state.
c906108c
SS
4961@end itemize
4962
4963You can use the following commands to enable or disable breakpoints,
4964watchpoints, and catchpoints:
4965
4966@table @code
c906108c 4967@kindex disable
41afff9a 4968@kindex dis @r{(@code{disable})}
18da0c51 4969@item disable @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
c906108c
SS
4970Disable the specified breakpoints---or all breakpoints, if none are
4971listed. A disabled breakpoint has no effect but is not forgotten. All
4972options such as ignore-counts, conditions and commands are remembered in
4973case the breakpoint is enabled again later. You may abbreviate
4974@code{disable} as @code{dis}.
4975
c906108c 4976@kindex enable
18da0c51 4977@item enable @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
c906108c
SS
4978Enable the specified breakpoints (or all defined breakpoints). They
4979become effective once again in stopping your program.
4980
18da0c51 4981@item enable @r{[}breakpoints@r{]} once @var{list}@dots{}
c906108c
SS
4982Enable the specified breakpoints temporarily. @value{GDBN} disables any
4983of these breakpoints immediately after stopping your program.
4984
18da0c51 4985@item enable @r{[}breakpoints@r{]} count @var{count} @var{list}@dots{}
816338b5
SS
4986Enable the specified breakpoints temporarily. @value{GDBN} records
4987@var{count} with each of the specified breakpoints, and decrements a
4988breakpoint's count when it is hit. When any count reaches 0,
4989@value{GDBN} disables that breakpoint. If a breakpoint has an ignore
4990count (@pxref{Conditions, ,Break Conditions}), that will be
4991decremented to 0 before @var{count} is affected.
4992
18da0c51 4993@item enable @r{[}breakpoints@r{]} delete @var{list}@dots{}
c906108c
SS
4994Enable the specified breakpoints to work once, then die. @value{GDBN}
4995deletes any of these breakpoints as soon as your program stops there.
09d4efe1 4996Breakpoints set by the @code{tbreak} command start out in this state.
c906108c
SS
4997@end table
4998
d4f3574e
SS
4999@c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
5000@c confusing: tbreak is also initially enabled.
c906108c 5001Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
79a6e687 5002,Setting Breakpoints}), breakpoints that you set are initially enabled;
c906108c
SS
5003subsequently, they become disabled or enabled only when you use one of
5004the commands above. (The command @code{until} can set and delete a
5005breakpoint of its own, but it does not change the state of your other
5006breakpoints; see @ref{Continuing and Stepping, ,Continuing and
79a6e687 5007Stepping}.)
c906108c 5008
6d2ebf8b 5009@node Conditions
79a6e687 5010@subsection Break Conditions
c906108c
SS
5011@cindex conditional breakpoints
5012@cindex breakpoint conditions
5013
5014@c FIXME what is scope of break condition expr? Context where wanted?
5d161b24 5015@c in particular for a watchpoint?
c906108c
SS
5016The simplest sort of breakpoint breaks every time your program reaches a
5017specified place. You can also specify a @dfn{condition} for a
5018breakpoint. A condition is just a Boolean expression in your
5019programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
5020a condition evaluates the expression each time your program reaches it,
5021and your program stops only if the condition is @emph{true}.
5022
5023This is the converse of using assertions for program validation; in that
5024situation, you want to stop when the assertion is violated---that is,
5025when the condition is false. In C, if you want to test an assertion expressed
5026by the condition @var{assert}, you should set the condition
5027@samp{! @var{assert}} on the appropriate breakpoint.
5028
5029Conditions are also accepted for watchpoints; you may not need them,
5030since a watchpoint is inspecting the value of an expression anyhow---but
5031it might be simpler, say, to just set a watchpoint on a variable name,
5032and specify a condition that tests whether the new value is an interesting
5033one.
5034
5035Break conditions can have side effects, and may even call functions in
5036your program. This can be useful, for example, to activate functions
5037that log program progress, or to use your own print functions to
99e008fe 5038format special data structures. The effects are completely predictable
c906108c
SS
5039unless there is another enabled breakpoint at the same address. (In
5040that case, @value{GDBN} might see the other breakpoint first and stop your
5041program without checking the condition of this one.) Note that
d4f3574e
SS
5042breakpoint commands are usually more convenient and flexible than break
5043conditions for the
c906108c 5044purpose of performing side effects when a breakpoint is reached
79a6e687 5045(@pxref{Break Commands, ,Breakpoint Command Lists}).
c906108c 5046
83364271
LM
5047Breakpoint conditions can also be evaluated on the target's side if
5048the target supports it. Instead of evaluating the conditions locally,
5049@value{GDBN} encodes the expression into an agent expression
5050(@pxref{Agent Expressions}) suitable for execution on the target,
5051independently of @value{GDBN}. Global variables become raw memory
5052locations, locals become stack accesses, and so forth.
5053
5054In this case, @value{GDBN} will only be notified of a breakpoint trigger
5055when its condition evaluates to true. This mechanism may provide faster
5056response times depending on the performance characteristics of the target
5057since it does not need to keep @value{GDBN} informed about
5058every breakpoint trigger, even those with false conditions.
5059
c906108c
SS
5060Break conditions can be specified when a breakpoint is set, by using
5061@samp{if} in the arguments to the @code{break} command. @xref{Set
79a6e687 5062Breaks, ,Setting Breakpoints}. They can also be changed at any time
c906108c 5063with the @code{condition} command.
53a5351d 5064
c906108c
SS
5065You can also use the @code{if} keyword with the @code{watch} command.
5066The @code{catch} command does not recognize the @code{if} keyword;
5067@code{condition} is the only way to impose a further condition on a
5068catchpoint.
c906108c
SS
5069
5070@table @code
5071@kindex condition
5072@item condition @var{bnum} @var{expression}
5073Specify @var{expression} as the break condition for breakpoint,
5074watchpoint, or catchpoint number @var{bnum}. After you set a condition,
5075breakpoint @var{bnum} stops your program only if the value of
5076@var{expression} is true (nonzero, in C). When you use
5077@code{condition}, @value{GDBN} checks @var{expression} immediately for
5078syntactic correctness, and to determine whether symbols in it have
d4f3574e
SS
5079referents in the context of your breakpoint. If @var{expression} uses
5080symbols not referenced in the context of the breakpoint, @value{GDBN}
5081prints an error message:
5082
474c8240 5083@smallexample
d4f3574e 5084No symbol "foo" in current context.
474c8240 5085@end smallexample
d4f3574e
SS
5086
5087@noindent
c906108c
SS
5088@value{GDBN} does
5089not actually evaluate @var{expression} at the time the @code{condition}
d4f3574e
SS
5090command (or a command that sets a breakpoint with a condition, like
5091@code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
c906108c
SS
5092
5093@item condition @var{bnum}
5094Remove the condition from breakpoint number @var{bnum}. It becomes
5095an ordinary unconditional breakpoint.
5096@end table
5097
5098@cindex ignore count (of breakpoint)
5099A special case of a breakpoint condition is to stop only when the
5100breakpoint has been reached a certain number of times. This is so
5101useful that there is a special way to do it, using the @dfn{ignore
5102count} of the breakpoint. Every breakpoint has an ignore count, which
5103is an integer. Most of the time, the ignore count is zero, and
5104therefore has no effect. But if your program reaches a breakpoint whose
5105ignore count is positive, then instead of stopping, it just decrements
5106the ignore count by one and continues. As a result, if the ignore count
5107value is @var{n}, the breakpoint does not stop the next @var{n} times
5108your program reaches it.
5109
5110@table @code
5111@kindex ignore
5112@item ignore @var{bnum} @var{count}
5113Set the ignore count of breakpoint number @var{bnum} to @var{count}.
5114The next @var{count} times the breakpoint is reached, your program's
5115execution does not stop; other than to decrement the ignore count, @value{GDBN}
5116takes no action.
5117
5118To make the breakpoint stop the next time it is reached, specify
5119a count of zero.
5120
5121When you use @code{continue} to resume execution of your program from a
5122breakpoint, you can specify an ignore count directly as an argument to
5123@code{continue}, rather than using @code{ignore}. @xref{Continuing and
79a6e687 5124Stepping,,Continuing and Stepping}.
c906108c
SS
5125
5126If a breakpoint has a positive ignore count and a condition, the
5127condition is not checked. Once the ignore count reaches zero,
5128@value{GDBN} resumes checking the condition.
5129
5130You could achieve the effect of the ignore count with a condition such
5131as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
5132is decremented each time. @xref{Convenience Vars, ,Convenience
79a6e687 5133Variables}.
c906108c
SS
5134@end table
5135
5136Ignore counts apply to breakpoints, watchpoints, and catchpoints.
5137
5138
6d2ebf8b 5139@node Break Commands
79a6e687 5140@subsection Breakpoint Command Lists
c906108c
SS
5141
5142@cindex breakpoint commands
5143You can give any breakpoint (or watchpoint or catchpoint) a series of
5144commands to execute when your program stops due to that breakpoint. For
5145example, you might want to print the values of certain expressions, or
5146enable other breakpoints.
5147
5148@table @code
5149@kindex commands
ca91424e 5150@kindex end@r{ (breakpoint commands)}
18da0c51 5151@item commands @r{[}@var{list}@dots{}@r{]}
c906108c
SS
5152@itemx @dots{} @var{command-list} @dots{}
5153@itemx end
95a42b64 5154Specify a list of commands for the given breakpoints. The commands
c906108c
SS
5155themselves appear on the following lines. Type a line containing just
5156@code{end} to terminate the commands.
5157
5158To remove all commands from a breakpoint, type @code{commands} and
5159follow it immediately with @code{end}; that is, give no commands.
5160
95a42b64
TT
5161With no argument, @code{commands} refers to the last breakpoint,
5162watchpoint, or catchpoint set (not to the breakpoint most recently
5163encountered). If the most recent breakpoints were set with a single
5164command, then the @code{commands} will apply to all the breakpoints
5165set by that command. This applies to breakpoints set by
86b17b60
PA
5166@code{rbreak}, and also applies when a single @code{break} command
5167creates multiple breakpoints (@pxref{Ambiguous Expressions,,Ambiguous
5168Expressions}).
c906108c
SS
5169@end table
5170
5171Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
5172disabled within a @var{command-list}.
5173
5174You can use breakpoint commands to start your program up again. Simply
5175use the @code{continue} command, or @code{step}, or any other command
5176that resumes execution.
5177
5178Any other commands in the command list, after a command that resumes
5179execution, are ignored. This is because any time you resume execution
5180(even with a simple @code{next} or @code{step}), you may encounter
5181another breakpoint---which could have its own command list, leading to
5182ambiguities about which list to execute.
5183
5184@kindex silent
5185If the first command you specify in a command list is @code{silent}, the
5186usual message about stopping at a breakpoint is not printed. This may
5187be desirable for breakpoints that are to print a specific message and
5188then continue. If none of the remaining commands print anything, you
5189see no sign that the breakpoint was reached. @code{silent} is
5190meaningful only at the beginning of a breakpoint command list.
5191
5192The commands @code{echo}, @code{output}, and @code{printf} allow you to
5193print precisely controlled output, and are often useful in silent
79a6e687 5194breakpoints. @xref{Output, ,Commands for Controlled Output}.
c906108c
SS
5195
5196For example, here is how you could use breakpoint commands to print the
5197value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
5198
474c8240 5199@smallexample
c906108c
SS
5200break foo if x>0
5201commands
5202silent
5203printf "x is %d\n",x
5204cont
5205end
474c8240 5206@end smallexample
c906108c
SS
5207
5208One application for breakpoint commands is to compensate for one bug so
5209you can test for another. Put a breakpoint just after the erroneous line
5210of code, give it a condition to detect the case in which something
5211erroneous has been done, and give it commands to assign correct values
5212to any variables that need them. End with the @code{continue} command
5213so that your program does not stop, and start with the @code{silent}
5214command so that no output is produced. Here is an example:
5215
474c8240 5216@smallexample
c906108c
SS
5217break 403
5218commands
5219silent
5220set x = y + 4
5221cont
5222end
474c8240 5223@end smallexample
c906108c 5224
e7e0cddf
SS
5225@node Dynamic Printf
5226@subsection Dynamic Printf
5227
5228@cindex dynamic printf
5229@cindex dprintf
5230The dynamic printf command @code{dprintf} combines a breakpoint with
5231formatted printing of your program's data to give you the effect of
5232inserting @code{printf} calls into your program on-the-fly, without
5233having to recompile it.
5234
5235In its most basic form, the output goes to the GDB console. However,
5236you can set the variable @code{dprintf-style} for alternate handling.
5237For instance, you can ask to format the output by calling your
5238program's @code{printf} function. This has the advantage that the
5239characters go to the program's output device, so they can recorded in
5240redirects to files and so forth.
5241
d3ce09f5
SS
5242If you are doing remote debugging with a stub or agent, you can also
5243ask to have the printf handled by the remote agent. In addition to
5244ensuring that the output goes to the remote program's device along
5245with any other output the program might produce, you can also ask that
5246the dprintf remain active even after disconnecting from the remote
5247target. Using the stub/agent is also more efficient, as it can do
5248everything without needing to communicate with @value{GDBN}.
5249
e7e0cddf
SS
5250@table @code
5251@kindex dprintf
5252@item dprintf @var{location},@var{template},@var{expression}[,@var{expression}@dots{}]
5253Whenever execution reaches @var{location}, print the values of one or
5254more @var{expressions} under the control of the string @var{template}.
5255To print several values, separate them with commas.
5256
5257@item set dprintf-style @var{style}
5258Set the dprintf output to be handled in one of several different
5259styles enumerated below. A change of style affects all existing
5260dynamic printfs immediately. (If you need individual control over the
5261print commands, simply define normal breakpoints with
5262explicitly-supplied command lists.)
5263
18da0c51 5264@table @code
e7e0cddf
SS
5265@item gdb
5266@kindex dprintf-style gdb
5267Handle the output using the @value{GDBN} @code{printf} command.
5268
5269@item call
5270@kindex dprintf-style call
5271Handle the output by calling a function in your program (normally
5272@code{printf}).
5273
d3ce09f5
SS
5274@item agent
5275@kindex dprintf-style agent
5276Have the remote debugging agent (such as @code{gdbserver}) handle
5277the output itself. This style is only available for agents that
5278support running commands on the target.
18da0c51 5279@end table
d3ce09f5 5280
e7e0cddf
SS
5281@item set dprintf-function @var{function}
5282Set the function to call if the dprintf style is @code{call}. By
5283default its value is @code{printf}. You may set it to any expression.
5284that @value{GDBN} can evaluate to a function, as per the @code{call}
5285command.
5286
5287@item set dprintf-channel @var{channel}
5288Set a ``channel'' for dprintf. If set to a non-empty value,
5289@value{GDBN} will evaluate it as an expression and pass the result as
5290a first argument to the @code{dprintf-function}, in the manner of
5291@code{fprintf} and similar functions. Otherwise, the dprintf format
5292string will be the first argument, in the manner of @code{printf}.
5293
5294As an example, if you wanted @code{dprintf} output to go to a logfile
5295that is a standard I/O stream assigned to the variable @code{mylog},
5296you could do the following:
5297
5298@example
5299(gdb) set dprintf-style call
5300(gdb) set dprintf-function fprintf
5301(gdb) set dprintf-channel mylog
5302(gdb) dprintf 25,"at line 25, glob=%d\n",glob
5303Dprintf 1 at 0x123456: file main.c, line 25.
5304(gdb) info break
53051 dprintf keep y 0x00123456 in main at main.c:25
5306 call (void) fprintf (mylog,"at line 25, glob=%d\n",glob)
5307 continue
5308(gdb)
5309@end example
5310
5311Note that the @code{info break} displays the dynamic printf commands
5312as normal breakpoint commands; you can thus easily see the effect of
5313the variable settings.
5314
d3ce09f5
SS
5315@item set disconnected-dprintf on
5316@itemx set disconnected-dprintf off
5317@kindex set disconnected-dprintf
5318Choose whether @code{dprintf} commands should continue to run if
5319@value{GDBN} has disconnected from the target. This only applies
5320if the @code{dprintf-style} is @code{agent}.
5321
5322@item show disconnected-dprintf off
5323@kindex show disconnected-dprintf
5324Show the current choice for disconnected @code{dprintf}.
5325
e7e0cddf
SS
5326@end table
5327
5328@value{GDBN} does not check the validity of function and channel,
5329relying on you to supply values that are meaningful for the contexts
5330in which they are being used. For instance, the function and channel
5331may be the values of local variables, but if that is the case, then
5332all enabled dynamic prints must be at locations within the scope of
5333those locals. If evaluation fails, @value{GDBN} will report an error.
5334
6149aea9
PA
5335@node Save Breakpoints
5336@subsection How to save breakpoints to a file
5337
5338To save breakpoint definitions to a file use the @w{@code{save
5339breakpoints}} command.
5340
5341@table @code
5342@kindex save breakpoints
5343@cindex save breakpoints to a file for future sessions
5344@item save breakpoints [@var{filename}]
5345This command saves all current breakpoint definitions together with
5346their commands and ignore counts, into a file @file{@var{filename}}
5347suitable for use in a later debugging session. This includes all
5348types of breakpoints (breakpoints, watchpoints, catchpoints,
5349tracepoints). To read the saved breakpoint definitions, use the
5350@code{source} command (@pxref{Command Files}). Note that watchpoints
5351with expressions involving local variables may fail to be recreated
5352because it may not be possible to access the context where the
5353watchpoint is valid anymore. Because the saved breakpoint definitions
5354are simply a sequence of @value{GDBN} commands that recreate the
5355breakpoints, you can edit the file in your favorite editing program,
5356and remove the breakpoint definitions you're not interested in, or
5357that can no longer be recreated.
5358@end table
5359
62e5f89c
SDJ
5360@node Static Probe Points
5361@subsection Static Probe Points
5362
5363@cindex static probe point, SystemTap
3133f8c1 5364@cindex static probe point, DTrace
62e5f89c
SDJ
5365@value{GDBN} supports @dfn{SDT} probes in the code. @acronym{SDT} stands
5366for Statically Defined Tracing, and the probes are designed to have a tiny
3133f8c1
JM
5367runtime code and data footprint, and no dynamic relocations.
5368
5369Currently, the following types of probes are supported on
5370ELF-compatible systems:
5371
5372@itemize @bullet
62e5f89c 5373
3133f8c1
JM
5374@item @code{SystemTap} (@uref{http://sourceware.org/systemtap/})
5375@acronym{SDT} probes@footnote{See
62e5f89c 5376@uref{http://sourceware.org/systemtap/wiki/AddingUserSpaceProbingToApps}
3133f8c1
JM
5377for more information on how to add @code{SystemTap} @acronym{SDT}
5378probes in your applications.}. @code{SystemTap} probes are usable
5379from assembly, C and C@t{++} languages@footnote{See
5380@uref{http://sourceware.org/systemtap/wiki/UserSpaceProbeImplementation}
5381for a good reference on how the @acronym{SDT} probes are implemented.}.
5382
5383@item @code{DTrace} (@uref{http://oss.oracle.com/projects/DTrace})
5384@acronym{USDT} probes. @code{DTrace} probes are usable from C and
5385C@t{++} languages.
5386@end itemize
62e5f89c
SDJ
5387
5388@cindex semaphores on static probe points
3133f8c1
JM
5389Some @code{SystemTap} probes have an associated semaphore variable;
5390for instance, this happens automatically if you defined your probe
5391using a DTrace-style @file{.d} file. If your probe has a semaphore,
5392@value{GDBN} will automatically enable it when you specify a
5393breakpoint using the @samp{-probe-stap} notation. But, if you put a
5394breakpoint at a probe's location by some other method (e.g.,
5395@code{break file:line}), then @value{GDBN} will not automatically set
5396the semaphore. @code{DTrace} probes do not support semaphores.
62e5f89c
SDJ
5397
5398You can examine the available static static probes using @code{info
5399probes}, with optional arguments:
5400
5401@table @code
5402@kindex info probes
3133f8c1
JM
5403@item info probes @r{[}@var{type}@r{]} @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5404If given, @var{type} is either @code{stap} for listing
5405@code{SystemTap} probes or @code{dtrace} for listing @code{DTrace}
5406probes. If omitted all probes are listed regardless of their types.
5407
62e5f89c
SDJ
5408If given, @var{provider} is a regular expression used to match against provider
5409names when selecting which probes to list. If omitted, probes by all
5410probes from all providers are listed.
5411
5412If given, @var{name} is a regular expression to match against probe names
5413when selecting which probes to list. If omitted, probe names are not
5414considered when deciding whether to display them.
5415
5416If given, @var{objfile} is a regular expression used to select which
5417object files (executable or shared libraries) to examine. If not
5418given, all object files are considered.
5419
5420@item info probes all
5421List the available static probes, from all types.
5422@end table
5423
9aca2ff8
JM
5424@cindex enabling and disabling probes
5425Some probe points can be enabled and/or disabled. The effect of
5426enabling or disabling a probe depends on the type of probe being
3133f8c1
JM
5427handled. Some @code{DTrace} probes can be enabled or
5428disabled, but @code{SystemTap} probes cannot be disabled.
9aca2ff8
JM
5429
5430You can enable (or disable) one or more probes using the following
5431commands, with optional arguments:
5432
5433@table @code
5434@kindex enable probes
5435@item enable probes @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5436If given, @var{provider} is a regular expression used to match against
5437provider names when selecting which probes to enable. If omitted,
5438all probes from all providers are enabled.
5439
5440If given, @var{name} is a regular expression to match against probe
5441names when selecting which probes to enable. If omitted, probe names
5442are not considered when deciding whether to enable them.
5443
5444If given, @var{objfile} is a regular expression used to select which
5445object files (executable or shared libraries) to examine. If not
5446given, all object files are considered.
5447
5448@kindex disable probes
5449@item disable probes @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5450See the @code{enable probes} command above for a description of the
5451optional arguments accepted by this command.
5452@end table
5453
62e5f89c
SDJ
5454@vindex $_probe_arg@r{, convenience variable}
5455A probe may specify up to twelve arguments. These are available at the
5456point at which the probe is defined---that is, when the current PC is
5457at the probe's location. The arguments are available using the
5458convenience variables (@pxref{Convenience Vars})
3133f8c1
JM
5459@code{$_probe_arg0}@dots{}@code{$_probe_arg11}. In @code{SystemTap}
5460probes each probe argument is an integer of the appropriate size;
5461types are not preserved. In @code{DTrace} probes types are preserved
5462provided that they are recognized as such by @value{GDBN}; otherwise
5463the value of the probe argument will be a long integer. The
62e5f89c
SDJ
5464convenience variable @code{$_probe_argc} holds the number of arguments
5465at the current probe point.
5466
5467These variables are always available, but attempts to access them at
5468any location other than a probe point will cause @value{GDBN} to give
5469an error message.
5470
5471
c906108c 5472@c @ifclear BARETARGET
6d2ebf8b 5473@node Error in Breakpoints
d4f3574e 5474@subsection ``Cannot insert breakpoints''
c906108c 5475
fa3a767f
PA
5476If you request too many active hardware-assisted breakpoints and
5477watchpoints, you will see this error message:
d4f3574e
SS
5478
5479@c FIXME: the precise wording of this message may change; the relevant
5480@c source change is not committed yet (Sep 3, 1999).
5481@smallexample
5482Stopped; cannot insert breakpoints.
5483You may have requested too many hardware breakpoints and watchpoints.
5484@end smallexample
5485
5486@noindent
5487This message is printed when you attempt to resume the program, since
5488only then @value{GDBN} knows exactly how many hardware breakpoints and
5489watchpoints it needs to insert.
5490
5491When this message is printed, you need to disable or remove some of the
5492hardware-assisted breakpoints and watchpoints, and then continue.
5493
79a6e687 5494@node Breakpoint-related Warnings
1485d690
KB
5495@subsection ``Breakpoint address adjusted...''
5496@cindex breakpoint address adjusted
5497
5498Some processor architectures place constraints on the addresses at
5499which breakpoints may be placed. For architectures thus constrained,
5500@value{GDBN} will attempt to adjust the breakpoint's address to comply
5501with the constraints dictated by the architecture.
5502
5503One example of such an architecture is the Fujitsu FR-V. The FR-V is
5504a VLIW architecture in which a number of RISC-like instructions may be
5505bundled together for parallel execution. The FR-V architecture
5506constrains the location of a breakpoint instruction within such a
5507bundle to the instruction with the lowest address. @value{GDBN}
5508honors this constraint by adjusting a breakpoint's address to the
5509first in the bundle.
5510
5511It is not uncommon for optimized code to have bundles which contain
5512instructions from different source statements, thus it may happen that
5513a breakpoint's address will be adjusted from one source statement to
5514another. Since this adjustment may significantly alter @value{GDBN}'s
5515breakpoint related behavior from what the user expects, a warning is
5516printed when the breakpoint is first set and also when the breakpoint
5517is hit.
5518
5519A warning like the one below is printed when setting a breakpoint
5520that's been subject to address adjustment:
5521
5522@smallexample
5523warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
5524@end smallexample
5525
5526Such warnings are printed both for user settable and @value{GDBN}'s
5527internal breakpoints. If you see one of these warnings, you should
5528verify that a breakpoint set at the adjusted address will have the
5529desired affect. If not, the breakpoint in question may be removed and
b383017d 5530other breakpoints may be set which will have the desired behavior.
1485d690
KB
5531E.g., it may be sufficient to place the breakpoint at a later
5532instruction. A conditional breakpoint may also be useful in some
5533cases to prevent the breakpoint from triggering too often.
5534
5535@value{GDBN} will also issue a warning when stopping at one of these
5536adjusted breakpoints:
5537
5538@smallexample
5539warning: Breakpoint 1 address previously adjusted from 0x00010414
5540to 0x00010410.
5541@end smallexample
5542
5543When this warning is encountered, it may be too late to take remedial
5544action except in cases where the breakpoint is hit earlier or more
5545frequently than expected.
d4f3574e 5546
6d2ebf8b 5547@node Continuing and Stepping
79a6e687 5548@section Continuing and Stepping
c906108c
SS
5549
5550@cindex stepping
5551@cindex continuing
5552@cindex resuming execution
5553@dfn{Continuing} means resuming program execution until your program
5554completes normally. In contrast, @dfn{stepping} means executing just
5555one more ``step'' of your program, where ``step'' may mean either one
5556line of source code, or one machine instruction (depending on what
7a292a7a
SS
5557particular command you use). Either when continuing or when stepping,
5558your program may stop even sooner, due to a breakpoint or a signal. (If
d4f3574e 5559it stops due to a signal, you may want to use @code{handle}, or use
e5f8a7cc
PA
5560@samp{signal 0} to resume execution (@pxref{Signals, ,Signals}),
5561or you may step into the signal's handler (@pxref{stepping and signal
5562handlers}).)
c906108c
SS
5563
5564@table @code
5565@kindex continue
41afff9a
EZ
5566@kindex c @r{(@code{continue})}
5567@kindex fg @r{(resume foreground execution)}
c906108c
SS
5568@item continue @r{[}@var{ignore-count}@r{]}
5569@itemx c @r{[}@var{ignore-count}@r{]}
5570@itemx fg @r{[}@var{ignore-count}@r{]}
5571Resume program execution, at the address where your program last stopped;
5572any breakpoints set at that address are bypassed. The optional argument
5573@var{ignore-count} allows you to specify a further number of times to
5574ignore a breakpoint at this location; its effect is like that of
79a6e687 5575@code{ignore} (@pxref{Conditions, ,Break Conditions}).
c906108c
SS
5576
5577The argument @var{ignore-count} is meaningful only when your program
5578stopped due to a breakpoint. At other times, the argument to
5579@code{continue} is ignored.
5580
d4f3574e
SS
5581The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
5582debugged program is deemed to be the foreground program) are provided
5583purely for convenience, and have exactly the same behavior as
5584@code{continue}.
c906108c
SS
5585@end table
5586
5587To resume execution at a different place, you can use @code{return}
79a6e687 5588(@pxref{Returning, ,Returning from a Function}) to go back to the
c906108c 5589calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
79a6e687 5590Different Address}) to go to an arbitrary location in your program.
c906108c
SS
5591
5592A typical technique for using stepping is to set a breakpoint
79a6e687 5593(@pxref{Breakpoints, ,Breakpoints; Watchpoints; and Catchpoints}) at the
c906108c
SS
5594beginning of the function or the section of your program where a problem
5595is believed to lie, run your program until it stops at that breakpoint,
5596and then step through the suspect area, examining the variables that are
5597interesting, until you see the problem happen.
5598
5599@table @code
5600@kindex step
41afff9a 5601@kindex s @r{(@code{step})}
c906108c
SS
5602@item step
5603Continue running your program until control reaches a different source
5604line, then stop it and return control to @value{GDBN}. This command is
5605abbreviated @code{s}.
5606
5607@quotation
5608@c "without debugging information" is imprecise; actually "without line
5609@c numbers in the debugging information". (gcc -g1 has debugging info but
5610@c not line numbers). But it seems complex to try to make that
5611@c distinction here.
5612@emph{Warning:} If you use the @code{step} command while control is
5613within a function that was compiled without debugging information,
5614execution proceeds until control reaches a function that does have
5615debugging information. Likewise, it will not step into a function which
5616is compiled without debugging information. To step through functions
5617without debugging information, use the @code{stepi} command, described
5618below.
5619@end quotation
5620
4a92d011
EZ
5621The @code{step} command only stops at the first instruction of a source
5622line. This prevents the multiple stops that could otherwise occur in
5623@code{switch} statements, @code{for} loops, etc. @code{step} continues
5624to stop if a function that has debugging information is called within
5625the line. In other words, @code{step} @emph{steps inside} any functions
5626called within the line.
c906108c 5627
d4f3574e
SS
5628Also, the @code{step} command only enters a function if there is line
5629number information for the function. Otherwise it acts like the
5d161b24 5630@code{next} command. This avoids problems when using @code{cc -gl}
eb17f351 5631on @acronym{MIPS} machines. Previously, @code{step} entered subroutines if there
5d161b24 5632was any debugging information about the routine.
c906108c
SS
5633
5634@item step @var{count}
5635Continue running as in @code{step}, but do so @var{count} times. If a
7a292a7a
SS
5636breakpoint is reached, or a signal not related to stepping occurs before
5637@var{count} steps, stepping stops right away.
c906108c
SS
5638
5639@kindex next
41afff9a 5640@kindex n @r{(@code{next})}
c906108c
SS
5641@item next @r{[}@var{count}@r{]}
5642Continue to the next source line in the current (innermost) stack frame.
7a292a7a
SS
5643This is similar to @code{step}, but function calls that appear within
5644the line of code are executed without stopping. Execution stops when
5645control reaches a different line of code at the original stack level
5646that was executing when you gave the @code{next} command. This command
5647is abbreviated @code{n}.
c906108c
SS
5648
5649An argument @var{count} is a repeat count, as for @code{step}.
5650
5651
5652@c FIX ME!! Do we delete this, or is there a way it fits in with
5653@c the following paragraph? --- Vctoria
5654@c
5655@c @code{next} within a function that lacks debugging information acts like
5656@c @code{step}, but any function calls appearing within the code of the
5657@c function are executed without stopping.
5658
d4f3574e
SS
5659The @code{next} command only stops at the first instruction of a
5660source line. This prevents multiple stops that could otherwise occur in
4a92d011 5661@code{switch} statements, @code{for} loops, etc.
c906108c 5662
b90a5f51
CF
5663@kindex set step-mode
5664@item set step-mode
5665@cindex functions without line info, and stepping
5666@cindex stepping into functions with no line info
5667@itemx set step-mode on
4a92d011 5668The @code{set step-mode on} command causes the @code{step} command to
b90a5f51
CF
5669stop at the first instruction of a function which contains no debug line
5670information rather than stepping over it.
5671
4a92d011
EZ
5672This is useful in cases where you may be interested in inspecting the
5673machine instructions of a function which has no symbolic info and do not
5674want @value{GDBN} to automatically skip over this function.
b90a5f51
CF
5675
5676@item set step-mode off
4a92d011 5677Causes the @code{step} command to step over any functions which contains no
b90a5f51
CF
5678debug information. This is the default.
5679
9c16f35a
EZ
5680@item show step-mode
5681Show whether @value{GDBN} will stop in or step over functions without
5682source line debug information.
5683
c906108c 5684@kindex finish
8dfa32fc 5685@kindex fin @r{(@code{finish})}
c906108c
SS
5686@item finish
5687Continue running until just after function in the selected stack frame
8dfa32fc
JB
5688returns. Print the returned value (if any). This command can be
5689abbreviated as @code{fin}.
c906108c
SS
5690
5691Contrast this with the @code{return} command (@pxref{Returning,
79a6e687 5692,Returning from a Function}).
c906108c 5693
000439d5
TT
5694@kindex set print finish
5695@kindex show print finish
5696@item set print finish @r{[}on|off@r{]}
5697@itemx show print finish
5698By default the @code{finish} command will show the value that is
5699returned by the function. This can be disabled using @code{set print
5700finish off}. When disabled, the value is still entered into the value
5701history (@pxref{Value History}), but not displayed.
5702
c906108c 5703@kindex until
41afff9a 5704@kindex u @r{(@code{until})}
09d4efe1 5705@cindex run until specified location
c906108c
SS
5706@item until
5707@itemx u
5708Continue running until a source line past the current line, in the
5709current stack frame, is reached. This command is used to avoid single
5710stepping through a loop more than once. It is like the @code{next}
5711command, except that when @code{until} encounters a jump, it
5712automatically continues execution until the program counter is greater
5713than the address of the jump.
5714
5715This means that when you reach the end of a loop after single stepping
5716though it, @code{until} makes your program continue execution until it
5717exits the loop. In contrast, a @code{next} command at the end of a loop
5718simply steps back to the beginning of the loop, which forces you to step
5719through the next iteration.
5720
5721@code{until} always stops your program if it attempts to exit the current
5722stack frame.
5723
5724@code{until} may produce somewhat counterintuitive results if the order
5725of machine code does not match the order of the source lines. For
5726example, in the following excerpt from a debugging session, the @code{f}
5727(@code{frame}) command shows that execution is stopped at line
5728@code{206}; yet when we use @code{until}, we get to line @code{195}:
5729
474c8240 5730@smallexample
c906108c
SS
5731(@value{GDBP}) f
5732#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
5733206 expand_input();
5734(@value{GDBP}) until
5735195 for ( ; argc > 0; NEXTARG) @{
474c8240 5736@end smallexample
c906108c
SS
5737
5738This happened because, for execution efficiency, the compiler had
5739generated code for the loop closure test at the end, rather than the
5740start, of the loop---even though the test in a C @code{for}-loop is
5741written before the body of the loop. The @code{until} command appeared
5742to step back to the beginning of the loop when it advanced to this
5743expression; however, it has not really gone to an earlier
5744statement---not in terms of the actual machine code.
5745
5746@code{until} with no argument works by means of single
5747instruction stepping, and hence is slower than @code{until} with an
5748argument.
5749
5750@item until @var{location}
5751@itemx u @var{location}
697aa1b7
EZ
5752Continue running your program until either the specified @var{location} is
5753reached, or the current stack frame returns. The location is any of
2a25a5ba
EZ
5754the forms described in @ref{Specify Location}.
5755This form of the command uses temporary breakpoints, and
c60eb6f1
EZ
5756hence is quicker than @code{until} without an argument. The specified
5757location is actually reached only if it is in the current frame. This
5758implies that @code{until} can be used to skip over recursive function
5759invocations. For instance in the code below, if the current location is
5760line @code{96}, issuing @code{until 99} will execute the program up to
db2e3e2e 5761line @code{99} in the same invocation of factorial, i.e., after the inner
c60eb6f1
EZ
5762invocations have returned.
5763
5764@smallexample
576594 int factorial (int value)
576695 @{
576796 if (value > 1) @{
576897 value *= factorial (value - 1);
576998 @}
577099 return (value);
5771100 @}
5772@end smallexample
5773
5774
5775@kindex advance @var{location}
984359d2 5776@item advance @var{location}
09d4efe1 5777Continue running the program up to the given @var{location}. An argument is
2a25a5ba
EZ
5778required, which should be of one of the forms described in
5779@ref{Specify Location}.
5780Execution will also stop upon exit from the current stack
c60eb6f1
EZ
5781frame. This command is similar to @code{until}, but @code{advance} will
5782not skip over recursive function calls, and the target location doesn't
5783have to be in the same frame as the current one.
5784
c906108c
SS
5785
5786@kindex stepi
41afff9a 5787@kindex si @r{(@code{stepi})}
c906108c 5788@item stepi
96a2c332 5789@itemx stepi @var{arg}
c906108c
SS
5790@itemx si
5791Execute one machine instruction, then stop and return to the debugger.
5792
5793It is often useful to do @samp{display/i $pc} when stepping by machine
5794instructions. This makes @value{GDBN} automatically display the next
5795instruction to be executed, each time your program stops. @xref{Auto
79a6e687 5796Display,, Automatic Display}.
c906108c
SS
5797
5798An argument is a repeat count, as in @code{step}.
5799
5800@need 750
5801@kindex nexti
41afff9a 5802@kindex ni @r{(@code{nexti})}
c906108c 5803@item nexti
96a2c332 5804@itemx nexti @var{arg}
c906108c
SS
5805@itemx ni
5806Execute one machine instruction, but if it is a function call,
5807proceed until the function returns.
5808
5809An argument is a repeat count, as in @code{next}.
c1e36e3e
PA
5810
5811@end table
5812
5813@anchor{range stepping}
5814@cindex range stepping
5815@cindex target-assisted range stepping
5816By default, and if available, @value{GDBN} makes use of
5817target-assisted @dfn{range stepping}. In other words, whenever you
5818use a stepping command (e.g., @code{step}, @code{next}), @value{GDBN}
5819tells the target to step the corresponding range of instruction
5820addresses instead of issuing multiple single-steps. This speeds up
5821line stepping, particularly for remote targets. Ideally, there should
5822be no reason you would want to turn range stepping off. However, it's
5823possible that a bug in the debug info, a bug in the remote stub (for
5824remote targets), or even a bug in @value{GDBN} could make line
5825stepping behave incorrectly when target-assisted range stepping is
5826enabled. You can use the following command to turn off range stepping
5827if necessary:
5828
5829@table @code
5830@kindex set range-stepping
5831@kindex show range-stepping
5832@item set range-stepping
5833@itemx show range-stepping
5834Control whether range stepping is enabled.
5835
5836If @code{on}, and the target supports it, @value{GDBN} tells the
5837target to step a range of addresses itself, instead of issuing
5838multiple single-steps. If @code{off}, @value{GDBN} always issues
5839single-steps, even if range stepping is supported by the target. The
5840default is @code{on}.
5841
c906108c
SS
5842@end table
5843
aad1c02c
TT
5844@node Skipping Over Functions and Files
5845@section Skipping Over Functions and Files
1bfeeb0f
JL
5846@cindex skipping over functions and files
5847
5848The program you are debugging may contain some functions which are
8244c20d 5849uninteresting to debug. The @code{skip} command lets you tell @value{GDBN} to
cce0e923
DE
5850skip a function, all functions in a file or a particular function in
5851a particular file when stepping.
1bfeeb0f
JL
5852
5853For example, consider the following C function:
5854
5855@smallexample
5856101 int func()
5857102 @{
5858103 foo(boring());
5859104 bar(boring());
5860105 @}
5861@end smallexample
5862
5863@noindent
5864Suppose you wish to step into the functions @code{foo} and @code{bar}, but you
5865are not interested in stepping through @code{boring}. If you run @code{step}
5866at line 103, you'll enter @code{boring()}, but if you run @code{next}, you'll
5867step over both @code{foo} and @code{boring}!
5868
5869One solution is to @code{step} into @code{boring} and use the @code{finish}
5870command to immediately exit it. But this can become tedious if @code{boring}
5871is called from many places.
5872
5873A more flexible solution is to execute @kbd{skip boring}. This instructs
5874@value{GDBN} never to step into @code{boring}. Now when you execute
5875@code{step} at line 103, you'll step over @code{boring} and directly into
5876@code{foo}.
5877
cce0e923
DE
5878Functions may be skipped by providing either a function name, linespec
5879(@pxref{Specify Location}), regular expression that matches the function's
5880name, file name or a @code{glob}-style pattern that matches the file name.
5881
5882On Posix systems the form of the regular expression is
5883``Extended Regular Expressions''. See for example @samp{man 7 regex}
5884on @sc{gnu}/Linux systems. On non-Posix systems the form of the regular
5885expression is whatever is provided by the @code{regcomp} function of
5886the underlying system.
5887See for example @samp{man 7 glob} on @sc{gnu}/Linux systems for a
5888description of @code{glob}-style patterns.
5889
5890@table @code
5891@kindex skip
5892@item skip @r{[}@var{options}@r{]}
5893The basic form of the @code{skip} command takes zero or more options
5894that specify what to skip.
5895The @var{options} argument is any useful combination of the following:
1bfeeb0f
JL
5896
5897@table @code
cce0e923
DE
5898@item -file @var{file}
5899@itemx -fi @var{file}
5900Functions in @var{file} will be skipped over when stepping.
5901
5902@item -gfile @var{file-glob-pattern}
5903@itemx -gfi @var{file-glob-pattern}
5904@cindex skipping over files via glob-style patterns
5905Functions in files matching @var{file-glob-pattern} will be skipped
5906over when stepping.
5907
5908@smallexample
5909(gdb) skip -gfi utils/*.c
5910@end smallexample
5911
5912@item -function @var{linespec}
5913@itemx -fu @var{linespec}
5914Functions named by @var{linespec} or the function containing the line
5915named by @var{linespec} will be skipped over when stepping.
5916@xref{Specify Location}.
5917
5918@item -rfunction @var{regexp}
5919@itemx -rfu @var{regexp}
5920@cindex skipping over functions via regular expressions
5921Functions whose name matches @var{regexp} will be skipped over when stepping.
5922
5923This form is useful for complex function names.
5924For example, there is generally no need to step into C@t{++} @code{std::string}
5925constructors or destructors. Plus with C@t{++} templates it can be hard to
5926write out the full name of the function, and often it doesn't matter what
5927the template arguments are. Specifying the function to be skipped as a
5928regular expression makes this easier.
5929
5930@smallexample
5931(gdb) skip -rfu ^std::(allocator|basic_string)<.*>::~?\1 *\(
5932@end smallexample
5933
5934If you want to skip every templated C@t{++} constructor and destructor
5935in the @code{std} namespace you can do:
5936
5937@smallexample
5938(gdb) skip -rfu ^std::([a-zA-z0-9_]+)<.*>::~?\1 *\(
5939@end smallexample
5940@end table
5941
5942If no options are specified, the function you're currently debugging
5943will be skipped.
5944
1bfeeb0f 5945@kindex skip function
cce0e923 5946@item skip function @r{[}@var{linespec}@r{]}
1bfeeb0f
JL
5947After running this command, the function named by @var{linespec} or the
5948function containing the line named by @var{linespec} will be skipped over when
983fb131 5949stepping. @xref{Specify Location}.
1bfeeb0f
JL
5950
5951If you do not specify @var{linespec}, the function you're currently debugging
5952will be skipped.
5953
5954(If you have a function called @code{file} that you want to skip, use
5955@kbd{skip function file}.)
5956
5957@kindex skip file
5958@item skip file @r{[}@var{filename}@r{]}
5959After running this command, any function whose source lives in @var{filename}
5960will be skipped over when stepping.
5961
cce0e923
DE
5962@smallexample
5963(gdb) skip file boring.c
5964File boring.c will be skipped when stepping.
5965@end smallexample
5966
1bfeeb0f
JL
5967If you do not specify @var{filename}, functions whose source lives in the file
5968you're currently debugging will be skipped.
5969@end table
5970
5971Skips can be listed, deleted, disabled, and enabled, much like breakpoints.
5972These are the commands for managing your list of skips:
5973
5974@table @code
5975@kindex info skip
5976@item info skip @r{[}@var{range}@r{]}
5977Print details about the specified skip(s). If @var{range} is not specified,
5978print a table with details about all functions and files marked for skipping.
5979@code{info skip} prints the following information about each skip:
5980
5981@table @emph
5982@item Identifier
5983A number identifying this skip.
1bfeeb0f 5984@item Enabled or Disabled
cce0e923
DE
5985Enabled skips are marked with @samp{y}.
5986Disabled skips are marked with @samp{n}.
5987@item Glob
5988If the file name is a @samp{glob} pattern this is @samp{y}.
5989Otherwise it is @samp{n}.
5990@item File
5991The name or @samp{glob} pattern of the file to be skipped.
5992If no file is specified this is @samp{<none>}.
5993@item RE
5994If the function name is a @samp{regular expression} this is @samp{y}.
5995Otherwise it is @samp{n}.
5996@item Function
5997The name or regular expression of the function to skip.
5998If no function is specified this is @samp{<none>}.
1bfeeb0f
JL
5999@end table
6000
6001@kindex skip delete
6002@item skip delete @r{[}@var{range}@r{]}
6003Delete the specified skip(s). If @var{range} is not specified, delete all
6004skips.
6005
6006@kindex skip enable
6007@item skip enable @r{[}@var{range}@r{]}
6008Enable the specified skip(s). If @var{range} is not specified, enable all
6009skips.
6010
6011@kindex skip disable
6012@item skip disable @r{[}@var{range}@r{]}
6013Disable the specified skip(s). If @var{range} is not specified, disable all
6014skips.
6015
3e68067f
SM
6016@kindex set debug skip
6017@item set debug skip @r{[}on|off@r{]}
6018Set whether to print the debug output about skipping files and functions.
6019
6020@kindex show debug skip
6021@item show debug skip
6022Show whether the debug output about skipping files and functions is printed.
6023
1bfeeb0f
JL
6024@end table
6025
6d2ebf8b 6026@node Signals
c906108c
SS
6027@section Signals
6028@cindex signals
6029
6030A signal is an asynchronous event that can happen in a program. The
6031operating system defines the possible kinds of signals, and gives each
6032kind a name and a number. For example, in Unix @code{SIGINT} is the
c8aa23ab 6033signal a program gets when you type an interrupt character (often @kbd{Ctrl-c});
c906108c
SS
6034@code{SIGSEGV} is the signal a program gets from referencing a place in
6035memory far away from all the areas in use; @code{SIGALRM} occurs when
6036the alarm clock timer goes off (which happens only if your program has
6037requested an alarm).
6038
6039@cindex fatal signals
6040Some signals, including @code{SIGALRM}, are a normal part of the
6041functioning of your program. Others, such as @code{SIGSEGV}, indicate
d4f3574e 6042errors; these signals are @dfn{fatal} (they kill your program immediately) if the
c906108c
SS
6043program has not specified in advance some other way to handle the signal.
6044@code{SIGINT} does not indicate an error in your program, but it is normally
6045fatal so it can carry out the purpose of the interrupt: to kill the program.
6046
6047@value{GDBN} has the ability to detect any occurrence of a signal in your
6048program. You can tell @value{GDBN} in advance what to do for each kind of
6049signal.
6050
6051@cindex handling signals
24f93129
EZ
6052Normally, @value{GDBN} is set up to let the non-erroneous signals like
6053@code{SIGALRM} be silently passed to your program
6054(so as not to interfere with their role in the program's functioning)
c906108c
SS
6055but to stop your program immediately whenever an error signal happens.
6056You can change these settings with the @code{handle} command.
6057
6058@table @code
6059@kindex info signals
09d4efe1 6060@kindex info handle
c906108c 6061@item info signals
96a2c332 6062@itemx info handle
c906108c
SS
6063Print a table of all the kinds of signals and how @value{GDBN} has been told to
6064handle each one. You can use this to see the signal numbers of all
6065the defined types of signals.
6066
45ac1734
EZ
6067@item info signals @var{sig}
6068Similar, but print information only about the specified signal number.
6069
d4f3574e 6070@code{info handle} is an alias for @code{info signals}.
c906108c 6071
ab04a2af
TT
6072@item catch signal @r{[}@var{signal}@dots{} @r{|} @samp{all}@r{]}
6073Set a catchpoint for the indicated signals. @xref{Set Catchpoints},
6074for details about this command.
6075
c906108c 6076@kindex handle
45ac1734 6077@item handle @var{signal} @r{[}@var{keywords}@dots{}@r{]}
697aa1b7 6078Change the way @value{GDBN} handles signal @var{signal}. The @var{signal}
5ece1a18 6079can be the number of a signal or its name (with or without the
24f93129 6080@samp{SIG} at the beginning); a list of signal numbers of the form
5ece1a18 6081@samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
45ac1734
EZ
6082known signals. Optional arguments @var{keywords}, described below,
6083say what change to make.
c906108c
SS
6084@end table
6085
6086@c @group
6087The keywords allowed by the @code{handle} command can be abbreviated.
6088Their full names are:
6089
6090@table @code
6091@item nostop
6092@value{GDBN} should not stop your program when this signal happens. It may
6093still print a message telling you that the signal has come in.
6094
6095@item stop
6096@value{GDBN} should stop your program when this signal happens. This implies
6097the @code{print} keyword as well.
6098
6099@item print
6100@value{GDBN} should print a message when this signal happens.
6101
6102@item noprint
6103@value{GDBN} should not mention the occurrence of the signal at all. This
6104implies the @code{nostop} keyword as well.
6105
6106@item pass
5ece1a18 6107@itemx noignore
c906108c
SS
6108@value{GDBN} should allow your program to see this signal; your program
6109can handle the signal, or else it may terminate if the signal is fatal
5ece1a18 6110and not handled. @code{pass} and @code{noignore} are synonyms.
c906108c
SS
6111
6112@item nopass
5ece1a18 6113@itemx ignore
c906108c 6114@value{GDBN} should not allow your program to see this signal.
5ece1a18 6115@code{nopass} and @code{ignore} are synonyms.
c906108c
SS
6116@end table
6117@c @end group
6118
d4f3574e
SS
6119When a signal stops your program, the signal is not visible to the
6120program until you
c906108c
SS
6121continue. Your program sees the signal then, if @code{pass} is in
6122effect for the signal in question @emph{at that time}. In other words,
6123after @value{GDBN} reports a signal, you can use the @code{handle}
6124command with @code{pass} or @code{nopass} to control whether your
6125program sees that signal when you continue.
6126
24f93129
EZ
6127The default is set to @code{nostop}, @code{noprint}, @code{pass} for
6128non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
6129@code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
6130erroneous signals.
6131
c906108c
SS
6132You can also use the @code{signal} command to prevent your program from
6133seeing a signal, or cause it to see a signal it normally would not see,
6134or to give it any signal at any time. For example, if your program stopped
6135due to some sort of memory reference error, you might store correct
6136values into the erroneous variables and continue, hoping to see more
6137execution; but your program would probably terminate immediately as
6138a result of the fatal signal once it saw the signal. To prevent this,
6139you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
79a6e687 6140Program a Signal}.
c906108c 6141
e5f8a7cc
PA
6142@cindex stepping and signal handlers
6143@anchor{stepping and signal handlers}
6144
6145@value{GDBN} optimizes for stepping the mainline code. If a signal
6146that has @code{handle nostop} and @code{handle pass} set arrives while
6147a stepping command (e.g., @code{stepi}, @code{step}, @code{next}) is
6148in progress, @value{GDBN} lets the signal handler run and then resumes
6149stepping the mainline code once the signal handler returns. In other
6150words, @value{GDBN} steps over the signal handler. This prevents
6151signals that you've specified as not interesting (with @code{handle
6152nostop}) from changing the focus of debugging unexpectedly. Note that
6153the signal handler itself may still hit a breakpoint, stop for another
6154signal that has @code{handle stop} in effect, or for any other event
6155that normally results in stopping the stepping command sooner. Also
6156note that @value{GDBN} still informs you that the program received a
6157signal if @code{handle print} is set.
6158
6159@anchor{stepping into signal handlers}
6160
6161If you set @code{handle pass} for a signal, and your program sets up a
6162handler for it, then issuing a stepping command, such as @code{step}
6163or @code{stepi}, when your program is stopped due to the signal will
6164step @emph{into} the signal handler (if the target supports that).
6165
6166Likewise, if you use the @code{queue-signal} command to queue a signal
6167to be delivered to the current thread when execution of the thread
6168resumes (@pxref{Signaling, ,Giving your Program a Signal}), then a
6169stepping command will step into the signal handler.
6170
6171Here's an example, using @code{stepi} to step to the first instruction
6172of @code{SIGUSR1}'s handler:
6173
6174@smallexample
6175(@value{GDBP}) handle SIGUSR1
6176Signal Stop Print Pass to program Description
6177SIGUSR1 Yes Yes Yes User defined signal 1
6178(@value{GDBP}) c
6179Continuing.
6180
6181Program received signal SIGUSR1, User defined signal 1.
6182main () sigusr1.c:28
618328 p = 0;
6184(@value{GDBP}) si
6185sigusr1_handler () at sigusr1.c:9
61869 @{
6187@end smallexample
6188
6189The same, but using @code{queue-signal} instead of waiting for the
6190program to receive the signal first:
6191
6192@smallexample
6193(@value{GDBP}) n
619428 p = 0;
6195(@value{GDBP}) queue-signal SIGUSR1
6196(@value{GDBP}) si
6197sigusr1_handler () at sigusr1.c:9
61989 @{
6199(@value{GDBP})
6200@end smallexample
6201
4aa995e1
PA
6202@cindex extra signal information
6203@anchor{extra signal information}
6204
6205On some targets, @value{GDBN} can inspect extra signal information
6206associated with the intercepted signal, before it is actually
6207delivered to the program being debugged. This information is exported
6208by the convenience variable @code{$_siginfo}, and consists of data
6209that is passed by the kernel to the signal handler at the time of the
6210receipt of a signal. The data type of the information itself is
6211target dependent. You can see the data type using the @code{ptype
6212$_siginfo} command. On Unix systems, it typically corresponds to the
6213standard @code{siginfo_t} type, as defined in the @file{signal.h}
6214system header.
6215
6216Here's an example, on a @sc{gnu}/Linux system, printing the stray
6217referenced address that raised a segmentation fault.
6218
6219@smallexample
6220@group
6221(@value{GDBP}) continue
6222Program received signal SIGSEGV, Segmentation fault.
62230x0000000000400766 in main ()
622469 *(int *)p = 0;
6225(@value{GDBP}) ptype $_siginfo
6226type = struct @{
6227 int si_signo;
6228 int si_errno;
6229 int si_code;
6230 union @{
6231 int _pad[28];
6232 struct @{...@} _kill;
6233 struct @{...@} _timer;
6234 struct @{...@} _rt;
6235 struct @{...@} _sigchld;
6236 struct @{...@} _sigfault;
6237 struct @{...@} _sigpoll;
6238 @} _sifields;
6239@}
6240(@value{GDBP}) ptype $_siginfo._sifields._sigfault
6241type = struct @{
6242 void *si_addr;
6243@}
6244(@value{GDBP}) p $_siginfo._sifields._sigfault.si_addr
6245$1 = (void *) 0x7ffff7ff7000
6246@end group
6247@end smallexample
6248
6249Depending on target support, @code{$_siginfo} may also be writable.
6250
012b3a21
WT
6251@cindex Intel MPX boundary violations
6252@cindex boundary violations, Intel MPX
6253On some targets, a @code{SIGSEGV} can be caused by a boundary
6254violation, i.e., accessing an address outside of the allowed range.
6255In those cases @value{GDBN} may displays additional information,
6256depending on how @value{GDBN} has been told to handle the signal.
6257With @code{handle stop SIGSEGV}, @value{GDBN} displays the violation
6258kind: "Upper" or "Lower", the memory address accessed and the
6259bounds, while with @code{handle nostop SIGSEGV} no additional
6260information is displayed.
6261
6262The usual output of a segfault is:
6263@smallexample
6264Program received signal SIGSEGV, Segmentation fault
62650x0000000000400d7c in upper () at i386-mpx-sigsegv.c:68
626668 value = *(p + len);
6267@end smallexample
6268
6269While a bound violation is presented as:
6270@smallexample
6271Program received signal SIGSEGV, Segmentation fault
6272Upper bound violation while accessing address 0x7fffffffc3b3
6273Bounds: [lower = 0x7fffffffc390, upper = 0x7fffffffc3a3]
62740x0000000000400d7c in upper () at i386-mpx-sigsegv.c:68
627568 value = *(p + len);
6276@end smallexample
6277
6d2ebf8b 6278@node Thread Stops
79a6e687 6279@section Stopping and Starting Multi-thread Programs
c906108c 6280
0606b73b
SL
6281@cindex stopped threads
6282@cindex threads, stopped
6283
6284@cindex continuing threads
6285@cindex threads, continuing
6286
6287@value{GDBN} supports debugging programs with multiple threads
6288(@pxref{Threads,, Debugging Programs with Multiple Threads}). There
6289are two modes of controlling execution of your program within the
6290debugger. In the default mode, referred to as @dfn{all-stop mode},
6291when any thread in your program stops (for example, at a breakpoint
6292or while being stepped), all other threads in the program are also stopped by
6293@value{GDBN}. On some targets, @value{GDBN} also supports
6294@dfn{non-stop mode}, in which other threads can continue to run freely while
6295you examine the stopped thread in the debugger.
6296
6297@menu
6298* All-Stop Mode:: All threads stop when GDB takes control
6299* Non-Stop Mode:: Other threads continue to execute
6300* Background Execution:: Running your program asynchronously
6301* Thread-Specific Breakpoints:: Controlling breakpoints
6302* Interrupted System Calls:: GDB may interfere with system calls
d914c394 6303* Observer Mode:: GDB does not alter program behavior
0606b73b
SL
6304@end menu
6305
6306@node All-Stop Mode
6307@subsection All-Stop Mode
6308
6309@cindex all-stop mode
6310
6311In all-stop mode, whenever your program stops under @value{GDBN} for any reason,
6312@emph{all} threads of execution stop, not just the current thread. This
6313allows you to examine the overall state of the program, including
6314switching between threads, without worrying that things may change
6315underfoot.
6316
6317Conversely, whenever you restart the program, @emph{all} threads start
6318executing. @emph{This is true even when single-stepping} with commands
6319like @code{step} or @code{next}.
6320
6321In particular, @value{GDBN} cannot single-step all threads in lockstep.
6322Since thread scheduling is up to your debugging target's operating
6323system (not controlled by @value{GDBN}), other threads may
6324execute more than one statement while the current thread completes a
6325single step. Moreover, in general other threads stop in the middle of a
6326statement, rather than at a clean statement boundary, when the program
6327stops.
6328
6329You might even find your program stopped in another thread after
6330continuing or even single-stepping. This happens whenever some other
6331thread runs into a breakpoint, a signal, or an exception before the
6332first thread completes whatever you requested.
6333
6334@cindex automatic thread selection
6335@cindex switching threads automatically
6336@cindex threads, automatic switching
6337Whenever @value{GDBN} stops your program, due to a breakpoint or a
6338signal, it automatically selects the thread where that breakpoint or
6339signal happened. @value{GDBN} alerts you to the context switch with a
6340message such as @samp{[Switching to Thread @var{n}]} to identify the
6341thread.
6342
6343On some OSes, you can modify @value{GDBN}'s default behavior by
6344locking the OS scheduler to allow only a single thread to run.
6345
6346@table @code
6347@item set scheduler-locking @var{mode}
6348@cindex scheduler locking mode
6349@cindex lock scheduler
f2665db5
MM
6350Set the scheduler locking mode. It applies to normal execution,
6351record mode, and replay mode. If it is @code{off}, then there is no
6352locking and any thread may run at any time. If @code{on}, then only
6353the current thread may run when the inferior is resumed. The
6354@code{step} mode optimizes for single-stepping; it prevents other
6355threads from preempting the current thread while you are stepping, so
6356that the focus of debugging does not change unexpectedly. Other
6357threads never get a chance to run when you step, and they are
6358completely free to run when you use commands like @samp{continue},
6359@samp{until}, or @samp{finish}. However, unless another thread hits a
6360breakpoint during its timeslice, @value{GDBN} does not change the
6361current thread away from the thread that you are debugging. The
6362@code{replay} mode behaves like @code{off} in record mode and like
6363@code{on} in replay mode.
0606b73b
SL
6364
6365@item show scheduler-locking
6366Display the current scheduler locking mode.
6367@end table
6368
d4db2f36
PA
6369@cindex resume threads of multiple processes simultaneously
6370By default, when you issue one of the execution commands such as
6371@code{continue}, @code{next} or @code{step}, @value{GDBN} allows only
6372threads of the current inferior to run. For example, if @value{GDBN}
6373is attached to two inferiors, each with two threads, the
6374@code{continue} command resumes only the two threads of the current
6375inferior. This is useful, for example, when you debug a program that
6376forks and you want to hold the parent stopped (so that, for instance,
6377it doesn't run to exit), while you debug the child. In other
6378situations, you may not be interested in inspecting the current state
6379of any of the processes @value{GDBN} is attached to, and you may want
6380to resume them all until some breakpoint is hit. In the latter case,
6381you can instruct @value{GDBN} to allow all threads of all the
6382inferiors to run with the @w{@code{set schedule-multiple}} command.
6383
6384@table @code
6385@kindex set schedule-multiple
6386@item set schedule-multiple
6387Set the mode for allowing threads of multiple processes to be resumed
6388when an execution command is issued. When @code{on}, all threads of
6389all processes are allowed to run. When @code{off}, only the threads
6390of the current process are resumed. The default is @code{off}. The
6391@code{scheduler-locking} mode takes precedence when set to @code{on},
6392or while you are stepping and set to @code{step}.
6393
6394@item show schedule-multiple
6395Display the current mode for resuming the execution of threads of
6396multiple processes.
6397@end table
6398
0606b73b
SL
6399@node Non-Stop Mode
6400@subsection Non-Stop Mode
6401
6402@cindex non-stop mode
6403
6404@c This section is really only a place-holder, and needs to be expanded
97d8f0ee 6405@c with more details.
0606b73b
SL
6406
6407For some multi-threaded targets, @value{GDBN} supports an optional
6408mode of operation in which you can examine stopped program threads in
6409the debugger while other threads continue to execute freely. This
97d8f0ee
DE
6410minimizes intrusion when debugging live systems, such as programs
6411where some threads have real-time constraints or must continue to
0606b73b
SL
6412respond to external events. This is referred to as @dfn{non-stop} mode.
6413
6414In non-stop mode, when a thread stops to report a debugging event,
6415@emph{only} that thread is stopped; @value{GDBN} does not stop other
6416threads as well, in contrast to the all-stop mode behavior. Additionally,
6417execution commands such as @code{continue} and @code{step} apply by default
6418only to the current thread in non-stop mode, rather than all threads as
6419in all-stop mode. This allows you to control threads explicitly in
97d8f0ee 6420ways that are not possible in all-stop mode --- for example, stepping
0606b73b 6421one thread while allowing others to run freely, stepping
97d8f0ee 6422one thread while holding all others stopped, or stepping several threads
0606b73b
SL
6423independently and simultaneously.
6424
6425To enter non-stop mode, use this sequence of commands before you run
6426or attach to your program:
6427
0606b73b 6428@smallexample
0606b73b
SL
6429# If using the CLI, pagination breaks non-stop.
6430set pagination off
6431
6432# Finally, turn it on!
6433set non-stop on
6434@end smallexample
6435
6436You can use these commands to manipulate the non-stop mode setting:
6437
6438@table @code
6439@kindex set non-stop
6440@item set non-stop on
6441Enable selection of non-stop mode.
6442@item set non-stop off
6443Disable selection of non-stop mode.
6444@kindex show non-stop
6445@item show non-stop
6446Show the current non-stop enablement setting.
6447@end table
6448
6449Note these commands only reflect whether non-stop mode is enabled,
97d8f0ee 6450not whether the currently-executing program is being run in non-stop mode.
0606b73b 6451In particular, the @code{set non-stop} preference is only consulted when
97d8f0ee 6452@value{GDBN} starts or connects to the target program, and it is generally
0606b73b
SL
6453not possible to switch modes once debugging has started. Furthermore,
6454since not all targets support non-stop mode, even when you have enabled
6455non-stop mode, @value{GDBN} may still fall back to all-stop operation by
6456default.
6457
6458In non-stop mode, all execution commands apply only to the current thread
97d8f0ee 6459by default. That is, @code{continue} only continues one thread.
0606b73b
SL
6460To continue all threads, issue @code{continue -a} or @code{c -a}.
6461
97d8f0ee 6462You can use @value{GDBN}'s background execution commands
0606b73b 6463(@pxref{Background Execution}) to run some threads in the background
97d8f0ee 6464while you continue to examine or step others from @value{GDBN}.
0606b73b
SL
6465The MI execution commands (@pxref{GDB/MI Program Execution}) are
6466always executed asynchronously in non-stop mode.
6467
6468Suspending execution is done with the @code{interrupt} command when
97d8f0ee
DE
6469running in the background, or @kbd{Ctrl-c} during foreground execution.
6470In all-stop mode, this stops the whole process;
6471but in non-stop mode the interrupt applies only to the current thread.
0606b73b
SL
6472To stop the whole program, use @code{interrupt -a}.
6473
6474Other execution commands do not currently support the @code{-a} option.
6475
6476In non-stop mode, when a thread stops, @value{GDBN} doesn't automatically make
6477that thread current, as it does in all-stop mode. This is because the
97d8f0ee 6478thread stop notifications are asynchronous with respect to @value{GDBN}'s
0606b73b
SL
6479command interpreter, and it would be confusing if @value{GDBN} unexpectedly
6480changed to a different thread just as you entered a command to operate on the
6481previously current thread.
6482
6483@node Background Execution
6484@subsection Background Execution
6485
6486@cindex foreground execution
6487@cindex background execution
6488@cindex asynchronous execution
6489@cindex execution, foreground, background and asynchronous
6490
6491@value{GDBN}'s execution commands have two variants: the normal
6492foreground (synchronous) behavior, and a background
97d8f0ee 6493(asynchronous) behavior. In foreground execution, @value{GDBN} waits for
0606b73b
SL
6494the program to report that some thread has stopped before prompting for
6495another command. In background execution, @value{GDBN} immediately gives
6496a command prompt so that you can issue other commands while your program runs.
6497
32fc0df9
PA
6498If the target doesn't support async mode, @value{GDBN} issues an error
6499message if you attempt to use the background execution commands.
6500
74fdb8ff 6501@cindex @code{&}, background execution of commands
0606b73b
SL
6502To specify background execution, add a @code{&} to the command. For example,
6503the background form of the @code{continue} command is @code{continue&}, or
6504just @code{c&}. The execution commands that accept background execution
6505are:
6506
6507@table @code
6508@kindex run&
6509@item run
6510@xref{Starting, , Starting your Program}.
6511
6512@item attach
6513@kindex attach&
6514@xref{Attach, , Debugging an Already-running Process}.
6515
6516@item step
6517@kindex step&
6518@xref{Continuing and Stepping, step}.
6519
6520@item stepi
6521@kindex stepi&
6522@xref{Continuing and Stepping, stepi}.
6523
6524@item next
6525@kindex next&
6526@xref{Continuing and Stepping, next}.
6527
7ce58dd2
DE
6528@item nexti
6529@kindex nexti&
6530@xref{Continuing and Stepping, nexti}.
6531
0606b73b
SL
6532@item continue
6533@kindex continue&
6534@xref{Continuing and Stepping, continue}.
6535
6536@item finish
6537@kindex finish&
6538@xref{Continuing and Stepping, finish}.
6539
6540@item until
6541@kindex until&
6542@xref{Continuing and Stepping, until}.
6543
6544@end table
6545
6546Background execution is especially useful in conjunction with non-stop
6547mode for debugging programs with multiple threads; see @ref{Non-Stop Mode}.
6548However, you can also use these commands in the normal all-stop mode with
6549the restriction that you cannot issue another execution command until the
6550previous one finishes. Examples of commands that are valid in all-stop
6551mode while the program is running include @code{help} and @code{info break}.
6552
6553You can interrupt your program while it is running in the background by
6554using the @code{interrupt} command.
6555
6556@table @code
6557@kindex interrupt
6558@item interrupt
6559@itemx interrupt -a
6560
97d8f0ee 6561Suspend execution of the running program. In all-stop mode,
0606b73b 6562@code{interrupt} stops the whole process, but in non-stop mode, it stops
97d8f0ee 6563only the current thread. To stop the whole program in non-stop mode,
0606b73b
SL
6564use @code{interrupt -a}.
6565@end table
6566
0606b73b
SL
6567@node Thread-Specific Breakpoints
6568@subsection Thread-Specific Breakpoints
6569
c906108c 6570When your program has multiple threads (@pxref{Threads,, Debugging
79a6e687 6571Programs with Multiple Threads}), you can choose whether to set
c906108c
SS
6572breakpoints on all threads, or on a particular thread.
6573
6574@table @code
6575@cindex breakpoints and threads
6576@cindex thread breakpoints
5d5658a1
PA
6577@kindex break @dots{} thread @var{thread-id}
6578@item break @var{location} thread @var{thread-id}
6579@itemx break @var{location} thread @var{thread-id} if @dots{}
629500fa 6580@var{location} specifies source lines; there are several ways of
2a25a5ba
EZ
6581writing them (@pxref{Specify Location}), but the effect is always to
6582specify some source line.
c906108c 6583
5d5658a1 6584Use the qualifier @samp{thread @var{thread-id}} with a breakpoint command
c906108c 6585to specify that you only want @value{GDBN} to stop the program when a
5d5658a1
PA
6586particular thread reaches this breakpoint. The @var{thread-id} specifier
6587is one of the thread identifiers assigned by @value{GDBN}, shown
697aa1b7 6588in the first column of the @samp{info threads} display.
c906108c 6589
5d5658a1 6590If you do not specify @samp{thread @var{thread-id}} when you set a
c906108c
SS
6591breakpoint, the breakpoint applies to @emph{all} threads of your
6592program.
6593
6594You can use the @code{thread} qualifier on conditional breakpoints as
5d5658a1 6595well; in this case, place @samp{thread @var{thread-id}} before or
b6199126 6596after the breakpoint condition, like this:
c906108c
SS
6597
6598@smallexample
2df3850c 6599(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
c906108c
SS
6600@end smallexample
6601
6602@end table
6603
f4fb82a1
PA
6604Thread-specific breakpoints are automatically deleted when
6605@value{GDBN} detects the corresponding thread is no longer in the
6606thread list. For example:
6607
6608@smallexample
6609(@value{GDBP}) c
6610Thread-specific breakpoint 3 deleted - thread 28 no longer in the thread list.
6611@end smallexample
6612
6613There are several ways for a thread to disappear, such as a regular
6614thread exit, but also when you detach from the process with the
6615@code{detach} command (@pxref{Attach, ,Debugging an Already-running
6616Process}), or if @value{GDBN} loses the remote connection
6617(@pxref{Remote Debugging}), etc. Note that with some targets,
6618@value{GDBN} is only able to detect a thread has exited when the user
6619explictly asks for the thread list with the @code{info threads}
6620command.
6621
0606b73b
SL
6622@node Interrupted System Calls
6623@subsection Interrupted System Calls
c906108c 6624
36d86913
MC
6625@cindex thread breakpoints and system calls
6626@cindex system calls and thread breakpoints
6627@cindex premature return from system calls
0606b73b
SL
6628There is an unfortunate side effect when using @value{GDBN} to debug
6629multi-threaded programs. If one thread stops for a
36d86913
MC
6630breakpoint, or for some other reason, and another thread is blocked in a
6631system call, then the system call may return prematurely. This is a
6632consequence of the interaction between multiple threads and the signals
6633that @value{GDBN} uses to implement breakpoints and other events that
6634stop execution.
6635
6636To handle this problem, your program should check the return value of
6637each system call and react appropriately. This is good programming
6638style anyways.
6639
6640For example, do not write code like this:
6641
6642@smallexample
6643 sleep (10);
6644@end smallexample
6645
6646The call to @code{sleep} will return early if a different thread stops
6647at a breakpoint or for some other reason.
6648
6649Instead, write this:
6650
6651@smallexample
6652 int unslept = 10;
6653 while (unslept > 0)
6654 unslept = sleep (unslept);
6655@end smallexample
6656
6657A system call is allowed to return early, so the system is still
6658conforming to its specification. But @value{GDBN} does cause your
6659multi-threaded program to behave differently than it would without
6660@value{GDBN}.
6661
6662Also, @value{GDBN} uses internal breakpoints in the thread library to
6663monitor certain events such as thread creation and thread destruction.
6664When such an event happens, a system call in another thread may return
6665prematurely, even though your program does not appear to stop.
6666
d914c394
SS
6667@node Observer Mode
6668@subsection Observer Mode
6669
6670If you want to build on non-stop mode and observe program behavior
6671without any chance of disruption by @value{GDBN}, you can set
6672variables to disable all of the debugger's attempts to modify state,
6673whether by writing memory, inserting breakpoints, etc. These operate
6674at a low level, intercepting operations from all commands.
6675
6676When all of these are set to @code{off}, then @value{GDBN} is said to
6677be @dfn{observer mode}. As a convenience, the variable
6678@code{observer} can be set to disable these, plus enable non-stop
6679mode.
6680
6681Note that @value{GDBN} will not prevent you from making nonsensical
6682combinations of these settings. For instance, if you have enabled
6683@code{may-insert-breakpoints} but disabled @code{may-write-memory},
6684then breakpoints that work by writing trap instructions into the code
6685stream will still not be able to be placed.
6686
6687@table @code
6688
6689@kindex observer
6690@item set observer on
6691@itemx set observer off
6692When set to @code{on}, this disables all the permission variables
6693below (except for @code{insert-fast-tracepoints}), plus enables
6694non-stop debugging. Setting this to @code{off} switches back to
6695normal debugging, though remaining in non-stop mode.
6696
6697@item show observer
6698Show whether observer mode is on or off.
6699
6700@kindex may-write-registers
6701@item set may-write-registers on
6702@itemx set may-write-registers off
6703This controls whether @value{GDBN} will attempt to alter the values of
6704registers, such as with assignment expressions in @code{print}, or the
6705@code{jump} command. It defaults to @code{on}.
6706
6707@item show may-write-registers
6708Show the current permission to write registers.
6709
6710@kindex may-write-memory
6711@item set may-write-memory on
6712@itemx set may-write-memory off
6713This controls whether @value{GDBN} will attempt to alter the contents
6714of memory, such as with assignment expressions in @code{print}. It
6715defaults to @code{on}.
6716
6717@item show may-write-memory
6718Show the current permission to write memory.
6719
6720@kindex may-insert-breakpoints
6721@item set may-insert-breakpoints on
6722@itemx set may-insert-breakpoints off
6723This controls whether @value{GDBN} will attempt to insert breakpoints.
6724This affects all breakpoints, including internal breakpoints defined
6725by @value{GDBN}. It defaults to @code{on}.
6726
6727@item show may-insert-breakpoints
6728Show the current permission to insert breakpoints.
6729
6730@kindex may-insert-tracepoints
6731@item set may-insert-tracepoints on
6732@itemx set may-insert-tracepoints off
6733This controls whether @value{GDBN} will attempt to insert (regular)
6734tracepoints at the beginning of a tracing experiment. It affects only
6735non-fast tracepoints, fast tracepoints being under the control of
6736@code{may-insert-fast-tracepoints}. It defaults to @code{on}.
6737
6738@item show may-insert-tracepoints
6739Show the current permission to insert tracepoints.
6740
6741@kindex may-insert-fast-tracepoints
6742@item set may-insert-fast-tracepoints on
6743@itemx set may-insert-fast-tracepoints off
6744This controls whether @value{GDBN} will attempt to insert fast
6745tracepoints at the beginning of a tracing experiment. It affects only
6746fast tracepoints, regular (non-fast) tracepoints being under the
6747control of @code{may-insert-tracepoints}. It defaults to @code{on}.
6748
6749@item show may-insert-fast-tracepoints
6750Show the current permission to insert fast tracepoints.
6751
6752@kindex may-interrupt
6753@item set may-interrupt on
6754@itemx set may-interrupt off
6755This controls whether @value{GDBN} will attempt to interrupt or stop
6756program execution. When this variable is @code{off}, the
6757@code{interrupt} command will have no effect, nor will
6758@kbd{Ctrl-c}. It defaults to @code{on}.
6759
6760@item show may-interrupt
6761Show the current permission to interrupt or stop the program.
6762
6763@end table
c906108c 6764
bacec72f
MS
6765@node Reverse Execution
6766@chapter Running programs backward
6767@cindex reverse execution
6768@cindex running programs backward
6769
6770When you are debugging a program, it is not unusual to realize that
6771you have gone too far, and some event of interest has already happened.
6772If the target environment supports it, @value{GDBN} can allow you to
6773``rewind'' the program by running it backward.
6774
6775A target environment that supports reverse execution should be able
6776to ``undo'' the changes in machine state that have taken place as the
6777program was executing normally. Variables, registers etc.@: should
6778revert to their previous values. Obviously this requires a great
6779deal of sophistication on the part of the target environment; not
6780all target environments can support reverse execution.
6781
6782When a program is executed in reverse, the instructions that
6783have most recently been executed are ``un-executed'', in reverse
6784order. The program counter runs backward, following the previous
6785thread of execution in reverse. As each instruction is ``un-executed'',
6786the values of memory and/or registers that were changed by that
6787instruction are reverted to their previous states. After executing
6788a piece of source code in reverse, all side effects of that code
6789should be ``undone'', and all variables should be returned to their
6790prior values@footnote{
6791Note that some side effects are easier to undo than others. For instance,
6792memory and registers are relatively easy, but device I/O is hard. Some
6793targets may be able undo things like device I/O, and some may not.
6794
6795The contract between @value{GDBN} and the reverse executing target
6796requires only that the target do something reasonable when
6797@value{GDBN} tells it to execute backwards, and then report the
6798results back to @value{GDBN}. Whatever the target reports back to
6799@value{GDBN}, @value{GDBN} will report back to the user. @value{GDBN}
6800assumes that the memory and registers that the target reports are in a
6801consistant state, but @value{GDBN} accepts whatever it is given.
6802}.
6803
73f8a590
PA
6804On some platforms, @value{GDBN} has built-in support for reverse
6805execution, activated with the @code{record} or @code{record btrace}
6806commands. @xref{Process Record and Replay}. Some remote targets,
6807typically full system emulators, support reverse execution directly
6808without requiring any special command.
6809
bacec72f
MS
6810If you are debugging in a target environment that supports
6811reverse execution, @value{GDBN} provides the following commands.
6812
6813@table @code
6814@kindex reverse-continue
6815@kindex rc @r{(@code{reverse-continue})}
6816@item reverse-continue @r{[}@var{ignore-count}@r{]}
6817@itemx rc @r{[}@var{ignore-count}@r{]}
6818Beginning at the point where your program last stopped, start executing
6819in reverse. Reverse execution will stop for breakpoints and synchronous
6820exceptions (signals), just like normal execution. Behavior of
6821asynchronous signals depends on the target environment.
6822
6823@kindex reverse-step
6824@kindex rs @r{(@code{step})}
6825@item reverse-step @r{[}@var{count}@r{]}
6826Run the program backward until control reaches the start of a
6827different source line; then stop it, and return control to @value{GDBN}.
6828
6829Like the @code{step} command, @code{reverse-step} will only stop
6830at the beginning of a source line. It ``un-executes'' the previously
6831executed source line. If the previous source line included calls to
6832debuggable functions, @code{reverse-step} will step (backward) into
6833the called function, stopping at the beginning of the @emph{last}
6834statement in the called function (typically a return statement).
6835
6836Also, as with the @code{step} command, if non-debuggable functions are
6837called, @code{reverse-step} will run thru them backward without stopping.
6838
6839@kindex reverse-stepi
6840@kindex rsi @r{(@code{reverse-stepi})}
6841@item reverse-stepi @r{[}@var{count}@r{]}
6842Reverse-execute one machine instruction. Note that the instruction
6843to be reverse-executed is @emph{not} the one pointed to by the program
6844counter, but the instruction executed prior to that one. For instance,
6845if the last instruction was a jump, @code{reverse-stepi} will take you
6846back from the destination of the jump to the jump instruction itself.
6847
6848@kindex reverse-next
6849@kindex rn @r{(@code{reverse-next})}
6850@item reverse-next @r{[}@var{count}@r{]}
6851Run backward to the beginning of the previous line executed in
6852the current (innermost) stack frame. If the line contains function
6853calls, they will be ``un-executed'' without stopping. Starting from
6854the first line of a function, @code{reverse-next} will take you back
6855to the caller of that function, @emph{before} the function was called,
6856just as the normal @code{next} command would take you from the last
6857line of a function back to its return to its caller
16af530a 6858@footnote{Unless the code is too heavily optimized.}.
bacec72f
MS
6859
6860@kindex reverse-nexti
6861@kindex rni @r{(@code{reverse-nexti})}
6862@item reverse-nexti @r{[}@var{count}@r{]}
6863Like @code{nexti}, @code{reverse-nexti} executes a single instruction
6864in reverse, except that called functions are ``un-executed'' atomically.
6865That is, if the previously executed instruction was a return from
540aa8e7 6866another function, @code{reverse-nexti} will continue to execute
bacec72f
MS
6867in reverse until the call to that function (from the current stack
6868frame) is reached.
6869
6870@kindex reverse-finish
6871@item reverse-finish
6872Just as the @code{finish} command takes you to the point where the
6873current function returns, @code{reverse-finish} takes you to the point
6874where it was called. Instead of ending up at the end of the current
6875function invocation, you end up at the beginning.
6876
6877@kindex set exec-direction
6878@item set exec-direction
6879Set the direction of target execution.
984359d2 6880@item set exec-direction reverse
bacec72f
MS
6881@cindex execute forward or backward in time
6882@value{GDBN} will perform all execution commands in reverse, until the
6883exec-direction mode is changed to ``forward''. Affected commands include
6884@code{step, stepi, next, nexti, continue, and finish}. The @code{return}
6885command cannot be used in reverse mode.
6886@item set exec-direction forward
6887@value{GDBN} will perform all execution commands in the normal fashion.
6888This is the default.
6889@end table
6890
c906108c 6891
a2311334
EZ
6892@node Process Record and Replay
6893@chapter Recording Inferior's Execution and Replaying It
53cc454a
HZ
6894@cindex process record and replay
6895@cindex recording inferior's execution and replaying it
6896
8e05493c
EZ
6897On some platforms, @value{GDBN} provides a special @dfn{process record
6898and replay} target that can record a log of the process execution, and
6899replay it later with both forward and reverse execution commands.
a2311334
EZ
6900
6901@cindex replay mode
6902When this target is in use, if the execution log includes the record
6903for the next instruction, @value{GDBN} will debug in @dfn{replay
6904mode}. In the replay mode, the inferior does not really execute code
6905instructions. Instead, all the events that normally happen during
6906code execution are taken from the execution log. While code is not
6907really executed in replay mode, the values of registers (including the
6908program counter register) and the memory of the inferior are still
8e05493c
EZ
6909changed as they normally would. Their contents are taken from the
6910execution log.
a2311334
EZ
6911
6912@cindex record mode
6913If the record for the next instruction is not in the execution log,
6914@value{GDBN} will debug in @dfn{record mode}. In this mode, the
6915inferior executes normally, and @value{GDBN} records the execution log
6916for future replay.
6917
8e05493c
EZ
6918The process record and replay target supports reverse execution
6919(@pxref{Reverse Execution}), even if the platform on which the
6920inferior runs does not. However, the reverse execution is limited in
6921this case by the range of the instructions recorded in the execution
6922log. In other words, reverse execution on platforms that don't
6923support it directly can only be done in the replay mode.
6924
6925When debugging in the reverse direction, @value{GDBN} will work in
6926replay mode as long as the execution log includes the record for the
6927previous instruction; otherwise, it will work in record mode, if the
6928platform supports reverse execution, or stop if not.
6929
73f8a590
PA
6930Currently, process record and replay is supported on ARM, Aarch64,
6931Moxie, PowerPC, PowerPC64, S/390, and x86 (i386/amd64) running
6932GNU/Linux. Process record and replay can be used both when native
6933debugging, and when remote debugging via @code{gdbserver}.
6934
a2311334
EZ
6935For architecture environments that support process record and replay,
6936@value{GDBN} provides the following commands:
53cc454a
HZ
6937
6938@table @code
6939@kindex target record
59ea5688
MM
6940@kindex target record-full
6941@kindex target record-btrace
53cc454a 6942@kindex record
59ea5688
MM
6943@kindex record full
6944@kindex record btrace
f4abbc16 6945@kindex record btrace bts
b20a6524 6946@kindex record btrace pt
f4abbc16 6947@kindex record bts
b20a6524 6948@kindex record pt
53cc454a 6949@kindex rec
59ea5688
MM
6950@kindex rec full
6951@kindex rec btrace
f4abbc16 6952@kindex rec btrace bts
b20a6524 6953@kindex rec btrace pt
f4abbc16 6954@kindex rec bts
b20a6524 6955@kindex rec pt
59ea5688
MM
6956@item record @var{method}
6957This command starts the process record and replay target. The
6958recording method can be specified as parameter. Without a parameter
6959the command uses the @code{full} recording method. The following
6960recording methods are available:
a2311334 6961
59ea5688
MM
6962@table @code
6963@item full
6964Full record/replay recording using @value{GDBN}'s software record and
6965replay implementation. This method allows replaying and reverse
6966execution.
6967
f4abbc16 6968@item btrace @var{format}
73f8a590
PA
6969Hardware-supported instruction recording, supported on Intel
6970processors. This method does not record data. Further, the data is
6971collected in a ring buffer so old data will be overwritten when the
6972buffer is full. It allows limited reverse execution. Variables and
6973registers are not available during reverse execution. In remote
6974debugging, recording continues on disconnect. Recorded data can be
6975inspected after reconnecting. The recording may be stopped using
6976@code{record stop}.
59ea5688 6977
f4abbc16
MM
6978The recording format can be specified as parameter. Without a parameter
6979the command chooses the recording format. The following recording
6980formats are available:
6981
6982@table @code
6983@item bts
6984@cindex branch trace store
6985Use the @dfn{Branch Trace Store} (@acronym{BTS}) recording format. In
6986this format, the processor stores a from/to record for each executed
6987branch in the btrace ring buffer.
b20a6524
MM
6988
6989@item pt
bc504a31
PA
6990@cindex Intel Processor Trace
6991Use the @dfn{Intel Processor Trace} recording format. In this
b20a6524
MM
6992format, the processor stores the execution trace in a compressed form
6993that is afterwards decoded by @value{GDBN}.
6994
6995The trace can be recorded with very low overhead. The compressed
6996trace format also allows small trace buffers to already contain a big
6997number of instructions compared to @acronym{BTS}.
6998
6999Decoding the recorded execution trace, on the other hand, is more
7000expensive than decoding @acronym{BTS} trace. This is mostly due to the
7001increased number of instructions to process. You should increase the
7002buffer-size with care.
f4abbc16
MM
7003@end table
7004
7005Not all recording formats may be available on all processors.
59ea5688
MM
7006@end table
7007
7008The process record and replay target can only debug a process that is
7009already running. Therefore, you need first to start the process with
7010the @kbd{run} or @kbd{start} commands, and then start the recording
7011with the @kbd{record @var{method}} command.
7012
a2311334
EZ
7013@cindex displaced stepping, and process record and replay
7014Displaced stepping (@pxref{Maintenance Commands,, displaced stepping})
7015will be automatically disabled when process record and replay target
7016is started. That's because the process record and replay target
7017doesn't support displaced stepping.
7018
7019@cindex non-stop mode, and process record and replay
7020@cindex asynchronous execution, and process record and replay
7021If the inferior is in the non-stop mode (@pxref{Non-Stop Mode}) or in
59ea5688
MM
7022the asynchronous execution mode (@pxref{Background Execution}), not
7023all recording methods are available. The @code{full} recording method
7024does not support these two modes.
53cc454a
HZ
7025
7026@kindex record stop
7027@kindex rec s
7028@item record stop
a2311334
EZ
7029Stop the process record and replay target. When process record and
7030replay target stops, the entire execution log will be deleted and the
7031inferior will either be terminated, or will remain in its final state.
53cc454a 7032
a2311334
EZ
7033When you stop the process record and replay target in record mode (at
7034the end of the execution log), the inferior will be stopped at the
7035next instruction that would have been recorded. In other words, if
7036you record for a while and then stop recording, the inferior process
7037will be left in the same state as if the recording never happened.
53cc454a 7038
a2311334
EZ
7039On the other hand, if the process record and replay target is stopped
7040while in replay mode (that is, not at the end of the execution log,
7041but at some earlier point), the inferior process will become ``live''
7042at that earlier state, and it will then be possible to continue the
7043usual ``live'' debugging of the process from that state.
53cc454a 7044
a2311334
EZ
7045When the inferior process exits, or @value{GDBN} detaches from it,
7046process record and replay target will automatically stop itself.
53cc454a 7047
742ce053
MM
7048@kindex record goto
7049@item record goto
7050Go to a specific location in the execution log. There are several
7051ways to specify the location to go to:
7052
7053@table @code
7054@item record goto begin
7055@itemx record goto start
7056Go to the beginning of the execution log.
7057
7058@item record goto end
7059Go to the end of the execution log.
7060
7061@item record goto @var{n}
7062Go to instruction number @var{n} in the execution log.
7063@end table
7064
24e933df
HZ
7065@kindex record save
7066@item record save @var{filename}
7067Save the execution log to a file @file{@var{filename}}.
7068Default filename is @file{gdb_record.@var{process_id}}, where
7069@var{process_id} is the process ID of the inferior.
7070
59ea5688
MM
7071This command may not be available for all recording methods.
7072
24e933df
HZ
7073@kindex record restore
7074@item record restore @var{filename}
7075Restore the execution log from a file @file{@var{filename}}.
7076File must have been created with @code{record save}.
7077
59ea5688
MM
7078@kindex set record full
7079@item set record full insn-number-max @var{limit}
f81d1120 7080@itemx set record full insn-number-max unlimited
59ea5688
MM
7081Set the limit of instructions to be recorded for the @code{full}
7082recording method. Default value is 200000.
53cc454a 7083
a2311334
EZ
7084If @var{limit} is a positive number, then @value{GDBN} will start
7085deleting instructions from the log once the number of the record
7086instructions becomes greater than @var{limit}. For every new recorded
7087instruction, @value{GDBN} will delete the earliest recorded
7088instruction to keep the number of recorded instructions at the limit.
7089(Since deleting recorded instructions loses information, @value{GDBN}
7090lets you control what happens when the limit is reached, by means of
7091the @code{stop-at-limit} option, described below.)
53cc454a 7092
f81d1120
PA
7093If @var{limit} is @code{unlimited} or zero, @value{GDBN} will never
7094delete recorded instructions from the execution log. The number of
7095recorded instructions is limited only by the available memory.
53cc454a 7096
59ea5688
MM
7097@kindex show record full
7098@item show record full insn-number-max
7099Show the limit of instructions to be recorded with the @code{full}
7100recording method.
53cc454a 7101
59ea5688
MM
7102@item set record full stop-at-limit
7103Control the behavior of the @code{full} recording method when the
7104number of recorded instructions reaches the limit. If ON (the
7105default), @value{GDBN} will stop when the limit is reached for the
7106first time and ask you whether you want to stop the inferior or
7107continue running it and recording the execution log. If you decide
7108to continue recording, each new recorded instruction will cause the
7109oldest one to be deleted.
53cc454a 7110
a2311334
EZ
7111If this option is OFF, @value{GDBN} will automatically delete the
7112oldest record to make room for each new one, without asking.
53cc454a 7113
59ea5688 7114@item show record full stop-at-limit
a2311334 7115Show the current setting of @code{stop-at-limit}.
53cc454a 7116
59ea5688 7117@item set record full memory-query
bb08c432 7118Control the behavior when @value{GDBN} is unable to record memory
59ea5688
MM
7119changes caused by an instruction for the @code{full} recording method.
7120If ON, @value{GDBN} will query whether to stop the inferior in that
7121case.
bb08c432
HZ
7122
7123If this option is OFF (the default), @value{GDBN} will automatically
7124ignore the effect of such instructions on memory. Later, when
7125@value{GDBN} replays this execution log, it will mark the log of this
7126instruction as not accessible, and it will not affect the replay
7127results.
7128
59ea5688 7129@item show record full memory-query
bb08c432
HZ
7130Show the current setting of @code{memory-query}.
7131
67b5c0c1
MM
7132@kindex set record btrace
7133The @code{btrace} record target does not trace data. As a
7134convenience, when replaying, @value{GDBN} reads read-only memory off
7135the live program directly, assuming that the addresses of the
7136read-only areas don't change. This for example makes it possible to
7137disassemble code while replaying, but not to print variables.
7138In some cases, being able to inspect variables might be useful.
7139You can use the following command for that:
7140
7141@item set record btrace replay-memory-access
7142Control the behavior of the @code{btrace} recording method when
7143accessing memory during replay. If @code{read-only} (the default),
7144@value{GDBN} will only allow accesses to read-only memory.
7145If @code{read-write}, @value{GDBN} will allow accesses to read-only
7146and to read-write memory. Beware that the accessed memory corresponds
7147to the live target and not necessarily to the current replay
7148position.
7149
4a4495d6
MM
7150@item set record btrace cpu @var{identifier}
7151Set the processor to be used for enabling workarounds for processor
7152errata when decoding the trace.
7153
7154Processor errata are defects in processor operation, caused by its
7155design or manufacture. They can cause a trace not to match the
7156specification. This, in turn, may cause trace decode to fail.
7157@value{GDBN} can detect erroneous trace packets and correct them, thus
7158avoiding the decoding failures. These corrections are known as
7159@dfn{errata workarounds}, and are enabled based on the processor on
7160which the trace was recorded.
7161
7162By default, @value{GDBN} attempts to detect the processor
7163automatically, and apply the necessary workarounds for it. However,
7164you may need to specify the processor if @value{GDBN} does not yet
7165support it. This command allows you to do that, and also allows to
7166disable the workarounds.
7167
7168The argument @var{identifier} identifies the @sc{cpu} and is of the
7169form: @code{@var{vendor}:@var{procesor identifier}}. In addition,
7170there are two special identifiers, @code{none} and @code{auto}
7171(default).
7172
7173The following vendor identifiers and corresponding processor
7174identifiers are currently supported:
7175
7176@multitable @columnfractions .1 .9
7177
7178@item @code{intel}
7179@tab @var{family}/@var{model}[/@var{stepping}]
7180
7181@end multitable
7182
7183On GNU/Linux systems, the processor @var{family}, @var{model}, and
7184@var{stepping} can be obtained from @code{/proc/cpuinfo}.
7185
7186If @var{identifier} is @code{auto}, enable errata workarounds for the
7187processor on which the trace was recorded. If @var{identifier} is
7188@code{none}, errata workarounds are disabled.
7189
7190For example, when using an old @value{GDBN} on a new system, decode
7191may fail because @value{GDBN} does not support the new processor. It
7192often suffices to specify an older processor that @value{GDBN}
7193supports.
7194
7195@smallexample
7196(gdb) info record
7197Active record target: record-btrace
7198Recording format: Intel Processor Trace.
7199Buffer size: 16kB.
7200Failed to configure the Intel Processor Trace decoder: unknown cpu.
7201(gdb) set record btrace cpu intel:6/158
7202(gdb) info record
7203Active record target: record-btrace
7204Recording format: Intel Processor Trace.
7205Buffer size: 16kB.
7206Recorded 84872 instructions in 3189 functions (0 gaps) for thread 1 (...).
7207@end smallexample
7208
67b5c0c1
MM
7209@kindex show record btrace
7210@item show record btrace replay-memory-access
7211Show the current setting of @code{replay-memory-access}.
7212
4a4495d6
MM
7213@item show record btrace cpu
7214Show the processor to be used for enabling trace decode errata
7215workarounds.
7216
d33501a5
MM
7217@kindex set record btrace bts
7218@item set record btrace bts buffer-size @var{size}
7219@itemx set record btrace bts buffer-size unlimited
7220Set the requested ring buffer size for branch tracing in @acronym{BTS}
7221format. Default is 64KB.
7222
7223If @var{size} is a positive number, then @value{GDBN} will try to
7224allocate a buffer of at least @var{size} bytes for each new thread
7225that uses the btrace recording method and the @acronym{BTS} format.
7226The actually obtained buffer size may differ from the requested
7227@var{size}. Use the @code{info record} command to see the actual
7228buffer size for each thread that uses the btrace recording method and
7229the @acronym{BTS} format.
7230
7231If @var{limit} is @code{unlimited} or zero, @value{GDBN} will try to
7232allocate a buffer of 4MB.
7233
7234Bigger buffers mean longer traces. On the other hand, @value{GDBN} will
7235also need longer to process the branch trace data before it can be used.
7236
7237@item show record btrace bts buffer-size @var{size}
7238Show the current setting of the requested ring buffer size for branch
7239tracing in @acronym{BTS} format.
7240
b20a6524
MM
7241@kindex set record btrace pt
7242@item set record btrace pt buffer-size @var{size}
7243@itemx set record btrace pt buffer-size unlimited
bc504a31 7244Set the requested ring buffer size for branch tracing in Intel
b20a6524
MM
7245Processor Trace format. Default is 16KB.
7246
7247If @var{size} is a positive number, then @value{GDBN} will try to
7248allocate a buffer of at least @var{size} bytes for each new thread
bc504a31 7249that uses the btrace recording method and the Intel Processor Trace
b20a6524
MM
7250format. The actually obtained buffer size may differ from the
7251requested @var{size}. Use the @code{info record} command to see the
7252actual buffer size for each thread.
7253
7254If @var{limit} is @code{unlimited} or zero, @value{GDBN} will try to
7255allocate a buffer of 4MB.
7256
7257Bigger buffers mean longer traces. On the other hand, @value{GDBN} will
7258also need longer to process the branch trace data before it can be used.
7259
7260@item show record btrace pt buffer-size @var{size}
7261Show the current setting of the requested ring buffer size for branch
bc504a31 7262tracing in Intel Processor Trace format.
b20a6524 7263
29153c24
MS
7264@kindex info record
7265@item info record
59ea5688
MM
7266Show various statistics about the recording depending on the recording
7267method:
7268
7269@table @code
7270@item full
7271For the @code{full} recording method, it shows the state of process
7272record and its in-memory execution log buffer, including:
29153c24
MS
7273
7274@itemize @bullet
7275@item
7276Whether in record mode or replay mode.
7277@item
7278Lowest recorded instruction number (counting from when the current execution log started recording instructions).
7279@item
7280Highest recorded instruction number.
7281@item
7282Current instruction about to be replayed (if in replay mode).
7283@item
7284Number of instructions contained in the execution log.
7285@item
7286Maximum number of instructions that may be contained in the execution log.
7287@end itemize
53cc454a 7288
59ea5688 7289@item btrace
d33501a5
MM
7290For the @code{btrace} recording method, it shows:
7291
7292@itemize @bullet
7293@item
7294Recording format.
7295@item
7296Number of instructions that have been recorded.
7297@item
7298Number of blocks of sequential control-flow formed by the recorded
7299instructions.
7300@item
7301Whether in record mode or replay mode.
7302@end itemize
7303
7304For the @code{bts} recording format, it also shows:
7305@itemize @bullet
7306@item
7307Size of the perf ring buffer.
7308@end itemize
b20a6524
MM
7309
7310For the @code{pt} recording format, it also shows:
7311@itemize @bullet
7312@item
7313Size of the perf ring buffer.
7314@end itemize
59ea5688
MM
7315@end table
7316
53cc454a
HZ
7317@kindex record delete
7318@kindex rec del
7319@item record delete
a2311334 7320When record target runs in replay mode (``in the past''), delete the
53cc454a 7321subsequent execution log and begin to record a new execution log starting
a2311334 7322from the current address. This means you will abandon the previously
53cc454a 7323recorded ``future'' and begin recording a new ``future''.
59ea5688
MM
7324
7325@kindex record instruction-history
7326@kindex rec instruction-history
7327@item record instruction-history
7328Disassembles instructions from the recorded execution log. By
7329default, ten instructions are disassembled. This can be changed using
7330the @code{set record instruction-history-size} command. Instructions
da8c46d2
MM
7331are printed in execution order.
7332
0c532a29
MM
7333It can also print mixed source+disassembly if you specify the the
7334@code{/m} or @code{/s} modifier, and print the raw instructions in hex
7335as well as in symbolic form by specifying the @code{/r} modifier.
7336
7337The current position marker is printed for the instruction at the
7338current program counter value. This instruction can appear multiple
7339times in the trace and the current position marker will be printed
7340every time. To omit the current position marker, specify the
7341@code{/p} modifier.
7342
7343To better align the printed instructions when the trace contains
7344instructions from more than one function, the function name may be
7345omitted by specifying the @code{/f} modifier.
7346
da8c46d2
MM
7347Speculatively executed instructions are prefixed with @samp{?}. This
7348feature is not available for all recording formats.
7349
7350There are several ways to specify what part of the execution log to
7351disassemble:
59ea5688
MM
7352
7353@table @code
7354@item record instruction-history @var{insn}
7355Disassembles ten instructions starting from instruction number
7356@var{insn}.
7357
7358@item record instruction-history @var{insn}, +/-@var{n}
7359Disassembles @var{n} instructions around instruction number
7360@var{insn}. If @var{n} is preceded with @code{+}, disassembles
7361@var{n} instructions after instruction number @var{insn}. If
7362@var{n} is preceded with @code{-}, disassembles @var{n}
7363instructions before instruction number @var{insn}.
7364
7365@item record instruction-history
7366Disassembles ten more instructions after the last disassembly.
7367
7368@item record instruction-history -
7369Disassembles ten more instructions before the last disassembly.
7370
792005b0 7371@item record instruction-history @var{begin}, @var{end}
59ea5688
MM
7372Disassembles instructions beginning with instruction number
7373@var{begin} until instruction number @var{end}. The instruction
0688d04e 7374number @var{end} is included.
59ea5688
MM
7375@end table
7376
7377This command may not be available for all recording methods.
7378
7379@kindex set record
f81d1120
PA
7380@item set record instruction-history-size @var{size}
7381@itemx set record instruction-history-size unlimited
59ea5688
MM
7382Define how many instructions to disassemble in the @code{record
7383instruction-history} command. The default value is 10.
f81d1120 7384A @var{size} of @code{unlimited} means unlimited instructions.
59ea5688
MM
7385
7386@kindex show record
7387@item show record instruction-history-size
7388Show how many instructions to disassemble in the @code{record
7389instruction-history} command.
7390
7391@kindex record function-call-history
7392@kindex rec function-call-history
7393@item record function-call-history
7394Prints the execution history at function granularity. It prints one
7395line for each sequence of instructions that belong to the same
7396function giving the name of that function, the source lines
7397for this instruction sequence (if the @code{/l} modifier is
7398specified), and the instructions numbers that form the sequence (if
8710b709
MM
7399the @code{/i} modifier is specified). The function names are indented
7400to reflect the call stack depth if the @code{/c} modifier is
7401specified. The @code{/l}, @code{/i}, and @code{/c} modifiers can be
7402given together.
59ea5688
MM
7403
7404@smallexample
7405(@value{GDBP}) @b{list 1, 10}
74061 void foo (void)
74072 @{
74083 @}
74094
74105 void bar (void)
74116 @{
74127 ...
74138 foo ();
74149 ...
741510 @}
8710b709
MM
7416(@value{GDBP}) @b{record function-call-history /ilc}
74171 bar inst 1,4 at foo.c:6,8
74182 foo inst 5,10 at foo.c:2,3
74193 bar inst 11,13 at foo.c:9,10
59ea5688
MM
7420@end smallexample
7421
7422By default, ten lines are printed. This can be changed using the
7423@code{set record function-call-history-size} command. Functions are
7424printed in execution order. There are several ways to specify what
7425to print:
7426
7427@table @code
7428@item record function-call-history @var{func}
7429Prints ten functions starting from function number @var{func}.
7430
7431@item record function-call-history @var{func}, +/-@var{n}
7432Prints @var{n} functions around function number @var{func}. If
7433@var{n} is preceded with @code{+}, prints @var{n} functions after
7434function number @var{func}. If @var{n} is preceded with @code{-},
7435prints @var{n} functions before function number @var{func}.
7436
7437@item record function-call-history
7438Prints ten more functions after the last ten-line print.
7439
7440@item record function-call-history -
7441Prints ten more functions before the last ten-line print.
7442
792005b0 7443@item record function-call-history @var{begin}, @var{end}
59ea5688 7444Prints functions beginning with function number @var{begin} until
0688d04e 7445function number @var{end}. The function number @var{end} is included.
59ea5688
MM
7446@end table
7447
7448This command may not be available for all recording methods.
7449
f81d1120
PA
7450@item set record function-call-history-size @var{size}
7451@itemx set record function-call-history-size unlimited
59ea5688
MM
7452Define how many lines to print in the
7453@code{record function-call-history} command. The default value is 10.
f81d1120 7454A size of @code{unlimited} means unlimited lines.
59ea5688
MM
7455
7456@item show record function-call-history-size
7457Show how many lines to print in the
7458@code{record function-call-history} command.
53cc454a
HZ
7459@end table
7460
7461
6d2ebf8b 7462@node Stack
c906108c
SS
7463@chapter Examining the Stack
7464
7465When your program has stopped, the first thing you need to know is where it
7466stopped and how it got there.
7467
7468@cindex call stack
5d161b24
DB
7469Each time your program performs a function call, information about the call
7470is generated.
7471That information includes the location of the call in your program,
7472the arguments of the call,
c906108c 7473and the local variables of the function being called.
5d161b24 7474The information is saved in a block of data called a @dfn{stack frame}.
c906108c
SS
7475The stack frames are allocated in a region of memory called the @dfn{call
7476stack}.
7477
7478When your program stops, the @value{GDBN} commands for examining the
7479stack allow you to see all of this information.
7480
7481@cindex selected frame
7482One of the stack frames is @dfn{selected} by @value{GDBN} and many
7483@value{GDBN} commands refer implicitly to the selected frame. In
7484particular, whenever you ask @value{GDBN} for the value of a variable in
7485your program, the value is found in the selected frame. There are
7486special @value{GDBN} commands to select whichever frame you are
79a6e687 7487interested in. @xref{Selection, ,Selecting a Frame}.
c906108c
SS
7488
7489When your program stops, @value{GDBN} automatically selects the
5d161b24 7490currently executing frame and describes it briefly, similar to the
79a6e687 7491@code{frame} command (@pxref{Frame Info, ,Information about a Frame}).
c906108c
SS
7492
7493@menu
7494* Frames:: Stack frames
7495* Backtrace:: Backtraces
7496* Selection:: Selecting a frame
7497* Frame Info:: Information on a frame
0a232300 7498* Frame Apply:: Applying a command to several frames
0f59c28f 7499* Frame Filter Management:: Managing frame filters
c906108c
SS
7500
7501@end menu
7502
6d2ebf8b 7503@node Frames
79a6e687 7504@section Stack Frames
c906108c 7505
d4f3574e 7506@cindex frame, definition
c906108c
SS
7507@cindex stack frame
7508The call stack is divided up into contiguous pieces called @dfn{stack
7509frames}, or @dfn{frames} for short; each frame is the data associated
7510with one call to one function. The frame contains the arguments given
7511to the function, the function's local variables, and the address at
7512which the function is executing.
7513
7514@cindex initial frame
7515@cindex outermost frame
7516@cindex innermost frame
7517When your program is started, the stack has only one frame, that of the
7518function @code{main}. This is called the @dfn{initial} frame or the
7519@dfn{outermost} frame. Each time a function is called, a new frame is
7520made. Each time a function returns, the frame for that function invocation
7521is eliminated. If a function is recursive, there can be many frames for
7522the same function. The frame for the function in which execution is
7523actually occurring is called the @dfn{innermost} frame. This is the most
7524recently created of all the stack frames that still exist.
7525
7526@cindex frame pointer
7527Inside your program, stack frames are identified by their addresses. A
7528stack frame consists of many bytes, each of which has its own address; each
7529kind of computer has a convention for choosing one byte whose
7530address serves as the address of the frame. Usually this address is kept
e09f16f9
EZ
7531in a register called the @dfn{frame pointer register}
7532(@pxref{Registers, $fp}) while execution is going on in that frame.
c906108c 7533
f67ffa6a 7534@cindex frame level
c906108c 7535@cindex frame number
f67ffa6a
AB
7536@value{GDBN} labels each existing stack frame with a @dfn{level}, a
7537number that is zero for the innermost frame, one for the frame that
7538called it, and so on upward. These level numbers give you a way of
7539designating stack frames in @value{GDBN} commands. The terms
7540@dfn{frame number} and @dfn{frame level} can be used interchangeably to
7541describe this number.
c906108c 7542
6d2ebf8b
SS
7543@c The -fomit-frame-pointer below perennially causes hbox overflow
7544@c underflow problems.
c906108c
SS
7545@cindex frameless execution
7546Some compilers provide a way to compile functions so that they operate
e22ea452 7547without stack frames. (For example, the @value{NGCC} option
474c8240 7548@smallexample
6d2ebf8b 7549@samp{-fomit-frame-pointer}
474c8240 7550@end smallexample
6d2ebf8b 7551generates functions without a frame.)
c906108c
SS
7552This is occasionally done with heavily used library functions to save
7553the frame setup time. @value{GDBN} has limited facilities for dealing
7554with these function invocations. If the innermost function invocation
7555has no stack frame, @value{GDBN} nevertheless regards it as though
7556it had a separate frame, which is numbered zero as usual, allowing
7557correct tracing of the function call chain. However, @value{GDBN} has
7558no provision for frameless functions elsewhere in the stack.
7559
6d2ebf8b 7560@node Backtrace
c906108c
SS
7561@section Backtraces
7562
09d4efe1
EZ
7563@cindex traceback
7564@cindex call stack traces
c906108c
SS
7565A backtrace is a summary of how your program got where it is. It shows one
7566line per frame, for many frames, starting with the currently executing
7567frame (frame zero), followed by its caller (frame one), and on up the
7568stack.
7569
1e611234 7570@anchor{backtrace-command}
c906108c 7571@kindex backtrace
41afff9a 7572@kindex bt @r{(@code{backtrace})}
ea3b0687
TT
7573To print a backtrace of the entire stack, use the @code{backtrace}
7574command, or its alias @code{bt}. This command will print one line per
7575frame for frames in the stack. By default, all stack frames are
7576printed. You can stop the backtrace at any time by typing the system
7577interrupt character, normally @kbd{Ctrl-c}.
7578
7579@table @code
7580@item backtrace [@var{args}@dots{}]
7581@itemx bt [@var{args}@dots{}]
7582Print the backtrace of the entire stack. The optional @var{args} can
7583be one of the following:
7584
7585@table @code
7586@item @var{n}
7587@itemx @var{n}
7588Print only the innermost @var{n} frames, where @var{n} is a positive
7589number.
7590
7591@item -@var{n}
7592@itemx -@var{n}
7593Print only the outermost @var{n} frames, where @var{n} is a positive
7594number.
7595
7596@item full
7597Print the values of the local variables also. This can be combined
7598with a number to limit the number of frames shown.
7599
7600@item no-filters
1e611234
PM
7601Do not run Python frame filters on this backtrace. @xref{Frame
7602Filter API}, for more information. Additionally use @ref{disable
7603frame-filter all} to turn off all frame filters. This is only
7604relevant when @value{GDBN} has been configured with @code{Python}
7605support.
978d6c75
TT
7606
7607@item hide
7608A Python frame filter might decide to ``elide'' some frames. Normally
7609such elided frames are still printed, but they are indented relative
7610to the filtered frames that cause them to be elided. The @code{hide}
7611option causes elided frames to not be printed at all.
c906108c 7612@end table
ea3b0687 7613@end table
c906108c
SS
7614
7615@kindex where
7616@kindex info stack
c906108c
SS
7617The names @code{where} and @code{info stack} (abbreviated @code{info s})
7618are additional aliases for @code{backtrace}.
7619
839c27b7
EZ
7620@cindex multiple threads, backtrace
7621In a multi-threaded program, @value{GDBN} by default shows the
7622backtrace only for the current thread. To display the backtrace for
7623several or all of the threads, use the command @code{thread apply}
7624(@pxref{Threads, thread apply}). For example, if you type @kbd{thread
7625apply all backtrace}, @value{GDBN} will display the backtrace for all
7626the threads; this is handy when you debug a core dump of a
7627multi-threaded program.
7628
c906108c
SS
7629Each line in the backtrace shows the frame number and the function name.
7630The program counter value is also shown---unless you use @code{set
7631print address off}. The backtrace also shows the source file name and
7632line number, as well as the arguments to the function. The program
7633counter value is omitted if it is at the beginning of the code for that
7634line number.
7635
7636Here is an example of a backtrace. It was made with the command
7637@samp{bt 3}, so it shows the innermost three frames.
7638
7639@smallexample
7640@group
5d161b24 7641#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
c906108c 7642 at builtin.c:993
4f5376b2 7643#1 0x6e38 in expand_macro (sym=0x2b600, data=...) at macro.c:242
c906108c
SS
7644#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
7645 at macro.c:71
7646(More stack frames follow...)
7647@end group
7648@end smallexample
7649
7650@noindent
7651The display for frame zero does not begin with a program counter
7652value, indicating that your program has stopped at the beginning of the
7653code for line @code{993} of @code{builtin.c}.
7654
4f5376b2
JB
7655@noindent
7656The value of parameter @code{data} in frame 1 has been replaced by
7657@code{@dots{}}. By default, @value{GDBN} prints the value of a parameter
7658only if it is a scalar (integer, pointer, enumeration, etc). See command
7659@kbd{set print frame-arguments} in @ref{Print Settings} for more details
7660on how to configure the way function parameter values are printed.
7661
585fdaa1 7662@cindex optimized out, in backtrace
18999be5
EZ
7663@cindex function call arguments, optimized out
7664If your program was compiled with optimizations, some compilers will
7665optimize away arguments passed to functions if those arguments are
7666never used after the call. Such optimizations generate code that
7667passes arguments through registers, but doesn't store those arguments
7668in the stack frame. @value{GDBN} has no way of displaying such
7669arguments in stack frames other than the innermost one. Here's what
7670such a backtrace might look like:
7671
7672@smallexample
7673@group
7674#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
7675 at builtin.c:993
585fdaa1
PA
7676#1 0x6e38 in expand_macro (sym=<optimized out>) at macro.c:242
7677#2 0x6840 in expand_token (obs=0x0, t=<optimized out>, td=0xf7fffb08)
18999be5
EZ
7678 at macro.c:71
7679(More stack frames follow...)
7680@end group
7681@end smallexample
7682
7683@noindent
7684The values of arguments that were not saved in their stack frames are
585fdaa1 7685shown as @samp{<optimized out>}.
18999be5
EZ
7686
7687If you need to display the values of such optimized-out arguments,
7688either deduce that from other variables whose values depend on the one
7689you are interested in, or recompile without optimizations.
7690
a8f24a35
EZ
7691@cindex backtrace beyond @code{main} function
7692@cindex program entry point
7693@cindex startup code, and backtrace
25d29d70
AC
7694Most programs have a standard user entry point---a place where system
7695libraries and startup code transition into user code. For C this is
d416eeec
EZ
7696@code{main}@footnote{
7697Note that embedded programs (the so-called ``free-standing''
7698environment) are not required to have a @code{main} function as the
7699entry point. They could even have multiple entry points.}.
7700When @value{GDBN} finds the entry function in a backtrace
25d29d70
AC
7701it will terminate the backtrace, to avoid tracing into highly
7702system-specific (and generally uninteresting) code.
7703
7704If you need to examine the startup code, or limit the number of levels
7705in a backtrace, you can change this behavior:
95f90d25
DJ
7706
7707@table @code
25d29d70
AC
7708@item set backtrace past-main
7709@itemx set backtrace past-main on
4644b6e3 7710@kindex set backtrace
25d29d70
AC
7711Backtraces will continue past the user entry point.
7712
7713@item set backtrace past-main off
95f90d25
DJ
7714Backtraces will stop when they encounter the user entry point. This is the
7715default.
7716
25d29d70 7717@item show backtrace past-main
4644b6e3 7718@kindex show backtrace
25d29d70
AC
7719Display the current user entry point backtrace policy.
7720
2315ffec
RC
7721@item set backtrace past-entry
7722@itemx set backtrace past-entry on
a8f24a35 7723Backtraces will continue past the internal entry point of an application.
2315ffec
RC
7724This entry point is encoded by the linker when the application is built,
7725and is likely before the user entry point @code{main} (or equivalent) is called.
7726
7727@item set backtrace past-entry off
d3e8051b 7728Backtraces will stop when they encounter the internal entry point of an
2315ffec
RC
7729application. This is the default.
7730
7731@item show backtrace past-entry
7732Display the current internal entry point backtrace policy.
7733
25d29d70
AC
7734@item set backtrace limit @var{n}
7735@itemx set backtrace limit 0
f81d1120 7736@itemx set backtrace limit unlimited
25d29d70 7737@cindex backtrace limit
f81d1120
PA
7738Limit the backtrace to @var{n} levels. A value of @code{unlimited}
7739or zero means unlimited levels.
95f90d25 7740
25d29d70
AC
7741@item show backtrace limit
7742Display the current limit on backtrace levels.
95f90d25
DJ
7743@end table
7744
1b56eb55
JK
7745You can control how file names are displayed.
7746
7747@table @code
7748@item set filename-display
7749@itemx set filename-display relative
7750@cindex filename-display
7751Display file names relative to the compilation directory. This is the default.
7752
7753@item set filename-display basename
7754Display only basename of a filename.
7755
7756@item set filename-display absolute
7757Display an absolute filename.
7758
7759@item show filename-display
7760Show the current way to display filenames.
7761@end table
7762
6d2ebf8b 7763@node Selection
79a6e687 7764@section Selecting a Frame
c906108c
SS
7765
7766Most commands for examining the stack and other data in your program work on
7767whichever stack frame is selected at the moment. Here are the commands for
7768selecting a stack frame; all of them finish by printing a brief description
7769of the stack frame just selected.
7770
7771@table @code
d4f3574e 7772@kindex frame@r{, selecting}
41afff9a 7773@kindex f @r{(@code{frame})}
f67ffa6a
AB
7774@item frame @r{[} @var{frame-selection-spec} @r{]}
7775@item f @r{[} @var{frame-selection-spec} @r{]}
7776The @command{frame} command allows different stack frames to be
7777selected. The @var{frame-selection-spec} can be any of the following:
7778
7779@table @code
7780@kindex frame level
7781@item @var{num}
7782@item level @var{num}
7783Select frame level @var{num}. Recall that frame zero is the innermost
c906108c 7784(currently executing) frame, frame one is the frame that called the
f67ffa6a
AB
7785innermost one, and so on. The highest level frame is usually the one
7786for @code{main}.
7787
7788As this is the most common method of navigating the frame stack, the
7789string @command{level} can be omitted. For example, the following two
7790commands are equivalent:
7791
7792@smallexample
7793(@value{GDBP}) frame 3
7794(@value{GDBP}) frame level 3
7795@end smallexample
7796
7797@kindex frame address
7798@item address @var{stack-address}
7799Select the frame with stack address @var{stack-address}. The
7800@var{stack-address} for a frame can be seen in the output of
7801@command{info frame}, for example:
7802
7803@smallexample
7804(gdb) info frame
7805Stack level 1, frame at 0x7fffffffda30:
7806 rip = 0x40066d in b (amd64-entry-value.cc:59); saved rip 0x4004c5
7807 tail call frame, caller of frame at 0x7fffffffda30
7808 source language c++.
7809 Arglist at unknown address.
7810 Locals at unknown address, Previous frame's sp is 0x7fffffffda30
7811@end smallexample
7812
7813The @var{stack-address} for this frame is @code{0x7fffffffda30} as
7814indicated by the line:
7815
7816@smallexample
7817Stack level 1, frame at 0x7fffffffda30:
7818@end smallexample
7819
7820@kindex frame function
7821@item function @var{function-name}
7822Select the stack frame for function @var{function-name}. If there are
7823multiple stack frames for function @var{function-name} then the inner
7824most stack frame is selected.
7825
7826@kindex frame view
7827@item view @var{stack-address} @r{[} @var{pc-addr} @r{]}
7828View a frame that is not part of @value{GDBN}'s backtrace. The frame
7829viewed has stack address @var{stack-addr}, and optionally, a program
7830counter address of @var{pc-addr}.
7831
7832This is useful mainly if the chaining of stack frames has been
7833damaged by a bug, making it impossible for @value{GDBN} to assign
7834numbers properly to all frames. In addition, this can be useful
7835when your program has multiple stacks and switches between them.
7836
7837When viewing a frame outside the current backtrace using
7838@command{frame view} then you can always return to the original
7839stack using one of the previous stack frame selection instructions,
7840for example @command{frame level 0}.
7841
7842@end table
c906108c
SS
7843
7844@kindex up
7845@item up @var{n}
697aa1b7
EZ
7846Move @var{n} frames up the stack; @var{n} defaults to 1. For positive
7847numbers @var{n}, this advances toward the outermost frame, to higher
7848frame numbers, to frames that have existed longer.
c906108c
SS
7849
7850@kindex down
41afff9a 7851@kindex do @r{(@code{down})}
c906108c 7852@item down @var{n}
697aa1b7
EZ
7853Move @var{n} frames down the stack; @var{n} defaults to 1. For
7854positive numbers @var{n}, this advances toward the innermost frame, to
7855lower frame numbers, to frames that were created more recently.
7856You may abbreviate @code{down} as @code{do}.
c906108c
SS
7857@end table
7858
7859All of these commands end by printing two lines of output describing the
7860frame. The first line shows the frame number, the function name, the
7861arguments, and the source file and line number of execution in that
5d161b24 7862frame. The second line shows the text of that source line.
c906108c
SS
7863
7864@need 1000
7865For example:
7866
7867@smallexample
7868@group
7869(@value{GDBP}) up
7870#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
7871 at env.c:10
787210 read_input_file (argv[i]);
7873@end group
7874@end smallexample
7875
7876After such a printout, the @code{list} command with no arguments
7877prints ten lines centered on the point of execution in the frame.
87885426
FN
7878You can also edit the program at the point of execution with your favorite
7879editing program by typing @code{edit}.
79a6e687 7880@xref{List, ,Printing Source Lines},
87885426 7881for details.
c906108c
SS
7882
7883@table @code
fc58fa65 7884@kindex select-frame
f67ffa6a 7885@item select-frame @r{[} @var{frame-selection-spec} @r{]}
fc58fa65
AB
7886The @code{select-frame} command is a variant of @code{frame} that does
7887not display the new frame after selecting it. This command is
7888intended primarily for use in @value{GDBN} command scripts, where the
f67ffa6a
AB
7889output might be unnecessary and distracting. The
7890@var{frame-selection-spec} is as for the @command{frame} command
7891described in @ref{Selection, ,Selecting a Frame}.
fc58fa65 7892
c906108c
SS
7893@kindex down-silently
7894@kindex up-silently
7895@item up-silently @var{n}
7896@itemx down-silently @var{n}
7897These two commands are variants of @code{up} and @code{down},
7898respectively; they differ in that they do their work silently, without
7899causing display of the new frame. They are intended primarily for use
7900in @value{GDBN} command scripts, where the output might be unnecessary and
7901distracting.
7902@end table
7903
6d2ebf8b 7904@node Frame Info
79a6e687 7905@section Information About a Frame
c906108c
SS
7906
7907There are several other commands to print information about the selected
7908stack frame.
7909
7910@table @code
7911@item frame
7912@itemx f
7913When used without any argument, this command does not change which
7914frame is selected, but prints a brief description of the currently
7915selected stack frame. It can be abbreviated @code{f}. With an
7916argument, this command is used to select a stack frame.
79a6e687 7917@xref{Selection, ,Selecting a Frame}.
c906108c
SS
7918
7919@kindex info frame
41afff9a 7920@kindex info f @r{(@code{info frame})}
c906108c
SS
7921@item info frame
7922@itemx info f
7923This command prints a verbose description of the selected stack frame,
7924including:
7925
7926@itemize @bullet
5d161b24
DB
7927@item
7928the address of the frame
c906108c
SS
7929@item
7930the address of the next frame down (called by this frame)
7931@item
7932the address of the next frame up (caller of this frame)
7933@item
7934the language in which the source code corresponding to this frame is written
7935@item
7936the address of the frame's arguments
7937@item
d4f3574e
SS
7938the address of the frame's local variables
7939@item
c906108c
SS
7940the program counter saved in it (the address of execution in the caller frame)
7941@item
7942which registers were saved in the frame
7943@end itemize
7944
7945@noindent The verbose description is useful when
7946something has gone wrong that has made the stack format fail to fit
7947the usual conventions.
7948
f67ffa6a
AB
7949@item info frame @r{[} @var{frame-selection-spec} @r{]}
7950@itemx info f @r{[} @var{frame-selection-spec} @r{]}
7951Print a verbose description of the frame selected by
7952@var{frame-selection-spec}. The @var{frame-selection-spec} is the
7953same as for the @command{frame} command (@pxref{Selection, ,Selecting
7954a Frame}). The selected frame remains unchanged by this command.
c906108c
SS
7955
7956@kindex info args
d321477b 7957@item info args [-q]
c906108c
SS
7958Print the arguments of the selected frame, each on a separate line.
7959
d321477b
PW
7960The optional flag @samp{-q}, which stands for @samp{quiet}, disables
7961printing header information and messages explaining why no argument
7962have been printed.
7963
7964@item info args [-q] [-t @var{type_regexp}] [@var{regexp}]
7965Like @kbd{info args}, but only print the arguments selected
7966with the provided regexp(s).
7967
7968If @var{regexp} is provided, print only the arguments whose names
7969match the regular expression @var{regexp}.
7970
7971If @var{type_regexp} is provided, print only the arguments whose
7972types, as printed by the @code{whatis} command, match
7973the regular expression @var{type_regexp}.
7974If @var{type_regexp} contains space(s), it should be enclosed in
7975quote characters. If needed, use backslash to escape the meaning
7976of special characters or quotes.
7977
7978If both @var{regexp} and @var{type_regexp} are provided, an argument
7979is printed only if its name matches @var{regexp} and its type matches
7980@var{type_regexp}.
7981
7982@item info locals [-q]
c906108c
SS
7983@kindex info locals
7984Print the local variables of the selected frame, each on a separate
7985line. These are all variables (declared either static or automatic)
7986accessible at the point of execution of the selected frame.
7987
d321477b
PW
7988The optional flag @samp{-q}, which stands for @samp{quiet}, disables
7989printing header information and messages explaining why no local variables
7990have been printed.
7991
7992@item info locals [-q] [-t @var{type_regexp}] [@var{regexp}]
7993Like @kbd{info locals}, but only print the local variables selected
7994with the provided regexp(s).
7995
7996If @var{regexp} is provided, print only the local variables whose names
7997match the regular expression @var{regexp}.
7998
7999If @var{type_regexp} is provided, print only the local variables whose
8000types, as printed by the @code{whatis} command, match
8001the regular expression @var{type_regexp}.
8002If @var{type_regexp} contains space(s), it should be enclosed in
8003quote characters. If needed, use backslash to escape the meaning
8004of special characters or quotes.
8005
8006If both @var{regexp} and @var{type_regexp} are provided, a local variable
8007is printed only if its name matches @var{regexp} and its type matches
8008@var{type_regexp}.
8009
8010The command @kbd{info locals -q -t @var{type_regexp}} can usefully be
8011combined with the commands @kbd{frame apply} and @kbd{thread apply}.
8012For example, your program might use Resource Acquisition Is
8013Initialization types (RAII) such as @code{lock_something_t}: each
8014local variable of type @code{lock_something_t} automatically places a
8015lock that is destroyed when the variable goes out of scope. You can
8016then list all acquired locks in your program by doing
8017@smallexample
8018thread apply all -s frame apply all -s info locals -q -t lock_something_t
8019@end smallexample
8020@noindent
8021or the equivalent shorter form
8022@smallexample
8023tfaas i lo -q -t lock_something_t
8024@end smallexample
8025
c906108c
SS
8026@end table
8027
0a232300
PW
8028@node Frame Apply
8029@section Applying a Command to Several Frames.
8030@kindex frame apply
8031@cindex apply command to several frames
8032@table @code
8033@item frame apply [all | @var{count} | @var{-count} | level @var{level}@dots{}] [@var{flag}]@dots{} @var{command}
8034The @code{frame apply} command allows you to apply the named
8035@var{command} to one or more frames.
8036
8037@table @code
8038@item @code{all}
8039Specify @code{all} to apply @var{command} to all frames.
8040
8041@item @var{count}
8042Use @var{count} to apply @var{command} to the innermost @var{count}
8043frames, where @var{count} is a positive number.
8044
8045@item @var{-count}
8046Use @var{-count} to apply @var{command} to the outermost @var{count}
8047frames, where @var{count} is a positive number.
8048
8049@item @code{level}
8050Use @code{level} to apply @var{command} to the set of frames identified
8051by the @var{level} list. @var{level} is a frame level or a range of frame
8052levels as @var{level1}-@var{level2}. The frame level is the number shown
8053in the first field of the @samp{backtrace} command output.
8054E.g., @samp{2-4 6-8 3} indicates to apply @var{command} for the frames
8055at levels 2, 3, 4, 6, 7, 8, and then again on frame at level 3.
8056
8057@end table
8058
8059@end table
8060
8061Note that the frames on which @code{frame apply} applies a command are
8062also influenced by the @code{set backtrace} settings such as @code{set
8063backtrace past-main} and @code{set backtrace limit N}. See
8064@xref{Backtrace,,Backtraces}.
8065
8066The @var{flag} arguments control what output to produce and how to handle
8067errors raised when applying @var{command} to a frame. @var{flag}
8068must start with a @code{-} directly followed by one letter in
8069@code{qcs}. If several flags are provided, they must be given
8070individually, such as @code{-c -q}.
8071
8072By default, @value{GDBN} displays some frame information before the
8073output produced by @var{command}, and an error raised during the
8074execution of a @var{command} will abort @code{frame apply}. The
8075following flags can be used to fine-tune this behavior:
8076
8077@table @code
8078@item -c
8079The flag @code{-c}, which stands for @samp{continue}, causes any
8080errors in @var{command} to be displayed, and the execution of
8081@code{frame apply} then continues.
8082@item -s
8083The flag @code{-s}, which stands for @samp{silent}, causes any errors
8084or empty output produced by a @var{command} to be silently ignored.
8085That is, the execution continues, but the frame information and errors
8086are not printed.
8087@item -q
8088The flag @code{-q} (@samp{quiet}) disables printing the frame
8089information.
8090@end table
8091
8092The following example shows how the flags @code{-c} and @code{-s} are
8093working when applying the command @code{p j} to all frames, where
8094variable @code{j} can only be successfully printed in the outermost
8095@code{#1 main} frame.
8096
8097@smallexample
8098@group
8099(gdb) frame apply all p j
8100#0 some_function (i=5) at fun.c:4
8101No symbol "j" in current context.
8102(gdb) frame apply all -c p j
8103#0 some_function (i=5) at fun.c:4
8104No symbol "j" in current context.
8105#1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8106$1 = 5
8107(gdb) frame apply all -s p j
8108#1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8109$2 = 5
8110(gdb)
8111@end group
8112@end smallexample
8113
8114By default, @samp{frame apply}, prints the frame location
8115information before the command output:
8116
8117@smallexample
8118@group
8119(gdb) frame apply all p $sp
8120#0 some_function (i=5) at fun.c:4
8121$4 = (void *) 0xffffd1e0
8122#1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8123$5 = (void *) 0xffffd1f0
8124(gdb)
8125@end group
8126@end smallexample
8127
8128If flag @code{-q} is given, no frame information is printed:
8129@smallexample
8130@group
8131(gdb) frame apply all -q p $sp
8132$12 = (void *) 0xffffd1e0
8133$13 = (void *) 0xffffd1f0
8134(gdb)
8135@end group
8136@end smallexample
8137
8138@table @code
8139
8140@kindex faas
8141@cindex apply a command to all frames (ignoring errors and empty output)
8142@item faas @var{command}
8143Shortcut for @code{frame apply all -s @var{command}}.
8144Applies @var{command} on all frames, ignoring errors and empty output.
8145
8146It can for example be used to print a local variable or a function
8147argument without knowing the frame where this variable or argument
8148is, using:
8149@smallexample
8150(@value{GDBP}) faas p some_local_var_i_do_not_remember_where_it_is
8151@end smallexample
8152
8153Note that the command @code{tfaas @var{command}} applies @var{command}
8154on all frames of all threads. See @xref{Threads,,Threads}.
8155@end table
8156
8157
fc58fa65
AB
8158@node Frame Filter Management
8159@section Management of Frame Filters.
8160@cindex managing frame filters
8161
8162Frame filters are Python based utilities to manage and decorate the
8163output of frames. @xref{Frame Filter API}, for further information.
8164
8165Managing frame filters is performed by several commands available
8166within @value{GDBN}, detailed here.
8167
8168@table @code
8169@kindex info frame-filter
8170@item info frame-filter
8171Print a list of installed frame filters from all dictionaries, showing
8172their name, priority and enabled status.
8173
8174@kindex disable frame-filter
8175@anchor{disable frame-filter all}
8176@item disable frame-filter @var{filter-dictionary} @var{filter-name}
8177Disable a frame filter in the dictionary matching
8178@var{filter-dictionary} and @var{filter-name}. The
8179@var{filter-dictionary} may be @code{all}, @code{global},
8180@code{progspace}, or the name of the object file where the frame filter
8181dictionary resides. When @code{all} is specified, all frame filters
8182across all dictionaries are disabled. The @var{filter-name} is the name
8183of the frame filter and is used when @code{all} is not the option for
8184@var{filter-dictionary}. A disabled frame-filter is not deleted, it
8185may be enabled again later.
8186
8187@kindex enable frame-filter
8188@item enable frame-filter @var{filter-dictionary} @var{filter-name}
8189Enable a frame filter in the dictionary matching
8190@var{filter-dictionary} and @var{filter-name}. The
8191@var{filter-dictionary} may be @code{all}, @code{global},
8192@code{progspace} or the name of the object file where the frame filter
8193dictionary resides. When @code{all} is specified, all frame filters across
8194all dictionaries are enabled. The @var{filter-name} is the name of the frame
8195filter and is used when @code{all} is not the option for
8196@var{filter-dictionary}.
8197
8198Example:
8199
8200@smallexample
8201(gdb) info frame-filter
8202
8203global frame-filters:
8204 Priority Enabled Name
8205 1000 No PrimaryFunctionFilter
8206 100 Yes Reverse
8207
8208progspace /build/test frame-filters:
8209 Priority Enabled Name
8210 100 Yes ProgspaceFilter
8211
8212objfile /build/test frame-filters:
8213 Priority Enabled Name
8214 999 Yes BuildProgra Filter
8215
8216(gdb) disable frame-filter /build/test BuildProgramFilter
8217(gdb) info frame-filter
8218
8219global frame-filters:
8220 Priority Enabled Name
8221 1000 No PrimaryFunctionFilter
8222 100 Yes Reverse
8223
8224progspace /build/test frame-filters:
8225 Priority Enabled Name
8226 100 Yes ProgspaceFilter
8227
8228objfile /build/test frame-filters:
8229 Priority Enabled Name
8230 999 No BuildProgramFilter
8231
8232(gdb) enable frame-filter global PrimaryFunctionFilter
8233(gdb) info frame-filter
8234
8235global frame-filters:
8236 Priority Enabled Name
8237 1000 Yes PrimaryFunctionFilter
8238 100 Yes Reverse
8239
8240progspace /build/test frame-filters:
8241 Priority Enabled Name
8242 100 Yes ProgspaceFilter
8243
8244objfile /build/test frame-filters:
8245 Priority Enabled Name
8246 999 No BuildProgramFilter
8247@end smallexample
8248
8249@kindex set frame-filter priority
8250@item set frame-filter priority @var{filter-dictionary} @var{filter-name} @var{priority}
8251Set the @var{priority} of a frame filter in the dictionary matching
8252@var{filter-dictionary}, and the frame filter name matching
8253@var{filter-name}. The @var{filter-dictionary} may be @code{global},
8254@code{progspace} or the name of the object file where the frame filter
8255dictionary resides. The @var{priority} is an integer.
8256
8257@kindex show frame-filter priority
8258@item show frame-filter priority @var{filter-dictionary} @var{filter-name}
8259Show the @var{priority} of a frame filter in the dictionary matching
8260@var{filter-dictionary}, and the frame filter name matching
8261@var{filter-name}. The @var{filter-dictionary} may be @code{global},
8262@code{progspace} or the name of the object file where the frame filter
8263dictionary resides.
8264
8265Example:
8266
8267@smallexample
8268(gdb) info frame-filter
8269
8270global frame-filters:
8271 Priority Enabled Name
8272 1000 Yes PrimaryFunctionFilter
8273 100 Yes Reverse
8274
8275progspace /build/test frame-filters:
8276 Priority Enabled Name
8277 100 Yes ProgspaceFilter
8278
8279objfile /build/test frame-filters:
8280 Priority Enabled Name
8281 999 No BuildProgramFilter
8282
8283(gdb) set frame-filter priority global Reverse 50
8284(gdb) info frame-filter
8285
8286global frame-filters:
8287 Priority Enabled Name
8288 1000 Yes PrimaryFunctionFilter
8289 50 Yes Reverse
8290
8291progspace /build/test frame-filters:
8292 Priority Enabled Name
8293 100 Yes ProgspaceFilter
8294
8295objfile /build/test frame-filters:
8296 Priority Enabled Name
8297 999 No BuildProgramFilter
8298@end smallexample
8299@end table
c906108c 8300
6d2ebf8b 8301@node Source
c906108c
SS
8302@chapter Examining Source Files
8303
8304@value{GDBN} can print parts of your program's source, since the debugging
8305information recorded in the program tells @value{GDBN} what source files were
8306used to build it. When your program stops, @value{GDBN} spontaneously prints
8307the line where it stopped. Likewise, when you select a stack frame
79a6e687 8308(@pxref{Selection, ,Selecting a Frame}), @value{GDBN} prints the line where
c906108c
SS
8309execution in that frame has stopped. You can print other portions of
8310source files by explicit command.
8311
7a292a7a 8312If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
d4f3574e 8313prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
7a292a7a 8314@value{GDBN} under @sc{gnu} Emacs}.
c906108c
SS
8315
8316@menu
8317* List:: Printing source lines
2a25a5ba 8318* Specify Location:: How to specify code locations
87885426 8319* Edit:: Editing source files
c906108c 8320* Search:: Searching source files
c906108c
SS
8321* Source Path:: Specifying source directories
8322* Machine Code:: Source and machine code
8323@end menu
8324
6d2ebf8b 8325@node List
79a6e687 8326@section Printing Source Lines
c906108c
SS
8327
8328@kindex list
41afff9a 8329@kindex l @r{(@code{list})}
c906108c 8330To print lines from a source file, use the @code{list} command
5d161b24 8331(abbreviated @code{l}). By default, ten lines are printed.
2a25a5ba
EZ
8332There are several ways to specify what part of the file you want to
8333print; see @ref{Specify Location}, for the full list.
c906108c
SS
8334
8335Here are the forms of the @code{list} command most commonly used:
8336
8337@table @code
8338@item list @var{linenum}
8339Print lines centered around line number @var{linenum} in the
8340current source file.
8341
8342@item list @var{function}
8343Print lines centered around the beginning of function
8344@var{function}.
8345
8346@item list
8347Print more lines. If the last lines printed were printed with a
8348@code{list} command, this prints lines following the last lines
8349printed; however, if the last line printed was a solitary line printed
8350as part of displaying a stack frame (@pxref{Stack, ,Examining the
8351Stack}), this prints lines centered around that line.
8352
8353@item list -
8354Print lines just before the lines last printed.
8355@end table
8356
9c16f35a 8357@cindex @code{list}, how many lines to display
c906108c
SS
8358By default, @value{GDBN} prints ten source lines with any of these forms of
8359the @code{list} command. You can change this using @code{set listsize}:
8360
8361@table @code
8362@kindex set listsize
8363@item set listsize @var{count}
f81d1120 8364@itemx set listsize unlimited
c906108c
SS
8365Make the @code{list} command display @var{count} source lines (unless
8366the @code{list} argument explicitly specifies some other number).
f81d1120 8367Setting @var{count} to @code{unlimited} or 0 means there's no limit.
c906108c
SS
8368
8369@kindex show listsize
8370@item show listsize
8371Display the number of lines that @code{list} prints.
8372@end table
8373
8374Repeating a @code{list} command with @key{RET} discards the argument,
8375so it is equivalent to typing just @code{list}. This is more useful
8376than listing the same lines again. An exception is made for an
8377argument of @samp{-}; that argument is preserved in repetition so that
8378each repetition moves up in the source file.
8379
c906108c 8380In general, the @code{list} command expects you to supply zero, one or two
629500fa 8381@dfn{locations}. Locations specify source lines; there are several ways
2a25a5ba
EZ
8382of writing them (@pxref{Specify Location}), but the effect is always
8383to specify some source line.
8384
c906108c
SS
8385Here is a complete description of the possible arguments for @code{list}:
8386
8387@table @code
629500fa
KS
8388@item list @var{location}
8389Print lines centered around the line specified by @var{location}.
c906108c
SS
8390
8391@item list @var{first},@var{last}
8392Print lines from @var{first} to @var{last}. Both arguments are
629500fa
KS
8393locations. When a @code{list} command has two locations, and the
8394source file of the second location is omitted, this refers to
8395the same source file as the first location.
c906108c
SS
8396
8397@item list ,@var{last}
8398Print lines ending with @var{last}.
8399
8400@item list @var{first},
8401Print lines starting with @var{first}.
8402
8403@item list +
8404Print lines just after the lines last printed.
8405
8406@item list -
8407Print lines just before the lines last printed.
8408
8409@item list
8410As described in the preceding table.
8411@end table
8412
2a25a5ba
EZ
8413@node Specify Location
8414@section Specifying a Location
8415@cindex specifying location
629500fa
KS
8416@cindex location
8417@cindex source location
8418
8419@menu
8420* Linespec Locations:: Linespec locations
8421* Explicit Locations:: Explicit locations
8422* Address Locations:: Address locations
8423@end menu
c906108c 8424
2a25a5ba
EZ
8425Several @value{GDBN} commands accept arguments that specify a location
8426of your program's code. Since @value{GDBN} is a source-level
629500fa
KS
8427debugger, a location usually specifies some line in the source code.
8428Locations may be specified using three different formats:
8429linespec locations, explicit locations, or address locations.
c906108c 8430
629500fa
KS
8431@node Linespec Locations
8432@subsection Linespec Locations
8433@cindex linespec locations
8434
8435A @dfn{linespec} is a colon-separated list of source location parameters such
8436as file name, function name, etc. Here are all the different ways of
8437specifying a linespec:
c906108c 8438
2a25a5ba
EZ
8439@table @code
8440@item @var{linenum}
8441Specifies the line number @var{linenum} of the current source file.
c906108c 8442
2a25a5ba
EZ
8443@item -@var{offset}
8444@itemx +@var{offset}
8445Specifies the line @var{offset} lines before or after the @dfn{current
8446line}. For the @code{list} command, the current line is the last one
8447printed; for the breakpoint commands, this is the line at which
8448execution stopped in the currently selected @dfn{stack frame}
8449(@pxref{Frames, ,Frames}, for a description of stack frames.) When
8450used as the second of the two linespecs in a @code{list} command,
8451this specifies the line @var{offset} lines up or down from the first
8452linespec.
8453
8454@item @var{filename}:@var{linenum}
8455Specifies the line @var{linenum} in the source file @var{filename}.
4aac40c8
TT
8456If @var{filename} is a relative file name, then it will match any
8457source file name with the same trailing components. For example, if
8458@var{filename} is @samp{gcc/expr.c}, then it will match source file
8459name of @file{/build/trunk/gcc/expr.c}, but not
8460@file{/build/trunk/libcpp/expr.c} or @file{/build/trunk/gcc/x-expr.c}.
c906108c
SS
8461
8462@item @var{function}
8463Specifies the line that begins the body of the function @var{function}.
2a25a5ba 8464For example, in C, this is the line with the open brace.
c906108c 8465
a20714ff
PA
8466By default, in C@t{++} and Ada, @var{function} is interpreted as
8467specifying all functions named @var{function} in all scopes. For
8468C@t{++}, this means in all namespaces and classes. For Ada, this
8469means in all packages.
8470
8471For example, assuming a program with C@t{++} symbols named
8472@code{A::B::func} and @code{B::func}, both commands @w{@kbd{break
8473func}} and @w{@kbd{break B::func}} set a breakpoint on both symbols.
8474
8475Commands that accept a linespec let you override this with the
8476@code{-qualified} option. For example, @w{@kbd{break -qualified
8477func}} sets a breakpoint on a free-function named @code{func} ignoring
8478any C@t{++} class methods and namespace functions called @code{func}.
8479
8480@xref{Explicit Locations}.
8481
9ef07c8c
TT
8482@item @var{function}:@var{label}
8483Specifies the line where @var{label} appears in @var{function}.
8484
c906108c 8485@item @var{filename}:@var{function}
2a25a5ba
EZ
8486Specifies the line that begins the body of the function @var{function}
8487in the file @var{filename}. You only need the file name with a
8488function name to avoid ambiguity when there are identically named
8489functions in different source files.
c906108c 8490
0f5238ed 8491@item @var{label}
629500fa
KS
8492Specifies the line at which the label named @var{label} appears
8493in the function corresponding to the currently selected stack frame.
8494If there is no current selected stack frame (for instance, if the inferior
8495is not running), then @value{GDBN} will not search for a label.
8496
8497@cindex breakpoint at static probe point
8498@item -pstap|-probe-stap @r{[}@var{objfile}:@r{[}@var{provider}:@r{]}@r{]}@var{name}
8499The @sc{gnu}/Linux tool @code{SystemTap} provides a way for
8500applications to embed static probes. @xref{Static Probe Points}, for more
8501information on finding and using static probes. This form of linespec
8502specifies the location of such a static probe.
8503
8504If @var{objfile} is given, only probes coming from that shared library
8505or executable matching @var{objfile} as a regular expression are considered.
8506If @var{provider} is given, then only probes from that provider are considered.
8507If several probes match the spec, @value{GDBN} will insert a breakpoint at
8508each one of those probes.
8509@end table
8510
8511@node Explicit Locations
8512@subsection Explicit Locations
8513@cindex explicit locations
8514
8515@dfn{Explicit locations} allow the user to directly specify the source
8516location's parameters using option-value pairs.
8517
8518Explicit locations are useful when several functions, labels, or
8519file names have the same name (base name for files) in the program's
8520sources. In these cases, explicit locations point to the source
8521line you meant more accurately and unambiguously. Also, using
8522explicit locations might be faster in large programs.
8523
8524For example, the linespec @samp{foo:bar} may refer to a function @code{bar}
8525defined in the file named @file{foo} or the label @code{bar} in a function
8526named @code{foo}. @value{GDBN} must search either the file system or
8527the symbol table to know.
8528
8529The list of valid explicit location options is summarized in the
8530following table:
8531
8532@table @code
8533@item -source @var{filename}
8534The value specifies the source file name. To differentiate between
8535files with the same base name, prepend as many directories as is necessary
8536to uniquely identify the desired file, e.g., @file{foo/bar/baz.c}. Otherwise
8537@value{GDBN} will use the first file it finds with the given base
8538name. This option requires the use of either @code{-function} or @code{-line}.
8539
8540@item -function @var{function}
8541The value specifies the name of a function. Operations
8542on function locations unmodified by other options (such as @code{-label}
8543or @code{-line}) refer to the line that begins the body of the function.
8544In C, for example, this is the line with the open brace.
8545
a20714ff
PA
8546By default, in C@t{++} and Ada, @var{function} is interpreted as
8547specifying all functions named @var{function} in all scopes. For
8548C@t{++}, this means in all namespaces and classes. For Ada, this
8549means in all packages.
8550
8551For example, assuming a program with C@t{++} symbols named
8552@code{A::B::func} and @code{B::func}, both commands @w{@kbd{break
8553-function func}} and @w{@kbd{break -function B::func}} set a
8554breakpoint on both symbols.
8555
8556You can use the @kbd{-qualified} flag to override this (see below).
8557
8558@item -qualified
8559
8560This flag makes @value{GDBN} interpret a function name specified with
8561@kbd{-function} as a complete fully-qualified name.
8562
8563For example, assuming a C@t{++} program with symbols named
8564@code{A::B::func} and @code{B::func}, the @w{@kbd{break -qualified
8565-function B::func}} command sets a breakpoint on @code{B::func}, only.
8566
8567(Note: the @kbd{-qualified} option can precede a linespec as well
8568(@pxref{Linespec Locations}), so the particular example above could be
8569simplified as @w{@kbd{break -qualified B::func}}.)
8570
629500fa
KS
8571@item -label @var{label}
8572The value specifies the name of a label. When the function
8573name is not specified, the label is searched in the function of the currently
8574selected stack frame.
8575
8576@item -line @var{number}
8577The value specifies a line offset for the location. The offset may either
8578be absolute (@code{-line 3}) or relative (@code{-line +3}), depending on
8579the command. When specified without any other options, the line offset is
8580relative to the current line.
8581@end table
8582
8583Explicit location options may be abbreviated by omitting any non-unique
a20714ff 8584trailing characters from the option name, e.g., @w{@kbd{break -s main.c -li 3}}.
629500fa
KS
8585
8586@node Address Locations
8587@subsection Address Locations
8588@cindex address locations
8589
8590@dfn{Address locations} indicate a specific program address. They have
8591the generalized form *@var{address}.
8592
8593For line-oriented commands, such as @code{list} and @code{edit}, this
8594specifies a source line that contains @var{address}. For @code{break} and
8595other breakpoint-oriented commands, this can be used to set breakpoints in
2a25a5ba
EZ
8596parts of your program which do not have debugging information or
8597source files.
8598
8599Here @var{address} may be any expression valid in the current working
8600language (@pxref{Languages, working language}) that specifies a code
5fa54e5d 8601address. In addition, as a convenience, @value{GDBN} extends the
629500fa
KS
8602semantics of expressions used in locations to cover several situations
8603that frequently occur during debugging. Here are the various forms
5fa54e5d 8604of @var{address}:
2a25a5ba
EZ
8605
8606@table @code
8607@item @var{expression}
8608Any expression valid in the current working language.
8609
8610@item @var{funcaddr}
8611An address of a function or procedure derived from its name. In C,
9c37b5ae 8612C@t{++}, Objective-C, Fortran, minimal, and assembly, this is
2a25a5ba
EZ
8613simply the function's name @var{function} (and actually a special case
8614of a valid expression). In Pascal and Modula-2, this is
8615@code{&@var{function}}. In Ada, this is @code{@var{function}'Address}
8616(although the Pascal form also works).
8617
8618This form specifies the address of the function's first instruction,
8619before the stack frame and arguments have been set up.
8620
9a284c97 8621@item '@var{filename}':@var{funcaddr}
2a25a5ba
EZ
8622Like @var{funcaddr} above, but also specifies the name of the source
8623file explicitly. This is useful if the name of the function does not
8624specify the function unambiguously, e.g., if there are several
8625functions with identical names in different source files.
c906108c
SS
8626@end table
8627
87885426 8628@node Edit
79a6e687 8629@section Editing Source Files
87885426
FN
8630@cindex editing source files
8631
8632@kindex edit
8633@kindex e @r{(@code{edit})}
8634To edit the lines in a source file, use the @code{edit} command.
8635The editing program of your choice
8636is invoked with the current line set to
8637the active line in the program.
8638Alternatively, there are several ways to specify what part of the file you
2a25a5ba 8639want to print if you want to see other parts of the program:
87885426
FN
8640
8641@table @code
2a25a5ba
EZ
8642@item edit @var{location}
8643Edit the source file specified by @code{location}. Editing starts at
8644that @var{location}, e.g., at the specified source line of the
8645specified file. @xref{Specify Location}, for all the possible forms
8646of the @var{location} argument; here are the forms of the @code{edit}
8647command most commonly used:
87885426 8648
2a25a5ba 8649@table @code
87885426
FN
8650@item edit @var{number}
8651Edit the current source file with @var{number} as the active line number.
8652
8653@item edit @var{function}
8654Edit the file containing @var{function} at the beginning of its definition.
2a25a5ba 8655@end table
87885426 8656
87885426
FN
8657@end table
8658
79a6e687 8659@subsection Choosing your Editor
87885426
FN
8660You can customize @value{GDBN} to use any editor you want
8661@footnote{
8662The only restriction is that your editor (say @code{ex}), recognizes the
8663following command-line syntax:
10998722 8664@smallexample
87885426 8665ex +@var{number} file
10998722 8666@end smallexample
15387254
EZ
8667The optional numeric value +@var{number} specifies the number of the line in
8668the file where to start editing.}.
8669By default, it is @file{@value{EDITOR}}, but you can change this
10998722
AC
8670by setting the environment variable @code{EDITOR} before using
8671@value{GDBN}. For example, to configure @value{GDBN} to use the
8672@code{vi} editor, you could use these commands with the @code{sh} shell:
8673@smallexample
87885426
FN
8674EDITOR=/usr/bin/vi
8675export EDITOR
15387254 8676gdb @dots{}
10998722 8677@end smallexample
87885426 8678or in the @code{csh} shell,
10998722 8679@smallexample
87885426 8680setenv EDITOR /usr/bin/vi
15387254 8681gdb @dots{}
10998722 8682@end smallexample
87885426 8683
6d2ebf8b 8684@node Search
79a6e687 8685@section Searching Source Files
15387254 8686@cindex searching source files
c906108c
SS
8687
8688There are two commands for searching through the current source file for a
8689regular expression.
8690
8691@table @code
8692@kindex search
8693@kindex forward-search
1e96de83 8694@kindex fo @r{(@code{forward-search})}
c906108c
SS
8695@item forward-search @var{regexp}
8696@itemx search @var{regexp}
8697The command @samp{forward-search @var{regexp}} checks each line,
8698starting with the one following the last line listed, for a match for
5d161b24 8699@var{regexp}. It lists the line that is found. You can use the
c906108c
SS
8700synonym @samp{search @var{regexp}} or abbreviate the command name as
8701@code{fo}.
8702
09d4efe1 8703@kindex reverse-search
c906108c
SS
8704@item reverse-search @var{regexp}
8705The command @samp{reverse-search @var{regexp}} checks each line, starting
8706with the one before the last line listed and going backward, for a match
8707for @var{regexp}. It lists the line that is found. You can abbreviate
8708this command as @code{rev}.
8709@end table
c906108c 8710
6d2ebf8b 8711@node Source Path
79a6e687 8712@section Specifying Source Directories
c906108c
SS
8713
8714@cindex source path
8715@cindex directories for source files
8716Executable programs sometimes do not record the directories of the source
8717files from which they were compiled, just the names. Even when they do,
8718the directories could be moved between the compilation and your debugging
8719session. @value{GDBN} has a list of directories to search for source files;
8720this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
8721it tries all the directories in the list, in the order they are present
0b66e38c
EZ
8722in the list, until it finds a file with the desired name.
8723
8724For example, suppose an executable references the file
8725@file{/usr/src/foo-1.0/lib/foo.c}, and our source path is
8726@file{/mnt/cross}. The file is first looked up literally; if this
8727fails, @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c} is tried; if this
8728fails, @file{/mnt/cross/foo.c} is opened; if this fails, an error
8729message is printed. @value{GDBN} does not look up the parts of the
8730source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
8731Likewise, the subdirectories of the source path are not searched: if
8732the source path is @file{/mnt/cross}, and the binary refers to
8733@file{foo.c}, @value{GDBN} would not find it under
8734@file{/mnt/cross/usr/src/foo-1.0/lib}.
8735
8736Plain file names, relative file names with leading directories, file
8737names containing dots, etc.@: are all treated as described above; for
8738instance, if the source path is @file{/mnt/cross}, and the source file
8739is recorded as @file{../lib/foo.c}, @value{GDBN} would first try
8740@file{../lib/foo.c}, then @file{/mnt/cross/../lib/foo.c}, and after
8741that---@file{/mnt/cross/foo.c}.
8742
8743Note that the executable search path is @emph{not} used to locate the
cd852561 8744source files.
c906108c
SS
8745
8746Whenever you reset or rearrange the source path, @value{GDBN} clears out
8747any information it has cached about where source files are found and where
8748each line is in the file.
8749
8750@kindex directory
8751@kindex dir
d4f3574e
SS
8752When you start @value{GDBN}, its source path includes only @samp{cdir}
8753and @samp{cwd}, in that order.
c906108c
SS
8754To add other directories, use the @code{directory} command.
8755
4b505b12
AS
8756The search path is used to find both program source files and @value{GDBN}
8757script files (read using the @samp{-command} option and @samp{source} command).
8758
30daae6c
JB
8759In addition to the source path, @value{GDBN} provides a set of commands
8760that manage a list of source path substitution rules. A @dfn{substitution
8761rule} specifies how to rewrite source directories stored in the program's
8762debug information in case the sources were moved to a different
8763directory between compilation and debugging. A rule is made of
8764two strings, the first specifying what needs to be rewritten in
8765the path, and the second specifying how it should be rewritten.
8766In @ref{set substitute-path}, we name these two parts @var{from} and
8767@var{to} respectively. @value{GDBN} does a simple string replacement
8768of @var{from} with @var{to} at the start of the directory part of the
8769source file name, and uses that result instead of the original file
8770name to look up the sources.
8771
8772Using the previous example, suppose the @file{foo-1.0} tree has been
8773moved from @file{/usr/src} to @file{/mnt/cross}, then you can tell
3f94c067 8774@value{GDBN} to replace @file{/usr/src} in all source path names with
30daae6c
JB
8775@file{/mnt/cross}. The first lookup will then be
8776@file{/mnt/cross/foo-1.0/lib/foo.c} in place of the original location
8777of @file{/usr/src/foo-1.0/lib/foo.c}. To define a source path
8778substitution rule, use the @code{set substitute-path} command
8779(@pxref{set substitute-path}).
8780
8781To avoid unexpected substitution results, a rule is applied only if the
8782@var{from} part of the directory name ends at a directory separator.
8783For instance, a rule substituting @file{/usr/source} into
8784@file{/mnt/cross} will be applied to @file{/usr/source/foo-1.0} but
8785not to @file{/usr/sourceware/foo-2.0}. And because the substitution
d3e8051b 8786is applied only at the beginning of the directory name, this rule will
30daae6c
JB
8787not be applied to @file{/root/usr/source/baz.c} either.
8788
8789In many cases, you can achieve the same result using the @code{directory}
8790command. However, @code{set substitute-path} can be more efficient in
8791the case where the sources are organized in a complex tree with multiple
8792subdirectories. With the @code{directory} command, you need to add each
8793subdirectory of your project. If you moved the entire tree while
8794preserving its internal organization, then @code{set substitute-path}
8795allows you to direct the debugger to all the sources with one single
8796command.
8797
8798@code{set substitute-path} is also more than just a shortcut command.
8799The source path is only used if the file at the original location no
8800longer exists. On the other hand, @code{set substitute-path} modifies
8801the debugger behavior to look at the rewritten location instead. So, if
8802for any reason a source file that is not relevant to your executable is
8803located at the original location, a substitution rule is the only
3f94c067 8804method available to point @value{GDBN} at the new location.
30daae6c 8805
29b0e8a2
JM
8806@cindex @samp{--with-relocated-sources}
8807@cindex default source path substitution
8808You can configure a default source path substitution rule by
8809configuring @value{GDBN} with the
8810@samp{--with-relocated-sources=@var{dir}} option. The @var{dir}
8811should be the name of a directory under @value{GDBN}'s configured
8812prefix (set with @samp{--prefix} or @samp{--exec-prefix}), and
8813directory names in debug information under @var{dir} will be adjusted
8814automatically if the installed @value{GDBN} is moved to a new
8815location. This is useful if @value{GDBN}, libraries or executables
8816with debug information and corresponding source code are being moved
8817together.
8818
c906108c
SS
8819@table @code
8820@item directory @var{dirname} @dots{}
8821@item dir @var{dirname} @dots{}
8822Add directory @var{dirname} to the front of the source path. Several
d4f3574e
SS
8823directory names may be given to this command, separated by @samp{:}
8824(@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
8825part of absolute file names) or
c906108c
SS
8826whitespace. You may specify a directory that is already in the source
8827path; this moves it forward, so @value{GDBN} searches it sooner.
8828
8829@kindex cdir
8830@kindex cwd
41afff9a 8831@vindex $cdir@r{, convenience variable}
d3e8051b 8832@vindex $cwd@r{, convenience variable}
c906108c
SS
8833@cindex compilation directory
8834@cindex current directory
8835@cindex working directory
8836@cindex directory, current
8837@cindex directory, compilation
8838You can use the string @samp{$cdir} to refer to the compilation
8839directory (if one is recorded), and @samp{$cwd} to refer to the current
8840working directory. @samp{$cwd} is not the same as @samp{.}---the former
8841tracks the current working directory as it changes during your @value{GDBN}
8842session, while the latter is immediately expanded to the current
8843directory at the time you add an entry to the source path.
8844
8845@item directory
cd852561 8846Reset the source path to its default value (@samp{$cdir:$cwd} on Unix systems). This requires confirmation.
c906108c
SS
8847
8848@c RET-repeat for @code{directory} is explicitly disabled, but since
8849@c repeating it would be a no-op we do not say that. (thanks to RMS)
8850
99e7ae30
DE
8851@item set directories @var{path-list}
8852@kindex set directories
8853Set the source path to @var{path-list}.
8854@samp{$cdir:$cwd} are added if missing.
8855
c906108c
SS
8856@item show directories
8857@kindex show directories
8858Print the source path: show which directories it contains.
30daae6c
JB
8859
8860@anchor{set substitute-path}
8861@item set substitute-path @var{from} @var{to}
8862@kindex set substitute-path
8863Define a source path substitution rule, and add it at the end of the
8864current list of existing substitution rules. If a rule with the same
8865@var{from} was already defined, then the old rule is also deleted.
8866
8867For example, if the file @file{/foo/bar/baz.c} was moved to
8868@file{/mnt/cross/baz.c}, then the command
8869
8870@smallexample
c58b006b 8871(@value{GDBP}) set substitute-path /foo/bar /mnt/cross
30daae6c
JB
8872@end smallexample
8873
8874@noindent
c58b006b 8875will tell @value{GDBN} to replace @samp{/foo/bar} with
30daae6c
JB
8876@samp{/mnt/cross}, which will allow @value{GDBN} to find the file
8877@file{baz.c} even though it was moved.
8878
8879In the case when more than one substitution rule have been defined,
8880the rules are evaluated one by one in the order where they have been
8881defined. The first one matching, if any, is selected to perform
8882the substitution.
8883
8884For instance, if we had entered the following commands:
8885
8886@smallexample
8887(@value{GDBP}) set substitute-path /usr/src/include /mnt/include
8888(@value{GDBP}) set substitute-path /usr/src /mnt/src
8889@end smallexample
8890
8891@noindent
8892@value{GDBN} would then rewrite @file{/usr/src/include/defs.h} into
8893@file{/mnt/include/defs.h} by using the first rule. However, it would
8894use the second rule to rewrite @file{/usr/src/lib/foo.c} into
8895@file{/mnt/src/lib/foo.c}.
8896
8897
8898@item unset substitute-path [path]
8899@kindex unset substitute-path
8900If a path is specified, search the current list of substitution rules
8901for a rule that would rewrite that path. Delete that rule if found.
8902A warning is emitted by the debugger if no rule could be found.
8903
8904If no path is specified, then all substitution rules are deleted.
8905
8906@item show substitute-path [path]
8907@kindex show substitute-path
8908If a path is specified, then print the source path substitution rule
8909which would rewrite that path, if any.
8910
8911If no path is specified, then print all existing source path substitution
8912rules.
8913
c906108c
SS
8914@end table
8915
8916If your source path is cluttered with directories that are no longer of
8917interest, @value{GDBN} may sometimes cause confusion by finding the wrong
8918versions of source. You can correct the situation as follows:
8919
8920@enumerate
8921@item
cd852561 8922Use @code{directory} with no argument to reset the source path to its default value.
c906108c
SS
8923
8924@item
8925Use @code{directory} with suitable arguments to reinstall the
8926directories you want in the source path. You can add all the
8927directories in one command.
8928@end enumerate
8929
6d2ebf8b 8930@node Machine Code
79a6e687 8931@section Source and Machine Code
15387254 8932@cindex source line and its code address
c906108c
SS
8933
8934You can use the command @code{info line} to map source lines to program
8935addresses (and vice versa), and the command @code{disassemble} to display
91440f57
HZ
8936a range of addresses as machine instructions. You can use the command
8937@code{set disassemble-next-line} to set whether to disassemble next
8938source line when execution stops. When run under @sc{gnu} Emacs
d4f3574e 8939mode, the @code{info line} command causes the arrow to point to the
5d161b24 8940line specified. Also, @code{info line} prints addresses in symbolic form as
c906108c
SS
8941well as hex.
8942
8943@table @code
8944@kindex info line
db1ae9c5
AB
8945@item info line
8946@itemx info line @var{location}
c906108c 8947Print the starting and ending addresses of the compiled code for
629500fa 8948source line @var{location}. You can specify source lines in any of
db1ae9c5
AB
8949the ways documented in @ref{Specify Location}. With no @var{location}
8950information about the current source line is printed.
c906108c
SS
8951@end table
8952
8953For example, we can use @code{info line} to discover the location of
8954the object code for the first line of function
8955@code{m4_changequote}:
8956
8957@smallexample
96a2c332 8958(@value{GDBP}) info line m4_changequote
db1ae9c5
AB
8959Line 895 of "builtin.c" starts at pc 0x634c <m4_changequote> and \
8960 ends at 0x6350 <m4_changequote+4>.
c906108c
SS
8961@end smallexample
8962
8963@noindent
15387254 8964@cindex code address and its source line
c906108c 8965We can also inquire (using @code{*@var{addr}} as the form for
629500fa 8966@var{location}) what source line covers a particular address:
c906108c
SS
8967@smallexample
8968(@value{GDBP}) info line *0x63ff
db1ae9c5
AB
8969Line 926 of "builtin.c" starts at pc 0x63e4 <m4_changequote+152> and \
8970 ends at 0x6404 <m4_changequote+184>.
c906108c
SS
8971@end smallexample
8972
8973@cindex @code{$_} and @code{info line}
15387254 8974@cindex @code{x} command, default address
41afff9a 8975@kindex x@r{(examine), and} info line
c906108c
SS
8976After @code{info line}, the default address for the @code{x} command
8977is changed to the starting address of the line, so that @samp{x/i} is
8978sufficient to begin examining the machine code (@pxref{Memory,
79a6e687 8979,Examining Memory}). Also, this address is saved as the value of the
c906108c 8980convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
79a6e687 8981Variables}).
c906108c 8982
db1ae9c5
AB
8983@cindex info line, repeated calls
8984After @code{info line}, using @code{info line} again without
8985specifying a location will display information about the next source
8986line.
8987
c906108c
SS
8988@table @code
8989@kindex disassemble
8990@cindex assembly instructions
8991@cindex instructions, assembly
8992@cindex machine instructions
8993@cindex listing machine instructions
8994@item disassemble
d14508fe 8995@itemx disassemble /m
6ff0ba5f 8996@itemx disassemble /s
9b117ef3 8997@itemx disassemble /r
c906108c 8998This specialized command dumps a range of memory as machine
d14508fe 8999instructions. It can also print mixed source+disassembly by specifying
6ff0ba5f
DE
9000the @code{/m} or @code{/s} modifier and print the raw instructions in hex
9001as well as in symbolic form by specifying the @code{/r} modifier.
d14508fe 9002The default memory range is the function surrounding the
c906108c
SS
9003program counter of the selected frame. A single argument to this
9004command is a program counter value; @value{GDBN} dumps the function
21a0512e
PP
9005surrounding this value. When two arguments are given, they should
9006be separated by a comma, possibly surrounded by whitespace. The
53a71c06
CR
9007arguments specify a range of addresses to dump, in one of two forms:
9008
9009@table @code
9010@item @var{start},@var{end}
9011the addresses from @var{start} (inclusive) to @var{end} (exclusive)
9012@item @var{start},+@var{length}
9013the addresses from @var{start} (inclusive) to
9014@code{@var{start}+@var{length}} (exclusive).
9015@end table
9016
9017@noindent
9018When 2 arguments are specified, the name of the function is also
9019printed (since there could be several functions in the given range).
21a0512e
PP
9020
9021The argument(s) can be any expression yielding a numeric value, such as
9022@samp{0x32c4}, @samp{&main+10} or @samp{$pc - 8}.
2b28d209
PP
9023
9024If the range of memory being disassembled contains current program counter,
9025the instruction at that location is shown with a @code{=>} marker.
c906108c
SS
9026@end table
9027
c906108c
SS
9028The following example shows the disassembly of a range of addresses of
9029HP PA-RISC 2.0 code:
9030
9031@smallexample
21a0512e 9032(@value{GDBP}) disas 0x32c4, 0x32e4
c906108c 9033Dump of assembler code from 0x32c4 to 0x32e4:
2b28d209
PP
9034 0x32c4 <main+204>: addil 0,dp
9035 0x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
9036 0x32cc <main+212>: ldil 0x3000,r31
9037 0x32d0 <main+216>: ble 0x3f8(sr4,r31)
9038 0x32d4 <main+220>: ldo 0(r31),rp
9039 0x32d8 <main+224>: addil -0x800,dp
9040 0x32dc <main+228>: ldo 0x588(r1),r26
9041 0x32e0 <main+232>: ldil 0x3000,r31
c906108c
SS
9042End of assembler dump.
9043@end smallexample
c906108c 9044
6ff0ba5f
DE
9045Here is an example showing mixed source+assembly for Intel x86
9046with @code{/m} or @code{/s}, when the program is stopped just after
9047function prologue in a non-optimized function with no inline code.
d14508fe
DE
9048
9049@smallexample
9050(@value{GDBP}) disas /m main
9051Dump of assembler code for function main:
90525 @{
9c419145
PP
9053 0x08048330 <+0>: push %ebp
9054 0x08048331 <+1>: mov %esp,%ebp
9055 0x08048333 <+3>: sub $0x8,%esp
9056 0x08048336 <+6>: and $0xfffffff0,%esp
9057 0x08048339 <+9>: sub $0x10,%esp
d14508fe
DE
9058
90596 printf ("Hello.\n");
9c419145
PP
9060=> 0x0804833c <+12>: movl $0x8048440,(%esp)
9061 0x08048343 <+19>: call 0x8048284 <puts@@plt>
d14508fe
DE
9062
90637 return 0;
90648 @}
9c419145
PP
9065 0x08048348 <+24>: mov $0x0,%eax
9066 0x0804834d <+29>: leave
9067 0x0804834e <+30>: ret
d14508fe
DE
9068
9069End of assembler dump.
9070@end smallexample
9071
6ff0ba5f
DE
9072The @code{/m} option is deprecated as its output is not useful when
9073there is either inlined code or re-ordered code.
9074The @code{/s} option is the preferred choice.
9075Here is an example for AMD x86-64 showing the difference between
9076@code{/m} output and @code{/s} output.
9077This example has one inline function defined in a header file,
9078and the code is compiled with @samp{-O2} optimization.
9079Note how the @code{/m} output is missing the disassembly of
9080several instructions that are present in the @code{/s} output.
9081
9082@file{foo.h}:
9083
9084@smallexample
9085int
9086foo (int a)
9087@{
9088 if (a < 0)
9089 return a * 2;
9090 if (a == 0)
9091 return 1;
9092 return a + 10;
9093@}
9094@end smallexample
9095
9096@file{foo.c}:
9097
9098@smallexample
9099#include "foo.h"
9100volatile int x, y;
9101int
9102main ()
9103@{
9104 x = foo (y);
9105 return 0;
9106@}
9107@end smallexample
9108
9109@smallexample
9110(@value{GDBP}) disas /m main
9111Dump of assembler code for function main:
91125 @{
9113
91146 x = foo (y);
9115 0x0000000000400400 <+0>: mov 0x200c2e(%rip),%eax # 0x601034 <y>
9116 0x0000000000400417 <+23>: mov %eax,0x200c13(%rip) # 0x601030 <x>
9117
91187 return 0;
91198 @}
9120 0x000000000040041d <+29>: xor %eax,%eax
9121 0x000000000040041f <+31>: retq
9122 0x0000000000400420 <+32>: add %eax,%eax
9123 0x0000000000400422 <+34>: jmp 0x400417 <main+23>
9124
9125End of assembler dump.
9126(@value{GDBP}) disas /s main
9127Dump of assembler code for function main:
9128foo.c:
91295 @{
91306 x = foo (y);
9131 0x0000000000400400 <+0>: mov 0x200c2e(%rip),%eax # 0x601034 <y>
9132
9133foo.h:
91344 if (a < 0)
9135 0x0000000000400406 <+6>: test %eax,%eax
9136 0x0000000000400408 <+8>: js 0x400420 <main+32>
9137
91386 if (a == 0)
91397 return 1;
91408 return a + 10;
9141 0x000000000040040a <+10>: lea 0xa(%rax),%edx
9142 0x000000000040040d <+13>: test %eax,%eax
9143 0x000000000040040f <+15>: mov $0x1,%eax
9144 0x0000000000400414 <+20>: cmovne %edx,%eax
9145
9146foo.c:
91476 x = foo (y);
9148 0x0000000000400417 <+23>: mov %eax,0x200c13(%rip) # 0x601030 <x>
9149
91507 return 0;
91518 @}
9152 0x000000000040041d <+29>: xor %eax,%eax
9153 0x000000000040041f <+31>: retq
9154
9155foo.h:
91565 return a * 2;
9157 0x0000000000400420 <+32>: add %eax,%eax
9158 0x0000000000400422 <+34>: jmp 0x400417 <main+23>
9159End of assembler dump.
9160@end smallexample
9161
53a71c06
CR
9162Here is another example showing raw instructions in hex for AMD x86-64,
9163
9164@smallexample
9165(gdb) disas /r 0x400281,+10
9166Dump of assembler code from 0x400281 to 0x40028b:
9167 0x0000000000400281: 38 36 cmp %dh,(%rsi)
9168 0x0000000000400283: 2d 36 34 2e 73 sub $0x732e3436,%eax
9169 0x0000000000400288: 6f outsl %ds:(%rsi),(%dx)
9170 0x0000000000400289: 2e 32 00 xor %cs:(%rax),%al
9171End of assembler dump.
9172@end smallexample
9173
629500fa 9174Addresses cannot be specified as a location (@pxref{Specify Location}).
7e1e0340
DE
9175So, for example, if you want to disassemble function @code{bar}
9176in file @file{foo.c}, you must type @samp{disassemble 'foo.c'::bar}
9177and not @samp{disassemble foo.c:bar}.
9178
c906108c
SS
9179Some architectures have more than one commonly-used set of instruction
9180mnemonics or other syntax.
9181
76d17f34
EZ
9182For programs that were dynamically linked and use shared libraries,
9183instructions that call functions or branch to locations in the shared
9184libraries might show a seemingly bogus location---it's actually a
9185location of the relocation table. On some architectures, @value{GDBN}
9186might be able to resolve these to actual function names.
9187
65b48a81
PB
9188@table @code
9189@kindex set disassembler-options
9190@cindex disassembler options
9191@item set disassembler-options @var{option1}[,@var{option2}@dots{}]
9192This command controls the passing of target specific information to
9193the disassembler. For a list of valid options, please refer to the
9194@code{-M}/@code{--disassembler-options} section of the @samp{objdump}
9195manual and/or the output of @kbd{objdump --help}
f5a476a7 9196(@pxref{objdump,,objdump,binutils,The GNU Binary Utilities}).
65b48a81
PB
9197The default value is the empty string.
9198
9199If it is necessary to specify more than one disassembler option, then
9200multiple options can be placed together into a comma separated list.
471b9d15 9201Currently this command is only supported on targets ARM, MIPS, PowerPC
65b48a81
PB
9202and S/390.
9203
9204@kindex show disassembler-options
9205@item show disassembler-options
9206Show the current setting of the disassembler options.
9207@end table
9208
c906108c 9209@table @code
d4f3574e 9210@kindex set disassembly-flavor
d4f3574e
SS
9211@cindex Intel disassembly flavor
9212@cindex AT&T disassembly flavor
9213@item set disassembly-flavor @var{instruction-set}
c906108c
SS
9214Select the instruction set to use when disassembling the
9215program via the @code{disassemble} or @code{x/i} commands.
9216
9217Currently this command is only defined for the Intel x86 family. You
d4f3574e
SS
9218can set @var{instruction-set} to either @code{intel} or @code{att}.
9219The default is @code{att}, the AT&T flavor used by default by Unix
9220assemblers for x86-based targets.
9c16f35a
EZ
9221
9222@kindex show disassembly-flavor
9223@item show disassembly-flavor
9224Show the current setting of the disassembly flavor.
c906108c
SS
9225@end table
9226
91440f57
HZ
9227@table @code
9228@kindex set disassemble-next-line
9229@kindex show disassemble-next-line
9230@item set disassemble-next-line
9231@itemx show disassemble-next-line
32ae1842
EZ
9232Control whether or not @value{GDBN} will disassemble the next source
9233line or instruction when execution stops. If ON, @value{GDBN} will
9234display disassembly of the next source line when execution of the
9235program being debugged stops. This is @emph{in addition} to
9236displaying the source line itself, which @value{GDBN} always does if
9237possible. If the next source line cannot be displayed for some reason
9238(e.g., if @value{GDBN} cannot find the source file, or there's no line
9239info in the debug info), @value{GDBN} will display disassembly of the
9240next @emph{instruction} instead of showing the next source line. If
9241AUTO, @value{GDBN} will display disassembly of next instruction only
9242if the source line cannot be displayed. This setting causes
9243@value{GDBN} to display some feedback when you step through a function
9244with no line info or whose source file is unavailable. The default is
9245OFF, which means never display the disassembly of the next line or
9246instruction.
91440f57
HZ
9247@end table
9248
c906108c 9249
6d2ebf8b 9250@node Data
c906108c
SS
9251@chapter Examining Data
9252
9253@cindex printing data
9254@cindex examining data
9255@kindex print
9256@kindex inspect
c906108c 9257The usual way to examine data in your program is with the @code{print}
7a292a7a
SS
9258command (abbreviated @code{p}), or its synonym @code{inspect}. It
9259evaluates and prints the value of an expression of the language your
9260program is written in (@pxref{Languages, ,Using @value{GDBN} with
78e2826b
TT
9261Different Languages}). It may also print the expression using a
9262Python-based pretty-printer (@pxref{Pretty Printing}).
c906108c
SS
9263
9264@table @code
d4f3574e
SS
9265@item print @var{expr}
9266@itemx print /@var{f} @var{expr}
9267@var{expr} is an expression (in the source language). By default the
9268value of @var{expr} is printed in a format appropriate to its data type;
c906108c 9269you can choose a different format by specifying @samp{/@var{f}}, where
d4f3574e 9270@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
79a6e687 9271Formats}.
c906108c
SS
9272
9273@item print
9274@itemx print /@var{f}
15387254 9275@cindex reprint the last value
d4f3574e 9276If you omit @var{expr}, @value{GDBN} displays the last value again (from the
79a6e687 9277@dfn{value history}; @pxref{Value History, ,Value History}). This allows you to
c906108c
SS
9278conveniently inspect the same value in an alternative format.
9279@end table
9280
9281A more low-level way of examining data is with the @code{x} command.
9282It examines data in memory at a specified address and prints it in a
79a6e687 9283specified format. @xref{Memory, ,Examining Memory}.
c906108c 9284
7a292a7a 9285If you are interested in information about types, or about how the
d4f3574e
SS
9286fields of a struct or a class are declared, use the @code{ptype @var{exp}}
9287command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
7a292a7a 9288Table}.
c906108c 9289
06fc020f
SCR
9290@cindex exploring hierarchical data structures
9291@kindex explore
9292Another way of examining values of expressions and type information is
9293through the Python extension command @code{explore} (available only if
9294the @value{GDBN} build is configured with @code{--with-python}). It
9295offers an interactive way to start at the highest level (or, the most
9296abstract level) of the data type of an expression (or, the data type
9297itself) and explore all the way down to leaf scalar values/fields
9298embedded in the higher level data types.
9299
9300@table @code
9301@item explore @var{arg}
9302@var{arg} is either an expression (in the source language), or a type
9303visible in the current context of the program being debugged.
9304@end table
9305
9306The working of the @code{explore} command can be illustrated with an
9307example. If a data type @code{struct ComplexStruct} is defined in your
9308C program as
9309
9310@smallexample
9311struct SimpleStruct
9312@{
9313 int i;
9314 double d;
9315@};
9316
9317struct ComplexStruct
9318@{
9319 struct SimpleStruct *ss_p;
9320 int arr[10];
9321@};
9322@end smallexample
9323
9324@noindent
9325followed by variable declarations as
9326
9327@smallexample
9328struct SimpleStruct ss = @{ 10, 1.11 @};
9329struct ComplexStruct cs = @{ &ss, @{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 @} @};
9330@end smallexample
9331
9332@noindent
9333then, the value of the variable @code{cs} can be explored using the
9334@code{explore} command as follows.
9335
9336@smallexample
9337(gdb) explore cs
9338The value of `cs' is a struct/class of type `struct ComplexStruct' with
9339the following fields:
9340
9341 ss_p = <Enter 0 to explore this field of type `struct SimpleStruct *'>
9342 arr = <Enter 1 to explore this field of type `int [10]'>
9343
9344Enter the field number of choice:
9345@end smallexample
9346
9347@noindent
9348Since the fields of @code{cs} are not scalar values, you are being
9349prompted to chose the field you want to explore. Let's say you choose
9350the field @code{ss_p} by entering @code{0}. Then, since this field is a
9351pointer, you will be asked if it is pointing to a single value. From
9352the declaration of @code{cs} above, it is indeed pointing to a single
9353value, hence you enter @code{y}. If you enter @code{n}, then you will
9354be asked if it were pointing to an array of values, in which case this
9355field will be explored as if it were an array.
9356
9357@smallexample
9358`cs.ss_p' is a pointer to a value of type `struct SimpleStruct'
9359Continue exploring it as a pointer to a single value [y/n]: y
9360The value of `*(cs.ss_p)' is a struct/class of type `struct
9361SimpleStruct' with the following fields:
9362
9363 i = 10 .. (Value of type `int')
9364 d = 1.1100000000000001 .. (Value of type `double')
9365
9366Press enter to return to parent value:
9367@end smallexample
9368
9369@noindent
9370If the field @code{arr} of @code{cs} was chosen for exploration by
9371entering @code{1} earlier, then since it is as array, you will be
9372prompted to enter the index of the element in the array that you want
9373to explore.
9374
9375@smallexample
9376`cs.arr' is an array of `int'.
9377Enter the index of the element you want to explore in `cs.arr': 5
9378
9379`(cs.arr)[5]' is a scalar value of type `int'.
9380
9381(cs.arr)[5] = 4
9382
9383Press enter to return to parent value:
9384@end smallexample
9385
9386In general, at any stage of exploration, you can go deeper towards the
9387leaf values by responding to the prompts appropriately, or hit the
9388return key to return to the enclosing data structure (the @i{higher}
9389level data structure).
9390
9391Similar to exploring values, you can use the @code{explore} command to
9392explore types. Instead of specifying a value (which is typically a
9393variable name or an expression valid in the current context of the
9394program being debugged), you specify a type name. If you consider the
9395same example as above, your can explore the type
9396@code{struct ComplexStruct} by passing the argument
9397@code{struct ComplexStruct} to the @code{explore} command.
9398
9399@smallexample
9400(gdb) explore struct ComplexStruct
9401@end smallexample
9402
9403@noindent
9404By responding to the prompts appropriately in the subsequent interactive
9405session, you can explore the type @code{struct ComplexStruct} in a
9406manner similar to how the value @code{cs} was explored in the above
9407example.
9408
9409The @code{explore} command also has two sub-commands,
9410@code{explore value} and @code{explore type}. The former sub-command is
9411a way to explicitly specify that value exploration of the argument is
9412being invoked, while the latter is a way to explicitly specify that type
9413exploration of the argument is being invoked.
9414
9415@table @code
9416@item explore value @var{expr}
9417@cindex explore value
9418This sub-command of @code{explore} explores the value of the
9419expression @var{expr} (if @var{expr} is an expression valid in the
9420current context of the program being debugged). The behavior of this
9421command is identical to that of the behavior of the @code{explore}
9422command being passed the argument @var{expr}.
9423
9424@item explore type @var{arg}
9425@cindex explore type
9426This sub-command of @code{explore} explores the type of @var{arg} (if
9427@var{arg} is a type visible in the current context of program being
9428debugged), or the type of the value/expression @var{arg} (if @var{arg}
9429is an expression valid in the current context of the program being
9430debugged). If @var{arg} is a type, then the behavior of this command is
9431identical to that of the @code{explore} command being passed the
9432argument @var{arg}. If @var{arg} is an expression, then the behavior of
9433this command will be identical to that of the @code{explore} command
9434being passed the type of @var{arg} as the argument.
9435@end table
9436
c906108c
SS
9437@menu
9438* Expressions:: Expressions
6ba66d6a 9439* Ambiguous Expressions:: Ambiguous Expressions
c906108c
SS
9440* Variables:: Program variables
9441* Arrays:: Artificial arrays
9442* Output Formats:: Output formats
9443* Memory:: Examining memory
9444* Auto Display:: Automatic display
9445* Print Settings:: Print settings
4c374409 9446* Pretty Printing:: Python pretty printing
c906108c
SS
9447* Value History:: Value history
9448* Convenience Vars:: Convenience variables
a72c3253 9449* Convenience Funs:: Convenience functions
c906108c 9450* Registers:: Registers
c906108c 9451* Floating Point Hardware:: Floating point hardware
53c69bd7 9452* Vector Unit:: Vector Unit
721c2651 9453* OS Information:: Auxiliary data provided by operating system
29e57380 9454* Memory Region Attributes:: Memory region attributes
16d9dec6 9455* Dump/Restore Files:: Copy between memory and a file
384ee23f 9456* Core File Generation:: Cause a program dump its core
a0eb71c5
KB
9457* Character Sets:: Debugging programs that use a different
9458 character set than GDB does
b12039c6 9459* Caching Target Data:: Data caching for targets
08388c79 9460* Searching Memory:: Searching memory for a sequence of bytes
5fdf6324 9461* Value Sizes:: Managing memory allocated for values
c906108c
SS
9462@end menu
9463
6d2ebf8b 9464@node Expressions
c906108c
SS
9465@section Expressions
9466
9467@cindex expressions
9468@code{print} and many other @value{GDBN} commands accept an expression and
9469compute its value. Any kind of constant, variable or operator defined
9470by the programming language you are using is valid in an expression in
e2e0bcd1
JB
9471@value{GDBN}. This includes conditional expressions, function calls,
9472casts, and string constants. It also includes preprocessor macros, if
9473you compiled your program to include this information; see
9474@ref{Compilation}.
c906108c 9475
15387254 9476@cindex arrays in expressions
d4f3574e
SS
9477@value{GDBN} supports array constants in expressions input by
9478the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
63092375
DJ
9479you can use the command @code{print @{1, 2, 3@}} to create an array
9480of three integers. If you pass an array to a function or assign it
9481to a program variable, @value{GDBN} copies the array to memory that
9482is @code{malloc}ed in the target program.
c906108c 9483
c906108c
SS
9484Because C is so widespread, most of the expressions shown in examples in
9485this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
9486Languages}, for information on how to use expressions in other
9487languages.
9488
9489In this section, we discuss operators that you can use in @value{GDBN}
9490expressions regardless of your programming language.
9491
15387254 9492@cindex casts, in expressions
c906108c
SS
9493Casts are supported in all languages, not just in C, because it is so
9494useful to cast a number into a pointer in order to examine a structure
9495at that address in memory.
9496@c FIXME: casts supported---Mod2 true?
c906108c
SS
9497
9498@value{GDBN} supports these operators, in addition to those common
9499to programming languages:
9500
9501@table @code
9502@item @@
9503@samp{@@} is a binary operator for treating parts of memory as arrays.
79a6e687 9504@xref{Arrays, ,Artificial Arrays}, for more information.
c906108c
SS
9505
9506@item ::
9507@samp{::} allows you to specify a variable in terms of the file or
79a6e687 9508function where it is defined. @xref{Variables, ,Program Variables}.
c906108c
SS
9509
9510@cindex @{@var{type}@}
9511@cindex type casting memory
9512@cindex memory, viewing as typed object
9513@cindex casts, to view memory
9514@item @{@var{type}@} @var{addr}
9515Refers to an object of type @var{type} stored at address @var{addr} in
697aa1b7
EZ
9516memory. The address @var{addr} may be any expression whose value is
9517an integer or pointer (but parentheses are required around binary
9518operators, just as in a cast). This construct is allowed regardless
9519of what kind of data is normally supposed to reside at @var{addr}.
c906108c
SS
9520@end table
9521
6ba66d6a
JB
9522@node Ambiguous Expressions
9523@section Ambiguous Expressions
9524@cindex ambiguous expressions
9525
9526Expressions can sometimes contain some ambiguous elements. For instance,
9527some programming languages (notably Ada, C@t{++} and Objective-C) permit
9528a single function name to be defined several times, for application in
9529different contexts. This is called @dfn{overloading}. Another example
9530involving Ada is generics. A @dfn{generic package} is similar to C@t{++}
9531templates and is typically instantiated several times, resulting in
9532the same function name being defined in different contexts.
9533
9534In some cases and depending on the language, it is possible to adjust
9535the expression to remove the ambiguity. For instance in C@t{++}, you
9536can specify the signature of the function you want to break on, as in
9537@kbd{break @var{function}(@var{types})}. In Ada, using the fully
9538qualified name of your function often makes the expression unambiguous
9539as well.
9540
9541When an ambiguity that needs to be resolved is detected, the debugger
9542has the capability to display a menu of numbered choices for each
9543possibility, and then waits for the selection with the prompt @samp{>}.
9544The first option is always @samp{[0] cancel}, and typing @kbd{0 @key{RET}}
9545aborts the current command. If the command in which the expression was
9546used allows more than one choice to be selected, the next option in the
9547menu is @samp{[1] all}, and typing @kbd{1 @key{RET}} selects all possible
9548choices.
9549
9550For example, the following session excerpt shows an attempt to set a
9551breakpoint at the overloaded symbol @code{String::after}.
9552We choose three particular definitions of that function name:
9553
9554@c FIXME! This is likely to change to show arg type lists, at least
9555@smallexample
9556@group
9557(@value{GDBP}) b String::after
9558[0] cancel
9559[1] all
9560[2] file:String.cc; line number:867
9561[3] file:String.cc; line number:860
9562[4] file:String.cc; line number:875
9563[5] file:String.cc; line number:853
9564[6] file:String.cc; line number:846
9565[7] file:String.cc; line number:735
9566> 2 4 6
9567Breakpoint 1 at 0xb26c: file String.cc, line 867.
9568Breakpoint 2 at 0xb344: file String.cc, line 875.
9569Breakpoint 3 at 0xafcc: file String.cc, line 846.
9570Multiple breakpoints were set.
9571Use the "delete" command to delete unwanted
9572 breakpoints.
9573(@value{GDBP})
9574@end group
9575@end smallexample
9576
9577@table @code
9578@kindex set multiple-symbols
9579@item set multiple-symbols @var{mode}
9580@cindex multiple-symbols menu
9581
9582This option allows you to adjust the debugger behavior when an expression
9583is ambiguous.
9584
9585By default, @var{mode} is set to @code{all}. If the command with which
9586the expression is used allows more than one choice, then @value{GDBN}
9587automatically selects all possible choices. For instance, inserting
9588a breakpoint on a function using an ambiguous name results in a breakpoint
9589inserted on each possible match. However, if a unique choice must be made,
9590then @value{GDBN} uses the menu to help you disambiguate the expression.
9591For instance, printing the address of an overloaded function will result
9592in the use of the menu.
9593
9594When @var{mode} is set to @code{ask}, the debugger always uses the menu
9595when an ambiguity is detected.
9596
9597Finally, when @var{mode} is set to @code{cancel}, the debugger reports
9598an error due to the ambiguity and the command is aborted.
9599
9600@kindex show multiple-symbols
9601@item show multiple-symbols
9602Show the current value of the @code{multiple-symbols} setting.
9603@end table
9604
6d2ebf8b 9605@node Variables
79a6e687 9606@section Program Variables
c906108c
SS
9607
9608The most common kind of expression to use is the name of a variable
9609in your program.
9610
9611Variables in expressions are understood in the selected stack frame
79a6e687 9612(@pxref{Selection, ,Selecting a Frame}); they must be either:
c906108c
SS
9613
9614@itemize @bullet
9615@item
9616global (or file-static)
9617@end itemize
9618
5d161b24 9619@noindent or
c906108c
SS
9620
9621@itemize @bullet
9622@item
9623visible according to the scope rules of the
9624programming language from the point of execution in that frame
5d161b24 9625@end itemize
c906108c
SS
9626
9627@noindent This means that in the function
9628
474c8240 9629@smallexample
c906108c
SS
9630foo (a)
9631 int a;
9632@{
9633 bar (a);
9634 @{
9635 int b = test ();
9636 bar (b);
9637 @}
9638@}
474c8240 9639@end smallexample
c906108c
SS
9640
9641@noindent
9642you can examine and use the variable @code{a} whenever your program is
9643executing within the function @code{foo}, but you can only use or
9644examine the variable @code{b} while your program is executing inside
9645the block where @code{b} is declared.
9646
9647@cindex variable name conflict
9648There is an exception: you can refer to a variable or function whose
9649scope is a single source file even if the current execution point is not
9650in this file. But it is possible to have more than one such variable or
9651function with the same name (in different source files). If that
9652happens, referring to that name has unpredictable effects. If you wish,
72384ba3 9653you can specify a static variable in a particular function or file by
15387254 9654using the colon-colon (@code{::}) notation:
c906108c 9655
d4f3574e 9656@cindex colon-colon, context for variables/functions
12c27660 9657@ifnotinfo
c906108c 9658@c info cannot cope with a :: index entry, but why deprive hard copy readers?
41afff9a 9659@cindex @code{::}, context for variables/functions
12c27660 9660@end ifnotinfo
474c8240 9661@smallexample
c906108c
SS
9662@var{file}::@var{variable}
9663@var{function}::@var{variable}
474c8240 9664@end smallexample
c906108c
SS
9665
9666@noindent
9667Here @var{file} or @var{function} is the name of the context for the
9668static @var{variable}. In the case of file names, you can use quotes to
9669make sure @value{GDBN} parses the file name as a single word---for example,
9670to print a global value of @code{x} defined in @file{f2.c}:
9671
474c8240 9672@smallexample
c906108c 9673(@value{GDBP}) p 'f2.c'::x
474c8240 9674@end smallexample
c906108c 9675
72384ba3
PH
9676The @code{::} notation is normally used for referring to
9677static variables, since you typically disambiguate uses of local variables
9678in functions by selecting the appropriate frame and using the
9679simple name of the variable. However, you may also use this notation
9680to refer to local variables in frames enclosing the selected frame:
9681
9682@smallexample
9683void
9684foo (int a)
9685@{
9686 if (a < 10)
9687 bar (a);
9688 else
9689 process (a); /* Stop here */
9690@}
9691
9692int
9693bar (int a)
9694@{
9695 foo (a + 5);
9696@}
9697@end smallexample
9698
9699@noindent
9700For example, if there is a breakpoint at the commented line,
9701here is what you might see
9702when the program stops after executing the call @code{bar(0)}:
9703
9704@smallexample
9705(@value{GDBP}) p a
9706$1 = 10
9707(@value{GDBP}) p bar::a
9708$2 = 5
9709(@value{GDBP}) up 2
9710#2 0x080483d0 in foo (a=5) at foobar.c:12
9711(@value{GDBP}) p a
9712$3 = 5
9713(@value{GDBP}) p bar::a
9714$4 = 0
9715@end smallexample
9716
b37052ae 9717@cindex C@t{++} scope resolution
805e1f19
TT
9718These uses of @samp{::} are very rarely in conflict with the very
9719similar use of the same notation in C@t{++}. When they are in
9720conflict, the C@t{++} meaning takes precedence; however, this can be
9721overridden by quoting the file or function name with single quotes.
9722
9723For example, suppose the program is stopped in a method of a class
9724that has a field named @code{includefile}, and there is also an
9725include file named @file{includefile} that defines a variable,
9726@code{some_global}.
9727
9728@smallexample
9729(@value{GDBP}) p includefile
9730$1 = 23
9731(@value{GDBP}) p includefile::some_global
9732A syntax error in expression, near `'.
9733(@value{GDBP}) p 'includefile'::some_global
9734$2 = 27
9735@end smallexample
c906108c
SS
9736
9737@cindex wrong values
9738@cindex variable values, wrong
15387254
EZ
9739@cindex function entry/exit, wrong values of variables
9740@cindex optimized code, wrong values of variables
c906108c
SS
9741@quotation
9742@emph{Warning:} Occasionally, a local variable may appear to have the
9743wrong value at certain points in a function---just after entry to a new
9744scope, and just before exit.
9745@end quotation
9746You may see this problem when you are stepping by machine instructions.
9747This is because, on most machines, it takes more than one instruction to
9748set up a stack frame (including local variable definitions); if you are
9749stepping by machine instructions, variables may appear to have the wrong
9750values until the stack frame is completely built. On exit, it usually
9751also takes more than one machine instruction to destroy a stack frame;
9752after you begin stepping through that group of instructions, local
9753variable definitions may be gone.
9754
9755This may also happen when the compiler does significant optimizations.
9756To be sure of always seeing accurate values, turn off all optimization
9757when compiling.
9758
d4f3574e
SS
9759@cindex ``No symbol "foo" in current context''
9760Another possible effect of compiler optimizations is to optimize
9761unused variables out of existence, or assign variables to registers (as
9762opposed to memory addresses). Depending on the support for such cases
9763offered by the debug info format used by the compiler, @value{GDBN}
9764might not be able to display values for such local variables. If that
9765happens, @value{GDBN} will print a message like this:
9766
474c8240 9767@smallexample
d4f3574e 9768No symbol "foo" in current context.
474c8240 9769@end smallexample
d4f3574e
SS
9770
9771To solve such problems, either recompile without optimizations, or use a
9772different debug info format, if the compiler supports several such
e0f8f636
TT
9773formats. @xref{Compilation}, for more information on choosing compiler
9774options. @xref{C, ,C and C@t{++}}, for more information about debug
9775info formats that are best suited to C@t{++} programs.
d4f3574e 9776
ab1adacd
EZ
9777If you ask to print an object whose contents are unknown to
9778@value{GDBN}, e.g., because its data type is not completely specified
9779by the debug information, @value{GDBN} will say @samp{<incomplete
9780type>}. @xref{Symbols, incomplete type}, for more about this.
9781
d69cf9b2
PA
9782@cindex no debug info variables
9783If you try to examine or use the value of a (global) variable for
9784which @value{GDBN} has no type information, e.g., because the program
9785includes no debug information, @value{GDBN} displays an error message.
9786@xref{Symbols, unknown type}, for more about unknown types. If you
9787cast the variable to its declared type, @value{GDBN} gets the
9788variable's value using the cast-to type as the variable's type. For
9789example, in a C program:
9790
9791@smallexample
9792 (@value{GDBP}) p var
9793 'var' has unknown type; cast it to its declared type
9794 (@value{GDBP}) p (float) var
9795 $1 = 3.14
9796@end smallexample
9797
36b11add
JK
9798If you append @kbd{@@entry} string to a function parameter name you get its
9799value at the time the function got called. If the value is not available an
9800error message is printed. Entry values are available only with some compilers.
9801Entry values are normally also printed at the function parameter list according
9802to @ref{set print entry-values}.
9803
9804@smallexample
9805Breakpoint 1, d (i=30) at gdb.base/entry-value.c:29
980629 i++;
9807(gdb) next
980830 e (i);
9809(gdb) print i
9810$1 = 31
9811(gdb) print i@@entry
9812$2 = 30
9813@end smallexample
9814
3a60f64e
JK
9815Strings are identified as arrays of @code{char} values without specified
9816signedness. Arrays of either @code{signed char} or @code{unsigned char} get
9817printed as arrays of 1 byte sized integers. @code{-fsigned-char} or
9818@code{-funsigned-char} @value{NGCC} options have no effect as @value{GDBN}
9819defines literal string type @code{"char"} as @code{char} without a sign.
9820For program code
9821
9822@smallexample
9823char var0[] = "A";
9824signed char var1[] = "A";
9825@end smallexample
9826
9827You get during debugging
9828@smallexample
9829(gdb) print var0
9830$1 = "A"
9831(gdb) print var1
9832$2 = @{65 'A', 0 '\0'@}
9833@end smallexample
9834
6d2ebf8b 9835@node Arrays
79a6e687 9836@section Artificial Arrays
c906108c
SS
9837
9838@cindex artificial array
15387254 9839@cindex arrays
41afff9a 9840@kindex @@@r{, referencing memory as an array}
c906108c
SS
9841It is often useful to print out several successive objects of the
9842same type in memory; a section of an array, or an array of
9843dynamically determined size for which only a pointer exists in the
9844program.
9845
9846You can do this by referring to a contiguous span of memory as an
9847@dfn{artificial array}, using the binary operator @samp{@@}. The left
9848operand of @samp{@@} should be the first element of the desired array
9849and be an individual object. The right operand should be the desired length
9850of the array. The result is an array value whose elements are all of
9851the type of the left argument. The first element is actually the left
9852argument; the second element comes from bytes of memory immediately
9853following those that hold the first element, and so on. Here is an
9854example. If a program says
9855
474c8240 9856@smallexample
c906108c 9857int *array = (int *) malloc (len * sizeof (int));
474c8240 9858@end smallexample
c906108c
SS
9859
9860@noindent
9861you can print the contents of @code{array} with
9862
474c8240 9863@smallexample
c906108c 9864p *array@@len
474c8240 9865@end smallexample
c906108c
SS
9866
9867The left operand of @samp{@@} must reside in memory. Array values made
9868with @samp{@@} in this way behave just like other arrays in terms of
9869subscripting, and are coerced to pointers when used in expressions.
9870Artificial arrays most often appear in expressions via the value history
79a6e687 9871(@pxref{Value History, ,Value History}), after printing one out.
c906108c
SS
9872
9873Another way to create an artificial array is to use a cast.
9874This re-interprets a value as if it were an array.
9875The value need not be in memory:
474c8240 9876@smallexample
c906108c
SS
9877(@value{GDBP}) p/x (short[2])0x12345678
9878$1 = @{0x1234, 0x5678@}
474c8240 9879@end smallexample
c906108c
SS
9880
9881As a convenience, if you leave the array length out (as in
c3f6f71d 9882@samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
c906108c 9883the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
474c8240 9884@smallexample
c906108c
SS
9885(@value{GDBP}) p/x (short[])0x12345678
9886$2 = @{0x1234, 0x5678@}
474c8240 9887@end smallexample
c906108c
SS
9888
9889Sometimes the artificial array mechanism is not quite enough; in
9890moderately complex data structures, the elements of interest may not
9891actually be adjacent---for example, if you are interested in the values
9892of pointers in an array. One useful work-around in this situation is
9893to use a convenience variable (@pxref{Convenience Vars, ,Convenience
79a6e687 9894Variables}) as a counter in an expression that prints the first
c906108c
SS
9895interesting value, and then repeat that expression via @key{RET}. For
9896instance, suppose you have an array @code{dtab} of pointers to
9897structures, and you are interested in the values of a field @code{fv}
9898in each structure. Here is an example of what you might type:
9899
474c8240 9900@smallexample
c906108c
SS
9901set $i = 0
9902p dtab[$i++]->fv
9903@key{RET}
9904@key{RET}
9905@dots{}
474c8240 9906@end smallexample
c906108c 9907
6d2ebf8b 9908@node Output Formats
79a6e687 9909@section Output Formats
c906108c
SS
9910
9911@cindex formatted output
9912@cindex output formats
9913By default, @value{GDBN} prints a value according to its data type. Sometimes
9914this is not what you want. For example, you might want to print a number
9915in hex, or a pointer in decimal. Or you might want to view data in memory
9916at a certain address as a character string or as an instruction. To do
9917these things, specify an @dfn{output format} when you print a value.
9918
9919The simplest use of output formats is to say how to print a value
9920already computed. This is done by starting the arguments of the
9921@code{print} command with a slash and a format letter. The format
9922letters supported are:
9923
9924@table @code
9925@item x
9926Regard the bits of the value as an integer, and print the integer in
9927hexadecimal.
9928
9929@item d
9930Print as integer in signed decimal.
9931
9932@item u
9933Print as integer in unsigned decimal.
9934
9935@item o
9936Print as integer in octal.
9937
9938@item t
9939Print as integer in binary. The letter @samp{t} stands for ``two''.
9940@footnote{@samp{b} cannot be used because these format letters are also
9941used with the @code{x} command, where @samp{b} stands for ``byte'';
79a6e687 9942see @ref{Memory,,Examining Memory}.}
c906108c
SS
9943
9944@item a
9945@cindex unknown address, locating
3d67e040 9946@cindex locate address
c906108c
SS
9947Print as an address, both absolute in hexadecimal and as an offset from
9948the nearest preceding symbol. You can use this format used to discover
9949where (in what function) an unknown address is located:
9950
474c8240 9951@smallexample
c906108c
SS
9952(@value{GDBP}) p/a 0x54320
9953$3 = 0x54320 <_initialize_vx+396>
474c8240 9954@end smallexample
c906108c 9955
3d67e040
EZ
9956@noindent
9957The command @code{info symbol 0x54320} yields similar results.
9958@xref{Symbols, info symbol}.
9959
c906108c 9960@item c
51274035
EZ
9961Regard as an integer and print it as a character constant. This
9962prints both the numerical value and its character representation. The
9963character representation is replaced with the octal escape @samp{\nnn}
9964for characters outside the 7-bit @sc{ascii} range.
c906108c 9965
ea37ba09
DJ
9966Without this format, @value{GDBN} displays @code{char},
9967@w{@code{unsigned char}}, and @w{@code{signed char}} data as character
9968constants. Single-byte members of vectors are displayed as integer
9969data.
9970
c906108c
SS
9971@item f
9972Regard the bits of the value as a floating point number and print
9973using typical floating point syntax.
ea37ba09
DJ
9974
9975@item s
9976@cindex printing strings
9977@cindex printing byte arrays
9978Regard as a string, if possible. With this format, pointers to single-byte
9979data are displayed as null-terminated strings and arrays of single-byte data
9980are displayed as fixed-length strings. Other values are displayed in their
9981natural types.
9982
9983Without this format, @value{GDBN} displays pointers to and arrays of
9984@code{char}, @w{@code{unsigned char}}, and @w{@code{signed char}} as
9985strings. Single-byte members of a vector are displayed as an integer
9986array.
a6bac58e 9987
6fbe845e
AB
9988@item z
9989Like @samp{x} formatting, the value is treated as an integer and
9990printed as hexadecimal, but leading zeros are printed to pad the value
9991to the size of the integer type.
9992
a6bac58e
TT
9993@item r
9994@cindex raw printing
9995Print using the @samp{raw} formatting. By default, @value{GDBN} will
78e2826b
TT
9996use a Python-based pretty-printer, if one is available (@pxref{Pretty
9997Printing}). This typically results in a higher-level display of the
9998value's contents. The @samp{r} format bypasses any Python
9999pretty-printer which might exist.
c906108c
SS
10000@end table
10001
10002For example, to print the program counter in hex (@pxref{Registers}), type
10003
474c8240 10004@smallexample
c906108c 10005p/x $pc
474c8240 10006@end smallexample
c906108c
SS
10007
10008@noindent
10009Note that no space is required before the slash; this is because command
10010names in @value{GDBN} cannot contain a slash.
10011
10012To reprint the last value in the value history with a different format,
10013you can use the @code{print} command with just a format and no
10014expression. For example, @samp{p/x} reprints the last value in hex.
10015
6d2ebf8b 10016@node Memory
79a6e687 10017@section Examining Memory
c906108c
SS
10018
10019You can use the command @code{x} (for ``examine'') to examine memory in
10020any of several formats, independently of your program's data types.
10021
10022@cindex examining memory
10023@table @code
41afff9a 10024@kindex x @r{(examine memory)}
c906108c
SS
10025@item x/@var{nfu} @var{addr}
10026@itemx x @var{addr}
10027@itemx x
10028Use the @code{x} command to examine memory.
10029@end table
10030
10031@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
10032much memory to display and how to format it; @var{addr} is an
10033expression giving the address where you want to start displaying memory.
10034If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
10035Several commands set convenient defaults for @var{addr}.
10036
10037@table @r
10038@item @var{n}, the repeat count
10039The repeat count is a decimal integer; the default is 1. It specifies
bb556f1f
TK
10040how much memory (counting by units @var{u}) to display. If a negative
10041number is specified, memory is examined backward from @var{addr}.
c906108c
SS
10042@c This really is **decimal**; unaffected by 'set radix' as of GDB
10043@c 4.1.2.
10044
10045@item @var{f}, the display format
51274035
EZ
10046The display format is one of the formats used by @code{print}
10047(@samp{x}, @samp{d}, @samp{u}, @samp{o}, @samp{t}, @samp{a}, @samp{c},
ea37ba09
DJ
10048@samp{f}, @samp{s}), and in addition @samp{i} (for machine instructions).
10049The default is @samp{x} (hexadecimal) initially. The default changes
10050each time you use either @code{x} or @code{print}.
c906108c
SS
10051
10052@item @var{u}, the unit size
10053The unit size is any of
10054
10055@table @code
10056@item b
10057Bytes.
10058@item h
10059Halfwords (two bytes).
10060@item w
10061Words (four bytes). This is the initial default.
10062@item g
10063Giant words (eight bytes).
10064@end table
10065
10066Each time you specify a unit size with @code{x}, that size becomes the
9a22f0d0
PM
10067default unit the next time you use @code{x}. For the @samp{i} format,
10068the unit size is ignored and is normally not written. For the @samp{s} format,
10069the unit size defaults to @samp{b}, unless it is explicitly given.
10070Use @kbd{x /hs} to display 16-bit char strings and @kbd{x /ws} to display
1007132-bit strings. The next use of @kbd{x /s} will again display 8-bit strings.
10072Note that the results depend on the programming language of the
10073current compilation unit. If the language is C, the @samp{s}
10074modifier will use the UTF-16 encoding while @samp{w} will use
10075UTF-32. The encoding is set by the programming language and cannot
10076be altered.
c906108c
SS
10077
10078@item @var{addr}, starting display address
10079@var{addr} is the address where you want @value{GDBN} to begin displaying
10080memory. The expression need not have a pointer value (though it may);
10081it is always interpreted as an integer address of a byte of memory.
10082@xref{Expressions, ,Expressions}, for more information on expressions. The default for
10083@var{addr} is usually just after the last address examined---but several
10084other commands also set the default address: @code{info breakpoints} (to
10085the address of the last breakpoint listed), @code{info line} (to the
10086starting address of a line), and @code{print} (if you use it to display
10087a value from memory).
10088@end table
10089
10090For example, @samp{x/3uh 0x54320} is a request to display three halfwords
10091(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
10092starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
10093words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
d4f3574e 10094@pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
c906108c 10095
bb556f1f
TK
10096You can also specify a negative repeat count to examine memory backward
10097from the given address. For example, @samp{x/-3uh 0x54320} prints three
10098halfwords (@code{h}) at @code{0x54314}, @code{0x54328}, and @code{0x5431c}.
10099
c906108c
SS
10100Since the letters indicating unit sizes are all distinct from the
10101letters specifying output formats, you do not have to remember whether
10102unit size or format comes first; either order works. The output
10103specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
10104(However, the count @var{n} must come first; @samp{wx4} does not work.)
10105
10106Even though the unit size @var{u} is ignored for the formats @samp{s}
10107and @samp{i}, you might still want to use a count @var{n}; for example,
10108@samp{3i} specifies that you want to see three machine instructions,
a4642986
MR
10109including any operands. For convenience, especially when used with
10110the @code{display} command, the @samp{i} format also prints branch delay
10111slot instructions, if any, beyond the count specified, which immediately
10112follow the last instruction that is within the count. The command
10113@code{disassemble} gives an alternative way of inspecting machine
10114instructions; see @ref{Machine Code,,Source and Machine Code}.
c906108c 10115
bb556f1f
TK
10116If a negative repeat count is specified for the formats @samp{s} or @samp{i},
10117the command displays null-terminated strings or instructions before the given
10118address as many as the absolute value of the given number. For the @samp{i}
10119format, we use line number information in the debug info to accurately locate
10120instruction boundaries while disassembling backward. If line info is not
10121available, the command stops examining memory with an error message.
10122
c906108c
SS
10123All the defaults for the arguments to @code{x} are designed to make it
10124easy to continue scanning memory with minimal specifications each time
10125you use @code{x}. For example, after you have inspected three machine
10126instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
10127with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
10128the repeat count @var{n} is used again; the other arguments default as
10129for successive uses of @code{x}.
10130
2b28d209
PP
10131When examining machine instructions, the instruction at current program
10132counter is shown with a @code{=>} marker. For example:
10133
10134@smallexample
10135(@value{GDBP}) x/5i $pc-6
10136 0x804837f <main+11>: mov %esp,%ebp
10137 0x8048381 <main+13>: push %ecx
10138 0x8048382 <main+14>: sub $0x4,%esp
10139=> 0x8048385 <main+17>: movl $0x8048460,(%esp)
10140 0x804838c <main+24>: call 0x80482d4 <puts@@plt>
10141@end smallexample
10142
c906108c
SS
10143@cindex @code{$_}, @code{$__}, and value history
10144The addresses and contents printed by the @code{x} command are not saved
10145in the value history because there is often too much of them and they
10146would get in the way. Instead, @value{GDBN} makes these values available for
10147subsequent use in expressions as values of the convenience variables
10148@code{$_} and @code{$__}. After an @code{x} command, the last address
10149examined is available for use in expressions in the convenience variable
10150@code{$_}. The contents of that address, as examined, are available in
10151the convenience variable @code{$__}.
10152
10153If the @code{x} command has a repeat count, the address and contents saved
10154are from the last memory unit printed; this is not the same as the last
10155address printed if several units were printed on the last line of output.
10156
a86c90e6
SM
10157@anchor{addressable memory unit}
10158@cindex addressable memory unit
10159Most targets have an addressable memory unit size of 8 bits. This means
10160that to each memory address are associated 8 bits of data. Some
10161targets, however, have other addressable memory unit sizes.
10162Within @value{GDBN} and this document, the term
10163@dfn{addressable memory unit} (or @dfn{memory unit} for short) is used
10164when explicitly referring to a chunk of data of that size. The word
10165@dfn{byte} is used to refer to a chunk of data of 8 bits, regardless of
10166the addressable memory unit size of the target. For most systems,
10167addressable memory unit is a synonym of byte.
10168
09d4efe1 10169@cindex remote memory comparison
936d2992 10170@cindex target memory comparison
09d4efe1 10171@cindex verify remote memory image
936d2992 10172@cindex verify target memory image
09d4efe1 10173When you are debugging a program running on a remote target machine
936d2992
PA
10174(@pxref{Remote Debugging}), you may wish to verify the program's image
10175in the remote machine's memory against the executable file you
10176downloaded to the target. Or, on any target, you may want to check
10177whether the program has corrupted its own read-only sections. The
10178@code{compare-sections} command is provided for such situations.
09d4efe1
EZ
10179
10180@table @code
10181@kindex compare-sections
95cf3b38 10182@item compare-sections @r{[}@var{section-name}@r{|}@code{-r}@r{]}
09d4efe1
EZ
10183Compare the data of a loadable section @var{section-name} in the
10184executable file of the program being debugged with the same section in
936d2992 10185the target machine's memory, and report any mismatches. With no
95cf3b38 10186arguments, compares all loadable sections. With an argument of
936d2992
PA
10187@code{-r}, compares all loadable read-only sections.
10188
10189Note: for remote targets, this command can be accelerated if the
10190target supports computing the CRC checksum of a block of memory
10191(@pxref{qCRC packet}).
09d4efe1
EZ
10192@end table
10193
6d2ebf8b 10194@node Auto Display
79a6e687 10195@section Automatic Display
c906108c
SS
10196@cindex automatic display
10197@cindex display of expressions
10198
10199If you find that you want to print the value of an expression frequently
10200(to see how it changes), you might want to add it to the @dfn{automatic
10201display list} so that @value{GDBN} prints its value each time your program stops.
10202Each expression added to the list is given a number to identify it;
10203to remove an expression from the list, you specify that number.
10204The automatic display looks like this:
10205
474c8240 10206@smallexample
c906108c
SS
102072: foo = 38
102083: bar[5] = (struct hack *) 0x3804
474c8240 10209@end smallexample
c906108c
SS
10210
10211@noindent
10212This display shows item numbers, expressions and their current values. As with
10213displays you request manually using @code{x} or @code{print}, you can
10214specify the output format you prefer; in fact, @code{display} decides
ea37ba09
DJ
10215whether to use @code{print} or @code{x} depending your format
10216specification---it uses @code{x} if you specify either the @samp{i}
10217or @samp{s} format, or a unit size; otherwise it uses @code{print}.
c906108c
SS
10218
10219@table @code
10220@kindex display
d4f3574e
SS
10221@item display @var{expr}
10222Add the expression @var{expr} to the list of expressions to display
c906108c
SS
10223each time your program stops. @xref{Expressions, ,Expressions}.
10224
10225@code{display} does not repeat if you press @key{RET} again after using it.
10226
d4f3574e 10227@item display/@var{fmt} @var{expr}
c906108c 10228For @var{fmt} specifying only a display format and not a size or
d4f3574e 10229count, add the expression @var{expr} to the auto-display list but
c906108c 10230arrange to display it each time in the specified format @var{fmt}.
79a6e687 10231@xref{Output Formats,,Output Formats}.
c906108c
SS
10232
10233@item display/@var{fmt} @var{addr}
10234For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
10235number of units, add the expression @var{addr} as a memory address to
10236be examined each time your program stops. Examining means in effect
79a6e687 10237doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining Memory}.
c906108c
SS
10238@end table
10239
10240For example, @samp{display/i $pc} can be helpful, to see the machine
10241instruction about to be executed each time execution stops (@samp{$pc}
d4f3574e 10242is a common name for the program counter; @pxref{Registers, ,Registers}).
c906108c
SS
10243
10244@table @code
10245@kindex delete display
10246@kindex undisplay
10247@item undisplay @var{dnums}@dots{}
10248@itemx delete display @var{dnums}@dots{}
c9174737
PA
10249Remove items from the list of expressions to display. Specify the
10250numbers of the displays that you want affected with the command
10251argument @var{dnums}. It can be a single display number, one of the
10252numbers shown in the first field of the @samp{info display} display;
10253or it could be a range of display numbers, as in @code{2-4}.
c906108c
SS
10254
10255@code{undisplay} does not repeat if you press @key{RET} after using it.
10256(Otherwise you would just get the error @samp{No display number @dots{}}.)
10257
10258@kindex disable display
10259@item disable display @var{dnums}@dots{}
10260Disable the display of item numbers @var{dnums}. A disabled display
10261item is not printed automatically, but is not forgotten. It may be
c9174737
PA
10262enabled again later. Specify the numbers of the displays that you
10263want affected with the command argument @var{dnums}. It can be a
10264single display number, one of the numbers shown in the first field of
10265the @samp{info display} display; or it could be a range of display
10266numbers, as in @code{2-4}.
c906108c
SS
10267
10268@kindex enable display
10269@item enable display @var{dnums}@dots{}
10270Enable display of item numbers @var{dnums}. It becomes effective once
10271again in auto display of its expression, until you specify otherwise.
c9174737
PA
10272Specify the numbers of the displays that you want affected with the
10273command argument @var{dnums}. It can be a single display number, one
10274of the numbers shown in the first field of the @samp{info display}
10275display; or it could be a range of display numbers, as in @code{2-4}.
c906108c
SS
10276
10277@item display
10278Display the current values of the expressions on the list, just as is
10279done when your program stops.
10280
10281@kindex info display
10282@item info display
10283Print the list of expressions previously set up to display
10284automatically, each one with its item number, but without showing the
10285values. This includes disabled expressions, which are marked as such.
10286It also includes expressions which would not be displayed right now
10287because they refer to automatic variables not currently available.
10288@end table
10289
15387254 10290@cindex display disabled out of scope
c906108c
SS
10291If a display expression refers to local variables, then it does not make
10292sense outside the lexical context for which it was set up. Such an
10293expression is disabled when execution enters a context where one of its
10294variables is not defined. For example, if you give the command
10295@code{display last_char} while inside a function with an argument
10296@code{last_char}, @value{GDBN} displays this argument while your program
10297continues to stop inside that function. When it stops elsewhere---where
10298there is no variable @code{last_char}---the display is disabled
10299automatically. The next time your program stops where @code{last_char}
10300is meaningful, you can enable the display expression once again.
10301
6d2ebf8b 10302@node Print Settings
79a6e687 10303@section Print Settings
c906108c
SS
10304
10305@cindex format options
10306@cindex print settings
10307@value{GDBN} provides the following ways to control how arrays, structures,
10308and symbols are printed.
10309
10310@noindent
10311These settings are useful for debugging programs in any language:
10312
10313@table @code
4644b6e3 10314@kindex set print
c906108c
SS
10315@item set print address
10316@itemx set print address on
4644b6e3 10317@cindex print/don't print memory addresses
c906108c
SS
10318@value{GDBN} prints memory addresses showing the location of stack
10319traces, structure values, pointer values, breakpoints, and so forth,
10320even when it also displays the contents of those addresses. The default
10321is @code{on}. For example, this is what a stack frame display looks like with
10322@code{set print address on}:
10323
10324@smallexample
10325@group
10326(@value{GDBP}) f
10327#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
10328 at input.c:530
10329530 if (lquote != def_lquote)
10330@end group
10331@end smallexample
10332
10333@item set print address off
10334Do not print addresses when displaying their contents. For example,
10335this is the same stack frame displayed with @code{set print address off}:
10336
10337@smallexample
10338@group
10339(@value{GDBP}) set print addr off
10340(@value{GDBP}) f
10341#0 set_quotes (lq="<<", rq=">>") at input.c:530
10342530 if (lquote != def_lquote)
10343@end group
10344@end smallexample
10345
10346You can use @samp{set print address off} to eliminate all machine
10347dependent displays from the @value{GDBN} interface. For example, with
10348@code{print address off}, you should get the same text for backtraces on
10349all machines---whether or not they involve pointer arguments.
10350
4644b6e3 10351@kindex show print
c906108c
SS
10352@item show print address
10353Show whether or not addresses are to be printed.
10354@end table
10355
10356When @value{GDBN} prints a symbolic address, it normally prints the
10357closest earlier symbol plus an offset. If that symbol does not uniquely
10358identify the address (for example, it is a name whose scope is a single
10359source file), you may need to clarify. One way to do this is with
10360@code{info line}, for example @samp{info line *0x4537}. Alternately,
10361you can set @value{GDBN} to print the source file and line number when
10362it prints a symbolic address:
10363
10364@table @code
c906108c 10365@item set print symbol-filename on
9c16f35a
EZ
10366@cindex source file and line of a symbol
10367@cindex symbol, source file and line
c906108c
SS
10368Tell @value{GDBN} to print the source file name and line number of a
10369symbol in the symbolic form of an address.
10370
10371@item set print symbol-filename off
10372Do not print source file name and line number of a symbol. This is the
10373default.
10374
c906108c
SS
10375@item show print symbol-filename
10376Show whether or not @value{GDBN} will print the source file name and
10377line number of a symbol in the symbolic form of an address.
10378@end table
10379
10380Another situation where it is helpful to show symbol filenames and line
10381numbers is when disassembling code; @value{GDBN} shows you the line
10382number and source file that corresponds to each instruction.
10383
10384Also, you may wish to see the symbolic form only if the address being
10385printed is reasonably close to the closest earlier symbol:
10386
10387@table @code
c906108c 10388@item set print max-symbolic-offset @var{max-offset}
f81d1120 10389@itemx set print max-symbolic-offset unlimited
4644b6e3 10390@cindex maximum value for offset of closest symbol
c906108c
SS
10391Tell @value{GDBN} to only display the symbolic form of an address if the
10392offset between the closest earlier symbol and the address is less than
f81d1120
PA
10393@var{max-offset}. The default is @code{unlimited}, which tells @value{GDBN}
10394to always print the symbolic form of an address if any symbol precedes
10395it. Zero is equivalent to @code{unlimited}.
c906108c 10396
c906108c
SS
10397@item show print max-symbolic-offset
10398Ask how large the maximum offset is that @value{GDBN} prints in a
10399symbolic address.
10400@end table
10401
10402@cindex wild pointer, interpreting
10403@cindex pointer, finding referent
10404If you have a pointer and you are not sure where it points, try
10405@samp{set print symbol-filename on}. Then you can determine the name
10406and source file location of the variable where it points, using
10407@samp{p/a @var{pointer}}. This interprets the address in symbolic form.
10408For example, here @value{GDBN} shows that a variable @code{ptt} points
10409at another variable @code{t}, defined in @file{hi2.c}:
10410
474c8240 10411@smallexample
c906108c
SS
10412(@value{GDBP}) set print symbol-filename on
10413(@value{GDBP}) p/a ptt
10414$4 = 0xe008 <t in hi2.c>
474c8240 10415@end smallexample
c906108c
SS
10416
10417@quotation
10418@emph{Warning:} For pointers that point to a local variable, @samp{p/a}
10419does not show the symbol name and filename of the referent, even with
10420the appropriate @code{set print} options turned on.
10421@end quotation
10422
9cb709b6
TT
10423You can also enable @samp{/a}-like formatting all the time using
10424@samp{set print symbol on}:
10425
10426@table @code
10427@item set print symbol on
10428Tell @value{GDBN} to print the symbol corresponding to an address, if
10429one exists.
10430
10431@item set print symbol off
10432Tell @value{GDBN} not to print the symbol corresponding to an
10433address. In this mode, @value{GDBN} will still print the symbol
10434corresponding to pointers to functions. This is the default.
10435
10436@item show print symbol
10437Show whether @value{GDBN} will display the symbol corresponding to an
10438address.
10439@end table
10440
c906108c
SS
10441Other settings control how different kinds of objects are printed:
10442
10443@table @code
c906108c
SS
10444@item set print array
10445@itemx set print array on
4644b6e3 10446@cindex pretty print arrays
c906108c
SS
10447Pretty print arrays. This format is more convenient to read,
10448but uses more space. The default is off.
10449
10450@item set print array off
10451Return to compressed format for arrays.
10452
c906108c
SS
10453@item show print array
10454Show whether compressed or pretty format is selected for displaying
10455arrays.
10456
3c9c013a
JB
10457@cindex print array indexes
10458@item set print array-indexes
10459@itemx set print array-indexes on
10460Print the index of each element when displaying arrays. May be more
10461convenient to locate a given element in the array or quickly find the
10462index of a given element in that printed array. The default is off.
10463
10464@item set print array-indexes off
10465Stop printing element indexes when displaying arrays.
10466
10467@item show print array-indexes
10468Show whether the index of each element is printed when displaying
10469arrays.
10470
c906108c 10471@item set print elements @var{number-of-elements}
f81d1120 10472@itemx set print elements unlimited
4644b6e3 10473@cindex number of array elements to print
9c16f35a 10474@cindex limit on number of printed array elements
c906108c
SS
10475Set a limit on how many elements of an array @value{GDBN} will print.
10476If @value{GDBN} is printing a large array, it stops printing after it has
10477printed the number of elements set by the @code{set print elements} command.
10478This limit also applies to the display of strings.
d4f3574e 10479When @value{GDBN} starts, this limit is set to 200.
f81d1120
PA
10480Setting @var{number-of-elements} to @code{unlimited} or zero means
10481that the number of elements to print is unlimited.
c906108c 10482
c906108c
SS
10483@item show print elements
10484Display the number of elements of a large array that @value{GDBN} will print.
10485If the number is 0, then the printing is unlimited.
10486
b4740add 10487@item set print frame-arguments @var{value}
a0381d3a 10488@kindex set print frame-arguments
b4740add
JB
10489@cindex printing frame argument values
10490@cindex print all frame argument values
10491@cindex print frame argument values for scalars only
10492@cindex do not print frame argument values
10493This command allows to control how the values of arguments are printed
10494when the debugger prints a frame (@pxref{Frames}). The possible
10495values are:
10496
10497@table @code
10498@item all
4f5376b2 10499The values of all arguments are printed.
b4740add
JB
10500
10501@item scalars
10502Print the value of an argument only if it is a scalar. The value of more
10503complex arguments such as arrays, structures, unions, etc, is replaced
4f5376b2
JB
10504by @code{@dots{}}. This is the default. Here is an example where
10505only scalar arguments are shown:
b4740add
JB
10506
10507@smallexample
10508#1 0x08048361 in call_me (i=3, s=@dots{}, ss=0xbf8d508c, u=@dots{}, e=green)
10509 at frame-args.c:23
10510@end smallexample
10511
10512@item none
10513None of the argument values are printed. Instead, the value of each argument
10514is replaced by @code{@dots{}}. In this case, the example above now becomes:
10515
10516@smallexample
10517#1 0x08048361 in call_me (i=@dots{}, s=@dots{}, ss=@dots{}, u=@dots{}, e=@dots{})
10518 at frame-args.c:23
10519@end smallexample
10520@end table
10521
4f5376b2
JB
10522By default, only scalar arguments are printed. This command can be used
10523to configure the debugger to print the value of all arguments, regardless
10524of their type. However, it is often advantageous to not print the value
10525of more complex parameters. For instance, it reduces the amount of
10526information printed in each frame, making the backtrace more readable.
10527Also, it improves performance when displaying Ada frames, because
10528the computation of large arguments can sometimes be CPU-intensive,
10529especially in large applications. Setting @code{print frame-arguments}
10530to @code{scalars} (the default) or @code{none} avoids this computation,
10531thus speeding up the display of each Ada frame.
b4740add
JB
10532
10533@item show print frame-arguments
10534Show how the value of arguments should be displayed when printing a frame.
10535
e7045703
DE
10536@item set print raw frame-arguments on
10537Print frame arguments in raw, non pretty-printed, form.
10538
10539@item set print raw frame-arguments off
10540Print frame arguments in pretty-printed form, if there is a pretty-printer
10541for the value (@pxref{Pretty Printing}),
10542otherwise print the value in raw form.
10543This is the default.
10544
10545@item show print raw frame-arguments
10546Show whether to print frame arguments in raw form.
10547
36b11add 10548@anchor{set print entry-values}
e18b2753
JK
10549@item set print entry-values @var{value}
10550@kindex set print entry-values
10551Set printing of frame argument values at function entry. In some cases
10552@value{GDBN} can determine the value of function argument which was passed by
10553the function caller, even if the value was modified inside the called function
10554and therefore is different. With optimized code, the current value could be
10555unavailable, but the entry value may still be known.
10556
10557The default value is @code{default} (see below for its description). Older
10558@value{GDBN} behaved as with the setting @code{no}. Compilers not supporting
10559this feature will behave in the @code{default} setting the same way as with the
10560@code{no} setting.
10561
10562This functionality is currently supported only by DWARF 2 debugging format and
216f72a1 10563the compiler has to produce @samp{DW_TAG_call_site} tags. With
e18b2753
JK
10564@value{NGCC}, you need to specify @option{-O -g} during compilation, to get
10565this information.
10566
10567The @var{value} parameter can be one of the following:
10568
10569@table @code
10570@item no
10571Print only actual parameter values, never print values from function entry
10572point.
10573@smallexample
10574#0 equal (val=5)
10575#0 different (val=6)
10576#0 lost (val=<optimized out>)
10577#0 born (val=10)
10578#0 invalid (val=<optimized out>)
10579@end smallexample
10580
10581@item only
10582Print only parameter values from function entry point. The actual parameter
10583values are never printed.
10584@smallexample
10585#0 equal (val@@entry=5)
10586#0 different (val@@entry=5)
10587#0 lost (val@@entry=5)
10588#0 born (val@@entry=<optimized out>)
10589#0 invalid (val@@entry=<optimized out>)
10590@end smallexample
10591
10592@item preferred
10593Print only parameter values from function entry point. If value from function
10594entry point is not known while the actual value is known, print the actual
10595value for such parameter.
10596@smallexample
10597#0 equal (val@@entry=5)
10598#0 different (val@@entry=5)
10599#0 lost (val@@entry=5)
10600#0 born (val=10)
10601#0 invalid (val@@entry=<optimized out>)
10602@end smallexample
10603
10604@item if-needed
10605Print actual parameter values. If actual parameter value is not known while
10606value from function entry point is known, print the entry point value for such
10607parameter.
10608@smallexample
10609#0 equal (val=5)
10610#0 different (val=6)
10611#0 lost (val@@entry=5)
10612#0 born (val=10)
10613#0 invalid (val=<optimized out>)
10614@end smallexample
10615
10616@item both
10617Always print both the actual parameter value and its value from function entry
10618point, even if values of one or both are not available due to compiler
10619optimizations.
10620@smallexample
10621#0 equal (val=5, val@@entry=5)
10622#0 different (val=6, val@@entry=5)
10623#0 lost (val=<optimized out>, val@@entry=5)
10624#0 born (val=10, val@@entry=<optimized out>)
10625#0 invalid (val=<optimized out>, val@@entry=<optimized out>)
10626@end smallexample
10627
10628@item compact
10629Print the actual parameter value if it is known and also its value from
10630function entry point if it is known. If neither is known, print for the actual
10631value @code{<optimized out>}. If not in MI mode (@pxref{GDB/MI}) and if both
10632values are known and identical, print the shortened
10633@code{param=param@@entry=VALUE} notation.
10634@smallexample
10635#0 equal (val=val@@entry=5)
10636#0 different (val=6, val@@entry=5)
10637#0 lost (val@@entry=5)
10638#0 born (val=10)
10639#0 invalid (val=<optimized out>)
10640@end smallexample
10641
10642@item default
10643Always print the actual parameter value. Print also its value from function
10644entry point, but only if it is known. If not in MI mode (@pxref{GDB/MI}) and
10645if both values are known and identical, print the shortened
10646@code{param=param@@entry=VALUE} notation.
10647@smallexample
10648#0 equal (val=val@@entry=5)
10649#0 different (val=6, val@@entry=5)
10650#0 lost (val=<optimized out>, val@@entry=5)
10651#0 born (val=10)
10652#0 invalid (val=<optimized out>)
10653@end smallexample
10654@end table
10655
10656For analysis messages on possible failures of frame argument values at function
10657entry resolution see @ref{set debug entry-values}.
10658
10659@item show print entry-values
10660Show the method being used for printing of frame argument values at function
10661entry.
10662
f81d1120
PA
10663@item set print repeats @var{number-of-repeats}
10664@itemx set print repeats unlimited
9c16f35a
EZ
10665@cindex repeated array elements
10666Set the threshold for suppressing display of repeated array
d3e8051b 10667elements. When the number of consecutive identical elements of an
9c16f35a
EZ
10668array exceeds the threshold, @value{GDBN} prints the string
10669@code{"<repeats @var{n} times>"}, where @var{n} is the number of
10670identical repetitions, instead of displaying the identical elements
f81d1120
PA
10671themselves. Setting the threshold to @code{unlimited} or zero will
10672cause all elements to be individually printed. The default threshold
10673is 10.
9c16f35a
EZ
10674
10675@item show print repeats
10676Display the current threshold for printing repeated identical
10677elements.
10678
2e62ab40
AB
10679@item set print max-depth @var{depth}
10680@item set print max-depth unlimited
10681@cindex printing nested structures
10682Set the threshold after which nested structures are replaced with
10683ellipsis, this can make visualising deeply nested structures easier.
10684
10685For example, given this C code
10686
10687@smallexample
10688typedef struct s1 @{ int a; @} s1;
10689typedef struct s2 @{ s1 b; @} s2;
10690typedef struct s3 @{ s2 c; @} s3;
10691typedef struct s4 @{ s3 d; @} s4;
10692
10693s4 var = @{ @{ @{ @{ 3 @} @} @} @};
10694@end smallexample
10695
10696The following table shows how different values of @var{depth} will
10697effect how @code{var} is printed by @value{GDBN}:
10698
10699@multitable @columnfractions .3 .7
10700@headitem @var{depth} setting @tab Result of @samp{p var}
10701@item unlimited
10702@tab @code{$1 = @{d = @{c = @{b = @{a = 3@}@}@}@}}
10703@item @code{0}
10704@tab @code{$1 = @{...@}}
10705@item @code{1}
10706@tab @code{$1 = @{d = @{...@}@}}
10707@item @code{2}
10708@tab @code{$1 = @{d = @{c = @{...@}@}@}}
10709@item @code{3}
10710@tab @code{$1 = @{d = @{c = @{b = @{...@}@}@}@}}
10711@item @code{4}
10712@tab @code{$1 = @{d = @{c = @{b = @{a = 3@}@}@}@}}
10713@end multitable
10714
10715To see the contents of structures that have been hidden the user can
10716either increase the print max-depth, or they can print the elements of
10717the structure that are visible, for example
10718
10719@smallexample
10720(gdb) set print max-depth 2
10721(gdb) p var
10722$1 = @{d = @{c = @{...@}@}@}
10723(gdb) p var.d
10724$2 = @{c = @{b = @{...@}@}@}
10725(gdb) p var.d.c
10726$3 = @{b = @{a = 3@}@}
10727@end smallexample
10728
10729The pattern used to replace nested structures varies based on
10730language, for most languages @code{@{...@}} is used, but Fortran uses
10731@code{(...)}.
10732
10733@item show print max-depth
10734Display the current threshold after which nested structures are
10735replaces with ellipsis.
10736
c906108c 10737@item set print null-stop
4644b6e3 10738@cindex @sc{null} elements in arrays
c906108c 10739Cause @value{GDBN} to stop printing the characters of an array when the first
d4f3574e 10740@sc{null} is encountered. This is useful when large arrays actually
c906108c 10741contain only short strings.
d4f3574e 10742The default is off.
c906108c 10743
9c16f35a
EZ
10744@item show print null-stop
10745Show whether @value{GDBN} stops printing an array on the first
10746@sc{null} character.
10747
c906108c 10748@item set print pretty on
9c16f35a
EZ
10749@cindex print structures in indented form
10750@cindex indentation in structure display
5d161b24 10751Cause @value{GDBN} to print structures in an indented format with one member
c906108c
SS
10752per line, like this:
10753
10754@smallexample
10755@group
10756$1 = @{
10757 next = 0x0,
10758 flags = @{
10759 sweet = 1,
10760 sour = 1
10761 @},
10762 meat = 0x54 "Pork"
10763@}
10764@end group
10765@end smallexample
10766
10767@item set print pretty off
10768Cause @value{GDBN} to print structures in a compact format, like this:
10769
10770@smallexample
10771@group
10772$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
10773meat = 0x54 "Pork"@}
10774@end group
10775@end smallexample
10776
10777@noindent
10778This is the default format.
10779
c906108c
SS
10780@item show print pretty
10781Show which format @value{GDBN} is using to print structures.
10782
c906108c 10783@item set print sevenbit-strings on
4644b6e3
EZ
10784@cindex eight-bit characters in strings
10785@cindex octal escapes in strings
c906108c
SS
10786Print using only seven-bit characters; if this option is set,
10787@value{GDBN} displays any eight-bit characters (in strings or
10788character values) using the notation @code{\}@var{nnn}. This setting is
10789best if you are working in English (@sc{ascii}) and you use the
10790high-order bit of characters as a marker or ``meta'' bit.
10791
10792@item set print sevenbit-strings off
10793Print full eight-bit characters. This allows the use of more
10794international character sets, and is the default.
10795
c906108c
SS
10796@item show print sevenbit-strings
10797Show whether or not @value{GDBN} is printing only seven-bit characters.
10798
c906108c 10799@item set print union on
4644b6e3 10800@cindex unions in structures, printing
9c16f35a
EZ
10801Tell @value{GDBN} to print unions which are contained in structures
10802and other unions. This is the default setting.
c906108c
SS
10803
10804@item set print union off
9c16f35a
EZ
10805Tell @value{GDBN} not to print unions which are contained in
10806structures and other unions. @value{GDBN} will print @code{"@{...@}"}
10807instead.
c906108c 10808
c906108c
SS
10809@item show print union
10810Ask @value{GDBN} whether or not it will print unions which are contained in
9c16f35a 10811structures and other unions.
c906108c
SS
10812
10813For example, given the declarations
10814
10815@smallexample
10816typedef enum @{Tree, Bug@} Species;
10817typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5d161b24 10818typedef enum @{Caterpillar, Cocoon, Butterfly@}
c906108c
SS
10819 Bug_forms;
10820
10821struct thing @{
10822 Species it;
10823 union @{
10824 Tree_forms tree;
10825 Bug_forms bug;
10826 @} form;
10827@};
10828
10829struct thing foo = @{Tree, @{Acorn@}@};
10830@end smallexample
10831
10832@noindent
10833with @code{set print union on} in effect @samp{p foo} would print
10834
10835@smallexample
10836$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
10837@end smallexample
10838
10839@noindent
10840and with @code{set print union off} in effect it would print
10841
10842@smallexample
10843$1 = @{it = Tree, form = @{...@}@}
10844@end smallexample
9c16f35a
EZ
10845
10846@noindent
10847@code{set print union} affects programs written in C-like languages
10848and in Pascal.
c906108c
SS
10849@end table
10850
c906108c
SS
10851@need 1000
10852@noindent
b37052ae 10853These settings are of interest when debugging C@t{++} programs:
c906108c
SS
10854
10855@table @code
4644b6e3 10856@cindex demangling C@t{++} names
c906108c
SS
10857@item set print demangle
10858@itemx set print demangle on
b37052ae 10859Print C@t{++} names in their source form rather than in the encoded
c906108c 10860(``mangled'') form passed to the assembler and linker for type-safe
d4f3574e 10861linkage. The default is on.
c906108c 10862
c906108c 10863@item show print demangle
b37052ae 10864Show whether C@t{++} names are printed in mangled or demangled form.
c906108c 10865
c906108c
SS
10866@item set print asm-demangle
10867@itemx set print asm-demangle on
b37052ae 10868Print C@t{++} names in their source form rather than their mangled form, even
c906108c
SS
10869in assembler code printouts such as instruction disassemblies.
10870The default is off.
10871
c906108c 10872@item show print asm-demangle
b37052ae 10873Show whether C@t{++} names in assembly listings are printed in mangled
c906108c
SS
10874or demangled form.
10875
b37052ae
EZ
10876@cindex C@t{++} symbol decoding style
10877@cindex symbol decoding style, C@t{++}
a8f24a35 10878@kindex set demangle-style
c906108c 10879@item set demangle-style @var{style}
041be526
SM
10880Choose among several encoding schemes used by different compilers to represent
10881C@t{++} names. If you omit @var{style}, you will see a list of possible
10882formats. The default value is @var{auto}, which lets @value{GDBN} choose a
10883decoding style by inspecting your program.
c906108c 10884
c906108c 10885@item show demangle-style
b37052ae 10886Display the encoding style currently in use for decoding C@t{++} symbols.
c906108c 10887
c906108c
SS
10888@item set print object
10889@itemx set print object on
4644b6e3 10890@cindex derived type of an object, printing
9c16f35a 10891@cindex display derived types
c906108c
SS
10892When displaying a pointer to an object, identify the @emph{actual}
10893(derived) type of the object rather than the @emph{declared} type, using
625c0d47
TT
10894the virtual function table. Note that the virtual function table is
10895required---this feature can only work for objects that have run-time
10896type identification; a single virtual method in the object's declared
8264ba82
AG
10897type is sufficient. Note that this setting is also taken into account when
10898working with variable objects via MI (@pxref{GDB/MI}).
c906108c
SS
10899
10900@item set print object off
10901Display only the declared type of objects, without reference to the
10902virtual function table. This is the default setting.
10903
c906108c
SS
10904@item show print object
10905Show whether actual, or declared, object types are displayed.
10906
c906108c
SS
10907@item set print static-members
10908@itemx set print static-members on
4644b6e3 10909@cindex static members of C@t{++} objects
b37052ae 10910Print static members when displaying a C@t{++} object. The default is on.
c906108c
SS
10911
10912@item set print static-members off
b37052ae 10913Do not print static members when displaying a C@t{++} object.
c906108c 10914
c906108c 10915@item show print static-members
9c16f35a
EZ
10916Show whether C@t{++} static members are printed or not.
10917
10918@item set print pascal_static-members
10919@itemx set print pascal_static-members on
d3e8051b
EZ
10920@cindex static members of Pascal objects
10921@cindex Pascal objects, static members display
9c16f35a
EZ
10922Print static members when displaying a Pascal object. The default is on.
10923
10924@item set print pascal_static-members off
10925Do not print static members when displaying a Pascal object.
10926
10927@item show print pascal_static-members
10928Show whether Pascal static members are printed or not.
c906108c
SS
10929
10930@c These don't work with HP ANSI C++ yet.
c906108c
SS
10931@item set print vtbl
10932@itemx set print vtbl on
4644b6e3 10933@cindex pretty print C@t{++} virtual function tables
9c16f35a
EZ
10934@cindex virtual functions (C@t{++}) display
10935@cindex VTBL display
b37052ae 10936Pretty print C@t{++} virtual function tables. The default is off.
c906108c 10937(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 10938ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
10939
10940@item set print vtbl off
b37052ae 10941Do not pretty print C@t{++} virtual function tables.
c906108c 10942
c906108c 10943@item show print vtbl
b37052ae 10944Show whether C@t{++} virtual function tables are pretty printed, or not.
c906108c 10945@end table
c906108c 10946
4c374409
JK
10947@node Pretty Printing
10948@section Pretty Printing
10949
10950@value{GDBN} provides a mechanism to allow pretty-printing of values using
10951Python code. It greatly simplifies the display of complex objects. This
10952mechanism works for both MI and the CLI.
10953
7b51bc51
DE
10954@menu
10955* Pretty-Printer Introduction:: Introduction to pretty-printers
10956* Pretty-Printer Example:: An example pretty-printer
10957* Pretty-Printer Commands:: Pretty-printer commands
10958@end menu
10959
10960@node Pretty-Printer Introduction
10961@subsection Pretty-Printer Introduction
10962
10963When @value{GDBN} prints a value, it first sees if there is a pretty-printer
10964registered for the value. If there is then @value{GDBN} invokes the
10965pretty-printer to print the value. Otherwise the value is printed normally.
10966
10967Pretty-printers are normally named. This makes them easy to manage.
10968The @samp{info pretty-printer} command will list all the installed
10969pretty-printers with their names.
10970If a pretty-printer can handle multiple data types, then its
10971@dfn{subprinters} are the printers for the individual data types.
10972Each such subprinter has its own name.
4e04c971 10973The format of the name is @var{printer-name};@var{subprinter-name}.
7b51bc51
DE
10974
10975Pretty-printers are installed by @dfn{registering} them with @value{GDBN}.
10976Typically they are automatically loaded and registered when the corresponding
10977debug information is loaded, thus making them available without having to
10978do anything special.
10979
10980There are three places where a pretty-printer can be registered.
10981
10982@itemize @bullet
10983@item
10984Pretty-printers registered globally are available when debugging
10985all inferiors.
10986
10987@item
10988Pretty-printers registered with a program space are available only
10989when debugging that program.
10990@xref{Progspaces In Python}, for more details on program spaces in Python.
10991
10992@item
10993Pretty-printers registered with an objfile are loaded and unloaded
10994with the corresponding objfile (e.g., shared library).
10995@xref{Objfiles In Python}, for more details on objfiles in Python.
10996@end itemize
10997
10998@xref{Selecting Pretty-Printers}, for further information on how
10999pretty-printers are selected,
11000
11001@xref{Writing a Pretty-Printer}, for implementing pretty printers
11002for new types.
11003
11004@node Pretty-Printer Example
11005@subsection Pretty-Printer Example
11006
11007Here is how a C@t{++} @code{std::string} looks without a pretty-printer:
4c374409
JK
11008
11009@smallexample
11010(@value{GDBP}) print s
11011$1 = @{
11012 static npos = 4294967295,
11013 _M_dataplus = @{
11014 <std::allocator<char>> = @{
11015 <__gnu_cxx::new_allocator<char>> = @{
11016 <No data fields>@}, <No data fields>
11017 @},
11018 members of std::basic_string<char, std::char_traits<char>,
11019 std::allocator<char> >::_Alloc_hider:
11020 _M_p = 0x804a014 "abcd"
11021 @}
11022@}
11023@end smallexample
11024
11025With a pretty-printer for @code{std::string} only the contents are printed:
11026
11027@smallexample
11028(@value{GDBP}) print s
11029$2 = "abcd"
11030@end smallexample
11031
7b51bc51
DE
11032@node Pretty-Printer Commands
11033@subsection Pretty-Printer Commands
11034@cindex pretty-printer commands
11035
11036@table @code
11037@kindex info pretty-printer
11038@item info pretty-printer [@var{object-regexp} [@var{name-regexp}]]
11039Print the list of installed pretty-printers.
11040This includes disabled pretty-printers, which are marked as such.
11041
11042@var{object-regexp} is a regular expression matching the objects
11043whose pretty-printers to list.
11044Objects can be @code{global}, the program space's file
11045(@pxref{Progspaces In Python}),
11046and the object files within that program space (@pxref{Objfiles In Python}).
11047@xref{Selecting Pretty-Printers}, for details on how @value{GDBN}
11048looks up a printer from these three objects.
11049
11050@var{name-regexp} is a regular expression matching the name of the printers
11051to list.
11052
11053@kindex disable pretty-printer
11054@item disable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
11055Disable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
11056A disabled pretty-printer is not forgotten, it may be enabled again later.
11057
11058@kindex enable pretty-printer
11059@item enable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
11060Enable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
11061@end table
11062
11063Example:
11064
11065Suppose we have three pretty-printers installed: one from library1.so
11066named @code{foo} that prints objects of type @code{foo}, and
11067another from library2.so named @code{bar} that prints two types of objects,
11068@code{bar1} and @code{bar2}.
11069
11070@smallexample
11071(gdb) info pretty-printer
11072library1.so:
11073 foo
11074library2.so:
11075 bar
11076 bar1
11077 bar2
11078(gdb) info pretty-printer library2
11079library2.so:
11080 bar
11081 bar1
11082 bar2
11083(gdb) disable pretty-printer library1
110841 printer disabled
110852 of 3 printers enabled
11086(gdb) info pretty-printer
11087library1.so:
11088 foo [disabled]
11089library2.so:
11090 bar
11091 bar1
11092 bar2
088a96da 11093(gdb) disable pretty-printer library2 bar;bar1
7b51bc51
DE
110941 printer disabled
110951 of 3 printers enabled
11096(gdb) info pretty-printer library2
11097library1.so:
11098 foo [disabled]
11099library2.so:
11100 bar
11101 bar1 [disabled]
11102 bar2
11103(gdb) disable pretty-printer library2 bar
111041 printer disabled
111050 of 3 printers enabled
11106(gdb) info pretty-printer library2
11107library1.so:
11108 foo [disabled]
11109library2.so:
11110 bar [disabled]
11111 bar1 [disabled]
11112 bar2
11113@end smallexample
11114
11115Note that for @code{bar} the entire printer can be disabled,
11116as can each individual subprinter.
4c374409 11117
6d2ebf8b 11118@node Value History
79a6e687 11119@section Value History
c906108c
SS
11120
11121@cindex value history
9c16f35a 11122@cindex history of values printed by @value{GDBN}
5d161b24
DB
11123Values printed by the @code{print} command are saved in the @value{GDBN}
11124@dfn{value history}. This allows you to refer to them in other expressions.
11125Values are kept until the symbol table is re-read or discarded
11126(for example with the @code{file} or @code{symbol-file} commands).
11127When the symbol table changes, the value history is discarded,
11128since the values may contain pointers back to the types defined in the
c906108c
SS
11129symbol table.
11130
11131@cindex @code{$}
11132@cindex @code{$$}
11133@cindex history number
11134The values printed are given @dfn{history numbers} by which you can
11135refer to them. These are successive integers starting with one.
11136@code{print} shows you the history number assigned to a value by
11137printing @samp{$@var{num} = } before the value; here @var{num} is the
11138history number.
11139
11140To refer to any previous value, use @samp{$} followed by the value's
11141history number. The way @code{print} labels its output is designed to
11142remind you of this. Just @code{$} refers to the most recent value in
11143the history, and @code{$$} refers to the value before that.
11144@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
11145is the value just prior to @code{$$}, @code{$$1} is equivalent to
11146@code{$$}, and @code{$$0} is equivalent to @code{$}.
11147
11148For example, suppose you have just printed a pointer to a structure and
11149want to see the contents of the structure. It suffices to type
11150
474c8240 11151@smallexample
c906108c 11152p *$
474c8240 11153@end smallexample
c906108c
SS
11154
11155If you have a chain of structures where the component @code{next} points
11156to the next one, you can print the contents of the next one with this:
11157
474c8240 11158@smallexample
c906108c 11159p *$.next
474c8240 11160@end smallexample
c906108c
SS
11161
11162@noindent
11163You can print successive links in the chain by repeating this
11164command---which you can do by just typing @key{RET}.
11165
11166Note that the history records values, not expressions. If the value of
11167@code{x} is 4 and you type these commands:
11168
474c8240 11169@smallexample
c906108c
SS
11170print x
11171set x=5
474c8240 11172@end smallexample
c906108c
SS
11173
11174@noindent
11175then the value recorded in the value history by the @code{print} command
11176remains 4 even though the value of @code{x} has changed.
11177
11178@table @code
11179@kindex show values
11180@item show values
11181Print the last ten values in the value history, with their item numbers.
11182This is like @samp{p@ $$9} repeated ten times, except that @code{show
11183values} does not change the history.
11184
11185@item show values @var{n}
11186Print ten history values centered on history item number @var{n}.
11187
11188@item show values +
11189Print ten history values just after the values last printed. If no more
11190values are available, @code{show values +} produces no display.
11191@end table
11192
11193Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
11194same effect as @samp{show values +}.
11195
6d2ebf8b 11196@node Convenience Vars
79a6e687 11197@section Convenience Variables
c906108c
SS
11198
11199@cindex convenience variables
9c16f35a 11200@cindex user-defined variables
c906108c
SS
11201@value{GDBN} provides @dfn{convenience variables} that you can use within
11202@value{GDBN} to hold on to a value and refer to it later. These variables
11203exist entirely within @value{GDBN}; they are not part of your program, and
11204setting a convenience variable has no direct effect on further execution
11205of your program. That is why you can use them freely.
11206
11207Convenience variables are prefixed with @samp{$}. Any name preceded by
11208@samp{$} can be used for a convenience variable, unless it is one of
d4f3574e 11209the predefined machine-specific register names (@pxref{Registers, ,Registers}).
c906108c 11210(Value history references, in contrast, are @emph{numbers} preceded
79a6e687 11211by @samp{$}. @xref{Value History, ,Value History}.)
c906108c
SS
11212
11213You can save a value in a convenience variable with an assignment
11214expression, just as you would set a variable in your program.
11215For example:
11216
474c8240 11217@smallexample
c906108c 11218set $foo = *object_ptr
474c8240 11219@end smallexample
c906108c
SS
11220
11221@noindent
11222would save in @code{$foo} the value contained in the object pointed to by
11223@code{object_ptr}.
11224
11225Using a convenience variable for the first time creates it, but its
11226value is @code{void} until you assign a new value. You can alter the
11227value with another assignment at any time.
11228
11229Convenience variables have no fixed types. You can assign a convenience
11230variable any type of value, including structures and arrays, even if
11231that variable already has a value of a different type. The convenience
11232variable, when used as an expression, has the type of its current value.
11233
11234@table @code
11235@kindex show convenience
f47f77df 11236@cindex show all user variables and functions
c906108c 11237@item show convenience
f47f77df
DE
11238Print a list of convenience variables used so far, and their values,
11239as well as a list of the convenience functions.
d4f3574e 11240Abbreviated @code{show conv}.
53e5f3cf
AS
11241
11242@kindex init-if-undefined
11243@cindex convenience variables, initializing
11244@item init-if-undefined $@var{variable} = @var{expression}
11245Set a convenience variable if it has not already been set. This is useful
11246for user-defined commands that keep some state. It is similar, in concept,
11247to using local static variables with initializers in C (except that
11248convenience variables are global). It can also be used to allow users to
11249override default values used in a command script.
11250
11251If the variable is already defined then the expression is not evaluated so
11252any side-effects do not occur.
c906108c
SS
11253@end table
11254
11255One of the ways to use a convenience variable is as a counter to be
11256incremented or a pointer to be advanced. For example, to print
11257a field from successive elements of an array of structures:
11258
474c8240 11259@smallexample
c906108c
SS
11260set $i = 0
11261print bar[$i++]->contents
474c8240 11262@end smallexample
c906108c 11263
d4f3574e
SS
11264@noindent
11265Repeat that command by typing @key{RET}.
c906108c
SS
11266
11267Some convenience variables are created automatically by @value{GDBN} and given
11268values likely to be useful.
11269
11270@table @code
41afff9a 11271@vindex $_@r{, convenience variable}
c906108c
SS
11272@item $_
11273The variable @code{$_} is automatically set by the @code{x} command to
79a6e687 11274the last address examined (@pxref{Memory, ,Examining Memory}). Other
c906108c
SS
11275commands which provide a default address for @code{x} to examine also
11276set @code{$_} to that address; these commands include @code{info line}
11277and @code{info breakpoint}. The type of @code{$_} is @code{void *}
11278except when set by the @code{x} command, in which case it is a pointer
11279to the type of @code{$__}.
11280
41afff9a 11281@vindex $__@r{, convenience variable}
c906108c
SS
11282@item $__
11283The variable @code{$__} is automatically set by the @code{x} command
11284to the value found in the last address examined. Its type is chosen
11285to match the format in which the data was printed.
11286
11287@item $_exitcode
41afff9a 11288@vindex $_exitcode@r{, convenience variable}
0c557179
SDJ
11289When the program being debugged terminates normally, @value{GDBN}
11290automatically sets this variable to the exit code of the program, and
11291resets @code{$_exitsignal} to @code{void}.
11292
11293@item $_exitsignal
11294@vindex $_exitsignal@r{, convenience variable}
11295When the program being debugged dies due to an uncaught signal,
11296@value{GDBN} automatically sets this variable to that signal's number,
11297and resets @code{$_exitcode} to @code{void}.
11298
11299To distinguish between whether the program being debugged has exited
11300(i.e., @code{$_exitcode} is not @code{void}) or signalled (i.e.,
11301@code{$_exitsignal} is not @code{void}), the convenience function
11302@code{$_isvoid} can be used (@pxref{Convenience Funs,, Convenience
11303Functions}). For example, considering the following source code:
11304
11305@smallexample
11306#include <signal.h>
11307
11308int
11309main (int argc, char *argv[])
11310@{
11311 raise (SIGALRM);
11312 return 0;
11313@}
11314@end smallexample
11315
11316A valid way of telling whether the program being debugged has exited
11317or signalled would be:
11318
11319@smallexample
11320(@value{GDBP}) define has_exited_or_signalled
11321Type commands for definition of ``has_exited_or_signalled''.
11322End with a line saying just ``end''.
11323>if $_isvoid ($_exitsignal)
11324 >echo The program has exited\n
11325 >else
11326 >echo The program has signalled\n
11327 >end
11328>end
11329(@value{GDBP}) run
11330Starting program:
11331
11332Program terminated with signal SIGALRM, Alarm clock.
11333The program no longer exists.
11334(@value{GDBP}) has_exited_or_signalled
11335The program has signalled
11336@end smallexample
11337
11338As can be seen, @value{GDBN} correctly informs that the program being
11339debugged has signalled, since it calls @code{raise} and raises a
11340@code{SIGALRM} signal. If the program being debugged had not called
11341@code{raise}, then @value{GDBN} would report a normal exit:
11342
11343@smallexample
11344(@value{GDBP}) has_exited_or_signalled
11345The program has exited
11346@end smallexample
4aa995e1 11347
72f1fe8a
TT
11348@item $_exception
11349The variable @code{$_exception} is set to the exception object being
11350thrown at an exception-related catchpoint. @xref{Set Catchpoints}.
11351
62e5f89c
SDJ
11352@item $_probe_argc
11353@itemx $_probe_arg0@dots{}$_probe_arg11
11354Arguments to a static probe. @xref{Static Probe Points}.
11355
0fb4aa4b
PA
11356@item $_sdata
11357@vindex $_sdata@r{, inspect, convenience variable}
11358The variable @code{$_sdata} contains extra collected static tracepoint
11359data. @xref{Tracepoint Actions,,Tracepoint Action Lists}. Note that
11360@code{$_sdata} could be empty, if not inspecting a trace buffer, or
11361if extra static tracepoint data has not been collected.
11362
4aa995e1
PA
11363@item $_siginfo
11364@vindex $_siginfo@r{, convenience variable}
ec7e75e7
PP
11365The variable @code{$_siginfo} contains extra signal information
11366(@pxref{extra signal information}). Note that @code{$_siginfo}
11367could be empty, if the application has not yet received any signals.
11368For example, it will be empty before you execute the @code{run} command.
711e434b
PM
11369
11370@item $_tlb
11371@vindex $_tlb@r{, convenience variable}
11372The variable @code{$_tlb} is automatically set when debugging
11373applications running on MS-Windows in native mode or connected to
7734102d 11374gdbserver that supports the @code{qGetTIBAddr} request.
711e434b
PM
11375@xref{General Query Packets}.
11376This variable contains the address of the thread information block.
11377
e3940304
PA
11378@item $_inferior
11379The number of the current inferior. @xref{Inferiors and
11380Programs, ,Debugging Multiple Inferiors and Programs}.
11381
5d5658a1
PA
11382@item $_thread
11383The thread number of the current thread. @xref{thread numbers}.
11384
663f6d42
PA
11385@item $_gthread
11386The global number of the current thread. @xref{global thread numbers}.
11387
7734102d
EZ
11388@item $_gdb_major
11389@itemx $_gdb_minor
11390@vindex $_gdb_major@r{, convenience variable}
11391@vindex $_gdb_minor@r{, convenience variable}
11392The major and minor version numbers of the running @value{GDBN}.
11393Development snapshots and pretest versions have their minor version
11394incremented by one; thus, @value{GDBN} pretest 9.11.90 will produce
11395the value 12 for @code{$_gdb_minor}. These variables allow you to
11396write scripts that work with different versions of @value{GDBN}
11397without errors caused by features unavailable in some of those
11398versions.
e2c52041
PW
11399
11400@item $_shell_exitcode
11401@itemx $_shell_exitsignal
11402@vindex $_shell_exitcode@r{, convenience variable}
11403@vindex $_shell_exitsignal@r{, convenience variable}
11404@cindex shell command, exit code
11405@cindex shell command, exit signal
11406@cindex exit status of shell commands
11407@value{GDBN} commands such as @code{shell} and @code{|} are launching
11408shell commands. When a launched command terminates, @value{GDBN}
11409automatically maintains the variables @code{$_shell_exitcode}
11410and @code{$_shell_exitsignal} according to the exit status of the last
11411launched command. These variables are set and used similarly to
11412the variables @code{$_exitcode} and @code{$_exitsignal}.
11413
c906108c
SS
11414@end table
11415
a72c3253
DE
11416@node Convenience Funs
11417@section Convenience Functions
11418
bc3b79fd
TJB
11419@cindex convenience functions
11420@value{GDBN} also supplies some @dfn{convenience functions}. These
11421have a syntax similar to convenience variables. A convenience
11422function can be used in an expression just like an ordinary function;
11423however, a convenience function is implemented internally to
11424@value{GDBN}.
11425
a280dbd1
SDJ
11426These functions do not require @value{GDBN} to be configured with
11427@code{Python} support, which means that they are always available.
11428
11429@table @code
11430
11431@item $_isvoid (@var{expr})
11432@findex $_isvoid@r{, convenience function}
11433Return one if the expression @var{expr} is @code{void}. Otherwise it
11434returns zero.
11435
11436A @code{void} expression is an expression where the type of the result
11437is @code{void}. For example, you can examine a convenience variable
11438(see @ref{Convenience Vars,, Convenience Variables}) to check whether
11439it is @code{void}:
11440
11441@smallexample
11442(@value{GDBP}) print $_exitcode
11443$1 = void
11444(@value{GDBP}) print $_isvoid ($_exitcode)
11445$2 = 1
11446(@value{GDBP}) run
11447Starting program: ./a.out
11448[Inferior 1 (process 29572) exited normally]
11449(@value{GDBP}) print $_exitcode
11450$3 = 0
11451(@value{GDBP}) print $_isvoid ($_exitcode)
11452$4 = 0
11453@end smallexample
11454
11455In the example above, we used @code{$_isvoid} to check whether
11456@code{$_exitcode} is @code{void} before and after the execution of the
11457program being debugged. Before the execution there is no exit code to
11458be examined, therefore @code{$_exitcode} is @code{void}. After the
11459execution the program being debugged returned zero, therefore
11460@code{$_exitcode} is zero, which means that it is not @code{void}
11461anymore.
11462
11463The @code{void} expression can also be a call of a function from the
11464program being debugged. For example, given the following function:
11465
11466@smallexample
11467void
11468foo (void)
11469@{
11470@}
11471@end smallexample
11472
11473The result of calling it inside @value{GDBN} is @code{void}:
11474
11475@smallexample
11476(@value{GDBP}) print foo ()
11477$1 = void
11478(@value{GDBP}) print $_isvoid (foo ())
11479$2 = 1
11480(@value{GDBP}) set $v = foo ()
11481(@value{GDBP}) print $v
11482$3 = void
11483(@value{GDBP}) print $_isvoid ($v)
11484$4 = 1
11485@end smallexample
11486
11487@end table
11488
a72c3253
DE
11489These functions require @value{GDBN} to be configured with
11490@code{Python} support.
11491
11492@table @code
11493
11494@item $_memeq(@var{buf1}, @var{buf2}, @var{length})
11495@findex $_memeq@r{, convenience function}
11496Returns one if the @var{length} bytes at the addresses given by
11497@var{buf1} and @var{buf2} are equal.
11498Otherwise it returns zero.
11499
11500@item $_regex(@var{str}, @var{regex})
11501@findex $_regex@r{, convenience function}
11502Returns one if the string @var{str} matches the regular expression
11503@var{regex}. Otherwise it returns zero.
11504The syntax of the regular expression is that specified by @code{Python}'s
11505regular expression support.
11506
11507@item $_streq(@var{str1}, @var{str2})
11508@findex $_streq@r{, convenience function}
11509Returns one if the strings @var{str1} and @var{str2} are equal.
11510Otherwise it returns zero.
11511
11512@item $_strlen(@var{str})
11513@findex $_strlen@r{, convenience function}
11514Returns the length of string @var{str}.
11515
faa42425
DE
11516@item $_caller_is(@var{name}@r{[}, @var{number_of_frames}@r{]})
11517@findex $_caller_is@r{, convenience function}
11518Returns one if the calling function's name is equal to @var{name}.
11519Otherwise it returns zero.
11520
11521If the optional argument @var{number_of_frames} is provided,
11522it is the number of frames up in the stack to look.
11523The default is 1.
11524
11525Example:
11526
11527@smallexample
11528(gdb) backtrace
11529#0 bottom_func ()
11530 at testsuite/gdb.python/py-caller-is.c:21
11531#1 0x00000000004005a0 in middle_func ()
11532 at testsuite/gdb.python/py-caller-is.c:27
11533#2 0x00000000004005ab in top_func ()
11534 at testsuite/gdb.python/py-caller-is.c:33
11535#3 0x00000000004005b6 in main ()
11536 at testsuite/gdb.python/py-caller-is.c:39
11537(gdb) print $_caller_is ("middle_func")
11538$1 = 1
11539(gdb) print $_caller_is ("top_func", 2)
11540$1 = 1
11541@end smallexample
11542
11543@item $_caller_matches(@var{regexp}@r{[}, @var{number_of_frames}@r{]})
11544@findex $_caller_matches@r{, convenience function}
11545Returns one if the calling function's name matches the regular expression
11546@var{regexp}. Otherwise it returns zero.
11547
11548If the optional argument @var{number_of_frames} is provided,
11549it is the number of frames up in the stack to look.
11550The default is 1.
11551
11552@item $_any_caller_is(@var{name}@r{[}, @var{number_of_frames}@r{]})
11553@findex $_any_caller_is@r{, convenience function}
11554Returns one if any calling function's name is equal to @var{name}.
11555Otherwise it returns zero.
11556
11557If the optional argument @var{number_of_frames} is provided,
11558it is the number of frames up in the stack to look.
11559The default is 1.
11560
11561This function differs from @code{$_caller_is} in that this function
11562checks all stack frames from the immediate caller to the frame specified
11563by @var{number_of_frames}, whereas @code{$_caller_is} only checks the
11564frame specified by @var{number_of_frames}.
11565
11566@item $_any_caller_matches(@var{regexp}@r{[}, @var{number_of_frames}@r{]})
11567@findex $_any_caller_matches@r{, convenience function}
11568Returns one if any calling function's name matches the regular expression
11569@var{regexp}. Otherwise it returns zero.
11570
11571If the optional argument @var{number_of_frames} is provided,
11572it is the number of frames up in the stack to look.
11573The default is 1.
11574
11575This function differs from @code{$_caller_matches} in that this function
11576checks all stack frames from the immediate caller to the frame specified
11577by @var{number_of_frames}, whereas @code{$_caller_matches} only checks the
11578frame specified by @var{number_of_frames}.
11579
f2f3ccb9
SM
11580@item $_as_string(@var{value})
11581@findex $_as_string@r{, convenience function}
11582Return the string representation of @var{value}.
11583
11584This function is useful to obtain the textual label (enumerator) of an
11585enumeration value. For example, assuming the variable @var{node} is of
11586an enumerated type:
11587
11588@smallexample
11589(gdb) printf "Visiting node of type %s\n", $_as_string(node)
11590Visiting node of type NODE_INTEGER
11591@end smallexample
11592
8bdc1658
AB
11593@item $_cimag(@var{value})
11594@itemx $_creal(@var{value})
11595@findex $_cimag@r{, convenience function}
11596@findex $_creal@r{, convenience function}
11597Return the imaginary (@code{$_cimag}) or real (@code{$_creal}) part of
11598the complex number @var{value}.
11599
11600The type of the imaginary or real part depends on the type of the
11601complex number, e.g., using @code{$_cimag} on a @code{float complex}
11602will return an imaginary part of type @code{float}.
11603
a72c3253
DE
11604@end table
11605
11606@value{GDBN} provides the ability to list and get help on
11607convenience functions.
11608
bc3b79fd
TJB
11609@table @code
11610@item help function
11611@kindex help function
11612@cindex show all convenience functions
11613Print a list of all convenience functions.
11614@end table
11615
6d2ebf8b 11616@node Registers
c906108c
SS
11617@section Registers
11618
11619@cindex registers
11620You can refer to machine register contents, in expressions, as variables
11621with names starting with @samp{$}. The names of registers are different
11622for each machine; use @code{info registers} to see the names used on
11623your machine.
11624
11625@table @code
11626@kindex info registers
11627@item info registers
11628Print the names and values of all registers except floating-point
c85508ee 11629and vector registers (in the selected stack frame).
c906108c
SS
11630
11631@kindex info all-registers
11632@cindex floating point registers
11633@item info all-registers
11634Print the names and values of all registers, including floating-point
c85508ee 11635and vector registers (in the selected stack frame).
c906108c 11636
b67d92b0
SH
11637@item info registers @var{reggroup} @dots{}
11638Print the name and value of the registers in each of the specified
11639@var{reggroup}s. The @var{reggoup} can be any of those returned by
11640@code{maint print reggroups} (@pxref{Maintenance Commands}).
11641
c906108c
SS
11642@item info registers @var{regname} @dots{}
11643Print the @dfn{relativized} value of each specified register @var{regname}.
5d161b24 11644As discussed in detail below, register values are normally relative to
697aa1b7 11645the selected stack frame. The @var{regname} may be any register name valid on
c906108c
SS
11646the machine you are using, with or without the initial @samp{$}.
11647@end table
11648
f5b95c01 11649@anchor{standard registers}
e09f16f9
EZ
11650@cindex stack pointer register
11651@cindex program counter register
11652@cindex process status register
11653@cindex frame pointer register
11654@cindex standard registers
c906108c
SS
11655@value{GDBN} has four ``standard'' register names that are available (in
11656expressions) on most machines---whenever they do not conflict with an
11657architecture's canonical mnemonics for registers. The register names
11658@code{$pc} and @code{$sp} are used for the program counter register and
11659the stack pointer. @code{$fp} is used for a register that contains a
11660pointer to the current stack frame, and @code{$ps} is used for a
11661register that contains the processor status. For example,
11662you could print the program counter in hex with
11663
474c8240 11664@smallexample
c906108c 11665p/x $pc
474c8240 11666@end smallexample
c906108c
SS
11667
11668@noindent
11669or print the instruction to be executed next with
11670
474c8240 11671@smallexample
c906108c 11672x/i $pc
474c8240 11673@end smallexample
c906108c
SS
11674
11675@noindent
11676or add four to the stack pointer@footnote{This is a way of removing
11677one word from the stack, on machines where stacks grow downward in
11678memory (most machines, nowadays). This assumes that the innermost
11679stack frame is selected; setting @code{$sp} is not allowed when other
11680stack frames are selected. To pop entire frames off the stack,
11681regardless of machine architecture, use @code{return};
79a6e687 11682see @ref{Returning, ,Returning from a Function}.} with
c906108c 11683
474c8240 11684@smallexample
c906108c 11685set $sp += 4
474c8240 11686@end smallexample
c906108c
SS
11687
11688Whenever possible, these four standard register names are available on
11689your machine even though the machine has different canonical mnemonics,
11690so long as there is no conflict. The @code{info registers} command
11691shows the canonical names. For example, on the SPARC, @code{info
11692registers} displays the processor status register as @code{$psr} but you
d4f3574e
SS
11693can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
11694is an alias for the @sc{eflags} register.
c906108c
SS
11695
11696@value{GDBN} always considers the contents of an ordinary register as an
11697integer when the register is examined in this way. Some machines have
11698special registers which can hold nothing but floating point; these
11699registers are considered to have floating point values. There is no way
11700to refer to the contents of an ordinary register as floating point value
11701(although you can @emph{print} it as a floating point value with
11702@samp{print/f $@var{regname}}).
11703
11704Some registers have distinct ``raw'' and ``virtual'' data formats. This
11705means that the data format in which the register contents are saved by
11706the operating system is not the same one that your program normally
11707sees. For example, the registers of the 68881 floating point
11708coprocessor are always saved in ``extended'' (raw) format, but all C
11709programs expect to work with ``double'' (virtual) format. In such
5d161b24 11710cases, @value{GDBN} normally works with the virtual format only (the format
c906108c
SS
11711that makes sense for your program), but the @code{info registers} command
11712prints the data in both formats.
11713
36b80e65
EZ
11714@cindex SSE registers (x86)
11715@cindex MMX registers (x86)
11716Some machines have special registers whose contents can be interpreted
11717in several different ways. For example, modern x86-based machines
11718have SSE and MMX registers that can hold several values packed
11719together in several different formats. @value{GDBN} refers to such
11720registers in @code{struct} notation:
11721
11722@smallexample
11723(@value{GDBP}) print $xmm1
11724$1 = @{
11725 v4_float = @{0, 3.43859137e-038, 1.54142831e-044, 1.821688e-044@},
11726 v2_double = @{9.92129282474342e-303, 2.7585945287983262e-313@},
11727 v16_int8 = "\000\000\000\000\3706;\001\v\000\000\000\r\000\000",
11728 v8_int16 = @{0, 0, 14072, 315, 11, 0, 13, 0@},
11729 v4_int32 = @{0, 20657912, 11, 13@},
11730 v2_int64 = @{88725056443645952, 55834574859@},
11731 uint128 = 0x0000000d0000000b013b36f800000000
11732@}
11733@end smallexample
11734
11735@noindent
11736To set values of such registers, you need to tell @value{GDBN} which
11737view of the register you wish to change, as if you were assigning
11738value to a @code{struct} member:
11739
11740@smallexample
11741 (@value{GDBP}) set $xmm1.uint128 = 0x000000000000000000000000FFFFFFFF
11742@end smallexample
11743
c906108c 11744Normally, register values are relative to the selected stack frame
79a6e687 11745(@pxref{Selection, ,Selecting a Frame}). This means that you get the
c906108c
SS
11746value that the register would contain if all stack frames farther in
11747were exited and their saved registers restored. In order to see the
11748true contents of hardware registers, you must select the innermost
11749frame (with @samp{frame 0}).
11750
901461f8
PA
11751@cindex caller-saved registers
11752@cindex call-clobbered registers
11753@cindex volatile registers
11754@cindex <not saved> values
11755Usually ABIs reserve some registers as not needed to be saved by the
11756callee (a.k.a.: ``caller-saved'', ``call-clobbered'' or ``volatile''
11757registers). It may therefore not be possible for @value{GDBN} to know
11758the value a register had before the call (in other words, in the outer
11759frame), if the register value has since been changed by the callee.
11760@value{GDBN} tries to deduce where the inner frame saved
11761(``callee-saved'') registers, from the debug info, unwind info, or the
11762machine code generated by your compiler. If some register is not
11763saved, and @value{GDBN} knows the register is ``caller-saved'' (via
11764its own knowledge of the ABI, or because the debug/unwind info
11765explicitly says the register's value is undefined), @value{GDBN}
11766displays @w{@samp{<not saved>}} as the register's value. With targets
11767that @value{GDBN} has no knowledge of the register saving convention,
11768if a register was not saved by the callee, then its value and location
11769in the outer frame are assumed to be the same of the inner frame.
11770This is usually harmless, because if the register is call-clobbered,
11771the caller either does not care what is in the register after the
11772call, or has code to restore the value that it does care about. Note,
11773however, that if you change such a register in the outer frame, you
11774may also be affecting the inner frame. Also, the more ``outer'' the
11775frame is you're looking at, the more likely a call-clobbered
11776register's value is to be wrong, in the sense that it doesn't actually
11777represent the value the register had just before the call.
c906108c 11778
6d2ebf8b 11779@node Floating Point Hardware
79a6e687 11780@section Floating Point Hardware
c906108c
SS
11781@cindex floating point
11782
11783Depending on the configuration, @value{GDBN} may be able to give
11784you more information about the status of the floating point hardware.
11785
11786@table @code
11787@kindex info float
11788@item info float
11789Display hardware-dependent information about the floating
11790point unit. The exact contents and layout vary depending on the
11791floating point chip. Currently, @samp{info float} is supported on
11792the ARM and x86 machines.
11793@end table
c906108c 11794
e76f1f2e
AC
11795@node Vector Unit
11796@section Vector Unit
11797@cindex vector unit
11798
11799Depending on the configuration, @value{GDBN} may be able to give you
11800more information about the status of the vector unit.
11801
11802@table @code
11803@kindex info vector
11804@item info vector
11805Display information about the vector unit. The exact contents and
11806layout vary depending on the hardware.
11807@end table
11808
721c2651 11809@node OS Information
79a6e687 11810@section Operating System Auxiliary Information
721c2651
EZ
11811@cindex OS information
11812
11813@value{GDBN} provides interfaces to useful OS facilities that can help
11814you debug your program.
11815
b383017d
RM
11816@cindex auxiliary vector
11817@cindex vector, auxiliary
b383017d
RM
11818Some operating systems supply an @dfn{auxiliary vector} to programs at
11819startup. This is akin to the arguments and environment that you
11820specify for a program, but contains a system-dependent variety of
11821binary values that tell system libraries important details about the
11822hardware, operating system, and process. Each value's purpose is
11823identified by an integer tag; the meanings are well-known but system-specific.
11824Depending on the configuration and operating system facilities,
9c16f35a
EZ
11825@value{GDBN} may be able to show you this information. For remote
11826targets, this functionality may further depend on the remote stub's
427c3a89
DJ
11827support of the @samp{qXfer:auxv:read} packet, see
11828@ref{qXfer auxiliary vector read}.
b383017d
RM
11829
11830@table @code
11831@kindex info auxv
11832@item info auxv
11833Display the auxiliary vector of the inferior, which can be either a
e4937fc1 11834live process or a core dump file. @value{GDBN} prints each tag value
b383017d
RM
11835numerically, and also shows names and text descriptions for recognized
11836tags. Some values in the vector are numbers, some bit masks, and some
e4937fc1 11837pointers to strings or other data. @value{GDBN} displays each value in the
b383017d
RM
11838most appropriate form for a recognized tag, and in hexadecimal for
11839an unrecognized tag.
11840@end table
11841
85d4a676
SS
11842On some targets, @value{GDBN} can access operating system-specific
11843information and show it to you. The types of information available
11844will differ depending on the type of operating system running on the
11845target. The mechanism used to fetch the data is described in
11846@ref{Operating System Information}. For remote targets, this
11847functionality depends on the remote stub's support of the
07e059b5
VP
11848@samp{qXfer:osdata:read} packet, see @ref{qXfer osdata read}.
11849
11850@table @code
a61408f8 11851@kindex info os
85d4a676
SS
11852@item info os @var{infotype}
11853
11854Display OS information of the requested type.
a61408f8 11855
85d4a676
SS
11856On @sc{gnu}/Linux, the following values of @var{infotype} are valid:
11857
11858@anchor{linux info os infotypes}
11859@table @code
d33279b3
AT
11860@kindex info os cpus
11861@item cpus
11862Display the list of all CPUs/cores. For each CPU/core, @value{GDBN} prints
11863the available fields from /proc/cpuinfo. For each supported architecture
11864different fields are available. Two common entries are processor which gives
11865CPU number and bogomips; a system constant that is calculated during
11866kernel initialization.
11867
11868@kindex info os files
11869@item files
11870Display the list of open file descriptors on the target. For each
11871file descriptor, @value{GDBN} prints the identifier of the process
11872owning the descriptor, the command of the owning process, the value
11873of the descriptor, and the target of the descriptor.
11874
11875@kindex info os modules
11876@item modules
11877Display the list of all loaded kernel modules on the target. For each
11878module, @value{GDBN} prints the module name, the size of the module in
11879bytes, the number of times the module is used, the dependencies of the
11880module, the status of the module, and the address of the loaded module
11881in memory.
11882
11883@kindex info os msg
11884@item msg
11885Display the list of all System V message queues on the target. For each
11886message queue, @value{GDBN} prints the message queue key, the message
11887queue identifier, the access permissions, the current number of bytes
11888on the queue, the current number of messages on the queue, the processes
11889that last sent and received a message on the queue, the user and group
11890of the owner and creator of the message queue, the times at which a
11891message was last sent and received on the queue, and the time at which
11892the message queue was last changed.
11893
07e059b5 11894@kindex info os processes
85d4a676 11895@item processes
07e059b5 11896Display the list of processes on the target. For each process,
85d4a676
SS
11897@value{GDBN} prints the process identifier, the name of the user, the
11898command corresponding to the process, and the list of processor cores
11899that the process is currently running on. (To understand what these
11900properties mean, for this and the following info types, please consult
11901the general @sc{gnu}/Linux documentation.)
11902
11903@kindex info os procgroups
11904@item procgroups
11905Display the list of process groups on the target. For each process,
11906@value{GDBN} prints the identifier of the process group that it belongs
11907to, the command corresponding to the process group leader, the process
11908identifier, and the command line of the process. The list is sorted
11909first by the process group identifier, then by the process identifier,
11910so that processes belonging to the same process group are grouped together
11911and the process group leader is listed first.
11912
d33279b3
AT
11913@kindex info os semaphores
11914@item semaphores
11915Display the list of all System V semaphore sets on the target. For each
11916semaphore set, @value{GDBN} prints the semaphore set key, the semaphore
11917set identifier, the access permissions, the number of semaphores in the
11918set, the user and group of the owner and creator of the semaphore set,
11919and the times at which the semaphore set was operated upon and changed.
85d4a676
SS
11920
11921@kindex info os shm
11922@item shm
11923Display the list of all System V shared-memory regions on the target.
11924For each shared-memory region, @value{GDBN} prints the region key,
11925the shared-memory identifier, the access permissions, the size of the
11926region, the process that created the region, the process that last
11927attached to or detached from the region, the current number of live
11928attaches to the region, and the times at which the region was last
11929attached to, detach from, and changed.
11930
d33279b3
AT
11931@kindex info os sockets
11932@item sockets
11933Display the list of Internet-domain sockets on the target. For each
11934socket, @value{GDBN} prints the address and port of the local and
11935remote endpoints, the current state of the connection, the creator of
11936the socket, the IP address family of the socket, and the type of the
11937connection.
85d4a676 11938
d33279b3
AT
11939@kindex info os threads
11940@item threads
11941Display the list of threads running on the target. For each thread,
11942@value{GDBN} prints the identifier of the process that the thread
11943belongs to, the command of the process, the thread identifier, and the
11944processor core that it is currently running on. The main thread of a
11945process is not listed.
85d4a676
SS
11946@end table
11947
11948@item info os
11949If @var{infotype} is omitted, then list the possible values for
11950@var{infotype} and the kind of OS information available for each
11951@var{infotype}. If the target does not return a list of possible
11952types, this command will report an error.
07e059b5 11953@end table
721c2651 11954
29e57380 11955@node Memory Region Attributes
79a6e687 11956@section Memory Region Attributes
29e57380
C
11957@cindex memory region attributes
11958
b383017d 11959@dfn{Memory region attributes} allow you to describe special handling
fd79ecee
DJ
11960required by regions of your target's memory. @value{GDBN} uses
11961attributes to determine whether to allow certain types of memory
11962accesses; whether to use specific width accesses; and whether to cache
11963target memory. By default the description of memory regions is
11964fetched from the target (if the current target supports this), but the
11965user can override the fetched regions.
29e57380
C
11966
11967Defined memory regions can be individually enabled and disabled. When a
11968memory region is disabled, @value{GDBN} uses the default attributes when
11969accessing memory in that region. Similarly, if no memory regions have
11970been defined, @value{GDBN} uses the default attributes when accessing
11971all memory.
11972
b383017d 11973When a memory region is defined, it is given a number to identify it;
29e57380
C
11974to enable, disable, or remove a memory region, you specify that number.
11975
11976@table @code
11977@kindex mem
bfac230e 11978@item mem @var{lower} @var{upper} @var{attributes}@dots{}
09d4efe1
EZ
11979Define a memory region bounded by @var{lower} and @var{upper} with
11980attributes @var{attributes}@dots{}, and add it to the list of regions
11981monitored by @value{GDBN}. Note that @var{upper} == 0 is a special
d3e8051b 11982case: it is treated as the target's maximum memory address.
bfac230e 11983(0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
29e57380 11984
fd79ecee
DJ
11985@item mem auto
11986Discard any user changes to the memory regions and use target-supplied
11987regions, if available, or no regions if the target does not support.
11988
29e57380
C
11989@kindex delete mem
11990@item delete mem @var{nums}@dots{}
09d4efe1
EZ
11991Remove memory regions @var{nums}@dots{} from the list of regions
11992monitored by @value{GDBN}.
29e57380
C
11993
11994@kindex disable mem
11995@item disable mem @var{nums}@dots{}
09d4efe1 11996Disable monitoring of memory regions @var{nums}@dots{}.
b383017d 11997A disabled memory region is not forgotten.
29e57380
C
11998It may be enabled again later.
11999
12000@kindex enable mem
12001@item enable mem @var{nums}@dots{}
09d4efe1 12002Enable monitoring of memory regions @var{nums}@dots{}.
29e57380
C
12003
12004@kindex info mem
12005@item info mem
12006Print a table of all defined memory regions, with the following columns
09d4efe1 12007for each region:
29e57380
C
12008
12009@table @emph
12010@item Memory Region Number
12011@item Enabled or Disabled.
b383017d 12012Enabled memory regions are marked with @samp{y}.
29e57380
C
12013Disabled memory regions are marked with @samp{n}.
12014
12015@item Lo Address
12016The address defining the inclusive lower bound of the memory region.
12017
12018@item Hi Address
12019The address defining the exclusive upper bound of the memory region.
12020
12021@item Attributes
12022The list of attributes set for this memory region.
12023@end table
12024@end table
12025
12026
12027@subsection Attributes
12028
b383017d 12029@subsubsection Memory Access Mode
29e57380
C
12030The access mode attributes set whether @value{GDBN} may make read or
12031write accesses to a memory region.
12032
12033While these attributes prevent @value{GDBN} from performing invalid
12034memory accesses, they do nothing to prevent the target system, I/O DMA,
359df76b 12035etc.@: from accessing memory.
29e57380
C
12036
12037@table @code
12038@item ro
12039Memory is read only.
12040@item wo
12041Memory is write only.
12042@item rw
6ca652b0 12043Memory is read/write. This is the default.
29e57380
C
12044@end table
12045
12046@subsubsection Memory Access Size
d3e8051b 12047The access size attribute tells @value{GDBN} to use specific sized
29e57380
C
12048accesses in the memory region. Often memory mapped device registers
12049require specific sized accesses. If no access size attribute is
12050specified, @value{GDBN} may use accesses of any size.
12051
12052@table @code
12053@item 8
12054Use 8 bit memory accesses.
12055@item 16
12056Use 16 bit memory accesses.
12057@item 32
12058Use 32 bit memory accesses.
12059@item 64
12060Use 64 bit memory accesses.
12061@end table
12062
12063@c @subsubsection Hardware/Software Breakpoints
12064@c The hardware/software breakpoint attributes set whether @value{GDBN}
12065@c will use hardware or software breakpoints for the internal breakpoints
12066@c used by the step, next, finish, until, etc. commands.
12067@c
12068@c @table @code
12069@c @item hwbreak
b383017d 12070@c Always use hardware breakpoints
29e57380
C
12071@c @item swbreak (default)
12072@c @end table
12073
12074@subsubsection Data Cache
12075The data cache attributes set whether @value{GDBN} will cache target
12076memory. While this generally improves performance by reducing debug
12077protocol overhead, it can lead to incorrect results because @value{GDBN}
12078does not know about volatile variables or memory mapped device
12079registers.
12080
12081@table @code
12082@item cache
b383017d 12083Enable @value{GDBN} to cache target memory.
6ca652b0
EZ
12084@item nocache
12085Disable @value{GDBN} from caching target memory. This is the default.
29e57380
C
12086@end table
12087
4b5752d0
VP
12088@subsection Memory Access Checking
12089@value{GDBN} can be instructed to refuse accesses to memory that is
12090not explicitly described. This can be useful if accessing such
12091regions has undesired effects for a specific target, or to provide
12092better error checking. The following commands control this behaviour.
12093
12094@table @code
12095@kindex set mem inaccessible-by-default
12096@item set mem inaccessible-by-default [on|off]
12097If @code{on} is specified, make @value{GDBN} treat memory not
12098explicitly described by the memory ranges as non-existent and refuse accesses
12099to such memory. The checks are only performed if there's at least one
12100memory range defined. If @code{off} is specified, make @value{GDBN}
12101treat the memory not explicitly described by the memory ranges as RAM.
56cf5405 12102The default value is @code{on}.
4b5752d0
VP
12103@kindex show mem inaccessible-by-default
12104@item show mem inaccessible-by-default
12105Show the current handling of accesses to unknown memory.
12106@end table
12107
12108
29e57380 12109@c @subsubsection Memory Write Verification
b383017d 12110@c The memory write verification attributes set whether @value{GDBN}
29e57380
C
12111@c will re-reads data after each write to verify the write was successful.
12112@c
12113@c @table @code
12114@c @item verify
12115@c @item noverify (default)
12116@c @end table
12117
16d9dec6 12118@node Dump/Restore Files
79a6e687 12119@section Copy Between Memory and a File
16d9dec6
MS
12120@cindex dump/restore files
12121@cindex append data to a file
12122@cindex dump data to a file
12123@cindex restore data from a file
16d9dec6 12124
df5215a6
JB
12125You can use the commands @code{dump}, @code{append}, and
12126@code{restore} to copy data between target memory and a file. The
12127@code{dump} and @code{append} commands write data to a file, and the
12128@code{restore} command reads data from a file back into the inferior's
cf75d6c3
AB
12129memory. Files may be in binary, Motorola S-record, Intel hex,
12130Tektronix Hex, or Verilog Hex format; however, @value{GDBN} can only
12131append to binary files, and cannot read from Verilog Hex files.
df5215a6
JB
12132
12133@table @code
12134
12135@kindex dump
12136@item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
12137@itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
12138Dump the contents of memory from @var{start_addr} to @var{end_addr},
12139or the value of @var{expr}, to @var{filename} in the given format.
16d9dec6 12140
df5215a6 12141The @var{format} parameter may be any one of:
16d9dec6 12142@table @code
df5215a6
JB
12143@item binary
12144Raw binary form.
12145@item ihex
12146Intel hex format.
12147@item srec
12148Motorola S-record format.
12149@item tekhex
12150Tektronix Hex format.
cf75d6c3
AB
12151@item verilog
12152Verilog Hex format.
df5215a6
JB
12153@end table
12154
12155@value{GDBN} uses the same definitions of these formats as the
12156@sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
12157@var{format} is omitted, @value{GDBN} dumps the data in raw binary
12158form.
12159
12160@kindex append
12161@item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
12162@itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
12163Append the contents of memory from @var{start_addr} to @var{end_addr},
09d4efe1 12164or the value of @var{expr}, to the file @var{filename}, in raw binary form.
df5215a6
JB
12165(@value{GDBN} can only append data to files in raw binary form.)
12166
12167@kindex restore
12168@item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
12169Restore the contents of file @var{filename} into memory. The
12170@code{restore} command can automatically recognize any known @sc{bfd}
12171file format, except for raw binary. To restore a raw binary file you
12172must specify the optional keyword @code{binary} after the filename.
16d9dec6 12173
b383017d 12174If @var{bias} is non-zero, its value will be added to the addresses
16d9dec6
MS
12175contained in the file. Binary files always start at address zero, so
12176they will be restored at address @var{bias}. Other bfd files have
12177a built-in location; they will be restored at offset @var{bias}
12178from that location.
12179
12180If @var{start} and/or @var{end} are non-zero, then only data between
12181file offset @var{start} and file offset @var{end} will be restored.
b383017d 12182These offsets are relative to the addresses in the file, before
16d9dec6
MS
12183the @var{bias} argument is applied.
12184
12185@end table
12186
384ee23f
EZ
12187@node Core File Generation
12188@section How to Produce a Core File from Your Program
12189@cindex dump core from inferior
12190
12191A @dfn{core file} or @dfn{core dump} is a file that records the memory
12192image of a running process and its process status (register values
12193etc.). Its primary use is post-mortem debugging of a program that
12194crashed while it ran outside a debugger. A program that crashes
12195automatically produces a core file, unless this feature is disabled by
12196the user. @xref{Files}, for information on invoking @value{GDBN} in
12197the post-mortem debugging mode.
12198
12199Occasionally, you may wish to produce a core file of the program you
12200are debugging in order to preserve a snapshot of its state.
12201@value{GDBN} has a special command for that.
12202
12203@table @code
12204@kindex gcore
12205@kindex generate-core-file
12206@item generate-core-file [@var{file}]
12207@itemx gcore [@var{file}]
12208Produce a core dump of the inferior process. The optional argument
12209@var{file} specifies the file name where to put the core dump. If not
12210specified, the file name defaults to @file{core.@var{pid}}, where
12211@var{pid} is the inferior process ID.
12212
12213Note that this command is implemented only for some systems (as of
05b4bd79 12214this writing, @sc{gnu}/Linux, FreeBSD, Solaris, and S390).
df8411da
SDJ
12215
12216On @sc{gnu}/Linux, this command can take into account the value of the
12217file @file{/proc/@var{pid}/coredump_filter} when generating the core
1e52e849
SL
12218dump (@pxref{set use-coredump-filter}), and by default honors the
12219@code{VM_DONTDUMP} flag for mappings where it is present in the file
12220@file{/proc/@var{pid}/smaps} (@pxref{set dump-excluded-mappings}).
df8411da
SDJ
12221
12222@kindex set use-coredump-filter
12223@anchor{set use-coredump-filter}
12224@item set use-coredump-filter on
12225@itemx set use-coredump-filter off
12226Enable or disable the use of the file
12227@file{/proc/@var{pid}/coredump_filter} when generating core dump
12228files. This file is used by the Linux kernel to decide what types of
12229memory mappings will be dumped or ignored when generating a core dump
12230file. @var{pid} is the process ID of a currently running process.
12231
12232To make use of this feature, you have to write in the
12233@file{/proc/@var{pid}/coredump_filter} file a value, in hexadecimal,
12234which is a bit mask representing the memory mapping types. If a bit
12235is set in the bit mask, then the memory mappings of the corresponding
12236types will be dumped; otherwise, they will be ignored. This
12237configuration is inherited by child processes. For more information
12238about the bits that can be set in the
12239@file{/proc/@var{pid}/coredump_filter} file, please refer to the
12240manpage of @code{core(5)}.
12241
12242By default, this option is @code{on}. If this option is turned
12243@code{off}, @value{GDBN} does not read the @file{coredump_filter} file
12244and instead uses the same default value as the Linux kernel in order
12245to decide which pages will be dumped in the core dump file. This
12246value is currently @code{0x33}, which means that bits @code{0}
12247(anonymous private mappings), @code{1} (anonymous shared mappings),
12248@code{4} (ELF headers) and @code{5} (private huge pages) are active.
12249This will cause these memory mappings to be dumped automatically.
1e52e849
SL
12250
12251@kindex set dump-excluded-mappings
12252@anchor{set dump-excluded-mappings}
12253@item set dump-excluded-mappings on
12254@itemx set dump-excluded-mappings off
12255If @code{on} is specified, @value{GDBN} will dump memory mappings
12256marked with the @code{VM_DONTDUMP} flag. This flag is represented in
12257the file @file{/proc/@var{pid}/smaps} with the acronym @code{dd}.
12258
12259The default value is @code{off}.
384ee23f
EZ
12260@end table
12261
a0eb71c5
KB
12262@node Character Sets
12263@section Character Sets
12264@cindex character sets
12265@cindex charset
12266@cindex translating between character sets
12267@cindex host character set
12268@cindex target character set
12269
12270If the program you are debugging uses a different character set to
12271represent characters and strings than the one @value{GDBN} uses itself,
12272@value{GDBN} can automatically translate between the character sets for
12273you. The character set @value{GDBN} uses we call the @dfn{host
12274character set}; the one the inferior program uses we call the
12275@dfn{target character set}.
12276
12277For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
12278uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
ea35711c 12279remote protocol (@pxref{Remote Debugging}) to debug a program
a0eb71c5
KB
12280running on an IBM mainframe, which uses the @sc{ebcdic} character set,
12281then the host character set is Latin-1, and the target character set is
12282@sc{ebcdic}. If you give @value{GDBN} the command @code{set
e33d66ec 12283target-charset EBCDIC-US}, then @value{GDBN} translates between
a0eb71c5
KB
12284@sc{ebcdic} and Latin 1 as you print character or string values, or use
12285character and string literals in expressions.
12286
12287@value{GDBN} has no way to automatically recognize which character set
12288the inferior program uses; you must tell it, using the @code{set
12289target-charset} command, described below.
12290
12291Here are the commands for controlling @value{GDBN}'s character set
12292support:
12293
12294@table @code
12295@item set target-charset @var{charset}
12296@kindex set target-charset
10af6951
EZ
12297Set the current target character set to @var{charset}. To display the
12298list of supported target character sets, type
12299@kbd{@w{set target-charset @key{TAB}@key{TAB}}}.
a0eb71c5 12300
a0eb71c5
KB
12301@item set host-charset @var{charset}
12302@kindex set host-charset
12303Set the current host character set to @var{charset}.
12304
12305By default, @value{GDBN} uses a host character set appropriate to the
12306system it is running on; you can override that default using the
732f6a93
TT
12307@code{set host-charset} command. On some systems, @value{GDBN} cannot
12308automatically determine the appropriate host character set. In this
12309case, @value{GDBN} uses @samp{UTF-8}.
a0eb71c5
KB
12310
12311@value{GDBN} can only use certain character sets as its host character
c1b6b909 12312set. If you type @kbd{@w{set host-charset @key{TAB}@key{TAB}}},
10af6951 12313@value{GDBN} will list the host character sets it supports.
a0eb71c5
KB
12314
12315@item set charset @var{charset}
12316@kindex set charset
e33d66ec 12317Set the current host and target character sets to @var{charset}. As
10af6951
EZ
12318above, if you type @kbd{@w{set charset @key{TAB}@key{TAB}}},
12319@value{GDBN} will list the names of the character sets that can be used
e33d66ec
EZ
12320for both host and target.
12321
a0eb71c5 12322@item show charset
a0eb71c5 12323@kindex show charset
10af6951 12324Show the names of the current host and target character sets.
e33d66ec 12325
10af6951 12326@item show host-charset
a0eb71c5 12327@kindex show host-charset
10af6951 12328Show the name of the current host character set.
e33d66ec 12329
10af6951 12330@item show target-charset
a0eb71c5 12331@kindex show target-charset
10af6951 12332Show the name of the current target character set.
a0eb71c5 12333
10af6951
EZ
12334@item set target-wide-charset @var{charset}
12335@kindex set target-wide-charset
12336Set the current target's wide character set to @var{charset}. This is
12337the character set used by the target's @code{wchar_t} type. To
12338display the list of supported wide character sets, type
12339@kbd{@w{set target-wide-charset @key{TAB}@key{TAB}}}.
12340
12341@item show target-wide-charset
12342@kindex show target-wide-charset
12343Show the name of the current target's wide character set.
a0eb71c5
KB
12344@end table
12345
a0eb71c5
KB
12346Here is an example of @value{GDBN}'s character set support in action.
12347Assume that the following source code has been placed in the file
12348@file{charset-test.c}:
12349
12350@smallexample
12351#include <stdio.h>
12352
12353char ascii_hello[]
12354 = @{72, 101, 108, 108, 111, 44, 32, 119,
12355 111, 114, 108, 100, 33, 10, 0@};
12356char ibm1047_hello[]
12357 = @{200, 133, 147, 147, 150, 107, 64, 166,
12358 150, 153, 147, 132, 90, 37, 0@};
12359
12360main ()
12361@{
12362 printf ("Hello, world!\n");
12363@}
10998722 12364@end smallexample
a0eb71c5
KB
12365
12366In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
12367containing the string @samp{Hello, world!} followed by a newline,
12368encoded in the @sc{ascii} and @sc{ibm1047} character sets.
12369
12370We compile the program, and invoke the debugger on it:
12371
12372@smallexample
12373$ gcc -g charset-test.c -o charset-test
12374$ gdb -nw charset-test
12375GNU gdb 2001-12-19-cvs
12376Copyright 2001 Free Software Foundation, Inc.
12377@dots{}
f7dc1244 12378(@value{GDBP})
10998722 12379@end smallexample
a0eb71c5
KB
12380
12381We can use the @code{show charset} command to see what character sets
12382@value{GDBN} is currently using to interpret and display characters and
12383strings:
12384
12385@smallexample
f7dc1244 12386(@value{GDBP}) show charset
e33d66ec 12387The current host and target character set is `ISO-8859-1'.
f7dc1244 12388(@value{GDBP})
10998722 12389@end smallexample
a0eb71c5
KB
12390
12391For the sake of printing this manual, let's use @sc{ascii} as our
12392initial character set:
12393@smallexample
f7dc1244
EZ
12394(@value{GDBP}) set charset ASCII
12395(@value{GDBP}) show charset
e33d66ec 12396The current host and target character set is `ASCII'.
f7dc1244 12397(@value{GDBP})
10998722 12398@end smallexample
a0eb71c5
KB
12399
12400Let's assume that @sc{ascii} is indeed the correct character set for our
12401host system --- in other words, let's assume that if @value{GDBN} prints
12402characters using the @sc{ascii} character set, our terminal will display
12403them properly. Since our current target character set is also
12404@sc{ascii}, the contents of @code{ascii_hello} print legibly:
12405
12406@smallexample
f7dc1244 12407(@value{GDBP}) print ascii_hello
a0eb71c5 12408$1 = 0x401698 "Hello, world!\n"
f7dc1244 12409(@value{GDBP}) print ascii_hello[0]
a0eb71c5 12410$2 = 72 'H'
f7dc1244 12411(@value{GDBP})
10998722 12412@end smallexample
a0eb71c5
KB
12413
12414@value{GDBN} uses the target character set for character and string
12415literals you use in expressions:
12416
12417@smallexample
f7dc1244 12418(@value{GDBP}) print '+'
a0eb71c5 12419$3 = 43 '+'
f7dc1244 12420(@value{GDBP})
10998722 12421@end smallexample
a0eb71c5
KB
12422
12423The @sc{ascii} character set uses the number 43 to encode the @samp{+}
12424character.
12425
12426@value{GDBN} relies on the user to tell it which character set the
12427target program uses. If we print @code{ibm1047_hello} while our target
12428character set is still @sc{ascii}, we get jibberish:
12429
12430@smallexample
f7dc1244 12431(@value{GDBP}) print ibm1047_hello
a0eb71c5 12432$4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
f7dc1244 12433(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 12434$5 = 200 '\310'
f7dc1244 12435(@value{GDBP})
10998722 12436@end smallexample
a0eb71c5 12437
e33d66ec 12438If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
a0eb71c5
KB
12439@value{GDBN} tells us the character sets it supports:
12440
12441@smallexample
f7dc1244 12442(@value{GDBP}) set target-charset
b383017d 12443ASCII EBCDIC-US IBM1047 ISO-8859-1
f7dc1244 12444(@value{GDBP}) set target-charset
10998722 12445@end smallexample
a0eb71c5
KB
12446
12447We can select @sc{ibm1047} as our target character set, and examine the
12448program's strings again. Now the @sc{ascii} string is wrong, but
12449@value{GDBN} translates the contents of @code{ibm1047_hello} from the
12450target character set, @sc{ibm1047}, to the host character set,
12451@sc{ascii}, and they display correctly:
12452
12453@smallexample
f7dc1244
EZ
12454(@value{GDBP}) set target-charset IBM1047
12455(@value{GDBP}) show charset
e33d66ec
EZ
12456The current host character set is `ASCII'.
12457The current target character set is `IBM1047'.
f7dc1244 12458(@value{GDBP}) print ascii_hello
a0eb71c5 12459$6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
f7dc1244 12460(@value{GDBP}) print ascii_hello[0]
a0eb71c5 12461$7 = 72 '\110'
f7dc1244 12462(@value{GDBP}) print ibm1047_hello
a0eb71c5 12463$8 = 0x4016a8 "Hello, world!\n"
f7dc1244 12464(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 12465$9 = 200 'H'
f7dc1244 12466(@value{GDBP})
10998722 12467@end smallexample
a0eb71c5
KB
12468
12469As above, @value{GDBN} uses the target character set for character and
12470string literals you use in expressions:
12471
12472@smallexample
f7dc1244 12473(@value{GDBP}) print '+'
a0eb71c5 12474$10 = 78 '+'
f7dc1244 12475(@value{GDBP})
10998722 12476@end smallexample
a0eb71c5 12477
e33d66ec 12478The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
a0eb71c5
KB
12479character.
12480
b12039c6
YQ
12481@node Caching Target Data
12482@section Caching Data of Targets
12483@cindex caching data of targets
12484
12485@value{GDBN} caches data exchanged between the debugger and a target.
b26dfc9a
YQ
12486Each cache is associated with the address space of the inferior.
12487@xref{Inferiors and Programs}, about inferior and address space.
b12039c6
YQ
12488Such caching generally improves performance in remote debugging
12489(@pxref{Remote Debugging}), because it reduces the overhead of the
12490remote protocol by bundling memory reads and writes into large chunks.
12491Unfortunately, simply caching everything would lead to incorrect results,
12492since @value{GDBN} does not necessarily know anything about volatile
12493values, memory-mapped I/O addresses, etc. Furthermore, in non-stop mode
12494(@pxref{Non-Stop Mode}) memory can be changed @emph{while} a gdb command
12495is executing.
29b090c0
DE
12496Therefore, by default, @value{GDBN} only caches data
12497known to be on the stack@footnote{In non-stop mode, it is moderately
12498rare for a running thread to modify the stack of a stopped thread
12499in a way that would interfere with a backtrace, and caching of
29453a14
YQ
12500stack reads provides a significant speed up of remote backtraces.} or
12501in the code segment.
29b090c0 12502Other regions of memory can be explicitly marked as
27b81af3 12503cacheable; @pxref{Memory Region Attributes}.
09d4efe1
EZ
12504
12505@table @code
12506@kindex set remotecache
12507@item set remotecache on
12508@itemx set remotecache off
4e5d721f
DE
12509This option no longer does anything; it exists for compatibility
12510with old scripts.
09d4efe1
EZ
12511
12512@kindex show remotecache
12513@item show remotecache
4e5d721f
DE
12514Show the current state of the obsolete remotecache flag.
12515
12516@kindex set stack-cache
12517@item set stack-cache on
12518@itemx set stack-cache off
6dd315ba
YQ
12519Enable or disable caching of stack accesses. When @code{on}, use
12520caching. By default, this option is @code{on}.
4e5d721f
DE
12521
12522@kindex show stack-cache
12523@item show stack-cache
12524Show the current state of data caching for memory accesses.
09d4efe1 12525
29453a14
YQ
12526@kindex set code-cache
12527@item set code-cache on
12528@itemx set code-cache off
12529Enable or disable caching of code segment accesses. When @code{on},
12530use caching. By default, this option is @code{on}. This improves
12531performance of disassembly in remote debugging.
12532
12533@kindex show code-cache
12534@item show code-cache
12535Show the current state of target memory cache for code segment
12536accesses.
12537
09d4efe1 12538@kindex info dcache
4e5d721f 12539@item info dcache @r{[}line@r{]}
b26dfc9a
YQ
12540Print the information about the performance of data cache of the
12541current inferior's address space. The information displayed
12542includes the dcache width and depth, and for each cache line, its
12543number, address, and how many times it was referenced. This
12544command is useful for debugging the data cache operation.
4e5d721f
DE
12545
12546If a line number is specified, the contents of that line will be
12547printed in hex.
1a532630
PP
12548
12549@item set dcache size @var{size}
12550@cindex dcache size
12551@kindex set dcache size
12552Set maximum number of entries in dcache (dcache depth above).
12553
12554@item set dcache line-size @var{line-size}
12555@cindex dcache line-size
12556@kindex set dcache line-size
12557Set number of bytes each dcache entry caches (dcache width above).
12558Must be a power of 2.
12559
12560@item show dcache size
12561@kindex show dcache size
b12039c6 12562Show maximum number of dcache entries. @xref{Caching Target Data, info dcache}.
1a532630
PP
12563
12564@item show dcache line-size
12565@kindex show dcache line-size
b12039c6 12566Show default size of dcache lines.
1a532630 12567
09d4efe1
EZ
12568@end table
12569
08388c79
DE
12570@node Searching Memory
12571@section Search Memory
12572@cindex searching memory
12573
12574Memory can be searched for a particular sequence of bytes with the
12575@code{find} command.
12576
12577@table @code
12578@kindex find
12579@item find @r{[}/@var{sn}@r{]} @var{start_addr}, +@var{len}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
12580@itemx find @r{[}/@var{sn}@r{]} @var{start_addr}, @var{end_addr}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
12581Search memory for the sequence of bytes specified by @var{val1}, @var{val2},
12582etc. The search begins at address @var{start_addr} and continues for either
12583@var{len} bytes or through to @var{end_addr} inclusive.
12584@end table
12585
12586@var{s} and @var{n} are optional parameters.
12587They may be specified in either order, apart or together.
12588
12589@table @r
12590@item @var{s}, search query size
12591The size of each search query value.
12592
12593@table @code
12594@item b
12595bytes
12596@item h
12597halfwords (two bytes)
12598@item w
12599words (four bytes)
12600@item g
12601giant words (eight bytes)
12602@end table
12603
12604All values are interpreted in the current language.
12605This means, for example, that if the current source language is C/C@t{++}
12606then searching for the string ``hello'' includes the trailing '\0'.
ee9a09e9
DC
12607The null terminator can be removed from searching by using casts,
12608e.g.: @samp{@{char[5]@}"hello"}.
08388c79
DE
12609
12610If the value size is not specified, it is taken from the
12611value's type in the current language.
12612This is useful when one wants to specify the search
12613pattern as a mixture of types.
12614Note that this means, for example, that in the case of C-like languages
12615a search for an untyped 0x42 will search for @samp{(int) 0x42}
12616which is typically four bytes.
12617
12618@item @var{n}, maximum number of finds
12619The maximum number of matches to print. The default is to print all finds.
12620@end table
12621
12622You can use strings as search values. Quote them with double-quotes
12623 (@code{"}).
12624The string value is copied into the search pattern byte by byte,
12625regardless of the endianness of the target and the size specification.
12626
12627The address of each match found is printed as well as a count of the
12628number of matches found.
12629
12630The address of the last value found is stored in convenience variable
12631@samp{$_}.
12632A count of the number of matches is stored in @samp{$numfound}.
12633
12634For example, if stopped at the @code{printf} in this function:
12635
12636@smallexample
12637void
12638hello ()
12639@{
12640 static char hello[] = "hello-hello";
12641 static struct @{ char c; short s; int i; @}
12642 __attribute__ ((packed)) mixed
12643 = @{ 'c', 0x1234, 0x87654321 @};
12644 printf ("%s\n", hello);
12645@}
12646@end smallexample
12647
12648@noindent
12649you get during debugging:
12650
12651@smallexample
12652(gdb) find &hello[0], +sizeof(hello), "hello"
126530x804956d <hello.1620+6>
126541 pattern found
12655(gdb) find &hello[0], +sizeof(hello), 'h', 'e', 'l', 'l', 'o'
126560x8049567 <hello.1620>
126570x804956d <hello.1620+6>
ee9a09e9
DC
126582 patterns found.
12659(gdb) find &hello[0], +sizeof(hello), @{char[5]@}"hello"
126600x8049567 <hello.1620>
126610x804956d <hello.1620+6>
126622 patterns found.
08388c79
DE
12663(gdb) find /b1 &hello[0], +sizeof(hello), 'h', 0x65, 'l'
126640x8049567 <hello.1620>
126651 pattern found
12666(gdb) find &mixed, +sizeof(mixed), (char) 'c', (short) 0x1234, (int) 0x87654321
126670x8049560 <mixed.1625>
126681 pattern found
12669(gdb) print $numfound
12670$1 = 1
12671(gdb) print $_
12672$2 = (void *) 0x8049560
12673@end smallexample
a0eb71c5 12674
5fdf6324
AB
12675@node Value Sizes
12676@section Value Sizes
12677
12678Whenever @value{GDBN} prints a value memory will be allocated within
12679@value{GDBN} to hold the contents of the value. It is possible in
12680some languages with dynamic typing systems, that an invalid program
12681may indicate a value that is incorrectly large, this in turn may cause
12682@value{GDBN} to try and allocate an overly large ammount of memory.
12683
12684@table @code
12685@kindex set max-value-size
713cdcbf 12686@item set max-value-size @var{bytes}
5fdf6324
AB
12687@itemx set max-value-size unlimited
12688Set the maximum size of memory that @value{GDBN} will allocate for the
12689contents of a value to @var{bytes}, trying to display a value that
12690requires more memory than that will result in an error.
12691
12692Setting this variable does not effect values that have already been
12693allocated within @value{GDBN}, only future allocations.
12694
12695There's a minimum size that @code{max-value-size} can be set to in
12696order that @value{GDBN} can still operate correctly, this minimum is
12697currently 16 bytes.
12698
12699The limit applies to the results of some subexpressions as well as to
12700complete expressions. For example, an expression denoting a simple
12701integer component, such as @code{x.y.z}, may fail if the size of
12702@var{x.y} is dynamic and exceeds @var{bytes}. On the other hand,
12703@value{GDBN} is sometimes clever; the expression @code{A[i]}, where
12704@var{A} is an array variable with non-constant size, will generally
12705succeed regardless of the bounds on @var{A}, as long as the component
12706size is less than @var{bytes}.
12707
12708The default value of @code{max-value-size} is currently 64k.
12709
12710@kindex show max-value-size
12711@item show max-value-size
12712Show the maximum size of memory, in bytes, that @value{GDBN} will
12713allocate for the contents of a value.
12714@end table
12715
edb3359d
DJ
12716@node Optimized Code
12717@chapter Debugging Optimized Code
12718@cindex optimized code, debugging
12719@cindex debugging optimized code
12720
12721Almost all compilers support optimization. With optimization
12722disabled, the compiler generates assembly code that corresponds
12723directly to your source code, in a simplistic way. As the compiler
12724applies more powerful optimizations, the generated assembly code
12725diverges from your original source code. With help from debugging
12726information generated by the compiler, @value{GDBN} can map from
12727the running program back to constructs from your original source.
12728
12729@value{GDBN} is more accurate with optimization disabled. If you
12730can recompile without optimization, it is easier to follow the
12731progress of your program during debugging. But, there are many cases
12732where you may need to debug an optimized version.
12733
12734When you debug a program compiled with @samp{-g -O}, remember that the
12735optimizer has rearranged your code; the debugger shows you what is
12736really there. Do not be too surprised when the execution path does not
12737exactly match your source file! An extreme example: if you define a
12738variable, but never use it, @value{GDBN} never sees that
12739variable---because the compiler optimizes it out of existence.
12740
12741Some things do not work as well with @samp{-g -O} as with just
12742@samp{-g}, particularly on machines with instruction scheduling. If in
12743doubt, recompile with @samp{-g} alone, and if this fixes the problem,
12744please report it to us as a bug (including a test case!).
12745@xref{Variables}, for more information about debugging optimized code.
12746
12747@menu
12748* Inline Functions:: How @value{GDBN} presents inlining
111c6489 12749* Tail Call Frames:: @value{GDBN} analysis of jumps to functions
edb3359d
DJ
12750@end menu
12751
12752@node Inline Functions
12753@section Inline Functions
12754@cindex inline functions, debugging
12755
12756@dfn{Inlining} is an optimization that inserts a copy of the function
12757body directly at each call site, instead of jumping to a shared
12758routine. @value{GDBN} displays inlined functions just like
12759non-inlined functions. They appear in backtraces. You can view their
12760arguments and local variables, step into them with @code{step}, skip
12761them with @code{next}, and escape from them with @code{finish}.
12762You can check whether a function was inlined by using the
12763@code{info frame} command.
12764
12765For @value{GDBN} to support inlined functions, the compiler must
12766record information about inlining in the debug information ---
12767@value{NGCC} using the @sc{dwarf 2} format does this, and several
12768other compilers do also. @value{GDBN} only supports inlined functions
12769when using @sc{dwarf 2}. Versions of @value{NGCC} before 4.1
12770do not emit two required attributes (@samp{DW_AT_call_file} and
12771@samp{DW_AT_call_line}); @value{GDBN} does not display inlined
12772function calls with earlier versions of @value{NGCC}. It instead
12773displays the arguments and local variables of inlined functions as
12774local variables in the caller.
12775
12776The body of an inlined function is directly included at its call site;
12777unlike a non-inlined function, there are no instructions devoted to
12778the call. @value{GDBN} still pretends that the call site and the
12779start of the inlined function are different instructions. Stepping to
12780the call site shows the call site, and then stepping again shows
12781the first line of the inlined function, even though no additional
12782instructions are executed.
12783
12784This makes source-level debugging much clearer; you can see both the
12785context of the call and then the effect of the call. Only stepping by
12786a single instruction using @code{stepi} or @code{nexti} does not do
12787this; single instruction steps always show the inlined body.
12788
12789There are some ways that @value{GDBN} does not pretend that inlined
12790function calls are the same as normal calls:
12791
12792@itemize @bullet
edb3359d
DJ
12793@item
12794Setting breakpoints at the call site of an inlined function may not
12795work, because the call site does not contain any code. @value{GDBN}
12796may incorrectly move the breakpoint to the next line of the enclosing
12797function, after the call. This limitation will be removed in a future
12798version of @value{GDBN}; until then, set a breakpoint on an earlier line
12799or inside the inlined function instead.
12800
12801@item
12802@value{GDBN} cannot locate the return value of inlined calls after
12803using the @code{finish} command. This is a limitation of compiler-generated
12804debugging information; after @code{finish}, you can step to the next line
12805and print a variable where your program stored the return value.
12806
12807@end itemize
12808
111c6489
JK
12809@node Tail Call Frames
12810@section Tail Call Frames
12811@cindex tail call frames, debugging
12812
12813Function @code{B} can call function @code{C} in its very last statement. In
12814unoptimized compilation the call of @code{C} is immediately followed by return
12815instruction at the end of @code{B} code. Optimizing compiler may replace the
12816call and return in function @code{B} into one jump to function @code{C}
12817instead. Such use of a jump instruction is called @dfn{tail call}.
12818
12819During execution of function @code{C}, there will be no indication in the
12820function call stack frames that it was tail-called from @code{B}. If function
12821@code{A} regularly calls function @code{B} which tail-calls function @code{C},
12822then @value{GDBN} will see @code{A} as the caller of @code{C}. However, in
12823some cases @value{GDBN} can determine that @code{C} was tail-called from
12824@code{B}, and it will then create fictitious call frame for that, with the
12825return address set up as if @code{B} called @code{C} normally.
12826
12827This functionality is currently supported only by DWARF 2 debugging format and
216f72a1 12828the compiler has to produce @samp{DW_TAG_call_site} tags. With
111c6489
JK
12829@value{NGCC}, you need to specify @option{-O -g} during compilation, to get
12830this information.
12831
12832@kbd{info frame} command (@pxref{Frame Info}) will indicate the tail call frame
12833kind by text @code{tail call frame} such as in this sample @value{GDBN} output:
12834
12835@smallexample
12836(gdb) x/i $pc - 2
12837 0x40066b <b(int, double)+11>: jmp 0x400640 <c(int, double)>
12838(gdb) info frame
12839Stack level 1, frame at 0x7fffffffda30:
12840 rip = 0x40066d in b (amd64-entry-value.cc:59); saved rip 0x4004c5
12841 tail call frame, caller of frame at 0x7fffffffda30
12842 source language c++.
12843 Arglist at unknown address.
12844 Locals at unknown address, Previous frame's sp is 0x7fffffffda30
12845@end smallexample
12846
12847The detection of all the possible code path executions can find them ambiguous.
12848There is no execution history stored (possible @ref{Reverse Execution} is never
12849used for this purpose) and the last known caller could have reached the known
12850callee by multiple different jump sequences. In such case @value{GDBN} still
12851tries to show at least all the unambiguous top tail callers and all the
12852unambiguous bottom tail calees, if any.
12853
12854@table @code
e18b2753 12855@anchor{set debug entry-values}
111c6489
JK
12856@item set debug entry-values
12857@kindex set debug entry-values
12858When set to on, enables printing of analysis messages for both frame argument
12859values at function entry and tail calls. It will show all the possible valid
12860tail calls code paths it has considered. It will also print the intersection
12861of them with the final unambiguous (possibly partial or even empty) code path
12862result.
12863
12864@item show debug entry-values
12865@kindex show debug entry-values
12866Show the current state of analysis messages printing for both frame argument
12867values at function entry and tail calls.
12868@end table
12869
12870The analysis messages for tail calls can for example show why the virtual tail
12871call frame for function @code{c} has not been recognized (due to the indirect
12872reference by variable @code{x}):
12873
12874@smallexample
12875static void __attribute__((noinline, noclone)) c (void);
12876void (*x) (void) = c;
12877static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
12878static void __attribute__((noinline, noclone)) c (void) @{ a (); @}
12879int main (void) @{ x (); return 0; @}
12880
216f72a1
JK
12881Breakpoint 1, DW_OP_entry_value resolving cannot find
12882DW_TAG_call_site 0x40039a in main
111c6489
JK
12883a () at t.c:3
128843 static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
12885(gdb) bt
12886#0 a () at t.c:3
12887#1 0x000000000040039a in main () at t.c:5
12888@end smallexample
12889
12890Another possibility is an ambiguous virtual tail call frames resolution:
12891
12892@smallexample
12893int i;
12894static void __attribute__((noinline, noclone)) f (void) @{ i++; @}
12895static void __attribute__((noinline, noclone)) e (void) @{ f (); @}
12896static void __attribute__((noinline, noclone)) d (void) @{ f (); @}
12897static void __attribute__((noinline, noclone)) c (void) @{ d (); @}
12898static void __attribute__((noinline, noclone)) b (void)
12899@{ if (i) c (); else e (); @}
12900static void __attribute__((noinline, noclone)) a (void) @{ b (); @}
12901int main (void) @{ a (); return 0; @}
12902
12903tailcall: initial: 0x4004d2(a) 0x4004ce(b) 0x4004b2(c) 0x4004a2(d)
12904tailcall: compare: 0x4004d2(a) 0x4004cc(b) 0x400492(e)
12905tailcall: reduced: 0x4004d2(a) |
12906(gdb) bt
12907#0 f () at t.c:2
12908#1 0x00000000004004d2 in a () at t.c:8
12909#2 0x0000000000400395 in main () at t.c:9
12910@end smallexample
12911
5048e516
JK
12912@set CALLSEQ1A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}c@value{ARROW}d@value{ARROW}f}
12913@set CALLSEQ2A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}e@value{ARROW}f}
12914
12915@c Convert CALLSEQ#A to CALLSEQ#B depending on HAVE_MAKEINFO_CLICK.
12916@ifset HAVE_MAKEINFO_CLICK
12917@set ARROW @click{}
12918@set CALLSEQ1B @clicksequence{@value{CALLSEQ1A}}
12919@set CALLSEQ2B @clicksequence{@value{CALLSEQ2A}}
12920@end ifset
12921@ifclear HAVE_MAKEINFO_CLICK
12922@set ARROW ->
12923@set CALLSEQ1B @value{CALLSEQ1A}
12924@set CALLSEQ2B @value{CALLSEQ2A}
12925@end ifclear
12926
12927Frames #0 and #2 are real, #1 is a virtual tail call frame.
12928The code can have possible execution paths @value{CALLSEQ1B} or
12929@value{CALLSEQ2B}, @value{GDBN} cannot find which one from the inferior state.
111c6489
JK
12930
12931@code{initial:} state shows some random possible calling sequence @value{GDBN}
12932has found. It then finds another possible calling sequcen - that one is
12933prefixed by @code{compare:}. The non-ambiguous intersection of these two is
12934printed as the @code{reduced:} calling sequence. That one could have many
12935futher @code{compare:} and @code{reduced:} statements as long as there remain
12936any non-ambiguous sequence entries.
12937
12938For the frame of function @code{b} in both cases there are different possible
12939@code{$pc} values (@code{0x4004cc} or @code{0x4004ce}), therefore this frame is
12940also ambigous. The only non-ambiguous frame is the one for function @code{a},
12941therefore this one is displayed to the user while the ambiguous frames are
12942omitted.
edb3359d 12943
e18b2753
JK
12944There can be also reasons why printing of frame argument values at function
12945entry may fail:
12946
12947@smallexample
12948int v;
12949static void __attribute__((noinline, noclone)) c (int i) @{ v++; @}
12950static void __attribute__((noinline, noclone)) a (int i);
12951static void __attribute__((noinline, noclone)) b (int i) @{ a (i); @}
12952static void __attribute__((noinline, noclone)) a (int i)
12953@{ if (i) b (i - 1); else c (0); @}
12954int main (void) @{ a (5); return 0; @}
12955
12956(gdb) bt
12957#0 c (i=i@@entry=0) at t.c:2
216f72a1 12958#1 0x0000000000400428 in a (DW_OP_entry_value resolving has found
e18b2753
JK
12959function "a" at 0x400420 can call itself via tail calls
12960i=<optimized out>) at t.c:6
12961#2 0x000000000040036e in main () at t.c:7
12962@end smallexample
12963
12964@value{GDBN} cannot find out from the inferior state if and how many times did
12965function @code{a} call itself (via function @code{b}) as these calls would be
12966tail calls. Such tail calls would modify thue @code{i} variable, therefore
12967@value{GDBN} cannot be sure the value it knows would be right - @value{GDBN}
12968prints @code{<optimized out>} instead.
12969
e2e0bcd1
JB
12970@node Macros
12971@chapter C Preprocessor Macros
12972
49efadf5 12973Some languages, such as C and C@t{++}, provide a way to define and invoke
e2e0bcd1
JB
12974``preprocessor macros'' which expand into strings of tokens.
12975@value{GDBN} can evaluate expressions containing macro invocations, show
12976the result of macro expansion, and show a macro's definition, including
12977where it was defined.
12978
12979You may need to compile your program specially to provide @value{GDBN}
12980with information about preprocessor macros. Most compilers do not
12981include macros in their debugging information, even when you compile
12982with the @option{-g} flag. @xref{Compilation}.
12983
12984A program may define a macro at one point, remove that definition later,
12985and then provide a different definition after that. Thus, at different
12986points in the program, a macro may have different definitions, or have
12987no definition at all. If there is a current stack frame, @value{GDBN}
12988uses the macros in scope at that frame's source code line. Otherwise,
12989@value{GDBN} uses the macros in scope at the current listing location;
12990see @ref{List}.
12991
e2e0bcd1
JB
12992Whenever @value{GDBN} evaluates an expression, it always expands any
12993macro invocations present in the expression. @value{GDBN} also provides
12994the following commands for working with macros explicitly.
12995
12996@table @code
12997
12998@kindex macro expand
12999@cindex macro expansion, showing the results of preprocessor
13000@cindex preprocessor macro expansion, showing the results of
13001@cindex expanding preprocessor macros
13002@item macro expand @var{expression}
13003@itemx macro exp @var{expression}
13004Show the results of expanding all preprocessor macro invocations in
13005@var{expression}. Since @value{GDBN} simply expands macros, but does
13006not parse the result, @var{expression} need not be a valid expression;
13007it can be any string of tokens.
13008
09d4efe1 13009@kindex macro exp1
e2e0bcd1
JB
13010@item macro expand-once @var{expression}
13011@itemx macro exp1 @var{expression}
4644b6e3 13012@cindex expand macro once
e2e0bcd1
JB
13013@i{(This command is not yet implemented.)} Show the results of
13014expanding those preprocessor macro invocations that appear explicitly in
13015@var{expression}. Macro invocations appearing in that expansion are
13016left unchanged. This command allows you to see the effect of a
13017particular macro more clearly, without being confused by further
13018expansions. Since @value{GDBN} simply expands macros, but does not
13019parse the result, @var{expression} need not be a valid expression; it
13020can be any string of tokens.
13021
475b0867 13022@kindex info macro
e2e0bcd1 13023@cindex macro definition, showing
9b158ba0 13024@cindex definition of a macro, showing
13025@cindex macros, from debug info
71eba9c2 13026@item info macro [-a|-all] [--] @var{macro}
13027Show the current definition or all definitions of the named @var{macro},
13028and describe the source location or compiler command-line where that
13029definition was established. The optional double dash is to signify the end of
13030argument processing and the beginning of @var{macro} for non C-like macros where
13031the macro may begin with a hyphen.
e2e0bcd1 13032
9b158ba0 13033@kindex info macros
629500fa 13034@item info macros @var{location}
9b158ba0 13035Show all macro definitions that are in effect at the location specified
629500fa 13036by @var{location}, and describe the source location or compiler
9b158ba0 13037command-line where those definitions were established.
13038
e2e0bcd1
JB
13039@kindex macro define
13040@cindex user-defined macros
13041@cindex defining macros interactively
13042@cindex macros, user-defined
13043@item macro define @var{macro} @var{replacement-list}
13044@itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
d7d9f01e
TT
13045Introduce a definition for a preprocessor macro named @var{macro},
13046invocations of which are replaced by the tokens given in
13047@var{replacement-list}. The first form of this command defines an
13048``object-like'' macro, which takes no arguments; the second form
13049defines a ``function-like'' macro, which takes the arguments given in
13050@var{arglist}.
13051
13052A definition introduced by this command is in scope in every
13053expression evaluated in @value{GDBN}, until it is removed with the
13054@code{macro undef} command, described below. The definition overrides
13055all definitions for @var{macro} present in the program being debugged,
13056as well as any previous user-supplied definition.
e2e0bcd1
JB
13057
13058@kindex macro undef
13059@item macro undef @var{macro}
d7d9f01e
TT
13060Remove any user-supplied definition for the macro named @var{macro}.
13061This command only affects definitions provided with the @code{macro
13062define} command, described above; it cannot remove definitions present
13063in the program being debugged.
e2e0bcd1 13064
09d4efe1
EZ
13065@kindex macro list
13066@item macro list
d7d9f01e 13067List all the macros defined using the @code{macro define} command.
e2e0bcd1
JB
13068@end table
13069
13070@cindex macros, example of debugging with
13071Here is a transcript showing the above commands in action. First, we
13072show our source files:
13073
13074@smallexample
13075$ cat sample.c
13076#include <stdio.h>
13077#include "sample.h"
13078
13079#define M 42
13080#define ADD(x) (M + x)
13081
13082main ()
13083@{
13084#define N 28
13085 printf ("Hello, world!\n");
13086#undef N
13087 printf ("We're so creative.\n");
13088#define N 1729
13089 printf ("Goodbye, world!\n");
13090@}
13091$ cat sample.h
13092#define Q <
13093$
13094@end smallexample
13095
e0f8f636
TT
13096Now, we compile the program using the @sc{gnu} C compiler,
13097@value{NGCC}. We pass the @option{-gdwarf-2}@footnote{This is the
13098minimum. Recent versions of @value{NGCC} support @option{-gdwarf-3}
13099and @option{-gdwarf-4}; we recommend always choosing the most recent
13100version of DWARF.} @emph{and} @option{-g3} flags to ensure the compiler
13101includes information about preprocessor macros in the debugging
e2e0bcd1
JB
13102information.
13103
13104@smallexample
13105$ gcc -gdwarf-2 -g3 sample.c -o sample
13106$
13107@end smallexample
13108
13109Now, we start @value{GDBN} on our sample program:
13110
13111@smallexample
13112$ gdb -nw sample
13113GNU gdb 2002-05-06-cvs
13114Copyright 2002 Free Software Foundation, Inc.
13115GDB is free software, @dots{}
f7dc1244 13116(@value{GDBP})
e2e0bcd1
JB
13117@end smallexample
13118
13119We can expand macros and examine their definitions, even when the
13120program is not running. @value{GDBN} uses the current listing position
13121to decide which macro definitions are in scope:
13122
13123@smallexample
f7dc1244 13124(@value{GDBP}) list main
e2e0bcd1
JB
131253
131264 #define M 42
131275 #define ADD(x) (M + x)
131286
131297 main ()
131308 @{
131319 #define N 28
1313210 printf ("Hello, world!\n");
1313311 #undef N
1313412 printf ("We're so creative.\n");
f7dc1244 13135(@value{GDBP}) info macro ADD
e2e0bcd1
JB
13136Defined at /home/jimb/gdb/macros/play/sample.c:5
13137#define ADD(x) (M + x)
f7dc1244 13138(@value{GDBP}) info macro Q
e2e0bcd1
JB
13139Defined at /home/jimb/gdb/macros/play/sample.h:1
13140 included at /home/jimb/gdb/macros/play/sample.c:2
13141#define Q <
f7dc1244 13142(@value{GDBP}) macro expand ADD(1)
e2e0bcd1 13143expands to: (42 + 1)
f7dc1244 13144(@value{GDBP}) macro expand-once ADD(1)
e2e0bcd1 13145expands to: once (M + 1)
f7dc1244 13146(@value{GDBP})
e2e0bcd1
JB
13147@end smallexample
13148
d7d9f01e 13149In the example above, note that @code{macro expand-once} expands only
e2e0bcd1
JB
13150the macro invocation explicit in the original text --- the invocation of
13151@code{ADD} --- but does not expand the invocation of the macro @code{M},
13152which was introduced by @code{ADD}.
13153
3f94c067
BW
13154Once the program is running, @value{GDBN} uses the macro definitions in
13155force at the source line of the current stack frame:
e2e0bcd1
JB
13156
13157@smallexample
f7dc1244 13158(@value{GDBP}) break main
e2e0bcd1 13159Breakpoint 1 at 0x8048370: file sample.c, line 10.
f7dc1244 13160(@value{GDBP}) run
b383017d 13161Starting program: /home/jimb/gdb/macros/play/sample
e2e0bcd1
JB
13162
13163Breakpoint 1, main () at sample.c:10
1316410 printf ("Hello, world!\n");
f7dc1244 13165(@value{GDBP})
e2e0bcd1
JB
13166@end smallexample
13167
13168At line 10, the definition of the macro @code{N} at line 9 is in force:
13169
13170@smallexample
f7dc1244 13171(@value{GDBP}) info macro N
e2e0bcd1
JB
13172Defined at /home/jimb/gdb/macros/play/sample.c:9
13173#define N 28
f7dc1244 13174(@value{GDBP}) macro expand N Q M
e2e0bcd1 13175expands to: 28 < 42
f7dc1244 13176(@value{GDBP}) print N Q M
e2e0bcd1 13177$1 = 1
f7dc1244 13178(@value{GDBP})
e2e0bcd1
JB
13179@end smallexample
13180
13181As we step over directives that remove @code{N}'s definition, and then
13182give it a new definition, @value{GDBN} finds the definition (or lack
13183thereof) in force at each point:
13184
13185@smallexample
f7dc1244 13186(@value{GDBP}) next
e2e0bcd1
JB
13187Hello, world!
1318812 printf ("We're so creative.\n");
f7dc1244 13189(@value{GDBP}) info macro N
e2e0bcd1
JB
13190The symbol `N' has no definition as a C/C++ preprocessor macro
13191at /home/jimb/gdb/macros/play/sample.c:12
f7dc1244 13192(@value{GDBP}) next
e2e0bcd1
JB
13193We're so creative.
1319414 printf ("Goodbye, world!\n");
f7dc1244 13195(@value{GDBP}) info macro N
e2e0bcd1
JB
13196Defined at /home/jimb/gdb/macros/play/sample.c:13
13197#define N 1729
f7dc1244 13198(@value{GDBP}) macro expand N Q M
e2e0bcd1 13199expands to: 1729 < 42
f7dc1244 13200(@value{GDBP}) print N Q M
e2e0bcd1 13201$2 = 0
f7dc1244 13202(@value{GDBP})
e2e0bcd1
JB
13203@end smallexample
13204
484086b7
JK
13205In addition to source files, macros can be defined on the compilation command
13206line using the @option{-D@var{name}=@var{value}} syntax. For macros defined in
13207such a way, @value{GDBN} displays the location of their definition as line zero
13208of the source file submitted to the compiler.
13209
13210@smallexample
13211(@value{GDBP}) info macro __STDC__
13212Defined at /home/jimb/gdb/macros/play/sample.c:0
13213-D__STDC__=1
13214(@value{GDBP})
13215@end smallexample
13216
e2e0bcd1 13217
b37052ae
EZ
13218@node Tracepoints
13219@chapter Tracepoints
13220@c This chapter is based on the documentation written by Michael
13221@c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
13222
13223@cindex tracepoints
13224In some applications, it is not feasible for the debugger to interrupt
13225the program's execution long enough for the developer to learn
13226anything helpful about its behavior. If the program's correctness
13227depends on its real-time behavior, delays introduced by a debugger
13228might cause the program to change its behavior drastically, or perhaps
13229fail, even when the code itself is correct. It is useful to be able
13230to observe the program's behavior without interrupting it.
13231
13232Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
13233specify locations in the program, called @dfn{tracepoints}, and
13234arbitrary expressions to evaluate when those tracepoints are reached.
13235Later, using the @code{tfind} command, you can examine the values
13236those expressions had when the program hit the tracepoints. The
13237expressions may also denote objects in memory---structures or arrays,
13238for example---whose values @value{GDBN} should record; while visiting
13239a particular tracepoint, you may inspect those objects as if they were
13240in memory at that moment. However, because @value{GDBN} records these
13241values without interacting with you, it can do so quickly and
13242unobtrusively, hopefully not disturbing the program's behavior.
13243
13244The tracepoint facility is currently available only for remote
9d29849a
JB
13245targets. @xref{Targets}. In addition, your remote target must know
13246how to collect trace data. This functionality is implemented in the
13247remote stub; however, none of the stubs distributed with @value{GDBN}
13248support tracepoints as of this writing. The format of the remote
13249packets used to implement tracepoints are described in @ref{Tracepoint
13250Packets}.
b37052ae 13251
00bf0b85
SS
13252It is also possible to get trace data from a file, in a manner reminiscent
13253of corefiles; you specify the filename, and use @code{tfind} to search
13254through the file. @xref{Trace Files}, for more details.
13255
b37052ae
EZ
13256This chapter describes the tracepoint commands and features.
13257
13258@menu
b383017d
RM
13259* Set Tracepoints::
13260* Analyze Collected Data::
13261* Tracepoint Variables::
00bf0b85 13262* Trace Files::
b37052ae
EZ
13263@end menu
13264
13265@node Set Tracepoints
13266@section Commands to Set Tracepoints
13267
13268Before running such a @dfn{trace experiment}, an arbitrary number of
1042e4c0
SS
13269tracepoints can be set. A tracepoint is actually a special type of
13270breakpoint (@pxref{Set Breaks}), so you can manipulate it using
13271standard breakpoint commands. For instance, as with breakpoints,
13272tracepoint numbers are successive integers starting from one, and many
13273of the commands associated with tracepoints take the tracepoint number
13274as their argument, to identify which tracepoint to work on.
b37052ae
EZ
13275
13276For each tracepoint, you can specify, in advance, some arbitrary set
13277of data that you want the target to collect in the trace buffer when
13278it hits that tracepoint. The collected data can include registers,
13279local variables, or global data. Later, you can use @value{GDBN}
13280commands to examine the values these data had at the time the
13281tracepoint was hit.
13282
7d13fe92
SS
13283Tracepoints do not support every breakpoint feature. Ignore counts on
13284tracepoints have no effect, and tracepoints cannot run @value{GDBN}
13285commands when they are hit. Tracepoints may not be thread-specific
13286either.
1042e4c0 13287
7a697b8d
SS
13288@cindex fast tracepoints
13289Some targets may support @dfn{fast tracepoints}, which are inserted in
13290a different way (such as with a jump instead of a trap), that is
13291faster but possibly restricted in where they may be installed.
13292
0fb4aa4b
PA
13293@cindex static tracepoints
13294@cindex markers, static tracepoints
13295@cindex probing markers, static tracepoints
13296Regular and fast tracepoints are dynamic tracing facilities, meaning
13297that they can be used to insert tracepoints at (almost) any location
13298in the target. Some targets may also support controlling @dfn{static
13299tracepoints} from @value{GDBN}. With static tracing, a set of
13300instrumentation points, also known as @dfn{markers}, are embedded in
13301the target program, and can be activated or deactivated by name or
13302address. These are usually placed at locations which facilitate
13303investigating what the target is actually doing. @value{GDBN}'s
13304support for static tracing includes being able to list instrumentation
13305points, and attach them with @value{GDBN} defined high level
13306tracepoints that expose the whole range of convenience of
8786b2bd 13307@value{GDBN}'s tracepoints support. Namely, support for collecting
0fb4aa4b
PA
13308registers values and values of global or local (to the instrumentation
13309point) variables; tracepoint conditions and trace state variables.
13310The act of installing a @value{GDBN} static tracepoint on an
13311instrumentation point, or marker, is referred to as @dfn{probing} a
13312static tracepoint marker.
13313
fa593d66
PA
13314@code{gdbserver} supports tracepoints on some target systems.
13315@xref{Server,,Tracepoints support in @code{gdbserver}}.
13316
b37052ae
EZ
13317This section describes commands to set tracepoints and associated
13318conditions and actions.
13319
13320@menu
b383017d
RM
13321* Create and Delete Tracepoints::
13322* Enable and Disable Tracepoints::
13323* Tracepoint Passcounts::
782b2b07 13324* Tracepoint Conditions::
f61e138d 13325* Trace State Variables::
b383017d
RM
13326* Tracepoint Actions::
13327* Listing Tracepoints::
0fb4aa4b 13328* Listing Static Tracepoint Markers::
79a6e687 13329* Starting and Stopping Trace Experiments::
c9429232 13330* Tracepoint Restrictions::
b37052ae
EZ
13331@end menu
13332
13333@node Create and Delete Tracepoints
13334@subsection Create and Delete Tracepoints
13335
13336@table @code
13337@cindex set tracepoint
13338@kindex trace
1042e4c0 13339@item trace @var{location}
b37052ae 13340The @code{trace} command is very similar to the @code{break} command.
629500fa
KS
13341Its argument @var{location} can be any valid location.
13342@xref{Specify Location}. The @code{trace} command defines a tracepoint,
13343which is a point in the target program where the debugger will briefly stop,
13344collect some data, and then allow the program to continue. Setting a tracepoint
13345or changing its actions takes effect immediately if the remote stub
1e4d1764
YQ
13346supports the @samp{InstallInTrace} feature (@pxref{install tracepoint
13347in tracing}).
13348If remote stub doesn't support the @samp{InstallInTrace} feature, all
13349these changes don't take effect until the next @code{tstart}
1042e4c0 13350command, and once a trace experiment is running, further changes will
bfccc43c
YQ
13351not have any effect until the next trace experiment starts. In addition,
13352@value{GDBN} supports @dfn{pending tracepoints}---tracepoints whose
13353address is not yet resolved. (This is similar to pending breakpoints.)
13354Pending tracepoints are not downloaded to the target and not installed
13355until they are resolved. The resolution of pending tracepoints requires
13356@value{GDBN} support---when debugging with the remote target, and
13357@value{GDBN} disconnects from the remote stub (@pxref{disconnected
13358tracing}), pending tracepoints can not be resolved (and downloaded to
13359the remote stub) while @value{GDBN} is disconnected.
b37052ae
EZ
13360
13361Here are some examples of using the @code{trace} command:
13362
13363@smallexample
13364(@value{GDBP}) @b{trace foo.c:121} // a source file and line number
13365
13366(@value{GDBP}) @b{trace +2} // 2 lines forward
13367
13368(@value{GDBP}) @b{trace my_function} // first source line of function
13369
13370(@value{GDBP}) @b{trace *my_function} // EXACT start address of function
13371
13372(@value{GDBP}) @b{trace *0x2117c4} // an address
13373@end smallexample
13374
13375@noindent
13376You can abbreviate @code{trace} as @code{tr}.
13377
782b2b07
SS
13378@item trace @var{location} if @var{cond}
13379Set a tracepoint with condition @var{cond}; evaluate the expression
13380@var{cond} each time the tracepoint is reached, and collect data only
13381if the value is nonzero---that is, if @var{cond} evaluates as true.
13382@xref{Tracepoint Conditions, ,Tracepoint Conditions}, for more
13383information on tracepoint conditions.
13384
7a697b8d
SS
13385@item ftrace @var{location} [ if @var{cond} ]
13386@cindex set fast tracepoint
74c761c1 13387@cindex fast tracepoints, setting
7a697b8d
SS
13388@kindex ftrace
13389The @code{ftrace} command sets a fast tracepoint. For targets that
13390support them, fast tracepoints will use a more efficient but possibly
13391less general technique to trigger data collection, such as a jump
13392instruction instead of a trap, or some sort of hardware support. It
13393may not be possible to create a fast tracepoint at the desired
13394location, in which case the command will exit with an explanatory
13395message.
13396
13397@value{GDBN} handles arguments to @code{ftrace} exactly as for
13398@code{trace}.
13399
405f8e94
SS
13400On 32-bit x86-architecture systems, fast tracepoints normally need to
13401be placed at an instruction that is 5 bytes or longer, but can be
13402placed at 4-byte instructions if the low 64K of memory of the target
13403program is available to install trampolines. Some Unix-type systems,
13404such as @sc{gnu}/Linux, exclude low addresses from the program's
13405address space; but for instance with the Linux kernel it is possible
13406to let @value{GDBN} use this area by doing a @command{sysctl} command
13407to set the @code{mmap_min_addr} kernel parameter, as in
13408
13409@example
13410sudo sysctl -w vm.mmap_min_addr=32768
13411@end example
13412
13413@noindent
13414which sets the low address to 32K, which leaves plenty of room for
13415trampolines. The minimum address should be set to a page boundary.
13416
0fb4aa4b 13417@item strace @var{location} [ if @var{cond} ]
74c761c1
PA
13418@cindex set static tracepoint
13419@cindex static tracepoints, setting
13420@cindex probe static tracepoint marker
0fb4aa4b
PA
13421@kindex strace
13422The @code{strace} command sets a static tracepoint. For targets that
13423support it, setting a static tracepoint probes a static
13424instrumentation point, or marker, found at @var{location}. It may not
13425be possible to set a static tracepoint at the desired location, in
13426which case the command will exit with an explanatory message.
13427
13428@value{GDBN} handles arguments to @code{strace} exactly as for
13429@code{trace}, with the addition that the user can also specify
13430@code{-m @var{marker}} as @var{location}. This probes the marker
13431identified by the @var{marker} string identifier. This identifier
13432depends on the static tracepoint backend library your program is
13433using. You can find all the marker identifiers in the @samp{ID} field
13434of the @code{info static-tracepoint-markers} command output.
13435@xref{Listing Static Tracepoint Markers,,Listing Static Tracepoint
13436Markers}. For example, in the following small program using the UST
13437tracing engine:
13438
13439@smallexample
13440main ()
13441@{
13442 trace_mark(ust, bar33, "str %s", "FOOBAZ");
13443@}
13444@end smallexample
13445
13446@noindent
13447the marker id is composed of joining the first two arguments to the
13448@code{trace_mark} call with a slash, which translates to:
13449
13450@smallexample
13451(@value{GDBP}) info static-tracepoint-markers
13452Cnt Enb ID Address What
134531 n ust/bar33 0x0000000000400ddc in main at stexample.c:22
13454 Data: "str %s"
13455[etc...]
13456@end smallexample
13457
13458@noindent
13459so you may probe the marker above with:
13460
13461@smallexample
13462(@value{GDBP}) strace -m ust/bar33
13463@end smallexample
13464
13465Static tracepoints accept an extra collect action --- @code{collect
13466$_sdata}. This collects arbitrary user data passed in the probe point
13467call to the tracing library. In the UST example above, you'll see
13468that the third argument to @code{trace_mark} is a printf-like format
13469string. The user data is then the result of running that formating
13470string against the following arguments. Note that @code{info
13471static-tracepoint-markers} command output lists that format string in
13472the @samp{Data:} field.
13473
13474You can inspect this data when analyzing the trace buffer, by printing
13475the $_sdata variable like any other variable available to
13476@value{GDBN}. @xref{Tracepoint Actions,,Tracepoint Action Lists}.
13477
b37052ae
EZ
13478@vindex $tpnum
13479@cindex last tracepoint number
13480@cindex recent tracepoint number
13481@cindex tracepoint number
13482The convenience variable @code{$tpnum} records the tracepoint number
13483of the most recently set tracepoint.
13484
13485@kindex delete tracepoint
13486@cindex tracepoint deletion
13487@item delete tracepoint @r{[}@var{num}@r{]}
13488Permanently delete one or more tracepoints. With no argument, the
1042e4c0
SS
13489default is to delete all tracepoints. Note that the regular
13490@code{delete} command can remove tracepoints also.
b37052ae
EZ
13491
13492Examples:
13493
13494@smallexample
13495(@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
13496
13497(@value{GDBP}) @b{delete trace} // remove all tracepoints
13498@end smallexample
13499
13500@noindent
13501You can abbreviate this command as @code{del tr}.
13502@end table
13503
13504@node Enable and Disable Tracepoints
13505@subsection Enable and Disable Tracepoints
13506
1042e4c0
SS
13507These commands are deprecated; they are equivalent to plain @code{disable} and @code{enable}.
13508
b37052ae
EZ
13509@table @code
13510@kindex disable tracepoint
13511@item disable tracepoint @r{[}@var{num}@r{]}
13512Disable tracepoint @var{num}, or all tracepoints if no argument
13513@var{num} is given. A disabled tracepoint will have no effect during
d248b706 13514a trace experiment, but it is not forgotten. You can re-enable
b37052ae 13515a disabled tracepoint using the @code{enable tracepoint} command.
d248b706
KY
13516If the command is issued during a trace experiment and the debug target
13517has support for disabling tracepoints during a trace experiment, then the
13518change will be effective immediately. Otherwise, it will be applied to the
13519next trace experiment.
b37052ae
EZ
13520
13521@kindex enable tracepoint
13522@item enable tracepoint @r{[}@var{num}@r{]}
d248b706
KY
13523Enable tracepoint @var{num}, or all tracepoints. If this command is
13524issued during a trace experiment and the debug target supports enabling
13525tracepoints during a trace experiment, then the enabled tracepoints will
13526become effective immediately. Otherwise, they will become effective the
13527next time a trace experiment is run.
b37052ae
EZ
13528@end table
13529
13530@node Tracepoint Passcounts
13531@subsection Tracepoint Passcounts
13532
13533@table @code
13534@kindex passcount
13535@cindex tracepoint pass count
13536@item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
13537Set the @dfn{passcount} of a tracepoint. The passcount is a way to
13538automatically stop a trace experiment. If a tracepoint's passcount is
13539@var{n}, then the trace experiment will be automatically stopped on
13540the @var{n}'th time that tracepoint is hit. If the tracepoint number
13541@var{num} is not specified, the @code{passcount} command sets the
13542passcount of the most recently defined tracepoint. If no passcount is
13543given, the trace experiment will run until stopped explicitly by the
13544user.
13545
13546Examples:
13547
13548@smallexample
b383017d 13549(@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
6826cf00 13550@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
b37052ae
EZ
13551
13552(@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
6826cf00 13553@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
b37052ae
EZ
13554(@value{GDBP}) @b{trace foo}
13555(@value{GDBP}) @b{pass 3}
13556(@value{GDBP}) @b{trace bar}
13557(@value{GDBP}) @b{pass 2}
13558(@value{GDBP}) @b{trace baz}
13559(@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
6826cf00
EZ
13560@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
13561@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
13562@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
b37052ae
EZ
13563@end smallexample
13564@end table
13565
782b2b07
SS
13566@node Tracepoint Conditions
13567@subsection Tracepoint Conditions
13568@cindex conditional tracepoints
13569@cindex tracepoint conditions
13570
13571The simplest sort of tracepoint collects data every time your program
13572reaches a specified place. You can also specify a @dfn{condition} for
13573a tracepoint. A condition is just a Boolean expression in your
13574programming language (@pxref{Expressions, ,Expressions}). A
13575tracepoint with a condition evaluates the expression each time your
13576program reaches it, and data collection happens only if the condition
13577is true.
13578
13579Tracepoint conditions can be specified when a tracepoint is set, by
13580using @samp{if} in the arguments to the @code{trace} command.
13581@xref{Create and Delete Tracepoints, ,Setting Tracepoints}. They can
13582also be set or changed at any time with the @code{condition} command,
13583just as with breakpoints.
13584
13585Unlike breakpoint conditions, @value{GDBN} does not actually evaluate
13586the conditional expression itself. Instead, @value{GDBN} encodes the
6dcd5565 13587expression into an agent expression (@pxref{Agent Expressions})
782b2b07
SS
13588suitable for execution on the target, independently of @value{GDBN}.
13589Global variables become raw memory locations, locals become stack
13590accesses, and so forth.
13591
13592For instance, suppose you have a function that is usually called
13593frequently, but should not be called after an error has occurred. You
13594could use the following tracepoint command to collect data about calls
13595of that function that happen while the error code is propagating
13596through the program; an unconditional tracepoint could end up
13597collecting thousands of useless trace frames that you would have to
13598search through.
13599
13600@smallexample
13601(@value{GDBP}) @kbd{trace normal_operation if errcode > 0}
13602@end smallexample
13603
f61e138d
SS
13604@node Trace State Variables
13605@subsection Trace State Variables
13606@cindex trace state variables
13607
13608A @dfn{trace state variable} is a special type of variable that is
13609created and managed by target-side code. The syntax is the same as
13610that for GDB's convenience variables (a string prefixed with ``$''),
13611but they are stored on the target. They must be created explicitly,
13612using a @code{tvariable} command. They are always 64-bit signed
13613integers.
13614
13615Trace state variables are remembered by @value{GDBN}, and downloaded
13616to the target along with tracepoint information when the trace
13617experiment starts. There are no intrinsic limits on the number of
13618trace state variables, beyond memory limitations of the target.
13619
13620@cindex convenience variables, and trace state variables
13621Although trace state variables are managed by the target, you can use
13622them in print commands and expressions as if they were convenience
13623variables; @value{GDBN} will get the current value from the target
13624while the trace experiment is running. Trace state variables share
13625the same namespace as other ``$'' variables, which means that you
13626cannot have trace state variables with names like @code{$23} or
13627@code{$pc}, nor can you have a trace state variable and a convenience
13628variable with the same name.
13629
13630@table @code
13631
13632@item tvariable $@var{name} [ = @var{expression} ]
13633@kindex tvariable
13634The @code{tvariable} command creates a new trace state variable named
13635@code{$@var{name}}, and optionally gives it an initial value of
697aa1b7 13636@var{expression}. The @var{expression} is evaluated when this command is
f61e138d
SS
13637entered; the result will be converted to an integer if possible,
13638otherwise @value{GDBN} will report an error. A subsequent
13639@code{tvariable} command specifying the same name does not create a
13640variable, but instead assigns the supplied initial value to the
13641existing variable of that name, overwriting any previous initial
13642value. The default initial value is 0.
13643
13644@item info tvariables
13645@kindex info tvariables
13646List all the trace state variables along with their initial values.
13647Their current values may also be displayed, if the trace experiment is
13648currently running.
13649
13650@item delete tvariable @r{[} $@var{name} @dots{} @r{]}
13651@kindex delete tvariable
13652Delete the given trace state variables, or all of them if no arguments
13653are specified.
13654
13655@end table
13656
b37052ae
EZ
13657@node Tracepoint Actions
13658@subsection Tracepoint Action Lists
13659
13660@table @code
13661@kindex actions
13662@cindex tracepoint actions
13663@item actions @r{[}@var{num}@r{]}
13664This command will prompt for a list of actions to be taken when the
13665tracepoint is hit. If the tracepoint number @var{num} is not
13666specified, this command sets the actions for the one that was most
13667recently defined (so that you can define a tracepoint and then say
13668@code{actions} without bothering about its number). You specify the
13669actions themselves on the following lines, one action at a time, and
13670terminate the actions list with a line containing just @code{end}. So
7d13fe92 13671far, the only defined actions are @code{collect}, @code{teval}, and
b37052ae
EZ
13672@code{while-stepping}.
13673
5a9351ae
SS
13674@code{actions} is actually equivalent to @code{commands} (@pxref{Break
13675Commands, ,Breakpoint Command Lists}), except that only the defined
13676actions are allowed; any other @value{GDBN} command is rejected.
13677
b37052ae
EZ
13678@cindex remove actions from a tracepoint
13679To remove all actions from a tracepoint, type @samp{actions @var{num}}
13680and follow it immediately with @samp{end}.
13681
13682@smallexample
13683(@value{GDBP}) @b{collect @var{data}} // collect some data
13684
6826cf00 13685(@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
b37052ae 13686
6826cf00 13687(@value{GDBP}) @b{end} // signals the end of actions.
b37052ae
EZ
13688@end smallexample
13689
13690In the following example, the action list begins with @code{collect}
13691commands indicating the things to be collected when the tracepoint is
13692hit. Then, in order to single-step and collect additional data
13693following the tracepoint, a @code{while-stepping} command is used,
7d13fe92
SS
13694followed by the list of things to be collected after each step in a
13695sequence of single steps. The @code{while-stepping} command is
13696terminated by its own separate @code{end} command. Lastly, the action
13697list is terminated by an @code{end} command.
b37052ae
EZ
13698
13699@smallexample
13700(@value{GDBP}) @b{trace foo}
13701(@value{GDBP}) @b{actions}
13702Enter actions for tracepoint 1, one per line:
13703> collect bar,baz
13704> collect $regs
13705> while-stepping 12
5a9351ae 13706 > collect $pc, arr[i]
b37052ae
EZ
13707 > end
13708end
13709@end smallexample
13710
13711@kindex collect @r{(tracepoints)}
3065dfb6 13712@item collect@r{[}/@var{mods}@r{]} @var{expr1}, @var{expr2}, @dots{}
b37052ae
EZ
13713Collect values of the given expressions when the tracepoint is hit.
13714This command accepts a comma-separated list of any valid expressions.
13715In addition to global, static, or local variables, the following
13716special arguments are supported:
13717
13718@table @code
13719@item $regs
0fb4aa4b 13720Collect all registers.
b37052ae
EZ
13721
13722@item $args
0fb4aa4b 13723Collect all function arguments.
b37052ae
EZ
13724
13725@item $locals
0fb4aa4b
PA
13726Collect all local variables.
13727
6710bf39
SS
13728@item $_ret
13729Collect the return address. This is helpful if you want to see more
13730of a backtrace.
13731
2a60e18f 13732@emph{Note:} The return address location can not always be reliably
45fa2529
PA
13733determined up front, and the wrong address / registers may end up
13734collected instead. On some architectures the reliability is higher
13735for tracepoints at function entry, while on others it's the opposite.
13736When this happens, backtracing will stop because the return address is
13737found unavailable (unless another collect rule happened to match it).
13738
62e5f89c
SDJ
13739@item $_probe_argc
13740Collects the number of arguments from the static probe at which the
13741tracepoint is located.
13742@xref{Static Probe Points}.
13743
13744@item $_probe_arg@var{n}
13745@var{n} is an integer between 0 and 11. Collects the @var{n}th argument
13746from the static probe at which the tracepoint is located.
13747@xref{Static Probe Points}.
13748
0fb4aa4b
PA
13749@item $_sdata
13750@vindex $_sdata@r{, collect}
13751Collect static tracepoint marker specific data. Only available for
13752static tracepoints. @xref{Tracepoint Actions,,Tracepoint Action
13753Lists}. On the UST static tracepoints library backend, an
13754instrumentation point resembles a @code{printf} function call. The
13755tracing library is able to collect user specified data formatted to a
13756character string using the format provided by the programmer that
13757instrumented the program. Other backends have similar mechanisms.
13758Here's an example of a UST marker call:
13759
13760@smallexample
13761 const char master_name[] = "$your_name";
13762 trace_mark(channel1, marker1, "hello %s", master_name)
13763@end smallexample
13764
13765In this case, collecting @code{$_sdata} collects the string
13766@samp{hello $yourname}. When analyzing the trace buffer, you can
13767inspect @samp{$_sdata} like any other variable available to
13768@value{GDBN}.
b37052ae
EZ
13769@end table
13770
13771You can give several consecutive @code{collect} commands, each one
13772with a single argument, or one @code{collect} command with several
5a9351ae 13773arguments separated by commas; the effect is the same.
b37052ae 13774
3065dfb6
SS
13775The optional @var{mods} changes the usual handling of the arguments.
13776@code{s} requests that pointers to chars be handled as strings, in
13777particular collecting the contents of the memory being pointed at, up
13778to the first zero. The upper bound is by default the value of the
13779@code{print elements} variable; if @code{s} is followed by a decimal
13780number, that is the upper bound instead. So for instance
13781@samp{collect/s25 mystr} collects as many as 25 characters at
13782@samp{mystr}.
13783
f5c37c66
EZ
13784The command @code{info scope} (@pxref{Symbols, info scope}) is
13785particularly useful for figuring out what data to collect.
13786
6da95a67
SS
13787@kindex teval @r{(tracepoints)}
13788@item teval @var{expr1}, @var{expr2}, @dots{}
13789Evaluate the given expressions when the tracepoint is hit. This
13790command accepts a comma-separated list of expressions. The results
13791are discarded, so this is mainly useful for assigning values to trace
13792state variables (@pxref{Trace State Variables}) without adding those
13793values to the trace buffer, as would be the case if the @code{collect}
13794action were used.
13795
b37052ae
EZ
13796@kindex while-stepping @r{(tracepoints)}
13797@item while-stepping @var{n}
c9429232 13798Perform @var{n} single-step instruction traces after the tracepoint,
7d13fe92 13799collecting new data after each step. The @code{while-stepping}
c9429232
SS
13800command is followed by the list of what to collect while stepping
13801(followed by its own @code{end} command):
b37052ae
EZ
13802
13803@smallexample
13804> while-stepping 12
13805 > collect $regs, myglobal
13806 > end
13807>
13808@end smallexample
13809
13810@noindent
7d13fe92
SS
13811Note that @code{$pc} is not automatically collected by
13812@code{while-stepping}; you need to explicitly collect that register if
13813you need it. You may abbreviate @code{while-stepping} as @code{ws} or
b37052ae 13814@code{stepping}.
236f1d4d
SS
13815
13816@item set default-collect @var{expr1}, @var{expr2}, @dots{}
13817@kindex set default-collect
13818@cindex default collection action
13819This variable is a list of expressions to collect at each tracepoint
13820hit. It is effectively an additional @code{collect} action prepended
13821to every tracepoint action list. The expressions are parsed
13822individually for each tracepoint, so for instance a variable named
13823@code{xyz} may be interpreted as a global for one tracepoint, and a
13824local for another, as appropriate to the tracepoint's location.
13825
13826@item show default-collect
13827@kindex show default-collect
13828Show the list of expressions that are collected by default at each
13829tracepoint hit.
13830
b37052ae
EZ
13831@end table
13832
13833@node Listing Tracepoints
13834@subsection Listing Tracepoints
13835
13836@table @code
e5a67952
MS
13837@kindex info tracepoints @r{[}@var{n}@dots{}@r{]}
13838@kindex info tp @r{[}@var{n}@dots{}@r{]}
b37052ae 13839@cindex information about tracepoints
e5a67952 13840@item info tracepoints @r{[}@var{num}@dots{}@r{]}
1042e4c0
SS
13841Display information about the tracepoint @var{num}. If you don't
13842specify a tracepoint number, displays information about all the
13843tracepoints defined so far. The format is similar to that used for
13844@code{info breakpoints}; in fact, @code{info tracepoints} is the same
13845command, simply restricting itself to tracepoints.
13846
13847A tracepoint's listing may include additional information specific to
13848tracing:
b37052ae
EZ
13849
13850@itemize @bullet
13851@item
b37052ae 13852its passcount as given by the @code{passcount @var{n}} command
f2a8bc8a
YQ
13853
13854@item
13855the state about installed on target of each location
b37052ae
EZ
13856@end itemize
13857
13858@smallexample
13859(@value{GDBP}) @b{info trace}
1042e4c0
SS
13860Num Type Disp Enb Address What
138611 tracepoint keep y 0x0804ab57 in foo() at main.cxx:7
5a9351ae
SS
13862 while-stepping 20
13863 collect globfoo, $regs
13864 end
13865 collect globfoo2
13866 end
1042e4c0 13867 pass count 1200
f2a8bc8a
YQ
138682 tracepoint keep y <MULTIPLE>
13869 collect $eip
138702.1 y 0x0804859c in func4 at change-loc.h:35
13871 installed on target
138722.2 y 0xb7ffc480 in func4 at change-loc.h:35
13873 installed on target
138742.3 y <PENDING> set_tracepoint
138753 tracepoint keep y 0x080485b1 in foo at change-loc.c:29
13876 not installed on target
b37052ae
EZ
13877(@value{GDBP})
13878@end smallexample
13879
13880@noindent
13881This command can be abbreviated @code{info tp}.
13882@end table
13883
0fb4aa4b
PA
13884@node Listing Static Tracepoint Markers
13885@subsection Listing Static Tracepoint Markers
13886
13887@table @code
13888@kindex info static-tracepoint-markers
13889@cindex information about static tracepoint markers
13890@item info static-tracepoint-markers
13891Display information about all static tracepoint markers defined in the
13892program.
13893
13894For each marker, the following columns are printed:
13895
13896@table @emph
13897@item Count
13898An incrementing counter, output to help readability. This is not a
13899stable identifier.
13900@item ID
13901The marker ID, as reported by the target.
13902@item Enabled or Disabled
13903Probed markers are tagged with @samp{y}. @samp{n} identifies marks
13904that are not enabled.
13905@item Address
13906Where the marker is in your program, as a memory address.
13907@item What
13908Where the marker is in the source for your program, as a file and line
13909number. If the debug information included in the program does not
13910allow @value{GDBN} to locate the source of the marker, this column
13911will be left blank.
13912@end table
13913
13914@noindent
13915In addition, the following information may be printed for each marker:
13916
13917@table @emph
13918@item Data
13919User data passed to the tracing library by the marker call. In the
13920UST backend, this is the format string passed as argument to the
13921marker call.
13922@item Static tracepoints probing the marker
13923The list of static tracepoints attached to the marker.
13924@end table
13925
13926@smallexample
13927(@value{GDBP}) info static-tracepoint-markers
13928Cnt ID Enb Address What
139291 ust/bar2 y 0x0000000000400e1a in main at stexample.c:25
13930 Data: number1 %d number2 %d
13931 Probed by static tracepoints: #2
139322 ust/bar33 n 0x0000000000400c87 in main at stexample.c:24
13933 Data: str %s
13934(@value{GDBP})
13935@end smallexample
13936@end table
13937
79a6e687
BW
13938@node Starting and Stopping Trace Experiments
13939@subsection Starting and Stopping Trace Experiments
b37052ae
EZ
13940
13941@table @code
f196051f 13942@kindex tstart [ @var{notes} ]
b37052ae
EZ
13943@cindex start a new trace experiment
13944@cindex collected data discarded
13945@item tstart
f196051f
SS
13946This command starts the trace experiment, and begins collecting data.
13947It has the side effect of discarding all the data collected in the
13948trace buffer during the previous trace experiment. If any arguments
13949are supplied, they are taken as a note and stored with the trace
13950experiment's state. The notes may be arbitrary text, and are
13951especially useful with disconnected tracing in a multi-user context;
13952the notes can explain what the trace is doing, supply user contact
13953information, and so forth.
13954
13955@kindex tstop [ @var{notes} ]
b37052ae
EZ
13956@cindex stop a running trace experiment
13957@item tstop
f196051f
SS
13958This command stops the trace experiment. If any arguments are
13959supplied, they are recorded with the experiment as a note. This is
13960useful if you are stopping a trace started by someone else, for
13961instance if the trace is interfering with the system's behavior and
13962needs to be stopped quickly.
b37052ae 13963
68c71a2e 13964@strong{Note}: a trace experiment and data collection may stop
b37052ae
EZ
13965automatically if any tracepoint's passcount is reached
13966(@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
13967
13968@kindex tstatus
13969@cindex status of trace data collection
13970@cindex trace experiment, status of
13971@item tstatus
13972This command displays the status of the current trace data
13973collection.
13974@end table
13975
13976Here is an example of the commands we described so far:
13977
13978@smallexample
13979(@value{GDBP}) @b{trace gdb_c_test}
13980(@value{GDBP}) @b{actions}
13981Enter actions for tracepoint #1, one per line.
13982> collect $regs,$locals,$args
13983> while-stepping 11
13984 > collect $regs
13985 > end
13986> end
13987(@value{GDBP}) @b{tstart}
13988 [time passes @dots{}]
13989(@value{GDBP}) @b{tstop}
13990@end smallexample
13991
03f2bd59 13992@anchor{disconnected tracing}
d5551862
SS
13993@cindex disconnected tracing
13994You can choose to continue running the trace experiment even if
13995@value{GDBN} disconnects from the target, voluntarily or
13996involuntarily. For commands such as @code{detach}, the debugger will
13997ask what you want to do with the trace. But for unexpected
13998terminations (@value{GDBN} crash, network outage), it would be
13999unfortunate to lose hard-won trace data, so the variable
14000@code{disconnected-tracing} lets you decide whether the trace should
14001continue running without @value{GDBN}.
14002
14003@table @code
14004@item set disconnected-tracing on
14005@itemx set disconnected-tracing off
14006@kindex set disconnected-tracing
14007Choose whether a tracing run should continue to run if @value{GDBN}
14008has disconnected from the target. Note that @code{detach} or
14009@code{quit} will ask you directly what to do about a running trace no
14010matter what this variable's setting, so the variable is mainly useful
14011for handling unexpected situations, such as loss of the network.
14012
14013@item show disconnected-tracing
14014@kindex show disconnected-tracing
14015Show the current choice for disconnected tracing.
14016
14017@end table
14018
14019When you reconnect to the target, the trace experiment may or may not
14020still be running; it might have filled the trace buffer in the
14021meantime, or stopped for one of the other reasons. If it is running,
14022it will continue after reconnection.
14023
14024Upon reconnection, the target will upload information about the
14025tracepoints in effect. @value{GDBN} will then compare that
14026information to the set of tracepoints currently defined, and attempt
14027to match them up, allowing for the possibility that the numbers may
14028have changed due to creation and deletion in the meantime. If one of
14029the target's tracepoints does not match any in @value{GDBN}, the
14030debugger will create a new tracepoint, so that you have a number with
14031which to specify that tracepoint. This matching-up process is
14032necessarily heuristic, and it may result in useless tracepoints being
14033created; you may simply delete them if they are of no use.
b37052ae 14034
4daf5ac0
SS
14035@cindex circular trace buffer
14036If your target agent supports a @dfn{circular trace buffer}, then you
14037can run a trace experiment indefinitely without filling the trace
14038buffer; when space runs out, the agent deletes already-collected trace
14039frames, oldest first, until there is enough room to continue
14040collecting. This is especially useful if your tracepoints are being
14041hit too often, and your trace gets terminated prematurely because the
14042buffer is full. To ask for a circular trace buffer, simply set
81896e36 14043@samp{circular-trace-buffer} to on. You can set this at any time,
4daf5ac0
SS
14044including during tracing; if the agent can do it, it will change
14045buffer handling on the fly, otherwise it will not take effect until
14046the next run.
14047
14048@table @code
14049@item set circular-trace-buffer on
14050@itemx set circular-trace-buffer off
14051@kindex set circular-trace-buffer
14052Choose whether a tracing run should use a linear or circular buffer
14053for trace data. A linear buffer will not lose any trace data, but may
14054fill up prematurely, while a circular buffer will discard old trace
14055data, but it will have always room for the latest tracepoint hits.
14056
14057@item show circular-trace-buffer
14058@kindex show circular-trace-buffer
14059Show the current choice for the trace buffer. Note that this may not
14060match the agent's current buffer handling, nor is it guaranteed to
14061match the setting that might have been in effect during a past run,
14062for instance if you are looking at frames from a trace file.
14063
14064@end table
14065
f6f899bf
HAQ
14066@table @code
14067@item set trace-buffer-size @var{n}
f81d1120 14068@itemx set trace-buffer-size unlimited
f6f899bf
HAQ
14069@kindex set trace-buffer-size
14070Request that the target use a trace buffer of @var{n} bytes. Not all
14071targets will honor the request; they may have a compiled-in size for
14072the trace buffer, or some other limitation. Set to a value of
f81d1120
PA
14073@code{unlimited} or @code{-1} to let the target use whatever size it
14074likes. This is also the default.
f6f899bf
HAQ
14075
14076@item show trace-buffer-size
14077@kindex show trace-buffer-size
14078Show the current requested size for the trace buffer. Note that this
14079will only match the actual size if the target supports size-setting,
14080and was able to handle the requested size. For instance, if the
14081target can only change buffer size between runs, this variable will
14082not reflect the change until the next run starts. Use @code{tstatus}
14083to get a report of the actual buffer size.
14084@end table
14085
f196051f
SS
14086@table @code
14087@item set trace-user @var{text}
14088@kindex set trace-user
14089
14090@item show trace-user
14091@kindex show trace-user
14092
14093@item set trace-notes @var{text}
14094@kindex set trace-notes
14095Set the trace run's notes.
14096
14097@item show trace-notes
14098@kindex show trace-notes
14099Show the trace run's notes.
14100
14101@item set trace-stop-notes @var{text}
14102@kindex set trace-stop-notes
14103Set the trace run's stop notes. The handling of the note is as for
14104@code{tstop} arguments; the set command is convenient way to fix a
14105stop note that is mistaken or incomplete.
14106
14107@item show trace-stop-notes
14108@kindex show trace-stop-notes
14109Show the trace run's stop notes.
14110
14111@end table
14112
c9429232
SS
14113@node Tracepoint Restrictions
14114@subsection Tracepoint Restrictions
14115
14116@cindex tracepoint restrictions
14117There are a number of restrictions on the use of tracepoints. As
14118described above, tracepoint data gathering occurs on the target
14119without interaction from @value{GDBN}. Thus the full capabilities of
14120the debugger are not available during data gathering, and then at data
14121examination time, you will be limited by only having what was
14122collected. The following items describe some common problems, but it
14123is not exhaustive, and you may run into additional difficulties not
14124mentioned here.
14125
14126@itemize @bullet
14127
14128@item
14129Tracepoint expressions are intended to gather objects (lvalues). Thus
14130the full flexibility of GDB's expression evaluator is not available.
14131You cannot call functions, cast objects to aggregate types, access
14132convenience variables or modify values (except by assignment to trace
14133state variables). Some language features may implicitly call
14134functions (for instance Objective-C fields with accessors), and therefore
14135cannot be collected either.
14136
14137@item
14138Collection of local variables, either individually or in bulk with
14139@code{$locals} or @code{$args}, during @code{while-stepping} may
14140behave erratically. The stepping action may enter a new scope (for
14141instance by stepping into a function), or the location of the variable
14142may change (for instance it is loaded into a register). The
14143tracepoint data recorded uses the location information for the
14144variables that is correct for the tracepoint location. When the
14145tracepoint is created, it is not possible, in general, to determine
14146where the steps of a @code{while-stepping} sequence will advance the
14147program---particularly if a conditional branch is stepped.
14148
14149@item
14150Collection of an incompletely-initialized or partially-destroyed object
14151may result in something that @value{GDBN} cannot display, or displays
14152in a misleading way.
14153
14154@item
14155When @value{GDBN} displays a pointer to character it automatically
14156dereferences the pointer to also display characters of the string
14157being pointed to. However, collecting the pointer during tracing does
14158not automatically collect the string. You need to explicitly
14159dereference the pointer and provide size information if you want to
14160collect not only the pointer, but the memory pointed to. For example,
14161@code{*ptr@@50} can be used to collect the 50 element array pointed to
14162by @code{ptr}.
14163
14164@item
14165It is not possible to collect a complete stack backtrace at a
14166tracepoint. Instead, you may collect the registers and a few hundred
d99f7e48 14167bytes from the stack pointer with something like @code{*(unsigned char *)$esp@@300}
c9429232
SS
14168(adjust to use the name of the actual stack pointer register on your
14169target architecture, and the amount of stack you wish to capture).
14170Then the @code{backtrace} command will show a partial backtrace when
14171using a trace frame. The number of stack frames that can be examined
14172depends on the sizes of the frames in the collected stack. Note that
14173if you ask for a block so large that it goes past the bottom of the
14174stack, the target agent may report an error trying to read from an
14175invalid address.
14176
af54718e
SS
14177@item
14178If you do not collect registers at a tracepoint, @value{GDBN} can
14179infer that the value of @code{$pc} must be the same as the address of
14180the tracepoint and use that when you are looking at a trace frame
14181for that tracepoint. However, this cannot work if the tracepoint has
14182multiple locations (for instance if it was set in a function that was
14183inlined), or if it has a @code{while-stepping} loop. In those cases
14184@value{GDBN} will warn you that it can't infer @code{$pc}, and default
14185it to zero.
14186
c9429232
SS
14187@end itemize
14188
b37052ae 14189@node Analyze Collected Data
79a6e687 14190@section Using the Collected Data
b37052ae
EZ
14191
14192After the tracepoint experiment ends, you use @value{GDBN} commands
14193for examining the trace data. The basic idea is that each tracepoint
14194collects a trace @dfn{snapshot} every time it is hit and another
14195snapshot every time it single-steps. All these snapshots are
14196consecutively numbered from zero and go into a buffer, and you can
14197examine them later. The way you examine them is to @dfn{focus} on a
14198specific trace snapshot. When the remote stub is focused on a trace
14199snapshot, it will respond to all @value{GDBN} requests for memory and
14200registers by reading from the buffer which belongs to that snapshot,
14201rather than from @emph{real} memory or registers of the program being
14202debugged. This means that @strong{all} @value{GDBN} commands
14203(@code{print}, @code{info registers}, @code{backtrace}, etc.) will
14204behave as if we were currently debugging the program state as it was
14205when the tracepoint occurred. Any requests for data that are not in
14206the buffer will fail.
14207
14208@menu
14209* tfind:: How to select a trace snapshot
14210* tdump:: How to display all data for a snapshot
6149aea9 14211* save tracepoints:: How to save tracepoints for a future run
b37052ae
EZ
14212@end menu
14213
14214@node tfind
14215@subsection @code{tfind @var{n}}
14216
14217@kindex tfind
14218@cindex select trace snapshot
14219@cindex find trace snapshot
14220The basic command for selecting a trace snapshot from the buffer is
14221@code{tfind @var{n}}, which finds trace snapshot number @var{n},
14222counting from zero. If no argument @var{n} is given, the next
14223snapshot is selected.
14224
14225Here are the various forms of using the @code{tfind} command.
14226
14227@table @code
14228@item tfind start
14229Find the first snapshot in the buffer. This is a synonym for
14230@code{tfind 0} (since 0 is the number of the first snapshot).
14231
14232@item tfind none
14233Stop debugging trace snapshots, resume @emph{live} debugging.
14234
14235@item tfind end
14236Same as @samp{tfind none}.
14237
14238@item tfind
310cdbb6
YQ
14239No argument means find the next trace snapshot or find the first
14240one if no trace snapshot is selected.
b37052ae
EZ
14241
14242@item tfind -
14243Find the previous trace snapshot before the current one. This permits
14244retracing earlier steps.
14245
14246@item tfind tracepoint @var{num}
14247Find the next snapshot associated with tracepoint @var{num}. Search
14248proceeds forward from the last examined trace snapshot. If no
14249argument @var{num} is given, it means find the next snapshot collected
14250for the same tracepoint as the current snapshot.
14251
14252@item tfind pc @var{addr}
14253Find the next snapshot associated with the value @var{addr} of the
14254program counter. Search proceeds forward from the last examined trace
14255snapshot. If no argument @var{addr} is given, it means find the next
14256snapshot with the same value of PC as the current snapshot.
14257
14258@item tfind outside @var{addr1}, @var{addr2}
14259Find the next snapshot whose PC is outside the given range of
081dfbf7 14260addresses (exclusive).
b37052ae
EZ
14261
14262@item tfind range @var{addr1}, @var{addr2}
14263Find the next snapshot whose PC is between @var{addr1} and
081dfbf7 14264@var{addr2} (inclusive).
b37052ae
EZ
14265
14266@item tfind line @r{[}@var{file}:@r{]}@var{n}
14267Find the next snapshot associated with the source line @var{n}. If
14268the optional argument @var{file} is given, refer to line @var{n} in
14269that source file. Search proceeds forward from the last examined
14270trace snapshot. If no argument @var{n} is given, it means find the
14271next line other than the one currently being examined; thus saying
14272@code{tfind line} repeatedly can appear to have the same effect as
14273stepping from line to line in a @emph{live} debugging session.
14274@end table
14275
14276The default arguments for the @code{tfind} commands are specifically
14277designed to make it easy to scan through the trace buffer. For
14278instance, @code{tfind} with no argument selects the next trace
14279snapshot, and @code{tfind -} with no argument selects the previous
14280trace snapshot. So, by giving one @code{tfind} command, and then
14281simply hitting @key{RET} repeatedly you can examine all the trace
14282snapshots in order. Or, by saying @code{tfind -} and then hitting
14283@key{RET} repeatedly you can examine the snapshots in reverse order.
14284The @code{tfind line} command with no argument selects the snapshot
14285for the next source line executed. The @code{tfind pc} command with
14286no argument selects the next snapshot with the same program counter
14287(PC) as the current frame. The @code{tfind tracepoint} command with
14288no argument selects the next trace snapshot collected by the same
14289tracepoint as the current one.
14290
14291In addition to letting you scan through the trace buffer manually,
14292these commands make it easy to construct @value{GDBN} scripts that
14293scan through the trace buffer and print out whatever collected data
14294you are interested in. Thus, if we want to examine the PC, FP, and SP
14295registers from each trace frame in the buffer, we can say this:
14296
14297@smallexample
14298(@value{GDBP}) @b{tfind start}
14299(@value{GDBP}) @b{while ($trace_frame != -1)}
14300> printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
14301 $trace_frame, $pc, $sp, $fp
14302> tfind
14303> end
14304
14305Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
14306Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
14307Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
14308Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
14309Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
14310Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
14311Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
14312Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
14313Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
14314Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
14315Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
14316@end smallexample
14317
14318Or, if we want to examine the variable @code{X} at each source line in
14319the buffer:
14320
14321@smallexample
14322(@value{GDBP}) @b{tfind start}
14323(@value{GDBP}) @b{while ($trace_frame != -1)}
14324> printf "Frame %d, X == %d\n", $trace_frame, X
14325> tfind line
14326> end
14327
14328Frame 0, X = 1
14329Frame 7, X = 2
14330Frame 13, X = 255
14331@end smallexample
14332
14333@node tdump
14334@subsection @code{tdump}
14335@kindex tdump
14336@cindex dump all data collected at tracepoint
14337@cindex tracepoint data, display
14338
14339This command takes no arguments. It prints all the data collected at
14340the current trace snapshot.
14341
14342@smallexample
14343(@value{GDBP}) @b{trace 444}
14344(@value{GDBP}) @b{actions}
14345Enter actions for tracepoint #2, one per line:
14346> collect $regs, $locals, $args, gdb_long_test
14347> end
14348
14349(@value{GDBP}) @b{tstart}
14350
14351(@value{GDBP}) @b{tfind line 444}
14352#0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
14353at gdb_test.c:444
14354444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
14355
14356(@value{GDBP}) @b{tdump}
14357Data collected at tracepoint 2, trace frame 1:
14358d0 0xc4aa0085 -995491707
14359d1 0x18 24
14360d2 0x80 128
14361d3 0x33 51
14362d4 0x71aea3d 119204413
14363d5 0x22 34
14364d6 0xe0 224
14365d7 0x380035 3670069
14366a0 0x19e24a 1696330
14367a1 0x3000668 50333288
14368a2 0x100 256
14369a3 0x322000 3284992
14370a4 0x3000698 50333336
14371a5 0x1ad3cc 1758156
14372fp 0x30bf3c 0x30bf3c
14373sp 0x30bf34 0x30bf34
14374ps 0x0 0
14375pc 0x20b2c8 0x20b2c8
14376fpcontrol 0x0 0
14377fpstatus 0x0 0
14378fpiaddr 0x0 0
14379p = 0x20e5b4 "gdb-test"
14380p1 = (void *) 0x11
14381p2 = (void *) 0x22
14382p3 = (void *) 0x33
14383p4 = (void *) 0x44
14384p5 = (void *) 0x55
14385p6 = (void *) 0x66
14386gdb_long_test = 17 '\021'
14387
14388(@value{GDBP})
14389@end smallexample
14390
af54718e
SS
14391@code{tdump} works by scanning the tracepoint's current collection
14392actions and printing the value of each expression listed. So
14393@code{tdump} can fail, if after a run, you change the tracepoint's
14394actions to mention variables that were not collected during the run.
14395
14396Also, for tracepoints with @code{while-stepping} loops, @code{tdump}
14397uses the collected value of @code{$pc} to distinguish between trace
14398frames that were collected at the tracepoint hit, and frames that were
14399collected while stepping. This allows it to correctly choose whether
14400to display the basic list of collections, or the collections from the
14401body of the while-stepping loop. However, if @code{$pc} was not collected,
14402then @code{tdump} will always attempt to dump using the basic collection
14403list, and may fail if a while-stepping frame does not include all the
14404same data that is collected at the tracepoint hit.
14405@c This is getting pretty arcane, example would be good.
14406
6149aea9
PA
14407@node save tracepoints
14408@subsection @code{save tracepoints @var{filename}}
14409@kindex save tracepoints
b37052ae
EZ
14410@kindex save-tracepoints
14411@cindex save tracepoints for future sessions
14412
14413This command saves all current tracepoint definitions together with
14414their actions and passcounts, into a file @file{@var{filename}}
14415suitable for use in a later debugging session. To read the saved
14416tracepoint definitions, use the @code{source} command (@pxref{Command
6149aea9
PA
14417Files}). The @w{@code{save-tracepoints}} command is a deprecated
14418alias for @w{@code{save tracepoints}}
b37052ae
EZ
14419
14420@node Tracepoint Variables
14421@section Convenience Variables for Tracepoints
14422@cindex tracepoint variables
14423@cindex convenience variables for tracepoints
14424
14425@table @code
14426@vindex $trace_frame
14427@item (int) $trace_frame
14428The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
14429snapshot is selected.
14430
14431@vindex $tracepoint
14432@item (int) $tracepoint
14433The tracepoint for the current trace snapshot.
14434
14435@vindex $trace_line
14436@item (int) $trace_line
14437The line number for the current trace snapshot.
14438
14439@vindex $trace_file
14440@item (char []) $trace_file
14441The source file for the current trace snapshot.
14442
14443@vindex $trace_func
14444@item (char []) $trace_func
14445The name of the function containing @code{$tracepoint}.
14446@end table
14447
14448Note: @code{$trace_file} is not suitable for use in @code{printf},
14449use @code{output} instead.
14450
14451Here's a simple example of using these convenience variables for
14452stepping through all the trace snapshots and printing some of their
f61e138d
SS
14453data. Note that these are not the same as trace state variables,
14454which are managed by the target.
b37052ae
EZ
14455
14456@smallexample
14457(@value{GDBP}) @b{tfind start}
14458
14459(@value{GDBP}) @b{while $trace_frame != -1}
14460> output $trace_file
14461> printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
14462> tfind
14463> end
14464@end smallexample
14465
00bf0b85
SS
14466@node Trace Files
14467@section Using Trace Files
14468@cindex trace files
14469
14470In some situations, the target running a trace experiment may no
14471longer be available; perhaps it crashed, or the hardware was needed
14472for a different activity. To handle these cases, you can arrange to
14473dump the trace data into a file, and later use that file as a source
14474of trace data, via the @code{target tfile} command.
14475
14476@table @code
14477
14478@kindex tsave
14479@item tsave [ -r ] @var{filename}
d0353e76 14480@itemx tsave [-ctf] @var{dirname}
00bf0b85
SS
14481Save the trace data to @var{filename}. By default, this command
14482assumes that @var{filename} refers to the host filesystem, so if
14483necessary @value{GDBN} will copy raw trace data up from the target and
14484then save it. If the target supports it, you can also supply the
14485optional argument @code{-r} (``remote'') to direct the target to save
14486the data directly into @var{filename} in its own filesystem, which may be
14487more efficient if the trace buffer is very large. (Note, however, that
14488@code{target tfile} can only read from files accessible to the host.)
d0353e76 14489By default, this command will save trace frame in tfile format.
be06ba8c 14490You can supply the optional argument @code{-ctf} to save data in CTF
d0353e76
YQ
14491format. The @dfn{Common Trace Format} (CTF) is proposed as a trace format
14492that can be shared by multiple debugging and tracing tools. Please go to
14493@indicateurl{http://www.efficios.com/ctf} to get more information.
00bf0b85
SS
14494
14495@kindex target tfile
14496@kindex tfile
393fd4c3
YQ
14497@kindex target ctf
14498@kindex ctf
00bf0b85 14499@item target tfile @var{filename}
393fd4c3
YQ
14500@itemx target ctf @var{dirname}
14501Use the file named @var{filename} or directory named @var{dirname} as
14502a source of trace data. Commands that examine data work as they do with
14503a live target, but it is not possible to run any new trace experiments.
14504@code{tstatus} will report the state of the trace run at the moment
14505the data was saved, as well as the current trace frame you are examining.
697aa1b7 14506Both @var{filename} and @var{dirname} must be on a filesystem accessible to
393fd4c3
YQ
14507the host.
14508
14509@smallexample
14510(@value{GDBP}) target ctf ctf.ctf
14511(@value{GDBP}) tfind
14512Found trace frame 0, tracepoint 2
1451339 ++a; /* set tracepoint 1 here */
14514(@value{GDBP}) tdump
14515Data collected at tracepoint 2, trace frame 0:
14516i = 0
14517a = 0
14518b = 1 '\001'
14519c = @{"123", "456", "789", "123", "456", "789"@}
14520d = @{@{@{a = 1, b = 2@}, @{a = 3, b = 4@}@}, @{@{a = 5, b = 6@}, @{a = 7, b = 8@}@}@}
14521(@value{GDBP}) p b
14522$1 = 1
14523@end smallexample
00bf0b85
SS
14524
14525@end table
14526
df0cd8c5
JB
14527@node Overlays
14528@chapter Debugging Programs That Use Overlays
14529@cindex overlays
14530
14531If your program is too large to fit completely in your target system's
14532memory, you can sometimes use @dfn{overlays} to work around this
14533problem. @value{GDBN} provides some support for debugging programs that
14534use overlays.
14535
14536@menu
14537* How Overlays Work:: A general explanation of overlays.
14538* Overlay Commands:: Managing overlays in @value{GDBN}.
14539* Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
14540 mapped by asking the inferior.
14541* Overlay Sample Program:: A sample program using overlays.
14542@end menu
14543
14544@node How Overlays Work
14545@section How Overlays Work
14546@cindex mapped overlays
14547@cindex unmapped overlays
14548@cindex load address, overlay's
14549@cindex mapped address
14550@cindex overlay area
14551
14552Suppose you have a computer whose instruction address space is only 64
14553kilobytes long, but which has much more memory which can be accessed by
14554other means: special instructions, segment registers, or memory
14555management hardware, for example. Suppose further that you want to
14556adapt a program which is larger than 64 kilobytes to run on this system.
14557
14558One solution is to identify modules of your program which are relatively
14559independent, and need not call each other directly; call these modules
14560@dfn{overlays}. Separate the overlays from the main program, and place
14561their machine code in the larger memory. Place your main program in
14562instruction memory, but leave at least enough space there to hold the
14563largest overlay as well.
14564
14565Now, to call a function located in an overlay, you must first copy that
14566overlay's machine code from the large memory into the space set aside
14567for it in the instruction memory, and then jump to its entry point
14568there.
14569
c928edc0
AC
14570@c NB: In the below the mapped area's size is greater or equal to the
14571@c size of all overlays. This is intentional to remind the developer
14572@c that overlays don't necessarily need to be the same size.
14573
474c8240 14574@smallexample
df0cd8c5 14575@group
c928edc0
AC
14576 Data Instruction Larger
14577Address Space Address Space Address Space
14578+-----------+ +-----------+ +-----------+
14579| | | | | |
14580+-----------+ +-----------+ +-----------+<-- overlay 1
14581| program | | main | .----| overlay 1 | load address
14582| variables | | program | | +-----------+
14583| and heap | | | | | |
14584+-----------+ | | | +-----------+<-- overlay 2
14585| | +-----------+ | | | load address
14586+-----------+ | | | .-| overlay 2 |
14587 | | | | | |
14588 mapped --->+-----------+ | | +-----------+
14589 address | | | | | |
14590 | overlay | <-' | | |
14591 | area | <---' +-----------+<-- overlay 3
14592 | | <---. | | load address
14593 +-----------+ `--| overlay 3 |
14594 | | | |
14595 +-----------+ | |
14596 +-----------+
14597 | |
14598 +-----------+
14599
14600 @anchor{A code overlay}A code overlay
df0cd8c5 14601@end group
474c8240 14602@end smallexample
df0cd8c5 14603
c928edc0
AC
14604The diagram (@pxref{A code overlay}) shows a system with separate data
14605and instruction address spaces. To map an overlay, the program copies
14606its code from the larger address space to the instruction address space.
14607Since the overlays shown here all use the same mapped address, only one
14608may be mapped at a time. For a system with a single address space for
14609data and instructions, the diagram would be similar, except that the
14610program variables and heap would share an address space with the main
14611program and the overlay area.
df0cd8c5
JB
14612
14613An overlay loaded into instruction memory and ready for use is called a
14614@dfn{mapped} overlay; its @dfn{mapped address} is its address in the
14615instruction memory. An overlay not present (or only partially present)
14616in instruction memory is called @dfn{unmapped}; its @dfn{load address}
14617is its address in the larger memory. The mapped address is also called
14618the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
14619called the @dfn{load memory address}, or @dfn{LMA}.
14620
14621Unfortunately, overlays are not a completely transparent way to adapt a
14622program to limited instruction memory. They introduce a new set of
14623global constraints you must keep in mind as you design your program:
14624
14625@itemize @bullet
14626
14627@item
14628Before calling or returning to a function in an overlay, your program
14629must make sure that overlay is actually mapped. Otherwise, the call or
14630return will transfer control to the right address, but in the wrong
14631overlay, and your program will probably crash.
14632
14633@item
14634If the process of mapping an overlay is expensive on your system, you
14635will need to choose your overlays carefully to minimize their effect on
14636your program's performance.
14637
14638@item
14639The executable file you load onto your system must contain each
14640overlay's instructions, appearing at the overlay's load address, not its
14641mapped address. However, each overlay's instructions must be relocated
14642and its symbols defined as if the overlay were at its mapped address.
14643You can use GNU linker scripts to specify different load and relocation
14644addresses for pieces of your program; see @ref{Overlay Description,,,
14645ld.info, Using ld: the GNU linker}.
14646
14647@item
14648The procedure for loading executable files onto your system must be able
14649to load their contents into the larger address space as well as the
14650instruction and data spaces.
14651
14652@end itemize
14653
14654The overlay system described above is rather simple, and could be
14655improved in many ways:
14656
14657@itemize @bullet
14658
14659@item
14660If your system has suitable bank switch registers or memory management
14661hardware, you could use those facilities to make an overlay's load area
14662contents simply appear at their mapped address in instruction space.
14663This would probably be faster than copying the overlay to its mapped
14664area in the usual way.
14665
14666@item
14667If your overlays are small enough, you could set aside more than one
14668overlay area, and have more than one overlay mapped at a time.
14669
14670@item
14671You can use overlays to manage data, as well as instructions. In
14672general, data overlays are even less transparent to your design than
14673code overlays: whereas code overlays only require care when you call or
14674return to functions, data overlays require care every time you access
14675the data. Also, if you change the contents of a data overlay, you
14676must copy its contents back out to its load address before you can copy a
14677different data overlay into the same mapped area.
14678
14679@end itemize
14680
14681
14682@node Overlay Commands
14683@section Overlay Commands
14684
14685To use @value{GDBN}'s overlay support, each overlay in your program must
14686correspond to a separate section of the executable file. The section's
14687virtual memory address and load memory address must be the overlay's
14688mapped and load addresses. Identifying overlays with sections allows
14689@value{GDBN} to determine the appropriate address of a function or
14690variable, depending on whether the overlay is mapped or not.
14691
14692@value{GDBN}'s overlay commands all start with the word @code{overlay};
14693you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
14694
14695@table @code
14696@item overlay off
4644b6e3 14697@kindex overlay
df0cd8c5
JB
14698Disable @value{GDBN}'s overlay support. When overlay support is
14699disabled, @value{GDBN} assumes that all functions and variables are
14700always present at their mapped addresses. By default, @value{GDBN}'s
14701overlay support is disabled.
14702
14703@item overlay manual
df0cd8c5
JB
14704@cindex manual overlay debugging
14705Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
14706relies on you to tell it which overlays are mapped, and which are not,
14707using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
14708commands described below.
14709
14710@item overlay map-overlay @var{overlay}
14711@itemx overlay map @var{overlay}
df0cd8c5
JB
14712@cindex map an overlay
14713Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
14714be the name of the object file section containing the overlay. When an
14715overlay is mapped, @value{GDBN} assumes it can find the overlay's
14716functions and variables at their mapped addresses. @value{GDBN} assumes
14717that any other overlays whose mapped ranges overlap that of
14718@var{overlay} are now unmapped.
14719
14720@item overlay unmap-overlay @var{overlay}
14721@itemx overlay unmap @var{overlay}
df0cd8c5
JB
14722@cindex unmap an overlay
14723Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
14724must be the name of the object file section containing the overlay.
14725When an overlay is unmapped, @value{GDBN} assumes it can find the
14726overlay's functions and variables at their load addresses.
14727
14728@item overlay auto
df0cd8c5
JB
14729Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
14730consults a data structure the overlay manager maintains in the inferior
14731to see which overlays are mapped. For details, see @ref{Automatic
14732Overlay Debugging}.
14733
14734@item overlay load-target
14735@itemx overlay load
df0cd8c5
JB
14736@cindex reloading the overlay table
14737Re-read the overlay table from the inferior. Normally, @value{GDBN}
14738re-reads the table @value{GDBN} automatically each time the inferior
14739stops, so this command should only be necessary if you have changed the
14740overlay mapping yourself using @value{GDBN}. This command is only
14741useful when using automatic overlay debugging.
14742
14743@item overlay list-overlays
14744@itemx overlay list
14745@cindex listing mapped overlays
14746Display a list of the overlays currently mapped, along with their mapped
14747addresses, load addresses, and sizes.
14748
14749@end table
14750
14751Normally, when @value{GDBN} prints a code address, it includes the name
14752of the function the address falls in:
14753
474c8240 14754@smallexample
f7dc1244 14755(@value{GDBP}) print main
df0cd8c5 14756$3 = @{int ()@} 0x11a0 <main>
474c8240 14757@end smallexample
df0cd8c5
JB
14758@noindent
14759When overlay debugging is enabled, @value{GDBN} recognizes code in
14760unmapped overlays, and prints the names of unmapped functions with
14761asterisks around them. For example, if @code{foo} is a function in an
14762unmapped overlay, @value{GDBN} prints it this way:
14763
474c8240 14764@smallexample
f7dc1244 14765(@value{GDBP}) overlay list
df0cd8c5 14766No sections are mapped.
f7dc1244 14767(@value{GDBP}) print foo
df0cd8c5 14768$5 = @{int (int)@} 0x100000 <*foo*>
474c8240 14769@end smallexample
df0cd8c5
JB
14770@noindent
14771When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
14772name normally:
14773
474c8240 14774@smallexample
f7dc1244 14775(@value{GDBP}) overlay list
b383017d 14776Section .ov.foo.text, loaded at 0x100000 - 0x100034,
df0cd8c5 14777 mapped at 0x1016 - 0x104a
f7dc1244 14778(@value{GDBP}) print foo
df0cd8c5 14779$6 = @{int (int)@} 0x1016 <foo>
474c8240 14780@end smallexample
df0cd8c5
JB
14781
14782When overlay debugging is enabled, @value{GDBN} can find the correct
14783address for functions and variables in an overlay, whether or not the
14784overlay is mapped. This allows most @value{GDBN} commands, like
14785@code{break} and @code{disassemble}, to work normally, even on unmapped
14786code. However, @value{GDBN}'s breakpoint support has some limitations:
14787
14788@itemize @bullet
14789@item
14790@cindex breakpoints in overlays
14791@cindex overlays, setting breakpoints in
14792You can set breakpoints in functions in unmapped overlays, as long as
14793@value{GDBN} can write to the overlay at its load address.
14794@item
14795@value{GDBN} can not set hardware or simulator-based breakpoints in
14796unmapped overlays. However, if you set a breakpoint at the end of your
14797overlay manager (and tell @value{GDBN} which overlays are now mapped, if
14798you are using manual overlay management), @value{GDBN} will re-set its
14799breakpoints properly.
14800@end itemize
14801
14802
14803@node Automatic Overlay Debugging
14804@section Automatic Overlay Debugging
14805@cindex automatic overlay debugging
14806
14807@value{GDBN} can automatically track which overlays are mapped and which
14808are not, given some simple co-operation from the overlay manager in the
14809inferior. If you enable automatic overlay debugging with the
14810@code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
14811looks in the inferior's memory for certain variables describing the
14812current state of the overlays.
14813
14814Here are the variables your overlay manager must define to support
14815@value{GDBN}'s automatic overlay debugging:
14816
14817@table @asis
14818
14819@item @code{_ovly_table}:
14820This variable must be an array of the following structures:
14821
474c8240 14822@smallexample
df0cd8c5
JB
14823struct
14824@{
14825 /* The overlay's mapped address. */
14826 unsigned long vma;
14827
14828 /* The size of the overlay, in bytes. */
14829 unsigned long size;
14830
14831 /* The overlay's load address. */
14832 unsigned long lma;
14833
14834 /* Non-zero if the overlay is currently mapped;
14835 zero otherwise. */
14836 unsigned long mapped;
14837@}
474c8240 14838@end smallexample
df0cd8c5
JB
14839
14840@item @code{_novlys}:
14841This variable must be a four-byte signed integer, holding the total
14842number of elements in @code{_ovly_table}.
14843
14844@end table
14845
14846To decide whether a particular overlay is mapped or not, @value{GDBN}
14847looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
14848@code{lma} members equal the VMA and LMA of the overlay's section in the
14849executable file. When @value{GDBN} finds a matching entry, it consults
14850the entry's @code{mapped} member to determine whether the overlay is
14851currently mapped.
14852
81d46470 14853In addition, your overlay manager may define a function called
def71bfa 14854@code{_ovly_debug_event}. If this function is defined, @value{GDBN}
81d46470
MS
14855will silently set a breakpoint there. If the overlay manager then
14856calls this function whenever it has changed the overlay table, this
14857will enable @value{GDBN} to accurately keep track of which overlays
14858are in program memory, and update any breakpoints that may be set
b383017d 14859in overlays. This will allow breakpoints to work even if the
81d46470
MS
14860overlays are kept in ROM or other non-writable memory while they
14861are not being executed.
df0cd8c5
JB
14862
14863@node Overlay Sample Program
14864@section Overlay Sample Program
14865@cindex overlay example program
14866
14867When linking a program which uses overlays, you must place the overlays
14868at their load addresses, while relocating them to run at their mapped
14869addresses. To do this, you must write a linker script (@pxref{Overlay
14870Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
14871since linker scripts are specific to a particular host system, target
14872architecture, and target memory layout, this manual cannot provide
14873portable sample code demonstrating @value{GDBN}'s overlay support.
14874
14875However, the @value{GDBN} source distribution does contain an overlaid
14876program, with linker scripts for a few systems, as part of its test
14877suite. The program consists of the following files from
14878@file{gdb/testsuite/gdb.base}:
14879
14880@table @file
14881@item overlays.c
14882The main program file.
14883@item ovlymgr.c
14884A simple overlay manager, used by @file{overlays.c}.
14885@item foo.c
14886@itemx bar.c
14887@itemx baz.c
14888@itemx grbx.c
14889Overlay modules, loaded and used by @file{overlays.c}.
14890@item d10v.ld
14891@itemx m32r.ld
14892Linker scripts for linking the test program on the @code{d10v-elf}
14893and @code{m32r-elf} targets.
14894@end table
14895
14896You can build the test program using the @code{d10v-elf} GCC
14897cross-compiler like this:
14898
474c8240 14899@smallexample
df0cd8c5
JB
14900$ d10v-elf-gcc -g -c overlays.c
14901$ d10v-elf-gcc -g -c ovlymgr.c
14902$ d10v-elf-gcc -g -c foo.c
14903$ d10v-elf-gcc -g -c bar.c
14904$ d10v-elf-gcc -g -c baz.c
14905$ d10v-elf-gcc -g -c grbx.c
14906$ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
14907 baz.o grbx.o -Wl,-Td10v.ld -o overlays
474c8240 14908@end smallexample
df0cd8c5
JB
14909
14910The build process is identical for any other architecture, except that
14911you must substitute the appropriate compiler and linker script for the
14912target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
14913
14914
6d2ebf8b 14915@node Languages
c906108c
SS
14916@chapter Using @value{GDBN} with Different Languages
14917@cindex languages
14918
c906108c
SS
14919Although programming languages generally have common aspects, they are
14920rarely expressed in the same manner. For instance, in ANSI C,
14921dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
14922Modula-2, it is accomplished by @code{p^}. Values can also be
5d161b24 14923represented (and displayed) differently. Hex numbers in C appear as
c906108c 14924@samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
c906108c
SS
14925
14926@cindex working language
14927Language-specific information is built into @value{GDBN} for some languages,
14928allowing you to express operations like the above in your program's
14929native language, and allowing @value{GDBN} to output values in a manner
14930consistent with the syntax of your program's native language. The
14931language you use to build expressions is called the @dfn{working
14932language}.
14933
14934@menu
14935* Setting:: Switching between source languages
14936* Show:: Displaying the language
c906108c 14937* Checks:: Type and range checks
79a6e687
BW
14938* Supported Languages:: Supported languages
14939* Unsupported Languages:: Unsupported languages
c906108c
SS
14940@end menu
14941
6d2ebf8b 14942@node Setting
79a6e687 14943@section Switching Between Source Languages
c906108c
SS
14944
14945There are two ways to control the working language---either have @value{GDBN}
14946set it automatically, or select it manually yourself. You can use the
14947@code{set language} command for either purpose. On startup, @value{GDBN}
14948defaults to setting the language automatically. The working language is
14949used to determine how expressions you type are interpreted, how values
14950are printed, etc.
14951
14952In addition to the working language, every source file that
14953@value{GDBN} knows about has its own working language. For some object
14954file formats, the compiler might indicate which language a particular
14955source file is in. However, most of the time @value{GDBN} infers the
14956language from the name of the file. The language of a source file
b37052ae 14957controls whether C@t{++} names are demangled---this way @code{backtrace} can
c906108c 14958show each frame appropriately for its own language. There is no way to
d4f3574e
SS
14959set the language of a source file from within @value{GDBN}, but you can
14960set the language associated with a filename extension. @xref{Show, ,
79a6e687 14961Displaying the Language}.
c906108c
SS
14962
14963This is most commonly a problem when you use a program, such
5d161b24 14964as @code{cfront} or @code{f2c}, that generates C but is written in
c906108c
SS
14965another language. In that case, make the
14966program use @code{#line} directives in its C output; that way
14967@value{GDBN} will know the correct language of the source code of the original
14968program, and will display that source code, not the generated C code.
14969
14970@menu
14971* Filenames:: Filename extensions and languages.
14972* Manually:: Setting the working language manually
14973* Automatically:: Having @value{GDBN} infer the source language
14974@end menu
14975
6d2ebf8b 14976@node Filenames
79a6e687 14977@subsection List of Filename Extensions and Languages
c906108c
SS
14978
14979If a source file name ends in one of the following extensions, then
14980@value{GDBN} infers that its language is the one indicated.
14981
14982@table @file
e07c999f
PH
14983@item .ada
14984@itemx .ads
14985@itemx .adb
14986@itemx .a
14987Ada source file.
c906108c
SS
14988
14989@item .c
14990C source file
14991
14992@item .C
14993@itemx .cc
14994@itemx .cp
14995@itemx .cpp
14996@itemx .cxx
14997@itemx .c++
b37052ae 14998C@t{++} source file
c906108c 14999
6aecb9c2
JB
15000@item .d
15001D source file
15002
b37303ee
AF
15003@item .m
15004Objective-C source file
15005
c906108c
SS
15006@item .f
15007@itemx .F
15008Fortran source file
15009
c906108c
SS
15010@item .mod
15011Modula-2 source file
c906108c
SS
15012
15013@item .s
15014@itemx .S
15015Assembler source file. This actually behaves almost like C, but
15016@value{GDBN} does not skip over function prologues when stepping.
15017@end table
15018
15019In addition, you may set the language associated with a filename
79a6e687 15020extension. @xref{Show, , Displaying the Language}.
c906108c 15021
6d2ebf8b 15022@node Manually
79a6e687 15023@subsection Setting the Working Language
c906108c
SS
15024
15025If you allow @value{GDBN} to set the language automatically,
15026expressions are interpreted the same way in your debugging session and
15027your program.
15028
15029@kindex set language
15030If you wish, you may set the language manually. To do this, issue the
15031command @samp{set language @var{lang}}, where @var{lang} is the name of
5d161b24 15032a language, such as
c906108c 15033@code{c} or @code{modula-2}.
c906108c
SS
15034For a list of the supported languages, type @samp{set language}.
15035
c906108c
SS
15036Setting the language manually prevents @value{GDBN} from updating the working
15037language automatically. This can lead to confusion if you try
15038to debug a program when the working language is not the same as the
15039source language, when an expression is acceptable to both
15040languages---but means different things. For instance, if the current
15041source file were written in C, and @value{GDBN} was parsing Modula-2, a
15042command such as:
15043
474c8240 15044@smallexample
c906108c 15045print a = b + c
474c8240 15046@end smallexample
c906108c
SS
15047
15048@noindent
15049might not have the effect you intended. In C, this means to add
15050@code{b} and @code{c} and place the result in @code{a}. The result
15051printed would be the value of @code{a}. In Modula-2, this means to compare
15052@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
c906108c 15053
6d2ebf8b 15054@node Automatically
79a6e687 15055@subsection Having @value{GDBN} Infer the Source Language
c906108c
SS
15056
15057To have @value{GDBN} set the working language automatically, use
15058@samp{set language local} or @samp{set language auto}. @value{GDBN}
15059then infers the working language. That is, when your program stops in a
15060frame (usually by encountering a breakpoint), @value{GDBN} sets the
15061working language to the language recorded for the function in that
15062frame. If the language for a frame is unknown (that is, if the function
15063or block corresponding to the frame was defined in a source file that
15064does not have a recognized extension), the current working language is
15065not changed, and @value{GDBN} issues a warning.
15066
15067This may not seem necessary for most programs, which are written
15068entirely in one source language. However, program modules and libraries
15069written in one source language can be used by a main program written in
15070a different source language. Using @samp{set language auto} in this
15071case frees you from having to set the working language manually.
15072
6d2ebf8b 15073@node Show
79a6e687 15074@section Displaying the Language
c906108c
SS
15075
15076The following commands help you find out which language is the
15077working language, and also what language source files were written in.
15078
c906108c
SS
15079@table @code
15080@item show language
403cb6b1 15081@anchor{show language}
9c16f35a 15082@kindex show language
c906108c
SS
15083Display the current working language. This is the
15084language you can use with commands such as @code{print} to
15085build and compute expressions that may involve variables in your program.
15086
15087@item info frame
4644b6e3 15088@kindex info frame@r{, show the source language}
5d161b24 15089Display the source language for this frame. This language becomes the
c906108c 15090working language if you use an identifier from this frame.
79a6e687 15091@xref{Frame Info, ,Information about a Frame}, to identify the other
c906108c
SS
15092information listed here.
15093
15094@item info source
4644b6e3 15095@kindex info source@r{, show the source language}
c906108c 15096Display the source language of this source file.
5d161b24 15097@xref{Symbols, ,Examining the Symbol Table}, to identify the other
c906108c
SS
15098information listed here.
15099@end table
15100
15101In unusual circumstances, you may have source files with extensions
15102not in the standard list. You can then set the extension associated
15103with a language explicitly:
15104
c906108c 15105@table @code
09d4efe1 15106@item set extension-language @var{ext} @var{language}
9c16f35a 15107@kindex set extension-language
09d4efe1
EZ
15108Tell @value{GDBN} that source files with extension @var{ext} are to be
15109assumed as written in the source language @var{language}.
c906108c
SS
15110
15111@item info extensions
9c16f35a 15112@kindex info extensions
c906108c
SS
15113List all the filename extensions and the associated languages.
15114@end table
15115
6d2ebf8b 15116@node Checks
79a6e687 15117@section Type and Range Checking
c906108c 15118
c906108c
SS
15119Some languages are designed to guard you against making seemingly common
15120errors through a series of compile- and run-time checks. These include
a451cb65 15121checking the type of arguments to functions and operators and making
c906108c
SS
15122sure mathematical overflows are caught at run time. Checks such as
15123these help to ensure a program's correctness once it has been compiled
a451cb65 15124by eliminating type mismatches and providing active checks for range
c906108c
SS
15125errors when your program is running.
15126
a451cb65
KS
15127By default @value{GDBN} checks for these errors according to the
15128rules of the current source language. Although @value{GDBN} does not check
15129the statements in your program, it can check expressions entered directly
15130into @value{GDBN} for evaluation via the @code{print} command, for example.
c906108c
SS
15131
15132@menu
15133* Type Checking:: An overview of type checking
15134* Range Checking:: An overview of range checking
15135@end menu
15136
15137@cindex type checking
15138@cindex checks, type
6d2ebf8b 15139@node Type Checking
79a6e687 15140@subsection An Overview of Type Checking
c906108c 15141
a451cb65 15142Some languages, such as C and C@t{++}, are strongly typed, meaning that the
c906108c
SS
15143arguments to operators and functions have to be of the correct type,
15144otherwise an error occurs. These checks prevent type mismatch
15145errors from ever causing any run-time problems. For example,
15146
15147@smallexample
a451cb65
KS
15148int klass::my_method(char *b) @{ return b ? 1 : 2; @}
15149
15150(@value{GDBP}) print obj.my_method (0)
15151$1 = 2
c906108c 15152@exdent but
a451cb65
KS
15153(@value{GDBP}) print obj.my_method (0x1234)
15154Cannot resolve method klass::my_method to any overloaded instance
c906108c
SS
15155@end smallexample
15156
a451cb65
KS
15157The second example fails because in C@t{++} the integer constant
15158@samp{0x1234} is not type-compatible with the pointer parameter type.
c906108c 15159
a451cb65
KS
15160For the expressions you use in @value{GDBN} commands, you can tell
15161@value{GDBN} to not enforce strict type checking or
5d161b24 15162to treat any mismatches as errors and abandon the expression;
a451cb65
KS
15163When type checking is disabled, @value{GDBN} successfully evaluates
15164expressions like the second example above.
c906108c 15165
a451cb65 15166Even if type checking is off, there may be other reasons
5d161b24
DB
15167related to type that prevent @value{GDBN} from evaluating an expression.
15168For instance, @value{GDBN} does not know how to add an @code{int} and
15169a @code{struct foo}. These particular type errors have nothing to do
a451cb65
KS
15170with the language in use and usually arise from expressions which make
15171little sense to evaluate anyway.
c906108c 15172
a451cb65 15173@value{GDBN} provides some additional commands for controlling type checking:
c906108c 15174
c906108c
SS
15175@kindex set check type
15176@kindex show check type
15177@table @code
c906108c
SS
15178@item set check type on
15179@itemx set check type off
a451cb65 15180Set strict type checking on or off. If any type mismatches occur in
d4f3574e 15181evaluating an expression while type checking is on, @value{GDBN} prints a
c906108c
SS
15182message and aborts evaluation of the expression.
15183
a451cb65
KS
15184@item show check type
15185Show the current setting of type checking and whether @value{GDBN}
15186is enforcing strict type checking rules.
c906108c
SS
15187@end table
15188
15189@cindex range checking
15190@cindex checks, range
6d2ebf8b 15191@node Range Checking
79a6e687 15192@subsection An Overview of Range Checking
c906108c
SS
15193
15194In some languages (such as Modula-2), it is an error to exceed the
15195bounds of a type; this is enforced with run-time checks. Such range
15196checking is meant to ensure program correctness by making sure
15197computations do not overflow, or indices on an array element access do
15198not exceed the bounds of the array.
15199
15200For expressions you use in @value{GDBN} commands, you can tell
15201@value{GDBN} to treat range errors in one of three ways: ignore them,
15202always treat them as errors and abandon the expression, or issue
15203warnings but evaluate the expression anyway.
15204
15205A range error can result from numerical overflow, from exceeding an
15206array index bound, or when you type a constant that is not a member
15207of any type. Some languages, however, do not treat overflows as an
15208error. In many implementations of C, mathematical overflow causes the
15209result to ``wrap around'' to lower values---for example, if @var{m} is
15210the largest integer value, and @var{s} is the smallest, then
15211
474c8240 15212@smallexample
c906108c 15213@var{m} + 1 @result{} @var{s}
474c8240 15214@end smallexample
c906108c
SS
15215
15216This, too, is specific to individual languages, and in some cases
79a6e687
BW
15217specific to individual compilers or machines. @xref{Supported Languages, ,
15218Supported Languages}, for further details on specific languages.
c906108c
SS
15219
15220@value{GDBN} provides some additional commands for controlling the range checker:
15221
c906108c
SS
15222@kindex set check range
15223@kindex show check range
15224@table @code
15225@item set check range auto
15226Set range checking on or off based on the current working language.
79a6e687 15227@xref{Supported Languages, ,Supported Languages}, for the default settings for
c906108c
SS
15228each language.
15229
15230@item set check range on
15231@itemx set check range off
15232Set range checking on or off, overriding the default setting for the
15233current working language. A warning is issued if the setting does not
c3f6f71d
JM
15234match the language default. If a range error occurs and range checking is on,
15235then a message is printed and evaluation of the expression is aborted.
c906108c
SS
15236
15237@item set check range warn
15238Output messages when the @value{GDBN} range checker detects a range error,
15239but attempt to evaluate the expression anyway. Evaluating the
15240expression may still be impossible for other reasons, such as accessing
15241memory that the process does not own (a typical example from many Unix
15242systems).
15243
15244@item show range
15245Show the current setting of the range checker, and whether or not it is
15246being set automatically by @value{GDBN}.
15247@end table
c906108c 15248
79a6e687
BW
15249@node Supported Languages
15250@section Supported Languages
c906108c 15251
9c37b5ae 15252@value{GDBN} supports C, C@t{++}, D, Go, Objective-C, Fortran,
0bdfa368 15253OpenCL C, Pascal, Rust, assembly, Modula-2, and Ada.
cce74817 15254@c This is false ...
c906108c
SS
15255Some @value{GDBN} features may be used in expressions regardless of the
15256language you use: the @value{GDBN} @code{@@} and @code{::} operators,
15257and the @samp{@{type@}addr} construct (@pxref{Expressions,
15258,Expressions}) can be used with the constructs of any supported
15259language.
15260
15261The following sections detail to what degree each source language is
15262supported by @value{GDBN}. These sections are not meant to be language
15263tutorials or references, but serve only as a reference guide to what the
15264@value{GDBN} expression parser accepts, and what input and output
15265formats should look like for different languages. There are many good
15266books written on each of these languages; please look to these for a
15267language reference or tutorial.
15268
c906108c 15269@menu
b37303ee 15270* C:: C and C@t{++}
6aecb9c2 15271* D:: D
a766d390 15272* Go:: Go
b383017d 15273* Objective-C:: Objective-C
f4b8a18d 15274* OpenCL C:: OpenCL C
09d4efe1 15275* Fortran:: Fortran
9c16f35a 15276* Pascal:: Pascal
0bdfa368 15277* Rust:: Rust
b37303ee 15278* Modula-2:: Modula-2
e07c999f 15279* Ada:: Ada
c906108c
SS
15280@end menu
15281
6d2ebf8b 15282@node C
b37052ae 15283@subsection C and C@t{++}
7a292a7a 15284
b37052ae
EZ
15285@cindex C and C@t{++}
15286@cindex expressions in C or C@t{++}
c906108c 15287
b37052ae 15288Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
c906108c
SS
15289to both languages. Whenever this is the case, we discuss those languages
15290together.
15291
41afff9a
EZ
15292@cindex C@t{++}
15293@cindex @code{g++}, @sc{gnu} C@t{++} compiler
b37052ae
EZ
15294@cindex @sc{gnu} C@t{++}
15295The C@t{++} debugging facilities are jointly implemented by the C@t{++}
15296compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
15297effectively, you must compile your C@t{++} programs with a supported
15298C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
c906108c
SS
15299compiler (@code{aCC}).
15300
c906108c 15301@menu
b37052ae
EZ
15302* C Operators:: C and C@t{++} operators
15303* C Constants:: C and C@t{++} constants
79a6e687 15304* C Plus Plus Expressions:: C@t{++} expressions
b37052ae
EZ
15305* C Defaults:: Default settings for C and C@t{++}
15306* C Checks:: C and C@t{++} type and range checks
c906108c 15307* Debugging C:: @value{GDBN} and C
79a6e687 15308* Debugging C Plus Plus:: @value{GDBN} features for C@t{++}
febe4383 15309* Decimal Floating Point:: Numbers in Decimal Floating Point format
c906108c 15310@end menu
c906108c 15311
6d2ebf8b 15312@node C Operators
79a6e687 15313@subsubsection C and C@t{++} Operators
7a292a7a 15314
b37052ae 15315@cindex C and C@t{++} operators
c906108c
SS
15316
15317Operators must be defined on values of specific types. For instance,
15318@code{+} is defined on numbers, but not on structures. Operators are
5d161b24 15319often defined on groups of types.
c906108c 15320
b37052ae 15321For the purposes of C and C@t{++}, the following definitions hold:
c906108c
SS
15322
15323@itemize @bullet
53a5351d 15324
c906108c 15325@item
c906108c 15326@emph{Integral types} include @code{int} with any of its storage-class
b37052ae 15327specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
c906108c
SS
15328
15329@item
d4f3574e
SS
15330@emph{Floating-point types} include @code{float}, @code{double}, and
15331@code{long double} (if supported by the target platform).
c906108c
SS
15332
15333@item
53a5351d 15334@emph{Pointer types} include all types defined as @code{(@var{type} *)}.
c906108c
SS
15335
15336@item
15337@emph{Scalar types} include all of the above.
53a5351d 15338
c906108c
SS
15339@end itemize
15340
15341@noindent
15342The following operators are supported. They are listed here
15343in order of increasing precedence:
15344
15345@table @code
15346@item ,
15347The comma or sequencing operator. Expressions in a comma-separated list
15348are evaluated from left to right, with the result of the entire
15349expression being the last expression evaluated.
15350
15351@item =
15352Assignment. The value of an assignment expression is the value
15353assigned. Defined on scalar types.
15354
15355@item @var{op}=
15356Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
15357and translated to @w{@code{@var{a} = @var{a op b}}}.
697aa1b7 15358@w{@code{@var{op}=}} and @code{=} have the same precedence. The operator
c906108c
SS
15359@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
15360@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
15361
15362@item ?:
15363The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
697aa1b7
EZ
15364of as: if @var{a} then @var{b} else @var{c}. The argument @var{a}
15365should be of an integral type.
c906108c
SS
15366
15367@item ||
15368Logical @sc{or}. Defined on integral types.
15369
15370@item &&
15371Logical @sc{and}. Defined on integral types.
15372
15373@item |
15374Bitwise @sc{or}. Defined on integral types.
15375
15376@item ^
15377Bitwise exclusive-@sc{or}. Defined on integral types.
15378
15379@item &
15380Bitwise @sc{and}. Defined on integral types.
15381
15382@item ==@r{, }!=
15383Equality and inequality. Defined on scalar types. The value of these
15384expressions is 0 for false and non-zero for true.
15385
15386@item <@r{, }>@r{, }<=@r{, }>=
15387Less than, greater than, less than or equal, greater than or equal.
15388Defined on scalar types. The value of these expressions is 0 for false
15389and non-zero for true.
15390
15391@item <<@r{, }>>
15392left shift, and right shift. Defined on integral types.
15393
15394@item @@
15395The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
15396
15397@item +@r{, }-
15398Addition and subtraction. Defined on integral types, floating-point types and
15399pointer types.
15400
15401@item *@r{, }/@r{, }%
15402Multiplication, division, and modulus. Multiplication and division are
15403defined on integral and floating-point types. Modulus is defined on
15404integral types.
15405
15406@item ++@r{, }--
15407Increment and decrement. When appearing before a variable, the
15408operation is performed before the variable is used in an expression;
15409when appearing after it, the variable's value is used before the
15410operation takes place.
15411
15412@item *
15413Pointer dereferencing. Defined on pointer types. Same precedence as
15414@code{++}.
15415
15416@item &
15417Address operator. Defined on variables. Same precedence as @code{++}.
15418
b37052ae
EZ
15419For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
15420allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
b17828ca 15421to examine the address
b37052ae 15422where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
c906108c 15423stored.
c906108c
SS
15424
15425@item -
15426Negative. Defined on integral and floating-point types. Same
15427precedence as @code{++}.
15428
15429@item !
15430Logical negation. Defined on integral types. Same precedence as
15431@code{++}.
15432
15433@item ~
15434Bitwise complement operator. Defined on integral types. Same precedence as
15435@code{++}.
15436
15437
15438@item .@r{, }->
15439Structure member, and pointer-to-structure member. For convenience,
15440@value{GDBN} regards the two as equivalent, choosing whether to dereference a
15441pointer based on the stored type information.
15442Defined on @code{struct} and @code{union} data.
15443
c906108c
SS
15444@item .*@r{, }->*
15445Dereferences of pointers to members.
c906108c
SS
15446
15447@item []
15448Array indexing. @code{@var{a}[@var{i}]} is defined as
15449@code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
15450
15451@item ()
15452Function parameter list. Same precedence as @code{->}.
15453
c906108c 15454@item ::
b37052ae 15455C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
7a292a7a 15456and @code{class} types.
c906108c
SS
15457
15458@item ::
7a292a7a
SS
15459Doubled colons also represent the @value{GDBN} scope operator
15460(@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
15461above.
c906108c
SS
15462@end table
15463
c906108c
SS
15464If an operator is redefined in the user code, @value{GDBN} usually
15465attempts to invoke the redefined version instead of using the operator's
15466predefined meaning.
c906108c 15467
6d2ebf8b 15468@node C Constants
79a6e687 15469@subsubsection C and C@t{++} Constants
c906108c 15470
b37052ae 15471@cindex C and C@t{++} constants
c906108c 15472
b37052ae 15473@value{GDBN} allows you to express the constants of C and C@t{++} in the
c906108c 15474following ways:
c906108c
SS
15475
15476@itemize @bullet
15477@item
15478Integer constants are a sequence of digits. Octal constants are
6ca652b0
EZ
15479specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
15480by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
c906108c
SS
15481@samp{l}, specifying that the constant should be treated as a
15482@code{long} value.
15483
15484@item
15485Floating point constants are a sequence of digits, followed by a decimal
15486point, followed by a sequence of digits, and optionally followed by an
15487exponent. An exponent is of the form:
15488@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
15489sequence of digits. The @samp{+} is optional for positive exponents.
d4f3574e
SS
15490A floating-point constant may also end with a letter @samp{f} or
15491@samp{F}, specifying that the constant should be treated as being of
15492the @code{float} (as opposed to the default @code{double}) type; or with
15493a letter @samp{l} or @samp{L}, which specifies a @code{long double}
15494constant.
c906108c
SS
15495
15496@item
15497Enumerated constants consist of enumerated identifiers, or their
15498integral equivalents.
15499
15500@item
15501Character constants are a single character surrounded by single quotes
15502(@code{'}), or a number---the ordinal value of the corresponding character
d4f3574e 15503(usually its @sc{ascii} value). Within quotes, the single character may
c906108c
SS
15504be represented by a letter or by @dfn{escape sequences}, which are of
15505the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
15506of the character's ordinal value; or of the form @samp{\@var{x}}, where
15507@samp{@var{x}} is a predefined special character---for example,
15508@samp{\n} for newline.
15509
e0f8f636
TT
15510Wide character constants can be written by prefixing a character
15511constant with @samp{L}, as in C. For example, @samp{L'x'} is the wide
15512form of @samp{x}. The target wide character set is used when
15513computing the value of this constant (@pxref{Character Sets}).
15514
c906108c 15515@item
96a2c332
SS
15516String constants are a sequence of character constants surrounded by
15517double quotes (@code{"}). Any valid character constant (as described
15518above) may appear. Double quotes within the string must be preceded by
15519a backslash, so for instance @samp{"a\"b'c"} is a string of five
15520characters.
c906108c 15521
e0f8f636
TT
15522Wide string constants can be written by prefixing a string constant
15523with @samp{L}, as in C. The target wide character set is used when
15524computing the value of this constant (@pxref{Character Sets}).
15525
c906108c
SS
15526@item
15527Pointer constants are an integral value. You can also write pointers
15528to constants using the C operator @samp{&}.
15529
15530@item
15531Array constants are comma-separated lists surrounded by braces @samp{@{}
15532and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
15533integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
15534and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
15535@end itemize
15536
79a6e687
BW
15537@node C Plus Plus Expressions
15538@subsubsection C@t{++} Expressions
b37052ae
EZ
15539
15540@cindex expressions in C@t{++}
15541@value{GDBN} expression handling can interpret most C@t{++} expressions.
15542
0179ffac
DC
15543@cindex debugging C@t{++} programs
15544@cindex C@t{++} compilers
15545@cindex debug formats and C@t{++}
15546@cindex @value{NGCC} and C@t{++}
c906108c 15547@quotation
e0f8f636
TT
15548@emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use
15549the proper compiler and the proper debug format. Currently,
15550@value{GDBN} works best when debugging C@t{++} code that is compiled
15551with the most recent version of @value{NGCC} possible. The DWARF
15552debugging format is preferred; @value{NGCC} defaults to this on most
15553popular platforms. Other compilers and/or debug formats are likely to
15554work badly or not at all when using @value{GDBN} to debug C@t{++}
15555code. @xref{Compilation}.
c906108c 15556@end quotation
c906108c
SS
15557
15558@enumerate
15559
15560@cindex member functions
15561@item
15562Member function calls are allowed; you can use expressions like
15563
474c8240 15564@smallexample
c906108c 15565count = aml->GetOriginal(x, y)
474c8240 15566@end smallexample
c906108c 15567
41afff9a 15568@vindex this@r{, inside C@t{++} member functions}
b37052ae 15569@cindex namespace in C@t{++}
c906108c
SS
15570@item
15571While a member function is active (in the selected stack frame), your
15572expressions have the same namespace available as the member function;
15573that is, @value{GDBN} allows implicit references to the class instance
e0f8f636
TT
15574pointer @code{this} following the same rules as C@t{++}. @code{using}
15575declarations in the current scope are also respected by @value{GDBN}.
c906108c 15576
c906108c 15577@cindex call overloaded functions
d4f3574e 15578@cindex overloaded functions, calling
b37052ae 15579@cindex type conversions in C@t{++}
c906108c
SS
15580@item
15581You can call overloaded functions; @value{GDBN} resolves the function
d4f3574e 15582call to the right definition, with some restrictions. @value{GDBN} does not
c906108c
SS
15583perform overload resolution involving user-defined type conversions,
15584calls to constructors, or instantiations of templates that do not exist
15585in the program. It also cannot handle ellipsis argument lists or
15586default arguments.
15587
15588It does perform integral conversions and promotions, floating-point
15589promotions, arithmetic conversions, pointer conversions, conversions of
15590class objects to base classes, and standard conversions such as those of
15591functions or arrays to pointers; it requires an exact match on the
15592number of function arguments.
15593
15594Overload resolution is always performed, unless you have specified
79a6e687
BW
15595@code{set overload-resolution off}. @xref{Debugging C Plus Plus,
15596,@value{GDBN} Features for C@t{++}}.
c906108c 15597
d4f3574e 15598You must specify @code{set overload-resolution off} in order to use an
c906108c
SS
15599explicit function signature to call an overloaded function, as in
15600@smallexample
15601p 'foo(char,int)'('x', 13)
15602@end smallexample
d4f3574e 15603
c906108c 15604The @value{GDBN} command-completion facility can simplify this;
79a6e687 15605see @ref{Completion, ,Command Completion}.
c906108c 15606
c906108c
SS
15607@cindex reference declarations
15608@item
c0f55cc6
AV
15609@value{GDBN} understands variables declared as C@t{++} lvalue or rvalue
15610references; you can use them in expressions just as you do in C@t{++}
15611source---they are automatically dereferenced.
c906108c
SS
15612
15613In the parameter list shown when @value{GDBN} displays a frame, the values of
15614reference variables are not displayed (unlike other variables); this
15615avoids clutter, since references are often used for large structures.
15616The @emph{address} of a reference variable is always shown, unless
15617you have specified @samp{set print address off}.
15618
15619@item
b37052ae 15620@value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
c906108c
SS
15621expressions can use it just as expressions in your program do. Since
15622one scope may be defined in another, you can use @code{::} repeatedly if
15623necessary, for example in an expression like
15624@samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
b37052ae 15625resolving name scope by reference to source files, in both C and C@t{++}
79a6e687 15626debugging (@pxref{Variables, ,Program Variables}).
c906108c 15627
e0f8f636
TT
15628@item
15629@value{GDBN} performs argument-dependent lookup, following the C@t{++}
15630specification.
15631@end enumerate
c906108c 15632
6d2ebf8b 15633@node C Defaults
79a6e687 15634@subsubsection C and C@t{++} Defaults
7a292a7a 15635
b37052ae 15636@cindex C and C@t{++} defaults
c906108c 15637
a451cb65
KS
15638If you allow @value{GDBN} to set range checking automatically, it
15639defaults to @code{off} whenever the working language changes to
b37052ae 15640C or C@t{++}. This happens regardless of whether you or @value{GDBN}
c906108c 15641selects the working language.
c906108c
SS
15642
15643If you allow @value{GDBN} to set the language automatically, it
15644recognizes source files whose names end with @file{.c}, @file{.C}, or
15645@file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
b37052ae 15646these files, it sets the working language to C or C@t{++}.
79a6e687 15647@xref{Automatically, ,Having @value{GDBN} Infer the Source Language},
c906108c
SS
15648for further details.
15649
6d2ebf8b 15650@node C Checks
79a6e687 15651@subsubsection C and C@t{++} Type and Range Checks
7a292a7a 15652
b37052ae 15653@cindex C and C@t{++} checks
c906108c 15654
a451cb65
KS
15655By default, when @value{GDBN} parses C or C@t{++} expressions, strict type
15656checking is used. However, if you turn type checking off, @value{GDBN}
15657will allow certain non-standard conversions, such as promoting integer
15658constants to pointers.
c906108c
SS
15659
15660Range checking, if turned on, is done on mathematical operations. Array
15661indices are not checked, since they are often used to index a pointer
15662that is not itself an array.
c906108c 15663
6d2ebf8b 15664@node Debugging C
c906108c 15665@subsubsection @value{GDBN} and C
c906108c
SS
15666
15667The @code{set print union} and @code{show print union} commands apply to
15668the @code{union} type. When set to @samp{on}, any @code{union} that is
7a292a7a
SS
15669inside a @code{struct} or @code{class} is also printed. Otherwise, it
15670appears as @samp{@{...@}}.
c906108c
SS
15671
15672The @code{@@} operator aids in the debugging of dynamic arrays, formed
15673with pointers and a memory allocation function. @xref{Expressions,
15674,Expressions}.
15675
79a6e687
BW
15676@node Debugging C Plus Plus
15677@subsubsection @value{GDBN} Features for C@t{++}
c906108c 15678
b37052ae 15679@cindex commands for C@t{++}
7a292a7a 15680
b37052ae
EZ
15681Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
15682designed specifically for use with C@t{++}. Here is a summary:
c906108c
SS
15683
15684@table @code
15685@cindex break in overloaded functions
15686@item @r{breakpoint menus}
15687When you want a breakpoint in a function whose name is overloaded,
6ba66d6a
JB
15688@value{GDBN} has the capability to display a menu of possible breakpoint
15689locations to help you specify which function definition you want.
15690@xref{Ambiguous Expressions,,Ambiguous Expressions}.
c906108c 15691
b37052ae 15692@cindex overloading in C@t{++}
c906108c
SS
15693@item rbreak @var{regex}
15694Setting breakpoints using regular expressions is helpful for setting
15695breakpoints on overloaded functions that are not members of any special
15696classes.
79a6e687 15697@xref{Set Breaks, ,Setting Breakpoints}.
c906108c 15698
b37052ae 15699@cindex C@t{++} exception handling
c906108c 15700@item catch throw
591f19e8 15701@itemx catch rethrow
c906108c 15702@itemx catch catch
b37052ae 15703Debug C@t{++} exception handling using these commands. @xref{Set
79a6e687 15704Catchpoints, , Setting Catchpoints}.
c906108c
SS
15705
15706@cindex inheritance
15707@item ptype @var{typename}
15708Print inheritance relationships as well as other information for type
15709@var{typename}.
15710@xref{Symbols, ,Examining the Symbol Table}.
15711
c4aeac85
TT
15712@item info vtbl @var{expression}.
15713The @code{info vtbl} command can be used to display the virtual
15714method tables of the object computed by @var{expression}. This shows
15715one entry per virtual table; there may be multiple virtual tables when
15716multiple inheritance is in use.
15717
439250fb
DE
15718@cindex C@t{++} demangling
15719@item demangle @var{name}
15720Demangle @var{name}.
15721@xref{Symbols}, for a more complete description of the @code{demangle} command.
15722
b37052ae 15723@cindex C@t{++} symbol display
c906108c
SS
15724@item set print demangle
15725@itemx show print demangle
15726@itemx set print asm-demangle
15727@itemx show print asm-demangle
b37052ae
EZ
15728Control whether C@t{++} symbols display in their source form, both when
15729displaying code as C@t{++} source and when displaying disassemblies.
79a6e687 15730@xref{Print Settings, ,Print Settings}.
c906108c
SS
15731
15732@item set print object
15733@itemx show print object
15734Choose whether to print derived (actual) or declared types of objects.
79a6e687 15735@xref{Print Settings, ,Print Settings}.
c906108c
SS
15736
15737@item set print vtbl
15738@itemx show print vtbl
15739Control the format for printing virtual function tables.
79a6e687 15740@xref{Print Settings, ,Print Settings}.
c906108c 15741(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 15742ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
15743
15744@kindex set overload-resolution
d4f3574e 15745@cindex overloaded functions, overload resolution
c906108c 15746@item set overload-resolution on
b37052ae 15747Enable overload resolution for C@t{++} expression evaluation. The default
c906108c
SS
15748is on. For overloaded functions, @value{GDBN} evaluates the arguments
15749and searches for a function whose signature matches the argument types,
79a6e687
BW
15750using the standard C@t{++} conversion rules (see @ref{C Plus Plus
15751Expressions, ,C@t{++} Expressions}, for details).
15752If it cannot find a match, it emits a message.
c906108c
SS
15753
15754@item set overload-resolution off
b37052ae 15755Disable overload resolution for C@t{++} expression evaluation. For
c906108c
SS
15756overloaded functions that are not class member functions, @value{GDBN}
15757chooses the first function of the specified name that it finds in the
15758symbol table, whether or not its arguments are of the correct type. For
15759overloaded functions that are class member functions, @value{GDBN}
15760searches for a function whose signature @emph{exactly} matches the
15761argument types.
c906108c 15762
9c16f35a
EZ
15763@kindex show overload-resolution
15764@item show overload-resolution
15765Show the current setting of overload resolution.
15766
c906108c
SS
15767@item @r{Overloaded symbol names}
15768You can specify a particular definition of an overloaded symbol, using
b37052ae 15769the same notation that is used to declare such symbols in C@t{++}: type
c906108c
SS
15770@code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
15771also use the @value{GDBN} command-line word completion facilities to list the
15772available choices, or to finish the type list for you.
79a6e687 15773@xref{Completion,, Command Completion}, for details on how to do this.
bd69330d
PA
15774
15775@item @r{Breakpoints in functions with ABI tags}
15776
15777The GNU C@t{++} compiler introduced the notion of ABI ``tags'', which
15778correspond to changes in the ABI of a type, function, or variable that
15779would not otherwise be reflected in a mangled name. See
15780@url{https://developers.redhat.com/blog/2015/02/05/gcc5-and-the-c11-abi/}
15781for more detail.
15782
15783The ABI tags are visible in C@t{++} demangled names. For example, a
15784function that returns a std::string:
15785
15786@smallexample
15787std::string function(int);
15788@end smallexample
15789
15790@noindent
15791when compiled for the C++11 ABI is marked with the @code{cxx11} ABI
15792tag, and @value{GDBN} displays the symbol like this:
15793
15794@smallexample
15795function[abi:cxx11](int)
15796@end smallexample
15797
15798You can set a breakpoint on such functions simply as if they had no
15799tag. For example:
15800
15801@smallexample
15802(gdb) b function(int)
15803Breakpoint 2 at 0x40060d: file main.cc, line 10.
15804(gdb) info breakpoints
15805Num Type Disp Enb Address What
158061 breakpoint keep y 0x0040060d in function[abi:cxx11](int)
15807 at main.cc:10
15808@end smallexample
15809
15810On the rare occasion you need to disambiguate between different ABI
15811tags, you can do so by simply including the ABI tag in the function
15812name, like:
15813
15814@smallexample
15815(@value{GDBP}) b ambiguous[abi:other_tag](int)
15816@end smallexample
c906108c 15817@end table
c906108c 15818
febe4383
TJB
15819@node Decimal Floating Point
15820@subsubsection Decimal Floating Point format
15821@cindex decimal floating point format
15822
15823@value{GDBN} can examine, set and perform computations with numbers in
15824decimal floating point format, which in the C language correspond to the
15825@code{_Decimal32}, @code{_Decimal64} and @code{_Decimal128} types as
15826specified by the extension to support decimal floating-point arithmetic.
15827
15828There are two encodings in use, depending on the architecture: BID (Binary
15829Integer Decimal) for x86 and x86-64, and DPD (Densely Packed Decimal) for
4ac33720
UW
15830PowerPC and S/390. @value{GDBN} will use the appropriate encoding for the
15831configured target.
febe4383
TJB
15832
15833Because of a limitation in @file{libdecnumber}, the library used by @value{GDBN}
15834to manipulate decimal floating point numbers, it is not possible to convert
15835(using a cast, for example) integers wider than 32-bit to decimal float.
15836
15837In addition, in order to imitate @value{GDBN}'s behaviour with binary floating
15838point computations, error checking in decimal float operations ignores
15839underflow, overflow and divide by zero exceptions.
15840
4acd40f3 15841In the PowerPC architecture, @value{GDBN} provides a set of pseudo-registers
99e008fe
EZ
15842to inspect @code{_Decimal128} values stored in floating point registers.
15843See @ref{PowerPC,,PowerPC} for more details.
4acd40f3 15844
6aecb9c2
JB
15845@node D
15846@subsection D
15847
15848@cindex D
15849@value{GDBN} can be used to debug programs written in D and compiled with
15850GDC, LDC or DMD compilers. Currently @value{GDBN} supports only one D
15851specific feature --- dynamic arrays.
15852
a766d390
DE
15853@node Go
15854@subsection Go
15855
15856@cindex Go (programming language)
15857@value{GDBN} can be used to debug programs written in Go and compiled with
15858@file{gccgo} or @file{6g} compilers.
15859
15860Here is a summary of the Go-specific features and restrictions:
15861
15862@table @code
15863@cindex current Go package
15864@item The current Go package
15865The name of the current package does not need to be specified when
15866specifying global variables and functions.
15867
15868For example, given the program:
15869
15870@example
15871package main
15872var myglob = "Shall we?"
15873func main () @{
15874 // ...
15875@}
15876@end example
15877
15878When stopped inside @code{main} either of these work:
15879
15880@example
15881(gdb) p myglob
15882(gdb) p main.myglob
15883@end example
15884
15885@cindex builtin Go types
15886@item Builtin Go types
15887The @code{string} type is recognized by @value{GDBN} and is printed
15888as a string.
15889
15890@cindex builtin Go functions
15891@item Builtin Go functions
15892The @value{GDBN} expression parser recognizes the @code{unsafe.Sizeof}
15893function and handles it internally.
a766d390
DE
15894
15895@cindex restrictions on Go expressions
15896@item Restrictions on Go expressions
15897All Go operators are supported except @code{&^}.
15898The Go @code{_} ``blank identifier'' is not supported.
15899Automatic dereferencing of pointers is not supported.
50f042b9 15900@end table
a766d390 15901
b37303ee
AF
15902@node Objective-C
15903@subsection Objective-C
15904
15905@cindex Objective-C
15906This section provides information about some commands and command
721c2651
EZ
15907options that are useful for debugging Objective-C code. See also
15908@ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
15909few more commands specific to Objective-C support.
b37303ee
AF
15910
15911@menu
b383017d
RM
15912* Method Names in Commands::
15913* The Print Command with Objective-C::
b37303ee
AF
15914@end menu
15915
c8f4133a 15916@node Method Names in Commands
b37303ee
AF
15917@subsubsection Method Names in Commands
15918
15919The following commands have been extended to accept Objective-C method
15920names as line specifications:
15921
15922@kindex clear@r{, and Objective-C}
15923@kindex break@r{, and Objective-C}
15924@kindex info line@r{, and Objective-C}
15925@kindex jump@r{, and Objective-C}
15926@kindex list@r{, and Objective-C}
15927@itemize
15928@item @code{clear}
15929@item @code{break}
15930@item @code{info line}
15931@item @code{jump}
15932@item @code{list}
15933@end itemize
15934
15935A fully qualified Objective-C method name is specified as
15936
15937@smallexample
15938-[@var{Class} @var{methodName}]
15939@end smallexample
15940
c552b3bb
JM
15941where the minus sign is used to indicate an instance method and a
15942plus sign (not shown) is used to indicate a class method. The class
15943name @var{Class} and method name @var{methodName} are enclosed in
15944brackets, similar to the way messages are specified in Objective-C
15945source code. For example, to set a breakpoint at the @code{create}
15946instance method of class @code{Fruit} in the program currently being
15947debugged, enter:
b37303ee
AF
15948
15949@smallexample
15950break -[Fruit create]
15951@end smallexample
15952
15953To list ten program lines around the @code{initialize} class method,
15954enter:
15955
15956@smallexample
15957list +[NSText initialize]
15958@end smallexample
15959
c552b3bb
JM
15960In the current version of @value{GDBN}, the plus or minus sign is
15961required. In future versions of @value{GDBN}, the plus or minus
15962sign will be optional, but you can use it to narrow the search. It
15963is also possible to specify just a method name:
b37303ee
AF
15964
15965@smallexample
15966break create
15967@end smallexample
15968
15969You must specify the complete method name, including any colons. If
15970your program's source files contain more than one @code{create} method,
15971you'll be presented with a numbered list of classes that implement that
15972method. Indicate your choice by number, or type @samp{0} to exit if
15973none apply.
15974
15975As another example, to clear a breakpoint established at the
15976@code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
15977
15978@smallexample
15979clear -[NSWindow makeKeyAndOrderFront:]
15980@end smallexample
15981
15982@node The Print Command with Objective-C
15983@subsubsection The Print Command With Objective-C
721c2651 15984@cindex Objective-C, print objects
c552b3bb
JM
15985@kindex print-object
15986@kindex po @r{(@code{print-object})}
b37303ee 15987
c552b3bb 15988The print command has also been extended to accept methods. For example:
b37303ee
AF
15989
15990@smallexample
c552b3bb 15991print -[@var{object} hash]
b37303ee
AF
15992@end smallexample
15993
15994@cindex print an Objective-C object description
c552b3bb
JM
15995@cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
15996@noindent
15997will tell @value{GDBN} to send the @code{hash} message to @var{object}
15998and print the result. Also, an additional command has been added,
15999@code{print-object} or @code{po} for short, which is meant to print
16000the description of an object. However, this command may only work
16001with certain Objective-C libraries that have a particular hook
16002function, @code{_NSPrintForDebugger}, defined.
b37303ee 16003
f4b8a18d
KW
16004@node OpenCL C
16005@subsection OpenCL C
16006
16007@cindex OpenCL C
16008This section provides information about @value{GDBN}s OpenCL C support.
16009
16010@menu
16011* OpenCL C Datatypes::
16012* OpenCL C Expressions::
16013* OpenCL C Operators::
16014@end menu
16015
16016@node OpenCL C Datatypes
16017@subsubsection OpenCL C Datatypes
16018
16019@cindex OpenCL C Datatypes
16020@value{GDBN} supports the builtin scalar and vector datatypes specified
16021by OpenCL 1.1. In addition the half- and double-precision floating point
16022data types of the @code{cl_khr_fp16} and @code{cl_khr_fp64} OpenCL
16023extensions are also known to @value{GDBN}.
16024
16025@node OpenCL C Expressions
16026@subsubsection OpenCL C Expressions
16027
16028@cindex OpenCL C Expressions
16029@value{GDBN} supports accesses to vector components including the access as
16030lvalue where possible. Since OpenCL C is based on C99 most C expressions
16031supported by @value{GDBN} can be used as well.
16032
16033@node OpenCL C Operators
16034@subsubsection OpenCL C Operators
16035
16036@cindex OpenCL C Operators
16037@value{GDBN} supports the operators specified by OpenCL 1.1 for scalar and
16038vector data types.
16039
09d4efe1
EZ
16040@node Fortran
16041@subsection Fortran
16042@cindex Fortran-specific support in @value{GDBN}
16043
814e32d7
WZ
16044@value{GDBN} can be used to debug programs written in Fortran, but it
16045currently supports only the features of Fortran 77 language.
16046
16047@cindex trailing underscore, in Fortran symbols
16048Some Fortran compilers (@sc{gnu} Fortran 77 and Fortran 95 compilers
16049among them) append an underscore to the names of variables and
16050functions. When you debug programs compiled by those compilers, you
16051will need to refer to variables and functions with a trailing
16052underscore.
16053
16054@menu
16055* Fortran Operators:: Fortran operators and expressions
16056* Fortran Defaults:: Default settings for Fortran
79a6e687 16057* Special Fortran Commands:: Special @value{GDBN} commands for Fortran
814e32d7
WZ
16058@end menu
16059
16060@node Fortran Operators
79a6e687 16061@subsubsection Fortran Operators and Expressions
814e32d7
WZ
16062
16063@cindex Fortran operators and expressions
16064
16065Operators must be defined on values of specific types. For instance,
16066@code{+} is defined on numbers, but not on characters or other non-
ff2587ec 16067arithmetic types. Operators are often defined on groups of types.
814e32d7
WZ
16068
16069@table @code
16070@item **
99e008fe 16071The exponentiation operator. It raises the first operand to the power
814e32d7
WZ
16072of the second one.
16073
16074@item :
16075The range operator. Normally used in the form of array(low:high) to
16076represent a section of array.
68837c9d
MD
16077
16078@item %
16079The access component operator. Normally used to access elements in derived
16080types. Also suitable for unions. As unions aren't part of regular Fortran,
16081this can only happen when accessing a register that uses a gdbarch-defined
16082union type.
814e32d7
WZ
16083@end table
16084
16085@node Fortran Defaults
16086@subsubsection Fortran Defaults
16087
16088@cindex Fortran Defaults
16089
16090Fortran symbols are usually case-insensitive, so @value{GDBN} by
16091default uses case-insensitive matches for Fortran symbols. You can
16092change that with the @samp{set case-insensitive} command, see
16093@ref{Symbols}, for the details.
16094
79a6e687
BW
16095@node Special Fortran Commands
16096@subsubsection Special Fortran Commands
814e32d7
WZ
16097
16098@cindex Special Fortran commands
16099
db2e3e2e
BW
16100@value{GDBN} has some commands to support Fortran-specific features,
16101such as displaying common blocks.
814e32d7 16102
09d4efe1
EZ
16103@table @code
16104@cindex @code{COMMON} blocks, Fortran
16105@kindex info common
16106@item info common @r{[}@var{common-name}@r{]}
16107This command prints the values contained in the Fortran @code{COMMON}
16108block whose name is @var{common-name}. With no argument, the names of
d52fb0e9 16109all @code{COMMON} blocks visible at the current program location are
09d4efe1
EZ
16110printed.
16111@end table
16112
9c16f35a
EZ
16113@node Pascal
16114@subsection Pascal
16115
16116@cindex Pascal support in @value{GDBN}, limitations
16117Debugging Pascal programs which use sets, subranges, file variables, or
16118nested functions does not currently work. @value{GDBN} does not support
16119entering expressions, printing values, or similar features using Pascal
16120syntax.
16121
16122The Pascal-specific command @code{set print pascal_static-members}
16123controls whether static members of Pascal objects are displayed.
16124@xref{Print Settings, pascal_static-members}.
16125
0bdfa368
TT
16126@node Rust
16127@subsection Rust
16128
16129@value{GDBN} supports the @url{https://www.rust-lang.org/, Rust
16130Programming Language}. Type- and value-printing, and expression
16131parsing, are reasonably complete. However, there are a few
16132peculiarities and holes to be aware of.
16133
16134@itemize @bullet
16135@item
16136Linespecs (@pxref{Specify Location}) are never relative to the current
16137crate. Instead, they act as if there were a global namespace of
16138crates, somewhat similar to the way @code{extern crate} behaves.
16139
16140That is, if @value{GDBN} is stopped at a breakpoint in a function in
16141crate @samp{A}, module @samp{B}, then @code{break B::f} will attempt
16142to set a breakpoint in a function named @samp{f} in a crate named
16143@samp{B}.
16144
16145As a consequence of this approach, linespecs also cannot refer to
16146items using @samp{self::} or @samp{super::}.
16147
16148@item
16149Because @value{GDBN} implements Rust name-lookup semantics in
16150expressions, it will sometimes prepend the current crate to a name.
16151For example, if @value{GDBN} is stopped at a breakpoint in the crate
16152@samp{K}, then @code{print ::x::y} will try to find the symbol
16153@samp{K::x::y}.
16154
16155However, since it is useful to be able to refer to other crates when
16156debugging, @value{GDBN} provides the @code{extern} extension to
16157circumvent this. To use the extension, just put @code{extern} before
16158a path expression to refer to the otherwise unavailable ``global''
16159scope.
16160
16161In the above example, if you wanted to refer to the symbol @samp{y} in
16162the crate @samp{x}, you would use @code{print extern x::y}.
16163
16164@item
16165The Rust expression evaluator does not support ``statement-like''
16166expressions such as @code{if} or @code{match}, or lambda expressions.
16167
16168@item
16169Tuple expressions are not implemented.
16170
16171@item
16172The Rust expression evaluator does not currently implement the
16173@code{Drop} trait. Objects that may be created by the evaluator will
16174never be destroyed.
16175
16176@item
16177@value{GDBN} does not implement type inference for generics. In order
16178to call generic functions or otherwise refer to generic items, you
16179will have to specify the type parameters manually.
16180
16181@item
16182@value{GDBN} currently uses the C@t{++} demangler for Rust. In most
16183cases this does not cause any problems. However, in an expression
16184context, completing a generic function name will give syntactically
16185invalid results. This happens because Rust requires the @samp{::}
16186operator between the function name and its generic arguments. For
16187example, @value{GDBN} might provide a completion like
16188@code{crate::f<u32>}, where the parser would require
16189@code{crate::f::<u32>}.
16190
16191@item
16192As of this writing, the Rust compiler (version 1.8) has a few holes in
16193the debugging information it generates. These holes prevent certain
16194features from being implemented by @value{GDBN}:
16195@itemize @bullet
16196
16197@item
16198Method calls cannot be made via traits.
16199
0bdfa368
TT
16200@item
16201Operator overloading is not implemented.
16202
16203@item
16204When debugging in a monomorphized function, you cannot use the generic
16205type names.
16206
16207@item
16208The type @code{Self} is not available.
16209
16210@item
16211@code{use} statements are not available, so some names may not be
16212available in the crate.
16213@end itemize
16214@end itemize
16215
09d4efe1 16216@node Modula-2
c906108c 16217@subsection Modula-2
7a292a7a 16218
d4f3574e 16219@cindex Modula-2, @value{GDBN} support
c906108c
SS
16220
16221The extensions made to @value{GDBN} to support Modula-2 only support
16222output from the @sc{gnu} Modula-2 compiler (which is currently being
16223developed). Other Modula-2 compilers are not currently supported, and
16224attempting to debug executables produced by them is most likely
16225to give an error as @value{GDBN} reads in the executable's symbol
16226table.
16227
16228@cindex expressions in Modula-2
16229@menu
16230* M2 Operators:: Built-in operators
16231* Built-In Func/Proc:: Built-in functions and procedures
16232* M2 Constants:: Modula-2 constants
72019c9c 16233* M2 Types:: Modula-2 types
c906108c
SS
16234* M2 Defaults:: Default settings for Modula-2
16235* Deviations:: Deviations from standard Modula-2
16236* M2 Checks:: Modula-2 type and range checks
16237* M2 Scope:: The scope operators @code{::} and @code{.}
16238* GDB/M2:: @value{GDBN} and Modula-2
16239@end menu
16240
6d2ebf8b 16241@node M2 Operators
c906108c
SS
16242@subsubsection Operators
16243@cindex Modula-2 operators
16244
16245Operators must be defined on values of specific types. For instance,
16246@code{+} is defined on numbers, but not on structures. Operators are
16247often defined on groups of types. For the purposes of Modula-2, the
16248following definitions hold:
16249
16250@itemize @bullet
16251
16252@item
16253@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
16254their subranges.
16255
16256@item
16257@emph{Character types} consist of @code{CHAR} and its subranges.
16258
16259@item
16260@emph{Floating-point types} consist of @code{REAL}.
16261
16262@item
16263@emph{Pointer types} consist of anything declared as @code{POINTER TO
16264@var{type}}.
16265
16266@item
16267@emph{Scalar types} consist of all of the above.
16268
16269@item
16270@emph{Set types} consist of @code{SET} and @code{BITSET} types.
16271
16272@item
16273@emph{Boolean types} consist of @code{BOOLEAN}.
16274@end itemize
16275
16276@noindent
16277The following operators are supported, and appear in order of
16278increasing precedence:
16279
16280@table @code
16281@item ,
16282Function argument or array index separator.
16283
16284@item :=
16285Assignment. The value of @var{var} @code{:=} @var{value} is
16286@var{value}.
16287
16288@item <@r{, }>
16289Less than, greater than on integral, floating-point, or enumerated
16290types.
16291
16292@item <=@r{, }>=
96a2c332 16293Less than or equal to, greater than or equal to
c906108c
SS
16294on integral, floating-point and enumerated types, or set inclusion on
16295set types. Same precedence as @code{<}.
16296
16297@item =@r{, }<>@r{, }#
16298Equality and two ways of expressing inequality, valid on scalar types.
16299Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
16300available for inequality, since @code{#} conflicts with the script
16301comment character.
16302
16303@item IN
16304Set membership. Defined on set types and the types of their members.
16305Same precedence as @code{<}.
16306
16307@item OR
16308Boolean disjunction. Defined on boolean types.
16309
16310@item AND@r{, }&
d4f3574e 16311Boolean conjunction. Defined on boolean types.
c906108c
SS
16312
16313@item @@
16314The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
16315
16316@item +@r{, }-
16317Addition and subtraction on integral and floating-point types, or union
16318and difference on set types.
16319
16320@item *
16321Multiplication on integral and floating-point types, or set intersection
16322on set types.
16323
16324@item /
16325Division on floating-point types, or symmetric set difference on set
16326types. Same precedence as @code{*}.
16327
16328@item DIV@r{, }MOD
16329Integer division and remainder. Defined on integral types. Same
16330precedence as @code{*}.
16331
16332@item -
99e008fe 16333Negative. Defined on @code{INTEGER} and @code{REAL} data.
c906108c
SS
16334
16335@item ^
16336Pointer dereferencing. Defined on pointer types.
16337
16338@item NOT
16339Boolean negation. Defined on boolean types. Same precedence as
16340@code{^}.
16341
16342@item .
16343@code{RECORD} field selector. Defined on @code{RECORD} data. Same
16344precedence as @code{^}.
16345
16346@item []
16347Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
16348
16349@item ()
16350Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
16351as @code{^}.
16352
16353@item ::@r{, }.
16354@value{GDBN} and Modula-2 scope operators.
16355@end table
16356
16357@quotation
72019c9c 16358@emph{Warning:} Set expressions and their operations are not yet supported, so @value{GDBN}
c906108c
SS
16359treats the use of the operator @code{IN}, or the use of operators
16360@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
16361@code{<=}, and @code{>=} on sets as an error.
16362@end quotation
16363
cb51c4e0 16364
6d2ebf8b 16365@node Built-In Func/Proc
79a6e687 16366@subsubsection Built-in Functions and Procedures
cb51c4e0 16367@cindex Modula-2 built-ins
c906108c
SS
16368
16369Modula-2 also makes available several built-in procedures and functions.
16370In describing these, the following metavariables are used:
16371
16372@table @var
16373
16374@item a
16375represents an @code{ARRAY} variable.
16376
16377@item c
16378represents a @code{CHAR} constant or variable.
16379
16380@item i
16381represents a variable or constant of integral type.
16382
16383@item m
16384represents an identifier that belongs to a set. Generally used in the
16385same function with the metavariable @var{s}. The type of @var{s} should
16386be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
16387
16388@item n
16389represents a variable or constant of integral or floating-point type.
16390
16391@item r
16392represents a variable or constant of floating-point type.
16393
16394@item t
16395represents a type.
16396
16397@item v
16398represents a variable.
16399
16400@item x
16401represents a variable or constant of one of many types. See the
16402explanation of the function for details.
16403@end table
16404
16405All Modula-2 built-in procedures also return a result, described below.
16406
16407@table @code
16408@item ABS(@var{n})
16409Returns the absolute value of @var{n}.
16410
16411@item CAP(@var{c})
16412If @var{c} is a lower case letter, it returns its upper case
c3f6f71d 16413equivalent, otherwise it returns its argument.
c906108c
SS
16414
16415@item CHR(@var{i})
16416Returns the character whose ordinal value is @var{i}.
16417
16418@item DEC(@var{v})
c3f6f71d 16419Decrements the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
16420
16421@item DEC(@var{v},@var{i})
16422Decrements the value in the variable @var{v} by @var{i}. Returns the
16423new value.
16424
16425@item EXCL(@var{m},@var{s})
16426Removes the element @var{m} from the set @var{s}. Returns the new
16427set.
16428
16429@item FLOAT(@var{i})
16430Returns the floating point equivalent of the integer @var{i}.
16431
16432@item HIGH(@var{a})
16433Returns the index of the last member of @var{a}.
16434
16435@item INC(@var{v})
c3f6f71d 16436Increments the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
16437
16438@item INC(@var{v},@var{i})
16439Increments the value in the variable @var{v} by @var{i}. Returns the
16440new value.
16441
16442@item INCL(@var{m},@var{s})
16443Adds the element @var{m} to the set @var{s} if it is not already
16444there. Returns the new set.
16445
16446@item MAX(@var{t})
16447Returns the maximum value of the type @var{t}.
16448
16449@item MIN(@var{t})
16450Returns the minimum value of the type @var{t}.
16451
16452@item ODD(@var{i})
16453Returns boolean TRUE if @var{i} is an odd number.
16454
16455@item ORD(@var{x})
16456Returns the ordinal value of its argument. For example, the ordinal
697aa1b7
EZ
16457value of a character is its @sc{ascii} value (on machines supporting
16458the @sc{ascii} character set). The argument @var{x} must be of an
16459ordered type, which include integral, character and enumerated types.
c906108c
SS
16460
16461@item SIZE(@var{x})
697aa1b7
EZ
16462Returns the size of its argument. The argument @var{x} can be a
16463variable or a type.
c906108c
SS
16464
16465@item TRUNC(@var{r})
16466Returns the integral part of @var{r}.
16467
844781a1 16468@item TSIZE(@var{x})
697aa1b7
EZ
16469Returns the size of its argument. The argument @var{x} can be a
16470variable or a type.
844781a1 16471
c906108c
SS
16472@item VAL(@var{t},@var{i})
16473Returns the member of the type @var{t} whose ordinal value is @var{i}.
16474@end table
16475
16476@quotation
16477@emph{Warning:} Sets and their operations are not yet supported, so
16478@value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
16479an error.
16480@end quotation
16481
16482@cindex Modula-2 constants
6d2ebf8b 16483@node M2 Constants
c906108c
SS
16484@subsubsection Constants
16485
16486@value{GDBN} allows you to express the constants of Modula-2 in the following
16487ways:
16488
16489@itemize @bullet
16490
16491@item
16492Integer constants are simply a sequence of digits. When used in an
16493expression, a constant is interpreted to be type-compatible with the
16494rest of the expression. Hexadecimal integers are specified by a
16495trailing @samp{H}, and octal integers by a trailing @samp{B}.
16496
16497@item
16498Floating point constants appear as a sequence of digits, followed by a
16499decimal point and another sequence of digits. An optional exponent can
16500then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
16501@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
16502digits of the floating point constant must be valid decimal (base 10)
16503digits.
16504
16505@item
16506Character constants consist of a single character enclosed by a pair of
16507like quotes, either single (@code{'}) or double (@code{"}). They may
c3f6f71d 16508also be expressed by their ordinal value (their @sc{ascii} value, usually)
c906108c
SS
16509followed by a @samp{C}.
16510
16511@item
16512String constants consist of a sequence of characters enclosed by a
16513pair of like quotes, either single (@code{'}) or double (@code{"}).
16514Escape sequences in the style of C are also allowed. @xref{C
79a6e687 16515Constants, ,C and C@t{++} Constants}, for a brief explanation of escape
c906108c
SS
16516sequences.
16517
16518@item
16519Enumerated constants consist of an enumerated identifier.
16520
16521@item
16522Boolean constants consist of the identifiers @code{TRUE} and
16523@code{FALSE}.
16524
16525@item
16526Pointer constants consist of integral values only.
16527
16528@item
16529Set constants are not yet supported.
16530@end itemize
16531
72019c9c
GM
16532@node M2 Types
16533@subsubsection Modula-2 Types
16534@cindex Modula-2 types
16535
16536Currently @value{GDBN} can print the following data types in Modula-2
16537syntax: array types, record types, set types, pointer types, procedure
16538types, enumerated types, subrange types and base types. You can also
16539print the contents of variables declared using these type.
16540This section gives a number of simple source code examples together with
16541sample @value{GDBN} sessions.
16542
16543The first example contains the following section of code:
16544
16545@smallexample
16546VAR
16547 s: SET OF CHAR ;
16548 r: [20..40] ;
16549@end smallexample
16550
16551@noindent
16552and you can request @value{GDBN} to interrogate the type and value of
16553@code{r} and @code{s}.
16554
16555@smallexample
16556(@value{GDBP}) print s
16557@{'A'..'C', 'Z'@}
16558(@value{GDBP}) ptype s
16559SET OF CHAR
16560(@value{GDBP}) print r
1656121
16562(@value{GDBP}) ptype r
16563[20..40]
16564@end smallexample
16565
16566@noindent
16567Likewise if your source code declares @code{s} as:
16568
16569@smallexample
16570VAR
16571 s: SET ['A'..'Z'] ;
16572@end smallexample
16573
16574@noindent
16575then you may query the type of @code{s} by:
16576
16577@smallexample
16578(@value{GDBP}) ptype s
16579type = SET ['A'..'Z']
16580@end smallexample
16581
16582@noindent
16583Note that at present you cannot interactively manipulate set
16584expressions using the debugger.
16585
16586The following example shows how you might declare an array in Modula-2
16587and how you can interact with @value{GDBN} to print its type and contents:
16588
16589@smallexample
16590VAR
16591 s: ARRAY [-10..10] OF CHAR ;
16592@end smallexample
16593
16594@smallexample
16595(@value{GDBP}) ptype s
16596ARRAY [-10..10] OF CHAR
16597@end smallexample
16598
16599Note that the array handling is not yet complete and although the type
16600is printed correctly, expression handling still assumes that all
16601arrays have a lower bound of zero and not @code{-10} as in the example
844781a1 16602above.
72019c9c
GM
16603
16604Here are some more type related Modula-2 examples:
16605
16606@smallexample
16607TYPE
16608 colour = (blue, red, yellow, green) ;
16609 t = [blue..yellow] ;
16610VAR
16611 s: t ;
16612BEGIN
16613 s := blue ;
16614@end smallexample
16615
16616@noindent
16617The @value{GDBN} interaction shows how you can query the data type
16618and value of a variable.
16619
16620@smallexample
16621(@value{GDBP}) print s
16622$1 = blue
16623(@value{GDBP}) ptype t
16624type = [blue..yellow]
16625@end smallexample
16626
16627@noindent
16628In this example a Modula-2 array is declared and its contents
16629displayed. Observe that the contents are written in the same way as
16630their @code{C} counterparts.
16631
16632@smallexample
16633VAR
16634 s: ARRAY [1..5] OF CARDINAL ;
16635BEGIN
16636 s[1] := 1 ;
16637@end smallexample
16638
16639@smallexample
16640(@value{GDBP}) print s
16641$1 = @{1, 0, 0, 0, 0@}
16642(@value{GDBP}) ptype s
16643type = ARRAY [1..5] OF CARDINAL
16644@end smallexample
16645
16646The Modula-2 language interface to @value{GDBN} also understands
16647pointer types as shown in this example:
16648
16649@smallexample
16650VAR
16651 s: POINTER TO ARRAY [1..5] OF CARDINAL ;
16652BEGIN
16653 NEW(s) ;
16654 s^[1] := 1 ;
16655@end smallexample
16656
16657@noindent
16658and you can request that @value{GDBN} describes the type of @code{s}.
16659
16660@smallexample
16661(@value{GDBP}) ptype s
16662type = POINTER TO ARRAY [1..5] OF CARDINAL
16663@end smallexample
16664
16665@value{GDBN} handles compound types as we can see in this example.
16666Here we combine array types, record types, pointer types and subrange
16667types:
16668
16669@smallexample
16670TYPE
16671 foo = RECORD
16672 f1: CARDINAL ;
16673 f2: CHAR ;
16674 f3: myarray ;
16675 END ;
16676
16677 myarray = ARRAY myrange OF CARDINAL ;
16678 myrange = [-2..2] ;
16679VAR
16680 s: POINTER TO ARRAY myrange OF foo ;
16681@end smallexample
16682
16683@noindent
16684and you can ask @value{GDBN} to describe the type of @code{s} as shown
16685below.
16686
16687@smallexample
16688(@value{GDBP}) ptype s
16689type = POINTER TO ARRAY [-2..2] OF foo = RECORD
16690 f1 : CARDINAL;
16691 f2 : CHAR;
16692 f3 : ARRAY [-2..2] OF CARDINAL;
16693END
16694@end smallexample
16695
6d2ebf8b 16696@node M2 Defaults
79a6e687 16697@subsubsection Modula-2 Defaults
c906108c
SS
16698@cindex Modula-2 defaults
16699
16700If type and range checking are set automatically by @value{GDBN}, they
16701both default to @code{on} whenever the working language changes to
d4f3574e 16702Modula-2. This happens regardless of whether you or @value{GDBN}
c906108c
SS
16703selected the working language.
16704
16705If you allow @value{GDBN} to set the language automatically, then entering
16706code compiled from a file whose name ends with @file{.mod} sets the
79a6e687
BW
16707working language to Modula-2. @xref{Automatically, ,Having @value{GDBN}
16708Infer the Source Language}, for further details.
c906108c 16709
6d2ebf8b 16710@node Deviations
79a6e687 16711@subsubsection Deviations from Standard Modula-2
c906108c
SS
16712@cindex Modula-2, deviations from
16713
16714A few changes have been made to make Modula-2 programs easier to debug.
16715This is done primarily via loosening its type strictness:
16716
16717@itemize @bullet
16718@item
16719Unlike in standard Modula-2, pointer constants can be formed by
16720integers. This allows you to modify pointer variables during
16721debugging. (In standard Modula-2, the actual address contained in a
16722pointer variable is hidden from you; it can only be modified
16723through direct assignment to another pointer variable or expression that
16724returned a pointer.)
16725
16726@item
16727C escape sequences can be used in strings and characters to represent
16728non-printable characters. @value{GDBN} prints out strings with these
16729escape sequences embedded. Single non-printable characters are
16730printed using the @samp{CHR(@var{nnn})} format.
16731
16732@item
16733The assignment operator (@code{:=}) returns the value of its right-hand
16734argument.
16735
16736@item
16737All built-in procedures both modify @emph{and} return their argument.
16738@end itemize
16739
6d2ebf8b 16740@node M2 Checks
79a6e687 16741@subsubsection Modula-2 Type and Range Checks
c906108c
SS
16742@cindex Modula-2 checks
16743
16744@quotation
16745@emph{Warning:} in this release, @value{GDBN} does not yet perform type or
16746range checking.
16747@end quotation
16748@c FIXME remove warning when type/range checks added
16749
16750@value{GDBN} considers two Modula-2 variables type equivalent if:
16751
16752@itemize @bullet
16753@item
16754They are of types that have been declared equivalent via a @code{TYPE
16755@var{t1} = @var{t2}} statement
16756
16757@item
16758They have been declared on the same line. (Note: This is true of the
16759@sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
16760@end itemize
16761
16762As long as type checking is enabled, any attempt to combine variables
16763whose types are not equivalent is an error.
16764
16765Range checking is done on all mathematical operations, assignment, array
16766index bounds, and all built-in functions and procedures.
16767
6d2ebf8b 16768@node M2 Scope
79a6e687 16769@subsubsection The Scope Operators @code{::} and @code{.}
c906108c 16770@cindex scope
41afff9a 16771@cindex @code{.}, Modula-2 scope operator
c906108c
SS
16772@cindex colon, doubled as scope operator
16773@ifinfo
41afff9a 16774@vindex colon-colon@r{, in Modula-2}
c906108c
SS
16775@c Info cannot handle :: but TeX can.
16776@end ifinfo
a67ec3f4 16777@ifnotinfo
41afff9a 16778@vindex ::@r{, in Modula-2}
a67ec3f4 16779@end ifnotinfo
c906108c
SS
16780
16781There are a few subtle differences between the Modula-2 scope operator
16782(@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
16783similar syntax:
16784
474c8240 16785@smallexample
c906108c
SS
16786
16787@var{module} . @var{id}
16788@var{scope} :: @var{id}
474c8240 16789@end smallexample
c906108c
SS
16790
16791@noindent
16792where @var{scope} is the name of a module or a procedure,
16793@var{module} the name of a module, and @var{id} is any declared
16794identifier within your program, except another module.
16795
16796Using the @code{::} operator makes @value{GDBN} search the scope
16797specified by @var{scope} for the identifier @var{id}. If it is not
16798found in the specified scope, then @value{GDBN} searches all scopes
16799enclosing the one specified by @var{scope}.
16800
16801Using the @code{.} operator makes @value{GDBN} search the current scope for
16802the identifier specified by @var{id} that was imported from the
16803definition module specified by @var{module}. With this operator, it is
16804an error if the identifier @var{id} was not imported from definition
16805module @var{module}, or if @var{id} is not an identifier in
16806@var{module}.
16807
6d2ebf8b 16808@node GDB/M2
c906108c
SS
16809@subsubsection @value{GDBN} and Modula-2
16810
16811Some @value{GDBN} commands have little use when debugging Modula-2 programs.
16812Five subcommands of @code{set print} and @code{show print} apply
b37052ae 16813specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
c906108c 16814@samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
b37052ae 16815apply to C@t{++}, and the last to the C @code{union} type, which has no direct
c906108c
SS
16816analogue in Modula-2.
16817
16818The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
d4f3574e 16819with any language, is not useful with Modula-2. Its
c906108c 16820intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
b37052ae 16821created in Modula-2 as they can in C or C@t{++}. However, because an
c906108c 16822address can be specified by an integral constant, the construct
d4f3574e 16823@samp{@{@var{type}@}@var{adrexp}} is still useful.
c906108c
SS
16824
16825@cindex @code{#} in Modula-2
16826In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
16827interpreted as the beginning of a comment. Use @code{<>} instead.
c906108c 16828
e07c999f
PH
16829@node Ada
16830@subsection Ada
16831@cindex Ada
16832
16833The extensions made to @value{GDBN} for Ada only support
16834output from the @sc{gnu} Ada (GNAT) compiler.
16835Other Ada compilers are not currently supported, and
16836attempting to debug executables produced by them is most likely
16837to be difficult.
16838
16839
16840@cindex expressions in Ada
16841@menu
16842* Ada Mode Intro:: General remarks on the Ada syntax
16843 and semantics supported by Ada mode
16844 in @value{GDBN}.
16845* Omissions from Ada:: Restrictions on the Ada expression syntax.
16846* Additions to Ada:: Extensions of the Ada expression syntax.
3685b09f
PMR
16847* Overloading support for Ada:: Support for expressions involving overloaded
16848 subprograms.
e07c999f 16849* Stopping Before Main Program:: Debugging the program during elaboration.
58d06528 16850* Ada Exceptions:: Ada Exceptions
20924a55
JB
16851* Ada Tasks:: Listing and setting breakpoints in tasks.
16852* Ada Tasks and Core Files:: Tasking Support when Debugging Core Files
6e1bb179
JB
16853* Ravenscar Profile:: Tasking Support when using the Ravenscar
16854 Profile
3fcded8f 16855* Ada Settings:: New settable GDB parameters for Ada.
e07c999f
PH
16856* Ada Glitches:: Known peculiarities of Ada mode.
16857@end menu
16858
16859@node Ada Mode Intro
16860@subsubsection Introduction
16861@cindex Ada mode, general
16862
16863The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
16864syntax, with some extensions.
16865The philosophy behind the design of this subset is
16866
16867@itemize @bullet
16868@item
16869That @value{GDBN} should provide basic literals and access to operations for
16870arithmetic, dereferencing, field selection, indexing, and subprogram calls,
16871leaving more sophisticated computations to subprograms written into the
16872program (which therefore may be called from @value{GDBN}).
16873
16874@item
16875That type safety and strict adherence to Ada language restrictions
16876are not particularly important to the @value{GDBN} user.
16877
16878@item
16879That brevity is important to the @value{GDBN} user.
16880@end itemize
16881
f3a2dd1a
JB
16882Thus, for brevity, the debugger acts as if all names declared in
16883user-written packages are directly visible, even if they are not visible
16884according to Ada rules, thus making it unnecessary to fully qualify most
16885names with their packages, regardless of context. Where this causes
16886ambiguity, @value{GDBN} asks the user's intent.
e07c999f
PH
16887
16888The debugger will start in Ada mode if it detects an Ada main program.
16889As for other languages, it will enter Ada mode when stopped in a program that
16890was translated from an Ada source file.
16891
16892While in Ada mode, you may use `@t{--}' for comments. This is useful
16893mostly for documenting command files. The standard @value{GDBN} comment
16894(@samp{#}) still works at the beginning of a line in Ada mode, but not in the
16895middle (to allow based literals).
16896
e07c999f
PH
16897@node Omissions from Ada
16898@subsubsection Omissions from Ada
16899@cindex Ada, omissions from
16900
16901Here are the notable omissions from the subset:
16902
16903@itemize @bullet
16904@item
16905Only a subset of the attributes are supported:
16906
16907@itemize @minus
16908@item
16909@t{'First}, @t{'Last}, and @t{'Length}
16910 on array objects (not on types and subtypes).
16911
16912@item
16913@t{'Min} and @t{'Max}.
16914
16915@item
16916@t{'Pos} and @t{'Val}.
16917
16918@item
16919@t{'Tag}.
16920
16921@item
16922@t{'Range} on array objects (not subtypes), but only as the right
16923operand of the membership (@code{in}) operator.
16924
16925@item
16926@t{'Access}, @t{'Unchecked_Access}, and
16927@t{'Unrestricted_Access} (a GNAT extension).
16928
16929@item
16930@t{'Address}.
16931@end itemize
16932
16933@item
16934The names in
16935@code{Characters.Latin_1} are not available and
16936concatenation is not implemented. Thus, escape characters in strings are
16937not currently available.
16938
16939@item
16940Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
16941equality of representations. They will generally work correctly
16942for strings and arrays whose elements have integer or enumeration types.
16943They may not work correctly for arrays whose element
16944types have user-defined equality, for arrays of real values
16945(in particular, IEEE-conformant floating point, because of negative
16946zeroes and NaNs), and for arrays whose elements contain unused bits with
16947indeterminate values.
16948
16949@item
16950The other component-by-component array operations (@code{and}, @code{or},
16951@code{xor}, @code{not}, and relational tests other than equality)
16952are not implemented.
16953
16954@item
860701dc
PH
16955@cindex array aggregates (Ada)
16956@cindex record aggregates (Ada)
16957@cindex aggregates (Ada)
16958There is limited support for array and record aggregates. They are
16959permitted only on the right sides of assignments, as in these examples:
16960
16961@smallexample
077e0a52
JB
16962(@value{GDBP}) set An_Array := (1, 2, 3, 4, 5, 6)
16963(@value{GDBP}) set An_Array := (1, others => 0)
16964(@value{GDBP}) set An_Array := (0|4 => 1, 1..3 => 2, 5 => 6)
16965(@value{GDBP}) set A_2D_Array := ((1, 2, 3), (4, 5, 6), (7, 8, 9))
16966(@value{GDBP}) set A_Record := (1, "Peter", True);
16967(@value{GDBP}) set A_Record := (Name => "Peter", Id => 1, Alive => True)
860701dc
PH
16968@end smallexample
16969
16970Changing a
16971discriminant's value by assigning an aggregate has an
16972undefined effect if that discriminant is used within the record.
16973However, you can first modify discriminants by directly assigning to
16974them (which normally would not be allowed in Ada), and then performing an
16975aggregate assignment. For example, given a variable @code{A_Rec}
16976declared to have a type such as:
16977
16978@smallexample
16979type Rec (Len : Small_Integer := 0) is record
16980 Id : Integer;
16981 Vals : IntArray (1 .. Len);
16982end record;
16983@end smallexample
16984
16985you can assign a value with a different size of @code{Vals} with two
16986assignments:
16987
16988@smallexample
077e0a52
JB
16989(@value{GDBP}) set A_Rec.Len := 4
16990(@value{GDBP}) set A_Rec := (Id => 42, Vals => (1, 2, 3, 4))
860701dc
PH
16991@end smallexample
16992
16993As this example also illustrates, @value{GDBN} is very loose about the usual
16994rules concerning aggregates. You may leave out some of the
16995components of an array or record aggregate (such as the @code{Len}
16996component in the assignment to @code{A_Rec} above); they will retain their
16997original values upon assignment. You may freely use dynamic values as
16998indices in component associations. You may even use overlapping or
16999redundant component associations, although which component values are
17000assigned in such cases is not defined.
e07c999f
PH
17001
17002@item
17003Calls to dispatching subprograms are not implemented.
17004
17005@item
17006The overloading algorithm is much more limited (i.e., less selective)
ae21e955
BW
17007than that of real Ada. It makes only limited use of the context in
17008which a subexpression appears to resolve its meaning, and it is much
17009looser in its rules for allowing type matches. As a result, some
17010function calls will be ambiguous, and the user will be asked to choose
17011the proper resolution.
e07c999f
PH
17012
17013@item
17014The @code{new} operator is not implemented.
17015
17016@item
17017Entry calls are not implemented.
17018
17019@item
17020Aside from printing, arithmetic operations on the native VAX floating-point
17021formats are not supported.
17022
17023@item
17024It is not possible to slice a packed array.
158c7665
PH
17025
17026@item
17027The names @code{True} and @code{False}, when not part of a qualified name,
17028are interpreted as if implicitly prefixed by @code{Standard}, regardless of
17029context.
17030Should your program
17031redefine these names in a package or procedure (at best a dubious practice),
17032you will have to use fully qualified names to access their new definitions.
e07c999f
PH
17033@end itemize
17034
17035@node Additions to Ada
17036@subsubsection Additions to Ada
17037@cindex Ada, deviations from
17038
17039As it does for other languages, @value{GDBN} makes certain generic
17040extensions to Ada (@pxref{Expressions}):
17041
17042@itemize @bullet
17043@item
ae21e955
BW
17044If the expression @var{E} is a variable residing in memory (typically
17045a local variable or array element) and @var{N} is a positive integer,
17046then @code{@var{E}@@@var{N}} displays the values of @var{E} and the
17047@var{N}-1 adjacent variables following it in memory as an array. In
17048Ada, this operator is generally not necessary, since its prime use is
17049in displaying parts of an array, and slicing will usually do this in
17050Ada. However, there are occasional uses when debugging programs in
17051which certain debugging information has been optimized away.
e07c999f
PH
17052
17053@item
ae21e955
BW
17054@code{@var{B}::@var{var}} means ``the variable named @var{var} that
17055appears in function or file @var{B}.'' When @var{B} is a file name,
17056you must typically surround it in single quotes.
e07c999f
PH
17057
17058@item
17059The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
17060@var{type} that appears at address @var{addr}.''
17061
17062@item
17063A name starting with @samp{$} is a convenience variable
17064(@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
17065@end itemize
17066
ae21e955
BW
17067In addition, @value{GDBN} provides a few other shortcuts and outright
17068additions specific to Ada:
e07c999f
PH
17069
17070@itemize @bullet
17071@item
17072The assignment statement is allowed as an expression, returning
17073its right-hand operand as its value. Thus, you may enter
17074
17075@smallexample
077e0a52
JB
17076(@value{GDBP}) set x := y + 3
17077(@value{GDBP}) print A(tmp := y + 1)
e07c999f
PH
17078@end smallexample
17079
17080@item
17081The semicolon is allowed as an ``operator,'' returning as its value
17082the value of its right-hand operand.
17083This allows, for example,
17084complex conditional breaks:
17085
17086@smallexample
077e0a52
JB
17087(@value{GDBP}) break f
17088(@value{GDBP}) condition 1 (report(i); k += 1; A(k) > 100)
e07c999f
PH
17089@end smallexample
17090
17091@item
17092Rather than use catenation and symbolic character names to introduce special
17093characters into strings, one may instead use a special bracket notation,
17094which is also used to print strings. A sequence of characters of the form
17095@samp{["@var{XX}"]} within a string or character literal denotes the
17096(single) character whose numeric encoding is @var{XX} in hexadecimal. The
17097sequence of characters @samp{["""]} also denotes a single quotation mark
17098in strings. For example,
17099@smallexample
17100 "One line.["0a"]Next line.["0a"]"
17101@end smallexample
17102@noindent
ae21e955
BW
17103contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF})
17104after each period.
e07c999f
PH
17105
17106@item
17107The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
17108@t{'Max} is optional (and is ignored in any case). For example, it is valid
17109to write
17110
17111@smallexample
077e0a52 17112(@value{GDBP}) print 'max(x, y)
e07c999f
PH
17113@end smallexample
17114
17115@item
17116When printing arrays, @value{GDBN} uses positional notation when the
17117array has a lower bound of 1, and uses a modified named notation otherwise.
ae21e955
BW
17118For example, a one-dimensional array of three integers with a lower bound
17119of 3 might print as
e07c999f
PH
17120
17121@smallexample
17122(3 => 10, 17, 1)
17123@end smallexample
17124
17125@noindent
17126That is, in contrast to valid Ada, only the first component has a @code{=>}
17127clause.
17128
17129@item
17130You may abbreviate attributes in expressions with any unique,
17131multi-character subsequence of
17132their names (an exact match gets preference).
17133For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
17134in place of @t{a'length}.
17135
17136@item
17137@cindex quoting Ada internal identifiers
17138Since Ada is case-insensitive, the debugger normally maps identifiers you type
17139to lower case. The GNAT compiler uses upper-case characters for
17140some of its internal identifiers, which are normally of no interest to users.
17141For the rare occasions when you actually have to look at them,
17142enclose them in angle brackets to avoid the lower-case mapping.
17143For example,
17144@smallexample
077e0a52 17145(@value{GDBP}) print <JMPBUF_SAVE>[0]
e07c999f
PH
17146@end smallexample
17147
17148@item
17149Printing an object of class-wide type or dereferencing an
17150access-to-class-wide value will display all the components of the object's
17151specific type (as indicated by its run-time tag). Likewise, component
17152selection on such a value will operate on the specific type of the
17153object.
17154
17155@end itemize
17156
3685b09f
PMR
17157@node Overloading support for Ada
17158@subsubsection Overloading support for Ada
17159@cindex overloading, Ada
17160
17161The debugger supports limited overloading. Given a subprogram call in which
17162the function symbol has multiple definitions, it will use the number of
17163actual parameters and some information about their types to attempt to narrow
17164the set of definitions. It also makes very limited use of context, preferring
17165procedures to functions in the context of the @code{call} command, and
17166functions to procedures elsewhere.
17167
17168If, after narrowing, the set of matching definitions still contains more than
17169one definition, @value{GDBN} will display a menu to query which one it should
17170use, for instance:
17171
17172@smallexample
17173(@value{GDBP}) print f(1)
17174Multiple matches for f
17175[0] cancel
17176[1] foo.f (integer) return boolean at foo.adb:23
17177[2] foo.f (foo.new_integer) return boolean at foo.adb:28
17178>
17179@end smallexample
17180
17181In this case, just select one menu entry either to cancel expression evaluation
17182(type @kbd{0} and press @key{RET}) or to continue evaluation with a specific
17183instance (type the corresponding number and press @key{RET}).
17184
17185Here are a couple of commands to customize @value{GDBN}'s behavior in this
17186case:
17187
17188@table @code
17189
17190@kindex set ada print-signatures
17191@item set ada print-signatures
17192Control whether parameter types and return types are displayed in overloads
17193selection menus. It is @code{on} by default.
17194@xref{Overloading support for Ada}.
17195
17196@kindex show ada print-signatures
17197@item show ada print-signatures
17198Show the current setting for displaying parameter types and return types in
17199overloads selection menu.
17200@xref{Overloading support for Ada}.
17201
17202@end table
17203
e07c999f
PH
17204@node Stopping Before Main Program
17205@subsubsection Stopping at the Very Beginning
17206
17207@cindex breakpointing Ada elaboration code
17208It is sometimes necessary to debug the program during elaboration, and
17209before reaching the main procedure.
17210As defined in the Ada Reference
17211Manual, the elaboration code is invoked from a procedure called
17212@code{adainit}. To run your program up to the beginning of
17213elaboration, simply use the following two commands:
17214@code{tbreak adainit} and @code{run}.
17215
58d06528
JB
17216@node Ada Exceptions
17217@subsubsection Ada Exceptions
17218
17219A command is provided to list all Ada exceptions:
17220
17221@table @code
17222@kindex info exceptions
17223@item info exceptions
17224@itemx info exceptions @var{regexp}
17225The @code{info exceptions} command allows you to list all Ada exceptions
17226defined within the program being debugged, as well as their addresses.
17227With a regular expression, @var{regexp}, as argument, only those exceptions
17228whose names match @var{regexp} are listed.
17229@end table
17230
17231Below is a small example, showing how the command can be used, first
17232without argument, and next with a regular expression passed as an
17233argument.
17234
17235@smallexample
17236(@value{GDBP}) info exceptions
17237All defined Ada exceptions:
17238constraint_error: 0x613da0
17239program_error: 0x613d20
17240storage_error: 0x613ce0
17241tasking_error: 0x613ca0
17242const.aint_global_e: 0x613b00
17243(@value{GDBP}) info exceptions const.aint
17244All Ada exceptions matching regular expression "const.aint":
17245constraint_error: 0x613da0
17246const.aint_global_e: 0x613b00
17247@end smallexample
17248
17249It is also possible to ask @value{GDBN} to stop your program's execution
17250when an exception is raised. For more details, see @ref{Set Catchpoints}.
17251
20924a55
JB
17252@node Ada Tasks
17253@subsubsection Extensions for Ada Tasks
17254@cindex Ada, tasking
17255
17256Support for Ada tasks is analogous to that for threads (@pxref{Threads}).
17257@value{GDBN} provides the following task-related commands:
17258
17259@table @code
17260@kindex info tasks
17261@item info tasks
17262This command shows a list of current Ada tasks, as in the following example:
17263
17264
17265@smallexample
17266@iftex
17267@leftskip=0.5cm
17268@end iftex
17269(@value{GDBP}) info tasks
17270 ID TID P-ID Pri State Name
17271 1 8088000 0 15 Child Activation Wait main_task
17272 2 80a4000 1 15 Accept Statement b
17273 3 809a800 1 15 Child Activation Wait a
32cd1edc 17274* 4 80ae800 3 15 Runnable c
20924a55
JB
17275
17276@end smallexample
17277
17278@noindent
17279In this listing, the asterisk before the last task indicates it to be the
17280task currently being inspected.
17281
17282@table @asis
17283@item ID
17284Represents @value{GDBN}'s internal task number.
17285
17286@item TID
17287The Ada task ID.
17288
17289@item P-ID
17290The parent's task ID (@value{GDBN}'s internal task number).
17291
17292@item Pri
17293The base priority of the task.
17294
17295@item State
17296Current state of the task.
17297
17298@table @code
17299@item Unactivated
17300The task has been created but has not been activated. It cannot be
17301executing.
17302
20924a55
JB
17303@item Runnable
17304The task is not blocked for any reason known to Ada. (It may be waiting
17305for a mutex, though.) It is conceptually "executing" in normal mode.
17306
17307@item Terminated
17308The task is terminated, in the sense of ARM 9.3 (5). Any dependents
17309that were waiting on terminate alternatives have been awakened and have
17310terminated themselves.
17311
17312@item Child Activation Wait
17313The task is waiting for created tasks to complete activation.
17314
17315@item Accept Statement
17316The task is waiting on an accept or selective wait statement.
17317
17318@item Waiting on entry call
17319The task is waiting on an entry call.
17320
17321@item Async Select Wait
17322The task is waiting to start the abortable part of an asynchronous
17323select statement.
17324
17325@item Delay Sleep
17326The task is waiting on a select statement with only a delay
17327alternative open.
17328
17329@item Child Termination Wait
17330The task is sleeping having completed a master within itself, and is
17331waiting for the tasks dependent on that master to become terminated or
17332waiting on a terminate Phase.
17333
17334@item Wait Child in Term Alt
17335The task is sleeping waiting for tasks on terminate alternatives to
17336finish terminating.
17337
17338@item Accepting RV with @var{taskno}
17339The task is accepting a rendez-vous with the task @var{taskno}.
17340@end table
17341
17342@item Name
17343Name of the task in the program.
17344
17345@end table
17346
17347@kindex info task @var{taskno}
17348@item info task @var{taskno}
17349This command shows detailled informations on the specified task, as in
17350the following example:
17351@smallexample
17352@iftex
17353@leftskip=0.5cm
17354@end iftex
17355(@value{GDBP}) info tasks
17356 ID TID P-ID Pri State Name
17357 1 8077880 0 15 Child Activation Wait main_task
32cd1edc 17358* 2 807c468 1 15 Runnable task_1
20924a55
JB
17359(@value{GDBP}) info task 2
17360Ada Task: 0x807c468
17361Name: task_1
87f7ab7b
JB
17362Thread: 0
17363LWP: 0x1fac
20924a55
JB
17364Parent: 1 (main_task)
17365Base Priority: 15
17366State: Runnable
17367@end smallexample
17368
17369@item task
17370@kindex task@r{ (Ada)}
17371@cindex current Ada task ID
17372This command prints the ID of the current task.
17373
17374@smallexample
17375@iftex
17376@leftskip=0.5cm
17377@end iftex
17378(@value{GDBP}) info tasks
17379 ID TID P-ID Pri State Name
17380 1 8077870 0 15 Child Activation Wait main_task
32cd1edc 17381* 2 807c458 1 15 Runnable t
20924a55
JB
17382(@value{GDBP}) task
17383[Current task is 2]
17384@end smallexample
17385
17386@item task @var{taskno}
17387@cindex Ada task switching
5d5658a1 17388This command is like the @code{thread @var{thread-id}}
20924a55
JB
17389command (@pxref{Threads}). It switches the context of debugging
17390from the current task to the given task.
17391
17392@smallexample
17393@iftex
17394@leftskip=0.5cm
17395@end iftex
17396(@value{GDBP}) info tasks
17397 ID TID P-ID Pri State Name
17398 1 8077870 0 15 Child Activation Wait main_task
32cd1edc 17399* 2 807c458 1 15 Runnable t
20924a55
JB
17400(@value{GDBP}) task 1
17401[Switching to task 1]
17402#0 0x8067726 in pthread_cond_wait ()
17403(@value{GDBP}) bt
17404#0 0x8067726 in pthread_cond_wait ()
17405#1 0x8056714 in system.os_interface.pthread_cond_wait ()
17406#2 0x805cb63 in system.task_primitives.operations.sleep ()
17407#3 0x806153e in system.tasking.stages.activate_tasks ()
17408#4 0x804aacc in un () at un.adb:5
17409@end smallexample
17410
629500fa
KS
17411@item break @var{location} task @var{taskno}
17412@itemx break @var{location} task @var{taskno} if @dots{}
45ac276d
JB
17413@cindex breakpoints and tasks, in Ada
17414@cindex task breakpoints, in Ada
17415@kindex break @dots{} task @var{taskno}@r{ (Ada)}
17416These commands are like the @code{break @dots{} thread @dots{}}
697aa1b7 17417command (@pxref{Thread Stops}). The
629500fa 17418@var{location} argument specifies source lines, as described
45ac276d
JB
17419in @ref{Specify Location}.
17420
17421Use the qualifier @samp{task @var{taskno}} with a breakpoint command
17422to specify that you only want @value{GDBN} to stop the program when a
697aa1b7 17423particular Ada task reaches this breakpoint. The @var{taskno} is one of the
45ac276d
JB
17424numeric task identifiers assigned by @value{GDBN}, shown in the first
17425column of the @samp{info tasks} display.
17426
17427If you do not specify @samp{task @var{taskno}} when you set a
17428breakpoint, the breakpoint applies to @emph{all} tasks of your
17429program.
17430
17431You can use the @code{task} qualifier on conditional breakpoints as
17432well; in this case, place @samp{task @var{taskno}} before the
17433breakpoint condition (before the @code{if}).
17434
17435For example,
17436
17437@smallexample
17438@iftex
17439@leftskip=0.5cm
17440@end iftex
17441(@value{GDBP}) info tasks
17442 ID TID P-ID Pri State Name
17443 1 140022020 0 15 Child Activation Wait main_task
17444 2 140045060 1 15 Accept/Select Wait t2
17445 3 140044840 1 15 Runnable t1
17446* 4 140056040 1 15 Runnable t3
17447(@value{GDBP}) b 15 task 2
17448Breakpoint 5 at 0x120044cb0: file test_task_debug.adb, line 15.
17449(@value{GDBP}) cont
17450Continuing.
17451task # 1 running
17452task # 2 running
17453
17454Breakpoint 5, test_task_debug () at test_task_debug.adb:15
1745515 flush;
17456(@value{GDBP}) info tasks
17457 ID TID P-ID Pri State Name
17458 1 140022020 0 15 Child Activation Wait main_task
17459* 2 140045060 1 15 Runnable t2
17460 3 140044840 1 15 Runnable t1
17461 4 140056040 1 15 Delay Sleep t3
17462@end smallexample
20924a55
JB
17463@end table
17464
17465@node Ada Tasks and Core Files
17466@subsubsection Tasking Support when Debugging Core Files
17467@cindex Ada tasking and core file debugging
17468
17469When inspecting a core file, as opposed to debugging a live program,
17470tasking support may be limited or even unavailable, depending on
17471the platform being used.
17472For instance, on x86-linux, the list of tasks is available, but task
32a8097b 17473switching is not supported.
20924a55 17474
32a8097b 17475On certain platforms, the debugger needs to perform some
20924a55
JB
17476memory writes in order to provide Ada tasking support. When inspecting
17477a core file, this means that the core file must be opened with read-write
17478privileges, using the command @samp{"set write on"} (@pxref{Patching}).
17479Under these circumstances, you should make a backup copy of the core
17480file before inspecting it with @value{GDBN}.
17481
6e1bb179
JB
17482@node Ravenscar Profile
17483@subsubsection Tasking Support when using the Ravenscar Profile
17484@cindex Ravenscar Profile
17485
17486The @dfn{Ravenscar Profile} is a subset of the Ada tasking features,
17487specifically designed for systems with safety-critical real-time
17488requirements.
17489
17490@table @code
17491@kindex set ravenscar task-switching on
17492@cindex task switching with program using Ravenscar Profile
17493@item set ravenscar task-switching on
17494Allows task switching when debugging a program that uses the Ravenscar
17495Profile. This is the default.
17496
17497@kindex set ravenscar task-switching off
17498@item set ravenscar task-switching off
17499Turn off task switching when debugging a program that uses the Ravenscar
17500Profile. This is mostly intended to disable the code that adds support
17501for the Ravenscar Profile, in case a bug in either @value{GDBN} or in
17502the Ravenscar runtime is preventing @value{GDBN} from working properly.
17503To be effective, this command should be run before the program is started.
17504
17505@kindex show ravenscar task-switching
17506@item show ravenscar task-switching
17507Show whether it is possible to switch from task to task in a program
17508using the Ravenscar Profile.
17509
17510@end table
17511
3fcded8f
JB
17512@node Ada Settings
17513@subsubsection Ada Settings
17514@cindex Ada settings
17515
17516@table @code
17517@kindex set varsize-limit
17518@item set varsize-limit @var{size}
17519Prevent @value{GDBN} from attempting to evaluate objects whose size
17520is above the given limit (@var{size}) when those sizes are computed
17521from run-time quantities. This is typically the case when the object
17522has a variable size, such as an array whose bounds are not known at
17523compile time for example. Setting @var{size} to @code{unlimited}
17524removes the size limitation. By default, the limit is about 65KB.
17525
17526The purpose of having such a limit is to prevent @value{GDBN} from
17527trying to grab enormous chunks of virtual memory when asked to evaluate
17528a quantity whose bounds have been corrupted or have not yet been fully
17529initialized. The limit applies to the results of some subexpressions
17530as well as to complete expressions. For example, an expression denoting
17531a simple integer component, such as @code{x.y.z}, may fail if the size of
17532@code{x.y} is variable and exceeds @code{size}. On the other hand,
17533@value{GDBN} is sometimes clever; the expression @code{A(i)}, where
17534@code{A} is an array variable with non-constant size, will generally
17535succeed regardless of the bounds on @code{A}, as long as the component
17536size is less than @var{size}.
17537
17538@kindex show varsize-limit
17539@item show varsize-limit
17540Show the limit on types whose size is determined by run-time quantities.
17541@end table
17542
e07c999f
PH
17543@node Ada Glitches
17544@subsubsection Known Peculiarities of Ada Mode
17545@cindex Ada, problems
17546
17547Besides the omissions listed previously (@pxref{Omissions from Ada}),
17548we know of several problems with and limitations of Ada mode in
17549@value{GDBN},
17550some of which will be fixed with planned future releases of the debugger
17551and the GNU Ada compiler.
17552
17553@itemize @bullet
e07c999f
PH
17554@item
17555Static constants that the compiler chooses not to materialize as objects in
17556storage are invisible to the debugger.
17557
17558@item
17559Named parameter associations in function argument lists are ignored (the
17560argument lists are treated as positional).
17561
17562@item
17563Many useful library packages are currently invisible to the debugger.
17564
17565@item
17566Fixed-point arithmetic, conversions, input, and output is carried out using
17567floating-point arithmetic, and may give results that only approximate those on
17568the host machine.
17569
e07c999f
PH
17570@item
17571The GNAT compiler never generates the prefix @code{Standard} for any of
17572the standard symbols defined by the Ada language. @value{GDBN} knows about
17573this: it will strip the prefix from names when you use it, and will never
17574look for a name you have so qualified among local symbols, nor match against
17575symbols in other packages or subprograms. If you have
17576defined entities anywhere in your program other than parameters and
17577local variables whose simple names match names in @code{Standard},
17578GNAT's lack of qualification here can cause confusion. When this happens,
17579you can usually resolve the confusion
17580by qualifying the problematic names with package
17581@code{Standard} explicitly.
17582@end itemize
17583
95433b34
JB
17584Older versions of the compiler sometimes generate erroneous debugging
17585information, resulting in the debugger incorrectly printing the value
17586of affected entities. In some cases, the debugger is able to work
17587around an issue automatically. In other cases, the debugger is able
17588to work around the issue, but the work-around has to be specifically
17589enabled.
17590
17591@kindex set ada trust-PAD-over-XVS
17592@kindex show ada trust-PAD-over-XVS
17593@table @code
17594
17595@item set ada trust-PAD-over-XVS on
17596Configure GDB to strictly follow the GNAT encoding when computing the
17597value of Ada entities, particularly when @code{PAD} and @code{PAD___XVS}
17598types are involved (see @code{ada/exp_dbug.ads} in the GCC sources for
17599a complete description of the encoding used by the GNAT compiler).
17600This is the default.
17601
17602@item set ada trust-PAD-over-XVS off
17603This is related to the encoding using by the GNAT compiler. If @value{GDBN}
17604sometimes prints the wrong value for certain entities, changing @code{ada
17605trust-PAD-over-XVS} to @code{off} activates a work-around which may fix
17606the issue. It is always safe to set @code{ada trust-PAD-over-XVS} to
17607@code{off}, but this incurs a slight performance penalty, so it is
17608recommended to leave this setting to @code{on} unless necessary.
17609
17610@end table
17611
c6044dd1
JB
17612@cindex GNAT descriptive types
17613@cindex GNAT encoding
17614Internally, the debugger also relies on the compiler following a number
17615of conventions known as the @samp{GNAT Encoding}, all documented in
17616@file{gcc/ada/exp_dbug.ads} in the GCC sources. This encoding describes
17617how the debugging information should be generated for certain types.
17618In particular, this convention makes use of @dfn{descriptive types},
17619which are artificial types generated purely to help the debugger.
17620
17621These encodings were defined at a time when the debugging information
17622format used was not powerful enough to describe some of the more complex
17623types available in Ada. Since DWARF allows us to express nearly all
17624Ada features, the long-term goal is to slowly replace these descriptive
17625types by their pure DWARF equivalent. To facilitate that transition,
17626a new maintenance option is available to force the debugger to ignore
17627those descriptive types. It allows the user to quickly evaluate how
17628well @value{GDBN} works without them.
17629
17630@table @code
17631
17632@kindex maint ada set ignore-descriptive-types
17633@item maintenance ada set ignore-descriptive-types [on|off]
17634Control whether the debugger should ignore descriptive types.
17635The default is not to ignore descriptives types (@code{off}).
17636
17637@kindex maint ada show ignore-descriptive-types
17638@item maintenance ada show ignore-descriptive-types
17639Show if descriptive types are ignored by @value{GDBN}.
17640
17641@end table
17642
79a6e687
BW
17643@node Unsupported Languages
17644@section Unsupported Languages
4e562065
JB
17645
17646@cindex unsupported languages
17647@cindex minimal language
17648In addition to the other fully-supported programming languages,
17649@value{GDBN} also provides a pseudo-language, called @code{minimal}.
17650It does not represent a real programming language, but provides a set
17651of capabilities close to what the C or assembly languages provide.
17652This should allow most simple operations to be performed while debugging
17653an application that uses a language currently not supported by @value{GDBN}.
17654
17655If the language is set to @code{auto}, @value{GDBN} will automatically
17656select this language if the current frame corresponds to an unsupported
17657language.
17658
6d2ebf8b 17659@node Symbols
c906108c
SS
17660@chapter Examining the Symbol Table
17661
d4f3574e 17662The commands described in this chapter allow you to inquire about the
c906108c
SS
17663symbols (names of variables, functions and types) defined in your
17664program. This information is inherent in the text of your program and
17665does not change as your program executes. @value{GDBN} finds it in your
17666program's symbol table, in the file indicated when you started @value{GDBN}
79a6e687
BW
17667(@pxref{File Options, ,Choosing Files}), or by one of the
17668file-management commands (@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
17669
17670@cindex symbol names
17671@cindex names of symbols
17672@cindex quoting names
d044bac8 17673@anchor{quoting names}
c906108c
SS
17674Occasionally, you may need to refer to symbols that contain unusual
17675characters, which @value{GDBN} ordinarily treats as word delimiters. The
17676most frequent case is in referring to static variables in other
79a6e687 17677source files (@pxref{Variables,,Program Variables}). File names
c906108c
SS
17678are recorded in object files as debugging symbols, but @value{GDBN} would
17679ordinarily parse a typical file name, like @file{foo.c}, as the three words
17680@samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
17681@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
17682
474c8240 17683@smallexample
c906108c 17684p 'foo.c'::x
474c8240 17685@end smallexample
c906108c
SS
17686
17687@noindent
17688looks up the value of @code{x} in the scope of the file @file{foo.c}.
17689
17690@table @code
a8f24a35
EZ
17691@cindex case-insensitive symbol names
17692@cindex case sensitivity in symbol names
17693@kindex set case-sensitive
17694@item set case-sensitive on
17695@itemx set case-sensitive off
17696@itemx set case-sensitive auto
17697Normally, when @value{GDBN} looks up symbols, it matches their names
17698with case sensitivity determined by the current source language.
17699Occasionally, you may wish to control that. The command @code{set
17700case-sensitive} lets you do that by specifying @code{on} for
17701case-sensitive matches or @code{off} for case-insensitive ones. If
17702you specify @code{auto}, case sensitivity is reset to the default
17703suitable for the source language. The default is case-sensitive
17704matches for all languages except for Fortran, for which the default is
17705case-insensitive matches.
17706
9c16f35a
EZ
17707@kindex show case-sensitive
17708@item show case-sensitive
a8f24a35
EZ
17709This command shows the current setting of case sensitivity for symbols
17710lookups.
17711
53342f27
TT
17712@kindex set print type methods
17713@item set print type methods
17714@itemx set print type methods on
17715@itemx set print type methods off
17716Normally, when @value{GDBN} prints a class, it displays any methods
17717declared in that class. You can control this behavior either by
17718passing the appropriate flag to @code{ptype}, or using @command{set
17719print type methods}. Specifying @code{on} will cause @value{GDBN} to
17720display the methods; this is the default. Specifying @code{off} will
17721cause @value{GDBN} to omit the methods.
17722
17723@kindex show print type methods
17724@item show print type methods
17725This command shows the current setting of method display when printing
17726classes.
17727
883fd55a
KS
17728@kindex set print type nested-type-limit
17729@item set print type nested-type-limit @var{limit}
17730@itemx set print type nested-type-limit unlimited
17731Set the limit of displayed nested types that the type printer will
17732show. A @var{limit} of @code{unlimited} or @code{-1} will show all
17733nested definitions. By default, the type printer will not show any nested
17734types defined in classes.
17735
17736@kindex show print type nested-type-limit
17737@item show print type nested-type-limit
17738This command shows the current display limit of nested types when
17739printing classes.
17740
53342f27
TT
17741@kindex set print type typedefs
17742@item set print type typedefs
17743@itemx set print type typedefs on
17744@itemx set print type typedefs off
17745
17746Normally, when @value{GDBN} prints a class, it displays any typedefs
17747defined in that class. You can control this behavior either by
17748passing the appropriate flag to @code{ptype}, or using @command{set
17749print type typedefs}. Specifying @code{on} will cause @value{GDBN} to
17750display the typedef definitions; this is the default. Specifying
17751@code{off} will cause @value{GDBN} to omit the typedef definitions.
17752Note that this controls whether the typedef definition itself is
17753printed, not whether typedef names are substituted when printing other
17754types.
17755
17756@kindex show print type typedefs
17757@item show print type typedefs
17758This command shows the current setting of typedef display when
17759printing classes.
17760
c906108c 17761@kindex info address
b37052ae 17762@cindex address of a symbol
c906108c
SS
17763@item info address @var{symbol}
17764Describe where the data for @var{symbol} is stored. For a register
17765variable, this says which register it is kept in. For a non-register
17766local variable, this prints the stack-frame offset at which the variable
17767is always stored.
17768
17769Note the contrast with @samp{print &@var{symbol}}, which does not work
17770at all for a register variable, and for a stack local variable prints
17771the exact address of the current instantiation of the variable.
17772
3d67e040 17773@kindex info symbol
b37052ae 17774@cindex symbol from address
9c16f35a 17775@cindex closest symbol and offset for an address
3d67e040
EZ
17776@item info symbol @var{addr}
17777Print the name of a symbol which is stored at the address @var{addr}.
17778If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
17779nearest symbol and an offset from it:
17780
474c8240 17781@smallexample
3d67e040
EZ
17782(@value{GDBP}) info symbol 0x54320
17783_initialize_vx + 396 in section .text
474c8240 17784@end smallexample
3d67e040
EZ
17785
17786@noindent
17787This is the opposite of the @code{info address} command. You can use
17788it to find out the name of a variable or a function given its address.
17789
c14c28ba
PP
17790For dynamically linked executables, the name of executable or shared
17791library containing the symbol is also printed:
17792
17793@smallexample
17794(@value{GDBP}) info symbol 0x400225
17795_start + 5 in section .text of /tmp/a.out
17796(@value{GDBP}) info symbol 0x2aaaac2811cf
17797__read_nocancel + 6 in section .text of /usr/lib64/libc.so.6
17798@end smallexample
17799
439250fb
DE
17800@kindex demangle
17801@cindex demangle
17802@item demangle @r{[}-l @var{language}@r{]} @r{[}@var{--}@r{]} @var{name}
17803Demangle @var{name}.
17804If @var{language} is provided it is the name of the language to demangle
17805@var{name} in. Otherwise @var{name} is demangled in the current language.
17806
17807The @samp{--} option specifies the end of options,
17808and is useful when @var{name} begins with a dash.
17809
17810The parameter @code{demangle-style} specifies how to interpret the kind
17811of mangling used. @xref{Print Settings}.
17812
c906108c 17813@kindex whatis
53342f27 17814@item whatis[/@var{flags}] [@var{arg}]
177bc839
JK
17815Print the data type of @var{arg}, which can be either an expression
17816or a name of a data type. With no argument, print the data type of
17817@code{$}, the last value in the value history.
17818
17819If @var{arg} is an expression (@pxref{Expressions, ,Expressions}), it
17820is not actually evaluated, and any side-effecting operations (such as
17821assignments or function calls) inside it do not take place.
17822
17823If @var{arg} is a variable or an expression, @code{whatis} prints its
17824literal type as it is used in the source code. If the type was
17825defined using a @code{typedef}, @code{whatis} will @emph{not} print
17826the data type underlying the @code{typedef}. If the type of the
17827variable or the expression is a compound data type, such as
17828@code{struct} or @code{class}, @code{whatis} never prints their
17829fields or methods. It just prints the @code{struct}/@code{class}
17830name (a.k.a.@: its @dfn{tag}). If you want to see the members of
17831such a compound data type, use @code{ptype}.
17832
17833If @var{arg} is a type name that was defined using @code{typedef},
17834@code{whatis} @dfn{unrolls} only one level of that @code{typedef}.
17835Unrolling means that @code{whatis} will show the underlying type used
17836in the @code{typedef} declaration of @var{arg}. However, if that
17837underlying type is also a @code{typedef}, @code{whatis} will not
17838unroll it.
17839
17840For C code, the type names may also have the form @samp{class
17841@var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
17842@var{union-tag}} or @samp{enum @var{enum-tag}}.
c906108c 17843
53342f27
TT
17844@var{flags} can be used to modify how the type is displayed.
17845Available flags are:
17846
17847@table @code
17848@item r
17849Display in ``raw'' form. Normally, @value{GDBN} substitutes template
17850parameters and typedefs defined in a class when printing the class'
17851members. The @code{/r} flag disables this.
17852
17853@item m
17854Do not print methods defined in the class.
17855
17856@item M
17857Print methods defined in the class. This is the default, but the flag
17858exists in case you change the default with @command{set print type methods}.
17859
17860@item t
17861Do not print typedefs defined in the class. Note that this controls
17862whether the typedef definition itself is printed, not whether typedef
17863names are substituted when printing other types.
17864
17865@item T
17866Print typedefs defined in the class. This is the default, but the flag
17867exists in case you change the default with @command{set print type typedefs}.
7c161838
SDJ
17868
17869@item o
17870Print the offsets and sizes of fields in a struct, similar to what the
17871@command{pahole} tool does. This option implies the @code{/tm} flags.
17872
17873For example, given the following declarations:
17874
17875@smallexample
17876struct tuv
17877@{
17878 int a1;
17879 char *a2;
17880 int a3;
17881@};
17882
17883struct xyz
17884@{
17885 int f1;
17886 char f2;
17887 void *f3;
17888 struct tuv f4;
17889@};
17890
17891union qwe
17892@{
17893 struct tuv fff1;
17894 struct xyz fff2;
17895@};
17896
17897struct tyu
17898@{
17899 int a1 : 1;
17900 int a2 : 3;
17901 int a3 : 23;
17902 char a4 : 2;
17903 int64_t a5;
17904 int a6 : 5;
17905 int64_t a7 : 3;
17906@};
17907@end smallexample
17908
17909Issuing a @kbd{ptype /o struct tuv} command would print:
17910
17911@smallexample
17912(@value{GDBP}) ptype /o struct tuv
17913/* offset | size */ type = struct tuv @{
17914/* 0 | 4 */ int a1;
17915/* XXX 4-byte hole */
17916/* 8 | 8 */ char *a2;
17917/* 16 | 4 */ int a3;
17918
17919 /* total size (bytes): 24 */
17920 @}
17921@end smallexample
17922
17923Notice the format of the first column of comments. There, you can
17924find two parts separated by the @samp{|} character: the @emph{offset},
17925which indicates where the field is located inside the struct, in
17926bytes, and the @emph{size} of the field. Another interesting line is
17927the marker of a @emph{hole} in the struct, indicating that it may be
17928possible to pack the struct and make it use less space by reorganizing
17929its fields.
17930
17931It is also possible to print offsets inside an union:
17932
17933@smallexample
17934(@value{GDBP}) ptype /o union qwe
17935/* offset | size */ type = union qwe @{
17936/* 24 */ struct tuv @{
17937/* 0 | 4 */ int a1;
17938/* XXX 4-byte hole */
17939/* 8 | 8 */ char *a2;
17940/* 16 | 4 */ int a3;
17941
17942 /* total size (bytes): 24 */
17943 @} fff1;
17944/* 40 */ struct xyz @{
17945/* 0 | 4 */ int f1;
17946/* 4 | 1 */ char f2;
17947/* XXX 3-byte hole */
17948/* 8 | 8 */ void *f3;
17949/* 16 | 24 */ struct tuv @{
17950/* 16 | 4 */ int a1;
17951/* XXX 4-byte hole */
17952/* 24 | 8 */ char *a2;
17953/* 32 | 4 */ int a3;
17954
17955 /* total size (bytes): 24 */
17956 @} f4;
17957
17958 /* total size (bytes): 40 */
17959 @} fff2;
17960
17961 /* total size (bytes): 40 */
17962 @}
17963@end smallexample
17964
17965In this case, since @code{struct tuv} and @code{struct xyz} occupy the
17966same space (because we are dealing with an union), the offset is not
17967printed for them. However, you can still examine the offset of each
17968of these structures' fields.
17969
17970Another useful scenario is printing the offsets of a struct containing
17971bitfields:
17972
17973@smallexample
17974(@value{GDBP}) ptype /o struct tyu
17975/* offset | size */ type = struct tyu @{
17976/* 0:31 | 4 */ int a1 : 1;
17977/* 0:28 | 4 */ int a2 : 3;
17978/* 0: 5 | 4 */ int a3 : 23;
17979/* 3: 3 | 1 */ signed char a4 : 2;
17980/* XXX 3-bit hole */
17981/* XXX 4-byte hole */
17982/* 8 | 8 */ int64_t a5;
9d3421af
TT
17983/* 16: 0 | 4 */ int a6 : 5;
17984/* 16: 5 | 8 */ int64_t a7 : 3;
17985"/* XXX 7-byte padding */
7c161838
SDJ
17986
17987 /* total size (bytes): 24 */
17988 @}
17989@end smallexample
17990
9d3421af
TT
17991Note how the offset information is now extended to also include the
17992first bit of the bitfield.
53342f27
TT
17993@end table
17994
c906108c 17995@kindex ptype
53342f27 17996@item ptype[/@var{flags}] [@var{arg}]
62f3a2ba
FF
17997@code{ptype} accepts the same arguments as @code{whatis}, but prints a
17998detailed description of the type, instead of just the name of the type.
17999@xref{Expressions, ,Expressions}.
c906108c 18000
177bc839
JK
18001Contrary to @code{whatis}, @code{ptype} always unrolls any
18002@code{typedef}s in its argument declaration, whether the argument is
18003a variable, expression, or a data type. This means that @code{ptype}
18004of a variable or an expression will not print literally its type as
18005present in the source code---use @code{whatis} for that. @code{typedef}s at
18006the pointer or reference targets are also unrolled. Only @code{typedef}s of
18007fields, methods and inner @code{class typedef}s of @code{struct}s,
18008@code{class}es and @code{union}s are not unrolled even with @code{ptype}.
18009
c906108c
SS
18010For example, for this variable declaration:
18011
474c8240 18012@smallexample
177bc839
JK
18013typedef double real_t;
18014struct complex @{ real_t real; double imag; @};
18015typedef struct complex complex_t;
18016complex_t var;
18017real_t *real_pointer_var;
474c8240 18018@end smallexample
c906108c
SS
18019
18020@noindent
18021the two commands give this output:
18022
474c8240 18023@smallexample
c906108c 18024@group
177bc839
JK
18025(@value{GDBP}) whatis var
18026type = complex_t
18027(@value{GDBP}) ptype var
18028type = struct complex @{
18029 real_t real;
18030 double imag;
18031@}
18032(@value{GDBP}) whatis complex_t
18033type = struct complex
18034(@value{GDBP}) whatis struct complex
c906108c 18035type = struct complex
177bc839 18036(@value{GDBP}) ptype struct complex
c906108c 18037type = struct complex @{
177bc839 18038 real_t real;
c906108c
SS
18039 double imag;
18040@}
177bc839
JK
18041(@value{GDBP}) whatis real_pointer_var
18042type = real_t *
18043(@value{GDBP}) ptype real_pointer_var
18044type = double *
c906108c 18045@end group
474c8240 18046@end smallexample
c906108c
SS
18047
18048@noindent
18049As with @code{whatis}, using @code{ptype} without an argument refers to
18050the type of @code{$}, the last value in the value history.
18051
ab1adacd
EZ
18052@cindex incomplete type
18053Sometimes, programs use opaque data types or incomplete specifications
18054of complex data structure. If the debug information included in the
18055program does not allow @value{GDBN} to display a full declaration of
18056the data type, it will say @samp{<incomplete type>}. For example,
18057given these declarations:
18058
18059@smallexample
18060 struct foo;
18061 struct foo *fooptr;
18062@end smallexample
18063
18064@noindent
18065but no definition for @code{struct foo} itself, @value{GDBN} will say:
18066
18067@smallexample
ddb50cd7 18068 (@value{GDBP}) ptype foo
ab1adacd
EZ
18069 $1 = <incomplete type>
18070@end smallexample
18071
18072@noindent
18073``Incomplete type'' is C terminology for data types that are not
18074completely specified.
18075
d69cf9b2
PA
18076@cindex unknown type
18077Othertimes, information about a variable's type is completely absent
18078from the debug information included in the program. This most often
18079happens when the program or library where the variable is defined
18080includes no debug information at all. @value{GDBN} knows the variable
18081exists from inspecting the linker/loader symbol table (e.g., the ELF
18082dynamic symbol table), but such symbols do not contain type
18083information. Inspecting the type of a (global) variable for which
18084@value{GDBN} has no type information shows:
18085
18086@smallexample
18087 (@value{GDBP}) ptype var
18088 type = <data variable, no debug info>
18089@end smallexample
18090
18091@xref{Variables, no debug info variables}, for how to print the values
18092of such variables.
18093
c906108c
SS
18094@kindex info types
18095@item info types @var{regexp}
18096@itemx info types
09d4efe1
EZ
18097Print a brief description of all types whose names match the regular
18098expression @var{regexp} (or all types in your program, if you supply
18099no argument). Each complete typename is matched as though it were a
18100complete line; thus, @samp{i type value} gives information on all
18101types in your program whose names include the string @code{value}, but
18102@samp{i type ^value$} gives information only on types whose complete
18103name is @code{value}.
c906108c 18104
20813a0b
PW
18105In programs using different languages, @value{GDBN} chooses the syntax
18106to print the type description according to the
18107@samp{set language} value: using @samp{set language auto}
18108(see @ref{Automatically, ,Set Language Automatically}) means to use the
18109language of the type, other values mean to use
18110the manually specified language (see @ref{Manually, ,Set Language Manually}).
18111
c906108c
SS
18112This command differs from @code{ptype} in two ways: first, like
18113@code{whatis}, it does not print a detailed description; second, it
b744723f 18114lists all source files and line numbers where a type is defined.
c906108c 18115
18a9fc12
TT
18116@kindex info type-printers
18117@item info type-printers
18118Versions of @value{GDBN} that ship with Python scripting enabled may
18119have ``type printers'' available. When using @command{ptype} or
18120@command{whatis}, these printers are consulted when the name of a type
18121is needed. @xref{Type Printing API}, for more information on writing
18122type printers.
18123
18124@code{info type-printers} displays all the available type printers.
18125
18126@kindex enable type-printer
18127@kindex disable type-printer
18128@item enable type-printer @var{name}@dots{}
18129@item disable type-printer @var{name}@dots{}
18130These commands can be used to enable or disable type printers.
18131
b37052ae
EZ
18132@kindex info scope
18133@cindex local variables
09d4efe1 18134@item info scope @var{location}
b37052ae 18135List all the variables local to a particular scope. This command
09d4efe1
EZ
18136accepts a @var{location} argument---a function name, a source line, or
18137an address preceded by a @samp{*}, and prints all the variables local
2a25a5ba
EZ
18138to the scope defined by that location. (@xref{Specify Location}, for
18139details about supported forms of @var{location}.) For example:
b37052ae
EZ
18140
18141@smallexample
18142(@value{GDBP}) @b{info scope command_line_handler}
18143Scope for command_line_handler:
18144Symbol rl is an argument at stack/frame offset 8, length 4.
18145Symbol linebuffer is in static storage at address 0x150a18, length 4.
18146Symbol linelength is in static storage at address 0x150a1c, length 4.
18147Symbol p is a local variable in register $esi, length 4.
18148Symbol p1 is a local variable in register $ebx, length 4.
18149Symbol nline is a local variable in register $edx, length 4.
18150Symbol repeat is a local variable at frame offset -8, length 4.
18151@end smallexample
18152
f5c37c66
EZ
18153@noindent
18154This command is especially useful for determining what data to collect
18155during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
18156collect}.
18157
c906108c
SS
18158@kindex info source
18159@item info source
919d772c
JB
18160Show information about the current source file---that is, the source file for
18161the function containing the current point of execution:
18162@itemize @bullet
18163@item
18164the name of the source file, and the directory containing it,
18165@item
18166the directory it was compiled in,
18167@item
18168its length, in lines,
18169@item
18170which programming language it is written in,
18171@item
b6577aab
DE
18172if the debug information provides it, the program that compiled the file
18173(which may include, e.g., the compiler version and command line arguments),
18174@item
919d772c
JB
18175whether the executable includes debugging information for that file, and
18176if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
18177@item
18178whether the debugging information includes information about
18179preprocessor macros.
18180@end itemize
18181
c906108c
SS
18182
18183@kindex info sources
18184@item info sources
18185Print the names of all source files in your program for which there is
18186debugging information, organized into two lists: files whose symbols
18187have already been read, and files whose symbols will be read when needed.
18188
18189@kindex info functions
d321477b 18190@item info functions [-q]
c906108c 18191Print the names and data types of all defined functions.
b744723f
AA
18192Similarly to @samp{info types}, this command groups its output by source
18193files and annotates each function definition with its source line
18194number.
c906108c 18195
20813a0b
PW
18196In programs using different languages, @value{GDBN} chooses the syntax
18197to print the function name and type according to the
18198@samp{set language} value: using @samp{set language auto}
18199(see @ref{Automatically, ,Set Language Automatically}) means to use the
18200language of the function, other values mean to use
18201the manually specified language (see @ref{Manually, ,Set Language Manually}).
18202
d321477b
PW
18203The optional flag @samp{-q}, which stands for @samp{quiet}, disables
18204printing header information and messages explaining why no functions
18205have been printed.
18206
18207@item info functions [-q] [-t @var{type_regexp}] [@var{regexp}]
18208Like @samp{info functions}, but only print the names and data types
18209of the functions selected with the provided regexp(s).
18210
18211If @var{regexp} is provided, print only the functions whose names
18212match the regular expression @var{regexp}.
18213Thus, @samp{info fun step} finds all functions whose
b744723f
AA
18214names include @code{step}; @samp{info fun ^step} finds those whose names
18215start with @code{step}. If a function name contains characters that
18216conflict with the regular expression language (e.g.@:
1c5dfdad 18217@samp{operator*()}), they may be quoted with a backslash.
c906108c 18218
d321477b
PW
18219If @var{type_regexp} is provided, print only the functions whose
18220types, as printed by the @code{whatis} command, match
18221the regular expression @var{type_regexp}.
18222If @var{type_regexp} contains space(s), it should be enclosed in
18223quote characters. If needed, use backslash to escape the meaning
18224of special characters or quotes.
18225Thus, @samp{info fun -t '^int ('} finds the functions that return
18226an integer; @samp{info fun -t '(.*int.*'} finds the functions that
18227have an argument type containing int; @samp{info fun -t '^int (' ^step}
18228finds the functions whose names start with @code{step} and that return
18229int.
18230
18231If both @var{regexp} and @var{type_regexp} are provided, a function
18232is printed only if its name matches @var{regexp} and its type matches
18233@var{type_regexp}.
18234
18235
c906108c 18236@kindex info variables
d321477b 18237@item info variables [-q]
0fe7935b 18238Print the names and data types of all variables that are defined
6ca652b0 18239outside of functions (i.e.@: excluding local variables).
b744723f
AA
18240The printed variables are grouped by source files and annotated with
18241their respective source line numbers.
c906108c 18242
20813a0b
PW
18243In programs using different languages, @value{GDBN} chooses the syntax
18244to print the variable name and type according to the
18245@samp{set language} value: using @samp{set language auto}
18246(see @ref{Automatically, ,Set Language Automatically}) means to use the
18247language of the variable, other values mean to use
18248the manually specified language (see @ref{Manually, ,Set Language Manually}).
18249
d321477b
PW
18250The optional flag @samp{-q}, which stands for @samp{quiet}, disables
18251printing header information and messages explaining why no variables
18252have been printed.
18253
18254@item info variables [-q] [-t @var{type_regexp}] [@var{regexp}]
18255Like @kbd{info variables}, but only print the variables selected
18256with the provided regexp(s).
18257
18258If @var{regexp} is provided, print only the variables whose names
18259match the regular expression @var{regexp}.
18260
18261If @var{type_regexp} is provided, print only the variables whose
18262types, as printed by the @code{whatis} command, match
18263the regular expression @var{type_regexp}.
18264If @var{type_regexp} contains space(s), it should be enclosed in
18265quote characters. If needed, use backslash to escape the meaning
18266of special characters or quotes.
18267
18268If both @var{regexp} and @var{type_regexp} are provided, an argument
18269is printed only if its name matches @var{regexp} and its type matches
18270@var{type_regexp}.
c906108c 18271
b37303ee 18272@kindex info classes
721c2651 18273@cindex Objective-C, classes and selectors
b37303ee
AF
18274@item info classes
18275@itemx info classes @var{regexp}
18276Display all Objective-C classes in your program, or
18277(with the @var{regexp} argument) all those matching a particular regular
18278expression.
18279
18280@kindex info selectors
18281@item info selectors
18282@itemx info selectors @var{regexp}
18283Display all Objective-C selectors in your program, or
18284(with the @var{regexp} argument) all those matching a particular regular
18285expression.
18286
c906108c
SS
18287@ignore
18288This was never implemented.
18289@kindex info methods
18290@item info methods
18291@itemx info methods @var{regexp}
18292The @code{info methods} command permits the user to examine all defined
b37052ae
EZ
18293methods within C@t{++} program, or (with the @var{regexp} argument) a
18294specific set of methods found in the various C@t{++} classes. Many
18295C@t{++} classes provide a large number of methods. Thus, the output
c906108c
SS
18296from the @code{ptype} command can be overwhelming and hard to use. The
18297@code{info-methods} command filters the methods, printing only those
18298which match the regular-expression @var{regexp}.
18299@end ignore
18300
9c16f35a 18301@cindex opaque data types
c906108c
SS
18302@kindex set opaque-type-resolution
18303@item set opaque-type-resolution on
18304Tell @value{GDBN} to resolve opaque types. An opaque type is a type
18305declared as a pointer to a @code{struct}, @code{class}, or
18306@code{union}---for example, @code{struct MyType *}---that is used in one
18307source file although the full declaration of @code{struct MyType} is in
18308another source file. The default is on.
18309
18310A change in the setting of this subcommand will not take effect until
18311the next time symbols for a file are loaded.
18312
18313@item set opaque-type-resolution off
18314Tell @value{GDBN} not to resolve opaque types. In this case, the type
18315is printed as follows:
18316@smallexample
18317@{<no data fields>@}
18318@end smallexample
18319
18320@kindex show opaque-type-resolution
18321@item show opaque-type-resolution
18322Show whether opaque types are resolved or not.
c906108c 18323
770e7fc7
DE
18324@kindex set print symbol-loading
18325@cindex print messages when symbols are loaded
18326@item set print symbol-loading
18327@itemx set print symbol-loading full
18328@itemx set print symbol-loading brief
18329@itemx set print symbol-loading off
18330The @code{set print symbol-loading} command allows you to control the
18331printing of messages when @value{GDBN} loads symbol information.
18332By default a message is printed for the executable and one for each
18333shared library, and normally this is what you want. However, when
18334debugging apps with large numbers of shared libraries these messages
18335can be annoying.
18336When set to @code{brief} a message is printed for each executable,
18337and when @value{GDBN} loads a collection of shared libraries at once
18338it will only print one message regardless of the number of shared
18339libraries. When set to @code{off} no messages are printed.
18340
18341@kindex show print symbol-loading
18342@item show print symbol-loading
18343Show whether messages will be printed when a @value{GDBN} command
18344entered from the keyboard causes symbol information to be loaded.
18345
c906108c
SS
18346@kindex maint print symbols
18347@cindex symbol dump
18348@kindex maint print psymbols
18349@cindex partial symbol dump
7c57fa1e
YQ
18350@kindex maint print msymbols
18351@cindex minimal symbol dump
34c41c68
DE
18352@item maint print symbols @r{[}-pc @var{address}@r{]} @r{[}@var{filename}@r{]}
18353@itemx maint print symbols @r{[}-objfile @var{objfile}@r{]} @r{[}-source @var{source}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
18354@itemx maint print psymbols @r{[}-objfile @var{objfile}@r{]} @r{[}-pc @var{address}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
18355@itemx maint print psymbols @r{[}-objfile @var{objfile}@r{]} @r{[}-source @var{source}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
18356@itemx maint print msymbols @r{[}-objfile @var{objfile}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
18357Write a dump of debugging symbol data into the file @var{filename} or
18358the terminal if @var{filename} is unspecified.
18359If @code{-objfile @var{objfile}} is specified, only dump symbols for
18360that objfile.
18361If @code{-pc @var{address}} is specified, only dump symbols for the file
18362with code at that address. Note that @var{address} may be a symbol like
18363@code{main}.
18364If @code{-source @var{source}} is specified, only dump symbols for that
18365source file.
18366
18367These commands are used to debug the @value{GDBN} symbol-reading code.
18368These commands do not modify internal @value{GDBN} state, therefore
18369@samp{maint print symbols} will only print symbols for already expanded symbol
18370tables.
18371You can use the command @code{info sources} to find out which files these are.
18372If you use @samp{maint print psymbols} instead, the dump shows information
18373about symbols that @value{GDBN} only knows partially---that is, symbols
18374defined in files that @value{GDBN} has skimmed, but not yet read completely.
18375Finally, @samp{maint print msymbols} just dumps ``minimal symbols'', e.g.,
18376``ELF symbols''.
18377
79a6e687 18378@xref{Files, ,Commands to Specify Files}, for a discussion of how
c906108c 18379@value{GDBN} reads symbols (in the description of @code{symbol-file}).
44ea7b70 18380
5e7b2f39
JB
18381@kindex maint info symtabs
18382@kindex maint info psymtabs
44ea7b70
JB
18383@cindex listing @value{GDBN}'s internal symbol tables
18384@cindex symbol tables, listing @value{GDBN}'s internal
18385@cindex full symbol tables, listing @value{GDBN}'s internal
18386@cindex partial symbol tables, listing @value{GDBN}'s internal
5e7b2f39
JB
18387@item maint info symtabs @r{[} @var{regexp} @r{]}
18388@itemx maint info psymtabs @r{[} @var{regexp} @r{]}
44ea7b70
JB
18389
18390List the @code{struct symtab} or @code{struct partial_symtab}
18391structures whose names match @var{regexp}. If @var{regexp} is not
18392given, list them all. The output includes expressions which you can
18393copy into a @value{GDBN} debugging this one to examine a particular
18394structure in more detail. For example:
18395
18396@smallexample
5e7b2f39 18397(@value{GDBP}) maint info psymtabs dwarf2read
44ea7b70
JB
18398@{ objfile /home/gnu/build/gdb/gdb
18399 ((struct objfile *) 0x82e69d0)
b383017d 18400 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
18401 ((struct partial_symtab *) 0x8474b10)
18402 readin no
18403 fullname (null)
18404 text addresses 0x814d3c8 -- 0x8158074
18405 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
18406 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
18407 dependencies (none)
18408 @}
18409@}
5e7b2f39 18410(@value{GDBP}) maint info symtabs
44ea7b70
JB
18411(@value{GDBP})
18412@end smallexample
18413@noindent
18414We see that there is one partial symbol table whose filename contains
18415the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
18416and we see that @value{GDBN} has not read in any symtabs yet at all.
18417If we set a breakpoint on a function, that will cause @value{GDBN} to
18418read the symtab for the compilation unit containing that function:
18419
18420@smallexample
18421(@value{GDBP}) break dwarf2_psymtab_to_symtab
18422Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
18423line 1574.
5e7b2f39 18424(@value{GDBP}) maint info symtabs
b383017d 18425@{ objfile /home/gnu/build/gdb/gdb
44ea7b70 18426 ((struct objfile *) 0x82e69d0)
b383017d 18427 @{ symtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
18428 ((struct symtab *) 0x86c1f38)
18429 dirname (null)
18430 fullname (null)
18431 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
1b39d5c0 18432 linetable ((struct linetable *) 0x8370fa0)
44ea7b70
JB
18433 debugformat DWARF 2
18434 @}
18435@}
b383017d 18436(@value{GDBP})
44ea7b70 18437@end smallexample
44ea7b70 18438
f2403c39
AB
18439@kindex maint info line-table
18440@cindex listing @value{GDBN}'s internal line tables
18441@cindex line tables, listing @value{GDBN}'s internal
18442@item maint info line-table @r{[} @var{regexp} @r{]}
18443
18444List the @code{struct linetable} from all @code{struct symtab}
18445instances whose name matches @var{regexp}. If @var{regexp} is not
18446given, list the @code{struct linetable} from all @code{struct symtab}.
18447
f57d2163
DE
18448@kindex maint set symbol-cache-size
18449@cindex symbol cache size
18450@item maint set symbol-cache-size @var{size}
18451Set the size of the symbol cache to @var{size}.
18452The default size is intended to be good enough for debugging
18453most applications. This option exists to allow for experimenting
18454with different sizes.
18455
18456@kindex maint show symbol-cache-size
18457@item maint show symbol-cache-size
18458Show the size of the symbol cache.
18459
18460@kindex maint print symbol-cache
18461@cindex symbol cache, printing its contents
18462@item maint print symbol-cache
18463Print the contents of the symbol cache.
18464This is useful when debugging symbol cache issues.
18465
18466@kindex maint print symbol-cache-statistics
18467@cindex symbol cache, printing usage statistics
18468@item maint print symbol-cache-statistics
18469Print symbol cache usage statistics.
18470This helps determine how well the cache is being utilized.
18471
18472@kindex maint flush-symbol-cache
18473@cindex symbol cache, flushing
18474@item maint flush-symbol-cache
18475Flush the contents of the symbol cache, all entries are removed.
18476This command is useful when debugging the symbol cache.
18477It is also useful when collecting performance data.
18478
18479@end table
6a3ca067 18480
6d2ebf8b 18481@node Altering
c906108c
SS
18482@chapter Altering Execution
18483
18484Once you think you have found an error in your program, you might want to
18485find out for certain whether correcting the apparent error would lead to
18486correct results in the rest of the run. You can find the answer by
18487experiment, using the @value{GDBN} features for altering execution of the
18488program.
18489
18490For example, you can store new values into variables or memory
7a292a7a
SS
18491locations, give your program a signal, restart it at a different
18492address, or even return prematurely from a function.
c906108c
SS
18493
18494@menu
18495* Assignment:: Assignment to variables
18496* Jumping:: Continuing at a different address
c906108c 18497* Signaling:: Giving your program a signal
c906108c
SS
18498* Returning:: Returning from a function
18499* Calling:: Calling your program's functions
18500* Patching:: Patching your program
bb2ec1b3 18501* Compiling and Injecting Code:: Compiling and injecting code in @value{GDBN}
c906108c
SS
18502@end menu
18503
6d2ebf8b 18504@node Assignment
79a6e687 18505@section Assignment to Variables
c906108c
SS
18506
18507@cindex assignment
18508@cindex setting variables
18509To alter the value of a variable, evaluate an assignment expression.
18510@xref{Expressions, ,Expressions}. For example,
18511
474c8240 18512@smallexample
c906108c 18513print x=4
474c8240 18514@end smallexample
c906108c
SS
18515
18516@noindent
18517stores the value 4 into the variable @code{x}, and then prints the
5d161b24 18518value of the assignment expression (which is 4).
c906108c
SS
18519@xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
18520information on operators in supported languages.
c906108c
SS
18521
18522@kindex set variable
18523@cindex variables, setting
18524If you are not interested in seeing the value of the assignment, use the
18525@code{set} command instead of the @code{print} command. @code{set} is
18526really the same as @code{print} except that the expression's value is
18527not printed and is not put in the value history (@pxref{Value History,
79a6e687 18528,Value History}). The expression is evaluated only for its effects.
c906108c 18529
c906108c
SS
18530If the beginning of the argument string of the @code{set} command
18531appears identical to a @code{set} subcommand, use the @code{set
18532variable} command instead of just @code{set}. This command is identical
18533to @code{set} except for its lack of subcommands. For example, if your
18534program has a variable @code{width}, you get an error if you try to set
18535a new value with just @samp{set width=13}, because @value{GDBN} has the
18536command @code{set width}:
18537
474c8240 18538@smallexample
c906108c
SS
18539(@value{GDBP}) whatis width
18540type = double
18541(@value{GDBP}) p width
18542$4 = 13
18543(@value{GDBP}) set width=47
18544Invalid syntax in expression.
474c8240 18545@end smallexample
c906108c
SS
18546
18547@noindent
18548The invalid expression, of course, is @samp{=47}. In
18549order to actually set the program's variable @code{width}, use
18550
474c8240 18551@smallexample
c906108c 18552(@value{GDBP}) set var width=47
474c8240 18553@end smallexample
53a5351d 18554
c906108c
SS
18555Because the @code{set} command has many subcommands that can conflict
18556with the names of program variables, it is a good idea to use the
18557@code{set variable} command instead of just @code{set}. For example, if
18558your program has a variable @code{g}, you run into problems if you try
18559to set a new value with just @samp{set g=4}, because @value{GDBN} has
18560the command @code{set gnutarget}, abbreviated @code{set g}:
18561
474c8240 18562@smallexample
c906108c
SS
18563@group
18564(@value{GDBP}) whatis g
18565type = double
18566(@value{GDBP}) p g
18567$1 = 1
18568(@value{GDBP}) set g=4
2df3850c 18569(@value{GDBP}) p g
c906108c
SS
18570$2 = 1
18571(@value{GDBP}) r
18572The program being debugged has been started already.
18573Start it from the beginning? (y or n) y
18574Starting program: /home/smith/cc_progs/a.out
6d2ebf8b
SS
18575"/home/smith/cc_progs/a.out": can't open to read symbols:
18576 Invalid bfd target.
c906108c
SS
18577(@value{GDBP}) show g
18578The current BFD target is "=4".
18579@end group
474c8240 18580@end smallexample
c906108c
SS
18581
18582@noindent
18583The program variable @code{g} did not change, and you silently set the
18584@code{gnutarget} to an invalid value. In order to set the variable
18585@code{g}, use
18586
474c8240 18587@smallexample
c906108c 18588(@value{GDBP}) set var g=4
474c8240 18589@end smallexample
c906108c
SS
18590
18591@value{GDBN} allows more implicit conversions in assignments than C; you can
18592freely store an integer value into a pointer variable or vice versa,
18593and you can convert any structure to any other structure that is the
18594same length or shorter.
18595@comment FIXME: how do structs align/pad in these conversions?
18596@comment /doc@cygnus.com 18dec1990
18597
18598To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
18599construct to generate a value of specified type at a specified address
18600(@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
18601to memory location @code{0x83040} as an integer (which implies a certain size
18602and representation in memory), and
18603
474c8240 18604@smallexample
c906108c 18605set @{int@}0x83040 = 4
474c8240 18606@end smallexample
c906108c
SS
18607
18608@noindent
18609stores the value 4 into that memory location.
18610
6d2ebf8b 18611@node Jumping
79a6e687 18612@section Continuing at a Different Address
c906108c
SS
18613
18614Ordinarily, when you continue your program, you do so at the place where
18615it stopped, with the @code{continue} command. You can instead continue at
18616an address of your own choosing, with the following commands:
18617
18618@table @code
18619@kindex jump
c1d780c2 18620@kindex j @r{(@code{jump})}
629500fa 18621@item jump @var{location}
c1d780c2 18622@itemx j @var{location}
629500fa
KS
18623Resume execution at @var{location}. Execution stops again immediately
18624if there is a breakpoint there. @xref{Specify Location}, for a description
18625of the different forms of @var{location}. It is common
2a25a5ba
EZ
18626practice to use the @code{tbreak} command in conjunction with
18627@code{jump}. @xref{Set Breaks, ,Setting Breakpoints}.
c906108c
SS
18628
18629The @code{jump} command does not change the current stack frame, or
18630the stack pointer, or the contents of any memory location or any
629500fa 18631register other than the program counter. If @var{location} is in
c906108c
SS
18632a different function from the one currently executing, the results may
18633be bizarre if the two functions expect different patterns of arguments or
18634of local variables. For this reason, the @code{jump} command requests
18635confirmation if the specified line is not in the function currently
18636executing. However, even bizarre results are predictable if you are
18637well acquainted with the machine-language code of your program.
c906108c
SS
18638@end table
18639
53a5351d
JM
18640On many systems, you can get much the same effect as the @code{jump}
18641command by storing a new value into the register @code{$pc}. The
18642difference is that this does not start your program running; it only
18643changes the address of where it @emph{will} run when you continue. For
18644example,
c906108c 18645
474c8240 18646@smallexample
c906108c 18647set $pc = 0x485
474c8240 18648@end smallexample
c906108c
SS
18649
18650@noindent
18651makes the next @code{continue} command or stepping command execute at
18652address @code{0x485}, rather than at the address where your program stopped.
79a6e687 18653@xref{Continuing and Stepping, ,Continuing and Stepping}.
c906108c
SS
18654
18655The most common occasion to use the @code{jump} command is to back
18656up---perhaps with more breakpoints set---over a portion of a program
18657that has already executed, in order to examine its execution in more
18658detail.
18659
c906108c 18660@c @group
6d2ebf8b 18661@node Signaling
79a6e687 18662@section Giving your Program a Signal
9c16f35a 18663@cindex deliver a signal to a program
c906108c
SS
18664
18665@table @code
18666@kindex signal
18667@item signal @var{signal}
70509625 18668Resume execution where your program is stopped, but immediately give it the
697aa1b7 18669signal @var{signal}. The @var{signal} can be the name or the number of a
c906108c
SS
18670signal. For example, on many systems @code{signal 2} and @code{signal
18671SIGINT} are both ways of sending an interrupt signal.
18672
18673Alternatively, if @var{signal} is zero, continue execution without
18674giving a signal. This is useful when your program stopped on account of
ae606bee 18675a signal and would ordinarily see the signal when resumed with the
c906108c
SS
18676@code{continue} command; @samp{signal 0} causes it to resume without a
18677signal.
18678
70509625
PA
18679@emph{Note:} When resuming a multi-threaded program, @var{signal} is
18680delivered to the currently selected thread, not the thread that last
18681reported a stop. This includes the situation where a thread was
18682stopped due to a signal. So if you want to continue execution
18683suppressing the signal that stopped a thread, you should select that
18684same thread before issuing the @samp{signal 0} command. If you issue
18685the @samp{signal 0} command with another thread as the selected one,
18686@value{GDBN} detects that and asks for confirmation.
18687
c906108c
SS
18688Invoking the @code{signal} command is not the same as invoking the
18689@code{kill} utility from the shell. Sending a signal with @code{kill}
18690causes @value{GDBN} to decide what to do with the signal depending on
18691the signal handling tables (@pxref{Signals}). The @code{signal} command
18692passes the signal directly to your program.
18693
81219e53
DE
18694@code{signal} does not repeat when you press @key{RET} a second time
18695after executing the command.
18696
18697@kindex queue-signal
18698@item queue-signal @var{signal}
18699Queue @var{signal} to be delivered immediately to the current thread
18700when execution of the thread resumes. The @var{signal} can be the name or
18701the number of a signal. For example, on many systems @code{signal 2} and
18702@code{signal SIGINT} are both ways of sending an interrupt signal.
18703The handling of the signal must be set to pass the signal to the program,
18704otherwise @value{GDBN} will report an error.
18705You can control the handling of signals from @value{GDBN} with the
18706@code{handle} command (@pxref{Signals}).
18707
18708Alternatively, if @var{signal} is zero, any currently queued signal
18709for the current thread is discarded and when execution resumes no signal
18710will be delivered. This is useful when your program stopped on account
18711of a signal and would ordinarily see the signal when resumed with the
18712@code{continue} command.
18713
18714This command differs from the @code{signal} command in that the signal
18715is just queued, execution is not resumed. And @code{queue-signal} cannot
18716be used to pass a signal whose handling state has been set to @code{nopass}
18717(@pxref{Signals}).
18718@end table
18719@c @end group
c906108c 18720
e5f8a7cc
PA
18721@xref{stepping into signal handlers}, for information on how stepping
18722commands behave when the thread has a signal queued.
18723
6d2ebf8b 18724@node Returning
79a6e687 18725@section Returning from a Function
c906108c
SS
18726
18727@table @code
18728@cindex returning from a function
18729@kindex return
18730@item return
18731@itemx return @var{expression}
18732You can cancel execution of a function call with the @code{return}
18733command. If you give an
18734@var{expression} argument, its value is used as the function's return
18735value.
18736@end table
18737
18738When you use @code{return}, @value{GDBN} discards the selected stack frame
18739(and all frames within it). You can think of this as making the
18740discarded frame return prematurely. If you wish to specify a value to
18741be returned, give that value as the argument to @code{return}.
18742
18743This pops the selected stack frame (@pxref{Selection, ,Selecting a
79a6e687 18744Frame}), and any other frames inside of it, leaving its caller as the
c906108c
SS
18745innermost remaining frame. That frame becomes selected. The
18746specified value is stored in the registers used for returning values
18747of functions.
18748
18749The @code{return} command does not resume execution; it leaves the
18750program stopped in the state that would exist if the function had just
18751returned. In contrast, the @code{finish} command (@pxref{Continuing
79a6e687 18752and Stepping, ,Continuing and Stepping}) resumes execution until the
c906108c
SS
18753selected stack frame returns naturally.
18754
61ff14c6
JK
18755@value{GDBN} needs to know how the @var{expression} argument should be set for
18756the inferior. The concrete registers assignment depends on the OS ABI and the
18757type being returned by the selected stack frame. For example it is common for
18758OS ABI to return floating point values in FPU registers while integer values in
18759CPU registers. Still some ABIs return even floating point values in CPU
18760registers. Larger integer widths (such as @code{long long int}) also have
18761specific placement rules. @value{GDBN} already knows the OS ABI from its
18762current target so it needs to find out also the type being returned to make the
18763assignment into the right register(s).
18764
18765Normally, the selected stack frame has debug info. @value{GDBN} will always
18766use the debug info instead of the implicit type of @var{expression} when the
18767debug info is available. For example, if you type @kbd{return -1}, and the
18768function in the current stack frame is declared to return a @code{long long
18769int}, @value{GDBN} transparently converts the implicit @code{int} value of -1
18770into a @code{long long int}:
18771
18772@smallexample
18773Breakpoint 1, func () at gdb.base/return-nodebug.c:29
1877429 return 31;
18775(@value{GDBP}) return -1
18776Make func return now? (y or n) y
18777#0 0x004004f6 in main () at gdb.base/return-nodebug.c:43
1877843 printf ("result=%lld\n", func ());
18779(@value{GDBP})
18780@end smallexample
18781
18782However, if the selected stack frame does not have a debug info, e.g., if the
18783function was compiled without debug info, @value{GDBN} has to find out the type
18784to return from user. Specifying a different type by mistake may set the value
18785in different inferior registers than the caller code expects. For example,
18786typing @kbd{return -1} with its implicit type @code{int} would set only a part
18787of a @code{long long int} result for a debug info less function (on 32-bit
18788architectures). Therefore the user is required to specify the return type by
18789an appropriate cast explicitly:
18790
18791@smallexample
18792Breakpoint 2, 0x0040050b in func ()
18793(@value{GDBP}) return -1
18794Return value type not available for selected stack frame.
18795Please use an explicit cast of the value to return.
18796(@value{GDBP}) return (long long int) -1
18797Make selected stack frame return now? (y or n) y
18798#0 0x00400526 in main ()
18799(@value{GDBP})
18800@end smallexample
18801
6d2ebf8b 18802@node Calling
79a6e687 18803@section Calling Program Functions
c906108c 18804
f8568604 18805@table @code
c906108c 18806@cindex calling functions
f8568604
EZ
18807@cindex inferior functions, calling
18808@item print @var{expr}
d3e8051b 18809Evaluate the expression @var{expr} and display the resulting value.
697aa1b7 18810The expression may include calls to functions in the program being
f8568604
EZ
18811debugged.
18812
c906108c 18813@kindex call
c906108c
SS
18814@item call @var{expr}
18815Evaluate the expression @var{expr} without displaying @code{void}
18816returned values.
c906108c
SS
18817
18818You can use this variant of the @code{print} command if you want to
f8568604
EZ
18819execute a function from your program that does not return anything
18820(a.k.a.@: @dfn{a void function}), but without cluttering the output
18821with @code{void} returned values that @value{GDBN} will otherwise
18822print. If the result is not void, it is printed and saved in the
18823value history.
18824@end table
18825
9c16f35a
EZ
18826It is possible for the function you call via the @code{print} or
18827@code{call} command to generate a signal (e.g., if there's a bug in
18828the function, or if you passed it incorrect arguments). What happens
18829in that case is controlled by the @code{set unwindonsignal} command.
18830
7cd1089b
PM
18831Similarly, with a C@t{++} program it is possible for the function you
18832call via the @code{print} or @code{call} command to generate an
18833exception that is not handled due to the constraints of the dummy
18834frame. In this case, any exception that is raised in the frame, but has
18835an out-of-frame exception handler will not be found. GDB builds a
18836dummy-frame for the inferior function call, and the unwinder cannot
18837seek for exception handlers outside of this dummy-frame. What happens
18838in that case is controlled by the
18839@code{set unwind-on-terminating-exception} command.
18840
9c16f35a
EZ
18841@table @code
18842@item set unwindonsignal
18843@kindex set unwindonsignal
18844@cindex unwind stack in called functions
18845@cindex call dummy stack unwinding
18846Set unwinding of the stack if a signal is received while in a function
18847that @value{GDBN} called in the program being debugged. If set to on,
18848@value{GDBN} unwinds the stack it created for the call and restores
18849the context to what it was before the call. If set to off (the
18850default), @value{GDBN} stops in the frame where the signal was
18851received.
18852
18853@item show unwindonsignal
18854@kindex show unwindonsignal
18855Show the current setting of stack unwinding in the functions called by
18856@value{GDBN}.
7cd1089b
PM
18857
18858@item set unwind-on-terminating-exception
18859@kindex set unwind-on-terminating-exception
18860@cindex unwind stack in called functions with unhandled exceptions
18861@cindex call dummy stack unwinding on unhandled exception.
18862Set unwinding of the stack if a C@t{++} exception is raised, but left
18863unhandled while in a function that @value{GDBN} called in the program being
18864debugged. If set to on (the default), @value{GDBN} unwinds the stack
18865it created for the call and restores the context to what it was before
18866the call. If set to off, @value{GDBN} the exception is delivered to
18867the default C@t{++} exception handler and the inferior terminated.
18868
18869@item show unwind-on-terminating-exception
18870@kindex show unwind-on-terminating-exception
18871Show the current setting of stack unwinding in the functions called by
18872@value{GDBN}.
18873
136afab8
PW
18874@item set may-call-functions
18875@kindex set may-call-functions
18876@cindex disabling calling functions in the program
18877@cindex calling functions in the program, disabling
18878Set permission to call functions in the program.
18879This controls whether @value{GDBN} will attempt to call functions in
18880the program, such as with expressions in the @code{print} command. It
18881defaults to @code{on}.
18882
18883To call a function in the program, @value{GDBN} has to temporarily
18884modify the state of the inferior. This has potentially undesired side
18885effects. Also, having @value{GDBN} call nested functions is likely to
18886be erroneous and may even crash the program being debugged. You can
18887avoid such hazards by forbidding @value{GDBN} from calling functions
18888in the program being debugged. If calling functions in the program
18889is forbidden, GDB will throw an error when a command (such as printing
18890an expression) starts a function call in the program.
18891
18892@item show may-call-functions
18893@kindex show may-call-functions
18894Show permission to call functions in the program.
18895
9c16f35a
EZ
18896@end table
18897
d69cf9b2
PA
18898@subsection Calling functions with no debug info
18899
18900@cindex no debug info functions
18901Sometimes, a function you wish to call is missing debug information.
18902In such case, @value{GDBN} does not know the type of the function,
18903including the types of the function's parameters. To avoid calling
18904the inferior function incorrectly, which could result in the called
18905function functioning erroneously and even crash, @value{GDBN} refuses
18906to call the function unless you tell it the type of the function.
18907
18908For prototyped (i.e.@: ANSI/ISO style) functions, there are two ways
18909to do that. The simplest is to cast the call to the function's
18910declared return type. For example:
18911
18912@smallexample
18913(@value{GDBP}) p getenv ("PATH")
18914'getenv' has unknown return type; cast the call to its declared return type
18915(@value{GDBP}) p (char *) getenv ("PATH")
18916$1 = 0x7fffffffe7ba "/usr/local/bin:/"...
18917@end smallexample
18918
18919Casting the return type of a no-debug function is equivalent to
18920casting the function to a pointer to a prototyped function that has a
18921prototype that matches the types of the passed-in arguments, and
18922calling that. I.e., the call above is equivalent to:
18923
18924@smallexample
18925(@value{GDBP}) p ((char * (*) (const char *)) getenv) ("PATH")
18926@end smallexample
18927
18928@noindent
18929and given this prototyped C or C++ function with float parameters:
18930
18931@smallexample
18932float multiply (float v1, float v2) @{ return v1 * v2; @}
18933@end smallexample
18934
18935@noindent
18936these calls are equivalent:
18937
18938@smallexample
18939(@value{GDBP}) p (float) multiply (2.0f, 3.0f)
18940(@value{GDBP}) p ((float (*) (float, float)) multiply) (2.0f, 3.0f)
18941@end smallexample
18942
18943If the function you wish to call is declared as unprototyped (i.e.@:
18944old K&R style), you must use the cast-to-function-pointer syntax, so
18945that @value{GDBN} knows that it needs to apply default argument
18946promotions (promote float arguments to double). @xref{ABI, float
18947promotion}. For example, given this unprototyped C function with
18948float parameters, and no debug info:
18949
18950@smallexample
18951float
18952multiply_noproto (v1, v2)
18953 float v1, v2;
18954@{
18955 return v1 * v2;
18956@}
18957@end smallexample
18958
18959@noindent
18960you call it like this:
18961
18962@smallexample
18963 (@value{GDBP}) p ((float (*) ()) multiply_noproto) (2.0f, 3.0f)
18964@end smallexample
c906108c 18965
6d2ebf8b 18966@node Patching
79a6e687 18967@section Patching Programs
7a292a7a 18968
c906108c
SS
18969@cindex patching binaries
18970@cindex writing into executables
c906108c 18971@cindex writing into corefiles
c906108c 18972
7a292a7a
SS
18973By default, @value{GDBN} opens the file containing your program's
18974executable code (or the corefile) read-only. This prevents accidental
18975alterations to machine code; but it also prevents you from intentionally
18976patching your program's binary.
c906108c
SS
18977
18978If you'd like to be able to patch the binary, you can specify that
18979explicitly with the @code{set write} command. For example, you might
18980want to turn on internal debugging flags, or even to make emergency
18981repairs.
18982
18983@table @code
18984@kindex set write
18985@item set write on
18986@itemx set write off
7a292a7a 18987If you specify @samp{set write on}, @value{GDBN} opens executable and
20924a55 18988core files for both reading and writing; if you specify @kbd{set write
c906108c
SS
18989off} (the default), @value{GDBN} opens them read-only.
18990
18991If you have already loaded a file, you must load it again (using the
7a292a7a
SS
18992@code{exec-file} or @code{core-file} command) after changing @code{set
18993write}, for your new setting to take effect.
c906108c
SS
18994
18995@item show write
18996@kindex show write
7a292a7a
SS
18997Display whether executable files and core files are opened for writing
18998as well as reading.
c906108c
SS
18999@end table
19000
bb2ec1b3
TT
19001@node Compiling and Injecting Code
19002@section Compiling and injecting code in @value{GDBN}
19003@cindex injecting code
19004@cindex writing into executables
19005@cindex compiling code
19006
19007@value{GDBN} supports on-demand compilation and code injection into
19008programs running under @value{GDBN}. GCC 5.0 or higher built with
19009@file{libcc1.so} must be installed for this functionality to be enabled.
19010This functionality is implemented with the following commands.
19011
19012@table @code
19013@kindex compile code
19014@item compile code @var{source-code}
19015@itemx compile code -raw @var{--} @var{source-code}
19016Compile @var{source-code} with the compiler language found as the current
19017language in @value{GDBN} (@pxref{Languages}). If compilation and
19018injection is not supported with the current language specified in
19019@value{GDBN}, or the compiler does not support this feature, an error
19020message will be printed. If @var{source-code} compiles and links
19021successfully, @value{GDBN} will load the object-code emitted,
19022and execute it within the context of the currently selected inferior.
19023It is important to note that the compiled code is executed immediately.
19024After execution, the compiled code is removed from @value{GDBN} and any
19025new types or variables you have defined will be deleted.
19026
19027The command allows you to specify @var{source-code} in two ways.
19028The simplest method is to provide a single line of code to the command.
19029E.g.:
19030
19031@smallexample
19032compile code printf ("hello world\n");
19033@end smallexample
19034
19035If you specify options on the command line as well as source code, they
19036may conflict. The @samp{--} delimiter can be used to separate options
19037from actual source code. E.g.:
19038
19039@smallexample
19040compile code -r -- printf ("hello world\n");
19041@end smallexample
19042
19043Alternatively you can enter source code as multiple lines of text. To
19044enter this mode, invoke the @samp{compile code} command without any text
19045following the command. This will start the multiple-line editor and
19046allow you to type as many lines of source code as required. When you
19047have completed typing, enter @samp{end} on its own line to exit the
19048editor.
19049
19050@smallexample
19051compile code
19052>printf ("hello\n");
19053>printf ("world\n");
19054>end
19055@end smallexample
19056
19057Specifying @samp{-raw}, prohibits @value{GDBN} from wrapping the
19058provided @var{source-code} in a callable scope. In this case, you must
19059specify the entry point of the code by defining a function named
19060@code{_gdb_expr_}. The @samp{-raw} code cannot access variables of the
19061inferior. Using @samp{-raw} option may be needed for example when
19062@var{source-code} requires @samp{#include} lines which may conflict with
19063inferior symbols otherwise.
19064
19065@kindex compile file
19066@item compile file @var{filename}
19067@itemx compile file -raw @var{filename}
19068Like @code{compile code}, but take the source code from @var{filename}.
19069
19070@smallexample
19071compile file /home/user/example.c
19072@end smallexample
19073@end table
19074
36de76f9
JK
19075@table @code
19076@item compile print @var{expr}
19077@itemx compile print /@var{f} @var{expr}
19078Compile and execute @var{expr} with the compiler language found as the
19079current language in @value{GDBN} (@pxref{Languages}). By default the
19080value of @var{expr} is printed in a format appropriate to its data type;
19081you can choose a different format by specifying @samp{/@var{f}}, where
19082@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
19083Formats}.
19084
19085@item compile print
19086@itemx compile print /@var{f}
19087@cindex reprint the last value
19088Alternatively you can enter the expression (source code producing it) as
19089multiple lines of text. To enter this mode, invoke the @samp{compile print}
19090command without any text following the command. This will start the
19091multiple-line editor.
19092@end table
19093
e7a8570f
JK
19094@noindent
19095The process of compiling and injecting the code can be inspected using:
19096
19097@table @code
19098@anchor{set debug compile}
19099@item set debug compile
19100@cindex compile command debugging info
19101Turns on or off display of @value{GDBN} process of compiling and
19102injecting the code. The default is off.
19103
19104@item show debug compile
19105Displays the current state of displaying @value{GDBN} process of
19106compiling and injecting the code.
078a0207
KS
19107
19108@anchor{set debug compile-cplus-types}
19109@item set debug compile-cplus-types
19110@cindex compile C@t{++} type conversion
19111Turns on or off the display of C@t{++} type conversion debugging information.
19112The default is off.
19113
19114@item show debug compile-cplus-types
19115Displays the current state of displaying debugging information for
19116C@t{++} type conversion.
e7a8570f
JK
19117@end table
19118
19119@subsection Compilation options for the @code{compile} command
19120
19121@value{GDBN} needs to specify the right compilation options for the code
19122to be injected, in part to make its ABI compatible with the inferior
19123and in part to make the injected code compatible with @value{GDBN}'s
19124injecting process.
19125
19126@noindent
19127The options used, in increasing precedence:
19128
19129@table @asis
19130@item target architecture and OS options (@code{gdbarch})
19131These options depend on target processor type and target operating
19132system, usually they specify at least 32-bit (@code{-m32}) or 64-bit
19133(@code{-m64}) compilation option.
19134
19135@item compilation options recorded in the target
19136@value{NGCC} (since version 4.7) stores the options used for compilation
19137into @code{DW_AT_producer} part of DWARF debugging information according
19138to the @value{NGCC} option @code{-grecord-gcc-switches}. One has to
19139explicitly specify @code{-g} during inferior compilation otherwise
19140@value{NGCC} produces no DWARF. This feature is only relevant for
19141platforms where @code{-g} produces DWARF by default, otherwise one may
19142try to enforce DWARF by using @code{-gdwarf-4}.
19143
19144@item compilation options set by @code{set compile-args}
19145@end table
19146
19147@noindent
19148You can override compilation options using the following command:
19149
19150@table @code
19151@item set compile-args
19152@cindex compile command options override
19153Set compilation options used for compiling and injecting code with the
19154@code{compile} commands. These options override any conflicting ones
19155from the target architecture and/or options stored during inferior
19156compilation.
19157
19158@item show compile-args
19159Displays the current state of compilation options override.
19160This does not show all the options actually used during compilation,
19161use @ref{set debug compile} for that.
19162@end table
19163
bb2ec1b3
TT
19164@subsection Caveats when using the @code{compile} command
19165
19166There are a few caveats to keep in mind when using the @code{compile}
19167command. As the caveats are different per language, the table below
19168highlights specific issues on a per language basis.
19169
19170@table @asis
19171@item C code examples and caveats
19172When the language in @value{GDBN} is set to @samp{C}, the compiler will
19173attempt to compile the source code with a @samp{C} compiler. The source
19174code provided to the @code{compile} command will have much the same
19175access to variables and types as it normally would if it were part of
19176the program currently being debugged in @value{GDBN}.
19177
19178Below is a sample program that forms the basis of the examples that
19179follow. This program has been compiled and loaded into @value{GDBN},
19180much like any other normal debugging session.
19181
19182@smallexample
19183void function1 (void)
19184@{
19185 int i = 42;
19186 printf ("function 1\n");
19187@}
19188
19189void function2 (void)
19190@{
19191 int j = 12;
19192 function1 ();
19193@}
19194
19195int main(void)
19196@{
19197 int k = 6;
19198 int *p;
19199 function2 ();
19200 return 0;
19201@}
19202@end smallexample
19203
19204For the purposes of the examples in this section, the program above has
19205been compiled, loaded into @value{GDBN}, stopped at the function
19206@code{main}, and @value{GDBN} is awaiting input from the user.
19207
19208To access variables and types for any program in @value{GDBN}, the
19209program must be compiled and packaged with debug information. The
19210@code{compile} command is not an exception to this rule. Without debug
19211information, you can still use the @code{compile} command, but you will
19212be very limited in what variables and types you can access.
19213
19214So with that in mind, the example above has been compiled with debug
19215information enabled. The @code{compile} command will have access to
19216all variables and types (except those that may have been optimized
19217out). Currently, as @value{GDBN} has stopped the program in the
19218@code{main} function, the @code{compile} command would have access to
19219the variable @code{k}. You could invoke the @code{compile} command
19220and type some source code to set the value of @code{k}. You can also
19221read it, or do anything with that variable you would normally do in
19222@code{C}. Be aware that changes to inferior variables in the
19223@code{compile} command are persistent. In the following example:
19224
19225@smallexample
19226compile code k = 3;
19227@end smallexample
19228
19229@noindent
19230the variable @code{k} is now 3. It will retain that value until
19231something else in the example program changes it, or another
19232@code{compile} command changes it.
19233
19234Normal scope and access rules apply to source code compiled and
19235injected by the @code{compile} command. In the example, the variables
19236@code{j} and @code{k} are not accessible yet, because the program is
19237currently stopped in the @code{main} function, where these variables
19238are not in scope. Therefore, the following command
19239
19240@smallexample
19241compile code j = 3;
19242@end smallexample
19243
19244@noindent
19245will result in a compilation error message.
19246
19247Once the program is continued, execution will bring these variables in
19248scope, and they will become accessible; then the code you specify via
19249the @code{compile} command will be able to access them.
19250
19251You can create variables and types with the @code{compile} command as
19252part of your source code. Variables and types that are created as part
19253of the @code{compile} command are not visible to the rest of the program for
19254the duration of its run. This example is valid:
19255
19256@smallexample
19257compile code int ff = 5; printf ("ff is %d\n", ff);
19258@end smallexample
19259
19260However, if you were to type the following into @value{GDBN} after that
19261command has completed:
19262
19263@smallexample
19264compile code printf ("ff is %d\n'', ff);
19265@end smallexample
19266
19267@noindent
19268a compiler error would be raised as the variable @code{ff} no longer
19269exists. Object code generated and injected by the @code{compile}
19270command is removed when its execution ends. Caution is advised
19271when assigning to program variables values of variables created by the
19272code submitted to the @code{compile} command. This example is valid:
19273
19274@smallexample
19275compile code int ff = 5; k = ff;
19276@end smallexample
19277
19278The value of the variable @code{ff} is assigned to @code{k}. The variable
19279@code{k} does not require the existence of @code{ff} to maintain the value
19280it has been assigned. However, pointers require particular care in
19281assignment. If the source code compiled with the @code{compile} command
19282changed the address of a pointer in the example program, perhaps to a
19283variable created in the @code{compile} command, that pointer would point
19284to an invalid location when the command exits. The following example
19285would likely cause issues with your debugged program:
19286
19287@smallexample
19288compile code int ff = 5; p = &ff;
19289@end smallexample
19290
19291In this example, @code{p} would point to @code{ff} when the
19292@code{compile} command is executing the source code provided to it.
19293However, as variables in the (example) program persist with their
19294assigned values, the variable @code{p} would point to an invalid
19295location when the command exists. A general rule should be followed
19296in that you should either assign @code{NULL} to any assigned pointers,
19297or restore a valid location to the pointer before the command exits.
19298
19299Similar caution must be exercised with any structs, unions, and typedefs
19300defined in @code{compile} command. Types defined in the @code{compile}
19301command will no longer be available in the next @code{compile} command.
19302Therefore, if you cast a variable to a type defined in the
19303@code{compile} command, care must be taken to ensure that any future
19304need to resolve the type can be achieved.
19305
19306@smallexample
19307(gdb) compile code static struct a @{ int a; @} v = @{ 42 @}; argv = &v;
19308(gdb) compile code printf ("%d\n", ((struct a *) argv)->a);
19309gdb command line:1:36: error: dereferencing pointer to incomplete type ‘struct a’
19310Compilation failed.
19311(gdb) compile code struct a @{ int a; @}; printf ("%d\n", ((struct a *) argv)->a);
1931242
19313@end smallexample
19314
19315Variables that have been optimized away by the compiler are not
19316accessible to the code submitted to the @code{compile} command.
19317Access to those variables will generate a compiler error which @value{GDBN}
19318will print to the console.
19319@end table
19320
e7a8570f
JK
19321@subsection Compiler search for the @code{compile} command
19322
6e41ddec
JK
19323@value{GDBN} needs to find @value{NGCC} for the inferior being debugged
19324which may not be obvious for remote targets of different architecture
19325than where @value{GDBN} is running. Environment variable @code{PATH} on
e7a8570f 19326@value{GDBN} host is searched for @value{NGCC} binary matching the
6e41ddec
JK
19327target architecture and operating system. This search can be overriden
19328by @code{set compile-gcc} @value{GDBN} command below. @code{PATH} is
19329taken from shell that executed @value{GDBN}, it is not the value set by
19330@value{GDBN} command @code{set environment}). @xref{Environment}.
19331
e7a8570f
JK
19332
19333Specifically @code{PATH} is searched for binaries matching regular expression
19334@code{@var{arch}(-[^-]*)?-@var{os}-gcc} according to the inferior target being
19335debugged. @var{arch} is processor name --- multiarch is supported, so for
19336example both @code{i386} and @code{x86_64} targets look for pattern
19337@code{(x86_64|i.86)} and both @code{s390} and @code{s390x} targets look
19338for pattern @code{s390x?}. @var{os} is currently supported only for
19339pattern @code{linux(-gnu)?}.
19340
6e41ddec
JK
19341On Posix hosts the compiler driver @value{GDBN} needs to find also
19342shared library @file{libcc1.so} from the compiler. It is searched in
19343default shared library search path (overridable with usual environment
19344variable @code{LD_LIBRARY_PATH}), unrelated to @code{PATH} or @code{set
19345compile-gcc} settings. Contrary to it @file{libcc1plugin.so} is found
19346according to the installation of the found compiler --- as possibly
19347specified by the @code{set compile-gcc} command.
19348
19349@table @code
19350@item set compile-gcc
19351@cindex compile command driver filename override
19352Set compilation command used for compiling and injecting code with the
19353@code{compile} commands. If this option is not set (it is set to
19354an empty string), the search described above will occur --- that is the
19355default.
19356
19357@item show compile-gcc
19358Displays the current compile command @value{NGCC} driver filename.
19359If set, it is the main command @command{gcc}, found usually for example
19360under name @file{x86_64-linux-gnu-gcc}.
19361@end table
19362
6d2ebf8b 19363@node GDB Files
c906108c
SS
19364@chapter @value{GDBN} Files
19365
7a292a7a
SS
19366@value{GDBN} needs to know the file name of the program to be debugged,
19367both in order to read its symbol table and in order to start your
19368program. To debug a core dump of a previous run, you must also tell
19369@value{GDBN} the name of the core dump file.
c906108c
SS
19370
19371@menu
19372* Files:: Commands to specify files
2b4bf6af 19373* File Caching:: Information about @value{GDBN}'s file caching
5b5d99cf 19374* Separate Debug Files:: Debugging information in separate files
608e2dbb 19375* MiniDebugInfo:: Debugging information in a special section
9291a0cd 19376* Index Files:: Index files speed up GDB
c906108c 19377* Symbol Errors:: Errors reading symbol files
b14b1491 19378* Data Files:: GDB data files
c906108c
SS
19379@end menu
19380
6d2ebf8b 19381@node Files
79a6e687 19382@section Commands to Specify Files
c906108c 19383
7a292a7a 19384@cindex symbol table
c906108c 19385@cindex core dump file
7a292a7a
SS
19386
19387You may want to specify executable and core dump file names. The usual
19388way to do this is at start-up time, using the arguments to
19389@value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
19390Out of @value{GDBN}}).
c906108c
SS
19391
19392Occasionally it is necessary to change to a different file during a
397ca115
EZ
19393@value{GDBN} session. Or you may run @value{GDBN} and forget to
19394specify a file you want to use. Or you are debugging a remote target
79a6e687
BW
19395via @code{gdbserver} (@pxref{Server, file, Using the @code{gdbserver}
19396Program}). In these situations the @value{GDBN} commands to specify
0869d01b 19397new files are useful.
c906108c
SS
19398
19399@table @code
19400@cindex executable file
19401@kindex file
19402@item file @var{filename}
19403Use @var{filename} as the program to be debugged. It is read for its
19404symbols and for the contents of pure memory. It is also the program
19405executed when you use the @code{run} command. If you do not specify a
5d161b24
DB
19406directory and the file is not found in the @value{GDBN} working directory,
19407@value{GDBN} uses the environment variable @code{PATH} as a list of
19408directories to search, just as the shell does when looking for a program
19409to run. You can change the value of this variable, for both @value{GDBN}
c906108c
SS
19410and your program, using the @code{path} command.
19411
fc8be69e
EZ
19412@cindex unlinked object files
19413@cindex patching object files
19414You can load unlinked object @file{.o} files into @value{GDBN} using
19415the @code{file} command. You will not be able to ``run'' an object
19416file, but you can disassemble functions and inspect variables. Also,
19417if the underlying BFD functionality supports it, you could use
19418@kbd{gdb -write} to patch object files using this technique. Note
19419that @value{GDBN} can neither interpret nor modify relocations in this
19420case, so branches and some initialized variables will appear to go to
19421the wrong place. But this feature is still handy from time to time.
19422
c906108c
SS
19423@item file
19424@code{file} with no argument makes @value{GDBN} discard any information it
19425has on both executable file and the symbol table.
19426
19427@kindex exec-file
19428@item exec-file @r{[} @var{filename} @r{]}
19429Specify that the program to be run (but not the symbol table) is found
19430in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
19431if necessary to locate your program. Omitting @var{filename} means to
19432discard information on the executable file.
19433
19434@kindex symbol-file
d4d429d5 19435@item symbol-file @r{[} @var{filename} @r{[} -o @var{offset} @r{]]}
c906108c
SS
19436Read symbol table information from file @var{filename}. @code{PATH} is
19437searched when necessary. Use the @code{file} command to get both symbol
19438table and program to run from the same file.
19439
d4d429d5
PT
19440If an optional @var{offset} is specified, it is added to the start
19441address of each section in the symbol file. This is useful if the
19442program is relocated at runtime, such as the Linux kernel with kASLR
19443enabled.
19444
c906108c
SS
19445@code{symbol-file} with no argument clears out @value{GDBN} information on your
19446program's symbol table.
19447
ae5a43e0
DJ
19448The @code{symbol-file} command causes @value{GDBN} to forget the contents of
19449some breakpoints and auto-display expressions. This is because they may
19450contain pointers to the internal data recording symbols and data types,
19451which are part of the old symbol table data being discarded inside
19452@value{GDBN}.
c906108c
SS
19453
19454@code{symbol-file} does not repeat if you press @key{RET} again after
19455executing it once.
19456
19457When @value{GDBN} is configured for a particular environment, it
19458understands debugging information in whatever format is the standard
19459generated for that environment; you may use either a @sc{gnu} compiler, or
19460other compilers that adhere to the local conventions.
c906108c 19461Best results are usually obtained from @sc{gnu} compilers; for example,
e22ea452 19462using @code{@value{NGCC}} you can generate debugging information for
c906108c 19463optimized code.
c906108c
SS
19464
19465For most kinds of object files, with the exception of old SVR3 systems
19466using COFF, the @code{symbol-file} command does not normally read the
19467symbol table in full right away. Instead, it scans the symbol table
19468quickly to find which source files and which symbols are present. The
19469details are read later, one source file at a time, as they are needed.
19470
19471The purpose of this two-stage reading strategy is to make @value{GDBN}
19472start up faster. For the most part, it is invisible except for
19473occasional pauses while the symbol table details for a particular source
19474file are being read. (The @code{set verbose} command can turn these
19475pauses into messages if desired. @xref{Messages/Warnings, ,Optional
79a6e687 19476Warnings and Messages}.)
c906108c 19477
c906108c
SS
19478We have not implemented the two-stage strategy for COFF yet. When the
19479symbol table is stored in COFF format, @code{symbol-file} reads the
19480symbol table data in full right away. Note that ``stabs-in-COFF''
19481still does the two-stage strategy, since the debug info is actually
19482in stabs format.
19483
19484@kindex readnow
19485@cindex reading symbols immediately
19486@cindex symbols, reading immediately
6ac33a4e
TT
19487@item symbol-file @r{[} -readnow @r{]} @var{filename}
19488@itemx file @r{[} -readnow @r{]} @var{filename}
c906108c
SS
19489You can override the @value{GDBN} two-stage strategy for reading symbol
19490tables by using the @samp{-readnow} option with any of the commands that
19491load symbol table information, if you want to be sure @value{GDBN} has the
5d161b24 19492entire symbol table available.
c906108c 19493
97cbe998
SDJ
19494@cindex @code{-readnever}, option for symbol-file command
19495@cindex never read symbols
19496@cindex symbols, never read
19497@item symbol-file @r{[} -readnever @r{]} @var{filename}
19498@itemx file @r{[} -readnever @r{]} @var{filename}
19499You can instruct @value{GDBN} to never read the symbolic information
19500contained in @var{filename} by using the @samp{-readnever} option.
19501@xref{--readnever}.
19502
c906108c
SS
19503@c FIXME: for now no mention of directories, since this seems to be in
19504@c flux. 13mar1992 status is that in theory GDB would look either in
19505@c current dir or in same dir as myprog; but issues like competing
19506@c GDB's, or clutter in system dirs, mean that in practice right now
19507@c only current dir is used. FFish says maybe a special GDB hierarchy
19508@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
19509@c files.
19510
c906108c 19511@kindex core-file
09d4efe1 19512@item core-file @r{[}@var{filename}@r{]}
4644b6e3 19513@itemx core
c906108c
SS
19514Specify the whereabouts of a core dump file to be used as the ``contents
19515of memory''. Traditionally, core files contain only some parts of the
19516address space of the process that generated them; @value{GDBN} can access the
19517executable file itself for other parts.
19518
19519@code{core-file} with no argument specifies that no core file is
19520to be used.
19521
19522Note that the core file is ignored when your program is actually running
7a292a7a
SS
19523under @value{GDBN}. So, if you have been running your program and you
19524wish to debug a core file instead, you must kill the subprocess in which
19525the program is running. To do this, use the @code{kill} command
79a6e687 19526(@pxref{Kill Process, ,Killing the Child Process}).
c906108c 19527
c906108c
SS
19528@kindex add-symbol-file
19529@cindex dynamic linking
291f9a96 19530@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
19531The @code{add-symbol-file} command reads additional symbol table
19532information from the file @var{filename}. You would use this command
19533when @var{filename} has been dynamically loaded (by some other means)
ed6dfe51
PT
19534into the program that is running. The @var{textaddress} parameter gives
19535the memory address at which the file's text section has been loaded.
19536You can additionally specify the base address of other sections using
19537an arbitrary number of @samp{-s @var{section} @var{address}} pairs.
19538If a section is omitted, @value{GDBN} will use its default addresses
19539as found in @var{filename}. Any @var{address} or @var{textaddress}
19540can be given as an expression.
c906108c 19541
291f9a96
PT
19542If an optional @var{offset} is specified, it is added to the start
19543address of each section, except those for which the address was
19544specified explicitly.
19545
c906108c
SS
19546The symbol table of the file @var{filename} is added to the symbol table
19547originally read with the @code{symbol-file} command. You can use the
96a2c332 19548@code{add-symbol-file} command any number of times; the new symbol data
98297bf6
NB
19549thus read is kept in addition to the old.
19550
19551Changes can be reverted using the command @code{remove-symbol-file}.
c906108c 19552
17d9d558
JB
19553@cindex relocatable object files, reading symbols from
19554@cindex object files, relocatable, reading symbols from
19555@cindex reading symbols from relocatable object files
19556@cindex symbols, reading from relocatable object files
19557@cindex @file{.o} files, reading symbols from
19558Although @var{filename} is typically a shared library file, an
19559executable file, or some other object file which has been fully
19560relocated for loading into a process, you can also load symbolic
19561information from relocatable @file{.o} files, as long as:
19562
19563@itemize @bullet
19564@item
19565the file's symbolic information refers only to linker symbols defined in
19566that file, not to symbols defined by other object files,
19567@item
19568every section the file's symbolic information refers to has actually
19569been loaded into the inferior, as it appears in the file, and
19570@item
19571you can determine the address at which every section was loaded, and
19572provide these to the @code{add-symbol-file} command.
19573@end itemize
19574
19575@noindent
19576Some embedded operating systems, like Sun Chorus and VxWorks, can load
19577relocatable files into an already running program; such systems
19578typically make the requirements above easy to meet. However, it's
19579important to recognize that many native systems use complex link
49efadf5 19580procedures (@code{.linkonce} section factoring and C@t{++} constructor table
17d9d558
JB
19581assembly, for example) that make the requirements difficult to meet. In
19582general, one cannot assume that using @code{add-symbol-file} to read a
19583relocatable object file's symbolic information will have the same effect
19584as linking the relocatable object file into the program in the normal
19585way.
19586
c906108c
SS
19587@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
19588
98297bf6
NB
19589@kindex remove-symbol-file
19590@item remove-symbol-file @var{filename}
19591@item remove-symbol-file -a @var{address}
19592Remove a symbol file added via the @code{add-symbol-file} command. The
19593file to remove can be identified by its @var{filename} or by an @var{address}
19594that lies within the boundaries of this symbol file in memory. Example:
19595
19596@smallexample
19597(gdb) add-symbol-file /home/user/gdb/mylib.so 0x7ffff7ff9480
19598add symbol table from file "/home/user/gdb/mylib.so" at
19599 .text_addr = 0x7ffff7ff9480
19600(y or n) y
19601Reading symbols from /home/user/gdb/mylib.so...done.
19602(gdb) remove-symbol-file -a 0x7ffff7ff9480
19603Remove symbol table from file "/home/user/gdb/mylib.so"? (y or n) y
19604(gdb)
19605@end smallexample
19606
19607
19608@code{remove-symbol-file} does not repeat if you press @key{RET} after using it.
19609
c45da7e6
EZ
19610@kindex add-symbol-file-from-memory
19611@cindex @code{syscall DSO}
19612@cindex load symbols from memory
19613@item add-symbol-file-from-memory @var{address}
19614Load symbols from the given @var{address} in a dynamically loaded
19615object file whose image is mapped directly into the inferior's memory.
19616For example, the Linux kernel maps a @code{syscall DSO} into each
19617process's address space; this DSO provides kernel-specific code for
19618some system calls. The argument can be any expression whose
19619evaluation yields the address of the file's shared object file header.
19620For this command to work, you must have used @code{symbol-file} or
19621@code{exec-file} commands in advance.
19622
c906108c 19623@kindex section
09d4efe1
EZ
19624@item section @var{section} @var{addr}
19625The @code{section} command changes the base address of the named
19626@var{section} of the exec file to @var{addr}. This can be used if the
19627exec file does not contain section addresses, (such as in the
19628@code{a.out} format), or when the addresses specified in the file
19629itself are wrong. Each section must be changed separately. The
19630@code{info files} command, described below, lists all the sections and
19631their addresses.
c906108c
SS
19632
19633@kindex info files
19634@kindex info target
19635@item info files
19636@itemx info target
7a292a7a
SS
19637@code{info files} and @code{info target} are synonymous; both print the
19638current target (@pxref{Targets, ,Specifying a Debugging Target}),
19639including the names of the executable and core dump files currently in
19640use by @value{GDBN}, and the files from which symbols were loaded. The
19641command @code{help target} lists all possible targets rather than
19642current ones.
19643
fe95c787
MS
19644@kindex maint info sections
19645@item maint info sections
19646Another command that can give you extra information about program sections
19647is @code{maint info sections}. In addition to the section information
19648displayed by @code{info files}, this command displays the flags and file
19649offset of each section in the executable and core dump files. In addition,
19650@code{maint info sections} provides the following command options (which
19651may be arbitrarily combined):
19652
19653@table @code
19654@item ALLOBJ
19655Display sections for all loaded object files, including shared libraries.
19656@item @var{sections}
6600abed 19657Display info only for named @var{sections}.
fe95c787
MS
19658@item @var{section-flags}
19659Display info only for sections for which @var{section-flags} are true.
19660The section flags that @value{GDBN} currently knows about are:
19661@table @code
19662@item ALLOC
19663Section will have space allocated in the process when loaded.
19664Set for all sections except those containing debug information.
19665@item LOAD
19666Section will be loaded from the file into the child process memory.
19667Set for pre-initialized code and data, clear for @code{.bss} sections.
19668@item RELOC
19669Section needs to be relocated before loading.
19670@item READONLY
19671Section cannot be modified by the child process.
19672@item CODE
19673Section contains executable code only.
6600abed 19674@item DATA
fe95c787
MS
19675Section contains data only (no executable code).
19676@item ROM
19677Section will reside in ROM.
19678@item CONSTRUCTOR
19679Section contains data for constructor/destructor lists.
19680@item HAS_CONTENTS
19681Section is not empty.
19682@item NEVER_LOAD
19683An instruction to the linker to not output the section.
19684@item COFF_SHARED_LIBRARY
19685A notification to the linker that the section contains
19686COFF shared library information.
19687@item IS_COMMON
19688Section contains common symbols.
19689@end table
19690@end table
6763aef9 19691@kindex set trust-readonly-sections
9c16f35a 19692@cindex read-only sections
6763aef9
MS
19693@item set trust-readonly-sections on
19694Tell @value{GDBN} that readonly sections in your object file
6ca652b0 19695really are read-only (i.e.@: that their contents will not change).
6763aef9
MS
19696In that case, @value{GDBN} can fetch values from these sections
19697out of the object file, rather than from the target program.
19698For some targets (notably embedded ones), this can be a significant
19699enhancement to debugging performance.
19700
19701The default is off.
19702
19703@item set trust-readonly-sections off
15110bc3 19704Tell @value{GDBN} not to trust readonly sections. This means that
6763aef9
MS
19705the contents of the section might change while the program is running,
19706and must therefore be fetched from the target when needed.
9c16f35a
EZ
19707
19708@item show trust-readonly-sections
19709Show the current setting of trusting readonly sections.
c906108c
SS
19710@end table
19711
19712All file-specifying commands allow both absolute and relative file names
19713as arguments. @value{GDBN} always converts the file name to an absolute file
19714name and remembers it that way.
19715
c906108c 19716@cindex shared libraries
9cceb671 19717@anchor{Shared Libraries}
b1236ac3
PA
19718@value{GDBN} supports @sc{gnu}/Linux, MS-Windows, SunOS,
19719Darwin/Mach-O, SVr4, IBM RS/6000 AIX, QNX Neutrino, FDPIC (FR-V), and
19720DSBT (TIC6X) shared libraries.
53a5351d 19721
9cceb671
DJ
19722On MS-Windows @value{GDBN} must be linked with the Expat library to support
19723shared libraries. @xref{Expat}.
19724
c906108c
SS
19725@value{GDBN} automatically loads symbol definitions from shared libraries
19726when you use the @code{run} command, or when you examine a core file.
19727(Before you issue the @code{run} command, @value{GDBN} does not understand
19728references to a function in a shared library, however---unless you are
19729debugging a core file).
53a5351d 19730
c906108c
SS
19731@c FIXME: some @value{GDBN} release may permit some refs to undef
19732@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
19733@c FIXME...lib; check this from time to time when updating manual
19734
b7209cb4
FF
19735There are times, however, when you may wish to not automatically load
19736symbol definitions from shared libraries, such as when they are
19737particularly large or there are many of them.
19738
19739To control the automatic loading of shared library symbols, use the
19740commands:
19741
19742@table @code
19743@kindex set auto-solib-add
19744@item set auto-solib-add @var{mode}
19745If @var{mode} is @code{on}, symbols from all shared object libraries
19746will be loaded automatically when the inferior begins execution, you
19747attach to an independently started inferior, or when the dynamic linker
19748informs @value{GDBN} that a new library has been loaded. If @var{mode}
19749is @code{off}, symbols must be loaded manually, using the
19750@code{sharedlibrary} command. The default value is @code{on}.
19751
dcaf7c2c
EZ
19752@cindex memory used for symbol tables
19753If your program uses lots of shared libraries with debug info that
19754takes large amounts of memory, you can decrease the @value{GDBN}
19755memory footprint by preventing it from automatically loading the
19756symbols from shared libraries. To that end, type @kbd{set
19757auto-solib-add off} before running the inferior, then load each
19758library whose debug symbols you do need with @kbd{sharedlibrary
d3e8051b 19759@var{regexp}}, where @var{regexp} is a regular expression that matches
dcaf7c2c
EZ
19760the libraries whose symbols you want to be loaded.
19761
b7209cb4
FF
19762@kindex show auto-solib-add
19763@item show auto-solib-add
19764Display the current autoloading mode.
19765@end table
19766
c45da7e6 19767@cindex load shared library
b7209cb4
FF
19768To explicitly load shared library symbols, use the @code{sharedlibrary}
19769command:
19770
c906108c
SS
19771@table @code
19772@kindex info sharedlibrary
19773@kindex info share
55333a84
DE
19774@item info share @var{regex}
19775@itemx info sharedlibrary @var{regex}
19776Print the names of the shared libraries which are currently loaded
19777that match @var{regex}. If @var{regex} is omitted then print
19778all shared libraries that are loaded.
c906108c 19779
b30a0bc3
JB
19780@kindex info dll
19781@item info dll @var{regex}
19782This is an alias of @code{info sharedlibrary}.
19783
c906108c
SS
19784@kindex sharedlibrary
19785@kindex share
19786@item sharedlibrary @var{regex}
19787@itemx share @var{regex}
c906108c
SS
19788Load shared object library symbols for files matching a
19789Unix regular expression.
19790As with files loaded automatically, it only loads shared libraries
19791required by your program for a core file or after typing @code{run}. If
19792@var{regex} is omitted all shared libraries required by your program are
19793loaded.
c45da7e6
EZ
19794
19795@item nosharedlibrary
19796@kindex nosharedlibrary
19797@cindex unload symbols from shared libraries
19798Unload all shared object library symbols. This discards all symbols
19799that have been loaded from all shared libraries. Symbols from shared
19800libraries that were loaded by explicit user requests are not
19801discarded.
c906108c
SS
19802@end table
19803
721c2651 19804Sometimes you may wish that @value{GDBN} stops and gives you control
edcc5120
TT
19805when any of shared library events happen. The best way to do this is
19806to use @code{catch load} and @code{catch unload} (@pxref{Set
19807Catchpoints}).
19808
19809@value{GDBN} also supports the the @code{set stop-on-solib-events}
19810command for this. This command exists for historical reasons. It is
19811less useful than setting a catchpoint, because it does not allow for
19812conditions or commands as a catchpoint does.
721c2651
EZ
19813
19814@table @code
19815@item set stop-on-solib-events
19816@kindex set stop-on-solib-events
19817This command controls whether @value{GDBN} should give you control
19818when the dynamic linker notifies it about some shared library event.
19819The most common event of interest is loading or unloading of a new
19820shared library.
19821
19822@item show stop-on-solib-events
19823@kindex show stop-on-solib-events
19824Show whether @value{GDBN} stops and gives you control when shared
19825library events happen.
19826@end table
19827
f5ebfba0 19828Shared libraries are also supported in many cross or remote debugging
f1838a98
UW
19829configurations. @value{GDBN} needs to have access to the target's libraries;
19830this can be accomplished either by providing copies of the libraries
19831on the host system, or by asking @value{GDBN} to automatically retrieve the
19832libraries from the target. If copies of the target libraries are
19833provided, they need to be the same as the target libraries, although the
f5ebfba0
DJ
19834copies on the target can be stripped as long as the copies on the host are
19835not.
19836
59b7b46f
EZ
19837@cindex where to look for shared libraries
19838For remote debugging, you need to tell @value{GDBN} where the target
19839libraries are, so that it can load the correct copies---otherwise, it
19840may try to load the host's libraries. @value{GDBN} has two variables
19841to specify the search directories for target libraries.
f5ebfba0
DJ
19842
19843@table @code
a9a5a3d1 19844@cindex prefix for executable and shared library file names
f822c95b 19845@cindex system root, alternate
f5ebfba0 19846@kindex set solib-absolute-prefix
f822c95b
DJ
19847@kindex set sysroot
19848@item set sysroot @var{path}
19849Use @var{path} as the system root for the program being debugged. Any
19850absolute shared library paths will be prefixed with @var{path}; many
19851runtime loaders store the absolute paths to the shared library in the
a9a5a3d1
GB
19852target program's memory. When starting processes remotely, and when
19853attaching to already-running processes (local or remote), their
19854executable filenames will be prefixed with @var{path} if reported to
19855@value{GDBN} as absolute by the operating system. If you use
19856@code{set sysroot} to find executables and shared libraries, they need
19857to be laid out in the same way that they are on the target, with
19858e.g.@: a @file{/bin}, @file{/lib} and @file{/usr/lib} hierarchy under
19859@var{path}.
f822c95b 19860
599bd15c
GB
19861If @var{path} starts with the sequence @file{target:} and the target
19862system is remote then @value{GDBN} will retrieve the target binaries
19863from the remote system. This is only supported when using a remote
19864target that supports the @code{remote get} command (@pxref{File
19865Transfer,,Sending files to a remote system}). The part of @var{path}
19866following the initial @file{target:} (if present) is used as system
19867root prefix on the remote file system. If @var{path} starts with the
19868sequence @file{remote:} this is converted to the sequence
19869@file{target:} by @code{set sysroot}@footnote{Historically the
19870functionality to retrieve binaries from the remote system was
19871provided by prefixing @var{path} with @file{remote:}}. If you want
19872to specify a local system root using a directory that happens to be
19873named @file{target:} or @file{remote:}, you need to use some
19874equivalent variant of the name like @file{./target:}.
f1838a98 19875
ab38a727
PA
19876For targets with an MS-DOS based filesystem, such as MS-Windows and
19877SymbianOS, @value{GDBN} tries prefixing a few variants of the target
19878absolute file name with @var{path}. But first, on Unix hosts,
19879@value{GDBN} converts all backslash directory separators into forward
19880slashes, because the backslash is not a directory separator on Unix:
19881
19882@smallexample
19883 c:\foo\bar.dll @result{} c:/foo/bar.dll
19884@end smallexample
19885
19886Then, @value{GDBN} attempts prefixing the target file name with
19887@var{path}, and looks for the resulting file name in the host file
19888system:
19889
19890@smallexample
19891 c:/foo/bar.dll @result{} /path/to/sysroot/c:/foo/bar.dll
19892@end smallexample
19893
a9a5a3d1 19894If that does not find the binary, @value{GDBN} tries removing
ab38a727
PA
19895the @samp{:} character from the drive spec, both for convenience, and,
19896for the case of the host file system not supporting file names with
19897colons:
19898
19899@smallexample
19900 c:/foo/bar.dll @result{} /path/to/sysroot/c/foo/bar.dll
19901@end smallexample
19902
19903This makes it possible to have a system root that mirrors a target
19904with more than one drive. E.g., you may want to setup your local
19905copies of the target system shared libraries like so (note @samp{c} vs
19906@samp{z}):
19907
19908@smallexample
19909 @file{/path/to/sysroot/c/sys/bin/foo.dll}
19910 @file{/path/to/sysroot/c/sys/bin/bar.dll}
19911 @file{/path/to/sysroot/z/sys/bin/bar.dll}
19912@end smallexample
19913
19914@noindent
19915and point the system root at @file{/path/to/sysroot}, so that
19916@value{GDBN} can find the correct copies of both
19917@file{c:\sys\bin\foo.dll}, and @file{z:\sys\bin\bar.dll}.
19918
a9a5a3d1 19919If that still does not find the binary, @value{GDBN} tries
ab38a727
PA
19920removing the whole drive spec from the target file name:
19921
19922@smallexample
19923 c:/foo/bar.dll @result{} /path/to/sysroot/foo/bar.dll
19924@end smallexample
19925
19926This last lookup makes it possible to not care about the drive name,
19927if you don't want or need to.
19928
f822c95b
DJ
19929The @code{set solib-absolute-prefix} command is an alias for @code{set
19930sysroot}.
19931
19932@cindex default system root
59b7b46f 19933@cindex @samp{--with-sysroot}
f822c95b
DJ
19934You can set the default system root by using the configure-time
19935@samp{--with-sysroot} option. If the system root is inside
19936@value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
19937@samp{--exec-prefix}), then the default system root will be updated
19938automatically if the installed @value{GDBN} is moved to a new
19939location.
19940
19941@kindex show sysroot
19942@item show sysroot
a9a5a3d1 19943Display the current executable and shared library prefix.
f5ebfba0
DJ
19944
19945@kindex set solib-search-path
19946@item set solib-search-path @var{path}
f822c95b
DJ
19947If this variable is set, @var{path} is a colon-separated list of
19948directories to search for shared libraries. @samp{solib-search-path}
19949is used after @samp{sysroot} fails to locate the library, or if the
19950path to the library is relative instead of absolute. If you want to
19951use @samp{solib-search-path} instead of @samp{sysroot}, be sure to set
d3e8051b 19952@samp{sysroot} to a nonexistent directory to prevent @value{GDBN} from
f822c95b 19953finding your host's libraries. @samp{sysroot} is preferred; setting
d3e8051b 19954it to a nonexistent directory may interfere with automatic loading
f822c95b 19955of shared library symbols.
f5ebfba0
DJ
19956
19957@kindex show solib-search-path
19958@item show solib-search-path
19959Display the current shared library search path.
ab38a727
PA
19960
19961@cindex DOS file-name semantics of file names.
19962@kindex set target-file-system-kind (unix|dos-based|auto)
19963@kindex show target-file-system-kind
19964@item set target-file-system-kind @var{kind}
19965Set assumed file system kind for target reported file names.
19966
19967Shared library file names as reported by the target system may not
19968make sense as is on the system @value{GDBN} is running on. For
19969example, when remote debugging a target that has MS-DOS based file
19970system semantics, from a Unix host, the target may be reporting to
19971@value{GDBN} a list of loaded shared libraries with file names such as
19972@file{c:\Windows\kernel32.dll}. On Unix hosts, there's no concept of
19973drive letters, so the @samp{c:\} prefix is not normally understood as
19974indicating an absolute file name, and neither is the backslash
19975normally considered a directory separator character. In that case,
19976the native file system would interpret this whole absolute file name
19977as a relative file name with no directory components. This would make
19978it impossible to point @value{GDBN} at a copy of the remote target's
19979shared libraries on the host using @code{set sysroot}, and impractical
19980with @code{set solib-search-path}. Setting
19981@code{target-file-system-kind} to @code{dos-based} tells @value{GDBN}
19982to interpret such file names similarly to how the target would, and to
19983map them to file names valid on @value{GDBN}'s native file system
19984semantics. The value of @var{kind} can be @code{"auto"}, in addition
19985to one of the supported file system kinds. In that case, @value{GDBN}
19986tries to determine the appropriate file system variant based on the
19987current target's operating system (@pxref{ABI, ,Configuring the
19988Current ABI}). The supported file system settings are:
19989
19990@table @code
19991@item unix
19992Instruct @value{GDBN} to assume the target file system is of Unix
19993kind. Only file names starting the forward slash (@samp{/}) character
19994are considered absolute, and the directory separator character is also
19995the forward slash.
19996
19997@item dos-based
19998Instruct @value{GDBN} to assume the target file system is DOS based.
19999File names starting with either a forward slash, or a drive letter
20000followed by a colon (e.g., @samp{c:}), are considered absolute, and
20001both the slash (@samp{/}) and the backslash (@samp{\\}) characters are
20002considered directory separators.
20003
20004@item auto
20005Instruct @value{GDBN} to use the file system kind associated with the
20006target operating system (@pxref{ABI, ,Configuring the Current ABI}).
20007This is the default.
20008@end table
f5ebfba0
DJ
20009@end table
20010
c011a4f4
DE
20011@cindex file name canonicalization
20012@cindex base name differences
20013When processing file names provided by the user, @value{GDBN}
20014frequently needs to compare them to the file names recorded in the
20015program's debug info. Normally, @value{GDBN} compares just the
20016@dfn{base names} of the files as strings, which is reasonably fast
20017even for very large programs. (The base name of a file is the last
20018portion of its name, after stripping all the leading directories.)
20019This shortcut in comparison is based upon the assumption that files
20020cannot have more than one base name. This is usually true, but
20021references to files that use symlinks or similar filesystem
20022facilities violate that assumption. If your program records files
20023using such facilities, or if you provide file names to @value{GDBN}
20024using symlinks etc., you can set @code{basenames-may-differ} to
20025@code{true} to instruct @value{GDBN} to completely canonicalize each
20026pair of file names it needs to compare. This will make file-name
20027comparisons accurate, but at a price of a significant slowdown.
20028
20029@table @code
20030@item set basenames-may-differ
20031@kindex set basenames-may-differ
20032Set whether a source file may have multiple base names.
20033
20034@item show basenames-may-differ
20035@kindex show basenames-may-differ
20036Show whether a source file may have multiple base names.
20037@end table
5b5d99cf 20038
18989b3c
AB
20039@node File Caching
20040@section File Caching
20041@cindex caching of opened files
20042@cindex caching of bfd objects
20043
20044To speed up file loading, and reduce memory usage, @value{GDBN} will
20045reuse the @code{bfd} objects used to track open files. @xref{Top, ,
20046BFD, bfd, The Binary File Descriptor Library}. The following commands
20047allow visibility and control of the caching behavior.
20048
20049@table @code
20050@kindex maint info bfds
20051@item maint info bfds
20052This prints information about each @code{bfd} object that is known to
20053@value{GDBN}.
20054
20055@kindex maint set bfd-sharing
20056@kindex maint show bfd-sharing
20057@kindex bfd caching
20058@item maint set bfd-sharing
20059@item maint show bfd-sharing
20060Control whether @code{bfd} objects can be shared. When sharing is
20061enabled @value{GDBN} reuses already open @code{bfd} objects rather
20062than reopening the same file. Turning sharing off does not cause
20063already shared @code{bfd} objects to be unshared, but all future files
20064that are opened will create a new @code{bfd} object. Similarly,
20065re-enabling sharing does not cause multiple existing @code{bfd}
20066objects to be collapsed into a single shared @code{bfd} object.
566f5e3b
AB
20067
20068@kindex set debug bfd-cache @var{level}
20069@kindex bfd caching
20070@item set debug bfd-cache @var{level}
20071Turns on debugging of the bfd cache, setting the level to @var{level}.
20072
20073@kindex show debug bfd-cache
20074@kindex bfd caching
20075@item show debug bfd-cache
20076Show the current debugging level of the bfd cache.
18989b3c
AB
20077@end table
20078
5b5d99cf
JB
20079@node Separate Debug Files
20080@section Debugging Information in Separate Files
20081@cindex separate debugging information files
20082@cindex debugging information in separate files
20083@cindex @file{.debug} subdirectories
20084@cindex debugging information directory, global
f307c045 20085@cindex global debugging information directories
c7e83d54
EZ
20086@cindex build ID, and separate debugging files
20087@cindex @file{.build-id} directory
5b5d99cf
JB
20088
20089@value{GDBN} allows you to put a program's debugging information in a
20090file separate from the executable itself, in a way that allows
20091@value{GDBN} to find and load the debugging information automatically.
c7e83d54
EZ
20092Since debugging information can be very large---sometimes larger
20093than the executable code itself---some systems distribute debugging
5b5d99cf
JB
20094information for their executables in separate files, which users can
20095install only when they need to debug a problem.
20096
c7e83d54
EZ
20097@value{GDBN} supports two ways of specifying the separate debug info
20098file:
5b5d99cf
JB
20099
20100@itemize @bullet
20101@item
c7e83d54
EZ
20102The executable contains a @dfn{debug link} that specifies the name of
20103the separate debug info file. The separate debug file's name is
20104usually @file{@var{executable}.debug}, where @var{executable} is the
20105name of the corresponding executable file without leading directories
20106(e.g., @file{ls.debug} for @file{/usr/bin/ls}). In addition, the
99e008fe
EZ
20107debug link specifies a 32-bit @dfn{Cyclic Redundancy Check} (CRC)
20108checksum for the debug file, which @value{GDBN} uses to validate that
20109the executable and the debug file came from the same build.
c7e83d54
EZ
20110
20111@item
7e27a47a 20112The executable contains a @dfn{build ID}, a unique bit string that is
c7e83d54 20113also present in the corresponding debug info file. (This is supported
c74f7d1c 20114only on some operating systems, when using the ELF or PE file formats
7e27a47a
EZ
20115for binary files and the @sc{gnu} Binutils.) For more details about
20116this feature, see the description of the @option{--build-id}
f5a476a7 20117command-line option in @ref{Options, , Command Line Options, ld,
7e27a47a
EZ
20118The GNU Linker}. The debug info file's name is not specified
20119explicitly by the build ID, but can be computed from the build ID, see
20120below.
d3750b24
JK
20121@end itemize
20122
c7e83d54
EZ
20123Depending on the way the debug info file is specified, @value{GDBN}
20124uses two different methods of looking for the debug file:
d3750b24
JK
20125
20126@itemize @bullet
20127@item
c7e83d54
EZ
20128For the ``debug link'' method, @value{GDBN} looks up the named file in
20129the directory of the executable file, then in a subdirectory of that
5f2459c2
EZ
20130directory named @file{.debug}, and finally under each one of the
20131global debug directories, in a subdirectory whose name is identical to
20132the leading directories of the executable's absolute file name. (On
20133MS-Windows/MS-DOS, the drive letter of the executable's leading
20134directories is converted to a one-letter subdirectory, i.e.@:
20135@file{d:/usr/bin/} is converted to @file{/d/usr/bin/}, because Windows
20136filesystems disallow colons in file names.)
c7e83d54
EZ
20137
20138@item
83f83d7f 20139For the ``build ID'' method, @value{GDBN} looks in the
f307c045
JK
20140@file{.build-id} subdirectory of each one of the global debug directories for
20141a file named @file{@var{nn}/@var{nnnnnnnn}.debug}, where @var{nn} are the
7e27a47a
EZ
20142first 2 hex characters of the build ID bit string, and @var{nnnnnnnn}
20143are the rest of the bit string. (Real build ID strings are 32 or more
20144hex characters, not 10.)
c7e83d54
EZ
20145@end itemize
20146
20147So, for example, suppose you ask @value{GDBN} to debug
7e27a47a
EZ
20148@file{/usr/bin/ls}, which has a debug link that specifies the
20149file @file{ls.debug}, and a build ID whose value in hex is
f307c045 20150@code{abcdef1234}. If the list of the global debug directories includes
c7e83d54
EZ
20151@file{/usr/lib/debug}, then @value{GDBN} will look for the following
20152debug information files, in the indicated order:
20153
20154@itemize @minus
20155@item
20156@file{/usr/lib/debug/.build-id/ab/cdef1234.debug}
d3750b24 20157@item
c7e83d54 20158@file{/usr/bin/ls.debug}
5b5d99cf 20159@item
c7e83d54 20160@file{/usr/bin/.debug/ls.debug}
5b5d99cf 20161@item
c7e83d54 20162@file{/usr/lib/debug/usr/bin/ls.debug}.
5b5d99cf 20163@end itemize
5b5d99cf 20164
1564a261
JK
20165@anchor{debug-file-directory}
20166Global debugging info directories default to what is set by @value{GDBN}
20167configure option @option{--with-separate-debug-dir}. During @value{GDBN} run
20168you can also set the global debugging info directories, and view the list
20169@value{GDBN} is currently using.
5b5d99cf
JB
20170
20171@table @code
20172
20173@kindex set debug-file-directory
24ddea62
JK
20174@item set debug-file-directory @var{directories}
20175Set the directories which @value{GDBN} searches for separate debugging
d9242c17
JK
20176information files to @var{directory}. Multiple path components can be set
20177concatenating them by a path separator.
5b5d99cf
JB
20178
20179@kindex show debug-file-directory
20180@item show debug-file-directory
24ddea62 20181Show the directories @value{GDBN} searches for separate debugging
5b5d99cf
JB
20182information files.
20183
20184@end table
20185
20186@cindex @code{.gnu_debuglink} sections
c7e83d54 20187@cindex debug link sections
5b5d99cf
JB
20188A debug link is a special section of the executable file named
20189@code{.gnu_debuglink}. The section must contain:
20190
20191@itemize
20192@item
20193A filename, with any leading directory components removed, followed by
20194a zero byte,
20195@item
20196zero to three bytes of padding, as needed to reach the next four-byte
20197boundary within the section, and
20198@item
20199a four-byte CRC checksum, stored in the same endianness used for the
20200executable file itself. The checksum is computed on the debugging
20201information file's full contents by the function given below, passing
20202zero as the @var{crc} argument.
20203@end itemize
20204
20205Any executable file format can carry a debug link, as long as it can
20206contain a section named @code{.gnu_debuglink} with the contents
20207described above.
20208
d3750b24 20209@cindex @code{.note.gnu.build-id} sections
c7e83d54 20210@cindex build ID sections
7e27a47a
EZ
20211The build ID is a special section in the executable file (and in other
20212ELF binary files that @value{GDBN} may consider). This section is
20213often named @code{.note.gnu.build-id}, but that name is not mandatory.
20214It contains unique identification for the built files---the ID remains
20215the same across multiple builds of the same build tree. The default
20216algorithm SHA1 produces 160 bits (40 hexadecimal characters) of the
20217content for the build ID string. The same section with an identical
20218value is present in the original built binary with symbols, in its
20219stripped variant, and in the separate debugging information file.
d3750b24 20220
5b5d99cf
JB
20221The debugging information file itself should be an ordinary
20222executable, containing a full set of linker symbols, sections, and
20223debugging information. The sections of the debugging information file
c7e83d54
EZ
20224should have the same names, addresses, and sizes as the original file,
20225but they need not contain any data---much like a @code{.bss} section
5b5d99cf
JB
20226in an ordinary executable.
20227
7e27a47a 20228The @sc{gnu} binary utilities (Binutils) package includes the
c7e83d54
EZ
20229@samp{objcopy} utility that can produce
20230the separated executable / debugging information file pairs using the
20231following commands:
20232
20233@smallexample
20234@kbd{objcopy --only-keep-debug foo foo.debug}
20235@kbd{strip -g foo}
c7e83d54
EZ
20236@end smallexample
20237
20238@noindent
20239These commands remove the debugging
83f83d7f
JK
20240information from the executable file @file{foo} and place it in the file
20241@file{foo.debug}. You can use the first, second or both methods to link the
20242two files:
20243
20244@itemize @bullet
20245@item
20246The debug link method needs the following additional command to also leave
20247behind a debug link in @file{foo}:
20248
20249@smallexample
20250@kbd{objcopy --add-gnu-debuglink=foo.debug foo}
20251@end smallexample
20252
20253Ulrich Drepper's @file{elfutils} package, starting with version 0.53, contains
d3750b24 20254a version of the @code{strip} command such that the command @kbd{strip foo -f
83f83d7f
JK
20255foo.debug} has the same functionality as the two @code{objcopy} commands and
20256the @code{ln -s} command above, together.
20257
20258@item
20259Build ID gets embedded into the main executable using @code{ld --build-id} or
20260the @value{NGCC} counterpart @code{gcc -Wl,--build-id}. Build ID support plus
20261compatibility fixes for debug files separation are present in @sc{gnu} binary
7e27a47a 20262utilities (Binutils) package since version 2.18.
83f83d7f
JK
20263@end itemize
20264
20265@noindent
d3750b24 20266
99e008fe
EZ
20267@cindex CRC algorithm definition
20268The CRC used in @code{.gnu_debuglink} is the CRC-32 defined in
20269IEEE 802.3 using the polynomial:
20270
20271@c TexInfo requires naked braces for multi-digit exponents for Tex
20272@c output, but this causes HTML output to barf. HTML has to be set using
20273@c raw commands. So we end up having to specify this equation in 2
20274@c different ways!
20275@ifhtml
20276@display
20277@html
20278 <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>
20279 + <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
20280@end html
20281@end display
20282@end ifhtml
20283@ifnothtml
20284@display
20285 @math{x^{32} + x^{26} + x^{23} + x^{22} + x^{16} + x^{12} + x^{11}}
20286 @math{+ x^{10} + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1}
20287@end display
20288@end ifnothtml
20289
20290The function is computed byte at a time, taking the least
20291significant bit of each byte first. The initial pattern
20292@code{0xffffffff} is used, to ensure leading zeros affect the CRC and
20293the final result is inverted to ensure trailing zeros also affect the
20294CRC.
20295
20296@emph{Note:} This is the same CRC polynomial as used in handling the
936d2992
PA
20297@dfn{Remote Serial Protocol} @code{qCRC} packet (@pxref{qCRC packet}).
20298However in the case of the Remote Serial Protocol, the CRC is computed
20299@emph{most} significant bit first, and the result is not inverted, so
20300trailing zeros have no effect on the CRC value.
99e008fe
EZ
20301
20302To complete the description, we show below the code of the function
20303which produces the CRC used in @code{.gnu_debuglink}. Inverting the
20304initially supplied @code{crc} argument means that an initial call to
20305this function passing in zero will start computing the CRC using
20306@code{0xffffffff}.
5b5d99cf 20307
4644b6e3 20308@kindex gnu_debuglink_crc32
5b5d99cf
JB
20309@smallexample
20310unsigned long
20311gnu_debuglink_crc32 (unsigned long crc,
20312 unsigned char *buf, size_t len)
20313@{
20314 static const unsigned long crc32_table[256] =
20315 @{
20316 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
20317 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
20318 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
20319 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
20320 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
20321 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
20322 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
20323 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
20324 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
20325 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
20326 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
20327 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
20328 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
20329 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
20330 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
20331 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
20332 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
20333 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
20334 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
20335 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
20336 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
20337 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
20338 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
20339 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
20340 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
20341 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
20342 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
20343 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
20344 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
20345 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
20346 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
20347 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
20348 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
20349 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
20350 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
20351 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
20352 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
20353 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
20354 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
20355 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
20356 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
20357 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
20358 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
20359 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
20360 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
20361 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
20362 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
20363 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
20364 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
20365 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
20366 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
20367 0x2d02ef8d
20368 @};
20369 unsigned char *end;
20370
20371 crc = ~crc & 0xffffffff;
20372 for (end = buf + len; buf < end; ++buf)
20373 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
e7a3abfc 20374 return ~crc & 0xffffffff;
5b5d99cf
JB
20375@}
20376@end smallexample
20377
c7e83d54
EZ
20378@noindent
20379This computation does not apply to the ``build ID'' method.
20380
608e2dbb
TT
20381@node MiniDebugInfo
20382@section Debugging information in a special section
20383@cindex separate debug sections
20384@cindex @samp{.gnu_debugdata} section
20385
20386Some systems ship pre-built executables and libraries that have a
20387special @samp{.gnu_debugdata} section. This feature is called
20388@dfn{MiniDebugInfo}. This section holds an LZMA-compressed object and
20389is used to supply extra symbols for backtraces.
20390
20391The intent of this section is to provide extra minimal debugging
20392information for use in simple backtraces. It is not intended to be a
20393replacement for full separate debugging information (@pxref{Separate
20394Debug Files}). The example below shows the intended use; however,
20395@value{GDBN} does not currently put restrictions on what sort of
20396debugging information might be included in the section.
20397
20398@value{GDBN} has support for this extension. If the section exists,
20399then it is used provided that no other source of debugging information
20400can be found, and that @value{GDBN} was configured with LZMA support.
20401
20402This section can be easily created using @command{objcopy} and other
20403standard utilities:
20404
20405@smallexample
20406# Extract the dynamic symbols from the main binary, there is no need
5423b017 20407# to also have these in the normal symbol table.
608e2dbb
TT
20408nm -D @var{binary} --format=posix --defined-only \
20409 | awk '@{ print $1 @}' | sort > dynsyms
20410
5423b017 20411# Extract all the text (i.e. function) symbols from the debuginfo.
1d236d23
JK
20412# (Note that we actually also accept "D" symbols, for the benefit
20413# of platforms like PowerPC64 that use function descriptors.)
608e2dbb 20414nm @var{binary} --format=posix --defined-only \
1d236d23 20415 | awk '@{ if ($2 == "T" || $2 == "t" || $2 == "D") print $1 @}' \
608e2dbb
TT
20416 | sort > funcsyms
20417
20418# Keep all the function symbols not already in the dynamic symbol
20419# table.
20420comm -13 dynsyms funcsyms > keep_symbols
20421
edf9f00c
JK
20422# Separate full debug info into debug binary.
20423objcopy --only-keep-debug @var{binary} debug
20424
608e2dbb
TT
20425# Copy the full debuginfo, keeping only a minimal set of symbols and
20426# removing some unnecessary sections.
20427objcopy -S --remove-section .gdb_index --remove-section .comment \
edf9f00c
JK
20428 --keep-symbols=keep_symbols debug mini_debuginfo
20429
20430# Drop the full debug info from the original binary.
20431strip --strip-all -R .comment @var{binary}
608e2dbb
TT
20432
20433# Inject the compressed data into the .gnu_debugdata section of the
20434# original binary.
20435xz mini_debuginfo
20436objcopy --add-section .gnu_debugdata=mini_debuginfo.xz @var{binary}
20437@end smallexample
5b5d99cf 20438
9291a0cd
TT
20439@node Index Files
20440@section Index Files Speed Up @value{GDBN}
20441@cindex index files
20442@cindex @samp{.gdb_index} section
20443
20444When @value{GDBN} finds a symbol file, it scans the symbols in the
20445file in order to construct an internal symbol table. This lets most
20446@value{GDBN} operations work quickly---at the cost of a delay early
20447on. For large programs, this delay can be quite lengthy, so
20448@value{GDBN} provides a way to build an index, which speeds up
20449startup.
20450
ba643918
SDJ
20451For convenience, @value{GDBN} comes with a program,
20452@command{gdb-add-index}, which can be used to add the index to a
20453symbol file. It takes the symbol file as its only argument:
20454
20455@smallexample
20456$ gdb-add-index symfile
20457@end smallexample
20458
20459@xref{gdb-add-index}.
20460
20461It is also possible to do the work manually. Here is what
20462@command{gdb-add-index} does behind the curtains.
20463
9291a0cd
TT
20464The index is stored as a section in the symbol file. @value{GDBN} can
20465write the index to a file, then you can put it into the symbol file
20466using @command{objcopy}.
20467
20468To create an index file, use the @code{save gdb-index} command:
20469
20470@table @code
437afbb8 20471@item save gdb-index [-dwarf-5] @var{directory}
9291a0cd 20472@kindex save gdb-index
437afbb8
JK
20473Create index files for all symbol files currently known by
20474@value{GDBN}. For each known @var{symbol-file}, this command by
20475default creates it produces a single file
20476@file{@var{symbol-file}.gdb-index}. If you invoke this command with
20477the @option{-dwarf-5} option, it produces 2 files:
20478@file{@var{symbol-file}.debug_names} and
20479@file{@var{symbol-file}.debug_str}. The files are created in the
20480given @var{directory}.
9291a0cd
TT
20481@end table
20482
20483Once you have created an index file you can merge it into your symbol
20484file, here named @file{symfile}, using @command{objcopy}:
20485
20486@smallexample
20487$ objcopy --add-section .gdb_index=symfile.gdb-index \
20488 --set-section-flags .gdb_index=readonly symfile symfile
20489@end smallexample
20490
437afbb8
JK
20491Or for @code{-dwarf-5}:
20492
20493@smallexample
20494$ objcopy --dump-section .debug_str=symfile.debug_str.new symfile
20495$ cat symfile.debug_str >>symfile.debug_str.new
20496$ objcopy --add-section .debug_names=symfile.gdb-index \
20497 --set-section-flags .debug_names=readonly \
20498 --update-section .debug_str=symfile.debug_str.new symfile symfile
20499@end smallexample
20500
e615022a
DE
20501@value{GDBN} will normally ignore older versions of @file{.gdb_index}
20502sections that have been deprecated. Usually they are deprecated because
20503they are missing a new feature or have performance issues.
20504To tell @value{GDBN} to use a deprecated index section anyway
20505specify @code{set use-deprecated-index-sections on}.
20506The default is @code{off}.
20507This can speed up startup, but may result in some functionality being lost.
20508@xref{Index Section Format}.
20509
20510@emph{Warning:} Setting @code{use-deprecated-index-sections} to @code{on}
20511must be done before gdb reads the file. The following will not work:
20512
20513@smallexample
20514$ gdb -ex "set use-deprecated-index-sections on" <program>
20515@end smallexample
20516
20517Instead you must do, for example,
20518
20519@smallexample
20520$ gdb -iex "set use-deprecated-index-sections on" <program>
20521@end smallexample
20522
9291a0cd
TT
20523There are currently some limitation on indices. They only work when
20524for DWARF debugging information, not stabs. And, they do not
20525currently work for programs using Ada.
20526
7d11235d
SM
20527@subsection Automatic symbol index cache
20528
a0a3a1e9 20529@cindex automatic symbol index cache
7d11235d
SM
20530It is possible for @value{GDBN} to automatically save a copy of this index in a
20531cache on disk and retrieve it from there when loading the same binary in the
20532future. This feature can be turned on with @kbd{set index-cache on}. The
20533following commands can be used to tweak the behavior of the index cache.
20534
20535@table @code
20536
a0a3a1e9 20537@kindex set index-cache
7d11235d
SM
20538@item set index-cache on
20539@itemx set index-cache off
20540Enable or disable the use of the symbol index cache.
20541
20542@item set index-cache directory @var{directory}
a0a3a1e9 20543@kindex show index-cache
7d11235d 20544@itemx show index-cache directory
e6cd1dc1
TT
20545Set/show the directory where index files will be saved.
20546
20547The default value for this directory depends on the host platform. On
20548most systems, the index is cached in the @file{gdb} subdirectory of
20549the directory pointed to by the @env{XDG_CACHE_HOME} environment
20550variable, if it is defined, else in the @file{.cache/gdb} subdirectory
20551of your home directory. However, on some systems, the default may
20552differ according to local convention.
7d11235d
SM
20553
20554There is no limit on the disk space used by index cache. It is perfectly safe
20555to delete the content of that directory to free up disk space.
20556
20557@item show index-cache stats
20558Print the number of cache hits and misses since the launch of @value{GDBN}.
20559
20560@end table
20561
6d2ebf8b 20562@node Symbol Errors
79a6e687 20563@section Errors Reading Symbol Files
c906108c
SS
20564
20565While reading a symbol file, @value{GDBN} occasionally encounters problems,
20566such as symbol types it does not recognize, or known bugs in compiler
20567output. By default, @value{GDBN} does not notify you of such problems, since
20568they are relatively common and primarily of interest to people
20569debugging compilers. If you are interested in seeing information
20570about ill-constructed symbol tables, you can either ask @value{GDBN} to print
20571only one message about each such type of problem, no matter how many
20572times the problem occurs; or you can ask @value{GDBN} to print more messages,
20573to see how many times the problems occur, with the @code{set
79a6e687
BW
20574complaints} command (@pxref{Messages/Warnings, ,Optional Warnings and
20575Messages}).
c906108c
SS
20576
20577The messages currently printed, and their meanings, include:
20578
20579@table @code
20580@item inner block not inside outer block in @var{symbol}
20581
20582The symbol information shows where symbol scopes begin and end
20583(such as at the start of a function or a block of statements). This
20584error indicates that an inner scope block is not fully contained
20585in its outer scope blocks.
20586
20587@value{GDBN} circumvents the problem by treating the inner block as if it had
20588the same scope as the outer block. In the error message, @var{symbol}
20589may be shown as ``@code{(don't know)}'' if the outer block is not a
20590function.
20591
20592@item block at @var{address} out of order
20593
20594The symbol information for symbol scope blocks should occur in
20595order of increasing addresses. This error indicates that it does not
20596do so.
20597
20598@value{GDBN} does not circumvent this problem, and has trouble
20599locating symbols in the source file whose symbols it is reading. (You
20600can often determine what source file is affected by specifying
79a6e687
BW
20601@code{set verbose on}. @xref{Messages/Warnings, ,Optional Warnings and
20602Messages}.)
c906108c
SS
20603
20604@item bad block start address patched
20605
20606The symbol information for a symbol scope block has a start address
20607smaller than the address of the preceding source line. This is known
20608to occur in the SunOS 4.1.1 (and earlier) C compiler.
20609
20610@value{GDBN} circumvents the problem by treating the symbol scope block as
20611starting on the previous source line.
20612
20613@item bad string table offset in symbol @var{n}
20614
20615@cindex foo
20616Symbol number @var{n} contains a pointer into the string table which is
20617larger than the size of the string table.
20618
20619@value{GDBN} circumvents the problem by considering the symbol to have the
20620name @code{foo}, which may cause other problems if many symbols end up
20621with this name.
20622
20623@item unknown symbol type @code{0x@var{nn}}
20624
7a292a7a
SS
20625The symbol information contains new data types that @value{GDBN} does
20626not yet know how to read. @code{0x@var{nn}} is the symbol type of the
d4f3574e 20627uncomprehended information, in hexadecimal.
c906108c 20628
7a292a7a
SS
20629@value{GDBN} circumvents the error by ignoring this symbol information.
20630This usually allows you to debug your program, though certain symbols
c906108c 20631are not accessible. If you encounter such a problem and feel like
7a292a7a
SS
20632debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
20633on @code{complain}, then go up to the function @code{read_dbx_symtab}
20634and examine @code{*bufp} to see the symbol.
c906108c
SS
20635
20636@item stub type has NULL name
c906108c 20637
7a292a7a 20638@value{GDBN} could not find the full definition for a struct or class.
c906108c 20639
7a292a7a 20640@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
b37052ae 20641The symbol information for a C@t{++} member function is missing some
7a292a7a
SS
20642information that recent versions of the compiler should have output for
20643it.
c906108c
SS
20644
20645@item info mismatch between compiler and debugger
20646
20647@value{GDBN} could not parse a type specification output by the compiler.
7a292a7a 20648
c906108c
SS
20649@end table
20650
b14b1491
TT
20651@node Data Files
20652@section GDB Data Files
20653
20654@cindex prefix for data files
20655@value{GDBN} will sometimes read an auxiliary data file. These files
20656are kept in a directory known as the @dfn{data directory}.
20657
20658You can set the data directory's name, and view the name @value{GDBN}
20659is currently using.
20660
20661@table @code
20662@kindex set data-directory
20663@item set data-directory @var{directory}
20664Set the directory which @value{GDBN} searches for auxiliary data files
20665to @var{directory}.
20666
20667@kindex show data-directory
20668@item show data-directory
20669Show the directory @value{GDBN} searches for auxiliary data files.
20670@end table
20671
20672@cindex default data directory
20673@cindex @samp{--with-gdb-datadir}
20674You can set the default data directory by using the configure-time
20675@samp{--with-gdb-datadir} option. If the data directory is inside
20676@value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
20677@samp{--exec-prefix}), then the default data directory will be updated
20678automatically if the installed @value{GDBN} is moved to a new
20679location.
20680
aae1c79a
DE
20681The data directory may also be specified with the
20682@code{--data-directory} command line option.
20683@xref{Mode Options}.
20684
6d2ebf8b 20685@node Targets
c906108c 20686@chapter Specifying a Debugging Target
7a292a7a 20687
c906108c 20688@cindex debugging target
c906108c 20689A @dfn{target} is the execution environment occupied by your program.
53a5351d
JM
20690
20691Often, @value{GDBN} runs in the same host environment as your program;
20692in that case, the debugging target is specified as a side effect when
20693you use the @code{file} or @code{core} commands. When you need more
c906108c
SS
20694flexibility---for example, running @value{GDBN} on a physically separate
20695host, or controlling a standalone system over a serial port or a
53a5351d
JM
20696realtime system over a TCP/IP connection---you can use the @code{target}
20697command to specify one of the target types configured for @value{GDBN}
79a6e687 20698(@pxref{Target Commands, ,Commands for Managing Targets}).
c906108c 20699
a8f24a35
EZ
20700@cindex target architecture
20701It is possible to build @value{GDBN} for several different @dfn{target
20702architectures}. When @value{GDBN} is built like that, you can choose
20703one of the available architectures with the @kbd{set architecture}
20704command.
20705
20706@table @code
20707@kindex set architecture
20708@kindex show architecture
20709@item set architecture @var{arch}
20710This command sets the current target architecture to @var{arch}. The
20711value of @var{arch} can be @code{"auto"}, in addition to one of the
20712supported architectures.
20713
20714@item show architecture
20715Show the current target architecture.
9c16f35a
EZ
20716
20717@item set processor
20718@itemx processor
20719@kindex set processor
20720@kindex show processor
20721These are alias commands for, respectively, @code{set architecture}
20722and @code{show architecture}.
a8f24a35
EZ
20723@end table
20724
c906108c
SS
20725@menu
20726* Active Targets:: Active targets
20727* Target Commands:: Commands for managing targets
c906108c 20728* Byte Order:: Choosing target byte order
c906108c
SS
20729@end menu
20730
6d2ebf8b 20731@node Active Targets
79a6e687 20732@section Active Targets
7a292a7a 20733
c906108c
SS
20734@cindex stacking targets
20735@cindex active targets
20736@cindex multiple targets
20737
8ea5bce5 20738There are multiple classes of targets such as: processes, executable files or
c0edd9ed
JK
20739recording sessions. Core files belong to the process class, making core file
20740and process mutually exclusive. Otherwise, @value{GDBN} can work concurrently
20741on multiple active targets, one in each class. This allows you to (for
20742example) start a process and inspect its activity, while still having access to
20743the executable file after the process finishes. Or if you start process
20744recording (@pxref{Reverse Execution}) and @code{reverse-step} there, you are
20745presented a virtual layer of the recording target, while the process target
20746remains stopped at the chronologically last point of the process execution.
20747
20748Use the @code{core-file} and @code{exec-file} commands to select a new core
20749file or executable target (@pxref{Files, ,Commands to Specify Files}). To
20750specify as a target a process that is already running, use the @code{attach}
20751command (@pxref{Attach, ,Debugging an Already-running Process}).
c906108c 20752
6d2ebf8b 20753@node Target Commands
79a6e687 20754@section Commands for Managing Targets
c906108c
SS
20755
20756@table @code
20757@item target @var{type} @var{parameters}
7a292a7a
SS
20758Connects the @value{GDBN} host environment to a target machine or
20759process. A target is typically a protocol for talking to debugging
20760facilities. You use the argument @var{type} to specify the type or
20761protocol of the target machine.
c906108c
SS
20762
20763Further @var{parameters} are interpreted by the target protocol, but
20764typically include things like device names or host names to connect
20765with, process numbers, and baud rates.
c906108c
SS
20766
20767The @code{target} command does not repeat if you press @key{RET} again
20768after executing the command.
20769
20770@kindex help target
20771@item help target
20772Displays the names of all targets available. To display targets
20773currently selected, use either @code{info target} or @code{info files}
79a6e687 20774(@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
20775
20776@item help target @var{name}
20777Describe a particular target, including any parameters necessary to
20778select it.
20779
20780@kindex set gnutarget
20781@item set gnutarget @var{args}
5d161b24 20782@value{GDBN} uses its own library BFD to read your files. @value{GDBN}
c906108c 20783knows whether it is reading an @dfn{executable},
5d161b24
DB
20784a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
20785with the @code{set gnutarget} command. Unlike most @code{target} commands,
c906108c
SS
20786with @code{gnutarget} the @code{target} refers to a program, not a machine.
20787
d4f3574e 20788@quotation
c906108c
SS
20789@emph{Warning:} To specify a file format with @code{set gnutarget},
20790you must know the actual BFD name.
d4f3574e 20791@end quotation
c906108c 20792
d4f3574e 20793@noindent
79a6e687 20794@xref{Files, , Commands to Specify Files}.
c906108c 20795
5d161b24 20796@kindex show gnutarget
c906108c
SS
20797@item show gnutarget
20798Use the @code{show gnutarget} command to display what file format
20799@code{gnutarget} is set to read. If you have not set @code{gnutarget},
20800@value{GDBN} will determine the file format for each file automatically,
c4957902 20801and @code{show gnutarget} displays @samp{The current BFD target is "auto"}.
c906108c
SS
20802@end table
20803
4644b6e3 20804@cindex common targets
c906108c
SS
20805Here are some common targets (available, or not, depending on the GDB
20806configuration):
c906108c
SS
20807
20808@table @code
4644b6e3 20809@kindex target
c906108c 20810@item target exec @var{program}
4644b6e3 20811@cindex executable file target
c906108c
SS
20812An executable file. @samp{target exec @var{program}} is the same as
20813@samp{exec-file @var{program}}.
20814
c906108c 20815@item target core @var{filename}
4644b6e3 20816@cindex core dump file target
c906108c
SS
20817A core dump file. @samp{target core @var{filename}} is the same as
20818@samp{core-file @var{filename}}.
c906108c 20819
1a10341b 20820@item target remote @var{medium}
4644b6e3 20821@cindex remote target
1a10341b
JB
20822A remote system connected to @value{GDBN} via a serial line or network
20823connection. This command tells @value{GDBN} to use its own remote
20824protocol over @var{medium} for debugging. @xref{Remote Debugging}.
20825
20826For example, if you have a board connected to @file{/dev/ttya} on the
20827machine running @value{GDBN}, you could say:
20828
20829@smallexample
20830target remote /dev/ttya
20831@end smallexample
20832
20833@code{target remote} supports the @code{load} command. This is only
20834useful if you have some other way of getting the stub to the target
20835system, and you can put it somewhere in memory where it won't get
20836clobbered by the download.
c906108c 20837
ee8e71d4 20838@item target sim @r{[}@var{simargs}@r{]} @dots{}
4644b6e3 20839@cindex built-in simulator target
2df3850c 20840Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
104c1213 20841In general,
474c8240 20842@smallexample
104c1213
JM
20843 target sim
20844 load
20845 run
474c8240 20846@end smallexample
d4f3574e 20847@noindent
104c1213 20848works; however, you cannot assume that a specific memory map, device
d4f3574e 20849drivers, or even basic I/O is available, although some simulators do
104c1213
JM
20850provide these. For info about any processor-specific simulator details,
20851see the appropriate section in @ref{Embedded Processors, ,Embedded
20852Processors}.
20853
6a3cb8e8
PA
20854@item target native
20855@cindex native target
20856Setup for local/native process debugging. Useful to make the
20857@code{run} command spawn native processes (likewise @code{attach},
20858etc.@:) even when @code{set auto-connect-native-target} is @code{off}
20859(@pxref{set auto-connect-native-target}).
20860
c906108c
SS
20861@end table
20862
5d161b24 20863Different targets are available on different configurations of @value{GDBN};
c906108c 20864your configuration may have more or fewer targets.
c906108c 20865
721c2651
EZ
20866Many remote targets require you to download the executable's code once
20867you've successfully established a connection. You may wish to control
3d00d119
DJ
20868various aspects of this process.
20869
20870@table @code
721c2651
EZ
20871
20872@item set hash
20873@kindex set hash@r{, for remote monitors}
20874@cindex hash mark while downloading
20875This command controls whether a hash mark @samp{#} is displayed while
20876downloading a file to the remote monitor. If on, a hash mark is
20877displayed after each S-record is successfully downloaded to the
20878monitor.
20879
20880@item show hash
20881@kindex show hash@r{, for remote monitors}
20882Show the current status of displaying the hash mark.
20883
20884@item set debug monitor
20885@kindex set debug monitor
20886@cindex display remote monitor communications
20887Enable or disable display of communications messages between
20888@value{GDBN} and the remote monitor.
20889
20890@item show debug monitor
20891@kindex show debug monitor
20892Show the current status of displaying communications between
20893@value{GDBN} and the remote monitor.
a8f24a35 20894@end table
c906108c
SS
20895
20896@table @code
20897
5cf30ebf
LM
20898@kindex load @var{filename} @var{offset}
20899@item load @var{filename} @var{offset}
8edfe269 20900@anchor{load}
c906108c
SS
20901Depending on what remote debugging facilities are configured into
20902@value{GDBN}, the @code{load} command may be available. Where it exists, it
20903is meant to make @var{filename} (an executable) available for debugging
20904on the remote system---by downloading, or dynamic linking, for example.
20905@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
20906the @code{add-symbol-file} command.
20907
20908If your @value{GDBN} does not have a @code{load} command, attempting to
20909execute it gets the error message ``@code{You can't do that when your
20910target is @dots{}}''
c906108c
SS
20911
20912The file is loaded at whatever address is specified in the executable.
20913For some object file formats, you can specify the load address when you
20914link the program; for other formats, like a.out, the object file format
20915specifies a fixed address.
20916@c FIXME! This would be a good place for an xref to the GNU linker doc.
20917
5cf30ebf
LM
20918It is also possible to tell @value{GDBN} to load the executable file at a
20919specific offset described by the optional argument @var{offset}. When
20920@var{offset} is provided, @var{filename} must also be provided.
20921
68437a39
DJ
20922Depending on the remote side capabilities, @value{GDBN} may be able to
20923load programs into flash memory.
20924
c906108c
SS
20925@code{load} does not repeat if you press @key{RET} again after using it.
20926@end table
20927
78cbbba8
LM
20928@table @code
20929
20930@kindex flash-erase
20931@item flash-erase
20932@anchor{flash-erase}
20933
20934Erases all known flash memory regions on the target.
20935
20936@end table
20937
6d2ebf8b 20938@node Byte Order
79a6e687 20939@section Choosing Target Byte Order
7a292a7a 20940
c906108c
SS
20941@cindex choosing target byte order
20942@cindex target byte order
c906108c 20943
eb17f351 20944Some types of processors, such as the @acronym{MIPS}, PowerPC, and Renesas SH,
c906108c
SS
20945offer the ability to run either big-endian or little-endian byte
20946orders. Usually the executable or symbol will include a bit to
20947designate the endian-ness, and you will not need to worry about
20948which to use. However, you may still find it useful to adjust
d4f3574e 20949@value{GDBN}'s idea of processor endian-ness manually.
c906108c
SS
20950
20951@table @code
4644b6e3 20952@kindex set endian
c906108c
SS
20953@item set endian big
20954Instruct @value{GDBN} to assume the target is big-endian.
20955
c906108c
SS
20956@item set endian little
20957Instruct @value{GDBN} to assume the target is little-endian.
20958
c906108c
SS
20959@item set endian auto
20960Instruct @value{GDBN} to use the byte order associated with the
20961executable.
20962
20963@item show endian
20964Display @value{GDBN}'s current idea of the target byte order.
20965
20966@end table
20967
4b2dfa9d
MR
20968If the @code{set endian auto} mode is in effect and no executable has
20969been selected, then the endianness used is the last one chosen either
20970by one of the @code{set endian big} and @code{set endian little}
20971commands or by inferring from the last executable used. If no
20972endianness has been previously chosen, then the default for this mode
20973is inferred from the target @value{GDBN} has been built for, and is
20974@code{little} if the name of the target CPU has an @code{el} suffix
20975and @code{big} otherwise.
20976
c906108c
SS
20977Note that these commands merely adjust interpretation of symbolic
20978data on the host, and that they have absolutely no effect on the
20979target system.
20980
ea35711c
DJ
20981
20982@node Remote Debugging
20983@chapter Debugging Remote Programs
c906108c
SS
20984@cindex remote debugging
20985
20986If you are trying to debug a program running on a machine that cannot run
5d161b24
DB
20987@value{GDBN} in the usual way, it is often useful to use remote debugging.
20988For example, you might use remote debugging on an operating system kernel,
c906108c
SS
20989or on a small system which does not have a general purpose operating system
20990powerful enough to run a full-featured debugger.
20991
20992Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
20993to make this work with particular debugging targets. In addition,
5d161b24 20994@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
c906108c
SS
20995but not specific to any particular target system) which you can use if you
20996write the remote stubs---the code that runs on the remote system to
20997communicate with @value{GDBN}.
20998
20999Other remote targets may be available in your
21000configuration of @value{GDBN}; use @code{help target} to list them.
c906108c 21001
6b2f586d 21002@menu
07f31aa6 21003* Connecting:: Connecting to a remote target
a6b151f1 21004* File Transfer:: Sending files to a remote system
6b2f586d 21005* Server:: Using the gdbserver program
79a6e687
BW
21006* Remote Configuration:: Remote configuration
21007* Remote Stub:: Implementing a remote stub
6b2f586d
AC
21008@end menu
21009
07f31aa6 21010@node Connecting
79a6e687 21011@section Connecting to a Remote Target
19d9d4ef
DB
21012@cindex remote debugging, connecting
21013@cindex @code{gdbserver}, connecting
21014@cindex remote debugging, types of connections
21015@cindex @code{gdbserver}, types of connections
21016@cindex @code{gdbserver}, @code{target remote} mode
21017@cindex @code{gdbserver}, @code{target extended-remote} mode
21018
21019This section describes how to connect to a remote target, including the
21020types of connections and their differences, how to set up executable and
21021symbol files on the host and target, and the commands used for
21022connecting to and disconnecting from the remote target.
21023
21024@subsection Types of Remote Connections
21025
21026@value{GDBN} supports two types of remote connections, @code{target remote}
21027mode and @code{target extended-remote} mode. Note that many remote targets
21028support only @code{target remote} mode. There are several major
21029differences between the two types of connections, enumerated here:
21030
21031@table @asis
21032
21033@cindex remote debugging, detach and program exit
21034@item Result of detach or program exit
21035@strong{With target remote mode:} When the debugged program exits or you
21036detach from it, @value{GDBN} disconnects from the target. When using
21037@code{gdbserver}, @code{gdbserver} will exit.
21038
21039@strong{With target extended-remote mode:} When the debugged program exits or
21040you detach from it, @value{GDBN} remains connected to the target, even
21041though no program is running. You can rerun the program, attach to a
21042running program, or use @code{monitor} commands specific to the target.
21043
21044When using @code{gdbserver} in this case, it does not exit unless it was
21045invoked using the @option{--once} option. If the @option{--once} option
21046was not used, you can ask @code{gdbserver} to exit using the
21047@code{monitor exit} command (@pxref{Monitor Commands for gdbserver}).
21048
21049@item Specifying the program to debug
21050For both connection types you use the @code{file} command to specify the
21051program on the host system. If you are using @code{gdbserver} there are
21052some differences in how to specify the location of the program on the
21053target.
21054
21055@strong{With target remote mode:} You must either specify the program to debug
21056on the @code{gdbserver} command line or use the @option{--attach} option
21057(@pxref{Attaching to a program,,Attaching to a Running Program}).
21058
21059@cindex @option{--multi}, @code{gdbserver} option
21060@strong{With target extended-remote mode:} You may specify the program to debug
21061on the @code{gdbserver} command line, or you can load the program or attach
21062to it using @value{GDBN} commands after connecting to @code{gdbserver}.
21063
21064@anchor{--multi Option in Types of Remote Connnections}
21065You can start @code{gdbserver} without supplying an initial command to run
21066or process ID to attach. To do this, use the @option{--multi} command line
21067option. Then you can connect using @code{target extended-remote} and start
21068the program you want to debug (see below for details on using the
21069@code{run} command in this scenario). Note that the conditions under which
21070@code{gdbserver} terminates depend on how @value{GDBN} connects to it
21071(@code{target remote} or @code{target extended-remote}). The
21072@option{--multi} option to @code{gdbserver} has no influence on that.
07f31aa6 21073
19d9d4ef
DB
21074@item The @code{run} command
21075@strong{With target remote mode:} The @code{run} command is not
21076supported. Once a connection has been established, you can use all
21077the usual @value{GDBN} commands to examine and change data. The
21078remote program is already running, so you can use commands like
21079@kbd{step} and @kbd{continue}.
21080
21081@strong{With target extended-remote mode:} The @code{run} command is
21082supported. The @code{run} command uses the value set by
21083@code{set remote exec-file} (@pxref{set remote exec-file}) to select
21084the program to run. Command line arguments are supported, except for
21085wildcard expansion and I/O redirection (@pxref{Arguments}).
21086
21087If you specify the program to debug on the command line, then the
21088@code{run} command is not required to start execution, and you can
21089resume using commands like @kbd{step} and @kbd{continue} as with
21090@code{target remote} mode.
21091
21092@anchor{Attaching in Types of Remote Connections}
21093@item Attaching
21094@strong{With target remote mode:} The @value{GDBN} command @code{attach} is
21095not supported. To attach to a running program using @code{gdbserver}, you
21096must use the @option{--attach} option (@pxref{Running gdbserver}).
21097
21098@strong{With target extended-remote mode:} To attach to a running program,
21099you may use the @code{attach} command after the connection has been
21100established. If you are using @code{gdbserver}, you may also invoke
21101@code{gdbserver} using the @option{--attach} option
21102(@pxref{Running gdbserver}).
21103
21104@end table
21105
21106@anchor{Host and target files}
21107@subsection Host and Target Files
21108@cindex remote debugging, symbol files
21109@cindex symbol files, remote debugging
21110
21111@value{GDBN}, running on the host, needs access to symbol and debugging
21112information for your program running on the target. This requires
21113access to an unstripped copy of your program, and possibly any associated
21114symbol files. Note that this section applies equally to both @code{target
21115remote} mode and @code{target extended-remote} mode.
21116
21117Some remote targets (@pxref{qXfer executable filename read}, and
21118@pxref{Host I/O Packets}) allow @value{GDBN} to access program files over
21119the same connection used to communicate with @value{GDBN}. With such a
21120target, if the remote program is unstripped, the only command you need is
21121@code{target remote} (or @code{target extended-remote}).
21122
21123If the remote program is stripped, or the target does not support remote
21124program file access, start up @value{GDBN} using the name of the local
1b6e6f5c 21125unstripped copy of your program as the first argument, or use the
19d9d4ef
DB
21126@code{file} command. Use @code{set sysroot} to specify the location (on
21127the host) of target libraries (unless your @value{GDBN} was compiled with
21128the correct sysroot using @code{--with-sysroot}). Alternatively, you
21129may use @code{set solib-search-path} to specify how @value{GDBN} locates
21130target libraries.
21131
21132The symbol file and target libraries must exactly match the executable
21133and libraries on the target, with one exception: the files on the host
21134system should not be stripped, even if the files on the target system
21135are. Mismatched or missing files will lead to confusing results
21136during debugging. On @sc{gnu}/Linux targets, mismatched or missing
21137files may also prevent @code{gdbserver} from debugging multi-threaded
21138programs.
07f31aa6 21139
19d9d4ef
DB
21140@subsection Remote Connection Commands
21141@cindex remote connection commands
c1168a2f
JD
21142@value{GDBN} can communicate with the target over a serial line, a
21143local Unix domain socket, or
86941c27
JB
21144over an @acronym{IP} network using @acronym{TCP} or @acronym{UDP}. In
21145each case, @value{GDBN} uses the same protocol for debugging your
21146program; only the medium carrying the debugging packets varies. The
19d9d4ef
DB
21147@code{target remote} and @code{target extended-remote} commands
21148establish a connection to the target. Both commands accept the same
21149arguments, which indicate the medium to use:
86941c27
JB
21150
21151@table @code
21152
21153@item target remote @var{serial-device}
19d9d4ef 21154@itemx target extended-remote @var{serial-device}
07f31aa6 21155@cindex serial line, @code{target remote}
86941c27
JB
21156Use @var{serial-device} to communicate with the target. For example,
21157to use a serial line connected to the device named @file{/dev/ttyb}:
21158
21159@smallexample
21160target remote /dev/ttyb
21161@end smallexample
21162
07f31aa6 21163If you're using a serial line, you may want to give @value{GDBN} the
2446f5ea 21164@samp{--baud} option, or use the @code{set serial baud} command
0d12017b 21165(@pxref{Remote Configuration, set serial baud}) before the
9c16f35a 21166@code{target} command.
07f31aa6 21167
c1168a2f
JD
21168@item target remote @var{local-socket}
21169@itemx target extended-remote @var{local-socket}
21170@cindex local socket, @code{target remote}
21171@cindex Unix domain socket
21172Use @var{local-socket} to communicate with the target. For example,
21173to use a local Unix domain socket bound to the file system entry @file{/tmp/gdb-socket0}:
21174
21175@smallexample
21176target remote /tmp/gdb-socket0
21177@end smallexample
21178
21179Note that this command has the same form as the command to connect
21180to a serial line. @value{GDBN} will automatically determine which
21181kind of file you have specified and will make the appropriate kind
21182of connection.
21183This feature is not available if the host system does not support
21184Unix domain sockets.
21185
86941c27 21186@item target remote @code{@var{host}:@var{port}}
c7ab0aef 21187@itemx target remote @code{@var{[host]}:@var{port}}
86941c27 21188@itemx target remote @code{tcp:@var{host}:@var{port}}
c7ab0aef
SDJ
21189@itemx target remote @code{tcp:@var{[host]}:@var{port}}
21190@itemx target remote @code{tcp4:@var{host}:@var{port}}
21191@itemx target remote @code{tcp6:@var{host}:@var{port}}
21192@itemx target remote @code{tcp6:@var{[host]}:@var{port}}
19d9d4ef 21193@itemx target extended-remote @code{@var{host}:@var{port}}
c7ab0aef 21194@itemx target extended-remote @code{@var{[host]}:@var{port}}
19d9d4ef 21195@itemx target extended-remote @code{tcp:@var{host}:@var{port}}
c7ab0aef
SDJ
21196@itemx target extended-remote @code{tcp:@var{[host]}:@var{port}}
21197@itemx target extended-remote @code{tcp4:@var{host}:@var{port}}
21198@itemx target extended-remote @code{tcp6:@var{host}:@var{port}}
21199@itemx target extended-remote @code{tcp6:@var{[host]}:@var{port}}
86941c27 21200@cindex @acronym{TCP} port, @code{target remote}
6a0b3457 21201Debug using a @acronym{TCP} connection to @var{port} on @var{host}.
c7ab0aef
SDJ
21202The @var{host} may be either a host name, a numeric @acronym{IPv4}
21203address, or a numeric @acronym{IPv6} address (with or without the
21204square brackets to separate the address from the port); @var{port}
21205must be a decimal number. The @var{host} could be the target machine
21206itself, if it is directly connected to the net, or it might be a
21207terminal server which in turn has a serial line to the target.
07f31aa6 21208
86941c27
JB
21209For example, to connect to port 2828 on a terminal server named
21210@code{manyfarms}:
07f31aa6
DJ
21211
21212@smallexample
21213target remote manyfarms:2828
21214@end smallexample
21215
c7ab0aef
SDJ
21216To connect to port 2828 on a terminal server whose address is
21217@code{2001:0db8:85a3:0000:0000:8a2e:0370:7334}, you can either use the
21218square bracket syntax:
21219
21220@smallexample
21221target remote [2001:0db8:85a3:0000:0000:8a2e:0370:7334]:2828
21222@end smallexample
21223
21224@noindent
21225or explicitly specify the @acronym{IPv6} protocol:
21226
21227@smallexample
21228target remote tcp6:2001:0db8:85a3:0000:0000:8a2e:0370:7334:2828
21229@end smallexample
21230
21231This last example may be confusing to the reader, because there is no
21232visible separation between the hostname and the port number.
21233Therefore, we recommend the user to provide @acronym{IPv6} addresses
21234using square brackets for clarity. However, it is important to
21235mention that for @value{GDBN} there is no ambiguity: the number after
21236the last colon is considered to be the port number.
21237
86941c27
JB
21238If your remote target is actually running on the same machine as your
21239debugger session (e.g.@: a simulator for your target running on the
21240same host), you can omit the hostname. For example, to connect to
21241port 1234 on your local machine:
07f31aa6
DJ
21242
21243@smallexample
21244target remote :1234
21245@end smallexample
21246@noindent
21247
21248Note that the colon is still required here.
21249
86941c27 21250@item target remote @code{udp:@var{host}:@var{port}}
c7ab0aef
SDJ
21251@itemx target remote @code{udp:@var{[host]}:@var{port}}
21252@itemx target remote @code{udp4:@var{host}:@var{port}}
21253@itemx target remote @code{udp6:@var{[host]}:@var{port}}
21254@itemx target extended-remote @code{udp:@var{host}:@var{port}}
19d9d4ef 21255@itemx target extended-remote @code{udp:@var{host}:@var{port}}
c7ab0aef
SDJ
21256@itemx target extended-remote @code{udp:@var{[host]}:@var{port}}
21257@itemx target extended-remote @code{udp4:@var{host}:@var{port}}
21258@itemx target extended-remote @code{udp6:@var{host}:@var{port}}
21259@itemx target extended-remote @code{udp6:@var{[host]}:@var{port}}
86941c27
JB
21260@cindex @acronym{UDP} port, @code{target remote}
21261Debug using @acronym{UDP} packets to @var{port} on @var{host}. For example, to
21262connect to @acronym{UDP} port 2828 on a terminal server named @code{manyfarms}:
07f31aa6
DJ
21263
21264@smallexample
21265target remote udp:manyfarms:2828
21266@end smallexample
21267
86941c27
JB
21268When using a @acronym{UDP} connection for remote debugging, you should
21269keep in mind that the `U' stands for ``Unreliable''. @acronym{UDP}
21270can silently drop packets on busy or unreliable networks, which will
21271cause havoc with your debugging session.
21272
66b8c7f6 21273@item target remote | @var{command}
19d9d4ef 21274@itemx target extended-remote | @var{command}
66b8c7f6
JB
21275@cindex pipe, @code{target remote} to
21276Run @var{command} in the background and communicate with it using a
21277pipe. The @var{command} is a shell command, to be parsed and expanded
21278by the system's command shell, @code{/bin/sh}; it should expect remote
21279protocol packets on its standard input, and send replies on its
21280standard output. You could use this to run a stand-alone simulator
21281that speaks the remote debugging protocol, to make net connections
21282using programs like @code{ssh}, or for other similar tricks.
21283
21284If @var{command} closes its standard output (perhaps by exiting),
21285@value{GDBN} will try to send it a @code{SIGTERM} signal. (If the
21286program has already exited, this will have no effect.)
21287
86941c27 21288@end table
07f31aa6 21289
07f31aa6
DJ
21290@cindex interrupting remote programs
21291@cindex remote programs, interrupting
21292Whenever @value{GDBN} is waiting for the remote program, if you type the
c8aa23ab 21293interrupt character (often @kbd{Ctrl-c}), @value{GDBN} attempts to stop the
07f31aa6
DJ
21294program. This may or may not succeed, depending in part on the hardware
21295and the serial drivers the remote system uses. If you type the
21296interrupt character once again, @value{GDBN} displays this prompt:
21297
21298@smallexample
21299Interrupted while waiting for the program.
21300Give up (and stop debugging it)? (y or n)
21301@end smallexample
21302
19d9d4ef
DB
21303In @code{target remote} mode, if you type @kbd{y}, @value{GDBN} abandons
21304the remote debugging session. (If you decide you want to try again later,
21305you can use @kbd{target remote} again to connect once more.) If you type
21306@kbd{n}, @value{GDBN} goes back to waiting.
21307
21308In @code{target extended-remote} mode, typing @kbd{n} will leave
21309@value{GDBN} connected to the target.
07f31aa6
DJ
21310
21311@table @code
21312@kindex detach (remote)
21313@item detach
21314When you have finished debugging the remote program, you can use the
21315@code{detach} command to release it from @value{GDBN} control.
21316Detaching from the target normally resumes its execution, but the results
21317will depend on your particular remote stub. After the @code{detach}
19d9d4ef
DB
21318command in @code{target remote} mode, @value{GDBN} is free to connect to
21319another target. In @code{target extended-remote} mode, @value{GDBN} is
21320still connected to the target.
07f31aa6
DJ
21321
21322@kindex disconnect
21323@item disconnect
19d9d4ef 21324The @code{disconnect} command closes the connection to the target, and
07f31aa6
DJ
21325the target is generally not resumed. It will wait for @value{GDBN}
21326(this instance or another one) to connect and continue debugging. After
21327the @code{disconnect} command, @value{GDBN} is again free to connect to
21328another target.
09d4efe1
EZ
21329
21330@cindex send command to remote monitor
fad38dfa
EZ
21331@cindex extend @value{GDBN} for remote targets
21332@cindex add new commands for external monitor
09d4efe1
EZ
21333@kindex monitor
21334@item monitor @var{cmd}
fad38dfa
EZ
21335This command allows you to send arbitrary commands directly to the
21336remote monitor. Since @value{GDBN} doesn't care about the commands it
21337sends like this, this command is the way to extend @value{GDBN}---you
21338can add new commands that only the external monitor will understand
21339and implement.
07f31aa6
DJ
21340@end table
21341
a6b151f1
DJ
21342@node File Transfer
21343@section Sending files to a remote system
21344@cindex remote target, file transfer
21345@cindex file transfer
21346@cindex sending files to remote systems
21347
21348Some remote targets offer the ability to transfer files over the same
21349connection used to communicate with @value{GDBN}. This is convenient
21350for targets accessible through other means, e.g.@: @sc{gnu}/Linux systems
21351running @code{gdbserver} over a network interface. For other targets,
21352e.g.@: embedded devices with only a single serial port, this may be
21353the only way to upload or download files.
21354
21355Not all remote targets support these commands.
21356
21357@table @code
21358@kindex remote put
21359@item remote put @var{hostfile} @var{targetfile}
21360Copy file @var{hostfile} from the host system (the machine running
21361@value{GDBN}) to @var{targetfile} on the target system.
21362
21363@kindex remote get
21364@item remote get @var{targetfile} @var{hostfile}
21365Copy file @var{targetfile} from the target system to @var{hostfile}
21366on the host system.
21367
21368@kindex remote delete
21369@item remote delete @var{targetfile}
21370Delete @var{targetfile} from the target system.
21371
21372@end table
21373
6f05cf9f 21374@node Server
79a6e687 21375@section Using the @code{gdbserver} Program
6f05cf9f
AC
21376
21377@kindex gdbserver
21378@cindex remote connection without stubs
21379@code{gdbserver} is a control program for Unix-like systems, which
21380allows you to connect your program with a remote @value{GDBN} via
19d9d4ef
DB
21381@code{target remote} or @code{target extended-remote}---but without
21382linking in the usual debugging stub.
6f05cf9f
AC
21383
21384@code{gdbserver} is not a complete replacement for the debugging stubs,
21385because it requires essentially the same operating-system facilities
21386that @value{GDBN} itself does. In fact, a system that can run
21387@code{gdbserver} to connect to a remote @value{GDBN} could also run
21388@value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
21389because it is a much smaller program than @value{GDBN} itself. It is
21390also easier to port than all of @value{GDBN}, so you may be able to get
21391started more quickly on a new system by using @code{gdbserver}.
21392Finally, if you develop code for real-time systems, you may find that
21393the tradeoffs involved in real-time operation make it more convenient to
21394do as much development work as possible on another system, for example
21395by cross-compiling. You can use @code{gdbserver} to make a similar
21396choice for debugging.
21397
21398@value{GDBN} and @code{gdbserver} communicate via either a serial line
21399or a TCP connection, using the standard @value{GDBN} remote serial
21400protocol.
21401
2d717e4f
DJ
21402@quotation
21403@emph{Warning:} @code{gdbserver} does not have any built-in security.
21404Do not run @code{gdbserver} connected to any public network; a
21405@value{GDBN} connection to @code{gdbserver} provides access to the
21406target system with the same privileges as the user running
21407@code{gdbserver}.
21408@end quotation
21409
19d9d4ef 21410@anchor{Running gdbserver}
2d717e4f
DJ
21411@subsection Running @code{gdbserver}
21412@cindex arguments, to @code{gdbserver}
d9b1a651 21413@cindex @code{gdbserver}, command-line arguments
2d717e4f
DJ
21414
21415Run @code{gdbserver} on the target system. You need a copy of the
21416program you want to debug, including any libraries it requires.
6f05cf9f
AC
21417@code{gdbserver} does not need your program's symbol table, so you can
21418strip the program if necessary to save space. @value{GDBN} on the host
21419system does all the symbol handling.
21420
21421To use the server, you must tell it how to communicate with @value{GDBN};
56460a61 21422the name of your program; and the arguments for your program. The usual
6f05cf9f
AC
21423syntax is:
21424
21425@smallexample
21426target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
21427@end smallexample
21428
6cf36756
SM
21429@var{comm} is either a device name (to use a serial line), or a TCP
21430hostname and portnumber, or @code{-} or @code{stdio} to use
21431stdin/stdout of @code{gdbserver}.
e0f9f062 21432For example, to debug Emacs with the argument
6f05cf9f
AC
21433@samp{foo.txt} and communicate with @value{GDBN} over the serial port
21434@file{/dev/com1}:
21435
21436@smallexample
21437target> gdbserver /dev/com1 emacs foo.txt
21438@end smallexample
21439
6cf36756
SM
21440@code{gdbserver} waits passively for the host @value{GDBN} to communicate
21441with it.
6f05cf9f
AC
21442
21443To use a TCP connection instead of a serial line:
21444
21445@smallexample
21446target> gdbserver host:2345 emacs foo.txt
21447@end smallexample
21448
21449The only difference from the previous example is the first argument,
21450specifying that you are communicating with the host @value{GDBN} via
21451TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
21452expect a TCP connection from machine @samp{host} to local TCP port 2345.
21453(Currently, the @samp{host} part is ignored.) You can choose any number
21454you want for the port number as long as it does not conflict with any
21455TCP ports already in use on the target system (for example, @code{23} is
21456reserved for @code{telnet}).@footnote{If you choose a port number that
21457conflicts with another service, @code{gdbserver} prints an error message
21458and exits.} You must use the same port number with the host @value{GDBN}
21459@code{target remote} command.
21460
6cf36756
SM
21461The @code{stdio} connection is useful when starting @code{gdbserver}
21462with ssh:
e0f9f062
DE
21463
21464@smallexample
6cf36756 21465(gdb) target remote | ssh -T hostname gdbserver - hello
e0f9f062
DE
21466@end smallexample
21467
6cf36756
SM
21468The @samp{-T} option to ssh is provided because we don't need a remote pty,
21469and we don't want escape-character handling. Ssh does this by default when
21470a command is provided, the flag is provided to make it explicit.
21471You could elide it if you want to.
e0f9f062 21472
6cf36756
SM
21473Programs started with stdio-connected gdbserver have @file{/dev/null} for
21474@code{stdin}, and @code{stdout},@code{stderr} are sent back to gdb for
21475display through a pipe connected to gdbserver.
21476Both @code{stdout} and @code{stderr} use the same pipe.
e0f9f062 21477
19d9d4ef 21478@anchor{Attaching to a program}
2d717e4f 21479@subsubsection Attaching to a Running Program
d9b1a651
EZ
21480@cindex attach to a program, @code{gdbserver}
21481@cindex @option{--attach}, @code{gdbserver} option
2d717e4f 21482
56460a61
DJ
21483On some targets, @code{gdbserver} can also attach to running programs.
21484This is accomplished via the @code{--attach} argument. The syntax is:
21485
21486@smallexample
2d717e4f 21487target> gdbserver --attach @var{comm} @var{pid}
56460a61
DJ
21488@end smallexample
21489
19d9d4ef
DB
21490@var{pid} is the process ID of a currently running process. It isn't
21491necessary to point @code{gdbserver} at a binary for the running process.
21492
21493In @code{target extended-remote} mode, you can also attach using the
21494@value{GDBN} attach command
21495(@pxref{Attaching in Types of Remote Connections}).
56460a61 21496
b1fe9455 21497@pindex pidof
b1fe9455
DJ
21498You can debug processes by name instead of process ID if your target has the
21499@code{pidof} utility:
21500
21501@smallexample
2d717e4f 21502target> gdbserver --attach @var{comm} `pidof @var{program}`
b1fe9455
DJ
21503@end smallexample
21504
f822c95b 21505In case more than one copy of @var{program} is running, or @var{program}
b1fe9455
DJ
21506has multiple threads, most versions of @code{pidof} support the
21507@code{-s} option to only return the first process ID.
21508
03f2bd59
JK
21509@subsubsection TCP port allocation lifecycle of @code{gdbserver}
21510
19d9d4ef
DB
21511This section applies only when @code{gdbserver} is run to listen on a TCP
21512port.
03f2bd59
JK
21513
21514@code{gdbserver} normally terminates after all of its debugged processes have
21515terminated in @kbd{target remote} mode. On the other hand, for @kbd{target
21516extended-remote}, @code{gdbserver} stays running even with no processes left.
21517@value{GDBN} normally terminates the spawned debugged process on its exit,
21518which normally also terminates @code{gdbserver} in the @kbd{target remote}
21519mode. Therefore, when the connection drops unexpectedly, and @value{GDBN}
21520cannot ask @code{gdbserver} to kill its debugged processes, @code{gdbserver}
21521stays running even in the @kbd{target remote} mode.
21522
21523When @code{gdbserver} stays running, @value{GDBN} can connect to it again later.
21524Such reconnecting is useful for features like @ref{disconnected tracing}. For
21525completeness, at most one @value{GDBN} can be connected at a time.
21526
21527@cindex @option{--once}, @code{gdbserver} option
21528By default, @code{gdbserver} keeps the listening TCP port open, so that
6e8c5661 21529subsequent connections are possible. However, if you start @code{gdbserver}
03f2bd59
JK
21530with the @option{--once} option, it will stop listening for any further
21531connection attempts after connecting to the first @value{GDBN} session. This
21532means no further connections to @code{gdbserver} will be possible after the
21533first one. It also means @code{gdbserver} will terminate after the first
21534connection with remote @value{GDBN} has closed, even for unexpectedly closed
21535connections and even in the @kbd{target extended-remote} mode. The
21536@option{--once} option allows reusing the same port number for connecting to
21537multiple instances of @code{gdbserver} running on the same host, since each
21538instance closes its port after the first connection.
2d717e4f 21539
87ce2a04 21540@anchor{Other Command-Line Arguments for gdbserver}
2d717e4f
DJ
21541@subsubsection Other Command-Line Arguments for @code{gdbserver}
21542
19d9d4ef
DB
21543You can use the @option{--multi} option to start @code{gdbserver} without
21544specifying a program to debug or a process to attach to. Then you can
21545attach in @code{target extended-remote} mode and run or attach to a
21546program. For more information,
21547@pxref{--multi Option in Types of Remote Connnections}.
21548
d9b1a651 21549@cindex @option{--debug}, @code{gdbserver} option
62709adf 21550The @option{--debug} option tells @code{gdbserver} to display extra
d9b1a651
EZ
21551status information about the debugging process.
21552@cindex @option{--remote-debug}, @code{gdbserver} option
21553The @option{--remote-debug} option tells @code{gdbserver} to display
aeb2e706
AH
21554remote protocol debug output.
21555@cindex @option{--debug-file}, @code{gdbserver} option
21556@cindex @code{gdbserver}, send all debug output to a single file
21557The @option{--debug-file=@var{filename}} option tells @code{gdbserver} to
21558write any debug output to the given @var{filename}. These options are intended
21559for @code{gdbserver} development and for bug reports to the developers.
2d717e4f 21560
87ce2a04
DE
21561@cindex @option{--debug-format}, @code{gdbserver} option
21562The @option{--debug-format=option1[,option2,...]} option tells
21563@code{gdbserver} to include additional information in each output.
21564Possible options are:
21565
21566@table @code
21567@item none
21568Turn off all extra information in debugging output.
21569@item all
21570Turn on all extra information in debugging output.
21571@item timestamps
21572Include a timestamp in each line of debugging output.
21573@end table
21574
21575Options are processed in order. Thus, for example, if @option{none}
21576appears last then no additional information is added to debugging output.
21577
d9b1a651 21578@cindex @option{--wrapper}, @code{gdbserver} option
ccd213ac
DJ
21579The @option{--wrapper} option specifies a wrapper to launch programs
21580for debugging. The option should be followed by the name of the
21581wrapper, then any command-line arguments to pass to the wrapper, then
21582@kbd{--} indicating the end of the wrapper arguments.
21583
21584@code{gdbserver} runs the specified wrapper program with a combined
21585command line including the wrapper arguments, then the name of the
21586program to debug, then any arguments to the program. The wrapper
21587runs until it executes your program, and then @value{GDBN} gains control.
21588
21589You can use any program that eventually calls @code{execve} with
21590its arguments as a wrapper. Several standard Unix utilities do
21591this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
21592with @code{exec "$@@"} will also work.
21593
21594For example, you can use @code{env} to pass an environment variable to
21595the debugged program, without setting the variable in @code{gdbserver}'s
21596environment:
21597
21598@smallexample
21599$ gdbserver --wrapper env LD_PRELOAD=libtest.so -- :2222 ./testprog
21600@end smallexample
21601
6d580b63
YQ
21602@cindex @option{--selftest}
21603The @option{--selftest} option runs the self tests in @code{gdbserver}:
21604
21605@smallexample
21606$ gdbserver --selftest
21607Ran 2 unit tests, 0 failed
21608@end smallexample
21609
21610These tests are disabled in release.
2d717e4f
DJ
21611@subsection Connecting to @code{gdbserver}
21612
19d9d4ef
DB
21613The basic procedure for connecting to the remote target is:
21614@itemize
2d717e4f 21615
19d9d4ef
DB
21616@item
21617Run @value{GDBN} on the host system.
f822c95b 21618
19d9d4ef
DB
21619@item
21620Make sure you have the necessary symbol files
21621(@pxref{Host and target files}).
21622Load symbols for your application using the @code{file} command before you
21623connect. Use @code{set sysroot} to locate target libraries (unless your
21624@value{GDBN} was compiled with the correct sysroot using
21625@code{--with-sysroot}).
f822c95b 21626
19d9d4ef 21627@item
79a6e687 21628Connect to your target (@pxref{Connecting,,Connecting to a Remote Target}).
6f05cf9f 21629For TCP connections, you must start up @code{gdbserver} prior to using
19d9d4ef 21630the @code{target} command. Otherwise you may get an error whose
6f05cf9f 21631text depends on the host system, but which usually looks something like
2d717e4f 21632@samp{Connection refused}. Don't use the @code{load}
19d9d4ef
DB
21633command in @value{GDBN} when using @code{target remote} mode, since the
21634program is already on the target.
21635
21636@end itemize
07f31aa6 21637
19d9d4ef 21638@anchor{Monitor Commands for gdbserver}
79a6e687 21639@subsection Monitor Commands for @code{gdbserver}
c74d0ad8
DJ
21640@cindex monitor commands, for @code{gdbserver}
21641
21642During a @value{GDBN} session using @code{gdbserver}, you can use the
21643@code{monitor} command to send special requests to @code{gdbserver}.
2d717e4f 21644Here are the available commands.
c74d0ad8
DJ
21645
21646@table @code
21647@item monitor help
21648List the available monitor commands.
21649
21650@item monitor set debug 0
21651@itemx monitor set debug 1
21652Disable or enable general debugging messages.
21653
21654@item monitor set remote-debug 0
21655@itemx monitor set remote-debug 1
21656Disable or enable specific debugging messages associated with the remote
21657protocol (@pxref{Remote Protocol}).
21658
aeb2e706
AH
21659@item monitor set debug-file filename
21660@itemx monitor set debug-file
21661Send any debug output to the given file, or to stderr.
21662
87ce2a04
DE
21663@item monitor set debug-format option1@r{[},option2,...@r{]}
21664Specify additional text to add to debugging messages.
21665Possible options are:
21666
21667@table @code
21668@item none
21669Turn off all extra information in debugging output.
21670@item all
21671Turn on all extra information in debugging output.
21672@item timestamps
21673Include a timestamp in each line of debugging output.
21674@end table
21675
21676Options are processed in order. Thus, for example, if @option{none}
21677appears last then no additional information is added to debugging output.
21678
cdbfd419
PP
21679@item monitor set libthread-db-search-path [PATH]
21680@cindex gdbserver, search path for @code{libthread_db}
21681When this command is issued, @var{path} is a colon-separated list of
21682directories to search for @code{libthread_db} (@pxref{Threads,,set
21683libthread-db-search-path}). If you omit @var{path},
84e578fb 21684@samp{libthread-db-search-path} will be reset to its default value.
cdbfd419 21685
98a5dd13
DE
21686The special entry @samp{$pdir} for @samp{libthread-db-search-path} is
21687not supported in @code{gdbserver}.
21688
2d717e4f
DJ
21689@item monitor exit
21690Tell gdbserver to exit immediately. This command should be followed by
21691@code{disconnect} to close the debugging session. @code{gdbserver} will
21692detach from any attached processes and kill any processes it created.
21693Use @code{monitor exit} to terminate @code{gdbserver} at the end
21694of a multi-process mode debug session.
21695
c74d0ad8
DJ
21696@end table
21697
fa593d66
PA
21698@subsection Tracepoints support in @code{gdbserver}
21699@cindex tracepoints support in @code{gdbserver}
21700
0fb4aa4b
PA
21701On some targets, @code{gdbserver} supports tracepoints, fast
21702tracepoints and static tracepoints.
fa593d66 21703
0fb4aa4b 21704For fast or static tracepoints to work, a special library called the
fa593d66
PA
21705@dfn{in-process agent} (IPA), must be loaded in the inferior process.
21706This library is built and distributed as an integral part of
0fb4aa4b
PA
21707@code{gdbserver}. In addition, support for static tracepoints
21708requires building the in-process agent library with static tracepoints
21709support. At present, the UST (LTTng Userspace Tracer,
21710@url{http://lttng.org/ust}) tracing engine is supported. This support
21711is automatically available if UST development headers are found in the
21712standard include path when @code{gdbserver} is built, or if
21713@code{gdbserver} was explicitly configured using @option{--with-ust}
21714to point at such headers. You can explicitly disable the support
21715using @option{--with-ust=no}.
fa593d66
PA
21716
21717There are several ways to load the in-process agent in your program:
21718
21719@table @code
21720@item Specifying it as dependency at link time
21721
21722You can link your program dynamically with the in-process agent
21723library. On most systems, this is accomplished by adding
21724@code{-linproctrace} to the link command.
21725
21726@item Using the system's preloading mechanisms
21727
21728You can force loading the in-process agent at startup time by using
21729your system's support for preloading shared libraries. Many Unixes
21730support the concept of preloading user defined libraries. In most
21731cases, you do that by specifying @code{LD_PRELOAD=libinproctrace.so}
21732in the environment. See also the description of @code{gdbserver}'s
21733@option{--wrapper} command line option.
21734
21735@item Using @value{GDBN} to force loading the agent at run time
21736
21737On some systems, you can force the inferior to load a shared library,
21738by calling a dynamic loader function in the inferior that takes care
21739of dynamically looking up and loading a shared library. On most Unix
21740systems, the function is @code{dlopen}. You'll use the @code{call}
21741command for that. For example:
21742
21743@smallexample
21744(@value{GDBP}) call dlopen ("libinproctrace.so", ...)
21745@end smallexample
21746
21747Note that on most Unix systems, for the @code{dlopen} function to be
21748available, the program needs to be linked with @code{-ldl}.
21749@end table
21750
21751On systems that have a userspace dynamic loader, like most Unix
21752systems, when you connect to @code{gdbserver} using @code{target
21753remote}, you'll find that the program is stopped at the dynamic
21754loader's entry point, and no shared library has been loaded in the
21755program's address space yet, including the in-process agent. In that
0fb4aa4b
PA
21756case, before being able to use any of the fast or static tracepoints
21757features, you need to let the loader run and load the shared
21758libraries. The simplest way to do that is to run the program to the
21759main procedure. E.g., if debugging a C or C@t{++} program, start
fa593d66
PA
21760@code{gdbserver} like so:
21761
21762@smallexample
21763$ gdbserver :9999 myprogram
21764@end smallexample
21765
21766Start GDB and connect to @code{gdbserver} like so, and run to main:
21767
21768@smallexample
21769$ gdb myprogram
21770(@value{GDBP}) target remote myhost:9999
217710x00007f215893ba60 in ?? () from /lib64/ld-linux-x86-64.so.2
21772(@value{GDBP}) b main
21773(@value{GDBP}) continue
21774@end smallexample
21775
21776The in-process tracing agent library should now be loaded into the
21777process; you can confirm it with the @code{info sharedlibrary}
21778command, which will list @file{libinproctrace.so} as loaded in the
0fb4aa4b
PA
21779process. You are now ready to install fast tracepoints, list static
21780tracepoint markers, probe static tracepoints markers, and start
fa593d66
PA
21781tracing.
21782
79a6e687
BW
21783@node Remote Configuration
21784@section Remote Configuration
501eef12 21785
9c16f35a
EZ
21786@kindex set remote
21787@kindex show remote
21788This section documents the configuration options available when
21789debugging remote programs. For the options related to the File I/O
fc320d37 21790extensions of the remote protocol, see @ref{system,
9c16f35a 21791system-call-allowed}.
501eef12
AC
21792
21793@table @code
9c16f35a 21794@item set remoteaddresssize @var{bits}
d3e8051b 21795@cindex address size for remote targets
9c16f35a
EZ
21796@cindex bits in remote address
21797Set the maximum size of address in a memory packet to the specified
21798number of bits. @value{GDBN} will mask off the address bits above
21799that number, when it passes addresses to the remote target. The
21800default value is the number of bits in the target's address.
21801
21802@item show remoteaddresssize
21803Show the current value of remote address size in bits.
21804
0d12017b 21805@item set serial baud @var{n}
9c16f35a
EZ
21806@cindex baud rate for remote targets
21807Set the baud rate for the remote serial I/O to @var{n} baud. The
21808value is used to set the speed of the serial port used for debugging
21809remote targets.
21810
0d12017b 21811@item show serial baud
9c16f35a
EZ
21812Show the current speed of the remote connection.
21813
236af5e3
YG
21814@item set serial parity @var{parity}
21815Set the parity for the remote serial I/O. Supported values of @var{parity} are:
21816@code{even}, @code{none}, and @code{odd}. The default is @code{none}.
21817
21818@item show serial parity
21819Show the current parity of the serial port.
21820
9c16f35a
EZ
21821@item set remotebreak
21822@cindex interrupt remote programs
21823@cindex BREAK signal instead of Ctrl-C
9a6253be 21824@anchor{set remotebreak}
9c16f35a 21825If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
c8aa23ab 21826when you type @kbd{Ctrl-c} to interrupt the program running
9a7a1b36 21827on the remote. If set to off, @value{GDBN} sends the @samp{Ctrl-C}
9c16f35a
EZ
21828character instead. The default is off, since most remote systems
21829expect to see @samp{Ctrl-C} as the interrupt signal.
21830
21831@item show remotebreak
21832Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
21833interrupt the remote program.
21834
23776285
MR
21835@item set remoteflow on
21836@itemx set remoteflow off
21837@kindex set remoteflow
21838Enable or disable hardware flow control (@code{RTS}/@code{CTS})
21839on the serial port used to communicate to the remote target.
21840
21841@item show remoteflow
21842@kindex show remoteflow
21843Show the current setting of hardware flow control.
21844
9c16f35a
EZ
21845@item set remotelogbase @var{base}
21846Set the base (a.k.a.@: radix) of logging serial protocol
21847communications to @var{base}. Supported values of @var{base} are:
21848@code{ascii}, @code{octal}, and @code{hex}. The default is
21849@code{ascii}.
21850
21851@item show remotelogbase
21852Show the current setting of the radix for logging remote serial
21853protocol.
21854
21855@item set remotelogfile @var{file}
21856@cindex record serial communications on file
21857Record remote serial communications on the named @var{file}. The
21858default is not to record at all.
21859
2d8b6830 21860@item show remotelogfile
9c16f35a
EZ
21861Show the current setting of the file name on which to record the
21862serial communications.
21863
21864@item set remotetimeout @var{num}
21865@cindex timeout for serial communications
21866@cindex remote timeout
21867Set the timeout limit to wait for the remote target to respond to
21868@var{num} seconds. The default is 2 seconds.
21869
21870@item show remotetimeout
21871Show the current number of seconds to wait for the remote target
21872responses.
21873
21874@cindex limit hardware breakpoints and watchpoints
21875@cindex remote target, limit break- and watchpoints
501eef12
AC
21876@anchor{set remote hardware-watchpoint-limit}
21877@anchor{set remote hardware-breakpoint-limit}
21878@item set remote hardware-watchpoint-limit @var{limit}
21879@itemx set remote hardware-breakpoint-limit @var{limit}
055303e2
AB
21880Restrict @value{GDBN} to using @var{limit} remote hardware watchpoints
21881or breakpoints. The @var{limit} can be set to 0 to disable hardware
21882watchpoints or breakpoints, and @code{unlimited} for unlimited
21883watchpoints or breakpoints.
21884
21885@item show remote hardware-watchpoint-limit
21886@itemx show remote hardware-breakpoint-limit
21887Show the current limit for the number of hardware watchpoints or
21888breakpoints that @value{GDBN} can use.
2d717e4f 21889
480a3f21
PW
21890@cindex limit hardware watchpoints length
21891@cindex remote target, limit watchpoints length
21892@anchor{set remote hardware-watchpoint-length-limit}
21893@item set remote hardware-watchpoint-length-limit @var{limit}
055303e2
AB
21894Restrict @value{GDBN} to using @var{limit} bytes for the maximum
21895length of a remote hardware watchpoint. A @var{limit} of 0 disables
21896hardware watchpoints and @code{unlimited} allows watchpoints of any
21897length.
480a3f21
PW
21898
21899@item show remote hardware-watchpoint-length-limit
21900Show the current limit (in bytes) of the maximum length of
21901a remote hardware watchpoint.
21902
2d717e4f
DJ
21903@item set remote exec-file @var{filename}
21904@itemx show remote exec-file
21905@anchor{set remote exec-file}
21906@cindex executable file, for remote target
21907Select the file used for @code{run} with @code{target
21908extended-remote}. This should be set to a filename valid on the
21909target system. If it is not set, the target will use a default
21910filename (e.g.@: the last program run).
84603566 21911
9a7071a8
JB
21912@item set remote interrupt-sequence
21913@cindex interrupt remote programs
21914@cindex select Ctrl-C, BREAK or BREAK-g
21915Allow the user to select one of @samp{Ctrl-C}, a @code{BREAK} or
21916@samp{BREAK-g} as the
21917sequence to the remote target in order to interrupt the execution.
21918@samp{Ctrl-C} is a default. Some system prefers @code{BREAK} which
21919is high level of serial line for some certain time.
21920Linux kernel prefers @samp{BREAK-g}, a.k.a Magic SysRq g.
21921It is @code{BREAK} signal followed by character @code{g}.
21922
21923@item show interrupt-sequence
21924Show which of @samp{Ctrl-C}, @code{BREAK} or @code{BREAK-g}
21925is sent by @value{GDBN} to interrupt the remote program.
21926@code{BREAK-g} is BREAK signal followed by @code{g} and
21927also known as Magic SysRq g.
21928
21929@item set remote interrupt-on-connect
21930@cindex send interrupt-sequence on start
21931Specify whether interrupt-sequence is sent to remote target when
21932@value{GDBN} connects to it. This is mostly needed when you debug
21933Linux kernel. Linux kernel expects @code{BREAK} followed by @code{g}
21934which is known as Magic SysRq g in order to connect @value{GDBN}.
21935
21936@item show interrupt-on-connect
21937Show whether interrupt-sequence is sent
21938to remote target when @value{GDBN} connects to it.
21939
84603566
SL
21940@kindex set tcp
21941@kindex show tcp
21942@item set tcp auto-retry on
21943@cindex auto-retry, for remote TCP target
21944Enable auto-retry for remote TCP connections. This is useful if the remote
21945debugging agent is launched in parallel with @value{GDBN}; there is a race
21946condition because the agent may not become ready to accept the connection
21947before @value{GDBN} attempts to connect. When auto-retry is
21948enabled, if the initial attempt to connect fails, @value{GDBN} reattempts
21949to establish the connection using the timeout specified by
21950@code{set tcp connect-timeout}.
21951
21952@item set tcp auto-retry off
21953Do not auto-retry failed TCP connections.
21954
21955@item show tcp auto-retry
21956Show the current auto-retry setting.
21957
21958@item set tcp connect-timeout @var{seconds}
f81d1120 21959@itemx set tcp connect-timeout unlimited
84603566
SL
21960@cindex connection timeout, for remote TCP target
21961@cindex timeout, for remote target connection
21962Set the timeout for establishing a TCP connection to the remote target to
21963@var{seconds}. The timeout affects both polling to retry failed connections
21964(enabled by @code{set tcp auto-retry on}) and waiting for connections
21965that are merely slow to complete, and represents an approximate cumulative
f81d1120
PA
21966value. If @var{seconds} is @code{unlimited}, there is no timeout and
21967@value{GDBN} will keep attempting to establish a connection forever,
21968unless interrupted with @kbd{Ctrl-c}. The default is 15 seconds.
84603566
SL
21969
21970@item show tcp connect-timeout
21971Show the current connection timeout setting.
501eef12
AC
21972@end table
21973
427c3a89
DJ
21974@cindex remote packets, enabling and disabling
21975The @value{GDBN} remote protocol autodetects the packets supported by
21976your debugging stub. If you need to override the autodetection, you
21977can use these commands to enable or disable individual packets. Each
21978packet can be set to @samp{on} (the remote target supports this
21979packet), @samp{off} (the remote target does not support this packet),
21980or @samp{auto} (detect remote target support for this packet). They
21981all default to @samp{auto}. For more information about each packet,
21982see @ref{Remote Protocol}.
21983
21984During normal use, you should not have to use any of these commands.
21985If you do, that may be a bug in your remote debugging stub, or a bug
21986in @value{GDBN}. You may want to report the problem to the
21987@value{GDBN} developers.
21988
cfa9d6d9
DJ
21989For each packet @var{name}, the command to enable or disable the
21990packet is @code{set remote @var{name}-packet}. The available settings
21991are:
427c3a89 21992
cfa9d6d9 21993@multitable @columnfractions 0.28 0.32 0.25
427c3a89
DJ
21994@item Command Name
21995@tab Remote Packet
21996@tab Related Features
21997
cfa9d6d9 21998@item @code{fetch-register}
427c3a89
DJ
21999@tab @code{p}
22000@tab @code{info registers}
22001
cfa9d6d9 22002@item @code{set-register}
427c3a89
DJ
22003@tab @code{P}
22004@tab @code{set}
22005
cfa9d6d9 22006@item @code{binary-download}
427c3a89
DJ
22007@tab @code{X}
22008@tab @code{load}, @code{set}
22009
cfa9d6d9 22010@item @code{read-aux-vector}
427c3a89
DJ
22011@tab @code{qXfer:auxv:read}
22012@tab @code{info auxv}
22013
cfa9d6d9 22014@item @code{symbol-lookup}
427c3a89
DJ
22015@tab @code{qSymbol}
22016@tab Detecting multiple threads
22017
2d717e4f
DJ
22018@item @code{attach}
22019@tab @code{vAttach}
22020@tab @code{attach}
22021
cfa9d6d9 22022@item @code{verbose-resume}
427c3a89
DJ
22023@tab @code{vCont}
22024@tab Stepping or resuming multiple threads
22025
2d717e4f
DJ
22026@item @code{run}
22027@tab @code{vRun}
22028@tab @code{run}
22029
cfa9d6d9 22030@item @code{software-breakpoint}
427c3a89
DJ
22031@tab @code{Z0}
22032@tab @code{break}
22033
cfa9d6d9 22034@item @code{hardware-breakpoint}
427c3a89
DJ
22035@tab @code{Z1}
22036@tab @code{hbreak}
22037
cfa9d6d9 22038@item @code{write-watchpoint}
427c3a89
DJ
22039@tab @code{Z2}
22040@tab @code{watch}
22041
cfa9d6d9 22042@item @code{read-watchpoint}
427c3a89
DJ
22043@tab @code{Z3}
22044@tab @code{rwatch}
22045
cfa9d6d9 22046@item @code{access-watchpoint}
427c3a89
DJ
22047@tab @code{Z4}
22048@tab @code{awatch}
22049
c78fa86a
GB
22050@item @code{pid-to-exec-file}
22051@tab @code{qXfer:exec-file:read}
22052@tab @code{attach}, @code{run}
22053
cfa9d6d9
DJ
22054@item @code{target-features}
22055@tab @code{qXfer:features:read}
22056@tab @code{set architecture}
22057
22058@item @code{library-info}
22059@tab @code{qXfer:libraries:read}
22060@tab @code{info sharedlibrary}
22061
22062@item @code{memory-map}
22063@tab @code{qXfer:memory-map:read}
22064@tab @code{info mem}
22065
0fb4aa4b
PA
22066@item @code{read-sdata-object}
22067@tab @code{qXfer:sdata:read}
22068@tab @code{print $_sdata}
22069
cfa9d6d9
DJ
22070@item @code{read-spu-object}
22071@tab @code{qXfer:spu:read}
22072@tab @code{info spu}
22073
22074@item @code{write-spu-object}
22075@tab @code{qXfer:spu:write}
22076@tab @code{info spu}
22077
4aa995e1
PA
22078@item @code{read-siginfo-object}
22079@tab @code{qXfer:siginfo:read}
22080@tab @code{print $_siginfo}
22081
22082@item @code{write-siginfo-object}
22083@tab @code{qXfer:siginfo:write}
22084@tab @code{set $_siginfo}
22085
dc146f7c
VP
22086@item @code{threads}
22087@tab @code{qXfer:threads:read}
22088@tab @code{info threads}
22089
cfa9d6d9 22090@item @code{get-thread-local-@*storage-address}
427c3a89
DJ
22091@tab @code{qGetTLSAddr}
22092@tab Displaying @code{__thread} variables
22093
711e434b
PM
22094@item @code{get-thread-information-block-address}
22095@tab @code{qGetTIBAddr}
22096@tab Display MS-Windows Thread Information Block.
22097
08388c79
DE
22098@item @code{search-memory}
22099@tab @code{qSearch:memory}
22100@tab @code{find}
22101
427c3a89
DJ
22102@item @code{supported-packets}
22103@tab @code{qSupported}
22104@tab Remote communications parameters
22105
82075af2
JS
22106@item @code{catch-syscalls}
22107@tab @code{QCatchSyscalls}
22108@tab @code{catch syscall}
22109
cfa9d6d9 22110@item @code{pass-signals}
89be2091
DJ
22111@tab @code{QPassSignals}
22112@tab @code{handle @var{signal}}
22113
9b224c5e
PA
22114@item @code{program-signals}
22115@tab @code{QProgramSignals}
22116@tab @code{handle @var{signal}}
22117
a6b151f1
DJ
22118@item @code{hostio-close-packet}
22119@tab @code{vFile:close}
22120@tab @code{remote get}, @code{remote put}
22121
22122@item @code{hostio-open-packet}
22123@tab @code{vFile:open}
22124@tab @code{remote get}, @code{remote put}
22125
22126@item @code{hostio-pread-packet}
22127@tab @code{vFile:pread}
22128@tab @code{remote get}, @code{remote put}
22129
22130@item @code{hostio-pwrite-packet}
22131@tab @code{vFile:pwrite}
22132@tab @code{remote get}, @code{remote put}
22133
22134@item @code{hostio-unlink-packet}
22135@tab @code{vFile:unlink}
22136@tab @code{remote delete}
a6f3e723 22137
b9e7b9c3
UW
22138@item @code{hostio-readlink-packet}
22139@tab @code{vFile:readlink}
22140@tab Host I/O
22141
0a93529c
GB
22142@item @code{hostio-fstat-packet}
22143@tab @code{vFile:fstat}
22144@tab Host I/O
22145
15a201c8
GB
22146@item @code{hostio-setfs-packet}
22147@tab @code{vFile:setfs}
22148@tab Host I/O
22149
a6f3e723
SL
22150@item @code{noack-packet}
22151@tab @code{QStartNoAckMode}
22152@tab Packet acknowledgment
07e059b5
VP
22153
22154@item @code{osdata}
22155@tab @code{qXfer:osdata:read}
22156@tab @code{info os}
0b16c5cf
PA
22157
22158@item @code{query-attached}
22159@tab @code{qAttached}
22160@tab Querying remote process attach state.
b3b9301e 22161
a46c1e42
PA
22162@item @code{trace-buffer-size}
22163@tab @code{QTBuffer:size}
22164@tab @code{set trace-buffer-size}
22165
bd3eecc3
PA
22166@item @code{trace-status}
22167@tab @code{qTStatus}
22168@tab @code{tstatus}
22169
b3b9301e
PA
22170@item @code{traceframe-info}
22171@tab @code{qXfer:traceframe-info:read}
22172@tab Traceframe info
03583c20 22173
1e4d1764
YQ
22174@item @code{install-in-trace}
22175@tab @code{InstallInTrace}
22176@tab Install tracepoint in tracing
22177
03583c20
UW
22178@item @code{disable-randomization}
22179@tab @code{QDisableRandomization}
22180@tab @code{set disable-randomization}
83364271 22181
aefd8b33
SDJ
22182@item @code{startup-with-shell}
22183@tab @code{QStartupWithShell}
22184@tab @code{set startup-with-shell}
22185
0a2dde4a
SDJ
22186@item @code{environment-hex-encoded}
22187@tab @code{QEnvironmentHexEncoded}
22188@tab @code{set environment}
22189
22190@item @code{environment-unset}
22191@tab @code{QEnvironmentUnset}
22192@tab @code{unset environment}
22193
22194@item @code{environment-reset}
22195@tab @code{QEnvironmentReset}
22196@tab @code{Reset the inferior environment (i.e., unset user-set variables)}
22197
bc3b087d
SDJ
22198@item @code{set-working-dir}
22199@tab @code{QSetWorkingDir}
22200@tab @code{set cwd}
22201
83364271
LM
22202@item @code{conditional-breakpoints-packet}
22203@tab @code{Z0 and Z1}
22204@tab @code{Support for target-side breakpoint condition evaluation}
f7e6eed5 22205
73b8c1fd
PA
22206@item @code{multiprocess-extensions}
22207@tab @code{multiprocess extensions}
22208@tab Debug multiple processes and remote process PID awareness
22209
f7e6eed5
PA
22210@item @code{swbreak-feature}
22211@tab @code{swbreak stop reason}
22212@tab @code{break}
22213
22214@item @code{hwbreak-feature}
22215@tab @code{hwbreak stop reason}
22216@tab @code{hbreak}
22217
0d71eef5
DB
22218@item @code{fork-event-feature}
22219@tab @code{fork stop reason}
22220@tab @code{fork}
22221
22222@item @code{vfork-event-feature}
22223@tab @code{vfork stop reason}
22224@tab @code{vfork}
22225
b459a59b
DB
22226@item @code{exec-event-feature}
22227@tab @code{exec stop reason}
22228@tab @code{exec}
22229
65706a29
PA
22230@item @code{thread-events}
22231@tab @code{QThreadEvents}
22232@tab Tracking thread lifetime.
22233
f2faf941
PA
22234@item @code{no-resumed-stop-reply}
22235@tab @code{no resumed thread left stop reply}
22236@tab Tracking thread lifetime.
22237
427c3a89
DJ
22238@end multitable
22239
79a6e687
BW
22240@node Remote Stub
22241@section Implementing a Remote Stub
7a292a7a 22242
8e04817f
AC
22243@cindex debugging stub, example
22244@cindex remote stub, example
22245@cindex stub example, remote debugging
22246The stub files provided with @value{GDBN} implement the target side of the
22247communication protocol, and the @value{GDBN} side is implemented in the
22248@value{GDBN} source file @file{remote.c}. Normally, you can simply allow
22249these subroutines to communicate, and ignore the details. (If you're
22250implementing your own stub file, you can still ignore the details: start
22251with one of the existing stub files. @file{sparc-stub.c} is the best
22252organized, and therefore the easiest to read.)
22253
104c1213
JM
22254@cindex remote serial debugging, overview
22255To debug a program running on another machine (the debugging
22256@dfn{target} machine), you must first arrange for all the usual
22257prerequisites for the program to run by itself. For example, for a C
22258program, you need:
c906108c 22259
104c1213
JM
22260@enumerate
22261@item
22262A startup routine to set up the C runtime environment; these usually
22263have a name like @file{crt0}. The startup routine may be supplied by
22264your hardware supplier, or you may have to write your own.
96baa820 22265
5d161b24 22266@item
d4f3574e 22267A C subroutine library to support your program's
104c1213 22268subroutine calls, notably managing input and output.
96baa820 22269
104c1213
JM
22270@item
22271A way of getting your program to the other machine---for example, a
22272download program. These are often supplied by the hardware
22273manufacturer, but you may have to write your own from hardware
22274documentation.
22275@end enumerate
96baa820 22276
104c1213
JM
22277The next step is to arrange for your program to use a serial port to
22278communicate with the machine where @value{GDBN} is running (the @dfn{host}
22279machine). In general terms, the scheme looks like this:
96baa820 22280
104c1213
JM
22281@table @emph
22282@item On the host,
22283@value{GDBN} already understands how to use this protocol; when everything
22284else is set up, you can simply use the @samp{target remote} command
22285(@pxref{Targets,,Specifying a Debugging Target}).
22286
22287@item On the target,
22288you must link with your program a few special-purpose subroutines that
22289implement the @value{GDBN} remote serial protocol. The file containing these
22290subroutines is called a @dfn{debugging stub}.
22291
22292On certain remote targets, you can use an auxiliary program
22293@code{gdbserver} instead of linking a stub into your program.
79a6e687 22294@xref{Server,,Using the @code{gdbserver} Program}, for details.
104c1213 22295@end table
96baa820 22296
104c1213
JM
22297The debugging stub is specific to the architecture of the remote
22298machine; for example, use @file{sparc-stub.c} to debug programs on
22299@sc{sparc} boards.
96baa820 22300
104c1213
JM
22301@cindex remote serial stub list
22302These working remote stubs are distributed with @value{GDBN}:
96baa820 22303
104c1213
JM
22304@table @code
22305
22306@item i386-stub.c
41afff9a 22307@cindex @file{i386-stub.c}
104c1213
JM
22308@cindex Intel
22309@cindex i386
22310For Intel 386 and compatible architectures.
22311
22312@item m68k-stub.c
41afff9a 22313@cindex @file{m68k-stub.c}
104c1213
JM
22314@cindex Motorola 680x0
22315@cindex m680x0
22316For Motorola 680x0 architectures.
22317
22318@item sh-stub.c
41afff9a 22319@cindex @file{sh-stub.c}
172c2a43 22320@cindex Renesas
104c1213 22321@cindex SH
172c2a43 22322For Renesas SH architectures.
104c1213
JM
22323
22324@item sparc-stub.c
41afff9a 22325@cindex @file{sparc-stub.c}
104c1213
JM
22326@cindex Sparc
22327For @sc{sparc} architectures.
22328
22329@item sparcl-stub.c
41afff9a 22330@cindex @file{sparcl-stub.c}
104c1213
JM
22331@cindex Fujitsu
22332@cindex SparcLite
22333For Fujitsu @sc{sparclite} architectures.
22334
22335@end table
22336
22337The @file{README} file in the @value{GDBN} distribution may list other
22338recently added stubs.
22339
22340@menu
22341* Stub Contents:: What the stub can do for you
22342* Bootstrapping:: What you must do for the stub
22343* Debug Session:: Putting it all together
104c1213
JM
22344@end menu
22345
6d2ebf8b 22346@node Stub Contents
79a6e687 22347@subsection What the Stub Can Do for You
104c1213
JM
22348
22349@cindex remote serial stub
22350The debugging stub for your architecture supplies these three
22351subroutines:
22352
22353@table @code
22354@item set_debug_traps
4644b6e3 22355@findex set_debug_traps
104c1213
JM
22356@cindex remote serial stub, initialization
22357This routine arranges for @code{handle_exception} to run when your
2fb860fc
PA
22358program stops. You must call this subroutine explicitly in your
22359program's startup code.
104c1213
JM
22360
22361@item handle_exception
4644b6e3 22362@findex handle_exception
104c1213
JM
22363@cindex remote serial stub, main routine
22364This is the central workhorse, but your program never calls it
22365explicitly---the setup code arranges for @code{handle_exception} to
22366run when a trap is triggered.
22367
22368@code{handle_exception} takes control when your program stops during
22369execution (for example, on a breakpoint), and mediates communications
22370with @value{GDBN} on the host machine. This is where the communications
22371protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
d4f3574e 22372representative on the target machine. It begins by sending summary
104c1213
JM
22373information on the state of your program, then continues to execute,
22374retrieving and transmitting any information @value{GDBN} needs, until you
22375execute a @value{GDBN} command that makes your program resume; at that point,
22376@code{handle_exception} returns control to your own code on the target
5d161b24 22377machine.
104c1213
JM
22378
22379@item breakpoint
22380@cindex @code{breakpoint} subroutine, remote
22381Use this auxiliary subroutine to make your program contain a
22382breakpoint. Depending on the particular situation, this may be the only
22383way for @value{GDBN} to get control. For instance, if your target
22384machine has some sort of interrupt button, you won't need to call this;
22385pressing the interrupt button transfers control to
22386@code{handle_exception}---in effect, to @value{GDBN}. On some machines,
22387simply receiving characters on the serial port may also trigger a trap;
22388again, in that situation, you don't need to call @code{breakpoint} from
22389your own program---simply running @samp{target remote} from the host
5d161b24 22390@value{GDBN} session gets control.
104c1213
JM
22391
22392Call @code{breakpoint} if none of these is true, or if you simply want
22393to make certain your program stops at a predetermined point for the
22394start of your debugging session.
22395@end table
22396
6d2ebf8b 22397@node Bootstrapping
79a6e687 22398@subsection What You Must Do for the Stub
104c1213
JM
22399
22400@cindex remote stub, support routines
22401The debugging stubs that come with @value{GDBN} are set up for a particular
22402chip architecture, but they have no information about the rest of your
22403debugging target machine.
22404
22405First of all you need to tell the stub how to communicate with the
22406serial port.
22407
22408@table @code
22409@item int getDebugChar()
4644b6e3 22410@findex getDebugChar
104c1213
JM
22411Write this subroutine to read a single character from the serial port.
22412It may be identical to @code{getchar} for your target system; a
22413different name is used to allow you to distinguish the two if you wish.
22414
22415@item void putDebugChar(int)
4644b6e3 22416@findex putDebugChar
104c1213 22417Write this subroutine to write a single character to the serial port.
5d161b24 22418It may be identical to @code{putchar} for your target system; a
104c1213
JM
22419different name is used to allow you to distinguish the two if you wish.
22420@end table
22421
22422@cindex control C, and remote debugging
22423@cindex interrupting remote targets
22424If you want @value{GDBN} to be able to stop your program while it is
22425running, you need to use an interrupt-driven serial driver, and arrange
22426for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
22427character). That is the character which @value{GDBN} uses to tell the
22428remote system to stop.
22429
22430Getting the debugging target to return the proper status to @value{GDBN}
22431probably requires changes to the standard stub; one quick and dirty way
22432is to just execute a breakpoint instruction (the ``dirty'' part is that
22433@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
22434
22435Other routines you need to supply are:
22436
22437@table @code
22438@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
4644b6e3 22439@findex exceptionHandler
104c1213
JM
22440Write this function to install @var{exception_address} in the exception
22441handling tables. You need to do this because the stub does not have any
22442way of knowing what the exception handling tables on your target system
22443are like (for example, the processor's table might be in @sc{rom},
22444containing entries which point to a table in @sc{ram}).
697aa1b7 22445The @var{exception_number} specifies the exception which should be changed;
104c1213
JM
22446its meaning is architecture-dependent (for example, different numbers
22447might represent divide by zero, misaligned access, etc). When this
22448exception occurs, control should be transferred directly to
22449@var{exception_address}, and the processor state (stack, registers,
22450and so on) should be just as it is when a processor exception occurs. So if
22451you want to use a jump instruction to reach @var{exception_address}, it
22452should be a simple jump, not a jump to subroutine.
22453
22454For the 386, @var{exception_address} should be installed as an interrupt
22455gate so that interrupts are masked while the handler runs. The gate
22456should be at privilege level 0 (the most privileged level). The
22457@sc{sparc} and 68k stubs are able to mask interrupts themselves without
22458help from @code{exceptionHandler}.
22459
22460@item void flush_i_cache()
4644b6e3 22461@findex flush_i_cache
d4f3574e 22462On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
104c1213
JM
22463instruction cache, if any, on your target machine. If there is no
22464instruction cache, this subroutine may be a no-op.
22465
22466On target machines that have instruction caches, @value{GDBN} requires this
22467function to make certain that the state of your program is stable.
22468@end table
22469
22470@noindent
22471You must also make sure this library routine is available:
22472
22473@table @code
22474@item void *memset(void *, int, int)
4644b6e3 22475@findex memset
104c1213
JM
22476This is the standard library function @code{memset} that sets an area of
22477memory to a known value. If you have one of the free versions of
22478@code{libc.a}, @code{memset} can be found there; otherwise, you must
22479either obtain it from your hardware manufacturer, or write your own.
22480@end table
22481
22482If you do not use the GNU C compiler, you may need other standard
22483library subroutines as well; this varies from one stub to another,
22484but in general the stubs are likely to use any of the common library
e22ea452 22485subroutines which @code{@value{NGCC}} generates as inline code.
104c1213
JM
22486
22487
6d2ebf8b 22488@node Debug Session
79a6e687 22489@subsection Putting it All Together
104c1213
JM
22490
22491@cindex remote serial debugging summary
22492In summary, when your program is ready to debug, you must follow these
22493steps.
22494
22495@enumerate
22496@item
6d2ebf8b 22497Make sure you have defined the supporting low-level routines
79a6e687 22498(@pxref{Bootstrapping,,What You Must Do for the Stub}):
104c1213
JM
22499@display
22500@code{getDebugChar}, @code{putDebugChar},
22501@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
22502@end display
22503
22504@item
2fb860fc
PA
22505Insert these lines in your program's startup code, before the main
22506procedure is called:
104c1213 22507
474c8240 22508@smallexample
104c1213
JM
22509set_debug_traps();
22510breakpoint();
474c8240 22511@end smallexample
104c1213 22512
2fb860fc
PA
22513On some machines, when a breakpoint trap is raised, the hardware
22514automatically makes the PC point to the instruction after the
22515breakpoint. If your machine doesn't do that, you may need to adjust
22516@code{handle_exception} to arrange for it to return to the instruction
22517after the breakpoint on this first invocation, so that your program
22518doesn't keep hitting the initial breakpoint instead of making
22519progress.
22520
104c1213
JM
22521@item
22522For the 680x0 stub only, you need to provide a variable called
22523@code{exceptionHook}. Normally you just use:
22524
474c8240 22525@smallexample
104c1213 22526void (*exceptionHook)() = 0;
474c8240 22527@end smallexample
104c1213 22528
d4f3574e 22529@noindent
104c1213 22530but if before calling @code{set_debug_traps}, you set it to point to a
598ca718 22531function in your program, that function is called when
104c1213
JM
22532@code{@value{GDBN}} continues after stopping on a trap (for example, bus
22533error). The function indicated by @code{exceptionHook} is called with
22534one parameter: an @code{int} which is the exception number.
22535
22536@item
22537Compile and link together: your program, the @value{GDBN} debugging stub for
22538your target architecture, and the supporting subroutines.
22539
22540@item
22541Make sure you have a serial connection between your target machine and
22542the @value{GDBN} host, and identify the serial port on the host.
22543
22544@item
22545@c The "remote" target now provides a `load' command, so we should
22546@c document that. FIXME.
22547Download your program to your target machine (or get it there by
22548whatever means the manufacturer provides), and start it.
22549
22550@item
07f31aa6 22551Start @value{GDBN} on the host, and connect to the target
79a6e687 22552(@pxref{Connecting,,Connecting to a Remote Target}).
9db8d71f 22553
104c1213
JM
22554@end enumerate
22555
8e04817f
AC
22556@node Configurations
22557@chapter Configuration-Specific Information
104c1213 22558
8e04817f
AC
22559While nearly all @value{GDBN} commands are available for all native and
22560cross versions of the debugger, there are some exceptions. This chapter
22561describes things that are only available in certain configurations.
104c1213 22562
8e04817f
AC
22563There are three major categories of configurations: native
22564configurations, where the host and target are the same, embedded
22565operating system configurations, which are usually the same for several
22566different processor architectures, and bare embedded processors, which
22567are quite different from each other.
104c1213 22568
8e04817f
AC
22569@menu
22570* Native::
22571* Embedded OS::
22572* Embedded Processors::
22573* Architectures::
22574@end menu
104c1213 22575
8e04817f
AC
22576@node Native
22577@section Native
104c1213 22578
8e04817f
AC
22579This section describes details specific to particular native
22580configurations.
6cf7e474 22581
8e04817f 22582@menu
7561d450 22583* BSD libkvm Interface:: Debugging BSD kernel memory images
2d97a5d9 22584* Process Information:: Process information
8e04817f 22585* DJGPP Native:: Features specific to the DJGPP port
78c47bea 22586* Cygwin Native:: Features specific to the Cygwin port
14d6dd68 22587* Hurd Native:: Features specific to @sc{gnu} Hurd
a80b95ba 22588* Darwin:: Features specific to Darwin
e9076973 22589* FreeBSD:: Features specific to FreeBSD
8e04817f 22590@end menu
6cf7e474 22591
7561d450
MK
22592@node BSD libkvm Interface
22593@subsection BSD libkvm Interface
22594
22595@cindex libkvm
22596@cindex kernel memory image
22597@cindex kernel crash dump
22598
22599BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
22600interface that provides a uniform interface for accessing kernel virtual
22601memory images, including live systems and crash dumps. @value{GDBN}
22602uses this interface to allow you to debug live kernels and kernel crash
22603dumps on many native BSD configurations. This is implemented as a
22604special @code{kvm} debugging target. For debugging a live system, load
22605the currently running kernel into @value{GDBN} and connect to the
22606@code{kvm} target:
22607
22608@smallexample
22609(@value{GDBP}) @b{target kvm}
22610@end smallexample
22611
22612For debugging crash dumps, provide the file name of the crash dump as an
22613argument:
22614
22615@smallexample
22616(@value{GDBP}) @b{target kvm /var/crash/bsd.0}
22617@end smallexample
22618
22619Once connected to the @code{kvm} target, the following commands are
22620available:
22621
22622@table @code
22623@kindex kvm
22624@item kvm pcb
721c2651 22625Set current context from the @dfn{Process Control Block} (PCB) address.
7561d450
MK
22626
22627@item kvm proc
22628Set current context from proc address. This command isn't available on
22629modern FreeBSD systems.
22630@end table
22631
2d97a5d9
JB
22632@node Process Information
22633@subsection Process Information
60bf7e09
EZ
22634@cindex /proc
22635@cindex examine process image
22636@cindex process info via @file{/proc}
104c1213 22637
2d97a5d9
JB
22638Some operating systems provide interfaces to fetch additional
22639information about running processes beyond memory and per-thread
22640register state. If @value{GDBN} is configured for an operating system
22641with a supported interface, the command @code{info proc} is available
22642to report information about the process running your program, or about
22643any process running on your system.
451b7c33 22644
2d97a5d9
JB
22645One supported interface is a facility called @samp{/proc} that can be
22646used to examine the image of a running process using file-system
22647subroutines. This facility is supported on @sc{gnu}/Linux and Solaris
22648systems.
451b7c33 22649
2d97a5d9
JB
22650On FreeBSD systems, system control nodes are used to query process
22651information.
22652
22653In addition, some systems may provide additional process information
22654in core files. Note that a core file may include a subset of the
22655information available from a live process. Process information is
22656currently avaiable from cores created on @sc{gnu}/Linux and FreeBSD
22657systems.
104c1213 22658
8e04817f
AC
22659@table @code
22660@kindex info proc
60bf7e09 22661@cindex process ID
8e04817f 22662@item info proc
60bf7e09 22663@itemx info proc @var{process-id}
73f1bd76 22664Summarize available information about a process. If a
60bf7e09
EZ
22665process ID is specified by @var{process-id}, display information about
22666that process; otherwise display information about the program being
22667debugged. The summary includes the debugged process ID, the command
22668line used to invoke it, its current working directory, and its
22669executable file's absolute file name.
22670
22671On some systems, @var{process-id} can be of the form
22672@samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
22673within a process. If the optional @var{pid} part is missing, it means
22674a thread from the process being debugged (the leading @samp{/} still
22675needs to be present, or else @value{GDBN} will interpret the number as
22676a process ID rather than a thread ID).
6cf7e474 22677
0c631110
TT
22678@item info proc cmdline
22679@cindex info proc cmdline
22680Show the original command line of the process. This command is
2d97a5d9 22681supported on @sc{gnu}/Linux and FreeBSD.
0c631110
TT
22682
22683@item info proc cwd
22684@cindex info proc cwd
22685Show the current working directory of the process. This command is
2d97a5d9 22686supported on @sc{gnu}/Linux and FreeBSD.
0c631110
TT
22687
22688@item info proc exe
22689@cindex info proc exe
2d97a5d9
JB
22690Show the name of executable of the process. This command is supported
22691on @sc{gnu}/Linux and FreeBSD.
0c631110 22692
8b113111
JB
22693@item info proc files
22694@cindex info proc files
22695Show the file descriptors open by the process. For each open file
22696descriptor, @value{GDBN} shows its number, type (file, directory,
22697character device, socket), file pointer offset, and the name of the
22698resource open on the descriptor. The resource name can be a file name
22699(for files, directories, and devices) or a protocol followed by socket
22700address (for network connections). This command is supported on
22701FreeBSD.
22702
22703This example shows the open file descriptors for a process using a
22704tty for standard input and output as well as two network sockets:
22705
22706@smallexample
22707(gdb) info proc files 22136
22708process 22136
22709Open files:
22710
22711 FD Type Offset Flags Name
22712 text file - r-------- /usr/bin/ssh
22713 ctty chr - rw------- /dev/pts/20
22714 cwd dir - r-------- /usr/home/john
22715 root dir - r-------- /
22716 0 chr 0x32933a4 rw------- /dev/pts/20
22717 1 chr 0x32933a4 rw------- /dev/pts/20
22718 2 chr 0x32933a4 rw------- /dev/pts/20
22719 3 socket 0x0 rw----n-- tcp4 10.0.1.2:53014 -> 10.0.1.10:22
22720 4 socket 0x0 rw------- unix stream:/tmp/ssh-FIt89oAzOn5f/agent.2456
22721@end smallexample
22722
8e04817f 22723@item info proc mappings
60bf7e09 22724@cindex memory address space mappings
73f1bd76 22725Report the memory address space ranges accessible in a process. On
2d97a5d9
JB
22726Solaris and FreeBSD systems, each memory range includes information on
22727whether the process has read, write, or execute access rights to each
22728range. On @sc{gnu}/Linux and FreeBSD systems, each memory range
22729includes the object file which is mapped to that range.
60bf7e09
EZ
22730
22731@item info proc stat
22732@itemx info proc status
22733@cindex process detailed status information
2d97a5d9
JB
22734Show additional process-related information, including the user ID and
22735group ID; virtual memory usage; the signals that are pending, blocked,
22736and ignored; its TTY; its consumption of system and user time; its
22737stack size; its @samp{nice} value; etc. These commands are supported
22738on @sc{gnu}/Linux and FreeBSD.
22739
22740For @sc{gnu}/Linux systems, see the @samp{proc} man page for more
22741information (type @kbd{man 5 proc} from your shell prompt).
22742
22743For FreeBSD systems, @code{info proc stat} is an alias for @code{info
22744proc status}.
60bf7e09
EZ
22745
22746@item info proc all
22747Show all the information about the process described under all of the
22748above @code{info proc} subcommands.
22749
8e04817f
AC
22750@ignore
22751@comment These sub-options of 'info proc' were not included when
22752@comment procfs.c was re-written. Keep their descriptions around
22753@comment against the day when someone finds the time to put them back in.
22754@kindex info proc times
22755@item info proc times
22756Starting time, user CPU time, and system CPU time for your program and
22757its children.
6cf7e474 22758
8e04817f
AC
22759@kindex info proc id
22760@item info proc id
22761Report on the process IDs related to your program: its own process ID,
22762the ID of its parent, the process group ID, and the session ID.
8e04817f 22763@end ignore
721c2651
EZ
22764
22765@item set procfs-trace
22766@kindex set procfs-trace
22767@cindex @code{procfs} API calls
22768This command enables and disables tracing of @code{procfs} API calls.
22769
22770@item show procfs-trace
22771@kindex show procfs-trace
22772Show the current state of @code{procfs} API call tracing.
22773
22774@item set procfs-file @var{file}
22775@kindex set procfs-file
22776Tell @value{GDBN} to write @code{procfs} API trace to the named
22777@var{file}. @value{GDBN} appends the trace info to the previous
22778contents of the file. The default is to display the trace on the
22779standard output.
22780
22781@item show procfs-file
22782@kindex show procfs-file
22783Show the file to which @code{procfs} API trace is written.
22784
22785@item proc-trace-entry
22786@itemx proc-trace-exit
22787@itemx proc-untrace-entry
22788@itemx proc-untrace-exit
22789@kindex proc-trace-entry
22790@kindex proc-trace-exit
22791@kindex proc-untrace-entry
22792@kindex proc-untrace-exit
22793These commands enable and disable tracing of entries into and exits
22794from the @code{syscall} interface.
22795
22796@item info pidlist
22797@kindex info pidlist
22798@cindex process list, QNX Neutrino
22799For QNX Neutrino only, this command displays the list of all the
22800processes and all the threads within each process.
22801
22802@item info meminfo
22803@kindex info meminfo
22804@cindex mapinfo list, QNX Neutrino
22805For QNX Neutrino only, this command displays the list of all mapinfos.
8e04817f 22806@end table
104c1213 22807
8e04817f
AC
22808@node DJGPP Native
22809@subsection Features for Debugging @sc{djgpp} Programs
22810@cindex @sc{djgpp} debugging
22811@cindex native @sc{djgpp} debugging
22812@cindex MS-DOS-specific commands
104c1213 22813
514c4d71
EZ
22814@cindex DPMI
22815@sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
8e04817f
AC
22816MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
22817that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
22818top of real-mode DOS systems and their emulations.
104c1213 22819
8e04817f
AC
22820@value{GDBN} supports native debugging of @sc{djgpp} programs, and
22821defines a few commands specific to the @sc{djgpp} port. This
22822subsection describes those commands.
104c1213 22823
8e04817f
AC
22824@table @code
22825@kindex info dos
22826@item info dos
22827This is a prefix of @sc{djgpp}-specific commands which print
22828information about the target system and important OS structures.
f1251bdd 22829
8e04817f
AC
22830@kindex sysinfo
22831@cindex MS-DOS system info
22832@cindex free memory information (MS-DOS)
22833@item info dos sysinfo
22834This command displays assorted information about the underlying
22835platform: the CPU type and features, the OS version and flavor, the
22836DPMI version, and the available conventional and DPMI memory.
104c1213 22837
8e04817f
AC
22838@cindex GDT
22839@cindex LDT
22840@cindex IDT
22841@cindex segment descriptor tables
22842@cindex descriptor tables display
22843@item info dos gdt
22844@itemx info dos ldt
22845@itemx info dos idt
22846These 3 commands display entries from, respectively, Global, Local,
22847and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
22848tables are data structures which store a descriptor for each segment
22849that is currently in use. The segment's selector is an index into a
22850descriptor table; the table entry for that index holds the
22851descriptor's base address and limit, and its attributes and access
22852rights.
104c1213 22853
8e04817f
AC
22854A typical @sc{djgpp} program uses 3 segments: a code segment, a data
22855segment (used for both data and the stack), and a DOS segment (which
22856allows access to DOS/BIOS data structures and absolute addresses in
22857conventional memory). However, the DPMI host will usually define
22858additional segments in order to support the DPMI environment.
d4f3574e 22859
8e04817f
AC
22860@cindex garbled pointers
22861These commands allow to display entries from the descriptor tables.
22862Without an argument, all entries from the specified table are
22863displayed. An argument, which should be an integer expression, means
22864display a single entry whose index is given by the argument. For
22865example, here's a convenient way to display information about the
22866debugged program's data segment:
104c1213 22867
8e04817f
AC
22868@smallexample
22869@exdent @code{(@value{GDBP}) info dos ldt $ds}
22870@exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
22871@end smallexample
104c1213 22872
8e04817f
AC
22873@noindent
22874This comes in handy when you want to see whether a pointer is outside
22875the data segment's limit (i.e.@: @dfn{garbled}).
104c1213 22876
8e04817f
AC
22877@cindex page tables display (MS-DOS)
22878@item info dos pde
22879@itemx info dos pte
22880These two commands display entries from, respectively, the Page
22881Directory and the Page Tables. Page Directories and Page Tables are
22882data structures which control how virtual memory addresses are mapped
22883into physical addresses. A Page Table includes an entry for every
22884page of memory that is mapped into the program's address space; there
22885may be several Page Tables, each one holding up to 4096 entries. A
22886Page Directory has up to 4096 entries, one each for every Page Table
22887that is currently in use.
104c1213 22888
8e04817f
AC
22889Without an argument, @kbd{info dos pde} displays the entire Page
22890Directory, and @kbd{info dos pte} displays all the entries in all of
22891the Page Tables. An argument, an integer expression, given to the
22892@kbd{info dos pde} command means display only that entry from the Page
22893Directory table. An argument given to the @kbd{info dos pte} command
22894means display entries from a single Page Table, the one pointed to by
22895the specified entry in the Page Directory.
104c1213 22896
8e04817f
AC
22897@cindex direct memory access (DMA) on MS-DOS
22898These commands are useful when your program uses @dfn{DMA} (Direct
22899Memory Access), which needs physical addresses to program the DMA
22900controller.
104c1213 22901
8e04817f 22902These commands are supported only with some DPMI servers.
104c1213 22903
8e04817f
AC
22904@cindex physical address from linear address
22905@item info dos address-pte @var{addr}
22906This command displays the Page Table entry for a specified linear
514c4d71
EZ
22907address. The argument @var{addr} is a linear address which should
22908already have the appropriate segment's base address added to it,
22909because this command accepts addresses which may belong to @emph{any}
22910segment. For example, here's how to display the Page Table entry for
22911the page where a variable @code{i} is stored:
104c1213 22912
b383017d 22913@smallexample
8e04817f
AC
22914@exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
22915@exdent @code{Page Table entry for address 0x11a00d30:}
b383017d 22916@exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
8e04817f 22917@end smallexample
104c1213 22918
8e04817f
AC
22919@noindent
22920This says that @code{i} is stored at offset @code{0xd30} from the page
514c4d71 22921whose physical base address is @code{0x02698000}, and shows all the
8e04817f 22922attributes of that page.
104c1213 22923
8e04817f
AC
22924Note that you must cast the addresses of variables to a @code{char *},
22925since otherwise the value of @code{__djgpp_base_address}, the base
22926address of all variables and functions in a @sc{djgpp} program, will
22927be added using the rules of C pointer arithmetics: if @code{i} is
22928declared an @code{int}, @value{GDBN} will add 4 times the value of
22929@code{__djgpp_base_address} to the address of @code{i}.
104c1213 22930
8e04817f
AC
22931Here's another example, it displays the Page Table entry for the
22932transfer buffer:
104c1213 22933
8e04817f
AC
22934@smallexample
22935@exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
22936@exdent @code{Page Table entry for address 0x29110:}
22937@exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
22938@end smallexample
104c1213 22939
8e04817f
AC
22940@noindent
22941(The @code{+ 3} offset is because the transfer buffer's address is the
514c4d71
EZ
229423rd member of the @code{_go32_info_block} structure.) The output
22943clearly shows that this DPMI server maps the addresses in conventional
22944memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
22945linear (@code{0x29110}) addresses are identical.
104c1213 22946
8e04817f
AC
22947This command is supported only with some DPMI servers.
22948@end table
104c1213 22949
c45da7e6 22950@cindex DOS serial data link, remote debugging
a8f24a35
EZ
22951In addition to native debugging, the DJGPP port supports remote
22952debugging via a serial data link. The following commands are specific
22953to remote serial debugging in the DJGPP port of @value{GDBN}.
22954
22955@table @code
22956@kindex set com1base
22957@kindex set com1irq
22958@kindex set com2base
22959@kindex set com2irq
22960@kindex set com3base
22961@kindex set com3irq
22962@kindex set com4base
22963@kindex set com4irq
22964@item set com1base @var{addr}
22965This command sets the base I/O port address of the @file{COM1} serial
22966port.
22967
22968@item set com1irq @var{irq}
22969This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
22970for the @file{COM1} serial port.
22971
22972There are similar commands @samp{set com2base}, @samp{set com3irq},
22973etc.@: for setting the port address and the @code{IRQ} lines for the
22974other 3 COM ports.
22975
22976@kindex show com1base
22977@kindex show com1irq
22978@kindex show com2base
22979@kindex show com2irq
22980@kindex show com3base
22981@kindex show com3irq
22982@kindex show com4base
22983@kindex show com4irq
22984The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
22985display the current settings of the base address and the @code{IRQ}
22986lines used by the COM ports.
c45da7e6
EZ
22987
22988@item info serial
22989@kindex info serial
22990@cindex DOS serial port status
22991This command prints the status of the 4 DOS serial ports. For each
22992port, it prints whether it's active or not, its I/O base address and
22993IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
22994counts of various errors encountered so far.
a8f24a35
EZ
22995@end table
22996
22997
78c47bea 22998@node Cygwin Native
79a6e687 22999@subsection Features for Debugging MS Windows PE Executables
78c47bea
PM
23000@cindex MS Windows debugging
23001@cindex native Cygwin debugging
23002@cindex Cygwin-specific commands
23003
be448670 23004@value{GDBN} supports native debugging of MS Windows programs, including
cbb8f428
EZ
23005DLLs with and without symbolic debugging information.
23006
23007@cindex Ctrl-BREAK, MS-Windows
23008@cindex interrupt debuggee on MS-Windows
23009MS-Windows programs that call @code{SetConsoleMode} to switch off the
23010special meaning of the @samp{Ctrl-C} keystroke cannot be interrupted
23011by typing @kbd{C-c}. For this reason, @value{GDBN} on MS-Windows
23012supports @kbd{C-@key{BREAK}} as an alternative interrupt key
23013sequence, which can be used to interrupt the debuggee even if it
23014ignores @kbd{C-c}.
23015
23016There are various additional Cygwin-specific commands, described in
23017this section. Working with DLLs that have no debugging symbols is
23018described in @ref{Non-debug DLL Symbols}.
78c47bea
PM
23019
23020@table @code
23021@kindex info w32
23022@item info w32
db2e3e2e 23023This is a prefix of MS Windows-specific commands which print
78c47bea
PM
23024information about the target system and important OS structures.
23025
23026@item info w32 selector
23027This command displays information returned by
23028the Win32 API @code{GetThreadSelectorEntry} function.
23029It takes an optional argument that is evaluated to
23030a long value to give the information about this given selector.
23031Without argument, this command displays information
d3e8051b 23032about the six segment registers.
78c47bea 23033
711e434b
PM
23034@item info w32 thread-information-block
23035This command displays thread specific information stored in the
23036Thread Information Block (readable on the X86 CPU family using @code{$fs}
23037selector for 32-bit programs and @code{$gs} for 64-bit programs).
23038
463888ab
РИ
23039@kindex signal-event
23040@item signal-event @var{id}
23041This command signals an event with user-provided @var{id}. Used to resume
23042crashing process when attached to it using MS-Windows JIT debugging (AeDebug).
23043
23044To use it, create or edit the following keys in
23045@code{HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug} and/or
23046@code{HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\AeDebug}
23047(for x86_64 versions):
23048
23049@itemize @minus
23050@item
23051@code{Debugger} (REG_SZ) --- a command to launch the debugger.
23052Suggested command is: @code{@var{fully-qualified-path-to-gdb.exe} -ex
23053"attach %ld" -ex "signal-event %ld" -ex "continue"}.
23054
23055The first @code{%ld} will be replaced by the process ID of the
23056crashing process, the second @code{%ld} will be replaced by the ID of
23057the event that blocks the crashing process, waiting for @value{GDBN}
23058to attach.
23059
23060@item
23061@code{Auto} (REG_SZ) --- either @code{1} or @code{0}. @code{1} will
23062make the system run debugger specified by the Debugger key
23063automatically, @code{0} will cause a dialog box with ``OK'' and
23064``Cancel'' buttons to appear, which allows the user to either
23065terminate the crashing process (OK) or debug it (Cancel).
23066@end itemize
23067
be90c084 23068@kindex set cygwin-exceptions
e16b02ee
EZ
23069@cindex debugging the Cygwin DLL
23070@cindex Cygwin DLL, debugging
be90c084 23071@item set cygwin-exceptions @var{mode}
e16b02ee
EZ
23072If @var{mode} is @code{on}, @value{GDBN} will break on exceptions that
23073happen inside the Cygwin DLL. If @var{mode} is @code{off},
23074@value{GDBN} will delay recognition of exceptions, and may ignore some
23075exceptions which seem to be caused by internal Cygwin DLL
23076``bookkeeping''. This option is meant primarily for debugging the
23077Cygwin DLL itself; the default value is @code{off} to avoid annoying
23078@value{GDBN} users with false @code{SIGSEGV} signals.
be90c084
CF
23079
23080@kindex show cygwin-exceptions
23081@item show cygwin-exceptions
e16b02ee
EZ
23082Displays whether @value{GDBN} will break on exceptions that happen
23083inside the Cygwin DLL itself.
be90c084 23084
b383017d 23085@kindex set new-console
78c47bea 23086@item set new-console @var{mode}
b383017d 23087If @var{mode} is @code{on} the debuggee will
78c47bea 23088be started in a new console on next start.
e03e5e7b 23089If @var{mode} is @code{off}, the debuggee will
78c47bea
PM
23090be started in the same console as the debugger.
23091
23092@kindex show new-console
23093@item show new-console
23094Displays whether a new console is used
23095when the debuggee is started.
23096
23097@kindex set new-group
23098@item set new-group @var{mode}
23099This boolean value controls whether the debuggee should
23100start a new group or stay in the same group as the debugger.
23101This affects the way the Windows OS handles
c8aa23ab 23102@samp{Ctrl-C}.
78c47bea
PM
23103
23104@kindex show new-group
23105@item show new-group
23106Displays current value of new-group boolean.
23107
23108@kindex set debugevents
23109@item set debugevents
219eec71
EZ
23110This boolean value adds debug output concerning kernel events related
23111to the debuggee seen by the debugger. This includes events that
23112signal thread and process creation and exit, DLL loading and
23113unloading, console interrupts, and debugging messages produced by the
23114Windows @code{OutputDebugString} API call.
78c47bea
PM
23115
23116@kindex set debugexec
23117@item set debugexec
b383017d 23118This boolean value adds debug output concerning execute events
219eec71 23119(such as resume thread) seen by the debugger.
78c47bea
PM
23120
23121@kindex set debugexceptions
23122@item set debugexceptions
219eec71
EZ
23123This boolean value adds debug output concerning exceptions in the
23124debuggee seen by the debugger.
78c47bea
PM
23125
23126@kindex set debugmemory
23127@item set debugmemory
219eec71
EZ
23128This boolean value adds debug output concerning debuggee memory reads
23129and writes by the debugger.
78c47bea
PM
23130
23131@kindex set shell
23132@item set shell
23133This boolean values specifies whether the debuggee is called
23134via a shell or directly (default value is on).
23135
23136@kindex show shell
23137@item show shell
23138Displays if the debuggee will be started with a shell.
23139
23140@end table
23141
be448670 23142@menu
79a6e687 23143* Non-debug DLL Symbols:: Support for DLLs without debugging symbols
be448670
CF
23144@end menu
23145
79a6e687
BW
23146@node Non-debug DLL Symbols
23147@subsubsection Support for DLLs without Debugging Symbols
be448670
CF
23148@cindex DLLs with no debugging symbols
23149@cindex Minimal symbols and DLLs
23150
23151Very often on windows, some of the DLLs that your program relies on do
23152not include symbolic debugging information (for example,
db2e3e2e 23153@file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
be448670 23154symbols in a DLL, it relies on the minimal amount of symbolic
db2e3e2e 23155information contained in the DLL's export table. This section
be448670
CF
23156describes working with such symbols, known internally to @value{GDBN} as
23157``minimal symbols''.
23158
23159Note that before the debugged program has started execution, no DLLs
db2e3e2e 23160will have been loaded. The easiest way around this problem is simply to
be448670 23161start the program --- either by setting a breakpoint or letting the
95060284 23162program run once to completion.
be448670 23163
79a6e687 23164@subsubsection DLL Name Prefixes
be448670
CF
23165
23166In keeping with the naming conventions used by the Microsoft debugging
23167tools, DLL export symbols are made available with a prefix based on the
23168DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
23169also entered into the symbol table, so @code{CreateFileA} is often
99e008fe 23170sufficient. In some cases there will be name clashes within a program
be448670
CF
23171(particularly if the executable itself includes full debugging symbols)
23172necessitating the use of the fully qualified name when referring to the
99e008fe 23173contents of the DLL. Use single-quotes around the name to avoid the
be448670
CF
23174exclamation mark (``!'') being interpreted as a language operator.
23175
23176Note that the internal name of the DLL may be all upper-case, even
99e008fe 23177though the file name of the DLL is lower-case, or vice-versa. Since
be448670
CF
23178symbols within @value{GDBN} are @emph{case-sensitive} this may cause
23179some confusion. If in doubt, try the @code{info functions} and
0869d01b
NR
23180@code{info variables} commands or even @code{maint print msymbols}
23181(@pxref{Symbols}). Here's an example:
be448670
CF
23182
23183@smallexample
f7dc1244 23184(@value{GDBP}) info function CreateFileA
be448670
CF
23185All functions matching regular expression "CreateFileA":
23186
23187Non-debugging symbols:
231880x77e885f4 CreateFileA
231890x77e885f4 KERNEL32!CreateFileA
23190@end smallexample
23191
23192@smallexample
f7dc1244 23193(@value{GDBP}) info function !
be448670
CF
23194All functions matching regular expression "!":
23195
23196Non-debugging symbols:
231970x6100114c cygwin1!__assert
231980x61004034 cygwin1!_dll_crt0@@0
231990x61004240 cygwin1!dll_crt0(per_process *)
23200[etc...]
23201@end smallexample
23202
79a6e687 23203@subsubsection Working with Minimal Symbols
be448670
CF
23204
23205Symbols extracted from a DLL's export table do not contain very much
23206type information. All that @value{GDBN} can do is guess whether a symbol
23207refers to a function or variable depending on the linker section that
23208contains the symbol. Also note that the actual contents of the memory
23209contained in a DLL are not available unless the program is running. This
23210means that you cannot examine the contents of a variable or disassemble
23211a function within a DLL without a running program.
23212
23213Variables are generally treated as pointers and dereferenced
23214automatically. For this reason, it is often necessary to prefix a
23215variable name with the address-of operator (``&'') and provide explicit
23216type information in the command. Here's an example of the type of
23217problem:
23218
23219@smallexample
f7dc1244 23220(@value{GDBP}) print 'cygwin1!__argv'
d69cf9b2 23221'cygwin1!__argv' has unknown type; cast it to its declared type
be448670
CF
23222@end smallexample
23223
23224@smallexample
f7dc1244 23225(@value{GDBP}) x 'cygwin1!__argv'
d69cf9b2 23226'cygwin1!__argv' has unknown type; cast it to its declared type
be448670
CF
23227@end smallexample
23228
23229And two possible solutions:
23230
23231@smallexample
f7dc1244 23232(@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
be448670
CF
23233$2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
23234@end smallexample
23235
23236@smallexample
f7dc1244 23237(@value{GDBP}) x/2x &'cygwin1!__argv'
be448670 232380x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
f7dc1244 23239(@value{GDBP}) x/x 0x10021608
be448670 232400x10021608: 0x0022fd98
f7dc1244 23241(@value{GDBP}) x/s 0x0022fd98
be448670
CF
232420x22fd98: "/cygdrive/c/mydirectory/myprogram"
23243@end smallexample
23244
23245Setting a break point within a DLL is possible even before the program
23246starts execution. However, under these circumstances, @value{GDBN} can't
23247examine the initial instructions of the function in order to skip the
23248function's frame set-up code. You can work around this by using ``*&''
23249to set the breakpoint at a raw memory address:
23250
23251@smallexample
f7dc1244 23252(@value{GDBP}) break *&'python22!PyOS_Readline'
be448670
CF
23253Breakpoint 1 at 0x1e04eff0
23254@end smallexample
23255
23256The author of these extensions is not entirely convinced that setting a
23257break point within a shared DLL like @file{kernel32.dll} is completely
23258safe.
23259
14d6dd68 23260@node Hurd Native
79a6e687 23261@subsection Commands Specific to @sc{gnu} Hurd Systems
14d6dd68
EZ
23262@cindex @sc{gnu} Hurd debugging
23263
23264This subsection describes @value{GDBN} commands specific to the
23265@sc{gnu} Hurd native debugging.
23266
23267@table @code
23268@item set signals
23269@itemx set sigs
23270@kindex set signals@r{, Hurd command}
23271@kindex set sigs@r{, Hurd command}
23272This command toggles the state of inferior signal interception by
23273@value{GDBN}. Mach exceptions, such as breakpoint traps, are not
23274affected by this command. @code{sigs} is a shorthand alias for
23275@code{signals}.
23276
23277@item show signals
23278@itemx show sigs
23279@kindex show signals@r{, Hurd command}
23280@kindex show sigs@r{, Hurd command}
23281Show the current state of intercepting inferior's signals.
23282
23283@item set signal-thread
23284@itemx set sigthread
23285@kindex set signal-thread
23286@kindex set sigthread
23287This command tells @value{GDBN} which thread is the @code{libc} signal
23288thread. That thread is run when a signal is delivered to a running
23289process. @code{set sigthread} is the shorthand alias of @code{set
23290signal-thread}.
23291
23292@item show signal-thread
23293@itemx show sigthread
23294@kindex show signal-thread
23295@kindex show sigthread
23296These two commands show which thread will run when the inferior is
23297delivered a signal.
23298
23299@item set stopped
23300@kindex set stopped@r{, Hurd command}
23301This commands tells @value{GDBN} that the inferior process is stopped,
23302as with the @code{SIGSTOP} signal. The stopped process can be
23303continued by delivering a signal to it.
23304
23305@item show stopped
23306@kindex show stopped@r{, Hurd command}
23307This command shows whether @value{GDBN} thinks the debuggee is
23308stopped.
23309
23310@item set exceptions
23311@kindex set exceptions@r{, Hurd command}
23312Use this command to turn off trapping of exceptions in the inferior.
23313When exception trapping is off, neither breakpoints nor
23314single-stepping will work. To restore the default, set exception
23315trapping on.
23316
23317@item show exceptions
23318@kindex show exceptions@r{, Hurd command}
23319Show the current state of trapping exceptions in the inferior.
23320
23321@item set task pause
23322@kindex set task@r{, Hurd commands}
23323@cindex task attributes (@sc{gnu} Hurd)
23324@cindex pause current task (@sc{gnu} Hurd)
23325This command toggles task suspension when @value{GDBN} has control.
23326Setting it to on takes effect immediately, and the task is suspended
23327whenever @value{GDBN} gets control. Setting it to off will take
23328effect the next time the inferior is continued. If this option is set
23329to off, you can use @code{set thread default pause on} or @code{set
23330thread pause on} (see below) to pause individual threads.
23331
23332@item show task pause
23333@kindex show task@r{, Hurd commands}
23334Show the current state of task suspension.
23335
23336@item set task detach-suspend-count
23337@cindex task suspend count
23338@cindex detach from task, @sc{gnu} Hurd
23339This command sets the suspend count the task will be left with when
23340@value{GDBN} detaches from it.
23341
23342@item show task detach-suspend-count
23343Show the suspend count the task will be left with when detaching.
23344
23345@item set task exception-port
23346@itemx set task excp
23347@cindex task exception port, @sc{gnu} Hurd
23348This command sets the task exception port to which @value{GDBN} will
23349forward exceptions. The argument should be the value of the @dfn{send
23350rights} of the task. @code{set task excp} is a shorthand alias.
23351
23352@item set noninvasive
23353@cindex noninvasive task options
23354This command switches @value{GDBN} to a mode that is the least
23355invasive as far as interfering with the inferior is concerned. This
23356is the same as using @code{set task pause}, @code{set exceptions}, and
23357@code{set signals} to values opposite to the defaults.
23358
23359@item info send-rights
23360@itemx info receive-rights
23361@itemx info port-rights
23362@itemx info port-sets
23363@itemx info dead-names
23364@itemx info ports
23365@itemx info psets
23366@cindex send rights, @sc{gnu} Hurd
23367@cindex receive rights, @sc{gnu} Hurd
23368@cindex port rights, @sc{gnu} Hurd
23369@cindex port sets, @sc{gnu} Hurd
23370@cindex dead names, @sc{gnu} Hurd
23371These commands display information about, respectively, send rights,
23372receive rights, port rights, port sets, and dead names of a task.
23373There are also shorthand aliases: @code{info ports} for @code{info
23374port-rights} and @code{info psets} for @code{info port-sets}.
23375
23376@item set thread pause
23377@kindex set thread@r{, Hurd command}
23378@cindex thread properties, @sc{gnu} Hurd
23379@cindex pause current thread (@sc{gnu} Hurd)
23380This command toggles current thread suspension when @value{GDBN} has
23381control. Setting it to on takes effect immediately, and the current
23382thread is suspended whenever @value{GDBN} gets control. Setting it to
23383off will take effect the next time the inferior is continued.
23384Normally, this command has no effect, since when @value{GDBN} has
23385control, the whole task is suspended. However, if you used @code{set
23386task pause off} (see above), this command comes in handy to suspend
23387only the current thread.
23388
23389@item show thread pause
23390@kindex show thread@r{, Hurd command}
23391This command shows the state of current thread suspension.
23392
23393@item set thread run
d3e8051b 23394This command sets whether the current thread is allowed to run.
14d6dd68
EZ
23395
23396@item show thread run
23397Show whether the current thread is allowed to run.
23398
23399@item set thread detach-suspend-count
23400@cindex thread suspend count, @sc{gnu} Hurd
23401@cindex detach from thread, @sc{gnu} Hurd
23402This command sets the suspend count @value{GDBN} will leave on a
23403thread when detaching. This number is relative to the suspend count
23404found by @value{GDBN} when it notices the thread; use @code{set thread
23405takeover-suspend-count} to force it to an absolute value.
23406
23407@item show thread detach-suspend-count
23408Show the suspend count @value{GDBN} will leave on the thread when
23409detaching.
23410
23411@item set thread exception-port
23412@itemx set thread excp
23413Set the thread exception port to which to forward exceptions. This
23414overrides the port set by @code{set task exception-port} (see above).
23415@code{set thread excp} is the shorthand alias.
23416
23417@item set thread takeover-suspend-count
23418Normally, @value{GDBN}'s thread suspend counts are relative to the
23419value @value{GDBN} finds when it notices each thread. This command
23420changes the suspend counts to be absolute instead.
23421
23422@item set thread default
23423@itemx show thread default
23424@cindex thread default settings, @sc{gnu} Hurd
23425Each of the above @code{set thread} commands has a @code{set thread
23426default} counterpart (e.g., @code{set thread default pause}, @code{set
23427thread default exception-port}, etc.). The @code{thread default}
23428variety of commands sets the default thread properties for all
23429threads; you can then change the properties of individual threads with
23430the non-default commands.
23431@end table
23432
a80b95ba
TG
23433@node Darwin
23434@subsection Darwin
23435@cindex Darwin
23436
23437@value{GDBN} provides the following commands specific to the Darwin target:
23438
23439@table @code
23440@item set debug darwin @var{num}
23441@kindex set debug darwin
23442When set to a non zero value, enables debugging messages specific to
23443the Darwin support. Higher values produce more verbose output.
23444
23445@item show debug darwin
23446@kindex show debug darwin
23447Show the current state of Darwin messages.
23448
23449@item set debug mach-o @var{num}
23450@kindex set debug mach-o
23451When set to a non zero value, enables debugging messages while
23452@value{GDBN} is reading Darwin object files. (@dfn{Mach-O} is the
23453file format used on Darwin for object and executable files.) Higher
23454values produce more verbose output. This is a command to diagnose
23455problems internal to @value{GDBN} and should not be needed in normal
23456usage.
23457
23458@item show debug mach-o
23459@kindex show debug mach-o
23460Show the current state of Mach-O file messages.
23461
23462@item set mach-exceptions on
23463@itemx set mach-exceptions off
23464@kindex set mach-exceptions
23465On Darwin, faults are first reported as a Mach exception and are then
23466mapped to a Posix signal. Use this command to turn on trapping of
23467Mach exceptions in the inferior. This might be sometimes useful to
23468better understand the cause of a fault. The default is off.
23469
23470@item show mach-exceptions
23471@kindex show mach-exceptions
23472Show the current state of exceptions trapping.
23473@end table
23474
e9076973
JB
23475@node FreeBSD
23476@subsection FreeBSD
23477@cindex FreeBSD
23478
23479When the ABI of a system call is changed in the FreeBSD kernel, this
23480is implemented by leaving a compatibility system call using the old
23481ABI at the existing number and allocating a new system call number for
23482the version using the new ABI. As a convenience, when a system call
23483is caught by name (@pxref{catch syscall}), compatibility system calls
23484are also caught.
23485
23486For example, FreeBSD 12 introduced a new variant of the @code{kevent}
23487system call and catching the @code{kevent} system call by name catches
23488both variants:
23489
23490@smallexample
23491(@value{GDBP}) catch syscall kevent
23492Catchpoint 1 (syscalls 'freebsd11_kevent' [363] 'kevent' [560])
23493(@value{GDBP})
23494@end smallexample
23495
a64548ea 23496
8e04817f
AC
23497@node Embedded OS
23498@section Embedded Operating Systems
104c1213 23499
8e04817f
AC
23500This section describes configurations involving the debugging of
23501embedded operating systems that are available for several different
23502architectures.
d4f3574e 23503
8e04817f
AC
23504@value{GDBN} includes the ability to debug programs running on
23505various real-time operating systems.
104c1213 23506
6d2ebf8b 23507@node Embedded Processors
104c1213
JM
23508@section Embedded Processors
23509
23510This section goes into details specific to particular embedded
23511configurations.
23512
c45da7e6
EZ
23513@cindex send command to simulator
23514Whenever a specific embedded processor has a simulator, @value{GDBN}
23515allows to send an arbitrary command to the simulator.
23516
23517@table @code
23518@item sim @var{command}
23519@kindex sim@r{, a command}
23520Send an arbitrary @var{command} string to the simulator. Consult the
23521documentation for the specific simulator in use for information about
23522acceptable commands.
23523@end table
23524
7d86b5d5 23525
104c1213 23526@menu
ad0a504f 23527* ARC:: Synopsys ARC
bb615428 23528* ARM:: ARM
104c1213 23529* M68K:: Motorola M68K
08be9d71 23530* MicroBlaze:: Xilinx MicroBlaze
104c1213 23531* MIPS Embedded:: MIPS Embedded
a994fec4 23532* OpenRISC 1000:: OpenRISC 1000 (or1k)
4acd40f3 23533* PowerPC Embedded:: PowerPC Embedded
a64548ea
EZ
23534* AVR:: Atmel AVR
23535* CRIS:: CRIS
23536* Super-H:: Renesas Super-H
104c1213
JM
23537@end menu
23538
ad0a504f
AK
23539@node ARC
23540@subsection Synopsys ARC
23541@cindex Synopsys ARC
23542@cindex ARC specific commands
23543@cindex ARC600
23544@cindex ARC700
23545@cindex ARC EM
23546@cindex ARC HS
23547
23548@value{GDBN} provides the following ARC-specific commands:
23549
23550@table @code
23551@item set debug arc
23552@kindex set debug arc
23553Control the level of ARC specific debug messages. Use 0 for no messages (the
fe5f7374 23554default), 1 for debug messages, and 2 for even more debug messages.
ad0a504f
AK
23555
23556@item show debug arc
23557@kindex show debug arc
23558Show the level of ARC specific debugging in operation.
23559
eea78757
AK
23560@item maint print arc arc-instruction @var{address}
23561@kindex maint print arc arc-instruction
23562Print internal disassembler information about instruction at a given address.
23563
ad0a504f
AK
23564@end table
23565
6d2ebf8b 23566@node ARM
104c1213 23567@subsection ARM
8e04817f 23568
e2f4edfd
EZ
23569@value{GDBN} provides the following ARM-specific commands:
23570
23571@table @code
23572@item set arm disassembler
23573@kindex set arm
23574This commands selects from a list of disassembly styles. The
23575@code{"std"} style is the standard style.
23576
23577@item show arm disassembler
23578@kindex show arm
23579Show the current disassembly style.
23580
23581@item set arm apcs32
23582@cindex ARM 32-bit mode
23583This command toggles ARM operation mode between 32-bit and 26-bit.
23584
23585@item show arm apcs32
23586Display the current usage of the ARM 32-bit mode.
23587
23588@item set arm fpu @var{fputype}
23589This command sets the ARM floating-point unit (FPU) type. The
23590argument @var{fputype} can be one of these:
23591
23592@table @code
23593@item auto
23594Determine the FPU type by querying the OS ABI.
23595@item softfpa
23596Software FPU, with mixed-endian doubles on little-endian ARM
23597processors.
23598@item fpa
23599GCC-compiled FPA co-processor.
23600@item softvfp
23601Software FPU with pure-endian doubles.
23602@item vfp
23603VFP co-processor.
23604@end table
23605
23606@item show arm fpu
23607Show the current type of the FPU.
23608
23609@item set arm abi
23610This command forces @value{GDBN} to use the specified ABI.
23611
23612@item show arm abi
23613Show the currently used ABI.
23614
0428b8f5
DJ
23615@item set arm fallback-mode (arm|thumb|auto)
23616@value{GDBN} uses the symbol table, when available, to determine
23617whether instructions are ARM or Thumb. This command controls
23618@value{GDBN}'s default behavior when the symbol table is not
23619available. The default is @samp{auto}, which causes @value{GDBN} to
23620use the current execution mode (from the @code{T} bit in the @code{CPSR}
23621register).
23622
23623@item show arm fallback-mode
23624Show the current fallback instruction mode.
23625
23626@item set arm force-mode (arm|thumb|auto)
23627This command overrides use of the symbol table to determine whether
23628instructions are ARM or Thumb. The default is @samp{auto}, which
23629causes @value{GDBN} to use the symbol table and then the setting
23630of @samp{set arm fallback-mode}.
23631
23632@item show arm force-mode
23633Show the current forced instruction mode.
23634
e2f4edfd
EZ
23635@item set debug arm
23636Toggle whether to display ARM-specific debugging messages from the ARM
23637target support subsystem.
23638
23639@item show debug arm
23640Show whether ARM-specific debugging messages are enabled.
23641@end table
23642
ee8e71d4
EZ
23643@table @code
23644@item target sim @r{[}@var{simargs}@r{]} @dots{}
23645The @value{GDBN} ARM simulator accepts the following optional arguments.
23646
23647@table @code
23648@item --swi-support=@var{type}
697aa1b7 23649Tell the simulator which SWI interfaces to support. The argument
ee8e71d4
EZ
23650@var{type} may be a comma separated list of the following values.
23651The default value is @code{all}.
23652
23653@table @code
23654@item none
23655@item demon
23656@item angel
23657@item redboot
23658@item all
23659@end table
23660@end table
23661@end table
e2f4edfd 23662
8e04817f
AC
23663@node M68K
23664@subsection M68k
23665
bb615428 23666The Motorola m68k configuration includes ColdFire support.
8e04817f 23667
08be9d71
ME
23668@node MicroBlaze
23669@subsection MicroBlaze
23670@cindex Xilinx MicroBlaze
23671@cindex XMD, Xilinx Microprocessor Debugger
23672
23673The MicroBlaze is a soft-core processor supported on various Xilinx
23674FPGAs, such as Spartan or Virtex series. Boards with these processors
23675usually have JTAG ports which connect to a host system running the Xilinx
23676Embedded Development Kit (EDK) or Software Development Kit (SDK).
23677This host system is used to download the configuration bitstream to
23678the target FPGA. The Xilinx Microprocessor Debugger (XMD) program
23679communicates with the target board using the JTAG interface and
23680presents a @code{gdbserver} interface to the board. By default
23681@code{xmd} uses port @code{1234}. (While it is possible to change
23682this default port, it requires the use of undocumented @code{xmd}
23683commands. Contact Xilinx support if you need to do this.)
23684
23685Use these GDB commands to connect to the MicroBlaze target processor.
23686
23687@table @code
23688@item target remote :1234
23689Use this command to connect to the target if you are running @value{GDBN}
23690on the same system as @code{xmd}.
23691
23692@item target remote @var{xmd-host}:1234
23693Use this command to connect to the target if it is connected to @code{xmd}
23694running on a different system named @var{xmd-host}.
23695
23696@item load
23697Use this command to download a program to the MicroBlaze target.
23698
23699@item set debug microblaze @var{n}
23700Enable MicroBlaze-specific debugging messages if non-zero.
23701
23702@item show debug microblaze @var{n}
23703Show MicroBlaze-specific debugging level.
23704@end table
23705
8e04817f 23706@node MIPS Embedded
eb17f351 23707@subsection @acronym{MIPS} Embedded
8e04817f 23708
8e04817f 23709@noindent
f7c38292 23710@value{GDBN} supports these special commands for @acronym{MIPS} targets:
104c1213 23711
8e04817f 23712@table @code
8e04817f
AC
23713@item set mipsfpu double
23714@itemx set mipsfpu single
23715@itemx set mipsfpu none
a64548ea 23716@itemx set mipsfpu auto
8e04817f
AC
23717@itemx show mipsfpu
23718@kindex set mipsfpu
23719@kindex show mipsfpu
eb17f351
EZ
23720@cindex @acronym{MIPS} remote floating point
23721@cindex floating point, @acronym{MIPS} remote
23722If your target board does not support the @acronym{MIPS} floating point
8e04817f
AC
23723coprocessor, you should use the command @samp{set mipsfpu none} (if you
23724need this, you may wish to put the command in your @value{GDBN} init
23725file). This tells @value{GDBN} how to find the return value of
23726functions which return floating point values. It also allows
23727@value{GDBN} to avoid saving the floating point registers when calling
23728functions on the board. If you are using a floating point coprocessor
23729with only single precision floating point support, as on the @sc{r4650}
23730processor, use the command @samp{set mipsfpu single}. The default
23731double precision floating point coprocessor may be selected using
23732@samp{set mipsfpu double}.
104c1213 23733
8e04817f
AC
23734In previous versions the only choices were double precision or no
23735floating point, so @samp{set mipsfpu on} will select double precision
23736and @samp{set mipsfpu off} will select no floating point.
104c1213 23737
8e04817f
AC
23738As usual, you can inquire about the @code{mipsfpu} variable with
23739@samp{show mipsfpu}.
8e04817f 23740@end table
104c1213 23741
a994fec4
FJ
23742@node OpenRISC 1000
23743@subsection OpenRISC 1000
23744@cindex OpenRISC 1000
23745
23746@noindent
23747The OpenRISC 1000 provides a free RISC instruction set architecture. It is
23748mainly provided as a soft-core which can run on Xilinx, Altera and other
23749FPGA's.
23750
23751@value{GDBN} for OpenRISC supports the below commands when connecting to
23752a target:
23753
23754@table @code
23755
23756@kindex target sim
23757@item target sim
23758
23759Runs the builtin CPU simulator which can run very basic
23760programs but does not support most hardware functions like MMU.
23761For more complex use cases the user is advised to run an external
23762target, and connect using @samp{target remote}.
23763
23764Example: @code{target sim}
23765
23766@item set debug or1k
23767Toggle whether to display OpenRISC-specific debugging messages from the
23768OpenRISC target support subsystem.
23769
23770@item show debug or1k
23771Show whether OpenRISC-specific debugging messages are enabled.
23772@end table
23773
4acd40f3
TJB
23774@node PowerPC Embedded
23775@subsection PowerPC Embedded
104c1213 23776
66b73624
TJB
23777@cindex DVC register
23778@value{GDBN} supports using the DVC (Data Value Compare) register to
23779implement in hardware simple hardware watchpoint conditions of the form:
23780
23781@smallexample
23782(@value{GDBP}) watch @var{ADDRESS|VARIABLE} \
23783 if @var{ADDRESS|VARIABLE} == @var{CONSTANT EXPRESSION}
23784@end smallexample
23785
e09342b5
TJB
23786The DVC register will be automatically used when @value{GDBN} detects
23787such pattern in a condition expression, and the created watchpoint uses one
23788debug register (either the @code{exact-watchpoints} option is on and the
23789variable is scalar, or the variable has a length of one byte). This feature
23790is available in native @value{GDBN} running on a Linux kernel version 2.6.34
23791or newer.
23792
23793When running on PowerPC embedded processors, @value{GDBN} automatically uses
23794ranged hardware watchpoints, unless the @code{exact-watchpoints} option is on,
23795in which case watchpoints using only one debug register are created when
23796watching variables of scalar types.
23797
23798You can create an artificial array to watch an arbitrary memory
23799region using one of the following commands (@pxref{Expressions}):
23800
23801@smallexample
23802(@value{GDBP}) watch *((char *) @var{address})@@@var{length}
23803(@value{GDBP}) watch @{char[@var{length}]@} @var{address}
23804@end smallexample
66b73624 23805
9c06b0b4
TJB
23806PowerPC embedded processors support masked watchpoints. See the discussion
23807about the @code{mask} argument in @ref{Set Watchpoints}.
23808
f1310107
TJB
23809@cindex ranged breakpoint
23810PowerPC embedded processors support hardware accelerated
23811@dfn{ranged breakpoints}. A ranged breakpoint stops execution of
23812the inferior whenever it executes an instruction at any address within
23813the range it specifies. To set a ranged breakpoint in @value{GDBN},
23814use the @code{break-range} command.
23815
55eddb0f
DJ
23816@value{GDBN} provides the following PowerPC-specific commands:
23817
104c1213 23818@table @code
f1310107
TJB
23819@kindex break-range
23820@item break-range @var{start-location}, @var{end-location}
697aa1b7
EZ
23821Set a breakpoint for an address range given by
23822@var{start-location} and @var{end-location}, which can specify a function name,
f1310107
TJB
23823a line number, an offset of lines from the current line or from the start
23824location, or an address of an instruction (see @ref{Specify Location},
23825for a list of all the possible ways to specify a @var{location}.)
23826The breakpoint will stop execution of the inferior whenever it
23827executes an instruction at any address within the specified range,
23828(including @var{start-location} and @var{end-location}.)
23829
55eddb0f
DJ
23830@kindex set powerpc
23831@item set powerpc soft-float
23832@itemx show powerpc soft-float
23833Force @value{GDBN} to use (or not use) a software floating point calling
23834convention. By default, @value{GDBN} selects the calling convention based
23835on the selected architecture and the provided executable file.
23836
23837@item set powerpc vector-abi
23838@itemx show powerpc vector-abi
23839Force @value{GDBN} to use the specified calling convention for vector
23840arguments and return values. The valid options are @samp{auto};
23841@samp{generic}, to avoid vector registers even if they are present;
23842@samp{altivec}, to use AltiVec registers; and @samp{spe} to use SPE
23843registers. By default, @value{GDBN} selects the calling convention
23844based on the selected architecture and the provided executable file.
23845
e09342b5
TJB
23846@item set powerpc exact-watchpoints
23847@itemx show powerpc exact-watchpoints
23848Allow @value{GDBN} to use only one debug register when watching a variable
23849of scalar type, thus assuming that the variable is accessed through the
23850address of its first byte.
23851
104c1213
JM
23852@end table
23853
a64548ea
EZ
23854@node AVR
23855@subsection Atmel AVR
23856@cindex AVR
23857
23858When configured for debugging the Atmel AVR, @value{GDBN} supports the
23859following AVR-specific commands:
23860
23861@table @code
23862@item info io_registers
23863@kindex info io_registers@r{, AVR}
23864@cindex I/O registers (Atmel AVR)
23865This command displays information about the AVR I/O registers. For
23866each register, @value{GDBN} prints its number and value.
23867@end table
23868
23869@node CRIS
23870@subsection CRIS
23871@cindex CRIS
23872
23873When configured for debugging CRIS, @value{GDBN} provides the
23874following CRIS-specific commands:
23875
23876@table @code
23877@item set cris-version @var{ver}
23878@cindex CRIS version
e22e55c9
OF
23879Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
23880The CRIS version affects register names and sizes. This command is useful in
23881case autodetection of the CRIS version fails.
a64548ea
EZ
23882
23883@item show cris-version
23884Show the current CRIS version.
23885
23886@item set cris-dwarf2-cfi
23887@cindex DWARF-2 CFI and CRIS
e22e55c9
OF
23888Set the usage of DWARF-2 CFI for CRIS debugging. The default is @samp{on}.
23889Change to @samp{off} when using @code{gcc-cris} whose version is below
23890@code{R59}.
a64548ea
EZ
23891
23892@item show cris-dwarf2-cfi
23893Show the current state of using DWARF-2 CFI.
e22e55c9
OF
23894
23895@item set cris-mode @var{mode}
23896@cindex CRIS mode
23897Set the current CRIS mode to @var{mode}. It should only be changed when
23898debugging in guru mode, in which case it should be set to
23899@samp{guru} (the default is @samp{normal}).
23900
23901@item show cris-mode
23902Show the current CRIS mode.
a64548ea
EZ
23903@end table
23904
23905@node Super-H
23906@subsection Renesas Super-H
23907@cindex Super-H
23908
23909For the Renesas Super-H processor, @value{GDBN} provides these
23910commands:
23911
23912@table @code
c055b101
CV
23913@item set sh calling-convention @var{convention}
23914@kindex set sh calling-convention
23915Set the calling-convention used when calling functions from @value{GDBN}.
23916Allowed values are @samp{gcc}, which is the default setting, and @samp{renesas}.
23917With the @samp{gcc} setting, functions are called using the @value{NGCC} calling
23918convention. If the DWARF-2 information of the called function specifies
23919that the function follows the Renesas calling convention, the function
23920is called using the Renesas calling convention. If the calling convention
23921is set to @samp{renesas}, the Renesas calling convention is always used,
23922regardless of the DWARF-2 information. This can be used to override the
23923default of @samp{gcc} if debug information is missing, or the compiler
23924does not emit the DWARF-2 calling convention entry for a function.
23925
23926@item show sh calling-convention
23927@kindex show sh calling-convention
23928Show the current calling convention setting.
23929
a64548ea
EZ
23930@end table
23931
23932
8e04817f
AC
23933@node Architectures
23934@section Architectures
104c1213 23935
8e04817f
AC
23936This section describes characteristics of architectures that affect
23937all uses of @value{GDBN} with the architecture, both native and cross.
104c1213 23938
8e04817f 23939@menu
430ed3f0 23940* AArch64::
9c16f35a 23941* i386::
8e04817f
AC
23942* Alpha::
23943* MIPS::
a64548ea 23944* HPPA:: HP PA architecture
23d964e7 23945* SPU:: Cell Broadband Engine SPU architecture
4acd40f3 23946* PowerPC::
a1217d97 23947* Nios II::
58afddc6 23948* Sparc64::
51d21d60 23949* S12Z::
8e04817f 23950@end menu
104c1213 23951
430ed3f0
MS
23952@node AArch64
23953@subsection AArch64
23954@cindex AArch64 support
23955
23956When @value{GDBN} is debugging the AArch64 architecture, it provides the
23957following special commands:
23958
23959@table @code
23960@item set debug aarch64
23961@kindex set debug aarch64
23962This command determines whether AArch64 architecture-specific debugging
23963messages are to be displayed.
23964
23965@item show debug aarch64
23966Show whether AArch64 debugging messages are displayed.
23967
23968@end table
23969
1461bdac
AH
23970@subsubsection AArch64 SVE.
23971@cindex AArch64 SVE.
23972
23973When @value{GDBN} is debugging the AArch64 architecture, if the Scalable Vector
23974Extension (SVE) is present, then @value{GDBN} will provide the vector registers
23975@code{$z0} through @code{$z31}, vector predicate registers @code{$p0} through
23976@code{$p15}, and the @code{$ffr} register. In addition, the pseudo register
23977@code{$vg} will be provided. This is the vector granule for the current thread
23978and represents the number of 64-bit chunks in an SVE @code{z} register.
23979
23980If the vector length changes, then the @code{$vg} register will be updated,
23981but the lengths of the @code{z} and @code{p} registers will not change. This
23982is a known limitation of @value{GDBN} and does not affect the execution of the
23983target process.
23984
23985
9c16f35a 23986@node i386
db2e3e2e 23987@subsection x86 Architecture-specific Issues
9c16f35a
EZ
23988
23989@table @code
23990@item set struct-convention @var{mode}
23991@kindex set struct-convention
23992@cindex struct return convention
23993@cindex struct/union returned in registers
23994Set the convention used by the inferior to return @code{struct}s and
23995@code{union}s from functions to @var{mode}. Possible values of
23996@var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
23997default). @code{"default"} or @code{"pcc"} means that @code{struct}s
23998are returned on the stack, while @code{"reg"} means that a
23999@code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
24000be returned in a register.
24001
24002@item show struct-convention
24003@kindex show struct-convention
24004Show the current setting of the convention to return @code{struct}s
24005from functions.
966f0aef 24006@end table
29c1c244 24007
ca8941bb 24008
bc504a31
PA
24009@subsubsection Intel @dfn{Memory Protection Extensions} (MPX).
24010@cindex Intel Memory Protection Extensions (MPX).
ca8941bb 24011
ca8941bb
WT
24012Memory Protection Extension (MPX) adds the bound registers @samp{BND0}
24013@footnote{The register named with capital letters represent the architecture
24014registers.} through @samp{BND3}. Bound registers store a pair of 64-bit values
24015which are the lower bound and upper bound. Bounds are effective addresses or
24016memory locations. The upper bounds are architecturally represented in 1's
24017complement form. A bound having lower bound = 0, and upper bound = 0
24018(1's complement of all bits set) will allow access to the entire address space.
24019
24020@samp{BND0} through @samp{BND3} are represented in @value{GDBN} as @samp{bnd0raw}
24021through @samp{bnd3raw}. Pseudo registers @samp{bnd0} through @samp{bnd3}
24022display the upper bound performing the complement of one operation on the
24023upper bound value, i.e.@ when upper bound in @samp{bnd0raw} is 0 in the
24024@value{GDBN} @samp{bnd0} it will be @code{0xfff@dots{}}. In this sense it
24025can also be noted that the upper bounds are inclusive.
24026
24027As an example, assume that the register BND0 holds bounds for a pointer having
24028access allowed for the range between 0x32 and 0x71. The values present on
24029bnd0raw and bnd registers are presented as follows:
24030
24031@smallexample
24032 bnd0raw = @{0x32, 0xffffffff8e@}
24033 bnd0 = @{lbound = 0x32, ubound = 0x71@} : size 64
24034@end smallexample
24035
22f25c9d
EZ
24036This way the raw value can be accessed via bnd0raw@dots{}bnd3raw. Any
24037change on bnd0@dots{}bnd3 or bnd0raw@dots{}bnd3raw is reflect on its
24038counterpart. When the bnd0@dots{}bnd3 registers are displayed via
24039Python, the display includes the memory size, in bits, accessible to
24040the pointer.
9c16f35a 24041
29c1c244
WT
24042Bounds can also be stored in bounds tables, which are stored in
24043application memory. These tables store bounds for pointers by specifying
24044the bounds pointer's value along with its bounds. Evaluating and changing
24045bounds located in bound tables is therefore interesting while investigating
24046bugs on MPX context. @value{GDBN} provides commands for this purpose:
24047
966f0aef 24048@table @code
29c1c244
WT
24049@item show mpx bound @var{pointer}
24050@kindex show mpx bound
24051Display bounds of the given @var{pointer}.
24052
24053@item set mpx bound @var{pointer}, @var{lbound}, @var{ubound}
24054@kindex set mpx bound
24055Set the bounds of a pointer in the bound table.
24056This command takes three parameters: @var{pointer} is the pointers
24057whose bounds are to be changed, @var{lbound} and @var{ubound} are new values
24058for lower and upper bounds respectively.
24059@end table
24060
4a612d6f
WT
24061When you call an inferior function on an Intel MPX enabled program,
24062GDB sets the inferior's bound registers to the init (disabled) state
24063before calling the function. As a consequence, bounds checks for the
24064pointer arguments passed to the function will always pass.
24065
24066This is necessary because when you call an inferior function, the
24067program is usually in the middle of the execution of other function.
24068Since at that point bound registers are in an arbitrary state, not
24069clearing them would lead to random bound violations in the called
24070function.
24071
24072You can still examine the influence of the bound registers on the
24073execution of the called function by stopping the execution of the
24074called function at its prologue, setting bound registers, and
24075continuing the execution. For example:
24076
24077@smallexample
24078 $ break *upper
24079 Breakpoint 2 at 0x4009de: file i386-mpx-call.c, line 47.
24080 $ print upper (a, b, c, d, 1)
24081 Breakpoint 2, upper (a=0x0, b=0x6e0000005b, c=0x0, d=0x0, len=48)....
24082 $ print $bnd0
5cf70512 24083 @{lbound = 0x0, ubound = ffffffff@} : size -1
4a612d6f
WT
24084@end smallexample
24085
24086At this last step the value of bnd0 can be changed for investigation of bound
24087violations caused along the execution of the call. In order to know how to
24088set the bound registers or bound table for the call consult the ABI.
24089
8e04817f
AC
24090@node Alpha
24091@subsection Alpha
104c1213 24092
8e04817f 24093See the following section.
104c1213 24094
8e04817f 24095@node MIPS
eb17f351 24096@subsection @acronym{MIPS}
104c1213 24097
8e04817f 24098@cindex stack on Alpha
eb17f351 24099@cindex stack on @acronym{MIPS}
8e04817f 24100@cindex Alpha stack
eb17f351
EZ
24101@cindex @acronym{MIPS} stack
24102Alpha- and @acronym{MIPS}-based computers use an unusual stack frame, which
8e04817f
AC
24103sometimes requires @value{GDBN} to search backward in the object code to
24104find the beginning of a function.
104c1213 24105
eb17f351 24106@cindex response time, @acronym{MIPS} debugging
8e04817f
AC
24107To improve response time (especially for embedded applications, where
24108@value{GDBN} may be restricted to a slow serial line for this search)
24109you may want to limit the size of this search, using one of these
24110commands:
104c1213 24111
8e04817f 24112@table @code
eb17f351 24113@cindex @code{heuristic-fence-post} (Alpha, @acronym{MIPS})
8e04817f
AC
24114@item set heuristic-fence-post @var{limit}
24115Restrict @value{GDBN} to examining at most @var{limit} bytes in its
24116search for the beginning of a function. A value of @var{0} (the
24117default) means there is no limit. However, except for @var{0}, the
24118larger the limit the more bytes @code{heuristic-fence-post} must search
e2f4edfd
EZ
24119and therefore the longer it takes to run. You should only need to use
24120this command when debugging a stripped executable.
104c1213 24121
8e04817f
AC
24122@item show heuristic-fence-post
24123Display the current limit.
24124@end table
104c1213
JM
24125
24126@noindent
8e04817f 24127These commands are available @emph{only} when @value{GDBN} is configured
eb17f351 24128for debugging programs on Alpha or @acronym{MIPS} processors.
104c1213 24129
eb17f351 24130Several @acronym{MIPS}-specific commands are available when debugging @acronym{MIPS}
a64548ea
EZ
24131programs:
24132
24133@table @code
a64548ea
EZ
24134@item set mips abi @var{arg}
24135@kindex set mips abi
eb17f351
EZ
24136@cindex set ABI for @acronym{MIPS}
24137Tell @value{GDBN} which @acronym{MIPS} ABI is used by the inferior. Possible
a64548ea
EZ
24138values of @var{arg} are:
24139
24140@table @samp
24141@item auto
24142The default ABI associated with the current binary (this is the
24143default).
24144@item o32
24145@item o64
24146@item n32
24147@item n64
24148@item eabi32
24149@item eabi64
a64548ea
EZ
24150@end table
24151
24152@item show mips abi
24153@kindex show mips abi
eb17f351 24154Show the @acronym{MIPS} ABI used by @value{GDBN} to debug the inferior.
a64548ea 24155
4cc0665f
MR
24156@item set mips compression @var{arg}
24157@kindex set mips compression
24158@cindex code compression, @acronym{MIPS}
24159Tell @value{GDBN} which @acronym{MIPS} compressed
24160@acronym{ISA, Instruction Set Architecture} encoding is used by the
24161inferior. @value{GDBN} uses this for code disassembly and other
24162internal interpretation purposes. This setting is only referred to
24163when no executable has been associated with the debugging session or
24164the executable does not provide information about the encoding it uses.
24165Otherwise this setting is automatically updated from information
24166provided by the executable.
24167
24168Possible values of @var{arg} are @samp{mips16} and @samp{micromips}.
24169The default compressed @acronym{ISA} encoding is @samp{mips16}, as
24170executables containing @acronym{MIPS16} code frequently are not
24171identified as such.
24172
24173This setting is ``sticky''; that is, it retains its value across
24174debugging sessions until reset either explicitly with this command or
24175implicitly from an executable.
24176
24177The compiler and/or assembler typically add symbol table annotations to
24178identify functions compiled for the @acronym{MIPS16} or
24179@acronym{microMIPS} @acronym{ISA}s. If these function-scope annotations
24180are present, @value{GDBN} uses them in preference to the global
24181compressed @acronym{ISA} encoding setting.
24182
24183@item show mips compression
24184@kindex show mips compression
24185Show the @acronym{MIPS} compressed @acronym{ISA} encoding used by
24186@value{GDBN} to debug the inferior.
24187
a64548ea
EZ
24188@item set mipsfpu
24189@itemx show mipsfpu
24190@xref{MIPS Embedded, set mipsfpu}.
24191
24192@item set mips mask-address @var{arg}
24193@kindex set mips mask-address
eb17f351 24194@cindex @acronym{MIPS} addresses, masking
a64548ea 24195This command determines whether the most-significant 32 bits of 64-bit
eb17f351 24196@acronym{MIPS} addresses are masked off. The argument @var{arg} can be
a64548ea
EZ
24197@samp{on}, @samp{off}, or @samp{auto}. The latter is the default
24198setting, which lets @value{GDBN} determine the correct value.
24199
24200@item show mips mask-address
24201@kindex show mips mask-address
eb17f351 24202Show whether the upper 32 bits of @acronym{MIPS} addresses are masked off or
a64548ea
EZ
24203not.
24204
24205@item set remote-mips64-transfers-32bit-regs
24206@kindex set remote-mips64-transfers-32bit-regs
eb17f351
EZ
24207This command controls compatibility with 64-bit @acronym{MIPS} targets that
24208transfer data in 32-bit quantities. If you have an old @acronym{MIPS} 64 target
a64548ea
EZ
24209that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
24210and 64 bits for other registers, set this option to @samp{on}.
24211
24212@item show remote-mips64-transfers-32bit-regs
24213@kindex show remote-mips64-transfers-32bit-regs
eb17f351 24214Show the current setting of compatibility with older @acronym{MIPS} 64 targets.
a64548ea
EZ
24215
24216@item set debug mips
24217@kindex set debug mips
eb17f351 24218This command turns on and off debugging messages for the @acronym{MIPS}-specific
a64548ea
EZ
24219target code in @value{GDBN}.
24220
24221@item show debug mips
24222@kindex show debug mips
eb17f351 24223Show the current setting of @acronym{MIPS} debugging messages.
a64548ea
EZ
24224@end table
24225
24226
24227@node HPPA
24228@subsection HPPA
24229@cindex HPPA support
24230
d3e8051b 24231When @value{GDBN} is debugging the HP PA architecture, it provides the
a64548ea
EZ
24232following special commands:
24233
24234@table @code
24235@item set debug hppa
24236@kindex set debug hppa
db2e3e2e 24237This command determines whether HPPA architecture-specific debugging
a64548ea
EZ
24238messages are to be displayed.
24239
24240@item show debug hppa
24241Show whether HPPA debugging messages are displayed.
24242
24243@item maint print unwind @var{address}
24244@kindex maint print unwind@r{, HPPA}
24245This command displays the contents of the unwind table entry at the
24246given @var{address}.
24247
24248@end table
24249
104c1213 24250
23d964e7
UW
24251@node SPU
24252@subsection Cell Broadband Engine SPU architecture
24253@cindex Cell Broadband Engine
24254@cindex SPU
24255
24256When @value{GDBN} is debugging the Cell Broadband Engine SPU architecture,
24257it provides the following special commands:
24258
24259@table @code
24260@item info spu event
24261@kindex info spu
24262Display SPU event facility status. Shows current event mask
24263and pending event status.
24264
24265@item info spu signal
24266Display SPU signal notification facility status. Shows pending
24267signal-control word and signal notification mode of both signal
24268notification channels.
24269
24270@item info spu mailbox
24271Display SPU mailbox facility status. Shows all pending entries,
24272in order of processing, in each of the SPU Write Outbound,
24273SPU Write Outbound Interrupt, and SPU Read Inbound mailboxes.
24274
24275@item info spu dma
24276Display MFC DMA status. Shows all pending commands in the MFC
24277DMA queue. For each entry, opcode, tag, class IDs, effective
24278and local store addresses and transfer size are shown.
24279
24280@item info spu proxydma
24281Display MFC Proxy-DMA status. Shows all pending commands in the MFC
24282Proxy-DMA queue. For each entry, opcode, tag, class IDs, effective
24283and local store addresses and transfer size are shown.
24284
24285@end table
24286
3285f3fe
UW
24287When @value{GDBN} is debugging a combined PowerPC/SPU application
24288on the Cell Broadband Engine, it provides in addition the following
24289special commands:
24290
24291@table @code
24292@item set spu stop-on-load @var{arg}
24293@kindex set spu
24294Set whether to stop for new SPE threads. When set to @code{on}, @value{GDBN}
24295will give control to the user when a new SPE thread enters its @code{main}
24296function. The default is @code{off}.
24297
24298@item show spu stop-on-load
24299@kindex show spu
24300Show whether to stop for new SPE threads.
24301
ff1a52c6
UW
24302@item set spu auto-flush-cache @var{arg}
24303Set whether to automatically flush the software-managed cache. When set to
24304@code{on}, @value{GDBN} will automatically cause the SPE software-managed
24305cache to be flushed whenever SPE execution stops. This provides a consistent
24306view of PowerPC memory that is accessed via the cache. If an application
24307does not use the software-managed cache, this option has no effect.
24308
24309@item show spu auto-flush-cache
24310Show whether to automatically flush the software-managed cache.
24311
3285f3fe
UW
24312@end table
24313
4acd40f3
TJB
24314@node PowerPC
24315@subsection PowerPC
24316@cindex PowerPC architecture
24317
24318When @value{GDBN} is debugging the PowerPC architecture, it provides a set of
24319pseudo-registers to enable inspection of 128-bit wide Decimal Floating Point
24320numbers stored in the floating point registers. These values must be stored
24321in two consecutive registers, always starting at an even register like
24322@code{f0} or @code{f2}.
24323
24324The pseudo-registers go from @code{$dl0} through @code{$dl15}, and are formed
24325by joining the even/odd register pairs @code{f0} and @code{f1} for @code{$dl0},
24326@code{f2} and @code{f3} for @code{$dl1} and so on.
24327
aeac0ff9 24328For POWER7 processors, @value{GDBN} provides a set of pseudo-registers, the 64-bit
677c5bb1
LM
24329wide Extended Floating Point Registers (@samp{f32} through @samp{f63}).
24330
a1217d97
SL
24331@node Nios II
24332@subsection Nios II
24333@cindex Nios II architecture
24334
24335When @value{GDBN} is debugging the Nios II architecture,
24336it provides the following special commands:
24337
24338@table @code
24339
24340@item set debug nios2
24341@kindex set debug nios2
24342This command turns on and off debugging messages for the Nios II
24343target code in @value{GDBN}.
24344
24345@item show debug nios2
24346@kindex show debug nios2
24347Show the current setting of Nios II debugging messages.
24348@end table
23d964e7 24349
58afddc6
WP
24350@node Sparc64
24351@subsection Sparc64
24352@cindex Sparc64 support
24353@cindex Application Data Integrity
24354@subsubsection ADI Support
24355
24356The M7 processor supports an Application Data Integrity (ADI) feature that
24357detects invalid data accesses. When software allocates memory and enables
24358ADI on the allocated memory, it chooses a 4-bit version number, sets the
24359version in the upper 4 bits of the 64-bit pointer to that data, and stores
24360the 4-bit version in every cacheline of that data. Hardware saves the latter
24361in spare bits in the cache and memory hierarchy. On each load and store,
24362the processor compares the upper 4 VA (virtual address) bits to the
24363cacheline's version. If there is a mismatch, the processor generates a
24364version mismatch trap which can be either precise or disrupting. The trap
24365is an error condition which the kernel delivers to the process as a SIGSEGV
24366signal.
24367
24368Note that only 64-bit applications can use ADI and need to be built with
24369ADI-enabled.
24370
24371Values of the ADI version tags, which are in granularity of a
24372cacheline (64 bytes), can be viewed or modified.
24373
24374
24375@table @code
24376@kindex adi examine
24377@item adi (examine | x) [ / @var{n} ] @var{addr}
24378
24379The @code{adi examine} command displays the value of one ADI version tag per
24380cacheline.
24381
24382@var{n} is a decimal integer specifying the number in bytes; the default
24383is 1. It specifies how much ADI version information, at the ratio of 1:ADI
24384block size, to display.
24385
24386@var{addr} is the address in user address space where you want @value{GDBN}
24387to begin displaying the ADI version tags.
24388
24389Below is an example of displaying ADI versions of variable "shmaddr".
24390
24391@smallexample
24392(@value{GDBP}) adi x/100 shmaddr
24393 0xfff800010002c000: 0 0
24394@end smallexample
24395
24396@kindex adi assign
24397@item adi (assign | a) [ / @var{n} ] @var{addr} = @var{tag}
24398
24399The @code{adi assign} command is used to assign new ADI version tag
24400to an address.
24401
24402@var{n} is a decimal integer specifying the number in bytes;
24403the default is 1. It specifies how much ADI version information, at the
24404ratio of 1:ADI block size, to modify.
24405
24406@var{addr} is the address in user address space where you want @value{GDBN}
24407to begin modifying the ADI version tags.
24408
24409@var{tag} is the new ADI version tag.
24410
24411For example, do the following to modify then verify ADI versions of
24412variable "shmaddr":
24413
24414@smallexample
24415(@value{GDBP}) adi a/100 shmaddr = 7
24416(@value{GDBP}) adi x/100 shmaddr
24417 0xfff800010002c000: 7 7
24418@end smallexample
24419
24420@end table
24421
51d21d60
JD
24422@node S12Z
24423@subsection S12Z
24424@cindex S12Z support
24425
24426When @value{GDBN} is debugging the S12Z architecture,
24427it provides the following special command:
24428
24429@table @code
24430@item maint info bdccsr
24431@kindex maint info bdccsr@r{, S12Z}
24432This command displays the current value of the microprocessor's
24433BDCCSR register.
24434@end table
24435
24436
8e04817f
AC
24437@node Controlling GDB
24438@chapter Controlling @value{GDBN}
24439
24440You can alter the way @value{GDBN} interacts with you by using the
24441@code{set} command. For commands controlling how @value{GDBN} displays
79a6e687 24442data, see @ref{Print Settings, ,Print Settings}. Other settings are
8e04817f
AC
24443described here.
24444
24445@menu
24446* Prompt:: Prompt
24447* Editing:: Command editing
d620b259 24448* Command History:: Command history
8e04817f 24449* Screen Size:: Screen size
140a4bc0 24450* Output Styling:: Output styling
8e04817f 24451* Numbers:: Numbers
1e698235 24452* ABI:: Configuring the current ABI
bf88dd68 24453* Auto-loading:: Automatically loading associated files
8e04817f
AC
24454* Messages/Warnings:: Optional warnings and messages
24455* Debugging Output:: Optional messages about internal happenings
14fb1bac 24456* Other Misc Settings:: Other Miscellaneous Settings
8e04817f
AC
24457@end menu
24458
24459@node Prompt
24460@section Prompt
104c1213 24461
8e04817f 24462@cindex prompt
104c1213 24463
8e04817f
AC
24464@value{GDBN} indicates its readiness to read a command by printing a string
24465called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
24466can change the prompt string with the @code{set prompt} command. For
24467instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
24468the prompt in one of the @value{GDBN} sessions so that you can always tell
24469which one you are talking to.
104c1213 24470
8e04817f
AC
24471@emph{Note:} @code{set prompt} does not add a space for you after the
24472prompt you set. This allows you to set a prompt which ends in a space
24473or a prompt that does not.
104c1213 24474
8e04817f
AC
24475@table @code
24476@kindex set prompt
24477@item set prompt @var{newprompt}
24478Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
104c1213 24479
8e04817f
AC
24480@kindex show prompt
24481@item show prompt
24482Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
104c1213
JM
24483@end table
24484
fa3a4f15
PM
24485Versions of @value{GDBN} that ship with Python scripting enabled have
24486prompt extensions. The commands for interacting with these extensions
24487are:
24488
24489@table @code
24490@kindex set extended-prompt
24491@item set extended-prompt @var{prompt}
24492Set an extended prompt that allows for substitutions.
24493@xref{gdb.prompt}, for a list of escape sequences that can be used for
24494substitution. Any escape sequences specified as part of the prompt
24495string are replaced with the corresponding strings each time the prompt
24496is displayed.
24497
24498For example:
24499
24500@smallexample
24501set extended-prompt Current working directory: \w (gdb)
24502@end smallexample
24503
24504Note that when an extended-prompt is set, it takes control of the
24505@var{prompt_hook} hook. @xref{prompt_hook}, for further information.
24506
24507@kindex show extended-prompt
24508@item show extended-prompt
24509Prints the extended prompt. Any escape sequences specified as part of
24510the prompt string with @code{set extended-prompt}, are replaced with the
24511corresponding strings each time the prompt is displayed.
24512@end table
24513
8e04817f 24514@node Editing
79a6e687 24515@section Command Editing
8e04817f
AC
24516@cindex readline
24517@cindex command line editing
104c1213 24518
703663ab 24519@value{GDBN} reads its input commands via the @dfn{Readline} interface. This
8e04817f
AC
24520@sc{gnu} library provides consistent behavior for programs which provide a
24521command line interface to the user. Advantages are @sc{gnu} Emacs-style
24522or @dfn{vi}-style inline editing of commands, @code{csh}-like history
24523substitution, and a storage and recall of command history across
24524debugging sessions.
104c1213 24525
8e04817f
AC
24526You may control the behavior of command line editing in @value{GDBN} with the
24527command @code{set}.
104c1213 24528
8e04817f
AC
24529@table @code
24530@kindex set editing
24531@cindex editing
24532@item set editing
24533@itemx set editing on
24534Enable command line editing (enabled by default).
104c1213 24535
8e04817f
AC
24536@item set editing off
24537Disable command line editing.
104c1213 24538
8e04817f
AC
24539@kindex show editing
24540@item show editing
24541Show whether command line editing is enabled.
104c1213
JM
24542@end table
24543
39037522
TT
24544@ifset SYSTEM_READLINE
24545@xref{Command Line Editing, , , rluserman, GNU Readline Library},
24546@end ifset
24547@ifclear SYSTEM_READLINE
24548@xref{Command Line Editing},
24549@end ifclear
24550for more details about the Readline
703663ab
EZ
24551interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
24552encouraged to read that chapter.
24553
d620b259 24554@node Command History
79a6e687 24555@section Command History
703663ab 24556@cindex command history
8e04817f
AC
24557
24558@value{GDBN} can keep track of the commands you type during your
24559debugging sessions, so that you can be certain of precisely what
24560happened. Use these commands to manage the @value{GDBN} command
24561history facility.
104c1213 24562
703663ab 24563@value{GDBN} uses the @sc{gnu} History library, a part of the Readline
39037522
TT
24564package, to provide the history facility.
24565@ifset SYSTEM_READLINE
24566@xref{Using History Interactively, , , history, GNU History Library},
24567@end ifset
24568@ifclear SYSTEM_READLINE
24569@xref{Using History Interactively},
24570@end ifclear
24571for the detailed description of the History library.
703663ab 24572
d620b259 24573To issue a command to @value{GDBN} without affecting certain aspects of
9e6c4bd5
NR
24574the state which is seen by users, prefix it with @samp{server }
24575(@pxref{Server Prefix}). This
d620b259
NR
24576means that this command will not affect the command history, nor will it
24577affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
24578pressed on a line by itself.
24579
24580@cindex @code{server}, command prefix
24581The server prefix does not affect the recording of values into the value
24582history; to print a value without recording it into the value history,
24583use the @code{output} command instead of the @code{print} command.
24584
703663ab
EZ
24585Here is the description of @value{GDBN} commands related to command
24586history.
24587
104c1213 24588@table @code
8e04817f
AC
24589@cindex history substitution
24590@cindex history file
24591@kindex set history filename
4644b6e3 24592@cindex @env{GDBHISTFILE}, environment variable
8e04817f
AC
24593@item set history filename @var{fname}
24594Set the name of the @value{GDBN} command history file to @var{fname}.
24595This is the file where @value{GDBN} reads an initial command history
24596list, and where it writes the command history from this session when it
24597exits. You can access this list through history expansion or through
24598the history command editing characters listed below. This file defaults
24599to the value of the environment variable @code{GDBHISTFILE}, or to
24600@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
24601is not set.
104c1213 24602
9c16f35a
EZ
24603@cindex save command history
24604@kindex set history save
8e04817f
AC
24605@item set history save
24606@itemx set history save on
24607Record command history in a file, whose name may be specified with the
24608@code{set history filename} command. By default, this option is disabled.
104c1213 24609
8e04817f
AC
24610@item set history save off
24611Stop recording command history in a file.
104c1213 24612
8e04817f 24613@cindex history size
9c16f35a 24614@kindex set history size
b58c513b 24615@cindex @env{GDBHISTSIZE}, environment variable
8e04817f 24616@item set history size @var{size}
f81d1120 24617@itemx set history size unlimited
8e04817f 24618Set the number of commands which @value{GDBN} keeps in its history list.
bc460514
PP
24619This defaults to the value of the environment variable @env{GDBHISTSIZE}, or
24620to 256 if this variable is not set. Non-numeric values of @env{GDBHISTSIZE}
0eacb298
PP
24621are ignored. If @var{size} is @code{unlimited} or if @env{GDBHISTSIZE} is
24622either a negative number or the empty string, then the number of commands
24623@value{GDBN} keeps in the history list is unlimited.
fc637f04
PP
24624
24625@cindex remove duplicate history
24626@kindex set history remove-duplicates
24627@item set history remove-duplicates @var{count}
24628@itemx set history remove-duplicates unlimited
24629Control the removal of duplicate history entries in the command history list.
24630If @var{count} is non-zero, @value{GDBN} will look back at the last @var{count}
24631history entries and remove the first entry that is a duplicate of the current
24632entry being added to the command history list. If @var{count} is
24633@code{unlimited} then this lookbehind is unbounded. If @var{count} is 0, then
24634removal of duplicate history entries is disabled.
24635
24636Only history entries added during the current session are considered for
24637removal. This option is set to 0 by default.
24638
104c1213
JM
24639@end table
24640
8e04817f 24641History expansion assigns special meaning to the character @kbd{!}.
39037522
TT
24642@ifset SYSTEM_READLINE
24643@xref{Event Designators, , , history, GNU History Library},
24644@end ifset
24645@ifclear SYSTEM_READLINE
24646@xref{Event Designators},
24647@end ifclear
24648for more details.
8e04817f 24649
703663ab 24650@cindex history expansion, turn on/off
8e04817f
AC
24651Since @kbd{!} is also the logical not operator in C, history expansion
24652is off by default. If you decide to enable history expansion with the
24653@code{set history expansion on} command, you may sometimes need to
24654follow @kbd{!} (when it is used as logical not, in an expression) with
24655a space or a tab to prevent it from being expanded. The readline
24656history facilities do not attempt substitution on the strings
24657@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
24658
24659The commands to control history expansion are:
104c1213
JM
24660
24661@table @code
8e04817f
AC
24662@item set history expansion on
24663@itemx set history expansion
703663ab 24664@kindex set history expansion
8e04817f 24665Enable history expansion. History expansion is off by default.
104c1213 24666
8e04817f
AC
24667@item set history expansion off
24668Disable history expansion.
104c1213 24669
8e04817f
AC
24670@c @group
24671@kindex show history
24672@item show history
24673@itemx show history filename
24674@itemx show history save
24675@itemx show history size
24676@itemx show history expansion
24677These commands display the state of the @value{GDBN} history parameters.
24678@code{show history} by itself displays all four states.
24679@c @end group
24680@end table
24681
24682@table @code
9c16f35a
EZ
24683@kindex show commands
24684@cindex show last commands
24685@cindex display command history
8e04817f
AC
24686@item show commands
24687Display the last ten commands in the command history.
104c1213 24688
8e04817f
AC
24689@item show commands @var{n}
24690Print ten commands centered on command number @var{n}.
24691
24692@item show commands +
24693Print ten commands just after the commands last printed.
104c1213
JM
24694@end table
24695
8e04817f 24696@node Screen Size
79a6e687 24697@section Screen Size
8e04817f 24698@cindex size of screen
f179cf97
EZ
24699@cindex screen size
24700@cindex pagination
24701@cindex page size
8e04817f 24702@cindex pauses in output
104c1213 24703
8e04817f
AC
24704Certain commands to @value{GDBN} may produce large amounts of
24705information output to the screen. To help you read all of it,
24706@value{GDBN} pauses and asks you for input at the end of each page of
eb6af809
TT
24707output. Type @key{RET} when you want to see one more page of output,
24708@kbd{q} to discard the remaining output, or @kbd{c} to continue
24709without paging for the rest of the current command. Also, the screen
24710width setting determines when to wrap lines of output. Depending on
24711what is being printed, @value{GDBN} tries to break the line at a
24712readable place, rather than simply letting it overflow onto the
24713following line.
8e04817f
AC
24714
24715Normally @value{GDBN} knows the size of the screen from the terminal
24716driver software. For example, on Unix @value{GDBN} uses the termcap data base
24717together with the value of the @code{TERM} environment variable and the
24718@code{stty rows} and @code{stty cols} settings. If this is not correct,
24719you can override it with the @code{set height} and @code{set
24720width} commands:
24721
24722@table @code
24723@kindex set height
24724@kindex set width
24725@kindex show width
24726@kindex show height
24727@item set height @var{lpp}
f81d1120 24728@itemx set height unlimited
8e04817f
AC
24729@itemx show height
24730@itemx set width @var{cpl}
f81d1120 24731@itemx set width unlimited
8e04817f
AC
24732@itemx show width
24733These @code{set} commands specify a screen height of @var{lpp} lines and
24734a screen width of @var{cpl} characters. The associated @code{show}
24735commands display the current settings.
104c1213 24736
f81d1120
PA
24737If you specify a height of either @code{unlimited} or zero lines,
24738@value{GDBN} does not pause during output no matter how long the
24739output is. This is useful if output is to a file or to an editor
24740buffer.
104c1213 24741
f81d1120
PA
24742Likewise, you can specify @samp{set width unlimited} or @samp{set
24743width 0} to prevent @value{GDBN} from wrapping its output.
9c16f35a
EZ
24744
24745@item set pagination on
24746@itemx set pagination off
24747@kindex set pagination
24748Turn the output pagination on or off; the default is on. Turning
f81d1120 24749pagination off is the alternative to @code{set height unlimited}. Note that
7c953934
TT
24750running @value{GDBN} with the @option{--batch} option (@pxref{Mode
24751Options, -batch}) also automatically disables pagination.
9c16f35a
EZ
24752
24753@item show pagination
24754@kindex show pagination
24755Show the current pagination mode.
104c1213
JM
24756@end table
24757
140a4bc0
TT
24758@node Output Styling
24759@section Output Styling
24760@cindex styling
24761@cindex colors
24762
24763@kindex set style
24764@kindex show style
24765@value{GDBN} can style its output on a capable terminal. This is
7557a514
AH
24766enabled by default on most systems, but disabled by default when in
24767batch mode (@pxref{Mode Options}). Various style settings are available;
24768and styles can also be disabled entirely.
140a4bc0
TT
24769
24770@table @code
24771@item set style enabled @samp{on|off}
24772Enable or disable all styling. The default is host-dependent, with
24773most hosts defaulting to @samp{on}.
24774
24775@item show style enabled
24776Show the current state of styling.
d085f989
TT
24777
24778@item set style sources @samp{on|off}
24779Enable or disable source code styling. This affects whether source
24780code, such as the output of the @code{list} command, is styled. Note
24781that source styling only works if styling in general is enabled, and
24782if @value{GDBN} was linked with the GNU Source Highlight library. The
24783default is @samp{on}.
24784
24785@item show style sources
24786Show the current state of source code styling.
140a4bc0
TT
24787@end table
24788
24789Subcommands of @code{set style} control specific forms of styling.
24790These subcommands all follow the same pattern: each style-able object
24791can be styled with a foreground color, a background color, and an
24792intensity.
24793
24794For example, the style of file names can be controlled using the
24795@code{set style filename} group of commands:
24796
24797@table @code
24798@item set style filename background @var{color}
24799Set the background to @var{color}. Valid colors are @samp{none}
24800(meaning the terminal's default color), @samp{black}, @samp{red},
e3624a40 24801@samp{green}, @samp{yellow}, @samp{blue}, @samp{magenta}, @samp{cyan},
140a4bc0
TT
24802and@samp{white}.
24803
24804@item set style filename foreground @var{color}
24805Set the foreground to @var{color}. Valid colors are @samp{none}
24806(meaning the terminal's default color), @samp{black}, @samp{red},
e3624a40 24807@samp{green}, @samp{yellow}, @samp{blue}, @samp{magenta}, @samp{cyan},
140a4bc0
TT
24808and@samp{white}.
24809
24810@item set style filename intensity @var{value}
24811Set the intensity to @var{value}. Valid intensities are @samp{normal}
24812(the default), @samp{bold}, and @samp{dim}.
24813@end table
24814
e664d728
PW
24815The @code{show style} command and its subcommands are styling
24816a style name in their output using its own style.
24817So, use @command{show style} to see the complete list of styles,
24818their characteristics and the visual aspect of each style.
24819
140a4bc0
TT
24820The style-able objects are:
24821@table @code
24822@item filename
e3624a40
EZ
24823Control the styling of file names. By default, this style's
24824foreground color is green.
140a4bc0
TT
24825
24826@item function
24827Control the styling of function names. These are managed with the
e3624a40
EZ
24828@code{set style function} family of commands. By default, this
24829style's foreground color is yellow.
140a4bc0
TT
24830
24831@item variable
24832Control the styling of variable names. These are managed with the
e3624a40
EZ
24833@code{set style variable} family of commands. By default, this style's
24834foreground color is cyan.
140a4bc0
TT
24835
24836@item address
24837Control the styling of addresses. These are managed with the
e3624a40
EZ
24838@code{set style address} family of commands. By default, this style's
24839foreground color is blue.
e664d728
PW
24840
24841@item title
24842Control the styling of titles. These are managed with the
24843@code{set style title} family of commands. By default, this style's
24844intensity is bold. Commands are using the title style to improve
24845the readibility of large output. For example, the commands
24846@command{apropos} and @command{help} are using the title style
24847for the command names.
24848
24849@item highlight
24850Control the styling of highlightings. These are managed with the
24851@code{set style highlight} family of commands. By default, this style's
24852foreground color is red. Commands are using the highlight style to draw
24853the user attention to some specific parts of their output. For example,
24854the command @command{apropos -v REGEXP} uses the highlight style to
24855mark the documentation parts matching @var{regexp}.
24856
140a4bc0
TT
24857@end table
24858
8e04817f
AC
24859@node Numbers
24860@section Numbers
24861@cindex number representation
24862@cindex entering numbers
104c1213 24863
8e04817f
AC
24864You can always enter numbers in octal, decimal, or hexadecimal in
24865@value{GDBN} by the usual conventions: octal numbers begin with
24866@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
eb2dae08
EZ
24867begin with @samp{0x}. Numbers that neither begin with @samp{0} or
24868@samp{0x}, nor end with a @samp{.} are, by default, entered in base
2486910; likewise, the default display for numbers---when no particular
24870format is specified---is base 10. You can change the default base for
24871both input and output with the commands described below.
104c1213 24872
8e04817f
AC
24873@table @code
24874@kindex set input-radix
24875@item set input-radix @var{base}
24876Set the default base for numeric input. Supported choices
697aa1b7 24877for @var{base} are decimal 8, 10, or 16. The base must itself be
eb2dae08 24878specified either unambiguously or using the current input radix; for
8e04817f 24879example, any of
104c1213 24880
8e04817f 24881@smallexample
9c16f35a
EZ
24882set input-radix 012
24883set input-radix 10.
24884set input-radix 0xa
8e04817f 24885@end smallexample
104c1213 24886
8e04817f 24887@noindent
9c16f35a 24888sets the input base to decimal. On the other hand, @samp{set input-radix 10}
eb2dae08
EZ
24889leaves the input radix unchanged, no matter what it was, since
24890@samp{10}, being without any leading or trailing signs of its base, is
24891interpreted in the current radix. Thus, if the current radix is 16,
24892@samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
24893change the radix.
104c1213 24894
8e04817f
AC
24895@kindex set output-radix
24896@item set output-radix @var{base}
24897Set the default base for numeric display. Supported choices
697aa1b7 24898for @var{base} are decimal 8, 10, or 16. The base must itself be
eb2dae08 24899specified either unambiguously or using the current input radix.
104c1213 24900
8e04817f
AC
24901@kindex show input-radix
24902@item show input-radix
24903Display the current default base for numeric input.
104c1213 24904
8e04817f
AC
24905@kindex show output-radix
24906@item show output-radix
24907Display the current default base for numeric display.
9c16f35a
EZ
24908
24909@item set radix @r{[}@var{base}@r{]}
24910@itemx show radix
24911@kindex set radix
24912@kindex show radix
24913These commands set and show the default base for both input and output
24914of numbers. @code{set radix} sets the radix of input and output to
24915the same base; without an argument, it resets the radix back to its
24916default value of 10.
24917
8e04817f 24918@end table
104c1213 24919
1e698235 24920@node ABI
79a6e687 24921@section Configuring the Current ABI
1e698235
DJ
24922
24923@value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
24924application automatically. However, sometimes you need to override its
24925conclusions. Use these commands to manage @value{GDBN}'s view of the
24926current ABI.
24927
98b45e30
DJ
24928@cindex OS ABI
24929@kindex set osabi
b4e9345d 24930@kindex show osabi
430ed3f0 24931@cindex Newlib OS ABI and its influence on the longjmp handling
98b45e30
DJ
24932
24933One @value{GDBN} configuration can debug binaries for multiple operating
b383017d 24934system targets, either via remote debugging or native emulation.
98b45e30
DJ
24935@value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
24936but you can override its conclusion using the @code{set osabi} command.
24937One example where this is useful is in debugging of binaries which use
24938an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
24939not have the same identifying marks that the standard C library for your
24940platform provides.
24941
430ed3f0
MS
24942When @value{GDBN} is debugging the AArch64 architecture, it provides a
24943``Newlib'' OS ABI. This is useful for handling @code{setjmp} and
24944@code{longjmp} when debugging binaries that use the @sc{newlib} C library.
24945The ``Newlib'' OS ABI can be selected by @code{set osabi Newlib}.
24946
98b45e30
DJ
24947@table @code
24948@item show osabi
24949Show the OS ABI currently in use.
24950
24951@item set osabi
24952With no argument, show the list of registered available OS ABI's.
24953
24954@item set osabi @var{abi}
24955Set the current OS ABI to @var{abi}.
24956@end table
24957
1e698235 24958@cindex float promotion
1e698235
DJ
24959
24960Generally, the way that an argument of type @code{float} is passed to a
24961function depends on whether the function is prototyped. For a prototyped
24962(i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
24963according to the architecture's convention for @code{float}. For unprototyped
24964(i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
24965@code{double} and then passed.
24966
24967Unfortunately, some forms of debug information do not reliably indicate whether
24968a function is prototyped. If @value{GDBN} calls a function that is not marked
24969as prototyped, it consults @kbd{set coerce-float-to-double}.
24970
24971@table @code
a8f24a35 24972@kindex set coerce-float-to-double
1e698235
DJ
24973@item set coerce-float-to-double
24974@itemx set coerce-float-to-double on
24975Arguments of type @code{float} will be promoted to @code{double} when passed
24976to an unprototyped function. This is the default setting.
24977
24978@item set coerce-float-to-double off
24979Arguments of type @code{float} will be passed directly to unprototyped
24980functions.
9c16f35a
EZ
24981
24982@kindex show coerce-float-to-double
24983@item show coerce-float-to-double
24984Show the current setting of promoting @code{float} to @code{double}.
1e698235
DJ
24985@end table
24986
f1212245
DJ
24987@kindex set cp-abi
24988@kindex show cp-abi
24989@value{GDBN} needs to know the ABI used for your program's C@t{++}
24990objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
24991used to build your application. @value{GDBN} only fully supports
24992programs with a single C@t{++} ABI; if your program contains code using
24993multiple C@t{++} ABI's or if @value{GDBN} can not identify your
24994program's ABI correctly, you can tell @value{GDBN} which ABI to use.
24995Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
24996before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
24997``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
24998use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
24999``auto''.
25000
25001@table @code
25002@item show cp-abi
25003Show the C@t{++} ABI currently in use.
25004
25005@item set cp-abi
25006With no argument, show the list of supported C@t{++} ABI's.
25007
25008@item set cp-abi @var{abi}
25009@itemx set cp-abi auto
25010Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
25011@end table
25012
bf88dd68
JK
25013@node Auto-loading
25014@section Automatically loading associated files
25015@cindex auto-loading
25016
25017@value{GDBN} sometimes reads files with commands and settings automatically,
25018without being explicitly told so by the user. We call this feature
25019@dfn{auto-loading}. While auto-loading is useful for automatically adapting
25020@value{GDBN} to the needs of your project, it can sometimes produce unexpected
25021results or introduce security risks (e.g., if the file comes from untrusted
25022sources).
25023
71b8c845
DE
25024@menu
25025* Init File in the Current Directory:: @samp{set/show/info auto-load local-gdbinit}
25026* libthread_db.so.1 file:: @samp{set/show/info auto-load libthread-db}
25027
25028* Auto-loading safe path:: @samp{set/show/info auto-load safe-path}
25029* Auto-loading verbose mode:: @samp{set/show debug auto-load}
25030@end menu
25031
25032There are various kinds of files @value{GDBN} can automatically load.
25033In addition to these files, @value{GDBN} supports auto-loading code written
25034in various extension languages. @xref{Auto-loading extensions}.
25035
c1668e4e
JK
25036Note that loading of these associated files (including the local @file{.gdbinit}
25037file) requires accordingly configured @code{auto-load safe-path}
25038(@pxref{Auto-loading safe path}).
25039
bf88dd68
JK
25040For these reasons, @value{GDBN} includes commands and options to let you
25041control when to auto-load files and which files should be auto-loaded.
25042
25043@table @code
25044@anchor{set auto-load off}
25045@kindex set auto-load off
25046@item set auto-load off
25047Globally disable loading of all auto-loaded files.
25048You may want to use this command with the @samp{-iex} option
25049(@pxref{Option -init-eval-command}) such as:
25050@smallexample
25051$ @kbd{gdb -iex "set auto-load off" untrusted-executable corefile}
25052@end smallexample
25053
25054Be aware that system init file (@pxref{System-wide configuration})
25055and init files from your home directory (@pxref{Home Directory Init File})
25056still get read (as they come from generally trusted directories).
25057To prevent @value{GDBN} from auto-loading even those init files, use the
25058@option{-nx} option (@pxref{Mode Options}), in addition to
25059@code{set auto-load no}.
25060
25061@anchor{show auto-load}
25062@kindex show auto-load
25063@item show auto-load
25064Show whether auto-loading of each specific @samp{auto-load} file(s) is enabled
25065or disabled.
25066
25067@smallexample
25068(gdb) show auto-load
25069gdb-scripts: Auto-loading of canned sequences of commands scripts is on.
25070libthread-db: Auto-loading of inferior specific libthread_db is on.
1ccacbcd
JK
25071local-gdbinit: Auto-loading of .gdbinit script from current directory
25072 is on.
bf88dd68 25073python-scripts: Auto-loading of Python scripts is on.
bccbefd2 25074safe-path: List of directories from which it is safe to auto-load files
1564a261 25075 is $debugdir:$datadir/auto-load.
7349ff92 25076scripts-directory: List of directories from which to load auto-loaded scripts
1564a261 25077 is $debugdir:$datadir/auto-load.
bf88dd68
JK
25078@end smallexample
25079
25080@anchor{info auto-load}
25081@kindex info auto-load
25082@item info auto-load
25083Print whether each specific @samp{auto-load} file(s) have been auto-loaded or
25084not.
25085
25086@smallexample
25087(gdb) info auto-load
25088gdb-scripts:
25089Loaded Script
25090Yes /home/user/gdb/gdb-gdb.gdb
25091libthread-db: No auto-loaded libthread-db.
1ccacbcd
JK
25092local-gdbinit: Local .gdbinit file "/home/user/gdb/.gdbinit" has been
25093 loaded.
bf88dd68
JK
25094python-scripts:
25095Loaded Script
25096Yes /home/user/gdb/gdb-gdb.py
25097@end smallexample
25098@end table
25099
bf88dd68
JK
25100These are @value{GDBN} control commands for the auto-loading:
25101
25102@multitable @columnfractions .5 .5
25103@item @xref{set auto-load off}.
25104@tab Disable auto-loading globally.
25105@item @xref{show auto-load}.
25106@tab Show setting of all kinds of files.
25107@item @xref{info auto-load}.
25108@tab Show state of all kinds of files.
25109@item @xref{set auto-load gdb-scripts}.
25110@tab Control for @value{GDBN} command scripts.
25111@item @xref{show auto-load gdb-scripts}.
25112@tab Show setting of @value{GDBN} command scripts.
25113@item @xref{info auto-load gdb-scripts}.
25114@tab Show state of @value{GDBN} command scripts.
25115@item @xref{set auto-load python-scripts}.
25116@tab Control for @value{GDBN} Python scripts.
25117@item @xref{show auto-load python-scripts}.
25118@tab Show setting of @value{GDBN} Python scripts.
25119@item @xref{info auto-load python-scripts}.
25120@tab Show state of @value{GDBN} Python scripts.
ed3ef339
DE
25121@item @xref{set auto-load guile-scripts}.
25122@tab Control for @value{GDBN} Guile scripts.
25123@item @xref{show auto-load guile-scripts}.
25124@tab Show setting of @value{GDBN} Guile scripts.
25125@item @xref{info auto-load guile-scripts}.
25126@tab Show state of @value{GDBN} Guile scripts.
7349ff92
JK
25127@item @xref{set auto-load scripts-directory}.
25128@tab Control for @value{GDBN} auto-loaded scripts location.
25129@item @xref{show auto-load scripts-directory}.
25130@tab Show @value{GDBN} auto-loaded scripts location.
f10c5b19
JK
25131@item @xref{add-auto-load-scripts-directory}.
25132@tab Add directory for auto-loaded scripts location list.
bf88dd68
JK
25133@item @xref{set auto-load local-gdbinit}.
25134@tab Control for init file in the current directory.
25135@item @xref{show auto-load local-gdbinit}.
25136@tab Show setting of init file in the current directory.
25137@item @xref{info auto-load local-gdbinit}.
25138@tab Show state of init file in the current directory.
25139@item @xref{set auto-load libthread-db}.
25140@tab Control for thread debugging library.
25141@item @xref{show auto-load libthread-db}.
25142@tab Show setting of thread debugging library.
25143@item @xref{info auto-load libthread-db}.
25144@tab Show state of thread debugging library.
bccbefd2
JK
25145@item @xref{set auto-load safe-path}.
25146@tab Control directories trusted for automatic loading.
25147@item @xref{show auto-load safe-path}.
25148@tab Show directories trusted for automatic loading.
25149@item @xref{add-auto-load-safe-path}.
25150@tab Add directory trusted for automatic loading.
bf88dd68
JK
25151@end multitable
25152
bf88dd68
JK
25153@node Init File in the Current Directory
25154@subsection Automatically loading init file in the current directory
25155@cindex auto-loading init file in the current directory
25156
25157By default, @value{GDBN} reads and executes the canned sequences of commands
25158from init file (if any) in the current working directory,
25159see @ref{Init File in the Current Directory during Startup}.
25160
c1668e4e
JK
25161Note that loading of this local @file{.gdbinit} file also requires accordingly
25162configured @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
25163
bf88dd68
JK
25164@table @code
25165@anchor{set auto-load local-gdbinit}
25166@kindex set auto-load local-gdbinit
25167@item set auto-load local-gdbinit [on|off]
25168Enable or disable the auto-loading of canned sequences of commands
25169(@pxref{Sequences}) found in init file in the current directory.
25170
25171@anchor{show auto-load local-gdbinit}
25172@kindex show auto-load local-gdbinit
25173@item show auto-load local-gdbinit
25174Show whether auto-loading of canned sequences of commands from init file in the
25175current directory is enabled or disabled.
25176
25177@anchor{info auto-load local-gdbinit}
25178@kindex info auto-load local-gdbinit
25179@item info auto-load local-gdbinit
25180Print whether canned sequences of commands from init file in the
25181current directory have been auto-loaded.
25182@end table
25183
25184@node libthread_db.so.1 file
25185@subsection Automatically loading thread debugging library
25186@cindex auto-loading libthread_db.so.1
25187
25188This feature is currently present only on @sc{gnu}/Linux native hosts.
25189
25190@value{GDBN} reads in some cases thread debugging library from places specific
25191to the inferior (@pxref{set libthread-db-search-path}).
25192
25193The special @samp{libthread-db-search-path} entry @samp{$sdir} is processed
25194without checking this @samp{set auto-load libthread-db} switch as system
25195libraries have to be trusted in general. In all other cases of
25196@samp{libthread-db-search-path} entries @value{GDBN} checks first if @samp{set
25197auto-load libthread-db} is enabled before trying to open such thread debugging
25198library.
25199
c1668e4e
JK
25200Note that loading of this debugging library also requires accordingly configured
25201@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
25202
bf88dd68
JK
25203@table @code
25204@anchor{set auto-load libthread-db}
25205@kindex set auto-load libthread-db
25206@item set auto-load libthread-db [on|off]
25207Enable or disable the auto-loading of inferior specific thread debugging library.
25208
25209@anchor{show auto-load libthread-db}
25210@kindex show auto-load libthread-db
25211@item show auto-load libthread-db
25212Show whether auto-loading of inferior specific thread debugging library is
25213enabled or disabled.
25214
25215@anchor{info auto-load libthread-db}
25216@kindex info auto-load libthread-db
25217@item info auto-load libthread-db
25218Print the list of all loaded inferior specific thread debugging libraries and
25219for each such library print list of inferior @var{pid}s using it.
25220@end table
25221
bccbefd2
JK
25222@node Auto-loading safe path
25223@subsection Security restriction for auto-loading
25224@cindex auto-loading safe-path
25225
25226As the files of inferior can come from untrusted source (such as submitted by
25227an application user) @value{GDBN} does not always load any files automatically.
25228@value{GDBN} provides the @samp{set auto-load safe-path} setting to list
25229directories trusted for loading files not explicitly requested by user.
202cbf1c 25230Each directory can also be a shell wildcard pattern.
bccbefd2
JK
25231
25232If the path is not set properly you will see a warning and the file will not
25233get loaded:
25234
25235@smallexample
25236$ ./gdb -q ./gdb
25237Reading symbols from /home/user/gdb/gdb...done.
25238warning: File "/home/user/gdb/gdb-gdb.gdb" auto-loading has been
1564a261
JK
25239 declined by your `auto-load safe-path' set
25240 to "$debugdir:$datadir/auto-load".
bccbefd2 25241warning: File "/home/user/gdb/gdb-gdb.py" auto-loading has been
1564a261
JK
25242 declined by your `auto-load safe-path' set
25243 to "$debugdir:$datadir/auto-load".
bccbefd2
JK
25244@end smallexample
25245
2c91021c
JK
25246@noindent
25247To instruct @value{GDBN} to go ahead and use the init files anyway,
25248invoke @value{GDBN} like this:
25249
25250@smallexample
25251$ gdb -q -iex "set auto-load safe-path /home/user/gdb" ./gdb
25252@end smallexample
25253
bccbefd2
JK
25254The list of trusted directories is controlled by the following commands:
25255
25256@table @code
25257@anchor{set auto-load safe-path}
25258@kindex set auto-load safe-path
af2c1515 25259@item set auto-load safe-path @r{[}@var{directories}@r{]}
bccbefd2
JK
25260Set the list of directories (and their subdirectories) trusted for automatic
25261loading and execution of scripts. You can also enter a specific trusted file.
202cbf1c
JK
25262Each directory can also be a shell wildcard pattern; wildcards do not match
25263directory separator - see @code{FNM_PATHNAME} for system function @code{fnmatch}
25264(@pxref{Wildcard Matching, fnmatch, , libc, GNU C Library Reference Manual}).
af2c1515
JK
25265If you omit @var{directories}, @samp{auto-load safe-path} will be reset to
25266its default value as specified during @value{GDBN} compilation.
25267
d9242c17 25268The list of directories uses path separator (@samp{:} on GNU and Unix
bccbefd2
JK
25269systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
25270to the @env{PATH} environment variable.
25271
25272@anchor{show auto-load safe-path}
25273@kindex show auto-load safe-path
25274@item show auto-load safe-path
25275Show the list of directories trusted for automatic loading and execution of
25276scripts.
25277
25278@anchor{add-auto-load-safe-path}
25279@kindex add-auto-load-safe-path
25280@item add-auto-load-safe-path
413b59ae
JK
25281Add an entry (or list of entries) to the list of directories trusted for
25282automatic loading and execution of scripts. Multiple entries may be delimited
25283by the host platform path separator in use.
bccbefd2
JK
25284@end table
25285
7349ff92 25286This variable defaults to what @code{--with-auto-load-dir} has been configured
1564a261
JK
25287to (@pxref{with-auto-load-dir}). @file{$debugdir} and @file{$datadir}
25288substitution applies the same as for @ref{set auto-load scripts-directory}.
25289The default @code{set auto-load safe-path} value can be also overriden by
25290@value{GDBN} configuration option @option{--with-auto-load-safe-path}.
6dea1fbd 25291
6dea1fbd
JK
25292Setting this variable to @file{/} disables this security protection,
25293corresponding @value{GDBN} configuration option is
25294@option{--without-auto-load-safe-path}.
bccbefd2
JK
25295This variable is supposed to be set to the system directories writable by the
25296system superuser only. Users can add their source directories in init files in
25297their home directories (@pxref{Home Directory Init File}). See also deprecated
25298init file in the current directory
25299(@pxref{Init File in the Current Directory during Startup}).
25300
25301To force @value{GDBN} to load the files it declined to load in the previous
25302example, you could use one of the following ways:
25303
0511cc75
JK
25304@table @asis
25305@item @file{~/.gdbinit}: @samp{add-auto-load-safe-path ~/src/gdb}
bccbefd2
JK
25306Specify this trusted directory (or a file) as additional component of the list.
25307You have to specify also any existing directories displayed by
25308by @samp{show auto-load safe-path} (such as @samp{/usr:/bin} in this example).
25309
174bb630 25310@item @kbd{gdb -iex "set auto-load safe-path /usr:/bin:~/src/gdb" @dots{}}
bccbefd2
JK
25311Specify this directory as in the previous case but just for a single
25312@value{GDBN} session.
25313
af2c1515 25314@item @kbd{gdb -iex "set auto-load safe-path /" @dots{}}
bccbefd2
JK
25315Disable auto-loading safety for a single @value{GDBN} session.
25316This assumes all the files you debug during this @value{GDBN} session will come
25317from trusted sources.
25318
25319@item @kbd{./configure --without-auto-load-safe-path}
25320During compilation of @value{GDBN} you may disable any auto-loading safety.
25321This assumes all the files you will ever debug with this @value{GDBN} come from
25322trusted sources.
0511cc75 25323@end table
bccbefd2
JK
25324
25325On the other hand you can also explicitly forbid automatic files loading which
25326also suppresses any such warning messages:
25327
0511cc75 25328@table @asis
174bb630 25329@item @kbd{gdb -iex "set auto-load no" @dots{}}
bccbefd2
JK
25330You can use @value{GDBN} command-line option for a single @value{GDBN} session.
25331
0511cc75 25332@item @file{~/.gdbinit}: @samp{set auto-load no}
bccbefd2
JK
25333Disable auto-loading globally for the user
25334(@pxref{Home Directory Init File}). While it is improbable, you could also
25335use system init file instead (@pxref{System-wide configuration}).
0511cc75 25336@end table
bccbefd2
JK
25337
25338This setting applies to the file names as entered by user. If no entry matches
25339@value{GDBN} tries as a last resort to also resolve all the file names into
25340their canonical form (typically resolving symbolic links) and compare the
25341entries again. @value{GDBN} already canonicalizes most of the filenames on its
25342own before starting the comparison so a canonical form of directories is
25343recommended to be entered.
25344
4dc84fd1
JK
25345@node Auto-loading verbose mode
25346@subsection Displaying files tried for auto-load
25347@cindex auto-loading verbose mode
25348
25349For better visibility of all the file locations where you can place scripts to
25350be auto-loaded with inferior --- or to protect yourself against accidental
25351execution of untrusted scripts --- @value{GDBN} provides a feature for printing
25352all the files attempted to be loaded. Both existing and non-existing files may
25353be printed.
25354
25355For example the list of directories from which it is safe to auto-load files
25356(@pxref{Auto-loading safe path}) applies also to canonicalized filenames which
25357may not be too obvious while setting it up.
25358
25359@smallexample
0070f25a 25360(gdb) set debug auto-load on
4dc84fd1
JK
25361(gdb) file ~/src/t/true
25362auto-load: Loading canned sequences of commands script "/tmp/true-gdb.gdb"
25363 for objfile "/tmp/true".
25364auto-load: Updating directories of "/usr:/opt".
25365auto-load: Using directory "/usr".
25366auto-load: Using directory "/opt".
25367warning: File "/tmp/true-gdb.gdb" auto-loading has been declined
25368 by your `auto-load safe-path' set to "/usr:/opt".
25369@end smallexample
25370
25371@table @code
25372@anchor{set debug auto-load}
25373@kindex set debug auto-load
25374@item set debug auto-load [on|off]
25375Set whether to print the filenames attempted to be auto-loaded.
25376
25377@anchor{show debug auto-load}
25378@kindex show debug auto-load
25379@item show debug auto-load
25380Show whether printing of the filenames attempted to be auto-loaded is turned
25381on or off.
25382@end table
25383
8e04817f 25384@node Messages/Warnings
79a6e687 25385@section Optional Warnings and Messages
104c1213 25386
9c16f35a
EZ
25387@cindex verbose operation
25388@cindex optional warnings
8e04817f
AC
25389By default, @value{GDBN} is silent about its inner workings. If you are
25390running on a slow machine, you may want to use the @code{set verbose}
25391command. This makes @value{GDBN} tell you when it does a lengthy
25392internal operation, so you will not think it has crashed.
104c1213 25393
8e04817f
AC
25394Currently, the messages controlled by @code{set verbose} are those
25395which announce that the symbol table for a source file is being read;
79a6e687 25396see @code{symbol-file} in @ref{Files, ,Commands to Specify Files}.
104c1213 25397
8e04817f
AC
25398@table @code
25399@kindex set verbose
25400@item set verbose on
25401Enables @value{GDBN} output of certain informational messages.
104c1213 25402
8e04817f
AC
25403@item set verbose off
25404Disables @value{GDBN} output of certain informational messages.
104c1213 25405
8e04817f
AC
25406@kindex show verbose
25407@item show verbose
25408Displays whether @code{set verbose} is on or off.
25409@end table
104c1213 25410
8e04817f
AC
25411By default, if @value{GDBN} encounters bugs in the symbol table of an
25412object file, it is silent; but if you are debugging a compiler, you may
79a6e687
BW
25413find this information useful (@pxref{Symbol Errors, ,Errors Reading
25414Symbol Files}).
104c1213 25415
8e04817f 25416@table @code
104c1213 25417
8e04817f
AC
25418@kindex set complaints
25419@item set complaints @var{limit}
25420Permits @value{GDBN} to output @var{limit} complaints about each type of
25421unusual symbols before becoming silent about the problem. Set
25422@var{limit} to zero to suppress all complaints; set it to a large number
25423to prevent complaints from being suppressed.
104c1213 25424
8e04817f
AC
25425@kindex show complaints
25426@item show complaints
25427Displays how many symbol complaints @value{GDBN} is permitted to produce.
104c1213 25428
8e04817f 25429@end table
104c1213 25430
d837706a 25431@anchor{confirmation requests}
8e04817f
AC
25432By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
25433lot of stupid questions to confirm certain commands. For example, if
25434you try to run a program which is already running:
104c1213 25435
474c8240 25436@smallexample
8e04817f
AC
25437(@value{GDBP}) run
25438The program being debugged has been started already.
25439Start it from the beginning? (y or n)
474c8240 25440@end smallexample
104c1213 25441
8e04817f
AC
25442If you are willing to unflinchingly face the consequences of your own
25443commands, you can disable this ``feature'':
104c1213 25444
8e04817f 25445@table @code
104c1213 25446
8e04817f
AC
25447@kindex set confirm
25448@cindex flinching
25449@cindex confirmation
25450@cindex stupid questions
25451@item set confirm off
7c953934
TT
25452Disables confirmation requests. Note that running @value{GDBN} with
25453the @option{--batch} option (@pxref{Mode Options, -batch}) also
25454automatically disables confirmation requests.
104c1213 25455
8e04817f
AC
25456@item set confirm on
25457Enables confirmation requests (the default).
104c1213 25458
8e04817f
AC
25459@kindex show confirm
25460@item show confirm
25461Displays state of confirmation requests.
25462
25463@end table
104c1213 25464
16026cd7
AS
25465@cindex command tracing
25466If you need to debug user-defined commands or sourced files you may find it
25467useful to enable @dfn{command tracing}. In this mode each command will be
25468printed as it is executed, prefixed with one or more @samp{+} symbols, the
25469quantity denoting the call depth of each command.
25470
25471@table @code
25472@kindex set trace-commands
25473@cindex command scripts, debugging
25474@item set trace-commands on
25475Enable command tracing.
25476@item set trace-commands off
25477Disable command tracing.
25478@item show trace-commands
25479Display the current state of command tracing.
25480@end table
25481
8e04817f 25482@node Debugging Output
79a6e687 25483@section Optional Messages about Internal Happenings
4644b6e3
EZ
25484@cindex optional debugging messages
25485
da316a69
EZ
25486@value{GDBN} has commands that enable optional debugging messages from
25487various @value{GDBN} subsystems; normally these commands are of
25488interest to @value{GDBN} maintainers, or when reporting a bug. This
25489section documents those commands.
25490
104c1213 25491@table @code
a8f24a35
EZ
25492@kindex set exec-done-display
25493@item set exec-done-display
25494Turns on or off the notification of asynchronous commands'
25495completion. When on, @value{GDBN} will print a message when an
25496asynchronous command finishes its execution. The default is off.
25497@kindex show exec-done-display
25498@item show exec-done-display
25499Displays the current setting of asynchronous command completion
25500notification.
4644b6e3 25501@kindex set debug
be9a8770
PA
25502@cindex ARM AArch64
25503@item set debug aarch64
25504Turns on or off display of debugging messages related to ARM AArch64.
25505The default is off.
25506@kindex show debug
25507@item show debug aarch64
25508Displays the current state of displaying debugging messages related to
25509ARM AArch64.
4644b6e3 25510@cindex gdbarch debugging info
a8f24a35 25511@cindex architecture debugging info
8e04817f 25512@item set debug arch
a8f24a35 25513Turns on or off display of gdbarch debugging info. The default is off
8e04817f
AC
25514@item show debug arch
25515Displays the current state of displaying gdbarch debugging info.
9a005eb9
JB
25516@item set debug aix-solib
25517@cindex AIX shared library debugging
25518Control display of debugging messages from the AIX shared library
25519support module. The default is off.
25520@item show debug aix-thread
25521Show the current state of displaying AIX shared library debugging messages.
721c2651
EZ
25522@item set debug aix-thread
25523@cindex AIX threads
25524Display debugging messages about inner workings of the AIX thread
25525module.
25526@item show debug aix-thread
25527Show the current state of AIX thread debugging info display.
900e11f9
JK
25528@item set debug check-physname
25529@cindex physname
25530Check the results of the ``physname'' computation. When reading DWARF
25531debugging information for C@t{++}, @value{GDBN} attempts to compute
25532each entity's name. @value{GDBN} can do this computation in two
25533different ways, depending on exactly what information is present.
25534When enabled, this setting causes @value{GDBN} to compute the names
25535both ways and display any discrepancies.
25536@item show debug check-physname
25537Show the current state of ``physname'' checking.
be9a8770
PA
25538@item set debug coff-pe-read
25539@cindex COFF/PE exported symbols
25540Control display of debugging messages related to reading of COFF/PE
25541exported symbols. The default is off.
25542@item show debug coff-pe-read
25543Displays the current state of displaying debugging messages related to
25544reading of COFF/PE exported symbols.
b4f54984
DE
25545@item set debug dwarf-die
25546@cindex DWARF DIEs
25547Dump DWARF DIEs after they are read in.
d97bc12b
DE
25548The value is the number of nesting levels to print.
25549A value of zero turns off the display.
b4f54984
DE
25550@item show debug dwarf-die
25551Show the current state of DWARF DIE debugging.
27e0867f
DE
25552@item set debug dwarf-line
25553@cindex DWARF Line Tables
25554Turns on or off display of debugging messages related to reading
25555DWARF line tables. The default is 0 (off).
25556A value of 1 provides basic information.
25557A value greater than 1 provides more verbose information.
25558@item show debug dwarf-line
25559Show the current state of DWARF line table debugging.
b4f54984
DE
25560@item set debug dwarf-read
25561@cindex DWARF Reading
45cfd468 25562Turns on or off display of debugging messages related to reading
73be47f5
DE
25563DWARF debug info. The default is 0 (off).
25564A value of 1 provides basic information.
25565A value greater than 1 provides more verbose information.
b4f54984
DE
25566@item show debug dwarf-read
25567Show the current state of DWARF reader debugging.
237fc4c9
PA
25568@item set debug displaced
25569@cindex displaced stepping debugging info
25570Turns on or off display of @value{GDBN} debugging info for the
25571displaced stepping support. The default is off.
25572@item show debug displaced
25573Displays the current state of displaying @value{GDBN} debugging info
25574related to displaced stepping.
8e04817f 25575@item set debug event
4644b6e3 25576@cindex event debugging info
a8f24a35 25577Turns on or off display of @value{GDBN} event debugging info. The
8e04817f 25578default is off.
8e04817f
AC
25579@item show debug event
25580Displays the current state of displaying @value{GDBN} event debugging
25581info.
8e04817f 25582@item set debug expression
4644b6e3 25583@cindex expression debugging info
721c2651
EZ
25584Turns on or off display of debugging info about @value{GDBN}
25585expression parsing. The default is off.
8e04817f 25586@item show debug expression
721c2651
EZ
25587Displays the current state of displaying debugging info about
25588@value{GDBN} expression parsing.
6e9567fe
JB
25589@item set debug fbsd-lwp
25590@cindex FreeBSD LWP debug messages
25591Turns on or off debugging messages from the FreeBSD LWP debug support.
25592@item show debug fbsd-lwp
25593Show the current state of FreeBSD LWP debugging messages.
386a8676
JB
25594@item set debug fbsd-nat
25595@cindex FreeBSD native target debug messages
25596Turns on or off debugging messages from the FreeBSD native target.
25597@item show debug fbsd-nat
25598Show the current state of FreeBSD native target debugging messages.
7453dc06 25599@item set debug frame
4644b6e3 25600@cindex frame debugging info
7453dc06
AC
25601Turns on or off display of @value{GDBN} frame debugging info. The
25602default is off.
7453dc06
AC
25603@item show debug frame
25604Displays the current state of displaying @value{GDBN} frame debugging
25605info.
cbe54154
PA
25606@item set debug gnu-nat
25607@cindex @sc{gnu}/Hurd debug messages
67ebd9cb 25608Turn on or off debugging messages from the @sc{gnu}/Hurd debug support.
cbe54154
PA
25609@item show debug gnu-nat
25610Show the current state of @sc{gnu}/Hurd debugging messages.
30e91e0b
RC
25611@item set debug infrun
25612@cindex inferior debugging info
25613Turns on or off display of @value{GDBN} debugging info for running the inferior.
25614The default is off. @file{infrun.c} contains GDB's runtime state machine used
25615for implementing operations such as single-stepping the inferior.
25616@item show debug infrun
25617Displays the current state of @value{GDBN} inferior debugging.
a255712f
PP
25618@item set debug jit
25619@cindex just-in-time compilation, debugging messages
67ebd9cb 25620Turn on or off debugging messages from JIT debug support.
a255712f
PP
25621@item show debug jit
25622Displays the current state of @value{GDBN} JIT debugging.
da316a69
EZ
25623@item set debug lin-lwp
25624@cindex @sc{gnu}/Linux LWP debug messages
25625@cindex Linux lightweight processes
67ebd9cb 25626Turn on or off debugging messages from the Linux LWP debug support.
da316a69
EZ
25627@item show debug lin-lwp
25628Show the current state of Linux LWP debugging messages.
7a6a1731
GB
25629@item set debug linux-namespaces
25630@cindex @sc{gnu}/Linux namespaces debug messages
67ebd9cb 25631Turn on or off debugging messages from the Linux namespaces debug support.
7a6a1731
GB
25632@item show debug linux-namespaces
25633Show the current state of Linux namespaces debugging messages.
be9a8770
PA
25634@item set debug mach-o
25635@cindex Mach-O symbols processing
25636Control display of debugging messages related to Mach-O symbols
25637processing. The default is off.
25638@item show debug mach-o
25639Displays the current state of displaying debugging messages related to
25640reading of COFF/PE exported symbols.
c9b6281a
YQ
25641@item set debug notification
25642@cindex remote async notification debugging info
67ebd9cb 25643Turn on or off debugging messages about remote async notification.
c9b6281a
YQ
25644The default is off.
25645@item show debug notification
25646Displays the current state of remote async notification debugging messages.
2b4855ab 25647@item set debug observer
4644b6e3 25648@cindex observer debugging info
2b4855ab
AC
25649Turns on or off display of @value{GDBN} observer debugging. This
25650includes info such as the notification of observable events.
2b4855ab
AC
25651@item show debug observer
25652Displays the current state of observer debugging.
8e04817f 25653@item set debug overload
4644b6e3 25654@cindex C@t{++} overload debugging info
8e04817f 25655Turns on or off display of @value{GDBN} C@t{++} overload debugging
359df76b 25656info. This includes info such as ranking of functions, etc. The default
8e04817f 25657is off.
8e04817f
AC
25658@item show debug overload
25659Displays the current state of displaying @value{GDBN} C@t{++} overload
25660debugging info.
92981e24
TT
25661@cindex expression parser, debugging info
25662@cindex debug expression parser
25663@item set debug parser
25664Turns on or off the display of expression parser debugging output.
25665Internally, this sets the @code{yydebug} variable in the expression
25666parser. @xref{Tracing, , Tracing Your Parser, bison, Bison}, for
25667details. The default is off.
25668@item show debug parser
25669Show the current state of expression parser debugging.
8e04817f
AC
25670@cindex packets, reporting on stdout
25671@cindex serial connections, debugging
605a56cb
DJ
25672@cindex debug remote protocol
25673@cindex remote protocol debugging
25674@cindex display remote packets
8e04817f
AC
25675@item set debug remote
25676Turns on or off display of reports on all packets sent back and forth across
25677the serial line to the remote machine. The info is printed on the
25678@value{GDBN} standard output stream. The default is off.
8e04817f
AC
25679@item show debug remote
25680Displays the state of display of remote packets.
c4dcb155
SM
25681
25682@item set debug separate-debug-file
25683Turns on or off display of debug output about separate debug file search.
25684@item show debug separate-debug-file
25685Displays the state of separate debug file search debug output.
25686
8e04817f
AC
25687@item set debug serial
25688Turns on or off display of @value{GDBN} serial debugging info. The
25689default is off.
8e04817f
AC
25690@item show debug serial
25691Displays the current state of displaying @value{GDBN} serial debugging
25692info.
c45da7e6
EZ
25693@item set debug solib-frv
25694@cindex FR-V shared-library debugging
67ebd9cb 25695Turn on or off debugging messages for FR-V shared-library code.
c45da7e6
EZ
25696@item show debug solib-frv
25697Display the current state of FR-V shared-library code debugging
25698messages.
cc485e62
DE
25699@item set debug symbol-lookup
25700@cindex symbol lookup
25701Turns on or off display of debugging messages related to symbol lookup.
25702The default is 0 (off).
25703A value of 1 provides basic information.
25704A value greater than 1 provides more verbose information.
25705@item show debug symbol-lookup
25706Show the current state of symbol lookup debugging messages.
8fb8eb5c
DE
25707@item set debug symfile
25708@cindex symbol file functions
25709Turns on or off display of debugging messages related to symbol file functions.
25710The default is off. @xref{Files}.
25711@item show debug symfile
25712Show the current state of symbol file debugging messages.
45cfd468
DE
25713@item set debug symtab-create
25714@cindex symbol table creation
25715Turns on or off display of debugging messages related to symbol table creation.
db0fec5c
DE
25716The default is 0 (off).
25717A value of 1 provides basic information.
25718A value greater than 1 provides more verbose information.
45cfd468
DE
25719@item show debug symtab-create
25720Show the current state of symbol table creation debugging.
8e04817f 25721@item set debug target
4644b6e3 25722@cindex target debugging info
8e04817f
AC
25723Turns on or off display of @value{GDBN} target debugging info. This info
25724includes what is going on at the target level of GDB, as it happens. The
701b08bb 25725default is 0. Set it to 1 to track events, and to 2 to also track the
3cecbbbe 25726value of large memory transfers.
8e04817f
AC
25727@item show debug target
25728Displays the current state of displaying @value{GDBN} target debugging
25729info.
75feb17d
DJ
25730@item set debug timestamp
25731@cindex timestampping debugging info
25732Turns on or off display of timestamps with @value{GDBN} debugging info.
25733When enabled, seconds and microseconds are displayed before each debugging
25734message.
25735@item show debug timestamp
25736Displays the current state of displaying timestamps with @value{GDBN}
25737debugging info.
f989a1c8 25738@item set debug varobj
4644b6e3 25739@cindex variable object debugging info
8e04817f
AC
25740Turns on or off display of @value{GDBN} variable object debugging
25741info. The default is off.
f989a1c8 25742@item show debug varobj
8e04817f
AC
25743Displays the current state of displaying @value{GDBN} variable object
25744debugging info.
e776119f
DJ
25745@item set debug xml
25746@cindex XML parser debugging
67ebd9cb 25747Turn on or off debugging messages for built-in XML parsers.
e776119f
DJ
25748@item show debug xml
25749Displays the current state of XML debugging messages.
8e04817f 25750@end table
104c1213 25751
14fb1bac
JB
25752@node Other Misc Settings
25753@section Other Miscellaneous Settings
25754@cindex miscellaneous settings
25755
25756@table @code
25757@kindex set interactive-mode
25758@item set interactive-mode
7bfc9434
JB
25759If @code{on}, forces @value{GDBN} to assume that GDB was started
25760in a terminal. In practice, this means that @value{GDBN} should wait
25761for the user to answer queries generated by commands entered at
25762the command prompt. If @code{off}, forces @value{GDBN} to operate
25763in the opposite mode, and it uses the default answers to all queries.
25764If @code{auto} (the default), @value{GDBN} tries to determine whether
25765its standard input is a terminal, and works in interactive-mode if it
25766is, non-interactively otherwise.
14fb1bac
JB
25767
25768In the vast majority of cases, the debugger should be able to guess
25769correctly which mode should be used. But this setting can be useful
25770in certain specific cases, such as running a MinGW @value{GDBN}
25771inside a cygwin window.
25772
25773@kindex show interactive-mode
25774@item show interactive-mode
25775Displays whether the debugger is operating in interactive mode or not.
25776@end table
25777
d57a3c85
TJB
25778@node Extending GDB
25779@chapter Extending @value{GDBN}
25780@cindex extending GDB
25781
71b8c845
DE
25782@value{GDBN} provides several mechanisms for extension.
25783@value{GDBN} also provides the ability to automatically load
25784extensions when it reads a file for debugging. This allows the
25785user to automatically customize @value{GDBN} for the program
25786being debugged.
d57a3c85 25787
71b8c845
DE
25788@menu
25789* Sequences:: Canned Sequences of @value{GDBN} Commands
25790* Python:: Extending @value{GDBN} using Python
ed3ef339 25791* Guile:: Extending @value{GDBN} using Guile
71b8c845 25792* Auto-loading extensions:: Automatically loading extensions
ed3ef339 25793* Multiple Extension Languages:: Working with multiple extension languages
71b8c845
DE
25794* Aliases:: Creating new spellings of existing commands
25795@end menu
25796
25797To facilitate the use of extension languages, @value{GDBN} is capable
95433b34 25798of evaluating the contents of a file. When doing so, @value{GDBN}
71b8c845 25799can recognize which extension language is being used by looking at
95433b34
JB
25800the filename extension. Files with an unrecognized filename extension
25801are always treated as a @value{GDBN} Command Files.
25802@xref{Command Files,, Command files}.
25803
25804You can control how @value{GDBN} evaluates these files with the following
25805setting:
25806
25807@table @code
25808@kindex set script-extension
25809@kindex show script-extension
25810@item set script-extension off
25811All scripts are always evaluated as @value{GDBN} Command Files.
25812
25813@item set script-extension soft
25814The debugger determines the scripting language based on filename
25815extension. If this scripting language is supported, @value{GDBN}
25816evaluates the script using that language. Otherwise, it evaluates
25817the file as a @value{GDBN} Command File.
25818
25819@item set script-extension strict
25820The debugger determines the scripting language based on filename
25821extension, and evaluates the script using that language. If the
25822language is not supported, then the evaluation fails.
25823
25824@item show script-extension
25825Display the current value of the @code{script-extension} option.
25826
25827@end table
25828
8e04817f 25829@node Sequences
d57a3c85 25830@section Canned Sequences of Commands
104c1213 25831
8e04817f 25832Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
79a6e687 25833Command Lists}), @value{GDBN} provides two ways to store sequences of
8e04817f
AC
25834commands for execution as a unit: user-defined commands and command
25835files.
104c1213 25836
8e04817f 25837@menu
fcc73fe3
EZ
25838* Define:: How to define your own commands
25839* Hooks:: Hooks for user-defined commands
25840* Command Files:: How to write scripts of commands to be stored in a file
25841* Output:: Commands for controlled output
71b8c845 25842* Auto-loading sequences:: Controlling auto-loaded command files
8e04817f 25843@end menu
104c1213 25844
8e04817f 25845@node Define
d57a3c85 25846@subsection User-defined Commands
104c1213 25847
8e04817f 25848@cindex user-defined command
fcc73fe3 25849@cindex arguments, to user-defined commands
8e04817f
AC
25850A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
25851which you assign a new name as a command. This is done with the
df3ee9ca 25852@code{define} command. User commands may accept an unlimited number of arguments
8e04817f 25853separated by whitespace. Arguments are accessed within the user command
df3ee9ca 25854via @code{$arg0@dots{}$argN}. A trivial example:
104c1213 25855
8e04817f
AC
25856@smallexample
25857define adder
25858 print $arg0 + $arg1 + $arg2
c03c782f 25859end
8e04817f 25860@end smallexample
104c1213
JM
25861
25862@noindent
8e04817f 25863To execute the command use:
104c1213 25864
8e04817f
AC
25865@smallexample
25866adder 1 2 3
25867@end smallexample
104c1213 25868
8e04817f
AC
25869@noindent
25870This defines the command @code{adder}, which prints the sum of
25871its three arguments. Note the arguments are text substitutions, so they may
25872reference variables, use complex expressions, or even perform inferior
25873functions calls.
104c1213 25874
fcc73fe3
EZ
25875@cindex argument count in user-defined commands
25876@cindex how many arguments (user-defined commands)
c03c782f 25877In addition, @code{$argc} may be used to find out how many arguments have
df3ee9ca 25878been passed.
c03c782f
AS
25879
25880@smallexample
25881define adder
25882 if $argc == 2
25883 print $arg0 + $arg1
25884 end
25885 if $argc == 3
25886 print $arg0 + $arg1 + $arg2
25887 end
25888end
25889@end smallexample
25890
01770bbd
PA
25891Combining with the @code{eval} command (@pxref{eval}) makes it easier
25892to process a variable number of arguments:
25893
25894@smallexample
25895define adder
25896 set $i = 0
25897 set $sum = 0
25898 while $i < $argc
25899 eval "set $sum = $sum + $arg%d", $i
25900 set $i = $i + 1
25901 end
25902 print $sum
25903end
25904@end smallexample
25905
104c1213 25906@table @code
104c1213 25907
8e04817f
AC
25908@kindex define
25909@item define @var{commandname}
25910Define a command named @var{commandname}. If there is already a command
25911by that name, you are asked to confirm that you want to redefine it.
697aa1b7 25912The argument @var{commandname} may be a bare command name consisting of letters,
adb483fe
DJ
25913numbers, dashes, and underscores. It may also start with any predefined
25914prefix command. For example, @samp{define target my-target} creates
25915a user-defined @samp{target my-target} command.
104c1213 25916
8e04817f
AC
25917The definition of the command is made up of other @value{GDBN} command lines,
25918which are given following the @code{define} command. The end of these
25919commands is marked by a line containing @code{end}.
104c1213 25920
8e04817f 25921@kindex document
ca91424e 25922@kindex end@r{ (user-defined commands)}
8e04817f
AC
25923@item document @var{commandname}
25924Document the user-defined command @var{commandname}, so that it can be
25925accessed by @code{help}. The command @var{commandname} must already be
25926defined. This command reads lines of documentation just as @code{define}
25927reads the lines of the command definition, ending with @code{end}.
25928After the @code{document} command is finished, @code{help} on command
25929@var{commandname} displays the documentation you have written.
104c1213 25930
8e04817f
AC
25931You may use the @code{document} command again to change the
25932documentation of a command. Redefining the command with @code{define}
25933does not change the documentation.
104c1213 25934
c45da7e6
EZ
25935@kindex dont-repeat
25936@cindex don't repeat command
25937@item dont-repeat
25938Used inside a user-defined command, this tells @value{GDBN} that this
25939command should not be repeated when the user hits @key{RET}
25940(@pxref{Command Syntax, repeat last command}).
25941
8e04817f
AC
25942@kindex help user-defined
25943@item help user-defined
7d74f244
DE
25944List all user-defined commands and all python commands defined in class
25945COMAND_USER. The first line of the documentation or docstring is
25946included (if any).
104c1213 25947
8e04817f
AC
25948@kindex show user
25949@item show user
25950@itemx show user @var{commandname}
25951Display the @value{GDBN} commands used to define @var{commandname} (but
25952not its documentation). If no @var{commandname} is given, display the
25953definitions for all user-defined commands.
7d74f244 25954This does not work for user-defined python commands.
104c1213 25955
fcc73fe3 25956@cindex infinite recursion in user-defined commands
20f01a46
DH
25957@kindex show max-user-call-depth
25958@kindex set max-user-call-depth
25959@item show max-user-call-depth
5ca0cb28
DH
25960@itemx set max-user-call-depth
25961The value of @code{max-user-call-depth} controls how many recursion
3f94c067 25962levels are allowed in user-defined commands before @value{GDBN} suspects an
5ca0cb28 25963infinite recursion and aborts the command.
7d74f244 25964This does not apply to user-defined python commands.
104c1213
JM
25965@end table
25966
fcc73fe3
EZ
25967In addition to the above commands, user-defined commands frequently
25968use control flow commands, described in @ref{Command Files}.
25969
8e04817f
AC
25970When user-defined commands are executed, the
25971commands of the definition are not printed. An error in any command
25972stops execution of the user-defined command.
104c1213 25973
8e04817f
AC
25974If used interactively, commands that would ask for confirmation proceed
25975without asking when used inside a user-defined command. Many @value{GDBN}
25976commands that normally print messages to say what they are doing omit the
25977messages when used in a user-defined command.
104c1213 25978
8e04817f 25979@node Hooks
d57a3c85 25980@subsection User-defined Command Hooks
8e04817f
AC
25981@cindex command hooks
25982@cindex hooks, for commands
25983@cindex hooks, pre-command
104c1213 25984
8e04817f 25985@kindex hook
8e04817f
AC
25986You may define @dfn{hooks}, which are a special kind of user-defined
25987command. Whenever you run the command @samp{foo}, if the user-defined
25988command @samp{hook-foo} exists, it is executed (with no arguments)
25989before that command.
104c1213 25990
8e04817f
AC
25991@cindex hooks, post-command
25992@kindex hookpost
8e04817f
AC
25993A hook may also be defined which is run after the command you executed.
25994Whenever you run the command @samp{foo}, if the user-defined command
25995@samp{hookpost-foo} exists, it is executed (with no arguments) after
25996that command. Post-execution hooks may exist simultaneously with
25997pre-execution hooks, for the same command.
104c1213 25998
8e04817f 25999It is valid for a hook to call the command which it hooks. If this
9f1c6395 26000occurs, the hook is not re-executed, thereby avoiding infinite recursion.
104c1213 26001
8e04817f
AC
26002@c It would be nice if hookpost could be passed a parameter indicating
26003@c if the command it hooks executed properly or not. FIXME!
104c1213 26004
8e04817f
AC
26005@kindex stop@r{, a pseudo-command}
26006In addition, a pseudo-command, @samp{stop} exists. Defining
26007(@samp{hook-stop}) makes the associated commands execute every time
26008execution stops in your program: before breakpoint commands are run,
26009displays are printed, or the stack frame is printed.
104c1213 26010
8e04817f
AC
26011For example, to ignore @code{SIGALRM} signals while
26012single-stepping, but treat them normally during normal execution,
26013you could define:
104c1213 26014
474c8240 26015@smallexample
8e04817f
AC
26016define hook-stop
26017handle SIGALRM nopass
26018end
104c1213 26019
8e04817f
AC
26020define hook-run
26021handle SIGALRM pass
26022end
104c1213 26023
8e04817f 26024define hook-continue
d3e8051b 26025handle SIGALRM pass
8e04817f 26026end
474c8240 26027@end smallexample
104c1213 26028
d3e8051b 26029As a further example, to hook at the beginning and end of the @code{echo}
b383017d 26030command, and to add extra text to the beginning and end of the message,
8e04817f 26031you could define:
104c1213 26032
474c8240 26033@smallexample
8e04817f
AC
26034define hook-echo
26035echo <<<---
26036end
104c1213 26037
8e04817f
AC
26038define hookpost-echo
26039echo --->>>\n
26040end
104c1213 26041
8e04817f
AC
26042(@value{GDBP}) echo Hello World
26043<<<---Hello World--->>>
26044(@value{GDBP})
104c1213 26045
474c8240 26046@end smallexample
104c1213 26047
8e04817f
AC
26048You can define a hook for any single-word command in @value{GDBN}, but
26049not for command aliases; you should define a hook for the basic command
c1468174 26050name, e.g.@: @code{backtrace} rather than @code{bt}.
8e04817f
AC
26051@c FIXME! So how does Joe User discover whether a command is an alias
26052@c or not?
adb483fe
DJ
26053You can hook a multi-word command by adding @code{hook-} or
26054@code{hookpost-} to the last word of the command, e.g.@:
26055@samp{define target hook-remote} to add a hook to @samp{target remote}.
26056
8e04817f
AC
26057If an error occurs during the execution of your hook, execution of
26058@value{GDBN} commands stops and @value{GDBN} issues a prompt
26059(before the command that you actually typed had a chance to run).
104c1213 26060
8e04817f
AC
26061If you try to define a hook which does not match any known command, you
26062get a warning from the @code{define} command.
c906108c 26063
8e04817f 26064@node Command Files
d57a3c85 26065@subsection Command Files
c906108c 26066
8e04817f 26067@cindex command files
fcc73fe3 26068@cindex scripting commands
6fc08d32
EZ
26069A command file for @value{GDBN} is a text file made of lines that are
26070@value{GDBN} commands. Comments (lines starting with @kbd{#}) may
26071also be included. An empty line in a command file does nothing; it
26072does not mean to repeat the last command, as it would from the
26073terminal.
c906108c 26074
6fc08d32 26075You can request the execution of a command file with the @code{source}
95433b34
JB
26076command. Note that the @code{source} command is also used to evaluate
26077scripts that are not Command Files. The exact behavior can be configured
26078using the @code{script-extension} setting.
26079@xref{Extending GDB,, Extending GDB}.
c906108c 26080
8e04817f
AC
26081@table @code
26082@kindex source
ca91424e 26083@cindex execute commands from a file
3f7b2faa 26084@item source [-s] [-v] @var{filename}
8e04817f 26085Execute the command file @var{filename}.
c906108c
SS
26086@end table
26087
fcc73fe3
EZ
26088The lines in a command file are generally executed sequentially,
26089unless the order of execution is changed by one of the
26090@emph{flow-control commands} described below. The commands are not
a71ec265
DH
26091printed as they are executed. An error in any command terminates
26092execution of the command file and control is returned to the console.
c906108c 26093
08001717
DE
26094@value{GDBN} first searches for @var{filename} in the current directory.
26095If the file is not found there, and @var{filename} does not specify a
26096directory, then @value{GDBN} also looks for the file on the source search path
26097(specified with the @samp{directory} command);
26098except that @file{$cdir} is not searched because the compilation directory
26099is not relevant to scripts.
4b505b12 26100
3f7b2faa
DE
26101If @code{-s} is specified, then @value{GDBN} searches for @var{filename}
26102on the search path even if @var{filename} specifies a directory.
26103The search is done by appending @var{filename} to each element of the
26104search path. So, for example, if @var{filename} is @file{mylib/myscript}
26105and the search path contains @file{/home/user} then @value{GDBN} will
26106look for the script @file{/home/user/mylib/myscript}.
26107The search is also done if @var{filename} is an absolute path.
26108For example, if @var{filename} is @file{/tmp/myscript} and
26109the search path contains @file{/home/user} then @value{GDBN} will
26110look for the script @file{/home/user/tmp/myscript}.
26111For DOS-like systems, if @var{filename} contains a drive specification,
26112it is stripped before concatenation. For example, if @var{filename} is
26113@file{d:myscript} and the search path contains @file{c:/tmp} then @value{GDBN}
26114will look for the script @file{c:/tmp/myscript}.
26115
16026cd7
AS
26116If @code{-v}, for verbose mode, is given then @value{GDBN} displays
26117each command as it is executed. The option must be given before
26118@var{filename}, and is interpreted as part of the filename anywhere else.
26119
8e04817f
AC
26120Commands that would ask for confirmation if used interactively proceed
26121without asking when used in a command file. Many @value{GDBN} commands that
26122normally print messages to say what they are doing omit the messages
26123when called from command files.
c906108c 26124
8e04817f
AC
26125@value{GDBN} also accepts command input from standard input. In this
26126mode, normal output goes to standard output and error output goes to
26127standard error. Errors in a command file supplied on standard input do
6fc08d32 26128not terminate execution of the command file---execution continues with
8e04817f 26129the next command.
c906108c 26130
474c8240 26131@smallexample
8e04817f 26132gdb < cmds > log 2>&1
474c8240 26133@end smallexample
c906108c 26134
8e04817f
AC
26135(The syntax above will vary depending on the shell used.) This example
26136will execute commands from the file @file{cmds}. All output and errors
26137would be directed to @file{log}.
c906108c 26138
fcc73fe3
EZ
26139Since commands stored on command files tend to be more general than
26140commands typed interactively, they frequently need to deal with
26141complicated situations, such as different or unexpected values of
26142variables and symbols, changes in how the program being debugged is
26143built, etc. @value{GDBN} provides a set of flow-control commands to
26144deal with these complexities. Using these commands, you can write
26145complex scripts that loop over data structures, execute commands
26146conditionally, etc.
26147
26148@table @code
26149@kindex if
26150@kindex else
26151@item if
26152@itemx else
26153This command allows to include in your script conditionally executed
26154commands. The @code{if} command takes a single argument, which is an
26155expression to evaluate. It is followed by a series of commands that
26156are executed only if the expression is true (its value is nonzero).
26157There can then optionally be an @code{else} line, followed by a series
26158of commands that are only executed if the expression was false. The
26159end of the list is marked by a line containing @code{end}.
26160
26161@kindex while
26162@item while
26163This command allows to write loops. Its syntax is similar to
26164@code{if}: the command takes a single argument, which is an expression
26165to evaluate, and must be followed by the commands to execute, one per
26166line, terminated by an @code{end}. These commands are called the
26167@dfn{body} of the loop. The commands in the body of @code{while} are
26168executed repeatedly as long as the expression evaluates to true.
26169
26170@kindex loop_break
26171@item loop_break
26172This command exits the @code{while} loop in whose body it is included.
26173Execution of the script continues after that @code{while}s @code{end}
26174line.
26175
26176@kindex loop_continue
26177@item loop_continue
26178This command skips the execution of the rest of the body of commands
26179in the @code{while} loop in whose body it is included. Execution
26180branches to the beginning of the @code{while} loop, where it evaluates
26181the controlling expression.
ca91424e
EZ
26182
26183@kindex end@r{ (if/else/while commands)}
26184@item end
26185Terminate the block of commands that are the body of @code{if},
26186@code{else}, or @code{while} flow-control commands.
fcc73fe3
EZ
26187@end table
26188
26189
8e04817f 26190@node Output
d57a3c85 26191@subsection Commands for Controlled Output
c906108c 26192
8e04817f
AC
26193During the execution of a command file or a user-defined command, normal
26194@value{GDBN} output is suppressed; the only output that appears is what is
26195explicitly printed by the commands in the definition. This section
26196describes three commands useful for generating exactly the output you
26197want.
c906108c
SS
26198
26199@table @code
8e04817f
AC
26200@kindex echo
26201@item echo @var{text}
26202@c I do not consider backslash-space a standard C escape sequence
26203@c because it is not in ANSI.
26204Print @var{text}. Nonprinting characters can be included in
26205@var{text} using C escape sequences, such as @samp{\n} to print a
26206newline. @strong{No newline is printed unless you specify one.}
26207In addition to the standard C escape sequences, a backslash followed
26208by a space stands for a space. This is useful for displaying a
26209string with spaces at the beginning or the end, since leading and
26210trailing spaces are otherwise trimmed from all arguments.
26211To print @samp{@w{ }and foo =@w{ }}, use the command
26212@samp{echo \@w{ }and foo = \@w{ }}.
c906108c 26213
8e04817f
AC
26214A backslash at the end of @var{text} can be used, as in C, to continue
26215the command onto subsequent lines. For example,
c906108c 26216
474c8240 26217@smallexample
8e04817f
AC
26218echo This is some text\n\
26219which is continued\n\
26220onto several lines.\n
474c8240 26221@end smallexample
c906108c 26222
8e04817f 26223produces the same output as
c906108c 26224
474c8240 26225@smallexample
8e04817f
AC
26226echo This is some text\n
26227echo which is continued\n
26228echo onto several lines.\n
474c8240 26229@end smallexample
c906108c 26230
8e04817f
AC
26231@kindex output
26232@item output @var{expression}
26233Print the value of @var{expression} and nothing but that value: no
26234newlines, no @samp{$@var{nn} = }. The value is not entered in the
26235value history either. @xref{Expressions, ,Expressions}, for more information
26236on expressions.
c906108c 26237
8e04817f
AC
26238@item output/@var{fmt} @var{expression}
26239Print the value of @var{expression} in format @var{fmt}. You can use
26240the same formats as for @code{print}. @xref{Output Formats,,Output
79a6e687 26241Formats}, for more information.
c906108c 26242
8e04817f 26243@kindex printf
82160952
EZ
26244@item printf @var{template}, @var{expressions}@dots{}
26245Print the values of one or more @var{expressions} under the control of
26246the string @var{template}. To print several values, make
26247@var{expressions} be a comma-separated list of individual expressions,
26248which may be either numbers or pointers. Their values are printed as
26249specified by @var{template}, exactly as a C program would do by
26250executing the code below:
c906108c 26251
474c8240 26252@smallexample
82160952 26253printf (@var{template}, @var{expressions}@dots{});
474c8240 26254@end smallexample
c906108c 26255
82160952
EZ
26256As in @code{C} @code{printf}, ordinary characters in @var{template}
26257are printed verbatim, while @dfn{conversion specification} introduced
26258by the @samp{%} character cause subsequent @var{expressions} to be
26259evaluated, their values converted and formatted according to type and
26260style information encoded in the conversion specifications, and then
26261printed.
26262
8e04817f 26263For example, you can print two values in hex like this:
c906108c 26264
8e04817f
AC
26265@smallexample
26266printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
26267@end smallexample
c906108c 26268
82160952
EZ
26269@code{printf} supports all the standard @code{C} conversion
26270specifications, including the flags and modifiers between the @samp{%}
26271character and the conversion letter, with the following exceptions:
26272
26273@itemize @bullet
26274@item
26275The argument-ordering modifiers, such as @samp{2$}, are not supported.
26276
26277@item
26278The modifier @samp{*} is not supported for specifying precision or
26279width.
26280
26281@item
26282The @samp{'} flag (for separation of digits into groups according to
26283@code{LC_NUMERIC'}) is not supported.
26284
26285@item
26286The type modifiers @samp{hh}, @samp{j}, @samp{t}, and @samp{z} are not
26287supported.
26288
26289@item
26290The conversion letter @samp{n} (as in @samp{%n}) is not supported.
26291
26292@item
26293The conversion letters @samp{a} and @samp{A} are not supported.
26294@end itemize
26295
26296@noindent
26297Note that the @samp{ll} type modifier is supported only if the
26298underlying @code{C} implementation used to build @value{GDBN} supports
26299the @code{long long int} type, and the @samp{L} type modifier is
26300supported only if @code{long double} type is available.
26301
26302As in @code{C}, @code{printf} supports simple backslash-escape
26303sequences, such as @code{\n}, @samp{\t}, @samp{\\}, @samp{\"},
26304@samp{\a}, and @samp{\f}, that consist of backslash followed by a
26305single character. Octal and hexadecimal escape sequences are not
26306supported.
1a619819
LM
26307
26308Additionally, @code{printf} supports conversion specifications for DFP
0aea4bf3
LM
26309(@dfn{Decimal Floating Point}) types using the following length modifiers
26310together with a floating point specifier.
1a619819
LM
26311letters:
26312
26313@itemize @bullet
26314@item
26315@samp{H} for printing @code{Decimal32} types.
26316
26317@item
26318@samp{D} for printing @code{Decimal64} types.
26319
26320@item
26321@samp{DD} for printing @code{Decimal128} types.
26322@end itemize
26323
26324If the underlying @code{C} implementation used to build @value{GDBN} has
0aea4bf3 26325support for the three length modifiers for DFP types, other modifiers
3b784c4f 26326such as width and precision will also be available for @value{GDBN} to use.
1a619819
LM
26327
26328In case there is no such @code{C} support, no additional modifiers will be
26329available and the value will be printed in the standard way.
26330
26331Here's an example of printing DFP types using the above conversion letters:
26332@smallexample
0aea4bf3 26333printf "D32: %Hf - D64: %Df - D128: %DDf\n",1.2345df,1.2E10dd,1.2E1dl
1a619819
LM
26334@end smallexample
26335
01770bbd 26336@anchor{eval}
f1421989
HZ
26337@kindex eval
26338@item eval @var{template}, @var{expressions}@dots{}
26339Convert the values of one or more @var{expressions} under the control of
26340the string @var{template} to a command line, and call it.
26341
c906108c
SS
26342@end table
26343
71b8c845
DE
26344@node Auto-loading sequences
26345@subsection Controlling auto-loading native @value{GDBN} scripts
26346@cindex native script auto-loading
26347
26348When a new object file is read (for example, due to the @code{file}
26349command, or because the inferior has loaded a shared library),
26350@value{GDBN} will look for the command file @file{@var{objfile}-gdb.gdb}.
26351@xref{Auto-loading extensions}.
26352
26353Auto-loading can be enabled or disabled,
26354and the list of auto-loaded scripts can be printed.
26355
26356@table @code
26357@anchor{set auto-load gdb-scripts}
26358@kindex set auto-load gdb-scripts
26359@item set auto-load gdb-scripts [on|off]
26360Enable or disable the auto-loading of canned sequences of commands scripts.
26361
26362@anchor{show auto-load gdb-scripts}
26363@kindex show auto-load gdb-scripts
26364@item show auto-load gdb-scripts
26365Show whether auto-loading of canned sequences of commands scripts is enabled or
26366disabled.
26367
26368@anchor{info auto-load gdb-scripts}
26369@kindex info auto-load gdb-scripts
26370@cindex print list of auto-loaded canned sequences of commands scripts
26371@item info auto-load gdb-scripts [@var{regexp}]
26372Print the list of all canned sequences of commands scripts that @value{GDBN}
26373auto-loaded.
26374@end table
26375
26376If @var{regexp} is supplied only canned sequences of commands scripts with
26377matching names are printed.
26378
329baa95
DE
26379@c Python docs live in a separate file.
26380@include python.texi
0e3509db 26381
ed3ef339
DE
26382@c Guile docs live in a separate file.
26383@include guile.texi
26384
71b8c845
DE
26385@node Auto-loading extensions
26386@section Auto-loading extensions
26387@cindex auto-loading extensions
26388
26389@value{GDBN} provides two mechanisms for automatically loading extensions
26390when a new object file is read (for example, due to the @code{file}
26391command, or because the inferior has loaded a shared library):
26392@file{@var{objfile}-gdb.@var{ext}} and the @code{.debug_gdb_scripts}
26393section of modern file formats like ELF.
26394
26395@menu
26396* objfile-gdb.ext file: objfile-gdbdotext file. The @file{@var{objfile}-gdb.@var{ext}} file
26397* .debug_gdb_scripts section: dotdebug_gdb_scripts section. The @code{.debug_gdb_scripts} section
26398* Which flavor to choose?::
26399@end menu
26400
26401The auto-loading feature is useful for supplying application-specific
26402debugging commands and features.
26403
26404Auto-loading can be enabled or disabled,
26405and the list of auto-loaded scripts can be printed.
26406See the @samp{auto-loading} section of each extension language
26407for more information.
26408For @value{GDBN} command files see @ref{Auto-loading sequences}.
26409For Python files see @ref{Python Auto-loading}.
26410
26411Note that loading of this script file also requires accordingly configured
26412@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
26413
26414@node objfile-gdbdotext file
26415@subsection The @file{@var{objfile}-gdb.@var{ext}} file
26416@cindex @file{@var{objfile}-gdb.gdb}
26417@cindex @file{@var{objfile}-gdb.py}
26418@cindex @file{@var{objfile}-gdb.scm}
26419
26420When a new object file is read, @value{GDBN} looks for a file named
26421@file{@var{objfile}-gdb.@var{ext}} (we call it @var{script-name} below),
26422where @var{objfile} is the object file's name and
26423where @var{ext} is the file extension for the extension language:
26424
26425@table @code
26426@item @file{@var{objfile}-gdb.gdb}
26427GDB's own command language
26428@item @file{@var{objfile}-gdb.py}
26429Python
ed3ef339
DE
26430@item @file{@var{objfile}-gdb.scm}
26431Guile
71b8c845
DE
26432@end table
26433
26434@var{script-name} is formed by ensuring that the file name of @var{objfile}
26435is absolute, following all symlinks, and resolving @code{.} and @code{..}
26436components, and appending the @file{-gdb.@var{ext}} suffix.
26437If this file exists and is readable, @value{GDBN} will evaluate it as a
26438script in the specified extension language.
26439
26440If this file does not exist, then @value{GDBN} will look for
26441@var{script-name} file in all of the directories as specified below.
26442
26443Note that loading of these files requires an accordingly configured
26444@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
26445
26446For object files using @file{.exe} suffix @value{GDBN} tries to load first the
26447scripts normally according to its @file{.exe} filename. But if no scripts are
26448found @value{GDBN} also tries script filenames matching the object file without
26449its @file{.exe} suffix. This @file{.exe} stripping is case insensitive and it
26450is attempted on any platform. This makes the script filenames compatible
26451between Unix and MS-Windows hosts.
26452
26453@table @code
26454@anchor{set auto-load scripts-directory}
26455@kindex set auto-load scripts-directory
26456@item set auto-load scripts-directory @r{[}@var{directories}@r{]}
26457Control @value{GDBN} auto-loaded scripts location. Multiple directory entries
26458may be delimited by the host platform path separator in use
26459(@samp{:} on Unix, @samp{;} on MS-Windows and MS-DOS).
26460
26461Each entry here needs to be covered also by the security setting
26462@code{set auto-load safe-path} (@pxref{set auto-load safe-path}).
26463
26464@anchor{with-auto-load-dir}
26465This variable defaults to @file{$debugdir:$datadir/auto-load}. The default
26466@code{set auto-load safe-path} value can be also overriden by @value{GDBN}
26467configuration option @option{--with-auto-load-dir}.
26468
26469Any reference to @file{$debugdir} will get replaced by
26470@var{debug-file-directory} value (@pxref{Separate Debug Files}) and any
26471reference to @file{$datadir} will get replaced by @var{data-directory} which is
26472determined at @value{GDBN} startup (@pxref{Data Files}). @file{$debugdir} and
26473@file{$datadir} must be placed as a directory component --- either alone or
26474delimited by @file{/} or @file{\} directory separators, depending on the host
26475platform.
26476
26477The list of directories uses path separator (@samp{:} on GNU and Unix
26478systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
26479to the @env{PATH} environment variable.
26480
26481@anchor{show auto-load scripts-directory}
26482@kindex show auto-load scripts-directory
26483@item show auto-load scripts-directory
26484Show @value{GDBN} auto-loaded scripts location.
f10c5b19
JK
26485
26486@anchor{add-auto-load-scripts-directory}
26487@kindex add-auto-load-scripts-directory
26488@item add-auto-load-scripts-directory @r{[}@var{directories}@dots{}@r{]}
26489Add an entry (or list of entries) to the list of auto-loaded scripts locations.
26490Multiple entries may be delimited by the host platform path separator in use.
71b8c845
DE
26491@end table
26492
26493@value{GDBN} does not track which files it has already auto-loaded this way.
26494@value{GDBN} will load the associated script every time the corresponding
26495@var{objfile} is opened.
26496So your @file{-gdb.@var{ext}} file should be careful to avoid errors if it
26497is evaluated more than once.
26498
26499@node dotdebug_gdb_scripts section
26500@subsection The @code{.debug_gdb_scripts} section
26501@cindex @code{.debug_gdb_scripts} section
26502
26503For systems using file formats like ELF and COFF,
26504when @value{GDBN} loads a new object file
26505it will look for a special section named @code{.debug_gdb_scripts}.
9f050062
DE
26506If this section exists, its contents is a list of null-terminated entries
26507specifying scripts to load. Each entry begins with a non-null prefix byte that
26508specifies the kind of entry, typically the extension language and whether the
26509script is in a file or inlined in @code{.debug_gdb_scripts}.
71b8c845 26510
9f050062
DE
26511The following entries are supported:
26512
26513@table @code
26514@item SECTION_SCRIPT_ID_PYTHON_FILE = 1
26515@item SECTION_SCRIPT_ID_SCHEME_FILE = 3
26516@item SECTION_SCRIPT_ID_PYTHON_TEXT = 4
26517@item SECTION_SCRIPT_ID_SCHEME_TEXT = 6
26518@end table
26519
26520@subsubsection Script File Entries
26521
26522If the entry specifies a file, @value{GDBN} will look for the file first
26523in the current directory and then along the source search path
71b8c845
DE
26524(@pxref{Source Path, ,Specifying Source Directories}),
26525except that @file{$cdir} is not searched, since the compilation
26526directory is not relevant to scripts.
26527
9f050062 26528File entries can be placed in section @code{.debug_gdb_scripts} with,
71b8c845
DE
26529for example, this GCC macro for Python scripts.
26530
26531@example
26532/* Note: The "MS" section flags are to remove duplicates. */
26533#define DEFINE_GDB_PY_SCRIPT(script_name) \
26534 asm("\
26535.pushsection \".debug_gdb_scripts\", \"MS\",@@progbits,1\n\
26536.byte 1 /* Python */\n\
26537.asciz \"" script_name "\"\n\
26538.popsection \n\
26539");
26540@end example
26541
26542@noindent
ed3ef339 26543For Guile scripts, replace @code{.byte 1} with @code{.byte 3}.
71b8c845
DE
26544Then one can reference the macro in a header or source file like this:
26545
26546@example
26547DEFINE_GDB_PY_SCRIPT ("my-app-scripts.py")
26548@end example
26549
26550The script name may include directories if desired.
26551
26552Note that loading of this script file also requires accordingly configured
26553@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
26554
26555If the macro invocation is put in a header, any application or library
26556using this header will get a reference to the specified script,
26557and with the use of @code{"MS"} attributes on the section, the linker
26558will remove duplicates.
26559
9f050062
DE
26560@subsubsection Script Text Entries
26561
26562Script text entries allow to put the executable script in the entry
26563itself instead of loading it from a file.
26564The first line of the entry, everything after the prefix byte and up to
26565the first newline (@code{0xa}) character, is the script name, and must not
26566contain any kind of space character, e.g., spaces or tabs.
26567The rest of the entry, up to the trailing null byte, is the script to
26568execute in the specified language. The name needs to be unique among
26569all script names, as @value{GDBN} executes each script only once based
26570on its name.
26571
26572Here is an example from file @file{py-section-script.c} in the @value{GDBN}
26573testsuite.
26574
26575@example
26576#include "symcat.h"
26577#include "gdb/section-scripts.h"
26578asm(
26579".pushsection \".debug_gdb_scripts\", \"MS\",@@progbits,1\n"
26580".byte " XSTRING (SECTION_SCRIPT_ID_PYTHON_TEXT) "\n"
26581".ascii \"gdb.inlined-script\\n\"\n"
26582".ascii \"class test_cmd (gdb.Command):\\n\"\n"
26583".ascii \" def __init__ (self):\\n\"\n"
26584".ascii \" super (test_cmd, self).__init__ ("
26585 "\\\"test-cmd\\\", gdb.COMMAND_OBSCURE)\\n\"\n"
26586".ascii \" def invoke (self, arg, from_tty):\\n\"\n"
26587".ascii \" print (\\\"test-cmd output, arg = %s\\\" % arg)\\n\"\n"
26588".ascii \"test_cmd ()\\n\"\n"
26589".byte 0\n"
26590".popsection\n"
26591);
26592@end example
26593
26594Loading of inlined scripts requires a properly configured
26595@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
26596The path to specify in @code{auto-load safe-path} is the path of the file
26597containing the @code{.debug_gdb_scripts} section.
26598
71b8c845
DE
26599@node Which flavor to choose?
26600@subsection Which flavor to choose?
26601
26602Given the multiple ways of auto-loading extensions, it might not always
26603be clear which one to choose. This section provides some guidance.
26604
26605@noindent
26606Benefits of the @file{-gdb.@var{ext}} way:
26607
26608@itemize @bullet
26609@item
26610Can be used with file formats that don't support multiple sections.
26611
26612@item
26613Ease of finding scripts for public libraries.
26614
26615Scripts specified in the @code{.debug_gdb_scripts} section are searched for
26616in the source search path.
26617For publicly installed libraries, e.g., @file{libstdc++}, there typically
26618isn't a source directory in which to find the script.
26619
26620@item
26621Doesn't require source code additions.
26622@end itemize
26623
26624@noindent
26625Benefits of the @code{.debug_gdb_scripts} way:
26626
26627@itemize @bullet
26628@item
26629Works with static linking.
26630
26631Scripts for libraries done the @file{-gdb.@var{ext}} way require an objfile to
26632trigger their loading. When an application is statically linked the only
26633objfile available is the executable, and it is cumbersome to attach all the
26634scripts from all the input libraries to the executable's
26635@file{-gdb.@var{ext}} script.
26636
26637@item
26638Works with classes that are entirely inlined.
26639
26640Some classes can be entirely inlined, and thus there may not be an associated
26641shared library to attach a @file{-gdb.@var{ext}} script to.
26642
26643@item
26644Scripts needn't be copied out of the source tree.
26645
26646In some circumstances, apps can be built out of large collections of internal
26647libraries, and the build infrastructure necessary to install the
26648@file{-gdb.@var{ext}} scripts in a place where @value{GDBN} can find them is
26649cumbersome. It may be easier to specify the scripts in the
26650@code{.debug_gdb_scripts} section as relative paths, and add a path to the
26651top of the source tree to the source search path.
26652@end itemize
26653
ed3ef339
DE
26654@node Multiple Extension Languages
26655@section Multiple Extension Languages
26656
26657The Guile and Python extension languages do not share any state,
26658and generally do not interfere with each other.
26659There are some things to be aware of, however.
26660
26661@subsection Python comes first
26662
26663Python was @value{GDBN}'s first extension language, and to avoid breaking
26664existing behaviour Python comes first. This is generally solved by the
26665``first one wins'' principle. @value{GDBN} maintains a list of enabled
26666extension languages, and when it makes a call to an extension language,
26667(say to pretty-print a value), it tries each in turn until an extension
26668language indicates it has performed the request (e.g., has returned the
26669pretty-printed form of a value).
26670This extends to errors while performing such requests: If an error happens
26671while, for example, trying to pretty-print an object then the error is
26672reported and any following extension languages are not tried.
26673
5a56e9c5
DE
26674@node Aliases
26675@section Creating new spellings of existing commands
26676@cindex aliases for commands
26677
26678It is often useful to define alternate spellings of existing commands.
26679For example, if a new @value{GDBN} command defined in Python has
26680a long name to type, it is handy to have an abbreviated version of it
26681that involves less typing.
26682
26683@value{GDBN} itself uses aliases. For example @samp{s} is an alias
26684of the @samp{step} command even though it is otherwise an ambiguous
26685abbreviation of other commands like @samp{set} and @samp{show}.
26686
26687Aliases are also used to provide shortened or more common versions
26688of multi-word commands. For example, @value{GDBN} provides the
26689@samp{tty} alias of the @samp{set inferior-tty} command.
26690
26691You can define a new alias with the @samp{alias} command.
26692
26693@table @code
26694
26695@kindex alias
26696@item alias [-a] [--] @var{ALIAS} = @var{COMMAND}
26697
26698@end table
26699
26700@var{ALIAS} specifies the name of the new alias.
26701Each word of @var{ALIAS} must consist of letters, numbers, dashes and
26702underscores.
26703
26704@var{COMMAND} specifies the name of an existing command
26705that is being aliased.
26706
26707The @samp{-a} option specifies that the new alias is an abbreviation
26708of the command. Abbreviations are not shown in command
26709lists displayed by the @samp{help} command.
26710
26711The @samp{--} option specifies the end of options,
26712and is useful when @var{ALIAS} begins with a dash.
26713
26714Here is a simple example showing how to make an abbreviation
26715of a command so that there is less to type.
26716Suppose you were tired of typing @samp{disas}, the current
26717shortest unambiguous abbreviation of the @samp{disassemble} command
26718and you wanted an even shorter version named @samp{di}.
26719The following will accomplish this.
26720
26721@smallexample
26722(gdb) alias -a di = disas
26723@end smallexample
26724
26725Note that aliases are different from user-defined commands.
26726With a user-defined command, you also need to write documentation
26727for it with the @samp{document} command.
26728An alias automatically picks up the documentation of the existing command.
26729
26730Here is an example where we make @samp{elms} an abbreviation of
26731@samp{elements} in the @samp{set print elements} command.
26732This is to show that you can make an abbreviation of any part
26733of a command.
26734
26735@smallexample
26736(gdb) alias -a set print elms = set print elements
26737(gdb) alias -a show print elms = show print elements
26738(gdb) set p elms 20
26739(gdb) show p elms
26740Limit on string chars or array elements to print is 200.
26741@end smallexample
26742
26743Note that if you are defining an alias of a @samp{set} command,
26744and you want to have an alias for the corresponding @samp{show}
26745command, then you need to define the latter separately.
26746
26747Unambiguously abbreviated commands are allowed in @var{COMMAND} and
26748@var{ALIAS}, just as they are normally.
26749
26750@smallexample
26751(gdb) alias -a set pr elms = set p ele
26752@end smallexample
26753
26754Finally, here is an example showing the creation of a one word
26755alias for a more complex command.
26756This creates alias @samp{spe} of the command @samp{set print elements}.
26757
26758@smallexample
26759(gdb) alias spe = set print elements
26760(gdb) spe 20
26761@end smallexample
26762
21c294e6
AC
26763@node Interpreters
26764@chapter Command Interpreters
26765@cindex command interpreters
26766
26767@value{GDBN} supports multiple command interpreters, and some command
26768infrastructure to allow users or user interface writers to switch
26769between interpreters or run commands in other interpreters.
26770
26771@value{GDBN} currently supports two command interpreters, the console
26772interpreter (sometimes called the command-line interpreter or @sc{cli})
26773and the machine interface interpreter (or @sc{gdb/mi}). This manual
26774describes both of these interfaces in great detail.
26775
26776By default, @value{GDBN} will start with the console interpreter.
26777However, the user may choose to start @value{GDBN} with another
26778interpreter by specifying the @option{-i} or @option{--interpreter}
26779startup options. Defined interpreters include:
26780
26781@table @code
26782@item console
26783@cindex console interpreter
26784The traditional console or command-line interpreter. This is the most often
26785used interpreter with @value{GDBN}. With no interpreter specified at runtime,
26786@value{GDBN} will use this interpreter.
26787
26788@item mi
26789@cindex mi interpreter
b4be1b06 26790The newest @sc{gdb/mi} interface (currently @code{mi3}). Used primarily
21c294e6
AC
26791by programs wishing to use @value{GDBN} as a backend for a debugger GUI
26792or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
26793Interface}.
26794
b4be1b06
SM
26795@item mi3
26796@cindex mi3 interpreter
26797The @sc{gdb/mi} interface introduced in @value{GDBN} 9.1.
26798
21c294e6
AC
26799@item mi2
26800@cindex mi2 interpreter
b4be1b06 26801The @sc{gdb/mi} interface introduced in @value{GDBN} 6.0.
21c294e6
AC
26802
26803@item mi1
26804@cindex mi1 interpreter
b4be1b06 26805The @sc{gdb/mi} interface introduced in @value{GDBN} 5.1.
21c294e6
AC
26806
26807@end table
26808
26809@cindex invoke another interpreter
21c294e6
AC
26810
26811@kindex interpreter-exec
86f78169
PA
26812You may execute commands in any interpreter from the current
26813interpreter using the appropriate command. If you are running the
26814console interpreter, simply use the @code{interpreter-exec} command:
21c294e6
AC
26815
26816@smallexample
26817interpreter-exec mi "-data-list-register-names"
26818@end smallexample
26819
26820@sc{gdb/mi} has a similar command, although it is only available in versions of
26821@value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
26822
86f78169
PA
26823Note that @code{interpreter-exec} only changes the interpreter for the
26824duration of the specified command. It does not change the interpreter
26825permanently.
26826
26827@cindex start a new independent interpreter
26828
26829Although you may only choose a single interpreter at startup, it is
26830possible to run an independent interpreter on a specified input/output
26831device (usually a tty).
26832
26833For example, consider a debugger GUI or IDE that wants to provide a
26834@value{GDBN} console view. It may do so by embedding a terminal
26835emulator widget in its GUI, starting @value{GDBN} in the traditional
26836command-line mode with stdin/stdout/stderr redirected to that
26837terminal, and then creating an MI interpreter running on a specified
26838input/output device. The console interpreter created by @value{GDBN}
26839at startup handles commands the user types in the terminal widget,
26840while the GUI controls and synchronizes state with @value{GDBN} using
26841the separate MI interpreter.
26842
26843To start a new secondary @dfn{user interface} running MI, use the
26844@code{new-ui} command:
26845
26846@kindex new-ui
26847@cindex new user interface
26848@smallexample
26849new-ui @var{interpreter} @var{tty}
26850@end smallexample
26851
26852The @var{interpreter} parameter specifies the interpreter to run.
26853This accepts the same values as the @code{interpreter-exec} command.
26854For example, @samp{console}, @samp{mi}, @samp{mi2}, etc. The
26855@var{tty} parameter specifies the name of the bidirectional file the
26856interpreter uses for input/output, usually the name of a
26857pseudoterminal slave on Unix systems. For example:
26858
26859@smallexample
26860(@value{GDBP}) new-ui mi /dev/pts/9
26861@end smallexample
26862
26863@noindent
26864runs an MI interpreter on @file{/dev/pts/9}.
26865
8e04817f
AC
26866@node TUI
26867@chapter @value{GDBN} Text User Interface
26868@cindex TUI
d0d5df6f 26869@cindex Text User Interface
c906108c 26870
8e04817f
AC
26871@menu
26872* TUI Overview:: TUI overview
26873* TUI Keys:: TUI key bindings
7cf36c78 26874* TUI Single Key Mode:: TUI single key mode
db2e3e2e 26875* TUI Commands:: TUI-specific commands
8e04817f
AC
26876* TUI Configuration:: TUI configuration variables
26877@end menu
c906108c 26878
46ba6afa 26879The @value{GDBN} Text User Interface (TUI) is a terminal
d0d5df6f
AC
26880interface which uses the @code{curses} library to show the source
26881file, the assembly output, the program registers and @value{GDBN}
46ba6afa
BW
26882commands in separate text windows. The TUI mode is supported only
26883on platforms where a suitable version of the @code{curses} library
26884is available.
d0d5df6f 26885
46ba6afa 26886The TUI mode is enabled by default when you invoke @value{GDBN} as
217bff3e 26887@samp{@value{GDBP} -tui}.
46ba6afa 26888You can also switch in and out of TUI mode while @value{GDBN} runs by
a4ea0946 26889using various TUI commands and key bindings, such as @command{tui
bcd8537c 26890enable} or @kbd{C-x C-a}. @xref{TUI Commands, ,TUI Commands}, and
a4ea0946 26891@ref{TUI Keys, ,TUI Key Bindings}.
c906108c 26892
8e04817f 26893@node TUI Overview
79a6e687 26894@section TUI Overview
c906108c 26895
46ba6afa 26896In TUI mode, @value{GDBN} can display several text windows:
c906108c 26897
8e04817f
AC
26898@table @emph
26899@item command
26900This window is the @value{GDBN} command window with the @value{GDBN}
46ba6afa
BW
26901prompt and the @value{GDBN} output. The @value{GDBN} input is still
26902managed using readline.
c906108c 26903
8e04817f
AC
26904@item source
26905The source window shows the source file of the program. The current
46ba6afa 26906line and active breakpoints are displayed in this window.
c906108c 26907
8e04817f
AC
26908@item assembly
26909The assembly window shows the disassembly output of the program.
c906108c 26910
8e04817f 26911@item register
46ba6afa
BW
26912This window shows the processor registers. Registers are highlighted
26913when their values change.
c906108c
SS
26914@end table
26915
269c21fe 26916The source and assembly windows show the current program position
46ba6afa
BW
26917by highlighting the current line and marking it with a @samp{>} marker.
26918Breakpoints are indicated with two markers. The first marker
269c21fe
SC
26919indicates the breakpoint type:
26920
26921@table @code
26922@item B
26923Breakpoint which was hit at least once.
26924
26925@item b
26926Breakpoint which was never hit.
26927
26928@item H
26929Hardware breakpoint which was hit at least once.
26930
26931@item h
26932Hardware breakpoint which was never hit.
269c21fe
SC
26933@end table
26934
26935The second marker indicates whether the breakpoint is enabled or not:
26936
26937@table @code
26938@item +
26939Breakpoint is enabled.
26940
26941@item -
26942Breakpoint is disabled.
269c21fe
SC
26943@end table
26944
46ba6afa
BW
26945The source, assembly and register windows are updated when the current
26946thread changes, when the frame changes, or when the program counter
26947changes.
26948
26949These windows are not all visible at the same time. The command
26950window is always visible. The others can be arranged in several
26951layouts:
c906108c 26952
8e04817f
AC
26953@itemize @bullet
26954@item
46ba6afa 26955source only,
2df3850c 26956
8e04817f 26957@item
46ba6afa 26958assembly only,
8e04817f
AC
26959
26960@item
46ba6afa 26961source and assembly,
8e04817f
AC
26962
26963@item
46ba6afa 26964source and registers, or
c906108c 26965
8e04817f 26966@item
46ba6afa 26967assembly and registers.
8e04817f 26968@end itemize
c906108c 26969
46ba6afa 26970A status line above the command window shows the following information:
b7bb15bc
SC
26971
26972@table @emph
26973@item target
46ba6afa 26974Indicates the current @value{GDBN} target.
b7bb15bc
SC
26975(@pxref{Targets, ,Specifying a Debugging Target}).
26976
26977@item process
46ba6afa 26978Gives the current process or thread number.
b7bb15bc
SC
26979When no process is being debugged, this field is set to @code{No process}.
26980
26981@item function
26982Gives the current function name for the selected frame.
26983The name is demangled if demangling is turned on (@pxref{Print Settings}).
46ba6afa 26984When there is no symbol corresponding to the current program counter,
b7bb15bc
SC
26985the string @code{??} is displayed.
26986
26987@item line
26988Indicates the current line number for the selected frame.
46ba6afa 26989When the current line number is not known, the string @code{??} is displayed.
b7bb15bc
SC
26990
26991@item pc
26992Indicates the current program counter address.
b7bb15bc
SC
26993@end table
26994
8e04817f
AC
26995@node TUI Keys
26996@section TUI Key Bindings
26997@cindex TUI key bindings
c906108c 26998
8e04817f 26999The TUI installs several key bindings in the readline keymaps
39037522
TT
27000@ifset SYSTEM_READLINE
27001(@pxref{Command Line Editing, , , rluserman, GNU Readline Library}).
27002@end ifset
27003@ifclear SYSTEM_READLINE
27004(@pxref{Command Line Editing}).
27005@end ifclear
27006The following key bindings are installed for both TUI mode and the
27007@value{GDBN} standard mode.
c906108c 27008
8e04817f
AC
27009@table @kbd
27010@kindex C-x C-a
27011@item C-x C-a
27012@kindex C-x a
27013@itemx C-x a
27014@kindex C-x A
27015@itemx C-x A
46ba6afa
BW
27016Enter or leave the TUI mode. When leaving the TUI mode,
27017the curses window management stops and @value{GDBN} operates using
27018its standard mode, writing on the terminal directly. When reentering
27019the TUI mode, control is given back to the curses windows.
8e04817f 27020The screen is then refreshed.
c906108c 27021
8e04817f
AC
27022@kindex C-x 1
27023@item C-x 1
27024Use a TUI layout with only one window. The layout will
27025either be @samp{source} or @samp{assembly}. When the TUI mode
27026is not active, it will switch to the TUI mode.
2df3850c 27027
8e04817f 27028Think of this key binding as the Emacs @kbd{C-x 1} binding.
c906108c 27029
8e04817f
AC
27030@kindex C-x 2
27031@item C-x 2
27032Use a TUI layout with at least two windows. When the current
46ba6afa 27033layout already has two windows, the next layout with two windows is used.
8e04817f
AC
27034When a new layout is chosen, one window will always be common to the
27035previous layout and the new one.
c906108c 27036
8e04817f 27037Think of it as the Emacs @kbd{C-x 2} binding.
2df3850c 27038
72ffddc9
SC
27039@kindex C-x o
27040@item C-x o
27041Change the active window. The TUI associates several key bindings
46ba6afa 27042(like scrolling and arrow keys) with the active window. This command
72ffddc9
SC
27043gives the focus to the next TUI window.
27044
27045Think of it as the Emacs @kbd{C-x o} binding.
27046
7cf36c78
SC
27047@kindex C-x s
27048@item C-x s
46ba6afa
BW
27049Switch in and out of the TUI SingleKey mode that binds single
27050keys to @value{GDBN} commands (@pxref{TUI Single Key Mode}).
c906108c
SS
27051@end table
27052
46ba6afa 27053The following key bindings only work in the TUI mode:
5d161b24 27054
46ba6afa 27055@table @asis
8e04817f 27056@kindex PgUp
46ba6afa 27057@item @key{PgUp}
8e04817f 27058Scroll the active window one page up.
c906108c 27059
8e04817f 27060@kindex PgDn
46ba6afa 27061@item @key{PgDn}
8e04817f 27062Scroll the active window one page down.
c906108c 27063
8e04817f 27064@kindex Up
46ba6afa 27065@item @key{Up}
8e04817f 27066Scroll the active window one line up.
c906108c 27067
8e04817f 27068@kindex Down
46ba6afa 27069@item @key{Down}
8e04817f 27070Scroll the active window one line down.
c906108c 27071
8e04817f 27072@kindex Left
46ba6afa 27073@item @key{Left}
8e04817f 27074Scroll the active window one column left.
c906108c 27075
8e04817f 27076@kindex Right
46ba6afa 27077@item @key{Right}
8e04817f 27078Scroll the active window one column right.
c906108c 27079
8e04817f 27080@kindex C-L
46ba6afa 27081@item @kbd{C-L}
8e04817f 27082Refresh the screen.
8e04817f 27083@end table
c906108c 27084
46ba6afa
BW
27085Because the arrow keys scroll the active window in the TUI mode, they
27086are not available for their normal use by readline unless the command
27087window has the focus. When another window is active, you must use
27088other readline key bindings such as @kbd{C-p}, @kbd{C-n}, @kbd{C-b}
27089and @kbd{C-f} to control the command window.
8e04817f 27090
7cf36c78
SC
27091@node TUI Single Key Mode
27092@section TUI Single Key Mode
27093@cindex TUI single key mode
27094
46ba6afa
BW
27095The TUI also provides a @dfn{SingleKey} mode, which binds several
27096frequently used @value{GDBN} commands to single keys. Type @kbd{C-x s} to
27097switch into this mode, where the following key bindings are used:
7cf36c78
SC
27098
27099@table @kbd
27100@kindex c @r{(SingleKey TUI key)}
27101@item c
27102continue
27103
27104@kindex d @r{(SingleKey TUI key)}
27105@item d
27106down
27107
27108@kindex f @r{(SingleKey TUI key)}
27109@item f
27110finish
27111
27112@kindex n @r{(SingleKey TUI key)}
27113@item n
27114next
27115
a5afdb16
RK
27116@kindex o @r{(SingleKey TUI key)}
27117@item o
27118nexti. The shortcut letter @samp{o} stands for ``step Over''.
27119
7cf36c78
SC
27120@kindex q @r{(SingleKey TUI key)}
27121@item q
46ba6afa 27122exit the SingleKey mode.
7cf36c78
SC
27123
27124@kindex r @r{(SingleKey TUI key)}
27125@item r
27126run
27127
27128@kindex s @r{(SingleKey TUI key)}
27129@item s
27130step
27131
a5afdb16
RK
27132@kindex i @r{(SingleKey TUI key)}
27133@item i
27134stepi. The shortcut letter @samp{i} stands for ``step Into''.
27135
7cf36c78
SC
27136@kindex u @r{(SingleKey TUI key)}
27137@item u
27138up
27139
27140@kindex v @r{(SingleKey TUI key)}
27141@item v
27142info locals
27143
27144@kindex w @r{(SingleKey TUI key)}
27145@item w
27146where
7cf36c78
SC
27147@end table
27148
27149Other keys temporarily switch to the @value{GDBN} command prompt.
27150The key that was pressed is inserted in the editing buffer so that
27151it is possible to type most @value{GDBN} commands without interaction
46ba6afa
BW
27152with the TUI SingleKey mode. Once the command is entered the TUI
27153SingleKey mode is restored. The only way to permanently leave
7f9087cb 27154this mode is by typing @kbd{q} or @kbd{C-x s}.
7cf36c78
SC
27155
27156
8e04817f 27157@node TUI Commands
db2e3e2e 27158@section TUI-specific Commands
8e04817f
AC
27159@cindex TUI commands
27160
27161The TUI has specific commands to control the text windows.
46ba6afa
BW
27162These commands are always available, even when @value{GDBN} is not in
27163the TUI mode. When @value{GDBN} is in the standard mode, most
27164of these commands will automatically switch to the TUI mode.
c906108c 27165
ff12863f
PA
27166Note that if @value{GDBN}'s @code{stdout} is not connected to a
27167terminal, or @value{GDBN} has been started with the machine interface
27168interpreter (@pxref{GDB/MI, ,The @sc{gdb/mi} Interface}), most of
27169these commands will fail with an error, because it would not be
27170possible or desirable to enable curses window management.
27171
c906108c 27172@table @code
a4ea0946
AB
27173@item tui enable
27174@kindex tui enable
27175Activate TUI mode. The last active TUI window layout will be used if
27176TUI mode has prevsiouly been used in the current debugging session,
27177otherwise a default layout is used.
27178
27179@item tui disable
27180@kindex tui disable
27181Disable TUI mode, returning to the console interpreter.
27182
3d757584
SC
27183@item info win
27184@kindex info win
27185List and give the size of all displayed windows.
27186
6008fc5f 27187@item layout @var{name}
4644b6e3 27188@kindex layout
6008fc5f
AB
27189Changes which TUI windows are displayed. In each layout the command
27190window is always displayed, the @var{name} parameter controls which
27191additional windows are displayed, and can be any of the following:
27192
27193@table @code
27194@item next
8e04817f 27195Display the next layout.
2df3850c 27196
6008fc5f 27197@item prev
8e04817f 27198Display the previous layout.
c906108c 27199
6008fc5f
AB
27200@item src
27201Display the source and command windows.
c906108c 27202
6008fc5f
AB
27203@item asm
27204Display the assembly and command windows.
c906108c 27205
6008fc5f
AB
27206@item split
27207Display the source, assembly, and command windows.
c906108c 27208
6008fc5f
AB
27209@item regs
27210When in @code{src} layout display the register, source, and command
27211windows. When in @code{asm} or @code{split} layout display the
27212register, assembler, and command windows.
27213@end table
8e04817f 27214
6008fc5f 27215@item focus @var{name}
8e04817f 27216@kindex focus
6008fc5f
AB
27217Changes which TUI window is currently active for scrolling. The
27218@var{name} parameter can be any of the following:
27219
27220@table @code
27221@item next
46ba6afa
BW
27222Make the next window active for scrolling.
27223
6008fc5f 27224@item prev
46ba6afa
BW
27225Make the previous window active for scrolling.
27226
6008fc5f 27227@item src
46ba6afa
BW
27228Make the source window active for scrolling.
27229
6008fc5f 27230@item asm
46ba6afa
BW
27231Make the assembly window active for scrolling.
27232
6008fc5f 27233@item regs
46ba6afa
BW
27234Make the register window active for scrolling.
27235
6008fc5f 27236@item cmd
46ba6afa 27237Make the command window active for scrolling.
6008fc5f 27238@end table
c906108c 27239
8e04817f
AC
27240@item refresh
27241@kindex refresh
7f9087cb 27242Refresh the screen. This is similar to typing @kbd{C-L}.
c906108c 27243
51f0e40d 27244@item tui reg @var{group}
6a1b180d 27245@kindex tui reg
51f0e40d
AB
27246Changes the register group displayed in the tui register window to
27247@var{group}. If the register window is not currently displayed this
27248command will cause the register window to be displayed. The list of
27249register groups, as well as their order is target specific. The
27250following groups are available on most targets:
27251@table @code
27252@item next
27253Repeatedly selecting this group will cause the display to cycle
27254through all of the available register groups.
27255
27256@item prev
27257Repeatedly selecting this group will cause the display to cycle
27258through all of the available register groups in the reverse order to
27259@var{next}.
27260
27261@item general
27262Display the general registers.
27263@item float
27264Display the floating point registers.
27265@item system
27266Display the system registers.
27267@item vector
27268Display the vector registers.
27269@item all
27270Display all registers.
27271@end table
6a1b180d 27272
8e04817f
AC
27273@item update
27274@kindex update
27275Update the source window and the current execution point.
c906108c 27276
8e04817f
AC
27277@item winheight @var{name} +@var{count}
27278@itemx winheight @var{name} -@var{count}
27279@kindex winheight
27280Change the height of the window @var{name} by @var{count}
27281lines. Positive counts increase the height, while negative counts
bf555842
EZ
27282decrease it. The @var{name} parameter can be one of @code{src} (the
27283source window), @code{cmd} (the command window), @code{asm} (the
27284disassembly window), or @code{regs} (the register display window).
d6677607 27285@end table
2df3850c 27286
8e04817f 27287@node TUI Configuration
79a6e687 27288@section TUI Configuration Variables
8e04817f 27289@cindex TUI configuration variables
c906108c 27290
46ba6afa 27291Several configuration variables control the appearance of TUI windows.
c906108c 27292
8e04817f
AC
27293@table @code
27294@item set tui border-kind @var{kind}
27295@kindex set tui border-kind
27296Select the border appearance for the source, assembly and register windows.
27297The possible values are the following:
27298@table @code
27299@item space
27300Use a space character to draw the border.
c906108c 27301
8e04817f 27302@item ascii
46ba6afa 27303Use @sc{ascii} characters @samp{+}, @samp{-} and @samp{|} to draw the border.
c906108c 27304
8e04817f
AC
27305@item acs
27306Use the Alternate Character Set to draw the border. The border is
27307drawn using character line graphics if the terminal supports them.
8e04817f 27308@end table
c78b4128 27309
8e04817f
AC
27310@item set tui border-mode @var{mode}
27311@kindex set tui border-mode
46ba6afa
BW
27312@itemx set tui active-border-mode @var{mode}
27313@kindex set tui active-border-mode
27314Select the display attributes for the borders of the inactive windows
27315or the active window. The @var{mode} can be one of the following:
8e04817f
AC
27316@table @code
27317@item normal
27318Use normal attributes to display the border.
c906108c 27319
8e04817f
AC
27320@item standout
27321Use standout mode.
c906108c 27322
8e04817f
AC
27323@item reverse
27324Use reverse video mode.
c906108c 27325
8e04817f
AC
27326@item half
27327Use half bright mode.
c906108c 27328
8e04817f
AC
27329@item half-standout
27330Use half bright and standout mode.
c906108c 27331
8e04817f
AC
27332@item bold
27333Use extra bright or bold mode.
c78b4128 27334
8e04817f
AC
27335@item bold-standout
27336Use extra bright or bold and standout mode.
8e04817f 27337@end table
7806cea7
TT
27338
27339@item set tui tab-width @var{nchars}
27340@kindex set tui tab-width
27341@kindex tabset
27342Set the width of tab stops to be @var{nchars} characters. This
27343setting affects the display of TAB characters in the source and
27344assembly windows.
27345@end table
c78b4128 27346
8e04817f
AC
27347@node Emacs
27348@chapter Using @value{GDBN} under @sc{gnu} Emacs
c78b4128 27349
8e04817f
AC
27350@cindex Emacs
27351@cindex @sc{gnu} Emacs
27352A special interface allows you to use @sc{gnu} Emacs to view (and
27353edit) the source files for the program you are debugging with
27354@value{GDBN}.
c906108c 27355
8e04817f
AC
27356To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
27357executable file you want to debug as an argument. This command starts
27358@value{GDBN} as a subprocess of Emacs, with input and output through a newly
27359created Emacs buffer.
27360@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
c906108c 27361
5e252a2e 27362Running @value{GDBN} under Emacs can be just like running @value{GDBN} normally except for two
8e04817f 27363things:
c906108c 27364
8e04817f
AC
27365@itemize @bullet
27366@item
5e252a2e
NR
27367All ``terminal'' input and output goes through an Emacs buffer, called
27368the GUD buffer.
c906108c 27369
8e04817f
AC
27370This applies both to @value{GDBN} commands and their output, and to the input
27371and output done by the program you are debugging.
bf0184be 27372
8e04817f
AC
27373This is useful because it means that you can copy the text of previous
27374commands and input them again; you can even use parts of the output
27375in this way.
bf0184be 27376
8e04817f
AC
27377All the facilities of Emacs' Shell mode are available for interacting
27378with your program. In particular, you can send signals the usual
27379way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
27380stop.
bf0184be
ND
27381
27382@item
8e04817f 27383@value{GDBN} displays source code through Emacs.
bf0184be 27384
8e04817f
AC
27385Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
27386source file for that frame and puts an arrow (@samp{=>}) at the
27387left margin of the current line. Emacs uses a separate buffer for
27388source display, and splits the screen to show both your @value{GDBN} session
27389and the source.
bf0184be 27390
8e04817f
AC
27391Explicit @value{GDBN} @code{list} or search commands still produce output as
27392usual, but you probably have no reason to use them from Emacs.
5e252a2e
NR
27393@end itemize
27394
27395We call this @dfn{text command mode}. Emacs 22.1, and later, also uses
27396a graphical mode, enabled by default, which provides further buffers
27397that can control the execution and describe the state of your program.
27398@xref{GDB Graphical Interface,,, Emacs, The @sc{gnu} Emacs Manual}.
c906108c 27399
64fabec2
AC
27400If you specify an absolute file name when prompted for the @kbd{M-x
27401gdb} argument, then Emacs sets your current working directory to where
27402your program resides. If you only specify the file name, then Emacs
7a9dd1b2 27403sets your current working directory to the directory associated
64fabec2
AC
27404with the previous buffer. In this case, @value{GDBN} may find your
27405program by searching your environment's @code{PATH} variable, but on
27406some operating systems it might not find the source. So, although the
27407@value{GDBN} input and output session proceeds normally, the auxiliary
27408buffer does not display the current source and line of execution.
27409
27410The initial working directory of @value{GDBN} is printed on the top
5e252a2e
NR
27411line of the GUD buffer and this serves as a default for the commands
27412that specify files for @value{GDBN} to operate on. @xref{Files,
27413,Commands to Specify Files}.
64fabec2
AC
27414
27415By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
27416need to call @value{GDBN} by a different name (for example, if you
27417keep several configurations around, with different names) you can
27418customize the Emacs variable @code{gud-gdb-command-name} to run the
27419one you want.
8e04817f 27420
5e252a2e 27421In the GUD buffer, you can use these special Emacs commands in
8e04817f 27422addition to the standard Shell mode commands:
c906108c 27423
8e04817f
AC
27424@table @kbd
27425@item C-h m
5e252a2e 27426Describe the features of Emacs' GUD Mode.
c906108c 27427
64fabec2 27428@item C-c C-s
8e04817f
AC
27429Execute to another source line, like the @value{GDBN} @code{step} command; also
27430update the display window to show the current file and location.
c906108c 27431
64fabec2 27432@item C-c C-n
8e04817f
AC
27433Execute to next source line in this function, skipping all function
27434calls, like the @value{GDBN} @code{next} command. Then update the display window
27435to show the current file and location.
c906108c 27436
64fabec2 27437@item C-c C-i
8e04817f
AC
27438Execute one instruction, like the @value{GDBN} @code{stepi} command; update
27439display window accordingly.
c906108c 27440
8e04817f
AC
27441@item C-c C-f
27442Execute until exit from the selected stack frame, like the @value{GDBN}
27443@code{finish} command.
c906108c 27444
64fabec2 27445@item C-c C-r
8e04817f
AC
27446Continue execution of your program, like the @value{GDBN} @code{continue}
27447command.
b433d00b 27448
64fabec2 27449@item C-c <
8e04817f
AC
27450Go up the number of frames indicated by the numeric argument
27451(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
27452like the @value{GDBN} @code{up} command.
b433d00b 27453
64fabec2 27454@item C-c >
8e04817f
AC
27455Go down the number of frames indicated by the numeric argument, like the
27456@value{GDBN} @code{down} command.
8e04817f 27457@end table
c906108c 27458
7f9087cb 27459In any source file, the Emacs command @kbd{C-x @key{SPC}} (@code{gud-break})
8e04817f 27460tells @value{GDBN} to set a breakpoint on the source line point is on.
c906108c 27461
5e252a2e
NR
27462In text command mode, if you type @kbd{M-x speedbar}, Emacs displays a
27463separate frame which shows a backtrace when the GUD buffer is current.
27464Move point to any frame in the stack and type @key{RET} to make it
27465become the current frame and display the associated source in the
27466source buffer. Alternatively, click @kbd{Mouse-2} to make the
27467selected frame become the current one. In graphical mode, the
27468speedbar displays watch expressions.
64fabec2 27469
8e04817f
AC
27470If you accidentally delete the source-display buffer, an easy way to get
27471it back is to type the command @code{f} in the @value{GDBN} buffer, to
27472request a frame display; when you run under Emacs, this recreates
27473the source buffer if necessary to show you the context of the current
27474frame.
c906108c 27475
8e04817f
AC
27476The source files displayed in Emacs are in ordinary Emacs buffers
27477which are visiting the source files in the usual way. You can edit
27478the files with these buffers if you wish; but keep in mind that @value{GDBN}
27479communicates with Emacs in terms of line numbers. If you add or
27480delete lines from the text, the line numbers that @value{GDBN} knows cease
27481to correspond properly with the code.
b383017d 27482
5e252a2e
NR
27483A more detailed description of Emacs' interaction with @value{GDBN} is
27484given in the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu}
27485Emacs Manual}).
c906108c 27486
922fbb7b
AC
27487@node GDB/MI
27488@chapter The @sc{gdb/mi} Interface
27489
27490@unnumberedsec Function and Purpose
27491
27492@cindex @sc{gdb/mi}, its purpose
6b5e8c01
NR
27493@sc{gdb/mi} is a line based machine oriented text interface to
27494@value{GDBN} and is activated by specifying using the
27495@option{--interpreter} command line option (@pxref{Mode Options}). It
27496is specifically intended to support the development of systems which
27497use the debugger as just one small component of a larger system.
922fbb7b
AC
27498
27499This chapter is a specification of the @sc{gdb/mi} interface. It is written
27500in the form of a reference manual.
27501
27502Note that @sc{gdb/mi} is still under construction, so some of the
af6eff6f
NR
27503features described below are incomplete and subject to change
27504(@pxref{GDB/MI Development and Front Ends, , @sc{gdb/mi} Development and Front Ends}).
922fbb7b
AC
27505
27506@unnumberedsec Notation and Terminology
27507
27508@cindex notational conventions, for @sc{gdb/mi}
27509This chapter uses the following notation:
27510
27511@itemize @bullet
27512@item
27513@code{|} separates two alternatives.
27514
27515@item
27516@code{[ @var{something} ]} indicates that @var{something} is optional:
27517it may or may not be given.
27518
27519@item
27520@code{( @var{group} )*} means that @var{group} inside the parentheses
27521may repeat zero or more times.
27522
27523@item
27524@code{( @var{group} )+} means that @var{group} inside the parentheses
27525may repeat one or more times.
27526
27527@item
27528@code{"@var{string}"} means a literal @var{string}.
27529@end itemize
27530
27531@ignore
27532@heading Dependencies
27533@end ignore
27534
922fbb7b 27535@menu
c3b108f7 27536* GDB/MI General Design::
922fbb7b
AC
27537* GDB/MI Command Syntax::
27538* GDB/MI Compatibility with CLI::
af6eff6f 27539* GDB/MI Development and Front Ends::
922fbb7b 27540* GDB/MI Output Records::
ef21caaf 27541* GDB/MI Simple Examples::
922fbb7b 27542* GDB/MI Command Description Format::
ef21caaf 27543* GDB/MI Breakpoint Commands::
3fa7bf06 27544* GDB/MI Catchpoint Commands::
a2c02241
NR
27545* GDB/MI Program Context::
27546* GDB/MI Thread Commands::
5d77fe44 27547* GDB/MI Ada Tasking Commands::
a2c02241
NR
27548* GDB/MI Program Execution::
27549* GDB/MI Stack Manipulation::
27550* GDB/MI Variable Objects::
922fbb7b 27551* GDB/MI Data Manipulation::
a2c02241
NR
27552* GDB/MI Tracepoint Commands::
27553* GDB/MI Symbol Query::
351ff01a 27554* GDB/MI File Commands::
922fbb7b
AC
27555@ignore
27556* GDB/MI Kod Commands::
27557* GDB/MI Memory Overlay Commands::
27558* GDB/MI Signal Handling Commands::
27559@end ignore
922fbb7b 27560* GDB/MI Target Manipulation::
a6b151f1 27561* GDB/MI File Transfer Commands::
58d06528 27562* GDB/MI Ada Exceptions Commands::
d192b373 27563* GDB/MI Support Commands::
ef21caaf 27564* GDB/MI Miscellaneous Commands::
922fbb7b
AC
27565@end menu
27566
c3b108f7
VP
27567@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27568@node GDB/MI General Design
27569@section @sc{gdb/mi} General Design
27570@cindex GDB/MI General Design
27571
27572Interaction of a @sc{GDB/MI} frontend with @value{GDBN} involves three
27573parts---commands sent to @value{GDBN}, responses to those commands
27574and notifications. Each command results in exactly one response,
27575indicating either successful completion of the command, or an error.
27576For the commands that do not resume the target, the response contains the
27577requested information. For the commands that resume the target, the
27578response only indicates whether the target was successfully resumed.
27579Notifications is the mechanism for reporting changes in the state of the
27580target, or in @value{GDBN} state, that cannot conveniently be associated with
27581a command and reported as part of that command response.
27582
27583The important examples of notifications are:
27584@itemize @bullet
27585
27586@item
27587Exec notifications. These are used to report changes in
27588target state---when a target is resumed, or stopped. It would not
27589be feasible to include this information in response of resuming
27590commands, because one resume commands can result in multiple events in
27591different threads. Also, quite some time may pass before any event
27592happens in the target, while a frontend needs to know whether the resuming
27593command itself was successfully executed.
27594
27595@item
27596Console output, and status notifications. Console output
27597notifications are used to report output of CLI commands, as well as
27598diagnostics for other commands. Status notifications are used to
27599report the progress of a long-running operation. Naturally, including
27600this information in command response would mean no output is produced
27601until the command is finished, which is undesirable.
27602
27603@item
27604General notifications. Commands may have various side effects on
27605the @value{GDBN} or target state beyond their official purpose. For example,
27606a command may change the selected thread. Although such changes can
27607be included in command response, using notification allows for more
27608orthogonal frontend design.
27609
27610@end itemize
27611
27612There's no guarantee that whenever an MI command reports an error,
27613@value{GDBN} or the target are in any specific state, and especially,
27614the state is not reverted to the state before the MI command was
27615processed. Therefore, whenever an MI command results in an error,
27616we recommend that the frontend refreshes all the information shown in
27617the user interface.
27618
508094de
NR
27619
27620@menu
27621* Context management::
27622* Asynchronous and non-stop modes::
27623* Thread groups::
27624@end menu
27625
27626@node Context management
c3b108f7
VP
27627@subsection Context management
27628
403cb6b1
JB
27629@subsubsection Threads and Frames
27630
c3b108f7
VP
27631In most cases when @value{GDBN} accesses the target, this access is
27632done in context of a specific thread and frame (@pxref{Frames}).
27633Often, even when accessing global data, the target requires that a thread
27634be specified. The CLI interface maintains the selected thread and frame,
27635and supplies them to target on each command. This is convenient,
27636because a command line user would not want to specify that information
27637explicitly on each command, and because user interacts with
27638@value{GDBN} via a single terminal, so no confusion is possible as
27639to what thread and frame are the current ones.
27640
27641In the case of MI, the concept of selected thread and frame is less
27642useful. First, a frontend can easily remember this information
27643itself. Second, a graphical frontend can have more than one window,
27644each one used for debugging a different thread, and the frontend might
27645want to access additional threads for internal purposes. This
27646increases the risk that by relying on implicitly selected thread, the
27647frontend may be operating on a wrong one. Therefore, each MI command
27648should explicitly specify which thread and frame to operate on. To
27649make it possible, each MI command accepts the @samp{--thread} and
5d5658a1
PA
27650@samp{--frame} options, the value to each is @value{GDBN} global
27651identifier for thread and frame to operate on.
c3b108f7
VP
27652
27653Usually, each top-level window in a frontend allows the user to select
27654a thread and a frame, and remembers the user selection for further
27655operations. However, in some cases @value{GDBN} may suggest that the
4034d0ff
AT
27656current thread or frame be changed. For example, when stopping on a
27657breakpoint it is reasonable to switch to the thread where breakpoint is
27658hit. For another example, if the user issues the CLI @samp{thread} or
27659@samp{frame} commands via the frontend, it is desirable to change the
27660frontend's selection to the one specified by user. @value{GDBN}
27661communicates the suggestion to change current thread and frame using the
27662@samp{=thread-selected} notification.
c3b108f7
VP
27663
27664Note that historically, MI shares the selected thread with CLI, so
27665frontends used the @code{-thread-select} to execute commands in the
27666right context. However, getting this to work right is cumbersome. The
27667simplest way is for frontend to emit @code{-thread-select} command
27668before every command. This doubles the number of commands that need
27669to be sent. The alternative approach is to suppress @code{-thread-select}
27670if the selected thread in @value{GDBN} is supposed to be identical to the
27671thread the frontend wants to operate on. However, getting this
27672optimization right can be tricky. In particular, if the frontend
27673sends several commands to @value{GDBN}, and one of the commands changes the
27674selected thread, then the behaviour of subsequent commands will
27675change. So, a frontend should either wait for response from such
27676problematic commands, or explicitly add @code{-thread-select} for
27677all subsequent commands. No frontend is known to do this exactly
27678right, so it is suggested to just always pass the @samp{--thread} and
27679@samp{--frame} options.
27680
403cb6b1
JB
27681@subsubsection Language
27682
27683The execution of several commands depends on which language is selected.
27684By default, the current language (@pxref{show language}) is used.
27685But for commands known to be language-sensitive, it is recommended
27686to use the @samp{--language} option. This option takes one argument,
27687which is the name of the language to use while executing the command.
27688For instance:
27689
27690@smallexample
27691-data-evaluate-expression --language c "sizeof (void*)"
27692^done,value="4"
27693(gdb)
27694@end smallexample
27695
27696The valid language names are the same names accepted by the
27697@samp{set language} command (@pxref{Manually}), excluding @samp{auto},
27698@samp{local} or @samp{unknown}.
27699
508094de 27700@node Asynchronous and non-stop modes
c3b108f7
VP
27701@subsection Asynchronous command execution and non-stop mode
27702
27703On some targets, @value{GDBN} is capable of processing MI commands
27704even while the target is running. This is called @dfn{asynchronous
27705command execution} (@pxref{Background Execution}). The frontend may
27706specify a preferrence for asynchronous execution using the
329ea579 27707@code{-gdb-set mi-async 1} command, which should be emitted before
c3b108f7
VP
27708either running the executable or attaching to the target. After the
27709frontend has started the executable or attached to the target, it can
27710find if asynchronous execution is enabled using the
27711@code{-list-target-features} command.
27712
329ea579
PA
27713@table @code
27714@item -gdb-set mi-async on
27715@item -gdb-set mi-async off
27716Set whether MI is in asynchronous mode.
27717
27718When @code{off}, which is the default, MI execution commands (e.g.,
27719@code{-exec-continue}) are foreground commands, and @value{GDBN} waits
27720for the program to stop before processing further commands.
27721
27722When @code{on}, MI execution commands are background execution
27723commands (e.g., @code{-exec-continue} becomes the equivalent of the
27724@code{c&} CLI command), and so @value{GDBN} is capable of processing
27725MI commands even while the target is running.
27726
27727@item -gdb-show mi-async
27728Show whether MI asynchronous mode is enabled.
27729@end table
27730
27731Note: In @value{GDBN} version 7.7 and earlier, this option was called
27732@code{target-async} instead of @code{mi-async}, and it had the effect
27733of both putting MI in asynchronous mode and making CLI background
27734commands possible. CLI background commands are now always possible
27735``out of the box'' if the target supports them. The old spelling is
27736kept as a deprecated alias for backwards compatibility.
27737
c3b108f7
VP
27738Even if @value{GDBN} can accept a command while target is running,
27739many commands that access the target do not work when the target is
27740running. Therefore, asynchronous command execution is most useful
27741when combined with non-stop mode (@pxref{Non-Stop Mode}). Then,
27742it is possible to examine the state of one thread, while other threads
27743are running.
27744
27745When a given thread is running, MI commands that try to access the
27746target in the context of that thread may not work, or may work only on
27747some targets. In particular, commands that try to operate on thread's
27748stack will not work, on any target. Commands that read memory, or
27749modify breakpoints, may work or not work, depending on the target. Note
27750that even commands that operate on global state, such as @code{print},
27751@code{set}, and breakpoint commands, still access the target in the
27752context of a specific thread, so frontend should try to find a
27753stopped thread and perform the operation on that thread (using the
27754@samp{--thread} option).
27755
27756Which commands will work in the context of a running thread is
27757highly target dependent. However, the two commands
27758@code{-exec-interrupt}, to stop a thread, and @code{-thread-info},
27759to find the state of a thread, will always work.
27760
508094de 27761@node Thread groups
c3b108f7
VP
27762@subsection Thread groups
27763@value{GDBN} may be used to debug several processes at the same time.
27764On some platfroms, @value{GDBN} may support debugging of several
27765hardware systems, each one having several cores with several different
27766processes running on each core. This section describes the MI
27767mechanism to support such debugging scenarios.
27768
27769The key observation is that regardless of the structure of the
27770target, MI can have a global list of threads, because most commands that
27771accept the @samp{--thread} option do not need to know what process that
27772thread belongs to. Therefore, it is not necessary to introduce
27773neither additional @samp{--process} option, nor an notion of the
27774current process in the MI interface. The only strictly new feature
27775that is required is the ability to find how the threads are grouped
27776into processes.
27777
27778To allow the user to discover such grouping, and to support arbitrary
27779hierarchy of machines/cores/processes, MI introduces the concept of a
27780@dfn{thread group}. Thread group is a collection of threads and other
27781thread groups. A thread group always has a string identifier, a type,
27782and may have additional attributes specific to the type. A new
27783command, @code{-list-thread-groups}, returns the list of top-level
27784thread groups, which correspond to processes that @value{GDBN} is
27785debugging at the moment. By passing an identifier of a thread group
27786to the @code{-list-thread-groups} command, it is possible to obtain
27787the members of specific thread group.
27788
27789To allow the user to easily discover processes, and other objects, he
27790wishes to debug, a concept of @dfn{available thread group} is
27791introduced. Available thread group is an thread group that
27792@value{GDBN} is not debugging, but that can be attached to, using the
27793@code{-target-attach} command. The list of available top-level thread
27794groups can be obtained using @samp{-list-thread-groups --available}.
27795In general, the content of a thread group may be only retrieved only
27796after attaching to that thread group.
27797
a79b8f6e
VP
27798Thread groups are related to inferiors (@pxref{Inferiors and
27799Programs}). Each inferior corresponds to a thread group of a special
27800type @samp{process}, and some additional operations are permitted on
27801such thread groups.
27802
922fbb7b
AC
27803@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27804@node GDB/MI Command Syntax
27805@section @sc{gdb/mi} Command Syntax
27806
27807@menu
27808* GDB/MI Input Syntax::
27809* GDB/MI Output Syntax::
922fbb7b
AC
27810@end menu
27811
27812@node GDB/MI Input Syntax
27813@subsection @sc{gdb/mi} Input Syntax
27814
27815@cindex input syntax for @sc{gdb/mi}
27816@cindex @sc{gdb/mi}, input syntax
27817@table @code
27818@item @var{command} @expansion{}
27819@code{@var{cli-command} | @var{mi-command}}
27820
27821@item @var{cli-command} @expansion{}
27822@code{[ @var{token} ] @var{cli-command} @var{nl}}, where
27823@var{cli-command} is any existing @value{GDBN} CLI command.
27824
27825@item @var{mi-command} @expansion{}
27826@code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
27827@code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
27828
27829@item @var{token} @expansion{}
27830"any sequence of digits"
27831
27832@item @var{option} @expansion{}
27833@code{"-" @var{parameter} [ " " @var{parameter} ]}
27834
27835@item @var{parameter} @expansion{}
27836@code{@var{non-blank-sequence} | @var{c-string}}
27837
27838@item @var{operation} @expansion{}
27839@emph{any of the operations described in this chapter}
27840
27841@item @var{non-blank-sequence} @expansion{}
27842@emph{anything, provided it doesn't contain special characters such as
27843"-", @var{nl}, """ and of course " "}
27844
27845@item @var{c-string} @expansion{}
27846@code{""" @var{seven-bit-iso-c-string-content} """}
27847
27848@item @var{nl} @expansion{}
27849@code{CR | CR-LF}
27850@end table
27851
27852@noindent
27853Notes:
27854
27855@itemize @bullet
27856@item
27857The CLI commands are still handled by the @sc{mi} interpreter; their
27858output is described below.
27859
27860@item
27861The @code{@var{token}}, when present, is passed back when the command
27862finishes.
27863
27864@item
27865Some @sc{mi} commands accept optional arguments as part of the parameter
27866list. Each option is identified by a leading @samp{-} (dash) and may be
27867followed by an optional argument parameter. Options occur first in the
27868parameter list and can be delimited from normal parameters using
27869@samp{--} (this is useful when some parameters begin with a dash).
27870@end itemize
27871
27872Pragmatics:
27873
27874@itemize @bullet
27875@item
27876We want easy access to the existing CLI syntax (for debugging).
27877
27878@item
27879We want it to be easy to spot a @sc{mi} operation.
27880@end itemize
27881
27882@node GDB/MI Output Syntax
27883@subsection @sc{gdb/mi} Output Syntax
27884
27885@cindex output syntax of @sc{gdb/mi}
27886@cindex @sc{gdb/mi}, output syntax
27887The output from @sc{gdb/mi} consists of zero or more out-of-band records
27888followed, optionally, by a single result record. This result record
27889is for the most recent command. The sequence of output records is
594fe323 27890terminated by @samp{(gdb)}.
922fbb7b
AC
27891
27892If an input command was prefixed with a @code{@var{token}} then the
27893corresponding output for that command will also be prefixed by that same
27894@var{token}.
27895
27896@table @code
27897@item @var{output} @expansion{}
594fe323 27898@code{( @var{out-of-band-record} )* [ @var{result-record} ] "(gdb)" @var{nl}}
922fbb7b
AC
27899
27900@item @var{result-record} @expansion{}
27901@code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
27902
27903@item @var{out-of-band-record} @expansion{}
27904@code{@var{async-record} | @var{stream-record}}
27905
27906@item @var{async-record} @expansion{}
27907@code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
27908
27909@item @var{exec-async-output} @expansion{}
dcf106f3 27910@code{[ @var{token} ] "*" @var{async-output nl}}
922fbb7b
AC
27911
27912@item @var{status-async-output} @expansion{}
dcf106f3 27913@code{[ @var{token} ] "+" @var{async-output nl}}
922fbb7b
AC
27914
27915@item @var{notify-async-output} @expansion{}
dcf106f3 27916@code{[ @var{token} ] "=" @var{async-output nl}}
922fbb7b
AC
27917
27918@item @var{async-output} @expansion{}
dcf106f3 27919@code{@var{async-class} ( "," @var{result} )*}
922fbb7b
AC
27920
27921@item @var{result-class} @expansion{}
27922@code{"done" | "running" | "connected" | "error" | "exit"}
27923
27924@item @var{async-class} @expansion{}
27925@code{"stopped" | @var{others}} (where @var{others} will be added
27926depending on the needs---this is still in development).
27927
27928@item @var{result} @expansion{}
27929@code{ @var{variable} "=" @var{value}}
27930
27931@item @var{variable} @expansion{}
27932@code{ @var{string} }
27933
27934@item @var{value} @expansion{}
27935@code{ @var{const} | @var{tuple} | @var{list} }
27936
27937@item @var{const} @expansion{}
27938@code{@var{c-string}}
27939
27940@item @var{tuple} @expansion{}
27941@code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
27942
27943@item @var{list} @expansion{}
27944@code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
27945@var{result} ( "," @var{result} )* "]" }
27946
27947@item @var{stream-record} @expansion{}
27948@code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
27949
27950@item @var{console-stream-output} @expansion{}
dcf106f3 27951@code{"~" @var{c-string nl}}
922fbb7b
AC
27952
27953@item @var{target-stream-output} @expansion{}
dcf106f3 27954@code{"@@" @var{c-string nl}}
922fbb7b
AC
27955
27956@item @var{log-stream-output} @expansion{}
dcf106f3 27957@code{"&" @var{c-string nl}}
922fbb7b
AC
27958
27959@item @var{nl} @expansion{}
27960@code{CR | CR-LF}
27961
27962@item @var{token} @expansion{}
27963@emph{any sequence of digits}.
27964@end table
27965
27966@noindent
27967Notes:
27968
27969@itemize @bullet
27970@item
27971All output sequences end in a single line containing a period.
27972
27973@item
721c02de
VP
27974The @code{@var{token}} is from the corresponding request. Note that
27975for all async output, while the token is allowed by the grammar and
27976may be output by future versions of @value{GDBN} for select async
27977output messages, it is generally omitted. Frontends should treat
27978all async output as reporting general changes in the state of the
27979target and there should be no need to associate async output to any
27980prior command.
922fbb7b
AC
27981
27982@item
27983@cindex status output in @sc{gdb/mi}
27984@var{status-async-output} contains on-going status information about the
27985progress of a slow operation. It can be discarded. All status output is
27986prefixed by @samp{+}.
27987
27988@item
27989@cindex async output in @sc{gdb/mi}
27990@var{exec-async-output} contains asynchronous state change on the target
27991(stopped, started, disappeared). All async output is prefixed by
27992@samp{*}.
27993
27994@item
27995@cindex notify output in @sc{gdb/mi}
27996@var{notify-async-output} contains supplementary information that the
27997client should handle (e.g., a new breakpoint information). All notify
27998output is prefixed by @samp{=}.
27999
28000@item
28001@cindex console output in @sc{gdb/mi}
28002@var{console-stream-output} is output that should be displayed as is in the
28003console. It is the textual response to a CLI command. All the console
28004output is prefixed by @samp{~}.
28005
28006@item
28007@cindex target output in @sc{gdb/mi}
28008@var{target-stream-output} is the output produced by the target program.
28009All the target output is prefixed by @samp{@@}.
28010
28011@item
28012@cindex log output in @sc{gdb/mi}
28013@var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
28014instance messages that should be displayed as part of an error log. All
28015the log output is prefixed by @samp{&}.
28016
28017@item
28018@cindex list output in @sc{gdb/mi}
28019New @sc{gdb/mi} commands should only output @var{lists} containing
28020@var{values}.
28021
28022
28023@end itemize
28024
28025@xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
28026details about the various output records.
28027
922fbb7b
AC
28028@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28029@node GDB/MI Compatibility with CLI
28030@section @sc{gdb/mi} Compatibility with CLI
28031
28032@cindex compatibility, @sc{gdb/mi} and CLI
28033@cindex @sc{gdb/mi}, compatibility with CLI
922fbb7b 28034
a2c02241
NR
28035For the developers convenience CLI commands can be entered directly,
28036but there may be some unexpected behaviour. For example, commands
28037that query the user will behave as if the user replied yes, breakpoint
28038command lists are not executed and some CLI commands, such as
28039@code{if}, @code{when} and @code{define}, prompt for further input with
28040@samp{>}, which is not valid MI output.
ef21caaf
NR
28041
28042This feature may be removed at some stage in the future and it is
a2c02241
NR
28043recommended that front ends use the @code{-interpreter-exec} command
28044(@pxref{-interpreter-exec}).
922fbb7b 28045
af6eff6f
NR
28046@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28047@node GDB/MI Development and Front Ends
28048@section @sc{gdb/mi} Development and Front Ends
28049@cindex @sc{gdb/mi} development
28050
28051The application which takes the MI output and presents the state of the
28052program being debugged to the user is called a @dfn{front end}.
28053
1fea0d53
SM
28054Since @sc{gdb/mi} is used by a variety of front ends to @value{GDBN}, changes
28055to the MI interface may break existing usage. This section describes how the
28056protocol changes and how to request previous version of the protocol when it
28057does.
af6eff6f
NR
28058
28059Some changes in MI need not break a carefully designed front end, and
28060for these the MI version will remain unchanged. The following is a
28061list of changes that may occur within one level, so front ends should
28062parse MI output in a way that can handle them:
28063
28064@itemize @bullet
28065@item
28066New MI commands may be added.
28067
28068@item
28069New fields may be added to the output of any MI command.
28070
36ece8b3
NR
28071@item
28072The range of values for fields with specified values, e.g.,
9f708cb2 28073@code{in_scope} (@pxref{-var-update}) may be extended.
36ece8b3 28074
af6eff6f
NR
28075@c The format of field's content e.g type prefix, may change so parse it
28076@c at your own risk. Yes, in general?
28077
28078@c The order of fields may change? Shouldn't really matter but it might
28079@c resolve inconsistencies.
28080@end itemize
28081
28082If the changes are likely to break front ends, the MI version level
1fea0d53
SM
28083will be increased by one. The new versions of the MI protocol are not compatible
28084with the old versions. Old versions of MI remain available, allowing front ends
28085to keep using them until they are modified to use the latest MI version.
af6eff6f 28086
1fea0d53
SM
28087Since @code{--interpreter=mi} always points to the latest MI version, it is
28088recommended that front ends request a specific version of MI when launching
28089@value{GDBN} (e.g. @code{--interpreter=mi2}) to make sure they get an
28090interpreter with the MI version they expect.
28091
28092The following table gives a summary of the the released versions of the MI
28093interface: the version number, the version of GDB in which it first appeared
28094and the breaking changes compared to the previous version.
28095
28096@multitable @columnfractions .05 .05 .9
28097@headitem MI version @tab GDB version @tab Breaking changes
28098
28099@item
28100@center 1
28101@tab
28102@center 5.1
28103@tab
28104None
28105
28106@item
28107@center 2
28108@tab
28109@center 6.0
28110@tab
28111
28112@itemize
28113@item
28114The @code{-environment-pwd}, @code{-environment-directory} and
28115@code{-environment-path} commands now returns values using the MI output
28116syntax, rather than CLI output syntax.
28117
28118@item
28119@code{-var-list-children}'s @code{children} result field is now a list, rather
28120than a tuple.
28121
28122@item
28123@code{-var-update}'s @code{changelist} result field is now a list, rather than
28124a tuple.
28125@end itemize
28126
b4be1b06
SM
28127@item
28128@center 3
28129@tab
28130@center 9.1
28131@tab
28132
28133@itemize
28134@item
28135The output of information about multi-location breakpoints has changed in the
28136responses to the @code{-break-insert} and @code{-break-info} commands, as well
28137as in the @code{=breakpoint-created} and @code{=breakpoint-modified} events.
28138The multiple locations are now placed in a @code{locations} field, whose value
28139is a list.
28140@end itemize
28141
1fea0d53 28142@end multitable
af6eff6f 28143
b4be1b06
SM
28144If your front end cannot yet migrate to a more recent version of the
28145MI protocol, you can nevertheless selectively enable specific features
28146available in those recent MI versions, using the following commands:
28147
28148@table @code
28149
28150@item -fix-multi-location-breakpoint-output
28151Use the output for multi-location breakpoints which was introduced by
28152MI 3, even when using MI versions 2 or 1. This command has no
28153effect when using MI version 3 or later.
28154
5c85e20d 28155@end table
b4be1b06 28156
af6eff6f
NR
28157The best way to avoid unexpected changes in MI that might break your front
28158end is to make your project known to @value{GDBN} developers and
7a9a6b69 28159follow development on @email{gdb@@sourceware.org} and
fa0f268d 28160@email{gdb-patches@@sourceware.org}.
af6eff6f
NR
28161@cindex mailing lists
28162
922fbb7b
AC
28163@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28164@node GDB/MI Output Records
28165@section @sc{gdb/mi} Output Records
28166
28167@menu
28168* GDB/MI Result Records::
28169* GDB/MI Stream Records::
82f68b1c 28170* GDB/MI Async Records::
54516a0b 28171* GDB/MI Breakpoint Information::
c3b108f7 28172* GDB/MI Frame Information::
dc146f7c 28173* GDB/MI Thread Information::
4368ebeb 28174* GDB/MI Ada Exception Information::
922fbb7b
AC
28175@end menu
28176
28177@node GDB/MI Result Records
28178@subsection @sc{gdb/mi} Result Records
28179
28180@cindex result records in @sc{gdb/mi}
28181@cindex @sc{gdb/mi}, result records
28182In addition to a number of out-of-band notifications, the response to a
28183@sc{gdb/mi} command includes one of the following result indications:
28184
28185@table @code
28186@findex ^done
28187@item "^done" [ "," @var{results} ]
28188The synchronous operation was successful, @code{@var{results}} are the return
28189values.
28190
28191@item "^running"
28192@findex ^running
8e9c5e02
VP
28193This result record is equivalent to @samp{^done}. Historically, it
28194was output instead of @samp{^done} if the command has resumed the
28195target. This behaviour is maintained for backward compatibility, but
28196all frontends should treat @samp{^done} and @samp{^running}
28197identically and rely on the @samp{*running} output record to determine
28198which threads are resumed.
922fbb7b 28199
ef21caaf
NR
28200@item "^connected"
28201@findex ^connected
3f94c067 28202@value{GDBN} has connected to a remote target.
ef21caaf 28203
2ea126fa 28204@item "^error" "," "msg=" @var{c-string} [ "," "code=" @var{c-string} ]
922fbb7b 28205@findex ^error
2ea126fa
JB
28206The operation failed. The @code{msg=@var{c-string}} variable contains
28207the corresponding error message.
28208
28209If present, the @code{code=@var{c-string}} variable provides an error
28210code on which consumers can rely on to detect the corresponding
28211error condition. At present, only one error code is defined:
28212
28213@table @samp
28214@item "undefined-command"
28215Indicates that the command causing the error does not exist.
28216@end table
ef21caaf
NR
28217
28218@item "^exit"
28219@findex ^exit
3f94c067 28220@value{GDBN} has terminated.
ef21caaf 28221
922fbb7b
AC
28222@end table
28223
28224@node GDB/MI Stream Records
28225@subsection @sc{gdb/mi} Stream Records
28226
28227@cindex @sc{gdb/mi}, stream records
28228@cindex stream records in @sc{gdb/mi}
28229@value{GDBN} internally maintains a number of output streams: the console, the
28230target, and the log. The output intended for each of these streams is
28231funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
28232
28233Each stream record begins with a unique @dfn{prefix character} which
28234identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
28235Syntax}). In addition to the prefix, each stream record contains a
28236@code{@var{string-output}}. This is either raw text (with an implicit new
28237line) or a quoted C string (which does not contain an implicit newline).
28238
28239@table @code
28240@item "~" @var{string-output}
28241The console output stream contains text that should be displayed in the
28242CLI console window. It contains the textual responses to CLI commands.
28243
28244@item "@@" @var{string-output}
28245The target output stream contains any textual output from the running
ef21caaf
NR
28246target. This is only present when GDB's event loop is truly
28247asynchronous, which is currently only the case for remote targets.
922fbb7b
AC
28248
28249@item "&" @var{string-output}
28250The log stream contains debugging messages being produced by @value{GDBN}'s
28251internals.
28252@end table
28253
82f68b1c
VP
28254@node GDB/MI Async Records
28255@subsection @sc{gdb/mi} Async Records
922fbb7b 28256
82f68b1c
VP
28257@cindex async records in @sc{gdb/mi}
28258@cindex @sc{gdb/mi}, async records
28259@dfn{Async} records are used to notify the @sc{gdb/mi} client of
922fbb7b 28260additional changes that have occurred. Those changes can either be a
82f68b1c 28261consequence of @sc{gdb/mi} commands (e.g., a breakpoint modified) or a result of
922fbb7b
AC
28262target activity (e.g., target stopped).
28263
8eb41542 28264The following is the list of possible async records:
922fbb7b
AC
28265
28266@table @code
034dad6f 28267
e1ac3328 28268@item *running,thread-id="@var{thread}"
5d5658a1
PA
28269The target is now running. The @var{thread} field can be the global
28270thread ID of the the thread that is now running, and it can be
28271@samp{all} if all threads are running. The frontend should assume
28272that no interaction with a running thread is possible after this
28273notification is produced. The frontend should not assume that this
28274notification is output only once for any command. @value{GDBN} may
28275emit this notification several times, either for different threads,
28276because it cannot resume all threads together, or even for a single
28277thread, if the thread must be stepped though some code before letting
28278it run freely.
e1ac3328 28279
dc146f7c 28280@item *stopped,reason="@var{reason}",thread-id="@var{id}",stopped-threads="@var{stopped}",core="@var{core}"
82f68b1c
VP
28281The target has stopped. The @var{reason} field can have one of the
28282following values:
034dad6f
BR
28283
28284@table @code
28285@item breakpoint-hit
28286A breakpoint was reached.
28287@item watchpoint-trigger
28288A watchpoint was triggered.
28289@item read-watchpoint-trigger
28290A read watchpoint was triggered.
28291@item access-watchpoint-trigger
28292An access watchpoint was triggered.
28293@item function-finished
28294An -exec-finish or similar CLI command was accomplished.
28295@item location-reached
28296An -exec-until or similar CLI command was accomplished.
28297@item watchpoint-scope
28298A watchpoint has gone out of scope.
28299@item end-stepping-range
28300An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or
28301similar CLI command was accomplished.
28302@item exited-signalled
28303The inferior exited because of a signal.
28304@item exited
28305The inferior exited.
28306@item exited-normally
28307The inferior exited normally.
28308@item signal-received
28309A signal was received by the inferior.
36dfb11c
TT
28310@item solib-event
28311The inferior has stopped due to a library being loaded or unloaded.
edcc5120
TT
28312This can happen when @code{stop-on-solib-events} (@pxref{Files}) is
28313set or when a @code{catch load} or @code{catch unload} catchpoint is
28314in use (@pxref{Set Catchpoints}).
36dfb11c
TT
28315@item fork
28316The inferior has forked. This is reported when @code{catch fork}
28317(@pxref{Set Catchpoints}) has been used.
28318@item vfork
28319The inferior has vforked. This is reported in when @code{catch vfork}
28320(@pxref{Set Catchpoints}) has been used.
28321@item syscall-entry
28322The inferior entered a system call. This is reported when @code{catch
28323syscall} (@pxref{Set Catchpoints}) has been used.
a64c9f7b 28324@item syscall-return
36dfb11c
TT
28325The inferior returned from a system call. This is reported when
28326@code{catch syscall} (@pxref{Set Catchpoints}) has been used.
28327@item exec
28328The inferior called @code{exec}. This is reported when @code{catch exec}
28329(@pxref{Set Catchpoints}) has been used.
922fbb7b
AC
28330@end table
28331
5d5658a1
PA
28332The @var{id} field identifies the global thread ID of the thread
28333that directly caused the stop -- for example by hitting a breakpoint.
28334Depending on whether all-stop
c3b108f7
VP
28335mode is in effect (@pxref{All-Stop Mode}), @value{GDBN} may either
28336stop all threads, or only the thread that directly triggered the stop.
28337If all threads are stopped, the @var{stopped} field will have the
28338value of @code{"all"}. Otherwise, the value of the @var{stopped}
28339field will be a list of thread identifiers. Presently, this list will
28340always include a single thread, but frontend should be prepared to see
dc146f7c
VP
28341several threads in the list. The @var{core} field reports the
28342processor core on which the stop event has happened. This field may be absent
28343if such information is not available.
c3b108f7 28344
a79b8f6e
VP
28345@item =thread-group-added,id="@var{id}"
28346@itemx =thread-group-removed,id="@var{id}"
28347A thread group was either added or removed. The @var{id} field
28348contains the @value{GDBN} identifier of the thread group. When a thread
28349group is added, it generally might not be associated with a running
28350process. When a thread group is removed, its id becomes invalid and
28351cannot be used in any way.
28352
28353@item =thread-group-started,id="@var{id}",pid="@var{pid}"
28354A thread group became associated with a running program,
28355either because the program was just started or the thread group
28356was attached to a program. The @var{id} field contains the
28357@value{GDBN} identifier of the thread group. The @var{pid} field
28358contains process identifier, specific to the operating system.
28359
8cf64490 28360@item =thread-group-exited,id="@var{id}"[,exit-code="@var{code}"]
a79b8f6e
VP
28361A thread group is no longer associated with a running program,
28362either because the program has exited, or because it was detached
c3b108f7 28363from. The @var{id} field contains the @value{GDBN} identifier of the
697aa1b7 28364thread group. The @var{code} field is the exit code of the inferior; it exists
8cf64490 28365only when the inferior exited with some code.
c3b108f7
VP
28366
28367@item =thread-created,id="@var{id}",group-id="@var{gid}"
28368@itemx =thread-exited,id="@var{id}",group-id="@var{gid}"
82f68b1c 28369A thread either was created, or has exited. The @var{id} field
5d5658a1 28370contains the global @value{GDBN} identifier of the thread. The @var{gid}
c3b108f7 28371field identifies the thread group this thread belongs to.
66bb093b 28372
4034d0ff
AT
28373@item =thread-selected,id="@var{id}"[,frame="@var{frame}"]
28374Informs that the selected thread or frame were changed. This notification
28375is not emitted as result of the @code{-thread-select} or
28376@code{-stack-select-frame} commands, but is emitted whenever an MI command
28377that is not documented to change the selected thread and frame actually
28378changes them. In particular, invoking, directly or indirectly
28379(via user-defined command), the CLI @code{thread} or @code{frame} commands,
28380will generate this notification. Changing the thread or frame from another
28381user interface (see @ref{Interpreters}) will also generate this notification.
28382
28383The @var{frame} field is only present if the newly selected thread is
28384stopped. See @ref{GDB/MI Frame Information} for the format of its value.
66bb093b
VP
28385
28386We suggest that in response to this notification, front ends
28387highlight the selected thread and cause subsequent commands to apply to
28388that thread.
28389
c86cf029
VP
28390@item =library-loaded,...
28391Reports that a new library file was loaded by the program. This
51457a05
MAL
28392notification has 5 fields---@var{id}, @var{target-name},
28393@var{host-name}, @var{symbols-loaded} and @var{ranges}. The @var{id} field is an
c86cf029
VP
28394opaque identifier of the library. For remote debugging case,
28395@var{target-name} and @var{host-name} fields give the name of the
134eb42c
VP
28396library file on the target, and on the host respectively. For native
28397debugging, both those fields have the same value. The
f1cbe1d3
TT
28398@var{symbols-loaded} field is emitted only for backward compatibility
28399and should not be relied on to convey any useful information. The
28400@var{thread-group} field, if present, specifies the id of the thread
28401group in whose context the library was loaded. If the field is
28402absent, it means the library was loaded in the context of all present
51457a05
MAL
28403thread groups. The @var{ranges} field specifies the ranges of addresses belonging
28404to this library.
c86cf029
VP
28405
28406@item =library-unloaded,...
134eb42c 28407Reports that a library was unloaded by the program. This notification
c86cf029 28408has 3 fields---@var{id}, @var{target-name} and @var{host-name} with
a79b8f6e
VP
28409the same meaning as for the @code{=library-loaded} notification.
28410The @var{thread-group} field, if present, specifies the id of the
28411thread group in whose context the library was unloaded. If the field is
28412absent, it means the library was unloaded in the context of all present
28413thread groups.
c86cf029 28414
201b4506
YQ
28415@item =traceframe-changed,num=@var{tfnum},tracepoint=@var{tpnum}
28416@itemx =traceframe-changed,end
28417Reports that the trace frame was changed and its new number is
28418@var{tfnum}. The number of the tracepoint associated with this trace
28419frame is @var{tpnum}.
28420
134a2066 28421@item =tsv-created,name=@var{name},initial=@var{initial}
bb25a15c 28422Reports that the new trace state variable @var{name} is created with
134a2066 28423initial value @var{initial}.
bb25a15c
YQ
28424
28425@item =tsv-deleted,name=@var{name}
28426@itemx =tsv-deleted
28427Reports that the trace state variable @var{name} is deleted or all
28428trace state variables are deleted.
28429
134a2066
YQ
28430@item =tsv-modified,name=@var{name},initial=@var{initial}[,current=@var{current}]
28431Reports that the trace state variable @var{name} is modified with
28432the initial value @var{initial}. The current value @var{current} of
28433trace state variable is optional and is reported if the current
28434value of trace state variable is known.
28435
8d3788bd
VP
28436@item =breakpoint-created,bkpt=@{...@}
28437@itemx =breakpoint-modified,bkpt=@{...@}
d9f08f52 28438@itemx =breakpoint-deleted,id=@var{number}
8d3788bd
VP
28439Reports that a breakpoint was created, modified, or deleted,
28440respectively. Only user-visible breakpoints are reported to the MI
28441user.
28442
28443The @var{bkpt} argument is of the same form as returned by the various
d9f08f52
YQ
28444breakpoint commands; @xref{GDB/MI Breakpoint Commands}. The
28445@var{number} is the ordinal number of the breakpoint.
8d3788bd
VP
28446
28447Note that if a breakpoint is emitted in the result record of a
28448command, then it will not also be emitted in an async record.
28449
38b022b4 28450@item =record-started,thread-group="@var{id}",method="@var{method}"[,format="@var{format}"]
82a90ccf
YQ
28451@itemx =record-stopped,thread-group="@var{id}"
28452Execution log recording was either started or stopped on an
28453inferior. The @var{id} is the @value{GDBN} identifier of the thread
28454group corresponding to the affected inferior.
28455
38b022b4
SM
28456The @var{method} field indicates the method used to record execution. If the
28457method in use supports multiple recording formats, @var{format} will be present
8504e097 28458and contain the currently used format. @xref{Process Record and Replay},
38b022b4
SM
28459for existing method and format values.
28460
5b9afe8a
YQ
28461@item =cmd-param-changed,param=@var{param},value=@var{value}
28462Reports that a parameter of the command @code{set @var{param}} is
28463changed to @var{value}. In the multi-word @code{set} command,
28464the @var{param} is the whole parameter list to @code{set} command.
28465For example, In command @code{set check type on}, @var{param}
28466is @code{check type} and @var{value} is @code{on}.
8de0566d
YQ
28467
28468@item =memory-changed,thread-group=@var{id},addr=@var{addr},len=@var{len}[,type="code"]
28469Reports that bytes from @var{addr} to @var{data} + @var{len} were
28470written in an inferior. The @var{id} is the identifier of the
28471thread group corresponding to the affected inferior. The optional
28472@code{type="code"} part is reported if the memory written to holds
28473executable code.
82f68b1c
VP
28474@end table
28475
54516a0b
TT
28476@node GDB/MI Breakpoint Information
28477@subsection @sc{gdb/mi} Breakpoint Information
28478
28479When @value{GDBN} reports information about a breakpoint, a
28480tracepoint, a watchpoint, or a catchpoint, it uses a tuple with the
28481following fields:
28482
28483@table @code
28484@item number
b4be1b06 28485The breakpoint number.
54516a0b
TT
28486
28487@item type
28488The type of the breakpoint. For ordinary breakpoints this will be
28489@samp{breakpoint}, but many values are possible.
28490
8ac3646f
TT
28491@item catch-type
28492If the type of the breakpoint is @samp{catchpoint}, then this
28493indicates the exact type of catchpoint.
28494
54516a0b
TT
28495@item disp
28496This is the breakpoint disposition---either @samp{del}, meaning that
28497the breakpoint will be deleted at the next stop, or @samp{keep},
28498meaning that the breakpoint will not be deleted.
28499
28500@item enabled
28501This indicates whether the breakpoint is enabled, in which case the
28502value is @samp{y}, or disabled, in which case the value is @samp{n}.
28503Note that this is not the same as the field @code{enable}.
28504
28505@item addr
28506The address of the breakpoint. This may be a hexidecimal number,
28507giving the address; or the string @samp{<PENDING>}, for a pending
28508breakpoint; or the string @samp{<MULTIPLE>}, for a breakpoint with
28509multiple locations. This field will not be present if no address can
28510be determined. For example, a watchpoint does not have an address.
28511
28512@item func
28513If known, the function in which the breakpoint appears.
28514If not known, this field is not present.
28515
28516@item filename
28517The name of the source file which contains this function, if known.
28518If not known, this field is not present.
28519
28520@item fullname
28521The full file name of the source file which contains this function, if
28522known. If not known, this field is not present.
28523
28524@item line
28525The line number at which this breakpoint appears, if known.
28526If not known, this field is not present.
28527
28528@item at
28529If the source file is not known, this field may be provided. If
28530provided, this holds the address of the breakpoint, possibly followed
28531by a symbol name.
28532
28533@item pending
28534If this breakpoint is pending, this field is present and holds the
28535text used to set the breakpoint, as entered by the user.
28536
28537@item evaluated-by
28538Where this breakpoint's condition is evaluated, either @samp{host} or
28539@samp{target}.
28540
28541@item thread
28542If this is a thread-specific breakpoint, then this identifies the
28543thread in which the breakpoint can trigger.
28544
28545@item task
28546If this breakpoint is restricted to a particular Ada task, then this
28547field will hold the task identifier.
28548
28549@item cond
28550If the breakpoint is conditional, this is the condition expression.
28551
28552@item ignore
28553The ignore count of the breakpoint.
28554
28555@item enable
28556The enable count of the breakpoint.
28557
28558@item traceframe-usage
28559FIXME.
28560
28561@item static-tracepoint-marker-string-id
28562For a static tracepoint, the name of the static tracepoint marker.
28563
28564@item mask
28565For a masked watchpoint, this is the mask.
28566
28567@item pass
28568A tracepoint's pass count.
28569
28570@item original-location
28571The location of the breakpoint as originally specified by the user.
28572This field is optional.
28573
28574@item times
28575The number of times the breakpoint has been hit.
28576
28577@item installed
28578This field is only given for tracepoints. This is either @samp{y},
28579meaning that the tracepoint is installed, or @samp{n}, meaning that it
28580is not.
28581
28582@item what
28583Some extra data, the exact contents of which are type-dependent.
28584
b4be1b06
SM
28585@item locations
28586This field is present if the breakpoint has multiple locations. It is also
28587exceptionally present if the breakpoint is enabled and has a single, disabled
28588location.
28589
28590The value is a list of locations. The format of a location is decribed below.
28591
28592@end table
28593
28594A location in a multi-location breakpoint is represented as a tuple with the
28595following fields:
28596
28597@table @code
28598
28599@item number
28600The location number as a dotted pair, like @samp{1.2}. The first digit is the
28601number of the parent breakpoint. The second digit is the number of the
28602location within that breakpoint.
28603
28604@item enabled
28605This indicates whether the location is enabled, in which case the
28606value is @samp{y}, or disabled, in which case the value is @samp{n}.
28607Note that this is not the same as the field @code{enable}.
28608
28609@item addr
28610The address of this location as an hexidecimal number.
28611
28612@item func
28613If known, the function in which the location appears.
28614If not known, this field is not present.
28615
28616@item file
28617The name of the source file which contains this location, if known.
28618If not known, this field is not present.
28619
28620@item fullname
28621The full file name of the source file which contains this location, if
28622known. If not known, this field is not present.
28623
28624@item line
28625The line number at which this location appears, if known.
28626If not known, this field is not present.
28627
28628@item thread-groups
28629The thread groups this location is in.
28630
54516a0b
TT
28631@end table
28632
28633For example, here is what the output of @code{-break-insert}
28634(@pxref{GDB/MI Breakpoint Commands}) might be:
28635
28636@smallexample
28637-> -break-insert main
28638<- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
28639 enabled="y",addr="0x08048564",func="main",file="myprog.c",
998580f1
MK
28640 fullname="/home/nickrob/myprog.c",line="68",thread-groups=["i1"],
28641 times="0"@}
54516a0b
TT
28642<- (gdb)
28643@end smallexample
28644
c3b108f7
VP
28645@node GDB/MI Frame Information
28646@subsection @sc{gdb/mi} Frame Information
28647
28648Response from many MI commands includes an information about stack
28649frame. This information is a tuple that may have the following
28650fields:
28651
28652@table @code
28653@item level
28654The level of the stack frame. The innermost frame has the level of
28655zero. This field is always present.
28656
28657@item func
28658The name of the function corresponding to the frame. This field may
28659be absent if @value{GDBN} is unable to determine the function name.
28660
28661@item addr
28662The code address for the frame. This field is always present.
28663
28664@item file
28665The name of the source files that correspond to the frame's code
28666address. This field may be absent.
28667
28668@item line
28669The source line corresponding to the frames' code address. This field
28670may be absent.
28671
28672@item from
28673The name of the binary file (either executable or shared library) the
28674corresponds to the frame's code address. This field may be absent.
28675
28676@end table
82f68b1c 28677
dc146f7c
VP
28678@node GDB/MI Thread Information
28679@subsection @sc{gdb/mi} Thread Information
28680
28681Whenever @value{GDBN} has to report an information about a thread, it
ebe553db
SM
28682uses a tuple with the following fields. The fields are always present unless
28683stated otherwise.
dc146f7c
VP
28684
28685@table @code
28686@item id
ebe553db 28687The global numeric id assigned to the thread by @value{GDBN}.
dc146f7c
VP
28688
28689@item target-id
ebe553db 28690The target-specific string identifying the thread.
dc146f7c
VP
28691
28692@item details
28693Additional information about the thread provided by the target.
28694It is supposed to be human-readable and not interpreted by the
28695frontend. This field is optional.
28696
ebe553db
SM
28697@item name
28698The name of the thread. If the user specified a name using the
28699@code{thread name} command, then this name is given. Otherwise, if
28700@value{GDBN} can extract the thread name from the target, then that
28701name is given. If @value{GDBN} cannot find the thread name, then this
28702field is omitted.
28703
dc146f7c 28704@item state
ebe553db
SM
28705The execution state of the thread, either @samp{stopped} or @samp{running},
28706depending on whether the thread is presently running.
28707
28708@item frame
28709The stack frame currently executing in the thread. This field is only present
28710if the thread is stopped. Its format is documented in
28711@ref{GDB/MI Frame Information}.
dc146f7c
VP
28712
28713@item core
28714The value of this field is an integer number of the processor core the
28715thread was last seen on. This field is optional.
28716@end table
28717
956a9fb9
JB
28718@node GDB/MI Ada Exception Information
28719@subsection @sc{gdb/mi} Ada Exception Information
28720
28721Whenever a @code{*stopped} record is emitted because the program
28722stopped after hitting an exception catchpoint (@pxref{Set Catchpoints}),
28723@value{GDBN} provides the name of the exception that was raised via
e547c119
JB
28724the @code{exception-name} field. Also, for exceptions that were raised
28725with an exception message, @value{GDBN} provides that message via
28726the @code{exception-message} field.
922fbb7b 28727
ef21caaf
NR
28728@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28729@node GDB/MI Simple Examples
28730@section Simple Examples of @sc{gdb/mi} Interaction
28731@cindex @sc{gdb/mi}, simple examples
28732
28733This subsection presents several simple examples of interaction using
28734the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
28735following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
28736the output received from @sc{gdb/mi}.
28737
d3e8051b 28738Note the line breaks shown in the examples are here only for
ef21caaf
NR
28739readability, they don't appear in the real output.
28740
79a6e687 28741@subheading Setting a Breakpoint
ef21caaf
NR
28742
28743Setting a breakpoint generates synchronous output which contains detailed
28744information of the breakpoint.
28745
28746@smallexample
28747-> -break-insert main
28748<- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
28749 enabled="y",addr="0x08048564",func="main",file="myprog.c",
998580f1
MK
28750 fullname="/home/nickrob/myprog.c",line="68",thread-groups=["i1"],
28751 times="0"@}
ef21caaf
NR
28752<- (gdb)
28753@end smallexample
28754
28755@subheading Program Execution
28756
28757Program execution generates asynchronous records and MI gives the
28758reason that execution stopped.
28759
28760@smallexample
28761-> -exec-run
28762<- ^running
28763<- (gdb)
a47ec5fe 28764<- *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
ef21caaf
NR
28765 frame=@{addr="0x08048564",func="main",
28766 args=[@{name="argc",value="1"@},@{name="argv",value="0xbfc4d4d4"@}],
6d52907e
JV
28767 file="myprog.c",fullname="/home/nickrob/myprog.c",line="68",
28768 arch="i386:x86_64"@}
ef21caaf
NR
28769<- (gdb)
28770-> -exec-continue
28771<- ^running
28772<- (gdb)
28773<- *stopped,reason="exited-normally"
28774<- (gdb)
28775@end smallexample
28776
3f94c067 28777@subheading Quitting @value{GDBN}
ef21caaf 28778
3f94c067 28779Quitting @value{GDBN} just prints the result class @samp{^exit}.
ef21caaf
NR
28780
28781@smallexample
28782-> (gdb)
28783<- -gdb-exit
28784<- ^exit
28785@end smallexample
28786
a6b29f87
VP
28787Please note that @samp{^exit} is printed immediately, but it might
28788take some time for @value{GDBN} to actually exit. During that time, @value{GDBN}
28789performs necessary cleanups, including killing programs being debugged
28790or disconnecting from debug hardware, so the frontend should wait till
28791@value{GDBN} exits and should only forcibly kill @value{GDBN} if it
28792fails to exit in reasonable time.
28793
a2c02241 28794@subheading A Bad Command
ef21caaf
NR
28795
28796Here's what happens if you pass a non-existent command:
28797
28798@smallexample
28799-> -rubbish
28800<- ^error,msg="Undefined MI command: rubbish"
594fe323 28801<- (gdb)
ef21caaf
NR
28802@end smallexample
28803
28804
922fbb7b
AC
28805@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28806@node GDB/MI Command Description Format
28807@section @sc{gdb/mi} Command Description Format
28808
28809The remaining sections describe blocks of commands. Each block of
28810commands is laid out in a fashion similar to this section.
28811
922fbb7b
AC
28812@subheading Motivation
28813
28814The motivation for this collection of commands.
28815
28816@subheading Introduction
28817
28818A brief introduction to this collection of commands as a whole.
28819
28820@subheading Commands
28821
28822For each command in the block, the following is described:
28823
28824@subsubheading Synopsis
28825
28826@smallexample
28827 -command @var{args}@dots{}
28828@end smallexample
28829
922fbb7b
AC
28830@subsubheading Result
28831
265eeb58 28832@subsubheading @value{GDBN} Command
922fbb7b 28833
265eeb58 28834The corresponding @value{GDBN} CLI command(s), if any.
922fbb7b
AC
28835
28836@subsubheading Example
28837
ef21caaf
NR
28838Example(s) formatted for readability. Some of the described commands have
28839not been implemented yet and these are labeled N.A.@: (not available).
28840
28841
922fbb7b 28842@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ef21caaf
NR
28843@node GDB/MI Breakpoint Commands
28844@section @sc{gdb/mi} Breakpoint Commands
922fbb7b
AC
28845
28846@cindex breakpoint commands for @sc{gdb/mi}
28847@cindex @sc{gdb/mi}, breakpoint commands
28848This section documents @sc{gdb/mi} commands for manipulating
28849breakpoints.
28850
28851@subheading The @code{-break-after} Command
28852@findex -break-after
28853
28854@subsubheading Synopsis
28855
28856@smallexample
28857 -break-after @var{number} @var{count}
28858@end smallexample
28859
28860The breakpoint number @var{number} is not in effect until it has been
28861hit @var{count} times. To see how this is reflected in the output of
28862the @samp{-break-list} command, see the description of the
28863@samp{-break-list} command below.
28864
28865@subsubheading @value{GDBN} Command
28866
28867The corresponding @value{GDBN} command is @samp{ignore}.
28868
28869@subsubheading Example
28870
28871@smallexample
594fe323 28872(gdb)
922fbb7b 28873-break-insert main
a47ec5fe
AR
28874^done,bkpt=@{number="1",type="breakpoint",disp="keep",
28875enabled="y",addr="0x000100d0",func="main",file="hello.c",
998580f1
MK
28876fullname="/home/foo/hello.c",line="5",thread-groups=["i1"],
28877times="0"@}
594fe323 28878(gdb)
922fbb7b
AC
28879-break-after 1 3
28880~
28881^done
594fe323 28882(gdb)
922fbb7b
AC
28883-break-list
28884^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
28885hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
28886@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
28887@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
28888@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
28889@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
28890@{width="40",alignment="2",col_name="what",colhdr="What"@}],
28891body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102 28892addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
998580f1 28893line="5",thread-groups=["i1"],times="0",ignore="3"@}]@}
594fe323 28894(gdb)
922fbb7b
AC
28895@end smallexample
28896
28897@ignore
28898@subheading The @code{-break-catch} Command
28899@findex -break-catch
48cb2d85 28900@end ignore
922fbb7b
AC
28901
28902@subheading The @code{-break-commands} Command
28903@findex -break-commands
922fbb7b 28904
48cb2d85
VP
28905@subsubheading Synopsis
28906
28907@smallexample
28908 -break-commands @var{number} [ @var{command1} ... @var{commandN} ]
28909@end smallexample
28910
28911Specifies the CLI commands that should be executed when breakpoint
28912@var{number} is hit. The parameters @var{command1} to @var{commandN}
28913are the commands. If no command is specified, any previously-set
28914commands are cleared. @xref{Break Commands}. Typical use of this
28915functionality is tracing a program, that is, printing of values of
28916some variables whenever breakpoint is hit and then continuing.
28917
28918@subsubheading @value{GDBN} Command
28919
28920The corresponding @value{GDBN} command is @samp{commands}.
28921
28922@subsubheading Example
28923
28924@smallexample
28925(gdb)
28926-break-insert main
28927^done,bkpt=@{number="1",type="breakpoint",disp="keep",
28928enabled="y",addr="0x000100d0",func="main",file="hello.c",
998580f1
MK
28929fullname="/home/foo/hello.c",line="5",thread-groups=["i1"],
28930times="0"@}
48cb2d85
VP
28931(gdb)
28932-break-commands 1 "print v" "continue"
28933^done
28934(gdb)
28935@end smallexample
922fbb7b
AC
28936
28937@subheading The @code{-break-condition} Command
28938@findex -break-condition
28939
28940@subsubheading Synopsis
28941
28942@smallexample
28943 -break-condition @var{number} @var{expr}
28944@end smallexample
28945
28946Breakpoint @var{number} will stop the program only if the condition in
28947@var{expr} is true. The condition becomes part of the
28948@samp{-break-list} output (see the description of the @samp{-break-list}
28949command below).
28950
28951@subsubheading @value{GDBN} Command
28952
28953The corresponding @value{GDBN} command is @samp{condition}.
28954
28955@subsubheading Example
28956
28957@smallexample
594fe323 28958(gdb)
922fbb7b
AC
28959-break-condition 1 1
28960^done
594fe323 28961(gdb)
922fbb7b
AC
28962-break-list
28963^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
28964hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
28965@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
28966@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
28967@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
28968@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
28969@{width="40",alignment="2",col_name="what",colhdr="What"@}],
28970body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102 28971addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
998580f1 28972line="5",cond="1",thread-groups=["i1"],times="0",ignore="3"@}]@}
594fe323 28973(gdb)
922fbb7b
AC
28974@end smallexample
28975
28976@subheading The @code{-break-delete} Command
28977@findex -break-delete
28978
28979@subsubheading Synopsis
28980
28981@smallexample
28982 -break-delete ( @var{breakpoint} )+
28983@end smallexample
28984
28985Delete the breakpoint(s) whose number(s) are specified in the argument
28986list. This is obviously reflected in the breakpoint list.
28987
79a6e687 28988@subsubheading @value{GDBN} Command
922fbb7b
AC
28989
28990The corresponding @value{GDBN} command is @samp{delete}.
28991
28992@subsubheading Example
28993
28994@smallexample
594fe323 28995(gdb)
922fbb7b
AC
28996-break-delete 1
28997^done
594fe323 28998(gdb)
922fbb7b
AC
28999-break-list
29000^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
29001hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
29002@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
29003@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
29004@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
29005@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
29006@{width="40",alignment="2",col_name="what",colhdr="What"@}],
29007body=[]@}
594fe323 29008(gdb)
922fbb7b
AC
29009@end smallexample
29010
29011@subheading The @code{-break-disable} Command
29012@findex -break-disable
29013
29014@subsubheading Synopsis
29015
29016@smallexample
29017 -break-disable ( @var{breakpoint} )+
29018@end smallexample
29019
29020Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
29021break list is now set to @samp{n} for the named @var{breakpoint}(s).
29022
29023@subsubheading @value{GDBN} Command
29024
29025The corresponding @value{GDBN} command is @samp{disable}.
29026
29027@subsubheading Example
29028
29029@smallexample
594fe323 29030(gdb)
922fbb7b
AC
29031-break-disable 2
29032^done
594fe323 29033(gdb)
922fbb7b
AC
29034-break-list
29035^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
29036hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
29037@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
29038@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
29039@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
29040@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
29041@{width="40",alignment="2",col_name="what",colhdr="What"@}],
29042body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
948d5102 29043addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
998580f1 29044line="5",thread-groups=["i1"],times="0"@}]@}
594fe323 29045(gdb)
922fbb7b
AC
29046@end smallexample
29047
29048@subheading The @code{-break-enable} Command
29049@findex -break-enable
29050
29051@subsubheading Synopsis
29052
29053@smallexample
29054 -break-enable ( @var{breakpoint} )+
29055@end smallexample
29056
29057Enable (previously disabled) @var{breakpoint}(s).
29058
29059@subsubheading @value{GDBN} Command
29060
29061The corresponding @value{GDBN} command is @samp{enable}.
29062
29063@subsubheading Example
29064
29065@smallexample
594fe323 29066(gdb)
922fbb7b
AC
29067-break-enable 2
29068^done
594fe323 29069(gdb)
922fbb7b
AC
29070-break-list
29071^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
29072hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
29073@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
29074@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
29075@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
29076@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
29077@{width="40",alignment="2",col_name="what",colhdr="What"@}],
29078body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
948d5102 29079addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
998580f1 29080line="5",thread-groups=["i1"],times="0"@}]@}
594fe323 29081(gdb)
922fbb7b
AC
29082@end smallexample
29083
29084@subheading The @code{-break-info} Command
29085@findex -break-info
29086
29087@subsubheading Synopsis
29088
29089@smallexample
29090 -break-info @var{breakpoint}
29091@end smallexample
29092
29093@c REDUNDANT???
29094Get information about a single breakpoint.
29095
54516a0b
TT
29096The result is a table of breakpoints. @xref{GDB/MI Breakpoint
29097Information}, for details on the format of each breakpoint in the
29098table.
29099
79a6e687 29100@subsubheading @value{GDBN} Command
922fbb7b
AC
29101
29102The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
29103
29104@subsubheading Example
29105N.A.
29106
29107@subheading The @code{-break-insert} Command
29108@findex -break-insert
629500fa 29109@anchor{-break-insert}
922fbb7b
AC
29110
29111@subsubheading Synopsis
29112
29113@smallexample
18148017 29114 -break-insert [ -t ] [ -h ] [ -f ] [ -d ] [ -a ]
922fbb7b 29115 [ -c @var{condition} ] [ -i @var{ignore-count} ]
472a2379 29116 [ -p @var{thread-id} ] [ @var{location} ]
922fbb7b
AC
29117@end smallexample
29118
29119@noindent
afe8ab22 29120If specified, @var{location}, can be one of:
922fbb7b 29121
629500fa
KS
29122@table @var
29123@item linespec location
29124A linespec location. @xref{Linespec Locations}.
29125
29126@item explicit location
29127An explicit location. @sc{gdb/mi} explicit locations are
29128analogous to the CLI's explicit locations using the option names
29129listed below. @xref{Explicit Locations}.
29130
29131@table @samp
29132@item --source @var{filename}
29133The source file name of the location. This option requires the use
29134of either @samp{--function} or @samp{--line}.
29135
29136@item --function @var{function}
29137The name of a function or method.
922fbb7b 29138
629500fa
KS
29139@item --label @var{label}
29140The name of a label.
29141
29142@item --line @var{lineoffset}
29143An absolute or relative line offset from the start of the location.
29144@end table
29145
29146@item address location
29147An address location, *@var{address}. @xref{Address Locations}.
29148@end table
29149
29150@noindent
922fbb7b
AC
29151The possible optional parameters of this command are:
29152
29153@table @samp
29154@item -t
948d5102 29155Insert a temporary breakpoint.
922fbb7b
AC
29156@item -h
29157Insert a hardware breakpoint.
afe8ab22
VP
29158@item -f
29159If @var{location} cannot be parsed (for example if it
29160refers to unknown files or functions), create a pending
29161breakpoint. Without this flag, @value{GDBN} will report
29162an error, and won't create a breakpoint, if @var{location}
29163cannot be parsed.
41447f92
VP
29164@item -d
29165Create a disabled breakpoint.
18148017
VP
29166@item -a
29167Create a tracepoint. @xref{Tracepoints}. When this parameter
29168is used together with @samp{-h}, a fast tracepoint is created.
472a2379
KS
29169@item -c @var{condition}
29170Make the breakpoint conditional on @var{condition}.
29171@item -i @var{ignore-count}
29172Initialize the @var{ignore-count}.
29173@item -p @var{thread-id}
5d5658a1
PA
29174Restrict the breakpoint to the thread with the specified global
29175@var{thread-id}.
922fbb7b
AC
29176@end table
29177
29178@subsubheading Result
29179
54516a0b
TT
29180@xref{GDB/MI Breakpoint Information}, for details on the format of the
29181resulting breakpoint.
922fbb7b
AC
29182
29183Note: this format is open to change.
29184@c An out-of-band breakpoint instead of part of the result?
29185
29186@subsubheading @value{GDBN} Command
29187
29188The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
496ee73e 29189@samp{hbreak}, and @samp{thbreak}. @c and @samp{rbreak}.
922fbb7b
AC
29190
29191@subsubheading Example
29192
29193@smallexample
594fe323 29194(gdb)
922fbb7b 29195-break-insert main
948d5102 29196^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",
998580f1
MK
29197fullname="/home/foo/recursive2.c,line="4",thread-groups=["i1"],
29198times="0"@}
594fe323 29199(gdb)
922fbb7b 29200-break-insert -t foo
948d5102 29201^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",
998580f1
MK
29202fullname="/home/foo/recursive2.c,line="11",thread-groups=["i1"],
29203times="0"@}
594fe323 29204(gdb)
922fbb7b
AC
29205-break-list
29206^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
29207hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
29208@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
29209@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
29210@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
29211@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
29212@{width="40",alignment="2",col_name="what",colhdr="What"@}],
29213body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102 29214addr="0x0001072c", func="main",file="recursive2.c",
998580f1
MK
29215fullname="/home/foo/recursive2.c,"line="4",thread-groups=["i1"],
29216times="0"@},
922fbb7b 29217bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
948d5102 29218addr="0x00010774",func="foo",file="recursive2.c",
998580f1
MK
29219fullname="/home/foo/recursive2.c",line="11",thread-groups=["i1"],
29220times="0"@}]@}
594fe323 29221(gdb)
496ee73e
KS
29222@c -break-insert -r foo.*
29223@c ~int foo(int, int);
29224@c ^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c,
998580f1
MK
29225@c "fullname="/home/foo/recursive2.c",line="11",thread-groups=["i1"],
29226@c times="0"@}
496ee73e 29227@c (gdb)
922fbb7b
AC
29228@end smallexample
29229
c5867ab6
HZ
29230@subheading The @code{-dprintf-insert} Command
29231@findex -dprintf-insert
29232
29233@subsubheading Synopsis
29234
29235@smallexample
29236 -dprintf-insert [ -t ] [ -f ] [ -d ]
29237 [ -c @var{condition} ] [ -i @var{ignore-count} ]
29238 [ -p @var{thread-id} ] [ @var{location} ] [ @var{format} ]
29239 [ @var{argument} ]
29240@end smallexample
29241
29242@noindent
629500fa
KS
29243If supplied, @var{location} may be specified the same way as for
29244the @code{-break-insert} command. @xref{-break-insert}.
c5867ab6
HZ
29245
29246The possible optional parameters of this command are:
29247
29248@table @samp
29249@item -t
29250Insert a temporary breakpoint.
29251@item -f
29252If @var{location} cannot be parsed (for example, if it
29253refers to unknown files or functions), create a pending
29254breakpoint. Without this flag, @value{GDBN} will report
29255an error, and won't create a breakpoint, if @var{location}
29256cannot be parsed.
29257@item -d
29258Create a disabled breakpoint.
29259@item -c @var{condition}
29260Make the breakpoint conditional on @var{condition}.
29261@item -i @var{ignore-count}
29262Set the ignore count of the breakpoint (@pxref{Conditions, ignore count})
29263to @var{ignore-count}.
29264@item -p @var{thread-id}
5d5658a1
PA
29265Restrict the breakpoint to the thread with the specified global
29266@var{thread-id}.
c5867ab6
HZ
29267@end table
29268
29269@subsubheading Result
29270
29271@xref{GDB/MI Breakpoint Information}, for details on the format of the
29272resulting breakpoint.
29273
29274@c An out-of-band breakpoint instead of part of the result?
29275
29276@subsubheading @value{GDBN} Command
29277
29278The corresponding @value{GDBN} command is @samp{dprintf}.
29279
29280@subsubheading Example
29281
29282@smallexample
29283(gdb)
292844-dprintf-insert foo "At foo entry\n"
292854^done,bkpt=@{number="1",type="dprintf",disp="keep",enabled="y",
29286addr="0x000000000040061b",func="foo",file="mi-dprintf.c",
29287fullname="mi-dprintf.c",line="25",thread-groups=["i1"],
29288times="0",script=@{"printf \"At foo entry\\n\"","continue"@},
29289original-location="foo"@}
29290(gdb)
292915-dprintf-insert 26 "arg=%d, g=%d\n" arg g
292925^done,bkpt=@{number="2",type="dprintf",disp="keep",enabled="y",
29293addr="0x000000000040062a",func="foo",file="mi-dprintf.c",
29294fullname="mi-dprintf.c",line="26",thread-groups=["i1"],
29295times="0",script=@{"printf \"arg=%d, g=%d\\n\", arg, g","continue"@},
29296original-location="mi-dprintf.c:26"@}
29297(gdb)
29298@end smallexample
29299
922fbb7b
AC
29300@subheading The @code{-break-list} Command
29301@findex -break-list
29302
29303@subsubheading Synopsis
29304
29305@smallexample
29306 -break-list
29307@end smallexample
29308
29309Displays the list of inserted breakpoints, showing the following fields:
29310
29311@table @samp
29312@item Number
29313number of the breakpoint
29314@item Type
29315type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
29316@item Disposition
29317should the breakpoint be deleted or disabled when it is hit: @samp{keep}
29318or @samp{nokeep}
29319@item Enabled
29320is the breakpoint enabled or no: @samp{y} or @samp{n}
29321@item Address
29322memory location at which the breakpoint is set
29323@item What
29324logical location of the breakpoint, expressed by function name, file
29325name, line number
998580f1
MK
29326@item Thread-groups
29327list of thread groups to which this breakpoint applies
922fbb7b
AC
29328@item Times
29329number of times the breakpoint has been hit
29330@end table
29331
29332If there are no breakpoints or watchpoints, the @code{BreakpointTable}
29333@code{body} field is an empty list.
29334
29335@subsubheading @value{GDBN} Command
29336
29337The corresponding @value{GDBN} command is @samp{info break}.
29338
29339@subsubheading Example
29340
29341@smallexample
594fe323 29342(gdb)
922fbb7b
AC
29343-break-list
29344^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
29345hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
29346@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
29347@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
29348@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
29349@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
29350@{width="40",alignment="2",col_name="what",colhdr="What"@}],
29351body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
998580f1
MK
29352addr="0x000100d0",func="main",file="hello.c",line="5",thread-groups=["i1"],
29353times="0"@},
922fbb7b 29354bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
948d5102 29355addr="0x00010114",func="foo",file="hello.c",fullname="/home/foo/hello.c",
998580f1 29356line="13",thread-groups=["i1"],times="0"@}]@}
594fe323 29357(gdb)
922fbb7b
AC
29358@end smallexample
29359
29360Here's an example of the result when there are no breakpoints:
29361
29362@smallexample
594fe323 29363(gdb)
922fbb7b
AC
29364-break-list
29365^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
29366hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
29367@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
29368@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
29369@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
29370@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
29371@{width="40",alignment="2",col_name="what",colhdr="What"@}],
29372body=[]@}
594fe323 29373(gdb)
922fbb7b
AC
29374@end smallexample
29375
18148017
VP
29376@subheading The @code{-break-passcount} Command
29377@findex -break-passcount
29378
29379@subsubheading Synopsis
29380
29381@smallexample
29382 -break-passcount @var{tracepoint-number} @var{passcount}
29383@end smallexample
29384
29385Set the passcount for tracepoint @var{tracepoint-number} to
29386@var{passcount}. If the breakpoint referred to by @var{tracepoint-number}
29387is not a tracepoint, error is emitted. This corresponds to CLI
29388command @samp{passcount}.
29389
922fbb7b
AC
29390@subheading The @code{-break-watch} Command
29391@findex -break-watch
29392
29393@subsubheading Synopsis
29394
29395@smallexample
29396 -break-watch [ -a | -r ]
29397@end smallexample
29398
29399Create a watchpoint. With the @samp{-a} option it will create an
d3e8051b 29400@dfn{access} watchpoint, i.e., a watchpoint that triggers either on a
922fbb7b 29401read from or on a write to the memory location. With the @samp{-r}
d3e8051b 29402option, the watchpoint created is a @dfn{read} watchpoint, i.e., it will
922fbb7b
AC
29403trigger only when the memory location is accessed for reading. Without
29404either of the options, the watchpoint created is a regular watchpoint,
d3e8051b 29405i.e., it will trigger when the memory location is accessed for writing.
79a6e687 29406@xref{Set Watchpoints, , Setting Watchpoints}.
922fbb7b
AC
29407
29408Note that @samp{-break-list} will report a single list of watchpoints and
29409breakpoints inserted.
29410
29411@subsubheading @value{GDBN} Command
29412
29413The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
29414@samp{rwatch}.
29415
29416@subsubheading Example
29417
29418Setting a watchpoint on a variable in the @code{main} function:
29419
29420@smallexample
594fe323 29421(gdb)
922fbb7b
AC
29422-break-watch x
29423^done,wpt=@{number="2",exp="x"@}
594fe323 29424(gdb)
922fbb7b
AC
29425-exec-continue
29426^running
0869d01b
NR
29427(gdb)
29428*stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
922fbb7b 29429value=@{old="-268439212",new="55"@},
76ff342d 29430frame=@{func="main",args=[],file="recursive2.c",
6d52907e 29431fullname="/home/foo/bar/recursive2.c",line="5",arch="i386:x86_64"@}
594fe323 29432(gdb)
922fbb7b
AC
29433@end smallexample
29434
29435Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
29436the program execution twice: first for the variable changing value, then
29437for the watchpoint going out of scope.
29438
29439@smallexample
594fe323 29440(gdb)
922fbb7b
AC
29441-break-watch C
29442^done,wpt=@{number="5",exp="C"@}
594fe323 29443(gdb)
922fbb7b
AC
29444-exec-continue
29445^running
0869d01b
NR
29446(gdb)
29447*stopped,reason="watchpoint-trigger",
922fbb7b
AC
29448wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
29449frame=@{func="callee4",args=[],
76ff342d 29450file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
29451fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13",
29452arch="i386:x86_64"@}
594fe323 29453(gdb)
922fbb7b
AC
29454-exec-continue
29455^running
0869d01b
NR
29456(gdb)
29457*stopped,reason="watchpoint-scope",wpnum="5",
922fbb7b
AC
29458frame=@{func="callee3",args=[@{name="strarg",
29459value="0x11940 \"A string argument.\""@}],
76ff342d 29460file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
29461fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
29462arch="i386:x86_64"@}
594fe323 29463(gdb)
922fbb7b
AC
29464@end smallexample
29465
29466Listing breakpoints and watchpoints, at different points in the program
29467execution. Note that once the watchpoint goes out of scope, it is
29468deleted.
29469
29470@smallexample
594fe323 29471(gdb)
922fbb7b
AC
29472-break-watch C
29473^done,wpt=@{number="2",exp="C"@}
594fe323 29474(gdb)
922fbb7b
AC
29475-break-list
29476^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
29477hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
29478@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
29479@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
29480@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
29481@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
29482@{width="40",alignment="2",col_name="what",colhdr="What"@}],
29483body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
29484addr="0x00010734",func="callee4",
948d5102 29485file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
998580f1
MK
29486fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c"line="8",thread-groups=["i1"],
29487times="1"@},
922fbb7b 29488bkpt=@{number="2",type="watchpoint",disp="keep",
998580f1 29489enabled="y",addr="",what="C",thread-groups=["i1"],times="0"@}]@}
594fe323 29490(gdb)
922fbb7b
AC
29491-exec-continue
29492^running
0869d01b
NR
29493(gdb)
29494*stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
922fbb7b
AC
29495value=@{old="-276895068",new="3"@},
29496frame=@{func="callee4",args=[],
76ff342d 29497file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
29498fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13",
29499arch="i386:x86_64"@}
594fe323 29500(gdb)
922fbb7b
AC
29501-break-list
29502^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
29503hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
29504@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
29505@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
29506@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
29507@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
29508@{width="40",alignment="2",col_name="what",colhdr="What"@}],
29509body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
29510addr="0x00010734",func="callee4",
948d5102 29511file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
998580f1
MK
29512fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",thread-groups=["i1"],
29513times="1"@},
922fbb7b 29514bkpt=@{number="2",type="watchpoint",disp="keep",
998580f1 29515enabled="y",addr="",what="C",thread-groups=["i1"],times="-5"@}]@}
594fe323 29516(gdb)
922fbb7b
AC
29517-exec-continue
29518^running
29519^done,reason="watchpoint-scope",wpnum="2",
29520frame=@{func="callee3",args=[@{name="strarg",
29521value="0x11940 \"A string argument.\""@}],
76ff342d 29522file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
29523fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
29524arch="i386:x86_64"@}
594fe323 29525(gdb)
922fbb7b
AC
29526-break-list
29527^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
29528hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
29529@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
29530@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
29531@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
29532@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
29533@{width="40",alignment="2",col_name="what",colhdr="What"@}],
29534body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
29535addr="0x00010734",func="callee4",
948d5102
NR
29536file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
29537fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
998580f1 29538thread-groups=["i1"],times="1"@}]@}
594fe323 29539(gdb)
922fbb7b
AC
29540@end smallexample
29541
3fa7bf06
MG
29542
29543@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29544@node GDB/MI Catchpoint Commands
29545@section @sc{gdb/mi} Catchpoint Commands
29546
29547This section documents @sc{gdb/mi} commands for manipulating
29548catchpoints.
29549
40555925
JB
29550@menu
29551* Shared Library GDB/MI Catchpoint Commands::
29552* Ada Exception GDB/MI Catchpoint Commands::
29553@end menu
29554
29555@node Shared Library GDB/MI Catchpoint Commands
29556@subsection Shared Library @sc{gdb/mi} Catchpoints
29557
3fa7bf06
MG
29558@subheading The @code{-catch-load} Command
29559@findex -catch-load
29560
29561@subsubheading Synopsis
29562
29563@smallexample
29564 -catch-load [ -t ] [ -d ] @var{regexp}
29565@end smallexample
29566
29567Add a catchpoint for library load events. If the @samp{-t} option is used,
29568the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
29569Breakpoints}). If the @samp{-d} option is used, the catchpoint is created
29570in a disabled state. The @samp{regexp} argument is a regular
29571expression used to match the name of the loaded library.
29572
29573
29574@subsubheading @value{GDBN} Command
29575
29576The corresponding @value{GDBN} command is @samp{catch load}.
29577
29578@subsubheading Example
29579
29580@smallexample
29581-catch-load -t foo.so
29582^done,bkpt=@{number="1",type="catchpoint",disp="del",enabled="y",
8ac3646f 29583what="load of library matching foo.so",catch-type="load",times="0"@}
3fa7bf06
MG
29584(gdb)
29585@end smallexample
29586
29587
29588@subheading The @code{-catch-unload} Command
29589@findex -catch-unload
29590
29591@subsubheading Synopsis
29592
29593@smallexample
29594 -catch-unload [ -t ] [ -d ] @var{regexp}
29595@end smallexample
29596
29597Add a catchpoint for library unload events. If the @samp{-t} option is
29598used, the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
29599Breakpoints}). If the @samp{-d} option is used, the catchpoint is
29600created in a disabled state. The @samp{regexp} argument is a regular
29601expression used to match the name of the unloaded library.
29602
29603@subsubheading @value{GDBN} Command
29604
29605The corresponding @value{GDBN} command is @samp{catch unload}.
29606
29607@subsubheading Example
29608
29609@smallexample
29610-catch-unload -d bar.so
29611^done,bkpt=@{number="2",type="catchpoint",disp="keep",enabled="n",
8ac3646f 29612what="load of library matching bar.so",catch-type="unload",times="0"@}
3fa7bf06
MG
29613(gdb)
29614@end smallexample
29615
40555925
JB
29616@node Ada Exception GDB/MI Catchpoint Commands
29617@subsection Ada Exception @sc{gdb/mi} Catchpoints
29618
29619The following @sc{gdb/mi} commands can be used to create catchpoints
29620that stop the execution when Ada exceptions are being raised.
29621
29622@subheading The @code{-catch-assert} Command
29623@findex -catch-assert
29624
29625@subsubheading Synopsis
29626
29627@smallexample
29628 -catch-assert [ -c @var{condition}] [ -d ] [ -t ]
29629@end smallexample
29630
29631Add a catchpoint for failed Ada assertions.
29632
29633The possible optional parameters for this command are:
29634
29635@table @samp
29636@item -c @var{condition}
29637Make the catchpoint conditional on @var{condition}.
29638@item -d
29639Create a disabled catchpoint.
29640@item -t
29641Create a temporary catchpoint.
29642@end table
29643
29644@subsubheading @value{GDBN} Command
29645
29646The corresponding @value{GDBN} command is @samp{catch assert}.
29647
29648@subsubheading Example
29649
29650@smallexample
29651-catch-assert
29652^done,bkptno="5",bkpt=@{number="5",type="breakpoint",disp="keep",
29653enabled="y",addr="0x0000000000404888",what="failed Ada assertions",
29654thread-groups=["i1"],times="0",
29655original-location="__gnat_debug_raise_assert_failure"@}
29656(gdb)
29657@end smallexample
29658
29659@subheading The @code{-catch-exception} Command
29660@findex -catch-exception
29661
29662@subsubheading Synopsis
29663
29664@smallexample
29665 -catch-exception [ -c @var{condition}] [ -d ] [ -e @var{exception-name} ]
29666 [ -t ] [ -u ]
29667@end smallexample
29668
29669Add a catchpoint stopping when Ada exceptions are raised.
29670By default, the command stops the program when any Ada exception
29671gets raised. But it is also possible, by using some of the
29672optional parameters described below, to create more selective
29673catchpoints.
29674
29675The possible optional parameters for this command are:
29676
29677@table @samp
29678@item -c @var{condition}
29679Make the catchpoint conditional on @var{condition}.
29680@item -d
29681Create a disabled catchpoint.
29682@item -e @var{exception-name}
29683Only stop when @var{exception-name} is raised. This option cannot
29684be used combined with @samp{-u}.
29685@item -t
29686Create a temporary catchpoint.
29687@item -u
29688Stop only when an unhandled exception gets raised. This option
29689cannot be used combined with @samp{-e}.
29690@end table
29691
29692@subsubheading @value{GDBN} Command
29693
29694The corresponding @value{GDBN} commands are @samp{catch exception}
29695and @samp{catch exception unhandled}.
29696
29697@subsubheading Example
29698
29699@smallexample
29700-catch-exception -e Program_Error
29701^done,bkptno="4",bkpt=@{number="4",type="breakpoint",disp="keep",
29702enabled="y",addr="0x0000000000404874",
29703what="`Program_Error' Ada exception", thread-groups=["i1"],
29704times="0",original-location="__gnat_debug_raise_exception"@}
29705(gdb)
29706@end smallexample
3fa7bf06 29707
bea298f9
XR
29708@subheading The @code{-catch-handlers} Command
29709@findex -catch-handlers
29710
29711@subsubheading Synopsis
29712
29713@smallexample
29714 -catch-handlers [ -c @var{condition}] [ -d ] [ -e @var{exception-name} ]
29715 [ -t ]
29716@end smallexample
29717
29718Add a catchpoint stopping when Ada exceptions are handled.
29719By default, the command stops the program when any Ada exception
29720gets handled. But it is also possible, by using some of the
29721optional parameters described below, to create more selective
29722catchpoints.
29723
29724The possible optional parameters for this command are:
29725
29726@table @samp
29727@item -c @var{condition}
29728Make the catchpoint conditional on @var{condition}.
29729@item -d
29730Create a disabled catchpoint.
29731@item -e @var{exception-name}
29732Only stop when @var{exception-name} is handled.
29733@item -t
29734Create a temporary catchpoint.
29735@end table
29736
29737@subsubheading @value{GDBN} Command
29738
29739The corresponding @value{GDBN} command is @samp{catch handlers}.
29740
29741@subsubheading Example
29742
29743@smallexample
29744-catch-handlers -e Constraint_Error
29745^done,bkptno="4",bkpt=@{number="4",type="breakpoint",disp="keep",
29746enabled="y",addr="0x0000000000402f68",
29747what="`Constraint_Error' Ada exception handlers",thread-groups=["i1"],
29748times="0",original-location="__gnat_begin_handler"@}
29749(gdb)
29750@end smallexample
29751
922fbb7b 29752@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
29753@node GDB/MI Program Context
29754@section @sc{gdb/mi} Program Context
922fbb7b 29755
a2c02241
NR
29756@subheading The @code{-exec-arguments} Command
29757@findex -exec-arguments
922fbb7b 29758
922fbb7b
AC
29759
29760@subsubheading Synopsis
29761
29762@smallexample
a2c02241 29763 -exec-arguments @var{args}
922fbb7b
AC
29764@end smallexample
29765
a2c02241
NR
29766Set the inferior program arguments, to be used in the next
29767@samp{-exec-run}.
922fbb7b 29768
a2c02241 29769@subsubheading @value{GDBN} Command
922fbb7b 29770
a2c02241 29771The corresponding @value{GDBN} command is @samp{set args}.
922fbb7b 29772
a2c02241 29773@subsubheading Example
922fbb7b 29774
fbc5282e
MK
29775@smallexample
29776(gdb)
29777-exec-arguments -v word
29778^done
29779(gdb)
29780@end smallexample
922fbb7b 29781
a2c02241 29782
9901a55b 29783@ignore
a2c02241
NR
29784@subheading The @code{-exec-show-arguments} Command
29785@findex -exec-show-arguments
29786
29787@subsubheading Synopsis
29788
29789@smallexample
29790 -exec-show-arguments
29791@end smallexample
29792
29793Print the arguments of the program.
922fbb7b
AC
29794
29795@subsubheading @value{GDBN} Command
29796
a2c02241 29797The corresponding @value{GDBN} command is @samp{show args}.
922fbb7b
AC
29798
29799@subsubheading Example
a2c02241 29800N.A.
9901a55b 29801@end ignore
922fbb7b 29802
922fbb7b 29803
a2c02241
NR
29804@subheading The @code{-environment-cd} Command
29805@findex -environment-cd
922fbb7b 29806
a2c02241 29807@subsubheading Synopsis
922fbb7b
AC
29808
29809@smallexample
a2c02241 29810 -environment-cd @var{pathdir}
922fbb7b
AC
29811@end smallexample
29812
a2c02241 29813Set @value{GDBN}'s working directory.
922fbb7b 29814
a2c02241 29815@subsubheading @value{GDBN} Command
922fbb7b 29816
a2c02241
NR
29817The corresponding @value{GDBN} command is @samp{cd}.
29818
29819@subsubheading Example
922fbb7b
AC
29820
29821@smallexample
594fe323 29822(gdb)
a2c02241
NR
29823-environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
29824^done
594fe323 29825(gdb)
922fbb7b
AC
29826@end smallexample
29827
29828
a2c02241
NR
29829@subheading The @code{-environment-directory} Command
29830@findex -environment-directory
922fbb7b
AC
29831
29832@subsubheading Synopsis
29833
29834@smallexample
a2c02241 29835 -environment-directory [ -r ] [ @var{pathdir} ]+
922fbb7b
AC
29836@end smallexample
29837
a2c02241
NR
29838Add directories @var{pathdir} to beginning of search path for source files.
29839If the @samp{-r} option is used, the search path is reset to the default
29840search path. If directories @var{pathdir} are supplied in addition to the
29841@samp{-r} option, the search path is first reset and then addition
29842occurs as normal.
29843Multiple directories may be specified, separated by blanks. Specifying
29844multiple directories in a single command
29845results in the directories added to the beginning of the
29846search path in the same order they were presented in the command.
29847If blanks are needed as
29848part of a directory name, double-quotes should be used around
29849the name. In the command output, the path will show up separated
d3e8051b 29850by the system directory-separator character. The directory-separator
a2c02241
NR
29851character must not be used
29852in any directory name.
29853If no directories are specified, the current search path is displayed.
922fbb7b
AC
29854
29855@subsubheading @value{GDBN} Command
29856
a2c02241 29857The corresponding @value{GDBN} command is @samp{dir}.
922fbb7b
AC
29858
29859@subsubheading Example
29860
922fbb7b 29861@smallexample
594fe323 29862(gdb)
a2c02241
NR
29863-environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
29864^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
594fe323 29865(gdb)
a2c02241
NR
29866-environment-directory ""
29867^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
594fe323 29868(gdb)
a2c02241
NR
29869-environment-directory -r /home/jjohnstn/src/gdb /usr/src
29870^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
594fe323 29871(gdb)
a2c02241
NR
29872-environment-directory -r
29873^done,source-path="$cdir:$cwd"
594fe323 29874(gdb)
922fbb7b
AC
29875@end smallexample
29876
29877
a2c02241
NR
29878@subheading The @code{-environment-path} Command
29879@findex -environment-path
922fbb7b
AC
29880
29881@subsubheading Synopsis
29882
29883@smallexample
a2c02241 29884 -environment-path [ -r ] [ @var{pathdir} ]+
922fbb7b
AC
29885@end smallexample
29886
a2c02241
NR
29887Add directories @var{pathdir} to beginning of search path for object files.
29888If the @samp{-r} option is used, the search path is reset to the original
29889search path that existed at gdb start-up. If directories @var{pathdir} are
29890supplied in addition to the
29891@samp{-r} option, the search path is first reset and then addition
29892occurs as normal.
29893Multiple directories may be specified, separated by blanks. Specifying
29894multiple directories in a single command
29895results in the directories added to the beginning of the
29896search path in the same order they were presented in the command.
29897If blanks are needed as
29898part of a directory name, double-quotes should be used around
29899the name. In the command output, the path will show up separated
d3e8051b 29900by the system directory-separator character. The directory-separator
a2c02241
NR
29901character must not be used
29902in any directory name.
29903If no directories are specified, the current path is displayed.
29904
922fbb7b
AC
29905
29906@subsubheading @value{GDBN} Command
29907
a2c02241 29908The corresponding @value{GDBN} command is @samp{path}.
922fbb7b
AC
29909
29910@subsubheading Example
29911
922fbb7b 29912@smallexample
594fe323 29913(gdb)
a2c02241
NR
29914-environment-path
29915^done,path="/usr/bin"
594fe323 29916(gdb)
a2c02241
NR
29917-environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
29918^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
594fe323 29919(gdb)
a2c02241
NR
29920-environment-path -r /usr/local/bin
29921^done,path="/usr/local/bin:/usr/bin"
594fe323 29922(gdb)
922fbb7b
AC
29923@end smallexample
29924
29925
a2c02241
NR
29926@subheading The @code{-environment-pwd} Command
29927@findex -environment-pwd
922fbb7b
AC
29928
29929@subsubheading Synopsis
29930
29931@smallexample
a2c02241 29932 -environment-pwd
922fbb7b
AC
29933@end smallexample
29934
a2c02241 29935Show the current working directory.
922fbb7b 29936
79a6e687 29937@subsubheading @value{GDBN} Command
922fbb7b 29938
a2c02241 29939The corresponding @value{GDBN} command is @samp{pwd}.
922fbb7b
AC
29940
29941@subsubheading Example
29942
922fbb7b 29943@smallexample
594fe323 29944(gdb)
a2c02241
NR
29945-environment-pwd
29946^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
594fe323 29947(gdb)
922fbb7b
AC
29948@end smallexample
29949
a2c02241
NR
29950@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29951@node GDB/MI Thread Commands
29952@section @sc{gdb/mi} Thread Commands
29953
29954
29955@subheading The @code{-thread-info} Command
29956@findex -thread-info
922fbb7b
AC
29957
29958@subsubheading Synopsis
29959
29960@smallexample
8e8901c5 29961 -thread-info [ @var{thread-id} ]
922fbb7b
AC
29962@end smallexample
29963
5d5658a1
PA
29964Reports information about either a specific thread, if the
29965@var{thread-id} parameter is present, or about all threads.
29966@var{thread-id} is the thread's global thread ID. When printing
29967information about all threads, also reports the global ID of the
29968current thread.
8e8901c5 29969
79a6e687 29970@subsubheading @value{GDBN} Command
922fbb7b 29971
8e8901c5
VP
29972The @samp{info thread} command prints the same information
29973about all threads.
922fbb7b 29974
4694da01 29975@subsubheading Result
922fbb7b 29976
ebe553db 29977The result contains the following attributes:
4694da01
TT
29978
29979@table @samp
ebe553db
SM
29980@item threads
29981A list of threads. The format of the elements of the list is described in
29982@ref{GDB/MI Thread Information}.
29983
29984@item current-thread-id
29985The global id of the currently selected thread. This field is omitted if there
29986is no selected thread (for example, when the selected inferior is not running,
29987and therefore has no threads) or if a @var{thread-id} argument was passed to
29988the command.
4694da01
TT
29989
29990@end table
29991
29992@subsubheading Example
29993
29994@smallexample
29995-thread-info
29996^done,threads=[
29997@{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
29998 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",
29999 args=[]@},state="running"@},
30000@{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
30001 frame=@{level="0",addr="0x0804891f",func="foo",
30002 args=[@{name="i",value="10"@}],
6d52907e 30003 file="/tmp/a.c",fullname="/tmp/a.c",line="158",arch="i386:x86_64"@},
4694da01
TT
30004 state="running"@}],
30005current-thread-id="1"
30006(gdb)
30007@end smallexample
30008
a2c02241
NR
30009@subheading The @code{-thread-list-ids} Command
30010@findex -thread-list-ids
922fbb7b 30011
a2c02241 30012@subsubheading Synopsis
922fbb7b 30013
a2c02241
NR
30014@smallexample
30015 -thread-list-ids
30016@end smallexample
922fbb7b 30017
5d5658a1
PA
30018Produces a list of the currently known global @value{GDBN} thread ids.
30019At the end of the list it also prints the total number of such
30020threads.
922fbb7b 30021
c3b108f7
VP
30022This command is retained for historical reasons, the
30023@code{-thread-info} command should be used instead.
30024
922fbb7b
AC
30025@subsubheading @value{GDBN} Command
30026
a2c02241 30027Part of @samp{info threads} supplies the same information.
922fbb7b
AC
30028
30029@subsubheading Example
30030
922fbb7b 30031@smallexample
594fe323 30032(gdb)
a2c02241
NR
30033-thread-list-ids
30034^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
592375cd 30035current-thread-id="1",number-of-threads="3"
594fe323 30036(gdb)
922fbb7b
AC
30037@end smallexample
30038
a2c02241
NR
30039
30040@subheading The @code{-thread-select} Command
30041@findex -thread-select
922fbb7b
AC
30042
30043@subsubheading Synopsis
30044
30045@smallexample
5d5658a1 30046 -thread-select @var{thread-id}
922fbb7b
AC
30047@end smallexample
30048
5d5658a1
PA
30049Make thread with global thread number @var{thread-id} the current
30050thread. It prints the number of the new current thread, and the
30051topmost frame for that thread.
922fbb7b 30052
c3b108f7
VP
30053This command is deprecated in favor of explicitly using the
30054@samp{--thread} option to each command.
30055
922fbb7b
AC
30056@subsubheading @value{GDBN} Command
30057
a2c02241 30058The corresponding @value{GDBN} command is @samp{thread}.
922fbb7b
AC
30059
30060@subsubheading Example
922fbb7b
AC
30061
30062@smallexample
594fe323 30063(gdb)
a2c02241
NR
30064-exec-next
30065^running
594fe323 30066(gdb)
a2c02241
NR
30067*stopped,reason="end-stepping-range",thread-id="2",line="187",
30068file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
594fe323 30069(gdb)
a2c02241
NR
30070-thread-list-ids
30071^done,
30072thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
30073number-of-threads="3"
594fe323 30074(gdb)
a2c02241
NR
30075-thread-select 3
30076^done,new-thread-id="3",
30077frame=@{level="0",func="vprintf",
30078args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
6d52907e 30079@{name="arg",value="0x2"@}],file="vprintf.c",line="31",arch="i386:x86_64"@}
594fe323 30080(gdb)
922fbb7b
AC
30081@end smallexample
30082
5d77fe44
JB
30083@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30084@node GDB/MI Ada Tasking Commands
30085@section @sc{gdb/mi} Ada Tasking Commands
30086
30087@subheading The @code{-ada-task-info} Command
30088@findex -ada-task-info
30089
30090@subsubheading Synopsis
30091
30092@smallexample
30093 -ada-task-info [ @var{task-id} ]
30094@end smallexample
30095
30096Reports information about either a specific Ada task, if the
30097@var{task-id} parameter is present, or about all Ada tasks.
30098
30099@subsubheading @value{GDBN} Command
30100
30101The @samp{info tasks} command prints the same information
30102about all Ada tasks (@pxref{Ada Tasks}).
30103
30104@subsubheading Result
30105
30106The result is a table of Ada tasks. The following columns are
30107defined for each Ada task:
30108
30109@table @samp
30110@item current
30111This field exists only for the current thread. It has the value @samp{*}.
30112
30113@item id
30114The identifier that @value{GDBN} uses to refer to the Ada task.
30115
30116@item task-id
30117The identifier that the target uses to refer to the Ada task.
30118
30119@item thread-id
5d5658a1
PA
30120The global thread identifier of the thread corresponding to the Ada
30121task.
5d77fe44
JB
30122
30123This field should always exist, as Ada tasks are always implemented
30124on top of a thread. But if @value{GDBN} cannot find this corresponding
30125thread for any reason, the field is omitted.
30126
30127@item parent-id
30128This field exists only when the task was created by another task.
30129In this case, it provides the ID of the parent task.
30130
30131@item priority
30132The base priority of the task.
30133
30134@item state
30135The current state of the task. For a detailed description of the
30136possible states, see @ref{Ada Tasks}.
30137
30138@item name
30139The name of the task.
30140
30141@end table
30142
30143@subsubheading Example
30144
30145@smallexample
30146-ada-task-info
30147^done,tasks=@{nr_rows="3",nr_cols="8",
30148hdr=[@{width="1",alignment="-1",col_name="current",colhdr=""@},
30149@{width="3",alignment="1",col_name="id",colhdr="ID"@},
30150@{width="9",alignment="1",col_name="task-id",colhdr="TID"@},
30151@{width="4",alignment="1",col_name="thread-id",colhdr=""@},
30152@{width="4",alignment="1",col_name="parent-id",colhdr="P-ID"@},
30153@{width="3",alignment="1",col_name="priority",colhdr="Pri"@},
30154@{width="22",alignment="-1",col_name="state",colhdr="State"@},
30155@{width="1",alignment="2",col_name="name",colhdr="Name"@}],
30156body=[@{current="*",id="1",task-id=" 644010",thread-id="1",priority="48",
30157state="Child Termination Wait",name="main_task"@}]@}
30158(gdb)
30159@end smallexample
30160
a2c02241
NR
30161@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30162@node GDB/MI Program Execution
30163@section @sc{gdb/mi} Program Execution
922fbb7b 30164
ef21caaf 30165These are the asynchronous commands which generate the out-of-band
3f94c067 30166record @samp{*stopped}. Currently @value{GDBN} only really executes
ef21caaf
NR
30167asynchronously with remote targets and this interaction is mimicked in
30168other cases.
922fbb7b 30169
922fbb7b
AC
30170@subheading The @code{-exec-continue} Command
30171@findex -exec-continue
30172
30173@subsubheading Synopsis
30174
30175@smallexample
540aa8e7 30176 -exec-continue [--reverse] [--all|--thread-group N]
922fbb7b
AC
30177@end smallexample
30178
540aa8e7
MS
30179Resumes the execution of the inferior program, which will continue
30180to execute until it reaches a debugger stop event. If the
30181@samp{--reverse} option is specified, execution resumes in reverse until
30182it reaches a stop event. Stop events may include
30183@itemize @bullet
30184@item
30185breakpoints or watchpoints
30186@item
30187signals or exceptions
30188@item
30189the end of the process (or its beginning under @samp{--reverse})
30190@item
30191the end or beginning of a replay log if one is being used.
30192@end itemize
30193In all-stop mode (@pxref{All-Stop
30194Mode}), may resume only one thread, or all threads, depending on the
30195value of the @samp{scheduler-locking} variable. If @samp{--all} is
a79b8f6e 30196specified, all threads (in all inferiors) will be resumed. The @samp{--all} option is
540aa8e7
MS
30197ignored in all-stop mode. If the @samp{--thread-group} options is
30198specified, then all threads in that thread group are resumed.
922fbb7b
AC
30199
30200@subsubheading @value{GDBN} Command
30201
30202The corresponding @value{GDBN} corresponding is @samp{continue}.
30203
30204@subsubheading Example
30205
30206@smallexample
30207-exec-continue
30208^running
594fe323 30209(gdb)
922fbb7b 30210@@Hello world
a47ec5fe
AR
30211*stopped,reason="breakpoint-hit",disp="keep",bkptno="2",frame=@{
30212func="foo",args=[],file="hello.c",fullname="/home/foo/bar/hello.c",
6d52907e 30213line="13",arch="i386:x86_64"@}
594fe323 30214(gdb)
922fbb7b
AC
30215@end smallexample
30216
30217
30218@subheading The @code{-exec-finish} Command
30219@findex -exec-finish
30220
30221@subsubheading Synopsis
30222
30223@smallexample
540aa8e7 30224 -exec-finish [--reverse]
922fbb7b
AC
30225@end smallexample
30226
ef21caaf
NR
30227Resumes the execution of the inferior program until the current
30228function is exited. Displays the results returned by the function.
540aa8e7
MS
30229If the @samp{--reverse} option is specified, resumes the reverse
30230execution of the inferior program until the point where current
30231function was called.
922fbb7b
AC
30232
30233@subsubheading @value{GDBN} Command
30234
30235The corresponding @value{GDBN} command is @samp{finish}.
30236
30237@subsubheading Example
30238
30239Function returning @code{void}.
30240
30241@smallexample
30242-exec-finish
30243^running
594fe323 30244(gdb)
922fbb7b
AC
30245@@hello from foo
30246*stopped,reason="function-finished",frame=@{func="main",args=[],
6d52907e 30247file="hello.c",fullname="/home/foo/bar/hello.c",line="7",arch="i386:x86_64"@}
594fe323 30248(gdb)
922fbb7b
AC
30249@end smallexample
30250
30251Function returning other than @code{void}. The name of the internal
30252@value{GDBN} variable storing the result is printed, together with the
30253value itself.
30254
30255@smallexample
30256-exec-finish
30257^running
594fe323 30258(gdb)
922fbb7b
AC
30259*stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
30260args=[@{name="a",value="1"],@{name="b",value="9"@}@},
6d52907e
JV
30261file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
30262arch="i386:x86_64"@},
922fbb7b 30263gdb-result-var="$1",return-value="0"
594fe323 30264(gdb)
922fbb7b
AC
30265@end smallexample
30266
30267
30268@subheading The @code{-exec-interrupt} Command
30269@findex -exec-interrupt
30270
30271@subsubheading Synopsis
30272
30273@smallexample
c3b108f7 30274 -exec-interrupt [--all|--thread-group N]
922fbb7b
AC
30275@end smallexample
30276
ef21caaf
NR
30277Interrupts the background execution of the target. Note how the token
30278associated with the stop message is the one for the execution command
30279that has been interrupted. The token for the interrupt itself only
30280appears in the @samp{^done} output. If the user is trying to
922fbb7b
AC
30281interrupt a non-running program, an error message will be printed.
30282
c3b108f7
VP
30283Note that when asynchronous execution is enabled, this command is
30284asynchronous just like other execution commands. That is, first the
30285@samp{^done} response will be printed, and the target stop will be
30286reported after that using the @samp{*stopped} notification.
30287
30288In non-stop mode, only the context thread is interrupted by default.
a79b8f6e
VP
30289All threads (in all inferiors) will be interrupted if the
30290@samp{--all} option is specified. If the @samp{--thread-group}
30291option is specified, all threads in that group will be interrupted.
c3b108f7 30292
922fbb7b
AC
30293@subsubheading @value{GDBN} Command
30294
30295The corresponding @value{GDBN} command is @samp{interrupt}.
30296
30297@subsubheading Example
30298
30299@smallexample
594fe323 30300(gdb)
922fbb7b
AC
30301111-exec-continue
30302111^running
30303
594fe323 30304(gdb)
922fbb7b
AC
30305222-exec-interrupt
30306222^done
594fe323 30307(gdb)
922fbb7b 30308111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
76ff342d 30309frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
6d52907e 30310fullname="/home/foo/bar/try.c",line="13",arch="i386:x86_64"@}
594fe323 30311(gdb)
922fbb7b 30312
594fe323 30313(gdb)
922fbb7b
AC
30314-exec-interrupt
30315^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
594fe323 30316(gdb)
922fbb7b
AC
30317@end smallexample
30318
83eba9b7
VP
30319@subheading The @code{-exec-jump} Command
30320@findex -exec-jump
30321
30322@subsubheading Synopsis
30323
30324@smallexample
30325 -exec-jump @var{location}
30326@end smallexample
30327
30328Resumes execution of the inferior program at the location specified by
30329parameter. @xref{Specify Location}, for a description of the
30330different forms of @var{location}.
30331
30332@subsubheading @value{GDBN} Command
30333
30334The corresponding @value{GDBN} command is @samp{jump}.
30335
30336@subsubheading Example
30337
30338@smallexample
30339-exec-jump foo.c:10
30340*running,thread-id="all"
30341^running
30342@end smallexample
30343
922fbb7b
AC
30344
30345@subheading The @code{-exec-next} Command
30346@findex -exec-next
30347
30348@subsubheading Synopsis
30349
30350@smallexample
540aa8e7 30351 -exec-next [--reverse]
922fbb7b
AC
30352@end smallexample
30353
ef21caaf
NR
30354Resumes execution of the inferior program, stopping when the beginning
30355of the next source line is reached.
922fbb7b 30356
540aa8e7
MS
30357If the @samp{--reverse} option is specified, resumes reverse execution
30358of the inferior program, stopping at the beginning of the previous
30359source line. If you issue this command on the first line of a
30360function, it will take you back to the caller of that function, to the
30361source line where the function was called.
30362
30363
922fbb7b
AC
30364@subsubheading @value{GDBN} Command
30365
30366The corresponding @value{GDBN} command is @samp{next}.
30367
30368@subsubheading Example
30369
30370@smallexample
30371-exec-next
30372^running
594fe323 30373(gdb)
922fbb7b 30374*stopped,reason="end-stepping-range",line="8",file="hello.c"
594fe323 30375(gdb)
922fbb7b
AC
30376@end smallexample
30377
30378
30379@subheading The @code{-exec-next-instruction} Command
30380@findex -exec-next-instruction
30381
30382@subsubheading Synopsis
30383
30384@smallexample
540aa8e7 30385 -exec-next-instruction [--reverse]
922fbb7b
AC
30386@end smallexample
30387
ef21caaf
NR
30388Executes one machine instruction. If the instruction is a function
30389call, continues until the function returns. If the program stops at an
30390instruction in the middle of a source line, the address will be
30391printed as well.
922fbb7b 30392
540aa8e7
MS
30393If the @samp{--reverse} option is specified, resumes reverse execution
30394of the inferior program, stopping at the previous instruction. If the
30395previously executed instruction was a return from another function,
30396it will continue to execute in reverse until the call to that function
30397(from the current stack frame) is reached.
30398
922fbb7b
AC
30399@subsubheading @value{GDBN} Command
30400
30401The corresponding @value{GDBN} command is @samp{nexti}.
30402
30403@subsubheading Example
30404
30405@smallexample
594fe323 30406(gdb)
922fbb7b
AC
30407-exec-next-instruction
30408^running
30409
594fe323 30410(gdb)
922fbb7b
AC
30411*stopped,reason="end-stepping-range",
30412addr="0x000100d4",line="5",file="hello.c"
594fe323 30413(gdb)
922fbb7b
AC
30414@end smallexample
30415
30416
30417@subheading The @code{-exec-return} Command
30418@findex -exec-return
30419
30420@subsubheading Synopsis
30421
30422@smallexample
30423 -exec-return
30424@end smallexample
30425
30426Makes current function return immediately. Doesn't execute the inferior.
30427Displays the new current frame.
30428
30429@subsubheading @value{GDBN} Command
30430
30431The corresponding @value{GDBN} command is @samp{return}.
30432
30433@subsubheading Example
30434
30435@smallexample
594fe323 30436(gdb)
922fbb7b
AC
30437200-break-insert callee4
30438200^done,bkpt=@{number="1",addr="0x00010734",
30439file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
594fe323 30440(gdb)
922fbb7b
AC
30441000-exec-run
30442000^running
594fe323 30443(gdb)
a47ec5fe 30444000*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
922fbb7b 30445frame=@{func="callee4",args=[],
76ff342d 30446file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
30447fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
30448arch="i386:x86_64"@}
594fe323 30449(gdb)
922fbb7b
AC
30450205-break-delete
30451205^done
594fe323 30452(gdb)
922fbb7b
AC
30453111-exec-return
30454111^done,frame=@{level="0",func="callee3",
30455args=[@{name="strarg",
30456value="0x11940 \"A string argument.\""@}],
76ff342d 30457file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
30458fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
30459arch="i386:x86_64"@}
594fe323 30460(gdb)
922fbb7b
AC
30461@end smallexample
30462
30463
30464@subheading The @code{-exec-run} Command
30465@findex -exec-run
30466
30467@subsubheading Synopsis
30468
30469@smallexample
5713b9b5 30470 -exec-run [ --all | --thread-group N ] [ --start ]
922fbb7b
AC
30471@end smallexample
30472
ef21caaf
NR
30473Starts execution of the inferior from the beginning. The inferior
30474executes until either a breakpoint is encountered or the program
30475exits. In the latter case the output will include an exit code, if
30476the program has exited exceptionally.
922fbb7b 30477
5713b9b5
JB
30478When neither the @samp{--all} nor the @samp{--thread-group} option
30479is specified, the current inferior is started. If the
a79b8f6e
VP
30480@samp{--thread-group} option is specified, it should refer to a thread
30481group of type @samp{process}, and that thread group will be started.
30482If the @samp{--all} option is specified, then all inferiors will be started.
30483
5713b9b5
JB
30484Using the @samp{--start} option instructs the debugger to stop
30485the execution at the start of the inferior's main subprogram,
30486following the same behavior as the @code{start} command
30487(@pxref{Starting}).
30488
922fbb7b
AC
30489@subsubheading @value{GDBN} Command
30490
30491The corresponding @value{GDBN} command is @samp{run}.
30492
ef21caaf 30493@subsubheading Examples
922fbb7b
AC
30494
30495@smallexample
594fe323 30496(gdb)
922fbb7b
AC
30497-break-insert main
30498^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
594fe323 30499(gdb)
922fbb7b
AC
30500-exec-run
30501^running
594fe323 30502(gdb)
a47ec5fe 30503*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
76ff342d 30504frame=@{func="main",args=[],file="recursive2.c",
6d52907e 30505fullname="/home/foo/bar/recursive2.c",line="4",arch="i386:x86_64"@}
594fe323 30506(gdb)
922fbb7b
AC
30507@end smallexample
30508
ef21caaf
NR
30509@noindent
30510Program exited normally:
30511
30512@smallexample
594fe323 30513(gdb)
ef21caaf
NR
30514-exec-run
30515^running
594fe323 30516(gdb)
ef21caaf
NR
30517x = 55
30518*stopped,reason="exited-normally"
594fe323 30519(gdb)
ef21caaf
NR
30520@end smallexample
30521
30522@noindent
30523Program exited exceptionally:
30524
30525@smallexample
594fe323 30526(gdb)
ef21caaf
NR
30527-exec-run
30528^running
594fe323 30529(gdb)
ef21caaf
NR
30530x = 55
30531*stopped,reason="exited",exit-code="01"
594fe323 30532(gdb)
ef21caaf
NR
30533@end smallexample
30534
30535Another way the program can terminate is if it receives a signal such as
30536@code{SIGINT}. In this case, @sc{gdb/mi} displays this:
30537
30538@smallexample
594fe323 30539(gdb)
ef21caaf
NR
30540*stopped,reason="exited-signalled",signal-name="SIGINT",
30541signal-meaning="Interrupt"
30542@end smallexample
30543
922fbb7b 30544
a2c02241
NR
30545@c @subheading -exec-signal
30546
30547
30548@subheading The @code{-exec-step} Command
30549@findex -exec-step
922fbb7b
AC
30550
30551@subsubheading Synopsis
30552
30553@smallexample
540aa8e7 30554 -exec-step [--reverse]
922fbb7b
AC
30555@end smallexample
30556
a2c02241
NR
30557Resumes execution of the inferior program, stopping when the beginning
30558of the next source line is reached, if the next source line is not a
30559function call. If it is, stop at the first instruction of the called
540aa8e7
MS
30560function. If the @samp{--reverse} option is specified, resumes reverse
30561execution of the inferior program, stopping at the beginning of the
30562previously executed source line.
922fbb7b
AC
30563
30564@subsubheading @value{GDBN} Command
30565
a2c02241 30566The corresponding @value{GDBN} command is @samp{step}.
922fbb7b
AC
30567
30568@subsubheading Example
30569
30570Stepping into a function:
30571
30572@smallexample
30573-exec-step
30574^running
594fe323 30575(gdb)
922fbb7b
AC
30576*stopped,reason="end-stepping-range",
30577frame=@{func="foo",args=[@{name="a",value="10"@},
76ff342d 30578@{name="b",value="0"@}],file="recursive2.c",
6d52907e 30579fullname="/home/foo/bar/recursive2.c",line="11",arch="i386:x86_64"@}
594fe323 30580(gdb)
922fbb7b
AC
30581@end smallexample
30582
30583Regular stepping:
30584
30585@smallexample
30586-exec-step
30587^running
594fe323 30588(gdb)
922fbb7b 30589*stopped,reason="end-stepping-range",line="14",file="recursive2.c"
594fe323 30590(gdb)
922fbb7b
AC
30591@end smallexample
30592
30593
30594@subheading The @code{-exec-step-instruction} Command
30595@findex -exec-step-instruction
30596
30597@subsubheading Synopsis
30598
30599@smallexample
540aa8e7 30600 -exec-step-instruction [--reverse]
922fbb7b
AC
30601@end smallexample
30602
540aa8e7
MS
30603Resumes the inferior which executes one machine instruction. If the
30604@samp{--reverse} option is specified, resumes reverse execution of the
30605inferior program, stopping at the previously executed instruction.
30606The output, once @value{GDBN} has stopped, will vary depending on
30607whether we have stopped in the middle of a source line or not. In the
30608former case, the address at which the program stopped will be printed
30609as well.
922fbb7b
AC
30610
30611@subsubheading @value{GDBN} Command
30612
30613The corresponding @value{GDBN} command is @samp{stepi}.
30614
30615@subsubheading Example
30616
30617@smallexample
594fe323 30618(gdb)
922fbb7b
AC
30619-exec-step-instruction
30620^running
30621
594fe323 30622(gdb)
922fbb7b 30623*stopped,reason="end-stepping-range",
76ff342d 30624frame=@{func="foo",args=[],file="try.c",
6d52907e 30625fullname="/home/foo/bar/try.c",line="10",arch="i386:x86_64"@}
594fe323 30626(gdb)
922fbb7b
AC
30627-exec-step-instruction
30628^running
30629
594fe323 30630(gdb)
922fbb7b 30631*stopped,reason="end-stepping-range",
76ff342d 30632frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
6d52907e 30633fullname="/home/foo/bar/try.c",line="10",arch="i386:x86_64"@}
594fe323 30634(gdb)
922fbb7b
AC
30635@end smallexample
30636
30637
30638@subheading The @code{-exec-until} Command
30639@findex -exec-until
30640
30641@subsubheading Synopsis
30642
30643@smallexample
30644 -exec-until [ @var{location} ]
30645@end smallexample
30646
ef21caaf
NR
30647Executes the inferior until the @var{location} specified in the
30648argument is reached. If there is no argument, the inferior executes
30649until a source line greater than the current one is reached. The
30650reason for stopping in this case will be @samp{location-reached}.
922fbb7b
AC
30651
30652@subsubheading @value{GDBN} Command
30653
30654The corresponding @value{GDBN} command is @samp{until}.
30655
30656@subsubheading Example
30657
30658@smallexample
594fe323 30659(gdb)
922fbb7b
AC
30660-exec-until recursive2.c:6
30661^running
594fe323 30662(gdb)
922fbb7b
AC
30663x = 55
30664*stopped,reason="location-reached",frame=@{func="main",args=[],
6d52907e
JV
30665file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="6",
30666arch="i386:x86_64"@}
594fe323 30667(gdb)
922fbb7b
AC
30668@end smallexample
30669
30670@ignore
30671@subheading -file-clear
30672Is this going away????
30673@end ignore
30674
351ff01a 30675@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
30676@node GDB/MI Stack Manipulation
30677@section @sc{gdb/mi} Stack Manipulation Commands
351ff01a 30678
1e611234
PM
30679@subheading The @code{-enable-frame-filters} Command
30680@findex -enable-frame-filters
30681
30682@smallexample
30683-enable-frame-filters
30684@end smallexample
30685
30686@value{GDBN} allows Python-based frame filters to affect the output of
30687the MI commands relating to stack traces. As there is no way to
30688implement this in a fully backward-compatible way, a front end must
30689request that this functionality be enabled.
30690
30691Once enabled, this feature cannot be disabled.
30692
30693Note that if Python support has not been compiled into @value{GDBN},
30694this command will still succeed (and do nothing).
922fbb7b 30695
a2c02241
NR
30696@subheading The @code{-stack-info-frame} Command
30697@findex -stack-info-frame
922fbb7b
AC
30698
30699@subsubheading Synopsis
30700
30701@smallexample
a2c02241 30702 -stack-info-frame
922fbb7b
AC
30703@end smallexample
30704
a2c02241 30705Get info on the selected frame.
922fbb7b
AC
30706
30707@subsubheading @value{GDBN} Command
30708
a2c02241
NR
30709The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
30710(without arguments).
922fbb7b
AC
30711
30712@subsubheading Example
30713
30714@smallexample
594fe323 30715(gdb)
a2c02241
NR
30716-stack-info-frame
30717^done,frame=@{level="1",addr="0x0001076c",func="callee3",
30718file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
30719fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17",
30720arch="i386:x86_64"@}
594fe323 30721(gdb)
922fbb7b
AC
30722@end smallexample
30723
a2c02241
NR
30724@subheading The @code{-stack-info-depth} Command
30725@findex -stack-info-depth
922fbb7b
AC
30726
30727@subsubheading Synopsis
30728
30729@smallexample
a2c02241 30730 -stack-info-depth [ @var{max-depth} ]
922fbb7b
AC
30731@end smallexample
30732
a2c02241
NR
30733Return the depth of the stack. If the integer argument @var{max-depth}
30734is specified, do not count beyond @var{max-depth} frames.
922fbb7b
AC
30735
30736@subsubheading @value{GDBN} Command
30737
a2c02241 30738There's no equivalent @value{GDBN} command.
922fbb7b
AC
30739
30740@subsubheading Example
30741
a2c02241
NR
30742For a stack with frame levels 0 through 11:
30743
922fbb7b 30744@smallexample
594fe323 30745(gdb)
a2c02241
NR
30746-stack-info-depth
30747^done,depth="12"
594fe323 30748(gdb)
a2c02241
NR
30749-stack-info-depth 4
30750^done,depth="4"
594fe323 30751(gdb)
a2c02241
NR
30752-stack-info-depth 12
30753^done,depth="12"
594fe323 30754(gdb)
a2c02241
NR
30755-stack-info-depth 11
30756^done,depth="11"
594fe323 30757(gdb)
a2c02241
NR
30758-stack-info-depth 13
30759^done,depth="12"
594fe323 30760(gdb)
922fbb7b
AC
30761@end smallexample
30762
1e611234 30763@anchor{-stack-list-arguments}
a2c02241
NR
30764@subheading The @code{-stack-list-arguments} Command
30765@findex -stack-list-arguments
922fbb7b
AC
30766
30767@subsubheading Synopsis
30768
30769@smallexample
6211c335 30770 -stack-list-arguments [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
a2c02241 30771 [ @var{low-frame} @var{high-frame} ]
922fbb7b
AC
30772@end smallexample
30773
a2c02241
NR
30774Display a list of the arguments for the frames between @var{low-frame}
30775and @var{high-frame} (inclusive). If @var{low-frame} and
2f1acb09
VP
30776@var{high-frame} are not provided, list the arguments for the whole
30777call stack. If the two arguments are equal, show the single frame
30778at the corresponding level. It is an error if @var{low-frame} is
30779larger than the actual number of frames. On the other hand,
30780@var{high-frame} may be larger than the actual number of frames, in
30781which case only existing frames will be returned.
a2c02241 30782
3afae151
VP
30783If @var{print-values} is 0 or @code{--no-values}, print only the names of
30784the variables; if it is 1 or @code{--all-values}, print also their
30785values; and if it is 2 or @code{--simple-values}, print the name,
30786type and value for simple data types, and the name and type for arrays,
1e611234
PM
30787structures and unions. If the option @code{--no-frame-filters} is
30788supplied, then Python frame filters will not be executed.
30789
6211c335
YQ
30790If the @code{--skip-unavailable} option is specified, arguments that
30791are not available are not listed. Partially available arguments
30792are still displayed, however.
922fbb7b 30793
b3372f91
VP
30794Use of this command to obtain arguments in a single frame is
30795deprecated in favor of the @samp{-stack-list-variables} command.
30796
922fbb7b
AC
30797@subsubheading @value{GDBN} Command
30798
a2c02241
NR
30799@value{GDBN} does not have an equivalent command. @code{gdbtk} has a
30800@samp{gdb_get_args} command which partially overlaps with the
30801functionality of @samp{-stack-list-arguments}.
922fbb7b
AC
30802
30803@subsubheading Example
922fbb7b 30804
a2c02241 30805@smallexample
594fe323 30806(gdb)
a2c02241
NR
30807-stack-list-frames
30808^done,
30809stack=[
30810frame=@{level="0",addr="0x00010734",func="callee4",
30811file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
30812fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
30813arch="i386:x86_64"@},
a2c02241
NR
30814frame=@{level="1",addr="0x0001076c",func="callee3",
30815file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
30816fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17",
30817arch="i386:x86_64"@},
a2c02241
NR
30818frame=@{level="2",addr="0x0001078c",func="callee2",
30819file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
30820fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22",
30821arch="i386:x86_64"@},
a2c02241
NR
30822frame=@{level="3",addr="0x000107b4",func="callee1",
30823file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
30824fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27",
30825arch="i386:x86_64"@},
a2c02241
NR
30826frame=@{level="4",addr="0x000107e0",func="main",
30827file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
30828fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32",
30829arch="i386:x86_64"@}]
594fe323 30830(gdb)
a2c02241
NR
30831-stack-list-arguments 0
30832^done,
30833stack-args=[
30834frame=@{level="0",args=[]@},
30835frame=@{level="1",args=[name="strarg"]@},
30836frame=@{level="2",args=[name="intarg",name="strarg"]@},
30837frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
30838frame=@{level="4",args=[]@}]
594fe323 30839(gdb)
a2c02241
NR
30840-stack-list-arguments 1
30841^done,
30842stack-args=[
30843frame=@{level="0",args=[]@},
30844frame=@{level="1",
30845 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
30846frame=@{level="2",args=[
30847@{name="intarg",value="2"@},
30848@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
30849@{frame=@{level="3",args=[
30850@{name="intarg",value="2"@},
30851@{name="strarg",value="0x11940 \"A string argument.\""@},
30852@{name="fltarg",value="3.5"@}]@},
30853frame=@{level="4",args=[]@}]
594fe323 30854(gdb)
a2c02241
NR
30855-stack-list-arguments 0 2 2
30856^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
594fe323 30857(gdb)
a2c02241
NR
30858-stack-list-arguments 1 2 2
30859^done,stack-args=[frame=@{level="2",
30860args=[@{name="intarg",value="2"@},
30861@{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
594fe323 30862(gdb)
a2c02241
NR
30863@end smallexample
30864
30865@c @subheading -stack-list-exception-handlers
922fbb7b 30866
a2c02241 30867
1e611234 30868@anchor{-stack-list-frames}
a2c02241
NR
30869@subheading The @code{-stack-list-frames} Command
30870@findex -stack-list-frames
1abaf70c
BR
30871
30872@subsubheading Synopsis
30873
30874@smallexample
1e611234 30875 -stack-list-frames [ --no-frame-filters @var{low-frame} @var{high-frame} ]
1abaf70c
BR
30876@end smallexample
30877
a2c02241
NR
30878List the frames currently on the stack. For each frame it displays the
30879following info:
30880
30881@table @samp
30882@item @var{level}
d3e8051b 30883The frame number, 0 being the topmost frame, i.e., the innermost function.
a2c02241
NR
30884@item @var{addr}
30885The @code{$pc} value for that frame.
30886@item @var{func}
30887Function name.
30888@item @var{file}
30889File name of the source file where the function lives.
7d288aaa
TT
30890@item @var{fullname}
30891The full file name of the source file where the function lives.
a2c02241
NR
30892@item @var{line}
30893Line number corresponding to the @code{$pc}.
7d288aaa
TT
30894@item @var{from}
30895The shared library where this function is defined. This is only given
30896if the frame's function is not known.
6d52907e
JV
30897@item @var{arch}
30898Frame's architecture.
a2c02241
NR
30899@end table
30900
30901If invoked without arguments, this command prints a backtrace for the
30902whole stack. If given two integer arguments, it shows the frames whose
30903levels are between the two arguments (inclusive). If the two arguments
2ab1eb7a
VP
30904are equal, it shows the single frame at the corresponding level. It is
30905an error if @var{low-frame} is larger than the actual number of
a5451f4e 30906frames. On the other hand, @var{high-frame} may be larger than the
1e611234
PM
30907actual number of frames, in which case only existing frames will be
30908returned. If the option @code{--no-frame-filters} is supplied, then
30909Python frame filters will not be executed.
1abaf70c
BR
30910
30911@subsubheading @value{GDBN} Command
30912
a2c02241 30913The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
1abaf70c
BR
30914
30915@subsubheading Example
30916
a2c02241
NR
30917Full stack backtrace:
30918
1abaf70c 30919@smallexample
594fe323 30920(gdb)
a2c02241
NR
30921-stack-list-frames
30922^done,stack=
30923[frame=@{level="0",addr="0x0001076c",func="foo",
6d52907e
JV
30924 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="11",
30925 arch="i386:x86_64"@},
a2c02241 30926frame=@{level="1",addr="0x000107a4",func="foo",
6d52907e
JV
30927 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
30928 arch="i386:x86_64"@},
a2c02241 30929frame=@{level="2",addr="0x000107a4",func="foo",
6d52907e
JV
30930 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
30931 arch="i386:x86_64"@},
a2c02241 30932frame=@{level="3",addr="0x000107a4",func="foo",
6d52907e
JV
30933 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
30934 arch="i386:x86_64"@},
a2c02241 30935frame=@{level="4",addr="0x000107a4",func="foo",
6d52907e
JV
30936 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
30937 arch="i386:x86_64"@},
a2c02241 30938frame=@{level="5",addr="0x000107a4",func="foo",
6d52907e
JV
30939 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
30940 arch="i386:x86_64"@},
a2c02241 30941frame=@{level="6",addr="0x000107a4",func="foo",
6d52907e
JV
30942 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
30943 arch="i386:x86_64"@},
a2c02241 30944frame=@{level="7",addr="0x000107a4",func="foo",
6d52907e
JV
30945 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
30946 arch="i386:x86_64"@},
a2c02241 30947frame=@{level="8",addr="0x000107a4",func="foo",
6d52907e
JV
30948 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
30949 arch="i386:x86_64"@},
a2c02241 30950frame=@{level="9",addr="0x000107a4",func="foo",
6d52907e
JV
30951 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
30952 arch="i386:x86_64"@},
a2c02241 30953frame=@{level="10",addr="0x000107a4",func="foo",
6d52907e
JV
30954 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
30955 arch="i386:x86_64"@},
a2c02241 30956frame=@{level="11",addr="0x00010738",func="main",
6d52907e
JV
30957 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="4",
30958 arch="i386:x86_64"@}]
594fe323 30959(gdb)
1abaf70c
BR
30960@end smallexample
30961
a2c02241 30962Show frames between @var{low_frame} and @var{high_frame}:
1abaf70c 30963
a2c02241 30964@smallexample
594fe323 30965(gdb)
a2c02241
NR
30966-stack-list-frames 3 5
30967^done,stack=
30968[frame=@{level="3",addr="0x000107a4",func="foo",
6d52907e
JV
30969 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
30970 arch="i386:x86_64"@},
a2c02241 30971frame=@{level="4",addr="0x000107a4",func="foo",
6d52907e
JV
30972 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
30973 arch="i386:x86_64"@},
a2c02241 30974frame=@{level="5",addr="0x000107a4",func="foo",
6d52907e
JV
30975 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
30976 arch="i386:x86_64"@}]
594fe323 30977(gdb)
a2c02241 30978@end smallexample
922fbb7b 30979
a2c02241 30980Show a single frame:
922fbb7b
AC
30981
30982@smallexample
594fe323 30983(gdb)
a2c02241
NR
30984-stack-list-frames 3 3
30985^done,stack=
30986[frame=@{level="3",addr="0x000107a4",func="foo",
6d52907e
JV
30987 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
30988 arch="i386:x86_64"@}]
594fe323 30989(gdb)
922fbb7b
AC
30990@end smallexample
30991
922fbb7b 30992
a2c02241
NR
30993@subheading The @code{-stack-list-locals} Command
30994@findex -stack-list-locals
1e611234 30995@anchor{-stack-list-locals}
57c22c6c 30996
a2c02241 30997@subsubheading Synopsis
922fbb7b
AC
30998
30999@smallexample
6211c335 31000 -stack-list-locals [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
922fbb7b
AC
31001@end smallexample
31002
a2c02241
NR
31003Display the local variable names for the selected frame. If
31004@var{print-values} is 0 or @code{--no-values}, print only the names of
31005the variables; if it is 1 or @code{--all-values}, print also their
31006values; and if it is 2 or @code{--simple-values}, print the name,
3afae151 31007type and value for simple data types, and the name and type for arrays,
a2c02241
NR
31008structures and unions. In this last case, a frontend can immediately
31009display the value of simple data types and create variable objects for
d3e8051b 31010other data types when the user wishes to explore their values in
1e611234
PM
31011more detail. If the option @code{--no-frame-filters} is supplied, then
31012Python frame filters will not be executed.
922fbb7b 31013
6211c335
YQ
31014If the @code{--skip-unavailable} option is specified, local variables
31015that are not available are not listed. Partially available local
31016variables are still displayed, however.
31017
b3372f91
VP
31018This command is deprecated in favor of the
31019@samp{-stack-list-variables} command.
31020
922fbb7b
AC
31021@subsubheading @value{GDBN} Command
31022
a2c02241 31023@samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
922fbb7b
AC
31024
31025@subsubheading Example
922fbb7b
AC
31026
31027@smallexample
594fe323 31028(gdb)
a2c02241
NR
31029-stack-list-locals 0
31030^done,locals=[name="A",name="B",name="C"]
594fe323 31031(gdb)
a2c02241
NR
31032-stack-list-locals --all-values
31033^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
31034 @{name="C",value="@{1, 2, 3@}"@}]
31035-stack-list-locals --simple-values
31036^done,locals=[@{name="A",type="int",value="1"@},
31037 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
594fe323 31038(gdb)
922fbb7b
AC
31039@end smallexample
31040
1e611234 31041@anchor{-stack-list-variables}
b3372f91
VP
31042@subheading The @code{-stack-list-variables} Command
31043@findex -stack-list-variables
31044
31045@subsubheading Synopsis
31046
31047@smallexample
6211c335 31048 -stack-list-variables [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
b3372f91
VP
31049@end smallexample
31050
31051Display the names of local variables and function arguments for the selected frame. If
31052@var{print-values} is 0 or @code{--no-values}, print only the names of
31053the variables; if it is 1 or @code{--all-values}, print also their
31054values; and if it is 2 or @code{--simple-values}, print the name,
3afae151 31055type and value for simple data types, and the name and type for arrays,
1e611234
PM
31056structures and unions. If the option @code{--no-frame-filters} is
31057supplied, then Python frame filters will not be executed.
b3372f91 31058
6211c335
YQ
31059If the @code{--skip-unavailable} option is specified, local variables
31060and arguments that are not available are not listed. Partially
31061available arguments and local variables are still displayed, however.
31062
b3372f91
VP
31063@subsubheading Example
31064
31065@smallexample
31066(gdb)
31067-stack-list-variables --thread 1 --frame 0 --all-values
4f412fd0 31068^done,variables=[@{name="x",value="11"@},@{name="s",value="@{a = 1, b = 2@}"@}]
b3372f91
VP
31069(gdb)
31070@end smallexample
31071
922fbb7b 31072
a2c02241
NR
31073@subheading The @code{-stack-select-frame} Command
31074@findex -stack-select-frame
922fbb7b
AC
31075
31076@subsubheading Synopsis
31077
31078@smallexample
a2c02241 31079 -stack-select-frame @var{framenum}
922fbb7b
AC
31080@end smallexample
31081
a2c02241
NR
31082Change the selected frame. Select a different frame @var{framenum} on
31083the stack.
922fbb7b 31084
c3b108f7
VP
31085This command in deprecated in favor of passing the @samp{--frame}
31086option to every command.
31087
922fbb7b
AC
31088@subsubheading @value{GDBN} Command
31089
a2c02241
NR
31090The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
31091@samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
922fbb7b
AC
31092
31093@subsubheading Example
31094
31095@smallexample
594fe323 31096(gdb)
a2c02241 31097-stack-select-frame 2
922fbb7b 31098^done
594fe323 31099(gdb)
922fbb7b
AC
31100@end smallexample
31101
31102@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
31103@node GDB/MI Variable Objects
31104@section @sc{gdb/mi} Variable Objects
922fbb7b 31105
a1b5960f 31106@ignore
922fbb7b 31107
a2c02241 31108@subheading Motivation for Variable Objects in @sc{gdb/mi}
922fbb7b 31109
a2c02241
NR
31110For the implementation of a variable debugger window (locals, watched
31111expressions, etc.), we are proposing the adaptation of the existing code
31112used by @code{Insight}.
922fbb7b 31113
a2c02241 31114The two main reasons for that are:
922fbb7b 31115
a2c02241
NR
31116@enumerate 1
31117@item
31118It has been proven in practice (it is already on its second generation).
922fbb7b 31119
a2c02241
NR
31120@item
31121It will shorten development time (needless to say how important it is
31122now).
31123@end enumerate
922fbb7b 31124
a2c02241
NR
31125The original interface was designed to be used by Tcl code, so it was
31126slightly changed so it could be used through @sc{gdb/mi}. This section
31127describes the @sc{gdb/mi} operations that will be available and gives some
31128hints about their use.
922fbb7b 31129
a2c02241
NR
31130@emph{Note}: In addition to the set of operations described here, we
31131expect the @sc{gui} implementation of a variable window to require, at
31132least, the following operations:
922fbb7b 31133
a2c02241
NR
31134@itemize @bullet
31135@item @code{-gdb-show} @code{output-radix}
31136@item @code{-stack-list-arguments}
31137@item @code{-stack-list-locals}
31138@item @code{-stack-select-frame}
31139@end itemize
922fbb7b 31140
a1b5960f
VP
31141@end ignore
31142
c8b2f53c 31143@subheading Introduction to Variable Objects
922fbb7b 31144
a2c02241 31145@cindex variable objects in @sc{gdb/mi}
c8b2f53c
VP
31146
31147Variable objects are "object-oriented" MI interface for examining and
31148changing values of expressions. Unlike some other MI interfaces that
31149work with expressions, variable objects are specifically designed for
31150simple and efficient presentation in the frontend. A variable object
31151is identified by string name. When a variable object is created, the
31152frontend specifies the expression for that variable object. The
31153expression can be a simple variable, or it can be an arbitrary complex
31154expression, and can even involve CPU registers. After creating a
31155variable object, the frontend can invoke other variable object
31156operations---for example to obtain or change the value of a variable
31157object, or to change display format.
31158
31159Variable objects have hierarchical tree structure. Any variable object
31160that corresponds to a composite type, such as structure in C, has
31161a number of child variable objects, for example corresponding to each
31162element of a structure. A child variable object can itself have
31163children, recursively. Recursion ends when we reach
25d5ea92
VP
31164leaf variable objects, which always have built-in types. Child variable
31165objects are created only by explicit request, so if a frontend
31166is not interested in the children of a particular variable object, no
31167child will be created.
c8b2f53c
VP
31168
31169For a leaf variable object it is possible to obtain its value as a
31170string, or set the value from a string. String value can be also
31171obtained for a non-leaf variable object, but it's generally a string
31172that only indicates the type of the object, and does not list its
31173contents. Assignment to a non-leaf variable object is not allowed.
31174
31175A frontend does not need to read the values of all variable objects each time
31176the program stops. Instead, MI provides an update command that lists all
31177variable objects whose values has changed since the last update
31178operation. This considerably reduces the amount of data that must
25d5ea92
VP
31179be transferred to the frontend. As noted above, children variable
31180objects are created on demand, and only leaf variable objects have a
31181real value. As result, gdb will read target memory only for leaf
31182variables that frontend has created.
31183
31184The automatic update is not always desirable. For example, a frontend
31185might want to keep a value of some expression for future reference,
31186and never update it. For another example, fetching memory is
31187relatively slow for embedded targets, so a frontend might want
31188to disable automatic update for the variables that are either not
31189visible on the screen, or ``closed''. This is possible using so
31190called ``frozen variable objects''. Such variable objects are never
31191implicitly updated.
922fbb7b 31192
c3b108f7
VP
31193Variable objects can be either @dfn{fixed} or @dfn{floating}. For the
31194fixed variable object, the expression is parsed when the variable
31195object is created, including associating identifiers to specific
31196variables. The meaning of expression never changes. For a floating
31197variable object the values of variables whose names appear in the
31198expressions are re-evaluated every time in the context of the current
31199frame. Consider this example:
31200
31201@smallexample
31202void do_work(...)
31203@{
31204 struct work_state state;
31205
31206 if (...)
31207 do_work(...);
31208@}
31209@end smallexample
31210
31211If a fixed variable object for the @code{state} variable is created in
7a9dd1b2 31212this function, and we enter the recursive call, the variable
c3b108f7
VP
31213object will report the value of @code{state} in the top-level
31214@code{do_work} invocation. On the other hand, a floating variable
31215object will report the value of @code{state} in the current frame.
31216
31217If an expression specified when creating a fixed variable object
31218refers to a local variable, the variable object becomes bound to the
31219thread and frame in which the variable object is created. When such
31220variable object is updated, @value{GDBN} makes sure that the
31221thread/frame combination the variable object is bound to still exists,
31222and re-evaluates the variable object in context of that thread/frame.
31223
a2c02241
NR
31224The following is the complete set of @sc{gdb/mi} operations defined to
31225access this functionality:
922fbb7b 31226
a2c02241
NR
31227@multitable @columnfractions .4 .6
31228@item @strong{Operation}
31229@tab @strong{Description}
922fbb7b 31230
0cc7d26f
TT
31231@item @code{-enable-pretty-printing}
31232@tab enable Python-based pretty-printing
a2c02241
NR
31233@item @code{-var-create}
31234@tab create a variable object
31235@item @code{-var-delete}
22d8a470 31236@tab delete the variable object and/or its children
a2c02241
NR
31237@item @code{-var-set-format}
31238@tab set the display format of this variable
31239@item @code{-var-show-format}
31240@tab show the display format of this variable
31241@item @code{-var-info-num-children}
31242@tab tells how many children this object has
31243@item @code{-var-list-children}
31244@tab return a list of the object's children
31245@item @code{-var-info-type}
31246@tab show the type of this variable object
31247@item @code{-var-info-expression}
02142340
VP
31248@tab print parent-relative expression that this variable object represents
31249@item @code{-var-info-path-expression}
31250@tab print full expression that this variable object represents
a2c02241
NR
31251@item @code{-var-show-attributes}
31252@tab is this variable editable? does it exist here?
31253@item @code{-var-evaluate-expression}
31254@tab get the value of this variable
31255@item @code{-var-assign}
31256@tab set the value of this variable
31257@item @code{-var-update}
31258@tab update the variable and its children
25d5ea92
VP
31259@item @code{-var-set-frozen}
31260@tab set frozeness attribute
0cc7d26f
TT
31261@item @code{-var-set-update-range}
31262@tab set range of children to display on update
a2c02241 31263@end multitable
922fbb7b 31264
a2c02241
NR
31265In the next subsection we describe each operation in detail and suggest
31266how it can be used.
922fbb7b 31267
a2c02241 31268@subheading Description And Use of Operations on Variable Objects
922fbb7b 31269
0cc7d26f
TT
31270@subheading The @code{-enable-pretty-printing} Command
31271@findex -enable-pretty-printing
31272
31273@smallexample
31274-enable-pretty-printing
31275@end smallexample
31276
31277@value{GDBN} allows Python-based visualizers to affect the output of the
31278MI variable object commands. However, because there was no way to
31279implement this in a fully backward-compatible way, a front end must
31280request that this functionality be enabled.
31281
31282Once enabled, this feature cannot be disabled.
31283
31284Note that if Python support has not been compiled into @value{GDBN},
31285this command will still succeed (and do nothing).
31286
f43030c4
TT
31287This feature is currently (as of @value{GDBN} 7.0) experimental, and
31288may work differently in future versions of @value{GDBN}.
31289
a2c02241
NR
31290@subheading The @code{-var-create} Command
31291@findex -var-create
ef21caaf 31292
a2c02241 31293@subsubheading Synopsis
ef21caaf 31294
a2c02241
NR
31295@smallexample
31296 -var-create @{@var{name} | "-"@}
c3b108f7 31297 @{@var{frame-addr} | "*" | "@@"@} @var{expression}
a2c02241
NR
31298@end smallexample
31299
31300This operation creates a variable object, which allows the monitoring of
31301a variable, the result of an expression, a memory cell or a CPU
31302register.
ef21caaf 31303
a2c02241
NR
31304The @var{name} parameter is the string by which the object can be
31305referenced. It must be unique. If @samp{-} is specified, the varobj
31306system will generate a string ``varNNNNNN'' automatically. It will be
c3b108f7 31307unique provided that one does not specify @var{name} of that format.
a2c02241 31308The command fails if a duplicate name is found.
ef21caaf 31309
a2c02241
NR
31310The frame under which the expression should be evaluated can be
31311specified by @var{frame-addr}. A @samp{*} indicates that the current
c3b108f7
VP
31312frame should be used. A @samp{@@} indicates that a floating variable
31313object must be created.
922fbb7b 31314
a2c02241
NR
31315@var{expression} is any expression valid on the current language set (must not
31316begin with a @samp{*}), or one of the following:
922fbb7b 31317
a2c02241
NR
31318@itemize @bullet
31319@item
31320@samp{*@var{addr}}, where @var{addr} is the address of a memory cell
922fbb7b 31321
a2c02241
NR
31322@item
31323@samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
922fbb7b 31324
a2c02241
NR
31325@item
31326@samp{$@var{regname}} --- a CPU register name
31327@end itemize
922fbb7b 31328
0cc7d26f
TT
31329@cindex dynamic varobj
31330A varobj's contents may be provided by a Python-based pretty-printer. In this
31331case the varobj is known as a @dfn{dynamic varobj}. Dynamic varobjs
31332have slightly different semantics in some cases. If the
31333@code{-enable-pretty-printing} command is not sent, then @value{GDBN}
31334will never create a dynamic varobj. This ensures backward
31335compatibility for existing clients.
31336
a2c02241 31337@subsubheading Result
922fbb7b 31338
0cc7d26f
TT
31339This operation returns attributes of the newly-created varobj. These
31340are:
31341
31342@table @samp
31343@item name
31344The name of the varobj.
31345
31346@item numchild
31347The number of children of the varobj. This number is not necessarily
31348reliable for a dynamic varobj. Instead, you must examine the
31349@samp{has_more} attribute.
31350
31351@item value
31352The varobj's scalar value. For a varobj whose type is some sort of
31353aggregate (e.g., a @code{struct}), or for a dynamic varobj, this value
31354will not be interesting.
31355
31356@item type
31357The varobj's type. This is a string representation of the type, as
8264ba82
AG
31358would be printed by the @value{GDBN} CLI. If @samp{print object}
31359(@pxref{Print Settings, set print object}) is set to @code{on}, the
31360@emph{actual} (derived) type of the object is shown rather than the
31361@emph{declared} one.
0cc7d26f
TT
31362
31363@item thread-id
31364If a variable object is bound to a specific thread, then this is the
5d5658a1 31365thread's global identifier.
0cc7d26f
TT
31366
31367@item has_more
31368For a dynamic varobj, this indicates whether there appear to be any
31369children available. For a non-dynamic varobj, this will be 0.
31370
31371@item dynamic
31372This attribute will be present and have the value @samp{1} if the
31373varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
31374then this attribute will not be present.
31375
31376@item displayhint
31377A dynamic varobj can supply a display hint to the front end. The
31378value comes directly from the Python pretty-printer object's
4c374409 31379@code{display_hint} method. @xref{Pretty Printing API}.
0cc7d26f
TT
31380@end table
31381
31382Typical output will look like this:
922fbb7b
AC
31383
31384@smallexample
0cc7d26f
TT
31385 name="@var{name}",numchild="@var{N}",type="@var{type}",thread-id="@var{M}",
31386 has_more="@var{has_more}"
dcaaae04
NR
31387@end smallexample
31388
a2c02241
NR
31389
31390@subheading The @code{-var-delete} Command
31391@findex -var-delete
922fbb7b
AC
31392
31393@subsubheading Synopsis
31394
31395@smallexample
22d8a470 31396 -var-delete [ -c ] @var{name}
922fbb7b
AC
31397@end smallexample
31398
a2c02241 31399Deletes a previously created variable object and all of its children.
22d8a470 31400With the @samp{-c} option, just deletes the children.
922fbb7b 31401
a2c02241 31402Returns an error if the object @var{name} is not found.
922fbb7b 31403
922fbb7b 31404
a2c02241
NR
31405@subheading The @code{-var-set-format} Command
31406@findex -var-set-format
922fbb7b 31407
a2c02241 31408@subsubheading Synopsis
922fbb7b
AC
31409
31410@smallexample
a2c02241 31411 -var-set-format @var{name} @var{format-spec}
922fbb7b
AC
31412@end smallexample
31413
a2c02241
NR
31414Sets the output format for the value of the object @var{name} to be
31415@var{format-spec}.
31416
de051565 31417@anchor{-var-set-format}
a2c02241
NR
31418The syntax for the @var{format-spec} is as follows:
31419
31420@smallexample
31421 @var{format-spec} @expansion{}
1c35a88f 31422 @{binary | decimal | hexadecimal | octal | natural | zero-hexadecimal@}
a2c02241
NR
31423@end smallexample
31424
c8b2f53c
VP
31425The natural format is the default format choosen automatically
31426based on the variable type (like decimal for an @code{int}, hex
31427for pointers, etc.).
31428
1c35a88f
LM
31429The zero-hexadecimal format has a representation similar to hexadecimal
31430but with padding zeroes to the left of the value. For example, a 32-bit
31431hexadecimal value of 0x1234 would be represented as 0x00001234 in the
31432zero-hexadecimal format.
31433
c8b2f53c
VP
31434For a variable with children, the format is set only on the
31435variable itself, and the children are not affected.
a2c02241
NR
31436
31437@subheading The @code{-var-show-format} Command
31438@findex -var-show-format
922fbb7b
AC
31439
31440@subsubheading Synopsis
31441
31442@smallexample
a2c02241 31443 -var-show-format @var{name}
922fbb7b
AC
31444@end smallexample
31445
a2c02241 31446Returns the format used to display the value of the object @var{name}.
922fbb7b 31447
a2c02241
NR
31448@smallexample
31449 @var{format} @expansion{}
31450 @var{format-spec}
31451@end smallexample
922fbb7b 31452
922fbb7b 31453
a2c02241
NR
31454@subheading The @code{-var-info-num-children} Command
31455@findex -var-info-num-children
31456
31457@subsubheading Synopsis
31458
31459@smallexample
31460 -var-info-num-children @var{name}
31461@end smallexample
31462
31463Returns the number of children of a variable object @var{name}:
31464
31465@smallexample
31466 numchild=@var{n}
31467@end smallexample
31468
0cc7d26f
TT
31469Note that this number is not completely reliable for a dynamic varobj.
31470It will return the current number of children, but more children may
31471be available.
31472
a2c02241
NR
31473
31474@subheading The @code{-var-list-children} Command
31475@findex -var-list-children
31476
31477@subsubheading Synopsis
31478
31479@smallexample
0cc7d26f 31480 -var-list-children [@var{print-values}] @var{name} [@var{from} @var{to}]
a2c02241 31481@end smallexample
b569d230 31482@anchor{-var-list-children}
a2c02241
NR
31483
31484Return a list of the children of the specified variable object and
31485create variable objects for them, if they do not already exist. With
f5011d11 31486a single argument or if @var{print-values} has a value of 0 or
a2c02241
NR
31487@code{--no-values}, print only the names of the variables; if
31488@var{print-values} is 1 or @code{--all-values}, also print their
31489values; and if it is 2 or @code{--simple-values} print the name and
31490value for simple data types and just the name for arrays, structures
31491and unions.
922fbb7b 31492
0cc7d26f
TT
31493@var{from} and @var{to}, if specified, indicate the range of children
31494to report. If @var{from} or @var{to} is less than zero, the range is
31495reset and all children will be reported. Otherwise, children starting
31496at @var{from} (zero-based) and up to and excluding @var{to} will be
31497reported.
31498
31499If a child range is requested, it will only affect the current call to
31500@code{-var-list-children}, but not future calls to @code{-var-update}.
31501For this, you must instead use @code{-var-set-update-range}. The
31502intent of this approach is to enable a front end to implement any
31503update approach it likes; for example, scrolling a view may cause the
31504front end to request more children with @code{-var-list-children}, and
31505then the front end could call @code{-var-set-update-range} with a
31506different range to ensure that future updates are restricted to just
31507the visible items.
31508
b569d230
EZ
31509For each child the following results are returned:
31510
31511@table @var
31512
31513@item name
31514Name of the variable object created for this child.
31515
31516@item exp
31517The expression to be shown to the user by the front end to designate this child.
31518For example this may be the name of a structure member.
31519
0cc7d26f
TT
31520For a dynamic varobj, this value cannot be used to form an
31521expression. There is no way to do this at all with a dynamic varobj.
31522
b569d230
EZ
31523For C/C@t{++} structures there are several pseudo children returned to
31524designate access qualifiers. For these pseudo children @var{exp} is
31525@samp{public}, @samp{private}, or @samp{protected}. In this case the
31526type and value are not present.
31527
0cc7d26f
TT
31528A dynamic varobj will not report the access qualifying
31529pseudo-children, regardless of the language. This information is not
31530available at all with a dynamic varobj.
31531
b569d230 31532@item numchild
0cc7d26f
TT
31533Number of children this child has. For a dynamic varobj, this will be
315340.
b569d230
EZ
31535
31536@item type
8264ba82
AG
31537The type of the child. If @samp{print object}
31538(@pxref{Print Settings, set print object}) is set to @code{on}, the
31539@emph{actual} (derived) type of the object is shown rather than the
31540@emph{declared} one.
b569d230
EZ
31541
31542@item value
31543If values were requested, this is the value.
31544
31545@item thread-id
5d5658a1
PA
31546If this variable object is associated with a thread, this is the
31547thread's global thread id. Otherwise this result is not present.
b569d230
EZ
31548
31549@item frozen
31550If the variable object is frozen, this variable will be present with a value of 1.
c78feb39 31551
9df9dbe0
YQ
31552@item displayhint
31553A dynamic varobj can supply a display hint to the front end. The
31554value comes directly from the Python pretty-printer object's
31555@code{display_hint} method. @xref{Pretty Printing API}.
31556
c78feb39
YQ
31557@item dynamic
31558This attribute will be present and have the value @samp{1} if the
31559varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
31560then this attribute will not be present.
31561
b569d230
EZ
31562@end table
31563
0cc7d26f
TT
31564The result may have its own attributes:
31565
31566@table @samp
31567@item displayhint
31568A dynamic varobj can supply a display hint to the front end. The
31569value comes directly from the Python pretty-printer object's
4c374409 31570@code{display_hint} method. @xref{Pretty Printing API}.
0cc7d26f
TT
31571
31572@item has_more
31573This is an integer attribute which is nonzero if there are children
31574remaining after the end of the selected range.
31575@end table
31576
922fbb7b
AC
31577@subsubheading Example
31578
31579@smallexample
594fe323 31580(gdb)
a2c02241 31581 -var-list-children n
b569d230 31582 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
a2c02241 31583 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
594fe323 31584(gdb)
a2c02241 31585 -var-list-children --all-values n
b569d230 31586 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
a2c02241 31587 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
922fbb7b
AC
31588@end smallexample
31589
922fbb7b 31590
a2c02241
NR
31591@subheading The @code{-var-info-type} Command
31592@findex -var-info-type
922fbb7b 31593
a2c02241
NR
31594@subsubheading Synopsis
31595
31596@smallexample
31597 -var-info-type @var{name}
31598@end smallexample
31599
31600Returns the type of the specified variable @var{name}. The type is
31601returned as a string in the same format as it is output by the
31602@value{GDBN} CLI:
31603
31604@smallexample
31605 type=@var{typename}
31606@end smallexample
31607
31608
31609@subheading The @code{-var-info-expression} Command
31610@findex -var-info-expression
922fbb7b
AC
31611
31612@subsubheading Synopsis
31613
31614@smallexample
a2c02241 31615 -var-info-expression @var{name}
922fbb7b
AC
31616@end smallexample
31617
02142340
VP
31618Returns a string that is suitable for presenting this
31619variable object in user interface. The string is generally
31620not valid expression in the current language, and cannot be evaluated.
31621
31622For example, if @code{a} is an array, and variable object
31623@code{A} was created for @code{a}, then we'll get this output:
922fbb7b 31624
a2c02241 31625@smallexample
02142340
VP
31626(gdb) -var-info-expression A.1
31627^done,lang="C",exp="1"
a2c02241 31628@end smallexample
922fbb7b 31629
a2c02241 31630@noindent
fa4d0c40
YQ
31631Here, the value of @code{lang} is the language name, which can be
31632found in @ref{Supported Languages}.
02142340
VP
31633
31634Note that the output of the @code{-var-list-children} command also
31635includes those expressions, so the @code{-var-info-expression} command
31636is of limited use.
31637
31638@subheading The @code{-var-info-path-expression} Command
31639@findex -var-info-path-expression
31640
31641@subsubheading Synopsis
31642
31643@smallexample
31644 -var-info-path-expression @var{name}
31645@end smallexample
31646
31647Returns an expression that can be evaluated in the current
31648context and will yield the same value that a variable object has.
31649Compare this with the @code{-var-info-expression} command, which
31650result can be used only for UI presentation. Typical use of
31651the @code{-var-info-path-expression} command is creating a
31652watchpoint from a variable object.
31653
0cc7d26f
TT
31654This command is currently not valid for children of a dynamic varobj,
31655and will give an error when invoked on one.
31656
02142340
VP
31657For example, suppose @code{C} is a C@t{++} class, derived from class
31658@code{Base}, and that the @code{Base} class has a member called
31659@code{m_size}. Assume a variable @code{c} is has the type of
31660@code{C} and a variable object @code{C} was created for variable
31661@code{c}. Then, we'll get this output:
31662@smallexample
31663(gdb) -var-info-path-expression C.Base.public.m_size
31664^done,path_expr=((Base)c).m_size)
31665@end smallexample
922fbb7b 31666
a2c02241
NR
31667@subheading The @code{-var-show-attributes} Command
31668@findex -var-show-attributes
922fbb7b 31669
a2c02241 31670@subsubheading Synopsis
922fbb7b 31671
a2c02241
NR
31672@smallexample
31673 -var-show-attributes @var{name}
31674@end smallexample
922fbb7b 31675
a2c02241 31676List attributes of the specified variable object @var{name}:
922fbb7b
AC
31677
31678@smallexample
a2c02241 31679 status=@var{attr} [ ( ,@var{attr} )* ]
922fbb7b
AC
31680@end smallexample
31681
a2c02241
NR
31682@noindent
31683where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
31684
31685@subheading The @code{-var-evaluate-expression} Command
31686@findex -var-evaluate-expression
31687
31688@subsubheading Synopsis
31689
31690@smallexample
de051565 31691 -var-evaluate-expression [-f @var{format-spec}] @var{name}
a2c02241
NR
31692@end smallexample
31693
31694Evaluates the expression that is represented by the specified variable
de051565
MK
31695object and returns its value as a string. The format of the string
31696can be specified with the @samp{-f} option. The possible values of
31697this option are the same as for @code{-var-set-format}
31698(@pxref{-var-set-format}). If the @samp{-f} option is not specified,
31699the current display format will be used. The current display format
31700can be changed using the @code{-var-set-format} command.
a2c02241
NR
31701
31702@smallexample
31703 value=@var{value}
31704@end smallexample
31705
31706Note that one must invoke @code{-var-list-children} for a variable
31707before the value of a child variable can be evaluated.
31708
31709@subheading The @code{-var-assign} Command
31710@findex -var-assign
31711
31712@subsubheading Synopsis
31713
31714@smallexample
31715 -var-assign @var{name} @var{expression}
31716@end smallexample
31717
31718Assigns the value of @var{expression} to the variable object specified
31719by @var{name}. The object must be @samp{editable}. If the variable's
31720value is altered by the assign, the variable will show up in any
31721subsequent @code{-var-update} list.
31722
31723@subsubheading Example
922fbb7b
AC
31724
31725@smallexample
594fe323 31726(gdb)
a2c02241
NR
31727-var-assign var1 3
31728^done,value="3"
594fe323 31729(gdb)
a2c02241
NR
31730-var-update *
31731^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
594fe323 31732(gdb)
922fbb7b
AC
31733@end smallexample
31734
a2c02241
NR
31735@subheading The @code{-var-update} Command
31736@findex -var-update
31737
31738@subsubheading Synopsis
31739
31740@smallexample
31741 -var-update [@var{print-values}] @{@var{name} | "*"@}
31742@end smallexample
31743
c8b2f53c
VP
31744Reevaluate the expressions corresponding to the variable object
31745@var{name} and all its direct and indirect children, and return the
36ece8b3
NR
31746list of variable objects whose values have changed; @var{name} must
31747be a root variable object. Here, ``changed'' means that the result of
31748@code{-var-evaluate-expression} before and after the
31749@code{-var-update} is different. If @samp{*} is used as the variable
9f708cb2
VP
31750object names, all existing variable objects are updated, except
31751for frozen ones (@pxref{-var-set-frozen}). The option
36ece8b3 31752@var{print-values} determines whether both names and values, or just
de051565 31753names are printed. The possible values of this option are the same
36ece8b3
NR
31754as for @code{-var-list-children} (@pxref{-var-list-children}). It is
31755recommended to use the @samp{--all-values} option, to reduce the
31756number of MI commands needed on each program stop.
c8b2f53c 31757
c3b108f7
VP
31758With the @samp{*} parameter, if a variable object is bound to a
31759currently running thread, it will not be updated, without any
31760diagnostic.
a2c02241 31761
0cc7d26f
TT
31762If @code{-var-set-update-range} was previously used on a varobj, then
31763only the selected range of children will be reported.
922fbb7b 31764
0cc7d26f
TT
31765@code{-var-update} reports all the changed varobjs in a tuple named
31766@samp{changelist}.
31767
31768Each item in the change list is itself a tuple holding:
31769
31770@table @samp
31771@item name
31772The name of the varobj.
31773
31774@item value
31775If values were requested for this update, then this field will be
31776present and will hold the value of the varobj.
922fbb7b 31777
0cc7d26f 31778@item in_scope
9f708cb2 31779@anchor{-var-update}
0cc7d26f 31780This field is a string which may take one of three values:
36ece8b3
NR
31781
31782@table @code
31783@item "true"
31784The variable object's current value is valid.
31785
31786@item "false"
31787The variable object does not currently hold a valid value but it may
31788hold one in the future if its associated expression comes back into
31789scope.
31790
31791@item "invalid"
31792The variable object no longer holds a valid value.
31793This can occur when the executable file being debugged has changed,
31794either through recompilation or by using the @value{GDBN} @code{file}
31795command. The front end should normally choose to delete these variable
31796objects.
31797@end table
31798
31799In the future new values may be added to this list so the front should
31800be prepared for this possibility. @xref{GDB/MI Development and Front Ends, ,@sc{GDB/MI} Development and Front Ends}.
31801
0cc7d26f
TT
31802@item type_changed
31803This is only present if the varobj is still valid. If the type
31804changed, then this will be the string @samp{true}; otherwise it will
31805be @samp{false}.
31806
7191c139
JB
31807When a varobj's type changes, its children are also likely to have
31808become incorrect. Therefore, the varobj's children are automatically
31809deleted when this attribute is @samp{true}. Also, the varobj's update
31810range, when set using the @code{-var-set-update-range} command, is
31811unset.
31812
0cc7d26f
TT
31813@item new_type
31814If the varobj's type changed, then this field will be present and will
31815hold the new type.
31816
31817@item new_num_children
31818For a dynamic varobj, if the number of children changed, or if the
31819type changed, this will be the new number of children.
31820
31821The @samp{numchild} field in other varobj responses is generally not
31822valid for a dynamic varobj -- it will show the number of children that
31823@value{GDBN} knows about, but because dynamic varobjs lazily
31824instantiate their children, this will not reflect the number of
31825children which may be available.
31826
31827The @samp{new_num_children} attribute only reports changes to the
31828number of children known by @value{GDBN}. This is the only way to
31829detect whether an update has removed children (which necessarily can
31830only happen at the end of the update range).
31831
31832@item displayhint
31833The display hint, if any.
31834
31835@item has_more
31836This is an integer value, which will be 1 if there are more children
31837available outside the varobj's update range.
31838
31839@item dynamic
31840This attribute will be present and have the value @samp{1} if the
31841varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
31842then this attribute will not be present.
31843
31844@item new_children
31845If new children were added to a dynamic varobj within the selected
31846update range (as set by @code{-var-set-update-range}), then they will
31847be listed in this attribute.
31848@end table
31849
31850@subsubheading Example
31851
31852@smallexample
31853(gdb)
31854-var-assign var1 3
31855^done,value="3"
31856(gdb)
31857-var-update --all-values var1
31858^done,changelist=[@{name="var1",value="3",in_scope="true",
31859type_changed="false"@}]
31860(gdb)
31861@end smallexample
31862
25d5ea92
VP
31863@subheading The @code{-var-set-frozen} Command
31864@findex -var-set-frozen
9f708cb2 31865@anchor{-var-set-frozen}
25d5ea92
VP
31866
31867@subsubheading Synopsis
31868
31869@smallexample
9f708cb2 31870 -var-set-frozen @var{name} @var{flag}
25d5ea92
VP
31871@end smallexample
31872
9f708cb2 31873Set the frozenness flag on the variable object @var{name}. The
25d5ea92 31874@var{flag} parameter should be either @samp{1} to make the variable
9f708cb2 31875frozen or @samp{0} to make it unfrozen. If a variable object is
25d5ea92 31876frozen, then neither itself, nor any of its children, are
9f708cb2 31877implicitly updated by @code{-var-update} of
25d5ea92
VP
31878a parent variable or by @code{-var-update *}. Only
31879@code{-var-update} of the variable itself will update its value and
31880values of its children. After a variable object is unfrozen, it is
31881implicitly updated by all subsequent @code{-var-update} operations.
31882Unfreezing a variable does not update it, only subsequent
31883@code{-var-update} does.
31884
31885@subsubheading Example
31886
31887@smallexample
31888(gdb)
31889-var-set-frozen V 1
31890^done
31891(gdb)
31892@end smallexample
31893
0cc7d26f
TT
31894@subheading The @code{-var-set-update-range} command
31895@findex -var-set-update-range
31896@anchor{-var-set-update-range}
31897
31898@subsubheading Synopsis
31899
31900@smallexample
31901 -var-set-update-range @var{name} @var{from} @var{to}
31902@end smallexample
31903
31904Set the range of children to be returned by future invocations of
31905@code{-var-update}.
31906
31907@var{from} and @var{to} indicate the range of children to report. If
31908@var{from} or @var{to} is less than zero, the range is reset and all
31909children will be reported. Otherwise, children starting at @var{from}
31910(zero-based) and up to and excluding @var{to} will be reported.
31911
31912@subsubheading Example
31913
31914@smallexample
31915(gdb)
31916-var-set-update-range V 1 2
31917^done
31918@end smallexample
31919
b6313243
TT
31920@subheading The @code{-var-set-visualizer} command
31921@findex -var-set-visualizer
31922@anchor{-var-set-visualizer}
31923
31924@subsubheading Synopsis
31925
31926@smallexample
31927 -var-set-visualizer @var{name} @var{visualizer}
31928@end smallexample
31929
31930Set a visualizer for the variable object @var{name}.
31931
31932@var{visualizer} is the visualizer to use. The special value
31933@samp{None} means to disable any visualizer in use.
31934
31935If not @samp{None}, @var{visualizer} must be a Python expression.
31936This expression must evaluate to a callable object which accepts a
31937single argument. @value{GDBN} will call this object with the value of
31938the varobj @var{name} as an argument (this is done so that the same
31939Python pretty-printing code can be used for both the CLI and MI).
31940When called, this object must return an object which conforms to the
4c374409 31941pretty-printing interface (@pxref{Pretty Printing API}).
b6313243
TT
31942
31943The pre-defined function @code{gdb.default_visualizer} may be used to
31944select a visualizer by following the built-in process
31945(@pxref{Selecting Pretty-Printers}). This is done automatically when
31946a varobj is created, and so ordinarily is not needed.
31947
31948This feature is only available if Python support is enabled. The MI
d192b373 31949command @code{-list-features} (@pxref{GDB/MI Support Commands})
b6313243
TT
31950can be used to check this.
31951
31952@subsubheading Example
31953
31954Resetting the visualizer:
31955
31956@smallexample
31957(gdb)
31958-var-set-visualizer V None
31959^done
31960@end smallexample
31961
31962Reselecting the default (type-based) visualizer:
31963
31964@smallexample
31965(gdb)
31966-var-set-visualizer V gdb.default_visualizer
31967^done
31968@end smallexample
31969
31970Suppose @code{SomeClass} is a visualizer class. A lambda expression
31971can be used to instantiate this class for a varobj:
31972
31973@smallexample
31974(gdb)
31975-var-set-visualizer V "lambda val: SomeClass()"
31976^done
31977@end smallexample
25d5ea92 31978
a2c02241
NR
31979@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31980@node GDB/MI Data Manipulation
31981@section @sc{gdb/mi} Data Manipulation
922fbb7b 31982
a2c02241
NR
31983@cindex data manipulation, in @sc{gdb/mi}
31984@cindex @sc{gdb/mi}, data manipulation
31985This section describes the @sc{gdb/mi} commands that manipulate data:
31986examine memory and registers, evaluate expressions, etc.
31987
a86c90e6
SM
31988For details about what an addressable memory unit is,
31989@pxref{addressable memory unit}.
31990
a2c02241
NR
31991@c REMOVED FROM THE INTERFACE.
31992@c @subheading -data-assign
31993@c Change the value of a program variable. Plenty of side effects.
79a6e687 31994@c @subsubheading GDB Command
a2c02241
NR
31995@c set variable
31996@c @subsubheading Example
31997@c N.A.
31998
31999@subheading The @code{-data-disassemble} Command
32000@findex -data-disassemble
922fbb7b
AC
32001
32002@subsubheading Synopsis
32003
32004@smallexample
a2c02241
NR
32005 -data-disassemble
32006 [ -s @var{start-addr} -e @var{end-addr} ]
26fb3983 32007 | [ -a @var{addr} ]
a2c02241
NR
32008 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
32009 -- @var{mode}
922fbb7b
AC
32010@end smallexample
32011
a2c02241
NR
32012@noindent
32013Where:
32014
32015@table @samp
32016@item @var{start-addr}
32017is the beginning address (or @code{$pc})
32018@item @var{end-addr}
32019is the end address
26fb3983
JV
32020@item @var{addr}
32021is an address anywhere within (or the name of) the function to
32022disassemble. If an address is specified, the whole function
32023surrounding that address will be disassembled. If a name is
32024specified, the whole function with that name will be disassembled.
a2c02241
NR
32025@item @var{filename}
32026is the name of the file to disassemble
32027@item @var{linenum}
32028is the line number to disassemble around
32029@item @var{lines}
d3e8051b 32030is the number of disassembly lines to be produced. If it is -1,
a2c02241
NR
32031the whole function will be disassembled, in case no @var{end-addr} is
32032specified. If @var{end-addr} is specified as a non-zero value, and
32033@var{lines} is lower than the number of disassembly lines between
32034@var{start-addr} and @var{end-addr}, only @var{lines} lines are
32035displayed; if @var{lines} is higher than the number of lines between
32036@var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
32037are displayed.
32038@item @var{mode}
6ff0ba5f
DE
32039is one of:
32040@itemize @bullet
32041@item 0 disassembly only
32042@item 1 mixed source and disassembly (deprecated)
32043@item 2 disassembly with raw opcodes
32044@item 3 mixed source and disassembly with raw opcodes (deprecated)
32045@item 4 mixed source and disassembly
32046@item 5 mixed source and disassembly with raw opcodes
32047@end itemize
32048
32049Modes 1 and 3 are deprecated. The output is ``source centric''
32050which hasn't proved useful in practice.
32051@xref{Machine Code}, for a discussion of the difference between
32052@code{/m} and @code{/s} output of the @code{disassemble} command.
a2c02241
NR
32053@end table
32054
32055@subsubheading Result
32056
ed8a1c2d
AB
32057The result of the @code{-data-disassemble} command will be a list named
32058@samp{asm_insns}, the contents of this list depend on the @var{mode}
32059used with the @code{-data-disassemble} command.
a2c02241 32060
ed8a1c2d
AB
32061For modes 0 and 2 the @samp{asm_insns} list contains tuples with the
32062following fields:
32063
32064@table @code
32065@item address
32066The address at which this instruction was disassembled.
32067
32068@item func-name
32069The name of the function this instruction is within.
32070
32071@item offset
32072The decimal offset in bytes from the start of @samp{func-name}.
32073
32074@item inst
32075The text disassembly for this @samp{address}.
32076
32077@item opcodes
6ff0ba5f 32078This field is only present for modes 2, 3 and 5. This contains the raw opcode
ed8a1c2d
AB
32079bytes for the @samp{inst} field.
32080
32081@end table
32082
6ff0ba5f 32083For modes 1, 3, 4 and 5 the @samp{asm_insns} list contains tuples named
ed8a1c2d 32084@samp{src_and_asm_line}, each of which has the following fields:
a2c02241 32085
ed8a1c2d
AB
32086@table @code
32087@item line
32088The line number within @samp{file}.
32089
32090@item file
32091The file name from the compilation unit. This might be an absolute
32092file name or a relative file name depending on the compile command
32093used.
32094
32095@item fullname
f35a17b5
JK
32096Absolute file name of @samp{file}. It is converted to a canonical form
32097using the source file search path
32098(@pxref{Source Path, ,Specifying Source Directories})
32099and after resolving all the symbolic links.
32100
32101If the source file is not found this field will contain the path as
32102present in the debug information.
ed8a1c2d
AB
32103
32104@item line_asm_insn
32105This is a list of tuples containing the disassembly for @samp{line} in
32106@samp{file}. The fields of each tuple are the same as for
32107@code{-data-disassemble} in @var{mode} 0 and 2, so @samp{address},
32108@samp{func-name}, @samp{offset}, @samp{inst}, and optionally
32109@samp{opcodes}.
32110
32111@end table
32112
32113Note that whatever included in the @samp{inst} field, is not
32114manipulated directly by @sc{gdb/mi}, i.e., it is not possible to
32115adjust its format.
922fbb7b
AC
32116
32117@subsubheading @value{GDBN} Command
32118
ed8a1c2d 32119The corresponding @value{GDBN} command is @samp{disassemble}.
922fbb7b
AC
32120
32121@subsubheading Example
32122
a2c02241
NR
32123Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
32124
922fbb7b 32125@smallexample
594fe323 32126(gdb)
a2c02241
NR
32127-data-disassemble -s $pc -e "$pc + 20" -- 0
32128^done,
32129asm_insns=[
32130@{address="0x000107c0",func-name="main",offset="4",
32131inst="mov 2, %o0"@},
32132@{address="0x000107c4",func-name="main",offset="8",
32133inst="sethi %hi(0x11800), %o2"@},
32134@{address="0x000107c8",func-name="main",offset="12",
32135inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
32136@{address="0x000107cc",func-name="main",offset="16",
32137inst="sethi %hi(0x11800), %o2"@},
32138@{address="0x000107d0",func-name="main",offset="20",
32139inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
594fe323 32140(gdb)
a2c02241
NR
32141@end smallexample
32142
32143Disassemble the whole @code{main} function. Line 32 is part of
32144@code{main}.
32145
32146@smallexample
32147-data-disassemble -f basics.c -l 32 -- 0
32148^done,asm_insns=[
32149@{address="0x000107bc",func-name="main",offset="0",
32150inst="save %sp, -112, %sp"@},
32151@{address="0x000107c0",func-name="main",offset="4",
32152inst="mov 2, %o0"@},
32153@{address="0x000107c4",func-name="main",offset="8",
32154inst="sethi %hi(0x11800), %o2"@},
32155[@dots{}]
32156@{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
32157@{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
594fe323 32158(gdb)
922fbb7b
AC
32159@end smallexample
32160
a2c02241 32161Disassemble 3 instructions from the start of @code{main}:
922fbb7b 32162
a2c02241 32163@smallexample
594fe323 32164(gdb)
a2c02241
NR
32165-data-disassemble -f basics.c -l 32 -n 3 -- 0
32166^done,asm_insns=[
32167@{address="0x000107bc",func-name="main",offset="0",
32168inst="save %sp, -112, %sp"@},
32169@{address="0x000107c0",func-name="main",offset="4",
32170inst="mov 2, %o0"@},
32171@{address="0x000107c4",func-name="main",offset="8",
32172inst="sethi %hi(0x11800), %o2"@}]
594fe323 32173(gdb)
a2c02241
NR
32174@end smallexample
32175
32176Disassemble 3 instructions from the start of @code{main} in mixed mode:
32177
32178@smallexample
594fe323 32179(gdb)
a2c02241
NR
32180-data-disassemble -f basics.c -l 32 -n 3 -- 1
32181^done,asm_insns=[
32182src_and_asm_line=@{line="31",
ed8a1c2d
AB
32183file="../../../src/gdb/testsuite/gdb.mi/basics.c",
32184fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
32185line_asm_insn=[@{address="0x000107bc",
32186func-name="main",offset="0",inst="save %sp, -112, %sp"@}]@},
a2c02241 32187src_and_asm_line=@{line="32",
ed8a1c2d
AB
32188file="../../../src/gdb/testsuite/gdb.mi/basics.c",
32189fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
32190line_asm_insn=[@{address="0x000107c0",
32191func-name="main",offset="4",inst="mov 2, %o0"@},
a2c02241
NR
32192@{address="0x000107c4",func-name="main",offset="8",
32193inst="sethi %hi(0x11800), %o2"@}]@}]
594fe323 32194(gdb)
a2c02241
NR
32195@end smallexample
32196
32197
32198@subheading The @code{-data-evaluate-expression} Command
32199@findex -data-evaluate-expression
922fbb7b
AC
32200
32201@subsubheading Synopsis
32202
32203@smallexample
a2c02241 32204 -data-evaluate-expression @var{expr}
922fbb7b
AC
32205@end smallexample
32206
a2c02241
NR
32207Evaluate @var{expr} as an expression. The expression could contain an
32208inferior function call. The function call will execute synchronously.
32209If the expression contains spaces, it must be enclosed in double quotes.
922fbb7b
AC
32210
32211@subsubheading @value{GDBN} Command
32212
a2c02241
NR
32213The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
32214@samp{call}. In @code{gdbtk} only, there's a corresponding
32215@samp{gdb_eval} command.
922fbb7b
AC
32216
32217@subsubheading Example
32218
a2c02241
NR
32219In the following example, the numbers that precede the commands are the
32220@dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
32221Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
32222output.
32223
922fbb7b 32224@smallexample
a2c02241
NR
32225211-data-evaluate-expression A
32226211^done,value="1"
594fe323 32227(gdb)
a2c02241
NR
32228311-data-evaluate-expression &A
32229311^done,value="0xefffeb7c"
594fe323 32230(gdb)
a2c02241
NR
32231411-data-evaluate-expression A+3
32232411^done,value="4"
594fe323 32233(gdb)
a2c02241
NR
32234511-data-evaluate-expression "A + 3"
32235511^done,value="4"
594fe323 32236(gdb)
a2c02241 32237@end smallexample
922fbb7b
AC
32238
32239
a2c02241
NR
32240@subheading The @code{-data-list-changed-registers} Command
32241@findex -data-list-changed-registers
922fbb7b
AC
32242
32243@subsubheading Synopsis
32244
32245@smallexample
a2c02241 32246 -data-list-changed-registers
922fbb7b
AC
32247@end smallexample
32248
a2c02241 32249Display a list of the registers that have changed.
922fbb7b
AC
32250
32251@subsubheading @value{GDBN} Command
32252
a2c02241
NR
32253@value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
32254has the corresponding command @samp{gdb_changed_register_list}.
922fbb7b
AC
32255
32256@subsubheading Example
922fbb7b 32257
a2c02241 32258On a PPC MBX board:
922fbb7b
AC
32259
32260@smallexample
594fe323 32261(gdb)
a2c02241
NR
32262-exec-continue
32263^running
922fbb7b 32264
594fe323 32265(gdb)
a47ec5fe
AR
32266*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",frame=@{
32267func="main",args=[],file="try.c",fullname="/home/foo/bar/try.c",
6d52907e 32268line="5",arch="powerpc"@}
594fe323 32269(gdb)
a2c02241
NR
32270-data-list-changed-registers
32271^done,changed-registers=["0","1","2","4","5","6","7","8","9",
32272"10","11","13","14","15","16","17","18","19","20","21","22","23",
32273"24","25","26","27","28","30","31","64","65","66","67","69"]
594fe323 32274(gdb)
a2c02241 32275@end smallexample
922fbb7b
AC
32276
32277
a2c02241
NR
32278@subheading The @code{-data-list-register-names} Command
32279@findex -data-list-register-names
922fbb7b
AC
32280
32281@subsubheading Synopsis
32282
32283@smallexample
a2c02241 32284 -data-list-register-names [ ( @var{regno} )+ ]
922fbb7b
AC
32285@end smallexample
32286
a2c02241
NR
32287Show a list of register names for the current target. If no arguments
32288are given, it shows a list of the names of all the registers. If
32289integer numbers are given as arguments, it will print a list of the
32290names of the registers corresponding to the arguments. To ensure
32291consistency between a register name and its number, the output list may
32292include empty register names.
922fbb7b
AC
32293
32294@subsubheading @value{GDBN} Command
32295
a2c02241
NR
32296@value{GDBN} does not have a command which corresponds to
32297@samp{-data-list-register-names}. In @code{gdbtk} there is a
32298corresponding command @samp{gdb_regnames}.
922fbb7b
AC
32299
32300@subsubheading Example
922fbb7b 32301
a2c02241
NR
32302For the PPC MBX board:
32303@smallexample
594fe323 32304(gdb)
a2c02241
NR
32305-data-list-register-names
32306^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
32307"r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
32308"r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
32309"r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
32310"f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
32311"f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
32312"", "pc","ps","cr","lr","ctr","xer"]
594fe323 32313(gdb)
a2c02241
NR
32314-data-list-register-names 1 2 3
32315^done,register-names=["r1","r2","r3"]
594fe323 32316(gdb)
a2c02241 32317@end smallexample
922fbb7b 32318
a2c02241
NR
32319@subheading The @code{-data-list-register-values} Command
32320@findex -data-list-register-values
922fbb7b
AC
32321
32322@subsubheading Synopsis
32323
32324@smallexample
c898adb7
YQ
32325 -data-list-register-values
32326 [ @code{--skip-unavailable} ] @var{fmt} [ ( @var{regno} )*]
922fbb7b
AC
32327@end smallexample
32328
697aa1b7
EZ
32329Display the registers' contents. The format according to which the
32330registers' contents are to be returned is given by @var{fmt}, followed
32331by an optional list of numbers specifying the registers to display. A
32332missing list of numbers indicates that the contents of all the
32333registers must be returned. The @code{--skip-unavailable} option
32334indicates that only the available registers are to be returned.
a2c02241
NR
32335
32336Allowed formats for @var{fmt} are:
32337
32338@table @code
32339@item x
32340Hexadecimal
32341@item o
32342Octal
32343@item t
32344Binary
32345@item d
32346Decimal
32347@item r
32348Raw
32349@item N
32350Natural
32351@end table
922fbb7b
AC
32352
32353@subsubheading @value{GDBN} Command
32354
a2c02241
NR
32355The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
32356all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
922fbb7b
AC
32357
32358@subsubheading Example
922fbb7b 32359
a2c02241
NR
32360For a PPC MBX board (note: line breaks are for readability only, they
32361don't appear in the actual output):
32362
32363@smallexample
594fe323 32364(gdb)
a2c02241
NR
32365-data-list-register-values r 64 65
32366^done,register-values=[@{number="64",value="0xfe00a300"@},
32367@{number="65",value="0x00029002"@}]
594fe323 32368(gdb)
a2c02241
NR
32369-data-list-register-values x
32370^done,register-values=[@{number="0",value="0xfe0043c8"@},
32371@{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
32372@{number="3",value="0x0"@},@{number="4",value="0xa"@},
32373@{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
32374@{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
32375@{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
32376@{number="11",value="0x1"@},@{number="12",value="0x0"@},
32377@{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
32378@{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
32379@{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
32380@{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
32381@{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
32382@{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
32383@{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
32384@{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
32385@{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
32386@{number="31",value="0x0"@},@{number="32",value="0x0"@},
32387@{number="33",value="0x0"@},@{number="34",value="0x0"@},
32388@{number="35",value="0x0"@},@{number="36",value="0x0"@},
32389@{number="37",value="0x0"@},@{number="38",value="0x0"@},
32390@{number="39",value="0x0"@},@{number="40",value="0x0"@},
32391@{number="41",value="0x0"@},@{number="42",value="0x0"@},
32392@{number="43",value="0x0"@},@{number="44",value="0x0"@},
32393@{number="45",value="0x0"@},@{number="46",value="0x0"@},
32394@{number="47",value="0x0"@},@{number="48",value="0x0"@},
32395@{number="49",value="0x0"@},@{number="50",value="0x0"@},
32396@{number="51",value="0x0"@},@{number="52",value="0x0"@},
32397@{number="53",value="0x0"@},@{number="54",value="0x0"@},
32398@{number="55",value="0x0"@},@{number="56",value="0x0"@},
32399@{number="57",value="0x0"@},@{number="58",value="0x0"@},
32400@{number="59",value="0x0"@},@{number="60",value="0x0"@},
32401@{number="61",value="0x0"@},@{number="62",value="0x0"@},
32402@{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
32403@{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
32404@{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
32405@{number="69",value="0x20002b03"@}]
594fe323 32406(gdb)
a2c02241 32407@end smallexample
922fbb7b 32408
a2c02241
NR
32409
32410@subheading The @code{-data-read-memory} Command
32411@findex -data-read-memory
922fbb7b 32412
8dedea02
VP
32413This command is deprecated, use @code{-data-read-memory-bytes} instead.
32414
922fbb7b
AC
32415@subsubheading Synopsis
32416
32417@smallexample
a2c02241
NR
32418 -data-read-memory [ -o @var{byte-offset} ]
32419 @var{address} @var{word-format} @var{word-size}
32420 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
922fbb7b
AC
32421@end smallexample
32422
a2c02241
NR
32423@noindent
32424where:
922fbb7b 32425
a2c02241
NR
32426@table @samp
32427@item @var{address}
32428An expression specifying the address of the first memory word to be
32429read. Complex expressions containing embedded white space should be
32430quoted using the C convention.
922fbb7b 32431
a2c02241
NR
32432@item @var{word-format}
32433The format to be used to print the memory words. The notation is the
32434same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
79a6e687 32435,Output Formats}).
922fbb7b 32436
a2c02241
NR
32437@item @var{word-size}
32438The size of each memory word in bytes.
922fbb7b 32439
a2c02241
NR
32440@item @var{nr-rows}
32441The number of rows in the output table.
922fbb7b 32442
a2c02241
NR
32443@item @var{nr-cols}
32444The number of columns in the output table.
922fbb7b 32445
a2c02241
NR
32446@item @var{aschar}
32447If present, indicates that each row should include an @sc{ascii} dump. The
32448value of @var{aschar} is used as a padding character when a byte is not a
32449member of the printable @sc{ascii} character set (printable @sc{ascii}
32450characters are those whose code is between 32 and 126, inclusively).
922fbb7b 32451
a2c02241
NR
32452@item @var{byte-offset}
32453An offset to add to the @var{address} before fetching memory.
32454@end table
922fbb7b 32455
a2c02241
NR
32456This command displays memory contents as a table of @var{nr-rows} by
32457@var{nr-cols} words, each word being @var{word-size} bytes. In total,
32458@code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
32459(returned as @samp{total-bytes}). Should less than the requested number
32460of bytes be returned by the target, the missing words are identified
32461using @samp{N/A}. The number of bytes read from the target is returned
32462in @samp{nr-bytes} and the starting address used to read memory in
32463@samp{addr}.
32464
32465The address of the next/previous row or page is available in
32466@samp{next-row} and @samp{prev-row}, @samp{next-page} and
32467@samp{prev-page}.
922fbb7b
AC
32468
32469@subsubheading @value{GDBN} Command
32470
a2c02241
NR
32471The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
32472@samp{gdb_get_mem} memory read command.
922fbb7b
AC
32473
32474@subsubheading Example
32e7087d 32475
a2c02241
NR
32476Read six bytes of memory starting at @code{bytes+6} but then offset by
32477@code{-6} bytes. Format as three rows of two columns. One byte per
32478word. Display each word in hex.
32e7087d
JB
32479
32480@smallexample
594fe323 32481(gdb)
a2c02241
NR
324829-data-read-memory -o -6 -- bytes+6 x 1 3 2
324839^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
32484next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
32485prev-page="0x0000138a",memory=[
32486@{addr="0x00001390",data=["0x00","0x01"]@},
32487@{addr="0x00001392",data=["0x02","0x03"]@},
32488@{addr="0x00001394",data=["0x04","0x05"]@}]
594fe323 32489(gdb)
32e7087d
JB
32490@end smallexample
32491
a2c02241
NR
32492Read two bytes of memory starting at address @code{shorts + 64} and
32493display as a single word formatted in decimal.
32e7087d 32494
32e7087d 32495@smallexample
594fe323 32496(gdb)
a2c02241
NR
324975-data-read-memory shorts+64 d 2 1 1
324985^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
32499next-row="0x00001512",prev-row="0x0000150e",
32500next-page="0x00001512",prev-page="0x0000150e",memory=[
32501@{addr="0x00001510",data=["128"]@}]
594fe323 32502(gdb)
32e7087d
JB
32503@end smallexample
32504
a2c02241
NR
32505Read thirty two bytes of memory starting at @code{bytes+16} and format
32506as eight rows of four columns. Include a string encoding with @samp{x}
32507used as the non-printable character.
922fbb7b
AC
32508
32509@smallexample
594fe323 32510(gdb)
a2c02241
NR
325114-data-read-memory bytes+16 x 1 8 4 x
325124^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
32513next-row="0x000013c0",prev-row="0x0000139c",
32514next-page="0x000013c0",prev-page="0x00001380",memory=[
32515@{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
32516@{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
32517@{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
32518@{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
32519@{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
32520@{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
32521@{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
32522@{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
594fe323 32523(gdb)
922fbb7b
AC
32524@end smallexample
32525
8dedea02
VP
32526@subheading The @code{-data-read-memory-bytes} Command
32527@findex -data-read-memory-bytes
32528
32529@subsubheading Synopsis
32530
32531@smallexample
a86c90e6 32532 -data-read-memory-bytes [ -o @var{offset} ]
8dedea02
VP
32533 @var{address} @var{count}
32534@end smallexample
32535
32536@noindent
32537where:
32538
32539@table @samp
32540@item @var{address}
a86c90e6
SM
32541An expression specifying the address of the first addressable memory unit
32542to be read. Complex expressions containing embedded white space should be
8dedea02
VP
32543quoted using the C convention.
32544
32545@item @var{count}
a86c90e6
SM
32546The number of addressable memory units to read. This should be an integer
32547literal.
8dedea02 32548
a86c90e6
SM
32549@item @var{offset}
32550The offset relative to @var{address} at which to start reading. This
32551should be an integer literal. This option is provided so that a frontend
32552is not required to first evaluate address and then perform address
32553arithmetics itself.
8dedea02
VP
32554
32555@end table
32556
32557This command attempts to read all accessible memory regions in the
32558specified range. First, all regions marked as unreadable in the memory
32559map (if one is defined) will be skipped. @xref{Memory Region
32560Attributes}. Second, @value{GDBN} will attempt to read the remaining
32561regions. For each one, if reading full region results in an errors,
32562@value{GDBN} will try to read a subset of the region.
32563
a86c90e6
SM
32564In general, every single memory unit in the region may be readable or not,
32565and the only way to read every readable unit is to try a read at
8dedea02 32566every address, which is not practical. Therefore, @value{GDBN} will
a86c90e6 32567attempt to read all accessible memory units at either beginning or the end
8dedea02
VP
32568of the region, using a binary division scheme. This heuristic works
32569well for reading accross a memory map boundary. Note that if a region
32570has a readable range that is neither at the beginning or the end,
32571@value{GDBN} will not read it.
32572
32573The result record (@pxref{GDB/MI Result Records}) that is output of
32574the command includes a field named @samp{memory} whose content is a
32575list of tuples. Each tuple represent a successfully read memory block
32576and has the following fields:
32577
32578@table @code
32579@item begin
32580The start address of the memory block, as hexadecimal literal.
32581
32582@item end
32583The end address of the memory block, as hexadecimal literal.
32584
32585@item offset
32586The offset of the memory block, as hexadecimal literal, relative to
32587the start address passed to @code{-data-read-memory-bytes}.
32588
32589@item contents
32590The contents of the memory block, in hex.
32591
32592@end table
32593
32594
32595
32596@subsubheading @value{GDBN} Command
32597
32598The corresponding @value{GDBN} command is @samp{x}.
32599
32600@subsubheading Example
32601
32602@smallexample
32603(gdb)
32604-data-read-memory-bytes &a 10
32605^done,memory=[@{begin="0xbffff154",offset="0x00000000",
32606 end="0xbffff15e",
32607 contents="01000000020000000300"@}]
32608(gdb)
32609@end smallexample
32610
32611
32612@subheading The @code{-data-write-memory-bytes} Command
32613@findex -data-write-memory-bytes
32614
32615@subsubheading Synopsis
32616
32617@smallexample
32618 -data-write-memory-bytes @var{address} @var{contents}
62747a60 32619 -data-write-memory-bytes @var{address} @var{contents} @r{[}@var{count}@r{]}
8dedea02
VP
32620@end smallexample
32621
32622@noindent
32623where:
32624
32625@table @samp
32626@item @var{address}
a86c90e6
SM
32627An expression specifying the address of the first addressable memory unit
32628to be written. Complex expressions containing embedded white space should
32629be quoted using the C convention.
8dedea02
VP
32630
32631@item @var{contents}
a86c90e6
SM
32632The hex-encoded data to write. It is an error if @var{contents} does
32633not represent an integral number of addressable memory units.
8dedea02 32634
62747a60 32635@item @var{count}
a86c90e6
SM
32636Optional argument indicating the number of addressable memory units to be
32637written. If @var{count} is greater than @var{contents}' length,
32638@value{GDBN} will repeatedly write @var{contents} until it fills
32639@var{count} memory units.
62747a60 32640
8dedea02
VP
32641@end table
32642
32643@subsubheading @value{GDBN} Command
32644
32645There's no corresponding @value{GDBN} command.
32646
32647@subsubheading Example
32648
32649@smallexample
32650(gdb)
32651-data-write-memory-bytes &a "aabbccdd"
32652^done
32653(gdb)
32654@end smallexample
32655
62747a60
TT
32656@smallexample
32657(gdb)
32658-data-write-memory-bytes &a "aabbccdd" 16e
32659^done
32660(gdb)
32661@end smallexample
8dedea02 32662
a2c02241
NR
32663@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32664@node GDB/MI Tracepoint Commands
32665@section @sc{gdb/mi} Tracepoint Commands
922fbb7b 32666
18148017
VP
32667The commands defined in this section implement MI support for
32668tracepoints. For detailed introduction, see @ref{Tracepoints}.
32669
32670@subheading The @code{-trace-find} Command
32671@findex -trace-find
32672
32673@subsubheading Synopsis
32674
32675@smallexample
32676 -trace-find @var{mode} [@var{parameters}@dots{}]
32677@end smallexample
32678
32679Find a trace frame using criteria defined by @var{mode} and
32680@var{parameters}. The following table lists permissible
32681modes and their parameters. For details of operation, see @ref{tfind}.
32682
32683@table @samp
32684
32685@item none
32686No parameters are required. Stops examining trace frames.
32687
32688@item frame-number
32689An integer is required as parameter. Selects tracepoint frame with
32690that index.
32691
32692@item tracepoint-number
32693An integer is required as parameter. Finds next
32694trace frame that corresponds to tracepoint with the specified number.
32695
32696@item pc
32697An address is required as parameter. Finds
32698next trace frame that corresponds to any tracepoint at the specified
32699address.
32700
32701@item pc-inside-range
32702Two addresses are required as parameters. Finds next trace
32703frame that corresponds to a tracepoint at an address inside the
32704specified range. Both bounds are considered to be inside the range.
32705
32706@item pc-outside-range
32707Two addresses are required as parameters. Finds
32708next trace frame that corresponds to a tracepoint at an address outside
32709the specified range. Both bounds are considered to be inside the range.
32710
32711@item line
32712Line specification is required as parameter. @xref{Specify Location}.
32713Finds next trace frame that corresponds to a tracepoint at
32714the specified location.
32715
32716@end table
32717
32718If @samp{none} was passed as @var{mode}, the response does not
32719have fields. Otherwise, the response may have the following fields:
32720
32721@table @samp
32722@item found
32723This field has either @samp{0} or @samp{1} as the value, depending
32724on whether a matching tracepoint was found.
32725
32726@item traceframe
32727The index of the found traceframe. This field is present iff
32728the @samp{found} field has value of @samp{1}.
32729
32730@item tracepoint
32731The index of the found tracepoint. This field is present iff
32732the @samp{found} field has value of @samp{1}.
32733
32734@item frame
32735The information about the frame corresponding to the found trace
32736frame. This field is present only if a trace frame was found.
cd64ee31 32737@xref{GDB/MI Frame Information}, for description of this field.
18148017
VP
32738
32739@end table
32740
7d13fe92
SS
32741@subsubheading @value{GDBN} Command
32742
32743The corresponding @value{GDBN} command is @samp{tfind}.
32744
18148017
VP
32745@subheading -trace-define-variable
32746@findex -trace-define-variable
32747
32748@subsubheading Synopsis
32749
32750@smallexample
32751 -trace-define-variable @var{name} [ @var{value} ]
32752@end smallexample
32753
32754Create trace variable @var{name} if it does not exist. If
32755@var{value} is specified, sets the initial value of the specified
32756trace variable to that value. Note that the @var{name} should start
32757with the @samp{$} character.
32758
7d13fe92
SS
32759@subsubheading @value{GDBN} Command
32760
32761The corresponding @value{GDBN} command is @samp{tvariable}.
32762
dc673c81
YQ
32763@subheading The @code{-trace-frame-collected} Command
32764@findex -trace-frame-collected
32765
32766@subsubheading Synopsis
32767
32768@smallexample
32769 -trace-frame-collected
32770 [--var-print-values @var{var_pval}]
32771 [--comp-print-values @var{comp_pval}]
32772 [--registers-format @var{regformat}]
32773 [--memory-contents]
32774@end smallexample
32775
32776This command returns the set of collected objects, register names,
32777trace state variable names, memory ranges and computed expressions
32778that have been collected at a particular trace frame. The optional
32779parameters to the command affect the output format in different ways.
32780See the output description table below for more details.
32781
32782The reported names can be used in the normal manner to create
32783varobjs and inspect the objects themselves. The items returned by
32784this command are categorized so that it is clear which is a variable,
32785which is a register, which is a trace state variable, which is a
32786memory range and which is a computed expression.
32787
32788For instance, if the actions were
32789@smallexample
32790collect myVar, myArray[myIndex], myObj.field, myPtr->field, myCount + 2
32791collect *(int*)0xaf02bef0@@40
32792@end smallexample
32793
32794@noindent
32795the object collected in its entirety would be @code{myVar}. The
32796object @code{myArray} would be partially collected, because only the
32797element at index @code{myIndex} would be collected. The remaining
32798objects would be computed expressions.
32799
32800An example output would be:
32801
32802@smallexample
32803(gdb)
32804-trace-frame-collected
32805^done,
32806 explicit-variables=[@{name="myVar",value="1"@}],
32807 computed-expressions=[@{name="myArray[myIndex]",value="0"@},
32808 @{name="myObj.field",value="0"@},
32809 @{name="myPtr->field",value="1"@},
32810 @{name="myCount + 2",value="3"@},
32811 @{name="$tvar1 + 1",value="43970027"@}],
32812 registers=[@{number="0",value="0x7fe2c6e79ec8"@},
32813 @{number="1",value="0x0"@},
32814 @{number="2",value="0x4"@},
32815 ...
32816 @{number="125",value="0x0"@}],
32817 tvars=[@{name="$tvar1",current="43970026"@}],
32818 memory=[@{address="0x0000000000602264",length="4"@},
32819 @{address="0x0000000000615bc0",length="4"@}]
32820(gdb)
32821@end smallexample
32822
32823Where:
32824
32825@table @code
32826@item explicit-variables
32827The set of objects that have been collected in their entirety (as
32828opposed to collecting just a few elements of an array or a few struct
32829members). For each object, its name and value are printed.
32830The @code{--var-print-values} option affects how or whether the value
32831field is output. If @var{var_pval} is 0, then print only the names;
32832if it is 1, print also their values; and if it is 2, print the name,
32833type and value for simple data types, and the name and type for
32834arrays, structures and unions.
32835
32836@item computed-expressions
32837The set of computed expressions that have been collected at the
32838current trace frame. The @code{--comp-print-values} option affects
32839this set like the @code{--var-print-values} option affects the
32840@code{explicit-variables} set. See above.
32841
32842@item registers
32843The registers that have been collected at the current trace frame.
32844For each register collected, the name and current value are returned.
32845The value is formatted according to the @code{--registers-format}
32846option. See the @command{-data-list-register-values} command for a
32847list of the allowed formats. The default is @samp{x}.
32848
32849@item tvars
32850The trace state variables that have been collected at the current
32851trace frame. For each trace state variable collected, the name and
32852current value are returned.
32853
32854@item memory
32855The set of memory ranges that have been collected at the current trace
32856frame. Its content is a list of tuples. Each tuple represents a
32857collected memory range and has the following fields:
32858
32859@table @code
32860@item address
32861The start address of the memory range, as hexadecimal literal.
32862
32863@item length
32864The length of the memory range, as decimal literal.
32865
32866@item contents
32867The contents of the memory block, in hex. This field is only present
32868if the @code{--memory-contents} option is specified.
32869
32870@end table
32871
32872@end table
32873
32874@subsubheading @value{GDBN} Command
32875
32876There is no corresponding @value{GDBN} command.
32877
32878@subsubheading Example
32879
18148017
VP
32880@subheading -trace-list-variables
32881@findex -trace-list-variables
922fbb7b 32882
18148017 32883@subsubheading Synopsis
922fbb7b 32884
18148017
VP
32885@smallexample
32886 -trace-list-variables
32887@end smallexample
922fbb7b 32888
18148017
VP
32889Return a table of all defined trace variables. Each element of the
32890table has the following fields:
922fbb7b 32891
18148017
VP
32892@table @samp
32893@item name
32894The name of the trace variable. This field is always present.
922fbb7b 32895
18148017
VP
32896@item initial
32897The initial value. This is a 64-bit signed integer. This
32898field is always present.
922fbb7b 32899
18148017
VP
32900@item current
32901The value the trace variable has at the moment. This is a 64-bit
32902signed integer. This field is absent iff current value is
32903not defined, for example if the trace was never run, or is
32904presently running.
922fbb7b 32905
18148017 32906@end table
922fbb7b 32907
7d13fe92
SS
32908@subsubheading @value{GDBN} Command
32909
32910The corresponding @value{GDBN} command is @samp{tvariables}.
32911
18148017 32912@subsubheading Example
922fbb7b 32913
18148017
VP
32914@smallexample
32915(gdb)
32916-trace-list-variables
32917^done,trace-variables=@{nr_rows="1",nr_cols="3",
32918hdr=[@{width="15",alignment="-1",col_name="name",colhdr="Name"@},
32919 @{width="11",alignment="-1",col_name="initial",colhdr="Initial"@},
32920 @{width="11",alignment="-1",col_name="current",colhdr="Current"@}],
32921body=[variable=@{name="$trace_timestamp",initial="0"@}
32922 variable=@{name="$foo",initial="10",current="15"@}]@}
32923(gdb)
32924@end smallexample
922fbb7b 32925
18148017
VP
32926@subheading -trace-save
32927@findex -trace-save
922fbb7b 32928
18148017
VP
32929@subsubheading Synopsis
32930
32931@smallexample
99e61eda 32932 -trace-save [ -r ] [ -ctf ] @var{filename}
18148017
VP
32933@end smallexample
32934
32935Saves the collected trace data to @var{filename}. Without the
32936@samp{-r} option, the data is downloaded from the target and saved
32937in a local file. With the @samp{-r} option the target is asked
32938to perform the save.
32939
99e61eda
SM
32940By default, this command will save the trace in the tfile format. You can
32941supply the optional @samp{-ctf} argument to save it the CTF format. See
32942@ref{Trace Files} for more information about CTF.
32943
7d13fe92
SS
32944@subsubheading @value{GDBN} Command
32945
32946The corresponding @value{GDBN} command is @samp{tsave}.
32947
18148017
VP
32948
32949@subheading -trace-start
32950@findex -trace-start
32951
32952@subsubheading Synopsis
32953
32954@smallexample
32955 -trace-start
32956@end smallexample
922fbb7b 32957
be06ba8c 32958Starts a tracing experiment. The result of this command does not
18148017 32959have any fields.
922fbb7b 32960
7d13fe92
SS
32961@subsubheading @value{GDBN} Command
32962
32963The corresponding @value{GDBN} command is @samp{tstart}.
32964
18148017
VP
32965@subheading -trace-status
32966@findex -trace-status
922fbb7b 32967
18148017
VP
32968@subsubheading Synopsis
32969
32970@smallexample
32971 -trace-status
32972@end smallexample
32973
a97153c7 32974Obtains the status of a tracing experiment. The result may include
18148017
VP
32975the following fields:
32976
32977@table @samp
32978
32979@item supported
32980May have a value of either @samp{0}, when no tracing operations are
32981supported, @samp{1}, when all tracing operations are supported, or
32982@samp{file} when examining trace file. In the latter case, examining
32983of trace frame is possible but new tracing experiement cannot be
32984started. This field is always present.
32985
32986@item running
32987May have a value of either @samp{0} or @samp{1} depending on whether
32988tracing experiement is in progress on target. This field is present
32989if @samp{supported} field is not @samp{0}.
32990
32991@item stop-reason
32992Report the reason why the tracing was stopped last time. This field
32993may be absent iff tracing was never stopped on target yet. The
32994value of @samp{request} means the tracing was stopped as result of
32995the @code{-trace-stop} command. The value of @samp{overflow} means
32996the tracing buffer is full. The value of @samp{disconnection} means
32997tracing was automatically stopped when @value{GDBN} has disconnected.
32998The value of @samp{passcount} means tracing was stopped when a
32999tracepoint was passed a maximal number of times for that tracepoint.
33000This field is present if @samp{supported} field is not @samp{0}.
33001
33002@item stopping-tracepoint
33003The number of tracepoint whose passcount as exceeded. This field is
33004present iff the @samp{stop-reason} field has the value of
33005@samp{passcount}.
33006
33007@item frames
87290684
SS
33008@itemx frames-created
33009The @samp{frames} field is a count of the total number of trace frames
33010in the trace buffer, while @samp{frames-created} is the total created
33011during the run, including ones that were discarded, such as when a
33012circular trace buffer filled up. Both fields are optional.
18148017
VP
33013
33014@item buffer-size
33015@itemx buffer-free
33016These fields tell the current size of the tracing buffer and the
87290684 33017remaining space. These fields are optional.
18148017 33018
a97153c7
PA
33019@item circular
33020The value of the circular trace buffer flag. @code{1} means that the
33021trace buffer is circular and old trace frames will be discarded if
33022necessary to make room, @code{0} means that the trace buffer is linear
33023and may fill up.
33024
33025@item disconnected
33026The value of the disconnected tracing flag. @code{1} means that
33027tracing will continue after @value{GDBN} disconnects, @code{0} means
33028that the trace run will stop.
33029
f5911ea1
HAQ
33030@item trace-file
33031The filename of the trace file being examined. This field is
33032optional, and only present when examining a trace file.
33033
18148017
VP
33034@end table
33035
7d13fe92
SS
33036@subsubheading @value{GDBN} Command
33037
33038The corresponding @value{GDBN} command is @samp{tstatus}.
33039
18148017
VP
33040@subheading -trace-stop
33041@findex -trace-stop
33042
33043@subsubheading Synopsis
33044
33045@smallexample
33046 -trace-stop
33047@end smallexample
922fbb7b 33048
18148017
VP
33049Stops a tracing experiment. The result of this command has the same
33050fields as @code{-trace-status}, except that the @samp{supported} and
33051@samp{running} fields are not output.
922fbb7b 33052
7d13fe92
SS
33053@subsubheading @value{GDBN} Command
33054
33055The corresponding @value{GDBN} command is @samp{tstop}.
33056
922fbb7b 33057
a2c02241
NR
33058@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33059@node GDB/MI Symbol Query
33060@section @sc{gdb/mi} Symbol Query Commands
922fbb7b
AC
33061
33062
9901a55b 33063@ignore
a2c02241
NR
33064@subheading The @code{-symbol-info-address} Command
33065@findex -symbol-info-address
922fbb7b
AC
33066
33067@subsubheading Synopsis
33068
33069@smallexample
a2c02241 33070 -symbol-info-address @var{symbol}
922fbb7b
AC
33071@end smallexample
33072
a2c02241 33073Describe where @var{symbol} is stored.
922fbb7b
AC
33074
33075@subsubheading @value{GDBN} Command
33076
a2c02241 33077The corresponding @value{GDBN} command is @samp{info address}.
922fbb7b
AC
33078
33079@subsubheading Example
33080N.A.
33081
33082
a2c02241
NR
33083@subheading The @code{-symbol-info-file} Command
33084@findex -symbol-info-file
922fbb7b
AC
33085
33086@subsubheading Synopsis
33087
33088@smallexample
a2c02241 33089 -symbol-info-file
922fbb7b
AC
33090@end smallexample
33091
a2c02241 33092Show the file for the symbol.
922fbb7b 33093
a2c02241 33094@subsubheading @value{GDBN} Command
922fbb7b 33095
a2c02241
NR
33096There's no equivalent @value{GDBN} command. @code{gdbtk} has
33097@samp{gdb_find_file}.
922fbb7b
AC
33098
33099@subsubheading Example
33100N.A.
33101
33102
a2c02241
NR
33103@subheading The @code{-symbol-info-function} Command
33104@findex -symbol-info-function
922fbb7b
AC
33105
33106@subsubheading Synopsis
33107
33108@smallexample
a2c02241 33109 -symbol-info-function
922fbb7b
AC
33110@end smallexample
33111
a2c02241 33112Show which function the symbol lives in.
922fbb7b
AC
33113
33114@subsubheading @value{GDBN} Command
33115
a2c02241 33116@samp{gdb_get_function} in @code{gdbtk}.
922fbb7b
AC
33117
33118@subsubheading Example
33119N.A.
33120
33121
a2c02241
NR
33122@subheading The @code{-symbol-info-line} Command
33123@findex -symbol-info-line
922fbb7b
AC
33124
33125@subsubheading Synopsis
33126
33127@smallexample
a2c02241 33128 -symbol-info-line
922fbb7b
AC
33129@end smallexample
33130
a2c02241 33131Show the core addresses of the code for a source line.
922fbb7b 33132
a2c02241 33133@subsubheading @value{GDBN} Command
922fbb7b 33134
a2c02241
NR
33135The corresponding @value{GDBN} command is @samp{info line}.
33136@code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
922fbb7b
AC
33137
33138@subsubheading Example
a2c02241 33139N.A.
922fbb7b
AC
33140
33141
a2c02241
NR
33142@subheading The @code{-symbol-info-symbol} Command
33143@findex -symbol-info-symbol
07f31aa6
DJ
33144
33145@subsubheading Synopsis
33146
a2c02241
NR
33147@smallexample
33148 -symbol-info-symbol @var{addr}
33149@end smallexample
07f31aa6 33150
a2c02241 33151Describe what symbol is at location @var{addr}.
07f31aa6 33152
a2c02241 33153@subsubheading @value{GDBN} Command
07f31aa6 33154
a2c02241 33155The corresponding @value{GDBN} command is @samp{info symbol}.
07f31aa6
DJ
33156
33157@subsubheading Example
a2c02241 33158N.A.
07f31aa6
DJ
33159
33160
a2c02241
NR
33161@subheading The @code{-symbol-list-functions} Command
33162@findex -symbol-list-functions
922fbb7b
AC
33163
33164@subsubheading Synopsis
33165
33166@smallexample
a2c02241 33167 -symbol-list-functions
922fbb7b
AC
33168@end smallexample
33169
a2c02241 33170List the functions in the executable.
922fbb7b
AC
33171
33172@subsubheading @value{GDBN} Command
33173
a2c02241
NR
33174@samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
33175@samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
33176
33177@subsubheading Example
a2c02241 33178N.A.
9901a55b 33179@end ignore
922fbb7b
AC
33180
33181
a2c02241
NR
33182@subheading The @code{-symbol-list-lines} Command
33183@findex -symbol-list-lines
922fbb7b
AC
33184
33185@subsubheading Synopsis
33186
33187@smallexample
a2c02241 33188 -symbol-list-lines @var{filename}
922fbb7b
AC
33189@end smallexample
33190
a2c02241
NR
33191Print the list of lines that contain code and their associated program
33192addresses for the given source filename. The entries are sorted in
33193ascending PC order.
922fbb7b
AC
33194
33195@subsubheading @value{GDBN} Command
33196
a2c02241 33197There is no corresponding @value{GDBN} command.
922fbb7b
AC
33198
33199@subsubheading Example
a2c02241 33200@smallexample
594fe323 33201(gdb)
a2c02241
NR
33202-symbol-list-lines basics.c
33203^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
594fe323 33204(gdb)
a2c02241 33205@end smallexample
922fbb7b
AC
33206
33207
9901a55b 33208@ignore
a2c02241
NR
33209@subheading The @code{-symbol-list-types} Command
33210@findex -symbol-list-types
922fbb7b
AC
33211
33212@subsubheading Synopsis
33213
33214@smallexample
a2c02241 33215 -symbol-list-types
922fbb7b
AC
33216@end smallexample
33217
a2c02241 33218List all the type names.
922fbb7b
AC
33219
33220@subsubheading @value{GDBN} Command
33221
a2c02241
NR
33222The corresponding commands are @samp{info types} in @value{GDBN},
33223@samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
33224
33225@subsubheading Example
33226N.A.
33227
33228
a2c02241
NR
33229@subheading The @code{-symbol-list-variables} Command
33230@findex -symbol-list-variables
922fbb7b
AC
33231
33232@subsubheading Synopsis
33233
33234@smallexample
a2c02241 33235 -symbol-list-variables
922fbb7b
AC
33236@end smallexample
33237
a2c02241 33238List all the global and static variable names.
922fbb7b
AC
33239
33240@subsubheading @value{GDBN} Command
33241
a2c02241 33242@samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
33243
33244@subsubheading Example
33245N.A.
33246
33247
a2c02241
NR
33248@subheading The @code{-symbol-locate} Command
33249@findex -symbol-locate
922fbb7b
AC
33250
33251@subsubheading Synopsis
33252
33253@smallexample
a2c02241 33254 -symbol-locate
922fbb7b
AC
33255@end smallexample
33256
922fbb7b
AC
33257@subsubheading @value{GDBN} Command
33258
a2c02241 33259@samp{gdb_loc} in @code{gdbtk}.
922fbb7b
AC
33260
33261@subsubheading Example
33262N.A.
33263
33264
a2c02241
NR
33265@subheading The @code{-symbol-type} Command
33266@findex -symbol-type
922fbb7b
AC
33267
33268@subsubheading Synopsis
33269
33270@smallexample
a2c02241 33271 -symbol-type @var{variable}
922fbb7b
AC
33272@end smallexample
33273
a2c02241 33274Show type of @var{variable}.
922fbb7b 33275
a2c02241 33276@subsubheading @value{GDBN} Command
922fbb7b 33277
a2c02241
NR
33278The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
33279@samp{gdb_obj_variable}.
33280
33281@subsubheading Example
33282N.A.
9901a55b 33283@end ignore
a2c02241
NR
33284
33285
33286@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33287@node GDB/MI File Commands
33288@section @sc{gdb/mi} File Commands
33289
33290This section describes the GDB/MI commands to specify executable file names
33291and to read in and obtain symbol table information.
33292
33293@subheading The @code{-file-exec-and-symbols} Command
33294@findex -file-exec-and-symbols
33295
33296@subsubheading Synopsis
922fbb7b
AC
33297
33298@smallexample
a2c02241 33299 -file-exec-and-symbols @var{file}
922fbb7b
AC
33300@end smallexample
33301
a2c02241
NR
33302Specify the executable file to be debugged. This file is the one from
33303which the symbol table is also read. If no file is specified, the
33304command clears the executable and symbol information. If breakpoints
33305are set when using this command with no arguments, @value{GDBN} will produce
33306error messages. Otherwise, no output is produced, except a completion
33307notification.
33308
922fbb7b
AC
33309@subsubheading @value{GDBN} Command
33310
a2c02241 33311The corresponding @value{GDBN} command is @samp{file}.
922fbb7b
AC
33312
33313@subsubheading Example
33314
33315@smallexample
594fe323 33316(gdb)
a2c02241
NR
33317-file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
33318^done
594fe323 33319(gdb)
922fbb7b
AC
33320@end smallexample
33321
922fbb7b 33322
a2c02241
NR
33323@subheading The @code{-file-exec-file} Command
33324@findex -file-exec-file
922fbb7b
AC
33325
33326@subsubheading Synopsis
33327
33328@smallexample
a2c02241 33329 -file-exec-file @var{file}
922fbb7b
AC
33330@end smallexample
33331
a2c02241
NR
33332Specify the executable file to be debugged. Unlike
33333@samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
33334from this file. If used without argument, @value{GDBN} clears the information
33335about the executable file. No output is produced, except a completion
33336notification.
922fbb7b 33337
a2c02241
NR
33338@subsubheading @value{GDBN} Command
33339
33340The corresponding @value{GDBN} command is @samp{exec-file}.
922fbb7b
AC
33341
33342@subsubheading Example
a2c02241
NR
33343
33344@smallexample
594fe323 33345(gdb)
a2c02241
NR
33346-file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
33347^done
594fe323 33348(gdb)
a2c02241 33349@end smallexample
922fbb7b
AC
33350
33351
9901a55b 33352@ignore
a2c02241
NR
33353@subheading The @code{-file-list-exec-sections} Command
33354@findex -file-list-exec-sections
922fbb7b
AC
33355
33356@subsubheading Synopsis
33357
33358@smallexample
a2c02241 33359 -file-list-exec-sections
922fbb7b
AC
33360@end smallexample
33361
a2c02241
NR
33362List the sections of the current executable file.
33363
922fbb7b
AC
33364@subsubheading @value{GDBN} Command
33365
a2c02241
NR
33366The @value{GDBN} command @samp{info file} shows, among the rest, the same
33367information as this command. @code{gdbtk} has a corresponding command
33368@samp{gdb_load_info}.
922fbb7b
AC
33369
33370@subsubheading Example
33371N.A.
9901a55b 33372@end ignore
922fbb7b
AC
33373
33374
a2c02241
NR
33375@subheading The @code{-file-list-exec-source-file} Command
33376@findex -file-list-exec-source-file
922fbb7b
AC
33377
33378@subsubheading Synopsis
33379
33380@smallexample
a2c02241 33381 -file-list-exec-source-file
922fbb7b
AC
33382@end smallexample
33383
a2c02241 33384List the line number, the current source file, and the absolute path
44288b44
NR
33385to the current source file for the current executable. The macro
33386information field has a value of @samp{1} or @samp{0} depending on
33387whether or not the file includes preprocessor macro information.
922fbb7b
AC
33388
33389@subsubheading @value{GDBN} Command
33390
a2c02241 33391The @value{GDBN} equivalent is @samp{info source}
922fbb7b
AC
33392
33393@subsubheading Example
33394
922fbb7b 33395@smallexample
594fe323 33396(gdb)
a2c02241 33397123-file-list-exec-source-file
44288b44 33398123^done,line="1",file="foo.c",fullname="/home/bar/foo.c,macro-info="1"
594fe323 33399(gdb)
922fbb7b
AC
33400@end smallexample
33401
33402
a2c02241
NR
33403@subheading The @code{-file-list-exec-source-files} Command
33404@findex -file-list-exec-source-files
922fbb7b
AC
33405
33406@subsubheading Synopsis
33407
33408@smallexample
a2c02241 33409 -file-list-exec-source-files
922fbb7b
AC
33410@end smallexample
33411
a2c02241
NR
33412List the source files for the current executable.
33413
f35a17b5
JK
33414It will always output both the filename and fullname (absolute file
33415name) of a source file.
922fbb7b
AC
33416
33417@subsubheading @value{GDBN} Command
33418
a2c02241
NR
33419The @value{GDBN} equivalent is @samp{info sources}.
33420@code{gdbtk} has an analogous command @samp{gdb_listfiles}.
922fbb7b
AC
33421
33422@subsubheading Example
922fbb7b 33423@smallexample
594fe323 33424(gdb)
a2c02241
NR
33425-file-list-exec-source-files
33426^done,files=[
33427@{file=foo.c,fullname=/home/foo.c@},
33428@{file=/home/bar.c,fullname=/home/bar.c@},
33429@{file=gdb_could_not_find_fullpath.c@}]
594fe323 33430(gdb)
922fbb7b
AC
33431@end smallexample
33432
a2c02241
NR
33433@subheading The @code{-file-list-shared-libraries} Command
33434@findex -file-list-shared-libraries
922fbb7b 33435
a2c02241 33436@subsubheading Synopsis
922fbb7b 33437
a2c02241 33438@smallexample
51457a05 33439 -file-list-shared-libraries [ @var{regexp} ]
a2c02241 33440@end smallexample
922fbb7b 33441
a2c02241 33442List the shared libraries in the program.
51457a05
MAL
33443With a regular expression @var{regexp}, only those libraries whose
33444names match @var{regexp} are listed.
922fbb7b 33445
a2c02241 33446@subsubheading @value{GDBN} Command
922fbb7b 33447
51457a05
MAL
33448The corresponding @value{GDBN} command is @samp{info shared}. The fields
33449have a similar meaning to the @code{=library-loaded} notification.
33450The @code{ranges} field specifies the multiple segments belonging to this
33451library. Each range has the following fields:
33452
33453@table @samp
33454@item from
33455The address defining the inclusive lower bound of the segment.
33456@item to
33457The address defining the exclusive upper bound of the segment.
33458@end table
922fbb7b 33459
a2c02241 33460@subsubheading Example
51457a05
MAL
33461@smallexample
33462(gdb)
33463-file-list-exec-source-files
33464^done,shared-libraries=[
33465@{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"@}]@},
33466@{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"@}]@}]
33467(gdb)
33468@end smallexample
922fbb7b
AC
33469
33470
51457a05 33471@ignore
a2c02241
NR
33472@subheading The @code{-file-list-symbol-files} Command
33473@findex -file-list-symbol-files
922fbb7b 33474
a2c02241 33475@subsubheading Synopsis
922fbb7b 33476
a2c02241
NR
33477@smallexample
33478 -file-list-symbol-files
33479@end smallexample
922fbb7b 33480
a2c02241 33481List symbol files.
922fbb7b 33482
a2c02241 33483@subsubheading @value{GDBN} Command
922fbb7b 33484
a2c02241 33485The corresponding @value{GDBN} command is @samp{info file} (part of it).
922fbb7b 33486
a2c02241
NR
33487@subsubheading Example
33488N.A.
9901a55b 33489@end ignore
922fbb7b 33490
922fbb7b 33491
a2c02241
NR
33492@subheading The @code{-file-symbol-file} Command
33493@findex -file-symbol-file
922fbb7b 33494
a2c02241 33495@subsubheading Synopsis
922fbb7b 33496
a2c02241
NR
33497@smallexample
33498 -file-symbol-file @var{file}
33499@end smallexample
922fbb7b 33500
a2c02241
NR
33501Read symbol table info from the specified @var{file} argument. When
33502used without arguments, clears @value{GDBN}'s symbol table info. No output is
33503produced, except for a completion notification.
922fbb7b 33504
a2c02241 33505@subsubheading @value{GDBN} Command
922fbb7b 33506
a2c02241 33507The corresponding @value{GDBN} command is @samp{symbol-file}.
922fbb7b 33508
a2c02241 33509@subsubheading Example
922fbb7b 33510
a2c02241 33511@smallexample
594fe323 33512(gdb)
a2c02241
NR
33513-file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
33514^done
594fe323 33515(gdb)
a2c02241 33516@end smallexample
922fbb7b 33517
a2c02241 33518@ignore
a2c02241
NR
33519@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33520@node GDB/MI Memory Overlay Commands
33521@section @sc{gdb/mi} Memory Overlay Commands
922fbb7b 33522
a2c02241 33523The memory overlay commands are not implemented.
922fbb7b 33524
a2c02241 33525@c @subheading -overlay-auto
922fbb7b 33526
a2c02241 33527@c @subheading -overlay-list-mapping-state
922fbb7b 33528
a2c02241 33529@c @subheading -overlay-list-overlays
922fbb7b 33530
a2c02241 33531@c @subheading -overlay-map
922fbb7b 33532
a2c02241 33533@c @subheading -overlay-off
922fbb7b 33534
a2c02241 33535@c @subheading -overlay-on
922fbb7b 33536
a2c02241 33537@c @subheading -overlay-unmap
922fbb7b 33538
a2c02241
NR
33539@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33540@node GDB/MI Signal Handling Commands
33541@section @sc{gdb/mi} Signal Handling Commands
922fbb7b 33542
a2c02241 33543Signal handling commands are not implemented.
922fbb7b 33544
a2c02241 33545@c @subheading -signal-handle
922fbb7b 33546
a2c02241 33547@c @subheading -signal-list-handle-actions
922fbb7b 33548
a2c02241
NR
33549@c @subheading -signal-list-signal-types
33550@end ignore
922fbb7b 33551
922fbb7b 33552
a2c02241
NR
33553@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33554@node GDB/MI Target Manipulation
33555@section @sc{gdb/mi} Target Manipulation Commands
922fbb7b
AC
33556
33557
a2c02241
NR
33558@subheading The @code{-target-attach} Command
33559@findex -target-attach
922fbb7b
AC
33560
33561@subsubheading Synopsis
33562
33563@smallexample
c3b108f7 33564 -target-attach @var{pid} | @var{gid} | @var{file}
922fbb7b
AC
33565@end smallexample
33566
c3b108f7
VP
33567Attach to a process @var{pid} or a file @var{file} outside of
33568@value{GDBN}, or a thread group @var{gid}. If attaching to a thread
33569group, the id previously returned by
33570@samp{-list-thread-groups --available} must be used.
922fbb7b 33571
79a6e687 33572@subsubheading @value{GDBN} Command
922fbb7b 33573
a2c02241 33574The corresponding @value{GDBN} command is @samp{attach}.
922fbb7b 33575
a2c02241 33576@subsubheading Example
b56e7235
VP
33577@smallexample
33578(gdb)
33579-target-attach 34
33580=thread-created,id="1"
5ae4183a 33581*stopped,thread-id="1",frame=@{addr="0xb7f7e410",func="bar",args=[]@}
b56e7235
VP
33582^done
33583(gdb)
33584@end smallexample
a2c02241 33585
9901a55b 33586@ignore
a2c02241
NR
33587@subheading The @code{-target-compare-sections} Command
33588@findex -target-compare-sections
922fbb7b
AC
33589
33590@subsubheading Synopsis
33591
33592@smallexample
a2c02241 33593 -target-compare-sections [ @var{section} ]
922fbb7b
AC
33594@end smallexample
33595
a2c02241
NR
33596Compare data of section @var{section} on target to the exec file.
33597Without the argument, all sections are compared.
922fbb7b 33598
a2c02241 33599@subsubheading @value{GDBN} Command
922fbb7b 33600
a2c02241 33601The @value{GDBN} equivalent is @samp{compare-sections}.
922fbb7b 33602
a2c02241
NR
33603@subsubheading Example
33604N.A.
9901a55b 33605@end ignore
a2c02241
NR
33606
33607
33608@subheading The @code{-target-detach} Command
33609@findex -target-detach
922fbb7b
AC
33610
33611@subsubheading Synopsis
33612
33613@smallexample
c3b108f7 33614 -target-detach [ @var{pid} | @var{gid} ]
922fbb7b
AC
33615@end smallexample
33616
a2c02241 33617Detach from the remote target which normally resumes its execution.
c3b108f7
VP
33618If either @var{pid} or @var{gid} is specified, detaches from either
33619the specified process, or specified thread group. There's no output.
a2c02241 33620
79a6e687 33621@subsubheading @value{GDBN} Command
a2c02241
NR
33622
33623The corresponding @value{GDBN} command is @samp{detach}.
33624
33625@subsubheading Example
922fbb7b
AC
33626
33627@smallexample
594fe323 33628(gdb)
a2c02241
NR
33629-target-detach
33630^done
594fe323 33631(gdb)
922fbb7b
AC
33632@end smallexample
33633
33634
a2c02241
NR
33635@subheading The @code{-target-disconnect} Command
33636@findex -target-disconnect
922fbb7b
AC
33637
33638@subsubheading Synopsis
33639
123dc839 33640@smallexample
a2c02241 33641 -target-disconnect
123dc839 33642@end smallexample
922fbb7b 33643
a2c02241
NR
33644Disconnect from the remote target. There's no output and the target is
33645generally not resumed.
33646
79a6e687 33647@subsubheading @value{GDBN} Command
a2c02241
NR
33648
33649The corresponding @value{GDBN} command is @samp{disconnect}.
bc8ced35
NR
33650
33651@subsubheading Example
922fbb7b
AC
33652
33653@smallexample
594fe323 33654(gdb)
a2c02241
NR
33655-target-disconnect
33656^done
594fe323 33657(gdb)
922fbb7b
AC
33658@end smallexample
33659
33660
a2c02241
NR
33661@subheading The @code{-target-download} Command
33662@findex -target-download
922fbb7b
AC
33663
33664@subsubheading Synopsis
33665
33666@smallexample
a2c02241 33667 -target-download
922fbb7b
AC
33668@end smallexample
33669
a2c02241
NR
33670Loads the executable onto the remote target.
33671It prints out an update message every half second, which includes the fields:
33672
33673@table @samp
33674@item section
33675The name of the section.
33676@item section-sent
33677The size of what has been sent so far for that section.
33678@item section-size
33679The size of the section.
33680@item total-sent
33681The total size of what was sent so far (the current and the previous sections).
33682@item total-size
33683The size of the overall executable to download.
33684@end table
33685
33686@noindent
33687Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
33688@sc{gdb/mi} Output Syntax}).
33689
33690In addition, it prints the name and size of the sections, as they are
33691downloaded. These messages include the following fields:
33692
33693@table @samp
33694@item section
33695The name of the section.
33696@item section-size
33697The size of the section.
33698@item total-size
33699The size of the overall executable to download.
33700@end table
33701
33702@noindent
33703At the end, a summary is printed.
33704
33705@subsubheading @value{GDBN} Command
33706
33707The corresponding @value{GDBN} command is @samp{load}.
33708
33709@subsubheading Example
33710
33711Note: each status message appears on a single line. Here the messages
33712have been broken down so that they can fit onto a page.
922fbb7b
AC
33713
33714@smallexample
594fe323 33715(gdb)
a2c02241
NR
33716-target-download
33717+download,@{section=".text",section-size="6668",total-size="9880"@}
33718+download,@{section=".text",section-sent="512",section-size="6668",
33719total-sent="512",total-size="9880"@}
33720+download,@{section=".text",section-sent="1024",section-size="6668",
33721total-sent="1024",total-size="9880"@}
33722+download,@{section=".text",section-sent="1536",section-size="6668",
33723total-sent="1536",total-size="9880"@}
33724+download,@{section=".text",section-sent="2048",section-size="6668",
33725total-sent="2048",total-size="9880"@}
33726+download,@{section=".text",section-sent="2560",section-size="6668",
33727total-sent="2560",total-size="9880"@}
33728+download,@{section=".text",section-sent="3072",section-size="6668",
33729total-sent="3072",total-size="9880"@}
33730+download,@{section=".text",section-sent="3584",section-size="6668",
33731total-sent="3584",total-size="9880"@}
33732+download,@{section=".text",section-sent="4096",section-size="6668",
33733total-sent="4096",total-size="9880"@}
33734+download,@{section=".text",section-sent="4608",section-size="6668",
33735total-sent="4608",total-size="9880"@}
33736+download,@{section=".text",section-sent="5120",section-size="6668",
33737total-sent="5120",total-size="9880"@}
33738+download,@{section=".text",section-sent="5632",section-size="6668",
33739total-sent="5632",total-size="9880"@}
33740+download,@{section=".text",section-sent="6144",section-size="6668",
33741total-sent="6144",total-size="9880"@}
33742+download,@{section=".text",section-sent="6656",section-size="6668",
33743total-sent="6656",total-size="9880"@}
33744+download,@{section=".init",section-size="28",total-size="9880"@}
33745+download,@{section=".fini",section-size="28",total-size="9880"@}
33746+download,@{section=".data",section-size="3156",total-size="9880"@}
33747+download,@{section=".data",section-sent="512",section-size="3156",
33748total-sent="7236",total-size="9880"@}
33749+download,@{section=".data",section-sent="1024",section-size="3156",
33750total-sent="7748",total-size="9880"@}
33751+download,@{section=".data",section-sent="1536",section-size="3156",
33752total-sent="8260",total-size="9880"@}
33753+download,@{section=".data",section-sent="2048",section-size="3156",
33754total-sent="8772",total-size="9880"@}
33755+download,@{section=".data",section-sent="2560",section-size="3156",
33756total-sent="9284",total-size="9880"@}
33757+download,@{section=".data",section-sent="3072",section-size="3156",
33758total-sent="9796",total-size="9880"@}
33759^done,address="0x10004",load-size="9880",transfer-rate="6586",
33760write-rate="429"
594fe323 33761(gdb)
922fbb7b
AC
33762@end smallexample
33763
33764
9901a55b 33765@ignore
a2c02241
NR
33766@subheading The @code{-target-exec-status} Command
33767@findex -target-exec-status
922fbb7b
AC
33768
33769@subsubheading Synopsis
33770
33771@smallexample
a2c02241 33772 -target-exec-status
922fbb7b
AC
33773@end smallexample
33774
a2c02241
NR
33775Provide information on the state of the target (whether it is running or
33776not, for instance).
922fbb7b 33777
a2c02241 33778@subsubheading @value{GDBN} Command
922fbb7b 33779
a2c02241
NR
33780There's no equivalent @value{GDBN} command.
33781
33782@subsubheading Example
33783N.A.
922fbb7b 33784
a2c02241
NR
33785
33786@subheading The @code{-target-list-available-targets} Command
33787@findex -target-list-available-targets
922fbb7b
AC
33788
33789@subsubheading Synopsis
33790
33791@smallexample
a2c02241 33792 -target-list-available-targets
922fbb7b
AC
33793@end smallexample
33794
a2c02241 33795List the possible targets to connect to.
922fbb7b 33796
a2c02241 33797@subsubheading @value{GDBN} Command
922fbb7b 33798
a2c02241 33799The corresponding @value{GDBN} command is @samp{help target}.
922fbb7b 33800
a2c02241
NR
33801@subsubheading Example
33802N.A.
33803
33804
33805@subheading The @code{-target-list-current-targets} Command
33806@findex -target-list-current-targets
922fbb7b
AC
33807
33808@subsubheading Synopsis
33809
33810@smallexample
a2c02241 33811 -target-list-current-targets
922fbb7b
AC
33812@end smallexample
33813
a2c02241 33814Describe the current target.
922fbb7b 33815
a2c02241 33816@subsubheading @value{GDBN} Command
922fbb7b 33817
a2c02241
NR
33818The corresponding information is printed by @samp{info file} (among
33819other things).
922fbb7b 33820
a2c02241
NR
33821@subsubheading Example
33822N.A.
33823
33824
33825@subheading The @code{-target-list-parameters} Command
33826@findex -target-list-parameters
922fbb7b
AC
33827
33828@subsubheading Synopsis
33829
33830@smallexample
a2c02241 33831 -target-list-parameters
922fbb7b
AC
33832@end smallexample
33833
a2c02241 33834@c ????
9901a55b 33835@end ignore
a2c02241
NR
33836
33837@subsubheading @value{GDBN} Command
33838
33839No equivalent.
922fbb7b
AC
33840
33841@subsubheading Example
a2c02241
NR
33842N.A.
33843
78cbbba8
LM
33844@subheading The @code{-target-flash-erase} Command
33845@findex -target-flash-erase
33846
33847@subsubheading Synopsis
33848
33849@smallexample
33850 -target-flash-erase
33851@end smallexample
33852
33853Erases all known flash memory regions on the target.
33854
33855The corresponding @value{GDBN} command is @samp{flash-erase}.
33856
33857The output is a list of flash regions that have been erased, with starting
33858addresses and memory region sizes.
33859
33860@smallexample
33861(gdb)
33862-target-flash-erase
33863^done,erased-regions=@{address="0x0",size="0x40000"@}
33864(gdb)
33865@end smallexample
a2c02241
NR
33866
33867@subheading The @code{-target-select} Command
33868@findex -target-select
33869
33870@subsubheading Synopsis
922fbb7b
AC
33871
33872@smallexample
a2c02241 33873 -target-select @var{type} @var{parameters @dots{}}
922fbb7b
AC
33874@end smallexample
33875
a2c02241 33876Connect @value{GDBN} to the remote target. This command takes two args:
922fbb7b 33877
a2c02241
NR
33878@table @samp
33879@item @var{type}
75c99385 33880The type of target, for instance @samp{remote}, etc.
a2c02241
NR
33881@item @var{parameters}
33882Device names, host names and the like. @xref{Target Commands, ,
79a6e687 33883Commands for Managing Targets}, for more details.
a2c02241
NR
33884@end table
33885
33886The output is a connection notification, followed by the address at
33887which the target program is, in the following form:
922fbb7b
AC
33888
33889@smallexample
a2c02241
NR
33890^connected,addr="@var{address}",func="@var{function name}",
33891 args=[@var{arg list}]
922fbb7b
AC
33892@end smallexample
33893
a2c02241
NR
33894@subsubheading @value{GDBN} Command
33895
33896The corresponding @value{GDBN} command is @samp{target}.
265eeb58
NR
33897
33898@subsubheading Example
922fbb7b 33899
265eeb58 33900@smallexample
594fe323 33901(gdb)
75c99385 33902-target-select remote /dev/ttya
a2c02241 33903^connected,addr="0xfe00a300",func="??",args=[]
594fe323 33904(gdb)
265eeb58 33905@end smallexample
ef21caaf 33906
a6b151f1
DJ
33907@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33908@node GDB/MI File Transfer Commands
33909@section @sc{gdb/mi} File Transfer Commands
33910
33911
33912@subheading The @code{-target-file-put} Command
33913@findex -target-file-put
33914
33915@subsubheading Synopsis
33916
33917@smallexample
33918 -target-file-put @var{hostfile} @var{targetfile}
33919@end smallexample
33920
33921Copy file @var{hostfile} from the host system (the machine running
33922@value{GDBN}) to @var{targetfile} on the target system.
33923
33924@subsubheading @value{GDBN} Command
33925
33926The corresponding @value{GDBN} command is @samp{remote put}.
33927
33928@subsubheading Example
33929
33930@smallexample
33931(gdb)
33932-target-file-put localfile remotefile
33933^done
33934(gdb)
33935@end smallexample
33936
33937
1763a388 33938@subheading The @code{-target-file-get} Command
a6b151f1
DJ
33939@findex -target-file-get
33940
33941@subsubheading Synopsis
33942
33943@smallexample
33944 -target-file-get @var{targetfile} @var{hostfile}
33945@end smallexample
33946
33947Copy file @var{targetfile} from the target system to @var{hostfile}
33948on the host system.
33949
33950@subsubheading @value{GDBN} Command
33951
33952The corresponding @value{GDBN} command is @samp{remote get}.
33953
33954@subsubheading Example
33955
33956@smallexample
33957(gdb)
33958-target-file-get remotefile localfile
33959^done
33960(gdb)
33961@end smallexample
33962
33963
33964@subheading The @code{-target-file-delete} Command
33965@findex -target-file-delete
33966
33967@subsubheading Synopsis
33968
33969@smallexample
33970 -target-file-delete @var{targetfile}
33971@end smallexample
33972
33973Delete @var{targetfile} from the target system.
33974
33975@subsubheading @value{GDBN} Command
33976
33977The corresponding @value{GDBN} command is @samp{remote delete}.
33978
33979@subsubheading Example
33980
33981@smallexample
33982(gdb)
33983-target-file-delete remotefile
33984^done
33985(gdb)
33986@end smallexample
33987
33988
58d06528
JB
33989@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33990@node GDB/MI Ada Exceptions Commands
33991@section Ada Exceptions @sc{gdb/mi} Commands
33992
33993@subheading The @code{-info-ada-exceptions} Command
33994@findex -info-ada-exceptions
33995
33996@subsubheading Synopsis
33997
33998@smallexample
33999 -info-ada-exceptions [ @var{regexp}]
34000@end smallexample
34001
34002List all Ada exceptions defined within the program being debugged.
34003With a regular expression @var{regexp}, only those exceptions whose
34004names match @var{regexp} are listed.
34005
34006@subsubheading @value{GDBN} Command
34007
34008The corresponding @value{GDBN} command is @samp{info exceptions}.
34009
34010@subsubheading Result
34011
34012The result is a table of Ada exceptions. The following columns are
34013defined for each exception:
34014
34015@table @samp
34016@item name
34017The name of the exception.
34018
34019@item address
34020The address of the exception.
34021
34022@end table
34023
34024@subsubheading Example
34025
34026@smallexample
34027-info-ada-exceptions aint
34028^done,ada-exceptions=@{nr_rows="2",nr_cols="2",
34029hdr=[@{width="1",alignment="-1",col_name="name",colhdr="Name"@},
34030@{width="1",alignment="-1",col_name="address",colhdr="Address"@}],
34031body=[@{name="constraint_error",address="0x0000000000613da0"@},
34032@{name="const.aint_global_e",address="0x0000000000613b00"@}]@}
34033@end smallexample
34034
34035@subheading Catching Ada Exceptions
34036
34037The commands describing how to ask @value{GDBN} to stop when a program
34038raises an exception are described at @ref{Ada Exception GDB/MI
34039Catchpoint Commands}.
34040
34041
ef21caaf 34042@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d192b373
JB
34043@node GDB/MI Support Commands
34044@section @sc{gdb/mi} Support Commands
ef21caaf 34045
d192b373
JB
34046Since new commands and features get regularly added to @sc{gdb/mi},
34047some commands are available to help front-ends query the debugger
34048about support for these capabilities. Similarly, it is also possible
34049to query @value{GDBN} about target support of certain features.
ef21caaf 34050
6b7cbff1
JB
34051@subheading The @code{-info-gdb-mi-command} Command
34052@cindex @code{-info-gdb-mi-command}
34053@findex -info-gdb-mi-command
34054
34055@subsubheading Synopsis
34056
34057@smallexample
34058 -info-gdb-mi-command @var{cmd_name}
34059@end smallexample
34060
34061Query support for the @sc{gdb/mi} command named @var{cmd_name}.
34062
34063Note that the dash (@code{-}) starting all @sc{gdb/mi} commands
34064is technically not part of the command name (@pxref{GDB/MI Input
34065Syntax}), and thus should be omitted in @var{cmd_name}. However,
34066for ease of use, this command also accepts the form with the leading
34067dash.
34068
34069@subsubheading @value{GDBN} Command
34070
34071There is no corresponding @value{GDBN} command.
34072
34073@subsubheading Result
34074
34075The result is a tuple. There is currently only one field:
34076
34077@table @samp
34078@item exists
34079This field is equal to @code{"true"} if the @sc{gdb/mi} command exists,
34080@code{"false"} otherwise.
34081
34082@end table
34083
34084@subsubheading Example
34085
34086Here is an example where the @sc{gdb/mi} command does not exist:
34087
34088@smallexample
34089-info-gdb-mi-command unsupported-command
34090^done,command=@{exists="false"@}
34091@end smallexample
34092
34093@noindent
34094And here is an example where the @sc{gdb/mi} command is known
34095to the debugger:
34096
34097@smallexample
34098-info-gdb-mi-command symbol-list-lines
34099^done,command=@{exists="true"@}
34100@end smallexample
34101
084344da
VP
34102@subheading The @code{-list-features} Command
34103@findex -list-features
9b26f0fb 34104@cindex supported @sc{gdb/mi} features, list
084344da
VP
34105
34106Returns a list of particular features of the MI protocol that
34107this version of gdb implements. A feature can be a command,
34108or a new field in an output of some command, or even an
34109important bugfix. While a frontend can sometimes detect presence
34110of a feature at runtime, it is easier to perform detection at debugger
d192b373 34111startup.
084344da
VP
34112
34113The command returns a list of strings, with each string naming an
34114available feature. Each returned string is just a name, it does not
d192b373 34115have any internal structure. The list of possible feature names
084344da
VP
34116is given below.
34117
34118Example output:
34119
34120@smallexample
34121(gdb) -list-features
34122^done,result=["feature1","feature2"]
34123@end smallexample
34124
34125The current list of features is:
34126
edef6000 34127@ftable @samp
30e026bb 34128@item frozen-varobjs
a05336a1
JB
34129Indicates support for the @code{-var-set-frozen} command, as well
34130as possible presense of the @code{frozen} field in the output
30e026bb
VP
34131of @code{-varobj-create}.
34132@item pending-breakpoints
a05336a1
JB
34133Indicates support for the @option{-f} option to the @code{-break-insert}
34134command.
b6313243 34135@item python
a05336a1 34136Indicates Python scripting support, Python-based
b6313243
TT
34137pretty-printing commands, and possible presence of the
34138@samp{display_hint} field in the output of @code{-var-list-children}
30e026bb 34139@item thread-info
a05336a1 34140Indicates support for the @code{-thread-info} command.
8dedea02 34141@item data-read-memory-bytes
a05336a1 34142Indicates support for the @code{-data-read-memory-bytes} and the
8dedea02 34143@code{-data-write-memory-bytes} commands.
39c4d40a
TT
34144@item breakpoint-notifications
34145Indicates that changes to breakpoints and breakpoints created via the
34146CLI will be announced via async records.
5d77fe44 34147@item ada-task-info
6adcee18 34148Indicates support for the @code{-ada-task-info} command.
422ad5c2
JB
34149@item language-option
34150Indicates that all @sc{gdb/mi} commands accept the @option{--language}
34151option (@pxref{Context management}).
6b7cbff1
JB
34152@item info-gdb-mi-command
34153Indicates support for the @code{-info-gdb-mi-command} command.
2ea126fa
JB
34154@item undefined-command-error-code
34155Indicates support for the "undefined-command" error code in error result
34156records, produced when trying to execute an undefined @sc{gdb/mi} command
34157(@pxref{GDB/MI Result Records}).
72bfa06c
JB
34158@item exec-run-start-option
34159Indicates that the @code{-exec-run} command supports the @option{--start}
34160option (@pxref{GDB/MI Program Execution}).
26fb3983
JV
34161@item data-disassemble-a-option
34162Indicates that the @code{-data-disassemble} command supports the @option{-a}
34163option (@pxref{GDB/MI Data Manipulation}).
edef6000 34164@end ftable
084344da 34165
c6ebd6cf
VP
34166@subheading The @code{-list-target-features} Command
34167@findex -list-target-features
34168
34169Returns a list of particular features that are supported by the
34170target. Those features affect the permitted MI commands, but
34171unlike the features reported by the @code{-list-features} command, the
34172features depend on which target GDB is using at the moment. Whenever
34173a target can change, due to commands such as @code{-target-select},
34174@code{-target-attach} or @code{-exec-run}, the list of target features
34175may change, and the frontend should obtain it again.
34176Example output:
34177
34178@smallexample
b3d3b4bd 34179(gdb) -list-target-features
c6ebd6cf
VP
34180^done,result=["async"]
34181@end smallexample
34182
34183The current list of features is:
34184
34185@table @samp
34186@item async
34187Indicates that the target is capable of asynchronous command
34188execution, which means that @value{GDBN} will accept further commands
34189while the target is running.
34190
f75d858b
MK
34191@item reverse
34192Indicates that the target is capable of reverse execution.
34193@xref{Reverse Execution}, for more information.
34194
c6ebd6cf
VP
34195@end table
34196
d192b373
JB
34197@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34198@node GDB/MI Miscellaneous Commands
34199@section Miscellaneous @sc{gdb/mi} Commands
34200
34201@c @subheading -gdb-complete
34202
34203@subheading The @code{-gdb-exit} Command
34204@findex -gdb-exit
34205
34206@subsubheading Synopsis
34207
34208@smallexample
34209 -gdb-exit
34210@end smallexample
34211
34212Exit @value{GDBN} immediately.
34213
34214@subsubheading @value{GDBN} Command
34215
34216Approximately corresponds to @samp{quit}.
34217
34218@subsubheading Example
34219
34220@smallexample
34221(gdb)
34222-gdb-exit
34223^exit
34224@end smallexample
34225
34226
34227@ignore
34228@subheading The @code{-exec-abort} Command
34229@findex -exec-abort
34230
34231@subsubheading Synopsis
34232
34233@smallexample
34234 -exec-abort
34235@end smallexample
34236
34237Kill the inferior running program.
34238
34239@subsubheading @value{GDBN} Command
34240
34241The corresponding @value{GDBN} command is @samp{kill}.
34242
34243@subsubheading Example
34244N.A.
34245@end ignore
34246
34247
34248@subheading The @code{-gdb-set} Command
34249@findex -gdb-set
34250
34251@subsubheading Synopsis
34252
34253@smallexample
34254 -gdb-set
34255@end smallexample
34256
34257Set an internal @value{GDBN} variable.
34258@c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
34259
34260@subsubheading @value{GDBN} Command
34261
34262The corresponding @value{GDBN} command is @samp{set}.
34263
34264@subsubheading Example
34265
34266@smallexample
34267(gdb)
34268-gdb-set $foo=3
34269^done
34270(gdb)
34271@end smallexample
34272
34273
34274@subheading The @code{-gdb-show} Command
34275@findex -gdb-show
34276
34277@subsubheading Synopsis
34278
34279@smallexample
34280 -gdb-show
34281@end smallexample
34282
34283Show the current value of a @value{GDBN} variable.
34284
34285@subsubheading @value{GDBN} Command
34286
34287The corresponding @value{GDBN} command is @samp{show}.
34288
34289@subsubheading Example
34290
34291@smallexample
34292(gdb)
34293-gdb-show annotate
34294^done,value="0"
34295(gdb)
34296@end smallexample
34297
34298@c @subheading -gdb-source
34299
34300
34301@subheading The @code{-gdb-version} Command
34302@findex -gdb-version
34303
34304@subsubheading Synopsis
34305
34306@smallexample
34307 -gdb-version
34308@end smallexample
34309
34310Show version information for @value{GDBN}. Used mostly in testing.
34311
34312@subsubheading @value{GDBN} Command
34313
34314The @value{GDBN} equivalent is @samp{show version}. @value{GDBN} by
34315default shows this information when you start an interactive session.
34316
34317@subsubheading Example
34318
34319@c This example modifies the actual output from GDB to avoid overfull
34320@c box in TeX.
34321@smallexample
34322(gdb)
34323-gdb-version
34324~GNU gdb 5.2.1
34325~Copyright 2000 Free Software Foundation, Inc.
34326~GDB is free software, covered by the GNU General Public License, and
34327~you are welcome to change it and/or distribute copies of it under
34328~ certain conditions.
34329~Type "show copying" to see the conditions.
34330~There is absolutely no warranty for GDB. Type "show warranty" for
34331~ details.
34332~This GDB was configured as
34333 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
34334^done
34335(gdb)
34336@end smallexample
34337
c3b108f7
VP
34338@subheading The @code{-list-thread-groups} Command
34339@findex -list-thread-groups
34340
34341@subheading Synopsis
34342
34343@smallexample
dc146f7c 34344-list-thread-groups [ --available ] [ --recurse 1 ] [ @var{group} ... ]
c3b108f7
VP
34345@end smallexample
34346
dc146f7c
VP
34347Lists thread groups (@pxref{Thread groups}). When a single thread
34348group is passed as the argument, lists the children of that group.
34349When several thread group are passed, lists information about those
34350thread groups. Without any parameters, lists information about all
34351top-level thread groups.
34352
34353Normally, thread groups that are being debugged are reported.
34354With the @samp{--available} option, @value{GDBN} reports thread groups
34355available on the target.
34356
34357The output of this command may have either a @samp{threads} result or
34358a @samp{groups} result. The @samp{thread} result has a list of tuples
34359as value, with each tuple describing a thread (@pxref{GDB/MI Thread
34360Information}). The @samp{groups} result has a list of tuples as value,
34361each tuple describing a thread group. If top-level groups are
34362requested (that is, no parameter is passed), or when several groups
34363are passed, the output always has a @samp{groups} result. The format
34364of the @samp{group} result is described below.
34365
34366To reduce the number of roundtrips it's possible to list thread groups
34367together with their children, by passing the @samp{--recurse} option
34368and the recursion depth. Presently, only recursion depth of 1 is
34369permitted. If this option is present, then every reported thread group
34370will also include its children, either as @samp{group} or
34371@samp{threads} field.
34372
34373In general, any combination of option and parameters is permitted, with
34374the following caveats:
34375
34376@itemize @bullet
34377@item
34378When a single thread group is passed, the output will typically
34379be the @samp{threads} result. Because threads may not contain
34380anything, the @samp{recurse} option will be ignored.
34381
34382@item
34383When the @samp{--available} option is passed, limited information may
34384be available. In particular, the list of threads of a process might
34385be inaccessible. Further, specifying specific thread groups might
34386not give any performance advantage over listing all thread groups.
34387The frontend should assume that @samp{-list-thread-groups --available}
34388is always an expensive operation and cache the results.
34389
34390@end itemize
34391
34392The @samp{groups} result is a list of tuples, where each tuple may
34393have the following fields:
34394
34395@table @code
34396@item id
34397Identifier of the thread group. This field is always present.
a79b8f6e
VP
34398The identifier is an opaque string; frontends should not try to
34399convert it to an integer, even though it might look like one.
dc146f7c
VP
34400
34401@item type
34402The type of the thread group. At present, only @samp{process} is a
34403valid type.
34404
34405@item pid
34406The target-specific process identifier. This field is only present
a79b8f6e 34407for thread groups of type @samp{process} and only if the process exists.
c3b108f7 34408
2ddf4301
SM
34409@item exit-code
34410The exit code of this group's last exited thread, formatted in octal.
34411This field is only present for thread groups of type @samp{process} and
34412only if the process is not running.
34413
dc146f7c
VP
34414@item num_children
34415The number of children this thread group has. This field may be
34416absent for an available thread group.
34417
34418@item threads
34419This field has a list of tuples as value, each tuple describing a
34420thread. It may be present if the @samp{--recurse} option is
34421specified, and it's actually possible to obtain the threads.
34422
34423@item cores
34424This field is a list of integers, each identifying a core that one
34425thread of the group is running on. This field may be absent if
34426such information is not available.
34427
a79b8f6e
VP
34428@item executable
34429The name of the executable file that corresponds to this thread group.
34430The field is only present for thread groups of type @samp{process},
34431and only if there is a corresponding executable file.
34432
dc146f7c 34433@end table
c3b108f7
VP
34434
34435@subheading Example
34436
34437@smallexample
34438@value{GDBP}
34439-list-thread-groups
34440^done,groups=[@{id="17",type="process",pid="yyy",num_children="2"@}]
34441-list-thread-groups 17
34442^done,threads=[@{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
34443 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",args=[]@},state="running"@},
34444@{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
34445 frame=@{level="0",addr="0x0804891f",func="foo",args=[@{name="i",value="10"@}],
6d52907e 34446 file="/tmp/a.c",fullname="/tmp/a.c",line="158",arch="i386:x86_64"@},state="running"@}]]
dc146f7c
VP
34447-list-thread-groups --available
34448^done,groups=[@{id="17",type="process",pid="yyy",num_children="2",cores=[1,2]@}]
34449-list-thread-groups --available --recurse 1
34450 ^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
34451 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
34452 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},..]
34453-list-thread-groups --available --recurse 1 17 18
34454^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
34455 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
34456 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},...]
c3b108f7 34457@end smallexample
c6ebd6cf 34458
f3e0e960
SS
34459@subheading The @code{-info-os} Command
34460@findex -info-os
34461
34462@subsubheading Synopsis
34463
34464@smallexample
34465-info-os [ @var{type} ]
34466@end smallexample
34467
34468If no argument is supplied, the command returns a table of available
34469operating-system-specific information types. If one of these types is
34470supplied as an argument @var{type}, then the command returns a table
34471of data of that type.
34472
34473The types of information available depend on the target operating
34474system.
34475
34476@subsubheading @value{GDBN} Command
34477
34478The corresponding @value{GDBN} command is @samp{info os}.
34479
34480@subsubheading Example
34481
34482When run on a @sc{gnu}/Linux system, the output will look something
34483like this:
34484
34485@smallexample
34486@value{GDBP}
34487-info-os
d33279b3 34488^done,OSDataTable=@{nr_rows="10",nr_cols="3",
f3e0e960 34489hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="Type"@},
71caed83
SS
34490 @{width="10",alignment="-1",col_name="col1",colhdr="Description"@},
34491 @{width="10",alignment="-1",col_name="col2",colhdr="Title"@}],
d33279b3
AT
34492body=[item=@{col0="cpus",col1="Listing of all cpus/cores on the system",
34493 col2="CPUs"@},
34494 item=@{col0="files",col1="Listing of all file descriptors",
34495 col2="File descriptors"@},
34496 item=@{col0="modules",col1="Listing of all loaded kernel modules",
34497 col2="Kernel modules"@},
34498 item=@{col0="msg",col1="Listing of all message queues",
34499 col2="Message queues"@},
34500 item=@{col0="processes",col1="Listing of all processes",
71caed83
SS
34501 col2="Processes"@},
34502 item=@{col0="procgroups",col1="Listing of all process groups",
34503 col2="Process groups"@},
71caed83
SS
34504 item=@{col0="semaphores",col1="Listing of all semaphores",
34505 col2="Semaphores"@},
d33279b3
AT
34506 item=@{col0="shm",col1="Listing of all shared-memory regions",
34507 col2="Shared-memory regions"@},
34508 item=@{col0="sockets",col1="Listing of all internet-domain sockets",
34509 col2="Sockets"@},
34510 item=@{col0="threads",col1="Listing of all threads",
34511 col2="Threads"@}]
f3e0e960
SS
34512@value{GDBP}
34513-info-os processes
34514^done,OSDataTable=@{nr_rows="190",nr_cols="4",
34515hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="pid"@},
34516 @{width="10",alignment="-1",col_name="col1",colhdr="user"@},
34517 @{width="10",alignment="-1",col_name="col2",colhdr="command"@},
34518 @{width="10",alignment="-1",col_name="col3",colhdr="cores"@}],
34519body=[item=@{col0="1",col1="root",col2="/sbin/init",col3="0"@},
34520 item=@{col0="2",col1="root",col2="[kthreadd]",col3="1"@},
34521 item=@{col0="3",col1="root",col2="[ksoftirqd/0]",col3="0"@},
34522 ...
34523 item=@{col0="26446",col1="stan",col2="bash",col3="0"@},
34524 item=@{col0="28152",col1="stan",col2="bash",col3="1"@}]@}
34525(gdb)
34526@end smallexample
a79b8f6e 34527
71caed83
SS
34528(Note that the MI output here includes a @code{"Title"} column that
34529does not appear in command-line @code{info os}; this column is useful
34530for MI clients that want to enumerate the types of data, such as in a
34531popup menu, but is needless clutter on the command line, and
34532@code{info os} omits it.)
34533
a79b8f6e
VP
34534@subheading The @code{-add-inferior} Command
34535@findex -add-inferior
34536
34537@subheading Synopsis
34538
34539@smallexample
34540-add-inferior
34541@end smallexample
34542
34543Creates a new inferior (@pxref{Inferiors and Programs}). The created
34544inferior is not associated with any executable. Such association may
34545be established with the @samp{-file-exec-and-symbols} command
34546(@pxref{GDB/MI File Commands}). The command response has a single
b7742092 34547field, @samp{inferior}, whose value is the identifier of the
a79b8f6e
VP
34548thread group corresponding to the new inferior.
34549
34550@subheading Example
34551
34552@smallexample
34553@value{GDBP}
34554-add-inferior
b7742092 34555^done,inferior="i3"
a79b8f6e
VP
34556@end smallexample
34557
ef21caaf
NR
34558@subheading The @code{-interpreter-exec} Command
34559@findex -interpreter-exec
34560
34561@subheading Synopsis
34562
34563@smallexample
34564-interpreter-exec @var{interpreter} @var{command}
34565@end smallexample
a2c02241 34566@anchor{-interpreter-exec}
ef21caaf
NR
34567
34568Execute the specified @var{command} in the given @var{interpreter}.
34569
34570@subheading @value{GDBN} Command
34571
34572The corresponding @value{GDBN} command is @samp{interpreter-exec}.
34573
34574@subheading Example
34575
34576@smallexample
594fe323 34577(gdb)
ef21caaf
NR
34578-interpreter-exec console "break main"
34579&"During symbol reading, couldn't parse type; debugger out of date?.\n"
34580&"During symbol reading, bad structure-type format.\n"
34581~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
34582^done
594fe323 34583(gdb)
ef21caaf
NR
34584@end smallexample
34585
34586@subheading The @code{-inferior-tty-set} Command
34587@findex -inferior-tty-set
34588
34589@subheading Synopsis
34590
34591@smallexample
34592-inferior-tty-set /dev/pts/1
34593@end smallexample
34594
34595Set terminal for future runs of the program being debugged.
34596
34597@subheading @value{GDBN} Command
34598
34599The corresponding @value{GDBN} command is @samp{set inferior-tty} /dev/pts/1.
34600
34601@subheading Example
34602
34603@smallexample
594fe323 34604(gdb)
ef21caaf
NR
34605-inferior-tty-set /dev/pts/1
34606^done
594fe323 34607(gdb)
ef21caaf
NR
34608@end smallexample
34609
34610@subheading The @code{-inferior-tty-show} Command
34611@findex -inferior-tty-show
34612
34613@subheading Synopsis
34614
34615@smallexample
34616-inferior-tty-show
34617@end smallexample
34618
34619Show terminal for future runs of program being debugged.
34620
34621@subheading @value{GDBN} Command
34622
34623The corresponding @value{GDBN} command is @samp{show inferior-tty}.
34624
34625@subheading Example
34626
34627@smallexample
594fe323 34628(gdb)
ef21caaf
NR
34629-inferior-tty-set /dev/pts/1
34630^done
594fe323 34631(gdb)
ef21caaf
NR
34632-inferior-tty-show
34633^done,inferior_tty_terminal="/dev/pts/1"
594fe323 34634(gdb)
ef21caaf 34635@end smallexample
922fbb7b 34636
a4eefcd8
NR
34637@subheading The @code{-enable-timings} Command
34638@findex -enable-timings
34639
34640@subheading Synopsis
34641
34642@smallexample
34643-enable-timings [yes | no]
34644@end smallexample
34645
34646Toggle the printing of the wallclock, user and system times for an MI
34647command as a field in its output. This command is to help frontend
34648developers optimize the performance of their code. No argument is
34649equivalent to @samp{yes}.
34650
34651@subheading @value{GDBN} Command
34652
34653No equivalent.
34654
34655@subheading Example
34656
34657@smallexample
34658(gdb)
34659-enable-timings
34660^done
34661(gdb)
34662-break-insert main
34663^done,bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
34664addr="0x080484ed",func="main",file="myprog.c",
998580f1
MK
34665fullname="/home/nickrob/myprog.c",line="73",thread-groups=["i1"],
34666times="0"@},
a4eefcd8
NR
34667time=@{wallclock="0.05185",user="0.00800",system="0.00000"@}
34668(gdb)
34669-enable-timings no
34670^done
34671(gdb)
34672-exec-run
34673^running
34674(gdb)
a47ec5fe 34675*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
a4eefcd8
NR
34676frame=@{addr="0x080484ed",func="main",args=[@{name="argc",value="1"@},
34677@{name="argv",value="0xbfb60364"@}],file="myprog.c",
6d52907e 34678fullname="/home/nickrob/myprog.c",line="73",arch="i386:x86_64"@}
a4eefcd8
NR
34679(gdb)
34680@end smallexample
34681
26648588
JV
34682@subheading The @code{-complete} Command
34683@findex -complete
34684
34685@subheading Synopsis
34686
34687@smallexample
34688-complete @var{command}
34689@end smallexample
34690
34691Show a list of completions for partially typed CLI @var{command}.
34692
34693This command is intended for @sc{gdb/mi} frontends that cannot use two separate
7166f90a 34694CLI and MI channels --- for example: because of lack of PTYs like on Windows or
26648588
JV
34695because @value{GDBN} is used remotely via a SSH connection.
34696
34697@subheading Result
34698
34699The result consists of two or three fields:
34700
34701@table @samp
34702@item completion
34703This field contains the completed @var{command}. If @var{command}
34704has no known completions, this field is omitted.
34705
34706@item matches
34707This field contains a (possibly empty) array of matches. It is always present.
34708
34709@item max_completions_reached
34710This field contains @code{1} if number of known completions is above
7166f90a 34711@code{max-completions} limit (@pxref{Completion}), otherwise it contains
26648588
JV
34712@code{0}. It is always present.
34713
34714@end table
34715
34716@subheading @value{GDBN} Command
34717
34718The corresponding @value{GDBN} command is @samp{complete}.
34719
34720@subheading Example
34721
34722@smallexample
34723(gdb)
34724-complete br
34725^done,completion="break",
34726 matches=["break","break-range"],
34727 max_completions_reached="0"
34728(gdb)
34729-complete "b ma"
34730^done,completion="b ma",
34731 matches=["b madvise","b main"],max_completions_reached="0"
34732(gdb)
34733-complete "b push_b"
34734^done,completion="b push_back(",
34735 matches=[
34736 "b A::push_back(void*)",
34737 "b std::string::push_back(char)",
34738 "b std::vector<int, std::allocator<int> >::push_back(int&&)"],
34739 max_completions_reached="0"
34740(gdb)
34741-complete "nonexist"
34742^done,matches=[],max_completions_reached="0"
34743(gdb)
34744
34745@end smallexample
34746
922fbb7b
AC
34747@node Annotations
34748@chapter @value{GDBN} Annotations
34749
086432e2
AC
34750This chapter describes annotations in @value{GDBN}. Annotations were
34751designed to interface @value{GDBN} to graphical user interfaces or other
34752similar programs which want to interact with @value{GDBN} at a
922fbb7b
AC
34753relatively high level.
34754
d3e8051b 34755The annotation mechanism has largely been superseded by @sc{gdb/mi}
086432e2
AC
34756(@pxref{GDB/MI}).
34757
922fbb7b
AC
34758@ignore
34759This is Edition @value{EDITION}, @value{DATE}.
34760@end ignore
34761
34762@menu
34763* Annotations Overview:: What annotations are; the general syntax.
9e6c4bd5 34764* Server Prefix:: Issuing a command without affecting user state.
922fbb7b
AC
34765* Prompting:: Annotations marking @value{GDBN}'s need for input.
34766* Errors:: Annotations for error messages.
922fbb7b
AC
34767* Invalidation:: Some annotations describe things now invalid.
34768* Annotations for Running::
34769 Whether the program is running, how it stopped, etc.
34770* Source Annotations:: Annotations describing source code.
922fbb7b
AC
34771@end menu
34772
34773@node Annotations Overview
34774@section What is an Annotation?
34775@cindex annotations
34776
922fbb7b
AC
34777Annotations start with a newline character, two @samp{control-z}
34778characters, and the name of the annotation. If there is no additional
34779information associated with this annotation, the name of the annotation
34780is followed immediately by a newline. If there is additional
34781information, the name of the annotation is followed by a space, the
34782additional information, and a newline. The additional information
34783cannot contain newline characters.
34784
34785Any output not beginning with a newline and two @samp{control-z}
34786characters denotes literal output from @value{GDBN}. Currently there is
34787no need for @value{GDBN} to output a newline followed by two
34788@samp{control-z} characters, but if there was such a need, the
34789annotations could be extended with an @samp{escape} annotation which
34790means those three characters as output.
34791
086432e2
AC
34792The annotation @var{level}, which is specified using the
34793@option{--annotate} command line option (@pxref{Mode Options}), controls
34794how much information @value{GDBN} prints together with its prompt,
34795values of expressions, source lines, and other types of output. Level 0
d3e8051b 34796is for no annotations, level 1 is for use when @value{GDBN} is run as a
086432e2
AC
34797subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
34798for programs that control @value{GDBN}, and level 2 annotations have
34799been made obsolete (@pxref{Limitations, , Limitations of the Annotation
09d4efe1
EZ
34800Interface, annotate, GDB's Obsolete Annotations}).
34801
34802@table @code
34803@kindex set annotate
34804@item set annotate @var{level}
e09f16f9 34805The @value{GDBN} command @code{set annotate} sets the level of
09d4efe1 34806annotations to the specified @var{level}.
9c16f35a
EZ
34807
34808@item show annotate
34809@kindex show annotate
34810Show the current annotation level.
09d4efe1
EZ
34811@end table
34812
34813This chapter describes level 3 annotations.
086432e2 34814
922fbb7b
AC
34815A simple example of starting up @value{GDBN} with annotations is:
34816
34817@smallexample
086432e2
AC
34818$ @kbd{gdb --annotate=3}
34819GNU gdb 6.0
34820Copyright 2003 Free Software Foundation, Inc.
922fbb7b
AC
34821GDB is free software, covered by the GNU General Public License,
34822and you are welcome to change it and/or distribute copies of it
34823under certain conditions.
34824Type "show copying" to see the conditions.
34825There is absolutely no warranty for GDB. Type "show warranty"
34826for details.
086432e2 34827This GDB was configured as "i386-pc-linux-gnu"
922fbb7b
AC
34828
34829^Z^Zpre-prompt
f7dc1244 34830(@value{GDBP})
922fbb7b 34831^Z^Zprompt
086432e2 34832@kbd{quit}
922fbb7b
AC
34833
34834^Z^Zpost-prompt
b383017d 34835$
922fbb7b
AC
34836@end smallexample
34837
34838Here @samp{quit} is input to @value{GDBN}; the rest is output from
34839@value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
34840denotes a @samp{control-z} character) are annotations; the rest is
34841output from @value{GDBN}.
34842
9e6c4bd5
NR
34843@node Server Prefix
34844@section The Server Prefix
34845@cindex server prefix
34846
34847If you prefix a command with @samp{server } then it will not affect
34848the command history, nor will it affect @value{GDBN}'s notion of which
34849command to repeat if @key{RET} is pressed on a line by itself. This
34850means that commands can be run behind a user's back by a front-end in
34851a transparent manner.
34852
d837706a
NR
34853The @code{server } prefix does not affect the recording of values into
34854the value history; to print a value without recording it into the
34855value history, use the @code{output} command instead of the
34856@code{print} command.
34857
34858Using this prefix also disables confirmation requests
34859(@pxref{confirmation requests}).
9e6c4bd5 34860
922fbb7b
AC
34861@node Prompting
34862@section Annotation for @value{GDBN} Input
34863
34864@cindex annotations for prompts
34865When @value{GDBN} prompts for input, it annotates this fact so it is possible
34866to know when to send output, when the output from a given command is
34867over, etc.
34868
34869Different kinds of input each have a different @dfn{input type}. Each
34870input type has three annotations: a @code{pre-} annotation, which
34871denotes the beginning of any prompt which is being output, a plain
34872annotation, which denotes the end of the prompt, and then a @code{post-}
34873annotation which denotes the end of any echo which may (or may not) be
34874associated with the input. For example, the @code{prompt} input type
34875features the following annotations:
34876
34877@smallexample
34878^Z^Zpre-prompt
34879^Z^Zprompt
34880^Z^Zpost-prompt
34881@end smallexample
34882
34883The input types are
34884
34885@table @code
e5ac9b53
EZ
34886@findex pre-prompt annotation
34887@findex prompt annotation
34888@findex post-prompt annotation
922fbb7b
AC
34889@item prompt
34890When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
34891
e5ac9b53
EZ
34892@findex pre-commands annotation
34893@findex commands annotation
34894@findex post-commands annotation
922fbb7b
AC
34895@item commands
34896When @value{GDBN} prompts for a set of commands, like in the @code{commands}
34897command. The annotations are repeated for each command which is input.
34898
e5ac9b53
EZ
34899@findex pre-overload-choice annotation
34900@findex overload-choice annotation
34901@findex post-overload-choice annotation
922fbb7b
AC
34902@item overload-choice
34903When @value{GDBN} wants the user to select between various overloaded functions.
34904
e5ac9b53
EZ
34905@findex pre-query annotation
34906@findex query annotation
34907@findex post-query annotation
922fbb7b
AC
34908@item query
34909When @value{GDBN} wants the user to confirm a potentially dangerous operation.
34910
e5ac9b53
EZ
34911@findex pre-prompt-for-continue annotation
34912@findex prompt-for-continue annotation
34913@findex post-prompt-for-continue annotation
922fbb7b
AC
34914@item prompt-for-continue
34915When @value{GDBN} is asking the user to press return to continue. Note: Don't
34916expect this to work well; instead use @code{set height 0} to disable
34917prompting. This is because the counting of lines is buggy in the
34918presence of annotations.
34919@end table
34920
34921@node Errors
34922@section Errors
34923@cindex annotations for errors, warnings and interrupts
34924
e5ac9b53 34925@findex quit annotation
922fbb7b
AC
34926@smallexample
34927^Z^Zquit
34928@end smallexample
34929
34930This annotation occurs right before @value{GDBN} responds to an interrupt.
34931
e5ac9b53 34932@findex error annotation
922fbb7b
AC
34933@smallexample
34934^Z^Zerror
34935@end smallexample
34936
34937This annotation occurs right before @value{GDBN} responds to an error.
34938
34939Quit and error annotations indicate that any annotations which @value{GDBN} was
34940in the middle of may end abruptly. For example, if a
34941@code{value-history-begin} annotation is followed by a @code{error}, one
34942cannot expect to receive the matching @code{value-history-end}. One
34943cannot expect not to receive it either, however; an error annotation
34944does not necessarily mean that @value{GDBN} is immediately returning all the way
34945to the top level.
34946
e5ac9b53 34947@findex error-begin annotation
922fbb7b
AC
34948A quit or error annotation may be preceded by
34949
34950@smallexample
34951^Z^Zerror-begin
34952@end smallexample
34953
34954Any output between that and the quit or error annotation is the error
34955message.
34956
34957Warning messages are not yet annotated.
34958@c If we want to change that, need to fix warning(), type_error(),
34959@c range_error(), and possibly other places.
34960
922fbb7b
AC
34961@node Invalidation
34962@section Invalidation Notices
34963
34964@cindex annotations for invalidation messages
34965The following annotations say that certain pieces of state may have
34966changed.
34967
34968@table @code
e5ac9b53 34969@findex frames-invalid annotation
922fbb7b
AC
34970@item ^Z^Zframes-invalid
34971
34972The frames (for example, output from the @code{backtrace} command) may
34973have changed.
34974
e5ac9b53 34975@findex breakpoints-invalid annotation
922fbb7b
AC
34976@item ^Z^Zbreakpoints-invalid
34977
34978The breakpoints may have changed. For example, the user just added or
34979deleted a breakpoint.
34980@end table
34981
34982@node Annotations for Running
34983@section Running the Program
34984@cindex annotations for running programs
34985
e5ac9b53
EZ
34986@findex starting annotation
34987@findex stopping annotation
922fbb7b 34988When the program starts executing due to a @value{GDBN} command such as
b383017d 34989@code{step} or @code{continue},
922fbb7b
AC
34990
34991@smallexample
34992^Z^Zstarting
34993@end smallexample
34994
b383017d 34995is output. When the program stops,
922fbb7b
AC
34996
34997@smallexample
34998^Z^Zstopped
34999@end smallexample
35000
35001is output. Before the @code{stopped} annotation, a variety of
35002annotations describe how the program stopped.
35003
35004@table @code
e5ac9b53 35005@findex exited annotation
922fbb7b
AC
35006@item ^Z^Zexited @var{exit-status}
35007The program exited, and @var{exit-status} is the exit status (zero for
35008successful exit, otherwise nonzero).
35009
e5ac9b53
EZ
35010@findex signalled annotation
35011@findex signal-name annotation
35012@findex signal-name-end annotation
35013@findex signal-string annotation
35014@findex signal-string-end annotation
922fbb7b
AC
35015@item ^Z^Zsignalled
35016The program exited with a signal. After the @code{^Z^Zsignalled}, the
35017annotation continues:
35018
35019@smallexample
35020@var{intro-text}
35021^Z^Zsignal-name
35022@var{name}
35023^Z^Zsignal-name-end
35024@var{middle-text}
35025^Z^Zsignal-string
35026@var{string}
35027^Z^Zsignal-string-end
35028@var{end-text}
35029@end smallexample
35030
35031@noindent
35032where @var{name} is the name of the signal, such as @code{SIGILL} or
35033@code{SIGSEGV}, and @var{string} is the explanation of the signal, such
697aa1b7 35034as @code{Illegal Instruction} or @code{Segmentation fault}. The arguments
922fbb7b
AC
35035@var{intro-text}, @var{middle-text}, and @var{end-text} are for the
35036user's benefit and have no particular format.
35037
e5ac9b53 35038@findex signal annotation
922fbb7b
AC
35039@item ^Z^Zsignal
35040The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
35041just saying that the program received the signal, not that it was
35042terminated with it.
35043
e5ac9b53 35044@findex breakpoint annotation
922fbb7b
AC
35045@item ^Z^Zbreakpoint @var{number}
35046The program hit breakpoint number @var{number}.
35047
e5ac9b53 35048@findex watchpoint annotation
922fbb7b
AC
35049@item ^Z^Zwatchpoint @var{number}
35050The program hit watchpoint number @var{number}.
35051@end table
35052
35053@node Source Annotations
35054@section Displaying Source
35055@cindex annotations for source display
35056
e5ac9b53 35057@findex source annotation
922fbb7b
AC
35058The following annotation is used instead of displaying source code:
35059
35060@smallexample
35061^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
35062@end smallexample
35063
35064where @var{filename} is an absolute file name indicating which source
35065file, @var{line} is the line number within that file (where 1 is the
35066first line in the file), @var{character} is the character position
35067within the file (where 0 is the first character in the file) (for most
35068debug formats this will necessarily point to the beginning of a line),
35069@var{middle} is @samp{middle} if @var{addr} is in the middle of the
35070line, or @samp{beg} if @var{addr} is at the beginning of the line, and
35071@var{addr} is the address in the target program associated with the
697aa1b7 35072source which is being displayed. The @var{addr} is in the form @samp{0x}
922fbb7b
AC
35073followed by one or more lowercase hex digits (note that this does not
35074depend on the language).
35075
4efc6507
DE
35076@node JIT Interface
35077@chapter JIT Compilation Interface
35078@cindex just-in-time compilation
35079@cindex JIT compilation interface
35080
35081This chapter documents @value{GDBN}'s @dfn{just-in-time} (JIT) compilation
35082interface. A JIT compiler is a program or library that generates native
35083executable code at runtime and executes it, usually in order to achieve good
35084performance while maintaining platform independence.
35085
35086Programs that use JIT compilation are normally difficult to debug because
35087portions of their code are generated at runtime, instead of being loaded from
35088object files, which is where @value{GDBN} normally finds the program's symbols
35089and debug information. In order to debug programs that use JIT compilation,
35090@value{GDBN} has an interface that allows the program to register in-memory
35091symbol files with @value{GDBN} at runtime.
35092
35093If you are using @value{GDBN} to debug a program that uses this interface, then
35094it should work transparently so long as you have not stripped the binary. If
35095you are developing a JIT compiler, then the interface is documented in the rest
35096of this chapter. At this time, the only known client of this interface is the
35097LLVM JIT.
35098
35099Broadly speaking, the JIT interface mirrors the dynamic loader interface. The
35100JIT compiler communicates with @value{GDBN} by writing data into a global
35101variable and calling a fuction at a well-known symbol. When @value{GDBN}
35102attaches, it reads a linked list of symbol files from the global variable to
35103find existing code, and puts a breakpoint in the function so that it can find
35104out about additional code.
35105
35106@menu
35107* Declarations:: Relevant C struct declarations
35108* Registering Code:: Steps to register code
35109* Unregistering Code:: Steps to unregister code
f85b53f8 35110* Custom Debug Info:: Emit debug information in a custom format
4efc6507
DE
35111@end menu
35112
35113@node Declarations
35114@section JIT Declarations
35115
35116These are the relevant struct declarations that a C program should include to
35117implement the interface:
35118
35119@smallexample
35120typedef enum
35121@{
35122 JIT_NOACTION = 0,
35123 JIT_REGISTER_FN,
35124 JIT_UNREGISTER_FN
35125@} jit_actions_t;
35126
35127struct jit_code_entry
35128@{
35129 struct jit_code_entry *next_entry;
35130 struct jit_code_entry *prev_entry;
35131 const char *symfile_addr;
35132 uint64_t symfile_size;
35133@};
35134
35135struct jit_descriptor
35136@{
35137 uint32_t version;
35138 /* This type should be jit_actions_t, but we use uint32_t
35139 to be explicit about the bitwidth. */
35140 uint32_t action_flag;
35141 struct jit_code_entry *relevant_entry;
35142 struct jit_code_entry *first_entry;
35143@};
35144
35145/* GDB puts a breakpoint in this function. */
35146void __attribute__((noinline)) __jit_debug_register_code() @{ @};
35147
35148/* Make sure to specify the version statically, because the
35149 debugger may check the version before we can set it. */
35150struct jit_descriptor __jit_debug_descriptor = @{ 1, 0, 0, 0 @};
35151@end smallexample
35152
35153If the JIT is multi-threaded, then it is important that the JIT synchronize any
35154modifications to this global data properly, which can easily be done by putting
35155a global mutex around modifications to these structures.
35156
35157@node Registering Code
35158@section Registering Code
35159
35160To register code with @value{GDBN}, the JIT should follow this protocol:
35161
35162@itemize @bullet
35163@item
35164Generate an object file in memory with symbols and other desired debug
35165information. The file must include the virtual addresses of the sections.
35166
35167@item
35168Create a code entry for the file, which gives the start and size of the symbol
35169file.
35170
35171@item
35172Add it to the linked list in the JIT descriptor.
35173
35174@item
35175Point the relevant_entry field of the descriptor at the entry.
35176
35177@item
35178Set @code{action_flag} to @code{JIT_REGISTER} and call
35179@code{__jit_debug_register_code}.
35180@end itemize
35181
35182When @value{GDBN} is attached and the breakpoint fires, @value{GDBN} uses the
35183@code{relevant_entry} pointer so it doesn't have to walk the list looking for
35184new code. However, the linked list must still be maintained in order to allow
35185@value{GDBN} to attach to a running process and still find the symbol files.
35186
35187@node Unregistering Code
35188@section Unregistering Code
35189
35190If code is freed, then the JIT should use the following protocol:
35191
35192@itemize @bullet
35193@item
35194Remove the code entry corresponding to the code from the linked list.
35195
35196@item
35197Point the @code{relevant_entry} field of the descriptor at the code entry.
35198
35199@item
35200Set @code{action_flag} to @code{JIT_UNREGISTER} and call
35201@code{__jit_debug_register_code}.
35202@end itemize
35203
35204If the JIT frees or recompiles code without unregistering it, then @value{GDBN}
35205and the JIT will leak the memory used for the associated symbol files.
35206
f85b53f8
SD
35207@node Custom Debug Info
35208@section Custom Debug Info
35209@cindex custom JIT debug info
35210@cindex JIT debug info reader
35211
35212Generating debug information in platform-native file formats (like ELF
35213or COFF) may be an overkill for JIT compilers; especially if all the
35214debug info is used for is displaying a meaningful backtrace. The
35215issue can be resolved by having the JIT writers decide on a debug info
35216format and also provide a reader that parses the debug info generated
35217by the JIT compiler. This section gives a brief overview on writing
35218such a parser. More specific details can be found in the source file
35219@file{gdb/jit-reader.in}, which is also installed as a header at
35220@file{@var{includedir}/gdb/jit-reader.h} for easy inclusion.
35221
35222The reader is implemented as a shared object (so this functionality is
35223not available on platforms which don't allow loading shared objects at
35224runtime). Two @value{GDBN} commands, @code{jit-reader-load} and
35225@code{jit-reader-unload} are provided, to be used to load and unload
35226the readers from a preconfigured directory. Once loaded, the shared
35227object is used the parse the debug information emitted by the JIT
35228compiler.
35229
35230@menu
35231* Using JIT Debug Info Readers:: How to use supplied readers correctly
35232* Writing JIT Debug Info Readers:: Creating a debug-info reader
35233@end menu
35234
35235@node Using JIT Debug Info Readers
35236@subsection Using JIT Debug Info Readers
35237@kindex jit-reader-load
35238@kindex jit-reader-unload
35239
35240Readers can be loaded and unloaded using the @code{jit-reader-load}
35241and @code{jit-reader-unload} commands.
35242
35243@table @code
c9fb1240 35244@item jit-reader-load @var{reader}
697aa1b7 35245Load the JIT reader named @var{reader}, which is a shared
c9fb1240
SD
35246object specified as either an absolute or a relative file name. In
35247the latter case, @value{GDBN} will try to load the reader from a
35248pre-configured directory, usually @file{@var{libdir}/gdb/} on a UNIX
35249system (here @var{libdir} is the system library directory, often
35250@file{/usr/local/lib}).
35251
35252Only one reader can be active at a time; trying to load a second
35253reader when one is already loaded will result in @value{GDBN}
35254reporting an error. A new JIT reader can be loaded by first unloading
35255the current one using @code{jit-reader-unload} and then invoking
35256@code{jit-reader-load}.
f85b53f8
SD
35257
35258@item jit-reader-unload
35259Unload the currently loaded JIT reader.
35260
35261@end table
35262
35263@node Writing JIT Debug Info Readers
35264@subsection Writing JIT Debug Info Readers
35265@cindex writing JIT debug info readers
35266
35267As mentioned, a reader is essentially a shared object conforming to a
35268certain ABI. This ABI is described in @file{jit-reader.h}.
35269
35270@file{jit-reader.h} defines the structures, macros and functions
35271required to write a reader. It is installed (along with
35272@value{GDBN}), in @file{@var{includedir}/gdb} where @var{includedir} is
35273the system include directory.
35274
35275Readers need to be released under a GPL compatible license. A reader
35276can be declared as released under such a license by placing the macro
35277@code{GDB_DECLARE_GPL_COMPATIBLE_READER} in a source file.
35278
35279The entry point for readers is the symbol @code{gdb_init_reader},
35280which is expected to be a function with the prototype
35281
35282@findex gdb_init_reader
35283@smallexample
35284extern struct gdb_reader_funcs *gdb_init_reader (void);
35285@end smallexample
35286
35287@cindex @code{struct gdb_reader_funcs}
35288
35289@code{struct gdb_reader_funcs} contains a set of pointers to callback
35290functions. These functions are executed to read the debug info
35291generated by the JIT compiler (@code{read}), to unwind stack frames
35292(@code{unwind}) and to create canonical frame IDs
35293(@code{get_Frame_id}). It also has a callback that is called when the
35294reader is being unloaded (@code{destroy}). The struct looks like this
35295
35296@smallexample
35297struct gdb_reader_funcs
35298@{
35299 /* Must be set to GDB_READER_INTERFACE_VERSION. */
35300 int reader_version;
35301
35302 /* For use by the reader. */
35303 void *priv_data;
35304
35305 gdb_read_debug_info *read;
35306 gdb_unwind_frame *unwind;
35307 gdb_get_frame_id *get_frame_id;
35308 gdb_destroy_reader *destroy;
35309@};
35310@end smallexample
35311
35312@cindex @code{struct gdb_symbol_callbacks}
35313@cindex @code{struct gdb_unwind_callbacks}
35314
35315The callbacks are provided with another set of callbacks by
35316@value{GDBN} to do their job. For @code{read}, these callbacks are
35317passed in a @code{struct gdb_symbol_callbacks} and for @code{unwind}
35318and @code{get_frame_id}, in a @code{struct gdb_unwind_callbacks}.
35319@code{struct gdb_symbol_callbacks} has callbacks to create new object
35320files and new symbol tables inside those object files. @code{struct
35321gdb_unwind_callbacks} has callbacks to read registers off the current
35322frame and to write out the values of the registers in the previous
35323frame. Both have a callback (@code{target_read}) to read bytes off the
35324target's address space.
35325
d1feda86
YQ
35326@node In-Process Agent
35327@chapter In-Process Agent
35328@cindex debugging agent
35329The traditional debugging model is conceptually low-speed, but works fine,
35330because most bugs can be reproduced in debugging-mode execution. However,
35331as multi-core or many-core processors are becoming mainstream, and
35332multi-threaded programs become more and more popular, there should be more
35333and more bugs that only manifest themselves at normal-mode execution, for
35334example, thread races, because debugger's interference with the program's
35335timing may conceal the bugs. On the other hand, in some applications,
35336it is not feasible for the debugger to interrupt the program's execution
35337long enough for the developer to learn anything helpful about its behavior.
35338If the program's correctness depends on its real-time behavior, delays
35339introduced by a debugger might cause the program to fail, even when the
35340code itself is correct. It is useful to be able to observe the program's
35341behavior without interrupting it.
35342
35343Therefore, traditional debugging model is too intrusive to reproduce
35344some bugs. In order to reduce the interference with the program, we can
35345reduce the number of operations performed by debugger. The
35346@dfn{In-Process Agent}, a shared library, is running within the same
35347process with inferior, and is able to perform some debugging operations
35348itself. As a result, debugger is only involved when necessary, and
35349performance of debugging can be improved accordingly. Note that
35350interference with program can be reduced but can't be removed completely,
35351because the in-process agent will still stop or slow down the program.
35352
35353The in-process agent can interpret and execute Agent Expressions
35354(@pxref{Agent Expressions}) during performing debugging operations. The
35355agent expressions can be used for different purposes, such as collecting
35356data in tracepoints, and condition evaluation in breakpoints.
35357
35358@anchor{Control Agent}
35359You can control whether the in-process agent is used as an aid for
35360debugging with the following commands:
35361
35362@table @code
35363@kindex set agent on
35364@item set agent on
35365Causes the in-process agent to perform some operations on behalf of the
35366debugger. Just which operations requested by the user will be done
35367by the in-process agent depends on the its capabilities. For example,
35368if you request to evaluate breakpoint conditions in the in-process agent,
35369and the in-process agent has such capability as well, then breakpoint
35370conditions will be evaluated in the in-process agent.
35371
35372@kindex set agent off
35373@item set agent off
35374Disables execution of debugging operations by the in-process agent. All
35375of the operations will be performed by @value{GDBN}.
35376
35377@kindex show agent
35378@item show agent
35379Display the current setting of execution of debugging operations by
35380the in-process agent.
35381@end table
35382
16bdd41f
YQ
35383@menu
35384* In-Process Agent Protocol::
35385@end menu
35386
35387@node In-Process Agent Protocol
35388@section In-Process Agent Protocol
35389@cindex in-process agent protocol
35390
35391The in-process agent is able to communicate with both @value{GDBN} and
35392GDBserver (@pxref{In-Process Agent}). This section documents the protocol
35393used for communications between @value{GDBN} or GDBserver and the IPA.
35394In general, @value{GDBN} or GDBserver sends commands
35395(@pxref{IPA Protocol Commands}) and data to in-process agent, and then
35396in-process agent replies back with the return result of the command, or
35397some other information. The data sent to in-process agent is composed
35398of primitive data types, such as 4-byte or 8-byte type, and composite
35399types, which are called objects (@pxref{IPA Protocol Objects}).
35400
35401@menu
35402* IPA Protocol Objects::
35403* IPA Protocol Commands::
35404@end menu
35405
35406@node IPA Protocol Objects
35407@subsection IPA Protocol Objects
35408@cindex ipa protocol objects
35409
35410The commands sent to and results received from agent may contain some
35411complex data types called @dfn{objects}.
35412
35413The in-process agent is running on the same machine with @value{GDBN}
35414or GDBserver, so it doesn't have to handle as much differences between
35415two ends as remote protocol (@pxref{Remote Protocol}) tries to handle.
35416However, there are still some differences of two ends in two processes:
35417
35418@enumerate
35419@item
35420word size. On some 64-bit machines, @value{GDBN} or GDBserver can be
35421compiled as a 64-bit executable, while in-process agent is a 32-bit one.
35422@item
35423ABI. Some machines may have multiple types of ABI, @value{GDBN} or
35424GDBserver is compiled with one, and in-process agent is compiled with
35425the other one.
35426@end enumerate
35427
35428Here are the IPA Protocol Objects:
35429
35430@enumerate
35431@item
35432agent expression object. It represents an agent expression
35433(@pxref{Agent Expressions}).
35434@anchor{agent expression object}
35435@item
35436tracepoint action object. It represents a tracepoint action
35437(@pxref{Tracepoint Actions,,Tracepoint Action Lists}) to collect registers,
35438memory, static trace data and to evaluate expression.
35439@anchor{tracepoint action object}
35440@item
35441tracepoint object. It represents a tracepoint (@pxref{Tracepoints}).
35442@anchor{tracepoint object}
35443
35444@end enumerate
35445
35446The following table describes important attributes of each IPA protocol
35447object:
35448
35449@multitable @columnfractions .30 .20 .50
35450@headitem Name @tab Size @tab Description
35451@item @emph{agent expression object} @tab @tab
35452@item length @tab 4 @tab length of bytes code
35453@item byte code @tab @var{length} @tab contents of byte code
35454@item @emph{tracepoint action for collecting memory} @tab @tab
35455@item 'M' @tab 1 @tab type of tracepoint action
35456@item addr @tab 8 @tab if @var{basereg} is @samp{-1}, @var{addr} is the
35457address of the lowest byte to collect, otherwise @var{addr} is the offset
35458of @var{basereg} for memory collecting.
35459@item len @tab 8 @tab length of memory for collecting
35460@item basereg @tab 4 @tab the register number containing the starting
35461memory address for collecting.
35462@item @emph{tracepoint action for collecting registers} @tab @tab
35463@item 'R' @tab 1 @tab type of tracepoint action
35464@item @emph{tracepoint action for collecting static trace data} @tab @tab
35465@item 'L' @tab 1 @tab type of tracepoint action
35466@item @emph{tracepoint action for expression evaluation} @tab @tab
35467@item 'X' @tab 1 @tab type of tracepoint action
35468@item agent expression @tab length of @tab @ref{agent expression object}
35469@item @emph{tracepoint object} @tab @tab
35470@item number @tab 4 @tab number of tracepoint
35471@item address @tab 8 @tab address of tracepoint inserted on
35472@item type @tab 4 @tab type of tracepoint
35473@item enabled @tab 1 @tab enable or disable of tracepoint
35474@item step_count @tab 8 @tab step
35475@item pass_count @tab 8 @tab pass
35476@item numactions @tab 4 @tab number of tracepoint actions
35477@item hit count @tab 8 @tab hit count
35478@item trace frame usage @tab 8 @tab trace frame usage
35479@item compiled_cond @tab 8 @tab compiled condition
35480@item orig_size @tab 8 @tab orig size
35481@item condition @tab 4 if condition is NULL otherwise length of
35482@ref{agent expression object}
35483@tab zero if condition is NULL, otherwise is
35484@ref{agent expression object}
35485@item actions @tab variable
35486@tab numactions number of @ref{tracepoint action object}
35487@end multitable
35488
35489@node IPA Protocol Commands
35490@subsection IPA Protocol Commands
35491@cindex ipa protocol commands
35492
35493The spaces in each command are delimiters to ease reading this commands
35494specification. They don't exist in real commands.
35495
35496@table @samp
35497
35498@item FastTrace:@var{tracepoint_object} @var{gdb_jump_pad_head}
35499Installs a new fast tracepoint described by @var{tracepoint_object}
697aa1b7 35500(@pxref{tracepoint object}). The @var{gdb_jump_pad_head}, 8-byte long, is the
16bdd41f
YQ
35501head of @dfn{jumppad}, which is used to jump to data collection routine
35502in IPA finally.
35503
35504Replies:
35505@table @samp
35506@item OK @var{target_address} @var{gdb_jump_pad_head} @var{fjump_size} @var{fjump}
35507@var{target_address} is address of tracepoint in the inferior.
697aa1b7 35508The @var{gdb_jump_pad_head} is updated head of jumppad. Both of
16bdd41f 35509@var{target_address} and @var{gdb_jump_pad_head} are 8-byte long.
697aa1b7
EZ
35510The @var{fjump} contains a sequence of instructions jump to jumppad entry.
35511The @var{fjump_size}, 4-byte long, is the size of @var{fjump}.
16bdd41f
YQ
35512@item E @var{NN}
35513for an error
35514
35515@end table
35516
7255706c
YQ
35517@item close
35518Closes the in-process agent. This command is sent when @value{GDBN} or GDBserver
35519is about to kill inferiors.
35520
16bdd41f
YQ
35521@item qTfSTM
35522@xref{qTfSTM}.
35523@item qTsSTM
35524@xref{qTsSTM}.
35525@item qTSTMat
35526@xref{qTSTMat}.
35527@item probe_marker_at:@var{address}
35528Asks in-process agent to probe the marker at @var{address}.
35529
35530Replies:
35531@table @samp
35532@item E @var{NN}
35533for an error
35534@end table
35535@item unprobe_marker_at:@var{address}
35536Asks in-process agent to unprobe the marker at @var{address}.
35537@end table
35538
8e04817f
AC
35539@node GDB Bugs
35540@chapter Reporting Bugs in @value{GDBN}
35541@cindex bugs in @value{GDBN}
35542@cindex reporting bugs in @value{GDBN}
c906108c 35543
8e04817f 35544Your bug reports play an essential role in making @value{GDBN} reliable.
c906108c 35545
8e04817f
AC
35546Reporting a bug may help you by bringing a solution to your problem, or it
35547may not. But in any case the principal function of a bug report is to help
35548the entire community by making the next version of @value{GDBN} work better. Bug
35549reports are your contribution to the maintenance of @value{GDBN}.
c906108c 35550
8e04817f
AC
35551In order for a bug report to serve its purpose, you must include the
35552information that enables us to fix the bug.
c4555f82
SC
35553
35554@menu
8e04817f
AC
35555* Bug Criteria:: Have you found a bug?
35556* Bug Reporting:: How to report bugs
c4555f82
SC
35557@end menu
35558
8e04817f 35559@node Bug Criteria
79a6e687 35560@section Have You Found a Bug?
8e04817f 35561@cindex bug criteria
c4555f82 35562
8e04817f 35563If you are not sure whether you have found a bug, here are some guidelines:
c4555f82
SC
35564
35565@itemize @bullet
8e04817f
AC
35566@cindex fatal signal
35567@cindex debugger crash
35568@cindex crash of debugger
c4555f82 35569@item
8e04817f
AC
35570If the debugger gets a fatal signal, for any input whatever, that is a
35571@value{GDBN} bug. Reliable debuggers never crash.
35572
35573@cindex error on valid input
35574@item
35575If @value{GDBN} produces an error message for valid input, that is a
35576bug. (Note that if you're cross debugging, the problem may also be
35577somewhere in the connection to the target.)
c4555f82 35578
8e04817f 35579@cindex invalid input
c4555f82 35580@item
8e04817f
AC
35581If @value{GDBN} does not produce an error message for invalid input,
35582that is a bug. However, you should note that your idea of
35583``invalid input'' might be our idea of ``an extension'' or ``support
35584for traditional practice''.
35585
35586@item
35587If you are an experienced user of debugging tools, your suggestions
35588for improvement of @value{GDBN} are welcome in any case.
c4555f82
SC
35589@end itemize
35590
8e04817f 35591@node Bug Reporting
79a6e687 35592@section How to Report Bugs
8e04817f
AC
35593@cindex bug reports
35594@cindex @value{GDBN} bugs, reporting
35595
35596A number of companies and individuals offer support for @sc{gnu} products.
35597If you obtained @value{GDBN} from a support organization, we recommend you
35598contact that organization first.
35599
35600You can find contact information for many support companies and
35601individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
35602distribution.
35603@c should add a web page ref...
35604
c16158bc
JM
35605@ifset BUGURL
35606@ifset BUGURL_DEFAULT
129188f6 35607In any event, we also recommend that you submit bug reports for
d3e8051b 35608@value{GDBN}. The preferred method is to submit them directly using
129188f6
AC
35609@uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
35610page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
35611be used.
8e04817f
AC
35612
35613@strong{Do not send bug reports to @samp{info-gdb}, or to
35614@samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
35615not want to receive bug reports. Those that do have arranged to receive
35616@samp{bug-gdb}.
35617
35618The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
35619serves as a repeater. The mailing list and the newsgroup carry exactly
35620the same messages. Often people think of posting bug reports to the
35621newsgroup instead of mailing them. This appears to work, but it has one
35622problem which can be crucial: a newsgroup posting often lacks a mail
35623path back to the sender. Thus, if we need to ask for more information,
35624we may be unable to reach you. For this reason, it is better to send
35625bug reports to the mailing list.
c16158bc
JM
35626@end ifset
35627@ifclear BUGURL_DEFAULT
35628In any event, we also recommend that you submit bug reports for
35629@value{GDBN} to @value{BUGURL}.
35630@end ifclear
35631@end ifset
c4555f82 35632
8e04817f
AC
35633The fundamental principle of reporting bugs usefully is this:
35634@strong{report all the facts}. If you are not sure whether to state a
35635fact or leave it out, state it!
c4555f82 35636
8e04817f
AC
35637Often people omit facts because they think they know what causes the
35638problem and assume that some details do not matter. Thus, you might
35639assume that the name of the variable you use in an example does not matter.
35640Well, probably it does not, but one cannot be sure. Perhaps the bug is a
35641stray memory reference which happens to fetch from the location where that
35642name is stored in memory; perhaps, if the name were different, the contents
35643of that location would fool the debugger into doing the right thing despite
35644the bug. Play it safe and give a specific, complete example. That is the
35645easiest thing for you to do, and the most helpful.
c4555f82 35646
8e04817f
AC
35647Keep in mind that the purpose of a bug report is to enable us to fix the
35648bug. It may be that the bug has been reported previously, but neither
35649you nor we can know that unless your bug report is complete and
35650self-contained.
c4555f82 35651
8e04817f
AC
35652Sometimes people give a few sketchy facts and ask, ``Does this ring a
35653bell?'' Those bug reports are useless, and we urge everyone to
35654@emph{refuse to respond to them} except to chide the sender to report
35655bugs properly.
35656
35657To enable us to fix the bug, you should include all these things:
c4555f82
SC
35658
35659@itemize @bullet
35660@item
8e04817f
AC
35661The version of @value{GDBN}. @value{GDBN} announces it if you start
35662with no arguments; you can also print it at any time using @code{show
35663version}.
c4555f82 35664
8e04817f
AC
35665Without this, we will not know whether there is any point in looking for
35666the bug in the current version of @value{GDBN}.
c4555f82
SC
35667
35668@item
8e04817f
AC
35669The type of machine you are using, and the operating system name and
35670version number.
c4555f82 35671
6eaaf48b
EZ
35672@item
35673The details of the @value{GDBN} build-time configuration.
35674@value{GDBN} shows these details if you invoke it with the
35675@option{--configuration} command-line option, or if you type
35676@code{show configuration} at @value{GDBN}'s prompt.
35677
c4555f82 35678@item
c1468174 35679What compiler (and its version) was used to compile @value{GDBN}---e.g.@:
8e04817f 35680``@value{GCC}--2.8.1''.
c4555f82
SC
35681
35682@item
8e04817f 35683What compiler (and its version) was used to compile the program you are
c1468174 35684debugging---e.g.@: ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
3f94c067
BW
35685C Compiler''. For @value{NGCC}, you can say @kbd{@value{GCC} --version}
35686to get this information; for other compilers, see the documentation for
35687those compilers.
c4555f82 35688
8e04817f
AC
35689@item
35690The command arguments you gave the compiler to compile your example and
35691observe the bug. For example, did you use @samp{-O}? To guarantee
35692you will not omit something important, list them all. A copy of the
35693Makefile (or the output from make) is sufficient.
c4555f82 35694
8e04817f
AC
35695If we were to try to guess the arguments, we would probably guess wrong
35696and then we might not encounter the bug.
c4555f82 35697
8e04817f
AC
35698@item
35699A complete input script, and all necessary source files, that will
35700reproduce the bug.
c4555f82 35701
8e04817f
AC
35702@item
35703A description of what behavior you observe that you believe is
35704incorrect. For example, ``It gets a fatal signal.''
c4555f82 35705
8e04817f
AC
35706Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
35707will certainly notice it. But if the bug is incorrect output, we might
35708not notice unless it is glaringly wrong. You might as well not give us
35709a chance to make a mistake.
c4555f82 35710
8e04817f
AC
35711Even if the problem you experience is a fatal signal, you should still
35712say so explicitly. Suppose something strange is going on, such as, your
35713copy of @value{GDBN} is out of synch, or you have encountered a bug in
35714the C library on your system. (This has happened!) Your copy might
35715crash and ours would not. If you told us to expect a crash, then when
35716ours fails to crash, we would know that the bug was not happening for
35717us. If you had not told us to expect a crash, then we would not be able
35718to draw any conclusion from our observations.
c4555f82 35719
e0c07bf0
MC
35720@pindex script
35721@cindex recording a session script
35722To collect all this information, you can use a session recording program
35723such as @command{script}, which is available on many Unix systems.
35724Just run your @value{GDBN} session inside @command{script} and then
35725include the @file{typescript} file with your bug report.
35726
35727Another way to record a @value{GDBN} session is to run @value{GDBN}
35728inside Emacs and then save the entire buffer to a file.
35729
8e04817f
AC
35730@item
35731If you wish to suggest changes to the @value{GDBN} source, send us context
35732diffs. If you even discuss something in the @value{GDBN} source, refer to
35733it by context, not by line number.
c4555f82 35734
8e04817f
AC
35735The line numbers in our development sources will not match those in your
35736sources. Your line numbers would convey no useful information to us.
c4555f82 35737
8e04817f 35738@end itemize
c4555f82 35739
8e04817f 35740Here are some things that are not necessary:
c4555f82 35741
8e04817f
AC
35742@itemize @bullet
35743@item
35744A description of the envelope of the bug.
c4555f82 35745
8e04817f
AC
35746Often people who encounter a bug spend a lot of time investigating
35747which changes to the input file will make the bug go away and which
35748changes will not affect it.
c4555f82 35749
8e04817f
AC
35750This is often time consuming and not very useful, because the way we
35751will find the bug is by running a single example under the debugger
35752with breakpoints, not by pure deduction from a series of examples.
35753We recommend that you save your time for something else.
c4555f82 35754
8e04817f
AC
35755Of course, if you can find a simpler example to report @emph{instead}
35756of the original one, that is a convenience for us. Errors in the
35757output will be easier to spot, running under the debugger will take
35758less time, and so on.
c4555f82 35759
8e04817f
AC
35760However, simplification is not vital; if you do not want to do this,
35761report the bug anyway and send us the entire test case you used.
c4555f82 35762
8e04817f
AC
35763@item
35764A patch for the bug.
c4555f82 35765
8e04817f
AC
35766A patch for the bug does help us if it is a good one. But do not omit
35767the necessary information, such as the test case, on the assumption that
35768a patch is all we need. We might see problems with your patch and decide
35769to fix the problem another way, or we might not understand it at all.
c4555f82 35770
8e04817f
AC
35771Sometimes with a program as complicated as @value{GDBN} it is very hard to
35772construct an example that will make the program follow a certain path
35773through the code. If you do not send us the example, we will not be able
35774to construct one, so we will not be able to verify that the bug is fixed.
c4555f82 35775
8e04817f
AC
35776And if we cannot understand what bug you are trying to fix, or why your
35777patch should be an improvement, we will not install it. A test case will
35778help us to understand.
c4555f82 35779
8e04817f
AC
35780@item
35781A guess about what the bug is or what it depends on.
c4555f82 35782
8e04817f
AC
35783Such guesses are usually wrong. Even we cannot guess right about such
35784things without first using the debugger to find the facts.
35785@end itemize
c4555f82 35786
8e04817f
AC
35787@c The readline documentation is distributed with the readline code
35788@c and consists of the two following files:
cc88a640
JK
35789@c rluser.texi
35790@c hsuser.texi
8e04817f
AC
35791@c Use -I with makeinfo to point to the appropriate directory,
35792@c environment var TEXINPUTS with TeX.
39037522 35793@ifclear SYSTEM_READLINE
5bdf8622 35794@include rluser.texi
cc88a640 35795@include hsuser.texi
39037522 35796@end ifclear
c4555f82 35797
4ceed123
JB
35798@node In Memoriam
35799@appendix In Memoriam
35800
9ed350ad
JB
35801The @value{GDBN} project mourns the loss of the following long-time
35802contributors:
4ceed123
JB
35803
35804@table @code
35805@item Fred Fish
9ed350ad
JB
35806Fred was a long-standing contributor to @value{GDBN} (1991-2006), and
35807to Free Software in general. Outside of @value{GDBN}, he was known in
35808the Amiga world for his series of Fish Disks, and the GeekGadget project.
4ceed123
JB
35809
35810@item Michael Snyder
9ed350ad
JB
35811Michael was one of the Global Maintainers of the @value{GDBN} project,
35812with contributions recorded as early as 1996, until 2011. In addition
35813to his day to day participation, he was a large driving force behind
35814adding Reverse Debugging to @value{GDBN}.
4ceed123
JB
35815@end table
35816
35817Beyond their technical contributions to the project, they were also
35818enjoyable members of the Free Software Community. We will miss them.
c4555f82 35819
8e04817f
AC
35820@node Formatting Documentation
35821@appendix Formatting Documentation
c4555f82 35822
8e04817f
AC
35823@cindex @value{GDBN} reference card
35824@cindex reference card
35825The @value{GDBN} 4 release includes an already-formatted reference card, ready
35826for printing with PostScript or Ghostscript, in the @file{gdb}
35827subdirectory of the main source directory@footnote{In
35828@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
35829release.}. If you can use PostScript or Ghostscript with your printer,
35830you can print the reference card immediately with @file{refcard.ps}.
c4555f82 35831
8e04817f
AC
35832The release also includes the source for the reference card. You
35833can format it, using @TeX{}, by typing:
c4555f82 35834
474c8240 35835@smallexample
8e04817f 35836make refcard.dvi
474c8240 35837@end smallexample
c4555f82 35838
8e04817f
AC
35839The @value{GDBN} reference card is designed to print in @dfn{landscape}
35840mode on US ``letter'' size paper;
35841that is, on a sheet 11 inches wide by 8.5 inches
35842high. You will need to specify this form of printing as an option to
35843your @sc{dvi} output program.
c4555f82 35844
8e04817f 35845@cindex documentation
c4555f82 35846
8e04817f
AC
35847All the documentation for @value{GDBN} comes as part of the machine-readable
35848distribution. The documentation is written in Texinfo format, which is
35849a documentation system that uses a single source file to produce both
35850on-line information and a printed manual. You can use one of the Info
35851formatting commands to create the on-line version of the documentation
35852and @TeX{} (or @code{texi2roff}) to typeset the printed version.
c4555f82 35853
8e04817f
AC
35854@value{GDBN} includes an already formatted copy of the on-line Info
35855version of this manual in the @file{gdb} subdirectory. The main Info
35856file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
35857subordinate files matching @samp{gdb.info*} in the same directory. If
35858necessary, you can print out these files, or read them with any editor;
35859but they are easier to read using the @code{info} subsystem in @sc{gnu}
35860Emacs or the standalone @code{info} program, available as part of the
35861@sc{gnu} Texinfo distribution.
c4555f82 35862
8e04817f
AC
35863If you want to format these Info files yourself, you need one of the
35864Info formatting programs, such as @code{texinfo-format-buffer} or
35865@code{makeinfo}.
c4555f82 35866
8e04817f
AC
35867If you have @code{makeinfo} installed, and are in the top level
35868@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
35869version @value{GDBVN}), you can make the Info file by typing:
c4555f82 35870
474c8240 35871@smallexample
8e04817f
AC
35872cd gdb
35873make gdb.info
474c8240 35874@end smallexample
c4555f82 35875
8e04817f
AC
35876If you want to typeset and print copies of this manual, you need @TeX{},
35877a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
35878Texinfo definitions file.
c4555f82 35879
8e04817f
AC
35880@TeX{} is a typesetting program; it does not print files directly, but
35881produces output files called @sc{dvi} files. To print a typeset
35882document, you need a program to print @sc{dvi} files. If your system
35883has @TeX{} installed, chances are it has such a program. The precise
35884command to use depends on your system; @kbd{lpr -d} is common; another
35885(for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
35886require a file name without any extension or a @samp{.dvi} extension.
c4555f82 35887
8e04817f
AC
35888@TeX{} also requires a macro definitions file called
35889@file{texinfo.tex}. This file tells @TeX{} how to typeset a document
35890written in Texinfo format. On its own, @TeX{} cannot either read or
35891typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
35892and is located in the @file{gdb-@var{version-number}/texinfo}
35893directory.
c4555f82 35894
8e04817f 35895If you have @TeX{} and a @sc{dvi} printer program installed, you can
d3e8051b 35896typeset and print this manual. First switch to the @file{gdb}
8e04817f
AC
35897subdirectory of the main source directory (for example, to
35898@file{gdb-@value{GDBVN}/gdb}) and type:
c4555f82 35899
474c8240 35900@smallexample
8e04817f 35901make gdb.dvi
474c8240 35902@end smallexample
c4555f82 35903
8e04817f 35904Then give @file{gdb.dvi} to your @sc{dvi} printing program.
c4555f82 35905
8e04817f
AC
35906@node Installing GDB
35907@appendix Installing @value{GDBN}
8e04817f 35908@cindex installation
c4555f82 35909
7fa2210b
DJ
35910@menu
35911* Requirements:: Requirements for building @value{GDBN}
db2e3e2e 35912* Running Configure:: Invoking the @value{GDBN} @file{configure} script
7fa2210b
DJ
35913* Separate Objdir:: Compiling @value{GDBN} in another directory
35914* Config Names:: Specifying names for hosts and targets
35915* Configure Options:: Summary of options for configure
098b41a6 35916* System-wide configuration:: Having a system-wide init file
7fa2210b
DJ
35917@end menu
35918
35919@node Requirements
79a6e687 35920@section Requirements for Building @value{GDBN}
7fa2210b
DJ
35921@cindex building @value{GDBN}, requirements for
35922
35923Building @value{GDBN} requires various tools and packages to be available.
35924Other packages will be used only if they are found.
35925
79a6e687 35926@heading Tools/Packages Necessary for Building @value{GDBN}
7fa2210b 35927@table @asis
7f0bd420
TT
35928@item C@t{++}11 compiler
35929@value{GDBN} is written in C@t{++}11. It should be buildable with any
35930recent C@t{++}11 compiler, e.g.@: GCC.
7fa2210b 35931
7f0bd420
TT
35932@item GNU make
35933@value{GDBN}'s build system relies on features only found in the GNU
35934make program. Other variants of @code{make} will not work.
7fa2210b
DJ
35935@end table
35936
79a6e687 35937@heading Tools/Packages Optional for Building @value{GDBN}
7fa2210b
DJ
35938@table @asis
35939@item Expat
123dc839 35940@anchor{Expat}
7fa2210b
DJ
35941@value{GDBN} can use the Expat XML parsing library. This library may be
35942included with your operating system distribution; if it is not, you
35943can get the latest version from @url{http://expat.sourceforge.net}.
db2e3e2e 35944The @file{configure} script will search for this library in several
7fa2210b
DJ
35945standard locations; if it is installed in an unusual path, you can
35946use the @option{--with-libexpat-prefix} option to specify its location.
35947
9cceb671
DJ
35948Expat is used for:
35949
35950@itemize @bullet
35951@item
35952Remote protocol memory maps (@pxref{Memory Map Format})
35953@item
35954Target descriptions (@pxref{Target Descriptions})
35955@item
2268b414
JK
35956Remote shared library lists (@xref{Library List Format},
35957or alternatively @pxref{Library List Format for SVR4 Targets})
9cceb671
DJ
35958@item
35959MS-Windows shared libraries (@pxref{Shared Libraries})
b3b9301e
PA
35960@item
35961Traceframe info (@pxref{Traceframe Info Format})
2ae8c8e7 35962@item
f4abbc16
MM
35963Branch trace (@pxref{Branch Trace Format},
35964@pxref{Branch Trace Configuration Format})
9cceb671 35965@end itemize
7fa2210b 35966
7f0bd420
TT
35967@item Guile
35968@value{GDBN} can be scripted using GNU Guile. @xref{Guile}. By
35969default, @value{GDBN} will be compiled if the Guile libraries are
35970installed and are found by @file{configure}. You can use the
35971@code{--with-guile} option to request Guile, and pass either the Guile
35972version number or the file name of the relevant @code{pkg-config}
35973program to choose a particular version of Guile.
35974
35975@item iconv
35976@value{GDBN}'s features related to character sets (@pxref{Character
35977Sets}) require a functioning @code{iconv} implementation. If you are
35978on a GNU system, then this is provided by the GNU C Library. Some
35979other systems also provide a working @code{iconv}.
35980
35981If @value{GDBN} is using the @code{iconv} program which is installed
35982in a non-standard place, you will need to tell @value{GDBN} where to
35983find it. This is done with @option{--with-iconv-bin} which specifies
35984the directory that contains the @code{iconv} program. This program is
35985run in order to make a list of the available character sets.
35986
35987On systems without @code{iconv}, you can install GNU Libiconv. If
35988Libiconv is installed in a standard place, @value{GDBN} will
35989automatically use it if it is needed. If you have previously
35990installed Libiconv in a non-standard place, you can use the
35991@option{--with-libiconv-prefix} option to @file{configure}.
35992
35993@value{GDBN}'s top-level @file{configure} and @file{Makefile} will
35994arrange to build Libiconv if a directory named @file{libiconv} appears
35995in the top-most source directory. If Libiconv is built this way, and
35996if the operating system does not provide a suitable @code{iconv}
35997implementation, then the just-built library will automatically be used
35998by @value{GDBN}. One easy way to set this up is to download GNU
35999Libiconv, unpack it inside the top-level directory of the @value{GDBN}
36000source tree, and then rename the directory holding the Libiconv source
36001code to @samp{libiconv}.
36002
36003@item lzma
36004@value{GDBN} can support debugging sections that are compressed with
36005the LZMA library. @xref{MiniDebugInfo}. If this library is not
36006included with your operating system, you can find it in the xz package
36007at @url{http://tukaani.org/xz/}. If the LZMA library is available in
36008the usual place, then the @file{configure} script will use it
36009automatically. If it is installed in an unusual path, you can use the
36010@option{--with-lzma-prefix} option to specify its location.
36011
2400729e
UW
36012@item MPFR
36013@anchor{MPFR}
36014@value{GDBN} can use the GNU MPFR multiple-precision floating-point
36015library. This library may be included with your operating system
36016distribution; if it is not, you can get the latest version from
36017@url{http://www.mpfr.org}. The @file{configure} script will search
36018for this library in several standard locations; if it is installed
36019in an unusual path, you can use the @option{--with-libmpfr-prefix}
36020option to specify its location.
36021
36022GNU MPFR is used to emulate target floating-point arithmetic during
36023expression evaluation when the target uses different floating-point
36024formats than the host. If GNU MPFR it is not available, @value{GDBN}
36025will fall back to using host floating-point arithmetic.
36026
7f0bd420
TT
36027@item Python
36028@value{GDBN} can be scripted using Python language. @xref{Python}.
36029By default, @value{GDBN} will be compiled if the Python libraries are
36030installed and are found by @file{configure}. You can use the
36031@code{--with-python} option to request Python, and pass either the
36032file name of the relevant @code{python} executable, or the name of the
36033directory in which Python is installed, to choose a particular
36034installation of Python.
36035
31fffb02
CS
36036@item zlib
36037@cindex compressed debug sections
36038@value{GDBN} will use the @samp{zlib} library, if available, to read
36039compressed debug sections. Some linkers, such as GNU gold, are capable
36040of producing binaries with compressed debug sections. If @value{GDBN}
36041is compiled with @samp{zlib}, it will be able to read the debug
36042information in such binaries.
36043
36044The @samp{zlib} library is likely included with your operating system
36045distribution; if it is not, you can get the latest version from
36046@url{http://zlib.net}.
7fa2210b
DJ
36047@end table
36048
36049@node Running Configure
db2e3e2e 36050@section Invoking the @value{GDBN} @file{configure} Script
7fa2210b 36051@cindex configuring @value{GDBN}
db2e3e2e 36052@value{GDBN} comes with a @file{configure} script that automates the process
8e04817f
AC
36053of preparing @value{GDBN} for installation; you can then use @code{make} to
36054build the @code{gdb} program.
36055@iftex
36056@c irrelevant in info file; it's as current as the code it lives with.
36057@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
36058look at the @file{README} file in the sources; we may have improved the
36059installation procedures since publishing this manual.}
36060@end iftex
c4555f82 36061
8e04817f
AC
36062The @value{GDBN} distribution includes all the source code you need for
36063@value{GDBN} in a single directory, whose name is usually composed by
36064appending the version number to @samp{gdb}.
c4555f82 36065
8e04817f
AC
36066For example, the @value{GDBN} version @value{GDBVN} distribution is in the
36067@file{gdb-@value{GDBVN}} directory. That directory contains:
c4555f82 36068
8e04817f
AC
36069@table @code
36070@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
36071script for configuring @value{GDBN} and all its supporting libraries
c4555f82 36072
8e04817f
AC
36073@item gdb-@value{GDBVN}/gdb
36074the source specific to @value{GDBN} itself
c4555f82 36075
8e04817f
AC
36076@item gdb-@value{GDBVN}/bfd
36077source for the Binary File Descriptor library
c906108c 36078
8e04817f
AC
36079@item gdb-@value{GDBVN}/include
36080@sc{gnu} include files
c906108c 36081
8e04817f
AC
36082@item gdb-@value{GDBVN}/libiberty
36083source for the @samp{-liberty} free software library
c906108c 36084
8e04817f
AC
36085@item gdb-@value{GDBVN}/opcodes
36086source for the library of opcode tables and disassemblers
c906108c 36087
8e04817f
AC
36088@item gdb-@value{GDBVN}/readline
36089source for the @sc{gnu} command-line interface
8e04817f 36090@end table
c906108c 36091
7f0bd420
TT
36092There may be other subdirectories as well.
36093
db2e3e2e 36094The simplest way to configure and build @value{GDBN} is to run @file{configure}
8e04817f
AC
36095from the @file{gdb-@var{version-number}} source directory, which in
36096this example is the @file{gdb-@value{GDBVN}} directory.
c906108c 36097
8e04817f 36098First switch to the @file{gdb-@var{version-number}} source directory
db2e3e2e 36099if you are not already in it; then run @file{configure}. Pass the
8e04817f
AC
36100identifier for the platform on which @value{GDBN} will run as an
36101argument.
c906108c 36102
8e04817f 36103For example:
c906108c 36104
474c8240 36105@smallexample
8e04817f 36106cd gdb-@value{GDBVN}
7f0bd420 36107./configure
8e04817f 36108make
474c8240 36109@end smallexample
c906108c 36110
7f0bd420
TT
36111Running @samp{configure} and then running @code{make} builds the
36112included supporting libraries, then @code{gdb} itself. The configured
36113source files, and the binaries, are left in the corresponding source
36114directories.
c906108c 36115
8e04817f 36116@need 750
db2e3e2e 36117@file{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
8e04817f
AC
36118system does not recognize this automatically when you run a different
36119shell, you may need to run @code{sh} on it explicitly:
c906108c 36120
474c8240 36121@smallexample
7f0bd420 36122sh configure
474c8240 36123@end smallexample
c906108c 36124
db2e3e2e 36125You should run the @file{configure} script from the top directory in the
94e91d6d 36126source tree, the @file{gdb-@var{version-number}} directory. If you run
db2e3e2e 36127@file{configure} from one of the subdirectories, you will configure only
94e91d6d 36128that subdirectory. That is usually not what you want. In particular,
db2e3e2e 36129if you run the first @file{configure} from the @file{gdb} subdirectory
94e91d6d
MC
36130of the @file{gdb-@var{version-number}} directory, you will omit the
36131configuration of @file{bfd}, @file{readline}, and other sibling
36132directories of the @file{gdb} subdirectory. This leads to build errors
36133about missing include files such as @file{bfd/bfd.h}.
c906108c 36134
7f0bd420
TT
36135You can install @code{@value{GDBN}} anywhere. The best way to do this
36136is to pass the @code{--prefix} option to @code{configure}, and then
36137install it with @code{make install}.
c906108c 36138
8e04817f 36139@node Separate Objdir
79a6e687 36140@section Compiling @value{GDBN} in Another Directory
c906108c 36141
8e04817f
AC
36142If you want to run @value{GDBN} versions for several host or target machines,
36143you need a different @code{gdb} compiled for each combination of
db2e3e2e 36144host and target. @file{configure} is designed to make this easy by
8e04817f
AC
36145allowing you to generate each configuration in a separate subdirectory,
36146rather than in the source directory. If your @code{make} program
36147handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
36148@code{make} in each of these directories builds the @code{gdb}
36149program specified there.
c906108c 36150
db2e3e2e 36151To build @code{gdb} in a separate directory, run @file{configure}
8e04817f 36152with the @samp{--srcdir} option to specify where to find the source.
db2e3e2e
BW
36153(You also need to specify a path to find @file{configure}
36154itself from your working directory. If the path to @file{configure}
8e04817f
AC
36155would be the same as the argument to @samp{--srcdir}, you can leave out
36156the @samp{--srcdir} option; it is assumed.)
c906108c 36157
8e04817f
AC
36158For example, with version @value{GDBVN}, you can build @value{GDBN} in a
36159separate directory for a Sun 4 like this:
c906108c 36160
474c8240 36161@smallexample
8e04817f
AC
36162@group
36163cd gdb-@value{GDBVN}
36164mkdir ../gdb-sun4
36165cd ../gdb-sun4
7f0bd420 36166../gdb-@value{GDBVN}/configure
8e04817f
AC
36167make
36168@end group
474c8240 36169@end smallexample
c906108c 36170
db2e3e2e 36171When @file{configure} builds a configuration using a remote source
8e04817f
AC
36172directory, it creates a tree for the binaries with the same structure
36173(and using the same names) as the tree under the source directory. In
36174the example, you'd find the Sun 4 library @file{libiberty.a} in the
36175directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
36176@file{gdb-sun4/gdb}.
c906108c 36177
94e91d6d
MC
36178Make sure that your path to the @file{configure} script has just one
36179instance of @file{gdb} in it. If your path to @file{configure} looks
36180like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
36181one subdirectory of @value{GDBN}, not the whole package. This leads to
36182build errors about missing include files such as @file{bfd/bfd.h}.
36183
8e04817f
AC
36184One popular reason to build several @value{GDBN} configurations in separate
36185directories is to configure @value{GDBN} for cross-compiling (where
36186@value{GDBN} runs on one machine---the @dfn{host}---while debugging
36187programs that run on another machine---the @dfn{target}).
36188You specify a cross-debugging target by
db2e3e2e 36189giving the @samp{--target=@var{target}} option to @file{configure}.
c906108c 36190
8e04817f
AC
36191When you run @code{make} to build a program or library, you must run
36192it in a configured directory---whatever directory you were in when you
db2e3e2e 36193called @file{configure} (or one of its subdirectories).
c906108c 36194
db2e3e2e 36195The @code{Makefile} that @file{configure} generates in each source
8e04817f
AC
36196directory also runs recursively. If you type @code{make} in a source
36197directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
36198directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
36199will build all the required libraries, and then build GDB.
c906108c 36200
8e04817f
AC
36201When you have multiple hosts or targets configured in separate
36202directories, you can run @code{make} on them in parallel (for example,
36203if they are NFS-mounted on each of the hosts); they will not interfere
36204with each other.
c906108c 36205
8e04817f 36206@node Config Names
79a6e687 36207@section Specifying Names for Hosts and Targets
c906108c 36208
db2e3e2e 36209The specifications used for hosts and targets in the @file{configure}
8e04817f
AC
36210script are based on a three-part naming scheme, but some short predefined
36211aliases are also supported. The full naming scheme encodes three pieces
36212of information in the following pattern:
c906108c 36213
474c8240 36214@smallexample
8e04817f 36215@var{architecture}-@var{vendor}-@var{os}
474c8240 36216@end smallexample
c906108c 36217
8e04817f
AC
36218For example, you can use the alias @code{sun4} as a @var{host} argument,
36219or as the value for @var{target} in a @code{--target=@var{target}}
36220option. The equivalent full name is @samp{sparc-sun-sunos4}.
c906108c 36221
db2e3e2e 36222The @file{configure} script accompanying @value{GDBN} does not provide
8e04817f 36223any query facility to list all supported host and target names or
db2e3e2e 36224aliases. @file{configure} calls the Bourne shell script
8e04817f
AC
36225@code{config.sub} to map abbreviations to full names; you can read the
36226script, if you wish, or you can use it to test your guesses on
36227abbreviations---for example:
c906108c 36228
8e04817f
AC
36229@smallexample
36230% sh config.sub i386-linux
36231i386-pc-linux-gnu
36232% sh config.sub alpha-linux
36233alpha-unknown-linux-gnu
36234% sh config.sub hp9k700
36235hppa1.1-hp-hpux
36236% sh config.sub sun4
36237sparc-sun-sunos4.1.1
36238% sh config.sub sun3
36239m68k-sun-sunos4.1.1
36240% sh config.sub i986v
36241Invalid configuration `i986v': machine `i986v' not recognized
36242@end smallexample
c906108c 36243
8e04817f
AC
36244@noindent
36245@code{config.sub} is also distributed in the @value{GDBN} source
36246directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
d700128c 36247
8e04817f 36248@node Configure Options
db2e3e2e 36249@section @file{configure} Options
c906108c 36250
db2e3e2e 36251Here is a summary of the @file{configure} options and arguments that
7f0bd420
TT
36252are most often useful for building @value{GDBN}. @file{configure}
36253also has several other options not listed here. @inforef{Running
36254configure scripts,,autoconf.info}, for a full
36255explanation of @file{configure}.
c906108c 36256
474c8240 36257@smallexample
8e04817f
AC
36258configure @r{[}--help@r{]}
36259 @r{[}--prefix=@var{dir}@r{]}
36260 @r{[}--exec-prefix=@var{dir}@r{]}
36261 @r{[}--srcdir=@var{dirname}@r{]}
8e04817f 36262 @r{[}--target=@var{target}@r{]}
474c8240 36263@end smallexample
c906108c 36264
8e04817f
AC
36265@noindent
36266You may introduce options with a single @samp{-} rather than
36267@samp{--} if you prefer; but you may abbreviate option names if you use
36268@samp{--}.
c906108c 36269
8e04817f
AC
36270@table @code
36271@item --help
db2e3e2e 36272Display a quick summary of how to invoke @file{configure}.
c906108c 36273
8e04817f
AC
36274@item --prefix=@var{dir}
36275Configure the source to install programs and files under directory
36276@file{@var{dir}}.
c906108c 36277
8e04817f
AC
36278@item --exec-prefix=@var{dir}
36279Configure the source to install programs under directory
36280@file{@var{dir}}.
c906108c 36281
8e04817f
AC
36282@c avoid splitting the warning from the explanation:
36283@need 2000
36284@item --srcdir=@var{dirname}
8e04817f
AC
36285Use this option to make configurations in directories separate from the
36286@value{GDBN} source directories. Among other things, you can use this to
36287build (or maintain) several configurations simultaneously, in separate
db2e3e2e 36288directories. @file{configure} writes configuration-specific files in
8e04817f 36289the current directory, but arranges for them to use the source in the
db2e3e2e 36290directory @var{dirname}. @file{configure} creates directories under
8e04817f
AC
36291the working directory in parallel to the source directories below
36292@var{dirname}.
c906108c 36293
8e04817f
AC
36294@item --target=@var{target}
36295Configure @value{GDBN} for cross-debugging programs running on the specified
36296@var{target}. Without this option, @value{GDBN} is configured to debug
36297programs that run on the same machine (@var{host}) as @value{GDBN} itself.
c906108c 36298
a95746f9
TT
36299There is no convenient way to generate a list of all available
36300targets. Also see the @code{--enable-targets} option, below.
8e04817f 36301@end table
c906108c 36302
a95746f9
TT
36303There are many other options that are specific to @value{GDBN}. This
36304lists just the most common ones; there are some very specialized
36305options not described here.
36306
36307@table @code
36308@item --enable-targets=@r{[}@var{target}@r{]}@dots{}
36309@itemx --enable-targets=all
36310Configure @value{GDBN} for cross-debugging programs running on the
36311specified list of targets. The special value @samp{all} configures
36312@value{GDBN} for debugging programs running on any target it supports.
36313
36314@item --with-gdb-datadir=@var{path}
36315Set the @value{GDBN}-specific data directory. @value{GDBN} will look
36316here for certain supporting files or scripts. This defaults to the
36317@file{gdb} subdirectory of @samp{datadi} (which can be set using
36318@code{--datadir}).
36319
36320@item --with-relocated-sources=@var{dir}
36321Sets up the default source path substitution rule so that directory
36322names recorded in debug information will be automatically adjusted for
36323any directory under @var{dir}. @var{dir} should be a subdirectory of
36324@value{GDBN}'s configured prefix, the one mentioned in the
36325@code{--prefix} or @code{--exec-prefix} options to configure. This
36326option is useful if GDB is supposed to be moved to a different place
36327after it is built.
36328
36329@item --enable-64-bit-bfd
36330Enable 64-bit support in BFD on 32-bit hosts.
36331
36332@item --disable-gdbmi
36333Build @value{GDBN} without the GDB/MI machine interface
36334(@pxref{GDB/MI}).
36335
36336@item --enable-tui
36337Build @value{GDBN} with the text-mode full-screen user interface
36338(TUI). Requires a curses library (ncurses and cursesX are also
36339supported).
36340
36341@item --with-curses
36342Use the curses library instead of the termcap library, for text-mode
36343terminal operations.
36344
36345@item --with-libunwind-ia64
36346Use the libunwind library for unwinding function call stack on ia64
36347target platforms. See http://www.nongnu.org/libunwind/index.html for
36348details.
36349
36350@item --with-system-readline
36351Use the readline library installed on the host, rather than the
36352library supplied as part of @value{GDBN}.
36353
36354@item --with-system-zlib
36355Use the zlib library installed on the host, rather than the library
36356supplied as part of @value{GDBN}.
36357
36358@item --with-expat
36359Build @value{GDBN} with Expat, a library for XML parsing. (Done by
36360default if libexpat is installed and found at configure time.) This
36361library is used to read XML files supplied with @value{GDBN}. If it
36362is unavailable, some features, such as remote protocol memory maps,
36363target descriptions, and shared library lists, that are based on XML
36364files, will not be available in @value{GDBN}. If your host does not
36365have libexpat installed, you can get the latest version from
36366`http://expat.sourceforge.net'.
36367
36368@item --with-libiconv-prefix@r{[}=@var{dir}@r{]}
36369
36370Build @value{GDBN} with GNU libiconv, a character set encoding
36371conversion library. This is not done by default, as on GNU systems
36372the @code{iconv} that is built in to the C library is sufficient. If
36373your host does not have a working @code{iconv}, you can get the latest
36374version of GNU iconv from `https://www.gnu.org/software/libiconv/'.
36375
36376@value{GDBN}'s build system also supports building GNU libiconv as
36377part of the overall build. @xref{Requirements}.
36378
36379@item --with-lzma
36380Build @value{GDBN} with LZMA, a compression library. (Done by default
36381if liblzma is installed and found at configure time.) LZMA is used by
36382@value{GDBN}'s "mini debuginfo" feature, which is only useful on
36383platforms using the ELF object file format. If your host does not
36384have liblzma installed, you can get the latest version from
36385`https://tukaani.org/xz/'.
36386
36387@item --with-mpfr
36388Build @value{GDBN} with GNU MPFR, a library for multiple-precision
36389floating-point computation with correct rounding. (Done by default if
36390GNU MPFR is installed and found at configure time.) This library is
36391used to emulate target floating-point arithmetic during expression
36392evaluation when the target uses different floating-point formats than
36393the host. If GNU MPFR is not available, @value{GDBN} will fall back
36394to using host floating-point arithmetic. If your host does not have
36395GNU MPFR installed, you can get the latest version from
36396`http://www.mpfr.org'.
36397
36398@item --with-python@r{[}=@var{python}@r{]}
36399Build @value{GDBN} with Python scripting support. (Done by default if
36400libpython is present and found at configure time.) Python makes
36401@value{GDBN} scripting much more powerful than the restricted CLI
36402scripting language. If your host does not have Python installed, you
36403can find it on `http://www.python.org/download/'. The oldest version
2c3fc25d 36404of Python supported by GDB is 2.6. The optional argument @var{python}
a95746f9
TT
36405is used to find the Python headers and libraries. It can be either
36406the name of a Python executable, or the name of the directory in which
36407Python is installed.
36408
36409@item --with-guile[=GUILE]'
36410Build @value{GDBN} with GNU Guile scripting support. (Done by default
36411if libguile is present and found at configure time.) If your host
36412does not have Guile installed, you can find it at
36413`https://www.gnu.org/software/guile/'. The optional argument GUILE
36414can be a version number, which will cause @code{configure} to try to
36415use that version of Guile; or the file name of a @code{pkg-config}
36416executable, which will be queried to find the information needed to
36417compile and link against Guile.
36418
36419@item --without-included-regex
36420Don't use the regex library included with @value{GDBN} (as part of the
36421libiberty library). This is the default on hosts with version 2 of
36422the GNU C library.
36423
36424@item --with-sysroot=@var{dir}
36425Use @var{dir} as the default system root directory for libraries whose
36426file names begin with @file{/lib}' or @file{/usr/lib'}. (The value of
36427@var{dir} can be modified at run time by using the @command{set
36428sysroot} command.) If @var{dir} is under the @value{GDBN} configured
36429prefix (set with @code{--prefix} or @code{--exec-prefix options}, the
36430default system root will be automatically adjusted if and when
36431@value{GDBN} is moved to a different location.
36432
36433@item --with-system-gdbinit=@var{file}
36434Configure @value{GDBN} to automatically load a system-wide init file.
36435@var{file} should be an absolute file name. If @var{file} is in a
36436directory under the configured prefix, and @value{GDBN} is moved to
36437another location after being built, the location of the system-wide
36438init file will be adjusted accordingly.
36439
36440@item --enable-build-warnings
36441When building the @value{GDBN} sources, ask the compiler to warn about
36442any code which looks even vaguely suspicious. It passes many
36443different warning flags, depending on the exact version of the
36444compiler you are using.
36445
36446@item --enable-werror
36447Treat compiler warnings as werrors. It adds the @code{-Werror} flag
36448to the compiler, which will fail the compilation if the compiler
36449outputs any warning messages.
f35d5ade
TT
36450
36451@item --enable-ubsan
eff98030
TT
36452Enable the GCC undefined behavior sanitizer. This is disabled by
36453default, but passing @code{--enable-ubsan=yes} or
36454@code{--enable-ubsan=auto} to @code{configure} will enable it. The
36455undefined behavior sanitizer checks for C@t{++} undefined behavior.
36456It has a performance cost, so if you are looking at @value{GDBN}'s
36457performance, you should disable it. The undefined behavior sanitizer
36458was first introduced in GCC 4.9.
a95746f9 36459@end table
c906108c 36460
098b41a6
JG
36461@node System-wide configuration
36462@section System-wide configuration and settings
36463@cindex system-wide init file
36464
36465@value{GDBN} can be configured to have a system-wide init file;
36466this file will be read and executed at startup (@pxref{Startup, , What
36467@value{GDBN} does during startup}).
36468
36469Here is the corresponding configure option:
36470
36471@table @code
36472@item --with-system-gdbinit=@var{file}
36473Specify that the default location of the system-wide init file is
36474@var{file}.
36475@end table
36476
36477If @value{GDBN} has been configured with the option @option{--prefix=$prefix},
36478it may be subject to relocation. Two possible cases:
36479
36480@itemize @bullet
36481@item
36482If the default location of this init file contains @file{$prefix},
36483it will be subject to relocation. Suppose that the configure options
36484are @option{--prefix=$prefix --with-system-gdbinit=$prefix/etc/gdbinit};
36485if @value{GDBN} is moved from @file{$prefix} to @file{$install}, the system
36486init file is looked for as @file{$install/etc/gdbinit} instead of
36487@file{$prefix/etc/gdbinit}.
36488
36489@item
36490By contrast, if the default location does not contain the prefix,
36491it will not be relocated. E.g.@: if @value{GDBN} has been configured with
36492@option{--prefix=/usr/local --with-system-gdbinit=/usr/share/gdb/gdbinit},
36493then @value{GDBN} will always look for @file{/usr/share/gdb/gdbinit},
36494wherever @value{GDBN} is installed.
36495@end itemize
36496
e64e0392
DE
36497If the configured location of the system-wide init file (as given by the
36498@option{--with-system-gdbinit} option at configure time) is in the
36499data-directory (as specified by @option{--with-gdb-datadir} at configure
36500time) or in one of its subdirectories, then @value{GDBN} will look for the
36501system-wide init file in the directory specified by the
36502@option{--data-directory} command-line option.
36503Note that the system-wide init file is only read once, during @value{GDBN}
36504initialization. If the data-directory is changed after @value{GDBN} has
36505started with the @code{set data-directory} command, the file will not be
36506reread.
36507
5901af59
JB
36508@menu
36509* System-wide Configuration Scripts:: Installed System-wide Configuration Scripts
36510@end menu
36511
36512@node System-wide Configuration Scripts
0201faac
JB
36513@subsection Installed System-wide Configuration Scripts
36514@cindex system-wide configuration scripts
36515
36516The @file{system-gdbinit} directory, located inside the data-directory
36517(as specified by @option{--with-gdb-datadir} at configure time) contains
36518a number of scripts which can be used as system-wide init files. To
36519automatically source those scripts at startup, @value{GDBN} should be
36520configured with @option{--with-system-gdbinit}. Otherwise, any user
36521should be able to source them by hand as needed.
36522
36523The following scripts are currently available:
36524@itemize @bullet
36525
36526@item @file{elinos.py}
36527@pindex elinos.py
36528@cindex ELinOS system-wide configuration script
36529This script is useful when debugging a program on an ELinOS target.
36530It takes advantage of the environment variables defined in a standard
36531ELinOS environment in order to determine the location of the system
36532shared libraries, and then sets the @samp{solib-absolute-prefix}
36533and @samp{solib-search-path} variables appropriately.
36534
36535@item @file{wrs-linux.py}
36536@pindex wrs-linux.py
36537@cindex Wind River Linux system-wide configuration script
36538This script is useful when debugging a program on a target running
36539Wind River Linux. It expects the @env{ENV_PREFIX} to be set to
36540the host-side sysroot used by the target system.
36541
36542@end itemize
36543
8e04817f
AC
36544@node Maintenance Commands
36545@appendix Maintenance Commands
36546@cindex maintenance commands
36547@cindex internal commands
c906108c 36548
8e04817f 36549In addition to commands intended for @value{GDBN} users, @value{GDBN}
09d4efe1
EZ
36550includes a number of commands intended for @value{GDBN} developers,
36551that are not documented elsewhere in this manual. These commands are
da316a69
EZ
36552provided here for reference. (For commands that turn on debugging
36553messages, see @ref{Debugging Output}.)
c906108c 36554
8e04817f 36555@table @code
09d4efe1 36556@kindex maint agent
782b2b07 36557@kindex maint agent-eval
f77cc5f0
HZ
36558@item maint agent @r{[}-at @var{location}@r{,}@r{]} @var{expression}
36559@itemx maint agent-eval @r{[}-at @var{location}@r{,}@r{]} @var{expression}
09d4efe1
EZ
36560Translate the given @var{expression} into remote agent bytecodes.
36561This command is useful for debugging the Agent Expression mechanism
782b2b07
SS
36562(@pxref{Agent Expressions}). The @samp{agent} version produces an
36563expression useful for data collection, such as by tracepoints, while
36564@samp{maint agent-eval} produces an expression that evaluates directly
36565to a result. For instance, a collection expression for @code{globa +
36566globb} will include bytecodes to record four bytes of memory at each
36567of the addresses of @code{globa} and @code{globb}, while discarding
36568the result of the addition, while an evaluation expression will do the
36569addition and return the sum.
f77cc5f0
HZ
36570If @code{-at} is given, generate remote agent bytecode for @var{location}.
36571If not, generate remote agent bytecode for current frame PC address.
09d4efe1 36572
d3ce09f5
SS
36573@kindex maint agent-printf
36574@item maint agent-printf @var{format},@var{expr},...
36575Translate the given format string and list of argument expressions
36576into remote agent bytecodes and display them as a disassembled list.
36577This command is useful for debugging the agent version of dynamic
6dd24dfa 36578printf (@pxref{Dynamic Printf}).
d3ce09f5 36579
8e04817f
AC
36580@kindex maint info breakpoints
36581@item @anchor{maint info breakpoints}maint info breakpoints
36582Using the same format as @samp{info breakpoints}, display both the
36583breakpoints you've set explicitly, and those @value{GDBN} is using for
36584internal purposes. Internal breakpoints are shown with negative
36585breakpoint numbers. The type column identifies what kind of breakpoint
36586is shown:
c906108c 36587
8e04817f
AC
36588@table @code
36589@item breakpoint
36590Normal, explicitly set breakpoint.
c906108c 36591
8e04817f
AC
36592@item watchpoint
36593Normal, explicitly set watchpoint.
c906108c 36594
8e04817f
AC
36595@item longjmp
36596Internal breakpoint, used to handle correctly stepping through
36597@code{longjmp} calls.
c906108c 36598
8e04817f
AC
36599@item longjmp resume
36600Internal breakpoint at the target of a @code{longjmp}.
c906108c 36601
8e04817f
AC
36602@item until
36603Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
c906108c 36604
8e04817f
AC
36605@item finish
36606Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
c906108c 36607
8e04817f
AC
36608@item shlib events
36609Shared library events.
c906108c 36610
8e04817f 36611@end table
c906108c 36612
b0627500
MM
36613@kindex maint info btrace
36614@item maint info btrace
36615Pint information about raw branch tracing data.
36616
36617@kindex maint btrace packet-history
36618@item maint btrace packet-history
36619Print the raw branch trace packets that are used to compute the
36620execution history for the @samp{record btrace} command. Both the
36621information and the format in which it is printed depend on the btrace
36622recording format.
36623
36624@table @code
36625@item bts
36626For the BTS recording format, print a list of blocks of sequential
36627code. For each block, the following information is printed:
36628
36629@table @asis
36630@item Block number
36631Newer blocks have higher numbers. The oldest block has number zero.
36632@item Lowest @samp{PC}
36633@item Highest @samp{PC}
36634@end table
36635
36636@item pt
bc504a31
PA
36637For the Intel Processor Trace recording format, print a list of
36638Intel Processor Trace packets. For each packet, the following
b0627500
MM
36639information is printed:
36640
36641@table @asis
36642@item Packet number
36643Newer packets have higher numbers. The oldest packet has number zero.
36644@item Trace offset
36645The packet's offset in the trace stream.
36646@item Packet opcode and payload
36647@end table
36648@end table
36649
36650@kindex maint btrace clear-packet-history
36651@item maint btrace clear-packet-history
36652Discards the cached packet history printed by the @samp{maint btrace
36653packet-history} command. The history will be computed again when
36654needed.
36655
36656@kindex maint btrace clear
36657@item maint btrace clear
36658Discard the branch trace data. The data will be fetched anew and the
36659branch trace will be recomputed when needed.
36660
36661This implicitly truncates the branch trace to a single branch trace
36662buffer. When updating branch trace incrementally, the branch trace
36663available to @value{GDBN} may be bigger than a single branch trace
36664buffer.
36665
36666@kindex maint set btrace pt skip-pad
36667@item maint set btrace pt skip-pad
36668@kindex maint show btrace pt skip-pad
36669@item maint show btrace pt skip-pad
36670Control whether @value{GDBN} will skip PAD packets when computing the
36671packet history.
36672
fff08868
HZ
36673@kindex set displaced-stepping
36674@kindex show displaced-stepping
237fc4c9
PA
36675@cindex displaced stepping support
36676@cindex out-of-line single-stepping
fff08868
HZ
36677@item set displaced-stepping
36678@itemx show displaced-stepping
237fc4c9 36679Control whether or not @value{GDBN} will do @dfn{displaced stepping}
fff08868
HZ
36680if the target supports it. Displaced stepping is a way to single-step
36681over breakpoints without removing them from the inferior, by executing
36682an out-of-line copy of the instruction that was originally at the
36683breakpoint location. It is also known as out-of-line single-stepping.
36684
36685@table @code
36686@item set displaced-stepping on
36687If the target architecture supports it, @value{GDBN} will use
36688displaced stepping to step over breakpoints.
36689
36690@item set displaced-stepping off
36691@value{GDBN} will not use displaced stepping to step over breakpoints,
36692even if such is supported by the target architecture.
36693
36694@cindex non-stop mode, and @samp{set displaced-stepping}
36695@item set displaced-stepping auto
36696This is the default mode. @value{GDBN} will use displaced stepping
36697only if non-stop mode is active (@pxref{Non-Stop Mode}) and the target
36698architecture supports displaced stepping.
36699@end table
237fc4c9 36700
7d0c9981
DE
36701@kindex maint check-psymtabs
36702@item maint check-psymtabs
36703Check the consistency of currently expanded psymtabs versus symtabs.
36704Use this to check, for example, whether a symbol is in one but not the other.
36705
09d4efe1
EZ
36706@kindex maint check-symtabs
36707@item maint check-symtabs
7d0c9981
DE
36708Check the consistency of currently expanded symtabs.
36709
36710@kindex maint expand-symtabs
36711@item maint expand-symtabs [@var{regexp}]
36712Expand symbol tables.
36713If @var{regexp} is specified, only expand symbol tables for file
36714names matching @var{regexp}.
09d4efe1 36715
992c7d70
GB
36716@kindex maint set catch-demangler-crashes
36717@kindex maint show catch-demangler-crashes
36718@cindex demangler crashes
36719@item maint set catch-demangler-crashes [on|off]
36720@itemx maint show catch-demangler-crashes
36721Control whether @value{GDBN} should attempt to catch crashes in the
36722symbol name demangler. The default is to attempt to catch crashes.
36723If enabled, the first time a crash is caught, a core file is created,
36724the offending symbol is displayed and the user is presented with the
36725option to terminate the current session.
36726
09d4efe1
EZ
36727@kindex maint cplus first_component
36728@item maint cplus first_component @var{name}
36729Print the first C@t{++} class/namespace component of @var{name}.
36730
36731@kindex maint cplus namespace
36732@item maint cplus namespace
36733Print the list of possible C@t{++} namespaces.
36734
09d4efe1
EZ
36735@kindex maint deprecate
36736@kindex maint undeprecate
36737@cindex deprecated commands
36738@item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
36739@itemx maint undeprecate @var{command}
36740Deprecate or undeprecate the named @var{command}. Deprecated commands
36741cause @value{GDBN} to issue a warning when you use them. The optional
36742argument @var{replacement} says which newer command should be used in
36743favor of the deprecated one; if it is given, @value{GDBN} will mention
36744the replacement as part of the warning.
36745
36746@kindex maint dump-me
36747@item maint dump-me
721c2651 36748@cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
09d4efe1 36749Cause a fatal signal in the debugger and force it to dump its core.
721c2651
EZ
36750This is supported only on systems which support aborting a program
36751with the @code{SIGQUIT} signal.
09d4efe1 36752
8d30a00d
AC
36753@kindex maint internal-error
36754@kindex maint internal-warning
57fcfb1b
GB
36755@kindex maint demangler-warning
36756@cindex demangler crashes
09d4efe1
EZ
36757@item maint internal-error @r{[}@var{message-text}@r{]}
36758@itemx maint internal-warning @r{[}@var{message-text}@r{]}
57fcfb1b
GB
36759@itemx maint demangler-warning @r{[}@var{message-text}@r{]}
36760
36761Cause @value{GDBN} to call the internal function @code{internal_error},
36762@code{internal_warning} or @code{demangler_warning} and hence behave
7ee67ee4 36763as though an internal problem has been detected. In addition to
57fcfb1b
GB
36764reporting the internal problem, these functions give the user the
36765opportunity to either quit @value{GDBN} or (for @code{internal_error}
36766and @code{internal_warning}) create a core file of the current
8d30a00d
AC
36767@value{GDBN} session.
36768
09d4efe1
EZ
36769These commands take an optional parameter @var{message-text} that is
36770used as the text of the error or warning message.
36771
d3e8051b 36772Here's an example of using @code{internal-error}:
09d4efe1 36773
8d30a00d 36774@smallexample
f7dc1244 36775(@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
8d30a00d
AC
36776@dots{}/maint.c:121: internal-error: testing, 1, 2
36777A problem internal to GDB has been detected. Further
36778debugging may prove unreliable.
36779Quit this debugging session? (y or n) @kbd{n}
36780Create a core file? (y or n) @kbd{n}
f7dc1244 36781(@value{GDBP})
8d30a00d
AC
36782@end smallexample
36783
3c16cced
PA
36784@cindex @value{GDBN} internal error
36785@cindex internal errors, control of @value{GDBN} behavior
57fcfb1b 36786@cindex demangler crashes
3c16cced
PA
36787
36788@kindex maint set internal-error
36789@kindex maint show internal-error
36790@kindex maint set internal-warning
36791@kindex maint show internal-warning
57fcfb1b
GB
36792@kindex maint set demangler-warning
36793@kindex maint show demangler-warning
3c16cced
PA
36794@item maint set internal-error @var{action} [ask|yes|no]
36795@itemx maint show internal-error @var{action}
36796@itemx maint set internal-warning @var{action} [ask|yes|no]
36797@itemx maint show internal-warning @var{action}
57fcfb1b
GB
36798@itemx maint set demangler-warning @var{action} [ask|yes|no]
36799@itemx maint show demangler-warning @var{action}
3c16cced
PA
36800When @value{GDBN} reports an internal problem (error or warning) it
36801gives the user the opportunity to both quit @value{GDBN} and create a
36802core file of the current @value{GDBN} session. These commands let you
36803override the default behaviour for each particular @var{action},
36804described in the table below.
36805
36806@table @samp
36807@item quit
36808You can specify that @value{GDBN} should always (yes) or never (no)
36809quit. The default is to ask the user what to do.
36810
36811@item corefile
36812You can specify that @value{GDBN} should always (yes) or never (no)
57fcfb1b
GB
36813create a core file. The default is to ask the user what to do. Note
36814that there is no @code{corefile} option for @code{demangler-warning}:
36815demangler warnings always create a core file and this cannot be
36816disabled.
3c16cced
PA
36817@end table
36818
09d4efe1
EZ
36819@kindex maint packet
36820@item maint packet @var{text}
36821If @value{GDBN} is talking to an inferior via the serial protocol,
36822then this command sends the string @var{text} to the inferior, and
36823displays the response packet. @value{GDBN} supplies the initial
36824@samp{$} character, the terminating @samp{#} character, and the
36825checksum.
36826
36827@kindex maint print architecture
36828@item maint print architecture @r{[}@var{file}@r{]}
36829Print the entire architecture configuration. The optional argument
36830@var{file} names the file where the output goes.
8d30a00d 36831
8e2141c6 36832@kindex maint print c-tdesc @r{[}@var{file}@r{]}
81adfced 36833@item maint print c-tdesc
8e2141c6
YQ
36834Print the target description (@pxref{Target Descriptions}) as
36835a C source file. By default, the target description is for the current
36836target, but if the optional argument @var{file} is provided, that file
36837is used to produce the description. The @var{file} should be an XML
36838document, of the form described in @ref{Target Description Format}.
36839The created source file is built into @value{GDBN} when @value{GDBN} is
36840built again. This command is used by developers after they add or
36841modify XML target descriptions.
81adfced 36842
27d41eac
YQ
36843@kindex maint check xml-descriptions
36844@item maint check xml-descriptions @var{dir}
36845Check that the target descriptions dynamically created by @value{GDBN}
36846equal the descriptions created from XML files found in @var{dir}.
36847
41fc26a2 36848@anchor{maint check libthread-db}
5045b3d7
GB
36849@kindex maint check libthread-db
36850@item maint check libthread-db
36851Run integrity checks on the current inferior's thread debugging
36852library. This exercises all @code{libthread_db} functionality used by
36853@value{GDBN} on GNU/Linux systems, and by extension also exercises the
36854@code{proc_service} functions provided by @value{GDBN} that
36855@code{libthread_db} uses. Note that parts of the test may be skipped
36856on some platforms when debugging core files.
36857
00905d52
AC
36858@kindex maint print dummy-frames
36859@item maint print dummy-frames
00905d52
AC
36860Prints the contents of @value{GDBN}'s internal dummy-frame stack.
36861
36862@smallexample
f7dc1244 36863(@value{GDBP}) @kbd{b add}
00905d52 36864@dots{}
f7dc1244 36865(@value{GDBP}) @kbd{print add(2,3)}
00905d52
AC
36866Breakpoint 2, add (a=2, b=3) at @dots{}
3686758 return (a + b);
36868The program being debugged stopped while in a function called from GDB.
36869@dots{}
f7dc1244 36870(@value{GDBP}) @kbd{maint print dummy-frames}
b67a2c6f 368710xa8206d8: id=@{stack=0xbfffe734,code=0xbfffe73f,!special@}, ptid=process 9353
f7dc1244 36872(@value{GDBP})
00905d52
AC
36873@end smallexample
36874
36875Takes an optional file parameter.
36876
0680b120
AC
36877@kindex maint print registers
36878@kindex maint print raw-registers
36879@kindex maint print cooked-registers
617073a9 36880@kindex maint print register-groups
c21236dc 36881@kindex maint print remote-registers
09d4efe1
EZ
36882@item maint print registers @r{[}@var{file}@r{]}
36883@itemx maint print raw-registers @r{[}@var{file}@r{]}
36884@itemx maint print cooked-registers @r{[}@var{file}@r{]}
36885@itemx maint print register-groups @r{[}@var{file}@r{]}
c21236dc 36886@itemx maint print remote-registers @r{[}@var{file}@r{]}
0680b120
AC
36887Print @value{GDBN}'s internal register data structures.
36888
617073a9 36889The command @code{maint print raw-registers} includes the contents of
c21236dc
PA
36890the raw register cache; the command @code{maint print
36891cooked-registers} includes the (cooked) value of all registers,
36892including registers which aren't available on the target nor visible
36893to user; the command @code{maint print register-groups} includes the
36894groups that each register is a member of; and the command @code{maint
36895print remote-registers} includes the remote target's register numbers
0a7cfe2c 36896and offsets in the `G' packets.
0680b120 36897
09d4efe1
EZ
36898These commands take an optional parameter, a file name to which to
36899write the information.
0680b120 36900
617073a9 36901@kindex maint print reggroups
09d4efe1
EZ
36902@item maint print reggroups @r{[}@var{file}@r{]}
36903Print @value{GDBN}'s internal register group data structures. The
36904optional argument @var{file} tells to what file to write the
36905information.
617073a9 36906
09d4efe1 36907The register groups info looks like this:
617073a9
AC
36908
36909@smallexample
f7dc1244 36910(@value{GDBP}) @kbd{maint print reggroups}
b383017d
RM
36911 Group Type
36912 general user
36913 float user
36914 all user
36915 vector user
36916 system user
36917 save internal
36918 restore internal
617073a9
AC
36919@end smallexample
36920
09d4efe1
EZ
36921@kindex flushregs
36922@item flushregs
36923This command forces @value{GDBN} to flush its internal register cache.
36924
36925@kindex maint print objfiles
36926@cindex info for known object files
52e260a3
DE
36927@item maint print objfiles @r{[}@var{regexp}@r{]}
36928Print a dump of all known object files.
36929If @var{regexp} is specified, only print object files whose names
36930match @var{regexp}. For each object file, this command prints its name,
36931address in memory, and all of its psymtabs and symtabs.
09d4efe1 36932
f5b95c01
AA
36933@kindex maint print user-registers
36934@cindex user registers
36935@item maint print user-registers
36936List all currently available @dfn{user registers}. User registers
36937typically provide alternate names for actual hardware registers. They
36938include the four ``standard'' registers @code{$fp}, @code{$pc},
36939@code{$sp}, and @code{$ps}. @xref{standard registers}. User
36940registers can be used in expressions in the same way as the canonical
36941register names, but only the latter are listed by the @code{info
36942registers} and @code{maint print registers} commands.
36943
8a1ea21f
DE
36944@kindex maint print section-scripts
36945@cindex info for known .debug_gdb_scripts-loaded scripts
36946@item maint print section-scripts [@var{regexp}]
36947Print a dump of scripts specified in the @code{.debug_gdb_section} section.
36948If @var{regexp} is specified, only print scripts loaded by object files
36949matching @var{regexp}.
36950For each script, this command prints its name as specified in the objfile,
36951and the full path if known.
8e0583c8 36952@xref{dotdebug_gdb_scripts section}.
8a1ea21f 36953
09d4efe1
EZ
36954@kindex maint print statistics
36955@cindex bcache statistics
36956@item maint print statistics
36957This command prints, for each object file in the program, various data
36958about that object file followed by the byte cache (@dfn{bcache})
36959statistics for the object file. The objfile data includes the number
d3e8051b 36960of minimal, partial, full, and stabs symbols, the number of types
09d4efe1
EZ
36961defined by the objfile, the number of as yet unexpanded psym tables,
36962the number of line tables and string tables, and the amount of memory
36963used by the various tables. The bcache statistics include the counts,
36964sizes, and counts of duplicates of all and unique objects, max,
36965average, and median entry size, total memory used and its overhead and
36966savings, and various measures of the hash table size and chain
36967lengths.
36968
c7ba131e
JB
36969@kindex maint print target-stack
36970@cindex target stack description
36971@item maint print target-stack
36972A @dfn{target} is an interface between the debugger and a particular
36973kind of file or process. Targets can be stacked in @dfn{strata},
36974so that more than one target can potentially respond to a request.
36975In particular, memory accesses will walk down the stack of targets
36976until they find a target that is interested in handling that particular
36977address.
36978
36979This command prints a short description of each layer that was pushed on
36980the @dfn{target stack}, starting from the top layer down to the bottom one.
36981
09d4efe1
EZ
36982@kindex maint print type
36983@cindex type chain of a data type
36984@item maint print type @var{expr}
36985Print the type chain for a type specified by @var{expr}. The argument
36986can be either a type name or a symbol. If it is a symbol, the type of
36987that symbol is described. The type chain produced by this command is
36988a recursive definition of the data type as stored in @value{GDBN}'s
36989data structures, including its flags and contained types.
36990
dcd1f979
TT
36991@kindex maint selftest
36992@cindex self tests
1526853e 36993@item maint selftest @r{[}@var{filter}@r{]}
dcd1f979
TT
36994Run any self tests that were compiled in to @value{GDBN}. This will
36995print a message showing how many tests were run, and how many failed.
1526853e
SM
36996If a @var{filter} is passed, only the tests with @var{filter} in their
36997name will by ran.
36998
3c2fcaf9 36999@kindex maint info selftests
1526853e
SM
37000@cindex self tests
37001@item maint info selftests
37002List the selftests compiled in to @value{GDBN}.
dcd1f979 37003
b4f54984
DE
37004@kindex maint set dwarf always-disassemble
37005@kindex maint show dwarf always-disassemble
37006@item maint set dwarf always-disassemble
37007@item maint show dwarf always-disassemble
9eae7c52
TT
37008Control the behavior of @code{info address} when using DWARF debugging
37009information.
37010
37011The default is @code{off}, which means that @value{GDBN} should try to
37012describe a variable's location in an easily readable format. When
37013@code{on}, @value{GDBN} will instead display the DWARF location
37014expression in an assembly-like format. Note that some locations are
37015too complex for @value{GDBN} to describe simply; in this case you will
37016always see the disassembly form.
37017
37018Here is an example of the resulting disassembly:
37019
37020@smallexample
37021(gdb) info addr argc
37022Symbol "argc" is a complex DWARF expression:
37023 1: DW_OP_fbreg 0
37024@end smallexample
37025
37026For more information on these expressions, see
37027@uref{http://www.dwarfstd.org/, the DWARF standard}.
37028
b4f54984
DE
37029@kindex maint set dwarf max-cache-age
37030@kindex maint show dwarf max-cache-age
37031@item maint set dwarf max-cache-age
37032@itemx maint show dwarf max-cache-age
37033Control the DWARF compilation unit cache.
09d4efe1 37034
b4f54984 37035@cindex DWARF compilation units cache
09d4efe1 37036In object files with inter-compilation-unit references, such as those
b4f54984 37037produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF
09d4efe1
EZ
37038reader needs to frequently refer to previously read compilation units.
37039This setting controls how long a compilation unit will remain in the
37040cache if it is not referenced. A higher limit means that cached
37041compilation units will be stored in memory longer, and more total
37042memory will be used. Setting it to zero disables caching, which will
37043slow down @value{GDBN} startup, but reduce memory consumption.
37044
3c3bb058
AB
37045@kindex maint set dwarf unwinders
37046@kindex maint show dwarf unwinders
37047@item maint set dwarf unwinders
37048@itemx maint show dwarf unwinders
37049Control use of the DWARF frame unwinders.
37050
37051@cindex DWARF frame unwinders
37052Many targets that support DWARF debugging use @value{GDBN}'s DWARF
37053frame unwinders to build the backtrace. Many of these targets will
37054also have a second mechanism for building the backtrace for use in
37055cases where DWARF information is not available, this second mechanism
37056is often an analysis of a function's prologue.
37057
37058In order to extend testing coverage of the second level stack
37059unwinding mechanisms it is helpful to be able to disable the DWARF
37060stack unwinders, this can be done with this switch.
37061
37062In normal use of @value{GDBN} disabling the DWARF unwinders is not
37063advisable, there are cases that are better handled through DWARF than
37064prologue analysis, and the debug experience is likely to be better
37065with the DWARF frame unwinders enabled.
37066
37067If DWARF frame unwinders are not supported for a particular target
37068architecture, then enabling this flag does not cause them to be used.
e7ba9c65
DJ
37069@kindex maint set profile
37070@kindex maint show profile
37071@cindex profiling GDB
37072@item maint set profile
37073@itemx maint show profile
37074Control profiling of @value{GDBN}.
37075
37076Profiling will be disabled until you use the @samp{maint set profile}
37077command to enable it. When you enable profiling, the system will begin
37078collecting timing and execution count data; when you disable profiling or
37079exit @value{GDBN}, the results will be written to a log file. Remember that
37080if you use profiling, @value{GDBN} will overwrite the profiling log file
37081(often called @file{gmon.out}). If you have a record of important profiling
37082data in a @file{gmon.out} file, be sure to move it to a safe location.
37083
37084Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
b383017d 37085compiled with the @samp{-pg} compiler option.
e7ba9c65 37086
cbe54154
PA
37087@kindex maint set show-debug-regs
37088@kindex maint show show-debug-regs
eac35c4e 37089@cindex hardware debug registers
cbe54154
PA
37090@item maint set show-debug-regs
37091@itemx maint show show-debug-regs
eac35c4e 37092Control whether to show variables that mirror the hardware debug
6dd315ba 37093registers. Use @code{on} to enable, @code{off} to disable. If
3f94c067 37094enabled, the debug registers values are shown when @value{GDBN} inserts or
09d4efe1
EZ
37095removes a hardware breakpoint or watchpoint, and when the inferior
37096triggers a hardware-assisted breakpoint or watchpoint.
37097
711e434b
PM
37098@kindex maint set show-all-tib
37099@kindex maint show show-all-tib
37100@item maint set show-all-tib
37101@itemx maint show show-all-tib
37102Control whether to show all non zero areas within a 1k block starting
37103at thread local base, when using the @samp{info w32 thread-information-block}
37104command.
37105
329ea579
PA
37106@kindex maint set target-async
37107@kindex maint show target-async
37108@item maint set target-async
37109@itemx maint show target-async
37110This controls whether @value{GDBN} targets operate in synchronous or
37111asynchronous mode (@pxref{Background Execution}). Normally the
37112default is asynchronous, if it is available; but this can be changed
37113to more easily debug problems occurring only in synchronous mode.
37114
fbea99ea
PA
37115@kindex maint set target-non-stop @var{mode} [on|off|auto]
37116@kindex maint show target-non-stop
37117@item maint set target-non-stop
37118@itemx maint show target-non-stop
37119
37120This controls whether @value{GDBN} targets always operate in non-stop
37121mode even if @code{set non-stop} is @code{off} (@pxref{Non-Stop
37122Mode}). The default is @code{auto}, meaning non-stop mode is enabled
37123if supported by the target.
37124
37125@table @code
37126@item maint set target-non-stop auto
37127This is the default mode. @value{GDBN} controls the target in
37128non-stop mode if the target supports it.
37129
37130@item maint set target-non-stop on
37131@value{GDBN} controls the target in non-stop mode even if the target
37132does not indicate support.
37133
37134@item maint set target-non-stop off
37135@value{GDBN} does not control the target in non-stop mode even if the
37136target supports it.
37137@end table
37138
bd712aed
DE
37139@kindex maint set per-command
37140@kindex maint show per-command
37141@item maint set per-command
37142@itemx maint show per-command
37143@cindex resources used by commands
09d4efe1 37144
bd712aed
DE
37145@value{GDBN} can display the resources used by each command.
37146This is useful in debugging performance problems.
37147
37148@table @code
37149@item maint set per-command space [on|off]
37150@itemx maint show per-command space
37151Enable or disable the printing of the memory used by GDB for each command.
37152If enabled, @value{GDBN} will display how much memory each command
37153took, following the command's own output.
37154This can also be requested by invoking @value{GDBN} with the
37155@option{--statistics} command-line switch (@pxref{Mode Options}).
37156
37157@item maint set per-command time [on|off]
37158@itemx maint show per-command time
37159Enable or disable the printing of the execution time of @value{GDBN}
37160for each command.
37161If enabled, @value{GDBN} will display how much time it
09d4efe1 37162took to execute each command, following the command's own output.
0a1c4d10
DE
37163Both CPU time and wallclock time are printed.
37164Printing both is useful when trying to determine whether the cost is
bd712aed 37165CPU or, e.g., disk/network latency.
0a1c4d10
DE
37166Note that the CPU time printed is for @value{GDBN} only, it does not include
37167the execution time of the inferior because there's no mechanism currently
37168to compute how much time was spent by @value{GDBN} and how much time was
37169spent by the program been debugged.
09d4efe1
EZ
37170This can also be requested by invoking @value{GDBN} with the
37171@option{--statistics} command-line switch (@pxref{Mode Options}).
37172
bd712aed
DE
37173@item maint set per-command symtab [on|off]
37174@itemx maint show per-command symtab
37175Enable or disable the printing of basic symbol table statistics
37176for each command.
37177If enabled, @value{GDBN} will display the following information:
37178
215b9f98
EZ
37179@enumerate a
37180@item
37181number of symbol tables
37182@item
37183number of primary symbol tables
37184@item
37185number of blocks in the blockvector
37186@end enumerate
bd712aed
DE
37187@end table
37188
5045b3d7
GB
37189@kindex maint set check-libthread-db
37190@kindex maint show check-libthread-db
37191@item maint set check-libthread-db [on|off]
37192@itemx maint show check-libthread-db
37193Control whether @value{GDBN} should run integrity checks on inferior
37194specific thread debugging libraries as they are loaded. The default
37195is not to perform such checks. If any check fails @value{GDBN} will
37196unload the library and continue searching for a suitable candidate as
37197described in @ref{set libthread-db-search-path}. For more information
37198about the tests, see @ref{maint check libthread-db}.
37199
bd712aed
DE
37200@kindex maint space
37201@cindex memory used by commands
37202@item maint space @var{value}
37203An alias for @code{maint set per-command space}.
37204A non-zero value enables it, zero disables it.
37205
37206@kindex maint time
37207@cindex time of command execution
37208@item maint time @var{value}
37209An alias for @code{maint set per-command time}.
37210A non-zero value enables it, zero disables it.
37211
09d4efe1
EZ
37212@kindex maint translate-address
37213@item maint translate-address @r{[}@var{section}@r{]} @var{addr}
37214Find the symbol stored at the location specified by the address
37215@var{addr} and an optional section name @var{section}. If found,
37216@value{GDBN} prints the name of the closest symbol and an offset from
37217the symbol's location to the specified address. This is similar to
37218the @code{info address} command (@pxref{Symbols}), except that this
37219command also allows to find symbols in other sections.
ae038cb0 37220
c14c28ba
PP
37221If section was not specified, the section in which the symbol was found
37222is also printed. For dynamically linked executables, the name of
37223executable or shared library containing the symbol is printed as well.
37224
dca0f6c0
PA
37225@kindex maint test-settings
37226@item maint test-settings set @var{kind}
37227@itemx maint test-settings show @var{kind}
37228These are representative commands for each @var{kind} of setting type
37229@value{GDBN} supports. They are used by the testsuite for exercising
37230the settings infrastructure.
8e04817f 37231@end table
c906108c 37232
9c16f35a
EZ
37233The following command is useful for non-interactive invocations of
37234@value{GDBN}, such as in the test suite.
37235
37236@table @code
37237@item set watchdog @var{nsec}
37238@kindex set watchdog
37239@cindex watchdog timer
37240@cindex timeout for commands
37241Set the maximum number of seconds @value{GDBN} will wait for the
37242target operation to finish. If this time expires, @value{GDBN}
37243reports and error and the command is aborted.
37244
37245@item show watchdog
37246Show the current setting of the target wait timeout.
37247@end table
c906108c 37248
e0ce93ac 37249@node Remote Protocol
8e04817f 37250@appendix @value{GDBN} Remote Serial Protocol
c906108c 37251
ee2d5c50
AC
37252@menu
37253* Overview::
37254* Packets::
37255* Stop Reply Packets::
37256* General Query Packets::
a1dcb23a 37257* Architecture-Specific Protocol Details::
9d29849a 37258* Tracepoint Packets::
a6b151f1 37259* Host I/O Packets::
9a6253be 37260* Interrupts::
8b23ecc4
SL
37261* Notification Packets::
37262* Remote Non-Stop::
a6f3e723 37263* Packet Acknowledgment::
ee2d5c50 37264* Examples::
79a6e687 37265* File-I/O Remote Protocol Extension::
cfa9d6d9 37266* Library List Format::
2268b414 37267* Library List Format for SVR4 Targets::
79a6e687 37268* Memory Map Format::
dc146f7c 37269* Thread List Format::
b3b9301e 37270* Traceframe Info Format::
2ae8c8e7 37271* Branch Trace Format::
f4abbc16 37272* Branch Trace Configuration Format::
ee2d5c50
AC
37273@end menu
37274
37275@node Overview
37276@section Overview
37277
8e04817f
AC
37278There may be occasions when you need to know something about the
37279protocol---for example, if there is only one serial port to your target
37280machine, you might want your program to do something special if it
37281recognizes a packet meant for @value{GDBN}.
c906108c 37282
d2c6833e 37283In the examples below, @samp{->} and @samp{<-} are used to indicate
bf06d120 37284transmitted and received data, respectively.
c906108c 37285
8e04817f
AC
37286@cindex protocol, @value{GDBN} remote serial
37287@cindex serial protocol, @value{GDBN} remote
37288@cindex remote serial protocol
8b23ecc4
SL
37289All @value{GDBN} commands and responses (other than acknowledgments
37290and notifications, see @ref{Notification Packets}) are sent as a
37291@var{packet}. A @var{packet} is introduced with the character
8e04817f
AC
37292@samp{$}, the actual @var{packet-data}, and the terminating character
37293@samp{#} followed by a two-digit @var{checksum}:
c906108c 37294
474c8240 37295@smallexample
8e04817f 37296@code{$}@var{packet-data}@code{#}@var{checksum}
474c8240 37297@end smallexample
8e04817f 37298@noindent
c906108c 37299
8e04817f
AC
37300@cindex checksum, for @value{GDBN} remote
37301@noindent
37302The two-digit @var{checksum} is computed as the modulo 256 sum of all
37303characters between the leading @samp{$} and the trailing @samp{#} (an
37304eight bit unsigned checksum).
c906108c 37305
8e04817f
AC
37306Implementors should note that prior to @value{GDBN} 5.0 the protocol
37307specification also included an optional two-digit @var{sequence-id}:
c906108c 37308
474c8240 37309@smallexample
8e04817f 37310@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
474c8240 37311@end smallexample
c906108c 37312
8e04817f
AC
37313@cindex sequence-id, for @value{GDBN} remote
37314@noindent
37315That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
37316has never output @var{sequence-id}s. Stubs that handle packets added
37317since @value{GDBN} 5.0 must not accept @var{sequence-id}.
c906108c 37318
8e04817f
AC
37319When either the host or the target machine receives a packet, the first
37320response expected is an acknowledgment: either @samp{+} (to indicate
37321the package was received correctly) or @samp{-} (to request
37322retransmission):
c906108c 37323
474c8240 37324@smallexample
d2c6833e
AC
37325-> @code{$}@var{packet-data}@code{#}@var{checksum}
37326<- @code{+}
474c8240 37327@end smallexample
8e04817f 37328@noindent
53a5351d 37329
a6f3e723
SL
37330The @samp{+}/@samp{-} acknowledgments can be disabled
37331once a connection is established.
37332@xref{Packet Acknowledgment}, for details.
37333
8e04817f
AC
37334The host (@value{GDBN}) sends @var{command}s, and the target (the
37335debugging stub incorporated in your program) sends a @var{response}. In
37336the case of step and continue @var{command}s, the response is only sent
8b23ecc4
SL
37337when the operation has completed, and the target has again stopped all
37338threads in all attached processes. This is the default all-stop mode
37339behavior, but the remote protocol also supports @value{GDBN}'s non-stop
37340execution mode; see @ref{Remote Non-Stop}, for details.
c906108c 37341
8e04817f
AC
37342@var{packet-data} consists of a sequence of characters with the
37343exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
37344exceptions).
c906108c 37345
ee2d5c50 37346@cindex remote protocol, field separator
0876f84a 37347Fields within the packet should be separated using @samp{,} @samp{;} or
8e04817f 37348@samp{:}. Except where otherwise noted all numbers are represented in
ee2d5c50 37349@sc{hex} with leading zeros suppressed.
c906108c 37350
8e04817f
AC
37351Implementors should note that prior to @value{GDBN} 5.0, the character
37352@samp{:} could not appear as the third character in a packet (as it
37353would potentially conflict with the @var{sequence-id}).
c906108c 37354
0876f84a
DJ
37355@cindex remote protocol, binary data
37356@anchor{Binary Data}
37357Binary data in most packets is encoded either as two hexadecimal
37358digits per byte of binary data. This allowed the traditional remote
37359protocol to work over connections which were only seven-bit clean.
37360Some packets designed more recently assume an eight-bit clean
37361connection, and use a more efficient encoding to send and receive
37362binary data.
37363
37364The binary data representation uses @code{7d} (@sc{ascii} @samp{@}})
37365as an escape character. Any escaped byte is transmitted as the escape
37366character followed by the original character XORed with @code{0x20}.
37367For example, the byte @code{0x7d} would be transmitted as the two
37368bytes @code{0x7d 0x5d}. The bytes @code{0x23} (@sc{ascii} @samp{#}),
37369@code{0x24} (@sc{ascii} @samp{$}), and @code{0x7d} (@sc{ascii}
37370@samp{@}}) must always be escaped. Responses sent by the stub
37371must also escape @code{0x2a} (@sc{ascii} @samp{*}), so that it
37372is not interpreted as the start of a run-length encoded sequence
37373(described next).
37374
1d3811f6
DJ
37375Response @var{data} can be run-length encoded to save space.
37376Run-length encoding replaces runs of identical characters with one
37377instance of the repeated character, followed by a @samp{*} and a
37378repeat count. The repeat count is itself sent encoded, to avoid
37379binary characters in @var{data}: a value of @var{n} is sent as
37380@code{@var{n}+29}. For a repeat count greater or equal to 3, this
37381produces a printable @sc{ascii} character, e.g.@: a space (@sc{ascii}
37382code 32) for a repeat count of 3. (This is because run-length
37383encoding starts to win for counts 3 or more.) Thus, for example,
37384@samp{0* } is a run-length encoding of ``0000'': the space character
37385after @samp{*} means repeat the leading @code{0} @w{@code{32 - 29 =
373863}} more times.
37387
37388The printable characters @samp{#} and @samp{$} or with a numeric value
37389greater than 126 must not be used. Runs of six repeats (@samp{#}) or
37390seven repeats (@samp{$}) can be expanded using a repeat count of only
37391five (@samp{"}). For example, @samp{00000000} can be encoded as
37392@samp{0*"00}.
c906108c 37393
8e04817f
AC
37394The error response returned for some packets includes a two character
37395error number. That number is not well defined.
c906108c 37396
f8da2bff 37397@cindex empty response, for unsupported packets
8e04817f
AC
37398For any @var{command} not supported by the stub, an empty response
37399(@samp{$#00}) should be returned. That way it is possible to extend the
37400protocol. A newer @value{GDBN} can tell if a packet is supported based
37401on that response.
c906108c 37402
393eab54
PA
37403At a minimum, a stub is required to support the @samp{g} and @samp{G}
37404commands for register access, and the @samp{m} and @samp{M} commands
37405for memory access. Stubs that only control single-threaded targets
37406can implement run control with the @samp{c} (continue), and @samp{s}
37407(step) commands. Stubs that support multi-threading targets should
37408support the @samp{vCont} command. All other commands are optional.
c906108c 37409
ee2d5c50
AC
37410@node Packets
37411@section Packets
37412
37413The following table provides a complete list of all currently defined
37414@var{command}s and their corresponding response @var{data}.
79a6e687 37415@xref{File-I/O Remote Protocol Extension}, for details about the File
9c16f35a 37416I/O extension of the remote protocol.
ee2d5c50 37417
b8ff78ce
JB
37418Each packet's description has a template showing the packet's overall
37419syntax, followed by an explanation of the packet's meaning. We
37420include spaces in some of the templates for clarity; these are not
37421part of the packet's syntax. No @value{GDBN} packet uses spaces to
37422separate its components. For example, a template like @samp{foo
37423@var{bar} @var{baz}} describes a packet beginning with the three ASCII
37424bytes @samp{foo}, followed by a @var{bar}, followed directly by a
3f94c067 37425@var{baz}. @value{GDBN} does not transmit a space character between the
b8ff78ce
JB
37426@samp{foo} and the @var{bar}, or between the @var{bar} and the
37427@var{baz}.
37428
b90a069a
SL
37429@cindex @var{thread-id}, in remote protocol
37430@anchor{thread-id syntax}
37431Several packets and replies include a @var{thread-id} field to identify
37432a thread. Normally these are positive numbers with a target-specific
37433interpretation, formatted as big-endian hex strings. A @var{thread-id}
37434can also be a literal @samp{-1} to indicate all threads, or @samp{0} to
37435pick any thread.
37436
37437In addition, the remote protocol supports a multiprocess feature in
37438which the @var{thread-id} syntax is extended to optionally include both
37439process and thread ID fields, as @samp{p@var{pid}.@var{tid}}.
37440The @var{pid} (process) and @var{tid} (thread) components each have the
37441format described above: a positive number with target-specific
37442interpretation formatted as a big-endian hex string, literal @samp{-1}
37443to indicate all processes or threads (respectively), or @samp{0} to
37444indicate an arbitrary process or thread. Specifying just a process, as
37445@samp{p@var{pid}}, is equivalent to @samp{p@var{pid}.-1}. It is an
37446error to specify all processes but a specific thread, such as
37447@samp{p-1.@var{tid}}. Note that the @samp{p} prefix is @emph{not} used
37448for those packets and replies explicitly documented to include a process
37449ID, rather than a @var{thread-id}.
37450
37451The multiprocess @var{thread-id} syntax extensions are only used if both
37452@value{GDBN} and the stub report support for the @samp{multiprocess}
37453feature using @samp{qSupported}. @xref{multiprocess extensions}, for
37454more information.
37455
8ffe2530
JB
37456Note that all packet forms beginning with an upper- or lower-case
37457letter, other than those described here, are reserved for future use.
37458
b8ff78ce 37459Here are the packet descriptions.
ee2d5c50 37460
b8ff78ce 37461@table @samp
ee2d5c50 37462
b8ff78ce
JB
37463@item !
37464@cindex @samp{!} packet
2d717e4f 37465@anchor{extended mode}
8e04817f
AC
37466Enable extended mode. In extended mode, the remote server is made
37467persistent. The @samp{R} packet is used to restart the program being
37468debugged.
ee2d5c50
AC
37469
37470Reply:
37471@table @samp
37472@item OK
8e04817f 37473The remote target both supports and has enabled extended mode.
ee2d5c50 37474@end table
c906108c 37475
b8ff78ce
JB
37476@item ?
37477@cindex @samp{?} packet
36cb1214 37478@anchor{? packet}
ee2d5c50 37479Indicate the reason the target halted. The reply is the same as for
8b23ecc4
SL
37480step and continue. This packet has a special interpretation when the
37481target is in non-stop mode; see @ref{Remote Non-Stop}.
c906108c 37482
ee2d5c50
AC
37483Reply:
37484@xref{Stop Reply Packets}, for the reply specifications.
37485
b8ff78ce
JB
37486@item A @var{arglen},@var{argnum},@var{arg},@dots{}
37487@cindex @samp{A} packet
37488Initialized @code{argv[]} array passed into program. @var{arglen}
37489specifies the number of bytes in the hex encoded byte stream
37490@var{arg}. See @code{gdbserver} for more details.
ee2d5c50
AC
37491
37492Reply:
37493@table @samp
37494@item OK
b8ff78ce
JB
37495The arguments were set.
37496@item E @var{NN}
37497An error occurred.
ee2d5c50
AC
37498@end table
37499
b8ff78ce
JB
37500@item b @var{baud}
37501@cindex @samp{b} packet
37502(Don't use this packet; its behavior is not well-defined.)
ee2d5c50
AC
37503Change the serial line speed to @var{baud}.
37504
37505JTC: @emph{When does the transport layer state change? When it's
37506received, or after the ACK is transmitted. In either case, there are
37507problems if the command or the acknowledgment packet is dropped.}
37508
37509Stan: @emph{If people really wanted to add something like this, and get
37510it working for the first time, they ought to modify ser-unix.c to send
37511some kind of out-of-band message to a specially-setup stub and have the
37512switch happen "in between" packets, so that from remote protocol's point
37513of view, nothing actually happened.}
37514
b8ff78ce
JB
37515@item B @var{addr},@var{mode}
37516@cindex @samp{B} packet
8e04817f 37517Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
2f870471
AC
37518breakpoint at @var{addr}.
37519
b8ff78ce 37520Don't use this packet. Use the @samp{Z} and @samp{z} packets instead
2f870471 37521(@pxref{insert breakpoint or watchpoint packet}).
c906108c 37522
bacec72f 37523@cindex @samp{bc} packet
0d772ac9
MS
37524@anchor{bc}
37525@item bc
bacec72f
MS
37526Backward continue. Execute the target system in reverse. No parameter.
37527@xref{Reverse Execution}, for more information.
37528
37529Reply:
37530@xref{Stop Reply Packets}, for the reply specifications.
37531
bacec72f 37532@cindex @samp{bs} packet
0d772ac9
MS
37533@anchor{bs}
37534@item bs
bacec72f
MS
37535Backward single step. Execute one instruction in reverse. No parameter.
37536@xref{Reverse Execution}, for more information.
37537
37538Reply:
37539@xref{Stop Reply Packets}, for the reply specifications.
37540
4f553f88 37541@item c @r{[}@var{addr}@r{]}
b8ff78ce 37542@cindex @samp{c} packet
697aa1b7
EZ
37543Continue at @var{addr}, which is the address to resume. If @var{addr}
37544is omitted, resume at current address.
c906108c 37545
393eab54
PA
37546This packet is deprecated for multi-threading support. @xref{vCont
37547packet}.
37548
ee2d5c50
AC
37549Reply:
37550@xref{Stop Reply Packets}, for the reply specifications.
37551
4f553f88 37552@item C @var{sig}@r{[};@var{addr}@r{]}
b8ff78ce 37553@cindex @samp{C} packet
8e04817f 37554Continue with signal @var{sig} (hex signal number). If
b8ff78ce 37555@samp{;@var{addr}} is omitted, resume at same address.
c906108c 37556
393eab54
PA
37557This packet is deprecated for multi-threading support. @xref{vCont
37558packet}.
37559
ee2d5c50
AC
37560Reply:
37561@xref{Stop Reply Packets}, for the reply specifications.
c906108c 37562
b8ff78ce
JB
37563@item d
37564@cindex @samp{d} packet
ee2d5c50
AC
37565Toggle debug flag.
37566
b8ff78ce
JB
37567Don't use this packet; instead, define a general set packet
37568(@pxref{General Query Packets}).
ee2d5c50 37569
b8ff78ce 37570@item D
b90a069a 37571@itemx D;@var{pid}
b8ff78ce 37572@cindex @samp{D} packet
b90a069a
SL
37573The first form of the packet is used to detach @value{GDBN} from the
37574remote system. It is sent to the remote target
07f31aa6 37575before @value{GDBN} disconnects via the @code{detach} command.
ee2d5c50 37576
b90a069a
SL
37577The second form, including a process ID, is used when multiprocess
37578protocol extensions are enabled (@pxref{multiprocess extensions}), to
37579detach only a specific process. The @var{pid} is specified as a
37580big-endian hex string.
37581
ee2d5c50
AC
37582Reply:
37583@table @samp
10fac096
NW
37584@item OK
37585for success
b8ff78ce 37586@item E @var{NN}
10fac096 37587for an error
ee2d5c50 37588@end table
c906108c 37589
b8ff78ce
JB
37590@item F @var{RC},@var{EE},@var{CF};@var{XX}
37591@cindex @samp{F} packet
37592A reply from @value{GDBN} to an @samp{F} packet sent by the target.
37593This is part of the File-I/O protocol extension. @xref{File-I/O
79a6e687 37594Remote Protocol Extension}, for the specification.
ee2d5c50 37595
b8ff78ce 37596@item g
ee2d5c50 37597@anchor{read registers packet}
b8ff78ce 37598@cindex @samp{g} packet
ee2d5c50
AC
37599Read general registers.
37600
37601Reply:
37602@table @samp
37603@item @var{XX@dots{}}
8e04817f
AC
37604Each byte of register data is described by two hex digits. The bytes
37605with the register are transmitted in target byte order. The size of
b8ff78ce 37606each register and their position within the @samp{g} packet are
4a9bb1df 37607determined by the @value{GDBN} internal gdbarch functions
4435e1cc 37608@code{DEPRECATED_REGISTER_RAW_SIZE} and @code{gdbarch_register_name}.
ad196637
PA
37609
37610When reading registers from a trace frame (@pxref{Analyze Collected
37611Data,,Using the Collected Data}), the stub may also return a string of
37612literal @samp{x}'s in place of the register data digits, to indicate
37613that the corresponding register has not been collected, thus its value
37614is unavailable. For example, for an architecture with 4 registers of
376154 bytes each, the following reply indicates to @value{GDBN} that
37616registers 0 and 2 have not been collected, while registers 1 and 3
37617have been collected, and both have zero value:
37618
37619@smallexample
37620-> @code{g}
37621<- @code{xxxxxxxx00000000xxxxxxxx00000000}
37622@end smallexample
37623
b8ff78ce 37624@item E @var{NN}
ee2d5c50
AC
37625for an error.
37626@end table
c906108c 37627
b8ff78ce
JB
37628@item G @var{XX@dots{}}
37629@cindex @samp{G} packet
37630Write general registers. @xref{read registers packet}, for a
37631description of the @var{XX@dots{}} data.
ee2d5c50
AC
37632
37633Reply:
37634@table @samp
37635@item OK
37636for success
b8ff78ce 37637@item E @var{NN}
ee2d5c50
AC
37638for an error
37639@end table
37640
393eab54 37641@item H @var{op} @var{thread-id}
b8ff78ce 37642@cindex @samp{H} packet
8e04817f 37643Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
697aa1b7
EZ
37644@samp{G}, et.al.). Depending on the operation to be performed, @var{op}
37645should be @samp{c} for step and continue operations (note that this
393eab54 37646is deprecated, supporting the @samp{vCont} command is a better
697aa1b7 37647option), and @samp{g} for other operations. The thread designator
393eab54
PA
37648@var{thread-id} has the format and interpretation described in
37649@ref{thread-id syntax}.
ee2d5c50
AC
37650
37651Reply:
37652@table @samp
37653@item OK
37654for success
b8ff78ce 37655@item E @var{NN}
ee2d5c50
AC
37656for an error
37657@end table
c906108c 37658
8e04817f
AC
37659@c FIXME: JTC:
37660@c 'H': How restrictive (or permissive) is the thread model. If a
37661@c thread is selected and stopped, are other threads allowed
37662@c to continue to execute? As I mentioned above, I think the
37663@c semantics of each command when a thread is selected must be
37664@c described. For example:
37665@c
37666@c 'g': If the stub supports threads and a specific thread is
37667@c selected, returns the register block from that thread;
37668@c otherwise returns current registers.
37669@c
37670@c 'G' If the stub supports threads and a specific thread is
37671@c selected, sets the registers of the register block of
37672@c that thread; otherwise sets current registers.
c906108c 37673
b8ff78ce 37674@item i @r{[}@var{addr}@r{[},@var{nnn}@r{]]}
ee2d5c50 37675@anchor{cycle step packet}
b8ff78ce
JB
37676@cindex @samp{i} packet
37677Step the remote target by a single clock cycle. If @samp{,@var{nnn}} is
8e04817f
AC
37678present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
37679step starting at that address.
c906108c 37680
b8ff78ce
JB
37681@item I
37682@cindex @samp{I} packet
37683Signal, then cycle step. @xref{step with signal packet}. @xref{cycle
37684step packet}.
ee2d5c50 37685
b8ff78ce
JB
37686@item k
37687@cindex @samp{k} packet
37688Kill request.
c906108c 37689
36cb1214
HZ
37690The exact effect of this packet is not specified.
37691
37692For a bare-metal target, it may power cycle or reset the target
37693system. For that reason, the @samp{k} packet has no reply.
37694
37695For a single-process target, it may kill that process if possible.
37696
37697A multiple-process target may choose to kill just one process, or all
37698that are under @value{GDBN}'s control. For more precise control, use
37699the vKill packet (@pxref{vKill packet}).
37700
37701If the target system immediately closes the connection in response to
37702@samp{k}, @value{GDBN} does not consider the lack of packet
37703acknowledgment to be an error, and assumes the kill was successful.
37704
37705If connected using @kbd{target extended-remote}, and the target does
37706not close the connection in response to a kill request, @value{GDBN}
37707probes the target state as if a new connection was opened
37708(@pxref{? packet}).
c906108c 37709
b8ff78ce
JB
37710@item m @var{addr},@var{length}
37711@cindex @samp{m} packet
a86c90e6
SM
37712Read @var{length} addressable memory units starting at address @var{addr}
37713(@pxref{addressable memory unit}). Note that @var{addr} may not be aligned to
37714any particular boundary.
fb031cdf
JB
37715
37716The stub need not use any particular size or alignment when gathering
37717data from memory for the response; even if @var{addr} is word-aligned
37718and @var{length} is a multiple of the word size, the stub is free to
37719use byte accesses, or not. For this reason, this packet may not be
37720suitable for accessing memory-mapped I/O devices.
c43c5473
JB
37721@cindex alignment of remote memory accesses
37722@cindex size of remote memory accesses
37723@cindex memory, alignment and size of remote accesses
c906108c 37724
ee2d5c50
AC
37725Reply:
37726@table @samp
37727@item @var{XX@dots{}}
a86c90e6
SM
37728Memory contents; each byte is transmitted as a two-digit hexadecimal number.
37729The reply may contain fewer addressable memory units than requested if the
b8ff78ce
JB
37730server was able to read only part of the region of memory.
37731@item E @var{NN}
ee2d5c50
AC
37732@var{NN} is errno
37733@end table
37734
b8ff78ce
JB
37735@item M @var{addr},@var{length}:@var{XX@dots{}}
37736@cindex @samp{M} packet
a86c90e6
SM
37737Write @var{length} addressable memory units starting at address @var{addr}
37738(@pxref{addressable memory unit}). The data is given by @var{XX@dots{}}; each
37739byte is transmitted as a two-digit hexadecimal number.
ee2d5c50
AC
37740
37741Reply:
37742@table @samp
37743@item OK
37744for success
b8ff78ce 37745@item E @var{NN}
8e04817f
AC
37746for an error (this includes the case where only part of the data was
37747written).
ee2d5c50 37748@end table
c906108c 37749
b8ff78ce
JB
37750@item p @var{n}
37751@cindex @samp{p} packet
37752Read the value of register @var{n}; @var{n} is in hex.
2e868123
AC
37753@xref{read registers packet}, for a description of how the returned
37754register value is encoded.
ee2d5c50
AC
37755
37756Reply:
37757@table @samp
2e868123
AC
37758@item @var{XX@dots{}}
37759the register's value
b8ff78ce 37760@item E @var{NN}
2e868123 37761for an error
d57350ea 37762@item @w{}
2e868123 37763Indicating an unrecognized @var{query}.
ee2d5c50
AC
37764@end table
37765
b8ff78ce 37766@item P @var{n@dots{}}=@var{r@dots{}}
ee2d5c50 37767@anchor{write register packet}
b8ff78ce
JB
37768@cindex @samp{P} packet
37769Write register @var{n@dots{}} with value @var{r@dots{}}. The register
599b237a 37770number @var{n} is in hexadecimal, and @var{r@dots{}} contains two hex
8e04817f 37771digits for each byte in the register (target byte order).
c906108c 37772
ee2d5c50
AC
37773Reply:
37774@table @samp
37775@item OK
37776for success
b8ff78ce 37777@item E @var{NN}
ee2d5c50
AC
37778for an error
37779@end table
37780
5f3bebba
JB
37781@item q @var{name} @var{params}@dots{}
37782@itemx Q @var{name} @var{params}@dots{}
b8ff78ce 37783@cindex @samp{q} packet
b8ff78ce 37784@cindex @samp{Q} packet
5f3bebba
JB
37785General query (@samp{q}) and set (@samp{Q}). These packets are
37786described fully in @ref{General Query Packets}.
c906108c 37787
b8ff78ce
JB
37788@item r
37789@cindex @samp{r} packet
8e04817f 37790Reset the entire system.
c906108c 37791
b8ff78ce 37792Don't use this packet; use the @samp{R} packet instead.
ee2d5c50 37793
b8ff78ce
JB
37794@item R @var{XX}
37795@cindex @samp{R} packet
697aa1b7 37796Restart the program being debugged. The @var{XX}, while needed, is ignored.
2d717e4f 37797This packet is only available in extended mode (@pxref{extended mode}).
ee2d5c50 37798
8e04817f 37799The @samp{R} packet has no reply.
ee2d5c50 37800
4f553f88 37801@item s @r{[}@var{addr}@r{]}
b8ff78ce 37802@cindex @samp{s} packet
697aa1b7 37803Single step, resuming at @var{addr}. If
b8ff78ce 37804@var{addr} is omitted, resume at same address.
c906108c 37805
393eab54
PA
37806This packet is deprecated for multi-threading support. @xref{vCont
37807packet}.
37808
ee2d5c50
AC
37809Reply:
37810@xref{Stop Reply Packets}, for the reply specifications.
37811
4f553f88 37812@item S @var{sig}@r{[};@var{addr}@r{]}
ee2d5c50 37813@anchor{step with signal packet}
b8ff78ce
JB
37814@cindex @samp{S} packet
37815Step with signal. This is analogous to the @samp{C} packet, but
37816requests a single-step, rather than a normal resumption of execution.
c906108c 37817
393eab54
PA
37818This packet is deprecated for multi-threading support. @xref{vCont
37819packet}.
37820
ee2d5c50
AC
37821Reply:
37822@xref{Stop Reply Packets}, for the reply specifications.
37823
b8ff78ce
JB
37824@item t @var{addr}:@var{PP},@var{MM}
37825@cindex @samp{t} packet
8e04817f 37826Search backwards starting at address @var{addr} for a match with pattern
697aa1b7
EZ
37827@var{PP} and mask @var{MM}, both of which are are 4 byte long.
37828There must be at least 3 digits in @var{addr}.
c906108c 37829
b90a069a 37830@item T @var{thread-id}
b8ff78ce 37831@cindex @samp{T} packet
b90a069a 37832Find out if the thread @var{thread-id} is alive. @xref{thread-id syntax}.
c906108c 37833
ee2d5c50
AC
37834Reply:
37835@table @samp
37836@item OK
37837thread is still alive
b8ff78ce 37838@item E @var{NN}
ee2d5c50
AC
37839thread is dead
37840@end table
37841
b8ff78ce
JB
37842@item v
37843Packets starting with @samp{v} are identified by a multi-letter name,
37844up to the first @samp{;} or @samp{?} (or the end of the packet).
86d30acc 37845
2d717e4f
DJ
37846@item vAttach;@var{pid}
37847@cindex @samp{vAttach} packet
8b23ecc4
SL
37848Attach to a new process with the specified process ID @var{pid}.
37849The process ID is a
37850hexadecimal integer identifying the process. In all-stop mode, all
37851threads in the attached process are stopped; in non-stop mode, it may be
37852attached without being stopped if that is supported by the target.
37853
37854@c In non-stop mode, on a successful vAttach, the stub should set the
37855@c current thread to a thread of the newly-attached process. After
37856@c attaching, GDB queries for the attached process's thread ID with qC.
37857@c Also note that, from a user perspective, whether or not the
37858@c target is stopped on attach in non-stop mode depends on whether you
37859@c use the foreground or background version of the attach command, not
37860@c on what vAttach does; GDB does the right thing with respect to either
37861@c stopping or restarting threads.
2d717e4f
DJ
37862
37863This packet is only available in extended mode (@pxref{extended mode}).
37864
37865Reply:
37866@table @samp
37867@item E @var{nn}
37868for an error
37869@item @r{Any stop packet}
8b23ecc4
SL
37870for success in all-stop mode (@pxref{Stop Reply Packets})
37871@item OK
37872for success in non-stop mode (@pxref{Remote Non-Stop})
2d717e4f
DJ
37873@end table
37874
b90a069a 37875@item vCont@r{[};@var{action}@r{[}:@var{thread-id}@r{]]}@dots{}
b8ff78ce 37876@cindex @samp{vCont} packet
393eab54 37877@anchor{vCont packet}
b8ff78ce 37878Resume the inferior, specifying different actions for each thread.
ca6eff59
PA
37879
37880For each inferior thread, the leftmost action with a matching
37881@var{thread-id} is applied. Threads that don't match any action
37882remain in their current state. Thread IDs are specified using the
37883syntax described in @ref{thread-id syntax}. If multiprocess
37884extensions (@pxref{multiprocess extensions}) are supported, actions
37885can be specified to match all threads in a process by using the
37886@samp{p@var{pid}.-1} form of the @var{thread-id}. An action with no
39402e6c
PA
37887@var{thread-id} matches all threads. Specifying no actions is an
37888error.
b90a069a
SL
37889
37890Currently supported actions are:
86d30acc 37891
b8ff78ce 37892@table @samp
86d30acc
DJ
37893@item c
37894Continue.
b8ff78ce 37895@item C @var{sig}
8b23ecc4 37896Continue with signal @var{sig}. The signal @var{sig} should be two hex digits.
86d30acc
DJ
37897@item s
37898Step.
b8ff78ce 37899@item S @var{sig}
8b23ecc4
SL
37900Step with signal @var{sig}. The signal @var{sig} should be two hex digits.
37901@item t
37902Stop.
c1e36e3e
PA
37903@item r @var{start},@var{end}
37904Step once, and then keep stepping as long as the thread stops at
37905addresses between @var{start} (inclusive) and @var{end} (exclusive).
37906The remote stub reports a stop reply when either the thread goes out
37907of the range or is stopped due to an unrelated reason, such as hitting
37908a breakpoint. @xref{range stepping}.
37909
37910If the range is empty (@var{start} == @var{end}), then the action
37911becomes equivalent to the @samp{s} action. In other words,
37912single-step once, and report the stop (even if the stepped instruction
37913jumps to @var{start}).
37914
37915(A stop reply may be sent at any point even if the PC is still within
37916the stepping range; for example, it is valid to implement this packet
37917in a degenerate way as a single instruction step operation.)
37918
86d30acc
DJ
37919@end table
37920
8b23ecc4
SL
37921The optional argument @var{addr} normally associated with the
37922@samp{c}, @samp{C}, @samp{s}, and @samp{S} packets is
b8ff78ce 37923not supported in @samp{vCont}.
86d30acc 37924
08a0efd0
PA
37925The @samp{t} action is only relevant in non-stop mode
37926(@pxref{Remote Non-Stop}) and may be ignored by the stub otherwise.
8b23ecc4
SL
37927A stop reply should be generated for any affected thread not already stopped.
37928When a thread is stopped by means of a @samp{t} action,
37929the corresponding stop reply should indicate that the thread has stopped with
37930signal @samp{0}, regardless of whether the target uses some other signal
37931as an implementation detail.
37932
ca6eff59
PA
37933The server must ignore @samp{c}, @samp{C}, @samp{s}, @samp{S}, and
37934@samp{r} actions for threads that are already running. Conversely,
37935the server must ignore @samp{t} actions for threads that are already
37936stopped.
37937
37938@emph{Note:} In non-stop mode, a thread is considered running until
37939@value{GDBN} acknowleges an asynchronous stop notification for it with
37940the @samp{vStopped} packet (@pxref{Remote Non-Stop}).
37941
4220b2f8 37942The stub must support @samp{vCont} if it reports support for
ca6eff59 37943multiprocess extensions (@pxref{multiprocess extensions}).
4220b2f8 37944
86d30acc
DJ
37945Reply:
37946@xref{Stop Reply Packets}, for the reply specifications.
37947
b8ff78ce
JB
37948@item vCont?
37949@cindex @samp{vCont?} packet
d3e8051b 37950Request a list of actions supported by the @samp{vCont} packet.
86d30acc
DJ
37951
37952Reply:
37953@table @samp
b8ff78ce
JB
37954@item vCont@r{[};@var{action}@dots{}@r{]}
37955The @samp{vCont} packet is supported. Each @var{action} is a supported
37956command in the @samp{vCont} packet.
d57350ea 37957@item @w{}
b8ff78ce 37958The @samp{vCont} packet is not supported.
86d30acc 37959@end table
ee2d5c50 37960
de979965
PA
37961@anchor{vCtrlC packet}
37962@item vCtrlC
37963@cindex @samp{vCtrlC} packet
37964Interrupt remote target as if a control-C was pressed on the remote
37965terminal. This is the equivalent to reacting to the @code{^C}
37966(@samp{\003}, the control-C character) character in all-stop mode
37967while the target is running, except this works in non-stop mode.
37968@xref{interrupting remote targets}, for more info on the all-stop
37969variant.
37970
37971Reply:
37972@table @samp
37973@item E @var{nn}
37974for an error
37975@item OK
37976for success
37977@end table
37978
a6b151f1
DJ
37979@item vFile:@var{operation}:@var{parameter}@dots{}
37980@cindex @samp{vFile} packet
37981Perform a file operation on the target system. For details,
37982see @ref{Host I/O Packets}.
37983
68437a39
DJ
37984@item vFlashErase:@var{addr},@var{length}
37985@cindex @samp{vFlashErase} packet
37986Direct the stub to erase @var{length} bytes of flash starting at
37987@var{addr}. The region may enclose any number of flash blocks, but
37988its start and end must fall on block boundaries, as indicated by the
79a6e687
BW
37989flash block size appearing in the memory map (@pxref{Memory Map
37990Format}). @value{GDBN} groups flash memory programming operations
68437a39
DJ
37991together, and sends a @samp{vFlashDone} request after each group; the
37992stub is allowed to delay erase operation until the @samp{vFlashDone}
37993packet is received.
37994
37995Reply:
37996@table @samp
37997@item OK
37998for success
37999@item E @var{NN}
38000for an error
38001@end table
38002
38003@item vFlashWrite:@var{addr}:@var{XX@dots{}}
38004@cindex @samp{vFlashWrite} packet
38005Direct the stub to write data to flash address @var{addr}. The data
38006is passed in binary form using the same encoding as for the @samp{X}
38007packet (@pxref{Binary Data}). The memory ranges specified by
38008@samp{vFlashWrite} packets preceding a @samp{vFlashDone} packet must
38009not overlap, and must appear in order of increasing addresses
38010(although @samp{vFlashErase} packets for higher addresses may already
38011have been received; the ordering is guaranteed only between
38012@samp{vFlashWrite} packets). If a packet writes to an address that was
38013neither erased by a preceding @samp{vFlashErase} packet nor by some other
38014target-specific method, the results are unpredictable.
38015
38016
38017Reply:
38018@table @samp
38019@item OK
38020for success
38021@item E.memtype
38022for vFlashWrite addressing non-flash memory
38023@item E @var{NN}
38024for an error
38025@end table
38026
38027@item vFlashDone
38028@cindex @samp{vFlashDone} packet
38029Indicate to the stub that flash programming operation is finished.
38030The stub is permitted to delay or batch the effects of a group of
38031@samp{vFlashErase} and @samp{vFlashWrite} packets until a
38032@samp{vFlashDone} packet is received. The contents of the affected
38033regions of flash memory are unpredictable until the @samp{vFlashDone}
38034request is completed.
38035
b90a069a
SL
38036@item vKill;@var{pid}
38037@cindex @samp{vKill} packet
36cb1214 38038@anchor{vKill packet}
697aa1b7 38039Kill the process with the specified process ID @var{pid}, which is a
b90a069a
SL
38040hexadecimal integer identifying the process. This packet is used in
38041preference to @samp{k} when multiprocess protocol extensions are
38042supported; see @ref{multiprocess extensions}.
38043
38044Reply:
38045@table @samp
38046@item E @var{nn}
38047for an error
38048@item OK
38049for success
38050@end table
38051
176efed1
AB
38052@item vMustReplyEmpty
38053@cindex @samp{vMustReplyEmpty} packet
38054The correct reply to an unknown @samp{v} packet is to return the empty
38055string, however, some older versions of @command{gdbserver} would
38056incorrectly return @samp{OK} for unknown @samp{v} packets.
38057
38058The @samp{vMustReplyEmpty} is used as a feature test to check how
38059@command{gdbserver} handles unknown packets, it is important that this
38060packet be handled in the same way as other unknown @samp{v} packets.
38061If this packet is handled differently to other unknown @samp{v}
38062packets then it is possile that @value{GDBN} may run into problems in
38063other areas, specifically around use of @samp{vFile:setfs:}.
38064
2d717e4f
DJ
38065@item vRun;@var{filename}@r{[};@var{argument}@r{]}@dots{}
38066@cindex @samp{vRun} packet
38067Run the program @var{filename}, passing it each @var{argument} on its
38068command line. The file and arguments are hex-encoded strings. If
38069@var{filename} is an empty string, the stub may use a default program
38070(e.g.@: the last program run). The program is created in the stopped
9b562ab8 38071state.
2d717e4f 38072
8b23ecc4
SL
38073@c FIXME: What about non-stop mode?
38074
2d717e4f
DJ
38075This packet is only available in extended mode (@pxref{extended mode}).
38076
38077Reply:
38078@table @samp
38079@item E @var{nn}
38080for an error
38081@item @r{Any stop packet}
38082for success (@pxref{Stop Reply Packets})
38083@end table
38084
8b23ecc4 38085@item vStopped
8b23ecc4 38086@cindex @samp{vStopped} packet
8dbe8ece 38087@xref{Notification Packets}.
8b23ecc4 38088
b8ff78ce 38089@item X @var{addr},@var{length}:@var{XX@dots{}}
9a6253be 38090@anchor{X packet}
b8ff78ce
JB
38091@cindex @samp{X} packet
38092Write data to memory, where the data is transmitted in binary.
a86c90e6
SM
38093Memory is specified by its address @var{addr} and number of addressable memory
38094units @var{length} (@pxref{addressable memory unit});
0876f84a 38095@samp{@var{XX}@dots{}} is binary data (@pxref{Binary Data}).
c906108c 38096
ee2d5c50
AC
38097Reply:
38098@table @samp
38099@item OK
38100for success
b8ff78ce 38101@item E @var{NN}
ee2d5c50
AC
38102for an error
38103@end table
38104
a1dcb23a
DJ
38105@item z @var{type},@var{addr},@var{kind}
38106@itemx Z @var{type},@var{addr},@var{kind}
2f870471 38107@anchor{insert breakpoint or watchpoint packet}
b8ff78ce
JB
38108@cindex @samp{z} packet
38109@cindex @samp{Z} packets
38110Insert (@samp{Z}) or remove (@samp{z}) a @var{type} breakpoint or
a1dcb23a 38111watchpoint starting at address @var{address} of kind @var{kind}.
ee2d5c50 38112
2f870471
AC
38113Each breakpoint and watchpoint packet @var{type} is documented
38114separately.
38115
512217c7
AC
38116@emph{Implementation notes: A remote target shall return an empty string
38117for an unrecognized breakpoint or watchpoint packet @var{type}. A
38118remote target shall support either both or neither of a given
b8ff78ce 38119@samp{Z@var{type}@dots{}} and @samp{z@var{type}@dots{}} packet pair. To
2f870471
AC
38120avoid potential problems with duplicate packets, the operations should
38121be implemented in an idempotent way.}
38122
a1dcb23a 38123@item z0,@var{addr},@var{kind}
d3ce09f5 38124@itemx Z0,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}@r{[};cmds:@var{persist},@var{cmd_list}@dots{}@r{]}
b8ff78ce
JB
38125@cindex @samp{z0} packet
38126@cindex @samp{Z0} packet
4435e1cc 38127Insert (@samp{Z0}) or remove (@samp{z0}) a software breakpoint at address
a1dcb23a 38128@var{addr} of type @var{kind}.
2f870471 38129
4435e1cc 38130A software breakpoint is implemented by replacing the instruction at
2f870471 38131@var{addr} with a software breakpoint or trap instruction. The
4435e1cc
TT
38132@var{kind} is target-specific and typically indicates the size of the
38133breakpoint in bytes that should be inserted. E.g., the @sc{arm} and
38134@sc{mips} can insert either a 2 or 4 byte breakpoint. Some
38135architectures have additional meanings for @var{kind}
38136(@pxref{Architecture-Specific Protocol Details}); if no
38137architecture-specific value is being used, it should be @samp{0}.
38138@var{kind} is hex-encoded. @var{cond_list} is an optional list of
38139conditional expressions in bytecode form that should be evaluated on
38140the target's side. These are the conditions that should be taken into
38141consideration when deciding if the breakpoint trigger should be
38142reported back to @value{GDBN}.
83364271 38143
f7e6eed5 38144See also the @samp{swbreak} stop reason (@pxref{swbreak stop reason})
4435e1cc 38145for how to best report a software breakpoint event to @value{GDBN}.
f7e6eed5 38146
83364271
LM
38147The @var{cond_list} parameter is comprised of a series of expressions,
38148concatenated without separators. Each expression has the following form:
38149
38150@table @samp
38151
38152@item X @var{len},@var{expr}
38153@var{len} is the length of the bytecode expression and @var{expr} is the
38154actual conditional expression in bytecode form.
38155
38156@end table
38157
d3ce09f5
SS
38158The optional @var{cmd_list} parameter introduces commands that may be
38159run on the target, rather than being reported back to @value{GDBN}.
38160The parameter starts with a numeric flag @var{persist}; if the flag is
38161nonzero, then the breakpoint may remain active and the commands
38162continue to be run even when @value{GDBN} disconnects from the target.
38163Following this flag is a series of expressions concatenated with no
38164separators. Each expression has the following form:
38165
38166@table @samp
38167
38168@item X @var{len},@var{expr}
38169@var{len} is the length of the bytecode expression and @var{expr} is the
0968fbae 38170actual commands expression in bytecode form.
d3ce09f5
SS
38171
38172@end table
38173
2f870471 38174@emph{Implementation note: It is possible for a target to copy or move
4435e1cc 38175code that contains software breakpoints (e.g., when implementing
2f870471
AC
38176overlays). The behavior of this packet, in the presence of such a
38177target, is not defined.}
c906108c 38178
ee2d5c50
AC
38179Reply:
38180@table @samp
2f870471
AC
38181@item OK
38182success
d57350ea 38183@item @w{}
2f870471 38184not supported
b8ff78ce 38185@item E @var{NN}
ee2d5c50 38186for an error
2f870471
AC
38187@end table
38188
a1dcb23a 38189@item z1,@var{addr},@var{kind}
4435e1cc 38190@itemx Z1,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}@r{[};cmds:@var{persist},@var{cmd_list}@dots{}@r{]}
b8ff78ce
JB
38191@cindex @samp{z1} packet
38192@cindex @samp{Z1} packet
38193Insert (@samp{Z1}) or remove (@samp{z1}) a hardware breakpoint at
a1dcb23a 38194address @var{addr}.
2f870471
AC
38195
38196A hardware breakpoint is implemented using a mechanism that is not
4435e1cc
TT
38197dependent on being able to modify the target's memory. The
38198@var{kind}, @var{cond_list}, and @var{cmd_list} arguments have the
38199same meaning as in @samp{Z0} packets.
2f870471
AC
38200
38201@emph{Implementation note: A hardware breakpoint is not affected by code
38202movement.}
38203
38204Reply:
38205@table @samp
ee2d5c50 38206@item OK
2f870471 38207success
d57350ea 38208@item @w{}
2f870471 38209not supported
b8ff78ce 38210@item E @var{NN}
2f870471
AC
38211for an error
38212@end table
38213
a1dcb23a
DJ
38214@item z2,@var{addr},@var{kind}
38215@itemx Z2,@var{addr},@var{kind}
b8ff78ce
JB
38216@cindex @samp{z2} packet
38217@cindex @samp{Z2} packet
a1dcb23a 38218Insert (@samp{Z2}) or remove (@samp{z2}) a write watchpoint at @var{addr}.
697aa1b7 38219The number of bytes to watch is specified by @var{kind}.
2f870471
AC
38220
38221Reply:
38222@table @samp
38223@item OK
38224success
d57350ea 38225@item @w{}
2f870471 38226not supported
b8ff78ce 38227@item E @var{NN}
2f870471
AC
38228for an error
38229@end table
38230
a1dcb23a
DJ
38231@item z3,@var{addr},@var{kind}
38232@itemx Z3,@var{addr},@var{kind}
b8ff78ce
JB
38233@cindex @samp{z3} packet
38234@cindex @samp{Z3} packet
a1dcb23a 38235Insert (@samp{Z3}) or remove (@samp{z3}) a read watchpoint at @var{addr}.
697aa1b7 38236The number of bytes to watch is specified by @var{kind}.
2f870471
AC
38237
38238Reply:
38239@table @samp
38240@item OK
38241success
d57350ea 38242@item @w{}
2f870471 38243not supported
b8ff78ce 38244@item E @var{NN}
2f870471
AC
38245for an error
38246@end table
38247
a1dcb23a
DJ
38248@item z4,@var{addr},@var{kind}
38249@itemx Z4,@var{addr},@var{kind}
b8ff78ce
JB
38250@cindex @samp{z4} packet
38251@cindex @samp{Z4} packet
a1dcb23a 38252Insert (@samp{Z4}) or remove (@samp{z4}) an access watchpoint at @var{addr}.
697aa1b7 38253The number of bytes to watch is specified by @var{kind}.
2f870471
AC
38254
38255Reply:
38256@table @samp
38257@item OK
38258success
d57350ea 38259@item @w{}
2f870471 38260not supported
b8ff78ce 38261@item E @var{NN}
2f870471 38262for an error
ee2d5c50
AC
38263@end table
38264
38265@end table
c906108c 38266
ee2d5c50
AC
38267@node Stop Reply Packets
38268@section Stop Reply Packets
38269@cindex stop reply packets
c906108c 38270
8b23ecc4
SL
38271The @samp{C}, @samp{c}, @samp{S}, @samp{s}, @samp{vCont},
38272@samp{vAttach}, @samp{vRun}, @samp{vStopped}, and @samp{?} packets can
38273receive any of the below as a reply. Except for @samp{?}
38274and @samp{vStopped}, that reply is only returned
b8ff78ce 38275when the target halts. In the below the exact meaning of @dfn{signal
89be2091
DJ
38276number} is defined by the header @file{include/gdb/signals.h} in the
38277@value{GDBN} source code.
c906108c 38278
4435e1cc
TT
38279In non-stop mode, the server will simply reply @samp{OK} to commands
38280such as @samp{vCont}; any stop will be the subject of a future
38281notification. @xref{Remote Non-Stop}.
38282
b8ff78ce
JB
38283As in the description of request packets, we include spaces in the
38284reply templates for clarity; these are not part of the reply packet's
38285syntax. No @value{GDBN} stop reply packet uses spaces to separate its
38286components.
c906108c 38287
b8ff78ce 38288@table @samp
ee2d5c50 38289
b8ff78ce 38290@item S @var{AA}
599b237a 38291The program received signal number @var{AA} (a two-digit hexadecimal
940178d3
JB
38292number). This is equivalent to a @samp{T} response with no
38293@var{n}:@var{r} pairs.
c906108c 38294
b8ff78ce
JB
38295@item T @var{AA} @var{n1}:@var{r1};@var{n2}:@var{r2};@dots{}
38296@cindex @samp{T} packet reply
599b237a 38297The program received signal number @var{AA} (a two-digit hexadecimal
940178d3
JB
38298number). This is equivalent to an @samp{S} response, except that the
38299@samp{@var{n}:@var{r}} pairs can carry values of important registers
38300and other information directly in the stop reply packet, reducing
38301round-trip latency. Single-step and breakpoint traps are reported
38302this way. Each @samp{@var{n}:@var{r}} pair is interpreted as follows:
cfa9d6d9
DJ
38303
38304@itemize @bullet
b8ff78ce 38305@item
599b237a 38306If @var{n} is a hexadecimal number, it is a register number, and the
697aa1b7 38307corresponding @var{r} gives that register's value. The data @var{r} is a
b8ff78ce
JB
38308series of bytes in target byte order, with each byte given by a
38309two-digit hex number.
cfa9d6d9 38310
b8ff78ce 38311@item
b90a069a
SL
38312If @var{n} is @samp{thread}, then @var{r} is the @var{thread-id} of
38313the stopped thread, as specified in @ref{thread-id syntax}.
cfa9d6d9 38314
dc146f7c
VP
38315@item
38316If @var{n} is @samp{core}, then @var{r} is the hexadecimal number of
38317the core on which the stop event was detected.
38318
b8ff78ce 38319@item
cfa9d6d9
DJ
38320If @var{n} is a recognized @dfn{stop reason}, it describes a more
38321specific event that stopped the target. The currently defined stop
697aa1b7 38322reasons are listed below. The @var{aa} should be @samp{05}, the trap
cfa9d6d9
DJ
38323signal. At most one stop reason should be present.
38324
b8ff78ce
JB
38325@item
38326Otherwise, @value{GDBN} should ignore this @samp{@var{n}:@var{r}} pair
38327and go on to the next; this allows us to extend the protocol in the
38328future.
cfa9d6d9
DJ
38329@end itemize
38330
38331The currently defined stop reasons are:
38332
38333@table @samp
38334@item watch
38335@itemx rwatch
38336@itemx awatch
38337The packet indicates a watchpoint hit, and @var{r} is the data address, in
38338hex.
38339
82075af2
JS
38340@item syscall_entry
38341@itemx syscall_return
38342The packet indicates a syscall entry or return, and @var{r} is the
38343syscall number, in hex.
38344
cfa9d6d9
DJ
38345@cindex shared library events, remote reply
38346@item library
38347The packet indicates that the loaded libraries have changed.
38348@value{GDBN} should use @samp{qXfer:libraries:read} to fetch a new
697aa1b7 38349list of loaded libraries. The @var{r} part is ignored.
bacec72f
MS
38350
38351@cindex replay log events, remote reply
38352@item replaylog
38353The packet indicates that the target cannot continue replaying
38354logged execution events, because it has reached the end (or the
38355beginning when executing backward) of the log. The value of @var{r}
38356will be either @samp{begin} or @samp{end}. @xref{Reverse Execution},
38357for more information.
f7e6eed5
PA
38358
38359@item swbreak
38360@anchor{swbreak stop reason}
4435e1cc 38361The packet indicates a software breakpoint instruction was executed,
f7e6eed5
PA
38362irrespective of whether it was @value{GDBN} that planted the
38363breakpoint or the breakpoint is hardcoded in the program. The @var{r}
38364part must be left empty.
38365
38366On some architectures, such as x86, at the architecture level, when a
38367breakpoint instruction executes the program counter points at the
38368breakpoint address plus an offset. On such targets, the stub is
38369responsible for adjusting the PC to point back at the breakpoint
38370address.
38371
38372This packet should not be sent by default; older @value{GDBN} versions
38373did not support it. @value{GDBN} requests it, by supplying an
38374appropriate @samp{qSupported} feature (@pxref{qSupported}). The
38375remote stub must also supply the appropriate @samp{qSupported} feature
38376indicating support.
38377
38378This packet is required for correct non-stop mode operation.
38379
38380@item hwbreak
38381The packet indicates the target stopped for a hardware breakpoint.
38382The @var{r} part must be left empty.
38383
38384The same remarks about @samp{qSupported} and non-stop mode above
38385apply.
0d71eef5
DB
38386
38387@cindex fork events, remote reply
38388@item fork
38389The packet indicates that @code{fork} was called, and @var{r}
38390is the thread ID of the new child process. Refer to
38391@ref{thread-id syntax} for the format of the @var{thread-id}
38392field. This packet is only applicable to targets that support
38393fork events.
38394
38395This packet should not be sent by default; older @value{GDBN} versions
38396did not support it. @value{GDBN} requests it, by supplying an
38397appropriate @samp{qSupported} feature (@pxref{qSupported}). The
38398remote stub must also supply the appropriate @samp{qSupported} feature
38399indicating support.
38400
38401@cindex vfork events, remote reply
38402@item vfork
38403The packet indicates that @code{vfork} was called, and @var{r}
38404is the thread ID of the new child process. Refer to
38405@ref{thread-id syntax} for the format of the @var{thread-id}
38406field. This packet is only applicable to targets that support
38407vfork events.
38408
38409This packet should not be sent by default; older @value{GDBN} versions
38410did not support it. @value{GDBN} requests it, by supplying an
38411appropriate @samp{qSupported} feature (@pxref{qSupported}). The
38412remote stub must also supply the appropriate @samp{qSupported} feature
38413indicating support.
38414
38415@cindex vforkdone events, remote reply
38416@item vforkdone
e68fa6f0
PA
38417The packet indicates that a child process created by a vfork
38418has either called @code{exec} or terminated, so that the
38419address spaces of the parent and child process are no longer
38420shared. The @var{r} part is ignored. This packet is only
38421applicable to targets that support vforkdone events.
0d71eef5
DB
38422
38423This packet should not be sent by default; older @value{GDBN} versions
38424did not support it. @value{GDBN} requests it, by supplying an
38425appropriate @samp{qSupported} feature (@pxref{qSupported}). The
38426remote stub must also supply the appropriate @samp{qSupported} feature
38427indicating support.
38428
b459a59b
DB
38429@cindex exec events, remote reply
38430@item exec
38431The packet indicates that @code{execve} was called, and @var{r}
38432is the absolute pathname of the file that was executed, in hex.
38433This packet is only applicable to targets that support exec events.
38434
38435This packet should not be sent by default; older @value{GDBN} versions
38436did not support it. @value{GDBN} requests it, by supplying an
38437appropriate @samp{qSupported} feature (@pxref{qSupported}). The
38438remote stub must also supply the appropriate @samp{qSupported} feature
38439indicating support.
38440
65706a29
PA
38441@cindex thread create event, remote reply
38442@anchor{thread create event}
38443@item create
38444The packet indicates that the thread was just created. The new thread
38445is stopped until @value{GDBN} sets it running with a resumption packet
38446(@pxref{vCont packet}). This packet should not be sent by default;
38447@value{GDBN} requests it with the @ref{QThreadEvents} packet. See
4435e1cc
TT
38448also the @samp{w} (@pxref{thread exit event}) remote reply below. The
38449@var{r} part is ignored.
65706a29 38450
cfa9d6d9 38451@end table
ee2d5c50 38452
b8ff78ce 38453@item W @var{AA}
b90a069a 38454@itemx W @var{AA} ; process:@var{pid}
8e04817f 38455The process exited, and @var{AA} is the exit status. This is only
ee2d5c50
AC
38456applicable to certain targets.
38457
4435e1cc
TT
38458The second form of the response, including the process ID of the
38459exited process, can be used only when @value{GDBN} has reported
38460support for multiprocess protocol extensions; see @ref{multiprocess
38461extensions}. Both @var{AA} and @var{pid} are formatted as big-endian
38462hex strings.
b90a069a 38463
b8ff78ce 38464@item X @var{AA}
b90a069a 38465@itemx X @var{AA} ; process:@var{pid}
8e04817f 38466The process terminated with signal @var{AA}.
c906108c 38467
b90a069a
SL
38468The second form of the response, including the process ID of the
38469terminated process, can be used only when @value{GDBN} has reported
38470support for multiprocess protocol extensions; see @ref{multiprocess
4435e1cc
TT
38471extensions}. Both @var{AA} and @var{pid} are formatted as big-endian
38472hex strings.
b90a069a 38473
65706a29
PA
38474@anchor{thread exit event}
38475@cindex thread exit event, remote reply
38476@item w @var{AA} ; @var{tid}
38477
38478The thread exited, and @var{AA} is the exit status. This response
38479should not be sent by default; @value{GDBN} requests it with the
38480@ref{QThreadEvents} packet. See also @ref{thread create event} above.
4435e1cc 38481@var{AA} is formatted as a big-endian hex string.
65706a29 38482
f2faf941
PA
38483@item N
38484There are no resumed threads left in the target. In other words, even
38485though the process is alive, the last resumed thread has exited. For
38486example, say the target process has two threads: thread 1 and thread
384872. The client leaves thread 1 stopped, and resumes thread 2, which
38488subsequently exits. At this point, even though the process is still
38489alive, and thus no @samp{W} stop reply is sent, no thread is actually
38490executing either. The @samp{N} stop reply thus informs the client
38491that it can stop waiting for stop replies. This packet should not be
38492sent by default; older @value{GDBN} versions did not support it.
38493@value{GDBN} requests it, by supplying an appropriate
38494@samp{qSupported} feature (@pxref{qSupported}). The remote stub must
38495also supply the appropriate @samp{qSupported} feature indicating
38496support.
38497
b8ff78ce
JB
38498@item O @var{XX}@dots{}
38499@samp{@var{XX}@dots{}} is hex encoding of @sc{ascii} data, to be
38500written as the program's console output. This can happen at any time
38501while the program is running and the debugger should continue to wait
8b23ecc4 38502for @samp{W}, @samp{T}, etc. This reply is not permitted in non-stop mode.
0ce1b118 38503
b8ff78ce 38504@item F @var{call-id},@var{parameter}@dots{}
0ce1b118
CV
38505@var{call-id} is the identifier which says which host system call should
38506be called. This is just the name of the function. Translation into the
38507correct system call is only applicable as it's defined in @value{GDBN}.
79a6e687 38508@xref{File-I/O Remote Protocol Extension}, for a list of implemented
0ce1b118
CV
38509system calls.
38510
b8ff78ce
JB
38511@samp{@var{parameter}@dots{}} is a list of parameters as defined for
38512this very system call.
0ce1b118 38513
b8ff78ce
JB
38514The target replies with this packet when it expects @value{GDBN} to
38515call a host system call on behalf of the target. @value{GDBN} replies
38516with an appropriate @samp{F} packet and keeps up waiting for the next
38517reply packet from the target. The latest @samp{C}, @samp{c}, @samp{S}
79a6e687
BW
38518or @samp{s} action is expected to be continued. @xref{File-I/O Remote
38519Protocol Extension}, for more details.
0ce1b118 38520
ee2d5c50
AC
38521@end table
38522
38523@node General Query Packets
38524@section General Query Packets
9c16f35a 38525@cindex remote query requests
c906108c 38526
5f3bebba
JB
38527Packets starting with @samp{q} are @dfn{general query packets};
38528packets starting with @samp{Q} are @dfn{general set packets}. General
38529query and set packets are a semi-unified form for retrieving and
38530sending information to and from the stub.
38531
38532The initial letter of a query or set packet is followed by a name
38533indicating what sort of thing the packet applies to. For example,
38534@value{GDBN} may use a @samp{qSymbol} packet to exchange symbol
38535definitions with the stub. These packet names follow some
38536conventions:
38537
38538@itemize @bullet
38539@item
38540The name must not contain commas, colons or semicolons.
38541@item
38542Most @value{GDBN} query and set packets have a leading upper case
38543letter.
38544@item
38545The names of custom vendor packets should use a company prefix, in
38546lower case, followed by a period. For example, packets designed at
38547the Acme Corporation might begin with @samp{qacme.foo} (for querying
38548foos) or @samp{Qacme.bar} (for setting bars).
38549@end itemize
38550
aa56d27a
JB
38551The name of a query or set packet should be separated from any
38552parameters by a @samp{:}; the parameters themselves should be
38553separated by @samp{,} or @samp{;}. Stubs must be careful to match the
369af7bd
DJ
38554full packet name, and check for a separator or the end of the packet,
38555in case two packet names share a common prefix. New packets should not begin
38556with @samp{qC}, @samp{qP}, or @samp{qL}@footnote{The @samp{qP} and @samp{qL}
38557packets predate these conventions, and have arguments without any terminator
38558for the packet name; we suspect they are in widespread use in places that
38559are difficult to upgrade. The @samp{qC} packet has no arguments, but some
38560existing stubs (e.g.@: RedBoot) are known to not check for the end of the
38561packet.}.
c906108c 38562
b8ff78ce
JB
38563Like the descriptions of the other packets, each description here
38564has a template showing the packet's overall syntax, followed by an
38565explanation of the packet's meaning. We include spaces in some of the
38566templates for clarity; these are not part of the packet's syntax. No
38567@value{GDBN} packet uses spaces to separate its components.
38568
5f3bebba
JB
38569Here are the currently defined query and set packets:
38570
b8ff78ce 38571@table @samp
c906108c 38572
d1feda86 38573@item QAgent:1
af4238e5 38574@itemx QAgent:0
d1feda86
YQ
38575Turn on or off the agent as a helper to perform some debugging operations
38576delegated from @value{GDBN} (@pxref{Control Agent}).
38577
d914c394
SS
38578@item QAllow:@var{op}:@var{val}@dots{}
38579@cindex @samp{QAllow} packet
38580Specify which operations @value{GDBN} expects to request of the
38581target, as a semicolon-separated list of operation name and value
38582pairs. Possible values for @var{op} include @samp{WriteReg},
38583@samp{WriteMem}, @samp{InsertBreak}, @samp{InsertTrace},
38584@samp{InsertFastTrace}, and @samp{Stop}. @var{val} is either 0,
38585indicating that @value{GDBN} will not request the operation, or 1,
38586indicating that it may. (The target can then use this to set up its
38587own internals optimally, for instance if the debugger never expects to
38588insert breakpoints, it may not need to install its own trap handler.)
38589
b8ff78ce 38590@item qC
9c16f35a 38591@cindex current thread, remote request
b8ff78ce 38592@cindex @samp{qC} packet
b90a069a 38593Return the current thread ID.
ee2d5c50
AC
38594
38595Reply:
38596@table @samp
b90a069a
SL
38597@item QC @var{thread-id}
38598Where @var{thread-id} is a thread ID as documented in
38599@ref{thread-id syntax}.
b8ff78ce 38600@item @r{(anything else)}
b90a069a 38601Any other reply implies the old thread ID.
ee2d5c50
AC
38602@end table
38603
b8ff78ce 38604@item qCRC:@var{addr},@var{length}
ff2587ec 38605@cindex CRC of memory block, remote request
b8ff78ce 38606@cindex @samp{qCRC} packet
936d2992 38607@anchor{qCRC packet}
99e008fe
EZ
38608Compute the CRC checksum of a block of memory using CRC-32 defined in
38609IEEE 802.3. The CRC is computed byte at a time, taking the most
38610significant bit of each byte first. The initial pattern code
38611@code{0xffffffff} is used to ensure leading zeros affect the CRC.
38612
38613@emph{Note:} This is the same CRC used in validating separate debug
38614files (@pxref{Separate Debug Files, , Debugging Information in Separate
38615Files}). However the algorithm is slightly different. When validating
38616separate debug files, the CRC is computed taking the @emph{least}
38617significant bit of each byte first, and the final result is inverted to
38618detect trailing zeros.
38619
ff2587ec
WZ
38620Reply:
38621@table @samp
b8ff78ce 38622@item E @var{NN}
ff2587ec 38623An error (such as memory fault)
b8ff78ce
JB
38624@item C @var{crc32}
38625The specified memory region's checksum is @var{crc32}.
ff2587ec
WZ
38626@end table
38627
03583c20
UW
38628@item QDisableRandomization:@var{value}
38629@cindex disable address space randomization, remote request
38630@cindex @samp{QDisableRandomization} packet
38631Some target operating systems will randomize the virtual address space
38632of the inferior process as a security feature, but provide a feature
38633to disable such randomization, e.g.@: to allow for a more deterministic
38634debugging experience. On such systems, this packet with a @var{value}
38635of 1 directs the target to disable address space randomization for
38636processes subsequently started via @samp{vRun} packets, while a packet
38637with a @var{value} of 0 tells the target to enable address space
38638randomization.
38639
38640This packet is only available in extended mode (@pxref{extended mode}).
38641
38642Reply:
38643@table @samp
38644@item OK
38645The request succeeded.
38646
38647@item E @var{nn}
697aa1b7 38648An error occurred. The error number @var{nn} is given as hex digits.
03583c20 38649
d57350ea 38650@item @w{}
03583c20
UW
38651An empty reply indicates that @samp{QDisableRandomization} is not supported
38652by the stub.
38653@end table
38654
38655This packet is not probed by default; the remote stub must request it,
38656by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
38657This should only be done on targets that actually support disabling
38658address space randomization.
38659
aefd8b33
SDJ
38660@item QStartupWithShell:@var{value}
38661@cindex startup with shell, remote request
38662@cindex @samp{QStartupWithShell} packet
38663On UNIX-like targets, it is possible to start the inferior using a
38664shell program. This is the default behavior on both @value{GDBN} and
38665@command{gdbserver} (@pxref{set startup-with-shell}). This packet is
38666used to inform @command{gdbserver} whether it should start the
38667inferior using a shell or not.
38668
38669If @var{value} is @samp{0}, @command{gdbserver} will not use a shell
38670to start the inferior. If @var{value} is @samp{1},
38671@command{gdbserver} will use a shell to start the inferior. All other
38672values are considered an error.
38673
38674This packet is only available in extended mode (@pxref{extended
38675mode}).
38676
38677Reply:
38678@table @samp
38679@item OK
38680The request succeeded.
38681
38682@item E @var{nn}
38683An error occurred. The error number @var{nn} is given as hex digits.
38684@end table
38685
38686This packet is not probed by default; the remote stub must request it,
38687by supplying an appropriate @samp{qSupported} response
38688(@pxref{qSupported}). This should only be done on targets that
38689actually support starting the inferior using a shell.
38690
38691Use of this packet is controlled by the @code{set startup-with-shell}
38692command; @pxref{set startup-with-shell}.
38693
0a2dde4a
SDJ
38694@item QEnvironmentHexEncoded:@var{hex-value}
38695@anchor{QEnvironmentHexEncoded}
38696@cindex set environment variable, remote request
38697@cindex @samp{QEnvironmentHexEncoded} packet
38698On UNIX-like targets, it is possible to set environment variables that
38699will be passed to the inferior during the startup process. This
38700packet is used to inform @command{gdbserver} of an environment
38701variable that has been defined by the user on @value{GDBN} (@pxref{set
38702environment}).
38703
38704The packet is composed by @var{hex-value}, an hex encoded
38705representation of the @var{name=value} format representing an
38706environment variable. The name of the environment variable is
38707represented by @var{name}, and the value to be assigned to the
38708environment variable is represented by @var{value}. If the variable
38709has no value (i.e., the value is @code{null}), then @var{value} will
38710not be present.
38711
38712This packet is only available in extended mode (@pxref{extended
38713mode}).
38714
38715Reply:
38716@table @samp
38717@item OK
38718The request succeeded.
38719@end table
38720
38721This packet is not probed by default; the remote stub must request it,
38722by supplying an appropriate @samp{qSupported} response
38723(@pxref{qSupported}). This should only be done on targets that
38724actually support passing environment variables to the starting
38725inferior.
38726
38727This packet is related to the @code{set environment} command;
38728@pxref{set environment}.
38729
38730@item QEnvironmentUnset:@var{hex-value}
38731@anchor{QEnvironmentUnset}
38732@cindex unset environment variable, remote request
38733@cindex @samp{QEnvironmentUnset} packet
38734On UNIX-like targets, it is possible to unset environment variables
38735before starting the inferior in the remote target. This packet is
38736used to inform @command{gdbserver} of an environment variable that has
38737been unset by the user on @value{GDBN} (@pxref{unset environment}).
38738
38739The packet is composed by @var{hex-value}, an hex encoded
38740representation of the name of the environment variable to be unset.
38741
38742This packet is only available in extended mode (@pxref{extended
38743mode}).
38744
38745Reply:
38746@table @samp
38747@item OK
38748The request succeeded.
38749@end table
38750
38751This packet is not probed by default; the remote stub must request it,
38752by supplying an appropriate @samp{qSupported} response
38753(@pxref{qSupported}). This should only be done on targets that
38754actually support passing environment variables to the starting
38755inferior.
38756
38757This packet is related to the @code{unset environment} command;
38758@pxref{unset environment}.
38759
38760@item QEnvironmentReset
38761@anchor{QEnvironmentReset}
38762@cindex reset environment, remote request
38763@cindex @samp{QEnvironmentReset} packet
38764On UNIX-like targets, this packet is used to reset the state of
38765environment variables in the remote target before starting the
38766inferior. In this context, reset means unsetting all environment
38767variables that were previously set by the user (i.e., were not
38768initially present in the environment). It is sent to
38769@command{gdbserver} before the @samp{QEnvironmentHexEncoded}
38770(@pxref{QEnvironmentHexEncoded}) and the @samp{QEnvironmentUnset}
38771(@pxref{QEnvironmentUnset}) packets.
38772
38773This packet is only available in extended mode (@pxref{extended
38774mode}).
38775
38776Reply:
38777@table @samp
38778@item OK
38779The request succeeded.
38780@end table
38781
38782This packet is not probed by default; the remote stub must request it,
38783by supplying an appropriate @samp{qSupported} response
38784(@pxref{qSupported}). This should only be done on targets that
38785actually support passing environment variables to the starting
38786inferior.
38787
bc3b087d
SDJ
38788@item QSetWorkingDir:@r{[}@var{directory}@r{]}
38789@anchor{QSetWorkingDir packet}
38790@cindex set working directory, remote request
38791@cindex @samp{QSetWorkingDir} packet
38792This packet is used to inform the remote server of the intended
38793current working directory for programs that are going to be executed.
38794
38795The packet is composed by @var{directory}, an hex encoded
38796representation of the directory that the remote inferior will use as
38797its current working directory. If @var{directory} is an empty string,
38798the remote server should reset the inferior's current working
38799directory to its original, empty value.
38800
38801This packet is only available in extended mode (@pxref{extended
38802mode}).
38803
38804Reply:
38805@table @samp
38806@item OK
38807The request succeeded.
38808@end table
38809
b8ff78ce
JB
38810@item qfThreadInfo
38811@itemx qsThreadInfo
9c16f35a 38812@cindex list active threads, remote request
b8ff78ce
JB
38813@cindex @samp{qfThreadInfo} packet
38814@cindex @samp{qsThreadInfo} packet
b90a069a 38815Obtain a list of all active thread IDs from the target (OS). Since there
8e04817f
AC
38816may be too many active threads to fit into one reply packet, this query
38817works iteratively: it may require more than one query/reply sequence to
38818obtain the entire list of threads. The first query of the sequence will
b8ff78ce
JB
38819be the @samp{qfThreadInfo} query; subsequent queries in the
38820sequence will be the @samp{qsThreadInfo} query.
ee2d5c50 38821
b8ff78ce 38822NOTE: This packet replaces the @samp{qL} query (see below).
ee2d5c50
AC
38823
38824Reply:
38825@table @samp
b90a069a
SL
38826@item m @var{thread-id}
38827A single thread ID
38828@item m @var{thread-id},@var{thread-id}@dots{}
38829a comma-separated list of thread IDs
b8ff78ce
JB
38830@item l
38831(lower case letter @samp{L}) denotes end of list.
ee2d5c50
AC
38832@end table
38833
38834In response to each query, the target will reply with a list of one or
b90a069a 38835more thread IDs, separated by commas.
e1aac25b 38836@value{GDBN} will respond to each reply with a request for more thread
b8ff78ce 38837ids (using the @samp{qs} form of the query), until the target responds
501994c0 38838with @samp{l} (lower-case ell, for @dfn{last}).
b90a069a
SL
38839Refer to @ref{thread-id syntax}, for the format of the @var{thread-id}
38840fields.
c906108c 38841
8dfcab11
DT
38842@emph{Note: @value{GDBN} will send the @code{qfThreadInfo} query during the
38843initial connection with the remote target, and the very first thread ID
38844mentioned in the reply will be stopped by @value{GDBN} in a subsequent
38845message. Therefore, the stub should ensure that the first thread ID in
38846the @code{qfThreadInfo} reply is suitable for being stopped by @value{GDBN}.}
38847
b8ff78ce 38848@item qGetTLSAddr:@var{thread-id},@var{offset},@var{lm}
ff2587ec 38849@cindex get thread-local storage address, remote request
b8ff78ce 38850@cindex @samp{qGetTLSAddr} packet
ff2587ec
WZ
38851Fetch the address associated with thread local storage specified
38852by @var{thread-id}, @var{offset}, and @var{lm}.
38853
b90a069a
SL
38854@var{thread-id} is the thread ID associated with the
38855thread for which to fetch the TLS address. @xref{thread-id syntax}.
ff2587ec
WZ
38856
38857@var{offset} is the (big endian, hex encoded) offset associated with the
38858thread local variable. (This offset is obtained from the debug
38859information associated with the variable.)
38860
db2e3e2e 38861@var{lm} is the (big endian, hex encoded) OS/ABI-specific encoding of the
7a9dd1b2 38862load module associated with the thread local storage. For example,
ff2587ec
WZ
38863a @sc{gnu}/Linux system will pass the link map address of the shared
38864object associated with the thread local storage under consideration.
38865Other operating environments may choose to represent the load module
38866differently, so the precise meaning of this parameter will vary.
ee2d5c50
AC
38867
38868Reply:
b8ff78ce
JB
38869@table @samp
38870@item @var{XX}@dots{}
ff2587ec
WZ
38871Hex encoded (big endian) bytes representing the address of the thread
38872local storage requested.
38873
b8ff78ce 38874@item E @var{nn}
697aa1b7 38875An error occurred. The error number @var{nn} is given as hex digits.
ff2587ec 38876
d57350ea 38877@item @w{}
b8ff78ce 38878An empty reply indicates that @samp{qGetTLSAddr} is not supported by the stub.
ee2d5c50
AC
38879@end table
38880
711e434b
PM
38881@item qGetTIBAddr:@var{thread-id}
38882@cindex get thread information block address
38883@cindex @samp{qGetTIBAddr} packet
38884Fetch address of the Windows OS specific Thread Information Block.
38885
38886@var{thread-id} is the thread ID associated with the thread.
38887
38888Reply:
38889@table @samp
38890@item @var{XX}@dots{}
38891Hex encoded (big endian) bytes representing the linear address of the
38892thread information block.
38893
38894@item E @var{nn}
38895An error occured. This means that either the thread was not found, or the
38896address could not be retrieved.
38897
d57350ea 38898@item @w{}
711e434b
PM
38899An empty reply indicates that @samp{qGetTIBAddr} is not supported by the stub.
38900@end table
38901
b8ff78ce 38902@item qL @var{startflag} @var{threadcount} @var{nextthread}
8e04817f
AC
38903Obtain thread information from RTOS. Where: @var{startflag} (one hex
38904digit) is one to indicate the first query and zero to indicate a
38905subsequent query; @var{threadcount} (two hex digits) is the maximum
38906number of threads the response packet can contain; and @var{nextthread}
38907(eight hex digits), for subsequent queries (@var{startflag} is zero), is
38908returned in the response as @var{argthread}.
ee2d5c50 38909
b8ff78ce 38910Don't use this packet; use the @samp{qfThreadInfo} query instead (see above).
ee2d5c50
AC
38911
38912Reply:
38913@table @samp
b8ff78ce 38914@item qM @var{count} @var{done} @var{argthread} @var{thread}@dots{}
8e04817f
AC
38915Where: @var{count} (two hex digits) is the number of threads being
38916returned; @var{done} (one hex digit) is zero to indicate more threads
38917and one indicates no further threads; @var{argthreadid} (eight hex
b8ff78ce 38918digits) is @var{nextthread} from the request packet; @var{thread}@dots{}
697aa1b7
EZ
38919is a sequence of thread IDs, @var{threadid} (eight hex
38920digits), from the target. See @code{remote.c:parse_threadlist_response()}.
ee2d5c50 38921@end table
c906108c 38922
b8ff78ce 38923@item qOffsets
9c16f35a 38924@cindex section offsets, remote request
b8ff78ce 38925@cindex @samp{qOffsets} packet
31d99776
DJ
38926Get section offsets that the target used when relocating the downloaded
38927image.
c906108c 38928
ee2d5c50
AC
38929Reply:
38930@table @samp
31d99776
DJ
38931@item Text=@var{xxx};Data=@var{yyy}@r{[};Bss=@var{zzz}@r{]}
38932Relocate the @code{Text} section by @var{xxx} from its original address.
38933Relocate the @code{Data} section by @var{yyy} from its original address.
38934If the object file format provides segment information (e.g.@: @sc{elf}
38935@samp{PT_LOAD} program headers), @value{GDBN} will relocate entire
38936segments by the supplied offsets.
38937
38938@emph{Note: while a @code{Bss} offset may be included in the response,
38939@value{GDBN} ignores this and instead applies the @code{Data} offset
38940to the @code{Bss} section.}
38941
38942@item TextSeg=@var{xxx}@r{[};DataSeg=@var{yyy}@r{]}
38943Relocate the first segment of the object file, which conventionally
38944contains program code, to a starting address of @var{xxx}. If
38945@samp{DataSeg} is specified, relocate the second segment, which
38946conventionally contains modifiable data, to a starting address of
38947@var{yyy}. @value{GDBN} will report an error if the object file
38948does not contain segment information, or does not contain at least
38949as many segments as mentioned in the reply. Extra segments are
38950kept at fixed offsets relative to the last relocated segment.
ee2d5c50
AC
38951@end table
38952
b90a069a 38953@item qP @var{mode} @var{thread-id}
9c16f35a 38954@cindex thread information, remote request
b8ff78ce 38955@cindex @samp{qP} packet
b90a069a
SL
38956Returns information on @var{thread-id}. Where: @var{mode} is a hex
38957encoded 32 bit mode; @var{thread-id} is a thread ID
38958(@pxref{thread-id syntax}).
ee2d5c50 38959
aa56d27a
JB
38960Don't use this packet; use the @samp{qThreadExtraInfo} query instead
38961(see below).
38962
b8ff78ce 38963Reply: see @code{remote.c:remote_unpack_thread_info_response()}.
c906108c 38964
8b23ecc4 38965@item QNonStop:1
687e43a4 38966@itemx QNonStop:0
8b23ecc4
SL
38967@cindex non-stop mode, remote request
38968@cindex @samp{QNonStop} packet
38969@anchor{QNonStop}
38970Enter non-stop (@samp{QNonStop:1}) or all-stop (@samp{QNonStop:0}) mode.
38971@xref{Remote Non-Stop}, for more information.
38972
38973Reply:
38974@table @samp
38975@item OK
38976The request succeeded.
38977
38978@item E @var{nn}
697aa1b7 38979An error occurred. The error number @var{nn} is given as hex digits.
8b23ecc4 38980
d57350ea 38981@item @w{}
8b23ecc4
SL
38982An empty reply indicates that @samp{QNonStop} is not supported by
38983the stub.
38984@end table
38985
38986This packet is not probed by default; the remote stub must request it,
38987by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
38988Use of this packet is controlled by the @code{set non-stop} command;
38989@pxref{Non-Stop Mode}.
38990
82075af2
JS
38991@item QCatchSyscalls:1 @r{[};@var{sysno}@r{]}@dots{}
38992@itemx QCatchSyscalls:0
38993@cindex catch syscalls from inferior, remote request
38994@cindex @samp{QCatchSyscalls} packet
38995@anchor{QCatchSyscalls}
38996Enable (@samp{QCatchSyscalls:1}) or disable (@samp{QCatchSyscalls:0})
38997catching syscalls from the inferior process.
38998
38999For @samp{QCatchSyscalls:1}, each listed syscall @var{sysno} (encoded
39000in hex) should be reported to @value{GDBN}. If no syscall @var{sysno}
39001is listed, every system call should be reported.
39002
39003Note that if a syscall not in the list is reported, @value{GDBN} will
39004still filter the event according to its own list from all corresponding
39005@code{catch syscall} commands. However, it is more efficient to only
39006report the requested syscalls.
39007
39008Multiple @samp{QCatchSyscalls:1} packets do not combine; any earlier
39009@samp{QCatchSyscalls:1} list is completely replaced by the new list.
39010
39011If the inferior process execs, the state of @samp{QCatchSyscalls} is
39012kept for the new process too. On targets where exec may affect syscall
39013numbers, for example with exec between 32 and 64-bit processes, the
39014client should send a new packet with the new syscall list.
39015
39016Reply:
39017@table @samp
39018@item OK
39019The request succeeded.
39020
39021@item E @var{nn}
39022An error occurred. @var{nn} are hex digits.
39023
39024@item @w{}
39025An empty reply indicates that @samp{QCatchSyscalls} is not supported by
39026the stub.
39027@end table
39028
39029Use of this packet is controlled by the @code{set remote catch-syscalls}
39030command (@pxref{Remote Configuration, set remote catch-syscalls}).
39031This packet is not probed by default; the remote stub must request it,
39032by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
39033
89be2091
DJ
39034@item QPassSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
39035@cindex pass signals to inferior, remote request
39036@cindex @samp{QPassSignals} packet
23181151 39037@anchor{QPassSignals}
89be2091
DJ
39038Each listed @var{signal} should be passed directly to the inferior process.
39039Signals are numbered identically to continue packets and stop replies
39040(@pxref{Stop Reply Packets}). Each @var{signal} list item should be
39041strictly greater than the previous item. These signals do not need to stop
39042the inferior, or be reported to @value{GDBN}. All other signals should be
39043reported to @value{GDBN}. Multiple @samp{QPassSignals} packets do not
39044combine; any earlier @samp{QPassSignals} list is completely replaced by the
39045new list. This packet improves performance when using @samp{handle
39046@var{signal} nostop noprint pass}.
39047
39048Reply:
39049@table @samp
39050@item OK
39051The request succeeded.
39052
39053@item E @var{nn}
697aa1b7 39054An error occurred. The error number @var{nn} is given as hex digits.
89be2091 39055
d57350ea 39056@item @w{}
89be2091
DJ
39057An empty reply indicates that @samp{QPassSignals} is not supported by
39058the stub.
39059@end table
39060
39061Use of this packet is controlled by the @code{set remote pass-signals}
79a6e687 39062command (@pxref{Remote Configuration, set remote pass-signals}).
89be2091
DJ
39063This packet is not probed by default; the remote stub must request it,
39064by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
39065
9b224c5e
PA
39066@item QProgramSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
39067@cindex signals the inferior may see, remote request
39068@cindex @samp{QProgramSignals} packet
39069@anchor{QProgramSignals}
39070Each listed @var{signal} may be delivered to the inferior process.
39071Others should be silently discarded.
39072
39073In some cases, the remote stub may need to decide whether to deliver a
39074signal to the program or not without @value{GDBN} involvement. One
39075example of that is while detaching --- the program's threads may have
39076stopped for signals that haven't yet had a chance of being reported to
39077@value{GDBN}, and so the remote stub can use the signal list specified
39078by this packet to know whether to deliver or ignore those pending
39079signals.
39080
39081This does not influence whether to deliver a signal as requested by a
39082resumption packet (@pxref{vCont packet}).
39083
39084Signals are numbered identically to continue packets and stop replies
39085(@pxref{Stop Reply Packets}). Each @var{signal} list item should be
39086strictly greater than the previous item. Multiple
39087@samp{QProgramSignals} packets do not combine; any earlier
39088@samp{QProgramSignals} list is completely replaced by the new list.
39089
39090Reply:
39091@table @samp
39092@item OK
39093The request succeeded.
39094
39095@item E @var{nn}
697aa1b7 39096An error occurred. The error number @var{nn} is given as hex digits.
9b224c5e 39097
d57350ea 39098@item @w{}
9b224c5e
PA
39099An empty reply indicates that @samp{QProgramSignals} is not supported
39100by the stub.
39101@end table
39102
39103Use of this packet is controlled by the @code{set remote program-signals}
39104command (@pxref{Remote Configuration, set remote program-signals}).
39105This packet is not probed by default; the remote stub must request it,
39106by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
39107
65706a29
PA
39108@anchor{QThreadEvents}
39109@item QThreadEvents:1
39110@itemx QThreadEvents:0
39111@cindex thread create/exit events, remote request
39112@cindex @samp{QThreadEvents} packet
39113
39114Enable (@samp{QThreadEvents:1}) or disable (@samp{QThreadEvents:0})
39115reporting of thread create and exit events. @xref{thread create
39116event}, for the reply specifications. For example, this is used in
39117non-stop mode when @value{GDBN} stops a set of threads and
39118synchronously waits for the their corresponding stop replies. Without
39119exit events, if one of the threads exits, @value{GDBN} would hang
39120forever not knowing that it should no longer expect a stop for that
39121same thread. @value{GDBN} does not enable this feature unless the
39122stub reports that it supports it by including @samp{QThreadEvents+} in
39123its @samp{qSupported} reply.
39124
39125Reply:
39126@table @samp
39127@item OK
39128The request succeeded.
39129
39130@item E @var{nn}
39131An error occurred. The error number @var{nn} is given as hex digits.
39132
39133@item @w{}
39134An empty reply indicates that @samp{QThreadEvents} is not supported by
39135the stub.
39136@end table
39137
39138Use of this packet is controlled by the @code{set remote thread-events}
39139command (@pxref{Remote Configuration, set remote thread-events}).
39140
b8ff78ce 39141@item qRcmd,@var{command}
ff2587ec 39142@cindex execute remote command, remote request
b8ff78ce 39143@cindex @samp{qRcmd} packet
ff2587ec 39144@var{command} (hex encoded) is passed to the local interpreter for
b8ff78ce
JB
39145execution. Invalid commands should be reported using the output
39146string. Before the final result packet, the target may also respond
39147with a number of intermediate @samp{O@var{output}} console output
39148packets. @emph{Implementors should note that providing access to a
39149stubs's interpreter may have security implications}.
fa93a9d8 39150
ff2587ec
WZ
39151Reply:
39152@table @samp
39153@item OK
39154A command response with no output.
39155@item @var{OUTPUT}
39156A command response with the hex encoded output string @var{OUTPUT}.
b8ff78ce 39157@item E @var{NN}
ff2587ec 39158Indicate a badly formed request.
d57350ea 39159@item @w{}
b8ff78ce 39160An empty reply indicates that @samp{qRcmd} is not recognized.
ff2587ec 39161@end table
fa93a9d8 39162
aa56d27a
JB
39163(Note that the @code{qRcmd} packet's name is separated from the
39164command by a @samp{,}, not a @samp{:}, contrary to the naming
39165conventions above. Please don't use this packet as a model for new
39166packets.)
39167
08388c79
DE
39168@item qSearch:memory:@var{address};@var{length};@var{search-pattern}
39169@cindex searching memory, in remote debugging
5c4808ca 39170@ifnotinfo
08388c79 39171@cindex @samp{qSearch:memory} packet
5c4808ca
EZ
39172@end ifnotinfo
39173@cindex @samp{qSearch memory} packet
08388c79
DE
39174@anchor{qSearch memory}
39175Search @var{length} bytes at @var{address} for @var{search-pattern}.
697aa1b7
EZ
39176Both @var{address} and @var{length} are encoded in hex;
39177@var{search-pattern} is a sequence of bytes, also hex encoded.
08388c79
DE
39178
39179Reply:
39180@table @samp
39181@item 0
39182The pattern was not found.
39183@item 1,address
39184The pattern was found at @var{address}.
39185@item E @var{NN}
39186A badly formed request or an error was encountered while searching memory.
d57350ea 39187@item @w{}
08388c79
DE
39188An empty reply indicates that @samp{qSearch:memory} is not recognized.
39189@end table
39190
a6f3e723
SL
39191@item QStartNoAckMode
39192@cindex @samp{QStartNoAckMode} packet
39193@anchor{QStartNoAckMode}
39194Request that the remote stub disable the normal @samp{+}/@samp{-}
39195protocol acknowledgments (@pxref{Packet Acknowledgment}).
39196
39197Reply:
39198@table @samp
39199@item OK
39200The stub has switched to no-acknowledgment mode.
39201@value{GDBN} acknowledges this reponse,
39202but neither the stub nor @value{GDBN} shall send or expect further
39203@samp{+}/@samp{-} acknowledgments in the current connection.
d57350ea 39204@item @w{}
a6f3e723
SL
39205An empty reply indicates that the stub does not support no-acknowledgment mode.
39206@end table
39207
be2a5f71
DJ
39208@item qSupported @r{[}:@var{gdbfeature} @r{[};@var{gdbfeature}@r{]}@dots{} @r{]}
39209@cindex supported packets, remote query
39210@cindex features of the remote protocol
39211@cindex @samp{qSupported} packet
0876f84a 39212@anchor{qSupported}
be2a5f71
DJ
39213Tell the remote stub about features supported by @value{GDBN}, and
39214query the stub for features it supports. This packet allows
39215@value{GDBN} and the remote stub to take advantage of each others'
39216features. @samp{qSupported} also consolidates multiple feature probes
39217at startup, to improve @value{GDBN} performance---a single larger
39218packet performs better than multiple smaller probe packets on
39219high-latency links. Some features may enable behavior which must not
39220be on by default, e.g.@: because it would confuse older clients or
39221stubs. Other features may describe packets which could be
39222automatically probed for, but are not. These features must be
39223reported before @value{GDBN} will use them. This ``default
39224unsupported'' behavior is not appropriate for all packets, but it
39225helps to keep the initial connection time under control with new
39226versions of @value{GDBN} which support increasing numbers of packets.
39227
39228Reply:
39229@table @samp
39230@item @var{stubfeature} @r{[};@var{stubfeature}@r{]}@dots{}
39231The stub supports or does not support each returned @var{stubfeature},
39232depending on the form of each @var{stubfeature} (see below for the
39233possible forms).
d57350ea 39234@item @w{}
be2a5f71
DJ
39235An empty reply indicates that @samp{qSupported} is not recognized,
39236or that no features needed to be reported to @value{GDBN}.
39237@end table
39238
39239The allowed forms for each feature (either a @var{gdbfeature} in the
39240@samp{qSupported} packet, or a @var{stubfeature} in the response)
39241are:
39242
39243@table @samp
39244@item @var{name}=@var{value}
39245The remote protocol feature @var{name} is supported, and associated
39246with the specified @var{value}. The format of @var{value} depends
39247on the feature, but it must not include a semicolon.
39248@item @var{name}+
39249The remote protocol feature @var{name} is supported, and does not
39250need an associated value.
39251@item @var{name}-
39252The remote protocol feature @var{name} is not supported.
39253@item @var{name}?
39254The remote protocol feature @var{name} may be supported, and
39255@value{GDBN} should auto-detect support in some other way when it is
39256needed. This form will not be used for @var{gdbfeature} notifications,
39257but may be used for @var{stubfeature} responses.
39258@end table
39259
39260Whenever the stub receives a @samp{qSupported} request, the
39261supplied set of @value{GDBN} features should override any previous
39262request. This allows @value{GDBN} to put the stub in a known
39263state, even if the stub had previously been communicating with
39264a different version of @value{GDBN}.
39265
b90a069a
SL
39266The following values of @var{gdbfeature} (for the packet sent by @value{GDBN})
39267are defined:
39268
39269@table @samp
39270@item multiprocess
39271This feature indicates whether @value{GDBN} supports multiprocess
39272extensions to the remote protocol. @value{GDBN} does not use such
39273extensions unless the stub also reports that it supports them by
39274including @samp{multiprocess+} in its @samp{qSupported} reply.
39275@xref{multiprocess extensions}, for details.
c8d5aac9
L
39276
39277@item xmlRegisters
39278This feature indicates that @value{GDBN} supports the XML target
39279description. If the stub sees @samp{xmlRegisters=} with target
39280specific strings separated by a comma, it will report register
39281description.
dde08ee1
PA
39282
39283@item qRelocInsn
39284This feature indicates whether @value{GDBN} supports the
39285@samp{qRelocInsn} packet (@pxref{Tracepoint Packets,,Relocate
39286instruction reply packet}).
f7e6eed5
PA
39287
39288@item swbreak
39289This feature indicates whether @value{GDBN} supports the swbreak stop
39290reason in stop replies. @xref{swbreak stop reason}, for details.
39291
39292@item hwbreak
39293This feature indicates whether @value{GDBN} supports the hwbreak stop
39294reason in stop replies. @xref{swbreak stop reason}, for details.
0d71eef5
DB
39295
39296@item fork-events
39297This feature indicates whether @value{GDBN} supports fork event
39298extensions to the remote protocol. @value{GDBN} does not use such
39299extensions unless the stub also reports that it supports them by
39300including @samp{fork-events+} in its @samp{qSupported} reply.
39301
39302@item vfork-events
39303This feature indicates whether @value{GDBN} supports vfork event
39304extensions to the remote protocol. @value{GDBN} does not use such
39305extensions unless the stub also reports that it supports them by
39306including @samp{vfork-events+} in its @samp{qSupported} reply.
b459a59b
DB
39307
39308@item exec-events
39309This feature indicates whether @value{GDBN} supports exec event
39310extensions to the remote protocol. @value{GDBN} does not use such
39311extensions unless the stub also reports that it supports them by
39312including @samp{exec-events+} in its @samp{qSupported} reply.
750ce8d1
YQ
39313
39314@item vContSupported
39315This feature indicates whether @value{GDBN} wants to know the
39316supported actions in the reply to @samp{vCont?} packet.
b90a069a
SL
39317@end table
39318
39319Stubs should ignore any unknown values for
be2a5f71
DJ
39320@var{gdbfeature}. Any @value{GDBN} which sends a @samp{qSupported}
39321packet supports receiving packets of unlimited length (earlier
b90a069a 39322versions of @value{GDBN} may reject overly long responses). Additional values
be2a5f71
DJ
39323for @var{gdbfeature} may be defined in the future to let the stub take
39324advantage of new features in @value{GDBN}, e.g.@: incompatible
b90a069a
SL
39325improvements in the remote protocol---the @samp{multiprocess} feature is
39326an example of such a feature. The stub's reply should be independent
be2a5f71
DJ
39327of the @var{gdbfeature} entries sent by @value{GDBN}; first @value{GDBN}
39328describes all the features it supports, and then the stub replies with
39329all the features it supports.
39330
39331Similarly, @value{GDBN} will silently ignore unrecognized stub feature
39332responses, as long as each response uses one of the standard forms.
39333
39334Some features are flags. A stub which supports a flag feature
39335should respond with a @samp{+} form response. Other features
39336require values, and the stub should respond with an @samp{=}
39337form response.
39338
39339Each feature has a default value, which @value{GDBN} will use if
39340@samp{qSupported} is not available or if the feature is not mentioned
39341in the @samp{qSupported} response. The default values are fixed; a
39342stub is free to omit any feature responses that match the defaults.
39343
39344Not all features can be probed, but for those which can, the probing
39345mechanism is useful: in some cases, a stub's internal
39346architecture may not allow the protocol layer to know some information
39347about the underlying target in advance. This is especially common in
39348stubs which may be configured for multiple targets.
39349
39350These are the currently defined stub features and their properties:
39351
cfa9d6d9 39352@multitable @columnfractions 0.35 0.2 0.12 0.2
be2a5f71
DJ
39353@c NOTE: The first row should be @headitem, but we do not yet require
39354@c a new enough version of Texinfo (4.7) to use @headitem.
0876f84a 39355@item Feature Name
be2a5f71
DJ
39356@tab Value Required
39357@tab Default
39358@tab Probe Allowed
39359
39360@item @samp{PacketSize}
39361@tab Yes
39362@tab @samp{-}
39363@tab No
39364
0876f84a
DJ
39365@item @samp{qXfer:auxv:read}
39366@tab No
39367@tab @samp{-}
39368@tab Yes
39369
2ae8c8e7
MM
39370@item @samp{qXfer:btrace:read}
39371@tab No
39372@tab @samp{-}
39373@tab Yes
39374
f4abbc16
MM
39375@item @samp{qXfer:btrace-conf:read}
39376@tab No
39377@tab @samp{-}
39378@tab Yes
39379
c78fa86a
GB
39380@item @samp{qXfer:exec-file:read}
39381@tab No
39382@tab @samp{-}
39383@tab Yes
39384
23181151
DJ
39385@item @samp{qXfer:features:read}
39386@tab No
39387@tab @samp{-}
39388@tab Yes
39389
cfa9d6d9
DJ
39390@item @samp{qXfer:libraries:read}
39391@tab No
39392@tab @samp{-}
39393@tab Yes
39394
85dc5a12
GB
39395@item @samp{qXfer:libraries-svr4:read}
39396@tab No
39397@tab @samp{-}
39398@tab Yes
39399
39400@item @samp{augmented-libraries-svr4-read}
39401@tab No
39402@tab @samp{-}
39403@tab No
39404
68437a39
DJ
39405@item @samp{qXfer:memory-map:read}
39406@tab No
39407@tab @samp{-}
39408@tab Yes
39409
0fb4aa4b
PA
39410@item @samp{qXfer:sdata:read}
39411@tab No
39412@tab @samp{-}
39413@tab Yes
39414
0e7f50da
UW
39415@item @samp{qXfer:spu:read}
39416@tab No
39417@tab @samp{-}
39418@tab Yes
39419
39420@item @samp{qXfer:spu:write}
39421@tab No
39422@tab @samp{-}
39423@tab Yes
39424
4aa995e1
PA
39425@item @samp{qXfer:siginfo:read}
39426@tab No
39427@tab @samp{-}
39428@tab Yes
39429
39430@item @samp{qXfer:siginfo:write}
39431@tab No
39432@tab @samp{-}
39433@tab Yes
39434
dc146f7c
VP
39435@item @samp{qXfer:threads:read}
39436@tab No
39437@tab @samp{-}
39438@tab Yes
39439
b3b9301e
PA
39440@item @samp{qXfer:traceframe-info:read}
39441@tab No
39442@tab @samp{-}
39443@tab Yes
39444
169081d0
TG
39445@item @samp{qXfer:uib:read}
39446@tab No
39447@tab @samp{-}
39448@tab Yes
39449
78d85199
YQ
39450@item @samp{qXfer:fdpic:read}
39451@tab No
39452@tab @samp{-}
39453@tab Yes
dc146f7c 39454
2ae8c8e7
MM
39455@item @samp{Qbtrace:off}
39456@tab Yes
39457@tab @samp{-}
39458@tab Yes
39459
39460@item @samp{Qbtrace:bts}
39461@tab Yes
39462@tab @samp{-}
39463@tab Yes
39464
b20a6524
MM
39465@item @samp{Qbtrace:pt}
39466@tab Yes
39467@tab @samp{-}
39468@tab Yes
39469
d33501a5
MM
39470@item @samp{Qbtrace-conf:bts:size}
39471@tab Yes
39472@tab @samp{-}
39473@tab Yes
39474
b20a6524
MM
39475@item @samp{Qbtrace-conf:pt:size}
39476@tab Yes
39477@tab @samp{-}
39478@tab Yes
39479
8b23ecc4
SL
39480@item @samp{QNonStop}
39481@tab No
39482@tab @samp{-}
39483@tab Yes
39484
82075af2
JS
39485@item @samp{QCatchSyscalls}
39486@tab No
39487@tab @samp{-}
39488@tab Yes
39489
89be2091
DJ
39490@item @samp{QPassSignals}
39491@tab No
39492@tab @samp{-}
39493@tab Yes
39494
a6f3e723
SL
39495@item @samp{QStartNoAckMode}
39496@tab No
39497@tab @samp{-}
39498@tab Yes
39499
b90a069a
SL
39500@item @samp{multiprocess}
39501@tab No
39502@tab @samp{-}
39503@tab No
39504
83364271
LM
39505@item @samp{ConditionalBreakpoints}
39506@tab No
39507@tab @samp{-}
39508@tab No
39509
782b2b07
SS
39510@item @samp{ConditionalTracepoints}
39511@tab No
39512@tab @samp{-}
39513@tab No
39514
0d772ac9
MS
39515@item @samp{ReverseContinue}
39516@tab No
2f8132f3 39517@tab @samp{-}
0d772ac9
MS
39518@tab No
39519
39520@item @samp{ReverseStep}
39521@tab No
2f8132f3 39522@tab @samp{-}
0d772ac9
MS
39523@tab No
39524
409873ef
SS
39525@item @samp{TracepointSource}
39526@tab No
39527@tab @samp{-}
39528@tab No
39529
d1feda86
YQ
39530@item @samp{QAgent}
39531@tab No
39532@tab @samp{-}
39533@tab No
39534
d914c394
SS
39535@item @samp{QAllow}
39536@tab No
39537@tab @samp{-}
39538@tab No
39539
03583c20
UW
39540@item @samp{QDisableRandomization}
39541@tab No
39542@tab @samp{-}
39543@tab No
39544
d248b706
KY
39545@item @samp{EnableDisableTracepoints}
39546@tab No
39547@tab @samp{-}
39548@tab No
39549
f6f899bf
HAQ
39550@item @samp{QTBuffer:size}
39551@tab No
39552@tab @samp{-}
39553@tab No
39554
3065dfb6
SS
39555@item @samp{tracenz}
39556@tab No
39557@tab @samp{-}
39558@tab No
39559
d3ce09f5
SS
39560@item @samp{BreakpointCommands}
39561@tab No
39562@tab @samp{-}
39563@tab No
39564
f7e6eed5
PA
39565@item @samp{swbreak}
39566@tab No
39567@tab @samp{-}
39568@tab No
39569
39570@item @samp{hwbreak}
39571@tab No
39572@tab @samp{-}
39573@tab No
39574
0d71eef5
DB
39575@item @samp{fork-events}
39576@tab No
39577@tab @samp{-}
39578@tab No
39579
39580@item @samp{vfork-events}
39581@tab No
39582@tab @samp{-}
39583@tab No
39584
b459a59b
DB
39585@item @samp{exec-events}
39586@tab No
39587@tab @samp{-}
39588@tab No
39589
65706a29
PA
39590@item @samp{QThreadEvents}
39591@tab No
39592@tab @samp{-}
39593@tab No
39594
f2faf941
PA
39595@item @samp{no-resumed}
39596@tab No
39597@tab @samp{-}
39598@tab No
39599
be2a5f71
DJ
39600@end multitable
39601
39602These are the currently defined stub features, in more detail:
39603
39604@table @samp
39605@cindex packet size, remote protocol
39606@item PacketSize=@var{bytes}
39607The remote stub can accept packets up to at least @var{bytes} in
39608length. @value{GDBN} will send packets up to this size for bulk
39609transfers, and will never send larger packets. This is a limit on the
39610data characters in the packet, including the frame and checksum.
39611There is no trailing NUL byte in a remote protocol packet; if the stub
39612stores packets in a NUL-terminated format, it should allow an extra
39613byte in its buffer for the NUL. If this stub feature is not supported,
39614@value{GDBN} guesses based on the size of the @samp{g} packet response.
39615
0876f84a
DJ
39616@item qXfer:auxv:read
39617The remote stub understands the @samp{qXfer:auxv:read} packet
39618(@pxref{qXfer auxiliary vector read}).
39619
2ae8c8e7
MM
39620@item qXfer:btrace:read
39621The remote stub understands the @samp{qXfer:btrace:read}
39622packet (@pxref{qXfer btrace read}).
39623
f4abbc16
MM
39624@item qXfer:btrace-conf:read
39625The remote stub understands the @samp{qXfer:btrace-conf:read}
39626packet (@pxref{qXfer btrace-conf read}).
39627
c78fa86a
GB
39628@item qXfer:exec-file:read
39629The remote stub understands the @samp{qXfer:exec-file:read} packet
39630(@pxref{qXfer executable filename read}).
39631
23181151
DJ
39632@item qXfer:features:read
39633The remote stub understands the @samp{qXfer:features:read} packet
39634(@pxref{qXfer target description read}).
39635
cfa9d6d9
DJ
39636@item qXfer:libraries:read
39637The remote stub understands the @samp{qXfer:libraries:read} packet
39638(@pxref{qXfer library list read}).
39639
2268b414
JK
39640@item qXfer:libraries-svr4:read
39641The remote stub understands the @samp{qXfer:libraries-svr4:read} packet
39642(@pxref{qXfer svr4 library list read}).
39643
85dc5a12
GB
39644@item augmented-libraries-svr4-read
39645The remote stub understands the augmented form of the
39646@samp{qXfer:libraries-svr4:read} packet
39647(@pxref{qXfer svr4 library list read}).
39648
23181151
DJ
39649@item qXfer:memory-map:read
39650The remote stub understands the @samp{qXfer:memory-map:read} packet
39651(@pxref{qXfer memory map read}).
39652
0fb4aa4b
PA
39653@item qXfer:sdata:read
39654The remote stub understands the @samp{qXfer:sdata:read} packet
39655(@pxref{qXfer sdata read}).
39656
0e7f50da
UW
39657@item qXfer:spu:read
39658The remote stub understands the @samp{qXfer:spu:read} packet
39659(@pxref{qXfer spu read}).
39660
39661@item qXfer:spu:write
39662The remote stub understands the @samp{qXfer:spu:write} packet
39663(@pxref{qXfer spu write}).
39664
4aa995e1
PA
39665@item qXfer:siginfo:read
39666The remote stub understands the @samp{qXfer:siginfo:read} packet
39667(@pxref{qXfer siginfo read}).
39668
39669@item qXfer:siginfo:write
39670The remote stub understands the @samp{qXfer:siginfo:write} packet
39671(@pxref{qXfer siginfo write}).
39672
dc146f7c
VP
39673@item qXfer:threads:read
39674The remote stub understands the @samp{qXfer:threads:read} packet
39675(@pxref{qXfer threads read}).
39676
b3b9301e
PA
39677@item qXfer:traceframe-info:read
39678The remote stub understands the @samp{qXfer:traceframe-info:read}
39679packet (@pxref{qXfer traceframe info read}).
39680
169081d0
TG
39681@item qXfer:uib:read
39682The remote stub understands the @samp{qXfer:uib:read}
39683packet (@pxref{qXfer unwind info block}).
39684
78d85199
YQ
39685@item qXfer:fdpic:read
39686The remote stub understands the @samp{qXfer:fdpic:read}
39687packet (@pxref{qXfer fdpic loadmap read}).
39688
8b23ecc4
SL
39689@item QNonStop
39690The remote stub understands the @samp{QNonStop} packet
39691(@pxref{QNonStop}).
39692
82075af2
JS
39693@item QCatchSyscalls
39694The remote stub understands the @samp{QCatchSyscalls} packet
39695(@pxref{QCatchSyscalls}).
39696
23181151
DJ
39697@item QPassSignals
39698The remote stub understands the @samp{QPassSignals} packet
39699(@pxref{QPassSignals}).
39700
a6f3e723
SL
39701@item QStartNoAckMode
39702The remote stub understands the @samp{QStartNoAckMode} packet and
39703prefers to operate in no-acknowledgment mode. @xref{Packet Acknowledgment}.
39704
b90a069a
SL
39705@item multiprocess
39706@anchor{multiprocess extensions}
39707@cindex multiprocess extensions, in remote protocol
39708The remote stub understands the multiprocess extensions to the remote
39709protocol syntax. The multiprocess extensions affect the syntax of
39710thread IDs in both packets and replies (@pxref{thread-id syntax}), and
39711add process IDs to the @samp{D} packet and @samp{W} and @samp{X}
39712replies. Note that reporting this feature indicates support for the
39713syntactic extensions only, not that the stub necessarily supports
39714debugging of more than one process at a time. The stub must not use
39715multiprocess extensions in packet replies unless @value{GDBN} has also
39716indicated it supports them in its @samp{qSupported} request.
39717
07e059b5
VP
39718@item qXfer:osdata:read
39719The remote stub understands the @samp{qXfer:osdata:read} packet
39720((@pxref{qXfer osdata read}).
39721
83364271
LM
39722@item ConditionalBreakpoints
39723The target accepts and implements evaluation of conditional expressions
39724defined for breakpoints. The target will only report breakpoint triggers
39725when such conditions are true (@pxref{Conditions, ,Break Conditions}).
39726
782b2b07
SS
39727@item ConditionalTracepoints
39728The remote stub accepts and implements conditional expressions defined
39729for tracepoints (@pxref{Tracepoint Conditions}).
39730
0d772ac9
MS
39731@item ReverseContinue
39732The remote stub accepts and implements the reverse continue packet
39733(@pxref{bc}).
39734
39735@item ReverseStep
39736The remote stub accepts and implements the reverse step packet
39737(@pxref{bs}).
39738
409873ef
SS
39739@item TracepointSource
39740The remote stub understands the @samp{QTDPsrc} packet that supplies
39741the source form of tracepoint definitions.
39742
d1feda86
YQ
39743@item QAgent
39744The remote stub understands the @samp{QAgent} packet.
39745
d914c394
SS
39746@item QAllow
39747The remote stub understands the @samp{QAllow} packet.
39748
03583c20
UW
39749@item QDisableRandomization
39750The remote stub understands the @samp{QDisableRandomization} packet.
39751
0fb4aa4b
PA
39752@item StaticTracepoint
39753@cindex static tracepoints, in remote protocol
39754The remote stub supports static tracepoints.
39755
1e4d1764
YQ
39756@item InstallInTrace
39757@anchor{install tracepoint in tracing}
39758The remote stub supports installing tracepoint in tracing.
39759
d248b706
KY
39760@item EnableDisableTracepoints
39761The remote stub supports the @samp{QTEnable} (@pxref{QTEnable}) and
39762@samp{QTDisable} (@pxref{QTDisable}) packets that allow tracepoints
39763to be enabled and disabled while a trace experiment is running.
39764
f6f899bf 39765@item QTBuffer:size
28abe188 39766The remote stub supports the @samp{QTBuffer:size} (@pxref{QTBuffer-size})
f6f899bf
HAQ
39767packet that allows to change the size of the trace buffer.
39768
3065dfb6
SS
39769@item tracenz
39770@cindex string tracing, in remote protocol
39771The remote stub supports the @samp{tracenz} bytecode for collecting strings.
39772See @ref{Bytecode Descriptions} for details about the bytecode.
39773
d3ce09f5
SS
39774@item BreakpointCommands
39775@cindex breakpoint commands, in remote protocol
39776The remote stub supports running a breakpoint's command list itself,
39777rather than reporting the hit to @value{GDBN}.
39778
2ae8c8e7
MM
39779@item Qbtrace:off
39780The remote stub understands the @samp{Qbtrace:off} packet.
39781
39782@item Qbtrace:bts
39783The remote stub understands the @samp{Qbtrace:bts} packet.
39784
b20a6524
MM
39785@item Qbtrace:pt
39786The remote stub understands the @samp{Qbtrace:pt} packet.
39787
d33501a5
MM
39788@item Qbtrace-conf:bts:size
39789The remote stub understands the @samp{Qbtrace-conf:bts:size} packet.
39790
b20a6524
MM
39791@item Qbtrace-conf:pt:size
39792The remote stub understands the @samp{Qbtrace-conf:pt:size} packet.
39793
f7e6eed5
PA
39794@item swbreak
39795The remote stub reports the @samp{swbreak} stop reason for memory
39796breakpoints.
39797
39798@item hwbreak
39799The remote stub reports the @samp{hwbreak} stop reason for hardware
39800breakpoints.
39801
0d71eef5
DB
39802@item fork-events
39803The remote stub reports the @samp{fork} stop reason for fork events.
39804
39805@item vfork-events
39806The remote stub reports the @samp{vfork} stop reason for vfork events
39807and vforkdone events.
39808
b459a59b
DB
39809@item exec-events
39810The remote stub reports the @samp{exec} stop reason for exec events.
39811
750ce8d1
YQ
39812@item vContSupported
39813The remote stub reports the supported actions in the reply to
39814@samp{vCont?} packet.
39815
65706a29
PA
39816@item QThreadEvents
39817The remote stub understands the @samp{QThreadEvents} packet.
39818
f2faf941
PA
39819@item no-resumed
39820The remote stub reports the @samp{N} stop reply.
39821
be2a5f71
DJ
39822@end table
39823
b8ff78ce 39824@item qSymbol::
ff2587ec 39825@cindex symbol lookup, remote request
b8ff78ce 39826@cindex @samp{qSymbol} packet
ff2587ec
WZ
39827Notify the target that @value{GDBN} is prepared to serve symbol lookup
39828requests. Accept requests from the target for the values of symbols.
fa93a9d8
JB
39829
39830Reply:
ff2587ec 39831@table @samp
b8ff78ce 39832@item OK
ff2587ec 39833The target does not need to look up any (more) symbols.
b8ff78ce 39834@item qSymbol:@var{sym_name}
ff2587ec
WZ
39835The target requests the value of symbol @var{sym_name} (hex encoded).
39836@value{GDBN} may provide the value by using the
b8ff78ce
JB
39837@samp{qSymbol:@var{sym_value}:@var{sym_name}} message, described
39838below.
ff2587ec 39839@end table
83761cbd 39840
b8ff78ce 39841@item qSymbol:@var{sym_value}:@var{sym_name}
ff2587ec
WZ
39842Set the value of @var{sym_name} to @var{sym_value}.
39843
39844@var{sym_name} (hex encoded) is the name of a symbol whose value the
39845target has previously requested.
39846
39847@var{sym_value} (hex) is the value for symbol @var{sym_name}. If
39848@value{GDBN} cannot supply a value for @var{sym_name}, then this field
39849will be empty.
39850
39851Reply:
39852@table @samp
b8ff78ce 39853@item OK
ff2587ec 39854The target does not need to look up any (more) symbols.
b8ff78ce 39855@item qSymbol:@var{sym_name}
ff2587ec
WZ
39856The target requests the value of a new symbol @var{sym_name} (hex
39857encoded). @value{GDBN} will continue to supply the values of symbols
39858(if available), until the target ceases to request them.
fa93a9d8 39859@end table
0abb7bc7 39860
00bf0b85 39861@item qTBuffer
687e43a4
TT
39862@itemx QTBuffer
39863@itemx QTDisconnected
d5551862 39864@itemx QTDP
409873ef 39865@itemx QTDPsrc
d5551862 39866@itemx QTDV
00bf0b85
SS
39867@itemx qTfP
39868@itemx qTfV
9d29849a 39869@itemx QTFrame
405f8e94
SS
39870@itemx qTMinFTPILen
39871
9d29849a
JB
39872@xref{Tracepoint Packets}.
39873
b90a069a 39874@item qThreadExtraInfo,@var{thread-id}
ff2587ec 39875@cindex thread attributes info, remote request
b8ff78ce 39876@cindex @samp{qThreadExtraInfo} packet
697aa1b7
EZ
39877Obtain from the target OS a printable string description of thread
39878attributes for the thread @var{thread-id}; see @ref{thread-id syntax},
39879for the forms of @var{thread-id}. This
b8ff78ce
JB
39880string may contain anything that the target OS thinks is interesting
39881for @value{GDBN} to tell the user about the thread. The string is
39882displayed in @value{GDBN}'s @code{info threads} display. Some
39883examples of possible thread extra info strings are @samp{Runnable}, or
39884@samp{Blocked on Mutex}.
ff2587ec
WZ
39885
39886Reply:
39887@table @samp
b8ff78ce
JB
39888@item @var{XX}@dots{}
39889Where @samp{@var{XX}@dots{}} is a hex encoding of @sc{ascii} data,
39890comprising the printable string containing the extra information about
39891the thread's attributes.
ff2587ec 39892@end table
814e32d7 39893
aa56d27a
JB
39894(Note that the @code{qThreadExtraInfo} packet's name is separated from
39895the command by a @samp{,}, not a @samp{:}, contrary to the naming
39896conventions above. Please don't use this packet as a model for new
39897packets.)
39898
f196051f 39899@item QTNotes
687e43a4
TT
39900@itemx qTP
39901@itemx QTSave
39902@itemx qTsP
39903@itemx qTsV
d5551862 39904@itemx QTStart
9d29849a 39905@itemx QTStop
d248b706
KY
39906@itemx QTEnable
39907@itemx QTDisable
9d29849a
JB
39908@itemx QTinit
39909@itemx QTro
39910@itemx qTStatus
d5551862 39911@itemx qTV
0fb4aa4b
PA
39912@itemx qTfSTM
39913@itemx qTsSTM
39914@itemx qTSTMat
9d29849a
JB
39915@xref{Tracepoint Packets}.
39916
0876f84a
DJ
39917@item qXfer:@var{object}:read:@var{annex}:@var{offset},@var{length}
39918@cindex read special object, remote request
39919@cindex @samp{qXfer} packet
68437a39 39920@anchor{qXfer read}
0876f84a
DJ
39921Read uninterpreted bytes from the target's special data area
39922identified by the keyword @var{object}. Request @var{length} bytes
39923starting at @var{offset} bytes into the data. The content and
0e7f50da 39924encoding of @var{annex} is specific to @var{object}; it can supply
0876f84a
DJ
39925additional details about what data to access.
39926
c185ba27
EZ
39927Reply:
39928@table @samp
39929@item m @var{data}
39930Data @var{data} (@pxref{Binary Data}) has been read from the
39931target. There may be more data at a higher address (although
39932it is permitted to return @samp{m} even for the last valid
39933block of data, as long as at least one byte of data was read).
39934It is possible for @var{data} to have fewer bytes than the @var{length} in the
39935request.
39936
39937@item l @var{data}
39938Data @var{data} (@pxref{Binary Data}) has been read from the target.
39939There is no more data to be read. It is possible for @var{data} to
39940have fewer bytes than the @var{length} in the request.
39941
39942@item l
39943The @var{offset} in the request is at the end of the data.
39944There is no more data to be read.
39945
39946@item E00
39947The request was malformed, or @var{annex} was invalid.
39948
39949@item E @var{nn}
39950The offset was invalid, or there was an error encountered reading the data.
39951The @var{nn} part is a hex-encoded @code{errno} value.
39952
39953@item @w{}
39954An empty reply indicates the @var{object} string was not recognized by
39955the stub, or that the object does not support reading.
39956@end table
39957
39958Here are the specific requests of this form defined so far. All the
0876f84a 39959@samp{qXfer:@var{object}:read:@dots{}} requests use the same reply
c185ba27 39960formats, listed above.
0876f84a
DJ
39961
39962@table @samp
39963@item qXfer:auxv:read::@var{offset},@var{length}
39964@anchor{qXfer auxiliary vector read}
39965Access the target's @dfn{auxiliary vector}. @xref{OS Information,
427c3a89 39966auxiliary vector}. Note @var{annex} must be empty.
0876f84a
DJ
39967
39968This packet is not probed by default; the remote stub must request it,
89be2091 39969by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
0876f84a 39970
2ae8c8e7
MM
39971@item qXfer:btrace:read:@var{annex}:@var{offset},@var{length}
39972@anchor{qXfer btrace read}
39973
39974Return a description of the current branch trace.
39975@xref{Branch Trace Format}. The annex part of the generic @samp{qXfer}
39976packet may have one of the following values:
39977
39978@table @code
39979@item all
39980Returns all available branch trace.
39981
39982@item new
39983Returns all available branch trace if the branch trace changed since
39984the last read request.
969c39fb
MM
39985
39986@item delta
39987Returns the new branch trace since the last read request. Adds a new
39988block to the end of the trace that begins at zero and ends at the source
39989location of the first branch in the trace buffer. This extra block is
39990used to stitch traces together.
39991
39992If the trace buffer overflowed, returns an error indicating the overflow.
2ae8c8e7
MM
39993@end table
39994
39995This packet is not probed by default; the remote stub must request it
39996by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
39997
f4abbc16
MM
39998@item qXfer:btrace-conf:read::@var{offset},@var{length}
39999@anchor{qXfer btrace-conf read}
40000
40001Return a description of the current branch trace configuration.
40002@xref{Branch Trace Configuration Format}.
40003
40004This packet is not probed by default; the remote stub must request it
40005by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
c78fa86a
GB
40006
40007@item qXfer:exec-file:read:@var{annex}:@var{offset},@var{length}
40008@anchor{qXfer executable filename read}
40009Return the full absolute name of the file that was executed to create
40010a process running on the remote system. The annex specifies the
40011numeric process ID of the process to query, encoded as a hexadecimal
835205d0
GB
40012number. If the annex part is empty the remote stub should return the
40013filename corresponding to the currently executing process.
c78fa86a
GB
40014
40015This packet is not probed by default; the remote stub must request it,
40016by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
f4abbc16 40017
23181151
DJ
40018@item qXfer:features:read:@var{annex}:@var{offset},@var{length}
40019@anchor{qXfer target description read}
40020Access the @dfn{target description}. @xref{Target Descriptions}. The
40021annex specifies which XML document to access. The main description is
40022always loaded from the @samp{target.xml} annex.
40023
40024This packet is not probed by default; the remote stub must request it,
40025by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40026
cfa9d6d9
DJ
40027@item qXfer:libraries:read:@var{annex}:@var{offset},@var{length}
40028@anchor{qXfer library list read}
40029Access the target's list of loaded libraries. @xref{Library List Format}.
40030The annex part of the generic @samp{qXfer} packet must be empty
40031(@pxref{qXfer read}).
40032
40033Targets which maintain a list of libraries in the program's memory do
40034not need to implement this packet; it is designed for platforms where
40035the operating system manages the list of loaded libraries.
40036
40037This packet is not probed by default; the remote stub must request it,
40038by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40039
2268b414
JK
40040@item qXfer:libraries-svr4:read:@var{annex}:@var{offset},@var{length}
40041@anchor{qXfer svr4 library list read}
40042Access the target's list of loaded libraries when the target is an SVR4
40043platform. @xref{Library List Format for SVR4 Targets}. The annex part
85dc5a12
GB
40044of the generic @samp{qXfer} packet must be empty unless the remote
40045stub indicated it supports the augmented form of this packet
40046by supplying an appropriate @samp{qSupported} response
40047(@pxref{qXfer read}, @ref{qSupported}).
2268b414
JK
40048
40049This packet is optional for better performance on SVR4 targets.
40050@value{GDBN} uses memory read packets to read the SVR4 library list otherwise.
40051
40052This packet is not probed by default; the remote stub must request it,
40053by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40054
85dc5a12
GB
40055If the remote stub indicates it supports the augmented form of this
40056packet then the annex part of the generic @samp{qXfer} packet may
40057contain a semicolon-separated list of @samp{@var{name}=@var{value}}
40058arguments. The currently supported arguments are:
40059
40060@table @code
40061@item start=@var{address}
40062A hexadecimal number specifying the address of the @samp{struct
40063link_map} to start reading the library list from. If unset or zero
40064then the first @samp{struct link_map} in the library list will be
40065chosen as the starting point.
40066
40067@item prev=@var{address}
40068A hexadecimal number specifying the address of the @samp{struct
40069link_map} immediately preceding the @samp{struct link_map}
40070specified by the @samp{start} argument. If unset or zero then
40071the remote stub will expect that no @samp{struct link_map}
40072exists prior to the starting point.
40073
40074@end table
40075
40076Arguments that are not understood by the remote stub will be silently
40077ignored.
40078
68437a39
DJ
40079@item qXfer:memory-map:read::@var{offset},@var{length}
40080@anchor{qXfer memory map read}
79a6e687 40081Access the target's @dfn{memory-map}. @xref{Memory Map Format}. The
68437a39
DJ
40082annex part of the generic @samp{qXfer} packet must be empty
40083(@pxref{qXfer read}).
40084
0e7f50da
UW
40085This packet is not probed by default; the remote stub must request it,
40086by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40087
0fb4aa4b
PA
40088@item qXfer:sdata:read::@var{offset},@var{length}
40089@anchor{qXfer sdata read}
40090
40091Read contents of the extra collected static tracepoint marker
40092information. The annex part of the generic @samp{qXfer} packet must
40093be empty (@pxref{qXfer read}). @xref{Tracepoint Actions,,Tracepoint
40094Action Lists}.
40095
40096This packet is not probed by default; the remote stub must request it,
40097by supplying an appropriate @samp{qSupported} response
40098(@pxref{qSupported}).
40099
4aa995e1
PA
40100@item qXfer:siginfo:read::@var{offset},@var{length}
40101@anchor{qXfer siginfo read}
40102Read contents of the extra signal information on the target
40103system. The annex part of the generic @samp{qXfer} packet must be
40104empty (@pxref{qXfer read}).
40105
40106This packet is not probed by default; the remote stub must request it,
40107by supplying an appropriate @samp{qSupported} response
40108(@pxref{qSupported}).
40109
0e7f50da
UW
40110@item qXfer:spu:read:@var{annex}:@var{offset},@var{length}
40111@anchor{qXfer spu read}
40112Read contents of an @code{spufs} file on the target system. The
40113annex specifies which file to read; it must be of the form
40114@file{@var{id}/@var{name}}, where @var{id} specifies an SPU context ID
40115in the target process, and @var{name} identifes the @code{spufs} file
40116in that context to be accessed.
40117
68437a39 40118This packet is not probed by default; the remote stub must request it,
07e059b5
VP
40119by supplying an appropriate @samp{qSupported} response
40120(@pxref{qSupported}).
40121
dc146f7c
VP
40122@item qXfer:threads:read::@var{offset},@var{length}
40123@anchor{qXfer threads read}
40124Access the list of threads on target. @xref{Thread List Format}. The
40125annex part of the generic @samp{qXfer} packet must be empty
40126(@pxref{qXfer read}).
40127
40128This packet is not probed by default; the remote stub must request it,
40129by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40130
b3b9301e
PA
40131@item qXfer:traceframe-info:read::@var{offset},@var{length}
40132@anchor{qXfer traceframe info read}
40133
40134Return a description of the current traceframe's contents.
40135@xref{Traceframe Info Format}. The annex part of the generic
40136@samp{qXfer} packet must be empty (@pxref{qXfer read}).
40137
40138This packet is not probed by default; the remote stub must request it,
40139by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40140
169081d0
TG
40141@item qXfer:uib:read:@var{pc}:@var{offset},@var{length}
40142@anchor{qXfer unwind info block}
40143
40144Return the unwind information block for @var{pc}. This packet is used
40145on OpenVMS/ia64 to ask the kernel unwind information.
40146
40147This packet is not probed by default.
40148
78d85199
YQ
40149@item qXfer:fdpic:read:@var{annex}:@var{offset},@var{length}
40150@anchor{qXfer fdpic loadmap read}
40151Read contents of @code{loadmap}s on the target system. The
40152annex, either @samp{exec} or @samp{interp}, specifies which @code{loadmap},
40153executable @code{loadmap} or interpreter @code{loadmap} to read.
40154
40155This packet is not probed by default; the remote stub must request it,
40156by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40157
07e059b5
VP
40158@item qXfer:osdata:read::@var{offset},@var{length}
40159@anchor{qXfer osdata read}
697aa1b7 40160Access the target's @dfn{operating system information}.
07e059b5
VP
40161@xref{Operating System Information}.
40162
68437a39
DJ
40163@end table
40164
c185ba27
EZ
40165@item qXfer:@var{object}:write:@var{annex}:@var{offset}:@var{data}@dots{}
40166@cindex write data into object, remote request
40167@anchor{qXfer write}
40168Write uninterpreted bytes into the target's special data area
40169identified by the keyword @var{object}, starting at @var{offset} bytes
40170into the data. The binary-encoded data (@pxref{Binary Data}) to be
40171written is given by @var{data}@dots{}. The content and encoding of @var{annex}
40172is specific to @var{object}; it can supply additional details about what data
40173to access.
40174
0876f84a
DJ
40175Reply:
40176@table @samp
c185ba27
EZ
40177@item @var{nn}
40178@var{nn} (hex encoded) is the number of bytes written.
40179This may be fewer bytes than supplied in the request.
0876f84a
DJ
40180
40181@item E00
40182The request was malformed, or @var{annex} was invalid.
40183
40184@item E @var{nn}
c185ba27 40185The offset was invalid, or there was an error encountered writing the data.
697aa1b7 40186The @var{nn} part is a hex-encoded @code{errno} value.
0876f84a 40187
d57350ea 40188@item @w{}
c185ba27
EZ
40189An empty reply indicates the @var{object} string was not
40190recognized by the stub, or that the object does not support writing.
0876f84a
DJ
40191@end table
40192
c185ba27 40193Here are the specific requests of this form defined so far. All the
0e7f50da 40194@samp{qXfer:@var{object}:write:@dots{}} requests use the same reply
c185ba27 40195formats, listed above.
0e7f50da
UW
40196
40197@table @samp
4aa995e1
PA
40198@item qXfer:siginfo:write::@var{offset}:@var{data}@dots{}
40199@anchor{qXfer siginfo write}
40200Write @var{data} to the extra signal information on the target system.
40201The annex part of the generic @samp{qXfer} packet must be
40202empty (@pxref{qXfer write}).
40203
40204This packet is not probed by default; the remote stub must request it,
40205by supplying an appropriate @samp{qSupported} response
40206(@pxref{qSupported}).
40207
84fcdf95 40208@item qXfer:spu:write:@var{annex}:@var{offset}:@var{data}@dots{}
0e7f50da
UW
40209@anchor{qXfer spu write}
40210Write @var{data} to an @code{spufs} file on the target system. The
40211annex specifies which file to write; it must be of the form
40212@file{@var{id}/@var{name}}, where @var{id} specifies an SPU context ID
40213in the target process, and @var{name} identifes the @code{spufs} file
40214in that context to be accessed.
40215
40216This packet is not probed by default; the remote stub must request it,
40217by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40218@end table
0876f84a 40219
0876f84a
DJ
40220@item qXfer:@var{object}:@var{operation}:@dots{}
40221Requests of this form may be added in the future. When a stub does
40222not recognize the @var{object} keyword, or its support for
40223@var{object} does not recognize the @var{operation} keyword, the stub
40224must respond with an empty packet.
40225
0b16c5cf
PA
40226@item qAttached:@var{pid}
40227@cindex query attached, remote request
40228@cindex @samp{qAttached} packet
40229Return an indication of whether the remote server attached to an
40230existing process or created a new process. When the multiprocess
40231protocol extensions are supported (@pxref{multiprocess extensions}),
40232@var{pid} is an integer in hexadecimal format identifying the target
40233process. Otherwise, @value{GDBN} will omit the @var{pid} field and
40234the query packet will be simplified as @samp{qAttached}.
40235
40236This query is used, for example, to know whether the remote process
40237should be detached or killed when a @value{GDBN} session is ended with
40238the @code{quit} command.
40239
40240Reply:
40241@table @samp
40242@item 1
40243The remote server attached to an existing process.
40244@item 0
40245The remote server created a new process.
40246@item E @var{NN}
40247A badly formed request or an error was encountered.
40248@end table
40249
2ae8c8e7 40250@item Qbtrace:bts
b20a6524
MM
40251Enable branch tracing for the current thread using Branch Trace Store.
40252
40253Reply:
40254@table @samp
40255@item OK
40256Branch tracing has been enabled.
40257@item E.errtext
40258A badly formed request or an error was encountered.
40259@end table
40260
40261@item Qbtrace:pt
bc504a31 40262Enable branch tracing for the current thread using Intel Processor Trace.
2ae8c8e7
MM
40263
40264Reply:
40265@table @samp
40266@item OK
40267Branch tracing has been enabled.
40268@item E.errtext
40269A badly formed request or an error was encountered.
40270@end table
40271
40272@item Qbtrace:off
40273Disable branch tracing for the current thread.
40274
40275Reply:
40276@table @samp
40277@item OK
40278Branch tracing has been disabled.
40279@item E.errtext
40280A badly formed request or an error was encountered.
40281@end table
40282
d33501a5
MM
40283@item Qbtrace-conf:bts:size=@var{value}
40284Set the requested ring buffer size for new threads that use the
40285btrace recording method in bts format.
40286
40287Reply:
40288@table @samp
40289@item OK
40290The ring buffer size has been set.
40291@item E.errtext
40292A badly formed request or an error was encountered.
40293@end table
40294
b20a6524
MM
40295@item Qbtrace-conf:pt:size=@var{value}
40296Set the requested ring buffer size for new threads that use the
40297btrace recording method in pt format.
40298
40299Reply:
40300@table @samp
40301@item OK
40302The ring buffer size has been set.
40303@item E.errtext
40304A badly formed request or an error was encountered.
40305@end table
40306
ee2d5c50
AC
40307@end table
40308
a1dcb23a
DJ
40309@node Architecture-Specific Protocol Details
40310@section Architecture-Specific Protocol Details
40311
40312This section describes how the remote protocol is applied to specific
40313target architectures. Also see @ref{Standard Target Features}, for
40314details of XML target descriptions for each architecture.
40315
02b67415
MR
40316@menu
40317* ARM-Specific Protocol Details::
40318* MIPS-Specific Protocol Details::
40319@end menu
40320
40321@node ARM-Specific Protocol Details
40322@subsection @acronym{ARM}-specific Protocol Details
40323
40324@menu
40325* ARM Breakpoint Kinds::
40326@end menu
a1dcb23a 40327
02b67415
MR
40328@node ARM Breakpoint Kinds
40329@subsubsection @acronym{ARM} Breakpoint Kinds
40330@cindex breakpoint kinds, @acronym{ARM}
a1dcb23a
DJ
40331
40332These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
40333
40334@table @r
40335
40336@item 2
4033716-bit Thumb mode breakpoint.
40338
40339@item 3
4034032-bit Thumb mode (Thumb-2) breakpoint.
40341
40342@item 4
02b67415 4034332-bit @acronym{ARM} mode breakpoint.
a1dcb23a
DJ
40344
40345@end table
40346
02b67415
MR
40347@node MIPS-Specific Protocol Details
40348@subsection @acronym{MIPS}-specific Protocol Details
40349
40350@menu
40351* MIPS Register packet Format::
4cc0665f 40352* MIPS Breakpoint Kinds::
02b67415 40353@end menu
a1dcb23a 40354
02b67415
MR
40355@node MIPS Register packet Format
40356@subsubsection @acronym{MIPS} Register Packet Format
eb17f351 40357@cindex register packet format, @acronym{MIPS}
eb12ee30 40358
b8ff78ce 40359The following @code{g}/@code{G} packets have previously been defined.
ee2d5c50
AC
40360In the below, some thirty-two bit registers are transferred as
40361sixty-four bits. Those registers should be zero/sign extended (which?)
599b237a
BW
40362to fill the space allocated. Register bytes are transferred in target
40363byte order. The two nibbles within a register byte are transferred
02b67415 40364most-significant -- least-significant.
eb12ee30 40365
ee2d5c50 40366@table @r
eb12ee30 40367
8e04817f 40368@item MIPS32
599b237a 40369All registers are transferred as thirty-two bit quantities in the order:
8e04817f
AC
4037032 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
40371registers; fsr; fir; fp.
eb12ee30 40372
8e04817f 40373@item MIPS64
599b237a 40374All registers are transferred as sixty-four bit quantities (including
8e04817f
AC
40375thirty-two bit registers such as @code{sr}). The ordering is the same
40376as @code{MIPS32}.
eb12ee30 40377
ee2d5c50
AC
40378@end table
40379
4cc0665f
MR
40380@node MIPS Breakpoint Kinds
40381@subsubsection @acronym{MIPS} Breakpoint Kinds
40382@cindex breakpoint kinds, @acronym{MIPS}
40383
40384These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
40385
40386@table @r
40387
40388@item 2
4038916-bit @acronym{MIPS16} mode breakpoint.
40390
40391@item 3
4039216-bit @acronym{microMIPS} mode breakpoint.
40393
40394@item 4
4039532-bit standard @acronym{MIPS} mode breakpoint.
40396
40397@item 5
4039832-bit @acronym{microMIPS} mode breakpoint.
40399
40400@end table
40401
9d29849a
JB
40402@node Tracepoint Packets
40403@section Tracepoint Packets
40404@cindex tracepoint packets
40405@cindex packets, tracepoint
40406
40407Here we describe the packets @value{GDBN} uses to implement
40408tracepoints (@pxref{Tracepoints}).
40409
40410@table @samp
40411
7a697b8d 40412@item QTDP:@var{n}:@var{addr}:@var{ena}:@var{step}:@var{pass}[:F@var{flen}][:X@var{len},@var{bytes}]@r{[}-@r{]}
c614397c 40413@cindex @samp{QTDP} packet
9d29849a
JB
40414Create a new tracepoint, number @var{n}, at @var{addr}. If @var{ena}
40415is @samp{E}, then the tracepoint is enabled; if it is @samp{D}, then
697aa1b7
EZ
40416the tracepoint is disabled. The @var{step} gives the tracepoint's step
40417count, and @var{pass} gives its pass count. If an @samp{F} is present,
7a697b8d
SS
40418then the tracepoint is to be a fast tracepoint, and the @var{flen} is
40419the number of bytes that the target should copy elsewhere to make room
40420for the tracepoint. If an @samp{X} is present, it introduces a
40421tracepoint condition, which consists of a hexadecimal length, followed
40422by a comma and hex-encoded bytes, in a manner similar to action
40423encodings as described below. If the trailing @samp{-} is present,
40424further @samp{QTDP} packets will follow to specify this tracepoint's
40425actions.
9d29849a
JB
40426
40427Replies:
40428@table @samp
40429@item OK
40430The packet was understood and carried out.
dde08ee1
PA
40431@item qRelocInsn
40432@xref{Tracepoint Packets,,Relocate instruction reply packet}.
d57350ea 40433@item @w{}
9d29849a
JB
40434The packet was not recognized.
40435@end table
40436
40437@item QTDP:-@var{n}:@var{addr}:@r{[}S@r{]}@var{action}@dots{}@r{[}-@r{]}
697aa1b7 40438Define actions to be taken when a tracepoint is hit. The @var{n} and
9d29849a
JB
40439@var{addr} must be the same as in the initial @samp{QTDP} packet for
40440this tracepoint. This packet may only be sent immediately after
40441another @samp{QTDP} packet that ended with a @samp{-}. If the
40442trailing @samp{-} is present, further @samp{QTDP} packets will follow,
40443specifying more actions for this tracepoint.
40444
40445In the series of action packets for a given tracepoint, at most one
40446can have an @samp{S} before its first @var{action}. If such a packet
40447is sent, it and the following packets define ``while-stepping''
40448actions. Any prior packets define ordinary actions --- that is, those
40449taken when the tracepoint is first hit. If no action packet has an
40450@samp{S}, then all the packets in the series specify ordinary
40451tracepoint actions.
40452
40453The @samp{@var{action}@dots{}} portion of the packet is a series of
40454actions, concatenated without separators. Each action has one of the
40455following forms:
40456
40457@table @samp
40458
40459@item R @var{mask}
697aa1b7 40460Collect the registers whose bits are set in @var{mask},
599b237a 40461a hexadecimal number whose @var{i}'th bit is set if register number
9d29849a
JB
40462@var{i} should be collected. (The least significant bit is numbered
40463zero.) Note that @var{mask} may be any number of digits long; it may
40464not fit in a 32-bit word.
40465
40466@item M @var{basereg},@var{offset},@var{len}
40467Collect @var{len} bytes of memory starting at the address in register
40468number @var{basereg}, plus @var{offset}. If @var{basereg} is
40469@samp{-1}, then the range has a fixed address: @var{offset} is the
40470address of the lowest byte to collect. The @var{basereg},
599b237a 40471@var{offset}, and @var{len} parameters are all unsigned hexadecimal
9d29849a
JB
40472values (the @samp{-1} value for @var{basereg} is a special case).
40473
40474@item X @var{len},@var{expr}
40475Evaluate @var{expr}, whose length is @var{len}, and collect memory as
697aa1b7 40476it directs. The agent expression @var{expr} is as described in
9d29849a
JB
40477@ref{Agent Expressions}. Each byte of the expression is encoded as a
40478two-digit hex number in the packet; @var{len} is the number of bytes
40479in the expression (and thus one-half the number of hex digits in the
40480packet).
40481
40482@end table
40483
40484Any number of actions may be packed together in a single @samp{QTDP}
40485packet, as long as the packet does not exceed the maximum packet
c1947b85
JB
40486length (400 bytes, for many stubs). There may be only one @samp{R}
40487action per tracepoint, and it must precede any @samp{M} or @samp{X}
40488actions. Any registers referred to by @samp{M} and @samp{X} actions
40489must be collected by a preceding @samp{R} action. (The
40490``while-stepping'' actions are treated as if they were attached to a
40491separate tracepoint, as far as these restrictions are concerned.)
9d29849a
JB
40492
40493Replies:
40494@table @samp
40495@item OK
40496The packet was understood and carried out.
dde08ee1
PA
40497@item qRelocInsn
40498@xref{Tracepoint Packets,,Relocate instruction reply packet}.
d57350ea 40499@item @w{}
9d29849a
JB
40500The packet was not recognized.
40501@end table
40502
409873ef
SS
40503@item QTDPsrc:@var{n}:@var{addr}:@var{type}:@var{start}:@var{slen}:@var{bytes}
40504@cindex @samp{QTDPsrc} packet
40505Specify a source string of tracepoint @var{n} at address @var{addr}.
40506This is useful to get accurate reproduction of the tracepoints
697aa1b7 40507originally downloaded at the beginning of the trace run. The @var{type}
409873ef
SS
40508is the name of the tracepoint part, such as @samp{cond} for the
40509tracepoint's conditional expression (see below for a list of types), while
40510@var{bytes} is the string, encoded in hexadecimal.
40511
40512@var{start} is the offset of the @var{bytes} within the overall source
40513string, while @var{slen} is the total length of the source string.
40514This is intended for handling source strings that are longer than will
40515fit in a single packet.
40516@c Add detailed example when this info is moved into a dedicated
40517@c tracepoint descriptions section.
40518
40519The available string types are @samp{at} for the location,
40520@samp{cond} for the conditional, and @samp{cmd} for an action command.
40521@value{GDBN} sends a separate packet for each command in the action
40522list, in the same order in which the commands are stored in the list.
40523
40524The target does not need to do anything with source strings except
40525report them back as part of the replies to the @samp{qTfP}/@samp{qTsP}
40526query packets.
40527
40528Although this packet is optional, and @value{GDBN} will only send it
40529if the target replies with @samp{TracepointSource} @xref{General
40530Query Packets}, it makes both disconnected tracing and trace files
40531much easier to use. Otherwise the user must be careful that the
40532tracepoints in effect while looking at trace frames are identical to
40533the ones in effect during the trace run; even a small discrepancy
40534could cause @samp{tdump} not to work, or a particular trace frame not
40535be found.
40536
fa3f8d5a 40537@item QTDV:@var{n}:@var{value}:@var{builtin}:@var{name}
f61e138d
SS
40538@cindex define trace state variable, remote request
40539@cindex @samp{QTDV} packet
40540Create a new trace state variable, number @var{n}, with an initial
40541value of @var{value}, which is a 64-bit signed integer. Both @var{n}
40542and @var{value} are encoded as hexadecimal values. @value{GDBN} has
40543the option of not using this packet for initial values of zero; the
40544target should simply create the trace state variables as they are
fa3f8d5a
DT
40545mentioned in expressions. The value @var{builtin} should be 1 (one)
40546if the trace state variable is builtin and 0 (zero) if it is not builtin.
40547@value{GDBN} only sets @var{builtin} to 1 if a previous @samp{qTfV} or
40548@samp{qTsV} packet had it set. The contents of @var{name} is the
40549hex-encoded name (without the leading @samp{$}) of the trace state
40550variable.
f61e138d 40551
9d29849a 40552@item QTFrame:@var{n}
c614397c 40553@cindex @samp{QTFrame} packet
9d29849a
JB
40554Select the @var{n}'th tracepoint frame from the buffer, and use the
40555register and memory contents recorded there to answer subsequent
40556request packets from @value{GDBN}.
40557
40558A successful reply from the stub indicates that the stub has found the
40559requested frame. The response is a series of parts, concatenated
40560without separators, describing the frame we selected. Each part has
40561one of the following forms:
40562
40563@table @samp
40564@item F @var{f}
40565The selected frame is number @var{n} in the trace frame buffer;
599b237a 40566@var{f} is a hexadecimal number. If @var{f} is @samp{-1}, then there
9d29849a
JB
40567was no frame matching the criteria in the request packet.
40568
40569@item T @var{t}
40570The selected trace frame records a hit of tracepoint number @var{t};
599b237a 40571@var{t} is a hexadecimal number.
9d29849a
JB
40572
40573@end table
40574
40575@item QTFrame:pc:@var{addr}
40576Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
40577currently selected frame whose PC is @var{addr};
599b237a 40578@var{addr} is a hexadecimal number.
9d29849a
JB
40579
40580@item QTFrame:tdp:@var{t}
40581Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
40582currently selected frame that is a hit of tracepoint @var{t}; @var{t}
599b237a 40583is a hexadecimal number.
9d29849a
JB
40584
40585@item QTFrame:range:@var{start}:@var{end}
40586Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
40587currently selected frame whose PC is between @var{start} (inclusive)
081dfbf7 40588and @var{end} (inclusive); @var{start} and @var{end} are hexadecimal
9d29849a
JB
40589numbers.
40590
40591@item QTFrame:outside:@var{start}:@var{end}
40592Like @samp{QTFrame:range:@var{start}:@var{end}}, but select the first
081dfbf7 40593frame @emph{outside} the given range of addresses (exclusive).
9d29849a 40594
405f8e94 40595@item qTMinFTPILen
c614397c 40596@cindex @samp{qTMinFTPILen} packet
405f8e94
SS
40597This packet requests the minimum length of instruction at which a fast
40598tracepoint (@pxref{Set Tracepoints}) may be placed. For instance, on
40599the 32-bit x86 architecture, it is possible to use a 4-byte jump, but
40600it depends on the target system being able to create trampolines in
40601the first 64K of memory, which might or might not be possible for that
40602system. So the reply to this packet will be 4 if it is able to
40603arrange for that.
40604
40605Replies:
40606
40607@table @samp
40608@item 0
40609The minimum instruction length is currently unknown.
40610@item @var{length}
697aa1b7
EZ
40611The minimum instruction length is @var{length}, where @var{length}
40612is a hexadecimal number greater or equal to 1. A reply
40613of 1 means that a fast tracepoint may be placed on any instruction
40614regardless of size.
405f8e94
SS
40615@item E
40616An error has occurred.
d57350ea 40617@item @w{}
405f8e94
SS
40618An empty reply indicates that the request is not supported by the stub.
40619@end table
40620
9d29849a 40621@item QTStart
c614397c 40622@cindex @samp{QTStart} packet
dde08ee1
PA
40623Begin the tracepoint experiment. Begin collecting data from
40624tracepoint hits in the trace frame buffer. This packet supports the
40625@samp{qRelocInsn} reply (@pxref{Tracepoint Packets,,Relocate
40626instruction reply packet}).
9d29849a
JB
40627
40628@item QTStop
c614397c 40629@cindex @samp{QTStop} packet
9d29849a
JB
40630End the tracepoint experiment. Stop collecting trace frames.
40631
d248b706
KY
40632@item QTEnable:@var{n}:@var{addr}
40633@anchor{QTEnable}
c614397c 40634@cindex @samp{QTEnable} packet
d248b706
KY
40635Enable tracepoint @var{n} at address @var{addr} in a started tracepoint
40636experiment. If the tracepoint was previously disabled, then collection
40637of data from it will resume.
40638
40639@item QTDisable:@var{n}:@var{addr}
40640@anchor{QTDisable}
c614397c 40641@cindex @samp{QTDisable} packet
d248b706
KY
40642Disable tracepoint @var{n} at address @var{addr} in a started tracepoint
40643experiment. No more data will be collected from the tracepoint unless
40644@samp{QTEnable:@var{n}:@var{addr}} is subsequently issued.
40645
9d29849a 40646@item QTinit
c614397c 40647@cindex @samp{QTinit} packet
9d29849a
JB
40648Clear the table of tracepoints, and empty the trace frame buffer.
40649
40650@item QTro:@var{start1},@var{end1}:@var{start2},@var{end2}:@dots{}
c614397c 40651@cindex @samp{QTro} packet
9d29849a
JB
40652Establish the given ranges of memory as ``transparent''. The stub
40653will answer requests for these ranges from memory's current contents,
40654if they were not collected as part of the tracepoint hit.
40655
40656@value{GDBN} uses this to mark read-only regions of memory, like those
40657containing program code. Since these areas never change, they should
40658still have the same contents they did when the tracepoint was hit, so
40659there's no reason for the stub to refuse to provide their contents.
40660
d5551862 40661@item QTDisconnected:@var{value}
c614397c 40662@cindex @samp{QTDisconnected} packet
d5551862
SS
40663Set the choice to what to do with the tracing run when @value{GDBN}
40664disconnects from the target. A @var{value} of 1 directs the target to
40665continue the tracing run, while 0 tells the target to stop tracing if
40666@value{GDBN} is no longer in the picture.
40667
9d29849a 40668@item qTStatus
c614397c 40669@cindex @samp{qTStatus} packet
9d29849a
JB
40670Ask the stub if there is a trace experiment running right now.
40671
4daf5ac0
SS
40672The reply has the form:
40673
40674@table @samp
40675
40676@item T@var{running}@r{[};@var{field}@r{]}@dots{}
40677@var{running} is a single digit @code{1} if the trace is presently
40678running, or @code{0} if not. It is followed by semicolon-separated
40679optional fields that an agent may use to report additional status.
40680
40681@end table
40682
40683If the trace is not running, the agent may report any of several
40684explanations as one of the optional fields:
40685
40686@table @samp
40687
40688@item tnotrun:0
40689No trace has been run yet.
40690
f196051f
SS
40691@item tstop[:@var{text}]:0
40692The trace was stopped by a user-originated stop command. The optional
40693@var{text} field is a user-supplied string supplied as part of the
40694stop command (for instance, an explanation of why the trace was
40695stopped manually). It is hex-encoded.
4daf5ac0
SS
40696
40697@item tfull:0
40698The trace stopped because the trace buffer filled up.
40699
40700@item tdisconnected:0
40701The trace stopped because @value{GDBN} disconnected from the target.
40702
40703@item tpasscount:@var{tpnum}
40704The trace stopped because tracepoint @var{tpnum} exceeded its pass count.
40705
6c28cbf2
SS
40706@item terror:@var{text}:@var{tpnum}
40707The trace stopped because tracepoint @var{tpnum} had an error. The
40708string @var{text} is available to describe the nature of the error
697aa1b7
EZ
40709(for instance, a divide by zero in the condition expression); it
40710is hex encoded.
6c28cbf2 40711
4daf5ac0
SS
40712@item tunknown:0
40713The trace stopped for some other reason.
40714
40715@end table
40716
33da3f1c
SS
40717Additional optional fields supply statistical and other information.
40718Although not required, they are extremely useful for users monitoring
40719the progress of a trace run. If a trace has stopped, and these
40720numbers are reported, they must reflect the state of the just-stopped
40721trace.
4daf5ac0 40722
9d29849a 40723@table @samp
4daf5ac0
SS
40724
40725@item tframes:@var{n}
40726The number of trace frames in the buffer.
40727
40728@item tcreated:@var{n}
40729The total number of trace frames created during the run. This may
40730be larger than the trace frame count, if the buffer is circular.
40731
40732@item tsize:@var{n}
40733The total size of the trace buffer, in bytes.
40734
40735@item tfree:@var{n}
40736The number of bytes still unused in the buffer.
40737
33da3f1c
SS
40738@item circular:@var{n}
40739The value of the circular trace buffer flag. @code{1} means that the
40740trace buffer is circular and old trace frames will be discarded if
40741necessary to make room, @code{0} means that the trace buffer is linear
40742and may fill up.
40743
40744@item disconn:@var{n}
40745The value of the disconnected tracing flag. @code{1} means that
40746tracing will continue after @value{GDBN} disconnects, @code{0} means
40747that the trace run will stop.
40748
9d29849a
JB
40749@end table
40750
f196051f
SS
40751@item qTP:@var{tp}:@var{addr}
40752@cindex tracepoint status, remote request
40753@cindex @samp{qTP} packet
40754Ask the stub for the current state of tracepoint number @var{tp} at
40755address @var{addr}.
40756
40757Replies:
40758@table @samp
40759@item V@var{hits}:@var{usage}
40760The tracepoint has been hit @var{hits} times so far during the trace
40761run, and accounts for @var{usage} in the trace buffer. Note that
40762@code{while-stepping} steps are not counted as separate hits, but the
40763steps' space consumption is added into the usage number.
40764
40765@end table
40766
f61e138d
SS
40767@item qTV:@var{var}
40768@cindex trace state variable value, remote request
40769@cindex @samp{qTV} packet
40770Ask the stub for the value of the trace state variable number @var{var}.
40771
40772Replies:
40773@table @samp
40774@item V@var{value}
40775The value of the variable is @var{value}. This will be the current
40776value of the variable if the user is examining a running target, or a
40777saved value if the variable was collected in the trace frame that the
40778user is looking at. Note that multiple requests may result in
40779different reply values, such as when requesting values while the
40780program is running.
40781
40782@item U
40783The value of the variable is unknown. This would occur, for example,
40784if the user is examining a trace frame in which the requested variable
40785was not collected.
9d29849a
JB
40786@end table
40787
d5551862 40788@item qTfP
c614397c 40789@cindex @samp{qTfP} packet
d5551862 40790@itemx qTsP
c614397c 40791@cindex @samp{qTsP} packet
d5551862
SS
40792These packets request data about tracepoints that are being used by
40793the target. @value{GDBN} sends @code{qTfP} to get the first piece
40794of data, and multiple @code{qTsP} to get additional pieces. Replies
40795to these packets generally take the form of the @code{QTDP} packets
40796that define tracepoints. (FIXME add detailed syntax)
40797
00bf0b85 40798@item qTfV
c614397c 40799@cindex @samp{qTfV} packet
00bf0b85 40800@itemx qTsV
c614397c 40801@cindex @samp{qTsV} packet
00bf0b85
SS
40802These packets request data about trace state variables that are on the
40803target. @value{GDBN} sends @code{qTfV} to get the first vari of data,
40804and multiple @code{qTsV} to get additional variables. Replies to
40805these packets follow the syntax of the @code{QTDV} packets that define
40806trace state variables.
40807
0fb4aa4b
PA
40808@item qTfSTM
40809@itemx qTsSTM
16bdd41f
YQ
40810@anchor{qTfSTM}
40811@anchor{qTsSTM}
c614397c
YQ
40812@cindex @samp{qTfSTM} packet
40813@cindex @samp{qTsSTM} packet
0fb4aa4b
PA
40814These packets request data about static tracepoint markers that exist
40815in the target program. @value{GDBN} sends @code{qTfSTM} to get the
40816first piece of data, and multiple @code{qTsSTM} to get additional
40817pieces. Replies to these packets take the following form:
40818
40819Reply:
40820@table @samp
40821@item m @var{address}:@var{id}:@var{extra}
40822A single marker
40823@item m @var{address}:@var{id}:@var{extra},@var{address}:@var{id}:@var{extra}@dots{}
40824a comma-separated list of markers
40825@item l
40826(lower case letter @samp{L}) denotes end of list.
40827@item E @var{nn}
697aa1b7 40828An error occurred. The error number @var{nn} is given as hex digits.
d57350ea 40829@item @w{}
0fb4aa4b
PA
40830An empty reply indicates that the request is not supported by the
40831stub.
40832@end table
40833
697aa1b7 40834The @var{address} is encoded in hex;
0fb4aa4b
PA
40835@var{id} and @var{extra} are strings encoded in hex.
40836
40837In response to each query, the target will reply with a list of one or
40838more markers, separated by commas. @value{GDBN} will respond to each
40839reply with a request for more markers (using the @samp{qs} form of the
40840query), until the target responds with @samp{l} (lower-case ell, for
40841@dfn{last}).
40842
40843@item qTSTMat:@var{address}
16bdd41f 40844@anchor{qTSTMat}
c614397c 40845@cindex @samp{qTSTMat} packet
0fb4aa4b
PA
40846This packets requests data about static tracepoint markers in the
40847target program at @var{address}. Replies to this packet follow the
40848syntax of the @samp{qTfSTM} and @code{qTsSTM} packets that list static
40849tracepoint markers.
40850
00bf0b85 40851@item QTSave:@var{filename}
c614397c 40852@cindex @samp{QTSave} packet
00bf0b85 40853This packet directs the target to save trace data to the file name
697aa1b7 40854@var{filename} in the target's filesystem. The @var{filename} is encoded
00bf0b85
SS
40855as a hex string; the interpretation of the file name (relative vs
40856absolute, wild cards, etc) is up to the target.
40857
40858@item qTBuffer:@var{offset},@var{len}
c614397c 40859@cindex @samp{qTBuffer} packet
00bf0b85
SS
40860Return up to @var{len} bytes of the current contents of trace buffer,
40861starting at @var{offset}. The trace buffer is treated as if it were
40862a contiguous collection of traceframes, as per the trace file format.
40863The reply consists as many hex-encoded bytes as the target can deliver
40864in a packet; it is not an error to return fewer than were asked for.
40865A reply consisting of just @code{l} indicates that no bytes are
40866available.
40867
4daf5ac0
SS
40868@item QTBuffer:circular:@var{value}
40869This packet directs the target to use a circular trace buffer if
40870@var{value} is 1, or a linear buffer if the value is 0.
40871
f6f899bf 40872@item QTBuffer:size:@var{size}
28abe188
EZ
40873@anchor{QTBuffer-size}
40874@cindex @samp{QTBuffer size} packet
f6f899bf
HAQ
40875This packet directs the target to make the trace buffer be of size
40876@var{size} if possible. A value of @code{-1} tells the target to
40877use whatever size it prefers.
40878
f196051f 40879@item QTNotes:@r{[}@var{type}:@var{text}@r{]}@r{[};@var{type}:@var{text}@r{]}@dots{}
c614397c 40880@cindex @samp{QTNotes} packet
f196051f
SS
40881This packet adds optional textual notes to the trace run. Allowable
40882types include @code{user}, @code{notes}, and @code{tstop}, the
40883@var{text} fields are arbitrary strings, hex-encoded.
40884
f61e138d 40885@end table
9d29849a 40886
dde08ee1
PA
40887@subsection Relocate instruction reply packet
40888When installing fast tracepoints in memory, the target may need to
40889relocate the instruction currently at the tracepoint address to a
40890different address in memory. For most instructions, a simple copy is
40891enough, but, for example, call instructions that implicitly push the
40892return address on the stack, and relative branches or other
40893PC-relative instructions require offset adjustment, so that the effect
40894of executing the instruction at a different address is the same as if
40895it had executed in the original location.
40896
40897In response to several of the tracepoint packets, the target may also
40898respond with a number of intermediate @samp{qRelocInsn} request
40899packets before the final result packet, to have @value{GDBN} handle
40900this relocation operation. If a packet supports this mechanism, its
40901documentation will explicitly say so. See for example the above
40902descriptions for the @samp{QTStart} and @samp{QTDP} packets. The
40903format of the request is:
40904
40905@table @samp
40906@item qRelocInsn:@var{from};@var{to}
40907
40908This requests @value{GDBN} to copy instruction at address @var{from}
40909to address @var{to}, possibly adjusted so that executing the
40910instruction at @var{to} has the same effect as executing it at
40911@var{from}. @value{GDBN} writes the adjusted instruction to target
40912memory starting at @var{to}.
40913@end table
40914
40915Replies:
40916@table @samp
40917@item qRelocInsn:@var{adjusted_size}
697aa1b7 40918Informs the stub the relocation is complete. The @var{adjusted_size} is
dde08ee1
PA
40919the length in bytes of resulting relocated instruction sequence.
40920@item E @var{NN}
40921A badly formed request was detected, or an error was encountered while
40922relocating the instruction.
40923@end table
40924
a6b151f1
DJ
40925@node Host I/O Packets
40926@section Host I/O Packets
40927@cindex Host I/O, remote protocol
40928@cindex file transfer, remote protocol
40929
40930The @dfn{Host I/O} packets allow @value{GDBN} to perform I/O
40931operations on the far side of a remote link. For example, Host I/O is
40932used to upload and download files to a remote target with its own
40933filesystem. Host I/O uses the same constant values and data structure
40934layout as the target-initiated File-I/O protocol. However, the
40935Host I/O packets are structured differently. The target-initiated
40936protocol relies on target memory to store parameters and buffers.
40937Host I/O requests are initiated by @value{GDBN}, and the
40938target's memory is not involved. @xref{File-I/O Remote Protocol
40939Extension}, for more details on the target-initiated protocol.
40940
40941The Host I/O request packets all encode a single operation along with
40942its arguments. They have this format:
40943
40944@table @samp
40945
40946@item vFile:@var{operation}: @var{parameter}@dots{}
40947@var{operation} is the name of the particular request; the target
40948should compare the entire packet name up to the second colon when checking
40949for a supported operation. The format of @var{parameter} depends on
40950the operation. Numbers are always passed in hexadecimal. Negative
40951numbers have an explicit minus sign (i.e.@: two's complement is not
40952used). Strings (e.g.@: filenames) are encoded as a series of
40953hexadecimal bytes. The last argument to a system call may be a
40954buffer of escaped binary data (@pxref{Binary Data}).
40955
40956@end table
40957
40958The valid responses to Host I/O packets are:
40959
40960@table @samp
40961
40962@item F @var{result} [, @var{errno}] [; @var{attachment}]
40963@var{result} is the integer value returned by this operation, usually
40964non-negative for success and -1 for errors. If an error has occured,
697aa1b7 40965@var{errno} will be included in the result specifying a
a6b151f1
DJ
40966value defined by the File-I/O protocol (@pxref{Errno Values}). For
40967operations which return data, @var{attachment} supplies the data as a
40968binary buffer. Binary buffers in response packets are escaped in the
40969normal way (@pxref{Binary Data}). See the individual packet
40970documentation for the interpretation of @var{result} and
40971@var{attachment}.
40972
d57350ea 40973@item @w{}
a6b151f1
DJ
40974An empty response indicates that this operation is not recognized.
40975
40976@end table
40977
40978These are the supported Host I/O operations:
40979
40980@table @samp
697aa1b7
EZ
40981@item vFile:open: @var{filename}, @var{flags}, @var{mode}
40982Open a file at @var{filename} and return a file descriptor for it, or
40983return -1 if an error occurs. The @var{filename} is a string,
a6b151f1
DJ
40984@var{flags} is an integer indicating a mask of open flags
40985(@pxref{Open Flags}), and @var{mode} is an integer indicating a mask
40986of mode bits to use if the file is created (@pxref{mode_t Values}).
c1c25a1a 40987@xref{open}, for details of the open flags and mode values.
a6b151f1
DJ
40988
40989@item vFile:close: @var{fd}
40990Close the open file corresponding to @var{fd} and return 0, or
40991-1 if an error occurs.
40992
40993@item vFile:pread: @var{fd}, @var{count}, @var{offset}
40994Read data from the open file corresponding to @var{fd}. Up to
40995@var{count} bytes will be read from the file, starting at @var{offset}
40996relative to the start of the file. The target may read fewer bytes;
40997common reasons include packet size limits and an end-of-file
40998condition. The number of bytes read is returned. Zero should only be
40999returned for a successful read at the end of the file, or if
41000@var{count} was zero.
41001
41002The data read should be returned as a binary attachment on success.
41003If zero bytes were read, the response should include an empty binary
41004attachment (i.e.@: a trailing semicolon). The return value is the
41005number of target bytes read; the binary attachment may be longer if
41006some characters were escaped.
41007
41008@item vFile:pwrite: @var{fd}, @var{offset}, @var{data}
41009Write @var{data} (a binary buffer) to the open file corresponding
41010to @var{fd}. Start the write at @var{offset} from the start of the
41011file. Unlike many @code{write} system calls, there is no
41012separate @var{count} argument; the length of @var{data} in the
41013packet is used. @samp{vFile:write} returns the number of bytes written,
41014which may be shorter than the length of @var{data}, or -1 if an
41015error occurred.
41016
0a93529c
GB
41017@item vFile:fstat: @var{fd}
41018Get information about the open file corresponding to @var{fd}.
41019On success the information is returned as a binary attachment
41020and the return value is the size of this attachment in bytes.
41021If an error occurs the return value is -1. The format of the
41022returned binary attachment is as described in @ref{struct stat}.
41023
697aa1b7
EZ
41024@item vFile:unlink: @var{filename}
41025Delete the file at @var{filename} on the target. Return 0,
41026or -1 if an error occurs. The @var{filename} is a string.
a6b151f1 41027
b9e7b9c3
UW
41028@item vFile:readlink: @var{filename}
41029Read value of symbolic link @var{filename} on the target. Return
41030the number of bytes read, or -1 if an error occurs.
41031
41032The data read should be returned as a binary attachment on success.
41033If zero bytes were read, the response should include an empty binary
41034attachment (i.e.@: a trailing semicolon). The return value is the
41035number of target bytes read; the binary attachment may be longer if
41036some characters were escaped.
41037
15a201c8
GB
41038@item vFile:setfs: @var{pid}
41039Select the filesystem on which @code{vFile} operations with
41040@var{filename} arguments will operate. This is required for
41041@value{GDBN} to be able to access files on remote targets where
41042the remote stub does not share a common filesystem with the
41043inferior(s).
41044
41045If @var{pid} is nonzero, select the filesystem as seen by process
41046@var{pid}. If @var{pid} is zero, select the filesystem as seen by
41047the remote stub. Return 0 on success, or -1 if an error occurs.
41048If @code{vFile:setfs:} indicates success, the selected filesystem
41049remains selected until the next successful @code{vFile:setfs:}
41050operation.
41051
a6b151f1
DJ
41052@end table
41053
9a6253be
KB
41054@node Interrupts
41055@section Interrupts
41056@cindex interrupts (remote protocol)
de979965 41057@anchor{interrupting remote targets}
9a6253be 41058
de979965
PA
41059In all-stop mode, when a program on the remote target is running,
41060@value{GDBN} may attempt to interrupt it by sending a @samp{Ctrl-C},
41061@code{BREAK} or a @code{BREAK} followed by @code{g}, control of which
41062is specified via @value{GDBN}'s @samp{interrupt-sequence}.
9a6253be
KB
41063
41064The precise meaning of @code{BREAK} is defined by the transport
8775bb90
MS
41065mechanism and may, in fact, be undefined. @value{GDBN} does not
41066currently define a @code{BREAK} mechanism for any of the network
41067interfaces except for TCP, in which case @value{GDBN} sends the
41068@code{telnet} BREAK sequence.
9a6253be
KB
41069
41070@samp{Ctrl-C}, on the other hand, is defined and implemented for all
41071transport mechanisms. It is represented by sending the single byte
41072@code{0x03} without any of the usual packet overhead described in
41073the Overview section (@pxref{Overview}). When a @code{0x03} byte is
41074transmitted as part of a packet, it is considered to be packet data
41075and does @emph{not} represent an interrupt. E.g., an @samp{X} packet
0876f84a 41076(@pxref{X packet}), used for binary downloads, may include an unescaped
9a6253be
KB
41077@code{0x03} as part of its packet.
41078
9a7071a8
JB
41079@code{BREAK} followed by @code{g} is also known as Magic SysRq g.
41080When Linux kernel receives this sequence from serial port,
41081it stops execution and connects to gdb.
41082
de979965
PA
41083In non-stop mode, because packet resumptions are asynchronous
41084(@pxref{vCont packet}), @value{GDBN} is always free to send a remote
41085command to the remote stub, even when the target is running. For that
41086reason, @value{GDBN} instead sends a regular packet (@pxref{vCtrlC
41087packet}) with the usual packet framing instead of the single byte
41088@code{0x03}.
41089
9a6253be
KB
41090Stubs are not required to recognize these interrupt mechanisms and the
41091precise meaning associated with receipt of the interrupt is
8b23ecc4
SL
41092implementation defined. If the target supports debugging of multiple
41093threads and/or processes, it should attempt to interrupt all
41094currently-executing threads and processes.
41095If the stub is successful at interrupting the
41096running program, it should send one of the stop
41097reply packets (@pxref{Stop Reply Packets}) to @value{GDBN} as a result
41098of successfully stopping the program in all-stop mode, and a stop reply
41099for each stopped thread in non-stop mode.
41100Interrupts received while the
cde67b27
YQ
41101program is stopped are queued and the program will be interrupted when
41102it is resumed next time.
8b23ecc4
SL
41103
41104@node Notification Packets
41105@section Notification Packets
41106@cindex notification packets
41107@cindex packets, notification
41108
41109The @value{GDBN} remote serial protocol includes @dfn{notifications},
41110packets that require no acknowledgment. Both the GDB and the stub
41111may send notifications (although the only notifications defined at
41112present are sent by the stub). Notifications carry information
41113without incurring the round-trip latency of an acknowledgment, and so
41114are useful for low-impact communications where occasional packet loss
41115is not a problem.
41116
41117A notification packet has the form @samp{% @var{data} #
41118@var{checksum}}, where @var{data} is the content of the notification,
41119and @var{checksum} is a checksum of @var{data}, computed and formatted
41120as for ordinary @value{GDBN} packets. A notification's @var{data}
41121never contains @samp{$}, @samp{%} or @samp{#} characters. Upon
41122receiving a notification, the recipient sends no @samp{+} or @samp{-}
41123to acknowledge the notification's receipt or to report its corruption.
41124
41125Every notification's @var{data} begins with a name, which contains no
41126colon characters, followed by a colon character.
41127
41128Recipients should silently ignore corrupted notifications and
41129notifications they do not understand. Recipients should restart
41130timeout periods on receipt of a well-formed notification, whether or
41131not they understand it.
41132
41133Senders should only send the notifications described here when this
41134protocol description specifies that they are permitted. In the
41135future, we may extend the protocol to permit existing notifications in
41136new contexts; this rule helps older senders avoid confusing newer
41137recipients.
41138
41139(Older versions of @value{GDBN} ignore bytes received until they see
41140the @samp{$} byte that begins an ordinary packet, so new stubs may
41141transmit notifications without fear of confusing older clients. There
41142are no notifications defined for @value{GDBN} to send at the moment, but we
41143assume that most older stubs would ignore them, as well.)
41144
8dbe8ece 41145Each notification is comprised of three parts:
8b23ecc4 41146@table @samp
8dbe8ece
YQ
41147@item @var{name}:@var{event}
41148The notification packet is sent by the side that initiates the
41149exchange (currently, only the stub does that), with @var{event}
697aa1b7
EZ
41150carrying the specific information about the notification, and
41151@var{name} specifying the name of the notification.
8dbe8ece
YQ
41152@item @var{ack}
41153The acknowledge sent by the other side, usually @value{GDBN}, to
41154acknowledge the exchange and request the event.
41155@end table
41156
41157The purpose of an asynchronous notification mechanism is to report to
41158@value{GDBN} that something interesting happened in the remote stub.
41159
41160The remote stub may send notification @var{name}:@var{event}
41161at any time, but @value{GDBN} acknowledges the notification when
41162appropriate. The notification event is pending before @value{GDBN}
41163acknowledges. Only one notification at a time may be pending; if
41164additional events occur before @value{GDBN} has acknowledged the
41165previous notification, they must be queued by the stub for later
41166synchronous transmission in response to @var{ack} packets from
41167@value{GDBN}. Because the notification mechanism is unreliable,
41168the stub is permitted to resend a notification if it believes
41169@value{GDBN} may not have received it.
41170
41171Specifically, notifications may appear when @value{GDBN} is not
41172otherwise reading input from the stub, or when @value{GDBN} is
41173expecting to read a normal synchronous response or a
41174@samp{+}/@samp{-} acknowledgment to a packet it has sent.
41175Notification packets are distinct from any other communication from
41176the stub so there is no ambiguity.
41177
41178After receiving a notification, @value{GDBN} shall acknowledge it by
41179sending a @var{ack} packet as a regular, synchronous request to the
41180stub. Such acknowledgment is not required to happen immediately, as
41181@value{GDBN} is permitted to send other, unrelated packets to the
41182stub first, which the stub should process normally.
41183
41184Upon receiving a @var{ack} packet, if the stub has other queued
41185events to report to @value{GDBN}, it shall respond by sending a
41186normal @var{event}. @value{GDBN} shall then send another @var{ack}
41187packet to solicit further responses; again, it is permitted to send
41188other, unrelated packets as well which the stub should process
41189normally.
41190
41191If the stub receives a @var{ack} packet and there are no additional
41192@var{event} to report, the stub shall return an @samp{OK} response.
41193At this point, @value{GDBN} has finished processing a notification
41194and the stub has completed sending any queued events. @value{GDBN}
41195won't accept any new notifications until the final @samp{OK} is
41196received . If further notification events occur, the stub shall send
41197a new notification, @value{GDBN} shall accept the notification, and
41198the process shall be repeated.
41199
41200The process of asynchronous notification can be illustrated by the
41201following example:
41202@smallexample
4435e1cc 41203<- @code{%Stop:T0505:98e7ffbf;04:4ce6ffbf;08:b1b6e54c;thread:p7526.7526;core:0;}
8dbe8ece
YQ
41204@code{...}
41205-> @code{vStopped}
41206<- @code{T0505:68f37db7;04:40f37db7;08:63850408;thread:p7526.7528;core:0;}
41207-> @code{vStopped}
41208<- @code{T0505:68e3fdb6;04:40e3fdb6;08:63850408;thread:p7526.7529;core:0;}
41209-> @code{vStopped}
41210<- @code{OK}
41211@end smallexample
41212
41213The following notifications are defined:
41214@multitable @columnfractions 0.12 0.12 0.38 0.38
41215
41216@item Notification
41217@tab Ack
41218@tab Event
41219@tab Description
41220
41221@item Stop
41222@tab vStopped
41223@tab @var{reply}. The @var{reply} has the form of a stop reply, as
8b23ecc4
SL
41224described in @ref{Stop Reply Packets}. Refer to @ref{Remote Non-Stop},
41225for information on how these notifications are acknowledged by
41226@value{GDBN}.
8dbe8ece
YQ
41227@tab Report an asynchronous stop event in non-stop mode.
41228
41229@end multitable
8b23ecc4
SL
41230
41231@node Remote Non-Stop
41232@section Remote Protocol Support for Non-Stop Mode
41233
41234@value{GDBN}'s remote protocol supports non-stop debugging of
41235multi-threaded programs, as described in @ref{Non-Stop Mode}. If the stub
41236supports non-stop mode, it should report that to @value{GDBN} by including
41237@samp{QNonStop+} in its @samp{qSupported} response (@pxref{qSupported}).
41238
41239@value{GDBN} typically sends a @samp{QNonStop} packet only when
41240establishing a new connection with the stub. Entering non-stop mode
41241does not alter the state of any currently-running threads, but targets
41242must stop all threads in any already-attached processes when entering
41243all-stop mode. @value{GDBN} uses the @samp{?} packet as necessary to
41244probe the target state after a mode change.
41245
41246In non-stop mode, when an attached process encounters an event that
41247would otherwise be reported with a stop reply, it uses the
41248asynchronous notification mechanism (@pxref{Notification Packets}) to
41249inform @value{GDBN}. In contrast to all-stop mode, where all threads
41250in all processes are stopped when a stop reply is sent, in non-stop
41251mode only the thread reporting the stop event is stopped. That is,
41252when reporting a @samp{S} or @samp{T} response to indicate completion
41253of a step operation, hitting a breakpoint, or a fault, only the
41254affected thread is stopped; any other still-running threads continue
41255to run. When reporting a @samp{W} or @samp{X} response, all running
41256threads belonging to other attached processes continue to run.
41257
8b23ecc4
SL
41258In non-stop mode, the target shall respond to the @samp{?} packet as
41259follows. First, any incomplete stop reply notification/@samp{vStopped}
41260sequence in progress is abandoned. The target must begin a new
41261sequence reporting stop events for all stopped threads, whether or not
41262it has previously reported those events to @value{GDBN}. The first
41263stop reply is sent as a synchronous reply to the @samp{?} packet, and
41264subsequent stop replies are sent as responses to @samp{vStopped} packets
41265using the mechanism described above. The target must not send
41266asynchronous stop reply notifications until the sequence is complete.
41267If all threads are running when the target receives the @samp{?} packet,
41268or if the target is not attached to any process, it shall respond
41269@samp{OK}.
9a6253be 41270
f7e6eed5
PA
41271If the stub supports non-stop mode, it should also support the
41272@samp{swbreak} stop reason if software breakpoints are supported, and
41273the @samp{hwbreak} stop reason if hardware breakpoints are supported
41274(@pxref{swbreak stop reason}). This is because given the asynchronous
41275nature of non-stop mode, between the time a thread hits a breakpoint
41276and the time the event is finally processed by @value{GDBN}, the
41277breakpoint may have already been removed from the target. Due to
41278this, @value{GDBN} needs to be able to tell whether a trap stop was
41279caused by a delayed breakpoint event, which should be ignored, as
41280opposed to a random trap signal, which should be reported to the user.
41281Note the @samp{swbreak} feature implies that the target is responsible
41282for adjusting the PC when a software breakpoint triggers, if
41283necessary, such as on the x86 architecture.
41284
a6f3e723
SL
41285@node Packet Acknowledgment
41286@section Packet Acknowledgment
41287
41288@cindex acknowledgment, for @value{GDBN} remote
41289@cindex packet acknowledgment, for @value{GDBN} remote
41290By default, when either the host or the target machine receives a packet,
41291the first response expected is an acknowledgment: either @samp{+} (to indicate
41292the package was received correctly) or @samp{-} (to request retransmission).
41293This mechanism allows the @value{GDBN} remote protocol to operate over
41294unreliable transport mechanisms, such as a serial line.
41295
41296In cases where the transport mechanism is itself reliable (such as a pipe or
41297TCP connection), the @samp{+}/@samp{-} acknowledgments are redundant.
41298It may be desirable to disable them in that case to reduce communication
41299overhead, or for other reasons. This can be accomplished by means of the
41300@samp{QStartNoAckMode} packet; @pxref{QStartNoAckMode}.
41301
41302When in no-acknowledgment mode, neither the stub nor @value{GDBN} shall send or
41303expect @samp{+}/@samp{-} protocol acknowledgments. The packet
41304and response format still includes the normal checksum, as described in
41305@ref{Overview}, but the checksum may be ignored by the receiver.
41306
41307If the stub supports @samp{QStartNoAckMode} and prefers to operate in
41308no-acknowledgment mode, it should report that to @value{GDBN}
41309by including @samp{QStartNoAckMode+} in its response to @samp{qSupported};
41310@pxref{qSupported}.
41311If @value{GDBN} also supports @samp{QStartNoAckMode} and it has not been
41312disabled via the @code{set remote noack-packet off} command
41313(@pxref{Remote Configuration}),
41314@value{GDBN} may then send a @samp{QStartNoAckMode} packet to the stub.
41315Only then may the stub actually turn off packet acknowledgments.
41316@value{GDBN} sends a final @samp{+} acknowledgment of the stub's @samp{OK}
41317response, which can be safely ignored by the stub.
41318
41319Note that @code{set remote noack-packet} command only affects negotiation
41320between @value{GDBN} and the stub when subsequent connections are made;
41321it does not affect the protocol acknowledgment state for any current
41322connection.
41323Since @samp{+}/@samp{-} acknowledgments are enabled by default when a
41324new connection is established,
41325there is also no protocol request to re-enable the acknowledgments
41326for the current connection, once disabled.
41327
ee2d5c50
AC
41328@node Examples
41329@section Examples
eb12ee30 41330
8e04817f
AC
41331Example sequence of a target being re-started. Notice how the restart
41332does not get any direct output:
eb12ee30 41333
474c8240 41334@smallexample
d2c6833e
AC
41335-> @code{R00}
41336<- @code{+}
8e04817f 41337@emph{target restarts}
d2c6833e 41338-> @code{?}
8e04817f 41339<- @code{+}
d2c6833e
AC
41340<- @code{T001:1234123412341234}
41341-> @code{+}
474c8240 41342@end smallexample
eb12ee30 41343
8e04817f 41344Example sequence of a target being stepped by a single instruction:
eb12ee30 41345
474c8240 41346@smallexample
d2c6833e 41347-> @code{G1445@dots{}}
8e04817f 41348<- @code{+}
d2c6833e
AC
41349-> @code{s}
41350<- @code{+}
41351@emph{time passes}
41352<- @code{T001:1234123412341234}
8e04817f 41353-> @code{+}
d2c6833e 41354-> @code{g}
8e04817f 41355<- @code{+}
d2c6833e
AC
41356<- @code{1455@dots{}}
41357-> @code{+}
474c8240 41358@end smallexample
eb12ee30 41359
79a6e687
BW
41360@node File-I/O Remote Protocol Extension
41361@section File-I/O Remote Protocol Extension
0ce1b118
CV
41362@cindex File-I/O remote protocol extension
41363
41364@menu
41365* File-I/O Overview::
79a6e687
BW
41366* Protocol Basics::
41367* The F Request Packet::
41368* The F Reply Packet::
41369* The Ctrl-C Message::
0ce1b118 41370* Console I/O::
79a6e687 41371* List of Supported Calls::
db2e3e2e 41372* Protocol-specific Representation of Datatypes::
0ce1b118
CV
41373* Constants::
41374* File-I/O Examples::
41375@end menu
41376
41377@node File-I/O Overview
41378@subsection File-I/O Overview
41379@cindex file-i/o overview
41380
9c16f35a 41381The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
fc320d37 41382target to use the host's file system and console I/O to perform various
0ce1b118 41383system calls. System calls on the target system are translated into a
fc320d37
SL
41384remote protocol packet to the host system, which then performs the needed
41385actions and returns a response packet to the target system.
0ce1b118
CV
41386This simulates file system operations even on targets that lack file systems.
41387
fc320d37
SL
41388The protocol is defined to be independent of both the host and target systems.
41389It uses its own internal representation of datatypes and values. Both
0ce1b118 41390@value{GDBN} and the target's @value{GDBN} stub are responsible for
fc320d37
SL
41391translating the system-dependent value representations into the internal
41392protocol representations when data is transmitted.
0ce1b118 41393
fc320d37
SL
41394The communication is synchronous. A system call is possible only when
41395@value{GDBN} is waiting for a response from the @samp{C}, @samp{c}, @samp{S}
41396or @samp{s} packets. While @value{GDBN} handles the request for a system call,
0ce1b118 41397the target is stopped to allow deterministic access to the target's
fc320d37
SL
41398memory. Therefore File-I/O is not interruptible by target signals. On
41399the other hand, it is possible to interrupt File-I/O by a user interrupt
c8aa23ab 41400(@samp{Ctrl-C}) within @value{GDBN}.
0ce1b118
CV
41401
41402The target's request to perform a host system call does not finish
41403the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
41404after finishing the system call, the target returns to continuing the
41405previous activity (continue, step). No additional continue or step
41406request from @value{GDBN} is required.
41407
41408@smallexample
f7dc1244 41409(@value{GDBP}) continue
0ce1b118
CV
41410 <- target requests 'system call X'
41411 target is stopped, @value{GDBN} executes system call
3f94c067
BW
41412 -> @value{GDBN} returns result
41413 ... target continues, @value{GDBN} returns to wait for the target
0ce1b118
CV
41414 <- target hits breakpoint and sends a Txx packet
41415@end smallexample
41416
fc320d37
SL
41417The protocol only supports I/O on the console and to regular files on
41418the host file system. Character or block special devices, pipes,
41419named pipes, sockets or any other communication method on the host
0ce1b118
CV
41420system are not supported by this protocol.
41421
8b23ecc4
SL
41422File I/O is not supported in non-stop mode.
41423
79a6e687
BW
41424@node Protocol Basics
41425@subsection Protocol Basics
0ce1b118
CV
41426@cindex protocol basics, file-i/o
41427
fc320d37
SL
41428The File-I/O protocol uses the @code{F} packet as the request as well
41429as reply packet. Since a File-I/O system call can only occur when
41430@value{GDBN} is waiting for a response from the continuing or stepping target,
41431the File-I/O request is a reply that @value{GDBN} has to expect as a result
41432of a previous @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
0ce1b118
CV
41433This @code{F} packet contains all information needed to allow @value{GDBN}
41434to call the appropriate host system call:
41435
41436@itemize @bullet
b383017d 41437@item
0ce1b118
CV
41438A unique identifier for the requested system call.
41439
41440@item
41441All parameters to the system call. Pointers are given as addresses
41442in the target memory address space. Pointers to strings are given as
b383017d 41443pointer/length pair. Numerical values are given as they are.
db2e3e2e 41444Numerical control flags are given in a protocol-specific representation.
0ce1b118
CV
41445
41446@end itemize
41447
fc320d37 41448At this point, @value{GDBN} has to perform the following actions.
0ce1b118
CV
41449
41450@itemize @bullet
b383017d 41451@item
fc320d37
SL
41452If the parameters include pointer values to data needed as input to a
41453system call, @value{GDBN} requests this data from the target with a
0ce1b118
CV
41454standard @code{m} packet request. This additional communication has to be
41455expected by the target implementation and is handled as any other @code{m}
41456packet.
41457
41458@item
41459@value{GDBN} translates all value from protocol representation to host
41460representation as needed. Datatypes are coerced into the host types.
41461
41462@item
fc320d37 41463@value{GDBN} calls the system call.
0ce1b118
CV
41464
41465@item
41466It then coerces datatypes back to protocol representation.
41467
41468@item
fc320d37
SL
41469If the system call is expected to return data in buffer space specified
41470by pointer parameters to the call, the data is transmitted to the
0ce1b118
CV
41471target using a @code{M} or @code{X} packet. This packet has to be expected
41472by the target implementation and is handled as any other @code{M} or @code{X}
41473packet.
41474
41475@end itemize
41476
41477Eventually @value{GDBN} replies with another @code{F} packet which contains all
41478necessary information for the target to continue. This at least contains
41479
41480@itemize @bullet
41481@item
41482Return value.
41483
41484@item
41485@code{errno}, if has been changed by the system call.
41486
41487@item
41488``Ctrl-C'' flag.
41489
41490@end itemize
41491
41492After having done the needed type and value coercion, the target continues
41493the latest continue or step action.
41494
79a6e687
BW
41495@node The F Request Packet
41496@subsection The @code{F} Request Packet
0ce1b118
CV
41497@cindex file-i/o request packet
41498@cindex @code{F} request packet
41499
41500The @code{F} request packet has the following format:
41501
41502@table @samp
fc320d37 41503@item F@var{call-id},@var{parameter@dots{}}
0ce1b118
CV
41504
41505@var{call-id} is the identifier to indicate the host system call to be called.
41506This is just the name of the function.
41507
fc320d37
SL
41508@var{parameter@dots{}} are the parameters to the system call.
41509Parameters are hexadecimal integer values, either the actual values in case
41510of scalar datatypes, pointers to target buffer space in case of compound
41511datatypes and unspecified memory areas, or pointer/length pairs in case
41512of string parameters. These are appended to the @var{call-id} as a
41513comma-delimited list. All values are transmitted in ASCII
41514string representation, pointer/length pairs separated by a slash.
0ce1b118 41515
b383017d 41516@end table
0ce1b118 41517
fc320d37 41518
0ce1b118 41519
79a6e687
BW
41520@node The F Reply Packet
41521@subsection The @code{F} Reply Packet
0ce1b118
CV
41522@cindex file-i/o reply packet
41523@cindex @code{F} reply packet
41524
41525The @code{F} reply packet has the following format:
41526
41527@table @samp
41528
d3bdde98 41529@item F@var{retcode},@var{errno},@var{Ctrl-C flag};@var{call-specific attachment}
0ce1b118
CV
41530
41531@var{retcode} is the return code of the system call as hexadecimal value.
41532
db2e3e2e
BW
41533@var{errno} is the @code{errno} set by the call, in protocol-specific
41534representation.
0ce1b118
CV
41535This parameter can be omitted if the call was successful.
41536
fc320d37
SL
41537@var{Ctrl-C flag} is only sent if the user requested a break. In this
41538case, @var{errno} must be sent as well, even if the call was successful.
41539The @var{Ctrl-C flag} itself consists of the character @samp{C}:
0ce1b118
CV
41540
41541@smallexample
41542F0,0,C
41543@end smallexample
41544
41545@noindent
fc320d37 41546or, if the call was interrupted before the host call has been performed:
0ce1b118
CV
41547
41548@smallexample
41549F-1,4,C
41550@end smallexample
41551
41552@noindent
db2e3e2e 41553assuming 4 is the protocol-specific representation of @code{EINTR}.
0ce1b118
CV
41554
41555@end table
41556
0ce1b118 41557
79a6e687
BW
41558@node The Ctrl-C Message
41559@subsection The @samp{Ctrl-C} Message
0ce1b118
CV
41560@cindex ctrl-c message, in file-i/o protocol
41561
c8aa23ab 41562If the @samp{Ctrl-C} flag is set in the @value{GDBN}
79a6e687 41563reply packet (@pxref{The F Reply Packet}),
fc320d37 41564the target should behave as if it had
0ce1b118 41565gotten a break message. The meaning for the target is ``system call
fc320d37 41566interrupted by @code{SIGINT}''. Consequentially, the target should actually stop
0ce1b118 41567(as with a break message) and return to @value{GDBN} with a @code{T02}
c8aa23ab 41568packet.
fc320d37
SL
41569
41570It's important for the target to know in which
41571state the system call was interrupted. There are two possible cases:
0ce1b118
CV
41572
41573@itemize @bullet
41574@item
41575The system call hasn't been performed on the host yet.
41576
41577@item
41578The system call on the host has been finished.
41579
41580@end itemize
41581
41582These two states can be distinguished by the target by the value of the
41583returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
41584call hasn't been performed. This is equivalent to the @code{EINTR} handling
41585on POSIX systems. In any other case, the target may presume that the
fc320d37 41586system call has been finished --- successfully or not --- and should behave
0ce1b118
CV
41587as if the break message arrived right after the system call.
41588
fc320d37 41589@value{GDBN} must behave reliably. If the system call has not been called
0ce1b118
CV
41590yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
41591@code{errno} in the packet. If the system call on the host has been finished
fc320d37
SL
41592before the user requests a break, the full action must be finished by
41593@value{GDBN}. This requires sending @code{M} or @code{X} packets as necessary.
41594The @code{F} packet may only be sent when either nothing has happened
0ce1b118
CV
41595or the full action has been completed.
41596
41597@node Console I/O
41598@subsection Console I/O
41599@cindex console i/o as part of file-i/o
41600
d3e8051b 41601By default and if not explicitly closed by the target system, the file
0ce1b118
CV
41602descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
41603on the @value{GDBN} console is handled as any other file output operation
41604(@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
41605by @value{GDBN} so that after the target read request from file descriptor
416060 all following typing is buffered until either one of the following
41607conditions is met:
41608
41609@itemize @bullet
41610@item
c8aa23ab 41611The user types @kbd{Ctrl-c}. The behaviour is as explained above, and the
0ce1b118
CV
41612@code{read}
41613system call is treated as finished.
41614
41615@item
7f9087cb 41616The user presses @key{RET}. This is treated as end of input with a trailing
fc320d37 41617newline.
0ce1b118
CV
41618
41619@item
c8aa23ab
EZ
41620The user types @kbd{Ctrl-d}. This is treated as end of input. No trailing
41621character (neither newline nor @samp{Ctrl-D}) is appended to the input.
0ce1b118
CV
41622
41623@end itemize
41624
fc320d37
SL
41625If the user has typed more characters than fit in the buffer given to
41626the @code{read} call, the trailing characters are buffered in @value{GDBN} until
41627either another @code{read(0, @dots{})} is requested by the target, or debugging
41628is stopped at the user's request.
0ce1b118 41629
0ce1b118 41630
79a6e687
BW
41631@node List of Supported Calls
41632@subsection List of Supported Calls
0ce1b118
CV
41633@cindex list of supported file-i/o calls
41634
41635@menu
41636* open::
41637* close::
41638* read::
41639* write::
41640* lseek::
41641* rename::
41642* unlink::
41643* stat/fstat::
41644* gettimeofday::
41645* isatty::
41646* system::
41647@end menu
41648
41649@node open
41650@unnumberedsubsubsec open
41651@cindex open, file-i/o system call
41652
fc320d37
SL
41653@table @asis
41654@item Synopsis:
0ce1b118 41655@smallexample
0ce1b118
CV
41656int open(const char *pathname, int flags);
41657int open(const char *pathname, int flags, mode_t mode);
0ce1b118
CV
41658@end smallexample
41659
fc320d37
SL
41660@item Request:
41661@samp{Fopen,@var{pathptr}/@var{len},@var{flags},@var{mode}}
41662
0ce1b118 41663@noindent
fc320d37 41664@var{flags} is the bitwise @code{OR} of the following values:
0ce1b118
CV
41665
41666@table @code
b383017d 41667@item O_CREAT
0ce1b118
CV
41668If the file does not exist it will be created. The host
41669rules apply as far as file ownership and time stamps
41670are concerned.
41671
b383017d 41672@item O_EXCL
fc320d37 41673When used with @code{O_CREAT}, if the file already exists it is
0ce1b118
CV
41674an error and open() fails.
41675
b383017d 41676@item O_TRUNC
0ce1b118 41677If the file already exists and the open mode allows
fc320d37
SL
41678writing (@code{O_RDWR} or @code{O_WRONLY} is given) it will be
41679truncated to zero length.
0ce1b118 41680
b383017d 41681@item O_APPEND
0ce1b118
CV
41682The file is opened in append mode.
41683
b383017d 41684@item O_RDONLY
0ce1b118
CV
41685The file is opened for reading only.
41686
b383017d 41687@item O_WRONLY
0ce1b118
CV
41688The file is opened for writing only.
41689
b383017d 41690@item O_RDWR
0ce1b118 41691The file is opened for reading and writing.
fc320d37 41692@end table
0ce1b118
CV
41693
41694@noindent
fc320d37 41695Other bits are silently ignored.
0ce1b118 41696
0ce1b118
CV
41697
41698@noindent
fc320d37 41699@var{mode} is the bitwise @code{OR} of the following values:
0ce1b118
CV
41700
41701@table @code
b383017d 41702@item S_IRUSR
0ce1b118
CV
41703User has read permission.
41704
b383017d 41705@item S_IWUSR
0ce1b118
CV
41706User has write permission.
41707
b383017d 41708@item S_IRGRP
0ce1b118
CV
41709Group has read permission.
41710
b383017d 41711@item S_IWGRP
0ce1b118
CV
41712Group has write permission.
41713
b383017d 41714@item S_IROTH
0ce1b118
CV
41715Others have read permission.
41716
b383017d 41717@item S_IWOTH
0ce1b118 41718Others have write permission.
fc320d37 41719@end table
0ce1b118
CV
41720
41721@noindent
fc320d37 41722Other bits are silently ignored.
0ce1b118 41723
0ce1b118 41724
fc320d37
SL
41725@item Return value:
41726@code{open} returns the new file descriptor or -1 if an error
41727occurred.
0ce1b118 41728
fc320d37 41729@item Errors:
0ce1b118
CV
41730
41731@table @code
b383017d 41732@item EEXIST
fc320d37 41733@var{pathname} already exists and @code{O_CREAT} and @code{O_EXCL} were used.
0ce1b118 41734
b383017d 41735@item EISDIR
fc320d37 41736@var{pathname} refers to a directory.
0ce1b118 41737
b383017d 41738@item EACCES
0ce1b118
CV
41739The requested access is not allowed.
41740
41741@item ENAMETOOLONG
fc320d37 41742@var{pathname} was too long.
0ce1b118 41743
b383017d 41744@item ENOENT
fc320d37 41745A directory component in @var{pathname} does not exist.
0ce1b118 41746
b383017d 41747@item ENODEV
fc320d37 41748@var{pathname} refers to a device, pipe, named pipe or socket.
0ce1b118 41749
b383017d 41750@item EROFS
fc320d37 41751@var{pathname} refers to a file on a read-only filesystem and
0ce1b118
CV
41752write access was requested.
41753
b383017d 41754@item EFAULT
fc320d37 41755@var{pathname} is an invalid pointer value.
0ce1b118 41756
b383017d 41757@item ENOSPC
0ce1b118
CV
41758No space on device to create the file.
41759
b383017d 41760@item EMFILE
0ce1b118
CV
41761The process already has the maximum number of files open.
41762
b383017d 41763@item ENFILE
0ce1b118
CV
41764The limit on the total number of files open on the system
41765has been reached.
41766
b383017d 41767@item EINTR
0ce1b118
CV
41768The call was interrupted by the user.
41769@end table
41770
fc320d37
SL
41771@end table
41772
0ce1b118
CV
41773@node close
41774@unnumberedsubsubsec close
41775@cindex close, file-i/o system call
41776
fc320d37
SL
41777@table @asis
41778@item Synopsis:
0ce1b118 41779@smallexample
0ce1b118 41780int close(int fd);
fc320d37 41781@end smallexample
0ce1b118 41782
fc320d37
SL
41783@item Request:
41784@samp{Fclose,@var{fd}}
0ce1b118 41785
fc320d37
SL
41786@item Return value:
41787@code{close} returns zero on success, or -1 if an error occurred.
0ce1b118 41788
fc320d37 41789@item Errors:
0ce1b118
CV
41790
41791@table @code
b383017d 41792@item EBADF
fc320d37 41793@var{fd} isn't a valid open file descriptor.
0ce1b118 41794
b383017d 41795@item EINTR
0ce1b118
CV
41796The call was interrupted by the user.
41797@end table
41798
fc320d37
SL
41799@end table
41800
0ce1b118
CV
41801@node read
41802@unnumberedsubsubsec read
41803@cindex read, file-i/o system call
41804
fc320d37
SL
41805@table @asis
41806@item Synopsis:
0ce1b118 41807@smallexample
0ce1b118 41808int read(int fd, void *buf, unsigned int count);
fc320d37 41809@end smallexample
0ce1b118 41810
fc320d37
SL
41811@item Request:
41812@samp{Fread,@var{fd},@var{bufptr},@var{count}}
0ce1b118 41813
fc320d37 41814@item Return value:
0ce1b118
CV
41815On success, the number of bytes read is returned.
41816Zero indicates end of file. If count is zero, read
b383017d 41817returns zero as well. On error, -1 is returned.
0ce1b118 41818
fc320d37 41819@item Errors:
0ce1b118
CV
41820
41821@table @code
b383017d 41822@item EBADF
fc320d37 41823@var{fd} is not a valid file descriptor or is not open for
0ce1b118
CV
41824reading.
41825
b383017d 41826@item EFAULT
fc320d37 41827@var{bufptr} is an invalid pointer value.
0ce1b118 41828
b383017d 41829@item EINTR
0ce1b118
CV
41830The call was interrupted by the user.
41831@end table
41832
fc320d37
SL
41833@end table
41834
0ce1b118
CV
41835@node write
41836@unnumberedsubsubsec write
41837@cindex write, file-i/o system call
41838
fc320d37
SL
41839@table @asis
41840@item Synopsis:
0ce1b118 41841@smallexample
0ce1b118 41842int write(int fd, const void *buf, unsigned int count);
fc320d37 41843@end smallexample
0ce1b118 41844
fc320d37
SL
41845@item Request:
41846@samp{Fwrite,@var{fd},@var{bufptr},@var{count}}
0ce1b118 41847
fc320d37 41848@item Return value:
0ce1b118
CV
41849On success, the number of bytes written are returned.
41850Zero indicates nothing was written. On error, -1
41851is returned.
41852
fc320d37 41853@item Errors:
0ce1b118
CV
41854
41855@table @code
b383017d 41856@item EBADF
fc320d37 41857@var{fd} is not a valid file descriptor or is not open for
0ce1b118
CV
41858writing.
41859
b383017d 41860@item EFAULT
fc320d37 41861@var{bufptr} is an invalid pointer value.
0ce1b118 41862
b383017d 41863@item EFBIG
0ce1b118 41864An attempt was made to write a file that exceeds the
db2e3e2e 41865host-specific maximum file size allowed.
0ce1b118 41866
b383017d 41867@item ENOSPC
0ce1b118
CV
41868No space on device to write the data.
41869
b383017d 41870@item EINTR
0ce1b118
CV
41871The call was interrupted by the user.
41872@end table
41873
fc320d37
SL
41874@end table
41875
0ce1b118
CV
41876@node lseek
41877@unnumberedsubsubsec lseek
41878@cindex lseek, file-i/o system call
41879
fc320d37
SL
41880@table @asis
41881@item Synopsis:
0ce1b118 41882@smallexample
0ce1b118 41883long lseek (int fd, long offset, int flag);
0ce1b118
CV
41884@end smallexample
41885
fc320d37
SL
41886@item Request:
41887@samp{Flseek,@var{fd},@var{offset},@var{flag}}
41888
41889@var{flag} is one of:
0ce1b118
CV
41890
41891@table @code
b383017d 41892@item SEEK_SET
fc320d37 41893The offset is set to @var{offset} bytes.
0ce1b118 41894
b383017d 41895@item SEEK_CUR
fc320d37 41896The offset is set to its current location plus @var{offset}
0ce1b118
CV
41897bytes.
41898
b383017d 41899@item SEEK_END
fc320d37 41900The offset is set to the size of the file plus @var{offset}
0ce1b118
CV
41901bytes.
41902@end table
41903
fc320d37 41904@item Return value:
0ce1b118
CV
41905On success, the resulting unsigned offset in bytes from
41906the beginning of the file is returned. Otherwise, a
41907value of -1 is returned.
41908
fc320d37 41909@item Errors:
0ce1b118
CV
41910
41911@table @code
b383017d 41912@item EBADF
fc320d37 41913@var{fd} is not a valid open file descriptor.
0ce1b118 41914
b383017d 41915@item ESPIPE
fc320d37 41916@var{fd} is associated with the @value{GDBN} console.
0ce1b118 41917
b383017d 41918@item EINVAL
fc320d37 41919@var{flag} is not a proper value.
0ce1b118 41920
b383017d 41921@item EINTR
0ce1b118
CV
41922The call was interrupted by the user.
41923@end table
41924
fc320d37
SL
41925@end table
41926
0ce1b118
CV
41927@node rename
41928@unnumberedsubsubsec rename
41929@cindex rename, file-i/o system call
41930
fc320d37
SL
41931@table @asis
41932@item Synopsis:
0ce1b118 41933@smallexample
0ce1b118 41934int rename(const char *oldpath, const char *newpath);
fc320d37 41935@end smallexample
0ce1b118 41936
fc320d37
SL
41937@item Request:
41938@samp{Frename,@var{oldpathptr}/@var{len},@var{newpathptr}/@var{len}}
0ce1b118 41939
fc320d37 41940@item Return value:
0ce1b118
CV
41941On success, zero is returned. On error, -1 is returned.
41942
fc320d37 41943@item Errors:
0ce1b118
CV
41944
41945@table @code
b383017d 41946@item EISDIR
fc320d37 41947@var{newpath} is an existing directory, but @var{oldpath} is not a
0ce1b118
CV
41948directory.
41949
b383017d 41950@item EEXIST
fc320d37 41951@var{newpath} is a non-empty directory.
0ce1b118 41952
b383017d 41953@item EBUSY
fc320d37 41954@var{oldpath} or @var{newpath} is a directory that is in use by some
0ce1b118
CV
41955process.
41956
b383017d 41957@item EINVAL
0ce1b118
CV
41958An attempt was made to make a directory a subdirectory
41959of itself.
41960
b383017d 41961@item ENOTDIR
fc320d37
SL
41962A component used as a directory in @var{oldpath} or new
41963path is not a directory. Or @var{oldpath} is a directory
41964and @var{newpath} exists but is not a directory.
0ce1b118 41965
b383017d 41966@item EFAULT
fc320d37 41967@var{oldpathptr} or @var{newpathptr} are invalid pointer values.
0ce1b118 41968
b383017d 41969@item EACCES
0ce1b118
CV
41970No access to the file or the path of the file.
41971
41972@item ENAMETOOLONG
b383017d 41973
fc320d37 41974@var{oldpath} or @var{newpath} was too long.
0ce1b118 41975
b383017d 41976@item ENOENT
fc320d37 41977A directory component in @var{oldpath} or @var{newpath} does not exist.
0ce1b118 41978
b383017d 41979@item EROFS
0ce1b118
CV
41980The file is on a read-only filesystem.
41981
b383017d 41982@item ENOSPC
0ce1b118
CV
41983The device containing the file has no room for the new
41984directory entry.
41985
b383017d 41986@item EINTR
0ce1b118
CV
41987The call was interrupted by the user.
41988@end table
41989
fc320d37
SL
41990@end table
41991
0ce1b118
CV
41992@node unlink
41993@unnumberedsubsubsec unlink
41994@cindex unlink, file-i/o system call
41995
fc320d37
SL
41996@table @asis
41997@item Synopsis:
0ce1b118 41998@smallexample
0ce1b118 41999int unlink(const char *pathname);
fc320d37 42000@end smallexample
0ce1b118 42001
fc320d37
SL
42002@item Request:
42003@samp{Funlink,@var{pathnameptr}/@var{len}}
0ce1b118 42004
fc320d37 42005@item Return value:
0ce1b118
CV
42006On success, zero is returned. On error, -1 is returned.
42007
fc320d37 42008@item Errors:
0ce1b118
CV
42009
42010@table @code
b383017d 42011@item EACCES
0ce1b118
CV
42012No access to the file or the path of the file.
42013
b383017d 42014@item EPERM
0ce1b118
CV
42015The system does not allow unlinking of directories.
42016
b383017d 42017@item EBUSY
fc320d37 42018The file @var{pathname} cannot be unlinked because it's
0ce1b118
CV
42019being used by another process.
42020
b383017d 42021@item EFAULT
fc320d37 42022@var{pathnameptr} is an invalid pointer value.
0ce1b118
CV
42023
42024@item ENAMETOOLONG
fc320d37 42025@var{pathname} was too long.
0ce1b118 42026
b383017d 42027@item ENOENT
fc320d37 42028A directory component in @var{pathname} does not exist.
0ce1b118 42029
b383017d 42030@item ENOTDIR
0ce1b118
CV
42031A component of the path is not a directory.
42032
b383017d 42033@item EROFS
0ce1b118
CV
42034The file is on a read-only filesystem.
42035
b383017d 42036@item EINTR
0ce1b118
CV
42037The call was interrupted by the user.
42038@end table
42039
fc320d37
SL
42040@end table
42041
0ce1b118
CV
42042@node stat/fstat
42043@unnumberedsubsubsec stat/fstat
42044@cindex fstat, file-i/o system call
42045@cindex stat, file-i/o system call
42046
fc320d37
SL
42047@table @asis
42048@item Synopsis:
0ce1b118 42049@smallexample
0ce1b118
CV
42050int stat(const char *pathname, struct stat *buf);
42051int fstat(int fd, struct stat *buf);
fc320d37 42052@end smallexample
0ce1b118 42053
fc320d37
SL
42054@item Request:
42055@samp{Fstat,@var{pathnameptr}/@var{len},@var{bufptr}}@*
42056@samp{Ffstat,@var{fd},@var{bufptr}}
0ce1b118 42057
fc320d37 42058@item Return value:
0ce1b118
CV
42059On success, zero is returned. On error, -1 is returned.
42060
fc320d37 42061@item Errors:
0ce1b118
CV
42062
42063@table @code
b383017d 42064@item EBADF
fc320d37 42065@var{fd} is not a valid open file.
0ce1b118 42066
b383017d 42067@item ENOENT
fc320d37 42068A directory component in @var{pathname} does not exist or the
0ce1b118
CV
42069path is an empty string.
42070
b383017d 42071@item ENOTDIR
0ce1b118
CV
42072A component of the path is not a directory.
42073
b383017d 42074@item EFAULT
fc320d37 42075@var{pathnameptr} is an invalid pointer value.
0ce1b118 42076
b383017d 42077@item EACCES
0ce1b118
CV
42078No access to the file or the path of the file.
42079
42080@item ENAMETOOLONG
fc320d37 42081@var{pathname} was too long.
0ce1b118 42082
b383017d 42083@item EINTR
0ce1b118
CV
42084The call was interrupted by the user.
42085@end table
42086
fc320d37
SL
42087@end table
42088
0ce1b118
CV
42089@node gettimeofday
42090@unnumberedsubsubsec gettimeofday
42091@cindex gettimeofday, file-i/o system call
42092
fc320d37
SL
42093@table @asis
42094@item Synopsis:
0ce1b118 42095@smallexample
0ce1b118 42096int gettimeofday(struct timeval *tv, void *tz);
fc320d37 42097@end smallexample
0ce1b118 42098
fc320d37
SL
42099@item Request:
42100@samp{Fgettimeofday,@var{tvptr},@var{tzptr}}
0ce1b118 42101
fc320d37 42102@item Return value:
0ce1b118
CV
42103On success, 0 is returned, -1 otherwise.
42104
fc320d37 42105@item Errors:
0ce1b118
CV
42106
42107@table @code
b383017d 42108@item EINVAL
fc320d37 42109@var{tz} is a non-NULL pointer.
0ce1b118 42110
b383017d 42111@item EFAULT
fc320d37
SL
42112@var{tvptr} and/or @var{tzptr} is an invalid pointer value.
42113@end table
42114
0ce1b118
CV
42115@end table
42116
42117@node isatty
42118@unnumberedsubsubsec isatty
42119@cindex isatty, file-i/o system call
42120
fc320d37
SL
42121@table @asis
42122@item Synopsis:
0ce1b118 42123@smallexample
0ce1b118 42124int isatty(int fd);
fc320d37 42125@end smallexample
0ce1b118 42126
fc320d37
SL
42127@item Request:
42128@samp{Fisatty,@var{fd}}
0ce1b118 42129
fc320d37
SL
42130@item Return value:
42131Returns 1 if @var{fd} refers to the @value{GDBN} console, 0 otherwise.
0ce1b118 42132
fc320d37 42133@item Errors:
0ce1b118
CV
42134
42135@table @code
b383017d 42136@item EINTR
0ce1b118
CV
42137The call was interrupted by the user.
42138@end table
42139
fc320d37
SL
42140@end table
42141
42142Note that the @code{isatty} call is treated as a special case: it returns
421431 to the target if the file descriptor is attached
42144to the @value{GDBN} console, 0 otherwise. Implementing through system calls
42145would require implementing @code{ioctl} and would be more complex than
42146needed.
42147
42148
0ce1b118
CV
42149@node system
42150@unnumberedsubsubsec system
42151@cindex system, file-i/o system call
42152
fc320d37
SL
42153@table @asis
42154@item Synopsis:
0ce1b118 42155@smallexample
0ce1b118 42156int system(const char *command);
fc320d37 42157@end smallexample
0ce1b118 42158
fc320d37
SL
42159@item Request:
42160@samp{Fsystem,@var{commandptr}/@var{len}}
0ce1b118 42161
fc320d37 42162@item Return value:
5600ea19
NS
42163If @var{len} is zero, the return value indicates whether a shell is
42164available. A zero return value indicates a shell is not available.
42165For non-zero @var{len}, the value returned is -1 on error and the
42166return status of the command otherwise. Only the exit status of the
42167command is returned, which is extracted from the host's @code{system}
42168return value by calling @code{WEXITSTATUS(retval)}. In case
42169@file{/bin/sh} could not be executed, 127 is returned.
0ce1b118 42170
fc320d37 42171@item Errors:
0ce1b118
CV
42172
42173@table @code
b383017d 42174@item EINTR
0ce1b118
CV
42175The call was interrupted by the user.
42176@end table
42177
fc320d37
SL
42178@end table
42179
42180@value{GDBN} takes over the full task of calling the necessary host calls
42181to perform the @code{system} call. The return value of @code{system} on
42182the host is simplified before it's returned
42183to the target. Any termination signal information from the child process
42184is discarded, and the return value consists
42185entirely of the exit status of the called command.
42186
42187Due to security concerns, the @code{system} call is by default refused
42188by @value{GDBN}. The user has to allow this call explicitly with the
42189@code{set remote system-call-allowed 1} command.
42190
42191@table @code
42192@item set remote system-call-allowed
42193@kindex set remote system-call-allowed
42194Control whether to allow the @code{system} calls in the File I/O
42195protocol for the remote target. The default is zero (disabled).
42196
42197@item show remote system-call-allowed
42198@kindex show remote system-call-allowed
42199Show whether the @code{system} calls are allowed in the File I/O
42200protocol.
42201@end table
42202
db2e3e2e
BW
42203@node Protocol-specific Representation of Datatypes
42204@subsection Protocol-specific Representation of Datatypes
42205@cindex protocol-specific representation of datatypes, in file-i/o protocol
0ce1b118
CV
42206
42207@menu
79a6e687
BW
42208* Integral Datatypes::
42209* Pointer Values::
42210* Memory Transfer::
0ce1b118
CV
42211* struct stat::
42212* struct timeval::
42213@end menu
42214
79a6e687
BW
42215@node Integral Datatypes
42216@unnumberedsubsubsec Integral Datatypes
0ce1b118
CV
42217@cindex integral datatypes, in file-i/o protocol
42218
fc320d37
SL
42219The integral datatypes used in the system calls are @code{int},
42220@code{unsigned int}, @code{long}, @code{unsigned long},
42221@code{mode_t}, and @code{time_t}.
0ce1b118 42222
fc320d37 42223@code{int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
0ce1b118
CV
42224implemented as 32 bit values in this protocol.
42225
fc320d37 42226@code{long} and @code{unsigned long} are implemented as 64 bit types.
b383017d 42227
0ce1b118
CV
42228@xref{Limits}, for corresponding MIN and MAX values (similar to those
42229in @file{limits.h}) to allow range checking on host and target.
42230
42231@code{time_t} datatypes are defined as seconds since the Epoch.
42232
42233All integral datatypes transferred as part of a memory read or write of a
42234structured datatype e.g.@: a @code{struct stat} have to be given in big endian
42235byte order.
42236
79a6e687
BW
42237@node Pointer Values
42238@unnumberedsubsubsec Pointer Values
0ce1b118
CV
42239@cindex pointer values, in file-i/o protocol
42240
42241Pointers to target data are transmitted as they are. An exception
42242is made for pointers to buffers for which the length isn't
42243transmitted as part of the function call, namely strings. Strings
42244are transmitted as a pointer/length pair, both as hex values, e.g.@:
42245
42246@smallexample
42247@code{1aaf/12}
42248@end smallexample
42249
42250@noindent
42251which is a pointer to data of length 18 bytes at position 0x1aaf.
42252The length is defined as the full string length in bytes, including
fc320d37
SL
42253the trailing null byte. For example, the string @code{"hello world"}
42254at address 0x123456 is transmitted as
0ce1b118
CV
42255
42256@smallexample
fc320d37 42257@code{123456/d}
0ce1b118
CV
42258@end smallexample
42259
79a6e687
BW
42260@node Memory Transfer
42261@unnumberedsubsubsec Memory Transfer
fc320d37
SL
42262@cindex memory transfer, in file-i/o protocol
42263
42264Structured data which is transferred using a memory read or write (for
db2e3e2e 42265example, a @code{struct stat}) is expected to be in a protocol-specific format
fc320d37
SL
42266with all scalar multibyte datatypes being big endian. Translation to
42267this representation needs to be done both by the target before the @code{F}
42268packet is sent, and by @value{GDBN} before
42269it transfers memory to the target. Transferred pointers to structured
42270data should point to the already-coerced data at any time.
0ce1b118 42271
0ce1b118
CV
42272
42273@node struct stat
42274@unnumberedsubsubsec struct stat
42275@cindex struct stat, in file-i/o protocol
42276
fc320d37
SL
42277The buffer of type @code{struct stat} used by the target and @value{GDBN}
42278is defined as follows:
0ce1b118
CV
42279
42280@smallexample
42281struct stat @{
42282 unsigned int st_dev; /* device */
42283 unsigned int st_ino; /* inode */
42284 mode_t st_mode; /* protection */
42285 unsigned int st_nlink; /* number of hard links */
42286 unsigned int st_uid; /* user ID of owner */
42287 unsigned int st_gid; /* group ID of owner */
42288 unsigned int st_rdev; /* device type (if inode device) */
42289 unsigned long st_size; /* total size, in bytes */
42290 unsigned long st_blksize; /* blocksize for filesystem I/O */
42291 unsigned long st_blocks; /* number of blocks allocated */
42292 time_t st_atime; /* time of last access */
42293 time_t st_mtime; /* time of last modification */
42294 time_t st_ctime; /* time of last change */
42295@};
42296@end smallexample
42297
fc320d37 42298The integral datatypes conform to the definitions given in the
79a6e687 42299appropriate section (see @ref{Integral Datatypes}, for details) so this
0ce1b118
CV
42300structure is of size 64 bytes.
42301
42302The values of several fields have a restricted meaning and/or
42303range of values.
42304
fc320d37 42305@table @code
0ce1b118 42306
fc320d37
SL
42307@item st_dev
42308A value of 0 represents a file, 1 the console.
0ce1b118 42309
fc320d37
SL
42310@item st_ino
42311No valid meaning for the target. Transmitted unchanged.
0ce1b118 42312
fc320d37
SL
42313@item st_mode
42314Valid mode bits are described in @ref{Constants}. Any other
42315bits have currently no meaning for the target.
0ce1b118 42316
fc320d37
SL
42317@item st_uid
42318@itemx st_gid
42319@itemx st_rdev
42320No valid meaning for the target. Transmitted unchanged.
0ce1b118 42321
fc320d37
SL
42322@item st_atime
42323@itemx st_mtime
42324@itemx st_ctime
42325These values have a host and file system dependent
42326accuracy. Especially on Windows hosts, the file system may not
42327support exact timing values.
42328@end table
0ce1b118 42329
fc320d37
SL
42330The target gets a @code{struct stat} of the above representation and is
42331responsible for coercing it to the target representation before
0ce1b118
CV
42332continuing.
42333
fc320d37
SL
42334Note that due to size differences between the host, target, and protocol
42335representations of @code{struct stat} members, these members could eventually
0ce1b118
CV
42336get truncated on the target.
42337
42338@node struct timeval
42339@unnumberedsubsubsec struct timeval
42340@cindex struct timeval, in file-i/o protocol
42341
fc320d37 42342The buffer of type @code{struct timeval} used by the File-I/O protocol
0ce1b118
CV
42343is defined as follows:
42344
42345@smallexample
b383017d 42346struct timeval @{
0ce1b118
CV
42347 time_t tv_sec; /* second */
42348 long tv_usec; /* microsecond */
42349@};
42350@end smallexample
42351
fc320d37 42352The integral datatypes conform to the definitions given in the
79a6e687 42353appropriate section (see @ref{Integral Datatypes}, for details) so this
0ce1b118
CV
42354structure is of size 8 bytes.
42355
42356@node Constants
42357@subsection Constants
42358@cindex constants, in file-i/o protocol
42359
42360The following values are used for the constants inside of the
fc320d37 42361protocol. @value{GDBN} and target are responsible for translating these
0ce1b118
CV
42362values before and after the call as needed.
42363
42364@menu
79a6e687
BW
42365* Open Flags::
42366* mode_t Values::
42367* Errno Values::
42368* Lseek Flags::
0ce1b118
CV
42369* Limits::
42370@end menu
42371
79a6e687
BW
42372@node Open Flags
42373@unnumberedsubsubsec Open Flags
0ce1b118
CV
42374@cindex open flags, in file-i/o protocol
42375
42376All values are given in hexadecimal representation.
42377
42378@smallexample
42379 O_RDONLY 0x0
42380 O_WRONLY 0x1
42381 O_RDWR 0x2
42382 O_APPEND 0x8
42383 O_CREAT 0x200
42384 O_TRUNC 0x400
42385 O_EXCL 0x800
42386@end smallexample
42387
79a6e687
BW
42388@node mode_t Values
42389@unnumberedsubsubsec mode_t Values
0ce1b118
CV
42390@cindex mode_t values, in file-i/o protocol
42391
42392All values are given in octal representation.
42393
42394@smallexample
42395 S_IFREG 0100000
42396 S_IFDIR 040000
42397 S_IRUSR 0400
42398 S_IWUSR 0200
42399 S_IXUSR 0100
42400 S_IRGRP 040
42401 S_IWGRP 020
42402 S_IXGRP 010
42403 S_IROTH 04
42404 S_IWOTH 02
42405 S_IXOTH 01
42406@end smallexample
42407
79a6e687
BW
42408@node Errno Values
42409@unnumberedsubsubsec Errno Values
0ce1b118
CV
42410@cindex errno values, in file-i/o protocol
42411
42412All values are given in decimal representation.
42413
42414@smallexample
42415 EPERM 1
42416 ENOENT 2
42417 EINTR 4
42418 EBADF 9
42419 EACCES 13
42420 EFAULT 14
42421 EBUSY 16
42422 EEXIST 17
42423 ENODEV 19
42424 ENOTDIR 20
42425 EISDIR 21
42426 EINVAL 22
42427 ENFILE 23
42428 EMFILE 24
42429 EFBIG 27
42430 ENOSPC 28
42431 ESPIPE 29
42432 EROFS 30
42433 ENAMETOOLONG 91
42434 EUNKNOWN 9999
42435@end smallexample
42436
fc320d37 42437 @code{EUNKNOWN} is used as a fallback error value if a host system returns
0ce1b118
CV
42438 any error value not in the list of supported error numbers.
42439
79a6e687
BW
42440@node Lseek Flags
42441@unnumberedsubsubsec Lseek Flags
0ce1b118
CV
42442@cindex lseek flags, in file-i/o protocol
42443
42444@smallexample
42445 SEEK_SET 0
42446 SEEK_CUR 1
42447 SEEK_END 2
42448@end smallexample
42449
42450@node Limits
42451@unnumberedsubsubsec Limits
42452@cindex limits, in file-i/o protocol
42453
42454All values are given in decimal representation.
42455
42456@smallexample
42457 INT_MIN -2147483648
42458 INT_MAX 2147483647
42459 UINT_MAX 4294967295
42460 LONG_MIN -9223372036854775808
42461 LONG_MAX 9223372036854775807
42462 ULONG_MAX 18446744073709551615
42463@end smallexample
42464
42465@node File-I/O Examples
42466@subsection File-I/O Examples
42467@cindex file-i/o examples
42468
42469Example sequence of a write call, file descriptor 3, buffer is at target
42470address 0x1234, 6 bytes should be written:
42471
42472@smallexample
42473<- @code{Fwrite,3,1234,6}
42474@emph{request memory read from target}
42475-> @code{m1234,6}
42476<- XXXXXX
42477@emph{return "6 bytes written"}
42478-> @code{F6}
42479@end smallexample
42480
42481Example sequence of a read call, file descriptor 3, buffer is at target
42482address 0x1234, 6 bytes should be read:
42483
42484@smallexample
42485<- @code{Fread,3,1234,6}
42486@emph{request memory write to target}
42487-> @code{X1234,6:XXXXXX}
42488@emph{return "6 bytes read"}
42489-> @code{F6}
42490@end smallexample
42491
42492Example sequence of a read call, call fails on the host due to invalid
fc320d37 42493file descriptor (@code{EBADF}):
0ce1b118
CV
42494
42495@smallexample
42496<- @code{Fread,3,1234,6}
42497-> @code{F-1,9}
42498@end smallexample
42499
c8aa23ab 42500Example sequence of a read call, user presses @kbd{Ctrl-c} before syscall on
0ce1b118
CV
42501host is called:
42502
42503@smallexample
42504<- @code{Fread,3,1234,6}
42505-> @code{F-1,4,C}
42506<- @code{T02}
42507@end smallexample
42508
c8aa23ab 42509Example sequence of a read call, user presses @kbd{Ctrl-c} after syscall on
0ce1b118
CV
42510host is called:
42511
42512@smallexample
42513<- @code{Fread,3,1234,6}
42514-> @code{X1234,6:XXXXXX}
42515<- @code{T02}
42516@end smallexample
42517
cfa9d6d9
DJ
42518@node Library List Format
42519@section Library List Format
42520@cindex library list format, remote protocol
42521
42522On some platforms, a dynamic loader (e.g.@: @file{ld.so}) runs in the
42523same process as your application to manage libraries. In this case,
42524@value{GDBN} can use the loader's symbol table and normal memory
42525operations to maintain a list of shared libraries. On other
42526platforms, the operating system manages loaded libraries.
42527@value{GDBN} can not retrieve the list of currently loaded libraries
42528through memory operations, so it uses the @samp{qXfer:libraries:read}
42529packet (@pxref{qXfer library list read}) instead. The remote stub
42530queries the target's operating system and reports which libraries
42531are loaded.
42532
42533The @samp{qXfer:libraries:read} packet returns an XML document which
42534lists loaded libraries and their offsets. Each library has an
1fddbabb
PA
42535associated name and one or more segment or section base addresses,
42536which report where the library was loaded in memory.
42537
42538For the common case of libraries that are fully linked binaries, the
42539library should have a list of segments. If the target supports
42540dynamic linking of a relocatable object file, its library XML element
42541should instead include a list of allocated sections. The segment or
42542section bases are start addresses, not relocation offsets; they do not
42543depend on the library's link-time base addresses.
cfa9d6d9 42544
9cceb671
DJ
42545@value{GDBN} must be linked with the Expat library to support XML
42546library lists. @xref{Expat}.
42547
cfa9d6d9
DJ
42548A simple memory map, with one loaded library relocated by a single
42549offset, looks like this:
42550
42551@smallexample
42552<library-list>
42553 <library name="/lib/libc.so.6">
42554 <segment address="0x10000000"/>
42555 </library>
42556</library-list>
42557@end smallexample
42558
1fddbabb
PA
42559Another simple memory map, with one loaded library with three
42560allocated sections (.text, .data, .bss), looks like this:
42561
42562@smallexample
42563<library-list>
42564 <library name="sharedlib.o">
42565 <section address="0x10000000"/>
42566 <section address="0x20000000"/>
42567 <section address="0x30000000"/>
42568 </library>
42569</library-list>
42570@end smallexample
42571
cfa9d6d9
DJ
42572The format of a library list is described by this DTD:
42573
42574@smallexample
42575<!-- library-list: Root element with versioning -->
42576<!ELEMENT library-list (library)*>
42577<!ATTLIST library-list version CDATA #FIXED "1.0">
1fddbabb 42578<!ELEMENT library (segment*, section*)>
cfa9d6d9
DJ
42579<!ATTLIST library name CDATA #REQUIRED>
42580<!ELEMENT segment EMPTY>
42581<!ATTLIST segment address CDATA #REQUIRED>
1fddbabb
PA
42582<!ELEMENT section EMPTY>
42583<!ATTLIST section address CDATA #REQUIRED>
cfa9d6d9
DJ
42584@end smallexample
42585
1fddbabb
PA
42586In addition, segments and section descriptors cannot be mixed within a
42587single library element, and you must supply at least one segment or
42588section for each library.
42589
2268b414
JK
42590@node Library List Format for SVR4 Targets
42591@section Library List Format for SVR4 Targets
42592@cindex library list format, remote protocol
42593
42594On SVR4 platforms @value{GDBN} can use the symbol table of a dynamic loader
42595(e.g.@: @file{ld.so}) and normal memory operations to maintain a list of
42596shared libraries. Still a special library list provided by this packet is
42597more efficient for the @value{GDBN} remote protocol.
42598
42599The @samp{qXfer:libraries-svr4:read} packet returns an XML document which lists
42600loaded libraries and their SVR4 linker parameters. For each library on SVR4
42601target, the following parameters are reported:
42602
42603@itemize @minus
42604@item
42605@code{name}, the absolute file name from the @code{l_name} field of
42606@code{struct link_map}.
42607@item
42608@code{lm} with address of @code{struct link_map} used for TLS
42609(Thread Local Storage) access.
42610@item
42611@code{l_addr}, the displacement as read from the field @code{l_addr} of
42612@code{struct link_map}. For prelinked libraries this is not an absolute
42613memory address. It is a displacement of absolute memory address against
42614address the file was prelinked to during the library load.
42615@item
42616@code{l_ld}, which is memory address of the @code{PT_DYNAMIC} segment
42617@end itemize
42618
42619Additionally the single @code{main-lm} attribute specifies address of
42620@code{struct link_map} used for the main executable. This parameter is used
42621for TLS access and its presence is optional.
42622
42623@value{GDBN} must be linked with the Expat library to support XML
42624SVR4 library lists. @xref{Expat}.
42625
42626A simple memory map, with two loaded libraries (which do not use prelink),
42627looks like this:
42628
42629@smallexample
42630<library-list-svr4 version="1.0" main-lm="0xe4f8f8">
42631 <library name="/lib/ld-linux.so.2" lm="0xe4f51c" l_addr="0xe2d000"
42632 l_ld="0xe4eefc"/>
42633 <library name="/lib/libc.so.6" lm="0xe4fbe8" l_addr="0x154000"
db1ff28b 42634 l_ld="0x152350"/>
2268b414
JK
42635</library-list-svr>
42636@end smallexample
42637
42638The format of an SVR4 library list is described by this DTD:
42639
42640@smallexample
42641<!-- library-list-svr4: Root element with versioning -->
42642<!ELEMENT library-list-svr4 (library)*>
db1ff28b
JK
42643<!ATTLIST library-list-svr4 version CDATA #FIXED "1.0">
42644<!ATTLIST library-list-svr4 main-lm CDATA #IMPLIED>
2268b414 42645<!ELEMENT library EMPTY>
db1ff28b
JK
42646<!ATTLIST library name CDATA #REQUIRED>
42647<!ATTLIST library lm CDATA #REQUIRED>
42648<!ATTLIST library l_addr CDATA #REQUIRED>
42649<!ATTLIST library l_ld CDATA #REQUIRED>
2268b414
JK
42650@end smallexample
42651
79a6e687
BW
42652@node Memory Map Format
42653@section Memory Map Format
68437a39
DJ
42654@cindex memory map format
42655
42656To be able to write into flash memory, @value{GDBN} needs to obtain a
42657memory map from the target. This section describes the format of the
42658memory map.
42659
42660The memory map is obtained using the @samp{qXfer:memory-map:read}
42661(@pxref{qXfer memory map read}) packet and is an XML document that
9cceb671
DJ
42662lists memory regions.
42663
42664@value{GDBN} must be linked with the Expat library to support XML
42665memory maps. @xref{Expat}.
42666
42667The top-level structure of the document is shown below:
68437a39
DJ
42668
42669@smallexample
42670<?xml version="1.0"?>
42671<!DOCTYPE memory-map
42672 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
42673 "http://sourceware.org/gdb/gdb-memory-map.dtd">
42674<memory-map>
42675 region...
42676</memory-map>
42677@end smallexample
42678
42679Each region can be either:
42680
42681@itemize
42682
42683@item
42684A region of RAM starting at @var{addr} and extending for @var{length}
42685bytes from there:
42686
42687@smallexample
42688<memory type="ram" start="@var{addr}" length="@var{length}"/>
42689@end smallexample
42690
42691
42692@item
42693A region of read-only memory:
42694
42695@smallexample
42696<memory type="rom" start="@var{addr}" length="@var{length}"/>
42697@end smallexample
42698
42699
42700@item
42701A region of flash memory, with erasure blocks @var{blocksize}
42702bytes in length:
42703
42704@smallexample
42705<memory type="flash" start="@var{addr}" length="@var{length}">
42706 <property name="blocksize">@var{blocksize}</property>
42707</memory>
42708@end smallexample
42709
42710@end itemize
42711
42712Regions must not overlap. @value{GDBN} assumes that areas of memory not covered
42713by the memory map are RAM, and uses the ordinary @samp{M} and @samp{X}
42714packets to write to addresses in such ranges.
42715
42716The formal DTD for memory map format is given below:
42717
42718@smallexample
42719<!-- ................................................... -->
42720<!-- Memory Map XML DTD ................................ -->
42721<!-- File: memory-map.dtd .............................. -->
42722<!-- .................................... .............. -->
42723<!-- memory-map.dtd -->
42724<!-- memory-map: Root element with versioning -->
5f1ca24a 42725<!ELEMENT memory-map (memory)*>
68437a39 42726<!ATTLIST memory-map version CDATA #FIXED "1.0.0">
5f1ca24a 42727<!ELEMENT memory (property)*>
68437a39
DJ
42728<!-- memory: Specifies a memory region,
42729 and its type, or device. -->
5f1ca24a 42730<!ATTLIST memory type (ram|rom|flash) #REQUIRED
68437a39 42731 start CDATA #REQUIRED
5f1ca24a 42732 length CDATA #REQUIRED>
68437a39
DJ
42733<!-- property: Generic attribute tag -->
42734<!ELEMENT property (#PCDATA | property)*>
5f1ca24a 42735<!ATTLIST property name (blocksize) #REQUIRED>
68437a39
DJ
42736@end smallexample
42737
dc146f7c
VP
42738@node Thread List Format
42739@section Thread List Format
42740@cindex thread list format
42741
42742To efficiently update the list of threads and their attributes,
42743@value{GDBN} issues the @samp{qXfer:threads:read} packet
42744(@pxref{qXfer threads read}) and obtains the XML document with
42745the following structure:
42746
42747@smallexample
42748<?xml version="1.0"?>
42749<threads>
79efa585 42750 <thread id="id" core="0" name="name">
dc146f7c
VP
42751 ... description ...
42752 </thread>
42753</threads>
42754@end smallexample
42755
42756Each @samp{thread} element must have the @samp{id} attribute that
42757identifies the thread (@pxref{thread-id syntax}). The
42758@samp{core} attribute, if present, specifies which processor core
79efa585
SM
42759the thread was last executing on. The @samp{name} attribute, if
42760present, specifies the human-readable name of the thread. The content
42761of the of @samp{thread} element is interpreted as human-readable
f2ff95c5
KB
42762auxiliary information. The @samp{handle} attribute, if present,
42763is a hex encoded representation of the thread handle.
42764
dc146f7c 42765
b3b9301e
PA
42766@node Traceframe Info Format
42767@section Traceframe Info Format
42768@cindex traceframe info format
42769
42770To be able to know which objects in the inferior can be examined when
42771inspecting a tracepoint hit, @value{GDBN} needs to obtain the list of
42772memory ranges, registers and trace state variables that have been
42773collected in a traceframe.
42774
42775This list is obtained using the @samp{qXfer:traceframe-info:read}
42776(@pxref{qXfer traceframe info read}) packet and is an XML document.
42777
42778@value{GDBN} must be linked with the Expat library to support XML
42779traceframe info discovery. @xref{Expat}.
42780
42781The top-level structure of the document is shown below:
42782
42783@smallexample
42784<?xml version="1.0"?>
42785<!DOCTYPE traceframe-info
42786 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
42787 "http://sourceware.org/gdb/gdb-traceframe-info.dtd">
42788<traceframe-info>
42789 block...
42790</traceframe-info>
42791@end smallexample
42792
42793Each traceframe block can be either:
42794
42795@itemize
42796
42797@item
42798A region of collected memory starting at @var{addr} and extending for
42799@var{length} bytes from there:
42800
42801@smallexample
42802<memory start="@var{addr}" length="@var{length}"/>
42803@end smallexample
42804
28a93511
YQ
42805@item
42806A block indicating trace state variable numbered @var{number} has been
42807collected:
42808
42809@smallexample
42810<tvar id="@var{number}"/>
42811@end smallexample
42812
b3b9301e
PA
42813@end itemize
42814
42815The formal DTD for the traceframe info format is given below:
42816
42817@smallexample
28a93511 42818<!ELEMENT traceframe-info (memory | tvar)* >
b3b9301e
PA
42819<!ATTLIST traceframe-info version CDATA #FIXED "1.0">
42820
42821<!ELEMENT memory EMPTY>
42822<!ATTLIST memory start CDATA #REQUIRED
42823 length CDATA #REQUIRED>
28a93511
YQ
42824<!ELEMENT tvar>
42825<!ATTLIST tvar id CDATA #REQUIRED>
b3b9301e
PA
42826@end smallexample
42827
2ae8c8e7
MM
42828@node Branch Trace Format
42829@section Branch Trace Format
42830@cindex branch trace format
42831
42832In order to display the branch trace of an inferior thread,
42833@value{GDBN} needs to obtain the list of branches. This list is
42834represented as list of sequential code blocks that are connected via
42835branches. The code in each block has been executed sequentially.
42836
42837This list is obtained using the @samp{qXfer:btrace:read}
42838(@pxref{qXfer btrace read}) packet and is an XML document.
42839
42840@value{GDBN} must be linked with the Expat library to support XML
42841traceframe info discovery. @xref{Expat}.
42842
42843The top-level structure of the document is shown below:
42844
42845@smallexample
42846<?xml version="1.0"?>
42847<!DOCTYPE btrace
42848 PUBLIC "+//IDN gnu.org//DTD GDB Branch Trace V1.0//EN"
42849 "http://sourceware.org/gdb/gdb-btrace.dtd">
42850<btrace>
42851 block...
42852</btrace>
42853@end smallexample
42854
42855@itemize
42856
42857@item
42858A block of sequentially executed instructions starting at @var{begin}
42859and ending at @var{end}:
42860
42861@smallexample
42862<block begin="@var{begin}" end="@var{end}"/>
42863@end smallexample
42864
42865@end itemize
42866
42867The formal DTD for the branch trace format is given below:
42868
42869@smallexample
b20a6524 42870<!ELEMENT btrace (block* | pt) >
2ae8c8e7
MM
42871<!ATTLIST btrace version CDATA #FIXED "1.0">
42872
42873<!ELEMENT block EMPTY>
42874<!ATTLIST block begin CDATA #REQUIRED
42875 end CDATA #REQUIRED>
b20a6524
MM
42876
42877<!ELEMENT pt (pt-config?, raw?)>
42878
42879<!ELEMENT pt-config (cpu?)>
42880
42881<!ELEMENT cpu EMPTY>
42882<!ATTLIST cpu vendor CDATA #REQUIRED
42883 family CDATA #REQUIRED
42884 model CDATA #REQUIRED
42885 stepping CDATA #REQUIRED>
42886
42887<!ELEMENT raw (#PCDATA)>
2ae8c8e7
MM
42888@end smallexample
42889
f4abbc16
MM
42890@node Branch Trace Configuration Format
42891@section Branch Trace Configuration Format
42892@cindex branch trace configuration format
42893
42894For each inferior thread, @value{GDBN} can obtain the branch trace
42895configuration using the @samp{qXfer:btrace-conf:read}
42896(@pxref{qXfer btrace-conf read}) packet.
42897
42898The configuration describes the branch trace format and configuration
d33501a5
MM
42899settings for that format. The following information is described:
42900
42901@table @code
42902@item bts
42903This thread uses the @dfn{Branch Trace Store} (@acronym{BTS}) format.
42904@table @code
42905@item size
42906The size of the @acronym{BTS} ring buffer in bytes.
42907@end table
b20a6524 42908@item pt
bc504a31 42909This thread uses the @dfn{Intel Processor Trace} (@acronym{Intel
b20a6524
MM
42910PT}) format.
42911@table @code
42912@item size
bc504a31 42913The size of the @acronym{Intel PT} ring buffer in bytes.
b20a6524 42914@end table
d33501a5 42915@end table
f4abbc16
MM
42916
42917@value{GDBN} must be linked with the Expat library to support XML
42918branch trace configuration discovery. @xref{Expat}.
42919
42920The formal DTD for the branch trace configuration format is given below:
42921
42922@smallexample
b20a6524 42923<!ELEMENT btrace-conf (bts?, pt?)>
f4abbc16
MM
42924<!ATTLIST btrace-conf version CDATA #FIXED "1.0">
42925
42926<!ELEMENT bts EMPTY>
d33501a5 42927<!ATTLIST bts size CDATA #IMPLIED>
b20a6524
MM
42928
42929<!ELEMENT pt EMPTY>
42930<!ATTLIST pt size CDATA #IMPLIED>
f4abbc16
MM
42931@end smallexample
42932
f418dd93
DJ
42933@include agentexpr.texi
42934
23181151
DJ
42935@node Target Descriptions
42936@appendix Target Descriptions
42937@cindex target descriptions
42938
23181151
DJ
42939One of the challenges of using @value{GDBN} to debug embedded systems
42940is that there are so many minor variants of each processor
42941architecture in use. It is common practice for vendors to start with
eb17f351 42942a standard processor core --- ARM, PowerPC, or @acronym{MIPS}, for example ---
23181151
DJ
42943and then make changes to adapt it to a particular market niche. Some
42944architectures have hundreds of variants, available from dozens of
42945vendors. This leads to a number of problems:
42946
42947@itemize @bullet
42948@item
42949With so many different customized processors, it is difficult for
42950the @value{GDBN} maintainers to keep up with the changes.
42951@item
42952Since individual variants may have short lifetimes or limited
42953audiences, it may not be worthwhile to carry information about every
42954variant in the @value{GDBN} source tree.
42955@item
42956When @value{GDBN} does support the architecture of the embedded system
42957at hand, the task of finding the correct architecture name to give the
42958@command{set architecture} command can be error-prone.
42959@end itemize
42960
42961To address these problems, the @value{GDBN} remote protocol allows a
42962target system to not only identify itself to @value{GDBN}, but to
42963actually describe its own features. This lets @value{GDBN} support
42964processor variants it has never seen before --- to the extent that the
42965descriptions are accurate, and that @value{GDBN} understands them.
42966
9cceb671
DJ
42967@value{GDBN} must be linked with the Expat library to support XML
42968target descriptions. @xref{Expat}.
123dc839 42969
23181151
DJ
42970@menu
42971* Retrieving Descriptions:: How descriptions are fetched from a target.
42972* Target Description Format:: The contents of a target description.
123dc839
DJ
42973* Predefined Target Types:: Standard types available for target
42974 descriptions.
81516450 42975* Enum Target Types:: How to define enum target types.
123dc839 42976* Standard Target Features:: Features @value{GDBN} knows about.
23181151
DJ
42977@end menu
42978
42979@node Retrieving Descriptions
42980@section Retrieving Descriptions
42981
42982Target descriptions can be read from the target automatically, or
42983specified by the user manually. The default behavior is to read the
42984description from the target. @value{GDBN} retrieves it via the remote
42985protocol using @samp{qXfer} requests (@pxref{General Query Packets,
42986qXfer}). The @var{annex} in the @samp{qXfer} packet will be
42987@samp{target.xml}. The contents of the @samp{target.xml} annex are an
42988XML document, of the form described in @ref{Target Description
42989Format}.
42990
42991Alternatively, you can specify a file to read for the target description.
42992If a file is set, the target will not be queried. The commands to
42993specify a file are:
42994
42995@table @code
42996@cindex set tdesc filename
42997@item set tdesc filename @var{path}
42998Read the target description from @var{path}.
42999
43000@cindex unset tdesc filename
43001@item unset tdesc filename
43002Do not read the XML target description from a file. @value{GDBN}
43003will use the description supplied by the current target.
43004
43005@cindex show tdesc filename
43006@item show tdesc filename
43007Show the filename to read for a target description, if any.
43008@end table
43009
43010
43011@node Target Description Format
43012@section Target Description Format
43013@cindex target descriptions, XML format
43014
43015A target description annex is an @uref{http://www.w3.org/XML/, XML}
43016document which complies with the Document Type Definition provided in
43017the @value{GDBN} sources in @file{gdb/features/gdb-target.dtd}. This
43018means you can use generally available tools like @command{xmllint} to
43019check that your feature descriptions are well-formed and valid.
43020However, to help people unfamiliar with XML write descriptions for
43021their targets, we also describe the grammar here.
43022
123dc839
DJ
43023Target descriptions can identify the architecture of the remote target
43024and (for some architectures) provide information about custom register
08d16641
PA
43025sets. They can also identify the OS ABI of the remote target.
43026@value{GDBN} can use this information to autoconfigure for your
123dc839 43027target, or to warn you if you connect to an unsupported target.
23181151
DJ
43028
43029Here is a simple target description:
43030
123dc839 43031@smallexample
1780a0ed 43032<target version="1.0">
23181151
DJ
43033 <architecture>i386:x86-64</architecture>
43034</target>
123dc839 43035@end smallexample
23181151
DJ
43036
43037@noindent
43038This minimal description only says that the target uses
43039the x86-64 architecture.
43040
123dc839
DJ
43041A target description has the following overall form, with [ ] marking
43042optional elements and @dots{} marking repeatable elements. The elements
43043are explained further below.
23181151 43044
123dc839 43045@smallexample
23181151
DJ
43046<?xml version="1.0"?>
43047<!DOCTYPE target SYSTEM "gdb-target.dtd">
1780a0ed 43048<target version="1.0">
123dc839 43049 @r{[}@var{architecture}@r{]}
08d16641 43050 @r{[}@var{osabi}@r{]}
e35359c5 43051 @r{[}@var{compatible}@r{]}
123dc839 43052 @r{[}@var{feature}@dots{}@r{]}
23181151 43053</target>
123dc839 43054@end smallexample
23181151
DJ
43055
43056@noindent
43057The description is generally insensitive to whitespace and line
43058breaks, under the usual common-sense rules. The XML version
43059declaration and document type declaration can generally be omitted
43060(@value{GDBN} does not require them), but specifying them may be
1780a0ed
DJ
43061useful for XML validation tools. The @samp{version} attribute for
43062@samp{<target>} may also be omitted, but we recommend
43063including it; if future versions of @value{GDBN} use an incompatible
43064revision of @file{gdb-target.dtd}, they will detect and report
43065the version mismatch.
23181151 43066
108546a0
DJ
43067@subsection Inclusion
43068@cindex target descriptions, inclusion
43069@cindex XInclude
43070@ifnotinfo
43071@cindex <xi:include>
43072@end ifnotinfo
43073
43074It can sometimes be valuable to split a target description up into
43075several different annexes, either for organizational purposes, or to
43076share files between different possible target descriptions. You can
43077divide a description into multiple files by replacing any element of
43078the target description with an inclusion directive of the form:
43079
123dc839 43080@smallexample
108546a0 43081<xi:include href="@var{document}"/>
123dc839 43082@end smallexample
108546a0
DJ
43083
43084@noindent
43085When @value{GDBN} encounters an element of this form, it will retrieve
43086the named XML @var{document}, and replace the inclusion directive with
43087the contents of that document. If the current description was read
43088using @samp{qXfer}, then so will be the included document;
43089@var{document} will be interpreted as the name of an annex. If the
43090current description was read from a file, @value{GDBN} will look for
43091@var{document} as a file in the same directory where it found the
43092original description.
43093
123dc839
DJ
43094@subsection Architecture
43095@cindex <architecture>
43096
43097An @samp{<architecture>} element has this form:
43098
43099@smallexample
43100 <architecture>@var{arch}</architecture>
43101@end smallexample
43102
e35359c5
UW
43103@var{arch} is one of the architectures from the set accepted by
43104@code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
123dc839 43105
08d16641
PA
43106@subsection OS ABI
43107@cindex @code{<osabi>}
43108
43109This optional field was introduced in @value{GDBN} version 7.0.
43110Previous versions of @value{GDBN} ignore it.
43111
43112An @samp{<osabi>} element has this form:
43113
43114@smallexample
43115 <osabi>@var{abi-name}</osabi>
43116@end smallexample
43117
43118@var{abi-name} is an OS ABI name from the same selection accepted by
43119@w{@code{set osabi}} (@pxref{ABI, ,Configuring the Current ABI}).
43120
e35359c5
UW
43121@subsection Compatible Architecture
43122@cindex @code{<compatible>}
43123
43124This optional field was introduced in @value{GDBN} version 7.0.
43125Previous versions of @value{GDBN} ignore it.
43126
43127A @samp{<compatible>} element has this form:
43128
43129@smallexample
43130 <compatible>@var{arch}</compatible>
43131@end smallexample
43132
43133@var{arch} is one of the architectures from the set accepted by
43134@code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
43135
43136A @samp{<compatible>} element is used to specify that the target
43137is able to run binaries in some other than the main target architecture
43138given by the @samp{<architecture>} element. For example, on the
43139Cell Broadband Engine, the main architecture is @code{powerpc:common}
43140or @code{powerpc:common64}, but the system is able to run binaries
43141in the @code{spu} architecture as well. The way to describe this
43142capability with @samp{<compatible>} is as follows:
43143
43144@smallexample
43145 <architecture>powerpc:common</architecture>
43146 <compatible>spu</compatible>
43147@end smallexample
43148
123dc839
DJ
43149@subsection Features
43150@cindex <feature>
43151
43152Each @samp{<feature>} describes some logical portion of the target
43153system. Features are currently used to describe available CPU
43154registers and the types of their contents. A @samp{<feature>} element
43155has this form:
43156
43157@smallexample
43158<feature name="@var{name}">
43159 @r{[}@var{type}@dots{}@r{]}
43160 @var{reg}@dots{}
43161</feature>
43162@end smallexample
43163
43164@noindent
43165Each feature's name should be unique within the description. The name
43166of a feature does not matter unless @value{GDBN} has some special
43167knowledge of the contents of that feature; if it does, the feature
43168should have its standard name. @xref{Standard Target Features}.
43169
43170@subsection Types
43171
43172Any register's value is a collection of bits which @value{GDBN} must
43173interpret. The default interpretation is a two's complement integer,
43174but other types can be requested by name in the register description.
43175Some predefined types are provided by @value{GDBN} (@pxref{Predefined
81516450
DE
43176Target Types}), and the description can define additional composite
43177and enum types.
123dc839
DJ
43178
43179Each type element must have an @samp{id} attribute, which gives
43180a unique (within the containing @samp{<feature>}) name to the type.
43181Types must be defined before they are used.
43182
43183@cindex <vector>
43184Some targets offer vector registers, which can be treated as arrays
43185of scalar elements. These types are written as @samp{<vector>} elements,
43186specifying the array element type, @var{type}, and the number of elements,
43187@var{count}:
43188
43189@smallexample
43190<vector id="@var{id}" type="@var{type}" count="@var{count}"/>
43191@end smallexample
43192
43193@cindex <union>
43194If a register's value is usefully viewed in multiple ways, define it
43195with a union type containing the useful representations. The
43196@samp{<union>} element contains one or more @samp{<field>} elements,
43197each of which has a @var{name} and a @var{type}:
43198
43199@smallexample
43200<union id="@var{id}">
43201 <field name="@var{name}" type="@var{type}"/>
43202 @dots{}
43203</union>
43204@end smallexample
43205
f5dff777 43206@cindex <struct>
81516450 43207@cindex <flags>
f5dff777 43208If a register's value is composed from several separate values, define
81516450
DE
43209it with either a structure type or a flags type.
43210A flags type may only contain bitfields.
43211A structure type may either contain only bitfields or contain no bitfields.
43212If the value contains only bitfields, its total size in bytes must be
43213specified.
43214
43215Non-bitfield values have a @var{name} and @var{type}.
f5dff777
DJ
43216
43217@smallexample
81516450
DE
43218<struct id="@var{id}">
43219 <field name="@var{name}" type="@var{type}"/>
f5dff777
DJ
43220 @dots{}
43221</struct>
43222@end smallexample
43223
81516450
DE
43224Both @var{name} and @var{type} values are required.
43225No implicit padding is added.
43226
43227Bitfield values have a @var{name}, @var{start}, @var{end} and @var{type}.
f5dff777
DJ
43228
43229@smallexample
81516450
DE
43230<struct id="@var{id}" size="@var{size}">
43231 <field name="@var{name}" start="@var{start}" end="@var{end}" type="@var{type}"/>
f5dff777
DJ
43232 @dots{}
43233</struct>
43234@end smallexample
43235
f5dff777
DJ
43236@smallexample
43237<flags id="@var{id}" size="@var{size}">
81516450 43238 <field name="@var{name}" start="@var{start}" end="@var{end}" type="@var{type}"/>
f5dff777
DJ
43239 @dots{}
43240</flags>
43241@end smallexample
43242
81516450
DE
43243The @var{name} value is required.
43244Bitfield values may be named with the empty string, @samp{""},
43245in which case the field is ``filler'' and its value is not printed.
43246Not all bits need to be specified, so ``filler'' fields are optional.
43247
ee8da4b8
DE
43248The @var{start} and @var{end} values are required, and @var{type}
43249is optional.
81516450
DE
43250The field's @var{start} must be less than or equal to its @var{end},
43251and zero represents the least significant bit.
81516450 43252
ee8da4b8
DE
43253The default value of @var{type} is @code{bool} for single bit fields,
43254and an unsigned integer otherwise.
81516450
DE
43255
43256Which to choose? Structures or flags?
43257
43258Registers defined with @samp{flags} have these advantages over
43259defining them with @samp{struct}:
43260
43261@itemize @bullet
43262@item
43263Arithmetic may be performed on them as if they were integers.
43264@item
43265They are printed in a more readable fashion.
43266@end itemize
43267
43268Registers defined with @samp{struct} have one advantage over
43269defining them with @samp{flags}:
43270
43271@itemize @bullet
43272@item
43273One can fetch individual fields like in @samp{C}.
43274
43275@smallexample
43276(gdb) print $my_struct_reg.field3
43277$1 = 42
43278@end smallexample
43279
43280@end itemize
43281
123dc839
DJ
43282@subsection Registers
43283@cindex <reg>
43284
43285Each register is represented as an element with this form:
43286
43287@smallexample
43288<reg name="@var{name}"
43289 bitsize="@var{size}"
43290 @r{[}regnum="@var{num}"@r{]}
43291 @r{[}save-restore="@var{save-restore}"@r{]}
43292 @r{[}type="@var{type}"@r{]}
43293 @r{[}group="@var{group}"@r{]}/>
43294@end smallexample
43295
43296@noindent
43297The components are as follows:
43298
43299@table @var
43300
43301@item name
43302The register's name; it must be unique within the target description.
43303
43304@item bitsize
43305The register's size, in bits.
43306
43307@item regnum
43308The register's number. If omitted, a register's number is one greater
43309than that of the previous register (either in the current feature or in
177b42fe 43310a preceding feature); the first register in the target description
123dc839
DJ
43311defaults to zero. This register number is used to read or write
43312the register; e.g.@: it is used in the remote @code{p} and @code{P}
43313packets, and registers appear in the @code{g} and @code{G} packets
43314in order of increasing register number.
43315
43316@item save-restore
43317Whether the register should be preserved across inferior function
43318calls; this must be either @code{yes} or @code{no}. The default is
43319@code{yes}, which is appropriate for most registers except for
43320some system control registers; this is not related to the target's
43321ABI.
43322
43323@item type
697aa1b7 43324The type of the register. It may be a predefined type, a type
123dc839
DJ
43325defined in the current feature, or one of the special types @code{int}
43326and @code{float}. @code{int} is an integer type of the correct size
43327for @var{bitsize}, and @code{float} is a floating point type (in the
43328architecture's normal floating point format) of the correct size for
43329@var{bitsize}. The default is @code{int}.
43330
43331@item group
cef0f868
SH
43332The register group to which this register belongs. It can be one of the
43333standard register groups @code{general}, @code{float}, @code{vector} or an
43334arbitrary string. Group names should be limited to alphanumeric characters.
43335If a group name is made up of multiple words the words may be separated by
43336hyphens; e.g.@: @code{special-group} or @code{ultra-special-group}. If no
43337@var{group} is specified, @value{GDBN} will not display the register in
43338@code{info registers}.
123dc839
DJ
43339
43340@end table
43341
43342@node Predefined Target Types
43343@section Predefined Target Types
43344@cindex target descriptions, predefined types
43345
43346Type definitions in the self-description can build up composite types
43347from basic building blocks, but can not define fundamental types. Instead,
43348standard identifiers are provided by @value{GDBN} for the fundamental
43349types. The currently supported types are:
43350
43351@table @code
43352
81516450
DE
43353@item bool
43354Boolean type, occupying a single bit.
43355
123dc839
DJ
43356@item int8
43357@itemx int16
d1908f2d 43358@itemx int24
123dc839
DJ
43359@itemx int32
43360@itemx int64
7cc46491 43361@itemx int128
123dc839
DJ
43362Signed integer types holding the specified number of bits.
43363
43364@item uint8
43365@itemx uint16
d1908f2d 43366@itemx uint24
123dc839
DJ
43367@itemx uint32
43368@itemx uint64
7cc46491 43369@itemx uint128
123dc839
DJ
43370Unsigned integer types holding the specified number of bits.
43371
43372@item code_ptr
43373@itemx data_ptr
43374Pointers to unspecified code and data. The program counter and
43375any dedicated return address register may be marked as code
43376pointers; printing a code pointer converts it into a symbolic
43377address. The stack pointer and any dedicated address registers
43378may be marked as data pointers.
43379
6e3bbd1a
PB
43380@item ieee_single
43381Single precision IEEE floating point.
43382
43383@item ieee_double
43384Double precision IEEE floating point.
43385
123dc839
DJ
43386@item arm_fpa_ext
43387The 12-byte extended precision format used by ARM FPA registers.
43388
075b51b7
L
43389@item i387_ext
43390The 10-byte extended precision format used by x87 registers.
43391
43392@item i386_eflags
4339332bit @sc{eflags} register used by x86.
43394
43395@item i386_mxcsr
4339632bit @sc{mxcsr} register used by x86.
43397
123dc839
DJ
43398@end table
43399
81516450
DE
43400@node Enum Target Types
43401@section Enum Target Types
43402@cindex target descriptions, enum types
43403
43404Enum target types are useful in @samp{struct} and @samp{flags}
43405register descriptions. @xref{Target Description Format}.
43406
43407Enum types have a name, size and a list of name/value pairs.
43408
43409@smallexample
43410<enum id="@var{id}" size="@var{size}">
43411 <evalue name="@var{name}" value="@var{value}"/>
43412 @dots{}
43413</enum>
43414@end smallexample
43415
43416Enums must be defined before they are used.
43417
43418@smallexample
43419<enum id="levels_type" size="4">
43420 <evalue name="low" value="0"/>
43421 <evalue name="high" value="1"/>
43422</enum>
43423<flags id="flags_type" size="4">
43424 <field name="X" start="0"/>
43425 <field name="LEVEL" start="1" end="1" type="levels_type"/>
43426</flags>
43427<reg name="flags" bitsize="32" type="flags_type"/>
43428@end smallexample
43429
43430Given that description, a value of 3 for the @samp{flags} register
43431would be printed as:
43432
43433@smallexample
43434(gdb) info register flags
43435flags 0x3 [ X LEVEL=high ]
43436@end smallexample
43437
123dc839
DJ
43438@node Standard Target Features
43439@section Standard Target Features
43440@cindex target descriptions, standard features
43441
43442A target description must contain either no registers or all the
43443target's registers. If the description contains no registers, then
43444@value{GDBN} will assume a default register layout, selected based on
43445the architecture. If the description contains any registers, the
43446default layout will not be used; the standard registers must be
43447described in the target description, in such a way that @value{GDBN}
43448can recognize them.
43449
43450This is accomplished by giving specific names to feature elements
43451which contain standard registers. @value{GDBN} will look for features
43452with those names and verify that they contain the expected registers;
43453if any known feature is missing required registers, or if any required
43454feature is missing, @value{GDBN} will reject the target
43455description. You can add additional registers to any of the
43456standard features --- @value{GDBN} will display them just as if
43457they were added to an unrecognized feature.
43458
43459This section lists the known features and their expected contents.
43460Sample XML documents for these features are included in the
43461@value{GDBN} source tree, in the directory @file{gdb/features}.
43462
43463Names recognized by @value{GDBN} should include the name of the
43464company or organization which selected the name, and the overall
43465architecture to which the feature applies; so e.g.@: the feature
43466containing ARM core registers is named @samp{org.gnu.gdb.arm.core}.
43467
ff6f572f
DJ
43468The names of registers are not case sensitive for the purpose
43469of recognizing standard features, but @value{GDBN} will only display
43470registers using the capitalization used in the description.
43471
e9c17194 43472@menu
430ed3f0 43473* AArch64 Features::
ad0a504f 43474* ARC Features::
e9c17194 43475* ARM Features::
3bb8d5c3 43476* i386 Features::
164224e9 43477* MicroBlaze Features::
1e26b4f8 43478* MIPS Features::
e9c17194 43479* M68K Features::
a28d8e50 43480* NDS32 Features::
a1217d97 43481* Nios II Features::
a994fec4 43482* OpenRISC 1000 Features::
1e26b4f8 43483* PowerPC Features::
b5ffee31 43484* RISC-V Features::
4ac33720 43485* S/390 and System z Features::
3f7b46f2 43486* Sparc Features::
224bbe49 43487* TIC6x Features::
e9c17194
VP
43488@end menu
43489
43490
430ed3f0
MS
43491@node AArch64 Features
43492@subsection AArch64 Features
43493@cindex target descriptions, AArch64 features
43494
43495The @samp{org.gnu.gdb.aarch64.core} feature is required for AArch64
43496targets. It should contain registers @samp{x0} through @samp{x30},
43497@samp{sp}, @samp{pc}, and @samp{cpsr}.
43498
43499The @samp{org.gnu.gdb.aarch64.fpu} feature is optional. If present,
43500it should contain registers @samp{v0} through @samp{v31}, @samp{fpsr},
43501and @samp{fpcr}.
43502
95228a0d
AH
43503The @samp{org.gnu.gdb.aarch64.sve} feature is optional. If present,
43504it should contain registers @samp{z0} through @samp{z31}, @samp{p0}
43505through @samp{p15}, @samp{ffr} and @samp{vg}.
43506
6dc0ebde
AH
43507The @samp{org.gnu.gdb.aarch64.pauth} feature is optional. If present,
43508it should contain registers @samp{pauth_dmask} and @samp{pauth_cmask}.
43509
ad0a504f
AK
43510@node ARC Features
43511@subsection ARC Features
43512@cindex target descriptions, ARC Features
43513
43514ARC processors are highly configurable, so even core registers and their number
43515are not completely predetermined. In addition flags and PC registers which are
43516important to @value{GDBN} are not ``core'' registers in ARC. It is required
43517that one of the core registers features is present.
43518@samp{org.gnu.gdb.arc.aux-minimal} feature is mandatory.
43519
43520The @samp{org.gnu.gdb.arc.core.v2} feature is required for ARC EM and ARC HS
43521targets with a normal register file. It should contain registers @samp{r0}
43522through @samp{r25}, @samp{gp}, @samp{fp}, @samp{sp}, @samp{r30}, @samp{blink},
43523@samp{lp_count} and @samp{pcl}. This feature may contain register @samp{ilink}
43524and any of extension core registers @samp{r32} through @samp{r59/acch}.
43525@samp{ilink} and extension core registers are not available to read/write, when
43526debugging GNU/Linux applications, thus @samp{ilink} is made optional.
43527
43528The @samp{org.gnu.gdb.arc.core-reduced.v2} feature is required for ARC EM and
43529ARC HS targets with a reduced register file. It should contain registers
43530@samp{r0} through @samp{r3}, @samp{r10} through @samp{r15}, @samp{gp},
43531@samp{fp}, @samp{sp}, @samp{r30}, @samp{blink}, @samp{lp_count} and @samp{pcl}.
43532This feature may contain register @samp{ilink} and any of extension core
43533registers @samp{r32} through @samp{r59/acch}.
43534
43535The @samp{org.gnu.gdb.arc.core.arcompact} feature is required for ARCompact
43536targets with a normal register file. It should contain registers @samp{r0}
43537through @samp{r25}, @samp{gp}, @samp{fp}, @samp{sp}, @samp{r30}, @samp{blink},
43538@samp{lp_count} and @samp{pcl}. This feature may contain registers
43539@samp{ilink1}, @samp{ilink2} and any of extension core registers @samp{r32}
43540through @samp{r59/acch}. @samp{ilink1} and @samp{ilink2} and extension core
43541registers are not available when debugging GNU/Linux applications. The only
43542difference with @samp{org.gnu.gdb.arc.core.v2} feature is in the names of
43543@samp{ilink1} and @samp{ilink2} registers and that @samp{r30} is mandatory in
43544ARC v2, but @samp{ilink2} is optional on ARCompact.
43545
43546The @samp{org.gnu.gdb.arc.aux-minimal} feature is required for all ARC
43547targets. It should contain registers @samp{pc} and @samp{status32}.
43548
e9c17194 43549@node ARM Features
123dc839
DJ
43550@subsection ARM Features
43551@cindex target descriptions, ARM features
43552
9779414d
DJ
43553The @samp{org.gnu.gdb.arm.core} feature is required for non-M-profile
43554ARM targets.
123dc839
DJ
43555It should contain registers @samp{r0} through @samp{r13}, @samp{sp},
43556@samp{lr}, @samp{pc}, and @samp{cpsr}.
43557
9779414d
DJ
43558For M-profile targets (e.g. Cortex-M3), the @samp{org.gnu.gdb.arm.core}
43559feature is replaced by @samp{org.gnu.gdb.arm.m-profile}. It should contain
43560registers @samp{r0} through @samp{r13}, @samp{sp}, @samp{lr}, @samp{pc},
43561and @samp{xpsr}.
43562
123dc839
DJ
43563The @samp{org.gnu.gdb.arm.fpa} feature is optional. If present, it
43564should contain registers @samp{f0} through @samp{f7} and @samp{fps}.
43565
ff6f572f
DJ
43566The @samp{org.gnu.gdb.xscale.iwmmxt} feature is optional. If present,
43567it should contain at least registers @samp{wR0} through @samp{wR15} and
43568@samp{wCGR0} through @samp{wCGR3}. The @samp{wCID}, @samp{wCon},
43569@samp{wCSSF}, and @samp{wCASF} registers are optional.
23181151 43570
58d6951d
DJ
43571The @samp{org.gnu.gdb.arm.vfp} feature is optional. If present, it
43572should contain at least registers @samp{d0} through @samp{d15}. If
43573they are present, @samp{d16} through @samp{d31} should also be included.
43574@value{GDBN} will synthesize the single-precision registers from
43575halves of the double-precision registers.
43576
43577The @samp{org.gnu.gdb.arm.neon} feature is optional. It does not
43578need to contain registers; it instructs @value{GDBN} to display the
43579VFP double-precision registers as vectors and to synthesize the
43580quad-precision registers from pairs of double-precision registers.
43581If this feature is present, @samp{org.gnu.gdb.arm.vfp} must also
43582be present and include 32 double-precision registers.
43583
3bb8d5c3
L
43584@node i386 Features
43585@subsection i386 Features
43586@cindex target descriptions, i386 features
43587
43588The @samp{org.gnu.gdb.i386.core} feature is required for i386/amd64
43589targets. It should describe the following registers:
43590
43591@itemize @minus
43592@item
43593@samp{eax} through @samp{edi} plus @samp{eip} for i386
43594@item
43595@samp{rax} through @samp{r15} plus @samp{rip} for amd64
43596@item
43597@samp{eflags}, @samp{cs}, @samp{ss}, @samp{ds}, @samp{es},
43598@samp{fs}, @samp{gs}
43599@item
43600@samp{st0} through @samp{st7}
43601@item
43602@samp{fctrl}, @samp{fstat}, @samp{ftag}, @samp{fiseg}, @samp{fioff},
43603@samp{foseg}, @samp{fooff} and @samp{fop}
43604@end itemize
43605
43606The register sets may be different, depending on the target.
43607
3a13a53b 43608The @samp{org.gnu.gdb.i386.sse} feature is optional. It should
3bb8d5c3
L
43609describe registers:
43610
43611@itemize @minus
43612@item
43613@samp{xmm0} through @samp{xmm7} for i386
43614@item
43615@samp{xmm0} through @samp{xmm15} for amd64
43616@item
43617@samp{mxcsr}
43618@end itemize
43619
3a13a53b
L
43620The @samp{org.gnu.gdb.i386.avx} feature is optional and requires the
43621@samp{org.gnu.gdb.i386.sse} feature. It should
f68eb612
L
43622describe the upper 128 bits of @sc{ymm} registers:
43623
43624@itemize @minus
43625@item
43626@samp{ymm0h} through @samp{ymm7h} for i386
43627@item
43628@samp{ymm0h} through @samp{ymm15h} for amd64
f68eb612
L
43629@end itemize
43630
bc504a31 43631The @samp{org.gnu.gdb.i386.mpx} is an optional feature representing Intel
ca8941bb
WT
43632Memory Protection Extension (MPX). It should describe the following registers:
43633
43634@itemize @minus
43635@item
43636@samp{bnd0raw} through @samp{bnd3raw} for i386 and amd64.
43637@item
43638@samp{bndcfgu} and @samp{bndstatus} for i386 and amd64.
43639@end itemize
43640
3bb8d5c3
L
43641The @samp{org.gnu.gdb.i386.linux} feature is optional. It should
43642describe a single register, @samp{orig_eax}.
43643
2735833d
WT
43644The @samp{org.gnu.gdb.i386.segments} feature is optional. It should
43645describe two system registers: @samp{fs_base} and @samp{gs_base}.
43646
01f9f808
MS
43647The @samp{org.gnu.gdb.i386.avx512} feature is optional and requires the
43648@samp{org.gnu.gdb.i386.avx} feature. It should
43649describe additional @sc{xmm} registers:
43650
43651@itemize @minus
43652@item
43653@samp{xmm16h} through @samp{xmm31h}, only valid for amd64.
43654@end itemize
43655
43656It should describe the upper 128 bits of additional @sc{ymm} registers:
43657
43658@itemize @minus
43659@item
43660@samp{ymm16h} through @samp{ymm31h}, only valid for amd64.
43661@end itemize
43662
43663It should
43664describe the upper 256 bits of @sc{zmm} registers:
43665
43666@itemize @minus
43667@item
43668@samp{zmm0h} through @samp{zmm7h} for i386.
43669@item
43670@samp{zmm0h} through @samp{zmm15h} for amd64.
43671@end itemize
43672
43673It should
43674describe the additional @sc{zmm} registers:
43675
43676@itemize @minus
43677@item
43678@samp{zmm16h} through @samp{zmm31h}, only valid for amd64.
43679@end itemize
43680
51547df6
MS
43681The @samp{org.gnu.gdb.i386.pkeys} feature is optional. It should
43682describe a single register, @samp{pkru}. It is a 32-bit register
43683valid for i386 and amd64.
43684
164224e9
ME
43685@node MicroBlaze Features
43686@subsection MicroBlaze Features
43687@cindex target descriptions, MicroBlaze features
43688
43689The @samp{org.gnu.gdb.microblaze.core} feature is required for MicroBlaze
43690targets. It should contain registers @samp{r0} through @samp{r31},
43691@samp{rpc}, @samp{rmsr}, @samp{rear}, @samp{resr}, @samp{rfsr}, @samp{rbtr},
43692@samp{rpvr}, @samp{rpvr1} through @samp{rpvr11}, @samp{redr}, @samp{rpid},
43693@samp{rzpr}, @samp{rtlbx}, @samp{rtlbsx}, @samp{rtlblo}, and @samp{rtlbhi}.
43694
43695The @samp{org.gnu.gdb.microblaze.stack-protect} feature is optional.
43696If present, it should contain registers @samp{rshr} and @samp{rslr}
43697
1e26b4f8 43698@node MIPS Features
eb17f351
EZ
43699@subsection @acronym{MIPS} Features
43700@cindex target descriptions, @acronym{MIPS} features
f8b73d13 43701
eb17f351 43702The @samp{org.gnu.gdb.mips.cpu} feature is required for @acronym{MIPS} targets.
f8b73d13
DJ
43703It should contain registers @samp{r0} through @samp{r31}, @samp{lo},
43704@samp{hi}, and @samp{pc}. They may be 32-bit or 64-bit depending
43705on the target.
43706
43707The @samp{org.gnu.gdb.mips.cp0} feature is also required. It should
43708contain at least the @samp{status}, @samp{badvaddr}, and @samp{cause}
43709registers. They may be 32-bit or 64-bit depending on the target.
43710
43711The @samp{org.gnu.gdb.mips.fpu} feature is currently required, though
43712it may be optional in a future version of @value{GDBN}. It should
43713contain registers @samp{f0} through @samp{f31}, @samp{fcsr}, and
43714@samp{fir}. They may be 32-bit or 64-bit depending on the target.
43715
1faeff08
MR
43716The @samp{org.gnu.gdb.mips.dsp} feature is optional. It should
43717contain registers @samp{hi1} through @samp{hi3}, @samp{lo1} through
43718@samp{lo3}, and @samp{dspctl}. The @samp{dspctl} register should
43719be 32-bit and the rest may be 32-bit or 64-bit depending on the target.
43720
822b6570
DJ
43721The @samp{org.gnu.gdb.mips.linux} feature is optional. It should
43722contain a single register, @samp{restart}, which is used by the
43723Linux kernel to control restartable syscalls.
43724
e9c17194
VP
43725@node M68K Features
43726@subsection M68K Features
43727@cindex target descriptions, M68K features
43728
43729@table @code
43730@item @samp{org.gnu.gdb.m68k.core}
43731@itemx @samp{org.gnu.gdb.coldfire.core}
43732@itemx @samp{org.gnu.gdb.fido.core}
43733One of those features must be always present.
249e1128 43734The feature that is present determines which flavor of m68k is
e9c17194
VP
43735used. The feature that is present should contain registers
43736@samp{d0} through @samp{d7}, @samp{a0} through @samp{a5}, @samp{fp},
43737@samp{sp}, @samp{ps} and @samp{pc}.
43738
43739@item @samp{org.gnu.gdb.coldfire.fp}
43740This feature is optional. If present, it should contain registers
43741@samp{fp0} through @samp{fp7}, @samp{fpcontrol}, @samp{fpstatus} and
43742@samp{fpiaddr}.
43743@end table
43744
a28d8e50
YTL
43745@node NDS32 Features
43746@subsection NDS32 Features
43747@cindex target descriptions, NDS32 features
43748
43749The @samp{org.gnu.gdb.nds32.core} feature is required for NDS32
43750targets. It should contain at least registers @samp{r0} through
43751@samp{r10}, @samp{r15}, @samp{fp}, @samp{gp}, @samp{lp}, @samp{sp},
43752and @samp{pc}.
43753
43754The @samp{org.gnu.gdb.nds32.fpu} feature is optional. If present,
43755it should contain 64-bit double-precision floating-point registers
43756@samp{fd0} through @emph{fdN}, which should be @samp{fd3}, @samp{fd7},
43757@samp{fd15}, or @samp{fd31} based on the FPU configuration implemented.
43758
43759@emph{Note:} The first sixteen 64-bit double-precision floating-point
43760registers are overlapped with the thirty-two 32-bit single-precision
43761floating-point registers. The 32-bit single-precision registers, if
43762not being listed explicitly, will be synthesized from halves of the
43763overlapping 64-bit double-precision registers. Listing 32-bit
43764single-precision registers explicitly is deprecated, and the
43765support to it could be totally removed some day.
43766
a1217d97
SL
43767@node Nios II Features
43768@subsection Nios II Features
43769@cindex target descriptions, Nios II features
43770
43771The @samp{org.gnu.gdb.nios2.cpu} feature is required for Nios II
43772targets. It should contain the 32 core registers (@samp{zero},
43773@samp{at}, @samp{r2} through @samp{r23}, @samp{et} through @samp{ra}),
43774@samp{pc}, and the 16 control registers (@samp{status} through
43775@samp{mpuacc}).
43776
a994fec4
FJ
43777@node OpenRISC 1000 Features
43778@subsection Openrisc 1000 Features
43779@cindex target descriptions, OpenRISC 1000 features
43780
43781The @samp{org.gnu.gdb.or1k.group0} feature is required for OpenRISC 1000
43782targets. It should contain the 32 general purpose registers (@samp{r0}
43783through @samp{r31}), @samp{ppc}, @samp{npc} and @samp{sr}.
43784
1e26b4f8 43785@node PowerPC Features
7cc46491
DJ
43786@subsection PowerPC Features
43787@cindex target descriptions, PowerPC features
43788
43789The @samp{org.gnu.gdb.power.core} feature is required for PowerPC
43790targets. It should contain registers @samp{r0} through @samp{r31},
43791@samp{pc}, @samp{msr}, @samp{cr}, @samp{lr}, @samp{ctr}, and
43792@samp{xer}. They may be 32-bit or 64-bit depending on the target.
43793
43794The @samp{org.gnu.gdb.power.fpu} feature is optional. It should
43795contain registers @samp{f0} through @samp{f31} and @samp{fpscr}.
43796
43797The @samp{org.gnu.gdb.power.altivec} feature is optional. It should
6f072a10
PFC
43798contain registers @samp{vr0} through @samp{vr31}, @samp{vscr}, and
43799@samp{vrsave}. @value{GDBN} will define pseudo-registers @samp{v0}
43800through @samp{v31} as aliases for the corresponding @samp{vrX}
43801registers.
7cc46491 43802
677c5bb1 43803The @samp{org.gnu.gdb.power.vsx} feature is optional. It should
4b905ae1
PFC
43804contain registers @samp{vs0h} through @samp{vs31h}. @value{GDBN} will
43805combine these registers with the floating point registers (@samp{f0}
43806through @samp{f31}) and the altivec registers (@samp{vr0} through
43807@samp{vr31}) to present the 128-bit wide registers @samp{vs0} through
43808@samp{vs63}, the set of vector-scalar registers for POWER7.
43809Therefore, this feature requires both @samp{org.gnu.gdb.power.fpu} and
43810@samp{org.gnu.gdb.power.altivec}.
677c5bb1 43811
7cc46491
DJ
43812The @samp{org.gnu.gdb.power.spe} feature is optional. It should
43813contain registers @samp{ev0h} through @samp{ev31h}, @samp{acc}, and
43814@samp{spefscr}. SPE targets should provide 32-bit registers in
43815@samp{org.gnu.gdb.power.core} and provide the upper halves in
43816@samp{ev0h} through @samp{ev31h}. @value{GDBN} will combine
43817these to present registers @samp{ev0} through @samp{ev31} to the
43818user.
43819
7ca18ed6
EBM
43820The @samp{org.gnu.gdb.power.ppr} feature is optional. It should
43821contain the 64-bit register @samp{ppr}.
43822
43823The @samp{org.gnu.gdb.power.dscr} feature is optional. It should
43824contain the 64-bit register @samp{dscr}.
43825
f2cf6173
EBM
43826The @samp{org.gnu.gdb.power.tar} feature is optional. It should
43827contain the 64-bit register @samp{tar}.
43828
232bfb86
EBM
43829The @samp{org.gnu.gdb.power.ebb} feature is optional. It should
43830contain registers @samp{bescr}, @samp{ebbhr} and @samp{ebbrr}, all
4383164-bit wide.
43832
43833The @samp{org.gnu.gdb.power.linux.pmu} feature is optional. It should
43834contain registers @samp{mmcr0}, @samp{mmcr2}, @samp{siar}, @samp{sdar}
43835and @samp{sier}, all 64-bit wide. This is the subset of the isa 2.07
43836server PMU registers provided by @sc{gnu}/Linux.
43837
8d619c01
EBM
43838The @samp{org.gnu.gdb.power.htm.spr} feature is optional. It should
43839contain registers @samp{tfhar}, @samp{texasr} and @samp{tfiar}, all
4384064-bit wide.
43841
43842The @samp{org.gnu.gdb.power.htm.core} feature is optional. It should
43843contain the checkpointed general-purpose registers @samp{cr0} through
43844@samp{cr31}, as well as the checkpointed registers @samp{clr} and
43845@samp{cctr}. These registers may all be either 32-bit or 64-bit
43846depending on the target. It should also contain the checkpointed
43847registers @samp{ccr} and @samp{cxer}, which should both be 32-bit
43848wide.
43849
43850The @samp{org.gnu.gdb.power.htm.fpu} feature is optional. It should
43851contain the checkpointed 64-bit floating-point registers @samp{cf0}
43852through @samp{cf31}, as well as the checkpointed 64-bit register
43853@samp{cfpscr}.
43854
43855The @samp{org.gnu.gdb.power.htm.altivec} feature is optional. It
43856should contain the checkpointed altivec registers @samp{cvr0} through
43857@samp{cvr31}, all 128-bit wide. It should also contain the
43858checkpointed registers @samp{cvscr} and @samp{cvrsave}, both 32-bit
43859wide.
43860
43861The @samp{org.gnu.gdb.power.htm.vsx} feature is optional. It should
43862contain registers @samp{cvs0h} through @samp{cvs31h}. @value{GDBN}
43863will combine these registers with the checkpointed floating point
43864registers (@samp{cf0} through @samp{cf31}) and the checkpointed
43865altivec registers (@samp{cvr0} through @samp{cvr31}) to present the
43866128-bit wide checkpointed vector-scalar registers @samp{cvs0} through
43867@samp{cvs63}. Therefore, this feature requires both
43868@samp{org.gnu.gdb.power.htm.altivec} and
43869@samp{org.gnu.gdb.power.htm.fpu}.
43870
43871The @samp{org.gnu.gdb.power.htm.ppr} feature is optional. It should
43872contain the 64-bit checkpointed register @samp{cppr}.
43873
43874The @samp{org.gnu.gdb.power.htm.dscr} feature is optional. It should
43875contain the 64-bit checkpointed register @samp{cdscr}.
43876
43877The @samp{org.gnu.gdb.power.htm.tar} feature is optional. It should
43878contain the 64-bit checkpointed register @samp{ctar}.
43879
b5ffee31
AB
43880
43881@node RISC-V Features
43882@subsection RISC-V Features
43883@cindex target descriptions, RISC-V Features
43884
43885The @samp{org.gnu.gdb.riscv.cpu} feature is required for RISC-V
43886targets. It should contain the registers @samp{x0} through
43887@samp{x31}, and @samp{pc}. Either the architectural names (@samp{x0},
43888@samp{x1}, etc) can be used, or the ABI names (@samp{zero}, @samp{ra},
43889etc).
43890
43891The @samp{org.gnu.gdb.riscv.fpu} feature is optional. If present, it
43892should contain registers @samp{f0} through @samp{f31}, @samp{fflags},
43893@samp{frm}, and @samp{fcsr}. As with the cpu feature, either the
43894architectural register names, or the ABI names can be used.
43895
43896The @samp{org.gnu.gdb.riscv.virtual} feature is optional. If present,
43897it should contain registers that are not backed by real registers on
43898the target, but are instead virtual, where the register value is
43899derived from other target state. In many ways these are like
43900@value{GDBN}s pseudo-registers, except implemented by the target.
43901Currently the only register expected in this set is the one byte
43902@samp{priv} register that contains the target's privilege level in the
43903least significant two bits.
43904
43905The @samp{org.gnu.gdb.riscv.csr} feature is optional. If present, it
43906should contain all of the target's standard CSRs. Standard CSRs are
43907those defined in the RISC-V specification documents. There is some
43908overlap between this feature and the fpu feature; the @samp{fflags},
43909@samp{frm}, and @samp{fcsr} registers could be in either feature. The
43910expectation is that these registers will be in the fpu feature if the
43911target has floating point hardware, but can be moved into the csr
43912feature if the target has the floating point control registers, but no
43913other floating point hardware.
43914
4ac33720
UW
43915@node S/390 and System z Features
43916@subsection S/390 and System z Features
43917@cindex target descriptions, S/390 features
43918@cindex target descriptions, System z features
43919
43920The @samp{org.gnu.gdb.s390.core} feature is required for S/390 and
43921System z targets. It should contain the PSW and the 16 general
43922registers. In particular, System z targets should provide the 64-bit
43923registers @samp{pswm}, @samp{pswa}, and @samp{r0} through @samp{r15}.
43924S/390 targets should provide the 32-bit versions of these registers.
43925A System z target that runs in 31-bit addressing mode should provide
4392632-bit versions of @samp{pswm} and @samp{pswa}, as well as the general
43927register's upper halves @samp{r0h} through @samp{r15h}, and their
43928lower halves @samp{r0l} through @samp{r15l}.
43929
43930The @samp{org.gnu.gdb.s390.fpr} feature is required. It should
43931contain the 64-bit registers @samp{f0} through @samp{f15}, and
43932@samp{fpc}.
43933
43934The @samp{org.gnu.gdb.s390.acr} feature is required. It should
43935contain the 32-bit registers @samp{acr0} through @samp{acr15}.
43936
43937The @samp{org.gnu.gdb.s390.linux} feature is optional. It should
43938contain the register @samp{orig_r2}, which is 64-bit wide on System z
43939targets and 32-bit otherwise. In addition, the feature may contain
43940the @samp{last_break} register, whose width depends on the addressing
43941mode, as well as the @samp{system_call} register, which is always
4394232-bit wide.
43943
43944The @samp{org.gnu.gdb.s390.tdb} feature is optional. It should
43945contain the 64-bit registers @samp{tdb0}, @samp{tac}, @samp{tct},
43946@samp{atia}, and @samp{tr0} through @samp{tr15}.
43947
446899e4
AA
43948The @samp{org.gnu.gdb.s390.vx} feature is optional. It should contain
4394964-bit wide registers @samp{v0l} through @samp{v15l}, which will be
43950combined by @value{GDBN} with the floating point registers @samp{f0}
43951through @samp{f15} to present the 128-bit wide vector registers
43952@samp{v0} through @samp{v15}. In addition, this feature should
43953contain the 128-bit wide vector registers @samp{v16} through
43954@samp{v31}.
43955
289e23aa
AA
43956The @samp{org.gnu.gdb.s390.gs} feature is optional. It should contain
43957the 64-bit wide guarded-storage-control registers @samp{gsd},
43958@samp{gssm}, and @samp{gsepla}.
43959
43960The @samp{org.gnu.gdb.s390.gsbc} feature is optional. It should contain
43961the 64-bit wide guarded-storage broadcast control registers
43962@samp{bc_gsd}, @samp{bc_gssm}, and @samp{bc_gsepla}.
43963
3f7b46f2
IR
43964@node Sparc Features
43965@subsection Sparc Features
43966@cindex target descriptions, sparc32 features
43967@cindex target descriptions, sparc64 features
43968The @samp{org.gnu.gdb.sparc.cpu} feature is required for sparc32/sparc64
43969targets. It should describe the following registers:
43970
43971@itemize @minus
43972@item
43973@samp{g0} through @samp{g7}
43974@item
43975@samp{o0} through @samp{o7}
43976@item
43977@samp{l0} through @samp{l7}
43978@item
43979@samp{i0} through @samp{i7}
43980@end itemize
43981
43982They may be 32-bit or 64-bit depending on the target.
43983
43984Also the @samp{org.gnu.gdb.sparc.fpu} feature is required for sparc32/sparc64
43985targets. It should describe the following registers:
43986
43987@itemize @minus
43988@item
43989@samp{f0} through @samp{f31}
43990@item
43991@samp{f32} through @samp{f62} for sparc64
43992@end itemize
43993
43994The @samp{org.gnu.gdb.sparc.cp0} feature is required for sparc32/sparc64
43995targets. It should describe the following registers:
43996
43997@itemize @minus
43998@item
43999@samp{y}, @samp{psr}, @samp{wim}, @samp{tbr}, @samp{pc}, @samp{npc},
44000@samp{fsr}, and @samp{csr} for sparc32
44001@item
44002@samp{pc}, @samp{npc}, @samp{state}, @samp{fsr}, @samp{fprs}, and @samp{y}
44003for sparc64
44004@end itemize
44005
224bbe49
YQ
44006@node TIC6x Features
44007@subsection TMS320C6x Features
44008@cindex target descriptions, TIC6x features
44009@cindex target descriptions, TMS320C6x features
44010The @samp{org.gnu.gdb.tic6x.core} feature is required for TMS320C6x
44011targets. It should contain registers @samp{A0} through @samp{A15},
44012registers @samp{B0} through @samp{B15}, @samp{CSR} and @samp{PC}.
44013
44014The @samp{org.gnu.gdb.tic6x.gp} feature is optional. It should
44015contain registers @samp{A16} through @samp{A31} and @samp{B16}
44016through @samp{B31}.
44017
44018The @samp{org.gnu.gdb.tic6x.c6xp} feature is optional. It should
44019contain registers @samp{TSR}, @samp{ILC} and @samp{RILC}.
44020
07e059b5
VP
44021@node Operating System Information
44022@appendix Operating System Information
44023@cindex operating system information
44024
44025@menu
44026* Process list::
44027@end menu
44028
44029Users of @value{GDBN} often wish to obtain information about the state of
44030the operating system running on the target---for example the list of
44031processes, or the list of open files. This section describes the
44032mechanism that makes it possible. This mechanism is similar to the
44033target features mechanism (@pxref{Target Descriptions}), but focuses
44034on a different aspect of target.
44035
44036Operating system information is retrived from the target via the
44037remote protocol, using @samp{qXfer} requests (@pxref{qXfer osdata
44038read}). The object name in the request should be @samp{osdata}, and
44039the @var{annex} identifies the data to be fetched.
44040
44041@node Process list
44042@appendixsection Process list
44043@cindex operating system information, process list
44044
44045When requesting the process list, the @var{annex} field in the
44046@samp{qXfer} request should be @samp{processes}. The returned data is
44047an XML document. The formal syntax of this document is defined in
44048@file{gdb/features/osdata.dtd}.
44049
44050An example document is:
44051
44052@smallexample
44053<?xml version="1.0"?>
44054<!DOCTYPE target SYSTEM "osdata.dtd">
44055<osdata type="processes">
44056 <item>
44057 <column name="pid">1</column>
44058 <column name="user">root</column>
44059 <column name="command">/sbin/init</column>
dc146f7c 44060 <column name="cores">1,2,3</column>
07e059b5
VP
44061 </item>
44062</osdata>
44063@end smallexample
44064
44065Each item should include a column whose name is @samp{pid}. The value
44066of that column should identify the process on the target. The
44067@samp{user} and @samp{command} columns are optional, and will be
dc146f7c
VP
44068displayed by @value{GDBN}. The @samp{cores} column, if present,
44069should contain a comma-separated list of cores that this process
44070is running on. Target may provide additional columns,
07e059b5
VP
44071which @value{GDBN} currently ignores.
44072
05c8c3f5
TT
44073@node Trace File Format
44074@appendix Trace File Format
44075@cindex trace file format
44076
44077The trace file comes in three parts: a header, a textual description
44078section, and a trace frame section with binary data.
44079
44080The header has the form @code{\x7fTRACE0\n}. The first byte is
44081@code{0x7f} so as to indicate that the file contains binary data,
44082while the @code{0} is a version number that may have different values
44083in the future.
44084
44085The description section consists of multiple lines of @sc{ascii} text
44086separated by newline characters (@code{0xa}). The lines may include a
44087variety of optional descriptive or context-setting information, such
44088as tracepoint definitions or register set size. @value{GDBN} will
44089ignore any line that it does not recognize. An empty line marks the end
44090of this section.
44091
0748bf3e
MK
44092@table @code
44093@item R @var{size}
44094Specifies the size of a register block in bytes. This is equal to the
44095size of a @code{g} packet payload in the remote protocol. @var{size}
44096is an ascii decimal number. There should be only one such line in
44097a single trace file.
44098
44099@item status @var{status}
44100Trace status. @var{status} has the same format as a @code{qTStatus}
44101remote packet reply. There should be only one such line in a single trace
44102file.
44103
44104@item tp @var{payload}
44105Tracepoint definition. The @var{payload} has the same format as
44106@code{qTfP}/@code{qTsP} remote packet reply payload. A single tracepoint
44107may take multiple lines of definition, corresponding to the multiple
44108reply packets.
44109
44110@item tsv @var{payload}
44111Trace state variable definition. The @var{payload} has the same format as
44112@code{qTfV}/@code{qTsV} remote packet reply payload. A single variable
44113may take multiple lines of definition, corresponding to the multiple
44114reply packets.
44115
44116@item tdesc @var{payload}
44117Target description in XML format. The @var{payload} is a single line of
44118the XML file. All such lines should be concatenated together to get
44119the original XML file. This file is in the same format as @code{qXfer}
44120@code{features} payload, and corresponds to the main @code{target.xml}
44121file. Includes are not allowed.
44122
44123@end table
05c8c3f5
TT
44124
44125The trace frame section consists of a number of consecutive frames.
44126Each frame begins with a two-byte tracepoint number, followed by a
44127four-byte size giving the amount of data in the frame. The data in
44128the frame consists of a number of blocks, each introduced by a
44129character indicating its type (at least register, memory, and trace
44130state variable). The data in this section is raw binary, not a
44131hexadecimal or other encoding; its endianness matches the target's
44132endianness.
44133
44134@c FIXME bi-arch may require endianness/arch info in description section
44135
44136@table @code
44137@item R @var{bytes}
44138Register block. The number and ordering of bytes matches that of a
44139@code{g} packet in the remote protocol. Note that these are the
e909d859 44140actual bytes, in target order, not a hexadecimal encoding.
05c8c3f5
TT
44141
44142@item M @var{address} @var{length} @var{bytes}...
44143Memory block. This is a contiguous block of memory, at the 8-byte
44144address @var{address}, with a 2-byte length @var{length}, followed by
44145@var{length} bytes.
44146
44147@item V @var{number} @var{value}
44148Trace state variable block. This records the 8-byte signed value
44149@var{value} of trace state variable numbered @var{number}.
44150
44151@end table
44152
44153Future enhancements of the trace file format may include additional types
44154of blocks.
44155
90476074
TT
44156@node Index Section Format
44157@appendix @code{.gdb_index} section format
44158@cindex .gdb_index section format
44159@cindex index section format
44160
44161This section documents the index section that is created by @code{save
44162gdb-index} (@pxref{Index Files}). The index section is
44163DWARF-specific; some knowledge of DWARF is assumed in this
44164description.
44165
44166The mapped index file format is designed to be directly
44167@code{mmap}able on any architecture. In most cases, a datum is
44168represented using a little-endian 32-bit integer value, called an
44169@code{offset_type}. Big endian machines must byte-swap the values
44170before using them. Exceptions to this rule are noted. The data is
44171laid out such that alignment is always respected.
44172
44173A mapped index consists of several areas, laid out in order.
44174
44175@enumerate
44176@item
44177The file header. This is a sequence of values, of @code{offset_type}
44178unless otherwise noted:
44179
44180@enumerate
44181@item
796a7ff8 44182The version number, currently 8. Versions 1, 2 and 3 are obsolete.
481860b3 44183Version 4 uses a different hashing function from versions 5 and 6.
b6ba681c
TT
44184Version 6 includes symbols for inlined functions, whereas versions 4
44185and 5 do not. Version 7 adds attributes to the CU indices in the
796a7ff8
DE
44186symbol table. Version 8 specifies that symbols from DWARF type units
44187(@samp{DW_TAG_type_unit}) refer to the type unit's symbol table and not the
44188compilation unit (@samp{DW_TAG_comp_unit}) using the type.
44189
44190@value{GDBN} will only read version 4, 5, or 6 indices
e615022a 44191by specifying @code{set use-deprecated-index-sections on}.
796a7ff8
DE
44192GDB has a workaround for potentially broken version 7 indices so it is
44193currently not flagged as deprecated.
90476074
TT
44194
44195@item
44196The offset, from the start of the file, of the CU list.
44197
44198@item
44199The offset, from the start of the file, of the types CU list. Note
44200that this area can be empty, in which case this offset will be equal
44201to the next offset.
44202
44203@item
44204The offset, from the start of the file, of the address area.
44205
44206@item
44207The offset, from the start of the file, of the symbol table.
44208
44209@item
44210The offset, from the start of the file, of the constant pool.
44211@end enumerate
44212
44213@item
44214The CU list. This is a sequence of pairs of 64-bit little-endian
44215values, sorted by the CU offset. The first element in each pair is
44216the offset of a CU in the @code{.debug_info} section. The second
44217element in each pair is the length of that CU. References to a CU
44218elsewhere in the map are done using a CU index, which is just the
442190-based index into this table. Note that if there are type CUs, then
44220conceptually CUs and type CUs form a single list for the purposes of
44221CU indices.
44222
44223@item
44224The types CU list. This is a sequence of triplets of 64-bit
44225little-endian values. In a triplet, the first value is the CU offset,
44226the second value is the type offset in the CU, and the third value is
44227the type signature. The types CU list is not sorted.
44228
44229@item
44230The address area. The address area consists of a sequence of address
44231entries. Each address entry has three elements:
44232
44233@enumerate
44234@item
44235The low address. This is a 64-bit little-endian value.
44236
44237@item
44238The high address. This is a 64-bit little-endian value. Like
44239@code{DW_AT_high_pc}, the value is one byte beyond the end.
44240
44241@item
44242The CU index. This is an @code{offset_type} value.
44243@end enumerate
44244
44245@item
44246The symbol table. This is an open-addressed hash table. The size of
44247the hash table is always a power of 2.
44248
44249Each slot in the hash table consists of a pair of @code{offset_type}
44250values. The first value is the offset of the symbol's name in the
44251constant pool. The second value is the offset of the CU vector in the
44252constant pool.
44253
44254If both values are 0, then this slot in the hash table is empty. This
44255is ok because while 0 is a valid constant pool index, it cannot be a
44256valid index for both a string and a CU vector.
44257
44258The hash value for a table entry is computed by applying an
44259iterative hash function to the symbol's name. Starting with an
44260initial value of @code{r = 0}, each (unsigned) character @samp{c} in
559a7a62
JK
44261the string is incorporated into the hash using the formula depending on the
44262index version:
44263
44264@table @asis
44265@item Version 4
44266The formula is @code{r = r * 67 + c - 113}.
44267
156942c7 44268@item Versions 5 to 7
559a7a62
JK
44269The formula is @code{r = r * 67 + tolower (c) - 113}.
44270@end table
44271
44272The terminating @samp{\0} is not incorporated into the hash.
90476074
TT
44273
44274The step size used in the hash table is computed via
44275@code{((hash * 17) & (size - 1)) | 1}, where @samp{hash} is the hash
44276value, and @samp{size} is the size of the hash table. The step size
44277is used to find the next candidate slot when handling a hash
44278collision.
44279
44280The names of C@t{++} symbols in the hash table are canonicalized. We
44281don't currently have a simple description of the canonicalization
44282algorithm; if you intend to create new index sections, you must read
44283the code.
44284
44285@item
44286The constant pool. This is simply a bunch of bytes. It is organized
44287so that alignment is correct: CU vectors are stored first, followed by
44288strings.
44289
44290A CU vector in the constant pool is a sequence of @code{offset_type}
44291values. The first value is the number of CU indices in the vector.
156942c7
DE
44292Each subsequent value is the index and symbol attributes of a CU in
44293the CU list. This element in the hash table is used to indicate which
44294CUs define the symbol and how the symbol is used.
44295See below for the format of each CU index+attributes entry.
90476074
TT
44296
44297A string in the constant pool is zero-terminated.
44298@end enumerate
44299
156942c7
DE
44300Attributes were added to CU index values in @code{.gdb_index} version 7.
44301If a symbol has multiple uses within a CU then there is one
44302CU index+attributes value for each use.
44303
44304The format of each CU index+attributes entry is as follows
44305(bit 0 = LSB):
44306
44307@table @asis
44308
44309@item Bits 0-23
44310This is the index of the CU in the CU list.
44311@item Bits 24-27
44312These bits are reserved for future purposes and must be zero.
44313@item Bits 28-30
44314The kind of the symbol in the CU.
44315
44316@table @asis
44317@item 0
44318This value is reserved and should not be used.
44319By reserving zero the full @code{offset_type} value is backwards compatible
44320with previous versions of the index.
44321@item 1
44322The symbol is a type.
44323@item 2
44324The symbol is a variable or an enum value.
44325@item 3
44326The symbol is a function.
44327@item 4
44328Any other kind of symbol.
44329@item 5,6,7
44330These values are reserved.
44331@end table
44332
44333@item Bit 31
44334This bit is zero if the value is global and one if it is static.
44335
44336The determination of whether a symbol is global or static is complicated.
44337The authorative reference is the file @file{dwarf2read.c} in
44338@value{GDBN} sources.
44339
44340@end table
44341
44342This pseudo-code describes the computation of a symbol's kind and
44343global/static attributes in the index.
44344
44345@smallexample
44346is_external = get_attribute (die, DW_AT_external);
44347language = get_attribute (cu_die, DW_AT_language);
44348switch (die->tag)
44349 @{
44350 case DW_TAG_typedef:
44351 case DW_TAG_base_type:
44352 case DW_TAG_subrange_type:
44353 kind = TYPE;
44354 is_static = 1;
44355 break;
44356 case DW_TAG_enumerator:
44357 kind = VARIABLE;
9c37b5ae 44358 is_static = language != CPLUS;
156942c7
DE
44359 break;
44360 case DW_TAG_subprogram:
44361 kind = FUNCTION;
44362 is_static = ! (is_external || language == ADA);
44363 break;
44364 case DW_TAG_constant:
44365 kind = VARIABLE;
44366 is_static = ! is_external;
44367 break;
44368 case DW_TAG_variable:
44369 kind = VARIABLE;
44370 is_static = ! is_external;
44371 break;
44372 case DW_TAG_namespace:
44373 kind = TYPE;
44374 is_static = 0;
44375 break;
44376 case DW_TAG_class_type:
44377 case DW_TAG_interface_type:
44378 case DW_TAG_structure_type:
44379 case DW_TAG_union_type:
44380 case DW_TAG_enumeration_type:
44381 kind = TYPE;
9c37b5ae 44382 is_static = language != CPLUS;
156942c7
DE
44383 break;
44384 default:
44385 assert (0);
44386 @}
44387@end smallexample
44388
43662968
JK
44389@node Man Pages
44390@appendix Manual pages
44391@cindex Man pages
44392
44393@menu
44394* gdb man:: The GNU Debugger man page
44395* gdbserver man:: Remote Server for the GNU Debugger man page
b292c783 44396* gcore man:: Generate a core file of a running program
43662968 44397* gdbinit man:: gdbinit scripts
ba643918 44398* gdb-add-index man:: Add index files to speed up GDB
43662968
JK
44399@end menu
44400
44401@node gdb man
44402@heading gdb man
44403
44404@c man title gdb The GNU Debugger
44405
44406@c man begin SYNOPSIS gdb
44407gdb [@option{-help}] [@option{-nh}] [@option{-nx}] [@option{-q}]
44408[@option{-batch}] [@option{-cd=}@var{dir}] [@option{-f}]
44409[@option{-b}@w{ }@var{bps}]
44410 [@option{-tty=}@var{dev}] [@option{-s} @var{symfile}]
44411[@option{-e}@w{ }@var{prog}] [@option{-se}@w{ }@var{prog}]
906ccdf0
JK
44412[@option{-c}@w{ }@var{core}] [@option{-p}@w{ }@var{procID}]
44413 [@option{-x}@w{ }@var{cmds}] [@option{-d}@w{ }@var{dir}]
44414[@var{prog}|@var{prog} @var{procID}|@var{prog} @var{core}]
43662968
JK
44415@c man end
44416
44417@c man begin DESCRIPTION gdb
44418The purpose of a debugger such as @value{GDBN} is to allow you to see what is
44419going on ``inside'' another program while it executes -- or what another
44420program was doing at the moment it crashed.
44421
44422@value{GDBN} can do four main kinds of things (plus other things in support of
44423these) to help you catch bugs in the act:
44424
44425@itemize @bullet
44426@item
44427Start your program, specifying anything that might affect its behavior.
44428
44429@item
44430Make your program stop on specified conditions.
44431
44432@item
44433Examine what has happened, when your program has stopped.
44434
44435@item
44436Change things in your program, so you can experiment with correcting the
44437effects of one bug and go on to learn about another.
44438@end itemize
44439
906ccdf0
JK
44440You can use @value{GDBN} to debug programs written in C, C@t{++}, Fortran and
44441Modula-2.
43662968
JK
44442
44443@value{GDBN} is invoked with the shell command @code{gdb}. Once started, it reads
44444commands from the terminal until you tell it to exit with the @value{GDBN}
44445command @code{quit}. You can get online help from @value{GDBN} itself
44446by using the command @code{help}.
44447
44448You can run @code{gdb} with no arguments or options; but the most
44449usual way to start @value{GDBN} is with one argument or two, specifying an
44450executable program as the argument:
44451
44452@smallexample
44453gdb program
44454@end smallexample
44455
44456You can also start with both an executable program and a core file specified:
44457
44458@smallexample
44459gdb program core
44460@end smallexample
44461
44462You can, instead, specify a process ID as a second argument, if you want
44463to debug a running process:
44464
44465@smallexample
44466gdb program 1234
906ccdf0 44467gdb -p 1234
43662968
JK
44468@end smallexample
44469
44470@noindent
44471would attach @value{GDBN} to process @code{1234} (unless you also have a file
44472named @file{1234}; @value{GDBN} does check for a core file first).
906ccdf0 44473With option @option{-p} you can omit the @var{program} filename.
43662968
JK
44474
44475Here are some of the most frequently needed @value{GDBN} commands:
44476
44477@c pod2man highlights the right hand side of the @item lines.
44478@table @env
224f10c1 44479@item break [@var{file}:]@var{function}
43662968
JK
44480Set a breakpoint at @var{function} (in @var{file}).
44481
44482@item run [@var{arglist}]
44483Start your program (with @var{arglist}, if specified).
44484
44485@item bt
44486Backtrace: display the program stack.
44487
44488@item print @var{expr}
44489Display the value of an expression.
44490
44491@item c
44492Continue running your program (after stopping, e.g. at a breakpoint).
44493
44494@item next
44495Execute next program line (after stopping); step @emph{over} any
44496function calls in the line.
44497
44498@item edit [@var{file}:]@var{function}
44499look at the program line where it is presently stopped.
44500
44501@item list [@var{file}:]@var{function}
44502type the text of the program in the vicinity of where it is presently stopped.
44503
44504@item step
44505Execute next program line (after stopping); step @emph{into} any
44506function calls in the line.
44507
44508@item help [@var{name}]
44509Show information about @value{GDBN} command @var{name}, or general information
44510about using @value{GDBN}.
44511
44512@item quit
44513Exit from @value{GDBN}.
44514@end table
44515
44516@ifset man
44517For full details on @value{GDBN},
44518see @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
44519by Richard M. Stallman and Roland H. Pesch. The same text is available online
44520as the @code{gdb} entry in the @code{info} program.
44521@end ifset
44522@c man end
44523
44524@c man begin OPTIONS gdb
44525Any arguments other than options specify an executable
44526file and core file (or process ID); that is, the first argument
44527encountered with no
44528associated option flag is equivalent to a @option{-se} option, and the second,
44529if any, is equivalent to a @option{-c} option if it's the name of a file.
44530Many options have
44531both long and short forms; both are shown here. The long forms are also
44532recognized if you truncate them, so long as enough of the option is
44533present to be unambiguous. (If you prefer, you can flag option
44534arguments with @option{+} rather than @option{-}, though we illustrate the
44535more usual convention.)
44536
44537All the options and command line arguments you give are processed
44538in sequential order. The order makes a difference when the @option{-x}
44539option is used.
44540
44541@table @env
44542@item -help
44543@itemx -h
44544List all options, with brief explanations.
44545
44546@item -symbols=@var{file}
44547@itemx -s @var{file}
44548Read symbol table from file @var{file}.
44549
44550@item -write
44551Enable writing into executable and core files.
44552
44553@item -exec=@var{file}
44554@itemx -e @var{file}
44555Use file @var{file} as the executable file to execute when
44556appropriate, and for examining pure data in conjunction with a core
44557dump.
44558
44559@item -se=@var{file}
44560Read symbol table from file @var{file} and use it as the executable
44561file.
44562
44563@item -core=@var{file}
44564@itemx -c @var{file}
44565Use file @var{file} as a core dump to examine.
44566
44567@item -command=@var{file}
44568@itemx -x @var{file}
44569Execute @value{GDBN} commands from file @var{file}.
44570
44571@item -ex @var{command}
44572Execute given @value{GDBN} @var{command}.
44573
44574@item -directory=@var{directory}
44575@itemx -d @var{directory}
44576Add @var{directory} to the path to search for source files.
44577
44578@item -nh
44579Do not execute commands from @file{~/.gdbinit}.
44580
44581@item -nx
44582@itemx -n
44583Do not execute commands from any @file{.gdbinit} initialization files.
44584
44585@item -quiet
44586@itemx -q
44587``Quiet''. Do not print the introductory and copyright messages. These
44588messages are also suppressed in batch mode.
44589
44590@item -batch
44591Run in batch mode. Exit with status @code{0} after processing all the command
44592files specified with @option{-x} (and @file{.gdbinit}, if not inhibited).
44593Exit with nonzero status if an error occurs in executing the @value{GDBN}
44594commands in the command files.
44595
44596Batch mode may be useful for running @value{GDBN} as a filter, for example to
44597download and run a program on another computer; in order to make this
44598more useful, the message
44599
44600@smallexample
44601Program exited normally.
44602@end smallexample
44603
44604@noindent
44605(which is ordinarily issued whenever a program running under @value{GDBN} control
44606terminates) is not issued when running in batch mode.
44607
44608@item -cd=@var{directory}
44609Run @value{GDBN} using @var{directory} as its working directory,
44610instead of the current directory.
44611
44612@item -fullname
44613@itemx -f
44614Emacs sets this option when it runs @value{GDBN} as a subprocess. It tells
44615@value{GDBN} to output the full file name and line number in a standard,
44616recognizable fashion each time a stack frame is displayed (which
44617includes each time the program stops). This recognizable format looks
44618like two @samp{\032} characters, followed by the file name, line number
44619and character position separated by colons, and a newline. The
44620Emacs-to-@value{GDBN} interface program uses the two @samp{\032}
44621characters as a signal to display the source code for the frame.
44622
44623@item -b @var{bps}
44624Set the line speed (baud rate or bits per second) of any serial
44625interface used by @value{GDBN} for remote debugging.
44626
44627@item -tty=@var{device}
44628Run using @var{device} for your program's standard input and output.
44629@end table
44630@c man end
44631
44632@c man begin SEEALSO gdb
44633@ifset man
44634The full documentation for @value{GDBN} is maintained as a Texinfo manual.
44635If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
44636documentation are properly installed at your site, the command
44637
44638@smallexample
44639info gdb
44640@end smallexample
44641
44642@noindent
44643should give you access to the complete manual.
44644
44645@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
44646Richard M. Stallman and Roland H. Pesch, July 1991.
44647@end ifset
44648@c man end
44649
44650@node gdbserver man
44651@heading gdbserver man
44652
44653@c man title gdbserver Remote Server for the GNU Debugger
44654@format
44655@c man begin SYNOPSIS gdbserver
5b8b6385 44656gdbserver @var{comm} @var{prog} [@var{args}@dots{}]
43662968 44657
5b8b6385
JK
44658gdbserver --attach @var{comm} @var{pid}
44659
44660gdbserver --multi @var{comm}
43662968
JK
44661@c man end
44662@end format
44663
44664@c man begin DESCRIPTION gdbserver
44665@command{gdbserver} is a program that allows you to run @value{GDBN} on a different machine
44666than the one which is running the program being debugged.
44667
44668@ifclear man
44669@subheading Usage (server (target) side)
44670@end ifclear
44671@ifset man
44672Usage (server (target) side):
44673@end ifset
44674
44675First, you need to have a copy of the program you want to debug put onto
44676the target system. The program can be stripped to save space if needed, as
44677@command{gdbserver} doesn't care about symbols. All symbol handling is taken care of by
44678the @value{GDBN} running on the host system.
44679
44680To use the server, you log on to the target system, and run the @command{gdbserver}
44681program. You must tell it (a) how to communicate with @value{GDBN}, (b) the name of
44682your program, and (c) its arguments. The general syntax is:
44683
44684@smallexample
44685target> gdbserver @var{comm} @var{program} [@var{args} ...]
44686@end smallexample
44687
44688For example, using a serial port, you might say:
44689
44690@smallexample
44691@ifset man
44692@c @file would wrap it as F</dev/com1>.
44693target> gdbserver /dev/com1 emacs foo.txt
44694@end ifset
44695@ifclear man
44696target> gdbserver @file{/dev/com1} emacs foo.txt
44697@end ifclear
44698@end smallexample
44699
44700This tells @command{gdbserver} to debug emacs with an argument of foo.txt, and
44701to communicate with @value{GDBN} via @file{/dev/com1}. @command{gdbserver} now
44702waits patiently for the host @value{GDBN} to communicate with it.
44703
44704To use a TCP connection, you could say:
44705
44706@smallexample
44707target> gdbserver host:2345 emacs foo.txt
44708@end smallexample
44709
44710This says pretty much the same thing as the last example, except that we are
44711going to communicate with the @code{host} @value{GDBN} via TCP. The @code{host:2345} argument means
44712that we are expecting to see a TCP connection from @code{host} to local TCP port
447132345. (Currently, the @code{host} part is ignored.) You can choose any number you
44714want for the port number as long as it does not conflict with any existing TCP
44715ports on the target system. This same port number must be used in the host
44716@value{GDBN}s @code{target remote} command, which will be described shortly. Note that if
44717you chose a port number that conflicts with another service, @command{gdbserver} will
44718print an error message and exit.
44719
5b8b6385 44720@command{gdbserver} can also attach to running programs.
43662968
JK
44721This is accomplished via the @option{--attach} argument. The syntax is:
44722
44723@smallexample
5b8b6385 44724target> gdbserver --attach @var{comm} @var{pid}
43662968
JK
44725@end smallexample
44726
44727@var{pid} is the process ID of a currently running process. It isn't
44728necessary to point @command{gdbserver} at a binary for the running process.
44729
5b8b6385
JK
44730To start @code{gdbserver} without supplying an initial command to run
44731or process ID to attach, use the @option{--multi} command line option.
44732In such case you should connect using @kbd{target extended-remote} to start
44733the program you want to debug.
44734
44735@smallexample
44736target> gdbserver --multi @var{comm}
44737@end smallexample
44738
43662968
JK
44739@ifclear man
44740@subheading Usage (host side)
44741@end ifclear
44742@ifset man
44743Usage (host side):
44744@end ifset
44745
44746You need an unstripped copy of the target program on your host system, since
1a088a2e 44747@value{GDBN} needs to examine its symbol tables and such. Start up @value{GDBN} as you normally
43662968
JK
44748would, with the target program as the first argument. (You may need to use the
44749@option{--baud} option if the serial line is running at anything except 9600 baud.)
44750That is @code{gdb TARGET-PROG}, or @code{gdb --baud BAUD TARGET-PROG}. After that, the only
5b8b6385
JK
44751new command you need to know about is @code{target remote}
44752(or @code{target extended-remote}). Its argument is either
43662968
JK
44753a device name (usually a serial device, like @file{/dev/ttyb}), or a @code{HOST:PORT}
44754descriptor. For example:
44755
44756@smallexample
44757@ifset man
44758@c @file would wrap it as F</dev/ttyb>.
44759(gdb) target remote /dev/ttyb
44760@end ifset
44761@ifclear man
44762(gdb) target remote @file{/dev/ttyb}
44763@end ifclear
44764@end smallexample
44765
44766@noindent
44767communicates with the server via serial line @file{/dev/ttyb}, and:
44768
44769@smallexample
44770(gdb) target remote the-target:2345
44771@end smallexample
44772
44773@noindent
44774communicates via a TCP connection to port 2345 on host `the-target', where
44775you previously started up @command{gdbserver} with the same port number. Note that for
44776TCP connections, you must start up @command{gdbserver} prior to using the `target remote'
44777command, otherwise you may get an error that looks something like
44778`Connection refused'.
5b8b6385
JK
44779
44780@command{gdbserver} can also debug multiple inferiors at once,
44781described in
44782@ifset man
44783the @value{GDBN} manual in node @code{Inferiors and Programs}
44784-- shell command @code{info -f gdb -n 'Inferiors and Programs'}.
44785@end ifset
44786@ifclear man
44787@ref{Inferiors and Programs}.
44788@end ifclear
44789In such case use the @code{extended-remote} @value{GDBN} command variant:
44790
44791@smallexample
44792(gdb) target extended-remote the-target:2345
44793@end smallexample
44794
44795The @command{gdbserver} option @option{--multi} may or may not be used in such
44796case.
43662968
JK
44797@c man end
44798
44799@c man begin OPTIONS gdbserver
5b8b6385
JK
44800There are three different modes for invoking @command{gdbserver}:
44801
44802@itemize @bullet
44803
44804@item
44805Debug a specific program specified by its program name:
44806
44807@smallexample
44808gdbserver @var{comm} @var{prog} [@var{args}@dots{}]
44809@end smallexample
44810
44811The @var{comm} parameter specifies how should the server communicate
44812with @value{GDBN}; it is either a device name (to use a serial line),
44813a TCP port number (@code{:1234}), or @code{-} or @code{stdio} to use
44814stdin/stdout of @code{gdbserver}. Specify the name of the program to
44815debug in @var{prog}. Any remaining arguments will be passed to the
44816program verbatim. When the program exits, @value{GDBN} will close the
44817connection, and @code{gdbserver} will exit.
44818
44819@item
44820Debug a specific program by specifying the process ID of a running
44821program:
44822
44823@smallexample
44824gdbserver --attach @var{comm} @var{pid}
44825@end smallexample
44826
44827The @var{comm} parameter is as described above. Supply the process ID
44828of a running program in @var{pid}; @value{GDBN} will do everything
44829else. Like with the previous mode, when the process @var{pid} exits,
44830@value{GDBN} will close the connection, and @code{gdbserver} will exit.
44831
44832@item
44833Multi-process mode -- debug more than one program/process:
44834
44835@smallexample
44836gdbserver --multi @var{comm}
44837@end smallexample
44838
44839In this mode, @value{GDBN} can instruct @command{gdbserver} which
44840command(s) to run. Unlike the other 2 modes, @value{GDBN} will not
44841close the connection when a process being debugged exits, so you can
44842debug several processes in the same session.
44843@end itemize
44844
44845In each of the modes you may specify these options:
44846
44847@table @env
44848
44849@item --help
44850List all options, with brief explanations.
44851
44852@item --version
44853This option causes @command{gdbserver} to print its version number and exit.
44854
44855@item --attach
44856@command{gdbserver} will attach to a running program. The syntax is:
44857
44858@smallexample
44859target> gdbserver --attach @var{comm} @var{pid}
44860@end smallexample
44861
44862@var{pid} is the process ID of a currently running process. It isn't
44863necessary to point @command{gdbserver} at a binary for the running process.
44864
44865@item --multi
44866To start @code{gdbserver} without supplying an initial command to run
44867or process ID to attach, use this command line option.
44868Then you can connect using @kbd{target extended-remote} and start
44869the program you want to debug. The syntax is:
44870
44871@smallexample
44872target> gdbserver --multi @var{comm}
44873@end smallexample
44874
44875@item --debug
44876Instruct @code{gdbserver} to display extra status information about the debugging
44877process.
44878This option is intended for @code{gdbserver} development and for bug reports to
44879the developers.
44880
44881@item --remote-debug
44882Instruct @code{gdbserver} to display remote protocol debug output.
44883This option is intended for @code{gdbserver} development and for bug reports to
44884the developers.
44885
aeb2e706
AH
44886@item --debug-file=@var{filename}
44887Instruct @code{gdbserver} to send any debug output to the given @var{filename}.
44888This option is intended for @code{gdbserver} development and for bug reports to
44889the developers.
44890
87ce2a04
DE
44891@item --debug-format=option1@r{[},option2,...@r{]}
44892Instruct @code{gdbserver} to include extra information in each line
44893of debugging output.
44894@xref{Other Command-Line Arguments for gdbserver}.
44895
5b8b6385
JK
44896@item --wrapper
44897Specify a wrapper to launch programs
44898for debugging. The option should be followed by the name of the
44899wrapper, then any command-line arguments to pass to the wrapper, then
44900@kbd{--} indicating the end of the wrapper arguments.
44901
44902@item --once
44903By default, @command{gdbserver} keeps the listening TCP port open, so that
44904additional connections are possible. However, if you start @code{gdbserver}
44905with the @option{--once} option, it will stop listening for any further
44906connection attempts after connecting to the first @value{GDBN} session.
44907
44908@c --disable-packet is not documented for users.
44909
44910@c --disable-randomization and --no-disable-randomization are superseded by
44911@c QDisableRandomization.
44912
44913@end table
43662968
JK
44914@c man end
44915
44916@c man begin SEEALSO gdbserver
44917@ifset man
44918The full documentation for @value{GDBN} is maintained as a Texinfo manual.
44919If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
44920documentation are properly installed at your site, the command
44921
44922@smallexample
44923info gdb
44924@end smallexample
44925
44926should give you access to the complete manual.
44927
44928@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
44929Richard M. Stallman and Roland H. Pesch, July 1991.
44930@end ifset
44931@c man end
44932
b292c783
JK
44933@node gcore man
44934@heading gcore
44935
44936@c man title gcore Generate a core file of a running program
44937
44938@format
44939@c man begin SYNOPSIS gcore
129eb0f1 44940gcore [-a] [-o @var{prefix}] @var{pid1} [@var{pid2}...@var{pidN}]
b292c783
JK
44941@c man end
44942@end format
44943
44944@c man begin DESCRIPTION gcore
129eb0f1
SDJ
44945Generate core dumps of one or more running programs with process IDs
44946@var{pid1}, @var{pid2}, etc. A core file produced by @command{gcore}
44947is equivalent to one produced by the kernel when the process crashes
44948(and when @kbd{ulimit -c} was used to set up an appropriate core dump
44949limit). However, unlike after a crash, after @command{gcore} finishes
44950its job the program remains running without any change.
b292c783
JK
44951@c man end
44952
44953@c man begin OPTIONS gcore
44954@table @env
c179febe
SL
44955@item -a
44956Dump all memory mappings. The actual effect of this option depends on
44957the Operating System. On @sc{gnu}/Linux, it will disable
44958@code{use-coredump-filter} (@pxref{set use-coredump-filter}) and
44959enable @code{dump-excluded-mappings} (@pxref{set
44960dump-excluded-mappings}).
44961
129eb0f1
SDJ
44962@item -o @var{prefix}
44963The optional argument @var{prefix} specifies the prefix to be used
44964when composing the file names of the core dumps. The file name is
44965composed as @file{@var{prefix}.@var{pid}}, where @var{pid} is the
44966process ID of the running program being analyzed by @command{gcore}.
44967If not specified, @var{prefix} defaults to @var{gcore}.
b292c783
JK
44968@end table
44969@c man end
44970
44971@c man begin SEEALSO gcore
44972@ifset man
44973The full documentation for @value{GDBN} is maintained as a Texinfo manual.
44974If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
44975documentation are properly installed at your site, the command
44976
44977@smallexample
44978info gdb
44979@end smallexample
44980
44981@noindent
44982should give you access to the complete manual.
44983
44984@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
44985Richard M. Stallman and Roland H. Pesch, July 1991.
44986@end ifset
44987@c man end
44988
43662968
JK
44989@node gdbinit man
44990@heading gdbinit
44991
44992@c man title gdbinit GDB initialization scripts
44993
44994@format
44995@c man begin SYNOPSIS gdbinit
44996@ifset SYSTEM_GDBINIT
44997@value{SYSTEM_GDBINIT}
44998@end ifset
44999
45000~/.gdbinit
45001
45002./.gdbinit
45003@c man end
45004@end format
45005
45006@c man begin DESCRIPTION gdbinit
45007These files contain @value{GDBN} commands to automatically execute during
45008@value{GDBN} startup. The lines of contents are canned sequences of commands,
45009described in
45010@ifset man
45011the @value{GDBN} manual in node @code{Sequences}
45012-- shell command @code{info -f gdb -n Sequences}.
45013@end ifset
45014@ifclear man
45015@ref{Sequences}.
45016@end ifclear
45017
45018Please read more in
45019@ifset man
45020the @value{GDBN} manual in node @code{Startup}
45021-- shell command @code{info -f gdb -n Startup}.
45022@end ifset
45023@ifclear man
45024@ref{Startup}.
45025@end ifclear
45026
45027@table @env
45028@ifset SYSTEM_GDBINIT
45029@item @value{SYSTEM_GDBINIT}
45030@end ifset
45031@ifclear SYSTEM_GDBINIT
45032@item (not enabled with @code{--with-system-gdbinit} during compilation)
45033@end ifclear
45034System-wide initialization file. It is executed unless user specified
45035@value{GDBN} option @code{-nx} or @code{-n}.
45036See more in
45037@ifset man
45038the @value{GDBN} manual in node @code{System-wide configuration}
45039-- shell command @code{info -f gdb -n 'System-wide configuration'}.
45040@end ifset
45041@ifclear man
45042@ref{System-wide configuration}.
45043@end ifclear
45044
45045@item ~/.gdbinit
45046User initialization file. It is executed unless user specified
45047@value{GDBN} options @code{-nx}, @code{-n} or @code{-nh}.
45048
45049@item ./.gdbinit
45050Initialization file for current directory. It may need to be enabled with
45051@value{GDBN} security command @code{set auto-load local-gdbinit}.
45052See more in
45053@ifset man
45054the @value{GDBN} manual in node @code{Init File in the Current Directory}
45055-- shell command @code{info -f gdb -n 'Init File in the Current Directory'}.
45056@end ifset
45057@ifclear man
45058@ref{Init File in the Current Directory}.
45059@end ifclear
45060@end table
45061@c man end
45062
45063@c man begin SEEALSO gdbinit
45064@ifset man
45065gdb(1), @code{info -f gdb -n Startup}
45066
45067The full documentation for @value{GDBN} is maintained as a Texinfo manual.
45068If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
45069documentation are properly installed at your site, the command
ba643918
SDJ
45070
45071@smallexample
45072info gdb
45073@end smallexample
45074
45075should give you access to the complete manual.
45076
45077@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
45078Richard M. Stallman and Roland H. Pesch, July 1991.
45079@end ifset
45080@c man end
45081
45082@node gdb-add-index man
ba643918 45083@heading gdb-add-index
d726cb5d 45084@pindex gdb-add-index
dbfa4523 45085@anchor{gdb-add-index}
ba643918
SDJ
45086
45087@c man title gdb-add-index Add index files to speed up GDB
45088
45089@c man begin SYNOPSIS gdb-add-index
45090gdb-add-index @var{filename}
45091@c man end
45092
45093@c man begin DESCRIPTION gdb-add-index
45094When @value{GDBN} finds a symbol file, it scans the symbols in the
45095file in order to construct an internal symbol table. This lets most
45096@value{GDBN} operations work quickly--at the cost of a delay early on.
45097For large programs, this delay can be quite lengthy, so @value{GDBN}
45098provides a way to build an index, which speeds up startup.
45099
45100To determine whether a file contains such an index, use the command
45101@kbd{readelf -S filename}: the index is stored in a section named
45102@code{.gdb_index}. The index file can only be produced on systems
45103which use ELF binaries and DWARF debug information (i.e., sections
45104named @code{.debug_*}).
45105
45106@command{gdb-add-index} uses @value{GDBN} and @command{objdump} found
45107in the @env{PATH} environment variable. If you want to use different
45108versions of these programs, you can specify them through the
45109@env{GDB} and @env{OBJDUMP} environment variables.
45110
45111See more in
45112@ifset man
45113the @value{GDBN} manual in node @code{Index Files}
45114-- shell command @kbd{info -f gdb -n "Index Files"}.
45115@end ifset
45116@ifclear man
45117@ref{Index Files}.
45118@end ifclear
45119@c man end
45120
45121@c man begin SEEALSO gdb-add-index
45122@ifset man
45123The full documentation for @value{GDBN} is maintained as a Texinfo manual.
45124If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
45125documentation are properly installed at your site, the command
43662968
JK
45126
45127@smallexample
45128info gdb
45129@end smallexample
45130
45131should give you access to the complete manual.
45132
45133@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
45134Richard M. Stallman and Roland H. Pesch, July 1991.
45135@end ifset
45136@c man end
45137
aab4e0ec 45138@include gpl.texi
eb12ee30 45139
e4c0cfae
SS
45140@node GNU Free Documentation License
45141@appendix GNU Free Documentation License
6826cf00
EZ
45142@include fdl.texi
45143
00595b5e
EZ
45144@node Concept Index
45145@unnumbered Concept Index
c906108c
SS
45146
45147@printindex cp
45148
00595b5e
EZ
45149@node Command and Variable Index
45150@unnumbered Command, Variable, and Function Index
45151
45152@printindex fn
45153
c906108c 45154@tex
984359d2 45155% I think something like @@colophon should be in texinfo. In the
c906108c
SS
45156% meantime:
45157\long\def\colophon{\hbox to0pt{}\vfill
45158\centerline{The body of this manual is set in}
45159\centerline{\fontname\tenrm,}
45160\centerline{with headings in {\bf\fontname\tenbf}}
45161\centerline{and examples in {\tt\fontname\tentt}.}
45162\centerline{{\it\fontname\tenit\/},}
45163\centerline{{\bf\fontname\tenbf}, and}
45164\centerline{{\sl\fontname\tensl\/}}
45165\centerline{are used for emphasis.}\vfill}
45166\page\colophon
984359d2 45167% Blame: doc@@cygnus.com, 1991.
c906108c
SS
45168@end tex
45169
c906108c 45170@bye
This page took 7.889151 seconds and 4 git commands to generate.