Multi-target: NEWS and user manual
[deliverable/binutils-gdb.git] / gdb / doc / gdb.texinfo
CommitLineData
c906108c 1\input texinfo @c -*-texinfo-*-
b811d2c2 2@c Copyright (C) 1988--2020 Free Software Foundation, Inc.
c906108c 3@c
5d161b24 4@c %**start of header
c906108c
SS
5@c makeinfo ignores cmds prev to setfilename, so its arg cannot make use
6@c of @set vars. However, you can override filename with makeinfo -o.
7@setfilename gdb.info
8@c
43662968 9@c man begin INCLUDE
c906108c 10@include gdb-cfg.texi
43662968 11@c man end
c906108c 12@c
c906108c 13@settitle Debugging with @value{GDBN}
c906108c
SS
14@setchapternewpage odd
15@c %**end of header
16
17@iftex
18@c @smallbook
19@c @cropmarks
20@end iftex
21
22@finalout
00595b5e
EZ
23@c To avoid file-name clashes between index.html and Index.html, when
24@c the manual is produced on a Posix host and then moved to a
25@c case-insensitive filesystem (e.g., MS-Windows), we separate the
26@c indices into two: Concept Index and all the rest.
27@syncodeindex ky fn
28@syncodeindex tp fn
c906108c 29
41afff9a 30@c readline appendices use @vindex, @findex and @ftable,
48e934c6 31@c annotate.texi and gdbmi use @findex.
00595b5e 32@syncodeindex vr fn
c906108c
SS
33
34@c !!set GDB manual's edition---not the same as GDB version!
9fe8321b 35@c This is updated by GNU Press.
26829f2b 36@set EDITION Tenth
c906108c 37
87885426
FN
38@c !!set GDB edit command default editor
39@set EDITOR /bin/ex
c906108c 40
6c0e9fb3 41@c THIS MANUAL REQUIRES TEXINFO 4.0 OR LATER.
c906108c 42
c906108c 43@c This is a dir.info fragment to support semi-automated addition of
6d2ebf8b 44@c manuals to an info tree.
03727ca6 45@dircategory Software development
96a2c332 46@direntry
03727ca6 47* Gdb: (gdb). The GNU debugger.
6cb999f8 48* gdbserver: (gdb) Server. The GNU debugging server.
96a2c332
SS
49@end direntry
50
a67ec3f4 51@copying
43662968 52@c man begin COPYRIGHT
e5d78223 53Copyright @copyright{} 1988-2020 Free Software Foundation, Inc.
c906108c 54
e9c75b65 55Permission is granted to copy, distribute and/or modify this document
4f5d9f07 56under the terms of the GNU Free Documentation License, Version 1.3 or
e9c75b65 57any later version published by the Free Software Foundation; with the
959acfd1
EZ
58Invariant Sections being ``Free Software'' and ``Free Software Needs
59Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
60and with the Back-Cover Texts as in (a) below.
c906108c 61
b8533aec
DJ
62(a) The FSF's Back-Cover Text is: ``You are free to copy and modify
63this GNU Manual. Buying copies from GNU Press supports the FSF in
64developing GNU and promoting software freedom.''
43662968 65@c man end
a67ec3f4
JM
66@end copying
67
68@ifnottex
69This file documents the @sc{gnu} debugger @value{GDBN}.
70
71This is the @value{EDITION} Edition, of @cite{Debugging with
72@value{GDBN}: the @sc{gnu} Source-Level Debugger} for @value{GDBN}
73@ifset VERSION_PACKAGE
74@value{VERSION_PACKAGE}
75@end ifset
76Version @value{GDBVN}.
77
78@insertcopying
79@end ifnottex
c906108c
SS
80
81@titlepage
82@title Debugging with @value{GDBN}
83@subtitle The @sc{gnu} Source-Level Debugger
c906108c 84@sp 1
c906108c 85@subtitle @value{EDITION} Edition, for @value{GDBN} version @value{GDBVN}
c16158bc
JM
86@ifset VERSION_PACKAGE
87@sp 1
88@subtitle @value{VERSION_PACKAGE}
89@end ifset
9e9c5ae7 90@author Richard Stallman, Roland Pesch, Stan Shebs, et al.
c906108c 91@page
c906108c
SS
92@tex
93{\parskip=0pt
c16158bc 94\hfill (Send bugs and comments on @value{GDBN} to @value{BUGURL}.)\par
c906108c
SS
95\hfill {\it Debugging with @value{GDBN}}\par
96\hfill \TeX{}info \texinfoversion\par
97}
98@end tex
53a5351d 99
c906108c 100@vskip 0pt plus 1filll
c906108c 101Published by the Free Software Foundation @*
c02a867d
EZ
10251 Franklin Street, Fifth Floor,
103Boston, MA 02110-1301, USA@*
26829f2b 104ISBN 978-0-9831592-3-0 @*
e9c75b65 105
a67ec3f4 106@insertcopying
c906108c
SS
107@end titlepage
108@page
109
6c0e9fb3 110@ifnottex
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
e5d78223 123Copyright (C) 1988-2020 Free Software Foundation, Inc.
6d2ebf8b 124
3fb6a982
JB
125This edition of the GDB manual is dedicated to the memory of Fred
126Fish. Fred was a long-standing contributor to GDB and to Free
127software in general. We will miss him.
128
6d2ebf8b
SS
129@menu
130* Summary:: Summary of @value{GDBN}
131* Sample Session:: A sample @value{GDBN} session
132
133* Invocation:: Getting in and out of @value{GDBN}
134* Commands:: @value{GDBN} commands
135* Running:: Running programs under @value{GDBN}
136* Stopping:: Stopping and continuing
bacec72f 137* Reverse Execution:: Running programs backward
a2311334 138* Process Record and Replay:: Recording inferior's execution and replaying it
6d2ebf8b
SS
139* Stack:: Examining the stack
140* Source:: Examining source files
141* Data:: Examining data
edb3359d 142* Optimized Code:: Debugging optimized code
e2e0bcd1 143* Macros:: Preprocessor Macros
b37052ae 144* Tracepoints:: Debugging remote targets non-intrusively
df0cd8c5 145* Overlays:: Debugging programs that use overlays
6d2ebf8b
SS
146
147* Languages:: Using @value{GDBN} with different languages
148
149* Symbols:: Examining the symbol table
150* Altering:: Altering execution
151* GDB Files:: @value{GDBN} files
152* Targets:: Specifying a debugging target
6b2f586d 153* Remote Debugging:: Debugging remote programs
6d2ebf8b
SS
154* Configurations:: Configuration-specific information
155* Controlling GDB:: Controlling @value{GDBN}
d57a3c85 156* Extending GDB:: Extending @value{GDBN}
21c294e6 157* Interpreters:: Command Interpreters
c8f4133a 158* TUI:: @value{GDBN} Text User Interface
6d2ebf8b 159* Emacs:: Using @value{GDBN} under @sc{gnu} Emacs
7162c0ca 160* GDB/MI:: @value{GDBN}'s Machine Interface.
c8f4133a 161* Annotations:: @value{GDBN}'s annotation interface.
4efc6507 162* JIT Interface:: Using the JIT debugging interface.
d1feda86 163* In-Process Agent:: In-Process Agent
6d2ebf8b
SS
164
165* GDB Bugs:: Reporting bugs in @value{GDBN}
6d2ebf8b 166
39037522
TT
167@ifset SYSTEM_READLINE
168* Command Line Editing: (rluserman). Command Line Editing
169* Using History Interactively: (history). Using History Interactively
170@end ifset
171@ifclear SYSTEM_READLINE
6d2ebf8b
SS
172* Command Line Editing:: Command Line Editing
173* Using History Interactively:: Using History Interactively
39037522 174@end ifclear
4ceed123 175* In Memoriam:: In Memoriam
0869d01b 176* Formatting Documentation:: How to format and print @value{GDBN} documentation
6d2ebf8b 177* Installing GDB:: Installing GDB
eb12ee30 178* Maintenance Commands:: Maintenance Commands
e0ce93ac 179* Remote Protocol:: GDB Remote Serial Protocol
f418dd93 180* Agent Expressions:: The GDB Agent Expression Mechanism
23181151
DJ
181* Target Descriptions:: How targets can describe themselves to
182 @value{GDBN}
07e059b5
VP
183* Operating System Information:: Getting additional information from
184 the operating system
00bf0b85 185* Trace File Format:: GDB trace file format
90476074 186* Index Section Format:: .gdb_index section format
43662968 187* Man Pages:: Manual pages
aab4e0ec
AC
188* Copying:: GNU General Public License says
189 how you can copy and share GDB
6826cf00 190* GNU Free Documentation License:: The license for this documentation
00595b5e
EZ
191* Concept Index:: Index of @value{GDBN} concepts
192* Command and Variable Index:: Index of @value{GDBN} commands, variables,
193 functions, and Python data types
6d2ebf8b
SS
194@end menu
195
6c0e9fb3 196@end ifnottex
c906108c 197
449f3b6c 198@contents
449f3b6c 199
6d2ebf8b 200@node Summary
c906108c
SS
201@unnumbered Summary of @value{GDBN}
202
203The purpose of a debugger such as @value{GDBN} is to allow you to see what is
204going on ``inside'' another program while it executes---or what another
205program was doing at the moment it crashed.
206
207@value{GDBN} can do four main kinds of things (plus other things in support of
208these) to help you catch bugs in the act:
209
210@itemize @bullet
211@item
212Start your program, specifying anything that might affect its behavior.
213
214@item
215Make your program stop on specified conditions.
216
217@item
218Examine what has happened, when your program has stopped.
219
220@item
221Change things in your program, so you can experiment with correcting the
222effects of one bug and go on to learn about another.
223@end itemize
224
49efadf5 225You can use @value{GDBN} to debug programs written in C and C@t{++}.
79a6e687 226For more information, see @ref{Supported Languages,,Supported Languages}.
c906108c
SS
227For more information, see @ref{C,,C and C++}.
228
6aecb9c2
JB
229Support for D is partial. For information on D, see
230@ref{D,,D}.
231
cce74817 232@cindex Modula-2
e632838e
AC
233Support for Modula-2 is partial. For information on Modula-2, see
234@ref{Modula-2,,Modula-2}.
c906108c 235
f4b8a18d
KW
236Support for OpenCL C is partial. For information on OpenCL C, see
237@ref{OpenCL C,,OpenCL C}.
238
cce74817
JM
239@cindex Pascal
240Debugging Pascal programs which use sets, subranges, file variables, or
241nested functions does not currently work. @value{GDBN} does not support
242entering expressions, printing values, or similar features using Pascal
243syntax.
c906108c 244
c906108c
SS
245@cindex Fortran
246@value{GDBN} can be used to debug programs written in Fortran, although
53a5351d 247it may be necessary to refer to some variables with a trailing
cce74817 248underscore.
c906108c 249
b37303ee
AF
250@value{GDBN} can be used to debug programs written in Objective-C,
251using either the Apple/NeXT or the GNU Objective-C runtime.
252
c906108c
SS
253@menu
254* Free Software:: Freely redistributable software
984359d2 255* Free Documentation:: Free Software Needs Free Documentation
c906108c
SS
256* Contributors:: Contributors to GDB
257@end menu
258
6d2ebf8b 259@node Free Software
79a6e687 260@unnumberedsec Free Software
c906108c 261
5d161b24 262@value{GDBN} is @dfn{free software}, protected by the @sc{gnu}
c906108c
SS
263General Public License
264(GPL). The GPL gives you the freedom to copy or adapt a licensed
265program---but every person getting a copy also gets with it the
266freedom to modify that copy (which means that they must get access to
267the source code), and the freedom to distribute further copies.
268Typical software companies use copyrights to limit your freedoms; the
269Free Software Foundation uses the GPL to preserve these freedoms.
270
271Fundamentally, the General Public License is a license which says that
272you have these freedoms and that you cannot take these freedoms away
273from anyone else.
274
984359d2 275@node Free Documentation
2666264b 276@unnumberedsec Free Software Needs Free Documentation
959acfd1
EZ
277
278The biggest deficiency in the free software community today is not in
279the software---it is the lack of good free documentation that we can
280include with the free software. Many of our most important
281programs do not come with free reference manuals and free introductory
282texts. Documentation is an essential part of any software package;
283when an important free software package does not come with a free
284manual and a free tutorial, that is a major gap. We have many such
285gaps today.
286
287Consider Perl, for instance. The tutorial manuals that people
288normally use are non-free. How did this come about? Because the
289authors of those manuals published them with restrictive terms---no
290copying, no modification, source files not available---which exclude
291them from the free software world.
292
293That wasn't the first time this sort of thing happened, and it was far
294from the last. Many times we have heard a GNU user eagerly describe a
295manual that he is writing, his intended contribution to the community,
296only to learn that he had ruined everything by signing a publication
297contract to make it non-free.
298
299Free documentation, like free software, is a matter of freedom, not
300price. The problem with the non-free manual is not that publishers
301charge a price for printed copies---that in itself is fine. (The Free
302Software Foundation sells printed copies of manuals, too.) The
303problem is the restrictions on the use of the manual. Free manuals
304are available in source code form, and give you permission to copy and
305modify. Non-free manuals do not allow this.
306
307The criteria of freedom for a free manual are roughly the same as for
308free software. Redistribution (including the normal kinds of
309commercial redistribution) must be permitted, so that the manual can
310accompany every copy of the program, both on-line and on paper.
311
312Permission for modification of the technical content is crucial too.
313When people modify the software, adding or changing features, if they
314are conscientious they will change the manual too---so they can
315provide accurate and clear documentation for the modified program. A
316manual that leaves you no choice but to write a new manual to document
317a changed version of the program is not really available to our
318community.
319
320Some kinds of limits on the way modification is handled are
321acceptable. For example, requirements to preserve the original
322author's copyright notice, the distribution terms, or the list of
323authors, are ok. It is also no problem to require modified versions
324to include notice that they were modified. Even entire sections that
325may not be deleted or changed are acceptable, as long as they deal
326with nontechnical topics (like this one). These kinds of restrictions
327are acceptable because they don't obstruct the community's normal use
328of the manual.
329
330However, it must be possible to modify all the @emph{technical}
331content of the manual, and then distribute the result in all the usual
332media, through all the usual channels. Otherwise, the restrictions
333obstruct the use of the manual, it is not free, and we need another
334manual to replace it.
335
336Please spread the word about this issue. Our community continues to
337lose manuals to proprietary publishing. If we spread the word that
338free software needs free reference manuals and free tutorials, perhaps
339the next person who wants to contribute by writing documentation will
340realize, before it is too late, that only free manuals contribute to
341the free software community.
342
343If you are writing documentation, please insist on publishing it under
344the GNU Free Documentation License or another free documentation
345license. Remember that this decision requires your approval---you
346don't have to let the publisher decide. Some commercial publishers
347will use a free license if you insist, but they will not propose the
348option; it is up to you to raise the issue and say firmly that this is
349what you want. If the publisher you are dealing with refuses, please
350try other publishers. If you're not sure whether a proposed license
42584a72 351is free, write to @email{licensing@@gnu.org}.
959acfd1
EZ
352
353You can encourage commercial publishers to sell more free, copylefted
354manuals and tutorials by buying them, and particularly by buying
355copies from the publishers that paid for their writing or for major
356improvements. Meanwhile, try to avoid buying non-free documentation
357at all. Check the distribution terms of a manual before you buy it,
358and insist that whoever seeks your business must respect your freedom.
72c9928d
EZ
359Check the history of the book, and try to reward the publishers that
360have paid or pay the authors to work on it.
959acfd1
EZ
361
362The Free Software Foundation maintains a list of free documentation
363published by other publishers, at
364@url{http://www.fsf.org/doc/other-free-books.html}.
365
6d2ebf8b 366@node Contributors
96a2c332
SS
367@unnumberedsec Contributors to @value{GDBN}
368
369Richard Stallman was the original author of @value{GDBN}, and of many
370other @sc{gnu} programs. Many others have contributed to its
371development. This section attempts to credit major contributors. One
372of the virtues of free software is that everyone is free to contribute
373to it; with regret, we cannot actually acknowledge everyone here. The
374file @file{ChangeLog} in the @value{GDBN} distribution approximates a
c906108c
SS
375blow-by-blow account.
376
377Changes much prior to version 2.0 are lost in the mists of time.
378
379@quotation
380@emph{Plea:} Additions to this section are particularly welcome. If you
381or your friends (or enemies, to be evenhanded) have been unfairly
382omitted from this list, we would like to add your names!
383@end quotation
384
385So that they may not regard their many labors as thankless, we
386particularly thank those who shepherded @value{GDBN} through major
387releases:
7ba3cf9c 388Andrew Cagney (releases 6.3, 6.2, 6.1, 6.0, 5.3, 5.2, 5.1 and 5.0);
c906108c
SS
389Jim Blandy (release 4.18);
390Jason Molenda (release 4.17);
391Stan Shebs (release 4.14);
392Fred Fish (releases 4.16, 4.15, 4.13, 4.12, 4.11, 4.10, and 4.9);
393Stu Grossman and John Gilmore (releases 4.8, 4.7, 4.6, 4.5, and 4.4);
394John Gilmore (releases 4.3, 4.2, 4.1, 4.0, and 3.9);
395Jim Kingdon (releases 3.5, 3.4, and 3.3);
396and Randy Smith (releases 3.2, 3.1, and 3.0).
397
398Richard Stallman, assisted at various times by Peter TerMaat, Chris
399Hanson, and Richard Mlynarik, handled releases through 2.8.
400
b37052ae
EZ
401Michael Tiemann is the author of most of the @sc{gnu} C@t{++} support
402in @value{GDBN}, with significant additional contributions from Per
403Bothner and Daniel Berlin. James Clark wrote the @sc{gnu} C@t{++}
404demangler. Early work on C@t{++} was by Peter TerMaat (who also did
405much general update work leading to release 3.0).
c906108c 406
b37052ae 407@value{GDBN} uses the BFD subroutine library to examine multiple
c906108c
SS
408object-file formats; BFD was a joint project of David V.
409Henkel-Wallace, Rich Pixley, Steve Chamberlain, and John Gilmore.
410
411David Johnson wrote the original COFF support; Pace Willison did
412the original support for encapsulated COFF.
413
0179ffac 414Brent Benson of Harris Computer Systems contributed DWARF 2 support.
c906108c
SS
415
416Adam de Boor and Bradley Davis contributed the ISI Optimum V support.
417Per Bothner, Noboyuki Hikichi, and Alessandro Forin contributed MIPS
418support.
419Jean-Daniel Fekete contributed Sun 386i support.
420Chris Hanson improved the HP9000 support.
421Noboyuki Hikichi and Tomoyuki Hasei contributed Sony/News OS 3 support.
422David Johnson contributed Encore Umax support.
423Jyrki Kuoppala contributed Altos 3068 support.
424Jeff Law contributed HP PA and SOM support.
425Keith Packard contributed NS32K support.
426Doug Rabson contributed Acorn Risc Machine support.
427Bob Rusk contributed Harris Nighthawk CX-UX support.
428Chris Smith contributed Convex support (and Fortran debugging).
429Jonathan Stone contributed Pyramid support.
430Michael Tiemann contributed SPARC support.
431Tim Tucker contributed support for the Gould NP1 and Gould Powernode.
432Pace Willison contributed Intel 386 support.
433Jay Vosburgh contributed Symmetry support.
a37295f9 434Marko Mlinar contributed OpenRISC 1000 support.
c906108c 435
1104b9e7 436Andreas Schwab contributed M68K @sc{gnu}/Linux support.
c906108c
SS
437
438Rich Schaefer and Peter Schauer helped with support of SunOS shared
439libraries.
440
441Jay Fenlason and Roland McGrath ensured that @value{GDBN} and GAS agree
442about several machine instruction sets.
443
444Patrick Duval, Ted Goldstein, Vikram Koka and Glenn Engel helped develop
445remote debugging. Intel Corporation, Wind River Systems, AMD, and ARM
446contributed remote debugging modules for the i960, VxWorks, A29K UDI,
447and RDI targets, respectively.
448
449Brian Fox is the author of the readline libraries providing
450command-line editing and command history.
451
7a292a7a
SS
452Andrew Beers of SUNY Buffalo wrote the language-switching code, the
453Modula-2 support, and contributed the Languages chapter of this manual.
c906108c 454
5d161b24 455Fred Fish wrote most of the support for Unix System Vr4.
b37052ae 456He also enhanced the command-completion support to cover C@t{++} overloaded
c906108c 457symbols.
c906108c 458
f24c5e49
KI
459Hitachi America (now Renesas America), Ltd. sponsored the support for
460H8/300, H8/500, and Super-H processors.
c906108c
SS
461
462NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
463
f24c5e49
KI
464Mitsubishi (now Renesas) sponsored the support for D10V, D30V, and M32R/D
465processors.
c906108c
SS
466
467Toshiba sponsored the support for the TX39 Mips processor.
468
469Matsushita sponsored the support for the MN10200 and MN10300 processors.
470
96a2c332 471Fujitsu sponsored the support for SPARClite and FR30 processors.
c906108c
SS
472
473Kung Hsu, Jeff Law, and Rick Sladkey added support for hardware
474watchpoints.
475
476Michael Snyder added support for tracepoints.
477
478Stu Grossman wrote gdbserver.
479
480Jim Kingdon, Peter Schauer, Ian Taylor, and Stu Grossman made
96a2c332 481nearly innumerable bug fixes and cleanups throughout @value{GDBN}.
c906108c
SS
482
483The following people at the Hewlett-Packard Company contributed
484support for the PA-RISC 2.0 architecture, HP-UX 10.20, 10.30, and 11.0
b37052ae 485(narrow mode), HP's implementation of kernel threads, HP's aC@t{++}
d0d5df6f
AC
486compiler, and the Text User Interface (nee Terminal User Interface):
487Ben Krepp, Richard Title, John Bishop, Susan Macchia, Kathy Mann,
488Satish Pai, India Paul, Steve Rehrauer, and Elena Zannoni. Kim Haase
489provided HP-specific information in this manual.
c906108c 490
b37052ae
EZ
491DJ Delorie ported @value{GDBN} to MS-DOS, for the DJGPP project.
492Robert Hoehne made significant contributions to the DJGPP port.
493
96a2c332
SS
494Cygnus Solutions has sponsored @value{GDBN} maintenance and much of its
495development since 1991. Cygnus engineers who have worked on @value{GDBN}
2df3850c
JM
496fulltime include Mark Alexander, Jim Blandy, Per Bothner, Kevin
497Buettner, Edith Epstein, Chris Faylor, Fred Fish, Martin Hunt, Jim
498Ingham, John Gilmore, Stu Grossman, Kung Hsu, Jim Kingdon, John Metzler,
499Fernando Nasser, Geoffrey Noer, Dawn Perchik, Rich Pixley, Zdenek
500Radouch, Keith Seitz, Stan Shebs, David Taylor, and Elena Zannoni. In
501addition, Dave Brolley, Ian Carmichael, Steve Chamberlain, Nick Clifton,
502JT Conklin, Stan Cox, DJ Delorie, Ulrich Drepper, Frank Eigler, Doug
503Evans, Sean Fagan, David Henkel-Wallace, Richard Henderson, Jeff
504Holcomb, Jeff Law, Jim Lemke, Tom Lord, Bob Manson, Michael Meissner,
505Jason Merrill, Catherine Moore, Drew Moseley, Ken Raeburn, Gavin
506Romig-Koch, Rob Savoye, Jamie Smith, Mike Stump, Ian Taylor, Angela
507Thomas, Michael Tiemann, Tom Tromey, Ron Unrau, Jim Wilson, and David
508Zuhn have made contributions both large and small.
c906108c 509
ffed4509
AC
510Andrew Cagney, Fernando Nasser, and Elena Zannoni, while working for
511Cygnus Solutions, implemented the original @sc{gdb/mi} interface.
512
e2e0bcd1
JB
513Jim Blandy added support for preprocessor macros, while working for Red
514Hat.
c906108c 515
a9967aef
AC
516Andrew Cagney designed @value{GDBN}'s architecture vector. Many
517people including Andrew Cagney, Stephane Carrez, Randolph Chung, Nick
518Duffek, Richard Henderson, Mark Kettenis, Grace Sainsbury, Kei
519Sakamoto, Yoshinori Sato, Michael Snyder, Andreas Schwab, Jason
520Thorpe, Corinna Vinschen, Ulrich Weigand, and Elena Zannoni, helped
521with the migration of old architectures to this new framework.
522
c5e30d01
AC
523Andrew Cagney completely re-designed and re-implemented @value{GDBN}'s
524unwinder framework, this consisting of a fresh new design featuring
525frame IDs, independent frame sniffers, and the sentinel frame. Mark
526Kettenis implemented the @sc{dwarf 2} unwinder, Jeff Johnston the
527libunwind unwinder, and Andrew Cagney the dummy, sentinel, tramp, and
db2e3e2e 528trad unwinders. The architecture-specific changes, each involving a
c5e30d01
AC
529complete rewrite of the architecture's frame code, were carried out by
530Jim Blandy, Joel Brobecker, Kevin Buettner, Andrew Cagney, Stephane
531Carrez, Randolph Chung, Orjan Friberg, Richard Henderson, Daniel
532Jacobowitz, Jeff Johnston, Mark Kettenis, Theodore A. Roth, Kei
533Sakamoto, Yoshinori Sato, Michael Snyder, Corinna Vinschen, and Ulrich
534Weigand.
535
ca3bf3bd
DJ
536Christian Zankel, Ross Morley, Bob Wilson, and Maxim Grigoriev from
537Tensilica, Inc.@: contributed support for Xtensa processors. Others
538who have worked on the Xtensa port of @value{GDBN} in the past include
539Steve Tjiang, John Newlin, and Scott Foehner.
540
08be9d71
ME
541Michael Eager and staff of Xilinx, Inc., contributed support for the
542Xilinx MicroBlaze architecture.
543
387360da
JB
544Initial support for the FreeBSD/mips target and native configuration
545was developed by SRI International and the University of Cambridge
546Computer Laboratory under DARPA/AFRL contract FA8750-10-C-0237
547("CTSRD"), as part of the DARPA CRASH research programme.
548
74792ff7
JB
549Initial support for the FreeBSD/riscv target and native configuration
550was developed by SRI International and the University of Cambridge
551Computer Laboratory (Department of Computer Science and Technology)
552under DARPA contract HR0011-18-C-0016 ("ECATS"), as part of the DARPA
553SSITH research programme.
554
a994fec4
FJ
555The original port to the OpenRISC 1000 is believed to be due to
556Alessandro Forin and Per Bothner. More recent ports have been the work
557of Jeremy Bennett, Franck Jullien, Stefan Wallentowitz and
558Stafford Horne.
559
6d2ebf8b 560@node Sample Session
c906108c
SS
561@chapter A Sample @value{GDBN} Session
562
563You can use this manual at your leisure to read all about @value{GDBN}.
564However, a handful of commands are enough to get started using the
565debugger. This chapter illustrates those commands.
566
567@iftex
568In this sample session, we emphasize user input like this: @b{input},
569to make it easier to pick out from the surrounding output.
570@end iftex
571
572@c FIXME: this example may not be appropriate for some configs, where
573@c FIXME...primary interest is in remote use.
574
575One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
576processor) exhibits the following bug: sometimes, when we change its
577quote strings from the default, the commands used to capture one macro
578definition within another stop working. In the following short @code{m4}
579session, we define a macro @code{foo} which expands to @code{0000}; we
580then use the @code{m4} built-in @code{defn} to define @code{bar} as the
581same thing. However, when we change the open quote string to
582@code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
583procedure fails to define a new synonym @code{baz}:
584
585@smallexample
586$ @b{cd gnu/m4}
587$ @b{./m4}
588@b{define(foo,0000)}
589
590@b{foo}
5910000
592@b{define(bar,defn(`foo'))}
593
594@b{bar}
5950000
596@b{changequote(<QUOTE>,<UNQUOTE>)}
597
598@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
599@b{baz}
c8aa23ab 600@b{Ctrl-d}
c906108c
SS
601m4: End of input: 0: fatal error: EOF in string
602@end smallexample
603
604@noindent
605Let us use @value{GDBN} to try to see what is going on.
606
c906108c
SS
607@smallexample
608$ @b{@value{GDBP} m4}
609@c FIXME: this falsifies the exact text played out, to permit smallbook
610@c FIXME... format to come out better.
611@value{GDBN} is free software and you are welcome to distribute copies
5d161b24 612 of it under certain conditions; type "show copying" to see
c906108c 613 the conditions.
5d161b24 614There is absolutely no warranty for @value{GDBN}; type "show warranty"
c906108c
SS
615 for details.
616
617@value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
618(@value{GDBP})
619@end smallexample
c906108c
SS
620
621@noindent
622@value{GDBN} reads only enough symbol data to know where to find the
623rest when needed; as a result, the first prompt comes up very quickly.
624We now tell @value{GDBN} to use a narrower display width than usual, so
625that examples fit in this manual.
626
627@smallexample
628(@value{GDBP}) @b{set width 70}
629@end smallexample
630
631@noindent
632We need to see how the @code{m4} built-in @code{changequote} works.
633Having looked at the source, we know the relevant subroutine is
634@code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
635@code{break} command.
636
637@smallexample
638(@value{GDBP}) @b{break m4_changequote}
639Breakpoint 1 at 0x62f4: file builtin.c, line 879.
640@end smallexample
641
642@noindent
643Using the @code{run} command, we start @code{m4} running under @value{GDBN}
644control; as long as control does not reach the @code{m4_changequote}
645subroutine, the program runs as usual:
646
647@smallexample
648(@value{GDBP}) @b{run}
649Starting program: /work/Editorial/gdb/gnu/m4/m4
650@b{define(foo,0000)}
651
652@b{foo}
6530000
654@end smallexample
655
656@noindent
657To trigger the breakpoint, we call @code{changequote}. @value{GDBN}
658suspends execution of @code{m4}, displaying information about the
659context where it stops.
660
661@smallexample
662@b{changequote(<QUOTE>,<UNQUOTE>)}
663
5d161b24 664Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
665 at builtin.c:879
666879 if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
667@end smallexample
668
669@noindent
670Now we use the command @code{n} (@code{next}) to advance execution to
671the next line of the current function.
672
673@smallexample
674(@value{GDBP}) @b{n}
675882 set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
676 : nil,
677@end smallexample
678
679@noindent
680@code{set_quotes} looks like a promising subroutine. We can go into it
681by using the command @code{s} (@code{step}) instead of @code{next}.
682@code{step} goes to the next line to be executed in @emph{any}
683subroutine, so it steps into @code{set_quotes}.
684
685@smallexample
686(@value{GDBP}) @b{s}
687set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
688 at input.c:530
689530 if (lquote != def_lquote)
690@end smallexample
691
692@noindent
693The display that shows the subroutine where @code{m4} is now
694suspended (and its arguments) is called a stack frame display. It
695shows a summary of the stack. We can use the @code{backtrace}
696command (which can also be spelled @code{bt}), to see where we are
697in the stack as a whole: the @code{backtrace} command displays a
698stack frame for each active subroutine.
699
700@smallexample
701(@value{GDBP}) @b{bt}
702#0 set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
703 at input.c:530
5d161b24 704#1 0x6344 in m4_changequote (argc=3, argv=0x33c70)
c906108c
SS
705 at builtin.c:882
706#2 0x8174 in expand_macro (sym=0x33320) at macro.c:242
707#3 0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
708 at macro.c:71
709#4 0x79dc in expand_input () at macro.c:40
710#5 0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
711@end smallexample
712
713@noindent
714We step through a few more lines to see what happens. The first two
715times, we can use @samp{s}; the next two times we use @code{n} to avoid
716falling into the @code{xstrdup} subroutine.
717
718@smallexample
719(@value{GDBP}) @b{s}
7200x3b5c 532 if (rquote != def_rquote)
721(@value{GDBP}) @b{s}
7220x3b80 535 lquote = (lq == nil || *lq == '\0') ? \
723def_lquote : xstrdup(lq);
724(@value{GDBP}) @b{n}
725536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
726 : xstrdup(rq);
727(@value{GDBP}) @b{n}
728538 len_lquote = strlen(rquote);
729@end smallexample
730
731@noindent
732The last line displayed looks a little odd; we can examine the variables
733@code{lquote} and @code{rquote} to see if they are in fact the new left
734and right quotes we specified. We use the command @code{p}
735(@code{print}) to see their values.
736
737@smallexample
738(@value{GDBP}) @b{p lquote}
739$1 = 0x35d40 "<QUOTE>"
740(@value{GDBP}) @b{p rquote}
741$2 = 0x35d50 "<UNQUOTE>"
742@end smallexample
743
744@noindent
745@code{lquote} and @code{rquote} are indeed the new left and right quotes.
746To look at some context, we can display ten lines of source
747surrounding the current line with the @code{l} (@code{list}) command.
748
749@smallexample
750(@value{GDBP}) @b{l}
751533 xfree(rquote);
752534
753535 lquote = (lq == nil || *lq == '\0') ? def_lquote\
754 : xstrdup (lq);
755536 rquote = (rq == nil || *rq == '\0') ? def_rquote\
756 : xstrdup (rq);
757537
758538 len_lquote = strlen(rquote);
759539 len_rquote = strlen(lquote);
760540 @}
761541
762542 void
763@end smallexample
764
765@noindent
766Let us step past the two lines that set @code{len_lquote} and
767@code{len_rquote}, and then examine the values of those variables.
768
769@smallexample
770(@value{GDBP}) @b{n}
771539 len_rquote = strlen(lquote);
772(@value{GDBP}) @b{n}
773540 @}
774(@value{GDBP}) @b{p len_lquote}
775$3 = 9
776(@value{GDBP}) @b{p len_rquote}
777$4 = 7
778@end smallexample
779
780@noindent
781That certainly looks wrong, assuming @code{len_lquote} and
782@code{len_rquote} are meant to be the lengths of @code{lquote} and
783@code{rquote} respectively. We can set them to better values using
784the @code{p} command, since it can print the value of
785any expression---and that expression can include subroutine calls and
786assignments.
787
788@smallexample
789(@value{GDBP}) @b{p len_lquote=strlen(lquote)}
790$5 = 7
791(@value{GDBP}) @b{p len_rquote=strlen(rquote)}
792$6 = 9
793@end smallexample
794
795@noindent
796Is that enough to fix the problem of using the new quotes with the
797@code{m4} built-in @code{defn}? We can allow @code{m4} to continue
798executing with the @code{c} (@code{continue}) command, and then try the
799example that caused trouble initially:
800
801@smallexample
802(@value{GDBP}) @b{c}
803Continuing.
804
805@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
806
807baz
8080000
809@end smallexample
810
811@noindent
812Success! The new quotes now work just as well as the default ones. The
813problem seems to have been just the two typos defining the wrong
814lengths. We allow @code{m4} exit by giving it an EOF as input:
815
816@smallexample
c8aa23ab 817@b{Ctrl-d}
c906108c
SS
818Program exited normally.
819@end smallexample
820
821@noindent
822The message @samp{Program exited normally.} is from @value{GDBN}; it
823indicates @code{m4} has finished executing. We can end our @value{GDBN}
824session with the @value{GDBN} @code{quit} command.
825
826@smallexample
827(@value{GDBP}) @b{quit}
828@end smallexample
c906108c 829
6d2ebf8b 830@node Invocation
c906108c
SS
831@chapter Getting In and Out of @value{GDBN}
832
833This chapter discusses how to start @value{GDBN}, and how to get out of it.
5d161b24 834The essentials are:
c906108c 835@itemize @bullet
5d161b24 836@item
53a5351d 837type @samp{@value{GDBP}} to start @value{GDBN}.
5d161b24 838@item
c8aa23ab 839type @kbd{quit} or @kbd{Ctrl-d} to exit.
c906108c
SS
840@end itemize
841
842@menu
843* Invoking GDB:: How to start @value{GDBN}
844* Quitting GDB:: How to quit @value{GDBN}
845* Shell Commands:: How to use shell commands inside @value{GDBN}
79a6e687 846* Logging Output:: How to log @value{GDBN}'s output to a file
c906108c
SS
847@end menu
848
6d2ebf8b 849@node Invoking GDB
c906108c
SS
850@section Invoking @value{GDBN}
851
c906108c
SS
852Invoke @value{GDBN} by running the program @code{@value{GDBP}}. Once started,
853@value{GDBN} reads commands from the terminal until you tell it to exit.
854
855You can also run @code{@value{GDBP}} with a variety of arguments and options,
856to specify more of your debugging environment at the outset.
857
c906108c
SS
858The command-line options described here are designed
859to cover a variety of situations; in some environments, some of these
5d161b24 860options may effectively be unavailable.
c906108c
SS
861
862The most usual way to start @value{GDBN} is with one argument,
863specifying an executable program:
864
474c8240 865@smallexample
c906108c 866@value{GDBP} @var{program}
474c8240 867@end smallexample
c906108c 868
c906108c
SS
869@noindent
870You can also start with both an executable program and a core file
871specified:
872
474c8240 873@smallexample
c906108c 874@value{GDBP} @var{program} @var{core}
474c8240 875@end smallexample
c906108c 876
4ed4690f
SM
877You can, instead, specify a process ID as a second argument or use option
878@code{-p}, if you want to debug a running process:
c906108c 879
474c8240 880@smallexample
c906108c 881@value{GDBP} @var{program} 1234
4ed4690f 882@value{GDBP} -p 1234
474c8240 883@end smallexample
c906108c
SS
884
885@noindent
4ed4690f
SM
886would attach @value{GDBN} to process @code{1234}. With option @option{-p} you
887can omit the @var{program} filename.
c906108c 888
c906108c 889Taking advantage of the second command-line argument requires a fairly
2df3850c
JM
890complete operating system; when you use @value{GDBN} as a remote
891debugger attached to a bare board, there may not be any notion of
892``process'', and there is often no way to get a core dump. @value{GDBN}
893will warn you if it is unable to attach or to read core dumps.
c906108c 894
aa26fa3a
TT
895You can optionally have @code{@value{GDBP}} pass any arguments after the
896executable file to the inferior using @code{--args}. This option stops
897option processing.
474c8240 898@smallexample
3f94c067 899@value{GDBP} --args gcc -O2 -c foo.c
474c8240 900@end smallexample
aa26fa3a
TT
901This will cause @code{@value{GDBP}} to debug @code{gcc}, and to set
902@code{gcc}'s command-line arguments (@pxref{Arguments}) to @samp{-O2 -c foo.c}.
903
96a2c332 904You can run @code{@value{GDBP}} without printing the front material, which describes
adcc0a31 905@value{GDBN}'s non-warranty, by specifying @code{--silent}
906(or @code{-q}/@code{--quiet}):
c906108c
SS
907
908@smallexample
adcc0a31 909@value{GDBP} --silent
c906108c
SS
910@end smallexample
911
912@noindent
913You can further control how @value{GDBN} starts up by using command-line
914options. @value{GDBN} itself can remind you of the options available.
915
916@noindent
917Type
918
474c8240 919@smallexample
c906108c 920@value{GDBP} -help
474c8240 921@end smallexample
c906108c
SS
922
923@noindent
924to display all available options and briefly describe their use
925(@samp{@value{GDBP} -h} is a shorter equivalent).
926
927All options and command line arguments you give are processed
928in sequential order. The order makes a difference when the
929@samp{-x} option is used.
930
931
932@menu
c906108c
SS
933* File Options:: Choosing files
934* Mode Options:: Choosing modes
6fc08d32 935* Startup:: What @value{GDBN} does during startup
c906108c
SS
936@end menu
937
6d2ebf8b 938@node File Options
79a6e687 939@subsection Choosing Files
c906108c 940
2df3850c 941When @value{GDBN} starts, it reads any arguments other than options as
c906108c
SS
942specifying an executable file and core file (or process ID). This is
943the same as if the arguments were specified by the @samp{-se} and
d52fb0e9 944@samp{-c} (or @samp{-p}) options respectively. (@value{GDBN} reads the
19837790
MS
945first argument that does not have an associated option flag as
946equivalent to the @samp{-se} option followed by that argument; and the
947second argument that does not have an associated option flag, if any, as
948equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
949If the second argument begins with a decimal digit, @value{GDBN} will
950first attempt to attach to it as a process, and if that fails, attempt
951to open it as a corefile. If you have a corefile whose name begins with
b383017d 952a digit, you can prevent @value{GDBN} from treating it as a pid by
c1468174 953prefixing it with @file{./}, e.g.@: @file{./12345}.
7a292a7a
SS
954
955If @value{GDBN} has not been configured to included core file support,
956such as for most embedded targets, then it will complain about a second
957argument and ignore it.
c906108c
SS
958
959Many options have both long and short forms; both are shown in the
960following list. @value{GDBN} also recognizes the long forms if you truncate
961them, so long as enough of the option is present to be unambiguous.
962(If you prefer, you can flag option arguments with @samp{--} rather
963than @samp{-}, though we illustrate the more usual convention.)
964
d700128c
EZ
965@c NOTE: the @cindex entries here use double dashes ON PURPOSE. This
966@c way, both those who look for -foo and --foo in the index, will find
967@c it.
968
c906108c
SS
969@table @code
970@item -symbols @var{file}
971@itemx -s @var{file}
d700128c
EZ
972@cindex @code{--symbols}
973@cindex @code{-s}
c906108c
SS
974Read symbol table from file @var{file}.
975
976@item -exec @var{file}
977@itemx -e @var{file}
d700128c
EZ
978@cindex @code{--exec}
979@cindex @code{-e}
7a292a7a
SS
980Use file @var{file} as the executable file to execute when appropriate,
981and for examining pure data in conjunction with a core dump.
c906108c
SS
982
983@item -se @var{file}
d700128c 984@cindex @code{--se}
c906108c
SS
985Read symbol table from file @var{file} and use it as the executable
986file.
987
c906108c
SS
988@item -core @var{file}
989@itemx -c @var{file}
d700128c
EZ
990@cindex @code{--core}
991@cindex @code{-c}
b383017d 992Use file @var{file} as a core dump to examine.
c906108c 993
19837790
MS
994@item -pid @var{number}
995@itemx -p @var{number}
996@cindex @code{--pid}
997@cindex @code{-p}
998Connect to process ID @var{number}, as with the @code{attach} command.
c906108c
SS
999
1000@item -command @var{file}
1001@itemx -x @var{file}
d700128c
EZ
1002@cindex @code{--command}
1003@cindex @code{-x}
95433b34
JB
1004Execute commands from file @var{file}. The contents of this file is
1005evaluated exactly as the @code{source} command would.
8150ff9c 1006@xref{Command Files,, Command files}.
c906108c 1007
8a5a3c82
AS
1008@item -eval-command @var{command}
1009@itemx -ex @var{command}
1010@cindex @code{--eval-command}
1011@cindex @code{-ex}
1012Execute a single @value{GDBN} command.
1013
1014This option may be used multiple times to call multiple commands. It may
1015also be interleaved with @samp{-command} as required.
1016
1017@smallexample
1018@value{GDBP} -ex 'target sim' -ex 'load' \
1019 -x setbreakpoints -ex 'run' a.out
1020@end smallexample
1021
8320cc4f
JK
1022@item -init-command @var{file}
1023@itemx -ix @var{file}
1024@cindex @code{--init-command}
1025@cindex @code{-ix}
2d7b58e8
JK
1026Execute commands from file @var{file} before loading the inferior (but
1027after loading gdbinit files).
8320cc4f
JK
1028@xref{Startup}.
1029
1030@item -init-eval-command @var{command}
1031@itemx -iex @var{command}
1032@cindex @code{--init-eval-command}
1033@cindex @code{-iex}
2d7b58e8
JK
1034Execute a single @value{GDBN} command before loading the inferior (but
1035after loading gdbinit files).
8320cc4f
JK
1036@xref{Startup}.
1037
c906108c
SS
1038@item -directory @var{directory}
1039@itemx -d @var{directory}
d700128c
EZ
1040@cindex @code{--directory}
1041@cindex @code{-d}
4b505b12 1042Add @var{directory} to the path to search for source and script files.
c906108c 1043
c906108c
SS
1044@item -r
1045@itemx -readnow
d700128c
EZ
1046@cindex @code{--readnow}
1047@cindex @code{-r}
c906108c
SS
1048Read each symbol file's entire symbol table immediately, rather than
1049the default, which is to read it incrementally as it is needed.
1050This makes startup slower, but makes future operations faster.
53a5351d 1051
97cbe998
SDJ
1052@item --readnever
1053@anchor{--readnever}
1054@cindex @code{--readnever}, command-line option
1055Do not read each symbol file's symbolic debug information. This makes
1056startup faster but at the expense of not being able to perform
1057symbolic debugging. DWARF unwind information is also not read,
1058meaning backtraces may become incomplete or inaccurate. One use of
1059this is when a user simply wants to do the following sequence: attach,
1060dump core, detach. Loading the debugging information in this case is
1061an unnecessary cause of delay.
c906108c
SS
1062@end table
1063
6d2ebf8b 1064@node Mode Options
79a6e687 1065@subsection Choosing Modes
c906108c
SS
1066
1067You can run @value{GDBN} in various alternative modes---for example, in
1068batch mode or quiet mode.
1069
1070@table @code
bf88dd68 1071@anchor{-nx}
c906108c
SS
1072@item -nx
1073@itemx -n
d700128c
EZ
1074@cindex @code{--nx}
1075@cindex @code{-n}
07540c15
DE
1076Do not execute commands found in any initialization file.
1077There are three init files, loaded in the following order:
1078
1079@table @code
1080@item @file{system.gdbinit}
1081This is the system-wide init file.
1082Its location is specified with the @code{--with-system-gdbinit}
1083configure option (@pxref{System-wide configuration}).
1084It is loaded first when @value{GDBN} starts, before command line options
1085have been processed.
ed2a2229
CB
1086@item @file{system.gdbinit.d}
1087This is the system-wide init directory.
1088Its location is specified with the @code{--with-system-gdbinit-dir}
1089configure option (@pxref{System-wide configuration}).
1090Files in this directory are loaded in alphabetical order immediately after
1091system.gdbinit (if enabled) when @value{GDBN} starts, before command line
1092options have been processed. Files need to have a recognized scripting
1093language extension (@file{.py}/@file{.scm}) or be named with a @file{.gdb}
1094extension to be interpreted as regular @value{GDBN} commands. @value{GDBN}
1095will not recurse into any subdirectories of this directory.
07540c15
DE
1096@item @file{~/.gdbinit}
1097This is the init file in your home directory.
1098It is loaded next, after @file{system.gdbinit}, and before
1099command options have been processed.
1100@item @file{./.gdbinit}
1101This is the init file in the current directory.
1102It is loaded last, after command line options other than @code{-x} and
1103@code{-ex} have been processed. Command line options @code{-x} and
1104@code{-ex} are processed last, after @file{./.gdbinit} has been loaded.
1105@end table
1106
1107For further documentation on startup processing, @xref{Startup}.
1108For documentation on how to write command files,
1109@xref{Command Files,,Command Files}.
1110
1111@anchor{-nh}
1112@item -nh
1113@cindex @code{--nh}
1114Do not execute commands found in @file{~/.gdbinit}, the init file
1115in your home directory.
1116@xref{Startup}.
c906108c
SS
1117
1118@item -quiet
d700128c 1119@itemx -silent
c906108c 1120@itemx -q
d700128c
EZ
1121@cindex @code{--quiet}
1122@cindex @code{--silent}
1123@cindex @code{-q}
c906108c
SS
1124``Quiet''. Do not print the introductory and copyright messages. These
1125messages are also suppressed in batch mode.
1126
1127@item -batch
d700128c 1128@cindex @code{--batch}
c906108c
SS
1129Run in batch mode. Exit with status @code{0} after processing all the
1130command files specified with @samp{-x} (and all commands from
1131initialization files, if not inhibited with @samp{-n}). Exit with
1132nonzero status if an error occurs in executing the @value{GDBN} commands
5da1313b
JK
1133in the command files. Batch mode also disables pagination, sets unlimited
1134terminal width and height @pxref{Screen Size}, and acts as if @kbd{set confirm
1135off} were in effect (@pxref{Messages/Warnings}).
c906108c 1136
2df3850c
JM
1137Batch mode may be useful for running @value{GDBN} as a filter, for
1138example to download and run a program on another computer; in order to
1139make this more useful, the message
c906108c 1140
474c8240 1141@smallexample
c906108c 1142Program exited normally.
474c8240 1143@end smallexample
c906108c
SS
1144
1145@noindent
2df3850c
JM
1146(which is ordinarily issued whenever a program running under
1147@value{GDBN} control terminates) is not issued when running in batch
1148mode.
1149
1a088d06
AS
1150@item -batch-silent
1151@cindex @code{--batch-silent}
1152Run in batch mode exactly like @samp{-batch}, but totally silently. All
1153@value{GDBN} output to @code{stdout} is prevented (@code{stderr} is
1154unaffected). This is much quieter than @samp{-silent} and would be useless
1155for an interactive session.
1156
1157This is particularly useful when using targets that give @samp{Loading section}
1158messages, for example.
1159
1160Note that targets that give their output via @value{GDBN}, as opposed to
1161writing directly to @code{stdout}, will also be made silent.
1162
4b0ad762
AS
1163@item -return-child-result
1164@cindex @code{--return-child-result}
1165The return code from @value{GDBN} will be the return code from the child
1166process (the process being debugged), with the following exceptions:
1167
1168@itemize @bullet
1169@item
1170@value{GDBN} exits abnormally. E.g., due to an incorrect argument or an
1171internal error. In this case the exit code is the same as it would have been
1172without @samp{-return-child-result}.
1173@item
1174The user quits with an explicit value. E.g., @samp{quit 1}.
1175@item
1176The child process never runs, or is not allowed to terminate, in which case
1177the exit code will be -1.
1178@end itemize
1179
1180This option is useful in conjunction with @samp{-batch} or @samp{-batch-silent},
1181when @value{GDBN} is being used as a remote program loader or simulator
1182interface.
1183
2df3850c
JM
1184@item -nowindows
1185@itemx -nw
d700128c
EZ
1186@cindex @code{--nowindows}
1187@cindex @code{-nw}
2df3850c 1188``No windows''. If @value{GDBN} comes with a graphical user interface
96a2c332 1189(GUI) built in, then this option tells @value{GDBN} to only use the command-line
2df3850c
JM
1190interface. If no GUI is available, this option has no effect.
1191
1192@item -windows
1193@itemx -w
d700128c
EZ
1194@cindex @code{--windows}
1195@cindex @code{-w}
2df3850c
JM
1196If @value{GDBN} includes a GUI, then this option requires it to be
1197used if possible.
c906108c
SS
1198
1199@item -cd @var{directory}
d700128c 1200@cindex @code{--cd}
c906108c
SS
1201Run @value{GDBN} using @var{directory} as its working directory,
1202instead of the current directory.
1203
aae1c79a 1204@item -data-directory @var{directory}
8d551b02 1205@itemx -D @var{directory}
aae1c79a 1206@cindex @code{--data-directory}
8d551b02 1207@cindex @code{-D}
aae1c79a
DE
1208Run @value{GDBN} using @var{directory} as its data directory.
1209The data directory is where @value{GDBN} searches for its
1210auxiliary files. @xref{Data Files}.
1211
c906108c
SS
1212@item -fullname
1213@itemx -f
d700128c
EZ
1214@cindex @code{--fullname}
1215@cindex @code{-f}
7a292a7a
SS
1216@sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1217subprocess. It tells @value{GDBN} to output the full file name and line
1218number in a standard, recognizable fashion each time a stack frame is
1219displayed (which includes each time your program stops). This
1220recognizable format looks like two @samp{\032} characters, followed by
1221the file name, line number and character position separated by colons,
1222and a newline. The Emacs-to-@value{GDBN} interface program uses the two
1223@samp{\032} characters as a signal to display the source code for the
1224frame.
c906108c 1225
d700128c
EZ
1226@item -annotate @var{level}
1227@cindex @code{--annotate}
1228This option sets the @dfn{annotation level} inside @value{GDBN}. Its
1229effect is identical to using @samp{set annotate @var{level}}
086432e2
AC
1230(@pxref{Annotations}). The annotation @var{level} controls how much
1231information @value{GDBN} prints together with its prompt, values of
1232expressions, source lines, and other types of output. Level 0 is the
1233normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1234@sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1235that control @value{GDBN}, and level 2 has been deprecated.
1236
265eeb58 1237The annotation mechanism has largely been superseded by @sc{gdb/mi}
086432e2 1238(@pxref{GDB/MI}).
d700128c 1239
aa26fa3a
TT
1240@item --args
1241@cindex @code{--args}
1242Change interpretation of command line so that arguments following the
1243executable file are passed as command line arguments to the inferior.
1244This option stops option processing.
1245
2df3850c
JM
1246@item -baud @var{bps}
1247@itemx -b @var{bps}
d700128c
EZ
1248@cindex @code{--baud}
1249@cindex @code{-b}
c906108c
SS
1250Set the line speed (baud rate or bits per second) of any serial
1251interface used by @value{GDBN} for remote debugging.
c906108c 1252
f47b1503
AS
1253@item -l @var{timeout}
1254@cindex @code{-l}
1255Set the timeout (in seconds) of any communication used by @value{GDBN}
1256for remote debugging.
1257
c906108c 1258@item -tty @var{device}
d700128c
EZ
1259@itemx -t @var{device}
1260@cindex @code{--tty}
1261@cindex @code{-t}
c906108c
SS
1262Run using @var{device} for your program's standard input and output.
1263@c FIXME: kingdon thinks there is more to -tty. Investigate.
c906108c 1264
53a5351d 1265@c resolve the situation of these eventually
c4555f82
SC
1266@item -tui
1267@cindex @code{--tui}
d0d5df6f
AC
1268Activate the @dfn{Text User Interface} when starting. The Text User
1269Interface manages several text windows on the terminal, showing
1270source, assembly, registers and @value{GDBN} command outputs
217bff3e
JK
1271(@pxref{TUI, ,@value{GDBN} Text User Interface}). Do not use this
1272option if you run @value{GDBN} from Emacs (@pxref{Emacs, ,
1273Using @value{GDBN} under @sc{gnu} Emacs}).
53a5351d 1274
d700128c
EZ
1275@item -interpreter @var{interp}
1276@cindex @code{--interpreter}
1277Use the interpreter @var{interp} for interface with the controlling
1278program or device. This option is meant to be set by programs which
94bbb2c0 1279communicate with @value{GDBN} using it as a back end.
21c294e6 1280@xref{Interpreters, , Command Interpreters}.
94bbb2c0 1281
b4be1b06
SM
1282@samp{--interpreter=mi} (or @samp{--interpreter=mi3}) causes
1283@value{GDBN} to use the @dfn{@sc{gdb/mi} interface} version 3 (@pxref{GDB/MI, ,
1284The @sc{gdb/mi} Interface}) included since @value{GDBN} version 9.1. @sc{gdb/mi}
1285version 2 (@code{mi2}), included in @value{GDBN} 6.0 and version 1 (@code{mi1}),
1286included in @value{GDBN} 5.3, are also available. Earlier @sc{gdb/mi}
1287interfaces are no longer supported.
d700128c
EZ
1288
1289@item -write
1290@cindex @code{--write}
1291Open the executable and core files for both reading and writing. This
1292is equivalent to the @samp{set write on} command inside @value{GDBN}
1293(@pxref{Patching}).
1294
1295@item -statistics
1296@cindex @code{--statistics}
1297This option causes @value{GDBN} to print statistics about time and
1298memory usage after it completes each command and returns to the prompt.
1299
1300@item -version
1301@cindex @code{--version}
1302This option causes @value{GDBN} to print its version number and
1303no-warranty blurb, and exit.
1304
6eaaf48b
EZ
1305@item -configuration
1306@cindex @code{--configuration}
1307This option causes @value{GDBN} to print details about its build-time
1308configuration parameters, and then exit. These details can be
1309important when reporting @value{GDBN} bugs (@pxref{GDB Bugs}).
1310
c906108c
SS
1311@end table
1312
6fc08d32 1313@node Startup
79a6e687 1314@subsection What @value{GDBN} Does During Startup
6fc08d32
EZ
1315@cindex @value{GDBN} startup
1316
1317Here's the description of what @value{GDBN} does during session startup:
1318
1319@enumerate
1320@item
1321Sets up the command interpreter as specified by the command line
1322(@pxref{Mode Options, interpreter}).
1323
1324@item
1325@cindex init file
098b41a6
JG
1326Reads the system-wide @dfn{init file} (if @option{--with-system-gdbinit} was
1327used when building @value{GDBN}; @pxref{System-wide configuration,
ed2a2229
CB
1328 ,System-wide configuration and settings}) and the files in the system-wide
1329gdbinit directory (if @option{--with-system-gdbinit-dir} was used) and executes
1330all the commands in those files. The files need to be named with a @file{.gdb}
1331extension to be interpreted as @value{GDBN} commands, or they can be written
1332in a supported scripting language with an appropriate file extension.
098b41a6 1333
bf88dd68 1334@anchor{Home Directory Init File}
098b41a6
JG
1335@item
1336Reads the init file (if any) in your home directory@footnote{On
6fc08d32
EZ
1337DOS/Windows systems, the home directory is the one pointed to by the
1338@code{HOME} environment variable.} and executes all the commands in
1339that file.
1340
2d7b58e8
JK
1341@anchor{Option -init-eval-command}
1342@item
1343Executes commands and command files specified by the @samp{-iex} and
1344@samp{-ix} options in their specified order. Usually you should use the
1345@samp{-ex} and @samp{-x} options instead, but this way you can apply
1346settings before @value{GDBN} init files get executed and before inferior
1347gets loaded.
1348
6fc08d32
EZ
1349@item
1350Processes command line options and operands.
1351
bf88dd68 1352@anchor{Init File in the Current Directory during Startup}
6fc08d32
EZ
1353@item
1354Reads and executes the commands from init file (if any) in the current
bf88dd68
JK
1355working directory as long as @samp{set auto-load local-gdbinit} is set to
1356@samp{on} (@pxref{Init File in the Current Directory}).
1357This is only done if the current directory is
119b882a
EZ
1358different from your home directory. Thus, you can have more than one
1359init file, one generic in your home directory, and another, specific
1360to the program you are debugging, in the directory where you invoke
6fc08d32
EZ
1361@value{GDBN}.
1362
a86caf66
DE
1363@item
1364If the command line specified a program to debug, or a process to
1365attach to, or a core file, @value{GDBN} loads any auto-loaded
1366scripts provided for the program or for its loaded shared libraries.
1367@xref{Auto-loading}.
1368
1369If you wish to disable the auto-loading during startup,
1370you must do something like the following:
1371
1372@smallexample
bf88dd68 1373$ gdb -iex "set auto-load python-scripts off" myprogram
a86caf66
DE
1374@end smallexample
1375
8320cc4f
JK
1376Option @samp{-ex} does not work because the auto-loading is then turned
1377off too late.
a86caf66 1378
6fc08d32 1379@item
6fe37d23
JK
1380Executes commands and command files specified by the @samp{-ex} and
1381@samp{-x} options in their specified order. @xref{Command Files}, for
1382more details about @value{GDBN} command files.
6fc08d32
EZ
1383
1384@item
1385Reads the command history recorded in the @dfn{history file}.
d620b259 1386@xref{Command History}, for more details about the command history and the
6fc08d32
EZ
1387files where @value{GDBN} records it.
1388@end enumerate
1389
1390Init files use the same syntax as @dfn{command files} (@pxref{Command
1391Files}) and are processed by @value{GDBN} in the same way. The init
1392file in your home directory can set options (such as @samp{set
1393complaints}) that affect subsequent processing of command line options
1394and operands. Init files are not executed if you use the @samp{-nx}
79a6e687 1395option (@pxref{Mode Options, ,Choosing Modes}).
6fc08d32 1396
098b41a6
JG
1397To display the list of init files loaded by gdb at startup, you
1398can use @kbd{gdb --help}.
1399
6fc08d32
EZ
1400@cindex init file name
1401@cindex @file{.gdbinit}
119b882a 1402@cindex @file{gdb.ini}
8807d78b 1403The @value{GDBN} init files are normally called @file{.gdbinit}.
119b882a
EZ
1404The DJGPP port of @value{GDBN} uses the name @file{gdb.ini}, due to
1405the limitations of file names imposed by DOS filesystems. The Windows
4d3f93a2
JB
1406port of @value{GDBN} uses the standard name, but if it finds a
1407@file{gdb.ini} file in your home directory, it warns you about that
1408and suggests to rename the file to the standard name.
119b882a 1409
6fc08d32 1410
6d2ebf8b 1411@node Quitting GDB
c906108c
SS
1412@section Quitting @value{GDBN}
1413@cindex exiting @value{GDBN}
1414@cindex leaving @value{GDBN}
1415
1416@table @code
1417@kindex quit @r{[}@var{expression}@r{]}
41afff9a 1418@kindex q @r{(@code{quit})}
96a2c332
SS
1419@item quit @r{[}@var{expression}@r{]}
1420@itemx q
1421To exit @value{GDBN}, use the @code{quit} command (abbreviated
c8aa23ab 1422@code{q}), or type an end-of-file character (usually @kbd{Ctrl-d}). If you
96a2c332
SS
1423do not supply @var{expression}, @value{GDBN} will terminate normally;
1424otherwise it will terminate using the result of @var{expression} as the
1425error code.
c906108c
SS
1426@end table
1427
1428@cindex interrupt
c8aa23ab 1429An interrupt (often @kbd{Ctrl-c}) does not exit from @value{GDBN}, but rather
c906108c
SS
1430terminates the action of any @value{GDBN} command that is in progress and
1431returns to @value{GDBN} command level. It is safe to type the interrupt
1432character at any time because @value{GDBN} does not allow it to take effect
1433until a time when it is safe.
1434
c906108c
SS
1435If you have been using @value{GDBN} to control an attached process or
1436device, you can release it with the @code{detach} command
79a6e687 1437(@pxref{Attach, ,Debugging an Already-running Process}).
c906108c 1438
6d2ebf8b 1439@node Shell Commands
79a6e687 1440@section Shell Commands
c906108c
SS
1441
1442If you need to execute occasional shell commands during your
1443debugging session, there is no need to leave or suspend @value{GDBN}; you can
1444just use the @code{shell} command.
1445
1446@table @code
1447@kindex shell
ed59ded5 1448@kindex !
c906108c 1449@cindex shell escape
ed59ded5
DE
1450@item shell @var{command-string}
1451@itemx !@var{command-string}
1452Invoke a standard shell to execute @var{command-string}.
1453Note that no space is needed between @code{!} and @var{command-string}.
c906108c 1454If it exists, the environment variable @code{SHELL} determines which
d4f3574e
SS
1455shell to run. Otherwise @value{GDBN} uses the default shell
1456(@file{/bin/sh} on Unix systems, @file{COMMAND.COM} on MS-DOS, etc.).
c906108c
SS
1457@end table
1458
1459The utility @code{make} is often needed in development environments.
1460You do not have to use the @code{shell} command for this purpose in
1461@value{GDBN}:
1462
1463@table @code
1464@kindex make
1465@cindex calling make
1466@item make @var{make-args}
1467Execute the @code{make} program with the specified
1468arguments. This is equivalent to @samp{shell make @var{make-args}}.
1469@end table
1470
e2c52041
PW
1471@table @code
1472@kindex pipe
1473@kindex |
1474@cindex send the output of a gdb command to a shell command
1475@anchor{pipe}
1476@item pipe [@var{command}] | @var{shell_command}
1477@itemx | [@var{command}] | @var{shell_command}
1478@itemx pipe -d @var{delim} @var{command} @var{delim} @var{shell_command}
1479@itemx | -d @var{delim} @var{command} @var{delim} @var{shell_command}
1480Executes @var{command} and sends its output to @var{shell_command}.
1481Note that no space is needed around @code{|}.
1482If no @var{command} is provided, the last command executed is repeated.
1483
1484In case the @var{command} contains a @code{|}, the option @code{-d @var{delim}}
1485can be used to specify an alternate delimiter string @var{delim} that separates
1486the @var{command} from the @var{shell_command}.
1487
1488Example:
1489@smallexample
1490@group
1491(gdb) p var
1492$1 = @{
1493 black = 144,
1494 red = 233,
1495 green = 377,
1496 blue = 610,
1497 white = 987
1498@}
1499@end group
1500@group
1501(gdb) pipe p var|wc
1502 7 19 80
1503(gdb) |p var|wc -l
15047
1505@end group
1506@group
1507(gdb) p /x var
1508$4 = @{
1509 black = 0x90,
1510 red = 0xe9,
1511 green = 0x179,
1512 blue = 0x262,
1513 white = 0x3db
1514@}
1515(gdb) ||grep red
1516 red => 0xe9,
1517@end group
1518@group
1519(gdb) | -d ! echo this contains a | char\n ! sed -e 's/|/PIPE/'
1520this contains a PIPE char
1521(gdb) | -d xxx echo this contains a | char!\n xxx sed -e 's/|/PIPE/'
1522this contains a PIPE char!
1523(gdb)
1524@end group
1525@end smallexample
1526@end table
1527
1528The convenience variables @code{$_shell_exitcode} and @code{$_shell_exitsignal}
1529can be used to examine the exit status of the last shell command launched
1530by @code{shell}, @code{make}, @code{pipe} and @code{|}.
1531@xref{Convenience Vars,, Convenience Variables}.
1532
79a6e687
BW
1533@node Logging Output
1534@section Logging Output
0fac0b41 1535@cindex logging @value{GDBN} output
9c16f35a 1536@cindex save @value{GDBN} output to a file
0fac0b41
DJ
1537
1538You may want to save the output of @value{GDBN} commands to a file.
1539There are several commands to control @value{GDBN}'s logging.
1540
1541@table @code
1542@kindex set logging
1543@item set logging on
1544Enable logging.
1545@item set logging off
1546Disable logging.
9c16f35a 1547@cindex logging file name
0fac0b41
DJ
1548@item set logging file @var{file}
1549Change the name of the current logfile. The default logfile is @file{gdb.txt}.
1550@item set logging overwrite [on|off]
1551By default, @value{GDBN} will append to the logfile. Set @code{overwrite} if
1552you want @code{set logging on} to overwrite the logfile instead.
1553@item set logging redirect [on|off]
1554By default, @value{GDBN} output will go to both the terminal and the logfile.
1555Set @code{redirect} if you want output to go only to the log file.
b7060614
AH
1556@item set logging debugredirect [on|off]
1557By default, @value{GDBN} debug output will go to both the terminal and the logfile.
1558Set @code{debugredirect} if you want debug output to go only to the log file.
0fac0b41
DJ
1559@kindex show logging
1560@item show logging
1561Show the current values of the logging settings.
1562@end table
1563
e2c52041
PW
1564You can also redirect the output of a @value{GDBN} command to a
1565shell command. @xref{pipe}.
6d2ebf8b 1566@node Commands
c906108c
SS
1567@chapter @value{GDBN} Commands
1568
1569You can abbreviate a @value{GDBN} command to the first few letters of the command
1570name, if that abbreviation is unambiguous; and you can repeat certain
1571@value{GDBN} commands by typing just @key{RET}. You can also use the @key{TAB}
1572key to get @value{GDBN} to fill out the rest of a word in a command (or to
1573show you the alternatives available, if there is more than one possibility).
1574
1575@menu
1576* Command Syntax:: How to give commands to @value{GDBN}
fdbc9870 1577* Command Settings:: How to change default behavior of commands
c906108c 1578* Completion:: Command completion
3345721a 1579* Command Options:: Command options
c906108c
SS
1580* Help:: How to ask @value{GDBN} for help
1581@end menu
1582
6d2ebf8b 1583@node Command Syntax
79a6e687 1584@section Command Syntax
c906108c
SS
1585
1586A @value{GDBN} command is a single line of input. There is no limit on
1587how long it can be. It starts with a command name, which is followed by
1588arguments whose meaning depends on the command name. For example, the
1589command @code{step} accepts an argument which is the number of times to
1590step, as in @samp{step 5}. You can also use the @code{step} command
96a2c332 1591with no arguments. Some commands do not allow any arguments.
c906108c
SS
1592
1593@cindex abbreviation
1594@value{GDBN} command names may always be truncated if that abbreviation is
1595unambiguous. Other possible command abbreviations are listed in the
1596documentation for individual commands. In some cases, even ambiguous
1597abbreviations are allowed; for example, @code{s} is specially defined as
1598equivalent to @code{step} even though there are other commands whose
1599names start with @code{s}. You can test abbreviations by using them as
1600arguments to the @code{help} command.
1601
1602@cindex repeating commands
41afff9a 1603@kindex RET @r{(repeat last command)}
c906108c 1604A blank line as input to @value{GDBN} (typing just @key{RET}) means to
96a2c332 1605repeat the previous command. Certain commands (for example, @code{run})
c906108c
SS
1606will not repeat this way; these are commands whose unintentional
1607repetition might cause trouble and which you are unlikely to want to
c45da7e6
EZ
1608repeat. User-defined commands can disable this feature; see
1609@ref{Define, dont-repeat}.
c906108c
SS
1610
1611The @code{list} and @code{x} commands, when you repeat them with
1612@key{RET}, construct new arguments rather than repeating
1613exactly as typed. This permits easy scanning of source or memory.
1614
1615@value{GDBN} can also use @key{RET} in another way: to partition lengthy
1616output, in a way similar to the common utility @code{more}
79a6e687 1617(@pxref{Screen Size,,Screen Size}). Since it is easy to press one
c906108c
SS
1618@key{RET} too many in this situation, @value{GDBN} disables command
1619repetition after any command that generates this sort of display.
1620
41afff9a 1621@kindex # @r{(a comment)}
c906108c
SS
1622@cindex comment
1623Any text from a @kbd{#} to the end of the line is a comment; it does
1624nothing. This is useful mainly in command files (@pxref{Command
79a6e687 1625Files,,Command Files}).
c906108c 1626
88118b3a 1627@cindex repeating command sequences
c8aa23ab
EZ
1628@kindex Ctrl-o @r{(operate-and-get-next)}
1629The @kbd{Ctrl-o} binding is useful for repeating a complex sequence of
7f9087cb 1630commands. This command accepts the current line, like @key{RET}, and
88118b3a
TT
1631then fetches the next line relative to the current line from the history
1632for editing.
1633
fdbc9870
PA
1634
1635@node Command Settings
1636@section Command Settings
1637@cindex default behavior of commands, changing
1638@cindex default settings, changing
1639
1640Many commands change their behavior according to command-specific
1641variables or settings. These settings can be changed with the
1642@code{set} subcommands. For example, the @code{print} command
1643(@pxref{Data, ,Examining Data}) prints arrays differently depending on
1644settings changeable with the commands @code{set print elements
1645NUMBER-OF-ELEMENTS} and @code{set print array-indexes}, among others.
1646
1647You can change these settings to your preference in the gdbinit files
1648loaded at @value{GDBN} startup. @xref{Startup}.
1649
1650The settings can also be changed interactively during the debugging
1651session. For example, to change the limit of array elements to print,
1652you can do the following:
1653@smallexample
1654(@value{GDBN}) set print elements 10
1655(@value{GDBN}) print some_array
1656$1 = @{0, 10, 20, 30, 40, 50, 60, 70, 80, 90...@}
1657@end smallexample
1658
1659The above @code{set print elements 10} command changes the number of
1660elements to print from the default of 200 to 10. If you only intend
1661this limit of 10 to be used for printing @code{some_array}, then you
1662must restore the limit back to 200, with @code{set print elements
1663200}.
1664
1665Some commands allow overriding settings with command options. For
1666example, the @code{print} command supports a number of options that
1667allow overriding relevant global print settings as set by @code{set
1668print} subcommands. @xref{print options}. The example above could be
1669rewritten as:
1670@smallexample
1671(@value{GDBN}) print -elements 10 -- some_array
1672$1 = @{0, 10, 20, 30, 40, 50, 60, 70, 80, 90...@}
1673@end smallexample
1674
1675Alternatively, you can use the @code{with} command to change a setting
1676temporarily, for the duration of a command invocation.
1677
1678@table @code
1679@kindex with command
1680@kindex w @r{(@code{with})}
1681@cindex settings
1682@cindex temporarily change settings
1683@item with @var{setting} [@var{value}] [-- @var{command}]
1684@itemx w @var{setting} [@var{value}] [-- @var{command}]
1685Temporarily set @var{setting} to @var{value} for the duration of
1686@var{command}.
1687
1688@var{setting} is any setting you can change with the @code{set}
1689subcommands. @var{value} is the value to assign to @code{setting}
1690while running @code{command}.
1691
1692If no @var{command} is provided, the last command executed is
1693repeated.
1694
1695If a @var{command} is provided, it must be preceded by a double dash
1696(@code{--}) separator. This is required because some settings accept
1697free-form arguments, such as expressions or filenames.
1698
1699For example, the command
1700@smallexample
1701(@value{GDBN}) with print array on -- print some_array
1702@end smallexample
1703@noindent
1704is equivalent to the following 3 commands:
1705@smallexample
1706(@value{GDBN}) set print array on
1707(@value{GDBN}) print some_array
1708(@value{GDBN}) set print array off
1709@end smallexample
1710
1711The @code{with} command is particularly useful when you want to
1712override a setting while running user-defined commands, or commands
1713defined in Python or Guile. @xref{Extending GDB,, Extending GDB}.
1714
1715@smallexample
1716(@value{GDBN}) with print pretty on -- my_complex_command
1717@end smallexample
1718
1719To change several settings for the same command, you can nest
1720@code{with} commands. For example, @code{with language ada -- with
1721print elements 10} temporarily changes the language to Ada and sets a
1722limit of 10 elements to print for arrays and strings.
1723
1724@end table
1725
6d2ebf8b 1726@node Completion
79a6e687 1727@section Command Completion
c906108c
SS
1728
1729@cindex completion
1730@cindex word completion
1731@value{GDBN} can fill in the rest of a word in a command for you, if there is
1732only one possibility; it can also show you what the valid possibilities
1733are for the next word in a command, at any time. This works for @value{GDBN}
3345721a
PA
1734commands, @value{GDBN} subcommands, command options, and the names of symbols
1735in your program.
c906108c
SS
1736
1737Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1738of a word. If there is only one possibility, @value{GDBN} fills in the
1739word, and waits for you to finish the command (or press @key{RET} to
1740enter it). For example, if you type
1741
1742@c FIXME "@key" does not distinguish its argument sufficiently to permit
1743@c complete accuracy in these examples; space introduced for clarity.
1744@c If texinfo enhancements make it unnecessary, it would be nice to
1745@c replace " @key" by "@key" in the following...
474c8240 1746@smallexample
c906108c 1747(@value{GDBP}) info bre @key{TAB}
474c8240 1748@end smallexample
c906108c
SS
1749
1750@noindent
1751@value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1752the only @code{info} subcommand beginning with @samp{bre}:
1753
474c8240 1754@smallexample
c906108c 1755(@value{GDBP}) info breakpoints
474c8240 1756@end smallexample
c906108c
SS
1757
1758@noindent
1759You can either press @key{RET} at this point, to run the @code{info
1760breakpoints} command, or backspace and enter something else, if
1761@samp{breakpoints} does not look like the command you expected. (If you
1762were sure you wanted @code{info breakpoints} in the first place, you
1763might as well just type @key{RET} immediately after @samp{info bre},
1764to exploit command abbreviations rather than command completion).
1765
1766If there is more than one possibility for the next word when you press
1767@key{TAB}, @value{GDBN} sounds a bell. You can either supply more
1768characters and try again, or just press @key{TAB} a second time;
1769@value{GDBN} displays all the possible completions for that word. For
1770example, you might want to set a breakpoint on a subroutine whose name
1771begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1772just sounds the bell. Typing @key{TAB} again displays all the
1773function names in your program that begin with those characters, for
1774example:
1775
474c8240 1776@smallexample
c906108c
SS
1777(@value{GDBP}) b make_ @key{TAB}
1778@exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
5d161b24
DB
1779make_a_section_from_file make_environ
1780make_abs_section make_function_type
1781make_blockvector make_pointer_type
1782make_cleanup make_reference_type
c906108c
SS
1783make_command make_symbol_completion_list
1784(@value{GDBP}) b make_
474c8240 1785@end smallexample
c906108c
SS
1786
1787@noindent
1788After displaying the available possibilities, @value{GDBN} copies your
1789partial input (@samp{b make_} in the example) so you can finish the
1790command.
1791
1792If you just want to see the list of alternatives in the first place, you
b37052ae 1793can press @kbd{M-?} rather than pressing @key{TAB} twice. @kbd{M-?}
7a292a7a 1794means @kbd{@key{META} ?}. You can type this either by holding down a
c906108c 1795key designated as the @key{META} shift on your keyboard (if there is
7a292a7a 1796one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
c906108c 1797
ef0b411a
GB
1798If the number of possible completions is large, @value{GDBN} will
1799print as much of the list as it has collected, as well as a message
1800indicating that the list may be truncated.
1801
1802@smallexample
1803(@value{GDBP}) b m@key{TAB}@key{TAB}
1804main
1805<... the rest of the possible completions ...>
1806*** List may be truncated, max-completions reached. ***
1807(@value{GDBP}) b m
1808@end smallexample
1809
1810@noindent
1811This behavior can be controlled with the following commands:
1812
1813@table @code
1814@kindex set max-completions
1815@item set max-completions @var{limit}
1816@itemx set max-completions unlimited
1817Set the maximum number of completion candidates. @value{GDBN} will
1818stop looking for more completions once it collects this many candidates.
1819This is useful when completing on things like function names as collecting
1820all the possible candidates can be time consuming.
1821The default value is 200. A value of zero disables tab-completion.
1822Note that setting either no limit or a very large limit can make
1823completion slow.
1824@kindex show max-completions
1825@item show max-completions
1826Show the maximum number of candidates that @value{GDBN} will collect and show
1827during completion.
1828@end table
1829
c906108c
SS
1830@cindex quotes in commands
1831@cindex completion of quoted strings
1832Sometimes the string you need, while logically a ``word'', may contain
7a292a7a
SS
1833parentheses or other characters that @value{GDBN} normally excludes from
1834its notion of a word. To permit word completion to work in this
1835situation, you may enclose words in @code{'} (single quote marks) in
1836@value{GDBN} commands.
c906108c 1837
d044bac8
PA
1838A likely situation where you might need this is in typing an
1839expression that involves a C@t{++} symbol name with template
1840parameters. This is because when completing expressions, GDB treats
1841the @samp{<} character as word delimiter, assuming that it's the
1842less-than comparison operator (@pxref{C Operators, , C and C@t{++}
1843Operators}).
1844
1845For example, when you want to call a C@t{++} template function
1846interactively using the @code{print} or @code{call} commands, you may
1847need to distinguish whether you mean the version of @code{name} that
1848was specialized for @code{int}, @code{name<int>()}, or the version
1849that was specialized for @code{float}, @code{name<float>()}. To use
1850the word-completion facilities in this situation, type a single quote
b37052ae
EZ
1851@code{'} at the beginning of the function name. This alerts
1852@value{GDBN} that it may need to consider more information than usual
1853when you press @key{TAB} or @kbd{M-?} to request word completion:
c906108c 1854
474c8240 1855@smallexample
d044bac8
PA
1856(@value{GDBP}) p 'func< @kbd{M-?}
1857func<int>() func<float>()
1858(@value{GDBP}) p 'func<
474c8240 1859@end smallexample
c906108c 1860
d044bac8
PA
1861When setting breakpoints however (@pxref{Specify Location}), you don't
1862usually need to type a quote before the function name, because
1863@value{GDBN} understands that you want to set a breakpoint on a
1864function:
c906108c 1865
474c8240 1866@smallexample
d044bac8
PA
1867(@value{GDBP}) b func< @kbd{M-?}
1868func<int>() func<float>()
1869(@value{GDBP}) b func<
474c8240 1870@end smallexample
c906108c 1871
d044bac8
PA
1872This is true even in the case of typing the name of C@t{++} overloaded
1873functions (multiple definitions of the same function, distinguished by
1874argument type). For example, when you want to set a breakpoint you
1875don't need to distinguish whether you mean the version of @code{name}
1876that takes an @code{int} parameter, @code{name(int)}, or the version
1877that takes a @code{float} parameter, @code{name(float)}.
1878
1879@smallexample
1880(@value{GDBP}) b bubble( @kbd{M-?}
1881bubble(int) bubble(double)
1882(@value{GDBP}) b bubble(dou @kbd{M-?}
1883bubble(double)
1884@end smallexample
1885
1886See @ref{quoting names} for a description of other scenarios that
1887require quoting.
c906108c 1888
79a6e687
BW
1889For more information about overloaded functions, see @ref{C Plus Plus
1890Expressions, ,C@t{++} Expressions}. You can use the command @code{set
c906108c 1891overload-resolution off} to disable overload resolution;
79a6e687 1892see @ref{Debugging C Plus Plus, ,@value{GDBN} Features for C@t{++}}.
c906108c 1893
65d12d83
TT
1894@cindex completion of structure field names
1895@cindex structure field name completion
1896@cindex completion of union field names
1897@cindex union field name completion
1898When completing in an expression which looks up a field in a
1899structure, @value{GDBN} also tries@footnote{The completer can be
1900confused by certain kinds of invalid expressions. Also, it only
1901examines the static type of the expression, not the dynamic type.} to
1902limit completions to the field names available in the type of the
1903left-hand-side:
1904
1905@smallexample
1906(@value{GDBP}) p gdb_stdout.@kbd{M-?}
01124a23
DE
1907magic to_fputs to_rewind
1908to_data to_isatty to_write
1909to_delete to_put to_write_async_safe
1910to_flush to_read
65d12d83
TT
1911@end smallexample
1912
1913@noindent
1914This is because the @code{gdb_stdout} is a variable of the type
1915@code{struct ui_file} that is defined in @value{GDBN} sources as
1916follows:
1917
1918@smallexample
1919struct ui_file
1920@{
1921 int *magic;
1922 ui_file_flush_ftype *to_flush;
1923 ui_file_write_ftype *to_write;
01124a23 1924 ui_file_write_async_safe_ftype *to_write_async_safe;
65d12d83
TT
1925 ui_file_fputs_ftype *to_fputs;
1926 ui_file_read_ftype *to_read;
1927 ui_file_delete_ftype *to_delete;
1928 ui_file_isatty_ftype *to_isatty;
1929 ui_file_rewind_ftype *to_rewind;
1930 ui_file_put_ftype *to_put;
1931 void *to_data;
1932@}
1933@end smallexample
1934
3345721a
PA
1935@node Command Options
1936@section Command options
1937
1938@cindex command options
1939Some commands accept options starting with a leading dash. For
1940example, @code{print -pretty}. Similarly to command names, you can
1941abbreviate a @value{GDBN} option to the first few letters of the
1942option name, if that abbreviation is unambiguous, and you can also use
1943the @key{TAB} key to get @value{GDBN} to fill out the rest of a word
1944in an option (or to show you the alternatives available, if there is
1945more than one possibility).
1946
1947@cindex command options, raw input
1948Some commands take raw input as argument. For example, the print
1949command processes arbitrary expressions in any of the languages
1950supported by @value{GDBN}. With such commands, because raw input may
1951start with a leading dash that would be confused with an option or any
d8edc8b7
PW
1952of its abbreviations, e.g.@: @code{print -p} (short for @code{print
1953-pretty} or printing negative @code{p}?), if you specify any command
3345721a
PA
1954option, then you must use a double-dash (@code{--}) delimiter to
1955indicate the end of options.
1956
1957@cindex command options, boolean
1958
1959Some options are described as accepting an argument which can be
1960either @code{on} or @code{off}. These are known as @dfn{boolean
1961options}. Similarly to boolean settings commands---@code{on} and
1962@code{off} are the typical values, but any of @code{1}, @code{yes} and
1963@code{enable} can also be used as ``true'' value, and any of @code{0},
1964@code{no} and @code{disable} can also be used as ``false'' value. You
1965can also omit a ``true'' value, as it is implied by default.
1966
1967For example, these are equivalent:
1968
1969@smallexample
1970(@value{GDBP}) print -object on -pretty off -element unlimited -- *myptr
1971(@value{GDBP}) p -o -p 0 -e u -- *myptr
1972@end smallexample
1973
1974You can discover the set of options some command accepts by completing
1975on @code{-} after the command name. For example:
1976
1977@smallexample
1978(@value{GDBP}) print -@key{TAB}@key{TAB}
d8edc8b7
PW
1979-address -max-depth -raw-values -union
1980-array -null-stop -repeats -vtbl
1981-array-indexes -object -static-members
1982-elements -pretty -symbol
3345721a
PA
1983@end smallexample
1984
1985Completion will in some cases guide you with a suggestion of what kind
1986of argument an option expects. For example:
1987
1988@smallexample
1989(@value{GDBP}) print -elements @key{TAB}@key{TAB}
1990NUMBER unlimited
1991@end smallexample
1992
1993Here, the option expects a number (e.g., @code{100}), not literal
1994@code{NUMBER}. Such metasyntactical arguments are always presented in
1995uppercase.
1996
1997(For more on using the @code{print} command, see @ref{Data, ,Examining
1998Data}.)
c906108c 1999
6d2ebf8b 2000@node Help
79a6e687 2001@section Getting Help
c906108c
SS
2002@cindex online documentation
2003@kindex help
2004
5d161b24 2005You can always ask @value{GDBN} itself for information on its commands,
c906108c
SS
2006using the command @code{help}.
2007
2008@table @code
41afff9a 2009@kindex h @r{(@code{help})}
c906108c
SS
2010@item help
2011@itemx h
2012You can use @code{help} (abbreviated @code{h}) with no arguments to
2013display a short list of named classes of commands:
2014
2015@smallexample
2016(@value{GDBP}) help
2017List of classes of commands:
2018
2df3850c 2019aliases -- Aliases of other commands
c906108c 2020breakpoints -- Making program stop at certain points
2df3850c 2021data -- Examining data
c906108c 2022files -- Specifying and examining files
2df3850c
JM
2023internals -- Maintenance commands
2024obscure -- Obscure features
2025running -- Running the program
2026stack -- Examining the stack
c906108c
SS
2027status -- Status inquiries
2028support -- Support facilities
12c27660 2029tracepoints -- Tracing of program execution without
96a2c332 2030 stopping the program
c906108c 2031user-defined -- User-defined commands
c906108c 2032
5d161b24 2033Type "help" followed by a class name for a list of
c906108c 2034commands in that class.
5d161b24 2035Type "help" followed by command name for full
c906108c
SS
2036documentation.
2037Command name abbreviations are allowed if unambiguous.
2038(@value{GDBP})
2039@end smallexample
96a2c332 2040@c the above line break eliminates huge line overfull...
c906108c
SS
2041
2042@item help @var{class}
2043Using one of the general help classes as an argument, you can get a
2044list of the individual commands in that class. For example, here is the
2045help display for the class @code{status}:
2046
2047@smallexample
2048(@value{GDBP}) help status
2049Status inquiries.
2050
2051List of commands:
2052
2053@c Line break in "show" line falsifies real output, but needed
2054@c to fit in smallbook page size.
2df3850c 2055info -- Generic command for showing things
12c27660 2056 about the program being debugged
2df3850c 2057show -- Generic command for showing things
12c27660 2058 about the debugger
c906108c 2059
5d161b24 2060Type "help" followed by command name for full
c906108c
SS
2061documentation.
2062Command name abbreviations are allowed if unambiguous.
2063(@value{GDBP})
2064@end smallexample
2065
2066@item help @var{command}
2067With a command name as @code{help} argument, @value{GDBN} displays a
2068short paragraph on how to use that command.
2069
6837a0a2 2070@kindex apropos
e664d728 2071@item apropos [-v] @var{regexp}
09d4efe1 2072The @code{apropos} command searches through all of the @value{GDBN}
6837a0a2 2073commands, and their documentation, for the regular expression specified in
e664d728
PW
2074@var{args}. It prints out all matches found. The optional flag @samp{-v},
2075which stands for @samp{verbose}, indicates to output the full documentation
2076of the matching commands and highlight the parts of the documentation
2077matching @var{regexp}. For example:
6837a0a2
DB
2078
2079@smallexample
16899756 2080apropos alias
6837a0a2
DB
2081@end smallexample
2082
b37052ae
EZ
2083@noindent
2084results in:
6837a0a2
DB
2085
2086@smallexample
e664d728 2087@group
16899756
DE
2088alias -- Define a new command that is an alias of an existing command
2089aliases -- Aliases of other commands
2090d -- Delete some breakpoints or auto-display expressions
2091del -- Delete some breakpoints or auto-display expressions
2092delete -- Delete some breakpoints or auto-display expressions
e664d728
PW
2093@end group
2094@end smallexample
2095
2096@noindent
2097while
2098
2099@smallexample
2100apropos -v cut.*thread apply
2101@end smallexample
2102
2103@noindent
2104results in the below output, where @samp{cut for 'thread apply}
2105is highlighted if styling is enabled.
2106
2107@smallexample
2108@group
2109taas -- Apply a command to all threads (ignoring errors
2110and empty output).
2111Usage: taas COMMAND
2112shortcut for 'thread apply all -s COMMAND'
2113
2114tfaas -- Apply a command to all frames of all threads
2115(ignoring errors and empty output).
2116Usage: tfaas COMMAND
2117shortcut for 'thread apply all -s frame apply all -s COMMAND'
2118@end group
6837a0a2
DB
2119@end smallexample
2120
c906108c
SS
2121@kindex complete
2122@item complete @var{args}
2123The @code{complete @var{args}} command lists all the possible completions
2124for the beginning of a command. Use @var{args} to specify the beginning of the
2125command you want completed. For example:
2126
2127@smallexample
2128complete i
2129@end smallexample
2130
2131@noindent results in:
2132
2133@smallexample
2134@group
2df3850c
JM
2135if
2136ignore
c906108c
SS
2137info
2138inspect
c906108c
SS
2139@end group
2140@end smallexample
2141
2142@noindent This is intended for use by @sc{gnu} Emacs.
2143@end table
2144
2145In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
2146and @code{show} to inquire about the state of your program, or the state
2147of @value{GDBN} itself. Each command supports many topics of inquiry; this
2148manual introduces each of them in the appropriate context. The listings
00595b5e
EZ
2149under @code{info} and under @code{show} in the Command, Variable, and
2150Function Index point to all the sub-commands. @xref{Command and Variable
2151Index}.
c906108c
SS
2152
2153@c @group
2154@table @code
2155@kindex info
41afff9a 2156@kindex i @r{(@code{info})}
c906108c
SS
2157@item info
2158This command (abbreviated @code{i}) is for describing the state of your
cda4ce5a 2159program. For example, you can show the arguments passed to a function
c906108c
SS
2160with @code{info args}, list the registers currently in use with @code{info
2161registers}, or list the breakpoints you have set with @code{info breakpoints}.
2162You can get a complete list of the @code{info} sub-commands with
2163@w{@code{help info}}.
2164
2165@kindex set
2166@item set
5d161b24 2167You can assign the result of an expression to an environment variable with
c906108c
SS
2168@code{set}. For example, you can set the @value{GDBN} prompt to a $-sign with
2169@code{set prompt $}.
2170
2171@kindex show
2172@item show
5d161b24 2173In contrast to @code{info}, @code{show} is for describing the state of
c906108c
SS
2174@value{GDBN} itself.
2175You can change most of the things you can @code{show}, by using the
2176related command @code{set}; for example, you can control what number
2177system is used for displays with @code{set radix}, or simply inquire
2178which is currently in use with @code{show radix}.
2179
2180@kindex info set
2181To display all the settable parameters and their current
2182values, you can use @code{show} with no arguments; you may also use
2183@code{info set}. Both commands produce the same display.
2184@c FIXME: "info set" violates the rule that "info" is for state of
2185@c FIXME...program. Ck w/ GNU: "info set" to be called something else,
2186@c FIXME...or change desc of rule---eg "state of prog and debugging session"?
2187@end table
2188@c @end group
2189
6eaaf48b 2190Here are several miscellaneous @code{show} subcommands, all of which are
c906108c
SS
2191exceptional in lacking corresponding @code{set} commands:
2192
2193@table @code
2194@kindex show version
9c16f35a 2195@cindex @value{GDBN} version number
c906108c
SS
2196@item show version
2197Show what version of @value{GDBN} is running. You should include this
2df3850c
JM
2198information in @value{GDBN} bug-reports. If multiple versions of
2199@value{GDBN} are in use at your site, you may need to determine which
2200version of @value{GDBN} you are running; as @value{GDBN} evolves, new
2201commands are introduced, and old ones may wither away. Also, many
2202system vendors ship variant versions of @value{GDBN}, and there are
96a2c332 2203variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2df3850c
JM
2204The version number is the same as the one announced when you start
2205@value{GDBN}.
c906108c
SS
2206
2207@kindex show copying
09d4efe1 2208@kindex info copying
9c16f35a 2209@cindex display @value{GDBN} copyright
c906108c 2210@item show copying
09d4efe1 2211@itemx info copying
c906108c
SS
2212Display information about permission for copying @value{GDBN}.
2213
2214@kindex show warranty
09d4efe1 2215@kindex info warranty
c906108c 2216@item show warranty
09d4efe1 2217@itemx info warranty
2df3850c 2218Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
96a2c332 2219if your version of @value{GDBN} comes with one.
2df3850c 2220
6eaaf48b
EZ
2221@kindex show configuration
2222@item show configuration
2223Display detailed information about the way @value{GDBN} was configured
2224when it was built. This displays the optional arguments passed to the
2225@file{configure} script and also configuration parameters detected
2226automatically by @command{configure}. When reporting a @value{GDBN}
2227bug (@pxref{GDB Bugs}), it is important to include this information in
2228your report.
2229
c906108c
SS
2230@end table
2231
6d2ebf8b 2232@node Running
c906108c
SS
2233@chapter Running Programs Under @value{GDBN}
2234
2235When you run a program under @value{GDBN}, you must first generate
2236debugging information when you compile it.
7a292a7a
SS
2237
2238You may start @value{GDBN} with its arguments, if any, in an environment
2239of your choice. If you are doing native debugging, you may redirect
2240your program's input and output, debug an already running process, or
2241kill a child process.
c906108c
SS
2242
2243@menu
2244* Compilation:: Compiling for debugging
2245* Starting:: Starting your program
c906108c
SS
2246* Arguments:: Your program's arguments
2247* Environment:: Your program's environment
c906108c
SS
2248
2249* Working Directory:: Your program's working directory
2250* Input/Output:: Your program's input and output
2251* Attach:: Debugging an already-running process
2252* Kill Process:: Killing the child process
65c574f6
PA
2253* Inferiors Connections and Programs:: Debugging multiple inferiors
2254 connections and programs
c906108c 2255* Threads:: Debugging programs with multiple threads
6c95b8df 2256* Forks:: Debugging forks
5c95884b 2257* Checkpoint/Restart:: Setting a @emph{bookmark} to return to later
c906108c
SS
2258@end menu
2259
6d2ebf8b 2260@node Compilation
79a6e687 2261@section Compiling for Debugging
c906108c
SS
2262
2263In order to debug a program effectively, you need to generate
2264debugging information when you compile it. This debugging information
2265is stored in the object file; it describes the data type of each
2266variable or function and the correspondence between source line numbers
2267and addresses in the executable code.
2268
2269To request debugging information, specify the @samp{-g} option when you run
2270the compiler.
2271
514c4d71 2272Programs that are to be shipped to your customers are compiled with
edb3359d 2273optimizations, using the @samp{-O} compiler option. However, some
514c4d71
EZ
2274compilers are unable to handle the @samp{-g} and @samp{-O} options
2275together. Using those compilers, you cannot generate optimized
c906108c
SS
2276executables containing debugging information.
2277
514c4d71 2278@value{NGCC}, the @sc{gnu} C/C@t{++} compiler, supports @samp{-g} with or
53a5351d
JM
2279without @samp{-O}, making it possible to debug optimized code. We
2280recommend that you @emph{always} use @samp{-g} whenever you compile a
2281program. You may think your program is correct, but there is no sense
edb3359d 2282in pushing your luck. For more information, see @ref{Optimized Code}.
c906108c
SS
2283
2284Older versions of the @sc{gnu} C compiler permitted a variant option
2285@w{@samp{-gg}} for debugging information. @value{GDBN} no longer supports this
2286format; if your @sc{gnu} C compiler has this option, do not use it.
2287
514c4d71
EZ
2288@value{GDBN} knows about preprocessor macros and can show you their
2289expansion (@pxref{Macros}). Most compilers do not include information
2290about preprocessor macros in the debugging information if you specify
e0f8f636
TT
2291the @option{-g} flag alone. Version 3.1 and later of @value{NGCC},
2292the @sc{gnu} C compiler, provides macro information if you are using
2293the DWARF debugging format, and specify the option @option{-g3}.
2294
2295@xref{Debugging Options,,Options for Debugging Your Program or GCC,
f5a476a7 2296gcc, Using the @sc{gnu} Compiler Collection (GCC)}, for more
e0f8f636
TT
2297information on @value{NGCC} options affecting debug information.
2298
2299You will have the best debugging experience if you use the latest
2300version of the DWARF debugging format that your compiler supports.
2301DWARF is currently the most expressive and best supported debugging
2302format in @value{GDBN}.
514c4d71 2303
c906108c 2304@need 2000
6d2ebf8b 2305@node Starting
79a6e687 2306@section Starting your Program
c906108c
SS
2307@cindex starting
2308@cindex running
2309
2310@table @code
2311@kindex run
41afff9a 2312@kindex r @r{(@code{run})}
c906108c
SS
2313@item run
2314@itemx r
7a292a7a 2315Use the @code{run} command to start your program under @value{GDBN}.
deb8ff2b
PA
2316You must first specify the program name with an argument to
2317@value{GDBN} (@pxref{Invocation, ,Getting In and Out of
2318@value{GDBN}}), or by using the @code{file} or @code{exec-file}
2319command (@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
2320
2321@end table
2322
c906108c
SS
2323If you are running your program in an execution environment that
2324supports processes, @code{run} creates an inferior process and makes
8edfe269
DJ
2325that process run your program. In some environments without processes,
2326@code{run} jumps to the start of your program. Other targets,
2327like @samp{remote}, are always running. If you get an error
2328message like this one:
2329
2330@smallexample
2331The "remote" target does not support "run".
2332Try "help target" or "continue".
2333@end smallexample
2334
2335@noindent
2336then use @code{continue} to run your program. You may need @code{load}
2337first (@pxref{load}).
c906108c
SS
2338
2339The execution of a program is affected by certain information it
2340receives from its superior. @value{GDBN} provides ways to specify this
2341information, which you must do @emph{before} starting your program. (You
2342can change it after starting your program, but such changes only affect
2343your program the next time you start it.) This information may be
2344divided into four categories:
2345
2346@table @asis
2347@item The @emph{arguments.}
2348Specify the arguments to give your program as the arguments of the
2349@code{run} command. If a shell is available on your target, the shell
2350is used to pass the arguments, so that you may use normal conventions
2351(such as wildcard expansion or variable substitution) in describing
2352the arguments.
2353In Unix systems, you can control which shell is used with the
98882a26
PA
2354@code{SHELL} environment variable. If you do not define @code{SHELL},
2355@value{GDBN} uses the default shell (@file{/bin/sh}). You can disable
2356use of any shell with the @code{set startup-with-shell} command (see
2357below for details).
c906108c
SS
2358
2359@item The @emph{environment.}
2360Your program normally inherits its environment from @value{GDBN}, but you can
2361use the @value{GDBN} commands @code{set environment} and @code{unset
2362environment} to change parts of the environment that affect
79a6e687 2363your program. @xref{Environment, ,Your Program's Environment}.
c906108c
SS
2364
2365@item The @emph{working directory.}
d092c5a2
SDJ
2366You can set your program's working directory with the command
2367@kbd{set cwd}. If you do not set any working directory with this
bc3b087d
SDJ
2368command, your program will inherit @value{GDBN}'s working directory if
2369native debugging, or the remote server's working directory if remote
2370debugging. @xref{Working Directory, ,Your Program's Working
2371Directory}.
c906108c
SS
2372
2373@item The @emph{standard input and output.}
2374Your program normally uses the same device for standard input and
2375standard output as @value{GDBN} is using. You can redirect input and output
2376in the @code{run} command line, or you can use the @code{tty} command to
2377set a different device for your program.
79a6e687 2378@xref{Input/Output, ,Your Program's Input and Output}.
c906108c
SS
2379
2380@cindex pipes
2381@emph{Warning:} While input and output redirection work, you cannot use
2382pipes to pass the output of the program you are debugging to another
2383program; if you attempt this, @value{GDBN} is likely to wind up debugging the
2384wrong program.
2385@end table
c906108c
SS
2386
2387When you issue the @code{run} command, your program begins to execute
79a6e687 2388immediately. @xref{Stopping, ,Stopping and Continuing}, for discussion
c906108c
SS
2389of how to arrange for your program to stop. Once your program has
2390stopped, you may call functions in your program, using the @code{print}
2391or @code{call} commands. @xref{Data, ,Examining Data}.
2392
2393If the modification time of your symbol file has changed since the last
2394time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
2395table, and reads it again. When it does this, @value{GDBN} tries to retain
2396your current breakpoints.
2397
4e8b0763
JB
2398@table @code
2399@kindex start
2400@item start
2401@cindex run to main procedure
2402The name of the main procedure can vary from language to language.
2403With C or C@t{++}, the main procedure name is always @code{main}, but
2404other languages such as Ada do not require a specific name for their
2405main procedure. The debugger provides a convenient way to start the
2406execution of the program and to stop at the beginning of the main
2407procedure, depending on the language used.
2408
2409The @samp{start} command does the equivalent of setting a temporary
2410breakpoint at the beginning of the main procedure and then invoking
2411the @samp{run} command.
2412
f018e82f
EZ
2413@cindex elaboration phase
2414Some programs contain an @dfn{elaboration} phase where some startup code is
2415executed before the main procedure is called. This depends on the
2416languages used to write your program. In C@t{++}, for instance,
4e8b0763
JB
2417constructors for static and global objects are executed before
2418@code{main} is called. It is therefore possible that the debugger stops
2419before reaching the main procedure. However, the temporary breakpoint
2420will remain to halt execution.
2421
2422Specify the arguments to give to your program as arguments to the
2423@samp{start} command. These arguments will be given verbatim to the
2424underlying @samp{run} command. Note that the same arguments will be
2425reused if no argument is provided during subsequent calls to
2426@samp{start} or @samp{run}.
2427
2428It is sometimes necessary to debug the program during elaboration. In
4e5a4f58
JB
2429these cases, using the @code{start} command would stop the execution
2430of your program too late, as the program would have already completed
2431the elaboration phase. Under these circumstances, either insert
2432breakpoints in your elaboration code before running your program or
2433use the @code{starti} command.
2434
2435@kindex starti
2436@item starti
2437@cindex run to first instruction
2438The @samp{starti} command does the equivalent of setting a temporary
2439breakpoint at the first instruction of a program's execution and then
2440invoking the @samp{run} command. For programs containing an
2441elaboration phase, the @code{starti} command will stop execution at
2442the start of the elaboration phase.
ccd213ac 2443
41ef2965 2444@anchor{set exec-wrapper}
ccd213ac
DJ
2445@kindex set exec-wrapper
2446@item set exec-wrapper @var{wrapper}
2447@itemx show exec-wrapper
2448@itemx unset exec-wrapper
2449When @samp{exec-wrapper} is set, the specified wrapper is used to
2450launch programs for debugging. @value{GDBN} starts your program
2451with a shell command of the form @kbd{exec @var{wrapper}
2452@var{program}}. Quoting is added to @var{program} and its
2453arguments, but not to @var{wrapper}, so you should add quotes if
2454appropriate for your shell. The wrapper runs until it executes
2455your program, and then @value{GDBN} takes control.
2456
2457You can use any program that eventually calls @code{execve} with
2458its arguments as a wrapper. Several standard Unix utilities do
2459this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
2460with @code{exec "$@@"} will also work.
2461
2462For example, you can use @code{env} to pass an environment variable to
2463the debugged program, without setting the variable in your shell's
2464environment:
2465
2466@smallexample
2467(@value{GDBP}) set exec-wrapper env 'LD_PRELOAD=libtest.so'
2468(@value{GDBP}) run
2469@end smallexample
2470
2471This command is available when debugging locally on most targets, excluding
2472@sc{djgpp}, Cygwin, MS Windows, and QNX Neutrino.
2473
98882a26 2474@kindex set startup-with-shell
aefd8b33 2475@anchor{set startup-with-shell}
98882a26
PA
2476@item set startup-with-shell
2477@itemx set startup-with-shell on
2478@itemx set startup-with-shell off
ca145713 2479@itemx show startup-with-shell
98882a26
PA
2480On Unix systems, by default, if a shell is available on your target,
2481@value{GDBN}) uses it to start your program. Arguments of the
2482@code{run} command are passed to the shell, which does variable
2483substitution, expands wildcard characters and performs redirection of
2484I/O. In some circumstances, it may be useful to disable such use of a
2485shell, for example, when debugging the shell itself or diagnosing
2486startup failures such as:
2487
2488@smallexample
2489(@value{GDBP}) run
2490Starting program: ./a.out
2491During startup program terminated with signal SIGSEGV, Segmentation fault.
2492@end smallexample
2493
2494@noindent
2495which indicates the shell or the wrapper specified with
2496@samp{exec-wrapper} crashed, not your program. Most often, this is
afa332ce
PA
2497caused by something odd in your shell's non-interactive mode
2498initialization file---such as @file{.cshrc} for C-shell,
2499$@file{.zshenv} for the Z shell, or the file specified in the
2500@samp{BASH_ENV} environment variable for BASH.
98882a26 2501
6a3cb8e8
PA
2502@anchor{set auto-connect-native-target}
2503@kindex set auto-connect-native-target
2504@item set auto-connect-native-target
2505@itemx set auto-connect-native-target on
2506@itemx set auto-connect-native-target off
2507@itemx show auto-connect-native-target
2508
65c574f6
PA
2509By default, if the current inferior is not connected to any target yet
2510(e.g., with @code{target remote}), the @code{run} command starts your
2511program as a native process under @value{GDBN}, on your local machine.
2512If you're sure you don't want to debug programs on your local machine,
2513you can tell @value{GDBN} to not connect to the native target
2514automatically with the @code{set auto-connect-native-target off}
2515command.
6a3cb8e8 2516
65c574f6 2517If @code{on}, which is the default, and if the current inferior is not
6a3cb8e8
PA
2518connected to a target already, the @code{run} command automaticaly
2519connects to the native target, if one is available.
2520
65c574f6
PA
2521If @code{off}, and if the current inferior is not connected to a
2522target already, the @code{run} command fails with an error:
6a3cb8e8
PA
2523
2524@smallexample
2525(@value{GDBP}) run
2526Don't know how to run. Try "help target".
2527@end smallexample
2528
65c574f6
PA
2529If the current inferior is already connected to a target, @value{GDBN}
2530always uses it with the @code{run} command.
6a3cb8e8
PA
2531
2532In any case, you can explicitly connect to the native target with the
2533@code{target native} command. For example,
2534
2535@smallexample
2536(@value{GDBP}) set auto-connect-native-target off
2537(@value{GDBP}) run
2538Don't know how to run. Try "help target".
2539(@value{GDBP}) target native
2540(@value{GDBP}) run
2541Starting program: ./a.out
2542[Inferior 1 (process 10421) exited normally]
2543@end smallexample
2544
2545In case you connected explicitly to the @code{native} target,
2546@value{GDBN} remains connected even if all inferiors exit, ready for
2547the next @code{run} command. Use the @code{disconnect} command to
2548disconnect.
2549
2550Examples of other commands that likewise respect the
2551@code{auto-connect-native-target} setting: @code{attach}, @code{info
2552proc}, @code{info os}.
2553
10568435
JK
2554@kindex set disable-randomization
2555@item set disable-randomization
2556@itemx set disable-randomization on
2557This option (enabled by default in @value{GDBN}) will turn off the native
2558randomization of the virtual address space of the started program. This option
2559is useful for multiple debugging sessions to make the execution better
2560reproducible and memory addresses reusable across debugging sessions.
2561
03583c20
UW
2562This feature is implemented only on certain targets, including @sc{gnu}/Linux.
2563On @sc{gnu}/Linux you can get the same behavior using
10568435
JK
2564
2565@smallexample
2566(@value{GDBP}) set exec-wrapper setarch `uname -m` -R
2567@end smallexample
2568
2569@item set disable-randomization off
2570Leave the behavior of the started executable unchanged. Some bugs rear their
2571ugly heads only when the program is loaded at certain addresses. If your bug
2572disappears when you run the program under @value{GDBN}, that might be because
2573@value{GDBN} by default disables the address randomization on platforms, such
2574as @sc{gnu}/Linux, which do that for stand-alone programs. Use @kbd{set
2575disable-randomization off} to try to reproduce such elusive bugs.
2576
03583c20
UW
2577On targets where it is available, virtual address space randomization
2578protects the programs against certain kinds of security attacks. In these
10568435
JK
2579cases the attacker needs to know the exact location of a concrete executable
2580code. Randomizing its location makes it impossible to inject jumps misusing
2581a code at its expected addresses.
2582
2583Prelinking shared libraries provides a startup performance advantage but it
2584makes addresses in these libraries predictable for privileged processes by
2585having just unprivileged access at the target system. Reading the shared
2586library binary gives enough information for assembling the malicious code
2587misusing it. Still even a prelinked shared library can get loaded at a new
2588random address just requiring the regular relocation process during the
2589startup. Shared libraries not already prelinked are always loaded at
2590a randomly chosen address.
2591
2592Position independent executables (PIE) contain position independent code
2593similar to the shared libraries and therefore such executables get loaded at
2594a randomly chosen address upon startup. PIE executables always load even
2595already prelinked shared libraries at a random address. You can build such
2596executable using @command{gcc -fPIE -pie}.
2597
2598Heap (malloc storage), stack and custom mmap areas are always placed randomly
2599(as long as the randomization is enabled).
2600
2601@item show disable-randomization
2602Show the current setting of the explicit disable of the native randomization of
2603the virtual address space of the started program.
2604
4e8b0763
JB
2605@end table
2606
6d2ebf8b 2607@node Arguments
79a6e687 2608@section Your Program's Arguments
c906108c
SS
2609
2610@cindex arguments (to your program)
2611The arguments to your program can be specified by the arguments of the
5d161b24 2612@code{run} command.
c906108c
SS
2613They are passed to a shell, which expands wildcard characters and
2614performs redirection of I/O, and thence to your program. Your
2615@code{SHELL} environment variable (if it exists) specifies what shell
2616@value{GDBN} uses. If you do not define @code{SHELL}, @value{GDBN} uses
d4f3574e
SS
2617the default shell (@file{/bin/sh} on Unix).
2618
2619On non-Unix systems, the program is usually invoked directly by
2620@value{GDBN}, which emulates I/O redirection via the appropriate system
2621calls, and the wildcard characters are expanded by the startup code of
2622the program, not by the shell.
c906108c
SS
2623
2624@code{run} with no arguments uses the same arguments used by the previous
2625@code{run}, or those set by the @code{set args} command.
2626
c906108c 2627@table @code
41afff9a 2628@kindex set args
c906108c
SS
2629@item set args
2630Specify the arguments to be used the next time your program is run. If
2631@code{set args} has no arguments, @code{run} executes your program
2632with no arguments. Once you have run your program with arguments,
2633using @code{set args} before the next @code{run} is the only way to run
2634it again without arguments.
2635
2636@kindex show args
2637@item show args
2638Show the arguments to give your program when it is started.
2639@end table
2640
6d2ebf8b 2641@node Environment
79a6e687 2642@section Your Program's Environment
c906108c
SS
2643
2644@cindex environment (of your program)
2645The @dfn{environment} consists of a set of environment variables and
2646their values. Environment variables conventionally record such things as
2647your user name, your home directory, your terminal type, and your search
2648path for programs to run. Usually you set up environment variables with
2649the shell and they are inherited by all the other programs you run. When
2650debugging, it can be useful to try running your program with a modified
2651environment without having to start @value{GDBN} over again.
2652
2653@table @code
2654@kindex path
2655@item path @var{directory}
2656Add @var{directory} to the front of the @code{PATH} environment variable
17cc6a06
EZ
2657(the search path for executables) that will be passed to your program.
2658The value of @code{PATH} used by @value{GDBN} does not change.
d4f3574e
SS
2659You may specify several directory names, separated by whitespace or by a
2660system-dependent separator character (@samp{:} on Unix, @samp{;} on
2661MS-DOS and MS-Windows). If @var{directory} is already in the path, it
2662is moved to the front, so it is searched sooner.
c906108c
SS
2663
2664You can use the string @samp{$cwd} to refer to whatever is the current
2665working directory at the time @value{GDBN} searches the path. If you
2666use @samp{.} instead, it refers to the directory where you executed the
2667@code{path} command. @value{GDBN} replaces @samp{.} in the
2668@var{directory} argument (with the current path) before adding
2669@var{directory} to the search path.
2670@c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
2671@c document that, since repeating it would be a no-op.
2672
2673@kindex show paths
2674@item show paths
2675Display the list of search paths for executables (the @code{PATH}
2676environment variable).
2677
2678@kindex show environment
2679@item show environment @r{[}@var{varname}@r{]}
2680Print the value of environment variable @var{varname} to be given to
2681your program when it starts. If you do not supply @var{varname},
2682print the names and values of all environment variables to be given to
2683your program. You can abbreviate @code{environment} as @code{env}.
2684
2685@kindex set environment
0a2dde4a 2686@anchor{set environment}
53a5351d 2687@item set environment @var{varname} @r{[}=@var{value}@r{]}
c906108c 2688Set environment variable @var{varname} to @var{value}. The value
41ef2965 2689changes for your program (and the shell @value{GDBN} uses to launch
697aa1b7 2690it), not for @value{GDBN} itself. The @var{value} may be any string; the
41ef2965
PA
2691values of environment variables are just strings, and any
2692interpretation is supplied by your program itself. The @var{value}
c906108c
SS
2693parameter is optional; if it is eliminated, the variable is set to a
2694null value.
2695@c "any string" here does not include leading, trailing
2696@c blanks. Gnu asks: does anyone care?
2697
2698For example, this command:
2699
474c8240 2700@smallexample
c906108c 2701set env USER = foo
474c8240 2702@end smallexample
c906108c
SS
2703
2704@noindent
d4f3574e 2705tells the debugged program, when subsequently run, that its user is named
c906108c
SS
2706@samp{foo}. (The spaces around @samp{=} are used for clarity here; they
2707are not actually required.)
2708
41ef2965
PA
2709Note that on Unix systems, @value{GDBN} runs your program via a shell,
2710which also inherits the environment set with @code{set environment}.
2711If necessary, you can avoid that by using the @samp{env} program as a
2712wrapper instead of using @code{set environment}. @xref{set
2713exec-wrapper}, for an example doing just that.
2714
0a2dde4a
SDJ
2715Environment variables that are set by the user are also transmitted to
2716@command{gdbserver} to be used when starting the remote inferior.
2717@pxref{QEnvironmentHexEncoded}.
2718
c906108c 2719@kindex unset environment
0a2dde4a 2720@anchor{unset environment}
c906108c
SS
2721@item unset environment @var{varname}
2722Remove variable @var{varname} from the environment to be passed to your
2723program. This is different from @samp{set env @var{varname} =};
2724@code{unset environment} removes the variable from the environment,
2725rather than assigning it an empty value.
0a2dde4a
SDJ
2726
2727Environment variables that are unset by the user are also unset on
2728@command{gdbserver} when starting the remote inferior.
2729@pxref{QEnvironmentUnset}.
c906108c
SS
2730@end table
2731
d4f3574e 2732@emph{Warning:} On Unix systems, @value{GDBN} runs your program using
afa332ce
PA
2733the shell indicated by your @code{SHELL} environment variable if it
2734exists (or @code{/bin/sh} if not). If your @code{SHELL} variable
2735names a shell that runs an initialization file when started
2736non-interactively---such as @file{.cshrc} for C-shell, $@file{.zshenv}
2737for the Z shell, or the file specified in the @samp{BASH_ENV}
2738environment variable for BASH---any variables you set in that file
2739affect your program. You may wish to move setting of environment
2740variables to files that are only run when you sign on, such as
2741@file{.login} or @file{.profile}.
c906108c 2742
6d2ebf8b 2743@node Working Directory
79a6e687 2744@section Your Program's Working Directory
c906108c
SS
2745
2746@cindex working directory (of your program)
d092c5a2
SDJ
2747Each time you start your program with @code{run}, the inferior will be
2748initialized with the current working directory specified by the
2749@kbd{set cwd} command. If no directory has been specified by this
2750command, then the inferior will inherit @value{GDBN}'s current working
bc3b087d
SDJ
2751directory as its working directory if native debugging, or it will
2752inherit the remote server's current working directory if remote
2753debugging.
c906108c
SS
2754
2755@table @code
d092c5a2
SDJ
2756@kindex set cwd
2757@cindex change inferior's working directory
2758@anchor{set cwd command}
2759@item set cwd @r{[}@var{directory}@r{]}
2760Set the inferior's working directory to @var{directory}, which will be
2761@code{glob}-expanded in order to resolve tildes (@file{~}). If no
2762argument has been specified, the command clears the setting and resets
2763it to an empty state. This setting has no effect on @value{GDBN}'s
2764working directory, and it only takes effect the next time you start
2765the inferior. The @file{~} in @var{directory} is a short for the
2766@dfn{home directory}, usually pointed to by the @env{HOME} environment
2767variable. On MS-Windows, if @env{HOME} is not defined, @value{GDBN}
2768uses the concatenation of @env{HOMEDRIVE} and @env{HOMEPATH} as
2769fallback.
2770
2771You can also change @value{GDBN}'s current working directory by using
2772the @code{cd} command.
dbfa4523 2773@xref{cd command}.
d092c5a2
SDJ
2774
2775@kindex show cwd
2776@cindex show inferior's working directory
2777@item show cwd
2778Show the inferior's working directory. If no directory has been
2779specified by @kbd{set cwd}, then the default inferior's working
2780directory is the same as @value{GDBN}'s working directory.
2781
c906108c 2782@kindex cd
d092c5a2
SDJ
2783@cindex change @value{GDBN}'s working directory
2784@anchor{cd command}
f3c8a52a
JK
2785@item cd @r{[}@var{directory}@r{]}
2786Set the @value{GDBN} working directory to @var{directory}. If not
2787given, @var{directory} uses @file{'~'}.
c906108c 2788
d092c5a2
SDJ
2789The @value{GDBN} working directory serves as a default for the
2790commands that specify files for @value{GDBN} to operate on.
2791@xref{Files, ,Commands to Specify Files}.
dbfa4523 2792@xref{set cwd command}.
d092c5a2 2793
c906108c
SS
2794@kindex pwd
2795@item pwd
2796Print the @value{GDBN} working directory.
2797@end table
2798
60bf7e09
EZ
2799It is generally impossible to find the current working directory of
2800the process being debugged (since a program can change its directory
2d97a5d9 2801during its run). If you work on a system where @value{GDBN} supports
754452f0 2802the @code{info proc} command (@pxref{Process Information}), you can
2d97a5d9 2803use the @code{info proc} command to find out the
60bf7e09
EZ
2804current working directory of the debuggee.
2805
6d2ebf8b 2806@node Input/Output
79a6e687 2807@section Your Program's Input and Output
c906108c
SS
2808
2809@cindex redirection
2810@cindex i/o
2811@cindex terminal
2812By default, the program you run under @value{GDBN} does input and output to
5d161b24 2813the same terminal that @value{GDBN} uses. @value{GDBN} switches the terminal
c906108c
SS
2814to its own terminal modes to interact with you, but it records the terminal
2815modes your program was using and switches back to them when you continue
2816running your program.
2817
2818@table @code
2819@kindex info terminal
2820@item info terminal
2821Displays information recorded by @value{GDBN} about the terminal modes your
2822program is using.
2823@end table
2824
2825You can redirect your program's input and/or output using shell
2826redirection with the @code{run} command. For example,
2827
474c8240 2828@smallexample
c906108c 2829run > outfile
474c8240 2830@end smallexample
c906108c
SS
2831
2832@noindent
2833starts your program, diverting its output to the file @file{outfile}.
2834
2835@kindex tty
2836@cindex controlling terminal
2837Another way to specify where your program should do input and output is
2838with the @code{tty} command. This command accepts a file name as
2839argument, and causes this file to be the default for future @code{run}
2840commands. It also resets the controlling terminal for the child
2841process, for future @code{run} commands. For example,
2842
474c8240 2843@smallexample
c906108c 2844tty /dev/ttyb
474c8240 2845@end smallexample
c906108c
SS
2846
2847@noindent
2848directs that processes started with subsequent @code{run} commands
2849default to do input and output on the terminal @file{/dev/ttyb} and have
2850that as their controlling terminal.
2851
2852An explicit redirection in @code{run} overrides the @code{tty} command's
2853effect on the input/output device, but not its effect on the controlling
2854terminal.
2855
2856When you use the @code{tty} command or redirect input in the @code{run}
2857command, only the input @emph{for your program} is affected. The input
3cb3b8df
BR
2858for @value{GDBN} still comes from your terminal. @code{tty} is an alias
2859for @code{set inferior-tty}.
2860
2861@cindex inferior tty
2862@cindex set inferior controlling terminal
2863You can use the @code{show inferior-tty} command to tell @value{GDBN} to
2864display the name of the terminal that will be used for future runs of your
2865program.
2866
2867@table @code
0a1ddfa6 2868@item set inferior-tty [ @var{tty} ]
3cb3b8df 2869@kindex set inferior-tty
0a1ddfa6
SM
2870Set the tty for the program being debugged to @var{tty}. Omitting @var{tty}
2871restores the default behavior, which is to use the same terminal as
2872@value{GDBN}.
3cb3b8df
BR
2873
2874@item show inferior-tty
2875@kindex show inferior-tty
2876Show the current tty for the program being debugged.
2877@end table
c906108c 2878
6d2ebf8b 2879@node Attach
79a6e687 2880@section Debugging an Already-running Process
c906108c
SS
2881@kindex attach
2882@cindex attach
2883
2884@table @code
2885@item attach @var{process-id}
2886This command attaches to a running process---one that was started
2887outside @value{GDBN}. (@code{info files} shows your active
2888targets.) The command takes as argument a process ID. The usual way to
09d4efe1 2889find out the @var{process-id} of a Unix process is with the @code{ps} utility,
c906108c
SS
2890or with the @samp{jobs -l} shell command.
2891
2892@code{attach} does not repeat if you press @key{RET} a second time after
2893executing the command.
2894@end table
2895
2896To use @code{attach}, your program must be running in an environment
2897which supports processes; for example, @code{attach} does not work for
2898programs on bare-board targets that lack an operating system. You must
2899also have permission to send the process a signal.
2900
2901When you use @code{attach}, the debugger finds the program running in
2902the process first by looking in the current working directory, then (if
2903the program is not found) by using the source file search path
79a6e687 2904(@pxref{Source Path, ,Specifying Source Directories}). You can also use
c906108c
SS
2905the @code{file} command to load the program. @xref{Files, ,Commands to
2906Specify Files}.
2907
2908The first thing @value{GDBN} does after arranging to debug the specified
2909process is to stop it. You can examine and modify an attached process
53a5351d
JM
2910with all the @value{GDBN} commands that are ordinarily available when
2911you start processes with @code{run}. You can insert breakpoints; you
2912can step and continue; you can modify storage. If you would rather the
2913process continue running, you may use the @code{continue} command after
c906108c
SS
2914attaching @value{GDBN} to the process.
2915
2916@table @code
2917@kindex detach
2918@item detach
2919When you have finished debugging the attached process, you can use the
2920@code{detach} command to release it from @value{GDBN} control. Detaching
2921the process continues its execution. After the @code{detach} command,
2922that process and @value{GDBN} become completely independent once more, and you
2923are ready to @code{attach} another process or start one with @code{run}.
2924@code{detach} does not repeat if you press @key{RET} again after
2925executing the command.
2926@end table
2927
159fcc13
JK
2928If you exit @value{GDBN} while you have an attached process, you detach
2929that process. If you use the @code{run} command, you kill that process.
2930By default, @value{GDBN} asks for confirmation if you try to do either of these
2931things; you can control whether or not you need to confirm by using the
2932@code{set confirm} command (@pxref{Messages/Warnings, ,Optional Warnings and
79a6e687 2933Messages}).
c906108c 2934
6d2ebf8b 2935@node Kill Process
79a6e687 2936@section Killing the Child Process
c906108c
SS
2937
2938@table @code
2939@kindex kill
2940@item kill
2941Kill the child process in which your program is running under @value{GDBN}.
2942@end table
2943
2944This command is useful if you wish to debug a core dump instead of a
2945running process. @value{GDBN} ignores any core dump file while your program
2946is running.
2947
2948On some operating systems, a program cannot be executed outside @value{GDBN}
2949while you have breakpoints set on it inside @value{GDBN}. You can use the
2950@code{kill} command in this situation to permit running your program
2951outside the debugger.
2952
2953The @code{kill} command is also useful if you wish to recompile and
2954relink your program, since on many systems it is impossible to modify an
2955executable file while it is running in a process. In this case, when you
2956next type @code{run}, @value{GDBN} notices that the file has changed, and
2957reads the symbol table again (while trying to preserve your current
2958breakpoint settings).
2959
65c574f6
PA
2960@node Inferiors Connections and Programs
2961@section Debugging Multiple Inferiors Connections and Programs
b77209e0 2962
6c95b8df
PA
2963@value{GDBN} lets you run and debug multiple programs in a single
2964session. In addition, @value{GDBN} on some systems may let you run
2965several programs simultaneously (otherwise you have to exit from one
65c574f6
PA
2966before starting another). On some systems @value{GDBN} may even let
2967you debug several programs simultaneously on different remote systems.
2968In the most general case, you can have multiple threads of execution
2969in each of multiple processes, launched from multiple executables,
2970running on different machines.
b77209e0
PA
2971
2972@cindex inferior
2973@value{GDBN} represents the state of each program execution with an
2974object called an @dfn{inferior}. An inferior typically corresponds to
2975a process, but is more general and applies also to targets that do not
2976have processes. Inferiors may be created before a process runs, and
6c95b8df
PA
2977may be retained after a process exits. Inferiors have unique
2978identifiers that are different from process ids. Usually each
2979inferior will also have its own distinct address space, although some
2980embedded targets may have several inferiors running in different parts
2981of a single address space. Each inferior may in turn have multiple
2982threads running in it.
b77209e0 2983
6c95b8df
PA
2984To find out what inferiors exist at any moment, use @w{@code{info
2985inferiors}}:
b77209e0
PA
2986
2987@table @code
a3c25011 2988@kindex info inferiors [ @var{id}@dots{} ]
b77209e0
PA
2989@item info inferiors
2990Print a list of all inferiors currently being managed by @value{GDBN}.
a3c25011
TT
2991By default all inferiors are printed, but the argument @var{id}@dots{}
2992-- a space separated list of inferior numbers -- can be used to limit
2993the display to just the requested inferiors.
3a1ff0b6
PA
2994
2995@value{GDBN} displays for each inferior (in this order):
2996
2997@enumerate
2998@item
2999the inferior number assigned by @value{GDBN}
3000
3001@item
3002the target system's inferior identifier
6c95b8df 3003
65c574f6
PA
3004@item
3005the target connection the inferior is bound to, including the unique
3006connection number assigned by @value{GDBN}, and the protocol used by
3007the connection.
3008
6c95b8df
PA
3009@item
3010the name of the executable the inferior is running.
3011
3a1ff0b6
PA
3012@end enumerate
3013
3014@noindent
3015An asterisk @samp{*} preceding the @value{GDBN} inferior number
3016indicates the current inferior.
3017
3018For example,
2277426b 3019@end table
3a1ff0b6
PA
3020@c end table here to get a little more width for example
3021
3022@smallexample
3023(@value{GDBP}) info inferiors
65c574f6
PA
3024 Num Description Connection Executable
3025* 1 process 3401 1 (native) goodbye
3026 2 process 2307 2 (extended-remote host:10000) hello
3027@end smallexample
3028
3029To find out what open target connections exist at any moment, use
3030@w{@code{info connections}}:
3031
3032@table @code
3033@kindex info connections [ @var{id}@dots{} ]
3034@item info connections
3035Print a list of all open target connections currently being managed by
3036@value{GDBN}. By default all connections are printed, but the
3037argument @var{id}@dots{} -- a space separated list of connections
3038numbers -- can be used to limit the display to just the requested
3039connections.
3040
3041@value{GDBN} displays for each connection (in this order):
3042
3043@enumerate
3044@item
3045the connection number assigned by @value{GDBN}.
3046
3047@item
3048the protocol used by the connection.
3049
3050@item
3051a textual description of the protocol used by the connection.
3052
3053@end enumerate
3054
3055@noindent
3056An asterisk @samp{*} preceding the connection number indicates the
3057connection of the current inferior.
3058
3059For example,
3060@end table
3061@c end table here to get a little more width for example
3062
3063@smallexample
3064(@value{GDBP}) info connections
3065 Num What Description
3066* 1 extended-remote host:10000 Extended remote serial target in gdb-specific protocol
3067 2 native Native process
3068 3 core Local core dump file
3a1ff0b6 3069@end smallexample
2277426b
PA
3070
3071To switch focus between inferiors, use the @code{inferior} command:
3072
3073@table @code
3a1ff0b6
PA
3074@kindex inferior @var{infno}
3075@item inferior @var{infno}
3076Make inferior number @var{infno} the current inferior. The argument
3077@var{infno} is the inferior number assigned by @value{GDBN}, as shown
3078in the first field of the @samp{info inferiors} display.
2277426b
PA
3079@end table
3080
e3940304
PA
3081@vindex $_inferior@r{, convenience variable}
3082The debugger convenience variable @samp{$_inferior} contains the
3083number of the current inferior. You may find this useful in writing
3084breakpoint conditional expressions, command scripts, and so forth.
3085@xref{Convenience Vars,, Convenience Variables}, for general
3086information on convenience variables.
6c95b8df
PA
3087
3088You can get multiple executables into a debugging session via the
3089@code{add-inferior} and @w{@code{clone-inferior}} commands. On some
3090systems @value{GDBN} can add inferiors to the debug session
3091automatically by following calls to @code{fork} and @code{exec}. To
3092remove inferiors from the debugging session use the
af624141 3093@w{@code{remove-inferiors}} command.
6c95b8df
PA
3094
3095@table @code
3096@kindex add-inferior
65c574f6 3097@item add-inferior [ -copies @var{n} ] [ -exec @var{executable} ] [-no-connection ]
6c95b8df 3098Adds @var{n} inferiors to be run using @var{executable} as the
697aa1b7 3099executable; @var{n} defaults to 1. If no executable is specified,
6c95b8df
PA
3100the inferiors begins empty, with no program. You can still assign or
3101change the program assigned to the inferior at any time by using the
3102@code{file} command with the executable name as its argument.
3103
65c574f6
PA
3104By default, the new inferior begins connected to the same target
3105connection as the current inferior. For example, if the current
3106inferior was connected to @code{gdbserver} with @code{target remote},
3107then the new inferior will be connected to the same @code{gdbserver}
3108instance. The @samp{-no-connection} option starts the new inferior
3109with no connection yet. You can then for example use the @code{target
3110remote} command to connect to some other @code{gdbserver} instance,
3111use @code{run} to spawn a local program, etc.
3112
6c95b8df
PA
3113@kindex clone-inferior
3114@item clone-inferior [ -copies @var{n} ] [ @var{infno} ]
3115Adds @var{n} inferiors ready to execute the same program as inferior
697aa1b7 3116@var{infno}; @var{n} defaults to 1, and @var{infno} defaults to the
6c95b8df
PA
3117number of the current inferior. This is a convenient command when you
3118want to run another instance of the inferior you are debugging.
3119
3120@smallexample
3121(@value{GDBP}) info inferiors
65c574f6
PA
3122 Num Description Connection Executable
3123* 1 process 29964 1 (native) helloworld
6c95b8df
PA
3124(@value{GDBP}) clone-inferior
3125Added inferior 2.
31261 inferiors added.
3127(@value{GDBP}) info inferiors
65c574f6
PA
3128 Num Description Connection Executable
3129* 1 process 29964 1 (native) helloworld
3130 2 <null> 1 (native) helloworld
6c95b8df
PA
3131@end smallexample
3132
3133You can now simply switch focus to inferior 2 and run it.
3134
af624141
MS
3135@kindex remove-inferiors
3136@item remove-inferiors @var{infno}@dots{}
3137Removes the inferior or inferiors @var{infno}@dots{}. It is not
3138possible to remove an inferior that is running with this command. For
3139those, use the @code{kill} or @code{detach} command first.
6c95b8df
PA
3140
3141@end table
3142
3143To quit debugging one of the running inferiors that is not the current
3144inferior, you can either detach from it by using the @w{@code{detach
3145inferior}} command (allowing it to run independently), or kill it
af624141 3146using the @w{@code{kill inferiors}} command:
2277426b
PA
3147
3148@table @code
af624141
MS
3149@kindex detach inferiors @var{infno}@dots{}
3150@item detach inferior @var{infno}@dots{}
3151Detach from the inferior or inferiors identified by @value{GDBN}
5e30da2c 3152inferior number(s) @var{infno}@dots{}. Note that the inferior's entry
af624141
MS
3153still stays on the list of inferiors shown by @code{info inferiors},
3154but its Description will show @samp{<null>}.
3155
3156@kindex kill inferiors @var{infno}@dots{}
3157@item kill inferiors @var{infno}@dots{}
3158Kill the inferior or inferiors identified by @value{GDBN} inferior
3159number(s) @var{infno}@dots{}. Note that the inferior's entry still
3160stays on the list of inferiors shown by @code{info inferiors}, but its
3161Description will show @samp{<null>}.
2277426b
PA
3162@end table
3163
6c95b8df 3164After the successful completion of a command such as @code{detach},
af624141 3165@code{detach inferiors}, @code{kill} or @code{kill inferiors}, or after
6c95b8df
PA
3166a normal process exit, the inferior is still valid and listed with
3167@code{info inferiors}, ready to be restarted.
3168
3169
2277426b
PA
3170To be notified when inferiors are started or exit under @value{GDBN}'s
3171control use @w{@code{set print inferior-events}}:
b77209e0 3172
2277426b 3173@table @code
b77209e0
PA
3174@kindex set print inferior-events
3175@cindex print messages on inferior start and exit
3176@item set print inferior-events
3177@itemx set print inferior-events on
3178@itemx set print inferior-events off
3179The @code{set print inferior-events} command allows you to enable or
3180disable printing of messages when @value{GDBN} notices that new
3181inferiors have started or that inferiors have exited or have been
3182detached. By default, these messages will not be printed.
3183
3184@kindex show print inferior-events
3185@item show print inferior-events
3186Show whether messages will be printed when @value{GDBN} detects that
3187inferiors have started, exited or have been detached.
3188@end table
3189
6c95b8df
PA
3190Many commands will work the same with multiple programs as with a
3191single program: e.g., @code{print myglobal} will simply display the
3192value of @code{myglobal} in the current inferior.
3193
3194
6b92c0d3 3195Occasionally, when debugging @value{GDBN} itself, it may be useful to
6c95b8df
PA
3196get more info about the relationship of inferiors, programs, address
3197spaces in a debug session. You can do that with the @w{@code{maint
3198info program-spaces}} command.
3199
3200@table @code
3201@kindex maint info program-spaces
3202@item maint info program-spaces
3203Print a list of all program spaces currently being managed by
3204@value{GDBN}.
3205
3206@value{GDBN} displays for each program space (in this order):
3207
3208@enumerate
3209@item
3210the program space number assigned by @value{GDBN}
3211
3212@item
3213the name of the executable loaded into the program space, with e.g.,
3214the @code{file} command.
3215
3216@end enumerate
3217
3218@noindent
3219An asterisk @samp{*} preceding the @value{GDBN} program space number
3220indicates the current program space.
3221
3222In addition, below each program space line, @value{GDBN} prints extra
3223information that isn't suitable to display in tabular form. For
3224example, the list of inferiors bound to the program space.
3225
3226@smallexample
3227(@value{GDBP}) maint info program-spaces
3228 Id Executable
b05b1202 3229* 1 hello
6c95b8df
PA
3230 2 goodbye
3231 Bound inferiors: ID 1 (process 21561)
6c95b8df
PA
3232@end smallexample
3233
3234Here we can see that no inferior is running the program @code{hello},
3235while @code{process 21561} is running the program @code{goodbye}. On
3236some targets, it is possible that multiple inferiors are bound to the
3237same program space. The most common example is that of debugging both
3238the parent and child processes of a @code{vfork} call. For example,
3239
3240@smallexample
3241(@value{GDBP}) maint info program-spaces
3242 Id Executable
3243* 1 vfork-test
3244 Bound inferiors: ID 2 (process 18050), ID 1 (process 18045)
3245@end smallexample
3246
3247Here, both inferior 2 and inferior 1 are running in the same program
3248space as a result of inferior 1 having executed a @code{vfork} call.
3249@end table
3250
6d2ebf8b 3251@node Threads
79a6e687 3252@section Debugging Programs with Multiple Threads
c906108c
SS
3253
3254@cindex threads of execution
3255@cindex multiple threads
3256@cindex switching threads
b1236ac3 3257In some operating systems, such as GNU/Linux and Solaris, a single program
c906108c
SS
3258may have more than one @dfn{thread} of execution. The precise semantics
3259of threads differ from one operating system to another, but in general
3260the threads of a single program are akin to multiple processes---except
3261that they share one address space (that is, they can all examine and
3262modify the same variables). On the other hand, each thread has its own
3263registers and execution stack, and perhaps private memory.
3264
3265@value{GDBN} provides these facilities for debugging multi-thread
3266programs:
3267
3268@itemize @bullet
3269@item automatic notification of new threads
5d5658a1 3270@item @samp{thread @var{thread-id}}, a command to switch among threads
c906108c 3271@item @samp{info threads}, a command to inquire about existing threads
0a232300 3272@item @samp{thread apply [@var{thread-id-list} | all] @var{args}},
c906108c
SS
3273a command to apply a command to a list of threads
3274@item thread-specific breakpoints
93815fbf
VP
3275@item @samp{set print thread-events}, which controls printing of
3276messages on thread start and exit.
17a37d48
PP
3277@item @samp{set libthread-db-search-path @var{path}}, which lets
3278the user specify which @code{libthread_db} to use if the default choice
3279isn't compatible with the program.
c906108c
SS
3280@end itemize
3281
c906108c
SS
3282@cindex focus of debugging
3283@cindex current thread
3284The @value{GDBN} thread debugging facility allows you to observe all
3285threads while your program runs---but whenever @value{GDBN} takes
3286control, one thread in particular is always the focus of debugging.
3287This thread is called the @dfn{current thread}. Debugging commands show
3288program information from the perspective of the current thread.
3289
41afff9a 3290@cindex @code{New} @var{systag} message
c906108c
SS
3291@cindex thread identifier (system)
3292@c FIXME-implementors!! It would be more helpful if the [New...] message
3293@c included GDB's numeric thread handle, so you could just go to that
3294@c thread without first checking `info threads'.
3295Whenever @value{GDBN} detects a new thread in your program, it displays
3296the target system's identification for the thread with a message in the
697aa1b7 3297form @samp{[New @var{systag}]}, where @var{systag} is a thread identifier
c906108c 3298whose form varies depending on the particular system. For example, on
8807d78b 3299@sc{gnu}/Linux, you might see
c906108c 3300
474c8240 3301@smallexample
08e796bc 3302[New Thread 0x41e02940 (LWP 25582)]
474c8240 3303@end smallexample
c906108c
SS
3304
3305@noindent
b1236ac3 3306when @value{GDBN} notices a new thread. In contrast, on other systems,
c906108c
SS
3307the @var{systag} is simply something like @samp{process 368}, with no
3308further qualifier.
3309
3310@c FIXME!! (1) Does the [New...] message appear even for the very first
3311@c thread of a program, or does it only appear for the
6ca652b0 3312@c second---i.e.@: when it becomes obvious we have a multithread
c906108c
SS
3313@c program?
3314@c (2) *Is* there necessarily a first thread always? Or do some
3315@c multithread systems permit starting a program with multiple
5d161b24 3316@c threads ab initio?
c906108c 3317
5d5658a1
PA
3318@anchor{thread numbers}
3319@cindex thread number, per inferior
c906108c 3320@cindex thread identifier (GDB)
5d5658a1
PA
3321For debugging purposes, @value{GDBN} associates its own thread number
3322---always a single integer---with each thread of an inferior. This
3323number is unique between all threads of an inferior, but not unique
3324between threads of different inferiors.
3325
3326@cindex qualified thread ID
3327You can refer to a given thread in an inferior using the qualified
3328@var{inferior-num}.@var{thread-num} syntax, also known as
3329@dfn{qualified thread ID}, with @var{inferior-num} being the inferior
3330number and @var{thread-num} being the thread number of the given
3331inferior. For example, thread @code{2.3} refers to thread number 3 of
3332inferior 2. If you omit @var{inferior-num} (e.g., @code{thread 3}),
3333then @value{GDBN} infers you're referring to a thread of the current
3334inferior.
3335
3336Until you create a second inferior, @value{GDBN} does not show the
3337@var{inferior-num} part of thread IDs, even though you can always use
3338the full @var{inferior-num}.@var{thread-num} form to refer to threads
3339of inferior 1, the initial inferior.
3340
3341@anchor{thread ID lists}
3342@cindex thread ID lists
3343Some commands accept a space-separated @dfn{thread ID list} as
71ef29a8
PA
3344argument. A list element can be:
3345
3346@enumerate
3347@item
3348A thread ID as shown in the first field of the @samp{info threads}
3349display, with or without an inferior qualifier. E.g., @samp{2.1} or
3350@samp{1}.
3351
3352@item
3353A range of thread numbers, again with or without an inferior
3354qualifier, as in @var{inf}.@var{thr1}-@var{thr2} or
3355@var{thr1}-@var{thr2}. E.g., @samp{1.2-4} or @samp{2-4}.
3356
3357@item
3358All threads of an inferior, specified with a star wildcard, with or
3359without an inferior qualifier, as in @var{inf}.@code{*} (e.g.,
3360@samp{1.*}) or @code{*}. The former refers to all threads of the
3361given inferior, and the latter form without an inferior qualifier
3362refers to all threads of the current inferior.
3363
3364@end enumerate
3365
3366For example, if the current inferior is 1, and inferior 7 has one
3367thread with ID 7.1, the thread list @samp{1 2-3 4.5 6.7-9 7.*}
3368includes threads 1 to 3 of inferior 1, thread 5 of inferior 4, threads
33697 to 9 of inferior 6 and all threads of inferior 7. That is, in
3370expanded qualified form, the same as @samp{1.1 1.2 1.3 4.5 6.7 6.8 6.9
33717.1}.
3372
5d5658a1
PA
3373
3374@anchor{global thread numbers}
3375@cindex global thread number
3376@cindex global thread identifier (GDB)
3377In addition to a @emph{per-inferior} number, each thread is also
3378assigned a unique @emph{global} number, also known as @dfn{global
3379thread ID}, a single integer. Unlike the thread number component of
3380the thread ID, no two threads have the same global ID, even when
3381you're debugging multiple inferiors.
c906108c 3382
f4f4330e
PA
3383From @value{GDBN}'s perspective, a process always has at least one
3384thread. In other words, @value{GDBN} assigns a thread number to the
3385program's ``main thread'' even if the program is not multi-threaded.
3386
5d5658a1 3387@vindex $_thread@r{, convenience variable}
663f6d42
PA
3388@vindex $_gthread@r{, convenience variable}
3389The debugger convenience variables @samp{$_thread} and
3390@samp{$_gthread} contain, respectively, the per-inferior thread number
3391and the global thread number of the current thread. You may find this
5d5658a1
PA
3392useful in writing breakpoint conditional expressions, command scripts,
3393and so forth. @xref{Convenience Vars,, Convenience Variables}, for
3394general information on convenience variables.
3395
f303dbd6
PA
3396If @value{GDBN} detects the program is multi-threaded, it augments the
3397usual message about stopping at a breakpoint with the ID and name of
3398the thread that hit the breakpoint.
3399
3400@smallexample
3401Thread 2 "client" hit Breakpoint 1, send_message () at client.c:68
3402@end smallexample
3403
3404Likewise when the program receives a signal:
3405
3406@smallexample
3407Thread 1 "main" received signal SIGINT, Interrupt.
3408@end smallexample
3409
c906108c
SS
3410@table @code
3411@kindex info threads
5d5658a1
PA
3412@item info threads @r{[}@var{thread-id-list}@r{]}
3413
3414Display information about one or more threads. With no arguments
3415displays information about all threads. You can specify the list of
3416threads that you want to display using the thread ID list syntax
3417(@pxref{thread ID lists}).
3418
60f98dde 3419@value{GDBN} displays for each thread (in this order):
c906108c
SS
3420
3421@enumerate
09d4efe1 3422@item
5d5658a1 3423the per-inferior thread number assigned by @value{GDBN}
c906108c 3424
c84f6bbf
PA
3425@item
3426the global thread number assigned by @value{GDBN}, if the @samp{-gid}
3427option was specified
3428
09d4efe1
EZ
3429@item
3430the target system's thread identifier (@var{systag})
c906108c 3431
4694da01
TT
3432@item
3433the thread's name, if one is known. A thread can either be named by
3434the user (see @code{thread name}, below), or, in some cases, by the
3435program itself.
3436
09d4efe1
EZ
3437@item
3438the current stack frame summary for that thread
c906108c
SS
3439@end enumerate
3440
3441@noindent
3442An asterisk @samp{*} to the left of the @value{GDBN} thread number
3443indicates the current thread.
3444
5d161b24 3445For example,
c906108c
SS
3446@end table
3447@c end table here to get a little more width for example
3448
3449@smallexample
3450(@value{GDBP}) info threads
13fd8b81 3451 Id Target Id Frame
c0ecb95f 3452* 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
b05b1202
PA
3453 2 process 35 thread 23 0x34e5 in sigpause ()
3454 3 process 35 thread 27 0x34e5 in sigpause ()
c906108c
SS
3455 at threadtest.c:68
3456@end smallexample
53a5351d 3457
5d5658a1
PA
3458If you're debugging multiple inferiors, @value{GDBN} displays thread
3459IDs using the qualified @var{inferior-num}.@var{thread-num} format.
c84f6bbf
PA
3460Otherwise, only @var{thread-num} is shown.
3461
3462If you specify the @samp{-gid} option, @value{GDBN} displays a column
3463indicating each thread's global thread ID:
5d5658a1
PA
3464
3465@smallexample
3466(@value{GDBP}) info threads
c84f6bbf
PA
3467 Id GId Target Id Frame
3468 1.1 1 process 35 thread 13 main (argc=1, argv=0x7ffffff8)
3469 1.2 3 process 35 thread 23 0x34e5 in sigpause ()
3470 1.3 4 process 35 thread 27 0x34e5 in sigpause ()
3471* 2.1 2 process 65 thread 1 main (argc=1, argv=0x7ffffff8)
5d5658a1
PA
3472@end smallexample
3473
c45da7e6
EZ
3474On Solaris, you can display more information about user threads with a
3475Solaris-specific command:
3476
3477@table @code
3478@item maint info sol-threads
3479@kindex maint info sol-threads
3480@cindex thread info (Solaris)
3481Display info on Solaris user threads.
3482@end table
3483
c906108c 3484@table @code
5d5658a1
PA
3485@kindex thread @var{thread-id}
3486@item thread @var{thread-id}
3487Make thread ID @var{thread-id} the current thread. The command
3488argument @var{thread-id} is the @value{GDBN} thread ID, as shown in
3489the first field of the @samp{info threads} display, with or without an
3490inferior qualifier (e.g., @samp{2.1} or @samp{1}).
3491
3492@value{GDBN} responds by displaying the system identifier of the
3493thread you selected, and its current stack frame summary:
c906108c
SS
3494
3495@smallexample
c906108c 3496(@value{GDBP}) thread 2
13fd8b81
TT
3497[Switching to thread 2 (Thread 0xb7fdab70 (LWP 12747))]
3498#0 some_function (ignore=0x0) at example.c:8
34998 printf ("hello\n");
c906108c
SS
3500@end smallexample
3501
3502@noindent
3503As with the @samp{[New @dots{}]} message, the form of the text after
3504@samp{Switching to} depends on your system's conventions for identifying
5d161b24 3505threads.
c906108c 3506
3345721a 3507@anchor{thread apply all}
9c16f35a 3508@kindex thread apply
638ac427 3509@cindex apply command to several threads
0a232300 3510@item thread apply [@var{thread-id-list} | all [-ascending]] [@var{flag}]@dots{} @var{command}
839c27b7 3511The @code{thread apply} command allows you to apply the named
5d5658a1
PA
3512@var{command} to one or more threads. Specify the threads that you
3513want affected using the thread ID list syntax (@pxref{thread ID
3514lists}), or specify @code{all} to apply to all threads. To apply a
3515command to all threads in descending order, type @kbd{thread apply all
253828f1
JK
3516@var{command}}. To apply a command to all threads in ascending order,
3517type @kbd{thread apply all -ascending @var{command}}.
3518
0a232300
PW
3519The @var{flag} arguments control what output to produce and how to handle
3520errors raised when applying @var{command} to a thread. @var{flag}
3521must start with a @code{-} directly followed by one letter in
3522@code{qcs}. If several flags are provided, they must be given
3523individually, such as @code{-c -q}.
3524
3525By default, @value{GDBN} displays some thread information before the
3526output produced by @var{command}, and an error raised during the
3527execution of a @var{command} will abort @code{thread apply}. The
3528following flags can be used to fine-tune this behavior:
3529
3530@table @code
3531@item -c
3532The flag @code{-c}, which stands for @samp{continue}, causes any
3533errors in @var{command} to be displayed, and the execution of
3534@code{thread apply} then continues.
3535@item -s
3536The flag @code{-s}, which stands for @samp{silent}, causes any errors
3537or empty output produced by a @var{command} to be silently ignored.
3538That is, the execution continues, but the thread information and errors
3539are not printed.
3540@item -q
3541The flag @code{-q} (@samp{quiet}) disables printing the thread
3542information.
3543@end table
3544
3545Flags @code{-c} and @code{-s} cannot be used together.
3546
3547@kindex taas
3548@cindex apply command to all threads (ignoring errors and empty output)
3345721a
PA
3549@item taas [@var{option}]@dots{} @var{command}
3550Shortcut for @code{thread apply all -s [@var{option}]@dots{} @var{command}}.
0a232300
PW
3551Applies @var{command} on all threads, ignoring errors and empty output.
3552
3345721a
PA
3553The @code{taas} command accepts the same options as the @code{thread
3554apply all} command. @xref{thread apply all}.
3555
0a232300
PW
3556@kindex tfaas
3557@cindex apply a command to all frames of all threads (ignoring errors and empty output)
3345721a
PA
3558@item tfaas [@var{option}]@dots{} @var{command}
3559Shortcut for @code{thread apply all -s -- frame apply all -s [@var{option}]@dots{} @var{command}}.
0a232300
PW
3560Applies @var{command} on all frames of all threads, ignoring errors
3561and empty output. Note that the flag @code{-s} is specified twice:
3562The first @code{-s} ensures that @code{thread apply} only shows the thread
3563information of the threads for which @code{frame apply} produces
3564some output. The second @code{-s} is needed to ensure that @code{frame
3565apply} shows the frame information of a frame only if the
3566@var{command} successfully produced some output.
3567
3568It can for example be used to print a local variable or a function
3569argument without knowing the thread or frame where this variable or argument
3570is, using:
3571@smallexample
3572(@value{GDBP}) tfaas p some_local_var_i_do_not_remember_where_it_is
3573@end smallexample
3574
3345721a
PA
3575The @code{tfaas} command accepts the same options as the @code{frame
3576apply} command. @xref{frame apply}.
93815fbf 3577
4694da01
TT
3578@kindex thread name
3579@cindex name a thread
3580@item thread name [@var{name}]
3581This command assigns a name to the current thread. If no argument is
3582given, any existing user-specified name is removed. The thread name
3583appears in the @samp{info threads} display.
3584
3585On some systems, such as @sc{gnu}/Linux, @value{GDBN} is able to
3586determine the name of the thread as given by the OS. On these
3587systems, a name specified with @samp{thread name} will override the
3588system-give name, and removing the user-specified name will cause
3589@value{GDBN} to once again display the system-specified name.
3590
60f98dde
MS
3591@kindex thread find
3592@cindex search for a thread
3593@item thread find [@var{regexp}]
3594Search for and display thread ids whose name or @var{systag}
3595matches the supplied regular expression.
3596
3597As well as being the complement to the @samp{thread name} command,
3598this command also allows you to identify a thread by its target
3599@var{systag}. For instance, on @sc{gnu}/Linux, the target @var{systag}
3600is the LWP id.
3601
3602@smallexample
3603(@value{GDBN}) thread find 26688
3604Thread 4 has target id 'Thread 0x41e02940 (LWP 26688)'
3605(@value{GDBN}) info thread 4
3606 Id Target Id Frame
3607 4 Thread 0x41e02940 (LWP 26688) 0x00000031ca6cd372 in select ()
3608@end smallexample
3609
93815fbf
VP
3610@kindex set print thread-events
3611@cindex print messages on thread start and exit
3612@item set print thread-events
3613@itemx set print thread-events on
3614@itemx set print thread-events off
3615The @code{set print thread-events} command allows you to enable or
3616disable printing of messages when @value{GDBN} notices that new threads have
3617started or that threads have exited. By default, these messages will
3618be printed if detection of these events is supported by the target.
3619Note that these messages cannot be disabled on all targets.
3620
3621@kindex show print thread-events
3622@item show print thread-events
3623Show whether messages will be printed when @value{GDBN} detects that threads
3624have started and exited.
c906108c
SS
3625@end table
3626
79a6e687 3627@xref{Thread Stops,,Stopping and Starting Multi-thread Programs}, for
c906108c
SS
3628more information about how @value{GDBN} behaves when you stop and start
3629programs with multiple threads.
3630
79a6e687 3631@xref{Set Watchpoints,,Setting Watchpoints}, for information about
c906108c 3632watchpoints in programs with multiple threads.
c906108c 3633
bf88dd68 3634@anchor{set libthread-db-search-path}
17a37d48
PP
3635@table @code
3636@kindex set libthread-db-search-path
3637@cindex search path for @code{libthread_db}
3638@item set libthread-db-search-path @r{[}@var{path}@r{]}
3639If this variable is set, @var{path} is a colon-separated list of
3640directories @value{GDBN} will use to search for @code{libthread_db}.
3641If you omit @var{path}, @samp{libthread-db-search-path} will be reset to
98a5dd13 3642its default value (@code{$sdir:$pdir} on @sc{gnu}/Linux and Solaris systems).
7e0396aa
DE
3643Internally, the default value comes from the @code{LIBTHREAD_DB_SEARCH_PATH}
3644macro.
17a37d48
PP
3645
3646On @sc{gnu}/Linux and Solaris systems, @value{GDBN} uses a ``helper''
3647@code{libthread_db} library to obtain information about threads in the
3648inferior process. @value{GDBN} will use @samp{libthread-db-search-path}
bf88dd68
JK
3649to find @code{libthread_db}. @value{GDBN} also consults first if inferior
3650specific thread debugging library loading is enabled
3651by @samp{set auto-load libthread-db} (@pxref{libthread_db.so.1 file}).
98a5dd13
DE
3652
3653A special entry @samp{$sdir} for @samp{libthread-db-search-path}
3654refers to the default system directories that are
bf88dd68
JK
3655normally searched for loading shared libraries. The @samp{$sdir} entry
3656is the only kind not needing to be enabled by @samp{set auto-load libthread-db}
3657(@pxref{libthread_db.so.1 file}).
98a5dd13
DE
3658
3659A special entry @samp{$pdir} for @samp{libthread-db-search-path}
3660refers to the directory from which @code{libpthread}
3661was loaded in the inferior process.
17a37d48
PP
3662
3663For any @code{libthread_db} library @value{GDBN} finds in above directories,
3664@value{GDBN} attempts to initialize it with the current inferior process.
3665If this initialization fails (which could happen because of a version
3666mismatch between @code{libthread_db} and @code{libpthread}), @value{GDBN}
3667will unload @code{libthread_db}, and continue with the next directory.
3668If none of @code{libthread_db} libraries initialize successfully,
3669@value{GDBN} will issue a warning and thread debugging will be disabled.
3670
3671Setting @code{libthread-db-search-path} is currently implemented
3672only on some platforms.
3673
3674@kindex show libthread-db-search-path
3675@item show libthread-db-search-path
3676Display current libthread_db search path.
02d868e8
PP
3677
3678@kindex set debug libthread-db
3679@kindex show debug libthread-db
3680@cindex debugging @code{libthread_db}
3681@item set debug libthread-db
3682@itemx show debug libthread-db
3683Turns on or off display of @code{libthread_db}-related events.
3684Use @code{1} to enable, @code{0} to disable.
17a37d48
PP
3685@end table
3686
6c95b8df
PA
3687@node Forks
3688@section Debugging Forks
c906108c
SS
3689
3690@cindex fork, debugging programs which call
3691@cindex multiple processes
3692@cindex processes, multiple
53a5351d
JM
3693On most systems, @value{GDBN} has no special support for debugging
3694programs which create additional processes using the @code{fork}
3695function. When a program forks, @value{GDBN} will continue to debug the
3696parent process and the child process will run unimpeded. If you have
3697set a breakpoint in any code which the child then executes, the child
3698will get a @code{SIGTRAP} signal which (unless it catches the signal)
3699will cause it to terminate.
c906108c
SS
3700
3701However, if you want to debug the child process there is a workaround
3702which isn't too painful. Put a call to @code{sleep} in the code which
3703the child process executes after the fork. It may be useful to sleep
3704only if a certain environment variable is set, or a certain file exists,
3705so that the delay need not occur when you don't want to run @value{GDBN}
3706on the child. While the child is sleeping, use the @code{ps} program to
3707get its process ID. Then tell @value{GDBN} (a new invocation of
3708@value{GDBN} if you are also debugging the parent process) to attach to
d4f3574e 3709the child process (@pxref{Attach}). From that point on you can debug
c906108c 3710the child process just like any other process which you attached to.
c906108c 3711
b1236ac3
PA
3712On some systems, @value{GDBN} provides support for debugging programs
3713that create additional processes using the @code{fork} or @code{vfork}
3714functions. On @sc{gnu}/Linux platforms, this feature is supported
19d9d4ef 3715with kernel version 2.5.46 and later.
c906108c 3716
19d9d4ef
DB
3717The fork debugging commands are supported in native mode and when
3718connected to @code{gdbserver} in either @code{target remote} mode or
3719@code{target extended-remote} mode.
0d71eef5 3720
c906108c
SS
3721By default, when a program forks, @value{GDBN} will continue to debug
3722the parent process and the child process will run unimpeded.
3723
3724If you want to follow the child process instead of the parent process,
3725use the command @w{@code{set follow-fork-mode}}.
3726
3727@table @code
3728@kindex set follow-fork-mode
3729@item set follow-fork-mode @var{mode}
3730Set the debugger response to a program call of @code{fork} or
3731@code{vfork}. A call to @code{fork} or @code{vfork} creates a new
9c16f35a 3732process. The @var{mode} argument can be:
c906108c
SS
3733
3734@table @code
3735@item parent
3736The original process is debugged after a fork. The child process runs
2df3850c 3737unimpeded. This is the default.
c906108c
SS
3738
3739@item child
3740The new process is debugged after a fork. The parent process runs
3741unimpeded.
3742
c906108c
SS
3743@end table
3744
9c16f35a 3745@kindex show follow-fork-mode
c906108c 3746@item show follow-fork-mode
2df3850c 3747Display the current debugger response to a @code{fork} or @code{vfork} call.
c906108c
SS
3748@end table
3749
5c95884b
MS
3750@cindex debugging multiple processes
3751On Linux, if you want to debug both the parent and child processes, use the
3752command @w{@code{set detach-on-fork}}.
3753
3754@table @code
3755@kindex set detach-on-fork
3756@item set detach-on-fork @var{mode}
3757Tells gdb whether to detach one of the processes after a fork, or
3758retain debugger control over them both.
3759
3760@table @code
3761@item on
3762The child process (or parent process, depending on the value of
3763@code{follow-fork-mode}) will be detached and allowed to run
3764independently. This is the default.
3765
3766@item off
3767Both processes will be held under the control of @value{GDBN}.
3768One process (child or parent, depending on the value of
3769@code{follow-fork-mode}) is debugged as usual, while the other
3770is held suspended.
3771
3772@end table
3773
11310833
NR
3774@kindex show detach-on-fork
3775@item show detach-on-fork
3776Show whether detach-on-fork mode is on/off.
5c95884b
MS
3777@end table
3778
2277426b
PA
3779If you choose to set @samp{detach-on-fork} mode off, then @value{GDBN}
3780will retain control of all forked processes (including nested forks).
3781You can list the forked processes under the control of @value{GDBN} by
3782using the @w{@code{info inferiors}} command, and switch from one fork
65c574f6
PA
3783to another by using the @code{inferior} command (@pxref{Inferiors Connections and
3784Programs, ,Debugging Multiple Inferiors Connections and Programs}).
5c95884b
MS
3785
3786To quit debugging one of the forked processes, you can either detach
af624141
MS
3787from it by using the @w{@code{detach inferiors}} command (allowing it
3788to run independently), or kill it using the @w{@code{kill inferiors}}
65c574f6
PA
3789command. @xref{Inferiors Connections and Programs, ,Debugging
3790Multiple Inferiors Connections and Programs}.
5c95884b 3791
c906108c
SS
3792If you ask to debug a child process and a @code{vfork} is followed by an
3793@code{exec}, @value{GDBN} executes the new target up to the first
3794breakpoint in the new target. If you have a breakpoint set on
3795@code{main} in your original program, the breakpoint will also be set on
3796the child process's @code{main}.
3797
2277426b
PA
3798On some systems, when a child process is spawned by @code{vfork}, you
3799cannot debug the child or parent until an @code{exec} call completes.
c906108c
SS
3800
3801If you issue a @code{run} command to @value{GDBN} after an @code{exec}
6c95b8df
PA
3802call executes, the new target restarts. To restart the parent
3803process, use the @code{file} command with the parent executable name
3804as its argument. By default, after an @code{exec} call executes,
3805@value{GDBN} discards the symbols of the previous executable image.
3806You can change this behaviour with the @w{@code{set follow-exec-mode}}
3807command.
3808
3809@table @code
3810@kindex set follow-exec-mode
3811@item set follow-exec-mode @var{mode}
3812
3813Set debugger response to a program call of @code{exec}. An
3814@code{exec} call replaces the program image of a process.
3815
3816@code{follow-exec-mode} can be:
3817
3818@table @code
3819@item new
3820@value{GDBN} creates a new inferior and rebinds the process to this
3821new inferior. The program the process was running before the
3822@code{exec} call can be restarted afterwards by restarting the
3823original inferior.
3824
3825For example:
3826
3827@smallexample
3828(@value{GDBP}) info inferiors
3829(gdb) info inferior
3830 Id Description Executable
3831* 1 <null> prog1
3832(@value{GDBP}) run
3833process 12020 is executing new program: prog2
3834Program exited normally.
3835(@value{GDBP}) info inferiors
3836 Id Description Executable
c0ecb95f 3837 1 <null> prog1
b05b1202 3838* 2 <null> prog2
6c95b8df
PA
3839@end smallexample
3840
3841@item same
3842@value{GDBN} keeps the process bound to the same inferior. The new
3843executable image replaces the previous executable loaded in the
3844inferior. Restarting the inferior after the @code{exec} call, with
3845e.g., the @code{run} command, restarts the executable the process was
3846running after the @code{exec} call. This is the default mode.
3847
3848For example:
3849
3850@smallexample
3851(@value{GDBP}) info inferiors
3852 Id Description Executable
3853* 1 <null> prog1
3854(@value{GDBP}) run
3855process 12020 is executing new program: prog2
3856Program exited normally.
3857(@value{GDBP}) info inferiors
3858 Id Description Executable
3859* 1 <null> prog2
3860@end smallexample
3861
3862@end table
3863@end table
c906108c 3864
19d9d4ef
DB
3865@code{follow-exec-mode} is supported in native mode and
3866@code{target extended-remote} mode.
3867
c906108c
SS
3868You can use the @code{catch} command to make @value{GDBN} stop whenever
3869a @code{fork}, @code{vfork}, or @code{exec} call is made. @xref{Set
79a6e687 3870Catchpoints, ,Setting Catchpoints}.
c906108c 3871
5c95884b 3872@node Checkpoint/Restart
79a6e687 3873@section Setting a @emph{Bookmark} to Return to Later
5c95884b
MS
3874
3875@cindex checkpoint
3876@cindex restart
3877@cindex bookmark
3878@cindex snapshot of a process
3879@cindex rewind program state
3880
3881On certain operating systems@footnote{Currently, only
3882@sc{gnu}/Linux.}, @value{GDBN} is able to save a @dfn{snapshot} of a
3883program's state, called a @dfn{checkpoint}, and come back to it
3884later.
3885
3886Returning to a checkpoint effectively undoes everything that has
3887happened in the program since the @code{checkpoint} was saved. This
3888includes changes in memory, registers, and even (within some limits)
3889system state. Effectively, it is like going back in time to the
3890moment when the checkpoint was saved.
3891
3892Thus, if you're stepping thru a program and you think you're
3893getting close to the point where things go wrong, you can save
3894a checkpoint. Then, if you accidentally go too far and miss
3895the critical statement, instead of having to restart your program
3896from the beginning, you can just go back to the checkpoint and
3897start again from there.
3898
3899This can be especially useful if it takes a lot of time or
3900steps to reach the point where you think the bug occurs.
3901
3902To use the @code{checkpoint}/@code{restart} method of debugging:
3903
3904@table @code
3905@kindex checkpoint
3906@item checkpoint
3907Save a snapshot of the debugged program's current execution state.
3908The @code{checkpoint} command takes no arguments, but each checkpoint
3909is assigned a small integer id, similar to a breakpoint id.
3910
3911@kindex info checkpoints
3912@item info checkpoints
3913List the checkpoints that have been saved in the current debugging
3914session. For each checkpoint, the following information will be
3915listed:
3916
3917@table @code
3918@item Checkpoint ID
3919@item Process ID
3920@item Code Address
3921@item Source line, or label
3922@end table
3923
3924@kindex restart @var{checkpoint-id}
3925@item restart @var{checkpoint-id}
3926Restore the program state that was saved as checkpoint number
3927@var{checkpoint-id}. All program variables, registers, stack frames
3928etc.@: will be returned to the values that they had when the checkpoint
3929was saved. In essence, gdb will ``wind back the clock'' to the point
3930in time when the checkpoint was saved.
3931
3932Note that breakpoints, @value{GDBN} variables, command history etc.
3933are not affected by restoring a checkpoint. In general, a checkpoint
3934only restores things that reside in the program being debugged, not in
3935the debugger.
3936
b8db102d
MS
3937@kindex delete checkpoint @var{checkpoint-id}
3938@item delete checkpoint @var{checkpoint-id}
5c95884b
MS
3939Delete the previously-saved checkpoint identified by @var{checkpoint-id}.
3940
3941@end table
3942
3943Returning to a previously saved checkpoint will restore the user state
3944of the program being debugged, plus a significant subset of the system
3945(OS) state, including file pointers. It won't ``un-write'' data from
3946a file, but it will rewind the file pointer to the previous location,
3947so that the previously written data can be overwritten. For files
3948opened in read mode, the pointer will also be restored so that the
3949previously read data can be read again.
3950
3951Of course, characters that have been sent to a printer (or other
3952external device) cannot be ``snatched back'', and characters received
3953from eg.@: a serial device can be removed from internal program buffers,
3954but they cannot be ``pushed back'' into the serial pipeline, ready to
3955be received again. Similarly, the actual contents of files that have
3956been changed cannot be restored (at this time).
3957
3958However, within those constraints, you actually can ``rewind'' your
3959program to a previously saved point in time, and begin debugging it
3960again --- and you can change the course of events so as to debug a
3961different execution path this time.
3962
3963@cindex checkpoints and process id
3964Finally, there is one bit of internal program state that will be
3965different when you return to a checkpoint --- the program's process
3966id. Each checkpoint will have a unique process id (or @var{pid}),
3967and each will be different from the program's original @var{pid}.
3968If your program has saved a local copy of its process id, this could
3969potentially pose a problem.
3970
79a6e687 3971@subsection A Non-obvious Benefit of Using Checkpoints
5c95884b
MS
3972
3973On some systems such as @sc{gnu}/Linux, address space randomization
3974is performed on new processes for security reasons. This makes it
3975difficult or impossible to set a breakpoint, or watchpoint, on an
3976absolute address if you have to restart the program, since the
3977absolute location of a symbol will change from one execution to the
3978next.
3979
3980A checkpoint, however, is an @emph{identical} copy of a process.
3981Therefore if you create a checkpoint at (eg.@:) the start of main,
3982and simply return to that checkpoint instead of restarting the
3983process, you can avoid the effects of address randomization and
3984your symbols will all stay in the same place.
3985
6d2ebf8b 3986@node Stopping
c906108c
SS
3987@chapter Stopping and Continuing
3988
3989The principal purposes of using a debugger are so that you can stop your
3990program before it terminates; or so that, if your program runs into
3991trouble, you can investigate and find out why.
3992
7a292a7a
SS
3993Inside @value{GDBN}, your program may stop for any of several reasons,
3994such as a signal, a breakpoint, or reaching a new line after a
3995@value{GDBN} command such as @code{step}. You may then examine and
3996change variables, set new breakpoints or remove old ones, and then
3997continue execution. Usually, the messages shown by @value{GDBN} provide
3998ample explanation of the status of your program---but you can also
3999explicitly request this information at any time.
c906108c
SS
4000
4001@table @code
4002@kindex info program
4003@item info program
4004Display information about the status of your program: whether it is
7a292a7a 4005running or not, what process it is, and why it stopped.
c906108c
SS
4006@end table
4007
4008@menu
4009* Breakpoints:: Breakpoints, watchpoints, and catchpoints
4010* Continuing and Stepping:: Resuming execution
aad1c02c
TT
4011* Skipping Over Functions and Files::
4012 Skipping over functions and files
c906108c 4013* Signals:: Signals
c906108c 4014* Thread Stops:: Stopping and starting multi-thread programs
c906108c
SS
4015@end menu
4016
6d2ebf8b 4017@node Breakpoints
79a6e687 4018@section Breakpoints, Watchpoints, and Catchpoints
c906108c
SS
4019
4020@cindex breakpoints
4021A @dfn{breakpoint} makes your program stop whenever a certain point in
4022the program is reached. For each breakpoint, you can add conditions to
4023control in finer detail whether your program stops. You can set
4024breakpoints with the @code{break} command and its variants (@pxref{Set
79a6e687 4025Breaks, ,Setting Breakpoints}), to specify the place where your program
c906108c
SS
4026should stop by line number, function name or exact address in the
4027program.
4028
09d4efe1 4029On some systems, you can set breakpoints in shared libraries before
b1236ac3 4030the executable is run.
c906108c
SS
4031
4032@cindex watchpoints
fd60e0df 4033@cindex data breakpoints
c906108c
SS
4034@cindex memory tracing
4035@cindex breakpoint on memory address
4036@cindex breakpoint on variable modification
4037A @dfn{watchpoint} is a special breakpoint that stops your program
fd60e0df 4038when the value of an expression changes. The expression may be a value
0ced0c34 4039of a variable, or it could involve values of one or more variables
fd60e0df
EZ
4040combined by operators, such as @samp{a + b}. This is sometimes called
4041@dfn{data breakpoints}. You must use a different command to set
79a6e687 4042watchpoints (@pxref{Set Watchpoints, ,Setting Watchpoints}), but aside
fd60e0df
EZ
4043from that, you can manage a watchpoint like any other breakpoint: you
4044enable, disable, and delete both breakpoints and watchpoints using the
4045same commands.
c906108c
SS
4046
4047You can arrange to have values from your program displayed automatically
4048whenever @value{GDBN} stops at a breakpoint. @xref{Auto Display,,
79a6e687 4049Automatic Display}.
c906108c
SS
4050
4051@cindex catchpoints
4052@cindex breakpoint on events
4053A @dfn{catchpoint} is another special breakpoint that stops your program
b37052ae 4054when a certain kind of event occurs, such as the throwing of a C@t{++}
c906108c
SS
4055exception or the loading of a library. As with watchpoints, you use a
4056different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
79a6e687 4057Catchpoints}), but aside from that, you can manage a catchpoint like any
c906108c 4058other breakpoint. (To stop when your program receives a signal, use the
d4f3574e 4059@code{handle} command; see @ref{Signals, ,Signals}.)
c906108c
SS
4060
4061@cindex breakpoint numbers
4062@cindex numbers for breakpoints
4063@value{GDBN} assigns a number to each breakpoint, watchpoint, or
4064catchpoint when you create it; these numbers are successive integers
4065starting with one. In many of the commands for controlling various
4066features of breakpoints you use the breakpoint number to say which
4067breakpoint you want to change. Each breakpoint may be @dfn{enabled} or
4068@dfn{disabled}; if disabled, it has no effect on your program until you
4069enable it again.
4070
c5394b80 4071@cindex breakpoint ranges
18da0c51 4072@cindex breakpoint lists
c5394b80 4073@cindex ranges of breakpoints
18da0c51
MG
4074@cindex lists of breakpoints
4075Some @value{GDBN} commands accept a space-separated list of breakpoints
4076on which to operate. A list element can be either a single breakpoint number,
4077like @samp{5}, or a range of such numbers, like @samp{5-7}.
4078When a breakpoint list is given to a command, all breakpoints in that list
4079are operated on.
c5394b80 4080
c906108c
SS
4081@menu
4082* Set Breaks:: Setting breakpoints
4083* Set Watchpoints:: Setting watchpoints
4084* Set Catchpoints:: Setting catchpoints
4085* Delete Breaks:: Deleting breakpoints
4086* Disabling:: Disabling breakpoints
4087* Conditions:: Break conditions
4088* Break Commands:: Breakpoint command lists
e7e0cddf 4089* Dynamic Printf:: Dynamic printf
6149aea9 4090* Save Breakpoints:: How to save breakpoints in a file
62e5f89c 4091* Static Probe Points:: Listing static probe points
d4f3574e 4092* Error in Breakpoints:: ``Cannot insert breakpoints''
79a6e687 4093* Breakpoint-related Warnings:: ``Breakpoint address adjusted...''
c906108c
SS
4094@end menu
4095
6d2ebf8b 4096@node Set Breaks
79a6e687 4097@subsection Setting Breakpoints
c906108c 4098
5d161b24 4099@c FIXME LMB what does GDB do if no code on line of breakpt?
c906108c
SS
4100@c consider in particular declaration with/without initialization.
4101@c
4102@c FIXME 2 is there stuff on this already? break at fun start, already init?
4103
4104@kindex break
41afff9a
EZ
4105@kindex b @r{(@code{break})}
4106@vindex $bpnum@r{, convenience variable}
c906108c
SS
4107@cindex latest breakpoint
4108Breakpoints are set with the @code{break} command (abbreviated
5d161b24 4109@code{b}). The debugger convenience variable @samp{$bpnum} records the
f3b28801 4110number of the breakpoint you've set most recently; see @ref{Convenience
79a6e687 4111Vars,, Convenience Variables}, for a discussion of what you can do with
c906108c
SS
4112convenience variables.
4113
c906108c 4114@table @code
2a25a5ba
EZ
4115@item break @var{location}
4116Set a breakpoint at the given @var{location}, which can specify a
4117function name, a line number, or an address of an instruction.
4118(@xref{Specify Location}, for a list of all the possible ways to
4119specify a @var{location}.) The breakpoint will stop your program just
4120before it executes any of the code in the specified @var{location}.
4121
c906108c 4122When using source languages that permit overloading of symbols, such as
2a25a5ba 4123C@t{++}, a function name may refer to more than one possible place to break.
6ba66d6a
JB
4124@xref{Ambiguous Expressions,,Ambiguous Expressions}, for a discussion of
4125that situation.
c906108c 4126
45ac276d 4127It is also possible to insert a breakpoint that will stop the program
2c88c651
JB
4128only if a specific thread (@pxref{Thread-Specific Breakpoints})
4129or a specific task (@pxref{Ada Tasks}) hits that breakpoint.
45ac276d 4130
c906108c
SS
4131@item break
4132When called without any arguments, @code{break} sets a breakpoint at
4133the next instruction to be executed in the selected stack frame
4134(@pxref{Stack, ,Examining the Stack}). In any selected frame but the
4135innermost, this makes your program stop as soon as control
4136returns to that frame. This is similar to the effect of a
4137@code{finish} command in the frame inside the selected frame---except
4138that @code{finish} does not leave an active breakpoint. If you use
4139@code{break} without an argument in the innermost frame, @value{GDBN} stops
4140the next time it reaches the current location; this may be useful
4141inside loops.
4142
4143@value{GDBN} normally ignores breakpoints when it resumes execution, until at
4144least one instruction has been executed. If it did not do this, you
4145would be unable to proceed past a breakpoint without first disabling the
4146breakpoint. This rule applies whether or not the breakpoint already
4147existed when your program stopped.
4148
4149@item break @dots{} if @var{cond}
4150Set a breakpoint with condition @var{cond}; evaluate the expression
4151@var{cond} each time the breakpoint is reached, and stop only if the
4152value is nonzero---that is, if @var{cond} evaluates as true.
4153@samp{@dots{}} stands for one of the possible arguments described
4154above (or no argument) specifying where to break. @xref{Conditions,
79a6e687 4155,Break Conditions}, for more information on breakpoint conditions.
c906108c
SS
4156
4157@kindex tbreak
4158@item tbreak @var{args}
697aa1b7 4159Set a breakpoint enabled only for one stop. The @var{args} are the
c906108c
SS
4160same as for the @code{break} command, and the breakpoint is set in the same
4161way, but the breakpoint is automatically deleted after the first time your
79a6e687 4162program stops there. @xref{Disabling, ,Disabling Breakpoints}.
c906108c 4163
c906108c 4164@kindex hbreak
ba04e063 4165@cindex hardware breakpoints
c906108c 4166@item hbreak @var{args}
697aa1b7 4167Set a hardware-assisted breakpoint. The @var{args} are the same as for the
d4f3574e 4168@code{break} command and the breakpoint is set in the same way, but the
c906108c
SS
4169breakpoint requires hardware support and some target hardware may not
4170have this support. The main purpose of this is EPROM/ROM code
d4f3574e
SS
4171debugging, so you can set a breakpoint at an instruction without
4172changing the instruction. This can be used with the new trap-generation
09d4efe1 4173provided by SPARClite DSU and most x86-based targets. These targets
d4f3574e
SS
4174will generate traps when a program accesses some data or instruction
4175address that is assigned to the debug registers. However the hardware
4176breakpoint registers can take a limited number of breakpoints. For
4177example, on the DSU, only two data breakpoints can be set at a time, and
4178@value{GDBN} will reject this command if more than two are used. Delete
4179or disable unused hardware breakpoints before setting new ones
79a6e687
BW
4180(@pxref{Disabling, ,Disabling Breakpoints}).
4181@xref{Conditions, ,Break Conditions}.
9c16f35a
EZ
4182For remote targets, you can restrict the number of hardware
4183breakpoints @value{GDBN} will use, see @ref{set remote
4184hardware-breakpoint-limit}.
501eef12 4185
c906108c
SS
4186@kindex thbreak
4187@item thbreak @var{args}
697aa1b7 4188Set a hardware-assisted breakpoint enabled only for one stop. The @var{args}
c906108c 4189are the same as for the @code{hbreak} command and the breakpoint is set in
5d161b24 4190the same way. However, like the @code{tbreak} command,
c906108c
SS
4191the breakpoint is automatically deleted after the
4192first time your program stops there. Also, like the @code{hbreak}
5d161b24 4193command, the breakpoint requires hardware support and some target hardware
79a6e687
BW
4194may not have this support. @xref{Disabling, ,Disabling Breakpoints}.
4195See also @ref{Conditions, ,Break Conditions}.
c906108c
SS
4196
4197@kindex rbreak
4198@cindex regular expression
8bd10a10 4199@cindex breakpoints at functions matching a regexp
c45da7e6 4200@cindex set breakpoints in many functions
c906108c 4201@item rbreak @var{regex}
c906108c 4202Set breakpoints on all functions matching the regular expression
11cf8741
JM
4203@var{regex}. This command sets an unconditional breakpoint on all
4204matches, printing a list of all breakpoints it set. Once these
4205breakpoints are set, they are treated just like the breakpoints set with
4206the @code{break} command. You can delete them, disable them, or make
4207them conditional the same way as any other breakpoint.
4208
20813a0b
PW
4209In programs using different languages, @value{GDBN} chooses the syntax
4210to print the list of all breakpoints it sets according to the
4211@samp{set language} value: using @samp{set language auto}
4212(see @ref{Automatically, ,Set Language Automatically}) means to use the
4213language of the breakpoint's function, other values mean to use
4214the manually specified language (see @ref{Manually, ,Set Language Manually}).
4215
11cf8741
JM
4216The syntax of the regular expression is the standard one used with tools
4217like @file{grep}. Note that this is different from the syntax used by
4218shells, so for instance @code{foo*} matches all functions that include
4219an @code{fo} followed by zero or more @code{o}s. There is an implicit
4220@code{.*} leading and trailing the regular expression you supply, so to
4221match only functions that begin with @code{foo}, use @code{^foo}.
c906108c 4222
f7dc1244 4223@cindex non-member C@t{++} functions, set breakpoint in
b37052ae 4224When debugging C@t{++} programs, @code{rbreak} is useful for setting
c906108c
SS
4225breakpoints on overloaded functions that are not members of any special
4226classes.
c906108c 4227
f7dc1244
EZ
4228@cindex set breakpoints on all functions
4229The @code{rbreak} command can be used to set breakpoints in
4230@strong{all} the functions in a program, like this:
4231
4232@smallexample
4233(@value{GDBP}) rbreak .
4234@end smallexample
4235
8bd10a10
CM
4236@item rbreak @var{file}:@var{regex}
4237If @code{rbreak} is called with a filename qualification, it limits
4238the search for functions matching the given regular expression to the
4239specified @var{file}. This can be used, for example, to set breakpoints on
4240every function in a given file:
4241
4242@smallexample
4243(@value{GDBP}) rbreak file.c:.
4244@end smallexample
4245
4246The colon separating the filename qualifier from the regex may
4247optionally be surrounded by spaces.
4248
c906108c
SS
4249@kindex info breakpoints
4250@cindex @code{$_} and @code{info breakpoints}
18da0c51
MG
4251@item info breakpoints @r{[}@var{list}@dots{}@r{]}
4252@itemx info break @r{[}@var{list}@dots{}@r{]}
c906108c 4253Print a table of all breakpoints, watchpoints, and catchpoints set and
45ac1734 4254not deleted. Optional argument @var{n} means print information only
e5a67952
MS
4255about the specified breakpoint(s) (or watchpoint(s) or catchpoint(s)).
4256For each breakpoint, following columns are printed:
c906108c
SS
4257
4258@table @emph
4259@item Breakpoint Numbers
4260@item Type
4261Breakpoint, watchpoint, or catchpoint.
4262@item Disposition
4263Whether the breakpoint is marked to be disabled or deleted when hit.
4264@item Enabled or Disabled
4265Enabled breakpoints are marked with @samp{y}. @samp{n} marks breakpoints
b3db7447 4266that are not enabled.
c906108c 4267@item Address
fe6fbf8b 4268Where the breakpoint is in your program, as a memory address. For a
b3db7447
NR
4269pending breakpoint whose address is not yet known, this field will
4270contain @samp{<PENDING>}. Such breakpoint won't fire until a shared
4271library that has the symbol or line referred by breakpoint is loaded.
4272See below for details. A breakpoint with several locations will
3b784c4f 4273have @samp{<MULTIPLE>} in this field---see below for details.
c906108c
SS
4274@item What
4275Where the breakpoint is in the source for your program, as a file and
2650777c
JJ
4276line number. For a pending breakpoint, the original string passed to
4277the breakpoint command will be listed as it cannot be resolved until
4278the appropriate shared library is loaded in the future.
c906108c
SS
4279@end table
4280
4281@noindent
83364271
LM
4282If a breakpoint is conditional, there are two evaluation modes: ``host'' and
4283``target''. If mode is ``host'', breakpoint condition evaluation is done by
4284@value{GDBN} on the host's side. If it is ``target'', then the condition
4285is evaluated by the target. The @code{info break} command shows
4286the condition on the line following the affected breakpoint, together with
4287its condition evaluation mode in between parentheses.
4288
4289Breakpoint commands, if any, are listed after that. A pending breakpoint is
4290allowed to have a condition specified for it. The condition is not parsed for
4291validity until a shared library is loaded that allows the pending
4292breakpoint to resolve to a valid location.
c906108c
SS
4293
4294@noindent
4295@code{info break} with a breakpoint
4296number @var{n} as argument lists only that breakpoint. The
4297convenience variable @code{$_} and the default examining-address for
4298the @code{x} command are set to the address of the last breakpoint
79a6e687 4299listed (@pxref{Memory, ,Examining Memory}).
c906108c
SS
4300
4301@noindent
4302@code{info break} displays a count of the number of times the breakpoint
4303has been hit. This is especially useful in conjunction with the
4304@code{ignore} command. You can ignore a large number of breakpoint
4305hits, look at the breakpoint info to see how many times the breakpoint
4306was hit, and then run again, ignoring one less than that number. This
4307will get you quickly to the last hit of that breakpoint.
816338b5
SS
4308
4309@noindent
4310For a breakpoints with an enable count (xref) greater than 1,
4311@code{info break} also displays that count.
4312
c906108c
SS
4313@end table
4314
4315@value{GDBN} allows you to set any number of breakpoints at the same place in
4316your program. There is nothing silly or meaningless about this. When
4317the breakpoints are conditional, this is even useful
79a6e687 4318(@pxref{Conditions, ,Break Conditions}).
c906108c 4319
2e9132cc
EZ
4320@cindex multiple locations, breakpoints
4321@cindex breakpoints, multiple locations
fcda367b 4322It is possible that a breakpoint corresponds to several locations
fe6fbf8b
VP
4323in your program. Examples of this situation are:
4324
4325@itemize @bullet
f8eba3c6
TT
4326@item
4327Multiple functions in the program may have the same name.
4328
fe6fbf8b
VP
4329@item
4330For a C@t{++} constructor, the @value{NGCC} compiler generates several
4331instances of the function body, used in different cases.
4332
4333@item
4334For a C@t{++} template function, a given line in the function can
4335correspond to any number of instantiations.
4336
4337@item
4338For an inlined function, a given source line can correspond to
4339several places where that function is inlined.
fe6fbf8b
VP
4340@end itemize
4341
4342In all those cases, @value{GDBN} will insert a breakpoint at all
f8eba3c6 4343the relevant locations.
fe6fbf8b 4344
3b784c4f
EZ
4345A breakpoint with multiple locations is displayed in the breakpoint
4346table using several rows---one header row, followed by one row for
4347each breakpoint location. The header row has @samp{<MULTIPLE>} in the
4348address column. The rows for individual locations contain the actual
4349addresses for locations, and show the functions to which those
4350locations belong. The number column for a location is of the form
fe6fbf8b
VP
4351@var{breakpoint-number}.@var{location-number}.
4352
4353For example:
3b784c4f 4354
fe6fbf8b
VP
4355@smallexample
4356Num Type Disp Enb Address What
43571 breakpoint keep y <MULTIPLE>
4358 stop only if i==1
4359 breakpoint already hit 1 time
43601.1 y 0x080486a2 in void foo<int>() at t.cc:8
43611.2 y 0x080486ca in void foo<double>() at t.cc:8
4362@end smallexample
4363
d0fe4701
XR
4364You cannot delete the individual locations from a breakpoint. However,
4365each location can be individually enabled or disabled by passing
fe6fbf8b 4366@var{breakpoint-number}.@var{location-number} as argument to the
d0fe4701
XR
4367@code{enable} and @code{disable} commands. It's also possible to
4368@code{enable} and @code{disable} a range of @var{location-number}
4369locations using a @var{breakpoint-number} and two @var{location-number}s,
4370in increasing order, separated by a hyphen, like
4371@kbd{@var{breakpoint-number}.@var{location-number1}-@var{location-number2}},
4372in which case @value{GDBN} acts on all the locations in the range (inclusive).
4373Disabling or enabling the parent breakpoint (@pxref{Disabling}) affects
4374all of the locations that belong to that breakpoint.
fe6fbf8b 4375
2650777c 4376@cindex pending breakpoints
fe6fbf8b 4377It's quite common to have a breakpoint inside a shared library.
3b784c4f 4378Shared libraries can be loaded and unloaded explicitly,
fe6fbf8b
VP
4379and possibly repeatedly, as the program is executed. To support
4380this use case, @value{GDBN} updates breakpoint locations whenever
4381any shared library is loaded or unloaded. Typically, you would
fcda367b 4382set a breakpoint in a shared library at the beginning of your
fe6fbf8b
VP
4383debugging session, when the library is not loaded, and when the
4384symbols from the library are not available. When you try to set
4385breakpoint, @value{GDBN} will ask you if you want to set
3b784c4f 4386a so called @dfn{pending breakpoint}---breakpoint whose address
fe6fbf8b
VP
4387is not yet resolved.
4388
4389After the program is run, whenever a new shared library is loaded,
4390@value{GDBN} reevaluates all the breakpoints. When a newly loaded
4391shared library contains the symbol or line referred to by some
4392pending breakpoint, that breakpoint is resolved and becomes an
4393ordinary breakpoint. When a library is unloaded, all breakpoints
4394that refer to its symbols or source lines become pending again.
4395
4396This logic works for breakpoints with multiple locations, too. For
4397example, if you have a breakpoint in a C@t{++} template function, and
4398a newly loaded shared library has an instantiation of that template,
4399a new location is added to the list of locations for the breakpoint.
4400
4401Except for having unresolved address, pending breakpoints do not
4402differ from regular breakpoints. You can set conditions or commands,
4403enable and disable them and perform other breakpoint operations.
4404
4405@value{GDBN} provides some additional commands for controlling what
4406happens when the @samp{break} command cannot resolve breakpoint
4407address specification to an address:
dd79a6cf
JJ
4408
4409@kindex set breakpoint pending
4410@kindex show breakpoint pending
4411@table @code
4412@item set breakpoint pending auto
4413This is the default behavior. When @value{GDBN} cannot find the breakpoint
4414location, it queries you whether a pending breakpoint should be created.
4415
4416@item set breakpoint pending on
4417This indicates that an unrecognized breakpoint location should automatically
4418result in a pending breakpoint being created.
4419
4420@item set breakpoint pending off
4421This indicates that pending breakpoints are not to be created. Any
4422unrecognized breakpoint location results in an error. This setting does
4423not affect any pending breakpoints previously created.
4424
4425@item show breakpoint pending
4426Show the current behavior setting for creating pending breakpoints.
4427@end table
2650777c 4428
fe6fbf8b
VP
4429The settings above only affect the @code{break} command and its
4430variants. Once breakpoint is set, it will be automatically updated
4431as shared libraries are loaded and unloaded.
2650777c 4432
765dc015
VP
4433@cindex automatic hardware breakpoints
4434For some targets, @value{GDBN} can automatically decide if hardware or
4435software breakpoints should be used, depending on whether the
4436breakpoint address is read-only or read-write. This applies to
4437breakpoints set with the @code{break} command as well as to internal
4438breakpoints set by commands like @code{next} and @code{finish}. For
fcda367b 4439breakpoints set with @code{hbreak}, @value{GDBN} will always use hardware
765dc015
VP
4440breakpoints.
4441
18da0c51 4442You can control this automatic behaviour with the following commands:
765dc015
VP
4443
4444@kindex set breakpoint auto-hw
4445@kindex show breakpoint auto-hw
4446@table @code
4447@item set breakpoint auto-hw on
4448This is the default behavior. When @value{GDBN} sets a breakpoint, it
4449will try to use the target memory map to decide if software or hardware
4450breakpoint must be used.
4451
4452@item set breakpoint auto-hw off
4453This indicates @value{GDBN} should not automatically select breakpoint
4454type. If the target provides a memory map, @value{GDBN} will warn when
4455trying to set software breakpoint at a read-only address.
4456@end table
4457
74960c60
VP
4458@value{GDBN} normally implements breakpoints by replacing the program code
4459at the breakpoint address with a special instruction, which, when
4460executed, given control to the debugger. By default, the program
4461code is so modified only when the program is resumed. As soon as
4462the program stops, @value{GDBN} restores the original instructions. This
4463behaviour guards against leaving breakpoints inserted in the
4464target should gdb abrubptly disconnect. However, with slow remote
4465targets, inserting and removing breakpoint can reduce the performance.
4466This behavior can be controlled with the following commands::
4467
4468@kindex set breakpoint always-inserted
4469@kindex show breakpoint always-inserted
4470@table @code
4471@item set breakpoint always-inserted off
33e5cbd6
PA
4472All breakpoints, including newly added by the user, are inserted in
4473the target only when the target is resumed. All breakpoints are
a25a5a45 4474removed from the target when it stops. This is the default mode.
74960c60
VP
4475
4476@item set breakpoint always-inserted on
4477Causes all breakpoints to be inserted in the target at all times. If
4478the user adds a new breakpoint, or changes an existing breakpoint, the
4479breakpoints in the target are updated immediately. A breakpoint is
a25a5a45 4480removed from the target only when breakpoint itself is deleted.
342cc091 4481@end table
765dc015 4482
83364271
LM
4483@value{GDBN} handles conditional breakpoints by evaluating these conditions
4484when a breakpoint breaks. If the condition is true, then the process being
4485debugged stops, otherwise the process is resumed.
4486
4487If the target supports evaluating conditions on its end, @value{GDBN} may
4488download the breakpoint, together with its conditions, to it.
4489
4490This feature can be controlled via the following commands:
4491
4492@kindex set breakpoint condition-evaluation
4493@kindex show breakpoint condition-evaluation
4494@table @code
4495@item set breakpoint condition-evaluation host
4496This option commands @value{GDBN} to evaluate the breakpoint
4497conditions on the host's side. Unconditional breakpoints are sent to
4498the target which in turn receives the triggers and reports them back to GDB
4499for condition evaluation. This is the standard evaluation mode.
4500
4501@item set breakpoint condition-evaluation target
4502This option commands @value{GDBN} to download breakpoint conditions
4503to the target at the moment of their insertion. The target
4504is responsible for evaluating the conditional expression and reporting
4505breakpoint stop events back to @value{GDBN} whenever the condition
4506is true. Due to limitations of target-side evaluation, some conditions
4507cannot be evaluated there, e.g., conditions that depend on local data
4508that is only known to the host. Examples include
4509conditional expressions involving convenience variables, complex types
4510that cannot be handled by the agent expression parser and expressions
4511that are too long to be sent over to the target, specially when the
4512target is a remote system. In these cases, the conditions will be
4513evaluated by @value{GDBN}.
4514
4515@item set breakpoint condition-evaluation auto
4516This is the default mode. If the target supports evaluating breakpoint
4517conditions on its end, @value{GDBN} will download breakpoint conditions to
4518the target (limitations mentioned previously apply). If the target does
4519not support breakpoint condition evaluation, then @value{GDBN} will fallback
4520to evaluating all these conditions on the host's side.
4521@end table
4522
4523
c906108c
SS
4524@cindex negative breakpoint numbers
4525@cindex internal @value{GDBN} breakpoints
eb12ee30
AC
4526@value{GDBN} itself sometimes sets breakpoints in your program for
4527special purposes, such as proper handling of @code{longjmp} (in C
4528programs). These internal breakpoints are assigned negative numbers,
4529starting with @code{-1}; @samp{info breakpoints} does not display them.
c906108c 4530You can see these breakpoints with the @value{GDBN} maintenance command
eb12ee30 4531@samp{maint info breakpoints} (@pxref{maint info breakpoints}).
c906108c
SS
4532
4533
6d2ebf8b 4534@node Set Watchpoints
79a6e687 4535@subsection Setting Watchpoints
c906108c
SS
4536
4537@cindex setting watchpoints
c906108c
SS
4538You can use a watchpoint to stop execution whenever the value of an
4539expression changes, without having to predict a particular place where
fd60e0df
EZ
4540this may happen. (This is sometimes called a @dfn{data breakpoint}.)
4541The expression may be as simple as the value of a single variable, or
4542as complex as many variables combined by operators. Examples include:
4543
4544@itemize @bullet
4545@item
4546A reference to the value of a single variable.
4547
4548@item
4549An address cast to an appropriate data type. For example,
4550@samp{*(int *)0x12345678} will watch a 4-byte region at the specified
4551address (assuming an @code{int} occupies 4 bytes).
4552
4553@item
4554An arbitrarily complex expression, such as @samp{a*b + c/d}. The
4555expression can use any operators valid in the program's native
4556language (@pxref{Languages}).
4557@end itemize
c906108c 4558
fa4727a6
DJ
4559You can set a watchpoint on an expression even if the expression can
4560not be evaluated yet. For instance, you can set a watchpoint on
4561@samp{*global_ptr} before @samp{global_ptr} is initialized.
4562@value{GDBN} will stop when your program sets @samp{global_ptr} and
4563the expression produces a valid value. If the expression becomes
4564valid in some other way than changing a variable (e.g.@: if the memory
4565pointed to by @samp{*global_ptr} becomes readable as the result of a
4566@code{malloc} call), @value{GDBN} may not stop until the next time
4567the expression changes.
4568
82f2d802
EZ
4569@cindex software watchpoints
4570@cindex hardware watchpoints
c906108c 4571Depending on your system, watchpoints may be implemented in software or
2df3850c 4572hardware. @value{GDBN} does software watchpointing by single-stepping your
c906108c
SS
4573program and testing the variable's value each time, which is hundreds of
4574times slower than normal execution. (But this may still be worth it, to
4575catch errors where you have no clue what part of your program is the
4576culprit.)
4577
b1236ac3
PA
4578On some systems, such as most PowerPC or x86-based targets,
4579@value{GDBN} includes support for hardware watchpoints, which do not
4580slow down the running of your program.
c906108c
SS
4581
4582@table @code
4583@kindex watch
5d5658a1 4584@item watch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
fd60e0df
EZ
4585Set a watchpoint for an expression. @value{GDBN} will break when the
4586expression @var{expr} is written into by the program and its value
4587changes. The simplest (and the most popular) use of this command is
4588to watch the value of a single variable:
4589
4590@smallexample
4591(@value{GDBP}) watch foo
4592@end smallexample
c906108c 4593
5d5658a1 4594If the command includes a @code{@r{[}thread @var{thread-id}@r{]}}
9c06b0b4 4595argument, @value{GDBN} breaks only when the thread identified by
5d5658a1 4596@var{thread-id} changes the value of @var{expr}. If any other threads
d8b2a693
JB
4597change the value of @var{expr}, @value{GDBN} will not break. Note
4598that watchpoints restricted to a single thread in this way only work
4599with Hardware Watchpoints.
4600
06a64a0b
TT
4601Ordinarily a watchpoint respects the scope of variables in @var{expr}
4602(see below). The @code{-location} argument tells @value{GDBN} to
4603instead watch the memory referred to by @var{expr}. In this case,
4604@value{GDBN} will evaluate @var{expr}, take the address of the result,
4605and watch the memory at that address. The type of the result is used
4606to determine the size of the watched memory. If the expression's
4607result does not have an address, then @value{GDBN} will print an
4608error.
4609
9c06b0b4
TJB
4610The @code{@r{[}mask @var{maskvalue}@r{]}} argument allows creation
4611of masked watchpoints, if the current architecture supports this
4612feature (e.g., PowerPC Embedded architecture, see @ref{PowerPC
4613Embedded}.) A @dfn{masked watchpoint} specifies a mask in addition
4614to an address to watch. The mask specifies that some bits of an address
4615(the bits which are reset in the mask) should be ignored when matching
4616the address accessed by the inferior against the watchpoint address.
4617Thus, a masked watchpoint watches many addresses simultaneously---those
4618addresses whose unmasked bits are identical to the unmasked bits in the
4619watchpoint address. The @code{mask} argument implies @code{-location}.
4620Examples:
4621
4622@smallexample
4623(@value{GDBP}) watch foo mask 0xffff00ff
4624(@value{GDBP}) watch *0xdeadbeef mask 0xffffff00
4625@end smallexample
4626
c906108c 4627@kindex rwatch
5d5658a1 4628@item rwatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
09d4efe1
EZ
4629Set a watchpoint that will break when the value of @var{expr} is read
4630by the program.
c906108c
SS
4631
4632@kindex awatch
5d5658a1 4633@item awatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
09d4efe1
EZ
4634Set a watchpoint that will break when @var{expr} is either read from
4635or written into by the program.
c906108c 4636
18da0c51
MG
4637@kindex info watchpoints @r{[}@var{list}@dots{}@r{]}
4638@item info watchpoints @r{[}@var{list}@dots{}@r{]}
d77f58be
SS
4639This command prints a list of watchpoints, using the same format as
4640@code{info break} (@pxref{Set Breaks}).
c906108c
SS
4641@end table
4642
65d79d4b
SDJ
4643If you watch for a change in a numerically entered address you need to
4644dereference it, as the address itself is just a constant number which will
4645never change. @value{GDBN} refuses to create a watchpoint that watches
4646a never-changing value:
4647
4648@smallexample
4649(@value{GDBP}) watch 0x600850
4650Cannot watch constant value 0x600850.
4651(@value{GDBP}) watch *(int *) 0x600850
4652Watchpoint 1: *(int *) 6293584
4653@end smallexample
4654
c906108c
SS
4655@value{GDBN} sets a @dfn{hardware watchpoint} if possible. Hardware
4656watchpoints execute very quickly, and the debugger reports a change in
4657value at the exact instruction where the change occurs. If @value{GDBN}
4658cannot set a hardware watchpoint, it sets a software watchpoint, which
4659executes more slowly and reports the change in value at the next
82f2d802
EZ
4660@emph{statement}, not the instruction, after the change occurs.
4661
82f2d802
EZ
4662@cindex use only software watchpoints
4663You can force @value{GDBN} to use only software watchpoints with the
4664@kbd{set can-use-hw-watchpoints 0} command. With this variable set to
4665zero, @value{GDBN} will never try to use hardware watchpoints, even if
4666the underlying system supports them. (Note that hardware-assisted
4667watchpoints that were set @emph{before} setting
4668@code{can-use-hw-watchpoints} to zero will still use the hardware
d3e8051b 4669mechanism of watching expression values.)
c906108c 4670
9c16f35a
EZ
4671@table @code
4672@item set can-use-hw-watchpoints
4673@kindex set can-use-hw-watchpoints
4674Set whether or not to use hardware watchpoints.
4675
4676@item show can-use-hw-watchpoints
4677@kindex show can-use-hw-watchpoints
4678Show the current mode of using hardware watchpoints.
4679@end table
4680
4681For remote targets, you can restrict the number of hardware
4682watchpoints @value{GDBN} will use, see @ref{set remote
4683hardware-breakpoint-limit}.
4684
c906108c
SS
4685When you issue the @code{watch} command, @value{GDBN} reports
4686
474c8240 4687@smallexample
c906108c 4688Hardware watchpoint @var{num}: @var{expr}
474c8240 4689@end smallexample
c906108c
SS
4690
4691@noindent
4692if it was able to set a hardware watchpoint.
4693
7be570e7
JM
4694Currently, the @code{awatch} and @code{rwatch} commands can only set
4695hardware watchpoints, because accesses to data that don't change the
4696value of the watched expression cannot be detected without examining
4697every instruction as it is being executed, and @value{GDBN} does not do
4698that currently. If @value{GDBN} finds that it is unable to set a
4699hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
4700will print a message like this:
4701
4702@smallexample
4703Expression cannot be implemented with read/access watchpoint.
4704@end smallexample
4705
4706Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
4707data type of the watched expression is wider than what a hardware
4708watchpoint on the target machine can handle. For example, some systems
4709can only watch regions that are up to 4 bytes wide; on such systems you
4710cannot set hardware watchpoints for an expression that yields a
4711double-precision floating-point number (which is typically 8 bytes
4712wide). As a work-around, it might be possible to break the large region
4713into a series of smaller ones and watch them with separate watchpoints.
4714
4715If you set too many hardware watchpoints, @value{GDBN} might be unable
4716to insert all of them when you resume the execution of your program.
4717Since the precise number of active watchpoints is unknown until such
4718time as the program is about to be resumed, @value{GDBN} might not be
4719able to warn you about this when you set the watchpoints, and the
4720warning will be printed only when the program is resumed:
4721
4722@smallexample
4723Hardware watchpoint @var{num}: Could not insert watchpoint
4724@end smallexample
4725
4726@noindent
4727If this happens, delete or disable some of the watchpoints.
4728
fd60e0df
EZ
4729Watching complex expressions that reference many variables can also
4730exhaust the resources available for hardware-assisted watchpoints.
4731That's because @value{GDBN} needs to watch every variable in the
4732expression with separately allocated resources.
4733
c906108c 4734If you call a function interactively using @code{print} or @code{call},
2df3850c 4735any watchpoints you have set will be inactive until @value{GDBN} reaches another
c906108c
SS
4736kind of breakpoint or the call completes.
4737
7be570e7
JM
4738@value{GDBN} automatically deletes watchpoints that watch local
4739(automatic) variables, or expressions that involve such variables, when
4740they go out of scope, that is, when the execution leaves the block in
4741which these variables were defined. In particular, when the program
4742being debugged terminates, @emph{all} local variables go out of scope,
4743and so only watchpoints that watch global variables remain set. If you
4744rerun the program, you will need to set all such watchpoints again. One
4745way of doing that would be to set a code breakpoint at the entry to the
4746@code{main} function and when it breaks, set all the watchpoints.
4747
c906108c
SS
4748@cindex watchpoints and threads
4749@cindex threads and watchpoints
d983da9c
DJ
4750In multi-threaded programs, watchpoints will detect changes to the
4751watched expression from every thread.
4752
4753@quotation
4754@emph{Warning:} In multi-threaded programs, software watchpoints
53a5351d
JM
4755have only limited usefulness. If @value{GDBN} creates a software
4756watchpoint, it can only watch the value of an expression @emph{in a
4757single thread}. If you are confident that the expression can only
4758change due to the current thread's activity (and if you are also
4759confident that no other thread can become current), then you can use
4760software watchpoints as usual. However, @value{GDBN} may not notice
4761when a non-current thread's activity changes the expression. (Hardware
4762watchpoints, in contrast, watch an expression in all threads.)
c906108c 4763@end quotation
c906108c 4764
501eef12
AC
4765@xref{set remote hardware-watchpoint-limit}.
4766
6d2ebf8b 4767@node Set Catchpoints
79a6e687 4768@subsection Setting Catchpoints
d4f3574e 4769@cindex catchpoints, setting
c906108c
SS
4770@cindex exception handlers
4771@cindex event handling
4772
4773You can use @dfn{catchpoints} to cause the debugger to stop for certain
b37052ae 4774kinds of program events, such as C@t{++} exceptions or the loading of a
c906108c
SS
4775shared library. Use the @code{catch} command to set a catchpoint.
4776
4777@table @code
4778@kindex catch
4779@item catch @var{event}
697aa1b7 4780Stop when @var{event} occurs. The @var{event} can be any of the following:
591f19e8 4781
c906108c 4782@table @code
cc16e6c9
TT
4783@item throw @r{[}@var{regexp}@r{]}
4784@itemx rethrow @r{[}@var{regexp}@r{]}
4785@itemx catch @r{[}@var{regexp}@r{]}
1a4f73eb
TT
4786@kindex catch throw
4787@kindex catch rethrow
4788@kindex catch catch
4644b6e3 4789@cindex stop on C@t{++} exceptions
591f19e8
TT
4790The throwing, re-throwing, or catching of a C@t{++} exception.
4791
cc16e6c9
TT
4792If @var{regexp} is given, then only exceptions whose type matches the
4793regular expression will be caught.
4794
72f1fe8a
TT
4795@vindex $_exception@r{, convenience variable}
4796The convenience variable @code{$_exception} is available at an
4797exception-related catchpoint, on some systems. This holds the
4798exception being thrown.
4799
591f19e8
TT
4800There are currently some limitations to C@t{++} exception handling in
4801@value{GDBN}:
c906108c 4802
591f19e8
TT
4803@itemize @bullet
4804@item
4805The support for these commands is system-dependent. Currently, only
4806systems using the @samp{gnu-v3} C@t{++} ABI (@pxref{ABI}) are
4807supported.
4808
72f1fe8a 4809@item
cc16e6c9
TT
4810The regular expression feature and the @code{$_exception} convenience
4811variable rely on the presence of some SDT probes in @code{libstdc++}.
4812If these probes are not present, then these features cannot be used.
dee368d3
TT
4813These probes were first available in the GCC 4.8 release, but whether
4814or not they are available in your GCC also depends on how it was
4815built.
72f1fe8a
TT
4816
4817@item
4818The @code{$_exception} convenience variable is only valid at the
4819instruction at which an exception-related catchpoint is set.
4820
591f19e8
TT
4821@item
4822When an exception-related catchpoint is hit, @value{GDBN} stops at a
4823location in the system library which implements runtime exception
4824support for C@t{++}, usually @code{libstdc++}. You can use @code{up}
4825(@pxref{Selection}) to get to your code.
4826
4827@item
4828If you call a function interactively, @value{GDBN} normally returns
4829control to you when the function has finished executing. If the call
4830raises an exception, however, the call may bypass the mechanism that
4831returns control to you and cause your program either to abort or to
4832simply continue running until it hits a breakpoint, catches a signal
4833that @value{GDBN} is listening for, or exits. This is the case even if
4834you set a catchpoint for the exception; catchpoints on exceptions are
4835disabled within interactive calls. @xref{Calling}, for information on
4836controlling this with @code{set unwind-on-terminating-exception}.
4837
4838@item
4839You cannot raise an exception interactively.
4840
4841@item
4842You cannot install an exception handler interactively.
4843@end itemize
c906108c 4844
b8e07335 4845@item exception @r{[}@var{name}@r{]}
1a4f73eb 4846@kindex catch exception
8936fcda
JB
4847@cindex Ada exception catching
4848@cindex catch Ada exceptions
4849An Ada exception being raised. If an exception name is specified
4850at the end of the command (eg @code{catch exception Program_Error}),
4851the debugger will stop only when this specific exception is raised.
4852Otherwise, the debugger stops execution when any Ada exception is raised.
4853
87f67dba
JB
4854When inserting an exception catchpoint on a user-defined exception whose
4855name is identical to one of the exceptions defined by the language, the
4856fully qualified name must be used as the exception name. Otherwise,
4857@value{GDBN} will assume that it should stop on the pre-defined exception
4858rather than the user-defined one. For instance, assuming an exception
4859called @code{Constraint_Error} is defined in package @code{Pck}, then
4860the command to use to catch such exceptions is @kbd{catch exception
4861Pck.Constraint_Error}.
4862
37f6a7f4
TT
4863@vindex $_ada_exception@r{, convenience variable}
4864The convenience variable @code{$_ada_exception} holds the address of
4865the exception being thrown. This can be useful when setting a
4866condition for such a catchpoint.
4867
b8e07335
TT
4868@item exception unhandled
4869@kindex catch exception unhandled
37f6a7f4
TT
4870An exception that was raised but is not handled by the program. The
4871convenience variable @code{$_ada_exception} is set as for @code{catch
4872exception}.
b8e07335
TT
4873
4874@item handlers @r{[}@var{name}@r{]}
9f757bf7
XR
4875@kindex catch handlers
4876@cindex Ada exception handlers catching
4877@cindex catch Ada exceptions when handled
4878An Ada exception being handled. If an exception name is
4879specified at the end of the command
4880 (eg @kbd{catch handlers Program_Error}), the debugger will stop
4881only when this specific exception is handled.
4882Otherwise, the debugger stops execution when any Ada exception is handled.
4883
4884When inserting a handlers catchpoint on a user-defined
4885exception whose name is identical to one of the exceptions
4886defined by the language, the fully qualified name must be used
4887as the exception name. Otherwise, @value{GDBN} will assume that it
4888should stop on the pre-defined exception rather than the
4889user-defined one. For instance, assuming an exception called
4890 @code{Constraint_Error} is defined in package @code{Pck}, then the
4891command to use to catch such exceptions handling is
4892@kbd{catch handlers Pck.Constraint_Error}.
4893
37f6a7f4
TT
4894The convenience variable @code{$_ada_exception} is set as for
4895@code{catch exception}.
4896
8936fcda 4897@item assert
1a4f73eb 4898@kindex catch assert
37f6a7f4
TT
4899A failed Ada assertion. Note that the convenience variable
4900@code{$_ada_exception} is @emph{not} set by this catchpoint.
8936fcda 4901
c906108c 4902@item exec
1a4f73eb 4903@kindex catch exec
4644b6e3 4904@cindex break on fork/exec
b1236ac3 4905A call to @code{exec}.
c906108c 4906
e9076973 4907@anchor{catch syscall}
a96d9b2e 4908@item syscall
e3487908 4909@itemx syscall @r{[}@var{name} @r{|} @var{number} @r{|} @r{group:}@var{groupname} @r{|} @r{g:}@var{groupname}@r{]} @dots{}
1a4f73eb 4910@kindex catch syscall
a96d9b2e
SDJ
4911@cindex break on a system call.
4912A call to or return from a system call, a.k.a.@: @dfn{syscall}. A
4913syscall is a mechanism for application programs to request a service
4914from the operating system (OS) or one of the OS system services.
4915@value{GDBN} can catch some or all of the syscalls issued by the
4916debuggee, and show the related information for each syscall. If no
4917argument is specified, calls to and returns from all system calls
4918will be caught.
4919
4920@var{name} can be any system call name that is valid for the
4921underlying OS. Just what syscalls are valid depends on the OS. On
4922GNU and Unix systems, you can find the full list of valid syscall
4923names on @file{/usr/include/asm/unistd.h}.
4924
4925@c For MS-Windows, the syscall names and the corresponding numbers
4926@c can be found, e.g., on this URL:
4927@c http://www.metasploit.com/users/opcode/syscalls.html
4928@c but we don't support Windows syscalls yet.
4929
4930Normally, @value{GDBN} knows in advance which syscalls are valid for
4931each OS, so you can use the @value{GDBN} command-line completion
4932facilities (@pxref{Completion,, command completion}) to list the
4933available choices.
4934
4935You may also specify the system call numerically. A syscall's
4936number is the value passed to the OS's syscall dispatcher to
4937identify the requested service. When you specify the syscall by its
4938name, @value{GDBN} uses its database of syscalls to convert the name
4939into the corresponding numeric code, but using the number directly
4940may be useful if @value{GDBN}'s database does not have the complete
4941list of syscalls on your system (e.g., because @value{GDBN} lags
4942behind the OS upgrades).
4943
e3487908
GKB
4944You may specify a group of related syscalls to be caught at once using
4945the @code{group:} syntax (@code{g:} is a shorter equivalent). For
4946instance, on some platforms @value{GDBN} allows you to catch all
4947network related syscalls, by passing the argument @code{group:network}
4948to @code{catch syscall}. Note that not all syscall groups are
4949available in every system. You can use the command completion
4950facilities (@pxref{Completion,, command completion}) to list the
4951syscall groups available on your environment.
4952
a96d9b2e
SDJ
4953The example below illustrates how this command works if you don't provide
4954arguments to it:
4955
4956@smallexample
4957(@value{GDBP}) catch syscall
4958Catchpoint 1 (syscall)
4959(@value{GDBP}) r
4960Starting program: /tmp/catch-syscall
4961
4962Catchpoint 1 (call to syscall 'close'), \
4963 0xffffe424 in __kernel_vsyscall ()
4964(@value{GDBP}) c
4965Continuing.
4966
4967Catchpoint 1 (returned from syscall 'close'), \
4968 0xffffe424 in __kernel_vsyscall ()
4969(@value{GDBP})
4970@end smallexample
4971
4972Here is an example of catching a system call by name:
4973
4974@smallexample
4975(@value{GDBP}) catch syscall chroot
4976Catchpoint 1 (syscall 'chroot' [61])
4977(@value{GDBP}) r
4978Starting program: /tmp/catch-syscall
4979
4980Catchpoint 1 (call to syscall 'chroot'), \
4981 0xffffe424 in __kernel_vsyscall ()
4982(@value{GDBP}) c
4983Continuing.
4984
4985Catchpoint 1 (returned from syscall 'chroot'), \
4986 0xffffe424 in __kernel_vsyscall ()
4987(@value{GDBP})
4988@end smallexample
4989
4990An example of specifying a system call numerically. In the case
4991below, the syscall number has a corresponding entry in the XML
4992file, so @value{GDBN} finds its name and prints it:
4993
4994@smallexample
4995(@value{GDBP}) catch syscall 252
4996Catchpoint 1 (syscall(s) 'exit_group')
4997(@value{GDBP}) r
4998Starting program: /tmp/catch-syscall
4999
5000Catchpoint 1 (call to syscall 'exit_group'), \
5001 0xffffe424 in __kernel_vsyscall ()
5002(@value{GDBP}) c
5003Continuing.
5004
5005Program exited normally.
5006(@value{GDBP})
5007@end smallexample
5008
e3487908
GKB
5009Here is an example of catching a syscall group:
5010
5011@smallexample
5012(@value{GDBP}) catch syscall group:process
5013Catchpoint 1 (syscalls 'exit' [1] 'fork' [2] 'waitpid' [7]
5014'execve' [11] 'wait4' [114] 'clone' [120] 'vfork' [190]
5015'exit_group' [252] 'waitid' [284] 'unshare' [310])
5016(@value{GDBP}) r
5017Starting program: /tmp/catch-syscall
5018
5019Catchpoint 1 (call to syscall fork), 0x00007ffff7df4e27 in open64 ()
5020 from /lib64/ld-linux-x86-64.so.2
5021
5022(@value{GDBP}) c
5023Continuing.
5024@end smallexample
5025
a96d9b2e
SDJ
5026However, there can be situations when there is no corresponding name
5027in XML file for that syscall number. In this case, @value{GDBN} prints
5028a warning message saying that it was not able to find the syscall name,
5029but the catchpoint will be set anyway. See the example below:
5030
5031@smallexample
5032(@value{GDBP}) catch syscall 764
5033warning: The number '764' does not represent a known syscall.
5034Catchpoint 2 (syscall 764)
5035(@value{GDBP})
5036@end smallexample
5037
5038If you configure @value{GDBN} using the @samp{--without-expat} option,
5039it will not be able to display syscall names. Also, if your
5040architecture does not have an XML file describing its system calls,
5041you will not be able to see the syscall names. It is important to
5042notice that these two features are used for accessing the syscall
5043name database. In either case, you will see a warning like this:
5044
5045@smallexample
5046(@value{GDBP}) catch syscall
5047warning: Could not open "syscalls/i386-linux.xml"
5048warning: Could not load the syscall XML file 'syscalls/i386-linux.xml'.
5049GDB will not be able to display syscall names.
5050Catchpoint 1 (syscall)
5051(@value{GDBP})
5052@end smallexample
5053
5054Of course, the file name will change depending on your architecture and system.
5055
5056Still using the example above, you can also try to catch a syscall by its
5057number. In this case, you would see something like:
5058
5059@smallexample
5060(@value{GDBP}) catch syscall 252
5061Catchpoint 1 (syscall(s) 252)
5062@end smallexample
5063
5064Again, in this case @value{GDBN} would not be able to display syscall's names.
5065
c906108c 5066@item fork
1a4f73eb 5067@kindex catch fork
b1236ac3 5068A call to @code{fork}.
c906108c
SS
5069
5070@item vfork
1a4f73eb 5071@kindex catch vfork
b1236ac3 5072A call to @code{vfork}.
c906108c 5073
b8e07335
TT
5074@item load @r{[}@var{regexp}@r{]}
5075@itemx unload @r{[}@var{regexp}@r{]}
1a4f73eb
TT
5076@kindex catch load
5077@kindex catch unload
edcc5120
TT
5078The loading or unloading of a shared library. If @var{regexp} is
5079given, then the catchpoint will stop only if the regular expression
5080matches one of the affected libraries.
5081
ab04a2af 5082@item signal @r{[}@var{signal}@dots{} @r{|} @samp{all}@r{]}
1a4f73eb 5083@kindex catch signal
ab04a2af
TT
5084The delivery of a signal.
5085
5086With no arguments, this catchpoint will catch any signal that is not
5087used internally by @value{GDBN}, specifically, all signals except
5088@samp{SIGTRAP} and @samp{SIGINT}.
5089
5090With the argument @samp{all}, all signals, including those used by
5091@value{GDBN}, will be caught. This argument cannot be used with other
5092signal names.
5093
5094Otherwise, the arguments are a list of signal names as given to
5095@code{handle} (@pxref{Signals}). Only signals specified in this list
5096will be caught.
5097
5098One reason that @code{catch signal} can be more useful than
5099@code{handle} is that you can attach commands and conditions to the
5100catchpoint.
5101
5102When a signal is caught by a catchpoint, the signal's @code{stop} and
5103@code{print} settings, as specified by @code{handle}, are ignored.
5104However, whether the signal is still delivered to the inferior depends
5105on the @code{pass} setting; this can be changed in the catchpoint's
5106commands.
5107
c906108c
SS
5108@end table
5109
5110@item tcatch @var{event}
1a4f73eb 5111@kindex tcatch
c906108c
SS
5112Set a catchpoint that is enabled only for one stop. The catchpoint is
5113automatically deleted after the first time the event is caught.
5114
5115@end table
5116
5117Use the @code{info break} command to list the current catchpoints.
5118
c906108c 5119
6d2ebf8b 5120@node Delete Breaks
79a6e687 5121@subsection Deleting Breakpoints
c906108c
SS
5122
5123@cindex clearing breakpoints, watchpoints, catchpoints
5124@cindex deleting breakpoints, watchpoints, catchpoints
5125It is often necessary to eliminate a breakpoint, watchpoint, or
5126catchpoint once it has done its job and you no longer want your program
5127to stop there. This is called @dfn{deleting} the breakpoint. A
5128breakpoint that has been deleted no longer exists; it is forgotten.
5129
5130With the @code{clear} command you can delete breakpoints according to
5131where they are in your program. With the @code{delete} command you can
5132delete individual breakpoints, watchpoints, or catchpoints by specifying
5133their breakpoint numbers.
5134
5135It is not necessary to delete a breakpoint to proceed past it. @value{GDBN}
5136automatically ignores breakpoints on the first instruction to be executed
5137when you continue execution without changing the execution address.
5138
5139@table @code
5140@kindex clear
5141@item clear
5142Delete any breakpoints at the next instruction to be executed in the
79a6e687 5143selected stack frame (@pxref{Selection, ,Selecting a Frame}). When
c906108c
SS
5144the innermost frame is selected, this is a good way to delete a
5145breakpoint where your program just stopped.
5146
2a25a5ba
EZ
5147@item clear @var{location}
5148Delete any breakpoints set at the specified @var{location}.
5149@xref{Specify Location}, for the various forms of @var{location}; the
5150most useful ones are listed below:
5151
5152@table @code
c906108c
SS
5153@item clear @var{function}
5154@itemx clear @var{filename}:@var{function}
09d4efe1 5155Delete any breakpoints set at entry to the named @var{function}.
c906108c
SS
5156
5157@item clear @var{linenum}
5158@itemx clear @var{filename}:@var{linenum}
09d4efe1
EZ
5159Delete any breakpoints set at or within the code of the specified
5160@var{linenum} of the specified @var{filename}.
2a25a5ba 5161@end table
c906108c
SS
5162
5163@cindex delete breakpoints
5164@kindex delete
41afff9a 5165@kindex d @r{(@code{delete})}
18da0c51 5166@item delete @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
c5394b80 5167Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
18da0c51 5168list specified as argument. If no argument is specified, delete all
c906108c
SS
5169breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
5170confirm off}). You can abbreviate this command as @code{d}.
5171@end table
5172
6d2ebf8b 5173@node Disabling
79a6e687 5174@subsection Disabling Breakpoints
c906108c 5175
4644b6e3 5176@cindex enable/disable a breakpoint
c906108c
SS
5177Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
5178prefer to @dfn{disable} it. This makes the breakpoint inoperative as if
5179it had been deleted, but remembers the information on the breakpoint so
5180that you can @dfn{enable} it again later.
5181
5182You disable and enable breakpoints, watchpoints, and catchpoints with
d77f58be
SS
5183the @code{enable} and @code{disable} commands, optionally specifying
5184one or more breakpoint numbers as arguments. Use @code{info break} to
5185print a list of all breakpoints, watchpoints, and catchpoints if you
5186do not know which numbers to use.
c906108c 5187
3b784c4f
EZ
5188Disabling and enabling a breakpoint that has multiple locations
5189affects all of its locations.
5190
816338b5
SS
5191A breakpoint, watchpoint, or catchpoint can have any of several
5192different states of enablement:
c906108c
SS
5193
5194@itemize @bullet
5195@item
5196Enabled. The breakpoint stops your program. A breakpoint set
5197with the @code{break} command starts out in this state.
5198@item
5199Disabled. The breakpoint has no effect on your program.
5200@item
5201Enabled once. The breakpoint stops your program, but then becomes
d4f3574e 5202disabled.
c906108c 5203@item
816338b5
SS
5204Enabled for a count. The breakpoint stops your program for the next
5205N times, then becomes disabled.
5206@item
c906108c 5207Enabled for deletion. The breakpoint stops your program, but
d4f3574e
SS
5208immediately after it does so it is deleted permanently. A breakpoint
5209set with the @code{tbreak} command starts out in this state.
c906108c
SS
5210@end itemize
5211
5212You can use the following commands to enable or disable breakpoints,
5213watchpoints, and catchpoints:
5214
5215@table @code
c906108c 5216@kindex disable
41afff9a 5217@kindex dis @r{(@code{disable})}
18da0c51 5218@item disable @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
c906108c
SS
5219Disable the specified breakpoints---or all breakpoints, if none are
5220listed. A disabled breakpoint has no effect but is not forgotten. All
5221options such as ignore-counts, conditions and commands are remembered in
5222case the breakpoint is enabled again later. You may abbreviate
5223@code{disable} as @code{dis}.
5224
c906108c 5225@kindex enable
18da0c51 5226@item enable @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
c906108c
SS
5227Enable the specified breakpoints (or all defined breakpoints). They
5228become effective once again in stopping your program.
5229
18da0c51 5230@item enable @r{[}breakpoints@r{]} once @var{list}@dots{}
c906108c
SS
5231Enable the specified breakpoints temporarily. @value{GDBN} disables any
5232of these breakpoints immediately after stopping your program.
5233
18da0c51 5234@item enable @r{[}breakpoints@r{]} count @var{count} @var{list}@dots{}
816338b5
SS
5235Enable the specified breakpoints temporarily. @value{GDBN} records
5236@var{count} with each of the specified breakpoints, and decrements a
5237breakpoint's count when it is hit. When any count reaches 0,
5238@value{GDBN} disables that breakpoint. If a breakpoint has an ignore
5239count (@pxref{Conditions, ,Break Conditions}), that will be
5240decremented to 0 before @var{count} is affected.
5241
18da0c51 5242@item enable @r{[}breakpoints@r{]} delete @var{list}@dots{}
c906108c
SS
5243Enable the specified breakpoints to work once, then die. @value{GDBN}
5244deletes any of these breakpoints as soon as your program stops there.
09d4efe1 5245Breakpoints set by the @code{tbreak} command start out in this state.
c906108c
SS
5246@end table
5247
d4f3574e
SS
5248@c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
5249@c confusing: tbreak is also initially enabled.
c906108c 5250Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
79a6e687 5251,Setting Breakpoints}), breakpoints that you set are initially enabled;
c906108c
SS
5252subsequently, they become disabled or enabled only when you use one of
5253the commands above. (The command @code{until} can set and delete a
5254breakpoint of its own, but it does not change the state of your other
5255breakpoints; see @ref{Continuing and Stepping, ,Continuing and
79a6e687 5256Stepping}.)
c906108c 5257
6d2ebf8b 5258@node Conditions
79a6e687 5259@subsection Break Conditions
c906108c
SS
5260@cindex conditional breakpoints
5261@cindex breakpoint conditions
5262
5263@c FIXME what is scope of break condition expr? Context where wanted?
5d161b24 5264@c in particular for a watchpoint?
c906108c
SS
5265The simplest sort of breakpoint breaks every time your program reaches a
5266specified place. You can also specify a @dfn{condition} for a
5267breakpoint. A condition is just a Boolean expression in your
5268programming language (@pxref{Expressions, ,Expressions}). A breakpoint with
5269a condition evaluates the expression each time your program reaches it,
5270and your program stops only if the condition is @emph{true}.
5271
5272This is the converse of using assertions for program validation; in that
5273situation, you want to stop when the assertion is violated---that is,
5274when the condition is false. In C, if you want to test an assertion expressed
5275by the condition @var{assert}, you should set the condition
5276@samp{! @var{assert}} on the appropriate breakpoint.
5277
5278Conditions are also accepted for watchpoints; you may not need them,
5279since a watchpoint is inspecting the value of an expression anyhow---but
5280it might be simpler, say, to just set a watchpoint on a variable name,
5281and specify a condition that tests whether the new value is an interesting
5282one.
5283
5284Break conditions can have side effects, and may even call functions in
5285your program. This can be useful, for example, to activate functions
5286that log program progress, or to use your own print functions to
99e008fe 5287format special data structures. The effects are completely predictable
c906108c
SS
5288unless there is another enabled breakpoint at the same address. (In
5289that case, @value{GDBN} might see the other breakpoint first and stop your
5290program without checking the condition of this one.) Note that
d4f3574e
SS
5291breakpoint commands are usually more convenient and flexible than break
5292conditions for the
c906108c 5293purpose of performing side effects when a breakpoint is reached
79a6e687 5294(@pxref{Break Commands, ,Breakpoint Command Lists}).
c906108c 5295
83364271
LM
5296Breakpoint conditions can also be evaluated on the target's side if
5297the target supports it. Instead of evaluating the conditions locally,
5298@value{GDBN} encodes the expression into an agent expression
5299(@pxref{Agent Expressions}) suitable for execution on the target,
5300independently of @value{GDBN}. Global variables become raw memory
5301locations, locals become stack accesses, and so forth.
5302
5303In this case, @value{GDBN} will only be notified of a breakpoint trigger
5304when its condition evaluates to true. This mechanism may provide faster
5305response times depending on the performance characteristics of the target
5306since it does not need to keep @value{GDBN} informed about
5307every breakpoint trigger, even those with false conditions.
5308
c906108c
SS
5309Break conditions can be specified when a breakpoint is set, by using
5310@samp{if} in the arguments to the @code{break} command. @xref{Set
79a6e687 5311Breaks, ,Setting Breakpoints}. They can also be changed at any time
c906108c 5312with the @code{condition} command.
53a5351d 5313
c906108c
SS
5314You can also use the @code{if} keyword with the @code{watch} command.
5315The @code{catch} command does not recognize the @code{if} keyword;
5316@code{condition} is the only way to impose a further condition on a
5317catchpoint.
c906108c
SS
5318
5319@table @code
5320@kindex condition
5321@item condition @var{bnum} @var{expression}
5322Specify @var{expression} as the break condition for breakpoint,
5323watchpoint, or catchpoint number @var{bnum}. After you set a condition,
5324breakpoint @var{bnum} stops your program only if the value of
5325@var{expression} is true (nonzero, in C). When you use
5326@code{condition}, @value{GDBN} checks @var{expression} immediately for
5327syntactic correctness, and to determine whether symbols in it have
d4f3574e
SS
5328referents in the context of your breakpoint. If @var{expression} uses
5329symbols not referenced in the context of the breakpoint, @value{GDBN}
5330prints an error message:
5331
474c8240 5332@smallexample
d4f3574e 5333No symbol "foo" in current context.
474c8240 5334@end smallexample
d4f3574e
SS
5335
5336@noindent
c906108c
SS
5337@value{GDBN} does
5338not actually evaluate @var{expression} at the time the @code{condition}
d4f3574e
SS
5339command (or a command that sets a breakpoint with a condition, like
5340@code{break if @dots{}}) is given, however. @xref{Expressions, ,Expressions}.
c906108c
SS
5341
5342@item condition @var{bnum}
5343Remove the condition from breakpoint number @var{bnum}. It becomes
5344an ordinary unconditional breakpoint.
5345@end table
5346
5347@cindex ignore count (of breakpoint)
5348A special case of a breakpoint condition is to stop only when the
5349breakpoint has been reached a certain number of times. This is so
5350useful that there is a special way to do it, using the @dfn{ignore
5351count} of the breakpoint. Every breakpoint has an ignore count, which
5352is an integer. Most of the time, the ignore count is zero, and
5353therefore has no effect. But if your program reaches a breakpoint whose
5354ignore count is positive, then instead of stopping, it just decrements
5355the ignore count by one and continues. As a result, if the ignore count
5356value is @var{n}, the breakpoint does not stop the next @var{n} times
5357your program reaches it.
5358
5359@table @code
5360@kindex ignore
5361@item ignore @var{bnum} @var{count}
5362Set the ignore count of breakpoint number @var{bnum} to @var{count}.
5363The next @var{count} times the breakpoint is reached, your program's
5364execution does not stop; other than to decrement the ignore count, @value{GDBN}
5365takes no action.
5366
5367To make the breakpoint stop the next time it is reached, specify
5368a count of zero.
5369
5370When you use @code{continue} to resume execution of your program from a
5371breakpoint, you can specify an ignore count directly as an argument to
5372@code{continue}, rather than using @code{ignore}. @xref{Continuing and
79a6e687 5373Stepping,,Continuing and Stepping}.
c906108c
SS
5374
5375If a breakpoint has a positive ignore count and a condition, the
5376condition is not checked. Once the ignore count reaches zero,
5377@value{GDBN} resumes checking the condition.
5378
5379You could achieve the effect of the ignore count with a condition such
5380as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
5381is decremented each time. @xref{Convenience Vars, ,Convenience
79a6e687 5382Variables}.
c906108c
SS
5383@end table
5384
5385Ignore counts apply to breakpoints, watchpoints, and catchpoints.
5386
5387
6d2ebf8b 5388@node Break Commands
79a6e687 5389@subsection Breakpoint Command Lists
c906108c
SS
5390
5391@cindex breakpoint commands
5392You can give any breakpoint (or watchpoint or catchpoint) a series of
5393commands to execute when your program stops due to that breakpoint. For
5394example, you might want to print the values of certain expressions, or
5395enable other breakpoints.
5396
5397@table @code
5398@kindex commands
ca91424e 5399@kindex end@r{ (breakpoint commands)}
18da0c51 5400@item commands @r{[}@var{list}@dots{}@r{]}
c906108c
SS
5401@itemx @dots{} @var{command-list} @dots{}
5402@itemx end
95a42b64 5403Specify a list of commands for the given breakpoints. The commands
c906108c
SS
5404themselves appear on the following lines. Type a line containing just
5405@code{end} to terminate the commands.
5406
5407To remove all commands from a breakpoint, type @code{commands} and
5408follow it immediately with @code{end}; that is, give no commands.
5409
95a42b64
TT
5410With no argument, @code{commands} refers to the last breakpoint,
5411watchpoint, or catchpoint set (not to the breakpoint most recently
5412encountered). If the most recent breakpoints were set with a single
5413command, then the @code{commands} will apply to all the breakpoints
5414set by that command. This applies to breakpoints set by
86b17b60
PA
5415@code{rbreak}, and also applies when a single @code{break} command
5416creates multiple breakpoints (@pxref{Ambiguous Expressions,,Ambiguous
5417Expressions}).
c906108c
SS
5418@end table
5419
5420Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
5421disabled within a @var{command-list}.
5422
5423You can use breakpoint commands to start your program up again. Simply
5424use the @code{continue} command, or @code{step}, or any other command
5425that resumes execution.
5426
5427Any other commands in the command list, after a command that resumes
5428execution, are ignored. This is because any time you resume execution
5429(even with a simple @code{next} or @code{step}), you may encounter
5430another breakpoint---which could have its own command list, leading to
5431ambiguities about which list to execute.
5432
5433@kindex silent
5434If the first command you specify in a command list is @code{silent}, the
5435usual message about stopping at a breakpoint is not printed. This may
5436be desirable for breakpoints that are to print a specific message and
5437then continue. If none of the remaining commands print anything, you
5438see no sign that the breakpoint was reached. @code{silent} is
5439meaningful only at the beginning of a breakpoint command list.
5440
5441The commands @code{echo}, @code{output}, and @code{printf} allow you to
5442print precisely controlled output, and are often useful in silent
79a6e687 5443breakpoints. @xref{Output, ,Commands for Controlled Output}.
c906108c
SS
5444
5445For example, here is how you could use breakpoint commands to print the
5446value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
5447
474c8240 5448@smallexample
c906108c
SS
5449break foo if x>0
5450commands
5451silent
5452printf "x is %d\n",x
5453cont
5454end
474c8240 5455@end smallexample
c906108c
SS
5456
5457One application for breakpoint commands is to compensate for one bug so
5458you can test for another. Put a breakpoint just after the erroneous line
5459of code, give it a condition to detect the case in which something
5460erroneous has been done, and give it commands to assign correct values
5461to any variables that need them. End with the @code{continue} command
5462so that your program does not stop, and start with the @code{silent}
5463command so that no output is produced. Here is an example:
5464
474c8240 5465@smallexample
c906108c
SS
5466break 403
5467commands
5468silent
5469set x = y + 4
5470cont
5471end
474c8240 5472@end smallexample
c906108c 5473
e7e0cddf
SS
5474@node Dynamic Printf
5475@subsection Dynamic Printf
5476
5477@cindex dynamic printf
5478@cindex dprintf
5479The dynamic printf command @code{dprintf} combines a breakpoint with
5480formatted printing of your program's data to give you the effect of
5481inserting @code{printf} calls into your program on-the-fly, without
5482having to recompile it.
5483
5484In its most basic form, the output goes to the GDB console. However,
5485you can set the variable @code{dprintf-style} for alternate handling.
5486For instance, you can ask to format the output by calling your
5487program's @code{printf} function. This has the advantage that the
5488characters go to the program's output device, so they can recorded in
5489redirects to files and so forth.
5490
d3ce09f5
SS
5491If you are doing remote debugging with a stub or agent, you can also
5492ask to have the printf handled by the remote agent. In addition to
5493ensuring that the output goes to the remote program's device along
5494with any other output the program might produce, you can also ask that
5495the dprintf remain active even after disconnecting from the remote
5496target. Using the stub/agent is also more efficient, as it can do
5497everything without needing to communicate with @value{GDBN}.
5498
e7e0cddf
SS
5499@table @code
5500@kindex dprintf
5501@item dprintf @var{location},@var{template},@var{expression}[,@var{expression}@dots{}]
5502Whenever execution reaches @var{location}, print the values of one or
5503more @var{expressions} under the control of the string @var{template}.
5504To print several values, separate them with commas.
5505
5506@item set dprintf-style @var{style}
5507Set the dprintf output to be handled in one of several different
5508styles enumerated below. A change of style affects all existing
5509dynamic printfs immediately. (If you need individual control over the
5510print commands, simply define normal breakpoints with
5511explicitly-supplied command lists.)
5512
18da0c51 5513@table @code
e7e0cddf
SS
5514@item gdb
5515@kindex dprintf-style gdb
5516Handle the output using the @value{GDBN} @code{printf} command.
5517
5518@item call
5519@kindex dprintf-style call
5520Handle the output by calling a function in your program (normally
5521@code{printf}).
5522
d3ce09f5
SS
5523@item agent
5524@kindex dprintf-style agent
5525Have the remote debugging agent (such as @code{gdbserver}) handle
5526the output itself. This style is only available for agents that
5527support running commands on the target.
18da0c51 5528@end table
d3ce09f5 5529
e7e0cddf
SS
5530@item set dprintf-function @var{function}
5531Set the function to call if the dprintf style is @code{call}. By
5532default its value is @code{printf}. You may set it to any expression.
5533that @value{GDBN} can evaluate to a function, as per the @code{call}
5534command.
5535
5536@item set dprintf-channel @var{channel}
5537Set a ``channel'' for dprintf. If set to a non-empty value,
5538@value{GDBN} will evaluate it as an expression and pass the result as
5539a first argument to the @code{dprintf-function}, in the manner of
5540@code{fprintf} and similar functions. Otherwise, the dprintf format
5541string will be the first argument, in the manner of @code{printf}.
5542
5543As an example, if you wanted @code{dprintf} output to go to a logfile
5544that is a standard I/O stream assigned to the variable @code{mylog},
5545you could do the following:
5546
5547@example
5548(gdb) set dprintf-style call
5549(gdb) set dprintf-function fprintf
5550(gdb) set dprintf-channel mylog
5551(gdb) dprintf 25,"at line 25, glob=%d\n",glob
5552Dprintf 1 at 0x123456: file main.c, line 25.
5553(gdb) info break
55541 dprintf keep y 0x00123456 in main at main.c:25
5555 call (void) fprintf (mylog,"at line 25, glob=%d\n",glob)
5556 continue
5557(gdb)
5558@end example
5559
5560Note that the @code{info break} displays the dynamic printf commands
5561as normal breakpoint commands; you can thus easily see the effect of
5562the variable settings.
5563
d3ce09f5
SS
5564@item set disconnected-dprintf on
5565@itemx set disconnected-dprintf off
5566@kindex set disconnected-dprintf
5567Choose whether @code{dprintf} commands should continue to run if
5568@value{GDBN} has disconnected from the target. This only applies
5569if the @code{dprintf-style} is @code{agent}.
5570
5571@item show disconnected-dprintf off
5572@kindex show disconnected-dprintf
5573Show the current choice for disconnected @code{dprintf}.
5574
e7e0cddf
SS
5575@end table
5576
5577@value{GDBN} does not check the validity of function and channel,
5578relying on you to supply values that are meaningful for the contexts
5579in which they are being used. For instance, the function and channel
5580may be the values of local variables, but if that is the case, then
5581all enabled dynamic prints must be at locations within the scope of
5582those locals. If evaluation fails, @value{GDBN} will report an error.
5583
6149aea9
PA
5584@node Save Breakpoints
5585@subsection How to save breakpoints to a file
5586
5587To save breakpoint definitions to a file use the @w{@code{save
5588breakpoints}} command.
5589
5590@table @code
5591@kindex save breakpoints
5592@cindex save breakpoints to a file for future sessions
5593@item save breakpoints [@var{filename}]
5594This command saves all current breakpoint definitions together with
5595their commands and ignore counts, into a file @file{@var{filename}}
5596suitable for use in a later debugging session. This includes all
5597types of breakpoints (breakpoints, watchpoints, catchpoints,
5598tracepoints). To read the saved breakpoint definitions, use the
5599@code{source} command (@pxref{Command Files}). Note that watchpoints
5600with expressions involving local variables may fail to be recreated
5601because it may not be possible to access the context where the
5602watchpoint is valid anymore. Because the saved breakpoint definitions
5603are simply a sequence of @value{GDBN} commands that recreate the
5604breakpoints, you can edit the file in your favorite editing program,
5605and remove the breakpoint definitions you're not interested in, or
5606that can no longer be recreated.
5607@end table
5608
62e5f89c
SDJ
5609@node Static Probe Points
5610@subsection Static Probe Points
5611
5612@cindex static probe point, SystemTap
3133f8c1 5613@cindex static probe point, DTrace
62e5f89c
SDJ
5614@value{GDBN} supports @dfn{SDT} probes in the code. @acronym{SDT} stands
5615for Statically Defined Tracing, and the probes are designed to have a tiny
3133f8c1
JM
5616runtime code and data footprint, and no dynamic relocations.
5617
5618Currently, the following types of probes are supported on
5619ELF-compatible systems:
5620
5621@itemize @bullet
62e5f89c 5622
3133f8c1
JM
5623@item @code{SystemTap} (@uref{http://sourceware.org/systemtap/})
5624@acronym{SDT} probes@footnote{See
62e5f89c 5625@uref{http://sourceware.org/systemtap/wiki/AddingUserSpaceProbingToApps}
3133f8c1
JM
5626for more information on how to add @code{SystemTap} @acronym{SDT}
5627probes in your applications.}. @code{SystemTap} probes are usable
5628from assembly, C and C@t{++} languages@footnote{See
5629@uref{http://sourceware.org/systemtap/wiki/UserSpaceProbeImplementation}
5630for a good reference on how the @acronym{SDT} probes are implemented.}.
5631
5632@item @code{DTrace} (@uref{http://oss.oracle.com/projects/DTrace})
5633@acronym{USDT} probes. @code{DTrace} probes are usable from C and
5634C@t{++} languages.
5635@end itemize
62e5f89c
SDJ
5636
5637@cindex semaphores on static probe points
3133f8c1
JM
5638Some @code{SystemTap} probes have an associated semaphore variable;
5639for instance, this happens automatically if you defined your probe
5640using a DTrace-style @file{.d} file. If your probe has a semaphore,
5641@value{GDBN} will automatically enable it when you specify a
5642breakpoint using the @samp{-probe-stap} notation. But, if you put a
5643breakpoint at a probe's location by some other method (e.g.,
5644@code{break file:line}), then @value{GDBN} will not automatically set
5645the semaphore. @code{DTrace} probes do not support semaphores.
62e5f89c
SDJ
5646
5647You can examine the available static static probes using @code{info
5648probes}, with optional arguments:
5649
5650@table @code
5651@kindex info probes
3133f8c1
JM
5652@item info probes @r{[}@var{type}@r{]} @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5653If given, @var{type} is either @code{stap} for listing
5654@code{SystemTap} probes or @code{dtrace} for listing @code{DTrace}
5655probes. If omitted all probes are listed regardless of their types.
5656
62e5f89c
SDJ
5657If given, @var{provider} is a regular expression used to match against provider
5658names when selecting which probes to list. If omitted, probes by all
5659probes from all providers are listed.
5660
5661If given, @var{name} is a regular expression to match against probe names
5662when selecting which probes to list. If omitted, probe names are not
5663considered when deciding whether to display them.
5664
5665If given, @var{objfile} is a regular expression used to select which
5666object files (executable or shared libraries) to examine. If not
5667given, all object files are considered.
5668
5669@item info probes all
5670List the available static probes, from all types.
5671@end table
5672
9aca2ff8
JM
5673@cindex enabling and disabling probes
5674Some probe points can be enabled and/or disabled. The effect of
5675enabling or disabling a probe depends on the type of probe being
3133f8c1
JM
5676handled. Some @code{DTrace} probes can be enabled or
5677disabled, but @code{SystemTap} probes cannot be disabled.
9aca2ff8
JM
5678
5679You can enable (or disable) one or more probes using the following
5680commands, with optional arguments:
5681
5682@table @code
5683@kindex enable probes
5684@item enable probes @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5685If given, @var{provider} is a regular expression used to match against
5686provider names when selecting which probes to enable. If omitted,
5687all probes from all providers are enabled.
5688
5689If given, @var{name} is a regular expression to match against probe
5690names when selecting which probes to enable. If omitted, probe names
5691are not considered when deciding whether to enable them.
5692
5693If given, @var{objfile} is a regular expression used to select which
5694object files (executable or shared libraries) to examine. If not
5695given, all object files are considered.
5696
5697@kindex disable probes
5698@item disable probes @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5699See the @code{enable probes} command above for a description of the
5700optional arguments accepted by this command.
5701@end table
5702
62e5f89c
SDJ
5703@vindex $_probe_arg@r{, convenience variable}
5704A probe may specify up to twelve arguments. These are available at the
5705point at which the probe is defined---that is, when the current PC is
5706at the probe's location. The arguments are available using the
5707convenience variables (@pxref{Convenience Vars})
3133f8c1
JM
5708@code{$_probe_arg0}@dots{}@code{$_probe_arg11}. In @code{SystemTap}
5709probes each probe argument is an integer of the appropriate size;
5710types are not preserved. In @code{DTrace} probes types are preserved
5711provided that they are recognized as such by @value{GDBN}; otherwise
5712the value of the probe argument will be a long integer. The
62e5f89c
SDJ
5713convenience variable @code{$_probe_argc} holds the number of arguments
5714at the current probe point.
5715
5716These variables are always available, but attempts to access them at
5717any location other than a probe point will cause @value{GDBN} to give
5718an error message.
5719
5720
c906108c 5721@c @ifclear BARETARGET
6d2ebf8b 5722@node Error in Breakpoints
d4f3574e 5723@subsection ``Cannot insert breakpoints''
c906108c 5724
fa3a767f
PA
5725If you request too many active hardware-assisted breakpoints and
5726watchpoints, you will see this error message:
d4f3574e
SS
5727
5728@c FIXME: the precise wording of this message may change; the relevant
5729@c source change is not committed yet (Sep 3, 1999).
5730@smallexample
5731Stopped; cannot insert breakpoints.
5732You may have requested too many hardware breakpoints and watchpoints.
5733@end smallexample
5734
5735@noindent
5736This message is printed when you attempt to resume the program, since
5737only then @value{GDBN} knows exactly how many hardware breakpoints and
5738watchpoints it needs to insert.
5739
5740When this message is printed, you need to disable or remove some of the
5741hardware-assisted breakpoints and watchpoints, and then continue.
5742
79a6e687 5743@node Breakpoint-related Warnings
1485d690
KB
5744@subsection ``Breakpoint address adjusted...''
5745@cindex breakpoint address adjusted
5746
5747Some processor architectures place constraints on the addresses at
5748which breakpoints may be placed. For architectures thus constrained,
5749@value{GDBN} will attempt to adjust the breakpoint's address to comply
5750with the constraints dictated by the architecture.
5751
5752One example of such an architecture is the Fujitsu FR-V. The FR-V is
5753a VLIW architecture in which a number of RISC-like instructions may be
5754bundled together for parallel execution. The FR-V architecture
5755constrains the location of a breakpoint instruction within such a
5756bundle to the instruction with the lowest address. @value{GDBN}
5757honors this constraint by adjusting a breakpoint's address to the
5758first in the bundle.
5759
5760It is not uncommon for optimized code to have bundles which contain
5761instructions from different source statements, thus it may happen that
5762a breakpoint's address will be adjusted from one source statement to
5763another. Since this adjustment may significantly alter @value{GDBN}'s
5764breakpoint related behavior from what the user expects, a warning is
5765printed when the breakpoint is first set and also when the breakpoint
5766is hit.
5767
5768A warning like the one below is printed when setting a breakpoint
5769that's been subject to address adjustment:
5770
5771@smallexample
5772warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
5773@end smallexample
5774
5775Such warnings are printed both for user settable and @value{GDBN}'s
5776internal breakpoints. If you see one of these warnings, you should
5777verify that a breakpoint set at the adjusted address will have the
5778desired affect. If not, the breakpoint in question may be removed and
b383017d 5779other breakpoints may be set which will have the desired behavior.
1485d690
KB
5780E.g., it may be sufficient to place the breakpoint at a later
5781instruction. A conditional breakpoint may also be useful in some
5782cases to prevent the breakpoint from triggering too often.
5783
5784@value{GDBN} will also issue a warning when stopping at one of these
5785adjusted breakpoints:
5786
5787@smallexample
5788warning: Breakpoint 1 address previously adjusted from 0x00010414
5789to 0x00010410.
5790@end smallexample
5791
5792When this warning is encountered, it may be too late to take remedial
5793action except in cases where the breakpoint is hit earlier or more
5794frequently than expected.
d4f3574e 5795
6d2ebf8b 5796@node Continuing and Stepping
79a6e687 5797@section Continuing and Stepping
c906108c
SS
5798
5799@cindex stepping
5800@cindex continuing
5801@cindex resuming execution
5802@dfn{Continuing} means resuming program execution until your program
5803completes normally. In contrast, @dfn{stepping} means executing just
5804one more ``step'' of your program, where ``step'' may mean either one
5805line of source code, or one machine instruction (depending on what
7a292a7a
SS
5806particular command you use). Either when continuing or when stepping,
5807your program may stop even sooner, due to a breakpoint or a signal. (If
d4f3574e 5808it stops due to a signal, you may want to use @code{handle}, or use
e5f8a7cc
PA
5809@samp{signal 0} to resume execution (@pxref{Signals, ,Signals}),
5810or you may step into the signal's handler (@pxref{stepping and signal
5811handlers}).)
c906108c
SS
5812
5813@table @code
5814@kindex continue
41afff9a
EZ
5815@kindex c @r{(@code{continue})}
5816@kindex fg @r{(resume foreground execution)}
c906108c
SS
5817@item continue @r{[}@var{ignore-count}@r{]}
5818@itemx c @r{[}@var{ignore-count}@r{]}
5819@itemx fg @r{[}@var{ignore-count}@r{]}
5820Resume program execution, at the address where your program last stopped;
5821any breakpoints set at that address are bypassed. The optional argument
5822@var{ignore-count} allows you to specify a further number of times to
5823ignore a breakpoint at this location; its effect is like that of
79a6e687 5824@code{ignore} (@pxref{Conditions, ,Break Conditions}).
c906108c
SS
5825
5826The argument @var{ignore-count} is meaningful only when your program
5827stopped due to a breakpoint. At other times, the argument to
5828@code{continue} is ignored.
5829
d4f3574e
SS
5830The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
5831debugged program is deemed to be the foreground program) are provided
5832purely for convenience, and have exactly the same behavior as
5833@code{continue}.
c906108c
SS
5834@end table
5835
5836To resume execution at a different place, you can use @code{return}
79a6e687 5837(@pxref{Returning, ,Returning from a Function}) to go back to the
c906108c 5838calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
79a6e687 5839Different Address}) to go to an arbitrary location in your program.
c906108c
SS
5840
5841A typical technique for using stepping is to set a breakpoint
79a6e687 5842(@pxref{Breakpoints, ,Breakpoints; Watchpoints; and Catchpoints}) at the
c906108c
SS
5843beginning of the function or the section of your program where a problem
5844is believed to lie, run your program until it stops at that breakpoint,
5845and then step through the suspect area, examining the variables that are
5846interesting, until you see the problem happen.
5847
5848@table @code
5849@kindex step
41afff9a 5850@kindex s @r{(@code{step})}
c906108c
SS
5851@item step
5852Continue running your program until control reaches a different source
5853line, then stop it and return control to @value{GDBN}. This command is
5854abbreviated @code{s}.
5855
5856@quotation
5857@c "without debugging information" is imprecise; actually "without line
5858@c numbers in the debugging information". (gcc -g1 has debugging info but
5859@c not line numbers). But it seems complex to try to make that
5860@c distinction here.
5861@emph{Warning:} If you use the @code{step} command while control is
5862within a function that was compiled without debugging information,
5863execution proceeds until control reaches a function that does have
5864debugging information. Likewise, it will not step into a function which
5865is compiled without debugging information. To step through functions
5866without debugging information, use the @code{stepi} command, described
5867below.
5868@end quotation
5869
4a92d011
EZ
5870The @code{step} command only stops at the first instruction of a source
5871line. This prevents the multiple stops that could otherwise occur in
5872@code{switch} statements, @code{for} loops, etc. @code{step} continues
5873to stop if a function that has debugging information is called within
5874the line. In other words, @code{step} @emph{steps inside} any functions
5875called within the line.
c906108c 5876
d4f3574e
SS
5877Also, the @code{step} command only enters a function if there is line
5878number information for the function. Otherwise it acts like the
5d161b24 5879@code{next} command. This avoids problems when using @code{cc -gl}
eb17f351 5880on @acronym{MIPS} machines. Previously, @code{step} entered subroutines if there
5d161b24 5881was any debugging information about the routine.
c906108c
SS
5882
5883@item step @var{count}
5884Continue running as in @code{step}, but do so @var{count} times. If a
7a292a7a
SS
5885breakpoint is reached, or a signal not related to stepping occurs before
5886@var{count} steps, stepping stops right away.
c906108c
SS
5887
5888@kindex next
41afff9a 5889@kindex n @r{(@code{next})}
c906108c
SS
5890@item next @r{[}@var{count}@r{]}
5891Continue to the next source line in the current (innermost) stack frame.
7a292a7a
SS
5892This is similar to @code{step}, but function calls that appear within
5893the line of code are executed without stopping. Execution stops when
5894control reaches a different line of code at the original stack level
5895that was executing when you gave the @code{next} command. This command
5896is abbreviated @code{n}.
c906108c
SS
5897
5898An argument @var{count} is a repeat count, as for @code{step}.
5899
5900
5901@c FIX ME!! Do we delete this, or is there a way it fits in with
5902@c the following paragraph? --- Vctoria
5903@c
5904@c @code{next} within a function that lacks debugging information acts like
5905@c @code{step}, but any function calls appearing within the code of the
5906@c function are executed without stopping.
5907
d4f3574e
SS
5908The @code{next} command only stops at the first instruction of a
5909source line. This prevents multiple stops that could otherwise occur in
4a92d011 5910@code{switch} statements, @code{for} loops, etc.
c906108c 5911
b90a5f51
CF
5912@kindex set step-mode
5913@item set step-mode
5914@cindex functions without line info, and stepping
5915@cindex stepping into functions with no line info
5916@itemx set step-mode on
4a92d011 5917The @code{set step-mode on} command causes the @code{step} command to
b90a5f51
CF
5918stop at the first instruction of a function which contains no debug line
5919information rather than stepping over it.
5920
4a92d011
EZ
5921This is useful in cases where you may be interested in inspecting the
5922machine instructions of a function which has no symbolic info and do not
5923want @value{GDBN} to automatically skip over this function.
b90a5f51
CF
5924
5925@item set step-mode off
4a92d011 5926Causes the @code{step} command to step over any functions which contains no
b90a5f51
CF
5927debug information. This is the default.
5928
9c16f35a
EZ
5929@item show step-mode
5930Show whether @value{GDBN} will stop in or step over functions without
5931source line debug information.
5932
c906108c 5933@kindex finish
8dfa32fc 5934@kindex fin @r{(@code{finish})}
c906108c
SS
5935@item finish
5936Continue running until just after function in the selected stack frame
8dfa32fc
JB
5937returns. Print the returned value (if any). This command can be
5938abbreviated as @code{fin}.
c906108c
SS
5939
5940Contrast this with the @code{return} command (@pxref{Returning,
79a6e687 5941,Returning from a Function}).
c906108c 5942
000439d5
TT
5943@kindex set print finish
5944@kindex show print finish
5945@item set print finish @r{[}on|off@r{]}
5946@itemx show print finish
5947By default the @code{finish} command will show the value that is
5948returned by the function. This can be disabled using @code{set print
5949finish off}. When disabled, the value is still entered into the value
5950history (@pxref{Value History}), but not displayed.
5951
c906108c 5952@kindex until
41afff9a 5953@kindex u @r{(@code{until})}
09d4efe1 5954@cindex run until specified location
c906108c
SS
5955@item until
5956@itemx u
5957Continue running until a source line past the current line, in the
5958current stack frame, is reached. This command is used to avoid single
5959stepping through a loop more than once. It is like the @code{next}
5960command, except that when @code{until} encounters a jump, it
5961automatically continues execution until the program counter is greater
5962than the address of the jump.
5963
5964This means that when you reach the end of a loop after single stepping
5965though it, @code{until} makes your program continue execution until it
5966exits the loop. In contrast, a @code{next} command at the end of a loop
5967simply steps back to the beginning of the loop, which forces you to step
5968through the next iteration.
5969
5970@code{until} always stops your program if it attempts to exit the current
5971stack frame.
5972
5973@code{until} may produce somewhat counterintuitive results if the order
5974of machine code does not match the order of the source lines. For
5975example, in the following excerpt from a debugging session, the @code{f}
5976(@code{frame}) command shows that execution is stopped at line
5977@code{206}; yet when we use @code{until}, we get to line @code{195}:
5978
474c8240 5979@smallexample
c906108c
SS
5980(@value{GDBP}) f
5981#0 main (argc=4, argv=0xf7fffae8) at m4.c:206
5982206 expand_input();
5983(@value{GDBP}) until
5984195 for ( ; argc > 0; NEXTARG) @{
474c8240 5985@end smallexample
c906108c
SS
5986
5987This happened because, for execution efficiency, the compiler had
5988generated code for the loop closure test at the end, rather than the
5989start, of the loop---even though the test in a C @code{for}-loop is
5990written before the body of the loop. The @code{until} command appeared
5991to step back to the beginning of the loop when it advanced to this
5992expression; however, it has not really gone to an earlier
5993statement---not in terms of the actual machine code.
5994
5995@code{until} with no argument works by means of single
5996instruction stepping, and hence is slower than @code{until} with an
5997argument.
5998
5999@item until @var{location}
6000@itemx u @var{location}
697aa1b7
EZ
6001Continue running your program until either the specified @var{location} is
6002reached, or the current stack frame returns. The location is any of
2a25a5ba
EZ
6003the forms described in @ref{Specify Location}.
6004This form of the command uses temporary breakpoints, and
c60eb6f1
EZ
6005hence is quicker than @code{until} without an argument. The specified
6006location is actually reached only if it is in the current frame. This
6007implies that @code{until} can be used to skip over recursive function
6008invocations. For instance in the code below, if the current location is
6009line @code{96}, issuing @code{until 99} will execute the program up to
db2e3e2e 6010line @code{99} in the same invocation of factorial, i.e., after the inner
c60eb6f1
EZ
6011invocations have returned.
6012
6013@smallexample
601494 int factorial (int value)
601595 @{
601696 if (value > 1) @{
601797 value *= factorial (value - 1);
601898 @}
601999 return (value);
6020100 @}
6021@end smallexample
6022
6023
6024@kindex advance @var{location}
984359d2 6025@item advance @var{location}
09d4efe1 6026Continue running the program up to the given @var{location}. An argument is
2a25a5ba
EZ
6027required, which should be of one of the forms described in
6028@ref{Specify Location}.
6029Execution will also stop upon exit from the current stack
c60eb6f1
EZ
6030frame. This command is similar to @code{until}, but @code{advance} will
6031not skip over recursive function calls, and the target location doesn't
6032have to be in the same frame as the current one.
6033
c906108c
SS
6034
6035@kindex stepi
41afff9a 6036@kindex si @r{(@code{stepi})}
c906108c 6037@item stepi
96a2c332 6038@itemx stepi @var{arg}
c906108c
SS
6039@itemx si
6040Execute one machine instruction, then stop and return to the debugger.
6041
6042It is often useful to do @samp{display/i $pc} when stepping by machine
6043instructions. This makes @value{GDBN} automatically display the next
6044instruction to be executed, each time your program stops. @xref{Auto
79a6e687 6045Display,, Automatic Display}.
c906108c
SS
6046
6047An argument is a repeat count, as in @code{step}.
6048
6049@need 750
6050@kindex nexti
41afff9a 6051@kindex ni @r{(@code{nexti})}
c906108c 6052@item nexti
96a2c332 6053@itemx nexti @var{arg}
c906108c
SS
6054@itemx ni
6055Execute one machine instruction, but if it is a function call,
6056proceed until the function returns.
6057
6058An argument is a repeat count, as in @code{next}.
c1e36e3e
PA
6059
6060@end table
6061
6062@anchor{range stepping}
6063@cindex range stepping
6064@cindex target-assisted range stepping
6065By default, and if available, @value{GDBN} makes use of
6066target-assisted @dfn{range stepping}. In other words, whenever you
6067use a stepping command (e.g., @code{step}, @code{next}), @value{GDBN}
6068tells the target to step the corresponding range of instruction
6069addresses instead of issuing multiple single-steps. This speeds up
6070line stepping, particularly for remote targets. Ideally, there should
6071be no reason you would want to turn range stepping off. However, it's
6072possible that a bug in the debug info, a bug in the remote stub (for
6073remote targets), or even a bug in @value{GDBN} could make line
6074stepping behave incorrectly when target-assisted range stepping is
6075enabled. You can use the following command to turn off range stepping
6076if necessary:
6077
6078@table @code
6079@kindex set range-stepping
6080@kindex show range-stepping
6081@item set range-stepping
6082@itemx show range-stepping
6083Control whether range stepping is enabled.
6084
6085If @code{on}, and the target supports it, @value{GDBN} tells the
6086target to step a range of addresses itself, instead of issuing
6087multiple single-steps. If @code{off}, @value{GDBN} always issues
6088single-steps, even if range stepping is supported by the target. The
6089default is @code{on}.
6090
c906108c
SS
6091@end table
6092
aad1c02c
TT
6093@node Skipping Over Functions and Files
6094@section Skipping Over Functions and Files
1bfeeb0f
JL
6095@cindex skipping over functions and files
6096
6097The program you are debugging may contain some functions which are
8244c20d 6098uninteresting to debug. The @code{skip} command lets you tell @value{GDBN} to
cce0e923
DE
6099skip a function, all functions in a file or a particular function in
6100a particular file when stepping.
1bfeeb0f
JL
6101
6102For example, consider the following C function:
6103
6104@smallexample
6105101 int func()
6106102 @{
6107103 foo(boring());
6108104 bar(boring());
6109105 @}
6110@end smallexample
6111
6112@noindent
6113Suppose you wish to step into the functions @code{foo} and @code{bar}, but you
6114are not interested in stepping through @code{boring}. If you run @code{step}
6115at line 103, you'll enter @code{boring()}, but if you run @code{next}, you'll
6116step over both @code{foo} and @code{boring}!
6117
6118One solution is to @code{step} into @code{boring} and use the @code{finish}
6119command to immediately exit it. But this can become tedious if @code{boring}
6120is called from many places.
6121
6122A more flexible solution is to execute @kbd{skip boring}. This instructs
6123@value{GDBN} never to step into @code{boring}. Now when you execute
6124@code{step} at line 103, you'll step over @code{boring} and directly into
6125@code{foo}.
6126
cce0e923
DE
6127Functions may be skipped by providing either a function name, linespec
6128(@pxref{Specify Location}), regular expression that matches the function's
6129name, file name or a @code{glob}-style pattern that matches the file name.
6130
6131On Posix systems the form of the regular expression is
6132``Extended Regular Expressions''. See for example @samp{man 7 regex}
6133on @sc{gnu}/Linux systems. On non-Posix systems the form of the regular
6134expression is whatever is provided by the @code{regcomp} function of
6135the underlying system.
6136See for example @samp{man 7 glob} on @sc{gnu}/Linux systems for a
6137description of @code{glob}-style patterns.
6138
6139@table @code
6140@kindex skip
6141@item skip @r{[}@var{options}@r{]}
6142The basic form of the @code{skip} command takes zero or more options
6143that specify what to skip.
6144The @var{options} argument is any useful combination of the following:
1bfeeb0f
JL
6145
6146@table @code
cce0e923
DE
6147@item -file @var{file}
6148@itemx -fi @var{file}
6149Functions in @var{file} will be skipped over when stepping.
6150
6151@item -gfile @var{file-glob-pattern}
6152@itemx -gfi @var{file-glob-pattern}
6153@cindex skipping over files via glob-style patterns
6154Functions in files matching @var{file-glob-pattern} will be skipped
6155over when stepping.
6156
6157@smallexample
6158(gdb) skip -gfi utils/*.c
6159@end smallexample
6160
6161@item -function @var{linespec}
6162@itemx -fu @var{linespec}
6163Functions named by @var{linespec} or the function containing the line
6164named by @var{linespec} will be skipped over when stepping.
6165@xref{Specify Location}.
6166
6167@item -rfunction @var{regexp}
6168@itemx -rfu @var{regexp}
6169@cindex skipping over functions via regular expressions
6170Functions whose name matches @var{regexp} will be skipped over when stepping.
6171
6172This form is useful for complex function names.
6173For example, there is generally no need to step into C@t{++} @code{std::string}
6174constructors or destructors. Plus with C@t{++} templates it can be hard to
6175write out the full name of the function, and often it doesn't matter what
6176the template arguments are. Specifying the function to be skipped as a
6177regular expression makes this easier.
6178
6179@smallexample
6180(gdb) skip -rfu ^std::(allocator|basic_string)<.*>::~?\1 *\(
6181@end smallexample
6182
6183If you want to skip every templated C@t{++} constructor and destructor
6184in the @code{std} namespace you can do:
6185
6186@smallexample
6187(gdb) skip -rfu ^std::([a-zA-z0-9_]+)<.*>::~?\1 *\(
6188@end smallexample
6189@end table
6190
6191If no options are specified, the function you're currently debugging
6192will be skipped.
6193
1bfeeb0f 6194@kindex skip function
cce0e923 6195@item skip function @r{[}@var{linespec}@r{]}
1bfeeb0f
JL
6196After running this command, the function named by @var{linespec} or the
6197function containing the line named by @var{linespec} will be skipped over when
983fb131 6198stepping. @xref{Specify Location}.
1bfeeb0f
JL
6199
6200If you do not specify @var{linespec}, the function you're currently debugging
6201will be skipped.
6202
6203(If you have a function called @code{file} that you want to skip, use
6204@kbd{skip function file}.)
6205
6206@kindex skip file
6207@item skip file @r{[}@var{filename}@r{]}
6208After running this command, any function whose source lives in @var{filename}
6209will be skipped over when stepping.
6210
cce0e923
DE
6211@smallexample
6212(gdb) skip file boring.c
6213File boring.c will be skipped when stepping.
6214@end smallexample
6215
1bfeeb0f
JL
6216If you do not specify @var{filename}, functions whose source lives in the file
6217you're currently debugging will be skipped.
6218@end table
6219
6220Skips can be listed, deleted, disabled, and enabled, much like breakpoints.
6221These are the commands for managing your list of skips:
6222
6223@table @code
6224@kindex info skip
6225@item info skip @r{[}@var{range}@r{]}
6226Print details about the specified skip(s). If @var{range} is not specified,
6227print a table with details about all functions and files marked for skipping.
6228@code{info skip} prints the following information about each skip:
6229
6230@table @emph
6231@item Identifier
6232A number identifying this skip.
1bfeeb0f 6233@item Enabled or Disabled
cce0e923
DE
6234Enabled skips are marked with @samp{y}.
6235Disabled skips are marked with @samp{n}.
6236@item Glob
6237If the file name is a @samp{glob} pattern this is @samp{y}.
6238Otherwise it is @samp{n}.
6239@item File
6240The name or @samp{glob} pattern of the file to be skipped.
6241If no file is specified this is @samp{<none>}.
6242@item RE
6243If the function name is a @samp{regular expression} this is @samp{y}.
6244Otherwise it is @samp{n}.
6245@item Function
6246The name or regular expression of the function to skip.
6247If no function is specified this is @samp{<none>}.
1bfeeb0f
JL
6248@end table
6249
6250@kindex skip delete
6251@item skip delete @r{[}@var{range}@r{]}
6252Delete the specified skip(s). If @var{range} is not specified, delete all
6253skips.
6254
6255@kindex skip enable
6256@item skip enable @r{[}@var{range}@r{]}
6257Enable the specified skip(s). If @var{range} is not specified, enable all
6258skips.
6259
6260@kindex skip disable
6261@item skip disable @r{[}@var{range}@r{]}
6262Disable the specified skip(s). If @var{range} is not specified, disable all
6263skips.
6264
3e68067f
SM
6265@kindex set debug skip
6266@item set debug skip @r{[}on|off@r{]}
6267Set whether to print the debug output about skipping files and functions.
6268
6269@kindex show debug skip
6270@item show debug skip
6271Show whether the debug output about skipping files and functions is printed.
6272
1bfeeb0f
JL
6273@end table
6274
6d2ebf8b 6275@node Signals
c906108c
SS
6276@section Signals
6277@cindex signals
6278
6279A signal is an asynchronous event that can happen in a program. The
6280operating system defines the possible kinds of signals, and gives each
6281kind a name and a number. For example, in Unix @code{SIGINT} is the
c8aa23ab 6282signal a program gets when you type an interrupt character (often @kbd{Ctrl-c});
c906108c
SS
6283@code{SIGSEGV} is the signal a program gets from referencing a place in
6284memory far away from all the areas in use; @code{SIGALRM} occurs when
6285the alarm clock timer goes off (which happens only if your program has
6286requested an alarm).
6287
6288@cindex fatal signals
6289Some signals, including @code{SIGALRM}, are a normal part of the
6290functioning of your program. Others, such as @code{SIGSEGV}, indicate
d4f3574e 6291errors; these signals are @dfn{fatal} (they kill your program immediately) if the
c906108c
SS
6292program has not specified in advance some other way to handle the signal.
6293@code{SIGINT} does not indicate an error in your program, but it is normally
6294fatal so it can carry out the purpose of the interrupt: to kill the program.
6295
6296@value{GDBN} has the ability to detect any occurrence of a signal in your
6297program. You can tell @value{GDBN} in advance what to do for each kind of
6298signal.
6299
6300@cindex handling signals
24f93129
EZ
6301Normally, @value{GDBN} is set up to let the non-erroneous signals like
6302@code{SIGALRM} be silently passed to your program
6303(so as not to interfere with their role in the program's functioning)
c906108c
SS
6304but to stop your program immediately whenever an error signal happens.
6305You can change these settings with the @code{handle} command.
6306
6307@table @code
6308@kindex info signals
09d4efe1 6309@kindex info handle
c906108c 6310@item info signals
96a2c332 6311@itemx info handle
c906108c
SS
6312Print a table of all the kinds of signals and how @value{GDBN} has been told to
6313handle each one. You can use this to see the signal numbers of all
6314the defined types of signals.
6315
45ac1734
EZ
6316@item info signals @var{sig}
6317Similar, but print information only about the specified signal number.
6318
d4f3574e 6319@code{info handle} is an alias for @code{info signals}.
c906108c 6320
ab04a2af
TT
6321@item catch signal @r{[}@var{signal}@dots{} @r{|} @samp{all}@r{]}
6322Set a catchpoint for the indicated signals. @xref{Set Catchpoints},
6323for details about this command.
6324
c906108c 6325@kindex handle
45ac1734 6326@item handle @var{signal} @r{[}@var{keywords}@dots{}@r{]}
697aa1b7 6327Change the way @value{GDBN} handles signal @var{signal}. The @var{signal}
5ece1a18 6328can be the number of a signal or its name (with or without the
24f93129 6329@samp{SIG} at the beginning); a list of signal numbers of the form
5ece1a18 6330@samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
45ac1734
EZ
6331known signals. Optional arguments @var{keywords}, described below,
6332say what change to make.
c906108c
SS
6333@end table
6334
6335@c @group
6336The keywords allowed by the @code{handle} command can be abbreviated.
6337Their full names are:
6338
6339@table @code
6340@item nostop
6341@value{GDBN} should not stop your program when this signal happens. It may
6342still print a message telling you that the signal has come in.
6343
6344@item stop
6345@value{GDBN} should stop your program when this signal happens. This implies
6346the @code{print} keyword as well.
6347
6348@item print
6349@value{GDBN} should print a message when this signal happens.
6350
6351@item noprint
6352@value{GDBN} should not mention the occurrence of the signal at all. This
6353implies the @code{nostop} keyword as well.
6354
6355@item pass
5ece1a18 6356@itemx noignore
c906108c
SS
6357@value{GDBN} should allow your program to see this signal; your program
6358can handle the signal, or else it may terminate if the signal is fatal
5ece1a18 6359and not handled. @code{pass} and @code{noignore} are synonyms.
c906108c
SS
6360
6361@item nopass
5ece1a18 6362@itemx ignore
c906108c 6363@value{GDBN} should not allow your program to see this signal.
5ece1a18 6364@code{nopass} and @code{ignore} are synonyms.
c906108c
SS
6365@end table
6366@c @end group
6367
d4f3574e
SS
6368When a signal stops your program, the signal is not visible to the
6369program until you
c906108c
SS
6370continue. Your program sees the signal then, if @code{pass} is in
6371effect for the signal in question @emph{at that time}. In other words,
6372after @value{GDBN} reports a signal, you can use the @code{handle}
6373command with @code{pass} or @code{nopass} to control whether your
6374program sees that signal when you continue.
6375
24f93129
EZ
6376The default is set to @code{nostop}, @code{noprint}, @code{pass} for
6377non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
6378@code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
6379erroneous signals.
6380
c906108c
SS
6381You can also use the @code{signal} command to prevent your program from
6382seeing a signal, or cause it to see a signal it normally would not see,
6383or to give it any signal at any time. For example, if your program stopped
6384due to some sort of memory reference error, you might store correct
6385values into the erroneous variables and continue, hoping to see more
6386execution; but your program would probably terminate immediately as
6387a result of the fatal signal once it saw the signal. To prevent this,
6388you can continue with @samp{signal 0}. @xref{Signaling, ,Giving your
79a6e687 6389Program a Signal}.
c906108c 6390
e5f8a7cc
PA
6391@cindex stepping and signal handlers
6392@anchor{stepping and signal handlers}
6393
6394@value{GDBN} optimizes for stepping the mainline code. If a signal
6395that has @code{handle nostop} and @code{handle pass} set arrives while
6396a stepping command (e.g., @code{stepi}, @code{step}, @code{next}) is
6397in progress, @value{GDBN} lets the signal handler run and then resumes
6398stepping the mainline code once the signal handler returns. In other
6399words, @value{GDBN} steps over the signal handler. This prevents
6400signals that you've specified as not interesting (with @code{handle
6401nostop}) from changing the focus of debugging unexpectedly. Note that
6402the signal handler itself may still hit a breakpoint, stop for another
6403signal that has @code{handle stop} in effect, or for any other event
6404that normally results in stopping the stepping command sooner. Also
6405note that @value{GDBN} still informs you that the program received a
6406signal if @code{handle print} is set.
6407
6408@anchor{stepping into signal handlers}
6409
6410If you set @code{handle pass} for a signal, and your program sets up a
6411handler for it, then issuing a stepping command, such as @code{step}
6412or @code{stepi}, when your program is stopped due to the signal will
6413step @emph{into} the signal handler (if the target supports that).
6414
6415Likewise, if you use the @code{queue-signal} command to queue a signal
6416to be delivered to the current thread when execution of the thread
6417resumes (@pxref{Signaling, ,Giving your Program a Signal}), then a
6418stepping command will step into the signal handler.
6419
6420Here's an example, using @code{stepi} to step to the first instruction
6421of @code{SIGUSR1}'s handler:
6422
6423@smallexample
6424(@value{GDBP}) handle SIGUSR1
6425Signal Stop Print Pass to program Description
6426SIGUSR1 Yes Yes Yes User defined signal 1
6427(@value{GDBP}) c
6428Continuing.
6429
6430Program received signal SIGUSR1, User defined signal 1.
6431main () sigusr1.c:28
643228 p = 0;
6433(@value{GDBP}) si
6434sigusr1_handler () at sigusr1.c:9
64359 @{
6436@end smallexample
6437
6438The same, but using @code{queue-signal} instead of waiting for the
6439program to receive the signal first:
6440
6441@smallexample
6442(@value{GDBP}) n
644328 p = 0;
6444(@value{GDBP}) queue-signal SIGUSR1
6445(@value{GDBP}) si
6446sigusr1_handler () at sigusr1.c:9
64479 @{
6448(@value{GDBP})
6449@end smallexample
6450
4aa995e1
PA
6451@cindex extra signal information
6452@anchor{extra signal information}
6453
6454On some targets, @value{GDBN} can inspect extra signal information
6455associated with the intercepted signal, before it is actually
6456delivered to the program being debugged. This information is exported
6457by the convenience variable @code{$_siginfo}, and consists of data
6458that is passed by the kernel to the signal handler at the time of the
6459receipt of a signal. The data type of the information itself is
6460target dependent. You can see the data type using the @code{ptype
6461$_siginfo} command. On Unix systems, it typically corresponds to the
6462standard @code{siginfo_t} type, as defined in the @file{signal.h}
6463system header.
6464
6465Here's an example, on a @sc{gnu}/Linux system, printing the stray
6466referenced address that raised a segmentation fault.
6467
6468@smallexample
6469@group
6470(@value{GDBP}) continue
6471Program received signal SIGSEGV, Segmentation fault.
64720x0000000000400766 in main ()
647369 *(int *)p = 0;
6474(@value{GDBP}) ptype $_siginfo
6475type = struct @{
6476 int si_signo;
6477 int si_errno;
6478 int si_code;
6479 union @{
6480 int _pad[28];
6481 struct @{...@} _kill;
6482 struct @{...@} _timer;
6483 struct @{...@} _rt;
6484 struct @{...@} _sigchld;
6485 struct @{...@} _sigfault;
6486 struct @{...@} _sigpoll;
6487 @} _sifields;
6488@}
6489(@value{GDBP}) ptype $_siginfo._sifields._sigfault
6490type = struct @{
6491 void *si_addr;
6492@}
6493(@value{GDBP}) p $_siginfo._sifields._sigfault.si_addr
6494$1 = (void *) 0x7ffff7ff7000
6495@end group
6496@end smallexample
6497
6498Depending on target support, @code{$_siginfo} may also be writable.
6499
012b3a21
WT
6500@cindex Intel MPX boundary violations
6501@cindex boundary violations, Intel MPX
6502On some targets, a @code{SIGSEGV} can be caused by a boundary
6503violation, i.e., accessing an address outside of the allowed range.
6504In those cases @value{GDBN} may displays additional information,
6505depending on how @value{GDBN} has been told to handle the signal.
6506With @code{handle stop SIGSEGV}, @value{GDBN} displays the violation
6507kind: "Upper" or "Lower", the memory address accessed and the
6508bounds, while with @code{handle nostop SIGSEGV} no additional
6509information is displayed.
6510
6511The usual output of a segfault is:
6512@smallexample
6513Program received signal SIGSEGV, Segmentation fault
65140x0000000000400d7c in upper () at i386-mpx-sigsegv.c:68
651568 value = *(p + len);
6516@end smallexample
6517
6518While a bound violation is presented as:
6519@smallexample
6520Program received signal SIGSEGV, Segmentation fault
6521Upper bound violation while accessing address 0x7fffffffc3b3
6522Bounds: [lower = 0x7fffffffc390, upper = 0x7fffffffc3a3]
65230x0000000000400d7c in upper () at i386-mpx-sigsegv.c:68
652468 value = *(p + len);
6525@end smallexample
6526
6d2ebf8b 6527@node Thread Stops
79a6e687 6528@section Stopping and Starting Multi-thread Programs
c906108c 6529
0606b73b
SL
6530@cindex stopped threads
6531@cindex threads, stopped
6532
6533@cindex continuing threads
6534@cindex threads, continuing
6535
6536@value{GDBN} supports debugging programs with multiple threads
6537(@pxref{Threads,, Debugging Programs with Multiple Threads}). There
6538are two modes of controlling execution of your program within the
6539debugger. In the default mode, referred to as @dfn{all-stop mode},
6540when any thread in your program stops (for example, at a breakpoint
6541or while being stepped), all other threads in the program are also stopped by
6542@value{GDBN}. On some targets, @value{GDBN} also supports
6543@dfn{non-stop mode}, in which other threads can continue to run freely while
6544you examine the stopped thread in the debugger.
6545
6546@menu
6547* All-Stop Mode:: All threads stop when GDB takes control
6548* Non-Stop Mode:: Other threads continue to execute
6549* Background Execution:: Running your program asynchronously
6550* Thread-Specific Breakpoints:: Controlling breakpoints
6551* Interrupted System Calls:: GDB may interfere with system calls
d914c394 6552* Observer Mode:: GDB does not alter program behavior
0606b73b
SL
6553@end menu
6554
6555@node All-Stop Mode
6556@subsection All-Stop Mode
6557
6558@cindex all-stop mode
6559
6560In all-stop mode, whenever your program stops under @value{GDBN} for any reason,
6561@emph{all} threads of execution stop, not just the current thread. This
6562allows you to examine the overall state of the program, including
6563switching between threads, without worrying that things may change
6564underfoot.
6565
6566Conversely, whenever you restart the program, @emph{all} threads start
6567executing. @emph{This is true even when single-stepping} with commands
6568like @code{step} or @code{next}.
6569
6570In particular, @value{GDBN} cannot single-step all threads in lockstep.
6571Since thread scheduling is up to your debugging target's operating
6572system (not controlled by @value{GDBN}), other threads may
6573execute more than one statement while the current thread completes a
6574single step. Moreover, in general other threads stop in the middle of a
6575statement, rather than at a clean statement boundary, when the program
6576stops.
6577
6578You might even find your program stopped in another thread after
6579continuing or even single-stepping. This happens whenever some other
6580thread runs into a breakpoint, a signal, or an exception before the
6581first thread completes whatever you requested.
6582
6583@cindex automatic thread selection
6584@cindex switching threads automatically
6585@cindex threads, automatic switching
6586Whenever @value{GDBN} stops your program, due to a breakpoint or a
6587signal, it automatically selects the thread where that breakpoint or
6588signal happened. @value{GDBN} alerts you to the context switch with a
6589message such as @samp{[Switching to Thread @var{n}]} to identify the
6590thread.
6591
6592On some OSes, you can modify @value{GDBN}'s default behavior by
6593locking the OS scheduler to allow only a single thread to run.
6594
6595@table @code
6596@item set scheduler-locking @var{mode}
6597@cindex scheduler locking mode
6598@cindex lock scheduler
f2665db5
MM
6599Set the scheduler locking mode. It applies to normal execution,
6600record mode, and replay mode. If it is @code{off}, then there is no
6601locking and any thread may run at any time. If @code{on}, then only
6602the current thread may run when the inferior is resumed. The
6603@code{step} mode optimizes for single-stepping; it prevents other
6604threads from preempting the current thread while you are stepping, so
6605that the focus of debugging does not change unexpectedly. Other
6606threads never get a chance to run when you step, and they are
6607completely free to run when you use commands like @samp{continue},
6608@samp{until}, or @samp{finish}. However, unless another thread hits a
6609breakpoint during its timeslice, @value{GDBN} does not change the
6610current thread away from the thread that you are debugging. The
6611@code{replay} mode behaves like @code{off} in record mode and like
6612@code{on} in replay mode.
0606b73b
SL
6613
6614@item show scheduler-locking
6615Display the current scheduler locking mode.
6616@end table
6617
d4db2f36
PA
6618@cindex resume threads of multiple processes simultaneously
6619By default, when you issue one of the execution commands such as
6620@code{continue}, @code{next} or @code{step}, @value{GDBN} allows only
6621threads of the current inferior to run. For example, if @value{GDBN}
6622is attached to two inferiors, each with two threads, the
6623@code{continue} command resumes only the two threads of the current
6624inferior. This is useful, for example, when you debug a program that
6625forks and you want to hold the parent stopped (so that, for instance,
6626it doesn't run to exit), while you debug the child. In other
6627situations, you may not be interested in inspecting the current state
6628of any of the processes @value{GDBN} is attached to, and you may want
6629to resume them all until some breakpoint is hit. In the latter case,
6630you can instruct @value{GDBN} to allow all threads of all the
6631inferiors to run with the @w{@code{set schedule-multiple}} command.
6632
6633@table @code
6634@kindex set schedule-multiple
6635@item set schedule-multiple
6636Set the mode for allowing threads of multiple processes to be resumed
6637when an execution command is issued. When @code{on}, all threads of
6638all processes are allowed to run. When @code{off}, only the threads
6639of the current process are resumed. The default is @code{off}. The
6640@code{scheduler-locking} mode takes precedence when set to @code{on},
6641or while you are stepping and set to @code{step}.
6642
6643@item show schedule-multiple
6644Display the current mode for resuming the execution of threads of
6645multiple processes.
6646@end table
6647
0606b73b
SL
6648@node Non-Stop Mode
6649@subsection Non-Stop Mode
6650
6651@cindex non-stop mode
6652
6653@c This section is really only a place-holder, and needs to be expanded
97d8f0ee 6654@c with more details.
0606b73b
SL
6655
6656For some multi-threaded targets, @value{GDBN} supports an optional
6657mode of operation in which you can examine stopped program threads in
6658the debugger while other threads continue to execute freely. This
97d8f0ee
DE
6659minimizes intrusion when debugging live systems, such as programs
6660where some threads have real-time constraints or must continue to
0606b73b
SL
6661respond to external events. This is referred to as @dfn{non-stop} mode.
6662
6663In non-stop mode, when a thread stops to report a debugging event,
6664@emph{only} that thread is stopped; @value{GDBN} does not stop other
6665threads as well, in contrast to the all-stop mode behavior. Additionally,
6666execution commands such as @code{continue} and @code{step} apply by default
6667only to the current thread in non-stop mode, rather than all threads as
6668in all-stop mode. This allows you to control threads explicitly in
97d8f0ee 6669ways that are not possible in all-stop mode --- for example, stepping
0606b73b 6670one thread while allowing others to run freely, stepping
97d8f0ee 6671one thread while holding all others stopped, or stepping several threads
0606b73b
SL
6672independently and simultaneously.
6673
6674To enter non-stop mode, use this sequence of commands before you run
6675or attach to your program:
6676
0606b73b 6677@smallexample
0606b73b
SL
6678# If using the CLI, pagination breaks non-stop.
6679set pagination off
6680
6681# Finally, turn it on!
6682set non-stop on
6683@end smallexample
6684
6685You can use these commands to manipulate the non-stop mode setting:
6686
6687@table @code
6688@kindex set non-stop
6689@item set non-stop on
6690Enable selection of non-stop mode.
6691@item set non-stop off
6692Disable selection of non-stop mode.
6693@kindex show non-stop
6694@item show non-stop
6695Show the current non-stop enablement setting.
6696@end table
6697
6698Note these commands only reflect whether non-stop mode is enabled,
97d8f0ee 6699not whether the currently-executing program is being run in non-stop mode.
0606b73b 6700In particular, the @code{set non-stop} preference is only consulted when
97d8f0ee 6701@value{GDBN} starts or connects to the target program, and it is generally
0606b73b
SL
6702not possible to switch modes once debugging has started. Furthermore,
6703since not all targets support non-stop mode, even when you have enabled
6704non-stop mode, @value{GDBN} may still fall back to all-stop operation by
6705default.
6706
6707In non-stop mode, all execution commands apply only to the current thread
97d8f0ee 6708by default. That is, @code{continue} only continues one thread.
0606b73b
SL
6709To continue all threads, issue @code{continue -a} or @code{c -a}.
6710
97d8f0ee 6711You can use @value{GDBN}'s background execution commands
0606b73b 6712(@pxref{Background Execution}) to run some threads in the background
97d8f0ee 6713while you continue to examine or step others from @value{GDBN}.
0606b73b
SL
6714The MI execution commands (@pxref{GDB/MI Program Execution}) are
6715always executed asynchronously in non-stop mode.
6716
6717Suspending execution is done with the @code{interrupt} command when
97d8f0ee
DE
6718running in the background, or @kbd{Ctrl-c} during foreground execution.
6719In all-stop mode, this stops the whole process;
6720but in non-stop mode the interrupt applies only to the current thread.
0606b73b
SL
6721To stop the whole program, use @code{interrupt -a}.
6722
6723Other execution commands do not currently support the @code{-a} option.
6724
6725In non-stop mode, when a thread stops, @value{GDBN} doesn't automatically make
6726that thread current, as it does in all-stop mode. This is because the
97d8f0ee 6727thread stop notifications are asynchronous with respect to @value{GDBN}'s
0606b73b
SL
6728command interpreter, and it would be confusing if @value{GDBN} unexpectedly
6729changed to a different thread just as you entered a command to operate on the
6730previously current thread.
6731
6732@node Background Execution
6733@subsection Background Execution
6734
6735@cindex foreground execution
6736@cindex background execution
6737@cindex asynchronous execution
6738@cindex execution, foreground, background and asynchronous
6739
6740@value{GDBN}'s execution commands have two variants: the normal
6741foreground (synchronous) behavior, and a background
97d8f0ee 6742(asynchronous) behavior. In foreground execution, @value{GDBN} waits for
0606b73b
SL
6743the program to report that some thread has stopped before prompting for
6744another command. In background execution, @value{GDBN} immediately gives
6745a command prompt so that you can issue other commands while your program runs.
6746
32fc0df9
PA
6747If the target doesn't support async mode, @value{GDBN} issues an error
6748message if you attempt to use the background execution commands.
6749
74fdb8ff 6750@cindex @code{&}, background execution of commands
0606b73b
SL
6751To specify background execution, add a @code{&} to the command. For example,
6752the background form of the @code{continue} command is @code{continue&}, or
6753just @code{c&}. The execution commands that accept background execution
6754are:
6755
6756@table @code
6757@kindex run&
6758@item run
6759@xref{Starting, , Starting your Program}.
6760
6761@item attach
6762@kindex attach&
6763@xref{Attach, , Debugging an Already-running Process}.
6764
6765@item step
6766@kindex step&
6767@xref{Continuing and Stepping, step}.
6768
6769@item stepi
6770@kindex stepi&
6771@xref{Continuing and Stepping, stepi}.
6772
6773@item next
6774@kindex next&
6775@xref{Continuing and Stepping, next}.
6776
7ce58dd2
DE
6777@item nexti
6778@kindex nexti&
6779@xref{Continuing and Stepping, nexti}.
6780
0606b73b
SL
6781@item continue
6782@kindex continue&
6783@xref{Continuing and Stepping, continue}.
6784
6785@item finish
6786@kindex finish&
6787@xref{Continuing and Stepping, finish}.
6788
6789@item until
6790@kindex until&
6791@xref{Continuing and Stepping, until}.
6792
6793@end table
6794
6795Background execution is especially useful in conjunction with non-stop
6796mode for debugging programs with multiple threads; see @ref{Non-Stop Mode}.
6797However, you can also use these commands in the normal all-stop mode with
6798the restriction that you cannot issue another execution command until the
6799previous one finishes. Examples of commands that are valid in all-stop
6800mode while the program is running include @code{help} and @code{info break}.
6801
6802You can interrupt your program while it is running in the background by
6803using the @code{interrupt} command.
6804
6805@table @code
6806@kindex interrupt
6807@item interrupt
6808@itemx interrupt -a
6809
97d8f0ee 6810Suspend execution of the running program. In all-stop mode,
0606b73b 6811@code{interrupt} stops the whole process, but in non-stop mode, it stops
97d8f0ee 6812only the current thread. To stop the whole program in non-stop mode,
0606b73b
SL
6813use @code{interrupt -a}.
6814@end table
6815
0606b73b
SL
6816@node Thread-Specific Breakpoints
6817@subsection Thread-Specific Breakpoints
6818
c906108c 6819When your program has multiple threads (@pxref{Threads,, Debugging
79a6e687 6820Programs with Multiple Threads}), you can choose whether to set
c906108c
SS
6821breakpoints on all threads, or on a particular thread.
6822
6823@table @code
6824@cindex breakpoints and threads
6825@cindex thread breakpoints
5d5658a1
PA
6826@kindex break @dots{} thread @var{thread-id}
6827@item break @var{location} thread @var{thread-id}
6828@itemx break @var{location} thread @var{thread-id} if @dots{}
629500fa 6829@var{location} specifies source lines; there are several ways of
2a25a5ba
EZ
6830writing them (@pxref{Specify Location}), but the effect is always to
6831specify some source line.
c906108c 6832
5d5658a1 6833Use the qualifier @samp{thread @var{thread-id}} with a breakpoint command
c906108c 6834to specify that you only want @value{GDBN} to stop the program when a
5d5658a1
PA
6835particular thread reaches this breakpoint. The @var{thread-id} specifier
6836is one of the thread identifiers assigned by @value{GDBN}, shown
697aa1b7 6837in the first column of the @samp{info threads} display.
c906108c 6838
5d5658a1 6839If you do not specify @samp{thread @var{thread-id}} when you set a
c906108c
SS
6840breakpoint, the breakpoint applies to @emph{all} threads of your
6841program.
6842
6843You can use the @code{thread} qualifier on conditional breakpoints as
5d5658a1 6844well; in this case, place @samp{thread @var{thread-id}} before or
b6199126 6845after the breakpoint condition, like this:
c906108c
SS
6846
6847@smallexample
2df3850c 6848(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
c906108c
SS
6849@end smallexample
6850
6851@end table
6852
f4fb82a1
PA
6853Thread-specific breakpoints are automatically deleted when
6854@value{GDBN} detects the corresponding thread is no longer in the
6855thread list. For example:
6856
6857@smallexample
6858(@value{GDBP}) c
6859Thread-specific breakpoint 3 deleted - thread 28 no longer in the thread list.
6860@end smallexample
6861
6862There are several ways for a thread to disappear, such as a regular
6863thread exit, but also when you detach from the process with the
6864@code{detach} command (@pxref{Attach, ,Debugging an Already-running
6865Process}), or if @value{GDBN} loses the remote connection
6866(@pxref{Remote Debugging}), etc. Note that with some targets,
6867@value{GDBN} is only able to detect a thread has exited when the user
6868explictly asks for the thread list with the @code{info threads}
6869command.
6870
0606b73b
SL
6871@node Interrupted System Calls
6872@subsection Interrupted System Calls
c906108c 6873
36d86913
MC
6874@cindex thread breakpoints and system calls
6875@cindex system calls and thread breakpoints
6876@cindex premature return from system calls
0606b73b
SL
6877There is an unfortunate side effect when using @value{GDBN} to debug
6878multi-threaded programs. If one thread stops for a
36d86913
MC
6879breakpoint, or for some other reason, and another thread is blocked in a
6880system call, then the system call may return prematurely. This is a
6881consequence of the interaction between multiple threads and the signals
6882that @value{GDBN} uses to implement breakpoints and other events that
6883stop execution.
6884
6885To handle this problem, your program should check the return value of
6886each system call and react appropriately. This is good programming
6887style anyways.
6888
6889For example, do not write code like this:
6890
6891@smallexample
6892 sleep (10);
6893@end smallexample
6894
6895The call to @code{sleep} will return early if a different thread stops
6896at a breakpoint or for some other reason.
6897
6898Instead, write this:
6899
6900@smallexample
6901 int unslept = 10;
6902 while (unslept > 0)
6903 unslept = sleep (unslept);
6904@end smallexample
6905
6906A system call is allowed to return early, so the system is still
6907conforming to its specification. But @value{GDBN} does cause your
6908multi-threaded program to behave differently than it would without
6909@value{GDBN}.
6910
6911Also, @value{GDBN} uses internal breakpoints in the thread library to
6912monitor certain events such as thread creation and thread destruction.
6913When such an event happens, a system call in another thread may return
6914prematurely, even though your program does not appear to stop.
6915
d914c394
SS
6916@node Observer Mode
6917@subsection Observer Mode
6918
6919If you want to build on non-stop mode and observe program behavior
6920without any chance of disruption by @value{GDBN}, you can set
6921variables to disable all of the debugger's attempts to modify state,
6922whether by writing memory, inserting breakpoints, etc. These operate
6923at a low level, intercepting operations from all commands.
6924
6925When all of these are set to @code{off}, then @value{GDBN} is said to
6926be @dfn{observer mode}. As a convenience, the variable
6927@code{observer} can be set to disable these, plus enable non-stop
6928mode.
6929
6930Note that @value{GDBN} will not prevent you from making nonsensical
6931combinations of these settings. For instance, if you have enabled
6932@code{may-insert-breakpoints} but disabled @code{may-write-memory},
6933then breakpoints that work by writing trap instructions into the code
6934stream will still not be able to be placed.
6935
6936@table @code
6937
6938@kindex observer
6939@item set observer on
6940@itemx set observer off
6941When set to @code{on}, this disables all the permission variables
6942below (except for @code{insert-fast-tracepoints}), plus enables
6943non-stop debugging. Setting this to @code{off} switches back to
6944normal debugging, though remaining in non-stop mode.
6945
6946@item show observer
6947Show whether observer mode is on or off.
6948
6949@kindex may-write-registers
6950@item set may-write-registers on
6951@itemx set may-write-registers off
6952This controls whether @value{GDBN} will attempt to alter the values of
6953registers, such as with assignment expressions in @code{print}, or the
6954@code{jump} command. It defaults to @code{on}.
6955
6956@item show may-write-registers
6957Show the current permission to write registers.
6958
6959@kindex may-write-memory
6960@item set may-write-memory on
6961@itemx set may-write-memory off
6962This controls whether @value{GDBN} will attempt to alter the contents
6963of memory, such as with assignment expressions in @code{print}. It
6964defaults to @code{on}.
6965
6966@item show may-write-memory
6967Show the current permission to write memory.
6968
6969@kindex may-insert-breakpoints
6970@item set may-insert-breakpoints on
6971@itemx set may-insert-breakpoints off
6972This controls whether @value{GDBN} will attempt to insert breakpoints.
6973This affects all breakpoints, including internal breakpoints defined
6974by @value{GDBN}. It defaults to @code{on}.
6975
6976@item show may-insert-breakpoints
6977Show the current permission to insert breakpoints.
6978
6979@kindex may-insert-tracepoints
6980@item set may-insert-tracepoints on
6981@itemx set may-insert-tracepoints off
6982This controls whether @value{GDBN} will attempt to insert (regular)
6983tracepoints at the beginning of a tracing experiment. It affects only
6984non-fast tracepoints, fast tracepoints being under the control of
6985@code{may-insert-fast-tracepoints}. It defaults to @code{on}.
6986
6987@item show may-insert-tracepoints
6988Show the current permission to insert tracepoints.
6989
6990@kindex may-insert-fast-tracepoints
6991@item set may-insert-fast-tracepoints on
6992@itemx set may-insert-fast-tracepoints off
6993This controls whether @value{GDBN} will attempt to insert fast
6994tracepoints at the beginning of a tracing experiment. It affects only
6995fast tracepoints, regular (non-fast) tracepoints being under the
6996control of @code{may-insert-tracepoints}. It defaults to @code{on}.
6997
6998@item show may-insert-fast-tracepoints
6999Show the current permission to insert fast tracepoints.
7000
7001@kindex may-interrupt
7002@item set may-interrupt on
7003@itemx set may-interrupt off
7004This controls whether @value{GDBN} will attempt to interrupt or stop
7005program execution. When this variable is @code{off}, the
7006@code{interrupt} command will have no effect, nor will
7007@kbd{Ctrl-c}. It defaults to @code{on}.
7008
7009@item show may-interrupt
7010Show the current permission to interrupt or stop the program.
7011
7012@end table
c906108c 7013
bacec72f
MS
7014@node Reverse Execution
7015@chapter Running programs backward
7016@cindex reverse execution
7017@cindex running programs backward
7018
7019When you are debugging a program, it is not unusual to realize that
7020you have gone too far, and some event of interest has already happened.
7021If the target environment supports it, @value{GDBN} can allow you to
7022``rewind'' the program by running it backward.
7023
7024A target environment that supports reverse execution should be able
7025to ``undo'' the changes in machine state that have taken place as the
7026program was executing normally. Variables, registers etc.@: should
7027revert to their previous values. Obviously this requires a great
7028deal of sophistication on the part of the target environment; not
7029all target environments can support reverse execution.
7030
7031When a program is executed in reverse, the instructions that
7032have most recently been executed are ``un-executed'', in reverse
7033order. The program counter runs backward, following the previous
7034thread of execution in reverse. As each instruction is ``un-executed'',
7035the values of memory and/or registers that were changed by that
7036instruction are reverted to their previous states. After executing
7037a piece of source code in reverse, all side effects of that code
7038should be ``undone'', and all variables should be returned to their
7039prior values@footnote{
7040Note that some side effects are easier to undo than others. For instance,
7041memory and registers are relatively easy, but device I/O is hard. Some
7042targets may be able undo things like device I/O, and some may not.
7043
7044The contract between @value{GDBN} and the reverse executing target
7045requires only that the target do something reasonable when
7046@value{GDBN} tells it to execute backwards, and then report the
7047results back to @value{GDBN}. Whatever the target reports back to
7048@value{GDBN}, @value{GDBN} will report back to the user. @value{GDBN}
7049assumes that the memory and registers that the target reports are in a
6b92c0d3 7050consistent state, but @value{GDBN} accepts whatever it is given.
bacec72f
MS
7051}.
7052
73f8a590
PA
7053On some platforms, @value{GDBN} has built-in support for reverse
7054execution, activated with the @code{record} or @code{record btrace}
7055commands. @xref{Process Record and Replay}. Some remote targets,
7056typically full system emulators, support reverse execution directly
7057without requiring any special command.
7058
bacec72f
MS
7059If you are debugging in a target environment that supports
7060reverse execution, @value{GDBN} provides the following commands.
7061
7062@table @code
7063@kindex reverse-continue
7064@kindex rc @r{(@code{reverse-continue})}
7065@item reverse-continue @r{[}@var{ignore-count}@r{]}
7066@itemx rc @r{[}@var{ignore-count}@r{]}
7067Beginning at the point where your program last stopped, start executing
7068in reverse. Reverse execution will stop for breakpoints and synchronous
7069exceptions (signals), just like normal execution. Behavior of
7070asynchronous signals depends on the target environment.
7071
7072@kindex reverse-step
7073@kindex rs @r{(@code{step})}
7074@item reverse-step @r{[}@var{count}@r{]}
7075Run the program backward until control reaches the start of a
7076different source line; then stop it, and return control to @value{GDBN}.
7077
7078Like the @code{step} command, @code{reverse-step} will only stop
7079at the beginning of a source line. It ``un-executes'' the previously
7080executed source line. If the previous source line included calls to
7081debuggable functions, @code{reverse-step} will step (backward) into
7082the called function, stopping at the beginning of the @emph{last}
7083statement in the called function (typically a return statement).
7084
7085Also, as with the @code{step} command, if non-debuggable functions are
7086called, @code{reverse-step} will run thru them backward without stopping.
7087
7088@kindex reverse-stepi
7089@kindex rsi @r{(@code{reverse-stepi})}
7090@item reverse-stepi @r{[}@var{count}@r{]}
7091Reverse-execute one machine instruction. Note that the instruction
7092to be reverse-executed is @emph{not} the one pointed to by the program
7093counter, but the instruction executed prior to that one. For instance,
7094if the last instruction was a jump, @code{reverse-stepi} will take you
7095back from the destination of the jump to the jump instruction itself.
7096
7097@kindex reverse-next
7098@kindex rn @r{(@code{reverse-next})}
7099@item reverse-next @r{[}@var{count}@r{]}
7100Run backward to the beginning of the previous line executed in
7101the current (innermost) stack frame. If the line contains function
7102calls, they will be ``un-executed'' without stopping. Starting from
7103the first line of a function, @code{reverse-next} will take you back
7104to the caller of that function, @emph{before} the function was called,
7105just as the normal @code{next} command would take you from the last
7106line of a function back to its return to its caller
16af530a 7107@footnote{Unless the code is too heavily optimized.}.
bacec72f
MS
7108
7109@kindex reverse-nexti
7110@kindex rni @r{(@code{reverse-nexti})}
7111@item reverse-nexti @r{[}@var{count}@r{]}
7112Like @code{nexti}, @code{reverse-nexti} executes a single instruction
7113in reverse, except that called functions are ``un-executed'' atomically.
7114That is, if the previously executed instruction was a return from
540aa8e7 7115another function, @code{reverse-nexti} will continue to execute
bacec72f
MS
7116in reverse until the call to that function (from the current stack
7117frame) is reached.
7118
7119@kindex reverse-finish
7120@item reverse-finish
7121Just as the @code{finish} command takes you to the point where the
7122current function returns, @code{reverse-finish} takes you to the point
7123where it was called. Instead of ending up at the end of the current
7124function invocation, you end up at the beginning.
7125
7126@kindex set exec-direction
7127@item set exec-direction
7128Set the direction of target execution.
984359d2 7129@item set exec-direction reverse
bacec72f
MS
7130@cindex execute forward or backward in time
7131@value{GDBN} will perform all execution commands in reverse, until the
7132exec-direction mode is changed to ``forward''. Affected commands include
7133@code{step, stepi, next, nexti, continue, and finish}. The @code{return}
7134command cannot be used in reverse mode.
7135@item set exec-direction forward
7136@value{GDBN} will perform all execution commands in the normal fashion.
7137This is the default.
7138@end table
7139
c906108c 7140
a2311334
EZ
7141@node Process Record and Replay
7142@chapter Recording Inferior's Execution and Replaying It
53cc454a
HZ
7143@cindex process record and replay
7144@cindex recording inferior's execution and replaying it
7145
8e05493c
EZ
7146On some platforms, @value{GDBN} provides a special @dfn{process record
7147and replay} target that can record a log of the process execution, and
7148replay it later with both forward and reverse execution commands.
a2311334
EZ
7149
7150@cindex replay mode
7151When this target is in use, if the execution log includes the record
7152for the next instruction, @value{GDBN} will debug in @dfn{replay
7153mode}. In the replay mode, the inferior does not really execute code
7154instructions. Instead, all the events that normally happen during
7155code execution are taken from the execution log. While code is not
7156really executed in replay mode, the values of registers (including the
7157program counter register) and the memory of the inferior are still
8e05493c
EZ
7158changed as they normally would. Their contents are taken from the
7159execution log.
a2311334
EZ
7160
7161@cindex record mode
7162If the record for the next instruction is not in the execution log,
7163@value{GDBN} will debug in @dfn{record mode}. In this mode, the
7164inferior executes normally, and @value{GDBN} records the execution log
7165for future replay.
7166
8e05493c
EZ
7167The process record and replay target supports reverse execution
7168(@pxref{Reverse Execution}), even if the platform on which the
7169inferior runs does not. However, the reverse execution is limited in
7170this case by the range of the instructions recorded in the execution
7171log. In other words, reverse execution on platforms that don't
7172support it directly can only be done in the replay mode.
7173
7174When debugging in the reverse direction, @value{GDBN} will work in
7175replay mode as long as the execution log includes the record for the
7176previous instruction; otherwise, it will work in record mode, if the
7177platform supports reverse execution, or stop if not.
7178
73f8a590
PA
7179Currently, process record and replay is supported on ARM, Aarch64,
7180Moxie, PowerPC, PowerPC64, S/390, and x86 (i386/amd64) running
7181GNU/Linux. Process record and replay can be used both when native
7182debugging, and when remote debugging via @code{gdbserver}.
7183
a2311334
EZ
7184For architecture environments that support process record and replay,
7185@value{GDBN} provides the following commands:
53cc454a
HZ
7186
7187@table @code
7188@kindex target record
59ea5688
MM
7189@kindex target record-full
7190@kindex target record-btrace
53cc454a 7191@kindex record
59ea5688
MM
7192@kindex record full
7193@kindex record btrace
f4abbc16 7194@kindex record btrace bts
b20a6524 7195@kindex record btrace pt
f4abbc16 7196@kindex record bts
b20a6524 7197@kindex record pt
53cc454a 7198@kindex rec
59ea5688
MM
7199@kindex rec full
7200@kindex rec btrace
f4abbc16 7201@kindex rec btrace bts
b20a6524 7202@kindex rec btrace pt
f4abbc16 7203@kindex rec bts
b20a6524 7204@kindex rec pt
59ea5688
MM
7205@item record @var{method}
7206This command starts the process record and replay target. The
7207recording method can be specified as parameter. Without a parameter
7208the command uses the @code{full} recording method. The following
7209recording methods are available:
a2311334 7210
59ea5688
MM
7211@table @code
7212@item full
7213Full record/replay recording using @value{GDBN}'s software record and
7214replay implementation. This method allows replaying and reverse
7215execution.
7216
f4abbc16 7217@item btrace @var{format}
73f8a590
PA
7218Hardware-supported instruction recording, supported on Intel
7219processors. This method does not record data. Further, the data is
7220collected in a ring buffer so old data will be overwritten when the
7221buffer is full. It allows limited reverse execution. Variables and
7222registers are not available during reverse execution. In remote
7223debugging, recording continues on disconnect. Recorded data can be
7224inspected after reconnecting. The recording may be stopped using
7225@code{record stop}.
59ea5688 7226
f4abbc16
MM
7227The recording format can be specified as parameter. Without a parameter
7228the command chooses the recording format. The following recording
7229formats are available:
7230
7231@table @code
7232@item bts
7233@cindex branch trace store
7234Use the @dfn{Branch Trace Store} (@acronym{BTS}) recording format. In
7235this format, the processor stores a from/to record for each executed
7236branch in the btrace ring buffer.
b20a6524
MM
7237
7238@item pt
bc504a31
PA
7239@cindex Intel Processor Trace
7240Use the @dfn{Intel Processor Trace} recording format. In this
b20a6524
MM
7241format, the processor stores the execution trace in a compressed form
7242that is afterwards decoded by @value{GDBN}.
7243
7244The trace can be recorded with very low overhead. The compressed
7245trace format also allows small trace buffers to already contain a big
7246number of instructions compared to @acronym{BTS}.
7247
7248Decoding the recorded execution trace, on the other hand, is more
7249expensive than decoding @acronym{BTS} trace. This is mostly due to the
7250increased number of instructions to process. You should increase the
7251buffer-size with care.
f4abbc16
MM
7252@end table
7253
7254Not all recording formats may be available on all processors.
59ea5688
MM
7255@end table
7256
7257The process record and replay target can only debug a process that is
7258already running. Therefore, you need first to start the process with
7259the @kbd{run} or @kbd{start} commands, and then start the recording
7260with the @kbd{record @var{method}} command.
7261
a2311334
EZ
7262@cindex displaced stepping, and process record and replay
7263Displaced stepping (@pxref{Maintenance Commands,, displaced stepping})
7264will be automatically disabled when process record and replay target
7265is started. That's because the process record and replay target
7266doesn't support displaced stepping.
7267
7268@cindex non-stop mode, and process record and replay
7269@cindex asynchronous execution, and process record and replay
7270If the inferior is in the non-stop mode (@pxref{Non-Stop Mode}) or in
59ea5688
MM
7271the asynchronous execution mode (@pxref{Background Execution}), not
7272all recording methods are available. The @code{full} recording method
7273does not support these two modes.
53cc454a
HZ
7274
7275@kindex record stop
7276@kindex rec s
7277@item record stop
a2311334
EZ
7278Stop the process record and replay target. When process record and
7279replay target stops, the entire execution log will be deleted and the
7280inferior will either be terminated, or will remain in its final state.
53cc454a 7281
a2311334
EZ
7282When you stop the process record and replay target in record mode (at
7283the end of the execution log), the inferior will be stopped at the
7284next instruction that would have been recorded. In other words, if
7285you record for a while and then stop recording, the inferior process
7286will be left in the same state as if the recording never happened.
53cc454a 7287
a2311334
EZ
7288On the other hand, if the process record and replay target is stopped
7289while in replay mode (that is, not at the end of the execution log,
7290but at some earlier point), the inferior process will become ``live''
7291at that earlier state, and it will then be possible to continue the
7292usual ``live'' debugging of the process from that state.
53cc454a 7293
a2311334
EZ
7294When the inferior process exits, or @value{GDBN} detaches from it,
7295process record and replay target will automatically stop itself.
53cc454a 7296
742ce053
MM
7297@kindex record goto
7298@item record goto
7299Go to a specific location in the execution log. There are several
7300ways to specify the location to go to:
7301
7302@table @code
7303@item record goto begin
7304@itemx record goto start
7305Go to the beginning of the execution log.
7306
7307@item record goto end
7308Go to the end of the execution log.
7309
7310@item record goto @var{n}
7311Go to instruction number @var{n} in the execution log.
7312@end table
7313
24e933df
HZ
7314@kindex record save
7315@item record save @var{filename}
7316Save the execution log to a file @file{@var{filename}}.
7317Default filename is @file{gdb_record.@var{process_id}}, where
7318@var{process_id} is the process ID of the inferior.
7319
59ea5688
MM
7320This command may not be available for all recording methods.
7321
24e933df
HZ
7322@kindex record restore
7323@item record restore @var{filename}
7324Restore the execution log from a file @file{@var{filename}}.
7325File must have been created with @code{record save}.
7326
59ea5688
MM
7327@kindex set record full
7328@item set record full insn-number-max @var{limit}
f81d1120 7329@itemx set record full insn-number-max unlimited
59ea5688
MM
7330Set the limit of instructions to be recorded for the @code{full}
7331recording method. Default value is 200000.
53cc454a 7332
a2311334
EZ
7333If @var{limit} is a positive number, then @value{GDBN} will start
7334deleting instructions from the log once the number of the record
7335instructions becomes greater than @var{limit}. For every new recorded
7336instruction, @value{GDBN} will delete the earliest recorded
7337instruction to keep the number of recorded instructions at the limit.
7338(Since deleting recorded instructions loses information, @value{GDBN}
7339lets you control what happens when the limit is reached, by means of
7340the @code{stop-at-limit} option, described below.)
53cc454a 7341
f81d1120
PA
7342If @var{limit} is @code{unlimited} or zero, @value{GDBN} will never
7343delete recorded instructions from the execution log. The number of
7344recorded instructions is limited only by the available memory.
53cc454a 7345
59ea5688
MM
7346@kindex show record full
7347@item show record full insn-number-max
7348Show the limit of instructions to be recorded with the @code{full}
7349recording method.
53cc454a 7350
59ea5688
MM
7351@item set record full stop-at-limit
7352Control the behavior of the @code{full} recording method when the
7353number of recorded instructions reaches the limit. If ON (the
7354default), @value{GDBN} will stop when the limit is reached for the
7355first time and ask you whether you want to stop the inferior or
7356continue running it and recording the execution log. If you decide
7357to continue recording, each new recorded instruction will cause the
7358oldest one to be deleted.
53cc454a 7359
a2311334
EZ
7360If this option is OFF, @value{GDBN} will automatically delete the
7361oldest record to make room for each new one, without asking.
53cc454a 7362
59ea5688 7363@item show record full stop-at-limit
a2311334 7364Show the current setting of @code{stop-at-limit}.
53cc454a 7365
59ea5688 7366@item set record full memory-query
bb08c432 7367Control the behavior when @value{GDBN} is unable to record memory
59ea5688
MM
7368changes caused by an instruction for the @code{full} recording method.
7369If ON, @value{GDBN} will query whether to stop the inferior in that
7370case.
bb08c432
HZ
7371
7372If this option is OFF (the default), @value{GDBN} will automatically
7373ignore the effect of such instructions on memory. Later, when
7374@value{GDBN} replays this execution log, it will mark the log of this
7375instruction as not accessible, and it will not affect the replay
7376results.
7377
59ea5688 7378@item show record full memory-query
bb08c432
HZ
7379Show the current setting of @code{memory-query}.
7380
67b5c0c1
MM
7381@kindex set record btrace
7382The @code{btrace} record target does not trace data. As a
7383convenience, when replaying, @value{GDBN} reads read-only memory off
7384the live program directly, assuming that the addresses of the
7385read-only areas don't change. This for example makes it possible to
7386disassemble code while replaying, but not to print variables.
7387In some cases, being able to inspect variables might be useful.
7388You can use the following command for that:
7389
7390@item set record btrace replay-memory-access
7391Control the behavior of the @code{btrace} recording method when
7392accessing memory during replay. If @code{read-only} (the default),
7393@value{GDBN} will only allow accesses to read-only memory.
7394If @code{read-write}, @value{GDBN} will allow accesses to read-only
7395and to read-write memory. Beware that the accessed memory corresponds
7396to the live target and not necessarily to the current replay
7397position.
7398
4a4495d6
MM
7399@item set record btrace cpu @var{identifier}
7400Set the processor to be used for enabling workarounds for processor
7401errata when decoding the trace.
7402
7403Processor errata are defects in processor operation, caused by its
7404design or manufacture. They can cause a trace not to match the
7405specification. This, in turn, may cause trace decode to fail.
7406@value{GDBN} can detect erroneous trace packets and correct them, thus
7407avoiding the decoding failures. These corrections are known as
7408@dfn{errata workarounds}, and are enabled based on the processor on
7409which the trace was recorded.
7410
7411By default, @value{GDBN} attempts to detect the processor
7412automatically, and apply the necessary workarounds for it. However,
7413you may need to specify the processor if @value{GDBN} does not yet
7414support it. This command allows you to do that, and also allows to
7415disable the workarounds.
7416
7417The argument @var{identifier} identifies the @sc{cpu} and is of the
6b92c0d3 7418form: @code{@var{vendor}:@var{processor identifier}}. In addition,
4a4495d6
MM
7419there are two special identifiers, @code{none} and @code{auto}
7420(default).
7421
7422The following vendor identifiers and corresponding processor
7423identifiers are currently supported:
7424
7425@multitable @columnfractions .1 .9
7426
7427@item @code{intel}
7428@tab @var{family}/@var{model}[/@var{stepping}]
7429
7430@end multitable
7431
7432On GNU/Linux systems, the processor @var{family}, @var{model}, and
7433@var{stepping} can be obtained from @code{/proc/cpuinfo}.
7434
7435If @var{identifier} is @code{auto}, enable errata workarounds for the
7436processor on which the trace was recorded. If @var{identifier} is
7437@code{none}, errata workarounds are disabled.
7438
7439For example, when using an old @value{GDBN} on a new system, decode
7440may fail because @value{GDBN} does not support the new processor. It
7441often suffices to specify an older processor that @value{GDBN}
7442supports.
7443
7444@smallexample
7445(gdb) info record
7446Active record target: record-btrace
7447Recording format: Intel Processor Trace.
7448Buffer size: 16kB.
7449Failed to configure the Intel Processor Trace decoder: unknown cpu.
7450(gdb) set record btrace cpu intel:6/158
7451(gdb) info record
7452Active record target: record-btrace
7453Recording format: Intel Processor Trace.
7454Buffer size: 16kB.
7455Recorded 84872 instructions in 3189 functions (0 gaps) for thread 1 (...).
7456@end smallexample
7457
67b5c0c1
MM
7458@kindex show record btrace
7459@item show record btrace replay-memory-access
7460Show the current setting of @code{replay-memory-access}.
7461
4a4495d6
MM
7462@item show record btrace cpu
7463Show the processor to be used for enabling trace decode errata
7464workarounds.
7465
d33501a5
MM
7466@kindex set record btrace bts
7467@item set record btrace bts buffer-size @var{size}
7468@itemx set record btrace bts buffer-size unlimited
7469Set the requested ring buffer size for branch tracing in @acronym{BTS}
7470format. Default is 64KB.
7471
7472If @var{size} is a positive number, then @value{GDBN} will try to
7473allocate a buffer of at least @var{size} bytes for each new thread
7474that uses the btrace recording method and the @acronym{BTS} format.
7475The actually obtained buffer size may differ from the requested
7476@var{size}. Use the @code{info record} command to see the actual
7477buffer size for each thread that uses the btrace recording method and
7478the @acronym{BTS} format.
7479
7480If @var{limit} is @code{unlimited} or zero, @value{GDBN} will try to
7481allocate a buffer of 4MB.
7482
7483Bigger buffers mean longer traces. On the other hand, @value{GDBN} will
7484also need longer to process the branch trace data before it can be used.
7485
7486@item show record btrace bts buffer-size @var{size}
7487Show the current setting of the requested ring buffer size for branch
7488tracing in @acronym{BTS} format.
7489
b20a6524
MM
7490@kindex set record btrace pt
7491@item set record btrace pt buffer-size @var{size}
7492@itemx set record btrace pt buffer-size unlimited
bc504a31 7493Set the requested ring buffer size for branch tracing in Intel
b20a6524
MM
7494Processor Trace format. Default is 16KB.
7495
7496If @var{size} is a positive number, then @value{GDBN} will try to
7497allocate a buffer of at least @var{size} bytes for each new thread
bc504a31 7498that uses the btrace recording method and the Intel Processor Trace
b20a6524
MM
7499format. The actually obtained buffer size may differ from the
7500requested @var{size}. Use the @code{info record} command to see the
7501actual buffer size for each thread.
7502
7503If @var{limit} is @code{unlimited} or zero, @value{GDBN} will try to
7504allocate a buffer of 4MB.
7505
7506Bigger buffers mean longer traces. On the other hand, @value{GDBN} will
7507also need longer to process the branch trace data before it can be used.
7508
7509@item show record btrace pt buffer-size @var{size}
7510Show the current setting of the requested ring buffer size for branch
bc504a31 7511tracing in Intel Processor Trace format.
b20a6524 7512
29153c24
MS
7513@kindex info record
7514@item info record
59ea5688
MM
7515Show various statistics about the recording depending on the recording
7516method:
7517
7518@table @code
7519@item full
7520For the @code{full} recording method, it shows the state of process
7521record and its in-memory execution log buffer, including:
29153c24
MS
7522
7523@itemize @bullet
7524@item
7525Whether in record mode or replay mode.
7526@item
7527Lowest recorded instruction number (counting from when the current execution log started recording instructions).
7528@item
7529Highest recorded instruction number.
7530@item
7531Current instruction about to be replayed (if in replay mode).
7532@item
7533Number of instructions contained in the execution log.
7534@item
7535Maximum number of instructions that may be contained in the execution log.
7536@end itemize
53cc454a 7537
59ea5688 7538@item btrace
d33501a5
MM
7539For the @code{btrace} recording method, it shows:
7540
7541@itemize @bullet
7542@item
7543Recording format.
7544@item
7545Number of instructions that have been recorded.
7546@item
7547Number of blocks of sequential control-flow formed by the recorded
7548instructions.
7549@item
7550Whether in record mode or replay mode.
7551@end itemize
7552
7553For the @code{bts} recording format, it also shows:
7554@itemize @bullet
7555@item
7556Size of the perf ring buffer.
7557@end itemize
b20a6524
MM
7558
7559For the @code{pt} recording format, it also shows:
7560@itemize @bullet
7561@item
7562Size of the perf ring buffer.
7563@end itemize
59ea5688
MM
7564@end table
7565
53cc454a
HZ
7566@kindex record delete
7567@kindex rec del
7568@item record delete
a2311334 7569When record target runs in replay mode (``in the past''), delete the
53cc454a 7570subsequent execution log and begin to record a new execution log starting
a2311334 7571from the current address. This means you will abandon the previously
53cc454a 7572recorded ``future'' and begin recording a new ``future''.
59ea5688
MM
7573
7574@kindex record instruction-history
7575@kindex rec instruction-history
7576@item record instruction-history
7577Disassembles instructions from the recorded execution log. By
7578default, ten instructions are disassembled. This can be changed using
7579the @code{set record instruction-history-size} command. Instructions
da8c46d2
MM
7580are printed in execution order.
7581
0c532a29
MM
7582It can also print mixed source+disassembly if you specify the the
7583@code{/m} or @code{/s} modifier, and print the raw instructions in hex
7584as well as in symbolic form by specifying the @code{/r} modifier.
7585
7586The current position marker is printed for the instruction at the
7587current program counter value. This instruction can appear multiple
7588times in the trace and the current position marker will be printed
7589every time. To omit the current position marker, specify the
7590@code{/p} modifier.
7591
7592To better align the printed instructions when the trace contains
7593instructions from more than one function, the function name may be
7594omitted by specifying the @code{/f} modifier.
7595
da8c46d2
MM
7596Speculatively executed instructions are prefixed with @samp{?}. This
7597feature is not available for all recording formats.
7598
7599There are several ways to specify what part of the execution log to
7600disassemble:
59ea5688
MM
7601
7602@table @code
7603@item record instruction-history @var{insn}
7604Disassembles ten instructions starting from instruction number
7605@var{insn}.
7606
7607@item record instruction-history @var{insn}, +/-@var{n}
7608Disassembles @var{n} instructions around instruction number
7609@var{insn}. If @var{n} is preceded with @code{+}, disassembles
7610@var{n} instructions after instruction number @var{insn}. If
7611@var{n} is preceded with @code{-}, disassembles @var{n}
7612instructions before instruction number @var{insn}.
7613
7614@item record instruction-history
7615Disassembles ten more instructions after the last disassembly.
7616
7617@item record instruction-history -
7618Disassembles ten more instructions before the last disassembly.
7619
792005b0 7620@item record instruction-history @var{begin}, @var{end}
59ea5688
MM
7621Disassembles instructions beginning with instruction number
7622@var{begin} until instruction number @var{end}. The instruction
0688d04e 7623number @var{end} is included.
59ea5688
MM
7624@end table
7625
7626This command may not be available for all recording methods.
7627
7628@kindex set record
f81d1120
PA
7629@item set record instruction-history-size @var{size}
7630@itemx set record instruction-history-size unlimited
59ea5688
MM
7631Define how many instructions to disassemble in the @code{record
7632instruction-history} command. The default value is 10.
f81d1120 7633A @var{size} of @code{unlimited} means unlimited instructions.
59ea5688
MM
7634
7635@kindex show record
7636@item show record instruction-history-size
7637Show how many instructions to disassemble in the @code{record
7638instruction-history} command.
7639
7640@kindex record function-call-history
7641@kindex rec function-call-history
7642@item record function-call-history
7643Prints the execution history at function granularity. It prints one
7644line for each sequence of instructions that belong to the same
7645function giving the name of that function, the source lines
7646for this instruction sequence (if the @code{/l} modifier is
7647specified), and the instructions numbers that form the sequence (if
8710b709
MM
7648the @code{/i} modifier is specified). The function names are indented
7649to reflect the call stack depth if the @code{/c} modifier is
7650specified. The @code{/l}, @code{/i}, and @code{/c} modifiers can be
7651given together.
59ea5688
MM
7652
7653@smallexample
7654(@value{GDBP}) @b{list 1, 10}
76551 void foo (void)
76562 @{
76573 @}
76584
76595 void bar (void)
76606 @{
76617 ...
76628 foo ();
76639 ...
766410 @}
8710b709
MM
7665(@value{GDBP}) @b{record function-call-history /ilc}
76661 bar inst 1,4 at foo.c:6,8
76672 foo inst 5,10 at foo.c:2,3
76683 bar inst 11,13 at foo.c:9,10
59ea5688
MM
7669@end smallexample
7670
7671By default, ten lines are printed. This can be changed using the
7672@code{set record function-call-history-size} command. Functions are
7673printed in execution order. There are several ways to specify what
7674to print:
7675
7676@table @code
7677@item record function-call-history @var{func}
7678Prints ten functions starting from function number @var{func}.
7679
7680@item record function-call-history @var{func}, +/-@var{n}
7681Prints @var{n} functions around function number @var{func}. If
7682@var{n} is preceded with @code{+}, prints @var{n} functions after
7683function number @var{func}. If @var{n} is preceded with @code{-},
7684prints @var{n} functions before function number @var{func}.
7685
7686@item record function-call-history
7687Prints ten more functions after the last ten-line print.
7688
7689@item record function-call-history -
7690Prints ten more functions before the last ten-line print.
7691
792005b0 7692@item record function-call-history @var{begin}, @var{end}
59ea5688 7693Prints functions beginning with function number @var{begin} until
0688d04e 7694function number @var{end}. The function number @var{end} is included.
59ea5688
MM
7695@end table
7696
7697This command may not be available for all recording methods.
7698
f81d1120
PA
7699@item set record function-call-history-size @var{size}
7700@itemx set record function-call-history-size unlimited
59ea5688
MM
7701Define how many lines to print in the
7702@code{record function-call-history} command. The default value is 10.
f81d1120 7703A size of @code{unlimited} means unlimited lines.
59ea5688
MM
7704
7705@item show record function-call-history-size
7706Show how many lines to print in the
7707@code{record function-call-history} command.
53cc454a
HZ
7708@end table
7709
7710
6d2ebf8b 7711@node Stack
c906108c
SS
7712@chapter Examining the Stack
7713
7714When your program has stopped, the first thing you need to know is where it
7715stopped and how it got there.
7716
7717@cindex call stack
5d161b24
DB
7718Each time your program performs a function call, information about the call
7719is generated.
7720That information includes the location of the call in your program,
7721the arguments of the call,
c906108c 7722and the local variables of the function being called.
5d161b24 7723The information is saved in a block of data called a @dfn{stack frame}.
c906108c
SS
7724The stack frames are allocated in a region of memory called the @dfn{call
7725stack}.
7726
7727When your program stops, the @value{GDBN} commands for examining the
7728stack allow you to see all of this information.
7729
7730@cindex selected frame
7731One of the stack frames is @dfn{selected} by @value{GDBN} and many
7732@value{GDBN} commands refer implicitly to the selected frame. In
7733particular, whenever you ask @value{GDBN} for the value of a variable in
7734your program, the value is found in the selected frame. There are
7735special @value{GDBN} commands to select whichever frame you are
79a6e687 7736interested in. @xref{Selection, ,Selecting a Frame}.
c906108c
SS
7737
7738When your program stops, @value{GDBN} automatically selects the
5d161b24 7739currently executing frame and describes it briefly, similar to the
79a6e687 7740@code{frame} command (@pxref{Frame Info, ,Information about a Frame}).
c906108c
SS
7741
7742@menu
7743* Frames:: Stack frames
7744* Backtrace:: Backtraces
7745* Selection:: Selecting a frame
7746* Frame Info:: Information on a frame
0a232300 7747* Frame Apply:: Applying a command to several frames
0f59c28f 7748* Frame Filter Management:: Managing frame filters
c906108c
SS
7749
7750@end menu
7751
6d2ebf8b 7752@node Frames
79a6e687 7753@section Stack Frames
c906108c 7754
d4f3574e 7755@cindex frame, definition
c906108c
SS
7756@cindex stack frame
7757The call stack is divided up into contiguous pieces called @dfn{stack
7758frames}, or @dfn{frames} for short; each frame is the data associated
7759with one call to one function. The frame contains the arguments given
7760to the function, the function's local variables, and the address at
7761which the function is executing.
7762
7763@cindex initial frame
7764@cindex outermost frame
7765@cindex innermost frame
7766When your program is started, the stack has only one frame, that of the
7767function @code{main}. This is called the @dfn{initial} frame or the
7768@dfn{outermost} frame. Each time a function is called, a new frame is
7769made. Each time a function returns, the frame for that function invocation
7770is eliminated. If a function is recursive, there can be many frames for
7771the same function. The frame for the function in which execution is
7772actually occurring is called the @dfn{innermost} frame. This is the most
7773recently created of all the stack frames that still exist.
7774
7775@cindex frame pointer
7776Inside your program, stack frames are identified by their addresses. A
7777stack frame consists of many bytes, each of which has its own address; each
7778kind of computer has a convention for choosing one byte whose
7779address serves as the address of the frame. Usually this address is kept
e09f16f9
EZ
7780in a register called the @dfn{frame pointer register}
7781(@pxref{Registers, $fp}) while execution is going on in that frame.
c906108c 7782
f67ffa6a 7783@cindex frame level
c906108c 7784@cindex frame number
f67ffa6a
AB
7785@value{GDBN} labels each existing stack frame with a @dfn{level}, a
7786number that is zero for the innermost frame, one for the frame that
7787called it, and so on upward. These level numbers give you a way of
7788designating stack frames in @value{GDBN} commands. The terms
7789@dfn{frame number} and @dfn{frame level} can be used interchangeably to
7790describe this number.
c906108c 7791
6d2ebf8b
SS
7792@c The -fomit-frame-pointer below perennially causes hbox overflow
7793@c underflow problems.
c906108c
SS
7794@cindex frameless execution
7795Some compilers provide a way to compile functions so that they operate
e22ea452 7796without stack frames. (For example, the @value{NGCC} option
474c8240 7797@smallexample
6d2ebf8b 7798@samp{-fomit-frame-pointer}
474c8240 7799@end smallexample
6d2ebf8b 7800generates functions without a frame.)
c906108c
SS
7801This is occasionally done with heavily used library functions to save
7802the frame setup time. @value{GDBN} has limited facilities for dealing
7803with these function invocations. If the innermost function invocation
7804has no stack frame, @value{GDBN} nevertheless regards it as though
7805it had a separate frame, which is numbered zero as usual, allowing
7806correct tracing of the function call chain. However, @value{GDBN} has
7807no provision for frameless functions elsewhere in the stack.
7808
6d2ebf8b 7809@node Backtrace
c906108c
SS
7810@section Backtraces
7811
09d4efe1
EZ
7812@cindex traceback
7813@cindex call stack traces
c906108c
SS
7814A backtrace is a summary of how your program got where it is. It shows one
7815line per frame, for many frames, starting with the currently executing
7816frame (frame zero), followed by its caller (frame one), and on up the
7817stack.
7818
1e611234 7819@anchor{backtrace-command}
c906108c 7820@kindex backtrace
41afff9a 7821@kindex bt @r{(@code{backtrace})}
ea3b0687
TT
7822To print a backtrace of the entire stack, use the @code{backtrace}
7823command, or its alias @code{bt}. This command will print one line per
7824frame for frames in the stack. By default, all stack frames are
7825printed. You can stop the backtrace at any time by typing the system
7826interrupt character, normally @kbd{Ctrl-c}.
7827
7828@table @code
3345721a
PA
7829@item backtrace [@var{option}]@dots{} [@var{qualifier}]@dots{} [@var{count}]
7830@itemx bt [@var{option}]@dots{} [@var{qualifier}]@dots{} [@var{count}]
7831Print the backtrace of the entire stack.
7832
7833The optional @var{count} can be one of the following:
ea3b0687
TT
7834
7835@table @code
7836@item @var{n}
7837@itemx @var{n}
7838Print only the innermost @var{n} frames, where @var{n} is a positive
7839number.
7840
7841@item -@var{n}
7842@itemx -@var{n}
7843Print only the outermost @var{n} frames, where @var{n} is a positive
7844number.
3345721a 7845@end table
ea3b0687 7846
3345721a
PA
7847Options:
7848
7849@table @code
7850@item -full
ea3b0687 7851Print the values of the local variables also. This can be combined
3345721a 7852with the optional @var{count} to limit the number of frames shown.
ea3b0687 7853
3345721a 7854@item -no-filters
1e611234
PM
7855Do not run Python frame filters on this backtrace. @xref{Frame
7856Filter API}, for more information. Additionally use @ref{disable
7857frame-filter all} to turn off all frame filters. This is only
7858relevant when @value{GDBN} has been configured with @code{Python}
7859support.
978d6c75 7860
3345721a 7861@item -hide
978d6c75
TT
7862A Python frame filter might decide to ``elide'' some frames. Normally
7863such elided frames are still printed, but they are indented relative
3345721a 7864to the filtered frames that cause them to be elided. The @code{-hide}
978d6c75 7865option causes elided frames to not be printed at all.
c906108c 7866@end table
3345721a
PA
7867
7868The @code{backtrace} command also supports a number of options that
7869allow overriding relevant global print settings as set by @code{set
7870backtrace} and @code{set print} subcommands:
7871
7872@table @code
7873@item -past-main [@code{on}|@code{off}]
7874Set whether backtraces should continue past @code{main}. Related setting:
7875@ref{set backtrace past-main}.
7876
7877@item -past-entry [@code{on}|@code{off}]
7878Set whether backtraces should continue past the entry point of a program.
7879Related setting: @ref{set backtrace past-entry}.
7880
7881@item -entry-values @code{no}|@code{only}|@code{preferred}|@code{if-needed}|@code{both}|@code{compact}|@code{default}
7882Set printing of function arguments at function entry.
7883Related setting: @ref{set print entry-values}.
7884
7885@item -frame-arguments @code{all}|@code{scalars}|@code{none}
7886Set printing of non-scalar frame arguments.
7887Related setting: @ref{set print frame-arguments}.
7888
7889@item -raw-frame-arguments [@code{on}|@code{off}]
7890Set whether to print frame arguments in raw form.
7891Related setting: @ref{set print raw-frame-arguments}.
bc4268a5
PW
7892
7893@item -frame-info @code{auto}|@code{source-line}|@code{location}|@code{source-and-location}|@code{location-and-address}|@code{short-location}
7894Set printing of frame information.
7895Related setting: @ref{set print frame-info}.
3345721a
PA
7896@end table
7897
7898The optional @var{qualifier} is maintained for backward compatibility.
7899It can be one of the following:
7900
7901@table @code
7902@item full
7903Equivalent to the @code{-full} option.
7904
7905@item no-filters
7906Equivalent to the @code{-no-filters} option.
7907
7908@item hide
7909Equivalent to the @code{-hide} option.
7910@end table
7911
ea3b0687 7912@end table
c906108c
SS
7913
7914@kindex where
7915@kindex info stack
c906108c
SS
7916The names @code{where} and @code{info stack} (abbreviated @code{info s})
7917are additional aliases for @code{backtrace}.
7918
839c27b7
EZ
7919@cindex multiple threads, backtrace
7920In a multi-threaded program, @value{GDBN} by default shows the
7921backtrace only for the current thread. To display the backtrace for
7922several or all of the threads, use the command @code{thread apply}
7923(@pxref{Threads, thread apply}). For example, if you type @kbd{thread
7924apply all backtrace}, @value{GDBN} will display the backtrace for all
7925the threads; this is handy when you debug a core dump of a
7926multi-threaded program.
7927
c906108c
SS
7928Each line in the backtrace shows the frame number and the function name.
7929The program counter value is also shown---unless you use @code{set
7930print address off}. The backtrace also shows the source file name and
7931line number, as well as the arguments to the function. The program
7932counter value is omitted if it is at the beginning of the code for that
7933line number.
7934
7935Here is an example of a backtrace. It was made with the command
7936@samp{bt 3}, so it shows the innermost three frames.
7937
7938@smallexample
7939@group
5d161b24 7940#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
c906108c 7941 at builtin.c:993
4f5376b2 7942#1 0x6e38 in expand_macro (sym=0x2b600, data=...) at macro.c:242
c906108c
SS
7943#2 0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
7944 at macro.c:71
7945(More stack frames follow...)
7946@end group
7947@end smallexample
7948
7949@noindent
7950The display for frame zero does not begin with a program counter
7951value, indicating that your program has stopped at the beginning of the
7952code for line @code{993} of @code{builtin.c}.
7953
4f5376b2
JB
7954@noindent
7955The value of parameter @code{data} in frame 1 has been replaced by
7956@code{@dots{}}. By default, @value{GDBN} prints the value of a parameter
7957only if it is a scalar (integer, pointer, enumeration, etc). See command
7958@kbd{set print frame-arguments} in @ref{Print Settings} for more details
7959on how to configure the way function parameter values are printed.
bc4268a5
PW
7960The command @kbd{set print frame-info} (@pxref{Print Settings}) controls
7961what frame information is printed.
4f5376b2 7962
585fdaa1 7963@cindex optimized out, in backtrace
18999be5
EZ
7964@cindex function call arguments, optimized out
7965If your program was compiled with optimizations, some compilers will
7966optimize away arguments passed to functions if those arguments are
7967never used after the call. Such optimizations generate code that
7968passes arguments through registers, but doesn't store those arguments
7969in the stack frame. @value{GDBN} has no way of displaying such
7970arguments in stack frames other than the innermost one. Here's what
7971such a backtrace might look like:
7972
7973@smallexample
7974@group
7975#0 m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
7976 at builtin.c:993
585fdaa1
PA
7977#1 0x6e38 in expand_macro (sym=<optimized out>) at macro.c:242
7978#2 0x6840 in expand_token (obs=0x0, t=<optimized out>, td=0xf7fffb08)
18999be5
EZ
7979 at macro.c:71
7980(More stack frames follow...)
7981@end group
7982@end smallexample
7983
7984@noindent
7985The values of arguments that were not saved in their stack frames are
585fdaa1 7986shown as @samp{<optimized out>}.
18999be5
EZ
7987
7988If you need to display the values of such optimized-out arguments,
7989either deduce that from other variables whose values depend on the one
7990you are interested in, or recompile without optimizations.
7991
a8f24a35
EZ
7992@cindex backtrace beyond @code{main} function
7993@cindex program entry point
7994@cindex startup code, and backtrace
25d29d70
AC
7995Most programs have a standard user entry point---a place where system
7996libraries and startup code transition into user code. For C this is
d416eeec
EZ
7997@code{main}@footnote{
7998Note that embedded programs (the so-called ``free-standing''
7999environment) are not required to have a @code{main} function as the
8000entry point. They could even have multiple entry points.}.
8001When @value{GDBN} finds the entry function in a backtrace
25d29d70
AC
8002it will terminate the backtrace, to avoid tracing into highly
8003system-specific (and generally uninteresting) code.
8004
8005If you need to examine the startup code, or limit the number of levels
8006in a backtrace, you can change this behavior:
95f90d25
DJ
8007
8008@table @code
25d29d70
AC
8009@item set backtrace past-main
8010@itemx set backtrace past-main on
3345721a 8011@anchor{set backtrace past-main}
4644b6e3 8012@kindex set backtrace
25d29d70
AC
8013Backtraces will continue past the user entry point.
8014
8015@item set backtrace past-main off
95f90d25
DJ
8016Backtraces will stop when they encounter the user entry point. This is the
8017default.
8018
25d29d70 8019@item show backtrace past-main
4644b6e3 8020@kindex show backtrace
25d29d70
AC
8021Display the current user entry point backtrace policy.
8022
2315ffec
RC
8023@item set backtrace past-entry
8024@itemx set backtrace past-entry on
3345721a 8025@anchor{set backtrace past-entry}
a8f24a35 8026Backtraces will continue past the internal entry point of an application.
2315ffec
RC
8027This entry point is encoded by the linker when the application is built,
8028and is likely before the user entry point @code{main} (or equivalent) is called.
8029
8030@item set backtrace past-entry off
d3e8051b 8031Backtraces will stop when they encounter the internal entry point of an
2315ffec
RC
8032application. This is the default.
8033
8034@item show backtrace past-entry
8035Display the current internal entry point backtrace policy.
8036
25d29d70
AC
8037@item set backtrace limit @var{n}
8038@itemx set backtrace limit 0
f81d1120 8039@itemx set backtrace limit unlimited
3345721a 8040@anchor{set backtrace limit}
25d29d70 8041@cindex backtrace limit
f81d1120
PA
8042Limit the backtrace to @var{n} levels. A value of @code{unlimited}
8043or zero means unlimited levels.
95f90d25 8044
25d29d70
AC
8045@item show backtrace limit
8046Display the current limit on backtrace levels.
95f90d25
DJ
8047@end table
8048
1b56eb55
JK
8049You can control how file names are displayed.
8050
8051@table @code
8052@item set filename-display
8053@itemx set filename-display relative
8054@cindex filename-display
8055Display file names relative to the compilation directory. This is the default.
8056
8057@item set filename-display basename
8058Display only basename of a filename.
8059
8060@item set filename-display absolute
8061Display an absolute filename.
8062
8063@item show filename-display
8064Show the current way to display filenames.
8065@end table
8066
6d2ebf8b 8067@node Selection
79a6e687 8068@section Selecting a Frame
c906108c
SS
8069
8070Most commands for examining the stack and other data in your program work on
8071whichever stack frame is selected at the moment. Here are the commands for
8072selecting a stack frame; all of them finish by printing a brief description
8073of the stack frame just selected.
8074
8075@table @code
d4f3574e 8076@kindex frame@r{, selecting}
41afff9a 8077@kindex f @r{(@code{frame})}
f67ffa6a
AB
8078@item frame @r{[} @var{frame-selection-spec} @r{]}
8079@item f @r{[} @var{frame-selection-spec} @r{]}
8080The @command{frame} command allows different stack frames to be
8081selected. The @var{frame-selection-spec} can be any of the following:
8082
8083@table @code
8084@kindex frame level
8085@item @var{num}
8086@item level @var{num}
8087Select frame level @var{num}. Recall that frame zero is the innermost
c906108c 8088(currently executing) frame, frame one is the frame that called the
f67ffa6a
AB
8089innermost one, and so on. The highest level frame is usually the one
8090for @code{main}.
8091
8092As this is the most common method of navigating the frame stack, the
8093string @command{level} can be omitted. For example, the following two
8094commands are equivalent:
8095
8096@smallexample
8097(@value{GDBP}) frame 3
8098(@value{GDBP}) frame level 3
8099@end smallexample
8100
8101@kindex frame address
8102@item address @var{stack-address}
8103Select the frame with stack address @var{stack-address}. The
8104@var{stack-address} for a frame can be seen in the output of
8105@command{info frame}, for example:
8106
8107@smallexample
8108(gdb) info frame
8109Stack level 1, frame at 0x7fffffffda30:
8110 rip = 0x40066d in b (amd64-entry-value.cc:59); saved rip 0x4004c5
8111 tail call frame, caller of frame at 0x7fffffffda30
8112 source language c++.
8113 Arglist at unknown address.
8114 Locals at unknown address, Previous frame's sp is 0x7fffffffda30
8115@end smallexample
8116
8117The @var{stack-address} for this frame is @code{0x7fffffffda30} as
8118indicated by the line:
8119
8120@smallexample
8121Stack level 1, frame at 0x7fffffffda30:
8122@end smallexample
8123
8124@kindex frame function
8125@item function @var{function-name}
8126Select the stack frame for function @var{function-name}. If there are
8127multiple stack frames for function @var{function-name} then the inner
8128most stack frame is selected.
8129
8130@kindex frame view
8131@item view @var{stack-address} @r{[} @var{pc-addr} @r{]}
8132View a frame that is not part of @value{GDBN}'s backtrace. The frame
8133viewed has stack address @var{stack-addr}, and optionally, a program
8134counter address of @var{pc-addr}.
8135
8136This is useful mainly if the chaining of stack frames has been
8137damaged by a bug, making it impossible for @value{GDBN} to assign
8138numbers properly to all frames. In addition, this can be useful
8139when your program has multiple stacks and switches between them.
8140
8141When viewing a frame outside the current backtrace using
8142@command{frame view} then you can always return to the original
8143stack using one of the previous stack frame selection instructions,
8144for example @command{frame level 0}.
8145
8146@end table
c906108c
SS
8147
8148@kindex up
8149@item up @var{n}
697aa1b7
EZ
8150Move @var{n} frames up the stack; @var{n} defaults to 1. For positive
8151numbers @var{n}, this advances toward the outermost frame, to higher
8152frame numbers, to frames that have existed longer.
c906108c
SS
8153
8154@kindex down
41afff9a 8155@kindex do @r{(@code{down})}
c906108c 8156@item down @var{n}
697aa1b7
EZ
8157Move @var{n} frames down the stack; @var{n} defaults to 1. For
8158positive numbers @var{n}, this advances toward the innermost frame, to
8159lower frame numbers, to frames that were created more recently.
8160You may abbreviate @code{down} as @code{do}.
c906108c
SS
8161@end table
8162
8163All of these commands end by printing two lines of output describing the
8164frame. The first line shows the frame number, the function name, the
8165arguments, and the source file and line number of execution in that
5d161b24 8166frame. The second line shows the text of that source line.
c906108c
SS
8167
8168@need 1000
8169For example:
8170
8171@smallexample
8172@group
8173(@value{GDBP}) up
8174#1 0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
8175 at env.c:10
817610 read_input_file (argv[i]);
8177@end group
8178@end smallexample
8179
8180After such a printout, the @code{list} command with no arguments
8181prints ten lines centered on the point of execution in the frame.
87885426
FN
8182You can also edit the program at the point of execution with your favorite
8183editing program by typing @code{edit}.
79a6e687 8184@xref{List, ,Printing Source Lines},
87885426 8185for details.
c906108c
SS
8186
8187@table @code
fc58fa65 8188@kindex select-frame
f67ffa6a 8189@item select-frame @r{[} @var{frame-selection-spec} @r{]}
fc58fa65
AB
8190The @code{select-frame} command is a variant of @code{frame} that does
8191not display the new frame after selecting it. This command is
8192intended primarily for use in @value{GDBN} command scripts, where the
f67ffa6a
AB
8193output might be unnecessary and distracting. The
8194@var{frame-selection-spec} is as for the @command{frame} command
8195described in @ref{Selection, ,Selecting a Frame}.
fc58fa65 8196
c906108c
SS
8197@kindex down-silently
8198@kindex up-silently
8199@item up-silently @var{n}
8200@itemx down-silently @var{n}
8201These two commands are variants of @code{up} and @code{down},
8202respectively; they differ in that they do their work silently, without
8203causing display of the new frame. They are intended primarily for use
8204in @value{GDBN} command scripts, where the output might be unnecessary and
8205distracting.
8206@end table
8207
6d2ebf8b 8208@node Frame Info
79a6e687 8209@section Information About a Frame
c906108c
SS
8210
8211There are several other commands to print information about the selected
8212stack frame.
8213
8214@table @code
8215@item frame
8216@itemx f
8217When used without any argument, this command does not change which
8218frame is selected, but prints a brief description of the currently
8219selected stack frame. It can be abbreviated @code{f}. With an
8220argument, this command is used to select a stack frame.
79a6e687 8221@xref{Selection, ,Selecting a Frame}.
c906108c
SS
8222
8223@kindex info frame
41afff9a 8224@kindex info f @r{(@code{info frame})}
c906108c
SS
8225@item info frame
8226@itemx info f
8227This command prints a verbose description of the selected stack frame,
8228including:
8229
8230@itemize @bullet
5d161b24
DB
8231@item
8232the address of the frame
c906108c
SS
8233@item
8234the address of the next frame down (called by this frame)
8235@item
8236the address of the next frame up (caller of this frame)
8237@item
8238the language in which the source code corresponding to this frame is written
8239@item
8240the address of the frame's arguments
8241@item
d4f3574e
SS
8242the address of the frame's local variables
8243@item
c906108c
SS
8244the program counter saved in it (the address of execution in the caller frame)
8245@item
8246which registers were saved in the frame
8247@end itemize
8248
8249@noindent The verbose description is useful when
8250something has gone wrong that has made the stack format fail to fit
8251the usual conventions.
8252
f67ffa6a
AB
8253@item info frame @r{[} @var{frame-selection-spec} @r{]}
8254@itemx info f @r{[} @var{frame-selection-spec} @r{]}
8255Print a verbose description of the frame selected by
8256@var{frame-selection-spec}. The @var{frame-selection-spec} is the
8257same as for the @command{frame} command (@pxref{Selection, ,Selecting
8258a Frame}). The selected frame remains unchanged by this command.
c906108c
SS
8259
8260@kindex info args
d321477b 8261@item info args [-q]
c906108c
SS
8262Print the arguments of the selected frame, each on a separate line.
8263
d321477b
PW
8264The optional flag @samp{-q}, which stands for @samp{quiet}, disables
8265printing header information and messages explaining why no argument
8266have been printed.
8267
8268@item info args [-q] [-t @var{type_regexp}] [@var{regexp}]
8269Like @kbd{info args}, but only print the arguments selected
8270with the provided regexp(s).
8271
8272If @var{regexp} is provided, print only the arguments whose names
8273match the regular expression @var{regexp}.
8274
8275If @var{type_regexp} is provided, print only the arguments whose
8276types, as printed by the @code{whatis} command, match
8277the regular expression @var{type_regexp}.
8278If @var{type_regexp} contains space(s), it should be enclosed in
8279quote characters. If needed, use backslash to escape the meaning
8280of special characters or quotes.
8281
8282If both @var{regexp} and @var{type_regexp} are provided, an argument
8283is printed only if its name matches @var{regexp} and its type matches
8284@var{type_regexp}.
8285
8286@item info locals [-q]
c906108c
SS
8287@kindex info locals
8288Print the local variables of the selected frame, each on a separate
8289line. These are all variables (declared either static or automatic)
8290accessible at the point of execution of the selected frame.
8291
d321477b
PW
8292The optional flag @samp{-q}, which stands for @samp{quiet}, disables
8293printing header information and messages explaining why no local variables
8294have been printed.
8295
8296@item info locals [-q] [-t @var{type_regexp}] [@var{regexp}]
8297Like @kbd{info locals}, but only print the local variables selected
8298with the provided regexp(s).
8299
8300If @var{regexp} is provided, print only the local variables whose names
8301match the regular expression @var{regexp}.
8302
8303If @var{type_regexp} is provided, print only the local variables whose
8304types, as printed by the @code{whatis} command, match
8305the regular expression @var{type_regexp}.
8306If @var{type_regexp} contains space(s), it should be enclosed in
8307quote characters. If needed, use backslash to escape the meaning
8308of special characters or quotes.
8309
8310If both @var{regexp} and @var{type_regexp} are provided, a local variable
8311is printed only if its name matches @var{regexp} and its type matches
8312@var{type_regexp}.
8313
8314The command @kbd{info locals -q -t @var{type_regexp}} can usefully be
8315combined with the commands @kbd{frame apply} and @kbd{thread apply}.
8316For example, your program might use Resource Acquisition Is
8317Initialization types (RAII) such as @code{lock_something_t}: each
8318local variable of type @code{lock_something_t} automatically places a
8319lock that is destroyed when the variable goes out of scope. You can
8320then list all acquired locks in your program by doing
8321@smallexample
8322thread apply all -s frame apply all -s info locals -q -t lock_something_t
8323@end smallexample
8324@noindent
8325or the equivalent shorter form
8326@smallexample
8327tfaas i lo -q -t lock_something_t
8328@end smallexample
8329
c906108c
SS
8330@end table
8331
0a232300
PW
8332@node Frame Apply
8333@section Applying a Command to Several Frames.
3345721a 8334@anchor{frame apply}
0a232300
PW
8335@kindex frame apply
8336@cindex apply command to several frames
8337@table @code
3345721a 8338@item frame apply [all | @var{count} | @var{-count} | level @var{level}@dots{}] [@var{option}]@dots{} @var{command}
0a232300
PW
8339The @code{frame apply} command allows you to apply the named
8340@var{command} to one or more frames.
8341
8342@table @code
8343@item @code{all}
8344Specify @code{all} to apply @var{command} to all frames.
8345
8346@item @var{count}
8347Use @var{count} to apply @var{command} to the innermost @var{count}
8348frames, where @var{count} is a positive number.
8349
8350@item @var{-count}
8351Use @var{-count} to apply @var{command} to the outermost @var{count}
8352frames, where @var{count} is a positive number.
8353
8354@item @code{level}
8355Use @code{level} to apply @var{command} to the set of frames identified
8356by the @var{level} list. @var{level} is a frame level or a range of frame
8357levels as @var{level1}-@var{level2}. The frame level is the number shown
8358in the first field of the @samp{backtrace} command output.
8359E.g., @samp{2-4 6-8 3} indicates to apply @var{command} for the frames
8360at levels 2, 3, 4, 6, 7, 8, and then again on frame at level 3.
8361
8362@end table
8363
0a232300
PW
8364Note that the frames on which @code{frame apply} applies a command are
8365also influenced by the @code{set backtrace} settings such as @code{set
3345721a 8366backtrace past-main} and @code{set backtrace limit N}.
0a232300
PW
8367@xref{Backtrace,,Backtraces}.
8368
3345721a
PA
8369The @code{frame apply} command also supports a number of options that
8370allow overriding relevant @code{set backtrace} settings:
8371
8372@table @code
8373@item -past-main [@code{on}|@code{off}]
8374Whether backtraces should continue past @code{main}.
8375Related setting: @ref{set backtrace past-main}.
8376
8377@item -past-entry [@code{on}|@code{off}]
8378Whether backtraces should continue past the entry point of a program.
8379Related setting: @ref{set backtrace past-entry}.
8380@end table
0a232300
PW
8381
8382By default, @value{GDBN} displays some frame information before the
8383output produced by @var{command}, and an error raised during the
8384execution of a @var{command} will abort @code{frame apply}. The
3345721a 8385following options can be used to fine-tune these behaviors:
0a232300
PW
8386
8387@table @code
8388@item -c
8389The flag @code{-c}, which stands for @samp{continue}, causes any
8390errors in @var{command} to be displayed, and the execution of
8391@code{frame apply} then continues.
8392@item -s
8393The flag @code{-s}, which stands for @samp{silent}, causes any errors
8394or empty output produced by a @var{command} to be silently ignored.
8395That is, the execution continues, but the frame information and errors
8396are not printed.
8397@item -q
8398The flag @code{-q} (@samp{quiet}) disables printing the frame
8399information.
8400@end table
8401
8402The following example shows how the flags @code{-c} and @code{-s} are
8403working when applying the command @code{p j} to all frames, where
8404variable @code{j} can only be successfully printed in the outermost
8405@code{#1 main} frame.
8406
8407@smallexample
8408@group
8409(gdb) frame apply all p j
8410#0 some_function (i=5) at fun.c:4
8411No symbol "j" in current context.
8412(gdb) frame apply all -c p j
8413#0 some_function (i=5) at fun.c:4
8414No symbol "j" in current context.
8415#1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8416$1 = 5
8417(gdb) frame apply all -s p j
8418#1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8419$2 = 5
8420(gdb)
8421@end group
8422@end smallexample
8423
8424By default, @samp{frame apply}, prints the frame location
8425information before the command output:
8426
8427@smallexample
8428@group
8429(gdb) frame apply all p $sp
8430#0 some_function (i=5) at fun.c:4
8431$4 = (void *) 0xffffd1e0
8432#1 0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8433$5 = (void *) 0xffffd1f0
8434(gdb)
8435@end group
8436@end smallexample
8437
3345721a 8438If the flag @code{-q} is given, no frame information is printed:
0a232300
PW
8439@smallexample
8440@group
8441(gdb) frame apply all -q p $sp
8442$12 = (void *) 0xffffd1e0
8443$13 = (void *) 0xffffd1f0
8444(gdb)
8445@end group
8446@end smallexample
8447
3345721a
PA
8448@end table
8449
0a232300
PW
8450@table @code
8451
8452@kindex faas
8453@cindex apply a command to all frames (ignoring errors and empty output)
8454@item faas @var{command}
8455Shortcut for @code{frame apply all -s @var{command}}.
8456Applies @var{command} on all frames, ignoring errors and empty output.
8457
8458It can for example be used to print a local variable or a function
8459argument without knowing the frame where this variable or argument
8460is, using:
8461@smallexample
8462(@value{GDBP}) faas p some_local_var_i_do_not_remember_where_it_is
8463@end smallexample
8464
3345721a
PA
8465The @code{faas} command accepts the same options as the @code{frame
8466apply} command. @xref{frame apply}.
8467
0a232300
PW
8468Note that the command @code{tfaas @var{command}} applies @var{command}
8469on all frames of all threads. See @xref{Threads,,Threads}.
8470@end table
8471
8472
fc58fa65
AB
8473@node Frame Filter Management
8474@section Management of Frame Filters.
8475@cindex managing frame filters
8476
8477Frame filters are Python based utilities to manage and decorate the
8478output of frames. @xref{Frame Filter API}, for further information.
8479
8480Managing frame filters is performed by several commands available
8481within @value{GDBN}, detailed here.
8482
8483@table @code
8484@kindex info frame-filter
8485@item info frame-filter
8486Print a list of installed frame filters from all dictionaries, showing
8487their name, priority and enabled status.
8488
8489@kindex disable frame-filter
8490@anchor{disable frame-filter all}
8491@item disable frame-filter @var{filter-dictionary} @var{filter-name}
8492Disable a frame filter in the dictionary matching
8493@var{filter-dictionary} and @var{filter-name}. The
8494@var{filter-dictionary} may be @code{all}, @code{global},
8495@code{progspace}, or the name of the object file where the frame filter
8496dictionary resides. When @code{all} is specified, all frame filters
8497across all dictionaries are disabled. The @var{filter-name} is the name
8498of the frame filter and is used when @code{all} is not the option for
8499@var{filter-dictionary}. A disabled frame-filter is not deleted, it
8500may be enabled again later.
8501
8502@kindex enable frame-filter
8503@item enable frame-filter @var{filter-dictionary} @var{filter-name}
8504Enable a frame filter in the dictionary matching
8505@var{filter-dictionary} and @var{filter-name}. The
8506@var{filter-dictionary} may be @code{all}, @code{global},
8507@code{progspace} or the name of the object file where the frame filter
8508dictionary resides. When @code{all} is specified, all frame filters across
8509all dictionaries are enabled. The @var{filter-name} is the name of the frame
8510filter and is used when @code{all} is not the option for
8511@var{filter-dictionary}.
8512
8513Example:
8514
8515@smallexample
8516(gdb) info frame-filter
8517
8518global frame-filters:
8519 Priority Enabled Name
8520 1000 No PrimaryFunctionFilter
8521 100 Yes Reverse
8522
8523progspace /build/test frame-filters:
8524 Priority Enabled Name
8525 100 Yes ProgspaceFilter
8526
8527objfile /build/test frame-filters:
8528 Priority Enabled Name
6b92c0d3 8529 999 Yes BuildProgramFilter
fc58fa65
AB
8530
8531(gdb) disable frame-filter /build/test BuildProgramFilter
8532(gdb) info frame-filter
8533
8534global frame-filters:
8535 Priority Enabled Name
8536 1000 No PrimaryFunctionFilter
8537 100 Yes Reverse
8538
8539progspace /build/test frame-filters:
8540 Priority Enabled Name
8541 100 Yes ProgspaceFilter
8542
8543objfile /build/test frame-filters:
8544 Priority Enabled Name
8545 999 No BuildProgramFilter
8546
8547(gdb) enable frame-filter global PrimaryFunctionFilter
8548(gdb) info frame-filter
8549
8550global frame-filters:
8551 Priority Enabled Name
8552 1000 Yes PrimaryFunctionFilter
8553 100 Yes Reverse
8554
8555progspace /build/test frame-filters:
8556 Priority Enabled Name
8557 100 Yes ProgspaceFilter
8558
8559objfile /build/test frame-filters:
8560 Priority Enabled Name
8561 999 No BuildProgramFilter
8562@end smallexample
8563
8564@kindex set frame-filter priority
8565@item set frame-filter priority @var{filter-dictionary} @var{filter-name} @var{priority}
8566Set the @var{priority} of a frame filter in the dictionary matching
8567@var{filter-dictionary}, and the frame filter name matching
8568@var{filter-name}. The @var{filter-dictionary} may be @code{global},
8569@code{progspace} or the name of the object file where the frame filter
8570dictionary resides. The @var{priority} is an integer.
8571
8572@kindex show frame-filter priority
8573@item show frame-filter priority @var{filter-dictionary} @var{filter-name}
8574Show the @var{priority} of a frame filter in the dictionary matching
8575@var{filter-dictionary}, and the frame filter name matching
8576@var{filter-name}. The @var{filter-dictionary} may be @code{global},
8577@code{progspace} or the name of the object file where the frame filter
8578dictionary resides.
8579
8580Example:
8581
8582@smallexample
8583(gdb) info frame-filter
8584
8585global frame-filters:
8586 Priority Enabled Name
8587 1000 Yes PrimaryFunctionFilter
8588 100 Yes Reverse
8589
8590progspace /build/test frame-filters:
8591 Priority Enabled Name
8592 100 Yes ProgspaceFilter
8593
8594objfile /build/test frame-filters:
8595 Priority Enabled Name
8596 999 No BuildProgramFilter
8597
8598(gdb) set frame-filter priority global Reverse 50
8599(gdb) info frame-filter
8600
8601global frame-filters:
8602 Priority Enabled Name
8603 1000 Yes PrimaryFunctionFilter
8604 50 Yes Reverse
8605
8606progspace /build/test frame-filters:
8607 Priority Enabled Name
8608 100 Yes ProgspaceFilter
8609
8610objfile /build/test frame-filters:
8611 Priority Enabled Name
8612 999 No BuildProgramFilter
8613@end smallexample
8614@end table
c906108c 8615
6d2ebf8b 8616@node Source
c906108c
SS
8617@chapter Examining Source Files
8618
8619@value{GDBN} can print parts of your program's source, since the debugging
8620information recorded in the program tells @value{GDBN} what source files were
8621used to build it. When your program stops, @value{GDBN} spontaneously prints
8622the line where it stopped. Likewise, when you select a stack frame
79a6e687 8623(@pxref{Selection, ,Selecting a Frame}), @value{GDBN} prints the line where
c906108c
SS
8624execution in that frame has stopped. You can print other portions of
8625source files by explicit command.
8626
7a292a7a 8627If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
d4f3574e 8628prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
7a292a7a 8629@value{GDBN} under @sc{gnu} Emacs}.
c906108c
SS
8630
8631@menu
8632* List:: Printing source lines
2a25a5ba 8633* Specify Location:: How to specify code locations
87885426 8634* Edit:: Editing source files
c906108c 8635* Search:: Searching source files
c906108c
SS
8636* Source Path:: Specifying source directories
8637* Machine Code:: Source and machine code
8638@end menu
8639
6d2ebf8b 8640@node List
79a6e687 8641@section Printing Source Lines
c906108c
SS
8642
8643@kindex list
41afff9a 8644@kindex l @r{(@code{list})}
c906108c 8645To print lines from a source file, use the @code{list} command
5d161b24 8646(abbreviated @code{l}). By default, ten lines are printed.
2a25a5ba
EZ
8647There are several ways to specify what part of the file you want to
8648print; see @ref{Specify Location}, for the full list.
c906108c
SS
8649
8650Here are the forms of the @code{list} command most commonly used:
8651
8652@table @code
8653@item list @var{linenum}
8654Print lines centered around line number @var{linenum} in the
8655current source file.
8656
8657@item list @var{function}
8658Print lines centered around the beginning of function
8659@var{function}.
8660
8661@item list
8662Print more lines. If the last lines printed were printed with a
8663@code{list} command, this prints lines following the last lines
8664printed; however, if the last line printed was a solitary line printed
8665as part of displaying a stack frame (@pxref{Stack, ,Examining the
8666Stack}), this prints lines centered around that line.
8667
8668@item list -
8669Print lines just before the lines last printed.
8670@end table
8671
9c16f35a 8672@cindex @code{list}, how many lines to display
c906108c
SS
8673By default, @value{GDBN} prints ten source lines with any of these forms of
8674the @code{list} command. You can change this using @code{set listsize}:
8675
8676@table @code
8677@kindex set listsize
8678@item set listsize @var{count}
f81d1120 8679@itemx set listsize unlimited
c906108c
SS
8680Make the @code{list} command display @var{count} source lines (unless
8681the @code{list} argument explicitly specifies some other number).
f81d1120 8682Setting @var{count} to @code{unlimited} or 0 means there's no limit.
c906108c
SS
8683
8684@kindex show listsize
8685@item show listsize
8686Display the number of lines that @code{list} prints.
8687@end table
8688
8689Repeating a @code{list} command with @key{RET} discards the argument,
8690so it is equivalent to typing just @code{list}. This is more useful
8691than listing the same lines again. An exception is made for an
8692argument of @samp{-}; that argument is preserved in repetition so that
8693each repetition moves up in the source file.
8694
c906108c 8695In general, the @code{list} command expects you to supply zero, one or two
629500fa 8696@dfn{locations}. Locations specify source lines; there are several ways
2a25a5ba
EZ
8697of writing them (@pxref{Specify Location}), but the effect is always
8698to specify some source line.
8699
c906108c
SS
8700Here is a complete description of the possible arguments for @code{list}:
8701
8702@table @code
629500fa
KS
8703@item list @var{location}
8704Print lines centered around the line specified by @var{location}.
c906108c
SS
8705
8706@item list @var{first},@var{last}
8707Print lines from @var{first} to @var{last}. Both arguments are
629500fa
KS
8708locations. When a @code{list} command has two locations, and the
8709source file of the second location is omitted, this refers to
8710the same source file as the first location.
c906108c
SS
8711
8712@item list ,@var{last}
8713Print lines ending with @var{last}.
8714
8715@item list @var{first},
8716Print lines starting with @var{first}.
8717
8718@item list +
8719Print lines just after the lines last printed.
8720
8721@item list -
8722Print lines just before the lines last printed.
8723
8724@item list
8725As described in the preceding table.
8726@end table
8727
2a25a5ba
EZ
8728@node Specify Location
8729@section Specifying a Location
8730@cindex specifying location
629500fa
KS
8731@cindex location
8732@cindex source location
8733
8734@menu
8735* Linespec Locations:: Linespec locations
8736* Explicit Locations:: Explicit locations
8737* Address Locations:: Address locations
8738@end menu
c906108c 8739
2a25a5ba
EZ
8740Several @value{GDBN} commands accept arguments that specify a location
8741of your program's code. Since @value{GDBN} is a source-level
629500fa
KS
8742debugger, a location usually specifies some line in the source code.
8743Locations may be specified using three different formats:
8744linespec locations, explicit locations, or address locations.
c906108c 8745
629500fa
KS
8746@node Linespec Locations
8747@subsection Linespec Locations
8748@cindex linespec locations
8749
8750A @dfn{linespec} is a colon-separated list of source location parameters such
8751as file name, function name, etc. Here are all the different ways of
8752specifying a linespec:
c906108c 8753
2a25a5ba
EZ
8754@table @code
8755@item @var{linenum}
8756Specifies the line number @var{linenum} of the current source file.
c906108c 8757
2a25a5ba
EZ
8758@item -@var{offset}
8759@itemx +@var{offset}
8760Specifies the line @var{offset} lines before or after the @dfn{current
8761line}. For the @code{list} command, the current line is the last one
8762printed; for the breakpoint commands, this is the line at which
8763execution stopped in the currently selected @dfn{stack frame}
8764(@pxref{Frames, ,Frames}, for a description of stack frames.) When
8765used as the second of the two linespecs in a @code{list} command,
8766this specifies the line @var{offset} lines up or down from the first
8767linespec.
8768
8769@item @var{filename}:@var{linenum}
8770Specifies the line @var{linenum} in the source file @var{filename}.
4aac40c8
TT
8771If @var{filename} is a relative file name, then it will match any
8772source file name with the same trailing components. For example, if
8773@var{filename} is @samp{gcc/expr.c}, then it will match source file
8774name of @file{/build/trunk/gcc/expr.c}, but not
8775@file{/build/trunk/libcpp/expr.c} or @file{/build/trunk/gcc/x-expr.c}.
c906108c
SS
8776
8777@item @var{function}
8778Specifies the line that begins the body of the function @var{function}.
2a25a5ba 8779For example, in C, this is the line with the open brace.
c906108c 8780
a20714ff
PA
8781By default, in C@t{++} and Ada, @var{function} is interpreted as
8782specifying all functions named @var{function} in all scopes. For
8783C@t{++}, this means in all namespaces and classes. For Ada, this
8784means in all packages.
8785
8786For example, assuming a program with C@t{++} symbols named
8787@code{A::B::func} and @code{B::func}, both commands @w{@kbd{break
8788func}} and @w{@kbd{break B::func}} set a breakpoint on both symbols.
8789
8790Commands that accept a linespec let you override this with the
8791@code{-qualified} option. For example, @w{@kbd{break -qualified
8792func}} sets a breakpoint on a free-function named @code{func} ignoring
8793any C@t{++} class methods and namespace functions called @code{func}.
8794
8795@xref{Explicit Locations}.
8796
9ef07c8c
TT
8797@item @var{function}:@var{label}
8798Specifies the line where @var{label} appears in @var{function}.
8799
c906108c 8800@item @var{filename}:@var{function}
2a25a5ba
EZ
8801Specifies the line that begins the body of the function @var{function}
8802in the file @var{filename}. You only need the file name with a
8803function name to avoid ambiguity when there are identically named
8804functions in different source files.
c906108c 8805
0f5238ed 8806@item @var{label}
629500fa
KS
8807Specifies the line at which the label named @var{label} appears
8808in the function corresponding to the currently selected stack frame.
8809If there is no current selected stack frame (for instance, if the inferior
8810is not running), then @value{GDBN} will not search for a label.
8811
8812@cindex breakpoint at static probe point
8813@item -pstap|-probe-stap @r{[}@var{objfile}:@r{[}@var{provider}:@r{]}@r{]}@var{name}
8814The @sc{gnu}/Linux tool @code{SystemTap} provides a way for
8815applications to embed static probes. @xref{Static Probe Points}, for more
8816information on finding and using static probes. This form of linespec
8817specifies the location of such a static probe.
8818
8819If @var{objfile} is given, only probes coming from that shared library
8820or executable matching @var{objfile} as a regular expression are considered.
8821If @var{provider} is given, then only probes from that provider are considered.
8822If several probes match the spec, @value{GDBN} will insert a breakpoint at
8823each one of those probes.
8824@end table
8825
8826@node Explicit Locations
8827@subsection Explicit Locations
8828@cindex explicit locations
8829
8830@dfn{Explicit locations} allow the user to directly specify the source
8831location's parameters using option-value pairs.
8832
8833Explicit locations are useful when several functions, labels, or
8834file names have the same name (base name for files) in the program's
8835sources. In these cases, explicit locations point to the source
8836line you meant more accurately and unambiguously. Also, using
8837explicit locations might be faster in large programs.
8838
8839For example, the linespec @samp{foo:bar} may refer to a function @code{bar}
8840defined in the file named @file{foo} or the label @code{bar} in a function
8841named @code{foo}. @value{GDBN} must search either the file system or
8842the symbol table to know.
8843
8844The list of valid explicit location options is summarized in the
8845following table:
8846
8847@table @code
8848@item -source @var{filename}
8849The value specifies the source file name. To differentiate between
8850files with the same base name, prepend as many directories as is necessary
8851to uniquely identify the desired file, e.g., @file{foo/bar/baz.c}. Otherwise
8852@value{GDBN} will use the first file it finds with the given base
8853name. This option requires the use of either @code{-function} or @code{-line}.
8854
8855@item -function @var{function}
8856The value specifies the name of a function. Operations
8857on function locations unmodified by other options (such as @code{-label}
8858or @code{-line}) refer to the line that begins the body of the function.
8859In C, for example, this is the line with the open brace.
8860
a20714ff
PA
8861By default, in C@t{++} and Ada, @var{function} is interpreted as
8862specifying all functions named @var{function} in all scopes. For
8863C@t{++}, this means in all namespaces and classes. For Ada, this
8864means in all packages.
8865
8866For example, assuming a program with C@t{++} symbols named
8867@code{A::B::func} and @code{B::func}, both commands @w{@kbd{break
8868-function func}} and @w{@kbd{break -function B::func}} set a
8869breakpoint on both symbols.
8870
8871You can use the @kbd{-qualified} flag to override this (see below).
8872
8873@item -qualified
8874
8875This flag makes @value{GDBN} interpret a function name specified with
8876@kbd{-function} as a complete fully-qualified name.
8877
8878For example, assuming a C@t{++} program with symbols named
8879@code{A::B::func} and @code{B::func}, the @w{@kbd{break -qualified
8880-function B::func}} command sets a breakpoint on @code{B::func}, only.
8881
8882(Note: the @kbd{-qualified} option can precede a linespec as well
8883(@pxref{Linespec Locations}), so the particular example above could be
8884simplified as @w{@kbd{break -qualified B::func}}.)
8885
629500fa
KS
8886@item -label @var{label}
8887The value specifies the name of a label. When the function
8888name is not specified, the label is searched in the function of the currently
8889selected stack frame.
8890
8891@item -line @var{number}
8892The value specifies a line offset for the location. The offset may either
8893be absolute (@code{-line 3}) or relative (@code{-line +3}), depending on
8894the command. When specified without any other options, the line offset is
8895relative to the current line.
8896@end table
8897
8898Explicit location options may be abbreviated by omitting any non-unique
a20714ff 8899trailing characters from the option name, e.g., @w{@kbd{break -s main.c -li 3}}.
629500fa
KS
8900
8901@node Address Locations
8902@subsection Address Locations
8903@cindex address locations
8904
8905@dfn{Address locations} indicate a specific program address. They have
8906the generalized form *@var{address}.
8907
8908For line-oriented commands, such as @code{list} and @code{edit}, this
8909specifies a source line that contains @var{address}. For @code{break} and
8910other breakpoint-oriented commands, this can be used to set breakpoints in
2a25a5ba
EZ
8911parts of your program which do not have debugging information or
8912source files.
8913
8914Here @var{address} may be any expression valid in the current working
8915language (@pxref{Languages, working language}) that specifies a code
5fa54e5d 8916address. In addition, as a convenience, @value{GDBN} extends the
629500fa
KS
8917semantics of expressions used in locations to cover several situations
8918that frequently occur during debugging. Here are the various forms
5fa54e5d 8919of @var{address}:
2a25a5ba
EZ
8920
8921@table @code
8922@item @var{expression}
8923Any expression valid in the current working language.
8924
8925@item @var{funcaddr}
8926An address of a function or procedure derived from its name. In C,
9c37b5ae 8927C@t{++}, Objective-C, Fortran, minimal, and assembly, this is
2a25a5ba
EZ
8928simply the function's name @var{function} (and actually a special case
8929of a valid expression). In Pascal and Modula-2, this is
8930@code{&@var{function}}. In Ada, this is @code{@var{function}'Address}
8931(although the Pascal form also works).
8932
8933This form specifies the address of the function's first instruction,
8934before the stack frame and arguments have been set up.
8935
9a284c97 8936@item '@var{filename}':@var{funcaddr}
2a25a5ba
EZ
8937Like @var{funcaddr} above, but also specifies the name of the source
8938file explicitly. This is useful if the name of the function does not
8939specify the function unambiguously, e.g., if there are several
8940functions with identical names in different source files.
c906108c
SS
8941@end table
8942
87885426 8943@node Edit
79a6e687 8944@section Editing Source Files
87885426
FN
8945@cindex editing source files
8946
8947@kindex edit
8948@kindex e @r{(@code{edit})}
8949To edit the lines in a source file, use the @code{edit} command.
8950The editing program of your choice
8951is invoked with the current line set to
8952the active line in the program.
8953Alternatively, there are several ways to specify what part of the file you
2a25a5ba 8954want to print if you want to see other parts of the program:
87885426
FN
8955
8956@table @code
2a25a5ba
EZ
8957@item edit @var{location}
8958Edit the source file specified by @code{location}. Editing starts at
8959that @var{location}, e.g., at the specified source line of the
8960specified file. @xref{Specify Location}, for all the possible forms
8961of the @var{location} argument; here are the forms of the @code{edit}
8962command most commonly used:
87885426 8963
2a25a5ba 8964@table @code
87885426
FN
8965@item edit @var{number}
8966Edit the current source file with @var{number} as the active line number.
8967
8968@item edit @var{function}
8969Edit the file containing @var{function} at the beginning of its definition.
2a25a5ba 8970@end table
87885426 8971
87885426
FN
8972@end table
8973
79a6e687 8974@subsection Choosing your Editor
87885426
FN
8975You can customize @value{GDBN} to use any editor you want
8976@footnote{
8977The only restriction is that your editor (say @code{ex}), recognizes the
8978following command-line syntax:
10998722 8979@smallexample
87885426 8980ex +@var{number} file
10998722 8981@end smallexample
15387254
EZ
8982The optional numeric value +@var{number} specifies the number of the line in
8983the file where to start editing.}.
8984By default, it is @file{@value{EDITOR}}, but you can change this
10998722
AC
8985by setting the environment variable @code{EDITOR} before using
8986@value{GDBN}. For example, to configure @value{GDBN} to use the
8987@code{vi} editor, you could use these commands with the @code{sh} shell:
8988@smallexample
87885426
FN
8989EDITOR=/usr/bin/vi
8990export EDITOR
15387254 8991gdb @dots{}
10998722 8992@end smallexample
87885426 8993or in the @code{csh} shell,
10998722 8994@smallexample
87885426 8995setenv EDITOR /usr/bin/vi
15387254 8996gdb @dots{}
10998722 8997@end smallexample
87885426 8998
6d2ebf8b 8999@node Search
79a6e687 9000@section Searching Source Files
15387254 9001@cindex searching source files
c906108c
SS
9002
9003There are two commands for searching through the current source file for a
9004regular expression.
9005
9006@table @code
9007@kindex search
9008@kindex forward-search
1e96de83 9009@kindex fo @r{(@code{forward-search})}
c906108c
SS
9010@item forward-search @var{regexp}
9011@itemx search @var{regexp}
9012The command @samp{forward-search @var{regexp}} checks each line,
9013starting with the one following the last line listed, for a match for
5d161b24 9014@var{regexp}. It lists the line that is found. You can use the
c906108c
SS
9015synonym @samp{search @var{regexp}} or abbreviate the command name as
9016@code{fo}.
9017
09d4efe1 9018@kindex reverse-search
c906108c
SS
9019@item reverse-search @var{regexp}
9020The command @samp{reverse-search @var{regexp}} checks each line, starting
9021with the one before the last line listed and going backward, for a match
9022for @var{regexp}. It lists the line that is found. You can abbreviate
9023this command as @code{rev}.
9024@end table
c906108c 9025
6d2ebf8b 9026@node Source Path
79a6e687 9027@section Specifying Source Directories
c906108c
SS
9028
9029@cindex source path
9030@cindex directories for source files
9031Executable programs sometimes do not record the directories of the source
9032files from which they were compiled, just the names. Even when they do,
9033the directories could be moved between the compilation and your debugging
9034session. @value{GDBN} has a list of directories to search for source files;
9035this is called the @dfn{source path}. Each time @value{GDBN} wants a source file,
9036it tries all the directories in the list, in the order they are present
0b66e38c
EZ
9037in the list, until it finds a file with the desired name.
9038
9039For example, suppose an executable references the file
f1b620e9
MG
9040@file{/usr/src/foo-1.0/lib/foo.c}, does not record a compilation
9041directory, and the @dfn{source path} is @file{/mnt/cross}.
9042@value{GDBN} would look for the source file in the following
9043locations:
9044
9045@enumerate
9046
9047@item @file{/usr/src/foo-1.0/lib/foo.c}
9048@item @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c}
9049@item @file{/mnt/cross/foo.c}
9050
9051@end enumerate
9052
9053If the source file is not present at any of the above locations then
9054an error is printed. @value{GDBN} does not look up the parts of the
0b66e38c
EZ
9055source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
9056Likewise, the subdirectories of the source path are not searched: if
9057the source path is @file{/mnt/cross}, and the binary refers to
9058@file{foo.c}, @value{GDBN} would not find it under
9059@file{/mnt/cross/usr/src/foo-1.0/lib}.
9060
9061Plain file names, relative file names with leading directories, file
f1b620e9
MG
9062names containing dots, etc.@: are all treated as described above,
9063except that non-absolute file names are not looked up literally. If
9064the @dfn{source path} is @file{/mnt/cross}, the source file is
9065recorded as @file{../lib/foo.c}, and no compilation directory is
9066recorded, then @value{GDBN} will search in the following locations:
9067
9068@enumerate
9069
9070@item @file{/mnt/cross/../lib/foo.c}
9071@item @file{/mnt/cross/foo.c}
9072
9073@end enumerate
9074
9075@kindex cdir
9076@kindex cwd
9077@vindex $cdir@r{, convenience variable}
9078@vindex $cwd@r{, convenience variable}
9079@cindex compilation directory
9080@cindex current directory
9081@cindex working directory
9082@cindex directory, current
9083@cindex directory, compilation
9084The @dfn{source path} will always include two special entries
9085@samp{$cdir} and @samp{$cwd}, these refer to the compilation directory
9086(if one is recorded) and the current working directory respectively.
9087
9088@samp{$cdir} causes @value{GDBN} to search within the compilation
9089directory, if one is recorded in the debug information. If no
9090compilation directory is recorded in the debug information then
9091@samp{$cdir} is ignored.
9092
9093@samp{$cwd} is not the same as @samp{.}---the former tracks the
9094current working directory as it changes during your @value{GDBN}
9095session, while the latter is immediately expanded to the current
9096directory at the time you add an entry to the source path.
9097
9098If a compilation directory is recorded in the debug information, and
9099@value{GDBN} has not found the source file after the first search
9100using @dfn{source path}, then @value{GDBN} will combine the
9101compilation directory and the filename, and then search for the source
9102file again using the @dfn{source path}.
9103
9104For example, if the executable records the source file as
9105@file{/usr/src/foo-1.0/lib/foo.c}, the compilation directory is
9106recorded as @file{/project/build}, and the @dfn{source path} is
9107@file{/mnt/cross:$cdir:$cwd} while the current working directory of
9108the @value{GDBN} session is @file{/home/user}, then @value{GDBN} will
6b92c0d3 9109search for the source file in the following locations:
f1b620e9
MG
9110
9111@enumerate
9112
9113@item @file{/usr/src/foo-1.0/lib/foo.c}
9114@item @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c}
9115@item @file{/project/build/usr/src/foo-1.0/lib/foo.c}
9116@item @file{/home/user/usr/src/foo-1.0/lib/foo.c}
9117@item @file{/mnt/cross/project/build/usr/src/foo-1.0/lib/foo.c}
9118@item @file{/project/build/project/build/usr/src/foo-1.0/lib/foo.c}
9119@item @file{/home/user/project/build/usr/src/foo-1.0/lib/foo.c}
9120@item @file{/mnt/cross/foo.c}
9121@item @file{/project/build/foo.c}
9122@item @file{/home/user/foo.c}
9123
9124@end enumerate
9125
9126If the file name in the previous example had been recorded in the
9127executable as a relative path rather than an absolute path, then the
9128first look up would not have occurred, but all of the remaining steps
9129would be similar.
9130
9131When searching for source files on MS-DOS and MS-Windows, where
9132absolute paths start with a drive letter (e.g.
9133@file{C:/project/foo.c}), @value{GDBN} will remove the drive letter
9134from the file name before appending it to a search directory from
9135@dfn{source path}; for instance if the executable references the
9136source file @file{C:/project/foo.c} and @dfn{source path} is set to
9137@file{D:/mnt/cross}, then @value{GDBN} will search in the following
9138locations for the source file:
9139
9140@enumerate
9141
9142@item @file{C:/project/foo.c}
9143@item @file{D:/mnt/cross/project/foo.c}
9144@item @file{D:/mnt/cross/foo.c}
9145
9146@end enumerate
0b66e38c
EZ
9147
9148Note that the executable search path is @emph{not} used to locate the
cd852561 9149source files.
c906108c
SS
9150
9151Whenever you reset or rearrange the source path, @value{GDBN} clears out
9152any information it has cached about where source files are found and where
9153each line is in the file.
9154
9155@kindex directory
9156@kindex dir
f1b620e9
MG
9157When you start @value{GDBN}, its source path includes only @samp{$cdir}
9158and @samp{$cwd}, in that order.
c906108c
SS
9159To add other directories, use the @code{directory} command.
9160
4b505b12
AS
9161The search path is used to find both program source files and @value{GDBN}
9162script files (read using the @samp{-command} option and @samp{source} command).
9163
30daae6c
JB
9164In addition to the source path, @value{GDBN} provides a set of commands
9165that manage a list of source path substitution rules. A @dfn{substitution
9166rule} specifies how to rewrite source directories stored in the program's
9167debug information in case the sources were moved to a different
9168directory between compilation and debugging. A rule is made of
9169two strings, the first specifying what needs to be rewritten in
9170the path, and the second specifying how it should be rewritten.
9171In @ref{set substitute-path}, we name these two parts @var{from} and
9172@var{to} respectively. @value{GDBN} does a simple string replacement
9173of @var{from} with @var{to} at the start of the directory part of the
9174source file name, and uses that result instead of the original file
9175name to look up the sources.
9176
9177Using the previous example, suppose the @file{foo-1.0} tree has been
9178moved from @file{/usr/src} to @file{/mnt/cross}, then you can tell
3f94c067 9179@value{GDBN} to replace @file{/usr/src} in all source path names with
30daae6c
JB
9180@file{/mnt/cross}. The first lookup will then be
9181@file{/mnt/cross/foo-1.0/lib/foo.c} in place of the original location
9182of @file{/usr/src/foo-1.0/lib/foo.c}. To define a source path
9183substitution rule, use the @code{set substitute-path} command
9184(@pxref{set substitute-path}).
9185
9186To avoid unexpected substitution results, a rule is applied only if the
9187@var{from} part of the directory name ends at a directory separator.
9188For instance, a rule substituting @file{/usr/source} into
9189@file{/mnt/cross} will be applied to @file{/usr/source/foo-1.0} but
9190not to @file{/usr/sourceware/foo-2.0}. And because the substitution
d3e8051b 9191is applied only at the beginning of the directory name, this rule will
30daae6c
JB
9192not be applied to @file{/root/usr/source/baz.c} either.
9193
9194In many cases, you can achieve the same result using the @code{directory}
9195command. However, @code{set substitute-path} can be more efficient in
9196the case where the sources are organized in a complex tree with multiple
9197subdirectories. With the @code{directory} command, you need to add each
9198subdirectory of your project. If you moved the entire tree while
9199preserving its internal organization, then @code{set substitute-path}
9200allows you to direct the debugger to all the sources with one single
9201command.
9202
9203@code{set substitute-path} is also more than just a shortcut command.
9204The source path is only used if the file at the original location no
9205longer exists. On the other hand, @code{set substitute-path} modifies
9206the debugger behavior to look at the rewritten location instead. So, if
9207for any reason a source file that is not relevant to your executable is
9208located at the original location, a substitution rule is the only
3f94c067 9209method available to point @value{GDBN} at the new location.
30daae6c 9210
29b0e8a2
JM
9211@cindex @samp{--with-relocated-sources}
9212@cindex default source path substitution
9213You can configure a default source path substitution rule by
9214configuring @value{GDBN} with the
9215@samp{--with-relocated-sources=@var{dir}} option. The @var{dir}
9216should be the name of a directory under @value{GDBN}'s configured
9217prefix (set with @samp{--prefix} or @samp{--exec-prefix}), and
9218directory names in debug information under @var{dir} will be adjusted
9219automatically if the installed @value{GDBN} is moved to a new
9220location. This is useful if @value{GDBN}, libraries or executables
9221with debug information and corresponding source code are being moved
9222together.
9223
c906108c
SS
9224@table @code
9225@item directory @var{dirname} @dots{}
9226@item dir @var{dirname} @dots{}
9227Add directory @var{dirname} to the front of the source path. Several
d4f3574e
SS
9228directory names may be given to this command, separated by @samp{:}
9229(@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
9230part of absolute file names) or
c906108c
SS
9231whitespace. You may specify a directory that is already in the source
9232path; this moves it forward, so @value{GDBN} searches it sooner.
9233
f1b620e9
MG
9234The special strings @samp{$cdir} (to refer to the compilation
9235directory, if one is recorded), and @samp{$cwd} (to refer to the
9236current working directory) can also be included in the list of
9237directories @var{dirname}. Though these will already be in the source
9238path they will be moved forward in the list so @value{GDBN} searches
9239them sooner.
c906108c
SS
9240
9241@item directory
cd852561 9242Reset the source path to its default value (@samp{$cdir:$cwd} on Unix systems). This requires confirmation.
c906108c
SS
9243
9244@c RET-repeat for @code{directory} is explicitly disabled, but since
9245@c repeating it would be a no-op we do not say that. (thanks to RMS)
9246
99e7ae30
DE
9247@item set directories @var{path-list}
9248@kindex set directories
9249Set the source path to @var{path-list}.
9250@samp{$cdir:$cwd} are added if missing.
9251
c906108c
SS
9252@item show directories
9253@kindex show directories
9254Print the source path: show which directories it contains.
30daae6c
JB
9255
9256@anchor{set substitute-path}
9257@item set substitute-path @var{from} @var{to}
9258@kindex set substitute-path
9259Define a source path substitution rule, and add it at the end of the
9260current list of existing substitution rules. If a rule with the same
9261@var{from} was already defined, then the old rule is also deleted.
9262
9263For example, if the file @file{/foo/bar/baz.c} was moved to
9264@file{/mnt/cross/baz.c}, then the command
9265
9266@smallexample
c58b006b 9267(@value{GDBP}) set substitute-path /foo/bar /mnt/cross
30daae6c
JB
9268@end smallexample
9269
9270@noindent
c58b006b 9271will tell @value{GDBN} to replace @samp{/foo/bar} with
30daae6c
JB
9272@samp{/mnt/cross}, which will allow @value{GDBN} to find the file
9273@file{baz.c} even though it was moved.
9274
9275In the case when more than one substitution rule have been defined,
9276the rules are evaluated one by one in the order where they have been
9277defined. The first one matching, if any, is selected to perform
9278the substitution.
9279
9280For instance, if we had entered the following commands:
9281
9282@smallexample
9283(@value{GDBP}) set substitute-path /usr/src/include /mnt/include
9284(@value{GDBP}) set substitute-path /usr/src /mnt/src
9285@end smallexample
9286
9287@noindent
9288@value{GDBN} would then rewrite @file{/usr/src/include/defs.h} into
9289@file{/mnt/include/defs.h} by using the first rule. However, it would
9290use the second rule to rewrite @file{/usr/src/lib/foo.c} into
9291@file{/mnt/src/lib/foo.c}.
9292
9293
9294@item unset substitute-path [path]
9295@kindex unset substitute-path
9296If a path is specified, search the current list of substitution rules
9297for a rule that would rewrite that path. Delete that rule if found.
9298A warning is emitted by the debugger if no rule could be found.
9299
9300If no path is specified, then all substitution rules are deleted.
9301
9302@item show substitute-path [path]
9303@kindex show substitute-path
9304If a path is specified, then print the source path substitution rule
9305which would rewrite that path, if any.
9306
9307If no path is specified, then print all existing source path substitution
9308rules.
9309
c906108c
SS
9310@end table
9311
9312If your source path is cluttered with directories that are no longer of
9313interest, @value{GDBN} may sometimes cause confusion by finding the wrong
9314versions of source. You can correct the situation as follows:
9315
9316@enumerate
9317@item
cd852561 9318Use @code{directory} with no argument to reset the source path to its default value.
c906108c
SS
9319
9320@item
9321Use @code{directory} with suitable arguments to reinstall the
9322directories you want in the source path. You can add all the
9323directories in one command.
9324@end enumerate
9325
6d2ebf8b 9326@node Machine Code
79a6e687 9327@section Source and Machine Code
15387254 9328@cindex source line and its code address
c906108c
SS
9329
9330You can use the command @code{info line} to map source lines to program
9331addresses (and vice versa), and the command @code{disassemble} to display
91440f57
HZ
9332a range of addresses as machine instructions. You can use the command
9333@code{set disassemble-next-line} to set whether to disassemble next
9334source line when execution stops. When run under @sc{gnu} Emacs
d4f3574e 9335mode, the @code{info line} command causes the arrow to point to the
5d161b24 9336line specified. Also, @code{info line} prints addresses in symbolic form as
c906108c
SS
9337well as hex.
9338
9339@table @code
9340@kindex info line
db1ae9c5
AB
9341@item info line
9342@itemx info line @var{location}
c906108c 9343Print the starting and ending addresses of the compiled code for
629500fa 9344source line @var{location}. You can specify source lines in any of
db1ae9c5
AB
9345the ways documented in @ref{Specify Location}. With no @var{location}
9346information about the current source line is printed.
c906108c
SS
9347@end table
9348
9349For example, we can use @code{info line} to discover the location of
9350the object code for the first line of function
9351@code{m4_changequote}:
9352
9353@smallexample
96a2c332 9354(@value{GDBP}) info line m4_changequote
db1ae9c5
AB
9355Line 895 of "builtin.c" starts at pc 0x634c <m4_changequote> and \
9356 ends at 0x6350 <m4_changequote+4>.
c906108c
SS
9357@end smallexample
9358
9359@noindent
15387254 9360@cindex code address and its source line
c906108c 9361We can also inquire (using @code{*@var{addr}} as the form for
629500fa 9362@var{location}) what source line covers a particular address:
c906108c
SS
9363@smallexample
9364(@value{GDBP}) info line *0x63ff
db1ae9c5
AB
9365Line 926 of "builtin.c" starts at pc 0x63e4 <m4_changequote+152> and \
9366 ends at 0x6404 <m4_changequote+184>.
c906108c
SS
9367@end smallexample
9368
9369@cindex @code{$_} and @code{info line}
15387254 9370@cindex @code{x} command, default address
41afff9a 9371@kindex x@r{(examine), and} info line
c906108c
SS
9372After @code{info line}, the default address for the @code{x} command
9373is changed to the starting address of the line, so that @samp{x/i} is
9374sufficient to begin examining the machine code (@pxref{Memory,
79a6e687 9375,Examining Memory}). Also, this address is saved as the value of the
c906108c 9376convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
79a6e687 9377Variables}).
c906108c 9378
db1ae9c5
AB
9379@cindex info line, repeated calls
9380After @code{info line}, using @code{info line} again without
9381specifying a location will display information about the next source
9382line.
9383
c906108c
SS
9384@table @code
9385@kindex disassemble
9386@cindex assembly instructions
9387@cindex instructions, assembly
9388@cindex machine instructions
9389@cindex listing machine instructions
9390@item disassemble
d14508fe 9391@itemx disassemble /m
6ff0ba5f 9392@itemx disassemble /s
9b117ef3 9393@itemx disassemble /r
c906108c 9394This specialized command dumps a range of memory as machine
d14508fe 9395instructions. It can also print mixed source+disassembly by specifying
6ff0ba5f
DE
9396the @code{/m} or @code{/s} modifier and print the raw instructions in hex
9397as well as in symbolic form by specifying the @code{/r} modifier.
d14508fe 9398The default memory range is the function surrounding the
c906108c
SS
9399program counter of the selected frame. A single argument to this
9400command is a program counter value; @value{GDBN} dumps the function
21a0512e
PP
9401surrounding this value. When two arguments are given, they should
9402be separated by a comma, possibly surrounded by whitespace. The
53a71c06
CR
9403arguments specify a range of addresses to dump, in one of two forms:
9404
9405@table @code
9406@item @var{start},@var{end}
9407the addresses from @var{start} (inclusive) to @var{end} (exclusive)
9408@item @var{start},+@var{length}
9409the addresses from @var{start} (inclusive) to
9410@code{@var{start}+@var{length}} (exclusive).
9411@end table
9412
9413@noindent
9414When 2 arguments are specified, the name of the function is also
9415printed (since there could be several functions in the given range).
21a0512e
PP
9416
9417The argument(s) can be any expression yielding a numeric value, such as
9418@samp{0x32c4}, @samp{&main+10} or @samp{$pc - 8}.
2b28d209
PP
9419
9420If the range of memory being disassembled contains current program counter,
9421the instruction at that location is shown with a @code{=>} marker.
c906108c
SS
9422@end table
9423
c906108c
SS
9424The following example shows the disassembly of a range of addresses of
9425HP PA-RISC 2.0 code:
9426
9427@smallexample
21a0512e 9428(@value{GDBP}) disas 0x32c4, 0x32e4
c906108c 9429Dump of assembler code from 0x32c4 to 0x32e4:
2b28d209
PP
9430 0x32c4 <main+204>: addil 0,dp
9431 0x32c8 <main+208>: ldw 0x22c(sr0,r1),r26
9432 0x32cc <main+212>: ldil 0x3000,r31
9433 0x32d0 <main+216>: ble 0x3f8(sr4,r31)
9434 0x32d4 <main+220>: ldo 0(r31),rp
9435 0x32d8 <main+224>: addil -0x800,dp
9436 0x32dc <main+228>: ldo 0x588(r1),r26
9437 0x32e0 <main+232>: ldil 0x3000,r31
c906108c
SS
9438End of assembler dump.
9439@end smallexample
c906108c 9440
6ff0ba5f
DE
9441Here is an example showing mixed source+assembly for Intel x86
9442with @code{/m} or @code{/s}, when the program is stopped just after
9443function prologue in a non-optimized function with no inline code.
d14508fe
DE
9444
9445@smallexample
9446(@value{GDBP}) disas /m main
9447Dump of assembler code for function main:
94485 @{
9c419145
PP
9449 0x08048330 <+0>: push %ebp
9450 0x08048331 <+1>: mov %esp,%ebp
9451 0x08048333 <+3>: sub $0x8,%esp
9452 0x08048336 <+6>: and $0xfffffff0,%esp
9453 0x08048339 <+9>: sub $0x10,%esp
d14508fe
DE
9454
94556 printf ("Hello.\n");
9c419145
PP
9456=> 0x0804833c <+12>: movl $0x8048440,(%esp)
9457 0x08048343 <+19>: call 0x8048284 <puts@@plt>
d14508fe
DE
9458
94597 return 0;
94608 @}
9c419145
PP
9461 0x08048348 <+24>: mov $0x0,%eax
9462 0x0804834d <+29>: leave
9463 0x0804834e <+30>: ret
d14508fe
DE
9464
9465End of assembler dump.
9466@end smallexample
9467
6ff0ba5f
DE
9468The @code{/m} option is deprecated as its output is not useful when
9469there is either inlined code or re-ordered code.
9470The @code{/s} option is the preferred choice.
9471Here is an example for AMD x86-64 showing the difference between
9472@code{/m} output and @code{/s} output.
9473This example has one inline function defined in a header file,
9474and the code is compiled with @samp{-O2} optimization.
9475Note how the @code{/m} output is missing the disassembly of
9476several instructions that are present in the @code{/s} output.
9477
9478@file{foo.h}:
9479
9480@smallexample
9481int
9482foo (int a)
9483@{
9484 if (a < 0)
9485 return a * 2;
9486 if (a == 0)
9487 return 1;
9488 return a + 10;
9489@}
9490@end smallexample
9491
9492@file{foo.c}:
9493
9494@smallexample
9495#include "foo.h"
9496volatile int x, y;
9497int
9498main ()
9499@{
9500 x = foo (y);
9501 return 0;
9502@}
9503@end smallexample
9504
9505@smallexample
9506(@value{GDBP}) disas /m main
9507Dump of assembler code for function main:
95085 @{
9509
95106 x = foo (y);
9511 0x0000000000400400 <+0>: mov 0x200c2e(%rip),%eax # 0x601034 <y>
9512 0x0000000000400417 <+23>: mov %eax,0x200c13(%rip) # 0x601030 <x>
9513
95147 return 0;
95158 @}
9516 0x000000000040041d <+29>: xor %eax,%eax
9517 0x000000000040041f <+31>: retq
9518 0x0000000000400420 <+32>: add %eax,%eax
9519 0x0000000000400422 <+34>: jmp 0x400417 <main+23>
9520
9521End of assembler dump.
9522(@value{GDBP}) disas /s main
9523Dump of assembler code for function main:
9524foo.c:
95255 @{
95266 x = foo (y);
9527 0x0000000000400400 <+0>: mov 0x200c2e(%rip),%eax # 0x601034 <y>
9528
9529foo.h:
95304 if (a < 0)
9531 0x0000000000400406 <+6>: test %eax,%eax
9532 0x0000000000400408 <+8>: js 0x400420 <main+32>
9533
95346 if (a == 0)
95357 return 1;
95368 return a + 10;
9537 0x000000000040040a <+10>: lea 0xa(%rax),%edx
9538 0x000000000040040d <+13>: test %eax,%eax
9539 0x000000000040040f <+15>: mov $0x1,%eax
9540 0x0000000000400414 <+20>: cmovne %edx,%eax
9541
9542foo.c:
95436 x = foo (y);
9544 0x0000000000400417 <+23>: mov %eax,0x200c13(%rip) # 0x601030 <x>
9545
95467 return 0;
95478 @}
9548 0x000000000040041d <+29>: xor %eax,%eax
9549 0x000000000040041f <+31>: retq
9550
9551foo.h:
95525 return a * 2;
9553 0x0000000000400420 <+32>: add %eax,%eax
9554 0x0000000000400422 <+34>: jmp 0x400417 <main+23>
9555End of assembler dump.
9556@end smallexample
9557
53a71c06
CR
9558Here is another example showing raw instructions in hex for AMD x86-64,
9559
9560@smallexample
9561(gdb) disas /r 0x400281,+10
9562Dump of assembler code from 0x400281 to 0x40028b:
9563 0x0000000000400281: 38 36 cmp %dh,(%rsi)
9564 0x0000000000400283: 2d 36 34 2e 73 sub $0x732e3436,%eax
9565 0x0000000000400288: 6f outsl %ds:(%rsi),(%dx)
9566 0x0000000000400289: 2e 32 00 xor %cs:(%rax),%al
9567End of assembler dump.
9568@end smallexample
9569
629500fa 9570Addresses cannot be specified as a location (@pxref{Specify Location}).
7e1e0340
DE
9571So, for example, if you want to disassemble function @code{bar}
9572in file @file{foo.c}, you must type @samp{disassemble 'foo.c'::bar}
9573and not @samp{disassemble foo.c:bar}.
9574
c906108c
SS
9575Some architectures have more than one commonly-used set of instruction
9576mnemonics or other syntax.
9577
76d17f34
EZ
9578For programs that were dynamically linked and use shared libraries,
9579instructions that call functions or branch to locations in the shared
9580libraries might show a seemingly bogus location---it's actually a
9581location of the relocation table. On some architectures, @value{GDBN}
9582might be able to resolve these to actual function names.
9583
65b48a81
PB
9584@table @code
9585@kindex set disassembler-options
9586@cindex disassembler options
9587@item set disassembler-options @var{option1}[,@var{option2}@dots{}]
9588This command controls the passing of target specific information to
9589the disassembler. For a list of valid options, please refer to the
9590@code{-M}/@code{--disassembler-options} section of the @samp{objdump}
9591manual and/or the output of @kbd{objdump --help}
f5a476a7 9592(@pxref{objdump,,objdump,binutils,The GNU Binary Utilities}).
65b48a81
PB
9593The default value is the empty string.
9594
9595If it is necessary to specify more than one disassembler option, then
9596multiple options can be placed together into a comma separated list.
471b9d15 9597Currently this command is only supported on targets ARM, MIPS, PowerPC
65b48a81
PB
9598and S/390.
9599
9600@kindex show disassembler-options
9601@item show disassembler-options
9602Show the current setting of the disassembler options.
9603@end table
9604
c906108c 9605@table @code
d4f3574e 9606@kindex set disassembly-flavor
d4f3574e
SS
9607@cindex Intel disassembly flavor
9608@cindex AT&T disassembly flavor
9609@item set disassembly-flavor @var{instruction-set}
c906108c
SS
9610Select the instruction set to use when disassembling the
9611program via the @code{disassemble} or @code{x/i} commands.
9612
9613Currently this command is only defined for the Intel x86 family. You
d4f3574e
SS
9614can set @var{instruction-set} to either @code{intel} or @code{att}.
9615The default is @code{att}, the AT&T flavor used by default by Unix
9616assemblers for x86-based targets.
9c16f35a
EZ
9617
9618@kindex show disassembly-flavor
9619@item show disassembly-flavor
9620Show the current setting of the disassembly flavor.
c906108c
SS
9621@end table
9622
91440f57
HZ
9623@table @code
9624@kindex set disassemble-next-line
9625@kindex show disassemble-next-line
9626@item set disassemble-next-line
9627@itemx show disassemble-next-line
32ae1842
EZ
9628Control whether or not @value{GDBN} will disassemble the next source
9629line or instruction when execution stops. If ON, @value{GDBN} will
9630display disassembly of the next source line when execution of the
9631program being debugged stops. This is @emph{in addition} to
9632displaying the source line itself, which @value{GDBN} always does if
9633possible. If the next source line cannot be displayed for some reason
9634(e.g., if @value{GDBN} cannot find the source file, or there's no line
9635info in the debug info), @value{GDBN} will display disassembly of the
9636next @emph{instruction} instead of showing the next source line. If
9637AUTO, @value{GDBN} will display disassembly of next instruction only
9638if the source line cannot be displayed. This setting causes
9639@value{GDBN} to display some feedback when you step through a function
9640with no line info or whose source file is unavailable. The default is
9641OFF, which means never display the disassembly of the next line or
9642instruction.
91440f57
HZ
9643@end table
9644
c906108c 9645
6d2ebf8b 9646@node Data
c906108c
SS
9647@chapter Examining Data
9648
9649@cindex printing data
9650@cindex examining data
9651@kindex print
9652@kindex inspect
c906108c 9653The usual way to examine data in your program is with the @code{print}
7a292a7a
SS
9654command (abbreviated @code{p}), or its synonym @code{inspect}. It
9655evaluates and prints the value of an expression of the language your
9656program is written in (@pxref{Languages, ,Using @value{GDBN} with
78e2826b
TT
9657Different Languages}). It may also print the expression using a
9658Python-based pretty-printer (@pxref{Pretty Printing}).
c906108c
SS
9659
9660@table @code
3345721a
PA
9661@item print [[@var{options}] --] @var{expr}
9662@itemx print [[@var{options}] --] /@var{f} @var{expr}
d4f3574e
SS
9663@var{expr} is an expression (in the source language). By default the
9664value of @var{expr} is printed in a format appropriate to its data type;
c906108c 9665you can choose a different format by specifying @samp{/@var{f}}, where
d4f3574e 9666@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
79a6e687 9667Formats}.
c906108c 9668
3345721a
PA
9669@anchor{print options}
9670The @code{print} command supports a number of options that allow
9671overriding relevant global print settings as set by @code{set print}
9672subcommands:
9673
9674@table @code
9675@item -address [@code{on}|@code{off}]
9676Set printing of addresses.
9677Related setting: @ref{set print address}.
9678
9679@item -array [@code{on}|@code{off}]
9680Pretty formatting of arrays.
9681Related setting: @ref{set print array}.
9682
9683@item -array-indexes [@code{on}|@code{off}]
9684Set printing of array indexes.
9685Related setting: @ref{set print array-indexes}.
9686
9687@item -elements @var{number-of-elements}|@code{unlimited}
9688Set limit on string chars or array elements to print. The value
9689@code{unlimited} causes there to be no limit. Related setting:
9690@ref{set print elements}.
9691
9692@item -max-depth @var{depth}|@code{unlimited}
9693Set the threshold after which nested structures are replaced with
9694ellipsis. Related setting: @ref{set print max-depth}.
9695
9696@item -null-stop [@code{on}|@code{off}]
9697Set printing of char arrays to stop at first null char. Related
9698setting: @ref{set print null-stop}.
9699
9700@item -object [@code{on}|@code{off}]
9701Set printing C@t{++} virtual function tables. Related setting:
9702@ref{set print object}.
9703
9704@item -pretty [@code{on}|@code{off}]
9705Set pretty formatting of structures. Related setting: @ref{set print
9706pretty}.
9707
d8edc8b7
PW
9708@item -raw-values [@code{on}|@code{off}]
9709Set whether to print values in raw form, bypassing any
9710pretty-printers for that value. Related setting: @ref{set print
9711raw-values}.
9712
3345721a
PA
9713@item -repeats @var{number-of-repeats}|@code{unlimited}
9714Set threshold for repeated print elements. @code{unlimited} causes
9715all elements to be individually printed. Related setting: @ref{set
9716print repeats}.
9717
9718@item -static-members [@code{on}|@code{off}]
9719Set printing C@t{++} static members. Related setting: @ref{set print
9720static-members}.
9721
9722@item -symbol [@code{on}|@code{off}]
9723Set printing of symbol names when printing pointers. Related setting:
9724@ref{set print symbol}.
9725
9726@item -union [@code{on}|@code{off}]
9727Set printing of unions interior to structures. Related setting:
9728@ref{set print union}.
9729
9730@item -vtbl [@code{on}|@code{off}]
9731Set printing of C++ virtual function tables. Related setting:
9732@ref{set print vtbl}.
9733@end table
9734
9735Because the @code{print} command accepts arbitrary expressions which
9736may look like options (including abbreviations), if you specify any
9737command option, then you must use a double dash (@code{--}) to mark
9738the end of option processing.
9739
d8edc8b7 9740For example, this prints the value of the @code{-p} expression:
3345721a
PA
9741
9742@smallexample
d8edc8b7 9743(@value{GDBP}) print -p
3345721a
PA
9744@end smallexample
9745
9746While this repeats the last value in the value history (see below)
d8edc8b7 9747with the @code{-pretty} option in effect:
3345721a
PA
9748
9749@smallexample
d8edc8b7 9750(@value{GDBP}) print -p --
3345721a
PA
9751@end smallexample
9752
9753Here is an example including both on option and an expression:
9754
9755@smallexample
9756@group
9757(@value{GDBP}) print -pretty -- *myptr
9758$1 = @{
9759 next = 0x0,
9760 flags = @{
9761 sweet = 1,
9762 sour = 1
9763 @},
9764 meat = 0x54 "Pork"
9765@}
9766@end group
9767@end smallexample
9768
9769@item print [@var{options}]
9770@itemx print [@var{options}] /@var{f}
15387254 9771@cindex reprint the last value
d4f3574e 9772If you omit @var{expr}, @value{GDBN} displays the last value again (from the
79a6e687 9773@dfn{value history}; @pxref{Value History, ,Value History}). This allows you to
c906108c
SS
9774conveniently inspect the same value in an alternative format.
9775@end table
9776
9777A more low-level way of examining data is with the @code{x} command.
9778It examines data in memory at a specified address and prints it in a
79a6e687 9779specified format. @xref{Memory, ,Examining Memory}.
c906108c 9780
7a292a7a 9781If you are interested in information about types, or about how the
d4f3574e
SS
9782fields of a struct or a class are declared, use the @code{ptype @var{exp}}
9783command rather than @code{print}. @xref{Symbols, ,Examining the Symbol
7a292a7a 9784Table}.
c906108c 9785
06fc020f
SCR
9786@cindex exploring hierarchical data structures
9787@kindex explore
9788Another way of examining values of expressions and type information is
9789through the Python extension command @code{explore} (available only if
9790the @value{GDBN} build is configured with @code{--with-python}). It
9791offers an interactive way to start at the highest level (or, the most
9792abstract level) of the data type of an expression (or, the data type
9793itself) and explore all the way down to leaf scalar values/fields
9794embedded in the higher level data types.
9795
9796@table @code
9797@item explore @var{arg}
9798@var{arg} is either an expression (in the source language), or a type
9799visible in the current context of the program being debugged.
9800@end table
9801
9802The working of the @code{explore} command can be illustrated with an
9803example. If a data type @code{struct ComplexStruct} is defined in your
9804C program as
9805
9806@smallexample
9807struct SimpleStruct
9808@{
9809 int i;
9810 double d;
9811@};
9812
9813struct ComplexStruct
9814@{
9815 struct SimpleStruct *ss_p;
9816 int arr[10];
9817@};
9818@end smallexample
9819
9820@noindent
9821followed by variable declarations as
9822
9823@smallexample
9824struct SimpleStruct ss = @{ 10, 1.11 @};
9825struct ComplexStruct cs = @{ &ss, @{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 @} @};
9826@end smallexample
9827
9828@noindent
9829then, the value of the variable @code{cs} can be explored using the
9830@code{explore} command as follows.
9831
9832@smallexample
9833(gdb) explore cs
9834The value of `cs' is a struct/class of type `struct ComplexStruct' with
9835the following fields:
9836
9837 ss_p = <Enter 0 to explore this field of type `struct SimpleStruct *'>
9838 arr = <Enter 1 to explore this field of type `int [10]'>
9839
9840Enter the field number of choice:
9841@end smallexample
9842
9843@noindent
9844Since the fields of @code{cs} are not scalar values, you are being
9845prompted to chose the field you want to explore. Let's say you choose
9846the field @code{ss_p} by entering @code{0}. Then, since this field is a
9847pointer, you will be asked if it is pointing to a single value. From
9848the declaration of @code{cs} above, it is indeed pointing to a single
9849value, hence you enter @code{y}. If you enter @code{n}, then you will
9850be asked if it were pointing to an array of values, in which case this
9851field will be explored as if it were an array.
9852
9853@smallexample
9854`cs.ss_p' is a pointer to a value of type `struct SimpleStruct'
9855Continue exploring it as a pointer to a single value [y/n]: y
9856The value of `*(cs.ss_p)' is a struct/class of type `struct
9857SimpleStruct' with the following fields:
9858
9859 i = 10 .. (Value of type `int')
9860 d = 1.1100000000000001 .. (Value of type `double')
9861
9862Press enter to return to parent value:
9863@end smallexample
9864
9865@noindent
9866If the field @code{arr} of @code{cs} was chosen for exploration by
9867entering @code{1} earlier, then since it is as array, you will be
9868prompted to enter the index of the element in the array that you want
9869to explore.
9870
9871@smallexample
9872`cs.arr' is an array of `int'.
9873Enter the index of the element you want to explore in `cs.arr': 5
9874
9875`(cs.arr)[5]' is a scalar value of type `int'.
9876
9877(cs.arr)[5] = 4
9878
9879Press enter to return to parent value:
9880@end smallexample
9881
9882In general, at any stage of exploration, you can go deeper towards the
9883leaf values by responding to the prompts appropriately, or hit the
9884return key to return to the enclosing data structure (the @i{higher}
9885level data structure).
9886
9887Similar to exploring values, you can use the @code{explore} command to
9888explore types. Instead of specifying a value (which is typically a
9889variable name or an expression valid in the current context of the
9890program being debugged), you specify a type name. If you consider the
9891same example as above, your can explore the type
9892@code{struct ComplexStruct} by passing the argument
9893@code{struct ComplexStruct} to the @code{explore} command.
9894
9895@smallexample
9896(gdb) explore struct ComplexStruct
9897@end smallexample
9898
9899@noindent
9900By responding to the prompts appropriately in the subsequent interactive
9901session, you can explore the type @code{struct ComplexStruct} in a
9902manner similar to how the value @code{cs} was explored in the above
9903example.
9904
9905The @code{explore} command also has two sub-commands,
9906@code{explore value} and @code{explore type}. The former sub-command is
9907a way to explicitly specify that value exploration of the argument is
9908being invoked, while the latter is a way to explicitly specify that type
9909exploration of the argument is being invoked.
9910
9911@table @code
9912@item explore value @var{expr}
9913@cindex explore value
9914This sub-command of @code{explore} explores the value of the
9915expression @var{expr} (if @var{expr} is an expression valid in the
9916current context of the program being debugged). The behavior of this
9917command is identical to that of the behavior of the @code{explore}
9918command being passed the argument @var{expr}.
9919
9920@item explore type @var{arg}
9921@cindex explore type
9922This sub-command of @code{explore} explores the type of @var{arg} (if
9923@var{arg} is a type visible in the current context of program being
9924debugged), or the type of the value/expression @var{arg} (if @var{arg}
9925is an expression valid in the current context of the program being
9926debugged). If @var{arg} is a type, then the behavior of this command is
9927identical to that of the @code{explore} command being passed the
9928argument @var{arg}. If @var{arg} is an expression, then the behavior of
9929this command will be identical to that of the @code{explore} command
9930being passed the type of @var{arg} as the argument.
9931@end table
9932
c906108c
SS
9933@menu
9934* Expressions:: Expressions
6ba66d6a 9935* Ambiguous Expressions:: Ambiguous Expressions
c906108c
SS
9936* Variables:: Program variables
9937* Arrays:: Artificial arrays
9938* Output Formats:: Output formats
9939* Memory:: Examining memory
9940* Auto Display:: Automatic display
9941* Print Settings:: Print settings
4c374409 9942* Pretty Printing:: Python pretty printing
c906108c
SS
9943* Value History:: Value history
9944* Convenience Vars:: Convenience variables
a72c3253 9945* Convenience Funs:: Convenience functions
c906108c 9946* Registers:: Registers
c906108c 9947* Floating Point Hardware:: Floating point hardware
53c69bd7 9948* Vector Unit:: Vector Unit
721c2651 9949* OS Information:: Auxiliary data provided by operating system
29e57380 9950* Memory Region Attributes:: Memory region attributes
16d9dec6 9951* Dump/Restore Files:: Copy between memory and a file
384ee23f 9952* Core File Generation:: Cause a program dump its core
a0eb71c5
KB
9953* Character Sets:: Debugging programs that use a different
9954 character set than GDB does
b12039c6 9955* Caching Target Data:: Data caching for targets
08388c79 9956* Searching Memory:: Searching memory for a sequence of bytes
5fdf6324 9957* Value Sizes:: Managing memory allocated for values
c906108c
SS
9958@end menu
9959
6d2ebf8b 9960@node Expressions
c906108c
SS
9961@section Expressions
9962
9963@cindex expressions
9964@code{print} and many other @value{GDBN} commands accept an expression and
9965compute its value. Any kind of constant, variable or operator defined
9966by the programming language you are using is valid in an expression in
e2e0bcd1
JB
9967@value{GDBN}. This includes conditional expressions, function calls,
9968casts, and string constants. It also includes preprocessor macros, if
9969you compiled your program to include this information; see
9970@ref{Compilation}.
c906108c 9971
15387254 9972@cindex arrays in expressions
d4f3574e
SS
9973@value{GDBN} supports array constants in expressions input by
9974the user. The syntax is @{@var{element}, @var{element}@dots{}@}. For example,
63092375
DJ
9975you can use the command @code{print @{1, 2, 3@}} to create an array
9976of three integers. If you pass an array to a function or assign it
9977to a program variable, @value{GDBN} copies the array to memory that
9978is @code{malloc}ed in the target program.
c906108c 9979
c906108c
SS
9980Because C is so widespread, most of the expressions shown in examples in
9981this manual are in C. @xref{Languages, , Using @value{GDBN} with Different
9982Languages}, for information on how to use expressions in other
9983languages.
9984
9985In this section, we discuss operators that you can use in @value{GDBN}
9986expressions regardless of your programming language.
9987
15387254 9988@cindex casts, in expressions
c906108c
SS
9989Casts are supported in all languages, not just in C, because it is so
9990useful to cast a number into a pointer in order to examine a structure
9991at that address in memory.
9992@c FIXME: casts supported---Mod2 true?
c906108c
SS
9993
9994@value{GDBN} supports these operators, in addition to those common
9995to programming languages:
9996
9997@table @code
9998@item @@
9999@samp{@@} is a binary operator for treating parts of memory as arrays.
79a6e687 10000@xref{Arrays, ,Artificial Arrays}, for more information.
c906108c
SS
10001
10002@item ::
10003@samp{::} allows you to specify a variable in terms of the file or
79a6e687 10004function where it is defined. @xref{Variables, ,Program Variables}.
c906108c
SS
10005
10006@cindex @{@var{type}@}
10007@cindex type casting memory
10008@cindex memory, viewing as typed object
10009@cindex casts, to view memory
10010@item @{@var{type}@} @var{addr}
10011Refers to an object of type @var{type} stored at address @var{addr} in
697aa1b7
EZ
10012memory. The address @var{addr} may be any expression whose value is
10013an integer or pointer (but parentheses are required around binary
10014operators, just as in a cast). This construct is allowed regardless
10015of what kind of data is normally supposed to reside at @var{addr}.
c906108c
SS
10016@end table
10017
6ba66d6a
JB
10018@node Ambiguous Expressions
10019@section Ambiguous Expressions
10020@cindex ambiguous expressions
10021
10022Expressions can sometimes contain some ambiguous elements. For instance,
10023some programming languages (notably Ada, C@t{++} and Objective-C) permit
10024a single function name to be defined several times, for application in
10025different contexts. This is called @dfn{overloading}. Another example
10026involving Ada is generics. A @dfn{generic package} is similar to C@t{++}
10027templates and is typically instantiated several times, resulting in
10028the same function name being defined in different contexts.
10029
10030In some cases and depending on the language, it is possible to adjust
10031the expression to remove the ambiguity. For instance in C@t{++}, you
10032can specify the signature of the function you want to break on, as in
10033@kbd{break @var{function}(@var{types})}. In Ada, using the fully
10034qualified name of your function often makes the expression unambiguous
10035as well.
10036
10037When an ambiguity that needs to be resolved is detected, the debugger
10038has the capability to display a menu of numbered choices for each
10039possibility, and then waits for the selection with the prompt @samp{>}.
10040The first option is always @samp{[0] cancel}, and typing @kbd{0 @key{RET}}
10041aborts the current command. If the command in which the expression was
10042used allows more than one choice to be selected, the next option in the
10043menu is @samp{[1] all}, and typing @kbd{1 @key{RET}} selects all possible
10044choices.
10045
10046For example, the following session excerpt shows an attempt to set a
10047breakpoint at the overloaded symbol @code{String::after}.
10048We choose three particular definitions of that function name:
10049
10050@c FIXME! This is likely to change to show arg type lists, at least
10051@smallexample
10052@group
10053(@value{GDBP}) b String::after
10054[0] cancel
10055[1] all
10056[2] file:String.cc; line number:867
10057[3] file:String.cc; line number:860
10058[4] file:String.cc; line number:875
10059[5] file:String.cc; line number:853
10060[6] file:String.cc; line number:846
10061[7] file:String.cc; line number:735
10062> 2 4 6
10063Breakpoint 1 at 0xb26c: file String.cc, line 867.
10064Breakpoint 2 at 0xb344: file String.cc, line 875.
10065Breakpoint 3 at 0xafcc: file String.cc, line 846.
10066Multiple breakpoints were set.
10067Use the "delete" command to delete unwanted
10068 breakpoints.
10069(@value{GDBP})
10070@end group
10071@end smallexample
10072
10073@table @code
10074@kindex set multiple-symbols
10075@item set multiple-symbols @var{mode}
10076@cindex multiple-symbols menu
10077
10078This option allows you to adjust the debugger behavior when an expression
10079is ambiguous.
10080
10081By default, @var{mode} is set to @code{all}. If the command with which
10082the expression is used allows more than one choice, then @value{GDBN}
10083automatically selects all possible choices. For instance, inserting
10084a breakpoint on a function using an ambiguous name results in a breakpoint
10085inserted on each possible match. However, if a unique choice must be made,
10086then @value{GDBN} uses the menu to help you disambiguate the expression.
10087For instance, printing the address of an overloaded function will result
10088in the use of the menu.
10089
10090When @var{mode} is set to @code{ask}, the debugger always uses the menu
10091when an ambiguity is detected.
10092
10093Finally, when @var{mode} is set to @code{cancel}, the debugger reports
10094an error due to the ambiguity and the command is aborted.
10095
10096@kindex show multiple-symbols
10097@item show multiple-symbols
10098Show the current value of the @code{multiple-symbols} setting.
10099@end table
10100
6d2ebf8b 10101@node Variables
79a6e687 10102@section Program Variables
c906108c
SS
10103
10104The most common kind of expression to use is the name of a variable
10105in your program.
10106
10107Variables in expressions are understood in the selected stack frame
79a6e687 10108(@pxref{Selection, ,Selecting a Frame}); they must be either:
c906108c
SS
10109
10110@itemize @bullet
10111@item
10112global (or file-static)
10113@end itemize
10114
5d161b24 10115@noindent or
c906108c
SS
10116
10117@itemize @bullet
10118@item
10119visible according to the scope rules of the
10120programming language from the point of execution in that frame
5d161b24 10121@end itemize
c906108c
SS
10122
10123@noindent This means that in the function
10124
474c8240 10125@smallexample
c906108c
SS
10126foo (a)
10127 int a;
10128@{
10129 bar (a);
10130 @{
10131 int b = test ();
10132 bar (b);
10133 @}
10134@}
474c8240 10135@end smallexample
c906108c
SS
10136
10137@noindent
10138you can examine and use the variable @code{a} whenever your program is
10139executing within the function @code{foo}, but you can only use or
10140examine the variable @code{b} while your program is executing inside
10141the block where @code{b} is declared.
10142
10143@cindex variable name conflict
10144There is an exception: you can refer to a variable or function whose
10145scope is a single source file even if the current execution point is not
10146in this file. But it is possible to have more than one such variable or
10147function with the same name (in different source files). If that
10148happens, referring to that name has unpredictable effects. If you wish,
72384ba3 10149you can specify a static variable in a particular function or file by
15387254 10150using the colon-colon (@code{::}) notation:
c906108c 10151
d4f3574e 10152@cindex colon-colon, context for variables/functions
12c27660 10153@ifnotinfo
c906108c 10154@c info cannot cope with a :: index entry, but why deprive hard copy readers?
41afff9a 10155@cindex @code{::}, context for variables/functions
12c27660 10156@end ifnotinfo
474c8240 10157@smallexample
c906108c
SS
10158@var{file}::@var{variable}
10159@var{function}::@var{variable}
474c8240 10160@end smallexample
c906108c
SS
10161
10162@noindent
10163Here @var{file} or @var{function} is the name of the context for the
10164static @var{variable}. In the case of file names, you can use quotes to
10165make sure @value{GDBN} parses the file name as a single word---for example,
10166to print a global value of @code{x} defined in @file{f2.c}:
10167
474c8240 10168@smallexample
c906108c 10169(@value{GDBP}) p 'f2.c'::x
474c8240 10170@end smallexample
c906108c 10171
72384ba3
PH
10172The @code{::} notation is normally used for referring to
10173static variables, since you typically disambiguate uses of local variables
10174in functions by selecting the appropriate frame and using the
10175simple name of the variable. However, you may also use this notation
10176to refer to local variables in frames enclosing the selected frame:
10177
10178@smallexample
10179void
10180foo (int a)
10181@{
10182 if (a < 10)
10183 bar (a);
10184 else
10185 process (a); /* Stop here */
10186@}
10187
10188int
10189bar (int a)
10190@{
10191 foo (a + 5);
10192@}
10193@end smallexample
10194
10195@noindent
10196For example, if there is a breakpoint at the commented line,
10197here is what you might see
10198when the program stops after executing the call @code{bar(0)}:
10199
10200@smallexample
10201(@value{GDBP}) p a
10202$1 = 10
10203(@value{GDBP}) p bar::a
10204$2 = 5
10205(@value{GDBP}) up 2
10206#2 0x080483d0 in foo (a=5) at foobar.c:12
10207(@value{GDBP}) p a
10208$3 = 5
10209(@value{GDBP}) p bar::a
10210$4 = 0
10211@end smallexample
10212
b37052ae 10213@cindex C@t{++} scope resolution
805e1f19
TT
10214These uses of @samp{::} are very rarely in conflict with the very
10215similar use of the same notation in C@t{++}. When they are in
10216conflict, the C@t{++} meaning takes precedence; however, this can be
10217overridden by quoting the file or function name with single quotes.
10218
10219For example, suppose the program is stopped in a method of a class
10220that has a field named @code{includefile}, and there is also an
10221include file named @file{includefile} that defines a variable,
10222@code{some_global}.
10223
10224@smallexample
10225(@value{GDBP}) p includefile
10226$1 = 23
10227(@value{GDBP}) p includefile::some_global
10228A syntax error in expression, near `'.
10229(@value{GDBP}) p 'includefile'::some_global
10230$2 = 27
10231@end smallexample
c906108c
SS
10232
10233@cindex wrong values
10234@cindex variable values, wrong
15387254
EZ
10235@cindex function entry/exit, wrong values of variables
10236@cindex optimized code, wrong values of variables
c906108c
SS
10237@quotation
10238@emph{Warning:} Occasionally, a local variable may appear to have the
10239wrong value at certain points in a function---just after entry to a new
10240scope, and just before exit.
10241@end quotation
10242You may see this problem when you are stepping by machine instructions.
10243This is because, on most machines, it takes more than one instruction to
10244set up a stack frame (including local variable definitions); if you are
10245stepping by machine instructions, variables may appear to have the wrong
10246values until the stack frame is completely built. On exit, it usually
10247also takes more than one machine instruction to destroy a stack frame;
10248after you begin stepping through that group of instructions, local
10249variable definitions may be gone.
10250
10251This may also happen when the compiler does significant optimizations.
10252To be sure of always seeing accurate values, turn off all optimization
10253when compiling.
10254
d4f3574e
SS
10255@cindex ``No symbol "foo" in current context''
10256Another possible effect of compiler optimizations is to optimize
10257unused variables out of existence, or assign variables to registers (as
10258opposed to memory addresses). Depending on the support for such cases
10259offered by the debug info format used by the compiler, @value{GDBN}
10260might not be able to display values for such local variables. If that
10261happens, @value{GDBN} will print a message like this:
10262
474c8240 10263@smallexample
d4f3574e 10264No symbol "foo" in current context.
474c8240 10265@end smallexample
d4f3574e
SS
10266
10267To solve such problems, either recompile without optimizations, or use a
10268different debug info format, if the compiler supports several such
e0f8f636
TT
10269formats. @xref{Compilation}, for more information on choosing compiler
10270options. @xref{C, ,C and C@t{++}}, for more information about debug
10271info formats that are best suited to C@t{++} programs.
d4f3574e 10272
ab1adacd
EZ
10273If you ask to print an object whose contents are unknown to
10274@value{GDBN}, e.g., because its data type is not completely specified
10275by the debug information, @value{GDBN} will say @samp{<incomplete
10276type>}. @xref{Symbols, incomplete type}, for more about this.
10277
d69cf9b2
PA
10278@cindex no debug info variables
10279If you try to examine or use the value of a (global) variable for
10280which @value{GDBN} has no type information, e.g., because the program
10281includes no debug information, @value{GDBN} displays an error message.
10282@xref{Symbols, unknown type}, for more about unknown types. If you
10283cast the variable to its declared type, @value{GDBN} gets the
10284variable's value using the cast-to type as the variable's type. For
10285example, in a C program:
10286
10287@smallexample
10288 (@value{GDBP}) p var
10289 'var' has unknown type; cast it to its declared type
10290 (@value{GDBP}) p (float) var
10291 $1 = 3.14
10292@end smallexample
10293
36b11add
JK
10294If you append @kbd{@@entry} string to a function parameter name you get its
10295value at the time the function got called. If the value is not available an
10296error message is printed. Entry values are available only with some compilers.
10297Entry values are normally also printed at the function parameter list according
10298to @ref{set print entry-values}.
10299
10300@smallexample
10301Breakpoint 1, d (i=30) at gdb.base/entry-value.c:29
1030229 i++;
10303(gdb) next
1030430 e (i);
10305(gdb) print i
10306$1 = 31
10307(gdb) print i@@entry
10308$2 = 30
10309@end smallexample
10310
3a60f64e
JK
10311Strings are identified as arrays of @code{char} values without specified
10312signedness. Arrays of either @code{signed char} or @code{unsigned char} get
10313printed as arrays of 1 byte sized integers. @code{-fsigned-char} or
10314@code{-funsigned-char} @value{NGCC} options have no effect as @value{GDBN}
10315defines literal string type @code{"char"} as @code{char} without a sign.
10316For program code
10317
10318@smallexample
10319char var0[] = "A";
10320signed char var1[] = "A";
10321@end smallexample
10322
10323You get during debugging
10324@smallexample
10325(gdb) print var0
10326$1 = "A"
10327(gdb) print var1
10328$2 = @{65 'A', 0 '\0'@}
10329@end smallexample
10330
6d2ebf8b 10331@node Arrays
79a6e687 10332@section Artificial Arrays
c906108c
SS
10333
10334@cindex artificial array
15387254 10335@cindex arrays
41afff9a 10336@kindex @@@r{, referencing memory as an array}
c906108c
SS
10337It is often useful to print out several successive objects of the
10338same type in memory; a section of an array, or an array of
10339dynamically determined size for which only a pointer exists in the
10340program.
10341
10342You can do this by referring to a contiguous span of memory as an
10343@dfn{artificial array}, using the binary operator @samp{@@}. The left
10344operand of @samp{@@} should be the first element of the desired array
10345and be an individual object. The right operand should be the desired length
10346of the array. The result is an array value whose elements are all of
10347the type of the left argument. The first element is actually the left
10348argument; the second element comes from bytes of memory immediately
10349following those that hold the first element, and so on. Here is an
10350example. If a program says
10351
474c8240 10352@smallexample
c906108c 10353int *array = (int *) malloc (len * sizeof (int));
474c8240 10354@end smallexample
c906108c
SS
10355
10356@noindent
10357you can print the contents of @code{array} with
10358
474c8240 10359@smallexample
c906108c 10360p *array@@len
474c8240 10361@end smallexample
c906108c
SS
10362
10363The left operand of @samp{@@} must reside in memory. Array values made
10364with @samp{@@} in this way behave just like other arrays in terms of
10365subscripting, and are coerced to pointers when used in expressions.
10366Artificial arrays most often appear in expressions via the value history
79a6e687 10367(@pxref{Value History, ,Value History}), after printing one out.
c906108c
SS
10368
10369Another way to create an artificial array is to use a cast.
10370This re-interprets a value as if it were an array.
10371The value need not be in memory:
474c8240 10372@smallexample
c906108c
SS
10373(@value{GDBP}) p/x (short[2])0x12345678
10374$1 = @{0x1234, 0x5678@}
474c8240 10375@end smallexample
c906108c
SS
10376
10377As a convenience, if you leave the array length out (as in
c3f6f71d 10378@samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
c906108c 10379the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
474c8240 10380@smallexample
c906108c
SS
10381(@value{GDBP}) p/x (short[])0x12345678
10382$2 = @{0x1234, 0x5678@}
474c8240 10383@end smallexample
c906108c
SS
10384
10385Sometimes the artificial array mechanism is not quite enough; in
10386moderately complex data structures, the elements of interest may not
10387actually be adjacent---for example, if you are interested in the values
10388of pointers in an array. One useful work-around in this situation is
10389to use a convenience variable (@pxref{Convenience Vars, ,Convenience
79a6e687 10390Variables}) as a counter in an expression that prints the first
c906108c
SS
10391interesting value, and then repeat that expression via @key{RET}. For
10392instance, suppose you have an array @code{dtab} of pointers to
10393structures, and you are interested in the values of a field @code{fv}
10394in each structure. Here is an example of what you might type:
10395
474c8240 10396@smallexample
c906108c
SS
10397set $i = 0
10398p dtab[$i++]->fv
10399@key{RET}
10400@key{RET}
10401@dots{}
474c8240 10402@end smallexample
c906108c 10403
6d2ebf8b 10404@node Output Formats
79a6e687 10405@section Output Formats
c906108c
SS
10406
10407@cindex formatted output
10408@cindex output formats
10409By default, @value{GDBN} prints a value according to its data type. Sometimes
10410this is not what you want. For example, you might want to print a number
10411in hex, or a pointer in decimal. Or you might want to view data in memory
10412at a certain address as a character string or as an instruction. To do
10413these things, specify an @dfn{output format} when you print a value.
10414
10415The simplest use of output formats is to say how to print a value
10416already computed. This is done by starting the arguments of the
10417@code{print} command with a slash and a format letter. The format
10418letters supported are:
10419
10420@table @code
10421@item x
10422Regard the bits of the value as an integer, and print the integer in
10423hexadecimal.
10424
10425@item d
10426Print as integer in signed decimal.
10427
10428@item u
10429Print as integer in unsigned decimal.
10430
10431@item o
10432Print as integer in octal.
10433
10434@item t
10435Print as integer in binary. The letter @samp{t} stands for ``two''.
10436@footnote{@samp{b} cannot be used because these format letters are also
10437used with the @code{x} command, where @samp{b} stands for ``byte'';
79a6e687 10438see @ref{Memory,,Examining Memory}.}
c906108c
SS
10439
10440@item a
10441@cindex unknown address, locating
3d67e040 10442@cindex locate address
c906108c
SS
10443Print as an address, both absolute in hexadecimal and as an offset from
10444the nearest preceding symbol. You can use this format used to discover
10445where (in what function) an unknown address is located:
10446
474c8240 10447@smallexample
c906108c
SS
10448(@value{GDBP}) p/a 0x54320
10449$3 = 0x54320 <_initialize_vx+396>
474c8240 10450@end smallexample
c906108c 10451
3d67e040
EZ
10452@noindent
10453The command @code{info symbol 0x54320} yields similar results.
10454@xref{Symbols, info symbol}.
10455
c906108c 10456@item c
51274035
EZ
10457Regard as an integer and print it as a character constant. This
10458prints both the numerical value and its character representation. The
10459character representation is replaced with the octal escape @samp{\nnn}
10460for characters outside the 7-bit @sc{ascii} range.
c906108c 10461
ea37ba09
DJ
10462Without this format, @value{GDBN} displays @code{char},
10463@w{@code{unsigned char}}, and @w{@code{signed char}} data as character
10464constants. Single-byte members of vectors are displayed as integer
10465data.
10466
c906108c
SS
10467@item f
10468Regard the bits of the value as a floating point number and print
10469using typical floating point syntax.
ea37ba09
DJ
10470
10471@item s
10472@cindex printing strings
10473@cindex printing byte arrays
10474Regard as a string, if possible. With this format, pointers to single-byte
10475data are displayed as null-terminated strings and arrays of single-byte data
10476are displayed as fixed-length strings. Other values are displayed in their
10477natural types.
10478
10479Without this format, @value{GDBN} displays pointers to and arrays of
10480@code{char}, @w{@code{unsigned char}}, and @w{@code{signed char}} as
10481strings. Single-byte members of a vector are displayed as an integer
10482array.
a6bac58e 10483
6fbe845e
AB
10484@item z
10485Like @samp{x} formatting, the value is treated as an integer and
10486printed as hexadecimal, but leading zeros are printed to pad the value
10487to the size of the integer type.
10488
a6bac58e
TT
10489@item r
10490@cindex raw printing
10491Print using the @samp{raw} formatting. By default, @value{GDBN} will
78e2826b
TT
10492use a Python-based pretty-printer, if one is available (@pxref{Pretty
10493Printing}). This typically results in a higher-level display of the
10494value's contents. The @samp{r} format bypasses any Python
10495pretty-printer which might exist.
c906108c
SS
10496@end table
10497
10498For example, to print the program counter in hex (@pxref{Registers}), type
10499
474c8240 10500@smallexample
c906108c 10501p/x $pc
474c8240 10502@end smallexample
c906108c
SS
10503
10504@noindent
10505Note that no space is required before the slash; this is because command
10506names in @value{GDBN} cannot contain a slash.
10507
10508To reprint the last value in the value history with a different format,
10509you can use the @code{print} command with just a format and no
10510expression. For example, @samp{p/x} reprints the last value in hex.
10511
6d2ebf8b 10512@node Memory
79a6e687 10513@section Examining Memory
c906108c
SS
10514
10515You can use the command @code{x} (for ``examine'') to examine memory in
10516any of several formats, independently of your program's data types.
10517
10518@cindex examining memory
10519@table @code
41afff9a 10520@kindex x @r{(examine memory)}
c906108c
SS
10521@item x/@var{nfu} @var{addr}
10522@itemx x @var{addr}
10523@itemx x
10524Use the @code{x} command to examine memory.
10525@end table
10526
10527@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
10528much memory to display and how to format it; @var{addr} is an
10529expression giving the address where you want to start displaying memory.
10530If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
10531Several commands set convenient defaults for @var{addr}.
10532
10533@table @r
10534@item @var{n}, the repeat count
10535The repeat count is a decimal integer; the default is 1. It specifies
bb556f1f
TK
10536how much memory (counting by units @var{u}) to display. If a negative
10537number is specified, memory is examined backward from @var{addr}.
c906108c
SS
10538@c This really is **decimal**; unaffected by 'set radix' as of GDB
10539@c 4.1.2.
10540
10541@item @var{f}, the display format
51274035
EZ
10542The display format is one of the formats used by @code{print}
10543(@samp{x}, @samp{d}, @samp{u}, @samp{o}, @samp{t}, @samp{a}, @samp{c},
ea37ba09
DJ
10544@samp{f}, @samp{s}), and in addition @samp{i} (for machine instructions).
10545The default is @samp{x} (hexadecimal) initially. The default changes
10546each time you use either @code{x} or @code{print}.
c906108c
SS
10547
10548@item @var{u}, the unit size
10549The unit size is any of
10550
10551@table @code
10552@item b
10553Bytes.
10554@item h
10555Halfwords (two bytes).
10556@item w
10557Words (four bytes). This is the initial default.
10558@item g
10559Giant words (eight bytes).
10560@end table
10561
10562Each time you specify a unit size with @code{x}, that size becomes the
9a22f0d0
PM
10563default unit the next time you use @code{x}. For the @samp{i} format,
10564the unit size is ignored and is normally not written. For the @samp{s} format,
10565the unit size defaults to @samp{b}, unless it is explicitly given.
10566Use @kbd{x /hs} to display 16-bit char strings and @kbd{x /ws} to display
1056732-bit strings. The next use of @kbd{x /s} will again display 8-bit strings.
10568Note that the results depend on the programming language of the
10569current compilation unit. If the language is C, the @samp{s}
10570modifier will use the UTF-16 encoding while @samp{w} will use
10571UTF-32. The encoding is set by the programming language and cannot
10572be altered.
c906108c
SS
10573
10574@item @var{addr}, starting display address
10575@var{addr} is the address where you want @value{GDBN} to begin displaying
10576memory. The expression need not have a pointer value (though it may);
10577it is always interpreted as an integer address of a byte of memory.
10578@xref{Expressions, ,Expressions}, for more information on expressions. The default for
10579@var{addr} is usually just after the last address examined---but several
10580other commands also set the default address: @code{info breakpoints} (to
10581the address of the last breakpoint listed), @code{info line} (to the
10582starting address of a line), and @code{print} (if you use it to display
10583a value from memory).
10584@end table
10585
10586For example, @samp{x/3uh 0x54320} is a request to display three halfwords
10587(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
10588starting at address @code{0x54320}. @samp{x/4xw $sp} prints the four
10589words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
d4f3574e 10590@pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
c906108c 10591
bb556f1f
TK
10592You can also specify a negative repeat count to examine memory backward
10593from the given address. For example, @samp{x/-3uh 0x54320} prints three
10594halfwords (@code{h}) at @code{0x54314}, @code{0x54328}, and @code{0x5431c}.
10595
c906108c
SS
10596Since the letters indicating unit sizes are all distinct from the
10597letters specifying output formats, you do not have to remember whether
10598unit size or format comes first; either order works. The output
10599specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
10600(However, the count @var{n} must come first; @samp{wx4} does not work.)
10601
10602Even though the unit size @var{u} is ignored for the formats @samp{s}
10603and @samp{i}, you might still want to use a count @var{n}; for example,
10604@samp{3i} specifies that you want to see three machine instructions,
a4642986
MR
10605including any operands. For convenience, especially when used with
10606the @code{display} command, the @samp{i} format also prints branch delay
10607slot instructions, if any, beyond the count specified, which immediately
10608follow the last instruction that is within the count. The command
10609@code{disassemble} gives an alternative way of inspecting machine
10610instructions; see @ref{Machine Code,,Source and Machine Code}.
c906108c 10611
bb556f1f
TK
10612If a negative repeat count is specified for the formats @samp{s} or @samp{i},
10613the command displays null-terminated strings or instructions before the given
10614address as many as the absolute value of the given number. For the @samp{i}
10615format, we use line number information in the debug info to accurately locate
10616instruction boundaries while disassembling backward. If line info is not
10617available, the command stops examining memory with an error message.
10618
c906108c
SS
10619All the defaults for the arguments to @code{x} are designed to make it
10620easy to continue scanning memory with minimal specifications each time
10621you use @code{x}. For example, after you have inspected three machine
10622instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
10623with just @samp{x/7}. If you use @key{RET} to repeat the @code{x} command,
10624the repeat count @var{n} is used again; the other arguments default as
10625for successive uses of @code{x}.
10626
2b28d209
PP
10627When examining machine instructions, the instruction at current program
10628counter is shown with a @code{=>} marker. For example:
10629
10630@smallexample
10631(@value{GDBP}) x/5i $pc-6
10632 0x804837f <main+11>: mov %esp,%ebp
10633 0x8048381 <main+13>: push %ecx
10634 0x8048382 <main+14>: sub $0x4,%esp
10635=> 0x8048385 <main+17>: movl $0x8048460,(%esp)
10636 0x804838c <main+24>: call 0x80482d4 <puts@@plt>
10637@end smallexample
10638
c906108c
SS
10639@cindex @code{$_}, @code{$__}, and value history
10640The addresses and contents printed by the @code{x} command are not saved
10641in the value history because there is often too much of them and they
10642would get in the way. Instead, @value{GDBN} makes these values available for
10643subsequent use in expressions as values of the convenience variables
10644@code{$_} and @code{$__}. After an @code{x} command, the last address
10645examined is available for use in expressions in the convenience variable
10646@code{$_}. The contents of that address, as examined, are available in
10647the convenience variable @code{$__}.
10648
10649If the @code{x} command has a repeat count, the address and contents saved
10650are from the last memory unit printed; this is not the same as the last
10651address printed if several units were printed on the last line of output.
10652
a86c90e6
SM
10653@anchor{addressable memory unit}
10654@cindex addressable memory unit
10655Most targets have an addressable memory unit size of 8 bits. This means
10656that to each memory address are associated 8 bits of data. Some
10657targets, however, have other addressable memory unit sizes.
10658Within @value{GDBN} and this document, the term
10659@dfn{addressable memory unit} (or @dfn{memory unit} for short) is used
10660when explicitly referring to a chunk of data of that size. The word
10661@dfn{byte} is used to refer to a chunk of data of 8 bits, regardless of
10662the addressable memory unit size of the target. For most systems,
10663addressable memory unit is a synonym of byte.
10664
09d4efe1 10665@cindex remote memory comparison
936d2992 10666@cindex target memory comparison
09d4efe1 10667@cindex verify remote memory image
936d2992 10668@cindex verify target memory image
09d4efe1 10669When you are debugging a program running on a remote target machine
936d2992
PA
10670(@pxref{Remote Debugging}), you may wish to verify the program's image
10671in the remote machine's memory against the executable file you
10672downloaded to the target. Or, on any target, you may want to check
10673whether the program has corrupted its own read-only sections. The
10674@code{compare-sections} command is provided for such situations.
09d4efe1
EZ
10675
10676@table @code
10677@kindex compare-sections
95cf3b38 10678@item compare-sections @r{[}@var{section-name}@r{|}@code{-r}@r{]}
09d4efe1
EZ
10679Compare the data of a loadable section @var{section-name} in the
10680executable file of the program being debugged with the same section in
936d2992 10681the target machine's memory, and report any mismatches. With no
95cf3b38 10682arguments, compares all loadable sections. With an argument of
936d2992
PA
10683@code{-r}, compares all loadable read-only sections.
10684
10685Note: for remote targets, this command can be accelerated if the
10686target supports computing the CRC checksum of a block of memory
10687(@pxref{qCRC packet}).
09d4efe1
EZ
10688@end table
10689
6d2ebf8b 10690@node Auto Display
79a6e687 10691@section Automatic Display
c906108c
SS
10692@cindex automatic display
10693@cindex display of expressions
10694
10695If you find that you want to print the value of an expression frequently
10696(to see how it changes), you might want to add it to the @dfn{automatic
10697display list} so that @value{GDBN} prints its value each time your program stops.
10698Each expression added to the list is given a number to identify it;
10699to remove an expression from the list, you specify that number.
10700The automatic display looks like this:
10701
474c8240 10702@smallexample
c906108c
SS
107032: foo = 38
107043: bar[5] = (struct hack *) 0x3804
474c8240 10705@end smallexample
c906108c
SS
10706
10707@noindent
10708This display shows item numbers, expressions and their current values. As with
10709displays you request manually using @code{x} or @code{print}, you can
10710specify the output format you prefer; in fact, @code{display} decides
ea37ba09
DJ
10711whether to use @code{print} or @code{x} depending your format
10712specification---it uses @code{x} if you specify either the @samp{i}
10713or @samp{s} format, or a unit size; otherwise it uses @code{print}.
c906108c
SS
10714
10715@table @code
10716@kindex display
d4f3574e
SS
10717@item display @var{expr}
10718Add the expression @var{expr} to the list of expressions to display
c906108c
SS
10719each time your program stops. @xref{Expressions, ,Expressions}.
10720
10721@code{display} does not repeat if you press @key{RET} again after using it.
10722
d4f3574e 10723@item display/@var{fmt} @var{expr}
c906108c 10724For @var{fmt} specifying only a display format and not a size or
d4f3574e 10725count, add the expression @var{expr} to the auto-display list but
c906108c 10726arrange to display it each time in the specified format @var{fmt}.
79a6e687 10727@xref{Output Formats,,Output Formats}.
c906108c
SS
10728
10729@item display/@var{fmt} @var{addr}
10730For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
10731number of units, add the expression @var{addr} as a memory address to
10732be examined each time your program stops. Examining means in effect
79a6e687 10733doing @samp{x/@var{fmt} @var{addr}}. @xref{Memory, ,Examining Memory}.
c906108c
SS
10734@end table
10735
10736For example, @samp{display/i $pc} can be helpful, to see the machine
10737instruction about to be executed each time execution stops (@samp{$pc}
d4f3574e 10738is a common name for the program counter; @pxref{Registers, ,Registers}).
c906108c
SS
10739
10740@table @code
10741@kindex delete display
10742@kindex undisplay
10743@item undisplay @var{dnums}@dots{}
10744@itemx delete display @var{dnums}@dots{}
c9174737
PA
10745Remove items from the list of expressions to display. Specify the
10746numbers of the displays that you want affected with the command
10747argument @var{dnums}. It can be a single display number, one of the
10748numbers shown in the first field of the @samp{info display} display;
10749or it could be a range of display numbers, as in @code{2-4}.
c906108c
SS
10750
10751@code{undisplay} does not repeat if you press @key{RET} after using it.
10752(Otherwise you would just get the error @samp{No display number @dots{}}.)
10753
10754@kindex disable display
10755@item disable display @var{dnums}@dots{}
10756Disable the display of item numbers @var{dnums}. A disabled display
10757item is not printed automatically, but is not forgotten. It may be
c9174737
PA
10758enabled again later. Specify the numbers of the displays that you
10759want affected with the command argument @var{dnums}. It can be a
10760single display number, one of the numbers shown in the first field of
10761the @samp{info display} display; or it could be a range of display
10762numbers, as in @code{2-4}.
c906108c
SS
10763
10764@kindex enable display
10765@item enable display @var{dnums}@dots{}
10766Enable display of item numbers @var{dnums}. It becomes effective once
10767again in auto display of its expression, until you specify otherwise.
c9174737
PA
10768Specify the numbers of the displays that you want affected with the
10769command argument @var{dnums}. It can be a single display number, one
10770of the numbers shown in the first field of the @samp{info display}
10771display; or it could be a range of display numbers, as in @code{2-4}.
c906108c
SS
10772
10773@item display
10774Display the current values of the expressions on the list, just as is
10775done when your program stops.
10776
10777@kindex info display
10778@item info display
10779Print the list of expressions previously set up to display
10780automatically, each one with its item number, but without showing the
10781values. This includes disabled expressions, which are marked as such.
10782It also includes expressions which would not be displayed right now
10783because they refer to automatic variables not currently available.
10784@end table
10785
15387254 10786@cindex display disabled out of scope
c906108c
SS
10787If a display expression refers to local variables, then it does not make
10788sense outside the lexical context for which it was set up. Such an
10789expression is disabled when execution enters a context where one of its
10790variables is not defined. For example, if you give the command
10791@code{display last_char} while inside a function with an argument
10792@code{last_char}, @value{GDBN} displays this argument while your program
10793continues to stop inside that function. When it stops elsewhere---where
10794there is no variable @code{last_char}---the display is disabled
10795automatically. The next time your program stops where @code{last_char}
10796is meaningful, you can enable the display expression once again.
10797
6d2ebf8b 10798@node Print Settings
79a6e687 10799@section Print Settings
c906108c
SS
10800
10801@cindex format options
10802@cindex print settings
10803@value{GDBN} provides the following ways to control how arrays, structures,
10804and symbols are printed.
10805
10806@noindent
10807These settings are useful for debugging programs in any language:
10808
10809@table @code
4644b6e3 10810@kindex set print
3345721a 10811@anchor{set print address}
c906108c
SS
10812@item set print address
10813@itemx set print address on
4644b6e3 10814@cindex print/don't print memory addresses
c906108c
SS
10815@value{GDBN} prints memory addresses showing the location of stack
10816traces, structure values, pointer values, breakpoints, and so forth,
10817even when it also displays the contents of those addresses. The default
10818is @code{on}. For example, this is what a stack frame display looks like with
10819@code{set print address on}:
10820
10821@smallexample
10822@group
10823(@value{GDBP}) f
10824#0 set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
10825 at input.c:530
10826530 if (lquote != def_lquote)
10827@end group
10828@end smallexample
10829
10830@item set print address off
10831Do not print addresses when displaying their contents. For example,
10832this is the same stack frame displayed with @code{set print address off}:
10833
10834@smallexample
10835@group
10836(@value{GDBP}) set print addr off
10837(@value{GDBP}) f
10838#0 set_quotes (lq="<<", rq=">>") at input.c:530
10839530 if (lquote != def_lquote)
10840@end group
10841@end smallexample
10842
10843You can use @samp{set print address off} to eliminate all machine
10844dependent displays from the @value{GDBN} interface. For example, with
10845@code{print address off}, you should get the same text for backtraces on
10846all machines---whether or not they involve pointer arguments.
10847
4644b6e3 10848@kindex show print
c906108c
SS
10849@item show print address
10850Show whether or not addresses are to be printed.
10851@end table
10852
10853When @value{GDBN} prints a symbolic address, it normally prints the
10854closest earlier symbol plus an offset. If that symbol does not uniquely
10855identify the address (for example, it is a name whose scope is a single
10856source file), you may need to clarify. One way to do this is with
10857@code{info line}, for example @samp{info line *0x4537}. Alternately,
10858you can set @value{GDBN} to print the source file and line number when
10859it prints a symbolic address:
10860
10861@table @code
c906108c 10862@item set print symbol-filename on
9c16f35a
EZ
10863@cindex source file and line of a symbol
10864@cindex symbol, source file and line
c906108c
SS
10865Tell @value{GDBN} to print the source file name and line number of a
10866symbol in the symbolic form of an address.
10867
10868@item set print symbol-filename off
10869Do not print source file name and line number of a symbol. This is the
10870default.
10871
c906108c
SS
10872@item show print symbol-filename
10873Show whether or not @value{GDBN} will print the source file name and
10874line number of a symbol in the symbolic form of an address.
10875@end table
10876
10877Another situation where it is helpful to show symbol filenames and line
10878numbers is when disassembling code; @value{GDBN} shows you the line
10879number and source file that corresponds to each instruction.
10880
10881Also, you may wish to see the symbolic form only if the address being
10882printed is reasonably close to the closest earlier symbol:
10883
10884@table @code
c906108c 10885@item set print max-symbolic-offset @var{max-offset}
f81d1120 10886@itemx set print max-symbolic-offset unlimited
4644b6e3 10887@cindex maximum value for offset of closest symbol
c906108c
SS
10888Tell @value{GDBN} to only display the symbolic form of an address if the
10889offset between the closest earlier symbol and the address is less than
f81d1120
PA
10890@var{max-offset}. The default is @code{unlimited}, which tells @value{GDBN}
10891to always print the symbolic form of an address if any symbol precedes
10892it. Zero is equivalent to @code{unlimited}.
c906108c 10893
c906108c
SS
10894@item show print max-symbolic-offset
10895Ask how large the maximum offset is that @value{GDBN} prints in a
10896symbolic address.
10897@end table
10898
10899@cindex wild pointer, interpreting
10900@cindex pointer, finding referent
10901If you have a pointer and you are not sure where it points, try
10902@samp{set print symbol-filename on}. Then you can determine the name
10903and source file location of the variable where it points, using
10904@samp{p/a @var{pointer}}. This interprets the address in symbolic form.
10905For example, here @value{GDBN} shows that a variable @code{ptt} points
10906at another variable @code{t}, defined in @file{hi2.c}:
10907
474c8240 10908@smallexample
c906108c
SS
10909(@value{GDBP}) set print symbol-filename on
10910(@value{GDBP}) p/a ptt
10911$4 = 0xe008 <t in hi2.c>
474c8240 10912@end smallexample
c906108c
SS
10913
10914@quotation
10915@emph{Warning:} For pointers that point to a local variable, @samp{p/a}
10916does not show the symbol name and filename of the referent, even with
10917the appropriate @code{set print} options turned on.
10918@end quotation
10919
9cb709b6
TT
10920You can also enable @samp{/a}-like formatting all the time using
10921@samp{set print symbol on}:
10922
3345721a 10923@anchor{set print symbol}
9cb709b6
TT
10924@table @code
10925@item set print symbol on
10926Tell @value{GDBN} to print the symbol corresponding to an address, if
10927one exists.
10928
10929@item set print symbol off
10930Tell @value{GDBN} not to print the symbol corresponding to an
10931address. In this mode, @value{GDBN} will still print the symbol
10932corresponding to pointers to functions. This is the default.
10933
10934@item show print symbol
10935Show whether @value{GDBN} will display the symbol corresponding to an
10936address.
10937@end table
10938
c906108c
SS
10939Other settings control how different kinds of objects are printed:
10940
10941@table @code
3345721a 10942@anchor{set print array}
c906108c
SS
10943@item set print array
10944@itemx set print array on
4644b6e3 10945@cindex pretty print arrays
c906108c
SS
10946Pretty print arrays. This format is more convenient to read,
10947but uses more space. The default is off.
10948
10949@item set print array off
10950Return to compressed format for arrays.
10951
c906108c
SS
10952@item show print array
10953Show whether compressed or pretty format is selected for displaying
10954arrays.
10955
3c9c013a 10956@cindex print array indexes
3345721a 10957@anchor{set print array-indexes}
3c9c013a
JB
10958@item set print array-indexes
10959@itemx set print array-indexes on
10960Print the index of each element when displaying arrays. May be more
10961convenient to locate a given element in the array or quickly find the
10962index of a given element in that printed array. The default is off.
10963
10964@item set print array-indexes off
10965Stop printing element indexes when displaying arrays.
10966
10967@item show print array-indexes
10968Show whether the index of each element is printed when displaying
10969arrays.
10970
3345721a 10971@anchor{set print elements}
c906108c 10972@item set print elements @var{number-of-elements}
f81d1120 10973@itemx set print elements unlimited
4644b6e3 10974@cindex number of array elements to print
9c16f35a 10975@cindex limit on number of printed array elements
c906108c
SS
10976Set a limit on how many elements of an array @value{GDBN} will print.
10977If @value{GDBN} is printing a large array, it stops printing after it has
10978printed the number of elements set by the @code{set print elements} command.
10979This limit also applies to the display of strings.
d4f3574e 10980When @value{GDBN} starts, this limit is set to 200.
f81d1120
PA
10981Setting @var{number-of-elements} to @code{unlimited} or zero means
10982that the number of elements to print is unlimited.
c906108c 10983
c906108c
SS
10984@item show print elements
10985Display the number of elements of a large array that @value{GDBN} will print.
10986If the number is 0, then the printing is unlimited.
10987
3345721a 10988@anchor{set print frame-arguments}
b4740add 10989@item set print frame-arguments @var{value}
a0381d3a 10990@kindex set print frame-arguments
b4740add
JB
10991@cindex printing frame argument values
10992@cindex print all frame argument values
10993@cindex print frame argument values for scalars only
bc4268a5 10994@cindex do not print frame arguments
b4740add
JB
10995This command allows to control how the values of arguments are printed
10996when the debugger prints a frame (@pxref{Frames}). The possible
10997values are:
10998
10999@table @code
11000@item all
4f5376b2 11001The values of all arguments are printed.
b4740add
JB
11002
11003@item scalars
11004Print the value of an argument only if it is a scalar. The value of more
11005complex arguments such as arrays, structures, unions, etc, is replaced
4f5376b2
JB
11006by @code{@dots{}}. This is the default. Here is an example where
11007only scalar arguments are shown:
b4740add
JB
11008
11009@smallexample
11010#1 0x08048361 in call_me (i=3, s=@dots{}, ss=0xbf8d508c, u=@dots{}, e=green)
11011 at frame-args.c:23
11012@end smallexample
11013
11014@item none
11015None of the argument values are printed. Instead, the value of each argument
11016is replaced by @code{@dots{}}. In this case, the example above now becomes:
11017
11018@smallexample
11019#1 0x08048361 in call_me (i=@dots{}, s=@dots{}, ss=@dots{}, u=@dots{}, e=@dots{})
11020 at frame-args.c:23
11021@end smallexample
bc4268a5
PW
11022
11023@item presence
11024Only the presence of arguments is indicated by @code{@dots{}}.
11025The @code{@dots{}} are not printed for function without any arguments.
11026None of the argument names and values are printed.
11027In this case, the example above now becomes:
11028
11029@smallexample
11030#1 0x08048361 in call_me (@dots{}) at frame-args.c:23
11031@end smallexample
11032
b4740add
JB
11033@end table
11034
4f5376b2
JB
11035By default, only scalar arguments are printed. This command can be used
11036to configure the debugger to print the value of all arguments, regardless
11037of their type. However, it is often advantageous to not print the value
11038of more complex parameters. For instance, it reduces the amount of
11039information printed in each frame, making the backtrace more readable.
11040Also, it improves performance when displaying Ada frames, because
11041the computation of large arguments can sometimes be CPU-intensive,
11042especially in large applications. Setting @code{print frame-arguments}
bc4268a5
PW
11043to @code{scalars} (the default), @code{none} or @code{presence} avoids
11044this computation, thus speeding up the display of each Ada frame.
b4740add
JB
11045
11046@item show print frame-arguments
11047Show how the value of arguments should be displayed when printing a frame.
11048
3345721a 11049@anchor{set print raw-frame-arguments}
2daf894e 11050@item set print raw-frame-arguments on
e7045703
DE
11051Print frame arguments in raw, non pretty-printed, form.
11052
2daf894e 11053@item set print raw-frame-arguments off
e7045703
DE
11054Print frame arguments in pretty-printed form, if there is a pretty-printer
11055for the value (@pxref{Pretty Printing}),
11056otherwise print the value in raw form.
11057This is the default.
11058
2daf894e 11059@item show print raw-frame-arguments
e7045703
DE
11060Show whether to print frame arguments in raw form.
11061
36b11add 11062@anchor{set print entry-values}
e18b2753
JK
11063@item set print entry-values @var{value}
11064@kindex set print entry-values
11065Set printing of frame argument values at function entry. In some cases
11066@value{GDBN} can determine the value of function argument which was passed by
11067the function caller, even if the value was modified inside the called function
11068and therefore is different. With optimized code, the current value could be
11069unavailable, but the entry value may still be known.
11070
11071The default value is @code{default} (see below for its description). Older
11072@value{GDBN} behaved as with the setting @code{no}. Compilers not supporting
11073this feature will behave in the @code{default} setting the same way as with the
11074@code{no} setting.
11075
11076This functionality is currently supported only by DWARF 2 debugging format and
216f72a1 11077the compiler has to produce @samp{DW_TAG_call_site} tags. With
e18b2753
JK
11078@value{NGCC}, you need to specify @option{-O -g} during compilation, to get
11079this information.
11080
11081The @var{value} parameter can be one of the following:
11082
11083@table @code
11084@item no
11085Print only actual parameter values, never print values from function entry
11086point.
11087@smallexample
11088#0 equal (val=5)
11089#0 different (val=6)
11090#0 lost (val=<optimized out>)
11091#0 born (val=10)
11092#0 invalid (val=<optimized out>)
11093@end smallexample
11094
11095@item only
11096Print only parameter values from function entry point. The actual parameter
11097values are never printed.
11098@smallexample
11099#0 equal (val@@entry=5)
11100#0 different (val@@entry=5)
11101#0 lost (val@@entry=5)
11102#0 born (val@@entry=<optimized out>)
11103#0 invalid (val@@entry=<optimized out>)
11104@end smallexample
11105
11106@item preferred
11107Print only parameter values from function entry point. If value from function
11108entry point is not known while the actual value is known, print the actual
11109value for such parameter.
11110@smallexample
11111#0 equal (val@@entry=5)
11112#0 different (val@@entry=5)
11113#0 lost (val@@entry=5)
11114#0 born (val=10)
11115#0 invalid (val@@entry=<optimized out>)
11116@end smallexample
11117
11118@item if-needed
11119Print actual parameter values. If actual parameter value is not known while
11120value from function entry point is known, print the entry point value for such
11121parameter.
11122@smallexample
11123#0 equal (val=5)
11124#0 different (val=6)
11125#0 lost (val@@entry=5)
11126#0 born (val=10)
11127#0 invalid (val=<optimized out>)
11128@end smallexample
11129
11130@item both
11131Always print both the actual parameter value and its value from function entry
11132point, even if values of one or both are not available due to compiler
11133optimizations.
11134@smallexample
11135#0 equal (val=5, val@@entry=5)
11136#0 different (val=6, val@@entry=5)
11137#0 lost (val=<optimized out>, val@@entry=5)
11138#0 born (val=10, val@@entry=<optimized out>)
11139#0 invalid (val=<optimized out>, val@@entry=<optimized out>)
11140@end smallexample
11141
11142@item compact
11143Print the actual parameter value if it is known and also its value from
11144function entry point if it is known. If neither is known, print for the actual
11145value @code{<optimized out>}. If not in MI mode (@pxref{GDB/MI}) and if both
11146values are known and identical, print the shortened
11147@code{param=param@@entry=VALUE} notation.
11148@smallexample
11149#0 equal (val=val@@entry=5)
11150#0 different (val=6, val@@entry=5)
11151#0 lost (val@@entry=5)
11152#0 born (val=10)
11153#0 invalid (val=<optimized out>)
11154@end smallexample
11155
11156@item default
11157Always print the actual parameter value. Print also its value from function
11158entry point, but only if it is known. If not in MI mode (@pxref{GDB/MI}) and
11159if both values are known and identical, print the shortened
11160@code{param=param@@entry=VALUE} notation.
11161@smallexample
11162#0 equal (val=val@@entry=5)
11163#0 different (val=6, val@@entry=5)
11164#0 lost (val=<optimized out>, val@@entry=5)
11165#0 born (val=10)
11166#0 invalid (val=<optimized out>)
11167@end smallexample
11168@end table
11169
11170For analysis messages on possible failures of frame argument values at function
11171entry resolution see @ref{set debug entry-values}.
11172
11173@item show print entry-values
11174Show the method being used for printing of frame argument values at function
11175entry.
11176
bc4268a5
PW
11177@anchor{set print frame-info}
11178@item set print frame-info @var{value}
11179@kindex set print frame-info
11180@cindex printing frame information
11181@cindex frame information, printing
11182This command allows to control the information printed when
11183the debugger prints a frame. See @ref{Frames}, @ref{Backtrace},
11184for a general explanation about frames and frame information.
11185Note that some other settings (such as @code{set print frame-arguments}
11186and @code{set print address}) are also influencing if and how some frame
11187information is displayed. In particular, the frame program counter is never
11188printed if @code{set print address} is off.
11189
11190The possible values for @code{set print frame-info} are:
11191@table @code
11192@item short-location
11193Print the frame level, the program counter (if not at the
11194beginning of the location source line), the function, the function
11195arguments.
11196@item location
11197Same as @code{short-location} but also print the source file and source line
11198number.
11199@item location-and-address
11200Same as @code{location} but print the program counter even if located at the
11201beginning of the location source line.
11202@item source-line
11203Print the program counter (if not at the beginning of the location
11204source line), the line number and the source line.
11205@item source-and-location
11206Print what @code{location} and @code{source-line} are printing.
11207@item auto
11208The information printed for a frame is decided automatically
11209by the @value{GDBN} command that prints a frame.
11210For example, @code{frame} prints the information printed by
11211@code{source-and-location} while @code{stepi} will switch between
11212@code{source-line} and @code{source-and-location} depending on the program
11213counter.
11214The default value is @code{auto}.
11215@end table
11216
3345721a 11217@anchor{set print repeats}
f81d1120
PA
11218@item set print repeats @var{number-of-repeats}
11219@itemx set print repeats unlimited
9c16f35a
EZ
11220@cindex repeated array elements
11221Set the threshold for suppressing display of repeated array
d3e8051b 11222elements. When the number of consecutive identical elements of an
9c16f35a
EZ
11223array exceeds the threshold, @value{GDBN} prints the string
11224@code{"<repeats @var{n} times>"}, where @var{n} is the number of
11225identical repetitions, instead of displaying the identical elements
f81d1120
PA
11226themselves. Setting the threshold to @code{unlimited} or zero will
11227cause all elements to be individually printed. The default threshold
11228is 10.
9c16f35a
EZ
11229
11230@item show print repeats
11231Display the current threshold for printing repeated identical
11232elements.
11233
3345721a 11234@anchor{set print max-depth}
2e62ab40
AB
11235@item set print max-depth @var{depth}
11236@item set print max-depth unlimited
11237@cindex printing nested structures
11238Set the threshold after which nested structures are replaced with
11239ellipsis, this can make visualising deeply nested structures easier.
11240
11241For example, given this C code
11242
11243@smallexample
11244typedef struct s1 @{ int a; @} s1;
11245typedef struct s2 @{ s1 b; @} s2;
11246typedef struct s3 @{ s2 c; @} s3;
11247typedef struct s4 @{ s3 d; @} s4;
11248
11249s4 var = @{ @{ @{ @{ 3 @} @} @} @};
11250@end smallexample
11251
11252The following table shows how different values of @var{depth} will
11253effect how @code{var} is printed by @value{GDBN}:
11254
11255@multitable @columnfractions .3 .7
11256@headitem @var{depth} setting @tab Result of @samp{p var}
11257@item unlimited
11258@tab @code{$1 = @{d = @{c = @{b = @{a = 3@}@}@}@}}
11259@item @code{0}
11260@tab @code{$1 = @{...@}}
11261@item @code{1}
11262@tab @code{$1 = @{d = @{...@}@}}
11263@item @code{2}
11264@tab @code{$1 = @{d = @{c = @{...@}@}@}}
11265@item @code{3}
11266@tab @code{$1 = @{d = @{c = @{b = @{...@}@}@}@}}
11267@item @code{4}
11268@tab @code{$1 = @{d = @{c = @{b = @{a = 3@}@}@}@}}
11269@end multitable
11270
11271To see the contents of structures that have been hidden the user can
11272either increase the print max-depth, or they can print the elements of
11273the structure that are visible, for example
11274
11275@smallexample
11276(gdb) set print max-depth 2
11277(gdb) p var
11278$1 = @{d = @{c = @{...@}@}@}
11279(gdb) p var.d
11280$2 = @{c = @{b = @{...@}@}@}
11281(gdb) p var.d.c
11282$3 = @{b = @{a = 3@}@}
11283@end smallexample
11284
11285The pattern used to replace nested structures varies based on
11286language, for most languages @code{@{...@}} is used, but Fortran uses
11287@code{(...)}.
11288
11289@item show print max-depth
11290Display the current threshold after which nested structures are
11291replaces with ellipsis.
11292
3345721a 11293@anchor{set print null-stop}
c906108c 11294@item set print null-stop
4644b6e3 11295@cindex @sc{null} elements in arrays
c906108c 11296Cause @value{GDBN} to stop printing the characters of an array when the first
d4f3574e 11297@sc{null} is encountered. This is useful when large arrays actually
c906108c 11298contain only short strings.
d4f3574e 11299The default is off.
c906108c 11300
9c16f35a
EZ
11301@item show print null-stop
11302Show whether @value{GDBN} stops printing an array on the first
11303@sc{null} character.
11304
3345721a 11305@anchor{set print pretty}
c906108c 11306@item set print pretty on
9c16f35a
EZ
11307@cindex print structures in indented form
11308@cindex indentation in structure display
5d161b24 11309Cause @value{GDBN} to print structures in an indented format with one member
c906108c
SS
11310per line, like this:
11311
11312@smallexample
11313@group
11314$1 = @{
11315 next = 0x0,
11316 flags = @{
11317 sweet = 1,
11318 sour = 1
11319 @},
11320 meat = 0x54 "Pork"
11321@}
11322@end group
11323@end smallexample
11324
11325@item set print pretty off
11326Cause @value{GDBN} to print structures in a compact format, like this:
11327
11328@smallexample
11329@group
11330$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
11331meat = 0x54 "Pork"@}
11332@end group
11333@end smallexample
11334
11335@noindent
11336This is the default format.
11337
c906108c
SS
11338@item show print pretty
11339Show which format @value{GDBN} is using to print structures.
11340
d8edc8b7
PW
11341@anchor{set print raw-values}
11342@item set print raw-values on
11343Print values in raw form, without applying the pretty
11344printers for the value.
11345
11346@item set print raw-values off
11347Print values in pretty-printed form, if there is a pretty-printer
11348for the value (@pxref{Pretty Printing}),
11349otherwise print the value in raw form.
11350
11351The default setting is ``off''.
11352
11353@item show print raw-values
11354Show whether to print values in raw form.
11355
c906108c 11356@item set print sevenbit-strings on
4644b6e3
EZ
11357@cindex eight-bit characters in strings
11358@cindex octal escapes in strings
c906108c
SS
11359Print using only seven-bit characters; if this option is set,
11360@value{GDBN} displays any eight-bit characters (in strings or
11361character values) using the notation @code{\}@var{nnn}. This setting is
11362best if you are working in English (@sc{ascii}) and you use the
11363high-order bit of characters as a marker or ``meta'' bit.
11364
11365@item set print sevenbit-strings off
11366Print full eight-bit characters. This allows the use of more
11367international character sets, and is the default.
11368
c906108c
SS
11369@item show print sevenbit-strings
11370Show whether or not @value{GDBN} is printing only seven-bit characters.
11371
3345721a 11372@anchor{set print union}
c906108c 11373@item set print union on
4644b6e3 11374@cindex unions in structures, printing
9c16f35a
EZ
11375Tell @value{GDBN} to print unions which are contained in structures
11376and other unions. This is the default setting.
c906108c
SS
11377
11378@item set print union off
9c16f35a
EZ
11379Tell @value{GDBN} not to print unions which are contained in
11380structures and other unions. @value{GDBN} will print @code{"@{...@}"}
11381instead.
c906108c 11382
c906108c
SS
11383@item show print union
11384Ask @value{GDBN} whether or not it will print unions which are contained in
9c16f35a 11385structures and other unions.
c906108c
SS
11386
11387For example, given the declarations
11388
11389@smallexample
11390typedef enum @{Tree, Bug@} Species;
11391typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
5d161b24 11392typedef enum @{Caterpillar, Cocoon, Butterfly@}
c906108c
SS
11393 Bug_forms;
11394
11395struct thing @{
11396 Species it;
11397 union @{
11398 Tree_forms tree;
11399 Bug_forms bug;
11400 @} form;
11401@};
11402
11403struct thing foo = @{Tree, @{Acorn@}@};
11404@end smallexample
11405
11406@noindent
11407with @code{set print union on} in effect @samp{p foo} would print
11408
11409@smallexample
11410$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
11411@end smallexample
11412
11413@noindent
11414and with @code{set print union off} in effect it would print
11415
11416@smallexample
11417$1 = @{it = Tree, form = @{...@}@}
11418@end smallexample
9c16f35a
EZ
11419
11420@noindent
11421@code{set print union} affects programs written in C-like languages
11422and in Pascal.
c906108c
SS
11423@end table
11424
c906108c
SS
11425@need 1000
11426@noindent
b37052ae 11427These settings are of interest when debugging C@t{++} programs:
c906108c
SS
11428
11429@table @code
4644b6e3 11430@cindex demangling C@t{++} names
c906108c
SS
11431@item set print demangle
11432@itemx set print demangle on
b37052ae 11433Print C@t{++} names in their source form rather than in the encoded
c906108c 11434(``mangled'') form passed to the assembler and linker for type-safe
d4f3574e 11435linkage. The default is on.
c906108c 11436
c906108c 11437@item show print demangle
b37052ae 11438Show whether C@t{++} names are printed in mangled or demangled form.
c906108c 11439
c906108c
SS
11440@item set print asm-demangle
11441@itemx set print asm-demangle on
b37052ae 11442Print C@t{++} names in their source form rather than their mangled form, even
c906108c
SS
11443in assembler code printouts such as instruction disassemblies.
11444The default is off.
11445
c906108c 11446@item show print asm-demangle
b37052ae 11447Show whether C@t{++} names in assembly listings are printed in mangled
c906108c
SS
11448or demangled form.
11449
b37052ae
EZ
11450@cindex C@t{++} symbol decoding style
11451@cindex symbol decoding style, C@t{++}
a8f24a35 11452@kindex set demangle-style
c906108c 11453@item set demangle-style @var{style}
041be526
SM
11454Choose among several encoding schemes used by different compilers to represent
11455C@t{++} names. If you omit @var{style}, you will see a list of possible
11456formats. The default value is @var{auto}, which lets @value{GDBN} choose a
11457decoding style by inspecting your program.
c906108c 11458
c906108c 11459@item show demangle-style
b37052ae 11460Display the encoding style currently in use for decoding C@t{++} symbols.
c906108c 11461
3345721a 11462@anchor{set print object}
c906108c
SS
11463@item set print object
11464@itemx set print object on
4644b6e3 11465@cindex derived type of an object, printing
9c16f35a 11466@cindex display derived types
c906108c
SS
11467When displaying a pointer to an object, identify the @emph{actual}
11468(derived) type of the object rather than the @emph{declared} type, using
625c0d47
TT
11469the virtual function table. Note that the virtual function table is
11470required---this feature can only work for objects that have run-time
11471type identification; a single virtual method in the object's declared
8264ba82
AG
11472type is sufficient. Note that this setting is also taken into account when
11473working with variable objects via MI (@pxref{GDB/MI}).
c906108c
SS
11474
11475@item set print object off
11476Display only the declared type of objects, without reference to the
11477virtual function table. This is the default setting.
11478
c906108c
SS
11479@item show print object
11480Show whether actual, or declared, object types are displayed.
11481
3345721a 11482@anchor{set print static-members}
c906108c
SS
11483@item set print static-members
11484@itemx set print static-members on
4644b6e3 11485@cindex static members of C@t{++} objects
b37052ae 11486Print static members when displaying a C@t{++} object. The default is on.
c906108c
SS
11487
11488@item set print static-members off
b37052ae 11489Do not print static members when displaying a C@t{++} object.
c906108c 11490
c906108c 11491@item show print static-members
9c16f35a
EZ
11492Show whether C@t{++} static members are printed or not.
11493
11494@item set print pascal_static-members
11495@itemx set print pascal_static-members on
d3e8051b
EZ
11496@cindex static members of Pascal objects
11497@cindex Pascal objects, static members display
9c16f35a
EZ
11498Print static members when displaying a Pascal object. The default is on.
11499
11500@item set print pascal_static-members off
11501Do not print static members when displaying a Pascal object.
11502
11503@item show print pascal_static-members
11504Show whether Pascal static members are printed or not.
c906108c
SS
11505
11506@c These don't work with HP ANSI C++ yet.
3345721a 11507@anchor{set print vtbl}
c906108c
SS
11508@item set print vtbl
11509@itemx set print vtbl on
4644b6e3 11510@cindex pretty print C@t{++} virtual function tables
9c16f35a
EZ
11511@cindex virtual functions (C@t{++}) display
11512@cindex VTBL display
b37052ae 11513Pretty print C@t{++} virtual function tables. The default is off.
c906108c 11514(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 11515ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
11516
11517@item set print vtbl off
b37052ae 11518Do not pretty print C@t{++} virtual function tables.
c906108c 11519
c906108c 11520@item show print vtbl
b37052ae 11521Show whether C@t{++} virtual function tables are pretty printed, or not.
c906108c 11522@end table
c906108c 11523
4c374409
JK
11524@node Pretty Printing
11525@section Pretty Printing
11526
11527@value{GDBN} provides a mechanism to allow pretty-printing of values using
11528Python code. It greatly simplifies the display of complex objects. This
11529mechanism works for both MI and the CLI.
11530
7b51bc51
DE
11531@menu
11532* Pretty-Printer Introduction:: Introduction to pretty-printers
11533* Pretty-Printer Example:: An example pretty-printer
11534* Pretty-Printer Commands:: Pretty-printer commands
11535@end menu
11536
11537@node Pretty-Printer Introduction
11538@subsection Pretty-Printer Introduction
11539
11540When @value{GDBN} prints a value, it first sees if there is a pretty-printer
11541registered for the value. If there is then @value{GDBN} invokes the
11542pretty-printer to print the value. Otherwise the value is printed normally.
11543
11544Pretty-printers are normally named. This makes them easy to manage.
11545The @samp{info pretty-printer} command will list all the installed
11546pretty-printers with their names.
11547If a pretty-printer can handle multiple data types, then its
11548@dfn{subprinters} are the printers for the individual data types.
11549Each such subprinter has its own name.
4e04c971 11550The format of the name is @var{printer-name};@var{subprinter-name}.
7b51bc51
DE
11551
11552Pretty-printers are installed by @dfn{registering} them with @value{GDBN}.
11553Typically they are automatically loaded and registered when the corresponding
11554debug information is loaded, thus making them available without having to
11555do anything special.
11556
11557There are three places where a pretty-printer can be registered.
11558
11559@itemize @bullet
11560@item
11561Pretty-printers registered globally are available when debugging
11562all inferiors.
11563
11564@item
11565Pretty-printers registered with a program space are available only
11566when debugging that program.
11567@xref{Progspaces In Python}, for more details on program spaces in Python.
11568
11569@item
11570Pretty-printers registered with an objfile are loaded and unloaded
11571with the corresponding objfile (e.g., shared library).
11572@xref{Objfiles In Python}, for more details on objfiles in Python.
11573@end itemize
11574
11575@xref{Selecting Pretty-Printers}, for further information on how
11576pretty-printers are selected,
11577
11578@xref{Writing a Pretty-Printer}, for implementing pretty printers
11579for new types.
11580
11581@node Pretty-Printer Example
11582@subsection Pretty-Printer Example
11583
11584Here is how a C@t{++} @code{std::string} looks without a pretty-printer:
4c374409
JK
11585
11586@smallexample
11587(@value{GDBP}) print s
11588$1 = @{
11589 static npos = 4294967295,
11590 _M_dataplus = @{
11591 <std::allocator<char>> = @{
11592 <__gnu_cxx::new_allocator<char>> = @{
11593 <No data fields>@}, <No data fields>
11594 @},
11595 members of std::basic_string<char, std::char_traits<char>,
11596 std::allocator<char> >::_Alloc_hider:
11597 _M_p = 0x804a014 "abcd"
11598 @}
11599@}
11600@end smallexample
11601
11602With a pretty-printer for @code{std::string} only the contents are printed:
11603
11604@smallexample
11605(@value{GDBP}) print s
11606$2 = "abcd"
11607@end smallexample
11608
7b51bc51
DE
11609@node Pretty-Printer Commands
11610@subsection Pretty-Printer Commands
11611@cindex pretty-printer commands
11612
11613@table @code
11614@kindex info pretty-printer
11615@item info pretty-printer [@var{object-regexp} [@var{name-regexp}]]
11616Print the list of installed pretty-printers.
11617This includes disabled pretty-printers, which are marked as such.
11618
11619@var{object-regexp} is a regular expression matching the objects
11620whose pretty-printers to list.
11621Objects can be @code{global}, the program space's file
11622(@pxref{Progspaces In Python}),
11623and the object files within that program space (@pxref{Objfiles In Python}).
11624@xref{Selecting Pretty-Printers}, for details on how @value{GDBN}
11625looks up a printer from these three objects.
11626
11627@var{name-regexp} is a regular expression matching the name of the printers
11628to list.
11629
11630@kindex disable pretty-printer
11631@item disable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
11632Disable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
11633A disabled pretty-printer is not forgotten, it may be enabled again later.
11634
11635@kindex enable pretty-printer
11636@item enable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
11637Enable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
11638@end table
11639
11640Example:
11641
11642Suppose we have three pretty-printers installed: one from library1.so
11643named @code{foo} that prints objects of type @code{foo}, and
11644another from library2.so named @code{bar} that prints two types of objects,
11645@code{bar1} and @code{bar2}.
11646
11647@smallexample
11648(gdb) info pretty-printer
11649library1.so:
11650 foo
11651library2.so:
11652 bar
11653 bar1
11654 bar2
11655(gdb) info pretty-printer library2
11656library2.so:
11657 bar
11658 bar1
11659 bar2
11660(gdb) disable pretty-printer library1
116611 printer disabled
116622 of 3 printers enabled
11663(gdb) info pretty-printer
11664library1.so:
11665 foo [disabled]
11666library2.so:
11667 bar
11668 bar1
11669 bar2
088a96da 11670(gdb) disable pretty-printer library2 bar;bar1
7b51bc51
DE
116711 printer disabled
116721 of 3 printers enabled
11673(gdb) info pretty-printer library2
11674library1.so:
11675 foo [disabled]
11676library2.so:
11677 bar
11678 bar1 [disabled]
11679 bar2
11680(gdb) disable pretty-printer library2 bar
116811 printer disabled
116820 of 3 printers enabled
11683(gdb) info pretty-printer library2
11684library1.so:
11685 foo [disabled]
11686library2.so:
11687 bar [disabled]
11688 bar1 [disabled]
11689 bar2
11690@end smallexample
11691
11692Note that for @code{bar} the entire printer can be disabled,
11693as can each individual subprinter.
4c374409 11694
d8edc8b7
PW
11695Printing values and frame arguments is done by default using
11696the enabled pretty printers.
11697
11698The print option @code{-raw-values} and @value{GDBN} setting
11699@code{set print raw-values} (@pxref{set print raw-values}) can be
11700used to print values without applying the enabled pretty printers.
11701
11702Similarly, the backtrace option @code{-raw-frame-arguments} and
11703@value{GDBN} setting @code{set print raw-frame-arguments}
11704(@pxref{set print raw-frame-arguments}) can be used to ignore the
11705enabled pretty printers when printing frame argument values.
11706
6d2ebf8b 11707@node Value History
79a6e687 11708@section Value History
c906108c
SS
11709
11710@cindex value history
9c16f35a 11711@cindex history of values printed by @value{GDBN}
5d161b24
DB
11712Values printed by the @code{print} command are saved in the @value{GDBN}
11713@dfn{value history}. This allows you to refer to them in other expressions.
11714Values are kept until the symbol table is re-read or discarded
11715(for example with the @code{file} or @code{symbol-file} commands).
11716When the symbol table changes, the value history is discarded,
11717since the values may contain pointers back to the types defined in the
c906108c
SS
11718symbol table.
11719
11720@cindex @code{$}
11721@cindex @code{$$}
11722@cindex history number
11723The values printed are given @dfn{history numbers} by which you can
11724refer to them. These are successive integers starting with one.
11725@code{print} shows you the history number assigned to a value by
11726printing @samp{$@var{num} = } before the value; here @var{num} is the
11727history number.
11728
11729To refer to any previous value, use @samp{$} followed by the value's
11730history number. The way @code{print} labels its output is designed to
11731remind you of this. Just @code{$} refers to the most recent value in
11732the history, and @code{$$} refers to the value before that.
11733@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
11734is the value just prior to @code{$$}, @code{$$1} is equivalent to
11735@code{$$}, and @code{$$0} is equivalent to @code{$}.
11736
11737For example, suppose you have just printed a pointer to a structure and
11738want to see the contents of the structure. It suffices to type
11739
474c8240 11740@smallexample
c906108c 11741p *$
474c8240 11742@end smallexample
c906108c
SS
11743
11744If you have a chain of structures where the component @code{next} points
11745to the next one, you can print the contents of the next one with this:
11746
474c8240 11747@smallexample
c906108c 11748p *$.next
474c8240 11749@end smallexample
c906108c
SS
11750
11751@noindent
11752You can print successive links in the chain by repeating this
11753command---which you can do by just typing @key{RET}.
11754
11755Note that the history records values, not expressions. If the value of
11756@code{x} is 4 and you type these commands:
11757
474c8240 11758@smallexample
c906108c
SS
11759print x
11760set x=5
474c8240 11761@end smallexample
c906108c
SS
11762
11763@noindent
11764then the value recorded in the value history by the @code{print} command
11765remains 4 even though the value of @code{x} has changed.
11766
11767@table @code
11768@kindex show values
11769@item show values
11770Print the last ten values in the value history, with their item numbers.
11771This is like @samp{p@ $$9} repeated ten times, except that @code{show
11772values} does not change the history.
11773
11774@item show values @var{n}
11775Print ten history values centered on history item number @var{n}.
11776
11777@item show values +
11778Print ten history values just after the values last printed. If no more
11779values are available, @code{show values +} produces no display.
11780@end table
11781
11782Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
11783same effect as @samp{show values +}.
11784
6d2ebf8b 11785@node Convenience Vars
79a6e687 11786@section Convenience Variables
c906108c
SS
11787
11788@cindex convenience variables
9c16f35a 11789@cindex user-defined variables
c906108c
SS
11790@value{GDBN} provides @dfn{convenience variables} that you can use within
11791@value{GDBN} to hold on to a value and refer to it later. These variables
11792exist entirely within @value{GDBN}; they are not part of your program, and
11793setting a convenience variable has no direct effect on further execution
11794of your program. That is why you can use them freely.
11795
11796Convenience variables are prefixed with @samp{$}. Any name preceded by
11797@samp{$} can be used for a convenience variable, unless it is one of
d4f3574e 11798the predefined machine-specific register names (@pxref{Registers, ,Registers}).
c906108c 11799(Value history references, in contrast, are @emph{numbers} preceded
79a6e687 11800by @samp{$}. @xref{Value History, ,Value History}.)
c906108c
SS
11801
11802You can save a value in a convenience variable with an assignment
11803expression, just as you would set a variable in your program.
11804For example:
11805
474c8240 11806@smallexample
c906108c 11807set $foo = *object_ptr
474c8240 11808@end smallexample
c906108c
SS
11809
11810@noindent
11811would save in @code{$foo} the value contained in the object pointed to by
11812@code{object_ptr}.
11813
11814Using a convenience variable for the first time creates it, but its
11815value is @code{void} until you assign a new value. You can alter the
11816value with another assignment at any time.
11817
11818Convenience variables have no fixed types. You can assign a convenience
11819variable any type of value, including structures and arrays, even if
11820that variable already has a value of a different type. The convenience
11821variable, when used as an expression, has the type of its current value.
11822
11823@table @code
11824@kindex show convenience
f47f77df 11825@cindex show all user variables and functions
c906108c 11826@item show convenience
f47f77df
DE
11827Print a list of convenience variables used so far, and their values,
11828as well as a list of the convenience functions.
d4f3574e 11829Abbreviated @code{show conv}.
53e5f3cf
AS
11830
11831@kindex init-if-undefined
11832@cindex convenience variables, initializing
11833@item init-if-undefined $@var{variable} = @var{expression}
11834Set a convenience variable if it has not already been set. This is useful
11835for user-defined commands that keep some state. It is similar, in concept,
11836to using local static variables with initializers in C (except that
11837convenience variables are global). It can also be used to allow users to
11838override default values used in a command script.
11839
11840If the variable is already defined then the expression is not evaluated so
11841any side-effects do not occur.
c906108c
SS
11842@end table
11843
11844One of the ways to use a convenience variable is as a counter to be
11845incremented or a pointer to be advanced. For example, to print
11846a field from successive elements of an array of structures:
11847
474c8240 11848@smallexample
c906108c
SS
11849set $i = 0
11850print bar[$i++]->contents
474c8240 11851@end smallexample
c906108c 11852
d4f3574e
SS
11853@noindent
11854Repeat that command by typing @key{RET}.
c906108c
SS
11855
11856Some convenience variables are created automatically by @value{GDBN} and given
11857values likely to be useful.
11858
11859@table @code
41afff9a 11860@vindex $_@r{, convenience variable}
c906108c
SS
11861@item $_
11862The variable @code{$_} is automatically set by the @code{x} command to
79a6e687 11863the last address examined (@pxref{Memory, ,Examining Memory}). Other
c906108c
SS
11864commands which provide a default address for @code{x} to examine also
11865set @code{$_} to that address; these commands include @code{info line}
11866and @code{info breakpoint}. The type of @code{$_} is @code{void *}
11867except when set by the @code{x} command, in which case it is a pointer
11868to the type of @code{$__}.
11869
41afff9a 11870@vindex $__@r{, convenience variable}
c906108c
SS
11871@item $__
11872The variable @code{$__} is automatically set by the @code{x} command
11873to the value found in the last address examined. Its type is chosen
11874to match the format in which the data was printed.
11875
11876@item $_exitcode
41afff9a 11877@vindex $_exitcode@r{, convenience variable}
0c557179
SDJ
11878When the program being debugged terminates normally, @value{GDBN}
11879automatically sets this variable to the exit code of the program, and
11880resets @code{$_exitsignal} to @code{void}.
11881
11882@item $_exitsignal
11883@vindex $_exitsignal@r{, convenience variable}
11884When the program being debugged dies due to an uncaught signal,
11885@value{GDBN} automatically sets this variable to that signal's number,
11886and resets @code{$_exitcode} to @code{void}.
11887
11888To distinguish between whether the program being debugged has exited
11889(i.e., @code{$_exitcode} is not @code{void}) or signalled (i.e.,
11890@code{$_exitsignal} is not @code{void}), the convenience function
11891@code{$_isvoid} can be used (@pxref{Convenience Funs,, Convenience
11892Functions}). For example, considering the following source code:
11893
11894@smallexample
11895#include <signal.h>
11896
11897int
11898main (int argc, char *argv[])
11899@{
11900 raise (SIGALRM);
11901 return 0;
11902@}
11903@end smallexample
11904
11905A valid way of telling whether the program being debugged has exited
11906or signalled would be:
11907
11908@smallexample
11909(@value{GDBP}) define has_exited_or_signalled
11910Type commands for definition of ``has_exited_or_signalled''.
11911End with a line saying just ``end''.
11912>if $_isvoid ($_exitsignal)
11913 >echo The program has exited\n
11914 >else
11915 >echo The program has signalled\n
11916 >end
11917>end
11918(@value{GDBP}) run
11919Starting program:
11920
11921Program terminated with signal SIGALRM, Alarm clock.
11922The program no longer exists.
11923(@value{GDBP}) has_exited_or_signalled
11924The program has signalled
11925@end smallexample
11926
11927As can be seen, @value{GDBN} correctly informs that the program being
11928debugged has signalled, since it calls @code{raise} and raises a
11929@code{SIGALRM} signal. If the program being debugged had not called
11930@code{raise}, then @value{GDBN} would report a normal exit:
11931
11932@smallexample
11933(@value{GDBP}) has_exited_or_signalled
11934The program has exited
11935@end smallexample
4aa995e1 11936
72f1fe8a
TT
11937@item $_exception
11938The variable @code{$_exception} is set to the exception object being
11939thrown at an exception-related catchpoint. @xref{Set Catchpoints}.
11940
37f6a7f4
TT
11941@item $_ada_exception
11942The variable @code{$_ada_exception} is set to the address of the
11943exception being caught or thrown at an Ada exception-related
11944catchpoint. @xref{Set Catchpoints}.
11945
62e5f89c
SDJ
11946@item $_probe_argc
11947@itemx $_probe_arg0@dots{}$_probe_arg11
11948Arguments to a static probe. @xref{Static Probe Points}.
11949
0fb4aa4b
PA
11950@item $_sdata
11951@vindex $_sdata@r{, inspect, convenience variable}
11952The variable @code{$_sdata} contains extra collected static tracepoint
11953data. @xref{Tracepoint Actions,,Tracepoint Action Lists}. Note that
11954@code{$_sdata} could be empty, if not inspecting a trace buffer, or
11955if extra static tracepoint data has not been collected.
11956
4aa995e1
PA
11957@item $_siginfo
11958@vindex $_siginfo@r{, convenience variable}
ec7e75e7
PP
11959The variable @code{$_siginfo} contains extra signal information
11960(@pxref{extra signal information}). Note that @code{$_siginfo}
11961could be empty, if the application has not yet received any signals.
11962For example, it will be empty before you execute the @code{run} command.
711e434b
PM
11963
11964@item $_tlb
11965@vindex $_tlb@r{, convenience variable}
11966The variable @code{$_tlb} is automatically set when debugging
11967applications running on MS-Windows in native mode or connected to
7734102d 11968gdbserver that supports the @code{qGetTIBAddr} request.
711e434b
PM
11969@xref{General Query Packets}.
11970This variable contains the address of the thread information block.
11971
e3940304 11972@item $_inferior
65c574f6
PA
11973The number of the current inferior. @xref{Inferiors Connections and
11974Programs, ,Debugging Multiple Inferiors Connections and Programs}.
e3940304 11975
5d5658a1
PA
11976@item $_thread
11977The thread number of the current thread. @xref{thread numbers}.
11978
663f6d42
PA
11979@item $_gthread
11980The global number of the current thread. @xref{global thread numbers}.
11981
7734102d
EZ
11982@item $_gdb_major
11983@itemx $_gdb_minor
11984@vindex $_gdb_major@r{, convenience variable}
11985@vindex $_gdb_minor@r{, convenience variable}
11986The major and minor version numbers of the running @value{GDBN}.
11987Development snapshots and pretest versions have their minor version
11988incremented by one; thus, @value{GDBN} pretest 9.11.90 will produce
11989the value 12 for @code{$_gdb_minor}. These variables allow you to
11990write scripts that work with different versions of @value{GDBN}
11991without errors caused by features unavailable in some of those
11992versions.
e2c52041
PW
11993
11994@item $_shell_exitcode
11995@itemx $_shell_exitsignal
11996@vindex $_shell_exitcode@r{, convenience variable}
11997@vindex $_shell_exitsignal@r{, convenience variable}
11998@cindex shell command, exit code
11999@cindex shell command, exit signal
12000@cindex exit status of shell commands
12001@value{GDBN} commands such as @code{shell} and @code{|} are launching
12002shell commands. When a launched command terminates, @value{GDBN}
12003automatically maintains the variables @code{$_shell_exitcode}
12004and @code{$_shell_exitsignal} according to the exit status of the last
12005launched command. These variables are set and used similarly to
12006the variables @code{$_exitcode} and @code{$_exitsignal}.
12007
c906108c
SS
12008@end table
12009
a72c3253
DE
12010@node Convenience Funs
12011@section Convenience Functions
12012
bc3b79fd
TJB
12013@cindex convenience functions
12014@value{GDBN} also supplies some @dfn{convenience functions}. These
12015have a syntax similar to convenience variables. A convenience
12016function can be used in an expression just like an ordinary function;
12017however, a convenience function is implemented internally to
12018@value{GDBN}.
12019
a280dbd1
SDJ
12020These functions do not require @value{GDBN} to be configured with
12021@code{Python} support, which means that they are always available.
12022
12023@table @code
12024
12025@item $_isvoid (@var{expr})
12026@findex $_isvoid@r{, convenience function}
12027Return one if the expression @var{expr} is @code{void}. Otherwise it
12028returns zero.
12029
12030A @code{void} expression is an expression where the type of the result
12031is @code{void}. For example, you can examine a convenience variable
12032(see @ref{Convenience Vars,, Convenience Variables}) to check whether
12033it is @code{void}:
12034
12035@smallexample
12036(@value{GDBP}) print $_exitcode
12037$1 = void
12038(@value{GDBP}) print $_isvoid ($_exitcode)
12039$2 = 1
12040(@value{GDBP}) run
12041Starting program: ./a.out
12042[Inferior 1 (process 29572) exited normally]
12043(@value{GDBP}) print $_exitcode
12044$3 = 0
12045(@value{GDBP}) print $_isvoid ($_exitcode)
12046$4 = 0
12047@end smallexample
12048
12049In the example above, we used @code{$_isvoid} to check whether
12050@code{$_exitcode} is @code{void} before and after the execution of the
12051program being debugged. Before the execution there is no exit code to
12052be examined, therefore @code{$_exitcode} is @code{void}. After the
12053execution the program being debugged returned zero, therefore
12054@code{$_exitcode} is zero, which means that it is not @code{void}
12055anymore.
12056
12057The @code{void} expression can also be a call of a function from the
12058program being debugged. For example, given the following function:
12059
12060@smallexample
12061void
12062foo (void)
12063@{
12064@}
12065@end smallexample
12066
12067The result of calling it inside @value{GDBN} is @code{void}:
12068
12069@smallexample
12070(@value{GDBP}) print foo ()
12071$1 = void
12072(@value{GDBP}) print $_isvoid (foo ())
12073$2 = 1
12074(@value{GDBP}) set $v = foo ()
12075(@value{GDBP}) print $v
12076$3 = void
12077(@value{GDBP}) print $_isvoid ($v)
12078$4 = 1
12079@end smallexample
12080
aed61d02
PW
12081@item $_gdb_setting_str (@var{setting})
12082@findex $_gdb_setting_str@r{, convenience function}
12083Return the value of the @value{GDBN} @var{setting} as a string.
12084@var{setting} is any setting that can be used in a @code{set} or
12085@code{show} command (@pxref{Controlling GDB}).
12086
12087@smallexample
12088(@value{GDBP}) show print frame-arguments
12089Printing of non-scalar frame arguments is "scalars".
12090(@value{GDBP}) p $_gdb_setting_str("print frame-arguments")
12091$1 = "scalars"
12092(@value{GDBP}) p $_gdb_setting_str("height")
12093$2 = "30"
12094(@value{GDBP})
12095@end smallexample
12096
12097@item $_gdb_setting (@var{setting})
12098@findex $_gdb_setting@r{, convenience function}
12099Return the value of the @value{GDBN} @var{setting}.
12100The type of the returned value depends on the setting.
12101
12102The value type for boolean and auto boolean settings is @code{int}.
12103The boolean values @code{off} and @code{on} are converted to
12104the integer values @code{0} and @code{1}. The value @code{auto} is
12105converted to the value @code{-1}.
12106
12107The value type for integer settings is either @code{unsigned int}
12108or @code{int}, depending on the setting.
12109
12110Some integer settings accept an @code{unlimited} value.
12111Depending on the setting, the @code{set} command also accepts
12112the value @code{0} or the value @code{@minus{}1} as a synonym for
12113@code{unlimited}.
12114For example, @code{set height unlimited} is equivalent to
12115@code{set height 0}.
12116
12117Some other settings that accept the @code{unlimited} value
12118use the value @code{0} to literally mean zero.
12119For example, @code{set history size 0} indicates to not
12120record any @value{GDBN} commands in the command history.
12121For such settings, @code{@minus{}1} is the synonym
12122for @code{unlimited}.
12123
12124See the documentation of the corresponding @code{set} command for
12125the numerical value equivalent to @code{unlimited}.
12126
12127The @code{$_gdb_setting} function converts the unlimited value
12128to a @code{0} or a @code{@minus{}1} value according to what the
12129@code{set} command uses.
12130
12131@smallexample
12132@group
12133(@value{GDBP}) p $_gdb_setting_str("height")
12134$1 = "30"
12135(@value{GDBP}) p $_gdb_setting("height")
12136$2 = 30
12137(@value{GDBP}) set height unlimited
12138(@value{GDBP}) p $_gdb_setting_str("height")
12139$3 = "unlimited"
12140(@value{GDBP}) p $_gdb_setting("height")
12141$4 = 0
12142@end group
12143@group
12144(@value{GDBP}) p $_gdb_setting_str("history size")
12145$5 = "unlimited"
12146(@value{GDBP}) p $_gdb_setting("history size")
12147$6 = -1
12148(@value{GDBP}) p $_gdb_setting_str("disassemble-next-line")
12149$7 = "auto"
12150(@value{GDBP}) p $_gdb_setting("disassemble-next-line")
12151$8 = -1
12152(@value{GDBP})
12153@end group
12154@end smallexample
12155
12156Other setting types (enum, filename, optional filename, string, string noescape)
12157are returned as string values.
12158
12159
12160@item $_gdb_maint_setting_str (@var{setting})
12161@findex $_gdb_maint_setting_str@r{, convenience function}
12162Like the @code{$_gdb_setting_str} function, but works with
12163@code{maintenance set} variables.
12164
12165@item $_gdb_maint_setting (@var{setting})
12166@findex $_gdb_maint_setting@r{, convenience function}
12167Like the @code{$_gdb_setting} function, but works with
12168@code{maintenance set} variables.
12169
a280dbd1
SDJ
12170@end table
12171
aed61d02 12172The following functions require @value{GDBN} to be configured with
a72c3253
DE
12173@code{Python} support.
12174
12175@table @code
12176
12177@item $_memeq(@var{buf1}, @var{buf2}, @var{length})
12178@findex $_memeq@r{, convenience function}
12179Returns one if the @var{length} bytes at the addresses given by
12180@var{buf1} and @var{buf2} are equal.
12181Otherwise it returns zero.
12182
12183@item $_regex(@var{str}, @var{regex})
12184@findex $_regex@r{, convenience function}
12185Returns one if the string @var{str} matches the regular expression
12186@var{regex}. Otherwise it returns zero.
12187The syntax of the regular expression is that specified by @code{Python}'s
12188regular expression support.
12189
12190@item $_streq(@var{str1}, @var{str2})
12191@findex $_streq@r{, convenience function}
12192Returns one if the strings @var{str1} and @var{str2} are equal.
12193Otherwise it returns zero.
12194
12195@item $_strlen(@var{str})
12196@findex $_strlen@r{, convenience function}
12197Returns the length of string @var{str}.
12198
faa42425
DE
12199@item $_caller_is(@var{name}@r{[}, @var{number_of_frames}@r{]})
12200@findex $_caller_is@r{, convenience function}
12201Returns one if the calling function's name is equal to @var{name}.
12202Otherwise it returns zero.
12203
12204If the optional argument @var{number_of_frames} is provided,
12205it is the number of frames up in the stack to look.
12206The default is 1.
12207
12208Example:
12209
12210@smallexample
12211(gdb) backtrace
12212#0 bottom_func ()
12213 at testsuite/gdb.python/py-caller-is.c:21
12214#1 0x00000000004005a0 in middle_func ()
12215 at testsuite/gdb.python/py-caller-is.c:27
12216#2 0x00000000004005ab in top_func ()
12217 at testsuite/gdb.python/py-caller-is.c:33
12218#3 0x00000000004005b6 in main ()
12219 at testsuite/gdb.python/py-caller-is.c:39
12220(gdb) print $_caller_is ("middle_func")
12221$1 = 1
12222(gdb) print $_caller_is ("top_func", 2)
12223$1 = 1
12224@end smallexample
12225
12226@item $_caller_matches(@var{regexp}@r{[}, @var{number_of_frames}@r{]})
12227@findex $_caller_matches@r{, convenience function}
12228Returns one if the calling function's name matches the regular expression
12229@var{regexp}. Otherwise it returns zero.
12230
12231If the optional argument @var{number_of_frames} is provided,
12232it is the number of frames up in the stack to look.
12233The default is 1.
12234
12235@item $_any_caller_is(@var{name}@r{[}, @var{number_of_frames}@r{]})
12236@findex $_any_caller_is@r{, convenience function}
12237Returns one if any calling function's name is equal to @var{name}.
12238Otherwise it returns zero.
12239
12240If the optional argument @var{number_of_frames} is provided,
12241it is the number of frames up in the stack to look.
12242The default is 1.
12243
12244This function differs from @code{$_caller_is} in that this function
12245checks all stack frames from the immediate caller to the frame specified
12246by @var{number_of_frames}, whereas @code{$_caller_is} only checks the
12247frame specified by @var{number_of_frames}.
12248
12249@item $_any_caller_matches(@var{regexp}@r{[}, @var{number_of_frames}@r{]})
12250@findex $_any_caller_matches@r{, convenience function}
12251Returns one if any calling function's name matches the regular expression
12252@var{regexp}. Otherwise it returns zero.
12253
12254If the optional argument @var{number_of_frames} is provided,
12255it is the number of frames up in the stack to look.
12256The default is 1.
12257
12258This function differs from @code{$_caller_matches} in that this function
12259checks all stack frames from the immediate caller to the frame specified
12260by @var{number_of_frames}, whereas @code{$_caller_matches} only checks the
12261frame specified by @var{number_of_frames}.
12262
f2f3ccb9
SM
12263@item $_as_string(@var{value})
12264@findex $_as_string@r{, convenience function}
12265Return the string representation of @var{value}.
12266
12267This function is useful to obtain the textual label (enumerator) of an
12268enumeration value. For example, assuming the variable @var{node} is of
12269an enumerated type:
12270
12271@smallexample
12272(gdb) printf "Visiting node of type %s\n", $_as_string(node)
12273Visiting node of type NODE_INTEGER
12274@end smallexample
12275
8bdc1658
AB
12276@item $_cimag(@var{value})
12277@itemx $_creal(@var{value})
12278@findex $_cimag@r{, convenience function}
12279@findex $_creal@r{, convenience function}
12280Return the imaginary (@code{$_cimag}) or real (@code{$_creal}) part of
12281the complex number @var{value}.
12282
12283The type of the imaginary or real part depends on the type of the
12284complex number, e.g., using @code{$_cimag} on a @code{float complex}
12285will return an imaginary part of type @code{float}.
12286
a72c3253
DE
12287@end table
12288
12289@value{GDBN} provides the ability to list and get help on
12290convenience functions.
12291
bc3b79fd
TJB
12292@table @code
12293@item help function
12294@kindex help function
12295@cindex show all convenience functions
12296Print a list of all convenience functions.
12297@end table
12298
6d2ebf8b 12299@node Registers
c906108c
SS
12300@section Registers
12301
12302@cindex registers
12303You can refer to machine register contents, in expressions, as variables
12304with names starting with @samp{$}. The names of registers are different
12305for each machine; use @code{info registers} to see the names used on
12306your machine.
12307
12308@table @code
12309@kindex info registers
12310@item info registers
12311Print the names and values of all registers except floating-point
c85508ee 12312and vector registers (in the selected stack frame).
c906108c
SS
12313
12314@kindex info all-registers
12315@cindex floating point registers
12316@item info all-registers
12317Print the names and values of all registers, including floating-point
c85508ee 12318and vector registers (in the selected stack frame).
c906108c 12319
b67d92b0
SH
12320@item info registers @var{reggroup} @dots{}
12321Print the name and value of the registers in each of the specified
6b92c0d3 12322@var{reggroup}s. The @var{reggroup} can be any of those returned by
b67d92b0
SH
12323@code{maint print reggroups} (@pxref{Maintenance Commands}).
12324
c906108c
SS
12325@item info registers @var{regname} @dots{}
12326Print the @dfn{relativized} value of each specified register @var{regname}.
5d161b24 12327As discussed in detail below, register values are normally relative to
697aa1b7 12328the selected stack frame. The @var{regname} may be any register name valid on
c906108c
SS
12329the machine you are using, with or without the initial @samp{$}.
12330@end table
12331
f5b95c01 12332@anchor{standard registers}
e09f16f9
EZ
12333@cindex stack pointer register
12334@cindex program counter register
12335@cindex process status register
12336@cindex frame pointer register
12337@cindex standard registers
c906108c
SS
12338@value{GDBN} has four ``standard'' register names that are available (in
12339expressions) on most machines---whenever they do not conflict with an
12340architecture's canonical mnemonics for registers. The register names
12341@code{$pc} and @code{$sp} are used for the program counter register and
12342the stack pointer. @code{$fp} is used for a register that contains a
12343pointer to the current stack frame, and @code{$ps} is used for a
12344register that contains the processor status. For example,
12345you could print the program counter in hex with
12346
474c8240 12347@smallexample
c906108c 12348p/x $pc
474c8240 12349@end smallexample
c906108c
SS
12350
12351@noindent
12352or print the instruction to be executed next with
12353
474c8240 12354@smallexample
c906108c 12355x/i $pc
474c8240 12356@end smallexample
c906108c
SS
12357
12358@noindent
12359or add four to the stack pointer@footnote{This is a way of removing
12360one word from the stack, on machines where stacks grow downward in
12361memory (most machines, nowadays). This assumes that the innermost
12362stack frame is selected; setting @code{$sp} is not allowed when other
12363stack frames are selected. To pop entire frames off the stack,
12364regardless of machine architecture, use @code{return};
79a6e687 12365see @ref{Returning, ,Returning from a Function}.} with
c906108c 12366
474c8240 12367@smallexample
c906108c 12368set $sp += 4
474c8240 12369@end smallexample
c906108c
SS
12370
12371Whenever possible, these four standard register names are available on
12372your machine even though the machine has different canonical mnemonics,
12373so long as there is no conflict. The @code{info registers} command
12374shows the canonical names. For example, on the SPARC, @code{info
12375registers} displays the processor status register as @code{$psr} but you
d4f3574e
SS
12376can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
12377is an alias for the @sc{eflags} register.
c906108c
SS
12378
12379@value{GDBN} always considers the contents of an ordinary register as an
12380integer when the register is examined in this way. Some machines have
12381special registers which can hold nothing but floating point; these
12382registers are considered to have floating point values. There is no way
12383to refer to the contents of an ordinary register as floating point value
12384(although you can @emph{print} it as a floating point value with
12385@samp{print/f $@var{regname}}).
12386
12387Some registers have distinct ``raw'' and ``virtual'' data formats. This
12388means that the data format in which the register contents are saved by
12389the operating system is not the same one that your program normally
12390sees. For example, the registers of the 68881 floating point
12391coprocessor are always saved in ``extended'' (raw) format, but all C
12392programs expect to work with ``double'' (virtual) format. In such
5d161b24 12393cases, @value{GDBN} normally works with the virtual format only (the format
c906108c
SS
12394that makes sense for your program), but the @code{info registers} command
12395prints the data in both formats.
12396
36b80e65
EZ
12397@cindex SSE registers (x86)
12398@cindex MMX registers (x86)
12399Some machines have special registers whose contents can be interpreted
12400in several different ways. For example, modern x86-based machines
12401have SSE and MMX registers that can hold several values packed
12402together in several different formats. @value{GDBN} refers to such
12403registers in @code{struct} notation:
12404
12405@smallexample
12406(@value{GDBP}) print $xmm1
12407$1 = @{
12408 v4_float = @{0, 3.43859137e-038, 1.54142831e-044, 1.821688e-044@},
12409 v2_double = @{9.92129282474342e-303, 2.7585945287983262e-313@},
12410 v16_int8 = "\000\000\000\000\3706;\001\v\000\000\000\r\000\000",
12411 v8_int16 = @{0, 0, 14072, 315, 11, 0, 13, 0@},
12412 v4_int32 = @{0, 20657912, 11, 13@},
12413 v2_int64 = @{88725056443645952, 55834574859@},
12414 uint128 = 0x0000000d0000000b013b36f800000000
12415@}
12416@end smallexample
12417
12418@noindent
12419To set values of such registers, you need to tell @value{GDBN} which
12420view of the register you wish to change, as if you were assigning
12421value to a @code{struct} member:
12422
12423@smallexample
12424 (@value{GDBP}) set $xmm1.uint128 = 0x000000000000000000000000FFFFFFFF
12425@end smallexample
12426
c906108c 12427Normally, register values are relative to the selected stack frame
79a6e687 12428(@pxref{Selection, ,Selecting a Frame}). This means that you get the
c906108c
SS
12429value that the register would contain if all stack frames farther in
12430were exited and their saved registers restored. In order to see the
12431true contents of hardware registers, you must select the innermost
12432frame (with @samp{frame 0}).
12433
901461f8
PA
12434@cindex caller-saved registers
12435@cindex call-clobbered registers
12436@cindex volatile registers
12437@cindex <not saved> values
12438Usually ABIs reserve some registers as not needed to be saved by the
12439callee (a.k.a.: ``caller-saved'', ``call-clobbered'' or ``volatile''
12440registers). It may therefore not be possible for @value{GDBN} to know
12441the value a register had before the call (in other words, in the outer
12442frame), if the register value has since been changed by the callee.
12443@value{GDBN} tries to deduce where the inner frame saved
12444(``callee-saved'') registers, from the debug info, unwind info, or the
12445machine code generated by your compiler. If some register is not
12446saved, and @value{GDBN} knows the register is ``caller-saved'' (via
12447its own knowledge of the ABI, or because the debug/unwind info
12448explicitly says the register's value is undefined), @value{GDBN}
12449displays @w{@samp{<not saved>}} as the register's value. With targets
12450that @value{GDBN} has no knowledge of the register saving convention,
12451if a register was not saved by the callee, then its value and location
12452in the outer frame are assumed to be the same of the inner frame.
12453This is usually harmless, because if the register is call-clobbered,
12454the caller either does not care what is in the register after the
12455call, or has code to restore the value that it does care about. Note,
12456however, that if you change such a register in the outer frame, you
12457may also be affecting the inner frame. Also, the more ``outer'' the
12458frame is you're looking at, the more likely a call-clobbered
12459register's value is to be wrong, in the sense that it doesn't actually
12460represent the value the register had just before the call.
c906108c 12461
6d2ebf8b 12462@node Floating Point Hardware
79a6e687 12463@section Floating Point Hardware
c906108c
SS
12464@cindex floating point
12465
12466Depending on the configuration, @value{GDBN} may be able to give
12467you more information about the status of the floating point hardware.
12468
12469@table @code
12470@kindex info float
12471@item info float
12472Display hardware-dependent information about the floating
12473point unit. The exact contents and layout vary depending on the
12474floating point chip. Currently, @samp{info float} is supported on
12475the ARM and x86 machines.
12476@end table
c906108c 12477
e76f1f2e
AC
12478@node Vector Unit
12479@section Vector Unit
12480@cindex vector unit
12481
12482Depending on the configuration, @value{GDBN} may be able to give you
12483more information about the status of the vector unit.
12484
12485@table @code
12486@kindex info vector
12487@item info vector
12488Display information about the vector unit. The exact contents and
12489layout vary depending on the hardware.
12490@end table
12491
721c2651 12492@node OS Information
79a6e687 12493@section Operating System Auxiliary Information
721c2651
EZ
12494@cindex OS information
12495
12496@value{GDBN} provides interfaces to useful OS facilities that can help
12497you debug your program.
12498
b383017d
RM
12499@cindex auxiliary vector
12500@cindex vector, auxiliary
b383017d
RM
12501Some operating systems supply an @dfn{auxiliary vector} to programs at
12502startup. This is akin to the arguments and environment that you
12503specify for a program, but contains a system-dependent variety of
12504binary values that tell system libraries important details about the
12505hardware, operating system, and process. Each value's purpose is
12506identified by an integer tag; the meanings are well-known but system-specific.
12507Depending on the configuration and operating system facilities,
9c16f35a
EZ
12508@value{GDBN} may be able to show you this information. For remote
12509targets, this functionality may further depend on the remote stub's
427c3a89
DJ
12510support of the @samp{qXfer:auxv:read} packet, see
12511@ref{qXfer auxiliary vector read}.
b383017d
RM
12512
12513@table @code
12514@kindex info auxv
12515@item info auxv
12516Display the auxiliary vector of the inferior, which can be either a
e4937fc1 12517live process or a core dump file. @value{GDBN} prints each tag value
b383017d
RM
12518numerically, and also shows names and text descriptions for recognized
12519tags. Some values in the vector are numbers, some bit masks, and some
e4937fc1 12520pointers to strings or other data. @value{GDBN} displays each value in the
b383017d
RM
12521most appropriate form for a recognized tag, and in hexadecimal for
12522an unrecognized tag.
12523@end table
12524
85d4a676
SS
12525On some targets, @value{GDBN} can access operating system-specific
12526information and show it to you. The types of information available
12527will differ depending on the type of operating system running on the
12528target. The mechanism used to fetch the data is described in
12529@ref{Operating System Information}. For remote targets, this
12530functionality depends on the remote stub's support of the
07e059b5
VP
12531@samp{qXfer:osdata:read} packet, see @ref{qXfer osdata read}.
12532
12533@table @code
a61408f8 12534@kindex info os
85d4a676
SS
12535@item info os @var{infotype}
12536
12537Display OS information of the requested type.
a61408f8 12538
85d4a676
SS
12539On @sc{gnu}/Linux, the following values of @var{infotype} are valid:
12540
12541@anchor{linux info os infotypes}
12542@table @code
d33279b3
AT
12543@kindex info os cpus
12544@item cpus
12545Display the list of all CPUs/cores. For each CPU/core, @value{GDBN} prints
12546the available fields from /proc/cpuinfo. For each supported architecture
12547different fields are available. Two common entries are processor which gives
12548CPU number and bogomips; a system constant that is calculated during
12549kernel initialization.
12550
12551@kindex info os files
12552@item files
12553Display the list of open file descriptors on the target. For each
12554file descriptor, @value{GDBN} prints the identifier of the process
12555owning the descriptor, the command of the owning process, the value
12556of the descriptor, and the target of the descriptor.
12557
12558@kindex info os modules
12559@item modules
12560Display the list of all loaded kernel modules on the target. For each
12561module, @value{GDBN} prints the module name, the size of the module in
12562bytes, the number of times the module is used, the dependencies of the
12563module, the status of the module, and the address of the loaded module
12564in memory.
12565
12566@kindex info os msg
12567@item msg
12568Display the list of all System V message queues on the target. For each
12569message queue, @value{GDBN} prints the message queue key, the message
12570queue identifier, the access permissions, the current number of bytes
12571on the queue, the current number of messages on the queue, the processes
12572that last sent and received a message on the queue, the user and group
12573of the owner and creator of the message queue, the times at which a
12574message was last sent and received on the queue, and the time at which
12575the message queue was last changed.
12576
07e059b5 12577@kindex info os processes
85d4a676 12578@item processes
07e059b5 12579Display the list of processes on the target. For each process,
85d4a676
SS
12580@value{GDBN} prints the process identifier, the name of the user, the
12581command corresponding to the process, and the list of processor cores
12582that the process is currently running on. (To understand what these
12583properties mean, for this and the following info types, please consult
12584the general @sc{gnu}/Linux documentation.)
12585
12586@kindex info os procgroups
12587@item procgroups
12588Display the list of process groups on the target. For each process,
12589@value{GDBN} prints the identifier of the process group that it belongs
12590to, the command corresponding to the process group leader, the process
12591identifier, and the command line of the process. The list is sorted
12592first by the process group identifier, then by the process identifier,
12593so that processes belonging to the same process group are grouped together
12594and the process group leader is listed first.
12595
d33279b3
AT
12596@kindex info os semaphores
12597@item semaphores
12598Display the list of all System V semaphore sets on the target. For each
12599semaphore set, @value{GDBN} prints the semaphore set key, the semaphore
12600set identifier, the access permissions, the number of semaphores in the
12601set, the user and group of the owner and creator of the semaphore set,
12602and the times at which the semaphore set was operated upon and changed.
85d4a676
SS
12603
12604@kindex info os shm
12605@item shm
12606Display the list of all System V shared-memory regions on the target.
12607For each shared-memory region, @value{GDBN} prints the region key,
12608the shared-memory identifier, the access permissions, the size of the
12609region, the process that created the region, the process that last
12610attached to or detached from the region, the current number of live
12611attaches to the region, and the times at which the region was last
12612attached to, detach from, and changed.
12613
d33279b3
AT
12614@kindex info os sockets
12615@item sockets
12616Display the list of Internet-domain sockets on the target. For each
12617socket, @value{GDBN} prints the address and port of the local and
12618remote endpoints, the current state of the connection, the creator of
12619the socket, the IP address family of the socket, and the type of the
12620connection.
85d4a676 12621
d33279b3
AT
12622@kindex info os threads
12623@item threads
12624Display the list of threads running on the target. For each thread,
12625@value{GDBN} prints the identifier of the process that the thread
12626belongs to, the command of the process, the thread identifier, and the
12627processor core that it is currently running on. The main thread of a
12628process is not listed.
85d4a676
SS
12629@end table
12630
12631@item info os
12632If @var{infotype} is omitted, then list the possible values for
12633@var{infotype} and the kind of OS information available for each
12634@var{infotype}. If the target does not return a list of possible
12635types, this command will report an error.
07e059b5 12636@end table
721c2651 12637
29e57380 12638@node Memory Region Attributes
79a6e687 12639@section Memory Region Attributes
29e57380
C
12640@cindex memory region attributes
12641
b383017d 12642@dfn{Memory region attributes} allow you to describe special handling
fd79ecee
DJ
12643required by regions of your target's memory. @value{GDBN} uses
12644attributes to determine whether to allow certain types of memory
12645accesses; whether to use specific width accesses; and whether to cache
12646target memory. By default the description of memory regions is
12647fetched from the target (if the current target supports this), but the
12648user can override the fetched regions.
29e57380
C
12649
12650Defined memory regions can be individually enabled and disabled. When a
12651memory region is disabled, @value{GDBN} uses the default attributes when
12652accessing memory in that region. Similarly, if no memory regions have
12653been defined, @value{GDBN} uses the default attributes when accessing
12654all memory.
12655
b383017d 12656When a memory region is defined, it is given a number to identify it;
29e57380
C
12657to enable, disable, or remove a memory region, you specify that number.
12658
12659@table @code
12660@kindex mem
bfac230e 12661@item mem @var{lower} @var{upper} @var{attributes}@dots{}
09d4efe1
EZ
12662Define a memory region bounded by @var{lower} and @var{upper} with
12663attributes @var{attributes}@dots{}, and add it to the list of regions
12664monitored by @value{GDBN}. Note that @var{upper} == 0 is a special
d3e8051b 12665case: it is treated as the target's maximum memory address.
bfac230e 12666(0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
29e57380 12667
fd79ecee
DJ
12668@item mem auto
12669Discard any user changes to the memory regions and use target-supplied
12670regions, if available, or no regions if the target does not support.
12671
29e57380
C
12672@kindex delete mem
12673@item delete mem @var{nums}@dots{}
09d4efe1
EZ
12674Remove memory regions @var{nums}@dots{} from the list of regions
12675monitored by @value{GDBN}.
29e57380
C
12676
12677@kindex disable mem
12678@item disable mem @var{nums}@dots{}
09d4efe1 12679Disable monitoring of memory regions @var{nums}@dots{}.
b383017d 12680A disabled memory region is not forgotten.
29e57380
C
12681It may be enabled again later.
12682
12683@kindex enable mem
12684@item enable mem @var{nums}@dots{}
09d4efe1 12685Enable monitoring of memory regions @var{nums}@dots{}.
29e57380
C
12686
12687@kindex info mem
12688@item info mem
12689Print a table of all defined memory regions, with the following columns
09d4efe1 12690for each region:
29e57380
C
12691
12692@table @emph
12693@item Memory Region Number
12694@item Enabled or Disabled.
b383017d 12695Enabled memory regions are marked with @samp{y}.
29e57380
C
12696Disabled memory regions are marked with @samp{n}.
12697
12698@item Lo Address
12699The address defining the inclusive lower bound of the memory region.
12700
12701@item Hi Address
12702The address defining the exclusive upper bound of the memory region.
12703
12704@item Attributes
12705The list of attributes set for this memory region.
12706@end table
12707@end table
12708
12709
12710@subsection Attributes
12711
b383017d 12712@subsubsection Memory Access Mode
29e57380
C
12713The access mode attributes set whether @value{GDBN} may make read or
12714write accesses to a memory region.
12715
12716While these attributes prevent @value{GDBN} from performing invalid
12717memory accesses, they do nothing to prevent the target system, I/O DMA,
359df76b 12718etc.@: from accessing memory.
29e57380
C
12719
12720@table @code
12721@item ro
12722Memory is read only.
12723@item wo
12724Memory is write only.
12725@item rw
6ca652b0 12726Memory is read/write. This is the default.
29e57380
C
12727@end table
12728
12729@subsubsection Memory Access Size
d3e8051b 12730The access size attribute tells @value{GDBN} to use specific sized
29e57380
C
12731accesses in the memory region. Often memory mapped device registers
12732require specific sized accesses. If no access size attribute is
12733specified, @value{GDBN} may use accesses of any size.
12734
12735@table @code
12736@item 8
12737Use 8 bit memory accesses.
12738@item 16
12739Use 16 bit memory accesses.
12740@item 32
12741Use 32 bit memory accesses.
12742@item 64
12743Use 64 bit memory accesses.
12744@end table
12745
12746@c @subsubsection Hardware/Software Breakpoints
12747@c The hardware/software breakpoint attributes set whether @value{GDBN}
12748@c will use hardware or software breakpoints for the internal breakpoints
12749@c used by the step, next, finish, until, etc. commands.
12750@c
12751@c @table @code
12752@c @item hwbreak
b383017d 12753@c Always use hardware breakpoints
29e57380
C
12754@c @item swbreak (default)
12755@c @end table
12756
12757@subsubsection Data Cache
12758The data cache attributes set whether @value{GDBN} will cache target
12759memory. While this generally improves performance by reducing debug
12760protocol overhead, it can lead to incorrect results because @value{GDBN}
12761does not know about volatile variables or memory mapped device
12762registers.
12763
12764@table @code
12765@item cache
b383017d 12766Enable @value{GDBN} to cache target memory.
6ca652b0
EZ
12767@item nocache
12768Disable @value{GDBN} from caching target memory. This is the default.
29e57380
C
12769@end table
12770
4b5752d0
VP
12771@subsection Memory Access Checking
12772@value{GDBN} can be instructed to refuse accesses to memory that is
12773not explicitly described. This can be useful if accessing such
12774regions has undesired effects for a specific target, or to provide
12775better error checking. The following commands control this behaviour.
12776
12777@table @code
12778@kindex set mem inaccessible-by-default
12779@item set mem inaccessible-by-default [on|off]
12780If @code{on} is specified, make @value{GDBN} treat memory not
12781explicitly described by the memory ranges as non-existent and refuse accesses
12782to such memory. The checks are only performed if there's at least one
12783memory range defined. If @code{off} is specified, make @value{GDBN}
12784treat the memory not explicitly described by the memory ranges as RAM.
56cf5405 12785The default value is @code{on}.
4b5752d0
VP
12786@kindex show mem inaccessible-by-default
12787@item show mem inaccessible-by-default
12788Show the current handling of accesses to unknown memory.
12789@end table
12790
12791
29e57380 12792@c @subsubsection Memory Write Verification
b383017d 12793@c The memory write verification attributes set whether @value{GDBN}
29e57380
C
12794@c will re-reads data after each write to verify the write was successful.
12795@c
12796@c @table @code
12797@c @item verify
12798@c @item noverify (default)
12799@c @end table
12800
16d9dec6 12801@node Dump/Restore Files
79a6e687 12802@section Copy Between Memory and a File
16d9dec6
MS
12803@cindex dump/restore files
12804@cindex append data to a file
12805@cindex dump data to a file
12806@cindex restore data from a file
16d9dec6 12807
df5215a6
JB
12808You can use the commands @code{dump}, @code{append}, and
12809@code{restore} to copy data between target memory and a file. The
12810@code{dump} and @code{append} commands write data to a file, and the
12811@code{restore} command reads data from a file back into the inferior's
cf75d6c3
AB
12812memory. Files may be in binary, Motorola S-record, Intel hex,
12813Tektronix Hex, or Verilog Hex format; however, @value{GDBN} can only
12814append to binary files, and cannot read from Verilog Hex files.
df5215a6
JB
12815
12816@table @code
12817
12818@kindex dump
12819@item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
12820@itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
12821Dump the contents of memory from @var{start_addr} to @var{end_addr},
12822or the value of @var{expr}, to @var{filename} in the given format.
16d9dec6 12823
df5215a6 12824The @var{format} parameter may be any one of:
16d9dec6 12825@table @code
df5215a6
JB
12826@item binary
12827Raw binary form.
12828@item ihex
12829Intel hex format.
12830@item srec
12831Motorola S-record format.
12832@item tekhex
12833Tektronix Hex format.
cf75d6c3
AB
12834@item verilog
12835Verilog Hex format.
df5215a6
JB
12836@end table
12837
12838@value{GDBN} uses the same definitions of these formats as the
12839@sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}. If
12840@var{format} is omitted, @value{GDBN} dumps the data in raw binary
12841form.
12842
12843@kindex append
12844@item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
12845@itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
12846Append the contents of memory from @var{start_addr} to @var{end_addr},
09d4efe1 12847or the value of @var{expr}, to the file @var{filename}, in raw binary form.
df5215a6
JB
12848(@value{GDBN} can only append data to files in raw binary form.)
12849
12850@kindex restore
12851@item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
12852Restore the contents of file @var{filename} into memory. The
12853@code{restore} command can automatically recognize any known @sc{bfd}
12854file format, except for raw binary. To restore a raw binary file you
12855must specify the optional keyword @code{binary} after the filename.
16d9dec6 12856
b383017d 12857If @var{bias} is non-zero, its value will be added to the addresses
16d9dec6
MS
12858contained in the file. Binary files always start at address zero, so
12859they will be restored at address @var{bias}. Other bfd files have
12860a built-in location; they will be restored at offset @var{bias}
12861from that location.
12862
12863If @var{start} and/or @var{end} are non-zero, then only data between
12864file offset @var{start} and file offset @var{end} will be restored.
b383017d 12865These offsets are relative to the addresses in the file, before
16d9dec6
MS
12866the @var{bias} argument is applied.
12867
12868@end table
12869
384ee23f
EZ
12870@node Core File Generation
12871@section How to Produce a Core File from Your Program
12872@cindex dump core from inferior
12873
12874A @dfn{core file} or @dfn{core dump} is a file that records the memory
12875image of a running process and its process status (register values
12876etc.). Its primary use is post-mortem debugging of a program that
12877crashed while it ran outside a debugger. A program that crashes
12878automatically produces a core file, unless this feature is disabled by
12879the user. @xref{Files}, for information on invoking @value{GDBN} in
12880the post-mortem debugging mode.
12881
12882Occasionally, you may wish to produce a core file of the program you
12883are debugging in order to preserve a snapshot of its state.
12884@value{GDBN} has a special command for that.
12885
12886@table @code
12887@kindex gcore
12888@kindex generate-core-file
12889@item generate-core-file [@var{file}]
12890@itemx gcore [@var{file}]
12891Produce a core dump of the inferior process. The optional argument
12892@var{file} specifies the file name where to put the core dump. If not
12893specified, the file name defaults to @file{core.@var{pid}}, where
12894@var{pid} is the inferior process ID.
12895
12896Note that this command is implemented only for some systems (as of
05b4bd79 12897this writing, @sc{gnu}/Linux, FreeBSD, Solaris, and S390).
df8411da
SDJ
12898
12899On @sc{gnu}/Linux, this command can take into account the value of the
12900file @file{/proc/@var{pid}/coredump_filter} when generating the core
1e52e849
SL
12901dump (@pxref{set use-coredump-filter}), and by default honors the
12902@code{VM_DONTDUMP} flag for mappings where it is present in the file
12903@file{/proc/@var{pid}/smaps} (@pxref{set dump-excluded-mappings}).
df8411da
SDJ
12904
12905@kindex set use-coredump-filter
12906@anchor{set use-coredump-filter}
12907@item set use-coredump-filter on
12908@itemx set use-coredump-filter off
12909Enable or disable the use of the file
12910@file{/proc/@var{pid}/coredump_filter} when generating core dump
12911files. This file is used by the Linux kernel to decide what types of
12912memory mappings will be dumped or ignored when generating a core dump
12913file. @var{pid} is the process ID of a currently running process.
12914
12915To make use of this feature, you have to write in the
12916@file{/proc/@var{pid}/coredump_filter} file a value, in hexadecimal,
12917which is a bit mask representing the memory mapping types. If a bit
12918is set in the bit mask, then the memory mappings of the corresponding
12919types will be dumped; otherwise, they will be ignored. This
12920configuration is inherited by child processes. For more information
12921about the bits that can be set in the
12922@file{/proc/@var{pid}/coredump_filter} file, please refer to the
12923manpage of @code{core(5)}.
12924
12925By default, this option is @code{on}. If this option is turned
12926@code{off}, @value{GDBN} does not read the @file{coredump_filter} file
12927and instead uses the same default value as the Linux kernel in order
12928to decide which pages will be dumped in the core dump file. This
12929value is currently @code{0x33}, which means that bits @code{0}
12930(anonymous private mappings), @code{1} (anonymous shared mappings),
12931@code{4} (ELF headers) and @code{5} (private huge pages) are active.
12932This will cause these memory mappings to be dumped automatically.
1e52e849
SL
12933
12934@kindex set dump-excluded-mappings
12935@anchor{set dump-excluded-mappings}
12936@item set dump-excluded-mappings on
12937@itemx set dump-excluded-mappings off
12938If @code{on} is specified, @value{GDBN} will dump memory mappings
12939marked with the @code{VM_DONTDUMP} flag. This flag is represented in
12940the file @file{/proc/@var{pid}/smaps} with the acronym @code{dd}.
12941
12942The default value is @code{off}.
384ee23f
EZ
12943@end table
12944
a0eb71c5
KB
12945@node Character Sets
12946@section Character Sets
12947@cindex character sets
12948@cindex charset
12949@cindex translating between character sets
12950@cindex host character set
12951@cindex target character set
12952
12953If the program you are debugging uses a different character set to
12954represent characters and strings than the one @value{GDBN} uses itself,
12955@value{GDBN} can automatically translate between the character sets for
12956you. The character set @value{GDBN} uses we call the @dfn{host
12957character set}; the one the inferior program uses we call the
12958@dfn{target character set}.
12959
12960For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
12961uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
ea35711c 12962remote protocol (@pxref{Remote Debugging}) to debug a program
a0eb71c5
KB
12963running on an IBM mainframe, which uses the @sc{ebcdic} character set,
12964then the host character set is Latin-1, and the target character set is
12965@sc{ebcdic}. If you give @value{GDBN} the command @code{set
e33d66ec 12966target-charset EBCDIC-US}, then @value{GDBN} translates between
a0eb71c5
KB
12967@sc{ebcdic} and Latin 1 as you print character or string values, or use
12968character and string literals in expressions.
12969
12970@value{GDBN} has no way to automatically recognize which character set
12971the inferior program uses; you must tell it, using the @code{set
12972target-charset} command, described below.
12973
12974Here are the commands for controlling @value{GDBN}'s character set
12975support:
12976
12977@table @code
12978@item set target-charset @var{charset}
12979@kindex set target-charset
10af6951
EZ
12980Set the current target character set to @var{charset}. To display the
12981list of supported target character sets, type
12982@kbd{@w{set target-charset @key{TAB}@key{TAB}}}.
a0eb71c5 12983
a0eb71c5
KB
12984@item set host-charset @var{charset}
12985@kindex set host-charset
12986Set the current host character set to @var{charset}.
12987
12988By default, @value{GDBN} uses a host character set appropriate to the
12989system it is running on; you can override that default using the
732f6a93
TT
12990@code{set host-charset} command. On some systems, @value{GDBN} cannot
12991automatically determine the appropriate host character set. In this
12992case, @value{GDBN} uses @samp{UTF-8}.
a0eb71c5
KB
12993
12994@value{GDBN} can only use certain character sets as its host character
c1b6b909 12995set. If you type @kbd{@w{set host-charset @key{TAB}@key{TAB}}},
10af6951 12996@value{GDBN} will list the host character sets it supports.
a0eb71c5
KB
12997
12998@item set charset @var{charset}
12999@kindex set charset
e33d66ec 13000Set the current host and target character sets to @var{charset}. As
10af6951
EZ
13001above, if you type @kbd{@w{set charset @key{TAB}@key{TAB}}},
13002@value{GDBN} will list the names of the character sets that can be used
e33d66ec
EZ
13003for both host and target.
13004
a0eb71c5 13005@item show charset
a0eb71c5 13006@kindex show charset
10af6951 13007Show the names of the current host and target character sets.
e33d66ec 13008
10af6951 13009@item show host-charset
a0eb71c5 13010@kindex show host-charset
10af6951 13011Show the name of the current host character set.
e33d66ec 13012
10af6951 13013@item show target-charset
a0eb71c5 13014@kindex show target-charset
10af6951 13015Show the name of the current target character set.
a0eb71c5 13016
10af6951
EZ
13017@item set target-wide-charset @var{charset}
13018@kindex set target-wide-charset
13019Set the current target's wide character set to @var{charset}. This is
13020the character set used by the target's @code{wchar_t} type. To
13021display the list of supported wide character sets, type
13022@kbd{@w{set target-wide-charset @key{TAB}@key{TAB}}}.
13023
13024@item show target-wide-charset
13025@kindex show target-wide-charset
13026Show the name of the current target's wide character set.
a0eb71c5
KB
13027@end table
13028
a0eb71c5
KB
13029Here is an example of @value{GDBN}'s character set support in action.
13030Assume that the following source code has been placed in the file
13031@file{charset-test.c}:
13032
13033@smallexample
13034#include <stdio.h>
13035
13036char ascii_hello[]
13037 = @{72, 101, 108, 108, 111, 44, 32, 119,
13038 111, 114, 108, 100, 33, 10, 0@};
13039char ibm1047_hello[]
13040 = @{200, 133, 147, 147, 150, 107, 64, 166,
13041 150, 153, 147, 132, 90, 37, 0@};
13042
13043main ()
13044@{
13045 printf ("Hello, world!\n");
13046@}
10998722 13047@end smallexample
a0eb71c5
KB
13048
13049In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
13050containing the string @samp{Hello, world!} followed by a newline,
13051encoded in the @sc{ascii} and @sc{ibm1047} character sets.
13052
13053We compile the program, and invoke the debugger on it:
13054
13055@smallexample
13056$ gcc -g charset-test.c -o charset-test
13057$ gdb -nw charset-test
13058GNU gdb 2001-12-19-cvs
13059Copyright 2001 Free Software Foundation, Inc.
13060@dots{}
f7dc1244 13061(@value{GDBP})
10998722 13062@end smallexample
a0eb71c5
KB
13063
13064We can use the @code{show charset} command to see what character sets
13065@value{GDBN} is currently using to interpret and display characters and
13066strings:
13067
13068@smallexample
f7dc1244 13069(@value{GDBP}) show charset
e33d66ec 13070The current host and target character set is `ISO-8859-1'.
f7dc1244 13071(@value{GDBP})
10998722 13072@end smallexample
a0eb71c5
KB
13073
13074For the sake of printing this manual, let's use @sc{ascii} as our
13075initial character set:
13076@smallexample
f7dc1244
EZ
13077(@value{GDBP}) set charset ASCII
13078(@value{GDBP}) show charset
e33d66ec 13079The current host and target character set is `ASCII'.
f7dc1244 13080(@value{GDBP})
10998722 13081@end smallexample
a0eb71c5
KB
13082
13083Let's assume that @sc{ascii} is indeed the correct character set for our
13084host system --- in other words, let's assume that if @value{GDBN} prints
13085characters using the @sc{ascii} character set, our terminal will display
13086them properly. Since our current target character set is also
13087@sc{ascii}, the contents of @code{ascii_hello} print legibly:
13088
13089@smallexample
f7dc1244 13090(@value{GDBP}) print ascii_hello
a0eb71c5 13091$1 = 0x401698 "Hello, world!\n"
f7dc1244 13092(@value{GDBP}) print ascii_hello[0]
a0eb71c5 13093$2 = 72 'H'
f7dc1244 13094(@value{GDBP})
10998722 13095@end smallexample
a0eb71c5
KB
13096
13097@value{GDBN} uses the target character set for character and string
13098literals you use in expressions:
13099
13100@smallexample
f7dc1244 13101(@value{GDBP}) print '+'
a0eb71c5 13102$3 = 43 '+'
f7dc1244 13103(@value{GDBP})
10998722 13104@end smallexample
a0eb71c5
KB
13105
13106The @sc{ascii} character set uses the number 43 to encode the @samp{+}
13107character.
13108
13109@value{GDBN} relies on the user to tell it which character set the
13110target program uses. If we print @code{ibm1047_hello} while our target
13111character set is still @sc{ascii}, we get jibberish:
13112
13113@smallexample
f7dc1244 13114(@value{GDBP}) print ibm1047_hello
a0eb71c5 13115$4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
f7dc1244 13116(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 13117$5 = 200 '\310'
f7dc1244 13118(@value{GDBP})
10998722 13119@end smallexample
a0eb71c5 13120
e33d66ec 13121If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
a0eb71c5
KB
13122@value{GDBN} tells us the character sets it supports:
13123
13124@smallexample
f7dc1244 13125(@value{GDBP}) set target-charset
b383017d 13126ASCII EBCDIC-US IBM1047 ISO-8859-1
f7dc1244 13127(@value{GDBP}) set target-charset
10998722 13128@end smallexample
a0eb71c5
KB
13129
13130We can select @sc{ibm1047} as our target character set, and examine the
13131program's strings again. Now the @sc{ascii} string is wrong, but
13132@value{GDBN} translates the contents of @code{ibm1047_hello} from the
13133target character set, @sc{ibm1047}, to the host character set,
13134@sc{ascii}, and they display correctly:
13135
13136@smallexample
f7dc1244
EZ
13137(@value{GDBP}) set target-charset IBM1047
13138(@value{GDBP}) show charset
e33d66ec
EZ
13139The current host character set is `ASCII'.
13140The current target character set is `IBM1047'.
f7dc1244 13141(@value{GDBP}) print ascii_hello
a0eb71c5 13142$6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
f7dc1244 13143(@value{GDBP}) print ascii_hello[0]
a0eb71c5 13144$7 = 72 '\110'
f7dc1244 13145(@value{GDBP}) print ibm1047_hello
a0eb71c5 13146$8 = 0x4016a8 "Hello, world!\n"
f7dc1244 13147(@value{GDBP}) print ibm1047_hello[0]
a0eb71c5 13148$9 = 200 'H'
f7dc1244 13149(@value{GDBP})
10998722 13150@end smallexample
a0eb71c5
KB
13151
13152As above, @value{GDBN} uses the target character set for character and
13153string literals you use in expressions:
13154
13155@smallexample
f7dc1244 13156(@value{GDBP}) print '+'
a0eb71c5 13157$10 = 78 '+'
f7dc1244 13158(@value{GDBP})
10998722 13159@end smallexample
a0eb71c5 13160
e33d66ec 13161The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
a0eb71c5
KB
13162character.
13163
b12039c6
YQ
13164@node Caching Target Data
13165@section Caching Data of Targets
13166@cindex caching data of targets
13167
13168@value{GDBN} caches data exchanged between the debugger and a target.
b26dfc9a 13169Each cache is associated with the address space of the inferior.
65c574f6 13170@xref{Inferiors Connections and Programs}, about inferior and address space.
b12039c6
YQ
13171Such caching generally improves performance in remote debugging
13172(@pxref{Remote Debugging}), because it reduces the overhead of the
13173remote protocol by bundling memory reads and writes into large chunks.
13174Unfortunately, simply caching everything would lead to incorrect results,
13175since @value{GDBN} does not necessarily know anything about volatile
13176values, memory-mapped I/O addresses, etc. Furthermore, in non-stop mode
13177(@pxref{Non-Stop Mode}) memory can be changed @emph{while} a gdb command
13178is executing.
29b090c0
DE
13179Therefore, by default, @value{GDBN} only caches data
13180known to be on the stack@footnote{In non-stop mode, it is moderately
13181rare for a running thread to modify the stack of a stopped thread
13182in a way that would interfere with a backtrace, and caching of
29453a14
YQ
13183stack reads provides a significant speed up of remote backtraces.} or
13184in the code segment.
29b090c0 13185Other regions of memory can be explicitly marked as
27b81af3 13186cacheable; @pxref{Memory Region Attributes}.
09d4efe1
EZ
13187
13188@table @code
13189@kindex set remotecache
13190@item set remotecache on
13191@itemx set remotecache off
4e5d721f
DE
13192This option no longer does anything; it exists for compatibility
13193with old scripts.
09d4efe1
EZ
13194
13195@kindex show remotecache
13196@item show remotecache
4e5d721f
DE
13197Show the current state of the obsolete remotecache flag.
13198
13199@kindex set stack-cache
13200@item set stack-cache on
13201@itemx set stack-cache off
6dd315ba
YQ
13202Enable or disable caching of stack accesses. When @code{on}, use
13203caching. By default, this option is @code{on}.
4e5d721f
DE
13204
13205@kindex show stack-cache
13206@item show stack-cache
13207Show the current state of data caching for memory accesses.
09d4efe1 13208
29453a14
YQ
13209@kindex set code-cache
13210@item set code-cache on
13211@itemx set code-cache off
13212Enable or disable caching of code segment accesses. When @code{on},
13213use caching. By default, this option is @code{on}. This improves
13214performance of disassembly in remote debugging.
13215
13216@kindex show code-cache
13217@item show code-cache
13218Show the current state of target memory cache for code segment
13219accesses.
13220
09d4efe1 13221@kindex info dcache
4e5d721f 13222@item info dcache @r{[}line@r{]}
b26dfc9a
YQ
13223Print the information about the performance of data cache of the
13224current inferior's address space. The information displayed
13225includes the dcache width and depth, and for each cache line, its
13226number, address, and how many times it was referenced. This
13227command is useful for debugging the data cache operation.
4e5d721f
DE
13228
13229If a line number is specified, the contents of that line will be
13230printed in hex.
1a532630
PP
13231
13232@item set dcache size @var{size}
13233@cindex dcache size
13234@kindex set dcache size
13235Set maximum number of entries in dcache (dcache depth above).
13236
13237@item set dcache line-size @var{line-size}
13238@cindex dcache line-size
13239@kindex set dcache line-size
13240Set number of bytes each dcache entry caches (dcache width above).
13241Must be a power of 2.
13242
13243@item show dcache size
13244@kindex show dcache size
b12039c6 13245Show maximum number of dcache entries. @xref{Caching Target Data, info dcache}.
1a532630
PP
13246
13247@item show dcache line-size
13248@kindex show dcache line-size
b12039c6 13249Show default size of dcache lines.
1a532630 13250
09d4efe1
EZ
13251@end table
13252
08388c79
DE
13253@node Searching Memory
13254@section Search Memory
13255@cindex searching memory
13256
13257Memory can be searched for a particular sequence of bytes with the
13258@code{find} command.
13259
13260@table @code
13261@kindex find
13262@item find @r{[}/@var{sn}@r{]} @var{start_addr}, +@var{len}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
13263@itemx find @r{[}/@var{sn}@r{]} @var{start_addr}, @var{end_addr}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
13264Search memory for the sequence of bytes specified by @var{val1}, @var{val2},
13265etc. The search begins at address @var{start_addr} and continues for either
13266@var{len} bytes or through to @var{end_addr} inclusive.
13267@end table
13268
13269@var{s} and @var{n} are optional parameters.
13270They may be specified in either order, apart or together.
13271
13272@table @r
13273@item @var{s}, search query size
13274The size of each search query value.
13275
13276@table @code
13277@item b
13278bytes
13279@item h
13280halfwords (two bytes)
13281@item w
13282words (four bytes)
13283@item g
13284giant words (eight bytes)
13285@end table
13286
13287All values are interpreted in the current language.
13288This means, for example, that if the current source language is C/C@t{++}
13289then searching for the string ``hello'' includes the trailing '\0'.
ee9a09e9
DC
13290The null terminator can be removed from searching by using casts,
13291e.g.: @samp{@{char[5]@}"hello"}.
08388c79
DE
13292
13293If the value size is not specified, it is taken from the
13294value's type in the current language.
13295This is useful when one wants to specify the search
13296pattern as a mixture of types.
13297Note that this means, for example, that in the case of C-like languages
13298a search for an untyped 0x42 will search for @samp{(int) 0x42}
13299which is typically four bytes.
13300
13301@item @var{n}, maximum number of finds
13302The maximum number of matches to print. The default is to print all finds.
13303@end table
13304
13305You can use strings as search values. Quote them with double-quotes
13306 (@code{"}).
13307The string value is copied into the search pattern byte by byte,
13308regardless of the endianness of the target and the size specification.
13309
13310The address of each match found is printed as well as a count of the
13311number of matches found.
13312
13313The address of the last value found is stored in convenience variable
13314@samp{$_}.
13315A count of the number of matches is stored in @samp{$numfound}.
13316
13317For example, if stopped at the @code{printf} in this function:
13318
13319@smallexample
13320void
13321hello ()
13322@{
13323 static char hello[] = "hello-hello";
13324 static struct @{ char c; short s; int i; @}
13325 __attribute__ ((packed)) mixed
13326 = @{ 'c', 0x1234, 0x87654321 @};
13327 printf ("%s\n", hello);
13328@}
13329@end smallexample
13330
13331@noindent
13332you get during debugging:
13333
13334@smallexample
13335(gdb) find &hello[0], +sizeof(hello), "hello"
133360x804956d <hello.1620+6>
133371 pattern found
13338(gdb) find &hello[0], +sizeof(hello), 'h', 'e', 'l', 'l', 'o'
133390x8049567 <hello.1620>
133400x804956d <hello.1620+6>
ee9a09e9
DC
133412 patterns found.
13342(gdb) find &hello[0], +sizeof(hello), @{char[5]@}"hello"
133430x8049567 <hello.1620>
133440x804956d <hello.1620+6>
133452 patterns found.
08388c79
DE
13346(gdb) find /b1 &hello[0], +sizeof(hello), 'h', 0x65, 'l'
133470x8049567 <hello.1620>
133481 pattern found
13349(gdb) find &mixed, +sizeof(mixed), (char) 'c', (short) 0x1234, (int) 0x87654321
133500x8049560 <mixed.1625>
133511 pattern found
13352(gdb) print $numfound
13353$1 = 1
13354(gdb) print $_
13355$2 = (void *) 0x8049560
13356@end smallexample
a0eb71c5 13357
5fdf6324
AB
13358@node Value Sizes
13359@section Value Sizes
13360
13361Whenever @value{GDBN} prints a value memory will be allocated within
13362@value{GDBN} to hold the contents of the value. It is possible in
13363some languages with dynamic typing systems, that an invalid program
13364may indicate a value that is incorrectly large, this in turn may cause
6b92c0d3 13365@value{GDBN} to try and allocate an overly large amount of memory.
5fdf6324
AB
13366
13367@table @code
13368@kindex set max-value-size
713cdcbf 13369@item set max-value-size @var{bytes}
5fdf6324
AB
13370@itemx set max-value-size unlimited
13371Set the maximum size of memory that @value{GDBN} will allocate for the
13372contents of a value to @var{bytes}, trying to display a value that
13373requires more memory than that will result in an error.
13374
13375Setting this variable does not effect values that have already been
13376allocated within @value{GDBN}, only future allocations.
13377
13378There's a minimum size that @code{max-value-size} can be set to in
13379order that @value{GDBN} can still operate correctly, this minimum is
13380currently 16 bytes.
13381
13382The limit applies to the results of some subexpressions as well as to
13383complete expressions. For example, an expression denoting a simple
13384integer component, such as @code{x.y.z}, may fail if the size of
13385@var{x.y} is dynamic and exceeds @var{bytes}. On the other hand,
13386@value{GDBN} is sometimes clever; the expression @code{A[i]}, where
13387@var{A} is an array variable with non-constant size, will generally
13388succeed regardless of the bounds on @var{A}, as long as the component
13389size is less than @var{bytes}.
13390
13391The default value of @code{max-value-size} is currently 64k.
13392
13393@kindex show max-value-size
13394@item show max-value-size
13395Show the maximum size of memory, in bytes, that @value{GDBN} will
13396allocate for the contents of a value.
13397@end table
13398
edb3359d
DJ
13399@node Optimized Code
13400@chapter Debugging Optimized Code
13401@cindex optimized code, debugging
13402@cindex debugging optimized code
13403
13404Almost all compilers support optimization. With optimization
13405disabled, the compiler generates assembly code that corresponds
13406directly to your source code, in a simplistic way. As the compiler
13407applies more powerful optimizations, the generated assembly code
13408diverges from your original source code. With help from debugging
13409information generated by the compiler, @value{GDBN} can map from
13410the running program back to constructs from your original source.
13411
13412@value{GDBN} is more accurate with optimization disabled. If you
13413can recompile without optimization, it is easier to follow the
13414progress of your program during debugging. But, there are many cases
13415where you may need to debug an optimized version.
13416
13417When you debug a program compiled with @samp{-g -O}, remember that the
13418optimizer has rearranged your code; the debugger shows you what is
13419really there. Do not be too surprised when the execution path does not
13420exactly match your source file! An extreme example: if you define a
13421variable, but never use it, @value{GDBN} never sees that
13422variable---because the compiler optimizes it out of existence.
13423
13424Some things do not work as well with @samp{-g -O} as with just
13425@samp{-g}, particularly on machines with instruction scheduling. If in
13426doubt, recompile with @samp{-g} alone, and if this fixes the problem,
13427please report it to us as a bug (including a test case!).
13428@xref{Variables}, for more information about debugging optimized code.
13429
13430@menu
13431* Inline Functions:: How @value{GDBN} presents inlining
111c6489 13432* Tail Call Frames:: @value{GDBN} analysis of jumps to functions
edb3359d
DJ
13433@end menu
13434
13435@node Inline Functions
13436@section Inline Functions
13437@cindex inline functions, debugging
13438
13439@dfn{Inlining} is an optimization that inserts a copy of the function
13440body directly at each call site, instead of jumping to a shared
13441routine. @value{GDBN} displays inlined functions just like
13442non-inlined functions. They appear in backtraces. You can view their
13443arguments and local variables, step into them with @code{step}, skip
13444them with @code{next}, and escape from them with @code{finish}.
13445You can check whether a function was inlined by using the
13446@code{info frame} command.
13447
13448For @value{GDBN} to support inlined functions, the compiler must
13449record information about inlining in the debug information ---
13450@value{NGCC} using the @sc{dwarf 2} format does this, and several
13451other compilers do also. @value{GDBN} only supports inlined functions
13452when using @sc{dwarf 2}. Versions of @value{NGCC} before 4.1
13453do not emit two required attributes (@samp{DW_AT_call_file} and
13454@samp{DW_AT_call_line}); @value{GDBN} does not display inlined
13455function calls with earlier versions of @value{NGCC}. It instead
13456displays the arguments and local variables of inlined functions as
13457local variables in the caller.
13458
13459The body of an inlined function is directly included at its call site;
13460unlike a non-inlined function, there are no instructions devoted to
13461the call. @value{GDBN} still pretends that the call site and the
13462start of the inlined function are different instructions. Stepping to
13463the call site shows the call site, and then stepping again shows
13464the first line of the inlined function, even though no additional
13465instructions are executed.
13466
13467This makes source-level debugging much clearer; you can see both the
13468context of the call and then the effect of the call. Only stepping by
13469a single instruction using @code{stepi} or @code{nexti} does not do
13470this; single instruction steps always show the inlined body.
13471
13472There are some ways that @value{GDBN} does not pretend that inlined
13473function calls are the same as normal calls:
13474
13475@itemize @bullet
edb3359d
DJ
13476@item
13477Setting breakpoints at the call site of an inlined function may not
13478work, because the call site does not contain any code. @value{GDBN}
13479may incorrectly move the breakpoint to the next line of the enclosing
13480function, after the call. This limitation will be removed in a future
13481version of @value{GDBN}; until then, set a breakpoint on an earlier line
13482or inside the inlined function instead.
13483
13484@item
13485@value{GDBN} cannot locate the return value of inlined calls after
13486using the @code{finish} command. This is a limitation of compiler-generated
13487debugging information; after @code{finish}, you can step to the next line
13488and print a variable where your program stored the return value.
13489
13490@end itemize
13491
111c6489
JK
13492@node Tail Call Frames
13493@section Tail Call Frames
13494@cindex tail call frames, debugging
13495
13496Function @code{B} can call function @code{C} in its very last statement. In
13497unoptimized compilation the call of @code{C} is immediately followed by return
13498instruction at the end of @code{B} code. Optimizing compiler may replace the
13499call and return in function @code{B} into one jump to function @code{C}
13500instead. Such use of a jump instruction is called @dfn{tail call}.
13501
13502During execution of function @code{C}, there will be no indication in the
13503function call stack frames that it was tail-called from @code{B}. If function
13504@code{A} regularly calls function @code{B} which tail-calls function @code{C},
13505then @value{GDBN} will see @code{A} as the caller of @code{C}. However, in
13506some cases @value{GDBN} can determine that @code{C} was tail-called from
13507@code{B}, and it will then create fictitious call frame for that, with the
13508return address set up as if @code{B} called @code{C} normally.
13509
13510This functionality is currently supported only by DWARF 2 debugging format and
216f72a1 13511the compiler has to produce @samp{DW_TAG_call_site} tags. With
111c6489
JK
13512@value{NGCC}, you need to specify @option{-O -g} during compilation, to get
13513this information.
13514
13515@kbd{info frame} command (@pxref{Frame Info}) will indicate the tail call frame
13516kind by text @code{tail call frame} such as in this sample @value{GDBN} output:
13517
13518@smallexample
13519(gdb) x/i $pc - 2
13520 0x40066b <b(int, double)+11>: jmp 0x400640 <c(int, double)>
13521(gdb) info frame
13522Stack level 1, frame at 0x7fffffffda30:
13523 rip = 0x40066d in b (amd64-entry-value.cc:59); saved rip 0x4004c5
13524 tail call frame, caller of frame at 0x7fffffffda30
13525 source language c++.
13526 Arglist at unknown address.
13527 Locals at unknown address, Previous frame's sp is 0x7fffffffda30
13528@end smallexample
13529
13530The detection of all the possible code path executions can find them ambiguous.
13531There is no execution history stored (possible @ref{Reverse Execution} is never
13532used for this purpose) and the last known caller could have reached the known
13533callee by multiple different jump sequences. In such case @value{GDBN} still
13534tries to show at least all the unambiguous top tail callers and all the
13535unambiguous bottom tail calees, if any.
13536
13537@table @code
e18b2753 13538@anchor{set debug entry-values}
111c6489
JK
13539@item set debug entry-values
13540@kindex set debug entry-values
13541When set to on, enables printing of analysis messages for both frame argument
13542values at function entry and tail calls. It will show all the possible valid
13543tail calls code paths it has considered. It will also print the intersection
13544of them with the final unambiguous (possibly partial or even empty) code path
13545result.
13546
13547@item show debug entry-values
13548@kindex show debug entry-values
13549Show the current state of analysis messages printing for both frame argument
13550values at function entry and tail calls.
13551@end table
13552
13553The analysis messages for tail calls can for example show why the virtual tail
13554call frame for function @code{c} has not been recognized (due to the indirect
13555reference by variable @code{x}):
13556
13557@smallexample
13558static void __attribute__((noinline, noclone)) c (void);
13559void (*x) (void) = c;
13560static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
13561static void __attribute__((noinline, noclone)) c (void) @{ a (); @}
13562int main (void) @{ x (); return 0; @}
13563
216f72a1
JK
13564Breakpoint 1, DW_OP_entry_value resolving cannot find
13565DW_TAG_call_site 0x40039a in main
111c6489
JK
13566a () at t.c:3
135673 static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
13568(gdb) bt
13569#0 a () at t.c:3
13570#1 0x000000000040039a in main () at t.c:5
13571@end smallexample
13572
13573Another possibility is an ambiguous virtual tail call frames resolution:
13574
13575@smallexample
13576int i;
13577static void __attribute__((noinline, noclone)) f (void) @{ i++; @}
13578static void __attribute__((noinline, noclone)) e (void) @{ f (); @}
13579static void __attribute__((noinline, noclone)) d (void) @{ f (); @}
13580static void __attribute__((noinline, noclone)) c (void) @{ d (); @}
13581static void __attribute__((noinline, noclone)) b (void)
13582@{ if (i) c (); else e (); @}
13583static void __attribute__((noinline, noclone)) a (void) @{ b (); @}
13584int main (void) @{ a (); return 0; @}
13585
13586tailcall: initial: 0x4004d2(a) 0x4004ce(b) 0x4004b2(c) 0x4004a2(d)
13587tailcall: compare: 0x4004d2(a) 0x4004cc(b) 0x400492(e)
13588tailcall: reduced: 0x4004d2(a) |
13589(gdb) bt
13590#0 f () at t.c:2
13591#1 0x00000000004004d2 in a () at t.c:8
13592#2 0x0000000000400395 in main () at t.c:9
13593@end smallexample
13594
5048e516
JK
13595@set CALLSEQ1A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}c@value{ARROW}d@value{ARROW}f}
13596@set CALLSEQ2A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}e@value{ARROW}f}
13597
13598@c Convert CALLSEQ#A to CALLSEQ#B depending on HAVE_MAKEINFO_CLICK.
13599@ifset HAVE_MAKEINFO_CLICK
13600@set ARROW @click{}
13601@set CALLSEQ1B @clicksequence{@value{CALLSEQ1A}}
13602@set CALLSEQ2B @clicksequence{@value{CALLSEQ2A}}
13603@end ifset
13604@ifclear HAVE_MAKEINFO_CLICK
13605@set ARROW ->
13606@set CALLSEQ1B @value{CALLSEQ1A}
13607@set CALLSEQ2B @value{CALLSEQ2A}
13608@end ifclear
13609
13610Frames #0 and #2 are real, #1 is a virtual tail call frame.
13611The code can have possible execution paths @value{CALLSEQ1B} or
13612@value{CALLSEQ2B}, @value{GDBN} cannot find which one from the inferior state.
111c6489
JK
13613
13614@code{initial:} state shows some random possible calling sequence @value{GDBN}
6b92c0d3 13615has found. It then finds another possible calling sequence - that one is
111c6489
JK
13616prefixed by @code{compare:}. The non-ambiguous intersection of these two is
13617printed as the @code{reduced:} calling sequence. That one could have many
6b92c0d3 13618further @code{compare:} and @code{reduced:} statements as long as there remain
111c6489
JK
13619any non-ambiguous sequence entries.
13620
13621For the frame of function @code{b} in both cases there are different possible
13622@code{$pc} values (@code{0x4004cc} or @code{0x4004ce}), therefore this frame is
6b92c0d3 13623also ambiguous. The only non-ambiguous frame is the one for function @code{a},
111c6489
JK
13624therefore this one is displayed to the user while the ambiguous frames are
13625omitted.
edb3359d 13626
e18b2753
JK
13627There can be also reasons why printing of frame argument values at function
13628entry may fail:
13629
13630@smallexample
13631int v;
13632static void __attribute__((noinline, noclone)) c (int i) @{ v++; @}
13633static void __attribute__((noinline, noclone)) a (int i);
13634static void __attribute__((noinline, noclone)) b (int i) @{ a (i); @}
13635static void __attribute__((noinline, noclone)) a (int i)
13636@{ if (i) b (i - 1); else c (0); @}
13637int main (void) @{ a (5); return 0; @}
13638
13639(gdb) bt
13640#0 c (i=i@@entry=0) at t.c:2
216f72a1 13641#1 0x0000000000400428 in a (DW_OP_entry_value resolving has found
e18b2753
JK
13642function "a" at 0x400420 can call itself via tail calls
13643i=<optimized out>) at t.c:6
13644#2 0x000000000040036e in main () at t.c:7
13645@end smallexample
13646
13647@value{GDBN} cannot find out from the inferior state if and how many times did
13648function @code{a} call itself (via function @code{b}) as these calls would be
6b92c0d3 13649tail calls. Such tail calls would modify the @code{i} variable, therefore
e18b2753
JK
13650@value{GDBN} cannot be sure the value it knows would be right - @value{GDBN}
13651prints @code{<optimized out>} instead.
13652
e2e0bcd1
JB
13653@node Macros
13654@chapter C Preprocessor Macros
13655
49efadf5 13656Some languages, such as C and C@t{++}, provide a way to define and invoke
e2e0bcd1
JB
13657``preprocessor macros'' which expand into strings of tokens.
13658@value{GDBN} can evaluate expressions containing macro invocations, show
13659the result of macro expansion, and show a macro's definition, including
13660where it was defined.
13661
13662You may need to compile your program specially to provide @value{GDBN}
13663with information about preprocessor macros. Most compilers do not
13664include macros in their debugging information, even when you compile
13665with the @option{-g} flag. @xref{Compilation}.
13666
13667A program may define a macro at one point, remove that definition later,
13668and then provide a different definition after that. Thus, at different
13669points in the program, a macro may have different definitions, or have
13670no definition at all. If there is a current stack frame, @value{GDBN}
13671uses the macros in scope at that frame's source code line. Otherwise,
13672@value{GDBN} uses the macros in scope at the current listing location;
13673see @ref{List}.
13674
e2e0bcd1
JB
13675Whenever @value{GDBN} evaluates an expression, it always expands any
13676macro invocations present in the expression. @value{GDBN} also provides
13677the following commands for working with macros explicitly.
13678
13679@table @code
13680
13681@kindex macro expand
13682@cindex macro expansion, showing the results of preprocessor
13683@cindex preprocessor macro expansion, showing the results of
13684@cindex expanding preprocessor macros
13685@item macro expand @var{expression}
13686@itemx macro exp @var{expression}
13687Show the results of expanding all preprocessor macro invocations in
13688@var{expression}. Since @value{GDBN} simply expands macros, but does
13689not parse the result, @var{expression} need not be a valid expression;
13690it can be any string of tokens.
13691
09d4efe1 13692@kindex macro exp1
e2e0bcd1
JB
13693@item macro expand-once @var{expression}
13694@itemx macro exp1 @var{expression}
4644b6e3 13695@cindex expand macro once
e2e0bcd1
JB
13696@i{(This command is not yet implemented.)} Show the results of
13697expanding those preprocessor macro invocations that appear explicitly in
13698@var{expression}. Macro invocations appearing in that expansion are
13699left unchanged. This command allows you to see the effect of a
13700particular macro more clearly, without being confused by further
13701expansions. Since @value{GDBN} simply expands macros, but does not
13702parse the result, @var{expression} need not be a valid expression; it
13703can be any string of tokens.
13704
475b0867 13705@kindex info macro
e2e0bcd1 13706@cindex macro definition, showing
9b158ba0 13707@cindex definition of a macro, showing
13708@cindex macros, from debug info
71eba9c2 13709@item info macro [-a|-all] [--] @var{macro}
13710Show the current definition or all definitions of the named @var{macro},
13711and describe the source location or compiler command-line where that
13712definition was established. The optional double dash is to signify the end of
13713argument processing and the beginning of @var{macro} for non C-like macros where
13714the macro may begin with a hyphen.
e2e0bcd1 13715
9b158ba0 13716@kindex info macros
629500fa 13717@item info macros @var{location}
9b158ba0 13718Show all macro definitions that are in effect at the location specified
629500fa 13719by @var{location}, and describe the source location or compiler
9b158ba0 13720command-line where those definitions were established.
13721
e2e0bcd1
JB
13722@kindex macro define
13723@cindex user-defined macros
13724@cindex defining macros interactively
13725@cindex macros, user-defined
13726@item macro define @var{macro} @var{replacement-list}
13727@itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
d7d9f01e
TT
13728Introduce a definition for a preprocessor macro named @var{macro},
13729invocations of which are replaced by the tokens given in
13730@var{replacement-list}. The first form of this command defines an
13731``object-like'' macro, which takes no arguments; the second form
13732defines a ``function-like'' macro, which takes the arguments given in
13733@var{arglist}.
13734
13735A definition introduced by this command is in scope in every
13736expression evaluated in @value{GDBN}, until it is removed with the
13737@code{macro undef} command, described below. The definition overrides
13738all definitions for @var{macro} present in the program being debugged,
13739as well as any previous user-supplied definition.
e2e0bcd1
JB
13740
13741@kindex macro undef
13742@item macro undef @var{macro}
d7d9f01e
TT
13743Remove any user-supplied definition for the macro named @var{macro}.
13744This command only affects definitions provided with the @code{macro
13745define} command, described above; it cannot remove definitions present
13746in the program being debugged.
e2e0bcd1 13747
09d4efe1
EZ
13748@kindex macro list
13749@item macro list
d7d9f01e 13750List all the macros defined using the @code{macro define} command.
e2e0bcd1
JB
13751@end table
13752
13753@cindex macros, example of debugging with
13754Here is a transcript showing the above commands in action. First, we
13755show our source files:
13756
13757@smallexample
13758$ cat sample.c
13759#include <stdio.h>
13760#include "sample.h"
13761
13762#define M 42
13763#define ADD(x) (M + x)
13764
13765main ()
13766@{
13767#define N 28
13768 printf ("Hello, world!\n");
13769#undef N
13770 printf ("We're so creative.\n");
13771#define N 1729
13772 printf ("Goodbye, world!\n");
13773@}
13774$ cat sample.h
13775#define Q <
13776$
13777@end smallexample
13778
e0f8f636
TT
13779Now, we compile the program using the @sc{gnu} C compiler,
13780@value{NGCC}. We pass the @option{-gdwarf-2}@footnote{This is the
13781minimum. Recent versions of @value{NGCC} support @option{-gdwarf-3}
13782and @option{-gdwarf-4}; we recommend always choosing the most recent
13783version of DWARF.} @emph{and} @option{-g3} flags to ensure the compiler
13784includes information about preprocessor macros in the debugging
e2e0bcd1
JB
13785information.
13786
13787@smallexample
13788$ gcc -gdwarf-2 -g3 sample.c -o sample
13789$
13790@end smallexample
13791
13792Now, we start @value{GDBN} on our sample program:
13793
13794@smallexample
13795$ gdb -nw sample
13796GNU gdb 2002-05-06-cvs
13797Copyright 2002 Free Software Foundation, Inc.
13798GDB is free software, @dots{}
f7dc1244 13799(@value{GDBP})
e2e0bcd1
JB
13800@end smallexample
13801
13802We can expand macros and examine their definitions, even when the
13803program is not running. @value{GDBN} uses the current listing position
13804to decide which macro definitions are in scope:
13805
13806@smallexample
f7dc1244 13807(@value{GDBP}) list main
e2e0bcd1
JB
138083
138094 #define M 42
138105 #define ADD(x) (M + x)
138116
138127 main ()
138138 @{
138149 #define N 28
1381510 printf ("Hello, world!\n");
1381611 #undef N
1381712 printf ("We're so creative.\n");
f7dc1244 13818(@value{GDBP}) info macro ADD
e2e0bcd1
JB
13819Defined at /home/jimb/gdb/macros/play/sample.c:5
13820#define ADD(x) (M + x)
f7dc1244 13821(@value{GDBP}) info macro Q
e2e0bcd1
JB
13822Defined at /home/jimb/gdb/macros/play/sample.h:1
13823 included at /home/jimb/gdb/macros/play/sample.c:2
13824#define Q <
f7dc1244 13825(@value{GDBP}) macro expand ADD(1)
e2e0bcd1 13826expands to: (42 + 1)
f7dc1244 13827(@value{GDBP}) macro expand-once ADD(1)
e2e0bcd1 13828expands to: once (M + 1)
f7dc1244 13829(@value{GDBP})
e2e0bcd1
JB
13830@end smallexample
13831
d7d9f01e 13832In the example above, note that @code{macro expand-once} expands only
e2e0bcd1
JB
13833the macro invocation explicit in the original text --- the invocation of
13834@code{ADD} --- but does not expand the invocation of the macro @code{M},
13835which was introduced by @code{ADD}.
13836
3f94c067
BW
13837Once the program is running, @value{GDBN} uses the macro definitions in
13838force at the source line of the current stack frame:
e2e0bcd1
JB
13839
13840@smallexample
f7dc1244 13841(@value{GDBP}) break main
e2e0bcd1 13842Breakpoint 1 at 0x8048370: file sample.c, line 10.
f7dc1244 13843(@value{GDBP}) run
b383017d 13844Starting program: /home/jimb/gdb/macros/play/sample
e2e0bcd1
JB
13845
13846Breakpoint 1, main () at sample.c:10
1384710 printf ("Hello, world!\n");
f7dc1244 13848(@value{GDBP})
e2e0bcd1
JB
13849@end smallexample
13850
13851At line 10, the definition of the macro @code{N} at line 9 is in force:
13852
13853@smallexample
f7dc1244 13854(@value{GDBP}) info macro N
e2e0bcd1
JB
13855Defined at /home/jimb/gdb/macros/play/sample.c:9
13856#define N 28
f7dc1244 13857(@value{GDBP}) macro expand N Q M
e2e0bcd1 13858expands to: 28 < 42
f7dc1244 13859(@value{GDBP}) print N Q M
e2e0bcd1 13860$1 = 1
f7dc1244 13861(@value{GDBP})
e2e0bcd1
JB
13862@end smallexample
13863
13864As we step over directives that remove @code{N}'s definition, and then
13865give it a new definition, @value{GDBN} finds the definition (or lack
13866thereof) in force at each point:
13867
13868@smallexample
f7dc1244 13869(@value{GDBP}) next
e2e0bcd1
JB
13870Hello, world!
1387112 printf ("We're so creative.\n");
f7dc1244 13872(@value{GDBP}) info macro N
e2e0bcd1
JB
13873The symbol `N' has no definition as a C/C++ preprocessor macro
13874at /home/jimb/gdb/macros/play/sample.c:12
f7dc1244 13875(@value{GDBP}) next
e2e0bcd1
JB
13876We're so creative.
1387714 printf ("Goodbye, world!\n");
f7dc1244 13878(@value{GDBP}) info macro N
e2e0bcd1
JB
13879Defined at /home/jimb/gdb/macros/play/sample.c:13
13880#define N 1729
f7dc1244 13881(@value{GDBP}) macro expand N Q M
e2e0bcd1 13882expands to: 1729 < 42
f7dc1244 13883(@value{GDBP}) print N Q M
e2e0bcd1 13884$2 = 0
f7dc1244 13885(@value{GDBP})
e2e0bcd1
JB
13886@end smallexample
13887
484086b7
JK
13888In addition to source files, macros can be defined on the compilation command
13889line using the @option{-D@var{name}=@var{value}} syntax. For macros defined in
13890such a way, @value{GDBN} displays the location of their definition as line zero
13891of the source file submitted to the compiler.
13892
13893@smallexample
13894(@value{GDBP}) info macro __STDC__
13895Defined at /home/jimb/gdb/macros/play/sample.c:0
13896-D__STDC__=1
13897(@value{GDBP})
13898@end smallexample
13899
e2e0bcd1 13900
b37052ae
EZ
13901@node Tracepoints
13902@chapter Tracepoints
13903@c This chapter is based on the documentation written by Michael
13904@c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
13905
13906@cindex tracepoints
13907In some applications, it is not feasible for the debugger to interrupt
13908the program's execution long enough for the developer to learn
13909anything helpful about its behavior. If the program's correctness
13910depends on its real-time behavior, delays introduced by a debugger
13911might cause the program to change its behavior drastically, or perhaps
13912fail, even when the code itself is correct. It is useful to be able
13913to observe the program's behavior without interrupting it.
13914
13915Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
13916specify locations in the program, called @dfn{tracepoints}, and
13917arbitrary expressions to evaluate when those tracepoints are reached.
13918Later, using the @code{tfind} command, you can examine the values
13919those expressions had when the program hit the tracepoints. The
13920expressions may also denote objects in memory---structures or arrays,
13921for example---whose values @value{GDBN} should record; while visiting
13922a particular tracepoint, you may inspect those objects as if they were
13923in memory at that moment. However, because @value{GDBN} records these
13924values without interacting with you, it can do so quickly and
13925unobtrusively, hopefully not disturbing the program's behavior.
13926
13927The tracepoint facility is currently available only for remote
9d29849a
JB
13928targets. @xref{Targets}. In addition, your remote target must know
13929how to collect trace data. This functionality is implemented in the
13930remote stub; however, none of the stubs distributed with @value{GDBN}
13931support tracepoints as of this writing. The format of the remote
13932packets used to implement tracepoints are described in @ref{Tracepoint
13933Packets}.
b37052ae 13934
00bf0b85
SS
13935It is also possible to get trace data from a file, in a manner reminiscent
13936of corefiles; you specify the filename, and use @code{tfind} to search
13937through the file. @xref{Trace Files}, for more details.
13938
b37052ae
EZ
13939This chapter describes the tracepoint commands and features.
13940
13941@menu
b383017d
RM
13942* Set Tracepoints::
13943* Analyze Collected Data::
13944* Tracepoint Variables::
00bf0b85 13945* Trace Files::
b37052ae
EZ
13946@end menu
13947
13948@node Set Tracepoints
13949@section Commands to Set Tracepoints
13950
13951Before running such a @dfn{trace experiment}, an arbitrary number of
1042e4c0
SS
13952tracepoints can be set. A tracepoint is actually a special type of
13953breakpoint (@pxref{Set Breaks}), so you can manipulate it using
13954standard breakpoint commands. For instance, as with breakpoints,
13955tracepoint numbers are successive integers starting from one, and many
13956of the commands associated with tracepoints take the tracepoint number
13957as their argument, to identify which tracepoint to work on.
b37052ae
EZ
13958
13959For each tracepoint, you can specify, in advance, some arbitrary set
13960of data that you want the target to collect in the trace buffer when
13961it hits that tracepoint. The collected data can include registers,
13962local variables, or global data. Later, you can use @value{GDBN}
13963commands to examine the values these data had at the time the
13964tracepoint was hit.
13965
7d13fe92
SS
13966Tracepoints do not support every breakpoint feature. Ignore counts on
13967tracepoints have no effect, and tracepoints cannot run @value{GDBN}
13968commands when they are hit. Tracepoints may not be thread-specific
13969either.
1042e4c0 13970
7a697b8d
SS
13971@cindex fast tracepoints
13972Some targets may support @dfn{fast tracepoints}, which are inserted in
13973a different way (such as with a jump instead of a trap), that is
13974faster but possibly restricted in where they may be installed.
13975
0fb4aa4b
PA
13976@cindex static tracepoints
13977@cindex markers, static tracepoints
13978@cindex probing markers, static tracepoints
13979Regular and fast tracepoints are dynamic tracing facilities, meaning
13980that they can be used to insert tracepoints at (almost) any location
13981in the target. Some targets may also support controlling @dfn{static
13982tracepoints} from @value{GDBN}. With static tracing, a set of
13983instrumentation points, also known as @dfn{markers}, are embedded in
13984the target program, and can be activated or deactivated by name or
13985address. These are usually placed at locations which facilitate
13986investigating what the target is actually doing. @value{GDBN}'s
13987support for static tracing includes being able to list instrumentation
13988points, and attach them with @value{GDBN} defined high level
13989tracepoints that expose the whole range of convenience of
8786b2bd 13990@value{GDBN}'s tracepoints support. Namely, support for collecting
0fb4aa4b
PA
13991registers values and values of global or local (to the instrumentation
13992point) variables; tracepoint conditions and trace state variables.
13993The act of installing a @value{GDBN} static tracepoint on an
13994instrumentation point, or marker, is referred to as @dfn{probing} a
13995static tracepoint marker.
13996
fa593d66
PA
13997@code{gdbserver} supports tracepoints on some target systems.
13998@xref{Server,,Tracepoints support in @code{gdbserver}}.
13999
b37052ae
EZ
14000This section describes commands to set tracepoints and associated
14001conditions and actions.
14002
14003@menu
b383017d
RM
14004* Create and Delete Tracepoints::
14005* Enable and Disable Tracepoints::
14006* Tracepoint Passcounts::
782b2b07 14007* Tracepoint Conditions::
f61e138d 14008* Trace State Variables::
b383017d
RM
14009* Tracepoint Actions::
14010* Listing Tracepoints::
0fb4aa4b 14011* Listing Static Tracepoint Markers::
79a6e687 14012* Starting and Stopping Trace Experiments::
c9429232 14013* Tracepoint Restrictions::
b37052ae
EZ
14014@end menu
14015
14016@node Create and Delete Tracepoints
14017@subsection Create and Delete Tracepoints
14018
14019@table @code
14020@cindex set tracepoint
14021@kindex trace
1042e4c0 14022@item trace @var{location}
b37052ae 14023The @code{trace} command is very similar to the @code{break} command.
629500fa
KS
14024Its argument @var{location} can be any valid location.
14025@xref{Specify Location}. The @code{trace} command defines a tracepoint,
14026which is a point in the target program where the debugger will briefly stop,
14027collect some data, and then allow the program to continue. Setting a tracepoint
14028or changing its actions takes effect immediately if the remote stub
1e4d1764
YQ
14029supports the @samp{InstallInTrace} feature (@pxref{install tracepoint
14030in tracing}).
14031If remote stub doesn't support the @samp{InstallInTrace} feature, all
14032these changes don't take effect until the next @code{tstart}
1042e4c0 14033command, and once a trace experiment is running, further changes will
bfccc43c
YQ
14034not have any effect until the next trace experiment starts. In addition,
14035@value{GDBN} supports @dfn{pending tracepoints}---tracepoints whose
14036address is not yet resolved. (This is similar to pending breakpoints.)
14037Pending tracepoints are not downloaded to the target and not installed
14038until they are resolved. The resolution of pending tracepoints requires
14039@value{GDBN} support---when debugging with the remote target, and
14040@value{GDBN} disconnects from the remote stub (@pxref{disconnected
14041tracing}), pending tracepoints can not be resolved (and downloaded to
14042the remote stub) while @value{GDBN} is disconnected.
b37052ae
EZ
14043
14044Here are some examples of using the @code{trace} command:
14045
14046@smallexample
14047(@value{GDBP}) @b{trace foo.c:121} // a source file and line number
14048
14049(@value{GDBP}) @b{trace +2} // 2 lines forward
14050
14051(@value{GDBP}) @b{trace my_function} // first source line of function
14052
14053(@value{GDBP}) @b{trace *my_function} // EXACT start address of function
14054
14055(@value{GDBP}) @b{trace *0x2117c4} // an address
14056@end smallexample
14057
14058@noindent
14059You can abbreviate @code{trace} as @code{tr}.
14060
782b2b07
SS
14061@item trace @var{location} if @var{cond}
14062Set a tracepoint with condition @var{cond}; evaluate the expression
14063@var{cond} each time the tracepoint is reached, and collect data only
14064if the value is nonzero---that is, if @var{cond} evaluates as true.
14065@xref{Tracepoint Conditions, ,Tracepoint Conditions}, for more
14066information on tracepoint conditions.
14067
7a697b8d
SS
14068@item ftrace @var{location} [ if @var{cond} ]
14069@cindex set fast tracepoint
74c761c1 14070@cindex fast tracepoints, setting
7a697b8d
SS
14071@kindex ftrace
14072The @code{ftrace} command sets a fast tracepoint. For targets that
14073support them, fast tracepoints will use a more efficient but possibly
14074less general technique to trigger data collection, such as a jump
14075instruction instead of a trap, or some sort of hardware support. It
14076may not be possible to create a fast tracepoint at the desired
14077location, in which case the command will exit with an explanatory
14078message.
14079
14080@value{GDBN} handles arguments to @code{ftrace} exactly as for
14081@code{trace}.
14082
405f8e94
SS
14083On 32-bit x86-architecture systems, fast tracepoints normally need to
14084be placed at an instruction that is 5 bytes or longer, but can be
14085placed at 4-byte instructions if the low 64K of memory of the target
14086program is available to install trampolines. Some Unix-type systems,
14087such as @sc{gnu}/Linux, exclude low addresses from the program's
14088address space; but for instance with the Linux kernel it is possible
14089to let @value{GDBN} use this area by doing a @command{sysctl} command
14090to set the @code{mmap_min_addr} kernel parameter, as in
14091
14092@example
14093sudo sysctl -w vm.mmap_min_addr=32768
14094@end example
14095
14096@noindent
14097which sets the low address to 32K, which leaves plenty of room for
14098trampolines. The minimum address should be set to a page boundary.
14099
0fb4aa4b 14100@item strace @var{location} [ if @var{cond} ]
74c761c1
PA
14101@cindex set static tracepoint
14102@cindex static tracepoints, setting
14103@cindex probe static tracepoint marker
0fb4aa4b
PA
14104@kindex strace
14105The @code{strace} command sets a static tracepoint. For targets that
14106support it, setting a static tracepoint probes a static
14107instrumentation point, or marker, found at @var{location}. It may not
14108be possible to set a static tracepoint at the desired location, in
14109which case the command will exit with an explanatory message.
14110
14111@value{GDBN} handles arguments to @code{strace} exactly as for
14112@code{trace}, with the addition that the user can also specify
14113@code{-m @var{marker}} as @var{location}. This probes the marker
14114identified by the @var{marker} string identifier. This identifier
14115depends on the static tracepoint backend library your program is
14116using. You can find all the marker identifiers in the @samp{ID} field
14117of the @code{info static-tracepoint-markers} command output.
14118@xref{Listing Static Tracepoint Markers,,Listing Static Tracepoint
14119Markers}. For example, in the following small program using the UST
14120tracing engine:
14121
14122@smallexample
14123main ()
14124@{
14125 trace_mark(ust, bar33, "str %s", "FOOBAZ");
14126@}
14127@end smallexample
14128
14129@noindent
14130the marker id is composed of joining the first two arguments to the
14131@code{trace_mark} call with a slash, which translates to:
14132
14133@smallexample
14134(@value{GDBP}) info static-tracepoint-markers
14135Cnt Enb ID Address What
141361 n ust/bar33 0x0000000000400ddc in main at stexample.c:22
14137 Data: "str %s"
14138[etc...]
14139@end smallexample
14140
14141@noindent
14142so you may probe the marker above with:
14143
14144@smallexample
14145(@value{GDBP}) strace -m ust/bar33
14146@end smallexample
14147
14148Static tracepoints accept an extra collect action --- @code{collect
14149$_sdata}. This collects arbitrary user data passed in the probe point
14150call to the tracing library. In the UST example above, you'll see
14151that the third argument to @code{trace_mark} is a printf-like format
6b92c0d3 14152string. The user data is then the result of running that formatting
0fb4aa4b
PA
14153string against the following arguments. Note that @code{info
14154static-tracepoint-markers} command output lists that format string in
14155the @samp{Data:} field.
14156
14157You can inspect this data when analyzing the trace buffer, by printing
14158the $_sdata variable like any other variable available to
14159@value{GDBN}. @xref{Tracepoint Actions,,Tracepoint Action Lists}.
14160
b37052ae
EZ
14161@vindex $tpnum
14162@cindex last tracepoint number
14163@cindex recent tracepoint number
14164@cindex tracepoint number
14165The convenience variable @code{$tpnum} records the tracepoint number
14166of the most recently set tracepoint.
14167
14168@kindex delete tracepoint
14169@cindex tracepoint deletion
14170@item delete tracepoint @r{[}@var{num}@r{]}
14171Permanently delete one or more tracepoints. With no argument, the
1042e4c0
SS
14172default is to delete all tracepoints. Note that the regular
14173@code{delete} command can remove tracepoints also.
b37052ae
EZ
14174
14175Examples:
14176
14177@smallexample
14178(@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
14179
14180(@value{GDBP}) @b{delete trace} // remove all tracepoints
14181@end smallexample
14182
14183@noindent
14184You can abbreviate this command as @code{del tr}.
14185@end table
14186
14187@node Enable and Disable Tracepoints
14188@subsection Enable and Disable Tracepoints
14189
1042e4c0
SS
14190These commands are deprecated; they are equivalent to plain @code{disable} and @code{enable}.
14191
b37052ae
EZ
14192@table @code
14193@kindex disable tracepoint
14194@item disable tracepoint @r{[}@var{num}@r{]}
14195Disable tracepoint @var{num}, or all tracepoints if no argument
14196@var{num} is given. A disabled tracepoint will have no effect during
d248b706 14197a trace experiment, but it is not forgotten. You can re-enable
b37052ae 14198a disabled tracepoint using the @code{enable tracepoint} command.
d248b706
KY
14199If the command is issued during a trace experiment and the debug target
14200has support for disabling tracepoints during a trace experiment, then the
14201change will be effective immediately. Otherwise, it will be applied to the
14202next trace experiment.
b37052ae
EZ
14203
14204@kindex enable tracepoint
14205@item enable tracepoint @r{[}@var{num}@r{]}
d248b706
KY
14206Enable tracepoint @var{num}, or all tracepoints. If this command is
14207issued during a trace experiment and the debug target supports enabling
14208tracepoints during a trace experiment, then the enabled tracepoints will
14209become effective immediately. Otherwise, they will become effective the
14210next time a trace experiment is run.
b37052ae
EZ
14211@end table
14212
14213@node Tracepoint Passcounts
14214@subsection Tracepoint Passcounts
14215
14216@table @code
14217@kindex passcount
14218@cindex tracepoint pass count
14219@item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
14220Set the @dfn{passcount} of a tracepoint. The passcount is a way to
14221automatically stop a trace experiment. If a tracepoint's passcount is
14222@var{n}, then the trace experiment will be automatically stopped on
14223the @var{n}'th time that tracepoint is hit. If the tracepoint number
14224@var{num} is not specified, the @code{passcount} command sets the
14225passcount of the most recently defined tracepoint. If no passcount is
14226given, the trace experiment will run until stopped explicitly by the
14227user.
14228
14229Examples:
14230
14231@smallexample
b383017d 14232(@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
6826cf00 14233@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
b37052ae
EZ
14234
14235(@value{GDBP}) @b{passcount 12} // Stop on the 12th execution of the
6826cf00 14236@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
b37052ae
EZ
14237(@value{GDBP}) @b{trace foo}
14238(@value{GDBP}) @b{pass 3}
14239(@value{GDBP}) @b{trace bar}
14240(@value{GDBP}) @b{pass 2}
14241(@value{GDBP}) @b{trace baz}
14242(@value{GDBP}) @b{pass 1} // Stop tracing when foo has been
6826cf00
EZ
14243@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
14244@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
14245@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
b37052ae
EZ
14246@end smallexample
14247@end table
14248
782b2b07
SS
14249@node Tracepoint Conditions
14250@subsection Tracepoint Conditions
14251@cindex conditional tracepoints
14252@cindex tracepoint conditions
14253
14254The simplest sort of tracepoint collects data every time your program
14255reaches a specified place. You can also specify a @dfn{condition} for
14256a tracepoint. A condition is just a Boolean expression in your
14257programming language (@pxref{Expressions, ,Expressions}). A
14258tracepoint with a condition evaluates the expression each time your
14259program reaches it, and data collection happens only if the condition
14260is true.
14261
14262Tracepoint conditions can be specified when a tracepoint is set, by
14263using @samp{if} in the arguments to the @code{trace} command.
14264@xref{Create and Delete Tracepoints, ,Setting Tracepoints}. They can
14265also be set or changed at any time with the @code{condition} command,
14266just as with breakpoints.
14267
14268Unlike breakpoint conditions, @value{GDBN} does not actually evaluate
14269the conditional expression itself. Instead, @value{GDBN} encodes the
6dcd5565 14270expression into an agent expression (@pxref{Agent Expressions})
782b2b07
SS
14271suitable for execution on the target, independently of @value{GDBN}.
14272Global variables become raw memory locations, locals become stack
14273accesses, and so forth.
14274
14275For instance, suppose you have a function that is usually called
14276frequently, but should not be called after an error has occurred. You
14277could use the following tracepoint command to collect data about calls
14278of that function that happen while the error code is propagating
14279through the program; an unconditional tracepoint could end up
14280collecting thousands of useless trace frames that you would have to
14281search through.
14282
14283@smallexample
14284(@value{GDBP}) @kbd{trace normal_operation if errcode > 0}
14285@end smallexample
14286
f61e138d
SS
14287@node Trace State Variables
14288@subsection Trace State Variables
14289@cindex trace state variables
14290
14291A @dfn{trace state variable} is a special type of variable that is
14292created and managed by target-side code. The syntax is the same as
14293that for GDB's convenience variables (a string prefixed with ``$''),
14294but they are stored on the target. They must be created explicitly,
14295using a @code{tvariable} command. They are always 64-bit signed
14296integers.
14297
14298Trace state variables are remembered by @value{GDBN}, and downloaded
14299to the target along with tracepoint information when the trace
14300experiment starts. There are no intrinsic limits on the number of
14301trace state variables, beyond memory limitations of the target.
14302
14303@cindex convenience variables, and trace state variables
14304Although trace state variables are managed by the target, you can use
14305them in print commands and expressions as if they were convenience
14306variables; @value{GDBN} will get the current value from the target
14307while the trace experiment is running. Trace state variables share
14308the same namespace as other ``$'' variables, which means that you
14309cannot have trace state variables with names like @code{$23} or
14310@code{$pc}, nor can you have a trace state variable and a convenience
14311variable with the same name.
14312
14313@table @code
14314
14315@item tvariable $@var{name} [ = @var{expression} ]
14316@kindex tvariable
14317The @code{tvariable} command creates a new trace state variable named
14318@code{$@var{name}}, and optionally gives it an initial value of
697aa1b7 14319@var{expression}. The @var{expression} is evaluated when this command is
f61e138d
SS
14320entered; the result will be converted to an integer if possible,
14321otherwise @value{GDBN} will report an error. A subsequent
14322@code{tvariable} command specifying the same name does not create a
14323variable, but instead assigns the supplied initial value to the
14324existing variable of that name, overwriting any previous initial
14325value. The default initial value is 0.
14326
14327@item info tvariables
14328@kindex info tvariables
14329List all the trace state variables along with their initial values.
14330Their current values may also be displayed, if the trace experiment is
14331currently running.
14332
14333@item delete tvariable @r{[} $@var{name} @dots{} @r{]}
14334@kindex delete tvariable
14335Delete the given trace state variables, or all of them if no arguments
14336are specified.
14337
14338@end table
14339
b37052ae
EZ
14340@node Tracepoint Actions
14341@subsection Tracepoint Action Lists
14342
14343@table @code
14344@kindex actions
14345@cindex tracepoint actions
14346@item actions @r{[}@var{num}@r{]}
14347This command will prompt for a list of actions to be taken when the
14348tracepoint is hit. If the tracepoint number @var{num} is not
14349specified, this command sets the actions for the one that was most
14350recently defined (so that you can define a tracepoint and then say
14351@code{actions} without bothering about its number). You specify the
14352actions themselves on the following lines, one action at a time, and
14353terminate the actions list with a line containing just @code{end}. So
7d13fe92 14354far, the only defined actions are @code{collect}, @code{teval}, and
b37052ae
EZ
14355@code{while-stepping}.
14356
5a9351ae
SS
14357@code{actions} is actually equivalent to @code{commands} (@pxref{Break
14358Commands, ,Breakpoint Command Lists}), except that only the defined
14359actions are allowed; any other @value{GDBN} command is rejected.
14360
b37052ae
EZ
14361@cindex remove actions from a tracepoint
14362To remove all actions from a tracepoint, type @samp{actions @var{num}}
14363and follow it immediately with @samp{end}.
14364
14365@smallexample
14366(@value{GDBP}) @b{collect @var{data}} // collect some data
14367
6826cf00 14368(@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
b37052ae 14369
6826cf00 14370(@value{GDBP}) @b{end} // signals the end of actions.
b37052ae
EZ
14371@end smallexample
14372
14373In the following example, the action list begins with @code{collect}
14374commands indicating the things to be collected when the tracepoint is
14375hit. Then, in order to single-step and collect additional data
14376following the tracepoint, a @code{while-stepping} command is used,
7d13fe92
SS
14377followed by the list of things to be collected after each step in a
14378sequence of single steps. The @code{while-stepping} command is
14379terminated by its own separate @code{end} command. Lastly, the action
14380list is terminated by an @code{end} command.
b37052ae
EZ
14381
14382@smallexample
14383(@value{GDBP}) @b{trace foo}
14384(@value{GDBP}) @b{actions}
14385Enter actions for tracepoint 1, one per line:
14386> collect bar,baz
14387> collect $regs
14388> while-stepping 12
5a9351ae 14389 > collect $pc, arr[i]
b37052ae
EZ
14390 > end
14391end
14392@end smallexample
14393
14394@kindex collect @r{(tracepoints)}
3065dfb6 14395@item collect@r{[}/@var{mods}@r{]} @var{expr1}, @var{expr2}, @dots{}
b37052ae
EZ
14396Collect values of the given expressions when the tracepoint is hit.
14397This command accepts a comma-separated list of any valid expressions.
14398In addition to global, static, or local variables, the following
14399special arguments are supported:
14400
14401@table @code
14402@item $regs
0fb4aa4b 14403Collect all registers.
b37052ae
EZ
14404
14405@item $args
0fb4aa4b 14406Collect all function arguments.
b37052ae
EZ
14407
14408@item $locals
0fb4aa4b
PA
14409Collect all local variables.
14410
6710bf39
SS
14411@item $_ret
14412Collect the return address. This is helpful if you want to see more
14413of a backtrace.
14414
2a60e18f 14415@emph{Note:} The return address location can not always be reliably
45fa2529
PA
14416determined up front, and the wrong address / registers may end up
14417collected instead. On some architectures the reliability is higher
14418for tracepoints at function entry, while on others it's the opposite.
14419When this happens, backtracing will stop because the return address is
14420found unavailable (unless another collect rule happened to match it).
14421
62e5f89c
SDJ
14422@item $_probe_argc
14423Collects the number of arguments from the static probe at which the
14424tracepoint is located.
14425@xref{Static Probe Points}.
14426
14427@item $_probe_arg@var{n}
14428@var{n} is an integer between 0 and 11. Collects the @var{n}th argument
14429from the static probe at which the tracepoint is located.
14430@xref{Static Probe Points}.
14431
0fb4aa4b
PA
14432@item $_sdata
14433@vindex $_sdata@r{, collect}
14434Collect static tracepoint marker specific data. Only available for
14435static tracepoints. @xref{Tracepoint Actions,,Tracepoint Action
14436Lists}. On the UST static tracepoints library backend, an
14437instrumentation point resembles a @code{printf} function call. The
14438tracing library is able to collect user specified data formatted to a
14439character string using the format provided by the programmer that
14440instrumented the program. Other backends have similar mechanisms.
14441Here's an example of a UST marker call:
14442
14443@smallexample
14444 const char master_name[] = "$your_name";
14445 trace_mark(channel1, marker1, "hello %s", master_name)
14446@end smallexample
14447
14448In this case, collecting @code{$_sdata} collects the string
14449@samp{hello $yourname}. When analyzing the trace buffer, you can
14450inspect @samp{$_sdata} like any other variable available to
14451@value{GDBN}.
b37052ae
EZ
14452@end table
14453
14454You can give several consecutive @code{collect} commands, each one
14455with a single argument, or one @code{collect} command with several
5a9351ae 14456arguments separated by commas; the effect is the same.
b37052ae 14457
3065dfb6
SS
14458The optional @var{mods} changes the usual handling of the arguments.
14459@code{s} requests that pointers to chars be handled as strings, in
14460particular collecting the contents of the memory being pointed at, up
14461to the first zero. The upper bound is by default the value of the
14462@code{print elements} variable; if @code{s} is followed by a decimal
14463number, that is the upper bound instead. So for instance
14464@samp{collect/s25 mystr} collects as many as 25 characters at
14465@samp{mystr}.
14466
f5c37c66
EZ
14467The command @code{info scope} (@pxref{Symbols, info scope}) is
14468particularly useful for figuring out what data to collect.
14469
6da95a67
SS
14470@kindex teval @r{(tracepoints)}
14471@item teval @var{expr1}, @var{expr2}, @dots{}
14472Evaluate the given expressions when the tracepoint is hit. This
14473command accepts a comma-separated list of expressions. The results
14474are discarded, so this is mainly useful for assigning values to trace
14475state variables (@pxref{Trace State Variables}) without adding those
14476values to the trace buffer, as would be the case if the @code{collect}
14477action were used.
14478
b37052ae
EZ
14479@kindex while-stepping @r{(tracepoints)}
14480@item while-stepping @var{n}
c9429232 14481Perform @var{n} single-step instruction traces after the tracepoint,
7d13fe92 14482collecting new data after each step. The @code{while-stepping}
c9429232
SS
14483command is followed by the list of what to collect while stepping
14484(followed by its own @code{end} command):
b37052ae
EZ
14485
14486@smallexample
14487> while-stepping 12
14488 > collect $regs, myglobal
14489 > end
14490>
14491@end smallexample
14492
14493@noindent
7d13fe92
SS
14494Note that @code{$pc} is not automatically collected by
14495@code{while-stepping}; you need to explicitly collect that register if
14496you need it. You may abbreviate @code{while-stepping} as @code{ws} or
b37052ae 14497@code{stepping}.
236f1d4d
SS
14498
14499@item set default-collect @var{expr1}, @var{expr2}, @dots{}
14500@kindex set default-collect
14501@cindex default collection action
14502This variable is a list of expressions to collect at each tracepoint
14503hit. It is effectively an additional @code{collect} action prepended
14504to every tracepoint action list. The expressions are parsed
14505individually for each tracepoint, so for instance a variable named
14506@code{xyz} may be interpreted as a global for one tracepoint, and a
14507local for another, as appropriate to the tracepoint's location.
14508
14509@item show default-collect
14510@kindex show default-collect
14511Show the list of expressions that are collected by default at each
14512tracepoint hit.
14513
b37052ae
EZ
14514@end table
14515
14516@node Listing Tracepoints
14517@subsection Listing Tracepoints
14518
14519@table @code
e5a67952
MS
14520@kindex info tracepoints @r{[}@var{n}@dots{}@r{]}
14521@kindex info tp @r{[}@var{n}@dots{}@r{]}
b37052ae 14522@cindex information about tracepoints
e5a67952 14523@item info tracepoints @r{[}@var{num}@dots{}@r{]}
1042e4c0
SS
14524Display information about the tracepoint @var{num}. If you don't
14525specify a tracepoint number, displays information about all the
14526tracepoints defined so far. The format is similar to that used for
14527@code{info breakpoints}; in fact, @code{info tracepoints} is the same
14528command, simply restricting itself to tracepoints.
14529
14530A tracepoint's listing may include additional information specific to
14531tracing:
b37052ae
EZ
14532
14533@itemize @bullet
14534@item
b37052ae 14535its passcount as given by the @code{passcount @var{n}} command
f2a8bc8a
YQ
14536
14537@item
14538the state about installed on target of each location
b37052ae
EZ
14539@end itemize
14540
14541@smallexample
14542(@value{GDBP}) @b{info trace}
1042e4c0
SS
14543Num Type Disp Enb Address What
145441 tracepoint keep y 0x0804ab57 in foo() at main.cxx:7
5a9351ae
SS
14545 while-stepping 20
14546 collect globfoo, $regs
14547 end
14548 collect globfoo2
14549 end
1042e4c0 14550 pass count 1200
f2a8bc8a
YQ
145512 tracepoint keep y <MULTIPLE>
14552 collect $eip
145532.1 y 0x0804859c in func4 at change-loc.h:35
14554 installed on target
145552.2 y 0xb7ffc480 in func4 at change-loc.h:35
14556 installed on target
145572.3 y <PENDING> set_tracepoint
145583 tracepoint keep y 0x080485b1 in foo at change-loc.c:29
14559 not installed on target
b37052ae
EZ
14560(@value{GDBP})
14561@end smallexample
14562
14563@noindent
14564This command can be abbreviated @code{info tp}.
14565@end table
14566
0fb4aa4b
PA
14567@node Listing Static Tracepoint Markers
14568@subsection Listing Static Tracepoint Markers
14569
14570@table @code
14571@kindex info static-tracepoint-markers
14572@cindex information about static tracepoint markers
14573@item info static-tracepoint-markers
14574Display information about all static tracepoint markers defined in the
14575program.
14576
14577For each marker, the following columns are printed:
14578
14579@table @emph
14580@item Count
14581An incrementing counter, output to help readability. This is not a
14582stable identifier.
14583@item ID
14584The marker ID, as reported by the target.
14585@item Enabled or Disabled
14586Probed markers are tagged with @samp{y}. @samp{n} identifies marks
14587that are not enabled.
14588@item Address
14589Where the marker is in your program, as a memory address.
14590@item What
14591Where the marker is in the source for your program, as a file and line
14592number. If the debug information included in the program does not
14593allow @value{GDBN} to locate the source of the marker, this column
14594will be left blank.
14595@end table
14596
14597@noindent
14598In addition, the following information may be printed for each marker:
14599
14600@table @emph
14601@item Data
14602User data passed to the tracing library by the marker call. In the
14603UST backend, this is the format string passed as argument to the
14604marker call.
14605@item Static tracepoints probing the marker
14606The list of static tracepoints attached to the marker.
14607@end table
14608
14609@smallexample
14610(@value{GDBP}) info static-tracepoint-markers
14611Cnt ID Enb Address What
146121 ust/bar2 y 0x0000000000400e1a in main at stexample.c:25
14613 Data: number1 %d number2 %d
14614 Probed by static tracepoints: #2
146152 ust/bar33 n 0x0000000000400c87 in main at stexample.c:24
14616 Data: str %s
14617(@value{GDBP})
14618@end smallexample
14619@end table
14620
79a6e687
BW
14621@node Starting and Stopping Trace Experiments
14622@subsection Starting and Stopping Trace Experiments
b37052ae
EZ
14623
14624@table @code
f196051f 14625@kindex tstart [ @var{notes} ]
b37052ae
EZ
14626@cindex start a new trace experiment
14627@cindex collected data discarded
14628@item tstart
f196051f
SS
14629This command starts the trace experiment, and begins collecting data.
14630It has the side effect of discarding all the data collected in the
14631trace buffer during the previous trace experiment. If any arguments
14632are supplied, they are taken as a note and stored with the trace
14633experiment's state. The notes may be arbitrary text, and are
14634especially useful with disconnected tracing in a multi-user context;
14635the notes can explain what the trace is doing, supply user contact
14636information, and so forth.
14637
14638@kindex tstop [ @var{notes} ]
b37052ae
EZ
14639@cindex stop a running trace experiment
14640@item tstop
f196051f
SS
14641This command stops the trace experiment. If any arguments are
14642supplied, they are recorded with the experiment as a note. This is
14643useful if you are stopping a trace started by someone else, for
14644instance if the trace is interfering with the system's behavior and
14645needs to be stopped quickly.
b37052ae 14646
68c71a2e 14647@strong{Note}: a trace experiment and data collection may stop
b37052ae
EZ
14648automatically if any tracepoint's passcount is reached
14649(@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
14650
14651@kindex tstatus
14652@cindex status of trace data collection
14653@cindex trace experiment, status of
14654@item tstatus
14655This command displays the status of the current trace data
14656collection.
14657@end table
14658
14659Here is an example of the commands we described so far:
14660
14661@smallexample
14662(@value{GDBP}) @b{trace gdb_c_test}
14663(@value{GDBP}) @b{actions}
14664Enter actions for tracepoint #1, one per line.
14665> collect $regs,$locals,$args
14666> while-stepping 11
14667 > collect $regs
14668 > end
14669> end
14670(@value{GDBP}) @b{tstart}
14671 [time passes @dots{}]
14672(@value{GDBP}) @b{tstop}
14673@end smallexample
14674
03f2bd59 14675@anchor{disconnected tracing}
d5551862
SS
14676@cindex disconnected tracing
14677You can choose to continue running the trace experiment even if
14678@value{GDBN} disconnects from the target, voluntarily or
14679involuntarily. For commands such as @code{detach}, the debugger will
14680ask what you want to do with the trace. But for unexpected
14681terminations (@value{GDBN} crash, network outage), it would be
14682unfortunate to lose hard-won trace data, so the variable
14683@code{disconnected-tracing} lets you decide whether the trace should
14684continue running without @value{GDBN}.
14685
14686@table @code
14687@item set disconnected-tracing on
14688@itemx set disconnected-tracing off
14689@kindex set disconnected-tracing
14690Choose whether a tracing run should continue to run if @value{GDBN}
14691has disconnected from the target. Note that @code{detach} or
14692@code{quit} will ask you directly what to do about a running trace no
14693matter what this variable's setting, so the variable is mainly useful
14694for handling unexpected situations, such as loss of the network.
14695
14696@item show disconnected-tracing
14697@kindex show disconnected-tracing
14698Show the current choice for disconnected tracing.
14699
14700@end table
14701
14702When you reconnect to the target, the trace experiment may or may not
14703still be running; it might have filled the trace buffer in the
14704meantime, or stopped for one of the other reasons. If it is running,
14705it will continue after reconnection.
14706
14707Upon reconnection, the target will upload information about the
14708tracepoints in effect. @value{GDBN} will then compare that
14709information to the set of tracepoints currently defined, and attempt
14710to match them up, allowing for the possibility that the numbers may
14711have changed due to creation and deletion in the meantime. If one of
14712the target's tracepoints does not match any in @value{GDBN}, the
14713debugger will create a new tracepoint, so that you have a number with
14714which to specify that tracepoint. This matching-up process is
14715necessarily heuristic, and it may result in useless tracepoints being
14716created; you may simply delete them if they are of no use.
b37052ae 14717
4daf5ac0
SS
14718@cindex circular trace buffer
14719If your target agent supports a @dfn{circular trace buffer}, then you
14720can run a trace experiment indefinitely without filling the trace
14721buffer; when space runs out, the agent deletes already-collected trace
14722frames, oldest first, until there is enough room to continue
14723collecting. This is especially useful if your tracepoints are being
14724hit too often, and your trace gets terminated prematurely because the
14725buffer is full. To ask for a circular trace buffer, simply set
81896e36 14726@samp{circular-trace-buffer} to on. You can set this at any time,
4daf5ac0
SS
14727including during tracing; if the agent can do it, it will change
14728buffer handling on the fly, otherwise it will not take effect until
14729the next run.
14730
14731@table @code
14732@item set circular-trace-buffer on
14733@itemx set circular-trace-buffer off
14734@kindex set circular-trace-buffer
14735Choose whether a tracing run should use a linear or circular buffer
14736for trace data. A linear buffer will not lose any trace data, but may
14737fill up prematurely, while a circular buffer will discard old trace
14738data, but it will have always room for the latest tracepoint hits.
14739
14740@item show circular-trace-buffer
14741@kindex show circular-trace-buffer
14742Show the current choice for the trace buffer. Note that this may not
14743match the agent's current buffer handling, nor is it guaranteed to
14744match the setting that might have been in effect during a past run,
14745for instance if you are looking at frames from a trace file.
14746
14747@end table
14748
f6f899bf
HAQ
14749@table @code
14750@item set trace-buffer-size @var{n}
f81d1120 14751@itemx set trace-buffer-size unlimited
f6f899bf
HAQ
14752@kindex set trace-buffer-size
14753Request that the target use a trace buffer of @var{n} bytes. Not all
14754targets will honor the request; they may have a compiled-in size for
14755the trace buffer, or some other limitation. Set to a value of
f81d1120
PA
14756@code{unlimited} or @code{-1} to let the target use whatever size it
14757likes. This is also the default.
f6f899bf
HAQ
14758
14759@item show trace-buffer-size
14760@kindex show trace-buffer-size
14761Show the current requested size for the trace buffer. Note that this
14762will only match the actual size if the target supports size-setting,
14763and was able to handle the requested size. For instance, if the
14764target can only change buffer size between runs, this variable will
14765not reflect the change until the next run starts. Use @code{tstatus}
14766to get a report of the actual buffer size.
14767@end table
14768
f196051f
SS
14769@table @code
14770@item set trace-user @var{text}
14771@kindex set trace-user
14772
14773@item show trace-user
14774@kindex show trace-user
14775
14776@item set trace-notes @var{text}
14777@kindex set trace-notes
14778Set the trace run's notes.
14779
14780@item show trace-notes
14781@kindex show trace-notes
14782Show the trace run's notes.
14783
14784@item set trace-stop-notes @var{text}
14785@kindex set trace-stop-notes
14786Set the trace run's stop notes. The handling of the note is as for
14787@code{tstop} arguments; the set command is convenient way to fix a
14788stop note that is mistaken or incomplete.
14789
14790@item show trace-stop-notes
14791@kindex show trace-stop-notes
14792Show the trace run's stop notes.
14793
14794@end table
14795
c9429232
SS
14796@node Tracepoint Restrictions
14797@subsection Tracepoint Restrictions
14798
14799@cindex tracepoint restrictions
14800There are a number of restrictions on the use of tracepoints. As
14801described above, tracepoint data gathering occurs on the target
14802without interaction from @value{GDBN}. Thus the full capabilities of
14803the debugger are not available during data gathering, and then at data
14804examination time, you will be limited by only having what was
14805collected. The following items describe some common problems, but it
14806is not exhaustive, and you may run into additional difficulties not
14807mentioned here.
14808
14809@itemize @bullet
14810
14811@item
14812Tracepoint expressions are intended to gather objects (lvalues). Thus
14813the full flexibility of GDB's expression evaluator is not available.
14814You cannot call functions, cast objects to aggregate types, access
14815convenience variables or modify values (except by assignment to trace
14816state variables). Some language features may implicitly call
14817functions (for instance Objective-C fields with accessors), and therefore
14818cannot be collected either.
14819
14820@item
14821Collection of local variables, either individually or in bulk with
14822@code{$locals} or @code{$args}, during @code{while-stepping} may
14823behave erratically. The stepping action may enter a new scope (for
14824instance by stepping into a function), or the location of the variable
14825may change (for instance it is loaded into a register). The
14826tracepoint data recorded uses the location information for the
14827variables that is correct for the tracepoint location. When the
14828tracepoint is created, it is not possible, in general, to determine
14829where the steps of a @code{while-stepping} sequence will advance the
14830program---particularly if a conditional branch is stepped.
14831
14832@item
14833Collection of an incompletely-initialized or partially-destroyed object
14834may result in something that @value{GDBN} cannot display, or displays
14835in a misleading way.
14836
14837@item
14838When @value{GDBN} displays a pointer to character it automatically
14839dereferences the pointer to also display characters of the string
14840being pointed to. However, collecting the pointer during tracing does
14841not automatically collect the string. You need to explicitly
14842dereference the pointer and provide size information if you want to
14843collect not only the pointer, but the memory pointed to. For example,
14844@code{*ptr@@50} can be used to collect the 50 element array pointed to
14845by @code{ptr}.
14846
14847@item
14848It is not possible to collect a complete stack backtrace at a
14849tracepoint. Instead, you may collect the registers and a few hundred
d99f7e48 14850bytes from the stack pointer with something like @code{*(unsigned char *)$esp@@300}
c9429232
SS
14851(adjust to use the name of the actual stack pointer register on your
14852target architecture, and the amount of stack you wish to capture).
14853Then the @code{backtrace} command will show a partial backtrace when
14854using a trace frame. The number of stack frames that can be examined
14855depends on the sizes of the frames in the collected stack. Note that
14856if you ask for a block so large that it goes past the bottom of the
14857stack, the target agent may report an error trying to read from an
14858invalid address.
14859
af54718e
SS
14860@item
14861If you do not collect registers at a tracepoint, @value{GDBN} can
14862infer that the value of @code{$pc} must be the same as the address of
14863the tracepoint and use that when you are looking at a trace frame
14864for that tracepoint. However, this cannot work if the tracepoint has
14865multiple locations (for instance if it was set in a function that was
14866inlined), or if it has a @code{while-stepping} loop. In those cases
14867@value{GDBN} will warn you that it can't infer @code{$pc}, and default
14868it to zero.
14869
c9429232
SS
14870@end itemize
14871
b37052ae 14872@node Analyze Collected Data
79a6e687 14873@section Using the Collected Data
b37052ae
EZ
14874
14875After the tracepoint experiment ends, you use @value{GDBN} commands
14876for examining the trace data. The basic idea is that each tracepoint
14877collects a trace @dfn{snapshot} every time it is hit and another
14878snapshot every time it single-steps. All these snapshots are
14879consecutively numbered from zero and go into a buffer, and you can
14880examine them later. The way you examine them is to @dfn{focus} on a
14881specific trace snapshot. When the remote stub is focused on a trace
14882snapshot, it will respond to all @value{GDBN} requests for memory and
14883registers by reading from the buffer which belongs to that snapshot,
14884rather than from @emph{real} memory or registers of the program being
14885debugged. This means that @strong{all} @value{GDBN} commands
14886(@code{print}, @code{info registers}, @code{backtrace}, etc.) will
14887behave as if we were currently debugging the program state as it was
14888when the tracepoint occurred. Any requests for data that are not in
14889the buffer will fail.
14890
14891@menu
14892* tfind:: How to select a trace snapshot
14893* tdump:: How to display all data for a snapshot
6149aea9 14894* save tracepoints:: How to save tracepoints for a future run
b37052ae
EZ
14895@end menu
14896
14897@node tfind
14898@subsection @code{tfind @var{n}}
14899
14900@kindex tfind
14901@cindex select trace snapshot
14902@cindex find trace snapshot
14903The basic command for selecting a trace snapshot from the buffer is
14904@code{tfind @var{n}}, which finds trace snapshot number @var{n},
14905counting from zero. If no argument @var{n} is given, the next
14906snapshot is selected.
14907
14908Here are the various forms of using the @code{tfind} command.
14909
14910@table @code
14911@item tfind start
14912Find the first snapshot in the buffer. This is a synonym for
14913@code{tfind 0} (since 0 is the number of the first snapshot).
14914
14915@item tfind none
14916Stop debugging trace snapshots, resume @emph{live} debugging.
14917
14918@item tfind end
14919Same as @samp{tfind none}.
14920
14921@item tfind
310cdbb6
YQ
14922No argument means find the next trace snapshot or find the first
14923one if no trace snapshot is selected.
b37052ae
EZ
14924
14925@item tfind -
14926Find the previous trace snapshot before the current one. This permits
14927retracing earlier steps.
14928
14929@item tfind tracepoint @var{num}
14930Find the next snapshot associated with tracepoint @var{num}. Search
14931proceeds forward from the last examined trace snapshot. If no
14932argument @var{num} is given, it means find the next snapshot collected
14933for the same tracepoint as the current snapshot.
14934
14935@item tfind pc @var{addr}
14936Find the next snapshot associated with the value @var{addr} of the
14937program counter. Search proceeds forward from the last examined trace
14938snapshot. If no argument @var{addr} is given, it means find the next
14939snapshot with the same value of PC as the current snapshot.
14940
14941@item tfind outside @var{addr1}, @var{addr2}
14942Find the next snapshot whose PC is outside the given range of
081dfbf7 14943addresses (exclusive).
b37052ae
EZ
14944
14945@item tfind range @var{addr1}, @var{addr2}
14946Find the next snapshot whose PC is between @var{addr1} and
081dfbf7 14947@var{addr2} (inclusive).
b37052ae
EZ
14948
14949@item tfind line @r{[}@var{file}:@r{]}@var{n}
14950Find the next snapshot associated with the source line @var{n}. If
14951the optional argument @var{file} is given, refer to line @var{n} in
14952that source file. Search proceeds forward from the last examined
14953trace snapshot. If no argument @var{n} is given, it means find the
14954next line other than the one currently being examined; thus saying
14955@code{tfind line} repeatedly can appear to have the same effect as
14956stepping from line to line in a @emph{live} debugging session.
14957@end table
14958
14959The default arguments for the @code{tfind} commands are specifically
14960designed to make it easy to scan through the trace buffer. For
14961instance, @code{tfind} with no argument selects the next trace
14962snapshot, and @code{tfind -} with no argument selects the previous
14963trace snapshot. So, by giving one @code{tfind} command, and then
14964simply hitting @key{RET} repeatedly you can examine all the trace
14965snapshots in order. Or, by saying @code{tfind -} and then hitting
14966@key{RET} repeatedly you can examine the snapshots in reverse order.
14967The @code{tfind line} command with no argument selects the snapshot
14968for the next source line executed. The @code{tfind pc} command with
14969no argument selects the next snapshot with the same program counter
14970(PC) as the current frame. The @code{tfind tracepoint} command with
14971no argument selects the next trace snapshot collected by the same
14972tracepoint as the current one.
14973
14974In addition to letting you scan through the trace buffer manually,
14975these commands make it easy to construct @value{GDBN} scripts that
14976scan through the trace buffer and print out whatever collected data
14977you are interested in. Thus, if we want to examine the PC, FP, and SP
14978registers from each trace frame in the buffer, we can say this:
14979
14980@smallexample
14981(@value{GDBP}) @b{tfind start}
14982(@value{GDBP}) @b{while ($trace_frame != -1)}
14983> printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
14984 $trace_frame, $pc, $sp, $fp
14985> tfind
14986> end
14987
14988Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
14989Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
14990Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
14991Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
14992Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
14993Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
14994Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
14995Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
14996Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
14997Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
14998Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
14999@end smallexample
15000
15001Or, if we want to examine the variable @code{X} at each source line in
15002the buffer:
15003
15004@smallexample
15005(@value{GDBP}) @b{tfind start}
15006(@value{GDBP}) @b{while ($trace_frame != -1)}
15007> printf "Frame %d, X == %d\n", $trace_frame, X
15008> tfind line
15009> end
15010
15011Frame 0, X = 1
15012Frame 7, X = 2
15013Frame 13, X = 255
15014@end smallexample
15015
15016@node tdump
15017@subsection @code{tdump}
15018@kindex tdump
15019@cindex dump all data collected at tracepoint
15020@cindex tracepoint data, display
15021
15022This command takes no arguments. It prints all the data collected at
15023the current trace snapshot.
15024
15025@smallexample
15026(@value{GDBP}) @b{trace 444}
15027(@value{GDBP}) @b{actions}
15028Enter actions for tracepoint #2, one per line:
15029> collect $regs, $locals, $args, gdb_long_test
15030> end
15031
15032(@value{GDBP}) @b{tstart}
15033
15034(@value{GDBP}) @b{tfind line 444}
15035#0 gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
15036at gdb_test.c:444
15037444 printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
15038
15039(@value{GDBP}) @b{tdump}
15040Data collected at tracepoint 2, trace frame 1:
15041d0 0xc4aa0085 -995491707
15042d1 0x18 24
15043d2 0x80 128
15044d3 0x33 51
15045d4 0x71aea3d 119204413
15046d5 0x22 34
15047d6 0xe0 224
15048d7 0x380035 3670069
15049a0 0x19e24a 1696330
15050a1 0x3000668 50333288
15051a2 0x100 256
15052a3 0x322000 3284992
15053a4 0x3000698 50333336
15054a5 0x1ad3cc 1758156
15055fp 0x30bf3c 0x30bf3c
15056sp 0x30bf34 0x30bf34
15057ps 0x0 0
15058pc 0x20b2c8 0x20b2c8
15059fpcontrol 0x0 0
15060fpstatus 0x0 0
15061fpiaddr 0x0 0
15062p = 0x20e5b4 "gdb-test"
15063p1 = (void *) 0x11
15064p2 = (void *) 0x22
15065p3 = (void *) 0x33
15066p4 = (void *) 0x44
15067p5 = (void *) 0x55
15068p6 = (void *) 0x66
15069gdb_long_test = 17 '\021'
15070
15071(@value{GDBP})
15072@end smallexample
15073
af54718e
SS
15074@code{tdump} works by scanning the tracepoint's current collection
15075actions and printing the value of each expression listed. So
15076@code{tdump} can fail, if after a run, you change the tracepoint's
15077actions to mention variables that were not collected during the run.
15078
15079Also, for tracepoints with @code{while-stepping} loops, @code{tdump}
15080uses the collected value of @code{$pc} to distinguish between trace
15081frames that were collected at the tracepoint hit, and frames that were
15082collected while stepping. This allows it to correctly choose whether
15083to display the basic list of collections, or the collections from the
15084body of the while-stepping loop. However, if @code{$pc} was not collected,
15085then @code{tdump} will always attempt to dump using the basic collection
15086list, and may fail if a while-stepping frame does not include all the
15087same data that is collected at the tracepoint hit.
15088@c This is getting pretty arcane, example would be good.
15089
6149aea9
PA
15090@node save tracepoints
15091@subsection @code{save tracepoints @var{filename}}
15092@kindex save tracepoints
b37052ae
EZ
15093@kindex save-tracepoints
15094@cindex save tracepoints for future sessions
15095
15096This command saves all current tracepoint definitions together with
15097their actions and passcounts, into a file @file{@var{filename}}
15098suitable for use in a later debugging session. To read the saved
15099tracepoint definitions, use the @code{source} command (@pxref{Command
6149aea9
PA
15100Files}). The @w{@code{save-tracepoints}} command is a deprecated
15101alias for @w{@code{save tracepoints}}
b37052ae
EZ
15102
15103@node Tracepoint Variables
15104@section Convenience Variables for Tracepoints
15105@cindex tracepoint variables
15106@cindex convenience variables for tracepoints
15107
15108@table @code
15109@vindex $trace_frame
15110@item (int) $trace_frame
15111The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
15112snapshot is selected.
15113
15114@vindex $tracepoint
15115@item (int) $tracepoint
15116The tracepoint for the current trace snapshot.
15117
15118@vindex $trace_line
15119@item (int) $trace_line
15120The line number for the current trace snapshot.
15121
15122@vindex $trace_file
15123@item (char []) $trace_file
15124The source file for the current trace snapshot.
15125
15126@vindex $trace_func
15127@item (char []) $trace_func
15128The name of the function containing @code{$tracepoint}.
15129@end table
15130
15131Note: @code{$trace_file} is not suitable for use in @code{printf},
15132use @code{output} instead.
15133
15134Here's a simple example of using these convenience variables for
15135stepping through all the trace snapshots and printing some of their
f61e138d
SS
15136data. Note that these are not the same as trace state variables,
15137which are managed by the target.
b37052ae
EZ
15138
15139@smallexample
15140(@value{GDBP}) @b{tfind start}
15141
15142(@value{GDBP}) @b{while $trace_frame != -1}
15143> output $trace_file
15144> printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
15145> tfind
15146> end
15147@end smallexample
15148
00bf0b85
SS
15149@node Trace Files
15150@section Using Trace Files
15151@cindex trace files
15152
15153In some situations, the target running a trace experiment may no
15154longer be available; perhaps it crashed, or the hardware was needed
15155for a different activity. To handle these cases, you can arrange to
15156dump the trace data into a file, and later use that file as a source
15157of trace data, via the @code{target tfile} command.
15158
15159@table @code
15160
15161@kindex tsave
15162@item tsave [ -r ] @var{filename}
d0353e76 15163@itemx tsave [-ctf] @var{dirname}
00bf0b85
SS
15164Save the trace data to @var{filename}. By default, this command
15165assumes that @var{filename} refers to the host filesystem, so if
15166necessary @value{GDBN} will copy raw trace data up from the target and
15167then save it. If the target supports it, you can also supply the
15168optional argument @code{-r} (``remote'') to direct the target to save
15169the data directly into @var{filename} in its own filesystem, which may be
15170more efficient if the trace buffer is very large. (Note, however, that
15171@code{target tfile} can only read from files accessible to the host.)
d0353e76 15172By default, this command will save trace frame in tfile format.
be06ba8c 15173You can supply the optional argument @code{-ctf} to save data in CTF
d0353e76
YQ
15174format. The @dfn{Common Trace Format} (CTF) is proposed as a trace format
15175that can be shared by multiple debugging and tracing tools. Please go to
15176@indicateurl{http://www.efficios.com/ctf} to get more information.
00bf0b85
SS
15177
15178@kindex target tfile
15179@kindex tfile
393fd4c3
YQ
15180@kindex target ctf
15181@kindex ctf
00bf0b85 15182@item target tfile @var{filename}
393fd4c3
YQ
15183@itemx target ctf @var{dirname}
15184Use the file named @var{filename} or directory named @var{dirname} as
15185a source of trace data. Commands that examine data work as they do with
15186a live target, but it is not possible to run any new trace experiments.
15187@code{tstatus} will report the state of the trace run at the moment
15188the data was saved, as well as the current trace frame you are examining.
697aa1b7 15189Both @var{filename} and @var{dirname} must be on a filesystem accessible to
393fd4c3
YQ
15190the host.
15191
15192@smallexample
15193(@value{GDBP}) target ctf ctf.ctf
15194(@value{GDBP}) tfind
15195Found trace frame 0, tracepoint 2
1519639 ++a; /* set tracepoint 1 here */
15197(@value{GDBP}) tdump
15198Data collected at tracepoint 2, trace frame 0:
15199i = 0
15200a = 0
15201b = 1 '\001'
15202c = @{"123", "456", "789", "123", "456", "789"@}
15203d = @{@{@{a = 1, b = 2@}, @{a = 3, b = 4@}@}, @{@{a = 5, b = 6@}, @{a = 7, b = 8@}@}@}
15204(@value{GDBP}) p b
15205$1 = 1
15206@end smallexample
00bf0b85
SS
15207
15208@end table
15209
df0cd8c5
JB
15210@node Overlays
15211@chapter Debugging Programs That Use Overlays
15212@cindex overlays
15213
15214If your program is too large to fit completely in your target system's
15215memory, you can sometimes use @dfn{overlays} to work around this
15216problem. @value{GDBN} provides some support for debugging programs that
15217use overlays.
15218
15219@menu
15220* How Overlays Work:: A general explanation of overlays.
15221* Overlay Commands:: Managing overlays in @value{GDBN}.
15222* Automatic Overlay Debugging:: @value{GDBN} can find out which overlays are
15223 mapped by asking the inferior.
15224* Overlay Sample Program:: A sample program using overlays.
15225@end menu
15226
15227@node How Overlays Work
15228@section How Overlays Work
15229@cindex mapped overlays
15230@cindex unmapped overlays
15231@cindex load address, overlay's
15232@cindex mapped address
15233@cindex overlay area
15234
15235Suppose you have a computer whose instruction address space is only 64
15236kilobytes long, but which has much more memory which can be accessed by
15237other means: special instructions, segment registers, or memory
15238management hardware, for example. Suppose further that you want to
15239adapt a program which is larger than 64 kilobytes to run on this system.
15240
15241One solution is to identify modules of your program which are relatively
15242independent, and need not call each other directly; call these modules
15243@dfn{overlays}. Separate the overlays from the main program, and place
15244their machine code in the larger memory. Place your main program in
15245instruction memory, but leave at least enough space there to hold the
15246largest overlay as well.
15247
15248Now, to call a function located in an overlay, you must first copy that
15249overlay's machine code from the large memory into the space set aside
15250for it in the instruction memory, and then jump to its entry point
15251there.
15252
c928edc0
AC
15253@c NB: In the below the mapped area's size is greater or equal to the
15254@c size of all overlays. This is intentional to remind the developer
15255@c that overlays don't necessarily need to be the same size.
15256
474c8240 15257@smallexample
df0cd8c5 15258@group
c928edc0
AC
15259 Data Instruction Larger
15260Address Space Address Space Address Space
15261+-----------+ +-----------+ +-----------+
15262| | | | | |
15263+-----------+ +-----------+ +-----------+<-- overlay 1
15264| program | | main | .----| overlay 1 | load address
15265| variables | | program | | +-----------+
15266| and heap | | | | | |
15267+-----------+ | | | +-----------+<-- overlay 2
15268| | +-----------+ | | | load address
15269+-----------+ | | | .-| overlay 2 |
15270 | | | | | |
15271 mapped --->+-----------+ | | +-----------+
15272 address | | | | | |
15273 | overlay | <-' | | |
15274 | area | <---' +-----------+<-- overlay 3
15275 | | <---. | | load address
15276 +-----------+ `--| overlay 3 |
15277 | | | |
15278 +-----------+ | |
15279 +-----------+
15280 | |
15281 +-----------+
15282
15283 @anchor{A code overlay}A code overlay
df0cd8c5 15284@end group
474c8240 15285@end smallexample
df0cd8c5 15286
c928edc0
AC
15287The diagram (@pxref{A code overlay}) shows a system with separate data
15288and instruction address spaces. To map an overlay, the program copies
15289its code from the larger address space to the instruction address space.
15290Since the overlays shown here all use the same mapped address, only one
15291may be mapped at a time. For a system with a single address space for
15292data and instructions, the diagram would be similar, except that the
15293program variables and heap would share an address space with the main
15294program and the overlay area.
df0cd8c5
JB
15295
15296An overlay loaded into instruction memory and ready for use is called a
15297@dfn{mapped} overlay; its @dfn{mapped address} is its address in the
15298instruction memory. An overlay not present (or only partially present)
15299in instruction memory is called @dfn{unmapped}; its @dfn{load address}
15300is its address in the larger memory. The mapped address is also called
15301the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
15302called the @dfn{load memory address}, or @dfn{LMA}.
15303
15304Unfortunately, overlays are not a completely transparent way to adapt a
15305program to limited instruction memory. They introduce a new set of
15306global constraints you must keep in mind as you design your program:
15307
15308@itemize @bullet
15309
15310@item
15311Before calling or returning to a function in an overlay, your program
15312must make sure that overlay is actually mapped. Otherwise, the call or
15313return will transfer control to the right address, but in the wrong
15314overlay, and your program will probably crash.
15315
15316@item
15317If the process of mapping an overlay is expensive on your system, you
15318will need to choose your overlays carefully to minimize their effect on
15319your program's performance.
15320
15321@item
15322The executable file you load onto your system must contain each
15323overlay's instructions, appearing at the overlay's load address, not its
15324mapped address. However, each overlay's instructions must be relocated
15325and its symbols defined as if the overlay were at its mapped address.
15326You can use GNU linker scripts to specify different load and relocation
15327addresses for pieces of your program; see @ref{Overlay Description,,,
15328ld.info, Using ld: the GNU linker}.
15329
15330@item
15331The procedure for loading executable files onto your system must be able
15332to load their contents into the larger address space as well as the
15333instruction and data spaces.
15334
15335@end itemize
15336
15337The overlay system described above is rather simple, and could be
15338improved in many ways:
15339
15340@itemize @bullet
15341
15342@item
15343If your system has suitable bank switch registers or memory management
15344hardware, you could use those facilities to make an overlay's load area
15345contents simply appear at their mapped address in instruction space.
15346This would probably be faster than copying the overlay to its mapped
15347area in the usual way.
15348
15349@item
15350If your overlays are small enough, you could set aside more than one
15351overlay area, and have more than one overlay mapped at a time.
15352
15353@item
15354You can use overlays to manage data, as well as instructions. In
15355general, data overlays are even less transparent to your design than
15356code overlays: whereas code overlays only require care when you call or
15357return to functions, data overlays require care every time you access
15358the data. Also, if you change the contents of a data overlay, you
15359must copy its contents back out to its load address before you can copy a
15360different data overlay into the same mapped area.
15361
15362@end itemize
15363
15364
15365@node Overlay Commands
15366@section Overlay Commands
15367
15368To use @value{GDBN}'s overlay support, each overlay in your program must
15369correspond to a separate section of the executable file. The section's
15370virtual memory address and load memory address must be the overlay's
15371mapped and load addresses. Identifying overlays with sections allows
15372@value{GDBN} to determine the appropriate address of a function or
15373variable, depending on whether the overlay is mapped or not.
15374
15375@value{GDBN}'s overlay commands all start with the word @code{overlay};
15376you can abbreviate this as @code{ov} or @code{ovly}. The commands are:
15377
15378@table @code
15379@item overlay off
4644b6e3 15380@kindex overlay
df0cd8c5
JB
15381Disable @value{GDBN}'s overlay support. When overlay support is
15382disabled, @value{GDBN} assumes that all functions and variables are
15383always present at their mapped addresses. By default, @value{GDBN}'s
15384overlay support is disabled.
15385
15386@item overlay manual
df0cd8c5
JB
15387@cindex manual overlay debugging
15388Enable @dfn{manual} overlay debugging. In this mode, @value{GDBN}
15389relies on you to tell it which overlays are mapped, and which are not,
15390using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
15391commands described below.
15392
15393@item overlay map-overlay @var{overlay}
15394@itemx overlay map @var{overlay}
df0cd8c5
JB
15395@cindex map an overlay
15396Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
15397be the name of the object file section containing the overlay. When an
15398overlay is mapped, @value{GDBN} assumes it can find the overlay's
15399functions and variables at their mapped addresses. @value{GDBN} assumes
15400that any other overlays whose mapped ranges overlap that of
15401@var{overlay} are now unmapped.
15402
15403@item overlay unmap-overlay @var{overlay}
15404@itemx overlay unmap @var{overlay}
df0cd8c5
JB
15405@cindex unmap an overlay
15406Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
15407must be the name of the object file section containing the overlay.
15408When an overlay is unmapped, @value{GDBN} assumes it can find the
15409overlay's functions and variables at their load addresses.
15410
15411@item overlay auto
df0cd8c5
JB
15412Enable @dfn{automatic} overlay debugging. In this mode, @value{GDBN}
15413consults a data structure the overlay manager maintains in the inferior
15414to see which overlays are mapped. For details, see @ref{Automatic
15415Overlay Debugging}.
15416
15417@item overlay load-target
15418@itemx overlay load
df0cd8c5
JB
15419@cindex reloading the overlay table
15420Re-read the overlay table from the inferior. Normally, @value{GDBN}
15421re-reads the table @value{GDBN} automatically each time the inferior
15422stops, so this command should only be necessary if you have changed the
15423overlay mapping yourself using @value{GDBN}. This command is only
15424useful when using automatic overlay debugging.
15425
15426@item overlay list-overlays
15427@itemx overlay list
15428@cindex listing mapped overlays
15429Display a list of the overlays currently mapped, along with their mapped
15430addresses, load addresses, and sizes.
15431
15432@end table
15433
15434Normally, when @value{GDBN} prints a code address, it includes the name
15435of the function the address falls in:
15436
474c8240 15437@smallexample
f7dc1244 15438(@value{GDBP}) print main
df0cd8c5 15439$3 = @{int ()@} 0x11a0 <main>
474c8240 15440@end smallexample
df0cd8c5
JB
15441@noindent
15442When overlay debugging is enabled, @value{GDBN} recognizes code in
15443unmapped overlays, and prints the names of unmapped functions with
15444asterisks around them. For example, if @code{foo} is a function in an
15445unmapped overlay, @value{GDBN} prints it this way:
15446
474c8240 15447@smallexample
f7dc1244 15448(@value{GDBP}) overlay list
df0cd8c5 15449No sections are mapped.
f7dc1244 15450(@value{GDBP}) print foo
df0cd8c5 15451$5 = @{int (int)@} 0x100000 <*foo*>
474c8240 15452@end smallexample
df0cd8c5
JB
15453@noindent
15454When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
15455name normally:
15456
474c8240 15457@smallexample
f7dc1244 15458(@value{GDBP}) overlay list
b383017d 15459Section .ov.foo.text, loaded at 0x100000 - 0x100034,
df0cd8c5 15460 mapped at 0x1016 - 0x104a
f7dc1244 15461(@value{GDBP}) print foo
df0cd8c5 15462$6 = @{int (int)@} 0x1016 <foo>
474c8240 15463@end smallexample
df0cd8c5
JB
15464
15465When overlay debugging is enabled, @value{GDBN} can find the correct
15466address for functions and variables in an overlay, whether or not the
15467overlay is mapped. This allows most @value{GDBN} commands, like
15468@code{break} and @code{disassemble}, to work normally, even on unmapped
15469code. However, @value{GDBN}'s breakpoint support has some limitations:
15470
15471@itemize @bullet
15472@item
15473@cindex breakpoints in overlays
15474@cindex overlays, setting breakpoints in
15475You can set breakpoints in functions in unmapped overlays, as long as
15476@value{GDBN} can write to the overlay at its load address.
15477@item
15478@value{GDBN} can not set hardware or simulator-based breakpoints in
15479unmapped overlays. However, if you set a breakpoint at the end of your
15480overlay manager (and tell @value{GDBN} which overlays are now mapped, if
15481you are using manual overlay management), @value{GDBN} will re-set its
15482breakpoints properly.
15483@end itemize
15484
15485
15486@node Automatic Overlay Debugging
15487@section Automatic Overlay Debugging
15488@cindex automatic overlay debugging
15489
15490@value{GDBN} can automatically track which overlays are mapped and which
15491are not, given some simple co-operation from the overlay manager in the
15492inferior. If you enable automatic overlay debugging with the
15493@code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
15494looks in the inferior's memory for certain variables describing the
15495current state of the overlays.
15496
15497Here are the variables your overlay manager must define to support
15498@value{GDBN}'s automatic overlay debugging:
15499
15500@table @asis
15501
15502@item @code{_ovly_table}:
15503This variable must be an array of the following structures:
15504
474c8240 15505@smallexample
df0cd8c5
JB
15506struct
15507@{
15508 /* The overlay's mapped address. */
15509 unsigned long vma;
15510
15511 /* The size of the overlay, in bytes. */
15512 unsigned long size;
15513
15514 /* The overlay's load address. */
15515 unsigned long lma;
15516
15517 /* Non-zero if the overlay is currently mapped;
15518 zero otherwise. */
15519 unsigned long mapped;
15520@}
474c8240 15521@end smallexample
df0cd8c5
JB
15522
15523@item @code{_novlys}:
15524This variable must be a four-byte signed integer, holding the total
15525number of elements in @code{_ovly_table}.
15526
15527@end table
15528
15529To decide whether a particular overlay is mapped or not, @value{GDBN}
15530looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
15531@code{lma} members equal the VMA and LMA of the overlay's section in the
15532executable file. When @value{GDBN} finds a matching entry, it consults
15533the entry's @code{mapped} member to determine whether the overlay is
15534currently mapped.
15535
81d46470 15536In addition, your overlay manager may define a function called
def71bfa 15537@code{_ovly_debug_event}. If this function is defined, @value{GDBN}
81d46470
MS
15538will silently set a breakpoint there. If the overlay manager then
15539calls this function whenever it has changed the overlay table, this
15540will enable @value{GDBN} to accurately keep track of which overlays
15541are in program memory, and update any breakpoints that may be set
b383017d 15542in overlays. This will allow breakpoints to work even if the
81d46470
MS
15543overlays are kept in ROM or other non-writable memory while they
15544are not being executed.
df0cd8c5
JB
15545
15546@node Overlay Sample Program
15547@section Overlay Sample Program
15548@cindex overlay example program
15549
15550When linking a program which uses overlays, you must place the overlays
15551at their load addresses, while relocating them to run at their mapped
15552addresses. To do this, you must write a linker script (@pxref{Overlay
15553Description,,, ld.info, Using ld: the GNU linker}). Unfortunately,
15554since linker scripts are specific to a particular host system, target
15555architecture, and target memory layout, this manual cannot provide
15556portable sample code demonstrating @value{GDBN}'s overlay support.
15557
15558However, the @value{GDBN} source distribution does contain an overlaid
15559program, with linker scripts for a few systems, as part of its test
15560suite. The program consists of the following files from
15561@file{gdb/testsuite/gdb.base}:
15562
15563@table @file
15564@item overlays.c
15565The main program file.
15566@item ovlymgr.c
15567A simple overlay manager, used by @file{overlays.c}.
15568@item foo.c
15569@itemx bar.c
15570@itemx baz.c
15571@itemx grbx.c
15572Overlay modules, loaded and used by @file{overlays.c}.
15573@item d10v.ld
15574@itemx m32r.ld
15575Linker scripts for linking the test program on the @code{d10v-elf}
15576and @code{m32r-elf} targets.
15577@end table
15578
15579You can build the test program using the @code{d10v-elf} GCC
15580cross-compiler like this:
15581
474c8240 15582@smallexample
df0cd8c5
JB
15583$ d10v-elf-gcc -g -c overlays.c
15584$ d10v-elf-gcc -g -c ovlymgr.c
15585$ d10v-elf-gcc -g -c foo.c
15586$ d10v-elf-gcc -g -c bar.c
15587$ d10v-elf-gcc -g -c baz.c
15588$ d10v-elf-gcc -g -c grbx.c
15589$ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
15590 baz.o grbx.o -Wl,-Td10v.ld -o overlays
474c8240 15591@end smallexample
df0cd8c5
JB
15592
15593The build process is identical for any other architecture, except that
15594you must substitute the appropriate compiler and linker script for the
15595target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
15596
15597
6d2ebf8b 15598@node Languages
c906108c
SS
15599@chapter Using @value{GDBN} with Different Languages
15600@cindex languages
15601
c906108c
SS
15602Although programming languages generally have common aspects, they are
15603rarely expressed in the same manner. For instance, in ANSI C,
15604dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
15605Modula-2, it is accomplished by @code{p^}. Values can also be
5d161b24 15606represented (and displayed) differently. Hex numbers in C appear as
c906108c 15607@samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
c906108c
SS
15608
15609@cindex working language
15610Language-specific information is built into @value{GDBN} for some languages,
15611allowing you to express operations like the above in your program's
15612native language, and allowing @value{GDBN} to output values in a manner
15613consistent with the syntax of your program's native language. The
15614language you use to build expressions is called the @dfn{working
15615language}.
15616
15617@menu
15618* Setting:: Switching between source languages
15619* Show:: Displaying the language
c906108c 15620* Checks:: Type and range checks
79a6e687
BW
15621* Supported Languages:: Supported languages
15622* Unsupported Languages:: Unsupported languages
c906108c
SS
15623@end menu
15624
6d2ebf8b 15625@node Setting
79a6e687 15626@section Switching Between Source Languages
c906108c
SS
15627
15628There are two ways to control the working language---either have @value{GDBN}
15629set it automatically, or select it manually yourself. You can use the
15630@code{set language} command for either purpose. On startup, @value{GDBN}
15631defaults to setting the language automatically. The working language is
15632used to determine how expressions you type are interpreted, how values
15633are printed, etc.
15634
15635In addition to the working language, every source file that
15636@value{GDBN} knows about has its own working language. For some object
15637file formats, the compiler might indicate which language a particular
15638source file is in. However, most of the time @value{GDBN} infers the
15639language from the name of the file. The language of a source file
b37052ae 15640controls whether C@t{++} names are demangled---this way @code{backtrace} can
c906108c 15641show each frame appropriately for its own language. There is no way to
d4f3574e
SS
15642set the language of a source file from within @value{GDBN}, but you can
15643set the language associated with a filename extension. @xref{Show, ,
79a6e687 15644Displaying the Language}.
c906108c
SS
15645
15646This is most commonly a problem when you use a program, such
5d161b24 15647as @code{cfront} or @code{f2c}, that generates C but is written in
c906108c
SS
15648another language. In that case, make the
15649program use @code{#line} directives in its C output; that way
15650@value{GDBN} will know the correct language of the source code of the original
15651program, and will display that source code, not the generated C code.
15652
15653@menu
15654* Filenames:: Filename extensions and languages.
15655* Manually:: Setting the working language manually
15656* Automatically:: Having @value{GDBN} infer the source language
15657@end menu
15658
6d2ebf8b 15659@node Filenames
79a6e687 15660@subsection List of Filename Extensions and Languages
c906108c
SS
15661
15662If a source file name ends in one of the following extensions, then
15663@value{GDBN} infers that its language is the one indicated.
15664
15665@table @file
e07c999f
PH
15666@item .ada
15667@itemx .ads
15668@itemx .adb
15669@itemx .a
15670Ada source file.
c906108c
SS
15671
15672@item .c
15673C source file
15674
15675@item .C
15676@itemx .cc
15677@itemx .cp
15678@itemx .cpp
15679@itemx .cxx
15680@itemx .c++
b37052ae 15681C@t{++} source file
c906108c 15682
6aecb9c2
JB
15683@item .d
15684D source file
15685
b37303ee
AF
15686@item .m
15687Objective-C source file
15688
c906108c
SS
15689@item .f
15690@itemx .F
15691Fortran source file
15692
c906108c
SS
15693@item .mod
15694Modula-2 source file
c906108c
SS
15695
15696@item .s
15697@itemx .S
15698Assembler source file. This actually behaves almost like C, but
15699@value{GDBN} does not skip over function prologues when stepping.
15700@end table
15701
15702In addition, you may set the language associated with a filename
79a6e687 15703extension. @xref{Show, , Displaying the Language}.
c906108c 15704
6d2ebf8b 15705@node Manually
79a6e687 15706@subsection Setting the Working Language
c906108c
SS
15707
15708If you allow @value{GDBN} to set the language automatically,
15709expressions are interpreted the same way in your debugging session and
15710your program.
15711
15712@kindex set language
15713If you wish, you may set the language manually. To do this, issue the
15714command @samp{set language @var{lang}}, where @var{lang} is the name of
5d161b24 15715a language, such as
c906108c 15716@code{c} or @code{modula-2}.
c906108c
SS
15717For a list of the supported languages, type @samp{set language}.
15718
c906108c
SS
15719Setting the language manually prevents @value{GDBN} from updating the working
15720language automatically. This can lead to confusion if you try
15721to debug a program when the working language is not the same as the
15722source language, when an expression is acceptable to both
15723languages---but means different things. For instance, if the current
15724source file were written in C, and @value{GDBN} was parsing Modula-2, a
15725command such as:
15726
474c8240 15727@smallexample
c906108c 15728print a = b + c
474c8240 15729@end smallexample
c906108c
SS
15730
15731@noindent
15732might not have the effect you intended. In C, this means to add
15733@code{b} and @code{c} and place the result in @code{a}. The result
15734printed would be the value of @code{a}. In Modula-2, this means to compare
15735@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
c906108c 15736
6d2ebf8b 15737@node Automatically
79a6e687 15738@subsection Having @value{GDBN} Infer the Source Language
c906108c
SS
15739
15740To have @value{GDBN} set the working language automatically, use
15741@samp{set language local} or @samp{set language auto}. @value{GDBN}
15742then infers the working language. That is, when your program stops in a
15743frame (usually by encountering a breakpoint), @value{GDBN} sets the
15744working language to the language recorded for the function in that
15745frame. If the language for a frame is unknown (that is, if the function
15746or block corresponding to the frame was defined in a source file that
15747does not have a recognized extension), the current working language is
15748not changed, and @value{GDBN} issues a warning.
15749
15750This may not seem necessary for most programs, which are written
15751entirely in one source language. However, program modules and libraries
15752written in one source language can be used by a main program written in
15753a different source language. Using @samp{set language auto} in this
15754case frees you from having to set the working language manually.
15755
6d2ebf8b 15756@node Show
79a6e687 15757@section Displaying the Language
c906108c
SS
15758
15759The following commands help you find out which language is the
15760working language, and also what language source files were written in.
15761
c906108c
SS
15762@table @code
15763@item show language
403cb6b1 15764@anchor{show language}
9c16f35a 15765@kindex show language
c906108c
SS
15766Display the current working language. This is the
15767language you can use with commands such as @code{print} to
15768build and compute expressions that may involve variables in your program.
15769
15770@item info frame
4644b6e3 15771@kindex info frame@r{, show the source language}
5d161b24 15772Display the source language for this frame. This language becomes the
c906108c 15773working language if you use an identifier from this frame.
79a6e687 15774@xref{Frame Info, ,Information about a Frame}, to identify the other
c906108c
SS
15775information listed here.
15776
15777@item info source
4644b6e3 15778@kindex info source@r{, show the source language}
c906108c 15779Display the source language of this source file.
5d161b24 15780@xref{Symbols, ,Examining the Symbol Table}, to identify the other
c906108c
SS
15781information listed here.
15782@end table
15783
15784In unusual circumstances, you may have source files with extensions
15785not in the standard list. You can then set the extension associated
15786with a language explicitly:
15787
c906108c 15788@table @code
09d4efe1 15789@item set extension-language @var{ext} @var{language}
9c16f35a 15790@kindex set extension-language
09d4efe1
EZ
15791Tell @value{GDBN} that source files with extension @var{ext} are to be
15792assumed as written in the source language @var{language}.
c906108c
SS
15793
15794@item info extensions
9c16f35a 15795@kindex info extensions
c906108c
SS
15796List all the filename extensions and the associated languages.
15797@end table
15798
6d2ebf8b 15799@node Checks
79a6e687 15800@section Type and Range Checking
c906108c 15801
c906108c
SS
15802Some languages are designed to guard you against making seemingly common
15803errors through a series of compile- and run-time checks. These include
a451cb65 15804checking the type of arguments to functions and operators and making
c906108c
SS
15805sure mathematical overflows are caught at run time. Checks such as
15806these help to ensure a program's correctness once it has been compiled
a451cb65 15807by eliminating type mismatches and providing active checks for range
c906108c
SS
15808errors when your program is running.
15809
a451cb65
KS
15810By default @value{GDBN} checks for these errors according to the
15811rules of the current source language. Although @value{GDBN} does not check
15812the statements in your program, it can check expressions entered directly
15813into @value{GDBN} for evaluation via the @code{print} command, for example.
c906108c
SS
15814
15815@menu
15816* Type Checking:: An overview of type checking
15817* Range Checking:: An overview of range checking
15818@end menu
15819
15820@cindex type checking
15821@cindex checks, type
6d2ebf8b 15822@node Type Checking
79a6e687 15823@subsection An Overview of Type Checking
c906108c 15824
a451cb65 15825Some languages, such as C and C@t{++}, are strongly typed, meaning that the
c906108c
SS
15826arguments to operators and functions have to be of the correct type,
15827otherwise an error occurs. These checks prevent type mismatch
15828errors from ever causing any run-time problems. For example,
15829
15830@smallexample
a451cb65
KS
15831int klass::my_method(char *b) @{ return b ? 1 : 2; @}
15832
15833(@value{GDBP}) print obj.my_method (0)
15834$1 = 2
c906108c 15835@exdent but
a451cb65
KS
15836(@value{GDBP}) print obj.my_method (0x1234)
15837Cannot resolve method klass::my_method to any overloaded instance
c906108c
SS
15838@end smallexample
15839
a451cb65
KS
15840The second example fails because in C@t{++} the integer constant
15841@samp{0x1234} is not type-compatible with the pointer parameter type.
c906108c 15842
a451cb65
KS
15843For the expressions you use in @value{GDBN} commands, you can tell
15844@value{GDBN} to not enforce strict type checking or
5d161b24 15845to treat any mismatches as errors and abandon the expression;
a451cb65
KS
15846When type checking is disabled, @value{GDBN} successfully evaluates
15847expressions like the second example above.
c906108c 15848
a451cb65 15849Even if type checking is off, there may be other reasons
5d161b24
DB
15850related to type that prevent @value{GDBN} from evaluating an expression.
15851For instance, @value{GDBN} does not know how to add an @code{int} and
15852a @code{struct foo}. These particular type errors have nothing to do
a451cb65
KS
15853with the language in use and usually arise from expressions which make
15854little sense to evaluate anyway.
c906108c 15855
a451cb65 15856@value{GDBN} provides some additional commands for controlling type checking:
c906108c 15857
c906108c
SS
15858@kindex set check type
15859@kindex show check type
15860@table @code
c906108c
SS
15861@item set check type on
15862@itemx set check type off
a451cb65 15863Set strict type checking on or off. If any type mismatches occur in
d4f3574e 15864evaluating an expression while type checking is on, @value{GDBN} prints a
c906108c
SS
15865message and aborts evaluation of the expression.
15866
a451cb65
KS
15867@item show check type
15868Show the current setting of type checking and whether @value{GDBN}
15869is enforcing strict type checking rules.
c906108c
SS
15870@end table
15871
15872@cindex range checking
15873@cindex checks, range
6d2ebf8b 15874@node Range Checking
79a6e687 15875@subsection An Overview of Range Checking
c906108c
SS
15876
15877In some languages (such as Modula-2), it is an error to exceed the
15878bounds of a type; this is enforced with run-time checks. Such range
15879checking is meant to ensure program correctness by making sure
15880computations do not overflow, or indices on an array element access do
15881not exceed the bounds of the array.
15882
15883For expressions you use in @value{GDBN} commands, you can tell
15884@value{GDBN} to treat range errors in one of three ways: ignore them,
15885always treat them as errors and abandon the expression, or issue
15886warnings but evaluate the expression anyway.
15887
15888A range error can result from numerical overflow, from exceeding an
15889array index bound, or when you type a constant that is not a member
15890of any type. Some languages, however, do not treat overflows as an
15891error. In many implementations of C, mathematical overflow causes the
15892result to ``wrap around'' to lower values---for example, if @var{m} is
15893the largest integer value, and @var{s} is the smallest, then
15894
474c8240 15895@smallexample
c906108c 15896@var{m} + 1 @result{} @var{s}
474c8240 15897@end smallexample
c906108c
SS
15898
15899This, too, is specific to individual languages, and in some cases
79a6e687
BW
15900specific to individual compilers or machines. @xref{Supported Languages, ,
15901Supported Languages}, for further details on specific languages.
c906108c
SS
15902
15903@value{GDBN} provides some additional commands for controlling the range checker:
15904
c906108c
SS
15905@kindex set check range
15906@kindex show check range
15907@table @code
15908@item set check range auto
15909Set range checking on or off based on the current working language.
79a6e687 15910@xref{Supported Languages, ,Supported Languages}, for the default settings for
c906108c
SS
15911each language.
15912
15913@item set check range on
15914@itemx set check range off
15915Set range checking on or off, overriding the default setting for the
15916current working language. A warning is issued if the setting does not
c3f6f71d
JM
15917match the language default. If a range error occurs and range checking is on,
15918then a message is printed and evaluation of the expression is aborted.
c906108c
SS
15919
15920@item set check range warn
15921Output messages when the @value{GDBN} range checker detects a range error,
15922but attempt to evaluate the expression anyway. Evaluating the
15923expression may still be impossible for other reasons, such as accessing
15924memory that the process does not own (a typical example from many Unix
15925systems).
15926
15927@item show range
15928Show the current setting of the range checker, and whether or not it is
15929being set automatically by @value{GDBN}.
15930@end table
c906108c 15931
79a6e687
BW
15932@node Supported Languages
15933@section Supported Languages
c906108c 15934
9c37b5ae 15935@value{GDBN} supports C, C@t{++}, D, Go, Objective-C, Fortran,
0bdfa368 15936OpenCL C, Pascal, Rust, assembly, Modula-2, and Ada.
cce74817 15937@c This is false ...
c906108c
SS
15938Some @value{GDBN} features may be used in expressions regardless of the
15939language you use: the @value{GDBN} @code{@@} and @code{::} operators,
15940and the @samp{@{type@}addr} construct (@pxref{Expressions,
15941,Expressions}) can be used with the constructs of any supported
15942language.
15943
15944The following sections detail to what degree each source language is
15945supported by @value{GDBN}. These sections are not meant to be language
15946tutorials or references, but serve only as a reference guide to what the
15947@value{GDBN} expression parser accepts, and what input and output
15948formats should look like for different languages. There are many good
15949books written on each of these languages; please look to these for a
15950language reference or tutorial.
15951
c906108c 15952@menu
b37303ee 15953* C:: C and C@t{++}
6aecb9c2 15954* D:: D
a766d390 15955* Go:: Go
b383017d 15956* Objective-C:: Objective-C
f4b8a18d 15957* OpenCL C:: OpenCL C
09d4efe1 15958* Fortran:: Fortran
9c16f35a 15959* Pascal:: Pascal
0bdfa368 15960* Rust:: Rust
b37303ee 15961* Modula-2:: Modula-2
e07c999f 15962* Ada:: Ada
c906108c
SS
15963@end menu
15964
6d2ebf8b 15965@node C
b37052ae 15966@subsection C and C@t{++}
7a292a7a 15967
b37052ae
EZ
15968@cindex C and C@t{++}
15969@cindex expressions in C or C@t{++}
c906108c 15970
b37052ae 15971Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
c906108c
SS
15972to both languages. Whenever this is the case, we discuss those languages
15973together.
15974
41afff9a
EZ
15975@cindex C@t{++}
15976@cindex @code{g++}, @sc{gnu} C@t{++} compiler
b37052ae
EZ
15977@cindex @sc{gnu} C@t{++}
15978The C@t{++} debugging facilities are jointly implemented by the C@t{++}
15979compiler and @value{GDBN}. Therefore, to debug your C@t{++} code
15980effectively, you must compile your C@t{++} programs with a supported
15981C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
c906108c
SS
15982compiler (@code{aCC}).
15983
c906108c 15984@menu
b37052ae
EZ
15985* C Operators:: C and C@t{++} operators
15986* C Constants:: C and C@t{++} constants
79a6e687 15987* C Plus Plus Expressions:: C@t{++} expressions
b37052ae
EZ
15988* C Defaults:: Default settings for C and C@t{++}
15989* C Checks:: C and C@t{++} type and range checks
c906108c 15990* Debugging C:: @value{GDBN} and C
79a6e687 15991* Debugging C Plus Plus:: @value{GDBN} features for C@t{++}
febe4383 15992* Decimal Floating Point:: Numbers in Decimal Floating Point format
c906108c 15993@end menu
c906108c 15994
6d2ebf8b 15995@node C Operators
79a6e687 15996@subsubsection C and C@t{++} Operators
7a292a7a 15997
b37052ae 15998@cindex C and C@t{++} operators
c906108c
SS
15999
16000Operators must be defined on values of specific types. For instance,
16001@code{+} is defined on numbers, but not on structures. Operators are
5d161b24 16002often defined on groups of types.
c906108c 16003
b37052ae 16004For the purposes of C and C@t{++}, the following definitions hold:
c906108c
SS
16005
16006@itemize @bullet
53a5351d 16007
c906108c 16008@item
c906108c 16009@emph{Integral types} include @code{int} with any of its storage-class
b37052ae 16010specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
c906108c
SS
16011
16012@item
d4f3574e
SS
16013@emph{Floating-point types} include @code{float}, @code{double}, and
16014@code{long double} (if supported by the target platform).
c906108c
SS
16015
16016@item
53a5351d 16017@emph{Pointer types} include all types defined as @code{(@var{type} *)}.
c906108c
SS
16018
16019@item
16020@emph{Scalar types} include all of the above.
53a5351d 16021
c906108c
SS
16022@end itemize
16023
16024@noindent
16025The following operators are supported. They are listed here
16026in order of increasing precedence:
16027
16028@table @code
16029@item ,
16030The comma or sequencing operator. Expressions in a comma-separated list
16031are evaluated from left to right, with the result of the entire
16032expression being the last expression evaluated.
16033
16034@item =
16035Assignment. The value of an assignment expression is the value
16036assigned. Defined on scalar types.
16037
16038@item @var{op}=
16039Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
16040and translated to @w{@code{@var{a} = @var{a op b}}}.
697aa1b7 16041@w{@code{@var{op}=}} and @code{=} have the same precedence. The operator
c906108c
SS
16042@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
16043@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
16044
16045@item ?:
16046The ternary operator. @code{@var{a} ? @var{b} : @var{c}} can be thought
697aa1b7
EZ
16047of as: if @var{a} then @var{b} else @var{c}. The argument @var{a}
16048should be of an integral type.
c906108c
SS
16049
16050@item ||
16051Logical @sc{or}. Defined on integral types.
16052
16053@item &&
16054Logical @sc{and}. Defined on integral types.
16055
16056@item |
16057Bitwise @sc{or}. Defined on integral types.
16058
16059@item ^
16060Bitwise exclusive-@sc{or}. Defined on integral types.
16061
16062@item &
16063Bitwise @sc{and}. Defined on integral types.
16064
16065@item ==@r{, }!=
16066Equality and inequality. Defined on scalar types. The value of these
16067expressions is 0 for false and non-zero for true.
16068
16069@item <@r{, }>@r{, }<=@r{, }>=
16070Less than, greater than, less than or equal, greater than or equal.
16071Defined on scalar types. The value of these expressions is 0 for false
16072and non-zero for true.
16073
16074@item <<@r{, }>>
16075left shift, and right shift. Defined on integral types.
16076
16077@item @@
16078The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
16079
16080@item +@r{, }-
16081Addition and subtraction. Defined on integral types, floating-point types and
16082pointer types.
16083
16084@item *@r{, }/@r{, }%
16085Multiplication, division, and modulus. Multiplication and division are
16086defined on integral and floating-point types. Modulus is defined on
16087integral types.
16088
16089@item ++@r{, }--
16090Increment and decrement. When appearing before a variable, the
16091operation is performed before the variable is used in an expression;
16092when appearing after it, the variable's value is used before the
16093operation takes place.
16094
16095@item *
16096Pointer dereferencing. Defined on pointer types. Same precedence as
16097@code{++}.
16098
16099@item &
16100Address operator. Defined on variables. Same precedence as @code{++}.
16101
b37052ae
EZ
16102For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
16103allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
b17828ca 16104to examine the address
b37052ae 16105where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
c906108c 16106stored.
c906108c
SS
16107
16108@item -
16109Negative. Defined on integral and floating-point types. Same
16110precedence as @code{++}.
16111
16112@item !
16113Logical negation. Defined on integral types. Same precedence as
16114@code{++}.
16115
16116@item ~
16117Bitwise complement operator. Defined on integral types. Same precedence as
16118@code{++}.
16119
16120
16121@item .@r{, }->
16122Structure member, and pointer-to-structure member. For convenience,
16123@value{GDBN} regards the two as equivalent, choosing whether to dereference a
16124pointer based on the stored type information.
16125Defined on @code{struct} and @code{union} data.
16126
c906108c
SS
16127@item .*@r{, }->*
16128Dereferences of pointers to members.
c906108c
SS
16129
16130@item []
16131Array indexing. @code{@var{a}[@var{i}]} is defined as
16132@code{*(@var{a}+@var{i})}. Same precedence as @code{->}.
16133
16134@item ()
16135Function parameter list. Same precedence as @code{->}.
16136
c906108c 16137@item ::
b37052ae 16138C@t{++} scope resolution operator. Defined on @code{struct}, @code{union},
7a292a7a 16139and @code{class} types.
c906108c
SS
16140
16141@item ::
7a292a7a
SS
16142Doubled colons also represent the @value{GDBN} scope operator
16143(@pxref{Expressions, ,Expressions}). Same precedence as @code{::},
16144above.
c906108c
SS
16145@end table
16146
c906108c
SS
16147If an operator is redefined in the user code, @value{GDBN} usually
16148attempts to invoke the redefined version instead of using the operator's
16149predefined meaning.
c906108c 16150
6d2ebf8b 16151@node C Constants
79a6e687 16152@subsubsection C and C@t{++} Constants
c906108c 16153
b37052ae 16154@cindex C and C@t{++} constants
c906108c 16155
b37052ae 16156@value{GDBN} allows you to express the constants of C and C@t{++} in the
c906108c 16157following ways:
c906108c
SS
16158
16159@itemize @bullet
16160@item
16161Integer constants are a sequence of digits. Octal constants are
6ca652b0
EZ
16162specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
16163by a leading @samp{0x} or @samp{0X}. Constants may also end with a letter
c906108c
SS
16164@samp{l}, specifying that the constant should be treated as a
16165@code{long} value.
16166
16167@item
16168Floating point constants are a sequence of digits, followed by a decimal
16169point, followed by a sequence of digits, and optionally followed by an
16170exponent. An exponent is of the form:
16171@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
16172sequence of digits. The @samp{+} is optional for positive exponents.
d4f3574e
SS
16173A floating-point constant may also end with a letter @samp{f} or
16174@samp{F}, specifying that the constant should be treated as being of
16175the @code{float} (as opposed to the default @code{double}) type; or with
16176a letter @samp{l} or @samp{L}, which specifies a @code{long double}
16177constant.
c906108c
SS
16178
16179@item
16180Enumerated constants consist of enumerated identifiers, or their
16181integral equivalents.
16182
16183@item
16184Character constants are a single character surrounded by single quotes
16185(@code{'}), or a number---the ordinal value of the corresponding character
d4f3574e 16186(usually its @sc{ascii} value). Within quotes, the single character may
c906108c
SS
16187be represented by a letter or by @dfn{escape sequences}, which are of
16188the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
16189of the character's ordinal value; or of the form @samp{\@var{x}}, where
16190@samp{@var{x}} is a predefined special character---for example,
16191@samp{\n} for newline.
16192
e0f8f636
TT
16193Wide character constants can be written by prefixing a character
16194constant with @samp{L}, as in C. For example, @samp{L'x'} is the wide
16195form of @samp{x}. The target wide character set is used when
16196computing the value of this constant (@pxref{Character Sets}).
16197
c906108c 16198@item
96a2c332
SS
16199String constants are a sequence of character constants surrounded by
16200double quotes (@code{"}). Any valid character constant (as described
16201above) may appear. Double quotes within the string must be preceded by
16202a backslash, so for instance @samp{"a\"b'c"} is a string of five
16203characters.
c906108c 16204
e0f8f636
TT
16205Wide string constants can be written by prefixing a string constant
16206with @samp{L}, as in C. The target wide character set is used when
16207computing the value of this constant (@pxref{Character Sets}).
16208
c906108c
SS
16209@item
16210Pointer constants are an integral value. You can also write pointers
16211to constants using the C operator @samp{&}.
16212
16213@item
16214Array constants are comma-separated lists surrounded by braces @samp{@{}
16215and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
16216integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
16217and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
16218@end itemize
16219
79a6e687
BW
16220@node C Plus Plus Expressions
16221@subsubsection C@t{++} Expressions
b37052ae
EZ
16222
16223@cindex expressions in C@t{++}
16224@value{GDBN} expression handling can interpret most C@t{++} expressions.
16225
0179ffac
DC
16226@cindex debugging C@t{++} programs
16227@cindex C@t{++} compilers
16228@cindex debug formats and C@t{++}
16229@cindex @value{NGCC} and C@t{++}
c906108c 16230@quotation
e0f8f636
TT
16231@emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use
16232the proper compiler and the proper debug format. Currently,
16233@value{GDBN} works best when debugging C@t{++} code that is compiled
16234with the most recent version of @value{NGCC} possible. The DWARF
16235debugging format is preferred; @value{NGCC} defaults to this on most
16236popular platforms. Other compilers and/or debug formats are likely to
16237work badly or not at all when using @value{GDBN} to debug C@t{++}
16238code. @xref{Compilation}.
c906108c 16239@end quotation
c906108c
SS
16240
16241@enumerate
16242
16243@cindex member functions
16244@item
16245Member function calls are allowed; you can use expressions like
16246
474c8240 16247@smallexample
c906108c 16248count = aml->GetOriginal(x, y)
474c8240 16249@end smallexample
c906108c 16250
41afff9a 16251@vindex this@r{, inside C@t{++} member functions}
b37052ae 16252@cindex namespace in C@t{++}
c906108c
SS
16253@item
16254While a member function is active (in the selected stack frame), your
16255expressions have the same namespace available as the member function;
16256that is, @value{GDBN} allows implicit references to the class instance
e0f8f636
TT
16257pointer @code{this} following the same rules as C@t{++}. @code{using}
16258declarations in the current scope are also respected by @value{GDBN}.
c906108c 16259
c906108c 16260@cindex call overloaded functions
d4f3574e 16261@cindex overloaded functions, calling
b37052ae 16262@cindex type conversions in C@t{++}
c906108c
SS
16263@item
16264You can call overloaded functions; @value{GDBN} resolves the function
d4f3574e 16265call to the right definition, with some restrictions. @value{GDBN} does not
c906108c
SS
16266perform overload resolution involving user-defined type conversions,
16267calls to constructors, or instantiations of templates that do not exist
16268in the program. It also cannot handle ellipsis argument lists or
16269default arguments.
16270
16271It does perform integral conversions and promotions, floating-point
16272promotions, arithmetic conversions, pointer conversions, conversions of
16273class objects to base classes, and standard conversions such as those of
16274functions or arrays to pointers; it requires an exact match on the
16275number of function arguments.
16276
16277Overload resolution is always performed, unless you have specified
79a6e687
BW
16278@code{set overload-resolution off}. @xref{Debugging C Plus Plus,
16279,@value{GDBN} Features for C@t{++}}.
c906108c 16280
d4f3574e 16281You must specify @code{set overload-resolution off} in order to use an
c906108c
SS
16282explicit function signature to call an overloaded function, as in
16283@smallexample
16284p 'foo(char,int)'('x', 13)
16285@end smallexample
d4f3574e 16286
c906108c 16287The @value{GDBN} command-completion facility can simplify this;
79a6e687 16288see @ref{Completion, ,Command Completion}.
c906108c 16289
c906108c
SS
16290@cindex reference declarations
16291@item
c0f55cc6
AV
16292@value{GDBN} understands variables declared as C@t{++} lvalue or rvalue
16293references; you can use them in expressions just as you do in C@t{++}
16294source---they are automatically dereferenced.
c906108c
SS
16295
16296In the parameter list shown when @value{GDBN} displays a frame, the values of
16297reference variables are not displayed (unlike other variables); this
16298avoids clutter, since references are often used for large structures.
16299The @emph{address} of a reference variable is always shown, unless
16300you have specified @samp{set print address off}.
16301
16302@item
b37052ae 16303@value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
c906108c
SS
16304expressions can use it just as expressions in your program do. Since
16305one scope may be defined in another, you can use @code{::} repeatedly if
16306necessary, for example in an expression like
16307@samp{@var{scope1}::@var{scope2}::@var{name}}. @value{GDBN} also allows
b37052ae 16308resolving name scope by reference to source files, in both C and C@t{++}
79a6e687 16309debugging (@pxref{Variables, ,Program Variables}).
c906108c 16310
e0f8f636
TT
16311@item
16312@value{GDBN} performs argument-dependent lookup, following the C@t{++}
16313specification.
16314@end enumerate
c906108c 16315
6d2ebf8b 16316@node C Defaults
79a6e687 16317@subsubsection C and C@t{++} Defaults
7a292a7a 16318
b37052ae 16319@cindex C and C@t{++} defaults
c906108c 16320
a451cb65
KS
16321If you allow @value{GDBN} to set range checking automatically, it
16322defaults to @code{off} whenever the working language changes to
b37052ae 16323C or C@t{++}. This happens regardless of whether you or @value{GDBN}
c906108c 16324selects the working language.
c906108c
SS
16325
16326If you allow @value{GDBN} to set the language automatically, it
16327recognizes source files whose names end with @file{.c}, @file{.C}, or
16328@file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
b37052ae 16329these files, it sets the working language to C or C@t{++}.
79a6e687 16330@xref{Automatically, ,Having @value{GDBN} Infer the Source Language},
c906108c
SS
16331for further details.
16332
6d2ebf8b 16333@node C Checks
79a6e687 16334@subsubsection C and C@t{++} Type and Range Checks
7a292a7a 16335
b37052ae 16336@cindex C and C@t{++} checks
c906108c 16337
a451cb65
KS
16338By default, when @value{GDBN} parses C or C@t{++} expressions, strict type
16339checking is used. However, if you turn type checking off, @value{GDBN}
16340will allow certain non-standard conversions, such as promoting integer
16341constants to pointers.
c906108c
SS
16342
16343Range checking, if turned on, is done on mathematical operations. Array
16344indices are not checked, since they are often used to index a pointer
16345that is not itself an array.
c906108c 16346
6d2ebf8b 16347@node Debugging C
c906108c 16348@subsubsection @value{GDBN} and C
c906108c
SS
16349
16350The @code{set print union} and @code{show print union} commands apply to
16351the @code{union} type. When set to @samp{on}, any @code{union} that is
7a292a7a
SS
16352inside a @code{struct} or @code{class} is also printed. Otherwise, it
16353appears as @samp{@{...@}}.
c906108c
SS
16354
16355The @code{@@} operator aids in the debugging of dynamic arrays, formed
16356with pointers and a memory allocation function. @xref{Expressions,
16357,Expressions}.
16358
79a6e687
BW
16359@node Debugging C Plus Plus
16360@subsubsection @value{GDBN} Features for C@t{++}
c906108c 16361
b37052ae 16362@cindex commands for C@t{++}
7a292a7a 16363
b37052ae
EZ
16364Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
16365designed specifically for use with C@t{++}. Here is a summary:
c906108c
SS
16366
16367@table @code
16368@cindex break in overloaded functions
16369@item @r{breakpoint menus}
16370When you want a breakpoint in a function whose name is overloaded,
6ba66d6a
JB
16371@value{GDBN} has the capability to display a menu of possible breakpoint
16372locations to help you specify which function definition you want.
16373@xref{Ambiguous Expressions,,Ambiguous Expressions}.
c906108c 16374
b37052ae 16375@cindex overloading in C@t{++}
c906108c
SS
16376@item rbreak @var{regex}
16377Setting breakpoints using regular expressions is helpful for setting
16378breakpoints on overloaded functions that are not members of any special
16379classes.
79a6e687 16380@xref{Set Breaks, ,Setting Breakpoints}.
c906108c 16381
b37052ae 16382@cindex C@t{++} exception handling
c906108c 16383@item catch throw
591f19e8 16384@itemx catch rethrow
c906108c 16385@itemx catch catch
b37052ae 16386Debug C@t{++} exception handling using these commands. @xref{Set
79a6e687 16387Catchpoints, , Setting Catchpoints}.
c906108c
SS
16388
16389@cindex inheritance
16390@item ptype @var{typename}
16391Print inheritance relationships as well as other information for type
16392@var{typename}.
16393@xref{Symbols, ,Examining the Symbol Table}.
16394
c4aeac85
TT
16395@item info vtbl @var{expression}.
16396The @code{info vtbl} command can be used to display the virtual
16397method tables of the object computed by @var{expression}. This shows
16398one entry per virtual table; there may be multiple virtual tables when
16399multiple inheritance is in use.
16400
439250fb
DE
16401@cindex C@t{++} demangling
16402@item demangle @var{name}
16403Demangle @var{name}.
16404@xref{Symbols}, for a more complete description of the @code{demangle} command.
16405
b37052ae 16406@cindex C@t{++} symbol display
c906108c
SS
16407@item set print demangle
16408@itemx show print demangle
16409@itemx set print asm-demangle
16410@itemx show print asm-demangle
b37052ae
EZ
16411Control whether C@t{++} symbols display in their source form, both when
16412displaying code as C@t{++} source and when displaying disassemblies.
79a6e687 16413@xref{Print Settings, ,Print Settings}.
c906108c
SS
16414
16415@item set print object
16416@itemx show print object
16417Choose whether to print derived (actual) or declared types of objects.
79a6e687 16418@xref{Print Settings, ,Print Settings}.
c906108c
SS
16419
16420@item set print vtbl
16421@itemx show print vtbl
16422Control the format for printing virtual function tables.
79a6e687 16423@xref{Print Settings, ,Print Settings}.
c906108c 16424(The @code{vtbl} commands do not work on programs compiled with the HP
b37052ae 16425ANSI C@t{++} compiler (@code{aCC}).)
c906108c
SS
16426
16427@kindex set overload-resolution
d4f3574e 16428@cindex overloaded functions, overload resolution
c906108c 16429@item set overload-resolution on
b37052ae 16430Enable overload resolution for C@t{++} expression evaluation. The default
c906108c
SS
16431is on. For overloaded functions, @value{GDBN} evaluates the arguments
16432and searches for a function whose signature matches the argument types,
79a6e687
BW
16433using the standard C@t{++} conversion rules (see @ref{C Plus Plus
16434Expressions, ,C@t{++} Expressions}, for details).
16435If it cannot find a match, it emits a message.
c906108c
SS
16436
16437@item set overload-resolution off
b37052ae 16438Disable overload resolution for C@t{++} expression evaluation. For
c906108c
SS
16439overloaded functions that are not class member functions, @value{GDBN}
16440chooses the first function of the specified name that it finds in the
16441symbol table, whether or not its arguments are of the correct type. For
16442overloaded functions that are class member functions, @value{GDBN}
16443searches for a function whose signature @emph{exactly} matches the
16444argument types.
c906108c 16445
9c16f35a
EZ
16446@kindex show overload-resolution
16447@item show overload-resolution
16448Show the current setting of overload resolution.
16449
c906108c
SS
16450@item @r{Overloaded symbol names}
16451You can specify a particular definition of an overloaded symbol, using
b37052ae 16452the same notation that is used to declare such symbols in C@t{++}: type
c906108c
SS
16453@code{@var{symbol}(@var{types})} rather than just @var{symbol}. You can
16454also use the @value{GDBN} command-line word completion facilities to list the
16455available choices, or to finish the type list for you.
79a6e687 16456@xref{Completion,, Command Completion}, for details on how to do this.
bd69330d
PA
16457
16458@item @r{Breakpoints in functions with ABI tags}
16459
16460The GNU C@t{++} compiler introduced the notion of ABI ``tags'', which
16461correspond to changes in the ABI of a type, function, or variable that
16462would not otherwise be reflected in a mangled name. See
16463@url{https://developers.redhat.com/blog/2015/02/05/gcc5-and-the-c11-abi/}
16464for more detail.
16465
16466The ABI tags are visible in C@t{++} demangled names. For example, a
16467function that returns a std::string:
16468
16469@smallexample
16470std::string function(int);
16471@end smallexample
16472
16473@noindent
16474when compiled for the C++11 ABI is marked with the @code{cxx11} ABI
16475tag, and @value{GDBN} displays the symbol like this:
16476
16477@smallexample
16478function[abi:cxx11](int)
16479@end smallexample
16480
16481You can set a breakpoint on such functions simply as if they had no
16482tag. For example:
16483
16484@smallexample
16485(gdb) b function(int)
16486Breakpoint 2 at 0x40060d: file main.cc, line 10.
16487(gdb) info breakpoints
16488Num Type Disp Enb Address What
164891 breakpoint keep y 0x0040060d in function[abi:cxx11](int)
16490 at main.cc:10
16491@end smallexample
16492
16493On the rare occasion you need to disambiguate between different ABI
16494tags, you can do so by simply including the ABI tag in the function
16495name, like:
16496
16497@smallexample
16498(@value{GDBP}) b ambiguous[abi:other_tag](int)
16499@end smallexample
c906108c 16500@end table
c906108c 16501
febe4383
TJB
16502@node Decimal Floating Point
16503@subsubsection Decimal Floating Point format
16504@cindex decimal floating point format
16505
16506@value{GDBN} can examine, set and perform computations with numbers in
16507decimal floating point format, which in the C language correspond to the
16508@code{_Decimal32}, @code{_Decimal64} and @code{_Decimal128} types as
16509specified by the extension to support decimal floating-point arithmetic.
16510
16511There are two encodings in use, depending on the architecture: BID (Binary
16512Integer Decimal) for x86 and x86-64, and DPD (Densely Packed Decimal) for
4ac33720
UW
16513PowerPC and S/390. @value{GDBN} will use the appropriate encoding for the
16514configured target.
febe4383
TJB
16515
16516Because of a limitation in @file{libdecnumber}, the library used by @value{GDBN}
16517to manipulate decimal floating point numbers, it is not possible to convert
16518(using a cast, for example) integers wider than 32-bit to decimal float.
16519
16520In addition, in order to imitate @value{GDBN}'s behaviour with binary floating
16521point computations, error checking in decimal float operations ignores
16522underflow, overflow and divide by zero exceptions.
16523
4acd40f3 16524In the PowerPC architecture, @value{GDBN} provides a set of pseudo-registers
99e008fe
EZ
16525to inspect @code{_Decimal128} values stored in floating point registers.
16526See @ref{PowerPC,,PowerPC} for more details.
4acd40f3 16527
6aecb9c2
JB
16528@node D
16529@subsection D
16530
16531@cindex D
16532@value{GDBN} can be used to debug programs written in D and compiled with
16533GDC, LDC or DMD compilers. Currently @value{GDBN} supports only one D
16534specific feature --- dynamic arrays.
16535
a766d390
DE
16536@node Go
16537@subsection Go
16538
16539@cindex Go (programming language)
16540@value{GDBN} can be used to debug programs written in Go and compiled with
16541@file{gccgo} or @file{6g} compilers.
16542
16543Here is a summary of the Go-specific features and restrictions:
16544
16545@table @code
16546@cindex current Go package
16547@item The current Go package
16548The name of the current package does not need to be specified when
16549specifying global variables and functions.
16550
16551For example, given the program:
16552
16553@example
16554package main
16555var myglob = "Shall we?"
16556func main () @{
16557 // ...
16558@}
16559@end example
16560
16561When stopped inside @code{main} either of these work:
16562
16563@example
16564(gdb) p myglob
16565(gdb) p main.myglob
16566@end example
16567
16568@cindex builtin Go types
16569@item Builtin Go types
16570The @code{string} type is recognized by @value{GDBN} and is printed
16571as a string.
16572
16573@cindex builtin Go functions
16574@item Builtin Go functions
16575The @value{GDBN} expression parser recognizes the @code{unsafe.Sizeof}
16576function and handles it internally.
a766d390
DE
16577
16578@cindex restrictions on Go expressions
16579@item Restrictions on Go expressions
16580All Go operators are supported except @code{&^}.
16581The Go @code{_} ``blank identifier'' is not supported.
16582Automatic dereferencing of pointers is not supported.
50f042b9 16583@end table
a766d390 16584
b37303ee
AF
16585@node Objective-C
16586@subsection Objective-C
16587
16588@cindex Objective-C
16589This section provides information about some commands and command
721c2651
EZ
16590options that are useful for debugging Objective-C code. See also
16591@ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
16592few more commands specific to Objective-C support.
b37303ee
AF
16593
16594@menu
b383017d
RM
16595* Method Names in Commands::
16596* The Print Command with Objective-C::
b37303ee
AF
16597@end menu
16598
c8f4133a 16599@node Method Names in Commands
b37303ee
AF
16600@subsubsection Method Names in Commands
16601
16602The following commands have been extended to accept Objective-C method
16603names as line specifications:
16604
16605@kindex clear@r{, and Objective-C}
16606@kindex break@r{, and Objective-C}
16607@kindex info line@r{, and Objective-C}
16608@kindex jump@r{, and Objective-C}
16609@kindex list@r{, and Objective-C}
16610@itemize
16611@item @code{clear}
16612@item @code{break}
16613@item @code{info line}
16614@item @code{jump}
16615@item @code{list}
16616@end itemize
16617
16618A fully qualified Objective-C method name is specified as
16619
16620@smallexample
16621-[@var{Class} @var{methodName}]
16622@end smallexample
16623
c552b3bb
JM
16624where the minus sign is used to indicate an instance method and a
16625plus sign (not shown) is used to indicate a class method. The class
16626name @var{Class} and method name @var{methodName} are enclosed in
16627brackets, similar to the way messages are specified in Objective-C
16628source code. For example, to set a breakpoint at the @code{create}
16629instance method of class @code{Fruit} in the program currently being
16630debugged, enter:
b37303ee
AF
16631
16632@smallexample
16633break -[Fruit create]
16634@end smallexample
16635
16636To list ten program lines around the @code{initialize} class method,
16637enter:
16638
16639@smallexample
16640list +[NSText initialize]
16641@end smallexample
16642
c552b3bb
JM
16643In the current version of @value{GDBN}, the plus or minus sign is
16644required. In future versions of @value{GDBN}, the plus or minus
16645sign will be optional, but you can use it to narrow the search. It
16646is also possible to specify just a method name:
b37303ee
AF
16647
16648@smallexample
16649break create
16650@end smallexample
16651
16652You must specify the complete method name, including any colons. If
16653your program's source files contain more than one @code{create} method,
16654you'll be presented with a numbered list of classes that implement that
16655method. Indicate your choice by number, or type @samp{0} to exit if
16656none apply.
16657
16658As another example, to clear a breakpoint established at the
16659@code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
16660
16661@smallexample
16662clear -[NSWindow makeKeyAndOrderFront:]
16663@end smallexample
16664
16665@node The Print Command with Objective-C
16666@subsubsection The Print Command With Objective-C
721c2651 16667@cindex Objective-C, print objects
c552b3bb
JM
16668@kindex print-object
16669@kindex po @r{(@code{print-object})}
b37303ee 16670
c552b3bb 16671The print command has also been extended to accept methods. For example:
b37303ee
AF
16672
16673@smallexample
c552b3bb 16674print -[@var{object} hash]
b37303ee
AF
16675@end smallexample
16676
16677@cindex print an Objective-C object description
c552b3bb
JM
16678@cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
16679@noindent
16680will tell @value{GDBN} to send the @code{hash} message to @var{object}
16681and print the result. Also, an additional command has been added,
16682@code{print-object} or @code{po} for short, which is meant to print
16683the description of an object. However, this command may only work
16684with certain Objective-C libraries that have a particular hook
16685function, @code{_NSPrintForDebugger}, defined.
b37303ee 16686
f4b8a18d
KW
16687@node OpenCL C
16688@subsection OpenCL C
16689
16690@cindex OpenCL C
16691This section provides information about @value{GDBN}s OpenCL C support.
16692
16693@menu
16694* OpenCL C Datatypes::
16695* OpenCL C Expressions::
16696* OpenCL C Operators::
16697@end menu
16698
16699@node OpenCL C Datatypes
16700@subsubsection OpenCL C Datatypes
16701
16702@cindex OpenCL C Datatypes
16703@value{GDBN} supports the builtin scalar and vector datatypes specified
16704by OpenCL 1.1. In addition the half- and double-precision floating point
16705data types of the @code{cl_khr_fp16} and @code{cl_khr_fp64} OpenCL
16706extensions are also known to @value{GDBN}.
16707
16708@node OpenCL C Expressions
16709@subsubsection OpenCL C Expressions
16710
16711@cindex OpenCL C Expressions
16712@value{GDBN} supports accesses to vector components including the access as
16713lvalue where possible. Since OpenCL C is based on C99 most C expressions
16714supported by @value{GDBN} can be used as well.
16715
16716@node OpenCL C Operators
16717@subsubsection OpenCL C Operators
16718
16719@cindex OpenCL C Operators
16720@value{GDBN} supports the operators specified by OpenCL 1.1 for scalar and
16721vector data types.
16722
09d4efe1
EZ
16723@node Fortran
16724@subsection Fortran
16725@cindex Fortran-specific support in @value{GDBN}
16726
814e32d7
WZ
16727@value{GDBN} can be used to debug programs written in Fortran, but it
16728currently supports only the features of Fortran 77 language.
16729
16730@cindex trailing underscore, in Fortran symbols
16731Some Fortran compilers (@sc{gnu} Fortran 77 and Fortran 95 compilers
16732among them) append an underscore to the names of variables and
16733functions. When you debug programs compiled by those compilers, you
16734will need to refer to variables and functions with a trailing
16735underscore.
16736
16737@menu
16738* Fortran Operators:: Fortran operators and expressions
16739* Fortran Defaults:: Default settings for Fortran
79a6e687 16740* Special Fortran Commands:: Special @value{GDBN} commands for Fortran
814e32d7
WZ
16741@end menu
16742
16743@node Fortran Operators
79a6e687 16744@subsubsection Fortran Operators and Expressions
814e32d7
WZ
16745
16746@cindex Fortran operators and expressions
16747
16748Operators must be defined on values of specific types. For instance,
16749@code{+} is defined on numbers, but not on characters or other non-
ff2587ec 16750arithmetic types. Operators are often defined on groups of types.
814e32d7
WZ
16751
16752@table @code
16753@item **
99e008fe 16754The exponentiation operator. It raises the first operand to the power
814e32d7
WZ
16755of the second one.
16756
16757@item :
16758The range operator. Normally used in the form of array(low:high) to
16759represent a section of array.
68837c9d
MD
16760
16761@item %
16762The access component operator. Normally used to access elements in derived
16763types. Also suitable for unions. As unions aren't part of regular Fortran,
16764this can only happen when accessing a register that uses a gdbarch-defined
16765union type.
0a4b0913
AB
16766@item ::
16767The scope operator. Normally used to access variables in modules or
16768to set breakpoints on subroutines nested in modules or in other
16769subroutines (internal subroutines).
814e32d7
WZ
16770@end table
16771
16772@node Fortran Defaults
16773@subsubsection Fortran Defaults
16774
16775@cindex Fortran Defaults
16776
16777Fortran symbols are usually case-insensitive, so @value{GDBN} by
16778default uses case-insensitive matches for Fortran symbols. You can
16779change that with the @samp{set case-insensitive} command, see
16780@ref{Symbols}, for the details.
16781
79a6e687
BW
16782@node Special Fortran Commands
16783@subsubsection Special Fortran Commands
814e32d7
WZ
16784
16785@cindex Special Fortran commands
16786
db2e3e2e
BW
16787@value{GDBN} has some commands to support Fortran-specific features,
16788such as displaying common blocks.
814e32d7 16789
09d4efe1
EZ
16790@table @code
16791@cindex @code{COMMON} blocks, Fortran
16792@kindex info common
16793@item info common @r{[}@var{common-name}@r{]}
16794This command prints the values contained in the Fortran @code{COMMON}
16795block whose name is @var{common-name}. With no argument, the names of
d52fb0e9 16796all @code{COMMON} blocks visible at the current program location are
09d4efe1
EZ
16797printed.
16798@end table
16799
9c16f35a
EZ
16800@node Pascal
16801@subsection Pascal
16802
16803@cindex Pascal support in @value{GDBN}, limitations
16804Debugging Pascal programs which use sets, subranges, file variables, or
16805nested functions does not currently work. @value{GDBN} does not support
16806entering expressions, printing values, or similar features using Pascal
16807syntax.
16808
16809The Pascal-specific command @code{set print pascal_static-members}
16810controls whether static members of Pascal objects are displayed.
16811@xref{Print Settings, pascal_static-members}.
16812
0bdfa368
TT
16813@node Rust
16814@subsection Rust
16815
16816@value{GDBN} supports the @url{https://www.rust-lang.org/, Rust
16817Programming Language}. Type- and value-printing, and expression
16818parsing, are reasonably complete. However, there are a few
16819peculiarities and holes to be aware of.
16820
16821@itemize @bullet
16822@item
16823Linespecs (@pxref{Specify Location}) are never relative to the current
16824crate. Instead, they act as if there were a global namespace of
16825crates, somewhat similar to the way @code{extern crate} behaves.
16826
16827That is, if @value{GDBN} is stopped at a breakpoint in a function in
16828crate @samp{A}, module @samp{B}, then @code{break B::f} will attempt
16829to set a breakpoint in a function named @samp{f} in a crate named
16830@samp{B}.
16831
16832As a consequence of this approach, linespecs also cannot refer to
16833items using @samp{self::} or @samp{super::}.
16834
16835@item
16836Because @value{GDBN} implements Rust name-lookup semantics in
16837expressions, it will sometimes prepend the current crate to a name.
16838For example, if @value{GDBN} is stopped at a breakpoint in the crate
16839@samp{K}, then @code{print ::x::y} will try to find the symbol
16840@samp{K::x::y}.
16841
16842However, since it is useful to be able to refer to other crates when
16843debugging, @value{GDBN} provides the @code{extern} extension to
16844circumvent this. To use the extension, just put @code{extern} before
16845a path expression to refer to the otherwise unavailable ``global''
16846scope.
16847
16848In the above example, if you wanted to refer to the symbol @samp{y} in
16849the crate @samp{x}, you would use @code{print extern x::y}.
16850
16851@item
16852The Rust expression evaluator does not support ``statement-like''
16853expressions such as @code{if} or @code{match}, or lambda expressions.
16854
16855@item
16856Tuple expressions are not implemented.
16857
16858@item
16859The Rust expression evaluator does not currently implement the
16860@code{Drop} trait. Objects that may be created by the evaluator will
16861never be destroyed.
16862
16863@item
16864@value{GDBN} does not implement type inference for generics. In order
16865to call generic functions or otherwise refer to generic items, you
16866will have to specify the type parameters manually.
16867
16868@item
16869@value{GDBN} currently uses the C@t{++} demangler for Rust. In most
16870cases this does not cause any problems. However, in an expression
16871context, completing a generic function name will give syntactically
16872invalid results. This happens because Rust requires the @samp{::}
16873operator between the function name and its generic arguments. For
16874example, @value{GDBN} might provide a completion like
16875@code{crate::f<u32>}, where the parser would require
16876@code{crate::f::<u32>}.
16877
16878@item
16879As of this writing, the Rust compiler (version 1.8) has a few holes in
16880the debugging information it generates. These holes prevent certain
16881features from being implemented by @value{GDBN}:
16882@itemize @bullet
16883
16884@item
16885Method calls cannot be made via traits.
16886
0bdfa368
TT
16887@item
16888Operator overloading is not implemented.
16889
16890@item
16891When debugging in a monomorphized function, you cannot use the generic
16892type names.
16893
16894@item
16895The type @code{Self} is not available.
16896
16897@item
16898@code{use} statements are not available, so some names may not be
16899available in the crate.
16900@end itemize
16901@end itemize
16902
09d4efe1 16903@node Modula-2
c906108c 16904@subsection Modula-2
7a292a7a 16905
d4f3574e 16906@cindex Modula-2, @value{GDBN} support
c906108c
SS
16907
16908The extensions made to @value{GDBN} to support Modula-2 only support
16909output from the @sc{gnu} Modula-2 compiler (which is currently being
16910developed). Other Modula-2 compilers are not currently supported, and
16911attempting to debug executables produced by them is most likely
16912to give an error as @value{GDBN} reads in the executable's symbol
16913table.
16914
16915@cindex expressions in Modula-2
16916@menu
16917* M2 Operators:: Built-in operators
16918* Built-In Func/Proc:: Built-in functions and procedures
16919* M2 Constants:: Modula-2 constants
72019c9c 16920* M2 Types:: Modula-2 types
c906108c
SS
16921* M2 Defaults:: Default settings for Modula-2
16922* Deviations:: Deviations from standard Modula-2
16923* M2 Checks:: Modula-2 type and range checks
16924* M2 Scope:: The scope operators @code{::} and @code{.}
16925* GDB/M2:: @value{GDBN} and Modula-2
16926@end menu
16927
6d2ebf8b 16928@node M2 Operators
c906108c
SS
16929@subsubsection Operators
16930@cindex Modula-2 operators
16931
16932Operators must be defined on values of specific types. For instance,
16933@code{+} is defined on numbers, but not on structures. Operators are
16934often defined on groups of types. For the purposes of Modula-2, the
16935following definitions hold:
16936
16937@itemize @bullet
16938
16939@item
16940@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
16941their subranges.
16942
16943@item
16944@emph{Character types} consist of @code{CHAR} and its subranges.
16945
16946@item
16947@emph{Floating-point types} consist of @code{REAL}.
16948
16949@item
16950@emph{Pointer types} consist of anything declared as @code{POINTER TO
16951@var{type}}.
16952
16953@item
16954@emph{Scalar types} consist of all of the above.
16955
16956@item
16957@emph{Set types} consist of @code{SET} and @code{BITSET} types.
16958
16959@item
16960@emph{Boolean types} consist of @code{BOOLEAN}.
16961@end itemize
16962
16963@noindent
16964The following operators are supported, and appear in order of
16965increasing precedence:
16966
16967@table @code
16968@item ,
16969Function argument or array index separator.
16970
16971@item :=
16972Assignment. The value of @var{var} @code{:=} @var{value} is
16973@var{value}.
16974
16975@item <@r{, }>
16976Less than, greater than on integral, floating-point, or enumerated
16977types.
16978
16979@item <=@r{, }>=
96a2c332 16980Less than or equal to, greater than or equal to
c906108c
SS
16981on integral, floating-point and enumerated types, or set inclusion on
16982set types. Same precedence as @code{<}.
16983
16984@item =@r{, }<>@r{, }#
16985Equality and two ways of expressing inequality, valid on scalar types.
16986Same precedence as @code{<}. In @value{GDBN} scripts, only @code{<>} is
16987available for inequality, since @code{#} conflicts with the script
16988comment character.
16989
16990@item IN
16991Set membership. Defined on set types and the types of their members.
16992Same precedence as @code{<}.
16993
16994@item OR
16995Boolean disjunction. Defined on boolean types.
16996
16997@item AND@r{, }&
d4f3574e 16998Boolean conjunction. Defined on boolean types.
c906108c
SS
16999
17000@item @@
17001The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
17002
17003@item +@r{, }-
17004Addition and subtraction on integral and floating-point types, or union
17005and difference on set types.
17006
17007@item *
17008Multiplication on integral and floating-point types, or set intersection
17009on set types.
17010
17011@item /
17012Division on floating-point types, or symmetric set difference on set
17013types. Same precedence as @code{*}.
17014
17015@item DIV@r{, }MOD
17016Integer division and remainder. Defined on integral types. Same
17017precedence as @code{*}.
17018
17019@item -
99e008fe 17020Negative. Defined on @code{INTEGER} and @code{REAL} data.
c906108c
SS
17021
17022@item ^
17023Pointer dereferencing. Defined on pointer types.
17024
17025@item NOT
17026Boolean negation. Defined on boolean types. Same precedence as
17027@code{^}.
17028
17029@item .
17030@code{RECORD} field selector. Defined on @code{RECORD} data. Same
17031precedence as @code{^}.
17032
17033@item []
17034Array indexing. Defined on @code{ARRAY} data. Same precedence as @code{^}.
17035
17036@item ()
17037Procedure argument list. Defined on @code{PROCEDURE} objects. Same precedence
17038as @code{^}.
17039
17040@item ::@r{, }.
17041@value{GDBN} and Modula-2 scope operators.
17042@end table
17043
17044@quotation
72019c9c 17045@emph{Warning:} Set expressions and their operations are not yet supported, so @value{GDBN}
c906108c
SS
17046treats the use of the operator @code{IN}, or the use of operators
17047@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
17048@code{<=}, and @code{>=} on sets as an error.
17049@end quotation
17050
cb51c4e0 17051
6d2ebf8b 17052@node Built-In Func/Proc
79a6e687 17053@subsubsection Built-in Functions and Procedures
cb51c4e0 17054@cindex Modula-2 built-ins
c906108c
SS
17055
17056Modula-2 also makes available several built-in procedures and functions.
17057In describing these, the following metavariables are used:
17058
17059@table @var
17060
17061@item a
17062represents an @code{ARRAY} variable.
17063
17064@item c
17065represents a @code{CHAR} constant or variable.
17066
17067@item i
17068represents a variable or constant of integral type.
17069
17070@item m
17071represents an identifier that belongs to a set. Generally used in the
17072same function with the metavariable @var{s}. The type of @var{s} should
17073be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
17074
17075@item n
17076represents a variable or constant of integral or floating-point type.
17077
17078@item r
17079represents a variable or constant of floating-point type.
17080
17081@item t
17082represents a type.
17083
17084@item v
17085represents a variable.
17086
17087@item x
17088represents a variable or constant of one of many types. See the
17089explanation of the function for details.
17090@end table
17091
17092All Modula-2 built-in procedures also return a result, described below.
17093
17094@table @code
17095@item ABS(@var{n})
17096Returns the absolute value of @var{n}.
17097
17098@item CAP(@var{c})
17099If @var{c} is a lower case letter, it returns its upper case
c3f6f71d 17100equivalent, otherwise it returns its argument.
c906108c
SS
17101
17102@item CHR(@var{i})
17103Returns the character whose ordinal value is @var{i}.
17104
17105@item DEC(@var{v})
c3f6f71d 17106Decrements the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
17107
17108@item DEC(@var{v},@var{i})
17109Decrements the value in the variable @var{v} by @var{i}. Returns the
17110new value.
17111
17112@item EXCL(@var{m},@var{s})
17113Removes the element @var{m} from the set @var{s}. Returns the new
17114set.
17115
17116@item FLOAT(@var{i})
17117Returns the floating point equivalent of the integer @var{i}.
17118
17119@item HIGH(@var{a})
17120Returns the index of the last member of @var{a}.
17121
17122@item INC(@var{v})
c3f6f71d 17123Increments the value in the variable @var{v} by one. Returns the new value.
c906108c
SS
17124
17125@item INC(@var{v},@var{i})
17126Increments the value in the variable @var{v} by @var{i}. Returns the
17127new value.
17128
17129@item INCL(@var{m},@var{s})
17130Adds the element @var{m} to the set @var{s} if it is not already
17131there. Returns the new set.
17132
17133@item MAX(@var{t})
17134Returns the maximum value of the type @var{t}.
17135
17136@item MIN(@var{t})
17137Returns the minimum value of the type @var{t}.
17138
17139@item ODD(@var{i})
17140Returns boolean TRUE if @var{i} is an odd number.
17141
17142@item ORD(@var{x})
17143Returns the ordinal value of its argument. For example, the ordinal
697aa1b7
EZ
17144value of a character is its @sc{ascii} value (on machines supporting
17145the @sc{ascii} character set). The argument @var{x} must be of an
17146ordered type, which include integral, character and enumerated types.
c906108c
SS
17147
17148@item SIZE(@var{x})
697aa1b7
EZ
17149Returns the size of its argument. The argument @var{x} can be a
17150variable or a type.
c906108c
SS
17151
17152@item TRUNC(@var{r})
17153Returns the integral part of @var{r}.
17154
844781a1 17155@item TSIZE(@var{x})
697aa1b7
EZ
17156Returns the size of its argument. The argument @var{x} can be a
17157variable or a type.
844781a1 17158
c906108c
SS
17159@item VAL(@var{t},@var{i})
17160Returns the member of the type @var{t} whose ordinal value is @var{i}.
17161@end table
17162
17163@quotation
17164@emph{Warning:} Sets and their operations are not yet supported, so
17165@value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
17166an error.
17167@end quotation
17168
17169@cindex Modula-2 constants
6d2ebf8b 17170@node M2 Constants
c906108c
SS
17171@subsubsection Constants
17172
17173@value{GDBN} allows you to express the constants of Modula-2 in the following
17174ways:
17175
17176@itemize @bullet
17177
17178@item
17179Integer constants are simply a sequence of digits. When used in an
17180expression, a constant is interpreted to be type-compatible with the
17181rest of the expression. Hexadecimal integers are specified by a
17182trailing @samp{H}, and octal integers by a trailing @samp{B}.
17183
17184@item
17185Floating point constants appear as a sequence of digits, followed by a
17186decimal point and another sequence of digits. An optional exponent can
17187then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
17188@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent. All of the
17189digits of the floating point constant must be valid decimal (base 10)
17190digits.
17191
17192@item
17193Character constants consist of a single character enclosed by a pair of
17194like quotes, either single (@code{'}) or double (@code{"}). They may
c3f6f71d 17195also be expressed by their ordinal value (their @sc{ascii} value, usually)
c906108c
SS
17196followed by a @samp{C}.
17197
17198@item
17199String constants consist of a sequence of characters enclosed by a
17200pair of like quotes, either single (@code{'}) or double (@code{"}).
17201Escape sequences in the style of C are also allowed. @xref{C
79a6e687 17202Constants, ,C and C@t{++} Constants}, for a brief explanation of escape
c906108c
SS
17203sequences.
17204
17205@item
17206Enumerated constants consist of an enumerated identifier.
17207
17208@item
17209Boolean constants consist of the identifiers @code{TRUE} and
17210@code{FALSE}.
17211
17212@item
17213Pointer constants consist of integral values only.
17214
17215@item
17216Set constants are not yet supported.
17217@end itemize
17218
72019c9c
GM
17219@node M2 Types
17220@subsubsection Modula-2 Types
17221@cindex Modula-2 types
17222
17223Currently @value{GDBN} can print the following data types in Modula-2
17224syntax: array types, record types, set types, pointer types, procedure
17225types, enumerated types, subrange types and base types. You can also
17226print the contents of variables declared using these type.
17227This section gives a number of simple source code examples together with
17228sample @value{GDBN} sessions.
17229
17230The first example contains the following section of code:
17231
17232@smallexample
17233VAR
17234 s: SET OF CHAR ;
17235 r: [20..40] ;
17236@end smallexample
17237
17238@noindent
17239and you can request @value{GDBN} to interrogate the type and value of
17240@code{r} and @code{s}.
17241
17242@smallexample
17243(@value{GDBP}) print s
17244@{'A'..'C', 'Z'@}
17245(@value{GDBP}) ptype s
17246SET OF CHAR
17247(@value{GDBP}) print r
1724821
17249(@value{GDBP}) ptype r
17250[20..40]
17251@end smallexample
17252
17253@noindent
17254Likewise if your source code declares @code{s} as:
17255
17256@smallexample
17257VAR
17258 s: SET ['A'..'Z'] ;
17259@end smallexample
17260
17261@noindent
17262then you may query the type of @code{s} by:
17263
17264@smallexample
17265(@value{GDBP}) ptype s
17266type = SET ['A'..'Z']
17267@end smallexample
17268
17269@noindent
17270Note that at present you cannot interactively manipulate set
17271expressions using the debugger.
17272
17273The following example shows how you might declare an array in Modula-2
17274and how you can interact with @value{GDBN} to print its type and contents:
17275
17276@smallexample
17277VAR
17278 s: ARRAY [-10..10] OF CHAR ;
17279@end smallexample
17280
17281@smallexample
17282(@value{GDBP}) ptype s
17283ARRAY [-10..10] OF CHAR
17284@end smallexample
17285
17286Note that the array handling is not yet complete and although the type
17287is printed correctly, expression handling still assumes that all
17288arrays have a lower bound of zero and not @code{-10} as in the example
844781a1 17289above.
72019c9c
GM
17290
17291Here are some more type related Modula-2 examples:
17292
17293@smallexample
17294TYPE
17295 colour = (blue, red, yellow, green) ;
17296 t = [blue..yellow] ;
17297VAR
17298 s: t ;
17299BEGIN
17300 s := blue ;
17301@end smallexample
17302
17303@noindent
17304The @value{GDBN} interaction shows how you can query the data type
17305and value of a variable.
17306
17307@smallexample
17308(@value{GDBP}) print s
17309$1 = blue
17310(@value{GDBP}) ptype t
17311type = [blue..yellow]
17312@end smallexample
17313
17314@noindent
17315In this example a Modula-2 array is declared and its contents
17316displayed. Observe that the contents are written in the same way as
17317their @code{C} counterparts.
17318
17319@smallexample
17320VAR
17321 s: ARRAY [1..5] OF CARDINAL ;
17322BEGIN
17323 s[1] := 1 ;
17324@end smallexample
17325
17326@smallexample
17327(@value{GDBP}) print s
17328$1 = @{1, 0, 0, 0, 0@}
17329(@value{GDBP}) ptype s
17330type = ARRAY [1..5] OF CARDINAL
17331@end smallexample
17332
17333The Modula-2 language interface to @value{GDBN} also understands
17334pointer types as shown in this example:
17335
17336@smallexample
17337VAR
17338 s: POINTER TO ARRAY [1..5] OF CARDINAL ;
17339BEGIN
17340 NEW(s) ;
17341 s^[1] := 1 ;
17342@end smallexample
17343
17344@noindent
17345and you can request that @value{GDBN} describes the type of @code{s}.
17346
17347@smallexample
17348(@value{GDBP}) ptype s
17349type = POINTER TO ARRAY [1..5] OF CARDINAL
17350@end smallexample
17351
17352@value{GDBN} handles compound types as we can see in this example.
17353Here we combine array types, record types, pointer types and subrange
17354types:
17355
17356@smallexample
17357TYPE
17358 foo = RECORD
17359 f1: CARDINAL ;
17360 f2: CHAR ;
17361 f3: myarray ;
17362 END ;
17363
17364 myarray = ARRAY myrange OF CARDINAL ;
17365 myrange = [-2..2] ;
17366VAR
17367 s: POINTER TO ARRAY myrange OF foo ;
17368@end smallexample
17369
17370@noindent
17371and you can ask @value{GDBN} to describe the type of @code{s} as shown
17372below.
17373
17374@smallexample
17375(@value{GDBP}) ptype s
17376type = POINTER TO ARRAY [-2..2] OF foo = RECORD
17377 f1 : CARDINAL;
17378 f2 : CHAR;
17379 f3 : ARRAY [-2..2] OF CARDINAL;
17380END
17381@end smallexample
17382
6d2ebf8b 17383@node M2 Defaults
79a6e687 17384@subsubsection Modula-2 Defaults
c906108c
SS
17385@cindex Modula-2 defaults
17386
17387If type and range checking are set automatically by @value{GDBN}, they
17388both default to @code{on} whenever the working language changes to
d4f3574e 17389Modula-2. This happens regardless of whether you or @value{GDBN}
c906108c
SS
17390selected the working language.
17391
17392If you allow @value{GDBN} to set the language automatically, then entering
17393code compiled from a file whose name ends with @file{.mod} sets the
79a6e687
BW
17394working language to Modula-2. @xref{Automatically, ,Having @value{GDBN}
17395Infer the Source Language}, for further details.
c906108c 17396
6d2ebf8b 17397@node Deviations
79a6e687 17398@subsubsection Deviations from Standard Modula-2
c906108c
SS
17399@cindex Modula-2, deviations from
17400
17401A few changes have been made to make Modula-2 programs easier to debug.
17402This is done primarily via loosening its type strictness:
17403
17404@itemize @bullet
17405@item
17406Unlike in standard Modula-2, pointer constants can be formed by
17407integers. This allows you to modify pointer variables during
17408debugging. (In standard Modula-2, the actual address contained in a
17409pointer variable is hidden from you; it can only be modified
17410through direct assignment to another pointer variable or expression that
17411returned a pointer.)
17412
17413@item
17414C escape sequences can be used in strings and characters to represent
17415non-printable characters. @value{GDBN} prints out strings with these
17416escape sequences embedded. Single non-printable characters are
17417printed using the @samp{CHR(@var{nnn})} format.
17418
17419@item
17420The assignment operator (@code{:=}) returns the value of its right-hand
17421argument.
17422
17423@item
17424All built-in procedures both modify @emph{and} return their argument.
17425@end itemize
17426
6d2ebf8b 17427@node M2 Checks
79a6e687 17428@subsubsection Modula-2 Type and Range Checks
c906108c
SS
17429@cindex Modula-2 checks
17430
17431@quotation
17432@emph{Warning:} in this release, @value{GDBN} does not yet perform type or
17433range checking.
17434@end quotation
17435@c FIXME remove warning when type/range checks added
17436
17437@value{GDBN} considers two Modula-2 variables type equivalent if:
17438
17439@itemize @bullet
17440@item
17441They are of types that have been declared equivalent via a @code{TYPE
17442@var{t1} = @var{t2}} statement
17443
17444@item
17445They have been declared on the same line. (Note: This is true of the
17446@sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
17447@end itemize
17448
17449As long as type checking is enabled, any attempt to combine variables
17450whose types are not equivalent is an error.
17451
17452Range checking is done on all mathematical operations, assignment, array
17453index bounds, and all built-in functions and procedures.
17454
6d2ebf8b 17455@node M2 Scope
79a6e687 17456@subsubsection The Scope Operators @code{::} and @code{.}
c906108c 17457@cindex scope
41afff9a 17458@cindex @code{.}, Modula-2 scope operator
c906108c
SS
17459@cindex colon, doubled as scope operator
17460@ifinfo
41afff9a 17461@vindex colon-colon@r{, in Modula-2}
c906108c
SS
17462@c Info cannot handle :: but TeX can.
17463@end ifinfo
a67ec3f4 17464@ifnotinfo
41afff9a 17465@vindex ::@r{, in Modula-2}
a67ec3f4 17466@end ifnotinfo
c906108c
SS
17467
17468There are a few subtle differences between the Modula-2 scope operator
17469(@code{.}) and the @value{GDBN} scope operator (@code{::}). The two have
17470similar syntax:
17471
474c8240 17472@smallexample
c906108c
SS
17473
17474@var{module} . @var{id}
17475@var{scope} :: @var{id}
474c8240 17476@end smallexample
c906108c
SS
17477
17478@noindent
17479where @var{scope} is the name of a module or a procedure,
17480@var{module} the name of a module, and @var{id} is any declared
17481identifier within your program, except another module.
17482
17483Using the @code{::} operator makes @value{GDBN} search the scope
17484specified by @var{scope} for the identifier @var{id}. If it is not
17485found in the specified scope, then @value{GDBN} searches all scopes
17486enclosing the one specified by @var{scope}.
17487
17488Using the @code{.} operator makes @value{GDBN} search the current scope for
17489the identifier specified by @var{id} that was imported from the
17490definition module specified by @var{module}. With this operator, it is
17491an error if the identifier @var{id} was not imported from definition
17492module @var{module}, or if @var{id} is not an identifier in
17493@var{module}.
17494
6d2ebf8b 17495@node GDB/M2
c906108c
SS
17496@subsubsection @value{GDBN} and Modula-2
17497
17498Some @value{GDBN} commands have little use when debugging Modula-2 programs.
17499Five subcommands of @code{set print} and @code{show print} apply
b37052ae 17500specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
c906108c 17501@samp{asm-demangle}, @samp{object}, and @samp{union}. The first four
b37052ae 17502apply to C@t{++}, and the last to the C @code{union} type, which has no direct
c906108c
SS
17503analogue in Modula-2.
17504
17505The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
d4f3574e 17506with any language, is not useful with Modula-2. Its
c906108c 17507intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
b37052ae 17508created in Modula-2 as they can in C or C@t{++}. However, because an
c906108c 17509address can be specified by an integral constant, the construct
d4f3574e 17510@samp{@{@var{type}@}@var{adrexp}} is still useful.
c906108c
SS
17511
17512@cindex @code{#} in Modula-2
17513In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
17514interpreted as the beginning of a comment. Use @code{<>} instead.
c906108c 17515
e07c999f
PH
17516@node Ada
17517@subsection Ada
17518@cindex Ada
17519
17520The extensions made to @value{GDBN} for Ada only support
17521output from the @sc{gnu} Ada (GNAT) compiler.
17522Other Ada compilers are not currently supported, and
17523attempting to debug executables produced by them is most likely
17524to be difficult.
17525
17526
17527@cindex expressions in Ada
17528@menu
17529* Ada Mode Intro:: General remarks on the Ada syntax
17530 and semantics supported by Ada mode
17531 in @value{GDBN}.
17532* Omissions from Ada:: Restrictions on the Ada expression syntax.
17533* Additions to Ada:: Extensions of the Ada expression syntax.
3685b09f
PMR
17534* Overloading support for Ada:: Support for expressions involving overloaded
17535 subprograms.
e07c999f 17536* Stopping Before Main Program:: Debugging the program during elaboration.
58d06528 17537* Ada Exceptions:: Ada Exceptions
20924a55
JB
17538* Ada Tasks:: Listing and setting breakpoints in tasks.
17539* Ada Tasks and Core Files:: Tasking Support when Debugging Core Files
6e1bb179
JB
17540* Ravenscar Profile:: Tasking Support when using the Ravenscar
17541 Profile
3fcded8f 17542* Ada Settings:: New settable GDB parameters for Ada.
e07c999f
PH
17543* Ada Glitches:: Known peculiarities of Ada mode.
17544@end menu
17545
17546@node Ada Mode Intro
17547@subsubsection Introduction
17548@cindex Ada mode, general
17549
17550The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
17551syntax, with some extensions.
17552The philosophy behind the design of this subset is
17553
17554@itemize @bullet
17555@item
17556That @value{GDBN} should provide basic literals and access to operations for
17557arithmetic, dereferencing, field selection, indexing, and subprogram calls,
17558leaving more sophisticated computations to subprograms written into the
17559program (which therefore may be called from @value{GDBN}).
17560
17561@item
17562That type safety and strict adherence to Ada language restrictions
17563are not particularly important to the @value{GDBN} user.
17564
17565@item
17566That brevity is important to the @value{GDBN} user.
17567@end itemize
17568
f3a2dd1a
JB
17569Thus, for brevity, the debugger acts as if all names declared in
17570user-written packages are directly visible, even if they are not visible
17571according to Ada rules, thus making it unnecessary to fully qualify most
17572names with their packages, regardless of context. Where this causes
17573ambiguity, @value{GDBN} asks the user's intent.
e07c999f
PH
17574
17575The debugger will start in Ada mode if it detects an Ada main program.
17576As for other languages, it will enter Ada mode when stopped in a program that
17577was translated from an Ada source file.
17578
17579While in Ada mode, you may use `@t{--}' for comments. This is useful
17580mostly for documenting command files. The standard @value{GDBN} comment
17581(@samp{#}) still works at the beginning of a line in Ada mode, but not in the
17582middle (to allow based literals).
17583
e07c999f
PH
17584@node Omissions from Ada
17585@subsubsection Omissions from Ada
17586@cindex Ada, omissions from
17587
17588Here are the notable omissions from the subset:
17589
17590@itemize @bullet
17591@item
17592Only a subset of the attributes are supported:
17593
17594@itemize @minus
17595@item
17596@t{'First}, @t{'Last}, and @t{'Length}
17597 on array objects (not on types and subtypes).
17598
17599@item
17600@t{'Min} and @t{'Max}.
17601
17602@item
17603@t{'Pos} and @t{'Val}.
17604
17605@item
17606@t{'Tag}.
17607
17608@item
17609@t{'Range} on array objects (not subtypes), but only as the right
17610operand of the membership (@code{in}) operator.
17611
17612@item
17613@t{'Access}, @t{'Unchecked_Access}, and
17614@t{'Unrestricted_Access} (a GNAT extension).
17615
17616@item
17617@t{'Address}.
17618@end itemize
17619
17620@item
17621The names in
17622@code{Characters.Latin_1} are not available and
17623concatenation is not implemented. Thus, escape characters in strings are
17624not currently available.
17625
17626@item
17627Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
17628equality of representations. They will generally work correctly
17629for strings and arrays whose elements have integer or enumeration types.
17630They may not work correctly for arrays whose element
17631types have user-defined equality, for arrays of real values
17632(in particular, IEEE-conformant floating point, because of negative
17633zeroes and NaNs), and for arrays whose elements contain unused bits with
17634indeterminate values.
17635
17636@item
17637The other component-by-component array operations (@code{and}, @code{or},
17638@code{xor}, @code{not}, and relational tests other than equality)
17639are not implemented.
17640
17641@item
860701dc
PH
17642@cindex array aggregates (Ada)
17643@cindex record aggregates (Ada)
17644@cindex aggregates (Ada)
17645There is limited support for array and record aggregates. They are
17646permitted only on the right sides of assignments, as in these examples:
17647
17648@smallexample
077e0a52
JB
17649(@value{GDBP}) set An_Array := (1, 2, 3, 4, 5, 6)
17650(@value{GDBP}) set An_Array := (1, others => 0)
17651(@value{GDBP}) set An_Array := (0|4 => 1, 1..3 => 2, 5 => 6)
17652(@value{GDBP}) set A_2D_Array := ((1, 2, 3), (4, 5, 6), (7, 8, 9))
17653(@value{GDBP}) set A_Record := (1, "Peter", True);
17654(@value{GDBP}) set A_Record := (Name => "Peter", Id => 1, Alive => True)
860701dc
PH
17655@end smallexample
17656
17657Changing a
17658discriminant's value by assigning an aggregate has an
17659undefined effect if that discriminant is used within the record.
17660However, you can first modify discriminants by directly assigning to
17661them (which normally would not be allowed in Ada), and then performing an
17662aggregate assignment. For example, given a variable @code{A_Rec}
17663declared to have a type such as:
17664
17665@smallexample
17666type Rec (Len : Small_Integer := 0) is record
17667 Id : Integer;
17668 Vals : IntArray (1 .. Len);
17669end record;
17670@end smallexample
17671
17672you can assign a value with a different size of @code{Vals} with two
17673assignments:
17674
17675@smallexample
077e0a52
JB
17676(@value{GDBP}) set A_Rec.Len := 4
17677(@value{GDBP}) set A_Rec := (Id => 42, Vals => (1, 2, 3, 4))
860701dc
PH
17678@end smallexample
17679
17680As this example also illustrates, @value{GDBN} is very loose about the usual
17681rules concerning aggregates. You may leave out some of the
17682components of an array or record aggregate (such as the @code{Len}
17683component in the assignment to @code{A_Rec} above); they will retain their
17684original values upon assignment. You may freely use dynamic values as
17685indices in component associations. You may even use overlapping or
17686redundant component associations, although which component values are
17687assigned in such cases is not defined.
e07c999f
PH
17688
17689@item
17690Calls to dispatching subprograms are not implemented.
17691
17692@item
17693The overloading algorithm is much more limited (i.e., less selective)
ae21e955
BW
17694than that of real Ada. It makes only limited use of the context in
17695which a subexpression appears to resolve its meaning, and it is much
17696looser in its rules for allowing type matches. As a result, some
17697function calls will be ambiguous, and the user will be asked to choose
17698the proper resolution.
e07c999f
PH
17699
17700@item
17701The @code{new} operator is not implemented.
17702
17703@item
17704Entry calls are not implemented.
17705
17706@item
17707Aside from printing, arithmetic operations on the native VAX floating-point
17708formats are not supported.
17709
17710@item
17711It is not possible to slice a packed array.
158c7665
PH
17712
17713@item
17714The names @code{True} and @code{False}, when not part of a qualified name,
17715are interpreted as if implicitly prefixed by @code{Standard}, regardless of
17716context.
17717Should your program
17718redefine these names in a package or procedure (at best a dubious practice),
17719you will have to use fully qualified names to access their new definitions.
e07c999f
PH
17720@end itemize
17721
17722@node Additions to Ada
17723@subsubsection Additions to Ada
17724@cindex Ada, deviations from
17725
17726As it does for other languages, @value{GDBN} makes certain generic
17727extensions to Ada (@pxref{Expressions}):
17728
17729@itemize @bullet
17730@item
ae21e955
BW
17731If the expression @var{E} is a variable residing in memory (typically
17732a local variable or array element) and @var{N} is a positive integer,
17733then @code{@var{E}@@@var{N}} displays the values of @var{E} and the
17734@var{N}-1 adjacent variables following it in memory as an array. In
17735Ada, this operator is generally not necessary, since its prime use is
17736in displaying parts of an array, and slicing will usually do this in
17737Ada. However, there are occasional uses when debugging programs in
17738which certain debugging information has been optimized away.
e07c999f
PH
17739
17740@item
ae21e955
BW
17741@code{@var{B}::@var{var}} means ``the variable named @var{var} that
17742appears in function or file @var{B}.'' When @var{B} is a file name,
17743you must typically surround it in single quotes.
e07c999f
PH
17744
17745@item
17746The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
17747@var{type} that appears at address @var{addr}.''
17748
17749@item
17750A name starting with @samp{$} is a convenience variable
17751(@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
17752@end itemize
17753
ae21e955
BW
17754In addition, @value{GDBN} provides a few other shortcuts and outright
17755additions specific to Ada:
e07c999f
PH
17756
17757@itemize @bullet
17758@item
17759The assignment statement is allowed as an expression, returning
17760its right-hand operand as its value. Thus, you may enter
17761
17762@smallexample
077e0a52
JB
17763(@value{GDBP}) set x := y + 3
17764(@value{GDBP}) print A(tmp := y + 1)
e07c999f
PH
17765@end smallexample
17766
17767@item
17768The semicolon is allowed as an ``operator,'' returning as its value
17769the value of its right-hand operand.
17770This allows, for example,
17771complex conditional breaks:
17772
17773@smallexample
077e0a52
JB
17774(@value{GDBP}) break f
17775(@value{GDBP}) condition 1 (report(i); k += 1; A(k) > 100)
e07c999f
PH
17776@end smallexample
17777
17778@item
17779Rather than use catenation and symbolic character names to introduce special
17780characters into strings, one may instead use a special bracket notation,
17781which is also used to print strings. A sequence of characters of the form
17782@samp{["@var{XX}"]} within a string or character literal denotes the
17783(single) character whose numeric encoding is @var{XX} in hexadecimal. The
17784sequence of characters @samp{["""]} also denotes a single quotation mark
17785in strings. For example,
17786@smallexample
17787 "One line.["0a"]Next line.["0a"]"
17788@end smallexample
17789@noindent
ae21e955
BW
17790contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF})
17791after each period.
e07c999f
PH
17792
17793@item
17794The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
17795@t{'Max} is optional (and is ignored in any case). For example, it is valid
17796to write
17797
17798@smallexample
077e0a52 17799(@value{GDBP}) print 'max(x, y)
e07c999f
PH
17800@end smallexample
17801
17802@item
17803When printing arrays, @value{GDBN} uses positional notation when the
17804array has a lower bound of 1, and uses a modified named notation otherwise.
ae21e955
BW
17805For example, a one-dimensional array of three integers with a lower bound
17806of 3 might print as
e07c999f
PH
17807
17808@smallexample
17809(3 => 10, 17, 1)
17810@end smallexample
17811
17812@noindent
17813That is, in contrast to valid Ada, only the first component has a @code{=>}
17814clause.
17815
17816@item
17817You may abbreviate attributes in expressions with any unique,
17818multi-character subsequence of
17819their names (an exact match gets preference).
17820For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
17821in place of @t{a'length}.
17822
17823@item
17824@cindex quoting Ada internal identifiers
17825Since Ada is case-insensitive, the debugger normally maps identifiers you type
17826to lower case. The GNAT compiler uses upper-case characters for
17827some of its internal identifiers, which are normally of no interest to users.
17828For the rare occasions when you actually have to look at them,
17829enclose them in angle brackets to avoid the lower-case mapping.
17830For example,
17831@smallexample
077e0a52 17832(@value{GDBP}) print <JMPBUF_SAVE>[0]
e07c999f
PH
17833@end smallexample
17834
17835@item
17836Printing an object of class-wide type or dereferencing an
17837access-to-class-wide value will display all the components of the object's
17838specific type (as indicated by its run-time tag). Likewise, component
17839selection on such a value will operate on the specific type of the
17840object.
17841
17842@end itemize
17843
3685b09f
PMR
17844@node Overloading support for Ada
17845@subsubsection Overloading support for Ada
17846@cindex overloading, Ada
17847
17848The debugger supports limited overloading. Given a subprogram call in which
17849the function symbol has multiple definitions, it will use the number of
17850actual parameters and some information about their types to attempt to narrow
17851the set of definitions. It also makes very limited use of context, preferring
17852procedures to functions in the context of the @code{call} command, and
17853functions to procedures elsewhere.
17854
17855If, after narrowing, the set of matching definitions still contains more than
17856one definition, @value{GDBN} will display a menu to query which one it should
17857use, for instance:
17858
17859@smallexample
17860(@value{GDBP}) print f(1)
17861Multiple matches for f
17862[0] cancel
17863[1] foo.f (integer) return boolean at foo.adb:23
17864[2] foo.f (foo.new_integer) return boolean at foo.adb:28
17865>
17866@end smallexample
17867
17868In this case, just select one menu entry either to cancel expression evaluation
17869(type @kbd{0} and press @key{RET}) or to continue evaluation with a specific
17870instance (type the corresponding number and press @key{RET}).
17871
17872Here are a couple of commands to customize @value{GDBN}'s behavior in this
17873case:
17874
17875@table @code
17876
17877@kindex set ada print-signatures
17878@item set ada print-signatures
17879Control whether parameter types and return types are displayed in overloads
17880selection menus. It is @code{on} by default.
17881@xref{Overloading support for Ada}.
17882
17883@kindex show ada print-signatures
17884@item show ada print-signatures
17885Show the current setting for displaying parameter types and return types in
17886overloads selection menu.
17887@xref{Overloading support for Ada}.
17888
17889@end table
17890
e07c999f
PH
17891@node Stopping Before Main Program
17892@subsubsection Stopping at the Very Beginning
17893
17894@cindex breakpointing Ada elaboration code
17895It is sometimes necessary to debug the program during elaboration, and
17896before reaching the main procedure.
17897As defined in the Ada Reference
17898Manual, the elaboration code is invoked from a procedure called
17899@code{adainit}. To run your program up to the beginning of
17900elaboration, simply use the following two commands:
17901@code{tbreak adainit} and @code{run}.
17902
58d06528
JB
17903@node Ada Exceptions
17904@subsubsection Ada Exceptions
17905
17906A command is provided to list all Ada exceptions:
17907
17908@table @code
17909@kindex info exceptions
17910@item info exceptions
17911@itemx info exceptions @var{regexp}
17912The @code{info exceptions} command allows you to list all Ada exceptions
17913defined within the program being debugged, as well as their addresses.
17914With a regular expression, @var{regexp}, as argument, only those exceptions
17915whose names match @var{regexp} are listed.
17916@end table
17917
17918Below is a small example, showing how the command can be used, first
17919without argument, and next with a regular expression passed as an
17920argument.
17921
17922@smallexample
17923(@value{GDBP}) info exceptions
17924All defined Ada exceptions:
17925constraint_error: 0x613da0
17926program_error: 0x613d20
17927storage_error: 0x613ce0
17928tasking_error: 0x613ca0
17929const.aint_global_e: 0x613b00
17930(@value{GDBP}) info exceptions const.aint
17931All Ada exceptions matching regular expression "const.aint":
17932constraint_error: 0x613da0
17933const.aint_global_e: 0x613b00
17934@end smallexample
17935
17936It is also possible to ask @value{GDBN} to stop your program's execution
17937when an exception is raised. For more details, see @ref{Set Catchpoints}.
17938
20924a55
JB
17939@node Ada Tasks
17940@subsubsection Extensions for Ada Tasks
17941@cindex Ada, tasking
17942
17943Support for Ada tasks is analogous to that for threads (@pxref{Threads}).
17944@value{GDBN} provides the following task-related commands:
17945
17946@table @code
17947@kindex info tasks
17948@item info tasks
17949This command shows a list of current Ada tasks, as in the following example:
17950
17951
17952@smallexample
17953@iftex
17954@leftskip=0.5cm
17955@end iftex
17956(@value{GDBP}) info tasks
17957 ID TID P-ID Pri State Name
17958 1 8088000 0 15 Child Activation Wait main_task
17959 2 80a4000 1 15 Accept Statement b
17960 3 809a800 1 15 Child Activation Wait a
32cd1edc 17961* 4 80ae800 3 15 Runnable c
20924a55
JB
17962
17963@end smallexample
17964
17965@noindent
17966In this listing, the asterisk before the last task indicates it to be the
17967task currently being inspected.
17968
17969@table @asis
17970@item ID
17971Represents @value{GDBN}'s internal task number.
17972
17973@item TID
17974The Ada task ID.
17975
17976@item P-ID
17977The parent's task ID (@value{GDBN}'s internal task number).
17978
17979@item Pri
17980The base priority of the task.
17981
17982@item State
17983Current state of the task.
17984
17985@table @code
17986@item Unactivated
17987The task has been created but has not been activated. It cannot be
17988executing.
17989
20924a55
JB
17990@item Runnable
17991The task is not blocked for any reason known to Ada. (It may be waiting
17992for a mutex, though.) It is conceptually "executing" in normal mode.
17993
17994@item Terminated
17995The task is terminated, in the sense of ARM 9.3 (5). Any dependents
17996that were waiting on terminate alternatives have been awakened and have
17997terminated themselves.
17998
17999@item Child Activation Wait
18000The task is waiting for created tasks to complete activation.
18001
18002@item Accept Statement
18003The task is waiting on an accept or selective wait statement.
18004
18005@item Waiting on entry call
18006The task is waiting on an entry call.
18007
18008@item Async Select Wait
18009The task is waiting to start the abortable part of an asynchronous
18010select statement.
18011
18012@item Delay Sleep
18013The task is waiting on a select statement with only a delay
18014alternative open.
18015
18016@item Child Termination Wait
18017The task is sleeping having completed a master within itself, and is
18018waiting for the tasks dependent on that master to become terminated or
18019waiting on a terminate Phase.
18020
18021@item Wait Child in Term Alt
18022The task is sleeping waiting for tasks on terminate alternatives to
18023finish terminating.
18024
18025@item Accepting RV with @var{taskno}
18026The task is accepting a rendez-vous with the task @var{taskno}.
18027@end table
18028
18029@item Name
18030Name of the task in the program.
18031
18032@end table
18033
18034@kindex info task @var{taskno}
18035@item info task @var{taskno}
6b92c0d3 18036This command shows detailed informations on the specified task, as in
20924a55
JB
18037the following example:
18038@smallexample
18039@iftex
18040@leftskip=0.5cm
18041@end iftex
18042(@value{GDBP}) info tasks
18043 ID TID P-ID Pri State Name
18044 1 8077880 0 15 Child Activation Wait main_task
32cd1edc 18045* 2 807c468 1 15 Runnable task_1
20924a55
JB
18046(@value{GDBP}) info task 2
18047Ada Task: 0x807c468
4993045d 18048Name: "task_1"
87f7ab7b
JB
18049Thread: 0
18050LWP: 0x1fac
4993045d 18051Parent: 1 ("main_task")
20924a55
JB
18052Base Priority: 15
18053State: Runnable
18054@end smallexample
18055
18056@item task
18057@kindex task@r{ (Ada)}
18058@cindex current Ada task ID
4993045d 18059This command prints the ID and name of the current task.
20924a55
JB
18060
18061@smallexample
18062@iftex
18063@leftskip=0.5cm
18064@end iftex
18065(@value{GDBP}) info tasks
18066 ID TID P-ID Pri State Name
18067 1 8077870 0 15 Child Activation Wait main_task
4993045d 18068* 2 807c458 1 15 Runnable some_task
20924a55 18069(@value{GDBP}) task
4993045d 18070[Current task is 2 "some_task"]
20924a55
JB
18071@end smallexample
18072
18073@item task @var{taskno}
18074@cindex Ada task switching
5d5658a1 18075This command is like the @code{thread @var{thread-id}}
20924a55
JB
18076command (@pxref{Threads}). It switches the context of debugging
18077from the current task to the given task.
18078
18079@smallexample
18080@iftex
18081@leftskip=0.5cm
18082@end iftex
18083(@value{GDBP}) info tasks
18084 ID TID P-ID Pri State Name
18085 1 8077870 0 15 Child Activation Wait main_task
4993045d 18086* 2 807c458 1 15 Runnable some_task
20924a55 18087(@value{GDBP}) task 1
4993045d 18088[Switching to task 1 "main_task"]
20924a55
JB
18089#0 0x8067726 in pthread_cond_wait ()
18090(@value{GDBP}) bt
18091#0 0x8067726 in pthread_cond_wait ()
18092#1 0x8056714 in system.os_interface.pthread_cond_wait ()
18093#2 0x805cb63 in system.task_primitives.operations.sleep ()
18094#3 0x806153e in system.tasking.stages.activate_tasks ()
18095#4 0x804aacc in un () at un.adb:5
18096@end smallexample
18097
629500fa
KS
18098@item break @var{location} task @var{taskno}
18099@itemx break @var{location} task @var{taskno} if @dots{}
45ac276d
JB
18100@cindex breakpoints and tasks, in Ada
18101@cindex task breakpoints, in Ada
18102@kindex break @dots{} task @var{taskno}@r{ (Ada)}
18103These commands are like the @code{break @dots{} thread @dots{}}
697aa1b7 18104command (@pxref{Thread Stops}). The
629500fa 18105@var{location} argument specifies source lines, as described
45ac276d
JB
18106in @ref{Specify Location}.
18107
18108Use the qualifier @samp{task @var{taskno}} with a breakpoint command
18109to specify that you only want @value{GDBN} to stop the program when a
697aa1b7 18110particular Ada task reaches this breakpoint. The @var{taskno} is one of the
45ac276d
JB
18111numeric task identifiers assigned by @value{GDBN}, shown in the first
18112column of the @samp{info tasks} display.
18113
18114If you do not specify @samp{task @var{taskno}} when you set a
18115breakpoint, the breakpoint applies to @emph{all} tasks of your
18116program.
18117
18118You can use the @code{task} qualifier on conditional breakpoints as
18119well; in this case, place @samp{task @var{taskno}} before the
18120breakpoint condition (before the @code{if}).
18121
18122For example,
18123
18124@smallexample
18125@iftex
18126@leftskip=0.5cm
18127@end iftex
18128(@value{GDBP}) info tasks
18129 ID TID P-ID Pri State Name
18130 1 140022020 0 15 Child Activation Wait main_task
18131 2 140045060 1 15 Accept/Select Wait t2
18132 3 140044840 1 15 Runnable t1
18133* 4 140056040 1 15 Runnable t3
18134(@value{GDBP}) b 15 task 2
18135Breakpoint 5 at 0x120044cb0: file test_task_debug.adb, line 15.
18136(@value{GDBP}) cont
18137Continuing.
18138task # 1 running
18139task # 2 running
18140
18141Breakpoint 5, test_task_debug () at test_task_debug.adb:15
1814215 flush;
18143(@value{GDBP}) info tasks
18144 ID TID P-ID Pri State Name
18145 1 140022020 0 15 Child Activation Wait main_task
18146* 2 140045060 1 15 Runnable t2
18147 3 140044840 1 15 Runnable t1
18148 4 140056040 1 15 Delay Sleep t3
18149@end smallexample
20924a55
JB
18150@end table
18151
18152@node Ada Tasks and Core Files
18153@subsubsection Tasking Support when Debugging Core Files
18154@cindex Ada tasking and core file debugging
18155
18156When inspecting a core file, as opposed to debugging a live program,
18157tasking support may be limited or even unavailable, depending on
18158the platform being used.
18159For instance, on x86-linux, the list of tasks is available, but task
32a8097b 18160switching is not supported.
20924a55 18161
32a8097b 18162On certain platforms, the debugger needs to perform some
20924a55
JB
18163memory writes in order to provide Ada tasking support. When inspecting
18164a core file, this means that the core file must be opened with read-write
18165privileges, using the command @samp{"set write on"} (@pxref{Patching}).
18166Under these circumstances, you should make a backup copy of the core
18167file before inspecting it with @value{GDBN}.
18168
6e1bb179
JB
18169@node Ravenscar Profile
18170@subsubsection Tasking Support when using the Ravenscar Profile
18171@cindex Ravenscar Profile
18172
18173The @dfn{Ravenscar Profile} is a subset of the Ada tasking features,
18174specifically designed for systems with safety-critical real-time
18175requirements.
18176
18177@table @code
18178@kindex set ravenscar task-switching on
18179@cindex task switching with program using Ravenscar Profile
18180@item set ravenscar task-switching on
18181Allows task switching when debugging a program that uses the Ravenscar
18182Profile. This is the default.
18183
18184@kindex set ravenscar task-switching off
18185@item set ravenscar task-switching off
18186Turn off task switching when debugging a program that uses the Ravenscar
18187Profile. This is mostly intended to disable the code that adds support
18188for the Ravenscar Profile, in case a bug in either @value{GDBN} or in
18189the Ravenscar runtime is preventing @value{GDBN} from working properly.
18190To be effective, this command should be run before the program is started.
18191
18192@kindex show ravenscar task-switching
18193@item show ravenscar task-switching
18194Show whether it is possible to switch from task to task in a program
18195using the Ravenscar Profile.
18196
18197@end table
18198
3fcded8f
JB
18199@node Ada Settings
18200@subsubsection Ada Settings
18201@cindex Ada settings
18202
18203@table @code
18204@kindex set varsize-limit
18205@item set varsize-limit @var{size}
18206Prevent @value{GDBN} from attempting to evaluate objects whose size
18207is above the given limit (@var{size}) when those sizes are computed
18208from run-time quantities. This is typically the case when the object
18209has a variable size, such as an array whose bounds are not known at
18210compile time for example. Setting @var{size} to @code{unlimited}
18211removes the size limitation. By default, the limit is about 65KB.
18212
18213The purpose of having such a limit is to prevent @value{GDBN} from
18214trying to grab enormous chunks of virtual memory when asked to evaluate
18215a quantity whose bounds have been corrupted or have not yet been fully
18216initialized. The limit applies to the results of some subexpressions
18217as well as to complete expressions. For example, an expression denoting
18218a simple integer component, such as @code{x.y.z}, may fail if the size of
18219@code{x.y} is variable and exceeds @code{size}. On the other hand,
18220@value{GDBN} is sometimes clever; the expression @code{A(i)}, where
18221@code{A} is an array variable with non-constant size, will generally
18222succeed regardless of the bounds on @code{A}, as long as the component
18223size is less than @var{size}.
18224
18225@kindex show varsize-limit
18226@item show varsize-limit
18227Show the limit on types whose size is determined by run-time quantities.
18228@end table
18229
e07c999f
PH
18230@node Ada Glitches
18231@subsubsection Known Peculiarities of Ada Mode
18232@cindex Ada, problems
18233
18234Besides the omissions listed previously (@pxref{Omissions from Ada}),
18235we know of several problems with and limitations of Ada mode in
18236@value{GDBN},
18237some of which will be fixed with planned future releases of the debugger
18238and the GNU Ada compiler.
18239
18240@itemize @bullet
e07c999f
PH
18241@item
18242Static constants that the compiler chooses not to materialize as objects in
18243storage are invisible to the debugger.
18244
18245@item
18246Named parameter associations in function argument lists are ignored (the
18247argument lists are treated as positional).
18248
18249@item
18250Many useful library packages are currently invisible to the debugger.
18251
18252@item
18253Fixed-point arithmetic, conversions, input, and output is carried out using
18254floating-point arithmetic, and may give results that only approximate those on
18255the host machine.
18256
e07c999f
PH
18257@item
18258The GNAT compiler never generates the prefix @code{Standard} for any of
18259the standard symbols defined by the Ada language. @value{GDBN} knows about
18260this: it will strip the prefix from names when you use it, and will never
18261look for a name you have so qualified among local symbols, nor match against
18262symbols in other packages or subprograms. If you have
18263defined entities anywhere in your program other than parameters and
18264local variables whose simple names match names in @code{Standard},
18265GNAT's lack of qualification here can cause confusion. When this happens,
18266you can usually resolve the confusion
18267by qualifying the problematic names with package
18268@code{Standard} explicitly.
18269@end itemize
18270
95433b34
JB
18271Older versions of the compiler sometimes generate erroneous debugging
18272information, resulting in the debugger incorrectly printing the value
18273of affected entities. In some cases, the debugger is able to work
18274around an issue automatically. In other cases, the debugger is able
18275to work around the issue, but the work-around has to be specifically
18276enabled.
18277
18278@kindex set ada trust-PAD-over-XVS
18279@kindex show ada trust-PAD-over-XVS
18280@table @code
18281
18282@item set ada trust-PAD-over-XVS on
18283Configure GDB to strictly follow the GNAT encoding when computing the
18284value of Ada entities, particularly when @code{PAD} and @code{PAD___XVS}
18285types are involved (see @code{ada/exp_dbug.ads} in the GCC sources for
18286a complete description of the encoding used by the GNAT compiler).
18287This is the default.
18288
18289@item set ada trust-PAD-over-XVS off
18290This is related to the encoding using by the GNAT compiler. If @value{GDBN}
18291sometimes prints the wrong value for certain entities, changing @code{ada
18292trust-PAD-over-XVS} to @code{off} activates a work-around which may fix
18293the issue. It is always safe to set @code{ada trust-PAD-over-XVS} to
18294@code{off}, but this incurs a slight performance penalty, so it is
18295recommended to leave this setting to @code{on} unless necessary.
18296
18297@end table
18298
c6044dd1
JB
18299@cindex GNAT descriptive types
18300@cindex GNAT encoding
18301Internally, the debugger also relies on the compiler following a number
18302of conventions known as the @samp{GNAT Encoding}, all documented in
18303@file{gcc/ada/exp_dbug.ads} in the GCC sources. This encoding describes
18304how the debugging information should be generated for certain types.
18305In particular, this convention makes use of @dfn{descriptive types},
18306which are artificial types generated purely to help the debugger.
18307
18308These encodings were defined at a time when the debugging information
18309format used was not powerful enough to describe some of the more complex
18310types available in Ada. Since DWARF allows us to express nearly all
18311Ada features, the long-term goal is to slowly replace these descriptive
18312types by their pure DWARF equivalent. To facilitate that transition,
18313a new maintenance option is available to force the debugger to ignore
18314those descriptive types. It allows the user to quickly evaluate how
18315well @value{GDBN} works without them.
18316
18317@table @code
18318
18319@kindex maint ada set ignore-descriptive-types
18320@item maintenance ada set ignore-descriptive-types [on|off]
18321Control whether the debugger should ignore descriptive types.
18322The default is not to ignore descriptives types (@code{off}).
18323
18324@kindex maint ada show ignore-descriptive-types
18325@item maintenance ada show ignore-descriptive-types
18326Show if descriptive types are ignored by @value{GDBN}.
18327
18328@end table
18329
79a6e687
BW
18330@node Unsupported Languages
18331@section Unsupported Languages
4e562065
JB
18332
18333@cindex unsupported languages
18334@cindex minimal language
18335In addition to the other fully-supported programming languages,
18336@value{GDBN} also provides a pseudo-language, called @code{minimal}.
18337It does not represent a real programming language, but provides a set
18338of capabilities close to what the C or assembly languages provide.
18339This should allow most simple operations to be performed while debugging
18340an application that uses a language currently not supported by @value{GDBN}.
18341
18342If the language is set to @code{auto}, @value{GDBN} will automatically
18343select this language if the current frame corresponds to an unsupported
18344language.
18345
6d2ebf8b 18346@node Symbols
c906108c
SS
18347@chapter Examining the Symbol Table
18348
d4f3574e 18349The commands described in this chapter allow you to inquire about the
c906108c
SS
18350symbols (names of variables, functions and types) defined in your
18351program. This information is inherent in the text of your program and
18352does not change as your program executes. @value{GDBN} finds it in your
18353program's symbol table, in the file indicated when you started @value{GDBN}
79a6e687
BW
18354(@pxref{File Options, ,Choosing Files}), or by one of the
18355file-management commands (@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
18356
18357@cindex symbol names
18358@cindex names of symbols
18359@cindex quoting names
d044bac8 18360@anchor{quoting names}
c906108c
SS
18361Occasionally, you may need to refer to symbols that contain unusual
18362characters, which @value{GDBN} ordinarily treats as word delimiters. The
18363most frequent case is in referring to static variables in other
79a6e687 18364source files (@pxref{Variables,,Program Variables}). File names
c906108c
SS
18365are recorded in object files as debugging symbols, but @value{GDBN} would
18366ordinarily parse a typical file name, like @file{foo.c}, as the three words
18367@samp{foo} @samp{.} @samp{c}. To allow @value{GDBN} to recognize
18368@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
18369
474c8240 18370@smallexample
c906108c 18371p 'foo.c'::x
474c8240 18372@end smallexample
c906108c
SS
18373
18374@noindent
18375looks up the value of @code{x} in the scope of the file @file{foo.c}.
18376
18377@table @code
a8f24a35
EZ
18378@cindex case-insensitive symbol names
18379@cindex case sensitivity in symbol names
18380@kindex set case-sensitive
18381@item set case-sensitive on
18382@itemx set case-sensitive off
18383@itemx set case-sensitive auto
18384Normally, when @value{GDBN} looks up symbols, it matches their names
18385with case sensitivity determined by the current source language.
18386Occasionally, you may wish to control that. The command @code{set
18387case-sensitive} lets you do that by specifying @code{on} for
18388case-sensitive matches or @code{off} for case-insensitive ones. If
18389you specify @code{auto}, case sensitivity is reset to the default
18390suitable for the source language. The default is case-sensitive
18391matches for all languages except for Fortran, for which the default is
18392case-insensitive matches.
18393
9c16f35a
EZ
18394@kindex show case-sensitive
18395@item show case-sensitive
a8f24a35
EZ
18396This command shows the current setting of case sensitivity for symbols
18397lookups.
18398
53342f27
TT
18399@kindex set print type methods
18400@item set print type methods
18401@itemx set print type methods on
18402@itemx set print type methods off
18403Normally, when @value{GDBN} prints a class, it displays any methods
18404declared in that class. You can control this behavior either by
18405passing the appropriate flag to @code{ptype}, or using @command{set
18406print type methods}. Specifying @code{on} will cause @value{GDBN} to
18407display the methods; this is the default. Specifying @code{off} will
18408cause @value{GDBN} to omit the methods.
18409
18410@kindex show print type methods
18411@item show print type methods
18412This command shows the current setting of method display when printing
18413classes.
18414
883fd55a
KS
18415@kindex set print type nested-type-limit
18416@item set print type nested-type-limit @var{limit}
18417@itemx set print type nested-type-limit unlimited
18418Set the limit of displayed nested types that the type printer will
18419show. A @var{limit} of @code{unlimited} or @code{-1} will show all
18420nested definitions. By default, the type printer will not show any nested
18421types defined in classes.
18422
18423@kindex show print type nested-type-limit
18424@item show print type nested-type-limit
18425This command shows the current display limit of nested types when
18426printing classes.
18427
53342f27
TT
18428@kindex set print type typedefs
18429@item set print type typedefs
18430@itemx set print type typedefs on
18431@itemx set print type typedefs off
18432
18433Normally, when @value{GDBN} prints a class, it displays any typedefs
18434defined in that class. You can control this behavior either by
18435passing the appropriate flag to @code{ptype}, or using @command{set
18436print type typedefs}. Specifying @code{on} will cause @value{GDBN} to
18437display the typedef definitions; this is the default. Specifying
18438@code{off} will cause @value{GDBN} to omit the typedef definitions.
18439Note that this controls whether the typedef definition itself is
18440printed, not whether typedef names are substituted when printing other
18441types.
18442
18443@kindex show print type typedefs
18444@item show print type typedefs
18445This command shows the current setting of typedef display when
18446printing classes.
18447
c906108c 18448@kindex info address
b37052ae 18449@cindex address of a symbol
c906108c
SS
18450@item info address @var{symbol}
18451Describe where the data for @var{symbol} is stored. For a register
18452variable, this says which register it is kept in. For a non-register
18453local variable, this prints the stack-frame offset at which the variable
18454is always stored.
18455
18456Note the contrast with @samp{print &@var{symbol}}, which does not work
18457at all for a register variable, and for a stack local variable prints
18458the exact address of the current instantiation of the variable.
18459
3d67e040 18460@kindex info symbol
b37052ae 18461@cindex symbol from address
9c16f35a 18462@cindex closest symbol and offset for an address
3d67e040
EZ
18463@item info symbol @var{addr}
18464Print the name of a symbol which is stored at the address @var{addr}.
18465If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
18466nearest symbol and an offset from it:
18467
474c8240 18468@smallexample
3d67e040
EZ
18469(@value{GDBP}) info symbol 0x54320
18470_initialize_vx + 396 in section .text
474c8240 18471@end smallexample
3d67e040
EZ
18472
18473@noindent
18474This is the opposite of the @code{info address} command. You can use
18475it to find out the name of a variable or a function given its address.
18476
c14c28ba
PP
18477For dynamically linked executables, the name of executable or shared
18478library containing the symbol is also printed:
18479
18480@smallexample
18481(@value{GDBP}) info symbol 0x400225
18482_start + 5 in section .text of /tmp/a.out
18483(@value{GDBP}) info symbol 0x2aaaac2811cf
18484__read_nocancel + 6 in section .text of /usr/lib64/libc.so.6
18485@end smallexample
18486
439250fb
DE
18487@kindex demangle
18488@cindex demangle
18489@item demangle @r{[}-l @var{language}@r{]} @r{[}@var{--}@r{]} @var{name}
18490Demangle @var{name}.
18491If @var{language} is provided it is the name of the language to demangle
18492@var{name} in. Otherwise @var{name} is demangled in the current language.
18493
18494The @samp{--} option specifies the end of options,
18495and is useful when @var{name} begins with a dash.
18496
18497The parameter @code{demangle-style} specifies how to interpret the kind
18498of mangling used. @xref{Print Settings}.
18499
c906108c 18500@kindex whatis
53342f27 18501@item whatis[/@var{flags}] [@var{arg}]
177bc839
JK
18502Print the data type of @var{arg}, which can be either an expression
18503or a name of a data type. With no argument, print the data type of
18504@code{$}, the last value in the value history.
18505
18506If @var{arg} is an expression (@pxref{Expressions, ,Expressions}), it
18507is not actually evaluated, and any side-effecting operations (such as
18508assignments or function calls) inside it do not take place.
18509
18510If @var{arg} is a variable or an expression, @code{whatis} prints its
18511literal type as it is used in the source code. If the type was
18512defined using a @code{typedef}, @code{whatis} will @emph{not} print
18513the data type underlying the @code{typedef}. If the type of the
18514variable or the expression is a compound data type, such as
18515@code{struct} or @code{class}, @code{whatis} never prints their
18516fields or methods. It just prints the @code{struct}/@code{class}
18517name (a.k.a.@: its @dfn{tag}). If you want to see the members of
18518such a compound data type, use @code{ptype}.
18519
18520If @var{arg} is a type name that was defined using @code{typedef},
18521@code{whatis} @dfn{unrolls} only one level of that @code{typedef}.
18522Unrolling means that @code{whatis} will show the underlying type used
18523in the @code{typedef} declaration of @var{arg}. However, if that
18524underlying type is also a @code{typedef}, @code{whatis} will not
18525unroll it.
18526
18527For C code, the type names may also have the form @samp{class
18528@var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
18529@var{union-tag}} or @samp{enum @var{enum-tag}}.
c906108c 18530
53342f27
TT
18531@var{flags} can be used to modify how the type is displayed.
18532Available flags are:
18533
18534@table @code
18535@item r
18536Display in ``raw'' form. Normally, @value{GDBN} substitutes template
18537parameters and typedefs defined in a class when printing the class'
18538members. The @code{/r} flag disables this.
18539
18540@item m
18541Do not print methods defined in the class.
18542
18543@item M
18544Print methods defined in the class. This is the default, but the flag
18545exists in case you change the default with @command{set print type methods}.
18546
18547@item t
18548Do not print typedefs defined in the class. Note that this controls
18549whether the typedef definition itself is printed, not whether typedef
18550names are substituted when printing other types.
18551
18552@item T
18553Print typedefs defined in the class. This is the default, but the flag
18554exists in case you change the default with @command{set print type typedefs}.
7c161838
SDJ
18555
18556@item o
18557Print the offsets and sizes of fields in a struct, similar to what the
18558@command{pahole} tool does. This option implies the @code{/tm} flags.
18559
18560For example, given the following declarations:
18561
18562@smallexample
18563struct tuv
18564@{
18565 int a1;
18566 char *a2;
18567 int a3;
18568@};
18569
18570struct xyz
18571@{
18572 int f1;
18573 char f2;
18574 void *f3;
18575 struct tuv f4;
18576@};
18577
18578union qwe
18579@{
18580 struct tuv fff1;
18581 struct xyz fff2;
18582@};
18583
18584struct tyu
18585@{
18586 int a1 : 1;
18587 int a2 : 3;
18588 int a3 : 23;
18589 char a4 : 2;
18590 int64_t a5;
18591 int a6 : 5;
18592 int64_t a7 : 3;
18593@};
18594@end smallexample
18595
18596Issuing a @kbd{ptype /o struct tuv} command would print:
18597
18598@smallexample
18599(@value{GDBP}) ptype /o struct tuv
18600/* offset | size */ type = struct tuv @{
18601/* 0 | 4 */ int a1;
18602/* XXX 4-byte hole */
18603/* 8 | 8 */ char *a2;
18604/* 16 | 4 */ int a3;
18605
18606 /* total size (bytes): 24 */
18607 @}
18608@end smallexample
18609
18610Notice the format of the first column of comments. There, you can
18611find two parts separated by the @samp{|} character: the @emph{offset},
18612which indicates where the field is located inside the struct, in
18613bytes, and the @emph{size} of the field. Another interesting line is
18614the marker of a @emph{hole} in the struct, indicating that it may be
18615possible to pack the struct and make it use less space by reorganizing
18616its fields.
18617
18618It is also possible to print offsets inside an union:
18619
18620@smallexample
18621(@value{GDBP}) ptype /o union qwe
18622/* offset | size */ type = union qwe @{
18623/* 24 */ struct tuv @{
18624/* 0 | 4 */ int a1;
18625/* XXX 4-byte hole */
18626/* 8 | 8 */ char *a2;
18627/* 16 | 4 */ int a3;
18628
18629 /* total size (bytes): 24 */
18630 @} fff1;
18631/* 40 */ struct xyz @{
18632/* 0 | 4 */ int f1;
18633/* 4 | 1 */ char f2;
18634/* XXX 3-byte hole */
18635/* 8 | 8 */ void *f3;
18636/* 16 | 24 */ struct tuv @{
18637/* 16 | 4 */ int a1;
18638/* XXX 4-byte hole */
18639/* 24 | 8 */ char *a2;
18640/* 32 | 4 */ int a3;
18641
18642 /* total size (bytes): 24 */
18643 @} f4;
18644
18645 /* total size (bytes): 40 */
18646 @} fff2;
18647
18648 /* total size (bytes): 40 */
18649 @}
18650@end smallexample
18651
18652In this case, since @code{struct tuv} and @code{struct xyz} occupy the
18653same space (because we are dealing with an union), the offset is not
18654printed for them. However, you can still examine the offset of each
18655of these structures' fields.
18656
18657Another useful scenario is printing the offsets of a struct containing
18658bitfields:
18659
18660@smallexample
18661(@value{GDBP}) ptype /o struct tyu
18662/* offset | size */ type = struct tyu @{
18663/* 0:31 | 4 */ int a1 : 1;
18664/* 0:28 | 4 */ int a2 : 3;
18665/* 0: 5 | 4 */ int a3 : 23;
18666/* 3: 3 | 1 */ signed char a4 : 2;
18667/* XXX 3-bit hole */
18668/* XXX 4-byte hole */
18669/* 8 | 8 */ int64_t a5;
9d3421af
TT
18670/* 16: 0 | 4 */ int a6 : 5;
18671/* 16: 5 | 8 */ int64_t a7 : 3;
18672"/* XXX 7-byte padding */
7c161838
SDJ
18673
18674 /* total size (bytes): 24 */
18675 @}
18676@end smallexample
18677
9d3421af
TT
18678Note how the offset information is now extended to also include the
18679first bit of the bitfield.
53342f27
TT
18680@end table
18681
c906108c 18682@kindex ptype
53342f27 18683@item ptype[/@var{flags}] [@var{arg}]
62f3a2ba
FF
18684@code{ptype} accepts the same arguments as @code{whatis}, but prints a
18685detailed description of the type, instead of just the name of the type.
18686@xref{Expressions, ,Expressions}.
c906108c 18687
177bc839
JK
18688Contrary to @code{whatis}, @code{ptype} always unrolls any
18689@code{typedef}s in its argument declaration, whether the argument is
18690a variable, expression, or a data type. This means that @code{ptype}
18691of a variable or an expression will not print literally its type as
18692present in the source code---use @code{whatis} for that. @code{typedef}s at
18693the pointer or reference targets are also unrolled. Only @code{typedef}s of
18694fields, methods and inner @code{class typedef}s of @code{struct}s,
18695@code{class}es and @code{union}s are not unrolled even with @code{ptype}.
18696
c906108c
SS
18697For example, for this variable declaration:
18698
474c8240 18699@smallexample
177bc839
JK
18700typedef double real_t;
18701struct complex @{ real_t real; double imag; @};
18702typedef struct complex complex_t;
18703complex_t var;
18704real_t *real_pointer_var;
474c8240 18705@end smallexample
c906108c
SS
18706
18707@noindent
18708the two commands give this output:
18709
474c8240 18710@smallexample
c906108c 18711@group
177bc839
JK
18712(@value{GDBP}) whatis var
18713type = complex_t
18714(@value{GDBP}) ptype var
18715type = struct complex @{
18716 real_t real;
18717 double imag;
18718@}
18719(@value{GDBP}) whatis complex_t
18720type = struct complex
18721(@value{GDBP}) whatis struct complex
c906108c 18722type = struct complex
177bc839 18723(@value{GDBP}) ptype struct complex
c906108c 18724type = struct complex @{
177bc839 18725 real_t real;
c906108c
SS
18726 double imag;
18727@}
177bc839
JK
18728(@value{GDBP}) whatis real_pointer_var
18729type = real_t *
18730(@value{GDBP}) ptype real_pointer_var
18731type = double *
c906108c 18732@end group
474c8240 18733@end smallexample
c906108c
SS
18734
18735@noindent
18736As with @code{whatis}, using @code{ptype} without an argument refers to
18737the type of @code{$}, the last value in the value history.
18738
ab1adacd
EZ
18739@cindex incomplete type
18740Sometimes, programs use opaque data types or incomplete specifications
18741of complex data structure. If the debug information included in the
18742program does not allow @value{GDBN} to display a full declaration of
18743the data type, it will say @samp{<incomplete type>}. For example,
18744given these declarations:
18745
18746@smallexample
18747 struct foo;
18748 struct foo *fooptr;
18749@end smallexample
18750
18751@noindent
18752but no definition for @code{struct foo} itself, @value{GDBN} will say:
18753
18754@smallexample
ddb50cd7 18755 (@value{GDBP}) ptype foo
ab1adacd
EZ
18756 $1 = <incomplete type>
18757@end smallexample
18758
18759@noindent
18760``Incomplete type'' is C terminology for data types that are not
18761completely specified.
18762
d69cf9b2
PA
18763@cindex unknown type
18764Othertimes, information about a variable's type is completely absent
18765from the debug information included in the program. This most often
18766happens when the program or library where the variable is defined
18767includes no debug information at all. @value{GDBN} knows the variable
18768exists from inspecting the linker/loader symbol table (e.g., the ELF
18769dynamic symbol table), but such symbols do not contain type
18770information. Inspecting the type of a (global) variable for which
18771@value{GDBN} has no type information shows:
18772
18773@smallexample
18774 (@value{GDBP}) ptype var
18775 type = <data variable, no debug info>
18776@end smallexample
18777
18778@xref{Variables, no debug info variables}, for how to print the values
18779of such variables.
18780
c906108c 18781@kindex info types
a8eab7c6 18782@item info types [-q] [@var{regexp}]
09d4efe1
EZ
18783Print a brief description of all types whose names match the regular
18784expression @var{regexp} (or all types in your program, if you supply
18785no argument). Each complete typename is matched as though it were a
18786complete line; thus, @samp{i type value} gives information on all
18787types in your program whose names include the string @code{value}, but
18788@samp{i type ^value$} gives information only on types whose complete
18789name is @code{value}.
c906108c 18790
20813a0b
PW
18791In programs using different languages, @value{GDBN} chooses the syntax
18792to print the type description according to the
18793@samp{set language} value: using @samp{set language auto}
18794(see @ref{Automatically, ,Set Language Automatically}) means to use the
18795language of the type, other values mean to use
18796the manually specified language (see @ref{Manually, ,Set Language Manually}).
18797
c906108c
SS
18798This command differs from @code{ptype} in two ways: first, like
18799@code{whatis}, it does not print a detailed description; second, it
b744723f 18800lists all source files and line numbers where a type is defined.
c906108c 18801
a8eab7c6
AB
18802The output from @samp{into types} is proceeded with a header line
18803describing what types are being listed. The optional flag @samp{-q},
18804which stands for @samp{quiet}, disables printing this header
18805information.
18806
18a9fc12
TT
18807@kindex info type-printers
18808@item info type-printers
18809Versions of @value{GDBN} that ship with Python scripting enabled may
18810have ``type printers'' available. When using @command{ptype} or
18811@command{whatis}, these printers are consulted when the name of a type
18812is needed. @xref{Type Printing API}, for more information on writing
18813type printers.
18814
18815@code{info type-printers} displays all the available type printers.
18816
18817@kindex enable type-printer
18818@kindex disable type-printer
18819@item enable type-printer @var{name}@dots{}
18820@item disable type-printer @var{name}@dots{}
18821These commands can be used to enable or disable type printers.
18822
b37052ae
EZ
18823@kindex info scope
18824@cindex local variables
09d4efe1 18825@item info scope @var{location}
b37052ae 18826List all the variables local to a particular scope. This command
09d4efe1
EZ
18827accepts a @var{location} argument---a function name, a source line, or
18828an address preceded by a @samp{*}, and prints all the variables local
2a25a5ba
EZ
18829to the scope defined by that location. (@xref{Specify Location}, for
18830details about supported forms of @var{location}.) For example:
b37052ae
EZ
18831
18832@smallexample
18833(@value{GDBP}) @b{info scope command_line_handler}
18834Scope for command_line_handler:
18835Symbol rl is an argument at stack/frame offset 8, length 4.
18836Symbol linebuffer is in static storage at address 0x150a18, length 4.
18837Symbol linelength is in static storage at address 0x150a1c, length 4.
18838Symbol p is a local variable in register $esi, length 4.
18839Symbol p1 is a local variable in register $ebx, length 4.
18840Symbol nline is a local variable in register $edx, length 4.
18841Symbol repeat is a local variable at frame offset -8, length 4.
18842@end smallexample
18843
f5c37c66
EZ
18844@noindent
18845This command is especially useful for determining what data to collect
18846during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
18847collect}.
18848
c906108c
SS
18849@kindex info source
18850@item info source
919d772c
JB
18851Show information about the current source file---that is, the source file for
18852the function containing the current point of execution:
18853@itemize @bullet
18854@item
18855the name of the source file, and the directory containing it,
18856@item
18857the directory it was compiled in,
18858@item
18859its length, in lines,
18860@item
18861which programming language it is written in,
18862@item
b6577aab
DE
18863if the debug information provides it, the program that compiled the file
18864(which may include, e.g., the compiler version and command line arguments),
18865@item
919d772c
JB
18866whether the executable includes debugging information for that file, and
18867if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
18868@item
18869whether the debugging information includes information about
18870preprocessor macros.
18871@end itemize
18872
c906108c
SS
18873
18874@kindex info sources
18875@item info sources
18876Print the names of all source files in your program for which there is
18877debugging information, organized into two lists: files whose symbols
18878have already been read, and files whose symbols will be read when needed.
18879
ae60f04e
PW
18880@item info sources [-dirname | -basename] [--] [@var{regexp}]
18881Like @samp{info sources}, but only print the names of the files
18882matching the provided @var{regexp}.
18883By default, the @var{regexp} is used to match anywhere in the filename.
18884If @code{-dirname}, only files having a dirname matching @var{regexp} are shown.
18885If @code{-basename}, only files having a basename matching @var{regexp}
18886are shown.
18887The matching is case-sensitive, except on operating systems that
18888have case-insensitive filesystem (e.g., MS-Windows).
18889
c906108c 18890@kindex info functions
4acfdd20 18891@item info functions [-q] [-n]
c906108c 18892Print the names and data types of all defined functions.
b744723f
AA
18893Similarly to @samp{info types}, this command groups its output by source
18894files and annotates each function definition with its source line
18895number.
c906108c 18896
20813a0b
PW
18897In programs using different languages, @value{GDBN} chooses the syntax
18898to print the function name and type according to the
18899@samp{set language} value: using @samp{set language auto}
18900(see @ref{Automatically, ,Set Language Automatically}) means to use the
18901language of the function, other values mean to use
18902the manually specified language (see @ref{Manually, ,Set Language Manually}).
18903
4acfdd20
AB
18904The @samp{-n} flag excludes @dfn{non-debugging symbols} from the
18905results. A non-debugging symbol is a symbol that comes from the
18906executable's symbol table, not from the debug information (for
18907example, DWARF) associated with the executable.
18908
d321477b
PW
18909The optional flag @samp{-q}, which stands for @samp{quiet}, disables
18910printing header information and messages explaining why no functions
18911have been printed.
18912
4acfdd20 18913@item info functions [-q] [-n] [-t @var{type_regexp}] [@var{regexp}]
d321477b
PW
18914Like @samp{info functions}, but only print the names and data types
18915of the functions selected with the provided regexp(s).
18916
18917If @var{regexp} is provided, print only the functions whose names
18918match the regular expression @var{regexp}.
18919Thus, @samp{info fun step} finds all functions whose
b744723f
AA
18920names include @code{step}; @samp{info fun ^step} finds those whose names
18921start with @code{step}. If a function name contains characters that
18922conflict with the regular expression language (e.g.@:
1c5dfdad 18923@samp{operator*()}), they may be quoted with a backslash.
c906108c 18924
d321477b
PW
18925If @var{type_regexp} is provided, print only the functions whose
18926types, as printed by the @code{whatis} command, match
18927the regular expression @var{type_regexp}.
18928If @var{type_regexp} contains space(s), it should be enclosed in
18929quote characters. If needed, use backslash to escape the meaning
18930of special characters or quotes.
18931Thus, @samp{info fun -t '^int ('} finds the functions that return
18932an integer; @samp{info fun -t '(.*int.*'} finds the functions that
18933have an argument type containing int; @samp{info fun -t '^int (' ^step}
18934finds the functions whose names start with @code{step} and that return
18935int.
18936
18937If both @var{regexp} and @var{type_regexp} are provided, a function
18938is printed only if its name matches @var{regexp} and its type matches
18939@var{type_regexp}.
18940
18941
c906108c 18942@kindex info variables
4acfdd20 18943@item info variables [-q] [-n]
0fe7935b 18944Print the names and data types of all variables that are defined
6ca652b0 18945outside of functions (i.e.@: excluding local variables).
b744723f
AA
18946The printed variables are grouped by source files and annotated with
18947their respective source line numbers.
c906108c 18948
20813a0b
PW
18949In programs using different languages, @value{GDBN} chooses the syntax
18950to print the variable name and type according to the
18951@samp{set language} value: using @samp{set language auto}
18952(see @ref{Automatically, ,Set Language Automatically}) means to use the
18953language of the variable, other values mean to use
18954the manually specified language (see @ref{Manually, ,Set Language Manually}).
18955
4acfdd20
AB
18956The @samp{-n} flag excludes non-debugging symbols from the results.
18957
d321477b
PW
18958The optional flag @samp{-q}, which stands for @samp{quiet}, disables
18959printing header information and messages explaining why no variables
18960have been printed.
18961
4acfdd20 18962@item info variables [-q] [-n] [-t @var{type_regexp}] [@var{regexp}]
d321477b
PW
18963Like @kbd{info variables}, but only print the variables selected
18964with the provided regexp(s).
18965
18966If @var{regexp} is provided, print only the variables whose names
18967match the regular expression @var{regexp}.
18968
18969If @var{type_regexp} is provided, print only the variables whose
18970types, as printed by the @code{whatis} command, match
18971the regular expression @var{type_regexp}.
18972If @var{type_regexp} contains space(s), it should be enclosed in
18973quote characters. If needed, use backslash to escape the meaning
18974of special characters or quotes.
18975
18976If both @var{regexp} and @var{type_regexp} are provided, an argument
18977is printed only if its name matches @var{regexp} and its type matches
18978@var{type_regexp}.
c906108c 18979
59c35742
AB
18980@kindex info modules
18981@cindex modules
18982@item info modules @r{[}-q@r{]} @r{[}@var{regexp}@r{]}
18983List all Fortran modules in the program, or all modules matching the
18984optional regular expression @var{regexp}.
18985
18986The optional flag @samp{-q}, which stands for @samp{quiet}, disables
18987printing header information and messages explaining why no modules
18988have been printed.
165f8965
AB
18989
18990@kindex info module
18991@cindex Fortran modules, information about
18992@cindex functions and variables by Fortran module
18993@cindex module functions and variables
18994@item info module functions @r{[}-q@r{]} @r{[}-m @var{module-regexp}@r{]} @r{[}-t @var{type-regexp}@r{]} @r{[}@var{regexp}@r{]}
18995@itemx info module variables @r{[}-q@r{]} @r{[}-m @var{module-regexp}@r{]} @r{[}-t @var{type-regexp}@r{]} @r{[}@var{regexp}@r{]}
18996List all functions or variables within all Fortran modules. The set
18997of functions or variables listed can be limited by providing some or
18998all of the optional regular expressions. If @var{module-regexp} is
18999provided, then only Fortran modules matching @var{module-regexp} will
19000be searched. Only functions or variables whose type matches the
19001optional regular expression @var{type-regexp} will be listed. And
19002only functions or variables whose name matches the optional regular
19003expression @var{regexp} will be listed.
19004
19005The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19006printing header information and messages explaining why no functions
19007or variables have been printed.
59c35742 19008
b37303ee 19009@kindex info classes
721c2651 19010@cindex Objective-C, classes and selectors
b37303ee
AF
19011@item info classes
19012@itemx info classes @var{regexp}
19013Display all Objective-C classes in your program, or
19014(with the @var{regexp} argument) all those matching a particular regular
19015expression.
19016
19017@kindex info selectors
19018@item info selectors
19019@itemx info selectors @var{regexp}
19020Display all Objective-C selectors in your program, or
19021(with the @var{regexp} argument) all those matching a particular regular
19022expression.
19023
c906108c
SS
19024@ignore
19025This was never implemented.
19026@kindex info methods
19027@item info methods
19028@itemx info methods @var{regexp}
19029The @code{info methods} command permits the user to examine all defined
b37052ae
EZ
19030methods within C@t{++} program, or (with the @var{regexp} argument) a
19031specific set of methods found in the various C@t{++} classes. Many
19032C@t{++} classes provide a large number of methods. Thus, the output
c906108c
SS
19033from the @code{ptype} command can be overwhelming and hard to use. The
19034@code{info-methods} command filters the methods, printing only those
19035which match the regular-expression @var{regexp}.
19036@end ignore
19037
9c16f35a 19038@cindex opaque data types
c906108c
SS
19039@kindex set opaque-type-resolution
19040@item set opaque-type-resolution on
19041Tell @value{GDBN} to resolve opaque types. An opaque type is a type
19042declared as a pointer to a @code{struct}, @code{class}, or
19043@code{union}---for example, @code{struct MyType *}---that is used in one
19044source file although the full declaration of @code{struct MyType} is in
19045another source file. The default is on.
19046
19047A change in the setting of this subcommand will not take effect until
19048the next time symbols for a file are loaded.
19049
19050@item set opaque-type-resolution off
19051Tell @value{GDBN} not to resolve opaque types. In this case, the type
19052is printed as follows:
19053@smallexample
19054@{<no data fields>@}
19055@end smallexample
19056
19057@kindex show opaque-type-resolution
19058@item show opaque-type-resolution
19059Show whether opaque types are resolved or not.
c906108c 19060
770e7fc7
DE
19061@kindex set print symbol-loading
19062@cindex print messages when symbols are loaded
19063@item set print symbol-loading
19064@itemx set print symbol-loading full
19065@itemx set print symbol-loading brief
19066@itemx set print symbol-loading off
19067The @code{set print symbol-loading} command allows you to control the
19068printing of messages when @value{GDBN} loads symbol information.
19069By default a message is printed for the executable and one for each
19070shared library, and normally this is what you want. However, when
19071debugging apps with large numbers of shared libraries these messages
19072can be annoying.
19073When set to @code{brief} a message is printed for each executable,
19074and when @value{GDBN} loads a collection of shared libraries at once
19075it will only print one message regardless of the number of shared
19076libraries. When set to @code{off} no messages are printed.
19077
19078@kindex show print symbol-loading
19079@item show print symbol-loading
19080Show whether messages will be printed when a @value{GDBN} command
19081entered from the keyboard causes symbol information to be loaded.
19082
c906108c
SS
19083@kindex maint print symbols
19084@cindex symbol dump
19085@kindex maint print psymbols
19086@cindex partial symbol dump
7c57fa1e
YQ
19087@kindex maint print msymbols
19088@cindex minimal symbol dump
34c41c68
DE
19089@item maint print symbols @r{[}-pc @var{address}@r{]} @r{[}@var{filename}@r{]}
19090@itemx maint print symbols @r{[}-objfile @var{objfile}@r{]} @r{[}-source @var{source}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19091@itemx maint print psymbols @r{[}-objfile @var{objfile}@r{]} @r{[}-pc @var{address}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19092@itemx maint print psymbols @r{[}-objfile @var{objfile}@r{]} @r{[}-source @var{source}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19093@itemx maint print msymbols @r{[}-objfile @var{objfile}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19094Write a dump of debugging symbol data into the file @var{filename} or
19095the terminal if @var{filename} is unspecified.
19096If @code{-objfile @var{objfile}} is specified, only dump symbols for
19097that objfile.
19098If @code{-pc @var{address}} is specified, only dump symbols for the file
19099with code at that address. Note that @var{address} may be a symbol like
19100@code{main}.
19101If @code{-source @var{source}} is specified, only dump symbols for that
19102source file.
19103
19104These commands are used to debug the @value{GDBN} symbol-reading code.
19105These commands do not modify internal @value{GDBN} state, therefore
19106@samp{maint print symbols} will only print symbols for already expanded symbol
19107tables.
19108You can use the command @code{info sources} to find out which files these are.
19109If you use @samp{maint print psymbols} instead, the dump shows information
19110about symbols that @value{GDBN} only knows partially---that is, symbols
19111defined in files that @value{GDBN} has skimmed, but not yet read completely.
19112Finally, @samp{maint print msymbols} just dumps ``minimal symbols'', e.g.,
19113``ELF symbols''.
19114
79a6e687 19115@xref{Files, ,Commands to Specify Files}, for a discussion of how
c906108c 19116@value{GDBN} reads symbols (in the description of @code{symbol-file}).
44ea7b70 19117
5e7b2f39
JB
19118@kindex maint info symtabs
19119@kindex maint info psymtabs
44ea7b70
JB
19120@cindex listing @value{GDBN}'s internal symbol tables
19121@cindex symbol tables, listing @value{GDBN}'s internal
19122@cindex full symbol tables, listing @value{GDBN}'s internal
19123@cindex partial symbol tables, listing @value{GDBN}'s internal
5e7b2f39
JB
19124@item maint info symtabs @r{[} @var{regexp} @r{]}
19125@itemx maint info psymtabs @r{[} @var{regexp} @r{]}
44ea7b70
JB
19126
19127List the @code{struct symtab} or @code{struct partial_symtab}
19128structures whose names match @var{regexp}. If @var{regexp} is not
19129given, list them all. The output includes expressions which you can
19130copy into a @value{GDBN} debugging this one to examine a particular
19131structure in more detail. For example:
19132
19133@smallexample
5e7b2f39 19134(@value{GDBP}) maint info psymtabs dwarf2read
44ea7b70
JB
19135@{ objfile /home/gnu/build/gdb/gdb
19136 ((struct objfile *) 0x82e69d0)
b383017d 19137 @{ psymtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
19138 ((struct partial_symtab *) 0x8474b10)
19139 readin no
19140 fullname (null)
19141 text addresses 0x814d3c8 -- 0x8158074
19142 globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
19143 statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
19144 dependencies (none)
19145 @}
19146@}
5e7b2f39 19147(@value{GDBP}) maint info symtabs
44ea7b70
JB
19148(@value{GDBP})
19149@end smallexample
19150@noindent
19151We see that there is one partial symbol table whose filename contains
19152the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
19153and we see that @value{GDBN} has not read in any symtabs yet at all.
19154If we set a breakpoint on a function, that will cause @value{GDBN} to
19155read the symtab for the compilation unit containing that function:
19156
19157@smallexample
19158(@value{GDBP}) break dwarf2_psymtab_to_symtab
19159Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
19160line 1574.
5e7b2f39 19161(@value{GDBP}) maint info symtabs
b383017d 19162@{ objfile /home/gnu/build/gdb/gdb
44ea7b70 19163 ((struct objfile *) 0x82e69d0)
b383017d 19164 @{ symtab /home/gnu/src/gdb/dwarf2read.c
44ea7b70
JB
19165 ((struct symtab *) 0x86c1f38)
19166 dirname (null)
19167 fullname (null)
19168 blockvector ((struct blockvector *) 0x86c1bd0) (primary)
1b39d5c0 19169 linetable ((struct linetable *) 0x8370fa0)
44ea7b70
JB
19170 debugformat DWARF 2
19171 @}
19172@}
b383017d 19173(@value{GDBP})
44ea7b70 19174@end smallexample
44ea7b70 19175
f2403c39
AB
19176@kindex maint info line-table
19177@cindex listing @value{GDBN}'s internal line tables
19178@cindex line tables, listing @value{GDBN}'s internal
19179@item maint info line-table @r{[} @var{regexp} @r{]}
19180
19181List the @code{struct linetable} from all @code{struct symtab}
19182instances whose name matches @var{regexp}. If @var{regexp} is not
19183given, list the @code{struct linetable} from all @code{struct symtab}.
19184
f57d2163
DE
19185@kindex maint set symbol-cache-size
19186@cindex symbol cache size
19187@item maint set symbol-cache-size @var{size}
19188Set the size of the symbol cache to @var{size}.
19189The default size is intended to be good enough for debugging
19190most applications. This option exists to allow for experimenting
19191with different sizes.
19192
19193@kindex maint show symbol-cache-size
19194@item maint show symbol-cache-size
19195Show the size of the symbol cache.
19196
19197@kindex maint print symbol-cache
19198@cindex symbol cache, printing its contents
19199@item maint print symbol-cache
19200Print the contents of the symbol cache.
19201This is useful when debugging symbol cache issues.
19202
19203@kindex maint print symbol-cache-statistics
19204@cindex symbol cache, printing usage statistics
19205@item maint print symbol-cache-statistics
19206Print symbol cache usage statistics.
19207This helps determine how well the cache is being utilized.
19208
19209@kindex maint flush-symbol-cache
19210@cindex symbol cache, flushing
19211@item maint flush-symbol-cache
19212Flush the contents of the symbol cache, all entries are removed.
19213This command is useful when debugging the symbol cache.
19214It is also useful when collecting performance data.
19215
19216@end table
6a3ca067 19217
6d2ebf8b 19218@node Altering
c906108c
SS
19219@chapter Altering Execution
19220
19221Once you think you have found an error in your program, you might want to
19222find out for certain whether correcting the apparent error would lead to
19223correct results in the rest of the run. You can find the answer by
19224experiment, using the @value{GDBN} features for altering execution of the
19225program.
19226
19227For example, you can store new values into variables or memory
7a292a7a
SS
19228locations, give your program a signal, restart it at a different
19229address, or even return prematurely from a function.
c906108c
SS
19230
19231@menu
19232* Assignment:: Assignment to variables
19233* Jumping:: Continuing at a different address
c906108c 19234* Signaling:: Giving your program a signal
c906108c
SS
19235* Returning:: Returning from a function
19236* Calling:: Calling your program's functions
19237* Patching:: Patching your program
bb2ec1b3 19238* Compiling and Injecting Code:: Compiling and injecting code in @value{GDBN}
c906108c
SS
19239@end menu
19240
6d2ebf8b 19241@node Assignment
79a6e687 19242@section Assignment to Variables
c906108c
SS
19243
19244@cindex assignment
19245@cindex setting variables
19246To alter the value of a variable, evaluate an assignment expression.
19247@xref{Expressions, ,Expressions}. For example,
19248
474c8240 19249@smallexample
c906108c 19250print x=4
474c8240 19251@end smallexample
c906108c
SS
19252
19253@noindent
19254stores the value 4 into the variable @code{x}, and then prints the
5d161b24 19255value of the assignment expression (which is 4).
c906108c
SS
19256@xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
19257information on operators in supported languages.
c906108c
SS
19258
19259@kindex set variable
19260@cindex variables, setting
19261If you are not interested in seeing the value of the assignment, use the
19262@code{set} command instead of the @code{print} command. @code{set} is
19263really the same as @code{print} except that the expression's value is
19264not printed and is not put in the value history (@pxref{Value History,
79a6e687 19265,Value History}). The expression is evaluated only for its effects.
c906108c 19266
c906108c
SS
19267If the beginning of the argument string of the @code{set} command
19268appears identical to a @code{set} subcommand, use the @code{set
19269variable} command instead of just @code{set}. This command is identical
19270to @code{set} except for its lack of subcommands. For example, if your
19271program has a variable @code{width}, you get an error if you try to set
19272a new value with just @samp{set width=13}, because @value{GDBN} has the
19273command @code{set width}:
19274
474c8240 19275@smallexample
c906108c
SS
19276(@value{GDBP}) whatis width
19277type = double
19278(@value{GDBP}) p width
19279$4 = 13
19280(@value{GDBP}) set width=47
19281Invalid syntax in expression.
474c8240 19282@end smallexample
c906108c
SS
19283
19284@noindent
19285The invalid expression, of course, is @samp{=47}. In
19286order to actually set the program's variable @code{width}, use
19287
474c8240 19288@smallexample
c906108c 19289(@value{GDBP}) set var width=47
474c8240 19290@end smallexample
53a5351d 19291
c906108c
SS
19292Because the @code{set} command has many subcommands that can conflict
19293with the names of program variables, it is a good idea to use the
19294@code{set variable} command instead of just @code{set}. For example, if
19295your program has a variable @code{g}, you run into problems if you try
19296to set a new value with just @samp{set g=4}, because @value{GDBN} has
19297the command @code{set gnutarget}, abbreviated @code{set g}:
19298
474c8240 19299@smallexample
c906108c
SS
19300@group
19301(@value{GDBP}) whatis g
19302type = double
19303(@value{GDBP}) p g
19304$1 = 1
19305(@value{GDBP}) set g=4
2df3850c 19306(@value{GDBP}) p g
c906108c
SS
19307$2 = 1
19308(@value{GDBP}) r
19309The program being debugged has been started already.
19310Start it from the beginning? (y or n) y
19311Starting program: /home/smith/cc_progs/a.out
6d2ebf8b
SS
19312"/home/smith/cc_progs/a.out": can't open to read symbols:
19313 Invalid bfd target.
c906108c
SS
19314(@value{GDBP}) show g
19315The current BFD target is "=4".
19316@end group
474c8240 19317@end smallexample
c906108c
SS
19318
19319@noindent
19320The program variable @code{g} did not change, and you silently set the
19321@code{gnutarget} to an invalid value. In order to set the variable
19322@code{g}, use
19323
474c8240 19324@smallexample
c906108c 19325(@value{GDBP}) set var g=4
474c8240 19326@end smallexample
c906108c
SS
19327
19328@value{GDBN} allows more implicit conversions in assignments than C; you can
19329freely store an integer value into a pointer variable or vice versa,
19330and you can convert any structure to any other structure that is the
19331same length or shorter.
19332@comment FIXME: how do structs align/pad in these conversions?
19333@comment /doc@cygnus.com 18dec1990
19334
19335To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
19336construct to generate a value of specified type at a specified address
19337(@pxref{Expressions, ,Expressions}). For example, @code{@{int@}0x83040} refers
19338to memory location @code{0x83040} as an integer (which implies a certain size
19339and representation in memory), and
19340
474c8240 19341@smallexample
c906108c 19342set @{int@}0x83040 = 4
474c8240 19343@end smallexample
c906108c
SS
19344
19345@noindent
19346stores the value 4 into that memory location.
19347
6d2ebf8b 19348@node Jumping
79a6e687 19349@section Continuing at a Different Address
c906108c
SS
19350
19351Ordinarily, when you continue your program, you do so at the place where
19352it stopped, with the @code{continue} command. You can instead continue at
19353an address of your own choosing, with the following commands:
19354
19355@table @code
19356@kindex jump
c1d780c2 19357@kindex j @r{(@code{jump})}
629500fa 19358@item jump @var{location}
c1d780c2 19359@itemx j @var{location}
629500fa
KS
19360Resume execution at @var{location}. Execution stops again immediately
19361if there is a breakpoint there. @xref{Specify Location}, for a description
19362of the different forms of @var{location}. It is common
2a25a5ba
EZ
19363practice to use the @code{tbreak} command in conjunction with
19364@code{jump}. @xref{Set Breaks, ,Setting Breakpoints}.
c906108c
SS
19365
19366The @code{jump} command does not change the current stack frame, or
19367the stack pointer, or the contents of any memory location or any
629500fa 19368register other than the program counter. If @var{location} is in
c906108c
SS
19369a different function from the one currently executing, the results may
19370be bizarre if the two functions expect different patterns of arguments or
19371of local variables. For this reason, the @code{jump} command requests
19372confirmation if the specified line is not in the function currently
19373executing. However, even bizarre results are predictable if you are
19374well acquainted with the machine-language code of your program.
c906108c
SS
19375@end table
19376
53a5351d
JM
19377On many systems, you can get much the same effect as the @code{jump}
19378command by storing a new value into the register @code{$pc}. The
19379difference is that this does not start your program running; it only
19380changes the address of where it @emph{will} run when you continue. For
19381example,
c906108c 19382
474c8240 19383@smallexample
c906108c 19384set $pc = 0x485
474c8240 19385@end smallexample
c906108c
SS
19386
19387@noindent
19388makes the next @code{continue} command or stepping command execute at
19389address @code{0x485}, rather than at the address where your program stopped.
79a6e687 19390@xref{Continuing and Stepping, ,Continuing and Stepping}.
c906108c
SS
19391
19392The most common occasion to use the @code{jump} command is to back
19393up---perhaps with more breakpoints set---over a portion of a program
19394that has already executed, in order to examine its execution in more
19395detail.
19396
c906108c 19397@c @group
6d2ebf8b 19398@node Signaling
79a6e687 19399@section Giving your Program a Signal
9c16f35a 19400@cindex deliver a signal to a program
c906108c
SS
19401
19402@table @code
19403@kindex signal
19404@item signal @var{signal}
70509625 19405Resume execution where your program is stopped, but immediately give it the
697aa1b7 19406signal @var{signal}. The @var{signal} can be the name or the number of a
c906108c
SS
19407signal. For example, on many systems @code{signal 2} and @code{signal
19408SIGINT} are both ways of sending an interrupt signal.
19409
19410Alternatively, if @var{signal} is zero, continue execution without
19411giving a signal. This is useful when your program stopped on account of
ae606bee 19412a signal and would ordinarily see the signal when resumed with the
c906108c
SS
19413@code{continue} command; @samp{signal 0} causes it to resume without a
19414signal.
19415
70509625
PA
19416@emph{Note:} When resuming a multi-threaded program, @var{signal} is
19417delivered to the currently selected thread, not the thread that last
19418reported a stop. This includes the situation where a thread was
19419stopped due to a signal. So if you want to continue execution
19420suppressing the signal that stopped a thread, you should select that
19421same thread before issuing the @samp{signal 0} command. If you issue
19422the @samp{signal 0} command with another thread as the selected one,
19423@value{GDBN} detects that and asks for confirmation.
19424
c906108c
SS
19425Invoking the @code{signal} command is not the same as invoking the
19426@code{kill} utility from the shell. Sending a signal with @code{kill}
19427causes @value{GDBN} to decide what to do with the signal depending on
19428the signal handling tables (@pxref{Signals}). The @code{signal} command
19429passes the signal directly to your program.
19430
81219e53
DE
19431@code{signal} does not repeat when you press @key{RET} a second time
19432after executing the command.
19433
19434@kindex queue-signal
19435@item queue-signal @var{signal}
19436Queue @var{signal} to be delivered immediately to the current thread
19437when execution of the thread resumes. The @var{signal} can be the name or
19438the number of a signal. For example, on many systems @code{signal 2} and
19439@code{signal SIGINT} are both ways of sending an interrupt signal.
19440The handling of the signal must be set to pass the signal to the program,
19441otherwise @value{GDBN} will report an error.
19442You can control the handling of signals from @value{GDBN} with the
19443@code{handle} command (@pxref{Signals}).
19444
19445Alternatively, if @var{signal} is zero, any currently queued signal
19446for the current thread is discarded and when execution resumes no signal
19447will be delivered. This is useful when your program stopped on account
19448of a signal and would ordinarily see the signal when resumed with the
19449@code{continue} command.
19450
19451This command differs from the @code{signal} command in that the signal
19452is just queued, execution is not resumed. And @code{queue-signal} cannot
19453be used to pass a signal whose handling state has been set to @code{nopass}
19454(@pxref{Signals}).
19455@end table
19456@c @end group
c906108c 19457
e5f8a7cc
PA
19458@xref{stepping into signal handlers}, for information on how stepping
19459commands behave when the thread has a signal queued.
19460
6d2ebf8b 19461@node Returning
79a6e687 19462@section Returning from a Function
c906108c
SS
19463
19464@table @code
19465@cindex returning from a function
19466@kindex return
19467@item return
19468@itemx return @var{expression}
19469You can cancel execution of a function call with the @code{return}
19470command. If you give an
19471@var{expression} argument, its value is used as the function's return
19472value.
19473@end table
19474
19475When you use @code{return}, @value{GDBN} discards the selected stack frame
19476(and all frames within it). You can think of this as making the
19477discarded frame return prematurely. If you wish to specify a value to
19478be returned, give that value as the argument to @code{return}.
19479
19480This pops the selected stack frame (@pxref{Selection, ,Selecting a
79a6e687 19481Frame}), and any other frames inside of it, leaving its caller as the
c906108c
SS
19482innermost remaining frame. That frame becomes selected. The
19483specified value is stored in the registers used for returning values
19484of functions.
19485
19486The @code{return} command does not resume execution; it leaves the
19487program stopped in the state that would exist if the function had just
19488returned. In contrast, the @code{finish} command (@pxref{Continuing
79a6e687 19489and Stepping, ,Continuing and Stepping}) resumes execution until the
c906108c
SS
19490selected stack frame returns naturally.
19491
61ff14c6
JK
19492@value{GDBN} needs to know how the @var{expression} argument should be set for
19493the inferior. The concrete registers assignment depends on the OS ABI and the
19494type being returned by the selected stack frame. For example it is common for
19495OS ABI to return floating point values in FPU registers while integer values in
19496CPU registers. Still some ABIs return even floating point values in CPU
19497registers. Larger integer widths (such as @code{long long int}) also have
19498specific placement rules. @value{GDBN} already knows the OS ABI from its
19499current target so it needs to find out also the type being returned to make the
19500assignment into the right register(s).
19501
19502Normally, the selected stack frame has debug info. @value{GDBN} will always
19503use the debug info instead of the implicit type of @var{expression} when the
19504debug info is available. For example, if you type @kbd{return -1}, and the
19505function in the current stack frame is declared to return a @code{long long
19506int}, @value{GDBN} transparently converts the implicit @code{int} value of -1
19507into a @code{long long int}:
19508
19509@smallexample
19510Breakpoint 1, func () at gdb.base/return-nodebug.c:29
1951129 return 31;
19512(@value{GDBP}) return -1
19513Make func return now? (y or n) y
19514#0 0x004004f6 in main () at gdb.base/return-nodebug.c:43
1951543 printf ("result=%lld\n", func ());
19516(@value{GDBP})
19517@end smallexample
19518
19519However, if the selected stack frame does not have a debug info, e.g., if the
19520function was compiled without debug info, @value{GDBN} has to find out the type
19521to return from user. Specifying a different type by mistake may set the value
19522in different inferior registers than the caller code expects. For example,
19523typing @kbd{return -1} with its implicit type @code{int} would set only a part
19524of a @code{long long int} result for a debug info less function (on 32-bit
19525architectures). Therefore the user is required to specify the return type by
19526an appropriate cast explicitly:
19527
19528@smallexample
19529Breakpoint 2, 0x0040050b in func ()
19530(@value{GDBP}) return -1
19531Return value type not available for selected stack frame.
19532Please use an explicit cast of the value to return.
19533(@value{GDBP}) return (long long int) -1
19534Make selected stack frame return now? (y or n) y
19535#0 0x00400526 in main ()
19536(@value{GDBP})
19537@end smallexample
19538
6d2ebf8b 19539@node Calling
79a6e687 19540@section Calling Program Functions
c906108c 19541
f8568604 19542@table @code
c906108c 19543@cindex calling functions
f8568604
EZ
19544@cindex inferior functions, calling
19545@item print @var{expr}
d3e8051b 19546Evaluate the expression @var{expr} and display the resulting value.
697aa1b7 19547The expression may include calls to functions in the program being
f8568604
EZ
19548debugged.
19549
c906108c 19550@kindex call
c906108c
SS
19551@item call @var{expr}
19552Evaluate the expression @var{expr} without displaying @code{void}
19553returned values.
c906108c
SS
19554
19555You can use this variant of the @code{print} command if you want to
f8568604
EZ
19556execute a function from your program that does not return anything
19557(a.k.a.@: @dfn{a void function}), but without cluttering the output
19558with @code{void} returned values that @value{GDBN} will otherwise
19559print. If the result is not void, it is printed and saved in the
19560value history.
19561@end table
19562
9c16f35a
EZ
19563It is possible for the function you call via the @code{print} or
19564@code{call} command to generate a signal (e.g., if there's a bug in
19565the function, or if you passed it incorrect arguments). What happens
19566in that case is controlled by the @code{set unwindonsignal} command.
19567
7cd1089b
PM
19568Similarly, with a C@t{++} program it is possible for the function you
19569call via the @code{print} or @code{call} command to generate an
19570exception that is not handled due to the constraints of the dummy
19571frame. In this case, any exception that is raised in the frame, but has
19572an out-of-frame exception handler will not be found. GDB builds a
19573dummy-frame for the inferior function call, and the unwinder cannot
19574seek for exception handlers outside of this dummy-frame. What happens
19575in that case is controlled by the
19576@code{set unwind-on-terminating-exception} command.
19577
9c16f35a
EZ
19578@table @code
19579@item set unwindonsignal
19580@kindex set unwindonsignal
19581@cindex unwind stack in called functions
19582@cindex call dummy stack unwinding
19583Set unwinding of the stack if a signal is received while in a function
19584that @value{GDBN} called in the program being debugged. If set to on,
19585@value{GDBN} unwinds the stack it created for the call and restores
19586the context to what it was before the call. If set to off (the
19587default), @value{GDBN} stops in the frame where the signal was
19588received.
19589
19590@item show unwindonsignal
19591@kindex show unwindonsignal
19592Show the current setting of stack unwinding in the functions called by
19593@value{GDBN}.
7cd1089b
PM
19594
19595@item set unwind-on-terminating-exception
19596@kindex set unwind-on-terminating-exception
19597@cindex unwind stack in called functions with unhandled exceptions
19598@cindex call dummy stack unwinding on unhandled exception.
19599Set unwinding of the stack if a C@t{++} exception is raised, but left
19600unhandled while in a function that @value{GDBN} called in the program being
19601debugged. If set to on (the default), @value{GDBN} unwinds the stack
19602it created for the call and restores the context to what it was before
19603the call. If set to off, @value{GDBN} the exception is delivered to
19604the default C@t{++} exception handler and the inferior terminated.
19605
19606@item show unwind-on-terminating-exception
19607@kindex show unwind-on-terminating-exception
19608Show the current setting of stack unwinding in the functions called by
19609@value{GDBN}.
19610
136afab8
PW
19611@item set may-call-functions
19612@kindex set may-call-functions
19613@cindex disabling calling functions in the program
19614@cindex calling functions in the program, disabling
19615Set permission to call functions in the program.
19616This controls whether @value{GDBN} will attempt to call functions in
19617the program, such as with expressions in the @code{print} command. It
19618defaults to @code{on}.
19619
19620To call a function in the program, @value{GDBN} has to temporarily
19621modify the state of the inferior. This has potentially undesired side
19622effects. Also, having @value{GDBN} call nested functions is likely to
19623be erroneous and may even crash the program being debugged. You can
19624avoid such hazards by forbidding @value{GDBN} from calling functions
19625in the program being debugged. If calling functions in the program
19626is forbidden, GDB will throw an error when a command (such as printing
19627an expression) starts a function call in the program.
19628
19629@item show may-call-functions
19630@kindex show may-call-functions
19631Show permission to call functions in the program.
19632
9c16f35a
EZ
19633@end table
19634
d69cf9b2
PA
19635@subsection Calling functions with no debug info
19636
19637@cindex no debug info functions
19638Sometimes, a function you wish to call is missing debug information.
19639In such case, @value{GDBN} does not know the type of the function,
19640including the types of the function's parameters. To avoid calling
19641the inferior function incorrectly, which could result in the called
19642function functioning erroneously and even crash, @value{GDBN} refuses
19643to call the function unless you tell it the type of the function.
19644
19645For prototyped (i.e.@: ANSI/ISO style) functions, there are two ways
19646to do that. The simplest is to cast the call to the function's
19647declared return type. For example:
19648
19649@smallexample
19650(@value{GDBP}) p getenv ("PATH")
19651'getenv' has unknown return type; cast the call to its declared return type
19652(@value{GDBP}) p (char *) getenv ("PATH")
19653$1 = 0x7fffffffe7ba "/usr/local/bin:/"...
19654@end smallexample
19655
19656Casting the return type of a no-debug function is equivalent to
19657casting the function to a pointer to a prototyped function that has a
19658prototype that matches the types of the passed-in arguments, and
19659calling that. I.e., the call above is equivalent to:
19660
19661@smallexample
19662(@value{GDBP}) p ((char * (*) (const char *)) getenv) ("PATH")
19663@end smallexample
19664
19665@noindent
19666and given this prototyped C or C++ function with float parameters:
19667
19668@smallexample
19669float multiply (float v1, float v2) @{ return v1 * v2; @}
19670@end smallexample
19671
19672@noindent
19673these calls are equivalent:
19674
19675@smallexample
19676(@value{GDBP}) p (float) multiply (2.0f, 3.0f)
19677(@value{GDBP}) p ((float (*) (float, float)) multiply) (2.0f, 3.0f)
19678@end smallexample
19679
19680If the function you wish to call is declared as unprototyped (i.e.@:
19681old K&R style), you must use the cast-to-function-pointer syntax, so
19682that @value{GDBN} knows that it needs to apply default argument
19683promotions (promote float arguments to double). @xref{ABI, float
19684promotion}. For example, given this unprototyped C function with
19685float parameters, and no debug info:
19686
19687@smallexample
19688float
19689multiply_noproto (v1, v2)
19690 float v1, v2;
19691@{
19692 return v1 * v2;
19693@}
19694@end smallexample
19695
19696@noindent
19697you call it like this:
19698
19699@smallexample
19700 (@value{GDBP}) p ((float (*) ()) multiply_noproto) (2.0f, 3.0f)
19701@end smallexample
c906108c 19702
6d2ebf8b 19703@node Patching
79a6e687 19704@section Patching Programs
7a292a7a 19705
c906108c
SS
19706@cindex patching binaries
19707@cindex writing into executables
c906108c 19708@cindex writing into corefiles
c906108c 19709
7a292a7a
SS
19710By default, @value{GDBN} opens the file containing your program's
19711executable code (or the corefile) read-only. This prevents accidental
19712alterations to machine code; but it also prevents you from intentionally
19713patching your program's binary.
c906108c
SS
19714
19715If you'd like to be able to patch the binary, you can specify that
19716explicitly with the @code{set write} command. For example, you might
19717want to turn on internal debugging flags, or even to make emergency
19718repairs.
19719
19720@table @code
19721@kindex set write
19722@item set write on
19723@itemx set write off
7a292a7a 19724If you specify @samp{set write on}, @value{GDBN} opens executable and
20924a55 19725core files for both reading and writing; if you specify @kbd{set write
c906108c
SS
19726off} (the default), @value{GDBN} opens them read-only.
19727
19728If you have already loaded a file, you must load it again (using the
7a292a7a
SS
19729@code{exec-file} or @code{core-file} command) after changing @code{set
19730write}, for your new setting to take effect.
c906108c
SS
19731
19732@item show write
19733@kindex show write
7a292a7a
SS
19734Display whether executable files and core files are opened for writing
19735as well as reading.
c906108c
SS
19736@end table
19737
bb2ec1b3
TT
19738@node Compiling and Injecting Code
19739@section Compiling and injecting code in @value{GDBN}
19740@cindex injecting code
19741@cindex writing into executables
19742@cindex compiling code
19743
19744@value{GDBN} supports on-demand compilation and code injection into
19745programs running under @value{GDBN}. GCC 5.0 or higher built with
19746@file{libcc1.so} must be installed for this functionality to be enabled.
19747This functionality is implemented with the following commands.
19748
19749@table @code
19750@kindex compile code
19751@item compile code @var{source-code}
19752@itemx compile code -raw @var{--} @var{source-code}
19753Compile @var{source-code} with the compiler language found as the current
19754language in @value{GDBN} (@pxref{Languages}). If compilation and
19755injection is not supported with the current language specified in
19756@value{GDBN}, or the compiler does not support this feature, an error
19757message will be printed. If @var{source-code} compiles and links
19758successfully, @value{GDBN} will load the object-code emitted,
19759and execute it within the context of the currently selected inferior.
19760It is important to note that the compiled code is executed immediately.
19761After execution, the compiled code is removed from @value{GDBN} and any
19762new types or variables you have defined will be deleted.
19763
19764The command allows you to specify @var{source-code} in two ways.
19765The simplest method is to provide a single line of code to the command.
19766E.g.:
19767
19768@smallexample
19769compile code printf ("hello world\n");
19770@end smallexample
19771
19772If you specify options on the command line as well as source code, they
19773may conflict. The @samp{--} delimiter can be used to separate options
19774from actual source code. E.g.:
19775
19776@smallexample
19777compile code -r -- printf ("hello world\n");
19778@end smallexample
19779
19780Alternatively you can enter source code as multiple lines of text. To
19781enter this mode, invoke the @samp{compile code} command without any text
19782following the command. This will start the multiple-line editor and
19783allow you to type as many lines of source code as required. When you
19784have completed typing, enter @samp{end} on its own line to exit the
19785editor.
19786
19787@smallexample
19788compile code
19789>printf ("hello\n");
19790>printf ("world\n");
19791>end
19792@end smallexample
19793
19794Specifying @samp{-raw}, prohibits @value{GDBN} from wrapping the
19795provided @var{source-code} in a callable scope. In this case, you must
19796specify the entry point of the code by defining a function named
19797@code{_gdb_expr_}. The @samp{-raw} code cannot access variables of the
19798inferior. Using @samp{-raw} option may be needed for example when
19799@var{source-code} requires @samp{#include} lines which may conflict with
19800inferior symbols otherwise.
19801
19802@kindex compile file
19803@item compile file @var{filename}
19804@itemx compile file -raw @var{filename}
19805Like @code{compile code}, but take the source code from @var{filename}.
19806
19807@smallexample
19808compile file /home/user/example.c
19809@end smallexample
19810@end table
19811
36de76f9 19812@table @code
3345721a
PA
19813@item compile print [[@var{options}] --] @var{expr}
19814@itemx compile print [[@var{options}] --] /@var{f} @var{expr}
36de76f9
JK
19815Compile and execute @var{expr} with the compiler language found as the
19816current language in @value{GDBN} (@pxref{Languages}). By default the
19817value of @var{expr} is printed in a format appropriate to its data type;
19818you can choose a different format by specifying @samp{/@var{f}}, where
19819@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
3345721a
PA
19820Formats}. The @code{compile print} command accepts the same options
19821as the @code{print} command; see @ref{print options}.
36de76f9 19822
3345721a
PA
19823@item compile print [[@var{options}] --]
19824@itemx compile print [[@var{options}] --] /@var{f}
36de76f9
JK
19825@cindex reprint the last value
19826Alternatively you can enter the expression (source code producing it) as
19827multiple lines of text. To enter this mode, invoke the @samp{compile print}
19828command without any text following the command. This will start the
19829multiple-line editor.
19830@end table
19831
e7a8570f
JK
19832@noindent
19833The process of compiling and injecting the code can be inspected using:
19834
19835@table @code
19836@anchor{set debug compile}
19837@item set debug compile
19838@cindex compile command debugging info
19839Turns on or off display of @value{GDBN} process of compiling and
19840injecting the code. The default is off.
19841
19842@item show debug compile
19843Displays the current state of displaying @value{GDBN} process of
19844compiling and injecting the code.
078a0207
KS
19845
19846@anchor{set debug compile-cplus-types}
19847@item set debug compile-cplus-types
19848@cindex compile C@t{++} type conversion
19849Turns on or off the display of C@t{++} type conversion debugging information.
19850The default is off.
19851
19852@item show debug compile-cplus-types
19853Displays the current state of displaying debugging information for
19854C@t{++} type conversion.
e7a8570f
JK
19855@end table
19856
19857@subsection Compilation options for the @code{compile} command
19858
19859@value{GDBN} needs to specify the right compilation options for the code
19860to be injected, in part to make its ABI compatible with the inferior
19861and in part to make the injected code compatible with @value{GDBN}'s
19862injecting process.
19863
19864@noindent
19865The options used, in increasing precedence:
19866
19867@table @asis
19868@item target architecture and OS options (@code{gdbarch})
19869These options depend on target processor type and target operating
19870system, usually they specify at least 32-bit (@code{-m32}) or 64-bit
19871(@code{-m64}) compilation option.
19872
19873@item compilation options recorded in the target
19874@value{NGCC} (since version 4.7) stores the options used for compilation
19875into @code{DW_AT_producer} part of DWARF debugging information according
19876to the @value{NGCC} option @code{-grecord-gcc-switches}. One has to
19877explicitly specify @code{-g} during inferior compilation otherwise
19878@value{NGCC} produces no DWARF. This feature is only relevant for
19879platforms where @code{-g} produces DWARF by default, otherwise one may
19880try to enforce DWARF by using @code{-gdwarf-4}.
19881
19882@item compilation options set by @code{set compile-args}
19883@end table
19884
19885@noindent
19886You can override compilation options using the following command:
19887
19888@table @code
19889@item set compile-args
19890@cindex compile command options override
19891Set compilation options used for compiling and injecting code with the
19892@code{compile} commands. These options override any conflicting ones
19893from the target architecture and/or options stored during inferior
19894compilation.
19895
19896@item show compile-args
19897Displays the current state of compilation options override.
19898This does not show all the options actually used during compilation,
19899use @ref{set debug compile} for that.
19900@end table
19901
bb2ec1b3
TT
19902@subsection Caveats when using the @code{compile} command
19903
19904There are a few caveats to keep in mind when using the @code{compile}
19905command. As the caveats are different per language, the table below
19906highlights specific issues on a per language basis.
19907
19908@table @asis
19909@item C code examples and caveats
19910When the language in @value{GDBN} is set to @samp{C}, the compiler will
19911attempt to compile the source code with a @samp{C} compiler. The source
19912code provided to the @code{compile} command will have much the same
19913access to variables and types as it normally would if it were part of
19914the program currently being debugged in @value{GDBN}.
19915
19916Below is a sample program that forms the basis of the examples that
19917follow. This program has been compiled and loaded into @value{GDBN},
19918much like any other normal debugging session.
19919
19920@smallexample
19921void function1 (void)
19922@{
19923 int i = 42;
19924 printf ("function 1\n");
19925@}
19926
19927void function2 (void)
19928@{
19929 int j = 12;
19930 function1 ();
19931@}
19932
19933int main(void)
19934@{
19935 int k = 6;
19936 int *p;
19937 function2 ();
19938 return 0;
19939@}
19940@end smallexample
19941
19942For the purposes of the examples in this section, the program above has
19943been compiled, loaded into @value{GDBN}, stopped at the function
19944@code{main}, and @value{GDBN} is awaiting input from the user.
19945
19946To access variables and types for any program in @value{GDBN}, the
19947program must be compiled and packaged with debug information. The
19948@code{compile} command is not an exception to this rule. Without debug
19949information, you can still use the @code{compile} command, but you will
19950be very limited in what variables and types you can access.
19951
19952So with that in mind, the example above has been compiled with debug
19953information enabled. The @code{compile} command will have access to
19954all variables and types (except those that may have been optimized
19955out). Currently, as @value{GDBN} has stopped the program in the
19956@code{main} function, the @code{compile} command would have access to
19957the variable @code{k}. You could invoke the @code{compile} command
19958and type some source code to set the value of @code{k}. You can also
19959read it, or do anything with that variable you would normally do in
19960@code{C}. Be aware that changes to inferior variables in the
19961@code{compile} command are persistent. In the following example:
19962
19963@smallexample
19964compile code k = 3;
19965@end smallexample
19966
19967@noindent
19968the variable @code{k} is now 3. It will retain that value until
19969something else in the example program changes it, or another
19970@code{compile} command changes it.
19971
19972Normal scope and access rules apply to source code compiled and
19973injected by the @code{compile} command. In the example, the variables
19974@code{j} and @code{k} are not accessible yet, because the program is
19975currently stopped in the @code{main} function, where these variables
19976are not in scope. Therefore, the following command
19977
19978@smallexample
19979compile code j = 3;
19980@end smallexample
19981
19982@noindent
19983will result in a compilation error message.
19984
19985Once the program is continued, execution will bring these variables in
19986scope, and they will become accessible; then the code you specify via
19987the @code{compile} command will be able to access them.
19988
19989You can create variables and types with the @code{compile} command as
19990part of your source code. Variables and types that are created as part
19991of the @code{compile} command are not visible to the rest of the program for
19992the duration of its run. This example is valid:
19993
19994@smallexample
19995compile code int ff = 5; printf ("ff is %d\n", ff);
19996@end smallexample
19997
19998However, if you were to type the following into @value{GDBN} after that
19999command has completed:
20000
20001@smallexample
20002compile code printf ("ff is %d\n'', ff);
20003@end smallexample
20004
20005@noindent
20006a compiler error would be raised as the variable @code{ff} no longer
20007exists. Object code generated and injected by the @code{compile}
20008command is removed when its execution ends. Caution is advised
20009when assigning to program variables values of variables created by the
20010code submitted to the @code{compile} command. This example is valid:
20011
20012@smallexample
20013compile code int ff = 5; k = ff;
20014@end smallexample
20015
20016The value of the variable @code{ff} is assigned to @code{k}. The variable
20017@code{k} does not require the existence of @code{ff} to maintain the value
20018it has been assigned. However, pointers require particular care in
20019assignment. If the source code compiled with the @code{compile} command
20020changed the address of a pointer in the example program, perhaps to a
20021variable created in the @code{compile} command, that pointer would point
20022to an invalid location when the command exits. The following example
20023would likely cause issues with your debugged program:
20024
20025@smallexample
20026compile code int ff = 5; p = &ff;
20027@end smallexample
20028
20029In this example, @code{p} would point to @code{ff} when the
20030@code{compile} command is executing the source code provided to it.
20031However, as variables in the (example) program persist with their
20032assigned values, the variable @code{p} would point to an invalid
20033location when the command exists. A general rule should be followed
20034in that you should either assign @code{NULL} to any assigned pointers,
20035or restore a valid location to the pointer before the command exits.
20036
20037Similar caution must be exercised with any structs, unions, and typedefs
20038defined in @code{compile} command. Types defined in the @code{compile}
20039command will no longer be available in the next @code{compile} command.
20040Therefore, if you cast a variable to a type defined in the
20041@code{compile} command, care must be taken to ensure that any future
20042need to resolve the type can be achieved.
20043
20044@smallexample
20045(gdb) compile code static struct a @{ int a; @} v = @{ 42 @}; argv = &v;
20046(gdb) compile code printf ("%d\n", ((struct a *) argv)->a);
20047gdb command line:1:36: error: dereferencing pointer to incomplete type ‘struct a’
20048Compilation failed.
20049(gdb) compile code struct a @{ int a; @}; printf ("%d\n", ((struct a *) argv)->a);
2005042
20051@end smallexample
20052
20053Variables that have been optimized away by the compiler are not
20054accessible to the code submitted to the @code{compile} command.
20055Access to those variables will generate a compiler error which @value{GDBN}
20056will print to the console.
20057@end table
20058
e7a8570f
JK
20059@subsection Compiler search for the @code{compile} command
20060
6e41ddec
JK
20061@value{GDBN} needs to find @value{NGCC} for the inferior being debugged
20062which may not be obvious for remote targets of different architecture
20063than where @value{GDBN} is running. Environment variable @code{PATH} on
e7a8570f 20064@value{GDBN} host is searched for @value{NGCC} binary matching the
6e41ddec
JK
20065target architecture and operating system. This search can be overriden
20066by @code{set compile-gcc} @value{GDBN} command below. @code{PATH} is
20067taken from shell that executed @value{GDBN}, it is not the value set by
20068@value{GDBN} command @code{set environment}). @xref{Environment}.
20069
e7a8570f
JK
20070
20071Specifically @code{PATH} is searched for binaries matching regular expression
20072@code{@var{arch}(-[^-]*)?-@var{os}-gcc} according to the inferior target being
20073debugged. @var{arch} is processor name --- multiarch is supported, so for
20074example both @code{i386} and @code{x86_64} targets look for pattern
20075@code{(x86_64|i.86)} and both @code{s390} and @code{s390x} targets look
20076for pattern @code{s390x?}. @var{os} is currently supported only for
20077pattern @code{linux(-gnu)?}.
20078
6e41ddec
JK
20079On Posix hosts the compiler driver @value{GDBN} needs to find also
20080shared library @file{libcc1.so} from the compiler. It is searched in
20081default shared library search path (overridable with usual environment
20082variable @code{LD_LIBRARY_PATH}), unrelated to @code{PATH} or @code{set
20083compile-gcc} settings. Contrary to it @file{libcc1plugin.so} is found
20084according to the installation of the found compiler --- as possibly
20085specified by the @code{set compile-gcc} command.
20086
20087@table @code
20088@item set compile-gcc
20089@cindex compile command driver filename override
20090Set compilation command used for compiling and injecting code with the
20091@code{compile} commands. If this option is not set (it is set to
20092an empty string), the search described above will occur --- that is the
20093default.
20094
20095@item show compile-gcc
20096Displays the current compile command @value{NGCC} driver filename.
20097If set, it is the main command @command{gcc}, found usually for example
20098under name @file{x86_64-linux-gnu-gcc}.
20099@end table
20100
6d2ebf8b 20101@node GDB Files
c906108c
SS
20102@chapter @value{GDBN} Files
20103
7a292a7a
SS
20104@value{GDBN} needs to know the file name of the program to be debugged,
20105both in order to read its symbol table and in order to start your
20106program. To debug a core dump of a previous run, you must also tell
20107@value{GDBN} the name of the core dump file.
c906108c
SS
20108
20109@menu
20110* Files:: Commands to specify files
2b4bf6af 20111* File Caching:: Information about @value{GDBN}'s file caching
5b5d99cf 20112* Separate Debug Files:: Debugging information in separate files
608e2dbb 20113* MiniDebugInfo:: Debugging information in a special section
9291a0cd 20114* Index Files:: Index files speed up GDB
c906108c 20115* Symbol Errors:: Errors reading symbol files
b14b1491 20116* Data Files:: GDB data files
c906108c
SS
20117@end menu
20118
6d2ebf8b 20119@node Files
79a6e687 20120@section Commands to Specify Files
c906108c 20121
7a292a7a 20122@cindex symbol table
c906108c 20123@cindex core dump file
7a292a7a
SS
20124
20125You may want to specify executable and core dump file names. The usual
20126way to do this is at start-up time, using the arguments to
20127@value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
20128Out of @value{GDBN}}).
c906108c
SS
20129
20130Occasionally it is necessary to change to a different file during a
397ca115
EZ
20131@value{GDBN} session. Or you may run @value{GDBN} and forget to
20132specify a file you want to use. Or you are debugging a remote target
79a6e687
BW
20133via @code{gdbserver} (@pxref{Server, file, Using the @code{gdbserver}
20134Program}). In these situations the @value{GDBN} commands to specify
0869d01b 20135new files are useful.
c906108c
SS
20136
20137@table @code
20138@cindex executable file
20139@kindex file
20140@item file @var{filename}
20141Use @var{filename} as the program to be debugged. It is read for its
20142symbols and for the contents of pure memory. It is also the program
20143executed when you use the @code{run} command. If you do not specify a
5d161b24
DB
20144directory and the file is not found in the @value{GDBN} working directory,
20145@value{GDBN} uses the environment variable @code{PATH} as a list of
20146directories to search, just as the shell does when looking for a program
20147to run. You can change the value of this variable, for both @value{GDBN}
c906108c
SS
20148and your program, using the @code{path} command.
20149
fc8be69e
EZ
20150@cindex unlinked object files
20151@cindex patching object files
20152You can load unlinked object @file{.o} files into @value{GDBN} using
20153the @code{file} command. You will not be able to ``run'' an object
20154file, but you can disassemble functions and inspect variables. Also,
20155if the underlying BFD functionality supports it, you could use
20156@kbd{gdb -write} to patch object files using this technique. Note
20157that @value{GDBN} can neither interpret nor modify relocations in this
20158case, so branches and some initialized variables will appear to go to
20159the wrong place. But this feature is still handy from time to time.
20160
c906108c
SS
20161@item file
20162@code{file} with no argument makes @value{GDBN} discard any information it
20163has on both executable file and the symbol table.
20164
20165@kindex exec-file
20166@item exec-file @r{[} @var{filename} @r{]}
20167Specify that the program to be run (but not the symbol table) is found
20168in @var{filename}. @value{GDBN} searches the environment variable @code{PATH}
20169if necessary to locate your program. Omitting @var{filename} means to
20170discard information on the executable file.
20171
20172@kindex symbol-file
d4d429d5 20173@item symbol-file @r{[} @var{filename} @r{[} -o @var{offset} @r{]]}
c906108c
SS
20174Read symbol table information from file @var{filename}. @code{PATH} is
20175searched when necessary. Use the @code{file} command to get both symbol
20176table and program to run from the same file.
20177
d4d429d5
PT
20178If an optional @var{offset} is specified, it is added to the start
20179address of each section in the symbol file. This is useful if the
20180program is relocated at runtime, such as the Linux kernel with kASLR
20181enabled.
20182
c906108c
SS
20183@code{symbol-file} with no argument clears out @value{GDBN} information on your
20184program's symbol table.
20185
ae5a43e0
DJ
20186The @code{symbol-file} command causes @value{GDBN} to forget the contents of
20187some breakpoints and auto-display expressions. This is because they may
20188contain pointers to the internal data recording symbols and data types,
20189which are part of the old symbol table data being discarded inside
20190@value{GDBN}.
c906108c
SS
20191
20192@code{symbol-file} does not repeat if you press @key{RET} again after
20193executing it once.
20194
20195When @value{GDBN} is configured for a particular environment, it
20196understands debugging information in whatever format is the standard
20197generated for that environment; you may use either a @sc{gnu} compiler, or
20198other compilers that adhere to the local conventions.
c906108c 20199Best results are usually obtained from @sc{gnu} compilers; for example,
e22ea452 20200using @code{@value{NGCC}} you can generate debugging information for
c906108c 20201optimized code.
c906108c
SS
20202
20203For most kinds of object files, with the exception of old SVR3 systems
20204using COFF, the @code{symbol-file} command does not normally read the
20205symbol table in full right away. Instead, it scans the symbol table
20206quickly to find which source files and which symbols are present. The
20207details are read later, one source file at a time, as they are needed.
20208
20209The purpose of this two-stage reading strategy is to make @value{GDBN}
20210start up faster. For the most part, it is invisible except for
20211occasional pauses while the symbol table details for a particular source
20212file are being read. (The @code{set verbose} command can turn these
20213pauses into messages if desired. @xref{Messages/Warnings, ,Optional
79a6e687 20214Warnings and Messages}.)
c906108c 20215
c906108c
SS
20216We have not implemented the two-stage strategy for COFF yet. When the
20217symbol table is stored in COFF format, @code{symbol-file} reads the
20218symbol table data in full right away. Note that ``stabs-in-COFF''
20219still does the two-stage strategy, since the debug info is actually
20220in stabs format.
20221
20222@kindex readnow
20223@cindex reading symbols immediately
20224@cindex symbols, reading immediately
6ac33a4e
TT
20225@item symbol-file @r{[} -readnow @r{]} @var{filename}
20226@itemx file @r{[} -readnow @r{]} @var{filename}
c906108c
SS
20227You can override the @value{GDBN} two-stage strategy for reading symbol
20228tables by using the @samp{-readnow} option with any of the commands that
20229load symbol table information, if you want to be sure @value{GDBN} has the
5d161b24 20230entire symbol table available.
c906108c 20231
97cbe998
SDJ
20232@cindex @code{-readnever}, option for symbol-file command
20233@cindex never read symbols
20234@cindex symbols, never read
20235@item symbol-file @r{[} -readnever @r{]} @var{filename}
20236@itemx file @r{[} -readnever @r{]} @var{filename}
20237You can instruct @value{GDBN} to never read the symbolic information
20238contained in @var{filename} by using the @samp{-readnever} option.
20239@xref{--readnever}.
20240
c906108c
SS
20241@c FIXME: for now no mention of directories, since this seems to be in
20242@c flux. 13mar1992 status is that in theory GDB would look either in
20243@c current dir or in same dir as myprog; but issues like competing
20244@c GDB's, or clutter in system dirs, mean that in practice right now
20245@c only current dir is used. FFish says maybe a special GDB hierarchy
20246@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
20247@c files.
20248
c906108c 20249@kindex core-file
09d4efe1 20250@item core-file @r{[}@var{filename}@r{]}
4644b6e3 20251@itemx core
c906108c
SS
20252Specify the whereabouts of a core dump file to be used as the ``contents
20253of memory''. Traditionally, core files contain only some parts of the
20254address space of the process that generated them; @value{GDBN} can access the
20255executable file itself for other parts.
20256
20257@code{core-file} with no argument specifies that no core file is
20258to be used.
20259
20260Note that the core file is ignored when your program is actually running
7a292a7a
SS
20261under @value{GDBN}. So, if you have been running your program and you
20262wish to debug a core file instead, you must kill the subprocess in which
20263the program is running. To do this, use the @code{kill} command
79a6e687 20264(@pxref{Kill Process, ,Killing the Child Process}).
c906108c 20265
c906108c
SS
20266@kindex add-symbol-file
20267@cindex dynamic linking
291f9a96 20268@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
20269The @code{add-symbol-file} command reads additional symbol table
20270information from the file @var{filename}. You would use this command
20271when @var{filename} has been dynamically loaded (by some other means)
ed6dfe51
PT
20272into the program that is running. The @var{textaddress} parameter gives
20273the memory address at which the file's text section has been loaded.
20274You can additionally specify the base address of other sections using
20275an arbitrary number of @samp{-s @var{section} @var{address}} pairs.
20276If a section is omitted, @value{GDBN} will use its default addresses
20277as found in @var{filename}. Any @var{address} or @var{textaddress}
20278can be given as an expression.
c906108c 20279
291f9a96
PT
20280If an optional @var{offset} is specified, it is added to the start
20281address of each section, except those for which the address was
20282specified explicitly.
20283
c906108c
SS
20284The symbol table of the file @var{filename} is added to the symbol table
20285originally read with the @code{symbol-file} command. You can use the
96a2c332 20286@code{add-symbol-file} command any number of times; the new symbol data
98297bf6
NB
20287thus read is kept in addition to the old.
20288
20289Changes can be reverted using the command @code{remove-symbol-file}.
c906108c 20290
17d9d558
JB
20291@cindex relocatable object files, reading symbols from
20292@cindex object files, relocatable, reading symbols from
20293@cindex reading symbols from relocatable object files
20294@cindex symbols, reading from relocatable object files
20295@cindex @file{.o} files, reading symbols from
20296Although @var{filename} is typically a shared library file, an
20297executable file, or some other object file which has been fully
20298relocated for loading into a process, you can also load symbolic
20299information from relocatable @file{.o} files, as long as:
20300
20301@itemize @bullet
20302@item
20303the file's symbolic information refers only to linker symbols defined in
20304that file, not to symbols defined by other object files,
20305@item
20306every section the file's symbolic information refers to has actually
20307been loaded into the inferior, as it appears in the file, and
20308@item
20309you can determine the address at which every section was loaded, and
20310provide these to the @code{add-symbol-file} command.
20311@end itemize
20312
20313@noindent
20314Some embedded operating systems, like Sun Chorus and VxWorks, can load
20315relocatable files into an already running program; such systems
20316typically make the requirements above easy to meet. However, it's
20317important to recognize that many native systems use complex link
49efadf5 20318procedures (@code{.linkonce} section factoring and C@t{++} constructor table
17d9d558
JB
20319assembly, for example) that make the requirements difficult to meet. In
20320general, one cannot assume that using @code{add-symbol-file} to read a
20321relocatable object file's symbolic information will have the same effect
20322as linking the relocatable object file into the program in the normal
20323way.
20324
c906108c
SS
20325@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
20326
98297bf6
NB
20327@kindex remove-symbol-file
20328@item remove-symbol-file @var{filename}
20329@item remove-symbol-file -a @var{address}
20330Remove a symbol file added via the @code{add-symbol-file} command. The
20331file to remove can be identified by its @var{filename} or by an @var{address}
20332that lies within the boundaries of this symbol file in memory. Example:
20333
20334@smallexample
20335(gdb) add-symbol-file /home/user/gdb/mylib.so 0x7ffff7ff9480
20336add symbol table from file "/home/user/gdb/mylib.so" at
20337 .text_addr = 0x7ffff7ff9480
20338(y or n) y
20339Reading symbols from /home/user/gdb/mylib.so...done.
20340(gdb) remove-symbol-file -a 0x7ffff7ff9480
20341Remove symbol table from file "/home/user/gdb/mylib.so"? (y or n) y
20342(gdb)
20343@end smallexample
20344
20345
20346@code{remove-symbol-file} does not repeat if you press @key{RET} after using it.
20347
c45da7e6
EZ
20348@kindex add-symbol-file-from-memory
20349@cindex @code{syscall DSO}
20350@cindex load symbols from memory
20351@item add-symbol-file-from-memory @var{address}
20352Load symbols from the given @var{address} in a dynamically loaded
20353object file whose image is mapped directly into the inferior's memory.
20354For example, the Linux kernel maps a @code{syscall DSO} into each
20355process's address space; this DSO provides kernel-specific code for
20356some system calls. The argument can be any expression whose
20357evaluation yields the address of the file's shared object file header.
20358For this command to work, you must have used @code{symbol-file} or
20359@code{exec-file} commands in advance.
20360
c906108c 20361@kindex section
09d4efe1
EZ
20362@item section @var{section} @var{addr}
20363The @code{section} command changes the base address of the named
20364@var{section} of the exec file to @var{addr}. This can be used if the
20365exec file does not contain section addresses, (such as in the
20366@code{a.out} format), or when the addresses specified in the file
20367itself are wrong. Each section must be changed separately. The
20368@code{info files} command, described below, lists all the sections and
20369their addresses.
c906108c
SS
20370
20371@kindex info files
20372@kindex info target
20373@item info files
20374@itemx info target
7a292a7a
SS
20375@code{info files} and @code{info target} are synonymous; both print the
20376current target (@pxref{Targets, ,Specifying a Debugging Target}),
20377including the names of the executable and core dump files currently in
20378use by @value{GDBN}, and the files from which symbols were loaded. The
20379command @code{help target} lists all possible targets rather than
20380current ones.
20381
fe95c787
MS
20382@kindex maint info sections
20383@item maint info sections
20384Another command that can give you extra information about program sections
20385is @code{maint info sections}. In addition to the section information
20386displayed by @code{info files}, this command displays the flags and file
20387offset of each section in the executable and core dump files. In addition,
20388@code{maint info sections} provides the following command options (which
20389may be arbitrarily combined):
20390
20391@table @code
20392@item ALLOBJ
20393Display sections for all loaded object files, including shared libraries.
20394@item @var{sections}
6600abed 20395Display info only for named @var{sections}.
fe95c787
MS
20396@item @var{section-flags}
20397Display info only for sections for which @var{section-flags} are true.
20398The section flags that @value{GDBN} currently knows about are:
20399@table @code
20400@item ALLOC
20401Section will have space allocated in the process when loaded.
20402Set for all sections except those containing debug information.
20403@item LOAD
20404Section will be loaded from the file into the child process memory.
20405Set for pre-initialized code and data, clear for @code{.bss} sections.
20406@item RELOC
20407Section needs to be relocated before loading.
20408@item READONLY
20409Section cannot be modified by the child process.
20410@item CODE
20411Section contains executable code only.
6600abed 20412@item DATA
fe95c787
MS
20413Section contains data only (no executable code).
20414@item ROM
20415Section will reside in ROM.
20416@item CONSTRUCTOR
20417Section contains data for constructor/destructor lists.
20418@item HAS_CONTENTS
20419Section is not empty.
20420@item NEVER_LOAD
20421An instruction to the linker to not output the section.
20422@item COFF_SHARED_LIBRARY
20423A notification to the linker that the section contains
20424COFF shared library information.
20425@item IS_COMMON
20426Section contains common symbols.
20427@end table
20428@end table
6763aef9 20429@kindex set trust-readonly-sections
9c16f35a 20430@cindex read-only sections
6763aef9
MS
20431@item set trust-readonly-sections on
20432Tell @value{GDBN} that readonly sections in your object file
6ca652b0 20433really are read-only (i.e.@: that their contents will not change).
6763aef9
MS
20434In that case, @value{GDBN} can fetch values from these sections
20435out of the object file, rather than from the target program.
20436For some targets (notably embedded ones), this can be a significant
20437enhancement to debugging performance.
20438
20439The default is off.
20440
20441@item set trust-readonly-sections off
15110bc3 20442Tell @value{GDBN} not to trust readonly sections. This means that
6763aef9
MS
20443the contents of the section might change while the program is running,
20444and must therefore be fetched from the target when needed.
9c16f35a
EZ
20445
20446@item show trust-readonly-sections
20447Show the current setting of trusting readonly sections.
c906108c
SS
20448@end table
20449
20450All file-specifying commands allow both absolute and relative file names
20451as arguments. @value{GDBN} always converts the file name to an absolute file
20452name and remembers it that way.
20453
c906108c 20454@cindex shared libraries
9cceb671 20455@anchor{Shared Libraries}
b1236ac3
PA
20456@value{GDBN} supports @sc{gnu}/Linux, MS-Windows, SunOS,
20457Darwin/Mach-O, SVr4, IBM RS/6000 AIX, QNX Neutrino, FDPIC (FR-V), and
20458DSBT (TIC6X) shared libraries.
53a5351d 20459
9cceb671
DJ
20460On MS-Windows @value{GDBN} must be linked with the Expat library to support
20461shared libraries. @xref{Expat}.
20462
c906108c
SS
20463@value{GDBN} automatically loads symbol definitions from shared libraries
20464when you use the @code{run} command, or when you examine a core file.
20465(Before you issue the @code{run} command, @value{GDBN} does not understand
20466references to a function in a shared library, however---unless you are
20467debugging a core file).
53a5351d 20468
c906108c
SS
20469@c FIXME: some @value{GDBN} release may permit some refs to undef
20470@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
20471@c FIXME...lib; check this from time to time when updating manual
20472
b7209cb4
FF
20473There are times, however, when you may wish to not automatically load
20474symbol definitions from shared libraries, such as when they are
20475particularly large or there are many of them.
20476
20477To control the automatic loading of shared library symbols, use the
20478commands:
20479
20480@table @code
20481@kindex set auto-solib-add
20482@item set auto-solib-add @var{mode}
20483If @var{mode} is @code{on}, symbols from all shared object libraries
20484will be loaded automatically when the inferior begins execution, you
20485attach to an independently started inferior, or when the dynamic linker
20486informs @value{GDBN} that a new library has been loaded. If @var{mode}
20487is @code{off}, symbols must be loaded manually, using the
20488@code{sharedlibrary} command. The default value is @code{on}.
20489
dcaf7c2c
EZ
20490@cindex memory used for symbol tables
20491If your program uses lots of shared libraries with debug info that
20492takes large amounts of memory, you can decrease the @value{GDBN}
20493memory footprint by preventing it from automatically loading the
20494symbols from shared libraries. To that end, type @kbd{set
20495auto-solib-add off} before running the inferior, then load each
20496library whose debug symbols you do need with @kbd{sharedlibrary
d3e8051b 20497@var{regexp}}, where @var{regexp} is a regular expression that matches
dcaf7c2c
EZ
20498the libraries whose symbols you want to be loaded.
20499
b7209cb4
FF
20500@kindex show auto-solib-add
20501@item show auto-solib-add
20502Display the current autoloading mode.
20503@end table
20504
c45da7e6 20505@cindex load shared library
b7209cb4
FF
20506To explicitly load shared library symbols, use the @code{sharedlibrary}
20507command:
20508
c906108c
SS
20509@table @code
20510@kindex info sharedlibrary
20511@kindex info share
55333a84
DE
20512@item info share @var{regex}
20513@itemx info sharedlibrary @var{regex}
20514Print the names of the shared libraries which are currently loaded
20515that match @var{regex}. If @var{regex} is omitted then print
20516all shared libraries that are loaded.
c906108c 20517
b30a0bc3
JB
20518@kindex info dll
20519@item info dll @var{regex}
20520This is an alias of @code{info sharedlibrary}.
20521
c906108c
SS
20522@kindex sharedlibrary
20523@kindex share
20524@item sharedlibrary @var{regex}
20525@itemx share @var{regex}
c906108c
SS
20526Load shared object library symbols for files matching a
20527Unix regular expression.
20528As with files loaded automatically, it only loads shared libraries
20529required by your program for a core file or after typing @code{run}. If
20530@var{regex} is omitted all shared libraries required by your program are
20531loaded.
c45da7e6
EZ
20532
20533@item nosharedlibrary
20534@kindex nosharedlibrary
20535@cindex unload symbols from shared libraries
20536Unload all shared object library symbols. This discards all symbols
20537that have been loaded from all shared libraries. Symbols from shared
20538libraries that were loaded by explicit user requests are not
20539discarded.
c906108c
SS
20540@end table
20541
721c2651 20542Sometimes you may wish that @value{GDBN} stops and gives you control
edcc5120
TT
20543when any of shared library events happen. The best way to do this is
20544to use @code{catch load} and @code{catch unload} (@pxref{Set
20545Catchpoints}).
20546
20547@value{GDBN} also supports the the @code{set stop-on-solib-events}
20548command for this. This command exists for historical reasons. It is
20549less useful than setting a catchpoint, because it does not allow for
20550conditions or commands as a catchpoint does.
721c2651
EZ
20551
20552@table @code
20553@item set stop-on-solib-events
20554@kindex set stop-on-solib-events
20555This command controls whether @value{GDBN} should give you control
20556when the dynamic linker notifies it about some shared library event.
20557The most common event of interest is loading or unloading of a new
20558shared library.
20559
20560@item show stop-on-solib-events
20561@kindex show stop-on-solib-events
20562Show whether @value{GDBN} stops and gives you control when shared
20563library events happen.
20564@end table
20565
f5ebfba0 20566Shared libraries are also supported in many cross or remote debugging
f1838a98
UW
20567configurations. @value{GDBN} needs to have access to the target's libraries;
20568this can be accomplished either by providing copies of the libraries
20569on the host system, or by asking @value{GDBN} to automatically retrieve the
20570libraries from the target. If copies of the target libraries are
20571provided, they need to be the same as the target libraries, although the
f5ebfba0
DJ
20572copies on the target can be stripped as long as the copies on the host are
20573not.
20574
59b7b46f
EZ
20575@cindex where to look for shared libraries
20576For remote debugging, you need to tell @value{GDBN} where the target
20577libraries are, so that it can load the correct copies---otherwise, it
20578may try to load the host's libraries. @value{GDBN} has two variables
20579to specify the search directories for target libraries.
f5ebfba0
DJ
20580
20581@table @code
a9a5a3d1 20582@cindex prefix for executable and shared library file names
f822c95b 20583@cindex system root, alternate
f5ebfba0 20584@kindex set solib-absolute-prefix
f822c95b
DJ
20585@kindex set sysroot
20586@item set sysroot @var{path}
20587Use @var{path} as the system root for the program being debugged. Any
20588absolute shared library paths will be prefixed with @var{path}; many
20589runtime loaders store the absolute paths to the shared library in the
a9a5a3d1
GB
20590target program's memory. When starting processes remotely, and when
20591attaching to already-running processes (local or remote), their
20592executable filenames will be prefixed with @var{path} if reported to
20593@value{GDBN} as absolute by the operating system. If you use
20594@code{set sysroot} to find executables and shared libraries, they need
20595to be laid out in the same way that they are on the target, with
20596e.g.@: a @file{/bin}, @file{/lib} and @file{/usr/lib} hierarchy under
20597@var{path}.
f822c95b 20598
599bd15c
GB
20599If @var{path} starts with the sequence @file{target:} and the target
20600system is remote then @value{GDBN} will retrieve the target binaries
20601from the remote system. This is only supported when using a remote
20602target that supports the @code{remote get} command (@pxref{File
20603Transfer,,Sending files to a remote system}). The part of @var{path}
20604following the initial @file{target:} (if present) is used as system
20605root prefix on the remote file system. If @var{path} starts with the
20606sequence @file{remote:} this is converted to the sequence
20607@file{target:} by @code{set sysroot}@footnote{Historically the
20608functionality to retrieve binaries from the remote system was
20609provided by prefixing @var{path} with @file{remote:}}. If you want
20610to specify a local system root using a directory that happens to be
20611named @file{target:} or @file{remote:}, you need to use some
20612equivalent variant of the name like @file{./target:}.
f1838a98 20613
ab38a727
PA
20614For targets with an MS-DOS based filesystem, such as MS-Windows and
20615SymbianOS, @value{GDBN} tries prefixing a few variants of the target
20616absolute file name with @var{path}. But first, on Unix hosts,
20617@value{GDBN} converts all backslash directory separators into forward
20618slashes, because the backslash is not a directory separator on Unix:
20619
20620@smallexample
20621 c:\foo\bar.dll @result{} c:/foo/bar.dll
20622@end smallexample
20623
20624Then, @value{GDBN} attempts prefixing the target file name with
20625@var{path}, and looks for the resulting file name in the host file
20626system:
20627
20628@smallexample
20629 c:/foo/bar.dll @result{} /path/to/sysroot/c:/foo/bar.dll
20630@end smallexample
20631
a9a5a3d1 20632If that does not find the binary, @value{GDBN} tries removing
ab38a727
PA
20633the @samp{:} character from the drive spec, both for convenience, and,
20634for the case of the host file system not supporting file names with
20635colons:
20636
20637@smallexample
20638 c:/foo/bar.dll @result{} /path/to/sysroot/c/foo/bar.dll
20639@end smallexample
20640
20641This makes it possible to have a system root that mirrors a target
20642with more than one drive. E.g., you may want to setup your local
20643copies of the target system shared libraries like so (note @samp{c} vs
20644@samp{z}):
20645
20646@smallexample
20647 @file{/path/to/sysroot/c/sys/bin/foo.dll}
20648 @file{/path/to/sysroot/c/sys/bin/bar.dll}
20649 @file{/path/to/sysroot/z/sys/bin/bar.dll}
20650@end smallexample
20651
20652@noindent
20653and point the system root at @file{/path/to/sysroot}, so that
20654@value{GDBN} can find the correct copies of both
20655@file{c:\sys\bin\foo.dll}, and @file{z:\sys\bin\bar.dll}.
20656
a9a5a3d1 20657If that still does not find the binary, @value{GDBN} tries
ab38a727
PA
20658removing the whole drive spec from the target file name:
20659
20660@smallexample
20661 c:/foo/bar.dll @result{} /path/to/sysroot/foo/bar.dll
20662@end smallexample
20663
20664This last lookup makes it possible to not care about the drive name,
20665if you don't want or need to.
20666
f822c95b
DJ
20667The @code{set solib-absolute-prefix} command is an alias for @code{set
20668sysroot}.
20669
20670@cindex default system root
59b7b46f 20671@cindex @samp{--with-sysroot}
f822c95b
DJ
20672You can set the default system root by using the configure-time
20673@samp{--with-sysroot} option. If the system root is inside
20674@value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
20675@samp{--exec-prefix}), then the default system root will be updated
20676automatically if the installed @value{GDBN} is moved to a new
20677location.
20678
20679@kindex show sysroot
20680@item show sysroot
a9a5a3d1 20681Display the current executable and shared library prefix.
f5ebfba0
DJ
20682
20683@kindex set solib-search-path
20684@item set solib-search-path @var{path}
f822c95b
DJ
20685If this variable is set, @var{path} is a colon-separated list of
20686directories to search for shared libraries. @samp{solib-search-path}
20687is used after @samp{sysroot} fails to locate the library, or if the
20688path to the library is relative instead of absolute. If you want to
20689use @samp{solib-search-path} instead of @samp{sysroot}, be sure to set
d3e8051b 20690@samp{sysroot} to a nonexistent directory to prevent @value{GDBN} from
f822c95b 20691finding your host's libraries. @samp{sysroot} is preferred; setting
d3e8051b 20692it to a nonexistent directory may interfere with automatic loading
f822c95b 20693of shared library symbols.
f5ebfba0
DJ
20694
20695@kindex show solib-search-path
20696@item show solib-search-path
20697Display the current shared library search path.
ab38a727
PA
20698
20699@cindex DOS file-name semantics of file names.
20700@kindex set target-file-system-kind (unix|dos-based|auto)
20701@kindex show target-file-system-kind
20702@item set target-file-system-kind @var{kind}
20703Set assumed file system kind for target reported file names.
20704
20705Shared library file names as reported by the target system may not
20706make sense as is on the system @value{GDBN} is running on. For
20707example, when remote debugging a target that has MS-DOS based file
20708system semantics, from a Unix host, the target may be reporting to
20709@value{GDBN} a list of loaded shared libraries with file names such as
20710@file{c:\Windows\kernel32.dll}. On Unix hosts, there's no concept of
20711drive letters, so the @samp{c:\} prefix is not normally understood as
20712indicating an absolute file name, and neither is the backslash
20713normally considered a directory separator character. In that case,
20714the native file system would interpret this whole absolute file name
20715as a relative file name with no directory components. This would make
20716it impossible to point @value{GDBN} at a copy of the remote target's
20717shared libraries on the host using @code{set sysroot}, and impractical
20718with @code{set solib-search-path}. Setting
20719@code{target-file-system-kind} to @code{dos-based} tells @value{GDBN}
20720to interpret such file names similarly to how the target would, and to
20721map them to file names valid on @value{GDBN}'s native file system
20722semantics. The value of @var{kind} can be @code{"auto"}, in addition
20723to one of the supported file system kinds. In that case, @value{GDBN}
20724tries to determine the appropriate file system variant based on the
20725current target's operating system (@pxref{ABI, ,Configuring the
20726Current ABI}). The supported file system settings are:
20727
20728@table @code
20729@item unix
20730Instruct @value{GDBN} to assume the target file system is of Unix
20731kind. Only file names starting the forward slash (@samp{/}) character
20732are considered absolute, and the directory separator character is also
20733the forward slash.
20734
20735@item dos-based
20736Instruct @value{GDBN} to assume the target file system is DOS based.
20737File names starting with either a forward slash, or a drive letter
20738followed by a colon (e.g., @samp{c:}), are considered absolute, and
20739both the slash (@samp{/}) and the backslash (@samp{\\}) characters are
20740considered directory separators.
20741
20742@item auto
20743Instruct @value{GDBN} to use the file system kind associated with the
20744target operating system (@pxref{ABI, ,Configuring the Current ABI}).
20745This is the default.
20746@end table
f5ebfba0
DJ
20747@end table
20748
c011a4f4
DE
20749@cindex file name canonicalization
20750@cindex base name differences
20751When processing file names provided by the user, @value{GDBN}
20752frequently needs to compare them to the file names recorded in the
20753program's debug info. Normally, @value{GDBN} compares just the
20754@dfn{base names} of the files as strings, which is reasonably fast
20755even for very large programs. (The base name of a file is the last
20756portion of its name, after stripping all the leading directories.)
20757This shortcut in comparison is based upon the assumption that files
20758cannot have more than one base name. This is usually true, but
20759references to files that use symlinks or similar filesystem
20760facilities violate that assumption. If your program records files
20761using such facilities, or if you provide file names to @value{GDBN}
20762using symlinks etc., you can set @code{basenames-may-differ} to
20763@code{true} to instruct @value{GDBN} to completely canonicalize each
20764pair of file names it needs to compare. This will make file-name
20765comparisons accurate, but at a price of a significant slowdown.
20766
20767@table @code
20768@item set basenames-may-differ
20769@kindex set basenames-may-differ
20770Set whether a source file may have multiple base names.
20771
20772@item show basenames-may-differ
20773@kindex show basenames-may-differ
20774Show whether a source file may have multiple base names.
20775@end table
5b5d99cf 20776
18989b3c
AB
20777@node File Caching
20778@section File Caching
20779@cindex caching of opened files
20780@cindex caching of bfd objects
20781
20782To speed up file loading, and reduce memory usage, @value{GDBN} will
20783reuse the @code{bfd} objects used to track open files. @xref{Top, ,
20784BFD, bfd, The Binary File Descriptor Library}. The following commands
20785allow visibility and control of the caching behavior.
20786
20787@table @code
20788@kindex maint info bfds
20789@item maint info bfds
20790This prints information about each @code{bfd} object that is known to
20791@value{GDBN}.
20792
20793@kindex maint set bfd-sharing
20794@kindex maint show bfd-sharing
20795@kindex bfd caching
20796@item maint set bfd-sharing
20797@item maint show bfd-sharing
20798Control whether @code{bfd} objects can be shared. When sharing is
20799enabled @value{GDBN} reuses already open @code{bfd} objects rather
20800than reopening the same file. Turning sharing off does not cause
20801already shared @code{bfd} objects to be unshared, but all future files
20802that are opened will create a new @code{bfd} object. Similarly,
20803re-enabling sharing does not cause multiple existing @code{bfd}
20804objects to be collapsed into a single shared @code{bfd} object.
566f5e3b
AB
20805
20806@kindex set debug bfd-cache @var{level}
20807@kindex bfd caching
20808@item set debug bfd-cache @var{level}
20809Turns on debugging of the bfd cache, setting the level to @var{level}.
20810
20811@kindex show debug bfd-cache
20812@kindex bfd caching
20813@item show debug bfd-cache
20814Show the current debugging level of the bfd cache.
18989b3c
AB
20815@end table
20816
5b5d99cf
JB
20817@node Separate Debug Files
20818@section Debugging Information in Separate Files
20819@cindex separate debugging information files
20820@cindex debugging information in separate files
20821@cindex @file{.debug} subdirectories
20822@cindex debugging information directory, global
f307c045 20823@cindex global debugging information directories
c7e83d54
EZ
20824@cindex build ID, and separate debugging files
20825@cindex @file{.build-id} directory
5b5d99cf
JB
20826
20827@value{GDBN} allows you to put a program's debugging information in a
20828file separate from the executable itself, in a way that allows
20829@value{GDBN} to find and load the debugging information automatically.
c7e83d54
EZ
20830Since debugging information can be very large---sometimes larger
20831than the executable code itself---some systems distribute debugging
5b5d99cf
JB
20832information for their executables in separate files, which users can
20833install only when they need to debug a problem.
20834
c7e83d54
EZ
20835@value{GDBN} supports two ways of specifying the separate debug info
20836file:
5b5d99cf
JB
20837
20838@itemize @bullet
20839@item
c7e83d54
EZ
20840The executable contains a @dfn{debug link} that specifies the name of
20841the separate debug info file. The separate debug file's name is
20842usually @file{@var{executable}.debug}, where @var{executable} is the
20843name of the corresponding executable file without leading directories
20844(e.g., @file{ls.debug} for @file{/usr/bin/ls}). In addition, the
99e008fe
EZ
20845debug link specifies a 32-bit @dfn{Cyclic Redundancy Check} (CRC)
20846checksum for the debug file, which @value{GDBN} uses to validate that
20847the executable and the debug file came from the same build.
c7e83d54
EZ
20848
20849@item
7e27a47a 20850The executable contains a @dfn{build ID}, a unique bit string that is
c7e83d54 20851also present in the corresponding debug info file. (This is supported
c74f7d1c 20852only on some operating systems, when using the ELF or PE file formats
7e27a47a
EZ
20853for binary files and the @sc{gnu} Binutils.) For more details about
20854this feature, see the description of the @option{--build-id}
f5a476a7 20855command-line option in @ref{Options, , Command Line Options, ld,
7e27a47a
EZ
20856The GNU Linker}. The debug info file's name is not specified
20857explicitly by the build ID, but can be computed from the build ID, see
20858below.
d3750b24
JK
20859@end itemize
20860
c7e83d54
EZ
20861Depending on the way the debug info file is specified, @value{GDBN}
20862uses two different methods of looking for the debug file:
d3750b24
JK
20863
20864@itemize @bullet
20865@item
c7e83d54
EZ
20866For the ``debug link'' method, @value{GDBN} looks up the named file in
20867the directory of the executable file, then in a subdirectory of that
5f2459c2
EZ
20868directory named @file{.debug}, and finally under each one of the
20869global debug directories, in a subdirectory whose name is identical to
20870the leading directories of the executable's absolute file name. (On
20871MS-Windows/MS-DOS, the drive letter of the executable's leading
20872directories is converted to a one-letter subdirectory, i.e.@:
20873@file{d:/usr/bin/} is converted to @file{/d/usr/bin/}, because Windows
20874filesystems disallow colons in file names.)
c7e83d54
EZ
20875
20876@item
83f83d7f 20877For the ``build ID'' method, @value{GDBN} looks in the
f307c045
JK
20878@file{.build-id} subdirectory of each one of the global debug directories for
20879a file named @file{@var{nn}/@var{nnnnnnnn}.debug}, where @var{nn} are the
7e27a47a
EZ
20880first 2 hex characters of the build ID bit string, and @var{nnnnnnnn}
20881are the rest of the bit string. (Real build ID strings are 32 or more
20882hex characters, not 10.)
c7e83d54
EZ
20883@end itemize
20884
20885So, for example, suppose you ask @value{GDBN} to debug
7e27a47a
EZ
20886@file{/usr/bin/ls}, which has a debug link that specifies the
20887file @file{ls.debug}, and a build ID whose value in hex is
f307c045 20888@code{abcdef1234}. If the list of the global debug directories includes
c7e83d54
EZ
20889@file{/usr/lib/debug}, then @value{GDBN} will look for the following
20890debug information files, in the indicated order:
20891
20892@itemize @minus
20893@item
20894@file{/usr/lib/debug/.build-id/ab/cdef1234.debug}
d3750b24 20895@item
c7e83d54 20896@file{/usr/bin/ls.debug}
5b5d99cf 20897@item
c7e83d54 20898@file{/usr/bin/.debug/ls.debug}
5b5d99cf 20899@item
c7e83d54 20900@file{/usr/lib/debug/usr/bin/ls.debug}.
5b5d99cf 20901@end itemize
5b5d99cf 20902
1564a261
JK
20903@anchor{debug-file-directory}
20904Global debugging info directories default to what is set by @value{GDBN}
20905configure option @option{--with-separate-debug-dir}. During @value{GDBN} run
20906you can also set the global debugging info directories, and view the list
20907@value{GDBN} is currently using.
5b5d99cf
JB
20908
20909@table @code
20910
20911@kindex set debug-file-directory
24ddea62
JK
20912@item set debug-file-directory @var{directories}
20913Set the directories which @value{GDBN} searches for separate debugging
d9242c17
JK
20914information files to @var{directory}. Multiple path components can be set
20915concatenating them by a path separator.
5b5d99cf
JB
20916
20917@kindex show debug-file-directory
20918@item show debug-file-directory
24ddea62 20919Show the directories @value{GDBN} searches for separate debugging
5b5d99cf
JB
20920information files.
20921
20922@end table
20923
20924@cindex @code{.gnu_debuglink} sections
c7e83d54 20925@cindex debug link sections
5b5d99cf
JB
20926A debug link is a special section of the executable file named
20927@code{.gnu_debuglink}. The section must contain:
20928
20929@itemize
20930@item
20931A filename, with any leading directory components removed, followed by
20932a zero byte,
20933@item
20934zero to three bytes of padding, as needed to reach the next four-byte
20935boundary within the section, and
20936@item
20937a four-byte CRC checksum, stored in the same endianness used for the
20938executable file itself. The checksum is computed on the debugging
20939information file's full contents by the function given below, passing
20940zero as the @var{crc} argument.
20941@end itemize
20942
20943Any executable file format can carry a debug link, as long as it can
20944contain a section named @code{.gnu_debuglink} with the contents
20945described above.
20946
d3750b24 20947@cindex @code{.note.gnu.build-id} sections
c7e83d54 20948@cindex build ID sections
7e27a47a
EZ
20949The build ID is a special section in the executable file (and in other
20950ELF binary files that @value{GDBN} may consider). This section is
20951often named @code{.note.gnu.build-id}, but that name is not mandatory.
20952It contains unique identification for the built files---the ID remains
20953the same across multiple builds of the same build tree. The default
20954algorithm SHA1 produces 160 bits (40 hexadecimal characters) of the
20955content for the build ID string. The same section with an identical
20956value is present in the original built binary with symbols, in its
20957stripped variant, and in the separate debugging information file.
d3750b24 20958
5b5d99cf
JB
20959The debugging information file itself should be an ordinary
20960executable, containing a full set of linker symbols, sections, and
20961debugging information. The sections of the debugging information file
c7e83d54
EZ
20962should have the same names, addresses, and sizes as the original file,
20963but they need not contain any data---much like a @code{.bss} section
5b5d99cf
JB
20964in an ordinary executable.
20965
7e27a47a 20966The @sc{gnu} binary utilities (Binutils) package includes the
c7e83d54
EZ
20967@samp{objcopy} utility that can produce
20968the separated executable / debugging information file pairs using the
20969following commands:
20970
20971@smallexample
20972@kbd{objcopy --only-keep-debug foo foo.debug}
20973@kbd{strip -g foo}
c7e83d54
EZ
20974@end smallexample
20975
20976@noindent
20977These commands remove the debugging
83f83d7f
JK
20978information from the executable file @file{foo} and place it in the file
20979@file{foo.debug}. You can use the first, second or both methods to link the
20980two files:
20981
20982@itemize @bullet
20983@item
20984The debug link method needs the following additional command to also leave
20985behind a debug link in @file{foo}:
20986
20987@smallexample
20988@kbd{objcopy --add-gnu-debuglink=foo.debug foo}
20989@end smallexample
20990
20991Ulrich Drepper's @file{elfutils} package, starting with version 0.53, contains
d3750b24 20992a version of the @code{strip} command such that the command @kbd{strip foo -f
83f83d7f
JK
20993foo.debug} has the same functionality as the two @code{objcopy} commands and
20994the @code{ln -s} command above, together.
20995
20996@item
20997Build ID gets embedded into the main executable using @code{ld --build-id} or
20998the @value{NGCC} counterpart @code{gcc -Wl,--build-id}. Build ID support plus
20999compatibility fixes for debug files separation are present in @sc{gnu} binary
7e27a47a 21000utilities (Binutils) package since version 2.18.
83f83d7f
JK
21001@end itemize
21002
21003@noindent
d3750b24 21004
99e008fe
EZ
21005@cindex CRC algorithm definition
21006The CRC used in @code{.gnu_debuglink} is the CRC-32 defined in
21007IEEE 802.3 using the polynomial:
21008
21009@c TexInfo requires naked braces for multi-digit exponents for Tex
21010@c output, but this causes HTML output to barf. HTML has to be set using
21011@c raw commands. So we end up having to specify this equation in 2
21012@c different ways!
21013@ifhtml
21014@display
21015@html
21016 <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>
21017 + <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
21018@end html
21019@end display
21020@end ifhtml
21021@ifnothtml
21022@display
21023 @math{x^{32} + x^{26} + x^{23} + x^{22} + x^{16} + x^{12} + x^{11}}
21024 @math{+ x^{10} + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1}
21025@end display
21026@end ifnothtml
21027
21028The function is computed byte at a time, taking the least
21029significant bit of each byte first. The initial pattern
21030@code{0xffffffff} is used, to ensure leading zeros affect the CRC and
21031the final result is inverted to ensure trailing zeros also affect the
21032CRC.
21033
21034@emph{Note:} This is the same CRC polynomial as used in handling the
936d2992
PA
21035@dfn{Remote Serial Protocol} @code{qCRC} packet (@pxref{qCRC packet}).
21036However in the case of the Remote Serial Protocol, the CRC is computed
21037@emph{most} significant bit first, and the result is not inverted, so
21038trailing zeros have no effect on the CRC value.
99e008fe
EZ
21039
21040To complete the description, we show below the code of the function
21041which produces the CRC used in @code{.gnu_debuglink}. Inverting the
21042initially supplied @code{crc} argument means that an initial call to
21043this function passing in zero will start computing the CRC using
21044@code{0xffffffff}.
5b5d99cf 21045
4644b6e3 21046@kindex gnu_debuglink_crc32
5b5d99cf
JB
21047@smallexample
21048unsigned long
21049gnu_debuglink_crc32 (unsigned long crc,
21050 unsigned char *buf, size_t len)
21051@{
21052 static const unsigned long crc32_table[256] =
21053 @{
21054 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
21055 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
21056 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
21057 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
21058 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
21059 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
21060 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
21061 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
21062 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
21063 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
21064 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
21065 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
21066 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
21067 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
21068 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
21069 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
21070 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
21071 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
21072 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
21073 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
21074 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
21075 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
21076 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
21077 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
21078 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
21079 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
21080 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
21081 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
21082 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
21083 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
21084 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
21085 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
21086 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
21087 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
21088 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
21089 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
21090 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
21091 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
21092 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
21093 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
21094 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
21095 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
21096 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
21097 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
21098 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
21099 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
21100 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
21101 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
21102 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
21103 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
21104 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
21105 0x2d02ef8d
21106 @};
21107 unsigned char *end;
21108
21109 crc = ~crc & 0xffffffff;
21110 for (end = buf + len; buf < end; ++buf)
21111 crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
e7a3abfc 21112 return ~crc & 0xffffffff;
5b5d99cf
JB
21113@}
21114@end smallexample
21115
c7e83d54
EZ
21116@noindent
21117This computation does not apply to the ``build ID'' method.
21118
608e2dbb
TT
21119@node MiniDebugInfo
21120@section Debugging information in a special section
21121@cindex separate debug sections
21122@cindex @samp{.gnu_debugdata} section
21123
21124Some systems ship pre-built executables and libraries that have a
21125special @samp{.gnu_debugdata} section. This feature is called
21126@dfn{MiniDebugInfo}. This section holds an LZMA-compressed object and
21127is used to supply extra symbols for backtraces.
21128
21129The intent of this section is to provide extra minimal debugging
21130information for use in simple backtraces. It is not intended to be a
21131replacement for full separate debugging information (@pxref{Separate
21132Debug Files}). The example below shows the intended use; however,
21133@value{GDBN} does not currently put restrictions on what sort of
21134debugging information might be included in the section.
21135
21136@value{GDBN} has support for this extension. If the section exists,
21137then it is used provided that no other source of debugging information
21138can be found, and that @value{GDBN} was configured with LZMA support.
21139
21140This section can be easily created using @command{objcopy} and other
21141standard utilities:
21142
21143@smallexample
21144# Extract the dynamic symbols from the main binary, there is no need
5423b017 21145# to also have these in the normal symbol table.
608e2dbb
TT
21146nm -D @var{binary} --format=posix --defined-only \
21147 | awk '@{ print $1 @}' | sort > dynsyms
21148
5423b017 21149# Extract all the text (i.e. function) symbols from the debuginfo.
1d236d23
JK
21150# (Note that we actually also accept "D" symbols, for the benefit
21151# of platforms like PowerPC64 that use function descriptors.)
608e2dbb 21152nm @var{binary} --format=posix --defined-only \
1d236d23 21153 | awk '@{ if ($2 == "T" || $2 == "t" || $2 == "D") print $1 @}' \
608e2dbb
TT
21154 | sort > funcsyms
21155
21156# Keep all the function symbols not already in the dynamic symbol
21157# table.
21158comm -13 dynsyms funcsyms > keep_symbols
21159
edf9f00c
JK
21160# Separate full debug info into debug binary.
21161objcopy --only-keep-debug @var{binary} debug
21162
608e2dbb
TT
21163# Copy the full debuginfo, keeping only a minimal set of symbols and
21164# removing some unnecessary sections.
21165objcopy -S --remove-section .gdb_index --remove-section .comment \
edf9f00c
JK
21166 --keep-symbols=keep_symbols debug mini_debuginfo
21167
21168# Drop the full debug info from the original binary.
21169strip --strip-all -R .comment @var{binary}
608e2dbb
TT
21170
21171# Inject the compressed data into the .gnu_debugdata section of the
21172# original binary.
21173xz mini_debuginfo
21174objcopy --add-section .gnu_debugdata=mini_debuginfo.xz @var{binary}
21175@end smallexample
5b5d99cf 21176
9291a0cd
TT
21177@node Index Files
21178@section Index Files Speed Up @value{GDBN}
21179@cindex index files
21180@cindex @samp{.gdb_index} section
21181
21182When @value{GDBN} finds a symbol file, it scans the symbols in the
21183file in order to construct an internal symbol table. This lets most
21184@value{GDBN} operations work quickly---at the cost of a delay early
21185on. For large programs, this delay can be quite lengthy, so
21186@value{GDBN} provides a way to build an index, which speeds up
21187startup.
21188
ba643918
SDJ
21189For convenience, @value{GDBN} comes with a program,
21190@command{gdb-add-index}, which can be used to add the index to a
21191symbol file. It takes the symbol file as its only argument:
21192
21193@smallexample
21194$ gdb-add-index symfile
21195@end smallexample
21196
21197@xref{gdb-add-index}.
21198
21199It is also possible to do the work manually. Here is what
21200@command{gdb-add-index} does behind the curtains.
21201
9291a0cd
TT
21202The index is stored as a section in the symbol file. @value{GDBN} can
21203write the index to a file, then you can put it into the symbol file
21204using @command{objcopy}.
21205
21206To create an index file, use the @code{save gdb-index} command:
21207
21208@table @code
437afbb8 21209@item save gdb-index [-dwarf-5] @var{directory}
9291a0cd 21210@kindex save gdb-index
437afbb8
JK
21211Create index files for all symbol files currently known by
21212@value{GDBN}. For each known @var{symbol-file}, this command by
21213default creates it produces a single file
21214@file{@var{symbol-file}.gdb-index}. If you invoke this command with
21215the @option{-dwarf-5} option, it produces 2 files:
21216@file{@var{symbol-file}.debug_names} and
21217@file{@var{symbol-file}.debug_str}. The files are created in the
21218given @var{directory}.
9291a0cd
TT
21219@end table
21220
21221Once you have created an index file you can merge it into your symbol
21222file, here named @file{symfile}, using @command{objcopy}:
21223
21224@smallexample
21225$ objcopy --add-section .gdb_index=symfile.gdb-index \
21226 --set-section-flags .gdb_index=readonly symfile symfile
21227@end smallexample
21228
437afbb8
JK
21229Or for @code{-dwarf-5}:
21230
21231@smallexample
21232$ objcopy --dump-section .debug_str=symfile.debug_str.new symfile
21233$ cat symfile.debug_str >>symfile.debug_str.new
21234$ objcopy --add-section .debug_names=symfile.gdb-index \
21235 --set-section-flags .debug_names=readonly \
21236 --update-section .debug_str=symfile.debug_str.new symfile symfile
21237@end smallexample
21238
e615022a
DE
21239@value{GDBN} will normally ignore older versions of @file{.gdb_index}
21240sections that have been deprecated. Usually they are deprecated because
21241they are missing a new feature or have performance issues.
21242To tell @value{GDBN} to use a deprecated index section anyway
21243specify @code{set use-deprecated-index-sections on}.
21244The default is @code{off}.
21245This can speed up startup, but may result in some functionality being lost.
21246@xref{Index Section Format}.
21247
21248@emph{Warning:} Setting @code{use-deprecated-index-sections} to @code{on}
21249must be done before gdb reads the file. The following will not work:
21250
21251@smallexample
21252$ gdb -ex "set use-deprecated-index-sections on" <program>
21253@end smallexample
21254
21255Instead you must do, for example,
21256
21257@smallexample
21258$ gdb -iex "set use-deprecated-index-sections on" <program>
21259@end smallexample
21260
9291a0cd 21261There are currently some limitation on indices. They only work when
2d601616
TT
21262using DWARF debugging information, not stabs. And, only the
21263@code{-dwarf-5} index works for programs using Ada.
9291a0cd 21264
7d11235d
SM
21265@subsection Automatic symbol index cache
21266
a0a3a1e9 21267@cindex automatic symbol index cache
7d11235d
SM
21268It is possible for @value{GDBN} to automatically save a copy of this index in a
21269cache on disk and retrieve it from there when loading the same binary in the
21270future. This feature can be turned on with @kbd{set index-cache on}. The
21271following commands can be used to tweak the behavior of the index cache.
21272
21273@table @code
21274
a0a3a1e9 21275@kindex set index-cache
7d11235d
SM
21276@item set index-cache on
21277@itemx set index-cache off
21278Enable or disable the use of the symbol index cache.
21279
21280@item set index-cache directory @var{directory}
a0a3a1e9 21281@kindex show index-cache
7d11235d 21282@itemx show index-cache directory
e6cd1dc1
TT
21283Set/show the directory where index files will be saved.
21284
21285The default value for this directory depends on the host platform. On
21286most systems, the index is cached in the @file{gdb} subdirectory of
21287the directory pointed to by the @env{XDG_CACHE_HOME} environment
21288variable, if it is defined, else in the @file{.cache/gdb} subdirectory
21289of your home directory. However, on some systems, the default may
21290differ according to local convention.
7d11235d
SM
21291
21292There is no limit on the disk space used by index cache. It is perfectly safe
21293to delete the content of that directory to free up disk space.
21294
21295@item show index-cache stats
21296Print the number of cache hits and misses since the launch of @value{GDBN}.
21297
21298@end table
21299
6d2ebf8b 21300@node Symbol Errors
79a6e687 21301@section Errors Reading Symbol Files
c906108c
SS
21302
21303While reading a symbol file, @value{GDBN} occasionally encounters problems,
21304such as symbol types it does not recognize, or known bugs in compiler
21305output. By default, @value{GDBN} does not notify you of such problems, since
21306they are relatively common and primarily of interest to people
21307debugging compilers. If you are interested in seeing information
21308about ill-constructed symbol tables, you can either ask @value{GDBN} to print
21309only one message about each such type of problem, no matter how many
21310times the problem occurs; or you can ask @value{GDBN} to print more messages,
21311to see how many times the problems occur, with the @code{set
79a6e687
BW
21312complaints} command (@pxref{Messages/Warnings, ,Optional Warnings and
21313Messages}).
c906108c
SS
21314
21315The messages currently printed, and their meanings, include:
21316
21317@table @code
21318@item inner block not inside outer block in @var{symbol}
21319
21320The symbol information shows where symbol scopes begin and end
21321(such as at the start of a function or a block of statements). This
21322error indicates that an inner scope block is not fully contained
21323in its outer scope blocks.
21324
21325@value{GDBN} circumvents the problem by treating the inner block as if it had
21326the same scope as the outer block. In the error message, @var{symbol}
21327may be shown as ``@code{(don't know)}'' if the outer block is not a
21328function.
21329
21330@item block at @var{address} out of order
21331
21332The symbol information for symbol scope blocks should occur in
21333order of increasing addresses. This error indicates that it does not
21334do so.
21335
21336@value{GDBN} does not circumvent this problem, and has trouble
21337locating symbols in the source file whose symbols it is reading. (You
21338can often determine what source file is affected by specifying
79a6e687
BW
21339@code{set verbose on}. @xref{Messages/Warnings, ,Optional Warnings and
21340Messages}.)
c906108c
SS
21341
21342@item bad block start address patched
21343
21344The symbol information for a symbol scope block has a start address
21345smaller than the address of the preceding source line. This is known
21346to occur in the SunOS 4.1.1 (and earlier) C compiler.
21347
21348@value{GDBN} circumvents the problem by treating the symbol scope block as
21349starting on the previous source line.
21350
21351@item bad string table offset in symbol @var{n}
21352
21353@cindex foo
21354Symbol number @var{n} contains a pointer into the string table which is
21355larger than the size of the string table.
21356
21357@value{GDBN} circumvents the problem by considering the symbol to have the
21358name @code{foo}, which may cause other problems if many symbols end up
21359with this name.
21360
21361@item unknown symbol type @code{0x@var{nn}}
21362
7a292a7a
SS
21363The symbol information contains new data types that @value{GDBN} does
21364not yet know how to read. @code{0x@var{nn}} is the symbol type of the
d4f3574e 21365uncomprehended information, in hexadecimal.
c906108c 21366
7a292a7a
SS
21367@value{GDBN} circumvents the error by ignoring this symbol information.
21368This usually allows you to debug your program, though certain symbols
c906108c 21369are not accessible. If you encounter such a problem and feel like
7a292a7a
SS
21370debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
21371on @code{complain}, then go up to the function @code{read_dbx_symtab}
21372and examine @code{*bufp} to see the symbol.
c906108c
SS
21373
21374@item stub type has NULL name
c906108c 21375
7a292a7a 21376@value{GDBN} could not find the full definition for a struct or class.
c906108c 21377
7a292a7a 21378@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
b37052ae 21379The symbol information for a C@t{++} member function is missing some
7a292a7a
SS
21380information that recent versions of the compiler should have output for
21381it.
c906108c
SS
21382
21383@item info mismatch between compiler and debugger
21384
21385@value{GDBN} could not parse a type specification output by the compiler.
7a292a7a 21386
c906108c
SS
21387@end table
21388
b14b1491
TT
21389@node Data Files
21390@section GDB Data Files
21391
21392@cindex prefix for data files
21393@value{GDBN} will sometimes read an auxiliary data file. These files
21394are kept in a directory known as the @dfn{data directory}.
21395
21396You can set the data directory's name, and view the name @value{GDBN}
21397is currently using.
21398
21399@table @code
21400@kindex set data-directory
21401@item set data-directory @var{directory}
21402Set the directory which @value{GDBN} searches for auxiliary data files
21403to @var{directory}.
21404
21405@kindex show data-directory
21406@item show data-directory
21407Show the directory @value{GDBN} searches for auxiliary data files.
21408@end table
21409
21410@cindex default data directory
21411@cindex @samp{--with-gdb-datadir}
21412You can set the default data directory by using the configure-time
21413@samp{--with-gdb-datadir} option. If the data directory is inside
21414@value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
21415@samp{--exec-prefix}), then the default data directory will be updated
21416automatically if the installed @value{GDBN} is moved to a new
21417location.
21418
aae1c79a
DE
21419The data directory may also be specified with the
21420@code{--data-directory} command line option.
21421@xref{Mode Options}.
21422
6d2ebf8b 21423@node Targets
c906108c 21424@chapter Specifying a Debugging Target
7a292a7a 21425
c906108c 21426@cindex debugging target
c906108c 21427A @dfn{target} is the execution environment occupied by your program.
53a5351d
JM
21428
21429Often, @value{GDBN} runs in the same host environment as your program;
21430in that case, the debugging target is specified as a side effect when
21431you use the @code{file} or @code{core} commands. When you need more
c906108c
SS
21432flexibility---for example, running @value{GDBN} on a physically separate
21433host, or controlling a standalone system over a serial port or a
53a5351d
JM
21434realtime system over a TCP/IP connection---you can use the @code{target}
21435command to specify one of the target types configured for @value{GDBN}
79a6e687 21436(@pxref{Target Commands, ,Commands for Managing Targets}).
c906108c 21437
a8f24a35
EZ
21438@cindex target architecture
21439It is possible to build @value{GDBN} for several different @dfn{target
21440architectures}. When @value{GDBN} is built like that, you can choose
21441one of the available architectures with the @kbd{set architecture}
21442command.
21443
21444@table @code
21445@kindex set architecture
21446@kindex show architecture
21447@item set architecture @var{arch}
21448This command sets the current target architecture to @var{arch}. The
21449value of @var{arch} can be @code{"auto"}, in addition to one of the
21450supported architectures.
21451
21452@item show architecture
21453Show the current target architecture.
9c16f35a
EZ
21454
21455@item set processor
21456@itemx processor
21457@kindex set processor
21458@kindex show processor
21459These are alias commands for, respectively, @code{set architecture}
21460and @code{show architecture}.
a8f24a35
EZ
21461@end table
21462
c906108c
SS
21463@menu
21464* Active Targets:: Active targets
21465* Target Commands:: Commands for managing targets
c906108c 21466* Byte Order:: Choosing target byte order
c906108c
SS
21467@end menu
21468
6d2ebf8b 21469@node Active Targets
79a6e687 21470@section Active Targets
7a292a7a 21471
c906108c
SS
21472@cindex stacking targets
21473@cindex active targets
21474@cindex multiple targets
21475
8ea5bce5 21476There are multiple classes of targets such as: processes, executable files or
c0edd9ed
JK
21477recording sessions. Core files belong to the process class, making core file
21478and process mutually exclusive. Otherwise, @value{GDBN} can work concurrently
21479on multiple active targets, one in each class. This allows you to (for
21480example) start a process and inspect its activity, while still having access to
21481the executable file after the process finishes. Or if you start process
21482recording (@pxref{Reverse Execution}) and @code{reverse-step} there, you are
21483presented a virtual layer of the recording target, while the process target
21484remains stopped at the chronologically last point of the process execution.
21485
21486Use the @code{core-file} and @code{exec-file} commands to select a new core
21487file or executable target (@pxref{Files, ,Commands to Specify Files}). To
21488specify as a target a process that is already running, use the @code{attach}
21489command (@pxref{Attach, ,Debugging an Already-running Process}).
c906108c 21490
6d2ebf8b 21491@node Target Commands
79a6e687 21492@section Commands for Managing Targets
c906108c
SS
21493
21494@table @code
21495@item target @var{type} @var{parameters}
7a292a7a
SS
21496Connects the @value{GDBN} host environment to a target machine or
21497process. A target is typically a protocol for talking to debugging
21498facilities. You use the argument @var{type} to specify the type or
21499protocol of the target machine.
c906108c
SS
21500
21501Further @var{parameters} are interpreted by the target protocol, but
21502typically include things like device names or host names to connect
21503with, process numbers, and baud rates.
c906108c
SS
21504
21505The @code{target} command does not repeat if you press @key{RET} again
21506after executing the command.
21507
21508@kindex help target
21509@item help target
21510Displays the names of all targets available. To display targets
21511currently selected, use either @code{info target} or @code{info files}
79a6e687 21512(@pxref{Files, ,Commands to Specify Files}).
c906108c
SS
21513
21514@item help target @var{name}
21515Describe a particular target, including any parameters necessary to
21516select it.
21517
21518@kindex set gnutarget
21519@item set gnutarget @var{args}
5d161b24 21520@value{GDBN} uses its own library BFD to read your files. @value{GDBN}
c906108c 21521knows whether it is reading an @dfn{executable},
5d161b24
DB
21522a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
21523with the @code{set gnutarget} command. Unlike most @code{target} commands,
c906108c
SS
21524with @code{gnutarget} the @code{target} refers to a program, not a machine.
21525
d4f3574e 21526@quotation
c906108c
SS
21527@emph{Warning:} To specify a file format with @code{set gnutarget},
21528you must know the actual BFD name.
d4f3574e 21529@end quotation
c906108c 21530
d4f3574e 21531@noindent
79a6e687 21532@xref{Files, , Commands to Specify Files}.
c906108c 21533
5d161b24 21534@kindex show gnutarget
c906108c
SS
21535@item show gnutarget
21536Use the @code{show gnutarget} command to display what file format
21537@code{gnutarget} is set to read. If you have not set @code{gnutarget},
21538@value{GDBN} will determine the file format for each file automatically,
c4957902 21539and @code{show gnutarget} displays @samp{The current BFD target is "auto"}.
c906108c
SS
21540@end table
21541
4644b6e3 21542@cindex common targets
c906108c
SS
21543Here are some common targets (available, or not, depending on the GDB
21544configuration):
c906108c
SS
21545
21546@table @code
4644b6e3 21547@kindex target
c906108c 21548@item target exec @var{program}
4644b6e3 21549@cindex executable file target
c906108c
SS
21550An executable file. @samp{target exec @var{program}} is the same as
21551@samp{exec-file @var{program}}.
21552
c906108c 21553@item target core @var{filename}
4644b6e3 21554@cindex core dump file target
c906108c
SS
21555A core dump file. @samp{target core @var{filename}} is the same as
21556@samp{core-file @var{filename}}.
c906108c 21557
1a10341b 21558@item target remote @var{medium}
4644b6e3 21559@cindex remote target
1a10341b
JB
21560A remote system connected to @value{GDBN} via a serial line or network
21561connection. This command tells @value{GDBN} to use its own remote
21562protocol over @var{medium} for debugging. @xref{Remote Debugging}.
21563
21564For example, if you have a board connected to @file{/dev/ttya} on the
21565machine running @value{GDBN}, you could say:
21566
21567@smallexample
21568target remote /dev/ttya
21569@end smallexample
21570
21571@code{target remote} supports the @code{load} command. This is only
21572useful if you have some other way of getting the stub to the target
21573system, and you can put it somewhere in memory where it won't get
21574clobbered by the download.
c906108c 21575
ee8e71d4 21576@item target sim @r{[}@var{simargs}@r{]} @dots{}
4644b6e3 21577@cindex built-in simulator target
2df3850c 21578Builtin CPU simulator. @value{GDBN} includes simulators for most architectures.
104c1213 21579In general,
474c8240 21580@smallexample
104c1213
JM
21581 target sim
21582 load
21583 run
474c8240 21584@end smallexample
d4f3574e 21585@noindent
104c1213 21586works; however, you cannot assume that a specific memory map, device
d4f3574e 21587drivers, or even basic I/O is available, although some simulators do
104c1213
JM
21588provide these. For info about any processor-specific simulator details,
21589see the appropriate section in @ref{Embedded Processors, ,Embedded
21590Processors}.
21591
6a3cb8e8
PA
21592@item target native
21593@cindex native target
21594Setup for local/native process debugging. Useful to make the
21595@code{run} command spawn native processes (likewise @code{attach},
21596etc.@:) even when @code{set auto-connect-native-target} is @code{off}
21597(@pxref{set auto-connect-native-target}).
21598
c906108c
SS
21599@end table
21600
5d161b24 21601Different targets are available on different configurations of @value{GDBN};
c906108c 21602your configuration may have more or fewer targets.
c906108c 21603
721c2651
EZ
21604Many remote targets require you to download the executable's code once
21605you've successfully established a connection. You may wish to control
3d00d119
DJ
21606various aspects of this process.
21607
21608@table @code
721c2651
EZ
21609
21610@item set hash
21611@kindex set hash@r{, for remote monitors}
21612@cindex hash mark while downloading
21613This command controls whether a hash mark @samp{#} is displayed while
21614downloading a file to the remote monitor. If on, a hash mark is
21615displayed after each S-record is successfully downloaded to the
21616monitor.
21617
21618@item show hash
21619@kindex show hash@r{, for remote monitors}
21620Show the current status of displaying the hash mark.
21621
21622@item set debug monitor
21623@kindex set debug monitor
21624@cindex display remote monitor communications
21625Enable or disable display of communications messages between
21626@value{GDBN} and the remote monitor.
21627
21628@item show debug monitor
21629@kindex show debug monitor
21630Show the current status of displaying communications between
21631@value{GDBN} and the remote monitor.
a8f24a35 21632@end table
c906108c
SS
21633
21634@table @code
21635
5cf30ebf
LM
21636@kindex load @var{filename} @var{offset}
21637@item load @var{filename} @var{offset}
8edfe269 21638@anchor{load}
c906108c
SS
21639Depending on what remote debugging facilities are configured into
21640@value{GDBN}, the @code{load} command may be available. Where it exists, it
21641is meant to make @var{filename} (an executable) available for debugging
21642on the remote system---by downloading, or dynamic linking, for example.
21643@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
21644the @code{add-symbol-file} command.
21645
21646If your @value{GDBN} does not have a @code{load} command, attempting to
21647execute it gets the error message ``@code{You can't do that when your
21648target is @dots{}}''
c906108c
SS
21649
21650The file is loaded at whatever address is specified in the executable.
21651For some object file formats, you can specify the load address when you
21652link the program; for other formats, like a.out, the object file format
21653specifies a fixed address.
21654@c FIXME! This would be a good place for an xref to the GNU linker doc.
21655
5cf30ebf
LM
21656It is also possible to tell @value{GDBN} to load the executable file at a
21657specific offset described by the optional argument @var{offset}. When
21658@var{offset} is provided, @var{filename} must also be provided.
21659
68437a39
DJ
21660Depending on the remote side capabilities, @value{GDBN} may be able to
21661load programs into flash memory.
21662
c906108c
SS
21663@code{load} does not repeat if you press @key{RET} again after using it.
21664@end table
21665
78cbbba8
LM
21666@table @code
21667
21668@kindex flash-erase
21669@item flash-erase
21670@anchor{flash-erase}
21671
21672Erases all known flash memory regions on the target.
21673
21674@end table
21675
6d2ebf8b 21676@node Byte Order
79a6e687 21677@section Choosing Target Byte Order
7a292a7a 21678
c906108c
SS
21679@cindex choosing target byte order
21680@cindex target byte order
c906108c 21681
eb17f351 21682Some types of processors, such as the @acronym{MIPS}, PowerPC, and Renesas SH,
c906108c
SS
21683offer the ability to run either big-endian or little-endian byte
21684orders. Usually the executable or symbol will include a bit to
21685designate the endian-ness, and you will not need to worry about
21686which to use. However, you may still find it useful to adjust
d4f3574e 21687@value{GDBN}'s idea of processor endian-ness manually.
c906108c
SS
21688
21689@table @code
4644b6e3 21690@kindex set endian
c906108c
SS
21691@item set endian big
21692Instruct @value{GDBN} to assume the target is big-endian.
21693
c906108c
SS
21694@item set endian little
21695Instruct @value{GDBN} to assume the target is little-endian.
21696
c906108c
SS
21697@item set endian auto
21698Instruct @value{GDBN} to use the byte order associated with the
21699executable.
21700
21701@item show endian
21702Display @value{GDBN}'s current idea of the target byte order.
21703
21704@end table
21705
4b2dfa9d
MR
21706If the @code{set endian auto} mode is in effect and no executable has
21707been selected, then the endianness used is the last one chosen either
21708by one of the @code{set endian big} and @code{set endian little}
21709commands or by inferring from the last executable used. If no
21710endianness has been previously chosen, then the default for this mode
21711is inferred from the target @value{GDBN} has been built for, and is
21712@code{little} if the name of the target CPU has an @code{el} suffix
21713and @code{big} otherwise.
21714
c906108c
SS
21715Note that these commands merely adjust interpretation of symbolic
21716data on the host, and that they have absolutely no effect on the
21717target system.
21718
ea35711c
DJ
21719
21720@node Remote Debugging
21721@chapter Debugging Remote Programs
c906108c
SS
21722@cindex remote debugging
21723
21724If you are trying to debug a program running on a machine that cannot run
5d161b24
DB
21725@value{GDBN} in the usual way, it is often useful to use remote debugging.
21726For example, you might use remote debugging on an operating system kernel,
c906108c
SS
21727or on a small system which does not have a general purpose operating system
21728powerful enough to run a full-featured debugger.
21729
21730Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
21731to make this work with particular debugging targets. In addition,
5d161b24 21732@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
c906108c
SS
21733but not specific to any particular target system) which you can use if you
21734write the remote stubs---the code that runs on the remote system to
21735communicate with @value{GDBN}.
21736
21737Other remote targets may be available in your
21738configuration of @value{GDBN}; use @code{help target} to list them.
c906108c 21739
6b2f586d 21740@menu
07f31aa6 21741* Connecting:: Connecting to a remote target
a6b151f1 21742* File Transfer:: Sending files to a remote system
6b2f586d 21743* Server:: Using the gdbserver program
79a6e687
BW
21744* Remote Configuration:: Remote configuration
21745* Remote Stub:: Implementing a remote stub
6b2f586d
AC
21746@end menu
21747
07f31aa6 21748@node Connecting
79a6e687 21749@section Connecting to a Remote Target
19d9d4ef
DB
21750@cindex remote debugging, connecting
21751@cindex @code{gdbserver}, connecting
21752@cindex remote debugging, types of connections
21753@cindex @code{gdbserver}, types of connections
21754@cindex @code{gdbserver}, @code{target remote} mode
21755@cindex @code{gdbserver}, @code{target extended-remote} mode
21756
21757This section describes how to connect to a remote target, including the
21758types of connections and their differences, how to set up executable and
21759symbol files on the host and target, and the commands used for
21760connecting to and disconnecting from the remote target.
21761
21762@subsection Types of Remote Connections
21763
21764@value{GDBN} supports two types of remote connections, @code{target remote}
21765mode and @code{target extended-remote} mode. Note that many remote targets
21766support only @code{target remote} mode. There are several major
21767differences between the two types of connections, enumerated here:
21768
21769@table @asis
21770
21771@cindex remote debugging, detach and program exit
21772@item Result of detach or program exit
21773@strong{With target remote mode:} When the debugged program exits or you
21774detach from it, @value{GDBN} disconnects from the target. When using
21775@code{gdbserver}, @code{gdbserver} will exit.
21776
21777@strong{With target extended-remote mode:} When the debugged program exits or
21778you detach from it, @value{GDBN} remains connected to the target, even
21779though no program is running. You can rerun the program, attach to a
21780running program, or use @code{monitor} commands specific to the target.
21781
21782When using @code{gdbserver} in this case, it does not exit unless it was
21783invoked using the @option{--once} option. If the @option{--once} option
21784was not used, you can ask @code{gdbserver} to exit using the
21785@code{monitor exit} command (@pxref{Monitor Commands for gdbserver}).
21786
21787@item Specifying the program to debug
21788For both connection types you use the @code{file} command to specify the
21789program on the host system. If you are using @code{gdbserver} there are
21790some differences in how to specify the location of the program on the
21791target.
21792
21793@strong{With target remote mode:} You must either specify the program to debug
21794on the @code{gdbserver} command line or use the @option{--attach} option
21795(@pxref{Attaching to a program,,Attaching to a Running Program}).
21796
21797@cindex @option{--multi}, @code{gdbserver} option
21798@strong{With target extended-remote mode:} You may specify the program to debug
21799on the @code{gdbserver} command line, or you can load the program or attach
21800to it using @value{GDBN} commands after connecting to @code{gdbserver}.
21801
21802@anchor{--multi Option in Types of Remote Connnections}
21803You can start @code{gdbserver} without supplying an initial command to run
21804or process ID to attach. To do this, use the @option{--multi} command line
21805option. Then you can connect using @code{target extended-remote} and start
21806the program you want to debug (see below for details on using the
21807@code{run} command in this scenario). Note that the conditions under which
21808@code{gdbserver} terminates depend on how @value{GDBN} connects to it
21809(@code{target remote} or @code{target extended-remote}). The
21810@option{--multi} option to @code{gdbserver} has no influence on that.
07f31aa6 21811
19d9d4ef
DB
21812@item The @code{run} command
21813@strong{With target remote mode:} The @code{run} command is not
21814supported. Once a connection has been established, you can use all
21815the usual @value{GDBN} commands to examine and change data. The
21816remote program is already running, so you can use commands like
21817@kbd{step} and @kbd{continue}.
21818
21819@strong{With target extended-remote mode:} The @code{run} command is
21820supported. The @code{run} command uses the value set by
21821@code{set remote exec-file} (@pxref{set remote exec-file}) to select
21822the program to run. Command line arguments are supported, except for
21823wildcard expansion and I/O redirection (@pxref{Arguments}).
21824
21825If you specify the program to debug on the command line, then the
21826@code{run} command is not required to start execution, and you can
21827resume using commands like @kbd{step} and @kbd{continue} as with
21828@code{target remote} mode.
21829
21830@anchor{Attaching in Types of Remote Connections}
21831@item Attaching
21832@strong{With target remote mode:} The @value{GDBN} command @code{attach} is
21833not supported. To attach to a running program using @code{gdbserver}, you
21834must use the @option{--attach} option (@pxref{Running gdbserver}).
21835
21836@strong{With target extended-remote mode:} To attach to a running program,
21837you may use the @code{attach} command after the connection has been
21838established. If you are using @code{gdbserver}, you may also invoke
21839@code{gdbserver} using the @option{--attach} option
21840(@pxref{Running gdbserver}).
21841
21842@end table
21843
21844@anchor{Host and target files}
21845@subsection Host and Target Files
21846@cindex remote debugging, symbol files
21847@cindex symbol files, remote debugging
21848
21849@value{GDBN}, running on the host, needs access to symbol and debugging
21850information for your program running on the target. This requires
21851access to an unstripped copy of your program, and possibly any associated
21852symbol files. Note that this section applies equally to both @code{target
21853remote} mode and @code{target extended-remote} mode.
21854
21855Some remote targets (@pxref{qXfer executable filename read}, and
21856@pxref{Host I/O Packets}) allow @value{GDBN} to access program files over
21857the same connection used to communicate with @value{GDBN}. With such a
21858target, if the remote program is unstripped, the only command you need is
21859@code{target remote} (or @code{target extended-remote}).
21860
21861If the remote program is stripped, or the target does not support remote
21862program file access, start up @value{GDBN} using the name of the local
1b6e6f5c 21863unstripped copy of your program as the first argument, or use the
19d9d4ef
DB
21864@code{file} command. Use @code{set sysroot} to specify the location (on
21865the host) of target libraries (unless your @value{GDBN} was compiled with
21866the correct sysroot using @code{--with-sysroot}). Alternatively, you
21867may use @code{set solib-search-path} to specify how @value{GDBN} locates
21868target libraries.
21869
21870The symbol file and target libraries must exactly match the executable
21871and libraries on the target, with one exception: the files on the host
21872system should not be stripped, even if the files on the target system
21873are. Mismatched or missing files will lead to confusing results
21874during debugging. On @sc{gnu}/Linux targets, mismatched or missing
21875files may also prevent @code{gdbserver} from debugging multi-threaded
21876programs.
07f31aa6 21877
19d9d4ef
DB
21878@subsection Remote Connection Commands
21879@cindex remote connection commands
c1168a2f
JD
21880@value{GDBN} can communicate with the target over a serial line, a
21881local Unix domain socket, or
86941c27
JB
21882over an @acronym{IP} network using @acronym{TCP} or @acronym{UDP}. In
21883each case, @value{GDBN} uses the same protocol for debugging your
21884program; only the medium carrying the debugging packets varies. The
19d9d4ef
DB
21885@code{target remote} and @code{target extended-remote} commands
21886establish a connection to the target. Both commands accept the same
21887arguments, which indicate the medium to use:
86941c27
JB
21888
21889@table @code
21890
21891@item target remote @var{serial-device}
19d9d4ef 21892@itemx target extended-remote @var{serial-device}
07f31aa6 21893@cindex serial line, @code{target remote}
86941c27
JB
21894Use @var{serial-device} to communicate with the target. For example,
21895to use a serial line connected to the device named @file{/dev/ttyb}:
21896
21897@smallexample
21898target remote /dev/ttyb
21899@end smallexample
21900
07f31aa6 21901If you're using a serial line, you may want to give @value{GDBN} the
2446f5ea 21902@samp{--baud} option, or use the @code{set serial baud} command
0d12017b 21903(@pxref{Remote Configuration, set serial baud}) before the
9c16f35a 21904@code{target} command.
07f31aa6 21905
c1168a2f
JD
21906@item target remote @var{local-socket}
21907@itemx target extended-remote @var{local-socket}
21908@cindex local socket, @code{target remote}
21909@cindex Unix domain socket
21910Use @var{local-socket} to communicate with the target. For example,
21911to use a local Unix domain socket bound to the file system entry @file{/tmp/gdb-socket0}:
21912
21913@smallexample
21914target remote /tmp/gdb-socket0
21915@end smallexample
21916
21917Note that this command has the same form as the command to connect
21918to a serial line. @value{GDBN} will automatically determine which
21919kind of file you have specified and will make the appropriate kind
21920of connection.
21921This feature is not available if the host system does not support
21922Unix domain sockets.
21923
86941c27 21924@item target remote @code{@var{host}:@var{port}}
c7ab0aef 21925@itemx target remote @code{@var{[host]}:@var{port}}
86941c27 21926@itemx target remote @code{tcp:@var{host}:@var{port}}
c7ab0aef
SDJ
21927@itemx target remote @code{tcp:@var{[host]}:@var{port}}
21928@itemx target remote @code{tcp4:@var{host}:@var{port}}
21929@itemx target remote @code{tcp6:@var{host}:@var{port}}
21930@itemx target remote @code{tcp6:@var{[host]}:@var{port}}
19d9d4ef 21931@itemx target extended-remote @code{@var{host}:@var{port}}
c7ab0aef 21932@itemx target extended-remote @code{@var{[host]}:@var{port}}
19d9d4ef 21933@itemx target extended-remote @code{tcp:@var{host}:@var{port}}
c7ab0aef
SDJ
21934@itemx target extended-remote @code{tcp:@var{[host]}:@var{port}}
21935@itemx target extended-remote @code{tcp4:@var{host}:@var{port}}
21936@itemx target extended-remote @code{tcp6:@var{host}:@var{port}}
21937@itemx target extended-remote @code{tcp6:@var{[host]}:@var{port}}
86941c27 21938@cindex @acronym{TCP} port, @code{target remote}
6a0b3457 21939Debug using a @acronym{TCP} connection to @var{port} on @var{host}.
c7ab0aef
SDJ
21940The @var{host} may be either a host name, a numeric @acronym{IPv4}
21941address, or a numeric @acronym{IPv6} address (with or without the
21942square brackets to separate the address from the port); @var{port}
21943must be a decimal number. The @var{host} could be the target machine
21944itself, if it is directly connected to the net, or it might be a
21945terminal server which in turn has a serial line to the target.
07f31aa6 21946
86941c27
JB
21947For example, to connect to port 2828 on a terminal server named
21948@code{manyfarms}:
07f31aa6
DJ
21949
21950@smallexample
21951target remote manyfarms:2828
21952@end smallexample
21953
c7ab0aef
SDJ
21954To connect to port 2828 on a terminal server whose address is
21955@code{2001:0db8:85a3:0000:0000:8a2e:0370:7334}, you can either use the
21956square bracket syntax:
21957
21958@smallexample
21959target remote [2001:0db8:85a3:0000:0000:8a2e:0370:7334]:2828
21960@end smallexample
21961
21962@noindent
21963or explicitly specify the @acronym{IPv6} protocol:
21964
21965@smallexample
21966target remote tcp6:2001:0db8:85a3:0000:0000:8a2e:0370:7334:2828
21967@end smallexample
21968
21969This last example may be confusing to the reader, because there is no
21970visible separation between the hostname and the port number.
21971Therefore, we recommend the user to provide @acronym{IPv6} addresses
21972using square brackets for clarity. However, it is important to
21973mention that for @value{GDBN} there is no ambiguity: the number after
21974the last colon is considered to be the port number.
21975
86941c27
JB
21976If your remote target is actually running on the same machine as your
21977debugger session (e.g.@: a simulator for your target running on the
21978same host), you can omit the hostname. For example, to connect to
21979port 1234 on your local machine:
07f31aa6
DJ
21980
21981@smallexample
21982target remote :1234
21983@end smallexample
21984@noindent
21985
21986Note that the colon is still required here.
21987
86941c27 21988@item target remote @code{udp:@var{host}:@var{port}}
c7ab0aef
SDJ
21989@itemx target remote @code{udp:@var{[host]}:@var{port}}
21990@itemx target remote @code{udp4:@var{host}:@var{port}}
21991@itemx target remote @code{udp6:@var{[host]}:@var{port}}
21992@itemx target extended-remote @code{udp:@var{host}:@var{port}}
19d9d4ef 21993@itemx target extended-remote @code{udp:@var{host}:@var{port}}
c7ab0aef
SDJ
21994@itemx target extended-remote @code{udp:@var{[host]}:@var{port}}
21995@itemx target extended-remote @code{udp4:@var{host}:@var{port}}
21996@itemx target extended-remote @code{udp6:@var{host}:@var{port}}
21997@itemx target extended-remote @code{udp6:@var{[host]}:@var{port}}
86941c27
JB
21998@cindex @acronym{UDP} port, @code{target remote}
21999Debug using @acronym{UDP} packets to @var{port} on @var{host}. For example, to
22000connect to @acronym{UDP} port 2828 on a terminal server named @code{manyfarms}:
07f31aa6
DJ
22001
22002@smallexample
22003target remote udp:manyfarms:2828
22004@end smallexample
22005
86941c27
JB
22006When using a @acronym{UDP} connection for remote debugging, you should
22007keep in mind that the `U' stands for ``Unreliable''. @acronym{UDP}
22008can silently drop packets on busy or unreliable networks, which will
22009cause havoc with your debugging session.
22010
66b8c7f6 22011@item target remote | @var{command}
19d9d4ef 22012@itemx target extended-remote | @var{command}
66b8c7f6
JB
22013@cindex pipe, @code{target remote} to
22014Run @var{command} in the background and communicate with it using a
22015pipe. The @var{command} is a shell command, to be parsed and expanded
22016by the system's command shell, @code{/bin/sh}; it should expect remote
22017protocol packets on its standard input, and send replies on its
22018standard output. You could use this to run a stand-alone simulator
22019that speaks the remote debugging protocol, to make net connections
22020using programs like @code{ssh}, or for other similar tricks.
22021
22022If @var{command} closes its standard output (perhaps by exiting),
22023@value{GDBN} will try to send it a @code{SIGTERM} signal. (If the
22024program has already exited, this will have no effect.)
22025
86941c27 22026@end table
07f31aa6 22027
07f31aa6
DJ
22028@cindex interrupting remote programs
22029@cindex remote programs, interrupting
22030Whenever @value{GDBN} is waiting for the remote program, if you type the
c8aa23ab 22031interrupt character (often @kbd{Ctrl-c}), @value{GDBN} attempts to stop the
07f31aa6
DJ
22032program. This may or may not succeed, depending in part on the hardware
22033and the serial drivers the remote system uses. If you type the
22034interrupt character once again, @value{GDBN} displays this prompt:
22035
22036@smallexample
22037Interrupted while waiting for the program.
22038Give up (and stop debugging it)? (y or n)
22039@end smallexample
22040
19d9d4ef
DB
22041In @code{target remote} mode, if you type @kbd{y}, @value{GDBN} abandons
22042the remote debugging session. (If you decide you want to try again later,
22043you can use @kbd{target remote} again to connect once more.) If you type
22044@kbd{n}, @value{GDBN} goes back to waiting.
22045
22046In @code{target extended-remote} mode, typing @kbd{n} will leave
22047@value{GDBN} connected to the target.
07f31aa6
DJ
22048
22049@table @code
22050@kindex detach (remote)
22051@item detach
22052When you have finished debugging the remote program, you can use the
22053@code{detach} command to release it from @value{GDBN} control.
22054Detaching from the target normally resumes its execution, but the results
22055will depend on your particular remote stub. After the @code{detach}
19d9d4ef
DB
22056command in @code{target remote} mode, @value{GDBN} is free to connect to
22057another target. In @code{target extended-remote} mode, @value{GDBN} is
22058still connected to the target.
07f31aa6
DJ
22059
22060@kindex disconnect
22061@item disconnect
19d9d4ef 22062The @code{disconnect} command closes the connection to the target, and
07f31aa6
DJ
22063the target is generally not resumed. It will wait for @value{GDBN}
22064(this instance or another one) to connect and continue debugging. After
22065the @code{disconnect} command, @value{GDBN} is again free to connect to
22066another target.
09d4efe1
EZ
22067
22068@cindex send command to remote monitor
fad38dfa
EZ
22069@cindex extend @value{GDBN} for remote targets
22070@cindex add new commands for external monitor
09d4efe1
EZ
22071@kindex monitor
22072@item monitor @var{cmd}
fad38dfa
EZ
22073This command allows you to send arbitrary commands directly to the
22074remote monitor. Since @value{GDBN} doesn't care about the commands it
22075sends like this, this command is the way to extend @value{GDBN}---you
22076can add new commands that only the external monitor will understand
22077and implement.
07f31aa6
DJ
22078@end table
22079
a6b151f1
DJ
22080@node File Transfer
22081@section Sending files to a remote system
22082@cindex remote target, file transfer
22083@cindex file transfer
22084@cindex sending files to remote systems
22085
22086Some remote targets offer the ability to transfer files over the same
22087connection used to communicate with @value{GDBN}. This is convenient
22088for targets accessible through other means, e.g.@: @sc{gnu}/Linux systems
22089running @code{gdbserver} over a network interface. For other targets,
22090e.g.@: embedded devices with only a single serial port, this may be
22091the only way to upload or download files.
22092
22093Not all remote targets support these commands.
22094
22095@table @code
22096@kindex remote put
22097@item remote put @var{hostfile} @var{targetfile}
22098Copy file @var{hostfile} from the host system (the machine running
22099@value{GDBN}) to @var{targetfile} on the target system.
22100
22101@kindex remote get
22102@item remote get @var{targetfile} @var{hostfile}
22103Copy file @var{targetfile} from the target system to @var{hostfile}
22104on the host system.
22105
22106@kindex remote delete
22107@item remote delete @var{targetfile}
22108Delete @var{targetfile} from the target system.
22109
22110@end table
22111
6f05cf9f 22112@node Server
79a6e687 22113@section Using the @code{gdbserver} Program
6f05cf9f
AC
22114
22115@kindex gdbserver
22116@cindex remote connection without stubs
22117@code{gdbserver} is a control program for Unix-like systems, which
22118allows you to connect your program with a remote @value{GDBN} via
19d9d4ef
DB
22119@code{target remote} or @code{target extended-remote}---but without
22120linking in the usual debugging stub.
6f05cf9f
AC
22121
22122@code{gdbserver} is not a complete replacement for the debugging stubs,
22123because it requires essentially the same operating-system facilities
22124that @value{GDBN} itself does. In fact, a system that can run
22125@code{gdbserver} to connect to a remote @value{GDBN} could also run
22126@value{GDBN} locally! @code{gdbserver} is sometimes useful nevertheless,
22127because it is a much smaller program than @value{GDBN} itself. It is
22128also easier to port than all of @value{GDBN}, so you may be able to get
22129started more quickly on a new system by using @code{gdbserver}.
22130Finally, if you develop code for real-time systems, you may find that
22131the tradeoffs involved in real-time operation make it more convenient to
22132do as much development work as possible on another system, for example
22133by cross-compiling. You can use @code{gdbserver} to make a similar
22134choice for debugging.
22135
22136@value{GDBN} and @code{gdbserver} communicate via either a serial line
22137or a TCP connection, using the standard @value{GDBN} remote serial
22138protocol.
22139
2d717e4f
DJ
22140@quotation
22141@emph{Warning:} @code{gdbserver} does not have any built-in security.
22142Do not run @code{gdbserver} connected to any public network; a
22143@value{GDBN} connection to @code{gdbserver} provides access to the
22144target system with the same privileges as the user running
22145@code{gdbserver}.
22146@end quotation
22147
19d9d4ef 22148@anchor{Running gdbserver}
2d717e4f
DJ
22149@subsection Running @code{gdbserver}
22150@cindex arguments, to @code{gdbserver}
d9b1a651 22151@cindex @code{gdbserver}, command-line arguments
2d717e4f
DJ
22152
22153Run @code{gdbserver} on the target system. You need a copy of the
22154program you want to debug, including any libraries it requires.
6f05cf9f
AC
22155@code{gdbserver} does not need your program's symbol table, so you can
22156strip the program if necessary to save space. @value{GDBN} on the host
22157system does all the symbol handling.
22158
22159To use the server, you must tell it how to communicate with @value{GDBN};
56460a61 22160the name of your program; and the arguments for your program. The usual
6f05cf9f
AC
22161syntax is:
22162
22163@smallexample
22164target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
22165@end smallexample
22166
6cf36756
SM
22167@var{comm} is either a device name (to use a serial line), or a TCP
22168hostname and portnumber, or @code{-} or @code{stdio} to use
22169stdin/stdout of @code{gdbserver}.
e0f9f062 22170For example, to debug Emacs with the argument
6f05cf9f
AC
22171@samp{foo.txt} and communicate with @value{GDBN} over the serial port
22172@file{/dev/com1}:
22173
22174@smallexample
22175target> gdbserver /dev/com1 emacs foo.txt
22176@end smallexample
22177
6cf36756
SM
22178@code{gdbserver} waits passively for the host @value{GDBN} to communicate
22179with it.
6f05cf9f
AC
22180
22181To use a TCP connection instead of a serial line:
22182
22183@smallexample
22184target> gdbserver host:2345 emacs foo.txt
22185@end smallexample
22186
22187The only difference from the previous example is the first argument,
22188specifying that you are communicating with the host @value{GDBN} via
22189TCP. The @samp{host:2345} argument means that @code{gdbserver} is to
22190expect a TCP connection from machine @samp{host} to local TCP port 2345.
22191(Currently, the @samp{host} part is ignored.) You can choose any number
22192you want for the port number as long as it does not conflict with any
22193TCP ports already in use on the target system (for example, @code{23} is
22194reserved for @code{telnet}).@footnote{If you choose a port number that
22195conflicts with another service, @code{gdbserver} prints an error message
22196and exits.} You must use the same port number with the host @value{GDBN}
22197@code{target remote} command.
22198
6cf36756
SM
22199The @code{stdio} connection is useful when starting @code{gdbserver}
22200with ssh:
e0f9f062
DE
22201
22202@smallexample
6cf36756 22203(gdb) target remote | ssh -T hostname gdbserver - hello
e0f9f062
DE
22204@end smallexample
22205
6cf36756
SM
22206The @samp{-T} option to ssh is provided because we don't need a remote pty,
22207and we don't want escape-character handling. Ssh does this by default when
22208a command is provided, the flag is provided to make it explicit.
22209You could elide it if you want to.
e0f9f062 22210
6cf36756
SM
22211Programs started with stdio-connected gdbserver have @file{/dev/null} for
22212@code{stdin}, and @code{stdout},@code{stderr} are sent back to gdb for
22213display through a pipe connected to gdbserver.
22214Both @code{stdout} and @code{stderr} use the same pipe.
e0f9f062 22215
19d9d4ef 22216@anchor{Attaching to a program}
2d717e4f 22217@subsubsection Attaching to a Running Program
d9b1a651
EZ
22218@cindex attach to a program, @code{gdbserver}
22219@cindex @option{--attach}, @code{gdbserver} option
2d717e4f 22220
56460a61
DJ
22221On some targets, @code{gdbserver} can also attach to running programs.
22222This is accomplished via the @code{--attach} argument. The syntax is:
22223
22224@smallexample
2d717e4f 22225target> gdbserver --attach @var{comm} @var{pid}
56460a61
DJ
22226@end smallexample
22227
19d9d4ef
DB
22228@var{pid} is the process ID of a currently running process. It isn't
22229necessary to point @code{gdbserver} at a binary for the running process.
22230
22231In @code{target extended-remote} mode, you can also attach using the
22232@value{GDBN} attach command
22233(@pxref{Attaching in Types of Remote Connections}).
56460a61 22234
b1fe9455 22235@pindex pidof
b1fe9455
DJ
22236You can debug processes by name instead of process ID if your target has the
22237@code{pidof} utility:
22238
22239@smallexample
2d717e4f 22240target> gdbserver --attach @var{comm} `pidof @var{program}`
b1fe9455
DJ
22241@end smallexample
22242
f822c95b 22243In case more than one copy of @var{program} is running, or @var{program}
b1fe9455
DJ
22244has multiple threads, most versions of @code{pidof} support the
22245@code{-s} option to only return the first process ID.
22246
03f2bd59
JK
22247@subsubsection TCP port allocation lifecycle of @code{gdbserver}
22248
19d9d4ef
DB
22249This section applies only when @code{gdbserver} is run to listen on a TCP
22250port.
03f2bd59
JK
22251
22252@code{gdbserver} normally terminates after all of its debugged processes have
22253terminated in @kbd{target remote} mode. On the other hand, for @kbd{target
22254extended-remote}, @code{gdbserver} stays running even with no processes left.
22255@value{GDBN} normally terminates the spawned debugged process on its exit,
22256which normally also terminates @code{gdbserver} in the @kbd{target remote}
22257mode. Therefore, when the connection drops unexpectedly, and @value{GDBN}
22258cannot ask @code{gdbserver} to kill its debugged processes, @code{gdbserver}
22259stays running even in the @kbd{target remote} mode.
22260
22261When @code{gdbserver} stays running, @value{GDBN} can connect to it again later.
22262Such reconnecting is useful for features like @ref{disconnected tracing}. For
22263completeness, at most one @value{GDBN} can be connected at a time.
22264
22265@cindex @option{--once}, @code{gdbserver} option
22266By default, @code{gdbserver} keeps the listening TCP port open, so that
6e8c5661 22267subsequent connections are possible. However, if you start @code{gdbserver}
03f2bd59
JK
22268with the @option{--once} option, it will stop listening for any further
22269connection attempts after connecting to the first @value{GDBN} session. This
22270means no further connections to @code{gdbserver} will be possible after the
22271first one. It also means @code{gdbserver} will terminate after the first
22272connection with remote @value{GDBN} has closed, even for unexpectedly closed
22273connections and even in the @kbd{target extended-remote} mode. The
22274@option{--once} option allows reusing the same port number for connecting to
22275multiple instances of @code{gdbserver} running on the same host, since each
22276instance closes its port after the first connection.
2d717e4f 22277
87ce2a04 22278@anchor{Other Command-Line Arguments for gdbserver}
2d717e4f
DJ
22279@subsubsection Other Command-Line Arguments for @code{gdbserver}
22280
19d9d4ef
DB
22281You can use the @option{--multi} option to start @code{gdbserver} without
22282specifying a program to debug or a process to attach to. Then you can
22283attach in @code{target extended-remote} mode and run or attach to a
22284program. For more information,
22285@pxref{--multi Option in Types of Remote Connnections}.
22286
d9b1a651 22287@cindex @option{--debug}, @code{gdbserver} option
62709adf 22288The @option{--debug} option tells @code{gdbserver} to display extra
d9b1a651
EZ
22289status information about the debugging process.
22290@cindex @option{--remote-debug}, @code{gdbserver} option
22291The @option{--remote-debug} option tells @code{gdbserver} to display
aeb2e706
AH
22292remote protocol debug output.
22293@cindex @option{--debug-file}, @code{gdbserver} option
22294@cindex @code{gdbserver}, send all debug output to a single file
22295The @option{--debug-file=@var{filename}} option tells @code{gdbserver} to
22296write any debug output to the given @var{filename}. These options are intended
22297for @code{gdbserver} development and for bug reports to the developers.
2d717e4f 22298
87ce2a04
DE
22299@cindex @option{--debug-format}, @code{gdbserver} option
22300The @option{--debug-format=option1[,option2,...]} option tells
22301@code{gdbserver} to include additional information in each output.
22302Possible options are:
22303
22304@table @code
22305@item none
22306Turn off all extra information in debugging output.
22307@item all
22308Turn on all extra information in debugging output.
22309@item timestamps
22310Include a timestamp in each line of debugging output.
22311@end table
22312
22313Options are processed in order. Thus, for example, if @option{none}
22314appears last then no additional information is added to debugging output.
22315
d9b1a651 22316@cindex @option{--wrapper}, @code{gdbserver} option
ccd213ac
DJ
22317The @option{--wrapper} option specifies a wrapper to launch programs
22318for debugging. The option should be followed by the name of the
22319wrapper, then any command-line arguments to pass to the wrapper, then
22320@kbd{--} indicating the end of the wrapper arguments.
22321
22322@code{gdbserver} runs the specified wrapper program with a combined
22323command line including the wrapper arguments, then the name of the
22324program to debug, then any arguments to the program. The wrapper
22325runs until it executes your program, and then @value{GDBN} gains control.
22326
22327You can use any program that eventually calls @code{execve} with
22328its arguments as a wrapper. Several standard Unix utilities do
22329this, e.g.@: @code{env} and @code{nohup}. Any Unix shell script ending
22330with @code{exec "$@@"} will also work.
22331
22332For example, you can use @code{env} to pass an environment variable to
22333the debugged program, without setting the variable in @code{gdbserver}'s
22334environment:
22335
22336@smallexample
22337$ gdbserver --wrapper env LD_PRELOAD=libtest.so -- :2222 ./testprog
22338@end smallexample
22339
6d580b63
YQ
22340@cindex @option{--selftest}
22341The @option{--selftest} option runs the self tests in @code{gdbserver}:
22342
22343@smallexample
22344$ gdbserver --selftest
22345Ran 2 unit tests, 0 failed
22346@end smallexample
22347
22348These tests are disabled in release.
2d717e4f
DJ
22349@subsection Connecting to @code{gdbserver}
22350
19d9d4ef
DB
22351The basic procedure for connecting to the remote target is:
22352@itemize
2d717e4f 22353
19d9d4ef
DB
22354@item
22355Run @value{GDBN} on the host system.
f822c95b 22356
19d9d4ef
DB
22357@item
22358Make sure you have the necessary symbol files
22359(@pxref{Host and target files}).
22360Load symbols for your application using the @code{file} command before you
22361connect. Use @code{set sysroot} to locate target libraries (unless your
22362@value{GDBN} was compiled with the correct sysroot using
22363@code{--with-sysroot}).
f822c95b 22364
19d9d4ef 22365@item
79a6e687 22366Connect to your target (@pxref{Connecting,,Connecting to a Remote Target}).
6f05cf9f 22367For TCP connections, you must start up @code{gdbserver} prior to using
19d9d4ef 22368the @code{target} command. Otherwise you may get an error whose
6f05cf9f 22369text depends on the host system, but which usually looks something like
2d717e4f 22370@samp{Connection refused}. Don't use the @code{load}
19d9d4ef
DB
22371command in @value{GDBN} when using @code{target remote} mode, since the
22372program is already on the target.
22373
22374@end itemize
07f31aa6 22375
19d9d4ef 22376@anchor{Monitor Commands for gdbserver}
79a6e687 22377@subsection Monitor Commands for @code{gdbserver}
c74d0ad8
DJ
22378@cindex monitor commands, for @code{gdbserver}
22379
22380During a @value{GDBN} session using @code{gdbserver}, you can use the
22381@code{monitor} command to send special requests to @code{gdbserver}.
2d717e4f 22382Here are the available commands.
c74d0ad8
DJ
22383
22384@table @code
22385@item monitor help
22386List the available monitor commands.
22387
22388@item monitor set debug 0
22389@itemx monitor set debug 1
22390Disable or enable general debugging messages.
22391
22392@item monitor set remote-debug 0
22393@itemx monitor set remote-debug 1
22394Disable or enable specific debugging messages associated with the remote
22395protocol (@pxref{Remote Protocol}).
22396
aeb2e706
AH
22397@item monitor set debug-file filename
22398@itemx monitor set debug-file
22399Send any debug output to the given file, or to stderr.
22400
87ce2a04
DE
22401@item monitor set debug-format option1@r{[},option2,...@r{]}
22402Specify additional text to add to debugging messages.
22403Possible options are:
22404
22405@table @code
22406@item none
22407Turn off all extra information in debugging output.
22408@item all
22409Turn on all extra information in debugging output.
22410@item timestamps
22411Include a timestamp in each line of debugging output.
22412@end table
22413
22414Options are processed in order. Thus, for example, if @option{none}
22415appears last then no additional information is added to debugging output.
22416
cdbfd419
PP
22417@item monitor set libthread-db-search-path [PATH]
22418@cindex gdbserver, search path for @code{libthread_db}
22419When this command is issued, @var{path} is a colon-separated list of
22420directories to search for @code{libthread_db} (@pxref{Threads,,set
22421libthread-db-search-path}). If you omit @var{path},
84e578fb 22422@samp{libthread-db-search-path} will be reset to its default value.
cdbfd419 22423
98a5dd13
DE
22424The special entry @samp{$pdir} for @samp{libthread-db-search-path} is
22425not supported in @code{gdbserver}.
22426
2d717e4f
DJ
22427@item monitor exit
22428Tell gdbserver to exit immediately. This command should be followed by
22429@code{disconnect} to close the debugging session. @code{gdbserver} will
22430detach from any attached processes and kill any processes it created.
22431Use @code{monitor exit} to terminate @code{gdbserver} at the end
22432of a multi-process mode debug session.
22433
c74d0ad8
DJ
22434@end table
22435
fa593d66
PA
22436@subsection Tracepoints support in @code{gdbserver}
22437@cindex tracepoints support in @code{gdbserver}
22438
0fb4aa4b
PA
22439On some targets, @code{gdbserver} supports tracepoints, fast
22440tracepoints and static tracepoints.
fa593d66 22441
0fb4aa4b 22442For fast or static tracepoints to work, a special library called the
fa593d66
PA
22443@dfn{in-process agent} (IPA), must be loaded in the inferior process.
22444This library is built and distributed as an integral part of
0fb4aa4b
PA
22445@code{gdbserver}. In addition, support for static tracepoints
22446requires building the in-process agent library with static tracepoints
22447support. At present, the UST (LTTng Userspace Tracer,
22448@url{http://lttng.org/ust}) tracing engine is supported. This support
22449is automatically available if UST development headers are found in the
22450standard include path when @code{gdbserver} is built, or if
22451@code{gdbserver} was explicitly configured using @option{--with-ust}
22452to point at such headers. You can explicitly disable the support
22453using @option{--with-ust=no}.
fa593d66
PA
22454
22455There are several ways to load the in-process agent in your program:
22456
22457@table @code
22458@item Specifying it as dependency at link time
22459
22460You can link your program dynamically with the in-process agent
22461library. On most systems, this is accomplished by adding
22462@code{-linproctrace} to the link command.
22463
22464@item Using the system's preloading mechanisms
22465
22466You can force loading the in-process agent at startup time by using
22467your system's support for preloading shared libraries. Many Unixes
22468support the concept of preloading user defined libraries. In most
22469cases, you do that by specifying @code{LD_PRELOAD=libinproctrace.so}
22470in the environment. See also the description of @code{gdbserver}'s
22471@option{--wrapper} command line option.
22472
22473@item Using @value{GDBN} to force loading the agent at run time
22474
22475On some systems, you can force the inferior to load a shared library,
22476by calling a dynamic loader function in the inferior that takes care
22477of dynamically looking up and loading a shared library. On most Unix
22478systems, the function is @code{dlopen}. You'll use the @code{call}
22479command for that. For example:
22480
22481@smallexample
22482(@value{GDBP}) call dlopen ("libinproctrace.so", ...)
22483@end smallexample
22484
22485Note that on most Unix systems, for the @code{dlopen} function to be
22486available, the program needs to be linked with @code{-ldl}.
22487@end table
22488
22489On systems that have a userspace dynamic loader, like most Unix
22490systems, when you connect to @code{gdbserver} using @code{target
22491remote}, you'll find that the program is stopped at the dynamic
22492loader's entry point, and no shared library has been loaded in the
22493program's address space yet, including the in-process agent. In that
0fb4aa4b
PA
22494case, before being able to use any of the fast or static tracepoints
22495features, you need to let the loader run and load the shared
22496libraries. The simplest way to do that is to run the program to the
22497main procedure. E.g., if debugging a C or C@t{++} program, start
fa593d66
PA
22498@code{gdbserver} like so:
22499
22500@smallexample
22501$ gdbserver :9999 myprogram
22502@end smallexample
22503
22504Start GDB and connect to @code{gdbserver} like so, and run to main:
22505
22506@smallexample
22507$ gdb myprogram
22508(@value{GDBP}) target remote myhost:9999
225090x00007f215893ba60 in ?? () from /lib64/ld-linux-x86-64.so.2
22510(@value{GDBP}) b main
22511(@value{GDBP}) continue
22512@end smallexample
22513
22514The in-process tracing agent library should now be loaded into the
22515process; you can confirm it with the @code{info sharedlibrary}
22516command, which will list @file{libinproctrace.so} as loaded in the
0fb4aa4b
PA
22517process. You are now ready to install fast tracepoints, list static
22518tracepoint markers, probe static tracepoints markers, and start
fa593d66
PA
22519tracing.
22520
79a6e687
BW
22521@node Remote Configuration
22522@section Remote Configuration
501eef12 22523
9c16f35a
EZ
22524@kindex set remote
22525@kindex show remote
22526This section documents the configuration options available when
22527debugging remote programs. For the options related to the File I/O
fc320d37 22528extensions of the remote protocol, see @ref{system,
9c16f35a 22529system-call-allowed}.
501eef12
AC
22530
22531@table @code
9c16f35a 22532@item set remoteaddresssize @var{bits}
d3e8051b 22533@cindex address size for remote targets
9c16f35a
EZ
22534@cindex bits in remote address
22535Set the maximum size of address in a memory packet to the specified
22536number of bits. @value{GDBN} will mask off the address bits above
22537that number, when it passes addresses to the remote target. The
22538default value is the number of bits in the target's address.
22539
22540@item show remoteaddresssize
22541Show the current value of remote address size in bits.
22542
0d12017b 22543@item set serial baud @var{n}
9c16f35a
EZ
22544@cindex baud rate for remote targets
22545Set the baud rate for the remote serial I/O to @var{n} baud. The
22546value is used to set the speed of the serial port used for debugging
22547remote targets.
22548
0d12017b 22549@item show serial baud
9c16f35a
EZ
22550Show the current speed of the remote connection.
22551
236af5e3
YG
22552@item set serial parity @var{parity}
22553Set the parity for the remote serial I/O. Supported values of @var{parity} are:
22554@code{even}, @code{none}, and @code{odd}. The default is @code{none}.
22555
22556@item show serial parity
22557Show the current parity of the serial port.
22558
9c16f35a
EZ
22559@item set remotebreak
22560@cindex interrupt remote programs
22561@cindex BREAK signal instead of Ctrl-C
9a6253be 22562@anchor{set remotebreak}
9c16f35a 22563If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
c8aa23ab 22564when you type @kbd{Ctrl-c} to interrupt the program running
9a7a1b36 22565on the remote. If set to off, @value{GDBN} sends the @samp{Ctrl-C}
9c16f35a
EZ
22566character instead. The default is off, since most remote systems
22567expect to see @samp{Ctrl-C} as the interrupt signal.
22568
22569@item show remotebreak
22570Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
22571interrupt the remote program.
22572
23776285
MR
22573@item set remoteflow on
22574@itemx set remoteflow off
22575@kindex set remoteflow
22576Enable or disable hardware flow control (@code{RTS}/@code{CTS})
22577on the serial port used to communicate to the remote target.
22578
22579@item show remoteflow
22580@kindex show remoteflow
22581Show the current setting of hardware flow control.
22582
9c16f35a
EZ
22583@item set remotelogbase @var{base}
22584Set the base (a.k.a.@: radix) of logging serial protocol
22585communications to @var{base}. Supported values of @var{base} are:
22586@code{ascii}, @code{octal}, and @code{hex}. The default is
22587@code{ascii}.
22588
22589@item show remotelogbase
22590Show the current setting of the radix for logging remote serial
22591protocol.
22592
22593@item set remotelogfile @var{file}
22594@cindex record serial communications on file
22595Record remote serial communications on the named @var{file}. The
22596default is not to record at all.
22597
2d8b6830 22598@item show remotelogfile
9c16f35a
EZ
22599Show the current setting of the file name on which to record the
22600serial communications.
22601
22602@item set remotetimeout @var{num}
22603@cindex timeout for serial communications
22604@cindex remote timeout
22605Set the timeout limit to wait for the remote target to respond to
22606@var{num} seconds. The default is 2 seconds.
22607
22608@item show remotetimeout
22609Show the current number of seconds to wait for the remote target
22610responses.
22611
22612@cindex limit hardware breakpoints and watchpoints
22613@cindex remote target, limit break- and watchpoints
501eef12
AC
22614@anchor{set remote hardware-watchpoint-limit}
22615@anchor{set remote hardware-breakpoint-limit}
22616@item set remote hardware-watchpoint-limit @var{limit}
22617@itemx set remote hardware-breakpoint-limit @var{limit}
055303e2
AB
22618Restrict @value{GDBN} to using @var{limit} remote hardware watchpoints
22619or breakpoints. The @var{limit} can be set to 0 to disable hardware
22620watchpoints or breakpoints, and @code{unlimited} for unlimited
22621watchpoints or breakpoints.
22622
22623@item show remote hardware-watchpoint-limit
22624@itemx show remote hardware-breakpoint-limit
22625Show the current limit for the number of hardware watchpoints or
22626breakpoints that @value{GDBN} can use.
2d717e4f 22627
480a3f21
PW
22628@cindex limit hardware watchpoints length
22629@cindex remote target, limit watchpoints length
22630@anchor{set remote hardware-watchpoint-length-limit}
22631@item set remote hardware-watchpoint-length-limit @var{limit}
055303e2
AB
22632Restrict @value{GDBN} to using @var{limit} bytes for the maximum
22633length of a remote hardware watchpoint. A @var{limit} of 0 disables
22634hardware watchpoints and @code{unlimited} allows watchpoints of any
22635length.
480a3f21
PW
22636
22637@item show remote hardware-watchpoint-length-limit
22638Show the current limit (in bytes) of the maximum length of
22639a remote hardware watchpoint.
22640
2d717e4f
DJ
22641@item set remote exec-file @var{filename}
22642@itemx show remote exec-file
22643@anchor{set remote exec-file}
22644@cindex executable file, for remote target
22645Select the file used for @code{run} with @code{target
22646extended-remote}. This should be set to a filename valid on the
22647target system. If it is not set, the target will use a default
22648filename (e.g.@: the last program run).
84603566 22649
9a7071a8
JB
22650@item set remote interrupt-sequence
22651@cindex interrupt remote programs
22652@cindex select Ctrl-C, BREAK or BREAK-g
22653Allow the user to select one of @samp{Ctrl-C}, a @code{BREAK} or
22654@samp{BREAK-g} as the
22655sequence to the remote target in order to interrupt the execution.
22656@samp{Ctrl-C} is a default. Some system prefers @code{BREAK} which
22657is high level of serial line for some certain time.
22658Linux kernel prefers @samp{BREAK-g}, a.k.a Magic SysRq g.
22659It is @code{BREAK} signal followed by character @code{g}.
22660
22661@item show interrupt-sequence
22662Show which of @samp{Ctrl-C}, @code{BREAK} or @code{BREAK-g}
22663is sent by @value{GDBN} to interrupt the remote program.
22664@code{BREAK-g} is BREAK signal followed by @code{g} and
22665also known as Magic SysRq g.
22666
22667@item set remote interrupt-on-connect
22668@cindex send interrupt-sequence on start
22669Specify whether interrupt-sequence is sent to remote target when
22670@value{GDBN} connects to it. This is mostly needed when you debug
22671Linux kernel. Linux kernel expects @code{BREAK} followed by @code{g}
22672which is known as Magic SysRq g in order to connect @value{GDBN}.
22673
22674@item show interrupt-on-connect
22675Show whether interrupt-sequence is sent
22676to remote target when @value{GDBN} connects to it.
22677
84603566
SL
22678@kindex set tcp
22679@kindex show tcp
22680@item set tcp auto-retry on
22681@cindex auto-retry, for remote TCP target
22682Enable auto-retry for remote TCP connections. This is useful if the remote
22683debugging agent is launched in parallel with @value{GDBN}; there is a race
22684condition because the agent may not become ready to accept the connection
22685before @value{GDBN} attempts to connect. When auto-retry is
22686enabled, if the initial attempt to connect fails, @value{GDBN} reattempts
22687to establish the connection using the timeout specified by
22688@code{set tcp connect-timeout}.
22689
22690@item set tcp auto-retry off
22691Do not auto-retry failed TCP connections.
22692
22693@item show tcp auto-retry
22694Show the current auto-retry setting.
22695
22696@item set tcp connect-timeout @var{seconds}
f81d1120 22697@itemx set tcp connect-timeout unlimited
84603566
SL
22698@cindex connection timeout, for remote TCP target
22699@cindex timeout, for remote target connection
22700Set the timeout for establishing a TCP connection to the remote target to
22701@var{seconds}. The timeout affects both polling to retry failed connections
22702(enabled by @code{set tcp auto-retry on}) and waiting for connections
22703that are merely slow to complete, and represents an approximate cumulative
f81d1120
PA
22704value. If @var{seconds} is @code{unlimited}, there is no timeout and
22705@value{GDBN} will keep attempting to establish a connection forever,
22706unless interrupted with @kbd{Ctrl-c}. The default is 15 seconds.
84603566
SL
22707
22708@item show tcp connect-timeout
22709Show the current connection timeout setting.
501eef12
AC
22710@end table
22711
427c3a89
DJ
22712@cindex remote packets, enabling and disabling
22713The @value{GDBN} remote protocol autodetects the packets supported by
22714your debugging stub. If you need to override the autodetection, you
22715can use these commands to enable or disable individual packets. Each
22716packet can be set to @samp{on} (the remote target supports this
22717packet), @samp{off} (the remote target does not support this packet),
22718or @samp{auto} (detect remote target support for this packet). They
22719all default to @samp{auto}. For more information about each packet,
22720see @ref{Remote Protocol}.
22721
22722During normal use, you should not have to use any of these commands.
22723If you do, that may be a bug in your remote debugging stub, or a bug
22724in @value{GDBN}. You may want to report the problem to the
22725@value{GDBN} developers.
22726
cfa9d6d9
DJ
22727For each packet @var{name}, the command to enable or disable the
22728packet is @code{set remote @var{name}-packet}. The available settings
22729are:
427c3a89 22730
cfa9d6d9 22731@multitable @columnfractions 0.28 0.32 0.25
427c3a89
DJ
22732@item Command Name
22733@tab Remote Packet
22734@tab Related Features
22735
cfa9d6d9 22736@item @code{fetch-register}
427c3a89
DJ
22737@tab @code{p}
22738@tab @code{info registers}
22739
cfa9d6d9 22740@item @code{set-register}
427c3a89
DJ
22741@tab @code{P}
22742@tab @code{set}
22743
cfa9d6d9 22744@item @code{binary-download}
427c3a89
DJ
22745@tab @code{X}
22746@tab @code{load}, @code{set}
22747
cfa9d6d9 22748@item @code{read-aux-vector}
427c3a89
DJ
22749@tab @code{qXfer:auxv:read}
22750@tab @code{info auxv}
22751
cfa9d6d9 22752@item @code{symbol-lookup}
427c3a89
DJ
22753@tab @code{qSymbol}
22754@tab Detecting multiple threads
22755
2d717e4f
DJ
22756@item @code{attach}
22757@tab @code{vAttach}
22758@tab @code{attach}
22759
cfa9d6d9 22760@item @code{verbose-resume}
427c3a89
DJ
22761@tab @code{vCont}
22762@tab Stepping or resuming multiple threads
22763
2d717e4f
DJ
22764@item @code{run}
22765@tab @code{vRun}
22766@tab @code{run}
22767
cfa9d6d9 22768@item @code{software-breakpoint}
427c3a89
DJ
22769@tab @code{Z0}
22770@tab @code{break}
22771
cfa9d6d9 22772@item @code{hardware-breakpoint}
427c3a89
DJ
22773@tab @code{Z1}
22774@tab @code{hbreak}
22775
cfa9d6d9 22776@item @code{write-watchpoint}
427c3a89
DJ
22777@tab @code{Z2}
22778@tab @code{watch}
22779
cfa9d6d9 22780@item @code{read-watchpoint}
427c3a89
DJ
22781@tab @code{Z3}
22782@tab @code{rwatch}
22783
cfa9d6d9 22784@item @code{access-watchpoint}
427c3a89
DJ
22785@tab @code{Z4}
22786@tab @code{awatch}
22787
c78fa86a
GB
22788@item @code{pid-to-exec-file}
22789@tab @code{qXfer:exec-file:read}
22790@tab @code{attach}, @code{run}
22791
cfa9d6d9
DJ
22792@item @code{target-features}
22793@tab @code{qXfer:features:read}
22794@tab @code{set architecture}
22795
22796@item @code{library-info}
22797@tab @code{qXfer:libraries:read}
22798@tab @code{info sharedlibrary}
22799
22800@item @code{memory-map}
22801@tab @code{qXfer:memory-map:read}
22802@tab @code{info mem}
22803
0fb4aa4b
PA
22804@item @code{read-sdata-object}
22805@tab @code{qXfer:sdata:read}
22806@tab @code{print $_sdata}
22807
4aa995e1
PA
22808@item @code{read-siginfo-object}
22809@tab @code{qXfer:siginfo:read}
22810@tab @code{print $_siginfo}
22811
22812@item @code{write-siginfo-object}
22813@tab @code{qXfer:siginfo:write}
22814@tab @code{set $_siginfo}
22815
dc146f7c
VP
22816@item @code{threads}
22817@tab @code{qXfer:threads:read}
22818@tab @code{info threads}
22819
cfa9d6d9 22820@item @code{get-thread-local-@*storage-address}
427c3a89
DJ
22821@tab @code{qGetTLSAddr}
22822@tab Displaying @code{__thread} variables
22823
711e434b
PM
22824@item @code{get-thread-information-block-address}
22825@tab @code{qGetTIBAddr}
22826@tab Display MS-Windows Thread Information Block.
22827
08388c79
DE
22828@item @code{search-memory}
22829@tab @code{qSearch:memory}
22830@tab @code{find}
22831
427c3a89
DJ
22832@item @code{supported-packets}
22833@tab @code{qSupported}
22834@tab Remote communications parameters
22835
82075af2
JS
22836@item @code{catch-syscalls}
22837@tab @code{QCatchSyscalls}
22838@tab @code{catch syscall}
22839
cfa9d6d9 22840@item @code{pass-signals}
89be2091
DJ
22841@tab @code{QPassSignals}
22842@tab @code{handle @var{signal}}
22843
9b224c5e
PA
22844@item @code{program-signals}
22845@tab @code{QProgramSignals}
22846@tab @code{handle @var{signal}}
22847
a6b151f1
DJ
22848@item @code{hostio-close-packet}
22849@tab @code{vFile:close}
22850@tab @code{remote get}, @code{remote put}
22851
22852@item @code{hostio-open-packet}
22853@tab @code{vFile:open}
22854@tab @code{remote get}, @code{remote put}
22855
22856@item @code{hostio-pread-packet}
22857@tab @code{vFile:pread}
22858@tab @code{remote get}, @code{remote put}
22859
22860@item @code{hostio-pwrite-packet}
22861@tab @code{vFile:pwrite}
22862@tab @code{remote get}, @code{remote put}
22863
22864@item @code{hostio-unlink-packet}
22865@tab @code{vFile:unlink}
22866@tab @code{remote delete}
a6f3e723 22867
b9e7b9c3
UW
22868@item @code{hostio-readlink-packet}
22869@tab @code{vFile:readlink}
22870@tab Host I/O
22871
0a93529c
GB
22872@item @code{hostio-fstat-packet}
22873@tab @code{vFile:fstat}
22874@tab Host I/O
22875
15a201c8
GB
22876@item @code{hostio-setfs-packet}
22877@tab @code{vFile:setfs}
22878@tab Host I/O
22879
a6f3e723
SL
22880@item @code{noack-packet}
22881@tab @code{QStartNoAckMode}
22882@tab Packet acknowledgment
07e059b5
VP
22883
22884@item @code{osdata}
22885@tab @code{qXfer:osdata:read}
22886@tab @code{info os}
0b16c5cf
PA
22887
22888@item @code{query-attached}
22889@tab @code{qAttached}
22890@tab Querying remote process attach state.
b3b9301e 22891
a46c1e42
PA
22892@item @code{trace-buffer-size}
22893@tab @code{QTBuffer:size}
22894@tab @code{set trace-buffer-size}
22895
bd3eecc3
PA
22896@item @code{trace-status}
22897@tab @code{qTStatus}
22898@tab @code{tstatus}
22899
b3b9301e
PA
22900@item @code{traceframe-info}
22901@tab @code{qXfer:traceframe-info:read}
22902@tab Traceframe info
03583c20 22903
1e4d1764
YQ
22904@item @code{install-in-trace}
22905@tab @code{InstallInTrace}
22906@tab Install tracepoint in tracing
22907
03583c20
UW
22908@item @code{disable-randomization}
22909@tab @code{QDisableRandomization}
22910@tab @code{set disable-randomization}
83364271 22911
aefd8b33
SDJ
22912@item @code{startup-with-shell}
22913@tab @code{QStartupWithShell}
22914@tab @code{set startup-with-shell}
22915
0a2dde4a
SDJ
22916@item @code{environment-hex-encoded}
22917@tab @code{QEnvironmentHexEncoded}
22918@tab @code{set environment}
22919
22920@item @code{environment-unset}
22921@tab @code{QEnvironmentUnset}
22922@tab @code{unset environment}
22923
22924@item @code{environment-reset}
22925@tab @code{QEnvironmentReset}
22926@tab @code{Reset the inferior environment (i.e., unset user-set variables)}
22927
bc3b087d
SDJ
22928@item @code{set-working-dir}
22929@tab @code{QSetWorkingDir}
22930@tab @code{set cwd}
22931
83364271
LM
22932@item @code{conditional-breakpoints-packet}
22933@tab @code{Z0 and Z1}
22934@tab @code{Support for target-side breakpoint condition evaluation}
f7e6eed5 22935
73b8c1fd
PA
22936@item @code{multiprocess-extensions}
22937@tab @code{multiprocess extensions}
22938@tab Debug multiple processes and remote process PID awareness
22939
f7e6eed5
PA
22940@item @code{swbreak-feature}
22941@tab @code{swbreak stop reason}
22942@tab @code{break}
22943
22944@item @code{hwbreak-feature}
22945@tab @code{hwbreak stop reason}
22946@tab @code{hbreak}
22947
0d71eef5
DB
22948@item @code{fork-event-feature}
22949@tab @code{fork stop reason}
22950@tab @code{fork}
22951
22952@item @code{vfork-event-feature}
22953@tab @code{vfork stop reason}
22954@tab @code{vfork}
22955
b459a59b
DB
22956@item @code{exec-event-feature}
22957@tab @code{exec stop reason}
22958@tab @code{exec}
22959
65706a29
PA
22960@item @code{thread-events}
22961@tab @code{QThreadEvents}
22962@tab Tracking thread lifetime.
22963
f2faf941
PA
22964@item @code{no-resumed-stop-reply}
22965@tab @code{no resumed thread left stop reply}
22966@tab Tracking thread lifetime.
22967
427c3a89
DJ
22968@end multitable
22969
79a6e687
BW
22970@node Remote Stub
22971@section Implementing a Remote Stub
7a292a7a 22972
8e04817f
AC
22973@cindex debugging stub, example
22974@cindex remote stub, example
22975@cindex stub example, remote debugging
22976The stub files provided with @value{GDBN} implement the target side of the
22977communication protocol, and the @value{GDBN} side is implemented in the
22978@value{GDBN} source file @file{remote.c}. Normally, you can simply allow
22979these subroutines to communicate, and ignore the details. (If you're
22980implementing your own stub file, you can still ignore the details: start
22981with one of the existing stub files. @file{sparc-stub.c} is the best
22982organized, and therefore the easiest to read.)
22983
104c1213
JM
22984@cindex remote serial debugging, overview
22985To debug a program running on another machine (the debugging
22986@dfn{target} machine), you must first arrange for all the usual
22987prerequisites for the program to run by itself. For example, for a C
22988program, you need:
c906108c 22989
104c1213
JM
22990@enumerate
22991@item
22992A startup routine to set up the C runtime environment; these usually
22993have a name like @file{crt0}. The startup routine may be supplied by
22994your hardware supplier, or you may have to write your own.
96baa820 22995
5d161b24 22996@item
d4f3574e 22997A C subroutine library to support your program's
104c1213 22998subroutine calls, notably managing input and output.
96baa820 22999
104c1213
JM
23000@item
23001A way of getting your program to the other machine---for example, a
23002download program. These are often supplied by the hardware
23003manufacturer, but you may have to write your own from hardware
23004documentation.
23005@end enumerate
96baa820 23006
104c1213
JM
23007The next step is to arrange for your program to use a serial port to
23008communicate with the machine where @value{GDBN} is running (the @dfn{host}
23009machine). In general terms, the scheme looks like this:
96baa820 23010
104c1213
JM
23011@table @emph
23012@item On the host,
23013@value{GDBN} already understands how to use this protocol; when everything
23014else is set up, you can simply use the @samp{target remote} command
23015(@pxref{Targets,,Specifying a Debugging Target}).
23016
23017@item On the target,
23018you must link with your program a few special-purpose subroutines that
23019implement the @value{GDBN} remote serial protocol. The file containing these
23020subroutines is called a @dfn{debugging stub}.
23021
23022On certain remote targets, you can use an auxiliary program
23023@code{gdbserver} instead of linking a stub into your program.
79a6e687 23024@xref{Server,,Using the @code{gdbserver} Program}, for details.
104c1213 23025@end table
96baa820 23026
104c1213
JM
23027The debugging stub is specific to the architecture of the remote
23028machine; for example, use @file{sparc-stub.c} to debug programs on
23029@sc{sparc} boards.
96baa820 23030
104c1213
JM
23031@cindex remote serial stub list
23032These working remote stubs are distributed with @value{GDBN}:
96baa820 23033
104c1213
JM
23034@table @code
23035
23036@item i386-stub.c
41afff9a 23037@cindex @file{i386-stub.c}
104c1213
JM
23038@cindex Intel
23039@cindex i386
23040For Intel 386 and compatible architectures.
23041
23042@item m68k-stub.c
41afff9a 23043@cindex @file{m68k-stub.c}
104c1213
JM
23044@cindex Motorola 680x0
23045@cindex m680x0
23046For Motorola 680x0 architectures.
23047
23048@item sh-stub.c
41afff9a 23049@cindex @file{sh-stub.c}
172c2a43 23050@cindex Renesas
104c1213 23051@cindex SH
172c2a43 23052For Renesas SH architectures.
104c1213
JM
23053
23054@item sparc-stub.c
41afff9a 23055@cindex @file{sparc-stub.c}
104c1213
JM
23056@cindex Sparc
23057For @sc{sparc} architectures.
23058
23059@item sparcl-stub.c
41afff9a 23060@cindex @file{sparcl-stub.c}
104c1213
JM
23061@cindex Fujitsu
23062@cindex SparcLite
23063For Fujitsu @sc{sparclite} architectures.
23064
23065@end table
23066
23067The @file{README} file in the @value{GDBN} distribution may list other
23068recently added stubs.
23069
23070@menu
23071* Stub Contents:: What the stub can do for you
23072* Bootstrapping:: What you must do for the stub
23073* Debug Session:: Putting it all together
104c1213
JM
23074@end menu
23075
6d2ebf8b 23076@node Stub Contents
79a6e687 23077@subsection What the Stub Can Do for You
104c1213
JM
23078
23079@cindex remote serial stub
23080The debugging stub for your architecture supplies these three
23081subroutines:
23082
23083@table @code
23084@item set_debug_traps
4644b6e3 23085@findex set_debug_traps
104c1213
JM
23086@cindex remote serial stub, initialization
23087This routine arranges for @code{handle_exception} to run when your
2fb860fc
PA
23088program stops. You must call this subroutine explicitly in your
23089program's startup code.
104c1213
JM
23090
23091@item handle_exception
4644b6e3 23092@findex handle_exception
104c1213
JM
23093@cindex remote serial stub, main routine
23094This is the central workhorse, but your program never calls it
23095explicitly---the setup code arranges for @code{handle_exception} to
23096run when a trap is triggered.
23097
23098@code{handle_exception} takes control when your program stops during
23099execution (for example, on a breakpoint), and mediates communications
23100with @value{GDBN} on the host machine. This is where the communications
23101protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
d4f3574e 23102representative on the target machine. It begins by sending summary
104c1213
JM
23103information on the state of your program, then continues to execute,
23104retrieving and transmitting any information @value{GDBN} needs, until you
23105execute a @value{GDBN} command that makes your program resume; at that point,
23106@code{handle_exception} returns control to your own code on the target
5d161b24 23107machine.
104c1213
JM
23108
23109@item breakpoint
23110@cindex @code{breakpoint} subroutine, remote
23111Use this auxiliary subroutine to make your program contain a
23112breakpoint. Depending on the particular situation, this may be the only
23113way for @value{GDBN} to get control. For instance, if your target
23114machine has some sort of interrupt button, you won't need to call this;
23115pressing the interrupt button transfers control to
23116@code{handle_exception}---in effect, to @value{GDBN}. On some machines,
23117simply receiving characters on the serial port may also trigger a trap;
23118again, in that situation, you don't need to call @code{breakpoint} from
23119your own program---simply running @samp{target remote} from the host
5d161b24 23120@value{GDBN} session gets control.
104c1213
JM
23121
23122Call @code{breakpoint} if none of these is true, or if you simply want
23123to make certain your program stops at a predetermined point for the
23124start of your debugging session.
23125@end table
23126
6d2ebf8b 23127@node Bootstrapping
79a6e687 23128@subsection What You Must Do for the Stub
104c1213
JM
23129
23130@cindex remote stub, support routines
23131The debugging stubs that come with @value{GDBN} are set up for a particular
23132chip architecture, but they have no information about the rest of your
23133debugging target machine.
23134
23135First of all you need to tell the stub how to communicate with the
23136serial port.
23137
23138@table @code
23139@item int getDebugChar()
4644b6e3 23140@findex getDebugChar
104c1213
JM
23141Write this subroutine to read a single character from the serial port.
23142It may be identical to @code{getchar} for your target system; a
23143different name is used to allow you to distinguish the two if you wish.
23144
23145@item void putDebugChar(int)
4644b6e3 23146@findex putDebugChar
104c1213 23147Write this subroutine to write a single character to the serial port.
5d161b24 23148It may be identical to @code{putchar} for your target system; a
104c1213
JM
23149different name is used to allow you to distinguish the two if you wish.
23150@end table
23151
23152@cindex control C, and remote debugging
23153@cindex interrupting remote targets
23154If you want @value{GDBN} to be able to stop your program while it is
23155running, you need to use an interrupt-driven serial driver, and arrange
23156for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
23157character). That is the character which @value{GDBN} uses to tell the
23158remote system to stop.
23159
23160Getting the debugging target to return the proper status to @value{GDBN}
23161probably requires changes to the standard stub; one quick and dirty way
23162is to just execute a breakpoint instruction (the ``dirty'' part is that
23163@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
23164
23165Other routines you need to supply are:
23166
23167@table @code
23168@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
4644b6e3 23169@findex exceptionHandler
104c1213
JM
23170Write this function to install @var{exception_address} in the exception
23171handling tables. You need to do this because the stub does not have any
23172way of knowing what the exception handling tables on your target system
23173are like (for example, the processor's table might be in @sc{rom},
23174containing entries which point to a table in @sc{ram}).
697aa1b7 23175The @var{exception_number} specifies the exception which should be changed;
104c1213
JM
23176its meaning is architecture-dependent (for example, different numbers
23177might represent divide by zero, misaligned access, etc). When this
23178exception occurs, control should be transferred directly to
23179@var{exception_address}, and the processor state (stack, registers,
23180and so on) should be just as it is when a processor exception occurs. So if
23181you want to use a jump instruction to reach @var{exception_address}, it
23182should be a simple jump, not a jump to subroutine.
23183
23184For the 386, @var{exception_address} should be installed as an interrupt
23185gate so that interrupts are masked while the handler runs. The gate
23186should be at privilege level 0 (the most privileged level). The
23187@sc{sparc} and 68k stubs are able to mask interrupts themselves without
23188help from @code{exceptionHandler}.
23189
23190@item void flush_i_cache()
4644b6e3 23191@findex flush_i_cache
d4f3574e 23192On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
104c1213
JM
23193instruction cache, if any, on your target machine. If there is no
23194instruction cache, this subroutine may be a no-op.
23195
23196On target machines that have instruction caches, @value{GDBN} requires this
23197function to make certain that the state of your program is stable.
23198@end table
23199
23200@noindent
23201You must also make sure this library routine is available:
23202
23203@table @code
23204@item void *memset(void *, int, int)
4644b6e3 23205@findex memset
104c1213
JM
23206This is the standard library function @code{memset} that sets an area of
23207memory to a known value. If you have one of the free versions of
23208@code{libc.a}, @code{memset} can be found there; otherwise, you must
23209either obtain it from your hardware manufacturer, or write your own.
23210@end table
23211
23212If you do not use the GNU C compiler, you may need other standard
23213library subroutines as well; this varies from one stub to another,
23214but in general the stubs are likely to use any of the common library
e22ea452 23215subroutines which @code{@value{NGCC}} generates as inline code.
104c1213
JM
23216
23217
6d2ebf8b 23218@node Debug Session
79a6e687 23219@subsection Putting it All Together
104c1213
JM
23220
23221@cindex remote serial debugging summary
23222In summary, when your program is ready to debug, you must follow these
23223steps.
23224
23225@enumerate
23226@item
6d2ebf8b 23227Make sure you have defined the supporting low-level routines
79a6e687 23228(@pxref{Bootstrapping,,What You Must Do for the Stub}):
104c1213
JM
23229@display
23230@code{getDebugChar}, @code{putDebugChar},
23231@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
23232@end display
23233
23234@item
2fb860fc
PA
23235Insert these lines in your program's startup code, before the main
23236procedure is called:
104c1213 23237
474c8240 23238@smallexample
104c1213
JM
23239set_debug_traps();
23240breakpoint();
474c8240 23241@end smallexample
104c1213 23242
2fb860fc
PA
23243On some machines, when a breakpoint trap is raised, the hardware
23244automatically makes the PC point to the instruction after the
23245breakpoint. If your machine doesn't do that, you may need to adjust
23246@code{handle_exception} to arrange for it to return to the instruction
23247after the breakpoint on this first invocation, so that your program
23248doesn't keep hitting the initial breakpoint instead of making
23249progress.
23250
104c1213
JM
23251@item
23252For the 680x0 stub only, you need to provide a variable called
23253@code{exceptionHook}. Normally you just use:
23254
474c8240 23255@smallexample
104c1213 23256void (*exceptionHook)() = 0;
474c8240 23257@end smallexample
104c1213 23258
d4f3574e 23259@noindent
104c1213 23260but if before calling @code{set_debug_traps}, you set it to point to a
598ca718 23261function in your program, that function is called when
104c1213
JM
23262@code{@value{GDBN}} continues after stopping on a trap (for example, bus
23263error). The function indicated by @code{exceptionHook} is called with
23264one parameter: an @code{int} which is the exception number.
23265
23266@item
23267Compile and link together: your program, the @value{GDBN} debugging stub for
23268your target architecture, and the supporting subroutines.
23269
23270@item
23271Make sure you have a serial connection between your target machine and
23272the @value{GDBN} host, and identify the serial port on the host.
23273
23274@item
23275@c The "remote" target now provides a `load' command, so we should
23276@c document that. FIXME.
23277Download your program to your target machine (or get it there by
23278whatever means the manufacturer provides), and start it.
23279
23280@item
07f31aa6 23281Start @value{GDBN} on the host, and connect to the target
79a6e687 23282(@pxref{Connecting,,Connecting to a Remote Target}).
9db8d71f 23283
104c1213
JM
23284@end enumerate
23285
8e04817f
AC
23286@node Configurations
23287@chapter Configuration-Specific Information
104c1213 23288
8e04817f
AC
23289While nearly all @value{GDBN} commands are available for all native and
23290cross versions of the debugger, there are some exceptions. This chapter
23291describes things that are only available in certain configurations.
104c1213 23292
8e04817f
AC
23293There are three major categories of configurations: native
23294configurations, where the host and target are the same, embedded
23295operating system configurations, which are usually the same for several
23296different processor architectures, and bare embedded processors, which
23297are quite different from each other.
104c1213 23298
8e04817f
AC
23299@menu
23300* Native::
23301* Embedded OS::
23302* Embedded Processors::
23303* Architectures::
23304@end menu
104c1213 23305
8e04817f
AC
23306@node Native
23307@section Native
104c1213 23308
8e04817f
AC
23309This section describes details specific to particular native
23310configurations.
6cf7e474 23311
8e04817f 23312@menu
7561d450 23313* BSD libkvm Interface:: Debugging BSD kernel memory images
2d97a5d9 23314* Process Information:: Process information
8e04817f 23315* DJGPP Native:: Features specific to the DJGPP port
78c47bea 23316* Cygwin Native:: Features specific to the Cygwin port
14d6dd68 23317* Hurd Native:: Features specific to @sc{gnu} Hurd
a80b95ba 23318* Darwin:: Features specific to Darwin
e9076973 23319* FreeBSD:: Features specific to FreeBSD
8e04817f 23320@end menu
6cf7e474 23321
7561d450
MK
23322@node BSD libkvm Interface
23323@subsection BSD libkvm Interface
23324
23325@cindex libkvm
23326@cindex kernel memory image
23327@cindex kernel crash dump
23328
23329BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
23330interface that provides a uniform interface for accessing kernel virtual
23331memory images, including live systems and crash dumps. @value{GDBN}
23332uses this interface to allow you to debug live kernels and kernel crash
23333dumps on many native BSD configurations. This is implemented as a
23334special @code{kvm} debugging target. For debugging a live system, load
23335the currently running kernel into @value{GDBN} and connect to the
23336@code{kvm} target:
23337
23338@smallexample
23339(@value{GDBP}) @b{target kvm}
23340@end smallexample
23341
23342For debugging crash dumps, provide the file name of the crash dump as an
23343argument:
23344
23345@smallexample
23346(@value{GDBP}) @b{target kvm /var/crash/bsd.0}
23347@end smallexample
23348
23349Once connected to the @code{kvm} target, the following commands are
23350available:
23351
23352@table @code
23353@kindex kvm
23354@item kvm pcb
721c2651 23355Set current context from the @dfn{Process Control Block} (PCB) address.
7561d450
MK
23356
23357@item kvm proc
23358Set current context from proc address. This command isn't available on
23359modern FreeBSD systems.
23360@end table
23361
2d97a5d9
JB
23362@node Process Information
23363@subsection Process Information
60bf7e09
EZ
23364@cindex /proc
23365@cindex examine process image
23366@cindex process info via @file{/proc}
104c1213 23367
2d97a5d9
JB
23368Some operating systems provide interfaces to fetch additional
23369information about running processes beyond memory and per-thread
23370register state. If @value{GDBN} is configured for an operating system
23371with a supported interface, the command @code{info proc} is available
23372to report information about the process running your program, or about
23373any process running on your system.
451b7c33 23374
2d97a5d9
JB
23375One supported interface is a facility called @samp{/proc} that can be
23376used to examine the image of a running process using file-system
23377subroutines. This facility is supported on @sc{gnu}/Linux and Solaris
23378systems.
451b7c33 23379
2d97a5d9
JB
23380On FreeBSD systems, system control nodes are used to query process
23381information.
23382
23383In addition, some systems may provide additional process information
23384in core files. Note that a core file may include a subset of the
23385information available from a live process. Process information is
6b92c0d3 23386currently available from cores created on @sc{gnu}/Linux and FreeBSD
2d97a5d9 23387systems.
104c1213 23388
8e04817f
AC
23389@table @code
23390@kindex info proc
60bf7e09 23391@cindex process ID
8e04817f 23392@item info proc
60bf7e09 23393@itemx info proc @var{process-id}
73f1bd76 23394Summarize available information about a process. If a
60bf7e09
EZ
23395process ID is specified by @var{process-id}, display information about
23396that process; otherwise display information about the program being
23397debugged. The summary includes the debugged process ID, the command
23398line used to invoke it, its current working directory, and its
23399executable file's absolute file name.
23400
23401On some systems, @var{process-id} can be of the form
23402@samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
23403within a process. If the optional @var{pid} part is missing, it means
23404a thread from the process being debugged (the leading @samp{/} still
23405needs to be present, or else @value{GDBN} will interpret the number as
23406a process ID rather than a thread ID).
6cf7e474 23407
0c631110
TT
23408@item info proc cmdline
23409@cindex info proc cmdline
23410Show the original command line of the process. This command is
2d97a5d9 23411supported on @sc{gnu}/Linux and FreeBSD.
0c631110
TT
23412
23413@item info proc cwd
23414@cindex info proc cwd
23415Show the current working directory of the process. This command is
2d97a5d9 23416supported on @sc{gnu}/Linux and FreeBSD.
0c631110
TT
23417
23418@item info proc exe
23419@cindex info proc exe
2d97a5d9
JB
23420Show the name of executable of the process. This command is supported
23421on @sc{gnu}/Linux and FreeBSD.
0c631110 23422
8b113111
JB
23423@item info proc files
23424@cindex info proc files
23425Show the file descriptors open by the process. For each open file
23426descriptor, @value{GDBN} shows its number, type (file, directory,
23427character device, socket), file pointer offset, and the name of the
23428resource open on the descriptor. The resource name can be a file name
23429(for files, directories, and devices) or a protocol followed by socket
23430address (for network connections). This command is supported on
23431FreeBSD.
23432
23433This example shows the open file descriptors for a process using a
23434tty for standard input and output as well as two network sockets:
23435
23436@smallexample
23437(gdb) info proc files 22136
23438process 22136
23439Open files:
23440
23441 FD Type Offset Flags Name
23442 text file - r-------- /usr/bin/ssh
23443 ctty chr - rw------- /dev/pts/20
23444 cwd dir - r-------- /usr/home/john
23445 root dir - r-------- /
23446 0 chr 0x32933a4 rw------- /dev/pts/20
23447 1 chr 0x32933a4 rw------- /dev/pts/20
23448 2 chr 0x32933a4 rw------- /dev/pts/20
23449 3 socket 0x0 rw----n-- tcp4 10.0.1.2:53014 -> 10.0.1.10:22
23450 4 socket 0x0 rw------- unix stream:/tmp/ssh-FIt89oAzOn5f/agent.2456
23451@end smallexample
23452
8e04817f 23453@item info proc mappings
60bf7e09 23454@cindex memory address space mappings
73f1bd76 23455Report the memory address space ranges accessible in a process. On
2d97a5d9
JB
23456Solaris and FreeBSD systems, each memory range includes information on
23457whether the process has read, write, or execute access rights to each
23458range. On @sc{gnu}/Linux and FreeBSD systems, each memory range
23459includes the object file which is mapped to that range.
60bf7e09
EZ
23460
23461@item info proc stat
23462@itemx info proc status
23463@cindex process detailed status information
2d97a5d9
JB
23464Show additional process-related information, including the user ID and
23465group ID; virtual memory usage; the signals that are pending, blocked,
23466and ignored; its TTY; its consumption of system and user time; its
23467stack size; its @samp{nice} value; etc. These commands are supported
23468on @sc{gnu}/Linux and FreeBSD.
23469
23470For @sc{gnu}/Linux systems, see the @samp{proc} man page for more
23471information (type @kbd{man 5 proc} from your shell prompt).
23472
23473For FreeBSD systems, @code{info proc stat} is an alias for @code{info
23474proc status}.
60bf7e09
EZ
23475
23476@item info proc all
23477Show all the information about the process described under all of the
23478above @code{info proc} subcommands.
23479
8e04817f
AC
23480@ignore
23481@comment These sub-options of 'info proc' were not included when
23482@comment procfs.c was re-written. Keep their descriptions around
23483@comment against the day when someone finds the time to put them back in.
23484@kindex info proc times
23485@item info proc times
23486Starting time, user CPU time, and system CPU time for your program and
23487its children.
6cf7e474 23488
8e04817f
AC
23489@kindex info proc id
23490@item info proc id
23491Report on the process IDs related to your program: its own process ID,
23492the ID of its parent, the process group ID, and the session ID.
8e04817f 23493@end ignore
721c2651
EZ
23494
23495@item set procfs-trace
23496@kindex set procfs-trace
23497@cindex @code{procfs} API calls
23498This command enables and disables tracing of @code{procfs} API calls.
23499
23500@item show procfs-trace
23501@kindex show procfs-trace
23502Show the current state of @code{procfs} API call tracing.
23503
23504@item set procfs-file @var{file}
23505@kindex set procfs-file
23506Tell @value{GDBN} to write @code{procfs} API trace to the named
23507@var{file}. @value{GDBN} appends the trace info to the previous
23508contents of the file. The default is to display the trace on the
23509standard output.
23510
23511@item show procfs-file
23512@kindex show procfs-file
23513Show the file to which @code{procfs} API trace is written.
23514
23515@item proc-trace-entry
23516@itemx proc-trace-exit
23517@itemx proc-untrace-entry
23518@itemx proc-untrace-exit
23519@kindex proc-trace-entry
23520@kindex proc-trace-exit
23521@kindex proc-untrace-entry
23522@kindex proc-untrace-exit
23523These commands enable and disable tracing of entries into and exits
23524from the @code{syscall} interface.
23525
23526@item info pidlist
23527@kindex info pidlist
23528@cindex process list, QNX Neutrino
23529For QNX Neutrino only, this command displays the list of all the
23530processes and all the threads within each process.
23531
23532@item info meminfo
23533@kindex info meminfo
23534@cindex mapinfo list, QNX Neutrino
23535For QNX Neutrino only, this command displays the list of all mapinfos.
8e04817f 23536@end table
104c1213 23537
8e04817f
AC
23538@node DJGPP Native
23539@subsection Features for Debugging @sc{djgpp} Programs
23540@cindex @sc{djgpp} debugging
23541@cindex native @sc{djgpp} debugging
23542@cindex MS-DOS-specific commands
104c1213 23543
514c4d71
EZ
23544@cindex DPMI
23545@sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
8e04817f
AC
23546MS-Windows. @sc{djgpp} programs are 32-bit protected-mode programs
23547that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
23548top of real-mode DOS systems and their emulations.
104c1213 23549
8e04817f
AC
23550@value{GDBN} supports native debugging of @sc{djgpp} programs, and
23551defines a few commands specific to the @sc{djgpp} port. This
23552subsection describes those commands.
104c1213 23553
8e04817f
AC
23554@table @code
23555@kindex info dos
23556@item info dos
23557This is a prefix of @sc{djgpp}-specific commands which print
23558information about the target system and important OS structures.
f1251bdd 23559
8e04817f
AC
23560@kindex sysinfo
23561@cindex MS-DOS system info
23562@cindex free memory information (MS-DOS)
23563@item info dos sysinfo
23564This command displays assorted information about the underlying
23565platform: the CPU type and features, the OS version and flavor, the
23566DPMI version, and the available conventional and DPMI memory.
104c1213 23567
8e04817f
AC
23568@cindex GDT
23569@cindex LDT
23570@cindex IDT
23571@cindex segment descriptor tables
23572@cindex descriptor tables display
23573@item info dos gdt
23574@itemx info dos ldt
23575@itemx info dos idt
23576These 3 commands display entries from, respectively, Global, Local,
23577and Interrupt Descriptor Tables (GDT, LDT, and IDT). The descriptor
23578tables are data structures which store a descriptor for each segment
23579that is currently in use. The segment's selector is an index into a
23580descriptor table; the table entry for that index holds the
23581descriptor's base address and limit, and its attributes and access
23582rights.
104c1213 23583
8e04817f
AC
23584A typical @sc{djgpp} program uses 3 segments: a code segment, a data
23585segment (used for both data and the stack), and a DOS segment (which
23586allows access to DOS/BIOS data structures and absolute addresses in
23587conventional memory). However, the DPMI host will usually define
23588additional segments in order to support the DPMI environment.
d4f3574e 23589
8e04817f
AC
23590@cindex garbled pointers
23591These commands allow to display entries from the descriptor tables.
23592Without an argument, all entries from the specified table are
23593displayed. An argument, which should be an integer expression, means
23594display a single entry whose index is given by the argument. For
23595example, here's a convenient way to display information about the
23596debugged program's data segment:
104c1213 23597
8e04817f
AC
23598@smallexample
23599@exdent @code{(@value{GDBP}) info dos ldt $ds}
23600@exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
23601@end smallexample
104c1213 23602
8e04817f
AC
23603@noindent
23604This comes in handy when you want to see whether a pointer is outside
23605the data segment's limit (i.e.@: @dfn{garbled}).
104c1213 23606
8e04817f
AC
23607@cindex page tables display (MS-DOS)
23608@item info dos pde
23609@itemx info dos pte
23610These two commands display entries from, respectively, the Page
23611Directory and the Page Tables. Page Directories and Page Tables are
23612data structures which control how virtual memory addresses are mapped
23613into physical addresses. A Page Table includes an entry for every
23614page of memory that is mapped into the program's address space; there
23615may be several Page Tables, each one holding up to 4096 entries. A
23616Page Directory has up to 4096 entries, one each for every Page Table
23617that is currently in use.
104c1213 23618
8e04817f
AC
23619Without an argument, @kbd{info dos pde} displays the entire Page
23620Directory, and @kbd{info dos pte} displays all the entries in all of
23621the Page Tables. An argument, an integer expression, given to the
23622@kbd{info dos pde} command means display only that entry from the Page
23623Directory table. An argument given to the @kbd{info dos pte} command
23624means display entries from a single Page Table, the one pointed to by
23625the specified entry in the Page Directory.
104c1213 23626
8e04817f
AC
23627@cindex direct memory access (DMA) on MS-DOS
23628These commands are useful when your program uses @dfn{DMA} (Direct
23629Memory Access), which needs physical addresses to program the DMA
23630controller.
104c1213 23631
8e04817f 23632These commands are supported only with some DPMI servers.
104c1213 23633
8e04817f
AC
23634@cindex physical address from linear address
23635@item info dos address-pte @var{addr}
23636This command displays the Page Table entry for a specified linear
514c4d71
EZ
23637address. The argument @var{addr} is a linear address which should
23638already have the appropriate segment's base address added to it,
23639because this command accepts addresses which may belong to @emph{any}
23640segment. For example, here's how to display the Page Table entry for
23641the page where a variable @code{i} is stored:
104c1213 23642
b383017d 23643@smallexample
8e04817f
AC
23644@exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
23645@exdent @code{Page Table entry for address 0x11a00d30:}
b383017d 23646@exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
8e04817f 23647@end smallexample
104c1213 23648
8e04817f
AC
23649@noindent
23650This says that @code{i} is stored at offset @code{0xd30} from the page
514c4d71 23651whose physical base address is @code{0x02698000}, and shows all the
8e04817f 23652attributes of that page.
104c1213 23653
8e04817f
AC
23654Note that you must cast the addresses of variables to a @code{char *},
23655since otherwise the value of @code{__djgpp_base_address}, the base
23656address of all variables and functions in a @sc{djgpp} program, will
23657be added using the rules of C pointer arithmetics: if @code{i} is
23658declared an @code{int}, @value{GDBN} will add 4 times the value of
23659@code{__djgpp_base_address} to the address of @code{i}.
104c1213 23660
8e04817f
AC
23661Here's another example, it displays the Page Table entry for the
23662transfer buffer:
104c1213 23663
8e04817f
AC
23664@smallexample
23665@exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
23666@exdent @code{Page Table entry for address 0x29110:}
23667@exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
23668@end smallexample
104c1213 23669
8e04817f
AC
23670@noindent
23671(The @code{+ 3} offset is because the transfer buffer's address is the
514c4d71
EZ
236723rd member of the @code{_go32_info_block} structure.) The output
23673clearly shows that this DPMI server maps the addresses in conventional
23674memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
23675linear (@code{0x29110}) addresses are identical.
104c1213 23676
8e04817f
AC
23677This command is supported only with some DPMI servers.
23678@end table
104c1213 23679
c45da7e6 23680@cindex DOS serial data link, remote debugging
a8f24a35
EZ
23681In addition to native debugging, the DJGPP port supports remote
23682debugging via a serial data link. The following commands are specific
23683to remote serial debugging in the DJGPP port of @value{GDBN}.
23684
23685@table @code
23686@kindex set com1base
23687@kindex set com1irq
23688@kindex set com2base
23689@kindex set com2irq
23690@kindex set com3base
23691@kindex set com3irq
23692@kindex set com4base
23693@kindex set com4irq
23694@item set com1base @var{addr}
23695This command sets the base I/O port address of the @file{COM1} serial
23696port.
23697
23698@item set com1irq @var{irq}
23699This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
23700for the @file{COM1} serial port.
23701
23702There are similar commands @samp{set com2base}, @samp{set com3irq},
23703etc.@: for setting the port address and the @code{IRQ} lines for the
23704other 3 COM ports.
23705
23706@kindex show com1base
23707@kindex show com1irq
23708@kindex show com2base
23709@kindex show com2irq
23710@kindex show com3base
23711@kindex show com3irq
23712@kindex show com4base
23713@kindex show com4irq
23714The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
23715display the current settings of the base address and the @code{IRQ}
23716lines used by the COM ports.
c45da7e6
EZ
23717
23718@item info serial
23719@kindex info serial
23720@cindex DOS serial port status
23721This command prints the status of the 4 DOS serial ports. For each
23722port, it prints whether it's active or not, its I/O base address and
23723IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
23724counts of various errors encountered so far.
a8f24a35
EZ
23725@end table
23726
23727
78c47bea 23728@node Cygwin Native
79a6e687 23729@subsection Features for Debugging MS Windows PE Executables
78c47bea
PM
23730@cindex MS Windows debugging
23731@cindex native Cygwin debugging
23732@cindex Cygwin-specific commands
23733
be448670 23734@value{GDBN} supports native debugging of MS Windows programs, including
cbb8f428
EZ
23735DLLs with and without symbolic debugging information.
23736
23737@cindex Ctrl-BREAK, MS-Windows
23738@cindex interrupt debuggee on MS-Windows
23739MS-Windows programs that call @code{SetConsoleMode} to switch off the
23740special meaning of the @samp{Ctrl-C} keystroke cannot be interrupted
23741by typing @kbd{C-c}. For this reason, @value{GDBN} on MS-Windows
23742supports @kbd{C-@key{BREAK}} as an alternative interrupt key
23743sequence, which can be used to interrupt the debuggee even if it
23744ignores @kbd{C-c}.
23745
23746There are various additional Cygwin-specific commands, described in
23747this section. Working with DLLs that have no debugging symbols is
23748described in @ref{Non-debug DLL Symbols}.
78c47bea
PM
23749
23750@table @code
23751@kindex info w32
23752@item info w32
db2e3e2e 23753This is a prefix of MS Windows-specific commands which print
78c47bea
PM
23754information about the target system and important OS structures.
23755
23756@item info w32 selector
23757This command displays information returned by
23758the Win32 API @code{GetThreadSelectorEntry} function.
23759It takes an optional argument that is evaluated to
23760a long value to give the information about this given selector.
23761Without argument, this command displays information
d3e8051b 23762about the six segment registers.
78c47bea 23763
711e434b
PM
23764@item info w32 thread-information-block
23765This command displays thread specific information stored in the
23766Thread Information Block (readable on the X86 CPU family using @code{$fs}
23767selector for 32-bit programs and @code{$gs} for 64-bit programs).
23768
463888ab
РИ
23769@kindex signal-event
23770@item signal-event @var{id}
23771This command signals an event with user-provided @var{id}. Used to resume
23772crashing process when attached to it using MS-Windows JIT debugging (AeDebug).
23773
23774To use it, create or edit the following keys in
23775@code{HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug} and/or
23776@code{HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\AeDebug}
23777(for x86_64 versions):
23778
23779@itemize @minus
23780@item
23781@code{Debugger} (REG_SZ) --- a command to launch the debugger.
23782Suggested command is: @code{@var{fully-qualified-path-to-gdb.exe} -ex
23783"attach %ld" -ex "signal-event %ld" -ex "continue"}.
23784
23785The first @code{%ld} will be replaced by the process ID of the
23786crashing process, the second @code{%ld} will be replaced by the ID of
23787the event that blocks the crashing process, waiting for @value{GDBN}
23788to attach.
23789
23790@item
23791@code{Auto} (REG_SZ) --- either @code{1} or @code{0}. @code{1} will
23792make the system run debugger specified by the Debugger key
23793automatically, @code{0} will cause a dialog box with ``OK'' and
23794``Cancel'' buttons to appear, which allows the user to either
23795terminate the crashing process (OK) or debug it (Cancel).
23796@end itemize
23797
be90c084 23798@kindex set cygwin-exceptions
e16b02ee
EZ
23799@cindex debugging the Cygwin DLL
23800@cindex Cygwin DLL, debugging
be90c084 23801@item set cygwin-exceptions @var{mode}
e16b02ee
EZ
23802If @var{mode} is @code{on}, @value{GDBN} will break on exceptions that
23803happen inside the Cygwin DLL. If @var{mode} is @code{off},
23804@value{GDBN} will delay recognition of exceptions, and may ignore some
23805exceptions which seem to be caused by internal Cygwin DLL
23806``bookkeeping''. This option is meant primarily for debugging the
23807Cygwin DLL itself; the default value is @code{off} to avoid annoying
23808@value{GDBN} users with false @code{SIGSEGV} signals.
be90c084
CF
23809
23810@kindex show cygwin-exceptions
23811@item show cygwin-exceptions
e16b02ee
EZ
23812Displays whether @value{GDBN} will break on exceptions that happen
23813inside the Cygwin DLL itself.
be90c084 23814
b383017d 23815@kindex set new-console
78c47bea 23816@item set new-console @var{mode}
b383017d 23817If @var{mode} is @code{on} the debuggee will
78c47bea 23818be started in a new console on next start.
e03e5e7b 23819If @var{mode} is @code{off}, the debuggee will
78c47bea
PM
23820be started in the same console as the debugger.
23821
23822@kindex show new-console
23823@item show new-console
23824Displays whether a new console is used
23825when the debuggee is started.
23826
23827@kindex set new-group
23828@item set new-group @var{mode}
23829This boolean value controls whether the debuggee should
23830start a new group or stay in the same group as the debugger.
23831This affects the way the Windows OS handles
c8aa23ab 23832@samp{Ctrl-C}.
78c47bea
PM
23833
23834@kindex show new-group
23835@item show new-group
23836Displays current value of new-group boolean.
23837
23838@kindex set debugevents
23839@item set debugevents
219eec71
EZ
23840This boolean value adds debug output concerning kernel events related
23841to the debuggee seen by the debugger. This includes events that
23842signal thread and process creation and exit, DLL loading and
23843unloading, console interrupts, and debugging messages produced by the
23844Windows @code{OutputDebugString} API call.
78c47bea
PM
23845
23846@kindex set debugexec
23847@item set debugexec
b383017d 23848This boolean value adds debug output concerning execute events
219eec71 23849(such as resume thread) seen by the debugger.
78c47bea
PM
23850
23851@kindex set debugexceptions
23852@item set debugexceptions
219eec71
EZ
23853This boolean value adds debug output concerning exceptions in the
23854debuggee seen by the debugger.
78c47bea
PM
23855
23856@kindex set debugmemory
23857@item set debugmemory
219eec71
EZ
23858This boolean value adds debug output concerning debuggee memory reads
23859and writes by the debugger.
78c47bea
PM
23860
23861@kindex set shell
23862@item set shell
23863This boolean values specifies whether the debuggee is called
23864via a shell or directly (default value is on).
23865
23866@kindex show shell
23867@item show shell
23868Displays if the debuggee will be started with a shell.
23869
23870@end table
23871
be448670 23872@menu
79a6e687 23873* Non-debug DLL Symbols:: Support for DLLs without debugging symbols
be448670
CF
23874@end menu
23875
79a6e687
BW
23876@node Non-debug DLL Symbols
23877@subsubsection Support for DLLs without Debugging Symbols
be448670
CF
23878@cindex DLLs with no debugging symbols
23879@cindex Minimal symbols and DLLs
23880
23881Very often on windows, some of the DLLs that your program relies on do
23882not include symbolic debugging information (for example,
db2e3e2e 23883@file{kernel32.dll}). When @value{GDBN} doesn't recognize any debugging
be448670 23884symbols in a DLL, it relies on the minimal amount of symbolic
db2e3e2e 23885information contained in the DLL's export table. This section
be448670
CF
23886describes working with such symbols, known internally to @value{GDBN} as
23887``minimal symbols''.
23888
23889Note that before the debugged program has started execution, no DLLs
db2e3e2e 23890will have been loaded. The easiest way around this problem is simply to
be448670 23891start the program --- either by setting a breakpoint or letting the
95060284 23892program run once to completion.
be448670 23893
79a6e687 23894@subsubsection DLL Name Prefixes
be448670
CF
23895
23896In keeping with the naming conventions used by the Microsoft debugging
23897tools, DLL export symbols are made available with a prefix based on the
23898DLL name, for instance @code{KERNEL32!CreateFileA}. The plain name is
23899also entered into the symbol table, so @code{CreateFileA} is often
99e008fe 23900sufficient. In some cases there will be name clashes within a program
be448670
CF
23901(particularly if the executable itself includes full debugging symbols)
23902necessitating the use of the fully qualified name when referring to the
99e008fe 23903contents of the DLL. Use single-quotes around the name to avoid the
be448670
CF
23904exclamation mark (``!'') being interpreted as a language operator.
23905
23906Note that the internal name of the DLL may be all upper-case, even
99e008fe 23907though the file name of the DLL is lower-case, or vice-versa. Since
be448670
CF
23908symbols within @value{GDBN} are @emph{case-sensitive} this may cause
23909some confusion. If in doubt, try the @code{info functions} and
0869d01b
NR
23910@code{info variables} commands or even @code{maint print msymbols}
23911(@pxref{Symbols}). Here's an example:
be448670
CF
23912
23913@smallexample
f7dc1244 23914(@value{GDBP}) info function CreateFileA
be448670
CF
23915All functions matching regular expression "CreateFileA":
23916
23917Non-debugging symbols:
239180x77e885f4 CreateFileA
239190x77e885f4 KERNEL32!CreateFileA
23920@end smallexample
23921
23922@smallexample
f7dc1244 23923(@value{GDBP}) info function !
be448670
CF
23924All functions matching regular expression "!":
23925
23926Non-debugging symbols:
239270x6100114c cygwin1!__assert
239280x61004034 cygwin1!_dll_crt0@@0
239290x61004240 cygwin1!dll_crt0(per_process *)
23930[etc...]
23931@end smallexample
23932
79a6e687 23933@subsubsection Working with Minimal Symbols
be448670
CF
23934
23935Symbols extracted from a DLL's export table do not contain very much
23936type information. All that @value{GDBN} can do is guess whether a symbol
23937refers to a function or variable depending on the linker section that
23938contains the symbol. Also note that the actual contents of the memory
23939contained in a DLL are not available unless the program is running. This
23940means that you cannot examine the contents of a variable or disassemble
23941a function within a DLL without a running program.
23942
23943Variables are generally treated as pointers and dereferenced
23944automatically. For this reason, it is often necessary to prefix a
23945variable name with the address-of operator (``&'') and provide explicit
23946type information in the command. Here's an example of the type of
23947problem:
23948
23949@smallexample
f7dc1244 23950(@value{GDBP}) print 'cygwin1!__argv'
d69cf9b2 23951'cygwin1!__argv' has unknown type; cast it to its declared type
be448670
CF
23952@end smallexample
23953
23954@smallexample
f7dc1244 23955(@value{GDBP}) x 'cygwin1!__argv'
d69cf9b2 23956'cygwin1!__argv' has unknown type; cast it to its declared type
be448670
CF
23957@end smallexample
23958
23959And two possible solutions:
23960
23961@smallexample
f7dc1244 23962(@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
be448670
CF
23963$2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
23964@end smallexample
23965
23966@smallexample
f7dc1244 23967(@value{GDBP}) x/2x &'cygwin1!__argv'
be448670 239680x610c0aa8 <cygwin1!__argv>: 0x10021608 0x00000000
f7dc1244 23969(@value{GDBP}) x/x 0x10021608
be448670 239700x10021608: 0x0022fd98
f7dc1244 23971(@value{GDBP}) x/s 0x0022fd98
be448670
CF
239720x22fd98: "/cygdrive/c/mydirectory/myprogram"
23973@end smallexample
23974
23975Setting a break point within a DLL is possible even before the program
23976starts execution. However, under these circumstances, @value{GDBN} can't
23977examine the initial instructions of the function in order to skip the
23978function's frame set-up code. You can work around this by using ``*&''
23979to set the breakpoint at a raw memory address:
23980
23981@smallexample
f7dc1244 23982(@value{GDBP}) break *&'python22!PyOS_Readline'
be448670
CF
23983Breakpoint 1 at 0x1e04eff0
23984@end smallexample
23985
23986The author of these extensions is not entirely convinced that setting a
23987break point within a shared DLL like @file{kernel32.dll} is completely
23988safe.
23989
14d6dd68 23990@node Hurd Native
79a6e687 23991@subsection Commands Specific to @sc{gnu} Hurd Systems
14d6dd68
EZ
23992@cindex @sc{gnu} Hurd debugging
23993
23994This subsection describes @value{GDBN} commands specific to the
23995@sc{gnu} Hurd native debugging.
23996
23997@table @code
23998@item set signals
23999@itemx set sigs
24000@kindex set signals@r{, Hurd command}
24001@kindex set sigs@r{, Hurd command}
24002This command toggles the state of inferior signal interception by
24003@value{GDBN}. Mach exceptions, such as breakpoint traps, are not
24004affected by this command. @code{sigs} is a shorthand alias for
24005@code{signals}.
24006
24007@item show signals
24008@itemx show sigs
24009@kindex show signals@r{, Hurd command}
24010@kindex show sigs@r{, Hurd command}
24011Show the current state of intercepting inferior's signals.
24012
24013@item set signal-thread
24014@itemx set sigthread
24015@kindex set signal-thread
24016@kindex set sigthread
24017This command tells @value{GDBN} which thread is the @code{libc} signal
24018thread. That thread is run when a signal is delivered to a running
24019process. @code{set sigthread} is the shorthand alias of @code{set
24020signal-thread}.
24021
24022@item show signal-thread
24023@itemx show sigthread
24024@kindex show signal-thread
24025@kindex show sigthread
24026These two commands show which thread will run when the inferior is
24027delivered a signal.
24028
24029@item set stopped
24030@kindex set stopped@r{, Hurd command}
24031This commands tells @value{GDBN} that the inferior process is stopped,
24032as with the @code{SIGSTOP} signal. The stopped process can be
24033continued by delivering a signal to it.
24034
24035@item show stopped
24036@kindex show stopped@r{, Hurd command}
24037This command shows whether @value{GDBN} thinks the debuggee is
24038stopped.
24039
24040@item set exceptions
24041@kindex set exceptions@r{, Hurd command}
24042Use this command to turn off trapping of exceptions in the inferior.
24043When exception trapping is off, neither breakpoints nor
24044single-stepping will work. To restore the default, set exception
24045trapping on.
24046
24047@item show exceptions
24048@kindex show exceptions@r{, Hurd command}
24049Show the current state of trapping exceptions in the inferior.
24050
24051@item set task pause
24052@kindex set task@r{, Hurd commands}
24053@cindex task attributes (@sc{gnu} Hurd)
24054@cindex pause current task (@sc{gnu} Hurd)
24055This command toggles task suspension when @value{GDBN} has control.
24056Setting it to on takes effect immediately, and the task is suspended
24057whenever @value{GDBN} gets control. Setting it to off will take
24058effect the next time the inferior is continued. If this option is set
24059to off, you can use @code{set thread default pause on} or @code{set
24060thread pause on} (see below) to pause individual threads.
24061
24062@item show task pause
24063@kindex show task@r{, Hurd commands}
24064Show the current state of task suspension.
24065
24066@item set task detach-suspend-count
24067@cindex task suspend count
24068@cindex detach from task, @sc{gnu} Hurd
24069This command sets the suspend count the task will be left with when
24070@value{GDBN} detaches from it.
24071
24072@item show task detach-suspend-count
24073Show the suspend count the task will be left with when detaching.
24074
24075@item set task exception-port
24076@itemx set task excp
24077@cindex task exception port, @sc{gnu} Hurd
24078This command sets the task exception port to which @value{GDBN} will
24079forward exceptions. The argument should be the value of the @dfn{send
24080rights} of the task. @code{set task excp} is a shorthand alias.
24081
24082@item set noninvasive
24083@cindex noninvasive task options
24084This command switches @value{GDBN} to a mode that is the least
24085invasive as far as interfering with the inferior is concerned. This
24086is the same as using @code{set task pause}, @code{set exceptions}, and
24087@code{set signals} to values opposite to the defaults.
24088
24089@item info send-rights
24090@itemx info receive-rights
24091@itemx info port-rights
24092@itemx info port-sets
24093@itemx info dead-names
24094@itemx info ports
24095@itemx info psets
24096@cindex send rights, @sc{gnu} Hurd
24097@cindex receive rights, @sc{gnu} Hurd
24098@cindex port rights, @sc{gnu} Hurd
24099@cindex port sets, @sc{gnu} Hurd
24100@cindex dead names, @sc{gnu} Hurd
24101These commands display information about, respectively, send rights,
24102receive rights, port rights, port sets, and dead names of a task.
24103There are also shorthand aliases: @code{info ports} for @code{info
24104port-rights} and @code{info psets} for @code{info port-sets}.
24105
24106@item set thread pause
24107@kindex set thread@r{, Hurd command}
24108@cindex thread properties, @sc{gnu} Hurd
24109@cindex pause current thread (@sc{gnu} Hurd)
24110This command toggles current thread suspension when @value{GDBN} has
24111control. Setting it to on takes effect immediately, and the current
24112thread is suspended whenever @value{GDBN} gets control. Setting it to
24113off will take effect the next time the inferior is continued.
24114Normally, this command has no effect, since when @value{GDBN} has
24115control, the whole task is suspended. However, if you used @code{set
24116task pause off} (see above), this command comes in handy to suspend
24117only the current thread.
24118
24119@item show thread pause
24120@kindex show thread@r{, Hurd command}
24121This command shows the state of current thread suspension.
24122
24123@item set thread run
d3e8051b 24124This command sets whether the current thread is allowed to run.
14d6dd68
EZ
24125
24126@item show thread run
24127Show whether the current thread is allowed to run.
24128
24129@item set thread detach-suspend-count
24130@cindex thread suspend count, @sc{gnu} Hurd
24131@cindex detach from thread, @sc{gnu} Hurd
24132This command sets the suspend count @value{GDBN} will leave on a
24133thread when detaching. This number is relative to the suspend count
24134found by @value{GDBN} when it notices the thread; use @code{set thread
24135takeover-suspend-count} to force it to an absolute value.
24136
24137@item show thread detach-suspend-count
24138Show the suspend count @value{GDBN} will leave on the thread when
24139detaching.
24140
24141@item set thread exception-port
24142@itemx set thread excp
24143Set the thread exception port to which to forward exceptions. This
24144overrides the port set by @code{set task exception-port} (see above).
24145@code{set thread excp} is the shorthand alias.
24146
24147@item set thread takeover-suspend-count
24148Normally, @value{GDBN}'s thread suspend counts are relative to the
24149value @value{GDBN} finds when it notices each thread. This command
24150changes the suspend counts to be absolute instead.
24151
24152@item set thread default
24153@itemx show thread default
24154@cindex thread default settings, @sc{gnu} Hurd
24155Each of the above @code{set thread} commands has a @code{set thread
24156default} counterpart (e.g., @code{set thread default pause}, @code{set
24157thread default exception-port}, etc.). The @code{thread default}
24158variety of commands sets the default thread properties for all
24159threads; you can then change the properties of individual threads with
24160the non-default commands.
24161@end table
24162
a80b95ba
TG
24163@node Darwin
24164@subsection Darwin
24165@cindex Darwin
24166
24167@value{GDBN} provides the following commands specific to the Darwin target:
24168
24169@table @code
24170@item set debug darwin @var{num}
24171@kindex set debug darwin
24172When set to a non zero value, enables debugging messages specific to
24173the Darwin support. Higher values produce more verbose output.
24174
24175@item show debug darwin
24176@kindex show debug darwin
24177Show the current state of Darwin messages.
24178
24179@item set debug mach-o @var{num}
24180@kindex set debug mach-o
24181When set to a non zero value, enables debugging messages while
24182@value{GDBN} is reading Darwin object files. (@dfn{Mach-O} is the
24183file format used on Darwin for object and executable files.) Higher
24184values produce more verbose output. This is a command to diagnose
24185problems internal to @value{GDBN} and should not be needed in normal
24186usage.
24187
24188@item show debug mach-o
24189@kindex show debug mach-o
24190Show the current state of Mach-O file messages.
24191
24192@item set mach-exceptions on
24193@itemx set mach-exceptions off
24194@kindex set mach-exceptions
24195On Darwin, faults are first reported as a Mach exception and are then
24196mapped to a Posix signal. Use this command to turn on trapping of
24197Mach exceptions in the inferior. This might be sometimes useful to
24198better understand the cause of a fault. The default is off.
24199
24200@item show mach-exceptions
24201@kindex show mach-exceptions
24202Show the current state of exceptions trapping.
24203@end table
24204
e9076973
JB
24205@node FreeBSD
24206@subsection FreeBSD
24207@cindex FreeBSD
24208
24209When the ABI of a system call is changed in the FreeBSD kernel, this
24210is implemented by leaving a compatibility system call using the old
24211ABI at the existing number and allocating a new system call number for
24212the version using the new ABI. As a convenience, when a system call
24213is caught by name (@pxref{catch syscall}), compatibility system calls
24214are also caught.
24215
24216For example, FreeBSD 12 introduced a new variant of the @code{kevent}
24217system call and catching the @code{kevent} system call by name catches
24218both variants:
24219
24220@smallexample
24221(@value{GDBP}) catch syscall kevent
24222Catchpoint 1 (syscalls 'freebsd11_kevent' [363] 'kevent' [560])
24223(@value{GDBP})
24224@end smallexample
24225
a64548ea 24226
8e04817f
AC
24227@node Embedded OS
24228@section Embedded Operating Systems
104c1213 24229
8e04817f
AC
24230This section describes configurations involving the debugging of
24231embedded operating systems that are available for several different
24232architectures.
d4f3574e 24233
8e04817f
AC
24234@value{GDBN} includes the ability to debug programs running on
24235various real-time operating systems.
104c1213 24236
6d2ebf8b 24237@node Embedded Processors
104c1213
JM
24238@section Embedded Processors
24239
24240This section goes into details specific to particular embedded
24241configurations.
24242
c45da7e6
EZ
24243@cindex send command to simulator
24244Whenever a specific embedded processor has a simulator, @value{GDBN}
24245allows to send an arbitrary command to the simulator.
24246
24247@table @code
24248@item sim @var{command}
24249@kindex sim@r{, a command}
24250Send an arbitrary @var{command} string to the simulator. Consult the
24251documentation for the specific simulator in use for information about
24252acceptable commands.
24253@end table
24254
7d86b5d5 24255
104c1213 24256@menu
ad0a504f 24257* ARC:: Synopsys ARC
bb615428 24258* ARM:: ARM
104c1213 24259* M68K:: Motorola M68K
08be9d71 24260* MicroBlaze:: Xilinx MicroBlaze
104c1213 24261* MIPS Embedded:: MIPS Embedded
a994fec4 24262* OpenRISC 1000:: OpenRISC 1000 (or1k)
4acd40f3 24263* PowerPC Embedded:: PowerPC Embedded
a64548ea
EZ
24264* AVR:: Atmel AVR
24265* CRIS:: CRIS
24266* Super-H:: Renesas Super-H
104c1213
JM
24267@end menu
24268
ad0a504f
AK
24269@node ARC
24270@subsection Synopsys ARC
24271@cindex Synopsys ARC
24272@cindex ARC specific commands
24273@cindex ARC600
24274@cindex ARC700
24275@cindex ARC EM
24276@cindex ARC HS
24277
24278@value{GDBN} provides the following ARC-specific commands:
24279
24280@table @code
24281@item set debug arc
24282@kindex set debug arc
24283Control the level of ARC specific debug messages. Use 0 for no messages (the
fe5f7374 24284default), 1 for debug messages, and 2 for even more debug messages.
ad0a504f
AK
24285
24286@item show debug arc
24287@kindex show debug arc
24288Show the level of ARC specific debugging in operation.
24289
eea78757
AK
24290@item maint print arc arc-instruction @var{address}
24291@kindex maint print arc arc-instruction
24292Print internal disassembler information about instruction at a given address.
24293
ad0a504f
AK
24294@end table
24295
6d2ebf8b 24296@node ARM
104c1213 24297@subsection ARM
8e04817f 24298
e2f4edfd
EZ
24299@value{GDBN} provides the following ARM-specific commands:
24300
24301@table @code
24302@item set arm disassembler
24303@kindex set arm
24304This commands selects from a list of disassembly styles. The
24305@code{"std"} style is the standard style.
24306
24307@item show arm disassembler
24308@kindex show arm
24309Show the current disassembly style.
24310
24311@item set arm apcs32
24312@cindex ARM 32-bit mode
24313This command toggles ARM operation mode between 32-bit and 26-bit.
24314
24315@item show arm apcs32
24316Display the current usage of the ARM 32-bit mode.
24317
24318@item set arm fpu @var{fputype}
24319This command sets the ARM floating-point unit (FPU) type. The
24320argument @var{fputype} can be one of these:
24321
24322@table @code
24323@item auto
24324Determine the FPU type by querying the OS ABI.
24325@item softfpa
24326Software FPU, with mixed-endian doubles on little-endian ARM
24327processors.
24328@item fpa
24329GCC-compiled FPA co-processor.
24330@item softvfp
24331Software FPU with pure-endian doubles.
24332@item vfp
24333VFP co-processor.
24334@end table
24335
24336@item show arm fpu
24337Show the current type of the FPU.
24338
24339@item set arm abi
24340This command forces @value{GDBN} to use the specified ABI.
24341
24342@item show arm abi
24343Show the currently used ABI.
24344
0428b8f5
DJ
24345@item set arm fallback-mode (arm|thumb|auto)
24346@value{GDBN} uses the symbol table, when available, to determine
24347whether instructions are ARM or Thumb. This command controls
24348@value{GDBN}'s default behavior when the symbol table is not
24349available. The default is @samp{auto}, which causes @value{GDBN} to
24350use the current execution mode (from the @code{T} bit in the @code{CPSR}
24351register).
24352
24353@item show arm fallback-mode
24354Show the current fallback instruction mode.
24355
24356@item set arm force-mode (arm|thumb|auto)
24357This command overrides use of the symbol table to determine whether
24358instructions are ARM or Thumb. The default is @samp{auto}, which
24359causes @value{GDBN} to use the symbol table and then the setting
24360of @samp{set arm fallback-mode}.
24361
24362@item show arm force-mode
24363Show the current forced instruction mode.
24364
e2f4edfd
EZ
24365@item set debug arm
24366Toggle whether to display ARM-specific debugging messages from the ARM
24367target support subsystem.
24368
24369@item show debug arm
24370Show whether ARM-specific debugging messages are enabled.
24371@end table
24372
ee8e71d4
EZ
24373@table @code
24374@item target sim @r{[}@var{simargs}@r{]} @dots{}
24375The @value{GDBN} ARM simulator accepts the following optional arguments.
24376
24377@table @code
24378@item --swi-support=@var{type}
697aa1b7 24379Tell the simulator which SWI interfaces to support. The argument
ee8e71d4
EZ
24380@var{type} may be a comma separated list of the following values.
24381The default value is @code{all}.
24382
24383@table @code
24384@item none
24385@item demon
24386@item angel
24387@item redboot
24388@item all
24389@end table
24390@end table
24391@end table
e2f4edfd 24392
8e04817f
AC
24393@node M68K
24394@subsection M68k
24395
bb615428 24396The Motorola m68k configuration includes ColdFire support.
8e04817f 24397
08be9d71
ME
24398@node MicroBlaze
24399@subsection MicroBlaze
24400@cindex Xilinx MicroBlaze
24401@cindex XMD, Xilinx Microprocessor Debugger
24402
24403The MicroBlaze is a soft-core processor supported on various Xilinx
24404FPGAs, such as Spartan or Virtex series. Boards with these processors
24405usually have JTAG ports which connect to a host system running the Xilinx
24406Embedded Development Kit (EDK) or Software Development Kit (SDK).
24407This host system is used to download the configuration bitstream to
24408the target FPGA. The Xilinx Microprocessor Debugger (XMD) program
24409communicates with the target board using the JTAG interface and
24410presents a @code{gdbserver} interface to the board. By default
24411@code{xmd} uses port @code{1234}. (While it is possible to change
24412this default port, it requires the use of undocumented @code{xmd}
24413commands. Contact Xilinx support if you need to do this.)
24414
24415Use these GDB commands to connect to the MicroBlaze target processor.
24416
24417@table @code
24418@item target remote :1234
24419Use this command to connect to the target if you are running @value{GDBN}
24420on the same system as @code{xmd}.
24421
24422@item target remote @var{xmd-host}:1234
24423Use this command to connect to the target if it is connected to @code{xmd}
24424running on a different system named @var{xmd-host}.
24425
24426@item load
24427Use this command to download a program to the MicroBlaze target.
24428
24429@item set debug microblaze @var{n}
24430Enable MicroBlaze-specific debugging messages if non-zero.
24431
24432@item show debug microblaze @var{n}
24433Show MicroBlaze-specific debugging level.
24434@end table
24435
8e04817f 24436@node MIPS Embedded
eb17f351 24437@subsection @acronym{MIPS} Embedded
8e04817f 24438
8e04817f 24439@noindent
f7c38292 24440@value{GDBN} supports these special commands for @acronym{MIPS} targets:
104c1213 24441
8e04817f 24442@table @code
8e04817f
AC
24443@item set mipsfpu double
24444@itemx set mipsfpu single
24445@itemx set mipsfpu none
a64548ea 24446@itemx set mipsfpu auto
8e04817f
AC
24447@itemx show mipsfpu
24448@kindex set mipsfpu
24449@kindex show mipsfpu
eb17f351
EZ
24450@cindex @acronym{MIPS} remote floating point
24451@cindex floating point, @acronym{MIPS} remote
24452If your target board does not support the @acronym{MIPS} floating point
8e04817f
AC
24453coprocessor, you should use the command @samp{set mipsfpu none} (if you
24454need this, you may wish to put the command in your @value{GDBN} init
24455file). This tells @value{GDBN} how to find the return value of
24456functions which return floating point values. It also allows
24457@value{GDBN} to avoid saving the floating point registers when calling
24458functions on the board. If you are using a floating point coprocessor
24459with only single precision floating point support, as on the @sc{r4650}
24460processor, use the command @samp{set mipsfpu single}. The default
24461double precision floating point coprocessor may be selected using
24462@samp{set mipsfpu double}.
104c1213 24463
8e04817f
AC
24464In previous versions the only choices were double precision or no
24465floating point, so @samp{set mipsfpu on} will select double precision
24466and @samp{set mipsfpu off} will select no floating point.
104c1213 24467
8e04817f
AC
24468As usual, you can inquire about the @code{mipsfpu} variable with
24469@samp{show mipsfpu}.
8e04817f 24470@end table
104c1213 24471
a994fec4
FJ
24472@node OpenRISC 1000
24473@subsection OpenRISC 1000
24474@cindex OpenRISC 1000
24475
24476@noindent
24477The OpenRISC 1000 provides a free RISC instruction set architecture. It is
24478mainly provided as a soft-core which can run on Xilinx, Altera and other
24479FPGA's.
24480
24481@value{GDBN} for OpenRISC supports the below commands when connecting to
24482a target:
24483
24484@table @code
24485
24486@kindex target sim
24487@item target sim
24488
24489Runs the builtin CPU simulator which can run very basic
24490programs but does not support most hardware functions like MMU.
24491For more complex use cases the user is advised to run an external
24492target, and connect using @samp{target remote}.
24493
24494Example: @code{target sim}
24495
24496@item set debug or1k
24497Toggle whether to display OpenRISC-specific debugging messages from the
24498OpenRISC target support subsystem.
24499
24500@item show debug or1k
24501Show whether OpenRISC-specific debugging messages are enabled.
24502@end table
24503
4acd40f3
TJB
24504@node PowerPC Embedded
24505@subsection PowerPC Embedded
104c1213 24506
66b73624
TJB
24507@cindex DVC register
24508@value{GDBN} supports using the DVC (Data Value Compare) register to
24509implement in hardware simple hardware watchpoint conditions of the form:
24510
24511@smallexample
24512(@value{GDBP}) watch @var{ADDRESS|VARIABLE} \
24513 if @var{ADDRESS|VARIABLE} == @var{CONSTANT EXPRESSION}
24514@end smallexample
24515
e09342b5
TJB
24516The DVC register will be automatically used when @value{GDBN} detects
24517such pattern in a condition expression, and the created watchpoint uses one
24518debug register (either the @code{exact-watchpoints} option is on and the
24519variable is scalar, or the variable has a length of one byte). This feature
24520is available in native @value{GDBN} running on a Linux kernel version 2.6.34
24521or newer.
24522
24523When running on PowerPC embedded processors, @value{GDBN} automatically uses
24524ranged hardware watchpoints, unless the @code{exact-watchpoints} option is on,
24525in which case watchpoints using only one debug register are created when
24526watching variables of scalar types.
24527
24528You can create an artificial array to watch an arbitrary memory
24529region using one of the following commands (@pxref{Expressions}):
24530
24531@smallexample
24532(@value{GDBP}) watch *((char *) @var{address})@@@var{length}
24533(@value{GDBP}) watch @{char[@var{length}]@} @var{address}
24534@end smallexample
66b73624 24535
9c06b0b4
TJB
24536PowerPC embedded processors support masked watchpoints. See the discussion
24537about the @code{mask} argument in @ref{Set Watchpoints}.
24538
f1310107
TJB
24539@cindex ranged breakpoint
24540PowerPC embedded processors support hardware accelerated
24541@dfn{ranged breakpoints}. A ranged breakpoint stops execution of
24542the inferior whenever it executes an instruction at any address within
24543the range it specifies. To set a ranged breakpoint in @value{GDBN},
24544use the @code{break-range} command.
24545
55eddb0f
DJ
24546@value{GDBN} provides the following PowerPC-specific commands:
24547
104c1213 24548@table @code
f1310107
TJB
24549@kindex break-range
24550@item break-range @var{start-location}, @var{end-location}
697aa1b7
EZ
24551Set a breakpoint for an address range given by
24552@var{start-location} and @var{end-location}, which can specify a function name,
f1310107
TJB
24553a line number, an offset of lines from the current line or from the start
24554location, or an address of an instruction (see @ref{Specify Location},
24555for a list of all the possible ways to specify a @var{location}.)
24556The breakpoint will stop execution of the inferior whenever it
24557executes an instruction at any address within the specified range,
24558(including @var{start-location} and @var{end-location}.)
24559
55eddb0f
DJ
24560@kindex set powerpc
24561@item set powerpc soft-float
24562@itemx show powerpc soft-float
24563Force @value{GDBN} to use (or not use) a software floating point calling
24564convention. By default, @value{GDBN} selects the calling convention based
24565on the selected architecture and the provided executable file.
24566
24567@item set powerpc vector-abi
24568@itemx show powerpc vector-abi
24569Force @value{GDBN} to use the specified calling convention for vector
24570arguments and return values. The valid options are @samp{auto};
24571@samp{generic}, to avoid vector registers even if they are present;
24572@samp{altivec}, to use AltiVec registers; and @samp{spe} to use SPE
24573registers. By default, @value{GDBN} selects the calling convention
24574based on the selected architecture and the provided executable file.
24575
e09342b5
TJB
24576@item set powerpc exact-watchpoints
24577@itemx show powerpc exact-watchpoints
24578Allow @value{GDBN} to use only one debug register when watching a variable
24579of scalar type, thus assuming that the variable is accessed through the
24580address of its first byte.
24581
104c1213
JM
24582@end table
24583
a64548ea
EZ
24584@node AVR
24585@subsection Atmel AVR
24586@cindex AVR
24587
24588When configured for debugging the Atmel AVR, @value{GDBN} supports the
24589following AVR-specific commands:
24590
24591@table @code
24592@item info io_registers
24593@kindex info io_registers@r{, AVR}
24594@cindex I/O registers (Atmel AVR)
24595This command displays information about the AVR I/O registers. For
24596each register, @value{GDBN} prints its number and value.
24597@end table
24598
24599@node CRIS
24600@subsection CRIS
24601@cindex CRIS
24602
24603When configured for debugging CRIS, @value{GDBN} provides the
24604following CRIS-specific commands:
24605
24606@table @code
24607@item set cris-version @var{ver}
24608@cindex CRIS version
e22e55c9
OF
24609Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
24610The CRIS version affects register names and sizes. This command is useful in
24611case autodetection of the CRIS version fails.
a64548ea
EZ
24612
24613@item show cris-version
24614Show the current CRIS version.
24615
24616@item set cris-dwarf2-cfi
24617@cindex DWARF-2 CFI and CRIS
e22e55c9
OF
24618Set the usage of DWARF-2 CFI for CRIS debugging. The default is @samp{on}.
24619Change to @samp{off} when using @code{gcc-cris} whose version is below
24620@code{R59}.
a64548ea
EZ
24621
24622@item show cris-dwarf2-cfi
24623Show the current state of using DWARF-2 CFI.
e22e55c9
OF
24624
24625@item set cris-mode @var{mode}
24626@cindex CRIS mode
24627Set the current CRIS mode to @var{mode}. It should only be changed when
24628debugging in guru mode, in which case it should be set to
24629@samp{guru} (the default is @samp{normal}).
24630
24631@item show cris-mode
24632Show the current CRIS mode.
a64548ea
EZ
24633@end table
24634
24635@node Super-H
24636@subsection Renesas Super-H
24637@cindex Super-H
24638
24639For the Renesas Super-H processor, @value{GDBN} provides these
24640commands:
24641
24642@table @code
c055b101
CV
24643@item set sh calling-convention @var{convention}
24644@kindex set sh calling-convention
24645Set the calling-convention used when calling functions from @value{GDBN}.
24646Allowed values are @samp{gcc}, which is the default setting, and @samp{renesas}.
24647With the @samp{gcc} setting, functions are called using the @value{NGCC} calling
24648convention. If the DWARF-2 information of the called function specifies
24649that the function follows the Renesas calling convention, the function
24650is called using the Renesas calling convention. If the calling convention
24651is set to @samp{renesas}, the Renesas calling convention is always used,
24652regardless of the DWARF-2 information. This can be used to override the
24653default of @samp{gcc} if debug information is missing, or the compiler
24654does not emit the DWARF-2 calling convention entry for a function.
24655
24656@item show sh calling-convention
24657@kindex show sh calling-convention
24658Show the current calling convention setting.
24659
a64548ea
EZ
24660@end table
24661
24662
8e04817f
AC
24663@node Architectures
24664@section Architectures
104c1213 24665
8e04817f
AC
24666This section describes characteristics of architectures that affect
24667all uses of @value{GDBN} with the architecture, both native and cross.
104c1213 24668
8e04817f 24669@menu
430ed3f0 24670* AArch64::
9c16f35a 24671* i386::
8e04817f
AC
24672* Alpha::
24673* MIPS::
a64548ea 24674* HPPA:: HP PA architecture
4acd40f3 24675* PowerPC::
a1217d97 24676* Nios II::
58afddc6 24677* Sparc64::
51d21d60 24678* S12Z::
8e04817f 24679@end menu
104c1213 24680
430ed3f0
MS
24681@node AArch64
24682@subsection AArch64
24683@cindex AArch64 support
24684
24685When @value{GDBN} is debugging the AArch64 architecture, it provides the
24686following special commands:
24687
24688@table @code
24689@item set debug aarch64
24690@kindex set debug aarch64
24691This command determines whether AArch64 architecture-specific debugging
24692messages are to be displayed.
24693
24694@item show debug aarch64
24695Show whether AArch64 debugging messages are displayed.
24696
24697@end table
24698
1461bdac
AH
24699@subsubsection AArch64 SVE.
24700@cindex AArch64 SVE.
24701
24702When @value{GDBN} is debugging the AArch64 architecture, if the Scalable Vector
24703Extension (SVE) is present, then @value{GDBN} will provide the vector registers
24704@code{$z0} through @code{$z31}, vector predicate registers @code{$p0} through
24705@code{$p15}, and the @code{$ffr} register. In addition, the pseudo register
24706@code{$vg} will be provided. This is the vector granule for the current thread
24707and represents the number of 64-bit chunks in an SVE @code{z} register.
24708
24709If the vector length changes, then the @code{$vg} register will be updated,
24710but the lengths of the @code{z} and @code{p} registers will not change. This
24711is a known limitation of @value{GDBN} and does not affect the execution of the
24712target process.
24713
3d31bc39
AH
24714@subsubsection AArch64 Pointer Authentication.
24715@cindex AArch64 Pointer Authentication.
24716
24717When @value{GDBN} is debugging the AArch64 architecture, and the program is
24718using the v8.3-A feature Pointer Authentication (PAC), then whenever the link
1ba7cdcd 24719register @code{$lr} is pointing to an PAC function its value will be masked.
3d31bc39 24720When GDB prints a backtrace, any addresses that required unmasking will be
aa7ca1bb
AH
24721postfixed with the marker [PAC]. When using the MI, this is printed as part
24722of the @code{addr_flags} field.
1461bdac 24723
9c16f35a 24724@node i386
db2e3e2e 24725@subsection x86 Architecture-specific Issues
9c16f35a
EZ
24726
24727@table @code
24728@item set struct-convention @var{mode}
24729@kindex set struct-convention
24730@cindex struct return convention
24731@cindex struct/union returned in registers
24732Set the convention used by the inferior to return @code{struct}s and
24733@code{union}s from functions to @var{mode}. Possible values of
24734@var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
24735default). @code{"default"} or @code{"pcc"} means that @code{struct}s
24736are returned on the stack, while @code{"reg"} means that a
24737@code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
24738be returned in a register.
24739
24740@item show struct-convention
24741@kindex show struct-convention
24742Show the current setting of the convention to return @code{struct}s
24743from functions.
966f0aef 24744@end table
29c1c244 24745
ca8941bb 24746
bc504a31
PA
24747@subsubsection Intel @dfn{Memory Protection Extensions} (MPX).
24748@cindex Intel Memory Protection Extensions (MPX).
ca8941bb 24749
ca8941bb
WT
24750Memory Protection Extension (MPX) adds the bound registers @samp{BND0}
24751@footnote{The register named with capital letters represent the architecture
24752registers.} through @samp{BND3}. Bound registers store a pair of 64-bit values
24753which are the lower bound and upper bound. Bounds are effective addresses or
24754memory locations. The upper bounds are architecturally represented in 1's
24755complement form. A bound having lower bound = 0, and upper bound = 0
24756(1's complement of all bits set) will allow access to the entire address space.
24757
24758@samp{BND0} through @samp{BND3} are represented in @value{GDBN} as @samp{bnd0raw}
24759through @samp{bnd3raw}. Pseudo registers @samp{bnd0} through @samp{bnd3}
24760display the upper bound performing the complement of one operation on the
24761upper bound value, i.e.@ when upper bound in @samp{bnd0raw} is 0 in the
24762@value{GDBN} @samp{bnd0} it will be @code{0xfff@dots{}}. In this sense it
24763can also be noted that the upper bounds are inclusive.
24764
24765As an example, assume that the register BND0 holds bounds for a pointer having
24766access allowed for the range between 0x32 and 0x71. The values present on
24767bnd0raw and bnd registers are presented as follows:
24768
24769@smallexample
24770 bnd0raw = @{0x32, 0xffffffff8e@}
24771 bnd0 = @{lbound = 0x32, ubound = 0x71@} : size 64
24772@end smallexample
24773
22f25c9d
EZ
24774This way the raw value can be accessed via bnd0raw@dots{}bnd3raw. Any
24775change on bnd0@dots{}bnd3 or bnd0raw@dots{}bnd3raw is reflect on its
24776counterpart. When the bnd0@dots{}bnd3 registers are displayed via
24777Python, the display includes the memory size, in bits, accessible to
24778the pointer.
9c16f35a 24779
29c1c244
WT
24780Bounds can also be stored in bounds tables, which are stored in
24781application memory. These tables store bounds for pointers by specifying
24782the bounds pointer's value along with its bounds. Evaluating and changing
24783bounds located in bound tables is therefore interesting while investigating
24784bugs on MPX context. @value{GDBN} provides commands for this purpose:
24785
966f0aef 24786@table @code
29c1c244
WT
24787@item show mpx bound @var{pointer}
24788@kindex show mpx bound
24789Display bounds of the given @var{pointer}.
24790
24791@item set mpx bound @var{pointer}, @var{lbound}, @var{ubound}
24792@kindex set mpx bound
24793Set the bounds of a pointer in the bound table.
24794This command takes three parameters: @var{pointer} is the pointers
24795whose bounds are to be changed, @var{lbound} and @var{ubound} are new values
24796for lower and upper bounds respectively.
24797@end table
24798
4a612d6f
WT
24799When you call an inferior function on an Intel MPX enabled program,
24800GDB sets the inferior's bound registers to the init (disabled) state
24801before calling the function. As a consequence, bounds checks for the
24802pointer arguments passed to the function will always pass.
24803
24804This is necessary because when you call an inferior function, the
24805program is usually in the middle of the execution of other function.
24806Since at that point bound registers are in an arbitrary state, not
24807clearing them would lead to random bound violations in the called
24808function.
24809
24810You can still examine the influence of the bound registers on the
24811execution of the called function by stopping the execution of the
24812called function at its prologue, setting bound registers, and
24813continuing the execution. For example:
24814
24815@smallexample
24816 $ break *upper
24817 Breakpoint 2 at 0x4009de: file i386-mpx-call.c, line 47.
24818 $ print upper (a, b, c, d, 1)
24819 Breakpoint 2, upper (a=0x0, b=0x6e0000005b, c=0x0, d=0x0, len=48)....
24820 $ print $bnd0
5cf70512 24821 @{lbound = 0x0, ubound = ffffffff@} : size -1
4a612d6f
WT
24822@end smallexample
24823
24824At this last step the value of bnd0 can be changed for investigation of bound
24825violations caused along the execution of the call. In order to know how to
24826set the bound registers or bound table for the call consult the ABI.
24827
8e04817f
AC
24828@node Alpha
24829@subsection Alpha
104c1213 24830
8e04817f 24831See the following section.
104c1213 24832
8e04817f 24833@node MIPS
eb17f351 24834@subsection @acronym{MIPS}
104c1213 24835
8e04817f 24836@cindex stack on Alpha
eb17f351 24837@cindex stack on @acronym{MIPS}
8e04817f 24838@cindex Alpha stack
eb17f351
EZ
24839@cindex @acronym{MIPS} stack
24840Alpha- and @acronym{MIPS}-based computers use an unusual stack frame, which
8e04817f
AC
24841sometimes requires @value{GDBN} to search backward in the object code to
24842find the beginning of a function.
104c1213 24843
eb17f351 24844@cindex response time, @acronym{MIPS} debugging
8e04817f
AC
24845To improve response time (especially for embedded applications, where
24846@value{GDBN} may be restricted to a slow serial line for this search)
24847you may want to limit the size of this search, using one of these
24848commands:
104c1213 24849
8e04817f 24850@table @code
eb17f351 24851@cindex @code{heuristic-fence-post} (Alpha, @acronym{MIPS})
8e04817f
AC
24852@item set heuristic-fence-post @var{limit}
24853Restrict @value{GDBN} to examining at most @var{limit} bytes in its
24854search for the beginning of a function. A value of @var{0} (the
24855default) means there is no limit. However, except for @var{0}, the
24856larger the limit the more bytes @code{heuristic-fence-post} must search
e2f4edfd
EZ
24857and therefore the longer it takes to run. You should only need to use
24858this command when debugging a stripped executable.
104c1213 24859
8e04817f
AC
24860@item show heuristic-fence-post
24861Display the current limit.
24862@end table
104c1213
JM
24863
24864@noindent
8e04817f 24865These commands are available @emph{only} when @value{GDBN} is configured
eb17f351 24866for debugging programs on Alpha or @acronym{MIPS} processors.
104c1213 24867
eb17f351 24868Several @acronym{MIPS}-specific commands are available when debugging @acronym{MIPS}
a64548ea
EZ
24869programs:
24870
24871@table @code
a64548ea
EZ
24872@item set mips abi @var{arg}
24873@kindex set mips abi
eb17f351
EZ
24874@cindex set ABI for @acronym{MIPS}
24875Tell @value{GDBN} which @acronym{MIPS} ABI is used by the inferior. Possible
a64548ea
EZ
24876values of @var{arg} are:
24877
24878@table @samp
24879@item auto
24880The default ABI associated with the current binary (this is the
24881default).
24882@item o32
24883@item o64
24884@item n32
24885@item n64
24886@item eabi32
24887@item eabi64
a64548ea
EZ
24888@end table
24889
24890@item show mips abi
24891@kindex show mips abi
eb17f351 24892Show the @acronym{MIPS} ABI used by @value{GDBN} to debug the inferior.
a64548ea 24893
4cc0665f
MR
24894@item set mips compression @var{arg}
24895@kindex set mips compression
24896@cindex code compression, @acronym{MIPS}
24897Tell @value{GDBN} which @acronym{MIPS} compressed
24898@acronym{ISA, Instruction Set Architecture} encoding is used by the
24899inferior. @value{GDBN} uses this for code disassembly and other
24900internal interpretation purposes. This setting is only referred to
24901when no executable has been associated with the debugging session or
24902the executable does not provide information about the encoding it uses.
24903Otherwise this setting is automatically updated from information
24904provided by the executable.
24905
24906Possible values of @var{arg} are @samp{mips16} and @samp{micromips}.
24907The default compressed @acronym{ISA} encoding is @samp{mips16}, as
24908executables containing @acronym{MIPS16} code frequently are not
24909identified as such.
24910
24911This setting is ``sticky''; that is, it retains its value across
24912debugging sessions until reset either explicitly with this command or
24913implicitly from an executable.
24914
24915The compiler and/or assembler typically add symbol table annotations to
24916identify functions compiled for the @acronym{MIPS16} or
24917@acronym{microMIPS} @acronym{ISA}s. If these function-scope annotations
24918are present, @value{GDBN} uses them in preference to the global
24919compressed @acronym{ISA} encoding setting.
24920
24921@item show mips compression
24922@kindex show mips compression
24923Show the @acronym{MIPS} compressed @acronym{ISA} encoding used by
24924@value{GDBN} to debug the inferior.
24925
a64548ea
EZ
24926@item set mipsfpu
24927@itemx show mipsfpu
24928@xref{MIPS Embedded, set mipsfpu}.
24929
24930@item set mips mask-address @var{arg}
24931@kindex set mips mask-address
eb17f351 24932@cindex @acronym{MIPS} addresses, masking
a64548ea 24933This command determines whether the most-significant 32 bits of 64-bit
eb17f351 24934@acronym{MIPS} addresses are masked off. The argument @var{arg} can be
a64548ea
EZ
24935@samp{on}, @samp{off}, or @samp{auto}. The latter is the default
24936setting, which lets @value{GDBN} determine the correct value.
24937
24938@item show mips mask-address
24939@kindex show mips mask-address
eb17f351 24940Show whether the upper 32 bits of @acronym{MIPS} addresses are masked off or
a64548ea
EZ
24941not.
24942
24943@item set remote-mips64-transfers-32bit-regs
24944@kindex set remote-mips64-transfers-32bit-regs
eb17f351
EZ
24945This command controls compatibility with 64-bit @acronym{MIPS} targets that
24946transfer data in 32-bit quantities. If you have an old @acronym{MIPS} 64 target
a64548ea
EZ
24947that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
24948and 64 bits for other registers, set this option to @samp{on}.
24949
24950@item show remote-mips64-transfers-32bit-regs
24951@kindex show remote-mips64-transfers-32bit-regs
eb17f351 24952Show the current setting of compatibility with older @acronym{MIPS} 64 targets.
a64548ea
EZ
24953
24954@item set debug mips
24955@kindex set debug mips
eb17f351 24956This command turns on and off debugging messages for the @acronym{MIPS}-specific
a64548ea
EZ
24957target code in @value{GDBN}.
24958
24959@item show debug mips
24960@kindex show debug mips
eb17f351 24961Show the current setting of @acronym{MIPS} debugging messages.
a64548ea
EZ
24962@end table
24963
24964
24965@node HPPA
24966@subsection HPPA
24967@cindex HPPA support
24968
d3e8051b 24969When @value{GDBN} is debugging the HP PA architecture, it provides the
a64548ea
EZ
24970following special commands:
24971
24972@table @code
24973@item set debug hppa
24974@kindex set debug hppa
db2e3e2e 24975This command determines whether HPPA architecture-specific debugging
a64548ea
EZ
24976messages are to be displayed.
24977
24978@item show debug hppa
24979Show whether HPPA debugging messages are displayed.
24980
24981@item maint print unwind @var{address}
24982@kindex maint print unwind@r{, HPPA}
24983This command displays the contents of the unwind table entry at the
24984given @var{address}.
24985
24986@end table
24987
104c1213 24988
4acd40f3
TJB
24989@node PowerPC
24990@subsection PowerPC
24991@cindex PowerPC architecture
24992
24993When @value{GDBN} is debugging the PowerPC architecture, it provides a set of
24994pseudo-registers to enable inspection of 128-bit wide Decimal Floating Point
24995numbers stored in the floating point registers. These values must be stored
24996in two consecutive registers, always starting at an even register like
24997@code{f0} or @code{f2}.
24998
24999The pseudo-registers go from @code{$dl0} through @code{$dl15}, and are formed
25000by joining the even/odd register pairs @code{f0} and @code{f1} for @code{$dl0},
25001@code{f2} and @code{f3} for @code{$dl1} and so on.
25002
aeac0ff9 25003For POWER7 processors, @value{GDBN} provides a set of pseudo-registers, the 64-bit
677c5bb1
LM
25004wide Extended Floating Point Registers (@samp{f32} through @samp{f63}).
25005
a1217d97
SL
25006@node Nios II
25007@subsection Nios II
25008@cindex Nios II architecture
25009
25010When @value{GDBN} is debugging the Nios II architecture,
25011it provides the following special commands:
25012
25013@table @code
25014
25015@item set debug nios2
25016@kindex set debug nios2
25017This command turns on and off debugging messages for the Nios II
25018target code in @value{GDBN}.
25019
25020@item show debug nios2
25021@kindex show debug nios2
25022Show the current setting of Nios II debugging messages.
25023@end table
23d964e7 25024
58afddc6
WP
25025@node Sparc64
25026@subsection Sparc64
25027@cindex Sparc64 support
25028@cindex Application Data Integrity
25029@subsubsection ADI Support
25030
25031The M7 processor supports an Application Data Integrity (ADI) feature that
25032detects invalid data accesses. When software allocates memory and enables
25033ADI on the allocated memory, it chooses a 4-bit version number, sets the
25034version in the upper 4 bits of the 64-bit pointer to that data, and stores
25035the 4-bit version in every cacheline of that data. Hardware saves the latter
25036in spare bits in the cache and memory hierarchy. On each load and store,
25037the processor compares the upper 4 VA (virtual address) bits to the
25038cacheline's version. If there is a mismatch, the processor generates a
25039version mismatch trap which can be either precise or disrupting. The trap
25040is an error condition which the kernel delivers to the process as a SIGSEGV
25041signal.
25042
25043Note that only 64-bit applications can use ADI and need to be built with
25044ADI-enabled.
25045
25046Values of the ADI version tags, which are in granularity of a
25047cacheline (64 bytes), can be viewed or modified.
25048
25049
25050@table @code
25051@kindex adi examine
25052@item adi (examine | x) [ / @var{n} ] @var{addr}
25053
25054The @code{adi examine} command displays the value of one ADI version tag per
25055cacheline.
25056
25057@var{n} is a decimal integer specifying the number in bytes; the default
25058is 1. It specifies how much ADI version information, at the ratio of 1:ADI
25059block size, to display.
25060
25061@var{addr} is the address in user address space where you want @value{GDBN}
25062to begin displaying the ADI version tags.
25063
25064Below is an example of displaying ADI versions of variable "shmaddr".
25065
25066@smallexample
25067(@value{GDBP}) adi x/100 shmaddr
25068 0xfff800010002c000: 0 0
25069@end smallexample
25070
25071@kindex adi assign
25072@item adi (assign | a) [ / @var{n} ] @var{addr} = @var{tag}
25073
25074The @code{adi assign} command is used to assign new ADI version tag
25075to an address.
25076
25077@var{n} is a decimal integer specifying the number in bytes;
25078the default is 1. It specifies how much ADI version information, at the
25079ratio of 1:ADI block size, to modify.
25080
25081@var{addr} is the address in user address space where you want @value{GDBN}
25082to begin modifying the ADI version tags.
25083
25084@var{tag} is the new ADI version tag.
25085
25086For example, do the following to modify then verify ADI versions of
25087variable "shmaddr":
25088
25089@smallexample
25090(@value{GDBP}) adi a/100 shmaddr = 7
25091(@value{GDBP}) adi x/100 shmaddr
25092 0xfff800010002c000: 7 7
25093@end smallexample
25094
25095@end table
25096
51d21d60
JD
25097@node S12Z
25098@subsection S12Z
25099@cindex S12Z support
25100
25101When @value{GDBN} is debugging the S12Z architecture,
25102it provides the following special command:
25103
25104@table @code
25105@item maint info bdccsr
25106@kindex maint info bdccsr@r{, S12Z}
25107This command displays the current value of the microprocessor's
25108BDCCSR register.
25109@end table
25110
25111
8e04817f
AC
25112@node Controlling GDB
25113@chapter Controlling @value{GDBN}
25114
25115You can alter the way @value{GDBN} interacts with you by using the
25116@code{set} command. For commands controlling how @value{GDBN} displays
79a6e687 25117data, see @ref{Print Settings, ,Print Settings}. Other settings are
8e04817f
AC
25118described here.
25119
25120@menu
25121* Prompt:: Prompt
25122* Editing:: Command editing
d620b259 25123* Command History:: Command history
8e04817f 25124* Screen Size:: Screen size
140a4bc0 25125* Output Styling:: Output styling
8e04817f 25126* Numbers:: Numbers
1e698235 25127* ABI:: Configuring the current ABI
bf88dd68 25128* Auto-loading:: Automatically loading associated files
8e04817f
AC
25129* Messages/Warnings:: Optional warnings and messages
25130* Debugging Output:: Optional messages about internal happenings
14fb1bac 25131* Other Misc Settings:: Other Miscellaneous Settings
8e04817f
AC
25132@end menu
25133
25134@node Prompt
25135@section Prompt
104c1213 25136
8e04817f 25137@cindex prompt
104c1213 25138
8e04817f
AC
25139@value{GDBN} indicates its readiness to read a command by printing a string
25140called the @dfn{prompt}. This string is normally @samp{(@value{GDBP})}. You
25141can change the prompt string with the @code{set prompt} command. For
25142instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
25143the prompt in one of the @value{GDBN} sessions so that you can always tell
25144which one you are talking to.
104c1213 25145
8e04817f
AC
25146@emph{Note:} @code{set prompt} does not add a space for you after the
25147prompt you set. This allows you to set a prompt which ends in a space
25148or a prompt that does not.
104c1213 25149
8e04817f
AC
25150@table @code
25151@kindex set prompt
25152@item set prompt @var{newprompt}
25153Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
104c1213 25154
8e04817f
AC
25155@kindex show prompt
25156@item show prompt
25157Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
104c1213
JM
25158@end table
25159
fa3a4f15
PM
25160Versions of @value{GDBN} that ship with Python scripting enabled have
25161prompt extensions. The commands for interacting with these extensions
25162are:
25163
25164@table @code
25165@kindex set extended-prompt
25166@item set extended-prompt @var{prompt}
25167Set an extended prompt that allows for substitutions.
25168@xref{gdb.prompt}, for a list of escape sequences that can be used for
25169substitution. Any escape sequences specified as part of the prompt
25170string are replaced with the corresponding strings each time the prompt
25171is displayed.
25172
25173For example:
25174
25175@smallexample
25176set extended-prompt Current working directory: \w (gdb)
25177@end smallexample
25178
25179Note that when an extended-prompt is set, it takes control of the
25180@var{prompt_hook} hook. @xref{prompt_hook}, for further information.
25181
25182@kindex show extended-prompt
25183@item show extended-prompt
25184Prints the extended prompt. Any escape sequences specified as part of
25185the prompt string with @code{set extended-prompt}, are replaced with the
25186corresponding strings each time the prompt is displayed.
25187@end table
25188
8e04817f 25189@node Editing
79a6e687 25190@section Command Editing
8e04817f
AC
25191@cindex readline
25192@cindex command line editing
104c1213 25193
703663ab 25194@value{GDBN} reads its input commands via the @dfn{Readline} interface. This
8e04817f
AC
25195@sc{gnu} library provides consistent behavior for programs which provide a
25196command line interface to the user. Advantages are @sc{gnu} Emacs-style
25197or @dfn{vi}-style inline editing of commands, @code{csh}-like history
25198substitution, and a storage and recall of command history across
25199debugging sessions.
104c1213 25200
8e04817f
AC
25201You may control the behavior of command line editing in @value{GDBN} with the
25202command @code{set}.
104c1213 25203
8e04817f
AC
25204@table @code
25205@kindex set editing
25206@cindex editing
25207@item set editing
25208@itemx set editing on
25209Enable command line editing (enabled by default).
104c1213 25210
8e04817f
AC
25211@item set editing off
25212Disable command line editing.
104c1213 25213
8e04817f
AC
25214@kindex show editing
25215@item show editing
25216Show whether command line editing is enabled.
104c1213
JM
25217@end table
25218
39037522
TT
25219@ifset SYSTEM_READLINE
25220@xref{Command Line Editing, , , rluserman, GNU Readline Library},
25221@end ifset
25222@ifclear SYSTEM_READLINE
25223@xref{Command Line Editing},
25224@end ifclear
25225for more details about the Readline
703663ab
EZ
25226interface. Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
25227encouraged to read that chapter.
25228
11061048
TT
25229@cindex Readline application name
25230@value{GDBN} sets the Readline application name to @samp{gdb}. This
25231is useful for conditions in @file{.inputrc}.
25232
c71acd15
TT
25233@cindex operate-and-get-next
25234@value{GDBN} defines a bindable Readline command,
25235@code{operate-and-get-next}. This is bound to @kbd{C-o} by default.
25236This command accepts the current line for execution and fetches the
25237next line relative to the current line from the history for editing.
25238Any argument is ignored.
25239
d620b259 25240@node Command History
79a6e687 25241@section Command History
703663ab 25242@cindex command history
8e04817f
AC
25243
25244@value{GDBN} can keep track of the commands you type during your
25245debugging sessions, so that you can be certain of precisely what
25246happened. Use these commands to manage the @value{GDBN} command
25247history facility.
104c1213 25248
703663ab 25249@value{GDBN} uses the @sc{gnu} History library, a part of the Readline
39037522
TT
25250package, to provide the history facility.
25251@ifset SYSTEM_READLINE
25252@xref{Using History Interactively, , , history, GNU History Library},
25253@end ifset
25254@ifclear SYSTEM_READLINE
25255@xref{Using History Interactively},
25256@end ifclear
25257for the detailed description of the History library.
703663ab 25258
d620b259 25259To issue a command to @value{GDBN} without affecting certain aspects of
9e6c4bd5
NR
25260the state which is seen by users, prefix it with @samp{server }
25261(@pxref{Server Prefix}). This
d620b259
NR
25262means that this command will not affect the command history, nor will it
25263affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
25264pressed on a line by itself.
25265
25266@cindex @code{server}, command prefix
25267The server prefix does not affect the recording of values into the value
25268history; to print a value without recording it into the value history,
25269use the @code{output} command instead of the @code{print} command.
25270
703663ab
EZ
25271Here is the description of @value{GDBN} commands related to command
25272history.
25273
104c1213 25274@table @code
8e04817f
AC
25275@cindex history substitution
25276@cindex history file
25277@kindex set history filename
4644b6e3 25278@cindex @env{GDBHISTFILE}, environment variable
8e04817f
AC
25279@item set history filename @var{fname}
25280Set the name of the @value{GDBN} command history file to @var{fname}.
25281This is the file where @value{GDBN} reads an initial command history
25282list, and where it writes the command history from this session when it
25283exits. You can access this list through history expansion or through
25284the history command editing characters listed below. This file defaults
25285to the value of the environment variable @code{GDBHISTFILE}, or to
25286@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
25287is not set.
104c1213 25288
9c16f35a
EZ
25289@cindex save command history
25290@kindex set history save
8e04817f
AC
25291@item set history save
25292@itemx set history save on
25293Record command history in a file, whose name may be specified with the
25294@code{set history filename} command. By default, this option is disabled.
104c1213 25295
8e04817f
AC
25296@item set history save off
25297Stop recording command history in a file.
104c1213 25298
8e04817f 25299@cindex history size
9c16f35a 25300@kindex set history size
b58c513b 25301@cindex @env{GDBHISTSIZE}, environment variable
8e04817f 25302@item set history size @var{size}
f81d1120 25303@itemx set history size unlimited
8e04817f 25304Set the number of commands which @value{GDBN} keeps in its history list.
bc460514
PP
25305This defaults to the value of the environment variable @env{GDBHISTSIZE}, or
25306to 256 if this variable is not set. Non-numeric values of @env{GDBHISTSIZE}
0eacb298
PP
25307are ignored. If @var{size} is @code{unlimited} or if @env{GDBHISTSIZE} is
25308either a negative number or the empty string, then the number of commands
25309@value{GDBN} keeps in the history list is unlimited.
fc637f04
PP
25310
25311@cindex remove duplicate history
25312@kindex set history remove-duplicates
25313@item set history remove-duplicates @var{count}
25314@itemx set history remove-duplicates unlimited
25315Control the removal of duplicate history entries in the command history list.
25316If @var{count} is non-zero, @value{GDBN} will look back at the last @var{count}
25317history entries and remove the first entry that is a duplicate of the current
25318entry being added to the command history list. If @var{count} is
25319@code{unlimited} then this lookbehind is unbounded. If @var{count} is 0, then
25320removal of duplicate history entries is disabled.
25321
25322Only history entries added during the current session are considered for
25323removal. This option is set to 0 by default.
25324
104c1213
JM
25325@end table
25326
8e04817f 25327History expansion assigns special meaning to the character @kbd{!}.
39037522
TT
25328@ifset SYSTEM_READLINE
25329@xref{Event Designators, , , history, GNU History Library},
25330@end ifset
25331@ifclear SYSTEM_READLINE
25332@xref{Event Designators},
25333@end ifclear
25334for more details.
8e04817f 25335
703663ab 25336@cindex history expansion, turn on/off
8e04817f
AC
25337Since @kbd{!} is also the logical not operator in C, history expansion
25338is off by default. If you decide to enable history expansion with the
25339@code{set history expansion on} command, you may sometimes need to
25340follow @kbd{!} (when it is used as logical not, in an expression) with
25341a space or a tab to prevent it from being expanded. The readline
25342history facilities do not attempt substitution on the strings
25343@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
25344
25345The commands to control history expansion are:
104c1213
JM
25346
25347@table @code
8e04817f
AC
25348@item set history expansion on
25349@itemx set history expansion
703663ab 25350@kindex set history expansion
8e04817f 25351Enable history expansion. History expansion is off by default.
104c1213 25352
8e04817f
AC
25353@item set history expansion off
25354Disable history expansion.
104c1213 25355
8e04817f
AC
25356@c @group
25357@kindex show history
25358@item show history
25359@itemx show history filename
25360@itemx show history save
25361@itemx show history size
25362@itemx show history expansion
25363These commands display the state of the @value{GDBN} history parameters.
25364@code{show history} by itself displays all four states.
25365@c @end group
25366@end table
25367
25368@table @code
9c16f35a
EZ
25369@kindex show commands
25370@cindex show last commands
25371@cindex display command history
8e04817f
AC
25372@item show commands
25373Display the last ten commands in the command history.
104c1213 25374
8e04817f
AC
25375@item show commands @var{n}
25376Print ten commands centered on command number @var{n}.
25377
25378@item show commands +
25379Print ten commands just after the commands last printed.
104c1213
JM
25380@end table
25381
8e04817f 25382@node Screen Size
79a6e687 25383@section Screen Size
8e04817f 25384@cindex size of screen
f179cf97
EZ
25385@cindex screen size
25386@cindex pagination
25387@cindex page size
8e04817f 25388@cindex pauses in output
104c1213 25389
8e04817f
AC
25390Certain commands to @value{GDBN} may produce large amounts of
25391information output to the screen. To help you read all of it,
25392@value{GDBN} pauses and asks you for input at the end of each page of
eb6af809
TT
25393output. Type @key{RET} when you want to see one more page of output,
25394@kbd{q} to discard the remaining output, or @kbd{c} to continue
25395without paging for the rest of the current command. Also, the screen
25396width setting determines when to wrap lines of output. Depending on
25397what is being printed, @value{GDBN} tries to break the line at a
25398readable place, rather than simply letting it overflow onto the
25399following line.
8e04817f
AC
25400
25401Normally @value{GDBN} knows the size of the screen from the terminal
25402driver software. For example, on Unix @value{GDBN} uses the termcap data base
25403together with the value of the @code{TERM} environment variable and the
25404@code{stty rows} and @code{stty cols} settings. If this is not correct,
25405you can override it with the @code{set height} and @code{set
25406width} commands:
25407
25408@table @code
25409@kindex set height
25410@kindex set width
25411@kindex show width
25412@kindex show height
25413@item set height @var{lpp}
f81d1120 25414@itemx set height unlimited
8e04817f
AC
25415@itemx show height
25416@itemx set width @var{cpl}
f81d1120 25417@itemx set width unlimited
8e04817f
AC
25418@itemx show width
25419These @code{set} commands specify a screen height of @var{lpp} lines and
25420a screen width of @var{cpl} characters. The associated @code{show}
25421commands display the current settings.
104c1213 25422
f81d1120
PA
25423If you specify a height of either @code{unlimited} or zero lines,
25424@value{GDBN} does not pause during output no matter how long the
25425output is. This is useful if output is to a file or to an editor
25426buffer.
104c1213 25427
f81d1120
PA
25428Likewise, you can specify @samp{set width unlimited} or @samp{set
25429width 0} to prevent @value{GDBN} from wrapping its output.
9c16f35a
EZ
25430
25431@item set pagination on
25432@itemx set pagination off
25433@kindex set pagination
25434Turn the output pagination on or off; the default is on. Turning
f81d1120 25435pagination off is the alternative to @code{set height unlimited}. Note that
7c953934
TT
25436running @value{GDBN} with the @option{--batch} option (@pxref{Mode
25437Options, -batch}) also automatically disables pagination.
9c16f35a
EZ
25438
25439@item show pagination
25440@kindex show pagination
25441Show the current pagination mode.
104c1213
JM
25442@end table
25443
140a4bc0
TT
25444@node Output Styling
25445@section Output Styling
25446@cindex styling
25447@cindex colors
25448
25449@kindex set style
25450@kindex show style
25451@value{GDBN} can style its output on a capable terminal. This is
7557a514
AH
25452enabled by default on most systems, but disabled by default when in
25453batch mode (@pxref{Mode Options}). Various style settings are available;
25454and styles can also be disabled entirely.
140a4bc0
TT
25455
25456@table @code
25457@item set style enabled @samp{on|off}
25458Enable or disable all styling. The default is host-dependent, with
25459most hosts defaulting to @samp{on}.
25460
25461@item show style enabled
25462Show the current state of styling.
d085f989
TT
25463
25464@item set style sources @samp{on|off}
25465Enable or disable source code styling. This affects whether source
25466code, such as the output of the @code{list} command, is styled. Note
25467that source styling only works if styling in general is enabled, and
25468if @value{GDBN} was linked with the GNU Source Highlight library. The
25469default is @samp{on}.
25470
25471@item show style sources
25472Show the current state of source code styling.
140a4bc0
TT
25473@end table
25474
25475Subcommands of @code{set style} control specific forms of styling.
25476These subcommands all follow the same pattern: each style-able object
25477can be styled with a foreground color, a background color, and an
25478intensity.
25479
25480For example, the style of file names can be controlled using the
25481@code{set style filename} group of commands:
25482
25483@table @code
25484@item set style filename background @var{color}
25485Set the background to @var{color}. Valid colors are @samp{none}
25486(meaning the terminal's default color), @samp{black}, @samp{red},
e3624a40 25487@samp{green}, @samp{yellow}, @samp{blue}, @samp{magenta}, @samp{cyan},
140a4bc0
TT
25488and@samp{white}.
25489
25490@item set style filename foreground @var{color}
25491Set the foreground to @var{color}. Valid colors are @samp{none}
25492(meaning the terminal's default color), @samp{black}, @samp{red},
e3624a40 25493@samp{green}, @samp{yellow}, @samp{blue}, @samp{magenta}, @samp{cyan},
140a4bc0
TT
25494and@samp{white}.
25495
25496@item set style filename intensity @var{value}
25497Set the intensity to @var{value}. Valid intensities are @samp{normal}
25498(the default), @samp{bold}, and @samp{dim}.
25499@end table
25500
e664d728
PW
25501The @code{show style} command and its subcommands are styling
25502a style name in their output using its own style.
25503So, use @command{show style} to see the complete list of styles,
25504their characteristics and the visual aspect of each style.
25505
140a4bc0
TT
25506The style-able objects are:
25507@table @code
25508@item filename
e3624a40
EZ
25509Control the styling of file names. By default, this style's
25510foreground color is green.
140a4bc0
TT
25511
25512@item function
25513Control the styling of function names. These are managed with the
e3624a40
EZ
25514@code{set style function} family of commands. By default, this
25515style's foreground color is yellow.
140a4bc0
TT
25516
25517@item variable
25518Control the styling of variable names. These are managed with the
e3624a40
EZ
25519@code{set style variable} family of commands. By default, this style's
25520foreground color is cyan.
140a4bc0
TT
25521
25522@item address
25523Control the styling of addresses. These are managed with the
e3624a40
EZ
25524@code{set style address} family of commands. By default, this style's
25525foreground color is blue.
e664d728
PW
25526
25527@item title
25528Control the styling of titles. These are managed with the
25529@code{set style title} family of commands. By default, this style's
25530intensity is bold. Commands are using the title style to improve
6b92c0d3 25531the readability of large output. For example, the commands
e664d728
PW
25532@command{apropos} and @command{help} are using the title style
25533for the command names.
25534
25535@item highlight
25536Control the styling of highlightings. These are managed with the
25537@code{set style highlight} family of commands. By default, this style's
25538foreground color is red. Commands are using the highlight style to draw
25539the user attention to some specific parts of their output. For example,
25540the command @command{apropos -v REGEXP} uses the highlight style to
25541mark the documentation parts matching @var{regexp}.
25542
a2a7af0c
TT
25543@item tui-border
25544Control the styling of the TUI border. Note that, unlike other
25545styling options, only the color of the border can be controlled via
25546@code{set style}. This was done for compatibility reasons, as TUI
25547controls to set the border's intensity predated the addition of
25548general styling to @value{GDBN}. @xref{TUI Configuration}.
25549
25550@item tui-active-border
25551Control the styling of the active TUI border; that is, the TUI window
25552that has the focus.
25553
140a4bc0
TT
25554@end table
25555
8e04817f
AC
25556@node Numbers
25557@section Numbers
25558@cindex number representation
25559@cindex entering numbers
104c1213 25560
8e04817f
AC
25561You can always enter numbers in octal, decimal, or hexadecimal in
25562@value{GDBN} by the usual conventions: octal numbers begin with
25563@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
eb2dae08
EZ
25564begin with @samp{0x}. Numbers that neither begin with @samp{0} or
25565@samp{0x}, nor end with a @samp{.} are, by default, entered in base
2556610; likewise, the default display for numbers---when no particular
25567format is specified---is base 10. You can change the default base for
25568both input and output with the commands described below.
104c1213 25569
8e04817f
AC
25570@table @code
25571@kindex set input-radix
25572@item set input-radix @var{base}
25573Set the default base for numeric input. Supported choices
697aa1b7 25574for @var{base} are decimal 8, 10, or 16. The base must itself be
eb2dae08 25575specified either unambiguously or using the current input radix; for
8e04817f 25576example, any of
104c1213 25577
8e04817f 25578@smallexample
9c16f35a
EZ
25579set input-radix 012
25580set input-radix 10.
25581set input-radix 0xa
8e04817f 25582@end smallexample
104c1213 25583
8e04817f 25584@noindent
9c16f35a 25585sets the input base to decimal. On the other hand, @samp{set input-radix 10}
eb2dae08
EZ
25586leaves the input radix unchanged, no matter what it was, since
25587@samp{10}, being without any leading or trailing signs of its base, is
25588interpreted in the current radix. Thus, if the current radix is 16,
25589@samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
25590change the radix.
104c1213 25591
8e04817f
AC
25592@kindex set output-radix
25593@item set output-radix @var{base}
25594Set the default base for numeric display. Supported choices
697aa1b7 25595for @var{base} are decimal 8, 10, or 16. The base must itself be
eb2dae08 25596specified either unambiguously or using the current input radix.
104c1213 25597
8e04817f
AC
25598@kindex show input-radix
25599@item show input-radix
25600Display the current default base for numeric input.
104c1213 25601
8e04817f
AC
25602@kindex show output-radix
25603@item show output-radix
25604Display the current default base for numeric display.
9c16f35a
EZ
25605
25606@item set radix @r{[}@var{base}@r{]}
25607@itemx show radix
25608@kindex set radix
25609@kindex show radix
25610These commands set and show the default base for both input and output
25611of numbers. @code{set radix} sets the radix of input and output to
25612the same base; without an argument, it resets the radix back to its
25613default value of 10.
25614
8e04817f 25615@end table
104c1213 25616
1e698235 25617@node ABI
79a6e687 25618@section Configuring the Current ABI
1e698235
DJ
25619
25620@value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
25621application automatically. However, sometimes you need to override its
25622conclusions. Use these commands to manage @value{GDBN}'s view of the
25623current ABI.
25624
98b45e30
DJ
25625@cindex OS ABI
25626@kindex set osabi
b4e9345d 25627@kindex show osabi
430ed3f0 25628@cindex Newlib OS ABI and its influence on the longjmp handling
98b45e30
DJ
25629
25630One @value{GDBN} configuration can debug binaries for multiple operating
b383017d 25631system targets, either via remote debugging or native emulation.
98b45e30
DJ
25632@value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
25633but you can override its conclusion using the @code{set osabi} command.
25634One example where this is useful is in debugging of binaries which use
25635an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
25636not have the same identifying marks that the standard C library for your
25637platform provides.
25638
430ed3f0
MS
25639When @value{GDBN} is debugging the AArch64 architecture, it provides a
25640``Newlib'' OS ABI. This is useful for handling @code{setjmp} and
25641@code{longjmp} when debugging binaries that use the @sc{newlib} C library.
25642The ``Newlib'' OS ABI can be selected by @code{set osabi Newlib}.
25643
98b45e30
DJ
25644@table @code
25645@item show osabi
25646Show the OS ABI currently in use.
25647
25648@item set osabi
25649With no argument, show the list of registered available OS ABI's.
25650
25651@item set osabi @var{abi}
25652Set the current OS ABI to @var{abi}.
25653@end table
25654
1e698235 25655@cindex float promotion
1e698235
DJ
25656
25657Generally, the way that an argument of type @code{float} is passed to a
25658function depends on whether the function is prototyped. For a prototyped
25659(i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
25660according to the architecture's convention for @code{float}. For unprototyped
25661(i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
25662@code{double} and then passed.
25663
25664Unfortunately, some forms of debug information do not reliably indicate whether
25665a function is prototyped. If @value{GDBN} calls a function that is not marked
25666as prototyped, it consults @kbd{set coerce-float-to-double}.
25667
25668@table @code
a8f24a35 25669@kindex set coerce-float-to-double
1e698235
DJ
25670@item set coerce-float-to-double
25671@itemx set coerce-float-to-double on
25672Arguments of type @code{float} will be promoted to @code{double} when passed
25673to an unprototyped function. This is the default setting.
25674
25675@item set coerce-float-to-double off
25676Arguments of type @code{float} will be passed directly to unprototyped
25677functions.
9c16f35a
EZ
25678
25679@kindex show coerce-float-to-double
25680@item show coerce-float-to-double
25681Show the current setting of promoting @code{float} to @code{double}.
1e698235
DJ
25682@end table
25683
f1212245
DJ
25684@kindex set cp-abi
25685@kindex show cp-abi
25686@value{GDBN} needs to know the ABI used for your program's C@t{++}
25687objects. The correct C@t{++} ABI depends on which C@t{++} compiler was
25688used to build your application. @value{GDBN} only fully supports
25689programs with a single C@t{++} ABI; if your program contains code using
25690multiple C@t{++} ABI's or if @value{GDBN} can not identify your
25691program's ABI correctly, you can tell @value{GDBN} which ABI to use.
25692Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
25693before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
25694``hpaCC'' for the HP ANSI C@t{++} compiler. Other C@t{++} compilers may
25695use the ``gnu-v2'' or ``gnu-v3'' ABI's as well. The default setting is
25696``auto''.
25697
25698@table @code
25699@item show cp-abi
25700Show the C@t{++} ABI currently in use.
25701
25702@item set cp-abi
25703With no argument, show the list of supported C@t{++} ABI's.
25704
25705@item set cp-abi @var{abi}
25706@itemx set cp-abi auto
25707Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
25708@end table
25709
bf88dd68
JK
25710@node Auto-loading
25711@section Automatically loading associated files
25712@cindex auto-loading
25713
25714@value{GDBN} sometimes reads files with commands and settings automatically,
25715without being explicitly told so by the user. We call this feature
25716@dfn{auto-loading}. While auto-loading is useful for automatically adapting
25717@value{GDBN} to the needs of your project, it can sometimes produce unexpected
25718results or introduce security risks (e.g., if the file comes from untrusted
25719sources).
25720
71b8c845
DE
25721@menu
25722* Init File in the Current Directory:: @samp{set/show/info auto-load local-gdbinit}
25723* libthread_db.so.1 file:: @samp{set/show/info auto-load libthread-db}
25724
25725* Auto-loading safe path:: @samp{set/show/info auto-load safe-path}
25726* Auto-loading verbose mode:: @samp{set/show debug auto-load}
25727@end menu
25728
25729There are various kinds of files @value{GDBN} can automatically load.
25730In addition to these files, @value{GDBN} supports auto-loading code written
25731in various extension languages. @xref{Auto-loading extensions}.
25732
c1668e4e
JK
25733Note that loading of these associated files (including the local @file{.gdbinit}
25734file) requires accordingly configured @code{auto-load safe-path}
25735(@pxref{Auto-loading safe path}).
25736
bf88dd68
JK
25737For these reasons, @value{GDBN} includes commands and options to let you
25738control when to auto-load files and which files should be auto-loaded.
25739
25740@table @code
25741@anchor{set auto-load off}
25742@kindex set auto-load off
25743@item set auto-load off
25744Globally disable loading of all auto-loaded files.
25745You may want to use this command with the @samp{-iex} option
25746(@pxref{Option -init-eval-command}) such as:
25747@smallexample
25748$ @kbd{gdb -iex "set auto-load off" untrusted-executable corefile}
25749@end smallexample
25750
25751Be aware that system init file (@pxref{System-wide configuration})
25752and init files from your home directory (@pxref{Home Directory Init File})
25753still get read (as they come from generally trusted directories).
25754To prevent @value{GDBN} from auto-loading even those init files, use the
25755@option{-nx} option (@pxref{Mode Options}), in addition to
25756@code{set auto-load no}.
25757
25758@anchor{show auto-load}
25759@kindex show auto-load
25760@item show auto-load
25761Show whether auto-loading of each specific @samp{auto-load} file(s) is enabled
25762or disabled.
25763
25764@smallexample
25765(gdb) show auto-load
25766gdb-scripts: Auto-loading of canned sequences of commands scripts is on.
25767libthread-db: Auto-loading of inferior specific libthread_db is on.
1ccacbcd
JK
25768local-gdbinit: Auto-loading of .gdbinit script from current directory
25769 is on.
bf88dd68 25770python-scripts: Auto-loading of Python scripts is on.
bccbefd2 25771safe-path: List of directories from which it is safe to auto-load files
1564a261 25772 is $debugdir:$datadir/auto-load.
7349ff92 25773scripts-directory: List of directories from which to load auto-loaded scripts
1564a261 25774 is $debugdir:$datadir/auto-load.
bf88dd68
JK
25775@end smallexample
25776
25777@anchor{info auto-load}
25778@kindex info auto-load
25779@item info auto-load
25780Print whether each specific @samp{auto-load} file(s) have been auto-loaded or
25781not.
25782
25783@smallexample
25784(gdb) info auto-load
25785gdb-scripts:
25786Loaded Script
25787Yes /home/user/gdb/gdb-gdb.gdb
25788libthread-db: No auto-loaded libthread-db.
1ccacbcd
JK
25789local-gdbinit: Local .gdbinit file "/home/user/gdb/.gdbinit" has been
25790 loaded.
bf88dd68
JK
25791python-scripts:
25792Loaded Script
25793Yes /home/user/gdb/gdb-gdb.py
25794@end smallexample
25795@end table
25796
bf88dd68
JK
25797These are @value{GDBN} control commands for the auto-loading:
25798
25799@multitable @columnfractions .5 .5
25800@item @xref{set auto-load off}.
25801@tab Disable auto-loading globally.
25802@item @xref{show auto-load}.
25803@tab Show setting of all kinds of files.
25804@item @xref{info auto-load}.
25805@tab Show state of all kinds of files.
25806@item @xref{set auto-load gdb-scripts}.
25807@tab Control for @value{GDBN} command scripts.
25808@item @xref{show auto-load gdb-scripts}.
25809@tab Show setting of @value{GDBN} command scripts.
25810@item @xref{info auto-load gdb-scripts}.
25811@tab Show state of @value{GDBN} command scripts.
25812@item @xref{set auto-load python-scripts}.
25813@tab Control for @value{GDBN} Python scripts.
25814@item @xref{show auto-load python-scripts}.
25815@tab Show setting of @value{GDBN} Python scripts.
25816@item @xref{info auto-load python-scripts}.
25817@tab Show state of @value{GDBN} Python scripts.
ed3ef339
DE
25818@item @xref{set auto-load guile-scripts}.
25819@tab Control for @value{GDBN} Guile scripts.
25820@item @xref{show auto-load guile-scripts}.
25821@tab Show setting of @value{GDBN} Guile scripts.
25822@item @xref{info auto-load guile-scripts}.
25823@tab Show state of @value{GDBN} Guile scripts.
7349ff92
JK
25824@item @xref{set auto-load scripts-directory}.
25825@tab Control for @value{GDBN} auto-loaded scripts location.
25826@item @xref{show auto-load scripts-directory}.
25827@tab Show @value{GDBN} auto-loaded scripts location.
f10c5b19
JK
25828@item @xref{add-auto-load-scripts-directory}.
25829@tab Add directory for auto-loaded scripts location list.
bf88dd68
JK
25830@item @xref{set auto-load local-gdbinit}.
25831@tab Control for init file in the current directory.
25832@item @xref{show auto-load local-gdbinit}.
25833@tab Show setting of init file in the current directory.
25834@item @xref{info auto-load local-gdbinit}.
25835@tab Show state of init file in the current directory.
25836@item @xref{set auto-load libthread-db}.
25837@tab Control for thread debugging library.
25838@item @xref{show auto-load libthread-db}.
25839@tab Show setting of thread debugging library.
25840@item @xref{info auto-load libthread-db}.
25841@tab Show state of thread debugging library.
bccbefd2
JK
25842@item @xref{set auto-load safe-path}.
25843@tab Control directories trusted for automatic loading.
25844@item @xref{show auto-load safe-path}.
25845@tab Show directories trusted for automatic loading.
25846@item @xref{add-auto-load-safe-path}.
25847@tab Add directory trusted for automatic loading.
bf88dd68
JK
25848@end multitable
25849
bf88dd68
JK
25850@node Init File in the Current Directory
25851@subsection Automatically loading init file in the current directory
25852@cindex auto-loading init file in the current directory
25853
25854By default, @value{GDBN} reads and executes the canned sequences of commands
25855from init file (if any) in the current working directory,
25856see @ref{Init File in the Current Directory during Startup}.
25857
c1668e4e
JK
25858Note that loading of this local @file{.gdbinit} file also requires accordingly
25859configured @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
25860
bf88dd68
JK
25861@table @code
25862@anchor{set auto-load local-gdbinit}
25863@kindex set auto-load local-gdbinit
25864@item set auto-load local-gdbinit [on|off]
25865Enable or disable the auto-loading of canned sequences of commands
25866(@pxref{Sequences}) found in init file in the current directory.
25867
25868@anchor{show auto-load local-gdbinit}
25869@kindex show auto-load local-gdbinit
25870@item show auto-load local-gdbinit
25871Show whether auto-loading of canned sequences of commands from init file in the
25872current directory is enabled or disabled.
25873
25874@anchor{info auto-load local-gdbinit}
25875@kindex info auto-load local-gdbinit
25876@item info auto-load local-gdbinit
25877Print whether canned sequences of commands from init file in the
25878current directory have been auto-loaded.
25879@end table
25880
25881@node libthread_db.so.1 file
25882@subsection Automatically loading thread debugging library
25883@cindex auto-loading libthread_db.so.1
25884
25885This feature is currently present only on @sc{gnu}/Linux native hosts.
25886
25887@value{GDBN} reads in some cases thread debugging library from places specific
25888to the inferior (@pxref{set libthread-db-search-path}).
25889
25890The special @samp{libthread-db-search-path} entry @samp{$sdir} is processed
25891without checking this @samp{set auto-load libthread-db} switch as system
25892libraries have to be trusted in general. In all other cases of
25893@samp{libthread-db-search-path} entries @value{GDBN} checks first if @samp{set
25894auto-load libthread-db} is enabled before trying to open such thread debugging
25895library.
25896
c1668e4e
JK
25897Note that loading of this debugging library also requires accordingly configured
25898@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
25899
bf88dd68
JK
25900@table @code
25901@anchor{set auto-load libthread-db}
25902@kindex set auto-load libthread-db
25903@item set auto-load libthread-db [on|off]
25904Enable or disable the auto-loading of inferior specific thread debugging library.
25905
25906@anchor{show auto-load libthread-db}
25907@kindex show auto-load libthread-db
25908@item show auto-load libthread-db
25909Show whether auto-loading of inferior specific thread debugging library is
25910enabled or disabled.
25911
25912@anchor{info auto-load libthread-db}
25913@kindex info auto-load libthread-db
25914@item info auto-load libthread-db
25915Print the list of all loaded inferior specific thread debugging libraries and
25916for each such library print list of inferior @var{pid}s using it.
25917@end table
25918
bccbefd2
JK
25919@node Auto-loading safe path
25920@subsection Security restriction for auto-loading
25921@cindex auto-loading safe-path
25922
25923As the files of inferior can come from untrusted source (such as submitted by
25924an application user) @value{GDBN} does not always load any files automatically.
25925@value{GDBN} provides the @samp{set auto-load safe-path} setting to list
25926directories trusted for loading files not explicitly requested by user.
202cbf1c 25927Each directory can also be a shell wildcard pattern.
bccbefd2
JK
25928
25929If the path is not set properly you will see a warning and the file will not
25930get loaded:
25931
25932@smallexample
25933$ ./gdb -q ./gdb
25934Reading symbols from /home/user/gdb/gdb...done.
25935warning: File "/home/user/gdb/gdb-gdb.gdb" auto-loading has been
1564a261
JK
25936 declined by your `auto-load safe-path' set
25937 to "$debugdir:$datadir/auto-load".
bccbefd2 25938warning: File "/home/user/gdb/gdb-gdb.py" auto-loading has been
1564a261
JK
25939 declined by your `auto-load safe-path' set
25940 to "$debugdir:$datadir/auto-load".
bccbefd2
JK
25941@end smallexample
25942
2c91021c
JK
25943@noindent
25944To instruct @value{GDBN} to go ahead and use the init files anyway,
25945invoke @value{GDBN} like this:
25946
25947@smallexample
25948$ gdb -q -iex "set auto-load safe-path /home/user/gdb" ./gdb
25949@end smallexample
25950
bccbefd2
JK
25951The list of trusted directories is controlled by the following commands:
25952
25953@table @code
25954@anchor{set auto-load safe-path}
25955@kindex set auto-load safe-path
af2c1515 25956@item set auto-load safe-path @r{[}@var{directories}@r{]}
bccbefd2
JK
25957Set the list of directories (and their subdirectories) trusted for automatic
25958loading and execution of scripts. You can also enter a specific trusted file.
202cbf1c
JK
25959Each directory can also be a shell wildcard pattern; wildcards do not match
25960directory separator - see @code{FNM_PATHNAME} for system function @code{fnmatch}
25961(@pxref{Wildcard Matching, fnmatch, , libc, GNU C Library Reference Manual}).
af2c1515
JK
25962If you omit @var{directories}, @samp{auto-load safe-path} will be reset to
25963its default value as specified during @value{GDBN} compilation.
25964
d9242c17 25965The list of directories uses path separator (@samp{:} on GNU and Unix
bccbefd2
JK
25966systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
25967to the @env{PATH} environment variable.
25968
25969@anchor{show auto-load safe-path}
25970@kindex show auto-load safe-path
25971@item show auto-load safe-path
25972Show the list of directories trusted for automatic loading and execution of
25973scripts.
25974
25975@anchor{add-auto-load-safe-path}
25976@kindex add-auto-load-safe-path
25977@item add-auto-load-safe-path
413b59ae
JK
25978Add an entry (or list of entries) to the list of directories trusted for
25979automatic loading and execution of scripts. Multiple entries may be delimited
25980by the host platform path separator in use.
bccbefd2
JK
25981@end table
25982
7349ff92 25983This variable defaults to what @code{--with-auto-load-dir} has been configured
1564a261
JK
25984to (@pxref{with-auto-load-dir}). @file{$debugdir} and @file{$datadir}
25985substitution applies the same as for @ref{set auto-load scripts-directory}.
25986The default @code{set auto-load safe-path} value can be also overriden by
25987@value{GDBN} configuration option @option{--with-auto-load-safe-path}.
6dea1fbd 25988
6dea1fbd
JK
25989Setting this variable to @file{/} disables this security protection,
25990corresponding @value{GDBN} configuration option is
25991@option{--without-auto-load-safe-path}.
bccbefd2
JK
25992This variable is supposed to be set to the system directories writable by the
25993system superuser only. Users can add their source directories in init files in
25994their home directories (@pxref{Home Directory Init File}). See also deprecated
25995init file in the current directory
25996(@pxref{Init File in the Current Directory during Startup}).
25997
25998To force @value{GDBN} to load the files it declined to load in the previous
25999example, you could use one of the following ways:
26000
0511cc75
JK
26001@table @asis
26002@item @file{~/.gdbinit}: @samp{add-auto-load-safe-path ~/src/gdb}
bccbefd2
JK
26003Specify this trusted directory (or a file) as additional component of the list.
26004You have to specify also any existing directories displayed by
26005by @samp{show auto-load safe-path} (such as @samp{/usr:/bin} in this example).
26006
174bb630 26007@item @kbd{gdb -iex "set auto-load safe-path /usr:/bin:~/src/gdb" @dots{}}
bccbefd2
JK
26008Specify this directory as in the previous case but just for a single
26009@value{GDBN} session.
26010
af2c1515 26011@item @kbd{gdb -iex "set auto-load safe-path /" @dots{}}
bccbefd2
JK
26012Disable auto-loading safety for a single @value{GDBN} session.
26013This assumes all the files you debug during this @value{GDBN} session will come
26014from trusted sources.
26015
26016@item @kbd{./configure --without-auto-load-safe-path}
26017During compilation of @value{GDBN} you may disable any auto-loading safety.
26018This assumes all the files you will ever debug with this @value{GDBN} come from
26019trusted sources.
0511cc75 26020@end table
bccbefd2
JK
26021
26022On the other hand you can also explicitly forbid automatic files loading which
26023also suppresses any such warning messages:
26024
0511cc75 26025@table @asis
174bb630 26026@item @kbd{gdb -iex "set auto-load no" @dots{}}
bccbefd2
JK
26027You can use @value{GDBN} command-line option for a single @value{GDBN} session.
26028
0511cc75 26029@item @file{~/.gdbinit}: @samp{set auto-load no}
bccbefd2
JK
26030Disable auto-loading globally for the user
26031(@pxref{Home Directory Init File}). While it is improbable, you could also
26032use system init file instead (@pxref{System-wide configuration}).
0511cc75 26033@end table
bccbefd2
JK
26034
26035This setting applies to the file names as entered by user. If no entry matches
26036@value{GDBN} tries as a last resort to also resolve all the file names into
26037their canonical form (typically resolving symbolic links) and compare the
26038entries again. @value{GDBN} already canonicalizes most of the filenames on its
26039own before starting the comparison so a canonical form of directories is
26040recommended to be entered.
26041
4dc84fd1
JK
26042@node Auto-loading verbose mode
26043@subsection Displaying files tried for auto-load
26044@cindex auto-loading verbose mode
26045
26046For better visibility of all the file locations where you can place scripts to
26047be auto-loaded with inferior --- or to protect yourself against accidental
26048execution of untrusted scripts --- @value{GDBN} provides a feature for printing
26049all the files attempted to be loaded. Both existing and non-existing files may
26050be printed.
26051
26052For example the list of directories from which it is safe to auto-load files
26053(@pxref{Auto-loading safe path}) applies also to canonicalized filenames which
26054may not be too obvious while setting it up.
26055
26056@smallexample
0070f25a 26057(gdb) set debug auto-load on
4dc84fd1
JK
26058(gdb) file ~/src/t/true
26059auto-load: Loading canned sequences of commands script "/tmp/true-gdb.gdb"
26060 for objfile "/tmp/true".
26061auto-load: Updating directories of "/usr:/opt".
26062auto-load: Using directory "/usr".
26063auto-load: Using directory "/opt".
26064warning: File "/tmp/true-gdb.gdb" auto-loading has been declined
26065 by your `auto-load safe-path' set to "/usr:/opt".
26066@end smallexample
26067
26068@table @code
26069@anchor{set debug auto-load}
26070@kindex set debug auto-load
26071@item set debug auto-load [on|off]
26072Set whether to print the filenames attempted to be auto-loaded.
26073
26074@anchor{show debug auto-load}
26075@kindex show debug auto-load
26076@item show debug auto-load
26077Show whether printing of the filenames attempted to be auto-loaded is turned
26078on or off.
26079@end table
26080
8e04817f 26081@node Messages/Warnings
79a6e687 26082@section Optional Warnings and Messages
104c1213 26083
9c16f35a
EZ
26084@cindex verbose operation
26085@cindex optional warnings
8e04817f
AC
26086By default, @value{GDBN} is silent about its inner workings. If you are
26087running on a slow machine, you may want to use the @code{set verbose}
26088command. This makes @value{GDBN} tell you when it does a lengthy
26089internal operation, so you will not think it has crashed.
104c1213 26090
8e04817f
AC
26091Currently, the messages controlled by @code{set verbose} are those
26092which announce that the symbol table for a source file is being read;
79a6e687 26093see @code{symbol-file} in @ref{Files, ,Commands to Specify Files}.
104c1213 26094
8e04817f
AC
26095@table @code
26096@kindex set verbose
26097@item set verbose on
26098Enables @value{GDBN} output of certain informational messages.
104c1213 26099
8e04817f
AC
26100@item set verbose off
26101Disables @value{GDBN} output of certain informational messages.
104c1213 26102
8e04817f
AC
26103@kindex show verbose
26104@item show verbose
26105Displays whether @code{set verbose} is on or off.
26106@end table
104c1213 26107
8e04817f
AC
26108By default, if @value{GDBN} encounters bugs in the symbol table of an
26109object file, it is silent; but if you are debugging a compiler, you may
79a6e687
BW
26110find this information useful (@pxref{Symbol Errors, ,Errors Reading
26111Symbol Files}).
104c1213 26112
8e04817f 26113@table @code
104c1213 26114
8e04817f
AC
26115@kindex set complaints
26116@item set complaints @var{limit}
26117Permits @value{GDBN} to output @var{limit} complaints about each type of
26118unusual symbols before becoming silent about the problem. Set
26119@var{limit} to zero to suppress all complaints; set it to a large number
26120to prevent complaints from being suppressed.
104c1213 26121
8e04817f
AC
26122@kindex show complaints
26123@item show complaints
26124Displays how many symbol complaints @value{GDBN} is permitted to produce.
104c1213 26125
8e04817f 26126@end table
104c1213 26127
d837706a 26128@anchor{confirmation requests}
8e04817f
AC
26129By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
26130lot of stupid questions to confirm certain commands. For example, if
26131you try to run a program which is already running:
104c1213 26132
474c8240 26133@smallexample
8e04817f
AC
26134(@value{GDBP}) run
26135The program being debugged has been started already.
26136Start it from the beginning? (y or n)
474c8240 26137@end smallexample
104c1213 26138
8e04817f
AC
26139If you are willing to unflinchingly face the consequences of your own
26140commands, you can disable this ``feature'':
104c1213 26141
8e04817f 26142@table @code
104c1213 26143
8e04817f
AC
26144@kindex set confirm
26145@cindex flinching
26146@cindex confirmation
26147@cindex stupid questions
26148@item set confirm off
7c953934
TT
26149Disables confirmation requests. Note that running @value{GDBN} with
26150the @option{--batch} option (@pxref{Mode Options, -batch}) also
26151automatically disables confirmation requests.
104c1213 26152
8e04817f
AC
26153@item set confirm on
26154Enables confirmation requests (the default).
104c1213 26155
8e04817f
AC
26156@kindex show confirm
26157@item show confirm
26158Displays state of confirmation requests.
26159
26160@end table
104c1213 26161
16026cd7
AS
26162@cindex command tracing
26163If you need to debug user-defined commands or sourced files you may find it
26164useful to enable @dfn{command tracing}. In this mode each command will be
26165printed as it is executed, prefixed with one or more @samp{+} symbols, the
26166quantity denoting the call depth of each command.
26167
26168@table @code
26169@kindex set trace-commands
26170@cindex command scripts, debugging
26171@item set trace-commands on
26172Enable command tracing.
26173@item set trace-commands off
26174Disable command tracing.
26175@item show trace-commands
26176Display the current state of command tracing.
26177@end table
26178
8e04817f 26179@node Debugging Output
79a6e687 26180@section Optional Messages about Internal Happenings
4644b6e3
EZ
26181@cindex optional debugging messages
26182
da316a69
EZ
26183@value{GDBN} has commands that enable optional debugging messages from
26184various @value{GDBN} subsystems; normally these commands are of
26185interest to @value{GDBN} maintainers, or when reporting a bug. This
26186section documents those commands.
26187
104c1213 26188@table @code
a8f24a35
EZ
26189@kindex set exec-done-display
26190@item set exec-done-display
26191Turns on or off the notification of asynchronous commands'
26192completion. When on, @value{GDBN} will print a message when an
26193asynchronous command finishes its execution. The default is off.
26194@kindex show exec-done-display
26195@item show exec-done-display
26196Displays the current setting of asynchronous command completion
26197notification.
4644b6e3 26198@kindex set debug
be9a8770
PA
26199@cindex ARM AArch64
26200@item set debug aarch64
26201Turns on or off display of debugging messages related to ARM AArch64.
26202The default is off.
26203@kindex show debug
26204@item show debug aarch64
26205Displays the current state of displaying debugging messages related to
26206ARM AArch64.
4644b6e3 26207@cindex gdbarch debugging info
a8f24a35 26208@cindex architecture debugging info
8e04817f 26209@item set debug arch
a8f24a35 26210Turns on or off display of gdbarch debugging info. The default is off
8e04817f
AC
26211@item show debug arch
26212Displays the current state of displaying gdbarch debugging info.
9a005eb9
JB
26213@item set debug aix-solib
26214@cindex AIX shared library debugging
26215Control display of debugging messages from the AIX shared library
26216support module. The default is off.
26217@item show debug aix-thread
26218Show the current state of displaying AIX shared library debugging messages.
721c2651
EZ
26219@item set debug aix-thread
26220@cindex AIX threads
26221Display debugging messages about inner workings of the AIX thread
26222module.
26223@item show debug aix-thread
26224Show the current state of AIX thread debugging info display.
900e11f9
JK
26225@item set debug check-physname
26226@cindex physname
26227Check the results of the ``physname'' computation. When reading DWARF
26228debugging information for C@t{++}, @value{GDBN} attempts to compute
26229each entity's name. @value{GDBN} can do this computation in two
26230different ways, depending on exactly what information is present.
26231When enabled, this setting causes @value{GDBN} to compute the names
26232both ways and display any discrepancies.
26233@item show debug check-physname
26234Show the current state of ``physname'' checking.
be9a8770
PA
26235@item set debug coff-pe-read
26236@cindex COFF/PE exported symbols
26237Control display of debugging messages related to reading of COFF/PE
26238exported symbols. The default is off.
26239@item show debug coff-pe-read
26240Displays the current state of displaying debugging messages related to
26241reading of COFF/PE exported symbols.
b4f54984
DE
26242@item set debug dwarf-die
26243@cindex DWARF DIEs
26244Dump DWARF DIEs after they are read in.
d97bc12b
DE
26245The value is the number of nesting levels to print.
26246A value of zero turns off the display.
b4f54984
DE
26247@item show debug dwarf-die
26248Show the current state of DWARF DIE debugging.
27e0867f
DE
26249@item set debug dwarf-line
26250@cindex DWARF Line Tables
26251Turns on or off display of debugging messages related to reading
26252DWARF line tables. The default is 0 (off).
26253A value of 1 provides basic information.
26254A value greater than 1 provides more verbose information.
26255@item show debug dwarf-line
26256Show the current state of DWARF line table debugging.
b4f54984
DE
26257@item set debug dwarf-read
26258@cindex DWARF Reading
45cfd468 26259Turns on or off display of debugging messages related to reading
73be47f5
DE
26260DWARF debug info. The default is 0 (off).
26261A value of 1 provides basic information.
26262A value greater than 1 provides more verbose information.
b4f54984
DE
26263@item show debug dwarf-read
26264Show the current state of DWARF reader debugging.
237fc4c9
PA
26265@item set debug displaced
26266@cindex displaced stepping debugging info
26267Turns on or off display of @value{GDBN} debugging info for the
26268displaced stepping support. The default is off.
26269@item show debug displaced
26270Displays the current state of displaying @value{GDBN} debugging info
26271related to displaced stepping.
8e04817f 26272@item set debug event
4644b6e3 26273@cindex event debugging info
a8f24a35 26274Turns on or off display of @value{GDBN} event debugging info. The
8e04817f 26275default is off.
8e04817f
AC
26276@item show debug event
26277Displays the current state of displaying @value{GDBN} event debugging
26278info.
8e04817f 26279@item set debug expression
4644b6e3 26280@cindex expression debugging info
721c2651
EZ
26281Turns on or off display of debugging info about @value{GDBN}
26282expression parsing. The default is off.
8e04817f 26283@item show debug expression
721c2651
EZ
26284Displays the current state of displaying debugging info about
26285@value{GDBN} expression parsing.
6e9567fe
JB
26286@item set debug fbsd-lwp
26287@cindex FreeBSD LWP debug messages
26288Turns on or off debugging messages from the FreeBSD LWP debug support.
26289@item show debug fbsd-lwp
26290Show the current state of FreeBSD LWP debugging messages.
386a8676
JB
26291@item set debug fbsd-nat
26292@cindex FreeBSD native target debug messages
26293Turns on or off debugging messages from the FreeBSD native target.
26294@item show debug fbsd-nat
26295Show the current state of FreeBSD native target debugging messages.
7453dc06 26296@item set debug frame
4644b6e3 26297@cindex frame debugging info
7453dc06
AC
26298Turns on or off display of @value{GDBN} frame debugging info. The
26299default is off.
7453dc06
AC
26300@item show debug frame
26301Displays the current state of displaying @value{GDBN} frame debugging
26302info.
cbe54154
PA
26303@item set debug gnu-nat
26304@cindex @sc{gnu}/Hurd debug messages
67ebd9cb 26305Turn on or off debugging messages from the @sc{gnu}/Hurd debug support.
cbe54154
PA
26306@item show debug gnu-nat
26307Show the current state of @sc{gnu}/Hurd debugging messages.
30e91e0b
RC
26308@item set debug infrun
26309@cindex inferior debugging info
26310Turns on or off display of @value{GDBN} debugging info for running the inferior.
26311The default is off. @file{infrun.c} contains GDB's runtime state machine used
26312for implementing operations such as single-stepping the inferior.
26313@item show debug infrun
26314Displays the current state of @value{GDBN} inferior debugging.
a255712f
PP
26315@item set debug jit
26316@cindex just-in-time compilation, debugging messages
67ebd9cb 26317Turn on or off debugging messages from JIT debug support.
a255712f
PP
26318@item show debug jit
26319Displays the current state of @value{GDBN} JIT debugging.
da316a69
EZ
26320@item set debug lin-lwp
26321@cindex @sc{gnu}/Linux LWP debug messages
26322@cindex Linux lightweight processes
67ebd9cb 26323Turn on or off debugging messages from the Linux LWP debug support.
da316a69
EZ
26324@item show debug lin-lwp
26325Show the current state of Linux LWP debugging messages.
7a6a1731
GB
26326@item set debug linux-namespaces
26327@cindex @sc{gnu}/Linux namespaces debug messages
67ebd9cb 26328Turn on or off debugging messages from the Linux namespaces debug support.
7a6a1731
GB
26329@item show debug linux-namespaces
26330Show the current state of Linux namespaces debugging messages.
be9a8770
PA
26331@item set debug mach-o
26332@cindex Mach-O symbols processing
26333Control display of debugging messages related to Mach-O symbols
26334processing. The default is off.
26335@item show debug mach-o
26336Displays the current state of displaying debugging messages related to
26337reading of COFF/PE exported symbols.
c9b6281a
YQ
26338@item set debug notification
26339@cindex remote async notification debugging info
67ebd9cb 26340Turn on or off debugging messages about remote async notification.
c9b6281a
YQ
26341The default is off.
26342@item show debug notification
26343Displays the current state of remote async notification debugging messages.
2b4855ab 26344@item set debug observer
4644b6e3 26345@cindex observer debugging info
2b4855ab
AC
26346Turns on or off display of @value{GDBN} observer debugging. This
26347includes info such as the notification of observable events.
2b4855ab
AC
26348@item show debug observer
26349Displays the current state of observer debugging.
8e04817f 26350@item set debug overload
4644b6e3 26351@cindex C@t{++} overload debugging info
8e04817f 26352Turns on or off display of @value{GDBN} C@t{++} overload debugging
359df76b 26353info. This includes info such as ranking of functions, etc. The default
8e04817f 26354is off.
8e04817f
AC
26355@item show debug overload
26356Displays the current state of displaying @value{GDBN} C@t{++} overload
26357debugging info.
92981e24
TT
26358@cindex expression parser, debugging info
26359@cindex debug expression parser
26360@item set debug parser
26361Turns on or off the display of expression parser debugging output.
26362Internally, this sets the @code{yydebug} variable in the expression
26363parser. @xref{Tracing, , Tracing Your Parser, bison, Bison}, for
26364details. The default is off.
26365@item show debug parser
26366Show the current state of expression parser debugging.
8e04817f
AC
26367@cindex packets, reporting on stdout
26368@cindex serial connections, debugging
605a56cb
DJ
26369@cindex debug remote protocol
26370@cindex remote protocol debugging
26371@cindex display remote packets
8e04817f
AC
26372@item set debug remote
26373Turns on or off display of reports on all packets sent back and forth across
26374the serial line to the remote machine. The info is printed on the
26375@value{GDBN} standard output stream. The default is off.
8e04817f
AC
26376@item show debug remote
26377Displays the state of display of remote packets.
c4dcb155 26378
6cc8564b
LM
26379@item set debug remote-packet-max-chars
26380Sets the maximum number of characters to display for each remote packet when
26381@code{set debug remote} is on. This is useful to prevent @value{GDBN} from
26382displaying lengthy remote packets and polluting the console.
26383
26384The default value is @code{512}, which means @value{GDBN} will truncate each
26385remote packet after 512 bytes.
26386
26387Setting this option to @code{unlimited} will disable truncation and will output
26388the full length of the remote packets.
26389@item show debug remote-packet-max-chars
26390Displays the number of bytes to output for remote packet debugging.
26391
c4dcb155
SM
26392@item set debug separate-debug-file
26393Turns on or off display of debug output about separate debug file search.
26394@item show debug separate-debug-file
26395Displays the state of separate debug file search debug output.
26396
8e04817f
AC
26397@item set debug serial
26398Turns on or off display of @value{GDBN} serial debugging info. The
26399default is off.
8e04817f
AC
26400@item show debug serial
26401Displays the current state of displaying @value{GDBN} serial debugging
26402info.
c45da7e6
EZ
26403@item set debug solib-frv
26404@cindex FR-V shared-library debugging
67ebd9cb 26405Turn on or off debugging messages for FR-V shared-library code.
c45da7e6
EZ
26406@item show debug solib-frv
26407Display the current state of FR-V shared-library code debugging
26408messages.
cc485e62
DE
26409@item set debug symbol-lookup
26410@cindex symbol lookup
26411Turns on or off display of debugging messages related to symbol lookup.
26412The default is 0 (off).
26413A value of 1 provides basic information.
26414A value greater than 1 provides more verbose information.
26415@item show debug symbol-lookup
26416Show the current state of symbol lookup debugging messages.
8fb8eb5c
DE
26417@item set debug symfile
26418@cindex symbol file functions
26419Turns on or off display of debugging messages related to symbol file functions.
26420The default is off. @xref{Files}.
26421@item show debug symfile
26422Show the current state of symbol file debugging messages.
45cfd468
DE
26423@item set debug symtab-create
26424@cindex symbol table creation
26425Turns on or off display of debugging messages related to symbol table creation.
db0fec5c
DE
26426The default is 0 (off).
26427A value of 1 provides basic information.
26428A value greater than 1 provides more verbose information.
45cfd468
DE
26429@item show debug symtab-create
26430Show the current state of symbol table creation debugging.
8e04817f 26431@item set debug target
4644b6e3 26432@cindex target debugging info
8e04817f
AC
26433Turns on or off display of @value{GDBN} target debugging info. This info
26434includes what is going on at the target level of GDB, as it happens. The
701b08bb 26435default is 0. Set it to 1 to track events, and to 2 to also track the
3cecbbbe 26436value of large memory transfers.
8e04817f
AC
26437@item show debug target
26438Displays the current state of displaying @value{GDBN} target debugging
26439info.
75feb17d 26440@item set debug timestamp
6b92c0d3 26441@cindex timestamping debugging info
75feb17d
DJ
26442Turns on or off display of timestamps with @value{GDBN} debugging info.
26443When enabled, seconds and microseconds are displayed before each debugging
26444message.
26445@item show debug timestamp
26446Displays the current state of displaying timestamps with @value{GDBN}
26447debugging info.
f989a1c8 26448@item set debug varobj
4644b6e3 26449@cindex variable object debugging info
8e04817f
AC
26450Turns on or off display of @value{GDBN} variable object debugging
26451info. The default is off.
f989a1c8 26452@item show debug varobj
8e04817f
AC
26453Displays the current state of displaying @value{GDBN} variable object
26454debugging info.
e776119f
DJ
26455@item set debug xml
26456@cindex XML parser debugging
67ebd9cb 26457Turn on or off debugging messages for built-in XML parsers.
e776119f
DJ
26458@item show debug xml
26459Displays the current state of XML debugging messages.
8e04817f 26460@end table
104c1213 26461
14fb1bac
JB
26462@node Other Misc Settings
26463@section Other Miscellaneous Settings
26464@cindex miscellaneous settings
26465
26466@table @code
26467@kindex set interactive-mode
26468@item set interactive-mode
7bfc9434
JB
26469If @code{on}, forces @value{GDBN} to assume that GDB was started
26470in a terminal. In practice, this means that @value{GDBN} should wait
26471for the user to answer queries generated by commands entered at
26472the command prompt. If @code{off}, forces @value{GDBN} to operate
26473in the opposite mode, and it uses the default answers to all queries.
26474If @code{auto} (the default), @value{GDBN} tries to determine whether
26475its standard input is a terminal, and works in interactive-mode if it
26476is, non-interactively otherwise.
14fb1bac
JB
26477
26478In the vast majority of cases, the debugger should be able to guess
26479correctly which mode should be used. But this setting can be useful
26480in certain specific cases, such as running a MinGW @value{GDBN}
26481inside a cygwin window.
26482
26483@kindex show interactive-mode
26484@item show interactive-mode
26485Displays whether the debugger is operating in interactive mode or not.
26486@end table
26487
d57a3c85
TJB
26488@node Extending GDB
26489@chapter Extending @value{GDBN}
26490@cindex extending GDB
26491
71b8c845
DE
26492@value{GDBN} provides several mechanisms for extension.
26493@value{GDBN} also provides the ability to automatically load
26494extensions when it reads a file for debugging. This allows the
26495user to automatically customize @value{GDBN} for the program
26496being debugged.
d57a3c85 26497
71b8c845
DE
26498@menu
26499* Sequences:: Canned Sequences of @value{GDBN} Commands
26500* Python:: Extending @value{GDBN} using Python
ed3ef339 26501* Guile:: Extending @value{GDBN} using Guile
71b8c845 26502* Auto-loading extensions:: Automatically loading extensions
ed3ef339 26503* Multiple Extension Languages:: Working with multiple extension languages
71b8c845
DE
26504* Aliases:: Creating new spellings of existing commands
26505@end menu
26506
26507To facilitate the use of extension languages, @value{GDBN} is capable
95433b34 26508of evaluating the contents of a file. When doing so, @value{GDBN}
71b8c845 26509can recognize which extension language is being used by looking at
95433b34
JB
26510the filename extension. Files with an unrecognized filename extension
26511are always treated as a @value{GDBN} Command Files.
26512@xref{Command Files,, Command files}.
26513
26514You can control how @value{GDBN} evaluates these files with the following
26515setting:
26516
26517@table @code
26518@kindex set script-extension
26519@kindex show script-extension
26520@item set script-extension off
26521All scripts are always evaluated as @value{GDBN} Command Files.
26522
26523@item set script-extension soft
26524The debugger determines the scripting language based on filename
26525extension. If this scripting language is supported, @value{GDBN}
26526evaluates the script using that language. Otherwise, it evaluates
26527the file as a @value{GDBN} Command File.
26528
26529@item set script-extension strict
26530The debugger determines the scripting language based on filename
26531extension, and evaluates the script using that language. If the
26532language is not supported, then the evaluation fails.
26533
26534@item show script-extension
26535Display the current value of the @code{script-extension} option.
26536
26537@end table
26538
ed2a2229
CB
26539@ifset SYSTEM_GDBINIT_DIR
26540This setting is not used for files in the system-wide gdbinit directory.
26541Files in that directory must have an extension matching their language,
26542or have a @file{.gdb} extension to be interpreted as regular @value{GDBN}
26543commands. @xref{Startup}.
26544@end ifset
26545
8e04817f 26546@node Sequences
d57a3c85 26547@section Canned Sequences of Commands
104c1213 26548
8e04817f 26549Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
79a6e687 26550Command Lists}), @value{GDBN} provides two ways to store sequences of
8e04817f
AC
26551commands for execution as a unit: user-defined commands and command
26552files.
104c1213 26553
8e04817f 26554@menu
fcc73fe3
EZ
26555* Define:: How to define your own commands
26556* Hooks:: Hooks for user-defined commands
26557* Command Files:: How to write scripts of commands to be stored in a file
26558* Output:: Commands for controlled output
71b8c845 26559* Auto-loading sequences:: Controlling auto-loaded command files
8e04817f 26560@end menu
104c1213 26561
8e04817f 26562@node Define
d57a3c85 26563@subsection User-defined Commands
104c1213 26564
8e04817f 26565@cindex user-defined command
fcc73fe3 26566@cindex arguments, to user-defined commands
8e04817f
AC
26567A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
26568which you assign a new name as a command. This is done with the
df3ee9ca 26569@code{define} command. User commands may accept an unlimited number of arguments
8e04817f 26570separated by whitespace. Arguments are accessed within the user command
df3ee9ca 26571via @code{$arg0@dots{}$argN}. A trivial example:
104c1213 26572
8e04817f
AC
26573@smallexample
26574define adder
26575 print $arg0 + $arg1 + $arg2
c03c782f 26576end
8e04817f 26577@end smallexample
104c1213
JM
26578
26579@noindent
8e04817f 26580To execute the command use:
104c1213 26581
8e04817f
AC
26582@smallexample
26583adder 1 2 3
26584@end smallexample
104c1213 26585
8e04817f
AC
26586@noindent
26587This defines the command @code{adder}, which prints the sum of
26588its three arguments. Note the arguments are text substitutions, so they may
26589reference variables, use complex expressions, or even perform inferior
26590functions calls.
104c1213 26591
fcc73fe3
EZ
26592@cindex argument count in user-defined commands
26593@cindex how many arguments (user-defined commands)
c03c782f 26594In addition, @code{$argc} may be used to find out how many arguments have
df3ee9ca 26595been passed.
c03c782f
AS
26596
26597@smallexample
26598define adder
26599 if $argc == 2
26600 print $arg0 + $arg1
26601 end
26602 if $argc == 3
26603 print $arg0 + $arg1 + $arg2
26604 end
26605end
26606@end smallexample
26607
01770bbd
PA
26608Combining with the @code{eval} command (@pxref{eval}) makes it easier
26609to process a variable number of arguments:
26610
26611@smallexample
26612define adder
26613 set $i = 0
26614 set $sum = 0
26615 while $i < $argc
26616 eval "set $sum = $sum + $arg%d", $i
26617 set $i = $i + 1
26618 end
26619 print $sum
26620end
26621@end smallexample
26622
104c1213 26623@table @code
104c1213 26624
8e04817f
AC
26625@kindex define
26626@item define @var{commandname}
26627Define a command named @var{commandname}. If there is already a command
26628by that name, you are asked to confirm that you want to redefine it.
697aa1b7 26629The argument @var{commandname} may be a bare command name consisting of letters,
bf498525
PW
26630numbers, dashes, dots, and underscores. It may also start with any
26631predefined or user-defined prefix command.
26632For example, @samp{define target my-target} creates
adb483fe 26633a user-defined @samp{target my-target} command.
104c1213 26634
8e04817f
AC
26635The definition of the command is made up of other @value{GDBN} command lines,
26636which are given following the @code{define} command. The end of these
26637commands is marked by a line containing @code{end}.
104c1213 26638
8e04817f 26639@kindex document
ca91424e 26640@kindex end@r{ (user-defined commands)}
8e04817f
AC
26641@item document @var{commandname}
26642Document the user-defined command @var{commandname}, so that it can be
26643accessed by @code{help}. The command @var{commandname} must already be
26644defined. This command reads lines of documentation just as @code{define}
26645reads the lines of the command definition, ending with @code{end}.
26646After the @code{document} command is finished, @code{help} on command
26647@var{commandname} displays the documentation you have written.
104c1213 26648
8e04817f
AC
26649You may use the @code{document} command again to change the
26650documentation of a command. Redefining the command with @code{define}
26651does not change the documentation.
104c1213 26652
bf498525
PW
26653@kindex define-prefix
26654@item define-prefix @var{commandname}
26655Define or mark the command @var{commandname} as a user-defined prefix
26656command. Once marked, @var{commandname} can be used as prefix command
26657by the @code{define} command.
26658Note that @code{define-prefix} can be used with a not yet defined
26659@var{commandname}. In such a case, @var{commandname} is defined as
26660an empty user-defined command.
26661In case you redefine a command that was marked as a user-defined
26662prefix command, the subcommands of the redefined command are kept
26663(and @value{GDBN} indicates so to the user).
26664
26665Example:
26666@example
26667(gdb) define-prefix abc
26668(gdb) define-prefix abc def
26669(gdb) define abc def
26670Type commands for definition of "abc def".
26671End with a line saying just "end".
26672>echo command initial def\n
26673>end
26674(gdb) define abc def ghi
26675Type commands for definition of "abc def ghi".
26676End with a line saying just "end".
26677>echo command ghi\n
26678>end
26679(gdb) define abc def
26680Keeping subcommands of prefix command "def".
26681Redefine command "def"? (y or n) y
26682Type commands for definition of "abc def".
26683End with a line saying just "end".
26684>echo command def\n
26685>end
26686(gdb) abc def ghi
26687command ghi
26688(gdb) abc def
26689command def
26690(gdb)
26691@end example
26692
c45da7e6
EZ
26693@kindex dont-repeat
26694@cindex don't repeat command
26695@item dont-repeat
26696Used inside a user-defined command, this tells @value{GDBN} that this
26697command should not be repeated when the user hits @key{RET}
26698(@pxref{Command Syntax, repeat last command}).
26699
8e04817f
AC
26700@kindex help user-defined
26701@item help user-defined
7d74f244 26702List all user-defined commands and all python commands defined in class
6b92c0d3 26703COMMAND_USER. The first line of the documentation or docstring is
7d74f244 26704included (if any).
104c1213 26705
8e04817f
AC
26706@kindex show user
26707@item show user
26708@itemx show user @var{commandname}
26709Display the @value{GDBN} commands used to define @var{commandname} (but
26710not its documentation). If no @var{commandname} is given, display the
26711definitions for all user-defined commands.
7d74f244 26712This does not work for user-defined python commands.
104c1213 26713
fcc73fe3 26714@cindex infinite recursion in user-defined commands
20f01a46
DH
26715@kindex show max-user-call-depth
26716@kindex set max-user-call-depth
26717@item show max-user-call-depth
5ca0cb28
DH
26718@itemx set max-user-call-depth
26719The value of @code{max-user-call-depth} controls how many recursion
3f94c067 26720levels are allowed in user-defined commands before @value{GDBN} suspects an
5ca0cb28 26721infinite recursion and aborts the command.
7d74f244 26722This does not apply to user-defined python commands.
104c1213
JM
26723@end table
26724
fcc73fe3
EZ
26725In addition to the above commands, user-defined commands frequently
26726use control flow commands, described in @ref{Command Files}.
26727
8e04817f
AC
26728When user-defined commands are executed, the
26729commands of the definition are not printed. An error in any command
26730stops execution of the user-defined command.
104c1213 26731
8e04817f
AC
26732If used interactively, commands that would ask for confirmation proceed
26733without asking when used inside a user-defined command. Many @value{GDBN}
26734commands that normally print messages to say what they are doing omit the
26735messages when used in a user-defined command.
104c1213 26736
8e04817f 26737@node Hooks
d57a3c85 26738@subsection User-defined Command Hooks
8e04817f
AC
26739@cindex command hooks
26740@cindex hooks, for commands
26741@cindex hooks, pre-command
104c1213 26742
8e04817f 26743@kindex hook
8e04817f
AC
26744You may define @dfn{hooks}, which are a special kind of user-defined
26745command. Whenever you run the command @samp{foo}, if the user-defined
26746command @samp{hook-foo} exists, it is executed (with no arguments)
26747before that command.
104c1213 26748
8e04817f
AC
26749@cindex hooks, post-command
26750@kindex hookpost
8e04817f
AC
26751A hook may also be defined which is run after the command you executed.
26752Whenever you run the command @samp{foo}, if the user-defined command
26753@samp{hookpost-foo} exists, it is executed (with no arguments) after
26754that command. Post-execution hooks may exist simultaneously with
26755pre-execution hooks, for the same command.
104c1213 26756
8e04817f 26757It is valid for a hook to call the command which it hooks. If this
9f1c6395 26758occurs, the hook is not re-executed, thereby avoiding infinite recursion.
104c1213 26759
8e04817f
AC
26760@c It would be nice if hookpost could be passed a parameter indicating
26761@c if the command it hooks executed properly or not. FIXME!
104c1213 26762
8e04817f
AC
26763@kindex stop@r{, a pseudo-command}
26764In addition, a pseudo-command, @samp{stop} exists. Defining
26765(@samp{hook-stop}) makes the associated commands execute every time
26766execution stops in your program: before breakpoint commands are run,
26767displays are printed, or the stack frame is printed.
104c1213 26768
8e04817f
AC
26769For example, to ignore @code{SIGALRM} signals while
26770single-stepping, but treat them normally during normal execution,
26771you could define:
104c1213 26772
474c8240 26773@smallexample
8e04817f
AC
26774define hook-stop
26775handle SIGALRM nopass
26776end
104c1213 26777
8e04817f
AC
26778define hook-run
26779handle SIGALRM pass
26780end
104c1213 26781
8e04817f 26782define hook-continue
d3e8051b 26783handle SIGALRM pass
8e04817f 26784end
474c8240 26785@end smallexample
104c1213 26786
d3e8051b 26787As a further example, to hook at the beginning and end of the @code{echo}
b383017d 26788command, and to add extra text to the beginning and end of the message,
8e04817f 26789you could define:
104c1213 26790
474c8240 26791@smallexample
8e04817f
AC
26792define hook-echo
26793echo <<<---
26794end
104c1213 26795
8e04817f
AC
26796define hookpost-echo
26797echo --->>>\n
26798end
104c1213 26799
8e04817f
AC
26800(@value{GDBP}) echo Hello World
26801<<<---Hello World--->>>
26802(@value{GDBP})
104c1213 26803
474c8240 26804@end smallexample
104c1213 26805
8e04817f
AC
26806You can define a hook for any single-word command in @value{GDBN}, but
26807not for command aliases; you should define a hook for the basic command
c1468174 26808name, e.g.@: @code{backtrace} rather than @code{bt}.
8e04817f
AC
26809@c FIXME! So how does Joe User discover whether a command is an alias
26810@c or not?
adb483fe
DJ
26811You can hook a multi-word command by adding @code{hook-} or
26812@code{hookpost-} to the last word of the command, e.g.@:
26813@samp{define target hook-remote} to add a hook to @samp{target remote}.
26814
8e04817f
AC
26815If an error occurs during the execution of your hook, execution of
26816@value{GDBN} commands stops and @value{GDBN} issues a prompt
26817(before the command that you actually typed had a chance to run).
104c1213 26818
8e04817f
AC
26819If you try to define a hook which does not match any known command, you
26820get a warning from the @code{define} command.
c906108c 26821
8e04817f 26822@node Command Files
d57a3c85 26823@subsection Command Files
c906108c 26824
8e04817f 26825@cindex command files
fcc73fe3 26826@cindex scripting commands
6fc08d32
EZ
26827A command file for @value{GDBN} is a text file made of lines that are
26828@value{GDBN} commands. Comments (lines starting with @kbd{#}) may
26829also be included. An empty line in a command file does nothing; it
26830does not mean to repeat the last command, as it would from the
26831terminal.
c906108c 26832
6fc08d32 26833You can request the execution of a command file with the @code{source}
95433b34
JB
26834command. Note that the @code{source} command is also used to evaluate
26835scripts that are not Command Files. The exact behavior can be configured
26836using the @code{script-extension} setting.
26837@xref{Extending GDB,, Extending GDB}.
c906108c 26838
8e04817f
AC
26839@table @code
26840@kindex source
ca91424e 26841@cindex execute commands from a file
3f7b2faa 26842@item source [-s] [-v] @var{filename}
8e04817f 26843Execute the command file @var{filename}.
c906108c
SS
26844@end table
26845
fcc73fe3
EZ
26846The lines in a command file are generally executed sequentially,
26847unless the order of execution is changed by one of the
26848@emph{flow-control commands} described below. The commands are not
a71ec265
DH
26849printed as they are executed. An error in any command terminates
26850execution of the command file and control is returned to the console.
c906108c 26851
08001717
DE
26852@value{GDBN} first searches for @var{filename} in the current directory.
26853If the file is not found there, and @var{filename} does not specify a
26854directory, then @value{GDBN} also looks for the file on the source search path
26855(specified with the @samp{directory} command);
26856except that @file{$cdir} is not searched because the compilation directory
26857is not relevant to scripts.
4b505b12 26858
3f7b2faa
DE
26859If @code{-s} is specified, then @value{GDBN} searches for @var{filename}
26860on the search path even if @var{filename} specifies a directory.
26861The search is done by appending @var{filename} to each element of the
26862search path. So, for example, if @var{filename} is @file{mylib/myscript}
26863and the search path contains @file{/home/user} then @value{GDBN} will
26864look for the script @file{/home/user/mylib/myscript}.
26865The search is also done if @var{filename} is an absolute path.
26866For example, if @var{filename} is @file{/tmp/myscript} and
26867the search path contains @file{/home/user} then @value{GDBN} will
26868look for the script @file{/home/user/tmp/myscript}.
26869For DOS-like systems, if @var{filename} contains a drive specification,
26870it is stripped before concatenation. For example, if @var{filename} is
26871@file{d:myscript} and the search path contains @file{c:/tmp} then @value{GDBN}
26872will look for the script @file{c:/tmp/myscript}.
26873
16026cd7
AS
26874If @code{-v}, for verbose mode, is given then @value{GDBN} displays
26875each command as it is executed. The option must be given before
26876@var{filename}, and is interpreted as part of the filename anywhere else.
26877
8e04817f
AC
26878Commands that would ask for confirmation if used interactively proceed
26879without asking when used in a command file. Many @value{GDBN} commands that
26880normally print messages to say what they are doing omit the messages
26881when called from command files.
c906108c 26882
8e04817f
AC
26883@value{GDBN} also accepts command input from standard input. In this
26884mode, normal output goes to standard output and error output goes to
26885standard error. Errors in a command file supplied on standard input do
6fc08d32 26886not terminate execution of the command file---execution continues with
8e04817f 26887the next command.
c906108c 26888
474c8240 26889@smallexample
8e04817f 26890gdb < cmds > log 2>&1
474c8240 26891@end smallexample
c906108c 26892
8e04817f
AC
26893(The syntax above will vary depending on the shell used.) This example
26894will execute commands from the file @file{cmds}. All output and errors
26895would be directed to @file{log}.
c906108c 26896
fcc73fe3
EZ
26897Since commands stored on command files tend to be more general than
26898commands typed interactively, they frequently need to deal with
26899complicated situations, such as different or unexpected values of
26900variables and symbols, changes in how the program being debugged is
26901built, etc. @value{GDBN} provides a set of flow-control commands to
26902deal with these complexities. Using these commands, you can write
26903complex scripts that loop over data structures, execute commands
26904conditionally, etc.
26905
26906@table @code
26907@kindex if
26908@kindex else
26909@item if
26910@itemx else
26911This command allows to include in your script conditionally executed
26912commands. The @code{if} command takes a single argument, which is an
26913expression to evaluate. It is followed by a series of commands that
26914are executed only if the expression is true (its value is nonzero).
26915There can then optionally be an @code{else} line, followed by a series
26916of commands that are only executed if the expression was false. The
26917end of the list is marked by a line containing @code{end}.
26918
26919@kindex while
26920@item while
26921This command allows to write loops. Its syntax is similar to
26922@code{if}: the command takes a single argument, which is an expression
26923to evaluate, and must be followed by the commands to execute, one per
26924line, terminated by an @code{end}. These commands are called the
26925@dfn{body} of the loop. The commands in the body of @code{while} are
26926executed repeatedly as long as the expression evaluates to true.
26927
26928@kindex loop_break
26929@item loop_break
26930This command exits the @code{while} loop in whose body it is included.
26931Execution of the script continues after that @code{while}s @code{end}
26932line.
26933
26934@kindex loop_continue
26935@item loop_continue
26936This command skips the execution of the rest of the body of commands
26937in the @code{while} loop in whose body it is included. Execution
26938branches to the beginning of the @code{while} loop, where it evaluates
26939the controlling expression.
ca91424e
EZ
26940
26941@kindex end@r{ (if/else/while commands)}
26942@item end
26943Terminate the block of commands that are the body of @code{if},
26944@code{else}, or @code{while} flow-control commands.
fcc73fe3
EZ
26945@end table
26946
26947
8e04817f 26948@node Output
d57a3c85 26949@subsection Commands for Controlled Output
c906108c 26950
8e04817f
AC
26951During the execution of a command file or a user-defined command, normal
26952@value{GDBN} output is suppressed; the only output that appears is what is
26953explicitly printed by the commands in the definition. This section
26954describes three commands useful for generating exactly the output you
26955want.
c906108c
SS
26956
26957@table @code
8e04817f
AC
26958@kindex echo
26959@item echo @var{text}
26960@c I do not consider backslash-space a standard C escape sequence
26961@c because it is not in ANSI.
26962Print @var{text}. Nonprinting characters can be included in
26963@var{text} using C escape sequences, such as @samp{\n} to print a
26964newline. @strong{No newline is printed unless you specify one.}
26965In addition to the standard C escape sequences, a backslash followed
26966by a space stands for a space. This is useful for displaying a
26967string with spaces at the beginning or the end, since leading and
26968trailing spaces are otherwise trimmed from all arguments.
26969To print @samp{@w{ }and foo =@w{ }}, use the command
26970@samp{echo \@w{ }and foo = \@w{ }}.
c906108c 26971
8e04817f
AC
26972A backslash at the end of @var{text} can be used, as in C, to continue
26973the command onto subsequent lines. For example,
c906108c 26974
474c8240 26975@smallexample
8e04817f
AC
26976echo This is some text\n\
26977which is continued\n\
26978onto several lines.\n
474c8240 26979@end smallexample
c906108c 26980
8e04817f 26981produces the same output as
c906108c 26982
474c8240 26983@smallexample
8e04817f
AC
26984echo This is some text\n
26985echo which is continued\n
26986echo onto several lines.\n
474c8240 26987@end smallexample
c906108c 26988
8e04817f
AC
26989@kindex output
26990@item output @var{expression}
26991Print the value of @var{expression} and nothing but that value: no
26992newlines, no @samp{$@var{nn} = }. The value is not entered in the
26993value history either. @xref{Expressions, ,Expressions}, for more information
26994on expressions.
c906108c 26995
8e04817f
AC
26996@item output/@var{fmt} @var{expression}
26997Print the value of @var{expression} in format @var{fmt}. You can use
26998the same formats as for @code{print}. @xref{Output Formats,,Output
79a6e687 26999Formats}, for more information.
c906108c 27000
8e04817f 27001@kindex printf
82160952
EZ
27002@item printf @var{template}, @var{expressions}@dots{}
27003Print the values of one or more @var{expressions} under the control of
27004the string @var{template}. To print several values, make
27005@var{expressions} be a comma-separated list of individual expressions,
27006which may be either numbers or pointers. Their values are printed as
27007specified by @var{template}, exactly as a C program would do by
27008executing the code below:
c906108c 27009
474c8240 27010@smallexample
82160952 27011printf (@var{template}, @var{expressions}@dots{});
474c8240 27012@end smallexample
c906108c 27013
82160952
EZ
27014As in @code{C} @code{printf}, ordinary characters in @var{template}
27015are printed verbatim, while @dfn{conversion specification} introduced
27016by the @samp{%} character cause subsequent @var{expressions} to be
27017evaluated, their values converted and formatted according to type and
27018style information encoded in the conversion specifications, and then
27019printed.
27020
8e04817f 27021For example, you can print two values in hex like this:
c906108c 27022
8e04817f
AC
27023@smallexample
27024printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
27025@end smallexample
c906108c 27026
82160952
EZ
27027@code{printf} supports all the standard @code{C} conversion
27028specifications, including the flags and modifiers between the @samp{%}
27029character and the conversion letter, with the following exceptions:
27030
27031@itemize @bullet
27032@item
27033The argument-ordering modifiers, such as @samp{2$}, are not supported.
27034
27035@item
27036The modifier @samp{*} is not supported for specifying precision or
27037width.
27038
27039@item
27040The @samp{'} flag (for separation of digits into groups according to
27041@code{LC_NUMERIC'}) is not supported.
27042
27043@item
27044The type modifiers @samp{hh}, @samp{j}, @samp{t}, and @samp{z} are not
27045supported.
27046
27047@item
27048The conversion letter @samp{n} (as in @samp{%n}) is not supported.
27049
27050@item
27051The conversion letters @samp{a} and @samp{A} are not supported.
27052@end itemize
27053
27054@noindent
27055Note that the @samp{ll} type modifier is supported only if the
27056underlying @code{C} implementation used to build @value{GDBN} supports
27057the @code{long long int} type, and the @samp{L} type modifier is
27058supported only if @code{long double} type is available.
27059
27060As in @code{C}, @code{printf} supports simple backslash-escape
27061sequences, such as @code{\n}, @samp{\t}, @samp{\\}, @samp{\"},
27062@samp{\a}, and @samp{\f}, that consist of backslash followed by a
27063single character. Octal and hexadecimal escape sequences are not
27064supported.
1a619819
LM
27065
27066Additionally, @code{printf} supports conversion specifications for DFP
0aea4bf3
LM
27067(@dfn{Decimal Floating Point}) types using the following length modifiers
27068together with a floating point specifier.
1a619819
LM
27069letters:
27070
27071@itemize @bullet
27072@item
27073@samp{H} for printing @code{Decimal32} types.
27074
27075@item
27076@samp{D} for printing @code{Decimal64} types.
27077
27078@item
27079@samp{DD} for printing @code{Decimal128} types.
27080@end itemize
27081
27082If the underlying @code{C} implementation used to build @value{GDBN} has
0aea4bf3 27083support for the three length modifiers for DFP types, other modifiers
3b784c4f 27084such as width and precision will also be available for @value{GDBN} to use.
1a619819
LM
27085
27086In case there is no such @code{C} support, no additional modifiers will be
27087available and the value will be printed in the standard way.
27088
27089Here's an example of printing DFP types using the above conversion letters:
27090@smallexample
0aea4bf3 27091printf "D32: %Hf - D64: %Df - D128: %DDf\n",1.2345df,1.2E10dd,1.2E1dl
1a619819
LM
27092@end smallexample
27093
01770bbd 27094@anchor{eval}
f1421989
HZ
27095@kindex eval
27096@item eval @var{template}, @var{expressions}@dots{}
27097Convert the values of one or more @var{expressions} under the control of
27098the string @var{template} to a command line, and call it.
27099
c906108c
SS
27100@end table
27101
71b8c845
DE
27102@node Auto-loading sequences
27103@subsection Controlling auto-loading native @value{GDBN} scripts
27104@cindex native script auto-loading
27105
27106When a new object file is read (for example, due to the @code{file}
27107command, or because the inferior has loaded a shared library),
27108@value{GDBN} will look for the command file @file{@var{objfile}-gdb.gdb}.
27109@xref{Auto-loading extensions}.
27110
27111Auto-loading can be enabled or disabled,
27112and the list of auto-loaded scripts can be printed.
27113
27114@table @code
27115@anchor{set auto-load gdb-scripts}
27116@kindex set auto-load gdb-scripts
27117@item set auto-load gdb-scripts [on|off]
27118Enable or disable the auto-loading of canned sequences of commands scripts.
27119
27120@anchor{show auto-load gdb-scripts}
27121@kindex show auto-load gdb-scripts
27122@item show auto-load gdb-scripts
27123Show whether auto-loading of canned sequences of commands scripts is enabled or
27124disabled.
27125
27126@anchor{info auto-load gdb-scripts}
27127@kindex info auto-load gdb-scripts
27128@cindex print list of auto-loaded canned sequences of commands scripts
27129@item info auto-load gdb-scripts [@var{regexp}]
27130Print the list of all canned sequences of commands scripts that @value{GDBN}
27131auto-loaded.
27132@end table
27133
27134If @var{regexp} is supplied only canned sequences of commands scripts with
27135matching names are printed.
27136
329baa95
DE
27137@c Python docs live in a separate file.
27138@include python.texi
0e3509db 27139
ed3ef339
DE
27140@c Guile docs live in a separate file.
27141@include guile.texi
27142
71b8c845
DE
27143@node Auto-loading extensions
27144@section Auto-loading extensions
27145@cindex auto-loading extensions
27146
27147@value{GDBN} provides two mechanisms for automatically loading extensions
27148when a new object file is read (for example, due to the @code{file}
27149command, or because the inferior has loaded a shared library):
27150@file{@var{objfile}-gdb.@var{ext}} and the @code{.debug_gdb_scripts}
27151section of modern file formats like ELF.
27152
27153@menu
27154* objfile-gdb.ext file: objfile-gdbdotext file. The @file{@var{objfile}-gdb.@var{ext}} file
27155* .debug_gdb_scripts section: dotdebug_gdb_scripts section. The @code{.debug_gdb_scripts} section
27156* Which flavor to choose?::
27157@end menu
27158
27159The auto-loading feature is useful for supplying application-specific
27160debugging commands and features.
27161
27162Auto-loading can be enabled or disabled,
27163and the list of auto-loaded scripts can be printed.
27164See the @samp{auto-loading} section of each extension language
27165for more information.
27166For @value{GDBN} command files see @ref{Auto-loading sequences}.
27167For Python files see @ref{Python Auto-loading}.
27168
27169Note that loading of this script file also requires accordingly configured
27170@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27171
27172@node objfile-gdbdotext file
27173@subsection The @file{@var{objfile}-gdb.@var{ext}} file
27174@cindex @file{@var{objfile}-gdb.gdb}
27175@cindex @file{@var{objfile}-gdb.py}
27176@cindex @file{@var{objfile}-gdb.scm}
27177
27178When a new object file is read, @value{GDBN} looks for a file named
27179@file{@var{objfile}-gdb.@var{ext}} (we call it @var{script-name} below),
27180where @var{objfile} is the object file's name and
27181where @var{ext} is the file extension for the extension language:
27182
27183@table @code
27184@item @file{@var{objfile}-gdb.gdb}
27185GDB's own command language
27186@item @file{@var{objfile}-gdb.py}
27187Python
ed3ef339
DE
27188@item @file{@var{objfile}-gdb.scm}
27189Guile
71b8c845
DE
27190@end table
27191
27192@var{script-name} is formed by ensuring that the file name of @var{objfile}
27193is absolute, following all symlinks, and resolving @code{.} and @code{..}
27194components, and appending the @file{-gdb.@var{ext}} suffix.
27195If this file exists and is readable, @value{GDBN} will evaluate it as a
27196script in the specified extension language.
27197
27198If this file does not exist, then @value{GDBN} will look for
27199@var{script-name} file in all of the directories as specified below.
27200
27201Note that loading of these files requires an accordingly configured
27202@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27203
27204For object files using @file{.exe} suffix @value{GDBN} tries to load first the
27205scripts normally according to its @file{.exe} filename. But if no scripts are
27206found @value{GDBN} also tries script filenames matching the object file without
27207its @file{.exe} suffix. This @file{.exe} stripping is case insensitive and it
27208is attempted on any platform. This makes the script filenames compatible
27209between Unix and MS-Windows hosts.
27210
27211@table @code
27212@anchor{set auto-load scripts-directory}
27213@kindex set auto-load scripts-directory
27214@item set auto-load scripts-directory @r{[}@var{directories}@r{]}
27215Control @value{GDBN} auto-loaded scripts location. Multiple directory entries
27216may be delimited by the host platform path separator in use
27217(@samp{:} on Unix, @samp{;} on MS-Windows and MS-DOS).
27218
27219Each entry here needs to be covered also by the security setting
27220@code{set auto-load safe-path} (@pxref{set auto-load safe-path}).
27221
27222@anchor{with-auto-load-dir}
27223This variable defaults to @file{$debugdir:$datadir/auto-load}. The default
27224@code{set auto-load safe-path} value can be also overriden by @value{GDBN}
27225configuration option @option{--with-auto-load-dir}.
27226
27227Any reference to @file{$debugdir} will get replaced by
27228@var{debug-file-directory} value (@pxref{Separate Debug Files}) and any
27229reference to @file{$datadir} will get replaced by @var{data-directory} which is
27230determined at @value{GDBN} startup (@pxref{Data Files}). @file{$debugdir} and
27231@file{$datadir} must be placed as a directory component --- either alone or
27232delimited by @file{/} or @file{\} directory separators, depending on the host
27233platform.
27234
27235The list of directories uses path separator (@samp{:} on GNU and Unix
27236systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
27237to the @env{PATH} environment variable.
27238
27239@anchor{show auto-load scripts-directory}
27240@kindex show auto-load scripts-directory
27241@item show auto-load scripts-directory
27242Show @value{GDBN} auto-loaded scripts location.
f10c5b19
JK
27243
27244@anchor{add-auto-load-scripts-directory}
27245@kindex add-auto-load-scripts-directory
27246@item add-auto-load-scripts-directory @r{[}@var{directories}@dots{}@r{]}
27247Add an entry (or list of entries) to the list of auto-loaded scripts locations.
27248Multiple entries may be delimited by the host platform path separator in use.
71b8c845
DE
27249@end table
27250
27251@value{GDBN} does not track which files it has already auto-loaded this way.
27252@value{GDBN} will load the associated script every time the corresponding
27253@var{objfile} is opened.
27254So your @file{-gdb.@var{ext}} file should be careful to avoid errors if it
27255is evaluated more than once.
27256
27257@node dotdebug_gdb_scripts section
27258@subsection The @code{.debug_gdb_scripts} section
27259@cindex @code{.debug_gdb_scripts} section
27260
27261For systems using file formats like ELF and COFF,
27262when @value{GDBN} loads a new object file
27263it will look for a special section named @code{.debug_gdb_scripts}.
9f050062
DE
27264If this section exists, its contents is a list of null-terminated entries
27265specifying scripts to load. Each entry begins with a non-null prefix byte that
27266specifies the kind of entry, typically the extension language and whether the
27267script is in a file or inlined in @code{.debug_gdb_scripts}.
71b8c845 27268
9f050062
DE
27269The following entries are supported:
27270
27271@table @code
27272@item SECTION_SCRIPT_ID_PYTHON_FILE = 1
27273@item SECTION_SCRIPT_ID_SCHEME_FILE = 3
27274@item SECTION_SCRIPT_ID_PYTHON_TEXT = 4
27275@item SECTION_SCRIPT_ID_SCHEME_TEXT = 6
27276@end table
27277
27278@subsubsection Script File Entries
27279
27280If the entry specifies a file, @value{GDBN} will look for the file first
27281in the current directory and then along the source search path
71b8c845
DE
27282(@pxref{Source Path, ,Specifying Source Directories}),
27283except that @file{$cdir} is not searched, since the compilation
27284directory is not relevant to scripts.
27285
9f050062 27286File entries can be placed in section @code{.debug_gdb_scripts} with,
71b8c845
DE
27287for example, this GCC macro for Python scripts.
27288
27289@example
27290/* Note: The "MS" section flags are to remove duplicates. */
27291#define DEFINE_GDB_PY_SCRIPT(script_name) \
27292 asm("\
27293.pushsection \".debug_gdb_scripts\", \"MS\",@@progbits,1\n\
27294.byte 1 /* Python */\n\
27295.asciz \"" script_name "\"\n\
27296.popsection \n\
27297");
27298@end example
27299
27300@noindent
ed3ef339 27301For Guile scripts, replace @code{.byte 1} with @code{.byte 3}.
71b8c845
DE
27302Then one can reference the macro in a header or source file like this:
27303
27304@example
27305DEFINE_GDB_PY_SCRIPT ("my-app-scripts.py")
27306@end example
27307
27308The script name may include directories if desired.
27309
27310Note that loading of this script file also requires accordingly configured
27311@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27312
27313If the macro invocation is put in a header, any application or library
27314using this header will get a reference to the specified script,
27315and with the use of @code{"MS"} attributes on the section, the linker
27316will remove duplicates.
27317
9f050062
DE
27318@subsubsection Script Text Entries
27319
27320Script text entries allow to put the executable script in the entry
27321itself instead of loading it from a file.
27322The first line of the entry, everything after the prefix byte and up to
27323the first newline (@code{0xa}) character, is the script name, and must not
27324contain any kind of space character, e.g., spaces or tabs.
27325The rest of the entry, up to the trailing null byte, is the script to
27326execute in the specified language. The name needs to be unique among
27327all script names, as @value{GDBN} executes each script only once based
27328on its name.
27329
27330Here is an example from file @file{py-section-script.c} in the @value{GDBN}
27331testsuite.
27332
27333@example
27334#include "symcat.h"
27335#include "gdb/section-scripts.h"
27336asm(
27337".pushsection \".debug_gdb_scripts\", \"MS\",@@progbits,1\n"
27338".byte " XSTRING (SECTION_SCRIPT_ID_PYTHON_TEXT) "\n"
27339".ascii \"gdb.inlined-script\\n\"\n"
27340".ascii \"class test_cmd (gdb.Command):\\n\"\n"
27341".ascii \" def __init__ (self):\\n\"\n"
27342".ascii \" super (test_cmd, self).__init__ ("
27343 "\\\"test-cmd\\\", gdb.COMMAND_OBSCURE)\\n\"\n"
27344".ascii \" def invoke (self, arg, from_tty):\\n\"\n"
27345".ascii \" print (\\\"test-cmd output, arg = %s\\\" % arg)\\n\"\n"
27346".ascii \"test_cmd ()\\n\"\n"
27347".byte 0\n"
27348".popsection\n"
27349);
27350@end example
27351
27352Loading of inlined scripts requires a properly configured
27353@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27354The path to specify in @code{auto-load safe-path} is the path of the file
27355containing the @code{.debug_gdb_scripts} section.
27356
71b8c845
DE
27357@node Which flavor to choose?
27358@subsection Which flavor to choose?
27359
27360Given the multiple ways of auto-loading extensions, it might not always
27361be clear which one to choose. This section provides some guidance.
27362
27363@noindent
27364Benefits of the @file{-gdb.@var{ext}} way:
27365
27366@itemize @bullet
27367@item
27368Can be used with file formats that don't support multiple sections.
27369
27370@item
27371Ease of finding scripts for public libraries.
27372
27373Scripts specified in the @code{.debug_gdb_scripts} section are searched for
27374in the source search path.
27375For publicly installed libraries, e.g., @file{libstdc++}, there typically
27376isn't a source directory in which to find the script.
27377
27378@item
27379Doesn't require source code additions.
27380@end itemize
27381
27382@noindent
27383Benefits of the @code{.debug_gdb_scripts} way:
27384
27385@itemize @bullet
27386@item
27387Works with static linking.
27388
27389Scripts for libraries done the @file{-gdb.@var{ext}} way require an objfile to
27390trigger their loading. When an application is statically linked the only
27391objfile available is the executable, and it is cumbersome to attach all the
27392scripts from all the input libraries to the executable's
27393@file{-gdb.@var{ext}} script.
27394
27395@item
27396Works with classes that are entirely inlined.
27397
27398Some classes can be entirely inlined, and thus there may not be an associated
27399shared library to attach a @file{-gdb.@var{ext}} script to.
27400
27401@item
27402Scripts needn't be copied out of the source tree.
27403
27404In some circumstances, apps can be built out of large collections of internal
27405libraries, and the build infrastructure necessary to install the
27406@file{-gdb.@var{ext}} scripts in a place where @value{GDBN} can find them is
27407cumbersome. It may be easier to specify the scripts in the
27408@code{.debug_gdb_scripts} section as relative paths, and add a path to the
27409top of the source tree to the source search path.
27410@end itemize
27411
ed3ef339
DE
27412@node Multiple Extension Languages
27413@section Multiple Extension Languages
27414
27415The Guile and Python extension languages do not share any state,
27416and generally do not interfere with each other.
27417There are some things to be aware of, however.
27418
27419@subsection Python comes first
27420
27421Python was @value{GDBN}'s first extension language, and to avoid breaking
27422existing behaviour Python comes first. This is generally solved by the
27423``first one wins'' principle. @value{GDBN} maintains a list of enabled
27424extension languages, and when it makes a call to an extension language,
27425(say to pretty-print a value), it tries each in turn until an extension
27426language indicates it has performed the request (e.g., has returned the
27427pretty-printed form of a value).
27428This extends to errors while performing such requests: If an error happens
27429while, for example, trying to pretty-print an object then the error is
27430reported and any following extension languages are not tried.
27431
5a56e9c5
DE
27432@node Aliases
27433@section Creating new spellings of existing commands
27434@cindex aliases for commands
27435
27436It is often useful to define alternate spellings of existing commands.
27437For example, if a new @value{GDBN} command defined in Python has
27438a long name to type, it is handy to have an abbreviated version of it
27439that involves less typing.
27440
27441@value{GDBN} itself uses aliases. For example @samp{s} is an alias
27442of the @samp{step} command even though it is otherwise an ambiguous
27443abbreviation of other commands like @samp{set} and @samp{show}.
27444
27445Aliases are also used to provide shortened or more common versions
27446of multi-word commands. For example, @value{GDBN} provides the
27447@samp{tty} alias of the @samp{set inferior-tty} command.
27448
27449You can define a new alias with the @samp{alias} command.
27450
27451@table @code
27452
27453@kindex alias
27454@item alias [-a] [--] @var{ALIAS} = @var{COMMAND}
27455
27456@end table
27457
27458@var{ALIAS} specifies the name of the new alias.
27459Each word of @var{ALIAS} must consist of letters, numbers, dashes and
27460underscores.
27461
27462@var{COMMAND} specifies the name of an existing command
27463that is being aliased.
27464
27465The @samp{-a} option specifies that the new alias is an abbreviation
27466of the command. Abbreviations are not shown in command
27467lists displayed by the @samp{help} command.
27468
27469The @samp{--} option specifies the end of options,
27470and is useful when @var{ALIAS} begins with a dash.
27471
27472Here is a simple example showing how to make an abbreviation
27473of a command so that there is less to type.
27474Suppose you were tired of typing @samp{disas}, the current
27475shortest unambiguous abbreviation of the @samp{disassemble} command
27476and you wanted an even shorter version named @samp{di}.
27477The following will accomplish this.
27478
27479@smallexample
27480(gdb) alias -a di = disas
27481@end smallexample
27482
27483Note that aliases are different from user-defined commands.
27484With a user-defined command, you also need to write documentation
27485for it with the @samp{document} command.
27486An alias automatically picks up the documentation of the existing command.
27487
27488Here is an example where we make @samp{elms} an abbreviation of
27489@samp{elements} in the @samp{set print elements} command.
27490This is to show that you can make an abbreviation of any part
27491of a command.
27492
27493@smallexample
27494(gdb) alias -a set print elms = set print elements
27495(gdb) alias -a show print elms = show print elements
27496(gdb) set p elms 20
27497(gdb) show p elms
27498Limit on string chars or array elements to print is 200.
27499@end smallexample
27500
27501Note that if you are defining an alias of a @samp{set} command,
27502and you want to have an alias for the corresponding @samp{show}
27503command, then you need to define the latter separately.
27504
27505Unambiguously abbreviated commands are allowed in @var{COMMAND} and
27506@var{ALIAS}, just as they are normally.
27507
27508@smallexample
27509(gdb) alias -a set pr elms = set p ele
27510@end smallexample
27511
27512Finally, here is an example showing the creation of a one word
27513alias for a more complex command.
27514This creates alias @samp{spe} of the command @samp{set print elements}.
27515
27516@smallexample
27517(gdb) alias spe = set print elements
27518(gdb) spe 20
27519@end smallexample
27520
21c294e6
AC
27521@node Interpreters
27522@chapter Command Interpreters
27523@cindex command interpreters
27524
27525@value{GDBN} supports multiple command interpreters, and some command
27526infrastructure to allow users or user interface writers to switch
27527between interpreters or run commands in other interpreters.
27528
27529@value{GDBN} currently supports two command interpreters, the console
27530interpreter (sometimes called the command-line interpreter or @sc{cli})
27531and the machine interface interpreter (or @sc{gdb/mi}). This manual
27532describes both of these interfaces in great detail.
27533
27534By default, @value{GDBN} will start with the console interpreter.
27535However, the user may choose to start @value{GDBN} with another
27536interpreter by specifying the @option{-i} or @option{--interpreter}
27537startup options. Defined interpreters include:
27538
27539@table @code
27540@item console
27541@cindex console interpreter
27542The traditional console or command-line interpreter. This is the most often
27543used interpreter with @value{GDBN}. With no interpreter specified at runtime,
27544@value{GDBN} will use this interpreter.
27545
27546@item mi
27547@cindex mi interpreter
b4be1b06 27548The newest @sc{gdb/mi} interface (currently @code{mi3}). Used primarily
21c294e6
AC
27549by programs wishing to use @value{GDBN} as a backend for a debugger GUI
27550or an IDE. For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
27551Interface}.
27552
b4be1b06
SM
27553@item mi3
27554@cindex mi3 interpreter
27555The @sc{gdb/mi} interface introduced in @value{GDBN} 9.1.
27556
21c294e6
AC
27557@item mi2
27558@cindex mi2 interpreter
b4be1b06 27559The @sc{gdb/mi} interface introduced in @value{GDBN} 6.0.
21c294e6
AC
27560
27561@item mi1
27562@cindex mi1 interpreter
b4be1b06 27563The @sc{gdb/mi} interface introduced in @value{GDBN} 5.1.
21c294e6
AC
27564
27565@end table
27566
27567@cindex invoke another interpreter
21c294e6
AC
27568
27569@kindex interpreter-exec
86f78169
PA
27570You may execute commands in any interpreter from the current
27571interpreter using the appropriate command. If you are running the
27572console interpreter, simply use the @code{interpreter-exec} command:
21c294e6
AC
27573
27574@smallexample
27575interpreter-exec mi "-data-list-register-names"
27576@end smallexample
27577
27578@sc{gdb/mi} has a similar command, although it is only available in versions of
27579@value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
27580
86f78169
PA
27581Note that @code{interpreter-exec} only changes the interpreter for the
27582duration of the specified command. It does not change the interpreter
27583permanently.
27584
27585@cindex start a new independent interpreter
27586
27587Although you may only choose a single interpreter at startup, it is
27588possible to run an independent interpreter on a specified input/output
27589device (usually a tty).
27590
27591For example, consider a debugger GUI or IDE that wants to provide a
27592@value{GDBN} console view. It may do so by embedding a terminal
27593emulator widget in its GUI, starting @value{GDBN} in the traditional
27594command-line mode with stdin/stdout/stderr redirected to that
27595terminal, and then creating an MI interpreter running on a specified
27596input/output device. The console interpreter created by @value{GDBN}
27597at startup handles commands the user types in the terminal widget,
27598while the GUI controls and synchronizes state with @value{GDBN} using
27599the separate MI interpreter.
27600
27601To start a new secondary @dfn{user interface} running MI, use the
27602@code{new-ui} command:
27603
27604@kindex new-ui
27605@cindex new user interface
27606@smallexample
27607new-ui @var{interpreter} @var{tty}
27608@end smallexample
27609
27610The @var{interpreter} parameter specifies the interpreter to run.
27611This accepts the same values as the @code{interpreter-exec} command.
27612For example, @samp{console}, @samp{mi}, @samp{mi2}, etc. The
27613@var{tty} parameter specifies the name of the bidirectional file the
27614interpreter uses for input/output, usually the name of a
27615pseudoterminal slave on Unix systems. For example:
27616
27617@smallexample
27618(@value{GDBP}) new-ui mi /dev/pts/9
27619@end smallexample
27620
27621@noindent
27622runs an MI interpreter on @file{/dev/pts/9}.
27623
8e04817f
AC
27624@node TUI
27625@chapter @value{GDBN} Text User Interface
27626@cindex TUI
d0d5df6f 27627@cindex Text User Interface
c906108c 27628
8e04817f
AC
27629@menu
27630* TUI Overview:: TUI overview
27631* TUI Keys:: TUI key bindings
7cf36c78 27632* TUI Single Key Mode:: TUI single key mode
db2e3e2e 27633* TUI Commands:: TUI-specific commands
8e04817f
AC
27634* TUI Configuration:: TUI configuration variables
27635@end menu
c906108c 27636
46ba6afa 27637The @value{GDBN} Text User Interface (TUI) is a terminal
d0d5df6f
AC
27638interface which uses the @code{curses} library to show the source
27639file, the assembly output, the program registers and @value{GDBN}
46ba6afa
BW
27640commands in separate text windows. The TUI mode is supported only
27641on platforms where a suitable version of the @code{curses} library
27642is available.
d0d5df6f 27643
46ba6afa 27644The TUI mode is enabled by default when you invoke @value{GDBN} as
217bff3e 27645@samp{@value{GDBP} -tui}.
46ba6afa 27646You can also switch in and out of TUI mode while @value{GDBN} runs by
a4ea0946 27647using various TUI commands and key bindings, such as @command{tui
bcd8537c 27648enable} or @kbd{C-x C-a}. @xref{TUI Commands, ,TUI Commands}, and
a4ea0946 27649@ref{TUI Keys, ,TUI Key Bindings}.
c906108c 27650
8e04817f 27651@node TUI Overview
79a6e687 27652@section TUI Overview
c906108c 27653
46ba6afa 27654In TUI mode, @value{GDBN} can display several text windows:
c906108c 27655
8e04817f
AC
27656@table @emph
27657@item command
27658This window is the @value{GDBN} command window with the @value{GDBN}
46ba6afa
BW
27659prompt and the @value{GDBN} output. The @value{GDBN} input is still
27660managed using readline.
c906108c 27661
8e04817f
AC
27662@item source
27663The source window shows the source file of the program. The current
46ba6afa 27664line and active breakpoints are displayed in this window.
c906108c 27665
8e04817f
AC
27666@item assembly
27667The assembly window shows the disassembly output of the program.
c906108c 27668
8e04817f 27669@item register
46ba6afa
BW
27670This window shows the processor registers. Registers are highlighted
27671when their values change.
c906108c
SS
27672@end table
27673
269c21fe 27674The source and assembly windows show the current program position
46ba6afa
BW
27675by highlighting the current line and marking it with a @samp{>} marker.
27676Breakpoints are indicated with two markers. The first marker
269c21fe
SC
27677indicates the breakpoint type:
27678
27679@table @code
27680@item B
27681Breakpoint which was hit at least once.
27682
27683@item b
27684Breakpoint which was never hit.
27685
27686@item H
27687Hardware breakpoint which was hit at least once.
27688
27689@item h
27690Hardware breakpoint which was never hit.
269c21fe
SC
27691@end table
27692
27693The second marker indicates whether the breakpoint is enabled or not:
27694
27695@table @code
27696@item +
27697Breakpoint is enabled.
27698
27699@item -
27700Breakpoint is disabled.
269c21fe
SC
27701@end table
27702
46ba6afa
BW
27703The source, assembly and register windows are updated when the current
27704thread changes, when the frame changes, or when the program counter
27705changes.
27706
27707These windows are not all visible at the same time. The command
27708window is always visible. The others can be arranged in several
27709layouts:
c906108c 27710
8e04817f
AC
27711@itemize @bullet
27712@item
46ba6afa 27713source only,
2df3850c 27714
8e04817f 27715@item
46ba6afa 27716assembly only,
8e04817f
AC
27717
27718@item
46ba6afa 27719source and assembly,
8e04817f
AC
27720
27721@item
46ba6afa 27722source and registers, or
c906108c 27723
8e04817f 27724@item
46ba6afa 27725assembly and registers.
8e04817f 27726@end itemize
c906108c 27727
46ba6afa 27728A status line above the command window shows the following information:
b7bb15bc
SC
27729
27730@table @emph
27731@item target
46ba6afa 27732Indicates the current @value{GDBN} target.
b7bb15bc
SC
27733(@pxref{Targets, ,Specifying a Debugging Target}).
27734
27735@item process
46ba6afa 27736Gives the current process or thread number.
b7bb15bc
SC
27737When no process is being debugged, this field is set to @code{No process}.
27738
27739@item function
27740Gives the current function name for the selected frame.
27741The name is demangled if demangling is turned on (@pxref{Print Settings}).
46ba6afa 27742When there is no symbol corresponding to the current program counter,
b7bb15bc
SC
27743the string @code{??} is displayed.
27744
27745@item line
27746Indicates the current line number for the selected frame.
46ba6afa 27747When the current line number is not known, the string @code{??} is displayed.
b7bb15bc
SC
27748
27749@item pc
27750Indicates the current program counter address.
b7bb15bc
SC
27751@end table
27752
8e04817f
AC
27753@node TUI Keys
27754@section TUI Key Bindings
27755@cindex TUI key bindings
c906108c 27756
8e04817f 27757The TUI installs several key bindings in the readline keymaps
39037522
TT
27758@ifset SYSTEM_READLINE
27759(@pxref{Command Line Editing, , , rluserman, GNU Readline Library}).
27760@end ifset
27761@ifclear SYSTEM_READLINE
27762(@pxref{Command Line Editing}).
27763@end ifclear
27764The following key bindings are installed for both TUI mode and the
27765@value{GDBN} standard mode.
c906108c 27766
8e04817f
AC
27767@table @kbd
27768@kindex C-x C-a
27769@item C-x C-a
27770@kindex C-x a
27771@itemx C-x a
27772@kindex C-x A
27773@itemx C-x A
46ba6afa
BW
27774Enter or leave the TUI mode. When leaving the TUI mode,
27775the curses window management stops and @value{GDBN} operates using
27776its standard mode, writing on the terminal directly. When reentering
27777the TUI mode, control is given back to the curses windows.
8e04817f 27778The screen is then refreshed.
c906108c 27779
c86d74cc
TT
27780This key binding uses the bindable Readline function
27781@code{tui-switch-mode}.
27782
8e04817f
AC
27783@kindex C-x 1
27784@item C-x 1
27785Use a TUI layout with only one window. The layout will
27786either be @samp{source} or @samp{assembly}. When the TUI mode
27787is not active, it will switch to the TUI mode.
2df3850c 27788
8e04817f 27789Think of this key binding as the Emacs @kbd{C-x 1} binding.
c906108c 27790
c86d74cc
TT
27791This key binding uses the bindable Readline function
27792@code{tui-delete-other-windows}.
27793
8e04817f
AC
27794@kindex C-x 2
27795@item C-x 2
27796Use a TUI layout with at least two windows. When the current
46ba6afa 27797layout already has two windows, the next layout with two windows is used.
8e04817f
AC
27798When a new layout is chosen, one window will always be common to the
27799previous layout and the new one.
c906108c 27800
8e04817f 27801Think of it as the Emacs @kbd{C-x 2} binding.
2df3850c 27802
c86d74cc
TT
27803This key binding uses the bindable Readline function
27804@code{tui-change-windows}.
27805
72ffddc9
SC
27806@kindex C-x o
27807@item C-x o
27808Change the active window. The TUI associates several key bindings
46ba6afa 27809(like scrolling and arrow keys) with the active window. This command
72ffddc9
SC
27810gives the focus to the next TUI window.
27811
27812Think of it as the Emacs @kbd{C-x o} binding.
27813
c86d74cc
TT
27814This key binding uses the bindable Readline function
27815@code{tui-other-window}.
27816
7cf36c78
SC
27817@kindex C-x s
27818@item C-x s
46ba6afa
BW
27819Switch in and out of the TUI SingleKey mode that binds single
27820keys to @value{GDBN} commands (@pxref{TUI Single Key Mode}).
c86d74cc
TT
27821
27822This key binding uses the bindable Readline function
27823@code{next-keymap}.
c906108c
SS
27824@end table
27825
46ba6afa 27826The following key bindings only work in the TUI mode:
5d161b24 27827
46ba6afa 27828@table @asis
8e04817f 27829@kindex PgUp
46ba6afa 27830@item @key{PgUp}
8e04817f 27831Scroll the active window one page up.
c906108c 27832
8e04817f 27833@kindex PgDn
46ba6afa 27834@item @key{PgDn}
8e04817f 27835Scroll the active window one page down.
c906108c 27836
8e04817f 27837@kindex Up
46ba6afa 27838@item @key{Up}
8e04817f 27839Scroll the active window one line up.
c906108c 27840
8e04817f 27841@kindex Down
46ba6afa 27842@item @key{Down}
8e04817f 27843Scroll the active window one line down.
c906108c 27844
8e04817f 27845@kindex Left
46ba6afa 27846@item @key{Left}
8e04817f 27847Scroll the active window one column left.
c906108c 27848
8e04817f 27849@kindex Right
46ba6afa 27850@item @key{Right}
8e04817f 27851Scroll the active window one column right.
c906108c 27852
8e04817f 27853@kindex C-L
46ba6afa 27854@item @kbd{C-L}
8e04817f 27855Refresh the screen.
8e04817f 27856@end table
c906108c 27857
46ba6afa
BW
27858Because the arrow keys scroll the active window in the TUI mode, they
27859are not available for their normal use by readline unless the command
27860window has the focus. When another window is active, you must use
27861other readline key bindings such as @kbd{C-p}, @kbd{C-n}, @kbd{C-b}
27862and @kbd{C-f} to control the command window.
8e04817f 27863
7cf36c78
SC
27864@node TUI Single Key Mode
27865@section TUI Single Key Mode
27866@cindex TUI single key mode
27867
46ba6afa
BW
27868The TUI also provides a @dfn{SingleKey} mode, which binds several
27869frequently used @value{GDBN} commands to single keys. Type @kbd{C-x s} to
27870switch into this mode, where the following key bindings are used:
7cf36c78
SC
27871
27872@table @kbd
27873@kindex c @r{(SingleKey TUI key)}
27874@item c
27875continue
27876
27877@kindex d @r{(SingleKey TUI key)}
27878@item d
27879down
27880
27881@kindex f @r{(SingleKey TUI key)}
27882@item f
27883finish
27884
27885@kindex n @r{(SingleKey TUI key)}
27886@item n
27887next
27888
a5afdb16
RK
27889@kindex o @r{(SingleKey TUI key)}
27890@item o
27891nexti. The shortcut letter @samp{o} stands for ``step Over''.
27892
7cf36c78
SC
27893@kindex q @r{(SingleKey TUI key)}
27894@item q
46ba6afa 27895exit the SingleKey mode.
7cf36c78
SC
27896
27897@kindex r @r{(SingleKey TUI key)}
27898@item r
27899run
27900
27901@kindex s @r{(SingleKey TUI key)}
27902@item s
27903step
27904
a5afdb16
RK
27905@kindex i @r{(SingleKey TUI key)}
27906@item i
27907stepi. The shortcut letter @samp{i} stands for ``step Into''.
27908
7cf36c78
SC
27909@kindex u @r{(SingleKey TUI key)}
27910@item u
27911up
27912
27913@kindex v @r{(SingleKey TUI key)}
27914@item v
27915info locals
27916
27917@kindex w @r{(SingleKey TUI key)}
27918@item w
27919where
7cf36c78
SC
27920@end table
27921
27922Other keys temporarily switch to the @value{GDBN} command prompt.
27923The key that was pressed is inserted in the editing buffer so that
27924it is possible to type most @value{GDBN} commands without interaction
46ba6afa
BW
27925with the TUI SingleKey mode. Once the command is entered the TUI
27926SingleKey mode is restored. The only way to permanently leave
7f9087cb 27927this mode is by typing @kbd{q} or @kbd{C-x s}.
7cf36c78 27928
11061048
TT
27929@cindex SingleKey keymap name
27930If @value{GDBN} was built with Readline 8.0 or later, the TUI
27931SingleKey keymap will be named @samp{SingleKey}. This can be used in
27932@file{.inputrc} to add additional bindings to this keymap.
7cf36c78 27933
8e04817f 27934@node TUI Commands
db2e3e2e 27935@section TUI-specific Commands
8e04817f
AC
27936@cindex TUI commands
27937
27938The TUI has specific commands to control the text windows.
46ba6afa
BW
27939These commands are always available, even when @value{GDBN} is not in
27940the TUI mode. When @value{GDBN} is in the standard mode, most
27941of these commands will automatically switch to the TUI mode.
c906108c 27942
ff12863f
PA
27943Note that if @value{GDBN}'s @code{stdout} is not connected to a
27944terminal, or @value{GDBN} has been started with the machine interface
27945interpreter (@pxref{GDB/MI, ,The @sc{gdb/mi} Interface}), most of
27946these commands will fail with an error, because it would not be
27947possible or desirable to enable curses window management.
27948
c906108c 27949@table @code
a4ea0946
AB
27950@item tui enable
27951@kindex tui enable
27952Activate TUI mode. The last active TUI window layout will be used if
760f7560 27953TUI mode has previously been used in the current debugging session,
a4ea0946
AB
27954otherwise a default layout is used.
27955
27956@item tui disable
27957@kindex tui disable
27958Disable TUI mode, returning to the console interpreter.
27959
3d757584
SC
27960@item info win
27961@kindex info win
27962List and give the size of all displayed windows.
27963
6008fc5f 27964@item layout @var{name}
4644b6e3 27965@kindex layout
6008fc5f
AB
27966Changes which TUI windows are displayed. In each layout the command
27967window is always displayed, the @var{name} parameter controls which
27968additional windows are displayed, and can be any of the following:
27969
27970@table @code
27971@item next
8e04817f 27972Display the next layout.
2df3850c 27973
6008fc5f 27974@item prev
8e04817f 27975Display the previous layout.
c906108c 27976
6008fc5f
AB
27977@item src
27978Display the source and command windows.
c906108c 27979
6008fc5f
AB
27980@item asm
27981Display the assembly and command windows.
c906108c 27982
6008fc5f
AB
27983@item split
27984Display the source, assembly, and command windows.
c906108c 27985
6008fc5f
AB
27986@item regs
27987When in @code{src} layout display the register, source, and command
27988windows. When in @code{asm} or @code{split} layout display the
27989register, assembler, and command windows.
27990@end table
8e04817f 27991
6008fc5f 27992@item focus @var{name}
8e04817f 27993@kindex focus
6008fc5f
AB
27994Changes which TUI window is currently active for scrolling. The
27995@var{name} parameter can be any of the following:
27996
27997@table @code
27998@item next
46ba6afa
BW
27999Make the next window active for scrolling.
28000
6008fc5f 28001@item prev
46ba6afa
BW
28002Make the previous window active for scrolling.
28003
6008fc5f 28004@item src
46ba6afa
BW
28005Make the source window active for scrolling.
28006
6008fc5f 28007@item asm
46ba6afa
BW
28008Make the assembly window active for scrolling.
28009
6008fc5f 28010@item regs
46ba6afa
BW
28011Make the register window active for scrolling.
28012
6008fc5f 28013@item cmd
46ba6afa 28014Make the command window active for scrolling.
6008fc5f 28015@end table
c906108c 28016
8e04817f
AC
28017@item refresh
28018@kindex refresh
7f9087cb 28019Refresh the screen. This is similar to typing @kbd{C-L}.
c906108c 28020
51f0e40d 28021@item tui reg @var{group}
6a1b180d 28022@kindex tui reg
51f0e40d
AB
28023Changes the register group displayed in the tui register window to
28024@var{group}. If the register window is not currently displayed this
28025command will cause the register window to be displayed. The list of
28026register groups, as well as their order is target specific. The
28027following groups are available on most targets:
28028@table @code
28029@item next
28030Repeatedly selecting this group will cause the display to cycle
28031through all of the available register groups.
28032
28033@item prev
28034Repeatedly selecting this group will cause the display to cycle
28035through all of the available register groups in the reverse order to
28036@var{next}.
28037
28038@item general
28039Display the general registers.
28040@item float
28041Display the floating point registers.
28042@item system
28043Display the system registers.
28044@item vector
28045Display the vector registers.
28046@item all
28047Display all registers.
28048@end table
6a1b180d 28049
8e04817f
AC
28050@item update
28051@kindex update
28052Update the source window and the current execution point.
c906108c 28053
8e04817f
AC
28054@item winheight @var{name} +@var{count}
28055@itemx winheight @var{name} -@var{count}
28056@kindex winheight
28057Change the height of the window @var{name} by @var{count}
28058lines. Positive counts increase the height, while negative counts
bf555842
EZ
28059decrease it. The @var{name} parameter can be one of @code{src} (the
28060source window), @code{cmd} (the command window), @code{asm} (the
28061disassembly window), or @code{regs} (the register display window).
d6677607 28062@end table
2df3850c 28063
8e04817f 28064@node TUI Configuration
79a6e687 28065@section TUI Configuration Variables
8e04817f 28066@cindex TUI configuration variables
c906108c 28067
46ba6afa 28068Several configuration variables control the appearance of TUI windows.
c906108c 28069
8e04817f
AC
28070@table @code
28071@item set tui border-kind @var{kind}
28072@kindex set tui border-kind
28073Select the border appearance for the source, assembly and register windows.
28074The possible values are the following:
28075@table @code
28076@item space
28077Use a space character to draw the border.
c906108c 28078
8e04817f 28079@item ascii
46ba6afa 28080Use @sc{ascii} characters @samp{+}, @samp{-} and @samp{|} to draw the border.
c906108c 28081
8e04817f
AC
28082@item acs
28083Use the Alternate Character Set to draw the border. The border is
28084drawn using character line graphics if the terminal supports them.
8e04817f 28085@end table
c78b4128 28086
8e04817f
AC
28087@item set tui border-mode @var{mode}
28088@kindex set tui border-mode
46ba6afa
BW
28089@itemx set tui active-border-mode @var{mode}
28090@kindex set tui active-border-mode
28091Select the display attributes for the borders of the inactive windows
28092or the active window. The @var{mode} can be one of the following:
8e04817f
AC
28093@table @code
28094@item normal
28095Use normal attributes to display the border.
c906108c 28096
8e04817f
AC
28097@item standout
28098Use standout mode.
c906108c 28099
8e04817f
AC
28100@item reverse
28101Use reverse video mode.
c906108c 28102
8e04817f
AC
28103@item half
28104Use half bright mode.
c906108c 28105
8e04817f
AC
28106@item half-standout
28107Use half bright and standout mode.
c906108c 28108
8e04817f
AC
28109@item bold
28110Use extra bright or bold mode.
c78b4128 28111
8e04817f
AC
28112@item bold-standout
28113Use extra bright or bold and standout mode.
8e04817f 28114@end table
7806cea7
TT
28115
28116@item set tui tab-width @var{nchars}
28117@kindex set tui tab-width
28118@kindex tabset
28119Set the width of tab stops to be @var{nchars} characters. This
28120setting affects the display of TAB characters in the source and
28121assembly windows.
d1da6b01
TT
28122
28123@item set tui compact-source @r{[}on@r{|}off@r{]}
28124@kindex set tui compact-source
28125Set whether the TUI source window is displayed in ``compact'' form.
28126The default display uses more space for line numbers and starts the
28127source text at the next tab stop; the compact display uses only as
28128much space as is needed for the line numbers in the current file, and
28129only a single space to separate the line numbers from the source.
7806cea7 28130@end table
c78b4128 28131
a2a7af0c
TT
28132Note that the colors of the TUI borders can be controlled using the
28133appropriate @code{set style} commands. @xref{Output Styling}.
28134
8e04817f
AC
28135@node Emacs
28136@chapter Using @value{GDBN} under @sc{gnu} Emacs
c78b4128 28137
8e04817f
AC
28138@cindex Emacs
28139@cindex @sc{gnu} Emacs
28140A special interface allows you to use @sc{gnu} Emacs to view (and
28141edit) the source files for the program you are debugging with
28142@value{GDBN}.
c906108c 28143
8e04817f
AC
28144To use this interface, use the command @kbd{M-x gdb} in Emacs. Give the
28145executable file you want to debug as an argument. This command starts
28146@value{GDBN} as a subprocess of Emacs, with input and output through a newly
28147created Emacs buffer.
28148@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
c906108c 28149
5e252a2e 28150Running @value{GDBN} under Emacs can be just like running @value{GDBN} normally except for two
8e04817f 28151things:
c906108c 28152
8e04817f
AC
28153@itemize @bullet
28154@item
5e252a2e
NR
28155All ``terminal'' input and output goes through an Emacs buffer, called
28156the GUD buffer.
c906108c 28157
8e04817f
AC
28158This applies both to @value{GDBN} commands and their output, and to the input
28159and output done by the program you are debugging.
bf0184be 28160
8e04817f
AC
28161This is useful because it means that you can copy the text of previous
28162commands and input them again; you can even use parts of the output
28163in this way.
bf0184be 28164
8e04817f
AC
28165All the facilities of Emacs' Shell mode are available for interacting
28166with your program. In particular, you can send signals the usual
28167way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
28168stop.
bf0184be
ND
28169
28170@item
8e04817f 28171@value{GDBN} displays source code through Emacs.
bf0184be 28172
8e04817f
AC
28173Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
28174source file for that frame and puts an arrow (@samp{=>}) at the
28175left margin of the current line. Emacs uses a separate buffer for
28176source display, and splits the screen to show both your @value{GDBN} session
28177and the source.
bf0184be 28178
8e04817f
AC
28179Explicit @value{GDBN} @code{list} or search commands still produce output as
28180usual, but you probably have no reason to use them from Emacs.
5e252a2e
NR
28181@end itemize
28182
28183We call this @dfn{text command mode}. Emacs 22.1, and later, also uses
28184a graphical mode, enabled by default, which provides further buffers
28185that can control the execution and describe the state of your program.
28186@xref{GDB Graphical Interface,,, Emacs, The @sc{gnu} Emacs Manual}.
c906108c 28187
64fabec2
AC
28188If you specify an absolute file name when prompted for the @kbd{M-x
28189gdb} argument, then Emacs sets your current working directory to where
28190your program resides. If you only specify the file name, then Emacs
7a9dd1b2 28191sets your current working directory to the directory associated
64fabec2
AC
28192with the previous buffer. In this case, @value{GDBN} may find your
28193program by searching your environment's @code{PATH} variable, but on
28194some operating systems it might not find the source. So, although the
28195@value{GDBN} input and output session proceeds normally, the auxiliary
28196buffer does not display the current source and line of execution.
28197
28198The initial working directory of @value{GDBN} is printed on the top
5e252a2e
NR
28199line of the GUD buffer and this serves as a default for the commands
28200that specify files for @value{GDBN} to operate on. @xref{Files,
28201,Commands to Specify Files}.
64fabec2
AC
28202
28203By default, @kbd{M-x gdb} calls the program called @file{gdb}. If you
28204need to call @value{GDBN} by a different name (for example, if you
28205keep several configurations around, with different names) you can
28206customize the Emacs variable @code{gud-gdb-command-name} to run the
28207one you want.
8e04817f 28208
5e252a2e 28209In the GUD buffer, you can use these special Emacs commands in
8e04817f 28210addition to the standard Shell mode commands:
c906108c 28211
8e04817f
AC
28212@table @kbd
28213@item C-h m
5e252a2e 28214Describe the features of Emacs' GUD Mode.
c906108c 28215
64fabec2 28216@item C-c C-s
8e04817f
AC
28217Execute to another source line, like the @value{GDBN} @code{step} command; also
28218update the display window to show the current file and location.
c906108c 28219
64fabec2 28220@item C-c C-n
8e04817f
AC
28221Execute to next source line in this function, skipping all function
28222calls, like the @value{GDBN} @code{next} command. Then update the display window
28223to show the current file and location.
c906108c 28224
64fabec2 28225@item C-c C-i
8e04817f
AC
28226Execute one instruction, like the @value{GDBN} @code{stepi} command; update
28227display window accordingly.
c906108c 28228
8e04817f
AC
28229@item C-c C-f
28230Execute until exit from the selected stack frame, like the @value{GDBN}
28231@code{finish} command.
c906108c 28232
64fabec2 28233@item C-c C-r
8e04817f
AC
28234Continue execution of your program, like the @value{GDBN} @code{continue}
28235command.
b433d00b 28236
64fabec2 28237@item C-c <
8e04817f
AC
28238Go up the number of frames indicated by the numeric argument
28239(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
28240like the @value{GDBN} @code{up} command.
b433d00b 28241
64fabec2 28242@item C-c >
8e04817f
AC
28243Go down the number of frames indicated by the numeric argument, like the
28244@value{GDBN} @code{down} command.
8e04817f 28245@end table
c906108c 28246
7f9087cb 28247In any source file, the Emacs command @kbd{C-x @key{SPC}} (@code{gud-break})
8e04817f 28248tells @value{GDBN} to set a breakpoint on the source line point is on.
c906108c 28249
5e252a2e
NR
28250In text command mode, if you type @kbd{M-x speedbar}, Emacs displays a
28251separate frame which shows a backtrace when the GUD buffer is current.
28252Move point to any frame in the stack and type @key{RET} to make it
28253become the current frame and display the associated source in the
28254source buffer. Alternatively, click @kbd{Mouse-2} to make the
28255selected frame become the current one. In graphical mode, the
28256speedbar displays watch expressions.
64fabec2 28257
8e04817f
AC
28258If you accidentally delete the source-display buffer, an easy way to get
28259it back is to type the command @code{f} in the @value{GDBN} buffer, to
28260request a frame display; when you run under Emacs, this recreates
28261the source buffer if necessary to show you the context of the current
28262frame.
c906108c 28263
8e04817f
AC
28264The source files displayed in Emacs are in ordinary Emacs buffers
28265which are visiting the source files in the usual way. You can edit
28266the files with these buffers if you wish; but keep in mind that @value{GDBN}
28267communicates with Emacs in terms of line numbers. If you add or
28268delete lines from the text, the line numbers that @value{GDBN} knows cease
28269to correspond properly with the code.
b383017d 28270
5e252a2e
NR
28271A more detailed description of Emacs' interaction with @value{GDBN} is
28272given in the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu}
28273Emacs Manual}).
c906108c 28274
922fbb7b
AC
28275@node GDB/MI
28276@chapter The @sc{gdb/mi} Interface
28277
28278@unnumberedsec Function and Purpose
28279
28280@cindex @sc{gdb/mi}, its purpose
6b5e8c01
NR
28281@sc{gdb/mi} is a line based machine oriented text interface to
28282@value{GDBN} and is activated by specifying using the
28283@option{--interpreter} command line option (@pxref{Mode Options}). It
28284is specifically intended to support the development of systems which
28285use the debugger as just one small component of a larger system.
922fbb7b
AC
28286
28287This chapter is a specification of the @sc{gdb/mi} interface. It is written
28288in the form of a reference manual.
28289
28290Note that @sc{gdb/mi} is still under construction, so some of the
af6eff6f
NR
28291features described below are incomplete and subject to change
28292(@pxref{GDB/MI Development and Front Ends, , @sc{gdb/mi} Development and Front Ends}).
922fbb7b
AC
28293
28294@unnumberedsec Notation and Terminology
28295
28296@cindex notational conventions, for @sc{gdb/mi}
28297This chapter uses the following notation:
28298
28299@itemize @bullet
28300@item
28301@code{|} separates two alternatives.
28302
28303@item
28304@code{[ @var{something} ]} indicates that @var{something} is optional:
28305it may or may not be given.
28306
28307@item
28308@code{( @var{group} )*} means that @var{group} inside the parentheses
28309may repeat zero or more times.
28310
28311@item
28312@code{( @var{group} )+} means that @var{group} inside the parentheses
28313may repeat one or more times.
28314
28315@item
28316@code{"@var{string}"} means a literal @var{string}.
28317@end itemize
28318
28319@ignore
28320@heading Dependencies
28321@end ignore
28322
922fbb7b 28323@menu
c3b108f7 28324* GDB/MI General Design::
922fbb7b
AC
28325* GDB/MI Command Syntax::
28326* GDB/MI Compatibility with CLI::
af6eff6f 28327* GDB/MI Development and Front Ends::
922fbb7b 28328* GDB/MI Output Records::
ef21caaf 28329* GDB/MI Simple Examples::
922fbb7b 28330* GDB/MI Command Description Format::
ef21caaf 28331* GDB/MI Breakpoint Commands::
3fa7bf06 28332* GDB/MI Catchpoint Commands::
a2c02241
NR
28333* GDB/MI Program Context::
28334* GDB/MI Thread Commands::
5d77fe44 28335* GDB/MI Ada Tasking Commands::
a2c02241
NR
28336* GDB/MI Program Execution::
28337* GDB/MI Stack Manipulation::
28338* GDB/MI Variable Objects::
922fbb7b 28339* GDB/MI Data Manipulation::
a2c02241
NR
28340* GDB/MI Tracepoint Commands::
28341* GDB/MI Symbol Query::
351ff01a 28342* GDB/MI File Commands::
922fbb7b
AC
28343@ignore
28344* GDB/MI Kod Commands::
28345* GDB/MI Memory Overlay Commands::
28346* GDB/MI Signal Handling Commands::
28347@end ignore
922fbb7b 28348* GDB/MI Target Manipulation::
a6b151f1 28349* GDB/MI File Transfer Commands::
58d06528 28350* GDB/MI Ada Exceptions Commands::
d192b373 28351* GDB/MI Support Commands::
ef21caaf 28352* GDB/MI Miscellaneous Commands::
922fbb7b
AC
28353@end menu
28354
c3b108f7
VP
28355@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28356@node GDB/MI General Design
28357@section @sc{gdb/mi} General Design
28358@cindex GDB/MI General Design
28359
28360Interaction of a @sc{GDB/MI} frontend with @value{GDBN} involves three
28361parts---commands sent to @value{GDBN}, responses to those commands
28362and notifications. Each command results in exactly one response,
28363indicating either successful completion of the command, or an error.
28364For the commands that do not resume the target, the response contains the
28365requested information. For the commands that resume the target, the
28366response only indicates whether the target was successfully resumed.
28367Notifications is the mechanism for reporting changes in the state of the
28368target, or in @value{GDBN} state, that cannot conveniently be associated with
28369a command and reported as part of that command response.
28370
28371The important examples of notifications are:
28372@itemize @bullet
28373
28374@item
28375Exec notifications. These are used to report changes in
28376target state---when a target is resumed, or stopped. It would not
28377be feasible to include this information in response of resuming
28378commands, because one resume commands can result in multiple events in
28379different threads. Also, quite some time may pass before any event
28380happens in the target, while a frontend needs to know whether the resuming
28381command itself was successfully executed.
28382
28383@item
28384Console output, and status notifications. Console output
28385notifications are used to report output of CLI commands, as well as
28386diagnostics for other commands. Status notifications are used to
28387report the progress of a long-running operation. Naturally, including
28388this information in command response would mean no output is produced
28389until the command is finished, which is undesirable.
28390
28391@item
28392General notifications. Commands may have various side effects on
28393the @value{GDBN} or target state beyond their official purpose. For example,
28394a command may change the selected thread. Although such changes can
28395be included in command response, using notification allows for more
28396orthogonal frontend design.
28397
28398@end itemize
28399
28400There's no guarantee that whenever an MI command reports an error,
28401@value{GDBN} or the target are in any specific state, and especially,
28402the state is not reverted to the state before the MI command was
28403processed. Therefore, whenever an MI command results in an error,
28404we recommend that the frontend refreshes all the information shown in
28405the user interface.
28406
508094de
NR
28407
28408@menu
28409* Context management::
28410* Asynchronous and non-stop modes::
28411* Thread groups::
28412@end menu
28413
28414@node Context management
c3b108f7
VP
28415@subsection Context management
28416
403cb6b1
JB
28417@subsubsection Threads and Frames
28418
c3b108f7
VP
28419In most cases when @value{GDBN} accesses the target, this access is
28420done in context of a specific thread and frame (@pxref{Frames}).
28421Often, even when accessing global data, the target requires that a thread
28422be specified. The CLI interface maintains the selected thread and frame,
28423and supplies them to target on each command. This is convenient,
28424because a command line user would not want to specify that information
28425explicitly on each command, and because user interacts with
28426@value{GDBN} via a single terminal, so no confusion is possible as
28427to what thread and frame are the current ones.
28428
28429In the case of MI, the concept of selected thread and frame is less
28430useful. First, a frontend can easily remember this information
28431itself. Second, a graphical frontend can have more than one window,
28432each one used for debugging a different thread, and the frontend might
28433want to access additional threads for internal purposes. This
28434increases the risk that by relying on implicitly selected thread, the
28435frontend may be operating on a wrong one. Therefore, each MI command
28436should explicitly specify which thread and frame to operate on. To
28437make it possible, each MI command accepts the @samp{--thread} and
5d5658a1
PA
28438@samp{--frame} options, the value to each is @value{GDBN} global
28439identifier for thread and frame to operate on.
c3b108f7
VP
28440
28441Usually, each top-level window in a frontend allows the user to select
28442a thread and a frame, and remembers the user selection for further
28443operations. However, in some cases @value{GDBN} may suggest that the
4034d0ff
AT
28444current thread or frame be changed. For example, when stopping on a
28445breakpoint it is reasonable to switch to the thread where breakpoint is
28446hit. For another example, if the user issues the CLI @samp{thread} or
28447@samp{frame} commands via the frontend, it is desirable to change the
28448frontend's selection to the one specified by user. @value{GDBN}
28449communicates the suggestion to change current thread and frame using the
28450@samp{=thread-selected} notification.
c3b108f7
VP
28451
28452Note that historically, MI shares the selected thread with CLI, so
28453frontends used the @code{-thread-select} to execute commands in the
28454right context. However, getting this to work right is cumbersome. The
28455simplest way is for frontend to emit @code{-thread-select} command
28456before every command. This doubles the number of commands that need
28457to be sent. The alternative approach is to suppress @code{-thread-select}
28458if the selected thread in @value{GDBN} is supposed to be identical to the
28459thread the frontend wants to operate on. However, getting this
28460optimization right can be tricky. In particular, if the frontend
28461sends several commands to @value{GDBN}, and one of the commands changes the
28462selected thread, then the behaviour of subsequent commands will
28463change. So, a frontend should either wait for response from such
28464problematic commands, or explicitly add @code{-thread-select} for
28465all subsequent commands. No frontend is known to do this exactly
28466right, so it is suggested to just always pass the @samp{--thread} and
28467@samp{--frame} options.
28468
403cb6b1
JB
28469@subsubsection Language
28470
28471The execution of several commands depends on which language is selected.
28472By default, the current language (@pxref{show language}) is used.
28473But for commands known to be language-sensitive, it is recommended
28474to use the @samp{--language} option. This option takes one argument,
28475which is the name of the language to use while executing the command.
28476For instance:
28477
28478@smallexample
28479-data-evaluate-expression --language c "sizeof (void*)"
28480^done,value="4"
28481(gdb)
28482@end smallexample
28483
28484The valid language names are the same names accepted by the
28485@samp{set language} command (@pxref{Manually}), excluding @samp{auto},
28486@samp{local} or @samp{unknown}.
28487
508094de 28488@node Asynchronous and non-stop modes
c3b108f7
VP
28489@subsection Asynchronous command execution and non-stop mode
28490
28491On some targets, @value{GDBN} is capable of processing MI commands
28492even while the target is running. This is called @dfn{asynchronous
28493command execution} (@pxref{Background Execution}). The frontend may
6b92c0d3 28494specify a preference for asynchronous execution using the
329ea579 28495@code{-gdb-set mi-async 1} command, which should be emitted before
c3b108f7
VP
28496either running the executable or attaching to the target. After the
28497frontend has started the executable or attached to the target, it can
28498find if asynchronous execution is enabled using the
28499@code{-list-target-features} command.
28500
329ea579
PA
28501@table @code
28502@item -gdb-set mi-async on
28503@item -gdb-set mi-async off
28504Set whether MI is in asynchronous mode.
28505
28506When @code{off}, which is the default, MI execution commands (e.g.,
28507@code{-exec-continue}) are foreground commands, and @value{GDBN} waits
28508for the program to stop before processing further commands.
28509
28510When @code{on}, MI execution commands are background execution
28511commands (e.g., @code{-exec-continue} becomes the equivalent of the
28512@code{c&} CLI command), and so @value{GDBN} is capable of processing
28513MI commands even while the target is running.
28514
28515@item -gdb-show mi-async
28516Show whether MI asynchronous mode is enabled.
28517@end table
28518
28519Note: In @value{GDBN} version 7.7 and earlier, this option was called
28520@code{target-async} instead of @code{mi-async}, and it had the effect
28521of both putting MI in asynchronous mode and making CLI background
28522commands possible. CLI background commands are now always possible
28523``out of the box'' if the target supports them. The old spelling is
28524kept as a deprecated alias for backwards compatibility.
28525
c3b108f7
VP
28526Even if @value{GDBN} can accept a command while target is running,
28527many commands that access the target do not work when the target is
28528running. Therefore, asynchronous command execution is most useful
28529when combined with non-stop mode (@pxref{Non-Stop Mode}). Then,
28530it is possible to examine the state of one thread, while other threads
28531are running.
28532
28533When a given thread is running, MI commands that try to access the
28534target in the context of that thread may not work, or may work only on
28535some targets. In particular, commands that try to operate on thread's
28536stack will not work, on any target. Commands that read memory, or
28537modify breakpoints, may work or not work, depending on the target. Note
28538that even commands that operate on global state, such as @code{print},
28539@code{set}, and breakpoint commands, still access the target in the
28540context of a specific thread, so frontend should try to find a
28541stopped thread and perform the operation on that thread (using the
28542@samp{--thread} option).
28543
28544Which commands will work in the context of a running thread is
28545highly target dependent. However, the two commands
28546@code{-exec-interrupt}, to stop a thread, and @code{-thread-info},
28547to find the state of a thread, will always work.
28548
508094de 28549@node Thread groups
c3b108f7
VP
28550@subsection Thread groups
28551@value{GDBN} may be used to debug several processes at the same time.
6b92c0d3 28552On some platforms, @value{GDBN} may support debugging of several
c3b108f7
VP
28553hardware systems, each one having several cores with several different
28554processes running on each core. This section describes the MI
28555mechanism to support such debugging scenarios.
28556
28557The key observation is that regardless of the structure of the
28558target, MI can have a global list of threads, because most commands that
28559accept the @samp{--thread} option do not need to know what process that
28560thread belongs to. Therefore, it is not necessary to introduce
28561neither additional @samp{--process} option, nor an notion of the
28562current process in the MI interface. The only strictly new feature
28563that is required is the ability to find how the threads are grouped
28564into processes.
28565
28566To allow the user to discover such grouping, and to support arbitrary
28567hierarchy of machines/cores/processes, MI introduces the concept of a
28568@dfn{thread group}. Thread group is a collection of threads and other
28569thread groups. A thread group always has a string identifier, a type,
28570and may have additional attributes specific to the type. A new
28571command, @code{-list-thread-groups}, returns the list of top-level
28572thread groups, which correspond to processes that @value{GDBN} is
28573debugging at the moment. By passing an identifier of a thread group
28574to the @code{-list-thread-groups} command, it is possible to obtain
28575the members of specific thread group.
28576
28577To allow the user to easily discover processes, and other objects, he
28578wishes to debug, a concept of @dfn{available thread group} is
28579introduced. Available thread group is an thread group that
28580@value{GDBN} is not debugging, but that can be attached to, using the
28581@code{-target-attach} command. The list of available top-level thread
28582groups can be obtained using @samp{-list-thread-groups --available}.
28583In general, the content of a thread group may be only retrieved only
28584after attaching to that thread group.
28585
65c574f6 28586Thread groups are related to inferiors (@pxref{Inferiors Connections and
a79b8f6e
VP
28587Programs}). Each inferior corresponds to a thread group of a special
28588type @samp{process}, and some additional operations are permitted on
28589such thread groups.
28590
922fbb7b
AC
28591@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28592@node GDB/MI Command Syntax
28593@section @sc{gdb/mi} Command Syntax
28594
28595@menu
28596* GDB/MI Input Syntax::
28597* GDB/MI Output Syntax::
922fbb7b
AC
28598@end menu
28599
28600@node GDB/MI Input Syntax
28601@subsection @sc{gdb/mi} Input Syntax
28602
28603@cindex input syntax for @sc{gdb/mi}
28604@cindex @sc{gdb/mi}, input syntax
28605@table @code
28606@item @var{command} @expansion{}
28607@code{@var{cli-command} | @var{mi-command}}
28608
28609@item @var{cli-command} @expansion{}
28610@code{[ @var{token} ] @var{cli-command} @var{nl}}, where
28611@var{cli-command} is any existing @value{GDBN} CLI command.
28612
28613@item @var{mi-command} @expansion{}
28614@code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
28615@code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
28616
28617@item @var{token} @expansion{}
28618"any sequence of digits"
28619
28620@item @var{option} @expansion{}
28621@code{"-" @var{parameter} [ " " @var{parameter} ]}
28622
28623@item @var{parameter} @expansion{}
28624@code{@var{non-blank-sequence} | @var{c-string}}
28625
28626@item @var{operation} @expansion{}
28627@emph{any of the operations described in this chapter}
28628
28629@item @var{non-blank-sequence} @expansion{}
28630@emph{anything, provided it doesn't contain special characters such as
28631"-", @var{nl}, """ and of course " "}
28632
28633@item @var{c-string} @expansion{}
28634@code{""" @var{seven-bit-iso-c-string-content} """}
28635
28636@item @var{nl} @expansion{}
28637@code{CR | CR-LF}
28638@end table
28639
28640@noindent
28641Notes:
28642
28643@itemize @bullet
28644@item
28645The CLI commands are still handled by the @sc{mi} interpreter; their
28646output is described below.
28647
28648@item
28649The @code{@var{token}}, when present, is passed back when the command
28650finishes.
28651
28652@item
28653Some @sc{mi} commands accept optional arguments as part of the parameter
28654list. Each option is identified by a leading @samp{-} (dash) and may be
28655followed by an optional argument parameter. Options occur first in the
28656parameter list and can be delimited from normal parameters using
28657@samp{--} (this is useful when some parameters begin with a dash).
28658@end itemize
28659
28660Pragmatics:
28661
28662@itemize @bullet
28663@item
28664We want easy access to the existing CLI syntax (for debugging).
28665
28666@item
28667We want it to be easy to spot a @sc{mi} operation.
28668@end itemize
28669
28670@node GDB/MI Output Syntax
28671@subsection @sc{gdb/mi} Output Syntax
28672
28673@cindex output syntax of @sc{gdb/mi}
28674@cindex @sc{gdb/mi}, output syntax
28675The output from @sc{gdb/mi} consists of zero or more out-of-band records
28676followed, optionally, by a single result record. This result record
28677is for the most recent command. The sequence of output records is
594fe323 28678terminated by @samp{(gdb)}.
922fbb7b
AC
28679
28680If an input command was prefixed with a @code{@var{token}} then the
28681corresponding output for that command will also be prefixed by that same
28682@var{token}.
28683
28684@table @code
28685@item @var{output} @expansion{}
594fe323 28686@code{( @var{out-of-band-record} )* [ @var{result-record} ] "(gdb)" @var{nl}}
922fbb7b
AC
28687
28688@item @var{result-record} @expansion{}
28689@code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
28690
28691@item @var{out-of-band-record} @expansion{}
28692@code{@var{async-record} | @var{stream-record}}
28693
28694@item @var{async-record} @expansion{}
28695@code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
28696
28697@item @var{exec-async-output} @expansion{}
dcf106f3 28698@code{[ @var{token} ] "*" @var{async-output nl}}
922fbb7b
AC
28699
28700@item @var{status-async-output} @expansion{}
dcf106f3 28701@code{[ @var{token} ] "+" @var{async-output nl}}
922fbb7b
AC
28702
28703@item @var{notify-async-output} @expansion{}
dcf106f3 28704@code{[ @var{token} ] "=" @var{async-output nl}}
922fbb7b
AC
28705
28706@item @var{async-output} @expansion{}
dcf106f3 28707@code{@var{async-class} ( "," @var{result} )*}
922fbb7b
AC
28708
28709@item @var{result-class} @expansion{}
28710@code{"done" | "running" | "connected" | "error" | "exit"}
28711
28712@item @var{async-class} @expansion{}
28713@code{"stopped" | @var{others}} (where @var{others} will be added
28714depending on the needs---this is still in development).
28715
28716@item @var{result} @expansion{}
28717@code{ @var{variable} "=" @var{value}}
28718
28719@item @var{variable} @expansion{}
28720@code{ @var{string} }
28721
28722@item @var{value} @expansion{}
28723@code{ @var{const} | @var{tuple} | @var{list} }
28724
28725@item @var{const} @expansion{}
28726@code{@var{c-string}}
28727
28728@item @var{tuple} @expansion{}
28729@code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
28730
28731@item @var{list} @expansion{}
28732@code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
28733@var{result} ( "," @var{result} )* "]" }
28734
28735@item @var{stream-record} @expansion{}
28736@code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
28737
28738@item @var{console-stream-output} @expansion{}
dcf106f3 28739@code{"~" @var{c-string nl}}
922fbb7b
AC
28740
28741@item @var{target-stream-output} @expansion{}
dcf106f3 28742@code{"@@" @var{c-string nl}}
922fbb7b
AC
28743
28744@item @var{log-stream-output} @expansion{}
dcf106f3 28745@code{"&" @var{c-string nl}}
922fbb7b
AC
28746
28747@item @var{nl} @expansion{}
28748@code{CR | CR-LF}
28749
28750@item @var{token} @expansion{}
28751@emph{any sequence of digits}.
28752@end table
28753
28754@noindent
28755Notes:
28756
28757@itemize @bullet
28758@item
28759All output sequences end in a single line containing a period.
28760
28761@item
721c02de
VP
28762The @code{@var{token}} is from the corresponding request. Note that
28763for all async output, while the token is allowed by the grammar and
28764may be output by future versions of @value{GDBN} for select async
28765output messages, it is generally omitted. Frontends should treat
28766all async output as reporting general changes in the state of the
28767target and there should be no need to associate async output to any
28768prior command.
922fbb7b
AC
28769
28770@item
28771@cindex status output in @sc{gdb/mi}
28772@var{status-async-output} contains on-going status information about the
28773progress of a slow operation. It can be discarded. All status output is
28774prefixed by @samp{+}.
28775
28776@item
28777@cindex async output in @sc{gdb/mi}
28778@var{exec-async-output} contains asynchronous state change on the target
28779(stopped, started, disappeared). All async output is prefixed by
28780@samp{*}.
28781
28782@item
28783@cindex notify output in @sc{gdb/mi}
28784@var{notify-async-output} contains supplementary information that the
28785client should handle (e.g., a new breakpoint information). All notify
28786output is prefixed by @samp{=}.
28787
28788@item
28789@cindex console output in @sc{gdb/mi}
28790@var{console-stream-output} is output that should be displayed as is in the
28791console. It is the textual response to a CLI command. All the console
28792output is prefixed by @samp{~}.
28793
28794@item
28795@cindex target output in @sc{gdb/mi}
28796@var{target-stream-output} is the output produced by the target program.
28797All the target output is prefixed by @samp{@@}.
28798
28799@item
28800@cindex log output in @sc{gdb/mi}
28801@var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
28802instance messages that should be displayed as part of an error log. All
28803the log output is prefixed by @samp{&}.
28804
28805@item
28806@cindex list output in @sc{gdb/mi}
28807New @sc{gdb/mi} commands should only output @var{lists} containing
28808@var{values}.
28809
28810
28811@end itemize
28812
28813@xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
28814details about the various output records.
28815
922fbb7b
AC
28816@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28817@node GDB/MI Compatibility with CLI
28818@section @sc{gdb/mi} Compatibility with CLI
28819
28820@cindex compatibility, @sc{gdb/mi} and CLI
28821@cindex @sc{gdb/mi}, compatibility with CLI
922fbb7b 28822
a2c02241
NR
28823For the developers convenience CLI commands can be entered directly,
28824but there may be some unexpected behaviour. For example, commands
28825that query the user will behave as if the user replied yes, breakpoint
28826command lists are not executed and some CLI commands, such as
28827@code{if}, @code{when} and @code{define}, prompt for further input with
28828@samp{>}, which is not valid MI output.
ef21caaf
NR
28829
28830This feature may be removed at some stage in the future and it is
a2c02241
NR
28831recommended that front ends use the @code{-interpreter-exec} command
28832(@pxref{-interpreter-exec}).
922fbb7b 28833
af6eff6f
NR
28834@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28835@node GDB/MI Development and Front Ends
28836@section @sc{gdb/mi} Development and Front Ends
28837@cindex @sc{gdb/mi} development
28838
28839The application which takes the MI output and presents the state of the
28840program being debugged to the user is called a @dfn{front end}.
28841
1fea0d53
SM
28842Since @sc{gdb/mi} is used by a variety of front ends to @value{GDBN}, changes
28843to the MI interface may break existing usage. This section describes how the
28844protocol changes and how to request previous version of the protocol when it
28845does.
af6eff6f
NR
28846
28847Some changes in MI need not break a carefully designed front end, and
28848for these the MI version will remain unchanged. The following is a
28849list of changes that may occur within one level, so front ends should
28850parse MI output in a way that can handle them:
28851
28852@itemize @bullet
28853@item
28854New MI commands may be added.
28855
28856@item
28857New fields may be added to the output of any MI command.
28858
36ece8b3
NR
28859@item
28860The range of values for fields with specified values, e.g.,
9f708cb2 28861@code{in_scope} (@pxref{-var-update}) may be extended.
36ece8b3 28862
af6eff6f
NR
28863@c The format of field's content e.g type prefix, may change so parse it
28864@c at your own risk. Yes, in general?
28865
28866@c The order of fields may change? Shouldn't really matter but it might
28867@c resolve inconsistencies.
28868@end itemize
28869
28870If the changes are likely to break front ends, the MI version level
1fea0d53
SM
28871will be increased by one. The new versions of the MI protocol are not compatible
28872with the old versions. Old versions of MI remain available, allowing front ends
28873to keep using them until they are modified to use the latest MI version.
af6eff6f 28874
1fea0d53
SM
28875Since @code{--interpreter=mi} always points to the latest MI version, it is
28876recommended that front ends request a specific version of MI when launching
28877@value{GDBN} (e.g. @code{--interpreter=mi2}) to make sure they get an
28878interpreter with the MI version they expect.
28879
28880The following table gives a summary of the the released versions of the MI
28881interface: the version number, the version of GDB in which it first appeared
28882and the breaking changes compared to the previous version.
28883
28884@multitable @columnfractions .05 .05 .9
28885@headitem MI version @tab GDB version @tab Breaking changes
28886
28887@item
28888@center 1
28889@tab
28890@center 5.1
28891@tab
28892None
28893
28894@item
28895@center 2
28896@tab
28897@center 6.0
28898@tab
28899
28900@itemize
28901@item
28902The @code{-environment-pwd}, @code{-environment-directory} and
28903@code{-environment-path} commands now returns values using the MI output
28904syntax, rather than CLI output syntax.
28905
28906@item
28907@code{-var-list-children}'s @code{children} result field is now a list, rather
28908than a tuple.
28909
28910@item
28911@code{-var-update}'s @code{changelist} result field is now a list, rather than
28912a tuple.
28913@end itemize
28914
b4be1b06
SM
28915@item
28916@center 3
28917@tab
28918@center 9.1
28919@tab
28920
28921@itemize
28922@item
28923The output of information about multi-location breakpoints has changed in the
28924responses to the @code{-break-insert} and @code{-break-info} commands, as well
28925as in the @code{=breakpoint-created} and @code{=breakpoint-modified} events.
28926The multiple locations are now placed in a @code{locations} field, whose value
28927is a list.
28928@end itemize
28929
1fea0d53 28930@end multitable
af6eff6f 28931
b4be1b06
SM
28932If your front end cannot yet migrate to a more recent version of the
28933MI protocol, you can nevertheless selectively enable specific features
28934available in those recent MI versions, using the following commands:
28935
28936@table @code
28937
28938@item -fix-multi-location-breakpoint-output
28939Use the output for multi-location breakpoints which was introduced by
28940MI 3, even when using MI versions 2 or 1. This command has no
28941effect when using MI version 3 or later.
28942
5c85e20d 28943@end table
b4be1b06 28944
af6eff6f
NR
28945The best way to avoid unexpected changes in MI that might break your front
28946end is to make your project known to @value{GDBN} developers and
7a9a6b69 28947follow development on @email{gdb@@sourceware.org} and
fa0f268d 28948@email{gdb-patches@@sourceware.org}.
af6eff6f
NR
28949@cindex mailing lists
28950
922fbb7b
AC
28951@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28952@node GDB/MI Output Records
28953@section @sc{gdb/mi} Output Records
28954
28955@menu
28956* GDB/MI Result Records::
28957* GDB/MI Stream Records::
82f68b1c 28958* GDB/MI Async Records::
54516a0b 28959* GDB/MI Breakpoint Information::
c3b108f7 28960* GDB/MI Frame Information::
dc146f7c 28961* GDB/MI Thread Information::
4368ebeb 28962* GDB/MI Ada Exception Information::
922fbb7b
AC
28963@end menu
28964
28965@node GDB/MI Result Records
28966@subsection @sc{gdb/mi} Result Records
28967
28968@cindex result records in @sc{gdb/mi}
28969@cindex @sc{gdb/mi}, result records
28970In addition to a number of out-of-band notifications, the response to a
28971@sc{gdb/mi} command includes one of the following result indications:
28972
28973@table @code
28974@findex ^done
28975@item "^done" [ "," @var{results} ]
28976The synchronous operation was successful, @code{@var{results}} are the return
28977values.
28978
28979@item "^running"
28980@findex ^running
8e9c5e02
VP
28981This result record is equivalent to @samp{^done}. Historically, it
28982was output instead of @samp{^done} if the command has resumed the
28983target. This behaviour is maintained for backward compatibility, but
28984all frontends should treat @samp{^done} and @samp{^running}
28985identically and rely on the @samp{*running} output record to determine
28986which threads are resumed.
922fbb7b 28987
ef21caaf
NR
28988@item "^connected"
28989@findex ^connected
3f94c067 28990@value{GDBN} has connected to a remote target.
ef21caaf 28991
2ea126fa 28992@item "^error" "," "msg=" @var{c-string} [ "," "code=" @var{c-string} ]
922fbb7b 28993@findex ^error
2ea126fa
JB
28994The operation failed. The @code{msg=@var{c-string}} variable contains
28995the corresponding error message.
28996
28997If present, the @code{code=@var{c-string}} variable provides an error
28998code on which consumers can rely on to detect the corresponding
28999error condition. At present, only one error code is defined:
29000
29001@table @samp
29002@item "undefined-command"
29003Indicates that the command causing the error does not exist.
29004@end table
ef21caaf
NR
29005
29006@item "^exit"
29007@findex ^exit
3f94c067 29008@value{GDBN} has terminated.
ef21caaf 29009
922fbb7b
AC
29010@end table
29011
29012@node GDB/MI Stream Records
29013@subsection @sc{gdb/mi} Stream Records
29014
29015@cindex @sc{gdb/mi}, stream records
29016@cindex stream records in @sc{gdb/mi}
29017@value{GDBN} internally maintains a number of output streams: the console, the
29018target, and the log. The output intended for each of these streams is
29019funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
29020
29021Each stream record begins with a unique @dfn{prefix character} which
29022identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
29023Syntax}). In addition to the prefix, each stream record contains a
29024@code{@var{string-output}}. This is either raw text (with an implicit new
29025line) or a quoted C string (which does not contain an implicit newline).
29026
29027@table @code
29028@item "~" @var{string-output}
29029The console output stream contains text that should be displayed in the
29030CLI console window. It contains the textual responses to CLI commands.
29031
29032@item "@@" @var{string-output}
29033The target output stream contains any textual output from the running
ef21caaf
NR
29034target. This is only present when GDB's event loop is truly
29035asynchronous, which is currently only the case for remote targets.
922fbb7b
AC
29036
29037@item "&" @var{string-output}
29038The log stream contains debugging messages being produced by @value{GDBN}'s
29039internals.
29040@end table
29041
82f68b1c
VP
29042@node GDB/MI Async Records
29043@subsection @sc{gdb/mi} Async Records
922fbb7b 29044
82f68b1c
VP
29045@cindex async records in @sc{gdb/mi}
29046@cindex @sc{gdb/mi}, async records
29047@dfn{Async} records are used to notify the @sc{gdb/mi} client of
922fbb7b 29048additional changes that have occurred. Those changes can either be a
82f68b1c 29049consequence of @sc{gdb/mi} commands (e.g., a breakpoint modified) or a result of
922fbb7b
AC
29050target activity (e.g., target stopped).
29051
8eb41542 29052The following is the list of possible async records:
922fbb7b
AC
29053
29054@table @code
034dad6f 29055
e1ac3328 29056@item *running,thread-id="@var{thread}"
5d5658a1
PA
29057The target is now running. The @var{thread} field can be the global
29058thread ID of the the thread that is now running, and it can be
29059@samp{all} if all threads are running. The frontend should assume
29060that no interaction with a running thread is possible after this
29061notification is produced. The frontend should not assume that this
29062notification is output only once for any command. @value{GDBN} may
29063emit this notification several times, either for different threads,
29064because it cannot resume all threads together, or even for a single
29065thread, if the thread must be stepped though some code before letting
29066it run freely.
e1ac3328 29067
dc146f7c 29068@item *stopped,reason="@var{reason}",thread-id="@var{id}",stopped-threads="@var{stopped}",core="@var{core}"
82f68b1c
VP
29069The target has stopped. The @var{reason} field can have one of the
29070following values:
034dad6f
BR
29071
29072@table @code
29073@item breakpoint-hit
29074A breakpoint was reached.
29075@item watchpoint-trigger
29076A watchpoint was triggered.
29077@item read-watchpoint-trigger
29078A read watchpoint was triggered.
29079@item access-watchpoint-trigger
29080An access watchpoint was triggered.
29081@item function-finished
29082An -exec-finish or similar CLI command was accomplished.
29083@item location-reached
29084An -exec-until or similar CLI command was accomplished.
29085@item watchpoint-scope
29086A watchpoint has gone out of scope.
29087@item end-stepping-range
29088An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or
29089similar CLI command was accomplished.
29090@item exited-signalled
29091The inferior exited because of a signal.
29092@item exited
29093The inferior exited.
29094@item exited-normally
29095The inferior exited normally.
29096@item signal-received
29097A signal was received by the inferior.
36dfb11c
TT
29098@item solib-event
29099The inferior has stopped due to a library being loaded or unloaded.
edcc5120
TT
29100This can happen when @code{stop-on-solib-events} (@pxref{Files}) is
29101set or when a @code{catch load} or @code{catch unload} catchpoint is
29102in use (@pxref{Set Catchpoints}).
36dfb11c
TT
29103@item fork
29104The inferior has forked. This is reported when @code{catch fork}
29105(@pxref{Set Catchpoints}) has been used.
29106@item vfork
29107The inferior has vforked. This is reported in when @code{catch vfork}
29108(@pxref{Set Catchpoints}) has been used.
29109@item syscall-entry
29110The inferior entered a system call. This is reported when @code{catch
29111syscall} (@pxref{Set Catchpoints}) has been used.
a64c9f7b 29112@item syscall-return
36dfb11c
TT
29113The inferior returned from a system call. This is reported when
29114@code{catch syscall} (@pxref{Set Catchpoints}) has been used.
29115@item exec
29116The inferior called @code{exec}. This is reported when @code{catch exec}
29117(@pxref{Set Catchpoints}) has been used.
922fbb7b
AC
29118@end table
29119
5d5658a1
PA
29120The @var{id} field identifies the global thread ID of the thread
29121that directly caused the stop -- for example by hitting a breakpoint.
29122Depending on whether all-stop
c3b108f7
VP
29123mode is in effect (@pxref{All-Stop Mode}), @value{GDBN} may either
29124stop all threads, or only the thread that directly triggered the stop.
29125If all threads are stopped, the @var{stopped} field will have the
29126value of @code{"all"}. Otherwise, the value of the @var{stopped}
29127field will be a list of thread identifiers. Presently, this list will
29128always include a single thread, but frontend should be prepared to see
dc146f7c
VP
29129several threads in the list. The @var{core} field reports the
29130processor core on which the stop event has happened. This field may be absent
29131if such information is not available.
c3b108f7 29132
a79b8f6e
VP
29133@item =thread-group-added,id="@var{id}"
29134@itemx =thread-group-removed,id="@var{id}"
29135A thread group was either added or removed. The @var{id} field
29136contains the @value{GDBN} identifier of the thread group. When a thread
29137group is added, it generally might not be associated with a running
29138process. When a thread group is removed, its id becomes invalid and
29139cannot be used in any way.
29140
29141@item =thread-group-started,id="@var{id}",pid="@var{pid}"
29142A thread group became associated with a running program,
29143either because the program was just started or the thread group
29144was attached to a program. The @var{id} field contains the
29145@value{GDBN} identifier of the thread group. The @var{pid} field
29146contains process identifier, specific to the operating system.
29147
8cf64490 29148@item =thread-group-exited,id="@var{id}"[,exit-code="@var{code}"]
a79b8f6e
VP
29149A thread group is no longer associated with a running program,
29150either because the program has exited, or because it was detached
c3b108f7 29151from. The @var{id} field contains the @value{GDBN} identifier of the
697aa1b7 29152thread group. The @var{code} field is the exit code of the inferior; it exists
8cf64490 29153only when the inferior exited with some code.
c3b108f7
VP
29154
29155@item =thread-created,id="@var{id}",group-id="@var{gid}"
29156@itemx =thread-exited,id="@var{id}",group-id="@var{gid}"
82f68b1c 29157A thread either was created, or has exited. The @var{id} field
5d5658a1 29158contains the global @value{GDBN} identifier of the thread. The @var{gid}
c3b108f7 29159field identifies the thread group this thread belongs to.
66bb093b 29160
4034d0ff
AT
29161@item =thread-selected,id="@var{id}"[,frame="@var{frame}"]
29162Informs that the selected thread or frame were changed. This notification
29163is not emitted as result of the @code{-thread-select} or
29164@code{-stack-select-frame} commands, but is emitted whenever an MI command
29165that is not documented to change the selected thread and frame actually
29166changes them. In particular, invoking, directly or indirectly
29167(via user-defined command), the CLI @code{thread} or @code{frame} commands,
29168will generate this notification. Changing the thread or frame from another
29169user interface (see @ref{Interpreters}) will also generate this notification.
29170
29171The @var{frame} field is only present if the newly selected thread is
29172stopped. See @ref{GDB/MI Frame Information} for the format of its value.
66bb093b
VP
29173
29174We suggest that in response to this notification, front ends
29175highlight the selected thread and cause subsequent commands to apply to
29176that thread.
29177
c86cf029
VP
29178@item =library-loaded,...
29179Reports that a new library file was loaded by the program. This
51457a05
MAL
29180notification has 5 fields---@var{id}, @var{target-name},
29181@var{host-name}, @var{symbols-loaded} and @var{ranges}. The @var{id} field is an
c86cf029
VP
29182opaque identifier of the library. For remote debugging case,
29183@var{target-name} and @var{host-name} fields give the name of the
134eb42c
VP
29184library file on the target, and on the host respectively. For native
29185debugging, both those fields have the same value. The
f1cbe1d3
TT
29186@var{symbols-loaded} field is emitted only for backward compatibility
29187and should not be relied on to convey any useful information. The
29188@var{thread-group} field, if present, specifies the id of the thread
29189group in whose context the library was loaded. If the field is
29190absent, it means the library was loaded in the context of all present
51457a05
MAL
29191thread groups. The @var{ranges} field specifies the ranges of addresses belonging
29192to this library.
c86cf029
VP
29193
29194@item =library-unloaded,...
134eb42c 29195Reports that a library was unloaded by the program. This notification
c86cf029 29196has 3 fields---@var{id}, @var{target-name} and @var{host-name} with
a79b8f6e
VP
29197the same meaning as for the @code{=library-loaded} notification.
29198The @var{thread-group} field, if present, specifies the id of the
29199thread group in whose context the library was unloaded. If the field is
29200absent, it means the library was unloaded in the context of all present
29201thread groups.
c86cf029 29202
201b4506
YQ
29203@item =traceframe-changed,num=@var{tfnum},tracepoint=@var{tpnum}
29204@itemx =traceframe-changed,end
29205Reports that the trace frame was changed and its new number is
29206@var{tfnum}. The number of the tracepoint associated with this trace
29207frame is @var{tpnum}.
29208
134a2066 29209@item =tsv-created,name=@var{name},initial=@var{initial}
bb25a15c 29210Reports that the new trace state variable @var{name} is created with
134a2066 29211initial value @var{initial}.
bb25a15c
YQ
29212
29213@item =tsv-deleted,name=@var{name}
29214@itemx =tsv-deleted
29215Reports that the trace state variable @var{name} is deleted or all
29216trace state variables are deleted.
29217
134a2066
YQ
29218@item =tsv-modified,name=@var{name},initial=@var{initial}[,current=@var{current}]
29219Reports that the trace state variable @var{name} is modified with
29220the initial value @var{initial}. The current value @var{current} of
29221trace state variable is optional and is reported if the current
29222value of trace state variable is known.
29223
8d3788bd
VP
29224@item =breakpoint-created,bkpt=@{...@}
29225@itemx =breakpoint-modified,bkpt=@{...@}
d9f08f52 29226@itemx =breakpoint-deleted,id=@var{number}
8d3788bd
VP
29227Reports that a breakpoint was created, modified, or deleted,
29228respectively. Only user-visible breakpoints are reported to the MI
29229user.
29230
29231The @var{bkpt} argument is of the same form as returned by the various
d9f08f52
YQ
29232breakpoint commands; @xref{GDB/MI Breakpoint Commands}. The
29233@var{number} is the ordinal number of the breakpoint.
8d3788bd
VP
29234
29235Note that if a breakpoint is emitted in the result record of a
29236command, then it will not also be emitted in an async record.
29237
38b022b4 29238@item =record-started,thread-group="@var{id}",method="@var{method}"[,format="@var{format}"]
82a90ccf
YQ
29239@itemx =record-stopped,thread-group="@var{id}"
29240Execution log recording was either started or stopped on an
29241inferior. The @var{id} is the @value{GDBN} identifier of the thread
29242group corresponding to the affected inferior.
29243
38b022b4
SM
29244The @var{method} field indicates the method used to record execution. If the
29245method in use supports multiple recording formats, @var{format} will be present
8504e097 29246and contain the currently used format. @xref{Process Record and Replay},
38b022b4
SM
29247for existing method and format values.
29248
5b9afe8a
YQ
29249@item =cmd-param-changed,param=@var{param},value=@var{value}
29250Reports that a parameter of the command @code{set @var{param}} is
29251changed to @var{value}. In the multi-word @code{set} command,
29252the @var{param} is the whole parameter list to @code{set} command.
29253For example, In command @code{set check type on}, @var{param}
29254is @code{check type} and @var{value} is @code{on}.
8de0566d
YQ
29255
29256@item =memory-changed,thread-group=@var{id},addr=@var{addr},len=@var{len}[,type="code"]
29257Reports that bytes from @var{addr} to @var{data} + @var{len} were
29258written in an inferior. The @var{id} is the identifier of the
29259thread group corresponding to the affected inferior. The optional
29260@code{type="code"} part is reported if the memory written to holds
29261executable code.
82f68b1c
VP
29262@end table
29263
54516a0b
TT
29264@node GDB/MI Breakpoint Information
29265@subsection @sc{gdb/mi} Breakpoint Information
29266
29267When @value{GDBN} reports information about a breakpoint, a
29268tracepoint, a watchpoint, or a catchpoint, it uses a tuple with the
29269following fields:
29270
29271@table @code
29272@item number
b4be1b06 29273The breakpoint number.
54516a0b
TT
29274
29275@item type
29276The type of the breakpoint. For ordinary breakpoints this will be
29277@samp{breakpoint}, but many values are possible.
29278
8ac3646f
TT
29279@item catch-type
29280If the type of the breakpoint is @samp{catchpoint}, then this
29281indicates the exact type of catchpoint.
29282
54516a0b
TT
29283@item disp
29284This is the breakpoint disposition---either @samp{del}, meaning that
29285the breakpoint will be deleted at the next stop, or @samp{keep},
29286meaning that the breakpoint will not be deleted.
29287
29288@item enabled
29289This indicates whether the breakpoint is enabled, in which case the
29290value is @samp{y}, or disabled, in which case the value is @samp{n}.
29291Note that this is not the same as the field @code{enable}.
29292
29293@item addr
29294The address of the breakpoint. This may be a hexidecimal number,
29295giving the address; or the string @samp{<PENDING>}, for a pending
29296breakpoint; or the string @samp{<MULTIPLE>}, for a breakpoint with
29297multiple locations. This field will not be present if no address can
29298be determined. For example, a watchpoint does not have an address.
29299
aa7ca1bb
AH
29300@item addr_flags
29301Optional field containing any flags related to the address. These flags are
29302architecture-dependent; see @ref{Architectures} for their meaning for a
29303particular CPU.
29304
54516a0b
TT
29305@item func
29306If known, the function in which the breakpoint appears.
29307If not known, this field is not present.
29308
29309@item filename
29310The name of the source file which contains this function, if known.
29311If not known, this field is not present.
29312
29313@item fullname
29314The full file name of the source file which contains this function, if
29315known. If not known, this field is not present.
29316
29317@item line
29318The line number at which this breakpoint appears, if known.
29319If not known, this field is not present.
29320
29321@item at
29322If the source file is not known, this field may be provided. If
29323provided, this holds the address of the breakpoint, possibly followed
29324by a symbol name.
29325
29326@item pending
29327If this breakpoint is pending, this field is present and holds the
29328text used to set the breakpoint, as entered by the user.
29329
29330@item evaluated-by
29331Where this breakpoint's condition is evaluated, either @samp{host} or
29332@samp{target}.
29333
29334@item thread
29335If this is a thread-specific breakpoint, then this identifies the
29336thread in which the breakpoint can trigger.
29337
29338@item task
29339If this breakpoint is restricted to a particular Ada task, then this
29340field will hold the task identifier.
29341
29342@item cond
29343If the breakpoint is conditional, this is the condition expression.
29344
29345@item ignore
29346The ignore count of the breakpoint.
29347
29348@item enable
29349The enable count of the breakpoint.
29350
29351@item traceframe-usage
29352FIXME.
29353
29354@item static-tracepoint-marker-string-id
29355For a static tracepoint, the name of the static tracepoint marker.
29356
29357@item mask
29358For a masked watchpoint, this is the mask.
29359
29360@item pass
29361A tracepoint's pass count.
29362
29363@item original-location
29364The location of the breakpoint as originally specified by the user.
29365This field is optional.
29366
29367@item times
29368The number of times the breakpoint has been hit.
29369
29370@item installed
29371This field is only given for tracepoints. This is either @samp{y},
29372meaning that the tracepoint is installed, or @samp{n}, meaning that it
29373is not.
29374
29375@item what
29376Some extra data, the exact contents of which are type-dependent.
29377
b4be1b06
SM
29378@item locations
29379This field is present if the breakpoint has multiple locations. It is also
29380exceptionally present if the breakpoint is enabled and has a single, disabled
29381location.
29382
6b92c0d3 29383The value is a list of locations. The format of a location is described below.
b4be1b06
SM
29384
29385@end table
29386
29387A location in a multi-location breakpoint is represented as a tuple with the
29388following fields:
29389
29390@table @code
29391
29392@item number
29393The location number as a dotted pair, like @samp{1.2}. The first digit is the
29394number of the parent breakpoint. The second digit is the number of the
29395location within that breakpoint.
29396
29397@item enabled
29398This indicates whether the location is enabled, in which case the
29399value is @samp{y}, or disabled, in which case the value is @samp{n}.
29400Note that this is not the same as the field @code{enable}.
29401
29402@item addr
29403The address of this location as an hexidecimal number.
29404
aa7ca1bb
AH
29405@item addr_flags
29406Optional field containing any flags related to the address. These flags are
29407architecture-dependent; see @ref{Architectures} for their meaning for a
29408particular CPU.
29409
b4be1b06
SM
29410@item func
29411If known, the function in which the location appears.
29412If not known, this field is not present.
29413
29414@item file
29415The name of the source file which contains this location, if known.
29416If not known, this field is not present.
29417
29418@item fullname
29419The full file name of the source file which contains this location, if
29420known. If not known, this field is not present.
29421
29422@item line
29423The line number at which this location appears, if known.
29424If not known, this field is not present.
29425
29426@item thread-groups
29427The thread groups this location is in.
29428
54516a0b
TT
29429@end table
29430
29431For example, here is what the output of @code{-break-insert}
29432(@pxref{GDB/MI Breakpoint Commands}) might be:
29433
29434@smallexample
29435-> -break-insert main
29436<- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
29437 enabled="y",addr="0x08048564",func="main",file="myprog.c",
998580f1
MK
29438 fullname="/home/nickrob/myprog.c",line="68",thread-groups=["i1"],
29439 times="0"@}
54516a0b
TT
29440<- (gdb)
29441@end smallexample
29442
c3b108f7
VP
29443@node GDB/MI Frame Information
29444@subsection @sc{gdb/mi} Frame Information
29445
29446Response from many MI commands includes an information about stack
29447frame. This information is a tuple that may have the following
29448fields:
29449
29450@table @code
29451@item level
29452The level of the stack frame. The innermost frame has the level of
29453zero. This field is always present.
29454
29455@item func
29456The name of the function corresponding to the frame. This field may
29457be absent if @value{GDBN} is unable to determine the function name.
29458
29459@item addr
29460The code address for the frame. This field is always present.
29461
aa7ca1bb
AH
29462@item addr_flags
29463Optional field containing any flags related to the address. These flags are
29464architecture-dependent; see @ref{Architectures} for their meaning for a
29465particular CPU.
29466
c3b108f7
VP
29467@item file
29468The name of the source files that correspond to the frame's code
29469address. This field may be absent.
29470
29471@item line
29472The source line corresponding to the frames' code address. This field
29473may be absent.
29474
29475@item from
29476The name of the binary file (either executable or shared library) the
29477corresponds to the frame's code address. This field may be absent.
29478
29479@end table
82f68b1c 29480
dc146f7c
VP
29481@node GDB/MI Thread Information
29482@subsection @sc{gdb/mi} Thread Information
29483
29484Whenever @value{GDBN} has to report an information about a thread, it
ebe553db
SM
29485uses a tuple with the following fields. The fields are always present unless
29486stated otherwise.
dc146f7c
VP
29487
29488@table @code
29489@item id
ebe553db 29490The global numeric id assigned to the thread by @value{GDBN}.
dc146f7c
VP
29491
29492@item target-id
ebe553db 29493The target-specific string identifying the thread.
dc146f7c
VP
29494
29495@item details
29496Additional information about the thread provided by the target.
29497It is supposed to be human-readable and not interpreted by the
29498frontend. This field is optional.
29499
ebe553db
SM
29500@item name
29501The name of the thread. If the user specified a name using the
29502@code{thread name} command, then this name is given. Otherwise, if
29503@value{GDBN} can extract the thread name from the target, then that
29504name is given. If @value{GDBN} cannot find the thread name, then this
29505field is omitted.
29506
dc146f7c 29507@item state
ebe553db
SM
29508The execution state of the thread, either @samp{stopped} or @samp{running},
29509depending on whether the thread is presently running.
29510
29511@item frame
29512The stack frame currently executing in the thread. This field is only present
29513if the thread is stopped. Its format is documented in
29514@ref{GDB/MI Frame Information}.
dc146f7c
VP
29515
29516@item core
29517The value of this field is an integer number of the processor core the
29518thread was last seen on. This field is optional.
29519@end table
29520
956a9fb9
JB
29521@node GDB/MI Ada Exception Information
29522@subsection @sc{gdb/mi} Ada Exception Information
29523
29524Whenever a @code{*stopped} record is emitted because the program
29525stopped after hitting an exception catchpoint (@pxref{Set Catchpoints}),
29526@value{GDBN} provides the name of the exception that was raised via
e547c119
JB
29527the @code{exception-name} field. Also, for exceptions that were raised
29528with an exception message, @value{GDBN} provides that message via
29529the @code{exception-message} field.
922fbb7b 29530
ef21caaf
NR
29531@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29532@node GDB/MI Simple Examples
29533@section Simple Examples of @sc{gdb/mi} Interaction
29534@cindex @sc{gdb/mi}, simple examples
29535
29536This subsection presents several simple examples of interaction using
29537the @sc{gdb/mi} interface. In these examples, @samp{->} means that the
29538following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
29539the output received from @sc{gdb/mi}.
29540
d3e8051b 29541Note the line breaks shown in the examples are here only for
ef21caaf
NR
29542readability, they don't appear in the real output.
29543
79a6e687 29544@subheading Setting a Breakpoint
ef21caaf
NR
29545
29546Setting a breakpoint generates synchronous output which contains detailed
29547information of the breakpoint.
29548
29549@smallexample
29550-> -break-insert main
29551<- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
29552 enabled="y",addr="0x08048564",func="main",file="myprog.c",
998580f1
MK
29553 fullname="/home/nickrob/myprog.c",line="68",thread-groups=["i1"],
29554 times="0"@}
ef21caaf
NR
29555<- (gdb)
29556@end smallexample
29557
29558@subheading Program Execution
29559
29560Program execution generates asynchronous records and MI gives the
29561reason that execution stopped.
29562
29563@smallexample
29564-> -exec-run
29565<- ^running
29566<- (gdb)
a47ec5fe 29567<- *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
ef21caaf
NR
29568 frame=@{addr="0x08048564",func="main",
29569 args=[@{name="argc",value="1"@},@{name="argv",value="0xbfc4d4d4"@}],
6d52907e
JV
29570 file="myprog.c",fullname="/home/nickrob/myprog.c",line="68",
29571 arch="i386:x86_64"@}
ef21caaf
NR
29572<- (gdb)
29573-> -exec-continue
29574<- ^running
29575<- (gdb)
29576<- *stopped,reason="exited-normally"
29577<- (gdb)
29578@end smallexample
29579
3f94c067 29580@subheading Quitting @value{GDBN}
ef21caaf 29581
3f94c067 29582Quitting @value{GDBN} just prints the result class @samp{^exit}.
ef21caaf
NR
29583
29584@smallexample
29585-> (gdb)
29586<- -gdb-exit
29587<- ^exit
29588@end smallexample
29589
a6b29f87
VP
29590Please note that @samp{^exit} is printed immediately, but it might
29591take some time for @value{GDBN} to actually exit. During that time, @value{GDBN}
29592performs necessary cleanups, including killing programs being debugged
29593or disconnecting from debug hardware, so the frontend should wait till
29594@value{GDBN} exits and should only forcibly kill @value{GDBN} if it
29595fails to exit in reasonable time.
29596
a2c02241 29597@subheading A Bad Command
ef21caaf
NR
29598
29599Here's what happens if you pass a non-existent command:
29600
29601@smallexample
29602-> -rubbish
29603<- ^error,msg="Undefined MI command: rubbish"
594fe323 29604<- (gdb)
ef21caaf
NR
29605@end smallexample
29606
29607
922fbb7b
AC
29608@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29609@node GDB/MI Command Description Format
29610@section @sc{gdb/mi} Command Description Format
29611
29612The remaining sections describe blocks of commands. Each block of
29613commands is laid out in a fashion similar to this section.
29614
922fbb7b
AC
29615@subheading Motivation
29616
29617The motivation for this collection of commands.
29618
29619@subheading Introduction
29620
29621A brief introduction to this collection of commands as a whole.
29622
29623@subheading Commands
29624
29625For each command in the block, the following is described:
29626
29627@subsubheading Synopsis
29628
29629@smallexample
29630 -command @var{args}@dots{}
29631@end smallexample
29632
922fbb7b
AC
29633@subsubheading Result
29634
265eeb58 29635@subsubheading @value{GDBN} Command
922fbb7b 29636
265eeb58 29637The corresponding @value{GDBN} CLI command(s), if any.
922fbb7b
AC
29638
29639@subsubheading Example
29640
ef21caaf
NR
29641Example(s) formatted for readability. Some of the described commands have
29642not been implemented yet and these are labeled N.A.@: (not available).
29643
29644
922fbb7b 29645@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ef21caaf
NR
29646@node GDB/MI Breakpoint Commands
29647@section @sc{gdb/mi} Breakpoint Commands
922fbb7b
AC
29648
29649@cindex breakpoint commands for @sc{gdb/mi}
29650@cindex @sc{gdb/mi}, breakpoint commands
29651This section documents @sc{gdb/mi} commands for manipulating
29652breakpoints.
29653
29654@subheading The @code{-break-after} Command
29655@findex -break-after
29656
29657@subsubheading Synopsis
29658
29659@smallexample
29660 -break-after @var{number} @var{count}
29661@end smallexample
29662
29663The breakpoint number @var{number} is not in effect until it has been
29664hit @var{count} times. To see how this is reflected in the output of
29665the @samp{-break-list} command, see the description of the
29666@samp{-break-list} command below.
29667
29668@subsubheading @value{GDBN} Command
29669
29670The corresponding @value{GDBN} command is @samp{ignore}.
29671
29672@subsubheading Example
29673
29674@smallexample
594fe323 29675(gdb)
922fbb7b 29676-break-insert main
a47ec5fe
AR
29677^done,bkpt=@{number="1",type="breakpoint",disp="keep",
29678enabled="y",addr="0x000100d0",func="main",file="hello.c",
998580f1
MK
29679fullname="/home/foo/hello.c",line="5",thread-groups=["i1"],
29680times="0"@}
594fe323 29681(gdb)
922fbb7b
AC
29682-break-after 1 3
29683~
29684^done
594fe323 29685(gdb)
922fbb7b
AC
29686-break-list
29687^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
29688hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
29689@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
29690@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
29691@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
29692@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
29693@{width="40",alignment="2",col_name="what",colhdr="What"@}],
29694body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102 29695addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
998580f1 29696line="5",thread-groups=["i1"],times="0",ignore="3"@}]@}
594fe323 29697(gdb)
922fbb7b
AC
29698@end smallexample
29699
29700@ignore
29701@subheading The @code{-break-catch} Command
29702@findex -break-catch
48cb2d85 29703@end ignore
922fbb7b
AC
29704
29705@subheading The @code{-break-commands} Command
29706@findex -break-commands
922fbb7b 29707
48cb2d85
VP
29708@subsubheading Synopsis
29709
29710@smallexample
29711 -break-commands @var{number} [ @var{command1} ... @var{commandN} ]
29712@end smallexample
29713
29714Specifies the CLI commands that should be executed when breakpoint
29715@var{number} is hit. The parameters @var{command1} to @var{commandN}
29716are the commands. If no command is specified, any previously-set
29717commands are cleared. @xref{Break Commands}. Typical use of this
29718functionality is tracing a program, that is, printing of values of
29719some variables whenever breakpoint is hit and then continuing.
29720
29721@subsubheading @value{GDBN} Command
29722
29723The corresponding @value{GDBN} command is @samp{commands}.
29724
29725@subsubheading Example
29726
29727@smallexample
29728(gdb)
29729-break-insert main
29730^done,bkpt=@{number="1",type="breakpoint",disp="keep",
29731enabled="y",addr="0x000100d0",func="main",file="hello.c",
998580f1
MK
29732fullname="/home/foo/hello.c",line="5",thread-groups=["i1"],
29733times="0"@}
48cb2d85
VP
29734(gdb)
29735-break-commands 1 "print v" "continue"
29736^done
29737(gdb)
29738@end smallexample
922fbb7b
AC
29739
29740@subheading The @code{-break-condition} Command
29741@findex -break-condition
29742
29743@subsubheading Synopsis
29744
29745@smallexample
29746 -break-condition @var{number} @var{expr}
29747@end smallexample
29748
29749Breakpoint @var{number} will stop the program only if the condition in
29750@var{expr} is true. The condition becomes part of the
29751@samp{-break-list} output (see the description of the @samp{-break-list}
29752command below).
29753
29754@subsubheading @value{GDBN} Command
29755
29756The corresponding @value{GDBN} command is @samp{condition}.
29757
29758@subsubheading Example
29759
29760@smallexample
594fe323 29761(gdb)
922fbb7b
AC
29762-break-condition 1 1
29763^done
594fe323 29764(gdb)
922fbb7b
AC
29765-break-list
29766^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
29767hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
29768@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
29769@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
29770@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
29771@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
29772@{width="40",alignment="2",col_name="what",colhdr="What"@}],
29773body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102 29774addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
998580f1 29775line="5",cond="1",thread-groups=["i1"],times="0",ignore="3"@}]@}
594fe323 29776(gdb)
922fbb7b
AC
29777@end smallexample
29778
29779@subheading The @code{-break-delete} Command
29780@findex -break-delete
29781
29782@subsubheading Synopsis
29783
29784@smallexample
29785 -break-delete ( @var{breakpoint} )+
29786@end smallexample
29787
29788Delete the breakpoint(s) whose number(s) are specified in the argument
29789list. This is obviously reflected in the breakpoint list.
29790
79a6e687 29791@subsubheading @value{GDBN} Command
922fbb7b
AC
29792
29793The corresponding @value{GDBN} command is @samp{delete}.
29794
29795@subsubheading Example
29796
29797@smallexample
594fe323 29798(gdb)
922fbb7b
AC
29799-break-delete 1
29800^done
594fe323 29801(gdb)
922fbb7b
AC
29802-break-list
29803^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
29804hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
29805@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
29806@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
29807@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
29808@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
29809@{width="40",alignment="2",col_name="what",colhdr="What"@}],
29810body=[]@}
594fe323 29811(gdb)
922fbb7b
AC
29812@end smallexample
29813
29814@subheading The @code{-break-disable} Command
29815@findex -break-disable
29816
29817@subsubheading Synopsis
29818
29819@smallexample
29820 -break-disable ( @var{breakpoint} )+
29821@end smallexample
29822
29823Disable the named @var{breakpoint}(s). The field @samp{enabled} in the
29824break list is now set to @samp{n} for the named @var{breakpoint}(s).
29825
29826@subsubheading @value{GDBN} Command
29827
29828The corresponding @value{GDBN} command is @samp{disable}.
29829
29830@subsubheading Example
29831
29832@smallexample
594fe323 29833(gdb)
922fbb7b
AC
29834-break-disable 2
29835^done
594fe323 29836(gdb)
922fbb7b
AC
29837-break-list
29838^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
29839hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
29840@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
29841@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
29842@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
29843@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
29844@{width="40",alignment="2",col_name="what",colhdr="What"@}],
29845body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
948d5102 29846addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
998580f1 29847line="5",thread-groups=["i1"],times="0"@}]@}
594fe323 29848(gdb)
922fbb7b
AC
29849@end smallexample
29850
29851@subheading The @code{-break-enable} Command
29852@findex -break-enable
29853
29854@subsubheading Synopsis
29855
29856@smallexample
29857 -break-enable ( @var{breakpoint} )+
29858@end smallexample
29859
29860Enable (previously disabled) @var{breakpoint}(s).
29861
29862@subsubheading @value{GDBN} Command
29863
29864The corresponding @value{GDBN} command is @samp{enable}.
29865
29866@subsubheading Example
29867
29868@smallexample
594fe323 29869(gdb)
922fbb7b
AC
29870-break-enable 2
29871^done
594fe323 29872(gdb)
922fbb7b
AC
29873-break-list
29874^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
29875hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
29876@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
29877@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
29878@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
29879@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
29880@{width="40",alignment="2",col_name="what",colhdr="What"@}],
29881body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
948d5102 29882addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
998580f1 29883line="5",thread-groups=["i1"],times="0"@}]@}
594fe323 29884(gdb)
922fbb7b
AC
29885@end smallexample
29886
29887@subheading The @code{-break-info} Command
29888@findex -break-info
29889
29890@subsubheading Synopsis
29891
29892@smallexample
29893 -break-info @var{breakpoint}
29894@end smallexample
29895
29896@c REDUNDANT???
29897Get information about a single breakpoint.
29898
54516a0b
TT
29899The result is a table of breakpoints. @xref{GDB/MI Breakpoint
29900Information}, for details on the format of each breakpoint in the
29901table.
29902
79a6e687 29903@subsubheading @value{GDBN} Command
922fbb7b
AC
29904
29905The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
29906
29907@subsubheading Example
29908N.A.
29909
29910@subheading The @code{-break-insert} Command
29911@findex -break-insert
629500fa 29912@anchor{-break-insert}
922fbb7b
AC
29913
29914@subsubheading Synopsis
29915
29916@smallexample
18148017 29917 -break-insert [ -t ] [ -h ] [ -f ] [ -d ] [ -a ]
922fbb7b 29918 [ -c @var{condition} ] [ -i @var{ignore-count} ]
472a2379 29919 [ -p @var{thread-id} ] [ @var{location} ]
922fbb7b
AC
29920@end smallexample
29921
29922@noindent
afe8ab22 29923If specified, @var{location}, can be one of:
922fbb7b 29924
629500fa
KS
29925@table @var
29926@item linespec location
29927A linespec location. @xref{Linespec Locations}.
29928
29929@item explicit location
29930An explicit location. @sc{gdb/mi} explicit locations are
29931analogous to the CLI's explicit locations using the option names
29932listed below. @xref{Explicit Locations}.
29933
29934@table @samp
29935@item --source @var{filename}
29936The source file name of the location. This option requires the use
29937of either @samp{--function} or @samp{--line}.
29938
29939@item --function @var{function}
29940The name of a function or method.
922fbb7b 29941
629500fa
KS
29942@item --label @var{label}
29943The name of a label.
29944
29945@item --line @var{lineoffset}
29946An absolute or relative line offset from the start of the location.
29947@end table
29948
29949@item address location
29950An address location, *@var{address}. @xref{Address Locations}.
29951@end table
29952
29953@noindent
922fbb7b
AC
29954The possible optional parameters of this command are:
29955
29956@table @samp
29957@item -t
948d5102 29958Insert a temporary breakpoint.
922fbb7b
AC
29959@item -h
29960Insert a hardware breakpoint.
afe8ab22
VP
29961@item -f
29962If @var{location} cannot be parsed (for example if it
29963refers to unknown files or functions), create a pending
29964breakpoint. Without this flag, @value{GDBN} will report
29965an error, and won't create a breakpoint, if @var{location}
29966cannot be parsed.
41447f92
VP
29967@item -d
29968Create a disabled breakpoint.
18148017
VP
29969@item -a
29970Create a tracepoint. @xref{Tracepoints}. When this parameter
29971is used together with @samp{-h}, a fast tracepoint is created.
472a2379
KS
29972@item -c @var{condition}
29973Make the breakpoint conditional on @var{condition}.
29974@item -i @var{ignore-count}
29975Initialize the @var{ignore-count}.
29976@item -p @var{thread-id}
5d5658a1
PA
29977Restrict the breakpoint to the thread with the specified global
29978@var{thread-id}.
922fbb7b
AC
29979@end table
29980
29981@subsubheading Result
29982
54516a0b
TT
29983@xref{GDB/MI Breakpoint Information}, for details on the format of the
29984resulting breakpoint.
922fbb7b
AC
29985
29986Note: this format is open to change.
29987@c An out-of-band breakpoint instead of part of the result?
29988
29989@subsubheading @value{GDBN} Command
29990
29991The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
496ee73e 29992@samp{hbreak}, and @samp{thbreak}. @c and @samp{rbreak}.
922fbb7b
AC
29993
29994@subsubheading Example
29995
29996@smallexample
594fe323 29997(gdb)
922fbb7b 29998-break-insert main
948d5102 29999^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",
998580f1
MK
30000fullname="/home/foo/recursive2.c,line="4",thread-groups=["i1"],
30001times="0"@}
594fe323 30002(gdb)
922fbb7b 30003-break-insert -t foo
948d5102 30004^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",
998580f1
MK
30005fullname="/home/foo/recursive2.c,line="11",thread-groups=["i1"],
30006times="0"@}
594fe323 30007(gdb)
922fbb7b
AC
30008-break-list
30009^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30010hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30011@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30012@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30013@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30014@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30015@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30016body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
948d5102 30017addr="0x0001072c", func="main",file="recursive2.c",
998580f1
MK
30018fullname="/home/foo/recursive2.c,"line="4",thread-groups=["i1"],
30019times="0"@},
922fbb7b 30020bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
948d5102 30021addr="0x00010774",func="foo",file="recursive2.c",
998580f1
MK
30022fullname="/home/foo/recursive2.c",line="11",thread-groups=["i1"],
30023times="0"@}]@}
594fe323 30024(gdb)
496ee73e
KS
30025@c -break-insert -r foo.*
30026@c ~int foo(int, int);
30027@c ^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c,
998580f1
MK
30028@c "fullname="/home/foo/recursive2.c",line="11",thread-groups=["i1"],
30029@c times="0"@}
496ee73e 30030@c (gdb)
922fbb7b
AC
30031@end smallexample
30032
c5867ab6
HZ
30033@subheading The @code{-dprintf-insert} Command
30034@findex -dprintf-insert
30035
30036@subsubheading Synopsis
30037
30038@smallexample
30039 -dprintf-insert [ -t ] [ -f ] [ -d ]
30040 [ -c @var{condition} ] [ -i @var{ignore-count} ]
30041 [ -p @var{thread-id} ] [ @var{location} ] [ @var{format} ]
30042 [ @var{argument} ]
30043@end smallexample
30044
30045@noindent
629500fa
KS
30046If supplied, @var{location} may be specified the same way as for
30047the @code{-break-insert} command. @xref{-break-insert}.
c5867ab6
HZ
30048
30049The possible optional parameters of this command are:
30050
30051@table @samp
30052@item -t
30053Insert a temporary breakpoint.
30054@item -f
30055If @var{location} cannot be parsed (for example, if it
30056refers to unknown files or functions), create a pending
30057breakpoint. Without this flag, @value{GDBN} will report
30058an error, and won't create a breakpoint, if @var{location}
30059cannot be parsed.
30060@item -d
30061Create a disabled breakpoint.
30062@item -c @var{condition}
30063Make the breakpoint conditional on @var{condition}.
30064@item -i @var{ignore-count}
30065Set the ignore count of the breakpoint (@pxref{Conditions, ignore count})
30066to @var{ignore-count}.
30067@item -p @var{thread-id}
5d5658a1
PA
30068Restrict the breakpoint to the thread with the specified global
30069@var{thread-id}.
c5867ab6
HZ
30070@end table
30071
30072@subsubheading Result
30073
30074@xref{GDB/MI Breakpoint Information}, for details on the format of the
30075resulting breakpoint.
30076
30077@c An out-of-band breakpoint instead of part of the result?
30078
30079@subsubheading @value{GDBN} Command
30080
30081The corresponding @value{GDBN} command is @samp{dprintf}.
30082
30083@subsubheading Example
30084
30085@smallexample
30086(gdb)
300874-dprintf-insert foo "At foo entry\n"
300884^done,bkpt=@{number="1",type="dprintf",disp="keep",enabled="y",
30089addr="0x000000000040061b",func="foo",file="mi-dprintf.c",
30090fullname="mi-dprintf.c",line="25",thread-groups=["i1"],
30091times="0",script=@{"printf \"At foo entry\\n\"","continue"@},
30092original-location="foo"@}
30093(gdb)
300945-dprintf-insert 26 "arg=%d, g=%d\n" arg g
300955^done,bkpt=@{number="2",type="dprintf",disp="keep",enabled="y",
30096addr="0x000000000040062a",func="foo",file="mi-dprintf.c",
30097fullname="mi-dprintf.c",line="26",thread-groups=["i1"],
30098times="0",script=@{"printf \"arg=%d, g=%d\\n\", arg, g","continue"@},
30099original-location="mi-dprintf.c:26"@}
30100(gdb)
30101@end smallexample
30102
922fbb7b
AC
30103@subheading The @code{-break-list} Command
30104@findex -break-list
30105
30106@subsubheading Synopsis
30107
30108@smallexample
30109 -break-list
30110@end smallexample
30111
30112Displays the list of inserted breakpoints, showing the following fields:
30113
30114@table @samp
30115@item Number
30116number of the breakpoint
30117@item Type
30118type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
30119@item Disposition
30120should the breakpoint be deleted or disabled when it is hit: @samp{keep}
30121or @samp{nokeep}
30122@item Enabled
30123is the breakpoint enabled or no: @samp{y} or @samp{n}
30124@item Address
30125memory location at which the breakpoint is set
30126@item What
30127logical location of the breakpoint, expressed by function name, file
30128name, line number
998580f1
MK
30129@item Thread-groups
30130list of thread groups to which this breakpoint applies
922fbb7b
AC
30131@item Times
30132number of times the breakpoint has been hit
30133@end table
30134
30135If there are no breakpoints or watchpoints, the @code{BreakpointTable}
30136@code{body} field is an empty list.
30137
30138@subsubheading @value{GDBN} Command
30139
30140The corresponding @value{GDBN} command is @samp{info break}.
30141
30142@subsubheading Example
30143
30144@smallexample
594fe323 30145(gdb)
922fbb7b
AC
30146-break-list
30147^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30148hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30149@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30150@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30151@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30152@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30153@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30154body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
998580f1
MK
30155addr="0x000100d0",func="main",file="hello.c",line="5",thread-groups=["i1"],
30156times="0"@},
922fbb7b 30157bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
948d5102 30158addr="0x00010114",func="foo",file="hello.c",fullname="/home/foo/hello.c",
998580f1 30159line="13",thread-groups=["i1"],times="0"@}]@}
594fe323 30160(gdb)
922fbb7b
AC
30161@end smallexample
30162
30163Here's an example of the result when there are no breakpoints:
30164
30165@smallexample
594fe323 30166(gdb)
922fbb7b
AC
30167-break-list
30168^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
30169hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30170@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30171@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30172@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30173@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30174@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30175body=[]@}
594fe323 30176(gdb)
922fbb7b
AC
30177@end smallexample
30178
18148017
VP
30179@subheading The @code{-break-passcount} Command
30180@findex -break-passcount
30181
30182@subsubheading Synopsis
30183
30184@smallexample
30185 -break-passcount @var{tracepoint-number} @var{passcount}
30186@end smallexample
30187
30188Set the passcount for tracepoint @var{tracepoint-number} to
30189@var{passcount}. If the breakpoint referred to by @var{tracepoint-number}
30190is not a tracepoint, error is emitted. This corresponds to CLI
30191command @samp{passcount}.
30192
922fbb7b
AC
30193@subheading The @code{-break-watch} Command
30194@findex -break-watch
30195
30196@subsubheading Synopsis
30197
30198@smallexample
30199 -break-watch [ -a | -r ]
30200@end smallexample
30201
30202Create a watchpoint. With the @samp{-a} option it will create an
d3e8051b 30203@dfn{access} watchpoint, i.e., a watchpoint that triggers either on a
922fbb7b 30204read from or on a write to the memory location. With the @samp{-r}
d3e8051b 30205option, the watchpoint created is a @dfn{read} watchpoint, i.e., it will
922fbb7b
AC
30206trigger only when the memory location is accessed for reading. Without
30207either of the options, the watchpoint created is a regular watchpoint,
d3e8051b 30208i.e., it will trigger when the memory location is accessed for writing.
79a6e687 30209@xref{Set Watchpoints, , Setting Watchpoints}.
922fbb7b
AC
30210
30211Note that @samp{-break-list} will report a single list of watchpoints and
30212breakpoints inserted.
30213
30214@subsubheading @value{GDBN} Command
30215
30216The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
30217@samp{rwatch}.
30218
30219@subsubheading Example
30220
30221Setting a watchpoint on a variable in the @code{main} function:
30222
30223@smallexample
594fe323 30224(gdb)
922fbb7b
AC
30225-break-watch x
30226^done,wpt=@{number="2",exp="x"@}
594fe323 30227(gdb)
922fbb7b
AC
30228-exec-continue
30229^running
0869d01b
NR
30230(gdb)
30231*stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
922fbb7b 30232value=@{old="-268439212",new="55"@},
76ff342d 30233frame=@{func="main",args=[],file="recursive2.c",
6d52907e 30234fullname="/home/foo/bar/recursive2.c",line="5",arch="i386:x86_64"@}
594fe323 30235(gdb)
922fbb7b
AC
30236@end smallexample
30237
30238Setting a watchpoint on a variable local to a function. @value{GDBN} will stop
30239the program execution twice: first for the variable changing value, then
30240for the watchpoint going out of scope.
30241
30242@smallexample
594fe323 30243(gdb)
922fbb7b
AC
30244-break-watch C
30245^done,wpt=@{number="5",exp="C"@}
594fe323 30246(gdb)
922fbb7b
AC
30247-exec-continue
30248^running
0869d01b
NR
30249(gdb)
30250*stopped,reason="watchpoint-trigger",
922fbb7b
AC
30251wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
30252frame=@{func="callee4",args=[],
76ff342d 30253file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
30254fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13",
30255arch="i386:x86_64"@}
594fe323 30256(gdb)
922fbb7b
AC
30257-exec-continue
30258^running
0869d01b
NR
30259(gdb)
30260*stopped,reason="watchpoint-scope",wpnum="5",
922fbb7b
AC
30261frame=@{func="callee3",args=[@{name="strarg",
30262value="0x11940 \"A string argument.\""@}],
76ff342d 30263file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
30264fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
30265arch="i386:x86_64"@}
594fe323 30266(gdb)
922fbb7b
AC
30267@end smallexample
30268
30269Listing breakpoints and watchpoints, at different points in the program
30270execution. Note that once the watchpoint goes out of scope, it is
30271deleted.
30272
30273@smallexample
594fe323 30274(gdb)
922fbb7b
AC
30275-break-watch C
30276^done,wpt=@{number="2",exp="C"@}
594fe323 30277(gdb)
922fbb7b
AC
30278-break-list
30279^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30280hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30281@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30282@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30283@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30284@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30285@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30286body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30287addr="0x00010734",func="callee4",
948d5102 30288file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
998580f1
MK
30289fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c"line="8",thread-groups=["i1"],
30290times="1"@},
922fbb7b 30291bkpt=@{number="2",type="watchpoint",disp="keep",
998580f1 30292enabled="y",addr="",what="C",thread-groups=["i1"],times="0"@}]@}
594fe323 30293(gdb)
922fbb7b
AC
30294-exec-continue
30295^running
0869d01b
NR
30296(gdb)
30297*stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
922fbb7b
AC
30298value=@{old="-276895068",new="3"@},
30299frame=@{func="callee4",args=[],
76ff342d 30300file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
30301fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13",
30302arch="i386:x86_64"@}
594fe323 30303(gdb)
922fbb7b
AC
30304-break-list
30305^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30306hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30307@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30308@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30309@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30310@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30311@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30312body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30313addr="0x00010734",func="callee4",
948d5102 30314file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
998580f1
MK
30315fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",thread-groups=["i1"],
30316times="1"@},
922fbb7b 30317bkpt=@{number="2",type="watchpoint",disp="keep",
998580f1 30318enabled="y",addr="",what="C",thread-groups=["i1"],times="-5"@}]@}
594fe323 30319(gdb)
922fbb7b
AC
30320-exec-continue
30321^running
30322^done,reason="watchpoint-scope",wpnum="2",
30323frame=@{func="callee3",args=[@{name="strarg",
30324value="0x11940 \"A string argument.\""@}],
76ff342d 30325file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
30326fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
30327arch="i386:x86_64"@}
594fe323 30328(gdb)
922fbb7b
AC
30329-break-list
30330^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
30331hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30332@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30333@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30334@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30335@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30336@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30337body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30338addr="0x00010734",func="callee4",
948d5102
NR
30339file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30340fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
998580f1 30341thread-groups=["i1"],times="1"@}]@}
594fe323 30342(gdb)
922fbb7b
AC
30343@end smallexample
30344
3fa7bf06
MG
30345
30346@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30347@node GDB/MI Catchpoint Commands
30348@section @sc{gdb/mi} Catchpoint Commands
30349
30350This section documents @sc{gdb/mi} commands for manipulating
30351catchpoints.
30352
40555925
JB
30353@menu
30354* Shared Library GDB/MI Catchpoint Commands::
30355* Ada Exception GDB/MI Catchpoint Commands::
30056ea0 30356* C++ Exception GDB/MI Catchpoint Commands::
40555925
JB
30357@end menu
30358
30359@node Shared Library GDB/MI Catchpoint Commands
30360@subsection Shared Library @sc{gdb/mi} Catchpoints
30361
3fa7bf06
MG
30362@subheading The @code{-catch-load} Command
30363@findex -catch-load
30364
30365@subsubheading Synopsis
30366
30367@smallexample
30368 -catch-load [ -t ] [ -d ] @var{regexp}
30369@end smallexample
30370
30371Add a catchpoint for library load events. If the @samp{-t} option is used,
30372the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
30373Breakpoints}). If the @samp{-d} option is used, the catchpoint is created
30374in a disabled state. The @samp{regexp} argument is a regular
30375expression used to match the name of the loaded library.
30376
30377
30378@subsubheading @value{GDBN} Command
30379
30380The corresponding @value{GDBN} command is @samp{catch load}.
30381
30382@subsubheading Example
30383
30384@smallexample
30385-catch-load -t foo.so
30386^done,bkpt=@{number="1",type="catchpoint",disp="del",enabled="y",
8ac3646f 30387what="load of library matching foo.so",catch-type="load",times="0"@}
3fa7bf06
MG
30388(gdb)
30389@end smallexample
30390
30391
30392@subheading The @code{-catch-unload} Command
30393@findex -catch-unload
30394
30395@subsubheading Synopsis
30396
30397@smallexample
30398 -catch-unload [ -t ] [ -d ] @var{regexp}
30399@end smallexample
30400
30401Add a catchpoint for library unload events. If the @samp{-t} option is
30402used, the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
30403Breakpoints}). If the @samp{-d} option is used, the catchpoint is
30404created in a disabled state. The @samp{regexp} argument is a regular
30405expression used to match the name of the unloaded library.
30406
30407@subsubheading @value{GDBN} Command
30408
30409The corresponding @value{GDBN} command is @samp{catch unload}.
30410
30411@subsubheading Example
30412
30413@smallexample
30414-catch-unload -d bar.so
30415^done,bkpt=@{number="2",type="catchpoint",disp="keep",enabled="n",
8ac3646f 30416what="load of library matching bar.so",catch-type="unload",times="0"@}
3fa7bf06
MG
30417(gdb)
30418@end smallexample
30419
40555925
JB
30420@node Ada Exception GDB/MI Catchpoint Commands
30421@subsection Ada Exception @sc{gdb/mi} Catchpoints
30422
30423The following @sc{gdb/mi} commands can be used to create catchpoints
30424that stop the execution when Ada exceptions are being raised.
30425
30426@subheading The @code{-catch-assert} Command
30427@findex -catch-assert
30428
30429@subsubheading Synopsis
30430
30431@smallexample
30432 -catch-assert [ -c @var{condition}] [ -d ] [ -t ]
30433@end smallexample
30434
30435Add a catchpoint for failed Ada assertions.
30436
30437The possible optional parameters for this command are:
30438
30439@table @samp
30440@item -c @var{condition}
30441Make the catchpoint conditional on @var{condition}.
30442@item -d
30443Create a disabled catchpoint.
30444@item -t
30445Create a temporary catchpoint.
30446@end table
30447
30448@subsubheading @value{GDBN} Command
30449
30450The corresponding @value{GDBN} command is @samp{catch assert}.
30451
30452@subsubheading Example
30453
30454@smallexample
30455-catch-assert
30456^done,bkptno="5",bkpt=@{number="5",type="breakpoint",disp="keep",
30457enabled="y",addr="0x0000000000404888",what="failed Ada assertions",
30458thread-groups=["i1"],times="0",
30459original-location="__gnat_debug_raise_assert_failure"@}
30460(gdb)
30461@end smallexample
30462
30463@subheading The @code{-catch-exception} Command
30464@findex -catch-exception
30465
30466@subsubheading Synopsis
30467
30468@smallexample
30469 -catch-exception [ -c @var{condition}] [ -d ] [ -e @var{exception-name} ]
30470 [ -t ] [ -u ]
30471@end smallexample
30472
30473Add a catchpoint stopping when Ada exceptions are raised.
30474By default, the command stops the program when any Ada exception
30475gets raised. But it is also possible, by using some of the
30476optional parameters described below, to create more selective
30477catchpoints.
30478
30479The possible optional parameters for this command are:
30480
30481@table @samp
30482@item -c @var{condition}
30483Make the catchpoint conditional on @var{condition}.
30484@item -d
30485Create a disabled catchpoint.
30486@item -e @var{exception-name}
30487Only stop when @var{exception-name} is raised. This option cannot
30488be used combined with @samp{-u}.
30489@item -t
30490Create a temporary catchpoint.
30491@item -u
30492Stop only when an unhandled exception gets raised. This option
30493cannot be used combined with @samp{-e}.
30494@end table
30495
30496@subsubheading @value{GDBN} Command
30497
30498The corresponding @value{GDBN} commands are @samp{catch exception}
30499and @samp{catch exception unhandled}.
30500
30501@subsubheading Example
30502
30503@smallexample
30504-catch-exception -e Program_Error
30505^done,bkptno="4",bkpt=@{number="4",type="breakpoint",disp="keep",
30506enabled="y",addr="0x0000000000404874",
30507what="`Program_Error' Ada exception", thread-groups=["i1"],
30508times="0",original-location="__gnat_debug_raise_exception"@}
30509(gdb)
30510@end smallexample
3fa7bf06 30511
bea298f9
XR
30512@subheading The @code{-catch-handlers} Command
30513@findex -catch-handlers
30514
30515@subsubheading Synopsis
30516
30517@smallexample
30518 -catch-handlers [ -c @var{condition}] [ -d ] [ -e @var{exception-name} ]
30519 [ -t ]
30520@end smallexample
30521
30522Add a catchpoint stopping when Ada exceptions are handled.
30523By default, the command stops the program when any Ada exception
30524gets handled. But it is also possible, by using some of the
30525optional parameters described below, to create more selective
30526catchpoints.
30527
30528The possible optional parameters for this command are:
30529
30530@table @samp
30531@item -c @var{condition}
30532Make the catchpoint conditional on @var{condition}.
30533@item -d
30534Create a disabled catchpoint.
30535@item -e @var{exception-name}
30536Only stop when @var{exception-name} is handled.
30537@item -t
30538Create a temporary catchpoint.
30539@end table
30540
30541@subsubheading @value{GDBN} Command
30542
30543The corresponding @value{GDBN} command is @samp{catch handlers}.
30544
30545@subsubheading Example
30546
30547@smallexample
30548-catch-handlers -e Constraint_Error
30549^done,bkptno="4",bkpt=@{number="4",type="breakpoint",disp="keep",
30550enabled="y",addr="0x0000000000402f68",
30551what="`Constraint_Error' Ada exception handlers",thread-groups=["i1"],
30552times="0",original-location="__gnat_begin_handler"@}
30553(gdb)
30554@end smallexample
30555
30056ea0
AB
30556@node C++ Exception GDB/MI Catchpoint Commands
30557@subsection C@t{++} Exception @sc{gdb/mi} Catchpoints
30558
30559The following @sc{gdb/mi} commands can be used to create catchpoints
30560that stop the execution when C@t{++} exceptions are being throw, rethrown,
30561or caught.
30562
30563@subheading The @code{-catch-throw} Command
30564@findex -catch-throw
30565
30566@subsubheading Synopsis
30567
30568@smallexample
30569 -catch-throw [ -t ] [ -r @var{regexp}]
30570@end smallexample
30571
30572Stop when the debuggee throws a C@t{++} exception. If @var{regexp} is
30573given, then only exceptions whose type matches the regular expression
30574will be caught.
30575
30576If @samp{-t} is given, then the catchpoint is enabled only for one
30577stop, the catchpoint is automatically deleted after stopping once for
30578the event.
30579
30580@subsubheading @value{GDBN} Command
30581
30582The corresponding @value{GDBN} commands are @samp{catch throw}
30583and @samp{tcatch throw} (@pxref{Set Catchpoints}).
30584
30585@subsubheading Example
30586
30587@smallexample
30588-catch-throw -r exception_type
cb1e4e32
PA
30589^done,bkpt=@{number="1",type="catchpoint",disp="keep",enabled="y",
30590 what="exception throw",catch-type="throw",
30591 thread-groups=["i1"],
30056ea0
AB
30592 regexp="exception_type",times="0"@}
30593(gdb)
30594-exec-run
30595^running
30596(gdb)
30597~"\n"
30598~"Catchpoint 1 (exception thrown), 0x00007ffff7ae00ed
30599 in __cxa_throw () from /lib64/libstdc++.so.6\n"
30600*stopped,bkptno="1",reason="breakpoint-hit",disp="keep",
30601 frame=@{addr="0x00007ffff7ae00ed",func="__cxa_throw",
30602 args=[],from="/lib64/libstdc++.so.6",arch="i386:x86-64"@},
30603 thread-id="1",stopped-threads="all",core="6"
30604(gdb)
30605@end smallexample
30606
30607@subheading The @code{-catch-rethrow} Command
30608@findex -catch-rethrow
30609
30610@subsubheading Synopsis
30611
30612@smallexample
30613 -catch-rethrow [ -t ] [ -r @var{regexp}]
30614@end smallexample
30615
30616Stop when a C@t{++} exception is re-thrown. If @var{regexp} is given,
30617then only exceptions whose type matches the regular expression will be
30618caught.
30619
30620If @samp{-t} is given, then the catchpoint is enabled only for one
30621stop, the catchpoint is automatically deleted after the first event is
30622caught.
30623
30624@subsubheading @value{GDBN} Command
30625
30626The corresponding @value{GDBN} commands are @samp{catch rethrow}
30627and @samp{tcatch rethrow} (@pxref{Set Catchpoints}).
30628
30629@subsubheading Example
30630
30631@smallexample
30632-catch-rethrow -r exception_type
cb1e4e32
PA
30633^done,bkpt=@{number="1",type="catchpoint",disp="keep",enabled="y",
30634 what="exception rethrow",catch-type="rethrow",
30635 thread-groups=["i1"],
30056ea0
AB
30636 regexp="exception_type",times="0"@}
30637(gdb)
30638-exec-run
30639^running
30640(gdb)
30641~"\n"
30642~"Catchpoint 1 (exception rethrown), 0x00007ffff7ae00ed
30643 in __cxa_rethrow () from /lib64/libstdc++.so.6\n"
30644*stopped,bkptno="1",reason="breakpoint-hit",disp="keep",
30645 frame=@{addr="0x00007ffff7ae00ed",func="__cxa_rethrow",
30646 args=[],from="/lib64/libstdc++.so.6",arch="i386:x86-64"@},
30647 thread-id="1",stopped-threads="all",core="6"
30648(gdb)
30649@end smallexample
30650
30651@subheading The @code{-catch-catch} Command
30652@findex -catch-catch
30653
30654@subsubheading Synopsis
30655
30656@smallexample
30657 -catch-catch [ -t ] [ -r @var{regexp}]
30658@end smallexample
30659
30660Stop when the debuggee catches a C@t{++} exception. If @var{regexp}
30661is given, then only exceptions whose type matches the regular
30662expression will be caught.
30663
30664If @samp{-t} is given, then the catchpoint is enabled only for one
30665stop, the catchpoint is automatically deleted after the first event is
30666caught.
30667
30668@subsubheading @value{GDBN} Command
30669
30670The corresponding @value{GDBN} commands are @samp{catch catch}
30671and @samp{tcatch catch} (@pxref{Set Catchpoints}).
30672
30673@subsubheading Example
30674
30675@smallexample
30676-catch-catch -r exception_type
cb1e4e32
PA
30677^done,bkpt=@{number="1",type="catchpoint",disp="keep",enabled="y",
30678 what="exception catch",catch-type="catch",
30679 thread-groups=["i1"],
30056ea0
AB
30680 regexp="exception_type",times="0"@}
30681(gdb)
30682-exec-run
30683^running
30684(gdb)
30685~"\n"
30686~"Catchpoint 1 (exception caught), 0x00007ffff7ae00ed
30687 in __cxa_begin_catch () from /lib64/libstdc++.so.6\n"
30688*stopped,bkptno="1",reason="breakpoint-hit",disp="keep",
30689 frame=@{addr="0x00007ffff7ae00ed",func="__cxa_begin_catch",
30690 args=[],from="/lib64/libstdc++.so.6",arch="i386:x86-64"@},
30691 thread-id="1",stopped-threads="all",core="6"
30692(gdb)
30693@end smallexample
30694
922fbb7b 30695@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
30696@node GDB/MI Program Context
30697@section @sc{gdb/mi} Program Context
922fbb7b 30698
a2c02241
NR
30699@subheading The @code{-exec-arguments} Command
30700@findex -exec-arguments
922fbb7b 30701
922fbb7b
AC
30702
30703@subsubheading Synopsis
30704
30705@smallexample
a2c02241 30706 -exec-arguments @var{args}
922fbb7b
AC
30707@end smallexample
30708
a2c02241
NR
30709Set the inferior program arguments, to be used in the next
30710@samp{-exec-run}.
922fbb7b 30711
a2c02241 30712@subsubheading @value{GDBN} Command
922fbb7b 30713
a2c02241 30714The corresponding @value{GDBN} command is @samp{set args}.
922fbb7b 30715
a2c02241 30716@subsubheading Example
922fbb7b 30717
fbc5282e
MK
30718@smallexample
30719(gdb)
30720-exec-arguments -v word
30721^done
30722(gdb)
30723@end smallexample
922fbb7b 30724
a2c02241 30725
9901a55b 30726@ignore
a2c02241
NR
30727@subheading The @code{-exec-show-arguments} Command
30728@findex -exec-show-arguments
30729
30730@subsubheading Synopsis
30731
30732@smallexample
30733 -exec-show-arguments
30734@end smallexample
30735
30736Print the arguments of the program.
922fbb7b
AC
30737
30738@subsubheading @value{GDBN} Command
30739
a2c02241 30740The corresponding @value{GDBN} command is @samp{show args}.
922fbb7b
AC
30741
30742@subsubheading Example
a2c02241 30743N.A.
9901a55b 30744@end ignore
922fbb7b 30745
922fbb7b 30746
a2c02241
NR
30747@subheading The @code{-environment-cd} Command
30748@findex -environment-cd
922fbb7b 30749
a2c02241 30750@subsubheading Synopsis
922fbb7b
AC
30751
30752@smallexample
a2c02241 30753 -environment-cd @var{pathdir}
922fbb7b
AC
30754@end smallexample
30755
a2c02241 30756Set @value{GDBN}'s working directory.
922fbb7b 30757
a2c02241 30758@subsubheading @value{GDBN} Command
922fbb7b 30759
a2c02241
NR
30760The corresponding @value{GDBN} command is @samp{cd}.
30761
30762@subsubheading Example
922fbb7b
AC
30763
30764@smallexample
594fe323 30765(gdb)
a2c02241
NR
30766-environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
30767^done
594fe323 30768(gdb)
922fbb7b
AC
30769@end smallexample
30770
30771
a2c02241
NR
30772@subheading The @code{-environment-directory} Command
30773@findex -environment-directory
922fbb7b
AC
30774
30775@subsubheading Synopsis
30776
30777@smallexample
a2c02241 30778 -environment-directory [ -r ] [ @var{pathdir} ]+
922fbb7b
AC
30779@end smallexample
30780
a2c02241
NR
30781Add directories @var{pathdir} to beginning of search path for source files.
30782If the @samp{-r} option is used, the search path is reset to the default
30783search path. If directories @var{pathdir} are supplied in addition to the
30784@samp{-r} option, the search path is first reset and then addition
30785occurs as normal.
30786Multiple directories may be specified, separated by blanks. Specifying
30787multiple directories in a single command
30788results in the directories added to the beginning of the
30789search path in the same order they were presented in the command.
30790If blanks are needed as
30791part of a directory name, double-quotes should be used around
30792the name. In the command output, the path will show up separated
d3e8051b 30793by the system directory-separator character. The directory-separator
a2c02241
NR
30794character must not be used
30795in any directory name.
30796If no directories are specified, the current search path is displayed.
922fbb7b
AC
30797
30798@subsubheading @value{GDBN} Command
30799
a2c02241 30800The corresponding @value{GDBN} command is @samp{dir}.
922fbb7b
AC
30801
30802@subsubheading Example
30803
922fbb7b 30804@smallexample
594fe323 30805(gdb)
a2c02241
NR
30806-environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
30807^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
594fe323 30808(gdb)
a2c02241
NR
30809-environment-directory ""
30810^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
594fe323 30811(gdb)
a2c02241
NR
30812-environment-directory -r /home/jjohnstn/src/gdb /usr/src
30813^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
594fe323 30814(gdb)
a2c02241
NR
30815-environment-directory -r
30816^done,source-path="$cdir:$cwd"
594fe323 30817(gdb)
922fbb7b
AC
30818@end smallexample
30819
30820
a2c02241
NR
30821@subheading The @code{-environment-path} Command
30822@findex -environment-path
922fbb7b
AC
30823
30824@subsubheading Synopsis
30825
30826@smallexample
a2c02241 30827 -environment-path [ -r ] [ @var{pathdir} ]+
922fbb7b
AC
30828@end smallexample
30829
a2c02241
NR
30830Add directories @var{pathdir} to beginning of search path for object files.
30831If the @samp{-r} option is used, the search path is reset to the original
30832search path that existed at gdb start-up. If directories @var{pathdir} are
30833supplied in addition to the
30834@samp{-r} option, the search path is first reset and then addition
30835occurs as normal.
30836Multiple directories may be specified, separated by blanks. Specifying
30837multiple directories in a single command
30838results in the directories added to the beginning of the
30839search path in the same order they were presented in the command.
30840If blanks are needed as
30841part of a directory name, double-quotes should be used around
30842the name. In the command output, the path will show up separated
d3e8051b 30843by the system directory-separator character. The directory-separator
a2c02241
NR
30844character must not be used
30845in any directory name.
30846If no directories are specified, the current path is displayed.
30847
922fbb7b
AC
30848
30849@subsubheading @value{GDBN} Command
30850
a2c02241 30851The corresponding @value{GDBN} command is @samp{path}.
922fbb7b
AC
30852
30853@subsubheading Example
30854
922fbb7b 30855@smallexample
594fe323 30856(gdb)
a2c02241
NR
30857-environment-path
30858^done,path="/usr/bin"
594fe323 30859(gdb)
a2c02241
NR
30860-environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
30861^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
594fe323 30862(gdb)
a2c02241
NR
30863-environment-path -r /usr/local/bin
30864^done,path="/usr/local/bin:/usr/bin"
594fe323 30865(gdb)
922fbb7b
AC
30866@end smallexample
30867
30868
a2c02241
NR
30869@subheading The @code{-environment-pwd} Command
30870@findex -environment-pwd
922fbb7b
AC
30871
30872@subsubheading Synopsis
30873
30874@smallexample
a2c02241 30875 -environment-pwd
922fbb7b
AC
30876@end smallexample
30877
a2c02241 30878Show the current working directory.
922fbb7b 30879
79a6e687 30880@subsubheading @value{GDBN} Command
922fbb7b 30881
a2c02241 30882The corresponding @value{GDBN} command is @samp{pwd}.
922fbb7b
AC
30883
30884@subsubheading Example
30885
922fbb7b 30886@smallexample
594fe323 30887(gdb)
a2c02241
NR
30888-environment-pwd
30889^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
594fe323 30890(gdb)
922fbb7b
AC
30891@end smallexample
30892
a2c02241
NR
30893@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30894@node GDB/MI Thread Commands
30895@section @sc{gdb/mi} Thread Commands
30896
30897
30898@subheading The @code{-thread-info} Command
30899@findex -thread-info
922fbb7b
AC
30900
30901@subsubheading Synopsis
30902
30903@smallexample
8e8901c5 30904 -thread-info [ @var{thread-id} ]
922fbb7b
AC
30905@end smallexample
30906
5d5658a1
PA
30907Reports information about either a specific thread, if the
30908@var{thread-id} parameter is present, or about all threads.
30909@var{thread-id} is the thread's global thread ID. When printing
30910information about all threads, also reports the global ID of the
30911current thread.
8e8901c5 30912
79a6e687 30913@subsubheading @value{GDBN} Command
922fbb7b 30914
8e8901c5
VP
30915The @samp{info thread} command prints the same information
30916about all threads.
922fbb7b 30917
4694da01 30918@subsubheading Result
922fbb7b 30919
ebe553db 30920The result contains the following attributes:
4694da01
TT
30921
30922@table @samp
ebe553db
SM
30923@item threads
30924A list of threads. The format of the elements of the list is described in
30925@ref{GDB/MI Thread Information}.
30926
30927@item current-thread-id
30928The global id of the currently selected thread. This field is omitted if there
30929is no selected thread (for example, when the selected inferior is not running,
30930and therefore has no threads) or if a @var{thread-id} argument was passed to
30931the command.
4694da01
TT
30932
30933@end table
30934
30935@subsubheading Example
30936
30937@smallexample
30938-thread-info
30939^done,threads=[
30940@{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
30941 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",
30942 args=[]@},state="running"@},
30943@{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
30944 frame=@{level="0",addr="0x0804891f",func="foo",
30945 args=[@{name="i",value="10"@}],
6d52907e 30946 file="/tmp/a.c",fullname="/tmp/a.c",line="158",arch="i386:x86_64"@},
4694da01
TT
30947 state="running"@}],
30948current-thread-id="1"
30949(gdb)
30950@end smallexample
30951
a2c02241
NR
30952@subheading The @code{-thread-list-ids} Command
30953@findex -thread-list-ids
922fbb7b 30954
a2c02241 30955@subsubheading Synopsis
922fbb7b 30956
a2c02241
NR
30957@smallexample
30958 -thread-list-ids
30959@end smallexample
922fbb7b 30960
5d5658a1
PA
30961Produces a list of the currently known global @value{GDBN} thread ids.
30962At the end of the list it also prints the total number of such
30963threads.
922fbb7b 30964
c3b108f7
VP
30965This command is retained for historical reasons, the
30966@code{-thread-info} command should be used instead.
30967
922fbb7b
AC
30968@subsubheading @value{GDBN} Command
30969
a2c02241 30970Part of @samp{info threads} supplies the same information.
922fbb7b
AC
30971
30972@subsubheading Example
30973
922fbb7b 30974@smallexample
594fe323 30975(gdb)
a2c02241
NR
30976-thread-list-ids
30977^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
592375cd 30978current-thread-id="1",number-of-threads="3"
594fe323 30979(gdb)
922fbb7b
AC
30980@end smallexample
30981
a2c02241
NR
30982
30983@subheading The @code{-thread-select} Command
30984@findex -thread-select
922fbb7b
AC
30985
30986@subsubheading Synopsis
30987
30988@smallexample
5d5658a1 30989 -thread-select @var{thread-id}
922fbb7b
AC
30990@end smallexample
30991
5d5658a1
PA
30992Make thread with global thread number @var{thread-id} the current
30993thread. It prints the number of the new current thread, and the
30994topmost frame for that thread.
922fbb7b 30995
c3b108f7
VP
30996This command is deprecated in favor of explicitly using the
30997@samp{--thread} option to each command.
30998
922fbb7b
AC
30999@subsubheading @value{GDBN} Command
31000
a2c02241 31001The corresponding @value{GDBN} command is @samp{thread}.
922fbb7b
AC
31002
31003@subsubheading Example
922fbb7b
AC
31004
31005@smallexample
594fe323 31006(gdb)
a2c02241
NR
31007-exec-next
31008^running
594fe323 31009(gdb)
a2c02241
NR
31010*stopped,reason="end-stepping-range",thread-id="2",line="187",
31011file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
594fe323 31012(gdb)
a2c02241
NR
31013-thread-list-ids
31014^done,
31015thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
31016number-of-threads="3"
594fe323 31017(gdb)
a2c02241
NR
31018-thread-select 3
31019^done,new-thread-id="3",
31020frame=@{level="0",func="vprintf",
31021args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
6d52907e 31022@{name="arg",value="0x2"@}],file="vprintf.c",line="31",arch="i386:x86_64"@}
594fe323 31023(gdb)
922fbb7b
AC
31024@end smallexample
31025
5d77fe44
JB
31026@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31027@node GDB/MI Ada Tasking Commands
31028@section @sc{gdb/mi} Ada Tasking Commands
31029
31030@subheading The @code{-ada-task-info} Command
31031@findex -ada-task-info
31032
31033@subsubheading Synopsis
31034
31035@smallexample
31036 -ada-task-info [ @var{task-id} ]
31037@end smallexample
31038
31039Reports information about either a specific Ada task, if the
31040@var{task-id} parameter is present, or about all Ada tasks.
31041
31042@subsubheading @value{GDBN} Command
31043
31044The @samp{info tasks} command prints the same information
31045about all Ada tasks (@pxref{Ada Tasks}).
31046
31047@subsubheading Result
31048
31049The result is a table of Ada tasks. The following columns are
31050defined for each Ada task:
31051
31052@table @samp
31053@item current
31054This field exists only for the current thread. It has the value @samp{*}.
31055
31056@item id
31057The identifier that @value{GDBN} uses to refer to the Ada task.
31058
31059@item task-id
31060The identifier that the target uses to refer to the Ada task.
31061
31062@item thread-id
5d5658a1
PA
31063The global thread identifier of the thread corresponding to the Ada
31064task.
5d77fe44
JB
31065
31066This field should always exist, as Ada tasks are always implemented
31067on top of a thread. But if @value{GDBN} cannot find this corresponding
31068thread for any reason, the field is omitted.
31069
31070@item parent-id
31071This field exists only when the task was created by another task.
31072In this case, it provides the ID of the parent task.
31073
31074@item priority
31075The base priority of the task.
31076
31077@item state
31078The current state of the task. For a detailed description of the
31079possible states, see @ref{Ada Tasks}.
31080
31081@item name
31082The name of the task.
31083
31084@end table
31085
31086@subsubheading Example
31087
31088@smallexample
31089-ada-task-info
31090^done,tasks=@{nr_rows="3",nr_cols="8",
31091hdr=[@{width="1",alignment="-1",col_name="current",colhdr=""@},
31092@{width="3",alignment="1",col_name="id",colhdr="ID"@},
31093@{width="9",alignment="1",col_name="task-id",colhdr="TID"@},
31094@{width="4",alignment="1",col_name="thread-id",colhdr=""@},
31095@{width="4",alignment="1",col_name="parent-id",colhdr="P-ID"@},
31096@{width="3",alignment="1",col_name="priority",colhdr="Pri"@},
31097@{width="22",alignment="-1",col_name="state",colhdr="State"@},
31098@{width="1",alignment="2",col_name="name",colhdr="Name"@}],
31099body=[@{current="*",id="1",task-id=" 644010",thread-id="1",priority="48",
31100state="Child Termination Wait",name="main_task"@}]@}
31101(gdb)
31102@end smallexample
31103
a2c02241
NR
31104@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31105@node GDB/MI Program Execution
31106@section @sc{gdb/mi} Program Execution
922fbb7b 31107
ef21caaf 31108These are the asynchronous commands which generate the out-of-band
3f94c067 31109record @samp{*stopped}. Currently @value{GDBN} only really executes
ef21caaf
NR
31110asynchronously with remote targets and this interaction is mimicked in
31111other cases.
922fbb7b 31112
922fbb7b
AC
31113@subheading The @code{-exec-continue} Command
31114@findex -exec-continue
31115
31116@subsubheading Synopsis
31117
31118@smallexample
540aa8e7 31119 -exec-continue [--reverse] [--all|--thread-group N]
922fbb7b
AC
31120@end smallexample
31121
540aa8e7
MS
31122Resumes the execution of the inferior program, which will continue
31123to execute until it reaches a debugger stop event. If the
31124@samp{--reverse} option is specified, execution resumes in reverse until
31125it reaches a stop event. Stop events may include
31126@itemize @bullet
31127@item
31128breakpoints or watchpoints
31129@item
31130signals or exceptions
31131@item
31132the end of the process (or its beginning under @samp{--reverse})
31133@item
31134the end or beginning of a replay log if one is being used.
31135@end itemize
31136In all-stop mode (@pxref{All-Stop
31137Mode}), may resume only one thread, or all threads, depending on the
31138value of the @samp{scheduler-locking} variable. If @samp{--all} is
a79b8f6e 31139specified, all threads (in all inferiors) will be resumed. The @samp{--all} option is
540aa8e7
MS
31140ignored in all-stop mode. If the @samp{--thread-group} options is
31141specified, then all threads in that thread group are resumed.
922fbb7b
AC
31142
31143@subsubheading @value{GDBN} Command
31144
31145The corresponding @value{GDBN} corresponding is @samp{continue}.
31146
31147@subsubheading Example
31148
31149@smallexample
31150-exec-continue
31151^running
594fe323 31152(gdb)
922fbb7b 31153@@Hello world
a47ec5fe
AR
31154*stopped,reason="breakpoint-hit",disp="keep",bkptno="2",frame=@{
31155func="foo",args=[],file="hello.c",fullname="/home/foo/bar/hello.c",
6d52907e 31156line="13",arch="i386:x86_64"@}
594fe323 31157(gdb)
922fbb7b
AC
31158@end smallexample
31159
31160
31161@subheading The @code{-exec-finish} Command
31162@findex -exec-finish
31163
31164@subsubheading Synopsis
31165
31166@smallexample
540aa8e7 31167 -exec-finish [--reverse]
922fbb7b
AC
31168@end smallexample
31169
ef21caaf
NR
31170Resumes the execution of the inferior program until the current
31171function is exited. Displays the results returned by the function.
540aa8e7
MS
31172If the @samp{--reverse} option is specified, resumes the reverse
31173execution of the inferior program until the point where current
31174function was called.
922fbb7b
AC
31175
31176@subsubheading @value{GDBN} Command
31177
31178The corresponding @value{GDBN} command is @samp{finish}.
31179
31180@subsubheading Example
31181
31182Function returning @code{void}.
31183
31184@smallexample
31185-exec-finish
31186^running
594fe323 31187(gdb)
922fbb7b
AC
31188@@hello from foo
31189*stopped,reason="function-finished",frame=@{func="main",args=[],
6d52907e 31190file="hello.c",fullname="/home/foo/bar/hello.c",line="7",arch="i386:x86_64"@}
594fe323 31191(gdb)
922fbb7b
AC
31192@end smallexample
31193
31194Function returning other than @code{void}. The name of the internal
31195@value{GDBN} variable storing the result is printed, together with the
31196value itself.
31197
31198@smallexample
31199-exec-finish
31200^running
594fe323 31201(gdb)
922fbb7b
AC
31202*stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
31203args=[@{name="a",value="1"],@{name="b",value="9"@}@},
6d52907e
JV
31204file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31205arch="i386:x86_64"@},
922fbb7b 31206gdb-result-var="$1",return-value="0"
594fe323 31207(gdb)
922fbb7b
AC
31208@end smallexample
31209
31210
31211@subheading The @code{-exec-interrupt} Command
31212@findex -exec-interrupt
31213
31214@subsubheading Synopsis
31215
31216@smallexample
c3b108f7 31217 -exec-interrupt [--all|--thread-group N]
922fbb7b
AC
31218@end smallexample
31219
ef21caaf
NR
31220Interrupts the background execution of the target. Note how the token
31221associated with the stop message is the one for the execution command
31222that has been interrupted. The token for the interrupt itself only
31223appears in the @samp{^done} output. If the user is trying to
922fbb7b
AC
31224interrupt a non-running program, an error message will be printed.
31225
c3b108f7
VP
31226Note that when asynchronous execution is enabled, this command is
31227asynchronous just like other execution commands. That is, first the
31228@samp{^done} response will be printed, and the target stop will be
31229reported after that using the @samp{*stopped} notification.
31230
31231In non-stop mode, only the context thread is interrupted by default.
a79b8f6e
VP
31232All threads (in all inferiors) will be interrupted if the
31233@samp{--all} option is specified. If the @samp{--thread-group}
31234option is specified, all threads in that group will be interrupted.
c3b108f7 31235
922fbb7b
AC
31236@subsubheading @value{GDBN} Command
31237
31238The corresponding @value{GDBN} command is @samp{interrupt}.
31239
31240@subsubheading Example
31241
31242@smallexample
594fe323 31243(gdb)
922fbb7b
AC
31244111-exec-continue
31245111^running
31246
594fe323 31247(gdb)
922fbb7b
AC
31248222-exec-interrupt
31249222^done
594fe323 31250(gdb)
922fbb7b 31251111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
76ff342d 31252frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
6d52907e 31253fullname="/home/foo/bar/try.c",line="13",arch="i386:x86_64"@}
594fe323 31254(gdb)
922fbb7b 31255
594fe323 31256(gdb)
922fbb7b
AC
31257-exec-interrupt
31258^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
594fe323 31259(gdb)
922fbb7b
AC
31260@end smallexample
31261
83eba9b7
VP
31262@subheading The @code{-exec-jump} Command
31263@findex -exec-jump
31264
31265@subsubheading Synopsis
31266
31267@smallexample
31268 -exec-jump @var{location}
31269@end smallexample
31270
31271Resumes execution of the inferior program at the location specified by
31272parameter. @xref{Specify Location}, for a description of the
31273different forms of @var{location}.
31274
31275@subsubheading @value{GDBN} Command
31276
31277The corresponding @value{GDBN} command is @samp{jump}.
31278
31279@subsubheading Example
31280
31281@smallexample
31282-exec-jump foo.c:10
31283*running,thread-id="all"
31284^running
31285@end smallexample
31286
922fbb7b
AC
31287
31288@subheading The @code{-exec-next} Command
31289@findex -exec-next
31290
31291@subsubheading Synopsis
31292
31293@smallexample
540aa8e7 31294 -exec-next [--reverse]
922fbb7b
AC
31295@end smallexample
31296
ef21caaf
NR
31297Resumes execution of the inferior program, stopping when the beginning
31298of the next source line is reached.
922fbb7b 31299
540aa8e7
MS
31300If the @samp{--reverse} option is specified, resumes reverse execution
31301of the inferior program, stopping at the beginning of the previous
31302source line. If you issue this command on the first line of a
31303function, it will take you back to the caller of that function, to the
31304source line where the function was called.
31305
31306
922fbb7b
AC
31307@subsubheading @value{GDBN} Command
31308
31309The corresponding @value{GDBN} command is @samp{next}.
31310
31311@subsubheading Example
31312
31313@smallexample
31314-exec-next
31315^running
594fe323 31316(gdb)
922fbb7b 31317*stopped,reason="end-stepping-range",line="8",file="hello.c"
594fe323 31318(gdb)
922fbb7b
AC
31319@end smallexample
31320
31321
31322@subheading The @code{-exec-next-instruction} Command
31323@findex -exec-next-instruction
31324
31325@subsubheading Synopsis
31326
31327@smallexample
540aa8e7 31328 -exec-next-instruction [--reverse]
922fbb7b
AC
31329@end smallexample
31330
ef21caaf
NR
31331Executes one machine instruction. If the instruction is a function
31332call, continues until the function returns. If the program stops at an
31333instruction in the middle of a source line, the address will be
31334printed as well.
922fbb7b 31335
540aa8e7
MS
31336If the @samp{--reverse} option is specified, resumes reverse execution
31337of the inferior program, stopping at the previous instruction. If the
31338previously executed instruction was a return from another function,
31339it will continue to execute in reverse until the call to that function
31340(from the current stack frame) is reached.
31341
922fbb7b
AC
31342@subsubheading @value{GDBN} Command
31343
31344The corresponding @value{GDBN} command is @samp{nexti}.
31345
31346@subsubheading Example
31347
31348@smallexample
594fe323 31349(gdb)
922fbb7b
AC
31350-exec-next-instruction
31351^running
31352
594fe323 31353(gdb)
922fbb7b
AC
31354*stopped,reason="end-stepping-range",
31355addr="0x000100d4",line="5",file="hello.c"
594fe323 31356(gdb)
922fbb7b
AC
31357@end smallexample
31358
31359
31360@subheading The @code{-exec-return} Command
31361@findex -exec-return
31362
31363@subsubheading Synopsis
31364
31365@smallexample
31366 -exec-return
31367@end smallexample
31368
31369Makes current function return immediately. Doesn't execute the inferior.
31370Displays the new current frame.
31371
31372@subsubheading @value{GDBN} Command
31373
31374The corresponding @value{GDBN} command is @samp{return}.
31375
31376@subsubheading Example
31377
31378@smallexample
594fe323 31379(gdb)
922fbb7b
AC
31380200-break-insert callee4
31381200^done,bkpt=@{number="1",addr="0x00010734",
31382file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
594fe323 31383(gdb)
922fbb7b
AC
31384000-exec-run
31385000^running
594fe323 31386(gdb)
a47ec5fe 31387000*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
922fbb7b 31388frame=@{func="callee4",args=[],
76ff342d 31389file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
31390fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
31391arch="i386:x86_64"@}
594fe323 31392(gdb)
922fbb7b
AC
31393205-break-delete
31394205^done
594fe323 31395(gdb)
922fbb7b
AC
31396111-exec-return
31397111^done,frame=@{level="0",func="callee3",
31398args=[@{name="strarg",
31399value="0x11940 \"A string argument.\""@}],
76ff342d 31400file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
31401fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
31402arch="i386:x86_64"@}
594fe323 31403(gdb)
922fbb7b
AC
31404@end smallexample
31405
31406
31407@subheading The @code{-exec-run} Command
31408@findex -exec-run
31409
31410@subsubheading Synopsis
31411
31412@smallexample
5713b9b5 31413 -exec-run [ --all | --thread-group N ] [ --start ]
922fbb7b
AC
31414@end smallexample
31415
ef21caaf
NR
31416Starts execution of the inferior from the beginning. The inferior
31417executes until either a breakpoint is encountered or the program
31418exits. In the latter case the output will include an exit code, if
31419the program has exited exceptionally.
922fbb7b 31420
5713b9b5
JB
31421When neither the @samp{--all} nor the @samp{--thread-group} option
31422is specified, the current inferior is started. If the
a79b8f6e
VP
31423@samp{--thread-group} option is specified, it should refer to a thread
31424group of type @samp{process}, and that thread group will be started.
31425If the @samp{--all} option is specified, then all inferiors will be started.
31426
5713b9b5
JB
31427Using the @samp{--start} option instructs the debugger to stop
31428the execution at the start of the inferior's main subprogram,
31429following the same behavior as the @code{start} command
31430(@pxref{Starting}).
31431
922fbb7b
AC
31432@subsubheading @value{GDBN} Command
31433
31434The corresponding @value{GDBN} command is @samp{run}.
31435
ef21caaf 31436@subsubheading Examples
922fbb7b
AC
31437
31438@smallexample
594fe323 31439(gdb)
922fbb7b
AC
31440-break-insert main
31441^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
594fe323 31442(gdb)
922fbb7b
AC
31443-exec-run
31444^running
594fe323 31445(gdb)
a47ec5fe 31446*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
76ff342d 31447frame=@{func="main",args=[],file="recursive2.c",
6d52907e 31448fullname="/home/foo/bar/recursive2.c",line="4",arch="i386:x86_64"@}
594fe323 31449(gdb)
922fbb7b
AC
31450@end smallexample
31451
ef21caaf
NR
31452@noindent
31453Program exited normally:
31454
31455@smallexample
594fe323 31456(gdb)
ef21caaf
NR
31457-exec-run
31458^running
594fe323 31459(gdb)
ef21caaf
NR
31460x = 55
31461*stopped,reason="exited-normally"
594fe323 31462(gdb)
ef21caaf
NR
31463@end smallexample
31464
31465@noindent
31466Program exited exceptionally:
31467
31468@smallexample
594fe323 31469(gdb)
ef21caaf
NR
31470-exec-run
31471^running
594fe323 31472(gdb)
ef21caaf
NR
31473x = 55
31474*stopped,reason="exited",exit-code="01"
594fe323 31475(gdb)
ef21caaf
NR
31476@end smallexample
31477
31478Another way the program can terminate is if it receives a signal such as
31479@code{SIGINT}. In this case, @sc{gdb/mi} displays this:
31480
31481@smallexample
594fe323 31482(gdb)
ef21caaf
NR
31483*stopped,reason="exited-signalled",signal-name="SIGINT",
31484signal-meaning="Interrupt"
31485@end smallexample
31486
922fbb7b 31487
a2c02241
NR
31488@c @subheading -exec-signal
31489
31490
31491@subheading The @code{-exec-step} Command
31492@findex -exec-step
922fbb7b
AC
31493
31494@subsubheading Synopsis
31495
31496@smallexample
540aa8e7 31497 -exec-step [--reverse]
922fbb7b
AC
31498@end smallexample
31499
a2c02241
NR
31500Resumes execution of the inferior program, stopping when the beginning
31501of the next source line is reached, if the next source line is not a
31502function call. If it is, stop at the first instruction of the called
540aa8e7
MS
31503function. If the @samp{--reverse} option is specified, resumes reverse
31504execution of the inferior program, stopping at the beginning of the
31505previously executed source line.
922fbb7b
AC
31506
31507@subsubheading @value{GDBN} Command
31508
a2c02241 31509The corresponding @value{GDBN} command is @samp{step}.
922fbb7b
AC
31510
31511@subsubheading Example
31512
31513Stepping into a function:
31514
31515@smallexample
31516-exec-step
31517^running
594fe323 31518(gdb)
922fbb7b
AC
31519*stopped,reason="end-stepping-range",
31520frame=@{func="foo",args=[@{name="a",value="10"@},
76ff342d 31521@{name="b",value="0"@}],file="recursive2.c",
6d52907e 31522fullname="/home/foo/bar/recursive2.c",line="11",arch="i386:x86_64"@}
594fe323 31523(gdb)
922fbb7b
AC
31524@end smallexample
31525
31526Regular stepping:
31527
31528@smallexample
31529-exec-step
31530^running
594fe323 31531(gdb)
922fbb7b 31532*stopped,reason="end-stepping-range",line="14",file="recursive2.c"
594fe323 31533(gdb)
922fbb7b
AC
31534@end smallexample
31535
31536
31537@subheading The @code{-exec-step-instruction} Command
31538@findex -exec-step-instruction
31539
31540@subsubheading Synopsis
31541
31542@smallexample
540aa8e7 31543 -exec-step-instruction [--reverse]
922fbb7b
AC
31544@end smallexample
31545
540aa8e7
MS
31546Resumes the inferior which executes one machine instruction. If the
31547@samp{--reverse} option is specified, resumes reverse execution of the
31548inferior program, stopping at the previously executed instruction.
31549The output, once @value{GDBN} has stopped, will vary depending on
31550whether we have stopped in the middle of a source line or not. In the
31551former case, the address at which the program stopped will be printed
31552as well.
922fbb7b
AC
31553
31554@subsubheading @value{GDBN} Command
31555
31556The corresponding @value{GDBN} command is @samp{stepi}.
31557
31558@subsubheading Example
31559
31560@smallexample
594fe323 31561(gdb)
922fbb7b
AC
31562-exec-step-instruction
31563^running
31564
594fe323 31565(gdb)
922fbb7b 31566*stopped,reason="end-stepping-range",
76ff342d 31567frame=@{func="foo",args=[],file="try.c",
6d52907e 31568fullname="/home/foo/bar/try.c",line="10",arch="i386:x86_64"@}
594fe323 31569(gdb)
922fbb7b
AC
31570-exec-step-instruction
31571^running
31572
594fe323 31573(gdb)
922fbb7b 31574*stopped,reason="end-stepping-range",
76ff342d 31575frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
6d52907e 31576fullname="/home/foo/bar/try.c",line="10",arch="i386:x86_64"@}
594fe323 31577(gdb)
922fbb7b
AC
31578@end smallexample
31579
31580
31581@subheading The @code{-exec-until} Command
31582@findex -exec-until
31583
31584@subsubheading Synopsis
31585
31586@smallexample
31587 -exec-until [ @var{location} ]
31588@end smallexample
31589
ef21caaf
NR
31590Executes the inferior until the @var{location} specified in the
31591argument is reached. If there is no argument, the inferior executes
31592until a source line greater than the current one is reached. The
31593reason for stopping in this case will be @samp{location-reached}.
922fbb7b
AC
31594
31595@subsubheading @value{GDBN} Command
31596
31597The corresponding @value{GDBN} command is @samp{until}.
31598
31599@subsubheading Example
31600
31601@smallexample
594fe323 31602(gdb)
922fbb7b
AC
31603-exec-until recursive2.c:6
31604^running
594fe323 31605(gdb)
922fbb7b
AC
31606x = 55
31607*stopped,reason="location-reached",frame=@{func="main",args=[],
6d52907e
JV
31608file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="6",
31609arch="i386:x86_64"@}
594fe323 31610(gdb)
922fbb7b
AC
31611@end smallexample
31612
31613@ignore
31614@subheading -file-clear
31615Is this going away????
31616@end ignore
31617
351ff01a 31618@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
31619@node GDB/MI Stack Manipulation
31620@section @sc{gdb/mi} Stack Manipulation Commands
351ff01a 31621
1e611234
PM
31622@subheading The @code{-enable-frame-filters} Command
31623@findex -enable-frame-filters
31624
31625@smallexample
31626-enable-frame-filters
31627@end smallexample
31628
31629@value{GDBN} allows Python-based frame filters to affect the output of
31630the MI commands relating to stack traces. As there is no way to
31631implement this in a fully backward-compatible way, a front end must
31632request that this functionality be enabled.
31633
31634Once enabled, this feature cannot be disabled.
31635
31636Note that if Python support has not been compiled into @value{GDBN},
31637this command will still succeed (and do nothing).
922fbb7b 31638
a2c02241
NR
31639@subheading The @code{-stack-info-frame} Command
31640@findex -stack-info-frame
922fbb7b
AC
31641
31642@subsubheading Synopsis
31643
31644@smallexample
a2c02241 31645 -stack-info-frame
922fbb7b
AC
31646@end smallexample
31647
a2c02241 31648Get info on the selected frame.
922fbb7b
AC
31649
31650@subsubheading @value{GDBN} Command
31651
a2c02241
NR
31652The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
31653(without arguments).
922fbb7b
AC
31654
31655@subsubheading Example
31656
31657@smallexample
594fe323 31658(gdb)
a2c02241
NR
31659-stack-info-frame
31660^done,frame=@{level="1",addr="0x0001076c",func="callee3",
31661file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
31662fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17",
31663arch="i386:x86_64"@}
594fe323 31664(gdb)
922fbb7b
AC
31665@end smallexample
31666
a2c02241
NR
31667@subheading The @code{-stack-info-depth} Command
31668@findex -stack-info-depth
922fbb7b
AC
31669
31670@subsubheading Synopsis
31671
31672@smallexample
a2c02241 31673 -stack-info-depth [ @var{max-depth} ]
922fbb7b
AC
31674@end smallexample
31675
a2c02241
NR
31676Return the depth of the stack. If the integer argument @var{max-depth}
31677is specified, do not count beyond @var{max-depth} frames.
922fbb7b
AC
31678
31679@subsubheading @value{GDBN} Command
31680
a2c02241 31681There's no equivalent @value{GDBN} command.
922fbb7b
AC
31682
31683@subsubheading Example
31684
a2c02241
NR
31685For a stack with frame levels 0 through 11:
31686
922fbb7b 31687@smallexample
594fe323 31688(gdb)
a2c02241
NR
31689-stack-info-depth
31690^done,depth="12"
594fe323 31691(gdb)
a2c02241
NR
31692-stack-info-depth 4
31693^done,depth="4"
594fe323 31694(gdb)
a2c02241
NR
31695-stack-info-depth 12
31696^done,depth="12"
594fe323 31697(gdb)
a2c02241
NR
31698-stack-info-depth 11
31699^done,depth="11"
594fe323 31700(gdb)
a2c02241
NR
31701-stack-info-depth 13
31702^done,depth="12"
594fe323 31703(gdb)
922fbb7b
AC
31704@end smallexample
31705
1e611234 31706@anchor{-stack-list-arguments}
a2c02241
NR
31707@subheading The @code{-stack-list-arguments} Command
31708@findex -stack-list-arguments
922fbb7b
AC
31709
31710@subsubheading Synopsis
31711
31712@smallexample
6211c335 31713 -stack-list-arguments [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
a2c02241 31714 [ @var{low-frame} @var{high-frame} ]
922fbb7b
AC
31715@end smallexample
31716
a2c02241
NR
31717Display a list of the arguments for the frames between @var{low-frame}
31718and @var{high-frame} (inclusive). If @var{low-frame} and
2f1acb09
VP
31719@var{high-frame} are not provided, list the arguments for the whole
31720call stack. If the two arguments are equal, show the single frame
31721at the corresponding level. It is an error if @var{low-frame} is
31722larger than the actual number of frames. On the other hand,
31723@var{high-frame} may be larger than the actual number of frames, in
31724which case only existing frames will be returned.
a2c02241 31725
3afae151
VP
31726If @var{print-values} is 0 or @code{--no-values}, print only the names of
31727the variables; if it is 1 or @code{--all-values}, print also their
31728values; and if it is 2 or @code{--simple-values}, print the name,
31729type and value for simple data types, and the name and type for arrays,
1e611234
PM
31730structures and unions. If the option @code{--no-frame-filters} is
31731supplied, then Python frame filters will not be executed.
31732
6211c335
YQ
31733If the @code{--skip-unavailable} option is specified, arguments that
31734are not available are not listed. Partially available arguments
31735are still displayed, however.
922fbb7b 31736
b3372f91
VP
31737Use of this command to obtain arguments in a single frame is
31738deprecated in favor of the @samp{-stack-list-variables} command.
31739
922fbb7b
AC
31740@subsubheading @value{GDBN} Command
31741
a2c02241
NR
31742@value{GDBN} does not have an equivalent command. @code{gdbtk} has a
31743@samp{gdb_get_args} command which partially overlaps with the
31744functionality of @samp{-stack-list-arguments}.
922fbb7b
AC
31745
31746@subsubheading Example
922fbb7b 31747
a2c02241 31748@smallexample
594fe323 31749(gdb)
a2c02241
NR
31750-stack-list-frames
31751^done,
31752stack=[
31753frame=@{level="0",addr="0x00010734",func="callee4",
31754file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
31755fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
31756arch="i386:x86_64"@},
a2c02241
NR
31757frame=@{level="1",addr="0x0001076c",func="callee3",
31758file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
31759fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17",
31760arch="i386:x86_64"@},
a2c02241
NR
31761frame=@{level="2",addr="0x0001078c",func="callee2",
31762file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
31763fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22",
31764arch="i386:x86_64"@},
a2c02241
NR
31765frame=@{level="3",addr="0x000107b4",func="callee1",
31766file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
31767fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27",
31768arch="i386:x86_64"@},
a2c02241
NR
31769frame=@{level="4",addr="0x000107e0",func="main",
31770file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
6d52907e
JV
31771fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32",
31772arch="i386:x86_64"@}]
594fe323 31773(gdb)
a2c02241
NR
31774-stack-list-arguments 0
31775^done,
31776stack-args=[
31777frame=@{level="0",args=[]@},
31778frame=@{level="1",args=[name="strarg"]@},
31779frame=@{level="2",args=[name="intarg",name="strarg"]@},
31780frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
31781frame=@{level="4",args=[]@}]
594fe323 31782(gdb)
a2c02241
NR
31783-stack-list-arguments 1
31784^done,
31785stack-args=[
31786frame=@{level="0",args=[]@},
31787frame=@{level="1",
31788 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
31789frame=@{level="2",args=[
31790@{name="intarg",value="2"@},
31791@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
31792@{frame=@{level="3",args=[
31793@{name="intarg",value="2"@},
31794@{name="strarg",value="0x11940 \"A string argument.\""@},
31795@{name="fltarg",value="3.5"@}]@},
31796frame=@{level="4",args=[]@}]
594fe323 31797(gdb)
a2c02241
NR
31798-stack-list-arguments 0 2 2
31799^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
594fe323 31800(gdb)
a2c02241
NR
31801-stack-list-arguments 1 2 2
31802^done,stack-args=[frame=@{level="2",
31803args=[@{name="intarg",value="2"@},
31804@{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
594fe323 31805(gdb)
a2c02241
NR
31806@end smallexample
31807
31808@c @subheading -stack-list-exception-handlers
922fbb7b 31809
a2c02241 31810
1e611234 31811@anchor{-stack-list-frames}
a2c02241
NR
31812@subheading The @code{-stack-list-frames} Command
31813@findex -stack-list-frames
1abaf70c
BR
31814
31815@subsubheading Synopsis
31816
31817@smallexample
1e611234 31818 -stack-list-frames [ --no-frame-filters @var{low-frame} @var{high-frame} ]
1abaf70c
BR
31819@end smallexample
31820
a2c02241
NR
31821List the frames currently on the stack. For each frame it displays the
31822following info:
31823
31824@table @samp
31825@item @var{level}
d3e8051b 31826The frame number, 0 being the topmost frame, i.e., the innermost function.
a2c02241
NR
31827@item @var{addr}
31828The @code{$pc} value for that frame.
31829@item @var{func}
31830Function name.
31831@item @var{file}
31832File name of the source file where the function lives.
7d288aaa
TT
31833@item @var{fullname}
31834The full file name of the source file where the function lives.
a2c02241
NR
31835@item @var{line}
31836Line number corresponding to the @code{$pc}.
7d288aaa
TT
31837@item @var{from}
31838The shared library where this function is defined. This is only given
31839if the frame's function is not known.
6d52907e
JV
31840@item @var{arch}
31841Frame's architecture.
a2c02241
NR
31842@end table
31843
31844If invoked without arguments, this command prints a backtrace for the
31845whole stack. If given two integer arguments, it shows the frames whose
31846levels are between the two arguments (inclusive). If the two arguments
2ab1eb7a
VP
31847are equal, it shows the single frame at the corresponding level. It is
31848an error if @var{low-frame} is larger than the actual number of
a5451f4e 31849frames. On the other hand, @var{high-frame} may be larger than the
1e611234
PM
31850actual number of frames, in which case only existing frames will be
31851returned. If the option @code{--no-frame-filters} is supplied, then
31852Python frame filters will not be executed.
1abaf70c
BR
31853
31854@subsubheading @value{GDBN} Command
31855
a2c02241 31856The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
1abaf70c
BR
31857
31858@subsubheading Example
31859
a2c02241
NR
31860Full stack backtrace:
31861
1abaf70c 31862@smallexample
594fe323 31863(gdb)
a2c02241
NR
31864-stack-list-frames
31865^done,stack=
31866[frame=@{level="0",addr="0x0001076c",func="foo",
6d52907e
JV
31867 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="11",
31868 arch="i386:x86_64"@},
a2c02241 31869frame=@{level="1",addr="0x000107a4",func="foo",
6d52907e
JV
31870 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31871 arch="i386:x86_64"@},
a2c02241 31872frame=@{level="2",addr="0x000107a4",func="foo",
6d52907e
JV
31873 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31874 arch="i386:x86_64"@},
a2c02241 31875frame=@{level="3",addr="0x000107a4",func="foo",
6d52907e
JV
31876 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31877 arch="i386:x86_64"@},
a2c02241 31878frame=@{level="4",addr="0x000107a4",func="foo",
6d52907e
JV
31879 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31880 arch="i386:x86_64"@},
a2c02241 31881frame=@{level="5",addr="0x000107a4",func="foo",
6d52907e
JV
31882 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31883 arch="i386:x86_64"@},
a2c02241 31884frame=@{level="6",addr="0x000107a4",func="foo",
6d52907e
JV
31885 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31886 arch="i386:x86_64"@},
a2c02241 31887frame=@{level="7",addr="0x000107a4",func="foo",
6d52907e
JV
31888 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31889 arch="i386:x86_64"@},
a2c02241 31890frame=@{level="8",addr="0x000107a4",func="foo",
6d52907e
JV
31891 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31892 arch="i386:x86_64"@},
a2c02241 31893frame=@{level="9",addr="0x000107a4",func="foo",
6d52907e
JV
31894 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31895 arch="i386:x86_64"@},
a2c02241 31896frame=@{level="10",addr="0x000107a4",func="foo",
6d52907e
JV
31897 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31898 arch="i386:x86_64"@},
a2c02241 31899frame=@{level="11",addr="0x00010738",func="main",
6d52907e
JV
31900 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="4",
31901 arch="i386:x86_64"@}]
594fe323 31902(gdb)
1abaf70c
BR
31903@end smallexample
31904
a2c02241 31905Show frames between @var{low_frame} and @var{high_frame}:
1abaf70c 31906
a2c02241 31907@smallexample
594fe323 31908(gdb)
a2c02241
NR
31909-stack-list-frames 3 5
31910^done,stack=
31911[frame=@{level="3",addr="0x000107a4",func="foo",
6d52907e
JV
31912 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31913 arch="i386:x86_64"@},
a2c02241 31914frame=@{level="4",addr="0x000107a4",func="foo",
6d52907e
JV
31915 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31916 arch="i386:x86_64"@},
a2c02241 31917frame=@{level="5",addr="0x000107a4",func="foo",
6d52907e
JV
31918 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31919 arch="i386:x86_64"@}]
594fe323 31920(gdb)
a2c02241 31921@end smallexample
922fbb7b 31922
a2c02241 31923Show a single frame:
922fbb7b
AC
31924
31925@smallexample
594fe323 31926(gdb)
a2c02241
NR
31927-stack-list-frames 3 3
31928^done,stack=
31929[frame=@{level="3",addr="0x000107a4",func="foo",
6d52907e
JV
31930 file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31931 arch="i386:x86_64"@}]
594fe323 31932(gdb)
922fbb7b
AC
31933@end smallexample
31934
922fbb7b 31935
a2c02241
NR
31936@subheading The @code{-stack-list-locals} Command
31937@findex -stack-list-locals
1e611234 31938@anchor{-stack-list-locals}
57c22c6c 31939
a2c02241 31940@subsubheading Synopsis
922fbb7b
AC
31941
31942@smallexample
6211c335 31943 -stack-list-locals [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
922fbb7b
AC
31944@end smallexample
31945
a2c02241
NR
31946Display the local variable names for the selected frame. If
31947@var{print-values} is 0 or @code{--no-values}, print only the names of
31948the variables; if it is 1 or @code{--all-values}, print also their
31949values; and if it is 2 or @code{--simple-values}, print the name,
3afae151 31950type and value for simple data types, and the name and type for arrays,
a2c02241
NR
31951structures and unions. In this last case, a frontend can immediately
31952display the value of simple data types and create variable objects for
d3e8051b 31953other data types when the user wishes to explore their values in
1e611234
PM
31954more detail. If the option @code{--no-frame-filters} is supplied, then
31955Python frame filters will not be executed.
922fbb7b 31956
6211c335
YQ
31957If the @code{--skip-unavailable} option is specified, local variables
31958that are not available are not listed. Partially available local
31959variables are still displayed, however.
31960
b3372f91
VP
31961This command is deprecated in favor of the
31962@samp{-stack-list-variables} command.
31963
922fbb7b
AC
31964@subsubheading @value{GDBN} Command
31965
a2c02241 31966@samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
922fbb7b
AC
31967
31968@subsubheading Example
922fbb7b
AC
31969
31970@smallexample
594fe323 31971(gdb)
a2c02241
NR
31972-stack-list-locals 0
31973^done,locals=[name="A",name="B",name="C"]
594fe323 31974(gdb)
a2c02241
NR
31975-stack-list-locals --all-values
31976^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
31977 @{name="C",value="@{1, 2, 3@}"@}]
31978-stack-list-locals --simple-values
31979^done,locals=[@{name="A",type="int",value="1"@},
31980 @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
594fe323 31981(gdb)
922fbb7b
AC
31982@end smallexample
31983
1e611234 31984@anchor{-stack-list-variables}
b3372f91
VP
31985@subheading The @code{-stack-list-variables} Command
31986@findex -stack-list-variables
31987
31988@subsubheading Synopsis
31989
31990@smallexample
6211c335 31991 -stack-list-variables [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
b3372f91
VP
31992@end smallexample
31993
31994Display the names of local variables and function arguments for the selected frame. If
31995@var{print-values} is 0 or @code{--no-values}, print only the names of
31996the variables; if it is 1 or @code{--all-values}, print also their
31997values; and if it is 2 or @code{--simple-values}, print the name,
3afae151 31998type and value for simple data types, and the name and type for arrays,
1e611234
PM
31999structures and unions. If the option @code{--no-frame-filters} is
32000supplied, then Python frame filters will not be executed.
b3372f91 32001
6211c335
YQ
32002If the @code{--skip-unavailable} option is specified, local variables
32003and arguments that are not available are not listed. Partially
32004available arguments and local variables are still displayed, however.
32005
b3372f91
VP
32006@subsubheading Example
32007
32008@smallexample
32009(gdb)
32010-stack-list-variables --thread 1 --frame 0 --all-values
4f412fd0 32011^done,variables=[@{name="x",value="11"@},@{name="s",value="@{a = 1, b = 2@}"@}]
b3372f91
VP
32012(gdb)
32013@end smallexample
32014
922fbb7b 32015
a2c02241
NR
32016@subheading The @code{-stack-select-frame} Command
32017@findex -stack-select-frame
922fbb7b
AC
32018
32019@subsubheading Synopsis
32020
32021@smallexample
a2c02241 32022 -stack-select-frame @var{framenum}
922fbb7b
AC
32023@end smallexample
32024
a2c02241
NR
32025Change the selected frame. Select a different frame @var{framenum} on
32026the stack.
922fbb7b 32027
c3b108f7
VP
32028This command in deprecated in favor of passing the @samp{--frame}
32029option to every command.
32030
922fbb7b
AC
32031@subsubheading @value{GDBN} Command
32032
a2c02241
NR
32033The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
32034@samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
922fbb7b
AC
32035
32036@subsubheading Example
32037
32038@smallexample
594fe323 32039(gdb)
a2c02241 32040-stack-select-frame 2
922fbb7b 32041^done
594fe323 32042(gdb)
922fbb7b
AC
32043@end smallexample
32044
32045@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
a2c02241
NR
32046@node GDB/MI Variable Objects
32047@section @sc{gdb/mi} Variable Objects
922fbb7b 32048
a1b5960f 32049@ignore
922fbb7b 32050
a2c02241 32051@subheading Motivation for Variable Objects in @sc{gdb/mi}
922fbb7b 32052
a2c02241
NR
32053For the implementation of a variable debugger window (locals, watched
32054expressions, etc.), we are proposing the adaptation of the existing code
32055used by @code{Insight}.
922fbb7b 32056
a2c02241 32057The two main reasons for that are:
922fbb7b 32058
a2c02241
NR
32059@enumerate 1
32060@item
32061It has been proven in practice (it is already on its second generation).
922fbb7b 32062
a2c02241
NR
32063@item
32064It will shorten development time (needless to say how important it is
32065now).
32066@end enumerate
922fbb7b 32067
a2c02241
NR
32068The original interface was designed to be used by Tcl code, so it was
32069slightly changed so it could be used through @sc{gdb/mi}. This section
32070describes the @sc{gdb/mi} operations that will be available and gives some
32071hints about their use.
922fbb7b 32072
a2c02241
NR
32073@emph{Note}: In addition to the set of operations described here, we
32074expect the @sc{gui} implementation of a variable window to require, at
32075least, the following operations:
922fbb7b 32076
a2c02241
NR
32077@itemize @bullet
32078@item @code{-gdb-show} @code{output-radix}
32079@item @code{-stack-list-arguments}
32080@item @code{-stack-list-locals}
32081@item @code{-stack-select-frame}
32082@end itemize
922fbb7b 32083
a1b5960f
VP
32084@end ignore
32085
c8b2f53c 32086@subheading Introduction to Variable Objects
922fbb7b 32087
a2c02241 32088@cindex variable objects in @sc{gdb/mi}
c8b2f53c
VP
32089
32090Variable objects are "object-oriented" MI interface for examining and
32091changing values of expressions. Unlike some other MI interfaces that
32092work with expressions, variable objects are specifically designed for
32093simple and efficient presentation in the frontend. A variable object
32094is identified by string name. When a variable object is created, the
32095frontend specifies the expression for that variable object. The
32096expression can be a simple variable, or it can be an arbitrary complex
32097expression, and can even involve CPU registers. After creating a
32098variable object, the frontend can invoke other variable object
32099operations---for example to obtain or change the value of a variable
32100object, or to change display format.
32101
32102Variable objects have hierarchical tree structure. Any variable object
32103that corresponds to a composite type, such as structure in C, has
32104a number of child variable objects, for example corresponding to each
32105element of a structure. A child variable object can itself have
32106children, recursively. Recursion ends when we reach
25d5ea92
VP
32107leaf variable objects, which always have built-in types. Child variable
32108objects are created only by explicit request, so if a frontend
32109is not interested in the children of a particular variable object, no
32110child will be created.
c8b2f53c
VP
32111
32112For a leaf variable object it is possible to obtain its value as a
32113string, or set the value from a string. String value can be also
32114obtained for a non-leaf variable object, but it's generally a string
32115that only indicates the type of the object, and does not list its
32116contents. Assignment to a non-leaf variable object is not allowed.
32117
32118A frontend does not need to read the values of all variable objects each time
32119the program stops. Instead, MI provides an update command that lists all
32120variable objects whose values has changed since the last update
32121operation. This considerably reduces the amount of data that must
25d5ea92
VP
32122be transferred to the frontend. As noted above, children variable
32123objects are created on demand, and only leaf variable objects have a
32124real value. As result, gdb will read target memory only for leaf
32125variables that frontend has created.
32126
32127The automatic update is not always desirable. For example, a frontend
32128might want to keep a value of some expression for future reference,
32129and never update it. For another example, fetching memory is
32130relatively slow for embedded targets, so a frontend might want
32131to disable automatic update for the variables that are either not
32132visible on the screen, or ``closed''. This is possible using so
32133called ``frozen variable objects''. Such variable objects are never
32134implicitly updated.
922fbb7b 32135
c3b108f7
VP
32136Variable objects can be either @dfn{fixed} or @dfn{floating}. For the
32137fixed variable object, the expression is parsed when the variable
32138object is created, including associating identifiers to specific
32139variables. The meaning of expression never changes. For a floating
32140variable object the values of variables whose names appear in the
32141expressions are re-evaluated every time in the context of the current
32142frame. Consider this example:
32143
32144@smallexample
32145void do_work(...)
32146@{
32147 struct work_state state;
32148
32149 if (...)
32150 do_work(...);
32151@}
32152@end smallexample
32153
32154If a fixed variable object for the @code{state} variable is created in
7a9dd1b2 32155this function, and we enter the recursive call, the variable
c3b108f7
VP
32156object will report the value of @code{state} in the top-level
32157@code{do_work} invocation. On the other hand, a floating variable
32158object will report the value of @code{state} in the current frame.
32159
32160If an expression specified when creating a fixed variable object
32161refers to a local variable, the variable object becomes bound to the
32162thread and frame in which the variable object is created. When such
32163variable object is updated, @value{GDBN} makes sure that the
32164thread/frame combination the variable object is bound to still exists,
32165and re-evaluates the variable object in context of that thread/frame.
32166
a2c02241
NR
32167The following is the complete set of @sc{gdb/mi} operations defined to
32168access this functionality:
922fbb7b 32169
a2c02241
NR
32170@multitable @columnfractions .4 .6
32171@item @strong{Operation}
32172@tab @strong{Description}
922fbb7b 32173
0cc7d26f
TT
32174@item @code{-enable-pretty-printing}
32175@tab enable Python-based pretty-printing
a2c02241
NR
32176@item @code{-var-create}
32177@tab create a variable object
32178@item @code{-var-delete}
22d8a470 32179@tab delete the variable object and/or its children
a2c02241
NR
32180@item @code{-var-set-format}
32181@tab set the display format of this variable
32182@item @code{-var-show-format}
32183@tab show the display format of this variable
32184@item @code{-var-info-num-children}
32185@tab tells how many children this object has
32186@item @code{-var-list-children}
32187@tab return a list of the object's children
32188@item @code{-var-info-type}
32189@tab show the type of this variable object
32190@item @code{-var-info-expression}
02142340
VP
32191@tab print parent-relative expression that this variable object represents
32192@item @code{-var-info-path-expression}
32193@tab print full expression that this variable object represents
a2c02241
NR
32194@item @code{-var-show-attributes}
32195@tab is this variable editable? does it exist here?
32196@item @code{-var-evaluate-expression}
32197@tab get the value of this variable
32198@item @code{-var-assign}
32199@tab set the value of this variable
32200@item @code{-var-update}
32201@tab update the variable and its children
25d5ea92 32202@item @code{-var-set-frozen}
6b92c0d3 32203@tab set frozenness attribute
0cc7d26f
TT
32204@item @code{-var-set-update-range}
32205@tab set range of children to display on update
a2c02241 32206@end multitable
922fbb7b 32207
a2c02241
NR
32208In the next subsection we describe each operation in detail and suggest
32209how it can be used.
922fbb7b 32210
a2c02241 32211@subheading Description And Use of Operations on Variable Objects
922fbb7b 32212
0cc7d26f
TT
32213@subheading The @code{-enable-pretty-printing} Command
32214@findex -enable-pretty-printing
32215
32216@smallexample
32217-enable-pretty-printing
32218@end smallexample
32219
32220@value{GDBN} allows Python-based visualizers to affect the output of the
32221MI variable object commands. However, because there was no way to
32222implement this in a fully backward-compatible way, a front end must
32223request that this functionality be enabled.
32224
32225Once enabled, this feature cannot be disabled.
32226
32227Note that if Python support has not been compiled into @value{GDBN},
32228this command will still succeed (and do nothing).
32229
f43030c4
TT
32230This feature is currently (as of @value{GDBN} 7.0) experimental, and
32231may work differently in future versions of @value{GDBN}.
32232
a2c02241
NR
32233@subheading The @code{-var-create} Command
32234@findex -var-create
ef21caaf 32235
a2c02241 32236@subsubheading Synopsis
ef21caaf 32237
a2c02241
NR
32238@smallexample
32239 -var-create @{@var{name} | "-"@}
c3b108f7 32240 @{@var{frame-addr} | "*" | "@@"@} @var{expression}
a2c02241
NR
32241@end smallexample
32242
32243This operation creates a variable object, which allows the monitoring of
32244a variable, the result of an expression, a memory cell or a CPU
32245register.
ef21caaf 32246
a2c02241
NR
32247The @var{name} parameter is the string by which the object can be
32248referenced. It must be unique. If @samp{-} is specified, the varobj
32249system will generate a string ``varNNNNNN'' automatically. It will be
c3b108f7 32250unique provided that one does not specify @var{name} of that format.
a2c02241 32251The command fails if a duplicate name is found.
ef21caaf 32252
a2c02241
NR
32253The frame under which the expression should be evaluated can be
32254specified by @var{frame-addr}. A @samp{*} indicates that the current
c3b108f7
VP
32255frame should be used. A @samp{@@} indicates that a floating variable
32256object must be created.
922fbb7b 32257
a2c02241
NR
32258@var{expression} is any expression valid on the current language set (must not
32259begin with a @samp{*}), or one of the following:
922fbb7b 32260
a2c02241
NR
32261@itemize @bullet
32262@item
32263@samp{*@var{addr}}, where @var{addr} is the address of a memory cell
922fbb7b 32264
a2c02241
NR
32265@item
32266@samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
922fbb7b 32267
a2c02241
NR
32268@item
32269@samp{$@var{regname}} --- a CPU register name
32270@end itemize
922fbb7b 32271
0cc7d26f
TT
32272@cindex dynamic varobj
32273A varobj's contents may be provided by a Python-based pretty-printer. In this
32274case the varobj is known as a @dfn{dynamic varobj}. Dynamic varobjs
32275have slightly different semantics in some cases. If the
32276@code{-enable-pretty-printing} command is not sent, then @value{GDBN}
32277will never create a dynamic varobj. This ensures backward
32278compatibility for existing clients.
32279
a2c02241 32280@subsubheading Result
922fbb7b 32281
0cc7d26f
TT
32282This operation returns attributes of the newly-created varobj. These
32283are:
32284
32285@table @samp
32286@item name
32287The name of the varobj.
32288
32289@item numchild
32290The number of children of the varobj. This number is not necessarily
32291reliable for a dynamic varobj. Instead, you must examine the
32292@samp{has_more} attribute.
32293
32294@item value
32295The varobj's scalar value. For a varobj whose type is some sort of
32296aggregate (e.g., a @code{struct}), or for a dynamic varobj, this value
32297will not be interesting.
32298
32299@item type
32300The varobj's type. This is a string representation of the type, as
8264ba82
AG
32301would be printed by the @value{GDBN} CLI. If @samp{print object}
32302(@pxref{Print Settings, set print object}) is set to @code{on}, the
32303@emph{actual} (derived) type of the object is shown rather than the
32304@emph{declared} one.
0cc7d26f
TT
32305
32306@item thread-id
32307If a variable object is bound to a specific thread, then this is the
5d5658a1 32308thread's global identifier.
0cc7d26f
TT
32309
32310@item has_more
32311For a dynamic varobj, this indicates whether there appear to be any
32312children available. For a non-dynamic varobj, this will be 0.
32313
32314@item dynamic
32315This attribute will be present and have the value @samp{1} if the
32316varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
32317then this attribute will not be present.
32318
32319@item displayhint
32320A dynamic varobj can supply a display hint to the front end. The
32321value comes directly from the Python pretty-printer object's
4c374409 32322@code{display_hint} method. @xref{Pretty Printing API}.
0cc7d26f
TT
32323@end table
32324
32325Typical output will look like this:
922fbb7b
AC
32326
32327@smallexample
0cc7d26f
TT
32328 name="@var{name}",numchild="@var{N}",type="@var{type}",thread-id="@var{M}",
32329 has_more="@var{has_more}"
dcaaae04
NR
32330@end smallexample
32331
a2c02241
NR
32332
32333@subheading The @code{-var-delete} Command
32334@findex -var-delete
922fbb7b
AC
32335
32336@subsubheading Synopsis
32337
32338@smallexample
22d8a470 32339 -var-delete [ -c ] @var{name}
922fbb7b
AC
32340@end smallexample
32341
a2c02241 32342Deletes a previously created variable object and all of its children.
22d8a470 32343With the @samp{-c} option, just deletes the children.
922fbb7b 32344
a2c02241 32345Returns an error if the object @var{name} is not found.
922fbb7b 32346
922fbb7b 32347
a2c02241
NR
32348@subheading The @code{-var-set-format} Command
32349@findex -var-set-format
922fbb7b 32350
a2c02241 32351@subsubheading Synopsis
922fbb7b
AC
32352
32353@smallexample
a2c02241 32354 -var-set-format @var{name} @var{format-spec}
922fbb7b
AC
32355@end smallexample
32356
a2c02241
NR
32357Sets the output format for the value of the object @var{name} to be
32358@var{format-spec}.
32359
de051565 32360@anchor{-var-set-format}
a2c02241
NR
32361The syntax for the @var{format-spec} is as follows:
32362
32363@smallexample
32364 @var{format-spec} @expansion{}
1c35a88f 32365 @{binary | decimal | hexadecimal | octal | natural | zero-hexadecimal@}
a2c02241
NR
32366@end smallexample
32367
c8b2f53c
VP
32368The natural format is the default format choosen automatically
32369based on the variable type (like decimal for an @code{int}, hex
32370for pointers, etc.).
32371
1c35a88f
LM
32372The zero-hexadecimal format has a representation similar to hexadecimal
32373but with padding zeroes to the left of the value. For example, a 32-bit
32374hexadecimal value of 0x1234 would be represented as 0x00001234 in the
32375zero-hexadecimal format.
32376
c8b2f53c
VP
32377For a variable with children, the format is set only on the
32378variable itself, and the children are not affected.
a2c02241
NR
32379
32380@subheading The @code{-var-show-format} Command
32381@findex -var-show-format
922fbb7b
AC
32382
32383@subsubheading Synopsis
32384
32385@smallexample
a2c02241 32386 -var-show-format @var{name}
922fbb7b
AC
32387@end smallexample
32388
a2c02241 32389Returns the format used to display the value of the object @var{name}.
922fbb7b 32390
a2c02241
NR
32391@smallexample
32392 @var{format} @expansion{}
32393 @var{format-spec}
32394@end smallexample
922fbb7b 32395
922fbb7b 32396
a2c02241
NR
32397@subheading The @code{-var-info-num-children} Command
32398@findex -var-info-num-children
32399
32400@subsubheading Synopsis
32401
32402@smallexample
32403 -var-info-num-children @var{name}
32404@end smallexample
32405
32406Returns the number of children of a variable object @var{name}:
32407
32408@smallexample
32409 numchild=@var{n}
32410@end smallexample
32411
0cc7d26f
TT
32412Note that this number is not completely reliable for a dynamic varobj.
32413It will return the current number of children, but more children may
32414be available.
32415
a2c02241
NR
32416
32417@subheading The @code{-var-list-children} Command
32418@findex -var-list-children
32419
32420@subsubheading Synopsis
32421
32422@smallexample
0cc7d26f 32423 -var-list-children [@var{print-values}] @var{name} [@var{from} @var{to}]
a2c02241 32424@end smallexample
b569d230 32425@anchor{-var-list-children}
a2c02241
NR
32426
32427Return a list of the children of the specified variable object and
32428create variable objects for them, if they do not already exist. With
f5011d11 32429a single argument or if @var{print-values} has a value of 0 or
a2c02241
NR
32430@code{--no-values}, print only the names of the variables; if
32431@var{print-values} is 1 or @code{--all-values}, also print their
32432values; and if it is 2 or @code{--simple-values} print the name and
32433value for simple data types and just the name for arrays, structures
32434and unions.
922fbb7b 32435
0cc7d26f
TT
32436@var{from} and @var{to}, if specified, indicate the range of children
32437to report. If @var{from} or @var{to} is less than zero, the range is
32438reset and all children will be reported. Otherwise, children starting
32439at @var{from} (zero-based) and up to and excluding @var{to} will be
32440reported.
32441
32442If a child range is requested, it will only affect the current call to
32443@code{-var-list-children}, but not future calls to @code{-var-update}.
32444For this, you must instead use @code{-var-set-update-range}. The
32445intent of this approach is to enable a front end to implement any
32446update approach it likes; for example, scrolling a view may cause the
32447front end to request more children with @code{-var-list-children}, and
32448then the front end could call @code{-var-set-update-range} with a
32449different range to ensure that future updates are restricted to just
32450the visible items.
32451
b569d230
EZ
32452For each child the following results are returned:
32453
32454@table @var
32455
32456@item name
32457Name of the variable object created for this child.
32458
32459@item exp
32460The expression to be shown to the user by the front end to designate this child.
32461For example this may be the name of a structure member.
32462
0cc7d26f
TT
32463For a dynamic varobj, this value cannot be used to form an
32464expression. There is no way to do this at all with a dynamic varobj.
32465
b569d230
EZ
32466For C/C@t{++} structures there are several pseudo children returned to
32467designate access qualifiers. For these pseudo children @var{exp} is
32468@samp{public}, @samp{private}, or @samp{protected}. In this case the
32469type and value are not present.
32470
0cc7d26f
TT
32471A dynamic varobj will not report the access qualifying
32472pseudo-children, regardless of the language. This information is not
32473available at all with a dynamic varobj.
32474
b569d230 32475@item numchild
0cc7d26f
TT
32476Number of children this child has. For a dynamic varobj, this will be
324770.
b569d230
EZ
32478
32479@item type
8264ba82
AG
32480The type of the child. If @samp{print object}
32481(@pxref{Print Settings, set print object}) is set to @code{on}, the
32482@emph{actual} (derived) type of the object is shown rather than the
32483@emph{declared} one.
b569d230
EZ
32484
32485@item value
32486If values were requested, this is the value.
32487
32488@item thread-id
5d5658a1
PA
32489If this variable object is associated with a thread, this is the
32490thread's global thread id. Otherwise this result is not present.
b569d230
EZ
32491
32492@item frozen
32493If the variable object is frozen, this variable will be present with a value of 1.
c78feb39 32494
9df9dbe0
YQ
32495@item displayhint
32496A dynamic varobj can supply a display hint to the front end. The
32497value comes directly from the Python pretty-printer object's
32498@code{display_hint} method. @xref{Pretty Printing API}.
32499
c78feb39
YQ
32500@item dynamic
32501This attribute will be present and have the value @samp{1} if the
32502varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
32503then this attribute will not be present.
32504
b569d230
EZ
32505@end table
32506
0cc7d26f
TT
32507The result may have its own attributes:
32508
32509@table @samp
32510@item displayhint
32511A dynamic varobj can supply a display hint to the front end. The
32512value comes directly from the Python pretty-printer object's
4c374409 32513@code{display_hint} method. @xref{Pretty Printing API}.
0cc7d26f
TT
32514
32515@item has_more
32516This is an integer attribute which is nonzero if there are children
32517remaining after the end of the selected range.
32518@end table
32519
922fbb7b
AC
32520@subsubheading Example
32521
32522@smallexample
594fe323 32523(gdb)
a2c02241 32524 -var-list-children n
b569d230 32525 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
a2c02241 32526 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
594fe323 32527(gdb)
a2c02241 32528 -var-list-children --all-values n
b569d230 32529 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
a2c02241 32530 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
922fbb7b
AC
32531@end smallexample
32532
922fbb7b 32533
a2c02241
NR
32534@subheading The @code{-var-info-type} Command
32535@findex -var-info-type
922fbb7b 32536
a2c02241
NR
32537@subsubheading Synopsis
32538
32539@smallexample
32540 -var-info-type @var{name}
32541@end smallexample
32542
32543Returns the type of the specified variable @var{name}. The type is
32544returned as a string in the same format as it is output by the
32545@value{GDBN} CLI:
32546
32547@smallexample
32548 type=@var{typename}
32549@end smallexample
32550
32551
32552@subheading The @code{-var-info-expression} Command
32553@findex -var-info-expression
922fbb7b
AC
32554
32555@subsubheading Synopsis
32556
32557@smallexample
a2c02241 32558 -var-info-expression @var{name}
922fbb7b
AC
32559@end smallexample
32560
02142340
VP
32561Returns a string that is suitable for presenting this
32562variable object in user interface. The string is generally
32563not valid expression in the current language, and cannot be evaluated.
32564
32565For example, if @code{a} is an array, and variable object
32566@code{A} was created for @code{a}, then we'll get this output:
922fbb7b 32567
a2c02241 32568@smallexample
02142340
VP
32569(gdb) -var-info-expression A.1
32570^done,lang="C",exp="1"
a2c02241 32571@end smallexample
922fbb7b 32572
a2c02241 32573@noindent
fa4d0c40
YQ
32574Here, the value of @code{lang} is the language name, which can be
32575found in @ref{Supported Languages}.
02142340
VP
32576
32577Note that the output of the @code{-var-list-children} command also
32578includes those expressions, so the @code{-var-info-expression} command
32579is of limited use.
32580
32581@subheading The @code{-var-info-path-expression} Command
32582@findex -var-info-path-expression
32583
32584@subsubheading Synopsis
32585
32586@smallexample
32587 -var-info-path-expression @var{name}
32588@end smallexample
32589
32590Returns an expression that can be evaluated in the current
32591context and will yield the same value that a variable object has.
32592Compare this with the @code{-var-info-expression} command, which
32593result can be used only for UI presentation. Typical use of
32594the @code{-var-info-path-expression} command is creating a
32595watchpoint from a variable object.
32596
0cc7d26f
TT
32597This command is currently not valid for children of a dynamic varobj,
32598and will give an error when invoked on one.
32599
02142340
VP
32600For example, suppose @code{C} is a C@t{++} class, derived from class
32601@code{Base}, and that the @code{Base} class has a member called
32602@code{m_size}. Assume a variable @code{c} is has the type of
32603@code{C} and a variable object @code{C} was created for variable
32604@code{c}. Then, we'll get this output:
32605@smallexample
32606(gdb) -var-info-path-expression C.Base.public.m_size
32607^done,path_expr=((Base)c).m_size)
32608@end smallexample
922fbb7b 32609
a2c02241
NR
32610@subheading The @code{-var-show-attributes} Command
32611@findex -var-show-attributes
922fbb7b 32612
a2c02241 32613@subsubheading Synopsis
922fbb7b 32614
a2c02241
NR
32615@smallexample
32616 -var-show-attributes @var{name}
32617@end smallexample
922fbb7b 32618
a2c02241 32619List attributes of the specified variable object @var{name}:
922fbb7b
AC
32620
32621@smallexample
a2c02241 32622 status=@var{attr} [ ( ,@var{attr} )* ]
922fbb7b
AC
32623@end smallexample
32624
a2c02241
NR
32625@noindent
32626where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
32627
32628@subheading The @code{-var-evaluate-expression} Command
32629@findex -var-evaluate-expression
32630
32631@subsubheading Synopsis
32632
32633@smallexample
de051565 32634 -var-evaluate-expression [-f @var{format-spec}] @var{name}
a2c02241
NR
32635@end smallexample
32636
32637Evaluates the expression that is represented by the specified variable
de051565
MK
32638object and returns its value as a string. The format of the string
32639can be specified with the @samp{-f} option. The possible values of
32640this option are the same as for @code{-var-set-format}
32641(@pxref{-var-set-format}). If the @samp{-f} option is not specified,
32642the current display format will be used. The current display format
32643can be changed using the @code{-var-set-format} command.
a2c02241
NR
32644
32645@smallexample
32646 value=@var{value}
32647@end smallexample
32648
32649Note that one must invoke @code{-var-list-children} for a variable
32650before the value of a child variable can be evaluated.
32651
32652@subheading The @code{-var-assign} Command
32653@findex -var-assign
32654
32655@subsubheading Synopsis
32656
32657@smallexample
32658 -var-assign @var{name} @var{expression}
32659@end smallexample
32660
32661Assigns the value of @var{expression} to the variable object specified
32662by @var{name}. The object must be @samp{editable}. If the variable's
32663value is altered by the assign, the variable will show up in any
32664subsequent @code{-var-update} list.
32665
32666@subsubheading Example
922fbb7b
AC
32667
32668@smallexample
594fe323 32669(gdb)
a2c02241
NR
32670-var-assign var1 3
32671^done,value="3"
594fe323 32672(gdb)
a2c02241
NR
32673-var-update *
32674^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
594fe323 32675(gdb)
922fbb7b
AC
32676@end smallexample
32677
a2c02241
NR
32678@subheading The @code{-var-update} Command
32679@findex -var-update
32680
32681@subsubheading Synopsis
32682
32683@smallexample
32684 -var-update [@var{print-values}] @{@var{name} | "*"@}
32685@end smallexample
32686
c8b2f53c
VP
32687Reevaluate the expressions corresponding to the variable object
32688@var{name} and all its direct and indirect children, and return the
36ece8b3
NR
32689list of variable objects whose values have changed; @var{name} must
32690be a root variable object. Here, ``changed'' means that the result of
32691@code{-var-evaluate-expression} before and after the
32692@code{-var-update} is different. If @samp{*} is used as the variable
9f708cb2
VP
32693object names, all existing variable objects are updated, except
32694for frozen ones (@pxref{-var-set-frozen}). The option
36ece8b3 32695@var{print-values} determines whether both names and values, or just
de051565 32696names are printed. The possible values of this option are the same
36ece8b3
NR
32697as for @code{-var-list-children} (@pxref{-var-list-children}). It is
32698recommended to use the @samp{--all-values} option, to reduce the
32699number of MI commands needed on each program stop.
c8b2f53c 32700
c3b108f7
VP
32701With the @samp{*} parameter, if a variable object is bound to a
32702currently running thread, it will not be updated, without any
32703diagnostic.
a2c02241 32704
0cc7d26f
TT
32705If @code{-var-set-update-range} was previously used on a varobj, then
32706only the selected range of children will be reported.
922fbb7b 32707
0cc7d26f
TT
32708@code{-var-update} reports all the changed varobjs in a tuple named
32709@samp{changelist}.
32710
32711Each item in the change list is itself a tuple holding:
32712
32713@table @samp
32714@item name
32715The name of the varobj.
32716
32717@item value
32718If values were requested for this update, then this field will be
32719present and will hold the value of the varobj.
922fbb7b 32720
0cc7d26f 32721@item in_scope
9f708cb2 32722@anchor{-var-update}
0cc7d26f 32723This field is a string which may take one of three values:
36ece8b3
NR
32724
32725@table @code
32726@item "true"
32727The variable object's current value is valid.
32728
32729@item "false"
32730The variable object does not currently hold a valid value but it may
32731hold one in the future if its associated expression comes back into
32732scope.
32733
32734@item "invalid"
32735The variable object no longer holds a valid value.
32736This can occur when the executable file being debugged has changed,
32737either through recompilation or by using the @value{GDBN} @code{file}
32738command. The front end should normally choose to delete these variable
32739objects.
32740@end table
32741
32742In the future new values may be added to this list so the front should
32743be prepared for this possibility. @xref{GDB/MI Development and Front Ends, ,@sc{GDB/MI} Development and Front Ends}.
32744
0cc7d26f
TT
32745@item type_changed
32746This is only present if the varobj is still valid. If the type
32747changed, then this will be the string @samp{true}; otherwise it will
32748be @samp{false}.
32749
7191c139
JB
32750When a varobj's type changes, its children are also likely to have
32751become incorrect. Therefore, the varobj's children are automatically
32752deleted when this attribute is @samp{true}. Also, the varobj's update
32753range, when set using the @code{-var-set-update-range} command, is
32754unset.
32755
0cc7d26f
TT
32756@item new_type
32757If the varobj's type changed, then this field will be present and will
32758hold the new type.
32759
32760@item new_num_children
32761For a dynamic varobj, if the number of children changed, or if the
32762type changed, this will be the new number of children.
32763
32764The @samp{numchild} field in other varobj responses is generally not
32765valid for a dynamic varobj -- it will show the number of children that
32766@value{GDBN} knows about, but because dynamic varobjs lazily
32767instantiate their children, this will not reflect the number of
32768children which may be available.
32769
32770The @samp{new_num_children} attribute only reports changes to the
32771number of children known by @value{GDBN}. This is the only way to
32772detect whether an update has removed children (which necessarily can
32773only happen at the end of the update range).
32774
32775@item displayhint
32776The display hint, if any.
32777
32778@item has_more
32779This is an integer value, which will be 1 if there are more children
32780available outside the varobj's update range.
32781
32782@item dynamic
32783This attribute will be present and have the value @samp{1} if the
32784varobj is a dynamic varobj. If the varobj is not a dynamic varobj,
32785then this attribute will not be present.
32786
32787@item new_children
32788If new children were added to a dynamic varobj within the selected
32789update range (as set by @code{-var-set-update-range}), then they will
32790be listed in this attribute.
32791@end table
32792
32793@subsubheading Example
32794
32795@smallexample
32796(gdb)
32797-var-assign var1 3
32798^done,value="3"
32799(gdb)
32800-var-update --all-values var1
32801^done,changelist=[@{name="var1",value="3",in_scope="true",
32802type_changed="false"@}]
32803(gdb)
32804@end smallexample
32805
25d5ea92
VP
32806@subheading The @code{-var-set-frozen} Command
32807@findex -var-set-frozen
9f708cb2 32808@anchor{-var-set-frozen}
25d5ea92
VP
32809
32810@subsubheading Synopsis
32811
32812@smallexample
9f708cb2 32813 -var-set-frozen @var{name} @var{flag}
25d5ea92
VP
32814@end smallexample
32815
9f708cb2 32816Set the frozenness flag on the variable object @var{name}. The
25d5ea92 32817@var{flag} parameter should be either @samp{1} to make the variable
9f708cb2 32818frozen or @samp{0} to make it unfrozen. If a variable object is
25d5ea92 32819frozen, then neither itself, nor any of its children, are
9f708cb2 32820implicitly updated by @code{-var-update} of
25d5ea92
VP
32821a parent variable or by @code{-var-update *}. Only
32822@code{-var-update} of the variable itself will update its value and
32823values of its children. After a variable object is unfrozen, it is
32824implicitly updated by all subsequent @code{-var-update} operations.
32825Unfreezing a variable does not update it, only subsequent
32826@code{-var-update} does.
32827
32828@subsubheading Example
32829
32830@smallexample
32831(gdb)
32832-var-set-frozen V 1
32833^done
32834(gdb)
32835@end smallexample
32836
0cc7d26f
TT
32837@subheading The @code{-var-set-update-range} command
32838@findex -var-set-update-range
32839@anchor{-var-set-update-range}
32840
32841@subsubheading Synopsis
32842
32843@smallexample
32844 -var-set-update-range @var{name} @var{from} @var{to}
32845@end smallexample
32846
32847Set the range of children to be returned by future invocations of
32848@code{-var-update}.
32849
32850@var{from} and @var{to} indicate the range of children to report. If
32851@var{from} or @var{to} is less than zero, the range is reset and all
32852children will be reported. Otherwise, children starting at @var{from}
32853(zero-based) and up to and excluding @var{to} will be reported.
32854
32855@subsubheading Example
32856
32857@smallexample
32858(gdb)
32859-var-set-update-range V 1 2
32860^done
32861@end smallexample
32862
b6313243
TT
32863@subheading The @code{-var-set-visualizer} command
32864@findex -var-set-visualizer
32865@anchor{-var-set-visualizer}
32866
32867@subsubheading Synopsis
32868
32869@smallexample
32870 -var-set-visualizer @var{name} @var{visualizer}
32871@end smallexample
32872
32873Set a visualizer for the variable object @var{name}.
32874
32875@var{visualizer} is the visualizer to use. The special value
32876@samp{None} means to disable any visualizer in use.
32877
32878If not @samp{None}, @var{visualizer} must be a Python expression.
32879This expression must evaluate to a callable object which accepts a
32880single argument. @value{GDBN} will call this object with the value of
32881the varobj @var{name} as an argument (this is done so that the same
32882Python pretty-printing code can be used for both the CLI and MI).
32883When called, this object must return an object which conforms to the
4c374409 32884pretty-printing interface (@pxref{Pretty Printing API}).
b6313243
TT
32885
32886The pre-defined function @code{gdb.default_visualizer} may be used to
32887select a visualizer by following the built-in process
32888(@pxref{Selecting Pretty-Printers}). This is done automatically when
32889a varobj is created, and so ordinarily is not needed.
32890
32891This feature is only available if Python support is enabled. The MI
d192b373 32892command @code{-list-features} (@pxref{GDB/MI Support Commands})
b6313243
TT
32893can be used to check this.
32894
32895@subsubheading Example
32896
32897Resetting the visualizer:
32898
32899@smallexample
32900(gdb)
32901-var-set-visualizer V None
32902^done
32903@end smallexample
32904
32905Reselecting the default (type-based) visualizer:
32906
32907@smallexample
32908(gdb)
32909-var-set-visualizer V gdb.default_visualizer
32910^done
32911@end smallexample
32912
32913Suppose @code{SomeClass} is a visualizer class. A lambda expression
32914can be used to instantiate this class for a varobj:
32915
32916@smallexample
32917(gdb)
32918-var-set-visualizer V "lambda val: SomeClass()"
32919^done
32920@end smallexample
25d5ea92 32921
a2c02241
NR
32922@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32923@node GDB/MI Data Manipulation
32924@section @sc{gdb/mi} Data Manipulation
922fbb7b 32925
a2c02241
NR
32926@cindex data manipulation, in @sc{gdb/mi}
32927@cindex @sc{gdb/mi}, data manipulation
32928This section describes the @sc{gdb/mi} commands that manipulate data:
32929examine memory and registers, evaluate expressions, etc.
32930
a86c90e6
SM
32931For details about what an addressable memory unit is,
32932@pxref{addressable memory unit}.
32933
a2c02241
NR
32934@c REMOVED FROM THE INTERFACE.
32935@c @subheading -data-assign
32936@c Change the value of a program variable. Plenty of side effects.
79a6e687 32937@c @subsubheading GDB Command
a2c02241
NR
32938@c set variable
32939@c @subsubheading Example
32940@c N.A.
32941
32942@subheading The @code{-data-disassemble} Command
32943@findex -data-disassemble
922fbb7b
AC
32944
32945@subsubheading Synopsis
32946
32947@smallexample
a2c02241
NR
32948 -data-disassemble
32949 [ -s @var{start-addr} -e @var{end-addr} ]
26fb3983 32950 | [ -a @var{addr} ]
a2c02241
NR
32951 | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
32952 -- @var{mode}
922fbb7b
AC
32953@end smallexample
32954
a2c02241
NR
32955@noindent
32956Where:
32957
32958@table @samp
32959@item @var{start-addr}
32960is the beginning address (or @code{$pc})
32961@item @var{end-addr}
32962is the end address
26fb3983
JV
32963@item @var{addr}
32964is an address anywhere within (or the name of) the function to
32965disassemble. If an address is specified, the whole function
32966surrounding that address will be disassembled. If a name is
32967specified, the whole function with that name will be disassembled.
a2c02241
NR
32968@item @var{filename}
32969is the name of the file to disassemble
32970@item @var{linenum}
32971is the line number to disassemble around
32972@item @var{lines}
d3e8051b 32973is the number of disassembly lines to be produced. If it is -1,
a2c02241
NR
32974the whole function will be disassembled, in case no @var{end-addr} is
32975specified. If @var{end-addr} is specified as a non-zero value, and
32976@var{lines} is lower than the number of disassembly lines between
32977@var{start-addr} and @var{end-addr}, only @var{lines} lines are
32978displayed; if @var{lines} is higher than the number of lines between
32979@var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
32980are displayed.
32981@item @var{mode}
6ff0ba5f
DE
32982is one of:
32983@itemize @bullet
32984@item 0 disassembly only
32985@item 1 mixed source and disassembly (deprecated)
32986@item 2 disassembly with raw opcodes
32987@item 3 mixed source and disassembly with raw opcodes (deprecated)
32988@item 4 mixed source and disassembly
32989@item 5 mixed source and disassembly with raw opcodes
32990@end itemize
32991
32992Modes 1 and 3 are deprecated. The output is ``source centric''
32993which hasn't proved useful in practice.
32994@xref{Machine Code}, for a discussion of the difference between
32995@code{/m} and @code{/s} output of the @code{disassemble} command.
a2c02241
NR
32996@end table
32997
32998@subsubheading Result
32999
ed8a1c2d
AB
33000The result of the @code{-data-disassemble} command will be a list named
33001@samp{asm_insns}, the contents of this list depend on the @var{mode}
33002used with the @code{-data-disassemble} command.
a2c02241 33003
ed8a1c2d
AB
33004For modes 0 and 2 the @samp{asm_insns} list contains tuples with the
33005following fields:
33006
33007@table @code
33008@item address
33009The address at which this instruction was disassembled.
33010
33011@item func-name
33012The name of the function this instruction is within.
33013
33014@item offset
33015The decimal offset in bytes from the start of @samp{func-name}.
33016
33017@item inst
33018The text disassembly for this @samp{address}.
33019
33020@item opcodes
6ff0ba5f 33021This field is only present for modes 2, 3 and 5. This contains the raw opcode
ed8a1c2d
AB
33022bytes for the @samp{inst} field.
33023
33024@end table
33025
6ff0ba5f 33026For modes 1, 3, 4 and 5 the @samp{asm_insns} list contains tuples named
ed8a1c2d 33027@samp{src_and_asm_line}, each of which has the following fields:
a2c02241 33028
ed8a1c2d
AB
33029@table @code
33030@item line
33031The line number within @samp{file}.
33032
33033@item file
33034The file name from the compilation unit. This might be an absolute
33035file name or a relative file name depending on the compile command
33036used.
33037
33038@item fullname
f35a17b5
JK
33039Absolute file name of @samp{file}. It is converted to a canonical form
33040using the source file search path
33041(@pxref{Source Path, ,Specifying Source Directories})
33042and after resolving all the symbolic links.
33043
33044If the source file is not found this field will contain the path as
33045present in the debug information.
ed8a1c2d
AB
33046
33047@item line_asm_insn
33048This is a list of tuples containing the disassembly for @samp{line} in
33049@samp{file}. The fields of each tuple are the same as for
33050@code{-data-disassemble} in @var{mode} 0 and 2, so @samp{address},
33051@samp{func-name}, @samp{offset}, @samp{inst}, and optionally
33052@samp{opcodes}.
33053
33054@end table
33055
33056Note that whatever included in the @samp{inst} field, is not
33057manipulated directly by @sc{gdb/mi}, i.e., it is not possible to
33058adjust its format.
922fbb7b
AC
33059
33060@subsubheading @value{GDBN} Command
33061
ed8a1c2d 33062The corresponding @value{GDBN} command is @samp{disassemble}.
922fbb7b
AC
33063
33064@subsubheading Example
33065
a2c02241
NR
33066Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
33067
922fbb7b 33068@smallexample
594fe323 33069(gdb)
a2c02241
NR
33070-data-disassemble -s $pc -e "$pc + 20" -- 0
33071^done,
33072asm_insns=[
33073@{address="0x000107c0",func-name="main",offset="4",
33074inst="mov 2, %o0"@},
33075@{address="0x000107c4",func-name="main",offset="8",
33076inst="sethi %hi(0x11800), %o2"@},
33077@{address="0x000107c8",func-name="main",offset="12",
33078inst="or %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
33079@{address="0x000107cc",func-name="main",offset="16",
33080inst="sethi %hi(0x11800), %o2"@},
33081@{address="0x000107d0",func-name="main",offset="20",
33082inst="or %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
594fe323 33083(gdb)
a2c02241
NR
33084@end smallexample
33085
33086Disassemble the whole @code{main} function. Line 32 is part of
33087@code{main}.
33088
33089@smallexample
33090-data-disassemble -f basics.c -l 32 -- 0
33091^done,asm_insns=[
33092@{address="0x000107bc",func-name="main",offset="0",
33093inst="save %sp, -112, %sp"@},
33094@{address="0x000107c0",func-name="main",offset="4",
33095inst="mov 2, %o0"@},
33096@{address="0x000107c4",func-name="main",offset="8",
33097inst="sethi %hi(0x11800), %o2"@},
33098[@dots{}]
33099@{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
33100@{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
594fe323 33101(gdb)
922fbb7b
AC
33102@end smallexample
33103
a2c02241 33104Disassemble 3 instructions from the start of @code{main}:
922fbb7b 33105
a2c02241 33106@smallexample
594fe323 33107(gdb)
a2c02241
NR
33108-data-disassemble -f basics.c -l 32 -n 3 -- 0
33109^done,asm_insns=[
33110@{address="0x000107bc",func-name="main",offset="0",
33111inst="save %sp, -112, %sp"@},
33112@{address="0x000107c0",func-name="main",offset="4",
33113inst="mov 2, %o0"@},
33114@{address="0x000107c4",func-name="main",offset="8",
33115inst="sethi %hi(0x11800), %o2"@}]
594fe323 33116(gdb)
a2c02241
NR
33117@end smallexample
33118
33119Disassemble 3 instructions from the start of @code{main} in mixed mode:
33120
33121@smallexample
594fe323 33122(gdb)
a2c02241
NR
33123-data-disassemble -f basics.c -l 32 -n 3 -- 1
33124^done,asm_insns=[
33125src_and_asm_line=@{line="31",
ed8a1c2d
AB
33126file="../../../src/gdb/testsuite/gdb.mi/basics.c",
33127fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
33128line_asm_insn=[@{address="0x000107bc",
33129func-name="main",offset="0",inst="save %sp, -112, %sp"@}]@},
a2c02241 33130src_and_asm_line=@{line="32",
ed8a1c2d
AB
33131file="../../../src/gdb/testsuite/gdb.mi/basics.c",
33132fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
33133line_asm_insn=[@{address="0x000107c0",
33134func-name="main",offset="4",inst="mov 2, %o0"@},
a2c02241
NR
33135@{address="0x000107c4",func-name="main",offset="8",
33136inst="sethi %hi(0x11800), %o2"@}]@}]
594fe323 33137(gdb)
a2c02241
NR
33138@end smallexample
33139
33140
33141@subheading The @code{-data-evaluate-expression} Command
33142@findex -data-evaluate-expression
922fbb7b
AC
33143
33144@subsubheading Synopsis
33145
33146@smallexample
a2c02241 33147 -data-evaluate-expression @var{expr}
922fbb7b
AC
33148@end smallexample
33149
a2c02241
NR
33150Evaluate @var{expr} as an expression. The expression could contain an
33151inferior function call. The function call will execute synchronously.
33152If the expression contains spaces, it must be enclosed in double quotes.
922fbb7b
AC
33153
33154@subsubheading @value{GDBN} Command
33155
a2c02241
NR
33156The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
33157@samp{call}. In @code{gdbtk} only, there's a corresponding
33158@samp{gdb_eval} command.
922fbb7b
AC
33159
33160@subsubheading Example
33161
a2c02241
NR
33162In the following example, the numbers that precede the commands are the
33163@dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
33164Command Syntax}. Notice how @sc{gdb/mi} returns the same tokens in its
33165output.
33166
922fbb7b 33167@smallexample
a2c02241
NR
33168211-data-evaluate-expression A
33169211^done,value="1"
594fe323 33170(gdb)
a2c02241
NR
33171311-data-evaluate-expression &A
33172311^done,value="0xefffeb7c"
594fe323 33173(gdb)
a2c02241
NR
33174411-data-evaluate-expression A+3
33175411^done,value="4"
594fe323 33176(gdb)
a2c02241
NR
33177511-data-evaluate-expression "A + 3"
33178511^done,value="4"
594fe323 33179(gdb)
a2c02241 33180@end smallexample
922fbb7b
AC
33181
33182
a2c02241
NR
33183@subheading The @code{-data-list-changed-registers} Command
33184@findex -data-list-changed-registers
922fbb7b
AC
33185
33186@subsubheading Synopsis
33187
33188@smallexample
a2c02241 33189 -data-list-changed-registers
922fbb7b
AC
33190@end smallexample
33191
a2c02241 33192Display a list of the registers that have changed.
922fbb7b
AC
33193
33194@subsubheading @value{GDBN} Command
33195
a2c02241
NR
33196@value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
33197has the corresponding command @samp{gdb_changed_register_list}.
922fbb7b
AC
33198
33199@subsubheading Example
922fbb7b 33200
a2c02241 33201On a PPC MBX board:
922fbb7b
AC
33202
33203@smallexample
594fe323 33204(gdb)
a2c02241
NR
33205-exec-continue
33206^running
922fbb7b 33207
594fe323 33208(gdb)
a47ec5fe
AR
33209*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",frame=@{
33210func="main",args=[],file="try.c",fullname="/home/foo/bar/try.c",
6d52907e 33211line="5",arch="powerpc"@}
594fe323 33212(gdb)
a2c02241
NR
33213-data-list-changed-registers
33214^done,changed-registers=["0","1","2","4","5","6","7","8","9",
33215"10","11","13","14","15","16","17","18","19","20","21","22","23",
33216"24","25","26","27","28","30","31","64","65","66","67","69"]
594fe323 33217(gdb)
a2c02241 33218@end smallexample
922fbb7b
AC
33219
33220
a2c02241
NR
33221@subheading The @code{-data-list-register-names} Command
33222@findex -data-list-register-names
922fbb7b
AC
33223
33224@subsubheading Synopsis
33225
33226@smallexample
a2c02241 33227 -data-list-register-names [ ( @var{regno} )+ ]
922fbb7b
AC
33228@end smallexample
33229
a2c02241
NR
33230Show a list of register names for the current target. If no arguments
33231are given, it shows a list of the names of all the registers. If
33232integer numbers are given as arguments, it will print a list of the
33233names of the registers corresponding to the arguments. To ensure
33234consistency between a register name and its number, the output list may
33235include empty register names.
922fbb7b
AC
33236
33237@subsubheading @value{GDBN} Command
33238
a2c02241
NR
33239@value{GDBN} does not have a command which corresponds to
33240@samp{-data-list-register-names}. In @code{gdbtk} there is a
33241corresponding command @samp{gdb_regnames}.
922fbb7b
AC
33242
33243@subsubheading Example
922fbb7b 33244
a2c02241
NR
33245For the PPC MBX board:
33246@smallexample
594fe323 33247(gdb)
a2c02241
NR
33248-data-list-register-names
33249^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
33250"r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
33251"r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
33252"r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
33253"f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
33254"f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
33255"", "pc","ps","cr","lr","ctr","xer"]
594fe323 33256(gdb)
a2c02241
NR
33257-data-list-register-names 1 2 3
33258^done,register-names=["r1","r2","r3"]
594fe323 33259(gdb)
a2c02241 33260@end smallexample
922fbb7b 33261
a2c02241
NR
33262@subheading The @code{-data-list-register-values} Command
33263@findex -data-list-register-values
922fbb7b
AC
33264
33265@subsubheading Synopsis
33266
33267@smallexample
c898adb7
YQ
33268 -data-list-register-values
33269 [ @code{--skip-unavailable} ] @var{fmt} [ ( @var{regno} )*]
922fbb7b
AC
33270@end smallexample
33271
697aa1b7
EZ
33272Display the registers' contents. The format according to which the
33273registers' contents are to be returned is given by @var{fmt}, followed
33274by an optional list of numbers specifying the registers to display. A
33275missing list of numbers indicates that the contents of all the
33276registers must be returned. The @code{--skip-unavailable} option
33277indicates that only the available registers are to be returned.
a2c02241
NR
33278
33279Allowed formats for @var{fmt} are:
33280
33281@table @code
33282@item x
33283Hexadecimal
33284@item o
33285Octal
33286@item t
33287Binary
33288@item d
33289Decimal
33290@item r
33291Raw
33292@item N
33293Natural
33294@end table
922fbb7b
AC
33295
33296@subsubheading @value{GDBN} Command
33297
a2c02241
NR
33298The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
33299all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
922fbb7b
AC
33300
33301@subsubheading Example
922fbb7b 33302
a2c02241
NR
33303For a PPC MBX board (note: line breaks are for readability only, they
33304don't appear in the actual output):
33305
33306@smallexample
594fe323 33307(gdb)
a2c02241
NR
33308-data-list-register-values r 64 65
33309^done,register-values=[@{number="64",value="0xfe00a300"@},
33310@{number="65",value="0x00029002"@}]
594fe323 33311(gdb)
a2c02241
NR
33312-data-list-register-values x
33313^done,register-values=[@{number="0",value="0xfe0043c8"@},
33314@{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
33315@{number="3",value="0x0"@},@{number="4",value="0xa"@},
33316@{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
33317@{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
33318@{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
33319@{number="11",value="0x1"@},@{number="12",value="0x0"@},
33320@{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
33321@{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
33322@{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
33323@{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
33324@{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
33325@{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
33326@{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
33327@{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
33328@{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
33329@{number="31",value="0x0"@},@{number="32",value="0x0"@},
33330@{number="33",value="0x0"@},@{number="34",value="0x0"@},
33331@{number="35",value="0x0"@},@{number="36",value="0x0"@},
33332@{number="37",value="0x0"@},@{number="38",value="0x0"@},
33333@{number="39",value="0x0"@},@{number="40",value="0x0"@},
33334@{number="41",value="0x0"@},@{number="42",value="0x0"@},
33335@{number="43",value="0x0"@},@{number="44",value="0x0"@},
33336@{number="45",value="0x0"@},@{number="46",value="0x0"@},
33337@{number="47",value="0x0"@},@{number="48",value="0x0"@},
33338@{number="49",value="0x0"@},@{number="50",value="0x0"@},
33339@{number="51",value="0x0"@},@{number="52",value="0x0"@},
33340@{number="53",value="0x0"@},@{number="54",value="0x0"@},
33341@{number="55",value="0x0"@},@{number="56",value="0x0"@},
33342@{number="57",value="0x0"@},@{number="58",value="0x0"@},
33343@{number="59",value="0x0"@},@{number="60",value="0x0"@},
33344@{number="61",value="0x0"@},@{number="62",value="0x0"@},
33345@{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
33346@{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
33347@{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
33348@{number="69",value="0x20002b03"@}]
594fe323 33349(gdb)
a2c02241 33350@end smallexample
922fbb7b 33351
a2c02241
NR
33352
33353@subheading The @code{-data-read-memory} Command
33354@findex -data-read-memory
922fbb7b 33355
8dedea02
VP
33356This command is deprecated, use @code{-data-read-memory-bytes} instead.
33357
922fbb7b
AC
33358@subsubheading Synopsis
33359
33360@smallexample
a2c02241
NR
33361 -data-read-memory [ -o @var{byte-offset} ]
33362 @var{address} @var{word-format} @var{word-size}
33363 @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
922fbb7b
AC
33364@end smallexample
33365
a2c02241
NR
33366@noindent
33367where:
922fbb7b 33368
a2c02241
NR
33369@table @samp
33370@item @var{address}
33371An expression specifying the address of the first memory word to be
33372read. Complex expressions containing embedded white space should be
33373quoted using the C convention.
922fbb7b 33374
a2c02241
NR
33375@item @var{word-format}
33376The format to be used to print the memory words. The notation is the
33377same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
79a6e687 33378,Output Formats}).
922fbb7b 33379
a2c02241
NR
33380@item @var{word-size}
33381The size of each memory word in bytes.
922fbb7b 33382
a2c02241
NR
33383@item @var{nr-rows}
33384The number of rows in the output table.
922fbb7b 33385
a2c02241
NR
33386@item @var{nr-cols}
33387The number of columns in the output table.
922fbb7b 33388
a2c02241
NR
33389@item @var{aschar}
33390If present, indicates that each row should include an @sc{ascii} dump. The
33391value of @var{aschar} is used as a padding character when a byte is not a
33392member of the printable @sc{ascii} character set (printable @sc{ascii}
33393characters are those whose code is between 32 and 126, inclusively).
922fbb7b 33394
a2c02241
NR
33395@item @var{byte-offset}
33396An offset to add to the @var{address} before fetching memory.
33397@end table
922fbb7b 33398
a2c02241
NR
33399This command displays memory contents as a table of @var{nr-rows} by
33400@var{nr-cols} words, each word being @var{word-size} bytes. In total,
33401@code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
33402(returned as @samp{total-bytes}). Should less than the requested number
33403of bytes be returned by the target, the missing words are identified
33404using @samp{N/A}. The number of bytes read from the target is returned
33405in @samp{nr-bytes} and the starting address used to read memory in
33406@samp{addr}.
33407
33408The address of the next/previous row or page is available in
33409@samp{next-row} and @samp{prev-row}, @samp{next-page} and
33410@samp{prev-page}.
922fbb7b
AC
33411
33412@subsubheading @value{GDBN} Command
33413
a2c02241
NR
33414The corresponding @value{GDBN} command is @samp{x}. @code{gdbtk} has
33415@samp{gdb_get_mem} memory read command.
922fbb7b
AC
33416
33417@subsubheading Example
32e7087d 33418
a2c02241
NR
33419Read six bytes of memory starting at @code{bytes+6} but then offset by
33420@code{-6} bytes. Format as three rows of two columns. One byte per
33421word. Display each word in hex.
32e7087d
JB
33422
33423@smallexample
594fe323 33424(gdb)
a2c02241
NR
334259-data-read-memory -o -6 -- bytes+6 x 1 3 2
334269^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
33427next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
33428prev-page="0x0000138a",memory=[
33429@{addr="0x00001390",data=["0x00","0x01"]@},
33430@{addr="0x00001392",data=["0x02","0x03"]@},
33431@{addr="0x00001394",data=["0x04","0x05"]@}]
594fe323 33432(gdb)
32e7087d
JB
33433@end smallexample
33434
a2c02241
NR
33435Read two bytes of memory starting at address @code{shorts + 64} and
33436display as a single word formatted in decimal.
32e7087d 33437
32e7087d 33438@smallexample
594fe323 33439(gdb)
a2c02241
NR
334405-data-read-memory shorts+64 d 2 1 1
334415^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
33442next-row="0x00001512",prev-row="0x0000150e",
33443next-page="0x00001512",prev-page="0x0000150e",memory=[
33444@{addr="0x00001510",data=["128"]@}]
594fe323 33445(gdb)
32e7087d
JB
33446@end smallexample
33447
a2c02241
NR
33448Read thirty two bytes of memory starting at @code{bytes+16} and format
33449as eight rows of four columns. Include a string encoding with @samp{x}
33450used as the non-printable character.
922fbb7b
AC
33451
33452@smallexample
594fe323 33453(gdb)
a2c02241
NR
334544-data-read-memory bytes+16 x 1 8 4 x
334554^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
33456next-row="0x000013c0",prev-row="0x0000139c",
33457next-page="0x000013c0",prev-page="0x00001380",memory=[
33458@{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
33459@{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
33460@{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
33461@{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
33462@{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
33463@{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
33464@{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
33465@{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
594fe323 33466(gdb)
922fbb7b
AC
33467@end smallexample
33468
8dedea02
VP
33469@subheading The @code{-data-read-memory-bytes} Command
33470@findex -data-read-memory-bytes
33471
33472@subsubheading Synopsis
33473
33474@smallexample
a86c90e6 33475 -data-read-memory-bytes [ -o @var{offset} ]
8dedea02
VP
33476 @var{address} @var{count}
33477@end smallexample
33478
33479@noindent
33480where:
33481
33482@table @samp
33483@item @var{address}
a86c90e6
SM
33484An expression specifying the address of the first addressable memory unit
33485to be read. Complex expressions containing embedded white space should be
8dedea02
VP
33486quoted using the C convention.
33487
33488@item @var{count}
a86c90e6
SM
33489The number of addressable memory units to read. This should be an integer
33490literal.
8dedea02 33491
a86c90e6
SM
33492@item @var{offset}
33493The offset relative to @var{address} at which to start reading. This
33494should be an integer literal. This option is provided so that a frontend
33495is not required to first evaluate address and then perform address
33496arithmetics itself.
8dedea02
VP
33497
33498@end table
33499
33500This command attempts to read all accessible memory regions in the
33501specified range. First, all regions marked as unreadable in the memory
33502map (if one is defined) will be skipped. @xref{Memory Region
33503Attributes}. Second, @value{GDBN} will attempt to read the remaining
33504regions. For each one, if reading full region results in an errors,
33505@value{GDBN} will try to read a subset of the region.
33506
a86c90e6
SM
33507In general, every single memory unit in the region may be readable or not,
33508and the only way to read every readable unit is to try a read at
8dedea02 33509every address, which is not practical. Therefore, @value{GDBN} will
a86c90e6 33510attempt to read all accessible memory units at either beginning or the end
8dedea02 33511of the region, using a binary division scheme. This heuristic works
6b92c0d3 33512well for reading across a memory map boundary. Note that if a region
8dedea02
VP
33513has a readable range that is neither at the beginning or the end,
33514@value{GDBN} will not read it.
33515
33516The result record (@pxref{GDB/MI Result Records}) that is output of
33517the command includes a field named @samp{memory} whose content is a
33518list of tuples. Each tuple represent a successfully read memory block
33519and has the following fields:
33520
33521@table @code
33522@item begin
33523The start address of the memory block, as hexadecimal literal.
33524
33525@item end
33526The end address of the memory block, as hexadecimal literal.
33527
33528@item offset
33529The offset of the memory block, as hexadecimal literal, relative to
33530the start address passed to @code{-data-read-memory-bytes}.
33531
33532@item contents
33533The contents of the memory block, in hex.
33534
33535@end table
33536
33537
33538
33539@subsubheading @value{GDBN} Command
33540
33541The corresponding @value{GDBN} command is @samp{x}.
33542
33543@subsubheading Example
33544
33545@smallexample
33546(gdb)
33547-data-read-memory-bytes &a 10
33548^done,memory=[@{begin="0xbffff154",offset="0x00000000",
33549 end="0xbffff15e",
33550 contents="01000000020000000300"@}]
33551(gdb)
33552@end smallexample
33553
33554
33555@subheading The @code{-data-write-memory-bytes} Command
33556@findex -data-write-memory-bytes
33557
33558@subsubheading Synopsis
33559
33560@smallexample
33561 -data-write-memory-bytes @var{address} @var{contents}
62747a60 33562 -data-write-memory-bytes @var{address} @var{contents} @r{[}@var{count}@r{]}
8dedea02
VP
33563@end smallexample
33564
33565@noindent
33566where:
33567
33568@table @samp
33569@item @var{address}
a86c90e6
SM
33570An expression specifying the address of the first addressable memory unit
33571to be written. Complex expressions containing embedded white space should
33572be quoted using the C convention.
8dedea02
VP
33573
33574@item @var{contents}
a86c90e6
SM
33575The hex-encoded data to write. It is an error if @var{contents} does
33576not represent an integral number of addressable memory units.
8dedea02 33577
62747a60 33578@item @var{count}
a86c90e6
SM
33579Optional argument indicating the number of addressable memory units to be
33580written. If @var{count} is greater than @var{contents}' length,
33581@value{GDBN} will repeatedly write @var{contents} until it fills
33582@var{count} memory units.
62747a60 33583
8dedea02
VP
33584@end table
33585
33586@subsubheading @value{GDBN} Command
33587
33588There's no corresponding @value{GDBN} command.
33589
33590@subsubheading Example
33591
33592@smallexample
33593(gdb)
33594-data-write-memory-bytes &a "aabbccdd"
33595^done
33596(gdb)
33597@end smallexample
33598
62747a60
TT
33599@smallexample
33600(gdb)
33601-data-write-memory-bytes &a "aabbccdd" 16e
33602^done
33603(gdb)
33604@end smallexample
8dedea02 33605
a2c02241
NR
33606@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33607@node GDB/MI Tracepoint Commands
33608@section @sc{gdb/mi} Tracepoint Commands
922fbb7b 33609
18148017
VP
33610The commands defined in this section implement MI support for
33611tracepoints. For detailed introduction, see @ref{Tracepoints}.
33612
33613@subheading The @code{-trace-find} Command
33614@findex -trace-find
33615
33616@subsubheading Synopsis
33617
33618@smallexample
33619 -trace-find @var{mode} [@var{parameters}@dots{}]
33620@end smallexample
33621
33622Find a trace frame using criteria defined by @var{mode} and
33623@var{parameters}. The following table lists permissible
33624modes and their parameters. For details of operation, see @ref{tfind}.
33625
33626@table @samp
33627
33628@item none
33629No parameters are required. Stops examining trace frames.
33630
33631@item frame-number
33632An integer is required as parameter. Selects tracepoint frame with
33633that index.
33634
33635@item tracepoint-number
33636An integer is required as parameter. Finds next
33637trace frame that corresponds to tracepoint with the specified number.
33638
33639@item pc
33640An address is required as parameter. Finds
33641next trace frame that corresponds to any tracepoint at the specified
33642address.
33643
33644@item pc-inside-range
33645Two addresses are required as parameters. Finds next trace
33646frame that corresponds to a tracepoint at an address inside the
33647specified range. Both bounds are considered to be inside the range.
33648
33649@item pc-outside-range
33650Two addresses are required as parameters. Finds
33651next trace frame that corresponds to a tracepoint at an address outside
33652the specified range. Both bounds are considered to be inside the range.
33653
33654@item line
33655Line specification is required as parameter. @xref{Specify Location}.
33656Finds next trace frame that corresponds to a tracepoint at
33657the specified location.
33658
33659@end table
33660
33661If @samp{none} was passed as @var{mode}, the response does not
33662have fields. Otherwise, the response may have the following fields:
33663
33664@table @samp
33665@item found
33666This field has either @samp{0} or @samp{1} as the value, depending
33667on whether a matching tracepoint was found.
33668
33669@item traceframe
33670The index of the found traceframe. This field is present iff
33671the @samp{found} field has value of @samp{1}.
33672
33673@item tracepoint
33674The index of the found tracepoint. This field is present iff
33675the @samp{found} field has value of @samp{1}.
33676
33677@item frame
33678The information about the frame corresponding to the found trace
33679frame. This field is present only if a trace frame was found.
cd64ee31 33680@xref{GDB/MI Frame Information}, for description of this field.
18148017
VP
33681
33682@end table
33683
7d13fe92
SS
33684@subsubheading @value{GDBN} Command
33685
33686The corresponding @value{GDBN} command is @samp{tfind}.
33687
18148017
VP
33688@subheading -trace-define-variable
33689@findex -trace-define-variable
33690
33691@subsubheading Synopsis
33692
33693@smallexample
33694 -trace-define-variable @var{name} [ @var{value} ]
33695@end smallexample
33696
33697Create trace variable @var{name} if it does not exist. If
33698@var{value} is specified, sets the initial value of the specified
33699trace variable to that value. Note that the @var{name} should start
33700with the @samp{$} character.
33701
7d13fe92
SS
33702@subsubheading @value{GDBN} Command
33703
33704The corresponding @value{GDBN} command is @samp{tvariable}.
33705
dc673c81
YQ
33706@subheading The @code{-trace-frame-collected} Command
33707@findex -trace-frame-collected
33708
33709@subsubheading Synopsis
33710
33711@smallexample
33712 -trace-frame-collected
33713 [--var-print-values @var{var_pval}]
33714 [--comp-print-values @var{comp_pval}]
33715 [--registers-format @var{regformat}]
33716 [--memory-contents]
33717@end smallexample
33718
33719This command returns the set of collected objects, register names,
33720trace state variable names, memory ranges and computed expressions
33721that have been collected at a particular trace frame. The optional
33722parameters to the command affect the output format in different ways.
33723See the output description table below for more details.
33724
33725The reported names can be used in the normal manner to create
33726varobjs and inspect the objects themselves. The items returned by
33727this command are categorized so that it is clear which is a variable,
33728which is a register, which is a trace state variable, which is a
33729memory range and which is a computed expression.
33730
33731For instance, if the actions were
33732@smallexample
33733collect myVar, myArray[myIndex], myObj.field, myPtr->field, myCount + 2
33734collect *(int*)0xaf02bef0@@40
33735@end smallexample
33736
33737@noindent
33738the object collected in its entirety would be @code{myVar}. The
33739object @code{myArray} would be partially collected, because only the
33740element at index @code{myIndex} would be collected. The remaining
33741objects would be computed expressions.
33742
33743An example output would be:
33744
33745@smallexample
33746(gdb)
33747-trace-frame-collected
33748^done,
33749 explicit-variables=[@{name="myVar",value="1"@}],
33750 computed-expressions=[@{name="myArray[myIndex]",value="0"@},
33751 @{name="myObj.field",value="0"@},
33752 @{name="myPtr->field",value="1"@},
33753 @{name="myCount + 2",value="3"@},
33754 @{name="$tvar1 + 1",value="43970027"@}],
33755 registers=[@{number="0",value="0x7fe2c6e79ec8"@},
33756 @{number="1",value="0x0"@},
33757 @{number="2",value="0x4"@},
33758 ...
33759 @{number="125",value="0x0"@}],
33760 tvars=[@{name="$tvar1",current="43970026"@}],
33761 memory=[@{address="0x0000000000602264",length="4"@},
33762 @{address="0x0000000000615bc0",length="4"@}]
33763(gdb)
33764@end smallexample
33765
33766Where:
33767
33768@table @code
33769@item explicit-variables
33770The set of objects that have been collected in their entirety (as
33771opposed to collecting just a few elements of an array or a few struct
33772members). For each object, its name and value are printed.
33773The @code{--var-print-values} option affects how or whether the value
33774field is output. If @var{var_pval} is 0, then print only the names;
33775if it is 1, print also their values; and if it is 2, print the name,
33776type and value for simple data types, and the name and type for
33777arrays, structures and unions.
33778
33779@item computed-expressions
33780The set of computed expressions that have been collected at the
33781current trace frame. The @code{--comp-print-values} option affects
33782this set like the @code{--var-print-values} option affects the
33783@code{explicit-variables} set. See above.
33784
33785@item registers
33786The registers that have been collected at the current trace frame.
33787For each register collected, the name and current value are returned.
33788The value is formatted according to the @code{--registers-format}
33789option. See the @command{-data-list-register-values} command for a
33790list of the allowed formats. The default is @samp{x}.
33791
33792@item tvars
33793The trace state variables that have been collected at the current
33794trace frame. For each trace state variable collected, the name and
33795current value are returned.
33796
33797@item memory
33798The set of memory ranges that have been collected at the current trace
33799frame. Its content is a list of tuples. Each tuple represents a
33800collected memory range and has the following fields:
33801
33802@table @code
33803@item address
33804The start address of the memory range, as hexadecimal literal.
33805
33806@item length
33807The length of the memory range, as decimal literal.
33808
33809@item contents
33810The contents of the memory block, in hex. This field is only present
33811if the @code{--memory-contents} option is specified.
33812
33813@end table
33814
33815@end table
33816
33817@subsubheading @value{GDBN} Command
33818
33819There is no corresponding @value{GDBN} command.
33820
33821@subsubheading Example
33822
18148017
VP
33823@subheading -trace-list-variables
33824@findex -trace-list-variables
922fbb7b 33825
18148017 33826@subsubheading Synopsis
922fbb7b 33827
18148017
VP
33828@smallexample
33829 -trace-list-variables
33830@end smallexample
922fbb7b 33831
18148017
VP
33832Return a table of all defined trace variables. Each element of the
33833table has the following fields:
922fbb7b 33834
18148017
VP
33835@table @samp
33836@item name
33837The name of the trace variable. This field is always present.
922fbb7b 33838
18148017
VP
33839@item initial
33840The initial value. This is a 64-bit signed integer. This
33841field is always present.
922fbb7b 33842
18148017
VP
33843@item current
33844The value the trace variable has at the moment. This is a 64-bit
33845signed integer. This field is absent iff current value is
33846not defined, for example if the trace was never run, or is
33847presently running.
922fbb7b 33848
18148017 33849@end table
922fbb7b 33850
7d13fe92
SS
33851@subsubheading @value{GDBN} Command
33852
33853The corresponding @value{GDBN} command is @samp{tvariables}.
33854
18148017 33855@subsubheading Example
922fbb7b 33856
18148017
VP
33857@smallexample
33858(gdb)
33859-trace-list-variables
33860^done,trace-variables=@{nr_rows="1",nr_cols="3",
33861hdr=[@{width="15",alignment="-1",col_name="name",colhdr="Name"@},
33862 @{width="11",alignment="-1",col_name="initial",colhdr="Initial"@},
33863 @{width="11",alignment="-1",col_name="current",colhdr="Current"@}],
33864body=[variable=@{name="$trace_timestamp",initial="0"@}
33865 variable=@{name="$foo",initial="10",current="15"@}]@}
33866(gdb)
33867@end smallexample
922fbb7b 33868
18148017
VP
33869@subheading -trace-save
33870@findex -trace-save
922fbb7b 33871
18148017
VP
33872@subsubheading Synopsis
33873
33874@smallexample
99e61eda 33875 -trace-save [ -r ] [ -ctf ] @var{filename}
18148017
VP
33876@end smallexample
33877
33878Saves the collected trace data to @var{filename}. Without the
33879@samp{-r} option, the data is downloaded from the target and saved
33880in a local file. With the @samp{-r} option the target is asked
33881to perform the save.
33882
99e61eda
SM
33883By default, this command will save the trace in the tfile format. You can
33884supply the optional @samp{-ctf} argument to save it the CTF format. See
33885@ref{Trace Files} for more information about CTF.
33886
7d13fe92
SS
33887@subsubheading @value{GDBN} Command
33888
33889The corresponding @value{GDBN} command is @samp{tsave}.
33890
18148017
VP
33891
33892@subheading -trace-start
33893@findex -trace-start
33894
33895@subsubheading Synopsis
33896
33897@smallexample
33898 -trace-start
33899@end smallexample
922fbb7b 33900
be06ba8c 33901Starts a tracing experiment. The result of this command does not
18148017 33902have any fields.
922fbb7b 33903
7d13fe92
SS
33904@subsubheading @value{GDBN} Command
33905
33906The corresponding @value{GDBN} command is @samp{tstart}.
33907
18148017
VP
33908@subheading -trace-status
33909@findex -trace-status
922fbb7b 33910
18148017
VP
33911@subsubheading Synopsis
33912
33913@smallexample
33914 -trace-status
33915@end smallexample
33916
a97153c7 33917Obtains the status of a tracing experiment. The result may include
18148017
VP
33918the following fields:
33919
33920@table @samp
33921
33922@item supported
33923May have a value of either @samp{0}, when no tracing operations are
33924supported, @samp{1}, when all tracing operations are supported, or
33925@samp{file} when examining trace file. In the latter case, examining
33926of trace frame is possible but new tracing experiement cannot be
33927started. This field is always present.
33928
33929@item running
33930May have a value of either @samp{0} or @samp{1} depending on whether
33931tracing experiement is in progress on target. This field is present
33932if @samp{supported} field is not @samp{0}.
33933
33934@item stop-reason
33935Report the reason why the tracing was stopped last time. This field
33936may be absent iff tracing was never stopped on target yet. The
33937value of @samp{request} means the tracing was stopped as result of
33938the @code{-trace-stop} command. The value of @samp{overflow} means
33939the tracing buffer is full. The value of @samp{disconnection} means
33940tracing was automatically stopped when @value{GDBN} has disconnected.
33941The value of @samp{passcount} means tracing was stopped when a
33942tracepoint was passed a maximal number of times for that tracepoint.
33943This field is present if @samp{supported} field is not @samp{0}.
33944
33945@item stopping-tracepoint
33946The number of tracepoint whose passcount as exceeded. This field is
33947present iff the @samp{stop-reason} field has the value of
33948@samp{passcount}.
33949
33950@item frames
87290684
SS
33951@itemx frames-created
33952The @samp{frames} field is a count of the total number of trace frames
33953in the trace buffer, while @samp{frames-created} is the total created
33954during the run, including ones that were discarded, such as when a
33955circular trace buffer filled up. Both fields are optional.
18148017
VP
33956
33957@item buffer-size
33958@itemx buffer-free
33959These fields tell the current size of the tracing buffer and the
87290684 33960remaining space. These fields are optional.
18148017 33961
a97153c7
PA
33962@item circular
33963The value of the circular trace buffer flag. @code{1} means that the
33964trace buffer is circular and old trace frames will be discarded if
33965necessary to make room, @code{0} means that the trace buffer is linear
33966and may fill up.
33967
33968@item disconnected
33969The value of the disconnected tracing flag. @code{1} means that
33970tracing will continue after @value{GDBN} disconnects, @code{0} means
33971that the trace run will stop.
33972
f5911ea1
HAQ
33973@item trace-file
33974The filename of the trace file being examined. This field is
33975optional, and only present when examining a trace file.
33976
18148017
VP
33977@end table
33978
7d13fe92
SS
33979@subsubheading @value{GDBN} Command
33980
33981The corresponding @value{GDBN} command is @samp{tstatus}.
33982
18148017
VP
33983@subheading -trace-stop
33984@findex -trace-stop
33985
33986@subsubheading Synopsis
33987
33988@smallexample
33989 -trace-stop
33990@end smallexample
922fbb7b 33991
18148017
VP
33992Stops a tracing experiment. The result of this command has the same
33993fields as @code{-trace-status}, except that the @samp{supported} and
33994@samp{running} fields are not output.
922fbb7b 33995
7d13fe92
SS
33996@subsubheading @value{GDBN} Command
33997
33998The corresponding @value{GDBN} command is @samp{tstop}.
33999
922fbb7b 34000
a2c02241
NR
34001@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34002@node GDB/MI Symbol Query
34003@section @sc{gdb/mi} Symbol Query Commands
922fbb7b
AC
34004
34005
9901a55b 34006@ignore
a2c02241
NR
34007@subheading The @code{-symbol-info-address} Command
34008@findex -symbol-info-address
922fbb7b
AC
34009
34010@subsubheading Synopsis
34011
34012@smallexample
a2c02241 34013 -symbol-info-address @var{symbol}
922fbb7b
AC
34014@end smallexample
34015
a2c02241 34016Describe where @var{symbol} is stored.
922fbb7b
AC
34017
34018@subsubheading @value{GDBN} Command
34019
a2c02241 34020The corresponding @value{GDBN} command is @samp{info address}.
922fbb7b
AC
34021
34022@subsubheading Example
34023N.A.
34024
34025
a2c02241
NR
34026@subheading The @code{-symbol-info-file} Command
34027@findex -symbol-info-file
922fbb7b
AC
34028
34029@subsubheading Synopsis
34030
34031@smallexample
a2c02241 34032 -symbol-info-file
922fbb7b
AC
34033@end smallexample
34034
a2c02241 34035Show the file for the symbol.
922fbb7b 34036
a2c02241 34037@subsubheading @value{GDBN} Command
922fbb7b 34038
a2c02241
NR
34039There's no equivalent @value{GDBN} command. @code{gdbtk} has
34040@samp{gdb_find_file}.
922fbb7b
AC
34041
34042@subsubheading Example
34043N.A.
7dc42066
AB
34044@end ignore
34045
34046@subheading The @code{-symbol-info-functions} Command
34047@findex -symbol-info-functions
34048@anchor{-symbol-info-functions}
34049
34050@subsubheading Synopsis
34051
34052@smallexample
34053 -symbol-info-functions [--include-nondebug]
34054 [--type @var{type_regexp}]
34055 [--name @var{name_regexp}]
c2512106 34056 [--max-results @var{limit}]
7dc42066
AB
34057@end smallexample
34058
34059@noindent
34060Return a list containing the names and types for all global functions
34061taken from the debug information. The functions are grouped by source
34062file, and shown with the line number on which each function is
34063defined.
922fbb7b 34064
7dc42066
AB
34065The @code{--include-nondebug} option causes the output to include
34066code symbols from the symbol table.
922fbb7b 34067
7dc42066
AB
34068The options @code{--type} and @code{--name} allow the symbols returned
34069to be filtered based on either the name of the function, or the type
34070signature of the function.
34071
c2512106
AB
34072The option @code{--max-results} restricts the command to return no
34073more than @var{limit} results. If exactly @var{limit} results are
34074returned then there might be additional results available if a higher
34075limit is used.
34076
7dc42066
AB
34077@subsubheading @value{GDBN} Command
34078
34079The corresponding @value{GDBN} command is @samp{info functions}.
34080
34081@subsubheading Example
34082@smallexample
34083@group
34084(gdb)
34085-symbol-info-functions
34086^done,symbols=
34087 @{debug=
34088 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34089 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34090 symbols=[@{line="36", name="f4", type="void (int *)",
34091 description="void f4(int *);"@},
34092 @{line="42", name="main", type="int ()",
34093 description="int main();"@},
34094 @{line="30", name="f1", type="my_int_t (int, int)",
34095 description="static my_int_t f1(int, int);"@}]@},
34096 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34097 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34098 symbols=[@{line="33", name="f2", type="float (another_float_t)",
34099 description="float f2(another_float_t);"@},
34100 @{line="39", name="f3", type="int (another_int_t)",
34101 description="int f3(another_int_t);"@},
34102 @{line="27", name="f1", type="another_float_t (int)",
34103 description="static another_float_t f1(int);"@}]@}]@}
34104@end group
34105@group
34106(gdb)
34107-symbol-info-functions --name f1
34108^done,symbols=
34109 @{debug=
34110 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34111 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34112 symbols=[@{line="30", name="f1", type="my_int_t (int, int)",
34113 description="static my_int_t f1(int, int);"@}]@},
34114 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34115 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34116 symbols=[@{line="27", name="f1", type="another_float_t (int)",
34117 description="static another_float_t f1(int);"@}]@}]@}
34118@end group
34119@group
34120(gdb)
34121-symbol-info-functions --type void
34122^done,symbols=
34123 @{debug=
34124 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34125 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34126 symbols=[@{line="36", name="f4", type="void (int *)",
34127 description="void f4(int *);"@}]@}]@}
34128@end group
34129@group
34130(gdb)
34131-symbol-info-functions --include-nondebug
34132^done,symbols=
34133 @{debug=
34134 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34135 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34136 symbols=[@{line="36", name="f4", type="void (int *)",
34137 description="void f4(int *);"@},
34138 @{line="42", name="main", type="int ()",
34139 description="int main();"@},
34140 @{line="30", name="f1", type="my_int_t (int, int)",
34141 description="static my_int_t f1(int, int);"@}]@},
34142 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34143 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34144 symbols=[@{line="33", name="f2", type="float (another_float_t)",
34145 description="float f2(another_float_t);"@},
34146 @{line="39", name="f3", type="int (another_int_t)",
34147 description="int f3(another_int_t);"@},
34148 @{line="27", name="f1", type="another_float_t (int)",
34149 description="static another_float_t f1(int);"@}]@}],
34150 nondebug=
34151 [@{address="0x0000000000400398",name="_init"@},
34152 @{address="0x00000000004003b0",name="_start"@},
34153 ...
34154 ]@}
34155@end group
34156@end smallexample
34157
293b38d6
AB
34158@subheading The @code{-symbol-info-module-functions} Command
34159@findex -symbol-info-module-functions
34160@anchor{-symbol-info-module-functions}
34161
34162@subsubheading Synopsis
34163
34164@smallexample
34165 -symbol-info-module-functions [--module @var{module_regexp}]
34166 [--name @var{name_regexp}]
34167 [--type @var{type_regexp}]
34168@end smallexample
34169
34170@noindent
34171Return a list containing the names of all known functions within all
34172know Fortran modules. The functions are grouped by source file and
34173containing module, and shown with the line number on which each
34174function is defined.
34175
34176The option @code{--module} only returns results for modules matching
34177@var{module_regexp}. The option @code{--name} only returns functions
34178whose name matches @var{name_regexp}, and @code{--type} only returns
34179functions whose type matches @var{type_regexp}.
34180
34181@subsubheading @value{GDBN} Command
34182
34183The corresponding @value{GDBN} command is @samp{info module functions}.
34184
34185@subsubheading Example
34186
34187@smallexample
34188@group
34189(gdb)
34190-symbol-info-module-functions
34191^done,symbols=
34192 [@{module="mod1",
34193 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34194 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34195 symbols=[@{line="21",name="mod1::check_all",type="void (void)",
34196 description="void mod1::check_all(void);"@}]@}]@},
34197 @{module="mod2",
34198 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34199 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34200 symbols=[@{line="30",name="mod2::check_var_i",type="void (void)",
34201 description="void mod2::check_var_i(void);"@}]@}]@},
34202 @{module="mod3",
34203 files=[@{filename="/projec/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34204 fullname="/projec/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34205 symbols=[@{line="21",name="mod3::check_all",type="void (void)",
34206 description="void mod3::check_all(void);"@},
34207 @{line="27",name="mod3::check_mod2",type="void (void)",
34208 description="void mod3::check_mod2(void);"@}]@}]@},
34209 @{module="modmany",
34210 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34211 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34212 symbols=[@{line="35",name="modmany::check_some",type="void (void)",
34213 description="void modmany::check_some(void);"@}]@}]@},
34214 @{module="moduse",
34215 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34216 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34217 symbols=[@{line="44",name="moduse::check_all",type="void (void)",
34218 description="void moduse::check_all(void);"@},
34219 @{line="49",name="moduse::check_var_x",type="void (void)",
34220 description="void moduse::check_var_x(void);"@}]@}]@}]
34221@end group
34222@end smallexample
34223
34224@subheading The @code{-symbol-info-module-variables} Command
34225@findex -symbol-info-module-variables
34226@anchor{-symbol-info-module-variables}
34227
34228@subsubheading Synopsis
34229
34230@smallexample
34231 -symbol-info-module-variables [--module @var{module_regexp}]
34232 [--name @var{name_regexp}]
34233 [--type @var{type_regexp}]
34234@end smallexample
34235
34236@noindent
34237Return a list containing the names of all known variables within all
34238know Fortran modules. The variables are grouped by source file and
34239containing module, and shown with the line number on which each
34240variable is defined.
34241
34242The option @code{--module} only returns results for modules matching
34243@var{module_regexp}. The option @code{--name} only returns variables
34244whose name matches @var{name_regexp}, and @code{--type} only returns
34245variables whose type matches @var{type_regexp}.
34246
34247@subsubheading @value{GDBN} Command
34248
34249The corresponding @value{GDBN} command is @samp{info module variables}.
34250
34251@subsubheading Example
34252
34253@smallexample
34254@group
34255(gdb)
34256-symbol-info-module-variables
34257^done,symbols=
34258 [@{module="mod1",
34259 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34260 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34261 symbols=[@{line="18",name="mod1::var_const",type="integer(kind=4)",
34262 description="integer(kind=4) mod1::var_const;"@},
34263 @{line="17",name="mod1::var_i",type="integer(kind=4)",
34264 description="integer(kind=4) mod1::var_i;"@}]@}]@},
34265 @{module="mod2",
34266 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34267 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34268 symbols=[@{line="28",name="mod2::var_i",type="integer(kind=4)",
34269 description="integer(kind=4) mod2::var_i;"@}]@}]@},
34270 @{module="mod3",
34271 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34272 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34273 symbols=[@{line="18",name="mod3::mod1",type="integer(kind=4)",
34274 description="integer(kind=4) mod3::mod1;"@},
34275 @{line="17",name="mod3::mod2",type="integer(kind=4)",
34276 description="integer(kind=4) mod3::mod2;"@},
34277 @{line="19",name="mod3::var_i",type="integer(kind=4)",
34278 description="integer(kind=4) mod3::var_i;"@}]@}]@},
34279 @{module="modmany",
34280 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34281 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34282 symbols=[@{line="33",name="modmany::var_a",type="integer(kind=4)",
34283 description="integer(kind=4) modmany::var_a;"@},
34284 @{line="33",name="modmany::var_b",type="integer(kind=4)",
34285 description="integer(kind=4) modmany::var_b;"@},
34286 @{line="33",name="modmany::var_c",type="integer(kind=4)",
34287 description="integer(kind=4) modmany::var_c;"@},
34288 @{line="33",name="modmany::var_i",type="integer(kind=4)",
34289 description="integer(kind=4) modmany::var_i;"@}]@}]@},
34290 @{module="moduse",
34291 files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34292 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34293 symbols=[@{line="42",name="moduse::var_x",type="integer(kind=4)",
34294 description="integer(kind=4) moduse::var_x;"@},
34295 @{line="42",name="moduse::var_y",type="integer(kind=4)",
34296 description="integer(kind=4) moduse::var_y;"@}]@}]@}]
34297@end group
34298@end smallexample
34299
db5960b4
AB
34300@subheading The @code{-symbol-info-modules} Command
34301@findex -symbol-info-modules
34302@anchor{-symbol-info-modules}
34303
34304@subsubheading Synopsis
34305
34306@smallexample
34307 -symbol-info-modules [--name @var{name_regexp}]
c2512106
AB
34308 [--max-results @var{limit}]
34309
db5960b4
AB
34310@end smallexample
34311
34312@noindent
34313Return a list containing the names of all known Fortran modules. The
34314modules are grouped by source file, and shown with the line number on
34315which each modules is defined.
34316
34317The option @code{--name} allows the modules returned to be filtered
34318based the name of the module.
34319
c2512106
AB
34320The option @code{--max-results} restricts the command to return no
34321more than @var{limit} results. If exactly @var{limit} results are
34322returned then there might be additional results available if a higher
34323limit is used.
34324
db5960b4
AB
34325@subsubheading @value{GDBN} Command
34326
34327The corresponding @value{GDBN} command is @samp{info modules}.
34328
34329@subsubheading Example
34330@smallexample
34331@group
34332(gdb)
34333-symbol-info-modules
34334^done,symbols=
34335 @{debug=
34336 [@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34337 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34338 symbols=[@{line="16",name="mod1"@},
34339 @{line="22",name="mod2"@}]@},
34340 @{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34341 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34342 symbols=[@{line="16",name="mod3"@},
34343 @{line="22",name="modmany"@},
34344 @{line="26",name="moduse"@}]@}]@}
34345@end group
34346@group
34347(gdb)
34348-symbol-info-modules --name mod[123]
34349^done,symbols=
34350 @{debug=
34351 [@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34352 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34353 symbols=[@{line="16",name="mod1"@},
34354 @{line="22",name="mod2"@}]@},
34355 @{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34356 fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34357 symbols=[@{line="16",name="mod3"@}]@}]@}
34358@end group
34359@end smallexample
34360
7dc42066
AB
34361@subheading The @code{-symbol-info-types} Command
34362@findex -symbol-info-types
34363@anchor{-symbol-info-types}
922fbb7b
AC
34364
34365@subsubheading Synopsis
34366
34367@smallexample
7dc42066 34368 -symbol-info-types [--name @var{name_regexp}]
c2512106
AB
34369 [--max-results @var{limit}]
34370
922fbb7b
AC
34371@end smallexample
34372
7dc42066
AB
34373@noindent
34374Return a list of all defined types. The types are grouped by source
34375file, and shown with the line number on which each user defined type
34376is defined. Some base types are not defined in the source code but
34377are added to the debug information by the compiler, for example
34378@code{int}, @code{float}, etc.; these types do not have an associated
34379line number.
34380
34381The option @code{--name} allows the list of types returned to be
34382filtered by name.
922fbb7b 34383
c2512106
AB
34384The option @code{--max-results} restricts the command to return no
34385more than @var{limit} results. If exactly @var{limit} results are
34386returned then there might be additional results available if a higher
34387limit is used.
34388
922fbb7b
AC
34389@subsubheading @value{GDBN} Command
34390
7dc42066 34391The corresponding @value{GDBN} command is @samp{info types}.
922fbb7b
AC
34392
34393@subsubheading Example
7dc42066
AB
34394@smallexample
34395@group
34396(gdb)
34397-symbol-info-types
34398^done,symbols=
34399 @{debug=
34400 [@{filename="gdb.mi/mi-sym-info-1.c",
34401 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34402 symbols=[@{name="float"@},
34403 @{name="int"@},
34404 @{line="27",name="typedef int my_int_t;"@}]@},
34405 @{filename="gdb.mi/mi-sym-info-2.c",
34406 fullname="/project/gdb.mi/mi-sym-info-2.c",
34407 symbols=[@{line="24",name="typedef float another_float_t;"@},
34408 @{line="23",name="typedef int another_int_t;"@},
34409 @{name="float"@},
34410 @{name="int"@}]@}]@}
34411@end group
34412@group
34413(gdb)
34414-symbol-info-types --name _int_
34415^done,symbols=
34416 @{debug=
34417 [@{filename="gdb.mi/mi-sym-info-1.c",
34418 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34419 symbols=[@{line="27",name="typedef int my_int_t;"@}]@},
34420 @{filename="gdb.mi/mi-sym-info-2.c",
34421 fullname="/project/gdb.mi/mi-sym-info-2.c",
34422 symbols=[@{line="23",name="typedef int another_int_t;"@}]@}]@}
34423@end group
34424@end smallexample
34425
34426@subheading The @code{-symbol-info-variables} Command
34427@findex -symbol-info-variables
34428@anchor{-symbol-info-variables}
34429
34430@subsubheading Synopsis
34431
34432@smallexample
34433 -symbol-info-variables [--include-nondebug]
34434 [--type @var{type_regexp}]
34435 [--name @var{name_regexp}]
c2512106
AB
34436 [--max-results @var{limit}]
34437
7dc42066
AB
34438@end smallexample
34439
34440@noindent
34441Return a list containing the names and types for all global variables
34442taken from the debug information. The variables are grouped by source
34443file, and shown with the line number on which each variable is
34444defined.
34445
34446The @code{--include-nondebug} option causes the output to include
34447data symbols from the symbol table.
34448
34449The options @code{--type} and @code{--name} allow the symbols returned
34450to be filtered based on either the name of the variable, or the type
34451of the variable.
34452
c2512106
AB
34453The option @code{--max-results} restricts the command to return no
34454more than @var{limit} results. If exactly @var{limit} results are
34455returned then there might be additional results available if a higher
34456limit is used.
34457
7dc42066 34458@subsubheading @value{GDBN} Command
922fbb7b 34459
7dc42066 34460The corresponding @value{GDBN} command is @samp{info variables}.
922fbb7b 34461
7dc42066
AB
34462@subsubheading Example
34463@smallexample
34464@group
34465(gdb)
34466-symbol-info-variables
34467^done,symbols=
34468 @{debug=
34469 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34470 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34471 symbols=[@{line="25",name="global_f1",type="float",
34472 description="static float global_f1;"@},
34473 @{line="24",name="global_i1",type="int",
34474 description="static int global_i1;"@}]@},
34475 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34476 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34477 symbols=[@{line="21",name="global_f2",type="int",
34478 description="int global_f2;"@},
34479 @{line="20",name="global_i2",type="int",
34480 description="int global_i2;"@},
34481 @{line="19",name="global_f1",type="float",
34482 description="static float global_f1;"@},
34483 @{line="18",name="global_i1",type="int",
34484 description="static int global_i1;"@}]@}]@}
34485@end group
34486@group
34487(gdb)
34488-symbol-info-variables --name f1
34489^done,symbols=
34490 @{debug=
34491 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34492 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34493 symbols=[@{line="25",name="global_f1",type="float",
34494 description="static float global_f1;"@}]@},
34495 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34496 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34497 symbols=[@{line="19",name="global_f1",type="float",
34498 description="static float global_f1;"@}]@}]@}
34499@end group
34500@group
34501(gdb)
34502-symbol-info-variables --type float
34503^done,symbols=
34504 @{debug=
34505 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34506 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34507 symbols=[@{line="25",name="global_f1",type="float",
34508 description="static float global_f1;"@}]@},
34509 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34510 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34511 symbols=[@{line="19",name="global_f1",type="float",
34512 description="static float global_f1;"@}]@}]@}
34513@end group
34514@group
34515(gdb)
34516-symbol-info-variables --include-nondebug
34517^done,symbols=
34518 @{debug=
34519 [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34520 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34521 symbols=[@{line="25",name="global_f1",type="float",
34522 description="static float global_f1;"@},
34523 @{line="24",name="global_i1",type="int",
34524 description="static int global_i1;"@}]@},
34525 @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34526 fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34527 symbols=[@{line="21",name="global_f2",type="int",
34528 description="int global_f2;"@},
34529 @{line="20",name="global_i2",type="int",
34530 description="int global_i2;"@},
34531 @{line="19",name="global_f1",type="float",
34532 description="static float global_f1;"@},
34533 @{line="18",name="global_i1",type="int",
34534 description="static int global_i1;"@}]@}],
34535 nondebug=
34536 [@{address="0x00000000004005d0",name="_IO_stdin_used"@},
34537 @{address="0x00000000004005d8",name="__dso_handle"@}
34538 ...
34539 ]@}
34540@end group
34541@end smallexample
34542
34543@ignore
a2c02241
NR
34544@subheading The @code{-symbol-info-line} Command
34545@findex -symbol-info-line
922fbb7b
AC
34546
34547@subsubheading Synopsis
34548
34549@smallexample
a2c02241 34550 -symbol-info-line
922fbb7b
AC
34551@end smallexample
34552
a2c02241 34553Show the core addresses of the code for a source line.
922fbb7b 34554
a2c02241 34555@subsubheading @value{GDBN} Command
922fbb7b 34556
a2c02241
NR
34557The corresponding @value{GDBN} command is @samp{info line}.
34558@code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
922fbb7b
AC
34559
34560@subsubheading Example
a2c02241 34561N.A.
922fbb7b
AC
34562
34563
a2c02241
NR
34564@subheading The @code{-symbol-info-symbol} Command
34565@findex -symbol-info-symbol
07f31aa6
DJ
34566
34567@subsubheading Synopsis
34568
a2c02241
NR
34569@smallexample
34570 -symbol-info-symbol @var{addr}
34571@end smallexample
07f31aa6 34572
a2c02241 34573Describe what symbol is at location @var{addr}.
07f31aa6 34574
a2c02241 34575@subsubheading @value{GDBN} Command
07f31aa6 34576
a2c02241 34577The corresponding @value{GDBN} command is @samp{info symbol}.
07f31aa6
DJ
34578
34579@subsubheading Example
a2c02241 34580N.A.
07f31aa6
DJ
34581
34582
a2c02241
NR
34583@subheading The @code{-symbol-list-functions} Command
34584@findex -symbol-list-functions
922fbb7b
AC
34585
34586@subsubheading Synopsis
34587
34588@smallexample
a2c02241 34589 -symbol-list-functions
922fbb7b
AC
34590@end smallexample
34591
a2c02241 34592List the functions in the executable.
922fbb7b
AC
34593
34594@subsubheading @value{GDBN} Command
34595
a2c02241
NR
34596@samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
34597@samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
34598
34599@subsubheading Example
a2c02241 34600N.A.
9901a55b 34601@end ignore
922fbb7b
AC
34602
34603
a2c02241
NR
34604@subheading The @code{-symbol-list-lines} Command
34605@findex -symbol-list-lines
922fbb7b
AC
34606
34607@subsubheading Synopsis
34608
34609@smallexample
a2c02241 34610 -symbol-list-lines @var{filename}
922fbb7b
AC
34611@end smallexample
34612
a2c02241
NR
34613Print the list of lines that contain code and their associated program
34614addresses for the given source filename. The entries are sorted in
34615ascending PC order.
922fbb7b
AC
34616
34617@subsubheading @value{GDBN} Command
34618
a2c02241 34619There is no corresponding @value{GDBN} command.
922fbb7b
AC
34620
34621@subsubheading Example
a2c02241 34622@smallexample
594fe323 34623(gdb)
a2c02241
NR
34624-symbol-list-lines basics.c
34625^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
594fe323 34626(gdb)
a2c02241 34627@end smallexample
922fbb7b
AC
34628
34629
9901a55b 34630@ignore
a2c02241
NR
34631@subheading The @code{-symbol-list-types} Command
34632@findex -symbol-list-types
922fbb7b
AC
34633
34634@subsubheading Synopsis
34635
34636@smallexample
a2c02241 34637 -symbol-list-types
922fbb7b
AC
34638@end smallexample
34639
a2c02241 34640List all the type names.
922fbb7b
AC
34641
34642@subsubheading @value{GDBN} Command
34643
a2c02241
NR
34644The corresponding commands are @samp{info types} in @value{GDBN},
34645@samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
34646
34647@subsubheading Example
34648N.A.
34649
34650
a2c02241
NR
34651@subheading The @code{-symbol-list-variables} Command
34652@findex -symbol-list-variables
922fbb7b
AC
34653
34654@subsubheading Synopsis
34655
34656@smallexample
a2c02241 34657 -symbol-list-variables
922fbb7b
AC
34658@end smallexample
34659
a2c02241 34660List all the global and static variable names.
922fbb7b
AC
34661
34662@subsubheading @value{GDBN} Command
34663
a2c02241 34664@samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
922fbb7b
AC
34665
34666@subsubheading Example
34667N.A.
34668
34669
a2c02241
NR
34670@subheading The @code{-symbol-locate} Command
34671@findex -symbol-locate
922fbb7b
AC
34672
34673@subsubheading Synopsis
34674
34675@smallexample
a2c02241 34676 -symbol-locate
922fbb7b
AC
34677@end smallexample
34678
922fbb7b
AC
34679@subsubheading @value{GDBN} Command
34680
a2c02241 34681@samp{gdb_loc} in @code{gdbtk}.
922fbb7b
AC
34682
34683@subsubheading Example
34684N.A.
34685
34686
a2c02241
NR
34687@subheading The @code{-symbol-type} Command
34688@findex -symbol-type
922fbb7b
AC
34689
34690@subsubheading Synopsis
34691
34692@smallexample
a2c02241 34693 -symbol-type @var{variable}
922fbb7b
AC
34694@end smallexample
34695
a2c02241 34696Show type of @var{variable}.
922fbb7b 34697
a2c02241 34698@subsubheading @value{GDBN} Command
922fbb7b 34699
a2c02241
NR
34700The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
34701@samp{gdb_obj_variable}.
34702
34703@subsubheading Example
34704N.A.
9901a55b 34705@end ignore
a2c02241
NR
34706
34707
34708@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34709@node GDB/MI File Commands
34710@section @sc{gdb/mi} File Commands
34711
34712This section describes the GDB/MI commands to specify executable file names
34713and to read in and obtain symbol table information.
34714
34715@subheading The @code{-file-exec-and-symbols} Command
34716@findex -file-exec-and-symbols
34717
34718@subsubheading Synopsis
922fbb7b
AC
34719
34720@smallexample
a2c02241 34721 -file-exec-and-symbols @var{file}
922fbb7b
AC
34722@end smallexample
34723
a2c02241
NR
34724Specify the executable file to be debugged. This file is the one from
34725which the symbol table is also read. If no file is specified, the
34726command clears the executable and symbol information. If breakpoints
34727are set when using this command with no arguments, @value{GDBN} will produce
34728error messages. Otherwise, no output is produced, except a completion
34729notification.
34730
922fbb7b
AC
34731@subsubheading @value{GDBN} Command
34732
a2c02241 34733The corresponding @value{GDBN} command is @samp{file}.
922fbb7b
AC
34734
34735@subsubheading Example
34736
34737@smallexample
594fe323 34738(gdb)
a2c02241
NR
34739-file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
34740^done
594fe323 34741(gdb)
922fbb7b
AC
34742@end smallexample
34743
922fbb7b 34744
a2c02241
NR
34745@subheading The @code{-file-exec-file} Command
34746@findex -file-exec-file
922fbb7b
AC
34747
34748@subsubheading Synopsis
34749
34750@smallexample
a2c02241 34751 -file-exec-file @var{file}
922fbb7b
AC
34752@end smallexample
34753
a2c02241
NR
34754Specify the executable file to be debugged. Unlike
34755@samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
34756from this file. If used without argument, @value{GDBN} clears the information
34757about the executable file. No output is produced, except a completion
34758notification.
922fbb7b 34759
a2c02241
NR
34760@subsubheading @value{GDBN} Command
34761
34762The corresponding @value{GDBN} command is @samp{exec-file}.
922fbb7b
AC
34763
34764@subsubheading Example
a2c02241
NR
34765
34766@smallexample
594fe323 34767(gdb)
a2c02241
NR
34768-file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
34769^done
594fe323 34770(gdb)
a2c02241 34771@end smallexample
922fbb7b
AC
34772
34773
9901a55b 34774@ignore
a2c02241
NR
34775@subheading The @code{-file-list-exec-sections} Command
34776@findex -file-list-exec-sections
922fbb7b
AC
34777
34778@subsubheading Synopsis
34779
34780@smallexample
a2c02241 34781 -file-list-exec-sections
922fbb7b
AC
34782@end smallexample
34783
a2c02241
NR
34784List the sections of the current executable file.
34785
922fbb7b
AC
34786@subsubheading @value{GDBN} Command
34787
a2c02241
NR
34788The @value{GDBN} command @samp{info file} shows, among the rest, the same
34789information as this command. @code{gdbtk} has a corresponding command
34790@samp{gdb_load_info}.
922fbb7b
AC
34791
34792@subsubheading Example
34793N.A.
9901a55b 34794@end ignore
922fbb7b
AC
34795
34796
a2c02241
NR
34797@subheading The @code{-file-list-exec-source-file} Command
34798@findex -file-list-exec-source-file
922fbb7b
AC
34799
34800@subsubheading Synopsis
34801
34802@smallexample
a2c02241 34803 -file-list-exec-source-file
922fbb7b
AC
34804@end smallexample
34805
a2c02241 34806List the line number, the current source file, and the absolute path
44288b44
NR
34807to the current source file for the current executable. The macro
34808information field has a value of @samp{1} or @samp{0} depending on
34809whether or not the file includes preprocessor macro information.
922fbb7b
AC
34810
34811@subsubheading @value{GDBN} Command
34812
a2c02241 34813The @value{GDBN} equivalent is @samp{info source}
922fbb7b
AC
34814
34815@subsubheading Example
34816
922fbb7b 34817@smallexample
594fe323 34818(gdb)
a2c02241 34819123-file-list-exec-source-file
44288b44 34820123^done,line="1",file="foo.c",fullname="/home/bar/foo.c,macro-info="1"
594fe323 34821(gdb)
922fbb7b
AC
34822@end smallexample
34823
34824
a2c02241
NR
34825@subheading The @code{-file-list-exec-source-files} Command
34826@findex -file-list-exec-source-files
922fbb7b
AC
34827
34828@subsubheading Synopsis
34829
34830@smallexample
a2c02241 34831 -file-list-exec-source-files
922fbb7b
AC
34832@end smallexample
34833
a2c02241
NR
34834List the source files for the current executable.
34835
f35a17b5
JK
34836It will always output both the filename and fullname (absolute file
34837name) of a source file.
922fbb7b
AC
34838
34839@subsubheading @value{GDBN} Command
34840
a2c02241
NR
34841The @value{GDBN} equivalent is @samp{info sources}.
34842@code{gdbtk} has an analogous command @samp{gdb_listfiles}.
922fbb7b
AC
34843
34844@subsubheading Example
922fbb7b 34845@smallexample
594fe323 34846(gdb)
a2c02241
NR
34847-file-list-exec-source-files
34848^done,files=[
34849@{file=foo.c,fullname=/home/foo.c@},
34850@{file=/home/bar.c,fullname=/home/bar.c@},
34851@{file=gdb_could_not_find_fullpath.c@}]
594fe323 34852(gdb)
922fbb7b
AC
34853@end smallexample
34854
a2c02241
NR
34855@subheading The @code{-file-list-shared-libraries} Command
34856@findex -file-list-shared-libraries
922fbb7b 34857
a2c02241 34858@subsubheading Synopsis
922fbb7b 34859
a2c02241 34860@smallexample
51457a05 34861 -file-list-shared-libraries [ @var{regexp} ]
a2c02241 34862@end smallexample
922fbb7b 34863
a2c02241 34864List the shared libraries in the program.
51457a05
MAL
34865With a regular expression @var{regexp}, only those libraries whose
34866names match @var{regexp} are listed.
922fbb7b 34867
a2c02241 34868@subsubheading @value{GDBN} Command
922fbb7b 34869
51457a05
MAL
34870The corresponding @value{GDBN} command is @samp{info shared}. The fields
34871have a similar meaning to the @code{=library-loaded} notification.
34872The @code{ranges} field specifies the multiple segments belonging to this
34873library. Each range has the following fields:
34874
34875@table @samp
34876@item from
34877The address defining the inclusive lower bound of the segment.
34878@item to
34879The address defining the exclusive upper bound of the segment.
34880@end table
922fbb7b 34881
a2c02241 34882@subsubheading Example
51457a05
MAL
34883@smallexample
34884(gdb)
34885-file-list-exec-source-files
34886^done,shared-libraries=[
34887@{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"@}]@},
34888@{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"@}]@}]
34889(gdb)
34890@end smallexample
922fbb7b
AC
34891
34892
51457a05 34893@ignore
a2c02241
NR
34894@subheading The @code{-file-list-symbol-files} Command
34895@findex -file-list-symbol-files
922fbb7b 34896
a2c02241 34897@subsubheading Synopsis
922fbb7b 34898
a2c02241
NR
34899@smallexample
34900 -file-list-symbol-files
34901@end smallexample
922fbb7b 34902
a2c02241 34903List symbol files.
922fbb7b 34904
a2c02241 34905@subsubheading @value{GDBN} Command
922fbb7b 34906
a2c02241 34907The corresponding @value{GDBN} command is @samp{info file} (part of it).
922fbb7b 34908
a2c02241
NR
34909@subsubheading Example
34910N.A.
9901a55b 34911@end ignore
922fbb7b 34912
922fbb7b 34913
a2c02241
NR
34914@subheading The @code{-file-symbol-file} Command
34915@findex -file-symbol-file
922fbb7b 34916
a2c02241 34917@subsubheading Synopsis
922fbb7b 34918
a2c02241
NR
34919@smallexample
34920 -file-symbol-file @var{file}
34921@end smallexample
922fbb7b 34922
a2c02241
NR
34923Read symbol table info from the specified @var{file} argument. When
34924used without arguments, clears @value{GDBN}'s symbol table info. No output is
34925produced, except for a completion notification.
922fbb7b 34926
a2c02241 34927@subsubheading @value{GDBN} Command
922fbb7b 34928
a2c02241 34929The corresponding @value{GDBN} command is @samp{symbol-file}.
922fbb7b 34930
a2c02241 34931@subsubheading Example
922fbb7b 34932
a2c02241 34933@smallexample
594fe323 34934(gdb)
a2c02241
NR
34935-file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
34936^done
594fe323 34937(gdb)
a2c02241 34938@end smallexample
922fbb7b 34939
a2c02241 34940@ignore
a2c02241
NR
34941@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34942@node GDB/MI Memory Overlay Commands
34943@section @sc{gdb/mi} Memory Overlay Commands
922fbb7b 34944
a2c02241 34945The memory overlay commands are not implemented.
922fbb7b 34946
a2c02241 34947@c @subheading -overlay-auto
922fbb7b 34948
a2c02241 34949@c @subheading -overlay-list-mapping-state
922fbb7b 34950
a2c02241 34951@c @subheading -overlay-list-overlays
922fbb7b 34952
a2c02241 34953@c @subheading -overlay-map
922fbb7b 34954
a2c02241 34955@c @subheading -overlay-off
922fbb7b 34956
a2c02241 34957@c @subheading -overlay-on
922fbb7b 34958
a2c02241 34959@c @subheading -overlay-unmap
922fbb7b 34960
a2c02241
NR
34961@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34962@node GDB/MI Signal Handling Commands
34963@section @sc{gdb/mi} Signal Handling Commands
922fbb7b 34964
a2c02241 34965Signal handling commands are not implemented.
922fbb7b 34966
a2c02241 34967@c @subheading -signal-handle
922fbb7b 34968
a2c02241 34969@c @subheading -signal-list-handle-actions
922fbb7b 34970
a2c02241
NR
34971@c @subheading -signal-list-signal-types
34972@end ignore
922fbb7b 34973
922fbb7b 34974
a2c02241
NR
34975@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34976@node GDB/MI Target Manipulation
34977@section @sc{gdb/mi} Target Manipulation Commands
922fbb7b
AC
34978
34979
a2c02241
NR
34980@subheading The @code{-target-attach} Command
34981@findex -target-attach
922fbb7b
AC
34982
34983@subsubheading Synopsis
34984
34985@smallexample
c3b108f7 34986 -target-attach @var{pid} | @var{gid} | @var{file}
922fbb7b
AC
34987@end smallexample
34988
c3b108f7
VP
34989Attach to a process @var{pid} or a file @var{file} outside of
34990@value{GDBN}, or a thread group @var{gid}. If attaching to a thread
34991group, the id previously returned by
34992@samp{-list-thread-groups --available} must be used.
922fbb7b 34993
79a6e687 34994@subsubheading @value{GDBN} Command
922fbb7b 34995
a2c02241 34996The corresponding @value{GDBN} command is @samp{attach}.
922fbb7b 34997
a2c02241 34998@subsubheading Example
b56e7235
VP
34999@smallexample
35000(gdb)
35001-target-attach 34
35002=thread-created,id="1"
5ae4183a 35003*stopped,thread-id="1",frame=@{addr="0xb7f7e410",func="bar",args=[]@}
b56e7235
VP
35004^done
35005(gdb)
35006@end smallexample
a2c02241 35007
9901a55b 35008@ignore
a2c02241
NR
35009@subheading The @code{-target-compare-sections} Command
35010@findex -target-compare-sections
922fbb7b
AC
35011
35012@subsubheading Synopsis
35013
35014@smallexample
a2c02241 35015 -target-compare-sections [ @var{section} ]
922fbb7b
AC
35016@end smallexample
35017
a2c02241
NR
35018Compare data of section @var{section} on target to the exec file.
35019Without the argument, all sections are compared.
922fbb7b 35020
a2c02241 35021@subsubheading @value{GDBN} Command
922fbb7b 35022
a2c02241 35023The @value{GDBN} equivalent is @samp{compare-sections}.
922fbb7b 35024
a2c02241
NR
35025@subsubheading Example
35026N.A.
9901a55b 35027@end ignore
a2c02241
NR
35028
35029
35030@subheading The @code{-target-detach} Command
35031@findex -target-detach
922fbb7b
AC
35032
35033@subsubheading Synopsis
35034
35035@smallexample
c3b108f7 35036 -target-detach [ @var{pid} | @var{gid} ]
922fbb7b
AC
35037@end smallexample
35038
a2c02241 35039Detach from the remote target which normally resumes its execution.
c3b108f7
VP
35040If either @var{pid} or @var{gid} is specified, detaches from either
35041the specified process, or specified thread group. There's no output.
a2c02241 35042
79a6e687 35043@subsubheading @value{GDBN} Command
a2c02241
NR
35044
35045The corresponding @value{GDBN} command is @samp{detach}.
35046
35047@subsubheading Example
922fbb7b
AC
35048
35049@smallexample
594fe323 35050(gdb)
a2c02241
NR
35051-target-detach
35052^done
594fe323 35053(gdb)
922fbb7b
AC
35054@end smallexample
35055
35056
a2c02241
NR
35057@subheading The @code{-target-disconnect} Command
35058@findex -target-disconnect
922fbb7b
AC
35059
35060@subsubheading Synopsis
35061
123dc839 35062@smallexample
a2c02241 35063 -target-disconnect
123dc839 35064@end smallexample
922fbb7b 35065
a2c02241
NR
35066Disconnect from the remote target. There's no output and the target is
35067generally not resumed.
35068
79a6e687 35069@subsubheading @value{GDBN} Command
a2c02241
NR
35070
35071The corresponding @value{GDBN} command is @samp{disconnect}.
bc8ced35
NR
35072
35073@subsubheading Example
922fbb7b
AC
35074
35075@smallexample
594fe323 35076(gdb)
a2c02241
NR
35077-target-disconnect
35078^done
594fe323 35079(gdb)
922fbb7b
AC
35080@end smallexample
35081
35082
a2c02241
NR
35083@subheading The @code{-target-download} Command
35084@findex -target-download
922fbb7b
AC
35085
35086@subsubheading Synopsis
35087
35088@smallexample
a2c02241 35089 -target-download
922fbb7b
AC
35090@end smallexample
35091
a2c02241
NR
35092Loads the executable onto the remote target.
35093It prints out an update message every half second, which includes the fields:
35094
35095@table @samp
35096@item section
35097The name of the section.
35098@item section-sent
35099The size of what has been sent so far for that section.
35100@item section-size
35101The size of the section.
35102@item total-sent
35103The total size of what was sent so far (the current and the previous sections).
35104@item total-size
35105The size of the overall executable to download.
35106@end table
35107
35108@noindent
35109Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
35110@sc{gdb/mi} Output Syntax}).
35111
35112In addition, it prints the name and size of the sections, as they are
35113downloaded. These messages include the following fields:
35114
35115@table @samp
35116@item section
35117The name of the section.
35118@item section-size
35119The size of the section.
35120@item total-size
35121The size of the overall executable to download.
35122@end table
35123
35124@noindent
35125At the end, a summary is printed.
35126
35127@subsubheading @value{GDBN} Command
35128
35129The corresponding @value{GDBN} command is @samp{load}.
35130
35131@subsubheading Example
35132
35133Note: each status message appears on a single line. Here the messages
35134have been broken down so that they can fit onto a page.
922fbb7b
AC
35135
35136@smallexample
594fe323 35137(gdb)
a2c02241
NR
35138-target-download
35139+download,@{section=".text",section-size="6668",total-size="9880"@}
35140+download,@{section=".text",section-sent="512",section-size="6668",
35141total-sent="512",total-size="9880"@}
35142+download,@{section=".text",section-sent="1024",section-size="6668",
35143total-sent="1024",total-size="9880"@}
35144+download,@{section=".text",section-sent="1536",section-size="6668",
35145total-sent="1536",total-size="9880"@}
35146+download,@{section=".text",section-sent="2048",section-size="6668",
35147total-sent="2048",total-size="9880"@}
35148+download,@{section=".text",section-sent="2560",section-size="6668",
35149total-sent="2560",total-size="9880"@}
35150+download,@{section=".text",section-sent="3072",section-size="6668",
35151total-sent="3072",total-size="9880"@}
35152+download,@{section=".text",section-sent="3584",section-size="6668",
35153total-sent="3584",total-size="9880"@}
35154+download,@{section=".text",section-sent="4096",section-size="6668",
35155total-sent="4096",total-size="9880"@}
35156+download,@{section=".text",section-sent="4608",section-size="6668",
35157total-sent="4608",total-size="9880"@}
35158+download,@{section=".text",section-sent="5120",section-size="6668",
35159total-sent="5120",total-size="9880"@}
35160+download,@{section=".text",section-sent="5632",section-size="6668",
35161total-sent="5632",total-size="9880"@}
35162+download,@{section=".text",section-sent="6144",section-size="6668",
35163total-sent="6144",total-size="9880"@}
35164+download,@{section=".text",section-sent="6656",section-size="6668",
35165total-sent="6656",total-size="9880"@}
35166+download,@{section=".init",section-size="28",total-size="9880"@}
35167+download,@{section=".fini",section-size="28",total-size="9880"@}
35168+download,@{section=".data",section-size="3156",total-size="9880"@}
35169+download,@{section=".data",section-sent="512",section-size="3156",
35170total-sent="7236",total-size="9880"@}
35171+download,@{section=".data",section-sent="1024",section-size="3156",
35172total-sent="7748",total-size="9880"@}
35173+download,@{section=".data",section-sent="1536",section-size="3156",
35174total-sent="8260",total-size="9880"@}
35175+download,@{section=".data",section-sent="2048",section-size="3156",
35176total-sent="8772",total-size="9880"@}
35177+download,@{section=".data",section-sent="2560",section-size="3156",
35178total-sent="9284",total-size="9880"@}
35179+download,@{section=".data",section-sent="3072",section-size="3156",
35180total-sent="9796",total-size="9880"@}
35181^done,address="0x10004",load-size="9880",transfer-rate="6586",
35182write-rate="429"
594fe323 35183(gdb)
922fbb7b
AC
35184@end smallexample
35185
35186
9901a55b 35187@ignore
a2c02241
NR
35188@subheading The @code{-target-exec-status} Command
35189@findex -target-exec-status
922fbb7b
AC
35190
35191@subsubheading Synopsis
35192
35193@smallexample
a2c02241 35194 -target-exec-status
922fbb7b
AC
35195@end smallexample
35196
a2c02241
NR
35197Provide information on the state of the target (whether it is running or
35198not, for instance).
922fbb7b 35199
a2c02241 35200@subsubheading @value{GDBN} Command
922fbb7b 35201
a2c02241
NR
35202There's no equivalent @value{GDBN} command.
35203
35204@subsubheading Example
35205N.A.
922fbb7b 35206
a2c02241
NR
35207
35208@subheading The @code{-target-list-available-targets} Command
35209@findex -target-list-available-targets
922fbb7b
AC
35210
35211@subsubheading Synopsis
35212
35213@smallexample
a2c02241 35214 -target-list-available-targets
922fbb7b
AC
35215@end smallexample
35216
a2c02241 35217List the possible targets to connect to.
922fbb7b 35218
a2c02241 35219@subsubheading @value{GDBN} Command
922fbb7b 35220
a2c02241 35221The corresponding @value{GDBN} command is @samp{help target}.
922fbb7b 35222
a2c02241
NR
35223@subsubheading Example
35224N.A.
35225
35226
35227@subheading The @code{-target-list-current-targets} Command
35228@findex -target-list-current-targets
922fbb7b
AC
35229
35230@subsubheading Synopsis
35231
35232@smallexample
a2c02241 35233 -target-list-current-targets
922fbb7b
AC
35234@end smallexample
35235
a2c02241 35236Describe the current target.
922fbb7b 35237
a2c02241 35238@subsubheading @value{GDBN} Command
922fbb7b 35239
a2c02241
NR
35240The corresponding information is printed by @samp{info file} (among
35241other things).
922fbb7b 35242
a2c02241
NR
35243@subsubheading Example
35244N.A.
35245
35246
35247@subheading The @code{-target-list-parameters} Command
35248@findex -target-list-parameters
922fbb7b
AC
35249
35250@subsubheading Synopsis
35251
35252@smallexample
a2c02241 35253 -target-list-parameters
922fbb7b
AC
35254@end smallexample
35255
a2c02241 35256@c ????
9901a55b 35257@end ignore
a2c02241
NR
35258
35259@subsubheading @value{GDBN} Command
35260
35261No equivalent.
922fbb7b
AC
35262
35263@subsubheading Example
a2c02241
NR
35264N.A.
35265
78cbbba8
LM
35266@subheading The @code{-target-flash-erase} Command
35267@findex -target-flash-erase
35268
35269@subsubheading Synopsis
35270
35271@smallexample
35272 -target-flash-erase
35273@end smallexample
35274
35275Erases all known flash memory regions on the target.
35276
35277The corresponding @value{GDBN} command is @samp{flash-erase}.
35278
35279The output is a list of flash regions that have been erased, with starting
35280addresses and memory region sizes.
35281
35282@smallexample
35283(gdb)
35284-target-flash-erase
35285^done,erased-regions=@{address="0x0",size="0x40000"@}
35286(gdb)
35287@end smallexample
a2c02241
NR
35288
35289@subheading The @code{-target-select} Command
35290@findex -target-select
35291
35292@subsubheading Synopsis
922fbb7b
AC
35293
35294@smallexample
a2c02241 35295 -target-select @var{type} @var{parameters @dots{}}
922fbb7b
AC
35296@end smallexample
35297
a2c02241 35298Connect @value{GDBN} to the remote target. This command takes two args:
922fbb7b 35299
a2c02241
NR
35300@table @samp
35301@item @var{type}
75c99385 35302The type of target, for instance @samp{remote}, etc.
a2c02241
NR
35303@item @var{parameters}
35304Device names, host names and the like. @xref{Target Commands, ,
79a6e687 35305Commands for Managing Targets}, for more details.
a2c02241
NR
35306@end table
35307
35308The output is a connection notification, followed by the address at
35309which the target program is, in the following form:
922fbb7b
AC
35310
35311@smallexample
a2c02241
NR
35312^connected,addr="@var{address}",func="@var{function name}",
35313 args=[@var{arg list}]
922fbb7b
AC
35314@end smallexample
35315
a2c02241
NR
35316@subsubheading @value{GDBN} Command
35317
35318The corresponding @value{GDBN} command is @samp{target}.
265eeb58
NR
35319
35320@subsubheading Example
922fbb7b 35321
265eeb58 35322@smallexample
594fe323 35323(gdb)
75c99385 35324-target-select remote /dev/ttya
a2c02241 35325^connected,addr="0xfe00a300",func="??",args=[]
594fe323 35326(gdb)
265eeb58 35327@end smallexample
ef21caaf 35328
a6b151f1
DJ
35329@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35330@node GDB/MI File Transfer Commands
35331@section @sc{gdb/mi} File Transfer Commands
35332
35333
35334@subheading The @code{-target-file-put} Command
35335@findex -target-file-put
35336
35337@subsubheading Synopsis
35338
35339@smallexample
35340 -target-file-put @var{hostfile} @var{targetfile}
35341@end smallexample
35342
35343Copy file @var{hostfile} from the host system (the machine running
35344@value{GDBN}) to @var{targetfile} on the target system.
35345
35346@subsubheading @value{GDBN} Command
35347
35348The corresponding @value{GDBN} command is @samp{remote put}.
35349
35350@subsubheading Example
35351
35352@smallexample
35353(gdb)
35354-target-file-put localfile remotefile
35355^done
35356(gdb)
35357@end smallexample
35358
35359
1763a388 35360@subheading The @code{-target-file-get} Command
a6b151f1
DJ
35361@findex -target-file-get
35362
35363@subsubheading Synopsis
35364
35365@smallexample
35366 -target-file-get @var{targetfile} @var{hostfile}
35367@end smallexample
35368
35369Copy file @var{targetfile} from the target system to @var{hostfile}
35370on the host system.
35371
35372@subsubheading @value{GDBN} Command
35373
35374The corresponding @value{GDBN} command is @samp{remote get}.
35375
35376@subsubheading Example
35377
35378@smallexample
35379(gdb)
35380-target-file-get remotefile localfile
35381^done
35382(gdb)
35383@end smallexample
35384
35385
35386@subheading The @code{-target-file-delete} Command
35387@findex -target-file-delete
35388
35389@subsubheading Synopsis
35390
35391@smallexample
35392 -target-file-delete @var{targetfile}
35393@end smallexample
35394
35395Delete @var{targetfile} from the target system.
35396
35397@subsubheading @value{GDBN} Command
35398
35399The corresponding @value{GDBN} command is @samp{remote delete}.
35400
35401@subsubheading Example
35402
35403@smallexample
35404(gdb)
35405-target-file-delete remotefile
35406^done
35407(gdb)
35408@end smallexample
35409
35410
58d06528
JB
35411@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35412@node GDB/MI Ada Exceptions Commands
35413@section Ada Exceptions @sc{gdb/mi} Commands
35414
35415@subheading The @code{-info-ada-exceptions} Command
35416@findex -info-ada-exceptions
35417
35418@subsubheading Synopsis
35419
35420@smallexample
35421 -info-ada-exceptions [ @var{regexp}]
35422@end smallexample
35423
35424List all Ada exceptions defined within the program being debugged.
35425With a regular expression @var{regexp}, only those exceptions whose
35426names match @var{regexp} are listed.
35427
35428@subsubheading @value{GDBN} Command
35429
35430The corresponding @value{GDBN} command is @samp{info exceptions}.
35431
35432@subsubheading Result
35433
35434The result is a table of Ada exceptions. The following columns are
35435defined for each exception:
35436
35437@table @samp
35438@item name
35439The name of the exception.
35440
35441@item address
35442The address of the exception.
35443
35444@end table
35445
35446@subsubheading Example
35447
35448@smallexample
35449-info-ada-exceptions aint
35450^done,ada-exceptions=@{nr_rows="2",nr_cols="2",
35451hdr=[@{width="1",alignment="-1",col_name="name",colhdr="Name"@},
35452@{width="1",alignment="-1",col_name="address",colhdr="Address"@}],
35453body=[@{name="constraint_error",address="0x0000000000613da0"@},
35454@{name="const.aint_global_e",address="0x0000000000613b00"@}]@}
35455@end smallexample
35456
35457@subheading Catching Ada Exceptions
35458
35459The commands describing how to ask @value{GDBN} to stop when a program
35460raises an exception are described at @ref{Ada Exception GDB/MI
35461Catchpoint Commands}.
35462
35463
ef21caaf 35464@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d192b373
JB
35465@node GDB/MI Support Commands
35466@section @sc{gdb/mi} Support Commands
ef21caaf 35467
d192b373
JB
35468Since new commands and features get regularly added to @sc{gdb/mi},
35469some commands are available to help front-ends query the debugger
35470about support for these capabilities. Similarly, it is also possible
35471to query @value{GDBN} about target support of certain features.
ef21caaf 35472
6b7cbff1
JB
35473@subheading The @code{-info-gdb-mi-command} Command
35474@cindex @code{-info-gdb-mi-command}
35475@findex -info-gdb-mi-command
35476
35477@subsubheading Synopsis
35478
35479@smallexample
35480 -info-gdb-mi-command @var{cmd_name}
35481@end smallexample
35482
35483Query support for the @sc{gdb/mi} command named @var{cmd_name}.
35484
35485Note that the dash (@code{-}) starting all @sc{gdb/mi} commands
35486is technically not part of the command name (@pxref{GDB/MI Input
35487Syntax}), and thus should be omitted in @var{cmd_name}. However,
35488for ease of use, this command also accepts the form with the leading
35489dash.
35490
35491@subsubheading @value{GDBN} Command
35492
35493There is no corresponding @value{GDBN} command.
35494
35495@subsubheading Result
35496
35497The result is a tuple. There is currently only one field:
35498
35499@table @samp
35500@item exists
35501This field is equal to @code{"true"} if the @sc{gdb/mi} command exists,
35502@code{"false"} otherwise.
35503
35504@end table
35505
35506@subsubheading Example
35507
35508Here is an example where the @sc{gdb/mi} command does not exist:
35509
35510@smallexample
35511-info-gdb-mi-command unsupported-command
35512^done,command=@{exists="false"@}
35513@end smallexample
35514
35515@noindent
35516And here is an example where the @sc{gdb/mi} command is known
35517to the debugger:
35518
35519@smallexample
35520-info-gdb-mi-command symbol-list-lines
35521^done,command=@{exists="true"@}
35522@end smallexample
35523
084344da
VP
35524@subheading The @code{-list-features} Command
35525@findex -list-features
9b26f0fb 35526@cindex supported @sc{gdb/mi} features, list
084344da
VP
35527
35528Returns a list of particular features of the MI protocol that
35529this version of gdb implements. A feature can be a command,
35530or a new field in an output of some command, or even an
35531important bugfix. While a frontend can sometimes detect presence
35532of a feature at runtime, it is easier to perform detection at debugger
d192b373 35533startup.
084344da
VP
35534
35535The command returns a list of strings, with each string naming an
35536available feature. Each returned string is just a name, it does not
d192b373 35537have any internal structure. The list of possible feature names
084344da
VP
35538is given below.
35539
35540Example output:
35541
35542@smallexample
35543(gdb) -list-features
35544^done,result=["feature1","feature2"]
35545@end smallexample
35546
35547The current list of features is:
35548
edef6000 35549@ftable @samp
30e026bb 35550@item frozen-varobjs
a05336a1 35551Indicates support for the @code{-var-set-frozen} command, as well
6b92c0d3 35552as possible presence of the @code{frozen} field in the output
30e026bb
VP
35553of @code{-varobj-create}.
35554@item pending-breakpoints
a05336a1
JB
35555Indicates support for the @option{-f} option to the @code{-break-insert}
35556command.
b6313243 35557@item python
a05336a1 35558Indicates Python scripting support, Python-based
b6313243
TT
35559pretty-printing commands, and possible presence of the
35560@samp{display_hint} field in the output of @code{-var-list-children}
30e026bb 35561@item thread-info
a05336a1 35562Indicates support for the @code{-thread-info} command.
8dedea02 35563@item data-read-memory-bytes
a05336a1 35564Indicates support for the @code{-data-read-memory-bytes} and the
8dedea02 35565@code{-data-write-memory-bytes} commands.
39c4d40a
TT
35566@item breakpoint-notifications
35567Indicates that changes to breakpoints and breakpoints created via the
35568CLI will be announced via async records.
5d77fe44 35569@item ada-task-info
6adcee18 35570Indicates support for the @code{-ada-task-info} command.
422ad5c2
JB
35571@item language-option
35572Indicates that all @sc{gdb/mi} commands accept the @option{--language}
35573option (@pxref{Context management}).
6b7cbff1
JB
35574@item info-gdb-mi-command
35575Indicates support for the @code{-info-gdb-mi-command} command.
2ea126fa
JB
35576@item undefined-command-error-code
35577Indicates support for the "undefined-command" error code in error result
35578records, produced when trying to execute an undefined @sc{gdb/mi} command
35579(@pxref{GDB/MI Result Records}).
72bfa06c
JB
35580@item exec-run-start-option
35581Indicates that the @code{-exec-run} command supports the @option{--start}
35582option (@pxref{GDB/MI Program Execution}).
26fb3983
JV
35583@item data-disassemble-a-option
35584Indicates that the @code{-data-disassemble} command supports the @option{-a}
35585option (@pxref{GDB/MI Data Manipulation}).
edef6000 35586@end ftable
084344da 35587
c6ebd6cf
VP
35588@subheading The @code{-list-target-features} Command
35589@findex -list-target-features
35590
35591Returns a list of particular features that are supported by the
35592target. Those features affect the permitted MI commands, but
35593unlike the features reported by the @code{-list-features} command, the
35594features depend on which target GDB is using at the moment. Whenever
35595a target can change, due to commands such as @code{-target-select},
35596@code{-target-attach} or @code{-exec-run}, the list of target features
35597may change, and the frontend should obtain it again.
35598Example output:
35599
35600@smallexample
b3d3b4bd 35601(gdb) -list-target-features
c6ebd6cf
VP
35602^done,result=["async"]
35603@end smallexample
35604
35605The current list of features is:
35606
35607@table @samp
35608@item async
35609Indicates that the target is capable of asynchronous command
35610execution, which means that @value{GDBN} will accept further commands
35611while the target is running.
35612
f75d858b
MK
35613@item reverse
35614Indicates that the target is capable of reverse execution.
35615@xref{Reverse Execution}, for more information.
35616
c6ebd6cf
VP
35617@end table
35618
d192b373
JB
35619@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35620@node GDB/MI Miscellaneous Commands
35621@section Miscellaneous @sc{gdb/mi} Commands
35622
35623@c @subheading -gdb-complete
35624
35625@subheading The @code{-gdb-exit} Command
35626@findex -gdb-exit
35627
35628@subsubheading Synopsis
35629
35630@smallexample
35631 -gdb-exit
35632@end smallexample
35633
35634Exit @value{GDBN} immediately.
35635
35636@subsubheading @value{GDBN} Command
35637
35638Approximately corresponds to @samp{quit}.
35639
35640@subsubheading Example
35641
35642@smallexample
35643(gdb)
35644-gdb-exit
35645^exit
35646@end smallexample
35647
35648
35649@ignore
35650@subheading The @code{-exec-abort} Command
35651@findex -exec-abort
35652
35653@subsubheading Synopsis
35654
35655@smallexample
35656 -exec-abort
35657@end smallexample
35658
35659Kill the inferior running program.
35660
35661@subsubheading @value{GDBN} Command
35662
35663The corresponding @value{GDBN} command is @samp{kill}.
35664
35665@subsubheading Example
35666N.A.
35667@end ignore
35668
35669
35670@subheading The @code{-gdb-set} Command
35671@findex -gdb-set
35672
35673@subsubheading Synopsis
35674
35675@smallexample
35676 -gdb-set
35677@end smallexample
35678
35679Set an internal @value{GDBN} variable.
35680@c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
35681
35682@subsubheading @value{GDBN} Command
35683
35684The corresponding @value{GDBN} command is @samp{set}.
35685
35686@subsubheading Example
35687
35688@smallexample
35689(gdb)
35690-gdb-set $foo=3
35691^done
35692(gdb)
35693@end smallexample
35694
35695
35696@subheading The @code{-gdb-show} Command
35697@findex -gdb-show
35698
35699@subsubheading Synopsis
35700
35701@smallexample
35702 -gdb-show
35703@end smallexample
35704
35705Show the current value of a @value{GDBN} variable.
35706
35707@subsubheading @value{GDBN} Command
35708
35709The corresponding @value{GDBN} command is @samp{show}.
35710
35711@subsubheading Example
35712
35713@smallexample
35714(gdb)
35715-gdb-show annotate
35716^done,value="0"
35717(gdb)
35718@end smallexample
35719
35720@c @subheading -gdb-source
35721
35722
35723@subheading The @code{-gdb-version} Command
35724@findex -gdb-version
35725
35726@subsubheading Synopsis
35727
35728@smallexample
35729 -gdb-version
35730@end smallexample
35731
35732Show version information for @value{GDBN}. Used mostly in testing.
35733
35734@subsubheading @value{GDBN} Command
35735
35736The @value{GDBN} equivalent is @samp{show version}. @value{GDBN} by
35737default shows this information when you start an interactive session.
35738
35739@subsubheading Example
35740
35741@c This example modifies the actual output from GDB to avoid overfull
35742@c box in TeX.
35743@smallexample
35744(gdb)
35745-gdb-version
35746~GNU gdb 5.2.1
35747~Copyright 2000 Free Software Foundation, Inc.
35748~GDB is free software, covered by the GNU General Public License, and
35749~you are welcome to change it and/or distribute copies of it under
35750~ certain conditions.
35751~Type "show copying" to see the conditions.
35752~There is absolutely no warranty for GDB. Type "show warranty" for
35753~ details.
35754~This GDB was configured as
35755 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
35756^done
35757(gdb)
35758@end smallexample
35759
c3b108f7
VP
35760@subheading The @code{-list-thread-groups} Command
35761@findex -list-thread-groups
35762
35763@subheading Synopsis
35764
35765@smallexample
dc146f7c 35766-list-thread-groups [ --available ] [ --recurse 1 ] [ @var{group} ... ]
c3b108f7
VP
35767@end smallexample
35768
dc146f7c
VP
35769Lists thread groups (@pxref{Thread groups}). When a single thread
35770group is passed as the argument, lists the children of that group.
35771When several thread group are passed, lists information about those
35772thread groups. Without any parameters, lists information about all
35773top-level thread groups.
35774
35775Normally, thread groups that are being debugged are reported.
35776With the @samp{--available} option, @value{GDBN} reports thread groups
35777available on the target.
35778
35779The output of this command may have either a @samp{threads} result or
35780a @samp{groups} result. The @samp{thread} result has a list of tuples
35781as value, with each tuple describing a thread (@pxref{GDB/MI Thread
35782Information}). The @samp{groups} result has a list of tuples as value,
35783each tuple describing a thread group. If top-level groups are
35784requested (that is, no parameter is passed), or when several groups
35785are passed, the output always has a @samp{groups} result. The format
35786of the @samp{group} result is described below.
35787
35788To reduce the number of roundtrips it's possible to list thread groups
35789together with their children, by passing the @samp{--recurse} option
35790and the recursion depth. Presently, only recursion depth of 1 is
35791permitted. If this option is present, then every reported thread group
35792will also include its children, either as @samp{group} or
35793@samp{threads} field.
35794
35795In general, any combination of option and parameters is permitted, with
35796the following caveats:
35797
35798@itemize @bullet
35799@item
35800When a single thread group is passed, the output will typically
35801be the @samp{threads} result. Because threads may not contain
35802anything, the @samp{recurse} option will be ignored.
35803
35804@item
35805When the @samp{--available} option is passed, limited information may
35806be available. In particular, the list of threads of a process might
35807be inaccessible. Further, specifying specific thread groups might
35808not give any performance advantage over listing all thread groups.
35809The frontend should assume that @samp{-list-thread-groups --available}
35810is always an expensive operation and cache the results.
35811
35812@end itemize
35813
35814The @samp{groups} result is a list of tuples, where each tuple may
35815have the following fields:
35816
35817@table @code
35818@item id
35819Identifier of the thread group. This field is always present.
a79b8f6e
VP
35820The identifier is an opaque string; frontends should not try to
35821convert it to an integer, even though it might look like one.
dc146f7c
VP
35822
35823@item type
35824The type of the thread group. At present, only @samp{process} is a
35825valid type.
35826
35827@item pid
35828The target-specific process identifier. This field is only present
a79b8f6e 35829for thread groups of type @samp{process} and only if the process exists.
c3b108f7 35830
2ddf4301
SM
35831@item exit-code
35832The exit code of this group's last exited thread, formatted in octal.
35833This field is only present for thread groups of type @samp{process} and
35834only if the process is not running.
35835
dc146f7c
VP
35836@item num_children
35837The number of children this thread group has. This field may be
35838absent for an available thread group.
35839
35840@item threads
35841This field has a list of tuples as value, each tuple describing a
35842thread. It may be present if the @samp{--recurse} option is
35843specified, and it's actually possible to obtain the threads.
35844
35845@item cores
35846This field is a list of integers, each identifying a core that one
35847thread of the group is running on. This field may be absent if
35848such information is not available.
35849
a79b8f6e
VP
35850@item executable
35851The name of the executable file that corresponds to this thread group.
35852The field is only present for thread groups of type @samp{process},
35853and only if there is a corresponding executable file.
35854
dc146f7c 35855@end table
c3b108f7
VP
35856
35857@subheading Example
35858
35859@smallexample
35860@value{GDBP}
35861-list-thread-groups
35862^done,groups=[@{id="17",type="process",pid="yyy",num_children="2"@}]
35863-list-thread-groups 17
35864^done,threads=[@{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
35865 frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",args=[]@},state="running"@},
35866@{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
35867 frame=@{level="0",addr="0x0804891f",func="foo",args=[@{name="i",value="10"@}],
6d52907e 35868 file="/tmp/a.c",fullname="/tmp/a.c",line="158",arch="i386:x86_64"@},state="running"@}]]
dc146f7c
VP
35869-list-thread-groups --available
35870^done,groups=[@{id="17",type="process",pid="yyy",num_children="2",cores=[1,2]@}]
35871-list-thread-groups --available --recurse 1
35872 ^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
35873 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
35874 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},..]
35875-list-thread-groups --available --recurse 1 17 18
35876^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
35877 threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
35878 @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},...]
c3b108f7 35879@end smallexample
c6ebd6cf 35880
f3e0e960
SS
35881@subheading The @code{-info-os} Command
35882@findex -info-os
35883
35884@subsubheading Synopsis
35885
35886@smallexample
35887-info-os [ @var{type} ]
35888@end smallexample
35889
35890If no argument is supplied, the command returns a table of available
35891operating-system-specific information types. If one of these types is
35892supplied as an argument @var{type}, then the command returns a table
35893of data of that type.
35894
35895The types of information available depend on the target operating
35896system.
35897
35898@subsubheading @value{GDBN} Command
35899
35900The corresponding @value{GDBN} command is @samp{info os}.
35901
35902@subsubheading Example
35903
35904When run on a @sc{gnu}/Linux system, the output will look something
35905like this:
35906
35907@smallexample
35908@value{GDBP}
35909-info-os
d33279b3 35910^done,OSDataTable=@{nr_rows="10",nr_cols="3",
f3e0e960 35911hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="Type"@},
71caed83
SS
35912 @{width="10",alignment="-1",col_name="col1",colhdr="Description"@},
35913 @{width="10",alignment="-1",col_name="col2",colhdr="Title"@}],
d33279b3
AT
35914body=[item=@{col0="cpus",col1="Listing of all cpus/cores on the system",
35915 col2="CPUs"@},
35916 item=@{col0="files",col1="Listing of all file descriptors",
35917 col2="File descriptors"@},
35918 item=@{col0="modules",col1="Listing of all loaded kernel modules",
35919 col2="Kernel modules"@},
35920 item=@{col0="msg",col1="Listing of all message queues",
35921 col2="Message queues"@},
35922 item=@{col0="processes",col1="Listing of all processes",
71caed83
SS
35923 col2="Processes"@},
35924 item=@{col0="procgroups",col1="Listing of all process groups",
35925 col2="Process groups"@},
71caed83
SS
35926 item=@{col0="semaphores",col1="Listing of all semaphores",
35927 col2="Semaphores"@},
d33279b3
AT
35928 item=@{col0="shm",col1="Listing of all shared-memory regions",
35929 col2="Shared-memory regions"@},
35930 item=@{col0="sockets",col1="Listing of all internet-domain sockets",
35931 col2="Sockets"@},
35932 item=@{col0="threads",col1="Listing of all threads",
35933 col2="Threads"@}]
f3e0e960
SS
35934@value{GDBP}
35935-info-os processes
35936^done,OSDataTable=@{nr_rows="190",nr_cols="4",
35937hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="pid"@},
35938 @{width="10",alignment="-1",col_name="col1",colhdr="user"@},
35939 @{width="10",alignment="-1",col_name="col2",colhdr="command"@},
35940 @{width="10",alignment="-1",col_name="col3",colhdr="cores"@}],
35941body=[item=@{col0="1",col1="root",col2="/sbin/init",col3="0"@},
35942 item=@{col0="2",col1="root",col2="[kthreadd]",col3="1"@},
35943 item=@{col0="3",col1="root",col2="[ksoftirqd/0]",col3="0"@},
35944 ...
35945 item=@{col0="26446",col1="stan",col2="bash",col3="0"@},
35946 item=@{col0="28152",col1="stan",col2="bash",col3="1"@}]@}
35947(gdb)
35948@end smallexample
a79b8f6e 35949
71caed83
SS
35950(Note that the MI output here includes a @code{"Title"} column that
35951does not appear in command-line @code{info os}; this column is useful
35952for MI clients that want to enumerate the types of data, such as in a
35953popup menu, but is needless clutter on the command line, and
35954@code{info os} omits it.)
35955
a79b8f6e
VP
35956@subheading The @code{-add-inferior} Command
35957@findex -add-inferior
35958
35959@subheading Synopsis
35960
35961@smallexample
35962-add-inferior
35963@end smallexample
35964
65c574f6 35965Creates a new inferior (@pxref{Inferiors Connections and Programs}). The created
a79b8f6e
VP
35966inferior is not associated with any executable. Such association may
35967be established with the @samp{-file-exec-and-symbols} command
35968(@pxref{GDB/MI File Commands}). The command response has a single
b7742092 35969field, @samp{inferior}, whose value is the identifier of the
a79b8f6e
VP
35970thread group corresponding to the new inferior.
35971
35972@subheading Example
35973
35974@smallexample
35975@value{GDBP}
35976-add-inferior
b7742092 35977^done,inferior="i3"
a79b8f6e
VP
35978@end smallexample
35979
ef21caaf
NR
35980@subheading The @code{-interpreter-exec} Command
35981@findex -interpreter-exec
35982
35983@subheading Synopsis
35984
35985@smallexample
35986-interpreter-exec @var{interpreter} @var{command}
35987@end smallexample
a2c02241 35988@anchor{-interpreter-exec}
ef21caaf
NR
35989
35990Execute the specified @var{command} in the given @var{interpreter}.
35991
35992@subheading @value{GDBN} Command
35993
35994The corresponding @value{GDBN} command is @samp{interpreter-exec}.
35995
35996@subheading Example
35997
35998@smallexample
594fe323 35999(gdb)
ef21caaf
NR
36000-interpreter-exec console "break main"
36001&"During symbol reading, couldn't parse type; debugger out of date?.\n"
36002&"During symbol reading, bad structure-type format.\n"
36003~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
36004^done
594fe323 36005(gdb)
ef21caaf
NR
36006@end smallexample
36007
36008@subheading The @code{-inferior-tty-set} Command
36009@findex -inferior-tty-set
36010
36011@subheading Synopsis
36012
36013@smallexample
36014-inferior-tty-set /dev/pts/1
36015@end smallexample
36016
36017Set terminal for future runs of the program being debugged.
36018
36019@subheading @value{GDBN} Command
36020
36021The corresponding @value{GDBN} command is @samp{set inferior-tty} /dev/pts/1.
36022
36023@subheading Example
36024
36025@smallexample
594fe323 36026(gdb)
ef21caaf
NR
36027-inferior-tty-set /dev/pts/1
36028^done
594fe323 36029(gdb)
ef21caaf
NR
36030@end smallexample
36031
36032@subheading The @code{-inferior-tty-show} Command
36033@findex -inferior-tty-show
36034
36035@subheading Synopsis
36036
36037@smallexample
36038-inferior-tty-show
36039@end smallexample
36040
36041Show terminal for future runs of program being debugged.
36042
36043@subheading @value{GDBN} Command
36044
36045The corresponding @value{GDBN} command is @samp{show inferior-tty}.
36046
36047@subheading Example
36048
36049@smallexample
594fe323 36050(gdb)
ef21caaf
NR
36051-inferior-tty-set /dev/pts/1
36052^done
594fe323 36053(gdb)
ef21caaf
NR
36054-inferior-tty-show
36055^done,inferior_tty_terminal="/dev/pts/1"
594fe323 36056(gdb)
ef21caaf 36057@end smallexample
922fbb7b 36058
a4eefcd8
NR
36059@subheading The @code{-enable-timings} Command
36060@findex -enable-timings
36061
36062@subheading Synopsis
36063
36064@smallexample
36065-enable-timings [yes | no]
36066@end smallexample
36067
36068Toggle the printing of the wallclock, user and system times for an MI
36069command as a field in its output. This command is to help frontend
36070developers optimize the performance of their code. No argument is
36071equivalent to @samp{yes}.
36072
36073@subheading @value{GDBN} Command
36074
36075No equivalent.
36076
36077@subheading Example
36078
36079@smallexample
36080(gdb)
36081-enable-timings
36082^done
36083(gdb)
36084-break-insert main
36085^done,bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
36086addr="0x080484ed",func="main",file="myprog.c",
998580f1
MK
36087fullname="/home/nickrob/myprog.c",line="73",thread-groups=["i1"],
36088times="0"@},
a4eefcd8
NR
36089time=@{wallclock="0.05185",user="0.00800",system="0.00000"@}
36090(gdb)
36091-enable-timings no
36092^done
36093(gdb)
36094-exec-run
36095^running
36096(gdb)
a47ec5fe 36097*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
a4eefcd8
NR
36098frame=@{addr="0x080484ed",func="main",args=[@{name="argc",value="1"@},
36099@{name="argv",value="0xbfb60364"@}],file="myprog.c",
6d52907e 36100fullname="/home/nickrob/myprog.c",line="73",arch="i386:x86_64"@}
a4eefcd8
NR
36101(gdb)
36102@end smallexample
36103
26648588
JV
36104@subheading The @code{-complete} Command
36105@findex -complete
36106
36107@subheading Synopsis
36108
36109@smallexample
36110-complete @var{command}
36111@end smallexample
36112
36113Show a list of completions for partially typed CLI @var{command}.
36114
36115This command is intended for @sc{gdb/mi} frontends that cannot use two separate
7166f90a 36116CLI and MI channels --- for example: because of lack of PTYs like on Windows or
26648588
JV
36117because @value{GDBN} is used remotely via a SSH connection.
36118
36119@subheading Result
36120
36121The result consists of two or three fields:
36122
36123@table @samp
36124@item completion
36125This field contains the completed @var{command}. If @var{command}
36126has no known completions, this field is omitted.
36127
36128@item matches
36129This field contains a (possibly empty) array of matches. It is always present.
36130
36131@item max_completions_reached
36132This field contains @code{1} if number of known completions is above
7166f90a 36133@code{max-completions} limit (@pxref{Completion}), otherwise it contains
26648588
JV
36134@code{0}. It is always present.
36135
36136@end table
36137
36138@subheading @value{GDBN} Command
36139
36140The corresponding @value{GDBN} command is @samp{complete}.
36141
36142@subheading Example
36143
36144@smallexample
36145(gdb)
36146-complete br
36147^done,completion="break",
36148 matches=["break","break-range"],
36149 max_completions_reached="0"
36150(gdb)
36151-complete "b ma"
36152^done,completion="b ma",
36153 matches=["b madvise","b main"],max_completions_reached="0"
36154(gdb)
36155-complete "b push_b"
36156^done,completion="b push_back(",
36157 matches=[
36158 "b A::push_back(void*)",
36159 "b std::string::push_back(char)",
36160 "b std::vector<int, std::allocator<int> >::push_back(int&&)"],
36161 max_completions_reached="0"
36162(gdb)
36163-complete "nonexist"
36164^done,matches=[],max_completions_reached="0"
36165(gdb)
36166
36167@end smallexample
36168
922fbb7b
AC
36169@node Annotations
36170@chapter @value{GDBN} Annotations
36171
086432e2
AC
36172This chapter describes annotations in @value{GDBN}. Annotations were
36173designed to interface @value{GDBN} to graphical user interfaces or other
36174similar programs which want to interact with @value{GDBN} at a
922fbb7b
AC
36175relatively high level.
36176
d3e8051b 36177The annotation mechanism has largely been superseded by @sc{gdb/mi}
086432e2
AC
36178(@pxref{GDB/MI}).
36179
922fbb7b
AC
36180@ignore
36181This is Edition @value{EDITION}, @value{DATE}.
36182@end ignore
36183
36184@menu
36185* Annotations Overview:: What annotations are; the general syntax.
9e6c4bd5 36186* Server Prefix:: Issuing a command without affecting user state.
922fbb7b
AC
36187* Prompting:: Annotations marking @value{GDBN}'s need for input.
36188* Errors:: Annotations for error messages.
922fbb7b
AC
36189* Invalidation:: Some annotations describe things now invalid.
36190* Annotations for Running::
36191 Whether the program is running, how it stopped, etc.
36192* Source Annotations:: Annotations describing source code.
922fbb7b
AC
36193@end menu
36194
36195@node Annotations Overview
36196@section What is an Annotation?
36197@cindex annotations
36198
922fbb7b
AC
36199Annotations start with a newline character, two @samp{control-z}
36200characters, and the name of the annotation. If there is no additional
36201information associated with this annotation, the name of the annotation
36202is followed immediately by a newline. If there is additional
36203information, the name of the annotation is followed by a space, the
36204additional information, and a newline. The additional information
36205cannot contain newline characters.
36206
36207Any output not beginning with a newline and two @samp{control-z}
36208characters denotes literal output from @value{GDBN}. Currently there is
36209no need for @value{GDBN} to output a newline followed by two
36210@samp{control-z} characters, but if there was such a need, the
36211annotations could be extended with an @samp{escape} annotation which
36212means those three characters as output.
36213
086432e2
AC
36214The annotation @var{level}, which is specified using the
36215@option{--annotate} command line option (@pxref{Mode Options}), controls
36216how much information @value{GDBN} prints together with its prompt,
36217values of expressions, source lines, and other types of output. Level 0
d3e8051b 36218is for no annotations, level 1 is for use when @value{GDBN} is run as a
086432e2
AC
36219subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
36220for programs that control @value{GDBN}, and level 2 annotations have
36221been made obsolete (@pxref{Limitations, , Limitations of the Annotation
09d4efe1
EZ
36222Interface, annotate, GDB's Obsolete Annotations}).
36223
36224@table @code
36225@kindex set annotate
36226@item set annotate @var{level}
e09f16f9 36227The @value{GDBN} command @code{set annotate} sets the level of
09d4efe1 36228annotations to the specified @var{level}.
9c16f35a
EZ
36229
36230@item show annotate
36231@kindex show annotate
36232Show the current annotation level.
09d4efe1
EZ
36233@end table
36234
36235This chapter describes level 3 annotations.
086432e2 36236
922fbb7b
AC
36237A simple example of starting up @value{GDBN} with annotations is:
36238
36239@smallexample
086432e2
AC
36240$ @kbd{gdb --annotate=3}
36241GNU gdb 6.0
36242Copyright 2003 Free Software Foundation, Inc.
922fbb7b
AC
36243GDB is free software, covered by the GNU General Public License,
36244and you are welcome to change it and/or distribute copies of it
36245under certain conditions.
36246Type "show copying" to see the conditions.
36247There is absolutely no warranty for GDB. Type "show warranty"
36248for details.
086432e2 36249This GDB was configured as "i386-pc-linux-gnu"
922fbb7b
AC
36250
36251^Z^Zpre-prompt
f7dc1244 36252(@value{GDBP})
922fbb7b 36253^Z^Zprompt
086432e2 36254@kbd{quit}
922fbb7b
AC
36255
36256^Z^Zpost-prompt
b383017d 36257$
922fbb7b
AC
36258@end smallexample
36259
36260Here @samp{quit} is input to @value{GDBN}; the rest is output from
36261@value{GDBN}. The three lines beginning @samp{^Z^Z} (where @samp{^Z}
36262denotes a @samp{control-z} character) are annotations; the rest is
36263output from @value{GDBN}.
36264
9e6c4bd5
NR
36265@node Server Prefix
36266@section The Server Prefix
36267@cindex server prefix
36268
36269If you prefix a command with @samp{server } then it will not affect
36270the command history, nor will it affect @value{GDBN}'s notion of which
36271command to repeat if @key{RET} is pressed on a line by itself. This
36272means that commands can be run behind a user's back by a front-end in
36273a transparent manner.
36274
d837706a
NR
36275The @code{server } prefix does not affect the recording of values into
36276the value history; to print a value without recording it into the
36277value history, use the @code{output} command instead of the
36278@code{print} command.
36279
36280Using this prefix also disables confirmation requests
36281(@pxref{confirmation requests}).
9e6c4bd5 36282
922fbb7b
AC
36283@node Prompting
36284@section Annotation for @value{GDBN} Input
36285
36286@cindex annotations for prompts
36287When @value{GDBN} prompts for input, it annotates this fact so it is possible
36288to know when to send output, when the output from a given command is
36289over, etc.
36290
36291Different kinds of input each have a different @dfn{input type}. Each
36292input type has three annotations: a @code{pre-} annotation, which
36293denotes the beginning of any prompt which is being output, a plain
36294annotation, which denotes the end of the prompt, and then a @code{post-}
36295annotation which denotes the end of any echo which may (or may not) be
36296associated with the input. For example, the @code{prompt} input type
36297features the following annotations:
36298
36299@smallexample
36300^Z^Zpre-prompt
36301^Z^Zprompt
36302^Z^Zpost-prompt
36303@end smallexample
36304
36305The input types are
36306
36307@table @code
e5ac9b53
EZ
36308@findex pre-prompt annotation
36309@findex prompt annotation
36310@findex post-prompt annotation
922fbb7b
AC
36311@item prompt
36312When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
36313
e5ac9b53
EZ
36314@findex pre-commands annotation
36315@findex commands annotation
36316@findex post-commands annotation
922fbb7b
AC
36317@item commands
36318When @value{GDBN} prompts for a set of commands, like in the @code{commands}
36319command. The annotations are repeated for each command which is input.
36320
e5ac9b53
EZ
36321@findex pre-overload-choice annotation
36322@findex overload-choice annotation
36323@findex post-overload-choice annotation
922fbb7b
AC
36324@item overload-choice
36325When @value{GDBN} wants the user to select between various overloaded functions.
36326
e5ac9b53
EZ
36327@findex pre-query annotation
36328@findex query annotation
36329@findex post-query annotation
922fbb7b
AC
36330@item query
36331When @value{GDBN} wants the user to confirm a potentially dangerous operation.
36332
e5ac9b53
EZ
36333@findex pre-prompt-for-continue annotation
36334@findex prompt-for-continue annotation
36335@findex post-prompt-for-continue annotation
922fbb7b
AC
36336@item prompt-for-continue
36337When @value{GDBN} is asking the user to press return to continue. Note: Don't
36338expect this to work well; instead use @code{set height 0} to disable
36339prompting. This is because the counting of lines is buggy in the
36340presence of annotations.
36341@end table
36342
36343@node Errors
36344@section Errors
36345@cindex annotations for errors, warnings and interrupts
36346
e5ac9b53 36347@findex quit annotation
922fbb7b
AC
36348@smallexample
36349^Z^Zquit
36350@end smallexample
36351
36352This annotation occurs right before @value{GDBN} responds to an interrupt.
36353
e5ac9b53 36354@findex error annotation
922fbb7b
AC
36355@smallexample
36356^Z^Zerror
36357@end smallexample
36358
36359This annotation occurs right before @value{GDBN} responds to an error.
36360
36361Quit and error annotations indicate that any annotations which @value{GDBN} was
36362in the middle of may end abruptly. For example, if a
36363@code{value-history-begin} annotation is followed by a @code{error}, one
36364cannot expect to receive the matching @code{value-history-end}. One
36365cannot expect not to receive it either, however; an error annotation
36366does not necessarily mean that @value{GDBN} is immediately returning all the way
36367to the top level.
36368
e5ac9b53 36369@findex error-begin annotation
922fbb7b
AC
36370A quit or error annotation may be preceded by
36371
36372@smallexample
36373^Z^Zerror-begin
36374@end smallexample
36375
36376Any output between that and the quit or error annotation is the error
36377message.
36378
36379Warning messages are not yet annotated.
36380@c If we want to change that, need to fix warning(), type_error(),
36381@c range_error(), and possibly other places.
36382
922fbb7b
AC
36383@node Invalidation
36384@section Invalidation Notices
36385
36386@cindex annotations for invalidation messages
36387The following annotations say that certain pieces of state may have
36388changed.
36389
36390@table @code
e5ac9b53 36391@findex frames-invalid annotation
922fbb7b
AC
36392@item ^Z^Zframes-invalid
36393
36394The frames (for example, output from the @code{backtrace} command) may
36395have changed.
36396
e5ac9b53 36397@findex breakpoints-invalid annotation
922fbb7b
AC
36398@item ^Z^Zbreakpoints-invalid
36399
36400The breakpoints may have changed. For example, the user just added or
36401deleted a breakpoint.
36402@end table
36403
36404@node Annotations for Running
36405@section Running the Program
36406@cindex annotations for running programs
36407
e5ac9b53
EZ
36408@findex starting annotation
36409@findex stopping annotation
922fbb7b 36410When the program starts executing due to a @value{GDBN} command such as
b383017d 36411@code{step} or @code{continue},
922fbb7b
AC
36412
36413@smallexample
36414^Z^Zstarting
36415@end smallexample
36416
b383017d 36417is output. When the program stops,
922fbb7b
AC
36418
36419@smallexample
36420^Z^Zstopped
36421@end smallexample
36422
36423is output. Before the @code{stopped} annotation, a variety of
36424annotations describe how the program stopped.
36425
36426@table @code
e5ac9b53 36427@findex exited annotation
922fbb7b
AC
36428@item ^Z^Zexited @var{exit-status}
36429The program exited, and @var{exit-status} is the exit status (zero for
36430successful exit, otherwise nonzero).
36431
e5ac9b53
EZ
36432@findex signalled annotation
36433@findex signal-name annotation
36434@findex signal-name-end annotation
36435@findex signal-string annotation
36436@findex signal-string-end annotation
922fbb7b
AC
36437@item ^Z^Zsignalled
36438The program exited with a signal. After the @code{^Z^Zsignalled}, the
36439annotation continues:
36440
36441@smallexample
36442@var{intro-text}
36443^Z^Zsignal-name
36444@var{name}
36445^Z^Zsignal-name-end
36446@var{middle-text}
36447^Z^Zsignal-string
36448@var{string}
36449^Z^Zsignal-string-end
36450@var{end-text}
36451@end smallexample
36452
36453@noindent
36454where @var{name} is the name of the signal, such as @code{SIGILL} or
36455@code{SIGSEGV}, and @var{string} is the explanation of the signal, such
697aa1b7 36456as @code{Illegal Instruction} or @code{Segmentation fault}. The arguments
922fbb7b
AC
36457@var{intro-text}, @var{middle-text}, and @var{end-text} are for the
36458user's benefit and have no particular format.
36459
e5ac9b53 36460@findex signal annotation
922fbb7b
AC
36461@item ^Z^Zsignal
36462The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
36463just saying that the program received the signal, not that it was
36464terminated with it.
36465
e5ac9b53 36466@findex breakpoint annotation
922fbb7b
AC
36467@item ^Z^Zbreakpoint @var{number}
36468The program hit breakpoint number @var{number}.
36469
e5ac9b53 36470@findex watchpoint annotation
922fbb7b
AC
36471@item ^Z^Zwatchpoint @var{number}
36472The program hit watchpoint number @var{number}.
36473@end table
36474
36475@node Source Annotations
36476@section Displaying Source
36477@cindex annotations for source display
36478
e5ac9b53 36479@findex source annotation
922fbb7b
AC
36480The following annotation is used instead of displaying source code:
36481
36482@smallexample
36483^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
36484@end smallexample
36485
36486where @var{filename} is an absolute file name indicating which source
36487file, @var{line} is the line number within that file (where 1 is the
36488first line in the file), @var{character} is the character position
36489within the file (where 0 is the first character in the file) (for most
36490debug formats this will necessarily point to the beginning of a line),
36491@var{middle} is @samp{middle} if @var{addr} is in the middle of the
36492line, or @samp{beg} if @var{addr} is at the beginning of the line, and
36493@var{addr} is the address in the target program associated with the
697aa1b7 36494source which is being displayed. The @var{addr} is in the form @samp{0x}
922fbb7b
AC
36495followed by one or more lowercase hex digits (note that this does not
36496depend on the language).
36497
4efc6507
DE
36498@node JIT Interface
36499@chapter JIT Compilation Interface
36500@cindex just-in-time compilation
36501@cindex JIT compilation interface
36502
36503This chapter documents @value{GDBN}'s @dfn{just-in-time} (JIT) compilation
36504interface. A JIT compiler is a program or library that generates native
36505executable code at runtime and executes it, usually in order to achieve good
36506performance while maintaining platform independence.
36507
36508Programs that use JIT compilation are normally difficult to debug because
36509portions of their code are generated at runtime, instead of being loaded from
36510object files, which is where @value{GDBN} normally finds the program's symbols
36511and debug information. In order to debug programs that use JIT compilation,
36512@value{GDBN} has an interface that allows the program to register in-memory
36513symbol files with @value{GDBN} at runtime.
36514
36515If you are using @value{GDBN} to debug a program that uses this interface, then
36516it should work transparently so long as you have not stripped the binary. If
36517you are developing a JIT compiler, then the interface is documented in the rest
36518of this chapter. At this time, the only known client of this interface is the
36519LLVM JIT.
36520
36521Broadly speaking, the JIT interface mirrors the dynamic loader interface. The
36522JIT compiler communicates with @value{GDBN} by writing data into a global
6b92c0d3 36523variable and calling a function at a well-known symbol. When @value{GDBN}
4efc6507
DE
36524attaches, it reads a linked list of symbol files from the global variable to
36525find existing code, and puts a breakpoint in the function so that it can find
36526out about additional code.
36527
36528@menu
36529* Declarations:: Relevant C struct declarations
36530* Registering Code:: Steps to register code
36531* Unregistering Code:: Steps to unregister code
f85b53f8 36532* Custom Debug Info:: Emit debug information in a custom format
4efc6507
DE
36533@end menu
36534
36535@node Declarations
36536@section JIT Declarations
36537
36538These are the relevant struct declarations that a C program should include to
36539implement the interface:
36540
36541@smallexample
36542typedef enum
36543@{
36544 JIT_NOACTION = 0,
36545 JIT_REGISTER_FN,
36546 JIT_UNREGISTER_FN
36547@} jit_actions_t;
36548
36549struct jit_code_entry
36550@{
36551 struct jit_code_entry *next_entry;
36552 struct jit_code_entry *prev_entry;
36553 const char *symfile_addr;
36554 uint64_t symfile_size;
36555@};
36556
36557struct jit_descriptor
36558@{
36559 uint32_t version;
36560 /* This type should be jit_actions_t, but we use uint32_t
36561 to be explicit about the bitwidth. */
36562 uint32_t action_flag;
36563 struct jit_code_entry *relevant_entry;
36564 struct jit_code_entry *first_entry;
36565@};
36566
36567/* GDB puts a breakpoint in this function. */
36568void __attribute__((noinline)) __jit_debug_register_code() @{ @};
36569
36570/* Make sure to specify the version statically, because the
36571 debugger may check the version before we can set it. */
36572struct jit_descriptor __jit_debug_descriptor = @{ 1, 0, 0, 0 @};
36573@end smallexample
36574
36575If the JIT is multi-threaded, then it is important that the JIT synchronize any
36576modifications to this global data properly, which can easily be done by putting
36577a global mutex around modifications to these structures.
36578
36579@node Registering Code
36580@section Registering Code
36581
36582To register code with @value{GDBN}, the JIT should follow this protocol:
36583
36584@itemize @bullet
36585@item
36586Generate an object file in memory with symbols and other desired debug
36587information. The file must include the virtual addresses of the sections.
36588
36589@item
36590Create a code entry for the file, which gives the start and size of the symbol
36591file.
36592
36593@item
36594Add it to the linked list in the JIT descriptor.
36595
36596@item
36597Point the relevant_entry field of the descriptor at the entry.
36598
36599@item
36600Set @code{action_flag} to @code{JIT_REGISTER} and call
36601@code{__jit_debug_register_code}.
36602@end itemize
36603
36604When @value{GDBN} is attached and the breakpoint fires, @value{GDBN} uses the
36605@code{relevant_entry} pointer so it doesn't have to walk the list looking for
36606new code. However, the linked list must still be maintained in order to allow
36607@value{GDBN} to attach to a running process and still find the symbol files.
36608
36609@node Unregistering Code
36610@section Unregistering Code
36611
36612If code is freed, then the JIT should use the following protocol:
36613
36614@itemize @bullet
36615@item
36616Remove the code entry corresponding to the code from the linked list.
36617
36618@item
36619Point the @code{relevant_entry} field of the descriptor at the code entry.
36620
36621@item
36622Set @code{action_flag} to @code{JIT_UNREGISTER} and call
36623@code{__jit_debug_register_code}.
36624@end itemize
36625
36626If the JIT frees or recompiles code without unregistering it, then @value{GDBN}
36627and the JIT will leak the memory used for the associated symbol files.
36628
f85b53f8
SD
36629@node Custom Debug Info
36630@section Custom Debug Info
36631@cindex custom JIT debug info
36632@cindex JIT debug info reader
36633
36634Generating debug information in platform-native file formats (like ELF
36635or COFF) may be an overkill for JIT compilers; especially if all the
36636debug info is used for is displaying a meaningful backtrace. The
36637issue can be resolved by having the JIT writers decide on a debug info
36638format and also provide a reader that parses the debug info generated
36639by the JIT compiler. This section gives a brief overview on writing
36640such a parser. More specific details can be found in the source file
36641@file{gdb/jit-reader.in}, which is also installed as a header at
36642@file{@var{includedir}/gdb/jit-reader.h} for easy inclusion.
36643
36644The reader is implemented as a shared object (so this functionality is
36645not available on platforms which don't allow loading shared objects at
36646runtime). Two @value{GDBN} commands, @code{jit-reader-load} and
36647@code{jit-reader-unload} are provided, to be used to load and unload
36648the readers from a preconfigured directory. Once loaded, the shared
36649object is used the parse the debug information emitted by the JIT
36650compiler.
36651
36652@menu
36653* Using JIT Debug Info Readers:: How to use supplied readers correctly
36654* Writing JIT Debug Info Readers:: Creating a debug-info reader
36655@end menu
36656
36657@node Using JIT Debug Info Readers
36658@subsection Using JIT Debug Info Readers
36659@kindex jit-reader-load
36660@kindex jit-reader-unload
36661
36662Readers can be loaded and unloaded using the @code{jit-reader-load}
36663and @code{jit-reader-unload} commands.
36664
36665@table @code
c9fb1240 36666@item jit-reader-load @var{reader}
697aa1b7 36667Load the JIT reader named @var{reader}, which is a shared
c9fb1240
SD
36668object specified as either an absolute or a relative file name. In
36669the latter case, @value{GDBN} will try to load the reader from a
36670pre-configured directory, usually @file{@var{libdir}/gdb/} on a UNIX
36671system (here @var{libdir} is the system library directory, often
36672@file{/usr/local/lib}).
36673
36674Only one reader can be active at a time; trying to load a second
36675reader when one is already loaded will result in @value{GDBN}
36676reporting an error. A new JIT reader can be loaded by first unloading
36677the current one using @code{jit-reader-unload} and then invoking
36678@code{jit-reader-load}.
f85b53f8
SD
36679
36680@item jit-reader-unload
36681Unload the currently loaded JIT reader.
36682
36683@end table
36684
36685@node Writing JIT Debug Info Readers
36686@subsection Writing JIT Debug Info Readers
36687@cindex writing JIT debug info readers
36688
36689As mentioned, a reader is essentially a shared object conforming to a
36690certain ABI. This ABI is described in @file{jit-reader.h}.
36691
36692@file{jit-reader.h} defines the structures, macros and functions
36693required to write a reader. It is installed (along with
36694@value{GDBN}), in @file{@var{includedir}/gdb} where @var{includedir} is
36695the system include directory.
36696
36697Readers need to be released under a GPL compatible license. A reader
36698can be declared as released under such a license by placing the macro
36699@code{GDB_DECLARE_GPL_COMPATIBLE_READER} in a source file.
36700
36701The entry point for readers is the symbol @code{gdb_init_reader},
36702which is expected to be a function with the prototype
36703
36704@findex gdb_init_reader
36705@smallexample
36706extern struct gdb_reader_funcs *gdb_init_reader (void);
36707@end smallexample
36708
36709@cindex @code{struct gdb_reader_funcs}
36710
36711@code{struct gdb_reader_funcs} contains a set of pointers to callback
36712functions. These functions are executed to read the debug info
36713generated by the JIT compiler (@code{read}), to unwind stack frames
36714(@code{unwind}) and to create canonical frame IDs
27f7b2f6 36715(@code{get_frame_id}). It also has a callback that is called when the
f85b53f8
SD
36716reader is being unloaded (@code{destroy}). The struct looks like this
36717
36718@smallexample
36719struct gdb_reader_funcs
36720@{
36721 /* Must be set to GDB_READER_INTERFACE_VERSION. */
36722 int reader_version;
36723
36724 /* For use by the reader. */
36725 void *priv_data;
36726
36727 gdb_read_debug_info *read;
36728 gdb_unwind_frame *unwind;
36729 gdb_get_frame_id *get_frame_id;
36730 gdb_destroy_reader *destroy;
36731@};
36732@end smallexample
36733
36734@cindex @code{struct gdb_symbol_callbacks}
36735@cindex @code{struct gdb_unwind_callbacks}
36736
36737The callbacks are provided with another set of callbacks by
36738@value{GDBN} to do their job. For @code{read}, these callbacks are
36739passed in a @code{struct gdb_symbol_callbacks} and for @code{unwind}
36740and @code{get_frame_id}, in a @code{struct gdb_unwind_callbacks}.
36741@code{struct gdb_symbol_callbacks} has callbacks to create new object
36742files and new symbol tables inside those object files. @code{struct
36743gdb_unwind_callbacks} has callbacks to read registers off the current
36744frame and to write out the values of the registers in the previous
36745frame. Both have a callback (@code{target_read}) to read bytes off the
36746target's address space.
36747
d1feda86
YQ
36748@node In-Process Agent
36749@chapter In-Process Agent
36750@cindex debugging agent
36751The traditional debugging model is conceptually low-speed, but works fine,
36752because most bugs can be reproduced in debugging-mode execution. However,
36753as multi-core or many-core processors are becoming mainstream, and
36754multi-threaded programs become more and more popular, there should be more
36755and more bugs that only manifest themselves at normal-mode execution, for
36756example, thread races, because debugger's interference with the program's
36757timing may conceal the bugs. On the other hand, in some applications,
36758it is not feasible for the debugger to interrupt the program's execution
36759long enough for the developer to learn anything helpful about its behavior.
36760If the program's correctness depends on its real-time behavior, delays
36761introduced by a debugger might cause the program to fail, even when the
36762code itself is correct. It is useful to be able to observe the program's
36763behavior without interrupting it.
36764
36765Therefore, traditional debugging model is too intrusive to reproduce
36766some bugs. In order to reduce the interference with the program, we can
36767reduce the number of operations performed by debugger. The
36768@dfn{In-Process Agent}, a shared library, is running within the same
36769process with inferior, and is able to perform some debugging operations
36770itself. As a result, debugger is only involved when necessary, and
36771performance of debugging can be improved accordingly. Note that
36772interference with program can be reduced but can't be removed completely,
36773because the in-process agent will still stop or slow down the program.
36774
36775The in-process agent can interpret and execute Agent Expressions
36776(@pxref{Agent Expressions}) during performing debugging operations. The
36777agent expressions can be used for different purposes, such as collecting
36778data in tracepoints, and condition evaluation in breakpoints.
36779
36780@anchor{Control Agent}
36781You can control whether the in-process agent is used as an aid for
36782debugging with the following commands:
36783
36784@table @code
36785@kindex set agent on
36786@item set agent on
36787Causes the in-process agent to perform some operations on behalf of the
36788debugger. Just which operations requested by the user will be done
36789by the in-process agent depends on the its capabilities. For example,
36790if you request to evaluate breakpoint conditions in the in-process agent,
36791and the in-process agent has such capability as well, then breakpoint
36792conditions will be evaluated in the in-process agent.
36793
36794@kindex set agent off
36795@item set agent off
36796Disables execution of debugging operations by the in-process agent. All
36797of the operations will be performed by @value{GDBN}.
36798
36799@kindex show agent
36800@item show agent
36801Display the current setting of execution of debugging operations by
36802the in-process agent.
36803@end table
36804
16bdd41f
YQ
36805@menu
36806* In-Process Agent Protocol::
36807@end menu
36808
36809@node In-Process Agent Protocol
36810@section In-Process Agent Protocol
36811@cindex in-process agent protocol
36812
36813The in-process agent is able to communicate with both @value{GDBN} and
36814GDBserver (@pxref{In-Process Agent}). This section documents the protocol
36815used for communications between @value{GDBN} or GDBserver and the IPA.
36816In general, @value{GDBN} or GDBserver sends commands
36817(@pxref{IPA Protocol Commands}) and data to in-process agent, and then
36818in-process agent replies back with the return result of the command, or
36819some other information. The data sent to in-process agent is composed
36820of primitive data types, such as 4-byte or 8-byte type, and composite
36821types, which are called objects (@pxref{IPA Protocol Objects}).
36822
36823@menu
36824* IPA Protocol Objects::
36825* IPA Protocol Commands::
36826@end menu
36827
36828@node IPA Protocol Objects
36829@subsection IPA Protocol Objects
36830@cindex ipa protocol objects
36831
36832The commands sent to and results received from agent may contain some
36833complex data types called @dfn{objects}.
36834
36835The in-process agent is running on the same machine with @value{GDBN}
36836or GDBserver, so it doesn't have to handle as much differences between
36837two ends as remote protocol (@pxref{Remote Protocol}) tries to handle.
36838However, there are still some differences of two ends in two processes:
36839
36840@enumerate
36841@item
36842word size. On some 64-bit machines, @value{GDBN} or GDBserver can be
36843compiled as a 64-bit executable, while in-process agent is a 32-bit one.
36844@item
36845ABI. Some machines may have multiple types of ABI, @value{GDBN} or
36846GDBserver is compiled with one, and in-process agent is compiled with
36847the other one.
36848@end enumerate
36849
36850Here are the IPA Protocol Objects:
36851
36852@enumerate
36853@item
36854agent expression object. It represents an agent expression
36855(@pxref{Agent Expressions}).
36856@anchor{agent expression object}
36857@item
36858tracepoint action object. It represents a tracepoint action
36859(@pxref{Tracepoint Actions,,Tracepoint Action Lists}) to collect registers,
36860memory, static trace data and to evaluate expression.
36861@anchor{tracepoint action object}
36862@item
36863tracepoint object. It represents a tracepoint (@pxref{Tracepoints}).
36864@anchor{tracepoint object}
36865
36866@end enumerate
36867
36868The following table describes important attributes of each IPA protocol
36869object:
36870
36871@multitable @columnfractions .30 .20 .50
36872@headitem Name @tab Size @tab Description
36873@item @emph{agent expression object} @tab @tab
36874@item length @tab 4 @tab length of bytes code
36875@item byte code @tab @var{length} @tab contents of byte code
36876@item @emph{tracepoint action for collecting memory} @tab @tab
36877@item 'M' @tab 1 @tab type of tracepoint action
36878@item addr @tab 8 @tab if @var{basereg} is @samp{-1}, @var{addr} is the
36879address of the lowest byte to collect, otherwise @var{addr} is the offset
36880of @var{basereg} for memory collecting.
36881@item len @tab 8 @tab length of memory for collecting
36882@item basereg @tab 4 @tab the register number containing the starting
36883memory address for collecting.
36884@item @emph{tracepoint action for collecting registers} @tab @tab
36885@item 'R' @tab 1 @tab type of tracepoint action
36886@item @emph{tracepoint action for collecting static trace data} @tab @tab
36887@item 'L' @tab 1 @tab type of tracepoint action
36888@item @emph{tracepoint action for expression evaluation} @tab @tab
36889@item 'X' @tab 1 @tab type of tracepoint action
36890@item agent expression @tab length of @tab @ref{agent expression object}
36891@item @emph{tracepoint object} @tab @tab
36892@item number @tab 4 @tab number of tracepoint
36893@item address @tab 8 @tab address of tracepoint inserted on
36894@item type @tab 4 @tab type of tracepoint
36895@item enabled @tab 1 @tab enable or disable of tracepoint
36896@item step_count @tab 8 @tab step
36897@item pass_count @tab 8 @tab pass
36898@item numactions @tab 4 @tab number of tracepoint actions
36899@item hit count @tab 8 @tab hit count
36900@item trace frame usage @tab 8 @tab trace frame usage
36901@item compiled_cond @tab 8 @tab compiled condition
36902@item orig_size @tab 8 @tab orig size
36903@item condition @tab 4 if condition is NULL otherwise length of
36904@ref{agent expression object}
36905@tab zero if condition is NULL, otherwise is
36906@ref{agent expression object}
36907@item actions @tab variable
36908@tab numactions number of @ref{tracepoint action object}
36909@end multitable
36910
36911@node IPA Protocol Commands
36912@subsection IPA Protocol Commands
36913@cindex ipa protocol commands
36914
36915The spaces in each command are delimiters to ease reading this commands
36916specification. They don't exist in real commands.
36917
36918@table @samp
36919
36920@item FastTrace:@var{tracepoint_object} @var{gdb_jump_pad_head}
36921Installs a new fast tracepoint described by @var{tracepoint_object}
697aa1b7 36922(@pxref{tracepoint object}). The @var{gdb_jump_pad_head}, 8-byte long, is the
16bdd41f
YQ
36923head of @dfn{jumppad}, which is used to jump to data collection routine
36924in IPA finally.
36925
36926Replies:
36927@table @samp
36928@item OK @var{target_address} @var{gdb_jump_pad_head} @var{fjump_size} @var{fjump}
36929@var{target_address} is address of tracepoint in the inferior.
697aa1b7 36930The @var{gdb_jump_pad_head} is updated head of jumppad. Both of
16bdd41f 36931@var{target_address} and @var{gdb_jump_pad_head} are 8-byte long.
697aa1b7
EZ
36932The @var{fjump} contains a sequence of instructions jump to jumppad entry.
36933The @var{fjump_size}, 4-byte long, is the size of @var{fjump}.
16bdd41f
YQ
36934@item E @var{NN}
36935for an error
36936
36937@end table
36938
7255706c
YQ
36939@item close
36940Closes the in-process agent. This command is sent when @value{GDBN} or GDBserver
36941is about to kill inferiors.
36942
16bdd41f
YQ
36943@item qTfSTM
36944@xref{qTfSTM}.
36945@item qTsSTM
36946@xref{qTsSTM}.
36947@item qTSTMat
36948@xref{qTSTMat}.
36949@item probe_marker_at:@var{address}
36950Asks in-process agent to probe the marker at @var{address}.
36951
36952Replies:
36953@table @samp
36954@item E @var{NN}
36955for an error
36956@end table
36957@item unprobe_marker_at:@var{address}
36958Asks in-process agent to unprobe the marker at @var{address}.
36959@end table
36960
8e04817f
AC
36961@node GDB Bugs
36962@chapter Reporting Bugs in @value{GDBN}
36963@cindex bugs in @value{GDBN}
36964@cindex reporting bugs in @value{GDBN}
c906108c 36965
8e04817f 36966Your bug reports play an essential role in making @value{GDBN} reliable.
c906108c 36967
8e04817f
AC
36968Reporting a bug may help you by bringing a solution to your problem, or it
36969may not. But in any case the principal function of a bug report is to help
36970the entire community by making the next version of @value{GDBN} work better. Bug
36971reports are your contribution to the maintenance of @value{GDBN}.
c906108c 36972
8e04817f
AC
36973In order for a bug report to serve its purpose, you must include the
36974information that enables us to fix the bug.
c4555f82
SC
36975
36976@menu
8e04817f
AC
36977* Bug Criteria:: Have you found a bug?
36978* Bug Reporting:: How to report bugs
c4555f82
SC
36979@end menu
36980
8e04817f 36981@node Bug Criteria
79a6e687 36982@section Have You Found a Bug?
8e04817f 36983@cindex bug criteria
c4555f82 36984
8e04817f 36985If you are not sure whether you have found a bug, here are some guidelines:
c4555f82
SC
36986
36987@itemize @bullet
8e04817f
AC
36988@cindex fatal signal
36989@cindex debugger crash
36990@cindex crash of debugger
c4555f82 36991@item
8e04817f
AC
36992If the debugger gets a fatal signal, for any input whatever, that is a
36993@value{GDBN} bug. Reliable debuggers never crash.
36994
36995@cindex error on valid input
36996@item
36997If @value{GDBN} produces an error message for valid input, that is a
36998bug. (Note that if you're cross debugging, the problem may also be
36999somewhere in the connection to the target.)
c4555f82 37000
8e04817f 37001@cindex invalid input
c4555f82 37002@item
8e04817f
AC
37003If @value{GDBN} does not produce an error message for invalid input,
37004that is a bug. However, you should note that your idea of
37005``invalid input'' might be our idea of ``an extension'' or ``support
37006for traditional practice''.
37007
37008@item
37009If you are an experienced user of debugging tools, your suggestions
37010for improvement of @value{GDBN} are welcome in any case.
c4555f82
SC
37011@end itemize
37012
8e04817f 37013@node Bug Reporting
79a6e687 37014@section How to Report Bugs
8e04817f
AC
37015@cindex bug reports
37016@cindex @value{GDBN} bugs, reporting
37017
37018A number of companies and individuals offer support for @sc{gnu} products.
37019If you obtained @value{GDBN} from a support organization, we recommend you
37020contact that organization first.
37021
37022You can find contact information for many support companies and
37023individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
37024distribution.
37025@c should add a web page ref...
37026
c16158bc
JM
37027@ifset BUGURL
37028@ifset BUGURL_DEFAULT
129188f6 37029In any event, we also recommend that you submit bug reports for
d3e8051b 37030@value{GDBN}. The preferred method is to submit them directly using
129188f6
AC
37031@uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
37032page}. Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
37033be used.
8e04817f
AC
37034
37035@strong{Do not send bug reports to @samp{info-gdb}, or to
37036@samp{help-gdb}, or to any newsgroups.} Most users of @value{GDBN} do
37037not want to receive bug reports. Those that do have arranged to receive
37038@samp{bug-gdb}.
37039
37040The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
37041serves as a repeater. The mailing list and the newsgroup carry exactly
37042the same messages. Often people think of posting bug reports to the
37043newsgroup instead of mailing them. This appears to work, but it has one
37044problem which can be crucial: a newsgroup posting often lacks a mail
37045path back to the sender. Thus, if we need to ask for more information,
37046we may be unable to reach you. For this reason, it is better to send
37047bug reports to the mailing list.
c16158bc
JM
37048@end ifset
37049@ifclear BUGURL_DEFAULT
37050In any event, we also recommend that you submit bug reports for
37051@value{GDBN} to @value{BUGURL}.
37052@end ifclear
37053@end ifset
c4555f82 37054
8e04817f
AC
37055The fundamental principle of reporting bugs usefully is this:
37056@strong{report all the facts}. If you are not sure whether to state a
37057fact or leave it out, state it!
c4555f82 37058
8e04817f
AC
37059Often people omit facts because they think they know what causes the
37060problem and assume that some details do not matter. Thus, you might
37061assume that the name of the variable you use in an example does not matter.
37062Well, probably it does not, but one cannot be sure. Perhaps the bug is a
37063stray memory reference which happens to fetch from the location where that
37064name is stored in memory; perhaps, if the name were different, the contents
37065of that location would fool the debugger into doing the right thing despite
37066the bug. Play it safe and give a specific, complete example. That is the
37067easiest thing for you to do, and the most helpful.
c4555f82 37068
8e04817f
AC
37069Keep in mind that the purpose of a bug report is to enable us to fix the
37070bug. It may be that the bug has been reported previously, but neither
37071you nor we can know that unless your bug report is complete and
37072self-contained.
c4555f82 37073
8e04817f
AC
37074Sometimes people give a few sketchy facts and ask, ``Does this ring a
37075bell?'' Those bug reports are useless, and we urge everyone to
37076@emph{refuse to respond to them} except to chide the sender to report
37077bugs properly.
37078
37079To enable us to fix the bug, you should include all these things:
c4555f82
SC
37080
37081@itemize @bullet
37082@item
8e04817f
AC
37083The version of @value{GDBN}. @value{GDBN} announces it if you start
37084with no arguments; you can also print it at any time using @code{show
37085version}.
c4555f82 37086
8e04817f
AC
37087Without this, we will not know whether there is any point in looking for
37088the bug in the current version of @value{GDBN}.
c4555f82
SC
37089
37090@item
8e04817f
AC
37091The type of machine you are using, and the operating system name and
37092version number.
c4555f82 37093
6eaaf48b
EZ
37094@item
37095The details of the @value{GDBN} build-time configuration.
37096@value{GDBN} shows these details if you invoke it with the
37097@option{--configuration} command-line option, or if you type
37098@code{show configuration} at @value{GDBN}'s prompt.
37099
c4555f82 37100@item
c1468174 37101What compiler (and its version) was used to compile @value{GDBN}---e.g.@:
8e04817f 37102``@value{GCC}--2.8.1''.
c4555f82
SC
37103
37104@item
8e04817f 37105What compiler (and its version) was used to compile the program you are
c1468174 37106debugging---e.g.@: ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
3f94c067
BW
37107C Compiler''. For @value{NGCC}, you can say @kbd{@value{GCC} --version}
37108to get this information; for other compilers, see the documentation for
37109those compilers.
c4555f82 37110
8e04817f
AC
37111@item
37112The command arguments you gave the compiler to compile your example and
37113observe the bug. For example, did you use @samp{-O}? To guarantee
37114you will not omit something important, list them all. A copy of the
37115Makefile (or the output from make) is sufficient.
c4555f82 37116
8e04817f
AC
37117If we were to try to guess the arguments, we would probably guess wrong
37118and then we might not encounter the bug.
c4555f82 37119
8e04817f
AC
37120@item
37121A complete input script, and all necessary source files, that will
37122reproduce the bug.
c4555f82 37123
8e04817f
AC
37124@item
37125A description of what behavior you observe that you believe is
37126incorrect. For example, ``It gets a fatal signal.''
c4555f82 37127
8e04817f
AC
37128Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
37129will certainly notice it. But if the bug is incorrect output, we might
37130not notice unless it is glaringly wrong. You might as well not give us
37131a chance to make a mistake.
c4555f82 37132
8e04817f
AC
37133Even if the problem you experience is a fatal signal, you should still
37134say so explicitly. Suppose something strange is going on, such as, your
37135copy of @value{GDBN} is out of synch, or you have encountered a bug in
37136the C library on your system. (This has happened!) Your copy might
37137crash and ours would not. If you told us to expect a crash, then when
37138ours fails to crash, we would know that the bug was not happening for
37139us. If you had not told us to expect a crash, then we would not be able
37140to draw any conclusion from our observations.
c4555f82 37141
e0c07bf0
MC
37142@pindex script
37143@cindex recording a session script
37144To collect all this information, you can use a session recording program
37145such as @command{script}, which is available on many Unix systems.
37146Just run your @value{GDBN} session inside @command{script} and then
37147include the @file{typescript} file with your bug report.
37148
37149Another way to record a @value{GDBN} session is to run @value{GDBN}
37150inside Emacs and then save the entire buffer to a file.
37151
8e04817f
AC
37152@item
37153If you wish to suggest changes to the @value{GDBN} source, send us context
37154diffs. If you even discuss something in the @value{GDBN} source, refer to
37155it by context, not by line number.
c4555f82 37156
8e04817f
AC
37157The line numbers in our development sources will not match those in your
37158sources. Your line numbers would convey no useful information to us.
c4555f82 37159
8e04817f 37160@end itemize
c4555f82 37161
8e04817f 37162Here are some things that are not necessary:
c4555f82 37163
8e04817f
AC
37164@itemize @bullet
37165@item
37166A description of the envelope of the bug.
c4555f82 37167
8e04817f
AC
37168Often people who encounter a bug spend a lot of time investigating
37169which changes to the input file will make the bug go away and which
37170changes will not affect it.
c4555f82 37171
8e04817f
AC
37172This is often time consuming and not very useful, because the way we
37173will find the bug is by running a single example under the debugger
37174with breakpoints, not by pure deduction from a series of examples.
37175We recommend that you save your time for something else.
c4555f82 37176
8e04817f
AC
37177Of course, if you can find a simpler example to report @emph{instead}
37178of the original one, that is a convenience for us. Errors in the
37179output will be easier to spot, running under the debugger will take
37180less time, and so on.
c4555f82 37181
8e04817f
AC
37182However, simplification is not vital; if you do not want to do this,
37183report the bug anyway and send us the entire test case you used.
c4555f82 37184
8e04817f
AC
37185@item
37186A patch for the bug.
c4555f82 37187
8e04817f
AC
37188A patch for the bug does help us if it is a good one. But do not omit
37189the necessary information, such as the test case, on the assumption that
37190a patch is all we need. We might see problems with your patch and decide
37191to fix the problem another way, or we might not understand it at all.
c4555f82 37192
8e04817f
AC
37193Sometimes with a program as complicated as @value{GDBN} it is very hard to
37194construct an example that will make the program follow a certain path
37195through the code. If you do not send us the example, we will not be able
37196to construct one, so we will not be able to verify that the bug is fixed.
c4555f82 37197
8e04817f
AC
37198And if we cannot understand what bug you are trying to fix, or why your
37199patch should be an improvement, we will not install it. A test case will
37200help us to understand.
c4555f82 37201
8e04817f
AC
37202@item
37203A guess about what the bug is or what it depends on.
c4555f82 37204
8e04817f
AC
37205Such guesses are usually wrong. Even we cannot guess right about such
37206things without first using the debugger to find the facts.
37207@end itemize
c4555f82 37208
8e04817f
AC
37209@c The readline documentation is distributed with the readline code
37210@c and consists of the two following files:
cc88a640
JK
37211@c rluser.texi
37212@c hsuser.texi
8e04817f
AC
37213@c Use -I with makeinfo to point to the appropriate directory,
37214@c environment var TEXINPUTS with TeX.
39037522 37215@ifclear SYSTEM_READLINE
5bdf8622 37216@include rluser.texi
cc88a640 37217@include hsuser.texi
39037522 37218@end ifclear
c4555f82 37219
4ceed123
JB
37220@node In Memoriam
37221@appendix In Memoriam
37222
9ed350ad
JB
37223The @value{GDBN} project mourns the loss of the following long-time
37224contributors:
4ceed123
JB
37225
37226@table @code
37227@item Fred Fish
9ed350ad
JB
37228Fred was a long-standing contributor to @value{GDBN} (1991-2006), and
37229to Free Software in general. Outside of @value{GDBN}, he was known in
37230the Amiga world for his series of Fish Disks, and the GeekGadget project.
4ceed123
JB
37231
37232@item Michael Snyder
9ed350ad
JB
37233Michael was one of the Global Maintainers of the @value{GDBN} project,
37234with contributions recorded as early as 1996, until 2011. In addition
37235to his day to day participation, he was a large driving force behind
37236adding Reverse Debugging to @value{GDBN}.
4ceed123
JB
37237@end table
37238
37239Beyond their technical contributions to the project, they were also
37240enjoyable members of the Free Software Community. We will miss them.
c4555f82 37241
8e04817f
AC
37242@node Formatting Documentation
37243@appendix Formatting Documentation
c4555f82 37244
8e04817f
AC
37245@cindex @value{GDBN} reference card
37246@cindex reference card
37247The @value{GDBN} 4 release includes an already-formatted reference card, ready
37248for printing with PostScript or Ghostscript, in the @file{gdb}
37249subdirectory of the main source directory@footnote{In
37250@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
37251release.}. If you can use PostScript or Ghostscript with your printer,
37252you can print the reference card immediately with @file{refcard.ps}.
c4555f82 37253
8e04817f
AC
37254The release also includes the source for the reference card. You
37255can format it, using @TeX{}, by typing:
c4555f82 37256
474c8240 37257@smallexample
8e04817f 37258make refcard.dvi
474c8240 37259@end smallexample
c4555f82 37260
8e04817f
AC
37261The @value{GDBN} reference card is designed to print in @dfn{landscape}
37262mode on US ``letter'' size paper;
37263that is, on a sheet 11 inches wide by 8.5 inches
37264high. You will need to specify this form of printing as an option to
37265your @sc{dvi} output program.
c4555f82 37266
8e04817f 37267@cindex documentation
c4555f82 37268
8e04817f
AC
37269All the documentation for @value{GDBN} comes as part of the machine-readable
37270distribution. The documentation is written in Texinfo format, which is
37271a documentation system that uses a single source file to produce both
37272on-line information and a printed manual. You can use one of the Info
37273formatting commands to create the on-line version of the documentation
37274and @TeX{} (or @code{texi2roff}) to typeset the printed version.
c4555f82 37275
8e04817f
AC
37276@value{GDBN} includes an already formatted copy of the on-line Info
37277version of this manual in the @file{gdb} subdirectory. The main Info
37278file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
37279subordinate files matching @samp{gdb.info*} in the same directory. If
37280necessary, you can print out these files, or read them with any editor;
37281but they are easier to read using the @code{info} subsystem in @sc{gnu}
37282Emacs or the standalone @code{info} program, available as part of the
37283@sc{gnu} Texinfo distribution.
c4555f82 37284
8e04817f
AC
37285If you want to format these Info files yourself, you need one of the
37286Info formatting programs, such as @code{texinfo-format-buffer} or
37287@code{makeinfo}.
c4555f82 37288
8e04817f
AC
37289If you have @code{makeinfo} installed, and are in the top level
37290@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
37291version @value{GDBVN}), you can make the Info file by typing:
c4555f82 37292
474c8240 37293@smallexample
8e04817f
AC
37294cd gdb
37295make gdb.info
474c8240 37296@end smallexample
c4555f82 37297
8e04817f
AC
37298If you want to typeset and print copies of this manual, you need @TeX{},
37299a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
37300Texinfo definitions file.
c4555f82 37301
8e04817f
AC
37302@TeX{} is a typesetting program; it does not print files directly, but
37303produces output files called @sc{dvi} files. To print a typeset
37304document, you need a program to print @sc{dvi} files. If your system
37305has @TeX{} installed, chances are it has such a program. The precise
37306command to use depends on your system; @kbd{lpr -d} is common; another
37307(for PostScript devices) is @kbd{dvips}. The @sc{dvi} print command may
37308require a file name without any extension or a @samp{.dvi} extension.
c4555f82 37309
8e04817f
AC
37310@TeX{} also requires a macro definitions file called
37311@file{texinfo.tex}. This file tells @TeX{} how to typeset a document
37312written in Texinfo format. On its own, @TeX{} cannot either read or
37313typeset a Texinfo file. @file{texinfo.tex} is distributed with GDB
37314and is located in the @file{gdb-@var{version-number}/texinfo}
37315directory.
c4555f82 37316
8e04817f 37317If you have @TeX{} and a @sc{dvi} printer program installed, you can
d3e8051b 37318typeset and print this manual. First switch to the @file{gdb}
8e04817f
AC
37319subdirectory of the main source directory (for example, to
37320@file{gdb-@value{GDBVN}/gdb}) and type:
c4555f82 37321
474c8240 37322@smallexample
8e04817f 37323make gdb.dvi
474c8240 37324@end smallexample
c4555f82 37325
8e04817f 37326Then give @file{gdb.dvi} to your @sc{dvi} printing program.
c4555f82 37327
8e04817f
AC
37328@node Installing GDB
37329@appendix Installing @value{GDBN}
8e04817f 37330@cindex installation
c4555f82 37331
7fa2210b
DJ
37332@menu
37333* Requirements:: Requirements for building @value{GDBN}
db2e3e2e 37334* Running Configure:: Invoking the @value{GDBN} @file{configure} script
7fa2210b
DJ
37335* Separate Objdir:: Compiling @value{GDBN} in another directory
37336* Config Names:: Specifying names for hosts and targets
37337* Configure Options:: Summary of options for configure
098b41a6 37338* System-wide configuration:: Having a system-wide init file
7fa2210b
DJ
37339@end menu
37340
37341@node Requirements
79a6e687 37342@section Requirements for Building @value{GDBN}
7fa2210b
DJ
37343@cindex building @value{GDBN}, requirements for
37344
37345Building @value{GDBN} requires various tools and packages to be available.
37346Other packages will be used only if they are found.
37347
79a6e687 37348@heading Tools/Packages Necessary for Building @value{GDBN}
7fa2210b 37349@table @asis
7f0bd420
TT
37350@item C@t{++}11 compiler
37351@value{GDBN} is written in C@t{++}11. It should be buildable with any
37352recent C@t{++}11 compiler, e.g.@: GCC.
7fa2210b 37353
7f0bd420
TT
37354@item GNU make
37355@value{GDBN}'s build system relies on features only found in the GNU
37356make program. Other variants of @code{make} will not work.
7fa2210b
DJ
37357@end table
37358
79a6e687 37359@heading Tools/Packages Optional for Building @value{GDBN}
7fa2210b
DJ
37360@table @asis
37361@item Expat
123dc839 37362@anchor{Expat}
7fa2210b
DJ
37363@value{GDBN} can use the Expat XML parsing library. This library may be
37364included with your operating system distribution; if it is not, you
37365can get the latest version from @url{http://expat.sourceforge.net}.
db2e3e2e 37366The @file{configure} script will search for this library in several
7fa2210b
DJ
37367standard locations; if it is installed in an unusual path, you can
37368use the @option{--with-libexpat-prefix} option to specify its location.
37369
9cceb671
DJ
37370Expat is used for:
37371
37372@itemize @bullet
37373@item
37374Remote protocol memory maps (@pxref{Memory Map Format})
37375@item
37376Target descriptions (@pxref{Target Descriptions})
37377@item
2268b414
JK
37378Remote shared library lists (@xref{Library List Format},
37379or alternatively @pxref{Library List Format for SVR4 Targets})
9cceb671
DJ
37380@item
37381MS-Windows shared libraries (@pxref{Shared Libraries})
b3b9301e
PA
37382@item
37383Traceframe info (@pxref{Traceframe Info Format})
2ae8c8e7 37384@item
f4abbc16
MM
37385Branch trace (@pxref{Branch Trace Format},
37386@pxref{Branch Trace Configuration Format})
9cceb671 37387@end itemize
7fa2210b 37388
7f0bd420
TT
37389@item Guile
37390@value{GDBN} can be scripted using GNU Guile. @xref{Guile}. By
37391default, @value{GDBN} will be compiled if the Guile libraries are
37392installed and are found by @file{configure}. You can use the
37393@code{--with-guile} option to request Guile, and pass either the Guile
37394version number or the file name of the relevant @code{pkg-config}
37395program to choose a particular version of Guile.
37396
37397@item iconv
37398@value{GDBN}'s features related to character sets (@pxref{Character
37399Sets}) require a functioning @code{iconv} implementation. If you are
37400on a GNU system, then this is provided by the GNU C Library. Some
37401other systems also provide a working @code{iconv}.
37402
37403If @value{GDBN} is using the @code{iconv} program which is installed
37404in a non-standard place, you will need to tell @value{GDBN} where to
37405find it. This is done with @option{--with-iconv-bin} which specifies
37406the directory that contains the @code{iconv} program. This program is
37407run in order to make a list of the available character sets.
37408
37409On systems without @code{iconv}, you can install GNU Libiconv. If
37410Libiconv is installed in a standard place, @value{GDBN} will
37411automatically use it if it is needed. If you have previously
37412installed Libiconv in a non-standard place, you can use the
37413@option{--with-libiconv-prefix} option to @file{configure}.
37414
37415@value{GDBN}'s top-level @file{configure} and @file{Makefile} will
37416arrange to build Libiconv if a directory named @file{libiconv} appears
37417in the top-most source directory. If Libiconv is built this way, and
37418if the operating system does not provide a suitable @code{iconv}
37419implementation, then the just-built library will automatically be used
37420by @value{GDBN}. One easy way to set this up is to download GNU
37421Libiconv, unpack it inside the top-level directory of the @value{GDBN}
37422source tree, and then rename the directory holding the Libiconv source
37423code to @samp{libiconv}.
37424
37425@item lzma
37426@value{GDBN} can support debugging sections that are compressed with
37427the LZMA library. @xref{MiniDebugInfo}. If this library is not
37428included with your operating system, you can find it in the xz package
37429at @url{http://tukaani.org/xz/}. If the LZMA library is available in
37430the usual place, then the @file{configure} script will use it
37431automatically. If it is installed in an unusual path, you can use the
37432@option{--with-lzma-prefix} option to specify its location.
37433
2400729e
UW
37434@item MPFR
37435@anchor{MPFR}
37436@value{GDBN} can use the GNU MPFR multiple-precision floating-point
37437library. This library may be included with your operating system
37438distribution; if it is not, you can get the latest version from
37439@url{http://www.mpfr.org}. The @file{configure} script will search
37440for this library in several standard locations; if it is installed
37441in an unusual path, you can use the @option{--with-libmpfr-prefix}
37442option to specify its location.
37443
37444GNU MPFR is used to emulate target floating-point arithmetic during
37445expression evaluation when the target uses different floating-point
37446formats than the host. If GNU MPFR it is not available, @value{GDBN}
37447will fall back to using host floating-point arithmetic.
37448
7f0bd420
TT
37449@item Python
37450@value{GDBN} can be scripted using Python language. @xref{Python}.
37451By default, @value{GDBN} will be compiled if the Python libraries are
37452installed and are found by @file{configure}. You can use the
37453@code{--with-python} option to request Python, and pass either the
37454file name of the relevant @code{python} executable, or the name of the
37455directory in which Python is installed, to choose a particular
37456installation of Python.
37457
31fffb02
CS
37458@item zlib
37459@cindex compressed debug sections
37460@value{GDBN} will use the @samp{zlib} library, if available, to read
37461compressed debug sections. Some linkers, such as GNU gold, are capable
37462of producing binaries with compressed debug sections. If @value{GDBN}
37463is compiled with @samp{zlib}, it will be able to read the debug
37464information in such binaries.
37465
37466The @samp{zlib} library is likely included with your operating system
37467distribution; if it is not, you can get the latest version from
37468@url{http://zlib.net}.
7fa2210b
DJ
37469@end table
37470
37471@node Running Configure
db2e3e2e 37472@section Invoking the @value{GDBN} @file{configure} Script
7fa2210b 37473@cindex configuring @value{GDBN}
db2e3e2e 37474@value{GDBN} comes with a @file{configure} script that automates the process
8e04817f
AC
37475of preparing @value{GDBN} for installation; you can then use @code{make} to
37476build the @code{gdb} program.
37477@iftex
37478@c irrelevant in info file; it's as current as the code it lives with.
37479@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
37480look at the @file{README} file in the sources; we may have improved the
37481installation procedures since publishing this manual.}
37482@end iftex
c4555f82 37483
8e04817f
AC
37484The @value{GDBN} distribution includes all the source code you need for
37485@value{GDBN} in a single directory, whose name is usually composed by
37486appending the version number to @samp{gdb}.
c4555f82 37487
8e04817f
AC
37488For example, the @value{GDBN} version @value{GDBVN} distribution is in the
37489@file{gdb-@value{GDBVN}} directory. That directory contains:
c4555f82 37490
8e04817f
AC
37491@table @code
37492@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
37493script for configuring @value{GDBN} and all its supporting libraries
c4555f82 37494
8e04817f
AC
37495@item gdb-@value{GDBVN}/gdb
37496the source specific to @value{GDBN} itself
c4555f82 37497
8e04817f
AC
37498@item gdb-@value{GDBVN}/bfd
37499source for the Binary File Descriptor library
c906108c 37500
8e04817f
AC
37501@item gdb-@value{GDBVN}/include
37502@sc{gnu} include files
c906108c 37503
8e04817f
AC
37504@item gdb-@value{GDBVN}/libiberty
37505source for the @samp{-liberty} free software library
c906108c 37506
8e04817f
AC
37507@item gdb-@value{GDBVN}/opcodes
37508source for the library of opcode tables and disassemblers
c906108c 37509
8e04817f
AC
37510@item gdb-@value{GDBVN}/readline
37511source for the @sc{gnu} command-line interface
8e04817f 37512@end table
c906108c 37513
7f0bd420
TT
37514There may be other subdirectories as well.
37515
db2e3e2e 37516The simplest way to configure and build @value{GDBN} is to run @file{configure}
8e04817f
AC
37517from the @file{gdb-@var{version-number}} source directory, which in
37518this example is the @file{gdb-@value{GDBVN}} directory.
c906108c 37519
8e04817f 37520First switch to the @file{gdb-@var{version-number}} source directory
db2e3e2e 37521if you are not already in it; then run @file{configure}. Pass the
8e04817f
AC
37522identifier for the platform on which @value{GDBN} will run as an
37523argument.
c906108c 37524
8e04817f 37525For example:
c906108c 37526
474c8240 37527@smallexample
8e04817f 37528cd gdb-@value{GDBVN}
7f0bd420 37529./configure
8e04817f 37530make
474c8240 37531@end smallexample
c906108c 37532
7f0bd420
TT
37533Running @samp{configure} and then running @code{make} builds the
37534included supporting libraries, then @code{gdb} itself. The configured
37535source files, and the binaries, are left in the corresponding source
37536directories.
c906108c 37537
8e04817f 37538@need 750
db2e3e2e 37539@file{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
8e04817f
AC
37540system does not recognize this automatically when you run a different
37541shell, you may need to run @code{sh} on it explicitly:
c906108c 37542
474c8240 37543@smallexample
7f0bd420 37544sh configure
474c8240 37545@end smallexample
c906108c 37546
db2e3e2e 37547You should run the @file{configure} script from the top directory in the
94e91d6d 37548source tree, the @file{gdb-@var{version-number}} directory. If you run
db2e3e2e 37549@file{configure} from one of the subdirectories, you will configure only
94e91d6d 37550that subdirectory. That is usually not what you want. In particular,
db2e3e2e 37551if you run the first @file{configure} from the @file{gdb} subdirectory
94e91d6d
MC
37552of the @file{gdb-@var{version-number}} directory, you will omit the
37553configuration of @file{bfd}, @file{readline}, and other sibling
37554directories of the @file{gdb} subdirectory. This leads to build errors
37555about missing include files such as @file{bfd/bfd.h}.
c906108c 37556
7f0bd420
TT
37557You can install @code{@value{GDBN}} anywhere. The best way to do this
37558is to pass the @code{--prefix} option to @code{configure}, and then
37559install it with @code{make install}.
c906108c 37560
8e04817f 37561@node Separate Objdir
79a6e687 37562@section Compiling @value{GDBN} in Another Directory
c906108c 37563
8e04817f
AC
37564If you want to run @value{GDBN} versions for several host or target machines,
37565you need a different @code{gdb} compiled for each combination of
db2e3e2e 37566host and target. @file{configure} is designed to make this easy by
8e04817f
AC
37567allowing you to generate each configuration in a separate subdirectory,
37568rather than in the source directory. If your @code{make} program
37569handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
37570@code{make} in each of these directories builds the @code{gdb}
37571program specified there.
c906108c 37572
db2e3e2e 37573To build @code{gdb} in a separate directory, run @file{configure}
8e04817f 37574with the @samp{--srcdir} option to specify where to find the source.
db2e3e2e
BW
37575(You also need to specify a path to find @file{configure}
37576itself from your working directory. If the path to @file{configure}
8e04817f
AC
37577would be the same as the argument to @samp{--srcdir}, you can leave out
37578the @samp{--srcdir} option; it is assumed.)
c906108c 37579
8e04817f
AC
37580For example, with version @value{GDBVN}, you can build @value{GDBN} in a
37581separate directory for a Sun 4 like this:
c906108c 37582
474c8240 37583@smallexample
8e04817f
AC
37584@group
37585cd gdb-@value{GDBVN}
37586mkdir ../gdb-sun4
37587cd ../gdb-sun4
7f0bd420 37588../gdb-@value{GDBVN}/configure
8e04817f
AC
37589make
37590@end group
474c8240 37591@end smallexample
c906108c 37592
db2e3e2e 37593When @file{configure} builds a configuration using a remote source
8e04817f
AC
37594directory, it creates a tree for the binaries with the same structure
37595(and using the same names) as the tree under the source directory. In
37596the example, you'd find the Sun 4 library @file{libiberty.a} in the
37597directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
37598@file{gdb-sun4/gdb}.
c906108c 37599
94e91d6d
MC
37600Make sure that your path to the @file{configure} script has just one
37601instance of @file{gdb} in it. If your path to @file{configure} looks
37602like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
37603one subdirectory of @value{GDBN}, not the whole package. This leads to
37604build errors about missing include files such as @file{bfd/bfd.h}.
37605
8e04817f
AC
37606One popular reason to build several @value{GDBN} configurations in separate
37607directories is to configure @value{GDBN} for cross-compiling (where
37608@value{GDBN} runs on one machine---the @dfn{host}---while debugging
37609programs that run on another machine---the @dfn{target}).
37610You specify a cross-debugging target by
db2e3e2e 37611giving the @samp{--target=@var{target}} option to @file{configure}.
c906108c 37612
8e04817f
AC
37613When you run @code{make} to build a program or library, you must run
37614it in a configured directory---whatever directory you were in when you
db2e3e2e 37615called @file{configure} (or one of its subdirectories).
c906108c 37616
db2e3e2e 37617The @code{Makefile} that @file{configure} generates in each source
8e04817f
AC
37618directory also runs recursively. If you type @code{make} in a source
37619directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
37620directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
37621will build all the required libraries, and then build GDB.
c906108c 37622
8e04817f
AC
37623When you have multiple hosts or targets configured in separate
37624directories, you can run @code{make} on them in parallel (for example,
37625if they are NFS-mounted on each of the hosts); they will not interfere
37626with each other.
c906108c 37627
8e04817f 37628@node Config Names
79a6e687 37629@section Specifying Names for Hosts and Targets
c906108c 37630
db2e3e2e 37631The specifications used for hosts and targets in the @file{configure}
8e04817f
AC
37632script are based on a three-part naming scheme, but some short predefined
37633aliases are also supported. The full naming scheme encodes three pieces
37634of information in the following pattern:
c906108c 37635
474c8240 37636@smallexample
8e04817f 37637@var{architecture}-@var{vendor}-@var{os}
474c8240 37638@end smallexample
c906108c 37639
8e04817f
AC
37640For example, you can use the alias @code{sun4} as a @var{host} argument,
37641or as the value for @var{target} in a @code{--target=@var{target}}
37642option. The equivalent full name is @samp{sparc-sun-sunos4}.
c906108c 37643
db2e3e2e 37644The @file{configure} script accompanying @value{GDBN} does not provide
8e04817f 37645any query facility to list all supported host and target names or
db2e3e2e 37646aliases. @file{configure} calls the Bourne shell script
8e04817f
AC
37647@code{config.sub} to map abbreviations to full names; you can read the
37648script, if you wish, or you can use it to test your guesses on
37649abbreviations---for example:
c906108c 37650
8e04817f
AC
37651@smallexample
37652% sh config.sub i386-linux
37653i386-pc-linux-gnu
37654% sh config.sub alpha-linux
37655alpha-unknown-linux-gnu
37656% sh config.sub hp9k700
37657hppa1.1-hp-hpux
37658% sh config.sub sun4
37659sparc-sun-sunos4.1.1
37660% sh config.sub sun3
37661m68k-sun-sunos4.1.1
37662% sh config.sub i986v
37663Invalid configuration `i986v': machine `i986v' not recognized
37664@end smallexample
c906108c 37665
8e04817f
AC
37666@noindent
37667@code{config.sub} is also distributed in the @value{GDBN} source
37668directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
d700128c 37669
8e04817f 37670@node Configure Options
db2e3e2e 37671@section @file{configure} Options
c906108c 37672
db2e3e2e 37673Here is a summary of the @file{configure} options and arguments that
7f0bd420
TT
37674are most often useful for building @value{GDBN}. @file{configure}
37675also has several other options not listed here. @inforef{Running
37676configure scripts,,autoconf.info}, for a full
37677explanation of @file{configure}.
c906108c 37678
474c8240 37679@smallexample
8e04817f
AC
37680configure @r{[}--help@r{]}
37681 @r{[}--prefix=@var{dir}@r{]}
37682 @r{[}--exec-prefix=@var{dir}@r{]}
37683 @r{[}--srcdir=@var{dirname}@r{]}
8e04817f 37684 @r{[}--target=@var{target}@r{]}
474c8240 37685@end smallexample
c906108c 37686
8e04817f
AC
37687@noindent
37688You may introduce options with a single @samp{-} rather than
37689@samp{--} if you prefer; but you may abbreviate option names if you use
37690@samp{--}.
c906108c 37691
8e04817f
AC
37692@table @code
37693@item --help
db2e3e2e 37694Display a quick summary of how to invoke @file{configure}.
c906108c 37695
8e04817f
AC
37696@item --prefix=@var{dir}
37697Configure the source to install programs and files under directory
37698@file{@var{dir}}.
c906108c 37699
8e04817f
AC
37700@item --exec-prefix=@var{dir}
37701Configure the source to install programs under directory
37702@file{@var{dir}}.
c906108c 37703
8e04817f
AC
37704@c avoid splitting the warning from the explanation:
37705@need 2000
37706@item --srcdir=@var{dirname}
8e04817f
AC
37707Use this option to make configurations in directories separate from the
37708@value{GDBN} source directories. Among other things, you can use this to
37709build (or maintain) several configurations simultaneously, in separate
db2e3e2e 37710directories. @file{configure} writes configuration-specific files in
8e04817f 37711the current directory, but arranges for them to use the source in the
db2e3e2e 37712directory @var{dirname}. @file{configure} creates directories under
8e04817f
AC
37713the working directory in parallel to the source directories below
37714@var{dirname}.
c906108c 37715
8e04817f
AC
37716@item --target=@var{target}
37717Configure @value{GDBN} for cross-debugging programs running on the specified
37718@var{target}. Without this option, @value{GDBN} is configured to debug
37719programs that run on the same machine (@var{host}) as @value{GDBN} itself.
c906108c 37720
a95746f9
TT
37721There is no convenient way to generate a list of all available
37722targets. Also see the @code{--enable-targets} option, below.
8e04817f 37723@end table
c906108c 37724
a95746f9
TT
37725There are many other options that are specific to @value{GDBN}. This
37726lists just the most common ones; there are some very specialized
37727options not described here.
37728
37729@table @code
37730@item --enable-targets=@r{[}@var{target}@r{]}@dots{}
37731@itemx --enable-targets=all
37732Configure @value{GDBN} for cross-debugging programs running on the
37733specified list of targets. The special value @samp{all} configures
37734@value{GDBN} for debugging programs running on any target it supports.
37735
37736@item --with-gdb-datadir=@var{path}
37737Set the @value{GDBN}-specific data directory. @value{GDBN} will look
37738here for certain supporting files or scripts. This defaults to the
6b92c0d3 37739@file{gdb} subdirectory of @samp{datadir} (which can be set using
a95746f9
TT
37740@code{--datadir}).
37741
37742@item --with-relocated-sources=@var{dir}
37743Sets up the default source path substitution rule so that directory
37744names recorded in debug information will be automatically adjusted for
37745any directory under @var{dir}. @var{dir} should be a subdirectory of
37746@value{GDBN}'s configured prefix, the one mentioned in the
37747@code{--prefix} or @code{--exec-prefix} options to configure. This
37748option is useful if GDB is supposed to be moved to a different place
37749after it is built.
37750
37751@item --enable-64-bit-bfd
37752Enable 64-bit support in BFD on 32-bit hosts.
37753
37754@item --disable-gdbmi
37755Build @value{GDBN} without the GDB/MI machine interface
37756(@pxref{GDB/MI}).
37757
37758@item --enable-tui
37759Build @value{GDBN} with the text-mode full-screen user interface
37760(TUI). Requires a curses library (ncurses and cursesX are also
37761supported).
37762
37763@item --with-curses
37764Use the curses library instead of the termcap library, for text-mode
37765terminal operations.
37766
37767@item --with-libunwind-ia64
37768Use the libunwind library for unwinding function call stack on ia64
37769target platforms. See http://www.nongnu.org/libunwind/index.html for
37770details.
37771
37772@item --with-system-readline
37773Use the readline library installed on the host, rather than the
86c6b807
TT
37774library supplied as part of @value{GDBN}. Readline 7 or newer is
37775required; this is enforced by the build system.
a95746f9
TT
37776
37777@item --with-system-zlib
37778Use the zlib library installed on the host, rather than the library
37779supplied as part of @value{GDBN}.
37780
37781@item --with-expat
37782Build @value{GDBN} with Expat, a library for XML parsing. (Done by
37783default if libexpat is installed and found at configure time.) This
37784library is used to read XML files supplied with @value{GDBN}. If it
37785is unavailable, some features, such as remote protocol memory maps,
37786target descriptions, and shared library lists, that are based on XML
37787files, will not be available in @value{GDBN}. If your host does not
37788have libexpat installed, you can get the latest version from
37789`http://expat.sourceforge.net'.
37790
37791@item --with-libiconv-prefix@r{[}=@var{dir}@r{]}
37792
37793Build @value{GDBN} with GNU libiconv, a character set encoding
37794conversion library. This is not done by default, as on GNU systems
37795the @code{iconv} that is built in to the C library is sufficient. If
37796your host does not have a working @code{iconv}, you can get the latest
37797version of GNU iconv from `https://www.gnu.org/software/libiconv/'.
37798
37799@value{GDBN}'s build system also supports building GNU libiconv as
37800part of the overall build. @xref{Requirements}.
37801
37802@item --with-lzma
37803Build @value{GDBN} with LZMA, a compression library. (Done by default
37804if liblzma is installed and found at configure time.) LZMA is used by
37805@value{GDBN}'s "mini debuginfo" feature, which is only useful on
37806platforms using the ELF object file format. If your host does not
37807have liblzma installed, you can get the latest version from
37808`https://tukaani.org/xz/'.
37809
37810@item --with-mpfr
37811Build @value{GDBN} with GNU MPFR, a library for multiple-precision
37812floating-point computation with correct rounding. (Done by default if
37813GNU MPFR is installed and found at configure time.) This library is
37814used to emulate target floating-point arithmetic during expression
37815evaluation when the target uses different floating-point formats than
37816the host. If GNU MPFR is not available, @value{GDBN} will fall back
37817to using host floating-point arithmetic. If your host does not have
37818GNU MPFR installed, you can get the latest version from
37819`http://www.mpfr.org'.
37820
37821@item --with-python@r{[}=@var{python}@r{]}
37822Build @value{GDBN} with Python scripting support. (Done by default if
37823libpython is present and found at configure time.) Python makes
37824@value{GDBN} scripting much more powerful than the restricted CLI
37825scripting language. If your host does not have Python installed, you
37826can find it on `http://www.python.org/download/'. The oldest version
2c3fc25d 37827of Python supported by GDB is 2.6. The optional argument @var{python}
a95746f9
TT
37828is used to find the Python headers and libraries. It can be either
37829the name of a Python executable, or the name of the directory in which
37830Python is installed.
37831
37832@item --with-guile[=GUILE]'
37833Build @value{GDBN} with GNU Guile scripting support. (Done by default
37834if libguile is present and found at configure time.) If your host
37835does not have Guile installed, you can find it at
37836`https://www.gnu.org/software/guile/'. The optional argument GUILE
37837can be a version number, which will cause @code{configure} to try to
37838use that version of Guile; or the file name of a @code{pkg-config}
37839executable, which will be queried to find the information needed to
37840compile and link against Guile.
37841
37842@item --without-included-regex
37843Don't use the regex library included with @value{GDBN} (as part of the
37844libiberty library). This is the default on hosts with version 2 of
37845the GNU C library.
37846
37847@item --with-sysroot=@var{dir}
37848Use @var{dir} as the default system root directory for libraries whose
37849file names begin with @file{/lib}' or @file{/usr/lib'}. (The value of
37850@var{dir} can be modified at run time by using the @command{set
37851sysroot} command.) If @var{dir} is under the @value{GDBN} configured
37852prefix (set with @code{--prefix} or @code{--exec-prefix options}, the
37853default system root will be automatically adjusted if and when
37854@value{GDBN} is moved to a different location.
37855
37856@item --with-system-gdbinit=@var{file}
37857Configure @value{GDBN} to automatically load a system-wide init file.
37858@var{file} should be an absolute file name. If @var{file} is in a
37859directory under the configured prefix, and @value{GDBN} is moved to
37860another location after being built, the location of the system-wide
37861init file will be adjusted accordingly.
37862
ed2a2229
CB
37863@item --with-system-gdbinit-dir=@var{directory}
37864Configure @value{GDBN} to automatically load init files from a
37865system-wide directory. @var{directory} should be an absolute directory
37866name. If @var{directory} is in a directory under the configured
37867prefix, and @value{GDBN} is moved to another location after being
37868built, the location of the system-wide init directory will be
37869adjusted accordingly.
37870
a95746f9
TT
37871@item --enable-build-warnings
37872When building the @value{GDBN} sources, ask the compiler to warn about
37873any code which looks even vaguely suspicious. It passes many
37874different warning flags, depending on the exact version of the
37875compiler you are using.
37876
37877@item --enable-werror
37878Treat compiler warnings as werrors. It adds the @code{-Werror} flag
37879to the compiler, which will fail the compilation if the compiler
37880outputs any warning messages.
f35d5ade
TT
37881
37882@item --enable-ubsan
eff98030
TT
37883Enable the GCC undefined behavior sanitizer. This is disabled by
37884default, but passing @code{--enable-ubsan=yes} or
37885@code{--enable-ubsan=auto} to @code{configure} will enable it. The
37886undefined behavior sanitizer checks for C@t{++} undefined behavior.
37887It has a performance cost, so if you are looking at @value{GDBN}'s
37888performance, you should disable it. The undefined behavior sanitizer
37889was first introduced in GCC 4.9.
a95746f9 37890@end table
c906108c 37891
098b41a6
JG
37892@node System-wide configuration
37893@section System-wide configuration and settings
37894@cindex system-wide init file
37895
ed2a2229
CB
37896@value{GDBN} can be configured to have a system-wide init file and a
37897system-wide init file directory; this file and files in that directory
37898(if they have a recognized file extension) will be read and executed at
37899startup (@pxref{Startup, , What @value{GDBN} does during startup}).
098b41a6 37900
ed2a2229 37901Here are the corresponding configure options:
098b41a6
JG
37902
37903@table @code
37904@item --with-system-gdbinit=@var{file}
37905Specify that the default location of the system-wide init file is
37906@var{file}.
ed2a2229
CB
37907@item --with-system-gdbinit-dir=@var{directory}
37908Specify that the default location of the system-wide init file directory
37909is @var{directory}.
098b41a6
JG
37910@end table
37911
37912If @value{GDBN} has been configured with the option @option{--prefix=$prefix},
ed2a2229 37913they may be subject to relocation. Two possible cases:
098b41a6
JG
37914
37915@itemize @bullet
37916@item
ed2a2229 37917If the default location of this init file/directory contains @file{$prefix},
098b41a6
JG
37918it will be subject to relocation. Suppose that the configure options
37919are @option{--prefix=$prefix --with-system-gdbinit=$prefix/etc/gdbinit};
37920if @value{GDBN} is moved from @file{$prefix} to @file{$install}, the system
37921init file is looked for as @file{$install/etc/gdbinit} instead of
37922@file{$prefix/etc/gdbinit}.
37923
37924@item
37925By contrast, if the default location does not contain the prefix,
37926it will not be relocated. E.g.@: if @value{GDBN} has been configured with
37927@option{--prefix=/usr/local --with-system-gdbinit=/usr/share/gdb/gdbinit},
37928then @value{GDBN} will always look for @file{/usr/share/gdb/gdbinit},
37929wherever @value{GDBN} is installed.
37930@end itemize
37931
e64e0392
DE
37932If the configured location of the system-wide init file (as given by the
37933@option{--with-system-gdbinit} option at configure time) is in the
37934data-directory (as specified by @option{--with-gdb-datadir} at configure
37935time) or in one of its subdirectories, then @value{GDBN} will look for the
37936system-wide init file in the directory specified by the
37937@option{--data-directory} command-line option.
37938Note that the system-wide init file is only read once, during @value{GDBN}
37939initialization. If the data-directory is changed after @value{GDBN} has
37940started with the @code{set data-directory} command, the file will not be
37941reread.
37942
ed2a2229
CB
37943This applies similarly to the system-wide directory specified in
37944@option{--with-system-gdbinit-dir}.
37945
37946Any supported scripting language can be used for these init files, as long
37947as the file extension matches the scripting language. To be interpreted
37948as regular @value{GDBN} commands, the files needs to have a @file{.gdb}
37949extension.
37950
5901af59
JB
37951@menu
37952* System-wide Configuration Scripts:: Installed System-wide Configuration Scripts
37953@end menu
37954
37955@node System-wide Configuration Scripts
0201faac
JB
37956@subsection Installed System-wide Configuration Scripts
37957@cindex system-wide configuration scripts
37958
37959The @file{system-gdbinit} directory, located inside the data-directory
37960(as specified by @option{--with-gdb-datadir} at configure time) contains
37961a number of scripts which can be used as system-wide init files. To
37962automatically source those scripts at startup, @value{GDBN} should be
37963configured with @option{--with-system-gdbinit}. Otherwise, any user
37964should be able to source them by hand as needed.
37965
37966The following scripts are currently available:
37967@itemize @bullet
37968
37969@item @file{elinos.py}
37970@pindex elinos.py
37971@cindex ELinOS system-wide configuration script
37972This script is useful when debugging a program on an ELinOS target.
37973It takes advantage of the environment variables defined in a standard
37974ELinOS environment in order to determine the location of the system
37975shared libraries, and then sets the @samp{solib-absolute-prefix}
37976and @samp{solib-search-path} variables appropriately.
37977
37978@item @file{wrs-linux.py}
37979@pindex wrs-linux.py
37980@cindex Wind River Linux system-wide configuration script
37981This script is useful when debugging a program on a target running
37982Wind River Linux. It expects the @env{ENV_PREFIX} to be set to
37983the host-side sysroot used by the target system.
37984
37985@end itemize
37986
8e04817f
AC
37987@node Maintenance Commands
37988@appendix Maintenance Commands
37989@cindex maintenance commands
37990@cindex internal commands
c906108c 37991
8e04817f 37992In addition to commands intended for @value{GDBN} users, @value{GDBN}
09d4efe1
EZ
37993includes a number of commands intended for @value{GDBN} developers,
37994that are not documented elsewhere in this manual. These commands are
da316a69
EZ
37995provided here for reference. (For commands that turn on debugging
37996messages, see @ref{Debugging Output}.)
c906108c 37997
8e04817f 37998@table @code
09d4efe1 37999@kindex maint agent
782b2b07 38000@kindex maint agent-eval
f77cc5f0
HZ
38001@item maint agent @r{[}-at @var{location}@r{,}@r{]} @var{expression}
38002@itemx maint agent-eval @r{[}-at @var{location}@r{,}@r{]} @var{expression}
09d4efe1
EZ
38003Translate the given @var{expression} into remote agent bytecodes.
38004This command is useful for debugging the Agent Expression mechanism
782b2b07
SS
38005(@pxref{Agent Expressions}). The @samp{agent} version produces an
38006expression useful for data collection, such as by tracepoints, while
38007@samp{maint agent-eval} produces an expression that evaluates directly
38008to a result. For instance, a collection expression for @code{globa +
38009globb} will include bytecodes to record four bytes of memory at each
38010of the addresses of @code{globa} and @code{globb}, while discarding
38011the result of the addition, while an evaluation expression will do the
38012addition and return the sum.
f77cc5f0
HZ
38013If @code{-at} is given, generate remote agent bytecode for @var{location}.
38014If not, generate remote agent bytecode for current frame PC address.
09d4efe1 38015
d3ce09f5
SS
38016@kindex maint agent-printf
38017@item maint agent-printf @var{format},@var{expr},...
38018Translate the given format string and list of argument expressions
38019into remote agent bytecodes and display them as a disassembled list.
38020This command is useful for debugging the agent version of dynamic
6dd24dfa 38021printf (@pxref{Dynamic Printf}).
d3ce09f5 38022
8e04817f
AC
38023@kindex maint info breakpoints
38024@item @anchor{maint info breakpoints}maint info breakpoints
38025Using the same format as @samp{info breakpoints}, display both the
38026breakpoints you've set explicitly, and those @value{GDBN} is using for
38027internal purposes. Internal breakpoints are shown with negative
38028breakpoint numbers. The type column identifies what kind of breakpoint
38029is shown:
c906108c 38030
8e04817f
AC
38031@table @code
38032@item breakpoint
38033Normal, explicitly set breakpoint.
c906108c 38034
8e04817f
AC
38035@item watchpoint
38036Normal, explicitly set watchpoint.
c906108c 38037
8e04817f
AC
38038@item longjmp
38039Internal breakpoint, used to handle correctly stepping through
38040@code{longjmp} calls.
c906108c 38041
8e04817f
AC
38042@item longjmp resume
38043Internal breakpoint at the target of a @code{longjmp}.
c906108c 38044
8e04817f
AC
38045@item until
38046Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
c906108c 38047
8e04817f
AC
38048@item finish
38049Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
c906108c 38050
8e04817f
AC
38051@item shlib events
38052Shared library events.
c906108c 38053
8e04817f 38054@end table
c906108c 38055
b0627500
MM
38056@kindex maint info btrace
38057@item maint info btrace
38058Pint information about raw branch tracing data.
38059
38060@kindex maint btrace packet-history
38061@item maint btrace packet-history
38062Print the raw branch trace packets that are used to compute the
38063execution history for the @samp{record btrace} command. Both the
38064information and the format in which it is printed depend on the btrace
38065recording format.
38066
38067@table @code
38068@item bts
38069For the BTS recording format, print a list of blocks of sequential
38070code. For each block, the following information is printed:
38071
38072@table @asis
38073@item Block number
38074Newer blocks have higher numbers. The oldest block has number zero.
38075@item Lowest @samp{PC}
38076@item Highest @samp{PC}
38077@end table
38078
38079@item pt
bc504a31
PA
38080For the Intel Processor Trace recording format, print a list of
38081Intel Processor Trace packets. For each packet, the following
b0627500
MM
38082information is printed:
38083
38084@table @asis
38085@item Packet number
38086Newer packets have higher numbers. The oldest packet has number zero.
38087@item Trace offset
38088The packet's offset in the trace stream.
38089@item Packet opcode and payload
38090@end table
38091@end table
38092
38093@kindex maint btrace clear-packet-history
38094@item maint btrace clear-packet-history
38095Discards the cached packet history printed by the @samp{maint btrace
38096packet-history} command. The history will be computed again when
38097needed.
38098
38099@kindex maint btrace clear
38100@item maint btrace clear
38101Discard the branch trace data. The data will be fetched anew and the
38102branch trace will be recomputed when needed.
38103
38104This implicitly truncates the branch trace to a single branch trace
38105buffer. When updating branch trace incrementally, the branch trace
38106available to @value{GDBN} may be bigger than a single branch trace
38107buffer.
38108
38109@kindex maint set btrace pt skip-pad
38110@item maint set btrace pt skip-pad
38111@kindex maint show btrace pt skip-pad
38112@item maint show btrace pt skip-pad
38113Control whether @value{GDBN} will skip PAD packets when computing the
38114packet history.
38115
fff08868
HZ
38116@kindex set displaced-stepping
38117@kindex show displaced-stepping
237fc4c9
PA
38118@cindex displaced stepping support
38119@cindex out-of-line single-stepping
fff08868
HZ
38120@item set displaced-stepping
38121@itemx show displaced-stepping
237fc4c9 38122Control whether or not @value{GDBN} will do @dfn{displaced stepping}
fff08868
HZ
38123if the target supports it. Displaced stepping is a way to single-step
38124over breakpoints without removing them from the inferior, by executing
38125an out-of-line copy of the instruction that was originally at the
38126breakpoint location. It is also known as out-of-line single-stepping.
38127
38128@table @code
38129@item set displaced-stepping on
38130If the target architecture supports it, @value{GDBN} will use
38131displaced stepping to step over breakpoints.
38132
38133@item set displaced-stepping off
38134@value{GDBN} will not use displaced stepping to step over breakpoints,
38135even if such is supported by the target architecture.
38136
38137@cindex non-stop mode, and @samp{set displaced-stepping}
38138@item set displaced-stepping auto
38139This is the default mode. @value{GDBN} will use displaced stepping
38140only if non-stop mode is active (@pxref{Non-Stop Mode}) and the target
38141architecture supports displaced stepping.
38142@end table
237fc4c9 38143
7d0c9981
DE
38144@kindex maint check-psymtabs
38145@item maint check-psymtabs
38146Check the consistency of currently expanded psymtabs versus symtabs.
38147Use this to check, for example, whether a symbol is in one but not the other.
38148
09d4efe1
EZ
38149@kindex maint check-symtabs
38150@item maint check-symtabs
7d0c9981
DE
38151Check the consistency of currently expanded symtabs.
38152
38153@kindex maint expand-symtabs
38154@item maint expand-symtabs [@var{regexp}]
38155Expand symbol tables.
38156If @var{regexp} is specified, only expand symbol tables for file
38157names matching @var{regexp}.
09d4efe1 38158
992c7d70
GB
38159@kindex maint set catch-demangler-crashes
38160@kindex maint show catch-demangler-crashes
38161@cindex demangler crashes
38162@item maint set catch-demangler-crashes [on|off]
38163@itemx maint show catch-demangler-crashes
38164Control whether @value{GDBN} should attempt to catch crashes in the
38165symbol name demangler. The default is to attempt to catch crashes.
38166If enabled, the first time a crash is caught, a core file is created,
38167the offending symbol is displayed and the user is presented with the
38168option to terminate the current session.
38169
09d4efe1
EZ
38170@kindex maint cplus first_component
38171@item maint cplus first_component @var{name}
38172Print the first C@t{++} class/namespace component of @var{name}.
38173
38174@kindex maint cplus namespace
38175@item maint cplus namespace
38176Print the list of possible C@t{++} namespaces.
38177
09d4efe1
EZ
38178@kindex maint deprecate
38179@kindex maint undeprecate
38180@cindex deprecated commands
38181@item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
38182@itemx maint undeprecate @var{command}
38183Deprecate or undeprecate the named @var{command}. Deprecated commands
38184cause @value{GDBN} to issue a warning when you use them. The optional
38185argument @var{replacement} says which newer command should be used in
38186favor of the deprecated one; if it is given, @value{GDBN} will mention
38187the replacement as part of the warning.
38188
38189@kindex maint dump-me
38190@item maint dump-me
721c2651 38191@cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
09d4efe1 38192Cause a fatal signal in the debugger and force it to dump its core.
721c2651
EZ
38193This is supported only on systems which support aborting a program
38194with the @code{SIGQUIT} signal.
09d4efe1 38195
8d30a00d
AC
38196@kindex maint internal-error
38197@kindex maint internal-warning
57fcfb1b
GB
38198@kindex maint demangler-warning
38199@cindex demangler crashes
09d4efe1
EZ
38200@item maint internal-error @r{[}@var{message-text}@r{]}
38201@itemx maint internal-warning @r{[}@var{message-text}@r{]}
57fcfb1b
GB
38202@itemx maint demangler-warning @r{[}@var{message-text}@r{]}
38203
38204Cause @value{GDBN} to call the internal function @code{internal_error},
38205@code{internal_warning} or @code{demangler_warning} and hence behave
7ee67ee4 38206as though an internal problem has been detected. In addition to
57fcfb1b
GB
38207reporting the internal problem, these functions give the user the
38208opportunity to either quit @value{GDBN} or (for @code{internal_error}
38209and @code{internal_warning}) create a core file of the current
8d30a00d
AC
38210@value{GDBN} session.
38211
09d4efe1
EZ
38212These commands take an optional parameter @var{message-text} that is
38213used as the text of the error or warning message.
38214
d3e8051b 38215Here's an example of using @code{internal-error}:
09d4efe1 38216
8d30a00d 38217@smallexample
f7dc1244 38218(@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
8d30a00d
AC
38219@dots{}/maint.c:121: internal-error: testing, 1, 2
38220A problem internal to GDB has been detected. Further
38221debugging may prove unreliable.
38222Quit this debugging session? (y or n) @kbd{n}
38223Create a core file? (y or n) @kbd{n}
f7dc1244 38224(@value{GDBP})
8d30a00d
AC
38225@end smallexample
38226
3c16cced
PA
38227@cindex @value{GDBN} internal error
38228@cindex internal errors, control of @value{GDBN} behavior
57fcfb1b 38229@cindex demangler crashes
3c16cced
PA
38230
38231@kindex maint set internal-error
38232@kindex maint show internal-error
38233@kindex maint set internal-warning
38234@kindex maint show internal-warning
57fcfb1b
GB
38235@kindex maint set demangler-warning
38236@kindex maint show demangler-warning
3c16cced
PA
38237@item maint set internal-error @var{action} [ask|yes|no]
38238@itemx maint show internal-error @var{action}
38239@itemx maint set internal-warning @var{action} [ask|yes|no]
38240@itemx maint show internal-warning @var{action}
57fcfb1b
GB
38241@itemx maint set demangler-warning @var{action} [ask|yes|no]
38242@itemx maint show demangler-warning @var{action}
3c16cced
PA
38243When @value{GDBN} reports an internal problem (error or warning) it
38244gives the user the opportunity to both quit @value{GDBN} and create a
38245core file of the current @value{GDBN} session. These commands let you
38246override the default behaviour for each particular @var{action},
38247described in the table below.
38248
38249@table @samp
38250@item quit
38251You can specify that @value{GDBN} should always (yes) or never (no)
38252quit. The default is to ask the user what to do.
38253
38254@item corefile
38255You can specify that @value{GDBN} should always (yes) or never (no)
57fcfb1b
GB
38256create a core file. The default is to ask the user what to do. Note
38257that there is no @code{corefile} option for @code{demangler-warning}:
38258demangler warnings always create a core file and this cannot be
38259disabled.
3c16cced
PA
38260@end table
38261
09d4efe1
EZ
38262@kindex maint packet
38263@item maint packet @var{text}
38264If @value{GDBN} is talking to an inferior via the serial protocol,
38265then this command sends the string @var{text} to the inferior, and
38266displays the response packet. @value{GDBN} supplies the initial
38267@samp{$} character, the terminating @samp{#} character, and the
38268checksum.
38269
38270@kindex maint print architecture
38271@item maint print architecture @r{[}@var{file}@r{]}
38272Print the entire architecture configuration. The optional argument
38273@var{file} names the file where the output goes.
8d30a00d 38274
8e2141c6 38275@kindex maint print c-tdesc @r{[}@var{file}@r{]}
81adfced 38276@item maint print c-tdesc
8e2141c6
YQ
38277Print the target description (@pxref{Target Descriptions}) as
38278a C source file. By default, the target description is for the current
38279target, but if the optional argument @var{file} is provided, that file
38280is used to produce the description. The @var{file} should be an XML
38281document, of the form described in @ref{Target Description Format}.
38282The created source file is built into @value{GDBN} when @value{GDBN} is
38283built again. This command is used by developers after they add or
38284modify XML target descriptions.
81adfced 38285
27d41eac
YQ
38286@kindex maint check xml-descriptions
38287@item maint check xml-descriptions @var{dir}
38288Check that the target descriptions dynamically created by @value{GDBN}
38289equal the descriptions created from XML files found in @var{dir}.
38290
41fc26a2 38291@anchor{maint check libthread-db}
5045b3d7
GB
38292@kindex maint check libthread-db
38293@item maint check libthread-db
38294Run integrity checks on the current inferior's thread debugging
38295library. This exercises all @code{libthread_db} functionality used by
38296@value{GDBN} on GNU/Linux systems, and by extension also exercises the
38297@code{proc_service} functions provided by @value{GDBN} that
38298@code{libthread_db} uses. Note that parts of the test may be skipped
38299on some platforms when debugging core files.
38300
00905d52
AC
38301@kindex maint print dummy-frames
38302@item maint print dummy-frames
00905d52
AC
38303Prints the contents of @value{GDBN}'s internal dummy-frame stack.
38304
38305@smallexample
f7dc1244 38306(@value{GDBP}) @kbd{b add}
00905d52 38307@dots{}
f7dc1244 38308(@value{GDBP}) @kbd{print add(2,3)}
00905d52
AC
38309Breakpoint 2, add (a=2, b=3) at @dots{}
3831058 return (a + b);
38311The program being debugged stopped while in a function called from GDB.
38312@dots{}
f7dc1244 38313(@value{GDBP}) @kbd{maint print dummy-frames}
b67a2c6f 383140xa8206d8: id=@{stack=0xbfffe734,code=0xbfffe73f,!special@}, ptid=process 9353
f7dc1244 38315(@value{GDBP})
00905d52
AC
38316@end smallexample
38317
38318Takes an optional file parameter.
38319
0680b120
AC
38320@kindex maint print registers
38321@kindex maint print raw-registers
38322@kindex maint print cooked-registers
617073a9 38323@kindex maint print register-groups
c21236dc 38324@kindex maint print remote-registers
09d4efe1
EZ
38325@item maint print registers @r{[}@var{file}@r{]}
38326@itemx maint print raw-registers @r{[}@var{file}@r{]}
38327@itemx maint print cooked-registers @r{[}@var{file}@r{]}
38328@itemx maint print register-groups @r{[}@var{file}@r{]}
c21236dc 38329@itemx maint print remote-registers @r{[}@var{file}@r{]}
0680b120
AC
38330Print @value{GDBN}'s internal register data structures.
38331
617073a9 38332The command @code{maint print raw-registers} includes the contents of
c21236dc
PA
38333the raw register cache; the command @code{maint print
38334cooked-registers} includes the (cooked) value of all registers,
38335including registers which aren't available on the target nor visible
38336to user; the command @code{maint print register-groups} includes the
38337groups that each register is a member of; and the command @code{maint
38338print remote-registers} includes the remote target's register numbers
0a7cfe2c 38339and offsets in the `G' packets.
0680b120 38340
09d4efe1
EZ
38341These commands take an optional parameter, a file name to which to
38342write the information.
0680b120 38343
617073a9 38344@kindex maint print reggroups
09d4efe1
EZ
38345@item maint print reggroups @r{[}@var{file}@r{]}
38346Print @value{GDBN}'s internal register group data structures. The
38347optional argument @var{file} tells to what file to write the
38348information.
617073a9 38349
09d4efe1 38350The register groups info looks like this:
617073a9
AC
38351
38352@smallexample
f7dc1244 38353(@value{GDBP}) @kbd{maint print reggroups}
b383017d
RM
38354 Group Type
38355 general user
38356 float user
38357 all user
38358 vector user
38359 system user
38360 save internal
38361 restore internal
617073a9
AC
38362@end smallexample
38363
09d4efe1
EZ
38364@kindex flushregs
38365@item flushregs
38366This command forces @value{GDBN} to flush its internal register cache.
38367
38368@kindex maint print objfiles
38369@cindex info for known object files
52e260a3
DE
38370@item maint print objfiles @r{[}@var{regexp}@r{]}
38371Print a dump of all known object files.
38372If @var{regexp} is specified, only print object files whose names
38373match @var{regexp}. For each object file, this command prints its name,
38374address in memory, and all of its psymtabs and symtabs.
09d4efe1 38375
f5b95c01
AA
38376@kindex maint print user-registers
38377@cindex user registers
38378@item maint print user-registers
38379List all currently available @dfn{user registers}. User registers
38380typically provide alternate names for actual hardware registers. They
38381include the four ``standard'' registers @code{$fp}, @code{$pc},
38382@code{$sp}, and @code{$ps}. @xref{standard registers}. User
38383registers can be used in expressions in the same way as the canonical
38384register names, but only the latter are listed by the @code{info
38385registers} and @code{maint print registers} commands.
38386
8a1ea21f
DE
38387@kindex maint print section-scripts
38388@cindex info for known .debug_gdb_scripts-loaded scripts
38389@item maint print section-scripts [@var{regexp}]
38390Print a dump of scripts specified in the @code{.debug_gdb_section} section.
38391If @var{regexp} is specified, only print scripts loaded by object files
38392matching @var{regexp}.
38393For each script, this command prints its name as specified in the objfile,
38394and the full path if known.
8e0583c8 38395@xref{dotdebug_gdb_scripts section}.
8a1ea21f 38396
09d4efe1
EZ
38397@kindex maint print statistics
38398@cindex bcache statistics
38399@item maint print statistics
38400This command prints, for each object file in the program, various data
38401about that object file followed by the byte cache (@dfn{bcache})
38402statistics for the object file. The objfile data includes the number
d3e8051b 38403of minimal, partial, full, and stabs symbols, the number of types
09d4efe1
EZ
38404defined by the objfile, the number of as yet unexpanded psym tables,
38405the number of line tables and string tables, and the amount of memory
38406used by the various tables. The bcache statistics include the counts,
38407sizes, and counts of duplicates of all and unique objects, max,
38408average, and median entry size, total memory used and its overhead and
38409savings, and various measures of the hash table size and chain
38410lengths.
38411
c7ba131e
JB
38412@kindex maint print target-stack
38413@cindex target stack description
38414@item maint print target-stack
38415A @dfn{target} is an interface between the debugger and a particular
38416kind of file or process. Targets can be stacked in @dfn{strata},
38417so that more than one target can potentially respond to a request.
38418In particular, memory accesses will walk down the stack of targets
38419until they find a target that is interested in handling that particular
38420address.
38421
38422This command prints a short description of each layer that was pushed on
38423the @dfn{target stack}, starting from the top layer down to the bottom one.
38424
09d4efe1
EZ
38425@kindex maint print type
38426@cindex type chain of a data type
38427@item maint print type @var{expr}
38428Print the type chain for a type specified by @var{expr}. The argument
38429can be either a type name or a symbol. If it is a symbol, the type of
38430that symbol is described. The type chain produced by this command is
38431a recursive definition of the data type as stored in @value{GDBN}'s
38432data structures, including its flags and contained types.
38433
dcd1f979
TT
38434@kindex maint selftest
38435@cindex self tests
1526853e 38436@item maint selftest @r{[}@var{filter}@r{]}
dcd1f979
TT
38437Run any self tests that were compiled in to @value{GDBN}. This will
38438print a message showing how many tests were run, and how many failed.
1526853e
SM
38439If a @var{filter} is passed, only the tests with @var{filter} in their
38440name will by ran.
38441
3c2fcaf9 38442@kindex maint info selftests
1526853e
SM
38443@cindex self tests
38444@item maint info selftests
38445List the selftests compiled in to @value{GDBN}.
dcd1f979 38446
b4f54984
DE
38447@kindex maint set dwarf always-disassemble
38448@kindex maint show dwarf always-disassemble
38449@item maint set dwarf always-disassemble
38450@item maint show dwarf always-disassemble
9eae7c52
TT
38451Control the behavior of @code{info address} when using DWARF debugging
38452information.
38453
38454The default is @code{off}, which means that @value{GDBN} should try to
38455describe a variable's location in an easily readable format. When
38456@code{on}, @value{GDBN} will instead display the DWARF location
38457expression in an assembly-like format. Note that some locations are
38458too complex for @value{GDBN} to describe simply; in this case you will
38459always see the disassembly form.
38460
38461Here is an example of the resulting disassembly:
38462
38463@smallexample
38464(gdb) info addr argc
38465Symbol "argc" is a complex DWARF expression:
38466 1: DW_OP_fbreg 0
38467@end smallexample
38468
38469For more information on these expressions, see
38470@uref{http://www.dwarfstd.org/, the DWARF standard}.
38471
b4f54984
DE
38472@kindex maint set dwarf max-cache-age
38473@kindex maint show dwarf max-cache-age
38474@item maint set dwarf max-cache-age
38475@itemx maint show dwarf max-cache-age
38476Control the DWARF compilation unit cache.
09d4efe1 38477
b4f54984 38478@cindex DWARF compilation units cache
09d4efe1 38479In object files with inter-compilation-unit references, such as those
b4f54984 38480produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF
09d4efe1
EZ
38481reader needs to frequently refer to previously read compilation units.
38482This setting controls how long a compilation unit will remain in the
38483cache if it is not referenced. A higher limit means that cached
38484compilation units will be stored in memory longer, and more total
38485memory will be used. Setting it to zero disables caching, which will
38486slow down @value{GDBN} startup, but reduce memory consumption.
38487
3c3bb058
AB
38488@kindex maint set dwarf unwinders
38489@kindex maint show dwarf unwinders
38490@item maint set dwarf unwinders
38491@itemx maint show dwarf unwinders
38492Control use of the DWARF frame unwinders.
38493
38494@cindex DWARF frame unwinders
38495Many targets that support DWARF debugging use @value{GDBN}'s DWARF
38496frame unwinders to build the backtrace. Many of these targets will
38497also have a second mechanism for building the backtrace for use in
38498cases where DWARF information is not available, this second mechanism
38499is often an analysis of a function's prologue.
38500
38501In order to extend testing coverage of the second level stack
38502unwinding mechanisms it is helpful to be able to disable the DWARF
38503stack unwinders, this can be done with this switch.
38504
38505In normal use of @value{GDBN} disabling the DWARF unwinders is not
38506advisable, there are cases that are better handled through DWARF than
38507prologue analysis, and the debug experience is likely to be better
38508with the DWARF frame unwinders enabled.
38509
38510If DWARF frame unwinders are not supported for a particular target
38511architecture, then enabling this flag does not cause them to be used.
22138db6
TT
38512
38513@kindex maint set worker-threads
38514@kindex maint show worker-threads
38515@item maint set worker-threads
38516@item maint show worker-threads
38517Control the number of worker threads that may be used by @value{GDBN}.
38518On capable hosts, @value{GDBN} may use multiple threads to speed up
38519certain CPU-intensive operations, such as demangling symbol names.
38520While the number of threads used by @value{GDBN} may vary, this
38521command can be used to set an upper bound on this number. The default
38522is @code{unlimited}, which lets @value{GDBN} choose a reasonable
38523number. Note that this only controls worker threads started by
38524@value{GDBN} itself; libraries used by @value{GDBN} may start threads
38525of their own.
38526
e7ba9c65
DJ
38527@kindex maint set profile
38528@kindex maint show profile
38529@cindex profiling GDB
38530@item maint set profile
38531@itemx maint show profile
38532Control profiling of @value{GDBN}.
38533
38534Profiling will be disabled until you use the @samp{maint set profile}
38535command to enable it. When you enable profiling, the system will begin
38536collecting timing and execution count data; when you disable profiling or
38537exit @value{GDBN}, the results will be written to a log file. Remember that
38538if you use profiling, @value{GDBN} will overwrite the profiling log file
38539(often called @file{gmon.out}). If you have a record of important profiling
38540data in a @file{gmon.out} file, be sure to move it to a safe location.
38541
38542Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
b383017d 38543compiled with the @samp{-pg} compiler option.
e7ba9c65 38544
cbe54154
PA
38545@kindex maint set show-debug-regs
38546@kindex maint show show-debug-regs
eac35c4e 38547@cindex hardware debug registers
cbe54154
PA
38548@item maint set show-debug-regs
38549@itemx maint show show-debug-regs
eac35c4e 38550Control whether to show variables that mirror the hardware debug
6dd315ba 38551registers. Use @code{on} to enable, @code{off} to disable. If
3f94c067 38552enabled, the debug registers values are shown when @value{GDBN} inserts or
09d4efe1
EZ
38553removes a hardware breakpoint or watchpoint, and when the inferior
38554triggers a hardware-assisted breakpoint or watchpoint.
38555
711e434b
PM
38556@kindex maint set show-all-tib
38557@kindex maint show show-all-tib
38558@item maint set show-all-tib
38559@itemx maint show show-all-tib
38560Control whether to show all non zero areas within a 1k block starting
38561at thread local base, when using the @samp{info w32 thread-information-block}
38562command.
38563
329ea579
PA
38564@kindex maint set target-async
38565@kindex maint show target-async
38566@item maint set target-async
38567@itemx maint show target-async
38568This controls whether @value{GDBN} targets operate in synchronous or
38569asynchronous mode (@pxref{Background Execution}). Normally the
38570default is asynchronous, if it is available; but this can be changed
38571to more easily debug problems occurring only in synchronous mode.
38572
fbea99ea
PA
38573@kindex maint set target-non-stop @var{mode} [on|off|auto]
38574@kindex maint show target-non-stop
38575@item maint set target-non-stop
38576@itemx maint show target-non-stop
38577
38578This controls whether @value{GDBN} targets always operate in non-stop
38579mode even if @code{set non-stop} is @code{off} (@pxref{Non-Stop
38580Mode}). The default is @code{auto}, meaning non-stop mode is enabled
38581if supported by the target.
38582
38583@table @code
38584@item maint set target-non-stop auto
38585This is the default mode. @value{GDBN} controls the target in
38586non-stop mode if the target supports it.
38587
38588@item maint set target-non-stop on
38589@value{GDBN} controls the target in non-stop mode even if the target
38590does not indicate support.
38591
38592@item maint set target-non-stop off
38593@value{GDBN} does not control the target in non-stop mode even if the
38594target supports it.
38595@end table
38596
45e42163
TT
38597@kindex maint set tui-resize-message
38598@kindex maint show tui-resize-message
38599@item maint set tui-resize-message
38600@item maint show tui-resize-message
38601Control whether @value{GDBN} displays a message each time the terminal
38602is resized when in TUI mode. The default is @code{off}, which means
38603that @value{GDBN} is silent during resizes. When @code{on},
38604@value{GDBN} will display a message after a resize is completed; the
38605message will include a number indicating how many times the terminal
38606has been resized. This setting is intended for use by the test suite,
38607where it would otherwise be difficult to determine when a resize and
38608refresh has been completed.
38609
bd712aed
DE
38610@kindex maint set per-command
38611@kindex maint show per-command
38612@item maint set per-command
38613@itemx maint show per-command
38614@cindex resources used by commands
09d4efe1 38615
bd712aed
DE
38616@value{GDBN} can display the resources used by each command.
38617This is useful in debugging performance problems.
38618
38619@table @code
38620@item maint set per-command space [on|off]
38621@itemx maint show per-command space
38622Enable or disable the printing of the memory used by GDB for each command.
38623If enabled, @value{GDBN} will display how much memory each command
38624took, following the command's own output.
38625This can also be requested by invoking @value{GDBN} with the
38626@option{--statistics} command-line switch (@pxref{Mode Options}).
38627
38628@item maint set per-command time [on|off]
38629@itemx maint show per-command time
38630Enable or disable the printing of the execution time of @value{GDBN}
38631for each command.
38632If enabled, @value{GDBN} will display how much time it
09d4efe1 38633took to execute each command, following the command's own output.
0a1c4d10
DE
38634Both CPU time and wallclock time are printed.
38635Printing both is useful when trying to determine whether the cost is
bd712aed 38636CPU or, e.g., disk/network latency.
0a1c4d10
DE
38637Note that the CPU time printed is for @value{GDBN} only, it does not include
38638the execution time of the inferior because there's no mechanism currently
38639to compute how much time was spent by @value{GDBN} and how much time was
38640spent by the program been debugged.
09d4efe1
EZ
38641This can also be requested by invoking @value{GDBN} with the
38642@option{--statistics} command-line switch (@pxref{Mode Options}).
38643
bd712aed
DE
38644@item maint set per-command symtab [on|off]
38645@itemx maint show per-command symtab
38646Enable or disable the printing of basic symbol table statistics
38647for each command.
38648If enabled, @value{GDBN} will display the following information:
38649
215b9f98
EZ
38650@enumerate a
38651@item
38652number of symbol tables
38653@item
38654number of primary symbol tables
38655@item
38656number of blocks in the blockvector
38657@end enumerate
bd712aed
DE
38658@end table
38659
5045b3d7
GB
38660@kindex maint set check-libthread-db
38661@kindex maint show check-libthread-db
38662@item maint set check-libthread-db [on|off]
38663@itemx maint show check-libthread-db
38664Control whether @value{GDBN} should run integrity checks on inferior
38665specific thread debugging libraries as they are loaded. The default
38666is not to perform such checks. If any check fails @value{GDBN} will
38667unload the library and continue searching for a suitable candidate as
38668described in @ref{set libthread-db-search-path}. For more information
38669about the tests, see @ref{maint check libthread-db}.
38670
bd712aed
DE
38671@kindex maint space
38672@cindex memory used by commands
38673@item maint space @var{value}
38674An alias for @code{maint set per-command space}.
38675A non-zero value enables it, zero disables it.
38676
38677@kindex maint time
38678@cindex time of command execution
38679@item maint time @var{value}
38680An alias for @code{maint set per-command time}.
38681A non-zero value enables it, zero disables it.
38682
09d4efe1
EZ
38683@kindex maint translate-address
38684@item maint translate-address @r{[}@var{section}@r{]} @var{addr}
38685Find the symbol stored at the location specified by the address
38686@var{addr} and an optional section name @var{section}. If found,
38687@value{GDBN} prints the name of the closest symbol and an offset from
38688the symbol's location to the specified address. This is similar to
38689the @code{info address} command (@pxref{Symbols}), except that this
38690command also allows to find symbols in other sections.
ae038cb0 38691
c14c28ba
PP
38692If section was not specified, the section in which the symbol was found
38693is also printed. For dynamically linked executables, the name of
38694executable or shared library containing the symbol is printed as well.
38695
3345721a
PA
38696@kindex maint test-options
38697@item maint test-options require-delimiter
38698@itemx maint test-options unknown-is-error
38699@itemx maint test-options unknown-is-operand
38700These commands are used by the testsuite to validate the command
38701options framework. The @code{require-delimiter} variant requires a
38702double-dash delimiter to indicate end of options. The
38703@code{unknown-is-error} and @code{unknown-is-operand} do not. The
38704@code{unknown-is-error} variant throws an error on unknown option,
38705while @code{unknown-is-operand} treats unknown options as the start of
38706the command's operands. When run, the commands output the result of
38707the processed options. When completed, the commands store the
38708internal result of completion in a variable exposed by the @code{maint
38709show test-options-completion-result} command.
38710
38711@kindex maint show test-options-completion-result
38712@item maint show test-options-completion-result
38713Shows the result of completing the @code{maint test-options}
38714subcommands. This is used by the testsuite to validate completion
38715support in the command options framework.
38716
c6ac8931
PA
38717@kindex maint set test-settings
38718@kindex maint show test-settings
38719@item maint set test-settings @var{kind}
38720@itemx maint show test-settings @var{kind}
dca0f6c0
PA
38721These are representative commands for each @var{kind} of setting type
38722@value{GDBN} supports. They are used by the testsuite for exercising
38723the settings infrastructure.
fdbc9870
PA
38724
38725@kindex maint with
38726@item maint with @var{setting} [@var{value}] [-- @var{command}]
38727Like the @code{with} command, but works with @code{maintenance set}
38728variables. This is used by the testsuite to exercise the @code{with}
38729command's infrastructure.
38730
8e04817f 38731@end table
c906108c 38732
9c16f35a
EZ
38733The following command is useful for non-interactive invocations of
38734@value{GDBN}, such as in the test suite.
38735
38736@table @code
38737@item set watchdog @var{nsec}
38738@kindex set watchdog
38739@cindex watchdog timer
38740@cindex timeout for commands
38741Set the maximum number of seconds @value{GDBN} will wait for the
38742target operation to finish. If this time expires, @value{GDBN}
38743reports and error and the command is aborted.
38744
38745@item show watchdog
38746Show the current setting of the target wait timeout.
38747@end table
c906108c 38748
e0ce93ac 38749@node Remote Protocol
8e04817f 38750@appendix @value{GDBN} Remote Serial Protocol
c906108c 38751
ee2d5c50
AC
38752@menu
38753* Overview::
38754* Packets::
38755* Stop Reply Packets::
38756* General Query Packets::
a1dcb23a 38757* Architecture-Specific Protocol Details::
9d29849a 38758* Tracepoint Packets::
a6b151f1 38759* Host I/O Packets::
9a6253be 38760* Interrupts::
8b23ecc4
SL
38761* Notification Packets::
38762* Remote Non-Stop::
a6f3e723 38763* Packet Acknowledgment::
ee2d5c50 38764* Examples::
79a6e687 38765* File-I/O Remote Protocol Extension::
cfa9d6d9 38766* Library List Format::
2268b414 38767* Library List Format for SVR4 Targets::
79a6e687 38768* Memory Map Format::
dc146f7c 38769* Thread List Format::
b3b9301e 38770* Traceframe Info Format::
2ae8c8e7 38771* Branch Trace Format::
f4abbc16 38772* Branch Trace Configuration Format::
ee2d5c50
AC
38773@end menu
38774
38775@node Overview
38776@section Overview
38777
8e04817f
AC
38778There may be occasions when you need to know something about the
38779protocol---for example, if there is only one serial port to your target
38780machine, you might want your program to do something special if it
38781recognizes a packet meant for @value{GDBN}.
c906108c 38782
d2c6833e 38783In the examples below, @samp{->} and @samp{<-} are used to indicate
bf06d120 38784transmitted and received data, respectively.
c906108c 38785
8e04817f
AC
38786@cindex protocol, @value{GDBN} remote serial
38787@cindex serial protocol, @value{GDBN} remote
38788@cindex remote serial protocol
8b23ecc4
SL
38789All @value{GDBN} commands and responses (other than acknowledgments
38790and notifications, see @ref{Notification Packets}) are sent as a
38791@var{packet}. A @var{packet} is introduced with the character
8e04817f
AC
38792@samp{$}, the actual @var{packet-data}, and the terminating character
38793@samp{#} followed by a two-digit @var{checksum}:
c906108c 38794
474c8240 38795@smallexample
8e04817f 38796@code{$}@var{packet-data}@code{#}@var{checksum}
474c8240 38797@end smallexample
8e04817f 38798@noindent
c906108c 38799
8e04817f
AC
38800@cindex checksum, for @value{GDBN} remote
38801@noindent
38802The two-digit @var{checksum} is computed as the modulo 256 sum of all
38803characters between the leading @samp{$} and the trailing @samp{#} (an
38804eight bit unsigned checksum).
c906108c 38805
8e04817f
AC
38806Implementors should note that prior to @value{GDBN} 5.0 the protocol
38807specification also included an optional two-digit @var{sequence-id}:
c906108c 38808
474c8240 38809@smallexample
8e04817f 38810@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
474c8240 38811@end smallexample
c906108c 38812
8e04817f
AC
38813@cindex sequence-id, for @value{GDBN} remote
38814@noindent
38815That @var{sequence-id} was appended to the acknowledgment. @value{GDBN}
38816has never output @var{sequence-id}s. Stubs that handle packets added
38817since @value{GDBN} 5.0 must not accept @var{sequence-id}.
c906108c 38818
8e04817f
AC
38819When either the host or the target machine receives a packet, the first
38820response expected is an acknowledgment: either @samp{+} (to indicate
38821the package was received correctly) or @samp{-} (to request
38822retransmission):
c906108c 38823
474c8240 38824@smallexample
d2c6833e
AC
38825-> @code{$}@var{packet-data}@code{#}@var{checksum}
38826<- @code{+}
474c8240 38827@end smallexample
8e04817f 38828@noindent
53a5351d 38829
a6f3e723
SL
38830The @samp{+}/@samp{-} acknowledgments can be disabled
38831once a connection is established.
38832@xref{Packet Acknowledgment}, for details.
38833
8e04817f
AC
38834The host (@value{GDBN}) sends @var{command}s, and the target (the
38835debugging stub incorporated in your program) sends a @var{response}. In
38836the case of step and continue @var{command}s, the response is only sent
8b23ecc4
SL
38837when the operation has completed, and the target has again stopped all
38838threads in all attached processes. This is the default all-stop mode
38839behavior, but the remote protocol also supports @value{GDBN}'s non-stop
38840execution mode; see @ref{Remote Non-Stop}, for details.
c906108c 38841
8e04817f
AC
38842@var{packet-data} consists of a sequence of characters with the
38843exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
38844exceptions).
c906108c 38845
ee2d5c50 38846@cindex remote protocol, field separator
0876f84a 38847Fields within the packet should be separated using @samp{,} @samp{;} or
8e04817f 38848@samp{:}. Except where otherwise noted all numbers are represented in
ee2d5c50 38849@sc{hex} with leading zeros suppressed.
c906108c 38850
8e04817f
AC
38851Implementors should note that prior to @value{GDBN} 5.0, the character
38852@samp{:} could not appear as the third character in a packet (as it
38853would potentially conflict with the @var{sequence-id}).
c906108c 38854
0876f84a
DJ
38855@cindex remote protocol, binary data
38856@anchor{Binary Data}
38857Binary data in most packets is encoded either as two hexadecimal
38858digits per byte of binary data. This allowed the traditional remote
38859protocol to work over connections which were only seven-bit clean.
38860Some packets designed more recently assume an eight-bit clean
38861connection, and use a more efficient encoding to send and receive
38862binary data.
38863
38864The binary data representation uses @code{7d} (@sc{ascii} @samp{@}})
38865as an escape character. Any escaped byte is transmitted as the escape
38866character followed by the original character XORed with @code{0x20}.
38867For example, the byte @code{0x7d} would be transmitted as the two
38868bytes @code{0x7d 0x5d}. The bytes @code{0x23} (@sc{ascii} @samp{#}),
38869@code{0x24} (@sc{ascii} @samp{$}), and @code{0x7d} (@sc{ascii}
38870@samp{@}}) must always be escaped. Responses sent by the stub
38871must also escape @code{0x2a} (@sc{ascii} @samp{*}), so that it
38872is not interpreted as the start of a run-length encoded sequence
38873(described next).
38874
1d3811f6
DJ
38875Response @var{data} can be run-length encoded to save space.
38876Run-length encoding replaces runs of identical characters with one
38877instance of the repeated character, followed by a @samp{*} and a
38878repeat count. The repeat count is itself sent encoded, to avoid
38879binary characters in @var{data}: a value of @var{n} is sent as
38880@code{@var{n}+29}. For a repeat count greater or equal to 3, this
38881produces a printable @sc{ascii} character, e.g.@: a space (@sc{ascii}
38882code 32) for a repeat count of 3. (This is because run-length
38883encoding starts to win for counts 3 or more.) Thus, for example,
38884@samp{0* } is a run-length encoding of ``0000'': the space character
38885after @samp{*} means repeat the leading @code{0} @w{@code{32 - 29 =
388863}} more times.
38887
38888The printable characters @samp{#} and @samp{$} or with a numeric value
38889greater than 126 must not be used. Runs of six repeats (@samp{#}) or
38890seven repeats (@samp{$}) can be expanded using a repeat count of only
38891five (@samp{"}). For example, @samp{00000000} can be encoded as
38892@samp{0*"00}.
c906108c 38893
8e04817f
AC
38894The error response returned for some packets includes a two character
38895error number. That number is not well defined.
c906108c 38896
f8da2bff 38897@cindex empty response, for unsupported packets
8e04817f
AC
38898For any @var{command} not supported by the stub, an empty response
38899(@samp{$#00}) should be returned. That way it is possible to extend the
38900protocol. A newer @value{GDBN} can tell if a packet is supported based
38901on that response.
c906108c 38902
393eab54
PA
38903At a minimum, a stub is required to support the @samp{g} and @samp{G}
38904commands for register access, and the @samp{m} and @samp{M} commands
38905for memory access. Stubs that only control single-threaded targets
38906can implement run control with the @samp{c} (continue), and @samp{s}
38907(step) commands. Stubs that support multi-threading targets should
38908support the @samp{vCont} command. All other commands are optional.
c906108c 38909
ee2d5c50
AC
38910@node Packets
38911@section Packets
38912
38913The following table provides a complete list of all currently defined
38914@var{command}s and their corresponding response @var{data}.
79a6e687 38915@xref{File-I/O Remote Protocol Extension}, for details about the File
9c16f35a 38916I/O extension of the remote protocol.
ee2d5c50 38917
b8ff78ce
JB
38918Each packet's description has a template showing the packet's overall
38919syntax, followed by an explanation of the packet's meaning. We
38920include spaces in some of the templates for clarity; these are not
38921part of the packet's syntax. No @value{GDBN} packet uses spaces to
38922separate its components. For example, a template like @samp{foo
38923@var{bar} @var{baz}} describes a packet beginning with the three ASCII
38924bytes @samp{foo}, followed by a @var{bar}, followed directly by a
3f94c067 38925@var{baz}. @value{GDBN} does not transmit a space character between the
b8ff78ce
JB
38926@samp{foo} and the @var{bar}, or between the @var{bar} and the
38927@var{baz}.
38928
b90a069a
SL
38929@cindex @var{thread-id}, in remote protocol
38930@anchor{thread-id syntax}
38931Several packets and replies include a @var{thread-id} field to identify
38932a thread. Normally these are positive numbers with a target-specific
38933interpretation, formatted as big-endian hex strings. A @var{thread-id}
38934can also be a literal @samp{-1} to indicate all threads, or @samp{0} to
38935pick any thread.
38936
38937In addition, the remote protocol supports a multiprocess feature in
38938which the @var{thread-id} syntax is extended to optionally include both
38939process and thread ID fields, as @samp{p@var{pid}.@var{tid}}.
38940The @var{pid} (process) and @var{tid} (thread) components each have the
38941format described above: a positive number with target-specific
38942interpretation formatted as a big-endian hex string, literal @samp{-1}
38943to indicate all processes or threads (respectively), or @samp{0} to
38944indicate an arbitrary process or thread. Specifying just a process, as
38945@samp{p@var{pid}}, is equivalent to @samp{p@var{pid}.-1}. It is an
38946error to specify all processes but a specific thread, such as
38947@samp{p-1.@var{tid}}. Note that the @samp{p} prefix is @emph{not} used
38948for those packets and replies explicitly documented to include a process
38949ID, rather than a @var{thread-id}.
38950
38951The multiprocess @var{thread-id} syntax extensions are only used if both
38952@value{GDBN} and the stub report support for the @samp{multiprocess}
38953feature using @samp{qSupported}. @xref{multiprocess extensions}, for
38954more information.
38955
8ffe2530
JB
38956Note that all packet forms beginning with an upper- or lower-case
38957letter, other than those described here, are reserved for future use.
38958
b8ff78ce 38959Here are the packet descriptions.
ee2d5c50 38960
b8ff78ce 38961@table @samp
ee2d5c50 38962
b8ff78ce
JB
38963@item !
38964@cindex @samp{!} packet
2d717e4f 38965@anchor{extended mode}
8e04817f
AC
38966Enable extended mode. In extended mode, the remote server is made
38967persistent. The @samp{R} packet is used to restart the program being
38968debugged.
ee2d5c50
AC
38969
38970Reply:
38971@table @samp
38972@item OK
8e04817f 38973The remote target both supports and has enabled extended mode.
ee2d5c50 38974@end table
c906108c 38975
b8ff78ce
JB
38976@item ?
38977@cindex @samp{?} packet
36cb1214 38978@anchor{? packet}
ee2d5c50 38979Indicate the reason the target halted. The reply is the same as for
8b23ecc4
SL
38980step and continue. This packet has a special interpretation when the
38981target is in non-stop mode; see @ref{Remote Non-Stop}.
c906108c 38982
ee2d5c50
AC
38983Reply:
38984@xref{Stop Reply Packets}, for the reply specifications.
38985
b8ff78ce
JB
38986@item A @var{arglen},@var{argnum},@var{arg},@dots{}
38987@cindex @samp{A} packet
38988Initialized @code{argv[]} array passed into program. @var{arglen}
38989specifies the number of bytes in the hex encoded byte stream
38990@var{arg}. See @code{gdbserver} for more details.
ee2d5c50
AC
38991
38992Reply:
38993@table @samp
38994@item OK
b8ff78ce
JB
38995The arguments were set.
38996@item E @var{NN}
38997An error occurred.
ee2d5c50
AC
38998@end table
38999
b8ff78ce
JB
39000@item b @var{baud}
39001@cindex @samp{b} packet
39002(Don't use this packet; its behavior is not well-defined.)
ee2d5c50
AC
39003Change the serial line speed to @var{baud}.
39004
39005JTC: @emph{When does the transport layer state change? When it's
39006received, or after the ACK is transmitted. In either case, there are
39007problems if the command or the acknowledgment packet is dropped.}
39008
39009Stan: @emph{If people really wanted to add something like this, and get
39010it working for the first time, they ought to modify ser-unix.c to send
39011some kind of out-of-band message to a specially-setup stub and have the
39012switch happen "in between" packets, so that from remote protocol's point
39013of view, nothing actually happened.}
39014
b8ff78ce
JB
39015@item B @var{addr},@var{mode}
39016@cindex @samp{B} packet
8e04817f 39017Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
2f870471
AC
39018breakpoint at @var{addr}.
39019
b8ff78ce 39020Don't use this packet. Use the @samp{Z} and @samp{z} packets instead
2f870471 39021(@pxref{insert breakpoint or watchpoint packet}).
c906108c 39022
bacec72f 39023@cindex @samp{bc} packet
0d772ac9
MS
39024@anchor{bc}
39025@item bc
bacec72f
MS
39026Backward continue. Execute the target system in reverse. No parameter.
39027@xref{Reverse Execution}, for more information.
39028
39029Reply:
39030@xref{Stop Reply Packets}, for the reply specifications.
39031
bacec72f 39032@cindex @samp{bs} packet
0d772ac9
MS
39033@anchor{bs}
39034@item bs
bacec72f
MS
39035Backward single step. Execute one instruction in reverse. No parameter.
39036@xref{Reverse Execution}, for more information.
39037
39038Reply:
39039@xref{Stop Reply Packets}, for the reply specifications.
39040
4f553f88 39041@item c @r{[}@var{addr}@r{]}
b8ff78ce 39042@cindex @samp{c} packet
697aa1b7
EZ
39043Continue at @var{addr}, which is the address to resume. If @var{addr}
39044is omitted, resume at current address.
c906108c 39045
393eab54
PA
39046This packet is deprecated for multi-threading support. @xref{vCont
39047packet}.
39048
ee2d5c50
AC
39049Reply:
39050@xref{Stop Reply Packets}, for the reply specifications.
39051
4f553f88 39052@item C @var{sig}@r{[};@var{addr}@r{]}
b8ff78ce 39053@cindex @samp{C} packet
8e04817f 39054Continue with signal @var{sig} (hex signal number). If
b8ff78ce 39055@samp{;@var{addr}} is omitted, resume at same address.
c906108c 39056
393eab54
PA
39057This packet is deprecated for multi-threading support. @xref{vCont
39058packet}.
39059
ee2d5c50
AC
39060Reply:
39061@xref{Stop Reply Packets}, for the reply specifications.
c906108c 39062
b8ff78ce
JB
39063@item d
39064@cindex @samp{d} packet
ee2d5c50
AC
39065Toggle debug flag.
39066
b8ff78ce
JB
39067Don't use this packet; instead, define a general set packet
39068(@pxref{General Query Packets}).
ee2d5c50 39069
b8ff78ce 39070@item D
b90a069a 39071@itemx D;@var{pid}
b8ff78ce 39072@cindex @samp{D} packet
b90a069a
SL
39073The first form of the packet is used to detach @value{GDBN} from the
39074remote system. It is sent to the remote target
07f31aa6 39075before @value{GDBN} disconnects via the @code{detach} command.
ee2d5c50 39076
b90a069a
SL
39077The second form, including a process ID, is used when multiprocess
39078protocol extensions are enabled (@pxref{multiprocess extensions}), to
39079detach only a specific process. The @var{pid} is specified as a
39080big-endian hex string.
39081
ee2d5c50
AC
39082Reply:
39083@table @samp
10fac096
NW
39084@item OK
39085for success
b8ff78ce 39086@item E @var{NN}
10fac096 39087for an error
ee2d5c50 39088@end table
c906108c 39089
b8ff78ce
JB
39090@item F @var{RC},@var{EE},@var{CF};@var{XX}
39091@cindex @samp{F} packet
39092A reply from @value{GDBN} to an @samp{F} packet sent by the target.
39093This is part of the File-I/O protocol extension. @xref{File-I/O
79a6e687 39094Remote Protocol Extension}, for the specification.
ee2d5c50 39095
b8ff78ce 39096@item g
ee2d5c50 39097@anchor{read registers packet}
b8ff78ce 39098@cindex @samp{g} packet
ee2d5c50
AC
39099Read general registers.
39100
39101Reply:
39102@table @samp
39103@item @var{XX@dots{}}
8e04817f
AC
39104Each byte of register data is described by two hex digits. The bytes
39105with the register are transmitted in target byte order. The size of
b8ff78ce 39106each register and their position within the @samp{g} packet are
4a9bb1df 39107determined by the @value{GDBN} internal gdbarch functions
4435e1cc 39108@code{DEPRECATED_REGISTER_RAW_SIZE} and @code{gdbarch_register_name}.
ad196637
PA
39109
39110When reading registers from a trace frame (@pxref{Analyze Collected
39111Data,,Using the Collected Data}), the stub may also return a string of
39112literal @samp{x}'s in place of the register data digits, to indicate
39113that the corresponding register has not been collected, thus its value
39114is unavailable. For example, for an architecture with 4 registers of
391154 bytes each, the following reply indicates to @value{GDBN} that
39116registers 0 and 2 have not been collected, while registers 1 and 3
39117have been collected, and both have zero value:
39118
39119@smallexample
39120-> @code{g}
39121<- @code{xxxxxxxx00000000xxxxxxxx00000000}
39122@end smallexample
39123
b8ff78ce 39124@item E @var{NN}
ee2d5c50
AC
39125for an error.
39126@end table
c906108c 39127
b8ff78ce
JB
39128@item G @var{XX@dots{}}
39129@cindex @samp{G} packet
39130Write general registers. @xref{read registers packet}, for a
39131description of the @var{XX@dots{}} data.
ee2d5c50
AC
39132
39133Reply:
39134@table @samp
39135@item OK
39136for success
b8ff78ce 39137@item E @var{NN}
ee2d5c50
AC
39138for an error
39139@end table
39140
393eab54 39141@item H @var{op} @var{thread-id}
b8ff78ce 39142@cindex @samp{H} packet
8e04817f 39143Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
697aa1b7
EZ
39144@samp{G}, et.al.). Depending on the operation to be performed, @var{op}
39145should be @samp{c} for step and continue operations (note that this
393eab54 39146is deprecated, supporting the @samp{vCont} command is a better
697aa1b7 39147option), and @samp{g} for other operations. The thread designator
393eab54
PA
39148@var{thread-id} has the format and interpretation described in
39149@ref{thread-id syntax}.
ee2d5c50
AC
39150
39151Reply:
39152@table @samp
39153@item OK
39154for success
b8ff78ce 39155@item E @var{NN}
ee2d5c50
AC
39156for an error
39157@end table
c906108c 39158
8e04817f
AC
39159@c FIXME: JTC:
39160@c 'H': How restrictive (or permissive) is the thread model. If a
39161@c thread is selected and stopped, are other threads allowed
39162@c to continue to execute? As I mentioned above, I think the
39163@c semantics of each command when a thread is selected must be
39164@c described. For example:
39165@c
39166@c 'g': If the stub supports threads and a specific thread is
39167@c selected, returns the register block from that thread;
39168@c otherwise returns current registers.
39169@c
39170@c 'G' If the stub supports threads and a specific thread is
39171@c selected, sets the registers of the register block of
39172@c that thread; otherwise sets current registers.
c906108c 39173
b8ff78ce 39174@item i @r{[}@var{addr}@r{[},@var{nnn}@r{]]}
ee2d5c50 39175@anchor{cycle step packet}
b8ff78ce
JB
39176@cindex @samp{i} packet
39177Step the remote target by a single clock cycle. If @samp{,@var{nnn}} is
8e04817f
AC
39178present, cycle step @var{nnn} cycles. If @var{addr} is present, cycle
39179step starting at that address.
c906108c 39180
b8ff78ce
JB
39181@item I
39182@cindex @samp{I} packet
39183Signal, then cycle step. @xref{step with signal packet}. @xref{cycle
39184step packet}.
ee2d5c50 39185
b8ff78ce
JB
39186@item k
39187@cindex @samp{k} packet
39188Kill request.
c906108c 39189
36cb1214
HZ
39190The exact effect of this packet is not specified.
39191
39192For a bare-metal target, it may power cycle or reset the target
39193system. For that reason, the @samp{k} packet has no reply.
39194
39195For a single-process target, it may kill that process if possible.
39196
39197A multiple-process target may choose to kill just one process, or all
39198that are under @value{GDBN}'s control. For more precise control, use
39199the vKill packet (@pxref{vKill packet}).
39200
39201If the target system immediately closes the connection in response to
39202@samp{k}, @value{GDBN} does not consider the lack of packet
39203acknowledgment to be an error, and assumes the kill was successful.
39204
39205If connected using @kbd{target extended-remote}, and the target does
39206not close the connection in response to a kill request, @value{GDBN}
39207probes the target state as if a new connection was opened
39208(@pxref{? packet}).
c906108c 39209
b8ff78ce
JB
39210@item m @var{addr},@var{length}
39211@cindex @samp{m} packet
a86c90e6
SM
39212Read @var{length} addressable memory units starting at address @var{addr}
39213(@pxref{addressable memory unit}). Note that @var{addr} may not be aligned to
39214any particular boundary.
fb031cdf
JB
39215
39216The stub need not use any particular size or alignment when gathering
39217data from memory for the response; even if @var{addr} is word-aligned
39218and @var{length} is a multiple of the word size, the stub is free to
39219use byte accesses, or not. For this reason, this packet may not be
39220suitable for accessing memory-mapped I/O devices.
c43c5473
JB
39221@cindex alignment of remote memory accesses
39222@cindex size of remote memory accesses
39223@cindex memory, alignment and size of remote accesses
c906108c 39224
ee2d5c50
AC
39225Reply:
39226@table @samp
39227@item @var{XX@dots{}}
a86c90e6
SM
39228Memory contents; each byte is transmitted as a two-digit hexadecimal number.
39229The reply may contain fewer addressable memory units than requested if the
b8ff78ce
JB
39230server was able to read only part of the region of memory.
39231@item E @var{NN}
ee2d5c50
AC
39232@var{NN} is errno
39233@end table
39234
b8ff78ce
JB
39235@item M @var{addr},@var{length}:@var{XX@dots{}}
39236@cindex @samp{M} packet
a86c90e6
SM
39237Write @var{length} addressable memory units starting at address @var{addr}
39238(@pxref{addressable memory unit}). The data is given by @var{XX@dots{}}; each
39239byte is transmitted as a two-digit hexadecimal number.
ee2d5c50
AC
39240
39241Reply:
39242@table @samp
39243@item OK
39244for success
b8ff78ce 39245@item E @var{NN}
8e04817f
AC
39246for an error (this includes the case where only part of the data was
39247written).
ee2d5c50 39248@end table
c906108c 39249
b8ff78ce
JB
39250@item p @var{n}
39251@cindex @samp{p} packet
39252Read the value of register @var{n}; @var{n} is in hex.
2e868123
AC
39253@xref{read registers packet}, for a description of how the returned
39254register value is encoded.
ee2d5c50
AC
39255
39256Reply:
39257@table @samp
2e868123
AC
39258@item @var{XX@dots{}}
39259the register's value
b8ff78ce 39260@item E @var{NN}
2e868123 39261for an error
d57350ea 39262@item @w{}
2e868123 39263Indicating an unrecognized @var{query}.
ee2d5c50
AC
39264@end table
39265
b8ff78ce 39266@item P @var{n@dots{}}=@var{r@dots{}}
ee2d5c50 39267@anchor{write register packet}
b8ff78ce
JB
39268@cindex @samp{P} packet
39269Write register @var{n@dots{}} with value @var{r@dots{}}. The register
599b237a 39270number @var{n} is in hexadecimal, and @var{r@dots{}} contains two hex
8e04817f 39271digits for each byte in the register (target byte order).
c906108c 39272
ee2d5c50
AC
39273Reply:
39274@table @samp
39275@item OK
39276for success
b8ff78ce 39277@item E @var{NN}
ee2d5c50
AC
39278for an error
39279@end table
39280
5f3bebba
JB
39281@item q @var{name} @var{params}@dots{}
39282@itemx Q @var{name} @var{params}@dots{}
b8ff78ce 39283@cindex @samp{q} packet
b8ff78ce 39284@cindex @samp{Q} packet
5f3bebba
JB
39285General query (@samp{q}) and set (@samp{Q}). These packets are
39286described fully in @ref{General Query Packets}.
c906108c 39287
b8ff78ce
JB
39288@item r
39289@cindex @samp{r} packet
8e04817f 39290Reset the entire system.
c906108c 39291
b8ff78ce 39292Don't use this packet; use the @samp{R} packet instead.
ee2d5c50 39293
b8ff78ce
JB
39294@item R @var{XX}
39295@cindex @samp{R} packet
697aa1b7 39296Restart the program being debugged. The @var{XX}, while needed, is ignored.
2d717e4f 39297This packet is only available in extended mode (@pxref{extended mode}).
ee2d5c50 39298
8e04817f 39299The @samp{R} packet has no reply.
ee2d5c50 39300
4f553f88 39301@item s @r{[}@var{addr}@r{]}
b8ff78ce 39302@cindex @samp{s} packet
697aa1b7 39303Single step, resuming at @var{addr}. If
b8ff78ce 39304@var{addr} is omitted, resume at same address.
c906108c 39305
393eab54
PA
39306This packet is deprecated for multi-threading support. @xref{vCont
39307packet}.
39308
ee2d5c50
AC
39309Reply:
39310@xref{Stop Reply Packets}, for the reply specifications.
39311
4f553f88 39312@item S @var{sig}@r{[};@var{addr}@r{]}
ee2d5c50 39313@anchor{step with signal packet}
b8ff78ce
JB
39314@cindex @samp{S} packet
39315Step with signal. This is analogous to the @samp{C} packet, but
39316requests a single-step, rather than a normal resumption of execution.
c906108c 39317
393eab54
PA
39318This packet is deprecated for multi-threading support. @xref{vCont
39319packet}.
39320
ee2d5c50
AC
39321Reply:
39322@xref{Stop Reply Packets}, for the reply specifications.
39323
b8ff78ce
JB
39324@item t @var{addr}:@var{PP},@var{MM}
39325@cindex @samp{t} packet
8e04817f 39326Search backwards starting at address @var{addr} for a match with pattern
697aa1b7
EZ
39327@var{PP} and mask @var{MM}, both of which are are 4 byte long.
39328There must be at least 3 digits in @var{addr}.
c906108c 39329
b90a069a 39330@item T @var{thread-id}
b8ff78ce 39331@cindex @samp{T} packet
b90a069a 39332Find out if the thread @var{thread-id} is alive. @xref{thread-id syntax}.
c906108c 39333
ee2d5c50
AC
39334Reply:
39335@table @samp
39336@item OK
39337thread is still alive
b8ff78ce 39338@item E @var{NN}
ee2d5c50
AC
39339thread is dead
39340@end table
39341
b8ff78ce
JB
39342@item v
39343Packets starting with @samp{v} are identified by a multi-letter name,
39344up to the first @samp{;} or @samp{?} (or the end of the packet).
86d30acc 39345
2d717e4f
DJ
39346@item vAttach;@var{pid}
39347@cindex @samp{vAttach} packet
8b23ecc4
SL
39348Attach to a new process with the specified process ID @var{pid}.
39349The process ID is a
39350hexadecimal integer identifying the process. In all-stop mode, all
39351threads in the attached process are stopped; in non-stop mode, it may be
39352attached without being stopped if that is supported by the target.
39353
39354@c In non-stop mode, on a successful vAttach, the stub should set the
39355@c current thread to a thread of the newly-attached process. After
39356@c attaching, GDB queries for the attached process's thread ID with qC.
39357@c Also note that, from a user perspective, whether or not the
39358@c target is stopped on attach in non-stop mode depends on whether you
39359@c use the foreground or background version of the attach command, not
39360@c on what vAttach does; GDB does the right thing with respect to either
39361@c stopping or restarting threads.
2d717e4f
DJ
39362
39363This packet is only available in extended mode (@pxref{extended mode}).
39364
39365Reply:
39366@table @samp
39367@item E @var{nn}
39368for an error
39369@item @r{Any stop packet}
8b23ecc4
SL
39370for success in all-stop mode (@pxref{Stop Reply Packets})
39371@item OK
39372for success in non-stop mode (@pxref{Remote Non-Stop})
2d717e4f
DJ
39373@end table
39374
b90a069a 39375@item vCont@r{[};@var{action}@r{[}:@var{thread-id}@r{]]}@dots{}
b8ff78ce 39376@cindex @samp{vCont} packet
393eab54 39377@anchor{vCont packet}
b8ff78ce 39378Resume the inferior, specifying different actions for each thread.
ca6eff59
PA
39379
39380For each inferior thread, the leftmost action with a matching
39381@var{thread-id} is applied. Threads that don't match any action
39382remain in their current state. Thread IDs are specified using the
39383syntax described in @ref{thread-id syntax}. If multiprocess
39384extensions (@pxref{multiprocess extensions}) are supported, actions
39385can be specified to match all threads in a process by using the
39386@samp{p@var{pid}.-1} form of the @var{thread-id}. An action with no
39402e6c
PA
39387@var{thread-id} matches all threads. Specifying no actions is an
39388error.
b90a069a
SL
39389
39390Currently supported actions are:
86d30acc 39391
b8ff78ce 39392@table @samp
86d30acc
DJ
39393@item c
39394Continue.
b8ff78ce 39395@item C @var{sig}
8b23ecc4 39396Continue with signal @var{sig}. The signal @var{sig} should be two hex digits.
86d30acc
DJ
39397@item s
39398Step.
b8ff78ce 39399@item S @var{sig}
8b23ecc4
SL
39400Step with signal @var{sig}. The signal @var{sig} should be two hex digits.
39401@item t
39402Stop.
c1e36e3e
PA
39403@item r @var{start},@var{end}
39404Step once, and then keep stepping as long as the thread stops at
39405addresses between @var{start} (inclusive) and @var{end} (exclusive).
39406The remote stub reports a stop reply when either the thread goes out
39407of the range or is stopped due to an unrelated reason, such as hitting
39408a breakpoint. @xref{range stepping}.
39409
39410If the range is empty (@var{start} == @var{end}), then the action
39411becomes equivalent to the @samp{s} action. In other words,
39412single-step once, and report the stop (even if the stepped instruction
39413jumps to @var{start}).
39414
39415(A stop reply may be sent at any point even if the PC is still within
39416the stepping range; for example, it is valid to implement this packet
39417in a degenerate way as a single instruction step operation.)
39418
86d30acc
DJ
39419@end table
39420
8b23ecc4
SL
39421The optional argument @var{addr} normally associated with the
39422@samp{c}, @samp{C}, @samp{s}, and @samp{S} packets is
b8ff78ce 39423not supported in @samp{vCont}.
86d30acc 39424
08a0efd0
PA
39425The @samp{t} action is only relevant in non-stop mode
39426(@pxref{Remote Non-Stop}) and may be ignored by the stub otherwise.
8b23ecc4
SL
39427A stop reply should be generated for any affected thread not already stopped.
39428When a thread is stopped by means of a @samp{t} action,
39429the corresponding stop reply should indicate that the thread has stopped with
39430signal @samp{0}, regardless of whether the target uses some other signal
39431as an implementation detail.
39432
ca6eff59
PA
39433The server must ignore @samp{c}, @samp{C}, @samp{s}, @samp{S}, and
39434@samp{r} actions for threads that are already running. Conversely,
39435the server must ignore @samp{t} actions for threads that are already
39436stopped.
39437
39438@emph{Note:} In non-stop mode, a thread is considered running until
6b92c0d3 39439@value{GDBN} acknowledges an asynchronous stop notification for it with
ca6eff59
PA
39440the @samp{vStopped} packet (@pxref{Remote Non-Stop}).
39441
4220b2f8 39442The stub must support @samp{vCont} if it reports support for
ca6eff59 39443multiprocess extensions (@pxref{multiprocess extensions}).
4220b2f8 39444
86d30acc
DJ
39445Reply:
39446@xref{Stop Reply Packets}, for the reply specifications.
39447
b8ff78ce
JB
39448@item vCont?
39449@cindex @samp{vCont?} packet
d3e8051b 39450Request a list of actions supported by the @samp{vCont} packet.
86d30acc
DJ
39451
39452Reply:
39453@table @samp
b8ff78ce
JB
39454@item vCont@r{[};@var{action}@dots{}@r{]}
39455The @samp{vCont} packet is supported. Each @var{action} is a supported
39456command in the @samp{vCont} packet.
d57350ea 39457@item @w{}
b8ff78ce 39458The @samp{vCont} packet is not supported.
86d30acc 39459@end table
ee2d5c50 39460
de979965
PA
39461@anchor{vCtrlC packet}
39462@item vCtrlC
39463@cindex @samp{vCtrlC} packet
39464Interrupt remote target as if a control-C was pressed on the remote
39465terminal. This is the equivalent to reacting to the @code{^C}
39466(@samp{\003}, the control-C character) character in all-stop mode
39467while the target is running, except this works in non-stop mode.
39468@xref{interrupting remote targets}, for more info on the all-stop
39469variant.
39470
39471Reply:
39472@table @samp
39473@item E @var{nn}
39474for an error
39475@item OK
39476for success
39477@end table
39478
a6b151f1
DJ
39479@item vFile:@var{operation}:@var{parameter}@dots{}
39480@cindex @samp{vFile} packet
39481Perform a file operation on the target system. For details,
39482see @ref{Host I/O Packets}.
39483
68437a39
DJ
39484@item vFlashErase:@var{addr},@var{length}
39485@cindex @samp{vFlashErase} packet
39486Direct the stub to erase @var{length} bytes of flash starting at
39487@var{addr}. The region may enclose any number of flash blocks, but
39488its start and end must fall on block boundaries, as indicated by the
79a6e687
BW
39489flash block size appearing in the memory map (@pxref{Memory Map
39490Format}). @value{GDBN} groups flash memory programming operations
68437a39
DJ
39491together, and sends a @samp{vFlashDone} request after each group; the
39492stub is allowed to delay erase operation until the @samp{vFlashDone}
39493packet is received.
39494
39495Reply:
39496@table @samp
39497@item OK
39498for success
39499@item E @var{NN}
39500for an error
39501@end table
39502
39503@item vFlashWrite:@var{addr}:@var{XX@dots{}}
39504@cindex @samp{vFlashWrite} packet
39505Direct the stub to write data to flash address @var{addr}. The data
39506is passed in binary form using the same encoding as for the @samp{X}
39507packet (@pxref{Binary Data}). The memory ranges specified by
39508@samp{vFlashWrite} packets preceding a @samp{vFlashDone} packet must
39509not overlap, and must appear in order of increasing addresses
39510(although @samp{vFlashErase} packets for higher addresses may already
39511have been received; the ordering is guaranteed only between
39512@samp{vFlashWrite} packets). If a packet writes to an address that was
39513neither erased by a preceding @samp{vFlashErase} packet nor by some other
39514target-specific method, the results are unpredictable.
39515
39516
39517Reply:
39518@table @samp
39519@item OK
39520for success
39521@item E.memtype
39522for vFlashWrite addressing non-flash memory
39523@item E @var{NN}
39524for an error
39525@end table
39526
39527@item vFlashDone
39528@cindex @samp{vFlashDone} packet
39529Indicate to the stub that flash programming operation is finished.
39530The stub is permitted to delay or batch the effects of a group of
39531@samp{vFlashErase} and @samp{vFlashWrite} packets until a
39532@samp{vFlashDone} packet is received. The contents of the affected
39533regions of flash memory are unpredictable until the @samp{vFlashDone}
39534request is completed.
39535
b90a069a
SL
39536@item vKill;@var{pid}
39537@cindex @samp{vKill} packet
36cb1214 39538@anchor{vKill packet}
697aa1b7 39539Kill the process with the specified process ID @var{pid}, which is a
b90a069a
SL
39540hexadecimal integer identifying the process. This packet is used in
39541preference to @samp{k} when multiprocess protocol extensions are
39542supported; see @ref{multiprocess extensions}.
39543
39544Reply:
39545@table @samp
39546@item E @var{nn}
39547for an error
39548@item OK
39549for success
39550@end table
39551
176efed1
AB
39552@item vMustReplyEmpty
39553@cindex @samp{vMustReplyEmpty} packet
39554The correct reply to an unknown @samp{v} packet is to return the empty
39555string, however, some older versions of @command{gdbserver} would
39556incorrectly return @samp{OK} for unknown @samp{v} packets.
39557
39558The @samp{vMustReplyEmpty} is used as a feature test to check how
39559@command{gdbserver} handles unknown packets, it is important that this
39560packet be handled in the same way as other unknown @samp{v} packets.
39561If this packet is handled differently to other unknown @samp{v}
6b92c0d3 39562packets then it is possible that @value{GDBN} may run into problems in
176efed1
AB
39563other areas, specifically around use of @samp{vFile:setfs:}.
39564
2d717e4f
DJ
39565@item vRun;@var{filename}@r{[};@var{argument}@r{]}@dots{}
39566@cindex @samp{vRun} packet
39567Run the program @var{filename}, passing it each @var{argument} on its
39568command line. The file and arguments are hex-encoded strings. If
39569@var{filename} is an empty string, the stub may use a default program
39570(e.g.@: the last program run). The program is created in the stopped
9b562ab8 39571state.
2d717e4f 39572
8b23ecc4
SL
39573@c FIXME: What about non-stop mode?
39574
2d717e4f
DJ
39575This packet is only available in extended mode (@pxref{extended mode}).
39576
39577Reply:
39578@table @samp
39579@item E @var{nn}
39580for an error
39581@item @r{Any stop packet}
39582for success (@pxref{Stop Reply Packets})
39583@end table
39584
8b23ecc4 39585@item vStopped
8b23ecc4 39586@cindex @samp{vStopped} packet
8dbe8ece 39587@xref{Notification Packets}.
8b23ecc4 39588
b8ff78ce 39589@item X @var{addr},@var{length}:@var{XX@dots{}}
9a6253be 39590@anchor{X packet}
b8ff78ce
JB
39591@cindex @samp{X} packet
39592Write data to memory, where the data is transmitted in binary.
a86c90e6
SM
39593Memory is specified by its address @var{addr} and number of addressable memory
39594units @var{length} (@pxref{addressable memory unit});
0876f84a 39595@samp{@var{XX}@dots{}} is binary data (@pxref{Binary Data}).
c906108c 39596
ee2d5c50
AC
39597Reply:
39598@table @samp
39599@item OK
39600for success
b8ff78ce 39601@item E @var{NN}
ee2d5c50
AC
39602for an error
39603@end table
39604
a1dcb23a
DJ
39605@item z @var{type},@var{addr},@var{kind}
39606@itemx Z @var{type},@var{addr},@var{kind}
2f870471 39607@anchor{insert breakpoint or watchpoint packet}
b8ff78ce
JB
39608@cindex @samp{z} packet
39609@cindex @samp{Z} packets
39610Insert (@samp{Z}) or remove (@samp{z}) a @var{type} breakpoint or
a1dcb23a 39611watchpoint starting at address @var{address} of kind @var{kind}.
ee2d5c50 39612
2f870471
AC
39613Each breakpoint and watchpoint packet @var{type} is documented
39614separately.
39615
512217c7
AC
39616@emph{Implementation notes: A remote target shall return an empty string
39617for an unrecognized breakpoint or watchpoint packet @var{type}. A
39618remote target shall support either both or neither of a given
b8ff78ce 39619@samp{Z@var{type}@dots{}} and @samp{z@var{type}@dots{}} packet pair. To
2f870471
AC
39620avoid potential problems with duplicate packets, the operations should
39621be implemented in an idempotent way.}
39622
a1dcb23a 39623@item z0,@var{addr},@var{kind}
d3ce09f5 39624@itemx Z0,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}@r{[};cmds:@var{persist},@var{cmd_list}@dots{}@r{]}
b8ff78ce
JB
39625@cindex @samp{z0} packet
39626@cindex @samp{Z0} packet
4435e1cc 39627Insert (@samp{Z0}) or remove (@samp{z0}) a software breakpoint at address
a1dcb23a 39628@var{addr} of type @var{kind}.
2f870471 39629
4435e1cc 39630A software breakpoint is implemented by replacing the instruction at
2f870471 39631@var{addr} with a software breakpoint or trap instruction. The
4435e1cc
TT
39632@var{kind} is target-specific and typically indicates the size of the
39633breakpoint in bytes that should be inserted. E.g., the @sc{arm} and
39634@sc{mips} can insert either a 2 or 4 byte breakpoint. Some
39635architectures have additional meanings for @var{kind}
39636(@pxref{Architecture-Specific Protocol Details}); if no
39637architecture-specific value is being used, it should be @samp{0}.
39638@var{kind} is hex-encoded. @var{cond_list} is an optional list of
39639conditional expressions in bytecode form that should be evaluated on
39640the target's side. These are the conditions that should be taken into
39641consideration when deciding if the breakpoint trigger should be
39642reported back to @value{GDBN}.
83364271 39643
f7e6eed5 39644See also the @samp{swbreak} stop reason (@pxref{swbreak stop reason})
4435e1cc 39645for how to best report a software breakpoint event to @value{GDBN}.
f7e6eed5 39646
83364271
LM
39647The @var{cond_list} parameter is comprised of a series of expressions,
39648concatenated without separators. Each expression has the following form:
39649
39650@table @samp
39651
39652@item X @var{len},@var{expr}
39653@var{len} is the length of the bytecode expression and @var{expr} is the
39654actual conditional expression in bytecode form.
39655
39656@end table
39657
d3ce09f5
SS
39658The optional @var{cmd_list} parameter introduces commands that may be
39659run on the target, rather than being reported back to @value{GDBN}.
39660The parameter starts with a numeric flag @var{persist}; if the flag is
39661nonzero, then the breakpoint may remain active and the commands
39662continue to be run even when @value{GDBN} disconnects from the target.
39663Following this flag is a series of expressions concatenated with no
39664separators. Each expression has the following form:
39665
39666@table @samp
39667
39668@item X @var{len},@var{expr}
39669@var{len} is the length of the bytecode expression and @var{expr} is the
0968fbae 39670actual commands expression in bytecode form.
d3ce09f5
SS
39671
39672@end table
39673
2f870471 39674@emph{Implementation note: It is possible for a target to copy or move
4435e1cc 39675code that contains software breakpoints (e.g., when implementing
2f870471
AC
39676overlays). The behavior of this packet, in the presence of such a
39677target, is not defined.}
c906108c 39678
ee2d5c50
AC
39679Reply:
39680@table @samp
2f870471
AC
39681@item OK
39682success
d57350ea 39683@item @w{}
2f870471 39684not supported
b8ff78ce 39685@item E @var{NN}
ee2d5c50 39686for an error
2f870471
AC
39687@end table
39688
a1dcb23a 39689@item z1,@var{addr},@var{kind}
4435e1cc 39690@itemx Z1,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}@r{[};cmds:@var{persist},@var{cmd_list}@dots{}@r{]}
b8ff78ce
JB
39691@cindex @samp{z1} packet
39692@cindex @samp{Z1} packet
39693Insert (@samp{Z1}) or remove (@samp{z1}) a hardware breakpoint at
a1dcb23a 39694address @var{addr}.
2f870471
AC
39695
39696A hardware breakpoint is implemented using a mechanism that is not
4435e1cc
TT
39697dependent on being able to modify the target's memory. The
39698@var{kind}, @var{cond_list}, and @var{cmd_list} arguments have the
39699same meaning as in @samp{Z0} packets.
2f870471
AC
39700
39701@emph{Implementation note: A hardware breakpoint is not affected by code
39702movement.}
39703
39704Reply:
39705@table @samp
ee2d5c50 39706@item OK
2f870471 39707success
d57350ea 39708@item @w{}
2f870471 39709not supported
b8ff78ce 39710@item E @var{NN}
2f870471
AC
39711for an error
39712@end table
39713
a1dcb23a
DJ
39714@item z2,@var{addr},@var{kind}
39715@itemx Z2,@var{addr},@var{kind}
b8ff78ce
JB
39716@cindex @samp{z2} packet
39717@cindex @samp{Z2} packet
a1dcb23a 39718Insert (@samp{Z2}) or remove (@samp{z2}) a write watchpoint at @var{addr}.
697aa1b7 39719The number of bytes to watch is specified by @var{kind}.
2f870471
AC
39720
39721Reply:
39722@table @samp
39723@item OK
39724success
d57350ea 39725@item @w{}
2f870471 39726not supported
b8ff78ce 39727@item E @var{NN}
2f870471
AC
39728for an error
39729@end table
39730
a1dcb23a
DJ
39731@item z3,@var{addr},@var{kind}
39732@itemx Z3,@var{addr},@var{kind}
b8ff78ce
JB
39733@cindex @samp{z3} packet
39734@cindex @samp{Z3} packet
a1dcb23a 39735Insert (@samp{Z3}) or remove (@samp{z3}) a read watchpoint at @var{addr}.
697aa1b7 39736The number of bytes to watch is specified by @var{kind}.
2f870471
AC
39737
39738Reply:
39739@table @samp
39740@item OK
39741success
d57350ea 39742@item @w{}
2f870471 39743not supported
b8ff78ce 39744@item E @var{NN}
2f870471
AC
39745for an error
39746@end table
39747
a1dcb23a
DJ
39748@item z4,@var{addr},@var{kind}
39749@itemx Z4,@var{addr},@var{kind}
b8ff78ce
JB
39750@cindex @samp{z4} packet
39751@cindex @samp{Z4} packet
a1dcb23a 39752Insert (@samp{Z4}) or remove (@samp{z4}) an access watchpoint at @var{addr}.
697aa1b7 39753The number of bytes to watch is specified by @var{kind}.
2f870471
AC
39754
39755Reply:
39756@table @samp
39757@item OK
39758success
d57350ea 39759@item @w{}
2f870471 39760not supported
b8ff78ce 39761@item E @var{NN}
2f870471 39762for an error
ee2d5c50
AC
39763@end table
39764
39765@end table
c906108c 39766
ee2d5c50
AC
39767@node Stop Reply Packets
39768@section Stop Reply Packets
39769@cindex stop reply packets
c906108c 39770
8b23ecc4
SL
39771The @samp{C}, @samp{c}, @samp{S}, @samp{s}, @samp{vCont},
39772@samp{vAttach}, @samp{vRun}, @samp{vStopped}, and @samp{?} packets can
39773receive any of the below as a reply. Except for @samp{?}
39774and @samp{vStopped}, that reply is only returned
b8ff78ce 39775when the target halts. In the below the exact meaning of @dfn{signal
89be2091
DJ
39776number} is defined by the header @file{include/gdb/signals.h} in the
39777@value{GDBN} source code.
c906108c 39778
4435e1cc
TT
39779In non-stop mode, the server will simply reply @samp{OK} to commands
39780such as @samp{vCont}; any stop will be the subject of a future
39781notification. @xref{Remote Non-Stop}.
39782
b8ff78ce
JB
39783As in the description of request packets, we include spaces in the
39784reply templates for clarity; these are not part of the reply packet's
39785syntax. No @value{GDBN} stop reply packet uses spaces to separate its
39786components.
c906108c 39787
b8ff78ce 39788@table @samp
ee2d5c50 39789
b8ff78ce 39790@item S @var{AA}
599b237a 39791The program received signal number @var{AA} (a two-digit hexadecimal
940178d3
JB
39792number). This is equivalent to a @samp{T} response with no
39793@var{n}:@var{r} pairs.
c906108c 39794
b8ff78ce
JB
39795@item T @var{AA} @var{n1}:@var{r1};@var{n2}:@var{r2};@dots{}
39796@cindex @samp{T} packet reply
599b237a 39797The program received signal number @var{AA} (a two-digit hexadecimal
940178d3
JB
39798number). This is equivalent to an @samp{S} response, except that the
39799@samp{@var{n}:@var{r}} pairs can carry values of important registers
39800and other information directly in the stop reply packet, reducing
39801round-trip latency. Single-step and breakpoint traps are reported
39802this way. Each @samp{@var{n}:@var{r}} pair is interpreted as follows:
cfa9d6d9
DJ
39803
39804@itemize @bullet
b8ff78ce 39805@item
599b237a 39806If @var{n} is a hexadecimal number, it is a register number, and the
697aa1b7 39807corresponding @var{r} gives that register's value. The data @var{r} is a
b8ff78ce
JB
39808series of bytes in target byte order, with each byte given by a
39809two-digit hex number.
cfa9d6d9 39810
b8ff78ce 39811@item
b90a069a
SL
39812If @var{n} is @samp{thread}, then @var{r} is the @var{thread-id} of
39813the stopped thread, as specified in @ref{thread-id syntax}.
cfa9d6d9 39814
dc146f7c
VP
39815@item
39816If @var{n} is @samp{core}, then @var{r} is the hexadecimal number of
39817the core on which the stop event was detected.
39818
b8ff78ce 39819@item
cfa9d6d9
DJ
39820If @var{n} is a recognized @dfn{stop reason}, it describes a more
39821specific event that stopped the target. The currently defined stop
697aa1b7 39822reasons are listed below. The @var{aa} should be @samp{05}, the trap
cfa9d6d9
DJ
39823signal. At most one stop reason should be present.
39824
b8ff78ce
JB
39825@item
39826Otherwise, @value{GDBN} should ignore this @samp{@var{n}:@var{r}} pair
39827and go on to the next; this allows us to extend the protocol in the
39828future.
cfa9d6d9
DJ
39829@end itemize
39830
39831The currently defined stop reasons are:
39832
39833@table @samp
39834@item watch
39835@itemx rwatch
39836@itemx awatch
39837The packet indicates a watchpoint hit, and @var{r} is the data address, in
39838hex.
39839
82075af2
JS
39840@item syscall_entry
39841@itemx syscall_return
39842The packet indicates a syscall entry or return, and @var{r} is the
39843syscall number, in hex.
39844
cfa9d6d9
DJ
39845@cindex shared library events, remote reply
39846@item library
39847The packet indicates that the loaded libraries have changed.
39848@value{GDBN} should use @samp{qXfer:libraries:read} to fetch a new
697aa1b7 39849list of loaded libraries. The @var{r} part is ignored.
bacec72f
MS
39850
39851@cindex replay log events, remote reply
39852@item replaylog
39853The packet indicates that the target cannot continue replaying
39854logged execution events, because it has reached the end (or the
39855beginning when executing backward) of the log. The value of @var{r}
39856will be either @samp{begin} or @samp{end}. @xref{Reverse Execution},
39857for more information.
f7e6eed5
PA
39858
39859@item swbreak
39860@anchor{swbreak stop reason}
4435e1cc 39861The packet indicates a software breakpoint instruction was executed,
f7e6eed5
PA
39862irrespective of whether it was @value{GDBN} that planted the
39863breakpoint or the breakpoint is hardcoded in the program. The @var{r}
39864part must be left empty.
39865
39866On some architectures, such as x86, at the architecture level, when a
39867breakpoint instruction executes the program counter points at the
39868breakpoint address plus an offset. On such targets, the stub is
39869responsible for adjusting the PC to point back at the breakpoint
39870address.
39871
39872This packet should not be sent by default; older @value{GDBN} versions
39873did not support it. @value{GDBN} requests it, by supplying an
39874appropriate @samp{qSupported} feature (@pxref{qSupported}). The
39875remote stub must also supply the appropriate @samp{qSupported} feature
39876indicating support.
39877
39878This packet is required for correct non-stop mode operation.
39879
39880@item hwbreak
39881The packet indicates the target stopped for a hardware breakpoint.
39882The @var{r} part must be left empty.
39883
39884The same remarks about @samp{qSupported} and non-stop mode above
39885apply.
0d71eef5
DB
39886
39887@cindex fork events, remote reply
39888@item fork
39889The packet indicates that @code{fork} was called, and @var{r}
39890is the thread ID of the new child process. Refer to
39891@ref{thread-id syntax} for the format of the @var{thread-id}
39892field. This packet is only applicable to targets that support
39893fork events.
39894
39895This packet should not be sent by default; older @value{GDBN} versions
39896did not support it. @value{GDBN} requests it, by supplying an
39897appropriate @samp{qSupported} feature (@pxref{qSupported}). The
39898remote stub must also supply the appropriate @samp{qSupported} feature
39899indicating support.
39900
39901@cindex vfork events, remote reply
39902@item vfork
39903The packet indicates that @code{vfork} was called, and @var{r}
39904is the thread ID of the new child process. Refer to
39905@ref{thread-id syntax} for the format of the @var{thread-id}
39906field. This packet is only applicable to targets that support
39907vfork events.
39908
39909This packet should not be sent by default; older @value{GDBN} versions
39910did not support it. @value{GDBN} requests it, by supplying an
39911appropriate @samp{qSupported} feature (@pxref{qSupported}). The
39912remote stub must also supply the appropriate @samp{qSupported} feature
39913indicating support.
39914
39915@cindex vforkdone events, remote reply
39916@item vforkdone
e68fa6f0
PA
39917The packet indicates that a child process created by a vfork
39918has either called @code{exec} or terminated, so that the
39919address spaces of the parent and child process are no longer
39920shared. The @var{r} part is ignored. This packet is only
39921applicable to targets that support vforkdone events.
0d71eef5
DB
39922
39923This packet should not be sent by default; older @value{GDBN} versions
39924did not support it. @value{GDBN} requests it, by supplying an
39925appropriate @samp{qSupported} feature (@pxref{qSupported}). The
39926remote stub must also supply the appropriate @samp{qSupported} feature
39927indicating support.
39928
b459a59b
DB
39929@cindex exec events, remote reply
39930@item exec
39931The packet indicates that @code{execve} was called, and @var{r}
39932is the absolute pathname of the file that was executed, in hex.
39933This packet is only applicable to targets that support exec events.
39934
39935This packet should not be sent by default; older @value{GDBN} versions
39936did not support it. @value{GDBN} requests it, by supplying an
39937appropriate @samp{qSupported} feature (@pxref{qSupported}). The
39938remote stub must also supply the appropriate @samp{qSupported} feature
39939indicating support.
39940
65706a29
PA
39941@cindex thread create event, remote reply
39942@anchor{thread create event}
39943@item create
39944The packet indicates that the thread was just created. The new thread
39945is stopped until @value{GDBN} sets it running with a resumption packet
39946(@pxref{vCont packet}). This packet should not be sent by default;
39947@value{GDBN} requests it with the @ref{QThreadEvents} packet. See
4435e1cc
TT
39948also the @samp{w} (@pxref{thread exit event}) remote reply below. The
39949@var{r} part is ignored.
65706a29 39950
cfa9d6d9 39951@end table
ee2d5c50 39952
b8ff78ce 39953@item W @var{AA}
b90a069a 39954@itemx W @var{AA} ; process:@var{pid}
8e04817f 39955The process exited, and @var{AA} is the exit status. This is only
ee2d5c50
AC
39956applicable to certain targets.
39957
4435e1cc
TT
39958The second form of the response, including the process ID of the
39959exited process, can be used only when @value{GDBN} has reported
39960support for multiprocess protocol extensions; see @ref{multiprocess
39961extensions}. Both @var{AA} and @var{pid} are formatted as big-endian
39962hex strings.
b90a069a 39963
b8ff78ce 39964@item X @var{AA}
b90a069a 39965@itemx X @var{AA} ; process:@var{pid}
8e04817f 39966The process terminated with signal @var{AA}.
c906108c 39967
b90a069a
SL
39968The second form of the response, including the process ID of the
39969terminated process, can be used only when @value{GDBN} has reported
39970support for multiprocess protocol extensions; see @ref{multiprocess
4435e1cc
TT
39971extensions}. Both @var{AA} and @var{pid} are formatted as big-endian
39972hex strings.
b90a069a 39973
65706a29
PA
39974@anchor{thread exit event}
39975@cindex thread exit event, remote reply
39976@item w @var{AA} ; @var{tid}
39977
39978The thread exited, and @var{AA} is the exit status. This response
39979should not be sent by default; @value{GDBN} requests it with the
39980@ref{QThreadEvents} packet. See also @ref{thread create event} above.
4435e1cc 39981@var{AA} is formatted as a big-endian hex string.
65706a29 39982
f2faf941
PA
39983@item N
39984There are no resumed threads left in the target. In other words, even
39985though the process is alive, the last resumed thread has exited. For
39986example, say the target process has two threads: thread 1 and thread
399872. The client leaves thread 1 stopped, and resumes thread 2, which
39988subsequently exits. At this point, even though the process is still
39989alive, and thus no @samp{W} stop reply is sent, no thread is actually
39990executing either. The @samp{N} stop reply thus informs the client
39991that it can stop waiting for stop replies. This packet should not be
39992sent by default; older @value{GDBN} versions did not support it.
39993@value{GDBN} requests it, by supplying an appropriate
39994@samp{qSupported} feature (@pxref{qSupported}). The remote stub must
39995also supply the appropriate @samp{qSupported} feature indicating
39996support.
39997
b8ff78ce
JB
39998@item O @var{XX}@dots{}
39999@samp{@var{XX}@dots{}} is hex encoding of @sc{ascii} data, to be
40000written as the program's console output. This can happen at any time
40001while the program is running and the debugger should continue to wait
8b23ecc4 40002for @samp{W}, @samp{T}, etc. This reply is not permitted in non-stop mode.
0ce1b118 40003
b8ff78ce 40004@item F @var{call-id},@var{parameter}@dots{}
0ce1b118
CV
40005@var{call-id} is the identifier which says which host system call should
40006be called. This is just the name of the function. Translation into the
40007correct system call is only applicable as it's defined in @value{GDBN}.
79a6e687 40008@xref{File-I/O Remote Protocol Extension}, for a list of implemented
0ce1b118
CV
40009system calls.
40010
b8ff78ce
JB
40011@samp{@var{parameter}@dots{}} is a list of parameters as defined for
40012this very system call.
0ce1b118 40013
b8ff78ce
JB
40014The target replies with this packet when it expects @value{GDBN} to
40015call a host system call on behalf of the target. @value{GDBN} replies
40016with an appropriate @samp{F} packet and keeps up waiting for the next
40017reply packet from the target. The latest @samp{C}, @samp{c}, @samp{S}
79a6e687
BW
40018or @samp{s} action is expected to be continued. @xref{File-I/O Remote
40019Protocol Extension}, for more details.
0ce1b118 40020
ee2d5c50
AC
40021@end table
40022
40023@node General Query Packets
40024@section General Query Packets
9c16f35a 40025@cindex remote query requests
c906108c 40026
5f3bebba
JB
40027Packets starting with @samp{q} are @dfn{general query packets};
40028packets starting with @samp{Q} are @dfn{general set packets}. General
40029query and set packets are a semi-unified form for retrieving and
40030sending information to and from the stub.
40031
40032The initial letter of a query or set packet is followed by a name
40033indicating what sort of thing the packet applies to. For example,
40034@value{GDBN} may use a @samp{qSymbol} packet to exchange symbol
40035definitions with the stub. These packet names follow some
40036conventions:
40037
40038@itemize @bullet
40039@item
40040The name must not contain commas, colons or semicolons.
40041@item
40042Most @value{GDBN} query and set packets have a leading upper case
40043letter.
40044@item
40045The names of custom vendor packets should use a company prefix, in
40046lower case, followed by a period. For example, packets designed at
40047the Acme Corporation might begin with @samp{qacme.foo} (for querying
40048foos) or @samp{Qacme.bar} (for setting bars).
40049@end itemize
40050
aa56d27a
JB
40051The name of a query or set packet should be separated from any
40052parameters by a @samp{:}; the parameters themselves should be
40053separated by @samp{,} or @samp{;}. Stubs must be careful to match the
369af7bd
DJ
40054full packet name, and check for a separator or the end of the packet,
40055in case two packet names share a common prefix. New packets should not begin
40056with @samp{qC}, @samp{qP}, or @samp{qL}@footnote{The @samp{qP} and @samp{qL}
40057packets predate these conventions, and have arguments without any terminator
40058for the packet name; we suspect they are in widespread use in places that
40059are difficult to upgrade. The @samp{qC} packet has no arguments, but some
40060existing stubs (e.g.@: RedBoot) are known to not check for the end of the
40061packet.}.
c906108c 40062
b8ff78ce
JB
40063Like the descriptions of the other packets, each description here
40064has a template showing the packet's overall syntax, followed by an
40065explanation of the packet's meaning. We include spaces in some of the
40066templates for clarity; these are not part of the packet's syntax. No
40067@value{GDBN} packet uses spaces to separate its components.
40068
5f3bebba
JB
40069Here are the currently defined query and set packets:
40070
b8ff78ce 40071@table @samp
c906108c 40072
d1feda86 40073@item QAgent:1
af4238e5 40074@itemx QAgent:0
d1feda86
YQ
40075Turn on or off the agent as a helper to perform some debugging operations
40076delegated from @value{GDBN} (@pxref{Control Agent}).
40077
d914c394
SS
40078@item QAllow:@var{op}:@var{val}@dots{}
40079@cindex @samp{QAllow} packet
40080Specify which operations @value{GDBN} expects to request of the
40081target, as a semicolon-separated list of operation name and value
40082pairs. Possible values for @var{op} include @samp{WriteReg},
40083@samp{WriteMem}, @samp{InsertBreak}, @samp{InsertTrace},
40084@samp{InsertFastTrace}, and @samp{Stop}. @var{val} is either 0,
40085indicating that @value{GDBN} will not request the operation, or 1,
40086indicating that it may. (The target can then use this to set up its
40087own internals optimally, for instance if the debugger never expects to
40088insert breakpoints, it may not need to install its own trap handler.)
40089
b8ff78ce 40090@item qC
9c16f35a 40091@cindex current thread, remote request
b8ff78ce 40092@cindex @samp{qC} packet
b90a069a 40093Return the current thread ID.
ee2d5c50
AC
40094
40095Reply:
40096@table @samp
b90a069a
SL
40097@item QC @var{thread-id}
40098Where @var{thread-id} is a thread ID as documented in
40099@ref{thread-id syntax}.
b8ff78ce 40100@item @r{(anything else)}
b90a069a 40101Any other reply implies the old thread ID.
ee2d5c50
AC
40102@end table
40103
b8ff78ce 40104@item qCRC:@var{addr},@var{length}
ff2587ec 40105@cindex CRC of memory block, remote request
b8ff78ce 40106@cindex @samp{qCRC} packet
936d2992 40107@anchor{qCRC packet}
99e008fe
EZ
40108Compute the CRC checksum of a block of memory using CRC-32 defined in
40109IEEE 802.3. The CRC is computed byte at a time, taking the most
40110significant bit of each byte first. The initial pattern code
40111@code{0xffffffff} is used to ensure leading zeros affect the CRC.
40112
40113@emph{Note:} This is the same CRC used in validating separate debug
40114files (@pxref{Separate Debug Files, , Debugging Information in Separate
40115Files}). However the algorithm is slightly different. When validating
40116separate debug files, the CRC is computed taking the @emph{least}
40117significant bit of each byte first, and the final result is inverted to
40118detect trailing zeros.
40119
ff2587ec
WZ
40120Reply:
40121@table @samp
b8ff78ce 40122@item E @var{NN}
ff2587ec 40123An error (such as memory fault)
b8ff78ce
JB
40124@item C @var{crc32}
40125The specified memory region's checksum is @var{crc32}.
ff2587ec
WZ
40126@end table
40127
03583c20
UW
40128@item QDisableRandomization:@var{value}
40129@cindex disable address space randomization, remote request
40130@cindex @samp{QDisableRandomization} packet
40131Some target operating systems will randomize the virtual address space
40132of the inferior process as a security feature, but provide a feature
40133to disable such randomization, e.g.@: to allow for a more deterministic
40134debugging experience. On such systems, this packet with a @var{value}
40135of 1 directs the target to disable address space randomization for
40136processes subsequently started via @samp{vRun} packets, while a packet
40137with a @var{value} of 0 tells the target to enable address space
40138randomization.
40139
40140This packet is only available in extended mode (@pxref{extended mode}).
40141
40142Reply:
40143@table @samp
40144@item OK
40145The request succeeded.
40146
40147@item E @var{nn}
697aa1b7 40148An error occurred. The error number @var{nn} is given as hex digits.
03583c20 40149
d57350ea 40150@item @w{}
03583c20
UW
40151An empty reply indicates that @samp{QDisableRandomization} is not supported
40152by the stub.
40153@end table
40154
40155This packet is not probed by default; the remote stub must request it,
40156by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40157This should only be done on targets that actually support disabling
40158address space randomization.
40159
aefd8b33
SDJ
40160@item QStartupWithShell:@var{value}
40161@cindex startup with shell, remote request
40162@cindex @samp{QStartupWithShell} packet
40163On UNIX-like targets, it is possible to start the inferior using a
40164shell program. This is the default behavior on both @value{GDBN} and
40165@command{gdbserver} (@pxref{set startup-with-shell}). This packet is
40166used to inform @command{gdbserver} whether it should start the
40167inferior using a shell or not.
40168
40169If @var{value} is @samp{0}, @command{gdbserver} will not use a shell
40170to start the inferior. If @var{value} is @samp{1},
40171@command{gdbserver} will use a shell to start the inferior. All other
40172values are considered an error.
40173
40174This packet is only available in extended mode (@pxref{extended
40175mode}).
40176
40177Reply:
40178@table @samp
40179@item OK
40180The request succeeded.
40181
40182@item E @var{nn}
40183An error occurred. The error number @var{nn} is given as hex digits.
40184@end table
40185
40186This packet is not probed by default; the remote stub must request it,
40187by supplying an appropriate @samp{qSupported} response
40188(@pxref{qSupported}). This should only be done on targets that
40189actually support starting the inferior using a shell.
40190
40191Use of this packet is controlled by the @code{set startup-with-shell}
40192command; @pxref{set startup-with-shell}.
40193
0a2dde4a
SDJ
40194@item QEnvironmentHexEncoded:@var{hex-value}
40195@anchor{QEnvironmentHexEncoded}
40196@cindex set environment variable, remote request
40197@cindex @samp{QEnvironmentHexEncoded} packet
40198On UNIX-like targets, it is possible to set environment variables that
40199will be passed to the inferior during the startup process. This
40200packet is used to inform @command{gdbserver} of an environment
40201variable that has been defined by the user on @value{GDBN} (@pxref{set
40202environment}).
40203
40204The packet is composed by @var{hex-value}, an hex encoded
40205representation of the @var{name=value} format representing an
40206environment variable. The name of the environment variable is
40207represented by @var{name}, and the value to be assigned to the
40208environment variable is represented by @var{value}. If the variable
40209has no value (i.e., the value is @code{null}), then @var{value} will
40210not be present.
40211
40212This packet is only available in extended mode (@pxref{extended
40213mode}).
40214
40215Reply:
40216@table @samp
40217@item OK
40218The request succeeded.
40219@end table
40220
40221This packet is not probed by default; the remote stub must request it,
40222by supplying an appropriate @samp{qSupported} response
40223(@pxref{qSupported}). This should only be done on targets that
40224actually support passing environment variables to the starting
40225inferior.
40226
40227This packet is related to the @code{set environment} command;
40228@pxref{set environment}.
40229
40230@item QEnvironmentUnset:@var{hex-value}
40231@anchor{QEnvironmentUnset}
40232@cindex unset environment variable, remote request
40233@cindex @samp{QEnvironmentUnset} packet
40234On UNIX-like targets, it is possible to unset environment variables
40235before starting the inferior in the remote target. This packet is
40236used to inform @command{gdbserver} of an environment variable that has
40237been unset by the user on @value{GDBN} (@pxref{unset environment}).
40238
40239The packet is composed by @var{hex-value}, an hex encoded
40240representation of the name of the environment variable to be unset.
40241
40242This packet is only available in extended mode (@pxref{extended
40243mode}).
40244
40245Reply:
40246@table @samp
40247@item OK
40248The request succeeded.
40249@end table
40250
40251This packet is not probed by default; the remote stub must request it,
40252by supplying an appropriate @samp{qSupported} response
40253(@pxref{qSupported}). This should only be done on targets that
40254actually support passing environment variables to the starting
40255inferior.
40256
40257This packet is related to the @code{unset environment} command;
40258@pxref{unset environment}.
40259
40260@item QEnvironmentReset
40261@anchor{QEnvironmentReset}
40262@cindex reset environment, remote request
40263@cindex @samp{QEnvironmentReset} packet
40264On UNIX-like targets, this packet is used to reset the state of
40265environment variables in the remote target before starting the
40266inferior. In this context, reset means unsetting all environment
40267variables that were previously set by the user (i.e., were not
40268initially present in the environment). It is sent to
40269@command{gdbserver} before the @samp{QEnvironmentHexEncoded}
40270(@pxref{QEnvironmentHexEncoded}) and the @samp{QEnvironmentUnset}
40271(@pxref{QEnvironmentUnset}) packets.
40272
40273This packet is only available in extended mode (@pxref{extended
40274mode}).
40275
40276Reply:
40277@table @samp
40278@item OK
40279The request succeeded.
40280@end table
40281
40282This packet is not probed by default; the remote stub must request it,
40283by supplying an appropriate @samp{qSupported} response
40284(@pxref{qSupported}). This should only be done on targets that
40285actually support passing environment variables to the starting
40286inferior.
40287
bc3b087d
SDJ
40288@item QSetWorkingDir:@r{[}@var{directory}@r{]}
40289@anchor{QSetWorkingDir packet}
40290@cindex set working directory, remote request
40291@cindex @samp{QSetWorkingDir} packet
40292This packet is used to inform the remote server of the intended
40293current working directory for programs that are going to be executed.
40294
40295The packet is composed by @var{directory}, an hex encoded
40296representation of the directory that the remote inferior will use as
40297its current working directory. If @var{directory} is an empty string,
40298the remote server should reset the inferior's current working
40299directory to its original, empty value.
40300
40301This packet is only available in extended mode (@pxref{extended
40302mode}).
40303
40304Reply:
40305@table @samp
40306@item OK
40307The request succeeded.
40308@end table
40309
b8ff78ce
JB
40310@item qfThreadInfo
40311@itemx qsThreadInfo
9c16f35a 40312@cindex list active threads, remote request
b8ff78ce
JB
40313@cindex @samp{qfThreadInfo} packet
40314@cindex @samp{qsThreadInfo} packet
b90a069a 40315Obtain a list of all active thread IDs from the target (OS). Since there
8e04817f
AC
40316may be too many active threads to fit into one reply packet, this query
40317works iteratively: it may require more than one query/reply sequence to
40318obtain the entire list of threads. The first query of the sequence will
b8ff78ce
JB
40319be the @samp{qfThreadInfo} query; subsequent queries in the
40320sequence will be the @samp{qsThreadInfo} query.
ee2d5c50 40321
b8ff78ce 40322NOTE: This packet replaces the @samp{qL} query (see below).
ee2d5c50
AC
40323
40324Reply:
40325@table @samp
b90a069a
SL
40326@item m @var{thread-id}
40327A single thread ID
40328@item m @var{thread-id},@var{thread-id}@dots{}
40329a comma-separated list of thread IDs
b8ff78ce
JB
40330@item l
40331(lower case letter @samp{L}) denotes end of list.
ee2d5c50
AC
40332@end table
40333
40334In response to each query, the target will reply with a list of one or
b90a069a 40335more thread IDs, separated by commas.
e1aac25b 40336@value{GDBN} will respond to each reply with a request for more thread
b8ff78ce 40337ids (using the @samp{qs} form of the query), until the target responds
501994c0 40338with @samp{l} (lower-case ell, for @dfn{last}).
b90a069a
SL
40339Refer to @ref{thread-id syntax}, for the format of the @var{thread-id}
40340fields.
c906108c 40341
8dfcab11
DT
40342@emph{Note: @value{GDBN} will send the @code{qfThreadInfo} query during the
40343initial connection with the remote target, and the very first thread ID
40344mentioned in the reply will be stopped by @value{GDBN} in a subsequent
40345message. Therefore, the stub should ensure that the first thread ID in
40346the @code{qfThreadInfo} reply is suitable for being stopped by @value{GDBN}.}
40347
b8ff78ce 40348@item qGetTLSAddr:@var{thread-id},@var{offset},@var{lm}
ff2587ec 40349@cindex get thread-local storage address, remote request
b8ff78ce 40350@cindex @samp{qGetTLSAddr} packet
ff2587ec
WZ
40351Fetch the address associated with thread local storage specified
40352by @var{thread-id}, @var{offset}, and @var{lm}.
40353
b90a069a
SL
40354@var{thread-id} is the thread ID associated with the
40355thread for which to fetch the TLS address. @xref{thread-id syntax}.
ff2587ec
WZ
40356
40357@var{offset} is the (big endian, hex encoded) offset associated with the
40358thread local variable. (This offset is obtained from the debug
40359information associated with the variable.)
40360
db2e3e2e 40361@var{lm} is the (big endian, hex encoded) OS/ABI-specific encoding of the
7a9dd1b2 40362load module associated with the thread local storage. For example,
ff2587ec
WZ
40363a @sc{gnu}/Linux system will pass the link map address of the shared
40364object associated with the thread local storage under consideration.
40365Other operating environments may choose to represent the load module
40366differently, so the precise meaning of this parameter will vary.
ee2d5c50
AC
40367
40368Reply:
b8ff78ce
JB
40369@table @samp
40370@item @var{XX}@dots{}
ff2587ec
WZ
40371Hex encoded (big endian) bytes representing the address of the thread
40372local storage requested.
40373
b8ff78ce 40374@item E @var{nn}
697aa1b7 40375An error occurred. The error number @var{nn} is given as hex digits.
ff2587ec 40376
d57350ea 40377@item @w{}
b8ff78ce 40378An empty reply indicates that @samp{qGetTLSAddr} is not supported by the stub.
ee2d5c50
AC
40379@end table
40380
711e434b
PM
40381@item qGetTIBAddr:@var{thread-id}
40382@cindex get thread information block address
40383@cindex @samp{qGetTIBAddr} packet
40384Fetch address of the Windows OS specific Thread Information Block.
40385
40386@var{thread-id} is the thread ID associated with the thread.
40387
40388Reply:
40389@table @samp
40390@item @var{XX}@dots{}
40391Hex encoded (big endian) bytes representing the linear address of the
40392thread information block.
40393
40394@item E @var{nn}
40395An error occured. This means that either the thread was not found, or the
40396address could not be retrieved.
40397
d57350ea 40398@item @w{}
711e434b
PM
40399An empty reply indicates that @samp{qGetTIBAddr} is not supported by the stub.
40400@end table
40401
b8ff78ce 40402@item qL @var{startflag} @var{threadcount} @var{nextthread}
8e04817f
AC
40403Obtain thread information from RTOS. Where: @var{startflag} (one hex
40404digit) is one to indicate the first query and zero to indicate a
40405subsequent query; @var{threadcount} (two hex digits) is the maximum
40406number of threads the response packet can contain; and @var{nextthread}
40407(eight hex digits), for subsequent queries (@var{startflag} is zero), is
40408returned in the response as @var{argthread}.
ee2d5c50 40409
b8ff78ce 40410Don't use this packet; use the @samp{qfThreadInfo} query instead (see above).
ee2d5c50
AC
40411
40412Reply:
40413@table @samp
b8ff78ce 40414@item qM @var{count} @var{done} @var{argthread} @var{thread}@dots{}
8e04817f
AC
40415Where: @var{count} (two hex digits) is the number of threads being
40416returned; @var{done} (one hex digit) is zero to indicate more threads
40417and one indicates no further threads; @var{argthreadid} (eight hex
b8ff78ce 40418digits) is @var{nextthread} from the request packet; @var{thread}@dots{}
697aa1b7
EZ
40419is a sequence of thread IDs, @var{threadid} (eight hex
40420digits), from the target. See @code{remote.c:parse_threadlist_response()}.
ee2d5c50 40421@end table
c906108c 40422
b8ff78ce 40423@item qOffsets
9c16f35a 40424@cindex section offsets, remote request
b8ff78ce 40425@cindex @samp{qOffsets} packet
31d99776
DJ
40426Get section offsets that the target used when relocating the downloaded
40427image.
c906108c 40428
ee2d5c50
AC
40429Reply:
40430@table @samp
31d99776
DJ
40431@item Text=@var{xxx};Data=@var{yyy}@r{[};Bss=@var{zzz}@r{]}
40432Relocate the @code{Text} section by @var{xxx} from its original address.
40433Relocate the @code{Data} section by @var{yyy} from its original address.
40434If the object file format provides segment information (e.g.@: @sc{elf}
40435@samp{PT_LOAD} program headers), @value{GDBN} will relocate entire
40436segments by the supplied offsets.
40437
40438@emph{Note: while a @code{Bss} offset may be included in the response,
40439@value{GDBN} ignores this and instead applies the @code{Data} offset
40440to the @code{Bss} section.}
40441
40442@item TextSeg=@var{xxx}@r{[};DataSeg=@var{yyy}@r{]}
40443Relocate the first segment of the object file, which conventionally
40444contains program code, to a starting address of @var{xxx}. If
40445@samp{DataSeg} is specified, relocate the second segment, which
40446conventionally contains modifiable data, to a starting address of
40447@var{yyy}. @value{GDBN} will report an error if the object file
40448does not contain segment information, or does not contain at least
40449as many segments as mentioned in the reply. Extra segments are
40450kept at fixed offsets relative to the last relocated segment.
ee2d5c50
AC
40451@end table
40452
b90a069a 40453@item qP @var{mode} @var{thread-id}
9c16f35a 40454@cindex thread information, remote request
b8ff78ce 40455@cindex @samp{qP} packet
b90a069a
SL
40456Returns information on @var{thread-id}. Where: @var{mode} is a hex
40457encoded 32 bit mode; @var{thread-id} is a thread ID
40458(@pxref{thread-id syntax}).
ee2d5c50 40459
aa56d27a
JB
40460Don't use this packet; use the @samp{qThreadExtraInfo} query instead
40461(see below).
40462
b8ff78ce 40463Reply: see @code{remote.c:remote_unpack_thread_info_response()}.
c906108c 40464
8b23ecc4 40465@item QNonStop:1
687e43a4 40466@itemx QNonStop:0
8b23ecc4
SL
40467@cindex non-stop mode, remote request
40468@cindex @samp{QNonStop} packet
40469@anchor{QNonStop}
40470Enter non-stop (@samp{QNonStop:1}) or all-stop (@samp{QNonStop:0}) mode.
40471@xref{Remote Non-Stop}, for more information.
40472
40473Reply:
40474@table @samp
40475@item OK
40476The request succeeded.
40477
40478@item E @var{nn}
697aa1b7 40479An error occurred. The error number @var{nn} is given as hex digits.
8b23ecc4 40480
d57350ea 40481@item @w{}
8b23ecc4
SL
40482An empty reply indicates that @samp{QNonStop} is not supported by
40483the stub.
40484@end table
40485
40486This packet is not probed by default; the remote stub must request it,
40487by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40488Use of this packet is controlled by the @code{set non-stop} command;
40489@pxref{Non-Stop Mode}.
40490
82075af2
JS
40491@item QCatchSyscalls:1 @r{[};@var{sysno}@r{]}@dots{}
40492@itemx QCatchSyscalls:0
40493@cindex catch syscalls from inferior, remote request
40494@cindex @samp{QCatchSyscalls} packet
40495@anchor{QCatchSyscalls}
40496Enable (@samp{QCatchSyscalls:1}) or disable (@samp{QCatchSyscalls:0})
40497catching syscalls from the inferior process.
40498
40499For @samp{QCatchSyscalls:1}, each listed syscall @var{sysno} (encoded
40500in hex) should be reported to @value{GDBN}. If no syscall @var{sysno}
40501is listed, every system call should be reported.
40502
40503Note that if a syscall not in the list is reported, @value{GDBN} will
40504still filter the event according to its own list from all corresponding
40505@code{catch syscall} commands. However, it is more efficient to only
40506report the requested syscalls.
40507
40508Multiple @samp{QCatchSyscalls:1} packets do not combine; any earlier
40509@samp{QCatchSyscalls:1} list is completely replaced by the new list.
40510
40511If the inferior process execs, the state of @samp{QCatchSyscalls} is
40512kept for the new process too. On targets where exec may affect syscall
40513numbers, for example with exec between 32 and 64-bit processes, the
40514client should send a new packet with the new syscall list.
40515
40516Reply:
40517@table @samp
40518@item OK
40519The request succeeded.
40520
40521@item E @var{nn}
40522An error occurred. @var{nn} are hex digits.
40523
40524@item @w{}
40525An empty reply indicates that @samp{QCatchSyscalls} is not supported by
40526the stub.
40527@end table
40528
40529Use of this packet is controlled by the @code{set remote catch-syscalls}
40530command (@pxref{Remote Configuration, set remote catch-syscalls}).
40531This packet is not probed by default; the remote stub must request it,
40532by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40533
89be2091
DJ
40534@item QPassSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
40535@cindex pass signals to inferior, remote request
40536@cindex @samp{QPassSignals} packet
23181151 40537@anchor{QPassSignals}
89be2091
DJ
40538Each listed @var{signal} should be passed directly to the inferior process.
40539Signals are numbered identically to continue packets and stop replies
40540(@pxref{Stop Reply Packets}). Each @var{signal} list item should be
40541strictly greater than the previous item. These signals do not need to stop
40542the inferior, or be reported to @value{GDBN}. All other signals should be
40543reported to @value{GDBN}. Multiple @samp{QPassSignals} packets do not
40544combine; any earlier @samp{QPassSignals} list is completely replaced by the
40545new list. This packet improves performance when using @samp{handle
40546@var{signal} nostop noprint pass}.
40547
40548Reply:
40549@table @samp
40550@item OK
40551The request succeeded.
40552
40553@item E @var{nn}
697aa1b7 40554An error occurred. The error number @var{nn} is given as hex digits.
89be2091 40555
d57350ea 40556@item @w{}
89be2091
DJ
40557An empty reply indicates that @samp{QPassSignals} is not supported by
40558the stub.
40559@end table
40560
40561Use of this packet is controlled by the @code{set remote pass-signals}
79a6e687 40562command (@pxref{Remote Configuration, set remote pass-signals}).
89be2091
DJ
40563This packet is not probed by default; the remote stub must request it,
40564by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40565
9b224c5e
PA
40566@item QProgramSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
40567@cindex signals the inferior may see, remote request
40568@cindex @samp{QProgramSignals} packet
40569@anchor{QProgramSignals}
40570Each listed @var{signal} may be delivered to the inferior process.
40571Others should be silently discarded.
40572
40573In some cases, the remote stub may need to decide whether to deliver a
40574signal to the program or not without @value{GDBN} involvement. One
40575example of that is while detaching --- the program's threads may have
40576stopped for signals that haven't yet had a chance of being reported to
40577@value{GDBN}, and so the remote stub can use the signal list specified
40578by this packet to know whether to deliver or ignore those pending
40579signals.
40580
40581This does not influence whether to deliver a signal as requested by a
40582resumption packet (@pxref{vCont packet}).
40583
40584Signals are numbered identically to continue packets and stop replies
40585(@pxref{Stop Reply Packets}). Each @var{signal} list item should be
40586strictly greater than the previous item. Multiple
40587@samp{QProgramSignals} packets do not combine; any earlier
40588@samp{QProgramSignals} list is completely replaced by the new list.
40589
40590Reply:
40591@table @samp
40592@item OK
40593The request succeeded.
40594
40595@item E @var{nn}
697aa1b7 40596An error occurred. The error number @var{nn} is given as hex digits.
9b224c5e 40597
d57350ea 40598@item @w{}
9b224c5e
PA
40599An empty reply indicates that @samp{QProgramSignals} is not supported
40600by the stub.
40601@end table
40602
40603Use of this packet is controlled by the @code{set remote program-signals}
40604command (@pxref{Remote Configuration, set remote program-signals}).
40605This packet is not probed by default; the remote stub must request it,
40606by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40607
65706a29
PA
40608@anchor{QThreadEvents}
40609@item QThreadEvents:1
40610@itemx QThreadEvents:0
40611@cindex thread create/exit events, remote request
40612@cindex @samp{QThreadEvents} packet
40613
40614Enable (@samp{QThreadEvents:1}) or disable (@samp{QThreadEvents:0})
40615reporting of thread create and exit events. @xref{thread create
40616event}, for the reply specifications. For example, this is used in
40617non-stop mode when @value{GDBN} stops a set of threads and
40618synchronously waits for the their corresponding stop replies. Without
40619exit events, if one of the threads exits, @value{GDBN} would hang
40620forever not knowing that it should no longer expect a stop for that
40621same thread. @value{GDBN} does not enable this feature unless the
40622stub reports that it supports it by including @samp{QThreadEvents+} in
40623its @samp{qSupported} reply.
40624
40625Reply:
40626@table @samp
40627@item OK
40628The request succeeded.
40629
40630@item E @var{nn}
40631An error occurred. The error number @var{nn} is given as hex digits.
40632
40633@item @w{}
40634An empty reply indicates that @samp{QThreadEvents} is not supported by
40635the stub.
40636@end table
40637
40638Use of this packet is controlled by the @code{set remote thread-events}
40639command (@pxref{Remote Configuration, set remote thread-events}).
40640
b8ff78ce 40641@item qRcmd,@var{command}
ff2587ec 40642@cindex execute remote command, remote request
b8ff78ce 40643@cindex @samp{qRcmd} packet
ff2587ec 40644@var{command} (hex encoded) is passed to the local interpreter for
b8ff78ce
JB
40645execution. Invalid commands should be reported using the output
40646string. Before the final result packet, the target may also respond
40647with a number of intermediate @samp{O@var{output}} console output
40648packets. @emph{Implementors should note that providing access to a
40649stubs's interpreter may have security implications}.
fa93a9d8 40650
ff2587ec
WZ
40651Reply:
40652@table @samp
40653@item OK
40654A command response with no output.
40655@item @var{OUTPUT}
40656A command response with the hex encoded output string @var{OUTPUT}.
b8ff78ce 40657@item E @var{NN}
ff2587ec 40658Indicate a badly formed request.
d57350ea 40659@item @w{}
b8ff78ce 40660An empty reply indicates that @samp{qRcmd} is not recognized.
ff2587ec 40661@end table
fa93a9d8 40662
aa56d27a
JB
40663(Note that the @code{qRcmd} packet's name is separated from the
40664command by a @samp{,}, not a @samp{:}, contrary to the naming
40665conventions above. Please don't use this packet as a model for new
40666packets.)
40667
08388c79
DE
40668@item qSearch:memory:@var{address};@var{length};@var{search-pattern}
40669@cindex searching memory, in remote debugging
5c4808ca 40670@ifnotinfo
08388c79 40671@cindex @samp{qSearch:memory} packet
5c4808ca
EZ
40672@end ifnotinfo
40673@cindex @samp{qSearch memory} packet
08388c79
DE
40674@anchor{qSearch memory}
40675Search @var{length} bytes at @var{address} for @var{search-pattern}.
697aa1b7
EZ
40676Both @var{address} and @var{length} are encoded in hex;
40677@var{search-pattern} is a sequence of bytes, also hex encoded.
08388c79
DE
40678
40679Reply:
40680@table @samp
40681@item 0
40682The pattern was not found.
40683@item 1,address
40684The pattern was found at @var{address}.
40685@item E @var{NN}
40686A badly formed request or an error was encountered while searching memory.
d57350ea 40687@item @w{}
08388c79
DE
40688An empty reply indicates that @samp{qSearch:memory} is not recognized.
40689@end table
40690
a6f3e723
SL
40691@item QStartNoAckMode
40692@cindex @samp{QStartNoAckMode} packet
40693@anchor{QStartNoAckMode}
40694Request that the remote stub disable the normal @samp{+}/@samp{-}
40695protocol acknowledgments (@pxref{Packet Acknowledgment}).
40696
40697Reply:
40698@table @samp
40699@item OK
40700The stub has switched to no-acknowledgment mode.
6b92c0d3 40701@value{GDBN} acknowledges this response,
a6f3e723
SL
40702but neither the stub nor @value{GDBN} shall send or expect further
40703@samp{+}/@samp{-} acknowledgments in the current connection.
d57350ea 40704@item @w{}
a6f3e723
SL
40705An empty reply indicates that the stub does not support no-acknowledgment mode.
40706@end table
40707
be2a5f71
DJ
40708@item qSupported @r{[}:@var{gdbfeature} @r{[};@var{gdbfeature}@r{]}@dots{} @r{]}
40709@cindex supported packets, remote query
40710@cindex features of the remote protocol
40711@cindex @samp{qSupported} packet
0876f84a 40712@anchor{qSupported}
be2a5f71
DJ
40713Tell the remote stub about features supported by @value{GDBN}, and
40714query the stub for features it supports. This packet allows
40715@value{GDBN} and the remote stub to take advantage of each others'
40716features. @samp{qSupported} also consolidates multiple feature probes
40717at startup, to improve @value{GDBN} performance---a single larger
40718packet performs better than multiple smaller probe packets on
40719high-latency links. Some features may enable behavior which must not
40720be on by default, e.g.@: because it would confuse older clients or
40721stubs. Other features may describe packets which could be
40722automatically probed for, but are not. These features must be
40723reported before @value{GDBN} will use them. This ``default
40724unsupported'' behavior is not appropriate for all packets, but it
40725helps to keep the initial connection time under control with new
40726versions of @value{GDBN} which support increasing numbers of packets.
40727
40728Reply:
40729@table @samp
40730@item @var{stubfeature} @r{[};@var{stubfeature}@r{]}@dots{}
40731The stub supports or does not support each returned @var{stubfeature},
40732depending on the form of each @var{stubfeature} (see below for the
40733possible forms).
d57350ea 40734@item @w{}
be2a5f71
DJ
40735An empty reply indicates that @samp{qSupported} is not recognized,
40736or that no features needed to be reported to @value{GDBN}.
40737@end table
40738
40739The allowed forms for each feature (either a @var{gdbfeature} in the
40740@samp{qSupported} packet, or a @var{stubfeature} in the response)
40741are:
40742
40743@table @samp
40744@item @var{name}=@var{value}
40745The remote protocol feature @var{name} is supported, and associated
40746with the specified @var{value}. The format of @var{value} depends
40747on the feature, but it must not include a semicolon.
40748@item @var{name}+
40749The remote protocol feature @var{name} is supported, and does not
40750need an associated value.
40751@item @var{name}-
40752The remote protocol feature @var{name} is not supported.
40753@item @var{name}?
40754The remote protocol feature @var{name} may be supported, and
40755@value{GDBN} should auto-detect support in some other way when it is
40756needed. This form will not be used for @var{gdbfeature} notifications,
40757but may be used for @var{stubfeature} responses.
40758@end table
40759
40760Whenever the stub receives a @samp{qSupported} request, the
40761supplied set of @value{GDBN} features should override any previous
40762request. This allows @value{GDBN} to put the stub in a known
40763state, even if the stub had previously been communicating with
40764a different version of @value{GDBN}.
40765
b90a069a
SL
40766The following values of @var{gdbfeature} (for the packet sent by @value{GDBN})
40767are defined:
40768
40769@table @samp
40770@item multiprocess
40771This feature indicates whether @value{GDBN} supports multiprocess
40772extensions to the remote protocol. @value{GDBN} does not use such
40773extensions unless the stub also reports that it supports them by
40774including @samp{multiprocess+} in its @samp{qSupported} reply.
40775@xref{multiprocess extensions}, for details.
c8d5aac9
L
40776
40777@item xmlRegisters
40778This feature indicates that @value{GDBN} supports the XML target
40779description. If the stub sees @samp{xmlRegisters=} with target
40780specific strings separated by a comma, it will report register
40781description.
dde08ee1
PA
40782
40783@item qRelocInsn
40784This feature indicates whether @value{GDBN} supports the
40785@samp{qRelocInsn} packet (@pxref{Tracepoint Packets,,Relocate
40786instruction reply packet}).
f7e6eed5
PA
40787
40788@item swbreak
40789This feature indicates whether @value{GDBN} supports the swbreak stop
40790reason in stop replies. @xref{swbreak stop reason}, for details.
40791
40792@item hwbreak
40793This feature indicates whether @value{GDBN} supports the hwbreak stop
40794reason in stop replies. @xref{swbreak stop reason}, for details.
0d71eef5
DB
40795
40796@item fork-events
40797This feature indicates whether @value{GDBN} supports fork event
40798extensions to the remote protocol. @value{GDBN} does not use such
40799extensions unless the stub also reports that it supports them by
40800including @samp{fork-events+} in its @samp{qSupported} reply.
40801
40802@item vfork-events
40803This feature indicates whether @value{GDBN} supports vfork event
40804extensions to the remote protocol. @value{GDBN} does not use such
40805extensions unless the stub also reports that it supports them by
40806including @samp{vfork-events+} in its @samp{qSupported} reply.
b459a59b
DB
40807
40808@item exec-events
40809This feature indicates whether @value{GDBN} supports exec event
40810extensions to the remote protocol. @value{GDBN} does not use such
40811extensions unless the stub also reports that it supports them by
40812including @samp{exec-events+} in its @samp{qSupported} reply.
750ce8d1
YQ
40813
40814@item vContSupported
40815This feature indicates whether @value{GDBN} wants to know the
40816supported actions in the reply to @samp{vCont?} packet.
b90a069a
SL
40817@end table
40818
40819Stubs should ignore any unknown values for
be2a5f71
DJ
40820@var{gdbfeature}. Any @value{GDBN} which sends a @samp{qSupported}
40821packet supports receiving packets of unlimited length (earlier
b90a069a 40822versions of @value{GDBN} may reject overly long responses). Additional values
be2a5f71
DJ
40823for @var{gdbfeature} may be defined in the future to let the stub take
40824advantage of new features in @value{GDBN}, e.g.@: incompatible
b90a069a
SL
40825improvements in the remote protocol---the @samp{multiprocess} feature is
40826an example of such a feature. The stub's reply should be independent
be2a5f71
DJ
40827of the @var{gdbfeature} entries sent by @value{GDBN}; first @value{GDBN}
40828describes all the features it supports, and then the stub replies with
40829all the features it supports.
40830
40831Similarly, @value{GDBN} will silently ignore unrecognized stub feature
40832responses, as long as each response uses one of the standard forms.
40833
40834Some features are flags. A stub which supports a flag feature
40835should respond with a @samp{+} form response. Other features
40836require values, and the stub should respond with an @samp{=}
40837form response.
40838
40839Each feature has a default value, which @value{GDBN} will use if
40840@samp{qSupported} is not available or if the feature is not mentioned
40841in the @samp{qSupported} response. The default values are fixed; a
40842stub is free to omit any feature responses that match the defaults.
40843
40844Not all features can be probed, but for those which can, the probing
40845mechanism is useful: in some cases, a stub's internal
40846architecture may not allow the protocol layer to know some information
40847about the underlying target in advance. This is especially common in
40848stubs which may be configured for multiple targets.
40849
40850These are the currently defined stub features and their properties:
40851
cfa9d6d9 40852@multitable @columnfractions 0.35 0.2 0.12 0.2
be2a5f71
DJ
40853@c NOTE: The first row should be @headitem, but we do not yet require
40854@c a new enough version of Texinfo (4.7) to use @headitem.
0876f84a 40855@item Feature Name
be2a5f71
DJ
40856@tab Value Required
40857@tab Default
40858@tab Probe Allowed
40859
40860@item @samp{PacketSize}
40861@tab Yes
40862@tab @samp{-}
40863@tab No
40864
0876f84a
DJ
40865@item @samp{qXfer:auxv:read}
40866@tab No
40867@tab @samp{-}
40868@tab Yes
40869
2ae8c8e7
MM
40870@item @samp{qXfer:btrace:read}
40871@tab No
40872@tab @samp{-}
40873@tab Yes
40874
f4abbc16
MM
40875@item @samp{qXfer:btrace-conf:read}
40876@tab No
40877@tab @samp{-}
40878@tab Yes
40879
c78fa86a
GB
40880@item @samp{qXfer:exec-file:read}
40881@tab No
40882@tab @samp{-}
40883@tab Yes
40884
23181151
DJ
40885@item @samp{qXfer:features:read}
40886@tab No
40887@tab @samp{-}
40888@tab Yes
40889
cfa9d6d9
DJ
40890@item @samp{qXfer:libraries:read}
40891@tab No
40892@tab @samp{-}
40893@tab Yes
40894
85dc5a12
GB
40895@item @samp{qXfer:libraries-svr4:read}
40896@tab No
40897@tab @samp{-}
40898@tab Yes
40899
40900@item @samp{augmented-libraries-svr4-read}
40901@tab No
40902@tab @samp{-}
40903@tab No
40904
68437a39
DJ
40905@item @samp{qXfer:memory-map:read}
40906@tab No
40907@tab @samp{-}
40908@tab Yes
40909
0fb4aa4b
PA
40910@item @samp{qXfer:sdata:read}
40911@tab No
40912@tab @samp{-}
40913@tab Yes
40914
4aa995e1
PA
40915@item @samp{qXfer:siginfo:read}
40916@tab No
40917@tab @samp{-}
40918@tab Yes
40919
40920@item @samp{qXfer:siginfo:write}
40921@tab No
40922@tab @samp{-}
40923@tab Yes
40924
dc146f7c
VP
40925@item @samp{qXfer:threads:read}
40926@tab No
40927@tab @samp{-}
40928@tab Yes
40929
b3b9301e
PA
40930@item @samp{qXfer:traceframe-info:read}
40931@tab No
40932@tab @samp{-}
40933@tab Yes
40934
169081d0
TG
40935@item @samp{qXfer:uib:read}
40936@tab No
40937@tab @samp{-}
40938@tab Yes
40939
78d85199
YQ
40940@item @samp{qXfer:fdpic:read}
40941@tab No
40942@tab @samp{-}
40943@tab Yes
dc146f7c 40944
2ae8c8e7
MM
40945@item @samp{Qbtrace:off}
40946@tab Yes
40947@tab @samp{-}
40948@tab Yes
40949
40950@item @samp{Qbtrace:bts}
40951@tab Yes
40952@tab @samp{-}
40953@tab Yes
40954
b20a6524
MM
40955@item @samp{Qbtrace:pt}
40956@tab Yes
40957@tab @samp{-}
40958@tab Yes
40959
d33501a5
MM
40960@item @samp{Qbtrace-conf:bts:size}
40961@tab Yes
40962@tab @samp{-}
40963@tab Yes
40964
b20a6524
MM
40965@item @samp{Qbtrace-conf:pt:size}
40966@tab Yes
40967@tab @samp{-}
40968@tab Yes
40969
8b23ecc4
SL
40970@item @samp{QNonStop}
40971@tab No
40972@tab @samp{-}
40973@tab Yes
40974
82075af2
JS
40975@item @samp{QCatchSyscalls}
40976@tab No
40977@tab @samp{-}
40978@tab Yes
40979
89be2091
DJ
40980@item @samp{QPassSignals}
40981@tab No
40982@tab @samp{-}
40983@tab Yes
40984
a6f3e723
SL
40985@item @samp{QStartNoAckMode}
40986@tab No
40987@tab @samp{-}
40988@tab Yes
40989
b90a069a
SL
40990@item @samp{multiprocess}
40991@tab No
40992@tab @samp{-}
40993@tab No
40994
83364271
LM
40995@item @samp{ConditionalBreakpoints}
40996@tab No
40997@tab @samp{-}
40998@tab No
40999
782b2b07
SS
41000@item @samp{ConditionalTracepoints}
41001@tab No
41002@tab @samp{-}
41003@tab No
41004
0d772ac9
MS
41005@item @samp{ReverseContinue}
41006@tab No
2f8132f3 41007@tab @samp{-}
0d772ac9
MS
41008@tab No
41009
41010@item @samp{ReverseStep}
41011@tab No
2f8132f3 41012@tab @samp{-}
0d772ac9
MS
41013@tab No
41014
409873ef
SS
41015@item @samp{TracepointSource}
41016@tab No
41017@tab @samp{-}
41018@tab No
41019
d1feda86
YQ
41020@item @samp{QAgent}
41021@tab No
41022@tab @samp{-}
41023@tab No
41024
d914c394
SS
41025@item @samp{QAllow}
41026@tab No
41027@tab @samp{-}
41028@tab No
41029
03583c20
UW
41030@item @samp{QDisableRandomization}
41031@tab No
41032@tab @samp{-}
41033@tab No
41034
d248b706
KY
41035@item @samp{EnableDisableTracepoints}
41036@tab No
41037@tab @samp{-}
41038@tab No
41039
f6f899bf
HAQ
41040@item @samp{QTBuffer:size}
41041@tab No
41042@tab @samp{-}
41043@tab No
41044
3065dfb6
SS
41045@item @samp{tracenz}
41046@tab No
41047@tab @samp{-}
41048@tab No
41049
d3ce09f5
SS
41050@item @samp{BreakpointCommands}
41051@tab No
41052@tab @samp{-}
41053@tab No
41054
f7e6eed5
PA
41055@item @samp{swbreak}
41056@tab No
41057@tab @samp{-}
41058@tab No
41059
41060@item @samp{hwbreak}
41061@tab No
41062@tab @samp{-}
41063@tab No
41064
0d71eef5
DB
41065@item @samp{fork-events}
41066@tab No
41067@tab @samp{-}
41068@tab No
41069
41070@item @samp{vfork-events}
41071@tab No
41072@tab @samp{-}
41073@tab No
41074
b459a59b
DB
41075@item @samp{exec-events}
41076@tab No
41077@tab @samp{-}
41078@tab No
41079
65706a29
PA
41080@item @samp{QThreadEvents}
41081@tab No
41082@tab @samp{-}
41083@tab No
41084
f2faf941
PA
41085@item @samp{no-resumed}
41086@tab No
41087@tab @samp{-}
41088@tab No
41089
be2a5f71
DJ
41090@end multitable
41091
41092These are the currently defined stub features, in more detail:
41093
41094@table @samp
41095@cindex packet size, remote protocol
41096@item PacketSize=@var{bytes}
41097The remote stub can accept packets up to at least @var{bytes} in
41098length. @value{GDBN} will send packets up to this size for bulk
41099transfers, and will never send larger packets. This is a limit on the
41100data characters in the packet, including the frame and checksum.
41101There is no trailing NUL byte in a remote protocol packet; if the stub
41102stores packets in a NUL-terminated format, it should allow an extra
41103byte in its buffer for the NUL. If this stub feature is not supported,
41104@value{GDBN} guesses based on the size of the @samp{g} packet response.
41105
0876f84a
DJ
41106@item qXfer:auxv:read
41107The remote stub understands the @samp{qXfer:auxv:read} packet
41108(@pxref{qXfer auxiliary vector read}).
41109
2ae8c8e7
MM
41110@item qXfer:btrace:read
41111The remote stub understands the @samp{qXfer:btrace:read}
41112packet (@pxref{qXfer btrace read}).
41113
f4abbc16
MM
41114@item qXfer:btrace-conf:read
41115The remote stub understands the @samp{qXfer:btrace-conf:read}
41116packet (@pxref{qXfer btrace-conf read}).
41117
c78fa86a
GB
41118@item qXfer:exec-file:read
41119The remote stub understands the @samp{qXfer:exec-file:read} packet
41120(@pxref{qXfer executable filename read}).
41121
23181151
DJ
41122@item qXfer:features:read
41123The remote stub understands the @samp{qXfer:features:read} packet
41124(@pxref{qXfer target description read}).
41125
cfa9d6d9
DJ
41126@item qXfer:libraries:read
41127The remote stub understands the @samp{qXfer:libraries:read} packet
41128(@pxref{qXfer library list read}).
41129
2268b414
JK
41130@item qXfer:libraries-svr4:read
41131The remote stub understands the @samp{qXfer:libraries-svr4:read} packet
41132(@pxref{qXfer svr4 library list read}).
41133
85dc5a12
GB
41134@item augmented-libraries-svr4-read
41135The remote stub understands the augmented form of the
41136@samp{qXfer:libraries-svr4:read} packet
41137(@pxref{qXfer svr4 library list read}).
41138
23181151
DJ
41139@item qXfer:memory-map:read
41140The remote stub understands the @samp{qXfer:memory-map:read} packet
41141(@pxref{qXfer memory map read}).
41142
0fb4aa4b
PA
41143@item qXfer:sdata:read
41144The remote stub understands the @samp{qXfer:sdata:read} packet
41145(@pxref{qXfer sdata read}).
41146
4aa995e1
PA
41147@item qXfer:siginfo:read
41148The remote stub understands the @samp{qXfer:siginfo:read} packet
41149(@pxref{qXfer siginfo read}).
41150
41151@item qXfer:siginfo:write
41152The remote stub understands the @samp{qXfer:siginfo:write} packet
41153(@pxref{qXfer siginfo write}).
41154
dc146f7c
VP
41155@item qXfer:threads:read
41156The remote stub understands the @samp{qXfer:threads:read} packet
41157(@pxref{qXfer threads read}).
41158
b3b9301e
PA
41159@item qXfer:traceframe-info:read
41160The remote stub understands the @samp{qXfer:traceframe-info:read}
41161packet (@pxref{qXfer traceframe info read}).
41162
169081d0
TG
41163@item qXfer:uib:read
41164The remote stub understands the @samp{qXfer:uib:read}
41165packet (@pxref{qXfer unwind info block}).
41166
78d85199
YQ
41167@item qXfer:fdpic:read
41168The remote stub understands the @samp{qXfer:fdpic:read}
41169packet (@pxref{qXfer fdpic loadmap read}).
41170
8b23ecc4
SL
41171@item QNonStop
41172The remote stub understands the @samp{QNonStop} packet
41173(@pxref{QNonStop}).
41174
82075af2
JS
41175@item QCatchSyscalls
41176The remote stub understands the @samp{QCatchSyscalls} packet
41177(@pxref{QCatchSyscalls}).
41178
23181151
DJ
41179@item QPassSignals
41180The remote stub understands the @samp{QPassSignals} packet
41181(@pxref{QPassSignals}).
41182
a6f3e723
SL
41183@item QStartNoAckMode
41184The remote stub understands the @samp{QStartNoAckMode} packet and
41185prefers to operate in no-acknowledgment mode. @xref{Packet Acknowledgment}.
41186
b90a069a
SL
41187@item multiprocess
41188@anchor{multiprocess extensions}
41189@cindex multiprocess extensions, in remote protocol
41190The remote stub understands the multiprocess extensions to the remote
41191protocol syntax. The multiprocess extensions affect the syntax of
41192thread IDs in both packets and replies (@pxref{thread-id syntax}), and
41193add process IDs to the @samp{D} packet and @samp{W} and @samp{X}
41194replies. Note that reporting this feature indicates support for the
41195syntactic extensions only, not that the stub necessarily supports
41196debugging of more than one process at a time. The stub must not use
41197multiprocess extensions in packet replies unless @value{GDBN} has also
41198indicated it supports them in its @samp{qSupported} request.
41199
07e059b5
VP
41200@item qXfer:osdata:read
41201The remote stub understands the @samp{qXfer:osdata:read} packet
41202((@pxref{qXfer osdata read}).
41203
83364271
LM
41204@item ConditionalBreakpoints
41205The target accepts and implements evaluation of conditional expressions
41206defined for breakpoints. The target will only report breakpoint triggers
41207when such conditions are true (@pxref{Conditions, ,Break Conditions}).
41208
782b2b07
SS
41209@item ConditionalTracepoints
41210The remote stub accepts and implements conditional expressions defined
41211for tracepoints (@pxref{Tracepoint Conditions}).
41212
0d772ac9
MS
41213@item ReverseContinue
41214The remote stub accepts and implements the reverse continue packet
41215(@pxref{bc}).
41216
41217@item ReverseStep
41218The remote stub accepts and implements the reverse step packet
41219(@pxref{bs}).
41220
409873ef
SS
41221@item TracepointSource
41222The remote stub understands the @samp{QTDPsrc} packet that supplies
41223the source form of tracepoint definitions.
41224
d1feda86
YQ
41225@item QAgent
41226The remote stub understands the @samp{QAgent} packet.
41227
d914c394
SS
41228@item QAllow
41229The remote stub understands the @samp{QAllow} packet.
41230
03583c20
UW
41231@item QDisableRandomization
41232The remote stub understands the @samp{QDisableRandomization} packet.
41233
0fb4aa4b
PA
41234@item StaticTracepoint
41235@cindex static tracepoints, in remote protocol
41236The remote stub supports static tracepoints.
41237
1e4d1764
YQ
41238@item InstallInTrace
41239@anchor{install tracepoint in tracing}
41240The remote stub supports installing tracepoint in tracing.
41241
d248b706
KY
41242@item EnableDisableTracepoints
41243The remote stub supports the @samp{QTEnable} (@pxref{QTEnable}) and
41244@samp{QTDisable} (@pxref{QTDisable}) packets that allow tracepoints
41245to be enabled and disabled while a trace experiment is running.
41246
f6f899bf 41247@item QTBuffer:size
28abe188 41248The remote stub supports the @samp{QTBuffer:size} (@pxref{QTBuffer-size})
f6f899bf
HAQ
41249packet that allows to change the size of the trace buffer.
41250
3065dfb6
SS
41251@item tracenz
41252@cindex string tracing, in remote protocol
41253The remote stub supports the @samp{tracenz} bytecode for collecting strings.
41254See @ref{Bytecode Descriptions} for details about the bytecode.
41255
d3ce09f5
SS
41256@item BreakpointCommands
41257@cindex breakpoint commands, in remote protocol
41258The remote stub supports running a breakpoint's command list itself,
41259rather than reporting the hit to @value{GDBN}.
41260
2ae8c8e7
MM
41261@item Qbtrace:off
41262The remote stub understands the @samp{Qbtrace:off} packet.
41263
41264@item Qbtrace:bts
41265The remote stub understands the @samp{Qbtrace:bts} packet.
41266
b20a6524
MM
41267@item Qbtrace:pt
41268The remote stub understands the @samp{Qbtrace:pt} packet.
41269
d33501a5
MM
41270@item Qbtrace-conf:bts:size
41271The remote stub understands the @samp{Qbtrace-conf:bts:size} packet.
41272
b20a6524
MM
41273@item Qbtrace-conf:pt:size
41274The remote stub understands the @samp{Qbtrace-conf:pt:size} packet.
41275
f7e6eed5
PA
41276@item swbreak
41277The remote stub reports the @samp{swbreak} stop reason for memory
41278breakpoints.
41279
41280@item hwbreak
41281The remote stub reports the @samp{hwbreak} stop reason for hardware
41282breakpoints.
41283
0d71eef5
DB
41284@item fork-events
41285The remote stub reports the @samp{fork} stop reason for fork events.
41286
41287@item vfork-events
41288The remote stub reports the @samp{vfork} stop reason for vfork events
41289and vforkdone events.
41290
b459a59b
DB
41291@item exec-events
41292The remote stub reports the @samp{exec} stop reason for exec events.
41293
750ce8d1
YQ
41294@item vContSupported
41295The remote stub reports the supported actions in the reply to
41296@samp{vCont?} packet.
41297
65706a29
PA
41298@item QThreadEvents
41299The remote stub understands the @samp{QThreadEvents} packet.
41300
f2faf941
PA
41301@item no-resumed
41302The remote stub reports the @samp{N} stop reply.
41303
be2a5f71
DJ
41304@end table
41305
b8ff78ce 41306@item qSymbol::
ff2587ec 41307@cindex symbol lookup, remote request
b8ff78ce 41308@cindex @samp{qSymbol} packet
ff2587ec
WZ
41309Notify the target that @value{GDBN} is prepared to serve symbol lookup
41310requests. Accept requests from the target for the values of symbols.
fa93a9d8
JB
41311
41312Reply:
ff2587ec 41313@table @samp
b8ff78ce 41314@item OK
ff2587ec 41315The target does not need to look up any (more) symbols.
b8ff78ce 41316@item qSymbol:@var{sym_name}
ff2587ec
WZ
41317The target requests the value of symbol @var{sym_name} (hex encoded).
41318@value{GDBN} may provide the value by using the
b8ff78ce
JB
41319@samp{qSymbol:@var{sym_value}:@var{sym_name}} message, described
41320below.
ff2587ec 41321@end table
83761cbd 41322
b8ff78ce 41323@item qSymbol:@var{sym_value}:@var{sym_name}
ff2587ec
WZ
41324Set the value of @var{sym_name} to @var{sym_value}.
41325
41326@var{sym_name} (hex encoded) is the name of a symbol whose value the
41327target has previously requested.
41328
41329@var{sym_value} (hex) is the value for symbol @var{sym_name}. If
41330@value{GDBN} cannot supply a value for @var{sym_name}, then this field
41331will be empty.
41332
41333Reply:
41334@table @samp
b8ff78ce 41335@item OK
ff2587ec 41336The target does not need to look up any (more) symbols.
b8ff78ce 41337@item qSymbol:@var{sym_name}
ff2587ec
WZ
41338The target requests the value of a new symbol @var{sym_name} (hex
41339encoded). @value{GDBN} will continue to supply the values of symbols
41340(if available), until the target ceases to request them.
fa93a9d8 41341@end table
0abb7bc7 41342
00bf0b85 41343@item qTBuffer
687e43a4
TT
41344@itemx QTBuffer
41345@itemx QTDisconnected
d5551862 41346@itemx QTDP
409873ef 41347@itemx QTDPsrc
d5551862 41348@itemx QTDV
00bf0b85
SS
41349@itemx qTfP
41350@itemx qTfV
9d29849a 41351@itemx QTFrame
405f8e94
SS
41352@itemx qTMinFTPILen
41353
9d29849a
JB
41354@xref{Tracepoint Packets}.
41355
b90a069a 41356@item qThreadExtraInfo,@var{thread-id}
ff2587ec 41357@cindex thread attributes info, remote request
b8ff78ce 41358@cindex @samp{qThreadExtraInfo} packet
697aa1b7
EZ
41359Obtain from the target OS a printable string description of thread
41360attributes for the thread @var{thread-id}; see @ref{thread-id syntax},
41361for the forms of @var{thread-id}. This
b8ff78ce
JB
41362string may contain anything that the target OS thinks is interesting
41363for @value{GDBN} to tell the user about the thread. The string is
41364displayed in @value{GDBN}'s @code{info threads} display. Some
41365examples of possible thread extra info strings are @samp{Runnable}, or
41366@samp{Blocked on Mutex}.
ff2587ec
WZ
41367
41368Reply:
41369@table @samp
b8ff78ce
JB
41370@item @var{XX}@dots{}
41371Where @samp{@var{XX}@dots{}} is a hex encoding of @sc{ascii} data,
41372comprising the printable string containing the extra information about
41373the thread's attributes.
ff2587ec 41374@end table
814e32d7 41375
aa56d27a
JB
41376(Note that the @code{qThreadExtraInfo} packet's name is separated from
41377the command by a @samp{,}, not a @samp{:}, contrary to the naming
41378conventions above. Please don't use this packet as a model for new
41379packets.)
41380
f196051f 41381@item QTNotes
687e43a4
TT
41382@itemx qTP
41383@itemx QTSave
41384@itemx qTsP
41385@itemx qTsV
d5551862 41386@itemx QTStart
9d29849a 41387@itemx QTStop
d248b706
KY
41388@itemx QTEnable
41389@itemx QTDisable
9d29849a
JB
41390@itemx QTinit
41391@itemx QTro
41392@itemx qTStatus
d5551862 41393@itemx qTV
0fb4aa4b
PA
41394@itemx qTfSTM
41395@itemx qTsSTM
41396@itemx qTSTMat
9d29849a
JB
41397@xref{Tracepoint Packets}.
41398
0876f84a
DJ
41399@item qXfer:@var{object}:read:@var{annex}:@var{offset},@var{length}
41400@cindex read special object, remote request
41401@cindex @samp{qXfer} packet
68437a39 41402@anchor{qXfer read}
0876f84a
DJ
41403Read uninterpreted bytes from the target's special data area
41404identified by the keyword @var{object}. Request @var{length} bytes
41405starting at @var{offset} bytes into the data. The content and
0e7f50da 41406encoding of @var{annex} is specific to @var{object}; it can supply
0876f84a
DJ
41407additional details about what data to access.
41408
c185ba27
EZ
41409Reply:
41410@table @samp
41411@item m @var{data}
41412Data @var{data} (@pxref{Binary Data}) has been read from the
41413target. There may be more data at a higher address (although
41414it is permitted to return @samp{m} even for the last valid
41415block of data, as long as at least one byte of data was read).
41416It is possible for @var{data} to have fewer bytes than the @var{length} in the
41417request.
41418
41419@item l @var{data}
41420Data @var{data} (@pxref{Binary Data}) has been read from the target.
41421There is no more data to be read. It is possible for @var{data} to
41422have fewer bytes than the @var{length} in the request.
41423
41424@item l
41425The @var{offset} in the request is at the end of the data.
41426There is no more data to be read.
41427
41428@item E00
41429The request was malformed, or @var{annex} was invalid.
41430
41431@item E @var{nn}
41432The offset was invalid, or there was an error encountered reading the data.
41433The @var{nn} part is a hex-encoded @code{errno} value.
41434
41435@item @w{}
41436An empty reply indicates the @var{object} string was not recognized by
41437the stub, or that the object does not support reading.
41438@end table
41439
41440Here are the specific requests of this form defined so far. All the
0876f84a 41441@samp{qXfer:@var{object}:read:@dots{}} requests use the same reply
c185ba27 41442formats, listed above.
0876f84a
DJ
41443
41444@table @samp
41445@item qXfer:auxv:read::@var{offset},@var{length}
41446@anchor{qXfer auxiliary vector read}
41447Access the target's @dfn{auxiliary vector}. @xref{OS Information,
427c3a89 41448auxiliary vector}. Note @var{annex} must be empty.
0876f84a
DJ
41449
41450This packet is not probed by default; the remote stub must request it,
89be2091 41451by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
0876f84a 41452
2ae8c8e7
MM
41453@item qXfer:btrace:read:@var{annex}:@var{offset},@var{length}
41454@anchor{qXfer btrace read}
41455
41456Return a description of the current branch trace.
41457@xref{Branch Trace Format}. The annex part of the generic @samp{qXfer}
41458packet may have one of the following values:
41459
41460@table @code
41461@item all
41462Returns all available branch trace.
41463
41464@item new
41465Returns all available branch trace if the branch trace changed since
41466the last read request.
969c39fb
MM
41467
41468@item delta
41469Returns the new branch trace since the last read request. Adds a new
41470block to the end of the trace that begins at zero and ends at the source
41471location of the first branch in the trace buffer. This extra block is
41472used to stitch traces together.
41473
41474If the trace buffer overflowed, returns an error indicating the overflow.
2ae8c8e7
MM
41475@end table
41476
41477This packet is not probed by default; the remote stub must request it
41478by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41479
f4abbc16
MM
41480@item qXfer:btrace-conf:read::@var{offset},@var{length}
41481@anchor{qXfer btrace-conf read}
41482
41483Return a description of the current branch trace configuration.
41484@xref{Branch Trace Configuration Format}.
41485
41486This packet is not probed by default; the remote stub must request it
41487by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
c78fa86a
GB
41488
41489@item qXfer:exec-file:read:@var{annex}:@var{offset},@var{length}
41490@anchor{qXfer executable filename read}
41491Return the full absolute name of the file that was executed to create
41492a process running on the remote system. The annex specifies the
41493numeric process ID of the process to query, encoded as a hexadecimal
835205d0
GB
41494number. If the annex part is empty the remote stub should return the
41495filename corresponding to the currently executing process.
c78fa86a
GB
41496
41497This packet is not probed by default; the remote stub must request it,
41498by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
f4abbc16 41499
23181151
DJ
41500@item qXfer:features:read:@var{annex}:@var{offset},@var{length}
41501@anchor{qXfer target description read}
41502Access the @dfn{target description}. @xref{Target Descriptions}. The
41503annex specifies which XML document to access. The main description is
41504always loaded from the @samp{target.xml} annex.
41505
41506This packet is not probed by default; the remote stub must request it,
41507by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41508
cfa9d6d9
DJ
41509@item qXfer:libraries:read:@var{annex}:@var{offset},@var{length}
41510@anchor{qXfer library list read}
41511Access the target's list of loaded libraries. @xref{Library List Format}.
41512The annex part of the generic @samp{qXfer} packet must be empty
41513(@pxref{qXfer read}).
41514
41515Targets which maintain a list of libraries in the program's memory do
41516not need to implement this packet; it is designed for platforms where
41517the operating system manages the list of loaded libraries.
41518
41519This packet is not probed by default; the remote stub must request it,
41520by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41521
2268b414
JK
41522@item qXfer:libraries-svr4:read:@var{annex}:@var{offset},@var{length}
41523@anchor{qXfer svr4 library list read}
41524Access the target's list of loaded libraries when the target is an SVR4
41525platform. @xref{Library List Format for SVR4 Targets}. The annex part
85dc5a12
GB
41526of the generic @samp{qXfer} packet must be empty unless the remote
41527stub indicated it supports the augmented form of this packet
41528by supplying an appropriate @samp{qSupported} response
41529(@pxref{qXfer read}, @ref{qSupported}).
2268b414
JK
41530
41531This packet is optional for better performance on SVR4 targets.
41532@value{GDBN} uses memory read packets to read the SVR4 library list otherwise.
41533
41534This packet is not probed by default; the remote stub must request it,
41535by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41536
85dc5a12
GB
41537If the remote stub indicates it supports the augmented form of this
41538packet then the annex part of the generic @samp{qXfer} packet may
41539contain a semicolon-separated list of @samp{@var{name}=@var{value}}
41540arguments. The currently supported arguments are:
41541
41542@table @code
41543@item start=@var{address}
41544A hexadecimal number specifying the address of the @samp{struct
41545link_map} to start reading the library list from. If unset or zero
41546then the first @samp{struct link_map} in the library list will be
41547chosen as the starting point.
41548
41549@item prev=@var{address}
41550A hexadecimal number specifying the address of the @samp{struct
41551link_map} immediately preceding the @samp{struct link_map}
41552specified by the @samp{start} argument. If unset or zero then
41553the remote stub will expect that no @samp{struct link_map}
41554exists prior to the starting point.
41555
41556@end table
41557
41558Arguments that are not understood by the remote stub will be silently
41559ignored.
41560
68437a39
DJ
41561@item qXfer:memory-map:read::@var{offset},@var{length}
41562@anchor{qXfer memory map read}
79a6e687 41563Access the target's @dfn{memory-map}. @xref{Memory Map Format}. The
68437a39
DJ
41564annex part of the generic @samp{qXfer} packet must be empty
41565(@pxref{qXfer read}).
41566
0e7f50da
UW
41567This packet is not probed by default; the remote stub must request it,
41568by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41569
0fb4aa4b
PA
41570@item qXfer:sdata:read::@var{offset},@var{length}
41571@anchor{qXfer sdata read}
41572
41573Read contents of the extra collected static tracepoint marker
41574information. The annex part of the generic @samp{qXfer} packet must
41575be empty (@pxref{qXfer read}). @xref{Tracepoint Actions,,Tracepoint
41576Action Lists}.
41577
41578This packet is not probed by default; the remote stub must request it,
41579by supplying an appropriate @samp{qSupported} response
41580(@pxref{qSupported}).
41581
4aa995e1
PA
41582@item qXfer:siginfo:read::@var{offset},@var{length}
41583@anchor{qXfer siginfo read}
41584Read contents of the extra signal information on the target
41585system. The annex part of the generic @samp{qXfer} packet must be
41586empty (@pxref{qXfer read}).
41587
41588This packet is not probed by default; the remote stub must request it,
41589by supplying an appropriate @samp{qSupported} response
41590(@pxref{qSupported}).
41591
dc146f7c
VP
41592@item qXfer:threads:read::@var{offset},@var{length}
41593@anchor{qXfer threads read}
41594Access the list of threads on target. @xref{Thread List Format}. The
41595annex part of the generic @samp{qXfer} packet must be empty
41596(@pxref{qXfer read}).
41597
41598This packet is not probed by default; the remote stub must request it,
41599by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41600
b3b9301e
PA
41601@item qXfer:traceframe-info:read::@var{offset},@var{length}
41602@anchor{qXfer traceframe info read}
41603
41604Return a description of the current traceframe's contents.
41605@xref{Traceframe Info Format}. The annex part of the generic
41606@samp{qXfer} packet must be empty (@pxref{qXfer read}).
41607
41608This packet is not probed by default; the remote stub must request it,
41609by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41610
169081d0
TG
41611@item qXfer:uib:read:@var{pc}:@var{offset},@var{length}
41612@anchor{qXfer unwind info block}
41613
41614Return the unwind information block for @var{pc}. This packet is used
41615on OpenVMS/ia64 to ask the kernel unwind information.
41616
41617This packet is not probed by default.
41618
78d85199
YQ
41619@item qXfer:fdpic:read:@var{annex}:@var{offset},@var{length}
41620@anchor{qXfer fdpic loadmap read}
41621Read contents of @code{loadmap}s on the target system. The
41622annex, either @samp{exec} or @samp{interp}, specifies which @code{loadmap},
41623executable @code{loadmap} or interpreter @code{loadmap} to read.
41624
41625This packet is not probed by default; the remote stub must request it,
41626by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41627
07e059b5
VP
41628@item qXfer:osdata:read::@var{offset},@var{length}
41629@anchor{qXfer osdata read}
697aa1b7 41630Access the target's @dfn{operating system information}.
07e059b5
VP
41631@xref{Operating System Information}.
41632
68437a39
DJ
41633@end table
41634
c185ba27
EZ
41635@item qXfer:@var{object}:write:@var{annex}:@var{offset}:@var{data}@dots{}
41636@cindex write data into object, remote request
41637@anchor{qXfer write}
41638Write uninterpreted bytes into the target's special data area
41639identified by the keyword @var{object}, starting at @var{offset} bytes
41640into the data. The binary-encoded data (@pxref{Binary Data}) to be
41641written is given by @var{data}@dots{}. The content and encoding of @var{annex}
41642is specific to @var{object}; it can supply additional details about what data
41643to access.
41644
0876f84a
DJ
41645Reply:
41646@table @samp
c185ba27
EZ
41647@item @var{nn}
41648@var{nn} (hex encoded) is the number of bytes written.
41649This may be fewer bytes than supplied in the request.
0876f84a
DJ
41650
41651@item E00
41652The request was malformed, or @var{annex} was invalid.
41653
41654@item E @var{nn}
c185ba27 41655The offset was invalid, or there was an error encountered writing the data.
697aa1b7 41656The @var{nn} part is a hex-encoded @code{errno} value.
0876f84a 41657
d57350ea 41658@item @w{}
c185ba27
EZ
41659An empty reply indicates the @var{object} string was not
41660recognized by the stub, or that the object does not support writing.
0876f84a
DJ
41661@end table
41662
c185ba27 41663Here are the specific requests of this form defined so far. All the
0e7f50da 41664@samp{qXfer:@var{object}:write:@dots{}} requests use the same reply
c185ba27 41665formats, listed above.
0e7f50da
UW
41666
41667@table @samp
4aa995e1
PA
41668@item qXfer:siginfo:write::@var{offset}:@var{data}@dots{}
41669@anchor{qXfer siginfo write}
41670Write @var{data} to the extra signal information on the target system.
41671The annex part of the generic @samp{qXfer} packet must be
41672empty (@pxref{qXfer write}).
41673
41674This packet is not probed by default; the remote stub must request it,
41675by supplying an appropriate @samp{qSupported} response
41676(@pxref{qSupported}).
0e7f50da 41677@end table
0876f84a 41678
0876f84a
DJ
41679@item qXfer:@var{object}:@var{operation}:@dots{}
41680Requests of this form may be added in the future. When a stub does
41681not recognize the @var{object} keyword, or its support for
41682@var{object} does not recognize the @var{operation} keyword, the stub
41683must respond with an empty packet.
41684
0b16c5cf
PA
41685@item qAttached:@var{pid}
41686@cindex query attached, remote request
41687@cindex @samp{qAttached} packet
41688Return an indication of whether the remote server attached to an
41689existing process or created a new process. When the multiprocess
41690protocol extensions are supported (@pxref{multiprocess extensions}),
41691@var{pid} is an integer in hexadecimal format identifying the target
41692process. Otherwise, @value{GDBN} will omit the @var{pid} field and
41693the query packet will be simplified as @samp{qAttached}.
41694
41695This query is used, for example, to know whether the remote process
41696should be detached or killed when a @value{GDBN} session is ended with
41697the @code{quit} command.
41698
41699Reply:
41700@table @samp
41701@item 1
41702The remote server attached to an existing process.
41703@item 0
41704The remote server created a new process.
41705@item E @var{NN}
41706A badly formed request or an error was encountered.
41707@end table
41708
2ae8c8e7 41709@item Qbtrace:bts
b20a6524
MM
41710Enable branch tracing for the current thread using Branch Trace Store.
41711
41712Reply:
41713@table @samp
41714@item OK
41715Branch tracing has been enabled.
41716@item E.errtext
41717A badly formed request or an error was encountered.
41718@end table
41719
41720@item Qbtrace:pt
bc504a31 41721Enable branch tracing for the current thread using Intel Processor Trace.
2ae8c8e7
MM
41722
41723Reply:
41724@table @samp
41725@item OK
41726Branch tracing has been enabled.
41727@item E.errtext
41728A badly formed request or an error was encountered.
41729@end table
41730
41731@item Qbtrace:off
41732Disable branch tracing for the current thread.
41733
41734Reply:
41735@table @samp
41736@item OK
41737Branch tracing has been disabled.
41738@item E.errtext
41739A badly formed request or an error was encountered.
41740@end table
41741
d33501a5
MM
41742@item Qbtrace-conf:bts:size=@var{value}
41743Set the requested ring buffer size for new threads that use the
41744btrace recording method in bts format.
41745
41746Reply:
41747@table @samp
41748@item OK
41749The ring buffer size has been set.
41750@item E.errtext
41751A badly formed request or an error was encountered.
41752@end table
41753
b20a6524
MM
41754@item Qbtrace-conf:pt:size=@var{value}
41755Set the requested ring buffer size for new threads that use the
41756btrace recording method in pt format.
41757
41758Reply:
41759@table @samp
41760@item OK
41761The ring buffer size has been set.
41762@item E.errtext
41763A badly formed request or an error was encountered.
41764@end table
41765
ee2d5c50
AC
41766@end table
41767
a1dcb23a
DJ
41768@node Architecture-Specific Protocol Details
41769@section Architecture-Specific Protocol Details
41770
41771This section describes how the remote protocol is applied to specific
41772target architectures. Also see @ref{Standard Target Features}, for
41773details of XML target descriptions for each architecture.
41774
02b67415
MR
41775@menu
41776* ARM-Specific Protocol Details::
41777* MIPS-Specific Protocol Details::
41778@end menu
41779
41780@node ARM-Specific Protocol Details
41781@subsection @acronym{ARM}-specific Protocol Details
41782
41783@menu
41784* ARM Breakpoint Kinds::
41785@end menu
a1dcb23a 41786
02b67415
MR
41787@node ARM Breakpoint Kinds
41788@subsubsection @acronym{ARM} Breakpoint Kinds
41789@cindex breakpoint kinds, @acronym{ARM}
a1dcb23a
DJ
41790
41791These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
41792
41793@table @r
41794
41795@item 2
4179616-bit Thumb mode breakpoint.
41797
41798@item 3
4179932-bit Thumb mode (Thumb-2) breakpoint.
41800
41801@item 4
02b67415 4180232-bit @acronym{ARM} mode breakpoint.
a1dcb23a
DJ
41803
41804@end table
41805
02b67415
MR
41806@node MIPS-Specific Protocol Details
41807@subsection @acronym{MIPS}-specific Protocol Details
41808
41809@menu
41810* MIPS Register packet Format::
4cc0665f 41811* MIPS Breakpoint Kinds::
02b67415 41812@end menu
a1dcb23a 41813
02b67415
MR
41814@node MIPS Register packet Format
41815@subsubsection @acronym{MIPS} Register Packet Format
eb17f351 41816@cindex register packet format, @acronym{MIPS}
eb12ee30 41817
b8ff78ce 41818The following @code{g}/@code{G} packets have previously been defined.
ee2d5c50
AC
41819In the below, some thirty-two bit registers are transferred as
41820sixty-four bits. Those registers should be zero/sign extended (which?)
599b237a
BW
41821to fill the space allocated. Register bytes are transferred in target
41822byte order. The two nibbles within a register byte are transferred
02b67415 41823most-significant -- least-significant.
eb12ee30 41824
ee2d5c50 41825@table @r
eb12ee30 41826
8e04817f 41827@item MIPS32
599b237a 41828All registers are transferred as thirty-two bit quantities in the order:
8e04817f
AC
4182932 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
41830registers; fsr; fir; fp.
eb12ee30 41831
8e04817f 41832@item MIPS64
599b237a 41833All registers are transferred as sixty-four bit quantities (including
8e04817f
AC
41834thirty-two bit registers such as @code{sr}). The ordering is the same
41835as @code{MIPS32}.
eb12ee30 41836
ee2d5c50
AC
41837@end table
41838
4cc0665f
MR
41839@node MIPS Breakpoint Kinds
41840@subsubsection @acronym{MIPS} Breakpoint Kinds
41841@cindex breakpoint kinds, @acronym{MIPS}
41842
41843These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
41844
41845@table @r
41846
41847@item 2
4184816-bit @acronym{MIPS16} mode breakpoint.
41849
41850@item 3
4185116-bit @acronym{microMIPS} mode breakpoint.
41852
41853@item 4
4185432-bit standard @acronym{MIPS} mode breakpoint.
41855
41856@item 5
4185732-bit @acronym{microMIPS} mode breakpoint.
41858
41859@end table
41860
9d29849a
JB
41861@node Tracepoint Packets
41862@section Tracepoint Packets
41863@cindex tracepoint packets
41864@cindex packets, tracepoint
41865
41866Here we describe the packets @value{GDBN} uses to implement
41867tracepoints (@pxref{Tracepoints}).
41868
41869@table @samp
41870
7a697b8d 41871@item QTDP:@var{n}:@var{addr}:@var{ena}:@var{step}:@var{pass}[:F@var{flen}][:X@var{len},@var{bytes}]@r{[}-@r{]}
c614397c 41872@cindex @samp{QTDP} packet
9d29849a
JB
41873Create a new tracepoint, number @var{n}, at @var{addr}. If @var{ena}
41874is @samp{E}, then the tracepoint is enabled; if it is @samp{D}, then
697aa1b7
EZ
41875the tracepoint is disabled. The @var{step} gives the tracepoint's step
41876count, and @var{pass} gives its pass count. If an @samp{F} is present,
7a697b8d
SS
41877then the tracepoint is to be a fast tracepoint, and the @var{flen} is
41878the number of bytes that the target should copy elsewhere to make room
41879for the tracepoint. If an @samp{X} is present, it introduces a
41880tracepoint condition, which consists of a hexadecimal length, followed
41881by a comma and hex-encoded bytes, in a manner similar to action
41882encodings as described below. If the trailing @samp{-} is present,
41883further @samp{QTDP} packets will follow to specify this tracepoint's
41884actions.
9d29849a
JB
41885
41886Replies:
41887@table @samp
41888@item OK
41889The packet was understood and carried out.
dde08ee1
PA
41890@item qRelocInsn
41891@xref{Tracepoint Packets,,Relocate instruction reply packet}.
d57350ea 41892@item @w{}
9d29849a
JB
41893The packet was not recognized.
41894@end table
41895
41896@item QTDP:-@var{n}:@var{addr}:@r{[}S@r{]}@var{action}@dots{}@r{[}-@r{]}
697aa1b7 41897Define actions to be taken when a tracepoint is hit. The @var{n} and
9d29849a
JB
41898@var{addr} must be the same as in the initial @samp{QTDP} packet for
41899this tracepoint. This packet may only be sent immediately after
41900another @samp{QTDP} packet that ended with a @samp{-}. If the
41901trailing @samp{-} is present, further @samp{QTDP} packets will follow,
41902specifying more actions for this tracepoint.
41903
41904In the series of action packets for a given tracepoint, at most one
41905can have an @samp{S} before its first @var{action}. If such a packet
41906is sent, it and the following packets define ``while-stepping''
41907actions. Any prior packets define ordinary actions --- that is, those
41908taken when the tracepoint is first hit. If no action packet has an
41909@samp{S}, then all the packets in the series specify ordinary
41910tracepoint actions.
41911
41912The @samp{@var{action}@dots{}} portion of the packet is a series of
41913actions, concatenated without separators. Each action has one of the
41914following forms:
41915
41916@table @samp
41917
41918@item R @var{mask}
697aa1b7 41919Collect the registers whose bits are set in @var{mask},
599b237a 41920a hexadecimal number whose @var{i}'th bit is set if register number
9d29849a
JB
41921@var{i} should be collected. (The least significant bit is numbered
41922zero.) Note that @var{mask} may be any number of digits long; it may
41923not fit in a 32-bit word.
41924
41925@item M @var{basereg},@var{offset},@var{len}
41926Collect @var{len} bytes of memory starting at the address in register
41927number @var{basereg}, plus @var{offset}. If @var{basereg} is
41928@samp{-1}, then the range has a fixed address: @var{offset} is the
41929address of the lowest byte to collect. The @var{basereg},
599b237a 41930@var{offset}, and @var{len} parameters are all unsigned hexadecimal
9d29849a
JB
41931values (the @samp{-1} value for @var{basereg} is a special case).
41932
41933@item X @var{len},@var{expr}
41934Evaluate @var{expr}, whose length is @var{len}, and collect memory as
697aa1b7 41935it directs. The agent expression @var{expr} is as described in
9d29849a
JB
41936@ref{Agent Expressions}. Each byte of the expression is encoded as a
41937two-digit hex number in the packet; @var{len} is the number of bytes
41938in the expression (and thus one-half the number of hex digits in the
41939packet).
41940
41941@end table
41942
41943Any number of actions may be packed together in a single @samp{QTDP}
41944packet, as long as the packet does not exceed the maximum packet
c1947b85
JB
41945length (400 bytes, for many stubs). There may be only one @samp{R}
41946action per tracepoint, and it must precede any @samp{M} or @samp{X}
41947actions. Any registers referred to by @samp{M} and @samp{X} actions
41948must be collected by a preceding @samp{R} action. (The
41949``while-stepping'' actions are treated as if they were attached to a
41950separate tracepoint, as far as these restrictions are concerned.)
9d29849a
JB
41951
41952Replies:
41953@table @samp
41954@item OK
41955The packet was understood and carried out.
dde08ee1
PA
41956@item qRelocInsn
41957@xref{Tracepoint Packets,,Relocate instruction reply packet}.
d57350ea 41958@item @w{}
9d29849a
JB
41959The packet was not recognized.
41960@end table
41961
409873ef
SS
41962@item QTDPsrc:@var{n}:@var{addr}:@var{type}:@var{start}:@var{slen}:@var{bytes}
41963@cindex @samp{QTDPsrc} packet
41964Specify a source string of tracepoint @var{n} at address @var{addr}.
41965This is useful to get accurate reproduction of the tracepoints
697aa1b7 41966originally downloaded at the beginning of the trace run. The @var{type}
409873ef
SS
41967is the name of the tracepoint part, such as @samp{cond} for the
41968tracepoint's conditional expression (see below for a list of types), while
41969@var{bytes} is the string, encoded in hexadecimal.
41970
41971@var{start} is the offset of the @var{bytes} within the overall source
41972string, while @var{slen} is the total length of the source string.
41973This is intended for handling source strings that are longer than will
41974fit in a single packet.
41975@c Add detailed example when this info is moved into a dedicated
41976@c tracepoint descriptions section.
41977
41978The available string types are @samp{at} for the location,
41979@samp{cond} for the conditional, and @samp{cmd} for an action command.
41980@value{GDBN} sends a separate packet for each command in the action
41981list, in the same order in which the commands are stored in the list.
41982
41983The target does not need to do anything with source strings except
41984report them back as part of the replies to the @samp{qTfP}/@samp{qTsP}
41985query packets.
41986
41987Although this packet is optional, and @value{GDBN} will only send it
41988if the target replies with @samp{TracepointSource} @xref{General
41989Query Packets}, it makes both disconnected tracing and trace files
41990much easier to use. Otherwise the user must be careful that the
41991tracepoints in effect while looking at trace frames are identical to
41992the ones in effect during the trace run; even a small discrepancy
41993could cause @samp{tdump} not to work, or a particular trace frame not
41994be found.
41995
fa3f8d5a 41996@item QTDV:@var{n}:@var{value}:@var{builtin}:@var{name}
f61e138d
SS
41997@cindex define trace state variable, remote request
41998@cindex @samp{QTDV} packet
41999Create a new trace state variable, number @var{n}, with an initial
42000value of @var{value}, which is a 64-bit signed integer. Both @var{n}
42001and @var{value} are encoded as hexadecimal values. @value{GDBN} has
42002the option of not using this packet for initial values of zero; the
42003target should simply create the trace state variables as they are
fa3f8d5a
DT
42004mentioned in expressions. The value @var{builtin} should be 1 (one)
42005if the trace state variable is builtin and 0 (zero) if it is not builtin.
42006@value{GDBN} only sets @var{builtin} to 1 if a previous @samp{qTfV} or
42007@samp{qTsV} packet had it set. The contents of @var{name} is the
42008hex-encoded name (without the leading @samp{$}) of the trace state
42009variable.
f61e138d 42010
9d29849a 42011@item QTFrame:@var{n}
c614397c 42012@cindex @samp{QTFrame} packet
9d29849a
JB
42013Select the @var{n}'th tracepoint frame from the buffer, and use the
42014register and memory contents recorded there to answer subsequent
42015request packets from @value{GDBN}.
42016
42017A successful reply from the stub indicates that the stub has found the
42018requested frame. The response is a series of parts, concatenated
42019without separators, describing the frame we selected. Each part has
42020one of the following forms:
42021
42022@table @samp
42023@item F @var{f}
42024The selected frame is number @var{n} in the trace frame buffer;
599b237a 42025@var{f} is a hexadecimal number. If @var{f} is @samp{-1}, then there
9d29849a
JB
42026was no frame matching the criteria in the request packet.
42027
42028@item T @var{t}
42029The selected trace frame records a hit of tracepoint number @var{t};
599b237a 42030@var{t} is a hexadecimal number.
9d29849a
JB
42031
42032@end table
42033
42034@item QTFrame:pc:@var{addr}
42035Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
42036currently selected frame whose PC is @var{addr};
599b237a 42037@var{addr} is a hexadecimal number.
9d29849a
JB
42038
42039@item QTFrame:tdp:@var{t}
42040Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
42041currently selected frame that is a hit of tracepoint @var{t}; @var{t}
599b237a 42042is a hexadecimal number.
9d29849a
JB
42043
42044@item QTFrame:range:@var{start}:@var{end}
42045Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
42046currently selected frame whose PC is between @var{start} (inclusive)
081dfbf7 42047and @var{end} (inclusive); @var{start} and @var{end} are hexadecimal
9d29849a
JB
42048numbers.
42049
42050@item QTFrame:outside:@var{start}:@var{end}
42051Like @samp{QTFrame:range:@var{start}:@var{end}}, but select the first
081dfbf7 42052frame @emph{outside} the given range of addresses (exclusive).
9d29849a 42053
405f8e94 42054@item qTMinFTPILen
c614397c 42055@cindex @samp{qTMinFTPILen} packet
405f8e94
SS
42056This packet requests the minimum length of instruction at which a fast
42057tracepoint (@pxref{Set Tracepoints}) may be placed. For instance, on
42058the 32-bit x86 architecture, it is possible to use a 4-byte jump, but
42059it depends on the target system being able to create trampolines in
42060the first 64K of memory, which might or might not be possible for that
42061system. So the reply to this packet will be 4 if it is able to
42062arrange for that.
42063
42064Replies:
42065
42066@table @samp
42067@item 0
42068The minimum instruction length is currently unknown.
42069@item @var{length}
697aa1b7
EZ
42070The minimum instruction length is @var{length}, where @var{length}
42071is a hexadecimal number greater or equal to 1. A reply
42072of 1 means that a fast tracepoint may be placed on any instruction
42073regardless of size.
405f8e94
SS
42074@item E
42075An error has occurred.
d57350ea 42076@item @w{}
405f8e94
SS
42077An empty reply indicates that the request is not supported by the stub.
42078@end table
42079
9d29849a 42080@item QTStart
c614397c 42081@cindex @samp{QTStart} packet
dde08ee1
PA
42082Begin the tracepoint experiment. Begin collecting data from
42083tracepoint hits in the trace frame buffer. This packet supports the
42084@samp{qRelocInsn} reply (@pxref{Tracepoint Packets,,Relocate
42085instruction reply packet}).
9d29849a
JB
42086
42087@item QTStop
c614397c 42088@cindex @samp{QTStop} packet
9d29849a
JB
42089End the tracepoint experiment. Stop collecting trace frames.
42090
d248b706
KY
42091@item QTEnable:@var{n}:@var{addr}
42092@anchor{QTEnable}
c614397c 42093@cindex @samp{QTEnable} packet
d248b706
KY
42094Enable tracepoint @var{n} at address @var{addr} in a started tracepoint
42095experiment. If the tracepoint was previously disabled, then collection
42096of data from it will resume.
42097
42098@item QTDisable:@var{n}:@var{addr}
42099@anchor{QTDisable}
c614397c 42100@cindex @samp{QTDisable} packet
d248b706
KY
42101Disable tracepoint @var{n} at address @var{addr} in a started tracepoint
42102experiment. No more data will be collected from the tracepoint unless
42103@samp{QTEnable:@var{n}:@var{addr}} is subsequently issued.
42104
9d29849a 42105@item QTinit
c614397c 42106@cindex @samp{QTinit} packet
9d29849a
JB
42107Clear the table of tracepoints, and empty the trace frame buffer.
42108
42109@item QTro:@var{start1},@var{end1}:@var{start2},@var{end2}:@dots{}
c614397c 42110@cindex @samp{QTro} packet
9d29849a
JB
42111Establish the given ranges of memory as ``transparent''. The stub
42112will answer requests for these ranges from memory's current contents,
42113if they were not collected as part of the tracepoint hit.
42114
42115@value{GDBN} uses this to mark read-only regions of memory, like those
42116containing program code. Since these areas never change, they should
42117still have the same contents they did when the tracepoint was hit, so
42118there's no reason for the stub to refuse to provide their contents.
42119
d5551862 42120@item QTDisconnected:@var{value}
c614397c 42121@cindex @samp{QTDisconnected} packet
d5551862
SS
42122Set the choice to what to do with the tracing run when @value{GDBN}
42123disconnects from the target. A @var{value} of 1 directs the target to
42124continue the tracing run, while 0 tells the target to stop tracing if
42125@value{GDBN} is no longer in the picture.
42126
9d29849a 42127@item qTStatus
c614397c 42128@cindex @samp{qTStatus} packet
9d29849a
JB
42129Ask the stub if there is a trace experiment running right now.
42130
4daf5ac0
SS
42131The reply has the form:
42132
42133@table @samp
42134
42135@item T@var{running}@r{[};@var{field}@r{]}@dots{}
42136@var{running} is a single digit @code{1} if the trace is presently
42137running, or @code{0} if not. It is followed by semicolon-separated
42138optional fields that an agent may use to report additional status.
42139
42140@end table
42141
42142If the trace is not running, the agent may report any of several
42143explanations as one of the optional fields:
42144
42145@table @samp
42146
42147@item tnotrun:0
42148No trace has been run yet.
42149
f196051f
SS
42150@item tstop[:@var{text}]:0
42151The trace was stopped by a user-originated stop command. The optional
42152@var{text} field is a user-supplied string supplied as part of the
42153stop command (for instance, an explanation of why the trace was
42154stopped manually). It is hex-encoded.
4daf5ac0
SS
42155
42156@item tfull:0
42157The trace stopped because the trace buffer filled up.
42158
42159@item tdisconnected:0
42160The trace stopped because @value{GDBN} disconnected from the target.
42161
42162@item tpasscount:@var{tpnum}
42163The trace stopped because tracepoint @var{tpnum} exceeded its pass count.
42164
6c28cbf2
SS
42165@item terror:@var{text}:@var{tpnum}
42166The trace stopped because tracepoint @var{tpnum} had an error. The
42167string @var{text} is available to describe the nature of the error
697aa1b7
EZ
42168(for instance, a divide by zero in the condition expression); it
42169is hex encoded.
6c28cbf2 42170
4daf5ac0
SS
42171@item tunknown:0
42172The trace stopped for some other reason.
42173
42174@end table
42175
33da3f1c
SS
42176Additional optional fields supply statistical and other information.
42177Although not required, they are extremely useful for users monitoring
42178the progress of a trace run. If a trace has stopped, and these
42179numbers are reported, they must reflect the state of the just-stopped
42180trace.
4daf5ac0 42181
9d29849a 42182@table @samp
4daf5ac0
SS
42183
42184@item tframes:@var{n}
42185The number of trace frames in the buffer.
42186
42187@item tcreated:@var{n}
42188The total number of trace frames created during the run. This may
42189be larger than the trace frame count, if the buffer is circular.
42190
42191@item tsize:@var{n}
42192The total size of the trace buffer, in bytes.
42193
42194@item tfree:@var{n}
42195The number of bytes still unused in the buffer.
42196
33da3f1c
SS
42197@item circular:@var{n}
42198The value of the circular trace buffer flag. @code{1} means that the
42199trace buffer is circular and old trace frames will be discarded if
42200necessary to make room, @code{0} means that the trace buffer is linear
42201and may fill up.
42202
42203@item disconn:@var{n}
42204The value of the disconnected tracing flag. @code{1} means that
42205tracing will continue after @value{GDBN} disconnects, @code{0} means
42206that the trace run will stop.
42207
9d29849a
JB
42208@end table
42209
f196051f
SS
42210@item qTP:@var{tp}:@var{addr}
42211@cindex tracepoint status, remote request
42212@cindex @samp{qTP} packet
42213Ask the stub for the current state of tracepoint number @var{tp} at
42214address @var{addr}.
42215
42216Replies:
42217@table @samp
42218@item V@var{hits}:@var{usage}
42219The tracepoint has been hit @var{hits} times so far during the trace
42220run, and accounts for @var{usage} in the trace buffer. Note that
42221@code{while-stepping} steps are not counted as separate hits, but the
42222steps' space consumption is added into the usage number.
42223
42224@end table
42225
f61e138d
SS
42226@item qTV:@var{var}
42227@cindex trace state variable value, remote request
42228@cindex @samp{qTV} packet
42229Ask the stub for the value of the trace state variable number @var{var}.
42230
42231Replies:
42232@table @samp
42233@item V@var{value}
42234The value of the variable is @var{value}. This will be the current
42235value of the variable if the user is examining a running target, or a
42236saved value if the variable was collected in the trace frame that the
42237user is looking at. Note that multiple requests may result in
42238different reply values, such as when requesting values while the
42239program is running.
42240
42241@item U
42242The value of the variable is unknown. This would occur, for example,
42243if the user is examining a trace frame in which the requested variable
42244was not collected.
9d29849a
JB
42245@end table
42246
d5551862 42247@item qTfP
c614397c 42248@cindex @samp{qTfP} packet
d5551862 42249@itemx qTsP
c614397c 42250@cindex @samp{qTsP} packet
d5551862
SS
42251These packets request data about tracepoints that are being used by
42252the target. @value{GDBN} sends @code{qTfP} to get the first piece
42253of data, and multiple @code{qTsP} to get additional pieces. Replies
42254to these packets generally take the form of the @code{QTDP} packets
42255that define tracepoints. (FIXME add detailed syntax)
42256
00bf0b85 42257@item qTfV
c614397c 42258@cindex @samp{qTfV} packet
00bf0b85 42259@itemx qTsV
c614397c 42260@cindex @samp{qTsV} packet
00bf0b85
SS
42261These packets request data about trace state variables that are on the
42262target. @value{GDBN} sends @code{qTfV} to get the first vari of data,
42263and multiple @code{qTsV} to get additional variables. Replies to
42264these packets follow the syntax of the @code{QTDV} packets that define
42265trace state variables.
42266
0fb4aa4b
PA
42267@item qTfSTM
42268@itemx qTsSTM
16bdd41f
YQ
42269@anchor{qTfSTM}
42270@anchor{qTsSTM}
c614397c
YQ
42271@cindex @samp{qTfSTM} packet
42272@cindex @samp{qTsSTM} packet
0fb4aa4b
PA
42273These packets request data about static tracepoint markers that exist
42274in the target program. @value{GDBN} sends @code{qTfSTM} to get the
42275first piece of data, and multiple @code{qTsSTM} to get additional
42276pieces. Replies to these packets take the following form:
42277
42278Reply:
42279@table @samp
42280@item m @var{address}:@var{id}:@var{extra}
42281A single marker
42282@item m @var{address}:@var{id}:@var{extra},@var{address}:@var{id}:@var{extra}@dots{}
42283a comma-separated list of markers
42284@item l
42285(lower case letter @samp{L}) denotes end of list.
42286@item E @var{nn}
697aa1b7 42287An error occurred. The error number @var{nn} is given as hex digits.
d57350ea 42288@item @w{}
0fb4aa4b
PA
42289An empty reply indicates that the request is not supported by the
42290stub.
42291@end table
42292
697aa1b7 42293The @var{address} is encoded in hex;
0fb4aa4b
PA
42294@var{id} and @var{extra} are strings encoded in hex.
42295
42296In response to each query, the target will reply with a list of one or
42297more markers, separated by commas. @value{GDBN} will respond to each
42298reply with a request for more markers (using the @samp{qs} form of the
42299query), until the target responds with @samp{l} (lower-case ell, for
42300@dfn{last}).
42301
42302@item qTSTMat:@var{address}
16bdd41f 42303@anchor{qTSTMat}
c614397c 42304@cindex @samp{qTSTMat} packet
0fb4aa4b
PA
42305This packets requests data about static tracepoint markers in the
42306target program at @var{address}. Replies to this packet follow the
42307syntax of the @samp{qTfSTM} and @code{qTsSTM} packets that list static
42308tracepoint markers.
42309
00bf0b85 42310@item QTSave:@var{filename}
c614397c 42311@cindex @samp{QTSave} packet
00bf0b85 42312This packet directs the target to save trace data to the file name
697aa1b7 42313@var{filename} in the target's filesystem. The @var{filename} is encoded
00bf0b85
SS
42314as a hex string; the interpretation of the file name (relative vs
42315absolute, wild cards, etc) is up to the target.
42316
42317@item qTBuffer:@var{offset},@var{len}
c614397c 42318@cindex @samp{qTBuffer} packet
00bf0b85
SS
42319Return up to @var{len} bytes of the current contents of trace buffer,
42320starting at @var{offset}. The trace buffer is treated as if it were
42321a contiguous collection of traceframes, as per the trace file format.
42322The reply consists as many hex-encoded bytes as the target can deliver
42323in a packet; it is not an error to return fewer than were asked for.
42324A reply consisting of just @code{l} indicates that no bytes are
42325available.
42326
4daf5ac0
SS
42327@item QTBuffer:circular:@var{value}
42328This packet directs the target to use a circular trace buffer if
42329@var{value} is 1, or a linear buffer if the value is 0.
42330
f6f899bf 42331@item QTBuffer:size:@var{size}
28abe188
EZ
42332@anchor{QTBuffer-size}
42333@cindex @samp{QTBuffer size} packet
f6f899bf
HAQ
42334This packet directs the target to make the trace buffer be of size
42335@var{size} if possible. A value of @code{-1} tells the target to
42336use whatever size it prefers.
42337
f196051f 42338@item QTNotes:@r{[}@var{type}:@var{text}@r{]}@r{[};@var{type}:@var{text}@r{]}@dots{}
c614397c 42339@cindex @samp{QTNotes} packet
f196051f
SS
42340This packet adds optional textual notes to the trace run. Allowable
42341types include @code{user}, @code{notes}, and @code{tstop}, the
42342@var{text} fields are arbitrary strings, hex-encoded.
42343
f61e138d 42344@end table
9d29849a 42345
dde08ee1
PA
42346@subsection Relocate instruction reply packet
42347When installing fast tracepoints in memory, the target may need to
42348relocate the instruction currently at the tracepoint address to a
42349different address in memory. For most instructions, a simple copy is
42350enough, but, for example, call instructions that implicitly push the
42351return address on the stack, and relative branches or other
42352PC-relative instructions require offset adjustment, so that the effect
42353of executing the instruction at a different address is the same as if
42354it had executed in the original location.
42355
42356In response to several of the tracepoint packets, the target may also
42357respond with a number of intermediate @samp{qRelocInsn} request
42358packets before the final result packet, to have @value{GDBN} handle
42359this relocation operation. If a packet supports this mechanism, its
42360documentation will explicitly say so. See for example the above
42361descriptions for the @samp{QTStart} and @samp{QTDP} packets. The
42362format of the request is:
42363
42364@table @samp
42365@item qRelocInsn:@var{from};@var{to}
42366
42367This requests @value{GDBN} to copy instruction at address @var{from}
42368to address @var{to}, possibly adjusted so that executing the
42369instruction at @var{to} has the same effect as executing it at
42370@var{from}. @value{GDBN} writes the adjusted instruction to target
42371memory starting at @var{to}.
42372@end table
42373
42374Replies:
42375@table @samp
42376@item qRelocInsn:@var{adjusted_size}
697aa1b7 42377Informs the stub the relocation is complete. The @var{adjusted_size} is
dde08ee1
PA
42378the length in bytes of resulting relocated instruction sequence.
42379@item E @var{NN}
42380A badly formed request was detected, or an error was encountered while
42381relocating the instruction.
42382@end table
42383
a6b151f1
DJ
42384@node Host I/O Packets
42385@section Host I/O Packets
42386@cindex Host I/O, remote protocol
42387@cindex file transfer, remote protocol
42388
42389The @dfn{Host I/O} packets allow @value{GDBN} to perform I/O
42390operations on the far side of a remote link. For example, Host I/O is
42391used to upload and download files to a remote target with its own
42392filesystem. Host I/O uses the same constant values and data structure
42393layout as the target-initiated File-I/O protocol. However, the
42394Host I/O packets are structured differently. The target-initiated
42395protocol relies on target memory to store parameters and buffers.
42396Host I/O requests are initiated by @value{GDBN}, and the
42397target's memory is not involved. @xref{File-I/O Remote Protocol
42398Extension}, for more details on the target-initiated protocol.
42399
42400The Host I/O request packets all encode a single operation along with
42401its arguments. They have this format:
42402
42403@table @samp
42404
42405@item vFile:@var{operation}: @var{parameter}@dots{}
42406@var{operation} is the name of the particular request; the target
42407should compare the entire packet name up to the second colon when checking
42408for a supported operation. The format of @var{parameter} depends on
42409the operation. Numbers are always passed in hexadecimal. Negative
42410numbers have an explicit minus sign (i.e.@: two's complement is not
42411used). Strings (e.g.@: filenames) are encoded as a series of
42412hexadecimal bytes. The last argument to a system call may be a
42413buffer of escaped binary data (@pxref{Binary Data}).
42414
42415@end table
42416
42417The valid responses to Host I/O packets are:
42418
42419@table @samp
42420
42421@item F @var{result} [, @var{errno}] [; @var{attachment}]
42422@var{result} is the integer value returned by this operation, usually
42423non-negative for success and -1 for errors. If an error has occured,
697aa1b7 42424@var{errno} will be included in the result specifying a
a6b151f1
DJ
42425value defined by the File-I/O protocol (@pxref{Errno Values}). For
42426operations which return data, @var{attachment} supplies the data as a
42427binary buffer. Binary buffers in response packets are escaped in the
42428normal way (@pxref{Binary Data}). See the individual packet
42429documentation for the interpretation of @var{result} and
42430@var{attachment}.
42431
d57350ea 42432@item @w{}
a6b151f1
DJ
42433An empty response indicates that this operation is not recognized.
42434
42435@end table
42436
42437These are the supported Host I/O operations:
42438
42439@table @samp
697aa1b7
EZ
42440@item vFile:open: @var{filename}, @var{flags}, @var{mode}
42441Open a file at @var{filename} and return a file descriptor for it, or
42442return -1 if an error occurs. The @var{filename} is a string,
a6b151f1
DJ
42443@var{flags} is an integer indicating a mask of open flags
42444(@pxref{Open Flags}), and @var{mode} is an integer indicating a mask
42445of mode bits to use if the file is created (@pxref{mode_t Values}).
c1c25a1a 42446@xref{open}, for details of the open flags and mode values.
a6b151f1
DJ
42447
42448@item vFile:close: @var{fd}
42449Close the open file corresponding to @var{fd} and return 0, or
42450-1 if an error occurs.
42451
42452@item vFile:pread: @var{fd}, @var{count}, @var{offset}
42453Read data from the open file corresponding to @var{fd}. Up to
42454@var{count} bytes will be read from the file, starting at @var{offset}
42455relative to the start of the file. The target may read fewer bytes;
42456common reasons include packet size limits and an end-of-file
42457condition. The number of bytes read is returned. Zero should only be
42458returned for a successful read at the end of the file, or if
42459@var{count} was zero.
42460
42461The data read should be returned as a binary attachment on success.
42462If zero bytes were read, the response should include an empty binary
42463attachment (i.e.@: a trailing semicolon). The return value is the
42464number of target bytes read; the binary attachment may be longer if
42465some characters were escaped.
42466
42467@item vFile:pwrite: @var{fd}, @var{offset}, @var{data}
42468Write @var{data} (a binary buffer) to the open file corresponding
42469to @var{fd}. Start the write at @var{offset} from the start of the
42470file. Unlike many @code{write} system calls, there is no
42471separate @var{count} argument; the length of @var{data} in the
fb092e09 42472packet is used. @samp{vFile:pwrite} returns the number of bytes written,
a6b151f1
DJ
42473which may be shorter than the length of @var{data}, or -1 if an
42474error occurred.
42475
0a93529c
GB
42476@item vFile:fstat: @var{fd}
42477Get information about the open file corresponding to @var{fd}.
42478On success the information is returned as a binary attachment
42479and the return value is the size of this attachment in bytes.
42480If an error occurs the return value is -1. The format of the
42481returned binary attachment is as described in @ref{struct stat}.
42482
697aa1b7
EZ
42483@item vFile:unlink: @var{filename}
42484Delete the file at @var{filename} on the target. Return 0,
42485or -1 if an error occurs. The @var{filename} is a string.
a6b151f1 42486
b9e7b9c3
UW
42487@item vFile:readlink: @var{filename}
42488Read value of symbolic link @var{filename} on the target. Return
42489the number of bytes read, or -1 if an error occurs.
42490
42491The data read should be returned as a binary attachment on success.
42492If zero bytes were read, the response should include an empty binary
42493attachment (i.e.@: a trailing semicolon). The return value is the
42494number of target bytes read; the binary attachment may be longer if
42495some characters were escaped.
42496
15a201c8
GB
42497@item vFile:setfs: @var{pid}
42498Select the filesystem on which @code{vFile} operations with
42499@var{filename} arguments will operate. This is required for
42500@value{GDBN} to be able to access files on remote targets where
42501the remote stub does not share a common filesystem with the
42502inferior(s).
42503
42504If @var{pid} is nonzero, select the filesystem as seen by process
42505@var{pid}. If @var{pid} is zero, select the filesystem as seen by
42506the remote stub. Return 0 on success, or -1 if an error occurs.
42507If @code{vFile:setfs:} indicates success, the selected filesystem
42508remains selected until the next successful @code{vFile:setfs:}
42509operation.
42510
a6b151f1
DJ
42511@end table
42512
9a6253be
KB
42513@node Interrupts
42514@section Interrupts
42515@cindex interrupts (remote protocol)
de979965 42516@anchor{interrupting remote targets}
9a6253be 42517
de979965
PA
42518In all-stop mode, when a program on the remote target is running,
42519@value{GDBN} may attempt to interrupt it by sending a @samp{Ctrl-C},
42520@code{BREAK} or a @code{BREAK} followed by @code{g}, control of which
42521is specified via @value{GDBN}'s @samp{interrupt-sequence}.
9a6253be
KB
42522
42523The precise meaning of @code{BREAK} is defined by the transport
8775bb90
MS
42524mechanism and may, in fact, be undefined. @value{GDBN} does not
42525currently define a @code{BREAK} mechanism for any of the network
42526interfaces except for TCP, in which case @value{GDBN} sends the
42527@code{telnet} BREAK sequence.
9a6253be
KB
42528
42529@samp{Ctrl-C}, on the other hand, is defined and implemented for all
42530transport mechanisms. It is represented by sending the single byte
42531@code{0x03} without any of the usual packet overhead described in
42532the Overview section (@pxref{Overview}). When a @code{0x03} byte is
42533transmitted as part of a packet, it is considered to be packet data
42534and does @emph{not} represent an interrupt. E.g., an @samp{X} packet
0876f84a 42535(@pxref{X packet}), used for binary downloads, may include an unescaped
9a6253be
KB
42536@code{0x03} as part of its packet.
42537
9a7071a8
JB
42538@code{BREAK} followed by @code{g} is also known as Magic SysRq g.
42539When Linux kernel receives this sequence from serial port,
42540it stops execution and connects to gdb.
42541
de979965
PA
42542In non-stop mode, because packet resumptions are asynchronous
42543(@pxref{vCont packet}), @value{GDBN} is always free to send a remote
42544command to the remote stub, even when the target is running. For that
42545reason, @value{GDBN} instead sends a regular packet (@pxref{vCtrlC
42546packet}) with the usual packet framing instead of the single byte
42547@code{0x03}.
42548
9a6253be
KB
42549Stubs are not required to recognize these interrupt mechanisms and the
42550precise meaning associated with receipt of the interrupt is
8b23ecc4
SL
42551implementation defined. If the target supports debugging of multiple
42552threads and/or processes, it should attempt to interrupt all
42553currently-executing threads and processes.
42554If the stub is successful at interrupting the
42555running program, it should send one of the stop
42556reply packets (@pxref{Stop Reply Packets}) to @value{GDBN} as a result
42557of successfully stopping the program in all-stop mode, and a stop reply
42558for each stopped thread in non-stop mode.
42559Interrupts received while the
cde67b27
YQ
42560program is stopped are queued and the program will be interrupted when
42561it is resumed next time.
8b23ecc4
SL
42562
42563@node Notification Packets
42564@section Notification Packets
42565@cindex notification packets
42566@cindex packets, notification
42567
42568The @value{GDBN} remote serial protocol includes @dfn{notifications},
42569packets that require no acknowledgment. Both the GDB and the stub
42570may send notifications (although the only notifications defined at
42571present are sent by the stub). Notifications carry information
42572without incurring the round-trip latency of an acknowledgment, and so
42573are useful for low-impact communications where occasional packet loss
42574is not a problem.
42575
42576A notification packet has the form @samp{% @var{data} #
42577@var{checksum}}, where @var{data} is the content of the notification,
42578and @var{checksum} is a checksum of @var{data}, computed and formatted
42579as for ordinary @value{GDBN} packets. A notification's @var{data}
42580never contains @samp{$}, @samp{%} or @samp{#} characters. Upon
42581receiving a notification, the recipient sends no @samp{+} or @samp{-}
42582to acknowledge the notification's receipt or to report its corruption.
42583
42584Every notification's @var{data} begins with a name, which contains no
42585colon characters, followed by a colon character.
42586
42587Recipients should silently ignore corrupted notifications and
42588notifications they do not understand. Recipients should restart
42589timeout periods on receipt of a well-formed notification, whether or
42590not they understand it.
42591
42592Senders should only send the notifications described here when this
42593protocol description specifies that they are permitted. In the
42594future, we may extend the protocol to permit existing notifications in
42595new contexts; this rule helps older senders avoid confusing newer
42596recipients.
42597
42598(Older versions of @value{GDBN} ignore bytes received until they see
42599the @samp{$} byte that begins an ordinary packet, so new stubs may
42600transmit notifications without fear of confusing older clients. There
42601are no notifications defined for @value{GDBN} to send at the moment, but we
42602assume that most older stubs would ignore them, as well.)
42603
8dbe8ece 42604Each notification is comprised of three parts:
8b23ecc4 42605@table @samp
8dbe8ece
YQ
42606@item @var{name}:@var{event}
42607The notification packet is sent by the side that initiates the
42608exchange (currently, only the stub does that), with @var{event}
697aa1b7
EZ
42609carrying the specific information about the notification, and
42610@var{name} specifying the name of the notification.
8dbe8ece
YQ
42611@item @var{ack}
42612The acknowledge sent by the other side, usually @value{GDBN}, to
42613acknowledge the exchange and request the event.
42614@end table
42615
42616The purpose of an asynchronous notification mechanism is to report to
42617@value{GDBN} that something interesting happened in the remote stub.
42618
42619The remote stub may send notification @var{name}:@var{event}
42620at any time, but @value{GDBN} acknowledges the notification when
42621appropriate. The notification event is pending before @value{GDBN}
42622acknowledges. Only one notification at a time may be pending; if
42623additional events occur before @value{GDBN} has acknowledged the
42624previous notification, they must be queued by the stub for later
42625synchronous transmission in response to @var{ack} packets from
42626@value{GDBN}. Because the notification mechanism is unreliable,
42627the stub is permitted to resend a notification if it believes
42628@value{GDBN} may not have received it.
42629
42630Specifically, notifications may appear when @value{GDBN} is not
42631otherwise reading input from the stub, or when @value{GDBN} is
42632expecting to read a normal synchronous response or a
42633@samp{+}/@samp{-} acknowledgment to a packet it has sent.
42634Notification packets are distinct from any other communication from
42635the stub so there is no ambiguity.
42636
42637After receiving a notification, @value{GDBN} shall acknowledge it by
42638sending a @var{ack} packet as a regular, synchronous request to the
42639stub. Such acknowledgment is not required to happen immediately, as
42640@value{GDBN} is permitted to send other, unrelated packets to the
42641stub first, which the stub should process normally.
42642
42643Upon receiving a @var{ack} packet, if the stub has other queued
42644events to report to @value{GDBN}, it shall respond by sending a
42645normal @var{event}. @value{GDBN} shall then send another @var{ack}
42646packet to solicit further responses; again, it is permitted to send
42647other, unrelated packets as well which the stub should process
42648normally.
42649
42650If the stub receives a @var{ack} packet and there are no additional
42651@var{event} to report, the stub shall return an @samp{OK} response.
42652At this point, @value{GDBN} has finished processing a notification
42653and the stub has completed sending any queued events. @value{GDBN}
42654won't accept any new notifications until the final @samp{OK} is
42655received . If further notification events occur, the stub shall send
42656a new notification, @value{GDBN} shall accept the notification, and
42657the process shall be repeated.
42658
42659The process of asynchronous notification can be illustrated by the
42660following example:
42661@smallexample
4435e1cc 42662<- @code{%Stop:T0505:98e7ffbf;04:4ce6ffbf;08:b1b6e54c;thread:p7526.7526;core:0;}
8dbe8ece
YQ
42663@code{...}
42664-> @code{vStopped}
42665<- @code{T0505:68f37db7;04:40f37db7;08:63850408;thread:p7526.7528;core:0;}
42666-> @code{vStopped}
42667<- @code{T0505:68e3fdb6;04:40e3fdb6;08:63850408;thread:p7526.7529;core:0;}
42668-> @code{vStopped}
42669<- @code{OK}
42670@end smallexample
42671
42672The following notifications are defined:
42673@multitable @columnfractions 0.12 0.12 0.38 0.38
42674
42675@item Notification
42676@tab Ack
42677@tab Event
42678@tab Description
42679
42680@item Stop
42681@tab vStopped
42682@tab @var{reply}. The @var{reply} has the form of a stop reply, as
8b23ecc4
SL
42683described in @ref{Stop Reply Packets}. Refer to @ref{Remote Non-Stop},
42684for information on how these notifications are acknowledged by
42685@value{GDBN}.
8dbe8ece
YQ
42686@tab Report an asynchronous stop event in non-stop mode.
42687
42688@end multitable
8b23ecc4
SL
42689
42690@node Remote Non-Stop
42691@section Remote Protocol Support for Non-Stop Mode
42692
42693@value{GDBN}'s remote protocol supports non-stop debugging of
42694multi-threaded programs, as described in @ref{Non-Stop Mode}. If the stub
42695supports non-stop mode, it should report that to @value{GDBN} by including
42696@samp{QNonStop+} in its @samp{qSupported} response (@pxref{qSupported}).
42697
42698@value{GDBN} typically sends a @samp{QNonStop} packet only when
42699establishing a new connection with the stub. Entering non-stop mode
42700does not alter the state of any currently-running threads, but targets
42701must stop all threads in any already-attached processes when entering
42702all-stop mode. @value{GDBN} uses the @samp{?} packet as necessary to
42703probe the target state after a mode change.
42704
42705In non-stop mode, when an attached process encounters an event that
42706would otherwise be reported with a stop reply, it uses the
42707asynchronous notification mechanism (@pxref{Notification Packets}) to
42708inform @value{GDBN}. In contrast to all-stop mode, where all threads
42709in all processes are stopped when a stop reply is sent, in non-stop
42710mode only the thread reporting the stop event is stopped. That is,
42711when reporting a @samp{S} or @samp{T} response to indicate completion
42712of a step operation, hitting a breakpoint, or a fault, only the
42713affected thread is stopped; any other still-running threads continue
42714to run. When reporting a @samp{W} or @samp{X} response, all running
42715threads belonging to other attached processes continue to run.
42716
8b23ecc4
SL
42717In non-stop mode, the target shall respond to the @samp{?} packet as
42718follows. First, any incomplete stop reply notification/@samp{vStopped}
42719sequence in progress is abandoned. The target must begin a new
42720sequence reporting stop events for all stopped threads, whether or not
42721it has previously reported those events to @value{GDBN}. The first
42722stop reply is sent as a synchronous reply to the @samp{?} packet, and
42723subsequent stop replies are sent as responses to @samp{vStopped} packets
42724using the mechanism described above. The target must not send
42725asynchronous stop reply notifications until the sequence is complete.
42726If all threads are running when the target receives the @samp{?} packet,
42727or if the target is not attached to any process, it shall respond
42728@samp{OK}.
9a6253be 42729
f7e6eed5
PA
42730If the stub supports non-stop mode, it should also support the
42731@samp{swbreak} stop reason if software breakpoints are supported, and
42732the @samp{hwbreak} stop reason if hardware breakpoints are supported
42733(@pxref{swbreak stop reason}). This is because given the asynchronous
42734nature of non-stop mode, between the time a thread hits a breakpoint
42735and the time the event is finally processed by @value{GDBN}, the
42736breakpoint may have already been removed from the target. Due to
42737this, @value{GDBN} needs to be able to tell whether a trap stop was
42738caused by a delayed breakpoint event, which should be ignored, as
42739opposed to a random trap signal, which should be reported to the user.
42740Note the @samp{swbreak} feature implies that the target is responsible
42741for adjusting the PC when a software breakpoint triggers, if
42742necessary, such as on the x86 architecture.
42743
a6f3e723
SL
42744@node Packet Acknowledgment
42745@section Packet Acknowledgment
42746
42747@cindex acknowledgment, for @value{GDBN} remote
42748@cindex packet acknowledgment, for @value{GDBN} remote
42749By default, when either the host or the target machine receives a packet,
42750the first response expected is an acknowledgment: either @samp{+} (to indicate
42751the package was received correctly) or @samp{-} (to request retransmission).
42752This mechanism allows the @value{GDBN} remote protocol to operate over
42753unreliable transport mechanisms, such as a serial line.
42754
42755In cases where the transport mechanism is itself reliable (such as a pipe or
42756TCP connection), the @samp{+}/@samp{-} acknowledgments are redundant.
42757It may be desirable to disable them in that case to reduce communication
42758overhead, or for other reasons. This can be accomplished by means of the
42759@samp{QStartNoAckMode} packet; @pxref{QStartNoAckMode}.
42760
42761When in no-acknowledgment mode, neither the stub nor @value{GDBN} shall send or
42762expect @samp{+}/@samp{-} protocol acknowledgments. The packet
42763and response format still includes the normal checksum, as described in
42764@ref{Overview}, but the checksum may be ignored by the receiver.
42765
42766If the stub supports @samp{QStartNoAckMode} and prefers to operate in
42767no-acknowledgment mode, it should report that to @value{GDBN}
42768by including @samp{QStartNoAckMode+} in its response to @samp{qSupported};
42769@pxref{qSupported}.
42770If @value{GDBN} also supports @samp{QStartNoAckMode} and it has not been
42771disabled via the @code{set remote noack-packet off} command
42772(@pxref{Remote Configuration}),
42773@value{GDBN} may then send a @samp{QStartNoAckMode} packet to the stub.
42774Only then may the stub actually turn off packet acknowledgments.
42775@value{GDBN} sends a final @samp{+} acknowledgment of the stub's @samp{OK}
42776response, which can be safely ignored by the stub.
42777
42778Note that @code{set remote noack-packet} command only affects negotiation
42779between @value{GDBN} and the stub when subsequent connections are made;
42780it does not affect the protocol acknowledgment state for any current
42781connection.
42782Since @samp{+}/@samp{-} acknowledgments are enabled by default when a
42783new connection is established,
42784there is also no protocol request to re-enable the acknowledgments
42785for the current connection, once disabled.
42786
ee2d5c50
AC
42787@node Examples
42788@section Examples
eb12ee30 42789
8e04817f
AC
42790Example sequence of a target being re-started. Notice how the restart
42791does not get any direct output:
eb12ee30 42792
474c8240 42793@smallexample
d2c6833e
AC
42794-> @code{R00}
42795<- @code{+}
8e04817f 42796@emph{target restarts}
d2c6833e 42797-> @code{?}
8e04817f 42798<- @code{+}
d2c6833e
AC
42799<- @code{T001:1234123412341234}
42800-> @code{+}
474c8240 42801@end smallexample
eb12ee30 42802
8e04817f 42803Example sequence of a target being stepped by a single instruction:
eb12ee30 42804
474c8240 42805@smallexample
d2c6833e 42806-> @code{G1445@dots{}}
8e04817f 42807<- @code{+}
d2c6833e
AC
42808-> @code{s}
42809<- @code{+}
42810@emph{time passes}
42811<- @code{T001:1234123412341234}
8e04817f 42812-> @code{+}
d2c6833e 42813-> @code{g}
8e04817f 42814<- @code{+}
d2c6833e
AC
42815<- @code{1455@dots{}}
42816-> @code{+}
474c8240 42817@end smallexample
eb12ee30 42818
79a6e687
BW
42819@node File-I/O Remote Protocol Extension
42820@section File-I/O Remote Protocol Extension
0ce1b118
CV
42821@cindex File-I/O remote protocol extension
42822
42823@menu
42824* File-I/O Overview::
79a6e687
BW
42825* Protocol Basics::
42826* The F Request Packet::
42827* The F Reply Packet::
42828* The Ctrl-C Message::
0ce1b118 42829* Console I/O::
79a6e687 42830* List of Supported Calls::
db2e3e2e 42831* Protocol-specific Representation of Datatypes::
0ce1b118
CV
42832* Constants::
42833* File-I/O Examples::
42834@end menu
42835
42836@node File-I/O Overview
42837@subsection File-I/O Overview
42838@cindex file-i/o overview
42839
9c16f35a 42840The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
fc320d37 42841target to use the host's file system and console I/O to perform various
0ce1b118 42842system calls. System calls on the target system are translated into a
fc320d37
SL
42843remote protocol packet to the host system, which then performs the needed
42844actions and returns a response packet to the target system.
0ce1b118
CV
42845This simulates file system operations even on targets that lack file systems.
42846
fc320d37
SL
42847The protocol is defined to be independent of both the host and target systems.
42848It uses its own internal representation of datatypes and values. Both
0ce1b118 42849@value{GDBN} and the target's @value{GDBN} stub are responsible for
fc320d37
SL
42850translating the system-dependent value representations into the internal
42851protocol representations when data is transmitted.
0ce1b118 42852
fc320d37
SL
42853The communication is synchronous. A system call is possible only when
42854@value{GDBN} is waiting for a response from the @samp{C}, @samp{c}, @samp{S}
42855or @samp{s} packets. While @value{GDBN} handles the request for a system call,
0ce1b118 42856the target is stopped to allow deterministic access to the target's
fc320d37
SL
42857memory. Therefore File-I/O is not interruptible by target signals. On
42858the other hand, it is possible to interrupt File-I/O by a user interrupt
c8aa23ab 42859(@samp{Ctrl-C}) within @value{GDBN}.
0ce1b118
CV
42860
42861The target's request to perform a host system call does not finish
42862the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action. That means,
42863after finishing the system call, the target returns to continuing the
42864previous activity (continue, step). No additional continue or step
42865request from @value{GDBN} is required.
42866
42867@smallexample
f7dc1244 42868(@value{GDBP}) continue
0ce1b118
CV
42869 <- target requests 'system call X'
42870 target is stopped, @value{GDBN} executes system call
3f94c067
BW
42871 -> @value{GDBN} returns result
42872 ... target continues, @value{GDBN} returns to wait for the target
0ce1b118
CV
42873 <- target hits breakpoint and sends a Txx packet
42874@end smallexample
42875
fc320d37
SL
42876The protocol only supports I/O on the console and to regular files on
42877the host file system. Character or block special devices, pipes,
42878named pipes, sockets or any other communication method on the host
0ce1b118
CV
42879system are not supported by this protocol.
42880
8b23ecc4
SL
42881File I/O is not supported in non-stop mode.
42882
79a6e687
BW
42883@node Protocol Basics
42884@subsection Protocol Basics
0ce1b118
CV
42885@cindex protocol basics, file-i/o
42886
fc320d37
SL
42887The File-I/O protocol uses the @code{F} packet as the request as well
42888as reply packet. Since a File-I/O system call can only occur when
42889@value{GDBN} is waiting for a response from the continuing or stepping target,
42890the File-I/O request is a reply that @value{GDBN} has to expect as a result
42891of a previous @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
0ce1b118
CV
42892This @code{F} packet contains all information needed to allow @value{GDBN}
42893to call the appropriate host system call:
42894
42895@itemize @bullet
b383017d 42896@item
0ce1b118
CV
42897A unique identifier for the requested system call.
42898
42899@item
42900All parameters to the system call. Pointers are given as addresses
42901in the target memory address space. Pointers to strings are given as
b383017d 42902pointer/length pair. Numerical values are given as they are.
db2e3e2e 42903Numerical control flags are given in a protocol-specific representation.
0ce1b118
CV
42904
42905@end itemize
42906
fc320d37 42907At this point, @value{GDBN} has to perform the following actions.
0ce1b118
CV
42908
42909@itemize @bullet
b383017d 42910@item
fc320d37
SL
42911If the parameters include pointer values to data needed as input to a
42912system call, @value{GDBN} requests this data from the target with a
0ce1b118
CV
42913standard @code{m} packet request. This additional communication has to be
42914expected by the target implementation and is handled as any other @code{m}
42915packet.
42916
42917@item
42918@value{GDBN} translates all value from protocol representation to host
42919representation as needed. Datatypes are coerced into the host types.
42920
42921@item
fc320d37 42922@value{GDBN} calls the system call.
0ce1b118
CV
42923
42924@item
42925It then coerces datatypes back to protocol representation.
42926
42927@item
fc320d37
SL
42928If the system call is expected to return data in buffer space specified
42929by pointer parameters to the call, the data is transmitted to the
0ce1b118
CV
42930target using a @code{M} or @code{X} packet. This packet has to be expected
42931by the target implementation and is handled as any other @code{M} or @code{X}
42932packet.
42933
42934@end itemize
42935
42936Eventually @value{GDBN} replies with another @code{F} packet which contains all
42937necessary information for the target to continue. This at least contains
42938
42939@itemize @bullet
42940@item
42941Return value.
42942
42943@item
42944@code{errno}, if has been changed by the system call.
42945
42946@item
42947``Ctrl-C'' flag.
42948
42949@end itemize
42950
42951After having done the needed type and value coercion, the target continues
42952the latest continue or step action.
42953
79a6e687
BW
42954@node The F Request Packet
42955@subsection The @code{F} Request Packet
0ce1b118
CV
42956@cindex file-i/o request packet
42957@cindex @code{F} request packet
42958
42959The @code{F} request packet has the following format:
42960
42961@table @samp
fc320d37 42962@item F@var{call-id},@var{parameter@dots{}}
0ce1b118
CV
42963
42964@var{call-id} is the identifier to indicate the host system call to be called.
42965This is just the name of the function.
42966
fc320d37
SL
42967@var{parameter@dots{}} are the parameters to the system call.
42968Parameters are hexadecimal integer values, either the actual values in case
42969of scalar datatypes, pointers to target buffer space in case of compound
42970datatypes and unspecified memory areas, or pointer/length pairs in case
42971of string parameters. These are appended to the @var{call-id} as a
42972comma-delimited list. All values are transmitted in ASCII
42973string representation, pointer/length pairs separated by a slash.
0ce1b118 42974
b383017d 42975@end table
0ce1b118 42976
fc320d37 42977
0ce1b118 42978
79a6e687
BW
42979@node The F Reply Packet
42980@subsection The @code{F} Reply Packet
0ce1b118
CV
42981@cindex file-i/o reply packet
42982@cindex @code{F} reply packet
42983
42984The @code{F} reply packet has the following format:
42985
42986@table @samp
42987
d3bdde98 42988@item F@var{retcode},@var{errno},@var{Ctrl-C flag};@var{call-specific attachment}
0ce1b118
CV
42989
42990@var{retcode} is the return code of the system call as hexadecimal value.
42991
db2e3e2e
BW
42992@var{errno} is the @code{errno} set by the call, in protocol-specific
42993representation.
0ce1b118
CV
42994This parameter can be omitted if the call was successful.
42995
fc320d37
SL
42996@var{Ctrl-C flag} is only sent if the user requested a break. In this
42997case, @var{errno} must be sent as well, even if the call was successful.
42998The @var{Ctrl-C flag} itself consists of the character @samp{C}:
0ce1b118
CV
42999
43000@smallexample
43001F0,0,C
43002@end smallexample
43003
43004@noindent
fc320d37 43005or, if the call was interrupted before the host call has been performed:
0ce1b118
CV
43006
43007@smallexample
43008F-1,4,C
43009@end smallexample
43010
43011@noindent
db2e3e2e 43012assuming 4 is the protocol-specific representation of @code{EINTR}.
0ce1b118
CV
43013
43014@end table
43015
0ce1b118 43016
79a6e687
BW
43017@node The Ctrl-C Message
43018@subsection The @samp{Ctrl-C} Message
0ce1b118
CV
43019@cindex ctrl-c message, in file-i/o protocol
43020
c8aa23ab 43021If the @samp{Ctrl-C} flag is set in the @value{GDBN}
79a6e687 43022reply packet (@pxref{The F Reply Packet}),
fc320d37 43023the target should behave as if it had
0ce1b118 43024gotten a break message. The meaning for the target is ``system call
fc320d37 43025interrupted by @code{SIGINT}''. Consequentially, the target should actually stop
0ce1b118 43026(as with a break message) and return to @value{GDBN} with a @code{T02}
c8aa23ab 43027packet.
fc320d37
SL
43028
43029It's important for the target to know in which
43030state the system call was interrupted. There are two possible cases:
0ce1b118
CV
43031
43032@itemize @bullet
43033@item
43034The system call hasn't been performed on the host yet.
43035
43036@item
43037The system call on the host has been finished.
43038
43039@end itemize
43040
43041These two states can be distinguished by the target by the value of the
43042returned @code{errno}. If it's the protocol representation of @code{EINTR}, the system
43043call hasn't been performed. This is equivalent to the @code{EINTR} handling
43044on POSIX systems. In any other case, the target may presume that the
fc320d37 43045system call has been finished --- successfully or not --- and should behave
0ce1b118
CV
43046as if the break message arrived right after the system call.
43047
fc320d37 43048@value{GDBN} must behave reliably. If the system call has not been called
0ce1b118
CV
43049yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
43050@code{errno} in the packet. If the system call on the host has been finished
fc320d37
SL
43051before the user requests a break, the full action must be finished by
43052@value{GDBN}. This requires sending @code{M} or @code{X} packets as necessary.
43053The @code{F} packet may only be sent when either nothing has happened
0ce1b118
CV
43054or the full action has been completed.
43055
43056@node Console I/O
43057@subsection Console I/O
43058@cindex console i/o as part of file-i/o
43059
d3e8051b 43060By default and if not explicitly closed by the target system, the file
0ce1b118
CV
43061descriptors 0, 1 and 2 are connected to the @value{GDBN} console. Output
43062on the @value{GDBN} console is handled as any other file output operation
43063(@code{write(1, @dots{})} or @code{write(2, @dots{})}). Console input is handled
43064by @value{GDBN} so that after the target read request from file descriptor
430650 all following typing is buffered until either one of the following
43066conditions is met:
43067
43068@itemize @bullet
43069@item
c8aa23ab 43070The user types @kbd{Ctrl-c}. The behaviour is as explained above, and the
0ce1b118
CV
43071@code{read}
43072system call is treated as finished.
43073
43074@item
7f9087cb 43075The user presses @key{RET}. This is treated as end of input with a trailing
fc320d37 43076newline.
0ce1b118
CV
43077
43078@item
c8aa23ab
EZ
43079The user types @kbd{Ctrl-d}. This is treated as end of input. No trailing
43080character (neither newline nor @samp{Ctrl-D}) is appended to the input.
0ce1b118
CV
43081
43082@end itemize
43083
fc320d37
SL
43084If the user has typed more characters than fit in the buffer given to
43085the @code{read} call, the trailing characters are buffered in @value{GDBN} until
43086either another @code{read(0, @dots{})} is requested by the target, or debugging
43087is stopped at the user's request.
0ce1b118 43088
0ce1b118 43089
79a6e687
BW
43090@node List of Supported Calls
43091@subsection List of Supported Calls
0ce1b118
CV
43092@cindex list of supported file-i/o calls
43093
43094@menu
43095* open::
43096* close::
43097* read::
43098* write::
43099* lseek::
43100* rename::
43101* unlink::
43102* stat/fstat::
43103* gettimeofday::
43104* isatty::
43105* system::
43106@end menu
43107
43108@node open
43109@unnumberedsubsubsec open
43110@cindex open, file-i/o system call
43111
fc320d37
SL
43112@table @asis
43113@item Synopsis:
0ce1b118 43114@smallexample
0ce1b118
CV
43115int open(const char *pathname, int flags);
43116int open(const char *pathname, int flags, mode_t mode);
0ce1b118
CV
43117@end smallexample
43118
fc320d37
SL
43119@item Request:
43120@samp{Fopen,@var{pathptr}/@var{len},@var{flags},@var{mode}}
43121
0ce1b118 43122@noindent
fc320d37 43123@var{flags} is the bitwise @code{OR} of the following values:
0ce1b118
CV
43124
43125@table @code
b383017d 43126@item O_CREAT
0ce1b118
CV
43127If the file does not exist it will be created. The host
43128rules apply as far as file ownership and time stamps
43129are concerned.
43130
b383017d 43131@item O_EXCL
fc320d37 43132When used with @code{O_CREAT}, if the file already exists it is
0ce1b118
CV
43133an error and open() fails.
43134
b383017d 43135@item O_TRUNC
0ce1b118 43136If the file already exists and the open mode allows
fc320d37
SL
43137writing (@code{O_RDWR} or @code{O_WRONLY} is given) it will be
43138truncated to zero length.
0ce1b118 43139
b383017d 43140@item O_APPEND
0ce1b118
CV
43141The file is opened in append mode.
43142
b383017d 43143@item O_RDONLY
0ce1b118
CV
43144The file is opened for reading only.
43145
b383017d 43146@item O_WRONLY
0ce1b118
CV
43147The file is opened for writing only.
43148
b383017d 43149@item O_RDWR
0ce1b118 43150The file is opened for reading and writing.
fc320d37 43151@end table
0ce1b118
CV
43152
43153@noindent
fc320d37 43154Other bits are silently ignored.
0ce1b118 43155
0ce1b118
CV
43156
43157@noindent
fc320d37 43158@var{mode} is the bitwise @code{OR} of the following values:
0ce1b118
CV
43159
43160@table @code
b383017d 43161@item S_IRUSR
0ce1b118
CV
43162User has read permission.
43163
b383017d 43164@item S_IWUSR
0ce1b118
CV
43165User has write permission.
43166
b383017d 43167@item S_IRGRP
0ce1b118
CV
43168Group has read permission.
43169
b383017d 43170@item S_IWGRP
0ce1b118
CV
43171Group has write permission.
43172
b383017d 43173@item S_IROTH
0ce1b118
CV
43174Others have read permission.
43175
b383017d 43176@item S_IWOTH
0ce1b118 43177Others have write permission.
fc320d37 43178@end table
0ce1b118
CV
43179
43180@noindent
fc320d37 43181Other bits are silently ignored.
0ce1b118 43182
0ce1b118 43183
fc320d37
SL
43184@item Return value:
43185@code{open} returns the new file descriptor or -1 if an error
43186occurred.
0ce1b118 43187
fc320d37 43188@item Errors:
0ce1b118
CV
43189
43190@table @code
b383017d 43191@item EEXIST
fc320d37 43192@var{pathname} already exists and @code{O_CREAT} and @code{O_EXCL} were used.
0ce1b118 43193
b383017d 43194@item EISDIR
fc320d37 43195@var{pathname} refers to a directory.
0ce1b118 43196
b383017d 43197@item EACCES
0ce1b118
CV
43198The requested access is not allowed.
43199
43200@item ENAMETOOLONG
fc320d37 43201@var{pathname} was too long.
0ce1b118 43202
b383017d 43203@item ENOENT
fc320d37 43204A directory component in @var{pathname} does not exist.
0ce1b118 43205
b383017d 43206@item ENODEV
fc320d37 43207@var{pathname} refers to a device, pipe, named pipe or socket.
0ce1b118 43208
b383017d 43209@item EROFS
fc320d37 43210@var{pathname} refers to a file on a read-only filesystem and
0ce1b118
CV
43211write access was requested.
43212
b383017d 43213@item EFAULT
fc320d37 43214@var{pathname} is an invalid pointer value.
0ce1b118 43215
b383017d 43216@item ENOSPC
0ce1b118
CV
43217No space on device to create the file.
43218
b383017d 43219@item EMFILE
0ce1b118
CV
43220The process already has the maximum number of files open.
43221
b383017d 43222@item ENFILE
0ce1b118
CV
43223The limit on the total number of files open on the system
43224has been reached.
43225
b383017d 43226@item EINTR
0ce1b118
CV
43227The call was interrupted by the user.
43228@end table
43229
fc320d37
SL
43230@end table
43231
0ce1b118
CV
43232@node close
43233@unnumberedsubsubsec close
43234@cindex close, file-i/o system call
43235
fc320d37
SL
43236@table @asis
43237@item Synopsis:
0ce1b118 43238@smallexample
0ce1b118 43239int close(int fd);
fc320d37 43240@end smallexample
0ce1b118 43241
fc320d37
SL
43242@item Request:
43243@samp{Fclose,@var{fd}}
0ce1b118 43244
fc320d37
SL
43245@item Return value:
43246@code{close} returns zero on success, or -1 if an error occurred.
0ce1b118 43247
fc320d37 43248@item Errors:
0ce1b118
CV
43249
43250@table @code
b383017d 43251@item EBADF
fc320d37 43252@var{fd} isn't a valid open file descriptor.
0ce1b118 43253
b383017d 43254@item EINTR
0ce1b118
CV
43255The call was interrupted by the user.
43256@end table
43257
fc320d37
SL
43258@end table
43259
0ce1b118
CV
43260@node read
43261@unnumberedsubsubsec read
43262@cindex read, file-i/o system call
43263
fc320d37
SL
43264@table @asis
43265@item Synopsis:
0ce1b118 43266@smallexample
0ce1b118 43267int read(int fd, void *buf, unsigned int count);
fc320d37 43268@end smallexample
0ce1b118 43269
fc320d37
SL
43270@item Request:
43271@samp{Fread,@var{fd},@var{bufptr},@var{count}}
0ce1b118 43272
fc320d37 43273@item Return value:
0ce1b118
CV
43274On success, the number of bytes read is returned.
43275Zero indicates end of file. If count is zero, read
b383017d 43276returns zero as well. On error, -1 is returned.
0ce1b118 43277
fc320d37 43278@item Errors:
0ce1b118
CV
43279
43280@table @code
b383017d 43281@item EBADF
fc320d37 43282@var{fd} is not a valid file descriptor or is not open for
0ce1b118
CV
43283reading.
43284
b383017d 43285@item EFAULT
fc320d37 43286@var{bufptr} is an invalid pointer value.
0ce1b118 43287
b383017d 43288@item EINTR
0ce1b118
CV
43289The call was interrupted by the user.
43290@end table
43291
fc320d37
SL
43292@end table
43293
0ce1b118
CV
43294@node write
43295@unnumberedsubsubsec write
43296@cindex write, file-i/o system call
43297
fc320d37
SL
43298@table @asis
43299@item Synopsis:
0ce1b118 43300@smallexample
0ce1b118 43301int write(int fd, const void *buf, unsigned int count);
fc320d37 43302@end smallexample
0ce1b118 43303
fc320d37
SL
43304@item Request:
43305@samp{Fwrite,@var{fd},@var{bufptr},@var{count}}
0ce1b118 43306
fc320d37 43307@item Return value:
0ce1b118
CV
43308On success, the number of bytes written are returned.
43309Zero indicates nothing was written. On error, -1
43310is returned.
43311
fc320d37 43312@item Errors:
0ce1b118
CV
43313
43314@table @code
b383017d 43315@item EBADF
fc320d37 43316@var{fd} is not a valid file descriptor or is not open for
0ce1b118
CV
43317writing.
43318
b383017d 43319@item EFAULT
fc320d37 43320@var{bufptr} is an invalid pointer value.
0ce1b118 43321
b383017d 43322@item EFBIG
0ce1b118 43323An attempt was made to write a file that exceeds the
db2e3e2e 43324host-specific maximum file size allowed.
0ce1b118 43325
b383017d 43326@item ENOSPC
0ce1b118
CV
43327No space on device to write the data.
43328
b383017d 43329@item EINTR
0ce1b118
CV
43330The call was interrupted by the user.
43331@end table
43332
fc320d37
SL
43333@end table
43334
0ce1b118
CV
43335@node lseek
43336@unnumberedsubsubsec lseek
43337@cindex lseek, file-i/o system call
43338
fc320d37
SL
43339@table @asis
43340@item Synopsis:
0ce1b118 43341@smallexample
0ce1b118 43342long lseek (int fd, long offset, int flag);
0ce1b118
CV
43343@end smallexample
43344
fc320d37
SL
43345@item Request:
43346@samp{Flseek,@var{fd},@var{offset},@var{flag}}
43347
43348@var{flag} is one of:
0ce1b118
CV
43349
43350@table @code
b383017d 43351@item SEEK_SET
fc320d37 43352The offset is set to @var{offset} bytes.
0ce1b118 43353
b383017d 43354@item SEEK_CUR
fc320d37 43355The offset is set to its current location plus @var{offset}
0ce1b118
CV
43356bytes.
43357
b383017d 43358@item SEEK_END
fc320d37 43359The offset is set to the size of the file plus @var{offset}
0ce1b118
CV
43360bytes.
43361@end table
43362
fc320d37 43363@item Return value:
0ce1b118
CV
43364On success, the resulting unsigned offset in bytes from
43365the beginning of the file is returned. Otherwise, a
43366value of -1 is returned.
43367
fc320d37 43368@item Errors:
0ce1b118
CV
43369
43370@table @code
b383017d 43371@item EBADF
fc320d37 43372@var{fd} is not a valid open file descriptor.
0ce1b118 43373
b383017d 43374@item ESPIPE
fc320d37 43375@var{fd} is associated with the @value{GDBN} console.
0ce1b118 43376
b383017d 43377@item EINVAL
fc320d37 43378@var{flag} is not a proper value.
0ce1b118 43379
b383017d 43380@item EINTR
0ce1b118
CV
43381The call was interrupted by the user.
43382@end table
43383
fc320d37
SL
43384@end table
43385
0ce1b118
CV
43386@node rename
43387@unnumberedsubsubsec rename
43388@cindex rename, file-i/o system call
43389
fc320d37
SL
43390@table @asis
43391@item Synopsis:
0ce1b118 43392@smallexample
0ce1b118 43393int rename(const char *oldpath, const char *newpath);
fc320d37 43394@end smallexample
0ce1b118 43395
fc320d37
SL
43396@item Request:
43397@samp{Frename,@var{oldpathptr}/@var{len},@var{newpathptr}/@var{len}}
0ce1b118 43398
fc320d37 43399@item Return value:
0ce1b118
CV
43400On success, zero is returned. On error, -1 is returned.
43401
fc320d37 43402@item Errors:
0ce1b118
CV
43403
43404@table @code
b383017d 43405@item EISDIR
fc320d37 43406@var{newpath} is an existing directory, but @var{oldpath} is not a
0ce1b118
CV
43407directory.
43408
b383017d 43409@item EEXIST
fc320d37 43410@var{newpath} is a non-empty directory.
0ce1b118 43411
b383017d 43412@item EBUSY
fc320d37 43413@var{oldpath} or @var{newpath} is a directory that is in use by some
0ce1b118
CV
43414process.
43415
b383017d 43416@item EINVAL
0ce1b118
CV
43417An attempt was made to make a directory a subdirectory
43418of itself.
43419
b383017d 43420@item ENOTDIR
fc320d37
SL
43421A component used as a directory in @var{oldpath} or new
43422path is not a directory. Or @var{oldpath} is a directory
43423and @var{newpath} exists but is not a directory.
0ce1b118 43424
b383017d 43425@item EFAULT
fc320d37 43426@var{oldpathptr} or @var{newpathptr} are invalid pointer values.
0ce1b118 43427
b383017d 43428@item EACCES
0ce1b118
CV
43429No access to the file or the path of the file.
43430
43431@item ENAMETOOLONG
b383017d 43432
fc320d37 43433@var{oldpath} or @var{newpath} was too long.
0ce1b118 43434
b383017d 43435@item ENOENT
fc320d37 43436A directory component in @var{oldpath} or @var{newpath} does not exist.
0ce1b118 43437
b383017d 43438@item EROFS
0ce1b118
CV
43439The file is on a read-only filesystem.
43440
b383017d 43441@item ENOSPC
0ce1b118
CV
43442The device containing the file has no room for the new
43443directory entry.
43444
b383017d 43445@item EINTR
0ce1b118
CV
43446The call was interrupted by the user.
43447@end table
43448
fc320d37
SL
43449@end table
43450
0ce1b118
CV
43451@node unlink
43452@unnumberedsubsubsec unlink
43453@cindex unlink, file-i/o system call
43454
fc320d37
SL
43455@table @asis
43456@item Synopsis:
0ce1b118 43457@smallexample
0ce1b118 43458int unlink(const char *pathname);
fc320d37 43459@end smallexample
0ce1b118 43460
fc320d37
SL
43461@item Request:
43462@samp{Funlink,@var{pathnameptr}/@var{len}}
0ce1b118 43463
fc320d37 43464@item Return value:
0ce1b118
CV
43465On success, zero is returned. On error, -1 is returned.
43466
fc320d37 43467@item Errors:
0ce1b118
CV
43468
43469@table @code
b383017d 43470@item EACCES
0ce1b118
CV
43471No access to the file or the path of the file.
43472
b383017d 43473@item EPERM
0ce1b118
CV
43474The system does not allow unlinking of directories.
43475
b383017d 43476@item EBUSY
fc320d37 43477The file @var{pathname} cannot be unlinked because it's
0ce1b118
CV
43478being used by another process.
43479
b383017d 43480@item EFAULT
fc320d37 43481@var{pathnameptr} is an invalid pointer value.
0ce1b118
CV
43482
43483@item ENAMETOOLONG
fc320d37 43484@var{pathname} was too long.
0ce1b118 43485
b383017d 43486@item ENOENT
fc320d37 43487A directory component in @var{pathname} does not exist.
0ce1b118 43488
b383017d 43489@item ENOTDIR
0ce1b118
CV
43490A component of the path is not a directory.
43491
b383017d 43492@item EROFS
0ce1b118
CV
43493The file is on a read-only filesystem.
43494
b383017d 43495@item EINTR
0ce1b118
CV
43496The call was interrupted by the user.
43497@end table
43498
fc320d37
SL
43499@end table
43500
0ce1b118
CV
43501@node stat/fstat
43502@unnumberedsubsubsec stat/fstat
43503@cindex fstat, file-i/o system call
43504@cindex stat, file-i/o system call
43505
fc320d37
SL
43506@table @asis
43507@item Synopsis:
0ce1b118 43508@smallexample
0ce1b118
CV
43509int stat(const char *pathname, struct stat *buf);
43510int fstat(int fd, struct stat *buf);
fc320d37 43511@end smallexample
0ce1b118 43512
fc320d37
SL
43513@item Request:
43514@samp{Fstat,@var{pathnameptr}/@var{len},@var{bufptr}}@*
43515@samp{Ffstat,@var{fd},@var{bufptr}}
0ce1b118 43516
fc320d37 43517@item Return value:
0ce1b118
CV
43518On success, zero is returned. On error, -1 is returned.
43519
fc320d37 43520@item Errors:
0ce1b118
CV
43521
43522@table @code
b383017d 43523@item EBADF
fc320d37 43524@var{fd} is not a valid open file.
0ce1b118 43525
b383017d 43526@item ENOENT
fc320d37 43527A directory component in @var{pathname} does not exist or the
0ce1b118
CV
43528path is an empty string.
43529
b383017d 43530@item ENOTDIR
0ce1b118
CV
43531A component of the path is not a directory.
43532
b383017d 43533@item EFAULT
fc320d37 43534@var{pathnameptr} is an invalid pointer value.
0ce1b118 43535
b383017d 43536@item EACCES
0ce1b118
CV
43537No access to the file or the path of the file.
43538
43539@item ENAMETOOLONG
fc320d37 43540@var{pathname} was too long.
0ce1b118 43541
b383017d 43542@item EINTR
0ce1b118
CV
43543The call was interrupted by the user.
43544@end table
43545
fc320d37
SL
43546@end table
43547
0ce1b118
CV
43548@node gettimeofday
43549@unnumberedsubsubsec gettimeofday
43550@cindex gettimeofday, file-i/o system call
43551
fc320d37
SL
43552@table @asis
43553@item Synopsis:
0ce1b118 43554@smallexample
0ce1b118 43555int gettimeofday(struct timeval *tv, void *tz);
fc320d37 43556@end smallexample
0ce1b118 43557
fc320d37
SL
43558@item Request:
43559@samp{Fgettimeofday,@var{tvptr},@var{tzptr}}
0ce1b118 43560
fc320d37 43561@item Return value:
0ce1b118
CV
43562On success, 0 is returned, -1 otherwise.
43563
fc320d37 43564@item Errors:
0ce1b118
CV
43565
43566@table @code
b383017d 43567@item EINVAL
fc320d37 43568@var{tz} is a non-NULL pointer.
0ce1b118 43569
b383017d 43570@item EFAULT
fc320d37
SL
43571@var{tvptr} and/or @var{tzptr} is an invalid pointer value.
43572@end table
43573
0ce1b118
CV
43574@end table
43575
43576@node isatty
43577@unnumberedsubsubsec isatty
43578@cindex isatty, file-i/o system call
43579
fc320d37
SL
43580@table @asis
43581@item Synopsis:
0ce1b118 43582@smallexample
0ce1b118 43583int isatty(int fd);
fc320d37 43584@end smallexample
0ce1b118 43585
fc320d37
SL
43586@item Request:
43587@samp{Fisatty,@var{fd}}
0ce1b118 43588
fc320d37
SL
43589@item Return value:
43590Returns 1 if @var{fd} refers to the @value{GDBN} console, 0 otherwise.
0ce1b118 43591
fc320d37 43592@item Errors:
0ce1b118
CV
43593
43594@table @code
b383017d 43595@item EINTR
0ce1b118
CV
43596The call was interrupted by the user.
43597@end table
43598
fc320d37
SL
43599@end table
43600
43601Note that the @code{isatty} call is treated as a special case: it returns
436021 to the target if the file descriptor is attached
43603to the @value{GDBN} console, 0 otherwise. Implementing through system calls
43604would require implementing @code{ioctl} and would be more complex than
43605needed.
43606
43607
0ce1b118
CV
43608@node system
43609@unnumberedsubsubsec system
43610@cindex system, file-i/o system call
43611
fc320d37
SL
43612@table @asis
43613@item Synopsis:
0ce1b118 43614@smallexample
0ce1b118 43615int system(const char *command);
fc320d37 43616@end smallexample
0ce1b118 43617
fc320d37
SL
43618@item Request:
43619@samp{Fsystem,@var{commandptr}/@var{len}}
0ce1b118 43620
fc320d37 43621@item Return value:
5600ea19
NS
43622If @var{len} is zero, the return value indicates whether a shell is
43623available. A zero return value indicates a shell is not available.
43624For non-zero @var{len}, the value returned is -1 on error and the
43625return status of the command otherwise. Only the exit status of the
43626command is returned, which is extracted from the host's @code{system}
43627return value by calling @code{WEXITSTATUS(retval)}. In case
43628@file{/bin/sh} could not be executed, 127 is returned.
0ce1b118 43629
fc320d37 43630@item Errors:
0ce1b118
CV
43631
43632@table @code
b383017d 43633@item EINTR
0ce1b118
CV
43634The call was interrupted by the user.
43635@end table
43636
fc320d37
SL
43637@end table
43638
43639@value{GDBN} takes over the full task of calling the necessary host calls
43640to perform the @code{system} call. The return value of @code{system} on
43641the host is simplified before it's returned
43642to the target. Any termination signal information from the child process
43643is discarded, and the return value consists
43644entirely of the exit status of the called command.
43645
43646Due to security concerns, the @code{system} call is by default refused
43647by @value{GDBN}. The user has to allow this call explicitly with the
43648@code{set remote system-call-allowed 1} command.
43649
43650@table @code
43651@item set remote system-call-allowed
43652@kindex set remote system-call-allowed
43653Control whether to allow the @code{system} calls in the File I/O
43654protocol for the remote target. The default is zero (disabled).
43655
43656@item show remote system-call-allowed
43657@kindex show remote system-call-allowed
43658Show whether the @code{system} calls are allowed in the File I/O
43659protocol.
43660@end table
43661
db2e3e2e
BW
43662@node Protocol-specific Representation of Datatypes
43663@subsection Protocol-specific Representation of Datatypes
43664@cindex protocol-specific representation of datatypes, in file-i/o protocol
0ce1b118
CV
43665
43666@menu
79a6e687
BW
43667* Integral Datatypes::
43668* Pointer Values::
43669* Memory Transfer::
0ce1b118
CV
43670* struct stat::
43671* struct timeval::
43672@end menu
43673
79a6e687
BW
43674@node Integral Datatypes
43675@unnumberedsubsubsec Integral Datatypes
0ce1b118
CV
43676@cindex integral datatypes, in file-i/o protocol
43677
fc320d37
SL
43678The integral datatypes used in the system calls are @code{int},
43679@code{unsigned int}, @code{long}, @code{unsigned long},
43680@code{mode_t}, and @code{time_t}.
0ce1b118 43681
fc320d37 43682@code{int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
0ce1b118
CV
43683implemented as 32 bit values in this protocol.
43684
fc320d37 43685@code{long} and @code{unsigned long} are implemented as 64 bit types.
b383017d 43686
0ce1b118
CV
43687@xref{Limits}, for corresponding MIN and MAX values (similar to those
43688in @file{limits.h}) to allow range checking on host and target.
43689
43690@code{time_t} datatypes are defined as seconds since the Epoch.
43691
43692All integral datatypes transferred as part of a memory read or write of a
43693structured datatype e.g.@: a @code{struct stat} have to be given in big endian
43694byte order.
43695
79a6e687
BW
43696@node Pointer Values
43697@unnumberedsubsubsec Pointer Values
0ce1b118
CV
43698@cindex pointer values, in file-i/o protocol
43699
43700Pointers to target data are transmitted as they are. An exception
43701is made for pointers to buffers for which the length isn't
43702transmitted as part of the function call, namely strings. Strings
43703are transmitted as a pointer/length pair, both as hex values, e.g.@:
43704
43705@smallexample
43706@code{1aaf/12}
43707@end smallexample
43708
43709@noindent
43710which is a pointer to data of length 18 bytes at position 0x1aaf.
43711The length is defined as the full string length in bytes, including
fc320d37
SL
43712the trailing null byte. For example, the string @code{"hello world"}
43713at address 0x123456 is transmitted as
0ce1b118
CV
43714
43715@smallexample
fc320d37 43716@code{123456/d}
0ce1b118
CV
43717@end smallexample
43718
79a6e687
BW
43719@node Memory Transfer
43720@unnumberedsubsubsec Memory Transfer
fc320d37
SL
43721@cindex memory transfer, in file-i/o protocol
43722
43723Structured data which is transferred using a memory read or write (for
db2e3e2e 43724example, a @code{struct stat}) is expected to be in a protocol-specific format
fc320d37
SL
43725with all scalar multibyte datatypes being big endian. Translation to
43726this representation needs to be done both by the target before the @code{F}
43727packet is sent, and by @value{GDBN} before
43728it transfers memory to the target. Transferred pointers to structured
43729data should point to the already-coerced data at any time.
0ce1b118 43730
0ce1b118
CV
43731
43732@node struct stat
43733@unnumberedsubsubsec struct stat
43734@cindex struct stat, in file-i/o protocol
43735
fc320d37
SL
43736The buffer of type @code{struct stat} used by the target and @value{GDBN}
43737is defined as follows:
0ce1b118
CV
43738
43739@smallexample
43740struct stat @{
43741 unsigned int st_dev; /* device */
43742 unsigned int st_ino; /* inode */
43743 mode_t st_mode; /* protection */
43744 unsigned int st_nlink; /* number of hard links */
43745 unsigned int st_uid; /* user ID of owner */
43746 unsigned int st_gid; /* group ID of owner */
43747 unsigned int st_rdev; /* device type (if inode device) */
43748 unsigned long st_size; /* total size, in bytes */
43749 unsigned long st_blksize; /* blocksize for filesystem I/O */
43750 unsigned long st_blocks; /* number of blocks allocated */
43751 time_t st_atime; /* time of last access */
43752 time_t st_mtime; /* time of last modification */
43753 time_t st_ctime; /* time of last change */
43754@};
43755@end smallexample
43756
fc320d37 43757The integral datatypes conform to the definitions given in the
79a6e687 43758appropriate section (see @ref{Integral Datatypes}, for details) so this
0ce1b118
CV
43759structure is of size 64 bytes.
43760
43761The values of several fields have a restricted meaning and/or
43762range of values.
43763
fc320d37 43764@table @code
0ce1b118 43765
fc320d37
SL
43766@item st_dev
43767A value of 0 represents a file, 1 the console.
0ce1b118 43768
fc320d37
SL
43769@item st_ino
43770No valid meaning for the target. Transmitted unchanged.
0ce1b118 43771
fc320d37
SL
43772@item st_mode
43773Valid mode bits are described in @ref{Constants}. Any other
43774bits have currently no meaning for the target.
0ce1b118 43775
fc320d37
SL
43776@item st_uid
43777@itemx st_gid
43778@itemx st_rdev
43779No valid meaning for the target. Transmitted unchanged.
0ce1b118 43780
fc320d37
SL
43781@item st_atime
43782@itemx st_mtime
43783@itemx st_ctime
43784These values have a host and file system dependent
43785accuracy. Especially on Windows hosts, the file system may not
43786support exact timing values.
43787@end table
0ce1b118 43788
fc320d37
SL
43789The target gets a @code{struct stat} of the above representation and is
43790responsible for coercing it to the target representation before
0ce1b118
CV
43791continuing.
43792
fc320d37
SL
43793Note that due to size differences between the host, target, and protocol
43794representations of @code{struct stat} members, these members could eventually
0ce1b118
CV
43795get truncated on the target.
43796
43797@node struct timeval
43798@unnumberedsubsubsec struct timeval
43799@cindex struct timeval, in file-i/o protocol
43800
fc320d37 43801The buffer of type @code{struct timeval} used by the File-I/O protocol
0ce1b118
CV
43802is defined as follows:
43803
43804@smallexample
b383017d 43805struct timeval @{
0ce1b118
CV
43806 time_t tv_sec; /* second */
43807 long tv_usec; /* microsecond */
43808@};
43809@end smallexample
43810
fc320d37 43811The integral datatypes conform to the definitions given in the
79a6e687 43812appropriate section (see @ref{Integral Datatypes}, for details) so this
0ce1b118
CV
43813structure is of size 8 bytes.
43814
43815@node Constants
43816@subsection Constants
43817@cindex constants, in file-i/o protocol
43818
43819The following values are used for the constants inside of the
fc320d37 43820protocol. @value{GDBN} and target are responsible for translating these
0ce1b118
CV
43821values before and after the call as needed.
43822
43823@menu
79a6e687
BW
43824* Open Flags::
43825* mode_t Values::
43826* Errno Values::
43827* Lseek Flags::
0ce1b118
CV
43828* Limits::
43829@end menu
43830
79a6e687
BW
43831@node Open Flags
43832@unnumberedsubsubsec Open Flags
0ce1b118
CV
43833@cindex open flags, in file-i/o protocol
43834
43835All values are given in hexadecimal representation.
43836
43837@smallexample
43838 O_RDONLY 0x0
43839 O_WRONLY 0x1
43840 O_RDWR 0x2
43841 O_APPEND 0x8
43842 O_CREAT 0x200
43843 O_TRUNC 0x400
43844 O_EXCL 0x800
43845@end smallexample
43846
79a6e687
BW
43847@node mode_t Values
43848@unnumberedsubsubsec mode_t Values
0ce1b118
CV
43849@cindex mode_t values, in file-i/o protocol
43850
43851All values are given in octal representation.
43852
43853@smallexample
43854 S_IFREG 0100000
43855 S_IFDIR 040000
43856 S_IRUSR 0400
43857 S_IWUSR 0200
43858 S_IXUSR 0100
43859 S_IRGRP 040
43860 S_IWGRP 020
43861 S_IXGRP 010
43862 S_IROTH 04
43863 S_IWOTH 02
43864 S_IXOTH 01
43865@end smallexample
43866
79a6e687
BW
43867@node Errno Values
43868@unnumberedsubsubsec Errno Values
0ce1b118
CV
43869@cindex errno values, in file-i/o protocol
43870
43871All values are given in decimal representation.
43872
43873@smallexample
43874 EPERM 1
43875 ENOENT 2
43876 EINTR 4
43877 EBADF 9
43878 EACCES 13
43879 EFAULT 14
43880 EBUSY 16
43881 EEXIST 17
43882 ENODEV 19
43883 ENOTDIR 20
43884 EISDIR 21
43885 EINVAL 22
43886 ENFILE 23
43887 EMFILE 24
43888 EFBIG 27
43889 ENOSPC 28
43890 ESPIPE 29
43891 EROFS 30
43892 ENAMETOOLONG 91
43893 EUNKNOWN 9999
43894@end smallexample
43895
fc320d37 43896 @code{EUNKNOWN} is used as a fallback error value if a host system returns
0ce1b118
CV
43897 any error value not in the list of supported error numbers.
43898
79a6e687
BW
43899@node Lseek Flags
43900@unnumberedsubsubsec Lseek Flags
0ce1b118
CV
43901@cindex lseek flags, in file-i/o protocol
43902
43903@smallexample
43904 SEEK_SET 0
43905 SEEK_CUR 1
43906 SEEK_END 2
43907@end smallexample
43908
43909@node Limits
43910@unnumberedsubsubsec Limits
43911@cindex limits, in file-i/o protocol
43912
43913All values are given in decimal representation.
43914
43915@smallexample
43916 INT_MIN -2147483648
43917 INT_MAX 2147483647
43918 UINT_MAX 4294967295
43919 LONG_MIN -9223372036854775808
43920 LONG_MAX 9223372036854775807
43921 ULONG_MAX 18446744073709551615
43922@end smallexample
43923
43924@node File-I/O Examples
43925@subsection File-I/O Examples
43926@cindex file-i/o examples
43927
43928Example sequence of a write call, file descriptor 3, buffer is at target
43929address 0x1234, 6 bytes should be written:
43930
43931@smallexample
43932<- @code{Fwrite,3,1234,6}
43933@emph{request memory read from target}
43934-> @code{m1234,6}
43935<- XXXXXX
43936@emph{return "6 bytes written"}
43937-> @code{F6}
43938@end smallexample
43939
43940Example sequence of a read call, file descriptor 3, buffer is at target
43941address 0x1234, 6 bytes should be read:
43942
43943@smallexample
43944<- @code{Fread,3,1234,6}
43945@emph{request memory write to target}
43946-> @code{X1234,6:XXXXXX}
43947@emph{return "6 bytes read"}
43948-> @code{F6}
43949@end smallexample
43950
43951Example sequence of a read call, call fails on the host due to invalid
fc320d37 43952file descriptor (@code{EBADF}):
0ce1b118
CV
43953
43954@smallexample
43955<- @code{Fread,3,1234,6}
43956-> @code{F-1,9}
43957@end smallexample
43958
c8aa23ab 43959Example sequence of a read call, user presses @kbd{Ctrl-c} before syscall on
0ce1b118
CV
43960host is called:
43961
43962@smallexample
43963<- @code{Fread,3,1234,6}
43964-> @code{F-1,4,C}
43965<- @code{T02}
43966@end smallexample
43967
c8aa23ab 43968Example sequence of a read call, user presses @kbd{Ctrl-c} after syscall on
0ce1b118
CV
43969host is called:
43970
43971@smallexample
43972<- @code{Fread,3,1234,6}
43973-> @code{X1234,6:XXXXXX}
43974<- @code{T02}
43975@end smallexample
43976
cfa9d6d9
DJ
43977@node Library List Format
43978@section Library List Format
43979@cindex library list format, remote protocol
43980
43981On some platforms, a dynamic loader (e.g.@: @file{ld.so}) runs in the
43982same process as your application to manage libraries. In this case,
43983@value{GDBN} can use the loader's symbol table and normal memory
43984operations to maintain a list of shared libraries. On other
43985platforms, the operating system manages loaded libraries.
43986@value{GDBN} can not retrieve the list of currently loaded libraries
43987through memory operations, so it uses the @samp{qXfer:libraries:read}
43988packet (@pxref{qXfer library list read}) instead. The remote stub
43989queries the target's operating system and reports which libraries
43990are loaded.
43991
43992The @samp{qXfer:libraries:read} packet returns an XML document which
43993lists loaded libraries and their offsets. Each library has an
1fddbabb
PA
43994associated name and one or more segment or section base addresses,
43995which report where the library was loaded in memory.
43996
43997For the common case of libraries that are fully linked binaries, the
43998library should have a list of segments. If the target supports
43999dynamic linking of a relocatable object file, its library XML element
44000should instead include a list of allocated sections. The segment or
44001section bases are start addresses, not relocation offsets; they do not
44002depend on the library's link-time base addresses.
cfa9d6d9 44003
9cceb671
DJ
44004@value{GDBN} must be linked with the Expat library to support XML
44005library lists. @xref{Expat}.
44006
cfa9d6d9
DJ
44007A simple memory map, with one loaded library relocated by a single
44008offset, looks like this:
44009
44010@smallexample
44011<library-list>
44012 <library name="/lib/libc.so.6">
44013 <segment address="0x10000000"/>
44014 </library>
44015</library-list>
44016@end smallexample
44017
1fddbabb
PA
44018Another simple memory map, with one loaded library with three
44019allocated sections (.text, .data, .bss), looks like this:
44020
44021@smallexample
44022<library-list>
44023 <library name="sharedlib.o">
44024 <section address="0x10000000"/>
44025 <section address="0x20000000"/>
44026 <section address="0x30000000"/>
44027 </library>
44028</library-list>
44029@end smallexample
44030
cfa9d6d9
DJ
44031The format of a library list is described by this DTD:
44032
44033@smallexample
44034<!-- library-list: Root element with versioning -->
44035<!ELEMENT library-list (library)*>
44036<!ATTLIST library-list version CDATA #FIXED "1.0">
1fddbabb 44037<!ELEMENT library (segment*, section*)>
cfa9d6d9
DJ
44038<!ATTLIST library name CDATA #REQUIRED>
44039<!ELEMENT segment EMPTY>
44040<!ATTLIST segment address CDATA #REQUIRED>
1fddbabb
PA
44041<!ELEMENT section EMPTY>
44042<!ATTLIST section address CDATA #REQUIRED>
cfa9d6d9
DJ
44043@end smallexample
44044
1fddbabb
PA
44045In addition, segments and section descriptors cannot be mixed within a
44046single library element, and you must supply at least one segment or
44047section for each library.
44048
2268b414
JK
44049@node Library List Format for SVR4 Targets
44050@section Library List Format for SVR4 Targets
44051@cindex library list format, remote protocol
44052
44053On SVR4 platforms @value{GDBN} can use the symbol table of a dynamic loader
44054(e.g.@: @file{ld.so}) and normal memory operations to maintain a list of
44055shared libraries. Still a special library list provided by this packet is
44056more efficient for the @value{GDBN} remote protocol.
44057
44058The @samp{qXfer:libraries-svr4:read} packet returns an XML document which lists
44059loaded libraries and their SVR4 linker parameters. For each library on SVR4
44060target, the following parameters are reported:
44061
44062@itemize @minus
44063@item
44064@code{name}, the absolute file name from the @code{l_name} field of
44065@code{struct link_map}.
44066@item
44067@code{lm} with address of @code{struct link_map} used for TLS
44068(Thread Local Storage) access.
44069@item
44070@code{l_addr}, the displacement as read from the field @code{l_addr} of
44071@code{struct link_map}. For prelinked libraries this is not an absolute
44072memory address. It is a displacement of absolute memory address against
44073address the file was prelinked to during the library load.
44074@item
44075@code{l_ld}, which is memory address of the @code{PT_DYNAMIC} segment
44076@end itemize
44077
44078Additionally the single @code{main-lm} attribute specifies address of
44079@code{struct link_map} used for the main executable. This parameter is used
44080for TLS access and its presence is optional.
44081
44082@value{GDBN} must be linked with the Expat library to support XML
44083SVR4 library lists. @xref{Expat}.
44084
44085A simple memory map, with two loaded libraries (which do not use prelink),
44086looks like this:
44087
44088@smallexample
44089<library-list-svr4 version="1.0" main-lm="0xe4f8f8">
44090 <library name="/lib/ld-linux.so.2" lm="0xe4f51c" l_addr="0xe2d000"
44091 l_ld="0xe4eefc"/>
44092 <library name="/lib/libc.so.6" lm="0xe4fbe8" l_addr="0x154000"
db1ff28b 44093 l_ld="0x152350"/>
2268b414
JK
44094</library-list-svr>
44095@end smallexample
44096
44097The format of an SVR4 library list is described by this DTD:
44098
44099@smallexample
44100<!-- library-list-svr4: Root element with versioning -->
44101<!ELEMENT library-list-svr4 (library)*>
db1ff28b
JK
44102<!ATTLIST library-list-svr4 version CDATA #FIXED "1.0">
44103<!ATTLIST library-list-svr4 main-lm CDATA #IMPLIED>
2268b414 44104<!ELEMENT library EMPTY>
db1ff28b
JK
44105<!ATTLIST library name CDATA #REQUIRED>
44106<!ATTLIST library lm CDATA #REQUIRED>
44107<!ATTLIST library l_addr CDATA #REQUIRED>
44108<!ATTLIST library l_ld CDATA #REQUIRED>
2268b414
JK
44109@end smallexample
44110
79a6e687
BW
44111@node Memory Map Format
44112@section Memory Map Format
68437a39
DJ
44113@cindex memory map format
44114
44115To be able to write into flash memory, @value{GDBN} needs to obtain a
44116memory map from the target. This section describes the format of the
44117memory map.
44118
44119The memory map is obtained using the @samp{qXfer:memory-map:read}
44120(@pxref{qXfer memory map read}) packet and is an XML document that
9cceb671
DJ
44121lists memory regions.
44122
44123@value{GDBN} must be linked with the Expat library to support XML
44124memory maps. @xref{Expat}.
44125
44126The top-level structure of the document is shown below:
68437a39
DJ
44127
44128@smallexample
44129<?xml version="1.0"?>
44130<!DOCTYPE memory-map
44131 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
44132 "http://sourceware.org/gdb/gdb-memory-map.dtd">
44133<memory-map>
44134 region...
44135</memory-map>
44136@end smallexample
44137
44138Each region can be either:
44139
44140@itemize
44141
44142@item
44143A region of RAM starting at @var{addr} and extending for @var{length}
44144bytes from there:
44145
44146@smallexample
44147<memory type="ram" start="@var{addr}" length="@var{length}"/>
44148@end smallexample
44149
44150
44151@item
44152A region of read-only memory:
44153
44154@smallexample
44155<memory type="rom" start="@var{addr}" length="@var{length}"/>
44156@end smallexample
44157
44158
44159@item
44160A region of flash memory, with erasure blocks @var{blocksize}
44161bytes in length:
44162
44163@smallexample
44164<memory type="flash" start="@var{addr}" length="@var{length}">
44165 <property name="blocksize">@var{blocksize}</property>
44166</memory>
44167@end smallexample
44168
44169@end itemize
44170
44171Regions must not overlap. @value{GDBN} assumes that areas of memory not covered
44172by the memory map are RAM, and uses the ordinary @samp{M} and @samp{X}
44173packets to write to addresses in such ranges.
44174
44175The formal DTD for memory map format is given below:
44176
44177@smallexample
44178<!-- ................................................... -->
44179<!-- Memory Map XML DTD ................................ -->
44180<!-- File: memory-map.dtd .............................. -->
44181<!-- .................................... .............. -->
44182<!-- memory-map.dtd -->
44183<!-- memory-map: Root element with versioning -->
5f1ca24a 44184<!ELEMENT memory-map (memory)*>
68437a39 44185<!ATTLIST memory-map version CDATA #FIXED "1.0.0">
5f1ca24a 44186<!ELEMENT memory (property)*>
68437a39
DJ
44187<!-- memory: Specifies a memory region,
44188 and its type, or device. -->
5f1ca24a 44189<!ATTLIST memory type (ram|rom|flash) #REQUIRED
68437a39 44190 start CDATA #REQUIRED
5f1ca24a 44191 length CDATA #REQUIRED>
68437a39
DJ
44192<!-- property: Generic attribute tag -->
44193<!ELEMENT property (#PCDATA | property)*>
5f1ca24a 44194<!ATTLIST property name (blocksize) #REQUIRED>
68437a39
DJ
44195@end smallexample
44196
dc146f7c
VP
44197@node Thread List Format
44198@section Thread List Format
44199@cindex thread list format
44200
44201To efficiently update the list of threads and their attributes,
44202@value{GDBN} issues the @samp{qXfer:threads:read} packet
44203(@pxref{qXfer threads read}) and obtains the XML document with
44204the following structure:
44205
44206@smallexample
44207<?xml version="1.0"?>
44208<threads>
79efa585 44209 <thread id="id" core="0" name="name">
dc146f7c
VP
44210 ... description ...
44211 </thread>
44212</threads>
44213@end smallexample
44214
44215Each @samp{thread} element must have the @samp{id} attribute that
44216identifies the thread (@pxref{thread-id syntax}). The
44217@samp{core} attribute, if present, specifies which processor core
79efa585
SM
44218the thread was last executing on. The @samp{name} attribute, if
44219present, specifies the human-readable name of the thread. The content
44220of the of @samp{thread} element is interpreted as human-readable
f2ff95c5
KB
44221auxiliary information. The @samp{handle} attribute, if present,
44222is a hex encoded representation of the thread handle.
44223
dc146f7c 44224
b3b9301e
PA
44225@node Traceframe Info Format
44226@section Traceframe Info Format
44227@cindex traceframe info format
44228
44229To be able to know which objects in the inferior can be examined when
44230inspecting a tracepoint hit, @value{GDBN} needs to obtain the list of
44231memory ranges, registers and trace state variables that have been
44232collected in a traceframe.
44233
44234This list is obtained using the @samp{qXfer:traceframe-info:read}
44235(@pxref{qXfer traceframe info read}) packet and is an XML document.
44236
44237@value{GDBN} must be linked with the Expat library to support XML
44238traceframe info discovery. @xref{Expat}.
44239
44240The top-level structure of the document is shown below:
44241
44242@smallexample
44243<?xml version="1.0"?>
44244<!DOCTYPE traceframe-info
44245 PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
44246 "http://sourceware.org/gdb/gdb-traceframe-info.dtd">
44247<traceframe-info>
44248 block...
44249</traceframe-info>
44250@end smallexample
44251
44252Each traceframe block can be either:
44253
44254@itemize
44255
44256@item
44257A region of collected memory starting at @var{addr} and extending for
44258@var{length} bytes from there:
44259
44260@smallexample
44261<memory start="@var{addr}" length="@var{length}"/>
44262@end smallexample
44263
28a93511
YQ
44264@item
44265A block indicating trace state variable numbered @var{number} has been
44266collected:
44267
44268@smallexample
44269<tvar id="@var{number}"/>
44270@end smallexample
44271
b3b9301e
PA
44272@end itemize
44273
44274The formal DTD for the traceframe info format is given below:
44275
44276@smallexample
28a93511 44277<!ELEMENT traceframe-info (memory | tvar)* >
b3b9301e
PA
44278<!ATTLIST traceframe-info version CDATA #FIXED "1.0">
44279
44280<!ELEMENT memory EMPTY>
44281<!ATTLIST memory start CDATA #REQUIRED
44282 length CDATA #REQUIRED>
28a93511
YQ
44283<!ELEMENT tvar>
44284<!ATTLIST tvar id CDATA #REQUIRED>
b3b9301e
PA
44285@end smallexample
44286
2ae8c8e7
MM
44287@node Branch Trace Format
44288@section Branch Trace Format
44289@cindex branch trace format
44290
44291In order to display the branch trace of an inferior thread,
44292@value{GDBN} needs to obtain the list of branches. This list is
44293represented as list of sequential code blocks that are connected via
44294branches. The code in each block has been executed sequentially.
44295
44296This list is obtained using the @samp{qXfer:btrace:read}
44297(@pxref{qXfer btrace read}) packet and is an XML document.
44298
44299@value{GDBN} must be linked with the Expat library to support XML
44300traceframe info discovery. @xref{Expat}.
44301
44302The top-level structure of the document is shown below:
44303
44304@smallexample
44305<?xml version="1.0"?>
44306<!DOCTYPE btrace
44307 PUBLIC "+//IDN gnu.org//DTD GDB Branch Trace V1.0//EN"
44308 "http://sourceware.org/gdb/gdb-btrace.dtd">
44309<btrace>
44310 block...
44311</btrace>
44312@end smallexample
44313
44314@itemize
44315
44316@item
44317A block of sequentially executed instructions starting at @var{begin}
44318and ending at @var{end}:
44319
44320@smallexample
44321<block begin="@var{begin}" end="@var{end}"/>
44322@end smallexample
44323
44324@end itemize
44325
44326The formal DTD for the branch trace format is given below:
44327
44328@smallexample
b20a6524 44329<!ELEMENT btrace (block* | pt) >
2ae8c8e7
MM
44330<!ATTLIST btrace version CDATA #FIXED "1.0">
44331
44332<!ELEMENT block EMPTY>
44333<!ATTLIST block begin CDATA #REQUIRED
44334 end CDATA #REQUIRED>
b20a6524
MM
44335
44336<!ELEMENT pt (pt-config?, raw?)>
44337
44338<!ELEMENT pt-config (cpu?)>
44339
44340<!ELEMENT cpu EMPTY>
44341<!ATTLIST cpu vendor CDATA #REQUIRED
44342 family CDATA #REQUIRED
44343 model CDATA #REQUIRED
44344 stepping CDATA #REQUIRED>
44345
44346<!ELEMENT raw (#PCDATA)>
2ae8c8e7
MM
44347@end smallexample
44348
f4abbc16
MM
44349@node Branch Trace Configuration Format
44350@section Branch Trace Configuration Format
44351@cindex branch trace configuration format
44352
44353For each inferior thread, @value{GDBN} can obtain the branch trace
44354configuration using the @samp{qXfer:btrace-conf:read}
44355(@pxref{qXfer btrace-conf read}) packet.
44356
44357The configuration describes the branch trace format and configuration
d33501a5
MM
44358settings for that format. The following information is described:
44359
44360@table @code
44361@item bts
44362This thread uses the @dfn{Branch Trace Store} (@acronym{BTS}) format.
44363@table @code
44364@item size
44365The size of the @acronym{BTS} ring buffer in bytes.
44366@end table
b20a6524 44367@item pt
bc504a31 44368This thread uses the @dfn{Intel Processor Trace} (@acronym{Intel
b20a6524
MM
44369PT}) format.
44370@table @code
44371@item size
bc504a31 44372The size of the @acronym{Intel PT} ring buffer in bytes.
b20a6524 44373@end table
d33501a5 44374@end table
f4abbc16
MM
44375
44376@value{GDBN} must be linked with the Expat library to support XML
44377branch trace configuration discovery. @xref{Expat}.
44378
44379The formal DTD for the branch trace configuration format is given below:
44380
44381@smallexample
b20a6524 44382<!ELEMENT btrace-conf (bts?, pt?)>
f4abbc16
MM
44383<!ATTLIST btrace-conf version CDATA #FIXED "1.0">
44384
44385<!ELEMENT bts EMPTY>
d33501a5 44386<!ATTLIST bts size CDATA #IMPLIED>
b20a6524
MM
44387
44388<!ELEMENT pt EMPTY>
44389<!ATTLIST pt size CDATA #IMPLIED>
f4abbc16
MM
44390@end smallexample
44391
f418dd93
DJ
44392@include agentexpr.texi
44393
23181151
DJ
44394@node Target Descriptions
44395@appendix Target Descriptions
44396@cindex target descriptions
44397
23181151
DJ
44398One of the challenges of using @value{GDBN} to debug embedded systems
44399is that there are so many minor variants of each processor
44400architecture in use. It is common practice for vendors to start with
eb17f351 44401a standard processor core --- ARM, PowerPC, or @acronym{MIPS}, for example ---
23181151
DJ
44402and then make changes to adapt it to a particular market niche. Some
44403architectures have hundreds of variants, available from dozens of
44404vendors. This leads to a number of problems:
44405
44406@itemize @bullet
44407@item
44408With so many different customized processors, it is difficult for
44409the @value{GDBN} maintainers to keep up with the changes.
44410@item
44411Since individual variants may have short lifetimes or limited
44412audiences, it may not be worthwhile to carry information about every
44413variant in the @value{GDBN} source tree.
44414@item
44415When @value{GDBN} does support the architecture of the embedded system
44416at hand, the task of finding the correct architecture name to give the
44417@command{set architecture} command can be error-prone.
44418@end itemize
44419
44420To address these problems, the @value{GDBN} remote protocol allows a
44421target system to not only identify itself to @value{GDBN}, but to
44422actually describe its own features. This lets @value{GDBN} support
44423processor variants it has never seen before --- to the extent that the
44424descriptions are accurate, and that @value{GDBN} understands them.
44425
9cceb671
DJ
44426@value{GDBN} must be linked with the Expat library to support XML
44427target descriptions. @xref{Expat}.
123dc839 44428
23181151
DJ
44429@menu
44430* Retrieving Descriptions:: How descriptions are fetched from a target.
44431* Target Description Format:: The contents of a target description.
123dc839
DJ
44432* Predefined Target Types:: Standard types available for target
44433 descriptions.
81516450 44434* Enum Target Types:: How to define enum target types.
123dc839 44435* Standard Target Features:: Features @value{GDBN} knows about.
23181151
DJ
44436@end menu
44437
44438@node Retrieving Descriptions
44439@section Retrieving Descriptions
44440
44441Target descriptions can be read from the target automatically, or
44442specified by the user manually. The default behavior is to read the
44443description from the target. @value{GDBN} retrieves it via the remote
44444protocol using @samp{qXfer} requests (@pxref{General Query Packets,
44445qXfer}). The @var{annex} in the @samp{qXfer} packet will be
44446@samp{target.xml}. The contents of the @samp{target.xml} annex are an
44447XML document, of the form described in @ref{Target Description
44448Format}.
44449
44450Alternatively, you can specify a file to read for the target description.
44451If a file is set, the target will not be queried. The commands to
44452specify a file are:
44453
44454@table @code
44455@cindex set tdesc filename
44456@item set tdesc filename @var{path}
44457Read the target description from @var{path}.
44458
44459@cindex unset tdesc filename
44460@item unset tdesc filename
44461Do not read the XML target description from a file. @value{GDBN}
44462will use the description supplied by the current target.
44463
44464@cindex show tdesc filename
44465@item show tdesc filename
44466Show the filename to read for a target description, if any.
44467@end table
44468
44469
44470@node Target Description Format
44471@section Target Description Format
44472@cindex target descriptions, XML format
44473
44474A target description annex is an @uref{http://www.w3.org/XML/, XML}
44475document which complies with the Document Type Definition provided in
44476the @value{GDBN} sources in @file{gdb/features/gdb-target.dtd}. This
44477means you can use generally available tools like @command{xmllint} to
44478check that your feature descriptions are well-formed and valid.
44479However, to help people unfamiliar with XML write descriptions for
44480their targets, we also describe the grammar here.
44481
123dc839
DJ
44482Target descriptions can identify the architecture of the remote target
44483and (for some architectures) provide information about custom register
08d16641
PA
44484sets. They can also identify the OS ABI of the remote target.
44485@value{GDBN} can use this information to autoconfigure for your
123dc839 44486target, or to warn you if you connect to an unsupported target.
23181151
DJ
44487
44488Here is a simple target description:
44489
123dc839 44490@smallexample
1780a0ed 44491<target version="1.0">
23181151
DJ
44492 <architecture>i386:x86-64</architecture>
44493</target>
123dc839 44494@end smallexample
23181151
DJ
44495
44496@noindent
44497This minimal description only says that the target uses
44498the x86-64 architecture.
44499
123dc839
DJ
44500A target description has the following overall form, with [ ] marking
44501optional elements and @dots{} marking repeatable elements. The elements
44502are explained further below.
23181151 44503
123dc839 44504@smallexample
23181151
DJ
44505<?xml version="1.0"?>
44506<!DOCTYPE target SYSTEM "gdb-target.dtd">
1780a0ed 44507<target version="1.0">
123dc839 44508 @r{[}@var{architecture}@r{]}
08d16641 44509 @r{[}@var{osabi}@r{]}
e35359c5 44510 @r{[}@var{compatible}@r{]}
123dc839 44511 @r{[}@var{feature}@dots{}@r{]}
23181151 44512</target>
123dc839 44513@end smallexample
23181151
DJ
44514
44515@noindent
44516The description is generally insensitive to whitespace and line
44517breaks, under the usual common-sense rules. The XML version
44518declaration and document type declaration can generally be omitted
44519(@value{GDBN} does not require them), but specifying them may be
1780a0ed
DJ
44520useful for XML validation tools. The @samp{version} attribute for
44521@samp{<target>} may also be omitted, but we recommend
44522including it; if future versions of @value{GDBN} use an incompatible
44523revision of @file{gdb-target.dtd}, they will detect and report
44524the version mismatch.
23181151 44525
108546a0
DJ
44526@subsection Inclusion
44527@cindex target descriptions, inclusion
44528@cindex XInclude
44529@ifnotinfo
44530@cindex <xi:include>
44531@end ifnotinfo
44532
44533It can sometimes be valuable to split a target description up into
44534several different annexes, either for organizational purposes, or to
44535share files between different possible target descriptions. You can
44536divide a description into multiple files by replacing any element of
44537the target description with an inclusion directive of the form:
44538
123dc839 44539@smallexample
108546a0 44540<xi:include href="@var{document}"/>
123dc839 44541@end smallexample
108546a0
DJ
44542
44543@noindent
44544When @value{GDBN} encounters an element of this form, it will retrieve
44545the named XML @var{document}, and replace the inclusion directive with
44546the contents of that document. If the current description was read
44547using @samp{qXfer}, then so will be the included document;
44548@var{document} will be interpreted as the name of an annex. If the
44549current description was read from a file, @value{GDBN} will look for
44550@var{document} as a file in the same directory where it found the
44551original description.
44552
123dc839
DJ
44553@subsection Architecture
44554@cindex <architecture>
44555
44556An @samp{<architecture>} element has this form:
44557
44558@smallexample
44559 <architecture>@var{arch}</architecture>
44560@end smallexample
44561
e35359c5
UW
44562@var{arch} is one of the architectures from the set accepted by
44563@code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
123dc839 44564
08d16641
PA
44565@subsection OS ABI
44566@cindex @code{<osabi>}
44567
44568This optional field was introduced in @value{GDBN} version 7.0.
44569Previous versions of @value{GDBN} ignore it.
44570
44571An @samp{<osabi>} element has this form:
44572
44573@smallexample
44574 <osabi>@var{abi-name}</osabi>
44575@end smallexample
44576
44577@var{abi-name} is an OS ABI name from the same selection accepted by
44578@w{@code{set osabi}} (@pxref{ABI, ,Configuring the Current ABI}).
44579
e35359c5
UW
44580@subsection Compatible Architecture
44581@cindex @code{<compatible>}
44582
44583This optional field was introduced in @value{GDBN} version 7.0.
44584Previous versions of @value{GDBN} ignore it.
44585
44586A @samp{<compatible>} element has this form:
44587
44588@smallexample
44589 <compatible>@var{arch}</compatible>
44590@end smallexample
44591
44592@var{arch} is one of the architectures from the set accepted by
44593@code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
44594
44595A @samp{<compatible>} element is used to specify that the target
44596is able to run binaries in some other than the main target architecture
44597given by the @samp{<architecture>} element. For example, on the
44598Cell Broadband Engine, the main architecture is @code{powerpc:common}
44599or @code{powerpc:common64}, but the system is able to run binaries
44600in the @code{spu} architecture as well. The way to describe this
44601capability with @samp{<compatible>} is as follows:
44602
44603@smallexample
44604 <architecture>powerpc:common</architecture>
44605 <compatible>spu</compatible>
44606@end smallexample
44607
123dc839
DJ
44608@subsection Features
44609@cindex <feature>
44610
44611Each @samp{<feature>} describes some logical portion of the target
44612system. Features are currently used to describe available CPU
44613registers and the types of their contents. A @samp{<feature>} element
44614has this form:
44615
44616@smallexample
44617<feature name="@var{name}">
44618 @r{[}@var{type}@dots{}@r{]}
44619 @var{reg}@dots{}
44620</feature>
44621@end smallexample
44622
44623@noindent
44624Each feature's name should be unique within the description. The name
44625of a feature does not matter unless @value{GDBN} has some special
44626knowledge of the contents of that feature; if it does, the feature
44627should have its standard name. @xref{Standard Target Features}.
44628
44629@subsection Types
44630
44631Any register's value is a collection of bits which @value{GDBN} must
44632interpret. The default interpretation is a two's complement integer,
44633but other types can be requested by name in the register description.
44634Some predefined types are provided by @value{GDBN} (@pxref{Predefined
81516450
DE
44635Target Types}), and the description can define additional composite
44636and enum types.
123dc839
DJ
44637
44638Each type element must have an @samp{id} attribute, which gives
44639a unique (within the containing @samp{<feature>}) name to the type.
44640Types must be defined before they are used.
44641
44642@cindex <vector>
44643Some targets offer vector registers, which can be treated as arrays
44644of scalar elements. These types are written as @samp{<vector>} elements,
44645specifying the array element type, @var{type}, and the number of elements,
44646@var{count}:
44647
44648@smallexample
44649<vector id="@var{id}" type="@var{type}" count="@var{count}"/>
44650@end smallexample
44651
44652@cindex <union>
44653If a register's value is usefully viewed in multiple ways, define it
44654with a union type containing the useful representations. The
44655@samp{<union>} element contains one or more @samp{<field>} elements,
44656each of which has a @var{name} and a @var{type}:
44657
44658@smallexample
44659<union id="@var{id}">
44660 <field name="@var{name}" type="@var{type}"/>
44661 @dots{}
44662</union>
44663@end smallexample
44664
f5dff777 44665@cindex <struct>
81516450 44666@cindex <flags>
f5dff777 44667If a register's value is composed from several separate values, define
81516450
DE
44668it with either a structure type or a flags type.
44669A flags type may only contain bitfields.
44670A structure type may either contain only bitfields or contain no bitfields.
44671If the value contains only bitfields, its total size in bytes must be
44672specified.
44673
44674Non-bitfield values have a @var{name} and @var{type}.
f5dff777
DJ
44675
44676@smallexample
81516450
DE
44677<struct id="@var{id}">
44678 <field name="@var{name}" type="@var{type}"/>
f5dff777
DJ
44679 @dots{}
44680</struct>
44681@end smallexample
44682
81516450
DE
44683Both @var{name} and @var{type} values are required.
44684No implicit padding is added.
44685
44686Bitfield values have a @var{name}, @var{start}, @var{end} and @var{type}.
f5dff777
DJ
44687
44688@smallexample
81516450
DE
44689<struct id="@var{id}" size="@var{size}">
44690 <field name="@var{name}" start="@var{start}" end="@var{end}" type="@var{type}"/>
f5dff777
DJ
44691 @dots{}
44692</struct>
44693@end smallexample
44694
f5dff777
DJ
44695@smallexample
44696<flags id="@var{id}" size="@var{size}">
81516450 44697 <field name="@var{name}" start="@var{start}" end="@var{end}" type="@var{type}"/>
f5dff777
DJ
44698 @dots{}
44699</flags>
44700@end smallexample
44701
81516450
DE
44702The @var{name} value is required.
44703Bitfield values may be named with the empty string, @samp{""},
44704in which case the field is ``filler'' and its value is not printed.
44705Not all bits need to be specified, so ``filler'' fields are optional.
44706
ee8da4b8
DE
44707The @var{start} and @var{end} values are required, and @var{type}
44708is optional.
81516450
DE
44709The field's @var{start} must be less than or equal to its @var{end},
44710and zero represents the least significant bit.
81516450 44711
ee8da4b8
DE
44712The default value of @var{type} is @code{bool} for single bit fields,
44713and an unsigned integer otherwise.
81516450
DE
44714
44715Which to choose? Structures or flags?
44716
44717Registers defined with @samp{flags} have these advantages over
44718defining them with @samp{struct}:
44719
44720@itemize @bullet
44721@item
44722Arithmetic may be performed on them as if they were integers.
44723@item
44724They are printed in a more readable fashion.
44725@end itemize
44726
44727Registers defined with @samp{struct} have one advantage over
44728defining them with @samp{flags}:
44729
44730@itemize @bullet
44731@item
44732One can fetch individual fields like in @samp{C}.
44733
44734@smallexample
44735(gdb) print $my_struct_reg.field3
44736$1 = 42
44737@end smallexample
44738
44739@end itemize
44740
123dc839
DJ
44741@subsection Registers
44742@cindex <reg>
44743
44744Each register is represented as an element with this form:
44745
44746@smallexample
44747<reg name="@var{name}"
44748 bitsize="@var{size}"
44749 @r{[}regnum="@var{num}"@r{]}
44750 @r{[}save-restore="@var{save-restore}"@r{]}
44751 @r{[}type="@var{type}"@r{]}
44752 @r{[}group="@var{group}"@r{]}/>
44753@end smallexample
44754
44755@noindent
44756The components are as follows:
44757
44758@table @var
44759
44760@item name
44761The register's name; it must be unique within the target description.
44762
44763@item bitsize
44764The register's size, in bits.
44765
44766@item regnum
44767The register's number. If omitted, a register's number is one greater
44768than that of the previous register (either in the current feature or in
177b42fe 44769a preceding feature); the first register in the target description
123dc839
DJ
44770defaults to zero. This register number is used to read or write
44771the register; e.g.@: it is used in the remote @code{p} and @code{P}
44772packets, and registers appear in the @code{g} and @code{G} packets
44773in order of increasing register number.
44774
44775@item save-restore
44776Whether the register should be preserved across inferior function
44777calls; this must be either @code{yes} or @code{no}. The default is
44778@code{yes}, which is appropriate for most registers except for
44779some system control registers; this is not related to the target's
44780ABI.
44781
44782@item type
697aa1b7 44783The type of the register. It may be a predefined type, a type
123dc839
DJ
44784defined in the current feature, or one of the special types @code{int}
44785and @code{float}. @code{int} is an integer type of the correct size
44786for @var{bitsize}, and @code{float} is a floating point type (in the
44787architecture's normal floating point format) of the correct size for
44788@var{bitsize}. The default is @code{int}.
44789
44790@item group
cef0f868
SH
44791The register group to which this register belongs. It can be one of the
44792standard register groups @code{general}, @code{float}, @code{vector} or an
44793arbitrary string. Group names should be limited to alphanumeric characters.
44794If a group name is made up of multiple words the words may be separated by
44795hyphens; e.g.@: @code{special-group} or @code{ultra-special-group}. If no
44796@var{group} is specified, @value{GDBN} will not display the register in
44797@code{info registers}.
123dc839
DJ
44798
44799@end table
44800
44801@node Predefined Target Types
44802@section Predefined Target Types
44803@cindex target descriptions, predefined types
44804
44805Type definitions in the self-description can build up composite types
44806from basic building blocks, but can not define fundamental types. Instead,
44807standard identifiers are provided by @value{GDBN} for the fundamental
44808types. The currently supported types are:
44809
44810@table @code
44811
81516450
DE
44812@item bool
44813Boolean type, occupying a single bit.
44814
123dc839
DJ
44815@item int8
44816@itemx int16
d1908f2d 44817@itemx int24
123dc839
DJ
44818@itemx int32
44819@itemx int64
7cc46491 44820@itemx int128
123dc839
DJ
44821Signed integer types holding the specified number of bits.
44822
44823@item uint8
44824@itemx uint16
d1908f2d 44825@itemx uint24
123dc839
DJ
44826@itemx uint32
44827@itemx uint64
7cc46491 44828@itemx uint128
123dc839
DJ
44829Unsigned integer types holding the specified number of bits.
44830
44831@item code_ptr
44832@itemx data_ptr
44833Pointers to unspecified code and data. The program counter and
44834any dedicated return address register may be marked as code
44835pointers; printing a code pointer converts it into a symbolic
44836address. The stack pointer and any dedicated address registers
44837may be marked as data pointers.
44838
6e3bbd1a
PB
44839@item ieee_single
44840Single precision IEEE floating point.
44841
44842@item ieee_double
44843Double precision IEEE floating point.
44844
123dc839
DJ
44845@item arm_fpa_ext
44846The 12-byte extended precision format used by ARM FPA registers.
44847
075b51b7
L
44848@item i387_ext
44849The 10-byte extended precision format used by x87 registers.
44850
44851@item i386_eflags
4485232bit @sc{eflags} register used by x86.
44853
44854@item i386_mxcsr
4485532bit @sc{mxcsr} register used by x86.
44856
123dc839
DJ
44857@end table
44858
81516450
DE
44859@node Enum Target Types
44860@section Enum Target Types
44861@cindex target descriptions, enum types
44862
44863Enum target types are useful in @samp{struct} and @samp{flags}
44864register descriptions. @xref{Target Description Format}.
44865
44866Enum types have a name, size and a list of name/value pairs.
44867
44868@smallexample
44869<enum id="@var{id}" size="@var{size}">
44870 <evalue name="@var{name}" value="@var{value}"/>
44871 @dots{}
44872</enum>
44873@end smallexample
44874
44875Enums must be defined before they are used.
44876
44877@smallexample
44878<enum id="levels_type" size="4">
44879 <evalue name="low" value="0"/>
44880 <evalue name="high" value="1"/>
44881</enum>
44882<flags id="flags_type" size="4">
44883 <field name="X" start="0"/>
44884 <field name="LEVEL" start="1" end="1" type="levels_type"/>
44885</flags>
44886<reg name="flags" bitsize="32" type="flags_type"/>
44887@end smallexample
44888
44889Given that description, a value of 3 for the @samp{flags} register
44890would be printed as:
44891
44892@smallexample
44893(gdb) info register flags
44894flags 0x3 [ X LEVEL=high ]
44895@end smallexample
44896
123dc839
DJ
44897@node Standard Target Features
44898@section Standard Target Features
44899@cindex target descriptions, standard features
44900
44901A target description must contain either no registers or all the
44902target's registers. If the description contains no registers, then
44903@value{GDBN} will assume a default register layout, selected based on
44904the architecture. If the description contains any registers, the
44905default layout will not be used; the standard registers must be
44906described in the target description, in such a way that @value{GDBN}
44907can recognize them.
44908
44909This is accomplished by giving specific names to feature elements
44910which contain standard registers. @value{GDBN} will look for features
44911with those names and verify that they contain the expected registers;
44912if any known feature is missing required registers, or if any required
44913feature is missing, @value{GDBN} will reject the target
44914description. You can add additional registers to any of the
44915standard features --- @value{GDBN} will display them just as if
44916they were added to an unrecognized feature.
44917
44918This section lists the known features and their expected contents.
44919Sample XML documents for these features are included in the
44920@value{GDBN} source tree, in the directory @file{gdb/features}.
44921
44922Names recognized by @value{GDBN} should include the name of the
44923company or organization which selected the name, and the overall
44924architecture to which the feature applies; so e.g.@: the feature
44925containing ARM core registers is named @samp{org.gnu.gdb.arm.core}.
44926
ff6f572f
DJ
44927The names of registers are not case sensitive for the purpose
44928of recognizing standard features, but @value{GDBN} will only display
44929registers using the capitalization used in the description.
44930
e9c17194 44931@menu
430ed3f0 44932* AArch64 Features::
ad0a504f 44933* ARC Features::
e9c17194 44934* ARM Features::
3bb8d5c3 44935* i386 Features::
164224e9 44936* MicroBlaze Features::
1e26b4f8 44937* MIPS Features::
e9c17194 44938* M68K Features::
a28d8e50 44939* NDS32 Features::
a1217d97 44940* Nios II Features::
a994fec4 44941* OpenRISC 1000 Features::
1e26b4f8 44942* PowerPC Features::
b5ffee31 44943* RISC-V Features::
e3ec872f 44944* RX Features::
4ac33720 44945* S/390 and System z Features::
3f7b46f2 44946* Sparc Features::
224bbe49 44947* TIC6x Features::
e9c17194
VP
44948@end menu
44949
44950
430ed3f0
MS
44951@node AArch64 Features
44952@subsection AArch64 Features
44953@cindex target descriptions, AArch64 features
44954
44955The @samp{org.gnu.gdb.aarch64.core} feature is required for AArch64
44956targets. It should contain registers @samp{x0} through @samp{x30},
44957@samp{sp}, @samp{pc}, and @samp{cpsr}.
44958
44959The @samp{org.gnu.gdb.aarch64.fpu} feature is optional. If present,
44960it should contain registers @samp{v0} through @samp{v31}, @samp{fpsr},
44961and @samp{fpcr}.
44962
95228a0d
AH
44963The @samp{org.gnu.gdb.aarch64.sve} feature is optional. If present,
44964it should contain registers @samp{z0} through @samp{z31}, @samp{p0}
44965through @samp{p15}, @samp{ffr} and @samp{vg}.
44966
6dc0ebde
AH
44967The @samp{org.gnu.gdb.aarch64.pauth} feature is optional. If present,
44968it should contain registers @samp{pauth_dmask} and @samp{pauth_cmask}.
44969
ad0a504f
AK
44970@node ARC Features
44971@subsection ARC Features
44972@cindex target descriptions, ARC Features
44973
44974ARC processors are highly configurable, so even core registers and their number
44975are not completely predetermined. In addition flags and PC registers which are
44976important to @value{GDBN} are not ``core'' registers in ARC. It is required
44977that one of the core registers features is present.
44978@samp{org.gnu.gdb.arc.aux-minimal} feature is mandatory.
44979
44980The @samp{org.gnu.gdb.arc.core.v2} feature is required for ARC EM and ARC HS
44981targets with a normal register file. It should contain registers @samp{r0}
44982through @samp{r25}, @samp{gp}, @samp{fp}, @samp{sp}, @samp{r30}, @samp{blink},
44983@samp{lp_count} and @samp{pcl}. This feature may contain register @samp{ilink}
44984and any of extension core registers @samp{r32} through @samp{r59/acch}.
44985@samp{ilink} and extension core registers are not available to read/write, when
44986debugging GNU/Linux applications, thus @samp{ilink} is made optional.
44987
44988The @samp{org.gnu.gdb.arc.core-reduced.v2} feature is required for ARC EM and
44989ARC HS targets with a reduced register file. It should contain registers
44990@samp{r0} through @samp{r3}, @samp{r10} through @samp{r15}, @samp{gp},
44991@samp{fp}, @samp{sp}, @samp{r30}, @samp{blink}, @samp{lp_count} and @samp{pcl}.
44992This feature may contain register @samp{ilink} and any of extension core
44993registers @samp{r32} through @samp{r59/acch}.
44994
44995The @samp{org.gnu.gdb.arc.core.arcompact} feature is required for ARCompact
44996targets with a normal register file. It should contain registers @samp{r0}
44997through @samp{r25}, @samp{gp}, @samp{fp}, @samp{sp}, @samp{r30}, @samp{blink},
44998@samp{lp_count} and @samp{pcl}. This feature may contain registers
44999@samp{ilink1}, @samp{ilink2} and any of extension core registers @samp{r32}
45000through @samp{r59/acch}. @samp{ilink1} and @samp{ilink2} and extension core
45001registers are not available when debugging GNU/Linux applications. The only
45002difference with @samp{org.gnu.gdb.arc.core.v2} feature is in the names of
45003@samp{ilink1} and @samp{ilink2} registers and that @samp{r30} is mandatory in
45004ARC v2, but @samp{ilink2} is optional on ARCompact.
45005
45006The @samp{org.gnu.gdb.arc.aux-minimal} feature is required for all ARC
45007targets. It should contain registers @samp{pc} and @samp{status32}.
45008
e9c17194 45009@node ARM Features
123dc839
DJ
45010@subsection ARM Features
45011@cindex target descriptions, ARM features
45012
9779414d
DJ
45013The @samp{org.gnu.gdb.arm.core} feature is required for non-M-profile
45014ARM targets.
123dc839
DJ
45015It should contain registers @samp{r0} through @samp{r13}, @samp{sp},
45016@samp{lr}, @samp{pc}, and @samp{cpsr}.
45017
9779414d
DJ
45018For M-profile targets (e.g. Cortex-M3), the @samp{org.gnu.gdb.arm.core}
45019feature is replaced by @samp{org.gnu.gdb.arm.m-profile}. It should contain
45020registers @samp{r0} through @samp{r13}, @samp{sp}, @samp{lr}, @samp{pc},
45021and @samp{xpsr}.
45022
123dc839
DJ
45023The @samp{org.gnu.gdb.arm.fpa} feature is optional. If present, it
45024should contain registers @samp{f0} through @samp{f7} and @samp{fps}.
45025
ff6f572f
DJ
45026The @samp{org.gnu.gdb.xscale.iwmmxt} feature is optional. If present,
45027it should contain at least registers @samp{wR0} through @samp{wR15} and
45028@samp{wCGR0} through @samp{wCGR3}. The @samp{wCID}, @samp{wCon},
45029@samp{wCSSF}, and @samp{wCASF} registers are optional.
23181151 45030
58d6951d
DJ
45031The @samp{org.gnu.gdb.arm.vfp} feature is optional. If present, it
45032should contain at least registers @samp{d0} through @samp{d15}. If
45033they are present, @samp{d16} through @samp{d31} should also be included.
45034@value{GDBN} will synthesize the single-precision registers from
45035halves of the double-precision registers.
45036
45037The @samp{org.gnu.gdb.arm.neon} feature is optional. It does not
45038need to contain registers; it instructs @value{GDBN} to display the
45039VFP double-precision registers as vectors and to synthesize the
45040quad-precision registers from pairs of double-precision registers.
45041If this feature is present, @samp{org.gnu.gdb.arm.vfp} must also
45042be present and include 32 double-precision registers.
45043
3bb8d5c3
L
45044@node i386 Features
45045@subsection i386 Features
45046@cindex target descriptions, i386 features
45047
45048The @samp{org.gnu.gdb.i386.core} feature is required for i386/amd64
45049targets. It should describe the following registers:
45050
45051@itemize @minus
45052@item
45053@samp{eax} through @samp{edi} plus @samp{eip} for i386
45054@item
45055@samp{rax} through @samp{r15} plus @samp{rip} for amd64
45056@item
45057@samp{eflags}, @samp{cs}, @samp{ss}, @samp{ds}, @samp{es},
45058@samp{fs}, @samp{gs}
45059@item
45060@samp{st0} through @samp{st7}
45061@item
45062@samp{fctrl}, @samp{fstat}, @samp{ftag}, @samp{fiseg}, @samp{fioff},
45063@samp{foseg}, @samp{fooff} and @samp{fop}
45064@end itemize
45065
45066The register sets may be different, depending on the target.
45067
3a13a53b 45068The @samp{org.gnu.gdb.i386.sse} feature is optional. It should
3bb8d5c3
L
45069describe registers:
45070
45071@itemize @minus
45072@item
45073@samp{xmm0} through @samp{xmm7} for i386
45074@item
45075@samp{xmm0} through @samp{xmm15} for amd64
45076@item
45077@samp{mxcsr}
45078@end itemize
45079
3a13a53b
L
45080The @samp{org.gnu.gdb.i386.avx} feature is optional and requires the
45081@samp{org.gnu.gdb.i386.sse} feature. It should
f68eb612
L
45082describe the upper 128 bits of @sc{ymm} registers:
45083
45084@itemize @minus
45085@item
45086@samp{ymm0h} through @samp{ymm7h} for i386
45087@item
45088@samp{ymm0h} through @samp{ymm15h} for amd64
f68eb612
L
45089@end itemize
45090
bc504a31 45091The @samp{org.gnu.gdb.i386.mpx} is an optional feature representing Intel
ca8941bb
WT
45092Memory Protection Extension (MPX). It should describe the following registers:
45093
45094@itemize @minus
45095@item
45096@samp{bnd0raw} through @samp{bnd3raw} for i386 and amd64.
45097@item
45098@samp{bndcfgu} and @samp{bndstatus} for i386 and amd64.
45099@end itemize
45100
3bb8d5c3
L
45101The @samp{org.gnu.gdb.i386.linux} feature is optional. It should
45102describe a single register, @samp{orig_eax}.
45103
2735833d
WT
45104The @samp{org.gnu.gdb.i386.segments} feature is optional. It should
45105describe two system registers: @samp{fs_base} and @samp{gs_base}.
45106
01f9f808
MS
45107The @samp{org.gnu.gdb.i386.avx512} feature is optional and requires the
45108@samp{org.gnu.gdb.i386.avx} feature. It should
45109describe additional @sc{xmm} registers:
45110
45111@itemize @minus
45112@item
45113@samp{xmm16h} through @samp{xmm31h}, only valid for amd64.
45114@end itemize
45115
45116It should describe the upper 128 bits of additional @sc{ymm} registers:
45117
45118@itemize @minus
45119@item
45120@samp{ymm16h} through @samp{ymm31h}, only valid for amd64.
45121@end itemize
45122
45123It should
45124describe the upper 256 bits of @sc{zmm} registers:
45125
45126@itemize @minus
45127@item
45128@samp{zmm0h} through @samp{zmm7h} for i386.
45129@item
45130@samp{zmm0h} through @samp{zmm15h} for amd64.
45131@end itemize
45132
45133It should
45134describe the additional @sc{zmm} registers:
45135
45136@itemize @minus
45137@item
45138@samp{zmm16h} through @samp{zmm31h}, only valid for amd64.
45139@end itemize
45140
51547df6
MS
45141The @samp{org.gnu.gdb.i386.pkeys} feature is optional. It should
45142describe a single register, @samp{pkru}. It is a 32-bit register
45143valid for i386 and amd64.
45144
164224e9
ME
45145@node MicroBlaze Features
45146@subsection MicroBlaze Features
45147@cindex target descriptions, MicroBlaze features
45148
45149The @samp{org.gnu.gdb.microblaze.core} feature is required for MicroBlaze
45150targets. It should contain registers @samp{r0} through @samp{r31},
45151@samp{rpc}, @samp{rmsr}, @samp{rear}, @samp{resr}, @samp{rfsr}, @samp{rbtr},
45152@samp{rpvr}, @samp{rpvr1} through @samp{rpvr11}, @samp{redr}, @samp{rpid},
45153@samp{rzpr}, @samp{rtlbx}, @samp{rtlbsx}, @samp{rtlblo}, and @samp{rtlbhi}.
45154
45155The @samp{org.gnu.gdb.microblaze.stack-protect} feature is optional.
45156If present, it should contain registers @samp{rshr} and @samp{rslr}
45157
1e26b4f8 45158@node MIPS Features
eb17f351
EZ
45159@subsection @acronym{MIPS} Features
45160@cindex target descriptions, @acronym{MIPS} features
f8b73d13 45161
eb17f351 45162The @samp{org.gnu.gdb.mips.cpu} feature is required for @acronym{MIPS} targets.
f8b73d13
DJ
45163It should contain registers @samp{r0} through @samp{r31}, @samp{lo},
45164@samp{hi}, and @samp{pc}. They may be 32-bit or 64-bit depending
45165on the target.
45166
45167The @samp{org.gnu.gdb.mips.cp0} feature is also required. It should
45168contain at least the @samp{status}, @samp{badvaddr}, and @samp{cause}
45169registers. They may be 32-bit or 64-bit depending on the target.
45170
45171The @samp{org.gnu.gdb.mips.fpu} feature is currently required, though
45172it may be optional in a future version of @value{GDBN}. It should
45173contain registers @samp{f0} through @samp{f31}, @samp{fcsr}, and
45174@samp{fir}. They may be 32-bit or 64-bit depending on the target.
45175
1faeff08
MR
45176The @samp{org.gnu.gdb.mips.dsp} feature is optional. It should
45177contain registers @samp{hi1} through @samp{hi3}, @samp{lo1} through
45178@samp{lo3}, and @samp{dspctl}. The @samp{dspctl} register should
45179be 32-bit and the rest may be 32-bit or 64-bit depending on the target.
45180
822b6570
DJ
45181The @samp{org.gnu.gdb.mips.linux} feature is optional. It should
45182contain a single register, @samp{restart}, which is used by the
45183Linux kernel to control restartable syscalls.
45184
e9c17194
VP
45185@node M68K Features
45186@subsection M68K Features
45187@cindex target descriptions, M68K features
45188
45189@table @code
45190@item @samp{org.gnu.gdb.m68k.core}
45191@itemx @samp{org.gnu.gdb.coldfire.core}
45192@itemx @samp{org.gnu.gdb.fido.core}
45193One of those features must be always present.
249e1128 45194The feature that is present determines which flavor of m68k is
e9c17194
VP
45195used. The feature that is present should contain registers
45196@samp{d0} through @samp{d7}, @samp{a0} through @samp{a5}, @samp{fp},
45197@samp{sp}, @samp{ps} and @samp{pc}.
45198
45199@item @samp{org.gnu.gdb.coldfire.fp}
45200This feature is optional. If present, it should contain registers
45201@samp{fp0} through @samp{fp7}, @samp{fpcontrol}, @samp{fpstatus} and
45202@samp{fpiaddr}.
45203@end table
45204
a28d8e50
YTL
45205@node NDS32 Features
45206@subsection NDS32 Features
45207@cindex target descriptions, NDS32 features
45208
45209The @samp{org.gnu.gdb.nds32.core} feature is required for NDS32
45210targets. It should contain at least registers @samp{r0} through
45211@samp{r10}, @samp{r15}, @samp{fp}, @samp{gp}, @samp{lp}, @samp{sp},
45212and @samp{pc}.
45213
45214The @samp{org.gnu.gdb.nds32.fpu} feature is optional. If present,
45215it should contain 64-bit double-precision floating-point registers
45216@samp{fd0} through @emph{fdN}, which should be @samp{fd3}, @samp{fd7},
45217@samp{fd15}, or @samp{fd31} based on the FPU configuration implemented.
45218
45219@emph{Note:} The first sixteen 64-bit double-precision floating-point
45220registers are overlapped with the thirty-two 32-bit single-precision
45221floating-point registers. The 32-bit single-precision registers, if
45222not being listed explicitly, will be synthesized from halves of the
45223overlapping 64-bit double-precision registers. Listing 32-bit
45224single-precision registers explicitly is deprecated, and the
45225support to it could be totally removed some day.
45226
a1217d97
SL
45227@node Nios II Features
45228@subsection Nios II Features
45229@cindex target descriptions, Nios II features
45230
45231The @samp{org.gnu.gdb.nios2.cpu} feature is required for Nios II
45232targets. It should contain the 32 core registers (@samp{zero},
45233@samp{at}, @samp{r2} through @samp{r23}, @samp{et} through @samp{ra}),
45234@samp{pc}, and the 16 control registers (@samp{status} through
45235@samp{mpuacc}).
45236
a994fec4
FJ
45237@node OpenRISC 1000 Features
45238@subsection Openrisc 1000 Features
45239@cindex target descriptions, OpenRISC 1000 features
45240
45241The @samp{org.gnu.gdb.or1k.group0} feature is required for OpenRISC 1000
45242targets. It should contain the 32 general purpose registers (@samp{r0}
45243through @samp{r31}), @samp{ppc}, @samp{npc} and @samp{sr}.
45244
1e26b4f8 45245@node PowerPC Features
7cc46491
DJ
45246@subsection PowerPC Features
45247@cindex target descriptions, PowerPC features
45248
45249The @samp{org.gnu.gdb.power.core} feature is required for PowerPC
45250targets. It should contain registers @samp{r0} through @samp{r31},
45251@samp{pc}, @samp{msr}, @samp{cr}, @samp{lr}, @samp{ctr}, and
45252@samp{xer}. They may be 32-bit or 64-bit depending on the target.
45253
45254The @samp{org.gnu.gdb.power.fpu} feature is optional. It should
45255contain registers @samp{f0} through @samp{f31} and @samp{fpscr}.
45256
45257The @samp{org.gnu.gdb.power.altivec} feature is optional. It should
6f072a10
PFC
45258contain registers @samp{vr0} through @samp{vr31}, @samp{vscr}, and
45259@samp{vrsave}. @value{GDBN} will define pseudo-registers @samp{v0}
45260through @samp{v31} as aliases for the corresponding @samp{vrX}
45261registers.
7cc46491 45262
677c5bb1 45263The @samp{org.gnu.gdb.power.vsx} feature is optional. It should
4b905ae1
PFC
45264contain registers @samp{vs0h} through @samp{vs31h}. @value{GDBN} will
45265combine these registers with the floating point registers (@samp{f0}
45266through @samp{f31}) and the altivec registers (@samp{vr0} through
45267@samp{vr31}) to present the 128-bit wide registers @samp{vs0} through
45268@samp{vs63}, the set of vector-scalar registers for POWER7.
45269Therefore, this feature requires both @samp{org.gnu.gdb.power.fpu} and
45270@samp{org.gnu.gdb.power.altivec}.
677c5bb1 45271
7cc46491
DJ
45272The @samp{org.gnu.gdb.power.spe} feature is optional. It should
45273contain registers @samp{ev0h} through @samp{ev31h}, @samp{acc}, and
45274@samp{spefscr}. SPE targets should provide 32-bit registers in
45275@samp{org.gnu.gdb.power.core} and provide the upper halves in
45276@samp{ev0h} through @samp{ev31h}. @value{GDBN} will combine
45277these to present registers @samp{ev0} through @samp{ev31} to the
45278user.
45279
7ca18ed6
EBM
45280The @samp{org.gnu.gdb.power.ppr} feature is optional. It should
45281contain the 64-bit register @samp{ppr}.
45282
45283The @samp{org.gnu.gdb.power.dscr} feature is optional. It should
45284contain the 64-bit register @samp{dscr}.
45285
f2cf6173
EBM
45286The @samp{org.gnu.gdb.power.tar} feature is optional. It should
45287contain the 64-bit register @samp{tar}.
45288
232bfb86
EBM
45289The @samp{org.gnu.gdb.power.ebb} feature is optional. It should
45290contain registers @samp{bescr}, @samp{ebbhr} and @samp{ebbrr}, all
4529164-bit wide.
45292
45293The @samp{org.gnu.gdb.power.linux.pmu} feature is optional. It should
45294contain registers @samp{mmcr0}, @samp{mmcr2}, @samp{siar}, @samp{sdar}
45295and @samp{sier}, all 64-bit wide. This is the subset of the isa 2.07
45296server PMU registers provided by @sc{gnu}/Linux.
45297
8d619c01
EBM
45298The @samp{org.gnu.gdb.power.htm.spr} feature is optional. It should
45299contain registers @samp{tfhar}, @samp{texasr} and @samp{tfiar}, all
4530064-bit wide.
45301
45302The @samp{org.gnu.gdb.power.htm.core} feature is optional. It should
45303contain the checkpointed general-purpose registers @samp{cr0} through
45304@samp{cr31}, as well as the checkpointed registers @samp{clr} and
45305@samp{cctr}. These registers may all be either 32-bit or 64-bit
45306depending on the target. It should also contain the checkpointed
45307registers @samp{ccr} and @samp{cxer}, which should both be 32-bit
45308wide.
45309
45310The @samp{org.gnu.gdb.power.htm.fpu} feature is optional. It should
45311contain the checkpointed 64-bit floating-point registers @samp{cf0}
45312through @samp{cf31}, as well as the checkpointed 64-bit register
45313@samp{cfpscr}.
45314
45315The @samp{org.gnu.gdb.power.htm.altivec} feature is optional. It
45316should contain the checkpointed altivec registers @samp{cvr0} through
45317@samp{cvr31}, all 128-bit wide. It should also contain the
45318checkpointed registers @samp{cvscr} and @samp{cvrsave}, both 32-bit
45319wide.
45320
45321The @samp{org.gnu.gdb.power.htm.vsx} feature is optional. It should
45322contain registers @samp{cvs0h} through @samp{cvs31h}. @value{GDBN}
45323will combine these registers with the checkpointed floating point
45324registers (@samp{cf0} through @samp{cf31}) and the checkpointed
45325altivec registers (@samp{cvr0} through @samp{cvr31}) to present the
45326128-bit wide checkpointed vector-scalar registers @samp{cvs0} through
45327@samp{cvs63}. Therefore, this feature requires both
45328@samp{org.gnu.gdb.power.htm.altivec} and
45329@samp{org.gnu.gdb.power.htm.fpu}.
45330
45331The @samp{org.gnu.gdb.power.htm.ppr} feature is optional. It should
45332contain the 64-bit checkpointed register @samp{cppr}.
45333
45334The @samp{org.gnu.gdb.power.htm.dscr} feature is optional. It should
45335contain the 64-bit checkpointed register @samp{cdscr}.
45336
45337The @samp{org.gnu.gdb.power.htm.tar} feature is optional. It should
45338contain the 64-bit checkpointed register @samp{ctar}.
45339
b5ffee31
AB
45340
45341@node RISC-V Features
45342@subsection RISC-V Features
45343@cindex target descriptions, RISC-V Features
45344
45345The @samp{org.gnu.gdb.riscv.cpu} feature is required for RISC-V
45346targets. It should contain the registers @samp{x0} through
45347@samp{x31}, and @samp{pc}. Either the architectural names (@samp{x0},
45348@samp{x1}, etc) can be used, or the ABI names (@samp{zero}, @samp{ra},
45349etc).
45350
45351The @samp{org.gnu.gdb.riscv.fpu} feature is optional. If present, it
45352should contain registers @samp{f0} through @samp{f31}, @samp{fflags},
45353@samp{frm}, and @samp{fcsr}. As with the cpu feature, either the
45354architectural register names, or the ABI names can be used.
45355
45356The @samp{org.gnu.gdb.riscv.virtual} feature is optional. If present,
45357it should contain registers that are not backed by real registers on
45358the target, but are instead virtual, where the register value is
45359derived from other target state. In many ways these are like
45360@value{GDBN}s pseudo-registers, except implemented by the target.
45361Currently the only register expected in this set is the one byte
45362@samp{priv} register that contains the target's privilege level in the
45363least significant two bits.
45364
45365The @samp{org.gnu.gdb.riscv.csr} feature is optional. If present, it
45366should contain all of the target's standard CSRs. Standard CSRs are
45367those defined in the RISC-V specification documents. There is some
45368overlap between this feature and the fpu feature; the @samp{fflags},
45369@samp{frm}, and @samp{fcsr} registers could be in either feature. The
45370expectation is that these registers will be in the fpu feature if the
45371target has floating point hardware, but can be moved into the csr
45372feature if the target has the floating point control registers, but no
45373other floating point hardware.
45374
e3ec872f
YS
45375@node RX Features
45376@subsection RX Features
45377@cindex target descriptions, RX Features
45378
45379The @samp{org.gnu.gdb.rx.core} feature is required for RX
45380targets. It should contain the registers @samp{r0} through
45381@samp{r15}, @samp{usp}, @samp{isp}, @samp{psw}, @samp{pc}, @samp{intb},
45382@samp{bpsw}, @samp{bpc}, @samp{fintv}, @samp{fpsw}, and @samp{acc}.
45383
4ac33720
UW
45384@node S/390 and System z Features
45385@subsection S/390 and System z Features
45386@cindex target descriptions, S/390 features
45387@cindex target descriptions, System z features
45388
45389The @samp{org.gnu.gdb.s390.core} feature is required for S/390 and
45390System z targets. It should contain the PSW and the 16 general
45391registers. In particular, System z targets should provide the 64-bit
45392registers @samp{pswm}, @samp{pswa}, and @samp{r0} through @samp{r15}.
45393S/390 targets should provide the 32-bit versions of these registers.
45394A System z target that runs in 31-bit addressing mode should provide
4539532-bit versions of @samp{pswm} and @samp{pswa}, as well as the general
45396register's upper halves @samp{r0h} through @samp{r15h}, and their
45397lower halves @samp{r0l} through @samp{r15l}.
45398
45399The @samp{org.gnu.gdb.s390.fpr} feature is required. It should
45400contain the 64-bit registers @samp{f0} through @samp{f15}, and
45401@samp{fpc}.
45402
45403The @samp{org.gnu.gdb.s390.acr} feature is required. It should
45404contain the 32-bit registers @samp{acr0} through @samp{acr15}.
45405
45406The @samp{org.gnu.gdb.s390.linux} feature is optional. It should
45407contain the register @samp{orig_r2}, which is 64-bit wide on System z
45408targets and 32-bit otherwise. In addition, the feature may contain
45409the @samp{last_break} register, whose width depends on the addressing
45410mode, as well as the @samp{system_call} register, which is always
4541132-bit wide.
45412
45413The @samp{org.gnu.gdb.s390.tdb} feature is optional. It should
45414contain the 64-bit registers @samp{tdb0}, @samp{tac}, @samp{tct},
45415@samp{atia}, and @samp{tr0} through @samp{tr15}.
45416
446899e4
AA
45417The @samp{org.gnu.gdb.s390.vx} feature is optional. It should contain
4541864-bit wide registers @samp{v0l} through @samp{v15l}, which will be
45419combined by @value{GDBN} with the floating point registers @samp{f0}
45420through @samp{f15} to present the 128-bit wide vector registers
45421@samp{v0} through @samp{v15}. In addition, this feature should
45422contain the 128-bit wide vector registers @samp{v16} through
45423@samp{v31}.
45424
289e23aa
AA
45425The @samp{org.gnu.gdb.s390.gs} feature is optional. It should contain
45426the 64-bit wide guarded-storage-control registers @samp{gsd},
45427@samp{gssm}, and @samp{gsepla}.
45428
45429The @samp{org.gnu.gdb.s390.gsbc} feature is optional. It should contain
45430the 64-bit wide guarded-storage broadcast control registers
45431@samp{bc_gsd}, @samp{bc_gssm}, and @samp{bc_gsepla}.
45432
3f7b46f2
IR
45433@node Sparc Features
45434@subsection Sparc Features
45435@cindex target descriptions, sparc32 features
45436@cindex target descriptions, sparc64 features
45437The @samp{org.gnu.gdb.sparc.cpu} feature is required for sparc32/sparc64
45438targets. It should describe the following registers:
45439
45440@itemize @minus
45441@item
45442@samp{g0} through @samp{g7}
45443@item
45444@samp{o0} through @samp{o7}
45445@item
45446@samp{l0} through @samp{l7}
45447@item
45448@samp{i0} through @samp{i7}
45449@end itemize
45450
45451They may be 32-bit or 64-bit depending on the target.
45452
45453Also the @samp{org.gnu.gdb.sparc.fpu} feature is required for sparc32/sparc64
45454targets. It should describe the following registers:
45455
45456@itemize @minus
45457@item
45458@samp{f0} through @samp{f31}
45459@item
45460@samp{f32} through @samp{f62} for sparc64
45461@end itemize
45462
45463The @samp{org.gnu.gdb.sparc.cp0} feature is required for sparc32/sparc64
45464targets. It should describe the following registers:
45465
45466@itemize @minus
45467@item
45468@samp{y}, @samp{psr}, @samp{wim}, @samp{tbr}, @samp{pc}, @samp{npc},
45469@samp{fsr}, and @samp{csr} for sparc32
45470@item
45471@samp{pc}, @samp{npc}, @samp{state}, @samp{fsr}, @samp{fprs}, and @samp{y}
45472for sparc64
45473@end itemize
45474
224bbe49
YQ
45475@node TIC6x Features
45476@subsection TMS320C6x Features
45477@cindex target descriptions, TIC6x features
45478@cindex target descriptions, TMS320C6x features
45479The @samp{org.gnu.gdb.tic6x.core} feature is required for TMS320C6x
45480targets. It should contain registers @samp{A0} through @samp{A15},
45481registers @samp{B0} through @samp{B15}, @samp{CSR} and @samp{PC}.
45482
45483The @samp{org.gnu.gdb.tic6x.gp} feature is optional. It should
45484contain registers @samp{A16} through @samp{A31} and @samp{B16}
45485through @samp{B31}.
45486
45487The @samp{org.gnu.gdb.tic6x.c6xp} feature is optional. It should
45488contain registers @samp{TSR}, @samp{ILC} and @samp{RILC}.
45489
07e059b5
VP
45490@node Operating System Information
45491@appendix Operating System Information
45492@cindex operating system information
45493
45494@menu
45495* Process list::
45496@end menu
45497
45498Users of @value{GDBN} often wish to obtain information about the state of
45499the operating system running on the target---for example the list of
45500processes, or the list of open files. This section describes the
45501mechanism that makes it possible. This mechanism is similar to the
45502target features mechanism (@pxref{Target Descriptions}), but focuses
45503on a different aspect of target.
45504
6b92c0d3 45505Operating system information is retrieved from the target via the
07e059b5
VP
45506remote protocol, using @samp{qXfer} requests (@pxref{qXfer osdata
45507read}). The object name in the request should be @samp{osdata}, and
45508the @var{annex} identifies the data to be fetched.
45509
45510@node Process list
45511@appendixsection Process list
45512@cindex operating system information, process list
45513
45514When requesting the process list, the @var{annex} field in the
45515@samp{qXfer} request should be @samp{processes}. The returned data is
45516an XML document. The formal syntax of this document is defined in
45517@file{gdb/features/osdata.dtd}.
45518
45519An example document is:
45520
45521@smallexample
45522<?xml version="1.0"?>
45523<!DOCTYPE target SYSTEM "osdata.dtd">
45524<osdata type="processes">
45525 <item>
45526 <column name="pid">1</column>
45527 <column name="user">root</column>
45528 <column name="command">/sbin/init</column>
dc146f7c 45529 <column name="cores">1,2,3</column>
07e059b5
VP
45530 </item>
45531</osdata>
45532@end smallexample
45533
45534Each item should include a column whose name is @samp{pid}. The value
45535of that column should identify the process on the target. The
45536@samp{user} and @samp{command} columns are optional, and will be
dc146f7c
VP
45537displayed by @value{GDBN}. The @samp{cores} column, if present,
45538should contain a comma-separated list of cores that this process
45539is running on. Target may provide additional columns,
07e059b5
VP
45540which @value{GDBN} currently ignores.
45541
05c8c3f5
TT
45542@node Trace File Format
45543@appendix Trace File Format
45544@cindex trace file format
45545
45546The trace file comes in three parts: a header, a textual description
45547section, and a trace frame section with binary data.
45548
45549The header has the form @code{\x7fTRACE0\n}. The first byte is
45550@code{0x7f} so as to indicate that the file contains binary data,
45551while the @code{0} is a version number that may have different values
45552in the future.
45553
45554The description section consists of multiple lines of @sc{ascii} text
45555separated by newline characters (@code{0xa}). The lines may include a
45556variety of optional descriptive or context-setting information, such
45557as tracepoint definitions or register set size. @value{GDBN} will
45558ignore any line that it does not recognize. An empty line marks the end
45559of this section.
45560
0748bf3e
MK
45561@table @code
45562@item R @var{size}
45563Specifies the size of a register block in bytes. This is equal to the
45564size of a @code{g} packet payload in the remote protocol. @var{size}
45565is an ascii decimal number. There should be only one such line in
45566a single trace file.
45567
45568@item status @var{status}
45569Trace status. @var{status} has the same format as a @code{qTStatus}
45570remote packet reply. There should be only one such line in a single trace
45571file.
45572
45573@item tp @var{payload}
45574Tracepoint definition. The @var{payload} has the same format as
45575@code{qTfP}/@code{qTsP} remote packet reply payload. A single tracepoint
45576may take multiple lines of definition, corresponding to the multiple
45577reply packets.
45578
45579@item tsv @var{payload}
45580Trace state variable definition. The @var{payload} has the same format as
45581@code{qTfV}/@code{qTsV} remote packet reply payload. A single variable
45582may take multiple lines of definition, corresponding to the multiple
45583reply packets.
45584
45585@item tdesc @var{payload}
45586Target description in XML format. The @var{payload} is a single line of
45587the XML file. All such lines should be concatenated together to get
45588the original XML file. This file is in the same format as @code{qXfer}
45589@code{features} payload, and corresponds to the main @code{target.xml}
45590file. Includes are not allowed.
45591
45592@end table
05c8c3f5
TT
45593
45594The trace frame section consists of a number of consecutive frames.
45595Each frame begins with a two-byte tracepoint number, followed by a
45596four-byte size giving the amount of data in the frame. The data in
45597the frame consists of a number of blocks, each introduced by a
45598character indicating its type (at least register, memory, and trace
45599state variable). The data in this section is raw binary, not a
45600hexadecimal or other encoding; its endianness matches the target's
45601endianness.
45602
45603@c FIXME bi-arch may require endianness/arch info in description section
45604
45605@table @code
45606@item R @var{bytes}
45607Register block. The number and ordering of bytes matches that of a
45608@code{g} packet in the remote protocol. Note that these are the
e909d859 45609actual bytes, in target order, not a hexadecimal encoding.
05c8c3f5
TT
45610
45611@item M @var{address} @var{length} @var{bytes}...
45612Memory block. This is a contiguous block of memory, at the 8-byte
45613address @var{address}, with a 2-byte length @var{length}, followed by
45614@var{length} bytes.
45615
45616@item V @var{number} @var{value}
45617Trace state variable block. This records the 8-byte signed value
45618@var{value} of trace state variable numbered @var{number}.
45619
45620@end table
45621
45622Future enhancements of the trace file format may include additional types
45623of blocks.
45624
90476074
TT
45625@node Index Section Format
45626@appendix @code{.gdb_index} section format
45627@cindex .gdb_index section format
45628@cindex index section format
45629
45630This section documents the index section that is created by @code{save
45631gdb-index} (@pxref{Index Files}). The index section is
45632DWARF-specific; some knowledge of DWARF is assumed in this
45633description.
45634
45635The mapped index file format is designed to be directly
45636@code{mmap}able on any architecture. In most cases, a datum is
45637represented using a little-endian 32-bit integer value, called an
45638@code{offset_type}. Big endian machines must byte-swap the values
45639before using them. Exceptions to this rule are noted. The data is
45640laid out such that alignment is always respected.
45641
45642A mapped index consists of several areas, laid out in order.
45643
45644@enumerate
45645@item
45646The file header. This is a sequence of values, of @code{offset_type}
45647unless otherwise noted:
45648
45649@enumerate
45650@item
796a7ff8 45651The version number, currently 8. Versions 1, 2 and 3 are obsolete.
481860b3 45652Version 4 uses a different hashing function from versions 5 and 6.
b6ba681c
TT
45653Version 6 includes symbols for inlined functions, whereas versions 4
45654and 5 do not. Version 7 adds attributes to the CU indices in the
796a7ff8
DE
45655symbol table. Version 8 specifies that symbols from DWARF type units
45656(@samp{DW_TAG_type_unit}) refer to the type unit's symbol table and not the
45657compilation unit (@samp{DW_TAG_comp_unit}) using the type.
45658
45659@value{GDBN} will only read version 4, 5, or 6 indices
e615022a 45660by specifying @code{set use-deprecated-index-sections on}.
796a7ff8
DE
45661GDB has a workaround for potentially broken version 7 indices so it is
45662currently not flagged as deprecated.
90476074
TT
45663
45664@item
45665The offset, from the start of the file, of the CU list.
45666
45667@item
45668The offset, from the start of the file, of the types CU list. Note
45669that this area can be empty, in which case this offset will be equal
45670to the next offset.
45671
45672@item
45673The offset, from the start of the file, of the address area.
45674
45675@item
45676The offset, from the start of the file, of the symbol table.
45677
45678@item
45679The offset, from the start of the file, of the constant pool.
45680@end enumerate
45681
45682@item
45683The CU list. This is a sequence of pairs of 64-bit little-endian
45684values, sorted by the CU offset. The first element in each pair is
45685the offset of a CU in the @code{.debug_info} section. The second
45686element in each pair is the length of that CU. References to a CU
45687elsewhere in the map are done using a CU index, which is just the
456880-based index into this table. Note that if there are type CUs, then
45689conceptually CUs and type CUs form a single list for the purposes of
45690CU indices.
45691
45692@item
45693The types CU list. This is a sequence of triplets of 64-bit
45694little-endian values. In a triplet, the first value is the CU offset,
45695the second value is the type offset in the CU, and the third value is
45696the type signature. The types CU list is not sorted.
45697
45698@item
45699The address area. The address area consists of a sequence of address
45700entries. Each address entry has three elements:
45701
45702@enumerate
45703@item
45704The low address. This is a 64-bit little-endian value.
45705
45706@item
45707The high address. This is a 64-bit little-endian value. Like
45708@code{DW_AT_high_pc}, the value is one byte beyond the end.
45709
45710@item
45711The CU index. This is an @code{offset_type} value.
45712@end enumerate
45713
45714@item
45715The symbol table. This is an open-addressed hash table. The size of
45716the hash table is always a power of 2.
45717
45718Each slot in the hash table consists of a pair of @code{offset_type}
45719values. The first value is the offset of the symbol's name in the
45720constant pool. The second value is the offset of the CU vector in the
45721constant pool.
45722
45723If both values are 0, then this slot in the hash table is empty. This
45724is ok because while 0 is a valid constant pool index, it cannot be a
45725valid index for both a string and a CU vector.
45726
45727The hash value for a table entry is computed by applying an
45728iterative hash function to the symbol's name. Starting with an
45729initial value of @code{r = 0}, each (unsigned) character @samp{c} in
559a7a62
JK
45730the string is incorporated into the hash using the formula depending on the
45731index version:
45732
45733@table @asis
45734@item Version 4
45735The formula is @code{r = r * 67 + c - 113}.
45736
156942c7 45737@item Versions 5 to 7
559a7a62
JK
45738The formula is @code{r = r * 67 + tolower (c) - 113}.
45739@end table
45740
45741The terminating @samp{\0} is not incorporated into the hash.
90476074
TT
45742
45743The step size used in the hash table is computed via
45744@code{((hash * 17) & (size - 1)) | 1}, where @samp{hash} is the hash
45745value, and @samp{size} is the size of the hash table. The step size
45746is used to find the next candidate slot when handling a hash
45747collision.
45748
45749The names of C@t{++} symbols in the hash table are canonicalized. We
45750don't currently have a simple description of the canonicalization
45751algorithm; if you intend to create new index sections, you must read
45752the code.
45753
45754@item
45755The constant pool. This is simply a bunch of bytes. It is organized
45756so that alignment is correct: CU vectors are stored first, followed by
45757strings.
45758
45759A CU vector in the constant pool is a sequence of @code{offset_type}
45760values. The first value is the number of CU indices in the vector.
156942c7
DE
45761Each subsequent value is the index and symbol attributes of a CU in
45762the CU list. This element in the hash table is used to indicate which
45763CUs define the symbol and how the symbol is used.
45764See below for the format of each CU index+attributes entry.
90476074
TT
45765
45766A string in the constant pool is zero-terminated.
45767@end enumerate
45768
156942c7
DE
45769Attributes were added to CU index values in @code{.gdb_index} version 7.
45770If a symbol has multiple uses within a CU then there is one
45771CU index+attributes value for each use.
45772
45773The format of each CU index+attributes entry is as follows
45774(bit 0 = LSB):
45775
45776@table @asis
45777
45778@item Bits 0-23
45779This is the index of the CU in the CU list.
45780@item Bits 24-27
45781These bits are reserved for future purposes and must be zero.
45782@item Bits 28-30
45783The kind of the symbol in the CU.
45784
45785@table @asis
45786@item 0
45787This value is reserved and should not be used.
45788By reserving zero the full @code{offset_type} value is backwards compatible
45789with previous versions of the index.
45790@item 1
45791The symbol is a type.
45792@item 2
45793The symbol is a variable or an enum value.
45794@item 3
45795The symbol is a function.
45796@item 4
45797Any other kind of symbol.
45798@item 5,6,7
45799These values are reserved.
45800@end table
45801
45802@item Bit 31
45803This bit is zero if the value is global and one if it is static.
45804
45805The determination of whether a symbol is global or static is complicated.
45806The authorative reference is the file @file{dwarf2read.c} in
45807@value{GDBN} sources.
45808
45809@end table
45810
45811This pseudo-code describes the computation of a symbol's kind and
45812global/static attributes in the index.
45813
45814@smallexample
45815is_external = get_attribute (die, DW_AT_external);
45816language = get_attribute (cu_die, DW_AT_language);
45817switch (die->tag)
45818 @{
45819 case DW_TAG_typedef:
45820 case DW_TAG_base_type:
45821 case DW_TAG_subrange_type:
45822 kind = TYPE;
45823 is_static = 1;
45824 break;
45825 case DW_TAG_enumerator:
45826 kind = VARIABLE;
9c37b5ae 45827 is_static = language != CPLUS;
156942c7
DE
45828 break;
45829 case DW_TAG_subprogram:
45830 kind = FUNCTION;
45831 is_static = ! (is_external || language == ADA);
45832 break;
45833 case DW_TAG_constant:
45834 kind = VARIABLE;
45835 is_static = ! is_external;
45836 break;
45837 case DW_TAG_variable:
45838 kind = VARIABLE;
45839 is_static = ! is_external;
45840 break;
45841 case DW_TAG_namespace:
45842 kind = TYPE;
45843 is_static = 0;
45844 break;
45845 case DW_TAG_class_type:
45846 case DW_TAG_interface_type:
45847 case DW_TAG_structure_type:
45848 case DW_TAG_union_type:
45849 case DW_TAG_enumeration_type:
45850 kind = TYPE;
9c37b5ae 45851 is_static = language != CPLUS;
156942c7
DE
45852 break;
45853 default:
45854 assert (0);
45855 @}
45856@end smallexample
45857
43662968
JK
45858@node Man Pages
45859@appendix Manual pages
45860@cindex Man pages
45861
45862@menu
45863* gdb man:: The GNU Debugger man page
45864* gdbserver man:: Remote Server for the GNU Debugger man page
b292c783 45865* gcore man:: Generate a core file of a running program
43662968 45866* gdbinit man:: gdbinit scripts
ba643918 45867* gdb-add-index man:: Add index files to speed up GDB
43662968
JK
45868@end menu
45869
45870@node gdb man
45871@heading gdb man
45872
45873@c man title gdb The GNU Debugger
45874
45875@c man begin SYNOPSIS gdb
45876gdb [@option{-help}] [@option{-nh}] [@option{-nx}] [@option{-q}]
45877[@option{-batch}] [@option{-cd=}@var{dir}] [@option{-f}]
45878[@option{-b}@w{ }@var{bps}]
45879 [@option{-tty=}@var{dev}] [@option{-s} @var{symfile}]
45880[@option{-e}@w{ }@var{prog}] [@option{-se}@w{ }@var{prog}]
906ccdf0
JK
45881[@option{-c}@w{ }@var{core}] [@option{-p}@w{ }@var{procID}]
45882 [@option{-x}@w{ }@var{cmds}] [@option{-d}@w{ }@var{dir}]
45883[@var{prog}|@var{prog} @var{procID}|@var{prog} @var{core}]
43662968
JK
45884@c man end
45885
45886@c man begin DESCRIPTION gdb
45887The purpose of a debugger such as @value{GDBN} is to allow you to see what is
45888going on ``inside'' another program while it executes -- or what another
45889program was doing at the moment it crashed.
45890
45891@value{GDBN} can do four main kinds of things (plus other things in support of
45892these) to help you catch bugs in the act:
45893
45894@itemize @bullet
45895@item
45896Start your program, specifying anything that might affect its behavior.
45897
45898@item
45899Make your program stop on specified conditions.
45900
45901@item
45902Examine what has happened, when your program has stopped.
45903
45904@item
45905Change things in your program, so you can experiment with correcting the
45906effects of one bug and go on to learn about another.
45907@end itemize
45908
906ccdf0
JK
45909You can use @value{GDBN} to debug programs written in C, C@t{++}, Fortran and
45910Modula-2.
43662968
JK
45911
45912@value{GDBN} is invoked with the shell command @code{gdb}. Once started, it reads
45913commands from the terminal until you tell it to exit with the @value{GDBN}
45914command @code{quit}. You can get online help from @value{GDBN} itself
45915by using the command @code{help}.
45916
45917You can run @code{gdb} with no arguments or options; but the most
45918usual way to start @value{GDBN} is with one argument or two, specifying an
45919executable program as the argument:
45920
45921@smallexample
45922gdb program
45923@end smallexample
45924
45925You can also start with both an executable program and a core file specified:
45926
45927@smallexample
45928gdb program core
45929@end smallexample
45930
4ed4690f
SM
45931You can, instead, specify a process ID as a second argument or use option
45932@code{-p}, if you want to debug a running process:
43662968
JK
45933
45934@smallexample
45935gdb program 1234
906ccdf0 45936gdb -p 1234
43662968
JK
45937@end smallexample
45938
45939@noindent
4ed4690f
SM
45940would attach @value{GDBN} to process @code{1234}. With option @option{-p} you
45941can omit the @var{program} filename.
43662968
JK
45942
45943Here are some of the most frequently needed @value{GDBN} commands:
45944
45945@c pod2man highlights the right hand side of the @item lines.
45946@table @env
224f10c1 45947@item break [@var{file}:]@var{function}
43662968
JK
45948Set a breakpoint at @var{function} (in @var{file}).
45949
45950@item run [@var{arglist}]
45951Start your program (with @var{arglist}, if specified).
45952
45953@item bt
45954Backtrace: display the program stack.
45955
45956@item print @var{expr}
45957Display the value of an expression.
45958
45959@item c
45960Continue running your program (after stopping, e.g. at a breakpoint).
45961
45962@item next
45963Execute next program line (after stopping); step @emph{over} any
45964function calls in the line.
45965
45966@item edit [@var{file}:]@var{function}
45967look at the program line where it is presently stopped.
45968
45969@item list [@var{file}:]@var{function}
45970type the text of the program in the vicinity of where it is presently stopped.
45971
45972@item step
45973Execute next program line (after stopping); step @emph{into} any
45974function calls in the line.
45975
45976@item help [@var{name}]
45977Show information about @value{GDBN} command @var{name}, or general information
45978about using @value{GDBN}.
45979
45980@item quit
45981Exit from @value{GDBN}.
45982@end table
45983
45984@ifset man
45985For full details on @value{GDBN},
45986see @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
45987by Richard M. Stallman and Roland H. Pesch. The same text is available online
45988as the @code{gdb} entry in the @code{info} program.
45989@end ifset
45990@c man end
45991
45992@c man begin OPTIONS gdb
45993Any arguments other than options specify an executable
45994file and core file (or process ID); that is, the first argument
45995encountered with no
45996associated option flag is equivalent to a @option{-se} option, and the second,
45997if any, is equivalent to a @option{-c} option if it's the name of a file.
45998Many options have
45999both long and short forms; both are shown here. The long forms are also
46000recognized if you truncate them, so long as enough of the option is
46001present to be unambiguous. (If you prefer, you can flag option
46002arguments with @option{+} rather than @option{-}, though we illustrate the
46003more usual convention.)
46004
46005All the options and command line arguments you give are processed
46006in sequential order. The order makes a difference when the @option{-x}
46007option is used.
46008
46009@table @env
46010@item -help
46011@itemx -h
46012List all options, with brief explanations.
46013
46014@item -symbols=@var{file}
46015@itemx -s @var{file}
46016Read symbol table from file @var{file}.
46017
46018@item -write
46019Enable writing into executable and core files.
46020
46021@item -exec=@var{file}
46022@itemx -e @var{file}
46023Use file @var{file} as the executable file to execute when
46024appropriate, and for examining pure data in conjunction with a core
46025dump.
46026
46027@item -se=@var{file}
46028Read symbol table from file @var{file} and use it as the executable
46029file.
46030
46031@item -core=@var{file}
46032@itemx -c @var{file}
46033Use file @var{file} as a core dump to examine.
46034
46035@item -command=@var{file}
46036@itemx -x @var{file}
46037Execute @value{GDBN} commands from file @var{file}.
46038
46039@item -ex @var{command}
46040Execute given @value{GDBN} @var{command}.
46041
46042@item -directory=@var{directory}
46043@itemx -d @var{directory}
46044Add @var{directory} to the path to search for source files.
46045
46046@item -nh
46047Do not execute commands from @file{~/.gdbinit}.
46048
46049@item -nx
46050@itemx -n
46051Do not execute commands from any @file{.gdbinit} initialization files.
46052
46053@item -quiet
46054@itemx -q
46055``Quiet''. Do not print the introductory and copyright messages. These
46056messages are also suppressed in batch mode.
46057
46058@item -batch
46059Run in batch mode. Exit with status @code{0} after processing all the command
46060files specified with @option{-x} (and @file{.gdbinit}, if not inhibited).
46061Exit with nonzero status if an error occurs in executing the @value{GDBN}
46062commands in the command files.
46063
46064Batch mode may be useful for running @value{GDBN} as a filter, for example to
46065download and run a program on another computer; in order to make this
46066more useful, the message
46067
46068@smallexample
46069Program exited normally.
46070@end smallexample
46071
46072@noindent
46073(which is ordinarily issued whenever a program running under @value{GDBN} control
46074terminates) is not issued when running in batch mode.
46075
46076@item -cd=@var{directory}
46077Run @value{GDBN} using @var{directory} as its working directory,
46078instead of the current directory.
46079
46080@item -fullname
46081@itemx -f
46082Emacs sets this option when it runs @value{GDBN} as a subprocess. It tells
46083@value{GDBN} to output the full file name and line number in a standard,
46084recognizable fashion each time a stack frame is displayed (which
46085includes each time the program stops). This recognizable format looks
46086like two @samp{\032} characters, followed by the file name, line number
46087and character position separated by colons, and a newline. The
46088Emacs-to-@value{GDBN} interface program uses the two @samp{\032}
46089characters as a signal to display the source code for the frame.
46090
46091@item -b @var{bps}
46092Set the line speed (baud rate or bits per second) of any serial
46093interface used by @value{GDBN} for remote debugging.
46094
46095@item -tty=@var{device}
46096Run using @var{device} for your program's standard input and output.
46097@end table
46098@c man end
46099
46100@c man begin SEEALSO gdb
46101@ifset man
46102The full documentation for @value{GDBN} is maintained as a Texinfo manual.
46103If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
46104documentation are properly installed at your site, the command
46105
46106@smallexample
46107info gdb
46108@end smallexample
46109
46110@noindent
46111should give you access to the complete manual.
46112
46113@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46114Richard M. Stallman and Roland H. Pesch, July 1991.
46115@end ifset
46116@c man end
46117
46118@node gdbserver man
46119@heading gdbserver man
46120
46121@c man title gdbserver Remote Server for the GNU Debugger
46122@format
46123@c man begin SYNOPSIS gdbserver
5b8b6385 46124gdbserver @var{comm} @var{prog} [@var{args}@dots{}]
43662968 46125
5b8b6385
JK
46126gdbserver --attach @var{comm} @var{pid}
46127
46128gdbserver --multi @var{comm}
43662968
JK
46129@c man end
46130@end format
46131
46132@c man begin DESCRIPTION gdbserver
46133@command{gdbserver} is a program that allows you to run @value{GDBN} on a different machine
46134than the one which is running the program being debugged.
46135
46136@ifclear man
46137@subheading Usage (server (target) side)
46138@end ifclear
46139@ifset man
46140Usage (server (target) side):
46141@end ifset
46142
46143First, you need to have a copy of the program you want to debug put onto
46144the target system. The program can be stripped to save space if needed, as
46145@command{gdbserver} doesn't care about symbols. All symbol handling is taken care of by
46146the @value{GDBN} running on the host system.
46147
46148To use the server, you log on to the target system, and run the @command{gdbserver}
46149program. You must tell it (a) how to communicate with @value{GDBN}, (b) the name of
46150your program, and (c) its arguments. The general syntax is:
46151
46152@smallexample
46153target> gdbserver @var{comm} @var{program} [@var{args} ...]
46154@end smallexample
46155
46156For example, using a serial port, you might say:
46157
46158@smallexample
46159@ifset man
46160@c @file would wrap it as F</dev/com1>.
46161target> gdbserver /dev/com1 emacs foo.txt
46162@end ifset
46163@ifclear man
46164target> gdbserver @file{/dev/com1} emacs foo.txt
46165@end ifclear
46166@end smallexample
46167
46168This tells @command{gdbserver} to debug emacs with an argument of foo.txt, and
46169to communicate with @value{GDBN} via @file{/dev/com1}. @command{gdbserver} now
46170waits patiently for the host @value{GDBN} to communicate with it.
46171
46172To use a TCP connection, you could say:
46173
46174@smallexample
46175target> gdbserver host:2345 emacs foo.txt
46176@end smallexample
46177
46178This says pretty much the same thing as the last example, except that we are
46179going to communicate with the @code{host} @value{GDBN} via TCP. The @code{host:2345} argument means
46180that we are expecting to see a TCP connection from @code{host} to local TCP port
461812345. (Currently, the @code{host} part is ignored.) You can choose any number you
46182want for the port number as long as it does not conflict with any existing TCP
46183ports on the target system. This same port number must be used in the host
46184@value{GDBN}s @code{target remote} command, which will be described shortly. Note that if
46185you chose a port number that conflicts with another service, @command{gdbserver} will
46186print an error message and exit.
46187
5b8b6385 46188@command{gdbserver} can also attach to running programs.
43662968
JK
46189This is accomplished via the @option{--attach} argument. The syntax is:
46190
46191@smallexample
5b8b6385 46192target> gdbserver --attach @var{comm} @var{pid}
43662968
JK
46193@end smallexample
46194
46195@var{pid} is the process ID of a currently running process. It isn't
46196necessary to point @command{gdbserver} at a binary for the running process.
46197
5b8b6385
JK
46198To start @code{gdbserver} without supplying an initial command to run
46199or process ID to attach, use the @option{--multi} command line option.
46200In such case you should connect using @kbd{target extended-remote} to start
46201the program you want to debug.
46202
46203@smallexample
46204target> gdbserver --multi @var{comm}
46205@end smallexample
46206
43662968
JK
46207@ifclear man
46208@subheading Usage (host side)
46209@end ifclear
46210@ifset man
46211Usage (host side):
46212@end ifset
46213
46214You need an unstripped copy of the target program on your host system, since
1a088a2e 46215@value{GDBN} needs to examine its symbol tables and such. Start up @value{GDBN} as you normally
43662968
JK
46216would, with the target program as the first argument. (You may need to use the
46217@option{--baud} option if the serial line is running at anything except 9600 baud.)
46218That is @code{gdb TARGET-PROG}, or @code{gdb --baud BAUD TARGET-PROG}. After that, the only
5b8b6385
JK
46219new command you need to know about is @code{target remote}
46220(or @code{target extended-remote}). Its argument is either
43662968
JK
46221a device name (usually a serial device, like @file{/dev/ttyb}), or a @code{HOST:PORT}
46222descriptor. For example:
46223
46224@smallexample
46225@ifset man
46226@c @file would wrap it as F</dev/ttyb>.
46227(gdb) target remote /dev/ttyb
46228@end ifset
46229@ifclear man
46230(gdb) target remote @file{/dev/ttyb}
46231@end ifclear
46232@end smallexample
46233
46234@noindent
46235communicates with the server via serial line @file{/dev/ttyb}, and:
46236
46237@smallexample
46238(gdb) target remote the-target:2345
46239@end smallexample
46240
46241@noindent
46242communicates via a TCP connection to port 2345 on host `the-target', where
46243you previously started up @command{gdbserver} with the same port number. Note that for
46244TCP connections, you must start up @command{gdbserver} prior to using the `target remote'
46245command, otherwise you may get an error that looks something like
46246`Connection refused'.
5b8b6385
JK
46247
46248@command{gdbserver} can also debug multiple inferiors at once,
46249described in
46250@ifset man
65c574f6
PA
46251the @value{GDBN} manual in node @code{Inferiors Connections and Programs}
46252-- shell command @code{info -f gdb -n 'Inferiors Connections and Programs'}.
5b8b6385
JK
46253@end ifset
46254@ifclear man
65c574f6 46255@ref{Inferiors Connections and Programs}.
5b8b6385
JK
46256@end ifclear
46257In such case use the @code{extended-remote} @value{GDBN} command variant:
46258
46259@smallexample
46260(gdb) target extended-remote the-target:2345
46261@end smallexample
46262
46263The @command{gdbserver} option @option{--multi} may or may not be used in such
46264case.
43662968
JK
46265@c man end
46266
46267@c man begin OPTIONS gdbserver
5b8b6385
JK
46268There are three different modes for invoking @command{gdbserver}:
46269
46270@itemize @bullet
46271
46272@item
46273Debug a specific program specified by its program name:
46274
46275@smallexample
46276gdbserver @var{comm} @var{prog} [@var{args}@dots{}]
46277@end smallexample
46278
46279The @var{comm} parameter specifies how should the server communicate
46280with @value{GDBN}; it is either a device name (to use a serial line),
46281a TCP port number (@code{:1234}), or @code{-} or @code{stdio} to use
46282stdin/stdout of @code{gdbserver}. Specify the name of the program to
46283debug in @var{prog}. Any remaining arguments will be passed to the
46284program verbatim. When the program exits, @value{GDBN} will close the
46285connection, and @code{gdbserver} will exit.
46286
46287@item
46288Debug a specific program by specifying the process ID of a running
46289program:
46290
46291@smallexample
46292gdbserver --attach @var{comm} @var{pid}
46293@end smallexample
46294
46295The @var{comm} parameter is as described above. Supply the process ID
46296of a running program in @var{pid}; @value{GDBN} will do everything
46297else. Like with the previous mode, when the process @var{pid} exits,
46298@value{GDBN} will close the connection, and @code{gdbserver} will exit.
46299
46300@item
46301Multi-process mode -- debug more than one program/process:
46302
46303@smallexample
46304gdbserver --multi @var{comm}
46305@end smallexample
46306
46307In this mode, @value{GDBN} can instruct @command{gdbserver} which
46308command(s) to run. Unlike the other 2 modes, @value{GDBN} will not
46309close the connection when a process being debugged exits, so you can
46310debug several processes in the same session.
46311@end itemize
46312
46313In each of the modes you may specify these options:
46314
46315@table @env
46316
46317@item --help
46318List all options, with brief explanations.
46319
46320@item --version
46321This option causes @command{gdbserver} to print its version number and exit.
46322
46323@item --attach
46324@command{gdbserver} will attach to a running program. The syntax is:
46325
46326@smallexample
46327target> gdbserver --attach @var{comm} @var{pid}
46328@end smallexample
46329
46330@var{pid} is the process ID of a currently running process. It isn't
46331necessary to point @command{gdbserver} at a binary for the running process.
46332
46333@item --multi
46334To start @code{gdbserver} without supplying an initial command to run
46335or process ID to attach, use this command line option.
46336Then you can connect using @kbd{target extended-remote} and start
46337the program you want to debug. The syntax is:
46338
46339@smallexample
46340target> gdbserver --multi @var{comm}
46341@end smallexample
46342
46343@item --debug
46344Instruct @code{gdbserver} to display extra status information about the debugging
46345process.
46346This option is intended for @code{gdbserver} development and for bug reports to
46347the developers.
46348
46349@item --remote-debug
46350Instruct @code{gdbserver} to display remote protocol debug output.
46351This option is intended for @code{gdbserver} development and for bug reports to
46352the developers.
46353
aeb2e706
AH
46354@item --debug-file=@var{filename}
46355Instruct @code{gdbserver} to send any debug output to the given @var{filename}.
46356This option is intended for @code{gdbserver} development and for bug reports to
46357the developers.
46358
87ce2a04
DE
46359@item --debug-format=option1@r{[},option2,...@r{]}
46360Instruct @code{gdbserver} to include extra information in each line
46361of debugging output.
46362@xref{Other Command-Line Arguments for gdbserver}.
46363
5b8b6385
JK
46364@item --wrapper
46365Specify a wrapper to launch programs
46366for debugging. The option should be followed by the name of the
46367wrapper, then any command-line arguments to pass to the wrapper, then
46368@kbd{--} indicating the end of the wrapper arguments.
46369
46370@item --once
46371By default, @command{gdbserver} keeps the listening TCP port open, so that
46372additional connections are possible. However, if you start @code{gdbserver}
46373with the @option{--once} option, it will stop listening for any further
46374connection attempts after connecting to the first @value{GDBN} session.
46375
46376@c --disable-packet is not documented for users.
46377
46378@c --disable-randomization and --no-disable-randomization are superseded by
46379@c QDisableRandomization.
46380
46381@end table
43662968
JK
46382@c man end
46383
46384@c man begin SEEALSO gdbserver
46385@ifset man
46386The full documentation for @value{GDBN} is maintained as a Texinfo manual.
46387If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
46388documentation are properly installed at your site, the command
46389
46390@smallexample
46391info gdb
46392@end smallexample
46393
46394should give you access to the complete manual.
46395
46396@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46397Richard M. Stallman and Roland H. Pesch, July 1991.
46398@end ifset
46399@c man end
46400
b292c783
JK
46401@node gcore man
46402@heading gcore
46403
46404@c man title gcore Generate a core file of a running program
46405
46406@format
46407@c man begin SYNOPSIS gcore
129eb0f1 46408gcore [-a] [-o @var{prefix}] @var{pid1} [@var{pid2}...@var{pidN}]
b292c783
JK
46409@c man end
46410@end format
46411
46412@c man begin DESCRIPTION gcore
129eb0f1
SDJ
46413Generate core dumps of one or more running programs with process IDs
46414@var{pid1}, @var{pid2}, etc. A core file produced by @command{gcore}
46415is equivalent to one produced by the kernel when the process crashes
46416(and when @kbd{ulimit -c} was used to set up an appropriate core dump
46417limit). However, unlike after a crash, after @command{gcore} finishes
46418its job the program remains running without any change.
b292c783
JK
46419@c man end
46420
46421@c man begin OPTIONS gcore
46422@table @env
c179febe
SL
46423@item -a
46424Dump all memory mappings. The actual effect of this option depends on
46425the Operating System. On @sc{gnu}/Linux, it will disable
46426@code{use-coredump-filter} (@pxref{set use-coredump-filter}) and
46427enable @code{dump-excluded-mappings} (@pxref{set
46428dump-excluded-mappings}).
46429
129eb0f1
SDJ
46430@item -o @var{prefix}
46431The optional argument @var{prefix} specifies the prefix to be used
46432when composing the file names of the core dumps. The file name is
46433composed as @file{@var{prefix}.@var{pid}}, where @var{pid} is the
46434process ID of the running program being analyzed by @command{gcore}.
46435If not specified, @var{prefix} defaults to @var{gcore}.
b292c783
JK
46436@end table
46437@c man end
46438
46439@c man begin SEEALSO gcore
46440@ifset man
46441The full documentation for @value{GDBN} is maintained as a Texinfo manual.
46442If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
46443documentation are properly installed at your site, the command
46444
46445@smallexample
46446info gdb
46447@end smallexample
46448
46449@noindent
46450should give you access to the complete manual.
46451
46452@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46453Richard M. Stallman and Roland H. Pesch, July 1991.
46454@end ifset
46455@c man end
46456
43662968
JK
46457@node gdbinit man
46458@heading gdbinit
46459
46460@c man title gdbinit GDB initialization scripts
46461
46462@format
46463@c man begin SYNOPSIS gdbinit
46464@ifset SYSTEM_GDBINIT
46465@value{SYSTEM_GDBINIT}
46466@end ifset
46467
ed2a2229
CB
46468@ifset SYSTEM_GDBINIT_DIR
46469@value{SYSTEM_GDBINIT_DIR}/*
46470@end ifset
46471
43662968
JK
46472~/.gdbinit
46473
46474./.gdbinit
46475@c man end
46476@end format
46477
46478@c man begin DESCRIPTION gdbinit
46479These files contain @value{GDBN} commands to automatically execute during
46480@value{GDBN} startup. The lines of contents are canned sequences of commands,
46481described in
46482@ifset man
46483the @value{GDBN} manual in node @code{Sequences}
46484-- shell command @code{info -f gdb -n Sequences}.
46485@end ifset
46486@ifclear man
46487@ref{Sequences}.
46488@end ifclear
46489
46490Please read more in
46491@ifset man
46492the @value{GDBN} manual in node @code{Startup}
46493-- shell command @code{info -f gdb -n Startup}.
46494@end ifset
46495@ifclear man
46496@ref{Startup}.
46497@end ifclear
46498
46499@table @env
46500@ifset SYSTEM_GDBINIT
46501@item @value{SYSTEM_GDBINIT}
46502@end ifset
46503@ifclear SYSTEM_GDBINIT
46504@item (not enabled with @code{--with-system-gdbinit} during compilation)
46505@end ifclear
46506System-wide initialization file. It is executed unless user specified
46507@value{GDBN} option @code{-nx} or @code{-n}.
46508See more in
46509@ifset man
46510the @value{GDBN} manual in node @code{System-wide configuration}
46511-- shell command @code{info -f gdb -n 'System-wide configuration'}.
46512@end ifset
ed2a2229
CB
46513@ifset SYSTEM_GDBINIT_DIR
46514@item @value{SYSTEM_GDBINIT_DIR}
46515@end ifset
46516@ifclear SYSTEM_GDBINIT_DIR
46517@item (not enabled with @code{--with-system-gdbinit-dir} during compilation)
46518@end ifclear
46519System-wide initialization directory. All files in this directory are
46520executed on startup unless user specified @value{GDBN} option @code{-nx} or
46521@code{-n}, as long as they have a recognized file extension.
46522See more in
46523@ifset man
46524the @value{GDBN} manual in node @code{System-wide configuration}
46525-- shell command @code{info -f gdb -n 'System-wide configuration'}.
46526@end ifset
43662968
JK
46527@ifclear man
46528@ref{System-wide configuration}.
46529@end ifclear
46530
46531@item ~/.gdbinit
46532User initialization file. It is executed unless user specified
46533@value{GDBN} options @code{-nx}, @code{-n} or @code{-nh}.
46534
46535@item ./.gdbinit
46536Initialization file for current directory. It may need to be enabled with
46537@value{GDBN} security command @code{set auto-load local-gdbinit}.
46538See more in
46539@ifset man
46540the @value{GDBN} manual in node @code{Init File in the Current Directory}
46541-- shell command @code{info -f gdb -n 'Init File in the Current Directory'}.
46542@end ifset
46543@ifclear man
46544@ref{Init File in the Current Directory}.
46545@end ifclear
46546@end table
46547@c man end
46548
46549@c man begin SEEALSO gdbinit
46550@ifset man
46551gdb(1), @code{info -f gdb -n Startup}
46552
46553The full documentation for @value{GDBN} is maintained as a Texinfo manual.
46554If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
46555documentation are properly installed at your site, the command
ba643918
SDJ
46556
46557@smallexample
46558info gdb
46559@end smallexample
46560
46561should give you access to the complete manual.
46562
46563@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46564Richard M. Stallman and Roland H. Pesch, July 1991.
46565@end ifset
46566@c man end
46567
46568@node gdb-add-index man
ba643918 46569@heading gdb-add-index
d726cb5d 46570@pindex gdb-add-index
dbfa4523 46571@anchor{gdb-add-index}
ba643918
SDJ
46572
46573@c man title gdb-add-index Add index files to speed up GDB
46574
46575@c man begin SYNOPSIS gdb-add-index
46576gdb-add-index @var{filename}
46577@c man end
46578
46579@c man begin DESCRIPTION gdb-add-index
46580When @value{GDBN} finds a symbol file, it scans the symbols in the
46581file in order to construct an internal symbol table. This lets most
46582@value{GDBN} operations work quickly--at the cost of a delay early on.
46583For large programs, this delay can be quite lengthy, so @value{GDBN}
46584provides a way to build an index, which speeds up startup.
46585
46586To determine whether a file contains such an index, use the command
46587@kbd{readelf -S filename}: the index is stored in a section named
46588@code{.gdb_index}. The index file can only be produced on systems
46589which use ELF binaries and DWARF debug information (i.e., sections
46590named @code{.debug_*}).
46591
46592@command{gdb-add-index} uses @value{GDBN} and @command{objdump} found
46593in the @env{PATH} environment variable. If you want to use different
46594versions of these programs, you can specify them through the
46595@env{GDB} and @env{OBJDUMP} environment variables.
46596
46597See more in
46598@ifset man
46599the @value{GDBN} manual in node @code{Index Files}
46600-- shell command @kbd{info -f gdb -n "Index Files"}.
46601@end ifset
46602@ifclear man
46603@ref{Index Files}.
46604@end ifclear
46605@c man end
46606
46607@c man begin SEEALSO gdb-add-index
46608@ifset man
46609The full documentation for @value{GDBN} is maintained as a Texinfo manual.
46610If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
46611documentation are properly installed at your site, the command
43662968
JK
46612
46613@smallexample
46614info gdb
46615@end smallexample
46616
46617should give you access to the complete manual.
46618
46619@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46620Richard M. Stallman and Roland H. Pesch, July 1991.
46621@end ifset
46622@c man end
46623
aab4e0ec 46624@include gpl.texi
eb12ee30 46625
e4c0cfae
SS
46626@node GNU Free Documentation License
46627@appendix GNU Free Documentation License
6826cf00
EZ
46628@include fdl.texi
46629
00595b5e
EZ
46630@node Concept Index
46631@unnumbered Concept Index
c906108c
SS
46632
46633@printindex cp
46634
00595b5e
EZ
46635@node Command and Variable Index
46636@unnumbered Command, Variable, and Function Index
46637
46638@printindex fn
46639
c906108c 46640@tex
984359d2 46641% I think something like @@colophon should be in texinfo. In the
c906108c
SS
46642% meantime:
46643\long\def\colophon{\hbox to0pt{}\vfill
46644\centerline{The body of this manual is set in}
46645\centerline{\fontname\tenrm,}
46646\centerline{with headings in {\bf\fontname\tenbf}}
46647\centerline{and examples in {\tt\fontname\tentt}.}
46648\centerline{{\it\fontname\tenit\/},}
46649\centerline{{\bf\fontname\tenbf}, and}
46650\centerline{{\sl\fontname\tensl\/}}
46651\centerline{are used for emphasis.}\vfill}
46652\page\colophon
984359d2 46653% Blame: doc@@cygnus.com, 1991.
c906108c
SS
46654@end tex
46655
c906108c 46656@bye
This page took 7.893127 seconds and 4 git commands to generate.