xref: /netbsd-src/external/gpl3/gdb/dist/gdb/doc/gdb.texinfo (revision 7d62b00eb9ad855ffcd7da46b41e23feb5476fac)
1\input texinfo      @c -*-texinfo-*-
2@c Copyright (C) 1988--2020 Free Software Foundation, Inc.
3@c
4@c %**start of header
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
9@c man begin INCLUDE
10@include gdb-cfg.texi
11@c man end
12@c
13@settitle Debugging with @value{GDBN}
14@setchapternewpage odd
15@c %**end of header
16
17@iftex
18@c @smallbook
19@c @cropmarks
20@end iftex
21
22@finalout
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
29
30@c readline appendices use @vindex, @findex and @ftable,
31@c annotate.texi and gdbmi use @findex.
32@syncodeindex vr fn
33
34@c !!set GDB manual's edition---not the same as GDB version!
35@c This is updated by GNU Press.
36@set EDITION Tenth
37
38@c !!set GDB edit command default editor
39@set EDITOR /bin/ex
40
41@c THIS MANUAL REQUIRES TEXINFO 4.0 OR LATER.
42
43@c This is a dir.info fragment to support semi-automated addition of
44@c manuals to an info tree.
45@dircategory Software development
46@direntry
47* Gdb: (gdb).                     The GNU debugger.
48* gdbserver: (gdb) Server.        The GNU debugging server.
49@end direntry
50
51@copying
52@c man begin COPYRIGHT
53Copyright @copyright{} 1988-2020 Free Software Foundation, Inc.
54
55Permission is granted to copy, distribute and/or modify this document
56under the terms of the GNU Free Documentation License, Version 1.3 or
57any later version published by the Free Software Foundation; with the
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.
61
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.''
65@c man end
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
80
81@titlepage
82@title Debugging with @value{GDBN}
83@subtitle The @sc{gnu} Source-Level Debugger
84@sp 1
85@subtitle @value{EDITION} Edition, for @value{GDBN} version @value{GDBVN}
86@ifset VERSION_PACKAGE
87@sp 1
88@subtitle @value{VERSION_PACKAGE}
89@end ifset
90@author Richard Stallman, Roland Pesch, Stan Shebs, et al.
91@page
92@tex
93{\parskip=0pt
94\hfill (Send bugs and comments on @value{GDBN} to @value{BUGURL}.)\par
95\hfill {\it Debugging with @value{GDBN}}\par
96\hfill \TeX{}info \texinfoversion\par
97}
98@end tex
99
100@vskip 0pt plus 1filll
101Published by the Free Software Foundation @*
10251 Franklin Street, Fifth Floor,
103Boston, MA 02110-1301, USA@*
104ISBN 978-0-9831592-3-0 @*
105
106@insertcopying
107@end titlepage
108@page
109
110@ifnottex
111@node Top, Summary
112
113@top Debugging with @value{GDBN}
114
115This file describes @value{GDBN}, the @sc{gnu} symbolic debugger.
116
117This is the @value{EDITION} Edition, for @value{GDBN}
118@ifset VERSION_PACKAGE
119@value{VERSION_PACKAGE}
120@end ifset
121Version @value{GDBVN}.
122
123Copyright (C) 1988-2020 Free Software Foundation, Inc.
124
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
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
137* Reverse Execution::           Running programs backward
138* Process Record and Replay::   Recording inferior's execution and replaying it
139* Stack::                       Examining the stack
140* Source::                      Examining source files
141* Data::                        Examining data
142* Optimized Code::              Debugging optimized code
143* Macros::                      Preprocessor Macros
144* Tracepoints::                 Debugging remote targets non-intrusively
145* Overlays::                    Debugging programs that use overlays
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
153* Remote Debugging::            Debugging remote programs
154* Configurations::              Configuration-specific information
155* Controlling GDB::             Controlling @value{GDBN}
156* Extending GDB::               Extending @value{GDBN}
157* Interpreters::		Command Interpreters
158* TUI::                         @value{GDBN} Text User Interface
159* Emacs::                       Using @value{GDBN} under @sc{gnu} Emacs
160* GDB/MI::                      @value{GDBN}'s Machine Interface.
161* Annotations::                 @value{GDBN}'s annotation interface.
162* JIT Interface::               Using the JIT debugging interface.
163* In-Process Agent::            In-Process Agent
164
165* GDB Bugs::                    Reporting bugs in @value{GDBN}
166
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
172* Command Line Editing::        Command Line Editing
173* Using History Interactively:: Using History Interactively
174@end ifclear
175* In Memoriam::                 In Memoriam
176* Formatting Documentation::    How to format and print @value{GDBN} documentation
177* Installing GDB::              Installing GDB
178* Maintenance Commands::        Maintenance Commands
179* Remote Protocol::             GDB Remote Serial Protocol
180* Agent Expressions::           The GDB Agent Expression Mechanism
181* Target Descriptions::         How targets can describe themselves to
182                                @value{GDBN}
183* Operating System Information:: Getting additional information from
184                                 the operating system
185* Trace File Format::		GDB trace file format
186* Index Section Format::        .gdb_index section format
187* Man Pages::			Manual pages
188* Copying::			GNU General Public License says
189                                how you can copy and share GDB
190* GNU Free Documentation License::  The license for this documentation
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
194@end menu
195
196@end ifnottex
197
198@contents
199
200@node Summary
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
225You can use @value{GDBN} to debug programs written in C and C@t{++}.
226For more information, see @ref{Supported Languages,,Supported Languages}.
227For more information, see @ref{C,,C and C++}.
228
229Support for D is partial.  For information on D, see
230@ref{D,,D}.
231
232@cindex Modula-2
233Support for Modula-2 is partial.  For information on Modula-2, see
234@ref{Modula-2,,Modula-2}.
235
236Support for OpenCL C is partial.  For information on OpenCL C, see
237@ref{OpenCL C,,OpenCL C}.
238
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.
244
245@cindex Fortran
246@value{GDBN} can be used to debug programs written in Fortran, although
247it may be necessary to refer to some variables with a trailing
248underscore.
249
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
253@menu
254* Free Software::               Freely redistributable software
255* Free Documentation::          Free Software Needs Free Documentation
256* Contributors::                Contributors to GDB
257@end menu
258
259@node Free Software
260@unnumberedsec Free Software
261
262@value{GDBN} is @dfn{free software}, protected by the @sc{gnu}
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
275@node Free Documentation
276@unnumberedsec Free Software Needs Free Documentation
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
351is free, write to @email{licensing@@gnu.org}.
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.
359Check the history of the book, and try to reward the publishers that
360have paid or pay the authors to work on it.
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
366@node Contributors
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
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:
388Andrew Cagney (releases 6.3, 6.2, 6.1, 6.0, 5.3, 5.2, 5.1 and 5.0);
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
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).
406
407@value{GDBN} uses the BFD subroutine library to examine multiple
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
414Brent Benson of Harris Computer Systems contributed DWARF 2 support.
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.
434Marko Mlinar contributed OpenRISC 1000 support.
435
436Andreas Schwab contributed M68K @sc{gnu}/Linux support.
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
452Andrew Beers of SUNY Buffalo wrote the language-switching code, the
453Modula-2 support, and contributed the Languages chapter of this manual.
454
455Fred Fish wrote most of the support for Unix System Vr4.
456He also enhanced the command-completion support to cover C@t{++} overloaded
457symbols.
458
459Hitachi America (now Renesas America), Ltd. sponsored the support for
460H8/300, H8/500, and Super-H processors.
461
462NEC sponsored the support for the v850, Vr4xxx, and Vr5xxx processors.
463
464Mitsubishi (now Renesas) sponsored the support for D10V, D30V, and M32R/D
465processors.
466
467Toshiba sponsored the support for the TX39 Mips processor.
468
469Matsushita sponsored the support for the MN10200 and MN10300 processors.
470
471Fujitsu sponsored the support for SPARClite and FR30 processors.
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
481nearly innumerable bug fixes and cleanups throughout @value{GDBN}.
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
485(narrow mode), HP's implementation of kernel threads, HP's aC@t{++}
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.
490
491DJ Delorie ported @value{GDBN} to MS-DOS, for the DJGPP project.
492Robert Hoehne made significant contributions to the DJGPP port.
493
494Cygnus Solutions has sponsored @value{GDBN} maintenance and much of its
495development since 1991.  Cygnus engineers who have worked on @value{GDBN}
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.
509
510Andrew Cagney, Fernando Nasser, and Elena Zannoni, while working for
511Cygnus Solutions, implemented the original @sc{gdb/mi} interface.
512
513Jim Blandy added support for preprocessor macros, while working for Red
514Hat.
515
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
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
528trad unwinders.  The architecture-specific changes, each involving a
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
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
541Michael Eager and staff of Xilinx, Inc., contributed support for the
542Xilinx MicroBlaze architecture.
543
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
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
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
560Weimin Pan, David Faust and Jose E. Marchesi contributed support for
561the Linux kernel BPF virtual architecture.  This work was sponsored by
562Oracle.
563
564@node Sample Session
565@chapter A Sample @value{GDBN} Session
566
567You can use this manual at your leisure to read all about @value{GDBN}.
568However, a handful of commands are enough to get started using the
569debugger.  This chapter illustrates those commands.
570
571@iftex
572In this sample session, we emphasize user input like this: @b{input},
573to make it easier to pick out from the surrounding output.
574@end iftex
575
576@c FIXME: this example may not be appropriate for some configs, where
577@c FIXME...primary interest is in remote use.
578
579One of the preliminary versions of @sc{gnu} @code{m4} (a generic macro
580processor) exhibits the following bug: sometimes, when we change its
581quote strings from the default, the commands used to capture one macro
582definition within another stop working.  In the following short @code{m4}
583session, we define a macro @code{foo} which expands to @code{0000}; we
584then use the @code{m4} built-in @code{defn} to define @code{bar} as the
585same thing.  However, when we change the open quote string to
586@code{<QUOTE>} and the close quote string to @code{<UNQUOTE>}, the same
587procedure fails to define a new synonym @code{baz}:
588
589@smallexample
590$ @b{cd gnu/m4}
591$ @b{./m4}
592@b{define(foo,0000)}
593
594@b{foo}
5950000
596@b{define(bar,defn(`foo'))}
597
598@b{bar}
5990000
600@b{changequote(<QUOTE>,<UNQUOTE>)}
601
602@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
603@b{baz}
604@b{Ctrl-d}
605m4: End of input: 0: fatal error: EOF in string
606@end smallexample
607
608@noindent
609Let us use @value{GDBN} to try to see what is going on.
610
611@smallexample
612$ @b{@value{GDBP} m4}
613@c FIXME: this falsifies the exact text played out, to permit smallbook
614@c FIXME... format to come out better.
615@value{GDBN} is free software and you are welcome to distribute copies
616 of it under certain conditions; type "show copying" to see
617 the conditions.
618There is absolutely no warranty for @value{GDBN}; type "show warranty"
619 for details.
620
621@value{GDBN} @value{GDBVN}, Copyright 1999 Free Software Foundation, Inc...
622(@value{GDBP})
623@end smallexample
624
625@noindent
626@value{GDBN} reads only enough symbol data to know where to find the
627rest when needed; as a result, the first prompt comes up very quickly.
628We now tell @value{GDBN} to use a narrower display width than usual, so
629that examples fit in this manual.
630
631@smallexample
632(@value{GDBP}) @b{set width 70}
633@end smallexample
634
635@noindent
636We need to see how the @code{m4} built-in @code{changequote} works.
637Having looked at the source, we know the relevant subroutine is
638@code{m4_changequote}, so we set a breakpoint there with the @value{GDBN}
639@code{break} command.
640
641@smallexample
642(@value{GDBP}) @b{break m4_changequote}
643Breakpoint 1 at 0x62f4: file builtin.c, line 879.
644@end smallexample
645
646@noindent
647Using the @code{run} command, we start @code{m4} running under @value{GDBN}
648control; as long as control does not reach the @code{m4_changequote}
649subroutine, the program runs as usual:
650
651@smallexample
652(@value{GDBP}) @b{run}
653Starting program: /work/Editorial/gdb/gnu/m4/m4
654@b{define(foo,0000)}
655
656@b{foo}
6570000
658@end smallexample
659
660@noindent
661To trigger the breakpoint, we call @code{changequote}.  @value{GDBN}
662suspends execution of @code{m4}, displaying information about the
663context where it stops.
664
665@smallexample
666@b{changequote(<QUOTE>,<UNQUOTE>)}
667
668Breakpoint 1, m4_changequote (argc=3, argv=0x33c70)
669    at builtin.c:879
670879         if (bad_argc(TOKEN_DATA_TEXT(argv[0]),argc,1,3))
671@end smallexample
672
673@noindent
674Now we use the command @code{n} (@code{next}) to advance execution to
675the next line of the current function.
676
677@smallexample
678(@value{GDBP}) @b{n}
679882         set_quotes((argc >= 2) ? TOKEN_DATA_TEXT(argv[1])\
680 : nil,
681@end smallexample
682
683@noindent
684@code{set_quotes} looks like a promising subroutine.  We can go into it
685by using the command @code{s} (@code{step}) instead of @code{next}.
686@code{step} goes to the next line to be executed in @emph{any}
687subroutine, so it steps into @code{set_quotes}.
688
689@smallexample
690(@value{GDBP}) @b{s}
691set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
692    at input.c:530
693530         if (lquote != def_lquote)
694@end smallexample
695
696@noindent
697The display that shows the subroutine where @code{m4} is now
698suspended (and its arguments) is called a stack frame display.  It
699shows a summary of the stack.  We can use the @code{backtrace}
700command (which can also be spelled @code{bt}), to see where we are
701in the stack as a whole: the @code{backtrace} command displays a
702stack frame for each active subroutine.
703
704@smallexample
705(@value{GDBP}) @b{bt}
706#0  set_quotes (lq=0x34c78 "<QUOTE>", rq=0x34c88 "<UNQUOTE>")
707    at input.c:530
708#1  0x6344 in m4_changequote (argc=3, argv=0x33c70)
709    at builtin.c:882
710#2  0x8174 in expand_macro (sym=0x33320) at macro.c:242
711#3  0x7a88 in expand_token (obs=0x0, t=209696, td=0xf7fffa30)
712    at macro.c:71
713#4  0x79dc in expand_input () at macro.c:40
714#5  0x2930 in main (argc=0, argv=0xf7fffb20) at m4.c:195
715@end smallexample
716
717@noindent
718We step through a few more lines to see what happens.  The first two
719times, we can use @samp{s}; the next two times we use @code{n} to avoid
720falling into the @code{xstrdup} subroutine.
721
722@smallexample
723(@value{GDBP}) @b{s}
7240x3b5c  532         if (rquote != def_rquote)
725(@value{GDBP}) @b{s}
7260x3b80  535         lquote = (lq == nil || *lq == '\0') ?  \
727def_lquote : xstrdup(lq);
728(@value{GDBP}) @b{n}
729536         rquote = (rq == nil || *rq == '\0') ? def_rquote\
730 : xstrdup(rq);
731(@value{GDBP}) @b{n}
732538         len_lquote = strlen(rquote);
733@end smallexample
734
735@noindent
736The last line displayed looks a little odd; we can examine the variables
737@code{lquote} and @code{rquote} to see if they are in fact the new left
738and right quotes we specified.  We use the command @code{p}
739(@code{print}) to see their values.
740
741@smallexample
742(@value{GDBP}) @b{p lquote}
743$1 = 0x35d40 "<QUOTE>"
744(@value{GDBP}) @b{p rquote}
745$2 = 0x35d50 "<UNQUOTE>"
746@end smallexample
747
748@noindent
749@code{lquote} and @code{rquote} are indeed the new left and right quotes.
750To look at some context, we can display ten lines of source
751surrounding the current line with the @code{l} (@code{list}) command.
752
753@smallexample
754(@value{GDBP}) @b{l}
755533             xfree(rquote);
756534
757535         lquote = (lq == nil || *lq == '\0') ? def_lquote\
758 : xstrdup (lq);
759536         rquote = (rq == nil || *rq == '\0') ? def_rquote\
760 : xstrdup (rq);
761537
762538         len_lquote = strlen(rquote);
763539         len_rquote = strlen(lquote);
764540     @}
765541
766542     void
767@end smallexample
768
769@noindent
770Let us step past the two lines that set @code{len_lquote} and
771@code{len_rquote}, and then examine the values of those variables.
772
773@smallexample
774(@value{GDBP}) @b{n}
775539         len_rquote = strlen(lquote);
776(@value{GDBP}) @b{n}
777540     @}
778(@value{GDBP}) @b{p len_lquote}
779$3 = 9
780(@value{GDBP}) @b{p len_rquote}
781$4 = 7
782@end smallexample
783
784@noindent
785That certainly looks wrong, assuming @code{len_lquote} and
786@code{len_rquote} are meant to be the lengths of @code{lquote} and
787@code{rquote} respectively.  We can set them to better values using
788the @code{p} command, since it can print the value of
789any expression---and that expression can include subroutine calls and
790assignments.
791
792@smallexample
793(@value{GDBP}) @b{p len_lquote=strlen(lquote)}
794$5 = 7
795(@value{GDBP}) @b{p len_rquote=strlen(rquote)}
796$6 = 9
797@end smallexample
798
799@noindent
800Is that enough to fix the problem of using the new quotes with the
801@code{m4} built-in @code{defn}?  We can allow @code{m4} to continue
802executing with the @code{c} (@code{continue}) command, and then try the
803example that caused trouble initially:
804
805@smallexample
806(@value{GDBP}) @b{c}
807Continuing.
808
809@b{define(baz,defn(<QUOTE>foo<UNQUOTE>))}
810
811baz
8120000
813@end smallexample
814
815@noindent
816Success!  The new quotes now work just as well as the default ones.  The
817problem seems to have been just the two typos defining the wrong
818lengths.  We allow @code{m4} exit by giving it an EOF as input:
819
820@smallexample
821@b{Ctrl-d}
822Program exited normally.
823@end smallexample
824
825@noindent
826The message @samp{Program exited normally.} is from @value{GDBN}; it
827indicates @code{m4} has finished executing.  We can end our @value{GDBN}
828session with the @value{GDBN} @code{quit} command.
829
830@smallexample
831(@value{GDBP}) @b{quit}
832@end smallexample
833
834@node Invocation
835@chapter Getting In and Out of @value{GDBN}
836
837This chapter discusses how to start @value{GDBN}, and how to get out of it.
838The essentials are:
839@itemize @bullet
840@item
841type @samp{@value{GDBP}} to start @value{GDBN}.
842@item
843type @kbd{quit} or @kbd{Ctrl-d} to exit.
844@end itemize
845
846@menu
847* Invoking GDB::                How to start @value{GDBN}
848* Quitting GDB::                How to quit @value{GDBN}
849* Shell Commands::              How to use shell commands inside @value{GDBN}
850* Logging Output::              How to log @value{GDBN}'s output to a file
851@end menu
852
853@node Invoking GDB
854@section Invoking @value{GDBN}
855
856Invoke @value{GDBN} by running the program @code{@value{GDBP}}.  Once started,
857@value{GDBN} reads commands from the terminal until you tell it to exit.
858
859You can also run @code{@value{GDBP}} with a variety of arguments and options,
860to specify more of your debugging environment at the outset.
861
862The command-line options described here are designed
863to cover a variety of situations; in some environments, some of these
864options may effectively be unavailable.
865
866The most usual way to start @value{GDBN} is with one argument,
867specifying an executable program:
868
869@smallexample
870@value{GDBP} @var{program}
871@end smallexample
872
873@noindent
874You can also start with both an executable program and a core file
875specified:
876
877@smallexample
878@value{GDBP} @var{program} @var{core}
879@end smallexample
880
881You can, instead, specify a process ID as a second argument or use option
882@code{-p}, if you want to debug a running process:
883
884@smallexample
885@value{GDBP} @var{program} 1234
886@value{GDBP} -p 1234
887@end smallexample
888
889@noindent
890would attach @value{GDBN} to process @code{1234}.  With option @option{-p} you
891can omit the @var{program} filename.
892
893Taking advantage of the second command-line argument requires a fairly
894complete operating system; when you use @value{GDBN} as a remote
895debugger attached to a bare board, there may not be any notion of
896``process'', and there is often no way to get a core dump.  @value{GDBN}
897will warn you if it is unable to attach or to read core dumps.
898
899You can optionally have @code{@value{GDBP}} pass any arguments after the
900executable file to the inferior using @code{--args}.  This option stops
901option processing.
902@smallexample
903@value{GDBP} --args gcc -O2 -c foo.c
904@end smallexample
905This will cause @code{@value{GDBP}} to debug @code{gcc}, and to set
906@code{gcc}'s command-line arguments (@pxref{Arguments}) to @samp{-O2 -c foo.c}.
907
908You can run @code{@value{GDBP}} without printing the front material, which describes
909@value{GDBN}'s non-warranty, by specifying @code{--silent}
910(or @code{-q}/@code{--quiet}):
911
912@smallexample
913@value{GDBP} --silent
914@end smallexample
915
916@noindent
917You can further control how @value{GDBN} starts up by using command-line
918options.  @value{GDBN} itself can remind you of the options available.
919
920@noindent
921Type
922
923@smallexample
924@value{GDBP} -help
925@end smallexample
926
927@noindent
928to display all available options and briefly describe their use
929(@samp{@value{GDBP} -h} is a shorter equivalent).
930
931All options and command line arguments you give are processed
932in sequential order.  The order makes a difference when the
933@samp{-x} option is used.
934
935
936@menu
937* File Options::                Choosing files
938* Mode Options::                Choosing modes
939* Startup::                     What @value{GDBN} does during startup
940@end menu
941
942@node File Options
943@subsection Choosing Files
944
945When @value{GDBN} starts, it reads any arguments other than options as
946specifying an executable file and core file (or process ID).  This is
947the same as if the arguments were specified by the @samp{-se} and
948@samp{-c} (or @samp{-p}) options respectively.  (@value{GDBN} reads the
949first argument that does not have an associated option flag as
950equivalent to the @samp{-se} option followed by that argument; and the
951second argument that does not have an associated option flag, if any, as
952equivalent to the @samp{-c}/@samp{-p} option followed by that argument.)
953If the second argument begins with a decimal digit, @value{GDBN} will
954first attempt to attach to it as a process, and if that fails, attempt
955to open it as a corefile.  If you have a corefile whose name begins with
956a digit, you can prevent @value{GDBN} from treating it as a pid by
957prefixing it with @file{./}, e.g.@: @file{./12345}.
958
959If @value{GDBN} has not been configured to included core file support,
960such as for most embedded targets, then it will complain about a second
961argument and ignore it.
962
963Many options have both long and short forms; both are shown in the
964following list.  @value{GDBN} also recognizes the long forms if you truncate
965them, so long as enough of the option is present to be unambiguous.
966(If you prefer, you can flag option arguments with @samp{--} rather
967than @samp{-}, though we illustrate the more usual convention.)
968
969@c NOTE: the @cindex entries here use double dashes ON PURPOSE.  This
970@c way, both those who look for -foo and --foo in the index, will find
971@c it.
972
973@table @code
974@item -symbols @var{file}
975@itemx -s @var{file}
976@cindex @code{--symbols}
977@cindex @code{-s}
978Read symbol table from file @var{file}.
979
980@item -exec @var{file}
981@itemx -e @var{file}
982@cindex @code{--exec}
983@cindex @code{-e}
984Use file @var{file} as the executable file to execute when appropriate,
985and for examining pure data in conjunction with a core dump.
986
987@item -se @var{file}
988@cindex @code{--se}
989Read symbol table from file @var{file} and use it as the executable
990file.
991
992@item -core @var{file}
993@itemx -c @var{file}
994@cindex @code{--core}
995@cindex @code{-c}
996Use file @var{file} as a core dump to examine.
997
998@item -pid @var{number}
999@itemx -p @var{number}
1000@cindex @code{--pid}
1001@cindex @code{-p}
1002Connect to process ID @var{number}, as with the @code{attach} command.
1003
1004@item -command @var{file}
1005@itemx -x @var{file}
1006@cindex @code{--command}
1007@cindex @code{-x}
1008Execute commands from file @var{file}.  The contents of this file is
1009evaluated exactly as the @code{source} command would.
1010@xref{Command Files,, Command files}.
1011
1012@item -eval-command @var{command}
1013@itemx -ex @var{command}
1014@cindex @code{--eval-command}
1015@cindex @code{-ex}
1016Execute a single @value{GDBN} command.
1017
1018This option may be used multiple times to call multiple commands.  It may
1019also be interleaved with @samp{-command} as required.
1020
1021@smallexample
1022@value{GDBP} -ex 'target sim' -ex 'load' \
1023   -x setbreakpoints -ex 'run' a.out
1024@end smallexample
1025
1026@item -init-command @var{file}
1027@itemx -ix @var{file}
1028@cindex @code{--init-command}
1029@cindex @code{-ix}
1030Execute commands from file @var{file} before loading the inferior (but
1031after loading gdbinit files).
1032@xref{Startup}.
1033
1034@item -init-eval-command @var{command}
1035@itemx -iex @var{command}
1036@cindex @code{--init-eval-command}
1037@cindex @code{-iex}
1038Execute a single @value{GDBN} command before loading the inferior (but
1039after loading gdbinit files).
1040@xref{Startup}.
1041
1042@item -directory @var{directory}
1043@itemx -d @var{directory}
1044@cindex @code{--directory}
1045@cindex @code{-d}
1046Add @var{directory} to the path to search for source and script files.
1047
1048@item -r
1049@itemx -readnow
1050@cindex @code{--readnow}
1051@cindex @code{-r}
1052Read each symbol file's entire symbol table immediately, rather than
1053the default, which is to read it incrementally as it is needed.
1054This makes startup slower, but makes future operations faster.
1055
1056@item --readnever
1057@anchor{--readnever}
1058@cindex @code{--readnever}, command-line option
1059Do not read each symbol file's symbolic debug information.  This makes
1060startup faster but at the expense of not being able to perform
1061symbolic debugging.  DWARF unwind information is also not read,
1062meaning backtraces may become incomplete or inaccurate.  One use of
1063this is when a user simply wants to do the following sequence: attach,
1064dump core, detach.  Loading the debugging information in this case is
1065an unnecessary cause of delay.
1066@end table
1067
1068@node Mode Options
1069@subsection Choosing Modes
1070
1071You can run @value{GDBN} in various alternative modes---for example, in
1072batch mode or quiet mode.
1073
1074@table @code
1075@anchor{-nx}
1076@item -nx
1077@itemx -n
1078@cindex @code{--nx}
1079@cindex @code{-n}
1080Do not execute commands found in any initialization file.
1081There are three init files, loaded in the following order:
1082
1083@table @code
1084@item @file{system.gdbinit}
1085This is the system-wide init file.
1086Its location is specified with the @code{--with-system-gdbinit}
1087configure option (@pxref{System-wide configuration}).
1088It is loaded first when @value{GDBN} starts, before command line options
1089have been processed.
1090@item @file{system.gdbinit.d}
1091This is the system-wide init directory.
1092Its location is specified with the @code{--with-system-gdbinit-dir}
1093configure option (@pxref{System-wide configuration}).
1094Files in this directory are loaded in alphabetical order immediately after
1095system.gdbinit (if enabled) when @value{GDBN} starts, before command line
1096options have been processed.  Files need to have a recognized scripting
1097language extension (@file{.py}/@file{.scm}) or be named with a @file{.gdb}
1098extension to be interpreted as regular @value{GDBN} commands.  @value{GDBN}
1099will not recurse into any subdirectories of this directory.
1100@item @file{~/.gdbinit}
1101This is the init file in your home directory.
1102It is loaded next, after @file{system.gdbinit}, and before
1103command options have been processed.
1104@item @file{./.gdbinit}
1105This is the init file in the current directory.
1106It is loaded last, after command line options other than @code{-x} and
1107@code{-ex} have been processed.  Command line options @code{-x} and
1108@code{-ex} are processed last, after @file{./.gdbinit} has been loaded.
1109@end table
1110
1111For further documentation on startup processing, @xref{Startup}.
1112For documentation on how to write command files,
1113@xref{Command Files,,Command Files}.
1114
1115@anchor{-nh}
1116@item -nh
1117@cindex @code{--nh}
1118Do not execute commands found in @file{~/.gdbinit}, the init file
1119in your home directory.
1120@xref{Startup}.
1121
1122@item -quiet
1123@itemx -silent
1124@itemx -q
1125@cindex @code{--quiet}
1126@cindex @code{--silent}
1127@cindex @code{-q}
1128``Quiet''.  Do not print the introductory and copyright messages.  These
1129messages are also suppressed in batch mode.
1130
1131@item -batch
1132@cindex @code{--batch}
1133Run in batch mode.  Exit with status @code{0} after processing all the
1134command files specified with @samp{-x} (and all commands from
1135initialization files, if not inhibited with @samp{-n}).  Exit with
1136nonzero status if an error occurs in executing the @value{GDBN} commands
1137in the command files.  Batch mode also disables pagination, sets unlimited
1138terminal width and height @pxref{Screen Size}, and acts as if @kbd{set confirm
1139off} were in effect (@pxref{Messages/Warnings}).
1140
1141Batch mode may be useful for running @value{GDBN} as a filter, for
1142example to download and run a program on another computer; in order to
1143make this more useful, the message
1144
1145@smallexample
1146Program exited normally.
1147@end smallexample
1148
1149@noindent
1150(which is ordinarily issued whenever a program running under
1151@value{GDBN} control terminates) is not issued when running in batch
1152mode.
1153
1154@item -batch-silent
1155@cindex @code{--batch-silent}
1156Run in batch mode exactly like @samp{-batch}, but totally silently.  All
1157@value{GDBN} output to @code{stdout} is prevented (@code{stderr} is
1158unaffected).  This is much quieter than @samp{-silent} and would be useless
1159for an interactive session.
1160
1161This is particularly useful when using targets that give @samp{Loading section}
1162messages, for example.
1163
1164Note that targets that give their output via @value{GDBN}, as opposed to
1165writing directly to @code{stdout}, will also be made silent.
1166
1167@item -return-child-result
1168@cindex @code{--return-child-result}
1169The return code from @value{GDBN} will be the return code from the child
1170process (the process being debugged), with the following exceptions:
1171
1172@itemize @bullet
1173@item
1174@value{GDBN} exits abnormally.  E.g., due to an incorrect argument or an
1175internal error.  In this case the exit code is the same as it would have been
1176without @samp{-return-child-result}.
1177@item
1178The user quits with an explicit value.  E.g., @samp{quit 1}.
1179@item
1180The child process never runs, or is not allowed to terminate, in which case
1181the exit code will be -1.
1182@end itemize
1183
1184This option is useful in conjunction with @samp{-batch} or @samp{-batch-silent},
1185when @value{GDBN} is being used as a remote program loader or simulator
1186interface.
1187
1188@item -nowindows
1189@itemx -nw
1190@cindex @code{--nowindows}
1191@cindex @code{-nw}
1192``No windows''.  If @value{GDBN} comes with a graphical user interface
1193(GUI) built in, then this option tells @value{GDBN} to only use the command-line
1194interface.  If no GUI is available, this option has no effect.
1195
1196@item -windows
1197@itemx -w
1198@cindex @code{--windows}
1199@cindex @code{-w}
1200If @value{GDBN} includes a GUI, then this option requires it to be
1201used if possible.
1202
1203@item -cd @var{directory}
1204@cindex @code{--cd}
1205Run @value{GDBN} using @var{directory} as its working directory,
1206instead of the current directory.
1207
1208@item -data-directory @var{directory}
1209@itemx -D @var{directory}
1210@cindex @code{--data-directory}
1211@cindex @code{-D}
1212Run @value{GDBN} using @var{directory} as its data directory.
1213The data directory is where @value{GDBN} searches for its
1214auxiliary files.  @xref{Data Files}.
1215
1216@item -fullname
1217@itemx -f
1218@cindex @code{--fullname}
1219@cindex @code{-f}
1220@sc{gnu} Emacs sets this option when it runs @value{GDBN} as a
1221subprocess.  It tells @value{GDBN} to output the full file name and line
1222number in a standard, recognizable fashion each time a stack frame is
1223displayed (which includes each time your program stops).  This
1224recognizable format looks like two @samp{\032} characters, followed by
1225the file name, line number and character position separated by colons,
1226and a newline.  The Emacs-to-@value{GDBN} interface program uses the two
1227@samp{\032} characters as a signal to display the source code for the
1228frame.
1229
1230@item -annotate @var{level}
1231@cindex @code{--annotate}
1232This option sets the @dfn{annotation level} inside @value{GDBN}.  Its
1233effect is identical to using @samp{set annotate @var{level}}
1234(@pxref{Annotations}).  The annotation @var{level} controls how much
1235information @value{GDBN} prints together with its prompt, values of
1236expressions, source lines, and other types of output.  Level 0 is the
1237normal, level 1 is for use when @value{GDBN} is run as a subprocess of
1238@sc{gnu} Emacs, level 3 is the maximum annotation suitable for programs
1239that control @value{GDBN}, and level 2 has been deprecated.
1240
1241The annotation mechanism has largely been superseded by @sc{gdb/mi}
1242(@pxref{GDB/MI}).
1243
1244@item --args
1245@cindex @code{--args}
1246Change interpretation of command line so that arguments following the
1247executable file are passed as command line arguments to the inferior.
1248This option stops option processing.
1249
1250@item -baud @var{bps}
1251@itemx -b @var{bps}
1252@cindex @code{--baud}
1253@cindex @code{-b}
1254Set the line speed (baud rate or bits per second) of any serial
1255interface used by @value{GDBN} for remote debugging.
1256
1257@item -l @var{timeout}
1258@cindex @code{-l}
1259Set the timeout (in seconds) of any communication used by @value{GDBN}
1260for remote debugging.
1261
1262@item -tty @var{device}
1263@itemx -t @var{device}
1264@cindex @code{--tty}
1265@cindex @code{-t}
1266Run using @var{device} for your program's standard input and output.
1267@c FIXME: kingdon thinks there is more to -tty.  Investigate.
1268
1269@c resolve the situation of these eventually
1270@item -tui
1271@cindex @code{--tui}
1272Activate the @dfn{Text User Interface} when starting.  The Text User
1273Interface manages several text windows on the terminal, showing
1274source, assembly, registers and @value{GDBN} command outputs
1275(@pxref{TUI, ,@value{GDBN} Text User Interface}).  Do not use this
1276option if you run @value{GDBN} from Emacs (@pxref{Emacs, ,
1277Using @value{GDBN} under @sc{gnu} Emacs}).
1278
1279@item -interpreter @var{interp}
1280@cindex @code{--interpreter}
1281Use the interpreter @var{interp} for interface with the controlling
1282program or device.  This option is meant to be set by programs which
1283communicate with @value{GDBN} using it as a back end.
1284@xref{Interpreters, , Command Interpreters}.
1285
1286@samp{--interpreter=mi} (or @samp{--interpreter=mi3}) causes
1287@value{GDBN} to use the @dfn{@sc{gdb/mi} interface} version 3 (@pxref{GDB/MI, ,
1288The @sc{gdb/mi} Interface}) included since @value{GDBN} version 9.1.  @sc{gdb/mi}
1289version 2 (@code{mi2}), included in @value{GDBN} 6.0 and version 1 (@code{mi1}),
1290included in @value{GDBN} 5.3, are also available.  Earlier @sc{gdb/mi}
1291interfaces are no longer supported.
1292
1293@item -write
1294@cindex @code{--write}
1295Open the executable and core files for both reading and writing.  This
1296is equivalent to the @samp{set write on} command inside @value{GDBN}
1297(@pxref{Patching}).
1298
1299@item -statistics
1300@cindex @code{--statistics}
1301This option causes @value{GDBN} to print statistics about time and
1302memory usage after it completes each command and returns to the prompt.
1303
1304@item -version
1305@cindex @code{--version}
1306This option causes @value{GDBN} to print its version number and
1307no-warranty blurb, and exit.
1308
1309@item -configuration
1310@cindex @code{--configuration}
1311This option causes @value{GDBN} to print details about its build-time
1312configuration parameters, and then exit.  These details can be
1313important when reporting @value{GDBN} bugs (@pxref{GDB Bugs}).
1314
1315@end table
1316
1317@node Startup
1318@subsection What @value{GDBN} Does During Startup
1319@cindex @value{GDBN} startup
1320
1321Here's the description of what @value{GDBN} does during session startup:
1322
1323@enumerate
1324@item
1325Sets up the command interpreter as specified by the command line
1326(@pxref{Mode Options, interpreter}).
1327
1328@item
1329@cindex init file
1330Reads the system-wide @dfn{init file} (if @option{--with-system-gdbinit} was
1331used when building @value{GDBN}; @pxref{System-wide configuration,
1332 ,System-wide configuration and settings}) and the files in the system-wide
1333gdbinit directory (if @option{--with-system-gdbinit-dir} was used) and executes
1334all the commands in those files.  The files need to be named with a @file{.gdb}
1335extension to be interpreted as @value{GDBN} commands, or they can be written
1336in a supported scripting language with an appropriate file extension.
1337
1338@anchor{Home Directory Init File}
1339@item
1340Reads the init file (if any) in your home directory@footnote{On
1341DOS/Windows systems, the home directory is the one pointed to by the
1342@code{HOME} environment variable.} and executes all the commands in
1343that file.
1344
1345@anchor{Option -init-eval-command}
1346@item
1347Executes commands and command files specified by the @samp{-iex} and
1348@samp{-ix} options in their specified order.  Usually you should use the
1349@samp{-ex} and @samp{-x} options instead, but this way you can apply
1350settings before @value{GDBN} init files get executed and before inferior
1351gets loaded.
1352
1353@item
1354Processes command line options and operands.
1355
1356@anchor{Init File in the Current Directory during Startup}
1357@item
1358Reads and executes the commands from init file (if any) in the current
1359working directory as long as @samp{set auto-load local-gdbinit} is set to
1360@samp{on} (@pxref{Init File in the Current Directory}).
1361This is only done if the current directory is
1362different from your home directory.  Thus, you can have more than one
1363init file, one generic in your home directory, and another, specific
1364to the program you are debugging, in the directory where you invoke
1365@value{GDBN}.
1366
1367@item
1368If the command line specified a program to debug, or a process to
1369attach to, or a core file, @value{GDBN} loads any auto-loaded
1370scripts provided for the program or for its loaded shared libraries.
1371@xref{Auto-loading}.
1372
1373If you wish to disable the auto-loading during startup,
1374you must do something like the following:
1375
1376@smallexample
1377$ gdb -iex "set auto-load python-scripts off" myprogram
1378@end smallexample
1379
1380Option @samp{-ex} does not work because the auto-loading is then turned
1381off too late.
1382
1383@item
1384Executes commands and command files specified by the @samp{-ex} and
1385@samp{-x} options in their specified order.  @xref{Command Files}, for
1386more details about @value{GDBN} command files.
1387
1388@item
1389Reads the command history recorded in the @dfn{history file}.
1390@xref{Command History}, for more details about the command history and the
1391files where @value{GDBN} records it.
1392@end enumerate
1393
1394Init files use the same syntax as @dfn{command files} (@pxref{Command
1395Files}) and are processed by @value{GDBN} in the same way.  The init
1396file in your home directory can set options (such as @samp{set
1397complaints}) that affect subsequent processing of command line options
1398and operands.  Init files are not executed if you use the @samp{-nx}
1399option (@pxref{Mode Options, ,Choosing Modes}).
1400
1401To display the list of init files loaded by gdb at startup, you
1402can use @kbd{gdb --help}.
1403
1404@cindex init file name
1405@cindex @file{.gdbinit}
1406@cindex @file{gdb.ini}
1407The @value{GDBN} init files are normally called @file{.gdbinit}.
1408The DJGPP port of @value{GDBN} uses the name @file{gdb.ini}, due to
1409the limitations of file names imposed by DOS filesystems.  The Windows
1410port of @value{GDBN} uses the standard name, but if it finds a
1411@file{gdb.ini} file in your home directory, it warns you about that
1412and suggests to rename the file to the standard name.
1413
1414
1415@node Quitting GDB
1416@section Quitting @value{GDBN}
1417@cindex exiting @value{GDBN}
1418@cindex leaving @value{GDBN}
1419
1420@table @code
1421@kindex quit @r{[}@var{expression}@r{]}
1422@kindex q @r{(@code{quit})}
1423@item quit @r{[}@var{expression}@r{]}
1424@itemx q
1425To exit @value{GDBN}, use the @code{quit} command (abbreviated
1426@code{q}), or type an end-of-file character (usually @kbd{Ctrl-d}).  If you
1427do not supply @var{expression}, @value{GDBN} will terminate normally;
1428otherwise it will terminate using the result of @var{expression} as the
1429error code.
1430@end table
1431
1432@cindex interrupt
1433An interrupt (often @kbd{Ctrl-c}) does not exit from @value{GDBN}, but rather
1434terminates the action of any @value{GDBN} command that is in progress and
1435returns to @value{GDBN} command level.  It is safe to type the interrupt
1436character at any time because @value{GDBN} does not allow it to take effect
1437until a time when it is safe.
1438
1439If you have been using @value{GDBN} to control an attached process or
1440device, you can release it with the @code{detach} command
1441(@pxref{Attach, ,Debugging an Already-running Process}).
1442
1443@node Shell Commands
1444@section Shell Commands
1445
1446If you need to execute occasional shell commands during your
1447debugging session, there is no need to leave or suspend @value{GDBN}; you can
1448just use the @code{shell} command.
1449
1450@table @code
1451@kindex shell
1452@kindex !
1453@cindex shell escape
1454@item shell @var{command-string}
1455@itemx !@var{command-string}
1456Invoke a standard shell to execute @var{command-string}.
1457Note that no space is needed between @code{!} and @var{command-string}.
1458On GNU and Unix systems, the environment variable @code{SHELL}, if it
1459exists, determines which shell to run.  Otherwise @value{GDBN} uses
1460the default shell (@file{/bin/sh} on GNU and Unix systems,
1461@file{cmd.exe} on MS-Windows, @file{COMMAND.COM} on MS-DOS, etc.).
1462@end table
1463
1464The utility @code{make} is often needed in development environments.
1465You do not have to use the @code{shell} command for this purpose in
1466@value{GDBN}:
1467
1468@table @code
1469@kindex make
1470@cindex calling make
1471@item make @var{make-args}
1472Execute the @code{make} program with the specified
1473arguments.  This is equivalent to @samp{shell make @var{make-args}}.
1474@end table
1475
1476@table @code
1477@kindex pipe
1478@kindex |
1479@cindex send the output of a gdb command to a shell command
1480@anchor{pipe}
1481@item pipe [@var{command}] | @var{shell_command}
1482@itemx | [@var{command}] | @var{shell_command}
1483@itemx pipe -d @var{delim} @var{command} @var{delim} @var{shell_command}
1484@itemx | -d @var{delim} @var{command} @var{delim} @var{shell_command}
1485Executes @var{command} and sends its output to @var{shell_command}.
1486Note that no space is needed around @code{|}.
1487If no @var{command} is provided, the last command executed is repeated.
1488
1489In case the @var{command} contains a @code{|}, the option @code{-d @var{delim}}
1490can be used to specify an alternate delimiter string @var{delim} that separates
1491the @var{command} from the @var{shell_command}.
1492
1493Example:
1494@smallexample
1495@group
1496(gdb) p var
1497$1 = @{
1498  black = 144,
1499  red = 233,
1500  green = 377,
1501  blue = 610,
1502  white = 987
1503@}
1504@end group
1505@group
1506(gdb) pipe p var|wc
1507      7      19      80
1508(gdb) |p var|wc -l
15097
1510@end group
1511@group
1512(gdb) p /x var
1513$4 = @{
1514  black = 0x90,
1515  red = 0xe9,
1516  green = 0x179,
1517  blue = 0x262,
1518  white = 0x3db
1519@}
1520(gdb) ||grep red
1521  red => 0xe9,
1522@end group
1523@group
1524(gdb) | -d ! echo this contains a | char\n ! sed -e 's/|/PIPE/'
1525this contains a PIPE char
1526(gdb) | -d xxx echo this contains a | char!\n xxx sed -e 's/|/PIPE/'
1527this contains a PIPE char!
1528(gdb)
1529@end group
1530@end smallexample
1531@end table
1532
1533The convenience variables @code{$_shell_exitcode} and @code{$_shell_exitsignal}
1534can be used to examine the exit status of the last shell command launched
1535by @code{shell}, @code{make}, @code{pipe} and @code{|}.
1536@xref{Convenience Vars,, Convenience Variables}.
1537
1538@node Logging Output
1539@section Logging Output
1540@cindex logging @value{GDBN} output
1541@cindex save @value{GDBN} output to a file
1542
1543You may want to save the output of @value{GDBN} commands to a file.
1544There are several commands to control @value{GDBN}'s logging.
1545
1546@table @code
1547@kindex set logging
1548@item set logging on
1549Enable logging.
1550@item set logging off
1551Disable logging.
1552@cindex logging file name
1553@item set logging file @var{file}
1554Change the name of the current logfile.  The default logfile is @file{gdb.txt}.
1555@item set logging overwrite [on|off]
1556By default, @value{GDBN} will append to the logfile.  Set @code{overwrite} if
1557you want @code{set logging on} to overwrite the logfile instead.
1558@item set logging redirect [on|off]
1559By default, @value{GDBN} output will go to both the terminal and the logfile.
1560Set @code{redirect} if you want output to go only to the log file.
1561@item set logging debugredirect [on|off]
1562By default, @value{GDBN} debug output will go to both the terminal and the logfile.
1563Set @code{debugredirect} if you want debug output to go only to the log file.
1564@kindex show logging
1565@item show logging
1566Show the current values of the logging settings.
1567@end table
1568
1569You can also redirect the output of a @value{GDBN} command to a
1570shell command.  @xref{pipe}.
1571@node Commands
1572@chapter @value{GDBN} Commands
1573
1574You can abbreviate a @value{GDBN} command to the first few letters of the command
1575name, if that abbreviation is unambiguous; and you can repeat certain
1576@value{GDBN} commands by typing just @key{RET}.  You can also use the @key{TAB}
1577key to get @value{GDBN} to fill out the rest of a word in a command (or to
1578show you the alternatives available, if there is more than one possibility).
1579
1580@menu
1581* Command Syntax::              How to give commands to @value{GDBN}
1582* Command Settings::            How to change default behavior of commands
1583* Completion::                  Command completion
1584* Command Options::             Command options
1585* Command aliases default args::        Automatically prepend default arguments to user-defined aliases
1586* Help::                        How to ask @value{GDBN} for help
1587@end menu
1588
1589@node Command Syntax
1590@section Command Syntax
1591
1592A @value{GDBN} command is a single line of input.  There is no limit on
1593how long it can be.  It starts with a command name, which is followed by
1594arguments whose meaning depends on the command name.  For example, the
1595command @code{step} accepts an argument which is the number of times to
1596step, as in @samp{step 5}.  You can also use the @code{step} command
1597with no arguments.  Some commands do not allow any arguments.
1598
1599@cindex abbreviation
1600@value{GDBN} command names may always be truncated if that abbreviation is
1601unambiguous.  Other possible command abbreviations are listed in the
1602documentation for individual commands.  In some cases, even ambiguous
1603abbreviations are allowed; for example, @code{s} is specially defined as
1604equivalent to @code{step} even though there are other commands whose
1605names start with @code{s}.  You can test abbreviations by using them as
1606arguments to the @code{help} command.
1607
1608@cindex repeating commands
1609@kindex RET @r{(repeat last command)}
1610A blank line as input to @value{GDBN} (typing just @key{RET}) means to
1611repeat the previous command.  Certain commands (for example, @code{run})
1612will not repeat this way; these are commands whose unintentional
1613repetition might cause trouble and which you are unlikely to want to
1614repeat.  User-defined commands can disable this feature; see
1615@ref{Define, dont-repeat}.
1616
1617The @code{list} and @code{x} commands, when you repeat them with
1618@key{RET}, construct new arguments rather than repeating
1619exactly as typed.  This permits easy scanning of source or memory.
1620
1621@value{GDBN} can also use @key{RET} in another way: to partition lengthy
1622output, in a way similar to the common utility @code{more}
1623(@pxref{Screen Size,,Screen Size}).  Since it is easy to press one
1624@key{RET} too many in this situation, @value{GDBN} disables command
1625repetition after any command that generates this sort of display.
1626
1627@kindex # @r{(a comment)}
1628@cindex comment
1629Any text from a @kbd{#} to the end of the line is a comment; it does
1630nothing.  This is useful mainly in command files (@pxref{Command
1631Files,,Command Files}).
1632
1633@cindex repeating command sequences
1634@kindex Ctrl-o @r{(operate-and-get-next)}
1635The @kbd{Ctrl-o} binding is useful for repeating a complex sequence of
1636commands.  This command accepts the current line, like @key{RET}, and
1637then fetches the next line relative to the current line from the history
1638for editing.
1639
1640
1641@node Command Settings
1642@section Command Settings
1643@cindex default behavior of commands, changing
1644@cindex default settings, changing
1645
1646Many commands change their behavior according to command-specific
1647variables or settings.  These settings can be changed with the
1648@code{set} subcommands.  For example, the @code{print} command
1649(@pxref{Data, ,Examining Data}) prints arrays differently depending on
1650settings changeable with the commands @code{set print elements
1651NUMBER-OF-ELEMENTS} and @code{set print array-indexes}, among others.
1652
1653You can change these settings to your preference in the gdbinit files
1654loaded at @value{GDBN} startup.  @xref{Startup}.
1655
1656The settings can also be changed interactively during the debugging
1657session.  For example, to change the limit of array elements to print,
1658you can do the following:
1659@smallexample
1660(@value{GDBN}) set print elements 10
1661(@value{GDBN}) print some_array
1662$1 = @{0, 10, 20, 30, 40, 50, 60, 70, 80, 90...@}
1663@end smallexample
1664
1665The above @code{set print elements 10} command changes the number of
1666elements to print from the default of 200 to 10.  If you only intend
1667this limit of 10 to be used for printing @code{some_array}, then you
1668must restore the limit back to 200, with @code{set print elements
1669200}.
1670
1671Some commands allow overriding settings with command options.  For
1672example, the @code{print} command supports a number of options that
1673allow overriding relevant global print settings as set by @code{set
1674print} subcommands.  @xref{print options}.  The example above could be
1675rewritten as:
1676@smallexample
1677(@value{GDBN}) print -elements 10 -- some_array
1678$1 = @{0, 10, 20, 30, 40, 50, 60, 70, 80, 90...@}
1679@end smallexample
1680
1681Alternatively, you can use the @code{with} command to change a setting
1682temporarily, for the duration of a command invocation.
1683
1684@table @code
1685@kindex with command
1686@kindex w @r{(@code{with})}
1687@cindex settings
1688@cindex temporarily change settings
1689@item with @var{setting} [@var{value}] [-- @var{command}]
1690@itemx w @var{setting} [@var{value}] [-- @var{command}]
1691Temporarily set @var{setting} to @var{value} for the duration of
1692@var{command}.
1693
1694@var{setting} is any setting you can change with the @code{set}
1695subcommands.  @var{value} is the value to assign to @code{setting}
1696while running @code{command}.
1697
1698If no @var{command} is provided, the last command executed is
1699repeated.
1700
1701If a @var{command} is provided, it must be preceded by a double dash
1702(@code{--}) separator.  This is required because some settings accept
1703free-form arguments, such as expressions or filenames.
1704
1705For example, the command
1706@smallexample
1707(@value{GDBN}) with print array on -- print some_array
1708@end smallexample
1709@noindent
1710is equivalent to the following 3 commands:
1711@smallexample
1712(@value{GDBN}) set print array on
1713(@value{GDBN}) print some_array
1714(@value{GDBN}) set print array off
1715@end smallexample
1716
1717The @code{with} command is particularly useful when you want to
1718override a setting while running user-defined commands, or commands
1719defined in Python or Guile.  @xref{Extending GDB,, Extending GDB}.
1720
1721@smallexample
1722(@value{GDBN}) with print pretty on -- my_complex_command
1723@end smallexample
1724
1725To change several settings for the same command, you can nest
1726@code{with} commands.  For example, @code{with language ada -- with
1727print elements 10} temporarily changes the language to Ada and sets a
1728limit of 10 elements to print for arrays and strings.
1729
1730@end table
1731
1732@node Completion
1733@section Command Completion
1734
1735@cindex completion
1736@cindex word completion
1737@value{GDBN} can fill in the rest of a word in a command for you, if there is
1738only one possibility; it can also show you what the valid possibilities
1739are for the next word in a command, at any time.  This works for @value{GDBN}
1740commands, @value{GDBN} subcommands, command options, and the names of symbols
1741in your program.
1742
1743Press the @key{TAB} key whenever you want @value{GDBN} to fill out the rest
1744of a word.  If there is only one possibility, @value{GDBN} fills in the
1745word, and waits for you to finish the command (or press @key{RET} to
1746enter it).  For example, if you type
1747
1748@c FIXME "@key" does not distinguish its argument sufficiently to permit
1749@c complete accuracy in these examples; space introduced for clarity.
1750@c If texinfo enhancements make it unnecessary, it would be nice to
1751@c replace " @key" by "@key" in the following...
1752@smallexample
1753(@value{GDBP}) info bre @key{TAB}
1754@end smallexample
1755
1756@noindent
1757@value{GDBN} fills in the rest of the word @samp{breakpoints}, since that is
1758the only @code{info} subcommand beginning with @samp{bre}:
1759
1760@smallexample
1761(@value{GDBP}) info breakpoints
1762@end smallexample
1763
1764@noindent
1765You can either press @key{RET} at this point, to run the @code{info
1766breakpoints} command, or backspace and enter something else, if
1767@samp{breakpoints} does not look like the command you expected.  (If you
1768were sure you wanted @code{info breakpoints} in the first place, you
1769might as well just type @key{RET} immediately after @samp{info bre},
1770to exploit command abbreviations rather than command completion).
1771
1772If there is more than one possibility for the next word when you press
1773@key{TAB}, @value{GDBN} sounds a bell.  You can either supply more
1774characters and try again, or just press @key{TAB} a second time;
1775@value{GDBN} displays all the possible completions for that word.  For
1776example, you might want to set a breakpoint on a subroutine whose name
1777begins with @samp{make_}, but when you type @kbd{b make_@key{TAB}} @value{GDBN}
1778just sounds the bell.  Typing @key{TAB} again displays all the
1779function names in your program that begin with those characters, for
1780example:
1781
1782@smallexample
1783(@value{GDBP}) b make_ @key{TAB}
1784@exdent @value{GDBN} sounds bell; press @key{TAB} again, to see:
1785make_a_section_from_file     make_environ
1786make_abs_section             make_function_type
1787make_blockvector             make_pointer_type
1788make_cleanup                 make_reference_type
1789make_command                 make_symbol_completion_list
1790(@value{GDBP}) b make_
1791@end smallexample
1792
1793@noindent
1794After displaying the available possibilities, @value{GDBN} copies your
1795partial input (@samp{b make_} in the example) so you can finish the
1796command.
1797
1798If you just want to see the list of alternatives in the first place, you
1799can press @kbd{M-?} rather than pressing @key{TAB} twice.  @kbd{M-?}
1800means @kbd{@key{META} ?}.  You can type this either by holding down a
1801key designated as the @key{META} shift on your keyboard (if there is
1802one) while typing @kbd{?}, or as @key{ESC} followed by @kbd{?}.
1803
1804If the number of possible completions is large, @value{GDBN} will
1805print as much of the list as it has collected, as well as a message
1806indicating that the list may be truncated.
1807
1808@smallexample
1809(@value{GDBP}) b m@key{TAB}@key{TAB}
1810main
1811<... the rest of the possible completions ...>
1812*** List may be truncated, max-completions reached. ***
1813(@value{GDBP}) b m
1814@end smallexample
1815
1816@noindent
1817This behavior can be controlled with the following commands:
1818
1819@table @code
1820@kindex set max-completions
1821@item set max-completions @var{limit}
1822@itemx set max-completions unlimited
1823Set the maximum number of completion candidates.  @value{GDBN} will
1824stop looking for more completions once it collects this many candidates.
1825This is useful when completing on things like function names as collecting
1826all the possible candidates can be time consuming.
1827The default value is 200.  A value of zero disables tab-completion.
1828Note that setting either no limit or a very large limit can make
1829completion slow.
1830@kindex show max-completions
1831@item show max-completions
1832Show the maximum number of candidates that @value{GDBN} will collect and show
1833during completion.
1834@end table
1835
1836@cindex quotes in commands
1837@cindex completion of quoted strings
1838Sometimes the string you need, while logically a ``word'', may contain
1839parentheses or other characters that @value{GDBN} normally excludes from
1840its notion of a word.  To permit word completion to work in this
1841situation, you may enclose words in @code{'} (single quote marks) in
1842@value{GDBN} commands.
1843
1844A likely situation where you might need this is in typing an
1845expression that involves a C@t{++} symbol name with template
1846parameters.  This is because when completing expressions, GDB treats
1847the @samp{<} character as word delimiter, assuming that it's the
1848less-than comparison operator (@pxref{C Operators, , C and C@t{++}
1849Operators}).
1850
1851For example, when you want to call a C@t{++} template function
1852interactively using the @code{print} or @code{call} commands, you may
1853need to distinguish whether you mean the version of @code{name} that
1854was specialized for @code{int}, @code{name<int>()}, or the version
1855that was specialized for @code{float}, @code{name<float>()}.  To use
1856the word-completion facilities in this situation, type a single quote
1857@code{'} at the beginning of the function name.  This alerts
1858@value{GDBN} that it may need to consider more information than usual
1859when you press @key{TAB} or @kbd{M-?} to request word completion:
1860
1861@smallexample
1862(@value{GDBP}) p 'func< @kbd{M-?}
1863func<int>()    func<float>()
1864(@value{GDBP}) p 'func<
1865@end smallexample
1866
1867When setting breakpoints however (@pxref{Specify Location}), you don't
1868usually need to type a quote before the function name, because
1869@value{GDBN} understands that you want to set a breakpoint on a
1870function:
1871
1872@smallexample
1873(@value{GDBP}) b func< @kbd{M-?}
1874func<int>()    func<float>()
1875(@value{GDBP}) b func<
1876@end smallexample
1877
1878This is true even in the case of typing the name of C@t{++} overloaded
1879functions (multiple definitions of the same function, distinguished by
1880argument type).  For example, when you want to set a breakpoint you
1881don't need to distinguish whether you mean the version of @code{name}
1882that takes an @code{int} parameter, @code{name(int)}, or the version
1883that takes a @code{float} parameter, @code{name(float)}.
1884
1885@smallexample
1886(@value{GDBP}) b bubble( @kbd{M-?}
1887bubble(int)    bubble(double)
1888(@value{GDBP}) b bubble(dou @kbd{M-?}
1889bubble(double)
1890@end smallexample
1891
1892See @ref{quoting names} for a description of other scenarios that
1893require quoting.
1894
1895For more information about overloaded functions, see @ref{C Plus Plus
1896Expressions, ,C@t{++} Expressions}.  You can use the command @code{set
1897overload-resolution off} to disable overload resolution;
1898see @ref{Debugging C Plus Plus, ,@value{GDBN} Features for C@t{++}}.
1899
1900@cindex completion of structure field names
1901@cindex structure field name completion
1902@cindex completion of union field names
1903@cindex union field name completion
1904When completing in an expression which looks up a field in a
1905structure, @value{GDBN} also tries@footnote{The completer can be
1906confused by certain kinds of invalid expressions.  Also, it only
1907examines the static type of the expression, not the dynamic type.} to
1908limit completions to the field names available in the type of the
1909left-hand-side:
1910
1911@smallexample
1912(@value{GDBP}) p gdb_stdout.@kbd{M-?}
1913magic                to_fputs             to_rewind
1914to_data              to_isatty            to_write
1915to_delete            to_put               to_write_async_safe
1916to_flush             to_read
1917@end smallexample
1918
1919@noindent
1920This is because the @code{gdb_stdout} is a variable of the type
1921@code{struct ui_file} that is defined in @value{GDBN} sources as
1922follows:
1923
1924@smallexample
1925struct ui_file
1926@{
1927   int *magic;
1928   ui_file_flush_ftype *to_flush;
1929   ui_file_write_ftype *to_write;
1930   ui_file_write_async_safe_ftype *to_write_async_safe;
1931   ui_file_fputs_ftype *to_fputs;
1932   ui_file_read_ftype *to_read;
1933   ui_file_delete_ftype *to_delete;
1934   ui_file_isatty_ftype *to_isatty;
1935   ui_file_rewind_ftype *to_rewind;
1936   ui_file_put_ftype *to_put;
1937   void *to_data;
1938@}
1939@end smallexample
1940
1941@node Command Options
1942@section Command options
1943
1944@cindex command options
1945Some commands accept options starting with a leading dash.  For
1946example, @code{print -pretty}.  Similarly to command names, you can
1947abbreviate a @value{GDBN} option to the first few letters of the
1948option name, if that abbreviation is unambiguous, and you can also use
1949the @key{TAB} key to get @value{GDBN} to fill out the rest of a word
1950in an option (or to show you the alternatives available, if there is
1951more than one possibility).
1952
1953@cindex command options, raw input
1954Some commands take raw input as argument.  For example, the print
1955command processes arbitrary expressions in any of the languages
1956supported by @value{GDBN}.  With such commands, because raw input may
1957start with a leading dash that would be confused with an option or any
1958of its abbreviations, e.g.@: @code{print -p} (short for @code{print
1959-pretty} or printing negative @code{p}?), if you specify any command
1960option, then you must use a double-dash (@code{--}) delimiter to
1961indicate the end of options.
1962
1963@cindex command options, boolean
1964
1965Some options are described as accepting an argument which can be
1966either @code{on} or @code{off}.  These are known as @dfn{boolean
1967options}.  Similarly to boolean settings commands---@code{on} and
1968@code{off} are the typical values, but any of @code{1}, @code{yes} and
1969@code{enable} can also be used as ``true'' value, and any of @code{0},
1970@code{no} and @code{disable} can also be used as ``false'' value.  You
1971can also omit a ``true'' value, as it is implied by default.
1972
1973For example, these are equivalent:
1974
1975@smallexample
1976(@value{GDBP}) print -object on -pretty off -element unlimited -- *myptr
1977(@value{GDBP}) p -o -p 0 -e u -- *myptr
1978@end smallexample
1979
1980You can discover the set of options some command accepts by completing
1981on @code{-} after the command name.  For example:
1982
1983@smallexample
1984(@value{GDBP}) print -@key{TAB}@key{TAB}
1985-address         -max-depth       -raw-values      -union
1986-array           -null-stop       -repeats         -vtbl
1987-array-indexes   -object          -static-members
1988-elements        -pretty          -symbol
1989@end smallexample
1990
1991Completion will in some cases guide you with a suggestion of what kind
1992of argument an option expects.  For example:
1993
1994@smallexample
1995(@value{GDBP}) print -elements @key{TAB}@key{TAB}
1996NUMBER     unlimited
1997@end smallexample
1998
1999Here, the option expects a number (e.g., @code{100}), not literal
2000@code{NUMBER}.  Such metasyntactical arguments are always presented in
2001uppercase.
2002
2003(For more on using the @code{print} command, see @ref{Data, ,Examining
2004Data}.)
2005
2006@node Command aliases default args
2007@section Automatically prepend default arguments to user-defined aliases
2008
2009You can tell @value{GDBN} to always prepend some default arguments to
2010the list of arguments provided explicitly by the user when using a
2011user-defined alias.
2012
2013If you repeatedly use the same arguments or options for a command, you
2014can define an alias for this command and tell @value{GDBN} to
2015automatically prepend these arguments or options to the list of
2016arguments you type explicitly when using the alias@footnote{@value{GDBN}
2017could easily accept default arguments for pre-defined commands and aliases,
2018but it was deemed this would be confusing, and so is not allowed.}.
2019
2020For example, if you often use the command @code{thread apply all}
2021specifying to work on the threads in ascending order and to continue in case it
2022encounters an error, you can tell @value{GDBN} to automatically preprend
2023the @code{-ascending} and @code{-c} options by using:
2024
2025@smallexample
2026(@value{GDBP}) alias thread apply asc-all = thread apply all -ascending -c
2027@end smallexample
2028
2029Once you have defined this alias with its default args, any time you type
2030the @code{thread apply asc-all} followed by @code{some arguments},
2031@value{GDBN} will execute  @code{thread apply all -ascending -c some arguments}.
2032
2033To have even less to type, you can also define a one word alias:
2034@smallexample
2035(@value{GDBP}) alias t_a_c = thread apply all -ascending -c
2036@end smallexample
2037
2038As usual, unambiguous abbreviations can be used for @var{alias}
2039and @var{default-args}.
2040
2041The different aliases of a command do not share their default args.
2042For example, you define a new alias @code{bt_ALL} showing all possible
2043information and another alias @code{bt_SMALL} showing very limited information
2044using:
2045@smallexample
2046(@value{GDBP}) alias bt_ALL = backtrace -entry-values both -frame-arg all \
2047   -past-main -past-entry -full
2048(@value{GDBP}) alias bt_SMALL = backtrace -entry-values no -frame-arg none \
2049   -past-main off -past-entry off
2050@end smallexample
2051
2052(For more on using the @code{alias} command, see @ref{Aliases}.)
2053
2054Default args are not limited to the arguments and options of @var{command},
2055but can specify nested commands if @var{command} accepts such a nested command
2056as argument.
2057For example, the below defines @code{faalocalsoftype} that lists the
2058frames having locals of a certain type, together with the matching
2059local vars:
2060@smallexample
2061(@value{GDBP}) alias faalocalsoftype = frame apply all info locals -q -t
2062(@value{GDBP}) faalocalsoftype int
2063#1  0x55554f5e in sleeper_or_burner (v=0xdf50) at sleepers.c:86
2064i = 0
2065ret = 21845
2066@end smallexample
2067
2068This is also very useful to define an alias for a set of nested @code{with}
2069commands to have a particular combination of temporary settings.  For example,
2070the below defines the alias @code{pp10} that pretty prints an expression
2071argument, with a maximum of 10 elements if the expression is a string or
2072an array:
2073@smallexample
2074(@value{GDBP}) alias pp10 = with print pretty -- with print elements 10 -- print
2075@end smallexample
2076This defines the alias  @code{pp10} as being a sequence of 3 commands.
2077The first part @code{with print pretty --} temporarily activates the setting
2078@code{set print pretty}, then launches the command that follows the separator
2079@code{--}.
2080The command following the first part is also a @code{with} command that
2081temporarily changes the setting @code{set print elements} to 10, then
2082launches the command that follows the second separator @code{--}.
2083The third part @code{print} is the command the @code{pp10} alias will launch,
2084using the temporary values of the settings and the arguments explicitly given
2085by the user.
2086For more information about the @code{with} command usage,
2087see @ref{Command Settings}.
2088
2089@node Help
2090@section Getting Help
2091@cindex online documentation
2092@kindex help
2093
2094You can always ask @value{GDBN} itself for information on its commands,
2095using the command @code{help}.
2096
2097@table @code
2098@kindex h @r{(@code{help})}
2099@item help
2100@itemx h
2101You can use @code{help} (abbreviated @code{h}) with no arguments to
2102display a short list of named classes of commands:
2103
2104@smallexample
2105(@value{GDBP}) help
2106List of classes of commands:
2107
2108aliases -- User-defined aliases of other commands
2109breakpoints -- Making program stop at certain points
2110data -- Examining data
2111files -- Specifying and examining files
2112internals -- Maintenance commands
2113obscure -- Obscure features
2114running -- Running the program
2115stack -- Examining the stack
2116status -- Status inquiries
2117support -- Support facilities
2118tracepoints -- Tracing of program execution without
2119               stopping the program
2120user-defined -- User-defined commands
2121
2122Type "help" followed by a class name for a list of
2123commands in that class.
2124Type "help" followed by command name for full
2125documentation.
2126Command name abbreviations are allowed if unambiguous.
2127(@value{GDBP})
2128@end smallexample
2129@c the above line break eliminates huge line overfull...
2130
2131@item help @var{class}
2132Using one of the general help classes as an argument, you can get a
2133list of the individual commands in that class.  If a command has
2134aliases, the aliases are given after the command name, separated by
2135commas.  If an alias has default arguments, the full definition of
2136the alias is given after the first line.
2137For example, here is the help display for the class @code{status}:
2138
2139@smallexample
2140(@value{GDBP}) help status
2141Status inquiries.
2142
2143List of commands:
2144
2145@c Line break in "show" line falsifies real output, but needed
2146@c to fit in smallbook page size.
2147info, inf, i -- Generic command for showing things
2148        about the program being debugged
2149info address, iamain  -- Describe where symbol SYM is stored.
2150  alias iamain = info address main
2151info all-registers -- List of all registers and their contents,
2152        for selected stack frame.
2153...
2154show, info set -- Generic command for showing things
2155        about the debugger
2156
2157Type "help" followed by command name for full
2158documentation.
2159Command name abbreviations are allowed if unambiguous.
2160(@value{GDBP})
2161@end smallexample
2162
2163@item help @var{command}
2164With a command name as @code{help} argument, @value{GDBN} displays a
2165short paragraph on how to use that command.  If that command has
2166one or more aliases, @value{GDBN} will display a first line with
2167the command name and all its aliases separated by commas.
2168This first line will be followed by the full definition of all aliases
2169having default arguments.
2170
2171@kindex apropos
2172@item apropos [-v] @var{regexp}
2173The @code{apropos} command searches through all of the @value{GDBN}
2174commands, and their documentation, for the regular expression specified in
2175@var{args}.  It prints out all matches found.  The optional flag  @samp{-v},
2176which stands for @samp{verbose}, indicates to output the full documentation
2177of the matching commands and highlight the parts of the documentation
2178matching @var{regexp}.  For example:
2179
2180@smallexample
2181apropos alias
2182@end smallexample
2183
2184@noindent
2185results in:
2186
2187@smallexample
2188@group
2189alias -- Define a new command that is an alias of an existing command
2190aliases -- User-defined aliases of other commands
2191@end group
2192@end smallexample
2193
2194@noindent
2195while
2196
2197@smallexample
2198apropos -v cut.*thread apply
2199@end smallexample
2200
2201@noindent
2202results in the below output, where @samp{cut for 'thread apply}
2203is highlighted if styling is enabled.
2204
2205@smallexample
2206@group
2207taas -- Apply a command to all threads (ignoring errors
2208and empty output).
2209Usage: taas COMMAND
2210shortcut for 'thread apply all -s COMMAND'
2211
2212tfaas -- Apply a command to all frames of all threads
2213(ignoring errors and empty output).
2214Usage: tfaas COMMAND
2215shortcut for 'thread apply all -s frame apply all -s COMMAND'
2216@end group
2217@end smallexample
2218
2219@kindex complete
2220@item complete @var{args}
2221The @code{complete @var{args}} command lists all the possible completions
2222for the beginning of a command.  Use @var{args} to specify the beginning of the
2223command you want completed.  For example:
2224
2225@smallexample
2226complete i
2227@end smallexample
2228
2229@noindent results in:
2230
2231@smallexample
2232@group
2233if
2234ignore
2235info
2236inspect
2237@end group
2238@end smallexample
2239
2240@noindent This is intended for use by @sc{gnu} Emacs.
2241@end table
2242
2243In addition to @code{help}, you can use the @value{GDBN} commands @code{info}
2244and @code{show} to inquire about the state of your program, or the state
2245of @value{GDBN} itself.  Each command supports many topics of inquiry; this
2246manual introduces each of them in the appropriate context.  The listings
2247under @code{info} and under @code{show} in the Command, Variable, and
2248Function Index point to all the sub-commands.  @xref{Command and Variable
2249Index}.
2250
2251@c @group
2252@table @code
2253@kindex info
2254@kindex i @r{(@code{info})}
2255@item info
2256This command (abbreviated @code{i}) is for describing the state of your
2257program.  For example, you can show the arguments passed to a function
2258with @code{info args}, list the registers currently in use with @code{info
2259registers}, or list the breakpoints you have set with @code{info breakpoints}.
2260You can get a complete list of the @code{info} sub-commands with
2261@w{@code{help info}}.
2262
2263@kindex set
2264@item set
2265You can assign the result of an expression to an environment variable with
2266@code{set}.  For example, you can set the @value{GDBN} prompt to a $-sign with
2267@code{set prompt $}.
2268
2269@kindex show
2270@item show
2271In contrast to @code{info}, @code{show} is for describing the state of
2272@value{GDBN} itself.
2273You can change most of the things you can @code{show}, by using the
2274related command @code{set}; for example, you can control what number
2275system is used for displays with @code{set radix}, or simply inquire
2276which is currently in use with @code{show radix}.
2277
2278@kindex info set
2279To display all the settable parameters and their current
2280values, you can use @code{show} with no arguments; you may also use
2281@code{info set}.  Both commands produce the same display.
2282@c FIXME: "info set" violates the rule that "info" is for state of
2283@c FIXME...program.  Ck w/ GNU: "info set" to be called something else,
2284@c FIXME...or change desc of rule---eg "state of prog and debugging session"?
2285@end table
2286@c @end group
2287
2288Here are several miscellaneous @code{show} subcommands, all of which are
2289exceptional in lacking corresponding @code{set} commands:
2290
2291@table @code
2292@kindex show version
2293@cindex @value{GDBN} version number
2294@item show version
2295Show what version of @value{GDBN} is running.  You should include this
2296information in @value{GDBN} bug-reports.  If multiple versions of
2297@value{GDBN} are in use at your site, you may need to determine which
2298version of @value{GDBN} you are running; as @value{GDBN} evolves, new
2299commands are introduced, and old ones may wither away.  Also, many
2300system vendors ship variant versions of @value{GDBN}, and there are
2301variant versions of @value{GDBN} in @sc{gnu}/Linux distributions as well.
2302The version number is the same as the one announced when you start
2303@value{GDBN}.
2304
2305@kindex show copying
2306@kindex info copying
2307@cindex display @value{GDBN} copyright
2308@item show copying
2309@itemx info copying
2310Display information about permission for copying @value{GDBN}.
2311
2312@kindex show warranty
2313@kindex info warranty
2314@item show warranty
2315@itemx info warranty
2316Display the @sc{gnu} ``NO WARRANTY'' statement, or a warranty,
2317if your version of @value{GDBN} comes with one.
2318
2319@kindex show configuration
2320@item show configuration
2321Display detailed information about the way @value{GDBN} was configured
2322when it was built.  This displays the optional arguments passed to the
2323@file{configure} script and also configuration parameters detected
2324automatically by @command{configure}.  When reporting a @value{GDBN}
2325bug (@pxref{GDB Bugs}), it is important to include this information in
2326your report.
2327
2328@end table
2329
2330@node Running
2331@chapter Running Programs Under @value{GDBN}
2332
2333When you run a program under @value{GDBN}, you must first generate
2334debugging information when you compile it.
2335
2336You may start @value{GDBN} with its arguments, if any, in an environment
2337of your choice.  If you are doing native debugging, you may redirect
2338your program's input and output, debug an already running process, or
2339kill a child process.
2340
2341@menu
2342* Compilation::                 Compiling for debugging
2343* Starting::                    Starting your program
2344* Arguments::                   Your program's arguments
2345* Environment::                 Your program's environment
2346
2347* Working Directory::           Your program's working directory
2348* Input/Output::                Your program's input and output
2349* Attach::                      Debugging an already-running process
2350* Kill Process::                Killing the child process
2351* Inferiors Connections and Programs:: Debugging multiple inferiors
2352					 connections and programs
2353* Threads::                     Debugging programs with multiple threads
2354* Forks::                       Debugging forks
2355* Checkpoint/Restart::          Setting a @emph{bookmark} to return to later
2356@end menu
2357
2358@node Compilation
2359@section Compiling for Debugging
2360
2361In order to debug a program effectively, you need to generate
2362debugging information when you compile it.  This debugging information
2363is stored in the object file; it describes the data type of each
2364variable or function and the correspondence between source line numbers
2365and addresses in the executable code.
2366
2367To request debugging information, specify the @samp{-g} option when you run
2368the compiler.
2369
2370Programs that are to be shipped to your customers are compiled with
2371optimizations, using the @samp{-O} compiler option.  However, some
2372compilers are unable to handle the @samp{-g} and @samp{-O} options
2373together.  Using those compilers, you cannot generate optimized
2374executables containing debugging information.
2375
2376@value{NGCC}, the @sc{gnu} C/C@t{++} compiler, supports @samp{-g} with or
2377without @samp{-O}, making it possible to debug optimized code.  We
2378recommend that you @emph{always} use @samp{-g} whenever you compile a
2379program.  You may think your program is correct, but there is no sense
2380in pushing your luck.  For more information, see @ref{Optimized Code}.
2381
2382Older versions of the @sc{gnu} C compiler permitted a variant option
2383@w{@samp{-gg}} for debugging information.  @value{GDBN} no longer supports this
2384format; if your @sc{gnu} C compiler has this option, do not use it.
2385
2386@value{GDBN} knows about preprocessor macros and can show you their
2387expansion (@pxref{Macros}).  Most compilers do not include information
2388about preprocessor macros in the debugging information if you specify
2389the @option{-g} flag alone.  Version 3.1 and later of @value{NGCC},
2390the @sc{gnu} C compiler, provides macro information if you are using
2391the DWARF debugging format, and specify the option @option{-g3}.
2392
2393@xref{Debugging Options,,Options for Debugging Your Program or GCC,
2394gcc, Using the @sc{gnu} Compiler Collection (GCC)}, for more
2395information on @value{NGCC} options affecting debug information.
2396
2397You will have the best debugging experience if you use the latest
2398version of the DWARF debugging format that your compiler supports.
2399DWARF is currently the most expressive and best supported debugging
2400format in @value{GDBN}.
2401
2402@need 2000
2403@node Starting
2404@section Starting your Program
2405@cindex starting
2406@cindex running
2407
2408@table @code
2409@kindex run
2410@kindex r @r{(@code{run})}
2411@item run
2412@itemx r
2413Use the @code{run} command to start your program under @value{GDBN}.
2414You must first specify the program name with an argument to
2415@value{GDBN} (@pxref{Invocation, ,Getting In and Out of
2416@value{GDBN}}), or by using the @code{file} or @code{exec-file}
2417command (@pxref{Files, ,Commands to Specify Files}).
2418
2419@end table
2420
2421If you are running your program in an execution environment that
2422supports processes, @code{run} creates an inferior process and makes
2423that process run your program.  In some environments without processes,
2424@code{run} jumps to the start of your program.  Other targets,
2425like @samp{remote}, are always running.  If you get an error
2426message like this one:
2427
2428@smallexample
2429The "remote" target does not support "run".
2430Try "help target" or "continue".
2431@end smallexample
2432
2433@noindent
2434then use @code{continue} to run your program.  You may need @code{load}
2435first (@pxref{load}).
2436
2437The execution of a program is affected by certain information it
2438receives from its superior.  @value{GDBN} provides ways to specify this
2439information, which you must do @emph{before} starting your program.  (You
2440can change it after starting your program, but such changes only affect
2441your program the next time you start it.)  This information may be
2442divided into four categories:
2443
2444@table @asis
2445@item The @emph{arguments.}
2446Specify the arguments to give your program as the arguments of the
2447@code{run} command.  If a shell is available on your target, the shell
2448is used to pass the arguments, so that you may use normal conventions
2449(such as wildcard expansion or variable substitution) in describing
2450the arguments.
2451In Unix systems, you can control which shell is used with the
2452@code{SHELL} environment variable.  If you do not define @code{SHELL},
2453@value{GDBN} uses the default shell (@file{/bin/sh}).  You can disable
2454use of any shell with the @code{set startup-with-shell} command (see
2455below for details).
2456
2457@item The @emph{environment.}
2458Your program normally inherits its environment from @value{GDBN}, but you can
2459use the @value{GDBN} commands @code{set environment} and @code{unset
2460environment} to change parts of the environment that affect
2461your program.  @xref{Environment, ,Your Program's Environment}.
2462
2463@item The @emph{working directory.}
2464You can set your program's working directory with the command
2465@kbd{set cwd}.  If you do not set any working directory with this
2466command, your program will inherit @value{GDBN}'s working directory if
2467native debugging, or the remote server's working directory if remote
2468debugging.  @xref{Working Directory, ,Your Program's Working
2469Directory}.
2470
2471@item The @emph{standard input and output.}
2472Your program normally uses the same device for standard input and
2473standard output as @value{GDBN} is using.  You can redirect input and output
2474in the @code{run} command line, or you can use the @code{tty} command to
2475set a different device for your program.
2476@xref{Input/Output, ,Your Program's Input and Output}.
2477
2478@cindex pipes
2479@emph{Warning:} While input and output redirection work, you cannot use
2480pipes to pass the output of the program you are debugging to another
2481program; if you attempt this, @value{GDBN} is likely to wind up debugging the
2482wrong program.
2483@end table
2484
2485When you issue the @code{run} command, your program begins to execute
2486immediately.  @xref{Stopping, ,Stopping and Continuing}, for discussion
2487of how to arrange for your program to stop.  Once your program has
2488stopped, you may call functions in your program, using the @code{print}
2489or @code{call} commands.  @xref{Data, ,Examining Data}.
2490
2491If the modification time of your symbol file has changed since the last
2492time @value{GDBN} read its symbols, @value{GDBN} discards its symbol
2493table, and reads it again.  When it does this, @value{GDBN} tries to retain
2494your current breakpoints.
2495
2496@table @code
2497@kindex start
2498@item start
2499@cindex run to main procedure
2500The name of the main procedure can vary from language to language.
2501With C or C@t{++}, the main procedure name is always @code{main}, but
2502other languages such as Ada do not require a specific name for their
2503main procedure.  The debugger provides a convenient way to start the
2504execution of the program and to stop at the beginning of the main
2505procedure, depending on the language used.
2506
2507The @samp{start} command does the equivalent of setting a temporary
2508breakpoint at the beginning of the main procedure and then invoking
2509the @samp{run} command.
2510
2511@cindex elaboration phase
2512Some programs contain an @dfn{elaboration} phase where some startup code is
2513executed before the main procedure is called.  This depends on the
2514languages used to write your program.  In C@t{++}, for instance,
2515constructors for static and global objects are executed before
2516@code{main} is called.  It is therefore possible that the debugger stops
2517before reaching the main procedure.  However, the temporary breakpoint
2518will remain to halt execution.
2519
2520Specify the arguments to give to your program as arguments to the
2521@samp{start} command.  These arguments will be given verbatim to the
2522underlying @samp{run} command.  Note that the same arguments will be
2523reused if no argument is provided during subsequent calls to
2524@samp{start} or @samp{run}.
2525
2526It is sometimes necessary to debug the program during elaboration.  In
2527these cases, using the @code{start} command would stop the execution
2528of your program too late, as the program would have already completed
2529the elaboration phase.  Under these circumstances, either insert
2530breakpoints in your elaboration code before running your program or
2531use the @code{starti} command.
2532
2533@kindex starti
2534@item starti
2535@cindex run to first instruction
2536The @samp{starti} command does the equivalent of setting a temporary
2537breakpoint at the first instruction of a program's execution and then
2538invoking the @samp{run} command.  For programs containing an
2539elaboration phase, the @code{starti} command will stop execution at
2540the start of the elaboration phase.
2541
2542@anchor{set exec-wrapper}
2543@kindex set exec-wrapper
2544@item set exec-wrapper @var{wrapper}
2545@itemx show exec-wrapper
2546@itemx unset exec-wrapper
2547When @samp{exec-wrapper} is set, the specified wrapper is used to
2548launch programs for debugging.  @value{GDBN} starts your program
2549with a shell command of the form @kbd{exec @var{wrapper}
2550@var{program}}.  Quoting is added to @var{program} and its
2551arguments, but not to @var{wrapper}, so you should add quotes if
2552appropriate for your shell.  The wrapper runs until it executes
2553your program, and then @value{GDBN} takes control.
2554
2555You can use any program that eventually calls @code{execve} with
2556its arguments as a wrapper.  Several standard Unix utilities do
2557this, e.g.@: @code{env} and @code{nohup}.  Any Unix shell script ending
2558with @code{exec "$@@"} will also work.
2559
2560For example, you can use @code{env} to pass an environment variable to
2561the debugged program, without setting the variable in your shell's
2562environment:
2563
2564@smallexample
2565(@value{GDBP}) set exec-wrapper env 'LD_PRELOAD=libtest.so'
2566(@value{GDBP}) run
2567@end smallexample
2568
2569This command is available when debugging locally on most targets, excluding
2570@sc{djgpp}, Cygwin, MS Windows, and QNX Neutrino.
2571
2572@kindex set startup-with-shell
2573@anchor{set startup-with-shell}
2574@item set startup-with-shell
2575@itemx set startup-with-shell on
2576@itemx set startup-with-shell off
2577@itemx show startup-with-shell
2578On Unix systems, by default, if a shell is available on your target,
2579@value{GDBN}) uses it to start your program.  Arguments of the
2580@code{run} command are passed to the shell, which does variable
2581substitution, expands wildcard characters and performs redirection of
2582I/O.  In some circumstances, it may be useful to disable such use of a
2583shell, for example, when debugging the shell itself or diagnosing
2584startup failures such as:
2585
2586@smallexample
2587(@value{GDBP}) run
2588Starting program: ./a.out
2589During startup program terminated with signal SIGSEGV, Segmentation fault.
2590@end smallexample
2591
2592@noindent
2593which indicates the shell or the wrapper specified with
2594@samp{exec-wrapper} crashed, not your program.  Most often, this is
2595caused by something odd in your shell's non-interactive mode
2596initialization file---such as @file{.cshrc} for C-shell,
2597$@file{.zshenv} for the Z shell, or the file specified in the
2598@samp{BASH_ENV} environment variable for BASH.
2599
2600@anchor{set auto-connect-native-target}
2601@kindex set auto-connect-native-target
2602@item set auto-connect-native-target
2603@itemx set auto-connect-native-target on
2604@itemx set auto-connect-native-target off
2605@itemx show auto-connect-native-target
2606
2607By default, if the current inferior is not connected to any target yet
2608(e.g., with @code{target remote}), the @code{run} command starts your
2609program as a native process under @value{GDBN}, on your local machine.
2610If you're sure you don't want to debug programs on your local machine,
2611you can tell @value{GDBN} to not connect to the native target
2612automatically with the @code{set auto-connect-native-target off}
2613command.
2614
2615If @code{on}, which is the default, and if the current inferior is not
2616connected to a target already, the @code{run} command automaticaly
2617connects to the native target, if one is available.
2618
2619If @code{off}, and if the current inferior is not connected to a
2620target already, the @code{run} command fails with an error:
2621
2622@smallexample
2623(@value{GDBP}) run
2624Don't know how to run.  Try "help target".
2625@end smallexample
2626
2627If the current inferior is already connected to a target, @value{GDBN}
2628always uses it with the @code{run} command.
2629
2630In any case, you can explicitly connect to the native target with the
2631@code{target native} command.  For example,
2632
2633@smallexample
2634(@value{GDBP}) set auto-connect-native-target off
2635(@value{GDBP}) run
2636Don't know how to run.  Try "help target".
2637(@value{GDBP}) target native
2638(@value{GDBP}) run
2639Starting program: ./a.out
2640[Inferior 1 (process 10421) exited normally]
2641@end smallexample
2642
2643In case you connected explicitly to the @code{native} target,
2644@value{GDBN} remains connected even if all inferiors exit, ready for
2645the next @code{run} command.  Use the @code{disconnect} command to
2646disconnect.
2647
2648Examples of other commands that likewise respect the
2649@code{auto-connect-native-target} setting: @code{attach}, @code{info
2650proc}, @code{info os}.
2651
2652@kindex set disable-randomization
2653@item set disable-randomization
2654@itemx set disable-randomization on
2655This option (enabled by default in @value{GDBN}) will turn off the native
2656randomization of the virtual address space of the started program.  This option
2657is useful for multiple debugging sessions to make the execution better
2658reproducible and memory addresses reusable across debugging sessions.
2659
2660This feature is implemented only on certain targets, including @sc{gnu}/Linux.
2661On @sc{gnu}/Linux you can get the same behavior using
2662
2663@smallexample
2664(@value{GDBP}) set exec-wrapper setarch `uname -m` -R
2665@end smallexample
2666
2667@item set disable-randomization off
2668Leave the behavior of the started executable unchanged.  Some bugs rear their
2669ugly heads only when the program is loaded at certain addresses.  If your bug
2670disappears when you run the program under @value{GDBN}, that might be because
2671@value{GDBN} by default disables the address randomization on platforms, such
2672as @sc{gnu}/Linux, which do that for stand-alone programs.  Use @kbd{set
2673disable-randomization off} to try to reproduce such elusive bugs.
2674
2675On targets where it is available, virtual address space randomization
2676protects the programs against certain kinds of security attacks.  In these
2677cases the attacker needs to know the exact location of a concrete executable
2678code.  Randomizing its location makes it impossible to inject jumps misusing
2679a code at its expected addresses.
2680
2681Prelinking shared libraries provides a startup performance advantage but it
2682makes addresses in these libraries predictable for privileged processes by
2683having just unprivileged access at the target system.  Reading the shared
2684library binary gives enough information for assembling the malicious code
2685misusing it.  Still even a prelinked shared library can get loaded at a new
2686random address just requiring the regular relocation process during the
2687startup.  Shared libraries not already prelinked are always loaded at
2688a randomly chosen address.
2689
2690Position independent executables (PIE) contain position independent code
2691similar to the shared libraries and therefore such executables get loaded at
2692a randomly chosen address upon startup.  PIE executables always load even
2693already prelinked shared libraries at a random address.  You can build such
2694executable using @command{gcc -fPIE -pie}.
2695
2696Heap (malloc storage), stack and custom mmap areas are always placed randomly
2697(as long as the randomization is enabled).
2698
2699@item show disable-randomization
2700Show the current setting of the explicit disable of the native randomization of
2701the virtual address space of the started program.
2702
2703@end table
2704
2705@node Arguments
2706@section Your Program's Arguments
2707
2708@cindex arguments (to your program)
2709The arguments to your program can be specified by the arguments of the
2710@code{run} command.
2711They are passed to a shell, which expands wildcard characters and
2712performs redirection of I/O, and thence to your program.  Your
2713@code{SHELL} environment variable (if it exists) specifies what shell
2714@value{GDBN} uses.  If you do not define @code{SHELL}, @value{GDBN} uses
2715the default shell (@file{/bin/sh} on Unix).
2716
2717On non-Unix systems, the program is usually invoked directly by
2718@value{GDBN}, which emulates I/O redirection via the appropriate system
2719calls, and the wildcard characters are expanded by the startup code of
2720the program, not by the shell.
2721
2722@code{run} with no arguments uses the same arguments used by the previous
2723@code{run}, or those set by the @code{set args} command.
2724
2725@table @code
2726@kindex set args
2727@item set args
2728Specify the arguments to be used the next time your program is run.  If
2729@code{set args} has no arguments, @code{run} executes your program
2730with no arguments.  Once you have run your program with arguments,
2731using @code{set args} before the next @code{run} is the only way to run
2732it again without arguments.
2733
2734@kindex show args
2735@item show args
2736Show the arguments to give your program when it is started.
2737@end table
2738
2739@node Environment
2740@section Your Program's Environment
2741
2742@cindex environment (of your program)
2743The @dfn{environment} consists of a set of environment variables and
2744their values.  Environment variables conventionally record such things as
2745your user name, your home directory, your terminal type, and your search
2746path for programs to run.  Usually you set up environment variables with
2747the shell and they are inherited by all the other programs you run.  When
2748debugging, it can be useful to try running your program with a modified
2749environment without having to start @value{GDBN} over again.
2750
2751@table @code
2752@kindex path
2753@item path @var{directory}
2754Add @var{directory} to the front of the @code{PATH} environment variable
2755(the search path for executables) that will be passed to your program.
2756The value of @code{PATH} used by @value{GDBN} does not change.
2757You may specify several directory names, separated by whitespace or by a
2758system-dependent separator character (@samp{:} on Unix, @samp{;} on
2759MS-DOS and MS-Windows).  If @var{directory} is already in the path, it
2760is moved to the front, so it is searched sooner.
2761
2762You can use the string @samp{$cwd} to refer to whatever is the current
2763working directory at the time @value{GDBN} searches the path.  If you
2764use @samp{.} instead, it refers to the directory where you executed the
2765@code{path} command.  @value{GDBN} replaces @samp{.} in the
2766@var{directory} argument (with the current path) before adding
2767@var{directory} to the search path.
2768@c 'path' is explicitly nonrepeatable, but RMS points out it is silly to
2769@c document that, since repeating it would be a no-op.
2770
2771@kindex show paths
2772@item show paths
2773Display the list of search paths for executables (the @code{PATH}
2774environment variable).
2775
2776@kindex show environment
2777@item show environment @r{[}@var{varname}@r{]}
2778Print the value of environment variable @var{varname} to be given to
2779your program when it starts.  If you do not supply @var{varname},
2780print the names and values of all environment variables to be given to
2781your program.  You can abbreviate @code{environment} as @code{env}.
2782
2783@kindex set environment
2784@anchor{set environment}
2785@item set environment @var{varname} @r{[}=@var{value}@r{]}
2786Set environment variable @var{varname} to @var{value}.  The value
2787changes for your program (and the shell @value{GDBN} uses to launch
2788it), not for @value{GDBN} itself.  The @var{value} may be any string; the
2789values of environment variables are just strings, and any
2790interpretation is supplied by your program itself.  The @var{value}
2791parameter is optional; if it is eliminated, the variable is set to a
2792null value.
2793@c "any string" here does not include leading, trailing
2794@c blanks. Gnu asks: does anyone care?
2795
2796For example, this command:
2797
2798@smallexample
2799set env USER = foo
2800@end smallexample
2801
2802@noindent
2803tells the debugged program, when subsequently run, that its user is named
2804@samp{foo}.  (The spaces around @samp{=} are used for clarity here; they
2805are not actually required.)
2806
2807Note that on Unix systems, @value{GDBN} runs your program via a shell,
2808which also inherits the environment set with @code{set environment}.
2809If necessary, you can avoid that by using the @samp{env} program as a
2810wrapper instead of using @code{set environment}.  @xref{set
2811exec-wrapper}, for an example doing just that.
2812
2813Environment variables that are set by the user are also transmitted to
2814@command{gdbserver} to be used when starting the remote inferior.
2815@pxref{QEnvironmentHexEncoded}.
2816
2817@kindex unset environment
2818@anchor{unset environment}
2819@item unset environment @var{varname}
2820Remove variable @var{varname} from the environment to be passed to your
2821program.  This is different from @samp{set env @var{varname} =};
2822@code{unset environment} removes the variable from the environment,
2823rather than assigning it an empty value.
2824
2825Environment variables that are unset by the user are also unset on
2826@command{gdbserver} when starting the remote inferior.
2827@pxref{QEnvironmentUnset}.
2828@end table
2829
2830@emph{Warning:} On Unix systems, @value{GDBN} runs your program using
2831the shell indicated by your @code{SHELL} environment variable if it
2832exists (or @code{/bin/sh} if not).  If your @code{SHELL} variable
2833names a shell that runs an initialization file when started
2834non-interactively---such as @file{.cshrc} for C-shell, $@file{.zshenv}
2835for the Z shell, or the file specified in the @samp{BASH_ENV}
2836environment variable for BASH---any variables you set in that file
2837affect your program.  You may wish to move setting of environment
2838variables to files that are only run when you sign on, such as
2839@file{.login} or @file{.profile}.
2840
2841@node Working Directory
2842@section Your Program's Working Directory
2843
2844@cindex working directory (of your program)
2845Each time you start your program with @code{run}, the inferior will be
2846initialized with the current working directory specified by the
2847@kbd{set cwd} command.  If no directory has been specified by this
2848command, then the inferior will inherit @value{GDBN}'s current working
2849directory as its working directory if native debugging, or it will
2850inherit the remote server's current working directory if remote
2851debugging.
2852
2853@table @code
2854@kindex set cwd
2855@cindex change inferior's working directory
2856@anchor{set cwd command}
2857@item set cwd @r{[}@var{directory}@r{]}
2858Set the inferior's working directory to @var{directory}, which will be
2859@code{glob}-expanded in order to resolve tildes (@file{~}).  If no
2860argument has been specified, the command clears the setting and resets
2861it to an empty state.  This setting has no effect on @value{GDBN}'s
2862working directory, and it only takes effect the next time you start
2863the inferior.  The @file{~} in @var{directory} is a short for the
2864@dfn{home directory}, usually pointed to by the @env{HOME} environment
2865variable.  On MS-Windows, if @env{HOME} is not defined, @value{GDBN}
2866uses the concatenation of @env{HOMEDRIVE} and @env{HOMEPATH} as
2867fallback.
2868
2869You can also change @value{GDBN}'s current working directory by using
2870the @code{cd} command.
2871@xref{cd command}.
2872
2873@kindex show cwd
2874@cindex show inferior's working directory
2875@item show cwd
2876Show the inferior's working directory.  If no directory has been
2877specified by @kbd{set cwd}, then the default inferior's working
2878directory is the same as @value{GDBN}'s working directory.
2879
2880@kindex cd
2881@cindex change @value{GDBN}'s working directory
2882@anchor{cd command}
2883@item cd @r{[}@var{directory}@r{]}
2884Set the @value{GDBN} working directory to @var{directory}.  If not
2885given, @var{directory} uses @file{'~'}.
2886
2887The @value{GDBN} working directory serves as a default for the
2888commands that specify files for @value{GDBN} to operate on.
2889@xref{Files, ,Commands to Specify Files}.
2890@xref{set cwd command}.
2891
2892@kindex pwd
2893@item pwd
2894Print the @value{GDBN} working directory.
2895@end table
2896
2897It is generally impossible to find the current working directory of
2898the process being debugged (since a program can change its directory
2899during its run).  If you work on a system where @value{GDBN} supports
2900the @code{info proc} command (@pxref{Process Information}), you can
2901use the @code{info proc} command to find out the
2902current working directory of the debuggee.
2903
2904@node Input/Output
2905@section Your Program's Input and Output
2906
2907@cindex redirection
2908@cindex i/o
2909@cindex terminal
2910By default, the program you run under @value{GDBN} does input and output to
2911the same terminal that @value{GDBN} uses.  @value{GDBN} switches the terminal
2912to its own terminal modes to interact with you, but it records the terminal
2913modes your program was using and switches back to them when you continue
2914running your program.
2915
2916@table @code
2917@kindex info terminal
2918@item info terminal
2919Displays information recorded by @value{GDBN} about the terminal modes your
2920program is using.
2921@end table
2922
2923You can redirect your program's input and/or output using shell
2924redirection with the @code{run} command.  For example,
2925
2926@smallexample
2927run > outfile
2928@end smallexample
2929
2930@noindent
2931starts your program, diverting its output to the file @file{outfile}.
2932
2933@kindex tty
2934@cindex controlling terminal
2935Another way to specify where your program should do input and output is
2936with the @code{tty} command.  This command accepts a file name as
2937argument, and causes this file to be the default for future @code{run}
2938commands.  It also resets the controlling terminal for the child
2939process, for future @code{run} commands.  For example,
2940
2941@smallexample
2942tty /dev/ttyb
2943@end smallexample
2944
2945@noindent
2946directs that processes started with subsequent @code{run} commands
2947default to do input and output on the terminal @file{/dev/ttyb} and have
2948that as their controlling terminal.
2949
2950An explicit redirection in @code{run} overrides the @code{tty} command's
2951effect on the input/output device, but not its effect on the controlling
2952terminal.
2953
2954When you use the @code{tty} command or redirect input in the @code{run}
2955command, only the input @emph{for your program} is affected.  The input
2956for @value{GDBN} still comes from your terminal.  @code{tty} is an alias
2957for @code{set inferior-tty}.
2958
2959@cindex inferior tty
2960@cindex set inferior controlling terminal
2961You can use the @code{show inferior-tty} command to tell @value{GDBN} to
2962display the name of the terminal that will be used for future runs of your
2963program.
2964
2965@table @code
2966@item set inferior-tty [ @var{tty} ]
2967@kindex set inferior-tty
2968Set the tty for the program being debugged to @var{tty}.  Omitting @var{tty}
2969restores the default behavior, which is to use the same terminal as
2970@value{GDBN}.
2971
2972@item show inferior-tty
2973@kindex show inferior-tty
2974Show the current tty for the program being debugged.
2975@end table
2976
2977@node Attach
2978@section Debugging an Already-running Process
2979@kindex attach
2980@cindex attach
2981
2982@table @code
2983@item attach @var{process-id}
2984This command attaches to a running process---one that was started
2985outside @value{GDBN}.  (@code{info files} shows your active
2986targets.)  The command takes as argument a process ID.  The usual way to
2987find out the @var{process-id} of a Unix process is with the @code{ps} utility,
2988or with the @samp{jobs -l} shell command.
2989
2990@code{attach} does not repeat if you press @key{RET} a second time after
2991executing the command.
2992@end table
2993
2994To use @code{attach}, your program must be running in an environment
2995which supports processes; for example, @code{attach} does not work for
2996programs on bare-board targets that lack an operating system.  You must
2997also have permission to send the process a signal.
2998
2999When you use @code{attach}, the debugger finds the program running in
3000the process first by looking in the current working directory, then (if
3001the program is not found) by using the source file search path
3002(@pxref{Source Path, ,Specifying Source Directories}).  You can also use
3003the @code{file} command to load the program.  @xref{Files, ,Commands to
3004Specify Files}.
3005
3006@anchor{set exec-file-mismatch}
3007If the debugger can determine that the executable file running in the
3008process it is attaching to does not match the current exec-file loaded
3009by @value{GDBN}, the option @code{exec-file-mismatch} specifies how to
3010handle the mismatch.  @value{GDBN} tries to compare the files by
3011comparing their build IDs (@pxref{build ID}), if available.
3012
3013@table @code
3014@kindex exec-file-mismatch
3015@cindex set exec-file-mismatch
3016@item set exec-file-mismatch @samp{ask|warn|off}
3017
3018Whether to detect mismatch between the current executable file loaded
3019by @value{GDBN} and the executable file used to start the process.  If
3020@samp{ask}, the default, display a warning and ask the user whether to
3021load the process executable file; if @samp{warn}, just display a
3022warning; if @samp{off}, don't attempt to detect a mismatch.
3023If the user confirms loading the process executable file, then its symbols
3024will be loaded as well.
3025
3026@cindex show exec-file-mismatch
3027@item show exec-file-mismatch
3028Show the current value of @code{exec-file-mismatch}.
3029
3030@end table
3031
3032The first thing @value{GDBN} does after arranging to debug the specified
3033process is to stop it.  You can examine and modify an attached process
3034with all the @value{GDBN} commands that are ordinarily available when
3035you start processes with @code{run}.  You can insert breakpoints; you
3036can step and continue; you can modify storage.  If you would rather the
3037process continue running, you may use the @code{continue} command after
3038attaching @value{GDBN} to the process.
3039
3040@table @code
3041@kindex detach
3042@item detach
3043When you have finished debugging the attached process, you can use the
3044@code{detach} command to release it from @value{GDBN} control.  Detaching
3045the process continues its execution.  After the @code{detach} command,
3046that process and @value{GDBN} become completely independent once more, and you
3047are ready to @code{attach} another process or start one with @code{run}.
3048@code{detach} does not repeat if you press @key{RET} again after
3049executing the command.
3050@end table
3051
3052If you exit @value{GDBN} while you have an attached process, you detach
3053that process.  If you use the @code{run} command, you kill that process.
3054By default, @value{GDBN} asks for confirmation if you try to do either of these
3055things; you can control whether or not you need to confirm by using the
3056@code{set confirm} command (@pxref{Messages/Warnings, ,Optional Warnings and
3057Messages}).
3058
3059@node Kill Process
3060@section Killing the Child Process
3061
3062@table @code
3063@kindex kill
3064@item kill
3065Kill the child process in which your program is running under @value{GDBN}.
3066@end table
3067
3068This command is useful if you wish to debug a core dump instead of a
3069running process.  @value{GDBN} ignores any core dump file while your program
3070is running.
3071
3072On some operating systems, a program cannot be executed outside @value{GDBN}
3073while you have breakpoints set on it inside @value{GDBN}.  You can use the
3074@code{kill} command in this situation to permit running your program
3075outside the debugger.
3076
3077The @code{kill} command is also useful if you wish to recompile and
3078relink your program, since on many systems it is impossible to modify an
3079executable file while it is running in a process.  In this case, when you
3080next type @code{run}, @value{GDBN} notices that the file has changed, and
3081reads the symbol table again (while trying to preserve your current
3082breakpoint settings).
3083
3084@node Inferiors Connections and Programs
3085@section Debugging Multiple Inferiors Connections and Programs
3086
3087@value{GDBN} lets you run and debug multiple programs in a single
3088session.  In addition, @value{GDBN} on some systems may let you run
3089several programs simultaneously (otherwise you have to exit from one
3090before starting another).  On some systems @value{GDBN} may even let
3091you debug several programs simultaneously on different remote systems.
3092In the most general case, you can have multiple threads of execution
3093in each of multiple processes, launched from multiple executables,
3094running on different machines.
3095
3096@cindex inferior
3097@value{GDBN} represents the state of each program execution with an
3098object called an @dfn{inferior}.  An inferior typically corresponds to
3099a process, but is more general and applies also to targets that do not
3100have processes.  Inferiors may be created before a process runs, and
3101may be retained after a process exits.  Inferiors have unique
3102identifiers that are different from process ids.  Usually each
3103inferior will also have its own distinct address space, although some
3104embedded targets may have several inferiors running in different parts
3105of a single address space.  Each inferior may in turn have multiple
3106threads running in it.
3107
3108To find out what inferiors exist at any moment, use @w{@code{info
3109inferiors}}:
3110
3111@table @code
3112@kindex info inferiors [ @var{id}@dots{} ]
3113@item info inferiors
3114Print a list of all inferiors currently being managed by @value{GDBN}.
3115By default all inferiors are printed, but the argument @var{id}@dots{}
3116-- a space separated list of inferior numbers -- can be used to limit
3117the display to just the requested inferiors.
3118
3119@value{GDBN} displays for each inferior (in this order):
3120
3121@enumerate
3122@item
3123the inferior number assigned by @value{GDBN}
3124
3125@item
3126the target system's inferior identifier
3127
3128@item
3129the target connection the inferior is bound to, including the unique
3130connection number assigned by @value{GDBN}, and the protocol used by
3131the connection.
3132
3133@item
3134the name of the executable the inferior is running.
3135
3136@end enumerate
3137
3138@noindent
3139An asterisk @samp{*} preceding the @value{GDBN} inferior number
3140indicates the current inferior.
3141
3142For example,
3143@end table
3144@c end table here to get a little more width for example
3145
3146@smallexample
3147(@value{GDBP}) info inferiors
3148  Num  Description       Connection                      Executable
3149* 1    process 3401      1 (native)                      goodbye
3150  2    process 2307      2 (extended-remote host:10000)  hello
3151@end smallexample
3152
3153To find out what open target connections exist at any moment, use
3154@w{@code{info connections}}:
3155
3156@table @code
3157@kindex info connections [ @var{id}@dots{} ]
3158@item info connections
3159Print a list of all open target connections currently being managed by
3160@value{GDBN}.  By default all connections are printed, but the
3161argument @var{id}@dots{} -- a space separated list of connections
3162numbers -- can be used to limit the display to just the requested
3163connections.
3164
3165@value{GDBN} displays for each connection (in this order):
3166
3167@enumerate
3168@item
3169the connection number assigned by @value{GDBN}.
3170
3171@item
3172the protocol used by the connection.
3173
3174@item
3175a textual description of the protocol used by the connection.
3176
3177@end enumerate
3178
3179@noindent
3180An asterisk @samp{*} preceding the connection number indicates the
3181connection of the current inferior.
3182
3183For example,
3184@end table
3185@c end table here to get a little more width for example
3186
3187@smallexample
3188(@value{GDBP}) info connections
3189  Num  What                        Description
3190* 1    extended-remote host:10000  Extended remote serial target in gdb-specific protocol
3191  2    native                      Native process
3192  3    core                        Local core dump file
3193@end smallexample
3194
3195To switch focus between inferiors, use the @code{inferior} command:
3196
3197@table @code
3198@kindex inferior @var{infno}
3199@item inferior @var{infno}
3200Make inferior number @var{infno} the current inferior.  The argument
3201@var{infno} is the inferior number assigned by @value{GDBN}, as shown
3202in the first field of the @samp{info inferiors} display.
3203@end table
3204
3205@vindex $_inferior@r{, convenience variable}
3206The debugger convenience variable @samp{$_inferior} contains the
3207number of the current inferior.  You may find this useful in writing
3208breakpoint conditional expressions, command scripts, and so forth.
3209@xref{Convenience Vars,, Convenience Variables}, for general
3210information on convenience variables.
3211
3212You can get multiple executables into a debugging session via the
3213@code{add-inferior} and @w{@code{clone-inferior}} commands.  On some
3214systems @value{GDBN} can add inferiors to the debug session
3215automatically by following calls to @code{fork} and @code{exec}.  To
3216remove inferiors from the debugging session use the
3217@w{@code{remove-inferiors}} command.
3218
3219@table @code
3220@kindex add-inferior
3221@item add-inferior [ -copies @var{n} ] [ -exec @var{executable} ] [-no-connection ]
3222Adds @var{n} inferiors to be run using @var{executable} as the
3223executable; @var{n} defaults to 1.  If no executable is specified,
3224the inferiors begins empty, with no program.  You can still assign or
3225change the program assigned to the inferior at any time by using the
3226@code{file} command with the executable name as its argument.
3227
3228By default, the new inferior begins connected to the same target
3229connection as the current inferior.  For example, if the current
3230inferior was connected to @code{gdbserver} with @code{target remote},
3231then the new inferior will be connected to the same @code{gdbserver}
3232instance.  The @samp{-no-connection} option starts the new inferior
3233with no connection yet.  You can then for example use the @code{target
3234remote} command to connect to some other @code{gdbserver} instance,
3235use @code{run} to spawn a local program, etc.
3236
3237@kindex clone-inferior
3238@item clone-inferior [ -copies @var{n} ] [ @var{infno} ]
3239Adds @var{n} inferiors ready to execute the same program as inferior
3240@var{infno}; @var{n} defaults to 1, and @var{infno} defaults to the
3241number of the current inferior.  This is a convenient command when you
3242want to run another instance of the inferior you are debugging.
3243
3244@smallexample
3245(@value{GDBP}) info inferiors
3246  Num  Description       Connection   Executable
3247* 1    process 29964     1 (native)   helloworld
3248(@value{GDBP}) clone-inferior
3249Added inferior 2.
32501 inferiors added.
3251(@value{GDBP}) info inferiors
3252  Num  Description       Connection   Executable
3253* 1    process 29964     1 (native)   helloworld
3254  2    <null>            1 (native)   helloworld
3255@end smallexample
3256
3257You can now simply switch focus to inferior 2 and run it.
3258
3259@kindex remove-inferiors
3260@item remove-inferiors @var{infno}@dots{}
3261Removes the inferior or inferiors @var{infno}@dots{}.  It is not
3262possible to remove an inferior that is running with this command.  For
3263those, use the @code{kill} or @code{detach} command first.
3264
3265@end table
3266
3267To quit debugging one of the running inferiors that is not the current
3268inferior, you can either detach from it by using the @w{@code{detach
3269inferior}} command (allowing it to run independently), or kill it
3270using the @w{@code{kill inferiors}} command:
3271
3272@table @code
3273@kindex detach inferiors @var{infno}@dots{}
3274@item detach inferior @var{infno}@dots{}
3275Detach from the inferior or inferiors identified by @value{GDBN}
3276inferior number(s) @var{infno}@dots{}.  Note that the inferior's entry
3277still stays on the list of inferiors shown by @code{info inferiors},
3278but its Description will show @samp{<null>}.
3279
3280@kindex kill inferiors @var{infno}@dots{}
3281@item kill inferiors @var{infno}@dots{}
3282Kill the inferior or inferiors identified by @value{GDBN} inferior
3283number(s) @var{infno}@dots{}.  Note that the inferior's entry still
3284stays on the list of inferiors shown by @code{info inferiors}, but its
3285Description will show @samp{<null>}.
3286@end table
3287
3288After the successful completion of a command such as @code{detach},
3289@code{detach inferiors}, @code{kill} or @code{kill inferiors}, or after
3290a normal process exit, the inferior is still valid and listed with
3291@code{info inferiors}, ready to be restarted.
3292
3293
3294To be notified when inferiors are started or exit under @value{GDBN}'s
3295control use @w{@code{set print inferior-events}}:
3296
3297@table @code
3298@kindex set print inferior-events
3299@cindex print messages on inferior start and exit
3300@item set print inferior-events
3301@itemx set print inferior-events on
3302@itemx set print inferior-events off
3303The @code{set print inferior-events} command allows you to enable or
3304disable printing of messages when @value{GDBN} notices that new
3305inferiors have started or that inferiors have exited or have been
3306detached.  By default, these messages will not be printed.
3307
3308@kindex show print inferior-events
3309@item show print inferior-events
3310Show whether messages will be printed when @value{GDBN} detects that
3311inferiors have started, exited or have been detached.
3312@end table
3313
3314Many commands will work the same with multiple programs as with a
3315single program: e.g., @code{print myglobal} will simply display the
3316value of @code{myglobal} in the current inferior.
3317
3318
3319Occasionally, when debugging @value{GDBN} itself, it may be useful to
3320get more info about the relationship of inferiors, programs, address
3321spaces in a debug session.  You can do that with the @w{@code{maint
3322info program-spaces}} command.
3323
3324@table @code
3325@kindex maint info program-spaces
3326@item maint info program-spaces
3327Print a list of all program spaces currently being managed by
3328@value{GDBN}.
3329
3330@value{GDBN} displays for each program space (in this order):
3331
3332@enumerate
3333@item
3334the program space number assigned by @value{GDBN}
3335
3336@item
3337the name of the executable loaded into the program space, with e.g.,
3338the @code{file} command.
3339
3340@end enumerate
3341
3342@noindent
3343An asterisk @samp{*} preceding the @value{GDBN} program space number
3344indicates the current program space.
3345
3346In addition, below each program space line, @value{GDBN} prints extra
3347information that isn't suitable to display in tabular form.  For
3348example, the list of inferiors bound to the program space.
3349
3350@smallexample
3351(@value{GDBP}) maint info program-spaces
3352  Id   Executable
3353* 1    hello
3354  2    goodbye
3355        Bound inferiors: ID 1 (process 21561)
3356@end smallexample
3357
3358Here we can see that no inferior is running the program @code{hello},
3359while @code{process 21561} is running the program @code{goodbye}.  On
3360some targets, it is possible that multiple inferiors are bound to the
3361same program space.  The most common example is that of debugging both
3362the parent and child processes of a @code{vfork} call.  For example,
3363
3364@smallexample
3365(@value{GDBP}) maint info program-spaces
3366  Id   Executable
3367* 1    vfork-test
3368        Bound inferiors: ID 2 (process 18050), ID 1 (process 18045)
3369@end smallexample
3370
3371Here, both inferior 2 and inferior 1 are running in the same program
3372space as a result of inferior 1 having executed a @code{vfork} call.
3373@end table
3374
3375@node Threads
3376@section Debugging Programs with Multiple Threads
3377
3378@cindex threads of execution
3379@cindex multiple threads
3380@cindex switching threads
3381In some operating systems, such as GNU/Linux and Solaris, a single program
3382may have more than one @dfn{thread} of execution.  The precise semantics
3383of threads differ from one operating system to another, but in general
3384the threads of a single program are akin to multiple processes---except
3385that they share one address space (that is, they can all examine and
3386modify the same variables).  On the other hand, each thread has its own
3387registers and execution stack, and perhaps private memory.
3388
3389@value{GDBN} provides these facilities for debugging multi-thread
3390programs:
3391
3392@itemize @bullet
3393@item automatic notification of new threads
3394@item @samp{thread @var{thread-id}}, a command to switch among threads
3395@item @samp{info threads}, a command to inquire about existing threads
3396@item @samp{thread apply [@var{thread-id-list} | all] @var{args}},
3397a command to apply a command to a list of threads
3398@item thread-specific breakpoints
3399@item @samp{set print thread-events}, which controls printing of
3400messages on thread start and exit.
3401@item @samp{set libthread-db-search-path @var{path}}, which lets
3402the user specify which @code{libthread_db} to use if the default choice
3403isn't compatible with the program.
3404@end itemize
3405
3406@cindex focus of debugging
3407@cindex current thread
3408The @value{GDBN} thread debugging facility allows you to observe all
3409threads while your program runs---but whenever @value{GDBN} takes
3410control, one thread in particular is always the focus of debugging.
3411This thread is called the @dfn{current thread}.  Debugging commands show
3412program information from the perspective of the current thread.
3413
3414@cindex @code{New} @var{systag} message
3415@cindex thread identifier (system)
3416@c FIXME-implementors!! It would be more helpful if the [New...] message
3417@c included GDB's numeric thread handle, so you could just go to that
3418@c thread without first checking `info threads'.
3419Whenever @value{GDBN} detects a new thread in your program, it displays
3420the target system's identification for the thread with a message in the
3421form @samp{[New @var{systag}]}, where @var{systag} is a thread identifier
3422whose form varies depending on the particular system.  For example, on
3423@sc{gnu}/Linux, you might see
3424
3425@smallexample
3426[New Thread 0x41e02940 (LWP 25582)]
3427@end smallexample
3428
3429@noindent
3430when @value{GDBN} notices a new thread.  In contrast, on other systems,
3431the @var{systag} is simply something like @samp{process 368}, with no
3432further qualifier.
3433
3434@c FIXME!! (1) Does the [New...] message appear even for the very first
3435@c         thread of a program, or does it only appear for the
3436@c         second---i.e.@: when it becomes obvious we have a multithread
3437@c         program?
3438@c         (2) *Is* there necessarily a first thread always?  Or do some
3439@c         multithread systems permit starting a program with multiple
3440@c         threads ab initio?
3441
3442@anchor{thread numbers}
3443@cindex thread number, per inferior
3444@cindex thread identifier (GDB)
3445For debugging purposes, @value{GDBN} associates its own thread number
3446---always a single integer---with each thread of an inferior.  This
3447number is unique between all threads of an inferior, but not unique
3448between threads of different inferiors.
3449
3450@cindex qualified thread ID
3451You can refer to a given thread in an inferior using the qualified
3452@var{inferior-num}.@var{thread-num} syntax, also known as
3453@dfn{qualified thread ID}, with @var{inferior-num} being the inferior
3454number and @var{thread-num} being the thread number of the given
3455inferior.  For example, thread @code{2.3} refers to thread number 3 of
3456inferior 2.  If you omit @var{inferior-num} (e.g., @code{thread 3}),
3457then @value{GDBN} infers you're referring to a thread of the current
3458inferior.
3459
3460Until you create a second inferior, @value{GDBN} does not show the
3461@var{inferior-num} part of thread IDs, even though you can always use
3462the full @var{inferior-num}.@var{thread-num} form to refer to threads
3463of inferior 1, the initial inferior.
3464
3465@anchor{thread ID lists}
3466@cindex thread ID lists
3467Some commands accept a space-separated @dfn{thread ID list} as
3468argument.  A list element can be:
3469
3470@enumerate
3471@item
3472A thread ID as shown in the first field of the @samp{info threads}
3473display, with or without an inferior qualifier.  E.g., @samp{2.1} or
3474@samp{1}.
3475
3476@item
3477A range of thread numbers, again with or without an inferior
3478qualifier, as in @var{inf}.@var{thr1}-@var{thr2} or
3479@var{thr1}-@var{thr2}.  E.g., @samp{1.2-4} or @samp{2-4}.
3480
3481@item
3482All threads of an inferior, specified with a star wildcard, with or
3483without an inferior qualifier, as in @var{inf}.@code{*} (e.g.,
3484@samp{1.*}) or @code{*}.  The former refers to all threads of the
3485given inferior, and the latter form without an inferior qualifier
3486refers to all threads of the current inferior.
3487
3488@end enumerate
3489
3490For example, if the current inferior is 1, and inferior 7 has one
3491thread with ID 7.1, the thread list @samp{1 2-3 4.5 6.7-9 7.*}
3492includes threads 1 to 3 of inferior 1, thread 5 of inferior 4, threads
34937 to 9 of inferior 6 and all threads of inferior 7.  That is, in
3494expanded qualified form, the same as @samp{1.1 1.2 1.3 4.5 6.7 6.8 6.9
34957.1}.
3496
3497
3498@anchor{global thread numbers}
3499@cindex global thread number
3500@cindex global thread identifier (GDB)
3501In addition to a @emph{per-inferior} number, each thread is also
3502assigned a unique @emph{global} number, also known as @dfn{global
3503thread ID}, a single integer.  Unlike the thread number component of
3504the thread ID, no two threads have the same global ID, even when
3505you're debugging multiple inferiors.
3506
3507From @value{GDBN}'s perspective, a process always has at least one
3508thread.  In other words, @value{GDBN} assigns a thread number to the
3509program's ``main thread'' even if the program is not multi-threaded.
3510
3511@vindex $_thread@r{, convenience variable}
3512@vindex $_gthread@r{, convenience variable}
3513The debugger convenience variables @samp{$_thread} and
3514@samp{$_gthread} contain, respectively, the per-inferior thread number
3515and the global thread number of the current thread.  You may find this
3516useful in writing breakpoint conditional expressions, command scripts,
3517and so forth.  @xref{Convenience Vars,, Convenience Variables}, for
3518general information on convenience variables.
3519
3520If @value{GDBN} detects the program is multi-threaded, it augments the
3521usual message about stopping at a breakpoint with the ID and name of
3522the thread that hit the breakpoint.
3523
3524@smallexample
3525Thread 2 "client" hit Breakpoint 1, send_message () at client.c:68
3526@end smallexample
3527
3528Likewise when the program receives a signal:
3529
3530@smallexample
3531Thread 1 "main" received signal SIGINT, Interrupt.
3532@end smallexample
3533
3534@table @code
3535@kindex info threads
3536@item info threads @r{[}@var{thread-id-list}@r{]}
3537
3538Display information about one or more threads.  With no arguments
3539displays information about all threads.  You can specify the list of
3540threads that you want to display using the thread ID list syntax
3541(@pxref{thread ID lists}).
3542
3543@value{GDBN} displays for each thread (in this order):
3544
3545@enumerate
3546@item
3547the per-inferior thread number assigned by @value{GDBN}
3548
3549@item
3550the global thread number assigned by @value{GDBN}, if the @samp{-gid}
3551option was specified
3552
3553@item
3554the target system's thread identifier (@var{systag})
3555
3556@item
3557the thread's name, if one is known.  A thread can either be named by
3558the user (see @code{thread name}, below), or, in some cases, by the
3559program itself.
3560
3561@item
3562the current stack frame summary for that thread
3563@end enumerate
3564
3565@noindent
3566An asterisk @samp{*} to the left of the @value{GDBN} thread number
3567indicates the current thread.
3568
3569For example,
3570@end table
3571@c end table here to get a little more width for example
3572
3573@smallexample
3574(@value{GDBP}) info threads
3575  Id   Target Id             Frame
3576* 1    process 35 thread 13  main (argc=1, argv=0x7ffffff8)
3577  2    process 35 thread 23  0x34e5 in sigpause ()
3578  3    process 35 thread 27  0x34e5 in sigpause ()
3579    at threadtest.c:68
3580@end smallexample
3581
3582If you're debugging multiple inferiors, @value{GDBN} displays thread
3583IDs using the qualified @var{inferior-num}.@var{thread-num} format.
3584Otherwise, only @var{thread-num} is shown.
3585
3586If you specify the @samp{-gid} option, @value{GDBN} displays a column
3587indicating each thread's global thread ID:
3588
3589@smallexample
3590(@value{GDBP}) info threads
3591  Id   GId  Target Id             Frame
3592  1.1  1    process 35 thread 13  main (argc=1, argv=0x7ffffff8)
3593  1.2  3    process 35 thread 23  0x34e5 in sigpause ()
3594  1.3  4    process 35 thread 27  0x34e5 in sigpause ()
3595* 2.1  2    process 65 thread 1   main (argc=1, argv=0x7ffffff8)
3596@end smallexample
3597
3598On Solaris, you can display more information about user threads with a
3599Solaris-specific command:
3600
3601@table @code
3602@item maint info sol-threads
3603@kindex maint info sol-threads
3604@cindex thread info (Solaris)
3605Display info on Solaris user threads.
3606@end table
3607
3608@table @code
3609@kindex thread @var{thread-id}
3610@item thread @var{thread-id}
3611Make thread ID @var{thread-id} the current thread.  The command
3612argument @var{thread-id} is the @value{GDBN} thread ID, as shown in
3613the first field of the @samp{info threads} display, with or without an
3614inferior qualifier (e.g., @samp{2.1} or @samp{1}).
3615
3616@value{GDBN} responds by displaying the system identifier of the
3617thread you selected, and its current stack frame summary:
3618
3619@smallexample
3620(@value{GDBP}) thread 2
3621[Switching to thread 2 (Thread 0xb7fdab70 (LWP 12747))]
3622#0  some_function (ignore=0x0) at example.c:8
36238	    printf ("hello\n");
3624@end smallexample
3625
3626@noindent
3627As with the @samp{[New @dots{}]} message, the form of the text after
3628@samp{Switching to} depends on your system's conventions for identifying
3629threads.
3630
3631@anchor{thread apply all}
3632@kindex thread apply
3633@cindex apply command to several threads
3634@item thread apply [@var{thread-id-list} | all [-ascending]] [@var{flag}]@dots{} @var{command}
3635The @code{thread apply} command allows you to apply the named
3636@var{command} to one or more threads.  Specify the threads that you
3637want affected using the thread ID list syntax (@pxref{thread ID
3638lists}), or specify @code{all} to apply to all threads.  To apply a
3639command to all threads in descending order, type @kbd{thread apply all
3640@var{command}}.  To apply a command to all threads in ascending order,
3641type @kbd{thread apply all -ascending @var{command}}.
3642
3643The @var{flag} arguments control what output to produce and how to handle
3644errors raised when applying @var{command} to a thread.  @var{flag}
3645must start with a @code{-} directly followed by one letter in
3646@code{qcs}.  If several flags are provided, they must be given
3647individually, such as @code{-c -q}.
3648
3649By default, @value{GDBN} displays some thread information before the
3650output produced by @var{command}, and an error raised during the
3651execution of a @var{command} will abort @code{thread apply}.  The
3652following flags can be used to fine-tune this behavior:
3653
3654@table @code
3655@item -c
3656The flag @code{-c}, which stands for @samp{continue}, causes any
3657errors in @var{command} to be displayed, and the execution of
3658@code{thread apply} then continues.
3659@item -s
3660The flag @code{-s}, which stands for @samp{silent}, causes any errors
3661or empty output produced by a @var{command} to be silently ignored.
3662That is, the execution continues, but the thread information and errors
3663are not printed.
3664@item -q
3665The flag @code{-q} (@samp{quiet}) disables printing the thread
3666information.
3667@end table
3668
3669Flags @code{-c} and @code{-s} cannot be used together.
3670
3671@kindex taas
3672@cindex apply command to all threads (ignoring errors and empty output)
3673@item taas [@var{option}]@dots{} @var{command}
3674Shortcut for @code{thread apply all -s [@var{option}]@dots{} @var{command}}.
3675Applies @var{command} on all threads, ignoring errors and empty output.
3676
3677The @code{taas} command accepts the same options as the @code{thread
3678apply all} command.  @xref{thread apply all}.
3679
3680@kindex tfaas
3681@cindex apply a command to all frames of all threads (ignoring errors and empty output)
3682@item tfaas [@var{option}]@dots{} @var{command}
3683Shortcut for @code{thread apply all -s -- frame apply all -s [@var{option}]@dots{} @var{command}}.
3684Applies @var{command} on all frames of all threads, ignoring errors
3685and empty output.  Note that the flag @code{-s} is specified twice:
3686The first @code{-s} ensures that @code{thread apply} only shows the thread
3687information of the threads for which @code{frame apply} produces
3688some output.  The second @code{-s} is needed to ensure that @code{frame
3689apply} shows the frame information of a frame only if the
3690@var{command} successfully produced some output.
3691
3692It can for example be used to print a local variable or a function
3693argument without knowing the thread or frame where this variable or argument
3694is, using:
3695@smallexample
3696(@value{GDBP}) tfaas p some_local_var_i_do_not_remember_where_it_is
3697@end smallexample
3698
3699The @code{tfaas} command accepts the same options as the @code{frame
3700apply} command.  @xref{Frame Apply,,frame apply}.
3701
3702@kindex thread name
3703@cindex name a thread
3704@item thread name [@var{name}]
3705This command assigns a name to the current thread.  If no argument is
3706given, any existing user-specified name is removed.  The thread name
3707appears in the @samp{info threads} display.
3708
3709On some systems, such as @sc{gnu}/Linux, @value{GDBN} is able to
3710determine the name of the thread as given by the OS.  On these
3711systems, a name specified with @samp{thread name} will override the
3712system-give name, and removing the user-specified name will cause
3713@value{GDBN} to once again display the system-specified name.
3714
3715@kindex thread find
3716@cindex search for a thread
3717@item thread find [@var{regexp}]
3718Search for and display thread ids whose name or @var{systag}
3719matches the supplied regular expression.
3720
3721As well as being the complement to the @samp{thread name} command,
3722this command also allows you to identify a thread by its target
3723@var{systag}.  For instance, on @sc{gnu}/Linux, the target @var{systag}
3724is the LWP id.
3725
3726@smallexample
3727(@value{GDBN}) thread find 26688
3728Thread 4 has target id 'Thread 0x41e02940 (LWP 26688)'
3729(@value{GDBN}) info thread 4
3730  Id   Target Id         Frame
3731  4    Thread 0x41e02940 (LWP 26688) 0x00000031ca6cd372 in select ()
3732@end smallexample
3733
3734@kindex set print thread-events
3735@cindex print messages on thread start and exit
3736@item set print thread-events
3737@itemx set print thread-events on
3738@itemx set print thread-events off
3739The @code{set print thread-events} command allows you to enable or
3740disable printing of messages when @value{GDBN} notices that new threads have
3741started or that threads have exited.  By default, these messages will
3742be printed if detection of these events is supported by the target.
3743Note that these messages cannot be disabled on all targets.
3744
3745@kindex show print thread-events
3746@item show print thread-events
3747Show whether messages will be printed when @value{GDBN} detects that threads
3748have started and exited.
3749@end table
3750
3751@xref{Thread Stops,,Stopping and Starting Multi-thread Programs}, for
3752more information about how @value{GDBN} behaves when you stop and start
3753programs with multiple threads.
3754
3755@xref{Set Watchpoints,,Setting Watchpoints}, for information about
3756watchpoints in programs with multiple threads.
3757
3758@anchor{set libthread-db-search-path}
3759@table @code
3760@kindex set libthread-db-search-path
3761@cindex search path for @code{libthread_db}
3762@item set libthread-db-search-path @r{[}@var{path}@r{]}
3763If this variable is set, @var{path} is a colon-separated list of
3764directories @value{GDBN} will use to search for @code{libthread_db}.
3765If you omit @var{path}, @samp{libthread-db-search-path} will be reset to
3766its default value (@code{$sdir:$pdir} on @sc{gnu}/Linux and Solaris systems).
3767Internally, the default value comes from the @code{LIBTHREAD_DB_SEARCH_PATH}
3768macro.
3769
3770On @sc{gnu}/Linux and Solaris systems, @value{GDBN} uses a ``helper''
3771@code{libthread_db} library to obtain information about threads in the
3772inferior process.  @value{GDBN} will use @samp{libthread-db-search-path}
3773to find @code{libthread_db}.  @value{GDBN} also consults first if inferior
3774specific thread debugging library loading is enabled
3775by @samp{set auto-load libthread-db} (@pxref{libthread_db.so.1 file}).
3776
3777A special entry @samp{$sdir} for @samp{libthread-db-search-path}
3778refers to the default system directories that are
3779normally searched for loading shared libraries.  The @samp{$sdir} entry
3780is the only kind not needing to be enabled by @samp{set auto-load libthread-db}
3781(@pxref{libthread_db.so.1 file}).
3782
3783A special entry @samp{$pdir} for @samp{libthread-db-search-path}
3784refers to the directory from which @code{libpthread}
3785was loaded in the inferior process.
3786
3787For any @code{libthread_db} library @value{GDBN} finds in above directories,
3788@value{GDBN} attempts to initialize it with the current inferior process.
3789If this initialization fails (which could happen because of a version
3790mismatch between @code{libthread_db} and @code{libpthread}), @value{GDBN}
3791will unload @code{libthread_db}, and continue with the next directory.
3792If none of @code{libthread_db} libraries initialize successfully,
3793@value{GDBN} will issue a warning and thread debugging will be disabled.
3794
3795Setting @code{libthread-db-search-path} is currently implemented
3796only on some platforms.
3797
3798@kindex show libthread-db-search-path
3799@item show libthread-db-search-path
3800Display current libthread_db search path.
3801
3802@kindex set debug libthread-db
3803@kindex show debug libthread-db
3804@cindex debugging @code{libthread_db}
3805@item set debug libthread-db
3806@itemx show debug libthread-db
3807Turns on or off display of @code{libthread_db}-related events.
3808Use @code{1} to enable, @code{0} to disable.
3809@end table
3810
3811@node Forks
3812@section Debugging Forks
3813
3814@cindex fork, debugging programs which call
3815@cindex multiple processes
3816@cindex processes, multiple
3817On most systems, @value{GDBN} has no special support for debugging
3818programs which create additional processes using the @code{fork}
3819function.  When a program forks, @value{GDBN} will continue to debug the
3820parent process and the child process will run unimpeded.  If you have
3821set a breakpoint in any code which the child then executes, the child
3822will get a @code{SIGTRAP} signal which (unless it catches the signal)
3823will cause it to terminate.
3824
3825However, if you want to debug the child process there is a workaround
3826which isn't too painful.  Put a call to @code{sleep} in the code which
3827the child process executes after the fork.  It may be useful to sleep
3828only if a certain environment variable is set, or a certain file exists,
3829so that the delay need not occur when you don't want to run @value{GDBN}
3830on the child.  While the child is sleeping, use the @code{ps} program to
3831get its process ID.  Then tell @value{GDBN} (a new invocation of
3832@value{GDBN} if you are also debugging the parent process) to attach to
3833the child process (@pxref{Attach}).  From that point on you can debug
3834the child process just like any other process which you attached to.
3835
3836On some systems, @value{GDBN} provides support for debugging programs
3837that create additional processes using the @code{fork} or @code{vfork}
3838functions.  On @sc{gnu}/Linux platforms, this feature is supported
3839with kernel version 2.5.46 and later.
3840
3841The fork debugging commands are supported in native mode and when
3842connected to @code{gdbserver} in either @code{target remote} mode or
3843@code{target extended-remote} mode.
3844
3845By default, when a program forks, @value{GDBN} will continue to debug
3846the parent process and the child process will run unimpeded.
3847
3848If you want to follow the child process instead of the parent process,
3849use the command @w{@code{set follow-fork-mode}}.
3850
3851@table @code
3852@kindex set follow-fork-mode
3853@item set follow-fork-mode @var{mode}
3854Set the debugger response to a program call of @code{fork} or
3855@code{vfork}.  A call to @code{fork} or @code{vfork} creates a new
3856process.  The @var{mode} argument can be:
3857
3858@table @code
3859@item parent
3860The original process is debugged after a fork.  The child process runs
3861unimpeded.  This is the default.
3862
3863@item child
3864The new process is debugged after a fork.  The parent process runs
3865unimpeded.
3866
3867@end table
3868
3869@kindex show follow-fork-mode
3870@item show follow-fork-mode
3871Display the current debugger response to a @code{fork} or @code{vfork} call.
3872@end table
3873
3874@cindex debugging multiple processes
3875On Linux, if you want to debug both the parent and child processes, use the
3876command @w{@code{set detach-on-fork}}.
3877
3878@table @code
3879@kindex set detach-on-fork
3880@item set detach-on-fork @var{mode}
3881Tells gdb whether to detach one of the processes after a fork, or
3882retain debugger control over them both.
3883
3884@table @code
3885@item on
3886The child process (or parent process, depending on the value of
3887@code{follow-fork-mode}) will be detached and allowed to run
3888independently.  This is the default.
3889
3890@item off
3891Both processes will be held under the control of @value{GDBN}.
3892One process (child or parent, depending on the value of
3893@code{follow-fork-mode}) is debugged as usual, while the other
3894is held suspended.
3895
3896@end table
3897
3898@kindex show detach-on-fork
3899@item show detach-on-fork
3900Show whether detach-on-fork mode is on/off.
3901@end table
3902
3903If you choose to set @samp{detach-on-fork} mode off, then @value{GDBN}
3904will retain control of all forked processes (including nested forks).
3905You can list the forked processes under the control of @value{GDBN} by
3906using the @w{@code{info inferiors}} command, and switch from one fork
3907to another by using the @code{inferior} command (@pxref{Inferiors Connections and
3908Programs, ,Debugging Multiple Inferiors Connections and Programs}).
3909
3910To quit debugging one of the forked processes, you can either detach
3911from it by using the @w{@code{detach inferiors}} command (allowing it
3912to run independently), or kill it using the @w{@code{kill inferiors}}
3913command.  @xref{Inferiors Connections and Programs, ,Debugging
3914Multiple Inferiors Connections and Programs}.
3915
3916If you ask to debug a child process and a @code{vfork} is followed by an
3917@code{exec}, @value{GDBN} executes the new target up to the first
3918breakpoint in the new target.  If you have a breakpoint set on
3919@code{main} in your original program, the breakpoint will also be set on
3920the child process's @code{main}.
3921
3922On some systems, when a child process is spawned by @code{vfork}, you
3923cannot debug the child or parent until an @code{exec} call completes.
3924
3925If you issue a @code{run} command to @value{GDBN} after an @code{exec}
3926call executes, the new target restarts.  To restart the parent
3927process, use the @code{file} command with the parent executable name
3928as its argument.  By default, after an @code{exec} call executes,
3929@value{GDBN} discards the symbols of the previous executable image.
3930You can change this behaviour with the @w{@code{set follow-exec-mode}}
3931command.
3932
3933@table @code
3934@kindex set follow-exec-mode
3935@item set follow-exec-mode @var{mode}
3936
3937Set debugger response to a program call of @code{exec}.  An
3938@code{exec} call replaces the program image of a process.
3939
3940@code{follow-exec-mode} can be:
3941
3942@table @code
3943@item new
3944@value{GDBN} creates a new inferior and rebinds the process to this
3945new inferior.  The program the process was running before the
3946@code{exec} call can be restarted afterwards by restarting the
3947original inferior.
3948
3949For example:
3950
3951@smallexample
3952(@value{GDBP}) info inferiors
3953(gdb) info inferior
3954  Id   Description   Executable
3955* 1    <null>        prog1
3956(@value{GDBP}) run
3957process 12020 is executing new program: prog2
3958Program exited normally.
3959(@value{GDBP}) info inferiors
3960  Id   Description   Executable
3961  1    <null>        prog1
3962* 2    <null>        prog2
3963@end smallexample
3964
3965@item same
3966@value{GDBN} keeps the process bound to the same inferior.  The new
3967executable image replaces the previous executable loaded in the
3968inferior.  Restarting the inferior after the @code{exec} call, with
3969e.g., the @code{run} command, restarts the executable the process was
3970running after the @code{exec} call.  This is the default mode.
3971
3972For example:
3973
3974@smallexample
3975(@value{GDBP}) info inferiors
3976  Id   Description   Executable
3977* 1    <null>        prog1
3978(@value{GDBP}) run
3979process 12020 is executing new program: prog2
3980Program exited normally.
3981(@value{GDBP}) info inferiors
3982  Id   Description   Executable
3983* 1    <null>        prog2
3984@end smallexample
3985
3986@end table
3987@end table
3988
3989@code{follow-exec-mode} is supported in native mode and
3990@code{target extended-remote} mode.
3991
3992You can use the @code{catch} command to make @value{GDBN} stop whenever
3993a @code{fork}, @code{vfork}, or @code{exec} call is made.  @xref{Set
3994Catchpoints, ,Setting Catchpoints}.
3995
3996@node Checkpoint/Restart
3997@section Setting a @emph{Bookmark} to Return to Later
3998
3999@cindex checkpoint
4000@cindex restart
4001@cindex bookmark
4002@cindex snapshot of a process
4003@cindex rewind program state
4004
4005On certain operating systems@footnote{Currently, only
4006@sc{gnu}/Linux.}, @value{GDBN} is able to save a @dfn{snapshot} of a
4007program's state, called a @dfn{checkpoint}, and come back to it
4008later.
4009
4010Returning to a checkpoint effectively undoes everything that has
4011happened in the program since the @code{checkpoint} was saved.  This
4012includes changes in memory, registers, and even (within some limits)
4013system state.  Effectively, it is like going back in time to the
4014moment when the checkpoint was saved.
4015
4016Thus, if you're stepping thru a program and you think you're
4017getting close to the point where things go wrong, you can save
4018a checkpoint.  Then, if you accidentally go too far and miss
4019the critical statement, instead of having to restart your program
4020from the beginning, you can just go back to the checkpoint and
4021start again from there.
4022
4023This can be especially useful if it takes a lot of time or
4024steps to reach the point where you think the bug occurs.
4025
4026To use the @code{checkpoint}/@code{restart} method of debugging:
4027
4028@table @code
4029@kindex checkpoint
4030@item checkpoint
4031Save a snapshot of the debugged program's current execution state.
4032The @code{checkpoint} command takes no arguments, but each checkpoint
4033is assigned a small integer id, similar to a breakpoint id.
4034
4035@kindex info checkpoints
4036@item info checkpoints
4037List the checkpoints that have been saved in the current debugging
4038session.  For each checkpoint, the following information will be
4039listed:
4040
4041@table @code
4042@item Checkpoint ID
4043@item Process ID
4044@item Code Address
4045@item Source line, or label
4046@end table
4047
4048@kindex restart @var{checkpoint-id}
4049@item restart @var{checkpoint-id}
4050Restore the program state that was saved as checkpoint number
4051@var{checkpoint-id}.  All program variables, registers, stack frames
4052etc.@:  will be returned to the values that they had when the checkpoint
4053was saved.  In essence, gdb will ``wind back the clock'' to the point
4054in time when the checkpoint was saved.
4055
4056Note that breakpoints, @value{GDBN} variables, command history etc.
4057are not affected by restoring a checkpoint.  In general, a checkpoint
4058only restores things that reside in the program being debugged, not in
4059the debugger.
4060
4061@kindex delete checkpoint @var{checkpoint-id}
4062@item delete checkpoint @var{checkpoint-id}
4063Delete the previously-saved checkpoint identified by @var{checkpoint-id}.
4064
4065@end table
4066
4067Returning to a previously saved checkpoint will restore the user state
4068of the program being debugged, plus a significant subset of the system
4069(OS) state, including file pointers.  It won't ``un-write'' data from
4070a file, but it will rewind the file pointer to the previous location,
4071so that the previously written data can be overwritten.  For files
4072opened in read mode, the pointer will also be restored so that the
4073previously read data can be read again.
4074
4075Of course, characters that have been sent to a printer (or other
4076external device) cannot be ``snatched back'', and characters received
4077from eg.@: a serial device can be removed from internal program buffers,
4078but they cannot be ``pushed back'' into the serial pipeline, ready to
4079be received again.  Similarly, the actual contents of files that have
4080been changed cannot be restored (at this time).
4081
4082However, within those constraints, you actually can ``rewind'' your
4083program to a previously saved point in time, and begin debugging it
4084again --- and you can change the course of events so as to debug a
4085different execution path this time.
4086
4087@cindex checkpoints and process id
4088Finally, there is one bit of internal program state that will be
4089different when you return to a checkpoint --- the program's process
4090id.  Each checkpoint will have a unique process id (or @var{pid}),
4091and each will be different from the program's original @var{pid}.
4092If your program has saved a local copy of its process id, this could
4093potentially pose a problem.
4094
4095@subsection A Non-obvious Benefit of Using Checkpoints
4096
4097On some systems such as @sc{gnu}/Linux, address space randomization
4098is performed on new processes for security reasons.  This makes it
4099difficult or impossible to set a breakpoint, or watchpoint, on an
4100absolute address if you have to restart the program, since the
4101absolute location of a symbol will change from one execution to the
4102next.
4103
4104A checkpoint, however, is an @emph{identical} copy of a process.
4105Therefore if you create a checkpoint at (eg.@:) the start of main,
4106and simply return to that checkpoint instead of restarting the
4107process, you can avoid the effects of address randomization and
4108your symbols will all stay in the same place.
4109
4110@node Stopping
4111@chapter Stopping and Continuing
4112
4113The principal purposes of using a debugger are so that you can stop your
4114program before it terminates; or so that, if your program runs into
4115trouble, you can investigate and find out why.
4116
4117Inside @value{GDBN}, your program may stop for any of several reasons,
4118such as a signal, a breakpoint, or reaching a new line after a
4119@value{GDBN} command such as @code{step}.  You may then examine and
4120change variables, set new breakpoints or remove old ones, and then
4121continue execution.  Usually, the messages shown by @value{GDBN} provide
4122ample explanation of the status of your program---but you can also
4123explicitly request this information at any time.
4124
4125@table @code
4126@kindex info program
4127@item info program
4128Display information about the status of your program: whether it is
4129running or not, what process it is, and why it stopped.
4130@end table
4131
4132@menu
4133* Breakpoints::                 Breakpoints, watchpoints, and catchpoints
4134* Continuing and Stepping::     Resuming execution
4135* Skipping Over Functions and Files::
4136                                Skipping over functions and files
4137* Signals::                     Signals
4138* Thread Stops::                Stopping and starting multi-thread programs
4139@end menu
4140
4141@node Breakpoints
4142@section Breakpoints, Watchpoints, and Catchpoints
4143
4144@cindex breakpoints
4145A @dfn{breakpoint} makes your program stop whenever a certain point in
4146the program is reached.  For each breakpoint, you can add conditions to
4147control in finer detail whether your program stops.  You can set
4148breakpoints with the @code{break} command and its variants (@pxref{Set
4149Breaks, ,Setting Breakpoints}), to specify the place where your program
4150should stop by line number, function name or exact address in the
4151program.
4152
4153On some systems, you can set breakpoints in shared libraries before
4154the executable is run.
4155
4156@cindex watchpoints
4157@cindex data breakpoints
4158@cindex memory tracing
4159@cindex breakpoint on memory address
4160@cindex breakpoint on variable modification
4161A @dfn{watchpoint} is a special breakpoint that stops your program
4162when the value of an expression changes.  The expression may be a value
4163of a variable, or it could involve values of one or more variables
4164combined by operators, such as @samp{a + b}.  This is sometimes called
4165@dfn{data breakpoints}.  You must use a different command to set
4166watchpoints (@pxref{Set Watchpoints, ,Setting Watchpoints}), but aside
4167from that, you can manage a watchpoint like any other breakpoint: you
4168enable, disable, and delete both breakpoints and watchpoints using the
4169same commands.
4170
4171You can arrange to have values from your program displayed automatically
4172whenever @value{GDBN} stops at a breakpoint.  @xref{Auto Display,,
4173Automatic Display}.
4174
4175@cindex catchpoints
4176@cindex breakpoint on events
4177A @dfn{catchpoint} is another special breakpoint that stops your program
4178when a certain kind of event occurs, such as the throwing of a C@t{++}
4179exception or the loading of a library.  As with watchpoints, you use a
4180different command to set a catchpoint (@pxref{Set Catchpoints, ,Setting
4181Catchpoints}), but aside from that, you can manage a catchpoint like any
4182other breakpoint.  (To stop when your program receives a signal, use the
4183@code{handle} command; see @ref{Signals, ,Signals}.)
4184
4185@cindex breakpoint numbers
4186@cindex numbers for breakpoints
4187@value{GDBN} assigns a number to each breakpoint, watchpoint, or
4188catchpoint when you create it; these numbers are successive integers
4189starting with one.  In many of the commands for controlling various
4190features of breakpoints you use the breakpoint number to say which
4191breakpoint you want to change.  Each breakpoint may be @dfn{enabled} or
4192@dfn{disabled}; if disabled, it has no effect on your program until you
4193enable it again.
4194
4195@cindex breakpoint ranges
4196@cindex breakpoint lists
4197@cindex ranges of breakpoints
4198@cindex lists of breakpoints
4199Some @value{GDBN} commands accept a space-separated list of breakpoints
4200on which to operate.  A list element can be either a single breakpoint number,
4201like @samp{5}, or a range of such numbers, like @samp{5-7}.
4202When a breakpoint list is given to a command, all breakpoints in that list
4203are operated on.
4204
4205@menu
4206* Set Breaks::                  Setting breakpoints
4207* Set Watchpoints::             Setting watchpoints
4208* Set Catchpoints::             Setting catchpoints
4209* Delete Breaks::               Deleting breakpoints
4210* Disabling::                   Disabling breakpoints
4211* Conditions::                  Break conditions
4212* Break Commands::              Breakpoint command lists
4213* Dynamic Printf::              Dynamic printf
4214* Save Breakpoints::            How to save breakpoints in a file
4215* Static Probe Points::         Listing static probe points
4216* Error in Breakpoints::        ``Cannot insert breakpoints''
4217* Breakpoint-related Warnings:: ``Breakpoint address adjusted...''
4218@end menu
4219
4220@node Set Breaks
4221@subsection Setting Breakpoints
4222
4223@c FIXME LMB what does GDB do if no code on line of breakpt?
4224@c       consider in particular declaration with/without initialization.
4225@c
4226@c FIXME 2 is there stuff on this already? break at fun start, already init?
4227
4228@kindex break
4229@kindex b @r{(@code{break})}
4230@vindex $bpnum@r{, convenience variable}
4231@cindex latest breakpoint
4232Breakpoints are set with the @code{break} command (abbreviated
4233@code{b}).  The debugger convenience variable @samp{$bpnum} records the
4234number of the breakpoint you've set most recently; see @ref{Convenience
4235Vars,, Convenience Variables}, for a discussion of what you can do with
4236convenience variables.
4237
4238@table @code
4239@item break @var{location}
4240Set a breakpoint at the given @var{location}, which can specify a
4241function name, a line number, or an address of an instruction.
4242(@xref{Specify Location}, for a list of all the possible ways to
4243specify a @var{location}.)  The breakpoint will stop your program just
4244before it executes any of the code in the specified @var{location}.
4245
4246When using source languages that permit overloading of symbols, such as
4247C@t{++}, a function name may refer to more than one possible place to break.
4248@xref{Ambiguous Expressions,,Ambiguous Expressions}, for a discussion of
4249that situation.
4250
4251It is also possible to insert a breakpoint that will stop the program
4252only if a specific thread (@pxref{Thread-Specific Breakpoints})
4253or a specific task (@pxref{Ada Tasks}) hits that breakpoint.
4254
4255@item break
4256When called without any arguments, @code{break} sets a breakpoint at
4257the next instruction to be executed in the selected stack frame
4258(@pxref{Stack, ,Examining the Stack}).  In any selected frame but the
4259innermost, this makes your program stop as soon as control
4260returns to that frame.  This is similar to the effect of a
4261@code{finish} command in the frame inside the selected frame---except
4262that @code{finish} does not leave an active breakpoint.  If you use
4263@code{break} without an argument in the innermost frame, @value{GDBN} stops
4264the next time it reaches the current location; this may be useful
4265inside loops.
4266
4267@value{GDBN} normally ignores breakpoints when it resumes execution, until at
4268least one instruction has been executed.  If it did not do this, you
4269would be unable to proceed past a breakpoint without first disabling the
4270breakpoint.  This rule applies whether or not the breakpoint already
4271existed when your program stopped.
4272
4273@item break @dots{} if @var{cond}
4274Set a breakpoint with condition @var{cond}; evaluate the expression
4275@var{cond} each time the breakpoint is reached, and stop only if the
4276value is nonzero---that is, if @var{cond} evaluates as true.
4277@samp{@dots{}} stands for one of the possible arguments described
4278above (or no argument) specifying where to break.  @xref{Conditions,
4279,Break Conditions}, for more information on breakpoint conditions.
4280
4281@kindex tbreak
4282@item tbreak @var{args}
4283Set a breakpoint enabled only for one stop.  The @var{args} are the
4284same as for the @code{break} command, and the breakpoint is set in the same
4285way, but the breakpoint is automatically deleted after the first time your
4286program stops there.  @xref{Disabling, ,Disabling Breakpoints}.
4287
4288@kindex hbreak
4289@cindex hardware breakpoints
4290@item hbreak @var{args}
4291Set a hardware-assisted breakpoint.  The @var{args} are the same as for the
4292@code{break} command and the breakpoint is set in the same way, but the
4293breakpoint requires hardware support and some target hardware may not
4294have this support.  The main purpose of this is EPROM/ROM code
4295debugging, so you can set a breakpoint at an instruction without
4296changing the instruction.  This can be used with the new trap-generation
4297provided by SPARClite DSU and most x86-based targets.  These targets
4298will generate traps when a program accesses some data or instruction
4299address that is assigned to the debug registers.  However the hardware
4300breakpoint registers can take a limited number of breakpoints.  For
4301example, on the DSU, only two data breakpoints can be set at a time, and
4302@value{GDBN} will reject this command if more than two are used.  Delete
4303or disable unused hardware breakpoints before setting new ones
4304(@pxref{Disabling, ,Disabling Breakpoints}).
4305@xref{Conditions, ,Break Conditions}.
4306For remote targets, you can restrict the number of hardware
4307breakpoints @value{GDBN} will use, see @ref{set remote
4308hardware-breakpoint-limit}.
4309
4310@kindex thbreak
4311@item thbreak @var{args}
4312Set a hardware-assisted breakpoint enabled only for one stop.  The @var{args}
4313are the same as for the @code{hbreak} command and the breakpoint is set in
4314the same way.  However, like the @code{tbreak} command,
4315the breakpoint is automatically deleted after the
4316first time your program stops there.  Also, like the @code{hbreak}
4317command, the breakpoint requires hardware support and some target hardware
4318may not have this support.  @xref{Disabling, ,Disabling Breakpoints}.
4319See also @ref{Conditions, ,Break Conditions}.
4320
4321@kindex rbreak
4322@cindex regular expression
4323@cindex breakpoints at functions matching a regexp
4324@cindex set breakpoints in many functions
4325@item rbreak @var{regex}
4326Set breakpoints on all functions matching the regular expression
4327@var{regex}.  This command sets an unconditional breakpoint on all
4328matches, printing a list of all breakpoints it set.  Once these
4329breakpoints are set, they are treated just like the breakpoints set with
4330the @code{break} command.  You can delete them, disable them, or make
4331them conditional the same way as any other breakpoint.
4332
4333In programs using different languages, @value{GDBN} chooses the syntax
4334to print the list of all breakpoints it sets according to the
4335@samp{set language} value: using @samp{set language auto}
4336(see @ref{Automatically, ,Set Language Automatically}) means to use the
4337language of the breakpoint's function, other values mean to use
4338the manually specified language (see @ref{Manually, ,Set Language Manually}).
4339
4340The syntax of the regular expression is the standard one used with tools
4341like @file{grep}.  Note that this is different from the syntax used by
4342shells, so for instance @code{foo*} matches all functions that include
4343an @code{fo} followed by zero or more @code{o}s.  There is an implicit
4344@code{.*} leading and trailing the regular expression you supply, so to
4345match only functions that begin with @code{foo}, use @code{^foo}.
4346
4347@cindex non-member C@t{++} functions, set breakpoint in
4348When debugging C@t{++} programs, @code{rbreak} is useful for setting
4349breakpoints on overloaded functions that are not members of any special
4350classes.
4351
4352@cindex set breakpoints on all functions
4353The @code{rbreak} command can be used to set breakpoints in
4354@strong{all} the functions in a program, like this:
4355
4356@smallexample
4357(@value{GDBP}) rbreak .
4358@end smallexample
4359
4360@item rbreak @var{file}:@var{regex}
4361If @code{rbreak} is called with a filename qualification, it limits
4362the search for functions matching the given regular expression to the
4363specified @var{file}.  This can be used, for example, to set breakpoints on
4364every function in a given file:
4365
4366@smallexample
4367(@value{GDBP}) rbreak file.c:.
4368@end smallexample
4369
4370The colon separating the filename qualifier from the regex may
4371optionally be surrounded by spaces.
4372
4373@kindex info breakpoints
4374@cindex @code{$_} and @code{info breakpoints}
4375@item info breakpoints @r{[}@var{list}@dots{}@r{]}
4376@itemx info break @r{[}@var{list}@dots{}@r{]}
4377Print a table of all breakpoints, watchpoints, and catchpoints set and
4378not deleted.  Optional argument @var{n} means print information only
4379about the specified breakpoint(s) (or watchpoint(s) or catchpoint(s)).
4380For each breakpoint, following columns are printed:
4381
4382@table @emph
4383@item Breakpoint Numbers
4384@item Type
4385Breakpoint, watchpoint, or catchpoint.
4386@item Disposition
4387Whether the breakpoint is marked to be disabled or deleted when hit.
4388@item Enabled or Disabled
4389Enabled breakpoints are marked with @samp{y}.  @samp{n} marks breakpoints
4390that are not enabled.
4391@item Address
4392Where the breakpoint is in your program, as a memory address.  For a
4393pending breakpoint whose address is not yet known, this field will
4394contain @samp{<PENDING>}.  Such breakpoint won't fire until a shared
4395library that has the symbol or line referred by breakpoint is loaded.
4396See below for details.  A breakpoint with several locations will
4397have @samp{<MULTIPLE>} in this field---see below for details.
4398@item What
4399Where the breakpoint is in the source for your program, as a file and
4400line number.  For a pending breakpoint, the original string passed to
4401the breakpoint command will be listed as it cannot be resolved until
4402the appropriate shared library is loaded in the future.
4403@end table
4404
4405@noindent
4406If a breakpoint is conditional, there are two evaluation modes: ``host'' and
4407``target''.  If mode is ``host'', breakpoint condition evaluation is done by
4408@value{GDBN} on the host's side.  If it is ``target'', then the condition
4409is evaluated by the target.  The @code{info break} command shows
4410the condition on the line following the affected breakpoint, together with
4411its condition evaluation mode in between parentheses.
4412
4413Breakpoint commands, if any, are listed after that.  A pending breakpoint is
4414allowed to have a condition specified for it.  The condition is not parsed for
4415validity until a shared library is loaded that allows the pending
4416breakpoint to resolve to a valid location.
4417
4418@noindent
4419@code{info break} with a breakpoint
4420number @var{n} as argument lists only that breakpoint.  The
4421convenience variable @code{$_} and the default examining-address for
4422the @code{x} command are set to the address of the last breakpoint
4423listed (@pxref{Memory, ,Examining Memory}).
4424
4425@noindent
4426@code{info break} displays a count of the number of times the breakpoint
4427has been hit.  This is especially useful in conjunction with the
4428@code{ignore} command.  You can ignore a large number of breakpoint
4429hits, look at the breakpoint info to see how many times the breakpoint
4430was hit, and then run again, ignoring one less than that number.  This
4431will get you quickly to the last hit of that breakpoint.
4432
4433@noindent
4434For a breakpoints with an enable count (xref) greater than 1,
4435@code{info break} also displays that count.
4436
4437@end table
4438
4439@value{GDBN} allows you to set any number of breakpoints at the same place in
4440your program.  There is nothing silly or meaningless about this.  When
4441the breakpoints are conditional, this is even useful
4442(@pxref{Conditions, ,Break Conditions}).
4443
4444@cindex multiple locations, breakpoints
4445@cindex breakpoints, multiple locations
4446It is possible that a breakpoint corresponds to several locations
4447in your program.  Examples of this situation are:
4448
4449@itemize @bullet
4450@item
4451Multiple functions in the program may have the same name.
4452
4453@item
4454For a C@t{++} constructor, the @value{NGCC} compiler generates several
4455instances of the function body, used in different cases.
4456
4457@item
4458For a C@t{++} template function, a given line in the function can
4459correspond to any number of instantiations.
4460
4461@item
4462For an inlined function, a given source line can correspond to
4463several places where that function is inlined.
4464@end itemize
4465
4466In all those cases, @value{GDBN} will insert a breakpoint at all
4467the relevant locations.
4468
4469A breakpoint with multiple locations is displayed in the breakpoint
4470table using several rows---one header row, followed by one row for
4471each breakpoint location.  The header row has @samp{<MULTIPLE>} in the
4472address column.  The rows for individual locations contain the actual
4473addresses for locations, and show the functions to which those
4474locations belong.  The number column for a location is of the form
4475@var{breakpoint-number}.@var{location-number}.
4476
4477For example:
4478
4479@smallexample
4480Num     Type           Disp Enb  Address    What
44811       breakpoint     keep y    <MULTIPLE>
4482        stop only if i==1
4483        breakpoint already hit 1 time
44841.1                         y    0x080486a2 in void foo<int>() at t.cc:8
44851.2                         y    0x080486ca in void foo<double>() at t.cc:8
4486@end smallexample
4487
4488You cannot delete the individual locations from a breakpoint.  However,
4489each location can be individually enabled or disabled by passing
4490@var{breakpoint-number}.@var{location-number} as argument to the
4491@code{enable} and @code{disable} commands.  It's also possible to
4492@code{enable} and @code{disable} a range of @var{location-number}
4493locations using a @var{breakpoint-number} and two @var{location-number}s,
4494in increasing order, separated by a hyphen, like
4495@kbd{@var{breakpoint-number}.@var{location-number1}-@var{location-number2}},
4496in which case @value{GDBN} acts on all the locations in the range (inclusive).
4497Disabling or enabling the parent breakpoint (@pxref{Disabling}) affects
4498all of the locations that belong to that breakpoint.
4499
4500@cindex pending breakpoints
4501It's quite common to have a breakpoint inside a shared library.
4502Shared libraries can be loaded and unloaded explicitly,
4503and possibly repeatedly, as the program is executed.  To support
4504this use case, @value{GDBN} updates breakpoint locations whenever
4505any shared library is loaded or unloaded.  Typically, you would
4506set a breakpoint in a shared library at the beginning of your
4507debugging session, when the library is not loaded, and when the
4508symbols from the library are not available.  When you try to set
4509breakpoint, @value{GDBN} will ask you if you want to set
4510a so called @dfn{pending breakpoint}---breakpoint whose address
4511is not yet resolved.
4512
4513After the program is run, whenever a new shared library is loaded,
4514@value{GDBN} reevaluates all the breakpoints.  When a newly loaded
4515shared library contains the symbol or line referred to by some
4516pending breakpoint, that breakpoint is resolved and becomes an
4517ordinary breakpoint.  When a library is unloaded, all breakpoints
4518that refer to its symbols or source lines become pending again.
4519
4520This logic works for breakpoints with multiple locations, too.  For
4521example, if you have a breakpoint in a C@t{++} template function, and
4522a newly loaded shared library has an instantiation of that template,
4523a new location is added to the list of locations for the breakpoint.
4524
4525Except for having unresolved address, pending breakpoints do not
4526differ from regular breakpoints.  You can set conditions or commands,
4527enable and disable them and perform other breakpoint operations.
4528
4529@value{GDBN} provides some additional commands for controlling what
4530happens when the @samp{break} command cannot resolve breakpoint
4531address specification to an address:
4532
4533@kindex set breakpoint pending
4534@kindex show breakpoint pending
4535@table @code
4536@item set breakpoint pending auto
4537This is the default behavior.  When @value{GDBN} cannot find the breakpoint
4538location, it queries you whether a pending breakpoint should be created.
4539
4540@item set breakpoint pending on
4541This indicates that an unrecognized breakpoint location should automatically
4542result in a pending breakpoint being created.
4543
4544@item set breakpoint pending off
4545This indicates that pending breakpoints are not to be created.  Any
4546unrecognized breakpoint location results in an error.  This setting does
4547not affect any pending breakpoints previously created.
4548
4549@item show breakpoint pending
4550Show the current behavior setting for creating pending breakpoints.
4551@end table
4552
4553The settings above only affect the @code{break} command and its
4554variants.  Once breakpoint is set, it will be automatically updated
4555as shared libraries are loaded and unloaded.
4556
4557@cindex automatic hardware breakpoints
4558For some targets, @value{GDBN} can automatically decide if hardware or
4559software breakpoints should be used, depending on whether the
4560breakpoint address is read-only or read-write.  This applies to
4561breakpoints set with the @code{break} command as well as to internal
4562breakpoints set by commands like @code{next} and @code{finish}.  For
4563breakpoints set with @code{hbreak}, @value{GDBN} will always use hardware
4564breakpoints.
4565
4566You can control this automatic behaviour with the following commands:
4567
4568@kindex set breakpoint auto-hw
4569@kindex show breakpoint auto-hw
4570@table @code
4571@item set breakpoint auto-hw on
4572This is the default behavior.  When @value{GDBN} sets a breakpoint, it
4573will try to use the target memory map to decide if software or hardware
4574breakpoint must be used.
4575
4576@item set breakpoint auto-hw off
4577This indicates @value{GDBN} should not automatically select breakpoint
4578type.  If the target provides a memory map, @value{GDBN} will warn when
4579trying to set software breakpoint at a read-only address.
4580@end table
4581
4582@value{GDBN} normally implements breakpoints by replacing the program code
4583at the breakpoint address with a special instruction, which, when
4584executed, given control to the debugger.  By default, the program
4585code is so modified only when the program is resumed.  As soon as
4586the program stops, @value{GDBN} restores the original instructions.  This
4587behaviour guards against leaving breakpoints inserted in the
4588target should gdb abrubptly disconnect.  However, with slow remote
4589targets, inserting and removing breakpoint can reduce the performance.
4590This behavior can be controlled with the following commands::
4591
4592@kindex set breakpoint always-inserted
4593@kindex show breakpoint always-inserted
4594@table @code
4595@item set breakpoint always-inserted off
4596All breakpoints, including newly added by the user, are inserted in
4597the target only when the target is resumed.  All breakpoints are
4598removed from the target when it stops.  This is the default mode.
4599
4600@item set breakpoint always-inserted on
4601Causes all breakpoints to be inserted in the target at all times.  If
4602the user adds a new breakpoint, or changes an existing breakpoint, the
4603breakpoints in the target are updated immediately.  A breakpoint is
4604removed from the target only when breakpoint itself is deleted.
4605@end table
4606
4607@value{GDBN} handles conditional breakpoints by evaluating these conditions
4608when a breakpoint breaks.  If the condition is true, then the process being
4609debugged stops, otherwise the process is resumed.
4610
4611If the target supports evaluating conditions on its end, @value{GDBN} may
4612download the breakpoint, together with its conditions, to it.
4613
4614This feature can be controlled via the following commands:
4615
4616@kindex set breakpoint condition-evaluation
4617@kindex show breakpoint condition-evaluation
4618@table @code
4619@item set breakpoint condition-evaluation host
4620This option commands @value{GDBN} to evaluate the breakpoint
4621conditions on the host's side.  Unconditional breakpoints are sent to
4622the target which in turn receives the triggers and reports them back to GDB
4623for condition evaluation.  This is the standard evaluation mode.
4624
4625@item set breakpoint condition-evaluation target
4626This option commands @value{GDBN} to download breakpoint conditions
4627to the target at the moment of their insertion.  The target
4628is responsible for evaluating the conditional expression and reporting
4629breakpoint stop events back to @value{GDBN} whenever the condition
4630is true.  Due to limitations of target-side evaluation, some conditions
4631cannot be evaluated there, e.g., conditions that depend on local data
4632that is only known to the host.  Examples include
4633conditional expressions involving convenience variables, complex types
4634that cannot be handled by the agent expression parser and expressions
4635that are too long to be sent over to the target, specially when the
4636target is a remote system.  In these cases, the conditions will be
4637evaluated by @value{GDBN}.
4638
4639@item set breakpoint condition-evaluation auto
4640This is the default mode.  If the target supports evaluating breakpoint
4641conditions on its end, @value{GDBN} will download breakpoint conditions to
4642the target (limitations mentioned previously apply).  If the target does
4643not support breakpoint condition evaluation, then @value{GDBN} will fallback
4644to evaluating all these conditions on the host's side.
4645@end table
4646
4647
4648@cindex negative breakpoint numbers
4649@cindex internal @value{GDBN} breakpoints
4650@value{GDBN} itself sometimes sets breakpoints in your program for
4651special purposes, such as proper handling of @code{longjmp} (in C
4652programs).  These internal breakpoints are assigned negative numbers,
4653starting with @code{-1}; @samp{info breakpoints} does not display them.
4654You can see these breakpoints with the @value{GDBN} maintenance command
4655@samp{maint info breakpoints} (@pxref{maint info breakpoints}).
4656
4657
4658@node Set Watchpoints
4659@subsection Setting Watchpoints
4660
4661@cindex setting watchpoints
4662You can use a watchpoint to stop execution whenever the value of an
4663expression changes, without having to predict a particular place where
4664this may happen.  (This is sometimes called a @dfn{data breakpoint}.)
4665The expression may be as simple as the value of a single variable, or
4666as complex as many variables combined by operators.  Examples include:
4667
4668@itemize @bullet
4669@item
4670A reference to the value of a single variable.
4671
4672@item
4673An address cast to an appropriate data type.  For example,
4674@samp{*(int *)0x12345678} will watch a 4-byte region at the specified
4675address (assuming an @code{int} occupies 4 bytes).
4676
4677@item
4678An arbitrarily complex expression, such as @samp{a*b + c/d}.  The
4679expression can use any operators valid in the program's native
4680language (@pxref{Languages}).
4681@end itemize
4682
4683You can set a watchpoint on an expression even if the expression can
4684not be evaluated yet.  For instance, you can set a watchpoint on
4685@samp{*global_ptr} before @samp{global_ptr} is initialized.
4686@value{GDBN} will stop when your program sets @samp{global_ptr} and
4687the expression produces a valid value.  If the expression becomes
4688valid in some other way than changing a variable (e.g.@: if the memory
4689pointed to by @samp{*global_ptr} becomes readable as the result of a
4690@code{malloc} call), @value{GDBN} may not stop until the next time
4691the expression changes.
4692
4693@cindex software watchpoints
4694@cindex hardware watchpoints
4695Depending on your system, watchpoints may be implemented in software or
4696hardware.  @value{GDBN} does software watchpointing by single-stepping your
4697program and testing the variable's value each time, which is hundreds of
4698times slower than normal execution.  (But this may still be worth it, to
4699catch errors where you have no clue what part of your program is the
4700culprit.)
4701
4702On some systems, such as most PowerPC or x86-based targets,
4703@value{GDBN} includes support for hardware watchpoints, which do not
4704slow down the running of your program.
4705
4706@table @code
4707@kindex watch
4708@item watch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
4709Set a watchpoint for an expression.  @value{GDBN} will break when the
4710expression @var{expr} is written into by the program and its value
4711changes.  The simplest (and the most popular) use of this command is
4712to watch the value of a single variable:
4713
4714@smallexample
4715(@value{GDBP}) watch foo
4716@end smallexample
4717
4718If the command includes a @code{@r{[}thread @var{thread-id}@r{]}}
4719argument, @value{GDBN} breaks only when the thread identified by
4720@var{thread-id} changes the value of @var{expr}.  If any other threads
4721change the value of @var{expr}, @value{GDBN} will not break.  Note
4722that watchpoints restricted to a single thread in this way only work
4723with Hardware Watchpoints.
4724
4725Ordinarily a watchpoint respects the scope of variables in @var{expr}
4726(see below).  The @code{-location} argument tells @value{GDBN} to
4727instead watch the memory referred to by @var{expr}.  In this case,
4728@value{GDBN} will evaluate @var{expr}, take the address of the result,
4729and watch the memory at that address.  The type of the result is used
4730to determine the size of the watched memory.  If the expression's
4731result does not have an address, then @value{GDBN} will print an
4732error.
4733
4734The @code{@r{[}mask @var{maskvalue}@r{]}} argument allows creation
4735of masked watchpoints, if the current architecture supports this
4736feature (e.g., PowerPC Embedded architecture, see @ref{PowerPC
4737Embedded}.)  A @dfn{masked watchpoint} specifies a mask in addition
4738to an address to watch.  The mask specifies that some bits of an address
4739(the bits which are reset in the mask) should be ignored when matching
4740the address accessed by the inferior against the watchpoint address.
4741Thus, a masked watchpoint watches many addresses simultaneously---those
4742addresses whose unmasked bits are identical to the unmasked bits in the
4743watchpoint address.  The @code{mask} argument implies @code{-location}.
4744Examples:
4745
4746@smallexample
4747(@value{GDBP}) watch foo mask 0xffff00ff
4748(@value{GDBP}) watch *0xdeadbeef mask 0xffffff00
4749@end smallexample
4750
4751@kindex rwatch
4752@item rwatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
4753Set a watchpoint that will break when the value of @var{expr} is read
4754by the program.
4755
4756@kindex awatch
4757@item awatch @r{[}-l@r{|}-location@r{]} @var{expr} @r{[}thread @var{thread-id}@r{]} @r{[}mask @var{maskvalue}@r{]}
4758Set a watchpoint that will break when @var{expr} is either read from
4759or written into by the program.
4760
4761@kindex info watchpoints @r{[}@var{list}@dots{}@r{]}
4762@item info watchpoints @r{[}@var{list}@dots{}@r{]}
4763This command prints a list of watchpoints, using the same format as
4764@code{info break} (@pxref{Set Breaks}).
4765@end table
4766
4767If you watch for a change in a numerically entered address you need to
4768dereference it, as the address itself is just a constant number which will
4769never change.  @value{GDBN} refuses to create a watchpoint that watches
4770a never-changing value:
4771
4772@smallexample
4773(@value{GDBP}) watch 0x600850
4774Cannot watch constant value 0x600850.
4775(@value{GDBP}) watch *(int *) 0x600850
4776Watchpoint 1: *(int *) 6293584
4777@end smallexample
4778
4779@value{GDBN} sets a @dfn{hardware watchpoint} if possible.  Hardware
4780watchpoints execute very quickly, and the debugger reports a change in
4781value at the exact instruction where the change occurs.  If @value{GDBN}
4782cannot set a hardware watchpoint, it sets a software watchpoint, which
4783executes more slowly and reports the change in value at the next
4784@emph{statement}, not the instruction, after the change occurs.
4785
4786@cindex use only software watchpoints
4787You can force @value{GDBN} to use only software watchpoints with the
4788@kbd{set can-use-hw-watchpoints 0} command.  With this variable set to
4789zero, @value{GDBN} will never try to use hardware watchpoints, even if
4790the underlying system supports them.  (Note that hardware-assisted
4791watchpoints that were set @emph{before} setting
4792@code{can-use-hw-watchpoints} to zero will still use the hardware
4793mechanism of watching expression values.)
4794
4795@table @code
4796@item set can-use-hw-watchpoints
4797@kindex set can-use-hw-watchpoints
4798Set whether or not to use hardware watchpoints.
4799
4800@item show can-use-hw-watchpoints
4801@kindex show can-use-hw-watchpoints
4802Show the current mode of using hardware watchpoints.
4803@end table
4804
4805For remote targets, you can restrict the number of hardware
4806watchpoints @value{GDBN} will use, see @ref{set remote
4807hardware-breakpoint-limit}.
4808
4809When you issue the @code{watch} command, @value{GDBN} reports
4810
4811@smallexample
4812Hardware watchpoint @var{num}: @var{expr}
4813@end smallexample
4814
4815@noindent
4816if it was able to set a hardware watchpoint.
4817
4818Currently, the @code{awatch} and @code{rwatch} commands can only set
4819hardware watchpoints, because accesses to data that don't change the
4820value of the watched expression cannot be detected without examining
4821every instruction as it is being executed, and @value{GDBN} does not do
4822that currently.  If @value{GDBN} finds that it is unable to set a
4823hardware breakpoint with the @code{awatch} or @code{rwatch} command, it
4824will print a message like this:
4825
4826@smallexample
4827Expression cannot be implemented with read/access watchpoint.
4828@end smallexample
4829
4830Sometimes, @value{GDBN} cannot set a hardware watchpoint because the
4831data type of the watched expression is wider than what a hardware
4832watchpoint on the target machine can handle.  For example, some systems
4833can only watch regions that are up to 4 bytes wide; on such systems you
4834cannot set hardware watchpoints for an expression that yields a
4835double-precision floating-point number (which is typically 8 bytes
4836wide).  As a work-around, it might be possible to break the large region
4837into a series of smaller ones and watch them with separate watchpoints.
4838
4839If you set too many hardware watchpoints, @value{GDBN} might be unable
4840to insert all of them when you resume the execution of your program.
4841Since the precise number of active watchpoints is unknown until such
4842time as the program is about to be resumed, @value{GDBN} might not be
4843able to warn you about this when you set the watchpoints, and the
4844warning will be printed only when the program is resumed:
4845
4846@smallexample
4847Hardware watchpoint @var{num}: Could not insert watchpoint
4848@end smallexample
4849
4850@noindent
4851If this happens, delete or disable some of the watchpoints.
4852
4853Watching complex expressions that reference many variables can also
4854exhaust the resources available for hardware-assisted watchpoints.
4855That's because @value{GDBN} needs to watch every variable in the
4856expression with separately allocated resources.
4857
4858If you call a function interactively using @code{print} or @code{call},
4859any watchpoints you have set will be inactive until @value{GDBN} reaches another
4860kind of breakpoint or the call completes.
4861
4862@value{GDBN} automatically deletes watchpoints that watch local
4863(automatic) variables, or expressions that involve such variables, when
4864they go out of scope, that is, when the execution leaves the block in
4865which these variables were defined.  In particular, when the program
4866being debugged terminates, @emph{all} local variables go out of scope,
4867and so only watchpoints that watch global variables remain set.  If you
4868rerun the program, you will need to set all such watchpoints again.  One
4869way of doing that would be to set a code breakpoint at the entry to the
4870@code{main} function and when it breaks, set all the watchpoints.
4871
4872@cindex watchpoints and threads
4873@cindex threads and watchpoints
4874In multi-threaded programs, watchpoints will detect changes to the
4875watched expression from every thread.
4876
4877@quotation
4878@emph{Warning:} In multi-threaded programs, software watchpoints
4879have only limited usefulness.  If @value{GDBN} creates a software
4880watchpoint, it can only watch the value of an expression @emph{in a
4881single thread}.  If you are confident that the expression can only
4882change due to the current thread's activity (and if you are also
4883confident that no other thread can become current), then you can use
4884software watchpoints as usual.  However, @value{GDBN} may not notice
4885when a non-current thread's activity changes the expression.  (Hardware
4886watchpoints, in contrast, watch an expression in all threads.)
4887@end quotation
4888
4889@xref{set remote hardware-watchpoint-limit}.
4890
4891@node Set Catchpoints
4892@subsection Setting Catchpoints
4893@cindex catchpoints, setting
4894@cindex exception handlers
4895@cindex event handling
4896
4897You can use @dfn{catchpoints} to cause the debugger to stop for certain
4898kinds of program events, such as C@t{++} exceptions or the loading of a
4899shared library.  Use the @code{catch} command to set a catchpoint.
4900
4901@table @code
4902@kindex catch
4903@item catch @var{event}
4904Stop when @var{event} occurs.  The @var{event} can be any of the following:
4905
4906@table @code
4907@item throw @r{[}@var{regexp}@r{]}
4908@itemx rethrow @r{[}@var{regexp}@r{]}
4909@itemx catch @r{[}@var{regexp}@r{]}
4910@kindex catch throw
4911@kindex catch rethrow
4912@kindex catch catch
4913@cindex stop on C@t{++} exceptions
4914The throwing, re-throwing, or catching of a C@t{++} exception.
4915
4916If @var{regexp} is given, then only exceptions whose type matches the
4917regular expression will be caught.
4918
4919@vindex $_exception@r{, convenience variable}
4920The convenience variable @code{$_exception} is available at an
4921exception-related catchpoint, on some systems.  This holds the
4922exception being thrown.
4923
4924There are currently some limitations to C@t{++} exception handling in
4925@value{GDBN}:
4926
4927@itemize @bullet
4928@item
4929The support for these commands is system-dependent.  Currently, only
4930systems using the @samp{gnu-v3} C@t{++} ABI (@pxref{ABI}) are
4931supported.
4932
4933@item
4934The regular expression feature and the @code{$_exception} convenience
4935variable rely on the presence of some SDT probes in @code{libstdc++}.
4936If these probes are not present, then these features cannot be used.
4937These probes were first available in the GCC 4.8 release, but whether
4938or not they are available in your GCC also depends on how it was
4939built.
4940
4941@item
4942The @code{$_exception} convenience variable is only valid at the
4943instruction at which an exception-related catchpoint is set.
4944
4945@item
4946When an exception-related catchpoint is hit, @value{GDBN} stops at a
4947location in the system library which implements runtime exception
4948support for C@t{++}, usually @code{libstdc++}.  You can use @code{up}
4949(@pxref{Selection}) to get to your code.
4950
4951@item
4952If you call a function interactively, @value{GDBN} normally returns
4953control to you when the function has finished executing.  If the call
4954raises an exception, however, the call may bypass the mechanism that
4955returns control to you and cause your program either to abort or to
4956simply continue running until it hits a breakpoint, catches a signal
4957that @value{GDBN} is listening for, or exits.  This is the case even if
4958you set a catchpoint for the exception; catchpoints on exceptions are
4959disabled within interactive calls.  @xref{Calling}, for information on
4960controlling this with @code{set unwind-on-terminating-exception}.
4961
4962@item
4963You cannot raise an exception interactively.
4964
4965@item
4966You cannot install an exception handler interactively.
4967@end itemize
4968
4969@item exception @r{[}@var{name}@r{]}
4970@kindex catch exception
4971@cindex Ada exception catching
4972@cindex catch Ada exceptions
4973An Ada exception being raised.  If an exception name is specified
4974at the end of the command (eg @code{catch exception Program_Error}),
4975the debugger will stop only when this specific exception is raised.
4976Otherwise, the debugger stops execution when any Ada exception is raised.
4977
4978When inserting an exception catchpoint on a user-defined exception whose
4979name is identical to one of the exceptions defined by the language, the
4980fully qualified name must be used as the exception name.  Otherwise,
4981@value{GDBN} will assume that it should stop on the pre-defined exception
4982rather than the user-defined one.  For instance, assuming an exception
4983called @code{Constraint_Error} is defined in package @code{Pck}, then
4984the command to use to catch such exceptions is @kbd{catch exception
4985Pck.Constraint_Error}.
4986
4987@vindex $_ada_exception@r{, convenience variable}
4988The convenience variable @code{$_ada_exception} holds the address of
4989the exception being thrown.  This can be useful when setting a
4990condition for such a catchpoint.
4991
4992@item exception unhandled
4993@kindex catch exception unhandled
4994An exception that was raised but is not handled by the program.  The
4995convenience variable @code{$_ada_exception} is set as for @code{catch
4996exception}.
4997
4998@item handlers @r{[}@var{name}@r{]}
4999@kindex catch handlers
5000@cindex Ada exception handlers catching
5001@cindex catch Ada exceptions when handled
5002An Ada exception being handled.  If an exception name is
5003specified at the end of the command
5004 (eg @kbd{catch handlers Program_Error}), the debugger will stop
5005only when this specific exception is handled.
5006Otherwise, the debugger stops execution when any Ada exception is handled.
5007
5008When inserting a handlers catchpoint on a user-defined
5009exception whose name is identical to one of the exceptions
5010defined by the language, the fully qualified name must be used
5011as the exception name.  Otherwise, @value{GDBN} will assume that it
5012should stop on the pre-defined exception rather than the
5013user-defined one.  For instance, assuming an exception called
5014 @code{Constraint_Error} is defined in package @code{Pck}, then the
5015command to use to catch such exceptions handling is
5016@kbd{catch handlers Pck.Constraint_Error}.
5017
5018The convenience variable @code{$_ada_exception} is set as for
5019@code{catch exception}.
5020
5021@item assert
5022@kindex catch assert
5023A failed Ada assertion.  Note that the convenience variable
5024@code{$_ada_exception} is @emph{not} set by this catchpoint.
5025
5026@item exec
5027@kindex catch exec
5028@cindex break on fork/exec
5029A call to @code{exec}.
5030
5031@anchor{catch syscall}
5032@item syscall
5033@itemx syscall @r{[}@var{name} @r{|} @var{number} @r{|} @r{group:}@var{groupname} @r{|} @r{g:}@var{groupname}@r{]} @dots{}
5034@kindex catch syscall
5035@cindex break on a system call.
5036A call to or return from a system call, a.k.a.@: @dfn{syscall}.  A
5037syscall is a mechanism for application programs to request a service
5038from the operating system (OS) or one of the OS system services.
5039@value{GDBN} can catch some or all of the syscalls issued by the
5040debuggee, and show the related information for each syscall.  If no
5041argument is specified, calls to and returns from all system calls
5042will be caught.
5043
5044@var{name} can be any system call name that is valid for the
5045underlying OS.  Just what syscalls are valid depends on the OS.  On
5046GNU and Unix systems, you can find the full list of valid syscall
5047names on @file{/usr/include/asm/unistd.h}.
5048
5049@c For MS-Windows, the syscall names and the corresponding numbers
5050@c can be found, e.g., on this URL:
5051@c http://www.metasploit.com/users/opcode/syscalls.html
5052@c but we don't support Windows syscalls yet.
5053
5054Normally, @value{GDBN} knows in advance which syscalls are valid for
5055each OS, so you can use the @value{GDBN} command-line completion
5056facilities (@pxref{Completion,, command completion}) to list the
5057available choices.
5058
5059You may also specify the system call numerically.  A syscall's
5060number is the value passed to the OS's syscall dispatcher to
5061identify the requested service.  When you specify the syscall by its
5062name, @value{GDBN} uses its database of syscalls to convert the name
5063into the corresponding numeric code, but using the number directly
5064may be useful if @value{GDBN}'s database does not have the complete
5065list of syscalls on your system (e.g., because @value{GDBN} lags
5066behind the OS upgrades).
5067
5068You may specify a group of related syscalls to be caught at once using
5069the @code{group:} syntax (@code{g:} is a shorter equivalent).  For
5070instance, on some platforms @value{GDBN} allows you to catch all
5071network related syscalls, by passing the argument @code{group:network}
5072to @code{catch syscall}.  Note that not all syscall groups are
5073available in every system.  You can use the command completion
5074facilities (@pxref{Completion,, command completion}) to list the
5075syscall groups available on your environment.
5076
5077The example below illustrates how this command works if you don't provide
5078arguments to it:
5079
5080@smallexample
5081(@value{GDBP}) catch syscall
5082Catchpoint 1 (syscall)
5083(@value{GDBP}) r
5084Starting program: /tmp/catch-syscall
5085
5086Catchpoint 1 (call to syscall 'close'), \
5087	   0xffffe424 in __kernel_vsyscall ()
5088(@value{GDBP}) c
5089Continuing.
5090
5091Catchpoint 1 (returned from syscall 'close'), \
5092	0xffffe424 in __kernel_vsyscall ()
5093(@value{GDBP})
5094@end smallexample
5095
5096Here is an example of catching a system call by name:
5097
5098@smallexample
5099(@value{GDBP}) catch syscall chroot
5100Catchpoint 1 (syscall 'chroot' [61])
5101(@value{GDBP}) r
5102Starting program: /tmp/catch-syscall
5103
5104Catchpoint 1 (call to syscall 'chroot'), \
5105		   0xffffe424 in __kernel_vsyscall ()
5106(@value{GDBP}) c
5107Continuing.
5108
5109Catchpoint 1 (returned from syscall 'chroot'), \
5110	0xffffe424 in __kernel_vsyscall ()
5111(@value{GDBP})
5112@end smallexample
5113
5114An example of specifying a system call numerically.  In the case
5115below, the syscall number has a corresponding entry in the XML
5116file, so @value{GDBN} finds its name and prints it:
5117
5118@smallexample
5119(@value{GDBP}) catch syscall 252
5120Catchpoint 1 (syscall(s) 'exit_group')
5121(@value{GDBP}) r
5122Starting program: /tmp/catch-syscall
5123
5124Catchpoint 1 (call to syscall 'exit_group'), \
5125		   0xffffe424 in __kernel_vsyscall ()
5126(@value{GDBP}) c
5127Continuing.
5128
5129Program exited normally.
5130(@value{GDBP})
5131@end smallexample
5132
5133Here is an example of catching a syscall group:
5134
5135@smallexample
5136(@value{GDBP}) catch syscall group:process
5137Catchpoint 1 (syscalls 'exit' [1] 'fork' [2] 'waitpid' [7]
5138'execve' [11] 'wait4' [114] 'clone' [120] 'vfork' [190]
5139'exit_group' [252] 'waitid' [284] 'unshare' [310])
5140(@value{GDBP}) r
5141Starting program: /tmp/catch-syscall
5142
5143Catchpoint 1 (call to syscall fork), 0x00007ffff7df4e27 in open64 ()
5144   from /lib64/ld-linux-x86-64.so.2
5145
5146(@value{GDBP}) c
5147Continuing.
5148@end smallexample
5149
5150However, there can be situations when there is no corresponding name
5151in XML file for that syscall number.  In this case, @value{GDBN} prints
5152a warning message saying that it was not able to find the syscall name,
5153but the catchpoint will be set anyway.  See the example below:
5154
5155@smallexample
5156(@value{GDBP}) catch syscall 764
5157warning: The number '764' does not represent a known syscall.
5158Catchpoint 2 (syscall 764)
5159(@value{GDBP})
5160@end smallexample
5161
5162If you configure @value{GDBN} using the @samp{--without-expat} option,
5163it will not be able to display syscall names.  Also, if your
5164architecture does not have an XML file describing its system calls,
5165you will not be able to see the syscall names.  It is important to
5166notice that these two features are used for accessing the syscall
5167name database.  In either case, you will see a warning like this:
5168
5169@smallexample
5170(@value{GDBP}) catch syscall
5171warning: Could not open "syscalls/i386-linux.xml"
5172warning: Could not load the syscall XML file 'syscalls/i386-linux.xml'.
5173GDB will not be able to display syscall names.
5174Catchpoint 1 (syscall)
5175(@value{GDBP})
5176@end smallexample
5177
5178Of course, the file name will change depending on your architecture and system.
5179
5180Still using the example above, you can also try to catch a syscall by its
5181number.  In this case, you would see something like:
5182
5183@smallexample
5184(@value{GDBP}) catch syscall 252
5185Catchpoint 1 (syscall(s) 252)
5186@end smallexample
5187
5188Again, in this case @value{GDBN} would not be able to display syscall's names.
5189
5190@item fork
5191@kindex catch fork
5192A call to @code{fork}.
5193
5194@item vfork
5195@kindex catch vfork
5196A call to @code{vfork}.
5197
5198@item load @r{[}@var{regexp}@r{]}
5199@itemx unload @r{[}@var{regexp}@r{]}
5200@kindex catch load
5201@kindex catch unload
5202The loading or unloading of a shared library.  If @var{regexp} is
5203given, then the catchpoint will stop only if the regular expression
5204matches one of the affected libraries.
5205
5206@item signal @r{[}@var{signal}@dots{} @r{|} @samp{all}@r{]}
5207@kindex catch signal
5208The delivery of a signal.
5209
5210With no arguments, this catchpoint will catch any signal that is not
5211used internally by @value{GDBN}, specifically, all signals except
5212@samp{SIGTRAP} and @samp{SIGINT}.
5213
5214With the argument @samp{all}, all signals, including those used by
5215@value{GDBN}, will be caught.  This argument cannot be used with other
5216signal names.
5217
5218Otherwise, the arguments are a list of signal names as given to
5219@code{handle} (@pxref{Signals}).  Only signals specified in this list
5220will be caught.
5221
5222One reason that @code{catch signal} can be more useful than
5223@code{handle} is that you can attach commands and conditions to the
5224catchpoint.
5225
5226When a signal is caught by a catchpoint, the signal's @code{stop} and
5227@code{print} settings, as specified by @code{handle}, are ignored.
5228However, whether the signal is still delivered to the inferior depends
5229on the @code{pass} setting; this can be changed in the catchpoint's
5230commands.
5231
5232@end table
5233
5234@item tcatch @var{event}
5235@kindex tcatch
5236Set a catchpoint that is enabled only for one stop.  The catchpoint is
5237automatically deleted after the first time the event is caught.
5238
5239@end table
5240
5241Use the @code{info break} command to list the current catchpoints.
5242
5243
5244@node Delete Breaks
5245@subsection Deleting Breakpoints
5246
5247@cindex clearing breakpoints, watchpoints, catchpoints
5248@cindex deleting breakpoints, watchpoints, catchpoints
5249It is often necessary to eliminate a breakpoint, watchpoint, or
5250catchpoint once it has done its job and you no longer want your program
5251to stop there.  This is called @dfn{deleting} the breakpoint.  A
5252breakpoint that has been deleted no longer exists; it is forgotten.
5253
5254With the @code{clear} command you can delete breakpoints according to
5255where they are in your program.  With the @code{delete} command you can
5256delete individual breakpoints, watchpoints, or catchpoints by specifying
5257their breakpoint numbers.
5258
5259It is not necessary to delete a breakpoint to proceed past it.  @value{GDBN}
5260automatically ignores breakpoints on the first instruction to be executed
5261when you continue execution without changing the execution address.
5262
5263@table @code
5264@kindex clear
5265@item clear
5266Delete any breakpoints at the next instruction to be executed in the
5267selected stack frame (@pxref{Selection, ,Selecting a Frame}).  When
5268the innermost frame is selected, this is a good way to delete a
5269breakpoint where your program just stopped.
5270
5271@item clear @var{location}
5272Delete any breakpoints set at the specified @var{location}.
5273@xref{Specify Location}, for the various forms of @var{location}; the
5274most useful ones are listed below:
5275
5276@table @code
5277@item clear @var{function}
5278@itemx clear @var{filename}:@var{function}
5279Delete any breakpoints set at entry to the named @var{function}.
5280
5281@item clear @var{linenum}
5282@itemx clear @var{filename}:@var{linenum}
5283Delete any breakpoints set at or within the code of the specified
5284@var{linenum} of the specified @var{filename}.
5285@end table
5286
5287@cindex delete breakpoints
5288@kindex delete
5289@kindex d @r{(@code{delete})}
5290@item delete @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
5291Delete the breakpoints, watchpoints, or catchpoints of the breakpoint
5292list specified as argument.  If no argument is specified, delete all
5293breakpoints (@value{GDBN} asks confirmation, unless you have @code{set
5294confirm off}).  You can abbreviate this command as @code{d}.
5295@end table
5296
5297@node Disabling
5298@subsection Disabling Breakpoints
5299
5300@cindex enable/disable a breakpoint
5301Rather than deleting a breakpoint, watchpoint, or catchpoint, you might
5302prefer to @dfn{disable} it.  This makes the breakpoint inoperative as if
5303it had been deleted, but remembers the information on the breakpoint so
5304that you can @dfn{enable} it again later.
5305
5306You disable and enable breakpoints, watchpoints, and catchpoints with
5307the @code{enable} and @code{disable} commands, optionally specifying
5308one or more breakpoint numbers as arguments.  Use @code{info break} to
5309print a list of all breakpoints, watchpoints, and catchpoints if you
5310do not know which numbers to use.
5311
5312Disabling and enabling a breakpoint that has multiple locations
5313affects all of its locations.
5314
5315A breakpoint, watchpoint, or catchpoint can have any of several
5316different states of enablement:
5317
5318@itemize @bullet
5319@item
5320Enabled.  The breakpoint stops your program.  A breakpoint set
5321with the @code{break} command starts out in this state.
5322@item
5323Disabled.  The breakpoint has no effect on your program.
5324@item
5325Enabled once.  The breakpoint stops your program, but then becomes
5326disabled.
5327@item
5328Enabled for a count.  The breakpoint stops your program for the next
5329N times, then becomes disabled.
5330@item
5331Enabled for deletion.  The breakpoint stops your program, but
5332immediately after it does so it is deleted permanently.  A breakpoint
5333set with the @code{tbreak} command starts out in this state.
5334@end itemize
5335
5336You can use the following commands to enable or disable breakpoints,
5337watchpoints, and catchpoints:
5338
5339@table @code
5340@kindex disable
5341@kindex dis @r{(@code{disable})}
5342@item disable @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
5343Disable the specified breakpoints---or all breakpoints, if none are
5344listed.  A disabled breakpoint has no effect but is not forgotten.  All
5345options such as ignore-counts, conditions and commands are remembered in
5346case the breakpoint is enabled again later.  You may abbreviate
5347@code{disable} as @code{dis}.
5348
5349@kindex enable
5350@item enable @r{[}breakpoints@r{]} @r{[}@var{list}@dots{}@r{]}
5351Enable the specified breakpoints (or all defined breakpoints).  They
5352become effective once again in stopping your program.
5353
5354@item enable @r{[}breakpoints@r{]} once @var{list}@dots{}
5355Enable the specified breakpoints temporarily.  @value{GDBN} disables any
5356of these breakpoints immediately after stopping your program.
5357
5358@item enable @r{[}breakpoints@r{]} count @var{count} @var{list}@dots{}
5359Enable the specified breakpoints temporarily.  @value{GDBN} records
5360@var{count} with each of the specified breakpoints, and decrements a
5361breakpoint's count when it is hit.  When any count reaches 0,
5362@value{GDBN} disables that breakpoint.  If a breakpoint has an ignore
5363count (@pxref{Conditions, ,Break Conditions}), that will be
5364decremented to 0 before @var{count} is affected.
5365
5366@item enable @r{[}breakpoints@r{]} delete @var{list}@dots{}
5367Enable the specified breakpoints to work once, then die.  @value{GDBN}
5368deletes any of these breakpoints as soon as your program stops there.
5369Breakpoints set by the @code{tbreak} command start out in this state.
5370@end table
5371
5372@c FIXME: I think the following ``Except for [...] @code{tbreak}'' is
5373@c confusing: tbreak is also initially enabled.
5374Except for a breakpoint set with @code{tbreak} (@pxref{Set Breaks,
5375,Setting Breakpoints}), breakpoints that you set are initially enabled;
5376subsequently, they become disabled or enabled only when you use one of
5377the commands above.  (The command @code{until} can set and delete a
5378breakpoint of its own, but it does not change the state of your other
5379breakpoints; see @ref{Continuing and Stepping, ,Continuing and
5380Stepping}.)
5381
5382@node Conditions
5383@subsection Break Conditions
5384@cindex conditional breakpoints
5385@cindex breakpoint conditions
5386
5387@c FIXME what is scope of break condition expr?  Context where wanted?
5388@c      in particular for a watchpoint?
5389The simplest sort of breakpoint breaks every time your program reaches a
5390specified place.  You can also specify a @dfn{condition} for a
5391breakpoint.  A condition is just a Boolean expression in your
5392programming language (@pxref{Expressions, ,Expressions}).  A breakpoint with
5393a condition evaluates the expression each time your program reaches it,
5394and your program stops only if the condition is @emph{true}.
5395
5396This is the converse of using assertions for program validation; in that
5397situation, you want to stop when the assertion is violated---that is,
5398when the condition is false.  In C, if you want to test an assertion expressed
5399by the condition @var{assert}, you should set the condition
5400@samp{! @var{assert}} on the appropriate breakpoint.
5401
5402Conditions are also accepted for watchpoints; you may not need them,
5403since a watchpoint is inspecting the value of an expression anyhow---but
5404it might be simpler, say, to just set a watchpoint on a variable name,
5405and specify a condition that tests whether the new value is an interesting
5406one.
5407
5408Break conditions can have side effects, and may even call functions in
5409your program.  This can be useful, for example, to activate functions
5410that log program progress, or to use your own print functions to
5411format special data structures.  The effects are completely predictable
5412unless there is another enabled breakpoint at the same address.  (In
5413that case, @value{GDBN} might see the other breakpoint first and stop your
5414program without checking the condition of this one.)  Note that
5415breakpoint commands are usually more convenient and flexible than break
5416conditions for the
5417purpose of performing side effects when a breakpoint is reached
5418(@pxref{Break Commands, ,Breakpoint Command Lists}).
5419
5420Breakpoint conditions can also be evaluated on the target's side if
5421the target supports it.  Instead of evaluating the conditions locally,
5422@value{GDBN} encodes the expression into an agent expression
5423(@pxref{Agent Expressions}) suitable for execution on the target,
5424independently of @value{GDBN}.  Global variables become raw memory
5425locations, locals become stack accesses, and so forth.
5426
5427In this case, @value{GDBN} will only be notified of a breakpoint trigger
5428when its condition evaluates to true.  This mechanism may provide faster
5429response times depending on the performance characteristics of the target
5430since it does not need to keep @value{GDBN} informed about
5431every breakpoint trigger, even those with false conditions.
5432
5433Break conditions can be specified when a breakpoint is set, by using
5434@samp{if} in the arguments to the @code{break} command.  @xref{Set
5435Breaks, ,Setting Breakpoints}.  They can also be changed at any time
5436with the @code{condition} command.
5437
5438You can also use the @code{if} keyword with the @code{watch} command.
5439The @code{catch} command does not recognize the @code{if} keyword;
5440@code{condition} is the only way to impose a further condition on a
5441catchpoint.
5442
5443@table @code
5444@kindex condition
5445@item condition @var{bnum} @var{expression}
5446Specify @var{expression} as the break condition for breakpoint,
5447watchpoint, or catchpoint number @var{bnum}.  After you set a condition,
5448breakpoint @var{bnum} stops your program only if the value of
5449@var{expression} is true (nonzero, in C).  When you use
5450@code{condition}, @value{GDBN} checks @var{expression} immediately for
5451syntactic correctness, and to determine whether symbols in it have
5452referents in the context of your breakpoint.  If @var{expression} uses
5453symbols not referenced in the context of the breakpoint, @value{GDBN}
5454prints an error message:
5455
5456@smallexample
5457No symbol "foo" in current context.
5458@end smallexample
5459
5460@noindent
5461@value{GDBN} does
5462not actually evaluate @var{expression} at the time the @code{condition}
5463command (or a command that sets a breakpoint with a condition, like
5464@code{break if @dots{}}) is given, however.  @xref{Expressions, ,Expressions}.
5465
5466@item condition @var{bnum}
5467Remove the condition from breakpoint number @var{bnum}.  It becomes
5468an ordinary unconditional breakpoint.
5469@end table
5470
5471@cindex ignore count (of breakpoint)
5472A special case of a breakpoint condition is to stop only when the
5473breakpoint has been reached a certain number of times.  This is so
5474useful that there is a special way to do it, using the @dfn{ignore
5475count} of the breakpoint.  Every breakpoint has an ignore count, which
5476is an integer.  Most of the time, the ignore count is zero, and
5477therefore has no effect.  But if your program reaches a breakpoint whose
5478ignore count is positive, then instead of stopping, it just decrements
5479the ignore count by one and continues.  As a result, if the ignore count
5480value is @var{n}, the breakpoint does not stop the next @var{n} times
5481your program reaches it.
5482
5483@table @code
5484@kindex ignore
5485@item ignore @var{bnum} @var{count}
5486Set the ignore count of breakpoint number @var{bnum} to @var{count}.
5487The next @var{count} times the breakpoint is reached, your program's
5488execution does not stop; other than to decrement the ignore count, @value{GDBN}
5489takes no action.
5490
5491To make the breakpoint stop the next time it is reached, specify
5492a count of zero.
5493
5494When you use @code{continue} to resume execution of your program from a
5495breakpoint, you can specify an ignore count directly as an argument to
5496@code{continue}, rather than using @code{ignore}.  @xref{Continuing and
5497Stepping,,Continuing and Stepping}.
5498
5499If a breakpoint has a positive ignore count and a condition, the
5500condition is not checked.  Once the ignore count reaches zero,
5501@value{GDBN} resumes checking the condition.
5502
5503You could achieve the effect of the ignore count with a condition such
5504as @w{@samp{$foo-- <= 0}} using a debugger convenience variable that
5505is decremented each time.  @xref{Convenience Vars, ,Convenience
5506Variables}.
5507@end table
5508
5509Ignore counts apply to breakpoints, watchpoints, and catchpoints.
5510
5511
5512@node Break Commands
5513@subsection Breakpoint Command Lists
5514
5515@cindex breakpoint commands
5516You can give any breakpoint (or watchpoint or catchpoint) a series of
5517commands to execute when your program stops due to that breakpoint.  For
5518example, you might want to print the values of certain expressions, or
5519enable other breakpoints.
5520
5521@table @code
5522@kindex commands
5523@kindex end@r{ (breakpoint commands)}
5524@item commands @r{[}@var{list}@dots{}@r{]}
5525@itemx @dots{} @var{command-list} @dots{}
5526@itemx end
5527Specify a list of commands for the given breakpoints.  The commands
5528themselves appear on the following lines.  Type a line containing just
5529@code{end} to terminate the commands.
5530
5531To remove all commands from a breakpoint, type @code{commands} and
5532follow it immediately with @code{end}; that is, give no commands.
5533
5534With no argument, @code{commands} refers to the last breakpoint,
5535watchpoint, or catchpoint set (not to the breakpoint most recently
5536encountered).  If the most recent breakpoints were set with a single
5537command, then the @code{commands} will apply to all the breakpoints
5538set by that command.  This applies to breakpoints set by
5539@code{rbreak}, and also applies when a single @code{break} command
5540creates multiple breakpoints (@pxref{Ambiguous Expressions,,Ambiguous
5541Expressions}).
5542@end table
5543
5544Pressing @key{RET} as a means of repeating the last @value{GDBN} command is
5545disabled within a @var{command-list}.
5546
5547You can use breakpoint commands to start your program up again.  Simply
5548use the @code{continue} command, or @code{step}, or any other command
5549that resumes execution.
5550
5551Any other commands in the command list, after a command that resumes
5552execution, are ignored.  This is because any time you resume execution
5553(even with a simple @code{next} or @code{step}), you may encounter
5554another breakpoint---which could have its own command list, leading to
5555ambiguities about which list to execute.
5556
5557@kindex silent
5558If the first command you specify in a command list is @code{silent}, the
5559usual message about stopping at a breakpoint is not printed.  This may
5560be desirable for breakpoints that are to print a specific message and
5561then continue.  If none of the remaining commands print anything, you
5562see no sign that the breakpoint was reached.  @code{silent} is
5563meaningful only at the beginning of a breakpoint command list.
5564
5565The commands @code{echo}, @code{output}, and @code{printf} allow you to
5566print precisely controlled output, and are often useful in silent
5567breakpoints.  @xref{Output, ,Commands for Controlled Output}.
5568
5569For example, here is how you could use breakpoint commands to print the
5570value of @code{x} at entry to @code{foo} whenever @code{x} is positive.
5571
5572@smallexample
5573break foo if x>0
5574commands
5575silent
5576printf "x is %d\n",x
5577cont
5578end
5579@end smallexample
5580
5581One application for breakpoint commands is to compensate for one bug so
5582you can test for another.  Put a breakpoint just after the erroneous line
5583of code, give it a condition to detect the case in which something
5584erroneous has been done, and give it commands to assign correct values
5585to any variables that need them.  End with the @code{continue} command
5586so that your program does not stop, and start with the @code{silent}
5587command so that no output is produced.  Here is an example:
5588
5589@smallexample
5590break 403
5591commands
5592silent
5593set x = y + 4
5594cont
5595end
5596@end smallexample
5597
5598@node Dynamic Printf
5599@subsection Dynamic Printf
5600
5601@cindex dynamic printf
5602@cindex dprintf
5603The dynamic printf command @code{dprintf} combines a breakpoint with
5604formatted printing of your program's data to give you the effect of
5605inserting @code{printf} calls into your program on-the-fly, without
5606having to recompile it.
5607
5608In its most basic form, the output goes to the GDB console.  However,
5609you can set the variable @code{dprintf-style} for alternate handling.
5610For instance, you can ask to format the output by calling your
5611program's @code{printf} function.  This has the advantage that the
5612characters go to the program's output device, so they can recorded in
5613redirects to files and so forth.
5614
5615If you are doing remote debugging with a stub or agent, you can also
5616ask to have the printf handled by the remote agent.  In addition to
5617ensuring that the output goes to the remote program's device along
5618with any other output the program might produce, you can also ask that
5619the dprintf remain active even after disconnecting from the remote
5620target.  Using the stub/agent is also more efficient, as it can do
5621everything without needing to communicate with @value{GDBN}.
5622
5623@table @code
5624@kindex dprintf
5625@item dprintf @var{location},@var{template},@var{expression}[,@var{expression}@dots{}]
5626Whenever execution reaches @var{location}, print the values of one or
5627more @var{expressions} under the control of the string @var{template}.
5628To print several values, separate them with commas.
5629
5630@item set dprintf-style @var{style}
5631Set the dprintf output to be handled in one of several different
5632styles enumerated below.  A change of style affects all existing
5633dynamic printfs immediately.  (If you need individual control over the
5634print commands, simply define normal breakpoints with
5635explicitly-supplied command lists.)
5636
5637@table @code
5638@item gdb
5639@kindex dprintf-style gdb
5640Handle the output using the @value{GDBN} @code{printf} command.
5641
5642@item call
5643@kindex dprintf-style call
5644Handle the output by calling a function in your program (normally
5645@code{printf}).
5646
5647@item agent
5648@kindex dprintf-style agent
5649Have the remote debugging agent (such as @code{gdbserver}) handle
5650the output itself.  This style is only available for agents that
5651support running commands on the target.
5652@end table
5653
5654@item set dprintf-function @var{function}
5655Set the function to call if the dprintf style is @code{call}.  By
5656default its value is @code{printf}.  You may set it to any expression.
5657that @value{GDBN} can evaluate to a function, as per the @code{call}
5658command.
5659
5660@item set dprintf-channel @var{channel}
5661Set a ``channel'' for dprintf.  If set to a non-empty value,
5662@value{GDBN} will evaluate it as an expression and pass the result as
5663a first argument to the @code{dprintf-function}, in the manner of
5664@code{fprintf} and similar functions.  Otherwise, the dprintf format
5665string will be the first argument, in the manner of @code{printf}.
5666
5667As an example, if you wanted @code{dprintf} output to go to a logfile
5668that is a standard I/O stream assigned to the variable @code{mylog},
5669you could do the following:
5670
5671@example
5672(gdb) set dprintf-style call
5673(gdb) set dprintf-function fprintf
5674(gdb) set dprintf-channel mylog
5675(gdb) dprintf 25,"at line 25, glob=%d\n",glob
5676Dprintf 1 at 0x123456: file main.c, line 25.
5677(gdb) info break
56781       dprintf        keep y   0x00123456 in main at main.c:25
5679        call (void) fprintf (mylog,"at line 25, glob=%d\n",glob)
5680        continue
5681(gdb)
5682@end example
5683
5684Note that the @code{info break} displays the dynamic printf commands
5685as normal breakpoint commands; you can thus easily see the effect of
5686the variable settings.
5687
5688@item set disconnected-dprintf on
5689@itemx set disconnected-dprintf off
5690@kindex set disconnected-dprintf
5691Choose whether @code{dprintf} commands should continue to run if
5692@value{GDBN} has disconnected from the target.  This only applies
5693if the @code{dprintf-style} is @code{agent}.
5694
5695@item show disconnected-dprintf off
5696@kindex show disconnected-dprintf
5697Show the current choice for disconnected @code{dprintf}.
5698
5699@end table
5700
5701@value{GDBN} does not check the validity of function and channel,
5702relying on you to supply values that are meaningful for the contexts
5703in which they are being used.  For instance, the function and channel
5704may be the values of local variables, but if that is the case, then
5705all enabled dynamic prints must be at locations within the scope of
5706those locals.  If evaluation fails, @value{GDBN} will report an error.
5707
5708@node Save Breakpoints
5709@subsection How to save breakpoints to a file
5710
5711To save breakpoint definitions to a file use the @w{@code{save
5712breakpoints}} command.
5713
5714@table @code
5715@kindex save breakpoints
5716@cindex save breakpoints to a file for future sessions
5717@item save breakpoints [@var{filename}]
5718This command saves all current breakpoint definitions together with
5719their commands and ignore counts, into a file @file{@var{filename}}
5720suitable for use in a later debugging session.  This includes all
5721types of breakpoints (breakpoints, watchpoints, catchpoints,
5722tracepoints).  To read the saved breakpoint definitions, use the
5723@code{source} command (@pxref{Command Files}).  Note that watchpoints
5724with expressions involving local variables may fail to be recreated
5725because it may not be possible to access the context where the
5726watchpoint is valid anymore.  Because the saved breakpoint definitions
5727are simply a sequence of @value{GDBN} commands that recreate the
5728breakpoints, you can edit the file in your favorite editing program,
5729and remove the breakpoint definitions you're not interested in, or
5730that can no longer be recreated.
5731@end table
5732
5733@node Static Probe Points
5734@subsection Static Probe Points
5735
5736@cindex static probe point, SystemTap
5737@cindex static probe point, DTrace
5738@value{GDBN} supports @dfn{SDT} probes in the code.  @acronym{SDT} stands
5739for Statically Defined Tracing, and the probes are designed to have a tiny
5740runtime code and data footprint, and no dynamic relocations.
5741
5742Currently, the following types of probes are supported on
5743ELF-compatible systems:
5744
5745@itemize @bullet
5746
5747@item @code{SystemTap} (@uref{http://sourceware.org/systemtap/})
5748@acronym{SDT} probes@footnote{See
5749@uref{http://sourceware.org/systemtap/wiki/AddingUserSpaceProbingToApps}
5750for more information on how to add @code{SystemTap} @acronym{SDT}
5751probes in your applications.}.  @code{SystemTap} probes are usable
5752from assembly, C and C@t{++} languages@footnote{See
5753@uref{http://sourceware.org/systemtap/wiki/UserSpaceProbeImplementation}
5754for a good reference on how the @acronym{SDT} probes are implemented.}.
5755
5756@item @code{DTrace} (@uref{http://oss.oracle.com/projects/DTrace})
5757@acronym{USDT} probes.  @code{DTrace} probes are usable from C and
5758C@t{++} languages.
5759@end itemize
5760
5761@cindex semaphores on static probe points
5762Some @code{SystemTap} probes have an associated semaphore variable;
5763for instance, this happens automatically if you defined your probe
5764using a DTrace-style @file{.d} file.  If your probe has a semaphore,
5765@value{GDBN} will automatically enable it when you specify a
5766breakpoint using the @samp{-probe-stap} notation.  But, if you put a
5767breakpoint at a probe's location by some other method (e.g.,
5768@code{break file:line}), then @value{GDBN} will not automatically set
5769the semaphore.  @code{DTrace} probes do not support semaphores.
5770
5771You can examine the available static static probes using @code{info
5772probes}, with optional arguments:
5773
5774@table @code
5775@kindex info probes
5776@item info probes @r{[}@var{type}@r{]} @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5777If given, @var{type} is either @code{stap} for listing
5778@code{SystemTap} probes or @code{dtrace} for listing @code{DTrace}
5779probes.  If omitted all probes are listed regardless of their types.
5780
5781If given, @var{provider} is a regular expression used to match against provider
5782names when selecting which probes to list.  If omitted, probes by all
5783probes from all providers are listed.
5784
5785If given, @var{name} is a regular expression to match against probe names
5786when selecting which probes to list.  If omitted, probe names are not
5787considered when deciding whether to display them.
5788
5789If given, @var{objfile} is a regular expression used to select which
5790object files (executable or shared libraries) to examine.  If not
5791given, all object files are considered.
5792
5793@item info probes all
5794List the available static probes, from all types.
5795@end table
5796
5797@cindex enabling and disabling probes
5798Some probe points can be enabled and/or disabled.  The effect of
5799enabling or disabling a probe depends on the type of probe being
5800handled.  Some @code{DTrace} probes can be enabled or
5801disabled, but @code{SystemTap} probes cannot be disabled.
5802
5803You can enable (or disable) one or more probes using the following
5804commands, with optional arguments:
5805
5806@table @code
5807@kindex enable probes
5808@item enable probes @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5809If given, @var{provider} is a regular expression used to match against
5810provider names when selecting which probes to enable.  If omitted,
5811all probes from all providers are enabled.
5812
5813If given, @var{name} is a regular expression to match against probe
5814names when selecting which probes to enable.  If omitted, probe names
5815are not considered when deciding whether to enable them.
5816
5817If given, @var{objfile} is a regular expression used to select which
5818object files (executable or shared libraries) to examine.  If not
5819given, all object files are considered.
5820
5821@kindex disable probes
5822@item disable probes @r{[}@var{provider} @r{[}@var{name} @r{[}@var{objfile}@r{]}@r{]}@r{]}
5823See the @code{enable probes} command above for a description of the
5824optional arguments accepted by this command.
5825@end table
5826
5827@vindex $_probe_arg@r{, convenience variable}
5828A probe may specify up to twelve arguments.  These are available at the
5829point at which the probe is defined---that is, when the current PC is
5830at the probe's location.  The arguments are available using the
5831convenience variables (@pxref{Convenience Vars})
5832@code{$_probe_arg0}@dots{}@code{$_probe_arg11}.  In @code{SystemTap}
5833probes each probe argument is an integer of the appropriate size;
5834types are not preserved.  In @code{DTrace} probes types are preserved
5835provided that they are recognized as such by @value{GDBN}; otherwise
5836the value of the probe argument will be a long integer.  The
5837convenience variable @code{$_probe_argc} holds the number of arguments
5838at the current probe point.
5839
5840These variables are always available, but attempts to access them at
5841any location other than a probe point will cause @value{GDBN} to give
5842an error message.
5843
5844
5845@c  @ifclear BARETARGET
5846@node Error in Breakpoints
5847@subsection ``Cannot insert breakpoints''
5848
5849If you request too many active hardware-assisted breakpoints and
5850watchpoints, you will see this error message:
5851
5852@c FIXME: the precise wording of this message may change; the relevant
5853@c source change is not committed yet (Sep 3, 1999).
5854@smallexample
5855Stopped; cannot insert breakpoints.
5856You may have requested too many hardware breakpoints and watchpoints.
5857@end smallexample
5858
5859@noindent
5860This message is printed when you attempt to resume the program, since
5861only then @value{GDBN} knows exactly how many hardware breakpoints and
5862watchpoints it needs to insert.
5863
5864When this message is printed, you need to disable or remove some of the
5865hardware-assisted breakpoints and watchpoints, and then continue.
5866
5867@node Breakpoint-related Warnings
5868@subsection ``Breakpoint address adjusted...''
5869@cindex breakpoint address adjusted
5870
5871Some processor architectures place constraints on the addresses at
5872which breakpoints may be placed.  For architectures thus constrained,
5873@value{GDBN} will attempt to adjust the breakpoint's address to comply
5874with the constraints dictated by the architecture.
5875
5876One example of such an architecture is the Fujitsu FR-V.  The FR-V is
5877a VLIW architecture in which a number of RISC-like instructions may be
5878bundled together for parallel execution.  The FR-V architecture
5879constrains the location of a breakpoint instruction within such a
5880bundle to the instruction with the lowest address.  @value{GDBN}
5881honors this constraint by adjusting a breakpoint's address to the
5882first in the bundle.
5883
5884It is not uncommon for optimized code to have bundles which contain
5885instructions from different source statements, thus it may happen that
5886a breakpoint's address will be adjusted from one source statement to
5887another.  Since this adjustment may significantly alter @value{GDBN}'s
5888breakpoint related behavior from what the user expects, a warning is
5889printed when the breakpoint is first set and also when the breakpoint
5890is hit.
5891
5892A warning like the one below is printed when setting a breakpoint
5893that's been subject to address adjustment:
5894
5895@smallexample
5896warning: Breakpoint address adjusted from 0x00010414 to 0x00010410.
5897@end smallexample
5898
5899Such warnings are printed both for user settable and @value{GDBN}'s
5900internal breakpoints.  If you see one of these warnings, you should
5901verify that a breakpoint set at the adjusted address will have the
5902desired affect.  If not, the breakpoint in question may be removed and
5903other breakpoints may be set which will have the desired behavior.
5904E.g., it may be sufficient to place the breakpoint at a later
5905instruction.  A conditional breakpoint may also be useful in some
5906cases to prevent the breakpoint from triggering too often.
5907
5908@value{GDBN} will also issue a warning when stopping at one of these
5909adjusted breakpoints:
5910
5911@smallexample
5912warning: Breakpoint 1 address previously adjusted from 0x00010414
5913to 0x00010410.
5914@end smallexample
5915
5916When this warning is encountered, it may be too late to take remedial
5917action except in cases where the breakpoint is hit earlier or more
5918frequently than expected.
5919
5920@node Continuing and Stepping
5921@section Continuing and Stepping
5922
5923@cindex stepping
5924@cindex continuing
5925@cindex resuming execution
5926@dfn{Continuing} means resuming program execution until your program
5927completes normally.  In contrast, @dfn{stepping} means executing just
5928one more ``step'' of your program, where ``step'' may mean either one
5929line of source code, or one machine instruction (depending on what
5930particular command you use).  Either when continuing or when stepping,
5931your program may stop even sooner, due to a breakpoint or a signal.  (If
5932it stops due to a signal, you may want to use @code{handle}, or use
5933@samp{signal 0} to resume execution (@pxref{Signals, ,Signals}),
5934or you may step into the signal's handler (@pxref{stepping and signal
5935handlers}).)
5936
5937@table @code
5938@kindex continue
5939@kindex c @r{(@code{continue})}
5940@kindex fg @r{(resume foreground execution)}
5941@item continue @r{[}@var{ignore-count}@r{]}
5942@itemx c @r{[}@var{ignore-count}@r{]}
5943@itemx fg @r{[}@var{ignore-count}@r{]}
5944Resume program execution, at the address where your program last stopped;
5945any breakpoints set at that address are bypassed.  The optional argument
5946@var{ignore-count} allows you to specify a further number of times to
5947ignore a breakpoint at this location; its effect is like that of
5948@code{ignore} (@pxref{Conditions, ,Break Conditions}).
5949
5950The argument @var{ignore-count} is meaningful only when your program
5951stopped due to a breakpoint.  At other times, the argument to
5952@code{continue} is ignored.
5953
5954The synonyms @code{c} and @code{fg} (for @dfn{foreground}, as the
5955debugged program is deemed to be the foreground program) are provided
5956purely for convenience, and have exactly the same behavior as
5957@code{continue}.
5958@end table
5959
5960To resume execution at a different place, you can use @code{return}
5961(@pxref{Returning, ,Returning from a Function}) to go back to the
5962calling function; or @code{jump} (@pxref{Jumping, ,Continuing at a
5963Different Address}) to go to an arbitrary location in your program.
5964
5965A typical technique for using stepping is to set a breakpoint
5966(@pxref{Breakpoints, ,Breakpoints; Watchpoints; and Catchpoints}) at the
5967beginning of the function or the section of your program where a problem
5968is believed to lie, run your program until it stops at that breakpoint,
5969and then step through the suspect area, examining the variables that are
5970interesting, until you see the problem happen.
5971
5972@table @code
5973@kindex step
5974@kindex s @r{(@code{step})}
5975@item step
5976Continue running your program until control reaches a different source
5977line, then stop it and return control to @value{GDBN}.  This command is
5978abbreviated @code{s}.
5979
5980@quotation
5981@c "without debugging information" is imprecise; actually "without line
5982@c numbers in the debugging information".  (gcc -g1 has debugging info but
5983@c not line numbers).  But it seems complex to try to make that
5984@c distinction here.
5985@emph{Warning:} If you use the @code{step} command while control is
5986within a function that was compiled without debugging information,
5987execution proceeds until control reaches a function that does have
5988debugging information.  Likewise, it will not step into a function which
5989is compiled without debugging information.  To step through functions
5990without debugging information, use the @code{stepi} command, described
5991below.
5992@end quotation
5993
5994The @code{step} command only stops at the first instruction of a source
5995line.  This prevents the multiple stops that could otherwise occur in
5996@code{switch} statements, @code{for} loops, etc.  @code{step} continues
5997to stop if a function that has debugging information is called within
5998the line.  In other words, @code{step} @emph{steps inside} any functions
5999called within the line.
6000
6001Also, the @code{step} command only enters a function if there is line
6002number information for the function.  Otherwise it acts like the
6003@code{next} command.  This avoids problems when using @code{cc -gl}
6004on @acronym{MIPS} machines.  Previously, @code{step} entered subroutines if there
6005was any debugging information about the routine.
6006
6007@item step @var{count}
6008Continue running as in @code{step}, but do so @var{count} times.  If a
6009breakpoint is reached, or a signal not related to stepping occurs before
6010@var{count} steps, stepping stops right away.
6011
6012@kindex next
6013@kindex n @r{(@code{next})}
6014@item next @r{[}@var{count}@r{]}
6015Continue to the next source line in the current (innermost) stack frame.
6016This is similar to @code{step}, but function calls that appear within
6017the line of code are executed without stopping.  Execution stops when
6018control reaches a different line of code at the original stack level
6019that was executing when you gave the @code{next} command.  This command
6020is abbreviated @code{n}.
6021
6022An argument @var{count} is a repeat count, as for @code{step}.
6023
6024
6025@c  FIX ME!!  Do we delete this, or is there a way it fits in with
6026@c  the following paragraph?   ---  Vctoria
6027@c
6028@c  @code{next} within a function that lacks debugging information acts like
6029@c  @code{step}, but any function calls appearing within the code of the
6030@c  function are executed without stopping.
6031
6032The @code{next} command only stops at the first instruction of a
6033source line.  This prevents multiple stops that could otherwise occur in
6034@code{switch} statements, @code{for} loops, etc.
6035
6036@kindex set step-mode
6037@item set step-mode
6038@cindex functions without line info, and stepping
6039@cindex stepping into functions with no line info
6040@itemx set step-mode on
6041The @code{set step-mode on} command causes the @code{step} command to
6042stop at the first instruction of a function which contains no debug line
6043information rather than stepping over it.
6044
6045This is useful in cases where you may be interested in inspecting the
6046machine instructions of a function which has no symbolic info and do not
6047want @value{GDBN} to automatically skip over this function.
6048
6049@item set step-mode off
6050Causes the @code{step} command to step over any functions which contains no
6051debug information.  This is the default.
6052
6053@item show step-mode
6054Show whether @value{GDBN} will stop in or step over functions without
6055source line debug information.
6056
6057@kindex finish
6058@kindex fin @r{(@code{finish})}
6059@item finish
6060Continue running until just after function in the selected stack frame
6061returns.  Print the returned value (if any).  This command can be
6062abbreviated as @code{fin}.
6063
6064Contrast this with the @code{return} command (@pxref{Returning,
6065,Returning from a Function}).
6066
6067@kindex set print finish
6068@kindex show print finish
6069@item set print finish @r{[}on|off@r{]}
6070@itemx show print finish
6071By default the @code{finish} command will show the value that is
6072returned by the function.  This can be disabled using @code{set print
6073finish off}.  When disabled, the value is still entered into the value
6074history (@pxref{Value History}), but not displayed.
6075
6076@kindex until
6077@kindex u @r{(@code{until})}
6078@cindex run until specified location
6079@item until
6080@itemx u
6081Continue running until a source line past the current line, in the
6082current stack frame, is reached.  This command is used to avoid single
6083stepping through a loop more than once.  It is like the @code{next}
6084command, except that when @code{until} encounters a jump, it
6085automatically continues execution until the program counter is greater
6086than the address of the jump.
6087
6088This means that when you reach the end of a loop after single stepping
6089though it, @code{until} makes your program continue execution until it
6090exits the loop.  In contrast, a @code{next} command at the end of a loop
6091simply steps back to the beginning of the loop, which forces you to step
6092through the next iteration.
6093
6094@code{until} always stops your program if it attempts to exit the current
6095stack frame.
6096
6097@code{until} may produce somewhat counterintuitive results if the order
6098of machine code does not match the order of the source lines.  For
6099example, in the following excerpt from a debugging session, the @code{f}
6100(@code{frame}) command shows that execution is stopped at line
6101@code{206}; yet when we use @code{until}, we get to line @code{195}:
6102
6103@smallexample
6104(@value{GDBP}) f
6105#0  main (argc=4, argv=0xf7fffae8) at m4.c:206
6106206                 expand_input();
6107(@value{GDBP}) until
6108195             for ( ; argc > 0; NEXTARG) @{
6109@end smallexample
6110
6111This happened because, for execution efficiency, the compiler had
6112generated code for the loop closure test at the end, rather than the
6113start, of the loop---even though the test in a C @code{for}-loop is
6114written before the body of the loop.  The @code{until} command appeared
6115to step back to the beginning of the loop when it advanced to this
6116expression; however, it has not really gone to an earlier
6117statement---not in terms of the actual machine code.
6118
6119@code{until} with no argument works by means of single
6120instruction stepping, and hence is slower than @code{until} with an
6121argument.
6122
6123@item until @var{location}
6124@itemx u @var{location}
6125Continue running your program until either the specified @var{location} is
6126reached, or the current stack frame returns.  The location is any of
6127the forms described in @ref{Specify Location}.
6128This form of the command uses temporary breakpoints, and
6129hence is quicker than @code{until} without an argument.  The specified
6130location is actually reached only if it is in the current frame.  This
6131implies that @code{until} can be used to skip over recursive function
6132invocations.  For instance in the code below, if the current location is
6133line @code{96}, issuing @code{until 99} will execute the program up to
6134line @code{99} in the same invocation of factorial, i.e., after the inner
6135invocations have returned.
6136
6137@smallexample
613894	int factorial (int value)
613995	@{
614096	    if (value > 1) @{
614197            value *= factorial (value - 1);
614298	    @}
614399	    return (value);
6144100     @}
6145@end smallexample
6146
6147
6148@kindex advance @var{location}
6149@item advance @var{location}
6150Continue running the program up to the given @var{location}.  An argument is
6151required, which should be of one of the forms described in
6152@ref{Specify Location}.
6153Execution will also stop upon exit from the current stack
6154frame.  This command is similar to @code{until}, but @code{advance} will
6155not skip over recursive function calls, and the target location doesn't
6156have to be in the same frame as the current one.
6157
6158
6159@kindex stepi
6160@kindex si @r{(@code{stepi})}
6161@item stepi
6162@itemx stepi @var{arg}
6163@itemx si
6164Execute one machine instruction, then stop and return to the debugger.
6165
6166It is often useful to do @samp{display/i $pc} when stepping by machine
6167instructions.  This makes @value{GDBN} automatically display the next
6168instruction to be executed, each time your program stops.  @xref{Auto
6169Display,, Automatic Display}.
6170
6171An argument is a repeat count, as in @code{step}.
6172
6173@need 750
6174@kindex nexti
6175@kindex ni @r{(@code{nexti})}
6176@item nexti
6177@itemx nexti @var{arg}
6178@itemx ni
6179Execute one machine instruction, but if it is a function call,
6180proceed until the function returns.
6181
6182An argument is a repeat count, as in @code{next}.
6183
6184@end table
6185
6186@anchor{range stepping}
6187@cindex range stepping
6188@cindex target-assisted range stepping
6189By default, and if available, @value{GDBN} makes use of
6190target-assisted @dfn{range stepping}.  In other words, whenever you
6191use a stepping command (e.g., @code{step}, @code{next}), @value{GDBN}
6192tells the target to step the corresponding range of instruction
6193addresses instead of issuing multiple single-steps.  This speeds up
6194line stepping, particularly for remote targets.  Ideally, there should
6195be no reason you would want to turn range stepping off.  However, it's
6196possible that a bug in the debug info, a bug in the remote stub (for
6197remote targets), or even a bug in @value{GDBN} could make line
6198stepping behave incorrectly when target-assisted range stepping is
6199enabled.  You can use the following command to turn off range stepping
6200if necessary:
6201
6202@table @code
6203@kindex set range-stepping
6204@kindex show range-stepping
6205@item set range-stepping
6206@itemx show range-stepping
6207Control whether range stepping is enabled.
6208
6209If @code{on}, and the target supports it, @value{GDBN} tells the
6210target to step a range of addresses itself, instead of issuing
6211multiple single-steps.  If @code{off}, @value{GDBN} always issues
6212single-steps, even if range stepping is supported by the target.  The
6213default is @code{on}.
6214
6215@end table
6216
6217@node Skipping Over Functions and Files
6218@section Skipping Over Functions and Files
6219@cindex skipping over functions and files
6220
6221The program you are debugging may contain some functions which are
6222uninteresting to debug.  The @code{skip} command lets you tell @value{GDBN} to
6223skip a function, all functions in a file or a particular function in
6224a particular file when stepping.
6225
6226For example, consider the following C function:
6227
6228@smallexample
6229101     int func()
6230102     @{
6231103         foo(boring());
6232104         bar(boring());
6233105     @}
6234@end smallexample
6235
6236@noindent
6237Suppose you wish to step into the functions @code{foo} and @code{bar}, but you
6238are not interested in stepping through @code{boring}.  If you run @code{step}
6239at line 103, you'll enter @code{boring()}, but if you run @code{next}, you'll
6240step over both @code{foo} and @code{boring}!
6241
6242One solution is to @code{step} into @code{boring} and use the @code{finish}
6243command to immediately exit it.  But this can become tedious if @code{boring}
6244is called from many places.
6245
6246A more flexible solution is to execute @kbd{skip boring}.  This instructs
6247@value{GDBN} never to step into @code{boring}.  Now when you execute
6248@code{step} at line 103, you'll step over @code{boring} and directly into
6249@code{foo}.
6250
6251Functions may be skipped by providing either a function name, linespec
6252(@pxref{Specify Location}), regular expression that matches the function's
6253name, file name or a @code{glob}-style pattern that matches the file name.
6254
6255On Posix systems the form of the regular expression is
6256``Extended Regular Expressions''.  See for example @samp{man 7 regex}
6257on @sc{gnu}/Linux systems.  On non-Posix systems the form of the regular
6258expression is whatever is provided by the @code{regcomp} function of
6259the underlying system.
6260See for example @samp{man 7 glob} on @sc{gnu}/Linux systems for a
6261description of @code{glob}-style patterns.
6262
6263@table @code
6264@kindex skip
6265@item skip @r{[}@var{options}@r{]}
6266The basic form of the @code{skip} command takes zero or more options
6267that specify what to skip.
6268The @var{options} argument is any useful combination of the following:
6269
6270@table @code
6271@item -file @var{file}
6272@itemx -fi @var{file}
6273Functions in @var{file} will be skipped over when stepping.
6274
6275@item -gfile @var{file-glob-pattern}
6276@itemx -gfi @var{file-glob-pattern}
6277@cindex skipping over files via glob-style patterns
6278Functions in files matching @var{file-glob-pattern} will be skipped
6279over when stepping.
6280
6281@smallexample
6282(gdb) skip -gfi utils/*.c
6283@end smallexample
6284
6285@item -function @var{linespec}
6286@itemx -fu @var{linespec}
6287Functions named by @var{linespec} or the function containing the line
6288named by @var{linespec} will be skipped over when stepping.
6289@xref{Specify Location}.
6290
6291@item -rfunction @var{regexp}
6292@itemx -rfu @var{regexp}
6293@cindex skipping over functions via regular expressions
6294Functions whose name matches @var{regexp} will be skipped over when stepping.
6295
6296This form is useful for complex function names.
6297For example, there is generally no need to step into C@t{++} @code{std::string}
6298constructors or destructors.  Plus with C@t{++} templates it can be hard to
6299write out the full name of the function, and often it doesn't matter what
6300the template arguments are.  Specifying the function to be skipped as a
6301regular expression makes this easier.
6302
6303@smallexample
6304(gdb) skip -rfu ^std::(allocator|basic_string)<.*>::~?\1 *\(
6305@end smallexample
6306
6307If you want to skip every templated C@t{++} constructor and destructor
6308in the @code{std} namespace you can do:
6309
6310@smallexample
6311(gdb) skip -rfu ^std::([a-zA-z0-9_]+)<.*>::~?\1 *\(
6312@end smallexample
6313@end table
6314
6315If no options are specified, the function you're currently debugging
6316will be skipped.
6317
6318@kindex skip function
6319@item skip function @r{[}@var{linespec}@r{]}
6320After running this command, the function named by @var{linespec} or the
6321function containing the line named by @var{linespec} will be skipped over when
6322stepping.  @xref{Specify Location}.
6323
6324If you do not specify @var{linespec}, the function you're currently debugging
6325will be skipped.
6326
6327(If you have a function called @code{file} that you want to skip, use
6328@kbd{skip function file}.)
6329
6330@kindex skip file
6331@item skip file @r{[}@var{filename}@r{]}
6332After running this command, any function whose source lives in @var{filename}
6333will be skipped over when stepping.
6334
6335@smallexample
6336(gdb) skip file boring.c
6337File boring.c will be skipped when stepping.
6338@end smallexample
6339
6340If you do not specify @var{filename}, functions whose source lives in the file
6341you're currently debugging will be skipped.
6342@end table
6343
6344Skips can be listed, deleted, disabled, and enabled, much like breakpoints.
6345These are the commands for managing your list of skips:
6346
6347@table @code
6348@kindex info skip
6349@item info skip @r{[}@var{range}@r{]}
6350Print details about the specified skip(s).  If @var{range} is not specified,
6351print a table with details about all functions and files marked for skipping.
6352@code{info skip} prints the following information about each skip:
6353
6354@table @emph
6355@item Identifier
6356A number identifying this skip.
6357@item Enabled or Disabled
6358Enabled skips are marked with @samp{y}.
6359Disabled skips are marked with @samp{n}.
6360@item Glob
6361If the file name is a @samp{glob} pattern this is @samp{y}.
6362Otherwise it is @samp{n}.
6363@item File
6364The name or @samp{glob} pattern of the file to be skipped.
6365If no file is specified this is @samp{<none>}.
6366@item RE
6367If the function name is a @samp{regular expression} this is @samp{y}.
6368Otherwise it is @samp{n}.
6369@item Function
6370The name or regular expression of the function to skip.
6371If no function is specified this is @samp{<none>}.
6372@end table
6373
6374@kindex skip delete
6375@item skip delete @r{[}@var{range}@r{]}
6376Delete the specified skip(s).  If @var{range} is not specified, delete all
6377skips.
6378
6379@kindex skip enable
6380@item skip enable @r{[}@var{range}@r{]}
6381Enable the specified skip(s).  If @var{range} is not specified, enable all
6382skips.
6383
6384@kindex skip disable
6385@item skip disable @r{[}@var{range}@r{]}
6386Disable the specified skip(s).  If @var{range} is not specified, disable all
6387skips.
6388
6389@kindex set debug skip
6390@item set debug skip @r{[}on|off@r{]}
6391Set whether to print the debug output about skipping files and functions.
6392
6393@kindex show debug skip
6394@item show debug skip
6395Show whether the debug output about skipping files and functions is printed.
6396
6397@end table
6398
6399@node Signals
6400@section Signals
6401@cindex signals
6402
6403A signal is an asynchronous event that can happen in a program.  The
6404operating system defines the possible kinds of signals, and gives each
6405kind a name and a number.  For example, in Unix @code{SIGINT} is the
6406signal a program gets when you type an interrupt character (often @kbd{Ctrl-c});
6407@code{SIGSEGV} is the signal a program gets from referencing a place in
6408memory far away from all the areas in use; @code{SIGALRM} occurs when
6409the alarm clock timer goes off (which happens only if your program has
6410requested an alarm).
6411
6412@cindex fatal signals
6413Some signals, including @code{SIGALRM}, are a normal part of the
6414functioning of your program.  Others, such as @code{SIGSEGV}, indicate
6415errors; these signals are @dfn{fatal} (they kill your program immediately) if the
6416program has not specified in advance some other way to handle the signal.
6417@code{SIGINT} does not indicate an error in your program, but it is normally
6418fatal so it can carry out the purpose of the interrupt: to kill the program.
6419
6420@value{GDBN} has the ability to detect any occurrence of a signal in your
6421program.  You can tell @value{GDBN} in advance what to do for each kind of
6422signal.
6423
6424@cindex handling signals
6425Normally, @value{GDBN} is set up to let the non-erroneous signals like
6426@code{SIGALRM} be silently passed to your program
6427(so as not to interfere with their role in the program's functioning)
6428but to stop your program immediately whenever an error signal happens.
6429You can change these settings with the @code{handle} command.
6430
6431@table @code
6432@kindex info signals
6433@kindex info handle
6434@item info signals
6435@itemx info handle
6436Print a table of all the kinds of signals and how @value{GDBN} has been told to
6437handle each one.  You can use this to see the signal numbers of all
6438the defined types of signals.
6439
6440@item info signals @var{sig}
6441Similar, but print information only about the specified signal number.
6442
6443@code{info handle} is an alias for @code{info signals}.
6444
6445@item catch signal @r{[}@var{signal}@dots{} @r{|} @samp{all}@r{]}
6446Set a catchpoint for the indicated signals.  @xref{Set Catchpoints},
6447for details about this command.
6448
6449@kindex handle
6450@item handle @var{signal} @r{[}@var{keywords}@dots{}@r{]}
6451Change the way @value{GDBN} handles signal @var{signal}.  The @var{signal}
6452can be the number of a signal or its name (with or without the
6453@samp{SIG} at the beginning); a list of signal numbers of the form
6454@samp{@var{low}-@var{high}}; or the word @samp{all}, meaning all the
6455known signals.  Optional arguments @var{keywords}, described below,
6456say what change to make.
6457@end table
6458
6459@c @group
6460The keywords allowed by the @code{handle} command can be abbreviated.
6461Their full names are:
6462
6463@table @code
6464@item nostop
6465@value{GDBN} should not stop your program when this signal happens.  It may
6466still print a message telling you that the signal has come in.
6467
6468@item stop
6469@value{GDBN} should stop your program when this signal happens.  This implies
6470the @code{print} keyword as well.
6471
6472@item print
6473@value{GDBN} should print a message when this signal happens.
6474
6475@item noprint
6476@value{GDBN} should not mention the occurrence of the signal at all.  This
6477implies the @code{nostop} keyword as well.
6478
6479@item pass
6480@itemx noignore
6481@value{GDBN} should allow your program to see this signal; your program
6482can handle the signal, or else it may terminate if the signal is fatal
6483and not handled.  @code{pass} and @code{noignore} are synonyms.
6484
6485@item nopass
6486@itemx ignore
6487@value{GDBN} should not allow your program to see this signal.
6488@code{nopass} and @code{ignore} are synonyms.
6489@end table
6490@c @end group
6491
6492When a signal stops your program, the signal is not visible to the
6493program until you
6494continue.  Your program sees the signal then, if @code{pass} is in
6495effect for the signal in question @emph{at that time}.  In other words,
6496after @value{GDBN} reports a signal, you can use the @code{handle}
6497command with @code{pass} or @code{nopass} to control whether your
6498program sees that signal when you continue.
6499
6500The default is set to @code{nostop}, @code{noprint}, @code{pass} for
6501non-erroneous signals such as @code{SIGALRM}, @code{SIGWINCH} and
6502@code{SIGCHLD}, and to @code{stop}, @code{print}, @code{pass} for the
6503erroneous signals.
6504
6505You can also use the @code{signal} command to prevent your program from
6506seeing a signal, or cause it to see a signal it normally would not see,
6507or to give it any signal at any time.  For example, if your program stopped
6508due to some sort of memory reference error, you might store correct
6509values into the erroneous variables and continue, hoping to see more
6510execution; but your program would probably terminate immediately as
6511a result of the fatal signal once it saw the signal.  To prevent this,
6512you can continue with @samp{signal 0}.  @xref{Signaling, ,Giving your
6513Program a Signal}.
6514
6515@cindex stepping and signal handlers
6516@anchor{stepping and signal handlers}
6517
6518@value{GDBN} optimizes for stepping the mainline code.  If a signal
6519that has @code{handle nostop} and @code{handle pass} set arrives while
6520a stepping command (e.g., @code{stepi}, @code{step}, @code{next}) is
6521in progress, @value{GDBN} lets the signal handler run and then resumes
6522stepping the mainline code once the signal handler returns.  In other
6523words, @value{GDBN} steps over the signal handler.  This prevents
6524signals that you've specified as not interesting (with @code{handle
6525nostop}) from changing the focus of debugging unexpectedly.  Note that
6526the signal handler itself may still hit a breakpoint, stop for another
6527signal that has @code{handle stop} in effect, or for any other event
6528that normally results in stopping the stepping command sooner.  Also
6529note that @value{GDBN} still informs you that the program received a
6530signal if @code{handle print} is set.
6531
6532@anchor{stepping into signal handlers}
6533
6534If you set @code{handle pass} for a signal, and your program sets up a
6535handler for it, then issuing a stepping command, such as @code{step}
6536or @code{stepi}, when your program is stopped due to the signal will
6537step @emph{into} the signal handler (if the target supports that).
6538
6539Likewise, if you use the @code{queue-signal} command to queue a signal
6540to be delivered to the current thread when execution of the thread
6541resumes (@pxref{Signaling, ,Giving your Program a Signal}), then a
6542stepping command will step into the signal handler.
6543
6544Here's an example, using @code{stepi} to step to the first instruction
6545of @code{SIGUSR1}'s handler:
6546
6547@smallexample
6548(@value{GDBP}) handle SIGUSR1
6549Signal        Stop      Print   Pass to program Description
6550SIGUSR1       Yes       Yes     Yes             User defined signal 1
6551(@value{GDBP}) c
6552Continuing.
6553
6554Program received signal SIGUSR1, User defined signal 1.
6555main () sigusr1.c:28
655628        p = 0;
6557(@value{GDBP}) si
6558sigusr1_handler () at sigusr1.c:9
65599       @{
6560@end smallexample
6561
6562The same, but using @code{queue-signal} instead of waiting for the
6563program to receive the signal first:
6564
6565@smallexample
6566(@value{GDBP}) n
656728        p = 0;
6568(@value{GDBP}) queue-signal SIGUSR1
6569(@value{GDBP}) si
6570sigusr1_handler () at sigusr1.c:9
65719       @{
6572(@value{GDBP})
6573@end smallexample
6574
6575@cindex extra signal information
6576@anchor{extra signal information}
6577
6578On some targets, @value{GDBN} can inspect extra signal information
6579associated with the intercepted signal, before it is actually
6580delivered to the program being debugged.  This information is exported
6581by the convenience variable @code{$_siginfo}, and consists of data
6582that is passed by the kernel to the signal handler at the time of the
6583receipt of a signal.  The data type of the information itself is
6584target dependent.  You can see the data type using the @code{ptype
6585$_siginfo} command.  On Unix systems, it typically corresponds to the
6586standard @code{siginfo_t} type, as defined in the @file{signal.h}
6587system header.
6588
6589Here's an example, on a @sc{gnu}/Linux system, printing the stray
6590referenced address that raised a segmentation fault.
6591
6592@smallexample
6593@group
6594(@value{GDBP}) continue
6595Program received signal SIGSEGV, Segmentation fault.
65960x0000000000400766 in main ()
659769        *(int *)p = 0;
6598(@value{GDBP}) ptype $_siginfo
6599type = struct @{
6600    int si_signo;
6601    int si_errno;
6602    int si_code;
6603    union @{
6604        int _pad[28];
6605        struct @{...@} _kill;
6606        struct @{...@} _timer;
6607        struct @{...@} _rt;
6608        struct @{...@} _sigchld;
6609        struct @{...@} _sigfault;
6610        struct @{...@} _sigpoll;
6611    @} _sifields;
6612@}
6613(@value{GDBP}) ptype $_siginfo._sifields._sigfault
6614type = struct @{
6615    void *si_addr;
6616@}
6617(@value{GDBP}) p $_siginfo._sifields._sigfault.si_addr
6618$1 = (void *) 0x7ffff7ff7000
6619@end group
6620@end smallexample
6621
6622Depending on target support, @code{$_siginfo} may also be writable.
6623
6624@cindex Intel MPX boundary violations
6625@cindex boundary violations, Intel MPX
6626On some targets, a @code{SIGSEGV} can be caused by a boundary
6627violation, i.e., accessing an address outside of the allowed range.
6628In those cases @value{GDBN} may displays additional information,
6629depending on how @value{GDBN} has been told to handle the signal.
6630With @code{handle stop SIGSEGV}, @value{GDBN} displays the violation
6631kind: "Upper" or "Lower", the memory address accessed and the
6632bounds, while with @code{handle nostop SIGSEGV} no additional
6633information is displayed.
6634
6635The usual output of a segfault is:
6636@smallexample
6637Program received signal SIGSEGV, Segmentation fault
66380x0000000000400d7c in upper () at i386-mpx-sigsegv.c:68
663968        value = *(p + len);
6640@end smallexample
6641
6642While a bound violation is presented as:
6643@smallexample
6644Program received signal SIGSEGV, Segmentation fault
6645Upper bound violation while accessing address 0x7fffffffc3b3
6646Bounds: [lower = 0x7fffffffc390, upper = 0x7fffffffc3a3]
66470x0000000000400d7c in upper () at i386-mpx-sigsegv.c:68
664868        value = *(p + len);
6649@end smallexample
6650
6651@node Thread Stops
6652@section Stopping and Starting Multi-thread Programs
6653
6654@cindex stopped threads
6655@cindex threads, stopped
6656
6657@cindex continuing threads
6658@cindex threads, continuing
6659
6660@value{GDBN} supports debugging programs with multiple threads
6661(@pxref{Threads,, Debugging Programs with Multiple Threads}).  There
6662are two modes of controlling execution of your program within the
6663debugger.  In the default mode, referred to as @dfn{all-stop mode},
6664when any thread in your program stops (for example, at a breakpoint
6665or while being stepped), all other threads in the program are also stopped by
6666@value{GDBN}.  On some targets, @value{GDBN} also supports
6667@dfn{non-stop mode}, in which other threads can continue to run freely while
6668you examine the stopped thread in the debugger.
6669
6670@menu
6671* All-Stop Mode::		All threads stop when GDB takes control
6672* Non-Stop Mode::		Other threads continue to execute
6673* Background Execution::	Running your program asynchronously
6674* Thread-Specific Breakpoints::	Controlling breakpoints
6675* Interrupted System Calls::	GDB may interfere with system calls
6676* Observer Mode::               GDB does not alter program behavior
6677@end menu
6678
6679@node All-Stop Mode
6680@subsection All-Stop Mode
6681
6682@cindex all-stop mode
6683
6684In all-stop mode, whenever your program stops under @value{GDBN} for any reason,
6685@emph{all} threads of execution stop, not just the current thread.  This
6686allows you to examine the overall state of the program, including
6687switching between threads, without worrying that things may change
6688underfoot.
6689
6690Conversely, whenever you restart the program, @emph{all} threads start
6691executing.  @emph{This is true even when single-stepping} with commands
6692like @code{step} or @code{next}.
6693
6694In particular, @value{GDBN} cannot single-step all threads in lockstep.
6695Since thread scheduling is up to your debugging target's operating
6696system (not controlled by @value{GDBN}), other threads may
6697execute more than one statement while the current thread completes a
6698single step.  Moreover, in general other threads stop in the middle of a
6699statement, rather than at a clean statement boundary, when the program
6700stops.
6701
6702You might even find your program stopped in another thread after
6703continuing or even single-stepping.  This happens whenever some other
6704thread runs into a breakpoint, a signal, or an exception before the
6705first thread completes whatever you requested.
6706
6707@cindex automatic thread selection
6708@cindex switching threads automatically
6709@cindex threads, automatic switching
6710Whenever @value{GDBN} stops your program, due to a breakpoint or a
6711signal, it automatically selects the thread where that breakpoint or
6712signal happened.  @value{GDBN} alerts you to the context switch with a
6713message such as @samp{[Switching to Thread @var{n}]} to identify the
6714thread.
6715
6716On some OSes, you can modify @value{GDBN}'s default behavior by
6717locking the OS scheduler to allow only a single thread to run.
6718
6719@table @code
6720@item set scheduler-locking @var{mode}
6721@cindex scheduler locking mode
6722@cindex lock scheduler
6723Set the scheduler locking mode.  It applies to normal execution,
6724record mode, and replay mode.  If it is @code{off}, then there is no
6725locking and any thread may run at any time.  If @code{on}, then only
6726the current thread may run when the inferior is resumed.  The
6727@code{step} mode optimizes for single-stepping; it prevents other
6728threads from preempting the current thread while you are stepping, so
6729that the focus of debugging does not change unexpectedly.  Other
6730threads never get a chance to run when you step, and they are
6731completely free to run when you use commands like @samp{continue},
6732@samp{until}, or @samp{finish}.  However, unless another thread hits a
6733breakpoint during its timeslice, @value{GDBN} does not change the
6734current thread away from the thread that you are debugging.  The
6735@code{replay} mode behaves like @code{off} in record mode and like
6736@code{on} in replay mode.
6737
6738@item show scheduler-locking
6739Display the current scheduler locking mode.
6740@end table
6741
6742@cindex resume threads of multiple processes simultaneously
6743By default, when you issue one of the execution commands such as
6744@code{continue}, @code{next} or @code{step}, @value{GDBN} allows only
6745threads of the current inferior to run.  For example, if @value{GDBN}
6746is attached to two inferiors, each with two threads, the
6747@code{continue} command resumes only the two threads of the current
6748inferior.  This is useful, for example, when you debug a program that
6749forks and you want to hold the parent stopped (so that, for instance,
6750it doesn't run to exit), while you debug the child.  In other
6751situations, you may not be interested in inspecting the current state
6752of any of the processes @value{GDBN} is attached to, and you may want
6753to resume them all until some breakpoint is hit.  In the latter case,
6754you can instruct @value{GDBN} to allow all threads of all the
6755inferiors to run with the @w{@code{set schedule-multiple}} command.
6756
6757@table @code
6758@kindex set schedule-multiple
6759@item set schedule-multiple
6760Set the mode for allowing threads of multiple processes to be resumed
6761when an execution command is issued.  When @code{on}, all threads of
6762all processes are allowed to run.  When @code{off}, only the threads
6763of the current process are resumed.  The default is @code{off}.  The
6764@code{scheduler-locking} mode takes precedence when set to @code{on},
6765or while you are stepping and set to @code{step}.
6766
6767@item show schedule-multiple
6768Display the current mode for resuming the execution of threads of
6769multiple processes.
6770@end table
6771
6772@node Non-Stop Mode
6773@subsection Non-Stop Mode
6774
6775@cindex non-stop mode
6776
6777@c This section is really only a place-holder, and needs to be expanded
6778@c with more details.
6779
6780For some multi-threaded targets, @value{GDBN} supports an optional
6781mode of operation in which you can examine stopped program threads in
6782the debugger while other threads continue to execute freely.  This
6783minimizes intrusion when debugging live systems, such as programs
6784where some threads have real-time constraints or must continue to
6785respond to external events.  This is referred to as @dfn{non-stop} mode.
6786
6787In non-stop mode, when a thread stops to report a debugging event,
6788@emph{only} that thread is stopped; @value{GDBN} does not stop other
6789threads as well, in contrast to the all-stop mode behavior.  Additionally,
6790execution commands such as @code{continue} and @code{step} apply by default
6791only to the current thread in non-stop mode, rather than all threads as
6792in all-stop mode.  This allows you to control threads explicitly in
6793ways that are not possible in all-stop mode --- for example, stepping
6794one thread while allowing others to run freely, stepping
6795one thread while holding all others stopped, or stepping several threads
6796independently and simultaneously.
6797
6798To enter non-stop mode, use this sequence of commands before you run
6799or attach to your program:
6800
6801@smallexample
6802# If using the CLI, pagination breaks non-stop.
6803set pagination off
6804
6805# Finally, turn it on!
6806set non-stop on
6807@end smallexample
6808
6809You can use these commands to manipulate the non-stop mode setting:
6810
6811@table @code
6812@kindex set non-stop
6813@item set non-stop on
6814Enable selection of non-stop mode.
6815@item set non-stop off
6816Disable selection of non-stop mode.
6817@kindex show non-stop
6818@item show non-stop
6819Show the current non-stop enablement setting.
6820@end table
6821
6822Note these commands only reflect whether non-stop mode is enabled,
6823not whether the currently-executing program is being run in non-stop mode.
6824In particular, the @code{set non-stop} preference is only consulted when
6825@value{GDBN} starts or connects to the target program, and it is generally
6826not possible to switch modes once debugging has started.  Furthermore,
6827since not all targets support non-stop mode, even when you have enabled
6828non-stop mode, @value{GDBN} may still fall back to all-stop operation by
6829default.
6830
6831In non-stop mode, all execution commands apply only to the current thread
6832by default.  That is, @code{continue} only continues one thread.
6833To continue all threads, issue @code{continue -a} or @code{c -a}.
6834
6835You can use @value{GDBN}'s background execution commands
6836(@pxref{Background Execution}) to run some threads in the background
6837while you continue to examine or step others from @value{GDBN}.
6838The MI execution commands (@pxref{GDB/MI Program Execution}) are
6839always executed asynchronously in non-stop mode.
6840
6841Suspending execution is done with the @code{interrupt} command when
6842running in the background, or @kbd{Ctrl-c} during foreground execution.
6843In all-stop mode, this stops the whole process;
6844but in non-stop mode the interrupt applies only to the current thread.
6845To stop the whole program, use @code{interrupt -a}.
6846
6847Other execution commands do not currently support the @code{-a} option.
6848
6849In non-stop mode, when a thread stops, @value{GDBN} doesn't automatically make
6850that thread current, as it does in all-stop mode.  This is because the
6851thread stop notifications are asynchronous with respect to @value{GDBN}'s
6852command interpreter, and it would be confusing if @value{GDBN} unexpectedly
6853changed to a different thread just as you entered a command to operate on the
6854previously current thread.
6855
6856@node Background Execution
6857@subsection Background Execution
6858
6859@cindex foreground execution
6860@cindex background execution
6861@cindex asynchronous execution
6862@cindex execution, foreground, background and asynchronous
6863
6864@value{GDBN}'s execution commands have two variants:  the normal
6865foreground (synchronous) behavior, and a background
6866(asynchronous) behavior.  In foreground execution, @value{GDBN} waits for
6867the program to report that some thread has stopped before prompting for
6868another command.  In background execution, @value{GDBN} immediately gives
6869a command prompt so that you can issue other commands while your program runs.
6870
6871If the target doesn't support async mode, @value{GDBN} issues an error
6872message if you attempt to use the background execution commands.
6873
6874@cindex @code{&}, background execution of commands
6875To specify background execution, add a @code{&} to the command.  For example,
6876the background form of the @code{continue} command is @code{continue&}, or
6877just @code{c&}.  The execution commands that accept background execution
6878are:
6879
6880@table @code
6881@kindex run&
6882@item run
6883@xref{Starting, , Starting your Program}.
6884
6885@item attach
6886@kindex attach&
6887@xref{Attach, , Debugging an Already-running Process}.
6888
6889@item step
6890@kindex step&
6891@xref{Continuing and Stepping, step}.
6892
6893@item stepi
6894@kindex stepi&
6895@xref{Continuing and Stepping, stepi}.
6896
6897@item next
6898@kindex next&
6899@xref{Continuing and Stepping, next}.
6900
6901@item nexti
6902@kindex nexti&
6903@xref{Continuing and Stepping, nexti}.
6904
6905@item continue
6906@kindex continue&
6907@xref{Continuing and Stepping, continue}.
6908
6909@item finish
6910@kindex finish&
6911@xref{Continuing and Stepping, finish}.
6912
6913@item until
6914@kindex until&
6915@xref{Continuing and Stepping, until}.
6916
6917@end table
6918
6919Background execution is especially useful in conjunction with non-stop
6920mode for debugging programs with multiple threads; see @ref{Non-Stop Mode}.
6921However, you can also use these commands in the normal all-stop mode with
6922the restriction that you cannot issue another execution command until the
6923previous one finishes.  Examples of commands that are valid in all-stop
6924mode while the program is running include @code{help} and @code{info break}.
6925
6926You can interrupt your program while it is running in the background by
6927using the @code{interrupt} command.
6928
6929@table @code
6930@kindex interrupt
6931@item interrupt
6932@itemx interrupt -a
6933
6934Suspend execution of the running program.  In all-stop mode,
6935@code{interrupt} stops the whole process, but in non-stop mode, it stops
6936only the current thread.  To stop the whole program in non-stop mode,
6937use @code{interrupt -a}.
6938@end table
6939
6940@node Thread-Specific Breakpoints
6941@subsection Thread-Specific Breakpoints
6942
6943When your program has multiple threads (@pxref{Threads,, Debugging
6944Programs with Multiple Threads}), you can choose whether to set
6945breakpoints on all threads, or on a particular thread.
6946
6947@table @code
6948@cindex breakpoints and threads
6949@cindex thread breakpoints
6950@kindex break @dots{} thread @var{thread-id}
6951@item break @var{location} thread @var{thread-id}
6952@itemx break @var{location} thread @var{thread-id} if @dots{}
6953@var{location} specifies source lines; there are several ways of
6954writing them (@pxref{Specify Location}), but the effect is always to
6955specify some source line.
6956
6957Use the qualifier @samp{thread @var{thread-id}} with a breakpoint command
6958to specify that you only want @value{GDBN} to stop the program when a
6959particular thread reaches this breakpoint.  The @var{thread-id} specifier
6960is one of the thread identifiers assigned by @value{GDBN}, shown
6961in the first column of the @samp{info threads} display.
6962
6963If you do not specify @samp{thread @var{thread-id}} when you set a
6964breakpoint, the breakpoint applies to @emph{all} threads of your
6965program.
6966
6967You can use the @code{thread} qualifier on conditional breakpoints as
6968well; in this case, place @samp{thread @var{thread-id}} before or
6969after the breakpoint condition, like this:
6970
6971@smallexample
6972(@value{GDBP}) break frik.c:13 thread 28 if bartab > lim
6973@end smallexample
6974
6975@end table
6976
6977Thread-specific breakpoints are automatically deleted when
6978@value{GDBN} detects the corresponding thread is no longer in the
6979thread list.  For example:
6980
6981@smallexample
6982(@value{GDBP}) c
6983Thread-specific breakpoint 3 deleted - thread 28 no longer in the thread list.
6984@end smallexample
6985
6986There are several ways for a thread to disappear, such as a regular
6987thread exit, but also when you detach from the process with the
6988@code{detach} command (@pxref{Attach, ,Debugging an Already-running
6989Process}), or if @value{GDBN} loses the remote connection
6990(@pxref{Remote Debugging}), etc.  Note that with some targets,
6991@value{GDBN} is only able to detect a thread has exited when the user
6992explictly asks for the thread list with the @code{info threads}
6993command.
6994
6995@node Interrupted System Calls
6996@subsection Interrupted System Calls
6997
6998@cindex thread breakpoints and system calls
6999@cindex system calls and thread breakpoints
7000@cindex premature return from system calls
7001There is an unfortunate side effect when using @value{GDBN} to debug
7002multi-threaded programs.  If one thread stops for a
7003breakpoint, or for some other reason, and another thread is blocked in a
7004system call, then the system call may return prematurely.  This is a
7005consequence of the interaction between multiple threads and the signals
7006that @value{GDBN} uses to implement breakpoints and other events that
7007stop execution.
7008
7009To handle this problem, your program should check the return value of
7010each system call and react appropriately.  This is good programming
7011style anyways.
7012
7013For example, do not write code like this:
7014
7015@smallexample
7016  sleep (10);
7017@end smallexample
7018
7019The call to @code{sleep} will return early if a different thread stops
7020at a breakpoint or for some other reason.
7021
7022Instead, write this:
7023
7024@smallexample
7025  int unslept = 10;
7026  while (unslept > 0)
7027    unslept = sleep (unslept);
7028@end smallexample
7029
7030A system call is allowed to return early, so the system is still
7031conforming to its specification.  But @value{GDBN} does cause your
7032multi-threaded program to behave differently than it would without
7033@value{GDBN}.
7034
7035Also, @value{GDBN} uses internal breakpoints in the thread library to
7036monitor certain events such as thread creation and thread destruction.
7037When such an event happens, a system call in another thread may return
7038prematurely, even though your program does not appear to stop.
7039
7040@node Observer Mode
7041@subsection Observer Mode
7042
7043If you want to build on non-stop mode and observe program behavior
7044without any chance of disruption by @value{GDBN}, you can set
7045variables to disable all of the debugger's attempts to modify state,
7046whether by writing memory, inserting breakpoints, etc.  These operate
7047at a low level, intercepting operations from all commands.
7048
7049When all of these are set to @code{off}, then @value{GDBN} is said to
7050be @dfn{observer mode}.  As a convenience, the variable
7051@code{observer} can be set to disable these, plus enable non-stop
7052mode.
7053
7054Note that @value{GDBN} will not prevent you from making nonsensical
7055combinations of these settings. For instance, if you have enabled
7056@code{may-insert-breakpoints} but disabled @code{may-write-memory},
7057then breakpoints that work by writing trap instructions into the code
7058stream will still not be able to be placed.
7059
7060@table @code
7061
7062@kindex observer
7063@item set observer on
7064@itemx set observer off
7065When set to @code{on}, this disables all the permission variables
7066below (except for @code{insert-fast-tracepoints}), plus enables
7067non-stop debugging.  Setting this to @code{off} switches back to
7068normal debugging, though remaining in non-stop mode.
7069
7070@item show observer
7071Show whether observer mode is on or off.
7072
7073@kindex may-write-registers
7074@item set may-write-registers on
7075@itemx set may-write-registers off
7076This controls whether @value{GDBN} will attempt to alter the values of
7077registers, such as with assignment expressions in @code{print}, or the
7078@code{jump} command.  It defaults to @code{on}.
7079
7080@item show may-write-registers
7081Show the current permission to write registers.
7082
7083@kindex may-write-memory
7084@item set may-write-memory on
7085@itemx set may-write-memory off
7086This controls whether @value{GDBN} will attempt to alter the contents
7087of memory, such as with assignment expressions in @code{print}.  It
7088defaults to @code{on}.
7089
7090@item show may-write-memory
7091Show the current permission to write memory.
7092
7093@kindex may-insert-breakpoints
7094@item set may-insert-breakpoints on
7095@itemx set may-insert-breakpoints off
7096This controls whether @value{GDBN} will attempt to insert breakpoints.
7097This affects all breakpoints, including internal breakpoints defined
7098by @value{GDBN}.  It defaults to @code{on}.
7099
7100@item show may-insert-breakpoints
7101Show the current permission to insert breakpoints.
7102
7103@kindex may-insert-tracepoints
7104@item set may-insert-tracepoints on
7105@itemx set may-insert-tracepoints off
7106This controls whether @value{GDBN} will attempt to insert (regular)
7107tracepoints at the beginning of a tracing experiment.  It affects only
7108non-fast tracepoints, fast tracepoints being under the control of
7109@code{may-insert-fast-tracepoints}.  It defaults to @code{on}.
7110
7111@item show may-insert-tracepoints
7112Show the current permission to insert tracepoints.
7113
7114@kindex may-insert-fast-tracepoints
7115@item set may-insert-fast-tracepoints on
7116@itemx set may-insert-fast-tracepoints off
7117This controls whether @value{GDBN} will attempt to insert fast
7118tracepoints at the beginning of a tracing experiment.  It affects only
7119fast tracepoints, regular (non-fast) tracepoints being under the
7120control of @code{may-insert-tracepoints}.  It defaults to @code{on}.
7121
7122@item show may-insert-fast-tracepoints
7123Show the current permission to insert fast tracepoints.
7124
7125@kindex may-interrupt
7126@item set may-interrupt on
7127@itemx set may-interrupt off
7128This controls whether @value{GDBN} will attempt to interrupt or stop
7129program execution.  When this variable is @code{off}, the
7130@code{interrupt} command will have no effect, nor will
7131@kbd{Ctrl-c}. It defaults to @code{on}.
7132
7133@item show may-interrupt
7134Show the current permission to interrupt or stop the program.
7135
7136@end table
7137
7138@node Reverse Execution
7139@chapter Running programs backward
7140@cindex reverse execution
7141@cindex running programs backward
7142
7143When you are debugging a program, it is not unusual to realize that
7144you have gone too far, and some event of interest has already happened.
7145If the target environment supports it, @value{GDBN} can allow you to
7146``rewind'' the program by running it backward.
7147
7148A target environment that supports reverse execution should be able
7149to ``undo'' the changes in machine state that have taken place as the
7150program was executing normally.  Variables, registers etc.@: should
7151revert to their previous values.  Obviously this requires a great
7152deal of sophistication on the part of the target environment; not
7153all target environments can support reverse execution.
7154
7155When a program is executed in reverse, the instructions that
7156have most recently been executed are ``un-executed'', in reverse
7157order.  The program counter runs backward, following the previous
7158thread of execution in reverse.  As each instruction is ``un-executed'',
7159the values of memory and/or registers that were changed by that
7160instruction are reverted to their previous states.  After executing
7161a piece of source code in reverse, all side effects of that code
7162should be ``undone'', and all variables should be returned to their
7163prior values@footnote{
7164Note that some side effects are easier to undo than others.  For instance,
7165memory and registers are relatively easy, but device I/O is hard.  Some
7166targets may be able undo things like device I/O, and some may not.
7167
7168The contract between @value{GDBN} and the reverse executing target
7169requires only that the target do something reasonable when
7170@value{GDBN} tells it to execute backwards, and then report the
7171results back to @value{GDBN}.  Whatever the target reports back to
7172@value{GDBN}, @value{GDBN} will report back to the user.  @value{GDBN}
7173assumes that the memory and registers that the target reports are in a
7174consistent state, but @value{GDBN} accepts whatever it is given.
7175}.
7176
7177On some platforms, @value{GDBN} has built-in support for reverse
7178execution, activated with the @code{record} or @code{record btrace}
7179commands.  @xref{Process Record and Replay}.  Some remote targets,
7180typically full system emulators, support reverse execution directly
7181without requiring any special command.
7182
7183If you are debugging in a target environment that supports
7184reverse execution, @value{GDBN} provides the following commands.
7185
7186@table @code
7187@kindex reverse-continue
7188@kindex rc @r{(@code{reverse-continue})}
7189@item reverse-continue @r{[}@var{ignore-count}@r{]}
7190@itemx rc @r{[}@var{ignore-count}@r{]}
7191Beginning at the point where your program last stopped, start executing
7192in reverse.  Reverse execution will stop for breakpoints and synchronous
7193exceptions (signals), just like normal execution.  Behavior of
7194asynchronous signals depends on the target environment.
7195
7196@kindex reverse-step
7197@kindex rs @r{(@code{step})}
7198@item reverse-step @r{[}@var{count}@r{]}
7199Run the program backward until control reaches the start of a
7200different source line; then stop it, and return control to @value{GDBN}.
7201
7202Like the @code{step} command, @code{reverse-step} will only stop
7203at the beginning of a source line.  It ``un-executes'' the previously
7204executed source line.  If the previous source line included calls to
7205debuggable functions, @code{reverse-step} will step (backward) into
7206the called function, stopping at the beginning of the @emph{last}
7207statement in the called function (typically a return statement).
7208
7209Also, as with the @code{step} command, if non-debuggable functions are
7210called, @code{reverse-step} will run thru them backward without stopping.
7211
7212@kindex reverse-stepi
7213@kindex rsi @r{(@code{reverse-stepi})}
7214@item reverse-stepi @r{[}@var{count}@r{]}
7215Reverse-execute one machine instruction.  Note that the instruction
7216to be reverse-executed is @emph{not} the one pointed to by the program
7217counter, but the instruction executed prior to that one.  For instance,
7218if the last instruction was a jump, @code{reverse-stepi} will take you
7219back from the destination of the jump to the jump instruction itself.
7220
7221@kindex reverse-next
7222@kindex rn @r{(@code{reverse-next})}
7223@item reverse-next @r{[}@var{count}@r{]}
7224Run backward to the beginning of the previous line executed in
7225the current (innermost) stack frame.  If the line contains function
7226calls, they will be ``un-executed'' without stopping.  Starting from
7227the first line of a function, @code{reverse-next} will take you back
7228to the caller of that function, @emph{before} the function was called,
7229just as the normal @code{next} command would take you from the last
7230line of a function back to its return to its caller
7231@footnote{Unless the code is too heavily optimized.}.
7232
7233@kindex reverse-nexti
7234@kindex rni @r{(@code{reverse-nexti})}
7235@item reverse-nexti @r{[}@var{count}@r{]}
7236Like @code{nexti}, @code{reverse-nexti} executes a single instruction
7237in reverse, except that called functions are ``un-executed'' atomically.
7238That is, if the previously executed instruction was a return from
7239another function, @code{reverse-nexti} will continue to execute
7240in reverse until the call to that function (from the current stack
7241frame) is reached.
7242
7243@kindex reverse-finish
7244@item reverse-finish
7245Just as the @code{finish} command takes you to the point where the
7246current function returns, @code{reverse-finish} takes you to the point
7247where it was called.  Instead of ending up at the end of the current
7248function invocation, you end up at the beginning.
7249
7250@kindex set exec-direction
7251@item set exec-direction
7252Set the direction of target execution.
7253@item set exec-direction reverse
7254@cindex execute forward or backward in time
7255@value{GDBN} will perform all execution commands in reverse, until the
7256exec-direction mode is changed to ``forward''.  Affected commands include
7257@code{step, stepi, next, nexti, continue, and finish}.  The @code{return}
7258command cannot be used in reverse mode.
7259@item set exec-direction forward
7260@value{GDBN} will perform all execution commands in the normal fashion.
7261This is the default.
7262@end table
7263
7264
7265@node Process Record and Replay
7266@chapter Recording Inferior's Execution and Replaying It
7267@cindex process record and replay
7268@cindex recording inferior's execution and replaying it
7269
7270On some platforms, @value{GDBN} provides a special @dfn{process record
7271and replay} target that can record a log of the process execution, and
7272replay it later with both forward and reverse execution commands.
7273
7274@cindex replay mode
7275When this target is in use, if the execution log includes the record
7276for the next instruction, @value{GDBN} will debug in @dfn{replay
7277mode}.  In the replay mode, the inferior does not really execute code
7278instructions.  Instead, all the events that normally happen during
7279code execution are taken from the execution log.  While code is not
7280really executed in replay mode, the values of registers (including the
7281program counter register) and the memory of the inferior are still
7282changed as they normally would.  Their contents are taken from the
7283execution log.
7284
7285@cindex record mode
7286If the record for the next instruction is not in the execution log,
7287@value{GDBN} will debug in @dfn{record mode}.  In this mode, the
7288inferior executes normally, and @value{GDBN} records the execution log
7289for future replay.
7290
7291The process record and replay target supports reverse execution
7292(@pxref{Reverse Execution}), even if the platform on which the
7293inferior runs does not.  However, the reverse execution is limited in
7294this case by the range of the instructions recorded in the execution
7295log.  In other words, reverse execution on platforms that don't
7296support it directly can only be done in the replay mode.
7297
7298When debugging in the reverse direction, @value{GDBN} will work in
7299replay mode as long as the execution log includes the record for the
7300previous instruction; otherwise, it will work in record mode, if the
7301platform supports reverse execution, or stop if not.
7302
7303Currently, process record and replay is supported on ARM, Aarch64,
7304Moxie, PowerPC, PowerPC64, S/390, and x86 (i386/amd64) running
7305GNU/Linux.  Process record and replay can be used both when native
7306debugging, and when remote debugging via @code{gdbserver}.
7307
7308For architecture environments that support process record and replay,
7309@value{GDBN} provides the following commands:
7310
7311@table @code
7312@kindex target record
7313@kindex target record-full
7314@kindex target record-btrace
7315@kindex record
7316@kindex record full
7317@kindex record btrace
7318@kindex record btrace bts
7319@kindex record btrace pt
7320@kindex record bts
7321@kindex record pt
7322@kindex rec
7323@kindex rec full
7324@kindex rec btrace
7325@kindex rec btrace bts
7326@kindex rec btrace pt
7327@kindex rec bts
7328@kindex rec pt
7329@item record @var{method}
7330This command starts the process record and replay target.  The
7331recording method can be specified as parameter.  Without a parameter
7332the command uses the @code{full} recording method.  The following
7333recording methods are available:
7334
7335@table @code
7336@item full
7337Full record/replay recording using @value{GDBN}'s software record and
7338replay implementation.  This method allows replaying and reverse
7339execution.
7340
7341@item btrace @var{format}
7342Hardware-supported instruction recording, supported on Intel
7343processors.  This method does not record data.  Further, the data is
7344collected in a ring buffer so old data will be overwritten when the
7345buffer is full.  It allows limited reverse execution.  Variables and
7346registers are not available during reverse execution.  In remote
7347debugging, recording continues on disconnect.  Recorded data can be
7348inspected after reconnecting.  The recording may be stopped using
7349@code{record stop}.
7350
7351The recording format can be specified as parameter.  Without a parameter
7352the command chooses the recording format.  The following recording
7353formats are available:
7354
7355@table @code
7356@item bts
7357@cindex branch trace store
7358Use the @dfn{Branch Trace Store} (@acronym{BTS}) recording format.  In
7359this format, the processor stores a from/to record for each executed
7360branch in the btrace ring buffer.
7361
7362@item pt
7363@cindex Intel Processor Trace
7364Use the @dfn{Intel Processor Trace} recording format.  In this
7365format, the processor stores the execution trace in a compressed form
7366that is afterwards decoded by @value{GDBN}.
7367
7368The trace can be recorded with very low overhead.  The compressed
7369trace format also allows small trace buffers to already contain a big
7370number of instructions compared to @acronym{BTS}.
7371
7372Decoding the recorded execution trace, on the other hand, is more
7373expensive than decoding @acronym{BTS} trace.  This is mostly due to the
7374increased number of instructions to process.  You should increase the
7375buffer-size with care.
7376@end table
7377
7378Not all recording formats may be available on all processors.
7379@end table
7380
7381The process record and replay target can only debug a process that is
7382already running.  Therefore, you need first to start the process with
7383the @kbd{run} or @kbd{start} commands, and then start the recording
7384with the @kbd{record @var{method}} command.
7385
7386@cindex displaced stepping, and process record and replay
7387Displaced stepping (@pxref{Maintenance Commands,, displaced stepping})
7388will be automatically disabled when process record and replay target
7389is started.  That's because the process record and replay target
7390doesn't support displaced stepping.
7391
7392@cindex non-stop mode, and process record and replay
7393@cindex asynchronous execution, and process record and replay
7394If the inferior is in the non-stop mode (@pxref{Non-Stop Mode}) or in
7395the asynchronous execution mode (@pxref{Background Execution}), not
7396all recording methods are available.  The @code{full} recording method
7397does not support these two modes.
7398
7399@kindex record stop
7400@kindex rec s
7401@item record stop
7402Stop the process record and replay target.  When process record and
7403replay target stops, the entire execution log will be deleted and the
7404inferior will either be terminated, or will remain in its final state.
7405
7406When you stop the process record and replay target in record mode (at
7407the end of the execution log), the inferior will be stopped at the
7408next instruction that would have been recorded.  In other words, if
7409you record for a while and then stop recording, the inferior process
7410will be left in the same state as if the recording never happened.
7411
7412On the other hand, if the process record and replay target is stopped
7413while in replay mode (that is, not at the end of the execution log,
7414but at some earlier point), the inferior process will become ``live''
7415at that earlier state, and it will then be possible to continue the
7416usual ``live'' debugging of the process from that state.
7417
7418When the inferior process exits, or @value{GDBN} detaches from it,
7419process record and replay target will automatically stop itself.
7420
7421@kindex record goto
7422@item record goto
7423Go to a specific location in the execution log.  There are several
7424ways to specify the location to go to:
7425
7426@table @code
7427@item record goto begin
7428@itemx record goto start
7429Go to the beginning of the execution log.
7430
7431@item record goto end
7432Go to the end of the execution log.
7433
7434@item record goto @var{n}
7435Go to instruction number @var{n} in the execution log.
7436@end table
7437
7438@kindex record save
7439@item record save @var{filename}
7440Save the execution log to a file @file{@var{filename}}.
7441Default filename is @file{gdb_record.@var{process_id}}, where
7442@var{process_id} is the process ID of the inferior.
7443
7444This command may not be available for all recording methods.
7445
7446@kindex record restore
7447@item record restore @var{filename}
7448Restore the execution log from a file @file{@var{filename}}.
7449File must have been created with @code{record save}.
7450
7451@kindex set record full
7452@item set record full insn-number-max @var{limit}
7453@itemx set record full insn-number-max unlimited
7454Set the limit of instructions to be recorded for the @code{full}
7455recording method.  Default value is 200000.
7456
7457If @var{limit} is a positive number, then @value{GDBN} will start
7458deleting instructions from the log once the number of the record
7459instructions becomes greater than @var{limit}.  For every new recorded
7460instruction, @value{GDBN} will delete the earliest recorded
7461instruction to keep the number of recorded instructions at the limit.
7462(Since deleting recorded instructions loses information, @value{GDBN}
7463lets you control what happens when the limit is reached, by means of
7464the @code{stop-at-limit} option, described below.)
7465
7466If @var{limit} is @code{unlimited} or zero, @value{GDBN} will never
7467delete recorded instructions from the execution log.  The number of
7468recorded instructions is limited only by the available memory.
7469
7470@kindex show record full
7471@item show record full insn-number-max
7472Show the limit of instructions to be recorded with the @code{full}
7473recording method.
7474
7475@item set record full stop-at-limit
7476Control the behavior of the  @code{full} recording method when the
7477number of recorded instructions reaches the limit.  If ON (the
7478default), @value{GDBN} will stop when the limit is reached for the
7479first time and ask you whether you want to stop the inferior or
7480continue running it and recording the execution log.  If you decide
7481to continue recording, each new recorded instruction will cause the
7482oldest one to be deleted.
7483
7484If this option is OFF, @value{GDBN} will automatically delete the
7485oldest record to make room for each new one, without asking.
7486
7487@item show record full stop-at-limit
7488Show the current setting of @code{stop-at-limit}.
7489
7490@item set record full memory-query
7491Control the behavior when @value{GDBN} is unable to record memory
7492changes caused by an instruction for the @code{full} recording method.
7493If ON, @value{GDBN} will query whether to stop the inferior in that
7494case.
7495
7496If this option is OFF (the default), @value{GDBN} will automatically
7497ignore the effect of such instructions on memory.  Later, when
7498@value{GDBN} replays this execution log, it will mark the log of this
7499instruction as not accessible, and it will not affect the replay
7500results.
7501
7502@item show record full memory-query
7503Show the current setting of @code{memory-query}.
7504
7505@kindex set record btrace
7506The @code{btrace} record target does not trace data.  As a
7507convenience, when replaying, @value{GDBN} reads read-only memory off
7508the live program directly, assuming that the addresses of the
7509read-only areas don't change.  This for example makes it possible to
7510disassemble code while replaying, but not to print variables.
7511In some cases, being able to inspect variables might be useful.
7512You can use the following command for that:
7513
7514@item set record btrace replay-memory-access
7515Control the behavior of the @code{btrace} recording method when
7516accessing memory during replay.  If @code{read-only} (the default),
7517@value{GDBN} will only allow accesses to read-only memory.
7518If @code{read-write}, @value{GDBN} will allow accesses to read-only
7519and to read-write memory.  Beware that the accessed memory corresponds
7520to the live target and not necessarily to the current replay
7521position.
7522
7523@item set record btrace cpu @var{identifier}
7524Set the processor to be used for enabling workarounds for processor
7525errata when decoding the trace.
7526
7527Processor errata are defects in processor operation, caused by its
7528design or manufacture.  They can cause a trace not to match the
7529specification.  This, in turn, may cause trace decode to fail.
7530@value{GDBN} can detect erroneous trace packets and correct them, thus
7531avoiding the decoding failures.  These corrections are known as
7532@dfn{errata workarounds}, and are enabled based on the processor on
7533which the trace was recorded.
7534
7535By default, @value{GDBN} attempts to detect the processor
7536automatically, and apply the necessary workarounds for it.  However,
7537you may need to specify the processor if @value{GDBN} does not yet
7538support it.  This command allows you to do that, and also allows to
7539disable the workarounds.
7540
7541The argument @var{identifier} identifies the @sc{cpu} and is of the
7542form: @code{@var{vendor}:@var{processor identifier}}.  In addition,
7543there are two special identifiers, @code{none} and @code{auto}
7544(default).
7545
7546The following vendor identifiers and corresponding processor
7547identifiers are currently supported:
7548
7549@multitable @columnfractions .1 .9
7550
7551@item @code{intel}
7552@tab @var{family}/@var{model}[/@var{stepping}]
7553
7554@end multitable
7555
7556On GNU/Linux systems, the processor @var{family}, @var{model}, and
7557@var{stepping} can be obtained from @code{/proc/cpuinfo}.
7558
7559If @var{identifier} is @code{auto}, enable errata workarounds for the
7560processor on which the trace was recorded.  If @var{identifier} is
7561@code{none}, errata workarounds are disabled.
7562
7563For example, when using an old @value{GDBN} on a new system, decode
7564may fail because @value{GDBN} does not support the new processor.  It
7565often suffices to specify an older processor that @value{GDBN}
7566supports.
7567
7568@smallexample
7569(gdb) info record
7570Active record target: record-btrace
7571Recording format: Intel Processor Trace.
7572Buffer size: 16kB.
7573Failed to configure the Intel Processor Trace decoder: unknown cpu.
7574(gdb) set record btrace cpu intel:6/158
7575(gdb) info record
7576Active record target: record-btrace
7577Recording format: Intel Processor Trace.
7578Buffer size: 16kB.
7579Recorded 84872 instructions in 3189 functions (0 gaps) for thread 1 (...).
7580@end smallexample
7581
7582@kindex show record btrace
7583@item show record btrace replay-memory-access
7584Show the current setting of @code{replay-memory-access}.
7585
7586@item show record btrace cpu
7587Show the processor to be used for enabling trace decode errata
7588workarounds.
7589
7590@kindex set record btrace bts
7591@item set record btrace bts buffer-size @var{size}
7592@itemx set record btrace bts buffer-size unlimited
7593Set the requested ring buffer size for branch tracing in @acronym{BTS}
7594format.  Default is 64KB.
7595
7596If @var{size} is a positive number, then @value{GDBN} will try to
7597allocate a buffer of at least @var{size} bytes for each new thread
7598that uses the btrace recording method and the @acronym{BTS} format.
7599The actually obtained buffer size may differ from the requested
7600@var{size}.  Use the @code{info record} command to see the actual
7601buffer size for each thread that uses the btrace recording method and
7602the @acronym{BTS} format.
7603
7604If @var{limit} is @code{unlimited} or zero, @value{GDBN} will try to
7605allocate a buffer of 4MB.
7606
7607Bigger buffers mean longer traces.  On the other hand, @value{GDBN} will
7608also need longer to process the branch trace data before it can be used.
7609
7610@item show record btrace bts buffer-size @var{size}
7611Show the current setting of the requested ring buffer size for branch
7612tracing in @acronym{BTS} format.
7613
7614@kindex set record btrace pt
7615@item set record btrace pt buffer-size @var{size}
7616@itemx set record btrace pt buffer-size unlimited
7617Set the requested ring buffer size for branch tracing in Intel
7618Processor Trace format.  Default is 16KB.
7619
7620If @var{size} is a positive number, then @value{GDBN} will try to
7621allocate a buffer of at least @var{size} bytes for each new thread
7622that uses the btrace recording method and the Intel Processor Trace
7623format.  The actually obtained buffer size may differ from the
7624requested @var{size}.  Use the @code{info record} command to see the
7625actual buffer size for each thread.
7626
7627If @var{limit} is @code{unlimited} or zero, @value{GDBN} will try to
7628allocate a buffer of 4MB.
7629
7630Bigger buffers mean longer traces.  On the other hand, @value{GDBN} will
7631also need longer to process the branch trace data before it can be used.
7632
7633@item show record btrace pt buffer-size @var{size}
7634Show the current setting of the requested ring buffer size for branch
7635tracing in Intel Processor Trace format.
7636
7637@kindex info record
7638@item info record
7639Show various statistics about the recording depending on the recording
7640method:
7641
7642@table @code
7643@item full
7644For the @code{full} recording method, it shows the state of process
7645record and its in-memory execution log buffer, including:
7646
7647@itemize @bullet
7648@item
7649Whether in record mode or replay mode.
7650@item
7651Lowest recorded instruction number (counting from when the current execution log started recording instructions).
7652@item
7653Highest recorded instruction number.
7654@item
7655Current instruction about to be replayed (if in replay mode).
7656@item
7657Number of instructions contained in the execution log.
7658@item
7659Maximum number of instructions that may be contained in the execution log.
7660@end itemize
7661
7662@item btrace
7663For the @code{btrace} recording method, it shows:
7664
7665@itemize @bullet
7666@item
7667Recording format.
7668@item
7669Number of instructions that have been recorded.
7670@item
7671Number of blocks of sequential control-flow formed by the recorded
7672instructions.
7673@item
7674Whether in record mode or replay mode.
7675@end itemize
7676
7677For the @code{bts} recording format, it also shows:
7678@itemize @bullet
7679@item
7680Size of the perf ring buffer.
7681@end itemize
7682
7683For the @code{pt} recording format, it also shows:
7684@itemize @bullet
7685@item
7686Size of the perf ring buffer.
7687@end itemize
7688@end table
7689
7690@kindex record delete
7691@kindex rec del
7692@item record delete
7693When record target runs in replay mode (``in the past''), delete the
7694subsequent execution log and begin to record a new execution log starting
7695from the current address.  This means you will abandon the previously
7696recorded ``future'' and begin recording a new ``future''.
7697
7698@kindex record instruction-history
7699@kindex rec instruction-history
7700@item record instruction-history
7701Disassembles instructions from the recorded execution log.  By
7702default, ten instructions are disassembled.  This can be changed using
7703the @code{set record instruction-history-size} command.  Instructions
7704are printed in execution order.
7705
7706It can also print mixed source+disassembly if you specify the the
7707@code{/m} or @code{/s} modifier, and print the raw instructions in hex
7708as well as in symbolic form by specifying the @code{/r} modifier.
7709
7710The current position marker is printed for the instruction at the
7711current program counter value.  This instruction can appear multiple
7712times in the trace and the current position marker will be printed
7713every time.  To omit the current position marker, specify the
7714@code{/p} modifier.
7715
7716To better align the printed instructions when the trace contains
7717instructions from more than one function, the function name may be
7718omitted by specifying the @code{/f} modifier.
7719
7720Speculatively executed instructions are prefixed with @samp{?}.  This
7721feature is not available for all recording formats.
7722
7723There are several ways to specify what part of the execution log to
7724disassemble:
7725
7726@table @code
7727@item record instruction-history @var{insn}
7728Disassembles ten instructions starting from instruction number
7729@var{insn}.
7730
7731@item record instruction-history @var{insn}, +/-@var{n}
7732Disassembles @var{n} instructions around instruction number
7733@var{insn}.  If @var{n} is preceded with @code{+}, disassembles
7734@var{n} instructions after instruction number @var{insn}.  If
7735@var{n} is preceded with @code{-}, disassembles @var{n}
7736instructions before instruction number @var{insn}.
7737
7738@item record instruction-history
7739Disassembles ten more instructions after the last disassembly.
7740
7741@item record instruction-history -
7742Disassembles ten more instructions before the last disassembly.
7743
7744@item record instruction-history @var{begin}, @var{end}
7745Disassembles instructions beginning with instruction number
7746@var{begin} until instruction number @var{end}.  The instruction
7747number @var{end} is included.
7748@end table
7749
7750This command may not be available for all recording methods.
7751
7752@kindex set record
7753@item set record instruction-history-size @var{size}
7754@itemx set record instruction-history-size unlimited
7755Define how many instructions to disassemble in the @code{record
7756instruction-history} command.  The default value is 10.
7757A @var{size} of @code{unlimited} means unlimited instructions.
7758
7759@kindex show record
7760@item show record instruction-history-size
7761Show how many instructions to disassemble in the @code{record
7762instruction-history} command.
7763
7764@kindex record function-call-history
7765@kindex rec function-call-history
7766@item record function-call-history
7767Prints the execution history at function granularity. It prints one
7768line for each sequence of instructions that belong to the same
7769function giving the name of that function, the source lines
7770for this instruction sequence (if the @code{/l} modifier is
7771specified), and the instructions numbers that form the sequence (if
7772the @code{/i} modifier is specified).  The function names are indented
7773to reflect the call stack depth if the @code{/c} modifier is
7774specified.  The @code{/l}, @code{/i}, and @code{/c} modifiers can be
7775given together.
7776
7777@smallexample
7778(@value{GDBP}) @b{list 1, 10}
77791   void foo (void)
77802   @{
77813   @}
77824
77835   void bar (void)
77846   @{
77857     ...
77868     foo ();
77879     ...
778810  @}
7789(@value{GDBP}) @b{record function-call-history /ilc}
77901  bar     inst 1,4     at foo.c:6,8
77912    foo   inst 5,10    at foo.c:2,3
77923  bar     inst 11,13   at foo.c:9,10
7793@end smallexample
7794
7795By default, ten lines are printed.  This can be changed using the
7796@code{set record function-call-history-size} command.  Functions are
7797printed in execution order.  There are several ways to specify what
7798to print:
7799
7800@table @code
7801@item record function-call-history @var{func}
7802Prints ten functions starting from function number @var{func}.
7803
7804@item record function-call-history @var{func}, +/-@var{n}
7805Prints @var{n} functions around function number @var{func}.  If
7806@var{n} is preceded with @code{+}, prints @var{n} functions after
7807function number @var{func}.  If @var{n} is preceded with @code{-},
7808prints @var{n} functions before function number @var{func}.
7809
7810@item record function-call-history
7811Prints ten more functions after the last ten-line print.
7812
7813@item record function-call-history -
7814Prints ten more functions before the last ten-line print.
7815
7816@item record function-call-history @var{begin}, @var{end}
7817Prints functions beginning with function number @var{begin} until
7818function number @var{end}.  The function number @var{end} is included.
7819@end table
7820
7821This command may not be available for all recording methods.
7822
7823@item set record function-call-history-size @var{size}
7824@itemx set record function-call-history-size unlimited
7825Define how many lines to print in the
7826@code{record function-call-history} command.  The default value is 10.
7827A size of @code{unlimited} means unlimited lines.
7828
7829@item show record function-call-history-size
7830Show how many lines to print in the
7831@code{record function-call-history} command.
7832@end table
7833
7834
7835@node Stack
7836@chapter Examining the Stack
7837
7838When your program has stopped, the first thing you need to know is where it
7839stopped and how it got there.
7840
7841@cindex call stack
7842Each time your program performs a function call, information about the call
7843is generated.
7844That information includes the location of the call in your program,
7845the arguments of the call,
7846and the local variables of the function being called.
7847The information is saved in a block of data called a @dfn{stack frame}.
7848The stack frames are allocated in a region of memory called the @dfn{call
7849stack}.
7850
7851When your program stops, the @value{GDBN} commands for examining the
7852stack allow you to see all of this information.
7853
7854@cindex selected frame
7855One of the stack frames is @dfn{selected} by @value{GDBN} and many
7856@value{GDBN} commands refer implicitly to the selected frame.  In
7857particular, whenever you ask @value{GDBN} for the value of a variable in
7858your program, the value is found in the selected frame.  There are
7859special @value{GDBN} commands to select whichever frame you are
7860interested in.  @xref{Selection, ,Selecting a Frame}.
7861
7862When your program stops, @value{GDBN} automatically selects the
7863currently executing frame and describes it briefly, similar to the
7864@code{frame} command (@pxref{Frame Info, ,Information about a Frame}).
7865
7866@menu
7867* Frames::                      Stack frames
7868* Backtrace::                   Backtraces
7869* Selection::                   Selecting a frame
7870* Frame Info::                  Information on a frame
7871* Frame Apply::                 Applying a command to several frames
7872* Frame Filter Management::     Managing frame filters
7873
7874@end menu
7875
7876@node Frames
7877@section Stack Frames
7878
7879@cindex frame, definition
7880@cindex stack frame
7881The call stack is divided up into contiguous pieces called @dfn{stack
7882frames}, or @dfn{frames} for short; each frame is the data associated
7883with one call to one function.  The frame contains the arguments given
7884to the function, the function's local variables, and the address at
7885which the function is executing.
7886
7887@cindex initial frame
7888@cindex outermost frame
7889@cindex innermost frame
7890When your program is started, the stack has only one frame, that of the
7891function @code{main}.  This is called the @dfn{initial} frame or the
7892@dfn{outermost} frame.  Each time a function is called, a new frame is
7893made.  Each time a function returns, the frame for that function invocation
7894is eliminated.  If a function is recursive, there can be many frames for
7895the same function.  The frame for the function in which execution is
7896actually occurring is called the @dfn{innermost} frame.  This is the most
7897recently created of all the stack frames that still exist.
7898
7899@cindex frame pointer
7900Inside your program, stack frames are identified by their addresses.  A
7901stack frame consists of many bytes, each of which has its own address; each
7902kind of computer has a convention for choosing one byte whose
7903address serves as the address of the frame.  Usually this address is kept
7904in a register called the @dfn{frame pointer register}
7905(@pxref{Registers, $fp}) while execution is going on in that frame.
7906
7907@cindex frame level
7908@cindex frame number
7909@value{GDBN} labels each existing stack frame with a @dfn{level}, a
7910number that is zero for the innermost frame, one for the frame that
7911called it, and so on upward.  These level numbers give you a way of
7912designating stack frames in @value{GDBN} commands.  The terms
7913@dfn{frame number} and @dfn{frame level} can be used interchangeably to
7914describe this number.
7915
7916@c The -fomit-frame-pointer below perennially causes hbox overflow
7917@c underflow problems.
7918@cindex frameless execution
7919Some compilers provide a way to compile functions so that they operate
7920without stack frames.  (For example, the @value{NGCC} option
7921@smallexample
7922@samp{-fomit-frame-pointer}
7923@end smallexample
7924generates functions without a frame.)
7925This is occasionally done with heavily used library functions to save
7926the frame setup time.  @value{GDBN} has limited facilities for dealing
7927with these function invocations.  If the innermost function invocation
7928has no stack frame, @value{GDBN} nevertheless regards it as though
7929it had a separate frame, which is numbered zero as usual, allowing
7930correct tracing of the function call chain.  However, @value{GDBN} has
7931no provision for frameless functions elsewhere in the stack.
7932
7933@node Backtrace
7934@section Backtraces
7935
7936@cindex traceback
7937@cindex call stack traces
7938A backtrace is a summary of how your program got where it is.  It shows one
7939line per frame, for many frames, starting with the currently executing
7940frame (frame zero), followed by its caller (frame one), and on up the
7941stack.
7942
7943@anchor{backtrace-command}
7944@kindex backtrace
7945@kindex bt @r{(@code{backtrace})}
7946To print a backtrace of the entire stack, use the @code{backtrace}
7947command, or its alias @code{bt}.  This command will print one line per
7948frame for frames in the stack.  By default, all stack frames are
7949printed.  You can stop the backtrace at any time by typing the system
7950interrupt character, normally @kbd{Ctrl-c}.
7951
7952@table @code
7953@item backtrace [@var{option}]@dots{} [@var{qualifier}]@dots{} [@var{count}]
7954@itemx bt [@var{option}]@dots{} [@var{qualifier}]@dots{} [@var{count}]
7955Print the backtrace of the entire stack.
7956
7957The optional @var{count} can be one of the following:
7958
7959@table @code
7960@item @var{n}
7961@itemx @var{n}
7962Print only the innermost @var{n} frames, where @var{n} is a positive
7963number.
7964
7965@item -@var{n}
7966@itemx -@var{n}
7967Print only the outermost @var{n} frames, where @var{n} is a positive
7968number.
7969@end table
7970
7971Options:
7972
7973@table @code
7974@item -full
7975Print the values of the local variables also.  This can be combined
7976with the optional @var{count} to limit the number of frames shown.
7977
7978@item -no-filters
7979Do not run Python frame filters on this backtrace.  @xref{Frame
7980Filter API}, for more information.  Additionally use @ref{disable
7981frame-filter all} to turn off all frame filters.  This is only
7982relevant when @value{GDBN} has been configured with @code{Python}
7983support.
7984
7985@item -hide
7986A Python frame filter might decide to ``elide'' some frames.  Normally
7987such elided frames are still printed, but they are indented relative
7988to the filtered frames that cause them to be elided.  The @code{-hide}
7989option causes elided frames to not be printed at all.
7990@end table
7991
7992The @code{backtrace} command also supports a number of options that
7993allow overriding relevant global print settings as set by @code{set
7994backtrace} and @code{set print} subcommands:
7995
7996@table @code
7997@item -past-main [@code{on}|@code{off}]
7998Set whether backtraces should continue past @code{main}.  Related setting:
7999@ref{set backtrace past-main}.
8000
8001@item -past-entry [@code{on}|@code{off}]
8002Set whether backtraces should continue past the entry point of a program.
8003Related setting: @ref{set backtrace past-entry}.
8004
8005@item -entry-values @code{no}|@code{only}|@code{preferred}|@code{if-needed}|@code{both}|@code{compact}|@code{default}
8006Set printing of function arguments at function entry.
8007Related setting: @ref{set print entry-values}.
8008
8009@item -frame-arguments @code{all}|@code{scalars}|@code{none}
8010Set printing of non-scalar frame arguments.
8011Related setting: @ref{set print frame-arguments}.
8012
8013@item -raw-frame-arguments [@code{on}|@code{off}]
8014Set whether to print frame arguments in raw form.
8015Related setting: @ref{set print raw-frame-arguments}.
8016
8017@item -frame-info @code{auto}|@code{source-line}|@code{location}|@code{source-and-location}|@code{location-and-address}|@code{short-location}
8018Set printing of frame information.
8019Related setting: @ref{set print frame-info}.
8020@end table
8021
8022The optional @var{qualifier} is maintained for backward compatibility.
8023It can be one of the following:
8024
8025@table @code
8026@item full
8027Equivalent to the @code{-full} option.
8028
8029@item no-filters
8030Equivalent to the @code{-no-filters} option.
8031
8032@item hide
8033Equivalent to the @code{-hide} option.
8034@end table
8035
8036@end table
8037
8038@kindex where
8039@kindex info stack
8040The names @code{where} and @code{info stack} (abbreviated @code{info s})
8041are additional aliases for @code{backtrace}.
8042
8043@cindex multiple threads, backtrace
8044In a multi-threaded program, @value{GDBN} by default shows the
8045backtrace only for the current thread.  To display the backtrace for
8046several or all of the threads, use the command @code{thread apply}
8047(@pxref{Threads, thread apply}).  For example, if you type @kbd{thread
8048apply all backtrace}, @value{GDBN} will display the backtrace for all
8049the threads; this is handy when you debug a core dump of a
8050multi-threaded program.
8051
8052Each line in the backtrace shows the frame number and the function name.
8053The program counter value is also shown---unless you use @code{set
8054print address off}.  The backtrace also shows the source file name and
8055line number, as well as the arguments to the function.  The program
8056counter value is omitted if it is at the beginning of the code for that
8057line number.
8058
8059Here is an example of a backtrace.  It was made with the command
8060@samp{bt 3}, so it shows the innermost three frames.
8061
8062@smallexample
8063@group
8064#0  m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
8065    at builtin.c:993
8066#1  0x6e38 in expand_macro (sym=0x2b600, data=...) at macro.c:242
8067#2  0x6840 in expand_token (obs=0x0, t=177664, td=0xf7fffb08)
8068    at macro.c:71
8069(More stack frames follow...)
8070@end group
8071@end smallexample
8072
8073@noindent
8074The display for frame zero does not begin with a program counter
8075value, indicating that your program has stopped at the beginning of the
8076code for line @code{993} of @code{builtin.c}.
8077
8078@noindent
8079The value of parameter @code{data} in frame 1 has been replaced by
8080@code{@dots{}}.  By default, @value{GDBN} prints the value of a parameter
8081only if it is a scalar (integer, pointer, enumeration, etc).  See command
8082@kbd{set print frame-arguments} in @ref{Print Settings} for more details
8083on how to configure the way function parameter values are printed.
8084The command @kbd{set print frame-info} (@pxref{Print Settings}) controls
8085what frame information is printed.
8086
8087@cindex optimized out, in backtrace
8088@cindex function call arguments, optimized out
8089If your program was compiled with optimizations, some compilers will
8090optimize away arguments passed to functions if those arguments are
8091never used after the call.  Such optimizations generate code that
8092passes arguments through registers, but doesn't store those arguments
8093in the stack frame.  @value{GDBN} has no way of displaying such
8094arguments in stack frames other than the innermost one.  Here's what
8095such a backtrace might look like:
8096
8097@smallexample
8098@group
8099#0  m4_traceon (obs=0x24eb0, argc=1, argv=0x2b8c8)
8100    at builtin.c:993
8101#1  0x6e38 in expand_macro (sym=<optimized out>) at macro.c:242
8102#2  0x6840 in expand_token (obs=0x0, t=<optimized out>, td=0xf7fffb08)
8103    at macro.c:71
8104(More stack frames follow...)
8105@end group
8106@end smallexample
8107
8108@noindent
8109The values of arguments that were not saved in their stack frames are
8110shown as @samp{<optimized out>}.
8111
8112If you need to display the values of such optimized-out arguments,
8113either deduce that from other variables whose values depend on the one
8114you are interested in, or recompile without optimizations.
8115
8116@cindex backtrace beyond @code{main} function
8117@cindex program entry point
8118@cindex startup code, and backtrace
8119Most programs have a standard user entry point---a place where system
8120libraries and startup code transition into user code.  For C this is
8121@code{main}@footnote{
8122Note that embedded programs (the so-called ``free-standing''
8123environment) are not required to have a @code{main} function as the
8124entry point.  They could even have multiple entry points.}.
8125When @value{GDBN} finds the entry function in a backtrace
8126it will terminate the backtrace, to avoid tracing into highly
8127system-specific (and generally uninteresting) code.
8128
8129If you need to examine the startup code, or limit the number of levels
8130in a backtrace, you can change this behavior:
8131
8132@table @code
8133@item set backtrace past-main
8134@itemx set backtrace past-main on
8135@anchor{set backtrace past-main}
8136@kindex set backtrace
8137Backtraces will continue past the user entry point.
8138
8139@item set backtrace past-main off
8140Backtraces will stop when they encounter the user entry point.  This is the
8141default.
8142
8143@item show backtrace past-main
8144@kindex show backtrace
8145Display the current user entry point backtrace policy.
8146
8147@item set backtrace past-entry
8148@itemx set backtrace past-entry on
8149@anchor{set backtrace past-entry}
8150Backtraces will continue past the internal entry point of an application.
8151This entry point is encoded by the linker when the application is built,
8152and is likely before the user entry point @code{main} (or equivalent) is called.
8153
8154@item set backtrace past-entry off
8155Backtraces will stop when they encounter the internal entry point of an
8156application.  This is the default.
8157
8158@item show backtrace past-entry
8159Display the current internal entry point backtrace policy.
8160
8161@item set backtrace limit @var{n}
8162@itemx set backtrace limit 0
8163@itemx set backtrace limit unlimited
8164@anchor{set backtrace limit}
8165@cindex backtrace limit
8166Limit the backtrace to @var{n} levels.  A value of @code{unlimited}
8167or zero means unlimited levels.
8168
8169@item show backtrace limit
8170Display the current limit on backtrace levels.
8171@end table
8172
8173You can control how file names are displayed.
8174
8175@table @code
8176@item set filename-display
8177@itemx set filename-display relative
8178@cindex filename-display
8179Display file names relative to the compilation directory.  This is the default.
8180
8181@item set filename-display basename
8182Display only basename of a filename.
8183
8184@item set filename-display absolute
8185Display an absolute filename.
8186
8187@item show filename-display
8188Show the current way to display filenames.
8189@end table
8190
8191@node Selection
8192@section Selecting a Frame
8193
8194Most commands for examining the stack and other data in your program work on
8195whichever stack frame is selected at the moment.  Here are the commands for
8196selecting a stack frame; all of them finish by printing a brief description
8197of the stack frame just selected.
8198
8199@table @code
8200@kindex frame@r{, selecting}
8201@kindex f @r{(@code{frame})}
8202@item frame @r{[} @var{frame-selection-spec} @r{]}
8203@item f @r{[} @var{frame-selection-spec} @r{]}
8204The @command{frame} command allows different stack frames to be
8205selected.  The @var{frame-selection-spec} can be any of the following:
8206
8207@table @code
8208@kindex frame level
8209@item @var{num}
8210@item level @var{num}
8211Select frame level @var{num}.  Recall that frame zero is the innermost
8212(currently executing) frame, frame one is the frame that called the
8213innermost one, and so on.  The highest level frame is usually the one
8214for @code{main}.
8215
8216As this is the most common method of navigating the frame stack, the
8217string @command{level} can be omitted.  For example, the following two
8218commands are equivalent:
8219
8220@smallexample
8221(@value{GDBP}) frame 3
8222(@value{GDBP}) frame level 3
8223@end smallexample
8224
8225@kindex frame address
8226@item address @var{stack-address}
8227Select the frame with stack address @var{stack-address}.  The
8228@var{stack-address} for a frame can be seen in the output of
8229@command{info frame}, for example:
8230
8231@smallexample
8232(gdb) info frame
8233Stack level 1, frame at 0x7fffffffda30:
8234 rip = 0x40066d in b (amd64-entry-value.cc:59); saved rip 0x4004c5
8235 tail call frame, caller of frame at 0x7fffffffda30
8236 source language c++.
8237 Arglist at unknown address.
8238 Locals at unknown address, Previous frame's sp is 0x7fffffffda30
8239@end smallexample
8240
8241The @var{stack-address} for this frame is @code{0x7fffffffda30} as
8242indicated by the line:
8243
8244@smallexample
8245Stack level 1, frame at 0x7fffffffda30:
8246@end smallexample
8247
8248@kindex frame function
8249@item function @var{function-name}
8250Select the stack frame for function @var{function-name}.  If there are
8251multiple stack frames for function @var{function-name} then the inner
8252most stack frame is selected.
8253
8254@kindex frame view
8255@item view @var{stack-address} @r{[} @var{pc-addr} @r{]}
8256View a frame that is not part of @value{GDBN}'s backtrace.  The frame
8257viewed has stack address @var{stack-addr}, and optionally, a program
8258counter address of @var{pc-addr}.
8259
8260This is useful mainly if the chaining of stack frames has been
8261damaged by a bug, making it impossible for @value{GDBN} to assign
8262numbers properly to all frames.  In addition, this can be useful
8263when your program has multiple stacks and switches between them.
8264
8265When viewing a frame outside the current backtrace using
8266@command{frame view} then you can always return to the original
8267stack using one of the previous stack frame selection instructions,
8268for example @command{frame level 0}.
8269
8270@end table
8271
8272@kindex up
8273@item up @var{n}
8274Move @var{n} frames up the stack; @var{n} defaults to 1.  For positive
8275numbers @var{n}, this advances toward the outermost frame, to higher
8276frame numbers, to frames that have existed longer.
8277
8278@kindex down
8279@kindex do @r{(@code{down})}
8280@item down @var{n}
8281Move @var{n} frames down the stack; @var{n} defaults to 1.  For
8282positive numbers @var{n}, this advances toward the innermost frame, to
8283lower frame numbers, to frames that were created more recently.
8284You may abbreviate @code{down} as @code{do}.
8285@end table
8286
8287All of these commands end by printing two lines of output describing the
8288frame.  The first line shows the frame number, the function name, the
8289arguments, and the source file and line number of execution in that
8290frame.  The second line shows the text of that source line.
8291
8292@need 1000
8293For example:
8294
8295@smallexample
8296@group
8297(@value{GDBP}) up
8298#1  0x22f0 in main (argc=1, argv=0xf7fffbf4, env=0xf7fffbfc)
8299    at env.c:10
830010              read_input_file (argv[i]);
8301@end group
8302@end smallexample
8303
8304After such a printout, the @code{list} command with no arguments
8305prints ten lines centered on the point of execution in the frame.
8306You can also edit the program at the point of execution with your favorite
8307editing program by typing @code{edit}.
8308@xref{List, ,Printing Source Lines},
8309for details.
8310
8311@table @code
8312@kindex select-frame
8313@item select-frame @r{[} @var{frame-selection-spec} @r{]}
8314The @code{select-frame} command is a variant of @code{frame} that does
8315not display the new frame after selecting it.  This command is
8316intended primarily for use in @value{GDBN} command scripts, where the
8317output might be unnecessary and distracting.  The
8318@var{frame-selection-spec} is as for the @command{frame} command
8319described in @ref{Selection, ,Selecting a Frame}.
8320
8321@kindex down-silently
8322@kindex up-silently
8323@item up-silently @var{n}
8324@itemx down-silently @var{n}
8325These two commands are variants of @code{up} and @code{down},
8326respectively; they differ in that they do their work silently, without
8327causing display of the new frame.  They are intended primarily for use
8328in @value{GDBN} command scripts, where the output might be unnecessary and
8329distracting.
8330@end table
8331
8332@node Frame Info
8333@section Information About a Frame
8334
8335There are several other commands to print information about the selected
8336stack frame.
8337
8338@table @code
8339@item frame
8340@itemx f
8341When used without any argument, this command does not change which
8342frame is selected, but prints a brief description of the currently
8343selected stack frame.  It can be abbreviated @code{f}.  With an
8344argument, this command is used to select a stack frame.
8345@xref{Selection, ,Selecting a Frame}.
8346
8347@kindex info frame
8348@kindex info f @r{(@code{info frame})}
8349@item info frame
8350@itemx info f
8351This command prints a verbose description of the selected stack frame,
8352including:
8353
8354@itemize @bullet
8355@item
8356the address of the frame
8357@item
8358the address of the next frame down (called by this frame)
8359@item
8360the address of the next frame up (caller of this frame)
8361@item
8362the language in which the source code corresponding to this frame is written
8363@item
8364the address of the frame's arguments
8365@item
8366the address of the frame's local variables
8367@item
8368the program counter saved in it (the address of execution in the caller frame)
8369@item
8370which registers were saved in the frame
8371@end itemize
8372
8373@noindent The verbose description is useful when
8374something has gone wrong that has made the stack format fail to fit
8375the usual conventions.
8376
8377@item info frame @r{[} @var{frame-selection-spec} @r{]}
8378@itemx info f @r{[} @var{frame-selection-spec} @r{]}
8379Print a verbose description of the frame selected by
8380@var{frame-selection-spec}.  The @var{frame-selection-spec} is the
8381same as for the @command{frame} command (@pxref{Selection, ,Selecting
8382a Frame}).  The selected frame remains unchanged by this command.
8383
8384@kindex info args
8385@item info args [-q]
8386Print the arguments of the selected frame, each on a separate line.
8387
8388The optional flag @samp{-q}, which stands for @samp{quiet}, disables
8389printing header information and messages explaining why no argument
8390have been printed.
8391
8392@item info args [-q] [-t @var{type_regexp}] [@var{regexp}]
8393Like @kbd{info args}, but only print the arguments selected
8394with the provided regexp(s).
8395
8396If @var{regexp} is provided, print only the arguments whose names
8397match the regular expression @var{regexp}.
8398
8399If @var{type_regexp} is provided, print only the arguments whose
8400types, as printed by the @code{whatis} command, match
8401the regular expression @var{type_regexp}.
8402If @var{type_regexp} contains space(s), it should be enclosed in
8403quote characters.  If needed, use backslash to escape the meaning
8404of special characters or quotes.
8405
8406If both @var{regexp} and @var{type_regexp} are provided, an argument
8407is printed only if its name matches @var{regexp} and its type matches
8408@var{type_regexp}.
8409
8410@item info locals [-q]
8411@kindex info locals
8412Print the local variables of the selected frame, each on a separate
8413line.  These are all variables (declared either static or automatic)
8414accessible at the point of execution of the selected frame.
8415
8416The optional flag @samp{-q}, which stands for @samp{quiet}, disables
8417printing header information and messages explaining why no local variables
8418have been printed.
8419
8420@item info locals [-q] [-t @var{type_regexp}] [@var{regexp}]
8421Like @kbd{info locals}, but only print the local variables selected
8422with the provided regexp(s).
8423
8424If @var{regexp} is provided, print only the local variables whose names
8425match the regular expression @var{regexp}.
8426
8427If @var{type_regexp} is provided, print only the local variables whose
8428types, as printed by the @code{whatis} command, match
8429the regular expression @var{type_regexp}.
8430If @var{type_regexp} contains space(s), it should be enclosed in
8431quote characters.  If needed, use backslash to escape the meaning
8432of special characters or quotes.
8433
8434If both @var{regexp} and @var{type_regexp} are provided, a local variable
8435is printed only if its name matches @var{regexp} and its type matches
8436@var{type_regexp}.
8437
8438The command @kbd{info locals -q -t @var{type_regexp}} can usefully be
8439combined with the commands @kbd{frame apply} and @kbd{thread apply}.
8440For example, your program might use Resource Acquisition Is
8441Initialization types (RAII) such as @code{lock_something_t}: each
8442local variable of type @code{lock_something_t} automatically places a
8443lock that is destroyed when the variable goes out of scope.  You can
8444then list all acquired locks in your program by doing
8445@smallexample
8446thread apply all -s frame apply all -s info locals -q -t lock_something_t
8447@end smallexample
8448@noindent
8449or the equivalent shorter form
8450@smallexample
8451tfaas i lo -q -t lock_something_t
8452@end smallexample
8453
8454@end table
8455
8456@node Frame Apply
8457@section Applying a Command to Several Frames.
8458@kindex frame apply
8459@cindex apply command to several frames
8460@table @code
8461@item frame apply [all | @var{count} | @var{-count} | level @var{level}@dots{}] [@var{option}]@dots{} @var{command}
8462The @code{frame apply} command allows you to apply the named
8463@var{command} to one or more frames.
8464
8465@table @code
8466@item @code{all}
8467Specify @code{all} to apply @var{command} to all frames.
8468
8469@item @var{count}
8470Use @var{count} to apply @var{command} to the innermost @var{count}
8471frames, where @var{count} is a positive number.
8472
8473@item @var{-count}
8474Use @var{-count} to apply @var{command} to the outermost @var{count}
8475frames, where @var{count} is a positive number.
8476
8477@item @code{level}
8478Use @code{level} to apply @var{command} to the set of frames identified
8479by the @var{level} list.  @var{level} is a frame level or a range of frame
8480levels as @var{level1}-@var{level2}.  The frame level is the number shown
8481in the first field of the @samp{backtrace} command output.
8482E.g., @samp{2-4 6-8 3} indicates to apply @var{command} for the frames
8483at levels 2, 3, 4, 6, 7, 8, and then again on frame at level 3.
8484
8485@end table
8486
8487Note that the frames on which @code{frame apply} applies a command are
8488also influenced by the @code{set backtrace} settings such as @code{set
8489backtrace past-main} and @code{set backtrace limit N}.
8490@xref{Backtrace,,Backtraces}.
8491
8492The @code{frame apply} command also supports a number of options that
8493allow overriding relevant @code{set backtrace} settings:
8494
8495@table @code
8496@item -past-main [@code{on}|@code{off}]
8497Whether backtraces should continue past @code{main}.
8498Related setting: @ref{set backtrace past-main}.
8499
8500@item -past-entry [@code{on}|@code{off}]
8501Whether backtraces should continue past the entry point of a program.
8502Related setting: @ref{set backtrace past-entry}.
8503@end table
8504
8505By default, @value{GDBN} displays some frame information before the
8506output produced by @var{command}, and an error raised during the
8507execution of a @var{command} will abort @code{frame apply}.  The
8508following options can be used to fine-tune these behaviors:
8509
8510@table @code
8511@item -c
8512The flag @code{-c}, which stands for @samp{continue}, causes any
8513errors in @var{command} to be displayed, and the execution of
8514@code{frame apply} then continues.
8515@item -s
8516The flag @code{-s}, which stands for @samp{silent}, causes any errors
8517or empty output produced by a @var{command} to be silently ignored.
8518That is, the execution continues, but the frame information and errors
8519are not printed.
8520@item -q
8521The flag @code{-q} (@samp{quiet}) disables printing the frame
8522information.
8523@end table
8524
8525The following example shows how the flags @code{-c} and @code{-s} are
8526working when applying the command @code{p j} to all frames, where
8527variable @code{j} can only be successfully printed in the outermost
8528@code{#1 main} frame.
8529
8530@smallexample
8531@group
8532(gdb) frame apply all p j
8533#0  some_function (i=5) at fun.c:4
8534No symbol "j" in current context.
8535(gdb) frame apply all -c p j
8536#0  some_function (i=5) at fun.c:4
8537No symbol "j" in current context.
8538#1  0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8539$1 = 5
8540(gdb) frame apply all -s p j
8541#1  0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8542$2 = 5
8543(gdb)
8544@end group
8545@end smallexample
8546
8547By default, @samp{frame apply}, prints the frame location
8548information before the command output:
8549
8550@smallexample
8551@group
8552(gdb) frame apply all p $sp
8553#0  some_function (i=5) at fun.c:4
8554$4 = (void *) 0xffffd1e0
8555#1  0x565555fb in main (argc=1, argv=0xffffd2c4) at fun.c:11
8556$5 = (void *) 0xffffd1f0
8557(gdb)
8558@end group
8559@end smallexample
8560
8561If the flag @code{-q} is given, no frame information is printed:
8562@smallexample
8563@group
8564(gdb) frame apply all -q p $sp
8565$12 = (void *) 0xffffd1e0
8566$13 = (void *) 0xffffd1f0
8567(gdb)
8568@end group
8569@end smallexample
8570
8571@end table
8572
8573@table @code
8574
8575@kindex faas
8576@cindex apply a command to all frames (ignoring errors and empty output)
8577@item faas @var{command}
8578Shortcut for @code{frame apply all -s @var{command}}.
8579Applies @var{command} on all frames, ignoring errors and empty output.
8580
8581It can for example be used to print a local variable or a function
8582argument without knowing the frame where this variable or argument
8583is, using:
8584@smallexample
8585(@value{GDBP}) faas p some_local_var_i_do_not_remember_where_it_is
8586@end smallexample
8587
8588The @code{faas} command accepts the same options as the @code{frame
8589apply} command.  @xref{Frame Apply,,frame apply}.
8590
8591Note that the command @code{tfaas @var{command}} applies @var{command}
8592on all frames of all threads.  See @xref{Threads,,Threads}.
8593@end table
8594
8595
8596@node Frame Filter Management
8597@section Management of Frame Filters.
8598@cindex managing frame filters
8599
8600Frame filters are Python based utilities to manage and decorate the
8601output of frames.  @xref{Frame Filter API}, for further information.
8602
8603Managing frame filters is performed by several commands available
8604within @value{GDBN}, detailed here.
8605
8606@table @code
8607@kindex info frame-filter
8608@item info frame-filter
8609Print a list of installed frame filters from all dictionaries, showing
8610their name, priority and enabled status.
8611
8612@kindex disable frame-filter
8613@anchor{disable frame-filter all}
8614@item disable frame-filter @var{filter-dictionary} @var{filter-name}
8615Disable a frame filter in the dictionary matching
8616@var{filter-dictionary} and @var{filter-name}.  The
8617@var{filter-dictionary} may be @code{all}, @code{global},
8618@code{progspace}, or the name of the object file where the frame filter
8619dictionary resides.  When @code{all} is specified, all frame filters
8620across all dictionaries are disabled.  The @var{filter-name} is the name
8621of the frame filter and is used when @code{all} is not the option for
8622@var{filter-dictionary}.  A disabled frame-filter is not deleted, it
8623may be enabled again later.
8624
8625@kindex enable frame-filter
8626@item enable frame-filter @var{filter-dictionary} @var{filter-name}
8627Enable a frame filter in the dictionary matching
8628@var{filter-dictionary} and @var{filter-name}.  The
8629@var{filter-dictionary} may be @code{all}, @code{global},
8630@code{progspace} or the name of the object file where the frame filter
8631dictionary resides.  When @code{all} is specified, all frame filters across
8632all dictionaries are enabled.  The @var{filter-name} is the name of the frame
8633filter and is used when @code{all} is not the option for
8634@var{filter-dictionary}.
8635
8636Example:
8637
8638@smallexample
8639(gdb) info frame-filter
8640
8641global frame-filters:
8642  Priority  Enabled  Name
8643  1000      No       PrimaryFunctionFilter
8644  100       Yes      Reverse
8645
8646progspace /build/test frame-filters:
8647  Priority  Enabled  Name
8648  100       Yes      ProgspaceFilter
8649
8650objfile /build/test frame-filters:
8651  Priority  Enabled  Name
8652  999       Yes      BuildProgramFilter
8653
8654(gdb) disable frame-filter /build/test BuildProgramFilter
8655(gdb) info frame-filter
8656
8657global frame-filters:
8658  Priority  Enabled  Name
8659  1000      No       PrimaryFunctionFilter
8660  100       Yes      Reverse
8661
8662progspace /build/test frame-filters:
8663  Priority  Enabled  Name
8664  100       Yes      ProgspaceFilter
8665
8666objfile /build/test frame-filters:
8667  Priority  Enabled  Name
8668  999       No       BuildProgramFilter
8669
8670(gdb) enable frame-filter global PrimaryFunctionFilter
8671(gdb) info frame-filter
8672
8673global frame-filters:
8674  Priority  Enabled  Name
8675  1000      Yes      PrimaryFunctionFilter
8676  100       Yes      Reverse
8677
8678progspace /build/test frame-filters:
8679  Priority  Enabled  Name
8680  100       Yes      ProgspaceFilter
8681
8682objfile /build/test frame-filters:
8683  Priority  Enabled  Name
8684  999       No       BuildProgramFilter
8685@end smallexample
8686
8687@kindex set frame-filter priority
8688@item set frame-filter priority @var{filter-dictionary} @var{filter-name} @var{priority}
8689Set the @var{priority} of a frame filter in the dictionary matching
8690@var{filter-dictionary}, and the frame filter name matching
8691@var{filter-name}.  The @var{filter-dictionary} may be @code{global},
8692@code{progspace} or the name of the object file where the frame filter
8693dictionary resides.  The @var{priority} is an integer.
8694
8695@kindex show frame-filter priority
8696@item show frame-filter priority @var{filter-dictionary} @var{filter-name}
8697Show the @var{priority} of a frame filter in the dictionary matching
8698@var{filter-dictionary}, and the frame filter name matching
8699@var{filter-name}.  The @var{filter-dictionary} may be @code{global},
8700@code{progspace} or the name of the object file where the frame filter
8701dictionary resides.
8702
8703Example:
8704
8705@smallexample
8706(gdb) info frame-filter
8707
8708global frame-filters:
8709  Priority  Enabled  Name
8710  1000      Yes      PrimaryFunctionFilter
8711  100       Yes      Reverse
8712
8713progspace /build/test frame-filters:
8714  Priority  Enabled  Name
8715  100       Yes      ProgspaceFilter
8716
8717objfile /build/test frame-filters:
8718  Priority  Enabled  Name
8719  999       No       BuildProgramFilter
8720
8721(gdb) set frame-filter priority global Reverse 50
8722(gdb) info frame-filter
8723
8724global frame-filters:
8725  Priority  Enabled  Name
8726  1000      Yes      PrimaryFunctionFilter
8727  50        Yes      Reverse
8728
8729progspace /build/test frame-filters:
8730  Priority  Enabled  Name
8731  100       Yes      ProgspaceFilter
8732
8733objfile /build/test frame-filters:
8734  Priority  Enabled  Name
8735  999       No       BuildProgramFilter
8736@end smallexample
8737@end table
8738
8739@node Source
8740@chapter Examining Source Files
8741
8742@value{GDBN} can print parts of your program's source, since the debugging
8743information recorded in the program tells @value{GDBN} what source files were
8744used to build it.  When your program stops, @value{GDBN} spontaneously prints
8745the line where it stopped.  Likewise, when you select a stack frame
8746(@pxref{Selection, ,Selecting a Frame}), @value{GDBN} prints the line where
8747execution in that frame has stopped.  You can print other portions of
8748source files by explicit command.
8749
8750If you use @value{GDBN} through its @sc{gnu} Emacs interface, you may
8751prefer to use Emacs facilities to view source; see @ref{Emacs, ,Using
8752@value{GDBN} under @sc{gnu} Emacs}.
8753
8754@menu
8755* List::                        Printing source lines
8756* Specify Location::            How to specify code locations
8757* Edit::                        Editing source files
8758* Search::                      Searching source files
8759* Source Path::                 Specifying source directories
8760* Machine Code::                Source and machine code
8761@end menu
8762
8763@node List
8764@section Printing Source Lines
8765
8766@kindex list
8767@kindex l @r{(@code{list})}
8768To print lines from a source file, use the @code{list} command
8769(abbreviated @code{l}).  By default, ten lines are printed.
8770There are several ways to specify what part of the file you want to
8771print; see @ref{Specify Location}, for the full list.
8772
8773Here are the forms of the @code{list} command most commonly used:
8774
8775@table @code
8776@item list @var{linenum}
8777Print lines centered around line number @var{linenum} in the
8778current source file.
8779
8780@item list @var{function}
8781Print lines centered around the beginning of function
8782@var{function}.
8783
8784@item list
8785Print more lines.  If the last lines printed were printed with a
8786@code{list} command, this prints lines following the last lines
8787printed; however, if the last line printed was a solitary line printed
8788as part of displaying a stack frame (@pxref{Stack, ,Examining the
8789Stack}), this prints lines centered around that line.
8790
8791@item list -
8792Print lines just before the lines last printed.
8793@end table
8794
8795@cindex @code{list}, how many lines to display
8796By default, @value{GDBN} prints ten source lines with any of these forms of
8797the @code{list} command.  You can change this using @code{set listsize}:
8798
8799@table @code
8800@kindex set listsize
8801@item set listsize @var{count}
8802@itemx set listsize unlimited
8803Make the @code{list} command display @var{count} source lines (unless
8804the @code{list} argument explicitly specifies some other number).
8805Setting @var{count} to @code{unlimited} or 0 means there's no limit.
8806
8807@kindex show listsize
8808@item show listsize
8809Display the number of lines that @code{list} prints.
8810@end table
8811
8812Repeating a @code{list} command with @key{RET} discards the argument,
8813so it is equivalent to typing just @code{list}.  This is more useful
8814than listing the same lines again.  An exception is made for an
8815argument of @samp{-}; that argument is preserved in repetition so that
8816each repetition moves up in the source file.
8817
8818In general, the @code{list} command expects you to supply zero, one or two
8819@dfn{locations}.  Locations specify source lines; there are several ways
8820of writing them (@pxref{Specify Location}), but the effect is always
8821to specify some source line.
8822
8823Here is a complete description of the possible arguments for @code{list}:
8824
8825@table @code
8826@item list @var{location}
8827Print lines centered around the line specified by @var{location}.
8828
8829@item list @var{first},@var{last}
8830Print lines from @var{first} to @var{last}.  Both arguments are
8831locations.  When a @code{list} command has two locations, and the
8832source file of the second location is omitted, this refers to
8833the same source file as the first location.
8834
8835@item list ,@var{last}
8836Print lines ending with @var{last}.
8837
8838@item list @var{first},
8839Print lines starting with @var{first}.
8840
8841@item list +
8842Print lines just after the lines last printed.
8843
8844@item list -
8845Print lines just before the lines last printed.
8846
8847@item list
8848As described in the preceding table.
8849@end table
8850
8851@node Specify Location
8852@section Specifying a Location
8853@cindex specifying location
8854@cindex location
8855@cindex source location
8856
8857@menu
8858* Linespec Locations::                Linespec locations
8859* Explicit Locations::                Explicit locations
8860* Address Locations::                 Address locations
8861@end menu
8862
8863Several @value{GDBN} commands accept arguments that specify a location
8864of your program's code.  Since @value{GDBN} is a source-level
8865debugger, a location usually specifies some line in the source code.
8866Locations may be specified using three different formats:
8867linespec locations, explicit locations, or address locations.
8868
8869@node Linespec Locations
8870@subsection Linespec Locations
8871@cindex linespec locations
8872
8873A @dfn{linespec} is a colon-separated list of source location parameters such
8874as file name, function name, etc.  Here are all the different ways of
8875specifying a linespec:
8876
8877@table @code
8878@item @var{linenum}
8879Specifies the line number @var{linenum} of the current source file.
8880
8881@item -@var{offset}
8882@itemx +@var{offset}
8883Specifies the line @var{offset} lines before or after the @dfn{current
8884line}.  For the @code{list} command, the current line is the last one
8885printed; for the breakpoint commands, this is the line at which
8886execution stopped in the currently selected @dfn{stack frame}
8887(@pxref{Frames, ,Frames}, for a description of stack frames.)  When
8888used as the second of the two linespecs in a @code{list} command,
8889this specifies the line @var{offset} lines up or down from the first
8890linespec.
8891
8892@item @var{filename}:@var{linenum}
8893Specifies the line @var{linenum} in the source file @var{filename}.
8894If @var{filename} is a relative file name, then it will match any
8895source file name with the same trailing components.  For example, if
8896@var{filename} is @samp{gcc/expr.c}, then it will match source file
8897name of @file{/build/trunk/gcc/expr.c}, but not
8898@file{/build/trunk/libcpp/expr.c} or @file{/build/trunk/gcc/x-expr.c}.
8899
8900@item @var{function}
8901Specifies the line that begins the body of the function @var{function}.
8902For example, in C, this is the line with the open brace.
8903
8904By default, in C@t{++} and Ada, @var{function} is interpreted as
8905specifying all functions named @var{function} in all scopes.  For
8906C@t{++}, this means in all namespaces and classes.  For Ada, this
8907means in all packages.
8908
8909For example, assuming a program with C@t{++} symbols named
8910@code{A::B::func} and @code{B::func}, both commands @w{@kbd{break
8911func}} and @w{@kbd{break B::func}} set a breakpoint on both symbols.
8912
8913Commands that accept a linespec let you override this with the
8914@code{-qualified} option.  For example, @w{@kbd{break -qualified
8915func}} sets a breakpoint on a free-function named @code{func} ignoring
8916any C@t{++} class methods and namespace functions called @code{func}.
8917
8918@xref{Explicit Locations}.
8919
8920@item @var{function}:@var{label}
8921Specifies the line where @var{label} appears in @var{function}.
8922
8923@item @var{filename}:@var{function}
8924Specifies the line that begins the body of the function @var{function}
8925in the file @var{filename}.  You only need the file name with a
8926function name to avoid ambiguity when there are identically named
8927functions in different source files.
8928
8929@item @var{label}
8930Specifies the line at which the label named @var{label} appears
8931in the function corresponding to the currently selected stack frame.
8932If there is no current selected stack frame (for instance, if the inferior
8933is not running), then @value{GDBN} will not search for a label.
8934
8935@cindex breakpoint at static probe point
8936@item -pstap|-probe-stap @r{[}@var{objfile}:@r{[}@var{provider}:@r{]}@r{]}@var{name}
8937The @sc{gnu}/Linux tool @code{SystemTap} provides a way for
8938applications to embed static probes.  @xref{Static Probe Points}, for more
8939information on finding and using static probes.  This form of linespec
8940specifies the location of such a static probe.
8941
8942If @var{objfile} is given, only probes coming from that shared library
8943or executable matching @var{objfile} as a regular expression are considered.
8944If @var{provider} is given, then only probes from that provider are considered.
8945If several probes match the spec, @value{GDBN} will insert a breakpoint at
8946each one of those probes.
8947@end table
8948
8949@node Explicit Locations
8950@subsection Explicit Locations
8951@cindex explicit locations
8952
8953@dfn{Explicit locations} allow the user to directly specify the source
8954location's parameters using option-value pairs.
8955
8956Explicit locations are useful when several functions, labels, or
8957file names have the same name (base name for files) in the program's
8958sources.  In these cases, explicit locations point to the source
8959line you meant more accurately and unambiguously.  Also, using
8960explicit locations might be faster in large programs.
8961
8962For example, the linespec @samp{foo:bar} may refer to a function @code{bar}
8963defined in the file named @file{foo} or the label @code{bar} in a function
8964named @code{foo}.  @value{GDBN} must search either the file system or
8965the symbol table to know.
8966
8967The list of valid explicit location options is summarized in the
8968following table:
8969
8970@table @code
8971@item -source @var{filename}
8972The value specifies the source file name.  To differentiate between
8973files with the same base name, prepend as many directories as is necessary
8974to uniquely identify the desired file, e.g., @file{foo/bar/baz.c}.  Otherwise
8975@value{GDBN} will use the first file it finds with the given base
8976name.   This option requires the use of either @code{-function} or @code{-line}.
8977
8978@item -function @var{function}
8979The value specifies the name of a function.  Operations
8980on function locations unmodified by other options (such as @code{-label}
8981or @code{-line}) refer to the line that begins the body of the function.
8982In C, for example, this is the line with the open brace.
8983
8984By default, in C@t{++} and Ada, @var{function} is interpreted as
8985specifying all functions named @var{function} in all scopes.  For
8986C@t{++}, this means in all namespaces and classes.  For Ada, this
8987means in all packages.
8988
8989For example, assuming a program with C@t{++} symbols named
8990@code{A::B::func} and @code{B::func}, both commands @w{@kbd{break
8991-function func}} and @w{@kbd{break -function B::func}} set a
8992breakpoint on both symbols.
8993
8994You can use the @kbd{-qualified} flag to override this (see below).
8995
8996@item -qualified
8997
8998This flag makes @value{GDBN} interpret a function name specified with
8999@kbd{-function} as a complete fully-qualified name.
9000
9001For example, assuming a C@t{++} program with symbols named
9002@code{A::B::func} and @code{B::func}, the @w{@kbd{break -qualified
9003-function B::func}} command sets a breakpoint on @code{B::func}, only.
9004
9005(Note: the @kbd{-qualified} option can precede a linespec as well
9006(@pxref{Linespec Locations}), so the particular example above could be
9007simplified as @w{@kbd{break -qualified B::func}}.)
9008
9009@item -label @var{label}
9010The value specifies the name of a label.  When the function
9011name is not specified, the label is searched in the function of the currently
9012selected stack frame.
9013
9014@item -line @var{number}
9015The value specifies a line offset for the location.  The offset may either
9016be absolute (@code{-line 3}) or relative (@code{-line +3}), depending on
9017the command.  When specified without any other options, the line offset is
9018relative to the current line.
9019@end table
9020
9021Explicit location options may be abbreviated by omitting any non-unique
9022trailing characters from the option name, e.g., @w{@kbd{break -s main.c -li 3}}.
9023
9024@node Address Locations
9025@subsection Address Locations
9026@cindex address locations
9027
9028@dfn{Address locations} indicate a specific program address.  They have
9029the generalized form *@var{address}.
9030
9031For line-oriented commands, such as @code{list} and @code{edit}, this
9032specifies a source line that contains @var{address}.  For @code{break} and
9033other breakpoint-oriented commands, this can be used to set breakpoints in
9034parts of your program which do not have debugging information or
9035source files.
9036
9037Here @var{address} may be any expression valid in the current working
9038language (@pxref{Languages, working language}) that specifies a code
9039address.  In addition, as a convenience, @value{GDBN} extends the
9040semantics of expressions used in locations to cover several situations
9041that frequently occur during debugging.  Here are the various forms
9042of @var{address}:
9043
9044@table @code
9045@item @var{expression}
9046Any expression valid in the current working language.
9047
9048@item @var{funcaddr}
9049An address of a function or procedure derived from its name.  In C,
9050C@t{++}, Objective-C, Fortran, minimal, and assembly, this is
9051simply the function's name @var{function} (and actually a special case
9052of a valid expression).  In Pascal and Modula-2, this is
9053@code{&@var{function}}.  In Ada, this is @code{@var{function}'Address}
9054(although the Pascal form also works).
9055
9056This form specifies the address of the function's first instruction,
9057before the stack frame and arguments have been set up.
9058
9059@item '@var{filename}':@var{funcaddr}
9060Like @var{funcaddr} above, but also specifies the name of the source
9061file explicitly.  This is useful if the name of the function does not
9062specify the function unambiguously, e.g., if there are several
9063functions with identical names in different source files.
9064@end table
9065
9066@node Edit
9067@section Editing Source Files
9068@cindex editing source files
9069
9070@kindex edit
9071@kindex e @r{(@code{edit})}
9072To edit the lines in a source file, use the @code{edit} command.
9073The editing program of your choice
9074is invoked with the current line set to
9075the active line in the program.
9076Alternatively, there are several ways to specify what part of the file you
9077want to print if you want to see other parts of the program:
9078
9079@table @code
9080@item edit @var{location}
9081Edit the source file specified by @code{location}.  Editing starts at
9082that @var{location}, e.g., at the specified source line of the
9083specified file.  @xref{Specify Location}, for all the possible forms
9084of the @var{location} argument; here are the forms of the @code{edit}
9085command most commonly used:
9086
9087@table @code
9088@item edit @var{number}
9089Edit the current source file with @var{number} as the active line number.
9090
9091@item edit @var{function}
9092Edit the file containing @var{function} at the beginning of its definition.
9093@end table
9094
9095@end table
9096
9097@subsection Choosing your Editor
9098You can customize @value{GDBN} to use any editor you want
9099@footnote{
9100The only restriction is that your editor (say @code{ex}), recognizes the
9101following command-line syntax:
9102@smallexample
9103ex +@var{number} file
9104@end smallexample
9105The optional numeric value +@var{number} specifies the number of the line in
9106the file where to start editing.}.
9107By default, it is @file{@value{EDITOR}}, but you can change this
9108by setting the environment variable @code{EDITOR} before using
9109@value{GDBN}.  For example, to configure @value{GDBN} to use the
9110@code{vi} editor, you could use these commands with the @code{sh} shell:
9111@smallexample
9112EDITOR=/usr/bin/vi
9113export EDITOR
9114gdb @dots{}
9115@end smallexample
9116or in the @code{csh} shell,
9117@smallexample
9118setenv EDITOR /usr/bin/vi
9119gdb @dots{}
9120@end smallexample
9121
9122@node Search
9123@section Searching Source Files
9124@cindex searching source files
9125
9126There are two commands for searching through the current source file for a
9127regular expression.
9128
9129@table @code
9130@kindex search
9131@kindex forward-search
9132@kindex fo @r{(@code{forward-search})}
9133@item forward-search @var{regexp}
9134@itemx search @var{regexp}
9135The command @samp{forward-search @var{regexp}} checks each line,
9136starting with the one following the last line listed, for a match for
9137@var{regexp}.  It lists the line that is found.  You can use the
9138synonym @samp{search @var{regexp}} or abbreviate the command name as
9139@code{fo}.
9140
9141@kindex reverse-search
9142@item reverse-search @var{regexp}
9143The command @samp{reverse-search @var{regexp}} checks each line, starting
9144with the one before the last line listed and going backward, for a match
9145for @var{regexp}.  It lists the line that is found.  You can abbreviate
9146this command as @code{rev}.
9147@end table
9148
9149@node Source Path
9150@section Specifying Source Directories
9151
9152@cindex source path
9153@cindex directories for source files
9154Executable programs sometimes do not record the directories of the source
9155files from which they were compiled, just the names.  Even when they do,
9156the directories could be moved between the compilation and your debugging
9157session.  @value{GDBN} has a list of directories to search for source files;
9158this is called the @dfn{source path}.  Each time @value{GDBN} wants a source file,
9159it tries all the directories in the list, in the order they are present
9160in the list, until it finds a file with the desired name.
9161
9162For example, suppose an executable references the file
9163@file{/usr/src/foo-1.0/lib/foo.c}, does not record a compilation
9164directory, and the @dfn{source path} is @file{/mnt/cross}.
9165@value{GDBN} would look for the source file in the following
9166locations:
9167
9168@enumerate
9169
9170@item @file{/usr/src/foo-1.0/lib/foo.c}
9171@item @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c}
9172@item @file{/mnt/cross/foo.c}
9173
9174@end enumerate
9175
9176If the source file is not present at any of the above locations then
9177an error is printed.  @value{GDBN} does not look up the parts of the
9178source file name, such as @file{/mnt/cross/src/foo-1.0/lib/foo.c}.
9179Likewise, the subdirectories of the source path are not searched: if
9180the source path is @file{/mnt/cross}, and the binary refers to
9181@file{foo.c}, @value{GDBN} would not find it under
9182@file{/mnt/cross/usr/src/foo-1.0/lib}.
9183
9184Plain file names, relative file names with leading directories, file
9185names containing dots, etc.@: are all treated as described above,
9186except that non-absolute file names are not looked up literally.  If
9187the @dfn{source path} is @file{/mnt/cross}, the source file is
9188recorded as @file{../lib/foo.c}, and no compilation directory is
9189recorded, then @value{GDBN} will search in the following locations:
9190
9191@enumerate
9192
9193@item @file{/mnt/cross/../lib/foo.c}
9194@item @file{/mnt/cross/foo.c}
9195
9196@end enumerate
9197
9198@kindex cdir
9199@kindex cwd
9200@vindex $cdir@r{, convenience variable}
9201@vindex $cwd@r{, convenience variable}
9202@cindex compilation directory
9203@cindex current directory
9204@cindex working directory
9205@cindex directory, current
9206@cindex directory, compilation
9207The @dfn{source path} will always include two special entries
9208@samp{$cdir} and @samp{$cwd}, these refer to the compilation directory
9209(if one is recorded) and the current working directory respectively.
9210
9211@samp{$cdir} causes @value{GDBN} to search within the compilation
9212directory, if one is recorded in the debug information.  If no
9213compilation directory is recorded in the debug information then
9214@samp{$cdir} is ignored.
9215
9216@samp{$cwd} is not the same as @samp{.}---the former tracks the
9217current working directory as it changes during your @value{GDBN}
9218session, while the latter is immediately expanded to the current
9219directory at the time you add an entry to the source path.
9220
9221If a compilation directory is recorded in the debug information, and
9222@value{GDBN} has not found the source file after the first search
9223using @dfn{source path}, then @value{GDBN} will combine the
9224compilation directory and the filename, and then search for the source
9225file again using the @dfn{source path}.
9226
9227For example, if the executable records the source file as
9228@file{/usr/src/foo-1.0/lib/foo.c}, the compilation directory is
9229recorded as @file{/project/build}, and the @dfn{source path} is
9230@file{/mnt/cross:$cdir:$cwd} while the current working directory of
9231the @value{GDBN} session is @file{/home/user}, then @value{GDBN} will
9232search for the source file in the following locations:
9233
9234@enumerate
9235
9236@item @file{/usr/src/foo-1.0/lib/foo.c}
9237@item @file{/mnt/cross/usr/src/foo-1.0/lib/foo.c}
9238@item @file{/project/build/usr/src/foo-1.0/lib/foo.c}
9239@item @file{/home/user/usr/src/foo-1.0/lib/foo.c}
9240@item @file{/mnt/cross/project/build/usr/src/foo-1.0/lib/foo.c}
9241@item @file{/project/build/project/build/usr/src/foo-1.0/lib/foo.c}
9242@item @file{/home/user/project/build/usr/src/foo-1.0/lib/foo.c}
9243@item @file{/mnt/cross/foo.c}
9244@item @file{/project/build/foo.c}
9245@item @file{/home/user/foo.c}
9246
9247@end enumerate
9248
9249If the file name in the previous example had been recorded in the
9250executable as a relative path rather than an absolute path, then the
9251first look up would not have occurred, but all of the remaining steps
9252would be similar.
9253
9254When searching for source files on MS-DOS and MS-Windows, where
9255absolute paths start with a drive letter (e.g.
9256@file{C:/project/foo.c}), @value{GDBN} will remove the drive letter
9257from the file name before appending it to a search directory from
9258@dfn{source path}; for instance if the executable references the
9259source file @file{C:/project/foo.c} and @dfn{source path} is set to
9260@file{D:/mnt/cross}, then @value{GDBN} will search in the following
9261locations for the source file:
9262
9263@enumerate
9264
9265@item @file{C:/project/foo.c}
9266@item @file{D:/mnt/cross/project/foo.c}
9267@item @file{D:/mnt/cross/foo.c}
9268
9269@end enumerate
9270
9271Note that the executable search path is @emph{not} used to locate the
9272source files.
9273
9274Whenever you reset or rearrange the source path, @value{GDBN} clears out
9275any information it has cached about where source files are found and where
9276each line is in the file.
9277
9278@kindex directory
9279@kindex dir
9280When you start @value{GDBN}, its source path includes only @samp{$cdir}
9281and @samp{$cwd}, in that order.
9282To add other directories, use the @code{directory} command.
9283
9284The search path is used to find both program source files and @value{GDBN}
9285script files (read using the @samp{-command} option and @samp{source} command).
9286
9287In addition to the source path, @value{GDBN} provides a set of commands
9288that manage a list of source path substitution rules.  A @dfn{substitution
9289rule} specifies how to rewrite source directories stored in the program's
9290debug information in case the sources were moved to a different
9291directory between compilation and debugging.  A rule is made of
9292two strings, the first specifying what needs to be rewritten in
9293the path, and the second specifying how it should be rewritten.
9294In @ref{set substitute-path}, we name these two parts @var{from} and
9295@var{to} respectively.  @value{GDBN} does a simple string replacement
9296of @var{from} with @var{to} at the start of the directory part of the
9297source file name, and uses that result instead of the original file
9298name to look up the sources.
9299
9300Using the previous example, suppose the @file{foo-1.0} tree has been
9301moved from @file{/usr/src} to @file{/mnt/cross}, then you can tell
9302@value{GDBN} to replace @file{/usr/src} in all source path names with
9303@file{/mnt/cross}.  The first lookup will then be
9304@file{/mnt/cross/foo-1.0/lib/foo.c} in place of the original location
9305of @file{/usr/src/foo-1.0/lib/foo.c}.  To define a source path
9306substitution rule, use the @code{set substitute-path} command
9307(@pxref{set substitute-path}).
9308
9309To avoid unexpected substitution results, a rule is applied only if the
9310@var{from} part of the directory name ends at a directory separator.
9311For instance, a rule substituting  @file{/usr/source} into
9312@file{/mnt/cross} will be applied to @file{/usr/source/foo-1.0} but
9313not to @file{/usr/sourceware/foo-2.0}.  And because the substitution
9314is applied only at the beginning of the directory name, this rule will
9315not be applied to @file{/root/usr/source/baz.c} either.
9316
9317In many cases, you can achieve the same result using the @code{directory}
9318command.  However, @code{set substitute-path} can be more efficient in
9319the case where the sources are organized in a complex tree with multiple
9320subdirectories.  With the @code{directory} command, you need to add each
9321subdirectory of your project.  If you moved the entire tree while
9322preserving its internal organization, then @code{set substitute-path}
9323allows you to direct the debugger to all the sources with one single
9324command.
9325
9326@code{set substitute-path} is also more than just a shortcut command.
9327The source path is only used if the file at the original location no
9328longer exists.  On the other hand, @code{set substitute-path} modifies
9329the debugger behavior to look at the rewritten location instead.  So, if
9330for any reason a source file that is not relevant to your executable is
9331located at the original location, a substitution rule is the only
9332method available to point @value{GDBN} at the new location.
9333
9334@cindex @samp{--with-relocated-sources}
9335@cindex default source path substitution
9336You can configure a default source path substitution rule by
9337configuring @value{GDBN} with the
9338@samp{--with-relocated-sources=@var{dir}} option.  The @var{dir}
9339should be the name of a directory under @value{GDBN}'s configured
9340prefix (set with @samp{--prefix} or @samp{--exec-prefix}), and
9341directory names in debug information under @var{dir} will be adjusted
9342automatically if the installed @value{GDBN} is moved to a new
9343location.  This is useful if @value{GDBN}, libraries or executables
9344with debug information and corresponding source code are being moved
9345together.
9346
9347@table @code
9348@item directory @var{dirname} @dots{}
9349@item dir @var{dirname} @dots{}
9350Add directory @var{dirname} to the front of the source path.  Several
9351directory names may be given to this command, separated by @samp{:}
9352(@samp{;} on MS-DOS and MS-Windows, where @samp{:} usually appears as
9353part of absolute file names) or
9354whitespace.  You may specify a directory that is already in the source
9355path; this moves it forward, so @value{GDBN} searches it sooner.
9356
9357The special strings @samp{$cdir} (to refer to the compilation
9358directory, if one is recorded), and @samp{$cwd} (to refer to the
9359current working directory) can also be included in the list of
9360directories @var{dirname}.  Though these will already be in the source
9361path they will be moved forward in the list so @value{GDBN} searches
9362them sooner.
9363
9364@item directory
9365Reset the source path to its default value (@samp{$cdir:$cwd} on Unix systems).  This requires confirmation.
9366
9367@c RET-repeat for @code{directory} is explicitly disabled, but since
9368@c repeating it would be a no-op we do not say that.  (thanks to RMS)
9369
9370@item set directories @var{path-list}
9371@kindex set directories
9372Set the source path to @var{path-list}.
9373@samp{$cdir:$cwd} are added if missing.
9374
9375@item show directories
9376@kindex show directories
9377Print the source path: show which directories it contains.
9378
9379@anchor{set substitute-path}
9380@item set substitute-path @var{from} @var{to}
9381@kindex set substitute-path
9382Define a source path substitution rule, and add it at the end of the
9383current list of existing substitution rules.  If a rule with the same
9384@var{from} was already defined, then the old rule is also deleted.
9385
9386For example, if the file @file{/foo/bar/baz.c} was moved to
9387@file{/mnt/cross/baz.c}, then the command
9388
9389@smallexample
9390(@value{GDBP}) set substitute-path /foo/bar /mnt/cross
9391@end smallexample
9392
9393@noindent
9394will tell @value{GDBN} to replace @samp{/foo/bar} with
9395@samp{/mnt/cross}, which will allow @value{GDBN} to find the file
9396@file{baz.c} even though it was moved.
9397
9398In the case when more than one substitution rule have been defined,
9399the rules are evaluated one by one in the order where they have been
9400defined.  The first one matching, if any, is selected to perform
9401the substitution.
9402
9403For instance, if we had entered the following commands:
9404
9405@smallexample
9406(@value{GDBP}) set substitute-path /usr/src/include /mnt/include
9407(@value{GDBP}) set substitute-path /usr/src /mnt/src
9408@end smallexample
9409
9410@noindent
9411@value{GDBN} would then rewrite @file{/usr/src/include/defs.h} into
9412@file{/mnt/include/defs.h} by using the first rule.  However, it would
9413use the second rule to rewrite @file{/usr/src/lib/foo.c} into
9414@file{/mnt/src/lib/foo.c}.
9415
9416
9417@item unset substitute-path [path]
9418@kindex unset substitute-path
9419If a path is specified, search the current list of substitution rules
9420for a rule that would rewrite that path.  Delete that rule if found.
9421A warning is emitted by the debugger if no rule could be found.
9422
9423If no path is specified, then all substitution rules are deleted.
9424
9425@item show substitute-path [path]
9426@kindex show substitute-path
9427If a path is specified, then print the source path substitution rule
9428which would rewrite that path, if any.
9429
9430If no path is specified, then print all existing source path substitution
9431rules.
9432
9433@end table
9434
9435If your source path is cluttered with directories that are no longer of
9436interest, @value{GDBN} may sometimes cause confusion by finding the wrong
9437versions of source.  You can correct the situation as follows:
9438
9439@enumerate
9440@item
9441Use @code{directory} with no argument to reset the source path to its default value.
9442
9443@item
9444Use @code{directory} with suitable arguments to reinstall the
9445directories you want in the source path.  You can add all the
9446directories in one command.
9447@end enumerate
9448
9449@node Machine Code
9450@section Source and Machine Code
9451@cindex source line and its code address
9452
9453You can use the command @code{info line} to map source lines to program
9454addresses (and vice versa), and the command @code{disassemble} to display
9455a range of addresses as machine instructions.  You can use the command
9456@code{set disassemble-next-line} to set whether to disassemble next
9457source line when execution stops.  When run under @sc{gnu} Emacs
9458mode, the @code{info line} command causes the arrow to point to the
9459line specified.  Also, @code{info line} prints addresses in symbolic form as
9460well as hex.
9461
9462@table @code
9463@kindex info line
9464@item info line
9465@itemx info line @var{location}
9466Print the starting and ending addresses of the compiled code for
9467source line @var{location}.  You can specify source lines in any of
9468the ways documented in @ref{Specify Location}.  With no @var{location}
9469information about the current source line is printed.
9470@end table
9471
9472For example, we can use @code{info line} to discover the location of
9473the object code for the first line of function
9474@code{m4_changequote}:
9475
9476@smallexample
9477(@value{GDBP}) info line m4_changequote
9478Line 895 of "builtin.c" starts at pc 0x634c <m4_changequote> and \
9479        ends at 0x6350 <m4_changequote+4>.
9480@end smallexample
9481
9482@noindent
9483@cindex code address and its source line
9484We can also inquire (using @code{*@var{addr}} as the form for
9485@var{location}) what source line covers a particular address:
9486@smallexample
9487(@value{GDBP}) info line *0x63ff
9488Line 926 of "builtin.c" starts at pc 0x63e4 <m4_changequote+152> and \
9489        ends at 0x6404 <m4_changequote+184>.
9490@end smallexample
9491
9492@cindex @code{$_} and @code{info line}
9493@cindex @code{x} command, default address
9494@kindex x@r{(examine), and} info line
9495After @code{info line}, the default address for the @code{x} command
9496is changed to the starting address of the line, so that @samp{x/i} is
9497sufficient to begin examining the machine code (@pxref{Memory,
9498,Examining Memory}).  Also, this address is saved as the value of the
9499convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
9500Variables}).
9501
9502@cindex info line, repeated calls
9503After @code{info line}, using @code{info line} again without
9504specifying a location will display information about the next source
9505line.
9506
9507@table @code
9508@kindex disassemble
9509@cindex assembly instructions
9510@cindex instructions, assembly
9511@cindex machine instructions
9512@cindex listing machine instructions
9513@item disassemble
9514@itemx disassemble /m
9515@itemx disassemble /s
9516@itemx disassemble /r
9517This specialized command dumps a range of memory as machine
9518instructions.  It can also print mixed source+disassembly by specifying
9519the @code{/m} or @code{/s} modifier and print the raw instructions in hex
9520as well as in symbolic form by specifying the @code{/r} modifier.
9521The default memory range is the function surrounding the
9522program counter of the selected frame.  A single argument to this
9523command is a program counter value; @value{GDBN} dumps the function
9524surrounding this value.  When two arguments are given, they should
9525be separated by a comma, possibly surrounded by whitespace.  The
9526arguments specify a range of addresses to dump, in one of two forms:
9527
9528@table @code
9529@item @var{start},@var{end}
9530the addresses from @var{start} (inclusive) to @var{end} (exclusive)
9531@item @var{start},+@var{length}
9532the addresses from @var{start} (inclusive) to
9533@code{@var{start}+@var{length}} (exclusive).
9534@end table
9535
9536@noindent
9537When 2 arguments are specified, the name of the function is also
9538printed (since there could be several functions in the given range).
9539
9540The argument(s) can be any expression yielding a numeric value, such as
9541@samp{0x32c4}, @samp{&main+10} or @samp{$pc - 8}.
9542
9543If the range of memory being disassembled contains current program counter,
9544the instruction at that location is shown with a @code{=>} marker.
9545@end table
9546
9547The following example shows the disassembly of a range of addresses of
9548HP PA-RISC 2.0 code:
9549
9550@smallexample
9551(@value{GDBP}) disas 0x32c4, 0x32e4
9552Dump of assembler code from 0x32c4 to 0x32e4:
9553   0x32c4 <main+204>:      addil 0,dp
9554   0x32c8 <main+208>:      ldw 0x22c(sr0,r1),r26
9555   0x32cc <main+212>:      ldil 0x3000,r31
9556   0x32d0 <main+216>:      ble 0x3f8(sr4,r31)
9557   0x32d4 <main+220>:      ldo 0(r31),rp
9558   0x32d8 <main+224>:      addil -0x800,dp
9559   0x32dc <main+228>:      ldo 0x588(r1),r26
9560   0x32e0 <main+232>:      ldil 0x3000,r31
9561End of assembler dump.
9562@end smallexample
9563
9564Here is an example showing mixed source+assembly for Intel x86
9565with @code{/m} or @code{/s}, when the program is stopped just after
9566function prologue in a non-optimized function with no inline code.
9567
9568@smallexample
9569(@value{GDBP}) disas /m main
9570Dump of assembler code for function main:
95715       @{
9572   0x08048330 <+0>:    push   %ebp
9573   0x08048331 <+1>:    mov    %esp,%ebp
9574   0x08048333 <+3>:    sub    $0x8,%esp
9575   0x08048336 <+6>:    and    $0xfffffff0,%esp
9576   0x08048339 <+9>:    sub    $0x10,%esp
9577
95786         printf ("Hello.\n");
9579=> 0x0804833c <+12>:   movl   $0x8048440,(%esp)
9580   0x08048343 <+19>:   call   0x8048284 <puts@@plt>
9581
95827         return 0;
95838       @}
9584   0x08048348 <+24>:   mov    $0x0,%eax
9585   0x0804834d <+29>:   leave
9586   0x0804834e <+30>:   ret
9587
9588End of assembler dump.
9589@end smallexample
9590
9591The @code{/m} option is deprecated as its output is not useful when
9592there is either inlined code or re-ordered code.
9593The @code{/s} option is the preferred choice.
9594Here is an example for AMD x86-64 showing the difference between
9595@code{/m} output and @code{/s} output.
9596This example has one inline function defined in a header file,
9597and the code is compiled with @samp{-O2} optimization.
9598Note how the @code{/m} output is missing the disassembly of
9599several instructions that are present in the @code{/s} output.
9600
9601@file{foo.h}:
9602
9603@smallexample
9604int
9605foo (int a)
9606@{
9607  if (a < 0)
9608    return a * 2;
9609  if (a == 0)
9610    return 1;
9611  return a + 10;
9612@}
9613@end smallexample
9614
9615@file{foo.c}:
9616
9617@smallexample
9618#include "foo.h"
9619volatile int x, y;
9620int
9621main ()
9622@{
9623  x = foo (y);
9624  return 0;
9625@}
9626@end smallexample
9627
9628@smallexample
9629(@value{GDBP}) disas /m main
9630Dump of assembler code for function main:
96315	@{
9632
96336	  x = foo (y);
9634   0x0000000000400400 <+0>:	mov    0x200c2e(%rip),%eax # 0x601034 <y>
9635   0x0000000000400417 <+23>:	mov    %eax,0x200c13(%rip) # 0x601030 <x>
9636
96377	  return 0;
96388	@}
9639   0x000000000040041d <+29>:	xor    %eax,%eax
9640   0x000000000040041f <+31>:	retq
9641   0x0000000000400420 <+32>:	add    %eax,%eax
9642   0x0000000000400422 <+34>:	jmp    0x400417 <main+23>
9643
9644End of assembler dump.
9645(@value{GDBP}) disas /s main
9646Dump of assembler code for function main:
9647foo.c:
96485	@{
96496	  x = foo (y);
9650   0x0000000000400400 <+0>:	mov    0x200c2e(%rip),%eax # 0x601034 <y>
9651
9652foo.h:
96534	  if (a < 0)
9654   0x0000000000400406 <+6>:	test   %eax,%eax
9655   0x0000000000400408 <+8>:	js     0x400420 <main+32>
9656
96576	  if (a == 0)
96587	    return 1;
96598	  return a + 10;
9660   0x000000000040040a <+10>:	lea    0xa(%rax),%edx
9661   0x000000000040040d <+13>:	test   %eax,%eax
9662   0x000000000040040f <+15>:	mov    $0x1,%eax
9663   0x0000000000400414 <+20>:	cmovne %edx,%eax
9664
9665foo.c:
96666	  x = foo (y);
9667   0x0000000000400417 <+23>:	mov    %eax,0x200c13(%rip) # 0x601030 <x>
9668
96697	  return 0;
96708	@}
9671   0x000000000040041d <+29>:	xor    %eax,%eax
9672   0x000000000040041f <+31>:	retq
9673
9674foo.h:
96755	    return a * 2;
9676   0x0000000000400420 <+32>:	add    %eax,%eax
9677   0x0000000000400422 <+34>:	jmp    0x400417 <main+23>
9678End of assembler dump.
9679@end smallexample
9680
9681Here is another example showing raw instructions in hex for AMD x86-64,
9682
9683@smallexample
9684(gdb) disas /r 0x400281,+10
9685Dump of assembler code from 0x400281 to 0x40028b:
9686   0x0000000000400281:  38 36  cmp    %dh,(%rsi)
9687   0x0000000000400283:  2d 36 34 2e 73 sub    $0x732e3436,%eax
9688   0x0000000000400288:  6f     outsl  %ds:(%rsi),(%dx)
9689   0x0000000000400289:  2e 32 00       xor    %cs:(%rax),%al
9690End of assembler dump.
9691@end smallexample
9692
9693Addresses cannot be specified as a location (@pxref{Specify Location}).
9694So, for example, if you want to disassemble function @code{bar}
9695in file @file{foo.c}, you must type @samp{disassemble 'foo.c'::bar}
9696and not @samp{disassemble foo.c:bar}.
9697
9698Some architectures have more than one commonly-used set of instruction
9699mnemonics or other syntax.
9700
9701For programs that were dynamically linked and use shared libraries,
9702instructions that call functions or branch to locations in the shared
9703libraries might show a seemingly bogus location---it's actually a
9704location of the relocation table.  On some architectures, @value{GDBN}
9705might be able to resolve these to actual function names.
9706
9707@table @code
9708@kindex set disassembler-options
9709@cindex disassembler options
9710@item set disassembler-options @var{option1}[,@var{option2}@dots{}]
9711This command controls the passing of target specific information to
9712the disassembler.  For a list of valid options, please refer to the
9713@code{-M}/@code{--disassembler-options} section of the @samp{objdump}
9714manual and/or the output of @kbd{objdump --help}
9715(@pxref{objdump,,objdump,binutils,The GNU Binary Utilities}).
9716The default value is the empty string.
9717
9718If it is necessary to specify more than one disassembler option, then
9719multiple options can be placed together into a comma separated list.
9720Currently this command is only supported on targets ARM, MIPS, PowerPC
9721and S/390.
9722
9723@kindex show disassembler-options
9724@item show disassembler-options
9725Show the current setting of the disassembler options.
9726@end table
9727
9728@table @code
9729@kindex set disassembly-flavor
9730@cindex Intel disassembly flavor
9731@cindex AT&T disassembly flavor
9732@item set disassembly-flavor @var{instruction-set}
9733Select the instruction set to use when disassembling the
9734program via the @code{disassemble} or @code{x/i} commands.
9735
9736Currently this command is only defined for the Intel x86 family.  You
9737can set @var{instruction-set} to either @code{intel} or @code{att}.
9738The default is @code{att}, the AT&T flavor used by default by Unix
9739assemblers for x86-based targets.
9740
9741@kindex show disassembly-flavor
9742@item show disassembly-flavor
9743Show the current setting of the disassembly flavor.
9744@end table
9745
9746@table @code
9747@kindex set disassemble-next-line
9748@kindex show disassemble-next-line
9749@item set disassemble-next-line
9750@itemx show disassemble-next-line
9751Control whether or not @value{GDBN} will disassemble the next source
9752line or instruction when execution stops.  If ON, @value{GDBN} will
9753display disassembly of the next source line when execution of the
9754program being debugged stops.  This is @emph{in addition} to
9755displaying the source line itself, which @value{GDBN} always does if
9756possible.  If the next source line cannot be displayed for some reason
9757(e.g., if @value{GDBN} cannot find the source file, or there's no line
9758info in the debug info), @value{GDBN} will display disassembly of the
9759next @emph{instruction} instead of showing the next source line.  If
9760AUTO, @value{GDBN} will display disassembly of next instruction only
9761if the source line cannot be displayed.  This setting causes
9762@value{GDBN} to display some feedback when you step through a function
9763with no line info or whose source file is unavailable.  The default is
9764OFF, which means never display the disassembly of the next line or
9765instruction.
9766@end table
9767
9768
9769@node Data
9770@chapter Examining Data
9771
9772@cindex printing data
9773@cindex examining data
9774@kindex print
9775@kindex inspect
9776The usual way to examine data in your program is with the @code{print}
9777command (abbreviated @code{p}), or its synonym @code{inspect}.  It
9778evaluates and prints the value of an expression of the language your
9779program is written in (@pxref{Languages, ,Using @value{GDBN} with
9780Different Languages}).  It may also print the expression using a
9781Python-based pretty-printer (@pxref{Pretty Printing}).
9782
9783@table @code
9784@item print [[@var{options}] --] @var{expr}
9785@itemx print [[@var{options}] --] /@var{f} @var{expr}
9786@var{expr} is an expression (in the source language).  By default the
9787value of @var{expr} is printed in a format appropriate to its data type;
9788you can choose a different format by specifying @samp{/@var{f}}, where
9789@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
9790Formats}.
9791
9792@anchor{print options}
9793The @code{print} command supports a number of options that allow
9794overriding relevant global print settings as set by @code{set print}
9795subcommands:
9796
9797@table @code
9798@item -address [@code{on}|@code{off}]
9799Set printing of addresses.
9800Related setting: @ref{set print address}.
9801
9802@item -array [@code{on}|@code{off}]
9803Pretty formatting of arrays.
9804Related setting: @ref{set print array}.
9805
9806@item -array-indexes [@code{on}|@code{off}]
9807Set printing of array indexes.
9808Related setting: @ref{set print array-indexes}.
9809
9810@item -elements @var{number-of-elements}|@code{unlimited}
9811Set limit on string chars or array elements to print.  The value
9812@code{unlimited} causes there to be no limit.  Related setting:
9813@ref{set print elements}.
9814
9815@item -max-depth @var{depth}|@code{unlimited}
9816Set the threshold after which nested structures are replaced with
9817ellipsis.  Related setting: @ref{set print max-depth}.
9818
9819@item -null-stop [@code{on}|@code{off}]
9820Set printing of char arrays to stop at first null char.  Related
9821setting: @ref{set print null-stop}.
9822
9823@item -object [@code{on}|@code{off}]
9824Set printing C@t{++} virtual function tables.  Related setting:
9825@ref{set print object}.
9826
9827@item -pretty [@code{on}|@code{off}]
9828Set pretty formatting of structures.  Related setting: @ref{set print
9829pretty}.
9830
9831@item -raw-values [@code{on}|@code{off}]
9832Set whether to print values in raw form, bypassing any
9833pretty-printers for that value.  Related setting: @ref{set print
9834raw-values}.
9835
9836@item -repeats @var{number-of-repeats}|@code{unlimited}
9837Set threshold for repeated print elements.  @code{unlimited} causes
9838all elements to be individually printed.  Related setting: @ref{set
9839print repeats}.
9840
9841@item -static-members [@code{on}|@code{off}]
9842Set printing C@t{++} static members.  Related setting: @ref{set print
9843static-members}.
9844
9845@item -symbol [@code{on}|@code{off}]
9846Set printing of symbol names when printing pointers.  Related setting:
9847@ref{set print symbol}.
9848
9849@item -union [@code{on}|@code{off}]
9850Set printing of unions interior to structures.  Related setting:
9851@ref{set print union}.
9852
9853@item -vtbl [@code{on}|@code{off}]
9854Set printing of C++ virtual function tables.  Related setting:
9855@ref{set print vtbl}.
9856@end table
9857
9858Because the @code{print} command accepts arbitrary expressions which
9859may look like options (including abbreviations), if you specify any
9860command option, then you must use a double dash (@code{--}) to mark
9861the end of option processing.
9862
9863For example, this prints the value of the @code{-p} expression:
9864
9865@smallexample
9866(@value{GDBP}) print -p
9867@end smallexample
9868
9869While this repeats the last value in the value history (see below)
9870with the @code{-pretty} option in effect:
9871
9872@smallexample
9873(@value{GDBP}) print -p --
9874@end smallexample
9875
9876Here is an example including both on option and an expression:
9877
9878@smallexample
9879@group
9880(@value{GDBP}) print -pretty -- *myptr
9881$1 = @{
9882  next = 0x0,
9883  flags = @{
9884    sweet = 1,
9885    sour = 1
9886  @},
9887  meat = 0x54 "Pork"
9888@}
9889@end group
9890@end smallexample
9891
9892@item print [@var{options}]
9893@itemx print [@var{options}] /@var{f}
9894@cindex reprint the last value
9895If you omit @var{expr}, @value{GDBN} displays the last value again (from the
9896@dfn{value history}; @pxref{Value History, ,Value History}).  This allows you to
9897conveniently inspect the same value in an alternative format.
9898@end table
9899
9900A more low-level way of examining data is with the @code{x} command.
9901It examines data in memory at a specified address and prints it in a
9902specified format.  @xref{Memory, ,Examining Memory}.
9903
9904If you are interested in information about types, or about how the
9905fields of a struct or a class are declared, use the @code{ptype @var{exp}}
9906command rather than @code{print}.  @xref{Symbols, ,Examining the Symbol
9907Table}.
9908
9909@cindex exploring hierarchical data structures
9910@kindex explore
9911Another way of examining values of expressions and type information is
9912through the Python extension command @code{explore} (available only if
9913the @value{GDBN} build is configured with @code{--with-python}).  It
9914offers an interactive way to start at the highest level (or, the most
9915abstract level) of the data type of an expression (or, the data type
9916itself) and explore all the way down to leaf scalar values/fields
9917embedded in the higher level data types.
9918
9919@table @code
9920@item explore @var{arg}
9921@var{arg} is either an expression (in the source language), or a type
9922visible in the current context of the program being debugged.
9923@end table
9924
9925The working of the @code{explore} command can be illustrated with an
9926example.  If a data type @code{struct ComplexStruct} is defined in your
9927C program as
9928
9929@smallexample
9930struct SimpleStruct
9931@{
9932  int i;
9933  double d;
9934@};
9935
9936struct ComplexStruct
9937@{
9938  struct SimpleStruct *ss_p;
9939  int arr[10];
9940@};
9941@end smallexample
9942
9943@noindent
9944followed by variable declarations as
9945
9946@smallexample
9947struct SimpleStruct ss = @{ 10, 1.11 @};
9948struct ComplexStruct cs = @{ &ss, @{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 @} @};
9949@end smallexample
9950
9951@noindent
9952then, the value of the variable @code{cs} can be explored using the
9953@code{explore} command as follows.
9954
9955@smallexample
9956(gdb) explore cs
9957The value of `cs' is a struct/class of type `struct ComplexStruct' with
9958the following fields:
9959
9960  ss_p = <Enter 0 to explore this field of type `struct SimpleStruct *'>
9961   arr = <Enter 1 to explore this field of type `int [10]'>
9962
9963Enter the field number of choice:
9964@end smallexample
9965
9966@noindent
9967Since the fields of @code{cs} are not scalar values, you are being
9968prompted to chose the field you want to explore.  Let's say you choose
9969the field @code{ss_p} by entering @code{0}.  Then, since this field is a
9970pointer, you will be asked if it is pointing to a single value.  From
9971the declaration of @code{cs} above, it is indeed pointing to a single
9972value, hence you enter @code{y}.  If you enter @code{n}, then you will
9973be asked if it were pointing to an array of values, in which case this
9974field will be explored as if it were an array.
9975
9976@smallexample
9977`cs.ss_p' is a pointer to a value of type `struct SimpleStruct'
9978Continue exploring it as a pointer to a single value [y/n]: y
9979The value of `*(cs.ss_p)' is a struct/class of type `struct
9980SimpleStruct' with the following fields:
9981
9982  i = 10 .. (Value of type `int')
9983  d = 1.1100000000000001 .. (Value of type `double')
9984
9985Press enter to return to parent value:
9986@end smallexample
9987
9988@noindent
9989If the field @code{arr} of @code{cs} was chosen for exploration by
9990entering @code{1} earlier, then since it is as array, you will be
9991prompted to enter the index of the element in the array that you want
9992to explore.
9993
9994@smallexample
9995`cs.arr' is an array of `int'.
9996Enter the index of the element you want to explore in `cs.arr': 5
9997
9998`(cs.arr)[5]' is a scalar value of type `int'.
9999
10000(cs.arr)[5] = 4
10001
10002Press enter to return to parent value:
10003@end smallexample
10004
10005In general, at any stage of exploration, you can go deeper towards the
10006leaf values by responding to the prompts appropriately, or hit the
10007return key to return to the enclosing data structure (the @i{higher}
10008level data structure).
10009
10010Similar to exploring values, you can use the @code{explore} command to
10011explore types.  Instead of specifying a value (which is typically a
10012variable name or an expression valid in the current context of the
10013program being debugged), you specify a type name.  If you consider the
10014same example as above, your can explore the type
10015@code{struct ComplexStruct} by passing the argument
10016@code{struct ComplexStruct} to the @code{explore} command.
10017
10018@smallexample
10019(gdb) explore struct ComplexStruct
10020@end smallexample
10021
10022@noindent
10023By responding to the prompts appropriately in the subsequent interactive
10024session, you can explore the type @code{struct ComplexStruct} in a
10025manner similar to how the value @code{cs} was explored in the above
10026example.
10027
10028The @code{explore} command also has two sub-commands,
10029@code{explore value} and @code{explore type}. The former sub-command is
10030a way to explicitly specify that value exploration of the argument is
10031being invoked, while the latter is a way to explicitly specify that type
10032exploration of the argument is being invoked.
10033
10034@table @code
10035@item explore value @var{expr}
10036@cindex explore value
10037This sub-command of @code{explore} explores the value of the
10038expression @var{expr} (if @var{expr} is an expression valid in the
10039current context of the program being debugged).  The behavior of this
10040command is identical to that of the behavior of the @code{explore}
10041command being passed the argument @var{expr}.
10042
10043@item explore type @var{arg}
10044@cindex explore type
10045This sub-command of @code{explore} explores the type of @var{arg} (if
10046@var{arg} is a type visible in the current context of program being
10047debugged), or the type of the value/expression @var{arg} (if @var{arg}
10048is an expression valid in the current context of the program being
10049debugged).  If @var{arg} is a type, then the behavior of this command is
10050identical to that of the @code{explore} command being passed the
10051argument @var{arg}.  If @var{arg} is an expression, then the behavior of
10052this command will be identical to that of the @code{explore} command
10053being passed the type of @var{arg} as the argument.
10054@end table
10055
10056@menu
10057* Expressions::                 Expressions
10058* Ambiguous Expressions::       Ambiguous Expressions
10059* Variables::                   Program variables
10060* Arrays::                      Artificial arrays
10061* Output Formats::              Output formats
10062* Memory::                      Examining memory
10063* Auto Display::                Automatic display
10064* Print Settings::              Print settings
10065* Pretty Printing::             Python pretty printing
10066* Value History::               Value history
10067* Convenience Vars::            Convenience variables
10068* Convenience Funs::            Convenience functions
10069* Registers::                   Registers
10070* Floating Point Hardware::     Floating point hardware
10071* Vector Unit::                 Vector Unit
10072* OS Information::              Auxiliary data provided by operating system
10073* Memory Region Attributes::    Memory region attributes
10074* Dump/Restore Files::          Copy between memory and a file
10075* Core File Generation::        Cause a program dump its core
10076* Character Sets::              Debugging programs that use a different
10077                                character set than GDB does
10078* Caching Target Data::         Data caching for targets
10079* Searching Memory::            Searching memory for a sequence of bytes
10080* Value Sizes::                 Managing memory allocated for values
10081@end menu
10082
10083@node Expressions
10084@section Expressions
10085
10086@cindex expressions
10087@code{print} and many other @value{GDBN} commands accept an expression and
10088compute its value.  Any kind of constant, variable or operator defined
10089by the programming language you are using is valid in an expression in
10090@value{GDBN}.  This includes conditional expressions, function calls,
10091casts, and string constants.  It also includes preprocessor macros, if
10092you compiled your program to include this information; see
10093@ref{Compilation}.
10094
10095@cindex arrays in expressions
10096@value{GDBN} supports array constants in expressions input by
10097the user.  The syntax is @{@var{element}, @var{element}@dots{}@}.  For example,
10098you can use the command @code{print @{1, 2, 3@}} to create an array
10099of three integers.  If you pass an array to a function or assign it
10100to a program variable, @value{GDBN} copies the array to memory that
10101is @code{malloc}ed in the target program.
10102
10103Because C is so widespread, most of the expressions shown in examples in
10104this manual are in C.  @xref{Languages, , Using @value{GDBN} with Different
10105Languages}, for information on how to use expressions in other
10106languages.
10107
10108In this section, we discuss operators that you can use in @value{GDBN}
10109expressions regardless of your programming language.
10110
10111@cindex casts, in expressions
10112Casts are supported in all languages, not just in C, because it is so
10113useful to cast a number into a pointer in order to examine a structure
10114at that address in memory.
10115@c FIXME: casts supported---Mod2 true?
10116
10117@value{GDBN} supports these operators, in addition to those common
10118to programming languages:
10119
10120@table @code
10121@item @@
10122@samp{@@} is a binary operator for treating parts of memory as arrays.
10123@xref{Arrays, ,Artificial Arrays}, for more information.
10124
10125@item ::
10126@samp{::} allows you to specify a variable in terms of the file or
10127function where it is defined.  @xref{Variables, ,Program Variables}.
10128
10129@cindex @{@var{type}@}
10130@cindex type casting memory
10131@cindex memory, viewing as typed object
10132@cindex casts, to view memory
10133@item @{@var{type}@} @var{addr}
10134Refers to an object of type @var{type} stored at address @var{addr} in
10135memory.  The address @var{addr} may be any expression whose value is
10136an integer or pointer (but parentheses are required around binary
10137operators, just as in a cast).  This construct is allowed regardless
10138of what kind of data is normally supposed to reside at @var{addr}.
10139@end table
10140
10141@node Ambiguous Expressions
10142@section Ambiguous Expressions
10143@cindex ambiguous expressions
10144
10145Expressions can sometimes contain some ambiguous elements.  For instance,
10146some programming languages (notably Ada, C@t{++} and Objective-C) permit
10147a single function name to be defined several times, for application in
10148different contexts.  This is called @dfn{overloading}.  Another example
10149involving Ada is generics.  A @dfn{generic package} is similar to C@t{++}
10150templates and is typically instantiated several times, resulting in
10151the same function name being defined in different contexts.
10152
10153In some cases and depending on the language, it is possible to adjust
10154the expression to remove the ambiguity.  For instance in C@t{++}, you
10155can specify the signature of the function you want to break on, as in
10156@kbd{break @var{function}(@var{types})}.  In Ada, using the fully
10157qualified name of your function often makes the expression unambiguous
10158as well.
10159
10160When an ambiguity that needs to be resolved is detected, the debugger
10161has the capability to display a menu of numbered choices for each
10162possibility, and then waits for the selection with the prompt @samp{>}.
10163The first option is always @samp{[0] cancel}, and typing @kbd{0 @key{RET}}
10164aborts the current command.  If the command in which the expression was
10165used allows more than one choice to be selected, the next option in the
10166menu is @samp{[1] all}, and typing @kbd{1 @key{RET}} selects all possible
10167choices.
10168
10169For example, the following session excerpt shows an attempt to set a
10170breakpoint at the overloaded symbol @code{String::after}.
10171We choose three particular definitions of that function name:
10172
10173@c FIXME! This is likely to change to show arg type lists, at least
10174@smallexample
10175@group
10176(@value{GDBP}) b String::after
10177[0] cancel
10178[1] all
10179[2] file:String.cc; line number:867
10180[3] file:String.cc; line number:860
10181[4] file:String.cc; line number:875
10182[5] file:String.cc; line number:853
10183[6] file:String.cc; line number:846
10184[7] file:String.cc; line number:735
10185> 2 4 6
10186Breakpoint 1 at 0xb26c: file String.cc, line 867.
10187Breakpoint 2 at 0xb344: file String.cc, line 875.
10188Breakpoint 3 at 0xafcc: file String.cc, line 846.
10189Multiple breakpoints were set.
10190Use the "delete" command to delete unwanted
10191 breakpoints.
10192(@value{GDBP})
10193@end group
10194@end smallexample
10195
10196@table @code
10197@kindex set multiple-symbols
10198@item set multiple-symbols @var{mode}
10199@cindex multiple-symbols menu
10200
10201This option allows you to adjust the debugger behavior when an expression
10202is ambiguous.
10203
10204By default, @var{mode} is set to @code{all}.  If the command with which
10205the expression is used allows more than one choice, then @value{GDBN}
10206automatically selects all possible choices.  For instance, inserting
10207a breakpoint on a function using an ambiguous name results in a breakpoint
10208inserted on each possible match.  However, if a unique choice must be made,
10209then @value{GDBN} uses the menu to help you disambiguate the expression.
10210For instance, printing the address of an overloaded function will result
10211in the use of the menu.
10212
10213When @var{mode} is set to @code{ask}, the debugger always uses the menu
10214when an ambiguity is detected.
10215
10216Finally, when @var{mode} is set to @code{cancel}, the debugger reports
10217an error due to the ambiguity and the command is aborted.
10218
10219@kindex show multiple-symbols
10220@item show multiple-symbols
10221Show the current value of the @code{multiple-symbols} setting.
10222@end table
10223
10224@node Variables
10225@section Program Variables
10226
10227The most common kind of expression to use is the name of a variable
10228in your program.
10229
10230Variables in expressions are understood in the selected stack frame
10231(@pxref{Selection, ,Selecting a Frame}); they must be either:
10232
10233@itemize @bullet
10234@item
10235global (or file-static)
10236@end itemize
10237
10238@noindent or
10239
10240@itemize @bullet
10241@item
10242visible according to the scope rules of the
10243programming language from the point of execution in that frame
10244@end itemize
10245
10246@noindent This means that in the function
10247
10248@smallexample
10249foo (a)
10250     int a;
10251@{
10252  bar (a);
10253  @{
10254    int b = test ();
10255    bar (b);
10256  @}
10257@}
10258@end smallexample
10259
10260@noindent
10261you can examine and use the variable @code{a} whenever your program is
10262executing within the function @code{foo}, but you can only use or
10263examine the variable @code{b} while your program is executing inside
10264the block where @code{b} is declared.
10265
10266@cindex variable name conflict
10267There is an exception: you can refer to a variable or function whose
10268scope is a single source file even if the current execution point is not
10269in this file.  But it is possible to have more than one such variable or
10270function with the same name (in different source files).  If that
10271happens, referring to that name has unpredictable effects.  If you wish,
10272you can specify a static variable in a particular function or file by
10273using the colon-colon (@code{::}) notation:
10274
10275@cindex colon-colon, context for variables/functions
10276@ifnotinfo
10277@c info cannot cope with a :: index entry, but why deprive hard copy readers?
10278@cindex @code{::}, context for variables/functions
10279@end ifnotinfo
10280@smallexample
10281@var{file}::@var{variable}
10282@var{function}::@var{variable}
10283@end smallexample
10284
10285@noindent
10286Here @var{file} or @var{function} is the name of the context for the
10287static @var{variable}.  In the case of file names, you can use quotes to
10288make sure @value{GDBN} parses the file name as a single word---for example,
10289to print a global value of @code{x} defined in @file{f2.c}:
10290
10291@smallexample
10292(@value{GDBP}) p 'f2.c'::x
10293@end smallexample
10294
10295The @code{::} notation is normally used for referring to
10296static variables, since you typically disambiguate uses of local variables
10297in functions by selecting the appropriate frame and using the
10298simple name of the variable.  However, you may also use this notation
10299to refer to local variables in frames enclosing the selected frame:
10300
10301@smallexample
10302void
10303foo (int a)
10304@{
10305  if (a < 10)
10306    bar (a);
10307  else
10308    process (a);    /* Stop here */
10309@}
10310
10311int
10312bar (int a)
10313@{
10314  foo (a + 5);
10315@}
10316@end smallexample
10317
10318@noindent
10319For example, if there is a breakpoint at the commented line,
10320here is what you might see
10321when the program stops after executing the call @code{bar(0)}:
10322
10323@smallexample
10324(@value{GDBP}) p a
10325$1 = 10
10326(@value{GDBP}) p bar::a
10327$2 = 5
10328(@value{GDBP}) up 2
10329#2  0x080483d0 in foo (a=5) at foobar.c:12
10330(@value{GDBP}) p a
10331$3 = 5
10332(@value{GDBP}) p bar::a
10333$4 = 0
10334@end smallexample
10335
10336@cindex C@t{++} scope resolution
10337These uses of @samp{::} are very rarely in conflict with the very
10338similar use of the same notation in C@t{++}.  When they are in
10339conflict, the C@t{++} meaning takes precedence; however, this can be
10340overridden by quoting the file or function name with single quotes.
10341
10342For example, suppose the program is stopped in a method of a class
10343that has a field named @code{includefile}, and there is also an
10344include file named @file{includefile} that defines a variable,
10345@code{some_global}.
10346
10347@smallexample
10348(@value{GDBP}) p includefile
10349$1 = 23
10350(@value{GDBP}) p includefile::some_global
10351A syntax error in expression, near `'.
10352(@value{GDBP}) p 'includefile'::some_global
10353$2 = 27
10354@end smallexample
10355
10356@cindex wrong values
10357@cindex variable values, wrong
10358@cindex function entry/exit, wrong values of variables
10359@cindex optimized code, wrong values of variables
10360@quotation
10361@emph{Warning:} Occasionally, a local variable may appear to have the
10362wrong value at certain points in a function---just after entry to a new
10363scope, and just before exit.
10364@end quotation
10365You may see this problem when you are stepping by machine instructions.
10366This is because, on most machines, it takes more than one instruction to
10367set up a stack frame (including local variable definitions); if you are
10368stepping by machine instructions, variables may appear to have the wrong
10369values until the stack frame is completely built.  On exit, it usually
10370also takes more than one machine instruction to destroy a stack frame;
10371after you begin stepping through that group of instructions, local
10372variable definitions may be gone.
10373
10374This may also happen when the compiler does significant optimizations.
10375To be sure of always seeing accurate values, turn off all optimization
10376when compiling.
10377
10378@cindex ``No symbol "foo" in current context''
10379Another possible effect of compiler optimizations is to optimize
10380unused variables out of existence, or assign variables to registers (as
10381opposed to memory addresses).  Depending on the support for such cases
10382offered by the debug info format used by the compiler, @value{GDBN}
10383might not be able to display values for such local variables.  If that
10384happens, @value{GDBN} will print a message like this:
10385
10386@smallexample
10387No symbol "foo" in current context.
10388@end smallexample
10389
10390To solve such problems, either recompile without optimizations, or use a
10391different debug info format, if the compiler supports several such
10392formats.  @xref{Compilation}, for more information on choosing compiler
10393options.  @xref{C, ,C and C@t{++}}, for more information about debug
10394info formats that are best suited to C@t{++} programs.
10395
10396If you ask to print an object whose contents are unknown to
10397@value{GDBN}, e.g., because its data type is not completely specified
10398by the debug information, @value{GDBN} will say @samp{<incomplete
10399type>}.  @xref{Symbols, incomplete type}, for more about this.
10400
10401@cindex no debug info variables
10402If you try to examine or use the value of a (global) variable for
10403which @value{GDBN} has no type information, e.g., because the program
10404includes no debug information, @value{GDBN} displays an error message.
10405@xref{Symbols, unknown type}, for more about unknown types.  If you
10406cast the variable to its declared type, @value{GDBN} gets the
10407variable's value using the cast-to type as the variable's type.  For
10408example, in a C program:
10409
10410@smallexample
10411  (@value{GDBP}) p var
10412  'var' has unknown type; cast it to its declared type
10413  (@value{GDBP}) p (float) var
10414  $1 = 3.14
10415@end smallexample
10416
10417If you append @kbd{@@entry} string to a function parameter name you get its
10418value at the time the function got called.  If the value is not available an
10419error message is printed.  Entry values are available only with some compilers.
10420Entry values are normally also printed at the function parameter list according
10421to @ref{set print entry-values}.
10422
10423@smallexample
10424Breakpoint 1, d (i=30) at gdb.base/entry-value.c:29
1042529	  i++;
10426(gdb) next
1042730	  e (i);
10428(gdb) print i
10429$1 = 31
10430(gdb) print i@@entry
10431$2 = 30
10432@end smallexample
10433
10434Strings are identified as arrays of @code{char} values without specified
10435signedness.  Arrays of either @code{signed char} or @code{unsigned char} get
10436printed as arrays of 1 byte sized integers.  @code{-fsigned-char} or
10437@code{-funsigned-char} @value{NGCC} options have no effect as @value{GDBN}
10438defines literal string type @code{"char"} as @code{char} without a sign.
10439For program code
10440
10441@smallexample
10442char var0[] = "A";
10443signed char var1[] = "A";
10444@end smallexample
10445
10446You get during debugging
10447@smallexample
10448(gdb) print var0
10449$1 = "A"
10450(gdb) print var1
10451$2 = @{65 'A', 0 '\0'@}
10452@end smallexample
10453
10454@node Arrays
10455@section Artificial Arrays
10456
10457@cindex artificial array
10458@cindex arrays
10459@kindex @@@r{, referencing memory as an array}
10460It is often useful to print out several successive objects of the
10461same type in memory; a section of an array, or an array of
10462dynamically determined size for which only a pointer exists in the
10463program.
10464
10465You can do this by referring to a contiguous span of memory as an
10466@dfn{artificial array}, using the binary operator @samp{@@}.  The left
10467operand of @samp{@@} should be the first element of the desired array
10468and be an individual object.  The right operand should be the desired length
10469of the array.  The result is an array value whose elements are all of
10470the type of the left argument.  The first element is actually the left
10471argument; the second element comes from bytes of memory immediately
10472following those that hold the first element, and so on.  Here is an
10473example.  If a program says
10474
10475@smallexample
10476int *array = (int *) malloc (len * sizeof (int));
10477@end smallexample
10478
10479@noindent
10480you can print the contents of @code{array} with
10481
10482@smallexample
10483p *array@@len
10484@end smallexample
10485
10486The left operand of @samp{@@} must reside in memory.  Array values made
10487with @samp{@@} in this way behave just like other arrays in terms of
10488subscripting, and are coerced to pointers when used in expressions.
10489Artificial arrays most often appear in expressions via the value history
10490(@pxref{Value History, ,Value History}), after printing one out.
10491
10492Another way to create an artificial array is to use a cast.
10493This re-interprets a value as if it were an array.
10494The value need not be in memory:
10495@smallexample
10496(@value{GDBP}) p/x (short[2])0x12345678
10497$1 = @{0x1234, 0x5678@}
10498@end smallexample
10499
10500As a convenience, if you leave the array length out (as in
10501@samp{(@var{type}[])@var{value}}) @value{GDBN} calculates the size to fill
10502the value (as @samp{sizeof(@var{value})/sizeof(@var{type})}:
10503@smallexample
10504(@value{GDBP}) p/x (short[])0x12345678
10505$2 = @{0x1234, 0x5678@}
10506@end smallexample
10507
10508Sometimes the artificial array mechanism is not quite enough; in
10509moderately complex data structures, the elements of interest may not
10510actually be adjacent---for example, if you are interested in the values
10511of pointers in an array.  One useful work-around in this situation is
10512to use a convenience variable (@pxref{Convenience Vars, ,Convenience
10513Variables}) as a counter in an expression that prints the first
10514interesting value, and then repeat that expression via @key{RET}.  For
10515instance, suppose you have an array @code{dtab} of pointers to
10516structures, and you are interested in the values of a field @code{fv}
10517in each structure.  Here is an example of what you might type:
10518
10519@smallexample
10520set $i = 0
10521p dtab[$i++]->fv
10522@key{RET}
10523@key{RET}
10524@dots{}
10525@end smallexample
10526
10527@node Output Formats
10528@section Output Formats
10529
10530@cindex formatted output
10531@cindex output formats
10532By default, @value{GDBN} prints a value according to its data type.  Sometimes
10533this is not what you want.  For example, you might want to print a number
10534in hex, or a pointer in decimal.  Or you might want to view data in memory
10535at a certain address as a character string or as an instruction.  To do
10536these things, specify an @dfn{output format} when you print a value.
10537
10538The simplest use of output formats is to say how to print a value
10539already computed.  This is done by starting the arguments of the
10540@code{print} command with a slash and a format letter.  The format
10541letters supported are:
10542
10543@table @code
10544@item x
10545Regard the bits of the value as an integer, and print the integer in
10546hexadecimal.
10547
10548@item d
10549Print as integer in signed decimal.
10550
10551@item u
10552Print as integer in unsigned decimal.
10553
10554@item o
10555Print as integer in octal.
10556
10557@item t
10558Print as integer in binary.  The letter @samp{t} stands for ``two''.
10559@footnote{@samp{b} cannot be used because these format letters are also
10560used with the @code{x} command, where @samp{b} stands for ``byte'';
10561see @ref{Memory,,Examining Memory}.}
10562
10563@item a
10564@cindex unknown address, locating
10565@cindex locate address
10566Print as an address, both absolute in hexadecimal and as an offset from
10567the nearest preceding symbol.  You can use this format used to discover
10568where (in what function) an unknown address is located:
10569
10570@smallexample
10571(@value{GDBP}) p/a 0x54320
10572$3 = 0x54320 <_initialize_vx+396>
10573@end smallexample
10574
10575@noindent
10576The command @code{info symbol 0x54320} yields similar results.
10577@xref{Symbols, info symbol}.
10578
10579@item c
10580Regard as an integer and print it as a character constant.  This
10581prints both the numerical value and its character representation.  The
10582character representation is replaced with the octal escape @samp{\nnn}
10583for characters outside the 7-bit @sc{ascii} range.
10584
10585Without this format, @value{GDBN} displays @code{char},
10586@w{@code{unsigned char}}, and @w{@code{signed char}} data as character
10587constants.  Single-byte members of vectors are displayed as integer
10588data.
10589
10590@item f
10591Regard the bits of the value as a floating point number and print
10592using typical floating point syntax.
10593
10594@item s
10595@cindex printing strings
10596@cindex printing byte arrays
10597Regard as a string, if possible.  With this format, pointers to single-byte
10598data are displayed as null-terminated strings and arrays of single-byte data
10599are displayed as fixed-length strings.  Other values are displayed in their
10600natural types.
10601
10602Without this format, @value{GDBN} displays pointers to and arrays of
10603@code{char}, @w{@code{unsigned char}}, and @w{@code{signed char}} as
10604strings.  Single-byte members of a vector are displayed as an integer
10605array.
10606
10607@item z
10608Like @samp{x} formatting, the value is treated as an integer and
10609printed as hexadecimal, but leading zeros are printed to pad the value
10610to the size of the integer type.
10611
10612@item r
10613@cindex raw printing
10614Print using the @samp{raw} formatting.  By default, @value{GDBN} will
10615use a Python-based pretty-printer, if one is available (@pxref{Pretty
10616Printing}).  This typically results in a higher-level display of the
10617value's contents.  The @samp{r} format bypasses any Python
10618pretty-printer which might exist.
10619@end table
10620
10621For example, to print the program counter in hex (@pxref{Registers}), type
10622
10623@smallexample
10624p/x $pc
10625@end smallexample
10626
10627@noindent
10628Note that no space is required before the slash; this is because command
10629names in @value{GDBN} cannot contain a slash.
10630
10631To reprint the last value in the value history with a different format,
10632you can use the @code{print} command with just a format and no
10633expression.  For example, @samp{p/x} reprints the last value in hex.
10634
10635@node Memory
10636@section Examining Memory
10637
10638You can use the command @code{x} (for ``examine'') to examine memory in
10639any of several formats, independently of your program's data types.
10640
10641@cindex examining memory
10642@table @code
10643@kindex x @r{(examine memory)}
10644@item x/@var{nfu} @var{addr}
10645@itemx x @var{addr}
10646@itemx x
10647Use the @code{x} command to examine memory.
10648@end table
10649
10650@var{n}, @var{f}, and @var{u} are all optional parameters that specify how
10651much memory to display and how to format it; @var{addr} is an
10652expression giving the address where you want to start displaying memory.
10653If you use defaults for @var{nfu}, you need not type the slash @samp{/}.
10654Several commands set convenient defaults for @var{addr}.
10655
10656@table @r
10657@item @var{n}, the repeat count
10658The repeat count is a decimal integer; the default is 1.  It specifies
10659how much memory (counting by units @var{u}) to display.  If a negative
10660number is specified, memory is examined backward from @var{addr}.
10661@c This really is **decimal**; unaffected by 'set radix' as of GDB
10662@c 4.1.2.
10663
10664@item @var{f}, the display format
10665The display format is one of the formats used by @code{print}
10666(@samp{x}, @samp{d}, @samp{u}, @samp{o}, @samp{t}, @samp{a}, @samp{c},
10667@samp{f}, @samp{s}), and in addition @samp{i} (for machine instructions).
10668The default is @samp{x} (hexadecimal) initially.  The default changes
10669each time you use either @code{x} or @code{print}.
10670
10671@item @var{u}, the unit size
10672The unit size is any of
10673
10674@table @code
10675@item b
10676Bytes.
10677@item h
10678Halfwords (two bytes).
10679@item w
10680Words (four bytes).  This is the initial default.
10681@item g
10682Giant words (eight bytes).
10683@end table
10684
10685Each time you specify a unit size with @code{x}, that size becomes the
10686default unit the next time you use @code{x}.  For the @samp{i} format,
10687the unit size is ignored and is normally not written.  For the @samp{s} format,
10688the unit size defaults to @samp{b}, unless it is explicitly given.
10689Use @kbd{x /hs} to display 16-bit char strings and @kbd{x /ws} to display
1069032-bit strings.  The next use of @kbd{x /s} will again display 8-bit strings.
10691Note that the results depend on the programming language of the
10692current compilation unit.  If the language is C, the @samp{s}
10693modifier will use the UTF-16 encoding while @samp{w} will use
10694UTF-32.  The encoding is set by the programming language and cannot
10695be altered.
10696
10697@item @var{addr}, starting display address
10698@var{addr} is the address where you want @value{GDBN} to begin displaying
10699memory.  The expression need not have a pointer value (though it may);
10700it is always interpreted as an integer address of a byte of memory.
10701@xref{Expressions, ,Expressions}, for more information on expressions.  The default for
10702@var{addr} is usually just after the last address examined---but several
10703other commands also set the default address: @code{info breakpoints} (to
10704the address of the last breakpoint listed), @code{info line} (to the
10705starting address of a line), and @code{print} (if you use it to display
10706a value from memory).
10707@end table
10708
10709For example, @samp{x/3uh 0x54320} is a request to display three halfwords
10710(@code{h}) of memory, formatted as unsigned decimal integers (@samp{u}),
10711starting at address @code{0x54320}.  @samp{x/4xw $sp} prints the four
10712words (@samp{w}) of memory above the stack pointer (here, @samp{$sp};
10713@pxref{Registers, ,Registers}) in hexadecimal (@samp{x}).
10714
10715You can also specify a negative repeat count to examine memory backward
10716from the given address.  For example, @samp{x/-3uh 0x54320} prints three
10717halfwords (@code{h}) at @code{0x54314}, @code{0x54328}, and @code{0x5431c}.
10718
10719Since the letters indicating unit sizes are all distinct from the
10720letters specifying output formats, you do not have to remember whether
10721unit size or format comes first; either order works.  The output
10722specifications @samp{4xw} and @samp{4wx} mean exactly the same thing.
10723(However, the count @var{n} must come first; @samp{wx4} does not work.)
10724
10725Even though the unit size @var{u} is ignored for the formats @samp{s}
10726and @samp{i}, you might still want to use a count @var{n}; for example,
10727@samp{3i} specifies that you want to see three machine instructions,
10728including any operands.  For convenience, especially when used with
10729the @code{display} command, the @samp{i} format also prints branch delay
10730slot instructions, if any, beyond the count specified, which immediately
10731follow the last instruction that is within the count.  The command
10732@code{disassemble} gives an alternative way of inspecting machine
10733instructions; see @ref{Machine Code,,Source and Machine Code}.
10734
10735If a negative repeat count is specified for the formats @samp{s} or @samp{i},
10736the command displays null-terminated strings or instructions before the given
10737address as many as the absolute value of the given number.  For the @samp{i}
10738format, we use line number information in the debug info to accurately locate
10739instruction boundaries while disassembling backward.  If line info is not
10740available, the command stops examining memory with an error message.
10741
10742All the defaults for the arguments to @code{x} are designed to make it
10743easy to continue scanning memory with minimal specifications each time
10744you use @code{x}.  For example, after you have inspected three machine
10745instructions with @samp{x/3i @var{addr}}, you can inspect the next seven
10746with just @samp{x/7}.  If you use @key{RET} to repeat the @code{x} command,
10747the repeat count @var{n} is used again; the other arguments default as
10748for successive uses of @code{x}.
10749
10750When examining machine instructions, the instruction at current program
10751counter is shown with a @code{=>} marker. For example:
10752
10753@smallexample
10754(@value{GDBP}) x/5i $pc-6
10755   0x804837f <main+11>: mov    %esp,%ebp
10756   0x8048381 <main+13>: push   %ecx
10757   0x8048382 <main+14>: sub    $0x4,%esp
10758=> 0x8048385 <main+17>: movl   $0x8048460,(%esp)
10759   0x804838c <main+24>: call   0x80482d4 <puts@@plt>
10760@end smallexample
10761
10762@cindex @code{$_}, @code{$__}, and value history
10763The addresses and contents printed by the @code{x} command are not saved
10764in the value history because there is often too much of them and they
10765would get in the way.  Instead, @value{GDBN} makes these values available for
10766subsequent use in expressions as values of the convenience variables
10767@code{$_} and @code{$__}.  After an @code{x} command, the last address
10768examined is available for use in expressions in the convenience variable
10769@code{$_}.  The contents of that address, as examined, are available in
10770the convenience variable @code{$__}.
10771
10772If the @code{x} command has a repeat count, the address and contents saved
10773are from the last memory unit printed; this is not the same as the last
10774address printed if several units were printed on the last line of output.
10775
10776@anchor{addressable memory unit}
10777@cindex addressable memory unit
10778Most targets have an addressable memory unit size of 8 bits.  This means
10779that to each memory address are associated 8 bits of data.  Some
10780targets, however, have other addressable memory unit sizes.
10781Within @value{GDBN} and this document, the term
10782@dfn{addressable memory unit} (or @dfn{memory unit} for short) is used
10783when explicitly referring to a chunk of data of that size.  The word
10784@dfn{byte} is used to refer to a chunk of data of 8 bits, regardless of
10785the addressable memory unit size of the target.  For most systems,
10786addressable memory unit is a synonym of byte.
10787
10788@cindex remote memory comparison
10789@cindex target memory comparison
10790@cindex verify remote memory image
10791@cindex verify target memory image
10792When you are debugging a program running on a remote target machine
10793(@pxref{Remote Debugging}), you may wish to verify the program's image
10794in the remote machine's memory against the executable file you
10795downloaded to the target.  Or, on any target, you may want to check
10796whether the program has corrupted its own read-only sections.  The
10797@code{compare-sections} command is provided for such situations.
10798
10799@table @code
10800@kindex compare-sections
10801@item compare-sections @r{[}@var{section-name}@r{|}@code{-r}@r{]}
10802Compare the data of a loadable section @var{section-name} in the
10803executable file of the program being debugged with the same section in
10804the target machine's memory, and report any mismatches.  With no
10805arguments, compares all loadable sections.  With an argument of
10806@code{-r}, compares all loadable read-only sections.
10807
10808Note: for remote targets, this command can be accelerated if the
10809target supports computing the CRC checksum of a block of memory
10810(@pxref{qCRC packet}).
10811@end table
10812
10813@node Auto Display
10814@section Automatic Display
10815@cindex automatic display
10816@cindex display of expressions
10817
10818If you find that you want to print the value of an expression frequently
10819(to see how it changes), you might want to add it to the @dfn{automatic
10820display list} so that @value{GDBN} prints its value each time your program stops.
10821Each expression added to the list is given a number to identify it;
10822to remove an expression from the list, you specify that number.
10823The automatic display looks like this:
10824
10825@smallexample
108262: foo = 38
108273: bar[5] = (struct hack *) 0x3804
10828@end smallexample
10829
10830@noindent
10831This display shows item numbers, expressions and their current values.  As with
10832displays you request manually using @code{x} or @code{print}, you can
10833specify the output format you prefer; in fact, @code{display} decides
10834whether to use @code{print} or @code{x} depending your format
10835specification---it uses @code{x} if you specify either the @samp{i}
10836or @samp{s} format, or a unit size; otherwise it uses @code{print}.
10837
10838@table @code
10839@kindex display
10840@item display @var{expr}
10841Add the expression @var{expr} to the list of expressions to display
10842each time your program stops.  @xref{Expressions, ,Expressions}.
10843
10844@code{display} does not repeat if you press @key{RET} again after using it.
10845
10846@item display/@var{fmt} @var{expr}
10847For @var{fmt} specifying only a display format and not a size or
10848count, add the expression @var{expr} to the auto-display list but
10849arrange to display it each time in the specified format @var{fmt}.
10850@xref{Output Formats,,Output Formats}.
10851
10852@item display/@var{fmt} @var{addr}
10853For @var{fmt} @samp{i} or @samp{s}, or including a unit-size or a
10854number of units, add the expression @var{addr} as a memory address to
10855be examined each time your program stops.  Examining means in effect
10856doing @samp{x/@var{fmt} @var{addr}}.  @xref{Memory, ,Examining Memory}.
10857@end table
10858
10859For example, @samp{display/i $pc} can be helpful, to see the machine
10860instruction about to be executed each time execution stops (@samp{$pc}
10861is a common name for the program counter; @pxref{Registers, ,Registers}).
10862
10863@table @code
10864@kindex delete display
10865@kindex undisplay
10866@item undisplay @var{dnums}@dots{}
10867@itemx delete display @var{dnums}@dots{}
10868Remove items from the list of expressions to display.  Specify the
10869numbers of the displays that you want affected with the command
10870argument @var{dnums}.  It can be a single display number, one of the
10871numbers shown in the first field of the @samp{info display} display;
10872or it could be a range of display numbers, as in @code{2-4}.
10873
10874@code{undisplay} does not repeat if you press @key{RET} after using it.
10875(Otherwise you would just get the error @samp{No display number @dots{}}.)
10876
10877@kindex disable display
10878@item disable display @var{dnums}@dots{}
10879Disable the display of item numbers @var{dnums}.  A disabled display
10880item is not printed automatically, but is not forgotten.  It may be
10881enabled again later.  Specify the numbers of the displays that you
10882want affected with the command argument @var{dnums}.  It can be a
10883single display number, one of the numbers shown in the first field of
10884the @samp{info display} display; or it could be a range of display
10885numbers, as in @code{2-4}.
10886
10887@kindex enable display
10888@item enable display @var{dnums}@dots{}
10889Enable display of item numbers @var{dnums}.  It becomes effective once
10890again in auto display of its expression, until you specify otherwise.
10891Specify the numbers of the displays that you want affected with the
10892command argument @var{dnums}.  It can be a single display number, one
10893of the numbers shown in the first field of the @samp{info display}
10894display; or it could be a range of display numbers, as in @code{2-4}.
10895
10896@item display
10897Display the current values of the expressions on the list, just as is
10898done when your program stops.
10899
10900@kindex info display
10901@item info display
10902Print the list of expressions previously set up to display
10903automatically, each one with its item number, but without showing the
10904values.  This includes disabled expressions, which are marked as such.
10905It also includes expressions which would not be displayed right now
10906because they refer to automatic variables not currently available.
10907@end table
10908
10909@cindex display disabled out of scope
10910If a display expression refers to local variables, then it does not make
10911sense outside the lexical context for which it was set up.  Such an
10912expression is disabled when execution enters a context where one of its
10913variables is not defined.  For example, if you give the command
10914@code{display last_char} while inside a function with an argument
10915@code{last_char}, @value{GDBN} displays this argument while your program
10916continues to stop inside that function.  When it stops elsewhere---where
10917there is no variable @code{last_char}---the display is disabled
10918automatically.  The next time your program stops where @code{last_char}
10919is meaningful, you can enable the display expression once again.
10920
10921@node Print Settings
10922@section Print Settings
10923
10924@cindex format options
10925@cindex print settings
10926@value{GDBN} provides the following ways to control how arrays, structures,
10927and symbols are printed.
10928
10929@noindent
10930These settings are useful for debugging programs in any language:
10931
10932@table @code
10933@kindex set print
10934@anchor{set print address}
10935@item set print address
10936@itemx set print address on
10937@cindex print/don't print memory addresses
10938@value{GDBN} prints memory addresses showing the location of stack
10939traces, structure values, pointer values, breakpoints, and so forth,
10940even when it also displays the contents of those addresses.  The default
10941is @code{on}.  For example, this is what a stack frame display looks like with
10942@code{set print address on}:
10943
10944@smallexample
10945@group
10946(@value{GDBP}) f
10947#0  set_quotes (lq=0x34c78 "<<", rq=0x34c88 ">>")
10948    at input.c:530
10949530         if (lquote != def_lquote)
10950@end group
10951@end smallexample
10952
10953@item set print address off
10954Do not print addresses when displaying their contents.  For example,
10955this is the same stack frame displayed with @code{set print address off}:
10956
10957@smallexample
10958@group
10959(@value{GDBP}) set print addr off
10960(@value{GDBP}) f
10961#0  set_quotes (lq="<<", rq=">>") at input.c:530
10962530         if (lquote != def_lquote)
10963@end group
10964@end smallexample
10965
10966You can use @samp{set print address off} to eliminate all machine
10967dependent displays from the @value{GDBN} interface.  For example, with
10968@code{print address off}, you should get the same text for backtraces on
10969all machines---whether or not they involve pointer arguments.
10970
10971@kindex show print
10972@item show print address
10973Show whether or not addresses are to be printed.
10974@end table
10975
10976When @value{GDBN} prints a symbolic address, it normally prints the
10977closest earlier symbol plus an offset.  If that symbol does not uniquely
10978identify the address (for example, it is a name whose scope is a single
10979source file), you may need to clarify.  One way to do this is with
10980@code{info line}, for example @samp{info line *0x4537}.  Alternately,
10981you can set @value{GDBN} to print the source file and line number when
10982it prints a symbolic address:
10983
10984@table @code
10985@item set print symbol-filename on
10986@cindex source file and line of a symbol
10987@cindex symbol, source file and line
10988Tell @value{GDBN} to print the source file name and line number of a
10989symbol in the symbolic form of an address.
10990
10991@item set print symbol-filename off
10992Do not print source file name and line number of a symbol.  This is the
10993default.
10994
10995@item show print symbol-filename
10996Show whether or not @value{GDBN} will print the source file name and
10997line number of a symbol in the symbolic form of an address.
10998@end table
10999
11000Another situation where it is helpful to show symbol filenames and line
11001numbers is when disassembling code; @value{GDBN} shows you the line
11002number and source file that corresponds to each instruction.
11003
11004Also, you may wish to see the symbolic form only if the address being
11005printed is reasonably close to the closest earlier symbol:
11006
11007@table @code
11008@item set print max-symbolic-offset @var{max-offset}
11009@itemx set print max-symbolic-offset unlimited
11010@cindex maximum value for offset of closest symbol
11011Tell @value{GDBN} to only display the symbolic form of an address if the
11012offset between the closest earlier symbol and the address is less than
11013@var{max-offset}.  The default is @code{unlimited}, which tells @value{GDBN}
11014to always print the symbolic form of an address if any symbol precedes
11015it.  Zero is equivalent to @code{unlimited}.
11016
11017@item show print max-symbolic-offset
11018Ask how large the maximum offset is that @value{GDBN} prints in a
11019symbolic address.
11020@end table
11021
11022@cindex wild pointer, interpreting
11023@cindex pointer, finding referent
11024If you have a pointer and you are not sure where it points, try
11025@samp{set print symbol-filename on}.  Then you can determine the name
11026and source file location of the variable where it points, using
11027@samp{p/a @var{pointer}}.  This interprets the address in symbolic form.
11028For example, here @value{GDBN} shows that a variable @code{ptt} points
11029at another variable @code{t}, defined in @file{hi2.c}:
11030
11031@smallexample
11032(@value{GDBP}) set print symbol-filename on
11033(@value{GDBP}) p/a ptt
11034$4 = 0xe008 <t in hi2.c>
11035@end smallexample
11036
11037@quotation
11038@emph{Warning:} For pointers that point to a local variable, @samp{p/a}
11039does not show the symbol name and filename of the referent, even with
11040the appropriate @code{set print} options turned on.
11041@end quotation
11042
11043You can also enable @samp{/a}-like formatting all the time using
11044@samp{set print symbol on}:
11045
11046@anchor{set print symbol}
11047@table @code
11048@item set print symbol on
11049Tell @value{GDBN} to print the symbol corresponding to an address, if
11050one exists.
11051
11052@item set print symbol off
11053Tell @value{GDBN} not to print the symbol corresponding to an
11054address.  In this mode, @value{GDBN} will still print the symbol
11055corresponding to pointers to functions.  This is the default.
11056
11057@item show print symbol
11058Show whether @value{GDBN} will display the symbol corresponding to an
11059address.
11060@end table
11061
11062Other settings control how different kinds of objects are printed:
11063
11064@table @code
11065@anchor{set print array}
11066@item set print array
11067@itemx set print array on
11068@cindex pretty print arrays
11069Pretty print arrays.  This format is more convenient to read,
11070but uses more space.  The default is off.
11071
11072@item set print array off
11073Return to compressed format for arrays.
11074
11075@item show print array
11076Show whether compressed or pretty format is selected for displaying
11077arrays.
11078
11079@cindex print array indexes
11080@anchor{set print array-indexes}
11081@item set print array-indexes
11082@itemx set print array-indexes on
11083Print the index of each element when displaying arrays.  May be more
11084convenient to locate a given element in the array or quickly find the
11085index of a given element in that printed array.  The default is off.
11086
11087@item set print array-indexes off
11088Stop printing element indexes when displaying arrays.
11089
11090@item show print array-indexes
11091Show whether the index of each element is printed when displaying
11092arrays.
11093
11094@anchor{set print elements}
11095@item set print elements @var{number-of-elements}
11096@itemx set print elements unlimited
11097@cindex number of array elements to print
11098@cindex limit on number of printed array elements
11099Set a limit on how many elements of an array @value{GDBN} will print.
11100If @value{GDBN} is printing a large array, it stops printing after it has
11101printed the number of elements set by the @code{set print elements} command.
11102This limit also applies to the display of strings.
11103When @value{GDBN} starts, this limit is set to 200.
11104Setting @var{number-of-elements} to @code{unlimited} or zero means
11105that the number of elements to print is unlimited.
11106
11107@item show print elements
11108Display the number of elements of a large array that @value{GDBN} will print.
11109If the number is 0, then the printing is unlimited.
11110
11111@anchor{set print frame-arguments}
11112@item set print frame-arguments @var{value}
11113@kindex set print frame-arguments
11114@cindex printing frame argument values
11115@cindex print all frame argument values
11116@cindex print frame argument values for scalars only
11117@cindex do not print frame arguments
11118This command allows to control how the values of arguments are printed
11119when the debugger prints a frame (@pxref{Frames}).  The possible
11120values are:
11121
11122@table @code
11123@item all
11124The values of all arguments are printed.
11125
11126@item scalars
11127Print the value of an argument only if it is a scalar.  The value of more
11128complex arguments such as arrays, structures, unions, etc, is replaced
11129by @code{@dots{}}.  This is the default.  Here is an example where
11130only scalar arguments are shown:
11131
11132@smallexample
11133#1  0x08048361 in call_me (i=3, s=@dots{}, ss=0xbf8d508c, u=@dots{}, e=green)
11134  at frame-args.c:23
11135@end smallexample
11136
11137@item none
11138None of the argument values are printed.  Instead, the value of each argument
11139is replaced by @code{@dots{}}.  In this case, the example above now becomes:
11140
11141@smallexample
11142#1  0x08048361 in call_me (i=@dots{}, s=@dots{}, ss=@dots{}, u=@dots{}, e=@dots{})
11143  at frame-args.c:23
11144@end smallexample
11145
11146@item presence
11147Only the presence of arguments is indicated by @code{@dots{}}.
11148The @code{@dots{}} are not printed for function without any arguments.
11149None of the argument names and values are printed.
11150In this case, the example above now becomes:
11151
11152@smallexample
11153#1  0x08048361 in call_me (@dots{}) at frame-args.c:23
11154@end smallexample
11155
11156@end table
11157
11158By default, only scalar arguments are printed.  This command can be used
11159to configure the debugger to print the value of all arguments, regardless
11160of their type.  However, it is often advantageous to not print the value
11161of more complex parameters.  For instance, it reduces the amount of
11162information printed in each frame, making the backtrace more readable.
11163Also, it improves performance when displaying Ada frames, because
11164the computation of large arguments can sometimes be CPU-intensive,
11165especially in large applications.  Setting @code{print frame-arguments}
11166to @code{scalars} (the default), @code{none} or @code{presence} avoids
11167this computation, thus speeding up the display of each Ada frame.
11168
11169@item show print frame-arguments
11170Show how the value of arguments should be displayed when printing a frame.
11171
11172@anchor{set print raw-frame-arguments}
11173@item set print raw-frame-arguments on
11174Print frame arguments in raw, non pretty-printed, form.
11175
11176@item set print raw-frame-arguments off
11177Print frame arguments in pretty-printed form, if there is a pretty-printer
11178for the value (@pxref{Pretty Printing}),
11179otherwise print the value in raw form.
11180This is the default.
11181
11182@item show print raw-frame-arguments
11183Show whether to print frame arguments in raw form.
11184
11185@anchor{set print entry-values}
11186@item set print entry-values @var{value}
11187@kindex set print entry-values
11188Set printing of frame argument values at function entry.  In some cases
11189@value{GDBN} can determine the value of function argument which was passed by
11190the function caller, even if the value was modified inside the called function
11191and therefore is different.  With optimized code, the current value could be
11192unavailable, but the entry value may still be known.
11193
11194The default value is @code{default} (see below for its description).  Older
11195@value{GDBN} behaved as with the setting @code{no}.  Compilers not supporting
11196this feature will behave in the @code{default} setting the same way as with the
11197@code{no} setting.
11198
11199This functionality is currently supported only by DWARF 2 debugging format and
11200the compiler has to produce @samp{DW_TAG_call_site} tags.  With
11201@value{NGCC}, you need to specify @option{-O -g} during compilation, to get
11202this information.
11203
11204The @var{value} parameter can be one of the following:
11205
11206@table @code
11207@item no
11208Print only actual parameter values, never print values from function entry
11209point.
11210@smallexample
11211#0  equal (val=5)
11212#0  different (val=6)
11213#0  lost (val=<optimized out>)
11214#0  born (val=10)
11215#0  invalid (val=<optimized out>)
11216@end smallexample
11217
11218@item only
11219Print only parameter values from function entry point.  The actual parameter
11220values are never printed.
11221@smallexample
11222#0  equal (val@@entry=5)
11223#0  different (val@@entry=5)
11224#0  lost (val@@entry=5)
11225#0  born (val@@entry=<optimized out>)
11226#0  invalid (val@@entry=<optimized out>)
11227@end smallexample
11228
11229@item preferred
11230Print only parameter values from function entry point.  If value from function
11231entry point is not known while the actual value is known, print the actual
11232value for such parameter.
11233@smallexample
11234#0  equal (val@@entry=5)
11235#0  different (val@@entry=5)
11236#0  lost (val@@entry=5)
11237#0  born (val=10)
11238#0  invalid (val@@entry=<optimized out>)
11239@end smallexample
11240
11241@item if-needed
11242Print actual parameter values.  If actual parameter value is not known while
11243value from function entry point is known, print the entry point value for such
11244parameter.
11245@smallexample
11246#0  equal (val=5)
11247#0  different (val=6)
11248#0  lost (val@@entry=5)
11249#0  born (val=10)
11250#0  invalid (val=<optimized out>)
11251@end smallexample
11252
11253@item both
11254Always print both the actual parameter value and its value from function entry
11255point, even if values of one or both are not available due to compiler
11256optimizations.
11257@smallexample
11258#0  equal (val=5, val@@entry=5)
11259#0  different (val=6, val@@entry=5)
11260#0  lost (val=<optimized out>, val@@entry=5)
11261#0  born (val=10, val@@entry=<optimized out>)
11262#0  invalid (val=<optimized out>, val@@entry=<optimized out>)
11263@end smallexample
11264
11265@item compact
11266Print the actual parameter value if it is known and also its value from
11267function entry point if it is known.  If neither is known, print for the actual
11268value @code{<optimized out>}.  If not in MI mode (@pxref{GDB/MI}) and if both
11269values are known and identical, print the shortened
11270@code{param=param@@entry=VALUE} notation.
11271@smallexample
11272#0  equal (val=val@@entry=5)
11273#0  different (val=6, val@@entry=5)
11274#0  lost (val@@entry=5)
11275#0  born (val=10)
11276#0  invalid (val=<optimized out>)
11277@end smallexample
11278
11279@item default
11280Always print the actual parameter value.  Print also its value from function
11281entry point, but only if it is known.  If not in MI mode (@pxref{GDB/MI}) and
11282if both values are known and identical, print the shortened
11283@code{param=param@@entry=VALUE} notation.
11284@smallexample
11285#0  equal (val=val@@entry=5)
11286#0  different (val=6, val@@entry=5)
11287#0  lost (val=<optimized out>, val@@entry=5)
11288#0  born (val=10)
11289#0  invalid (val=<optimized out>)
11290@end smallexample
11291@end table
11292
11293For analysis messages on possible failures of frame argument values at function
11294entry resolution see @ref{set debug entry-values}.
11295
11296@item show print entry-values
11297Show the method being used for printing of frame argument values at function
11298entry.
11299
11300@anchor{set print frame-info}
11301@item set print frame-info @var{value}
11302@kindex set print frame-info
11303@cindex printing frame information
11304@cindex frame information, printing
11305This command allows to control the information printed when
11306the debugger prints a frame.  See @ref{Frames}, @ref{Backtrace},
11307for a general explanation about frames and frame information.
11308Note that some other settings (such as @code{set print frame-arguments}
11309and @code{set print address}) are also influencing if and how some frame
11310information is displayed.  In particular, the frame program counter is never
11311printed if @code{set print address} is off.
11312
11313The possible values for @code{set print frame-info} are:
11314@table @code
11315@item short-location
11316Print the frame level, the program counter (if not at the
11317beginning of the location source line), the function, the function
11318arguments.
11319@item location
11320Same as @code{short-location} but also print the source file and source line
11321number.
11322@item location-and-address
11323Same as @code{location} but print the program counter even if located at the
11324beginning of the location source line.
11325@item source-line
11326Print the program counter (if not at the beginning of the location
11327source line), the line number and the source line.
11328@item source-and-location
11329Print what @code{location} and @code{source-line} are printing.
11330@item auto
11331The information printed for a frame is decided automatically
11332by the @value{GDBN} command that prints a frame.
11333For example, @code{frame} prints the information printed by
11334@code{source-and-location} while @code{stepi} will switch between
11335@code{source-line} and @code{source-and-location} depending on the program
11336counter.
11337The default value is @code{auto}.
11338@end table
11339
11340@anchor{set print repeats}
11341@item set print repeats @var{number-of-repeats}
11342@itemx set print repeats unlimited
11343@cindex repeated array elements
11344Set the threshold for suppressing display of repeated array
11345elements.  When the number of consecutive identical elements of an
11346array exceeds the threshold, @value{GDBN} prints the string
11347@code{"<repeats @var{n} times>"}, where @var{n} is the number of
11348identical repetitions, instead of displaying the identical elements
11349themselves.  Setting the threshold to @code{unlimited} or zero will
11350cause all elements to be individually printed.  The default threshold
11351is 10.
11352
11353@item show print repeats
11354Display the current threshold for printing repeated identical
11355elements.
11356
11357@anchor{set print max-depth}
11358@item set print max-depth @var{depth}
11359@item set print max-depth unlimited
11360@cindex printing nested structures
11361Set the threshold after which nested structures are replaced with
11362ellipsis, this can make visualising deeply nested structures easier.
11363
11364For example, given this C code
11365
11366@smallexample
11367typedef struct s1 @{ int a; @} s1;
11368typedef struct s2 @{ s1 b; @} s2;
11369typedef struct s3 @{ s2 c; @} s3;
11370typedef struct s4 @{ s3 d; @} s4;
11371
11372s4 var = @{ @{ @{ @{ 3 @} @} @} @};
11373@end smallexample
11374
11375The following table shows how different values of @var{depth} will
11376effect how @code{var} is printed by @value{GDBN}:
11377
11378@multitable @columnfractions .3 .7
11379@headitem @var{depth} setting @tab Result of @samp{p var}
11380@item unlimited
11381@tab @code{$1 = @{d = @{c = @{b = @{a = 3@}@}@}@}}
11382@item @code{0}
11383@tab @code{$1 = @{...@}}
11384@item @code{1}
11385@tab @code{$1 = @{d = @{...@}@}}
11386@item @code{2}
11387@tab @code{$1 = @{d = @{c = @{...@}@}@}}
11388@item @code{3}
11389@tab @code{$1 = @{d = @{c = @{b = @{...@}@}@}@}}
11390@item @code{4}
11391@tab @code{$1 = @{d = @{c = @{b = @{a = 3@}@}@}@}}
11392@end multitable
11393
11394To see the contents of structures that have been hidden the user can
11395either increase the print max-depth, or they can print the elements of
11396the structure that are visible, for example
11397
11398@smallexample
11399(gdb) set print max-depth 2
11400(gdb) p var
11401$1 = @{d = @{c = @{...@}@}@}
11402(gdb) p var.d
11403$2 = @{c = @{b = @{...@}@}@}
11404(gdb) p var.d.c
11405$3 = @{b = @{a = 3@}@}
11406@end smallexample
11407
11408The pattern used to replace nested structures varies based on
11409language, for most languages @code{@{...@}} is used, but Fortran uses
11410@code{(...)}.
11411
11412@item show print max-depth
11413Display the current threshold after which nested structures are
11414replaces with ellipsis.
11415
11416@anchor{set print null-stop}
11417@item set print null-stop
11418@cindex @sc{null} elements in arrays
11419Cause @value{GDBN} to stop printing the characters of an array when the first
11420@sc{null} is encountered.  This is useful when large arrays actually
11421contain only short strings.
11422The default is off.
11423
11424@item show print null-stop
11425Show whether @value{GDBN} stops printing an array on the first
11426@sc{null} character.
11427
11428@anchor{set print pretty}
11429@item set print pretty on
11430@cindex print structures in indented form
11431@cindex indentation in structure display
11432Cause @value{GDBN} to print structures in an indented format with one member
11433per line, like this:
11434
11435@smallexample
11436@group
11437$1 = @{
11438  next = 0x0,
11439  flags = @{
11440    sweet = 1,
11441    sour = 1
11442  @},
11443  meat = 0x54 "Pork"
11444@}
11445@end group
11446@end smallexample
11447
11448@item set print pretty off
11449Cause @value{GDBN} to print structures in a compact format, like this:
11450
11451@smallexample
11452@group
11453$1 = @{next = 0x0, flags = @{sweet = 1, sour = 1@}, \
11454meat = 0x54 "Pork"@}
11455@end group
11456@end smallexample
11457
11458@noindent
11459This is the default format.
11460
11461@item show print pretty
11462Show which format @value{GDBN} is using to print structures.
11463
11464@anchor{set print raw-values}
11465@item set print raw-values on
11466Print values in raw form, without applying the pretty
11467printers for the value.
11468
11469@item set print raw-values off
11470Print values in pretty-printed form, if there is a pretty-printer
11471for the value (@pxref{Pretty Printing}),
11472otherwise print the value in raw form.
11473
11474The default setting is ``off''.
11475
11476@item show print raw-values
11477Show whether to print values in raw form.
11478
11479@item set print sevenbit-strings on
11480@cindex eight-bit characters in strings
11481@cindex octal escapes in strings
11482Print using only seven-bit characters; if this option is set,
11483@value{GDBN} displays any eight-bit characters (in strings or
11484character values) using the notation @code{\}@var{nnn}.  This setting is
11485best if you are working in English (@sc{ascii}) and you use the
11486high-order bit of characters as a marker or ``meta'' bit.
11487
11488@item set print sevenbit-strings off
11489Print full eight-bit characters.  This allows the use of more
11490international character sets, and is the default.
11491
11492@item show print sevenbit-strings
11493Show whether or not @value{GDBN} is printing only seven-bit characters.
11494
11495@anchor{set print union}
11496@item set print union on
11497@cindex unions in structures, printing
11498Tell @value{GDBN} to print unions which are contained in structures
11499and other unions.  This is the default setting.
11500
11501@item set print union off
11502Tell @value{GDBN} not to print unions which are contained in
11503structures and other unions.  @value{GDBN} will print @code{"@{...@}"}
11504instead.
11505
11506@item show print union
11507Ask @value{GDBN} whether or not it will print unions which are contained in
11508structures and other unions.
11509
11510For example, given the declarations
11511
11512@smallexample
11513typedef enum @{Tree, Bug@} Species;
11514typedef enum @{Big_tree, Acorn, Seedling@} Tree_forms;
11515typedef enum @{Caterpillar, Cocoon, Butterfly@}
11516              Bug_forms;
11517
11518struct thing @{
11519  Species it;
11520  union @{
11521    Tree_forms tree;
11522    Bug_forms bug;
11523  @} form;
11524@};
11525
11526struct thing foo = @{Tree, @{Acorn@}@};
11527@end smallexample
11528
11529@noindent
11530with @code{set print union on} in effect @samp{p foo} would print
11531
11532@smallexample
11533$1 = @{it = Tree, form = @{tree = Acorn, bug = Cocoon@}@}
11534@end smallexample
11535
11536@noindent
11537and with @code{set print union off} in effect it would print
11538
11539@smallexample
11540$1 = @{it = Tree, form = @{...@}@}
11541@end smallexample
11542
11543@noindent
11544@code{set print union} affects programs written in C-like languages
11545and in Pascal.
11546@end table
11547
11548@need 1000
11549@noindent
11550These settings are of interest when debugging C@t{++} programs:
11551
11552@table @code
11553@cindex demangling C@t{++} names
11554@item set print demangle
11555@itemx set print demangle on
11556Print C@t{++} names in their source form rather than in the encoded
11557(``mangled'') form passed to the assembler and linker for type-safe
11558linkage.  The default is on.
11559
11560@item show print demangle
11561Show whether C@t{++} names are printed in mangled or demangled form.
11562
11563@item set print asm-demangle
11564@itemx set print asm-demangle on
11565Print C@t{++} names in their source form rather than their mangled form, even
11566in assembler code printouts such as instruction disassemblies.
11567The default is off.
11568
11569@item show print asm-demangle
11570Show whether C@t{++} names in assembly listings are printed in mangled
11571or demangled form.
11572
11573@cindex C@t{++} symbol decoding style
11574@cindex symbol decoding style, C@t{++}
11575@kindex set demangle-style
11576@item set demangle-style @var{style}
11577Choose among several encoding schemes used by different compilers to represent
11578C@t{++} names.  If you omit @var{style}, you will see a list of possible
11579formats.  The default value is @var{auto}, which lets @value{GDBN} choose a
11580decoding style by inspecting your program.
11581
11582@item show demangle-style
11583Display the encoding style currently in use for decoding C@t{++} symbols.
11584
11585@anchor{set print object}
11586@item set print object
11587@itemx set print object on
11588@cindex derived type of an object, printing
11589@cindex display derived types
11590When displaying a pointer to an object, identify the @emph{actual}
11591(derived) type of the object rather than the @emph{declared} type, using
11592the virtual function table.  Note that the virtual function table is
11593required---this feature can only work for objects that have run-time
11594type identification; a single virtual method in the object's declared
11595type is sufficient.  Note that this setting is also taken into account when
11596working with variable objects via MI (@pxref{GDB/MI}).
11597
11598@item set print object off
11599Display only the declared type of objects, without reference to the
11600virtual function table.  This is the default setting.
11601
11602@item show print object
11603Show whether actual, or declared, object types are displayed.
11604
11605@anchor{set print static-members}
11606@item set print static-members
11607@itemx set print static-members on
11608@cindex static members of C@t{++} objects
11609Print static members when displaying a C@t{++} object.  The default is on.
11610
11611@item set print static-members off
11612Do not print static members when displaying a C@t{++} object.
11613
11614@item show print static-members
11615Show whether C@t{++} static members are printed or not.
11616
11617@item set print pascal_static-members
11618@itemx set print pascal_static-members on
11619@cindex static members of Pascal objects
11620@cindex Pascal objects, static members display
11621Print static members when displaying a Pascal object.  The default is on.
11622
11623@item set print pascal_static-members off
11624Do not print static members when displaying a Pascal object.
11625
11626@item show print pascal_static-members
11627Show whether Pascal static members are printed or not.
11628
11629@c These don't work with HP ANSI C++ yet.
11630@anchor{set print vtbl}
11631@item set print vtbl
11632@itemx set print vtbl on
11633@cindex pretty print C@t{++} virtual function tables
11634@cindex virtual functions (C@t{++}) display
11635@cindex VTBL display
11636Pretty print C@t{++} virtual function tables.  The default is off.
11637(The @code{vtbl} commands do not work on programs compiled with the HP
11638ANSI C@t{++} compiler (@code{aCC}).)
11639
11640@item set print vtbl off
11641Do not pretty print C@t{++} virtual function tables.
11642
11643@item show print vtbl
11644Show whether C@t{++} virtual function tables are pretty printed, or not.
11645@end table
11646
11647@node Pretty Printing
11648@section Pretty Printing
11649
11650@value{GDBN} provides a mechanism to allow pretty-printing of values using
11651Python code.  It greatly simplifies the display of complex objects.  This
11652mechanism works for both MI and the CLI.
11653
11654@menu
11655* Pretty-Printer Introduction::  Introduction to pretty-printers
11656* Pretty-Printer Example::       An example pretty-printer
11657* Pretty-Printer Commands::      Pretty-printer commands
11658@end menu
11659
11660@node Pretty-Printer Introduction
11661@subsection Pretty-Printer Introduction
11662
11663When @value{GDBN} prints a value, it first sees if there is a pretty-printer
11664registered for the value.  If there is then @value{GDBN} invokes the
11665pretty-printer to print the value.  Otherwise the value is printed normally.
11666
11667Pretty-printers are normally named.  This makes them easy to manage.
11668The @samp{info pretty-printer} command will list all the installed
11669pretty-printers with their names.
11670If a pretty-printer can handle multiple data types, then its
11671@dfn{subprinters} are the printers for the individual data types.
11672Each such subprinter has its own name.
11673The format of the name is @var{printer-name};@var{subprinter-name}.
11674
11675Pretty-printers are installed by @dfn{registering} them with @value{GDBN}.
11676Typically they are automatically loaded and registered when the corresponding
11677debug information is loaded, thus making them available without having to
11678do anything special.
11679
11680There are three places where a pretty-printer can be registered.
11681
11682@itemize @bullet
11683@item
11684Pretty-printers registered globally are available when debugging
11685all inferiors.
11686
11687@item
11688Pretty-printers registered with a program space are available only
11689when debugging that program.
11690@xref{Progspaces In Python}, for more details on program spaces in Python.
11691
11692@item
11693Pretty-printers registered with an objfile are loaded and unloaded
11694with the corresponding objfile (e.g., shared library).
11695@xref{Objfiles In Python}, for more details on objfiles in Python.
11696@end itemize
11697
11698@xref{Selecting Pretty-Printers}, for further information on how
11699pretty-printers are selected,
11700
11701@xref{Writing a Pretty-Printer}, for implementing pretty printers
11702for new types.
11703
11704@node Pretty-Printer Example
11705@subsection Pretty-Printer Example
11706
11707Here is how a C@t{++} @code{std::string} looks without a pretty-printer:
11708
11709@smallexample
11710(@value{GDBP}) print s
11711$1 = @{
11712  static npos = 4294967295,
11713  _M_dataplus = @{
11714    <std::allocator<char>> = @{
11715      <__gnu_cxx::new_allocator<char>> = @{
11716        <No data fields>@}, <No data fields>
11717      @},
11718    members of std::basic_string<char, std::char_traits<char>,
11719      std::allocator<char> >::_Alloc_hider:
11720    _M_p = 0x804a014 "abcd"
11721  @}
11722@}
11723@end smallexample
11724
11725With a pretty-printer for @code{std::string} only the contents are printed:
11726
11727@smallexample
11728(@value{GDBP}) print s
11729$2 = "abcd"
11730@end smallexample
11731
11732@node Pretty-Printer Commands
11733@subsection Pretty-Printer Commands
11734@cindex pretty-printer commands
11735
11736@table @code
11737@kindex info pretty-printer
11738@item info pretty-printer [@var{object-regexp} [@var{name-regexp}]]
11739Print the list of installed pretty-printers.
11740This includes disabled pretty-printers, which are marked as such.
11741
11742@var{object-regexp} is a regular expression matching the objects
11743whose pretty-printers to list.
11744Objects can be @code{global}, the program space's file
11745(@pxref{Progspaces In Python}),
11746and the object files within that program space (@pxref{Objfiles In Python}).
11747@xref{Selecting Pretty-Printers}, for details on how @value{GDBN}
11748looks up a printer from these three objects.
11749
11750@var{name-regexp} is a regular expression matching the name of the printers
11751to list.
11752
11753@kindex disable pretty-printer
11754@item disable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
11755Disable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
11756A disabled pretty-printer is not forgotten, it may be enabled again later.
11757
11758@kindex enable pretty-printer
11759@item enable pretty-printer [@var{object-regexp} [@var{name-regexp}]]
11760Enable pretty-printers matching @var{object-regexp} and @var{name-regexp}.
11761@end table
11762
11763Example:
11764
11765Suppose we have three pretty-printers installed: one from library1.so
11766named @code{foo} that prints objects of type @code{foo}, and
11767another from library2.so named @code{bar} that prints two types of objects,
11768@code{bar1} and @code{bar2}.
11769
11770@smallexample
11771(gdb) info pretty-printer
11772library1.so:
11773  foo
11774library2.so:
11775  bar
11776    bar1
11777    bar2
11778(gdb) info pretty-printer library2
11779library2.so:
11780  bar
11781    bar1
11782    bar2
11783(gdb) disable pretty-printer library1
117841 printer disabled
117852 of 3 printers enabled
11786(gdb) info pretty-printer
11787library1.so:
11788  foo [disabled]
11789library2.so:
11790  bar
11791    bar1
11792    bar2
11793(gdb) disable pretty-printer library2 bar;bar1
117941 printer disabled
117951 of 3 printers enabled
11796(gdb) info pretty-printer library2
11797library1.so:
11798  foo [disabled]
11799library2.so:
11800  bar
11801    bar1 [disabled]
11802    bar2
11803(gdb) disable pretty-printer library2 bar
118041 printer disabled
118050 of 3 printers enabled
11806(gdb) info pretty-printer library2
11807library1.so:
11808  foo [disabled]
11809library2.so:
11810  bar [disabled]
11811    bar1 [disabled]
11812    bar2
11813@end smallexample
11814
11815Note that for @code{bar} the entire printer can be disabled,
11816as can each individual subprinter.
11817
11818Printing values and frame arguments is done by default using
11819the enabled pretty printers.
11820
11821The print option @code{-raw-values} and @value{GDBN} setting
11822@code{set print raw-values} (@pxref{set print raw-values}) can be
11823used to print values without applying the enabled pretty printers.
11824
11825Similarly, the backtrace option @code{-raw-frame-arguments} and
11826@value{GDBN} setting @code{set print raw-frame-arguments}
11827(@pxref{set print raw-frame-arguments}) can be used to ignore the
11828enabled pretty printers when printing frame argument values.
11829
11830@node Value History
11831@section Value History
11832
11833@cindex value history
11834@cindex history of values printed by @value{GDBN}
11835Values printed by the @code{print} command are saved in the @value{GDBN}
11836@dfn{value history}.  This allows you to refer to them in other expressions.
11837Values are kept until the symbol table is re-read or discarded
11838(for example with the @code{file} or @code{symbol-file} commands).
11839When the symbol table changes, the value history is discarded,
11840since the values may contain pointers back to the types defined in the
11841symbol table.
11842
11843@cindex @code{$}
11844@cindex @code{$$}
11845@cindex history number
11846The values printed are given @dfn{history numbers} by which you can
11847refer to them.  These are successive integers starting with one.
11848@code{print} shows you the history number assigned to a value by
11849printing @samp{$@var{num} = } before the value; here @var{num} is the
11850history number.
11851
11852To refer to any previous value, use @samp{$} followed by the value's
11853history number.  The way @code{print} labels its output is designed to
11854remind you of this.  Just @code{$} refers to the most recent value in
11855the history, and @code{$$} refers to the value before that.
11856@code{$$@var{n}} refers to the @var{n}th value from the end; @code{$$2}
11857is the value just prior to @code{$$}, @code{$$1} is equivalent to
11858@code{$$}, and @code{$$0} is equivalent to @code{$}.
11859
11860For example, suppose you have just printed a pointer to a structure and
11861want to see the contents of the structure.  It suffices to type
11862
11863@smallexample
11864p *$
11865@end smallexample
11866
11867If you have a chain of structures where the component @code{next} points
11868to the next one, you can print the contents of the next one with this:
11869
11870@smallexample
11871p *$.next
11872@end smallexample
11873
11874@noindent
11875You can print successive links in the chain by repeating this
11876command---which you can do by just typing @key{RET}.
11877
11878Note that the history records values, not expressions.  If the value of
11879@code{x} is 4 and you type these commands:
11880
11881@smallexample
11882print x
11883set x=5
11884@end smallexample
11885
11886@noindent
11887then the value recorded in the value history by the @code{print} command
11888remains 4 even though the value of @code{x} has changed.
11889
11890@table @code
11891@kindex show values
11892@item show values
11893Print the last ten values in the value history, with their item numbers.
11894This is like @samp{p@ $$9} repeated ten times, except that @code{show
11895values} does not change the history.
11896
11897@item show values @var{n}
11898Print ten history values centered on history item number @var{n}.
11899
11900@item show values +
11901Print ten history values just after the values last printed.  If no more
11902values are available, @code{show values +} produces no display.
11903@end table
11904
11905Pressing @key{RET} to repeat @code{show values @var{n}} has exactly the
11906same effect as @samp{show values +}.
11907
11908@node Convenience Vars
11909@section Convenience Variables
11910
11911@cindex convenience variables
11912@cindex user-defined variables
11913@value{GDBN} provides @dfn{convenience variables} that you can use within
11914@value{GDBN} to hold on to a value and refer to it later.  These variables
11915exist entirely within @value{GDBN}; they are not part of your program, and
11916setting a convenience variable has no direct effect on further execution
11917of your program.  That is why you can use them freely.
11918
11919Convenience variables are prefixed with @samp{$}.  Any name preceded by
11920@samp{$} can be used for a convenience variable, unless it is one of
11921the predefined machine-specific register names (@pxref{Registers, ,Registers}).
11922(Value history references, in contrast, are @emph{numbers} preceded
11923by @samp{$}.  @xref{Value History, ,Value History}.)
11924
11925You can save a value in a convenience variable with an assignment
11926expression, just as you would set a variable in your program.
11927For example:
11928
11929@smallexample
11930set $foo = *object_ptr
11931@end smallexample
11932
11933@noindent
11934would save in @code{$foo} the value contained in the object pointed to by
11935@code{object_ptr}.
11936
11937Using a convenience variable for the first time creates it, but its
11938value is @code{void} until you assign a new value.  You can alter the
11939value with another assignment at any time.
11940
11941Convenience variables have no fixed types.  You can assign a convenience
11942variable any type of value, including structures and arrays, even if
11943that variable already has a value of a different type.  The convenience
11944variable, when used as an expression, has the type of its current value.
11945
11946@table @code
11947@kindex show convenience
11948@cindex show all user variables and functions
11949@item show convenience
11950Print a list of convenience variables used so far, and their values,
11951as well as a list of the convenience functions.
11952Abbreviated @code{show conv}.
11953
11954@kindex init-if-undefined
11955@cindex convenience variables, initializing
11956@item init-if-undefined $@var{variable} = @var{expression}
11957Set a convenience variable if it has not already been set.  This is useful
11958for user-defined commands that keep some state.  It is similar, in concept,
11959to using local static variables with initializers in C (except that
11960convenience variables are global).  It can also be used to allow users to
11961override default values used in a command script.
11962
11963If the variable is already defined then the expression is not evaluated so
11964any side-effects do not occur.
11965@end table
11966
11967One of the ways to use a convenience variable is as a counter to be
11968incremented or a pointer to be advanced.  For example, to print
11969a field from successive elements of an array of structures:
11970
11971@smallexample
11972set $i = 0
11973print bar[$i++]->contents
11974@end smallexample
11975
11976@noindent
11977Repeat that command by typing @key{RET}.
11978
11979Some convenience variables are created automatically by @value{GDBN} and given
11980values likely to be useful.
11981
11982@table @code
11983@vindex $_@r{, convenience variable}
11984@item $_
11985The variable @code{$_} is automatically set by the @code{x} command to
11986the last address examined (@pxref{Memory, ,Examining Memory}).  Other
11987commands which provide a default address for @code{x} to examine also
11988set @code{$_} to that address; these commands include @code{info line}
11989and @code{info breakpoint}.  The type of @code{$_} is @code{void *}
11990except when set by the @code{x} command, in which case it is a pointer
11991to the type of @code{$__}.
11992
11993@vindex $__@r{, convenience variable}
11994@item $__
11995The variable @code{$__} is automatically set by the @code{x} command
11996to the value found in the last address examined.  Its type is chosen
11997to match the format in which the data was printed.
11998
11999@item $_exitcode
12000@vindex $_exitcode@r{, convenience variable}
12001When the program being debugged terminates normally, @value{GDBN}
12002automatically sets this variable to the exit code of the program, and
12003resets @code{$_exitsignal} to @code{void}.
12004
12005@item $_exitsignal
12006@vindex $_exitsignal@r{, convenience variable}
12007When the program being debugged dies due to an uncaught signal,
12008@value{GDBN} automatically sets this variable to that signal's number,
12009and resets @code{$_exitcode} to @code{void}.
12010
12011To distinguish between whether the program being debugged has exited
12012(i.e., @code{$_exitcode} is not @code{void}) or signalled (i.e.,
12013@code{$_exitsignal} is not @code{void}), the convenience function
12014@code{$_isvoid} can be used (@pxref{Convenience Funs,, Convenience
12015Functions}).  For example, considering the following source code:
12016
12017@smallexample
12018#include <signal.h>
12019
12020int
12021main (int argc, char *argv[])
12022@{
12023  raise (SIGALRM);
12024  return 0;
12025@}
12026@end smallexample
12027
12028A valid way of telling whether the program being debugged has exited
12029or signalled would be:
12030
12031@smallexample
12032(@value{GDBP}) define has_exited_or_signalled
12033Type commands for definition of ``has_exited_or_signalled''.
12034End with a line saying just ``end''.
12035>if $_isvoid ($_exitsignal)
12036 >echo The program has exited\n
12037 >else
12038 >echo The program has signalled\n
12039 >end
12040>end
12041(@value{GDBP}) run
12042Starting program:
12043
12044Program terminated with signal SIGALRM, Alarm clock.
12045The program no longer exists.
12046(@value{GDBP}) has_exited_or_signalled
12047The program has signalled
12048@end smallexample
12049
12050As can be seen, @value{GDBN} correctly informs that the program being
12051debugged has signalled, since it calls @code{raise} and raises a
12052@code{SIGALRM} signal.  If the program being debugged had not called
12053@code{raise}, then @value{GDBN} would report a normal exit:
12054
12055@smallexample
12056(@value{GDBP}) has_exited_or_signalled
12057The program has exited
12058@end smallexample
12059
12060@item $_exception
12061The variable @code{$_exception} is set to the exception object being
12062thrown at an exception-related catchpoint.  @xref{Set Catchpoints}.
12063
12064@item $_ada_exception
12065The variable @code{$_ada_exception} is set to the address of the
12066exception being caught or thrown at an Ada exception-related
12067catchpoint.  @xref{Set Catchpoints}.
12068
12069@item $_probe_argc
12070@itemx $_probe_arg0@dots{}$_probe_arg11
12071Arguments to a static probe.  @xref{Static Probe Points}.
12072
12073@item $_sdata
12074@vindex $_sdata@r{, inspect, convenience variable}
12075The variable @code{$_sdata} contains extra collected static tracepoint
12076data.  @xref{Tracepoint Actions,,Tracepoint Action Lists}.  Note that
12077@code{$_sdata} could be empty, if not inspecting a trace buffer, or
12078if extra static tracepoint data has not been collected.
12079
12080@item $_siginfo
12081@vindex $_siginfo@r{, convenience variable}
12082The variable @code{$_siginfo} contains extra signal information
12083(@pxref{extra signal information}).  Note that @code{$_siginfo}
12084could be empty, if the application has not yet received any signals.
12085For example, it will be empty before you execute the @code{run} command.
12086
12087@item $_tlb
12088@vindex $_tlb@r{, convenience variable}
12089The variable @code{$_tlb} is automatically set when debugging
12090applications running on MS-Windows in native mode or connected to
12091gdbserver that supports the @code{qGetTIBAddr} request.
12092@xref{General Query Packets}.
12093This variable contains the address of the thread information block.
12094
12095@item $_inferior
12096The number of the current inferior.  @xref{Inferiors Connections and
12097Programs, ,Debugging Multiple Inferiors Connections and Programs}.
12098
12099@item $_thread
12100The thread number of the current thread.  @xref{thread numbers}.
12101
12102@item $_gthread
12103The global number of the current thread.  @xref{global thread numbers}.
12104
12105@item $_gdb_major
12106@itemx $_gdb_minor
12107@vindex $_gdb_major@r{, convenience variable}
12108@vindex $_gdb_minor@r{, convenience variable}
12109The major and minor version numbers of the running @value{GDBN}.
12110Development snapshots and pretest versions have their minor version
12111incremented by one; thus, @value{GDBN} pretest 9.11.90 will produce
12112the value 12 for @code{$_gdb_minor}.  These variables allow you to
12113write scripts that work with different versions of @value{GDBN}
12114without errors caused by features unavailable in some of those
12115versions.
12116
12117@item $_shell_exitcode
12118@itemx $_shell_exitsignal
12119@vindex $_shell_exitcode@r{, convenience variable}
12120@vindex $_shell_exitsignal@r{, convenience variable}
12121@cindex shell command, exit code
12122@cindex shell command, exit signal
12123@cindex exit status of shell commands
12124@value{GDBN} commands such as @code{shell} and @code{|} are launching
12125shell commands.  When a launched command terminates, @value{GDBN}
12126automatically maintains the variables @code{$_shell_exitcode}
12127and @code{$_shell_exitsignal} according to the exit status of the last
12128launched command.  These variables are set and used similarly to
12129the variables @code{$_exitcode} and @code{$_exitsignal}.
12130
12131@end table
12132
12133@node Convenience Funs
12134@section Convenience Functions
12135
12136@cindex convenience functions
12137@value{GDBN} also supplies some @dfn{convenience functions}.  These
12138have a syntax similar to convenience variables.  A convenience
12139function can be used in an expression just like an ordinary function;
12140however, a convenience function is implemented internally to
12141@value{GDBN}.
12142
12143These functions do not require @value{GDBN} to be configured with
12144@code{Python} support, which means that they are always available.
12145
12146@table @code
12147
12148@item $_isvoid (@var{expr})
12149@findex $_isvoid@r{, convenience function}
12150Return one if the expression @var{expr} is @code{void}.  Otherwise it
12151returns zero.
12152
12153A @code{void} expression is an expression where the type of the result
12154is @code{void}.  For example, you can examine a convenience variable
12155(see @ref{Convenience Vars,, Convenience Variables}) to check whether
12156it is @code{void}:
12157
12158@smallexample
12159(@value{GDBP}) print $_exitcode
12160$1 = void
12161(@value{GDBP}) print $_isvoid ($_exitcode)
12162$2 = 1
12163(@value{GDBP}) run
12164Starting program: ./a.out
12165[Inferior 1 (process 29572) exited normally]
12166(@value{GDBP}) print $_exitcode
12167$3 = 0
12168(@value{GDBP}) print $_isvoid ($_exitcode)
12169$4 = 0
12170@end smallexample
12171
12172In the example above, we used @code{$_isvoid} to check whether
12173@code{$_exitcode} is @code{void} before and after the execution of the
12174program being debugged.  Before the execution there is no exit code to
12175be examined, therefore @code{$_exitcode} is @code{void}.  After the
12176execution the program being debugged returned zero, therefore
12177@code{$_exitcode} is zero, which means that it is not @code{void}
12178anymore.
12179
12180The @code{void} expression can also be a call of a function from the
12181program being debugged.  For example, given the following function:
12182
12183@smallexample
12184void
12185foo (void)
12186@{
12187@}
12188@end smallexample
12189
12190The result of calling it inside @value{GDBN} is @code{void}:
12191
12192@smallexample
12193(@value{GDBP}) print foo ()
12194$1 = void
12195(@value{GDBP}) print $_isvoid (foo ())
12196$2 = 1
12197(@value{GDBP}) set $v = foo ()
12198(@value{GDBP}) print $v
12199$3 = void
12200(@value{GDBP}) print $_isvoid ($v)
12201$4 = 1
12202@end smallexample
12203
12204@item $_gdb_setting_str (@var{setting})
12205@findex $_gdb_setting_str@r{, convenience function}
12206Return the value of the @value{GDBN} @var{setting} as a string.
12207@var{setting} is any setting that can be used in a @code{set} or
12208@code{show} command (@pxref{Controlling GDB}).
12209
12210@smallexample
12211(@value{GDBP}) show print frame-arguments
12212Printing of non-scalar frame arguments is "scalars".
12213(@value{GDBP}) p $_gdb_setting_str("print frame-arguments")
12214$1 = "scalars"
12215(@value{GDBP}) p $_gdb_setting_str("height")
12216$2 = "30"
12217(@value{GDBP})
12218@end smallexample
12219
12220@item $_gdb_setting (@var{setting})
12221@findex $_gdb_setting@r{, convenience function}
12222Return the value of the @value{GDBN} @var{setting}.
12223The type of the returned value depends on the setting.
12224
12225The value type for boolean and auto boolean settings is @code{int}.
12226The boolean values @code{off} and @code{on} are converted to
12227the integer values @code{0} and @code{1}.  The value @code{auto} is
12228converted to the value @code{-1}.
12229
12230The value type for integer settings is either @code{unsigned int}
12231or @code{int}, depending on the setting.
12232
12233Some integer settings accept an @code{unlimited} value.
12234Depending on the setting, the @code{set} command also accepts
12235the value @code{0} or the value @code{@minus{}1} as a synonym for
12236@code{unlimited}.
12237For example, @code{set height unlimited} is equivalent to
12238@code{set height 0}.
12239
12240Some other settings that accept the @code{unlimited} value
12241use the value @code{0} to literally mean zero.
12242For example, @code{set history size 0} indicates to not
12243record any @value{GDBN} commands in the command history.
12244For such settings, @code{@minus{}1} is the synonym
12245for @code{unlimited}.
12246
12247See the documentation of the corresponding @code{set} command for
12248the numerical value equivalent to @code{unlimited}.
12249
12250The @code{$_gdb_setting} function converts the unlimited value
12251to a @code{0} or a @code{@minus{}1} value according to what the
12252@code{set} command uses.
12253
12254@smallexample
12255@group
12256(@value{GDBP}) p $_gdb_setting_str("height")
12257$1 = "30"
12258(@value{GDBP}) p $_gdb_setting("height")
12259$2 = 30
12260(@value{GDBP}) set height unlimited
12261(@value{GDBP}) p $_gdb_setting_str("height")
12262$3 = "unlimited"
12263(@value{GDBP}) p $_gdb_setting("height")
12264$4 = 0
12265@end group
12266@group
12267(@value{GDBP}) p $_gdb_setting_str("history size")
12268$5 = "unlimited"
12269(@value{GDBP}) p $_gdb_setting("history size")
12270$6 = -1
12271(@value{GDBP}) p $_gdb_setting_str("disassemble-next-line")
12272$7 = "auto"
12273(@value{GDBP}) p $_gdb_setting("disassemble-next-line")
12274$8 = -1
12275(@value{GDBP})
12276@end group
12277@end smallexample
12278
12279Other setting types (enum, filename, optional filename, string, string noescape)
12280are returned as string values.
12281
12282
12283@item $_gdb_maint_setting_str (@var{setting})
12284@findex $_gdb_maint_setting_str@r{, convenience function}
12285Like the @code{$_gdb_setting_str} function, but works with
12286@code{maintenance set} variables.
12287
12288@item $_gdb_maint_setting (@var{setting})
12289@findex $_gdb_maint_setting@r{, convenience function}
12290Like the @code{$_gdb_setting} function, but works with
12291@code{maintenance set} variables.
12292
12293@end table
12294
12295The following functions require @value{GDBN} to be configured with
12296@code{Python} support.
12297
12298@table @code
12299
12300@item $_memeq(@var{buf1}, @var{buf2}, @var{length})
12301@findex $_memeq@r{, convenience function}
12302Returns one if the @var{length} bytes at the addresses given by
12303@var{buf1} and @var{buf2} are equal.
12304Otherwise it returns zero.
12305
12306@item $_regex(@var{str}, @var{regex})
12307@findex $_regex@r{, convenience function}
12308Returns one if the string @var{str} matches the regular expression
12309@var{regex}.  Otherwise it returns zero.
12310The syntax of the regular expression is that specified by @code{Python}'s
12311regular expression support.
12312
12313@item $_streq(@var{str1}, @var{str2})
12314@findex $_streq@r{, convenience function}
12315Returns one if the strings @var{str1} and @var{str2} are equal.
12316Otherwise it returns zero.
12317
12318@item $_strlen(@var{str})
12319@findex $_strlen@r{, convenience function}
12320Returns the length of string @var{str}.
12321
12322@item $_caller_is(@var{name}@r{[}, @var{number_of_frames}@r{]})
12323@findex $_caller_is@r{, convenience function}
12324Returns one if the calling function's name is equal to @var{name}.
12325Otherwise it returns zero.
12326
12327If the optional argument @var{number_of_frames} is provided,
12328it is the number of frames up in the stack to look.
12329The default is 1.
12330
12331Example:
12332
12333@smallexample
12334(gdb) backtrace
12335#0  bottom_func ()
12336    at testsuite/gdb.python/py-caller-is.c:21
12337#1  0x00000000004005a0 in middle_func ()
12338    at testsuite/gdb.python/py-caller-is.c:27
12339#2  0x00000000004005ab in top_func ()
12340    at testsuite/gdb.python/py-caller-is.c:33
12341#3  0x00000000004005b6 in main ()
12342    at testsuite/gdb.python/py-caller-is.c:39
12343(gdb) print $_caller_is ("middle_func")
12344$1 = 1
12345(gdb) print $_caller_is ("top_func", 2)
12346$1 = 1
12347@end smallexample
12348
12349@item $_caller_matches(@var{regexp}@r{[}, @var{number_of_frames}@r{]})
12350@findex $_caller_matches@r{, convenience function}
12351Returns one if the calling function's name matches the regular expression
12352@var{regexp}.  Otherwise it returns zero.
12353
12354If the optional argument @var{number_of_frames} is provided,
12355it is the number of frames up in the stack to look.
12356The default is 1.
12357
12358@item $_any_caller_is(@var{name}@r{[}, @var{number_of_frames}@r{]})
12359@findex $_any_caller_is@r{, convenience function}
12360Returns one if any calling function's name is equal to @var{name}.
12361Otherwise it returns zero.
12362
12363If the optional argument @var{number_of_frames} is provided,
12364it is the number of frames up in the stack to look.
12365The default is 1.
12366
12367This function differs from @code{$_caller_is} in that this function
12368checks all stack frames from the immediate caller to the frame specified
12369by @var{number_of_frames}, whereas @code{$_caller_is} only checks the
12370frame specified by @var{number_of_frames}.
12371
12372@item $_any_caller_matches(@var{regexp}@r{[}, @var{number_of_frames}@r{]})
12373@findex $_any_caller_matches@r{, convenience function}
12374Returns one if any calling function's name matches the regular expression
12375@var{regexp}.  Otherwise it returns zero.
12376
12377If the optional argument @var{number_of_frames} is provided,
12378it is the number of frames up in the stack to look.
12379The default is 1.
12380
12381This function differs from @code{$_caller_matches} in that this function
12382checks all stack frames from the immediate caller to the frame specified
12383by @var{number_of_frames}, whereas @code{$_caller_matches} only checks the
12384frame specified by @var{number_of_frames}.
12385
12386@item $_as_string(@var{value})
12387@findex $_as_string@r{, convenience function}
12388Return the string representation of @var{value}.
12389
12390This function is useful to obtain the textual label (enumerator) of an
12391enumeration value.  For example, assuming the variable @var{node} is of
12392an enumerated type:
12393
12394@smallexample
12395(gdb) printf "Visiting node of type %s\n", $_as_string(node)
12396Visiting node of type NODE_INTEGER
12397@end smallexample
12398
12399@item $_cimag(@var{value})
12400@itemx $_creal(@var{value})
12401@findex $_cimag@r{, convenience function}
12402@findex $_creal@r{, convenience function}
12403Return the imaginary (@code{$_cimag}) or real (@code{$_creal}) part of
12404the complex number @var{value}.
12405
12406The type of the imaginary or real part depends on the type of the
12407complex number, e.g., using @code{$_cimag} on a @code{float complex}
12408will return an imaginary part of type @code{float}.
12409
12410@end table
12411
12412@value{GDBN} provides the ability to list and get help on
12413convenience functions.
12414
12415@table @code
12416@item help function
12417@kindex help function
12418@cindex show all convenience functions
12419Print a list of all convenience functions.
12420@end table
12421
12422@node Registers
12423@section Registers
12424
12425@cindex registers
12426You can refer to machine register contents, in expressions, as variables
12427with names starting with @samp{$}.  The names of registers are different
12428for each machine; use @code{info registers} to see the names used on
12429your machine.
12430
12431@table @code
12432@kindex info registers
12433@item info registers
12434Print the names and values of all registers except floating-point
12435and vector registers (in the selected stack frame).
12436
12437@kindex info all-registers
12438@cindex floating point registers
12439@item info all-registers
12440Print the names and values of all registers, including floating-point
12441and vector registers (in the selected stack frame).
12442
12443@anchor{info_registers_reggroup}
12444@item info registers @var{reggroup} @dots{}
12445Print the name and value of the registers in each of the specified
12446@var{reggroup}s.  The @var{reggroup} can be any of those returned by
12447@code{maint print reggroups} (@pxref{Maintenance Commands}).
12448
12449@item info registers @var{regname} @dots{}
12450Print the @dfn{relativized} value of each specified register @var{regname}.
12451As discussed in detail below, register values are normally relative to
12452the selected stack frame.  The @var{regname} may be any register name valid on
12453the machine you are using, with or without the initial @samp{$}.
12454@end table
12455
12456@anchor{standard registers}
12457@cindex stack pointer register
12458@cindex program counter register
12459@cindex process status register
12460@cindex frame pointer register
12461@cindex standard registers
12462@value{GDBN} has four ``standard'' register names that are available (in
12463expressions) on most machines---whenever they do not conflict with an
12464architecture's canonical mnemonics for registers.  The register names
12465@code{$pc} and @code{$sp} are used for the program counter register and
12466the stack pointer.  @code{$fp} is used for a register that contains a
12467pointer to the current stack frame, and @code{$ps} is used for a
12468register that contains the processor status.  For example,
12469you could print the program counter in hex with
12470
12471@smallexample
12472p/x $pc
12473@end smallexample
12474
12475@noindent
12476or print the instruction to be executed next with
12477
12478@smallexample
12479x/i $pc
12480@end smallexample
12481
12482@noindent
12483or add four to the stack pointer@footnote{This is a way of removing
12484one word from the stack, on machines where stacks grow downward in
12485memory (most machines, nowadays).  This assumes that the innermost
12486stack frame is selected; setting @code{$sp} is not allowed when other
12487stack frames are selected.  To pop entire frames off the stack,
12488regardless of machine architecture, use @code{return};
12489see @ref{Returning, ,Returning from a Function}.} with
12490
12491@smallexample
12492set $sp += 4
12493@end smallexample
12494
12495Whenever possible, these four standard register names are available on
12496your machine even though the machine has different canonical mnemonics,
12497so long as there is no conflict.  The @code{info registers} command
12498shows the canonical names.  For example, on the SPARC, @code{info
12499registers} displays the processor status register as @code{$psr} but you
12500can also refer to it as @code{$ps}; and on x86-based machines @code{$ps}
12501is an alias for the @sc{eflags} register.
12502
12503@value{GDBN} always considers the contents of an ordinary register as an
12504integer when the register is examined in this way.  Some machines have
12505special registers which can hold nothing but floating point; these
12506registers are considered to have floating point values.  There is no way
12507to refer to the contents of an ordinary register as floating point value
12508(although you can @emph{print} it as a floating point value with
12509@samp{print/f $@var{regname}}).
12510
12511Some registers have distinct ``raw'' and ``virtual'' data formats.  This
12512means that the data format in which the register contents are saved by
12513the operating system is not the same one that your program normally
12514sees.  For example, the registers of the 68881 floating point
12515coprocessor are always saved in ``extended'' (raw) format, but all C
12516programs expect to work with ``double'' (virtual) format.  In such
12517cases, @value{GDBN} normally works with the virtual format only (the format
12518that makes sense for your program), but the @code{info registers} command
12519prints the data in both formats.
12520
12521@cindex SSE registers (x86)
12522@cindex MMX registers (x86)
12523Some machines have special registers whose contents can be interpreted
12524in several different ways.  For example, modern x86-based machines
12525have SSE and MMX registers that can hold several values packed
12526together in several different formats.  @value{GDBN} refers to such
12527registers in @code{struct} notation:
12528
12529@smallexample
12530(@value{GDBP}) print $xmm1
12531$1 = @{
12532  v4_float = @{0, 3.43859137e-038, 1.54142831e-044, 1.821688e-044@},
12533  v2_double = @{9.92129282474342e-303, 2.7585945287983262e-313@},
12534  v16_int8 = "\000\000\000\000\3706;\001\v\000\000\000\r\000\000",
12535  v8_int16 = @{0, 0, 14072, 315, 11, 0, 13, 0@},
12536  v4_int32 = @{0, 20657912, 11, 13@},
12537  v2_int64 = @{88725056443645952, 55834574859@},
12538  uint128 = 0x0000000d0000000b013b36f800000000
12539@}
12540@end smallexample
12541
12542@noindent
12543To set values of such registers, you need to tell @value{GDBN} which
12544view of the register you wish to change, as if you were assigning
12545value to a @code{struct} member:
12546
12547@smallexample
12548 (@value{GDBP}) set $xmm1.uint128 = 0x000000000000000000000000FFFFFFFF
12549@end smallexample
12550
12551Normally, register values are relative to the selected stack frame
12552(@pxref{Selection, ,Selecting a Frame}).  This means that you get the
12553value that the register would contain if all stack frames farther in
12554were exited and their saved registers restored.  In order to see the
12555true contents of hardware registers, you must select the innermost
12556frame (with @samp{frame 0}).
12557
12558@cindex caller-saved registers
12559@cindex call-clobbered registers
12560@cindex volatile registers
12561@cindex <not saved> values
12562Usually ABIs reserve some registers as not needed to be saved by the
12563callee (a.k.a.: ``caller-saved'', ``call-clobbered'' or ``volatile''
12564registers).  It may therefore not be possible for @value{GDBN} to know
12565the value a register had before the call (in other words, in the outer
12566frame), if the register value has since been changed by the callee.
12567@value{GDBN} tries to deduce where the inner frame saved
12568(``callee-saved'') registers, from the debug info, unwind info, or the
12569machine code generated by your compiler.  If some register is not
12570saved, and @value{GDBN} knows the register is ``caller-saved'' (via
12571its own knowledge of the ABI, or because the debug/unwind info
12572explicitly says the register's value is undefined), @value{GDBN}
12573displays @w{@samp{<not saved>}} as the register's value.  With targets
12574that @value{GDBN} has no knowledge of the register saving convention,
12575if a register was not saved by the callee, then its value and location
12576in the outer frame are assumed to be the same of the inner frame.
12577This is usually harmless, because if the register is call-clobbered,
12578the caller either does not care what is in the register after the
12579call, or has code to restore the value that it does care about.  Note,
12580however, that if you change such a register in the outer frame, you
12581may also be affecting the inner frame.  Also, the more ``outer'' the
12582frame is you're looking at, the more likely a call-clobbered
12583register's value is to be wrong, in the sense that it doesn't actually
12584represent the value the register had just before the call.
12585
12586@node Floating Point Hardware
12587@section Floating Point Hardware
12588@cindex floating point
12589
12590Depending on the configuration, @value{GDBN} may be able to give
12591you more information about the status of the floating point hardware.
12592
12593@table @code
12594@kindex info float
12595@item info float
12596Display hardware-dependent information about the floating
12597point unit.  The exact contents and layout vary depending on the
12598floating point chip.  Currently, @samp{info float} is supported on
12599the ARM and x86 machines.
12600@end table
12601
12602@node Vector Unit
12603@section Vector Unit
12604@cindex vector unit
12605
12606Depending on the configuration, @value{GDBN} may be able to give you
12607more information about the status of the vector unit.
12608
12609@table @code
12610@kindex info vector
12611@item info vector
12612Display information about the vector unit.  The exact contents and
12613layout vary depending on the hardware.
12614@end table
12615
12616@node OS Information
12617@section Operating System Auxiliary Information
12618@cindex OS information
12619
12620@value{GDBN} provides interfaces to useful OS facilities that can help
12621you debug your program.
12622
12623@cindex auxiliary vector
12624@cindex vector, auxiliary
12625Some operating systems supply an @dfn{auxiliary vector} to programs at
12626startup.  This is akin to the arguments and environment that you
12627specify for a program, but contains a system-dependent variety of
12628binary values that tell system libraries important details about the
12629hardware, operating system, and process.  Each value's purpose is
12630identified by an integer tag; the meanings are well-known but system-specific.
12631Depending on the configuration and operating system facilities,
12632@value{GDBN} may be able to show you this information.  For remote
12633targets, this functionality may further depend on the remote stub's
12634support of the @samp{qXfer:auxv:read} packet, see
12635@ref{qXfer auxiliary vector read}.
12636
12637@table @code
12638@kindex info auxv
12639@item info auxv
12640Display the auxiliary vector of the inferior, which can be either a
12641live process or a core dump file.  @value{GDBN} prints each tag value
12642numerically, and also shows names and text descriptions for recognized
12643tags.  Some values in the vector are numbers, some bit masks, and some
12644pointers to strings or other data.  @value{GDBN} displays each value in the
12645most appropriate form for a recognized tag, and in hexadecimal for
12646an unrecognized tag.
12647@end table
12648
12649On some targets, @value{GDBN} can access operating system-specific
12650information and show it to you.  The types of information available
12651will differ depending on the type of operating system running on the
12652target.  The mechanism used to fetch the data is described in
12653@ref{Operating System Information}.  For remote targets, this
12654functionality depends on the remote stub's support of the
12655@samp{qXfer:osdata:read} packet, see @ref{qXfer osdata read}.
12656
12657@table @code
12658@kindex info os
12659@item info os @var{infotype}
12660
12661Display OS information of the requested type.
12662
12663On @sc{gnu}/Linux, the following values of @var{infotype} are valid:
12664
12665@anchor{linux info os infotypes}
12666@table @code
12667@kindex info os cpus
12668@item cpus
12669Display the list of all CPUs/cores. For each CPU/core, @value{GDBN} prints
12670the available fields from /proc/cpuinfo. For each supported architecture
12671different fields are available. Two common entries are processor which gives
12672CPU number and bogomips; a system constant that is calculated during
12673kernel initialization.
12674
12675@kindex info os files
12676@item files
12677Display the list of open file descriptors on the target.  For each
12678file descriptor, @value{GDBN} prints the identifier of the process
12679owning the descriptor, the command of the owning process, the value
12680of the descriptor, and the target of the descriptor.
12681
12682@kindex info os modules
12683@item modules
12684Display the list of all loaded kernel modules on the target.  For each
12685module, @value{GDBN} prints the module name, the size of the module in
12686bytes, the number of times the module is used, the dependencies of the
12687module, the status of the module, and the address of the loaded module
12688in memory.
12689
12690@kindex info os msg
12691@item msg
12692Display the list of all System V message queues on the target.  For each
12693message queue, @value{GDBN} prints the message queue key, the message
12694queue identifier, the access permissions, the current number of bytes
12695on the queue, the current number of messages on the queue, the processes
12696that last sent and received a message on the queue, the user and group
12697of the owner and creator of the message queue, the times at which a
12698message was last sent and received on the queue, and the time at which
12699the message queue was last changed.
12700
12701@kindex info os processes
12702@item processes
12703Display the list of processes on the target.  For each process,
12704@value{GDBN} prints the process identifier, the name of the user, the
12705command corresponding to the process, and the list of processor cores
12706that the process is currently running on.  (To understand what these
12707properties mean, for this and the following info types, please consult
12708the general @sc{gnu}/Linux documentation.)
12709
12710@kindex info os procgroups
12711@item procgroups
12712Display the list of process groups on the target.  For each process,
12713@value{GDBN} prints the identifier of the process group that it belongs
12714to, the command corresponding to the process group leader, the process
12715identifier, and the command line of the process.  The list is sorted
12716first by the process group identifier, then by the process identifier,
12717so that processes belonging to the same process group are grouped together
12718and the process group leader is listed first.
12719
12720@kindex info os semaphores
12721@item semaphores
12722Display the list of all System V semaphore sets on the target.  For each
12723semaphore set, @value{GDBN} prints the semaphore set key, the semaphore
12724set identifier, the access permissions, the number of semaphores in the
12725set, the user and group of the owner and creator of the semaphore set,
12726and the times at which the semaphore set was operated upon and changed.
12727
12728@kindex info os shm
12729@item shm
12730Display the list of all System V shared-memory regions on the target.
12731For each shared-memory region, @value{GDBN} prints the region key,
12732the shared-memory identifier, the access permissions, the size of the
12733region, the process that created the region, the process that last
12734attached to or detached from the region, the current number of live
12735attaches to the region, and the times at which the region was last
12736attached to, detach from, and changed.
12737
12738@kindex info os sockets
12739@item sockets
12740Display the list of Internet-domain sockets on the target.  For each
12741socket, @value{GDBN} prints the address and port of the local and
12742remote endpoints, the current state of the connection, the creator of
12743the socket, the IP address family of the socket, and the type of the
12744connection.
12745
12746@kindex info os threads
12747@item threads
12748Display the list of threads running on the target.  For each thread,
12749@value{GDBN} prints the identifier of the process that the thread
12750belongs to, the command of the process, the thread identifier, and the
12751processor core that it is currently running on.  The main thread of a
12752process is not listed.
12753@end table
12754
12755@item info os
12756If @var{infotype} is omitted, then list the possible values for
12757@var{infotype} and the kind of OS information available for each
12758@var{infotype}.  If the target does not return a list of possible
12759types, this command will report an error.
12760@end table
12761
12762@node Memory Region Attributes
12763@section Memory Region Attributes
12764@cindex memory region attributes
12765
12766@dfn{Memory region attributes} allow you to describe special handling
12767required by regions of your target's memory.  @value{GDBN} uses
12768attributes to determine whether to allow certain types of memory
12769accesses; whether to use specific width accesses; and whether to cache
12770target memory.  By default the description of memory regions is
12771fetched from the target (if the current target supports this), but the
12772user can override the fetched regions.
12773
12774Defined memory regions can be individually enabled and disabled.  When a
12775memory region is disabled, @value{GDBN} uses the default attributes when
12776accessing memory in that region.  Similarly, if no memory regions have
12777been defined, @value{GDBN} uses the default attributes when accessing
12778all memory.
12779
12780When a memory region is defined, it is given a number to identify it;
12781to enable, disable, or remove a memory region, you specify that number.
12782
12783@table @code
12784@kindex mem
12785@item mem @var{lower} @var{upper} @var{attributes}@dots{}
12786Define a memory region bounded by @var{lower} and @var{upper} with
12787attributes @var{attributes}@dots{}, and add it to the list of regions
12788monitored by @value{GDBN}.  Note that @var{upper} == 0 is a special
12789case: it is treated as the target's maximum memory address.
12790(0xffff on 16 bit targets, 0xffffffff on 32 bit targets, etc.)
12791
12792@item mem auto
12793Discard any user changes to the memory regions and use target-supplied
12794regions, if available, or no regions if the target does not support.
12795
12796@kindex delete mem
12797@item delete mem @var{nums}@dots{}
12798Remove memory regions @var{nums}@dots{} from the list of regions
12799monitored by @value{GDBN}.
12800
12801@kindex disable mem
12802@item disable mem @var{nums}@dots{}
12803Disable monitoring of memory regions @var{nums}@dots{}.
12804A disabled memory region is not forgotten.
12805It may be enabled again later.
12806
12807@kindex enable mem
12808@item enable mem @var{nums}@dots{}
12809Enable monitoring of memory regions @var{nums}@dots{}.
12810
12811@kindex info mem
12812@item info mem
12813Print a table of all defined memory regions, with the following columns
12814for each region:
12815
12816@table @emph
12817@item Memory Region Number
12818@item Enabled or Disabled.
12819Enabled memory regions are marked with @samp{y}.
12820Disabled memory regions are marked with @samp{n}.
12821
12822@item Lo Address
12823The address defining the inclusive lower bound of the memory region.
12824
12825@item Hi Address
12826The address defining the exclusive upper bound of the memory region.
12827
12828@item Attributes
12829The list of attributes set for this memory region.
12830@end table
12831@end table
12832
12833
12834@subsection Attributes
12835
12836@subsubsection Memory Access Mode
12837The access mode attributes set whether @value{GDBN} may make read or
12838write accesses to a memory region.
12839
12840While these attributes prevent @value{GDBN} from performing invalid
12841memory accesses, they do nothing to prevent the target system, I/O DMA,
12842etc.@: from accessing memory.
12843
12844@table @code
12845@item ro
12846Memory is read only.
12847@item wo
12848Memory is write only.
12849@item rw
12850Memory is read/write.  This is the default.
12851@end table
12852
12853@subsubsection Memory Access Size
12854The access size attribute tells @value{GDBN} to use specific sized
12855accesses in the memory region.  Often memory mapped device registers
12856require specific sized accesses.  If no access size attribute is
12857specified, @value{GDBN} may use accesses of any size.
12858
12859@table @code
12860@item 8
12861Use 8 bit memory accesses.
12862@item 16
12863Use 16 bit memory accesses.
12864@item 32
12865Use 32 bit memory accesses.
12866@item 64
12867Use 64 bit memory accesses.
12868@end table
12869
12870@c @subsubsection Hardware/Software Breakpoints
12871@c The hardware/software breakpoint attributes set whether @value{GDBN}
12872@c will use hardware or software breakpoints for the internal breakpoints
12873@c used by the step, next, finish, until, etc. commands.
12874@c
12875@c @table @code
12876@c @item hwbreak
12877@c Always use hardware breakpoints
12878@c @item swbreak (default)
12879@c @end table
12880
12881@subsubsection Data Cache
12882The data cache attributes set whether @value{GDBN} will cache target
12883memory.  While this generally improves performance by reducing debug
12884protocol overhead, it can lead to incorrect results because @value{GDBN}
12885does not know about volatile variables or memory mapped device
12886registers.
12887
12888@table @code
12889@item cache
12890Enable @value{GDBN} to cache target memory.
12891@item nocache
12892Disable @value{GDBN} from caching target memory.  This is the default.
12893@end table
12894
12895@subsection Memory Access Checking
12896@value{GDBN} can be instructed to refuse accesses to memory that is
12897not explicitly described.  This can be useful if accessing such
12898regions has undesired effects for a specific target, or to provide
12899better error checking.  The following commands control this behaviour.
12900
12901@table @code
12902@kindex set mem inaccessible-by-default
12903@item set mem inaccessible-by-default [on|off]
12904If @code{on} is specified, make  @value{GDBN} treat memory not
12905explicitly described by the memory ranges as non-existent and refuse accesses
12906to such memory.  The checks are only performed if there's at least one
12907memory range defined.  If @code{off} is specified, make @value{GDBN}
12908treat the memory not explicitly described by the memory ranges as RAM.
12909The default value is @code{on}.
12910@kindex show mem inaccessible-by-default
12911@item show mem inaccessible-by-default
12912Show the current handling of accesses to unknown memory.
12913@end table
12914
12915
12916@c @subsubsection Memory Write Verification
12917@c The memory write verification attributes set whether @value{GDBN}
12918@c will re-reads data after each write to verify the write was successful.
12919@c
12920@c @table @code
12921@c @item verify
12922@c @item noverify (default)
12923@c @end table
12924
12925@node Dump/Restore Files
12926@section Copy Between Memory and a File
12927@cindex dump/restore files
12928@cindex append data to a file
12929@cindex dump data to a file
12930@cindex restore data from a file
12931
12932You can use the commands @code{dump}, @code{append}, and
12933@code{restore} to copy data between target memory and a file.  The
12934@code{dump} and @code{append} commands write data to a file, and the
12935@code{restore} command reads data from a file back into the inferior's
12936memory.  Files may be in binary, Motorola S-record, Intel hex,
12937Tektronix Hex, or Verilog Hex format; however, @value{GDBN} can only
12938append to binary files, and cannot read from Verilog Hex files.
12939
12940@table @code
12941
12942@kindex dump
12943@item dump @r{[}@var{format}@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
12944@itemx dump @r{[}@var{format}@r{]} value @var{filename} @var{expr}
12945Dump the contents of memory from @var{start_addr} to @var{end_addr},
12946or the value of @var{expr}, to @var{filename} in the given format.
12947
12948The @var{format} parameter may be any one of:
12949@table @code
12950@item binary
12951Raw binary form.
12952@item ihex
12953Intel hex format.
12954@item srec
12955Motorola S-record format.
12956@item tekhex
12957Tektronix Hex format.
12958@item verilog
12959Verilog Hex format.
12960@end table
12961
12962@value{GDBN} uses the same definitions of these formats as the
12963@sc{gnu} binary utilities, like @samp{objdump} and @samp{objcopy}.  If
12964@var{format} is omitted, @value{GDBN} dumps the data in raw binary
12965form.
12966
12967@kindex append
12968@item append @r{[}binary@r{]} memory @var{filename} @var{start_addr} @var{end_addr}
12969@itemx append @r{[}binary@r{]} value @var{filename} @var{expr}
12970Append the contents of memory from @var{start_addr} to @var{end_addr},
12971or the value of @var{expr}, to the file @var{filename}, in raw binary form.
12972(@value{GDBN} can only append data to files in raw binary form.)
12973
12974@kindex restore
12975@item restore @var{filename} @r{[}binary@r{]} @var{bias} @var{start} @var{end}
12976Restore the contents of file @var{filename} into memory.  The
12977@code{restore} command can automatically recognize any known @sc{bfd}
12978file format, except for raw binary.  To restore a raw binary file you
12979must specify the optional keyword @code{binary} after the filename.
12980
12981If @var{bias} is non-zero, its value will be added to the addresses
12982contained in the file.  Binary files always start at address zero, so
12983they will be restored at address @var{bias}.  Other bfd files have
12984a built-in location; they will be restored at offset @var{bias}
12985from that location.
12986
12987If @var{start} and/or @var{end} are non-zero, then only data between
12988file offset @var{start} and file offset @var{end} will be restored.
12989These offsets are relative to the addresses in the file, before
12990the @var{bias} argument is applied.
12991
12992@end table
12993
12994@node Core File Generation
12995@section How to Produce a Core File from Your Program
12996@cindex dump core from inferior
12997
12998A @dfn{core file} or @dfn{core dump} is a file that records the memory
12999image of a running process and its process status (register values
13000etc.).  Its primary use is post-mortem debugging of a program that
13001crashed while it ran outside a debugger.  A program that crashes
13002automatically produces a core file, unless this feature is disabled by
13003the user.  @xref{Files}, for information on invoking @value{GDBN} in
13004the post-mortem debugging mode.
13005
13006Occasionally, you may wish to produce a core file of the program you
13007are debugging in order to preserve a snapshot of its state.
13008@value{GDBN} has a special command for that.
13009
13010@table @code
13011@kindex gcore
13012@kindex generate-core-file
13013@item generate-core-file [@var{file}]
13014@itemx gcore [@var{file}]
13015Produce a core dump of the inferior process.  The optional argument
13016@var{file} specifies the file name where to put the core dump.  If not
13017specified, the file name defaults to @file{core.@var{pid}}, where
13018@var{pid} is the inferior process ID.
13019
13020Note that this command is implemented only for some systems (as of
13021this writing, @sc{gnu}/Linux, FreeBSD, Solaris, and S390).
13022
13023On @sc{gnu}/Linux, this command can take into account the value of the
13024file @file{/proc/@var{pid}/coredump_filter} when generating the core
13025dump (@pxref{set use-coredump-filter}), and by default honors the
13026@code{VM_DONTDUMP} flag for mappings where it is present in the file
13027@file{/proc/@var{pid}/smaps} (@pxref{set dump-excluded-mappings}).
13028
13029@kindex set use-coredump-filter
13030@anchor{set use-coredump-filter}
13031@item set use-coredump-filter on
13032@itemx set use-coredump-filter off
13033Enable or disable the use of the file
13034@file{/proc/@var{pid}/coredump_filter} when generating core dump
13035files.  This file is used by the Linux kernel to decide what types of
13036memory mappings will be dumped or ignored when generating a core dump
13037file.  @var{pid} is the process ID of a currently running process.
13038
13039To make use of this feature, you have to write in the
13040@file{/proc/@var{pid}/coredump_filter} file a value, in hexadecimal,
13041which is a bit mask representing the memory mapping types.  If a bit
13042is set in the bit mask, then the memory mappings of the corresponding
13043types will be dumped; otherwise, they will be ignored.  This
13044configuration is inherited by child processes.  For more information
13045about the bits that can be set in the
13046@file{/proc/@var{pid}/coredump_filter} file, please refer to the
13047manpage of @code{core(5)}.
13048
13049By default, this option is @code{on}.  If this option is turned
13050@code{off}, @value{GDBN} does not read the @file{coredump_filter} file
13051and instead uses the same default value as the Linux kernel in order
13052to decide which pages will be dumped in the core dump file.  This
13053value is currently @code{0x33}, which means that bits @code{0}
13054(anonymous private mappings), @code{1} (anonymous shared mappings),
13055@code{4} (ELF headers) and @code{5} (private huge pages) are active.
13056This will cause these memory mappings to be dumped automatically.
13057
13058@kindex set dump-excluded-mappings
13059@anchor{set dump-excluded-mappings}
13060@item set dump-excluded-mappings on
13061@itemx set dump-excluded-mappings off
13062If @code{on} is specified, @value{GDBN} will dump memory mappings
13063marked with the @code{VM_DONTDUMP} flag.  This flag is represented in
13064the file @file{/proc/@var{pid}/smaps} with the acronym @code{dd}.
13065
13066The default value is @code{off}.
13067@end table
13068
13069@node Character Sets
13070@section Character Sets
13071@cindex character sets
13072@cindex charset
13073@cindex translating between character sets
13074@cindex host character set
13075@cindex target character set
13076
13077If the program you are debugging uses a different character set to
13078represent characters and strings than the one @value{GDBN} uses itself,
13079@value{GDBN} can automatically translate between the character sets for
13080you.  The character set @value{GDBN} uses we call the @dfn{host
13081character set}; the one the inferior program uses we call the
13082@dfn{target character set}.
13083
13084For example, if you are running @value{GDBN} on a @sc{gnu}/Linux system, which
13085uses the ISO Latin 1 character set, but you are using @value{GDBN}'s
13086remote protocol (@pxref{Remote Debugging}) to debug a program
13087running on an IBM mainframe, which uses the @sc{ebcdic} character set,
13088then the host character set is Latin-1, and the target character set is
13089@sc{ebcdic}.  If you give @value{GDBN} the command @code{set
13090target-charset EBCDIC-US}, then @value{GDBN} translates between
13091@sc{ebcdic} and Latin 1 as you print character or string values, or use
13092character and string literals in expressions.
13093
13094@value{GDBN} has no way to automatically recognize which character set
13095the inferior program uses; you must tell it, using the @code{set
13096target-charset} command, described below.
13097
13098Here are the commands for controlling @value{GDBN}'s character set
13099support:
13100
13101@table @code
13102@item set target-charset @var{charset}
13103@kindex set target-charset
13104Set the current target character set to @var{charset}.  To display the
13105list of supported target character sets, type
13106@kbd{@w{set target-charset @key{TAB}@key{TAB}}}.
13107
13108@item set host-charset @var{charset}
13109@kindex set host-charset
13110Set the current host character set to @var{charset}.
13111
13112By default, @value{GDBN} uses a host character set appropriate to the
13113system it is running on; you can override that default using the
13114@code{set host-charset} command.  On some systems, @value{GDBN} cannot
13115automatically determine the appropriate host character set.  In this
13116case, @value{GDBN} uses @samp{UTF-8}.
13117
13118@value{GDBN} can only use certain character sets as its host character
13119set.  If you type @kbd{@w{set host-charset @key{TAB}@key{TAB}}},
13120@value{GDBN} will list the host character sets it supports.
13121
13122@item set charset @var{charset}
13123@kindex set charset
13124Set the current host and target character sets to @var{charset}.  As
13125above, if you type @kbd{@w{set charset @key{TAB}@key{TAB}}},
13126@value{GDBN} will list the names of the character sets that can be used
13127for both host and target.
13128
13129@item show charset
13130@kindex show charset
13131Show the names of the current host and target character sets.
13132
13133@item show host-charset
13134@kindex show host-charset
13135Show the name of the current host character set.
13136
13137@item show target-charset
13138@kindex show target-charset
13139Show the name of the current target character set.
13140
13141@item set target-wide-charset @var{charset}
13142@kindex set target-wide-charset
13143Set the current target's wide character set to @var{charset}.  This is
13144the character set used by the target's @code{wchar_t} type.  To
13145display the list of supported wide character sets, type
13146@kbd{@w{set target-wide-charset @key{TAB}@key{TAB}}}.
13147
13148@item show target-wide-charset
13149@kindex show target-wide-charset
13150Show the name of the current target's wide character set.
13151@end table
13152
13153Here is an example of @value{GDBN}'s character set support in action.
13154Assume that the following source code has been placed in the file
13155@file{charset-test.c}:
13156
13157@smallexample
13158#include <stdio.h>
13159
13160char ascii_hello[]
13161  = @{72, 101, 108, 108, 111, 44, 32, 119,
13162     111, 114, 108, 100, 33, 10, 0@};
13163char ibm1047_hello[]
13164  = @{200, 133, 147, 147, 150, 107, 64, 166,
13165     150, 153, 147, 132, 90, 37, 0@};
13166
13167main ()
13168@{
13169  printf ("Hello, world!\n");
13170@}
13171@end smallexample
13172
13173In this program, @code{ascii_hello} and @code{ibm1047_hello} are arrays
13174containing the string @samp{Hello, world!} followed by a newline,
13175encoded in the @sc{ascii} and @sc{ibm1047} character sets.
13176
13177We compile the program, and invoke the debugger on it:
13178
13179@smallexample
13180$ gcc -g charset-test.c -o charset-test
13181$ gdb -nw charset-test
13182GNU gdb 2001-12-19-cvs
13183Copyright 2001 Free Software Foundation, Inc.
13184@dots{}
13185(@value{GDBP})
13186@end smallexample
13187
13188We can use the @code{show charset} command to see what character sets
13189@value{GDBN} is currently using to interpret and display characters and
13190strings:
13191
13192@smallexample
13193(@value{GDBP}) show charset
13194The current host and target character set is `ISO-8859-1'.
13195(@value{GDBP})
13196@end smallexample
13197
13198For the sake of printing this manual, let's use @sc{ascii} as our
13199initial character set:
13200@smallexample
13201(@value{GDBP}) set charset ASCII
13202(@value{GDBP}) show charset
13203The current host and target character set is `ASCII'.
13204(@value{GDBP})
13205@end smallexample
13206
13207Let's assume that @sc{ascii} is indeed the correct character set for our
13208host system --- in other words, let's assume that if @value{GDBN} prints
13209characters using the @sc{ascii} character set, our terminal will display
13210them properly.  Since our current target character set is also
13211@sc{ascii}, the contents of @code{ascii_hello} print legibly:
13212
13213@smallexample
13214(@value{GDBP}) print ascii_hello
13215$1 = 0x401698 "Hello, world!\n"
13216(@value{GDBP}) print ascii_hello[0]
13217$2 = 72 'H'
13218(@value{GDBP})
13219@end smallexample
13220
13221@value{GDBN} uses the target character set for character and string
13222literals you use in expressions:
13223
13224@smallexample
13225(@value{GDBP}) print '+'
13226$3 = 43 '+'
13227(@value{GDBP})
13228@end smallexample
13229
13230The @sc{ascii} character set uses the number 43 to encode the @samp{+}
13231character.
13232
13233@value{GDBN} relies on the user to tell it which character set the
13234target program uses.  If we print @code{ibm1047_hello} while our target
13235character set is still @sc{ascii}, we get jibberish:
13236
13237@smallexample
13238(@value{GDBP}) print ibm1047_hello
13239$4 = 0x4016a8 "\310\205\223\223\226k@@\246\226\231\223\204Z%"
13240(@value{GDBP}) print ibm1047_hello[0]
13241$5 = 200 '\310'
13242(@value{GDBP})
13243@end smallexample
13244
13245If we invoke the @code{set target-charset} followed by @key{TAB}@key{TAB},
13246@value{GDBN} tells us the character sets it supports:
13247
13248@smallexample
13249(@value{GDBP}) set target-charset
13250ASCII       EBCDIC-US   IBM1047     ISO-8859-1
13251(@value{GDBP}) set target-charset
13252@end smallexample
13253
13254We can select @sc{ibm1047} as our target character set, and examine the
13255program's strings again.  Now the @sc{ascii} string is wrong, but
13256@value{GDBN} translates the contents of @code{ibm1047_hello} from the
13257target character set, @sc{ibm1047}, to the host character set,
13258@sc{ascii}, and they display correctly:
13259
13260@smallexample
13261(@value{GDBP}) set target-charset IBM1047
13262(@value{GDBP}) show charset
13263The current host character set is `ASCII'.
13264The current target character set is `IBM1047'.
13265(@value{GDBP}) print ascii_hello
13266$6 = 0x401698 "\110\145%%?\054\040\167?\162%\144\041\012"
13267(@value{GDBP}) print ascii_hello[0]
13268$7 = 72 '\110'
13269(@value{GDBP}) print ibm1047_hello
13270$8 = 0x4016a8 "Hello, world!\n"
13271(@value{GDBP}) print ibm1047_hello[0]
13272$9 = 200 'H'
13273(@value{GDBP})
13274@end smallexample
13275
13276As above, @value{GDBN} uses the target character set for character and
13277string literals you use in expressions:
13278
13279@smallexample
13280(@value{GDBP}) print '+'
13281$10 = 78 '+'
13282(@value{GDBP})
13283@end smallexample
13284
13285The @sc{ibm1047} character set uses the number 78 to encode the @samp{+}
13286character.
13287
13288@node Caching Target Data
13289@section Caching Data of Targets
13290@cindex caching data of targets
13291
13292@value{GDBN} caches data exchanged between the debugger and a target.
13293Each cache is associated with the address space of the inferior.
13294@xref{Inferiors Connections and Programs}, about inferior and address space.
13295Such caching generally improves performance in remote debugging
13296(@pxref{Remote Debugging}), because it reduces the overhead of the
13297remote protocol by bundling memory reads and writes into large chunks.
13298Unfortunately, simply caching everything would lead to incorrect results,
13299since @value{GDBN} does not necessarily know anything about volatile
13300values, memory-mapped I/O addresses, etc.  Furthermore, in non-stop mode
13301(@pxref{Non-Stop Mode}) memory can be changed @emph{while} a gdb command
13302is executing.
13303Therefore, by default, @value{GDBN} only caches data
13304known to be on the stack@footnote{In non-stop mode, it is moderately
13305rare for a running thread to modify the stack of a stopped thread
13306in a way that would interfere with a backtrace, and caching of
13307stack reads provides a significant speed up of remote backtraces.} or
13308in the code segment.
13309Other regions of memory can be explicitly marked as
13310cacheable; @pxref{Memory Region Attributes}.
13311
13312@table @code
13313@kindex set remotecache
13314@item set remotecache on
13315@itemx set remotecache off
13316This option no longer does anything; it exists for compatibility
13317with old scripts.
13318
13319@kindex show remotecache
13320@item show remotecache
13321Show the current state of the obsolete remotecache flag.
13322
13323@kindex set stack-cache
13324@item set stack-cache on
13325@itemx set stack-cache off
13326Enable or disable caching of stack accesses.  When @code{on}, use
13327caching.  By default, this option is @code{on}.
13328
13329@kindex show stack-cache
13330@item show stack-cache
13331Show the current state of data caching for memory accesses.
13332
13333@kindex set code-cache
13334@item set code-cache on
13335@itemx set code-cache off
13336Enable or disable caching of code segment accesses.  When @code{on},
13337use caching.  By default, this option is @code{on}.  This improves
13338performance of disassembly in remote debugging.
13339
13340@kindex show code-cache
13341@item show code-cache
13342Show the current state of target memory cache for code segment
13343accesses.
13344
13345@kindex info dcache
13346@item info dcache @r{[}line@r{]}
13347Print the information about the performance of data cache of the
13348current inferior's address space.  The information displayed
13349includes the dcache width and depth, and for each cache line, its
13350number, address, and how many times it was referenced.  This
13351command is useful for debugging the data cache operation.
13352
13353If a line number is specified, the contents of that line will be
13354printed in hex.
13355
13356@item set dcache size @var{size}
13357@cindex dcache size
13358@kindex set dcache size
13359Set maximum number of entries in dcache (dcache depth above).
13360
13361@item set dcache line-size @var{line-size}
13362@cindex dcache line-size
13363@kindex set dcache line-size
13364Set number of bytes each dcache entry caches (dcache width above).
13365Must be a power of 2.
13366
13367@item show dcache size
13368@kindex show dcache size
13369Show maximum number of dcache entries.  @xref{Caching Target Data, info dcache}.
13370
13371@item show dcache line-size
13372@kindex show dcache line-size
13373Show default size of dcache lines.
13374
13375@end table
13376
13377@node Searching Memory
13378@section Search Memory
13379@cindex searching memory
13380
13381Memory can be searched for a particular sequence of bytes with the
13382@code{find} command.
13383
13384@table @code
13385@kindex find
13386@item find @r{[}/@var{sn}@r{]} @var{start_addr}, +@var{len}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
13387@itemx find @r{[}/@var{sn}@r{]} @var{start_addr}, @var{end_addr}, @var{val1} @r{[}, @var{val2}, @dots{}@r{]}
13388Search memory for the sequence of bytes specified by @var{val1}, @var{val2},
13389etc.  The search begins at address @var{start_addr} and continues for either
13390@var{len} bytes or through to @var{end_addr} inclusive.
13391@end table
13392
13393@var{s} and @var{n} are optional parameters.
13394They may be specified in either order, apart or together.
13395
13396@table @r
13397@item @var{s}, search query size
13398The size of each search query value.
13399
13400@table @code
13401@item b
13402bytes
13403@item h
13404halfwords (two bytes)
13405@item w
13406words (four bytes)
13407@item g
13408giant words (eight bytes)
13409@end table
13410
13411All values are interpreted in the current language.
13412This means, for example, that if the current source language is C/C@t{++}
13413then searching for the string ``hello'' includes the trailing '\0'.
13414The null terminator can be removed from searching by using casts,
13415e.g.: @samp{@{char[5]@}"hello"}.
13416
13417If the value size is not specified, it is taken from the
13418value's type in the current language.
13419This is useful when one wants to specify the search
13420pattern as a mixture of types.
13421Note that this means, for example, that in the case of C-like languages
13422a search for an untyped 0x42 will search for @samp{(int) 0x42}
13423which is typically four bytes.
13424
13425@item @var{n}, maximum number of finds
13426The maximum number of matches to print.  The default is to print all finds.
13427@end table
13428
13429You can use strings as search values.  Quote them with double-quotes
13430 (@code{"}).
13431The string value is copied into the search pattern byte by byte,
13432regardless of the endianness of the target and the size specification.
13433
13434The address of each match found is printed as well as a count of the
13435number of matches found.
13436
13437The address of the last value found is stored in convenience variable
13438@samp{$_}.
13439A count of the number of matches is stored in @samp{$numfound}.
13440
13441For example, if stopped at the @code{printf} in this function:
13442
13443@smallexample
13444void
13445hello ()
13446@{
13447  static char hello[] = "hello-hello";
13448  static struct @{ char c; short s; int i; @}
13449    __attribute__ ((packed)) mixed
13450    = @{ 'c', 0x1234, 0x87654321 @};
13451  printf ("%s\n", hello);
13452@}
13453@end smallexample
13454
13455@noindent
13456you get during debugging:
13457
13458@smallexample
13459(gdb) find &hello[0], +sizeof(hello), "hello"
134600x804956d <hello.1620+6>
134611 pattern found
13462(gdb) find &hello[0], +sizeof(hello), 'h', 'e', 'l', 'l', 'o'
134630x8049567 <hello.1620>
134640x804956d <hello.1620+6>
134652 patterns found.
13466(gdb) find &hello[0], +sizeof(hello), @{char[5]@}"hello"
134670x8049567 <hello.1620>
134680x804956d <hello.1620+6>
134692 patterns found.
13470(gdb) find /b1 &hello[0], +sizeof(hello), 'h', 0x65, 'l'
134710x8049567 <hello.1620>
134721 pattern found
13473(gdb) find &mixed, +sizeof(mixed), (char) 'c', (short) 0x1234, (int) 0x87654321
134740x8049560 <mixed.1625>
134751 pattern found
13476(gdb) print $numfound
13477$1 = 1
13478(gdb) print $_
13479$2 = (void *) 0x8049560
13480@end smallexample
13481
13482@node Value Sizes
13483@section Value Sizes
13484
13485Whenever @value{GDBN} prints a value memory will be allocated within
13486@value{GDBN} to hold the contents of the value.  It is possible in
13487some languages with dynamic typing systems, that an invalid program
13488may indicate a value that is incorrectly large, this in turn may cause
13489@value{GDBN} to try and allocate an overly large amount of memory.
13490
13491@table @code
13492@kindex set max-value-size
13493@item set max-value-size @var{bytes}
13494@itemx set max-value-size unlimited
13495Set the maximum size of memory that @value{GDBN} will allocate for the
13496contents of a value to @var{bytes}, trying to display a value that
13497requires more memory than that will result in an error.
13498
13499Setting this variable does not effect values that have already been
13500allocated within @value{GDBN}, only future allocations.
13501
13502There's a minimum size that @code{max-value-size} can be set to in
13503order that @value{GDBN} can still operate correctly, this minimum is
13504currently 16 bytes.
13505
13506The limit applies to the results of some subexpressions as well as to
13507complete expressions.  For example, an expression denoting a simple
13508integer component, such as @code{x.y.z}, may fail if the size of
13509@var{x.y} is dynamic and exceeds @var{bytes}.  On the other hand,
13510@value{GDBN} is sometimes clever; the expression @code{A[i]}, where
13511@var{A} is an array variable with non-constant size, will generally
13512succeed regardless of the bounds on @var{A}, as long as the component
13513size is less than @var{bytes}.
13514
13515The default value of @code{max-value-size} is currently 64k.
13516
13517@kindex show max-value-size
13518@item show max-value-size
13519Show the maximum size of memory, in bytes, that @value{GDBN} will
13520allocate for the contents of a value.
13521@end table
13522
13523@node Optimized Code
13524@chapter Debugging Optimized Code
13525@cindex optimized code, debugging
13526@cindex debugging optimized code
13527
13528Almost all compilers support optimization.  With optimization
13529disabled, the compiler generates assembly code that corresponds
13530directly to your source code, in a simplistic way.  As the compiler
13531applies more powerful optimizations, the generated assembly code
13532diverges from your original source code.  With help from debugging
13533information generated by the compiler, @value{GDBN} can map from
13534the running program back to constructs from your original source.
13535
13536@value{GDBN} is more accurate with optimization disabled.  If you
13537can recompile without optimization, it is easier to follow the
13538progress of your program during debugging.  But, there are many cases
13539where you may need to debug an optimized version.
13540
13541When you debug a program compiled with @samp{-g -O}, remember that the
13542optimizer has rearranged your code; the debugger shows you what is
13543really there.  Do not be too surprised when the execution path does not
13544exactly match your source file!  An extreme example: if you define a
13545variable, but never use it, @value{GDBN} never sees that
13546variable---because the compiler optimizes it out of existence.
13547
13548Some things do not work as well with @samp{-g -O} as with just
13549@samp{-g}, particularly on machines with instruction scheduling.  If in
13550doubt, recompile with @samp{-g} alone, and if this fixes the problem,
13551please report it to us as a bug (including a test case!).
13552@xref{Variables}, for more information about debugging optimized code.
13553
13554@menu
13555* Inline Functions::            How @value{GDBN} presents inlining
13556* Tail Call Frames::            @value{GDBN} analysis of jumps to functions
13557@end menu
13558
13559@node Inline Functions
13560@section Inline Functions
13561@cindex inline functions, debugging
13562
13563@dfn{Inlining} is an optimization that inserts a copy of the function
13564body directly at each call site, instead of jumping to a shared
13565routine.  @value{GDBN} displays inlined functions just like
13566non-inlined functions.  They appear in backtraces.  You can view their
13567arguments and local variables, step into them with @code{step}, skip
13568them with @code{next}, and escape from them with @code{finish}.
13569You can check whether a function was inlined by using the
13570@code{info frame} command.
13571
13572For @value{GDBN} to support inlined functions, the compiler must
13573record information about inlining in the debug information ---
13574@value{NGCC} using the @sc{dwarf 2} format does this, and several
13575other compilers do also.  @value{GDBN} only supports inlined functions
13576when using @sc{dwarf 2}.  Versions of @value{NGCC} before 4.1
13577do not emit two required attributes (@samp{DW_AT_call_file} and
13578@samp{DW_AT_call_line}); @value{GDBN} does not display inlined
13579function calls with earlier versions of @value{NGCC}.  It instead
13580displays the arguments and local variables of inlined functions as
13581local variables in the caller.
13582
13583The body of an inlined function is directly included at its call site;
13584unlike a non-inlined function, there are no instructions devoted to
13585the call.  @value{GDBN} still pretends that the call site and the
13586start of the inlined function are different instructions.  Stepping to
13587the call site shows the call site, and then stepping again shows
13588the first line of the inlined function, even though no additional
13589instructions are executed.
13590
13591This makes source-level debugging much clearer; you can see both the
13592context of the call and then the effect of the call.  Only stepping by
13593a single instruction using @code{stepi} or @code{nexti} does not do
13594this; single instruction steps always show the inlined body.
13595
13596There are some ways that @value{GDBN} does not pretend that inlined
13597function calls are the same as normal calls:
13598
13599@itemize @bullet
13600@item
13601Setting breakpoints at the call site of an inlined function may not
13602work, because the call site does not contain any code.  @value{GDBN}
13603may incorrectly move the breakpoint to the next line of the enclosing
13604function, after the call.  This limitation will be removed in a future
13605version of @value{GDBN}; until then, set a breakpoint on an earlier line
13606or inside the inlined function instead.
13607
13608@item
13609@value{GDBN} cannot locate the return value of inlined calls after
13610using the @code{finish} command.  This is a limitation of compiler-generated
13611debugging information; after @code{finish}, you can step to the next line
13612and print a variable where your program stored the return value.
13613
13614@end itemize
13615
13616@node Tail Call Frames
13617@section Tail Call Frames
13618@cindex tail call frames, debugging
13619
13620Function @code{B} can call function @code{C} in its very last statement.  In
13621unoptimized compilation the call of @code{C} is immediately followed by return
13622instruction at the end of @code{B} code.  Optimizing compiler may replace the
13623call and return in function @code{B} into one jump to function @code{C}
13624instead.  Such use of a jump instruction is called @dfn{tail call}.
13625
13626During execution of function @code{C}, there will be no indication in the
13627function call stack frames that it was tail-called from @code{B}.  If function
13628@code{A} regularly calls function @code{B} which tail-calls function @code{C},
13629then @value{GDBN} will see @code{A} as the caller of @code{C}.  However, in
13630some cases @value{GDBN} can determine that @code{C} was tail-called from
13631@code{B}, and it will then create fictitious call frame for that, with the
13632return address set up as if @code{B} called @code{C} normally.
13633
13634This functionality is currently supported only by DWARF 2 debugging format and
13635the compiler has to produce @samp{DW_TAG_call_site} tags.  With
13636@value{NGCC}, you need to specify @option{-O -g} during compilation, to get
13637this information.
13638
13639@kbd{info frame} command (@pxref{Frame Info}) will indicate the tail call frame
13640kind by text @code{tail call frame} such as in this sample @value{GDBN} output:
13641
13642@smallexample
13643(gdb) x/i $pc - 2
13644   0x40066b <b(int, double)+11>: jmp 0x400640 <c(int, double)>
13645(gdb) info frame
13646Stack level 1, frame at 0x7fffffffda30:
13647 rip = 0x40066d in b (amd64-entry-value.cc:59); saved rip 0x4004c5
13648 tail call frame, caller of frame at 0x7fffffffda30
13649 source language c++.
13650 Arglist at unknown address.
13651 Locals at unknown address, Previous frame's sp is 0x7fffffffda30
13652@end smallexample
13653
13654The detection of all the possible code path executions can find them ambiguous.
13655There is no execution history stored (possible @ref{Reverse Execution} is never
13656used for this purpose) and the last known caller could have reached the known
13657callee by multiple different jump sequences.  In such case @value{GDBN} still
13658tries to show at least all the unambiguous top tail callers and all the
13659unambiguous bottom tail calees, if any.
13660
13661@table @code
13662@anchor{set debug entry-values}
13663@item set debug entry-values
13664@kindex set debug entry-values
13665When set to on, enables printing of analysis messages for both frame argument
13666values at function entry and tail calls.  It will show all the possible valid
13667tail calls code paths it has considered.  It will also print the intersection
13668of them with the final unambiguous (possibly partial or even empty) code path
13669result.
13670
13671@item show debug entry-values
13672@kindex show debug entry-values
13673Show the current state of analysis messages printing for both frame argument
13674values at function entry and tail calls.
13675@end table
13676
13677The analysis messages for tail calls can for example show why the virtual tail
13678call frame for function @code{c} has not been recognized (due to the indirect
13679reference by variable @code{x}):
13680
13681@smallexample
13682static void __attribute__((noinline, noclone)) c (void);
13683void (*x) (void) = c;
13684static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
13685static void __attribute__((noinline, noclone)) c (void) @{ a (); @}
13686int main (void) @{ x (); return 0; @}
13687
13688Breakpoint 1, DW_OP_entry_value resolving cannot find
13689DW_TAG_call_site 0x40039a in main
13690a () at t.c:3
136913	static void __attribute__((noinline, noclone)) a (void) @{ x++; @}
13692(gdb) bt
13693#0  a () at t.c:3
13694#1  0x000000000040039a in main () at t.c:5
13695@end smallexample
13696
13697Another possibility is an ambiguous virtual tail call frames resolution:
13698
13699@smallexample
13700int i;
13701static void __attribute__((noinline, noclone)) f (void) @{ i++; @}
13702static void __attribute__((noinline, noclone)) e (void) @{ f (); @}
13703static void __attribute__((noinline, noclone)) d (void) @{ f (); @}
13704static void __attribute__((noinline, noclone)) c (void) @{ d (); @}
13705static void __attribute__((noinline, noclone)) b (void)
13706@{ if (i) c (); else e (); @}
13707static void __attribute__((noinline, noclone)) a (void) @{ b (); @}
13708int main (void) @{ a (); return 0; @}
13709
13710tailcall: initial: 0x4004d2(a) 0x4004ce(b) 0x4004b2(c) 0x4004a2(d)
13711tailcall: compare: 0x4004d2(a) 0x4004cc(b) 0x400492(e)
13712tailcall: reduced: 0x4004d2(a) |
13713(gdb) bt
13714#0  f () at t.c:2
13715#1  0x00000000004004d2 in a () at t.c:8
13716#2  0x0000000000400395 in main () at t.c:9
13717@end smallexample
13718
13719@set CALLSEQ1A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}c@value{ARROW}d@value{ARROW}f}
13720@set CALLSEQ2A @code{main@value{ARROW}a@value{ARROW}b@value{ARROW}e@value{ARROW}f}
13721
13722@c Convert CALLSEQ#A to CALLSEQ#B depending on HAVE_MAKEINFO_CLICK.
13723@ifset HAVE_MAKEINFO_CLICK
13724@set ARROW @click{}
13725@set CALLSEQ1B @clicksequence{@value{CALLSEQ1A}}
13726@set CALLSEQ2B @clicksequence{@value{CALLSEQ2A}}
13727@end ifset
13728@ifclear HAVE_MAKEINFO_CLICK
13729@set ARROW ->
13730@set CALLSEQ1B @value{CALLSEQ1A}
13731@set CALLSEQ2B @value{CALLSEQ2A}
13732@end ifclear
13733
13734Frames #0 and #2 are real, #1 is a virtual tail call frame.
13735The code can have possible execution paths @value{CALLSEQ1B} or
13736@value{CALLSEQ2B}, @value{GDBN} cannot find which one from the inferior state.
13737
13738@code{initial:} state shows some random possible calling sequence @value{GDBN}
13739has found.  It then finds another possible calling sequence - that one is
13740prefixed by @code{compare:}.  The non-ambiguous intersection of these two is
13741printed as the @code{reduced:} calling sequence.  That one could have many
13742further @code{compare:} and @code{reduced:} statements as long as there remain
13743any non-ambiguous sequence entries.
13744
13745For the frame of function @code{b} in both cases there are different possible
13746@code{$pc} values (@code{0x4004cc} or @code{0x4004ce}), therefore this frame is
13747also ambiguous.  The only non-ambiguous frame is the one for function @code{a},
13748therefore this one is displayed to the user while the ambiguous frames are
13749omitted.
13750
13751There can be also reasons why printing of frame argument values at function
13752entry may fail:
13753
13754@smallexample
13755int v;
13756static void __attribute__((noinline, noclone)) c (int i) @{ v++; @}
13757static void __attribute__((noinline, noclone)) a (int i);
13758static void __attribute__((noinline, noclone)) b (int i) @{ a (i); @}
13759static void __attribute__((noinline, noclone)) a (int i)
13760@{ if (i) b (i - 1); else c (0); @}
13761int main (void) @{ a (5); return 0; @}
13762
13763(gdb) bt
13764#0  c (i=i@@entry=0) at t.c:2
13765#1  0x0000000000400428 in a (DW_OP_entry_value resolving has found
13766function "a" at 0x400420 can call itself via tail calls
13767i=<optimized out>) at t.c:6
13768#2  0x000000000040036e in main () at t.c:7
13769@end smallexample
13770
13771@value{GDBN} cannot find out from the inferior state if and how many times did
13772function @code{a} call itself (via function @code{b}) as these calls would be
13773tail calls.  Such tail calls would modify the @code{i} variable, therefore
13774@value{GDBN} cannot be sure the value it knows would be right - @value{GDBN}
13775prints @code{<optimized out>} instead.
13776
13777@node Macros
13778@chapter C Preprocessor Macros
13779
13780Some languages, such as C and C@t{++}, provide a way to define and invoke
13781``preprocessor macros'' which expand into strings of tokens.
13782@value{GDBN} can evaluate expressions containing macro invocations, show
13783the result of macro expansion, and show a macro's definition, including
13784where it was defined.
13785
13786You may need to compile your program specially to provide @value{GDBN}
13787with information about preprocessor macros.  Most compilers do not
13788include macros in their debugging information, even when you compile
13789with the @option{-g} flag.  @xref{Compilation}.
13790
13791A program may define a macro at one point, remove that definition later,
13792and then provide a different definition after that.  Thus, at different
13793points in the program, a macro may have different definitions, or have
13794no definition at all.  If there is a current stack frame, @value{GDBN}
13795uses the macros in scope at that frame's source code line.  Otherwise,
13796@value{GDBN} uses the macros in scope at the current listing location;
13797see @ref{List}.
13798
13799Whenever @value{GDBN} evaluates an expression, it always expands any
13800macro invocations present in the expression.  @value{GDBN} also provides
13801the following commands for working with macros explicitly.
13802
13803@table @code
13804
13805@kindex macro expand
13806@cindex macro expansion, showing the results of preprocessor
13807@cindex preprocessor macro expansion, showing the results of
13808@cindex expanding preprocessor macros
13809@item macro expand @var{expression}
13810@itemx macro exp @var{expression}
13811Show the results of expanding all preprocessor macro invocations in
13812@var{expression}.  Since @value{GDBN} simply expands macros, but does
13813not parse the result, @var{expression} need not be a valid expression;
13814it can be any string of tokens.
13815
13816@kindex macro exp1
13817@item macro expand-once @var{expression}
13818@itemx macro exp1 @var{expression}
13819@cindex expand macro once
13820@i{(This command is not yet implemented.)}  Show the results of
13821expanding those preprocessor macro invocations that appear explicitly in
13822@var{expression}.  Macro invocations appearing in that expansion are
13823left unchanged.  This command allows you to see the effect of a
13824particular macro more clearly, without being confused by further
13825expansions.  Since @value{GDBN} simply expands macros, but does not
13826parse the result, @var{expression} need not be a valid expression; it
13827can be any string of tokens.
13828
13829@kindex info macro
13830@cindex macro definition, showing
13831@cindex definition of a macro, showing
13832@cindex macros, from debug info
13833@item info macro [-a|-all] [--] @var{macro}
13834Show the current definition or all definitions of the named @var{macro},
13835and describe the source location or compiler command-line where that
13836definition was established.  The optional double dash is to signify the end of
13837argument processing and the beginning of @var{macro} for non C-like macros where
13838the macro may begin with a hyphen.
13839
13840@kindex info macros
13841@item info macros @var{location}
13842Show all macro definitions that are in effect at the location specified
13843by @var{location},  and describe the source location or compiler
13844command-line where those definitions were established.
13845
13846@kindex macro define
13847@cindex user-defined macros
13848@cindex defining macros interactively
13849@cindex macros, user-defined
13850@item macro define @var{macro} @var{replacement-list}
13851@itemx macro define @var{macro}(@var{arglist}) @var{replacement-list}
13852Introduce a definition for a preprocessor macro named @var{macro},
13853invocations of which are replaced by the tokens given in
13854@var{replacement-list}.  The first form of this command defines an
13855``object-like'' macro, which takes no arguments; the second form
13856defines a ``function-like'' macro, which takes the arguments given in
13857@var{arglist}.
13858
13859A definition introduced by this command is in scope in every
13860expression evaluated in @value{GDBN}, until it is removed with the
13861@code{macro undef} command, described below.  The definition overrides
13862all definitions for @var{macro} present in the program being debugged,
13863as well as any previous user-supplied definition.
13864
13865@kindex macro undef
13866@item macro undef @var{macro}
13867Remove any user-supplied definition for the macro named @var{macro}.
13868This command only affects definitions provided with the @code{macro
13869define} command, described above; it cannot remove definitions present
13870in the program being debugged.
13871
13872@kindex macro list
13873@item macro list
13874List all the macros defined using the @code{macro define} command.
13875@end table
13876
13877@cindex macros, example of debugging with
13878Here is a transcript showing the above commands in action.  First, we
13879show our source files:
13880
13881@smallexample
13882$ cat sample.c
13883#include <stdio.h>
13884#include "sample.h"
13885
13886#define M 42
13887#define ADD(x) (M + x)
13888
13889main ()
13890@{
13891#define N 28
13892  printf ("Hello, world!\n");
13893#undef N
13894  printf ("We're so creative.\n");
13895#define N 1729
13896  printf ("Goodbye, world!\n");
13897@}
13898$ cat sample.h
13899#define Q <
13900$
13901@end smallexample
13902
13903Now, we compile the program using the @sc{gnu} C compiler,
13904@value{NGCC}.  We pass the @option{-gdwarf-2}@footnote{This is the
13905minimum.  Recent versions of @value{NGCC} support @option{-gdwarf-3}
13906and @option{-gdwarf-4}; we recommend always choosing the most recent
13907version of DWARF.} @emph{and} @option{-g3} flags to ensure the compiler
13908includes information about preprocessor macros in the debugging
13909information.
13910
13911@smallexample
13912$ gcc -gdwarf-2 -g3 sample.c -o sample
13913$
13914@end smallexample
13915
13916Now, we start @value{GDBN} on our sample program:
13917
13918@smallexample
13919$ gdb -nw sample
13920GNU gdb 2002-05-06-cvs
13921Copyright 2002 Free Software Foundation, Inc.
13922GDB is free software, @dots{}
13923(@value{GDBP})
13924@end smallexample
13925
13926We can expand macros and examine their definitions, even when the
13927program is not running.  @value{GDBN} uses the current listing position
13928to decide which macro definitions are in scope:
13929
13930@smallexample
13931(@value{GDBP}) list main
139323
139334       #define M 42
139345       #define ADD(x) (M + x)
139356
139367       main ()
139378       @{
139389       #define N 28
1393910        printf ("Hello, world!\n");
1394011      #undef N
1394112        printf ("We're so creative.\n");
13942(@value{GDBP}) info macro ADD
13943Defined at /home/jimb/gdb/macros/play/sample.c:5
13944#define ADD(x) (M + x)
13945(@value{GDBP}) info macro Q
13946Defined at /home/jimb/gdb/macros/play/sample.h:1
13947  included at /home/jimb/gdb/macros/play/sample.c:2
13948#define Q <
13949(@value{GDBP}) macro expand ADD(1)
13950expands to: (42 + 1)
13951(@value{GDBP}) macro expand-once ADD(1)
13952expands to: once (M + 1)
13953(@value{GDBP})
13954@end smallexample
13955
13956In the example above, note that @code{macro expand-once} expands only
13957the macro invocation explicit in the original text --- the invocation of
13958@code{ADD} --- but does not expand the invocation of the macro @code{M},
13959which was introduced by @code{ADD}.
13960
13961Once the program is running, @value{GDBN} uses the macro definitions in
13962force at the source line of the current stack frame:
13963
13964@smallexample
13965(@value{GDBP}) break main
13966Breakpoint 1 at 0x8048370: file sample.c, line 10.
13967(@value{GDBP}) run
13968Starting program: /home/jimb/gdb/macros/play/sample
13969
13970Breakpoint 1, main () at sample.c:10
1397110        printf ("Hello, world!\n");
13972(@value{GDBP})
13973@end smallexample
13974
13975At line 10, the definition of the macro @code{N} at line 9 is in force:
13976
13977@smallexample
13978(@value{GDBP}) info macro N
13979Defined at /home/jimb/gdb/macros/play/sample.c:9
13980#define N 28
13981(@value{GDBP}) macro expand N Q M
13982expands to: 28 < 42
13983(@value{GDBP}) print N Q M
13984$1 = 1
13985(@value{GDBP})
13986@end smallexample
13987
13988As we step over directives that remove @code{N}'s definition, and then
13989give it a new definition, @value{GDBN} finds the definition (or lack
13990thereof) in force at each point:
13991
13992@smallexample
13993(@value{GDBP}) next
13994Hello, world!
1399512        printf ("We're so creative.\n");
13996(@value{GDBP}) info macro N
13997The symbol `N' has no definition as a C/C++ preprocessor macro
13998at /home/jimb/gdb/macros/play/sample.c:12
13999(@value{GDBP}) next
14000We're so creative.
1400114        printf ("Goodbye, world!\n");
14002(@value{GDBP}) info macro N
14003Defined at /home/jimb/gdb/macros/play/sample.c:13
14004#define N 1729
14005(@value{GDBP}) macro expand N Q M
14006expands to: 1729 < 42
14007(@value{GDBP}) print N Q M
14008$2 = 0
14009(@value{GDBP})
14010@end smallexample
14011
14012In addition to source files, macros can be defined on the compilation command
14013line using the @option{-D@var{name}=@var{value}} syntax.  For macros defined in
14014such a way, @value{GDBN} displays the location of their definition as line zero
14015of the source file submitted to the compiler.
14016
14017@smallexample
14018(@value{GDBP}) info macro __STDC__
14019Defined at /home/jimb/gdb/macros/play/sample.c:0
14020-D__STDC__=1
14021(@value{GDBP})
14022@end smallexample
14023
14024
14025@node Tracepoints
14026@chapter Tracepoints
14027@c This chapter is based on the documentation written by Michael
14028@c Snyder, David Taylor, Jim Blandy, and Elena Zannoni.
14029
14030@cindex tracepoints
14031In some applications, it is not feasible for the debugger to interrupt
14032the program's execution long enough for the developer to learn
14033anything helpful about its behavior.  If the program's correctness
14034depends on its real-time behavior, delays introduced by a debugger
14035might cause the program to change its behavior drastically, or perhaps
14036fail, even when the code itself is correct.  It is useful to be able
14037to observe the program's behavior without interrupting it.
14038
14039Using @value{GDBN}'s @code{trace} and @code{collect} commands, you can
14040specify locations in the program, called @dfn{tracepoints}, and
14041arbitrary expressions to evaluate when those tracepoints are reached.
14042Later, using the @code{tfind} command, you can examine the values
14043those expressions had when the program hit the tracepoints.  The
14044expressions may also denote objects in memory---structures or arrays,
14045for example---whose values @value{GDBN} should record; while visiting
14046a particular tracepoint, you may inspect those objects as if they were
14047in memory at that moment.  However, because @value{GDBN} records these
14048values without interacting with you, it can do so quickly and
14049unobtrusively, hopefully not disturbing the program's behavior.
14050
14051The tracepoint facility is currently available only for remote
14052targets.  @xref{Targets}.  In addition, your remote target must know
14053how to collect trace data.  This functionality is implemented in the
14054remote stub; however, none of the stubs distributed with @value{GDBN}
14055support tracepoints as of this writing.  The format of the remote
14056packets used to implement tracepoints are described in @ref{Tracepoint
14057Packets}.
14058
14059It is also possible to get trace data from a file, in a manner reminiscent
14060of corefiles; you specify the filename, and use @code{tfind} to search
14061through the file.  @xref{Trace Files}, for more details.
14062
14063This chapter describes the tracepoint commands and features.
14064
14065@menu
14066* Set Tracepoints::
14067* Analyze Collected Data::
14068* Tracepoint Variables::
14069* Trace Files::
14070@end menu
14071
14072@node Set Tracepoints
14073@section Commands to Set Tracepoints
14074
14075Before running such a @dfn{trace experiment}, an arbitrary number of
14076tracepoints can be set.  A tracepoint is actually a special type of
14077breakpoint (@pxref{Set Breaks}), so you can manipulate it using
14078standard breakpoint commands.  For instance, as with breakpoints,
14079tracepoint numbers are successive integers starting from one, and many
14080of the commands associated with tracepoints take the tracepoint number
14081as their argument, to identify which tracepoint to work on.
14082
14083For each tracepoint, you can specify, in advance, some arbitrary set
14084of data that you want the target to collect in the trace buffer when
14085it hits that tracepoint.  The collected data can include registers,
14086local variables, or global data.  Later, you can use @value{GDBN}
14087commands to examine the values these data had at the time the
14088tracepoint was hit.
14089
14090Tracepoints do not support every breakpoint feature.  Ignore counts on
14091tracepoints have no effect, and tracepoints cannot run @value{GDBN}
14092commands when they are hit.  Tracepoints may not be thread-specific
14093either.
14094
14095@cindex fast tracepoints
14096Some targets may support @dfn{fast tracepoints}, which are inserted in
14097a different way (such as with a jump instead of a trap), that is
14098faster but possibly restricted in where they may be installed.
14099
14100@cindex static tracepoints
14101@cindex markers, static tracepoints
14102@cindex probing markers, static tracepoints
14103Regular and fast tracepoints are dynamic tracing facilities, meaning
14104that they can be used to insert tracepoints at (almost) any location
14105in the target.  Some targets may also support controlling @dfn{static
14106tracepoints} from @value{GDBN}.  With static tracing, a set of
14107instrumentation points, also known as @dfn{markers}, are embedded in
14108the target program, and can be activated or deactivated by name or
14109address.  These are usually placed at locations which facilitate
14110investigating what the target is actually doing.  @value{GDBN}'s
14111support for static tracing includes being able to list instrumentation
14112points, and attach them with @value{GDBN} defined high level
14113tracepoints that expose the whole range of convenience of
14114@value{GDBN}'s tracepoints support.  Namely, support for collecting
14115registers values and values of global or local (to the instrumentation
14116point) variables; tracepoint conditions and trace state variables.
14117The act of installing a @value{GDBN} static tracepoint on an
14118instrumentation point, or marker, is referred to as @dfn{probing} a
14119static tracepoint marker.
14120
14121@code{gdbserver} supports tracepoints on some target systems.
14122@xref{Server,,Tracepoints support in @code{gdbserver}}.
14123
14124This section describes commands to set tracepoints and associated
14125conditions and actions.
14126
14127@menu
14128* Create and Delete Tracepoints::
14129* Enable and Disable Tracepoints::
14130* Tracepoint Passcounts::
14131* Tracepoint Conditions::
14132* Trace State Variables::
14133* Tracepoint Actions::
14134* Listing Tracepoints::
14135* Listing Static Tracepoint Markers::
14136* Starting and Stopping Trace Experiments::
14137* Tracepoint Restrictions::
14138@end menu
14139
14140@node Create and Delete Tracepoints
14141@subsection Create and Delete Tracepoints
14142
14143@table @code
14144@cindex set tracepoint
14145@kindex trace
14146@item trace @var{location}
14147The @code{trace} command is very similar to the @code{break} command.
14148Its argument @var{location} can be any valid location.
14149@xref{Specify Location}.  The @code{trace} command defines a tracepoint,
14150which is a point in the target program where the debugger will briefly stop,
14151collect some data, and then allow the program to continue.  Setting a tracepoint
14152or changing its actions takes effect immediately if the remote stub
14153supports the @samp{InstallInTrace} feature (@pxref{install tracepoint
14154in tracing}).
14155If remote stub doesn't support the @samp{InstallInTrace} feature, all
14156these changes don't take effect until the next @code{tstart}
14157command, and once a trace experiment is running, further changes will
14158not have any effect until the next trace experiment starts.  In addition,
14159@value{GDBN} supports @dfn{pending tracepoints}---tracepoints whose
14160address is not yet resolved.  (This is similar to pending breakpoints.)
14161Pending tracepoints are not downloaded to the target and not installed
14162until they are resolved.  The resolution of pending tracepoints requires
14163@value{GDBN} support---when debugging with the remote target, and
14164@value{GDBN} disconnects from the remote stub (@pxref{disconnected
14165tracing}), pending tracepoints can not be resolved (and downloaded to
14166the remote stub) while @value{GDBN} is disconnected.
14167
14168Here are some examples of using the @code{trace} command:
14169
14170@smallexample
14171(@value{GDBP}) @b{trace foo.c:121}    // a source file and line number
14172
14173(@value{GDBP}) @b{trace +2}           // 2 lines forward
14174
14175(@value{GDBP}) @b{trace my_function}  // first source line of function
14176
14177(@value{GDBP}) @b{trace *my_function} // EXACT start address of function
14178
14179(@value{GDBP}) @b{trace *0x2117c4}    // an address
14180@end smallexample
14181
14182@noindent
14183You can abbreviate @code{trace} as @code{tr}.
14184
14185@item trace @var{location} if @var{cond}
14186Set a tracepoint with condition @var{cond}; evaluate the expression
14187@var{cond} each time the tracepoint is reached, and collect data only
14188if the value is nonzero---that is, if @var{cond} evaluates as true.
14189@xref{Tracepoint Conditions, ,Tracepoint Conditions}, for more
14190information on tracepoint conditions.
14191
14192@item ftrace @var{location} [ if @var{cond} ]
14193@cindex set fast tracepoint
14194@cindex fast tracepoints, setting
14195@kindex ftrace
14196The @code{ftrace} command sets a fast tracepoint.  For targets that
14197support them, fast tracepoints will use a more efficient but possibly
14198less general technique to trigger data collection, such as a jump
14199instruction instead of a trap, or some sort of hardware support.  It
14200may not be possible to create a fast tracepoint at the desired
14201location, in which case the command will exit with an explanatory
14202message.
14203
14204@value{GDBN} handles arguments to @code{ftrace} exactly as for
14205@code{trace}.
14206
14207On 32-bit x86-architecture systems, fast tracepoints normally need to
14208be placed at an instruction that is 5 bytes or longer, but can be
14209placed at 4-byte instructions if the low 64K of memory of the target
14210program is available to install trampolines.  Some Unix-type systems,
14211such as @sc{gnu}/Linux, exclude low addresses from the program's
14212address space; but for instance with the Linux kernel it is possible
14213to let @value{GDBN} use this area by doing a @command{sysctl} command
14214to set the @code{mmap_min_addr} kernel parameter, as in
14215
14216@example
14217sudo sysctl -w vm.mmap_min_addr=32768
14218@end example
14219
14220@noindent
14221which sets the low address to 32K, which leaves plenty of room for
14222trampolines.  The minimum address should be set to a page boundary.
14223
14224@item strace @var{location} [ if @var{cond} ]
14225@cindex set static tracepoint
14226@cindex static tracepoints, setting
14227@cindex probe static tracepoint marker
14228@kindex strace
14229The @code{strace} command sets a static tracepoint.  For targets that
14230support it, setting a static tracepoint probes a static
14231instrumentation point, or marker, found at @var{location}.  It may not
14232be possible to set a static tracepoint at the desired location, in
14233which case the command will exit with an explanatory message.
14234
14235@value{GDBN} handles arguments to @code{strace} exactly as for
14236@code{trace}, with the addition that the user can also specify
14237@code{-m @var{marker}} as @var{location}.  This probes the marker
14238identified by the @var{marker} string identifier.  This identifier
14239depends on the static tracepoint backend library your program is
14240using.  You can find all the marker identifiers in the @samp{ID} field
14241of the @code{info static-tracepoint-markers} command output.
14242@xref{Listing Static Tracepoint Markers,,Listing Static Tracepoint
14243Markers}.  For example, in the following small program using the UST
14244tracing engine:
14245
14246@smallexample
14247main ()
14248@{
14249  trace_mark(ust, bar33, "str %s", "FOOBAZ");
14250@}
14251@end smallexample
14252
14253@noindent
14254the marker id is composed of joining the first two arguments to the
14255@code{trace_mark} call with a slash, which translates to:
14256
14257@smallexample
14258(@value{GDBP}) info static-tracepoint-markers
14259Cnt Enb ID         Address            What
142601   n   ust/bar33  0x0000000000400ddc in main at stexample.c:22
14261         Data: "str %s"
14262[etc...]
14263@end smallexample
14264
14265@noindent
14266so you may probe the marker above with:
14267
14268@smallexample
14269(@value{GDBP}) strace -m ust/bar33
14270@end smallexample
14271
14272Static tracepoints accept an extra collect action --- @code{collect
14273$_sdata}.  This collects arbitrary user data passed in the probe point
14274call to the tracing library.  In the UST example above, you'll see
14275that the third argument to @code{trace_mark} is a printf-like format
14276string.  The user data is then the result of running that formatting
14277string against the following arguments.  Note that @code{info
14278static-tracepoint-markers} command output lists that format string in
14279the @samp{Data:} field.
14280
14281You can inspect this data when analyzing the trace buffer, by printing
14282the $_sdata variable like any other variable available to
14283@value{GDBN}.  @xref{Tracepoint Actions,,Tracepoint Action Lists}.
14284
14285@vindex $tpnum
14286@cindex last tracepoint number
14287@cindex recent tracepoint number
14288@cindex tracepoint number
14289The convenience variable @code{$tpnum} records the tracepoint number
14290of the most recently set tracepoint.
14291
14292@kindex delete tracepoint
14293@cindex tracepoint deletion
14294@item delete tracepoint @r{[}@var{num}@r{]}
14295Permanently delete one or more tracepoints.  With no argument, the
14296default is to delete all tracepoints.  Note that the regular
14297@code{delete} command can remove tracepoints also.
14298
14299Examples:
14300
14301@smallexample
14302(@value{GDBP}) @b{delete trace 1 2 3} // remove three tracepoints
14303
14304(@value{GDBP}) @b{delete trace}       // remove all tracepoints
14305@end smallexample
14306
14307@noindent
14308You can abbreviate this command as @code{del tr}.
14309@end table
14310
14311@node Enable and Disable Tracepoints
14312@subsection Enable and Disable Tracepoints
14313
14314These commands are deprecated; they are equivalent to plain @code{disable} and @code{enable}.
14315
14316@table @code
14317@kindex disable tracepoint
14318@item disable tracepoint @r{[}@var{num}@r{]}
14319Disable tracepoint @var{num}, or all tracepoints if no argument
14320@var{num} is given.  A disabled tracepoint will have no effect during
14321a trace experiment, but it is not forgotten.  You can re-enable
14322a disabled tracepoint using the @code{enable tracepoint} command.
14323If the command is issued during a trace experiment and the debug target
14324has support for disabling tracepoints during a trace experiment, then the
14325change will be effective immediately.  Otherwise, it will be applied to the
14326next trace experiment.
14327
14328@kindex enable tracepoint
14329@item enable tracepoint @r{[}@var{num}@r{]}
14330Enable tracepoint @var{num}, or all tracepoints.  If this command is
14331issued during a trace experiment and the debug target supports enabling
14332tracepoints during a trace experiment, then the enabled tracepoints will
14333become effective immediately.  Otherwise, they will become effective the
14334next time a trace experiment is run.
14335@end table
14336
14337@node Tracepoint Passcounts
14338@subsection Tracepoint Passcounts
14339
14340@table @code
14341@kindex passcount
14342@cindex tracepoint pass count
14343@item passcount @r{[}@var{n} @r{[}@var{num}@r{]]}
14344Set the @dfn{passcount} of a tracepoint.  The passcount is a way to
14345automatically stop a trace experiment.  If a tracepoint's passcount is
14346@var{n}, then the trace experiment will be automatically stopped on
14347the @var{n}'th time that tracepoint is hit.  If the tracepoint number
14348@var{num} is not specified, the @code{passcount} command sets the
14349passcount of the most recently defined tracepoint.  If no passcount is
14350given, the trace experiment will run until stopped explicitly by the
14351user.
14352
14353Examples:
14354
14355@smallexample
14356(@value{GDBP}) @b{passcount 5 2} // Stop on the 5th execution of
14357@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// tracepoint 2}
14358
14359(@value{GDBP}) @b{passcount 12}  // Stop on the 12th execution of the
14360@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// most recently defined tracepoint.}
14361(@value{GDBP}) @b{trace foo}
14362(@value{GDBP}) @b{pass 3}
14363(@value{GDBP}) @b{trace bar}
14364(@value{GDBP}) @b{pass 2}
14365(@value{GDBP}) @b{trace baz}
14366(@value{GDBP}) @b{pass 1}        // Stop tracing when foo has been
14367@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// executed 3 times OR when bar has}
14368@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// been executed 2 times}
14369@exdent @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @code{// OR when baz has been executed 1 time.}
14370@end smallexample
14371@end table
14372
14373@node Tracepoint Conditions
14374@subsection Tracepoint Conditions
14375@cindex conditional tracepoints
14376@cindex tracepoint conditions
14377
14378The simplest sort of tracepoint collects data every time your program
14379reaches a specified place.  You can also specify a @dfn{condition} for
14380a tracepoint.  A condition is just a Boolean expression in your
14381programming language (@pxref{Expressions, ,Expressions}).  A
14382tracepoint with a condition evaluates the expression each time your
14383program reaches it, and data collection happens only if the condition
14384is true.
14385
14386Tracepoint conditions can be specified when a tracepoint is set, by
14387using @samp{if} in the arguments to the @code{trace} command.
14388@xref{Create and Delete Tracepoints, ,Setting Tracepoints}.  They can
14389also be set or changed at any time with the @code{condition} command,
14390just as with breakpoints.
14391
14392Unlike breakpoint conditions, @value{GDBN} does not actually evaluate
14393the conditional expression itself.  Instead, @value{GDBN} encodes the
14394expression into an agent expression (@pxref{Agent Expressions})
14395suitable for execution on the target, independently of @value{GDBN}.
14396Global variables become raw memory locations, locals become stack
14397accesses, and so forth.
14398
14399For instance, suppose you have a function that is usually called
14400frequently, but should not be called after an error has occurred.  You
14401could use the following tracepoint command to collect data about calls
14402of that function that happen while the error code is propagating
14403through the program; an unconditional tracepoint could end up
14404collecting thousands of useless trace frames that you would have to
14405search through.
14406
14407@smallexample
14408(@value{GDBP}) @kbd{trace normal_operation if errcode > 0}
14409@end smallexample
14410
14411@node Trace State Variables
14412@subsection Trace State Variables
14413@cindex trace state variables
14414
14415A @dfn{trace state variable} is a special type of variable that is
14416created and managed by target-side code.  The syntax is the same as
14417that for GDB's convenience variables (a string prefixed with ``$''),
14418but they are stored on the target.  They must be created explicitly,
14419using a @code{tvariable} command.  They are always 64-bit signed
14420integers.
14421
14422Trace state variables are remembered by @value{GDBN}, and downloaded
14423to the target along with tracepoint information when the trace
14424experiment starts.  There are no intrinsic limits on the number of
14425trace state variables, beyond memory limitations of the target.
14426
14427@cindex convenience variables, and trace state variables
14428Although trace state variables are managed by the target, you can use
14429them in print commands and expressions as if they were convenience
14430variables; @value{GDBN} will get the current value from the target
14431while the trace experiment is running.  Trace state variables share
14432the same namespace as other ``$'' variables, which means that you
14433cannot have trace state variables with names like @code{$23} or
14434@code{$pc}, nor can you have a trace state variable and a convenience
14435variable with the same name.
14436
14437@table @code
14438
14439@item tvariable $@var{name} [ = @var{expression} ]
14440@kindex tvariable
14441The @code{tvariable} command creates a new trace state variable named
14442@code{$@var{name}}, and optionally gives it an initial value of
14443@var{expression}.  The @var{expression} is evaluated when this command is
14444entered; the result will be converted to an integer if possible,
14445otherwise @value{GDBN} will report an error. A subsequent
14446@code{tvariable} command specifying the same name does not create a
14447variable, but instead assigns the supplied initial value to the
14448existing variable of that name, overwriting any previous initial
14449value. The default initial value is 0.
14450
14451@item info tvariables
14452@kindex info tvariables
14453List all the trace state variables along with their initial values.
14454Their current values may also be displayed, if the trace experiment is
14455currently running.
14456
14457@item delete tvariable @r{[} $@var{name} @dots{} @r{]}
14458@kindex delete tvariable
14459Delete the given trace state variables, or all of them if no arguments
14460are specified.
14461
14462@end table
14463
14464@node Tracepoint Actions
14465@subsection Tracepoint Action Lists
14466
14467@table @code
14468@kindex actions
14469@cindex tracepoint actions
14470@item actions @r{[}@var{num}@r{]}
14471This command will prompt for a list of actions to be taken when the
14472tracepoint is hit.  If the tracepoint number @var{num} is not
14473specified, this command sets the actions for the one that was most
14474recently defined (so that you can define a tracepoint and then say
14475@code{actions} without bothering about its number).  You specify the
14476actions themselves on the following lines, one action at a time, and
14477terminate the actions list with a line containing just @code{end}.  So
14478far, the only defined actions are @code{collect}, @code{teval}, and
14479@code{while-stepping}.
14480
14481@code{actions} is actually equivalent to @code{commands} (@pxref{Break
14482Commands, ,Breakpoint Command Lists}), except that only the defined
14483actions are allowed; any other @value{GDBN} command is rejected.
14484
14485@cindex remove actions from a tracepoint
14486To remove all actions from a tracepoint, type @samp{actions @var{num}}
14487and follow it immediately with @samp{end}.
14488
14489@smallexample
14490(@value{GDBP}) @b{collect @var{data}} // collect some data
14491
14492(@value{GDBP}) @b{while-stepping 5} // single-step 5 times, collect data
14493
14494(@value{GDBP}) @b{end}              // signals the end of actions.
14495@end smallexample
14496
14497In the following example, the action list begins with @code{collect}
14498commands indicating the things to be collected when the tracepoint is
14499hit.  Then, in order to single-step and collect additional data
14500following the tracepoint, a @code{while-stepping} command is used,
14501followed by the list of things to be collected after each step in a
14502sequence of single steps.  The @code{while-stepping} command is
14503terminated by its own separate @code{end} command.  Lastly, the action
14504list is terminated by an @code{end} command.
14505
14506@smallexample
14507(@value{GDBP}) @b{trace foo}
14508(@value{GDBP}) @b{actions}
14509Enter actions for tracepoint 1, one per line:
14510> collect bar,baz
14511> collect $regs
14512> while-stepping 12
14513  > collect $pc, arr[i]
14514  > end
14515end
14516@end smallexample
14517
14518@kindex collect @r{(tracepoints)}
14519@item collect@r{[}/@var{mods}@r{]} @var{expr1}, @var{expr2}, @dots{}
14520Collect values of the given expressions when the tracepoint is hit.
14521This command accepts a comma-separated list of any valid expressions.
14522In addition to global, static, or local variables, the following
14523special arguments are supported:
14524
14525@table @code
14526@item $regs
14527Collect all registers.
14528
14529@item $args
14530Collect all function arguments.
14531
14532@item $locals
14533Collect all local variables.
14534
14535@item $_ret
14536Collect the return address.  This is helpful if you want to see more
14537of a backtrace.
14538
14539@emph{Note:} The return address location can not always be reliably
14540determined up front, and the wrong address / registers may end up
14541collected instead.  On some architectures the reliability is higher
14542for tracepoints at function entry, while on others it's the opposite.
14543When this happens, backtracing will stop because the return address is
14544found unavailable (unless another collect rule happened to match it).
14545
14546@item $_probe_argc
14547Collects the number of arguments from the static probe at which the
14548tracepoint is located.
14549@xref{Static Probe Points}.
14550
14551@item $_probe_arg@var{n}
14552@var{n} is an integer between 0 and 11.  Collects the @var{n}th argument
14553from the static probe at which the tracepoint is located.
14554@xref{Static Probe Points}.
14555
14556@item $_sdata
14557@vindex $_sdata@r{, collect}
14558Collect static tracepoint marker specific data.  Only available for
14559static tracepoints.  @xref{Tracepoint Actions,,Tracepoint Action
14560Lists}.  On the UST static tracepoints library backend, an
14561instrumentation point resembles a @code{printf} function call.  The
14562tracing library is able to collect user specified data formatted to a
14563character string using the format provided by the programmer that
14564instrumented the program.  Other backends have similar mechanisms.
14565Here's an example of a UST marker call:
14566
14567@smallexample
14568 const char master_name[] = "$your_name";
14569 trace_mark(channel1, marker1, "hello %s", master_name)
14570@end smallexample
14571
14572In this case, collecting @code{$_sdata} collects the string
14573@samp{hello $yourname}.  When analyzing the trace buffer, you can
14574inspect @samp{$_sdata} like any other variable available to
14575@value{GDBN}.
14576@end table
14577
14578You can give several consecutive @code{collect} commands, each one
14579with a single argument, or one @code{collect} command with several
14580arguments separated by commas; the effect is the same.
14581
14582The optional @var{mods} changes the usual handling of the arguments.
14583@code{s} requests that pointers to chars be handled as strings, in
14584particular collecting the contents of the memory being pointed at, up
14585to the first zero.  The upper bound is by default the value of the
14586@code{print elements} variable; if @code{s} is followed by a decimal
14587number, that is the upper bound instead.  So for instance
14588@samp{collect/s25 mystr} collects as many as 25 characters at
14589@samp{mystr}.
14590
14591The command @code{info scope} (@pxref{Symbols, info scope}) is
14592particularly useful for figuring out what data to collect.
14593
14594@kindex teval @r{(tracepoints)}
14595@item teval @var{expr1}, @var{expr2}, @dots{}
14596Evaluate the given expressions when the tracepoint is hit.  This
14597command accepts a comma-separated list of expressions.  The results
14598are discarded, so this is mainly useful for assigning values to trace
14599state variables (@pxref{Trace State Variables}) without adding those
14600values to the trace buffer, as would be the case if the @code{collect}
14601action were used.
14602
14603@kindex while-stepping @r{(tracepoints)}
14604@item while-stepping @var{n}
14605Perform @var{n} single-step instruction traces after the tracepoint,
14606collecting new data after each step.  The @code{while-stepping}
14607command is followed by the list of what to collect while stepping
14608(followed by its own @code{end} command):
14609
14610@smallexample
14611> while-stepping 12
14612  > collect $regs, myglobal
14613  > end
14614>
14615@end smallexample
14616
14617@noindent
14618Note that @code{$pc} is not automatically collected by
14619@code{while-stepping}; you need to explicitly collect that register if
14620you need it.  You may abbreviate @code{while-stepping} as @code{ws} or
14621@code{stepping}.
14622
14623@item set default-collect @var{expr1}, @var{expr2}, @dots{}
14624@kindex set default-collect
14625@cindex default collection action
14626This variable is a list of expressions to collect at each tracepoint
14627hit.  It is effectively an additional @code{collect} action prepended
14628to every tracepoint action list.  The expressions are parsed
14629individually for each tracepoint, so for instance a variable named
14630@code{xyz} may be interpreted as a global for one tracepoint, and a
14631local for another, as appropriate to the tracepoint's location.
14632
14633@item show default-collect
14634@kindex show default-collect
14635Show the list of expressions that are collected by default at each
14636tracepoint hit.
14637
14638@end table
14639
14640@node Listing Tracepoints
14641@subsection Listing Tracepoints
14642
14643@table @code
14644@kindex info tracepoints @r{[}@var{n}@dots{}@r{]}
14645@kindex info tp @r{[}@var{n}@dots{}@r{]}
14646@cindex information about tracepoints
14647@item info tracepoints @r{[}@var{num}@dots{}@r{]}
14648Display information about the tracepoint @var{num}.  If you don't
14649specify a tracepoint number, displays information about all the
14650tracepoints defined so far.  The format is similar to that used for
14651@code{info breakpoints}; in fact, @code{info tracepoints} is the same
14652command, simply restricting itself to tracepoints.
14653
14654A tracepoint's listing may include additional information specific to
14655tracing:
14656
14657@itemize @bullet
14658@item
14659its passcount as given by the @code{passcount @var{n}} command
14660
14661@item
14662the state about installed on target of each location
14663@end itemize
14664
14665@smallexample
14666(@value{GDBP}) @b{info trace}
14667Num     Type           Disp Enb Address    What
146681       tracepoint     keep y   0x0804ab57 in foo() at main.cxx:7
14669        while-stepping 20
14670          collect globfoo, $regs
14671        end
14672        collect globfoo2
14673        end
14674        pass count 1200
146752       tracepoint     keep y   <MULTIPLE>
14676        collect $eip
146772.1                         y     0x0804859c in func4 at change-loc.h:35
14678        installed on target
146792.2                         y     0xb7ffc480 in func4 at change-loc.h:35
14680        installed on target
146812.3                         y     <PENDING>  set_tracepoint
146823       tracepoint     keep y   0x080485b1 in foo at change-loc.c:29
14683        not installed on target
14684(@value{GDBP})
14685@end smallexample
14686
14687@noindent
14688This command can be abbreviated @code{info tp}.
14689@end table
14690
14691@node Listing Static Tracepoint Markers
14692@subsection Listing Static Tracepoint Markers
14693
14694@table @code
14695@kindex info static-tracepoint-markers
14696@cindex information about static tracepoint markers
14697@item info static-tracepoint-markers
14698Display information about all static tracepoint markers defined in the
14699program.
14700
14701For each marker, the following columns are printed:
14702
14703@table @emph
14704@item Count
14705An incrementing counter, output to help readability.  This is not a
14706stable identifier.
14707@item ID
14708The marker ID, as reported by the target.
14709@item Enabled or Disabled
14710Probed markers are tagged with @samp{y}.  @samp{n} identifies marks
14711that are not enabled.
14712@item Address
14713Where the marker is in your program, as a memory address.
14714@item What
14715Where the marker is in the source for your program, as a file and line
14716number.  If the debug information included in the program does not
14717allow @value{GDBN} to locate the source of the marker, this column
14718will be left blank.
14719@end table
14720
14721@noindent
14722In addition, the following information may be printed for each marker:
14723
14724@table @emph
14725@item Data
14726User data passed to the tracing library by the marker call.  In the
14727UST backend, this is the format string passed as argument to the
14728marker call.
14729@item Static tracepoints probing the marker
14730The list of static tracepoints attached to the marker.
14731@end table
14732
14733@smallexample
14734(@value{GDBP}) info static-tracepoint-markers
14735Cnt ID         Enb Address            What
147361   ust/bar2   y   0x0000000000400e1a in main at stexample.c:25
14737     Data: number1 %d number2 %d
14738     Probed by static tracepoints: #2
147392   ust/bar33  n   0x0000000000400c87 in main at stexample.c:24
14740     Data: str %s
14741(@value{GDBP})
14742@end smallexample
14743@end table
14744
14745@node Starting and Stopping Trace Experiments
14746@subsection Starting and Stopping Trace Experiments
14747
14748@table @code
14749@kindex tstart [ @var{notes} ]
14750@cindex start a new trace experiment
14751@cindex collected data discarded
14752@item tstart
14753This command starts the trace experiment, and begins collecting data.
14754It has the side effect of discarding all the data collected in the
14755trace buffer during the previous trace experiment.  If any arguments
14756are supplied, they are taken as a note and stored with the trace
14757experiment's state.  The notes may be arbitrary text, and are
14758especially useful with disconnected tracing in a multi-user context;
14759the notes can explain what the trace is doing, supply user contact
14760information, and so forth.
14761
14762@kindex tstop [ @var{notes} ]
14763@cindex stop a running trace experiment
14764@item tstop
14765This command stops the trace experiment.  If any arguments are
14766supplied, they are recorded with the experiment as a note.  This is
14767useful if you are stopping a trace started by someone else, for
14768instance if the trace is interfering with the system's behavior and
14769needs to be stopped quickly.
14770
14771@strong{Note}: a trace experiment and data collection may stop
14772automatically if any tracepoint's passcount is reached
14773(@pxref{Tracepoint Passcounts}), or if the trace buffer becomes full.
14774
14775@kindex tstatus
14776@cindex status of trace data collection
14777@cindex trace experiment, status of
14778@item tstatus
14779This command displays the status of the current trace data
14780collection.
14781@end table
14782
14783Here is an example of the commands we described so far:
14784
14785@smallexample
14786(@value{GDBP}) @b{trace gdb_c_test}
14787(@value{GDBP}) @b{actions}
14788Enter actions for tracepoint #1, one per line.
14789> collect $regs,$locals,$args
14790> while-stepping 11
14791  > collect $regs
14792  > end
14793> end
14794(@value{GDBP}) @b{tstart}
14795	[time passes @dots{}]
14796(@value{GDBP}) @b{tstop}
14797@end smallexample
14798
14799@anchor{disconnected tracing}
14800@cindex disconnected tracing
14801You can choose to continue running the trace experiment even if
14802@value{GDBN} disconnects from the target, voluntarily or
14803involuntarily.  For commands such as @code{detach}, the debugger will
14804ask what you want to do with the trace.  But for unexpected
14805terminations (@value{GDBN} crash, network outage), it would be
14806unfortunate to lose hard-won trace data, so the variable
14807@code{disconnected-tracing} lets you decide whether the trace should
14808continue running without @value{GDBN}.
14809
14810@table @code
14811@item set disconnected-tracing on
14812@itemx set disconnected-tracing off
14813@kindex set disconnected-tracing
14814Choose whether a tracing run should continue to run if @value{GDBN}
14815has disconnected from the target.  Note that @code{detach} or
14816@code{quit} will ask you directly what to do about a running trace no
14817matter what this variable's setting, so the variable is mainly useful
14818for handling unexpected situations, such as loss of the network.
14819
14820@item show disconnected-tracing
14821@kindex show disconnected-tracing
14822Show the current choice for disconnected tracing.
14823
14824@end table
14825
14826When you reconnect to the target, the trace experiment may or may not
14827still be running; it might have filled the trace buffer in the
14828meantime, or stopped for one of the other reasons.  If it is running,
14829it will continue after reconnection.
14830
14831Upon reconnection, the target will upload information about the
14832tracepoints in effect.  @value{GDBN} will then compare that
14833information to the set of tracepoints currently defined, and attempt
14834to match them up, allowing for the possibility that the numbers may
14835have changed due to creation and deletion in the meantime.  If one of
14836the target's tracepoints does not match any in @value{GDBN}, the
14837debugger will create a new tracepoint, so that you have a number with
14838which to specify that tracepoint.  This matching-up process is
14839necessarily heuristic, and it may result in useless tracepoints being
14840created; you may simply delete them if they are of no use.
14841
14842@cindex circular trace buffer
14843If your target agent supports a @dfn{circular trace buffer}, then you
14844can run a trace experiment indefinitely without filling the trace
14845buffer; when space runs out, the agent deletes already-collected trace
14846frames, oldest first, until there is enough room to continue
14847collecting.  This is especially useful if your tracepoints are being
14848hit too often, and your trace gets terminated prematurely because the
14849buffer is full.  To ask for a circular trace buffer, simply set
14850@samp{circular-trace-buffer} to on.  You can set this at any time,
14851including during tracing; if the agent can do it, it will change
14852buffer handling on the fly, otherwise it will not take effect until
14853the next run.
14854
14855@table @code
14856@item set circular-trace-buffer on
14857@itemx set circular-trace-buffer off
14858@kindex set circular-trace-buffer
14859Choose whether a tracing run should use a linear or circular buffer
14860for trace data.  A linear buffer will not lose any trace data, but may
14861fill up prematurely, while a circular buffer will discard old trace
14862data, but it will have always room for the latest tracepoint hits.
14863
14864@item show circular-trace-buffer
14865@kindex show circular-trace-buffer
14866Show the current choice for the trace buffer.  Note that this may not
14867match the agent's current buffer handling, nor is it guaranteed to
14868match the setting that might have been in effect during a past run,
14869for instance if you are looking at frames from a trace file.
14870
14871@end table
14872
14873@table @code
14874@item set trace-buffer-size @var{n}
14875@itemx set trace-buffer-size unlimited
14876@kindex set trace-buffer-size
14877Request that the target use a trace buffer of @var{n} bytes.  Not all
14878targets will honor the request; they may have a compiled-in size for
14879the trace buffer, or some other limitation.  Set to a value of
14880@code{unlimited} or @code{-1} to let the target use whatever size it
14881likes.  This is also the default.
14882
14883@item show trace-buffer-size
14884@kindex show trace-buffer-size
14885Show the current requested size for the trace buffer.  Note that this
14886will only match the actual size if the target supports size-setting,
14887and was able to handle the requested size.  For instance, if the
14888target can only change buffer size between runs, this variable will
14889not reflect the change until the next run starts.  Use @code{tstatus}
14890to get a report of the actual buffer size.
14891@end table
14892
14893@table @code
14894@item set trace-user @var{text}
14895@kindex set trace-user
14896
14897@item show trace-user
14898@kindex show trace-user
14899
14900@item set trace-notes @var{text}
14901@kindex set trace-notes
14902Set the trace run's notes.
14903
14904@item show trace-notes
14905@kindex show trace-notes
14906Show the trace run's notes.
14907
14908@item set trace-stop-notes @var{text}
14909@kindex set trace-stop-notes
14910Set the trace run's stop notes.  The handling of the note is as for
14911@code{tstop} arguments; the set command is convenient way to fix a
14912stop note that is mistaken or incomplete.
14913
14914@item show trace-stop-notes
14915@kindex show trace-stop-notes
14916Show the trace run's stop notes.
14917
14918@end table
14919
14920@node Tracepoint Restrictions
14921@subsection Tracepoint Restrictions
14922
14923@cindex tracepoint restrictions
14924There are a number of restrictions on the use of tracepoints.  As
14925described above, tracepoint data gathering occurs on the target
14926without interaction from @value{GDBN}.  Thus the full capabilities of
14927the debugger are not available during data gathering, and then at data
14928examination time, you will be limited by only having what was
14929collected.  The following items describe some common problems, but it
14930is not exhaustive, and you may run into additional difficulties not
14931mentioned here.
14932
14933@itemize @bullet
14934
14935@item
14936Tracepoint expressions are intended to gather objects (lvalues).  Thus
14937the full flexibility of GDB's expression evaluator is not available.
14938You cannot call functions, cast objects to aggregate types, access
14939convenience variables or modify values (except by assignment to trace
14940state variables).  Some language features may implicitly call
14941functions (for instance Objective-C fields with accessors), and therefore
14942cannot be collected either.
14943
14944@item
14945Collection of local variables, either individually or in bulk with
14946@code{$locals} or @code{$args}, during @code{while-stepping} may
14947behave erratically.  The stepping action may enter a new scope (for
14948instance by stepping into a function), or the location of the variable
14949may change (for instance it is loaded into a register).  The
14950tracepoint data recorded uses the location information for the
14951variables that is correct for the tracepoint location.  When the
14952tracepoint is created, it is not possible, in general, to determine
14953where the steps of a @code{while-stepping} sequence will advance the
14954program---particularly if a conditional branch is stepped.
14955
14956@item
14957Collection of an incompletely-initialized or partially-destroyed object
14958may result in something that @value{GDBN} cannot display, or displays
14959in a misleading way.
14960
14961@item
14962When @value{GDBN} displays a pointer to character it automatically
14963dereferences the pointer to also display characters of the string
14964being pointed to.  However, collecting the pointer during tracing does
14965not automatically collect the string.  You need to explicitly
14966dereference the pointer and provide size information if you want to
14967collect not only the pointer, but the memory pointed to.  For example,
14968@code{*ptr@@50} can be used to collect the 50 element array pointed to
14969by @code{ptr}.
14970
14971@item
14972It is not possible to collect a complete stack backtrace at a
14973tracepoint.  Instead, you may collect the registers and a few hundred
14974bytes from the stack pointer with something like @code{*(unsigned char *)$esp@@300}
14975(adjust to use the name of the actual stack pointer register on your
14976target architecture, and the amount of stack you wish to capture).
14977Then the @code{backtrace} command will show a partial backtrace when
14978using a trace frame.  The number of stack frames that can be examined
14979depends on the sizes of the frames in the collected stack.  Note that
14980if you ask for a block so large that it goes past the bottom of the
14981stack, the target agent may report an error trying to read from an
14982invalid address.
14983
14984@item
14985If you do not collect registers at a tracepoint, @value{GDBN} can
14986infer that the value of @code{$pc} must be the same as the address of
14987the tracepoint and use that when you are looking at a trace frame
14988for that tracepoint.  However, this cannot work if the tracepoint has
14989multiple locations (for instance if it was set in a function that was
14990inlined), or if it has a @code{while-stepping} loop.  In those cases
14991@value{GDBN} will warn you that it can't infer @code{$pc}, and default
14992it to zero.
14993
14994@end itemize
14995
14996@node Analyze Collected Data
14997@section Using the Collected Data
14998
14999After the tracepoint experiment ends, you use @value{GDBN} commands
15000for examining the trace data.  The basic idea is that each tracepoint
15001collects a trace @dfn{snapshot} every time it is hit and another
15002snapshot every time it single-steps.  All these snapshots are
15003consecutively numbered from zero and go into a buffer, and you can
15004examine them later.  The way you examine them is to @dfn{focus} on a
15005specific trace snapshot.  When the remote stub is focused on a trace
15006snapshot, it will respond to all @value{GDBN} requests for memory and
15007registers by reading from the buffer which belongs to that snapshot,
15008rather than from @emph{real} memory or registers of the program being
15009debugged.  This means that @strong{all} @value{GDBN} commands
15010(@code{print}, @code{info registers}, @code{backtrace}, etc.) will
15011behave as if we were currently debugging the program state as it was
15012when the tracepoint occurred.  Any requests for data that are not in
15013the buffer will fail.
15014
15015@menu
15016* tfind::                       How to select a trace snapshot
15017* tdump::                       How to display all data for a snapshot
15018* save tracepoints::            How to save tracepoints for a future run
15019@end menu
15020
15021@node tfind
15022@subsection @code{tfind @var{n}}
15023
15024@kindex tfind
15025@cindex select trace snapshot
15026@cindex find trace snapshot
15027The basic command for selecting a trace snapshot from the buffer is
15028@code{tfind @var{n}}, which finds trace snapshot number @var{n},
15029counting from zero.  If no argument @var{n} is given, the next
15030snapshot is selected.
15031
15032Here are the various forms of using the @code{tfind} command.
15033
15034@table @code
15035@item tfind start
15036Find the first snapshot in the buffer.  This is a synonym for
15037@code{tfind 0} (since 0 is the number of the first snapshot).
15038
15039@item tfind none
15040Stop debugging trace snapshots, resume @emph{live} debugging.
15041
15042@item tfind end
15043Same as @samp{tfind none}.
15044
15045@item tfind
15046No argument means find the next trace snapshot or find the first
15047one if no trace snapshot is selected.
15048
15049@item tfind -
15050Find the previous trace snapshot before the current one.  This permits
15051retracing earlier steps.
15052
15053@item tfind tracepoint @var{num}
15054Find the next snapshot associated with tracepoint @var{num}.  Search
15055proceeds forward from the last examined trace snapshot.  If no
15056argument @var{num} is given, it means find the next snapshot collected
15057for the same tracepoint as the current snapshot.
15058
15059@item tfind pc @var{addr}
15060Find the next snapshot associated with the value @var{addr} of the
15061program counter.  Search proceeds forward from the last examined trace
15062snapshot.  If no argument @var{addr} is given, it means find the next
15063snapshot with the same value of PC as the current snapshot.
15064
15065@item tfind outside @var{addr1}, @var{addr2}
15066Find the next snapshot whose PC is outside the given range of
15067addresses (exclusive).
15068
15069@item tfind range @var{addr1}, @var{addr2}
15070Find the next snapshot whose PC is between @var{addr1} and
15071@var{addr2} (inclusive).
15072
15073@item tfind line @r{[}@var{file}:@r{]}@var{n}
15074Find the next snapshot associated with the source line @var{n}.  If
15075the optional argument @var{file} is given, refer to line @var{n} in
15076that source file.  Search proceeds forward from the last examined
15077trace snapshot.  If no argument @var{n} is given, it means find the
15078next line other than the one currently being examined; thus saying
15079@code{tfind line} repeatedly can appear to have the same effect as
15080stepping from line to line in a @emph{live} debugging session.
15081@end table
15082
15083The default arguments for the @code{tfind} commands are specifically
15084designed to make it easy to scan through the trace buffer.  For
15085instance, @code{tfind} with no argument selects the next trace
15086snapshot, and @code{tfind -} with no argument selects the previous
15087trace snapshot.  So, by giving one @code{tfind} command, and then
15088simply hitting @key{RET} repeatedly you can examine all the trace
15089snapshots in order.  Or, by saying @code{tfind -} and then hitting
15090@key{RET} repeatedly you can examine the snapshots in reverse order.
15091The @code{tfind line} command with no argument selects the snapshot
15092for the next source line executed.  The @code{tfind pc} command with
15093no argument selects the next snapshot with the same program counter
15094(PC) as the current frame.  The @code{tfind tracepoint} command with
15095no argument selects the next trace snapshot collected by the same
15096tracepoint as the current one.
15097
15098In addition to letting you scan through the trace buffer manually,
15099these commands make it easy to construct @value{GDBN} scripts that
15100scan through the trace buffer and print out whatever collected data
15101you are interested in.  Thus, if we want to examine the PC, FP, and SP
15102registers from each trace frame in the buffer, we can say this:
15103
15104@smallexample
15105(@value{GDBP}) @b{tfind start}
15106(@value{GDBP}) @b{while ($trace_frame != -1)}
15107> printf "Frame %d, PC = %08X, SP = %08X, FP = %08X\n", \
15108          $trace_frame, $pc, $sp, $fp
15109> tfind
15110> end
15111
15112Frame 0, PC = 0020DC64, SP = 0030BF3C, FP = 0030BF44
15113Frame 1, PC = 0020DC6C, SP = 0030BF38, FP = 0030BF44
15114Frame 2, PC = 0020DC70, SP = 0030BF34, FP = 0030BF44
15115Frame 3, PC = 0020DC74, SP = 0030BF30, FP = 0030BF44
15116Frame 4, PC = 0020DC78, SP = 0030BF2C, FP = 0030BF44
15117Frame 5, PC = 0020DC7C, SP = 0030BF28, FP = 0030BF44
15118Frame 6, PC = 0020DC80, SP = 0030BF24, FP = 0030BF44
15119Frame 7, PC = 0020DC84, SP = 0030BF20, FP = 0030BF44
15120Frame 8, PC = 0020DC88, SP = 0030BF1C, FP = 0030BF44
15121Frame 9, PC = 0020DC8E, SP = 0030BF18, FP = 0030BF44
15122Frame 10, PC = 00203F6C, SP = 0030BE3C, FP = 0030BF14
15123@end smallexample
15124
15125Or, if we want to examine the variable @code{X} at each source line in
15126the buffer:
15127
15128@smallexample
15129(@value{GDBP}) @b{tfind start}
15130(@value{GDBP}) @b{while ($trace_frame != -1)}
15131> printf "Frame %d, X == %d\n", $trace_frame, X
15132> tfind line
15133> end
15134
15135Frame 0, X = 1
15136Frame 7, X = 2
15137Frame 13, X = 255
15138@end smallexample
15139
15140@node tdump
15141@subsection @code{tdump}
15142@kindex tdump
15143@cindex dump all data collected at tracepoint
15144@cindex tracepoint data, display
15145
15146This command takes no arguments.  It prints all the data collected at
15147the current trace snapshot.
15148
15149@smallexample
15150(@value{GDBP}) @b{trace 444}
15151(@value{GDBP}) @b{actions}
15152Enter actions for tracepoint #2, one per line:
15153> collect $regs, $locals, $args, gdb_long_test
15154> end
15155
15156(@value{GDBP}) @b{tstart}
15157
15158(@value{GDBP}) @b{tfind line 444}
15159#0  gdb_test (p1=0x11, p2=0x22, p3=0x33, p4=0x44, p5=0x55, p6=0x66)
15160at gdb_test.c:444
15161444        printp( "%s: arguments = 0x%X 0x%X 0x%X 0x%X 0x%X 0x%X\n", )
15162
15163(@value{GDBP}) @b{tdump}
15164Data collected at tracepoint 2, trace frame 1:
15165d0             0xc4aa0085       -995491707
15166d1             0x18     24
15167d2             0x80     128
15168d3             0x33     51
15169d4             0x71aea3d        119204413
15170d5             0x22     34
15171d6             0xe0     224
15172d7             0x380035 3670069
15173a0             0x19e24a 1696330
15174a1             0x3000668        50333288
15175a2             0x100    256
15176a3             0x322000 3284992
15177a4             0x3000698        50333336
15178a5             0x1ad3cc 1758156
15179fp             0x30bf3c 0x30bf3c
15180sp             0x30bf34 0x30bf34
15181ps             0x0      0
15182pc             0x20b2c8 0x20b2c8
15183fpcontrol      0x0      0
15184fpstatus       0x0      0
15185fpiaddr        0x0      0
15186p = 0x20e5b4 "gdb-test"
15187p1 = (void *) 0x11
15188p2 = (void *) 0x22
15189p3 = (void *) 0x33
15190p4 = (void *) 0x44
15191p5 = (void *) 0x55
15192p6 = (void *) 0x66
15193gdb_long_test = 17 '\021'
15194
15195(@value{GDBP})
15196@end smallexample
15197
15198@code{tdump} works by scanning the tracepoint's current collection
15199actions and printing the value of each expression listed.  So
15200@code{tdump} can fail, if after a run, you change the tracepoint's
15201actions to mention variables that were not collected during the run.
15202
15203Also, for tracepoints with @code{while-stepping} loops, @code{tdump}
15204uses the collected value of @code{$pc} to distinguish between trace
15205frames that were collected at the tracepoint hit, and frames that were
15206collected while stepping.  This allows it to correctly choose whether
15207to display the basic list of collections, or the collections from the
15208body of the while-stepping loop.  However, if @code{$pc} was not collected,
15209then @code{tdump} will always attempt to dump using the basic collection
15210list, and may fail if a while-stepping frame does not include all the
15211same data that is collected at the tracepoint hit.
15212@c This is getting pretty arcane, example would be good.
15213
15214@node save tracepoints
15215@subsection @code{save tracepoints @var{filename}}
15216@kindex save tracepoints
15217@kindex save-tracepoints
15218@cindex save tracepoints for future sessions
15219
15220This command saves all current tracepoint definitions together with
15221their actions and passcounts, into a file @file{@var{filename}}
15222suitable for use in a later debugging session.  To read the saved
15223tracepoint definitions, use the @code{source} command (@pxref{Command
15224Files}).  The @w{@code{save-tracepoints}} command is a deprecated
15225alias for @w{@code{save tracepoints}}
15226
15227@node Tracepoint Variables
15228@section Convenience Variables for Tracepoints
15229@cindex tracepoint variables
15230@cindex convenience variables for tracepoints
15231
15232@table @code
15233@vindex $trace_frame
15234@item (int) $trace_frame
15235The current trace snapshot (a.k.a.@: @dfn{frame}) number, or -1 if no
15236snapshot is selected.
15237
15238@vindex $tracepoint
15239@item (int) $tracepoint
15240The tracepoint for the current trace snapshot.
15241
15242@vindex $trace_line
15243@item (int) $trace_line
15244The line number for the current trace snapshot.
15245
15246@vindex $trace_file
15247@item (char []) $trace_file
15248The source file for the current trace snapshot.
15249
15250@vindex $trace_func
15251@item (char []) $trace_func
15252The name of the function containing @code{$tracepoint}.
15253@end table
15254
15255Note: @code{$trace_file} is not suitable for use in @code{printf},
15256use @code{output} instead.
15257
15258Here's a simple example of using these convenience variables for
15259stepping through all the trace snapshots and printing some of their
15260data.  Note that these are not the same as trace state variables,
15261which are managed by the target.
15262
15263@smallexample
15264(@value{GDBP}) @b{tfind start}
15265
15266(@value{GDBP}) @b{while $trace_frame != -1}
15267> output $trace_file
15268> printf ", line %d (tracepoint #%d)\n", $trace_line, $tracepoint
15269> tfind
15270> end
15271@end smallexample
15272
15273@node Trace Files
15274@section Using Trace Files
15275@cindex trace files
15276
15277In some situations, the target running a trace experiment may no
15278longer be available; perhaps it crashed, or the hardware was needed
15279for a different activity.  To handle these cases, you can arrange to
15280dump the trace data into a file, and later use that file as a source
15281of trace data, via the @code{target tfile} command.
15282
15283@table @code
15284
15285@kindex tsave
15286@item tsave [ -r ] @var{filename}
15287@itemx tsave [-ctf] @var{dirname}
15288Save the trace data to @var{filename}.  By default, this command
15289assumes that @var{filename} refers to the host filesystem, so if
15290necessary @value{GDBN} will copy raw trace data up from the target and
15291then save it.  If the target supports it, you can also supply the
15292optional argument @code{-r} (``remote'') to direct the target to save
15293the data directly into @var{filename} in its own filesystem, which may be
15294more efficient if the trace buffer is very large.  (Note, however, that
15295@code{target tfile} can only read from files accessible to the host.)
15296By default, this command will save trace frame in tfile format.
15297You can supply the optional argument @code{-ctf} to save data in CTF
15298format.  The @dfn{Common Trace Format} (CTF) is proposed as a trace format
15299that can be shared by multiple debugging and tracing tools.  Please go to
15300@indicateurl{http://www.efficios.com/ctf} to get more information.
15301
15302@kindex target tfile
15303@kindex tfile
15304@kindex target ctf
15305@kindex ctf
15306@item target tfile @var{filename}
15307@itemx target ctf @var{dirname}
15308Use the file named @var{filename} or directory named @var{dirname} as
15309a source of trace data.  Commands that examine data work as they do with
15310a live target, but it is not possible to run any new trace experiments.
15311@code{tstatus} will report the state of the trace run at the moment
15312the data was saved, as well as the current trace frame you are examining.
15313Both @var{filename} and @var{dirname} must be on a filesystem accessible to
15314the host.
15315
15316@smallexample
15317(@value{GDBP}) target ctf ctf.ctf
15318(@value{GDBP}) tfind
15319Found trace frame 0, tracepoint 2
1532039            ++a;  /* set tracepoint 1 here */
15321(@value{GDBP}) tdump
15322Data collected at tracepoint 2, trace frame 0:
15323i = 0
15324a = 0
15325b = 1 '\001'
15326c = @{"123", "456", "789", "123", "456", "789"@}
15327d = @{@{@{a = 1, b = 2@}, @{a = 3, b = 4@}@}, @{@{a = 5, b = 6@}, @{a = 7, b = 8@}@}@}
15328(@value{GDBP}) p b
15329$1 = 1
15330@end smallexample
15331
15332@end table
15333
15334@node Overlays
15335@chapter Debugging Programs That Use Overlays
15336@cindex overlays
15337
15338If your program is too large to fit completely in your target system's
15339memory, you can sometimes use @dfn{overlays} to work around this
15340problem.  @value{GDBN} provides some support for debugging programs that
15341use overlays.
15342
15343@menu
15344* How Overlays Work::              A general explanation of overlays.
15345* Overlay Commands::               Managing overlays in @value{GDBN}.
15346* Automatic Overlay Debugging::    @value{GDBN} can find out which overlays are
15347                                   mapped by asking the inferior.
15348* Overlay Sample Program::         A sample program using overlays.
15349@end menu
15350
15351@node How Overlays Work
15352@section How Overlays Work
15353@cindex mapped overlays
15354@cindex unmapped overlays
15355@cindex load address, overlay's
15356@cindex mapped address
15357@cindex overlay area
15358
15359Suppose you have a computer whose instruction address space is only 64
15360kilobytes long, but which has much more memory which can be accessed by
15361other means: special instructions, segment registers, or memory
15362management hardware, for example.  Suppose further that you want to
15363adapt a program which is larger than 64 kilobytes to run on this system.
15364
15365One solution is to identify modules of your program which are relatively
15366independent, and need not call each other directly; call these modules
15367@dfn{overlays}.  Separate the overlays from the main program, and place
15368their machine code in the larger memory.  Place your main program in
15369instruction memory, but leave at least enough space there to hold the
15370largest overlay as well.
15371
15372Now, to call a function located in an overlay, you must first copy that
15373overlay's machine code from the large memory into the space set aside
15374for it in the instruction memory, and then jump to its entry point
15375there.
15376
15377@c NB:  In the below the mapped area's size is greater or equal to the
15378@c size of all overlays.  This is intentional to remind the developer
15379@c that overlays don't necessarily need to be the same size.
15380
15381@smallexample
15382@group
15383    Data             Instruction            Larger
15384Address Space       Address Space        Address Space
15385+-----------+       +-----------+        +-----------+
15386|           |       |           |        |           |
15387+-----------+       +-----------+        +-----------+<-- overlay 1
15388| program   |       |   main    |   .----| overlay 1 | load address
15389| variables |       |  program  |   |    +-----------+
15390| and heap  |       |           |   |    |           |
15391+-----------+       |           |   |    +-----------+<-- overlay 2
15392|           |       +-----------+   |    |           | load address
15393+-----------+       |           |   |  .-| overlay 2 |
15394                    |           |   |  | |           |
15395         mapped --->+-----------+   |  | +-----------+
15396         address    |           |   |  | |           |
15397                    |  overlay  | <-'  | |           |
15398                    |   area    |  <---' +-----------+<-- overlay 3
15399                    |           | <---.  |           | load address
15400                    +-----------+     `--| overlay 3 |
15401                    |           |        |           |
15402                    +-----------+        |           |
15403                                         +-----------+
15404                                         |           |
15405                                         +-----------+
15406
15407                    @anchor{A code overlay}A code overlay
15408@end group
15409@end smallexample
15410
15411The diagram (@pxref{A code overlay}) shows a system with separate data
15412and instruction address spaces.  To map an overlay, the program copies
15413its code from the larger address space to the instruction address space.
15414Since the overlays shown here all use the same mapped address, only one
15415may be mapped at a time.  For a system with a single address space for
15416data and instructions, the diagram would be similar, except that the
15417program variables and heap would share an address space with the main
15418program and the overlay area.
15419
15420An overlay loaded into instruction memory and ready for use is called a
15421@dfn{mapped} overlay; its @dfn{mapped address} is its address in the
15422instruction memory.  An overlay not present (or only partially present)
15423in instruction memory is called @dfn{unmapped}; its @dfn{load address}
15424is its address in the larger memory.  The mapped address is also called
15425the @dfn{virtual memory address}, or @dfn{VMA}; the load address is also
15426called the @dfn{load memory address}, or @dfn{LMA}.
15427
15428Unfortunately, overlays are not a completely transparent way to adapt a
15429program to limited instruction memory.  They introduce a new set of
15430global constraints you must keep in mind as you design your program:
15431
15432@itemize @bullet
15433
15434@item
15435Before calling or returning to a function in an overlay, your program
15436must make sure that overlay is actually mapped.  Otherwise, the call or
15437return will transfer control to the right address, but in the wrong
15438overlay, and your program will probably crash.
15439
15440@item
15441If the process of mapping an overlay is expensive on your system, you
15442will need to choose your overlays carefully to minimize their effect on
15443your program's performance.
15444
15445@item
15446The executable file you load onto your system must contain each
15447overlay's instructions, appearing at the overlay's load address, not its
15448mapped address.  However, each overlay's instructions must be relocated
15449and its symbols defined as if the overlay were at its mapped address.
15450You can use GNU linker scripts to specify different load and relocation
15451addresses for pieces of your program; see @ref{Overlay Description,,,
15452ld.info, Using ld: the GNU linker}.
15453
15454@item
15455The procedure for loading executable files onto your system must be able
15456to load their contents into the larger address space as well as the
15457instruction and data spaces.
15458
15459@end itemize
15460
15461The overlay system described above is rather simple, and could be
15462improved in many ways:
15463
15464@itemize @bullet
15465
15466@item
15467If your system has suitable bank switch registers or memory management
15468hardware, you could use those facilities to make an overlay's load area
15469contents simply appear at their mapped address in instruction space.
15470This would probably be faster than copying the overlay to its mapped
15471area in the usual way.
15472
15473@item
15474If your overlays are small enough, you could set aside more than one
15475overlay area, and have more than one overlay mapped at a time.
15476
15477@item
15478You can use overlays to manage data, as well as instructions.  In
15479general, data overlays are even less transparent to your design than
15480code overlays: whereas code overlays only require care when you call or
15481return to functions, data overlays require care every time you access
15482the data.  Also, if you change the contents of a data overlay, you
15483must copy its contents back out to its load address before you can copy a
15484different data overlay into the same mapped area.
15485
15486@end itemize
15487
15488
15489@node Overlay Commands
15490@section Overlay Commands
15491
15492To use @value{GDBN}'s overlay support, each overlay in your program must
15493correspond to a separate section of the executable file.  The section's
15494virtual memory address and load memory address must be the overlay's
15495mapped and load addresses.  Identifying overlays with sections allows
15496@value{GDBN} to determine the appropriate address of a function or
15497variable, depending on whether the overlay is mapped or not.
15498
15499@value{GDBN}'s overlay commands all start with the word @code{overlay};
15500you can abbreviate this as @code{ov} or @code{ovly}.  The commands are:
15501
15502@table @code
15503@item overlay off
15504@kindex overlay
15505Disable @value{GDBN}'s overlay support.  When overlay support is
15506disabled, @value{GDBN} assumes that all functions and variables are
15507always present at their mapped addresses.  By default, @value{GDBN}'s
15508overlay support is disabled.
15509
15510@item overlay manual
15511@cindex manual overlay debugging
15512Enable @dfn{manual} overlay debugging.  In this mode, @value{GDBN}
15513relies on you to tell it which overlays are mapped, and which are not,
15514using the @code{overlay map-overlay} and @code{overlay unmap-overlay}
15515commands described below.
15516
15517@item overlay map-overlay @var{overlay}
15518@itemx overlay map @var{overlay}
15519@cindex map an overlay
15520Tell @value{GDBN} that @var{overlay} is now mapped; @var{overlay} must
15521be the name of the object file section containing the overlay.  When an
15522overlay is mapped, @value{GDBN} assumes it can find the overlay's
15523functions and variables at their mapped addresses.  @value{GDBN} assumes
15524that any other overlays whose mapped ranges overlap that of
15525@var{overlay} are now unmapped.
15526
15527@item overlay unmap-overlay @var{overlay}
15528@itemx overlay unmap @var{overlay}
15529@cindex unmap an overlay
15530Tell @value{GDBN} that @var{overlay} is no longer mapped; @var{overlay}
15531must be the name of the object file section containing the overlay.
15532When an overlay is unmapped, @value{GDBN} assumes it can find the
15533overlay's functions and variables at their load addresses.
15534
15535@item overlay auto
15536Enable @dfn{automatic} overlay debugging.  In this mode, @value{GDBN}
15537consults a data structure the overlay manager maintains in the inferior
15538to see which overlays are mapped.  For details, see @ref{Automatic
15539Overlay Debugging}.
15540
15541@item overlay load-target
15542@itemx overlay load
15543@cindex reloading the overlay table
15544Re-read the overlay table from the inferior.  Normally, @value{GDBN}
15545re-reads the table @value{GDBN} automatically each time the inferior
15546stops, so this command should only be necessary if you have changed the
15547overlay mapping yourself using @value{GDBN}.  This command is only
15548useful when using automatic overlay debugging.
15549
15550@item overlay list-overlays
15551@itemx overlay list
15552@cindex listing mapped overlays
15553Display a list of the overlays currently mapped, along with their mapped
15554addresses, load addresses, and sizes.
15555
15556@end table
15557
15558Normally, when @value{GDBN} prints a code address, it includes the name
15559of the function the address falls in:
15560
15561@smallexample
15562(@value{GDBP}) print main
15563$3 = @{int ()@} 0x11a0 <main>
15564@end smallexample
15565@noindent
15566When overlay debugging is enabled, @value{GDBN} recognizes code in
15567unmapped overlays, and prints the names of unmapped functions with
15568asterisks around them.  For example, if @code{foo} is a function in an
15569unmapped overlay, @value{GDBN} prints it this way:
15570
15571@smallexample
15572(@value{GDBP}) overlay list
15573No sections are mapped.
15574(@value{GDBP}) print foo
15575$5 = @{int (int)@} 0x100000 <*foo*>
15576@end smallexample
15577@noindent
15578When @code{foo}'s overlay is mapped, @value{GDBN} prints the function's
15579name normally:
15580
15581@smallexample
15582(@value{GDBP}) overlay list
15583Section .ov.foo.text, loaded at 0x100000 - 0x100034,
15584        mapped at 0x1016 - 0x104a
15585(@value{GDBP}) print foo
15586$6 = @{int (int)@} 0x1016 <foo>
15587@end smallexample
15588
15589When overlay debugging is enabled, @value{GDBN} can find the correct
15590address for functions and variables in an overlay, whether or not the
15591overlay is mapped.  This allows most @value{GDBN} commands, like
15592@code{break} and @code{disassemble}, to work normally, even on unmapped
15593code.  However, @value{GDBN}'s breakpoint support has some limitations:
15594
15595@itemize @bullet
15596@item
15597@cindex breakpoints in overlays
15598@cindex overlays, setting breakpoints in
15599You can set breakpoints in functions in unmapped overlays, as long as
15600@value{GDBN} can write to the overlay at its load address.
15601@item
15602@value{GDBN} can not set hardware or simulator-based breakpoints in
15603unmapped overlays.  However, if you set a breakpoint at the end of your
15604overlay manager (and tell @value{GDBN} which overlays are now mapped, if
15605you are using manual overlay management), @value{GDBN} will re-set its
15606breakpoints properly.
15607@end itemize
15608
15609
15610@node Automatic Overlay Debugging
15611@section Automatic Overlay Debugging
15612@cindex automatic overlay debugging
15613
15614@value{GDBN} can automatically track which overlays are mapped and which
15615are not, given some simple co-operation from the overlay manager in the
15616inferior.  If you enable automatic overlay debugging with the
15617@code{overlay auto} command (@pxref{Overlay Commands}), @value{GDBN}
15618looks in the inferior's memory for certain variables describing the
15619current state of the overlays.
15620
15621Here are the variables your overlay manager must define to support
15622@value{GDBN}'s automatic overlay debugging:
15623
15624@table @asis
15625
15626@item @code{_ovly_table}:
15627This variable must be an array of the following structures:
15628
15629@smallexample
15630struct
15631@{
15632  /* The overlay's mapped address.  */
15633  unsigned long vma;
15634
15635  /* The size of the overlay, in bytes.  */
15636  unsigned long size;
15637
15638  /* The overlay's load address.  */
15639  unsigned long lma;
15640
15641  /* Non-zero if the overlay is currently mapped;
15642     zero otherwise.  */
15643  unsigned long mapped;
15644@}
15645@end smallexample
15646
15647@item @code{_novlys}:
15648This variable must be a four-byte signed integer, holding the total
15649number of elements in @code{_ovly_table}.
15650
15651@end table
15652
15653To decide whether a particular overlay is mapped or not, @value{GDBN}
15654looks for an entry in @w{@code{_ovly_table}} whose @code{vma} and
15655@code{lma} members equal the VMA and LMA of the overlay's section in the
15656executable file.  When @value{GDBN} finds a matching entry, it consults
15657the entry's @code{mapped} member to determine whether the overlay is
15658currently mapped.
15659
15660In addition, your overlay manager may define a function called
15661@code{_ovly_debug_event}.  If this function is defined, @value{GDBN}
15662will silently set a breakpoint there.  If the overlay manager then
15663calls this function whenever it has changed the overlay table, this
15664will enable @value{GDBN} to accurately keep track of which overlays
15665are in program memory, and update any breakpoints that may be set
15666in overlays.  This will allow breakpoints to work even if the
15667overlays are kept in ROM or other non-writable memory while they
15668are not being executed.
15669
15670@node Overlay Sample Program
15671@section Overlay Sample Program
15672@cindex overlay example program
15673
15674When linking a program which uses overlays, you must place the overlays
15675at their load addresses, while relocating them to run at their mapped
15676addresses.  To do this, you must write a linker script (@pxref{Overlay
15677Description,,, ld.info, Using ld: the GNU linker}).  Unfortunately,
15678since linker scripts are specific to a particular host system, target
15679architecture, and target memory layout, this manual cannot provide
15680portable sample code demonstrating @value{GDBN}'s overlay support.
15681
15682However, the @value{GDBN} source distribution does contain an overlaid
15683program, with linker scripts for a few systems, as part of its test
15684suite.  The program consists of the following files from
15685@file{gdb/testsuite/gdb.base}:
15686
15687@table @file
15688@item overlays.c
15689The main program file.
15690@item ovlymgr.c
15691A simple overlay manager, used by @file{overlays.c}.
15692@item foo.c
15693@itemx bar.c
15694@itemx baz.c
15695@itemx grbx.c
15696Overlay modules, loaded and used by @file{overlays.c}.
15697@item d10v.ld
15698@itemx m32r.ld
15699Linker scripts for linking the test program on the @code{d10v-elf}
15700and @code{m32r-elf} targets.
15701@end table
15702
15703You can build the test program using the @code{d10v-elf} GCC
15704cross-compiler like this:
15705
15706@smallexample
15707$ d10v-elf-gcc -g -c overlays.c
15708$ d10v-elf-gcc -g -c ovlymgr.c
15709$ d10v-elf-gcc -g -c foo.c
15710$ d10v-elf-gcc -g -c bar.c
15711$ d10v-elf-gcc -g -c baz.c
15712$ d10v-elf-gcc -g -c grbx.c
15713$ d10v-elf-gcc -g overlays.o ovlymgr.o foo.o bar.o \
15714                  baz.o grbx.o -Wl,-Td10v.ld -o overlays
15715@end smallexample
15716
15717The build process is identical for any other architecture, except that
15718you must substitute the appropriate compiler and linker script for the
15719target system for @code{d10v-elf-gcc} and @code{d10v.ld}.
15720
15721
15722@node Languages
15723@chapter Using @value{GDBN} with Different Languages
15724@cindex languages
15725
15726Although programming languages generally have common aspects, they are
15727rarely expressed in the same manner.  For instance, in ANSI C,
15728dereferencing a pointer @code{p} is accomplished by @code{*p}, but in
15729Modula-2, it is accomplished by @code{p^}.  Values can also be
15730represented (and displayed) differently.  Hex numbers in C appear as
15731@samp{0x1ae}, while in Modula-2 they appear as @samp{1AEH}.
15732
15733@cindex working language
15734Language-specific information is built into @value{GDBN} for some languages,
15735allowing you to express operations like the above in your program's
15736native language, and allowing @value{GDBN} to output values in a manner
15737consistent with the syntax of your program's native language.  The
15738language you use to build expressions is called the @dfn{working
15739language}.
15740
15741@menu
15742* Setting::                     Switching between source languages
15743* Show::                        Displaying the language
15744* Checks::                      Type and range checks
15745* Supported Languages::         Supported languages
15746* Unsupported Languages::       Unsupported languages
15747@end menu
15748
15749@node Setting
15750@section Switching Between Source Languages
15751
15752There are two ways to control the working language---either have @value{GDBN}
15753set it automatically, or select it manually yourself.  You can use the
15754@code{set language} command for either purpose.  On startup, @value{GDBN}
15755defaults to setting the language automatically.  The working language is
15756used to determine how expressions you type are interpreted, how values
15757are printed, etc.
15758
15759In addition to the working language, every source file that
15760@value{GDBN} knows about has its own working language.  For some object
15761file formats, the compiler might indicate which language a particular
15762source file is in.  However, most of the time @value{GDBN} infers the
15763language from the name of the file.  The language of a source file
15764controls whether C@t{++} names are demangled---this way @code{backtrace} can
15765show each frame appropriately for its own language.  There is no way to
15766set the language of a source file from within @value{GDBN}, but you can
15767set the language associated with a filename extension.  @xref{Show, ,
15768Displaying the Language}.
15769
15770This is most commonly a problem when you use a program, such
15771as @code{cfront} or @code{f2c}, that generates C but is written in
15772another language.  In that case, make the
15773program use @code{#line} directives in its C output; that way
15774@value{GDBN} will know the correct language of the source code of the original
15775program, and will display that source code, not the generated C code.
15776
15777@menu
15778* Filenames::                   Filename extensions and languages.
15779* Manually::                    Setting the working language manually
15780* Automatically::               Having @value{GDBN} infer the source language
15781@end menu
15782
15783@node Filenames
15784@subsection List of Filename Extensions and Languages
15785
15786If a source file name ends in one of the following extensions, then
15787@value{GDBN} infers that its language is the one indicated.
15788
15789@table @file
15790@item .ada
15791@itemx .ads
15792@itemx .adb
15793@itemx .a
15794Ada source file.
15795
15796@item .c
15797C source file
15798
15799@item .C
15800@itemx .cc
15801@itemx .cp
15802@itemx .cpp
15803@itemx .cxx
15804@itemx .c++
15805C@t{++} source file
15806
15807@item .d
15808D source file
15809
15810@item .m
15811Objective-C source file
15812
15813@item .f
15814@itemx .F
15815Fortran source file
15816
15817@item .mod
15818Modula-2 source file
15819
15820@item .s
15821@itemx .S
15822Assembler source file.  This actually behaves almost like C, but
15823@value{GDBN} does not skip over function prologues when stepping.
15824@end table
15825
15826In addition, you may set the language associated with a filename
15827extension.  @xref{Show, , Displaying the Language}.
15828
15829@node Manually
15830@subsection Setting the Working Language
15831
15832If you allow @value{GDBN} to set the language automatically,
15833expressions are interpreted the same way in your debugging session and
15834your program.
15835
15836@kindex set language
15837If you wish, you may set the language manually.  To do this, issue the
15838command @samp{set language @var{lang}}, where @var{lang} is the name of
15839a language, such as
15840@code{c} or @code{modula-2}.
15841For a list of the supported languages, type @samp{set language}.
15842
15843Setting the language manually prevents @value{GDBN} from updating the working
15844language automatically.  This can lead to confusion if you try
15845to debug a program when the working language is not the same as the
15846source language, when an expression is acceptable to both
15847languages---but means different things.  For instance, if the current
15848source file were written in C, and @value{GDBN} was parsing Modula-2, a
15849command such as:
15850
15851@smallexample
15852print a = b + c
15853@end smallexample
15854
15855@noindent
15856might not have the effect you intended.  In C, this means to add
15857@code{b} and @code{c} and place the result in @code{a}.  The result
15858printed would be the value of @code{a}.  In Modula-2, this means to compare
15859@code{a} to the result of @code{b+c}, yielding a @code{BOOLEAN} value.
15860
15861@node Automatically
15862@subsection Having @value{GDBN} Infer the Source Language
15863
15864To have @value{GDBN} set the working language automatically, use
15865@samp{set language local} or @samp{set language auto}.  @value{GDBN}
15866then infers the working language.  That is, when your program stops in a
15867frame (usually by encountering a breakpoint), @value{GDBN} sets the
15868working language to the language recorded for the function in that
15869frame.  If the language for a frame is unknown (that is, if the function
15870or block corresponding to the frame was defined in a source file that
15871does not have a recognized extension), the current working language is
15872not changed, and @value{GDBN} issues a warning.
15873
15874This may not seem necessary for most programs, which are written
15875entirely in one source language.  However, program modules and libraries
15876written in one source language can be used by a main program written in
15877a different source language.  Using @samp{set language auto} in this
15878case frees you from having to set the working language manually.
15879
15880@node Show
15881@section Displaying the Language
15882
15883The following commands help you find out which language is the
15884working language, and also what language source files were written in.
15885
15886@table @code
15887@item show language
15888@anchor{show language}
15889@kindex show language
15890Display the current working language.  This is the
15891language you can use with commands such as @code{print} to
15892build and compute expressions that may involve variables in your program.
15893
15894@item info frame
15895@kindex info frame@r{, show the source language}
15896Display the source language for this frame.  This language becomes the
15897working language if you use an identifier from this frame.
15898@xref{Frame Info, ,Information about a Frame}, to identify the other
15899information listed here.
15900
15901@item info source
15902@kindex info source@r{, show the source language}
15903Display the source language of this source file.
15904@xref{Symbols, ,Examining the Symbol Table}, to identify the other
15905information listed here.
15906@end table
15907
15908In unusual circumstances, you may have source files with extensions
15909not in the standard list.  You can then set the extension associated
15910with a language explicitly:
15911
15912@table @code
15913@item set extension-language @var{ext} @var{language}
15914@kindex set extension-language
15915Tell @value{GDBN} that source files with extension @var{ext} are to be
15916assumed as written in the source language @var{language}.
15917
15918@item info extensions
15919@kindex info extensions
15920List all the filename extensions and the associated languages.
15921@end table
15922
15923@node Checks
15924@section Type and Range Checking
15925
15926Some languages are designed to guard you against making seemingly common
15927errors through a series of compile- and run-time checks.  These include
15928checking the type of arguments to functions and operators and making
15929sure mathematical overflows are caught at run time.  Checks such as
15930these help to ensure a program's correctness once it has been compiled
15931by eliminating type mismatches and providing active checks for range
15932errors when your program is running.
15933
15934By default @value{GDBN} checks for these errors according to the
15935rules of the current source language.  Although @value{GDBN} does not check
15936the statements in your program, it can check expressions entered directly
15937into @value{GDBN} for evaluation via the @code{print} command, for example.
15938
15939@menu
15940* Type Checking::               An overview of type checking
15941* Range Checking::              An overview of range checking
15942@end menu
15943
15944@cindex type checking
15945@cindex checks, type
15946@node Type Checking
15947@subsection An Overview of Type Checking
15948
15949Some languages, such as C and C@t{++}, are strongly typed, meaning that the
15950arguments to operators and functions have to be of the correct type,
15951otherwise an error occurs.  These checks prevent type mismatch
15952errors from ever causing any run-time problems.  For example,
15953
15954@smallexample
15955int klass::my_method(char *b) @{ return  b ? 1 : 2; @}
15956
15957(@value{GDBP}) print obj.my_method (0)
15958$1 = 2
15959@exdent but
15960(@value{GDBP}) print obj.my_method (0x1234)
15961Cannot resolve method klass::my_method to any overloaded instance
15962@end smallexample
15963
15964The second example fails because in C@t{++} the integer constant
15965@samp{0x1234} is not type-compatible with the pointer parameter type.
15966
15967For the expressions you use in @value{GDBN} commands, you can tell
15968@value{GDBN} to not enforce strict type checking or
15969to treat any mismatches as errors and abandon the expression;
15970When type checking is disabled, @value{GDBN} successfully evaluates
15971expressions like the second example above.
15972
15973Even if type checking is off, there may be other reasons
15974related to type that prevent @value{GDBN} from evaluating an expression.
15975For instance, @value{GDBN} does not know how to add an @code{int} and
15976a @code{struct foo}.  These particular type errors have nothing to do
15977with the language in use and usually arise from expressions which make
15978little sense to evaluate anyway.
15979
15980@value{GDBN} provides some additional commands for controlling type checking:
15981
15982@kindex set check type
15983@kindex show check type
15984@table @code
15985@item set check type on
15986@itemx set check type off
15987Set strict type checking on or off.  If any type mismatches occur in
15988evaluating an expression while type checking is on, @value{GDBN} prints a
15989message and aborts evaluation of the expression.
15990
15991@item show check type
15992Show the current setting of type checking and whether @value{GDBN}
15993is enforcing strict type checking rules.
15994@end table
15995
15996@cindex range checking
15997@cindex checks, range
15998@node Range Checking
15999@subsection An Overview of Range Checking
16000
16001In some languages (such as Modula-2), it is an error to exceed the
16002bounds of a type; this is enforced with run-time checks.  Such range
16003checking is meant to ensure program correctness by making sure
16004computations do not overflow, or indices on an array element access do
16005not exceed the bounds of the array.
16006
16007For expressions you use in @value{GDBN} commands, you can tell
16008@value{GDBN} to treat range errors in one of three ways: ignore them,
16009always treat them as errors and abandon the expression, or issue
16010warnings but evaluate the expression anyway.
16011
16012A range error can result from numerical overflow, from exceeding an
16013array index bound, or when you type a constant that is not a member
16014of any type.  Some languages, however, do not treat overflows as an
16015error.  In many implementations of C, mathematical overflow causes the
16016result to ``wrap around'' to lower values---for example, if @var{m} is
16017the largest integer value, and @var{s} is the smallest, then
16018
16019@smallexample
16020@var{m} + 1 @result{} @var{s}
16021@end smallexample
16022
16023This, too, is specific to individual languages, and in some cases
16024specific to individual compilers or machines.  @xref{Supported Languages, ,
16025Supported Languages}, for further details on specific languages.
16026
16027@value{GDBN} provides some additional commands for controlling the range checker:
16028
16029@kindex set check range
16030@kindex show check range
16031@table @code
16032@item set check range auto
16033Set range checking on or off based on the current working language.
16034@xref{Supported Languages, ,Supported Languages}, for the default settings for
16035each language.
16036
16037@item set check range on
16038@itemx set check range off
16039Set range checking on or off, overriding the default setting for the
16040current working language.  A warning is issued if the setting does not
16041match the language default.  If a range error occurs and range checking is on,
16042then a message is printed and evaluation of the expression is aborted.
16043
16044@item set check range warn
16045Output messages when the @value{GDBN} range checker detects a range error,
16046but attempt to evaluate the expression anyway.  Evaluating the
16047expression may still be impossible for other reasons, such as accessing
16048memory that the process does not own (a typical example from many Unix
16049systems).
16050
16051@item show range
16052Show the current setting of the range checker, and whether or not it is
16053being set automatically by @value{GDBN}.
16054@end table
16055
16056@node Supported Languages
16057@section Supported Languages
16058
16059@value{GDBN} supports C, C@t{++}, D, Go, Objective-C, Fortran,
16060OpenCL C, Pascal, Rust, assembly, Modula-2, and Ada.
16061@c This is false ...
16062Some @value{GDBN} features may be used in expressions regardless of the
16063language you use: the @value{GDBN} @code{@@} and @code{::} operators,
16064and the @samp{@{type@}addr} construct (@pxref{Expressions,
16065,Expressions}) can be used with the constructs of any supported
16066language.
16067
16068The following sections detail to what degree each source language is
16069supported by @value{GDBN}.  These sections are not meant to be language
16070tutorials or references, but serve only as a reference guide to what the
16071@value{GDBN} expression parser accepts, and what input and output
16072formats should look like for different languages.  There are many good
16073books written on each of these languages; please look to these for a
16074language reference or tutorial.
16075
16076@menu
16077* C::                           C and C@t{++}
16078* D::                           D
16079* Go::                          Go
16080* Objective-C::                 Objective-C
16081* OpenCL C::                    OpenCL C
16082* Fortran::                     Fortran
16083* Pascal::                      Pascal
16084* Rust::                        Rust
16085* Modula-2::                    Modula-2
16086* Ada::                         Ada
16087@end menu
16088
16089@node C
16090@subsection C and C@t{++}
16091
16092@cindex C and C@t{++}
16093@cindex expressions in C or C@t{++}
16094
16095Since C and C@t{++} are so closely related, many features of @value{GDBN} apply
16096to both languages.  Whenever this is the case, we discuss those languages
16097together.
16098
16099@cindex C@t{++}
16100@cindex @code{g++}, @sc{gnu} C@t{++} compiler
16101@cindex @sc{gnu} C@t{++}
16102The C@t{++} debugging facilities are jointly implemented by the C@t{++}
16103compiler and @value{GDBN}.  Therefore, to debug your C@t{++} code
16104effectively, you must compile your C@t{++} programs with a supported
16105C@t{++} compiler, such as @sc{gnu} @code{g++}, or the HP ANSI C@t{++}
16106compiler (@code{aCC}).
16107
16108@menu
16109* C Operators::                 C and C@t{++} operators
16110* C Constants::                 C and C@t{++} constants
16111* C Plus Plus Expressions::     C@t{++} expressions
16112* C Defaults::                  Default settings for C and C@t{++}
16113* C Checks::                    C and C@t{++} type and range checks
16114* Debugging C::                 @value{GDBN} and C
16115* Debugging C Plus Plus::       @value{GDBN} features for C@t{++}
16116* Decimal Floating Point::      Numbers in Decimal Floating Point format
16117@end menu
16118
16119@node C Operators
16120@subsubsection C and C@t{++} Operators
16121
16122@cindex C and C@t{++} operators
16123
16124Operators must be defined on values of specific types.  For instance,
16125@code{+} is defined on numbers, but not on structures.  Operators are
16126often defined on groups of types.
16127
16128For the purposes of C and C@t{++}, the following definitions hold:
16129
16130@itemize @bullet
16131
16132@item
16133@emph{Integral types} include @code{int} with any of its storage-class
16134specifiers; @code{char}; @code{enum}; and, for C@t{++}, @code{bool}.
16135
16136@item
16137@emph{Floating-point types} include @code{float}, @code{double}, and
16138@code{long double} (if supported by the target platform).
16139
16140@item
16141@emph{Pointer types} include all types defined as @code{(@var{type} *)}.
16142
16143@item
16144@emph{Scalar types} include all of the above.
16145
16146@end itemize
16147
16148@noindent
16149The following operators are supported.  They are listed here
16150in order of increasing precedence:
16151
16152@table @code
16153@item ,
16154The comma or sequencing operator.  Expressions in a comma-separated list
16155are evaluated from left to right, with the result of the entire
16156expression being the last expression evaluated.
16157
16158@item =
16159Assignment.  The value of an assignment expression is the value
16160assigned.  Defined on scalar types.
16161
16162@item @var{op}=
16163Used in an expression of the form @w{@code{@var{a} @var{op}= @var{b}}},
16164and translated to @w{@code{@var{a} = @var{a op b}}}.
16165@w{@code{@var{op}=}} and @code{=} have the same precedence.  The operator
16166@var{op} is any one of the operators @code{|}, @code{^}, @code{&},
16167@code{<<}, @code{>>}, @code{+}, @code{-}, @code{*}, @code{/}, @code{%}.
16168
16169@item ?:
16170The ternary operator.  @code{@var{a} ? @var{b} : @var{c}} can be thought
16171of as:  if @var{a} then @var{b} else @var{c}.  The argument @var{a}
16172should be of an integral type.
16173
16174@item ||
16175Logical @sc{or}.  Defined on integral types.
16176
16177@item &&
16178Logical @sc{and}.  Defined on integral types.
16179
16180@item |
16181Bitwise @sc{or}.  Defined on integral types.
16182
16183@item ^
16184Bitwise exclusive-@sc{or}.  Defined on integral types.
16185
16186@item &
16187Bitwise @sc{and}.  Defined on integral types.
16188
16189@item ==@r{, }!=
16190Equality and inequality.  Defined on scalar types.  The value of these
16191expressions is 0 for false and non-zero for true.
16192
16193@item <@r{, }>@r{, }<=@r{, }>=
16194Less than, greater than, less than or equal, greater than or equal.
16195Defined on scalar types.  The value of these expressions is 0 for false
16196and non-zero for true.
16197
16198@item <<@r{, }>>
16199left shift, and right shift.  Defined on integral types.
16200
16201@item @@
16202The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
16203
16204@item +@r{, }-
16205Addition and subtraction.  Defined on integral types, floating-point types and
16206pointer types.
16207
16208@item *@r{, }/@r{, }%
16209Multiplication, division, and modulus.  Multiplication and division are
16210defined on integral and floating-point types.  Modulus is defined on
16211integral types.
16212
16213@item ++@r{, }--
16214Increment and decrement.  When appearing before a variable, the
16215operation is performed before the variable is used in an expression;
16216when appearing after it, the variable's value is used before the
16217operation takes place.
16218
16219@item *
16220Pointer dereferencing.  Defined on pointer types.  Same precedence as
16221@code{++}.
16222
16223@item &
16224Address operator.  Defined on variables.  Same precedence as @code{++}.
16225
16226For debugging C@t{++}, @value{GDBN} implements a use of @samp{&} beyond what is
16227allowed in the C@t{++} language itself: you can use @samp{&(&@var{ref})}
16228to examine the address
16229where a C@t{++} reference variable (declared with @samp{&@var{ref}}) is
16230stored.
16231
16232@item -
16233Negative.  Defined on integral and floating-point types.  Same
16234precedence as @code{++}.
16235
16236@item !
16237Logical negation.  Defined on integral types.  Same precedence as
16238@code{++}.
16239
16240@item ~
16241Bitwise complement operator.  Defined on integral types.  Same precedence as
16242@code{++}.
16243
16244
16245@item .@r{, }->
16246Structure member, and pointer-to-structure member.  For convenience,
16247@value{GDBN} regards the two as equivalent, choosing whether to dereference a
16248pointer based on the stored type information.
16249Defined on @code{struct} and @code{union} data.
16250
16251@item .*@r{, }->*
16252Dereferences of pointers to members.
16253
16254@item []
16255Array indexing.  @code{@var{a}[@var{i}]} is defined as
16256@code{*(@var{a}+@var{i})}.  Same precedence as @code{->}.
16257
16258@item ()
16259Function parameter list.  Same precedence as @code{->}.
16260
16261@item ::
16262C@t{++} scope resolution operator.  Defined on @code{struct}, @code{union},
16263and @code{class} types.
16264
16265@item ::
16266Doubled colons also represent the @value{GDBN} scope operator
16267(@pxref{Expressions, ,Expressions}).  Same precedence as @code{::},
16268above.
16269@end table
16270
16271If an operator is redefined in the user code, @value{GDBN} usually
16272attempts to invoke the redefined version instead of using the operator's
16273predefined meaning.
16274
16275@node C Constants
16276@subsubsection C and C@t{++} Constants
16277
16278@cindex C and C@t{++} constants
16279
16280@value{GDBN} allows you to express the constants of C and C@t{++} in the
16281following ways:
16282
16283@itemize @bullet
16284@item
16285Integer constants are a sequence of digits.  Octal constants are
16286specified by a leading @samp{0} (i.e.@: zero), and hexadecimal constants
16287by a leading @samp{0x} or @samp{0X}.  Constants may also end with a letter
16288@samp{l}, specifying that the constant should be treated as a
16289@code{long} value.
16290
16291@item
16292Floating point constants are a sequence of digits, followed by a decimal
16293point, followed by a sequence of digits, and optionally followed by an
16294exponent.  An exponent is of the form:
16295@samp{@w{e@r{[[}+@r{]|}-@r{]}@var{nnn}}}, where @var{nnn} is another
16296sequence of digits.  The @samp{+} is optional for positive exponents.
16297A floating-point constant may also end with a letter @samp{f} or
16298@samp{F}, specifying that the constant should be treated as being of
16299the @code{float} (as opposed to the default @code{double}) type; or with
16300a letter @samp{l} or @samp{L}, which specifies a @code{long double}
16301constant.
16302
16303@item
16304Enumerated constants consist of enumerated identifiers, or their
16305integral equivalents.
16306
16307@item
16308Character constants are a single character surrounded by single quotes
16309(@code{'}), or a number---the ordinal value of the corresponding character
16310(usually its @sc{ascii} value).  Within quotes, the single character may
16311be represented by a letter or by @dfn{escape sequences}, which are of
16312the form @samp{\@var{nnn}}, where @var{nnn} is the octal representation
16313of the character's ordinal value; or of the form @samp{\@var{x}}, where
16314@samp{@var{x}} is a predefined special character---for example,
16315@samp{\n} for newline.
16316
16317Wide character constants can be written by prefixing a character
16318constant with @samp{L}, as in C.  For example, @samp{L'x'} is the wide
16319form of @samp{x}.  The target wide character set is used when
16320computing the value of this constant (@pxref{Character Sets}).
16321
16322@item
16323String constants are a sequence of character constants surrounded by
16324double quotes (@code{"}).  Any valid character constant (as described
16325above) may appear.  Double quotes within the string must be preceded by
16326a backslash, so for instance @samp{"a\"b'c"} is a string of five
16327characters.
16328
16329Wide string constants can be written by prefixing a string constant
16330with @samp{L}, as in C.  The target wide character set is used when
16331computing the value of this constant (@pxref{Character Sets}).
16332
16333@item
16334Pointer constants are an integral value.  You can also write pointers
16335to constants using the C operator @samp{&}.
16336
16337@item
16338Array constants are comma-separated lists surrounded by braces @samp{@{}
16339and @samp{@}}; for example, @samp{@{1,2,3@}} is a three-element array of
16340integers, @samp{@{@{1,2@}, @{3,4@}, @{5,6@}@}} is a three-by-two array,
16341and @samp{@{&"hi", &"there", &"fred"@}} is a three-element array of pointers.
16342@end itemize
16343
16344@node C Plus Plus Expressions
16345@subsubsection C@t{++} Expressions
16346
16347@cindex expressions in C@t{++}
16348@value{GDBN} expression handling can interpret most C@t{++} expressions.
16349
16350@cindex debugging C@t{++} programs
16351@cindex C@t{++} compilers
16352@cindex debug formats and C@t{++}
16353@cindex @value{NGCC} and C@t{++}
16354@quotation
16355@emph{Warning:} @value{GDBN} can only debug C@t{++} code if you use
16356the proper compiler and the proper debug format.  Currently,
16357@value{GDBN} works best when debugging C@t{++} code that is compiled
16358with the most recent version of @value{NGCC} possible.  The DWARF
16359debugging format is preferred; @value{NGCC} defaults to this on most
16360popular platforms.  Other compilers and/or debug formats are likely to
16361work badly or not at all when using @value{GDBN} to debug C@t{++}
16362code.  @xref{Compilation}.
16363@end quotation
16364
16365@enumerate
16366
16367@cindex member functions
16368@item
16369Member function calls are allowed; you can use expressions like
16370
16371@smallexample
16372count = aml->GetOriginal(x, y)
16373@end smallexample
16374
16375@vindex this@r{, inside C@t{++} member functions}
16376@cindex namespace in C@t{++}
16377@item
16378While a member function is active (in the selected stack frame), your
16379expressions have the same namespace available as the member function;
16380that is, @value{GDBN} allows implicit references to the class instance
16381pointer @code{this} following the same rules as C@t{++}.  @code{using}
16382declarations in the current scope are also respected by @value{GDBN}.
16383
16384@cindex call overloaded functions
16385@cindex overloaded functions, calling
16386@cindex type conversions in C@t{++}
16387@item
16388You can call overloaded functions; @value{GDBN} resolves the function
16389call to the right definition, with some restrictions.  @value{GDBN} does not
16390perform overload resolution involving user-defined type conversions,
16391calls to constructors, or instantiations of templates that do not exist
16392in the program.  It also cannot handle ellipsis argument lists or
16393default arguments.
16394
16395It does perform integral conversions and promotions, floating-point
16396promotions, arithmetic conversions, pointer conversions, conversions of
16397class objects to base classes, and standard conversions such as those of
16398functions or arrays to pointers; it requires an exact match on the
16399number of function arguments.
16400
16401Overload resolution is always performed, unless you have specified
16402@code{set overload-resolution off}.  @xref{Debugging C Plus Plus,
16403,@value{GDBN} Features for C@t{++}}.
16404
16405You must specify @code{set overload-resolution off} in order to use an
16406explicit function signature to call an overloaded function, as in
16407@smallexample
16408p 'foo(char,int)'('x', 13)
16409@end smallexample
16410
16411The @value{GDBN} command-completion facility can simplify this;
16412see @ref{Completion, ,Command Completion}.
16413
16414@cindex reference declarations
16415@item
16416@value{GDBN} understands variables declared as C@t{++} lvalue or rvalue
16417references; you can use them in expressions just as you do in C@t{++}
16418source---they are automatically dereferenced.
16419
16420In the parameter list shown when @value{GDBN} displays a frame, the values of
16421reference variables are not displayed (unlike other variables); this
16422avoids clutter, since references are often used for large structures.
16423The @emph{address} of a reference variable is always shown, unless
16424you have specified @samp{set print address off}.
16425
16426@item
16427@value{GDBN} supports the C@t{++} name resolution operator @code{::}---your
16428expressions can use it just as expressions in your program do.  Since
16429one scope may be defined in another, you can use @code{::} repeatedly if
16430necessary, for example in an expression like
16431@samp{@var{scope1}::@var{scope2}::@var{name}}.  @value{GDBN} also allows
16432resolving name scope by reference to source files, in both C and C@t{++}
16433debugging (@pxref{Variables, ,Program Variables}).
16434
16435@item
16436@value{GDBN} performs argument-dependent lookup, following the C@t{++}
16437specification.
16438@end enumerate
16439
16440@node C Defaults
16441@subsubsection C and C@t{++} Defaults
16442
16443@cindex C and C@t{++} defaults
16444
16445If you allow @value{GDBN} to set range checking automatically, it
16446defaults to @code{off} whenever the working language changes to
16447C or C@t{++}.  This happens regardless of whether you or @value{GDBN}
16448selects the working language.
16449
16450If you allow @value{GDBN} to set the language automatically, it
16451recognizes source files whose names end with @file{.c}, @file{.C}, or
16452@file{.cc}, etc, and when @value{GDBN} enters code compiled from one of
16453these files, it sets the working language to C or C@t{++}.
16454@xref{Automatically, ,Having @value{GDBN} Infer the Source Language},
16455for further details.
16456
16457@node C Checks
16458@subsubsection C and C@t{++} Type and Range Checks
16459
16460@cindex C and C@t{++} checks
16461
16462By default, when @value{GDBN} parses C or C@t{++} expressions, strict type
16463checking is used.  However, if you turn type checking off, @value{GDBN}
16464will allow certain non-standard conversions, such as promoting integer
16465constants to pointers.
16466
16467Range checking, if turned on, is done on mathematical operations.  Array
16468indices are not checked, since they are often used to index a pointer
16469that is not itself an array.
16470
16471@node Debugging C
16472@subsubsection @value{GDBN} and C
16473
16474The @code{set print union} and @code{show print union} commands apply to
16475the @code{union} type.  When set to @samp{on}, any @code{union} that is
16476inside a @code{struct} or @code{class} is also printed.  Otherwise, it
16477appears as @samp{@{...@}}.
16478
16479The @code{@@} operator aids in the debugging of dynamic arrays, formed
16480with pointers and a memory allocation function.  @xref{Expressions,
16481,Expressions}.
16482
16483@node Debugging C Plus Plus
16484@subsubsection @value{GDBN} Features for C@t{++}
16485
16486@cindex commands for C@t{++}
16487
16488Some @value{GDBN} commands are particularly useful with C@t{++}, and some are
16489designed specifically for use with C@t{++}.  Here is a summary:
16490
16491@table @code
16492@cindex break in overloaded functions
16493@item @r{breakpoint menus}
16494When you want a breakpoint in a function whose name is overloaded,
16495@value{GDBN} has the capability to display a menu of possible breakpoint
16496locations to help you specify which function definition you want.
16497@xref{Ambiguous Expressions,,Ambiguous Expressions}.
16498
16499@cindex overloading in C@t{++}
16500@item rbreak @var{regex}
16501Setting breakpoints using regular expressions is helpful for setting
16502breakpoints on overloaded functions that are not members of any special
16503classes.
16504@xref{Set Breaks, ,Setting Breakpoints}.
16505
16506@cindex C@t{++} exception handling
16507@item catch throw
16508@itemx catch rethrow
16509@itemx catch catch
16510Debug C@t{++} exception handling using these commands.  @xref{Set
16511Catchpoints, , Setting Catchpoints}.
16512
16513@cindex inheritance
16514@item ptype @var{typename}
16515Print inheritance relationships as well as other information for type
16516@var{typename}.
16517@xref{Symbols, ,Examining the Symbol Table}.
16518
16519@item info vtbl @var{expression}.
16520The @code{info vtbl} command can be used to display the virtual
16521method tables of the object computed by @var{expression}.  This shows
16522one entry per virtual table; there may be multiple virtual tables when
16523multiple inheritance is in use.
16524
16525@cindex C@t{++} demangling
16526@item demangle @var{name}
16527Demangle @var{name}.
16528@xref{Symbols}, for a more complete description of the @code{demangle} command.
16529
16530@cindex C@t{++} symbol display
16531@item set print demangle
16532@itemx show print demangle
16533@itemx set print asm-demangle
16534@itemx show print asm-demangle
16535Control whether C@t{++} symbols display in their source form, both when
16536displaying code as C@t{++} source and when displaying disassemblies.
16537@xref{Print Settings, ,Print Settings}.
16538
16539@item set print object
16540@itemx show print object
16541Choose whether to print derived (actual) or declared types of objects.
16542@xref{Print Settings, ,Print Settings}.
16543
16544@item set print vtbl
16545@itemx show print vtbl
16546Control the format for printing virtual function tables.
16547@xref{Print Settings, ,Print Settings}.
16548(The @code{vtbl} commands do not work on programs compiled with the HP
16549ANSI C@t{++} compiler (@code{aCC}).)
16550
16551@kindex set overload-resolution
16552@cindex overloaded functions, overload resolution
16553@item set overload-resolution on
16554Enable overload resolution for C@t{++} expression evaluation.  The default
16555is on.  For overloaded functions, @value{GDBN} evaluates the arguments
16556and searches for a function whose signature matches the argument types,
16557using the standard C@t{++} conversion rules (see @ref{C Plus Plus
16558Expressions, ,C@t{++} Expressions}, for details).
16559If it cannot find a match, it emits a message.
16560
16561@item set overload-resolution off
16562Disable overload resolution for C@t{++} expression evaluation.  For
16563overloaded functions that are not class member functions, @value{GDBN}
16564chooses the first function of the specified name that it finds in the
16565symbol table, whether or not its arguments are of the correct type.  For
16566overloaded functions that are class member functions, @value{GDBN}
16567searches for a function whose signature @emph{exactly} matches the
16568argument types.
16569
16570@kindex show overload-resolution
16571@item show overload-resolution
16572Show the current setting of overload resolution.
16573
16574@item @r{Overloaded symbol names}
16575You can specify a particular definition of an overloaded symbol, using
16576the same notation that is used to declare such symbols in C@t{++}: type
16577@code{@var{symbol}(@var{types})} rather than just @var{symbol}.  You can
16578also use the @value{GDBN} command-line word completion facilities to list the
16579available choices, or to finish the type list for you.
16580@xref{Completion,, Command Completion}, for details on how to do this.
16581
16582@item @r{Breakpoints in functions with ABI tags}
16583
16584The GNU C@t{++} compiler introduced the notion of ABI ``tags'', which
16585correspond to changes in the ABI of a type, function, or variable that
16586would not otherwise be reflected in a mangled name.  See
16587@url{https://developers.redhat.com/blog/2015/02/05/gcc5-and-the-c11-abi/}
16588for more detail.
16589
16590The ABI tags are visible in C@t{++} demangled names.  For example, a
16591function that returns a std::string:
16592
16593@smallexample
16594std::string function(int);
16595@end smallexample
16596
16597@noindent
16598when compiled for the C++11 ABI is marked with the @code{cxx11} ABI
16599tag, and @value{GDBN} displays the symbol like this:
16600
16601@smallexample
16602function[abi:cxx11](int)
16603@end smallexample
16604
16605You can set a breakpoint on such functions simply as if they had no
16606tag.  For example:
16607
16608@smallexample
16609(gdb) b function(int)
16610Breakpoint 2 at 0x40060d: file main.cc, line 10.
16611(gdb) info breakpoints
16612Num     Type           Disp Enb Address    What
166131       breakpoint     keep y   0x0040060d in function[abi:cxx11](int)
16614                                           at main.cc:10
16615@end smallexample
16616
16617On the rare occasion you need to disambiguate between different ABI
16618tags, you can do so by simply including the ABI tag in the function
16619name, like:
16620
16621@smallexample
16622(@value{GDBP}) b ambiguous[abi:other_tag](int)
16623@end smallexample
16624@end table
16625
16626@node Decimal Floating Point
16627@subsubsection Decimal Floating Point format
16628@cindex decimal floating point format
16629
16630@value{GDBN} can examine, set and perform computations with numbers in
16631decimal floating point format, which in the C language correspond to the
16632@code{_Decimal32}, @code{_Decimal64} and @code{_Decimal128} types as
16633specified by the extension to support decimal floating-point arithmetic.
16634
16635There are two encodings in use, depending on the architecture: BID (Binary
16636Integer Decimal) for x86 and x86-64, and DPD (Densely Packed Decimal) for
16637PowerPC and S/390.  @value{GDBN} will use the appropriate encoding for the
16638configured target.
16639
16640Because of a limitation in @file{libdecnumber}, the library used by @value{GDBN}
16641to manipulate decimal floating point numbers, it is not possible to convert
16642(using a cast, for example) integers wider than 32-bit to decimal float.
16643
16644In addition, in order to imitate @value{GDBN}'s behaviour with binary floating
16645point computations, error checking in decimal float operations ignores
16646underflow, overflow and divide by zero exceptions.
16647
16648In the PowerPC architecture, @value{GDBN} provides a set of pseudo-registers
16649to inspect @code{_Decimal128} values stored in floating point registers.
16650See @ref{PowerPC,,PowerPC} for more details.
16651
16652@node D
16653@subsection D
16654
16655@cindex D
16656@value{GDBN} can be used to debug programs written in D and compiled with
16657GDC, LDC or DMD compilers. Currently @value{GDBN} supports only one D
16658specific feature --- dynamic arrays.
16659
16660@node Go
16661@subsection Go
16662
16663@cindex Go (programming language)
16664@value{GDBN} can be used to debug programs written in Go and compiled with
16665@file{gccgo} or @file{6g} compilers.
16666
16667Here is a summary of the Go-specific features and restrictions:
16668
16669@table @code
16670@cindex current Go package
16671@item The current Go package
16672The name of the current package does not need to be specified when
16673specifying global variables and functions.
16674
16675For example, given the program:
16676
16677@example
16678package main
16679var myglob = "Shall we?"
16680func main () @{
16681  // ...
16682@}
16683@end example
16684
16685When stopped inside @code{main} either of these work:
16686
16687@example
16688(gdb) p myglob
16689(gdb) p main.myglob
16690@end example
16691
16692@cindex builtin Go types
16693@item Builtin Go types
16694The @code{string} type is recognized by @value{GDBN} and is printed
16695as a string.
16696
16697@cindex builtin Go functions
16698@item Builtin Go functions
16699The @value{GDBN} expression parser recognizes the @code{unsafe.Sizeof}
16700function and handles it internally.
16701
16702@cindex restrictions on Go expressions
16703@item Restrictions on Go expressions
16704All Go operators are supported except @code{&^}.
16705The Go @code{_} ``blank identifier'' is not supported.
16706Automatic dereferencing of pointers is not supported.
16707@end table
16708
16709@node Objective-C
16710@subsection Objective-C
16711
16712@cindex Objective-C
16713This section provides information about some commands and command
16714options that are useful for debugging Objective-C code.  See also
16715@ref{Symbols, info classes}, and @ref{Symbols, info selectors}, for a
16716few more commands specific to Objective-C support.
16717
16718@menu
16719* Method Names in Commands::
16720* The Print Command with Objective-C::
16721@end menu
16722
16723@node Method Names in Commands
16724@subsubsection Method Names in Commands
16725
16726The following commands have been extended to accept Objective-C method
16727names as line specifications:
16728
16729@kindex clear@r{, and Objective-C}
16730@kindex break@r{, and Objective-C}
16731@kindex info line@r{, and Objective-C}
16732@kindex jump@r{, and Objective-C}
16733@kindex list@r{, and Objective-C}
16734@itemize
16735@item @code{clear}
16736@item @code{break}
16737@item @code{info line}
16738@item @code{jump}
16739@item @code{list}
16740@end itemize
16741
16742A fully qualified Objective-C method name is specified as
16743
16744@smallexample
16745-[@var{Class} @var{methodName}]
16746@end smallexample
16747
16748where the minus sign is used to indicate an instance method and a
16749plus sign (not shown) is used to indicate a class method.  The class
16750name @var{Class} and method name @var{methodName} are enclosed in
16751brackets, similar to the way messages are specified in Objective-C
16752source code.  For example, to set a breakpoint at the @code{create}
16753instance method of class @code{Fruit} in the program currently being
16754debugged, enter:
16755
16756@smallexample
16757break -[Fruit create]
16758@end smallexample
16759
16760To list ten program lines around the @code{initialize} class method,
16761enter:
16762
16763@smallexample
16764list +[NSText initialize]
16765@end smallexample
16766
16767In the current version of @value{GDBN}, the plus or minus sign is
16768required.  In future versions of @value{GDBN}, the plus or minus
16769sign will be optional, but you can use it to narrow the search.  It
16770is also possible to specify just a method name:
16771
16772@smallexample
16773break create
16774@end smallexample
16775
16776You must specify the complete method name, including any colons.  If
16777your program's source files contain more than one @code{create} method,
16778you'll be presented with a numbered list of classes that implement that
16779method.  Indicate your choice by number, or type @samp{0} to exit if
16780none apply.
16781
16782As another example, to clear a breakpoint established at the
16783@code{makeKeyAndOrderFront:} method of the @code{NSWindow} class, enter:
16784
16785@smallexample
16786clear -[NSWindow makeKeyAndOrderFront:]
16787@end smallexample
16788
16789@node The Print Command with Objective-C
16790@subsubsection The Print Command With Objective-C
16791@cindex Objective-C, print objects
16792@kindex print-object
16793@kindex po @r{(@code{print-object})}
16794
16795The print command has also been extended to accept methods.  For example:
16796
16797@smallexample
16798print -[@var{object} hash]
16799@end smallexample
16800
16801@cindex print an Objective-C object description
16802@cindex @code{_NSPrintForDebugger}, and printing Objective-C objects
16803@noindent
16804will tell @value{GDBN} to send the @code{hash} message to @var{object}
16805and print the result.  Also, an additional command has been added,
16806@code{print-object} or @code{po} for short, which is meant to print
16807the description of an object.  However, this command may only work
16808with certain Objective-C libraries that have a particular hook
16809function, @code{_NSPrintForDebugger}, defined.
16810
16811@node OpenCL C
16812@subsection OpenCL C
16813
16814@cindex OpenCL C
16815This section provides information about @value{GDBN}s OpenCL C support.
16816
16817@menu
16818* OpenCL C Datatypes::
16819* OpenCL C Expressions::
16820* OpenCL C Operators::
16821@end menu
16822
16823@node OpenCL C Datatypes
16824@subsubsection OpenCL C Datatypes
16825
16826@cindex OpenCL C Datatypes
16827@value{GDBN} supports the builtin scalar and vector datatypes specified
16828by OpenCL 1.1.  In addition the half- and double-precision floating point
16829data types of the @code{cl_khr_fp16} and @code{cl_khr_fp64} OpenCL
16830extensions are also known to @value{GDBN}.
16831
16832@node OpenCL C Expressions
16833@subsubsection OpenCL C Expressions
16834
16835@cindex OpenCL C Expressions
16836@value{GDBN} supports accesses to vector components including the access as
16837lvalue where possible.  Since OpenCL C is based on C99 most C expressions
16838supported by @value{GDBN} can be used as well.
16839
16840@node OpenCL C Operators
16841@subsubsection OpenCL C Operators
16842
16843@cindex OpenCL C Operators
16844@value{GDBN} supports the operators specified by OpenCL 1.1 for scalar and
16845vector data types.
16846
16847@node Fortran
16848@subsection Fortran
16849@cindex Fortran-specific support in @value{GDBN}
16850
16851@value{GDBN} can be used to debug programs written in Fortran, but it
16852currently supports only the features of Fortran 77 language.
16853
16854@cindex trailing underscore, in Fortran symbols
16855Some Fortran compilers (@sc{gnu} Fortran 77 and Fortran 95 compilers
16856among them) append an underscore to the names of variables and
16857functions.  When you debug programs compiled by those compilers, you
16858will need to refer to variables and functions with a trailing
16859underscore.
16860
16861@menu
16862* Fortran Operators::           Fortran operators and expressions
16863* Fortran Defaults::            Default settings for Fortran
16864* Special Fortran Commands::    Special @value{GDBN} commands for Fortran
16865@end menu
16866
16867@node Fortran Operators
16868@subsubsection Fortran Operators and Expressions
16869
16870@cindex Fortran operators and expressions
16871
16872Operators must be defined on values of specific types.  For instance,
16873@code{+} is defined on numbers, but not on characters or other non-
16874arithmetic types.  Operators are often defined on groups of types.
16875
16876@table @code
16877@item **
16878The exponentiation operator.  It raises the first operand to the power
16879of the second one.
16880
16881@item :
16882The range operator.  Normally used in the form of array(low:high) to
16883represent a section of array.
16884
16885@item %
16886The access component operator.  Normally used to access elements in derived
16887types.  Also suitable for unions.  As unions aren't part of regular Fortran,
16888this can only happen when accessing a register that uses a gdbarch-defined
16889union type.
16890@item ::
16891The scope operator.  Normally used to access variables in modules or
16892to set breakpoints on subroutines nested in modules or in other
16893subroutines (internal subroutines).
16894@end table
16895
16896@node Fortran Defaults
16897@subsubsection Fortran Defaults
16898
16899@cindex Fortran Defaults
16900
16901Fortran symbols are usually case-insensitive, so @value{GDBN} by
16902default uses case-insensitive matches for Fortran symbols.  You can
16903change that with the @samp{set case-insensitive} command, see
16904@ref{Symbols}, for the details.
16905
16906@node Special Fortran Commands
16907@subsubsection Special Fortran Commands
16908
16909@cindex Special Fortran commands
16910
16911@value{GDBN} has some commands to support Fortran-specific features,
16912such as displaying common blocks.
16913
16914@table @code
16915@cindex @code{COMMON} blocks, Fortran
16916@kindex info common
16917@item info common @r{[}@var{common-name}@r{]}
16918This command prints the values contained in the Fortran @code{COMMON}
16919block whose name is @var{common-name}.  With no argument, the names of
16920all @code{COMMON} blocks visible at the current program location are
16921printed.
16922@end table
16923
16924@node Pascal
16925@subsection Pascal
16926
16927@cindex Pascal support in @value{GDBN}, limitations
16928Debugging Pascal programs which use sets, subranges, file variables, or
16929nested functions does not currently work.  @value{GDBN} does not support
16930entering expressions, printing values, or similar features using Pascal
16931syntax.
16932
16933The Pascal-specific command @code{set print pascal_static-members}
16934controls whether static members of Pascal objects are displayed.
16935@xref{Print Settings, pascal_static-members}.
16936
16937@node Rust
16938@subsection Rust
16939
16940@value{GDBN} supports the @url{https://www.rust-lang.org/, Rust
16941Programming Language}.  Type- and value-printing, and expression
16942parsing, are reasonably complete.  However, there are a few
16943peculiarities and holes to be aware of.
16944
16945@itemize @bullet
16946@item
16947Linespecs (@pxref{Specify Location}) are never relative to the current
16948crate.  Instead, they act as if there were a global namespace of
16949crates, somewhat similar to the way @code{extern crate} behaves.
16950
16951That is, if @value{GDBN} is stopped at a breakpoint in a function in
16952crate @samp{A}, module @samp{B}, then @code{break B::f} will attempt
16953to set a breakpoint in a function named @samp{f} in a crate named
16954@samp{B}.
16955
16956As a consequence of this approach, linespecs also cannot refer to
16957items using @samp{self::} or @samp{super::}.
16958
16959@item
16960Because @value{GDBN} implements Rust name-lookup semantics in
16961expressions, it will sometimes prepend the current crate to a name.
16962For example, if @value{GDBN} is stopped at a breakpoint in the crate
16963@samp{K}, then @code{print ::x::y} will try to find the symbol
16964@samp{K::x::y}.
16965
16966However, since it is useful to be able to refer to other crates when
16967debugging, @value{GDBN} provides the @code{extern} extension to
16968circumvent this.  To use the extension, just put @code{extern} before
16969a path expression to refer to the otherwise unavailable ``global''
16970scope.
16971
16972In the above example, if you wanted to refer to the symbol @samp{y} in
16973the crate @samp{x}, you would use @code{print extern x::y}.
16974
16975@item
16976The Rust expression evaluator does not support ``statement-like''
16977expressions such as @code{if} or @code{match}, or lambda expressions.
16978
16979@item
16980Tuple expressions are not implemented.
16981
16982@item
16983The Rust expression evaluator does not currently implement the
16984@code{Drop} trait.  Objects that may be created by the evaluator will
16985never be destroyed.
16986
16987@item
16988@value{GDBN} does not implement type inference for generics.  In order
16989to call generic functions or otherwise refer to generic items, you
16990will have to specify the type parameters manually.
16991
16992@item
16993@value{GDBN} currently uses the C@t{++} demangler for Rust.  In most
16994cases this does not cause any problems.  However, in an expression
16995context, completing a generic function name will give syntactically
16996invalid results.  This happens because Rust requires the @samp{::}
16997operator between the function name and its generic arguments.  For
16998example, @value{GDBN} might provide a completion like
16999@code{crate::f<u32>}, where the parser would require
17000@code{crate::f::<u32>}.
17001
17002@item
17003As of this writing, the Rust compiler (version 1.8) has a few holes in
17004the debugging information it generates.  These holes prevent certain
17005features from being implemented by @value{GDBN}:
17006@itemize @bullet
17007
17008@item
17009Method calls cannot be made via traits.
17010
17011@item
17012Operator overloading is not implemented.
17013
17014@item
17015When debugging in a monomorphized function, you cannot use the generic
17016type names.
17017
17018@item
17019The type @code{Self} is not available.
17020
17021@item
17022@code{use} statements are not available, so some names may not be
17023available in the crate.
17024@end itemize
17025@end itemize
17026
17027@node Modula-2
17028@subsection Modula-2
17029
17030@cindex Modula-2, @value{GDBN} support
17031
17032The extensions made to @value{GDBN} to support Modula-2 only support
17033output from the @sc{gnu} Modula-2 compiler (which is currently being
17034developed).  Other Modula-2 compilers are not currently supported, and
17035attempting to debug executables produced by them is most likely
17036to give an error as @value{GDBN} reads in the executable's symbol
17037table.
17038
17039@cindex expressions in Modula-2
17040@menu
17041* M2 Operators::                Built-in operators
17042* Built-In Func/Proc::          Built-in functions and procedures
17043* M2 Constants::                Modula-2 constants
17044* M2 Types::                    Modula-2 types
17045* M2 Defaults::                 Default settings for Modula-2
17046* Deviations::                  Deviations from standard Modula-2
17047* M2 Checks::                   Modula-2 type and range checks
17048* M2 Scope::                    The scope operators @code{::} and @code{.}
17049* GDB/M2::                      @value{GDBN} and Modula-2
17050@end menu
17051
17052@node M2 Operators
17053@subsubsection Operators
17054@cindex Modula-2 operators
17055
17056Operators must be defined on values of specific types.  For instance,
17057@code{+} is defined on numbers, but not on structures.  Operators are
17058often defined on groups of types.  For the purposes of Modula-2, the
17059following definitions hold:
17060
17061@itemize @bullet
17062
17063@item
17064@emph{Integral types} consist of @code{INTEGER}, @code{CARDINAL}, and
17065their subranges.
17066
17067@item
17068@emph{Character types} consist of @code{CHAR} and its subranges.
17069
17070@item
17071@emph{Floating-point types} consist of @code{REAL}.
17072
17073@item
17074@emph{Pointer types} consist of anything declared as @code{POINTER TO
17075@var{type}}.
17076
17077@item
17078@emph{Scalar types} consist of all of the above.
17079
17080@item
17081@emph{Set types} consist of @code{SET} and @code{BITSET} types.
17082
17083@item
17084@emph{Boolean types} consist of @code{BOOLEAN}.
17085@end itemize
17086
17087@noindent
17088The following operators are supported, and appear in order of
17089increasing precedence:
17090
17091@table @code
17092@item ,
17093Function argument or array index separator.
17094
17095@item :=
17096Assignment.  The value of @var{var} @code{:=} @var{value} is
17097@var{value}.
17098
17099@item <@r{, }>
17100Less than, greater than on integral, floating-point, or enumerated
17101types.
17102
17103@item <=@r{, }>=
17104Less than or equal to, greater than or equal to
17105on integral, floating-point and enumerated types, or set inclusion on
17106set types.  Same precedence as @code{<}.
17107
17108@item =@r{, }<>@r{, }#
17109Equality and two ways of expressing inequality, valid on scalar types.
17110Same precedence as @code{<}.  In @value{GDBN} scripts, only @code{<>} is
17111available for inequality, since @code{#} conflicts with the script
17112comment character.
17113
17114@item IN
17115Set membership.  Defined on set types and the types of their members.
17116Same precedence as @code{<}.
17117
17118@item OR
17119Boolean disjunction.  Defined on boolean types.
17120
17121@item AND@r{, }&
17122Boolean conjunction.  Defined on boolean types.
17123
17124@item @@
17125The @value{GDBN} ``artificial array'' operator (@pxref{Expressions, ,Expressions}).
17126
17127@item +@r{, }-
17128Addition and subtraction on integral and floating-point types, or union
17129and difference on set types.
17130
17131@item *
17132Multiplication on integral and floating-point types, or set intersection
17133on set types.
17134
17135@item /
17136Division on floating-point types, or symmetric set difference on set
17137types.  Same precedence as @code{*}.
17138
17139@item DIV@r{, }MOD
17140Integer division and remainder.  Defined on integral types.  Same
17141precedence as @code{*}.
17142
17143@item -
17144Negative.  Defined on @code{INTEGER} and @code{REAL} data.
17145
17146@item ^
17147Pointer dereferencing.  Defined on pointer types.
17148
17149@item NOT
17150Boolean negation.  Defined on boolean types.  Same precedence as
17151@code{^}.
17152
17153@item .
17154@code{RECORD} field selector.  Defined on @code{RECORD} data.  Same
17155precedence as @code{^}.
17156
17157@item []
17158Array indexing.  Defined on @code{ARRAY} data.  Same precedence as @code{^}.
17159
17160@item ()
17161Procedure argument list.  Defined on @code{PROCEDURE} objects.  Same precedence
17162as @code{^}.
17163
17164@item ::@r{, }.
17165@value{GDBN} and Modula-2 scope operators.
17166@end table
17167
17168@quotation
17169@emph{Warning:} Set expressions and their operations are not yet supported, so @value{GDBN}
17170treats the use of the operator @code{IN}, or the use of operators
17171@code{+}, @code{-}, @code{*}, @code{/}, @code{=}, , @code{<>}, @code{#},
17172@code{<=}, and @code{>=} on sets as an error.
17173@end quotation
17174
17175
17176@node Built-In Func/Proc
17177@subsubsection Built-in Functions and Procedures
17178@cindex Modula-2 built-ins
17179
17180Modula-2 also makes available several built-in procedures and functions.
17181In describing these, the following metavariables are used:
17182
17183@table @var
17184
17185@item a
17186represents an @code{ARRAY} variable.
17187
17188@item c
17189represents a @code{CHAR} constant or variable.
17190
17191@item i
17192represents a variable or constant of integral type.
17193
17194@item m
17195represents an identifier that belongs to a set.  Generally used in the
17196same function with the metavariable @var{s}.  The type of @var{s} should
17197be @code{SET OF @var{mtype}} (where @var{mtype} is the type of @var{m}).
17198
17199@item n
17200represents a variable or constant of integral or floating-point type.
17201
17202@item r
17203represents a variable or constant of floating-point type.
17204
17205@item t
17206represents a type.
17207
17208@item v
17209represents a variable.
17210
17211@item x
17212represents a variable or constant of one of many types.  See the
17213explanation of the function for details.
17214@end table
17215
17216All Modula-2 built-in procedures also return a result, described below.
17217
17218@table @code
17219@item ABS(@var{n})
17220Returns the absolute value of @var{n}.
17221
17222@item CAP(@var{c})
17223If @var{c} is a lower case letter, it returns its upper case
17224equivalent, otherwise it returns its argument.
17225
17226@item CHR(@var{i})
17227Returns the character whose ordinal value is @var{i}.
17228
17229@item DEC(@var{v})
17230Decrements the value in the variable @var{v} by one.  Returns the new value.
17231
17232@item DEC(@var{v},@var{i})
17233Decrements the value in the variable @var{v} by @var{i}.  Returns the
17234new value.
17235
17236@item EXCL(@var{m},@var{s})
17237Removes the element @var{m} from the set @var{s}.  Returns the new
17238set.
17239
17240@item FLOAT(@var{i})
17241Returns the floating point equivalent of the integer @var{i}.
17242
17243@item HIGH(@var{a})
17244Returns the index of the last member of @var{a}.
17245
17246@item INC(@var{v})
17247Increments the value in the variable @var{v} by one.  Returns the new value.
17248
17249@item INC(@var{v},@var{i})
17250Increments the value in the variable @var{v} by @var{i}.  Returns the
17251new value.
17252
17253@item INCL(@var{m},@var{s})
17254Adds the element @var{m} to the set @var{s} if it is not already
17255there.  Returns the new set.
17256
17257@item MAX(@var{t})
17258Returns the maximum value of the type @var{t}.
17259
17260@item MIN(@var{t})
17261Returns the minimum value of the type @var{t}.
17262
17263@item ODD(@var{i})
17264Returns boolean TRUE if @var{i} is an odd number.
17265
17266@item ORD(@var{x})
17267Returns the ordinal value of its argument.  For example, the ordinal
17268value of a character is its @sc{ascii} value (on machines supporting
17269the @sc{ascii} character set).  The argument @var{x} must be of an
17270ordered type, which include integral, character and enumerated types.
17271
17272@item SIZE(@var{x})
17273Returns the size of its argument.  The argument @var{x} can be a
17274variable or a type.
17275
17276@item TRUNC(@var{r})
17277Returns the integral part of @var{r}.
17278
17279@item TSIZE(@var{x})
17280Returns the size of its argument.  The argument @var{x} can be a
17281variable or a type.
17282
17283@item VAL(@var{t},@var{i})
17284Returns the member of the type @var{t} whose ordinal value is @var{i}.
17285@end table
17286
17287@quotation
17288@emph{Warning:}  Sets and their operations are not yet supported, so
17289@value{GDBN} treats the use of procedures @code{INCL} and @code{EXCL} as
17290an error.
17291@end quotation
17292
17293@cindex Modula-2 constants
17294@node M2 Constants
17295@subsubsection Constants
17296
17297@value{GDBN} allows you to express the constants of Modula-2 in the following
17298ways:
17299
17300@itemize @bullet
17301
17302@item
17303Integer constants are simply a sequence of digits.  When used in an
17304expression, a constant is interpreted to be type-compatible with the
17305rest of the expression.  Hexadecimal integers are specified by a
17306trailing @samp{H}, and octal integers by a trailing @samp{B}.
17307
17308@item
17309Floating point constants appear as a sequence of digits, followed by a
17310decimal point and another sequence of digits.  An optional exponent can
17311then be specified, in the form @samp{E@r{[}+@r{|}-@r{]}@var{nnn}}, where
17312@samp{@r{[}+@r{|}-@r{]}@var{nnn}} is the desired exponent.  All of the
17313digits of the floating point constant must be valid decimal (base 10)
17314digits.
17315
17316@item
17317Character constants consist of a single character enclosed by a pair of
17318like quotes, either single (@code{'}) or double (@code{"}).  They may
17319also be expressed by their ordinal value (their @sc{ascii} value, usually)
17320followed by a @samp{C}.
17321
17322@item
17323String constants consist of a sequence of characters enclosed by a
17324pair of like quotes, either single (@code{'}) or double (@code{"}).
17325Escape sequences in the style of C are also allowed.  @xref{C
17326Constants, ,C and C@t{++} Constants}, for a brief explanation of escape
17327sequences.
17328
17329@item
17330Enumerated constants consist of an enumerated identifier.
17331
17332@item
17333Boolean constants consist of the identifiers @code{TRUE} and
17334@code{FALSE}.
17335
17336@item
17337Pointer constants consist of integral values only.
17338
17339@item
17340Set constants are not yet supported.
17341@end itemize
17342
17343@node M2 Types
17344@subsubsection Modula-2 Types
17345@cindex Modula-2 types
17346
17347Currently @value{GDBN} can print the following data types in Modula-2
17348syntax: array types, record types, set types, pointer types, procedure
17349types, enumerated types, subrange types and base types.  You can also
17350print the contents of variables declared using these type.
17351This section gives a number of simple source code examples together with
17352sample @value{GDBN} sessions.
17353
17354The first example contains the following section of code:
17355
17356@smallexample
17357VAR
17358   s: SET OF CHAR ;
17359   r: [20..40] ;
17360@end smallexample
17361
17362@noindent
17363and you can request @value{GDBN} to interrogate the type and value of
17364@code{r} and @code{s}.
17365
17366@smallexample
17367(@value{GDBP}) print s
17368@{'A'..'C', 'Z'@}
17369(@value{GDBP}) ptype s
17370SET OF CHAR
17371(@value{GDBP}) print r
1737221
17373(@value{GDBP}) ptype r
17374[20..40]
17375@end smallexample
17376
17377@noindent
17378Likewise if your source code declares @code{s} as:
17379
17380@smallexample
17381VAR
17382   s: SET ['A'..'Z'] ;
17383@end smallexample
17384
17385@noindent
17386then you may query the type of @code{s} by:
17387
17388@smallexample
17389(@value{GDBP}) ptype s
17390type = SET ['A'..'Z']
17391@end smallexample
17392
17393@noindent
17394Note that at present you cannot interactively manipulate set
17395expressions using the debugger.
17396
17397The following example shows how you might declare an array in Modula-2
17398and how you can interact with @value{GDBN} to print its type and contents:
17399
17400@smallexample
17401VAR
17402   s: ARRAY [-10..10] OF CHAR ;
17403@end smallexample
17404
17405@smallexample
17406(@value{GDBP}) ptype s
17407ARRAY [-10..10] OF CHAR
17408@end smallexample
17409
17410Note that the array handling is not yet complete and although the type
17411is printed correctly, expression handling still assumes that all
17412arrays have a lower bound of zero and not @code{-10} as in the example
17413above.
17414
17415Here are some more type related Modula-2 examples:
17416
17417@smallexample
17418TYPE
17419   colour = (blue, red, yellow, green) ;
17420   t = [blue..yellow] ;
17421VAR
17422   s: t ;
17423BEGIN
17424   s := blue ;
17425@end smallexample
17426
17427@noindent
17428The @value{GDBN} interaction shows how you can query the data type
17429and value of a variable.
17430
17431@smallexample
17432(@value{GDBP}) print s
17433$1 = blue
17434(@value{GDBP}) ptype t
17435type = [blue..yellow]
17436@end smallexample
17437
17438@noindent
17439In this example a Modula-2 array is declared and its contents
17440displayed.  Observe that the contents are written in the same way as
17441their @code{C} counterparts.
17442
17443@smallexample
17444VAR
17445   s: ARRAY [1..5] OF CARDINAL ;
17446BEGIN
17447   s[1] := 1 ;
17448@end smallexample
17449
17450@smallexample
17451(@value{GDBP}) print s
17452$1 = @{1, 0, 0, 0, 0@}
17453(@value{GDBP}) ptype s
17454type = ARRAY [1..5] OF CARDINAL
17455@end smallexample
17456
17457The Modula-2 language interface to @value{GDBN} also understands
17458pointer types as shown in this example:
17459
17460@smallexample
17461VAR
17462   s: POINTER TO ARRAY [1..5] OF CARDINAL ;
17463BEGIN
17464   NEW(s) ;
17465   s^[1] := 1 ;
17466@end smallexample
17467
17468@noindent
17469and you can request that @value{GDBN} describes the type of @code{s}.
17470
17471@smallexample
17472(@value{GDBP}) ptype s
17473type = POINTER TO ARRAY [1..5] OF CARDINAL
17474@end smallexample
17475
17476@value{GDBN} handles compound types as we can see in this example.
17477Here we combine array types, record types, pointer types and subrange
17478types:
17479
17480@smallexample
17481TYPE
17482   foo = RECORD
17483            f1: CARDINAL ;
17484            f2: CHAR ;
17485            f3: myarray ;
17486         END ;
17487
17488   myarray = ARRAY myrange OF CARDINAL ;
17489   myrange = [-2..2] ;
17490VAR
17491   s: POINTER TO ARRAY myrange OF foo ;
17492@end smallexample
17493
17494@noindent
17495and you can ask @value{GDBN} to describe the type of @code{s} as shown
17496below.
17497
17498@smallexample
17499(@value{GDBP}) ptype s
17500type = POINTER TO ARRAY [-2..2] OF foo = RECORD
17501    f1 : CARDINAL;
17502    f2 : CHAR;
17503    f3 : ARRAY [-2..2] OF CARDINAL;
17504END
17505@end smallexample
17506
17507@node M2 Defaults
17508@subsubsection Modula-2 Defaults
17509@cindex Modula-2 defaults
17510
17511If type and range checking are set automatically by @value{GDBN}, they
17512both default to @code{on} whenever the working language changes to
17513Modula-2.  This happens regardless of whether you or @value{GDBN}
17514selected the working language.
17515
17516If you allow @value{GDBN} to set the language automatically, then entering
17517code compiled from a file whose name ends with @file{.mod} sets the
17518working language to Modula-2.  @xref{Automatically, ,Having @value{GDBN}
17519Infer the Source Language}, for further details.
17520
17521@node Deviations
17522@subsubsection Deviations from Standard Modula-2
17523@cindex Modula-2, deviations from
17524
17525A few changes have been made to make Modula-2 programs easier to debug.
17526This is done primarily via loosening its type strictness:
17527
17528@itemize @bullet
17529@item
17530Unlike in standard Modula-2, pointer constants can be formed by
17531integers.  This allows you to modify pointer variables during
17532debugging.  (In standard Modula-2, the actual address contained in a
17533pointer variable is hidden from you; it can only be modified
17534through direct assignment to another pointer variable or expression that
17535returned a pointer.)
17536
17537@item
17538C escape sequences can be used in strings and characters to represent
17539non-printable characters.  @value{GDBN} prints out strings with these
17540escape sequences embedded.  Single non-printable characters are
17541printed using the @samp{CHR(@var{nnn})} format.
17542
17543@item
17544The assignment operator (@code{:=}) returns the value of its right-hand
17545argument.
17546
17547@item
17548All built-in procedures both modify @emph{and} return their argument.
17549@end itemize
17550
17551@node M2 Checks
17552@subsubsection Modula-2 Type and Range Checks
17553@cindex Modula-2 checks
17554
17555@quotation
17556@emph{Warning:} in this release, @value{GDBN} does not yet perform type or
17557range checking.
17558@end quotation
17559@c FIXME remove warning when type/range checks added
17560
17561@value{GDBN} considers two Modula-2 variables type equivalent if:
17562
17563@itemize @bullet
17564@item
17565They are of types that have been declared equivalent via a @code{TYPE
17566@var{t1} = @var{t2}} statement
17567
17568@item
17569They have been declared on the same line.  (Note:  This is true of the
17570@sc{gnu} Modula-2 compiler, but it may not be true of other compilers.)
17571@end itemize
17572
17573As long as type checking is enabled, any attempt to combine variables
17574whose types are not equivalent is an error.
17575
17576Range checking is done on all mathematical operations, assignment, array
17577index bounds, and all built-in functions and procedures.
17578
17579@node M2 Scope
17580@subsubsection The Scope Operators @code{::} and @code{.}
17581@cindex scope
17582@cindex @code{.}, Modula-2 scope operator
17583@cindex colon, doubled as scope operator
17584@ifinfo
17585@vindex colon-colon@r{, in Modula-2}
17586@c Info cannot handle :: but TeX can.
17587@end ifinfo
17588@ifnotinfo
17589@vindex ::@r{, in Modula-2}
17590@end ifnotinfo
17591
17592There are a few subtle differences between the Modula-2 scope operator
17593(@code{.}) and the @value{GDBN} scope operator (@code{::}).  The two have
17594similar syntax:
17595
17596@smallexample
17597
17598@var{module} . @var{id}
17599@var{scope} :: @var{id}
17600@end smallexample
17601
17602@noindent
17603where @var{scope} is the name of a module or a procedure,
17604@var{module} the name of a module, and @var{id} is any declared
17605identifier within your program, except another module.
17606
17607Using the @code{::} operator makes @value{GDBN} search the scope
17608specified by @var{scope} for the identifier @var{id}.  If it is not
17609found in the specified scope, then @value{GDBN} searches all scopes
17610enclosing the one specified by @var{scope}.
17611
17612Using the @code{.} operator makes @value{GDBN} search the current scope for
17613the identifier specified by @var{id} that was imported from the
17614definition module specified by @var{module}.  With this operator, it is
17615an error if the identifier @var{id} was not imported from definition
17616module @var{module}, or if @var{id} is not an identifier in
17617@var{module}.
17618
17619@node GDB/M2
17620@subsubsection @value{GDBN} and Modula-2
17621
17622Some @value{GDBN} commands have little use when debugging Modula-2 programs.
17623Five subcommands of @code{set print} and @code{show print} apply
17624specifically to C and C@t{++}: @samp{vtbl}, @samp{demangle},
17625@samp{asm-demangle}, @samp{object}, and @samp{union}.  The first four
17626apply to C@t{++}, and the last to the C @code{union} type, which has no direct
17627analogue in Modula-2.
17628
17629The @code{@@} operator (@pxref{Expressions, ,Expressions}), while available
17630with any language, is not useful with Modula-2.  Its
17631intent is to aid the debugging of @dfn{dynamic arrays}, which cannot be
17632created in Modula-2 as they can in C or C@t{++}.  However, because an
17633address can be specified by an integral constant, the construct
17634@samp{@{@var{type}@}@var{adrexp}} is still useful.
17635
17636@cindex @code{#} in Modula-2
17637In @value{GDBN} scripts, the Modula-2 inequality operator @code{#} is
17638interpreted as the beginning of a comment.  Use @code{<>} instead.
17639
17640@node Ada
17641@subsection Ada
17642@cindex Ada
17643
17644The extensions made to @value{GDBN} for Ada only support
17645output from the @sc{gnu} Ada (GNAT) compiler.
17646Other Ada compilers are not currently supported, and
17647attempting to debug executables produced by them is most likely
17648to be difficult.
17649
17650
17651@cindex expressions in Ada
17652@menu
17653* Ada Mode Intro::              General remarks on the Ada syntax
17654                                   and semantics supported by Ada mode
17655                                   in @value{GDBN}.
17656* Omissions from Ada::          Restrictions on the Ada expression syntax.
17657* Additions to Ada::            Extensions of the Ada expression syntax.
17658* Overloading support for Ada:: Support for expressions involving overloaded
17659                                   subprograms.
17660* Stopping Before Main Program:: Debugging the program during elaboration.
17661* Ada Exceptions::              Ada Exceptions
17662* Ada Tasks::                   Listing and setting breakpoints in tasks.
17663* Ada Tasks and Core Files::    Tasking Support when Debugging Core Files
17664* Ravenscar Profile::           Tasking Support when using the Ravenscar
17665                                   Profile
17666* Ada Settings::                New settable GDB parameters for Ada.
17667* Ada Glitches::                Known peculiarities of Ada mode.
17668@end menu
17669
17670@node Ada Mode Intro
17671@subsubsection Introduction
17672@cindex Ada mode, general
17673
17674The Ada mode of @value{GDBN} supports a fairly large subset of Ada expression
17675syntax, with some extensions.
17676The philosophy behind the design of this subset is
17677
17678@itemize @bullet
17679@item
17680That @value{GDBN} should provide basic literals and access to operations for
17681arithmetic, dereferencing, field selection, indexing, and subprogram calls,
17682leaving more sophisticated computations to subprograms written into the
17683program (which therefore may be called from @value{GDBN}).
17684
17685@item
17686That type safety and strict adherence to Ada language restrictions
17687are not particularly important to the @value{GDBN} user.
17688
17689@item
17690That brevity is important to the @value{GDBN} user.
17691@end itemize
17692
17693Thus, for brevity, the debugger acts as if all names declared in
17694user-written packages are directly visible, even if they are not visible
17695according to Ada rules, thus making it unnecessary to fully qualify most
17696names with their packages, regardless of context.  Where this causes
17697ambiguity, @value{GDBN} asks the user's intent.
17698
17699The debugger will start in Ada mode if it detects an Ada main program.
17700As for other languages, it will enter Ada mode when stopped in a program that
17701was translated from an Ada source file.
17702
17703While in Ada mode, you may use `@t{--}' for comments.  This is useful
17704mostly for documenting command files.  The standard @value{GDBN} comment
17705(@samp{#}) still works at the beginning of a line in Ada mode, but not in the
17706middle (to allow based literals).
17707
17708@node Omissions from Ada
17709@subsubsection Omissions from Ada
17710@cindex Ada, omissions from
17711
17712Here are the notable omissions from the subset:
17713
17714@itemize @bullet
17715@item
17716Only a subset of the attributes are supported:
17717
17718@itemize @minus
17719@item
17720@t{'First}, @t{'Last}, and @t{'Length}
17721 on array objects (not on types and subtypes).
17722
17723@item
17724@t{'Min} and @t{'Max}.
17725
17726@item
17727@t{'Pos} and @t{'Val}.
17728
17729@item
17730@t{'Tag}.
17731
17732@item
17733@t{'Range} on array objects (not subtypes), but only as the right
17734operand of the membership (@code{in}) operator.
17735
17736@item
17737@t{'Access}, @t{'Unchecked_Access}, and
17738@t{'Unrestricted_Access} (a GNAT extension).
17739
17740@item
17741@t{'Address}.
17742@end itemize
17743
17744@item
17745The names in
17746@code{Characters.Latin_1} are not available and
17747concatenation is not implemented.  Thus, escape characters in strings are
17748not currently available.
17749
17750@item
17751Equality tests (@samp{=} and @samp{/=}) on arrays test for bitwise
17752equality of representations.  They will generally work correctly
17753for strings and arrays whose elements have integer or enumeration types.
17754They may not work correctly for arrays whose element
17755types have user-defined equality, for arrays of real values
17756(in particular, IEEE-conformant floating point, because of negative
17757zeroes and NaNs), and for arrays whose elements contain unused bits with
17758indeterminate values.
17759
17760@item
17761The other component-by-component array operations (@code{and}, @code{or},
17762@code{xor}, @code{not}, and relational tests other than equality)
17763are not implemented.
17764
17765@item
17766@cindex array aggregates (Ada)
17767@cindex record aggregates (Ada)
17768@cindex aggregates (Ada)
17769There is limited support for array and record aggregates.  They are
17770permitted only on the right sides of assignments, as in these examples:
17771
17772@smallexample
17773(@value{GDBP}) set An_Array := (1, 2, 3, 4, 5, 6)
17774(@value{GDBP}) set An_Array := (1, others => 0)
17775(@value{GDBP}) set An_Array := (0|4 => 1, 1..3 => 2, 5 => 6)
17776(@value{GDBP}) set A_2D_Array := ((1, 2, 3), (4, 5, 6), (7, 8, 9))
17777(@value{GDBP}) set A_Record := (1, "Peter", True);
17778(@value{GDBP}) set A_Record := (Name => "Peter", Id => 1, Alive => True)
17779@end smallexample
17780
17781Changing a
17782discriminant's value by assigning an aggregate has an
17783undefined effect if that discriminant is used within the record.
17784However, you can first modify discriminants by directly assigning to
17785them (which normally would not be allowed in Ada), and then performing an
17786aggregate assignment.  For example, given a variable @code{A_Rec}
17787declared to have a type such as:
17788
17789@smallexample
17790type Rec (Len : Small_Integer := 0) is record
17791    Id : Integer;
17792    Vals : IntArray (1 .. Len);
17793end record;
17794@end smallexample
17795
17796you can assign a value with a different size of @code{Vals} with two
17797assignments:
17798
17799@smallexample
17800(@value{GDBP}) set A_Rec.Len := 4
17801(@value{GDBP}) set A_Rec := (Id => 42, Vals => (1, 2, 3, 4))
17802@end smallexample
17803
17804As this example also illustrates, @value{GDBN} is very loose about the usual
17805rules concerning aggregates.  You may leave out some of the
17806components of an array or record aggregate (such as the @code{Len}
17807component in the assignment to @code{A_Rec} above); they will retain their
17808original values upon assignment.  You may freely use dynamic values as
17809indices in component associations.  You may even use overlapping or
17810redundant component associations, although which component values are
17811assigned in such cases is not defined.
17812
17813@item
17814Calls to dispatching subprograms are not implemented.
17815
17816@item
17817The overloading algorithm is much more limited (i.e., less selective)
17818than that of real Ada.  It makes only limited use of the context in
17819which a subexpression appears to resolve its meaning, and it is much
17820looser in its rules for allowing type matches.  As a result, some
17821function calls will be ambiguous, and the user will be asked to choose
17822the proper resolution.
17823
17824@item
17825The @code{new} operator is not implemented.
17826
17827@item
17828Entry calls are not implemented.
17829
17830@item
17831Aside from printing, arithmetic operations on the native VAX floating-point
17832formats are not supported.
17833
17834@item
17835It is not possible to slice a packed array.
17836
17837@item
17838The names @code{True} and @code{False}, when not part of a qualified name,
17839are interpreted as if implicitly prefixed by @code{Standard}, regardless of
17840context.
17841Should your program
17842redefine these names in a package or procedure (at best a dubious practice),
17843you will have to use fully qualified names to access their new definitions.
17844@end itemize
17845
17846@node Additions to Ada
17847@subsubsection Additions to Ada
17848@cindex Ada, deviations from
17849
17850As it does for other languages, @value{GDBN} makes certain generic
17851extensions to Ada (@pxref{Expressions}):
17852
17853@itemize @bullet
17854@item
17855If the expression @var{E} is a variable residing in memory (typically
17856a local variable or array element) and @var{N} is a positive integer,
17857then @code{@var{E}@@@var{N}} displays the values of @var{E} and the
17858@var{N}-1 adjacent variables following it in memory as an array.  In
17859Ada, this operator is generally not necessary, since its prime use is
17860in displaying parts of an array, and slicing will usually do this in
17861Ada.  However, there are occasional uses when debugging programs in
17862which certain debugging information has been optimized away.
17863
17864@item
17865@code{@var{B}::@var{var}} means ``the variable named @var{var} that
17866appears in function or file @var{B}.''  When @var{B} is a file name,
17867you must typically surround it in single quotes.
17868
17869@item
17870The expression @code{@{@var{type}@} @var{addr}} means ``the variable of type
17871@var{type} that appears at address @var{addr}.''
17872
17873@item
17874A name starting with @samp{$} is a convenience variable
17875(@pxref{Convenience Vars}) or a machine register (@pxref{Registers}).
17876@end itemize
17877
17878In addition, @value{GDBN} provides a few other shortcuts and outright
17879additions specific to Ada:
17880
17881@itemize @bullet
17882@item
17883The assignment statement is allowed as an expression, returning
17884its right-hand operand as its value.  Thus, you may enter
17885
17886@smallexample
17887(@value{GDBP}) set x := y + 3
17888(@value{GDBP}) print A(tmp := y + 1)
17889@end smallexample
17890
17891@item
17892The semicolon is allowed as an ``operator,''  returning as its value
17893the value of its right-hand operand.
17894This allows, for example,
17895complex conditional breaks:
17896
17897@smallexample
17898(@value{GDBP}) break f
17899(@value{GDBP}) condition 1 (report(i); k += 1; A(k) > 100)
17900@end smallexample
17901
17902@item
17903Rather than use catenation and symbolic character names to introduce special
17904characters into strings, one may instead use a special bracket notation,
17905which is also used to print strings.  A sequence of characters of the form
17906@samp{["@var{XX}"]} within a string or character literal denotes the
17907(single) character whose numeric encoding is @var{XX} in hexadecimal.  The
17908sequence of characters @samp{["""]} also denotes a single quotation mark
17909in strings.   For example,
17910@smallexample
17911   "One line.["0a"]Next line.["0a"]"
17912@end smallexample
17913@noindent
17914contains an ASCII newline character (@code{Ada.Characters.Latin_1.LF})
17915after each period.
17916
17917@item
17918The subtype used as a prefix for the attributes @t{'Pos}, @t{'Min}, and
17919@t{'Max} is optional (and is ignored in any case).  For example, it is valid
17920to write
17921
17922@smallexample
17923(@value{GDBP}) print 'max(x, y)
17924@end smallexample
17925
17926@item
17927When printing arrays, @value{GDBN} uses positional notation when the
17928array has a lower bound of 1, and uses a modified named notation otherwise.
17929For example, a one-dimensional array of three integers with a lower bound
17930of 3 might print as
17931
17932@smallexample
17933(3 => 10, 17, 1)
17934@end smallexample
17935
17936@noindent
17937That is, in contrast to valid Ada, only the first component has a @code{=>}
17938clause.
17939
17940@item
17941You may abbreviate attributes in expressions with any unique,
17942multi-character subsequence of
17943their names (an exact match gets preference).
17944For example, you may use @t{a'len}, @t{a'gth}, or @t{a'lh}
17945in place of  @t{a'length}.
17946
17947@item
17948@cindex quoting Ada internal identifiers
17949Since Ada is case-insensitive, the debugger normally maps identifiers you type
17950to lower case.  The GNAT compiler uses upper-case characters for
17951some of its internal identifiers, which are normally of no interest to users.
17952For the rare occasions when you actually have to look at them,
17953enclose them in angle brackets to avoid the lower-case mapping.
17954For example,
17955@smallexample
17956(@value{GDBP}) print <JMPBUF_SAVE>[0]
17957@end smallexample
17958
17959@item
17960Printing an object of class-wide type or dereferencing an
17961access-to-class-wide value will display all the components of the object's
17962specific type (as indicated by its run-time tag).  Likewise, component
17963selection on such a value will operate on the specific type of the
17964object.
17965
17966@end itemize
17967
17968@node Overloading support for Ada
17969@subsubsection Overloading support for Ada
17970@cindex overloading, Ada
17971
17972The debugger supports limited overloading.  Given a subprogram call in which
17973the function symbol has multiple definitions, it will use the number of
17974actual parameters and some information about their types to attempt to narrow
17975the set of definitions.  It also makes very limited use of context, preferring
17976procedures to functions in the context of the @code{call} command, and
17977functions to procedures elsewhere.
17978
17979If, after narrowing, the set of matching definitions still contains more than
17980one definition, @value{GDBN} will display a menu to query which one it should
17981use, for instance:
17982
17983@smallexample
17984(@value{GDBP}) print f(1)
17985Multiple matches for f
17986[0] cancel
17987[1] foo.f (integer) return boolean at foo.adb:23
17988[2] foo.f (foo.new_integer) return boolean at foo.adb:28
17989>
17990@end smallexample
17991
17992In this case, just select one menu entry either to cancel expression evaluation
17993(type @kbd{0} and press @key{RET}) or to continue evaluation with a specific
17994instance (type the corresponding number and press @key{RET}).
17995
17996Here are a couple of commands to customize @value{GDBN}'s behavior in this
17997case:
17998
17999@table @code
18000
18001@kindex set ada print-signatures
18002@item set ada print-signatures
18003Control whether parameter types and return types are displayed in overloads
18004selection menus.  It is @code{on} by default.
18005@xref{Overloading support for Ada}.
18006
18007@kindex show ada print-signatures
18008@item show ada print-signatures
18009Show the current setting for displaying parameter types and return types in
18010overloads selection menu.
18011@xref{Overloading support for Ada}.
18012
18013@end table
18014
18015@node Stopping Before Main Program
18016@subsubsection Stopping at the Very Beginning
18017
18018@cindex breakpointing Ada elaboration code
18019It is sometimes necessary to debug the program during elaboration, and
18020before reaching the main procedure.
18021As defined in the Ada Reference
18022Manual, the elaboration code is invoked from a procedure called
18023@code{adainit}.  To run your program up to the beginning of
18024elaboration, simply use the following two commands:
18025@code{tbreak adainit} and @code{run}.
18026
18027@node Ada Exceptions
18028@subsubsection Ada Exceptions
18029
18030A command is provided to list all Ada exceptions:
18031
18032@table @code
18033@kindex info exceptions
18034@item info exceptions
18035@itemx info exceptions @var{regexp}
18036The @code{info exceptions} command allows you to list all Ada exceptions
18037defined within the program being debugged, as well as their addresses.
18038With a regular expression, @var{regexp}, as argument, only those exceptions
18039whose names match @var{regexp} are listed.
18040@end table
18041
18042Below is a small example, showing how the command can be used, first
18043without argument, and next with a regular expression passed as an
18044argument.
18045
18046@smallexample
18047(@value{GDBP}) info exceptions
18048All defined Ada exceptions:
18049constraint_error: 0x613da0
18050program_error: 0x613d20
18051storage_error: 0x613ce0
18052tasking_error: 0x613ca0
18053const.aint_global_e: 0x613b00
18054(@value{GDBP}) info exceptions const.aint
18055All Ada exceptions matching regular expression "const.aint":
18056constraint_error: 0x613da0
18057const.aint_global_e: 0x613b00
18058@end smallexample
18059
18060It is also possible to ask @value{GDBN} to stop your program's execution
18061when an exception is raised.  For more details, see @ref{Set Catchpoints}.
18062
18063@node Ada Tasks
18064@subsubsection Extensions for Ada Tasks
18065@cindex Ada, tasking
18066
18067Support for Ada tasks is analogous to that for threads (@pxref{Threads}).
18068@value{GDBN} provides the following task-related commands:
18069
18070@table @code
18071@kindex info tasks
18072@item info tasks
18073This command shows a list of current Ada tasks, as in the following example:
18074
18075
18076@smallexample
18077@iftex
18078@leftskip=0.5cm
18079@end iftex
18080(@value{GDBP}) info tasks
18081  ID       TID P-ID Pri State                 Name
18082   1   8088000   0   15 Child Activation Wait main_task
18083   2   80a4000   1   15 Accept Statement      b
18084   3   809a800   1   15 Child Activation Wait a
18085*  4   80ae800   3   15 Runnable              c
18086
18087@end smallexample
18088
18089@noindent
18090In this listing, the asterisk before the last task indicates it to be the
18091task currently being inspected.
18092
18093@table @asis
18094@item ID
18095Represents @value{GDBN}'s internal task number.
18096
18097@item TID
18098The Ada task ID.
18099
18100@item P-ID
18101The parent's task ID (@value{GDBN}'s internal task number).
18102
18103@item Pri
18104The base priority of the task.
18105
18106@item State
18107Current state of the task.
18108
18109@table @code
18110@item Unactivated
18111The task has been created but has not been activated.  It cannot be
18112executing.
18113
18114@item Runnable
18115The task is not blocked for any reason known to Ada.  (It may be waiting
18116for a mutex, though.) It is conceptually "executing" in normal mode.
18117
18118@item Terminated
18119The task is terminated, in the sense of ARM 9.3 (5).  Any dependents
18120that were waiting on terminate alternatives have been awakened and have
18121terminated themselves.
18122
18123@item Child Activation Wait
18124The task is waiting for created tasks to complete activation.
18125
18126@item Accept Statement
18127The task is waiting on an accept or selective wait statement.
18128
18129@item Waiting on entry call
18130The task is waiting on an entry call.
18131
18132@item Async Select Wait
18133The task is waiting to start the abortable part of an asynchronous
18134select statement.
18135
18136@item Delay Sleep
18137The task is waiting on a select statement with only a delay
18138alternative open.
18139
18140@item Child Termination Wait
18141The task is sleeping having completed a master within itself, and is
18142waiting for the tasks dependent on that master to become terminated or
18143waiting on a terminate Phase.
18144
18145@item Wait Child in Term Alt
18146The task is sleeping waiting for tasks on terminate alternatives to
18147finish terminating.
18148
18149@item Accepting RV with @var{taskno}
18150The task is accepting a rendez-vous with the task @var{taskno}.
18151@end table
18152
18153@item Name
18154Name of the task in the program.
18155
18156@end table
18157
18158@kindex info task @var{taskno}
18159@item info task @var{taskno}
18160This command shows detailed informations on the specified task, as in
18161the following example:
18162@smallexample
18163@iftex
18164@leftskip=0.5cm
18165@end iftex
18166(@value{GDBP}) info tasks
18167  ID       TID P-ID Pri State                  Name
18168   1   8077880    0  15 Child Activation Wait  main_task
18169*  2   807c468    1  15 Runnable               task_1
18170(@value{GDBP}) info task 2
18171Ada Task: 0x807c468
18172Name: "task_1"
18173Thread: 0
18174LWP: 0x1fac
18175Parent: 1 ("main_task")
18176Base Priority: 15
18177State: Runnable
18178@end smallexample
18179
18180@item task
18181@kindex task@r{ (Ada)}
18182@cindex current Ada task ID
18183This command prints the ID and name of the current task.
18184
18185@smallexample
18186@iftex
18187@leftskip=0.5cm
18188@end iftex
18189(@value{GDBP}) info tasks
18190  ID       TID P-ID Pri State                  Name
18191   1   8077870    0  15 Child Activation Wait  main_task
18192*  2   807c458    1  15 Runnable               some_task
18193(@value{GDBP}) task
18194[Current task is 2 "some_task"]
18195@end smallexample
18196
18197@item task @var{taskno}
18198@cindex Ada task switching
18199This command is like the @code{thread @var{thread-id}}
18200command (@pxref{Threads}).  It switches the context of debugging
18201from the current task to the given task.
18202
18203@smallexample
18204@iftex
18205@leftskip=0.5cm
18206@end iftex
18207(@value{GDBP}) info tasks
18208  ID       TID P-ID Pri State                  Name
18209   1   8077870    0  15 Child Activation Wait  main_task
18210*  2   807c458    1  15 Runnable               some_task
18211(@value{GDBP}) task 1
18212[Switching to task 1 "main_task"]
18213#0  0x8067726 in pthread_cond_wait ()
18214(@value{GDBP}) bt
18215#0  0x8067726 in pthread_cond_wait ()
18216#1  0x8056714 in system.os_interface.pthread_cond_wait ()
18217#2  0x805cb63 in system.task_primitives.operations.sleep ()
18218#3  0x806153e in system.tasking.stages.activate_tasks ()
18219#4  0x804aacc in un () at un.adb:5
18220@end smallexample
18221
18222@item break @var{location} task @var{taskno}
18223@itemx break @var{location} task @var{taskno} if @dots{}
18224@cindex breakpoints and tasks, in Ada
18225@cindex task breakpoints, in Ada
18226@kindex break @dots{} task @var{taskno}@r{ (Ada)}
18227These commands are like the @code{break @dots{} thread @dots{}}
18228command (@pxref{Thread Stops}).  The
18229@var{location} argument specifies source lines, as described
18230in @ref{Specify Location}.
18231
18232Use the qualifier @samp{task @var{taskno}} with a breakpoint command
18233to specify that you only want @value{GDBN} to stop the program when a
18234particular Ada task reaches this breakpoint.  The @var{taskno} is one of the
18235numeric task identifiers assigned by @value{GDBN}, shown in the first
18236column of the @samp{info tasks} display.
18237
18238If you do not specify @samp{task @var{taskno}} when you set a
18239breakpoint, the breakpoint applies to @emph{all} tasks of your
18240program.
18241
18242You can use the @code{task} qualifier on conditional breakpoints as
18243well; in this case, place @samp{task @var{taskno}} before the
18244breakpoint condition (before the @code{if}).
18245
18246For example,
18247
18248@smallexample
18249@iftex
18250@leftskip=0.5cm
18251@end iftex
18252(@value{GDBP}) info tasks
18253  ID       TID P-ID Pri State                 Name
18254   1 140022020   0   15 Child Activation Wait main_task
18255   2 140045060   1   15 Accept/Select Wait    t2
18256   3 140044840   1   15 Runnable              t1
18257*  4 140056040   1   15 Runnable              t3
18258(@value{GDBP}) b 15 task 2
18259Breakpoint 5 at 0x120044cb0: file test_task_debug.adb, line 15.
18260(@value{GDBP}) cont
18261Continuing.
18262task # 1 running
18263task # 2 running
18264
18265Breakpoint 5, test_task_debug () at test_task_debug.adb:15
1826615               flush;
18267(@value{GDBP}) info tasks
18268  ID       TID P-ID Pri State                 Name
18269   1 140022020   0   15 Child Activation Wait main_task
18270*  2 140045060   1   15 Runnable              t2
18271   3 140044840   1   15 Runnable              t1
18272   4 140056040   1   15 Delay Sleep           t3
18273@end smallexample
18274@end table
18275
18276@node Ada Tasks and Core Files
18277@subsubsection Tasking Support when Debugging Core Files
18278@cindex Ada tasking and core file debugging
18279
18280When inspecting a core file, as opposed to debugging a live program,
18281tasking support may be limited or even unavailable, depending on
18282the platform being used.
18283For instance, on x86-linux, the list of tasks is available, but task
18284switching is not supported.
18285
18286On certain platforms, the debugger needs to perform some
18287memory writes in order to provide Ada tasking support.  When inspecting
18288a core file, this means that the core file must be opened with read-write
18289privileges, using the command @samp{"set write on"} (@pxref{Patching}).
18290Under these circumstances, you should make a backup copy of the core
18291file before inspecting it with @value{GDBN}.
18292
18293@node Ravenscar Profile
18294@subsubsection Tasking Support when using the Ravenscar Profile
18295@cindex Ravenscar Profile
18296
18297The @dfn{Ravenscar Profile} is a subset of the Ada tasking features,
18298specifically designed for systems with safety-critical real-time
18299requirements.
18300
18301@table @code
18302@kindex set ravenscar task-switching on
18303@cindex task switching with program using Ravenscar Profile
18304@item set ravenscar task-switching on
18305Allows task switching when debugging a program that uses the Ravenscar
18306Profile.  This is the default.
18307
18308@kindex set ravenscar task-switching off
18309@item set ravenscar task-switching off
18310Turn off task switching when debugging a program that uses the Ravenscar
18311Profile.  This is mostly intended to disable the code that adds support
18312for the Ravenscar Profile, in case a bug in either @value{GDBN} or in
18313the Ravenscar runtime is preventing @value{GDBN} from working properly.
18314To be effective, this command should be run before the program is started.
18315
18316@kindex show ravenscar task-switching
18317@item show ravenscar task-switching
18318Show whether it is possible to switch from task to task in a program
18319using the Ravenscar Profile.
18320
18321@end table
18322
18323@cindex Ravenscar thread
18324When Ravenscar task-switching is enabled, Ravenscar tasks are
18325announced by @value{GDBN} as if they were threads:
18326
18327@smallexample
18328(gdb) continue
18329[New Ravenscar Thread 0x2b8f0]
18330@end smallexample
18331
18332Both Ravenscar tasks and the underlying CPU threads will show up in
18333the output of @code{info threads}:
18334
18335@smallexample
18336(gdb) info threads
18337  Id   Target Id                  Frame
18338  1    Thread 1 (CPU#0 [running]) simple () at simple.adb:10
18339  2    Thread 2 (CPU#1 [running]) 0x0000000000003d34 in __gnat_initialize_cpu_devices ()
18340  3    Thread 3 (CPU#2 [running]) 0x0000000000003d28 in __gnat_initialize_cpu_devices ()
18341  4    Thread 4 (CPU#3 [halted ]) 0x000000000000c6ec in system.task_primitives.operations.idle ()
18342* 5    Ravenscar Thread 0x2b8f0   simple () at simple.adb:10
18343  6    Ravenscar Thread 0x2f150   0x000000000000c6ec in system.task_primitives.operations.idle ()
18344@end smallexample
18345
18346One known limitation of the Ravenscar support in @value{GDBN} is that
18347it isn't currently possible to single-step through the runtime
18348initialization sequence.  If you need to debug this code, you should
18349use @code{set ravenscar task-switching off}.
18350
18351@node Ada Settings
18352@subsubsection Ada Settings
18353@cindex Ada settings
18354
18355@table @code
18356@kindex set varsize-limit
18357@item set varsize-limit @var{size}
18358Prevent @value{GDBN} from attempting to evaluate objects whose size
18359is above the given limit (@var{size}) when those sizes are computed
18360from run-time quantities.  This is typically the case when the object
18361has a variable size, such as an array whose bounds are not known at
18362compile time for example.  Setting @var{size} to @code{unlimited}
18363removes the size limitation.  By default, the limit is about 65KB.
18364
18365The purpose of having such a limit is to prevent @value{GDBN} from
18366trying to grab enormous chunks of virtual memory when asked to evaluate
18367a quantity whose bounds have been corrupted or have not yet been fully
18368initialized.  The limit applies to the results of some subexpressions
18369as well as to complete expressions.  For example, an expression denoting
18370a simple integer component, such as @code{x.y.z}, may fail if the size of
18371@code{x.y} is variable and exceeds @code{size}.  On the other hand,
18372@value{GDBN} is sometimes clever; the expression @code{A(i)}, where
18373@code{A} is an array variable with non-constant size, will generally
18374succeed regardless of the bounds on @code{A}, as long as the component
18375size is less than @var{size}.
18376
18377@kindex show varsize-limit
18378@item show varsize-limit
18379Show the limit on types whose size is determined by run-time quantities.
18380@end table
18381
18382@node Ada Glitches
18383@subsubsection Known Peculiarities of Ada Mode
18384@cindex Ada, problems
18385
18386Besides the omissions listed previously (@pxref{Omissions from Ada}),
18387we know of several problems with and limitations of Ada mode in
18388@value{GDBN},
18389some of which will be fixed with planned future releases of the debugger
18390and the GNU Ada compiler.
18391
18392@itemize @bullet
18393@item
18394Static constants that the compiler chooses not to materialize as objects in
18395storage are invisible to the debugger.
18396
18397@item
18398Named parameter associations in function argument lists are ignored (the
18399argument lists are treated as positional).
18400
18401@item
18402Many useful library packages are currently invisible to the debugger.
18403
18404@item
18405Fixed-point arithmetic, conversions, input, and output is carried out using
18406floating-point arithmetic, and may give results that only approximate those on
18407the host machine.
18408
18409@item
18410The GNAT compiler never generates the prefix @code{Standard} for any of
18411the standard symbols defined by the Ada language.  @value{GDBN} knows about
18412this: it will strip the prefix from names when you use it, and will never
18413look for a name you have so qualified among local symbols, nor match against
18414symbols in other packages or subprograms.  If you have
18415defined entities anywhere in your program other than parameters and
18416local variables whose simple names match names in @code{Standard},
18417GNAT's lack of qualification here can cause confusion.  When this happens,
18418you can usually resolve the confusion
18419by qualifying the problematic names with package
18420@code{Standard} explicitly.
18421@end itemize
18422
18423Older versions of the compiler sometimes generate erroneous debugging
18424information, resulting in the debugger incorrectly printing the value
18425of affected entities.  In some cases, the debugger is able to work
18426around an issue automatically. In other cases, the debugger is able
18427to work around the issue, but the work-around has to be specifically
18428enabled.
18429
18430@kindex set ada trust-PAD-over-XVS
18431@kindex show ada trust-PAD-over-XVS
18432@table @code
18433
18434@item set ada trust-PAD-over-XVS on
18435Configure GDB to strictly follow the GNAT encoding when computing the
18436value of Ada entities, particularly when @code{PAD} and @code{PAD___XVS}
18437types are involved (see @code{ada/exp_dbug.ads} in the GCC sources for
18438a complete description of the encoding used by the GNAT compiler).
18439This is the default.
18440
18441@item set ada trust-PAD-over-XVS off
18442This is related to the encoding using by the GNAT compiler.  If @value{GDBN}
18443sometimes prints the wrong value for certain entities, changing @code{ada
18444trust-PAD-over-XVS} to @code{off} activates a work-around which may fix
18445the issue.  It is always safe to set @code{ada trust-PAD-over-XVS} to
18446@code{off}, but this incurs a slight performance penalty, so it is
18447recommended to leave this setting to @code{on} unless necessary.
18448
18449@end table
18450
18451@cindex GNAT descriptive types
18452@cindex GNAT encoding
18453Internally, the debugger also relies on the compiler following a number
18454of conventions known as the @samp{GNAT Encoding}, all documented in
18455@file{gcc/ada/exp_dbug.ads} in the GCC sources. This encoding describes
18456how the debugging information should be generated for certain types.
18457In particular, this convention makes use of @dfn{descriptive types},
18458which are artificial types generated purely to help the debugger.
18459
18460These encodings were defined at a time when the debugging information
18461format used was not powerful enough to describe some of the more complex
18462types available in Ada.  Since DWARF allows us to express nearly all
18463Ada features, the long-term goal is to slowly replace these descriptive
18464types by their pure DWARF equivalent.  To facilitate that transition,
18465a new maintenance option is available to force the debugger to ignore
18466those descriptive types.  It allows the user to quickly evaluate how
18467well @value{GDBN} works without them.
18468
18469@table @code
18470
18471@kindex maint ada set ignore-descriptive-types
18472@item maintenance ada set ignore-descriptive-types [on|off]
18473Control whether the debugger should ignore descriptive types.
18474The default is not to ignore descriptives types (@code{off}).
18475
18476@kindex maint ada show ignore-descriptive-types
18477@item maintenance ada show ignore-descriptive-types
18478Show if descriptive types are ignored by @value{GDBN}.
18479
18480@end table
18481
18482@node Unsupported Languages
18483@section Unsupported Languages
18484
18485@cindex unsupported languages
18486@cindex minimal language
18487In addition to the other fully-supported programming languages,
18488@value{GDBN} also provides a pseudo-language, called @code{minimal}.
18489It does not represent a real programming language, but provides a set
18490of capabilities close to what the C or assembly languages provide.
18491This should allow most simple operations to be performed while debugging
18492an application that uses a language currently not supported by @value{GDBN}.
18493
18494If the language is set to @code{auto}, @value{GDBN} will automatically
18495select this language if the current frame corresponds to an unsupported
18496language.
18497
18498@node Symbols
18499@chapter Examining the Symbol Table
18500
18501The commands described in this chapter allow you to inquire about the
18502symbols (names of variables, functions and types) defined in your
18503program.  This information is inherent in the text of your program and
18504does not change as your program executes.  @value{GDBN} finds it in your
18505program's symbol table, in the file indicated when you started @value{GDBN}
18506(@pxref{File Options, ,Choosing Files}), or by one of the
18507file-management commands (@pxref{Files, ,Commands to Specify Files}).
18508
18509@cindex symbol names
18510@cindex names of symbols
18511@cindex quoting names
18512@anchor{quoting names}
18513Occasionally, you may need to refer to symbols that contain unusual
18514characters, which @value{GDBN} ordinarily treats as word delimiters.  The
18515most frequent case is in referring to static variables in other
18516source files (@pxref{Variables,,Program Variables}).  File names
18517are recorded in object files as debugging symbols, but @value{GDBN} would
18518ordinarily parse a typical file name, like @file{foo.c}, as the three words
18519@samp{foo} @samp{.} @samp{c}.  To allow @value{GDBN} to recognize
18520@samp{foo.c} as a single symbol, enclose it in single quotes; for example,
18521
18522@smallexample
18523p 'foo.c'::x
18524@end smallexample
18525
18526@noindent
18527looks up the value of @code{x} in the scope of the file @file{foo.c}.
18528
18529@table @code
18530@cindex case-insensitive symbol names
18531@cindex case sensitivity in symbol names
18532@kindex set case-sensitive
18533@item set case-sensitive on
18534@itemx set case-sensitive off
18535@itemx set case-sensitive auto
18536Normally, when @value{GDBN} looks up symbols, it matches their names
18537with case sensitivity determined by the current source language.
18538Occasionally, you may wish to control that.  The command @code{set
18539case-sensitive} lets you do that by specifying @code{on} for
18540case-sensitive matches or @code{off} for case-insensitive ones.  If
18541you specify @code{auto}, case sensitivity is reset to the default
18542suitable for the source language.  The default is case-sensitive
18543matches for all languages except for Fortran, for which the default is
18544case-insensitive matches.
18545
18546@kindex show case-sensitive
18547@item show case-sensitive
18548This command shows the current setting of case sensitivity for symbols
18549lookups.
18550
18551@kindex set print type methods
18552@item set print type methods
18553@itemx set print type methods on
18554@itemx set print type methods off
18555Normally, when @value{GDBN} prints a class, it displays any methods
18556declared in that class.  You can control this behavior either by
18557passing the appropriate flag to @code{ptype}, or using @command{set
18558print type methods}.  Specifying @code{on} will cause @value{GDBN} to
18559display the methods; this is the default.  Specifying @code{off} will
18560cause @value{GDBN} to omit the methods.
18561
18562@kindex show print type methods
18563@item show print type methods
18564This command shows the current setting of method display when printing
18565classes.
18566
18567@kindex set print type nested-type-limit
18568@item set print type nested-type-limit @var{limit}
18569@itemx set print type nested-type-limit unlimited
18570Set the limit of displayed nested types that the type printer will
18571show.  A @var{limit} of @code{unlimited} or @code{-1} will show all
18572nested definitions.  By default, the type printer will not show any nested
18573types defined in classes.
18574
18575@kindex show print type nested-type-limit
18576@item show print type nested-type-limit
18577This command shows the current display limit of nested types when
18578printing classes.
18579
18580@kindex set print type typedefs
18581@item set print type typedefs
18582@itemx set print type typedefs on
18583@itemx set print type typedefs off
18584
18585Normally, when @value{GDBN} prints a class, it displays any typedefs
18586defined in that class.  You can control this behavior either by
18587passing the appropriate flag to @code{ptype}, or using @command{set
18588print type typedefs}.  Specifying @code{on} will cause @value{GDBN} to
18589display the typedef definitions; this is the default.  Specifying
18590@code{off} will cause @value{GDBN} to omit the typedef definitions.
18591Note that this controls whether the typedef definition itself is
18592printed, not whether typedef names are substituted when printing other
18593types.
18594
18595@kindex show print type typedefs
18596@item show print type typedefs
18597This command shows the current setting of typedef display when
18598printing classes.
18599
18600@kindex info address
18601@cindex address of a symbol
18602@item info address @var{symbol}
18603Describe where the data for @var{symbol} is stored.  For a register
18604variable, this says which register it is kept in.  For a non-register
18605local variable, this prints the stack-frame offset at which the variable
18606is always stored.
18607
18608Note the contrast with @samp{print &@var{symbol}}, which does not work
18609at all for a register variable, and for a stack local variable prints
18610the exact address of the current instantiation of the variable.
18611
18612@kindex info symbol
18613@cindex symbol from address
18614@cindex closest symbol and offset for an address
18615@item info symbol @var{addr}
18616Print the name of a symbol which is stored at the address @var{addr}.
18617If no symbol is stored exactly at @var{addr}, @value{GDBN} prints the
18618nearest symbol and an offset from it:
18619
18620@smallexample
18621(@value{GDBP}) info symbol 0x54320
18622_initialize_vx + 396 in section .text
18623@end smallexample
18624
18625@noindent
18626This is the opposite of the @code{info address} command.  You can use
18627it to find out the name of a variable or a function given its address.
18628
18629For dynamically linked executables, the name of executable or shared
18630library containing the symbol is also printed:
18631
18632@smallexample
18633(@value{GDBP}) info symbol 0x400225
18634_start + 5 in section .text of /tmp/a.out
18635(@value{GDBP}) info symbol 0x2aaaac2811cf
18636__read_nocancel + 6 in section .text of /usr/lib64/libc.so.6
18637@end smallexample
18638
18639@kindex demangle
18640@cindex demangle
18641@item demangle @r{[}-l @var{language}@r{]} @r{[}@var{--}@r{]} @var{name}
18642Demangle @var{name}.
18643If @var{language} is provided it is the name of the language to demangle
18644@var{name} in.  Otherwise @var{name} is demangled in the current language.
18645
18646The @samp{--} option specifies the end of options,
18647and is useful when @var{name} begins with a dash.
18648
18649The parameter @code{demangle-style} specifies how to interpret the kind
18650of mangling used. @xref{Print Settings}.
18651
18652@kindex whatis
18653@item whatis[/@var{flags}] [@var{arg}]
18654Print the data type of @var{arg}, which can be either an expression
18655or a name of a data type.  With no argument, print the data type of
18656@code{$}, the last value in the value history.
18657
18658If @var{arg} is an expression (@pxref{Expressions, ,Expressions}), it
18659is not actually evaluated, and any side-effecting operations (such as
18660assignments or function calls) inside it do not take place.
18661
18662If @var{arg} is a variable or an expression, @code{whatis} prints its
18663literal type as it is used in the source code.  If the type was
18664defined using a @code{typedef}, @code{whatis} will @emph{not} print
18665the data type underlying the @code{typedef}.  If the type of the
18666variable or the expression is a compound data type, such as
18667@code{struct} or  @code{class}, @code{whatis} never prints their
18668fields or methods.  It just prints the @code{struct}/@code{class}
18669name (a.k.a.@: its @dfn{tag}).  If you want to see the members of
18670such a compound data type, use @code{ptype}.
18671
18672If @var{arg} is a type name that was defined using @code{typedef},
18673@code{whatis} @dfn{unrolls} only one level of that @code{typedef}.
18674Unrolling means that @code{whatis} will show the underlying type used
18675in the @code{typedef} declaration of @var{arg}.  However, if that
18676underlying type is also a @code{typedef}, @code{whatis} will not
18677unroll it.
18678
18679For C code, the type names may also have the form @samp{class
18680@var{class-name}}, @samp{struct @var{struct-tag}}, @samp{union
18681@var{union-tag}} or @samp{enum @var{enum-tag}}.
18682
18683@var{flags} can be used to modify how the type is displayed.
18684Available flags are:
18685
18686@table @code
18687@item r
18688Display in ``raw'' form.  Normally, @value{GDBN} substitutes template
18689parameters and typedefs defined in a class when printing the class'
18690members.  The @code{/r} flag disables this.
18691
18692@item m
18693Do not print methods defined in the class.
18694
18695@item M
18696Print methods defined in the class.  This is the default, but the flag
18697exists in case you change the default with @command{set print type methods}.
18698
18699@item t
18700Do not print typedefs defined in the class.  Note that this controls
18701whether the typedef definition itself is printed, not whether typedef
18702names are substituted when printing other types.
18703
18704@item T
18705Print typedefs defined in the class.  This is the default, but the flag
18706exists in case you change the default with @command{set print type typedefs}.
18707
18708@item o
18709Print the offsets and sizes of fields in a struct, similar to what the
18710@command{pahole} tool does.  This option implies the @code{/tm} flags.
18711
18712For example, given the following declarations:
18713
18714@smallexample
18715struct tuv
18716@{
18717  int a1;
18718  char *a2;
18719  int a3;
18720@};
18721
18722struct xyz
18723@{
18724  int f1;
18725  char f2;
18726  void *f3;
18727  struct tuv f4;
18728@};
18729
18730union qwe
18731@{
18732  struct tuv fff1;
18733  struct xyz fff2;
18734@};
18735
18736struct tyu
18737@{
18738  int a1 : 1;
18739  int a2 : 3;
18740  int a3 : 23;
18741  char a4 : 2;
18742  int64_t a5;
18743  int a6 : 5;
18744  int64_t a7 : 3;
18745@};
18746@end smallexample
18747
18748Issuing a @kbd{ptype /o struct tuv} command would print:
18749
18750@smallexample
18751(@value{GDBP}) ptype /o struct tuv
18752/* offset    |  size */  type = struct tuv @{
18753/*    0      |     4 */    int a1;
18754/* XXX  4-byte hole  */
18755/*    8      |     8 */    char *a2;
18756/*   16      |     4 */    int a3;
18757
18758                           /* total size (bytes):   24 */
18759                         @}
18760@end smallexample
18761
18762Notice the format of the first column of comments.  There, you can
18763find two parts separated by the @samp{|} character: the @emph{offset},
18764which indicates where the field is located inside the struct, in
18765bytes, and the @emph{size} of the field.  Another interesting line is
18766the marker of a @emph{hole} in the struct, indicating that it may be
18767possible to pack the struct and make it use less space by reorganizing
18768its fields.
18769
18770It is also possible to print offsets inside an union:
18771
18772@smallexample
18773(@value{GDBP}) ptype /o union qwe
18774/* offset    |  size */  type = union qwe @{
18775/*                24 */    struct tuv @{
18776/*    0      |     4 */        int a1;
18777/* XXX  4-byte hole  */
18778/*    8      |     8 */        char *a2;
18779/*   16      |     4 */        int a3;
18780
18781                               /* total size (bytes):   24 */
18782                           @} fff1;
18783/*                40 */    struct xyz @{
18784/*    0      |     4 */        int f1;
18785/*    4      |     1 */        char f2;
18786/* XXX  3-byte hole  */
18787/*    8      |     8 */        void *f3;
18788/*   16      |    24 */        struct tuv @{
18789/*   16      |     4 */            int a1;
18790/* XXX  4-byte hole  */
18791/*   24      |     8 */            char *a2;
18792/*   32      |     4 */            int a3;
18793
18794                                   /* total size (bytes):   24 */
18795                               @} f4;
18796
18797                               /* total size (bytes):   40 */
18798                           @} fff2;
18799
18800                           /* total size (bytes):   40 */
18801                         @}
18802@end smallexample
18803
18804In this case, since @code{struct tuv} and @code{struct xyz} occupy the
18805same space (because we are dealing with an union), the offset is not
18806printed for them.  However, you can still examine the offset of each
18807of these structures' fields.
18808
18809Another useful scenario is printing the offsets of a struct containing
18810bitfields:
18811
18812@smallexample
18813(@value{GDBP}) ptype /o struct tyu
18814/* offset    |  size */  type = struct tyu @{
18815/*    0:31   |     4 */    int a1 : 1;
18816/*    0:28   |     4 */    int a2 : 3;
18817/*    0: 5   |     4 */    int a3 : 23;
18818/*    3: 3   |     1 */    signed char a4 : 2;
18819/* XXX  3-bit hole   */
18820/* XXX  4-byte hole  */
18821/*    8      |     8 */    int64_t a5;
18822/*   16: 0   |     4 */    int a6 : 5;
18823/*   16: 5   |     8 */    int64_t a7 : 3;
18824"/* XXX  7-byte padding  */
18825
18826                           /* total size (bytes):   24 */
18827                         @}
18828@end smallexample
18829
18830Note how the offset information is now extended to also include the
18831first bit of the bitfield.
18832@end table
18833
18834@kindex ptype
18835@item ptype[/@var{flags}] [@var{arg}]
18836@code{ptype} accepts the same arguments as @code{whatis}, but prints a
18837detailed description of the type, instead of just the name of the type.
18838@xref{Expressions, ,Expressions}.
18839
18840Contrary to @code{whatis}, @code{ptype} always unrolls any
18841@code{typedef}s in its argument declaration, whether the argument is
18842a variable, expression, or a data type.  This means that @code{ptype}
18843of a variable or an expression will not print literally its type as
18844present in the source code---use @code{whatis} for that.  @code{typedef}s at
18845the pointer or reference targets are also unrolled.  Only @code{typedef}s of
18846fields, methods and inner @code{class typedef}s of @code{struct}s,
18847@code{class}es and @code{union}s are not unrolled even with @code{ptype}.
18848
18849For example, for this variable declaration:
18850
18851@smallexample
18852typedef double real_t;
18853struct complex @{ real_t real; double imag; @};
18854typedef struct complex complex_t;
18855complex_t var;
18856real_t *real_pointer_var;
18857@end smallexample
18858
18859@noindent
18860the two commands give this output:
18861
18862@smallexample
18863@group
18864(@value{GDBP}) whatis var
18865type = complex_t
18866(@value{GDBP}) ptype var
18867type = struct complex @{
18868    real_t real;
18869    double imag;
18870@}
18871(@value{GDBP}) whatis complex_t
18872type = struct complex
18873(@value{GDBP}) whatis struct complex
18874type = struct complex
18875(@value{GDBP}) ptype struct complex
18876type = struct complex @{
18877    real_t real;
18878    double imag;
18879@}
18880(@value{GDBP}) whatis real_pointer_var
18881type = real_t *
18882(@value{GDBP}) ptype real_pointer_var
18883type = double *
18884@end group
18885@end smallexample
18886
18887@noindent
18888As with @code{whatis}, using @code{ptype} without an argument refers to
18889the type of @code{$}, the last value in the value history.
18890
18891@cindex incomplete type
18892Sometimes, programs use opaque data types or incomplete specifications
18893of complex data structure.  If the debug information included in the
18894program does not allow @value{GDBN} to display a full declaration of
18895the data type, it will say @samp{<incomplete type>}.  For example,
18896given these declarations:
18897
18898@smallexample
18899    struct foo;
18900    struct foo *fooptr;
18901@end smallexample
18902
18903@noindent
18904but no definition for @code{struct foo} itself, @value{GDBN} will say:
18905
18906@smallexample
18907  (@value{GDBP}) ptype foo
18908  $1 = <incomplete type>
18909@end smallexample
18910
18911@noindent
18912``Incomplete type'' is C terminology for data types that are not
18913completely specified.
18914
18915@cindex unknown type
18916Othertimes, information about a variable's type is completely absent
18917from the debug information included in the program.  This most often
18918happens when the program or library where the variable is defined
18919includes no debug information at all.  @value{GDBN} knows the variable
18920exists from inspecting the linker/loader symbol table (e.g., the ELF
18921dynamic symbol table), but such symbols do not contain type
18922information.  Inspecting the type of a (global) variable for which
18923@value{GDBN} has no type information shows:
18924
18925@smallexample
18926  (@value{GDBP}) ptype var
18927  type = <data variable, no debug info>
18928@end smallexample
18929
18930@xref{Variables, no debug info variables}, for how to print the values
18931of such variables.
18932
18933@kindex info types
18934@item info types [-q] [@var{regexp}]
18935Print a brief description of all types whose names match the regular
18936expression @var{regexp} (or all types in your program, if you supply
18937no argument).  Each complete typename is matched as though it were a
18938complete line; thus, @samp{i type value} gives information on all
18939types in your program whose names include the string @code{value}, but
18940@samp{i type ^value$} gives information only on types whose complete
18941name is @code{value}.
18942
18943In programs using different languages, @value{GDBN} chooses the syntax
18944to print the type description according to the
18945@samp{set language} value: using @samp{set language auto}
18946(see @ref{Automatically, ,Set Language Automatically}) means to use the
18947language of the type, other values mean to use
18948the manually specified language (see @ref{Manually, ,Set Language Manually}).
18949
18950This command differs from @code{ptype} in two ways: first, like
18951@code{whatis}, it does not print a detailed description; second, it
18952lists all source files and line numbers where a type is defined.
18953
18954The output from @samp{into types} is proceeded with a header line
18955describing what types are being listed.  The optional flag @samp{-q},
18956which stands for @samp{quiet}, disables printing this header
18957information.
18958
18959@kindex info type-printers
18960@item info type-printers
18961Versions of @value{GDBN} that ship with Python scripting enabled may
18962have ``type printers'' available.  When using @command{ptype} or
18963@command{whatis}, these printers are consulted when the name of a type
18964is needed.  @xref{Type Printing API}, for more information on writing
18965type printers.
18966
18967@code{info type-printers} displays all the available type printers.
18968
18969@kindex enable type-printer
18970@kindex disable type-printer
18971@item enable type-printer @var{name}@dots{}
18972@item disable type-printer @var{name}@dots{}
18973These commands can be used to enable or disable type printers.
18974
18975@kindex info scope
18976@cindex local variables
18977@item info scope @var{location}
18978List all the variables local to a particular scope.  This command
18979accepts a @var{location} argument---a function name, a source line, or
18980an address preceded by a @samp{*}, and prints all the variables local
18981to the scope defined by that location.  (@xref{Specify Location}, for
18982details about supported forms of @var{location}.)  For example:
18983
18984@smallexample
18985(@value{GDBP}) @b{info scope command_line_handler}
18986Scope for command_line_handler:
18987Symbol rl is an argument at stack/frame offset 8, length 4.
18988Symbol linebuffer is in static storage at address 0x150a18, length 4.
18989Symbol linelength is in static storage at address 0x150a1c, length 4.
18990Symbol p is a local variable in register $esi, length 4.
18991Symbol p1 is a local variable in register $ebx, length 4.
18992Symbol nline is a local variable in register $edx, length 4.
18993Symbol repeat is a local variable at frame offset -8, length 4.
18994@end smallexample
18995
18996@noindent
18997This command is especially useful for determining what data to collect
18998during a @dfn{trace experiment}, see @ref{Tracepoint Actions,
18999collect}.
19000
19001@kindex info source
19002@item info source
19003Show information about the current source file---that is, the source file for
19004the function containing the current point of execution:
19005@itemize @bullet
19006@item
19007the name of the source file, and the directory containing it,
19008@item
19009the directory it was compiled in,
19010@item
19011its length, in lines,
19012@item
19013which programming language it is written in,
19014@item
19015if the debug information provides it, the program that compiled the file
19016(which may include, e.g., the compiler version and command line arguments),
19017@item
19018whether the executable includes debugging information for that file, and
19019if so, what format the information is in (e.g., STABS, Dwarf 2, etc.), and
19020@item
19021whether the debugging information includes information about
19022preprocessor macros.
19023@end itemize
19024
19025
19026@kindex info sources
19027@item info sources
19028Print the names of all source files in your program for which there is
19029debugging information, organized into two lists: files whose symbols
19030have already been read, and files whose symbols will be read when needed.
19031
19032@item info sources [-dirname | -basename] [--] [@var{regexp}]
19033Like @samp{info sources}, but only print the names of the files
19034matching the provided @var{regexp}.
19035By default, the @var{regexp} is used to match anywhere in the filename.
19036If @code{-dirname}, only files having a dirname matching @var{regexp} are shown.
19037If  @code{-basename}, only files having a basename matching @var{regexp}
19038are shown.
19039The matching is case-sensitive, except on operating systems that
19040have case-insensitive filesystem (e.g., MS-Windows).
19041
19042@kindex info functions
19043@item info functions [-q] [-n]
19044Print the names and data types of all defined functions.
19045Similarly to @samp{info types}, this command groups its output by source
19046files and annotates each function definition with its source line
19047number.
19048
19049In programs using different languages, @value{GDBN} chooses the syntax
19050to print the function name and type according to the
19051@samp{set language} value: using @samp{set language auto}
19052(see @ref{Automatically, ,Set Language Automatically}) means to use the
19053language of the function, other values mean to use
19054the manually specified language (see @ref{Manually, ,Set Language Manually}).
19055
19056The @samp{-n} flag excludes @dfn{non-debugging symbols} from the
19057results.  A non-debugging symbol is a symbol that comes from the
19058executable's symbol table, not from the debug information (for
19059example, DWARF) associated with the executable.
19060
19061The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19062printing header information and messages explaining why no functions
19063have been printed.
19064
19065@item info functions [-q] [-n] [-t @var{type_regexp}] [@var{regexp}]
19066Like @samp{info functions}, but only print the names and data types
19067of the functions selected with the provided regexp(s).
19068
19069If @var{regexp} is provided, print only the functions whose names
19070match the regular expression @var{regexp}.
19071Thus, @samp{info fun step} finds all functions whose
19072names include @code{step}; @samp{info fun ^step} finds those whose names
19073start with @code{step}.  If a function name contains characters that
19074conflict with the regular expression language (e.g.@:
19075@samp{operator*()}), they may be quoted with a backslash.
19076
19077If @var{type_regexp} is provided, print only the functions whose
19078types, as printed by the @code{whatis} command, match
19079the regular expression @var{type_regexp}.
19080If @var{type_regexp} contains space(s), it should be enclosed in
19081quote characters.  If needed, use backslash to escape the meaning
19082of special characters or quotes.
19083Thus, @samp{info fun -t '^int ('} finds the functions that return
19084an integer; @samp{info fun -t '(.*int.*'} finds the functions that
19085have an argument type containing int; @samp{info fun -t '^int (' ^step}
19086finds the functions whose names start with @code{step} and that return
19087int.
19088
19089If both @var{regexp} and @var{type_regexp} are provided, a function
19090is printed only if its name matches @var{regexp} and its type matches
19091@var{type_regexp}.
19092
19093
19094@kindex info variables
19095@item info variables [-q] [-n]
19096Print the names and data types of all variables that are defined
19097outside of functions (i.e.@: excluding local variables).
19098The printed variables are grouped by source files and annotated with
19099their respective source line numbers.
19100
19101In programs using different languages, @value{GDBN} chooses the syntax
19102to print the variable name and type according to the
19103@samp{set language} value: using @samp{set language auto}
19104(see @ref{Automatically, ,Set Language Automatically}) means to use the
19105language of the variable, other values mean to use
19106the manually specified language (see @ref{Manually, ,Set Language Manually}).
19107
19108The @samp{-n} flag excludes non-debugging symbols from the results.
19109
19110The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19111printing header information and messages explaining why no variables
19112have been printed.
19113
19114@item info variables [-q] [-n] [-t @var{type_regexp}] [@var{regexp}]
19115Like @kbd{info variables}, but only print the variables selected
19116with the provided regexp(s).
19117
19118If @var{regexp} is provided, print only the variables whose names
19119match the regular expression @var{regexp}.
19120
19121If @var{type_regexp} is provided, print only the variables whose
19122types, as printed by the @code{whatis} command, match
19123the regular expression @var{type_regexp}.
19124If @var{type_regexp} contains space(s), it should be enclosed in
19125quote characters.  If needed, use backslash to escape the meaning
19126of special characters or quotes.
19127
19128If both @var{regexp} and @var{type_regexp} are provided, an argument
19129is printed only if its name matches @var{regexp} and its type matches
19130@var{type_regexp}.
19131
19132@kindex info modules
19133@cindex modules
19134@item info modules @r{[}-q@r{]} @r{[}@var{regexp}@r{]}
19135List all Fortran modules in the program, or all modules matching the
19136optional regular expression @var{regexp}.
19137
19138The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19139printing header information and messages explaining why no modules
19140have been printed.
19141
19142@kindex info module
19143@cindex Fortran modules, information about
19144@cindex functions and variables by Fortran module
19145@cindex module functions and variables
19146@item info module functions @r{[}-q@r{]} @r{[}-m @var{module-regexp}@r{]} @r{[}-t @var{type-regexp}@r{]} @r{[}@var{regexp}@r{]}
19147@itemx info module variables @r{[}-q@r{]} @r{[}-m @var{module-regexp}@r{]} @r{[}-t @var{type-regexp}@r{]} @r{[}@var{regexp}@r{]}
19148List all functions or variables within all Fortran modules.  The set
19149of functions or variables listed can be limited by providing some or
19150all of the optional regular expressions.  If @var{module-regexp} is
19151provided, then only Fortran modules matching @var{module-regexp} will
19152be searched.  Only functions or variables whose type matches the
19153optional regular expression @var{type-regexp} will be listed.  And
19154only functions or variables whose name matches the optional regular
19155expression @var{regexp} will be listed.
19156
19157The optional flag @samp{-q}, which stands for @samp{quiet}, disables
19158printing header information and messages explaining why no functions
19159or variables have been printed.
19160
19161@kindex info classes
19162@cindex Objective-C, classes and selectors
19163@item info classes
19164@itemx info classes @var{regexp}
19165Display all Objective-C classes in your program, or
19166(with the @var{regexp} argument) all those matching a particular regular
19167expression.
19168
19169@kindex info selectors
19170@item info selectors
19171@itemx info selectors @var{regexp}
19172Display all Objective-C selectors in your program, or
19173(with the @var{regexp} argument) all those matching a particular regular
19174expression.
19175
19176@ignore
19177This was never implemented.
19178@kindex info methods
19179@item info methods
19180@itemx info methods @var{regexp}
19181The @code{info methods} command permits the user to examine all defined
19182methods within C@t{++} program, or (with the @var{regexp} argument) a
19183specific set of methods found in the various C@t{++} classes.  Many
19184C@t{++} classes provide a large number of methods.  Thus, the output
19185from the @code{ptype} command can be overwhelming and hard to use.  The
19186@code{info-methods} command filters the methods, printing only those
19187which match the regular-expression @var{regexp}.
19188@end ignore
19189
19190@cindex opaque data types
19191@kindex set opaque-type-resolution
19192@item set opaque-type-resolution on
19193Tell @value{GDBN} to resolve opaque types.  An opaque type is a type
19194declared as a pointer to a @code{struct}, @code{class}, or
19195@code{union}---for example, @code{struct MyType *}---that is used in one
19196source file although the full declaration of @code{struct MyType} is in
19197another source file.  The default is on.
19198
19199A change in the setting of this subcommand will not take effect until
19200the next time symbols for a file are loaded.
19201
19202@item set opaque-type-resolution off
19203Tell @value{GDBN} not to resolve opaque types.  In this case, the type
19204is printed as follows:
19205@smallexample
19206@{<no data fields>@}
19207@end smallexample
19208
19209@kindex show opaque-type-resolution
19210@item show opaque-type-resolution
19211Show whether opaque types are resolved or not.
19212
19213@kindex set print symbol-loading
19214@cindex print messages when symbols are loaded
19215@item set print symbol-loading
19216@itemx set print symbol-loading full
19217@itemx set print symbol-loading brief
19218@itemx set print symbol-loading off
19219The @code{set print symbol-loading} command allows you to control the
19220printing of messages when @value{GDBN} loads symbol information.
19221By default a message is printed for the executable and one for each
19222shared library, and normally this is what you want.  However, when
19223debugging apps with large numbers of shared libraries these messages
19224can be annoying.
19225When set to @code{brief} a message is printed for each executable,
19226and when @value{GDBN} loads a collection of shared libraries at once
19227it will only print one message regardless of the number of shared
19228libraries.  When set to @code{off} no messages are printed.
19229
19230@kindex show print symbol-loading
19231@item show print symbol-loading
19232Show whether messages will be printed when a @value{GDBN} command
19233entered from the keyboard causes symbol information to be loaded.
19234
19235@kindex maint print symbols
19236@cindex symbol dump
19237@kindex maint print psymbols
19238@cindex partial symbol dump
19239@kindex maint print msymbols
19240@cindex minimal symbol dump
19241@item maint print symbols @r{[}-pc @var{address}@r{]} @r{[}@var{filename}@r{]}
19242@itemx maint print symbols @r{[}-objfile @var{objfile}@r{]} @r{[}-source @var{source}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19243@itemx maint print psymbols @r{[}-objfile @var{objfile}@r{]} @r{[}-pc @var{address}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19244@itemx maint print psymbols @r{[}-objfile @var{objfile}@r{]} @r{[}-source @var{source}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19245@itemx maint print msymbols @r{[}-objfile @var{objfile}@r{]} @r{[}--@r{]} @r{[}@var{filename}@r{]}
19246Write a dump of debugging symbol data into the file @var{filename} or
19247the terminal if @var{filename} is unspecified.
19248If @code{-objfile @var{objfile}} is specified, only dump symbols for
19249that objfile.
19250If @code{-pc @var{address}} is specified, only dump symbols for the file
19251with code at that address.  Note that @var{address} may be a symbol like
19252@code{main}.
19253If @code{-source @var{source}} is specified, only dump symbols for that
19254source file.
19255
19256These commands are used to debug the @value{GDBN} symbol-reading code.
19257These commands do not modify internal @value{GDBN} state, therefore
19258@samp{maint print symbols} will only print symbols for already expanded symbol
19259tables.
19260You can use the command @code{info sources} to find out which files these are.
19261If you use @samp{maint print psymbols} instead, the dump shows information
19262about symbols that @value{GDBN} only knows partially---that is, symbols
19263defined in files that @value{GDBN} has skimmed, but not yet read completely.
19264Finally, @samp{maint print msymbols} just dumps ``minimal symbols'', e.g.,
19265``ELF symbols''.
19266
19267@xref{Files, ,Commands to Specify Files}, for a discussion of how
19268@value{GDBN} reads symbols (in the description of @code{symbol-file}).
19269
19270@kindex maint info symtabs
19271@kindex maint info psymtabs
19272@cindex listing @value{GDBN}'s internal symbol tables
19273@cindex symbol tables, listing @value{GDBN}'s internal
19274@cindex full symbol tables, listing @value{GDBN}'s internal
19275@cindex partial symbol tables, listing @value{GDBN}'s internal
19276@item maint info symtabs @r{[} @var{regexp} @r{]}
19277@itemx maint info psymtabs @r{[} @var{regexp} @r{]}
19278
19279List the @code{struct symtab} or @code{struct partial_symtab}
19280structures whose names match @var{regexp}.  If @var{regexp} is not
19281given, list them all.  The output includes expressions which you can
19282copy into a @value{GDBN} debugging this one to examine a particular
19283structure in more detail.  For example:
19284
19285@smallexample
19286(@value{GDBP}) maint info psymtabs dwarf2read
19287@{ objfile /home/gnu/build/gdb/gdb
19288  ((struct objfile *) 0x82e69d0)
19289  @{ psymtab /home/gnu/src/gdb/dwarf2read.c
19290    ((struct partial_symtab *) 0x8474b10)
19291    readin no
19292    fullname (null)
19293    text addresses 0x814d3c8 -- 0x8158074
19294    globals (* (struct partial_symbol **) 0x8507a08 @@ 9)
19295    statics (* (struct partial_symbol **) 0x40e95b78 @@ 2882)
19296    dependencies (none)
19297  @}
19298@}
19299(@value{GDBP}) maint info symtabs
19300(@value{GDBP})
19301@end smallexample
19302@noindent
19303We see that there is one partial symbol table whose filename contains
19304the string @samp{dwarf2read}, belonging to the @samp{gdb} executable;
19305and we see that @value{GDBN} has not read in any symtabs yet at all.
19306If we set a breakpoint on a function, that will cause @value{GDBN} to
19307read the symtab for the compilation unit containing that function:
19308
19309@smallexample
19310(@value{GDBP}) break dwarf2_psymtab_to_symtab
19311Breakpoint 1 at 0x814e5da: file /home/gnu/src/gdb/dwarf2read.c,
19312line 1574.
19313(@value{GDBP}) maint info symtabs
19314@{ objfile /home/gnu/build/gdb/gdb
19315  ((struct objfile *) 0x82e69d0)
19316  @{ symtab /home/gnu/src/gdb/dwarf2read.c
19317    ((struct symtab *) 0x86c1f38)
19318    dirname (null)
19319    fullname (null)
19320    blockvector ((struct blockvector *) 0x86c1bd0) (primary)
19321    linetable ((struct linetable *) 0x8370fa0)
19322    debugformat DWARF 2
19323  @}
19324@}
19325(@value{GDBP})
19326@end smallexample
19327
19328@kindex maint info line-table
19329@cindex listing @value{GDBN}'s internal line tables
19330@cindex line tables, listing @value{GDBN}'s internal
19331@item maint info line-table @r{[} @var{regexp} @r{]}
19332
19333List the @code{struct linetable} from all @code{struct symtab}
19334instances whose name matches @var{regexp}.  If @var{regexp} is not
19335given, list the @code{struct linetable} from all @code{struct symtab}.
19336
19337@kindex maint set symbol-cache-size
19338@cindex symbol cache size
19339@item maint set symbol-cache-size @var{size}
19340Set the size of the symbol cache to @var{size}.
19341The default size is intended to be good enough for debugging
19342most applications.  This option exists to allow for experimenting
19343with different sizes.
19344
19345@kindex maint show symbol-cache-size
19346@item maint show symbol-cache-size
19347Show the size of the symbol cache.
19348
19349@kindex maint print symbol-cache
19350@cindex symbol cache, printing its contents
19351@item maint print symbol-cache
19352Print the contents of the symbol cache.
19353This is useful when debugging symbol cache issues.
19354
19355@kindex maint print symbol-cache-statistics
19356@cindex symbol cache, printing usage statistics
19357@item maint print symbol-cache-statistics
19358Print symbol cache usage statistics.
19359This helps determine how well the cache is being utilized.
19360
19361@kindex maint flush-symbol-cache
19362@cindex symbol cache, flushing
19363@item maint flush-symbol-cache
19364Flush the contents of the symbol cache, all entries are removed.
19365This command is useful when debugging the symbol cache.
19366It is also useful when collecting performance data.
19367
19368@end table
19369
19370@node Altering
19371@chapter Altering Execution
19372
19373Once you think you have found an error in your program, you might want to
19374find out for certain whether correcting the apparent error would lead to
19375correct results in the rest of the run.  You can find the answer by
19376experiment, using the @value{GDBN} features for altering execution of the
19377program.
19378
19379For example, you can store new values into variables or memory
19380locations, give your program a signal, restart it at a different
19381address, or even return prematurely from a function.
19382
19383@menu
19384* Assignment::                  Assignment to variables
19385* Jumping::                     Continuing at a different address
19386* Signaling::                   Giving your program a signal
19387* Returning::                   Returning from a function
19388* Calling::                     Calling your program's functions
19389* Patching::                    Patching your program
19390* Compiling and Injecting Code:: Compiling and injecting code in @value{GDBN}
19391@end menu
19392
19393@node Assignment
19394@section Assignment to Variables
19395
19396@cindex assignment
19397@cindex setting variables
19398To alter the value of a variable, evaluate an assignment expression.
19399@xref{Expressions, ,Expressions}.  For example,
19400
19401@smallexample
19402print x=4
19403@end smallexample
19404
19405@noindent
19406stores the value 4 into the variable @code{x}, and then prints the
19407value of the assignment expression (which is 4).
19408@xref{Languages, ,Using @value{GDBN} with Different Languages}, for more
19409information on operators in supported languages.
19410
19411@kindex set variable
19412@cindex variables, setting
19413If you are not interested in seeing the value of the assignment, use the
19414@code{set} command instead of the @code{print} command.  @code{set} is
19415really the same as @code{print} except that the expression's value is
19416not printed and is not put in the value history (@pxref{Value History,
19417,Value History}).  The expression is evaluated only for its effects.
19418
19419If the beginning of the argument string of the @code{set} command
19420appears identical to a @code{set} subcommand, use the @code{set
19421variable} command instead of just @code{set}.  This command is identical
19422to @code{set} except for its lack of subcommands.  For example, if your
19423program has a variable @code{width}, you get an error if you try to set
19424a new value with just @samp{set width=13}, because @value{GDBN} has the
19425command @code{set width}:
19426
19427@smallexample
19428(@value{GDBP}) whatis width
19429type = double
19430(@value{GDBP}) p width
19431$4 = 13
19432(@value{GDBP}) set width=47
19433Invalid syntax in expression.
19434@end smallexample
19435
19436@noindent
19437The invalid expression, of course, is @samp{=47}.  In
19438order to actually set the program's variable @code{width}, use
19439
19440@smallexample
19441(@value{GDBP}) set var width=47
19442@end smallexample
19443
19444Because the @code{set} command has many subcommands that can conflict
19445with the names of program variables, it is a good idea to use the
19446@code{set variable} command instead of just @code{set}.  For example, if
19447your program has a variable @code{g}, you run into problems if you try
19448to set a new value with just @samp{set g=4}, because @value{GDBN} has
19449the command @code{set gnutarget}, abbreviated @code{set g}:
19450
19451@smallexample
19452@group
19453(@value{GDBP}) whatis g
19454type = double
19455(@value{GDBP}) p g
19456$1 = 1
19457(@value{GDBP}) set g=4
19458(@value{GDBP}) p g
19459$2 = 1
19460(@value{GDBP}) r
19461The program being debugged has been started already.
19462Start it from the beginning? (y or n) y
19463Starting program: /home/smith/cc_progs/a.out
19464"/home/smith/cc_progs/a.out": can't open to read symbols:
19465                                 Invalid bfd target.
19466(@value{GDBP}) show g
19467The current BFD target is "=4".
19468@end group
19469@end smallexample
19470
19471@noindent
19472The program variable @code{g} did not change, and you silently set the
19473@code{gnutarget} to an invalid value.  In order to set the variable
19474@code{g}, use
19475
19476@smallexample
19477(@value{GDBP}) set var g=4
19478@end smallexample
19479
19480@value{GDBN} allows more implicit conversions in assignments than C; you can
19481freely store an integer value into a pointer variable or vice versa,
19482and you can convert any structure to any other structure that is the
19483same length or shorter.
19484@comment FIXME: how do structs align/pad in these conversions?
19485@comment        /doc@cygnus.com 18dec1990
19486
19487To store values into arbitrary places in memory, use the @samp{@{@dots{}@}}
19488construct to generate a value of specified type at a specified address
19489(@pxref{Expressions, ,Expressions}).  For example, @code{@{int@}0x83040} refers
19490to memory location @code{0x83040} as an integer (which implies a certain size
19491and representation in memory), and
19492
19493@smallexample
19494set @{int@}0x83040 = 4
19495@end smallexample
19496
19497@noindent
19498stores the value 4 into that memory location.
19499
19500@node Jumping
19501@section Continuing at a Different Address
19502
19503Ordinarily, when you continue your program, you do so at the place where
19504it stopped, with the @code{continue} command.  You can instead continue at
19505an address of your own choosing, with the following commands:
19506
19507@table @code
19508@kindex jump
19509@kindex j @r{(@code{jump})}
19510@item jump @var{location}
19511@itemx j @var{location}
19512Resume execution at @var{location}.  Execution stops again immediately
19513if there is a breakpoint there.  @xref{Specify Location}, for a description
19514of the different forms of @var{location}.  It is common
19515practice to use the @code{tbreak} command in conjunction with
19516@code{jump}.  @xref{Set Breaks, ,Setting Breakpoints}.
19517
19518The @code{jump} command does not change the current stack frame, or
19519the stack pointer, or the contents of any memory location or any
19520register other than the program counter.  If @var{location} is in
19521a different function from the one currently executing, the results may
19522be bizarre if the two functions expect different patterns of arguments or
19523of local variables.  For this reason, the @code{jump} command requests
19524confirmation if the specified line is not in the function currently
19525executing.  However, even bizarre results are predictable if you are
19526well acquainted with the machine-language code of your program.
19527@end table
19528
19529On many systems, you can get much the same effect as the @code{jump}
19530command by storing a new value into the register @code{$pc}.  The
19531difference is that this does not start your program running; it only
19532changes the address of where it @emph{will} run when you continue.  For
19533example,
19534
19535@smallexample
19536set $pc = 0x485
19537@end smallexample
19538
19539@noindent
19540makes the next @code{continue} command or stepping command execute at
19541address @code{0x485}, rather than at the address where your program stopped.
19542@xref{Continuing and Stepping, ,Continuing and Stepping}.
19543
19544The most common occasion to use the @code{jump} command is to back
19545up---perhaps with more breakpoints set---over a portion of a program
19546that has already executed, in order to examine its execution in more
19547detail.
19548
19549@c @group
19550@node Signaling
19551@section Giving your Program a Signal
19552@cindex deliver a signal to a program
19553
19554@table @code
19555@kindex signal
19556@item signal @var{signal}
19557Resume execution where your program is stopped, but immediately give it the
19558signal @var{signal}.  The @var{signal} can be the name or the number of a
19559signal.  For example, on many systems @code{signal 2} and @code{signal
19560SIGINT} are both ways of sending an interrupt signal.
19561
19562Alternatively, if @var{signal} is zero, continue execution without
19563giving a signal.  This is useful when your program stopped on account of
19564a signal and would ordinarily see the signal when resumed with the
19565@code{continue} command; @samp{signal 0} causes it to resume without a
19566signal.
19567
19568@emph{Note:} When resuming a multi-threaded program, @var{signal} is
19569delivered to the currently selected thread, not the thread that last
19570reported a stop.  This includes the situation where a thread was
19571stopped due to a signal.  So if you want to continue execution
19572suppressing the signal that stopped a thread, you should select that
19573same thread before issuing the @samp{signal 0} command.  If you issue
19574the @samp{signal 0} command with another thread as the selected one,
19575@value{GDBN} detects that and asks for confirmation.
19576
19577Invoking the @code{signal} command is not the same as invoking the
19578@code{kill} utility from the shell.  Sending a signal with @code{kill}
19579causes @value{GDBN} to decide what to do with the signal depending on
19580the signal handling tables (@pxref{Signals}).  The @code{signal} command
19581passes the signal directly to your program.
19582
19583@code{signal} does not repeat when you press @key{RET} a second time
19584after executing the command.
19585
19586@kindex queue-signal
19587@item queue-signal @var{signal}
19588Queue @var{signal} to be delivered immediately to the current thread
19589when execution of the thread resumes.  The @var{signal} can be the name or
19590the number of a signal.  For example, on many systems @code{signal 2} and
19591@code{signal SIGINT} are both ways of sending an interrupt signal.
19592The handling of the signal must be set to pass the signal to the program,
19593otherwise @value{GDBN} will report an error.
19594You can control the handling of signals from @value{GDBN} with the
19595@code{handle} command (@pxref{Signals}).
19596
19597Alternatively, if @var{signal} is zero, any currently queued signal
19598for the current thread is discarded and when execution resumes no signal
19599will be delivered.  This is useful when your program stopped on account
19600of a signal and would ordinarily see the signal when resumed with the
19601@code{continue} command.
19602
19603This command differs from the @code{signal} command in that the signal
19604is just queued, execution is not resumed.  And @code{queue-signal} cannot
19605be used to pass a signal whose handling state has been set to @code{nopass}
19606(@pxref{Signals}).
19607@end table
19608@c @end group
19609
19610@xref{stepping into signal handlers}, for information on how stepping
19611commands behave when the thread has a signal queued.
19612
19613@node Returning
19614@section Returning from a Function
19615
19616@table @code
19617@cindex returning from a function
19618@kindex return
19619@item return
19620@itemx return @var{expression}
19621You can cancel execution of a function call with the @code{return}
19622command.  If you give an
19623@var{expression} argument, its value is used as the function's return
19624value.
19625@end table
19626
19627When you use @code{return}, @value{GDBN} discards the selected stack frame
19628(and all frames within it).  You can think of this as making the
19629discarded frame return prematurely.  If you wish to specify a value to
19630be returned, give that value as the argument to @code{return}.
19631
19632This pops the selected stack frame (@pxref{Selection, ,Selecting a
19633Frame}), and any other frames inside of it, leaving its caller as the
19634innermost remaining frame.  That frame becomes selected.  The
19635specified value is stored in the registers used for returning values
19636of functions.
19637
19638The @code{return} command does not resume execution; it leaves the
19639program stopped in the state that would exist if the function had just
19640returned.  In contrast, the @code{finish} command (@pxref{Continuing
19641and Stepping, ,Continuing and Stepping}) resumes execution until the
19642selected stack frame returns naturally.
19643
19644@value{GDBN} needs to know how the @var{expression} argument should be set for
19645the inferior.  The concrete registers assignment depends on the OS ABI and the
19646type being returned by the selected stack frame.  For example it is common for
19647OS ABI to return floating point values in FPU registers while integer values in
19648CPU registers.  Still some ABIs return even floating point values in CPU
19649registers.  Larger integer widths (such as @code{long long int}) also have
19650specific placement rules.  @value{GDBN} already knows the OS ABI from its
19651current target so it needs to find out also the type being returned to make the
19652assignment into the right register(s).
19653
19654Normally, the selected stack frame has debug info.  @value{GDBN} will always
19655use the debug info instead of the implicit type of @var{expression} when the
19656debug info is available.  For example, if you type @kbd{return -1}, and the
19657function in the current stack frame is declared to return a @code{long long
19658int}, @value{GDBN} transparently converts the implicit @code{int} value of -1
19659into a @code{long long int}:
19660
19661@smallexample
19662Breakpoint 1, func () at gdb.base/return-nodebug.c:29
1966329        return 31;
19664(@value{GDBP}) return -1
19665Make func return now? (y or n) y
19666#0  0x004004f6 in main () at gdb.base/return-nodebug.c:43
1966743        printf ("result=%lld\n", func ());
19668(@value{GDBP})
19669@end smallexample
19670
19671However, if the selected stack frame does not have a debug info, e.g., if the
19672function was compiled without debug info, @value{GDBN} has to find out the type
19673to return from user.  Specifying a different type by mistake may set the value
19674in different inferior registers than the caller code expects.  For example,
19675typing @kbd{return -1} with its implicit type @code{int} would set only a part
19676of a @code{long long int} result for a debug info less function (on 32-bit
19677architectures).  Therefore the user is required to specify the return type by
19678an appropriate cast explicitly:
19679
19680@smallexample
19681Breakpoint 2, 0x0040050b in func ()
19682(@value{GDBP}) return -1
19683Return value type not available for selected stack frame.
19684Please use an explicit cast of the value to return.
19685(@value{GDBP}) return (long long int) -1
19686Make selected stack frame return now? (y or n) y
19687#0  0x00400526 in main ()
19688(@value{GDBP})
19689@end smallexample
19690
19691@node Calling
19692@section Calling Program Functions
19693
19694@table @code
19695@cindex calling functions
19696@cindex inferior functions, calling
19697@item print @var{expr}
19698Evaluate the expression @var{expr} and display the resulting value.
19699The expression may include calls to functions in the program being
19700debugged.
19701
19702@kindex call
19703@item call @var{expr}
19704Evaluate the expression @var{expr} without displaying @code{void}
19705returned values.
19706
19707You can use this variant of the @code{print} command if you want to
19708execute a function from your program that does not return anything
19709(a.k.a.@: @dfn{a void function}), but without cluttering the output
19710with @code{void} returned values that @value{GDBN} will otherwise
19711print.  If the result is not void, it is printed and saved in the
19712value history.
19713@end table
19714
19715It is possible for the function you call via the @code{print} or
19716@code{call} command to generate a signal (e.g., if there's a bug in
19717the function, or if you passed it incorrect arguments).  What happens
19718in that case is controlled by the @code{set unwindonsignal} command.
19719
19720Similarly, with a C@t{++} program it is possible for the function you
19721call via the @code{print} or @code{call} command to generate an
19722exception that is not handled due to the constraints of the dummy
19723frame.  In this case, any exception that is raised in the frame, but has
19724an out-of-frame exception handler will not be found.  GDB builds a
19725dummy-frame for the inferior function call, and the unwinder cannot
19726seek for exception handlers outside of this dummy-frame.  What happens
19727in that case is controlled by the
19728@code{set unwind-on-terminating-exception} command.
19729
19730@table @code
19731@item set unwindonsignal
19732@kindex set unwindonsignal
19733@cindex unwind stack in called functions
19734@cindex call dummy stack unwinding
19735Set unwinding of the stack if a signal is received while in a function
19736that @value{GDBN} called in the program being debugged.  If set to on,
19737@value{GDBN} unwinds the stack it created for the call and restores
19738the context to what it was before the call.  If set to off (the
19739default), @value{GDBN} stops in the frame where the signal was
19740received.
19741
19742@item show unwindonsignal
19743@kindex show unwindonsignal
19744Show the current setting of stack unwinding in the functions called by
19745@value{GDBN}.
19746
19747@item set unwind-on-terminating-exception
19748@kindex set unwind-on-terminating-exception
19749@cindex unwind stack in called functions with unhandled exceptions
19750@cindex call dummy stack unwinding on unhandled exception.
19751Set unwinding of the stack if a C@t{++} exception is raised, but left
19752unhandled while in a function that @value{GDBN} called in the program being
19753debugged.  If set to on (the default), @value{GDBN} unwinds the stack
19754it created for the call and restores the context to what it was before
19755the call.  If set to off, @value{GDBN} the exception is delivered to
19756the default C@t{++} exception handler and the inferior terminated.
19757
19758@item show unwind-on-terminating-exception
19759@kindex show unwind-on-terminating-exception
19760Show the current setting of stack unwinding in the functions called by
19761@value{GDBN}.
19762
19763@item set may-call-functions
19764@kindex set may-call-functions
19765@cindex disabling calling functions in the program
19766@cindex calling functions in the program, disabling
19767Set permission to call functions in the program.
19768This controls whether @value{GDBN} will attempt to call functions in
19769the program, such as with expressions in the @code{print} command.  It
19770defaults to @code{on}.
19771
19772To call a function in the program, @value{GDBN} has to temporarily
19773modify the state of the inferior.  This has potentially undesired side
19774effects.  Also, having @value{GDBN} call nested functions is likely to
19775be erroneous and may even crash the program being debugged.  You can
19776avoid such hazards by forbidding @value{GDBN} from calling functions
19777in the program being debugged.  If calling functions in the program
19778is forbidden, GDB will throw an error when a command (such as printing
19779an expression) starts a function call in the program.
19780
19781@item show may-call-functions
19782@kindex show may-call-functions
19783Show permission to call functions in the program.
19784
19785@end table
19786
19787@subsection Calling functions with no debug info
19788
19789@cindex no debug info functions
19790Sometimes, a function you wish to call is missing debug information.
19791In such case, @value{GDBN} does not know the type of the function,
19792including the types of the function's parameters.  To avoid calling
19793the inferior function incorrectly, which could result in the called
19794function functioning erroneously and even crash, @value{GDBN} refuses
19795to call the function unless you tell it the type of the function.
19796
19797For prototyped (i.e.@: ANSI/ISO style) functions, there are two ways
19798to do that.  The simplest is to cast the call to the function's
19799declared return type.  For example:
19800
19801@smallexample
19802(@value{GDBP}) p getenv ("PATH")
19803'getenv' has unknown return type; cast the call to its declared return type
19804(@value{GDBP}) p (char *) getenv ("PATH")
19805$1 = 0x7fffffffe7ba "/usr/local/bin:/"...
19806@end smallexample
19807
19808Casting the return type of a no-debug function is equivalent to
19809casting the function to a pointer to a prototyped function that has a
19810prototype that matches the types of the passed-in arguments, and
19811calling that.  I.e., the call above is equivalent to:
19812
19813@smallexample
19814(@value{GDBP}) p ((char * (*) (const char *)) getenv) ("PATH")
19815@end smallexample
19816
19817@noindent
19818and given this prototyped C or C++ function with float parameters:
19819
19820@smallexample
19821float multiply (float v1, float v2) @{ return v1 * v2; @}
19822@end smallexample
19823
19824@noindent
19825these calls are equivalent:
19826
19827@smallexample
19828(@value{GDBP}) p (float) multiply (2.0f, 3.0f)
19829(@value{GDBP}) p ((float (*) (float, float)) multiply) (2.0f, 3.0f)
19830@end smallexample
19831
19832If the function you wish to call is declared as unprototyped (i.e.@:
19833old K&R style), you must use the cast-to-function-pointer syntax, so
19834that @value{GDBN} knows that it needs to apply default argument
19835promotions (promote float arguments to double).  @xref{ABI, float
19836promotion}.  For example, given this unprototyped C function with
19837float parameters, and no debug info:
19838
19839@smallexample
19840float
19841multiply_noproto (v1, v2)
19842  float v1, v2;
19843@{
19844  return v1 * v2;
19845@}
19846@end smallexample
19847
19848@noindent
19849you call it like this:
19850
19851@smallexample
19852  (@value{GDBP}) p ((float (*) ()) multiply_noproto) (2.0f, 3.0f)
19853@end smallexample
19854
19855@node Patching
19856@section Patching Programs
19857
19858@cindex patching binaries
19859@cindex writing into executables
19860@cindex writing into corefiles
19861
19862By default, @value{GDBN} opens the file containing your program's
19863executable code (or the corefile) read-only.  This prevents accidental
19864alterations to machine code; but it also prevents you from intentionally
19865patching your program's binary.
19866
19867If you'd like to be able to patch the binary, you can specify that
19868explicitly with the @code{set write} command.  For example, you might
19869want to turn on internal debugging flags, or even to make emergency
19870repairs.
19871
19872@table @code
19873@kindex set write
19874@item set write on
19875@itemx set write off
19876If you specify @samp{set write on}, @value{GDBN} opens executable and
19877core files for both reading and writing; if you specify @kbd{set write
19878off} (the default), @value{GDBN} opens them read-only.
19879
19880If you have already loaded a file, you must load it again (using the
19881@code{exec-file} or @code{core-file} command) after changing @code{set
19882write}, for your new setting to take effect.
19883
19884@item show write
19885@kindex show write
19886Display whether executable files and core files are opened for writing
19887as well as reading.
19888@end table
19889
19890@node Compiling and Injecting Code
19891@section Compiling and injecting code in @value{GDBN}
19892@cindex injecting code
19893@cindex writing into executables
19894@cindex compiling code
19895
19896@value{GDBN} supports on-demand compilation and code injection into
19897programs running under @value{GDBN}.  GCC 5.0 or higher built with
19898@file{libcc1.so} must be installed for this functionality to be enabled.
19899This functionality is implemented with the following commands.
19900
19901@table @code
19902@kindex compile code
19903@item compile code @var{source-code}
19904@itemx compile code -raw @var{--} @var{source-code}
19905Compile @var{source-code} with the compiler language found as the current
19906language in @value{GDBN} (@pxref{Languages}).  If compilation and
19907injection is not supported with the current language specified in
19908@value{GDBN}, or the compiler does not support this feature, an error
19909message will be printed.  If @var{source-code} compiles and links
19910successfully, @value{GDBN} will load the object-code emitted,
19911and execute it within the context of the currently selected inferior.
19912It is important to note that the compiled code is executed immediately.
19913After execution, the compiled code is removed from @value{GDBN} and any
19914new types or variables you have defined will be deleted.
19915
19916The command allows you to specify @var{source-code} in two ways.
19917The simplest method is to provide a single line of code to the command.
19918E.g.:
19919
19920@smallexample
19921compile code printf ("hello world\n");
19922@end smallexample
19923
19924If you specify options on the command line as well as source code, they
19925may conflict.  The @samp{--} delimiter can be used to separate options
19926from actual source code.  E.g.:
19927
19928@smallexample
19929compile code -r -- printf ("hello world\n");
19930@end smallexample
19931
19932Alternatively you can enter source code as multiple lines of text.  To
19933enter this mode, invoke the @samp{compile code} command without any text
19934following the command.  This will start the multiple-line editor and
19935allow you to type as many lines of source code as required.  When you
19936have completed typing, enter @samp{end} on its own line to exit the
19937editor.
19938
19939@smallexample
19940compile code
19941>printf ("hello\n");
19942>printf ("world\n");
19943>end
19944@end smallexample
19945
19946Specifying @samp{-raw}, prohibits @value{GDBN} from wrapping the
19947provided @var{source-code} in a callable scope.  In this case, you must
19948specify the entry point of the code by defining a function named
19949@code{_gdb_expr_}.  The @samp{-raw} code cannot access variables of the
19950inferior.  Using @samp{-raw} option may be needed for example when
19951@var{source-code} requires @samp{#include} lines which may conflict with
19952inferior symbols otherwise.
19953
19954@kindex compile file
19955@item compile file @var{filename}
19956@itemx compile file -raw @var{filename}
19957Like @code{compile code}, but take the source code from @var{filename}.
19958
19959@smallexample
19960compile file /home/user/example.c
19961@end smallexample
19962@end table
19963
19964@table @code
19965@item compile print [[@var{options}] --] @var{expr}
19966@itemx compile print [[@var{options}] --] /@var{f} @var{expr}
19967Compile and execute @var{expr} with the compiler language found as the
19968current language in @value{GDBN} (@pxref{Languages}).  By default the
19969value of @var{expr} is printed in a format appropriate to its data type;
19970you can choose a different format by specifying @samp{/@var{f}}, where
19971@var{f} is a letter specifying the format; see @ref{Output Formats,,Output
19972Formats}.  The @code{compile print} command accepts the same options
19973as the @code{print} command; see @ref{print options}.
19974
19975@item compile print [[@var{options}] --]
19976@itemx compile print [[@var{options}] --] /@var{f}
19977@cindex reprint the last value
19978Alternatively you can enter the expression (source code producing it) as
19979multiple lines of text.  To enter this mode, invoke the @samp{compile print}
19980command without any text following the command.  This will start the
19981multiple-line editor.
19982@end table
19983
19984@noindent
19985The process of compiling and injecting the code can be inspected using:
19986
19987@table @code
19988@anchor{set debug compile}
19989@item set debug compile
19990@cindex compile command debugging info
19991Turns on or off display of @value{GDBN} process of compiling and
19992injecting the code.  The default is off.
19993
19994@item show debug compile
19995Displays the current state of displaying @value{GDBN} process of
19996compiling and injecting the code.
19997
19998@anchor{set debug compile-cplus-types}
19999@item set debug compile-cplus-types
20000@cindex compile C@t{++} type conversion
20001Turns on or off the display of C@t{++} type conversion debugging information.
20002The default is off.
20003
20004@item show debug compile-cplus-types
20005Displays the current state of displaying debugging information for
20006C@t{++} type conversion.
20007@end table
20008
20009@subsection Compilation options for the @code{compile} command
20010
20011@value{GDBN} needs to specify the right compilation options for the code
20012to be injected, in part to make its ABI compatible with the inferior
20013and in part to make the injected code compatible with @value{GDBN}'s
20014injecting process.
20015
20016@noindent
20017The options used, in increasing precedence:
20018
20019@table @asis
20020@item target architecture and OS options (@code{gdbarch})
20021These options depend on target processor type and target operating
20022system, usually they specify at least 32-bit (@code{-m32}) or 64-bit
20023(@code{-m64}) compilation option.
20024
20025@item compilation options recorded in the target
20026@value{NGCC} (since version 4.7) stores the options used for compilation
20027into @code{DW_AT_producer} part of DWARF debugging information according
20028to the @value{NGCC} option @code{-grecord-gcc-switches}.  One has to
20029explicitly specify @code{-g} during inferior compilation otherwise
20030@value{NGCC} produces no DWARF.  This feature is only relevant for
20031platforms where @code{-g} produces DWARF by default, otherwise one may
20032try to enforce DWARF by using @code{-gdwarf-4}.
20033
20034@item compilation options set by @code{set compile-args}
20035@end table
20036
20037@noindent
20038You can override compilation options using the following command:
20039
20040@table @code
20041@item set compile-args
20042@cindex compile command options override
20043Set compilation options used for compiling and injecting code with the
20044@code{compile} commands.  These options override any conflicting ones
20045from the target architecture and/or options stored during inferior
20046compilation.
20047
20048@item show compile-args
20049Displays the current state of compilation options override.
20050This does not show all the options actually used during compilation,
20051use @ref{set debug compile} for that.
20052@end table
20053
20054@subsection Caveats when using the @code{compile} command
20055
20056There are a few caveats to keep in mind when using the @code{compile}
20057command.  As the caveats are different per language, the table below
20058highlights specific issues on a per language basis.
20059
20060@table @asis
20061@item C code examples and caveats
20062When the language in @value{GDBN} is set to @samp{C}, the compiler will
20063attempt to compile the source code with a @samp{C} compiler.  The source
20064code provided to the @code{compile} command will have much the same
20065access to variables and types as it normally would if it were part of
20066the program currently being debugged in @value{GDBN}.
20067
20068Below is a sample program that forms the basis of the examples that
20069follow.  This program has been compiled and loaded into @value{GDBN},
20070much like any other normal debugging session.
20071
20072@smallexample
20073void function1 (void)
20074@{
20075   int i = 42;
20076   printf ("function 1\n");
20077@}
20078
20079void function2 (void)
20080@{
20081   int j = 12;
20082   function1 ();
20083@}
20084
20085int main(void)
20086@{
20087   int k = 6;
20088   int *p;
20089   function2 ();
20090   return 0;
20091@}
20092@end smallexample
20093
20094For the purposes of the examples in this section, the program above has
20095been compiled, loaded into @value{GDBN}, stopped at the function
20096@code{main}, and @value{GDBN} is awaiting input from the user.
20097
20098To access variables and types for any program in @value{GDBN}, the
20099program must be compiled and packaged with debug information.  The
20100@code{compile} command is not an exception to this rule.  Without debug
20101information, you can still use the @code{compile} command, but you will
20102be very limited in what variables and types you can access.
20103
20104So with that in mind, the example above has been compiled with debug
20105information enabled.  The @code{compile} command will have access to
20106all variables and types (except those that may have been optimized
20107out).  Currently, as @value{GDBN} has stopped the program in the
20108@code{main} function, the @code{compile} command would have access to
20109the variable @code{k}.  You could invoke the @code{compile} command
20110and type some source code to set the value of @code{k}.  You can also
20111read it, or do anything with that variable you would normally do in
20112@code{C}.  Be aware that changes to inferior variables in the
20113@code{compile} command are persistent.  In the following example:
20114
20115@smallexample
20116compile code k = 3;
20117@end smallexample
20118
20119@noindent
20120the variable @code{k} is now 3.  It will retain that value until
20121something else in the example program changes it, or another
20122@code{compile} command changes it.
20123
20124Normal scope and access rules apply to source code compiled and
20125injected by the @code{compile} command.  In the example, the variables
20126@code{j} and @code{k} are not accessible yet, because the program is
20127currently stopped in the @code{main} function, where these variables
20128are not in scope.  Therefore, the following command
20129
20130@smallexample
20131compile code j = 3;
20132@end smallexample
20133
20134@noindent
20135will result in a compilation error message.
20136
20137Once the program is continued, execution will bring these variables in
20138scope, and they will become accessible; then the code you specify via
20139the @code{compile} command will be able to access them.
20140
20141You can create variables and types with the @code{compile} command as
20142part of your source code.  Variables and types that are created as part
20143of the @code{compile} command are not visible to the rest of the program for
20144the duration of its run.  This example is valid:
20145
20146@smallexample
20147compile code int ff = 5; printf ("ff is %d\n", ff);
20148@end smallexample
20149
20150However, if you were to type the following into @value{GDBN} after that
20151command has completed:
20152
20153@smallexample
20154compile code printf ("ff is %d\n'', ff);
20155@end smallexample
20156
20157@noindent
20158a compiler error would be raised as the variable @code{ff} no longer
20159exists.  Object code generated and injected by the @code{compile}
20160command is removed when its execution ends.  Caution is advised
20161when assigning to program variables values of variables created by the
20162code submitted to the @code{compile} command.  This example is valid:
20163
20164@smallexample
20165compile code int ff = 5; k = ff;
20166@end smallexample
20167
20168The value of the variable @code{ff} is assigned to @code{k}.  The variable
20169@code{k} does not require the existence of @code{ff} to maintain the value
20170it has been assigned.  However, pointers require particular care in
20171assignment.  If the source code compiled with the @code{compile} command
20172changed the address of a pointer in the example program, perhaps to a
20173variable created in the @code{compile} command, that pointer would point
20174to an invalid location when the command exits.  The following example
20175would likely cause issues with your debugged program:
20176
20177@smallexample
20178compile code int ff = 5; p = &ff;
20179@end smallexample
20180
20181In this example, @code{p} would point to @code{ff} when the
20182@code{compile} command is executing the source code provided to it.
20183However, as variables in the (example) program persist with their
20184assigned values, the variable @code{p} would point to an invalid
20185location when the command exists.  A general rule should be followed
20186in that you should either assign @code{NULL} to any assigned pointers,
20187or restore a valid location to the pointer before the command exits.
20188
20189Similar caution must be exercised with any structs, unions, and typedefs
20190defined in @code{compile} command.  Types defined in the @code{compile}
20191command will no longer be available in the next @code{compile} command.
20192Therefore, if you cast a variable to a type defined in the
20193@code{compile} command, care must be taken to ensure that any future
20194need to resolve the type can be achieved.
20195
20196@smallexample
20197(gdb) compile code static struct a @{ int a; @} v = @{ 42 @}; argv = &v;
20198(gdb) compile code printf ("%d\n", ((struct a *) argv)->a);
20199gdb command line:1:36: error: dereferencing pointer to incomplete type ‘struct a’
20200Compilation failed.
20201(gdb) compile code struct a @{ int a; @}; printf ("%d\n", ((struct a *) argv)->a);
2020242
20203@end smallexample
20204
20205Variables that have been optimized away by the compiler are not
20206accessible to the code submitted to the @code{compile} command.
20207Access to those variables will generate a compiler error which @value{GDBN}
20208will print to the console.
20209@end table
20210
20211@subsection Compiler search for the @code{compile} command
20212
20213@value{GDBN} needs to find @value{NGCC} for the inferior being debugged
20214which may not be obvious for remote targets of different architecture
20215than where @value{GDBN} is running.  Environment variable @code{PATH} on
20216@value{GDBN} host is searched for @value{NGCC} binary matching the
20217target architecture and operating system.  This search can be overriden
20218by @code{set compile-gcc} @value{GDBN} command below.  @code{PATH} is
20219taken from shell that executed @value{GDBN}, it is not the value set by
20220@value{GDBN} command @code{set environment}).  @xref{Environment}.
20221
20222
20223Specifically @code{PATH} is searched for binaries matching regular expression
20224@code{@var{arch}(-[^-]*)?-@var{os}-gcc} according to the inferior target being
20225debugged.  @var{arch} is processor name --- multiarch is supported, so for
20226example both @code{i386} and @code{x86_64} targets look for pattern
20227@code{(x86_64|i.86)} and both @code{s390} and @code{s390x} targets look
20228for pattern @code{s390x?}.  @var{os} is currently supported only for
20229pattern @code{linux(-gnu)?}.
20230
20231On Posix hosts the compiler driver @value{GDBN} needs to find also
20232shared library @file{libcc1.so} from the compiler.  It is searched in
20233default shared library search path (overridable with usual environment
20234variable @code{LD_LIBRARY_PATH}), unrelated to @code{PATH} or @code{set
20235compile-gcc} settings.  Contrary to it @file{libcc1plugin.so} is found
20236according to the installation of the found compiler --- as possibly
20237specified by the @code{set compile-gcc} command.
20238
20239@table @code
20240@item set compile-gcc
20241@cindex compile command driver filename override
20242Set compilation command used for compiling and injecting code with the
20243@code{compile} commands.  If this option is not set (it is set to
20244an empty string), the search described above will occur --- that is the
20245default.
20246
20247@item show compile-gcc
20248Displays the current compile command @value{NGCC} driver filename.
20249If set, it is the main command @command{gcc}, found usually for example
20250under name @file{x86_64-linux-gnu-gcc}.
20251@end table
20252
20253@node GDB Files
20254@chapter @value{GDBN} Files
20255
20256@value{GDBN} needs to know the file name of the program to be debugged,
20257both in order to read its symbol table and in order to start your
20258program.  To debug a core dump of a previous run, you must also tell
20259@value{GDBN} the name of the core dump file.
20260
20261@menu
20262* Files::                       Commands to specify files
20263* File Caching::                Information about @value{GDBN}'s file caching
20264* Separate Debug Files::        Debugging information in separate files
20265* MiniDebugInfo::               Debugging information in a special section
20266* Index Files::                 Index files speed up GDB
20267* Symbol Errors::               Errors reading symbol files
20268* Data Files::                  GDB data files
20269@end menu
20270
20271@node Files
20272@section Commands to Specify Files
20273
20274@cindex symbol table
20275@cindex core dump file
20276
20277You may want to specify executable and core dump file names.  The usual
20278way to do this is at start-up time, using the arguments to
20279@value{GDBN}'s start-up commands (@pxref{Invocation, , Getting In and
20280Out of @value{GDBN}}).
20281
20282Occasionally it is necessary to change to a different file during a
20283@value{GDBN} session.  Or you may run @value{GDBN} and forget to
20284specify a file you want to use.  Or you are debugging a remote target
20285via @code{gdbserver} (@pxref{Server, file, Using the @code{gdbserver}
20286Program}).  In these situations the @value{GDBN} commands to specify
20287new files are useful.
20288
20289@table @code
20290@cindex executable file
20291@kindex file
20292@item file @var{filename}
20293Use @var{filename} as the program to be debugged.  It is read for its
20294symbols and for the contents of pure memory.  It is also the program
20295executed when you use the @code{run} command.  If you do not specify a
20296directory and the file is not found in the @value{GDBN} working directory,
20297@value{GDBN} uses the environment variable @code{PATH} as a list of
20298directories to search, just as the shell does when looking for a program
20299to run.  You can change the value of this variable, for both @value{GDBN}
20300and your program, using the @code{path} command.
20301
20302@cindex unlinked object files
20303@cindex patching object files
20304You can load unlinked object @file{.o} files into @value{GDBN} using
20305the @code{file} command.  You will not be able to ``run'' an object
20306file, but you can disassemble functions and inspect variables.  Also,
20307if the underlying BFD functionality supports it, you could use
20308@kbd{gdb -write} to patch object files using this technique.  Note
20309that @value{GDBN} can neither interpret nor modify relocations in this
20310case, so branches and some initialized variables will appear to go to
20311the wrong place.  But this feature is still handy from time to time.
20312
20313@item file
20314@code{file} with no argument makes @value{GDBN} discard any information it
20315has on both executable file and the symbol table.
20316
20317@kindex exec-file
20318@item exec-file @r{[} @var{filename} @r{]}
20319Specify that the program to be run (but not the symbol table) is found
20320in @var{filename}.  @value{GDBN} searches the environment variable @code{PATH}
20321if necessary to locate your program.  Omitting @var{filename} means to
20322discard information on the executable file.
20323
20324@kindex symbol-file
20325@item symbol-file @r{[} @var{filename} @r{[} -o @var{offset} @r{]]}
20326Read symbol table information from file @var{filename}.  @code{PATH} is
20327searched when necessary.  Use the @code{file} command to get both symbol
20328table and program to run from the same file.
20329
20330If an optional @var{offset} is specified, it is added to the start
20331address of each section in the symbol file.  This is useful if the
20332program is relocated at runtime, such as the Linux kernel with kASLR
20333enabled.
20334
20335@code{symbol-file} with no argument clears out @value{GDBN} information on your
20336program's symbol table.
20337
20338The @code{symbol-file} command causes @value{GDBN} to forget the contents of
20339some breakpoints and auto-display expressions.  This is because they may
20340contain pointers to the internal data recording symbols and data types,
20341which are part of the old symbol table data being discarded inside
20342@value{GDBN}.
20343
20344@code{symbol-file} does not repeat if you press @key{RET} again after
20345executing it once.
20346
20347When @value{GDBN} is configured for a particular environment, it
20348understands debugging information in whatever format is the standard
20349generated for that environment; you may use either a @sc{gnu} compiler, or
20350other compilers that adhere to the local conventions.
20351Best results are usually obtained from @sc{gnu} compilers; for example,
20352using @code{@value{NGCC}} you can generate debugging information for
20353optimized code.
20354
20355For most kinds of object files, with the exception of old SVR3 systems
20356using COFF, the @code{symbol-file} command does not normally read the
20357symbol table in full right away.  Instead, it scans the symbol table
20358quickly to find which source files and which symbols are present.  The
20359details are read later, one source file at a time, as they are needed.
20360
20361The purpose of this two-stage reading strategy is to make @value{GDBN}
20362start up faster.  For the most part, it is invisible except for
20363occasional pauses while the symbol table details for a particular source
20364file are being read.  (The @code{set verbose} command can turn these
20365pauses into messages if desired.  @xref{Messages/Warnings, ,Optional
20366Warnings and Messages}.)
20367
20368We have not implemented the two-stage strategy for COFF yet.  When the
20369symbol table is stored in COFF format, @code{symbol-file} reads the
20370symbol table data in full right away.  Note that ``stabs-in-COFF''
20371still does the two-stage strategy, since the debug info is actually
20372in stabs format.
20373
20374@kindex readnow
20375@cindex reading symbols immediately
20376@cindex symbols, reading immediately
20377@item symbol-file @r{[} -readnow @r{]} @var{filename}
20378@itemx file @r{[} -readnow @r{]} @var{filename}
20379You can override the @value{GDBN} two-stage strategy for reading symbol
20380tables by using the @samp{-readnow} option with any of the commands that
20381load symbol table information, if you want to be sure @value{GDBN} has the
20382entire symbol table available.
20383
20384@cindex @code{-readnever}, option for symbol-file command
20385@cindex never read symbols
20386@cindex symbols, never read
20387@item symbol-file @r{[} -readnever @r{]} @var{filename}
20388@itemx file @r{[} -readnever @r{]} @var{filename}
20389You can instruct @value{GDBN} to never read the symbolic information
20390contained in @var{filename} by using the @samp{-readnever} option.
20391@xref{--readnever}.
20392
20393@c FIXME: for now no mention of directories, since this seems to be in
20394@c flux.  13mar1992 status is that in theory GDB would look either in
20395@c current dir or in same dir as myprog; but issues like competing
20396@c GDB's, or clutter in system dirs, mean that in practice right now
20397@c only current dir is used.  FFish says maybe a special GDB hierarchy
20398@c (eg rooted in val of env var GDBSYMS) could exist for mappable symbol
20399@c files.
20400
20401@kindex core-file
20402@item core-file @r{[}@var{filename}@r{]}
20403@itemx core
20404Specify the whereabouts of a core dump file to be used as the ``contents
20405of memory''.  Traditionally, core files contain only some parts of the
20406address space of the process that generated them; @value{GDBN} can access the
20407executable file itself for other parts.
20408
20409@code{core-file} with no argument specifies that no core file is
20410to be used.
20411
20412Note that the core file is ignored when your program is actually running
20413under @value{GDBN}.  So, if you have been running your program and you
20414wish to debug a core file instead, you must kill the subprocess in which
20415the program is running.  To do this, use the @code{kill} command
20416(@pxref{Kill Process, ,Killing the Child Process}).
20417
20418@kindex add-symbol-file
20419@cindex dynamic linking
20420@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{]}
20421The @code{add-symbol-file} command reads additional symbol table
20422information from the file @var{filename}.  You would use this command
20423when @var{filename} has been dynamically loaded (by some other means)
20424into the program that is running.  The @var{textaddress} parameter gives
20425the memory address at which the file's text section has been loaded.
20426You can additionally specify the base address of other sections using
20427an arbitrary number of @samp{-s @var{section} @var{address}} pairs.
20428If a section is omitted, @value{GDBN} will use its default addresses
20429as found in @var{filename}.  Any @var{address} or @var{textaddress}
20430can be given as an expression.
20431
20432If an optional @var{offset} is specified, it is added to the start
20433address of each section, except those for which the address was
20434specified explicitly.
20435
20436The symbol table of the file @var{filename} is added to the symbol table
20437originally read with the @code{symbol-file} command.  You can use the
20438@code{add-symbol-file} command any number of times; the new symbol data
20439thus read is kept in addition to the old.
20440
20441Changes can be reverted using the command @code{remove-symbol-file}.
20442
20443@cindex relocatable object files, reading symbols from
20444@cindex object files, relocatable, reading symbols from
20445@cindex reading symbols from relocatable object files
20446@cindex symbols, reading from relocatable object files
20447@cindex @file{.o} files, reading symbols from
20448Although @var{filename} is typically a shared library file, an
20449executable file, or some other object file which has been fully
20450relocated for loading into a process, you can also load symbolic
20451information from relocatable @file{.o} files, as long as:
20452
20453@itemize @bullet
20454@item
20455the file's symbolic information refers only to linker symbols defined in
20456that file, not to symbols defined by other object files,
20457@item
20458every section the file's symbolic information refers to has actually
20459been loaded into the inferior, as it appears in the file, and
20460@item
20461you can determine the address at which every section was loaded, and
20462provide these to the @code{add-symbol-file} command.
20463@end itemize
20464
20465@noindent
20466Some embedded operating systems, like Sun Chorus and VxWorks, can load
20467relocatable files into an already running program; such systems
20468typically make the requirements above easy to meet.  However, it's
20469important to recognize that many native systems use complex link
20470procedures (@code{.linkonce} section factoring and C@t{++} constructor table
20471assembly, for example) that make the requirements difficult to meet.  In
20472general, one cannot assume that using @code{add-symbol-file} to read a
20473relocatable object file's symbolic information will have the same effect
20474as linking the relocatable object file into the program in the normal
20475way.
20476
20477@code{add-symbol-file} does not repeat if you press @key{RET} after using it.
20478
20479@kindex remove-symbol-file
20480@item remove-symbol-file @var{filename}
20481@item remove-symbol-file -a @var{address}
20482Remove a symbol file added via the @code{add-symbol-file} command.  The
20483file to remove can be identified by its @var{filename} or by an @var{address}
20484that lies within the boundaries of this symbol file in memory.  Example:
20485
20486@smallexample
20487(gdb) add-symbol-file /home/user/gdb/mylib.so 0x7ffff7ff9480
20488add symbol table from file "/home/user/gdb/mylib.so" at
20489    .text_addr = 0x7ffff7ff9480
20490(y or n) y
20491Reading symbols from /home/user/gdb/mylib.so...
20492(gdb) remove-symbol-file -a 0x7ffff7ff9480
20493Remove symbol table from file "/home/user/gdb/mylib.so"? (y or n) y
20494(gdb)
20495@end smallexample
20496
20497
20498@code{remove-symbol-file} does not repeat if you press @key{RET} after using it.
20499
20500@kindex add-symbol-file-from-memory
20501@cindex @code{syscall DSO}
20502@cindex load symbols from memory
20503@item add-symbol-file-from-memory @var{address}
20504Load symbols from the given @var{address} in a dynamically loaded
20505object file whose image is mapped directly into the inferior's memory.
20506For example, the Linux kernel maps a @code{syscall DSO} into each
20507process's address space; this DSO provides kernel-specific code for
20508some system calls.  The argument can be any expression whose
20509evaluation yields the address of the file's shared object file header.
20510For this command to work, you must have used @code{symbol-file} or
20511@code{exec-file} commands in advance.
20512
20513@kindex section
20514@item section @var{section} @var{addr}
20515The @code{section} command changes the base address of the named
20516@var{section} of the exec file to @var{addr}.  This can be used if the
20517exec file does not contain section addresses, (such as in the
20518@code{a.out} format), or when the addresses specified in the file
20519itself are wrong.  Each section must be changed separately.  The
20520@code{info files} command, described below, lists all the sections and
20521their addresses.
20522
20523@kindex info files
20524@kindex info target
20525@item info files
20526@itemx info target
20527@code{info files} and @code{info target} are synonymous; both print the
20528current target (@pxref{Targets, ,Specifying a Debugging Target}),
20529including the names of the executable and core dump files currently in
20530use by @value{GDBN}, and the files from which symbols were loaded.  The
20531command @code{help target} lists all possible targets rather than
20532current ones.
20533
20534@kindex maint info sections
20535@item maint info sections
20536Another command that can give you extra information about program sections
20537is @code{maint info sections}.  In addition to the section information
20538displayed by @code{info files}, this command displays the flags and file
20539offset of each section in the executable and core dump files.  In addition,
20540@code{maint info sections} provides the following command options (which
20541may be arbitrarily combined):
20542
20543@table @code
20544@item ALLOBJ
20545Display sections for all loaded object files, including shared libraries.
20546@item @var{sections}
20547Display info only for named @var{sections}.
20548@item @var{section-flags}
20549Display info only for sections for which @var{section-flags} are true.
20550The section flags that @value{GDBN} currently knows about are:
20551@table @code
20552@item ALLOC
20553Section will have space allocated in the process when loaded.
20554Set for all sections except those containing debug information.
20555@item LOAD
20556Section will be loaded from the file into the child process memory.
20557Set for pre-initialized code and data, clear for @code{.bss} sections.
20558@item RELOC
20559Section needs to be relocated before loading.
20560@item READONLY
20561Section cannot be modified by the child process.
20562@item CODE
20563Section contains executable code only.
20564@item DATA
20565Section contains data only (no executable code).
20566@item ROM
20567Section will reside in ROM.
20568@item CONSTRUCTOR
20569Section contains data for constructor/destructor lists.
20570@item HAS_CONTENTS
20571Section is not empty.
20572@item NEVER_LOAD
20573An instruction to the linker to not output the section.
20574@item COFF_SHARED_LIBRARY
20575A notification to the linker that the section contains
20576COFF shared library information.
20577@item IS_COMMON
20578Section contains common symbols.
20579@end table
20580@end table
20581@kindex set trust-readonly-sections
20582@cindex read-only sections
20583@item set trust-readonly-sections on
20584Tell @value{GDBN} that readonly sections in your object file
20585really are read-only (i.e.@: that their contents will not change).
20586In that case, @value{GDBN} can fetch values from these sections
20587out of the object file, rather than from the target program.
20588For some targets (notably embedded ones), this can be a significant
20589enhancement to debugging performance.
20590
20591The default is off.
20592
20593@item set trust-readonly-sections off
20594Tell @value{GDBN} not to trust readonly sections.  This means that
20595the contents of the section might change while the program is running,
20596and must therefore be fetched from the target when needed.
20597
20598@item show trust-readonly-sections
20599Show the current setting of trusting readonly sections.
20600@end table
20601
20602All file-specifying commands allow both absolute and relative file names
20603as arguments.  @value{GDBN} always converts the file name to an absolute file
20604name and remembers it that way.
20605
20606@cindex shared libraries
20607@anchor{Shared Libraries}
20608@value{GDBN} supports @sc{gnu}/Linux, MS-Windows, SunOS,
20609Darwin/Mach-O, SVr4, IBM RS/6000 AIX, QNX Neutrino, FDPIC (FR-V), and
20610DSBT (TIC6X) shared libraries.
20611
20612On MS-Windows @value{GDBN} must be linked with the Expat library to support
20613shared libraries.  @xref{Expat}.
20614
20615@value{GDBN} automatically loads symbol definitions from shared libraries
20616when you use the @code{run} command, or when you examine a core file.
20617(Before you issue the @code{run} command, @value{GDBN} does not understand
20618references to a function in a shared library, however---unless you are
20619debugging a core file).
20620
20621@c FIXME: some @value{GDBN} release may permit some refs to undef
20622@c FIXME...symbols---eg in a break cmd---assuming they are from a shared
20623@c FIXME...lib; check this from time to time when updating manual
20624
20625There are times, however, when you may wish to not automatically load
20626symbol definitions from shared libraries, such as when they are
20627particularly large or there are many of them.
20628
20629To control the automatic loading of shared library symbols, use the
20630commands:
20631
20632@table @code
20633@kindex set auto-solib-add
20634@item set auto-solib-add @var{mode}
20635If @var{mode} is @code{on}, symbols from all shared object libraries
20636will be loaded automatically when the inferior begins execution, you
20637attach to an independently started inferior, or when the dynamic linker
20638informs @value{GDBN} that a new library has been loaded.  If @var{mode}
20639is @code{off}, symbols must be loaded manually, using the
20640@code{sharedlibrary} command.  The default value is @code{on}.
20641
20642@cindex memory used for symbol tables
20643If your program uses lots of shared libraries with debug info that
20644takes large amounts of memory, you can decrease the @value{GDBN}
20645memory footprint by preventing it from automatically loading the
20646symbols from shared libraries.  To that end, type @kbd{set
20647auto-solib-add off} before running the inferior, then load each
20648library whose debug symbols you do need with @kbd{sharedlibrary
20649@var{regexp}}, where @var{regexp} is a regular expression that matches
20650the libraries whose symbols you want to be loaded.
20651
20652@kindex show auto-solib-add
20653@item show auto-solib-add
20654Display the current autoloading mode.
20655@end table
20656
20657@cindex load shared library
20658To explicitly load shared library symbols, use the @code{sharedlibrary}
20659command:
20660
20661@table @code
20662@kindex info sharedlibrary
20663@kindex info share
20664@item info share @var{regex}
20665@itemx info sharedlibrary @var{regex}
20666Print the names of the shared libraries which are currently loaded
20667that match @var{regex}.  If @var{regex} is omitted then print
20668all shared libraries that are loaded.
20669
20670@kindex info dll
20671@item info dll @var{regex}
20672This is an alias of @code{info sharedlibrary}.
20673
20674@kindex sharedlibrary
20675@kindex share
20676@item sharedlibrary @var{regex}
20677@itemx share @var{regex}
20678Load shared object library symbols for files matching a
20679Unix regular expression.
20680As with files loaded automatically, it only loads shared libraries
20681required by your program for a core file or after typing @code{run}.  If
20682@var{regex} is omitted all shared libraries required by your program are
20683loaded.
20684
20685@item nosharedlibrary
20686@kindex nosharedlibrary
20687@cindex unload symbols from shared libraries
20688Unload all shared object library symbols.  This discards all symbols
20689that have been loaded from all shared libraries.  Symbols from shared
20690libraries that were loaded by explicit user requests are not
20691discarded.
20692@end table
20693
20694Sometimes you may wish that @value{GDBN} stops and gives you control
20695when any of shared library events happen.  The best way to do this is
20696to use @code{catch load} and @code{catch unload} (@pxref{Set
20697Catchpoints}).
20698
20699@value{GDBN} also supports the @code{set stop-on-solib-events}
20700command for this.  This command exists for historical reasons.  It is
20701less useful than setting a catchpoint, because it does not allow for
20702conditions or commands as a catchpoint does.
20703
20704@table @code
20705@item set stop-on-solib-events
20706@kindex set stop-on-solib-events
20707This command controls whether @value{GDBN} should give you control
20708when the dynamic linker notifies it about some shared library event.
20709The most common event of interest is loading or unloading of a new
20710shared library.
20711
20712@item show stop-on-solib-events
20713@kindex show stop-on-solib-events
20714Show whether @value{GDBN} stops and gives you control when shared
20715library events happen.
20716@end table
20717
20718Shared libraries are also supported in many cross or remote debugging
20719configurations.  @value{GDBN} needs to have access to the target's libraries;
20720this can be accomplished either by providing copies of the libraries
20721on the host system, or by asking @value{GDBN} to automatically retrieve the
20722libraries from the target.  If copies of the target libraries are
20723provided, they need to be the same as the target libraries, although the
20724copies on the target can be stripped as long as the copies on the host are
20725not.
20726
20727@cindex where to look for shared libraries
20728For remote debugging, you need to tell @value{GDBN} where the target
20729libraries are, so that it can load the correct copies---otherwise, it
20730may try to load the host's libraries.  @value{GDBN} has two variables
20731to specify the search directories for target libraries.
20732
20733@table @code
20734@cindex prefix for executable and shared library file names
20735@cindex system root, alternate
20736@kindex set solib-absolute-prefix
20737@kindex set sysroot
20738@item set sysroot @var{path}
20739Use @var{path} as the system root for the program being debugged.  Any
20740absolute shared library paths will be prefixed with @var{path}; many
20741runtime loaders store the absolute paths to the shared library in the
20742target program's memory.  When starting processes remotely, and when
20743attaching to already-running processes (local or remote), their
20744executable filenames will be prefixed with @var{path} if reported to
20745@value{GDBN} as absolute by the operating system.  If you use
20746@code{set sysroot} to find executables and shared libraries, they need
20747to be laid out in the same way that they are on the target, with
20748e.g.@: a @file{/bin}, @file{/lib} and @file{/usr/lib} hierarchy under
20749@var{path}.
20750
20751If @var{path} starts with the sequence @file{target:} and the target
20752system is remote then @value{GDBN} will retrieve the target binaries
20753from the remote system.  This is only supported when using a remote
20754target that supports the @code{remote get} command (@pxref{File
20755Transfer,,Sending files to a remote system}).  The part of @var{path}
20756following the initial @file{target:} (if present) is used as system
20757root prefix on the remote file system.  If @var{path} starts with the
20758sequence @file{remote:} this is converted to the sequence
20759@file{target:} by @code{set sysroot}@footnote{Historically the
20760functionality to retrieve binaries from the remote system was
20761provided by prefixing @var{path} with @file{remote:}}.  If you want
20762to specify a local system root using a directory that happens to be
20763named @file{target:} or @file{remote:}, you need to use some
20764equivalent variant of the name like @file{./target:}.
20765
20766For targets with an MS-DOS based filesystem, such as MS-Windows and
20767SymbianOS, @value{GDBN} tries prefixing a few variants of the target
20768absolute file name with @var{path}.  But first, on Unix hosts,
20769@value{GDBN} converts all backslash directory separators into forward
20770slashes, because the backslash is not a directory separator on Unix:
20771
20772@smallexample
20773  c:\foo\bar.dll @result{} c:/foo/bar.dll
20774@end smallexample
20775
20776Then, @value{GDBN} attempts prefixing the target file name with
20777@var{path}, and looks for the resulting file name in the host file
20778system:
20779
20780@smallexample
20781  c:/foo/bar.dll @result{} /path/to/sysroot/c:/foo/bar.dll
20782@end smallexample
20783
20784If that does not find the binary, @value{GDBN} tries removing
20785the @samp{:} character from the drive spec, both for convenience, and,
20786for the case of the host file system not supporting file names with
20787colons:
20788
20789@smallexample
20790  c:/foo/bar.dll @result{} /path/to/sysroot/c/foo/bar.dll
20791@end smallexample
20792
20793This makes it possible to have a system root that mirrors a target
20794with more than one drive.  E.g., you may want to setup your local
20795copies of the target system shared libraries like so (note @samp{c} vs
20796@samp{z}):
20797
20798@smallexample
20799 @file{/path/to/sysroot/c/sys/bin/foo.dll}
20800 @file{/path/to/sysroot/c/sys/bin/bar.dll}
20801 @file{/path/to/sysroot/z/sys/bin/bar.dll}
20802@end smallexample
20803
20804@noindent
20805and point the system root at @file{/path/to/sysroot}, so that
20806@value{GDBN} can find the correct copies of both
20807@file{c:\sys\bin\foo.dll}, and @file{z:\sys\bin\bar.dll}.
20808
20809If that still does not find the binary, @value{GDBN} tries
20810removing the whole drive spec from the target file name:
20811
20812@smallexample
20813  c:/foo/bar.dll @result{} /path/to/sysroot/foo/bar.dll
20814@end smallexample
20815
20816This last lookup makes it possible to not care about the drive name,
20817if you don't want or need to.
20818
20819The @code{set solib-absolute-prefix} command is an alias for @code{set
20820sysroot}.
20821
20822@cindex default system root
20823@cindex @samp{--with-sysroot}
20824You can set the default system root by using the configure-time
20825@samp{--with-sysroot} option.  If the system root is inside
20826@value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
20827@samp{--exec-prefix}), then the default system root will be updated
20828automatically if the installed @value{GDBN} is moved to a new
20829location.
20830
20831@kindex show sysroot
20832@item show sysroot
20833Display the current executable and shared library prefix.
20834
20835@kindex set solib-search-path
20836@item set solib-search-path @var{path}
20837If this variable is set, @var{path} is a colon-separated list of
20838directories to search for shared libraries.  @samp{solib-search-path}
20839is used after @samp{sysroot} fails to locate the library, or if the
20840path to the library is relative instead of absolute.  If you want to
20841use @samp{solib-search-path} instead of @samp{sysroot}, be sure to set
20842@samp{sysroot} to a nonexistent directory to prevent @value{GDBN} from
20843finding your host's libraries.  @samp{sysroot} is preferred; setting
20844it to a nonexistent directory may interfere with automatic loading
20845of shared library symbols.
20846
20847@kindex show solib-search-path
20848@item show solib-search-path
20849Display the current shared library search path.
20850
20851@cindex DOS file-name semantics of file names.
20852@kindex set target-file-system-kind (unix|dos-based|auto)
20853@kindex show target-file-system-kind
20854@item set target-file-system-kind @var{kind}
20855Set assumed file system kind for target reported file names.
20856
20857Shared library file names as reported by the target system may not
20858make sense as is on the system @value{GDBN} is running on.  For
20859example, when remote debugging a target that has MS-DOS based file
20860system semantics, from a Unix host, the target may be reporting to
20861@value{GDBN} a list of loaded shared libraries with file names such as
20862@file{c:\Windows\kernel32.dll}.  On Unix hosts, there's no concept of
20863drive letters, so the @samp{c:\} prefix is not normally understood as
20864indicating an absolute file name, and neither is the backslash
20865normally considered a directory separator character.  In that case,
20866the native file system would interpret this whole absolute file name
20867as a relative file name with no directory components.  This would make
20868it impossible to point @value{GDBN} at a copy of the remote target's
20869shared libraries on the host using @code{set sysroot}, and impractical
20870with @code{set solib-search-path}.  Setting
20871@code{target-file-system-kind} to @code{dos-based} tells @value{GDBN}
20872to interpret such file names similarly to how the target would, and to
20873map them to file names valid on @value{GDBN}'s native file system
20874semantics.  The value of @var{kind} can be @code{"auto"}, in addition
20875to one of the supported file system kinds.  In that case, @value{GDBN}
20876tries to determine the appropriate file system variant based on the
20877current target's operating system (@pxref{ABI, ,Configuring the
20878Current ABI}).  The supported file system settings are:
20879
20880@table @code
20881@item unix
20882Instruct @value{GDBN} to assume the target file system is of Unix
20883kind.  Only file names starting the forward slash (@samp{/}) character
20884are considered absolute, and the directory separator character is also
20885the forward slash.
20886
20887@item dos-based
20888Instruct @value{GDBN} to assume the target file system is DOS based.
20889File names starting with either a forward slash, or a drive letter
20890followed by a colon (e.g., @samp{c:}), are considered absolute, and
20891both the slash (@samp{/}) and the backslash (@samp{\\}) characters are
20892considered directory separators.
20893
20894@item auto
20895Instruct @value{GDBN} to use the file system kind associated with the
20896target operating system (@pxref{ABI, ,Configuring the Current ABI}).
20897This is the default.
20898@end table
20899@end table
20900
20901@cindex file name canonicalization
20902@cindex base name differences
20903When processing file names provided by the user, @value{GDBN}
20904frequently needs to compare them to the file names recorded in the
20905program's debug info.  Normally, @value{GDBN} compares just the
20906@dfn{base names} of the files as strings, which is reasonably fast
20907even for very large programs.  (The base name of a file is the last
20908portion of its name, after stripping all the leading directories.)
20909This shortcut in comparison is based upon the assumption that files
20910cannot have more than one base name.  This is usually true, but
20911references to files that use symlinks or similar filesystem
20912facilities violate that assumption.  If your program records files
20913using such facilities, or if you provide file names to @value{GDBN}
20914using symlinks etc., you can set @code{basenames-may-differ} to
20915@code{true} to instruct @value{GDBN} to completely canonicalize each
20916pair of file names it needs to compare.  This will make file-name
20917comparisons accurate, but at a price of a significant slowdown.
20918
20919@table @code
20920@item set basenames-may-differ
20921@kindex set basenames-may-differ
20922Set whether a source file may have multiple base names.
20923
20924@item show basenames-may-differ
20925@kindex show basenames-may-differ
20926Show whether a source file may have multiple base names.
20927@end table
20928
20929@node File Caching
20930@section File Caching
20931@cindex caching of opened files
20932@cindex caching of bfd objects
20933
20934To speed up file loading, and reduce memory usage, @value{GDBN} will
20935reuse the @code{bfd} objects used to track open files.  @xref{Top, ,
20936BFD, bfd, The Binary File Descriptor Library}.  The following commands
20937allow visibility and control of the caching behavior.
20938
20939@table @code
20940@kindex maint info bfds
20941@item maint info bfds
20942This prints information about each @code{bfd} object that is known to
20943@value{GDBN}.
20944
20945@kindex maint set bfd-sharing
20946@kindex maint show bfd-sharing
20947@kindex bfd caching
20948@item maint set bfd-sharing
20949@item maint show bfd-sharing
20950Control whether @code{bfd} objects can be shared.  When sharing is
20951enabled @value{GDBN} reuses already open @code{bfd} objects rather
20952than reopening the same file.  Turning sharing off does not cause
20953already shared @code{bfd} objects to be unshared, but all future files
20954that are opened will create a new @code{bfd} object.  Similarly,
20955re-enabling sharing does not cause multiple existing @code{bfd}
20956objects to be collapsed into a single shared @code{bfd} object.
20957
20958@kindex set debug bfd-cache @var{level}
20959@kindex bfd caching
20960@item set debug bfd-cache @var{level}
20961Turns on debugging of the bfd cache, setting the level to @var{level}.
20962
20963@kindex show debug bfd-cache
20964@kindex bfd caching
20965@item show debug bfd-cache
20966Show the current debugging level of the bfd cache.
20967@end table
20968
20969@node Separate Debug Files
20970@section Debugging Information in Separate Files
20971@cindex separate debugging information files
20972@cindex debugging information in separate files
20973@cindex @file{.debug} subdirectories
20974@cindex debugging information directory, global
20975@cindex global debugging information directories
20976@cindex build ID, and separate debugging files
20977@cindex @file{.build-id} directory
20978
20979@value{GDBN} allows you to put a program's debugging information in a
20980file separate from the executable itself, in a way that allows
20981@value{GDBN} to find and load the debugging information automatically.
20982Since debugging information can be very large---sometimes larger
20983than the executable code itself---some systems distribute debugging
20984information for their executables in separate files, which users can
20985install only when they need to debug a problem.
20986
20987@value{GDBN} supports two ways of specifying the separate debug info
20988file:
20989
20990@itemize @bullet
20991@item
20992The executable contains a @dfn{debug link} that specifies the name of
20993the separate debug info file.  The separate debug file's name is
20994usually @file{@var{executable}.debug}, where @var{executable} is the
20995name of the corresponding executable file without leading directories
20996(e.g., @file{ls.debug} for @file{/usr/bin/ls}).  In addition, the
20997debug link specifies a 32-bit @dfn{Cyclic Redundancy Check} (CRC)
20998checksum for the debug file, which @value{GDBN} uses to validate that
20999the executable and the debug file came from the same build.
21000
21001@item
21002@anchor{build ID}
21003The executable contains a @dfn{build ID}, a unique bit string that is
21004also present in the corresponding debug info file.  (This is supported
21005only on some operating systems, when using the ELF or PE file formats
21006for binary files and the @sc{gnu} Binutils.)  For more details about
21007this feature, see the description of the @option{--build-id}
21008command-line option in @ref{Options, , Command Line Options, ld,
21009The GNU Linker}.  The debug info file's name is not specified
21010explicitly by the build ID, but can be computed from the build ID, see
21011below.
21012@end itemize
21013
21014Depending on the way the debug info file is specified, @value{GDBN}
21015uses two different methods of looking for the debug file:
21016
21017@itemize @bullet
21018@item
21019For the ``debug link'' method, @value{GDBN} looks up the named file in
21020the directory of the executable file, then in a subdirectory of that
21021directory named @file{.debug}, and finally under each one of the
21022global debug directories, in a subdirectory whose name is identical to
21023the leading directories of the executable's absolute file name.  (On
21024MS-Windows/MS-DOS, the drive letter of the executable's leading
21025directories is converted to a one-letter subdirectory, i.e.@:
21026@file{d:/usr/bin/} is converted to @file{/d/usr/bin/}, because Windows
21027filesystems disallow colons in file names.)
21028
21029@item
21030For the ``build ID'' method, @value{GDBN} looks in the
21031@file{.build-id} subdirectory of each one of the global debug directories for
21032a file named @file{@var{nn}/@var{nnnnnnnn}.debug}, where @var{nn} are the
21033first 2 hex characters of the build ID bit string, and @var{nnnnnnnn}
21034are the rest of the bit string.  (Real build ID strings are 32 or more
21035hex characters, not 10.)
21036@end itemize
21037
21038So, for example, suppose you ask @value{GDBN} to debug
21039@file{/usr/bin/ls}, which has a debug link that specifies the
21040file @file{ls.debug}, and a build ID whose value in hex is
21041@code{abcdef1234}.  If the list of the global debug directories includes
21042@file{/usr/lib/debug}, then @value{GDBN} will look for the following
21043debug information files, in the indicated order:
21044
21045@itemize @minus
21046@item
21047@file{/usr/lib/debug/.build-id/ab/cdef1234.debug}
21048@item
21049@file{/usr/bin/ls.debug}
21050@item
21051@file{/usr/bin/.debug/ls.debug}
21052@item
21053@file{/usr/lib/debug/usr/bin/ls.debug}.
21054@end itemize
21055
21056@anchor{debug-file-directory}
21057Global debugging info directories default to what is set by @value{GDBN}
21058configure option @option{--with-separate-debug-dir}.  During @value{GDBN} run
21059you can also set the global debugging info directories, and view the list
21060@value{GDBN} is currently using.
21061
21062@table @code
21063
21064@kindex set debug-file-directory
21065@item set debug-file-directory @var{directories}
21066Set the directories which @value{GDBN} searches for separate debugging
21067information files to @var{directory}.  Multiple path components can be set
21068concatenating them by a path separator.
21069
21070@kindex show debug-file-directory
21071@item show debug-file-directory
21072Show the directories @value{GDBN} searches for separate debugging
21073information files.
21074
21075@end table
21076
21077@cindex @code{.gnu_debuglink} sections
21078@cindex debug link sections
21079A debug link is a special section of the executable file named
21080@code{.gnu_debuglink}.  The section must contain:
21081
21082@itemize
21083@item
21084A filename, with any leading directory components removed, followed by
21085a zero byte,
21086@item
21087zero to three bytes of padding, as needed to reach the next four-byte
21088boundary within the section, and
21089@item
21090a four-byte CRC checksum, stored in the same endianness used for the
21091executable file itself.  The checksum is computed on the debugging
21092information file's full contents by the function given below, passing
21093zero as the @var{crc} argument.
21094@end itemize
21095
21096Any executable file format can carry a debug link, as long as it can
21097contain a section named @code{.gnu_debuglink} with the contents
21098described above.
21099
21100@cindex @code{.note.gnu.build-id} sections
21101@cindex build ID sections
21102The build ID is a special section in the executable file (and in other
21103ELF binary files that @value{GDBN} may consider).  This section is
21104often named @code{.note.gnu.build-id}, but that name is not mandatory.
21105It contains unique identification for the built files---the ID remains
21106the same across multiple builds of the same build tree.  The default
21107algorithm SHA1 produces 160 bits (40 hexadecimal characters) of the
21108content for the build ID string.  The same section with an identical
21109value is present in the original built binary with symbols, in its
21110stripped variant, and in the separate debugging information file.
21111
21112The debugging information file itself should be an ordinary
21113executable, containing a full set of linker symbols, sections, and
21114debugging information.  The sections of the debugging information file
21115should have the same names, addresses, and sizes as the original file,
21116but they need not contain any data---much like a @code{.bss} section
21117in an ordinary executable.
21118
21119The @sc{gnu} binary utilities (Binutils) package includes the
21120@samp{objcopy} utility that can produce
21121the separated executable / debugging information file pairs using the
21122following commands:
21123
21124@smallexample
21125@kbd{objcopy --only-keep-debug foo foo.debug}
21126@kbd{strip -g foo}
21127@end smallexample
21128
21129@noindent
21130These commands remove the debugging
21131information from the executable file @file{foo} and place it in the file
21132@file{foo.debug}.  You can use the first, second or both methods to link the
21133two files:
21134
21135@itemize @bullet
21136@item
21137The debug link method needs the following additional command to also leave
21138behind a debug link in @file{foo}:
21139
21140@smallexample
21141@kbd{objcopy --add-gnu-debuglink=foo.debug foo}
21142@end smallexample
21143
21144Ulrich Drepper's @file{elfutils} package, starting with version 0.53, contains
21145a version of the @code{strip} command such that the command @kbd{strip foo -f
21146foo.debug} has the same functionality as the two @code{objcopy} commands and
21147the @code{ln -s} command above, together.
21148
21149@item
21150Build ID gets embedded into the main executable using @code{ld --build-id} or
21151the @value{NGCC} counterpart @code{gcc -Wl,--build-id}.  Build ID support plus
21152compatibility fixes for debug files separation are present in @sc{gnu} binary
21153utilities (Binutils) package since version 2.18.
21154@end itemize
21155
21156@noindent
21157
21158@cindex CRC algorithm definition
21159The CRC used in @code{.gnu_debuglink} is the CRC-32 defined in
21160IEEE 802.3 using the polynomial:
21161
21162@c TexInfo requires naked braces for multi-digit exponents for Tex
21163@c output, but this causes HTML output to barf. HTML has to be set using
21164@c raw commands. So we end up having to specify this equation in 2
21165@c different ways!
21166@ifhtml
21167@display
21168@html
21169 <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>
21170 + <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
21171@end html
21172@end display
21173@end ifhtml
21174@ifnothtml
21175@display
21176 @math{x^{32} + x^{26} + x^{23} + x^{22} + x^{16} + x^{12} + x^{11}}
21177 @math{+ x^{10} + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1}
21178@end display
21179@end ifnothtml
21180
21181The function is computed byte at a time, taking the least
21182significant bit of each byte first.  The initial pattern
21183@code{0xffffffff} is used, to ensure leading zeros affect the CRC and
21184the final result is inverted to ensure trailing zeros also affect the
21185CRC.
21186
21187@emph{Note:} This is the same CRC polynomial as used in handling the
21188@dfn{Remote Serial Protocol} @code{qCRC} packet (@pxref{qCRC packet}).
21189However in the case of the Remote Serial Protocol, the CRC is computed
21190@emph{most} significant bit first, and the result is not inverted, so
21191trailing zeros have no effect on the CRC value.
21192
21193To complete the description, we show below the code of the function
21194which produces the CRC used in @code{.gnu_debuglink}.  Inverting the
21195initially supplied @code{crc} argument means that an initial call to
21196this function passing in zero will start computing the CRC using
21197@code{0xffffffff}.
21198
21199@kindex gnu_debuglink_crc32
21200@smallexample
21201unsigned long
21202gnu_debuglink_crc32 (unsigned long crc,
21203                     unsigned char *buf, size_t len)
21204@{
21205  static const unsigned long crc32_table[256] =
21206    @{
21207      0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
21208      0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
21209      0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
21210      0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
21211      0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
21212      0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
21213      0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
21214      0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
21215      0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
21216      0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
21217      0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
21218      0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
21219      0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
21220      0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
21221      0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
21222      0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
21223      0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
21224      0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
21225      0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
21226      0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
21227      0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
21228      0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
21229      0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
21230      0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
21231      0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
21232      0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
21233      0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
21234      0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
21235      0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
21236      0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
21237      0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
21238      0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
21239      0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
21240      0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
21241      0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
21242      0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
21243      0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
21244      0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
21245      0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
21246      0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
21247      0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
21248      0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
21249      0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
21250      0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
21251      0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
21252      0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
21253      0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
21254      0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
21255      0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
21256      0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
21257      0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
21258      0x2d02ef8d
21259    @};
21260  unsigned char *end;
21261
21262  crc = ~crc & 0xffffffff;
21263  for (end = buf + len; buf < end; ++buf)
21264    crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
21265  return ~crc & 0xffffffff;
21266@}
21267@end smallexample
21268
21269@noindent
21270This computation does not apply to the ``build ID'' method.
21271
21272@node MiniDebugInfo
21273@section Debugging information in a special section
21274@cindex separate debug sections
21275@cindex @samp{.gnu_debugdata} section
21276
21277Some systems ship pre-built executables and libraries that have a
21278special @samp{.gnu_debugdata} section.  This feature is called
21279@dfn{MiniDebugInfo}.  This section holds an LZMA-compressed object and
21280is used to supply extra symbols for backtraces.
21281
21282The intent of this section is to provide extra minimal debugging
21283information for use in simple backtraces.  It is not intended to be a
21284replacement for full separate debugging information (@pxref{Separate
21285Debug Files}).  The example below shows the intended use; however,
21286@value{GDBN} does not currently put restrictions on what sort of
21287debugging information might be included in the section.
21288
21289@value{GDBN} has support for this extension.  If the section exists,
21290then it is used provided that no other source of debugging information
21291can be found, and that @value{GDBN} was configured with LZMA support.
21292
21293This section can be easily created using @command{objcopy} and other
21294standard utilities:
21295
21296@smallexample
21297# Extract the dynamic symbols from the main binary, there is no need
21298# to also have these in the normal symbol table.
21299nm -D @var{binary} --format=posix --defined-only \
21300  | awk '@{ print $1 @}' | sort > dynsyms
21301
21302# Extract all the text (i.e. function) symbols from the debuginfo.
21303# (Note that we actually also accept "D" symbols, for the benefit
21304# of platforms like PowerPC64 that use function descriptors.)
21305nm @var{binary} --format=posix --defined-only \
21306  | awk '@{ if ($2 == "T" || $2 == "t" || $2 == "D") print $1 @}' \
21307  | sort > funcsyms
21308
21309# Keep all the function symbols not already in the dynamic symbol
21310# table.
21311comm -13 dynsyms funcsyms > keep_symbols
21312
21313# Separate full debug info into debug binary.
21314objcopy --only-keep-debug @var{binary} debug
21315
21316# Copy the full debuginfo, keeping only a minimal set of symbols and
21317# removing some unnecessary sections.
21318objcopy -S --remove-section .gdb_index --remove-section .comment \
21319  --keep-symbols=keep_symbols debug mini_debuginfo
21320
21321# Drop the full debug info from the original binary.
21322strip --strip-all -R .comment @var{binary}
21323
21324# Inject the compressed data into the .gnu_debugdata section of the
21325# original binary.
21326xz mini_debuginfo
21327objcopy --add-section .gnu_debugdata=mini_debuginfo.xz @var{binary}
21328@end smallexample
21329
21330@node Index Files
21331@section Index Files Speed Up @value{GDBN}
21332@cindex index files
21333@cindex @samp{.gdb_index} section
21334
21335When @value{GDBN} finds a symbol file, it scans the symbols in the
21336file in order to construct an internal symbol table.  This lets most
21337@value{GDBN} operations work quickly---at the cost of a delay early
21338on.  For large programs, this delay can be quite lengthy, so
21339@value{GDBN} provides a way to build an index, which speeds up
21340startup.
21341
21342For convenience, @value{GDBN} comes with a program,
21343@command{gdb-add-index}, which can be used to add the index to a
21344symbol file.  It takes the symbol file as its only argument:
21345
21346@smallexample
21347$ gdb-add-index symfile
21348@end smallexample
21349
21350@xref{gdb-add-index}.
21351
21352It is also possible to do the work manually.  Here is what
21353@command{gdb-add-index} does behind the curtains.
21354
21355The index is stored as a section in the symbol file.  @value{GDBN} can
21356write the index to a file, then you can put it into the symbol file
21357using @command{objcopy}.
21358
21359To create an index file, use the @code{save gdb-index} command:
21360
21361@table @code
21362@item save gdb-index [-dwarf-5] @var{directory}
21363@kindex save gdb-index
21364Create index files for all symbol files currently known by
21365@value{GDBN}.  For each known @var{symbol-file}, this command by
21366default creates it produces a single file
21367@file{@var{symbol-file}.gdb-index}.  If you invoke this command with
21368the @option{-dwarf-5} option, it produces 2 files:
21369@file{@var{symbol-file}.debug_names} and
21370@file{@var{symbol-file}.debug_str}.  The files are created in the
21371given @var{directory}.
21372@end table
21373
21374Once you have created an index file you can merge it into your symbol
21375file, here named @file{symfile}, using @command{objcopy}:
21376
21377@smallexample
21378$ objcopy --add-section .gdb_index=symfile.gdb-index \
21379    --set-section-flags .gdb_index=readonly symfile symfile
21380@end smallexample
21381
21382Or for @code{-dwarf-5}:
21383
21384@smallexample
21385$ objcopy --dump-section .debug_str=symfile.debug_str.new symfile
21386$ cat symfile.debug_str >>symfile.debug_str.new
21387$ objcopy --add-section .debug_names=symfile.gdb-index \
21388    --set-section-flags .debug_names=readonly \
21389    --update-section .debug_str=symfile.debug_str.new symfile symfile
21390@end smallexample
21391
21392@value{GDBN} will normally ignore older versions of @file{.gdb_index}
21393sections that have been deprecated.  Usually they are deprecated because
21394they are missing a new feature or have performance issues.
21395To tell @value{GDBN} to use a deprecated index section anyway
21396specify @code{set use-deprecated-index-sections on}.
21397The default is @code{off}.
21398This can speed up startup, but may result in some functionality being lost.
21399@xref{Index Section Format}.
21400
21401@emph{Warning:} Setting @code{use-deprecated-index-sections} to @code{on}
21402must be done before gdb reads the file.  The following will not work:
21403
21404@smallexample
21405$ gdb -ex "set use-deprecated-index-sections on" <program>
21406@end smallexample
21407
21408Instead you must do, for example,
21409
21410@smallexample
21411$ gdb -iex "set use-deprecated-index-sections on" <program>
21412@end smallexample
21413
21414Indices only work when using DWARF debugging information, not stabs.
21415
21416@subsection Automatic symbol index cache
21417
21418@cindex automatic symbol index cache
21419It is possible for @value{GDBN} to automatically save a copy of this index in a
21420cache on disk and retrieve it from there when loading the same binary in the
21421future.  This feature can be turned on with @kbd{set index-cache on}.  The
21422following commands can be used to tweak the behavior of the index cache.
21423
21424@table @code
21425
21426@kindex set index-cache
21427@item set index-cache on
21428@itemx set index-cache off
21429Enable or disable the use of the symbol index cache.
21430
21431@item set index-cache directory @var{directory}
21432@kindex show index-cache
21433@itemx show index-cache directory
21434Set/show the directory where index files will be saved.
21435
21436The default value for this directory depends on the host platform.  On
21437most systems, the index is cached in the @file{gdb} subdirectory of
21438the directory pointed to by the @env{XDG_CACHE_HOME} environment
21439variable, if it is defined, else in the @file{.cache/gdb} subdirectory
21440of your home directory.  However, on some systems, the default may
21441differ according to local convention.
21442
21443There is no limit on the disk space used by index cache.  It is perfectly safe
21444to delete the content of that directory to free up disk space.
21445
21446@item show index-cache stats
21447Print the number of cache hits and misses since the launch of @value{GDBN}.
21448
21449@end table
21450
21451@node Symbol Errors
21452@section Errors Reading Symbol Files
21453
21454While reading a symbol file, @value{GDBN} occasionally encounters problems,
21455such as symbol types it does not recognize, or known bugs in compiler
21456output.  By default, @value{GDBN} does not notify you of such problems, since
21457they are relatively common and primarily of interest to people
21458debugging compilers.  If you are interested in seeing information
21459about ill-constructed symbol tables, you can either ask @value{GDBN} to print
21460only one message about each such type of problem, no matter how many
21461times the problem occurs; or you can ask @value{GDBN} to print more messages,
21462to see how many times the problems occur, with the @code{set
21463complaints} command (@pxref{Messages/Warnings, ,Optional Warnings and
21464Messages}).
21465
21466The messages currently printed, and their meanings, include:
21467
21468@table @code
21469@item inner block not inside outer block in @var{symbol}
21470
21471The symbol information shows where symbol scopes begin and end
21472(such as at the start of a function or a block of statements).  This
21473error indicates that an inner scope block is not fully contained
21474in its outer scope blocks.
21475
21476@value{GDBN} circumvents the problem by treating the inner block as if it had
21477the same scope as the outer block.  In the error message, @var{symbol}
21478may be shown as ``@code{(don't know)}'' if the outer block is not a
21479function.
21480
21481@item block at @var{address} out of order
21482
21483The symbol information for symbol scope blocks should occur in
21484order of increasing addresses.  This error indicates that it does not
21485do so.
21486
21487@value{GDBN} does not circumvent this problem, and has trouble
21488locating symbols in the source file whose symbols it is reading.  (You
21489can often determine what source file is affected by specifying
21490@code{set verbose on}.  @xref{Messages/Warnings, ,Optional Warnings and
21491Messages}.)
21492
21493@item bad block start address patched
21494
21495The symbol information for a symbol scope block has a start address
21496smaller than the address of the preceding source line.  This is known
21497to occur in the SunOS 4.1.1 (and earlier) C compiler.
21498
21499@value{GDBN} circumvents the problem by treating the symbol scope block as
21500starting on the previous source line.
21501
21502@item bad string table offset in symbol @var{n}
21503
21504@cindex foo
21505Symbol number @var{n} contains a pointer into the string table which is
21506larger than the size of the string table.
21507
21508@value{GDBN} circumvents the problem by considering the symbol to have the
21509name @code{foo}, which may cause other problems if many symbols end up
21510with this name.
21511
21512@item unknown symbol type @code{0x@var{nn}}
21513
21514The symbol information contains new data types that @value{GDBN} does
21515not yet know how to read.  @code{0x@var{nn}} is the symbol type of the
21516uncomprehended information, in hexadecimal.
21517
21518@value{GDBN} circumvents the error by ignoring this symbol information.
21519This usually allows you to debug your program, though certain symbols
21520are not accessible.  If you encounter such a problem and feel like
21521debugging it, you can debug @code{@value{GDBP}} with itself, breakpoint
21522on @code{complain}, then go up to the function @code{read_dbx_symtab}
21523and examine @code{*bufp} to see the symbol.
21524
21525@item stub type has NULL name
21526
21527@value{GDBN} could not find the full definition for a struct or class.
21528
21529@item const/volatile indicator missing (ok if using g++ v1.x), got@dots{}
21530The symbol information for a C@t{++} member function is missing some
21531information that recent versions of the compiler should have output for
21532it.
21533
21534@item info mismatch between compiler and debugger
21535
21536@value{GDBN} could not parse a type specification output by the compiler.
21537
21538@end table
21539
21540@node Data Files
21541@section GDB Data Files
21542
21543@cindex prefix for data files
21544@value{GDBN} will sometimes read an auxiliary data file.  These files
21545are kept in a directory known as the @dfn{data directory}.
21546
21547You can set the data directory's name, and view the name @value{GDBN}
21548is currently using.
21549
21550@table @code
21551@kindex set data-directory
21552@item set data-directory @var{directory}
21553Set the directory which @value{GDBN} searches for auxiliary data files
21554to @var{directory}.
21555
21556@kindex show data-directory
21557@item show data-directory
21558Show the directory @value{GDBN} searches for auxiliary data files.
21559@end table
21560
21561@cindex default data directory
21562@cindex @samp{--with-gdb-datadir}
21563You can set the default data directory by using the configure-time
21564@samp{--with-gdb-datadir} option.  If the data directory is inside
21565@value{GDBN}'s configured binary prefix (set with @samp{--prefix} or
21566@samp{--exec-prefix}), then the default data directory will be updated
21567automatically if the installed @value{GDBN} is moved to a new
21568location.
21569
21570The data directory may also be specified with the
21571@code{--data-directory} command line option.
21572@xref{Mode Options}.
21573
21574@node Targets
21575@chapter Specifying a Debugging Target
21576
21577@cindex debugging target
21578A @dfn{target} is the execution environment occupied by your program.
21579
21580Often, @value{GDBN} runs in the same host environment as your program;
21581in that case, the debugging target is specified as a side effect when
21582you use the @code{file} or @code{core} commands.  When you need more
21583flexibility---for example, running @value{GDBN} on a physically separate
21584host, or controlling a standalone system over a serial port or a
21585realtime system over a TCP/IP connection---you can use the @code{target}
21586command to specify one of the target types configured for @value{GDBN}
21587(@pxref{Target Commands, ,Commands for Managing Targets}).
21588
21589@cindex target architecture
21590It is possible to build @value{GDBN} for several different @dfn{target
21591architectures}.  When @value{GDBN} is built like that, you can choose
21592one of the available architectures with the @kbd{set architecture}
21593command.
21594
21595@table @code
21596@kindex set architecture
21597@kindex show architecture
21598@item set architecture @var{arch}
21599This command sets the current target architecture to @var{arch}.  The
21600value of @var{arch} can be @code{"auto"}, in addition to one of the
21601supported architectures.
21602
21603@item show architecture
21604Show the current target architecture.
21605
21606@item set processor
21607@itemx processor
21608@kindex set processor
21609@kindex show processor
21610These are alias commands for, respectively, @code{set architecture}
21611and @code{show architecture}.
21612@end table
21613
21614@menu
21615* Active Targets::              Active targets
21616* Target Commands::             Commands for managing targets
21617* Byte Order::                  Choosing target byte order
21618@end menu
21619
21620@node Active Targets
21621@section Active Targets
21622
21623@cindex stacking targets
21624@cindex active targets
21625@cindex multiple targets
21626
21627There are multiple classes of targets such as: processes, executable files or
21628recording sessions.  Core files belong to the process class, making core file
21629and process mutually exclusive.  Otherwise, @value{GDBN} can work concurrently
21630on multiple active targets, one in each class.  This allows you to (for
21631example) start a process and inspect its activity, while still having access to
21632the executable file after the process finishes.  Or if you start process
21633recording (@pxref{Reverse Execution}) and @code{reverse-step} there, you are
21634presented a virtual layer of the recording target, while the process target
21635remains stopped at the chronologically last point of the process execution.
21636
21637Use the @code{core-file} and @code{exec-file} commands to select a new core
21638file or executable target (@pxref{Files, ,Commands to Specify Files}).  To
21639specify as a target a process that is already running, use the @code{attach}
21640command (@pxref{Attach, ,Debugging an Already-running Process}).
21641
21642@node Target Commands
21643@section Commands for Managing Targets
21644
21645@table @code
21646@item target @var{type} @var{parameters}
21647Connects the @value{GDBN} host environment to a target machine or
21648process.  A target is typically a protocol for talking to debugging
21649facilities.  You use the argument @var{type} to specify the type or
21650protocol of the target machine.
21651
21652Further @var{parameters} are interpreted by the target protocol, but
21653typically include things like device names or host names to connect
21654with, process numbers, and baud rates.
21655
21656The @code{target} command does not repeat if you press @key{RET} again
21657after executing the command.
21658
21659@kindex help target
21660@item help target
21661Displays the names of all targets available.  To display targets
21662currently selected, use either @code{info target} or @code{info files}
21663(@pxref{Files, ,Commands to Specify Files}).
21664
21665@item help target @var{name}
21666Describe a particular target, including any parameters necessary to
21667select it.
21668
21669@kindex set gnutarget
21670@item set gnutarget @var{args}
21671@value{GDBN} uses its own library BFD to read your files.  @value{GDBN}
21672knows whether it is reading an @dfn{executable},
21673a @dfn{core}, or a @dfn{.o} file; however, you can specify the file format
21674with the @code{set gnutarget} command.  Unlike most @code{target} commands,
21675with @code{gnutarget} the @code{target} refers to a program, not a machine.
21676
21677@quotation
21678@emph{Warning:} To specify a file format with @code{set gnutarget},
21679you must know the actual BFD name.
21680@end quotation
21681
21682@noindent
21683@xref{Files, , Commands to Specify Files}.
21684
21685@kindex show gnutarget
21686@item show gnutarget
21687Use the @code{show gnutarget} command to display what file format
21688@code{gnutarget} is set to read.  If you have not set @code{gnutarget},
21689@value{GDBN} will determine the file format for each file automatically,
21690and @code{show gnutarget} displays @samp{The current BFD target is "auto"}.
21691@end table
21692
21693@cindex common targets
21694Here are some common targets (available, or not, depending on the GDB
21695configuration):
21696
21697@table @code
21698@kindex target
21699@item target exec @var{program}
21700@cindex executable file target
21701An executable file.  @samp{target exec @var{program}} is the same as
21702@samp{exec-file @var{program}}.
21703
21704@item target core @var{filename}
21705@cindex core dump file target
21706A core dump file.  @samp{target core @var{filename}} is the same as
21707@samp{core-file @var{filename}}.
21708
21709@item target remote @var{medium}
21710@cindex remote target
21711A remote system connected to @value{GDBN} via a serial line or network
21712connection.  This command tells @value{GDBN} to use its own remote
21713protocol over @var{medium} for debugging.  @xref{Remote Debugging}.
21714
21715For example, if you have a board connected to @file{/dev/ttya} on the
21716machine running @value{GDBN}, you could say:
21717
21718@smallexample
21719target remote /dev/ttya
21720@end smallexample
21721
21722@code{target remote} supports the @code{load} command.  This is only
21723useful if you have some other way of getting the stub to the target
21724system, and you can put it somewhere in memory where it won't get
21725clobbered by the download.
21726
21727@item target sim @r{[}@var{simargs}@r{]} @dots{}
21728@cindex built-in simulator target
21729Builtin CPU simulator.  @value{GDBN} includes simulators for most architectures.
21730In general,
21731@smallexample
21732        target sim
21733        load
21734        run
21735@end smallexample
21736@noindent
21737works; however, you cannot assume that a specific memory map, device
21738drivers, or even basic I/O is available, although some simulators do
21739provide these.  For info about any processor-specific simulator details,
21740see the appropriate section in @ref{Embedded Processors, ,Embedded
21741Processors}.
21742
21743@item target native
21744@cindex native target
21745Setup for local/native process debugging.  Useful to make the
21746@code{run} command spawn native processes (likewise @code{attach},
21747etc.@:) even when @code{set auto-connect-native-target} is @code{off}
21748(@pxref{set auto-connect-native-target}).
21749
21750@end table
21751
21752Different targets are available on different configurations of @value{GDBN};
21753your configuration may have more or fewer targets.
21754
21755Many remote targets require you to download the executable's code once
21756you've successfully established a connection.  You may wish to control
21757various aspects of this process.
21758
21759@table @code
21760
21761@item set hash
21762@kindex set hash@r{, for remote monitors}
21763@cindex hash mark while downloading
21764This command controls whether a hash mark @samp{#} is displayed while
21765downloading a file to the remote monitor.  If on, a hash mark is
21766displayed after each S-record is successfully downloaded to the
21767monitor.
21768
21769@item show hash
21770@kindex show hash@r{, for remote monitors}
21771Show the current status of displaying the hash mark.
21772
21773@item set debug monitor
21774@kindex set debug monitor
21775@cindex display remote monitor communications
21776Enable or disable display of communications messages between
21777@value{GDBN} and the remote monitor.
21778
21779@item show debug monitor
21780@kindex show debug monitor
21781Show the current status of displaying communications between
21782@value{GDBN} and the remote monitor.
21783@end table
21784
21785@table @code
21786
21787@kindex load @var{filename} @var{offset}
21788@item load @var{filename} @var{offset}
21789@anchor{load}
21790Depending on what remote debugging facilities are configured into
21791@value{GDBN}, the @code{load} command may be available.  Where it exists, it
21792is meant to make @var{filename} (an executable) available for debugging
21793on the remote system---by downloading, or dynamic linking, for example.
21794@code{load} also records the @var{filename} symbol table in @value{GDBN}, like
21795the @code{add-symbol-file} command.
21796
21797If your @value{GDBN} does not have a @code{load} command, attempting to
21798execute it gets the error message ``@code{You can't do that when your
21799target is @dots{}}''
21800
21801The file is loaded at whatever address is specified in the executable.
21802For some object file formats, you can specify the load address when you
21803link the program; for other formats, like a.out, the object file format
21804specifies a fixed address.
21805@c FIXME! This would be a good place for an xref to the GNU linker doc.
21806
21807It is also possible to tell @value{GDBN} to load the executable file at a
21808specific offset described by the optional argument @var{offset}.  When
21809@var{offset} is provided, @var{filename} must also be provided.
21810
21811Depending on the remote side capabilities, @value{GDBN} may be able to
21812load programs into flash memory.
21813
21814@code{load} does not repeat if you press @key{RET} again after using it.
21815@end table
21816
21817@table @code
21818
21819@kindex flash-erase
21820@item flash-erase
21821@anchor{flash-erase}
21822
21823Erases all known flash memory regions on the target.
21824
21825@end table
21826
21827@node Byte Order
21828@section Choosing Target Byte Order
21829
21830@cindex choosing target byte order
21831@cindex target byte order
21832
21833Some types of processors, such as the @acronym{MIPS}, PowerPC, and Renesas SH,
21834offer the ability to run either big-endian or little-endian byte
21835orders.  Usually the executable or symbol will include a bit to
21836designate the endian-ness, and you will not need to worry about
21837which to use.  However, you may still find it useful to adjust
21838@value{GDBN}'s idea of processor endian-ness manually.
21839
21840@table @code
21841@kindex set endian
21842@item set endian big
21843Instruct @value{GDBN} to assume the target is big-endian.
21844
21845@item set endian little
21846Instruct @value{GDBN} to assume the target is little-endian.
21847
21848@item set endian auto
21849Instruct @value{GDBN} to use the byte order associated with the
21850executable.
21851
21852@item show endian
21853Display @value{GDBN}'s current idea of the target byte order.
21854
21855@end table
21856
21857If the @code{set endian auto} mode is in effect and no executable has
21858been selected, then the endianness used is the last one chosen either
21859by one of the @code{set endian big} and @code{set endian little}
21860commands or by inferring from the last executable used.  If no
21861endianness has been previously chosen, then the default for this mode
21862is inferred from the target @value{GDBN} has been built for, and is
21863@code{little} if the name of the target CPU has an @code{el} suffix
21864and @code{big} otherwise.
21865
21866Note that these commands merely adjust interpretation of symbolic
21867data on the host, and that they have absolutely no effect on the
21868target system.
21869
21870
21871@node Remote Debugging
21872@chapter Debugging Remote Programs
21873@cindex remote debugging
21874
21875If you are trying to debug a program running on a machine that cannot run
21876@value{GDBN} in the usual way, it is often useful to use remote debugging.
21877For example, you might use remote debugging on an operating system kernel,
21878or on a small system which does not have a general purpose operating system
21879powerful enough to run a full-featured debugger.
21880
21881Some configurations of @value{GDBN} have special serial or TCP/IP interfaces
21882to make this work with particular debugging targets.  In addition,
21883@value{GDBN} comes with a generic serial protocol (specific to @value{GDBN},
21884but not specific to any particular target system) which you can use if you
21885write the remote stubs---the code that runs on the remote system to
21886communicate with @value{GDBN}.
21887
21888Other remote targets may be available in your
21889configuration of @value{GDBN}; use @code{help target} to list them.
21890
21891@menu
21892* Connecting::                  Connecting to a remote target
21893* File Transfer::               Sending files to a remote system
21894* Server::	                Using the gdbserver program
21895* Remote Configuration::        Remote configuration
21896* Remote Stub::                 Implementing a remote stub
21897@end menu
21898
21899@node Connecting
21900@section Connecting to a Remote Target
21901@cindex remote debugging, connecting
21902@cindex @code{gdbserver}, connecting
21903@cindex remote debugging, types of connections
21904@cindex @code{gdbserver}, types of connections
21905@cindex @code{gdbserver}, @code{target remote} mode
21906@cindex @code{gdbserver}, @code{target extended-remote} mode
21907
21908This section describes how to connect to a remote target, including the
21909types of connections and their differences, how to set up executable and
21910symbol files on the host and target, and the commands used for
21911connecting to and disconnecting from the remote target.
21912
21913@subsection Types of Remote Connections
21914
21915@value{GDBN} supports two types of remote connections, @code{target remote}
21916mode and @code{target extended-remote} mode.  Note that many remote targets
21917support only @code{target remote} mode.  There are several major
21918differences between the two types of connections, enumerated here:
21919
21920@table @asis
21921
21922@cindex remote debugging, detach and program exit
21923@item Result of detach or program exit
21924@strong{With target remote mode:} When the debugged program exits or you
21925detach from it, @value{GDBN} disconnects from the target.  When using
21926@code{gdbserver}, @code{gdbserver} will exit.
21927
21928@strong{With target extended-remote mode:} When the debugged program exits or
21929you detach from it, @value{GDBN} remains connected to the target, even
21930though no program is running.  You can rerun the program, attach to a
21931running program, or use @code{monitor} commands specific to the target.
21932
21933When using @code{gdbserver} in this case, it does not exit unless it was
21934invoked using the @option{--once} option.  If the @option{--once} option
21935was not used, you can ask @code{gdbserver} to exit using the
21936@code{monitor exit} command (@pxref{Monitor Commands for gdbserver}).
21937
21938@item Specifying the program to debug
21939For both connection types you use the @code{file} command to specify the
21940program on the host system.  If you are using @code{gdbserver} there are
21941some differences in how to specify the location of the program on the
21942target.
21943
21944@strong{With target remote mode:} You must either specify the program to debug
21945on the @code{gdbserver} command line or use the @option{--attach} option
21946(@pxref{Attaching to a program,,Attaching to a Running Program}).
21947
21948@cindex @option{--multi}, @code{gdbserver} option
21949@strong{With target extended-remote mode:} You may specify the program to debug
21950on the @code{gdbserver} command line, or you can load the program or attach
21951to it using @value{GDBN} commands after connecting to @code{gdbserver}.
21952
21953@anchor{--multi Option in Types of Remote Connnections}
21954You can start @code{gdbserver} without supplying an initial command to run
21955or process ID to attach.  To do this, use the @option{--multi} command line
21956option.  Then you can connect using @code{target extended-remote} and start
21957the program you want to debug (see below for details on using the
21958@code{run} command in this scenario).  Note that the conditions under which
21959@code{gdbserver} terminates depend on how @value{GDBN} connects to it
21960(@code{target remote} or @code{target extended-remote}).  The
21961@option{--multi} option to @code{gdbserver} has no influence on that.
21962
21963@item The @code{run} command
21964@strong{With target remote mode:} The @code{run} command is not
21965supported.  Once a connection has been established, you can use all
21966the usual @value{GDBN} commands to examine and change data.  The
21967remote program is already running, so you can use commands like
21968@kbd{step} and @kbd{continue}.
21969
21970@strong{With target extended-remote mode:} The @code{run} command is
21971supported.  The @code{run} command uses the value set by
21972@code{set remote exec-file} (@pxref{set remote exec-file}) to select
21973the program to run.  Command line arguments are supported, except for
21974wildcard expansion and I/O redirection (@pxref{Arguments}).
21975
21976If you specify the program to debug on the command line, then the
21977@code{run} command is not required to start execution, and you can
21978resume using commands like @kbd{step} and @kbd{continue} as with
21979@code{target remote} mode.
21980
21981@anchor{Attaching in Types of Remote Connections}
21982@item Attaching
21983@strong{With target remote mode:} The @value{GDBN} command @code{attach} is
21984not supported.  To attach to a running program using @code{gdbserver}, you
21985must use the @option{--attach} option (@pxref{Running gdbserver}).
21986
21987@strong{With target extended-remote mode:} To attach to a running program,
21988you may use the @code{attach} command after the connection has been
21989established.  If you are using @code{gdbserver}, you may also invoke
21990@code{gdbserver} using the @option{--attach} option
21991(@pxref{Running gdbserver}).
21992
21993Some remote targets allow @value{GDBN} to determine the executable file running
21994in the process the debugger is attaching to.  In such a case, @value{GDBN}
21995uses the value of @code{exec-file-mismatch} to handle a possible mismatch
21996between the executable file name running in the process and the name of the
21997current exec-file loaded by @value{GDBN} (@pxref{set exec-file-mismatch}).
21998
21999@end table
22000
22001@anchor{Host and target files}
22002@subsection Host and Target Files
22003@cindex remote debugging, symbol files
22004@cindex symbol files, remote debugging
22005
22006@value{GDBN}, running on the host, needs access to symbol and debugging
22007information for your program running on the target.  This requires
22008access to an unstripped copy of your program, and possibly any associated
22009symbol files.  Note that this section applies equally to both @code{target
22010remote} mode and @code{target extended-remote} mode.
22011
22012Some remote targets (@pxref{qXfer executable filename read}, and
22013@pxref{Host I/O Packets}) allow @value{GDBN} to access program files over
22014the same connection used to communicate with @value{GDBN}.  With such a
22015target, if the remote program is unstripped, the only command you need is
22016@code{target remote} (or @code{target extended-remote}).
22017
22018If the remote program is stripped, or the target does not support remote
22019program file access, start up @value{GDBN} using the name of the local
22020unstripped copy of your program as the first argument, or use the
22021@code{file} command.  Use @code{set sysroot} to specify the location (on
22022the host) of target libraries (unless your @value{GDBN} was compiled with
22023the correct sysroot using @code{--with-sysroot}).  Alternatively, you
22024may use @code{set solib-search-path} to specify how @value{GDBN} locates
22025target libraries.
22026
22027The symbol file and target libraries must exactly match the executable
22028and libraries on the target, with one exception: the files on the host
22029system should not be stripped, even if the files on the target system
22030are.  Mismatched or missing files will lead to confusing results
22031during debugging.  On @sc{gnu}/Linux targets, mismatched or missing
22032files may also prevent @code{gdbserver} from debugging multi-threaded
22033programs.
22034
22035@subsection Remote Connection Commands
22036@cindex remote connection commands
22037@value{GDBN} can communicate with the target over a serial line, a
22038local Unix domain socket, or
22039over an @acronym{IP} network using @acronym{TCP} or @acronym{UDP}.  In
22040each case, @value{GDBN} uses the same protocol for debugging your
22041program; only the medium carrying the debugging packets varies.  The
22042@code{target remote} and @code{target extended-remote} commands
22043establish a connection to the target.  Both commands accept the same
22044arguments, which indicate the medium to use:
22045
22046@table @code
22047
22048@item target remote @var{serial-device}
22049@itemx target extended-remote @var{serial-device}
22050@cindex serial line, @code{target remote}
22051Use @var{serial-device} to communicate with the target.  For example,
22052to use a serial line connected to the device named @file{/dev/ttyb}:
22053
22054@smallexample
22055target remote /dev/ttyb
22056@end smallexample
22057
22058If you're using a serial line, you may want to give @value{GDBN} the
22059@samp{--baud} option, or use the @code{set serial baud} command
22060(@pxref{Remote Configuration, set serial baud}) before the
22061@code{target} command.
22062
22063@item target remote @var{local-socket}
22064@itemx target extended-remote @var{local-socket}
22065@cindex local socket, @code{target remote}
22066@cindex Unix domain socket
22067Use @var{local-socket} to communicate with the target.  For example,
22068to use a local Unix domain socket bound to the file system entry @file{/tmp/gdb-socket0}:
22069
22070@smallexample
22071target remote /tmp/gdb-socket0
22072@end smallexample
22073
22074Note that this command has the same form as the command to connect
22075to a serial line.  @value{GDBN} will automatically determine which
22076kind of file you have specified and will make the appropriate kind
22077of connection.
22078This feature is not available if the host system does not support
22079Unix domain sockets.
22080
22081@item target remote @code{@var{host}:@var{port}}
22082@itemx target remote @code{[@var{host}]:@var{port}}
22083@itemx target remote @code{tcp:@var{host}:@var{port}}
22084@itemx target remote @code{tcp:[@var{host}]:@var{port}}
22085@itemx target remote @code{tcp4:@var{host}:@var{port}}
22086@itemx target remote @code{tcp6:@var{host}:@var{port}}
22087@itemx target remote @code{tcp6:[@var{host}]:@var{port}}
22088@itemx target extended-remote @code{@var{host}:@var{port}}
22089@itemx target extended-remote @code{[@var{host}]:@var{port}}
22090@itemx target extended-remote @code{tcp:@var{host}:@var{port}}
22091@itemx target extended-remote @code{tcp:[@var{host}]:@var{port}}
22092@itemx target extended-remote @code{tcp4:@var{host}:@var{port}}
22093@itemx target extended-remote @code{tcp6:@var{host}:@var{port}}
22094@itemx target extended-remote @code{tcp6:[@var{host}]:@var{port}}
22095@cindex @acronym{TCP} port, @code{target remote}
22096Debug using a @acronym{TCP} connection to @var{port} on @var{host}.
22097The @var{host} may be either a host name, a numeric @acronym{IPv4}
22098address, or a numeric @acronym{IPv6} address (with or without the
22099square brackets to separate the address from the port); @var{port}
22100must be a decimal number.  The @var{host} could be the target machine
22101itself, if it is directly connected to the net, or it might be a
22102terminal server which in turn has a serial line to the target.
22103
22104For example, to connect to port 2828 on a terminal server named
22105@code{manyfarms}:
22106
22107@smallexample
22108target remote manyfarms:2828
22109@end smallexample
22110
22111To connect to port 2828 on a terminal server whose address is
22112@code{2001:0db8:85a3:0000:0000:8a2e:0370:7334}, you can either use the
22113square bracket syntax:
22114
22115@smallexample
22116target remote [2001:0db8:85a3:0000:0000:8a2e:0370:7334]:2828
22117@end smallexample
22118
22119@noindent
22120or explicitly specify the @acronym{IPv6} protocol:
22121
22122@smallexample
22123target remote tcp6:2001:0db8:85a3:0000:0000:8a2e:0370:7334:2828
22124@end smallexample
22125
22126This last example may be confusing to the reader, because there is no
22127visible separation between the hostname and the port number.
22128Therefore, we recommend the user to provide @acronym{IPv6} addresses
22129using square brackets for clarity.  However, it is important to
22130mention that for @value{GDBN} there is no ambiguity: the number after
22131the last colon is considered to be the port number.
22132
22133If your remote target is actually running on the same machine as your
22134debugger session (e.g.@: a simulator for your target running on the
22135same host), you can omit the hostname.  For example, to connect to
22136port 1234 on your local machine:
22137
22138@smallexample
22139target remote :1234
22140@end smallexample
22141@noindent
22142
22143Note that the colon is still required here.
22144
22145@item target remote @code{udp:@var{host}:@var{port}}
22146@itemx target remote @code{udp:[@var{host}]:@var{port}}
22147@itemx target remote @code{udp4:@var{host}:@var{port}}
22148@itemx target remote @code{udp6:[@var{host}]:@var{port}}
22149@itemx target extended-remote @code{udp:@var{host}:@var{port}}
22150@itemx target extended-remote @code{udp:@var{host}:@var{port}}
22151@itemx target extended-remote @code{udp:[@var{host}]:@var{port}}
22152@itemx target extended-remote @code{udp4:@var{host}:@var{port}}
22153@itemx target extended-remote @code{udp6:@var{host}:@var{port}}
22154@itemx target extended-remote @code{udp6:[@var{host}]:@var{port}}
22155@cindex @acronym{UDP} port, @code{target remote}
22156Debug using @acronym{UDP} packets to @var{port} on @var{host}.  For example, to
22157connect to @acronym{UDP} port 2828 on a terminal server named @code{manyfarms}:
22158
22159@smallexample
22160target remote udp:manyfarms:2828
22161@end smallexample
22162
22163When using a @acronym{UDP} connection for remote debugging, you should
22164keep in mind that the `U' stands for ``Unreliable''.  @acronym{UDP}
22165can silently drop packets on busy or unreliable networks, which will
22166cause havoc with your debugging session.
22167
22168@item target remote | @var{command}
22169@itemx target extended-remote | @var{command}
22170@cindex pipe, @code{target remote} to
22171Run @var{command} in the background and communicate with it using a
22172pipe.  The @var{command} is a shell command, to be parsed and expanded
22173by the system's command shell, @code{/bin/sh}; it should expect remote
22174protocol packets on its standard input, and send replies on its
22175standard output.  You could use this to run a stand-alone simulator
22176that speaks the remote debugging protocol, to make net connections
22177using programs like @code{ssh}, or for other similar tricks.
22178
22179If @var{command} closes its standard output (perhaps by exiting),
22180@value{GDBN} will try to send it a @code{SIGTERM} signal.  (If the
22181program has already exited, this will have no effect.)
22182
22183@end table
22184
22185@cindex interrupting remote programs
22186@cindex remote programs, interrupting
22187Whenever @value{GDBN} is waiting for the remote program, if you type the
22188interrupt character (often @kbd{Ctrl-c}), @value{GDBN} attempts to stop the
22189program.  This may or may not succeed, depending in part on the hardware
22190and the serial drivers the remote system uses.  If you type the
22191interrupt character once again, @value{GDBN} displays this prompt:
22192
22193@smallexample
22194Interrupted while waiting for the program.
22195Give up (and stop debugging it)?  (y or n)
22196@end smallexample
22197
22198In @code{target remote} mode, if you type @kbd{y}, @value{GDBN} abandons
22199the remote debugging session.  (If you decide you want to try again later,
22200you can use @kbd{target remote} again to connect once more.)  If you type
22201@kbd{n}, @value{GDBN} goes back to waiting.
22202
22203In @code{target extended-remote} mode, typing @kbd{n} will leave
22204@value{GDBN} connected to the target.
22205
22206@table @code
22207@kindex detach (remote)
22208@item detach
22209When you have finished debugging the remote program, you can use the
22210@code{detach} command to release it from @value{GDBN} control.
22211Detaching from the target normally resumes its execution, but the results
22212will depend on your particular remote stub.  After the @code{detach}
22213command in @code{target remote} mode, @value{GDBN} is free to connect to
22214another target.  In @code{target extended-remote} mode, @value{GDBN} is
22215still connected to the target.
22216
22217@kindex disconnect
22218@item disconnect
22219The @code{disconnect} command closes the connection to the target, and
22220the target is generally not resumed.  It will wait for @value{GDBN}
22221(this instance or another one) to connect and continue debugging.  After
22222the @code{disconnect} command, @value{GDBN} is again free to connect to
22223another target.
22224
22225@cindex send command to remote monitor
22226@cindex extend @value{GDBN} for remote targets
22227@cindex add new commands for external monitor
22228@kindex monitor
22229@item monitor @var{cmd}
22230This command allows you to send arbitrary commands directly to the
22231remote monitor.  Since @value{GDBN} doesn't care about the commands it
22232sends like this, this command is the way to extend @value{GDBN}---you
22233can add new commands that only the external monitor will understand
22234and implement.
22235@end table
22236
22237@node File Transfer
22238@section Sending files to a remote system
22239@cindex remote target, file transfer
22240@cindex file transfer
22241@cindex sending files to remote systems
22242
22243Some remote targets offer the ability to transfer files over the same
22244connection used to communicate with @value{GDBN}.  This is convenient
22245for targets accessible through other means, e.g.@: @sc{gnu}/Linux systems
22246running @code{gdbserver} over a network interface.  For other targets,
22247e.g.@: embedded devices with only a single serial port, this may be
22248the only way to upload or download files.
22249
22250Not all remote targets support these commands.
22251
22252@table @code
22253@kindex remote put
22254@item remote put @var{hostfile} @var{targetfile}
22255Copy file @var{hostfile} from the host system (the machine running
22256@value{GDBN}) to @var{targetfile} on the target system.
22257
22258@kindex remote get
22259@item remote get @var{targetfile} @var{hostfile}
22260Copy file @var{targetfile} from the target system to @var{hostfile}
22261on the host system.
22262
22263@kindex remote delete
22264@item remote delete @var{targetfile}
22265Delete @var{targetfile} from the target system.
22266
22267@end table
22268
22269@node Server
22270@section Using the @code{gdbserver} Program
22271
22272@kindex gdbserver
22273@cindex remote connection without stubs
22274@code{gdbserver} is a control program for Unix-like systems, which
22275allows you to connect your program with a remote @value{GDBN} via
22276@code{target remote} or @code{target extended-remote}---but without
22277linking in the usual debugging stub.
22278
22279@code{gdbserver} is not a complete replacement for the debugging stubs,
22280because it requires essentially the same operating-system facilities
22281that @value{GDBN} itself does.  In fact, a system that can run
22282@code{gdbserver} to connect to a remote @value{GDBN} could also run
22283@value{GDBN} locally!  @code{gdbserver} is sometimes useful nevertheless,
22284because it is a much smaller program than @value{GDBN} itself.  It is
22285also easier to port than all of @value{GDBN}, so you may be able to get
22286started more quickly on a new system by using @code{gdbserver}.
22287Finally, if you develop code for real-time systems, you may find that
22288the tradeoffs involved in real-time operation make it more convenient to
22289do as much development work as possible on another system, for example
22290by cross-compiling.  You can use @code{gdbserver} to make a similar
22291choice for debugging.
22292
22293@value{GDBN} and @code{gdbserver} communicate via either a serial line
22294or a TCP connection, using the standard @value{GDBN} remote serial
22295protocol.
22296
22297@quotation
22298@emph{Warning:} @code{gdbserver} does not have any built-in security.
22299Do not run @code{gdbserver} connected to any public network; a
22300@value{GDBN} connection to @code{gdbserver} provides access to the
22301target system with the same privileges as the user running
22302@code{gdbserver}.
22303@end quotation
22304
22305@anchor{Running gdbserver}
22306@subsection Running @code{gdbserver}
22307@cindex arguments, to @code{gdbserver}
22308@cindex @code{gdbserver}, command-line arguments
22309
22310Run @code{gdbserver} on the target system.  You need a copy of the
22311program you want to debug, including any libraries it requires.
22312@code{gdbserver} does not need your program's symbol table, so you can
22313strip the program if necessary to save space.  @value{GDBN} on the host
22314system does all the symbol handling.
22315
22316To use the server, you must tell it how to communicate with @value{GDBN};
22317the name of your program; and the arguments for your program.  The usual
22318syntax is:
22319
22320@smallexample
22321target> gdbserver @var{comm} @var{program} [ @var{args} @dots{} ]
22322@end smallexample
22323
22324@var{comm} is either a device name (to use a serial line), or a TCP
22325hostname and portnumber, or @code{-} or @code{stdio} to use
22326stdin/stdout of @code{gdbserver}.
22327For example, to debug Emacs with the argument
22328@samp{foo.txt} and communicate with @value{GDBN} over the serial port
22329@file{/dev/com1}:
22330
22331@smallexample
22332target> gdbserver /dev/com1 emacs foo.txt
22333@end smallexample
22334
22335@code{gdbserver} waits passively for the host @value{GDBN} to communicate
22336with it.
22337
22338To use a TCP connection instead of a serial line:
22339
22340@smallexample
22341target> gdbserver host:2345 emacs foo.txt
22342@end smallexample
22343
22344The only difference from the previous example is the first argument,
22345specifying that you are communicating with the host @value{GDBN} via
22346TCP.  The @samp{host:2345} argument means that @code{gdbserver} is to
22347expect a TCP connection from machine @samp{host} to local TCP port 2345.
22348(Currently, the @samp{host} part is ignored.)  You can choose any number
22349you want for the port number as long as it does not conflict with any
22350TCP ports already in use on the target system (for example, @code{23} is
22351reserved for @code{telnet}).@footnote{If you choose a port number that
22352conflicts with another service, @code{gdbserver} prints an error message
22353and exits.}  You must use the same port number with the host @value{GDBN}
22354@code{target remote} command.
22355
22356The @code{stdio} connection is useful when starting @code{gdbserver}
22357with ssh:
22358
22359@smallexample
22360(gdb) target remote | ssh -T hostname gdbserver - hello
22361@end smallexample
22362
22363The @samp{-T} option to ssh is provided because we don't need a remote pty,
22364and we don't want escape-character handling.  Ssh does this by default when
22365a command is provided, the flag is provided to make it explicit.
22366You could elide it if you want to.
22367
22368Programs started with stdio-connected gdbserver have @file{/dev/null} for
22369@code{stdin}, and @code{stdout},@code{stderr} are sent back to gdb for
22370display through a pipe connected to gdbserver.
22371Both @code{stdout} and @code{stderr} use the same pipe.
22372
22373@anchor{Attaching to a program}
22374@subsubsection Attaching to a Running Program
22375@cindex attach to a program, @code{gdbserver}
22376@cindex @option{--attach}, @code{gdbserver} option
22377
22378On some targets, @code{gdbserver} can also attach to running programs.
22379This is accomplished via the @code{--attach} argument.  The syntax is:
22380
22381@smallexample
22382target> gdbserver --attach @var{comm} @var{pid}
22383@end smallexample
22384
22385@var{pid} is the process ID of a currently running process.  It isn't
22386necessary to point @code{gdbserver} at a binary for the running process.
22387
22388In @code{target extended-remote} mode, you can also attach using the
22389@value{GDBN} attach command
22390(@pxref{Attaching in Types of Remote Connections}).
22391
22392@pindex pidof
22393You can debug processes by name instead of process ID if your target has the
22394@code{pidof} utility:
22395
22396@smallexample
22397target> gdbserver --attach @var{comm} `pidof @var{program}`
22398@end smallexample
22399
22400In case more than one copy of @var{program} is running, or @var{program}
22401has multiple threads, most versions of @code{pidof} support the
22402@code{-s} option to only return the first process ID.
22403
22404@subsubsection TCP port allocation lifecycle of @code{gdbserver}
22405
22406This section applies only when @code{gdbserver} is run to listen on a TCP
22407port.
22408
22409@code{gdbserver} normally terminates after all of its debugged processes have
22410terminated in @kbd{target remote} mode.  On the other hand, for @kbd{target
22411extended-remote}, @code{gdbserver} stays running even with no processes left.
22412@value{GDBN} normally terminates the spawned debugged process on its exit,
22413which normally also terminates @code{gdbserver} in the @kbd{target remote}
22414mode.  Therefore, when the connection drops unexpectedly, and @value{GDBN}
22415cannot ask @code{gdbserver} to kill its debugged processes, @code{gdbserver}
22416stays running even in the @kbd{target remote} mode.
22417
22418When @code{gdbserver} stays running, @value{GDBN} can connect to it again later.
22419Such reconnecting is useful for features like @ref{disconnected tracing}.  For
22420completeness, at most one @value{GDBN} can be connected at a time.
22421
22422@cindex @option{--once}, @code{gdbserver} option
22423By default, @code{gdbserver} keeps the listening TCP port open, so that
22424subsequent connections are possible.  However, if you start @code{gdbserver}
22425with the @option{--once} option, it will stop listening for any further
22426connection attempts after connecting to the first @value{GDBN} session.  This
22427means no further connections to @code{gdbserver} will be possible after the
22428first one.  It also means @code{gdbserver} will terminate after the first
22429connection with remote @value{GDBN} has closed, even for unexpectedly closed
22430connections and even in the @kbd{target extended-remote} mode.  The
22431@option{--once} option allows reusing the same port number for connecting to
22432multiple instances of @code{gdbserver} running on the same host, since each
22433instance closes its port after the first connection.
22434
22435@anchor{Other Command-Line Arguments for gdbserver}
22436@subsubsection Other Command-Line Arguments for @code{gdbserver}
22437
22438You can use the @option{--multi} option to start @code{gdbserver} without
22439specifying a program to debug or a process to attach to.  Then you can
22440attach in @code{target extended-remote} mode and run or attach to a
22441program.  For more information,
22442@pxref{--multi Option in Types of Remote Connnections}.
22443
22444@cindex @option{--debug}, @code{gdbserver} option
22445The @option{--debug} option tells @code{gdbserver} to display extra
22446status information about the debugging process.
22447@cindex @option{--remote-debug}, @code{gdbserver} option
22448The @option{--remote-debug} option tells @code{gdbserver} to display
22449remote protocol debug output.
22450@cindex @option{--debug-file}, @code{gdbserver} option
22451@cindex @code{gdbserver}, send all debug output to a single file
22452The @option{--debug-file=@var{filename}} option tells @code{gdbserver} to
22453write any debug output to the given @var{filename}.  These options are intended
22454for @code{gdbserver} development and for bug reports to the developers.
22455
22456@cindex @option{--debug-format}, @code{gdbserver} option
22457The @option{--debug-format=option1[,option2,...]} option tells
22458@code{gdbserver} to include additional information in each output.
22459Possible options are:
22460
22461@table @code
22462@item none
22463Turn off all extra information in debugging output.
22464@item all
22465Turn on all extra information in debugging output.
22466@item timestamps
22467Include a timestamp in each line of debugging output.
22468@end table
22469
22470Options are processed in order.  Thus, for example, if @option{none}
22471appears last then no additional information is added to debugging output.
22472
22473@cindex @option{--wrapper}, @code{gdbserver} option
22474The @option{--wrapper} option specifies a wrapper to launch programs
22475for debugging.  The option should be followed by the name of the
22476wrapper, then any command-line arguments to pass to the wrapper, then
22477@kbd{--} indicating the end of the wrapper arguments.
22478
22479@code{gdbserver} runs the specified wrapper program with a combined
22480command line including the wrapper arguments, then the name of the
22481program to debug, then any arguments to the program.  The wrapper
22482runs until it executes your program, and then @value{GDBN} gains control.
22483
22484You can use any program that eventually calls @code{execve} with
22485its arguments as a wrapper.  Several standard Unix utilities do
22486this, e.g.@: @code{env} and @code{nohup}.  Any Unix shell script ending
22487with @code{exec "$@@"} will also work.
22488
22489For example, you can use @code{env} to pass an environment variable to
22490the debugged program, without setting the variable in @code{gdbserver}'s
22491environment:
22492
22493@smallexample
22494$ gdbserver --wrapper env LD_PRELOAD=libtest.so -- :2222 ./testprog
22495@end smallexample
22496
22497@cindex @option{--selftest}
22498The @option{--selftest} option runs the self tests in @code{gdbserver}:
22499
22500@smallexample
22501$ gdbserver --selftest
22502Ran 2 unit tests, 0 failed
22503@end smallexample
22504
22505These tests are disabled in release.
22506@subsection Connecting to @code{gdbserver}
22507
22508The basic procedure for connecting to the remote target is:
22509@itemize
22510
22511@item
22512Run @value{GDBN} on the host system.
22513
22514@item
22515Make sure you have the necessary symbol files
22516(@pxref{Host and target files}).
22517Load symbols for your application using the @code{file} command before you
22518connect.  Use @code{set sysroot} to locate target libraries (unless your
22519@value{GDBN} was compiled with the correct sysroot using
22520@code{--with-sysroot}).
22521
22522@item
22523Connect to your target (@pxref{Connecting,,Connecting to a Remote Target}).
22524For TCP connections, you must start up @code{gdbserver} prior to using
22525the @code{target} command.  Otherwise you may get an error whose
22526text depends on the host system, but which usually looks something like
22527@samp{Connection refused}.  Don't use the @code{load}
22528command in @value{GDBN} when using @code{target remote} mode, since the
22529program is already on the target.
22530
22531@end itemize
22532
22533@anchor{Monitor Commands for gdbserver}
22534@subsection Monitor Commands for @code{gdbserver}
22535@cindex monitor commands, for @code{gdbserver}
22536
22537During a @value{GDBN} session using @code{gdbserver}, you can use the
22538@code{monitor} command to send special requests to @code{gdbserver}.
22539Here are the available commands.
22540
22541@table @code
22542@item monitor help
22543List the available monitor commands.
22544
22545@item monitor set debug 0
22546@itemx monitor set debug 1
22547Disable or enable general debugging messages.
22548
22549@item monitor set remote-debug 0
22550@itemx monitor set remote-debug 1
22551Disable or enable specific debugging messages associated with the remote
22552protocol (@pxref{Remote Protocol}).
22553
22554@item monitor set debug-file filename
22555@itemx monitor set debug-file
22556Send any debug output to the given file, or to stderr.
22557
22558@item monitor set debug-format option1@r{[},option2,...@r{]}
22559Specify additional text to add to debugging messages.
22560Possible options are:
22561
22562@table @code
22563@item none
22564Turn off all extra information in debugging output.
22565@item all
22566Turn on all extra information in debugging output.
22567@item timestamps
22568Include a timestamp in each line of debugging output.
22569@end table
22570
22571Options are processed in order.  Thus, for example, if @option{none}
22572appears last then no additional information is added to debugging output.
22573
22574@item monitor set libthread-db-search-path [PATH]
22575@cindex gdbserver, search path for @code{libthread_db}
22576When this command is issued, @var{path} is a colon-separated list of
22577directories to search for @code{libthread_db} (@pxref{Threads,,set
22578libthread-db-search-path}).  If you omit @var{path},
22579@samp{libthread-db-search-path} will be reset to its default value.
22580
22581The special entry @samp{$pdir} for @samp{libthread-db-search-path} is
22582not supported in @code{gdbserver}.
22583
22584@item monitor exit
22585Tell gdbserver to exit immediately.  This command should be followed by
22586@code{disconnect} to close the debugging session.  @code{gdbserver} will
22587detach from any attached processes and kill any processes it created.
22588Use @code{monitor exit} to terminate @code{gdbserver} at the end
22589of a multi-process mode debug session.
22590
22591@end table
22592
22593@subsection Tracepoints support in @code{gdbserver}
22594@cindex tracepoints support in @code{gdbserver}
22595
22596On some targets, @code{gdbserver} supports tracepoints, fast
22597tracepoints and static tracepoints.
22598
22599For fast or static tracepoints to work, a special library called the
22600@dfn{in-process agent} (IPA), must be loaded in the inferior process.
22601This library is built and distributed as an integral part of
22602@code{gdbserver}.  In addition, support for static tracepoints
22603requires building the in-process agent library with static tracepoints
22604support.  At present, the UST (LTTng Userspace Tracer,
22605@url{http://lttng.org/ust}) tracing engine is supported.  This support
22606is automatically available if UST development headers are found in the
22607standard include path when @code{gdbserver} is built, or if
22608@code{gdbserver} was explicitly configured using @option{--with-ust}
22609to point at such headers.  You can explicitly disable the support
22610using @option{--with-ust=no}.
22611
22612There are several ways to load the in-process agent in your program:
22613
22614@table @code
22615@item Specifying it as dependency at link time
22616
22617You can link your program dynamically with the in-process agent
22618library.  On most systems, this is accomplished by adding
22619@code{-linproctrace} to the link command.
22620
22621@item Using the system's preloading mechanisms
22622
22623You can force loading the in-process agent at startup time by using
22624your system's support for preloading shared libraries.  Many Unixes
22625support the concept of preloading user defined libraries.  In most
22626cases, you do that by specifying @code{LD_PRELOAD=libinproctrace.so}
22627in the environment.  See also the description of @code{gdbserver}'s
22628@option{--wrapper} command line option.
22629
22630@item Using @value{GDBN} to force loading the agent at run time
22631
22632On some systems, you can force the inferior to load a shared library,
22633by calling a dynamic loader function in the inferior that takes care
22634of dynamically looking up and loading a shared library.  On most Unix
22635systems, the function is @code{dlopen}.  You'll use the @code{call}
22636command for that.  For example:
22637
22638@smallexample
22639(@value{GDBP}) call dlopen ("libinproctrace.so", ...)
22640@end smallexample
22641
22642Note that on most Unix systems, for the @code{dlopen} function to be
22643available, the program needs to be linked with @code{-ldl}.
22644@end table
22645
22646On systems that have a userspace dynamic loader, like most Unix
22647systems, when you connect to @code{gdbserver} using @code{target
22648remote}, you'll find that the program is stopped at the dynamic
22649loader's entry point, and no shared library has been loaded in the
22650program's address space yet, including the in-process agent.  In that
22651case, before being able to use any of the fast or static tracepoints
22652features, you need to let the loader run and load the shared
22653libraries.  The simplest way to do that is to run the program to the
22654main procedure.  E.g., if debugging a C or C@t{++} program, start
22655@code{gdbserver} like so:
22656
22657@smallexample
22658$ gdbserver :9999 myprogram
22659@end smallexample
22660
22661Start GDB and connect to @code{gdbserver} like so, and run to main:
22662
22663@smallexample
22664$ gdb myprogram
22665(@value{GDBP}) target remote myhost:9999
226660x00007f215893ba60 in ?? () from /lib64/ld-linux-x86-64.so.2
22667(@value{GDBP}) b main
22668(@value{GDBP}) continue
22669@end smallexample
22670
22671The in-process tracing agent library should now be loaded into the
22672process; you can confirm it with the @code{info sharedlibrary}
22673command, which will list @file{libinproctrace.so} as loaded in the
22674process.  You are now ready to install fast tracepoints, list static
22675tracepoint markers, probe static tracepoints markers, and start
22676tracing.
22677
22678@node Remote Configuration
22679@section Remote Configuration
22680
22681@kindex set remote
22682@kindex show remote
22683This section documents the configuration options available when
22684debugging remote programs.  For the options related to the File I/O
22685extensions of the remote protocol, see @ref{system,
22686system-call-allowed}.
22687
22688@table @code
22689@item set remoteaddresssize @var{bits}
22690@cindex address size for remote targets
22691@cindex bits in remote address
22692Set the maximum size of address in a memory packet to the specified
22693number of bits.  @value{GDBN} will mask off the address bits above
22694that number, when it passes addresses to the remote target.  The
22695default value is the number of bits in the target's address.
22696
22697@item show remoteaddresssize
22698Show the current value of remote address size in bits.
22699
22700@item set serial baud @var{n}
22701@cindex baud rate for remote targets
22702Set the baud rate for the remote serial I/O to @var{n} baud.  The
22703value is used to set the speed of the serial port used for debugging
22704remote targets.
22705
22706@item show serial baud
22707Show the current speed of the remote connection.
22708
22709@item set serial parity @var{parity}
22710Set the parity for the remote serial I/O.  Supported values of @var{parity} are:
22711@code{even}, @code{none}, and @code{odd}.  The default is @code{none}.
22712
22713@item show serial parity
22714Show the current parity of the serial port.
22715
22716@item set remotebreak
22717@cindex interrupt remote programs
22718@cindex BREAK signal instead of Ctrl-C
22719@anchor{set remotebreak}
22720If set to on, @value{GDBN} sends a @code{BREAK} signal to the remote
22721when you type @kbd{Ctrl-c} to interrupt the program running
22722on the remote.  If set to off, @value{GDBN} sends the @samp{Ctrl-C}
22723character instead.  The default is off, since most remote systems
22724expect to see @samp{Ctrl-C} as the interrupt signal.
22725
22726@item show remotebreak
22727Show whether @value{GDBN} sends @code{BREAK} or @samp{Ctrl-C} to
22728interrupt the remote program.
22729
22730@item set remoteflow on
22731@itemx set remoteflow off
22732@kindex set remoteflow
22733Enable or disable hardware flow control (@code{RTS}/@code{CTS})
22734on the serial port used to communicate to the remote target.
22735
22736@item show remoteflow
22737@kindex show remoteflow
22738Show the current setting of hardware flow control.
22739
22740@item set remotelogbase @var{base}
22741Set the base (a.k.a.@: radix) of logging serial protocol
22742communications to @var{base}.  Supported values of @var{base} are:
22743@code{ascii}, @code{octal}, and @code{hex}.  The default is
22744@code{ascii}.
22745
22746@item show remotelogbase
22747Show the current setting of the radix for logging remote serial
22748protocol.
22749
22750@item set remotelogfile @var{file}
22751@cindex record serial communications on file
22752Record remote serial communications on the named @var{file}.  The
22753default is not to record at all.
22754
22755@item show remotelogfile
22756Show the current setting  of the file name on which to record the
22757serial communications.
22758
22759@item set remotetimeout @var{num}
22760@cindex timeout for serial communications
22761@cindex remote timeout
22762Set the timeout limit to wait for the remote target to respond to
22763@var{num} seconds.  The default is 2 seconds.
22764
22765@item show remotetimeout
22766Show the current number of seconds to wait for the remote target
22767responses.
22768
22769@cindex limit hardware breakpoints and watchpoints
22770@cindex remote target, limit break- and watchpoints
22771@anchor{set remote hardware-watchpoint-limit}
22772@anchor{set remote hardware-breakpoint-limit}
22773@item set remote hardware-watchpoint-limit @var{limit}
22774@itemx set remote hardware-breakpoint-limit @var{limit}
22775Restrict @value{GDBN} to using @var{limit} remote hardware watchpoints
22776or breakpoints.  The @var{limit} can be set to 0 to disable hardware
22777watchpoints or breakpoints, and @code{unlimited} for unlimited
22778watchpoints or breakpoints.
22779
22780@item show remote hardware-watchpoint-limit
22781@itemx show remote hardware-breakpoint-limit
22782Show the current limit for the number of hardware watchpoints or
22783breakpoints that @value{GDBN} can use.
22784
22785@cindex limit hardware watchpoints length
22786@cindex remote target, limit watchpoints length
22787@anchor{set remote hardware-watchpoint-length-limit}
22788@item set remote hardware-watchpoint-length-limit @var{limit}
22789Restrict @value{GDBN} to using @var{limit} bytes for the maximum
22790length of a remote hardware watchpoint.  A @var{limit} of 0 disables
22791hardware watchpoints and @code{unlimited} allows watchpoints of any
22792length.
22793
22794@item show remote hardware-watchpoint-length-limit
22795Show the current limit (in bytes) of the maximum length of
22796a remote hardware watchpoint.
22797
22798@item set remote exec-file @var{filename}
22799@itemx show remote exec-file
22800@anchor{set remote exec-file}
22801@cindex executable file, for remote target
22802Select the file used for @code{run} with @code{target
22803extended-remote}.  This should be set to a filename valid on the
22804target system.  If it is not set, the target will use a default
22805filename (e.g.@: the last program run).
22806
22807@item set remote interrupt-sequence
22808@cindex interrupt remote programs
22809@cindex select Ctrl-C, BREAK or BREAK-g
22810Allow the user to select one of @samp{Ctrl-C}, a @code{BREAK} or
22811@samp{BREAK-g} as the
22812sequence to the remote target in order to interrupt the execution.
22813@samp{Ctrl-C} is a default.  Some system prefers @code{BREAK} which
22814is high level of serial line for some certain time.
22815Linux kernel prefers @samp{BREAK-g}, a.k.a Magic SysRq g.
22816It is @code{BREAK} signal followed by character @code{g}.
22817
22818@item show interrupt-sequence
22819Show which of @samp{Ctrl-C}, @code{BREAK} or @code{BREAK-g}
22820is sent by @value{GDBN} to interrupt the remote program.
22821@code{BREAK-g} is BREAK signal followed by @code{g} and
22822also known as Magic SysRq g.
22823
22824@item set remote interrupt-on-connect
22825@cindex send interrupt-sequence on start
22826Specify whether interrupt-sequence is sent to remote target when
22827@value{GDBN} connects to it.  This is mostly needed when you debug
22828Linux kernel.  Linux kernel expects @code{BREAK} followed by @code{g}
22829which is known as Magic SysRq g in order to connect @value{GDBN}.
22830
22831@item show interrupt-on-connect
22832Show whether interrupt-sequence is sent
22833to remote target when @value{GDBN} connects to it.
22834
22835@kindex set tcp
22836@kindex show tcp
22837@item set tcp auto-retry on
22838@cindex auto-retry, for remote TCP target
22839Enable auto-retry for remote TCP connections.  This is useful if the remote
22840debugging agent is launched in parallel with @value{GDBN}; there is a race
22841condition because the agent may not become ready to accept the connection
22842before @value{GDBN} attempts to connect.  When auto-retry is
22843enabled, if the initial attempt to connect fails, @value{GDBN} reattempts
22844to establish the connection using the timeout specified by
22845@code{set tcp connect-timeout}.
22846
22847@item set tcp auto-retry off
22848Do not auto-retry failed TCP connections.
22849
22850@item show tcp auto-retry
22851Show the current auto-retry setting.
22852
22853@item set tcp connect-timeout @var{seconds}
22854@itemx set tcp connect-timeout unlimited
22855@cindex connection timeout, for remote TCP target
22856@cindex timeout, for remote target connection
22857Set the timeout for establishing a TCP connection to the remote target to
22858@var{seconds}.  The timeout affects both polling to retry failed connections
22859(enabled by @code{set tcp auto-retry on}) and waiting for connections
22860that are merely slow to complete, and represents an approximate cumulative
22861value.  If @var{seconds} is @code{unlimited}, there is no timeout and
22862@value{GDBN} will keep attempting to establish a connection forever,
22863unless interrupted with @kbd{Ctrl-c}.  The default is 15 seconds.
22864
22865@item show tcp connect-timeout
22866Show the current connection timeout setting.
22867@end table
22868
22869@cindex remote packets, enabling and disabling
22870The @value{GDBN} remote protocol autodetects the packets supported by
22871your debugging stub.  If you need to override the autodetection, you
22872can use these commands to enable or disable individual packets.  Each
22873packet can be set to @samp{on} (the remote target supports this
22874packet), @samp{off} (the remote target does not support this packet),
22875or @samp{auto} (detect remote target support for this packet).  They
22876all default to @samp{auto}.  For more information about each packet,
22877see @ref{Remote Protocol}.
22878
22879During normal use, you should not have to use any of these commands.
22880If you do, that may be a bug in your remote debugging stub, or a bug
22881in @value{GDBN}.  You may want to report the problem to the
22882@value{GDBN} developers.
22883
22884For each packet @var{name}, the command to enable or disable the
22885packet is @code{set remote @var{name}-packet}.  The available settings
22886are:
22887
22888@multitable @columnfractions 0.28 0.32 0.25
22889@item Command Name
22890@tab Remote Packet
22891@tab Related Features
22892
22893@item @code{fetch-register}
22894@tab @code{p}
22895@tab @code{info registers}
22896
22897@item @code{set-register}
22898@tab @code{P}
22899@tab @code{set}
22900
22901@item @code{binary-download}
22902@tab @code{X}
22903@tab @code{load}, @code{set}
22904
22905@item @code{read-aux-vector}
22906@tab @code{qXfer:auxv:read}
22907@tab @code{info auxv}
22908
22909@item @code{symbol-lookup}
22910@tab @code{qSymbol}
22911@tab Detecting multiple threads
22912
22913@item @code{attach}
22914@tab @code{vAttach}
22915@tab @code{attach}
22916
22917@item @code{verbose-resume}
22918@tab @code{vCont}
22919@tab Stepping or resuming multiple threads
22920
22921@item @code{run}
22922@tab @code{vRun}
22923@tab @code{run}
22924
22925@item @code{software-breakpoint}
22926@tab @code{Z0}
22927@tab @code{break}
22928
22929@item @code{hardware-breakpoint}
22930@tab @code{Z1}
22931@tab @code{hbreak}
22932
22933@item @code{write-watchpoint}
22934@tab @code{Z2}
22935@tab @code{watch}
22936
22937@item @code{read-watchpoint}
22938@tab @code{Z3}
22939@tab @code{rwatch}
22940
22941@item @code{access-watchpoint}
22942@tab @code{Z4}
22943@tab @code{awatch}
22944
22945@item @code{pid-to-exec-file}
22946@tab @code{qXfer:exec-file:read}
22947@tab @code{attach}, @code{run}
22948
22949@item @code{target-features}
22950@tab @code{qXfer:features:read}
22951@tab @code{set architecture}
22952
22953@item @code{library-info}
22954@tab @code{qXfer:libraries:read}
22955@tab @code{info sharedlibrary}
22956
22957@item @code{memory-map}
22958@tab @code{qXfer:memory-map:read}
22959@tab @code{info mem}
22960
22961@item @code{read-sdata-object}
22962@tab @code{qXfer:sdata:read}
22963@tab @code{print $_sdata}
22964
22965@item @code{read-siginfo-object}
22966@tab @code{qXfer:siginfo:read}
22967@tab @code{print $_siginfo}
22968
22969@item @code{write-siginfo-object}
22970@tab @code{qXfer:siginfo:write}
22971@tab @code{set $_siginfo}
22972
22973@item @code{threads}
22974@tab @code{qXfer:threads:read}
22975@tab @code{info threads}
22976
22977@item @code{get-thread-local-@*storage-address}
22978@tab @code{qGetTLSAddr}
22979@tab Displaying @code{__thread} variables
22980
22981@item @code{get-thread-information-block-address}
22982@tab @code{qGetTIBAddr}
22983@tab Display MS-Windows Thread Information Block.
22984
22985@item @code{search-memory}
22986@tab @code{qSearch:memory}
22987@tab @code{find}
22988
22989@item @code{supported-packets}
22990@tab @code{qSupported}
22991@tab Remote communications parameters
22992
22993@item @code{catch-syscalls}
22994@tab @code{QCatchSyscalls}
22995@tab @code{catch syscall}
22996
22997@item @code{pass-signals}
22998@tab @code{QPassSignals}
22999@tab @code{handle @var{signal}}
23000
23001@item @code{program-signals}
23002@tab @code{QProgramSignals}
23003@tab @code{handle @var{signal}}
23004
23005@item @code{hostio-close-packet}
23006@tab @code{vFile:close}
23007@tab @code{remote get}, @code{remote put}
23008
23009@item @code{hostio-open-packet}
23010@tab @code{vFile:open}
23011@tab @code{remote get}, @code{remote put}
23012
23013@item @code{hostio-pread-packet}
23014@tab @code{vFile:pread}
23015@tab @code{remote get}, @code{remote put}
23016
23017@item @code{hostio-pwrite-packet}
23018@tab @code{vFile:pwrite}
23019@tab @code{remote get}, @code{remote put}
23020
23021@item @code{hostio-unlink-packet}
23022@tab @code{vFile:unlink}
23023@tab @code{remote delete}
23024
23025@item @code{hostio-readlink-packet}
23026@tab @code{vFile:readlink}
23027@tab Host I/O
23028
23029@item @code{hostio-fstat-packet}
23030@tab @code{vFile:fstat}
23031@tab Host I/O
23032
23033@item @code{hostio-setfs-packet}
23034@tab @code{vFile:setfs}
23035@tab Host I/O
23036
23037@item @code{noack-packet}
23038@tab @code{QStartNoAckMode}
23039@tab Packet acknowledgment
23040
23041@item @code{osdata}
23042@tab @code{qXfer:osdata:read}
23043@tab @code{info os}
23044
23045@item @code{query-attached}
23046@tab @code{qAttached}
23047@tab Querying remote process attach state.
23048
23049@item @code{trace-buffer-size}
23050@tab @code{QTBuffer:size}
23051@tab @code{set trace-buffer-size}
23052
23053@item @code{trace-status}
23054@tab @code{qTStatus}
23055@tab @code{tstatus}
23056
23057@item @code{traceframe-info}
23058@tab @code{qXfer:traceframe-info:read}
23059@tab Traceframe info
23060
23061@item @code{install-in-trace}
23062@tab @code{InstallInTrace}
23063@tab Install tracepoint in tracing
23064
23065@item @code{disable-randomization}
23066@tab @code{QDisableRandomization}
23067@tab @code{set disable-randomization}
23068
23069@item @code{startup-with-shell}
23070@tab @code{QStartupWithShell}
23071@tab @code{set startup-with-shell}
23072
23073@item @code{environment-hex-encoded}
23074@tab @code{QEnvironmentHexEncoded}
23075@tab @code{set environment}
23076
23077@item @code{environment-unset}
23078@tab @code{QEnvironmentUnset}
23079@tab @code{unset environment}
23080
23081@item @code{environment-reset}
23082@tab @code{QEnvironmentReset}
23083@tab @code{Reset the inferior environment (i.e., unset user-set variables)}
23084
23085@item @code{set-working-dir}
23086@tab @code{QSetWorkingDir}
23087@tab @code{set cwd}
23088
23089@item @code{conditional-breakpoints-packet}
23090@tab @code{Z0 and Z1}
23091@tab @code{Support for target-side breakpoint condition evaluation}
23092
23093@item @code{multiprocess-extensions}
23094@tab @code{multiprocess extensions}
23095@tab Debug multiple processes and remote process PID awareness
23096
23097@item @code{swbreak-feature}
23098@tab @code{swbreak stop reason}
23099@tab @code{break}
23100
23101@item @code{hwbreak-feature}
23102@tab @code{hwbreak stop reason}
23103@tab @code{hbreak}
23104
23105@item @code{fork-event-feature}
23106@tab @code{fork stop reason}
23107@tab @code{fork}
23108
23109@item @code{vfork-event-feature}
23110@tab @code{vfork stop reason}
23111@tab @code{vfork}
23112
23113@item @code{exec-event-feature}
23114@tab @code{exec stop reason}
23115@tab @code{exec}
23116
23117@item @code{thread-events}
23118@tab @code{QThreadEvents}
23119@tab Tracking thread lifetime.
23120
23121@item @code{no-resumed-stop-reply}
23122@tab @code{no resumed thread left stop reply}
23123@tab Tracking thread lifetime.
23124
23125@end multitable
23126
23127@node Remote Stub
23128@section Implementing a Remote Stub
23129
23130@cindex debugging stub, example
23131@cindex remote stub, example
23132@cindex stub example, remote debugging
23133The stub files provided with @value{GDBN} implement the target side of the
23134communication protocol, and the @value{GDBN} side is implemented in the
23135@value{GDBN} source file @file{remote.c}.  Normally, you can simply allow
23136these subroutines to communicate, and ignore the details.  (If you're
23137implementing your own stub file, you can still ignore the details: start
23138with one of the existing stub files.  @file{sparc-stub.c} is the best
23139organized, and therefore the easiest to read.)
23140
23141@cindex remote serial debugging, overview
23142To debug a program running on another machine (the debugging
23143@dfn{target} machine), you must first arrange for all the usual
23144prerequisites for the program to run by itself.  For example, for a C
23145program, you need:
23146
23147@enumerate
23148@item
23149A startup routine to set up the C runtime environment; these usually
23150have a name like @file{crt0}.  The startup routine may be supplied by
23151your hardware supplier, or you may have to write your own.
23152
23153@item
23154A C subroutine library to support your program's
23155subroutine calls, notably managing input and output.
23156
23157@item
23158A way of getting your program to the other machine---for example, a
23159download program.  These are often supplied by the hardware
23160manufacturer, but you may have to write your own from hardware
23161documentation.
23162@end enumerate
23163
23164The next step is to arrange for your program to use a serial port to
23165communicate with the machine where @value{GDBN} is running (the @dfn{host}
23166machine).  In general terms, the scheme looks like this:
23167
23168@table @emph
23169@item On the host,
23170@value{GDBN} already understands how to use this protocol; when everything
23171else is set up, you can simply use the @samp{target remote} command
23172(@pxref{Targets,,Specifying a Debugging Target}).
23173
23174@item On the target,
23175you must link with your program a few special-purpose subroutines that
23176implement the @value{GDBN} remote serial protocol.  The file containing these
23177subroutines is called  a @dfn{debugging stub}.
23178
23179On certain remote targets, you can use an auxiliary program
23180@code{gdbserver} instead of linking a stub into your program.
23181@xref{Server,,Using the @code{gdbserver} Program}, for details.
23182@end table
23183
23184The debugging stub is specific to the architecture of the remote
23185machine; for example, use @file{sparc-stub.c} to debug programs on
23186@sc{sparc} boards.
23187
23188@cindex remote serial stub list
23189These working remote stubs are distributed with @value{GDBN}:
23190
23191@table @code
23192
23193@item i386-stub.c
23194@cindex @file{i386-stub.c}
23195@cindex Intel
23196@cindex i386
23197For Intel 386 and compatible architectures.
23198
23199@item m68k-stub.c
23200@cindex @file{m68k-stub.c}
23201@cindex Motorola 680x0
23202@cindex m680x0
23203For Motorola 680x0 architectures.
23204
23205@item sh-stub.c
23206@cindex @file{sh-stub.c}
23207@cindex Renesas
23208@cindex SH
23209For Renesas SH architectures.
23210
23211@item sparc-stub.c
23212@cindex @file{sparc-stub.c}
23213@cindex Sparc
23214For @sc{sparc} architectures.
23215
23216@item sparcl-stub.c
23217@cindex @file{sparcl-stub.c}
23218@cindex Fujitsu
23219@cindex SparcLite
23220For Fujitsu @sc{sparclite} architectures.
23221
23222@end table
23223
23224The @file{README} file in the @value{GDBN} distribution may list other
23225recently added stubs.
23226
23227@menu
23228* Stub Contents::       What the stub can do for you
23229* Bootstrapping::       What you must do for the stub
23230* Debug Session::       Putting it all together
23231@end menu
23232
23233@node Stub Contents
23234@subsection What the Stub Can Do for You
23235
23236@cindex remote serial stub
23237The debugging stub for your architecture supplies these three
23238subroutines:
23239
23240@table @code
23241@item set_debug_traps
23242@findex set_debug_traps
23243@cindex remote serial stub, initialization
23244This routine arranges for @code{handle_exception} to run when your
23245program stops.  You must call this subroutine explicitly in your
23246program's startup code.
23247
23248@item handle_exception
23249@findex handle_exception
23250@cindex remote serial stub, main routine
23251This is the central workhorse, but your program never calls it
23252explicitly---the setup code arranges for @code{handle_exception} to
23253run when a trap is triggered.
23254
23255@code{handle_exception} takes control when your program stops during
23256execution (for example, on a breakpoint), and mediates communications
23257with @value{GDBN} on the host machine.  This is where the communications
23258protocol is implemented; @code{handle_exception} acts as the @value{GDBN}
23259representative on the target machine.  It begins by sending summary
23260information on the state of your program, then continues to execute,
23261retrieving and transmitting any information @value{GDBN} needs, until you
23262execute a @value{GDBN} command that makes your program resume; at that point,
23263@code{handle_exception} returns control to your own code on the target
23264machine.
23265
23266@item breakpoint
23267@cindex @code{breakpoint} subroutine, remote
23268Use this auxiliary subroutine to make your program contain a
23269breakpoint.  Depending on the particular situation, this may be the only
23270way for @value{GDBN} to get control.  For instance, if your target
23271machine has some sort of interrupt button, you won't need to call this;
23272pressing the interrupt button transfers control to
23273@code{handle_exception}---in effect, to @value{GDBN}.  On some machines,
23274simply receiving characters on the serial port may also trigger a trap;
23275again, in that situation, you don't need to call @code{breakpoint} from
23276your own program---simply running @samp{target remote} from the host
23277@value{GDBN} session gets control.
23278
23279Call @code{breakpoint} if none of these is true, or if you simply want
23280to make certain your program stops at a predetermined point for the
23281start of your debugging session.
23282@end table
23283
23284@node Bootstrapping
23285@subsection What You Must Do for the Stub
23286
23287@cindex remote stub, support routines
23288The debugging stubs that come with @value{GDBN} are set up for a particular
23289chip architecture, but they have no information about the rest of your
23290debugging target machine.
23291
23292First of all you need to tell the stub how to communicate with the
23293serial port.
23294
23295@table @code
23296@item int getDebugChar()
23297@findex getDebugChar
23298Write this subroutine to read a single character from the serial port.
23299It may be identical to @code{getchar} for your target system; a
23300different name is used to allow you to distinguish the two if you wish.
23301
23302@item void putDebugChar(int)
23303@findex putDebugChar
23304Write this subroutine to write a single character to the serial port.
23305It may be identical to @code{putchar} for your target system; a
23306different name is used to allow you to distinguish the two if you wish.
23307@end table
23308
23309@cindex control C, and remote debugging
23310@cindex interrupting remote targets
23311If you want @value{GDBN} to be able to stop your program while it is
23312running, you need to use an interrupt-driven serial driver, and arrange
23313for it to stop when it receives a @code{^C} (@samp{\003}, the control-C
23314character).  That is the character which @value{GDBN} uses to tell the
23315remote system to stop.
23316
23317Getting the debugging target to return the proper status to @value{GDBN}
23318probably requires changes to the standard stub; one quick and dirty way
23319is to just execute a breakpoint instruction (the ``dirty'' part is that
23320@value{GDBN} reports a @code{SIGTRAP} instead of a @code{SIGINT}).
23321
23322Other routines you need to supply are:
23323
23324@table @code
23325@item void exceptionHandler (int @var{exception_number}, void *@var{exception_address})
23326@findex exceptionHandler
23327Write this function to install @var{exception_address} in the exception
23328handling tables.  You need to do this because the stub does not have any
23329way of knowing what the exception handling tables on your target system
23330are like (for example, the processor's table might be in @sc{rom},
23331containing entries which point to a table in @sc{ram}).
23332The @var{exception_number} specifies the exception which should be changed;
23333its meaning is architecture-dependent (for example, different numbers
23334might represent divide by zero, misaligned access, etc).  When this
23335exception occurs, control should be transferred directly to
23336@var{exception_address}, and the processor state (stack, registers,
23337and so on) should be just as it is when a processor exception occurs.  So if
23338you want to use a jump instruction to reach @var{exception_address}, it
23339should be a simple jump, not a jump to subroutine.
23340
23341For the 386, @var{exception_address} should be installed as an interrupt
23342gate so that interrupts are masked while the handler runs.  The gate
23343should be at privilege level 0 (the most privileged level).  The
23344@sc{sparc} and 68k stubs are able to mask interrupts themselves without
23345help from @code{exceptionHandler}.
23346
23347@item void flush_i_cache()
23348@findex flush_i_cache
23349On @sc{sparc} and @sc{sparclite} only, write this subroutine to flush the
23350instruction cache, if any, on your target machine.  If there is no
23351instruction cache, this subroutine may be a no-op.
23352
23353On target machines that have instruction caches, @value{GDBN} requires this
23354function to make certain that the state of your program is stable.
23355@end table
23356
23357@noindent
23358You must also make sure this library routine is available:
23359
23360@table @code
23361@item void *memset(void *, int, int)
23362@findex memset
23363This is the standard library function @code{memset} that sets an area of
23364memory to a known value.  If you have one of the free versions of
23365@code{libc.a}, @code{memset} can be found there; otherwise, you must
23366either obtain it from your hardware manufacturer, or write your own.
23367@end table
23368
23369If you do not use the GNU C compiler, you may need other standard
23370library subroutines as well; this varies from one stub to another,
23371but in general the stubs are likely to use any of the common library
23372subroutines which @code{@value{NGCC}} generates as inline code.
23373
23374
23375@node Debug Session
23376@subsection Putting it All Together
23377
23378@cindex remote serial debugging summary
23379In summary, when your program is ready to debug, you must follow these
23380steps.
23381
23382@enumerate
23383@item
23384Make sure you have defined the supporting low-level routines
23385(@pxref{Bootstrapping,,What You Must Do for the Stub}):
23386@display
23387@code{getDebugChar}, @code{putDebugChar},
23388@code{flush_i_cache}, @code{memset}, @code{exceptionHandler}.
23389@end display
23390
23391@item
23392Insert these lines in your program's startup code, before the main
23393procedure is called:
23394
23395@smallexample
23396set_debug_traps();
23397breakpoint();
23398@end smallexample
23399
23400On some machines, when a breakpoint trap is raised, the hardware
23401automatically makes the PC point to the instruction after the
23402breakpoint.  If your machine doesn't do that, you may need to adjust
23403@code{handle_exception} to arrange for it to return to the instruction
23404after the breakpoint on this first invocation, so that your program
23405doesn't keep hitting the initial breakpoint instead of making
23406progress.
23407
23408@item
23409For the 680x0 stub only, you need to provide a variable called
23410@code{exceptionHook}.  Normally you just use:
23411
23412@smallexample
23413void (*exceptionHook)() = 0;
23414@end smallexample
23415
23416@noindent
23417but if before calling @code{set_debug_traps}, you set it to point to a
23418function in your program, that function is called when
23419@code{@value{GDBN}} continues after stopping on a trap (for example, bus
23420error).  The function indicated by @code{exceptionHook} is called with
23421one parameter: an @code{int} which is the exception number.
23422
23423@item
23424Compile and link together: your program, the @value{GDBN} debugging stub for
23425your target architecture, and the supporting subroutines.
23426
23427@item
23428Make sure you have a serial connection between your target machine and
23429the @value{GDBN} host, and identify the serial port on the host.
23430
23431@item
23432@c The "remote" target now provides a `load' command, so we should
23433@c document that.  FIXME.
23434Download your program to your target machine (or get it there by
23435whatever means the manufacturer provides), and start it.
23436
23437@item
23438Start @value{GDBN} on the host, and connect to the target
23439(@pxref{Connecting,,Connecting to a Remote Target}).
23440
23441@end enumerate
23442
23443@node Configurations
23444@chapter Configuration-Specific Information
23445
23446While nearly all @value{GDBN} commands are available for all native and
23447cross versions of the debugger, there are some exceptions.  This chapter
23448describes things that are only available in certain configurations.
23449
23450There are three major categories of configurations: native
23451configurations, where the host and target are the same, embedded
23452operating system configurations, which are usually the same for several
23453different processor architectures, and bare embedded processors, which
23454are quite different from each other.
23455
23456@menu
23457* Native::
23458* Embedded OS::
23459* Embedded Processors::
23460* Architectures::
23461@end menu
23462
23463@node Native
23464@section Native
23465
23466This section describes details specific to particular native
23467configurations.
23468
23469@menu
23470* BSD libkvm Interface::	Debugging BSD kernel memory images
23471* Process Information::         Process information
23472* DJGPP Native::                Features specific to the DJGPP port
23473* Cygwin Native::		Features specific to the Cygwin port
23474* Hurd Native::                 Features specific to @sc{gnu} Hurd
23475* Darwin::			Features specific to Darwin
23476* FreeBSD::			Features specific to FreeBSD
23477@end menu
23478
23479@node BSD libkvm Interface
23480@subsection BSD libkvm Interface
23481
23482@cindex libkvm
23483@cindex kernel memory image
23484@cindex kernel crash dump
23485
23486BSD-derived systems (FreeBSD/NetBSD/OpenBSD) have a kernel memory
23487interface that provides a uniform interface for accessing kernel virtual
23488memory images, including live systems and crash dumps.  @value{GDBN}
23489uses this interface to allow you to debug live kernels and kernel crash
23490dumps on many native BSD configurations.  This is implemented as a
23491special @code{kvm} debugging target.  For debugging a live system, load
23492the currently running kernel into @value{GDBN} and connect to the
23493@code{kvm} target:
23494
23495@smallexample
23496(@value{GDBP}) @b{target kvm}
23497@end smallexample
23498
23499For debugging crash dumps, provide the file name of the crash dump as an
23500argument:
23501
23502@smallexample
23503(@value{GDBP}) @b{target kvm /var/crash/bsd.0}
23504@end smallexample
23505
23506Once connected to the @code{kvm} target, the following commands are
23507available:
23508
23509@table @code
23510@kindex kvm
23511@item kvm pcb
23512Set current context from the @dfn{Process Control Block} (PCB) address.
23513
23514@item kvm proc
23515Set current context from proc address.  This command isn't available on
23516modern FreeBSD systems.
23517@end table
23518
23519@node Process Information
23520@subsection Process Information
23521@cindex /proc
23522@cindex examine process image
23523@cindex process info via @file{/proc}
23524
23525Some operating systems provide interfaces to fetch additional
23526information about running processes beyond memory and per-thread
23527register state.  If @value{GDBN} is configured for an operating system
23528with a supported interface, the command @code{info proc} is available
23529to report information about the process running your program, or about
23530any process running on your system.
23531
23532One supported interface is a facility called @samp{/proc} that can be
23533used to examine the image of a running process using file-system
23534subroutines.  This facility is supported on @sc{gnu}/Linux and Solaris
23535systems.
23536
23537On FreeBSD and NetBSD systems, system control nodes are used to query
23538process information.
23539
23540In addition, some systems may provide additional process information
23541in core files.  Note that a core file may include a subset of the
23542information available from a live process.  Process information is
23543currently available from cores created on @sc{gnu}/Linux and FreeBSD
23544systems.
23545
23546@table @code
23547@kindex info proc
23548@cindex process ID
23549@item info proc
23550@itemx info proc @var{process-id}
23551Summarize available information about a process.  If a
23552process ID is specified by @var{process-id}, display information about
23553that process; otherwise display information about the program being
23554debugged.  The summary includes the debugged process ID, the command
23555line used to invoke it, its current working directory, and its
23556executable file's absolute file name.
23557
23558On some systems, @var{process-id} can be of the form
23559@samp{[@var{pid}]/@var{tid}} which specifies a certain thread ID
23560within a process.  If the optional @var{pid} part is missing, it means
23561a thread from the process being debugged (the leading @samp{/} still
23562needs to be present, or else @value{GDBN} will interpret the number as
23563a process ID rather than a thread ID).
23564
23565@item info proc cmdline
23566@cindex info proc cmdline
23567Show the original command line of the process.  This command is
23568supported on @sc{gnu}/Linux, FreeBSD and NetBSD.
23569
23570@item info proc cwd
23571@cindex info proc cwd
23572Show the current working directory of the process.  This command is
23573supported on @sc{gnu}/Linux, FreeBSD and NetBSD.
23574
23575@item info proc exe
23576@cindex info proc exe
23577Show the name of executable of the process.  This command is supported
23578on @sc{gnu}/Linux, FreeBSD and NetBSD.
23579
23580@item info proc files
23581@cindex info proc files
23582Show the file descriptors open by the process.  For each open file
23583descriptor, @value{GDBN} shows its number, type (file, directory,
23584character device, socket), file pointer offset, and the name of the
23585resource open on the descriptor.  The resource name can be a file name
23586(for files, directories, and devices) or a protocol followed by socket
23587address (for network connections).  This command is supported on
23588FreeBSD.
23589
23590This example shows the open file descriptors for a process using a
23591tty for standard input and output as well as two network sockets:
23592
23593@smallexample
23594(gdb) info proc files 22136
23595process 22136
23596Open files:
23597
23598      FD   Type     Offset   Flags   Name
23599    text   file          - r-------- /usr/bin/ssh
23600    ctty    chr          - rw------- /dev/pts/20
23601     cwd    dir          - r-------- /usr/home/john
23602    root    dir          - r-------- /
23603       0    chr  0x32933a4 rw------- /dev/pts/20
23604       1    chr  0x32933a4 rw------- /dev/pts/20
23605       2    chr  0x32933a4 rw------- /dev/pts/20
23606       3 socket        0x0 rw----n-- tcp4 10.0.1.2:53014 -> 10.0.1.10:22
23607       4 socket        0x0 rw------- unix stream:/tmp/ssh-FIt89oAzOn5f/agent.2456
23608@end smallexample
23609
23610@item info proc mappings
23611@cindex memory address space mappings
23612Report the memory address space ranges accessible in a process.  On
23613Solaris, FreeBSD and NetBSD systems, each memory range includes information
23614on whether the process has read, write, or execute access rights to each
23615range.  On @sc{gnu}/Linux, FreeBSD and NetBSD systems, each memory range
23616includes the object file which is mapped to that range.
23617
23618@item info proc stat
23619@itemx info proc status
23620@cindex process detailed status information
23621Show additional process-related information, including the user ID and
23622group ID; virtual memory usage; the signals that are pending, blocked,
23623and ignored; its TTY; its consumption of system and user time; its
23624stack size; its @samp{nice} value; etc.  These commands are supported
23625on @sc{gnu}/Linux, FreeBSD and NetBSD.
23626
23627For @sc{gnu}/Linux systems, see the @samp{proc} man page for more
23628information (type @kbd{man 5 proc} from your shell prompt).
23629
23630For FreeBSD and NetBSD systems, @code{info proc stat} is an alias for
23631@code{info proc status}.
23632
23633@item info proc all
23634Show all the information about the process described under all of the
23635above @code{info proc} subcommands.
23636
23637@ignore
23638@comment These sub-options of 'info proc' were not included when
23639@comment procfs.c was re-written.  Keep their descriptions around
23640@comment against the day when someone finds the time to put them back in.
23641@kindex info proc times
23642@item info proc times
23643Starting time, user CPU time, and system CPU time for your program and
23644its children.
23645
23646@kindex info proc id
23647@item info proc id
23648Report on the process IDs related to your program: its own process ID,
23649the ID of its parent, the process group ID, and the session ID.
23650@end ignore
23651
23652@item set procfs-trace
23653@kindex set procfs-trace
23654@cindex @code{procfs} API calls
23655This command enables and disables tracing of @code{procfs} API calls.
23656
23657@item show procfs-trace
23658@kindex show procfs-trace
23659Show the current state of @code{procfs} API call tracing.
23660
23661@item set procfs-file @var{file}
23662@kindex set procfs-file
23663Tell @value{GDBN} to write @code{procfs} API trace to the named
23664@var{file}.  @value{GDBN} appends the trace info to the previous
23665contents of the file.  The default is to display the trace on the
23666standard output.
23667
23668@item show procfs-file
23669@kindex show procfs-file
23670Show the file to which @code{procfs} API trace is written.
23671
23672@item proc-trace-entry
23673@itemx proc-trace-exit
23674@itemx proc-untrace-entry
23675@itemx proc-untrace-exit
23676@kindex proc-trace-entry
23677@kindex proc-trace-exit
23678@kindex proc-untrace-entry
23679@kindex proc-untrace-exit
23680These commands enable and disable tracing of entries into and exits
23681from the @code{syscall} interface.
23682
23683@item info pidlist
23684@kindex info pidlist
23685@cindex process list, QNX Neutrino
23686For QNX Neutrino only, this command displays the list of all the
23687processes and all the threads within each process.
23688
23689@item info meminfo
23690@kindex info meminfo
23691@cindex mapinfo list, QNX Neutrino
23692For QNX Neutrino only, this command displays the list of all mapinfos.
23693@end table
23694
23695@node DJGPP Native
23696@subsection Features for Debugging @sc{djgpp} Programs
23697@cindex @sc{djgpp} debugging
23698@cindex native @sc{djgpp} debugging
23699@cindex MS-DOS-specific commands
23700
23701@cindex DPMI
23702@sc{djgpp} is a port of the @sc{gnu} development tools to MS-DOS and
23703MS-Windows.  @sc{djgpp} programs are 32-bit protected-mode programs
23704that use the @dfn{DPMI} (DOS Protected-Mode Interface) API to run on
23705top of real-mode DOS systems and their emulations.
23706
23707@value{GDBN} supports native debugging of @sc{djgpp} programs, and
23708defines a few commands specific to the @sc{djgpp} port.  This
23709subsection describes those commands.
23710
23711@table @code
23712@kindex info dos
23713@item info dos
23714This is a prefix of @sc{djgpp}-specific commands which print
23715information about the target system and important OS structures.
23716
23717@kindex sysinfo
23718@cindex MS-DOS system info
23719@cindex free memory information (MS-DOS)
23720@item info dos sysinfo
23721This command displays assorted information about the underlying
23722platform: the CPU type and features, the OS version and flavor, the
23723DPMI version, and the available conventional and DPMI memory.
23724
23725@cindex GDT
23726@cindex LDT
23727@cindex IDT
23728@cindex segment descriptor tables
23729@cindex descriptor tables display
23730@item info dos gdt
23731@itemx info dos ldt
23732@itemx info dos idt
23733These 3 commands display entries from, respectively, Global, Local,
23734and Interrupt Descriptor Tables (GDT, LDT, and IDT).  The descriptor
23735tables are data structures which store a descriptor for each segment
23736that is currently in use.  The segment's selector is an index into a
23737descriptor table; the table entry for that index holds the
23738descriptor's base address and limit, and its attributes and access
23739rights.
23740
23741A typical @sc{djgpp} program uses 3 segments: a code segment, a data
23742segment (used for both data and the stack), and a DOS segment (which
23743allows access to DOS/BIOS data structures and absolute addresses in
23744conventional memory).  However, the DPMI host will usually define
23745additional segments in order to support the DPMI environment.
23746
23747@cindex garbled pointers
23748These commands allow to display entries from the descriptor tables.
23749Without an argument, all entries from the specified table are
23750displayed.  An argument, which should be an integer expression, means
23751display a single entry whose index is given by the argument.  For
23752example, here's a convenient way to display information about the
23753debugged program's data segment:
23754
23755@smallexample
23756@exdent @code{(@value{GDBP}) info dos ldt $ds}
23757@exdent @code{0x13f: base=0x11970000 limit=0x0009ffff 32-Bit Data (Read/Write, Exp-up)}
23758@end smallexample
23759
23760@noindent
23761This comes in handy when you want to see whether a pointer is outside
23762the data segment's limit (i.e.@: @dfn{garbled}).
23763
23764@cindex page tables display (MS-DOS)
23765@item info dos pde
23766@itemx info dos pte
23767These two commands display entries from, respectively, the Page
23768Directory and the Page Tables.  Page Directories and Page Tables are
23769data structures which control how virtual memory addresses are mapped
23770into physical addresses.  A Page Table includes an entry for every
23771page of memory that is mapped into the program's address space; there
23772may be several Page Tables, each one holding up to 4096 entries.  A
23773Page Directory has up to 4096 entries, one each for every Page Table
23774that is currently in use.
23775
23776Without an argument, @kbd{info dos pde} displays the entire Page
23777Directory, and @kbd{info dos pte} displays all the entries in all of
23778the Page Tables.  An argument, an integer expression, given to the
23779@kbd{info dos pde} command means display only that entry from the Page
23780Directory table.  An argument given to the @kbd{info dos pte} command
23781means display entries from a single Page Table, the one pointed to by
23782the specified entry in the Page Directory.
23783
23784@cindex direct memory access (DMA) on MS-DOS
23785These commands are useful when your program uses @dfn{DMA} (Direct
23786Memory Access), which needs physical addresses to program the DMA
23787controller.
23788
23789These commands are supported only with some DPMI servers.
23790
23791@cindex physical address from linear address
23792@item info dos address-pte @var{addr}
23793This command displays the Page Table entry for a specified linear
23794address.  The argument @var{addr} is a linear address which should
23795already have the appropriate segment's base address added to it,
23796because this command accepts addresses which may belong to @emph{any}
23797segment.  For example, here's how to display the Page Table entry for
23798the page where a variable @code{i} is stored:
23799
23800@smallexample
23801@exdent @code{(@value{GDBP}) info dos address-pte __djgpp_base_address + (char *)&i}
23802@exdent @code{Page Table entry for address 0x11a00d30:}
23803@exdent @code{Base=0x02698000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0xd30}
23804@end smallexample
23805
23806@noindent
23807This says that @code{i} is stored at offset @code{0xd30} from the page
23808whose physical base address is @code{0x02698000}, and shows all the
23809attributes of that page.
23810
23811Note that you must cast the addresses of variables to a @code{char *},
23812since otherwise the value of @code{__djgpp_base_address}, the base
23813address of all variables and functions in a @sc{djgpp} program, will
23814be added using the rules of C pointer arithmetics: if @code{i} is
23815declared an @code{int}, @value{GDBN} will add 4 times the value of
23816@code{__djgpp_base_address} to the address of @code{i}.
23817
23818Here's another example, it displays the Page Table entry for the
23819transfer buffer:
23820
23821@smallexample
23822@exdent @code{(@value{GDBP}) info dos address-pte *((unsigned *)&_go32_info_block + 3)}
23823@exdent @code{Page Table entry for address 0x29110:}
23824@exdent @code{Base=0x00029000 Dirty Acc. Not-Cached Write-Back Usr Read-Write +0x110}
23825@end smallexample
23826
23827@noindent
23828(The @code{+ 3} offset is because the transfer buffer's address is the
238293rd member of the @code{_go32_info_block} structure.)  The output
23830clearly shows that this DPMI server maps the addresses in conventional
23831memory 1:1, i.e.@: the physical (@code{0x00029000} + @code{0x110}) and
23832linear (@code{0x29110}) addresses are identical.
23833
23834This command is supported only with some DPMI servers.
23835@end table
23836
23837@cindex DOS serial data link, remote debugging
23838In addition to native debugging, the DJGPP port supports remote
23839debugging via a serial data link.  The following commands are specific
23840to remote serial debugging in the DJGPP port of @value{GDBN}.
23841
23842@table @code
23843@kindex set com1base
23844@kindex set com1irq
23845@kindex set com2base
23846@kindex set com2irq
23847@kindex set com3base
23848@kindex set com3irq
23849@kindex set com4base
23850@kindex set com4irq
23851@item set com1base @var{addr}
23852This command sets the base I/O port address of the @file{COM1} serial
23853port.
23854
23855@item set com1irq @var{irq}
23856This command sets the @dfn{Interrupt Request} (@code{IRQ}) line to use
23857for the @file{COM1} serial port.
23858
23859There are similar commands @samp{set com2base}, @samp{set com3irq},
23860etc.@: for setting the port address and the @code{IRQ} lines for the
23861other 3 COM ports.
23862
23863@kindex show com1base
23864@kindex show com1irq
23865@kindex show com2base
23866@kindex show com2irq
23867@kindex show com3base
23868@kindex show com3irq
23869@kindex show com4base
23870@kindex show com4irq
23871The related commands @samp{show com1base}, @samp{show com1irq} etc.@:
23872display the current settings of the base address and the @code{IRQ}
23873lines used by the COM ports.
23874
23875@item info serial
23876@kindex info serial
23877@cindex DOS serial port status
23878This command prints the status of the 4 DOS serial ports.  For each
23879port, it prints whether it's active or not, its I/O base address and
23880IRQ number, whether it uses a 16550-style FIFO, its baudrate, and the
23881counts of various errors encountered so far.
23882@end table
23883
23884
23885@node Cygwin Native
23886@subsection Features for Debugging MS Windows PE Executables
23887@cindex MS Windows debugging
23888@cindex native Cygwin debugging
23889@cindex Cygwin-specific commands
23890
23891@value{GDBN} supports native debugging of MS Windows programs, including
23892DLLs with and without symbolic debugging information.
23893
23894@cindex Ctrl-BREAK, MS-Windows
23895@cindex interrupt debuggee on MS-Windows
23896MS-Windows programs that call @code{SetConsoleMode} to switch off the
23897special meaning of the @samp{Ctrl-C} keystroke cannot be interrupted
23898by typing @kbd{C-c}.  For this reason, @value{GDBN} on MS-Windows
23899supports @kbd{C-@key{BREAK}} as an alternative interrupt key
23900sequence, which can be used to interrupt the debuggee even if it
23901ignores @kbd{C-c}.
23902
23903There are various additional Cygwin-specific commands, described in
23904this section.  Working with DLLs that have no debugging symbols is
23905described in @ref{Non-debug DLL Symbols}.
23906
23907@table @code
23908@kindex info w32
23909@item info w32
23910This is a prefix of MS Windows-specific commands which print
23911information about the target system and important OS structures.
23912
23913@item info w32 selector
23914This command displays information returned by
23915the Win32 API @code{GetThreadSelectorEntry} function.
23916It takes an optional argument that is evaluated to
23917a long value to give the information about this given selector.
23918Without argument, this command displays information
23919about the six segment registers.
23920
23921@item info w32 thread-information-block
23922This command displays thread specific information stored in the
23923Thread Information Block (readable on the X86 CPU family using @code{$fs}
23924selector for 32-bit programs and @code{$gs} for 64-bit programs).
23925
23926@kindex signal-event
23927@item signal-event @var{id}
23928This command signals an event with user-provided @var{id}.  Used to resume
23929crashing process when attached to it using MS-Windows JIT debugging (AeDebug).
23930
23931To use it, create or edit the following keys in
23932@code{HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AeDebug} and/or
23933@code{HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\AeDebug}
23934(for x86_64 versions):
23935
23936@itemize @minus
23937@item
23938@code{Debugger} (REG_SZ) --- a command to launch the debugger.
23939Suggested command is: @code{@var{fully-qualified-path-to-gdb.exe} -ex
23940"attach %ld" -ex "signal-event %ld" -ex "continue"}.
23941
23942The first @code{%ld} will be replaced by the process ID of the
23943crashing process, the second @code{%ld} will be replaced by the ID of
23944the event that blocks the crashing process, waiting for @value{GDBN}
23945to attach.
23946
23947@item
23948@code{Auto} (REG_SZ) --- either @code{1} or @code{0}.  @code{1} will
23949make the system run debugger specified by the Debugger key
23950automatically, @code{0} will cause a dialog box with ``OK'' and
23951``Cancel'' buttons to appear, which allows the user to either
23952terminate the crashing process (OK) or debug it (Cancel).
23953@end itemize
23954
23955@kindex set cygwin-exceptions
23956@cindex debugging the Cygwin DLL
23957@cindex Cygwin DLL, debugging
23958@item set cygwin-exceptions @var{mode}
23959If @var{mode} is @code{on}, @value{GDBN} will break on exceptions that
23960happen inside the Cygwin DLL.  If @var{mode} is @code{off},
23961@value{GDBN} will delay recognition of exceptions, and may ignore some
23962exceptions which seem to be caused by internal Cygwin DLL
23963``bookkeeping''.  This option is meant primarily for debugging the
23964Cygwin DLL itself; the default value is @code{off} to avoid annoying
23965@value{GDBN} users with false @code{SIGSEGV} signals.
23966
23967@kindex show cygwin-exceptions
23968@item show cygwin-exceptions
23969Displays whether @value{GDBN} will break on exceptions that happen
23970inside the Cygwin DLL itself.
23971
23972@kindex set new-console
23973@item set new-console @var{mode}
23974If @var{mode} is @code{on} the debuggee will
23975be started in a new console on next start.
23976If @var{mode} is @code{off}, the debuggee will
23977be started in the same console as the debugger.
23978
23979@kindex show new-console
23980@item show new-console
23981Displays whether a new console is used
23982when the debuggee is started.
23983
23984@kindex set new-group
23985@item set new-group @var{mode}
23986This boolean value controls whether the debuggee should
23987start a new group or stay in the same group as the debugger.
23988This affects the way the Windows OS handles
23989@samp{Ctrl-C}.
23990
23991@kindex show new-group
23992@item show new-group
23993Displays current value of new-group boolean.
23994
23995@kindex set debugevents
23996@item set debugevents
23997This boolean value adds debug output concerning kernel events related
23998to the debuggee seen by the debugger.  This includes events that
23999signal thread and process creation and exit, DLL loading and
24000unloading, console interrupts, and debugging messages produced by the
24001Windows @code{OutputDebugString} API call.
24002
24003@kindex set debugexec
24004@item set debugexec
24005This boolean value adds debug output concerning execute events
24006(such as resume thread) seen by the debugger.
24007
24008@kindex set debugexceptions
24009@item set debugexceptions
24010This boolean value adds debug output concerning exceptions in the
24011debuggee seen by the debugger.
24012
24013@kindex set debugmemory
24014@item set debugmemory
24015This boolean value adds debug output concerning debuggee memory reads
24016and writes by the debugger.
24017
24018@kindex set shell
24019@item set shell
24020This boolean values specifies whether the debuggee is called
24021via a shell or directly (default value is on).
24022
24023@kindex show shell
24024@item show shell
24025Displays if the debuggee will be started with a shell.
24026
24027@end table
24028
24029@menu
24030* Non-debug DLL Symbols::  Support for DLLs without debugging symbols
24031@end menu
24032
24033@node Non-debug DLL Symbols
24034@subsubsection Support for DLLs without Debugging Symbols
24035@cindex DLLs with no debugging symbols
24036@cindex Minimal symbols and DLLs
24037
24038Very often on windows, some of the DLLs that your program relies on do
24039not include symbolic debugging information (for example,
24040@file{kernel32.dll}).  When @value{GDBN} doesn't recognize any debugging
24041symbols in a DLL, it relies on the minimal amount of symbolic
24042information contained in the DLL's export table.  This section
24043describes working with such symbols, known internally to @value{GDBN} as
24044``minimal symbols''.
24045
24046Note that before the debugged program has started execution, no DLLs
24047will have been loaded.  The easiest way around this problem is simply to
24048start the program --- either by setting a breakpoint or letting the
24049program run once to completion.
24050
24051@subsubsection DLL Name Prefixes
24052
24053In keeping with the naming conventions used by the Microsoft debugging
24054tools, DLL export symbols are made available with a prefix based on the
24055DLL name, for instance @code{KERNEL32!CreateFileA}.  The plain name is
24056also entered into the symbol table, so @code{CreateFileA} is often
24057sufficient.  In some cases there will be name clashes within a program
24058(particularly if the executable itself includes full debugging symbols)
24059necessitating the use of the fully qualified name when referring to the
24060contents of the DLL.  Use single-quotes around the name to avoid the
24061exclamation mark (``!'')  being interpreted as a language operator.
24062
24063Note that the internal name of the DLL may be all upper-case, even
24064though the file name of the DLL is lower-case, or vice-versa.  Since
24065symbols within @value{GDBN} are @emph{case-sensitive} this may cause
24066some confusion. If in doubt, try the @code{info functions} and
24067@code{info variables} commands or even @code{maint print msymbols}
24068(@pxref{Symbols}). Here's an example:
24069
24070@smallexample
24071(@value{GDBP}) info function CreateFileA
24072All functions matching regular expression "CreateFileA":
24073
24074Non-debugging symbols:
240750x77e885f4  CreateFileA
240760x77e885f4  KERNEL32!CreateFileA
24077@end smallexample
24078
24079@smallexample
24080(@value{GDBP}) info function !
24081All functions matching regular expression "!":
24082
24083Non-debugging symbols:
240840x6100114c  cygwin1!__assert
240850x61004034  cygwin1!_dll_crt0@@0
240860x61004240  cygwin1!dll_crt0(per_process *)
24087[etc...]
24088@end smallexample
24089
24090@subsubsection Working with Minimal Symbols
24091
24092Symbols extracted from a DLL's export table do not contain very much
24093type information. All that @value{GDBN} can do is guess whether a symbol
24094refers to a function or variable depending on the linker section that
24095contains the symbol. Also note that the actual contents of the memory
24096contained in a DLL are not available unless the program is running. This
24097means that you cannot examine the contents of a variable or disassemble
24098a function within a DLL without a running program.
24099
24100Variables are generally treated as pointers and dereferenced
24101automatically. For this reason, it is often necessary to prefix a
24102variable name with the address-of operator (``&'') and provide explicit
24103type information in the command. Here's an example of the type of
24104problem:
24105
24106@smallexample
24107(@value{GDBP}) print 'cygwin1!__argv'
24108'cygwin1!__argv' has unknown type; cast it to its declared type
24109@end smallexample
24110
24111@smallexample
24112(@value{GDBP}) x 'cygwin1!__argv'
24113'cygwin1!__argv' has unknown type; cast it to its declared type
24114@end smallexample
24115
24116And two possible solutions:
24117
24118@smallexample
24119(@value{GDBP}) print ((char **)'cygwin1!__argv')[0]
24120$2 = 0x22fd98 "/cygdrive/c/mydirectory/myprogram"
24121@end smallexample
24122
24123@smallexample
24124(@value{GDBP}) x/2x &'cygwin1!__argv'
241250x610c0aa8 <cygwin1!__argv>:    0x10021608      0x00000000
24126(@value{GDBP}) x/x 0x10021608
241270x10021608:     0x0022fd98
24128(@value{GDBP}) x/s 0x0022fd98
241290x22fd98:        "/cygdrive/c/mydirectory/myprogram"
24130@end smallexample
24131
24132Setting a break point within a DLL is possible even before the program
24133starts execution. However, under these circumstances, @value{GDBN} can't
24134examine the initial instructions of the function in order to skip the
24135function's frame set-up code. You can work around this by using ``*&''
24136to set the breakpoint at a raw memory address:
24137
24138@smallexample
24139(@value{GDBP}) break *&'python22!PyOS_Readline'
24140Breakpoint 1 at 0x1e04eff0
24141@end smallexample
24142
24143The author of these extensions is not entirely convinced that setting a
24144break point within a shared DLL like @file{kernel32.dll} is completely
24145safe.
24146
24147@node Hurd Native
24148@subsection Commands Specific to @sc{gnu} Hurd Systems
24149@cindex @sc{gnu} Hurd debugging
24150
24151This subsection describes @value{GDBN} commands specific to the
24152@sc{gnu} Hurd native debugging.
24153
24154@table @code
24155@item set signals
24156@itemx set sigs
24157@kindex set signals@r{, Hurd command}
24158@kindex set sigs@r{, Hurd command}
24159This command toggles the state of inferior signal interception by
24160@value{GDBN}.  Mach exceptions, such as breakpoint traps, are not
24161affected by this command.  @code{sigs} is a shorthand alias for
24162@code{signals}.
24163
24164@item show signals
24165@itemx show sigs
24166@kindex show signals@r{, Hurd command}
24167@kindex show sigs@r{, Hurd command}
24168Show the current state of intercepting inferior's signals.
24169
24170@item set signal-thread
24171@itemx set sigthread
24172@kindex set signal-thread
24173@kindex set sigthread
24174This command tells @value{GDBN} which thread is the @code{libc} signal
24175thread.  That thread is run when a signal is delivered to a running
24176process.  @code{set sigthread} is the shorthand alias of @code{set
24177signal-thread}.
24178
24179@item show signal-thread
24180@itemx show sigthread
24181@kindex show signal-thread
24182@kindex show sigthread
24183These two commands show which thread will run when the inferior is
24184delivered a signal.
24185
24186@item set stopped
24187@kindex set stopped@r{, Hurd command}
24188This commands tells @value{GDBN} that the inferior process is stopped,
24189as with the @code{SIGSTOP} signal.  The stopped process can be
24190continued by delivering a signal to it.
24191
24192@item show stopped
24193@kindex show stopped@r{, Hurd command}
24194This command shows whether @value{GDBN} thinks the debuggee is
24195stopped.
24196
24197@item set exceptions
24198@kindex set exceptions@r{, Hurd command}
24199Use this command to turn off trapping of exceptions in the inferior.
24200When exception trapping is off, neither breakpoints nor
24201single-stepping will work.  To restore the default, set exception
24202trapping on.
24203
24204@item show exceptions
24205@kindex show exceptions@r{, Hurd command}
24206Show the current state of trapping exceptions in the inferior.
24207
24208@item set task pause
24209@kindex set task@r{, Hurd commands}
24210@cindex task attributes (@sc{gnu} Hurd)
24211@cindex pause current task (@sc{gnu} Hurd)
24212This command toggles task suspension when @value{GDBN} has control.
24213Setting it to on takes effect immediately, and the task is suspended
24214whenever @value{GDBN} gets control.  Setting it to off will take
24215effect the next time the inferior is continued.  If this option is set
24216to off, you can use @code{set thread default pause on} or @code{set
24217thread pause on} (see below) to pause individual threads.
24218
24219@item show task pause
24220@kindex show task@r{, Hurd commands}
24221Show the current state of task suspension.
24222
24223@item set task detach-suspend-count
24224@cindex task suspend count
24225@cindex detach from task, @sc{gnu} Hurd
24226This command sets the suspend count the task will be left with when
24227@value{GDBN} detaches from it.
24228
24229@item show task detach-suspend-count
24230Show the suspend count the task will be left with when detaching.
24231
24232@item set task exception-port
24233@itemx set task excp
24234@cindex task exception port, @sc{gnu} Hurd
24235This command sets the task exception port to which @value{GDBN} will
24236forward exceptions.  The argument should be the value of the @dfn{send
24237rights} of the task.  @code{set task excp} is a shorthand alias.
24238
24239@item set noninvasive
24240@cindex noninvasive task options
24241This command switches @value{GDBN} to a mode that is the least
24242invasive as far as interfering with the inferior is concerned.  This
24243is the same as using @code{set task pause}, @code{set exceptions}, and
24244@code{set signals} to values opposite to the defaults.
24245
24246@item info send-rights
24247@itemx info receive-rights
24248@itemx info port-rights
24249@itemx info port-sets
24250@itemx info dead-names
24251@itemx info ports
24252@itemx info psets
24253@cindex send rights, @sc{gnu} Hurd
24254@cindex receive rights, @sc{gnu} Hurd
24255@cindex port rights, @sc{gnu} Hurd
24256@cindex port sets, @sc{gnu} Hurd
24257@cindex dead names, @sc{gnu} Hurd
24258These commands display information about, respectively, send rights,
24259receive rights, port rights, port sets, and dead names of a task.
24260There are also shorthand aliases: @code{info ports} for @code{info
24261port-rights} and @code{info psets} for @code{info port-sets}.
24262
24263@item set thread pause
24264@kindex set thread@r{, Hurd command}
24265@cindex thread properties, @sc{gnu} Hurd
24266@cindex pause current thread (@sc{gnu} Hurd)
24267This command toggles current thread suspension when @value{GDBN} has
24268control.  Setting it to on takes effect immediately, and the current
24269thread is suspended whenever @value{GDBN} gets control.  Setting it to
24270off will take effect the next time the inferior is continued.
24271Normally, this command has no effect, since when @value{GDBN} has
24272control, the whole task is suspended.  However, if you used @code{set
24273task pause off} (see above), this command comes in handy to suspend
24274only the current thread.
24275
24276@item show thread pause
24277@kindex show thread@r{, Hurd command}
24278This command shows the state of current thread suspension.
24279
24280@item set thread run
24281This command sets whether the current thread is allowed to run.
24282
24283@item show thread run
24284Show whether the current thread is allowed to run.
24285
24286@item set thread detach-suspend-count
24287@cindex thread suspend count, @sc{gnu} Hurd
24288@cindex detach from thread, @sc{gnu} Hurd
24289This command sets the suspend count @value{GDBN} will leave on a
24290thread when detaching.  This number is relative to the suspend count
24291found by @value{GDBN} when it notices the thread; use @code{set thread
24292takeover-suspend-count} to force it to an absolute value.
24293
24294@item show thread detach-suspend-count
24295Show the suspend count @value{GDBN} will leave on the thread when
24296detaching.
24297
24298@item set thread exception-port
24299@itemx set thread excp
24300Set the thread exception port to which to forward exceptions.  This
24301overrides the port set by @code{set task exception-port} (see above).
24302@code{set thread excp} is the shorthand alias.
24303
24304@item set thread takeover-suspend-count
24305Normally, @value{GDBN}'s thread suspend counts are relative to the
24306value @value{GDBN} finds when it notices each thread.  This command
24307changes the suspend counts to be absolute instead.
24308
24309@item set thread default
24310@itemx show thread default
24311@cindex thread default settings, @sc{gnu} Hurd
24312Each of the above @code{set thread} commands has a @code{set thread
24313default} counterpart (e.g., @code{set thread default pause}, @code{set
24314thread default exception-port}, etc.).  The @code{thread default}
24315variety of commands sets the default thread properties for all
24316threads; you can then change the properties of individual threads with
24317the non-default commands.
24318@end table
24319
24320@node Darwin
24321@subsection Darwin
24322@cindex Darwin
24323
24324@value{GDBN} provides the following commands specific to the Darwin target:
24325
24326@table @code
24327@item set debug darwin @var{num}
24328@kindex set debug darwin
24329When set to a non zero value, enables debugging messages specific to
24330the Darwin support.  Higher values produce more verbose output.
24331
24332@item show debug darwin
24333@kindex show debug darwin
24334Show the current state of Darwin messages.
24335
24336@item set debug mach-o @var{num}
24337@kindex set debug mach-o
24338When set to a non zero value, enables debugging messages while
24339@value{GDBN} is reading Darwin object files.  (@dfn{Mach-O} is the
24340file format used on Darwin for object and executable files.)  Higher
24341values produce more verbose output.  This is a command to diagnose
24342problems internal to @value{GDBN} and should not be needed in normal
24343usage.
24344
24345@item show debug mach-o
24346@kindex show debug mach-o
24347Show the current state of Mach-O file messages.
24348
24349@item set mach-exceptions on
24350@itemx set mach-exceptions off
24351@kindex set mach-exceptions
24352On Darwin, faults are first reported as a Mach exception and are then
24353mapped to a Posix signal.  Use this command to turn on trapping of
24354Mach exceptions in the inferior.  This might be sometimes useful to
24355better understand the cause of a fault.  The default is off.
24356
24357@item show mach-exceptions
24358@kindex show mach-exceptions
24359Show the current state of exceptions trapping.
24360@end table
24361
24362@node FreeBSD
24363@subsection FreeBSD
24364@cindex FreeBSD
24365
24366When the ABI of a system call is changed in the FreeBSD kernel, this
24367is implemented by leaving a compatibility system call using the old
24368ABI at the existing number and allocating a new system call number for
24369the version using the new ABI.  As a convenience, when a system call
24370is caught by name (@pxref{catch syscall}), compatibility system calls
24371are also caught.
24372
24373For example, FreeBSD 12 introduced a new variant of the @code{kevent}
24374system call and catching the @code{kevent} system call by name catches
24375both variants:
24376
24377@smallexample
24378(@value{GDBP}) catch syscall kevent
24379Catchpoint 1 (syscalls 'freebsd11_kevent' [363] 'kevent' [560])
24380(@value{GDBP})
24381@end smallexample
24382
24383
24384@node Embedded OS
24385@section Embedded Operating Systems
24386
24387This section describes configurations involving the debugging of
24388embedded operating systems that are available for several different
24389architectures.
24390
24391@value{GDBN} includes the ability to debug programs running on
24392various real-time operating systems.
24393
24394@node Embedded Processors
24395@section Embedded Processors
24396
24397This section goes into details specific to particular embedded
24398configurations.
24399
24400@cindex send command to simulator
24401Whenever a specific embedded processor has a simulator, @value{GDBN}
24402allows to send an arbitrary command to the simulator.
24403
24404@table @code
24405@item sim @var{command}
24406@kindex sim@r{, a command}
24407Send an arbitrary @var{command} string to the simulator.  Consult the
24408documentation for the specific simulator in use for information about
24409acceptable commands.
24410@end table
24411
24412
24413@menu
24414* ARC::                         Synopsys ARC
24415* ARM::                         ARM
24416* BPF::                         eBPF
24417* M68K::                        Motorola M68K
24418* MicroBlaze::			Xilinx MicroBlaze
24419* MIPS Embedded::               MIPS Embedded
24420* OpenRISC 1000::               OpenRISC 1000 (or1k)
24421* PowerPC Embedded::            PowerPC Embedded
24422* AVR::                         Atmel AVR
24423* CRIS::                        CRIS
24424* Super-H::                     Renesas Super-H
24425@end menu
24426
24427@node ARC
24428@subsection Synopsys ARC
24429@cindex Synopsys ARC
24430@cindex ARC specific commands
24431@cindex ARC600
24432@cindex ARC700
24433@cindex ARC EM
24434@cindex ARC HS
24435
24436@value{GDBN} provides the following ARC-specific commands:
24437
24438@table @code
24439@item set debug arc
24440@kindex set debug arc
24441Control the level of ARC specific debug messages.  Use 0 for no messages (the
24442default), 1 for debug messages, and 2 for even more debug messages.
24443
24444@item show debug arc
24445@kindex show debug arc
24446Show the level of ARC specific debugging in operation.
24447
24448@item maint print arc arc-instruction @var{address}
24449@kindex maint print arc arc-instruction
24450Print internal disassembler information about instruction at a given address.
24451
24452@end table
24453
24454@node ARM
24455@subsection ARM
24456
24457@value{GDBN} provides the following ARM-specific commands:
24458
24459@table @code
24460@item set arm disassembler
24461@kindex set arm
24462This commands selects from a list of disassembly styles.  The
24463@code{"std"} style is the standard style.
24464
24465@item show arm disassembler
24466@kindex show arm
24467Show the current disassembly style.
24468
24469@item set arm apcs32
24470@cindex ARM 32-bit mode
24471This command toggles ARM operation mode between 32-bit and 26-bit.
24472
24473@item show arm apcs32
24474Display the current usage of the ARM 32-bit mode.
24475
24476@item set arm fpu @var{fputype}
24477This command sets the ARM floating-point unit (FPU) type.  The
24478argument @var{fputype} can be one of these:
24479
24480@table @code
24481@item auto
24482Determine the FPU type by querying the OS ABI.
24483@item softfpa
24484Software FPU, with mixed-endian doubles on little-endian ARM
24485processors.
24486@item fpa
24487GCC-compiled FPA co-processor.
24488@item softvfp
24489Software FPU with pure-endian doubles.
24490@item vfp
24491VFP co-processor.
24492@end table
24493
24494@item show arm fpu
24495Show the current type of the FPU.
24496
24497@item set arm abi
24498This command forces @value{GDBN} to use the specified ABI.
24499
24500@item show arm abi
24501Show the currently used ABI.
24502
24503@item set arm fallback-mode (arm|thumb|auto)
24504@value{GDBN} uses the symbol table, when available, to determine
24505whether instructions are ARM or Thumb.  This command controls
24506@value{GDBN}'s default behavior when the symbol table is not
24507available.  The default is @samp{auto}, which causes @value{GDBN} to
24508use the current execution mode (from the @code{T} bit in the @code{CPSR}
24509register).
24510
24511@item show arm fallback-mode
24512Show the current fallback instruction mode.
24513
24514@item set arm force-mode (arm|thumb|auto)
24515This command overrides use of the symbol table to determine whether
24516instructions are ARM or Thumb.  The default is @samp{auto}, which
24517causes @value{GDBN} to use the symbol table and then the setting
24518of @samp{set arm fallback-mode}.
24519
24520@item show arm force-mode
24521Show the current forced instruction mode.
24522
24523@item set debug arm
24524Toggle whether to display ARM-specific debugging messages from the ARM
24525target support subsystem.
24526
24527@item show debug arm
24528Show whether ARM-specific debugging messages are enabled.
24529@end table
24530
24531@table @code
24532@item target sim @r{[}@var{simargs}@r{]} @dots{}
24533The @value{GDBN} ARM simulator accepts the following optional arguments.
24534
24535@table @code
24536@item --swi-support=@var{type}
24537Tell the simulator which SWI interfaces to support.  The argument
24538@var{type} may be a comma separated list of the following values.
24539The default value is @code{all}.
24540
24541@table @code
24542@item none
24543@item demon
24544@item angel
24545@item redboot
24546@item all
24547@end table
24548@end table
24549@end table
24550
24551@node BPF
24552@subsection BPF
24553
24554@table @code
24555@item target sim @r{[}@var{simargs}@r{]} @dots{}
24556The @value{GDBN} BPF simulator accepts the following optional arguments.
24557
24558@table @code
24559@item --skb-data-offset=@var{offset}
24560Tell the simulator the offset, measured in bytes, of the
24561@code{skb_data} field in the kernel @code{struct sk_buff} structure.
24562This offset is used by some BPF specific-purpose load/store
24563instructions.  Defaults to 0.
24564@end table
24565@end table
24566
24567@node M68K
24568@subsection M68k
24569
24570The Motorola m68k configuration includes ColdFire support.
24571
24572@node MicroBlaze
24573@subsection MicroBlaze
24574@cindex Xilinx MicroBlaze
24575@cindex XMD, Xilinx Microprocessor Debugger
24576
24577The MicroBlaze is a soft-core processor supported on various Xilinx
24578FPGAs, such as Spartan or Virtex series.  Boards with these processors
24579usually have JTAG ports which connect to a host system running the Xilinx
24580Embedded Development Kit (EDK) or Software Development Kit (SDK).
24581This host system is used to download the configuration bitstream to
24582the target FPGA.  The Xilinx Microprocessor Debugger (XMD) program
24583communicates with the target board using the JTAG interface and
24584presents a @code{gdbserver} interface to the board.  By default
24585@code{xmd} uses port @code{1234}.  (While it is possible to change
24586this default port, it requires the use of undocumented @code{xmd}
24587commands.  Contact Xilinx support if you need to do this.)
24588
24589Use these GDB commands to connect to the MicroBlaze target processor.
24590
24591@table @code
24592@item target remote :1234
24593Use this command to connect to the target if you are running @value{GDBN}
24594on the same system as @code{xmd}.
24595
24596@item target remote @var{xmd-host}:1234
24597Use this command to connect to the target if it is connected to @code{xmd}
24598running on a different system named @var{xmd-host}.
24599
24600@item load
24601Use this command to download a program to the MicroBlaze target.
24602
24603@item set debug microblaze @var{n}
24604Enable MicroBlaze-specific debugging messages if non-zero.
24605
24606@item show debug microblaze @var{n}
24607Show MicroBlaze-specific debugging level.
24608@end table
24609
24610@node MIPS Embedded
24611@subsection @acronym{MIPS} Embedded
24612
24613@noindent
24614@value{GDBN} supports these special commands for @acronym{MIPS} targets:
24615
24616@table @code
24617@item set mipsfpu double
24618@itemx set mipsfpu single
24619@itemx set mipsfpu none
24620@itemx set mipsfpu auto
24621@itemx show mipsfpu
24622@kindex set mipsfpu
24623@kindex show mipsfpu
24624@cindex @acronym{MIPS} remote floating point
24625@cindex floating point, @acronym{MIPS} remote
24626If your target board does not support the @acronym{MIPS} floating point
24627coprocessor, you should use the command @samp{set mipsfpu none} (if you
24628need this, you may wish to put the command in your @value{GDBN} init
24629file).  This tells @value{GDBN} how to find the return value of
24630functions which return floating point values.  It also allows
24631@value{GDBN} to avoid saving the floating point registers when calling
24632functions on the board.  If you are using a floating point coprocessor
24633with only single precision floating point support, as on the @sc{r4650}
24634processor, use the command @samp{set mipsfpu single}.  The default
24635double precision floating point coprocessor may be selected using
24636@samp{set mipsfpu double}.
24637
24638In previous versions the only choices were double precision or no
24639floating point, so @samp{set mipsfpu on} will select double precision
24640and @samp{set mipsfpu off} will select no floating point.
24641
24642As usual, you can inquire about the @code{mipsfpu} variable with
24643@samp{show mipsfpu}.
24644@end table
24645
24646@node OpenRISC 1000
24647@subsection OpenRISC 1000
24648@cindex OpenRISC 1000
24649
24650@noindent
24651The OpenRISC 1000 provides a free RISC instruction set architecture.  It is
24652mainly provided as a soft-core which can run on Xilinx, Altera and other
24653FPGA's.
24654
24655@value{GDBN} for OpenRISC supports the below commands when connecting to
24656a target:
24657
24658@table @code
24659
24660@kindex target sim
24661@item target sim
24662
24663Runs the builtin CPU simulator which can run very basic
24664programs but does not support most hardware functions like MMU.
24665For more complex use cases the user is advised to run an external
24666target, and connect using @samp{target remote}.
24667
24668Example: @code{target sim}
24669
24670@item set debug or1k
24671Toggle whether to display OpenRISC-specific debugging messages from the
24672OpenRISC target support subsystem.
24673
24674@item show debug or1k
24675Show whether OpenRISC-specific debugging messages are enabled.
24676@end table
24677
24678@node PowerPC Embedded
24679@subsection PowerPC Embedded
24680
24681@cindex DVC register
24682@value{GDBN} supports using the DVC (Data Value Compare) register to
24683implement in hardware simple hardware watchpoint conditions of the form:
24684
24685@smallexample
24686(@value{GDBP}) watch @var{ADDRESS|VARIABLE} \
24687  if  @var{ADDRESS|VARIABLE} == @var{CONSTANT EXPRESSION}
24688@end smallexample
24689
24690The DVC register will be automatically used when @value{GDBN} detects
24691such pattern in a condition expression, and the created watchpoint uses one
24692debug register (either the @code{exact-watchpoints} option is on and the
24693variable is scalar, or the variable has a length of one byte).  This feature
24694is available in native @value{GDBN} running on a Linux kernel version 2.6.34
24695or newer.
24696
24697When running on PowerPC embedded processors, @value{GDBN} automatically uses
24698ranged hardware watchpoints, unless the @code{exact-watchpoints} option is on,
24699in which case watchpoints using only one debug register are created when
24700watching variables of scalar types.
24701
24702You can create an artificial array to watch an arbitrary memory
24703region using one of the following commands (@pxref{Expressions}):
24704
24705@smallexample
24706(@value{GDBP}) watch *((char *) @var{address})@@@var{length}
24707(@value{GDBP}) watch @{char[@var{length}]@} @var{address}
24708@end smallexample
24709
24710PowerPC embedded processors support masked watchpoints.  See the discussion
24711about the @code{mask} argument in @ref{Set Watchpoints}.
24712
24713@cindex ranged breakpoint
24714PowerPC embedded processors support hardware accelerated
24715@dfn{ranged breakpoints}.  A ranged breakpoint stops execution of
24716the inferior whenever it executes an instruction at any address within
24717the range it specifies.  To set a ranged breakpoint in @value{GDBN},
24718use the @code{break-range} command.
24719
24720@value{GDBN} provides the following PowerPC-specific commands:
24721
24722@table @code
24723@kindex break-range
24724@item break-range @var{start-location}, @var{end-location}
24725Set a breakpoint for an address range given by
24726@var{start-location} and @var{end-location}, which can specify a function name,
24727a line number, an offset of lines from the current line or from the start
24728location, or an address of an instruction (see @ref{Specify Location},
24729for a list of all the possible ways to specify a @var{location}.)
24730The breakpoint will stop execution of the inferior whenever it
24731executes an instruction at any address within the specified range,
24732(including @var{start-location} and @var{end-location}.)
24733
24734@kindex set powerpc
24735@item set powerpc soft-float
24736@itemx show powerpc soft-float
24737Force @value{GDBN} to use (or not use) a software floating point calling
24738convention.  By default, @value{GDBN} selects the calling convention based
24739on the selected architecture and the provided executable file.
24740
24741@item set powerpc vector-abi
24742@itemx show powerpc vector-abi
24743Force @value{GDBN} to use the specified calling convention for vector
24744arguments and return values.  The valid options are @samp{auto};
24745@samp{generic}, to avoid vector registers even if they are present;
24746@samp{altivec}, to use AltiVec registers; and @samp{spe} to use SPE
24747registers.  By default, @value{GDBN} selects the calling convention
24748based on the selected architecture and the provided executable file.
24749
24750@item set powerpc exact-watchpoints
24751@itemx show powerpc exact-watchpoints
24752Allow @value{GDBN} to use only one debug register when watching a variable
24753of scalar type, thus assuming that the variable is accessed through the
24754address of its first byte.
24755
24756@end table
24757
24758@node AVR
24759@subsection Atmel AVR
24760@cindex AVR
24761
24762When configured for debugging the Atmel AVR, @value{GDBN} supports the
24763following AVR-specific commands:
24764
24765@table @code
24766@item info io_registers
24767@kindex info io_registers@r{, AVR}
24768@cindex I/O registers (Atmel AVR)
24769This command displays information about the AVR I/O registers.  For
24770each register, @value{GDBN} prints its number and value.
24771@end table
24772
24773@node CRIS
24774@subsection CRIS
24775@cindex CRIS
24776
24777When configured for debugging CRIS, @value{GDBN} provides the
24778following CRIS-specific commands:
24779
24780@table @code
24781@item set cris-version @var{ver}
24782@cindex CRIS version
24783Set the current CRIS version to @var{ver}, either @samp{10} or @samp{32}.
24784The CRIS version affects register names and sizes.  This command is useful in
24785case autodetection of the CRIS version fails.
24786
24787@item show cris-version
24788Show the current CRIS version.
24789
24790@item set cris-dwarf2-cfi
24791@cindex DWARF-2 CFI and CRIS
24792Set the usage of DWARF-2 CFI for CRIS debugging.  The default is @samp{on}.
24793Change to @samp{off} when using @code{gcc-cris} whose version is below
24794@code{R59}.
24795
24796@item show cris-dwarf2-cfi
24797Show the current state of using DWARF-2 CFI.
24798
24799@item set cris-mode @var{mode}
24800@cindex CRIS mode
24801Set the current CRIS mode to @var{mode}.  It should only be changed when
24802debugging in guru mode, in which case it should be set to
24803@samp{guru} (the default is @samp{normal}).
24804
24805@item show cris-mode
24806Show the current CRIS mode.
24807@end table
24808
24809@node Super-H
24810@subsection Renesas Super-H
24811@cindex Super-H
24812
24813For the Renesas Super-H processor, @value{GDBN} provides these
24814commands:
24815
24816@table @code
24817@item set sh calling-convention @var{convention}
24818@kindex set sh calling-convention
24819Set the calling-convention used when calling functions from @value{GDBN}.
24820Allowed values are @samp{gcc}, which is the default setting, and @samp{renesas}.
24821With the @samp{gcc} setting, functions are called using the @value{NGCC} calling
24822convention.  If the DWARF-2 information of the called function specifies
24823that the function follows the Renesas calling convention, the function
24824is called using the Renesas calling convention.  If the calling convention
24825is set to @samp{renesas}, the Renesas calling convention is always used,
24826regardless of the DWARF-2 information.  This can be used to override the
24827default of @samp{gcc} if debug information is missing, or the compiler
24828does not emit the DWARF-2 calling convention entry for a function.
24829
24830@item show sh calling-convention
24831@kindex show sh calling-convention
24832Show the current calling convention setting.
24833
24834@end table
24835
24836
24837@node Architectures
24838@section Architectures
24839
24840This section describes characteristics of architectures that affect
24841all uses of @value{GDBN} with the architecture, both native and cross.
24842
24843@menu
24844* AArch64::
24845* i386::
24846* Alpha::
24847* MIPS::
24848* HPPA::               HP PA architecture
24849* PowerPC::
24850* Nios II::
24851* Sparc64::
24852* S12Z::
24853@end menu
24854
24855@node AArch64
24856@subsection AArch64
24857@cindex AArch64 support
24858
24859When @value{GDBN} is debugging the AArch64 architecture, it provides the
24860following special commands:
24861
24862@table @code
24863@item set debug aarch64
24864@kindex set debug aarch64
24865This command determines whether AArch64 architecture-specific debugging
24866messages are to be displayed.
24867
24868@item show debug aarch64
24869Show whether AArch64 debugging messages are displayed.
24870
24871@end table
24872
24873@subsubsection AArch64 SVE.
24874@cindex AArch64 SVE.
24875
24876When @value{GDBN} is debugging the AArch64 architecture, if the Scalable Vector
24877Extension (SVE) is present, then @value{GDBN} will provide the vector registers
24878@code{$z0} through @code{$z31}, vector predicate registers @code{$p0} through
24879@code{$p15}, and the @code{$ffr} register.  In addition, the pseudo register
24880@code{$vg} will be provided.  This is the vector granule for the current thread
24881and represents the number of 64-bit chunks in an SVE @code{z} register.
24882
24883If the vector length changes, then the @code{$vg} register will be updated,
24884but the lengths of the @code{z} and @code{p} registers will not change.  This
24885is a known limitation of @value{GDBN} and does not affect the execution of the
24886target process.
24887
24888@subsubsection AArch64 Pointer Authentication.
24889@cindex AArch64 Pointer Authentication.
24890
24891When @value{GDBN} is debugging the AArch64 architecture, and the program is
24892using the v8.3-A feature Pointer Authentication (PAC), then whenever the link
24893register @code{$lr} is pointing to an PAC function its value will be masked.
24894When GDB prints a backtrace, any addresses that required unmasking will be
24895postfixed with the marker [PAC].  When using the MI, this is printed as part
24896of the @code{addr_flags} field.
24897
24898@node i386
24899@subsection x86 Architecture-specific Issues
24900
24901@table @code
24902@item set struct-convention @var{mode}
24903@kindex set struct-convention
24904@cindex struct return convention
24905@cindex struct/union returned in registers
24906Set the convention used by the inferior to return @code{struct}s and
24907@code{union}s from functions to @var{mode}.  Possible values of
24908@var{mode} are @code{"pcc"}, @code{"reg"}, and @code{"default"} (the
24909default).  @code{"default"} or @code{"pcc"} means that @code{struct}s
24910are returned on the stack, while @code{"reg"} means that a
24911@code{struct} or a @code{union} whose size is 1, 2, 4, or 8 bytes will
24912be returned in a register.
24913
24914@item show struct-convention
24915@kindex show struct-convention
24916Show the current setting of the convention to return @code{struct}s
24917from functions.
24918@end table
24919
24920
24921@subsubsection Intel @dfn{Memory Protection Extensions} (MPX).
24922@cindex Intel Memory Protection Extensions (MPX).
24923
24924Memory Protection Extension (MPX) adds the bound registers @samp{BND0}
24925@footnote{The register named with capital letters represent the architecture
24926registers.} through @samp{BND3}.  Bound registers store a pair of 64-bit values
24927which are the lower bound and upper bound.  Bounds are effective addresses or
24928memory locations.  The upper bounds are architecturally represented in 1's
24929complement form.  A bound having lower bound = 0, and upper bound = 0
24930(1's complement of all bits set) will allow access to the entire address space.
24931
24932@samp{BND0} through @samp{BND3} are represented in @value{GDBN} as @samp{bnd0raw}
24933through @samp{bnd3raw}.  Pseudo registers @samp{bnd0} through @samp{bnd3}
24934display the upper bound performing the complement of one operation on the
24935upper bound value, i.e.@ when upper bound in @samp{bnd0raw} is 0 in the
24936@value{GDBN} @samp{bnd0} it will be @code{0xfff@dots{}}.  In this sense it
24937can also be noted that the upper bounds are inclusive.
24938
24939As an example, assume that the register BND0 holds bounds for a pointer having
24940access allowed for the range between 0x32 and 0x71.  The values present on
24941bnd0raw and bnd registers are presented as follows:
24942
24943@smallexample
24944	bnd0raw = @{0x32, 0xffffffff8e@}
24945	bnd0 = @{lbound = 0x32, ubound = 0x71@} : size 64
24946@end smallexample
24947
24948This way the raw value can be accessed via bnd0raw@dots{}bnd3raw.  Any
24949change on bnd0@dots{}bnd3 or bnd0raw@dots{}bnd3raw is reflect on its
24950counterpart.  When the bnd0@dots{}bnd3 registers are displayed via
24951Python, the display includes the memory size, in bits, accessible to
24952the pointer.
24953
24954Bounds can also be stored in bounds tables, which are stored in
24955application memory.  These tables store bounds for pointers by specifying
24956the bounds pointer's value along with its bounds.  Evaluating and changing
24957bounds located in bound tables is therefore interesting while investigating
24958bugs on MPX context.  @value{GDBN} provides commands for this purpose:
24959
24960@table @code
24961@item show mpx bound @var{pointer}
24962@kindex show mpx bound
24963Display bounds of the given @var{pointer}.
24964
24965@item set mpx bound @var{pointer}, @var{lbound}, @var{ubound}
24966@kindex  set mpx bound
24967Set the bounds of a pointer in the bound table.
24968This command takes three parameters: @var{pointer} is the pointers
24969whose bounds are to be changed, @var{lbound} and @var{ubound} are new values
24970for lower and upper bounds respectively.
24971@end table
24972
24973When you call an inferior function on an Intel MPX enabled program,
24974GDB sets the inferior's bound registers to the init (disabled) state
24975before calling the function.  As a consequence, bounds checks for the
24976pointer arguments passed to the function will always pass.
24977
24978This is necessary because when you call an inferior function, the
24979program is usually in the middle of the execution of other function.
24980Since at that point bound registers are in an arbitrary state, not
24981clearing them would lead to random bound violations in the called
24982function.
24983
24984You can still examine the influence of the bound registers on the
24985execution of the called function by stopping the execution of the
24986called function at its prologue, setting bound registers, and
24987continuing the execution.  For example:
24988
24989@smallexample
24990	$ break *upper
24991	Breakpoint 2 at 0x4009de: file i386-mpx-call.c, line 47.
24992	$ print upper (a, b, c, d, 1)
24993	Breakpoint 2, upper (a=0x0, b=0x6e0000005b, c=0x0, d=0x0, len=48)....
24994	$ print $bnd0
24995	@{lbound = 0x0, ubound = ffffffff@} : size -1
24996@end smallexample
24997
24998At this last step the value of bnd0 can be changed for investigation of bound
24999violations caused along the execution of the call.  In order to know how to
25000set the bound registers or bound table for the call consult the ABI.
25001
25002@node Alpha
25003@subsection Alpha
25004
25005See the following section.
25006
25007@node MIPS
25008@subsection @acronym{MIPS}
25009
25010@cindex stack on Alpha
25011@cindex stack on @acronym{MIPS}
25012@cindex Alpha stack
25013@cindex @acronym{MIPS} stack
25014Alpha- and @acronym{MIPS}-based computers use an unusual stack frame, which
25015sometimes requires @value{GDBN} to search backward in the object code to
25016find the beginning of a function.
25017
25018@cindex response time, @acronym{MIPS} debugging
25019To improve response time (especially for embedded applications, where
25020@value{GDBN} may be restricted to a slow serial line for this search)
25021you may want to limit the size of this search, using one of these
25022commands:
25023
25024@table @code
25025@cindex @code{heuristic-fence-post} (Alpha, @acronym{MIPS})
25026@item set heuristic-fence-post @var{limit}
25027Restrict @value{GDBN} to examining at most @var{limit} bytes in its
25028search for the beginning of a function.  A value of @var{0} (the
25029default) means there is no limit.  However, except for @var{0}, the
25030larger the limit the more bytes @code{heuristic-fence-post} must search
25031and therefore the longer it takes to run.  You should only need to use
25032this command when debugging a stripped executable.
25033
25034@item show heuristic-fence-post
25035Display the current limit.
25036@end table
25037
25038@noindent
25039These commands are available @emph{only} when @value{GDBN} is configured
25040for debugging programs on Alpha or @acronym{MIPS} processors.
25041
25042Several @acronym{MIPS}-specific commands are available when debugging @acronym{MIPS}
25043programs:
25044
25045@table @code
25046@item set mips abi @var{arg}
25047@kindex set mips abi
25048@cindex set ABI for @acronym{MIPS}
25049Tell @value{GDBN} which @acronym{MIPS} ABI is used by the inferior.  Possible
25050values of @var{arg} are:
25051
25052@table @samp
25053@item auto
25054The default ABI associated with the current binary (this is the
25055default).
25056@item o32
25057@item o64
25058@item n32
25059@item n64
25060@item eabi32
25061@item eabi64
25062@end table
25063
25064@item show mips abi
25065@kindex show mips abi
25066Show the @acronym{MIPS} ABI used by @value{GDBN} to debug the inferior.
25067
25068@item set mips compression @var{arg}
25069@kindex set mips compression
25070@cindex code compression, @acronym{MIPS}
25071Tell @value{GDBN} which @acronym{MIPS} compressed
25072@acronym{ISA, Instruction Set Architecture} encoding is used by the
25073inferior.  @value{GDBN} uses this for code disassembly and other
25074internal interpretation purposes.  This setting is only referred to
25075when no executable has been associated with the debugging session or
25076the executable does not provide information about the encoding it uses.
25077Otherwise this setting is automatically updated from information
25078provided by the executable.
25079
25080Possible values of @var{arg} are @samp{mips16} and @samp{micromips}.
25081The default compressed @acronym{ISA} encoding is @samp{mips16}, as
25082executables containing @acronym{MIPS16} code frequently are not
25083identified as such.
25084
25085This setting is ``sticky''; that is, it retains its value across
25086debugging sessions until reset either explicitly with this command or
25087implicitly from an executable.
25088
25089The compiler and/or assembler typically add symbol table annotations to
25090identify functions compiled for the @acronym{MIPS16} or
25091@acronym{microMIPS} @acronym{ISA}s.  If these function-scope annotations
25092are present, @value{GDBN} uses them in preference to the global
25093compressed @acronym{ISA} encoding setting.
25094
25095@item show mips compression
25096@kindex show mips compression
25097Show the @acronym{MIPS} compressed @acronym{ISA} encoding used by
25098@value{GDBN} to debug the inferior.
25099
25100@item set mipsfpu
25101@itemx show mipsfpu
25102@xref{MIPS Embedded, set mipsfpu}.
25103
25104@item set mips mask-address @var{arg}
25105@kindex set mips mask-address
25106@cindex @acronym{MIPS} addresses, masking
25107This command determines whether the most-significant 32 bits of 64-bit
25108@acronym{MIPS} addresses are masked off.  The argument @var{arg} can be
25109@samp{on}, @samp{off}, or @samp{auto}.  The latter is the default
25110setting, which lets @value{GDBN} determine the correct value.
25111
25112@item show mips mask-address
25113@kindex show mips mask-address
25114Show whether the upper 32 bits of @acronym{MIPS} addresses are masked off or
25115not.
25116
25117@item set remote-mips64-transfers-32bit-regs
25118@kindex set remote-mips64-transfers-32bit-regs
25119This command controls compatibility with 64-bit @acronym{MIPS} targets that
25120transfer data in 32-bit quantities.  If you have an old @acronym{MIPS} 64 target
25121that transfers 32 bits for some registers, like @sc{sr} and @sc{fsr},
25122and 64 bits for other registers, set this option to @samp{on}.
25123
25124@item show remote-mips64-transfers-32bit-regs
25125@kindex show remote-mips64-transfers-32bit-regs
25126Show the current setting of compatibility with older @acronym{MIPS} 64 targets.
25127
25128@item set debug mips
25129@kindex set debug mips
25130This command turns on and off debugging messages for the @acronym{MIPS}-specific
25131target code in @value{GDBN}.
25132
25133@item show debug mips
25134@kindex show debug mips
25135Show the current setting of @acronym{MIPS} debugging messages.
25136@end table
25137
25138
25139@node HPPA
25140@subsection HPPA
25141@cindex HPPA support
25142
25143When @value{GDBN} is debugging the HP PA architecture, it provides the
25144following special commands:
25145
25146@table @code
25147@item set debug hppa
25148@kindex set debug hppa
25149This command determines whether HPPA architecture-specific debugging
25150messages are to be displayed.
25151
25152@item show debug hppa
25153Show whether HPPA debugging messages are displayed.
25154
25155@item maint print unwind @var{address}
25156@kindex maint print unwind@r{, HPPA}
25157This command displays the contents of the unwind table entry at the
25158given @var{address}.
25159
25160@end table
25161
25162
25163@node PowerPC
25164@subsection PowerPC
25165@cindex PowerPC architecture
25166
25167When @value{GDBN} is debugging the PowerPC architecture, it provides a set of
25168pseudo-registers to enable inspection of 128-bit wide Decimal Floating Point
25169numbers stored in the floating point registers. These values must be stored
25170in two consecutive registers, always starting at an even register like
25171@code{f0} or @code{f2}.
25172
25173The pseudo-registers go from @code{$dl0} through @code{$dl15}, and are formed
25174by joining the even/odd register pairs @code{f0} and @code{f1} for @code{$dl0},
25175@code{f2} and @code{f3} for @code{$dl1} and so on.
25176
25177For POWER7 processors, @value{GDBN} provides a set of pseudo-registers, the 64-bit
25178wide Extended Floating Point Registers (@samp{f32} through @samp{f63}).
25179
25180@node Nios II
25181@subsection Nios II
25182@cindex Nios II architecture
25183
25184When @value{GDBN} is debugging the Nios II architecture,
25185it provides the following special commands:
25186
25187@table @code
25188
25189@item set debug nios2
25190@kindex set debug nios2
25191This command turns on and off debugging messages for the Nios II
25192target code in @value{GDBN}.
25193
25194@item show debug nios2
25195@kindex show debug nios2
25196Show the current setting of Nios II debugging messages.
25197@end table
25198
25199@node Sparc64
25200@subsection Sparc64
25201@cindex Sparc64 support
25202@cindex Application Data Integrity
25203@subsubsection ADI Support
25204
25205The M7 processor supports an Application Data Integrity (ADI) feature that
25206detects invalid data accesses.  When software allocates memory and enables
25207ADI on the allocated memory, it chooses a 4-bit version number, sets the
25208version in the upper 4 bits of the 64-bit pointer to that data, and stores
25209the 4-bit version in every cacheline of that data.  Hardware saves the latter
25210in spare bits in the cache and memory hierarchy.  On each load and store,
25211the processor compares the upper 4 VA (virtual address) bits to the
25212cacheline's version.  If there is a mismatch, the processor generates a
25213version mismatch trap which can be either precise or disrupting.  The trap
25214is an error condition which the kernel delivers to the process as a SIGSEGV
25215signal.
25216
25217Note that only 64-bit applications can use ADI and need to be built with
25218ADI-enabled.
25219
25220Values of the ADI version tags, which are in granularity of a
25221cacheline (64 bytes), can be viewed or modified.
25222
25223
25224@table @code
25225@kindex adi examine
25226@item adi (examine | x) [ / @var{n} ] @var{addr}
25227
25228The @code{adi examine} command displays the value of one ADI version tag per
25229cacheline.
25230
25231@var{n} is a decimal integer specifying the number in bytes; the default
25232is 1.  It specifies how much ADI version information, at the ratio of 1:ADI
25233block size, to display.
25234
25235@var{addr} is the address in user address space where you want @value{GDBN}
25236to begin displaying the ADI version tags.
25237
25238Below is an example of displaying ADI versions of variable "shmaddr".
25239
25240@smallexample
25241(@value{GDBP}) adi x/100 shmaddr
25242   0xfff800010002c000:     0 0
25243@end smallexample
25244
25245@kindex adi assign
25246@item adi (assign | a) [ / @var{n} ] @var{addr} = @var{tag}
25247
25248The @code{adi assign} command is used to assign new ADI version tag
25249to an address.
25250
25251@var{n} is a decimal integer specifying the number in bytes;
25252the default is 1.  It specifies how much ADI version information, at the
25253ratio of 1:ADI block size, to modify.
25254
25255@var{addr} is the address in user address space where you want @value{GDBN}
25256to begin modifying the ADI version tags.
25257
25258@var{tag} is the new ADI version tag.
25259
25260For example, do the following to modify then verify ADI versions of
25261variable "shmaddr":
25262
25263@smallexample
25264(@value{GDBP}) adi a/100 shmaddr = 7
25265(@value{GDBP}) adi x/100 shmaddr
25266   0xfff800010002c000:     7 7
25267@end smallexample
25268
25269@end table
25270
25271@node S12Z
25272@subsection S12Z
25273@cindex S12Z support
25274
25275When @value{GDBN} is debugging the S12Z architecture,
25276it provides the following special command:
25277
25278@table @code
25279@item maint info bdccsr
25280@kindex maint info bdccsr@r{, S12Z}
25281This command displays the current value of the microprocessor's
25282BDCCSR register.
25283@end table
25284
25285
25286@node Controlling GDB
25287@chapter Controlling @value{GDBN}
25288
25289You can alter the way @value{GDBN} interacts with you by using the
25290@code{set} command.  For commands controlling how @value{GDBN} displays
25291data, see @ref{Print Settings, ,Print Settings}.  Other settings are
25292described here.
25293
25294@menu
25295* Prompt::                      Prompt
25296* Editing::                     Command editing
25297* Command History::             Command history
25298* Screen Size::                 Screen size
25299* Output Styling::              Output styling
25300* Numbers::                     Numbers
25301* ABI::                         Configuring the current ABI
25302* Auto-loading::                Automatically loading associated files
25303* Messages/Warnings::           Optional warnings and messages
25304* Debugging Output::            Optional messages about internal happenings
25305* Other Misc Settings::         Other Miscellaneous Settings
25306@end menu
25307
25308@node Prompt
25309@section Prompt
25310
25311@cindex prompt
25312
25313@value{GDBN} indicates its readiness to read a command by printing a string
25314called the @dfn{prompt}.  This string is normally @samp{(@value{GDBP})}.  You
25315can change the prompt string with the @code{set prompt} command.  For
25316instance, when debugging @value{GDBN} with @value{GDBN}, it is useful to change
25317the prompt in one of the @value{GDBN} sessions so that you can always tell
25318which one you are talking to.
25319
25320@emph{Note:}  @code{set prompt} does not add a space for you after the
25321prompt you set.  This allows you to set a prompt which ends in a space
25322or a prompt that does not.
25323
25324@table @code
25325@kindex set prompt
25326@item set prompt @var{newprompt}
25327Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
25328
25329@kindex show prompt
25330@item show prompt
25331Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
25332@end table
25333
25334Versions of @value{GDBN} that ship with Python scripting enabled have
25335prompt extensions.  The commands for interacting with these extensions
25336are:
25337
25338@table @code
25339@kindex set extended-prompt
25340@item set extended-prompt @var{prompt}
25341Set an extended prompt that allows for substitutions.
25342@xref{gdb.prompt}, for a list of escape sequences that can be used for
25343substitution.  Any escape sequences specified as part of the prompt
25344string are replaced with the corresponding strings each time the prompt
25345is displayed.
25346
25347For example:
25348
25349@smallexample
25350set extended-prompt Current working directory: \w (gdb)
25351@end smallexample
25352
25353Note that when an extended-prompt is set, it takes control of the
25354@var{prompt_hook} hook.  @xref{prompt_hook}, for further information.
25355
25356@kindex show extended-prompt
25357@item show extended-prompt
25358Prints the extended prompt.  Any escape sequences specified as part of
25359the prompt string with @code{set extended-prompt}, are replaced with the
25360corresponding strings each time the prompt is displayed.
25361@end table
25362
25363@node Editing
25364@section Command Editing
25365@cindex readline
25366@cindex command line editing
25367
25368@value{GDBN} reads its input commands via the @dfn{Readline} interface.  This
25369@sc{gnu} library provides consistent behavior for programs which provide a
25370command line interface to the user.  Advantages are @sc{gnu} Emacs-style
25371or @dfn{vi}-style inline editing of commands, @code{csh}-like history
25372substitution, and a storage and recall of command history across
25373debugging sessions.
25374
25375You may control the behavior of command line editing in @value{GDBN} with the
25376command @code{set}.
25377
25378@table @code
25379@kindex set editing
25380@cindex editing
25381@item set editing
25382@itemx set editing on
25383Enable command line editing (enabled by default).
25384
25385@item set editing off
25386Disable command line editing.
25387
25388@kindex show editing
25389@item show editing
25390Show whether command line editing is enabled.
25391@end table
25392
25393@ifset SYSTEM_READLINE
25394@xref{Command Line Editing, , , rluserman, GNU Readline Library},
25395@end ifset
25396@ifclear SYSTEM_READLINE
25397@xref{Command Line Editing},
25398@end ifclear
25399for more details about the Readline
25400interface.  Users unfamiliar with @sc{gnu} Emacs or @code{vi} are
25401encouraged to read that chapter.
25402
25403@cindex Readline application name
25404@value{GDBN} sets the Readline application name to @samp{gdb}.  This
25405is useful for conditions in @file{.inputrc}.
25406
25407@cindex operate-and-get-next
25408@value{GDBN} defines a bindable Readline command,
25409@code{operate-and-get-next}.  This is bound to @kbd{C-o} by default.
25410This command accepts the current line for execution and fetches the
25411next line relative to the current line from the history for editing.
25412Any argument is ignored.
25413
25414@node Command History
25415@section Command History
25416@cindex command history
25417
25418@value{GDBN} can keep track of the commands you type during your
25419debugging sessions, so that you can be certain of precisely what
25420happened.  Use these commands to manage the @value{GDBN} command
25421history facility.
25422
25423@value{GDBN} uses the @sc{gnu} History library, a part of the Readline
25424package, to provide the history facility.
25425@ifset SYSTEM_READLINE
25426@xref{Using History Interactively, , , history, GNU History Library},
25427@end ifset
25428@ifclear SYSTEM_READLINE
25429@xref{Using History Interactively},
25430@end ifclear
25431for the detailed description of the History library.
25432
25433To issue a command to @value{GDBN} without affecting certain aspects of
25434the state which is seen by users, prefix it with @samp{server }
25435(@pxref{Server Prefix}).  This
25436means that this command will not affect the command history, nor will it
25437affect @value{GDBN}'s notion of which command to repeat if @key{RET} is
25438pressed on a line by itself.
25439
25440@cindex @code{server}, command prefix
25441The server prefix does not affect the recording of values into the value
25442history; to print a value without recording it into the value history,
25443use the @code{output} command instead of the @code{print} command.
25444
25445Here is the description of @value{GDBN} commands related to command
25446history.
25447
25448@table @code
25449@cindex history substitution
25450@cindex history file
25451@kindex set history filename
25452@cindex @env{GDBHISTFILE}, environment variable
25453@item set history filename @r{[}@var{fname}@r{]}
25454Set the name of the @value{GDBN} command history file to @var{fname}.
25455This is the file where @value{GDBN} reads an initial command history
25456list, and where it writes the command history from this session when it
25457exits.  You can access this list through history expansion or through
25458the history command editing characters listed below.  This file defaults
25459to the value of the environment variable @code{GDBHISTFILE}, or to
25460@file{./.gdb_history} (@file{./_gdb_history} on MS-DOS) if this variable
25461is not set.
25462
25463The @code{GDBHISTFILE} environment variable is read after processing
25464any @value{GDBN} initialization files (@pxref{Startup}) and after
25465processing any commands passed using command line options (for
25466example, @code{-ex}).
25467
25468If the @var{fname} argument is not given, or if the @code{GDBHISTFILE}
25469is the empty string then @value{GDBN} will neither try to load an
25470existing history file, nor will it try to save the history on exit.
25471
25472@cindex save command history
25473@kindex set history save
25474@item set history save
25475@itemx set history save on
25476Record command history in a file, whose name may be specified with the
25477@code{set history filename} command.  By default, this option is
25478disabled.  The command history will be recorded when @value{GDBN}
25479exits.  If @code{set history filename} is set to the empty string then
25480history saving is disabled, even when @code{set history save} is
25481@code{on}.
25482
25483@item set history save off
25484Don't record the command history into the file specified by @code{set
25485history filename} when @value{GDBN} exits.
25486
25487@cindex history size
25488@kindex set history size
25489@cindex @env{GDBHISTSIZE}, environment variable
25490@item set history size @var{size}
25491@itemx set history size unlimited
25492Set the number of commands which @value{GDBN} keeps in its history list.
25493This defaults to the value of the environment variable @env{GDBHISTSIZE}, or
25494to 256 if this variable is not set.  Non-numeric values of @env{GDBHISTSIZE}
25495are ignored.  If @var{size} is @code{unlimited} or if @env{GDBHISTSIZE} is
25496either a negative number or the empty string, then the number of commands
25497@value{GDBN} keeps in the history list is unlimited.
25498
25499The @code{GDBHISTSIZE} environment variable is read after processing
25500any @value{GDBN} initialization files (@pxref{Startup}) and after
25501processing any commands passed using command line options (for
25502example, @code{-ex}).
25503
25504@cindex remove duplicate history
25505@kindex set history remove-duplicates
25506@item set history remove-duplicates @var{count}
25507@itemx set history remove-duplicates unlimited
25508Control the removal of duplicate history entries in the command history list.
25509If @var{count} is non-zero, @value{GDBN} will look back at the last @var{count}
25510history entries and remove the first entry that is a duplicate of the current
25511entry being added to the command history list.  If @var{count} is
25512@code{unlimited} then this lookbehind is unbounded.  If @var{count} is 0, then
25513removal of duplicate history entries is disabled.
25514
25515Only history entries added during the current session are considered for
25516removal.  This option is set to 0 by default.
25517
25518@end table
25519
25520History expansion assigns special meaning to the character @kbd{!}.
25521@ifset SYSTEM_READLINE
25522@xref{Event Designators, , , history, GNU History Library},
25523@end ifset
25524@ifclear SYSTEM_READLINE
25525@xref{Event Designators},
25526@end ifclear
25527for more details.
25528
25529@cindex history expansion, turn on/off
25530Since @kbd{!} is also the logical not operator in C, history expansion
25531is off by default. If you decide to enable history expansion with the
25532@code{set history expansion on} command, you may sometimes need to
25533follow @kbd{!} (when it is used as logical not, in an expression) with
25534a space or a tab to prevent it from being expanded.  The readline
25535history facilities do not attempt substitution on the strings
25536@kbd{!=} and @kbd{!(}, even when history expansion is enabled.
25537
25538The commands to control history expansion are:
25539
25540@table @code
25541@item set history expansion on
25542@itemx set history expansion
25543@kindex set history expansion
25544Enable history expansion.  History expansion is off by default.
25545
25546@item set history expansion off
25547Disable history expansion.
25548
25549@c @group
25550@kindex show history
25551@item show history
25552@itemx show history filename
25553@itemx show history save
25554@itemx show history size
25555@itemx show history expansion
25556These commands display the state of the @value{GDBN} history parameters.
25557@code{show history} by itself displays all four states.
25558@c @end group
25559@end table
25560
25561@table @code
25562@kindex show commands
25563@cindex show last commands
25564@cindex display command history
25565@item show commands
25566Display the last ten commands in the command history.
25567
25568@item show commands @var{n}
25569Print ten commands centered on command number @var{n}.
25570
25571@item show commands +
25572Print ten commands just after the commands last printed.
25573@end table
25574
25575@node Screen Size
25576@section Screen Size
25577@cindex size of screen
25578@cindex screen size
25579@cindex pagination
25580@cindex page size
25581@cindex pauses in output
25582
25583Certain commands to @value{GDBN} may produce large amounts of
25584information output to the screen.  To help you read all of it,
25585@value{GDBN} pauses and asks you for input at the end of each page of
25586output.  Type @key{RET} when you want to see one more page of output,
25587@kbd{q} to discard the remaining output, or @kbd{c} to continue
25588without paging for the rest of the current command.  Also, the screen
25589width setting determines when to wrap lines of output.  Depending on
25590what is being printed, @value{GDBN} tries to break the line at a
25591readable place, rather than simply letting it overflow onto the
25592following line.
25593
25594Normally @value{GDBN} knows the size of the screen from the terminal
25595driver software.  For example, on Unix @value{GDBN} uses the termcap data base
25596together with the value of the @code{TERM} environment variable and the
25597@code{stty rows} and @code{stty cols} settings.  If this is not correct,
25598you can override it with the @code{set height} and @code{set
25599width} commands:
25600
25601@table @code
25602@kindex set height
25603@kindex set width
25604@kindex show width
25605@kindex show height
25606@item set height @var{lpp}
25607@itemx set height unlimited
25608@itemx show height
25609@itemx set width @var{cpl}
25610@itemx set width unlimited
25611@itemx show width
25612These @code{set} commands specify a screen height of @var{lpp} lines and
25613a screen width of @var{cpl} characters.  The associated @code{show}
25614commands display the current settings.
25615
25616If you specify a height of either @code{unlimited} or zero lines,
25617@value{GDBN} does not pause during output no matter how long the
25618output is.  This is useful if output is to a file or to an editor
25619buffer.
25620
25621Likewise, you can specify @samp{set width unlimited} or @samp{set
25622width 0} to prevent @value{GDBN} from wrapping its output.
25623
25624@item set pagination on
25625@itemx set pagination off
25626@kindex set pagination
25627Turn the output pagination on or off; the default is on.  Turning
25628pagination off is the alternative to @code{set height unlimited}.  Note that
25629running @value{GDBN} with the @option{--batch} option (@pxref{Mode
25630Options, -batch}) also automatically disables pagination.
25631
25632@item show pagination
25633@kindex show pagination
25634Show the current pagination mode.
25635@end table
25636
25637@node Output Styling
25638@section Output Styling
25639@cindex styling
25640@cindex colors
25641
25642@kindex set style
25643@kindex show style
25644@value{GDBN} can style its output on a capable terminal.  This is
25645enabled by default on most systems, but disabled by default when in
25646batch mode (@pxref{Mode Options}).  Various style settings are available;
25647and styles can also be disabled entirely.
25648
25649@table @code
25650@item set style enabled @samp{on|off}
25651Enable or disable all styling.  The default is host-dependent, with
25652most hosts defaulting to @samp{on}.
25653
25654@item show style enabled
25655Show the current state of styling.
25656
25657@item set style sources @samp{on|off}
25658Enable or disable source code styling.  This affects whether source
25659code, such as the output of the @code{list} command, is styled.  Note
25660that source styling only works if styling in general is enabled, and
25661if @value{GDBN} was linked with the GNU Source Highlight library.  The
25662default is @samp{on}.
25663
25664@item show style sources
25665Show the current state of source code styling.
25666@end table
25667
25668Subcommands of @code{set style} control specific forms of styling.
25669These subcommands all follow the same pattern: each style-able object
25670can be styled with a foreground color, a background color, and an
25671intensity.
25672
25673For example, the style of file names can be controlled using the
25674@code{set style filename} group of commands:
25675
25676@table @code
25677@item set style filename background @var{color}
25678Set the background to @var{color}.  Valid colors are @samp{none}
25679(meaning the terminal's default color), @samp{black}, @samp{red},
25680@samp{green}, @samp{yellow}, @samp{blue}, @samp{magenta}, @samp{cyan},
25681and@samp{white}.
25682
25683@item set style filename foreground @var{color}
25684Set the foreground to @var{color}.  Valid colors are @samp{none}
25685(meaning the terminal's default color), @samp{black}, @samp{red},
25686@samp{green}, @samp{yellow}, @samp{blue}, @samp{magenta}, @samp{cyan},
25687and@samp{white}.
25688
25689@item set style filename intensity @var{value}
25690Set the intensity to @var{value}.  Valid intensities are @samp{normal}
25691(the default), @samp{bold}, and @samp{dim}.
25692@end table
25693
25694The @code{show style} command and its subcommands are styling
25695a style name in their output using its own style.
25696So, use @command{show style} to see the complete list of styles,
25697their characteristics and the visual aspect of each style.
25698
25699The style-able objects are:
25700@table @code
25701@item filename
25702Control the styling of file names.  By default, this style's
25703foreground color is green.
25704
25705@item function
25706Control the styling of function names.  These are managed with the
25707@code{set style function} family of commands.  By default, this
25708style's foreground color is yellow.
25709
25710@item variable
25711Control the styling of variable names.  These are managed with the
25712@code{set style variable} family of commands.  By default, this style's
25713foreground color is cyan.
25714
25715@item address
25716Control the styling of addresses.  These are managed with the
25717@code{set style address} family of commands.  By default, this style's
25718foreground color is blue.
25719
25720@item title
25721Control the styling of titles.  These are managed with the
25722@code{set style title} family of commands.  By default, this style's
25723intensity is bold.  Commands are using the title style to improve
25724the readability of large output.  For example, the commands
25725@command{apropos} and @command{help} are using the title style
25726for the command names.
25727
25728@item highlight
25729Control the styling of highlightings.  These are managed with the
25730@code{set style highlight} family of commands.  By default, this style's
25731foreground color is red.  Commands are using the highlight style to draw
25732the user attention to some specific parts of their output.  For example,
25733the command @command{apropos -v REGEXP} uses the highlight style to
25734mark the documentation parts matching @var{regexp}.
25735
25736@item tui-border
25737Control the styling of the TUI border.  Note that, unlike other
25738styling options, only the color of the border can be controlled via
25739@code{set style}.  This was done for compatibility reasons, as TUI
25740controls to set the border's intensity predated the addition of
25741general styling to @value{GDBN}.  @xref{TUI Configuration}.
25742
25743@item tui-active-border
25744Control the styling of the active TUI border; that is, the TUI window
25745that has the focus.
25746
25747@end table
25748
25749@node Numbers
25750@section Numbers
25751@cindex number representation
25752@cindex entering numbers
25753
25754You can always enter numbers in octal, decimal, or hexadecimal in
25755@value{GDBN} by the usual conventions: octal numbers begin with
25756@samp{0}, decimal numbers end with @samp{.}, and hexadecimal numbers
25757begin with @samp{0x}.  Numbers that neither begin with @samp{0} or
25758@samp{0x}, nor end with a @samp{.} are, by default, entered in base
2575910; likewise, the default display for numbers---when no particular
25760format is specified---is base 10.  You can change the default base for
25761both input and output with the commands described below.
25762
25763@table @code
25764@kindex set input-radix
25765@item set input-radix @var{base}
25766Set the default base for numeric input.  Supported choices
25767for @var{base} are decimal 8, 10, or 16.  The base must itself be
25768specified either unambiguously or using the current input radix; for
25769example, any of
25770
25771@smallexample
25772set input-radix 012
25773set input-radix 10.
25774set input-radix 0xa
25775@end smallexample
25776
25777@noindent
25778sets the input base to decimal.  On the other hand, @samp{set input-radix 10}
25779leaves the input radix unchanged, no matter what it was, since
25780@samp{10}, being without any leading or trailing signs of its base, is
25781interpreted in the current radix.  Thus, if the current radix is 16,
25782@samp{10} is interpreted in hex, i.e.@: as 16 decimal, which doesn't
25783change the radix.
25784
25785@kindex set output-radix
25786@item set output-radix @var{base}
25787Set the default base for numeric display.  Supported choices
25788for @var{base} are decimal 8, 10, or 16.  The base must itself be
25789specified either unambiguously or using the current input radix.
25790
25791@kindex show input-radix
25792@item show input-radix
25793Display the current default base for numeric input.
25794
25795@kindex show output-radix
25796@item show output-radix
25797Display the current default base for numeric display.
25798
25799@item set radix @r{[}@var{base}@r{]}
25800@itemx show radix
25801@kindex set radix
25802@kindex show radix
25803These commands set and show the default base for both input and output
25804of numbers.  @code{set radix} sets the radix of input and output to
25805the same base; without an argument, it resets the radix back to its
25806default value of 10.
25807
25808@end table
25809
25810@node ABI
25811@section Configuring the Current ABI
25812
25813@value{GDBN} can determine the @dfn{ABI} (Application Binary Interface) of your
25814application automatically.  However, sometimes you need to override its
25815conclusions.  Use these commands to manage @value{GDBN}'s view of the
25816current ABI.
25817
25818@cindex OS ABI
25819@kindex set osabi
25820@kindex show osabi
25821@cindex Newlib OS ABI and its influence on the longjmp handling
25822
25823One @value{GDBN} configuration can debug binaries for multiple operating
25824system targets, either via remote debugging or native emulation.
25825@value{GDBN} will autodetect the @dfn{OS ABI} (Operating System ABI) in use,
25826but you can override its conclusion using the @code{set osabi} command.
25827One example where this is useful is in debugging of binaries which use
25828an alternate C library (e.g.@: @sc{uClibc} for @sc{gnu}/Linux) which does
25829not have the same identifying marks that the standard C library for your
25830platform provides.
25831
25832When @value{GDBN} is debugging the AArch64 architecture, it provides a
25833``Newlib'' OS ABI.  This is useful for handling @code{setjmp} and
25834@code{longjmp} when debugging binaries that use the @sc{newlib} C library.
25835The ``Newlib'' OS ABI can be selected by @code{set osabi Newlib}.
25836
25837@table @code
25838@item show osabi
25839Show the OS ABI currently in use.
25840
25841@item set osabi
25842With no argument, show the list of registered available OS ABI's.
25843
25844@item set osabi @var{abi}
25845Set the current OS ABI to @var{abi}.
25846@end table
25847
25848@cindex float promotion
25849
25850Generally, the way that an argument of type @code{float} is passed to a
25851function depends on whether the function is prototyped.  For a prototyped
25852(i.e.@: ANSI/ISO style) function, @code{float} arguments are passed unchanged,
25853according to the architecture's convention for @code{float}.  For unprototyped
25854(i.e.@: K&R style) functions, @code{float} arguments are first promoted to type
25855@code{double} and then passed.
25856
25857Unfortunately, some forms of debug information do not reliably indicate whether
25858a function is prototyped.  If @value{GDBN} calls a function that is not marked
25859as prototyped, it consults @kbd{set coerce-float-to-double}.
25860
25861@table @code
25862@kindex set coerce-float-to-double
25863@item set coerce-float-to-double
25864@itemx set coerce-float-to-double on
25865Arguments of type @code{float} will be promoted to @code{double} when passed
25866to an unprototyped function.  This is the default setting.
25867
25868@item set coerce-float-to-double off
25869Arguments of type @code{float} will be passed directly to unprototyped
25870functions.
25871
25872@kindex show coerce-float-to-double
25873@item show coerce-float-to-double
25874Show the current setting of promoting @code{float} to @code{double}.
25875@end table
25876
25877@kindex set cp-abi
25878@kindex show cp-abi
25879@value{GDBN} needs to know the ABI used for your program's C@t{++}
25880objects.  The correct C@t{++} ABI depends on which C@t{++} compiler was
25881used to build your application.  @value{GDBN} only fully supports
25882programs with a single C@t{++} ABI; if your program contains code using
25883multiple C@t{++} ABI's or if @value{GDBN} can not identify your
25884program's ABI correctly, you can tell @value{GDBN} which ABI to use.
25885Currently supported ABI's include ``gnu-v2'', for @code{g++} versions
25886before 3.0, ``gnu-v3'', for @code{g++} versions 3.0 and later, and
25887``hpaCC'' for the HP ANSI C@t{++} compiler.  Other C@t{++} compilers may
25888use the ``gnu-v2'' or ``gnu-v3'' ABI's as well.  The default setting is
25889``auto''.
25890
25891@table @code
25892@item show cp-abi
25893Show the C@t{++} ABI currently in use.
25894
25895@item set cp-abi
25896With no argument, show the list of supported C@t{++} ABI's.
25897
25898@item set cp-abi @var{abi}
25899@itemx set cp-abi auto
25900Set the current C@t{++} ABI to @var{abi}, or return to automatic detection.
25901@end table
25902
25903@node Auto-loading
25904@section Automatically loading associated files
25905@cindex auto-loading
25906
25907@value{GDBN} sometimes reads files with commands and settings automatically,
25908without being explicitly told so by the user.  We call this feature
25909@dfn{auto-loading}.  While auto-loading is useful for automatically adapting
25910@value{GDBN} to the needs of your project, it can sometimes produce unexpected
25911results or introduce security risks (e.g., if the file comes from untrusted
25912sources).
25913
25914@menu
25915* Init File in the Current Directory:: @samp{set/show/info auto-load local-gdbinit}
25916* libthread_db.so.1 file::             @samp{set/show/info auto-load libthread-db}
25917
25918* Auto-loading safe path::             @samp{set/show/info auto-load safe-path}
25919* Auto-loading verbose mode::          @samp{set/show debug auto-load}
25920@end menu
25921
25922There are various kinds of files @value{GDBN} can automatically load.
25923In addition to these files, @value{GDBN} supports auto-loading code written
25924in various extension languages.  @xref{Auto-loading extensions}.
25925
25926Note that loading of these associated files (including the local @file{.gdbinit}
25927file) requires accordingly configured @code{auto-load safe-path}
25928(@pxref{Auto-loading safe path}).
25929
25930For these reasons, @value{GDBN} includes commands and options to let you
25931control when to auto-load files and which files should be auto-loaded.
25932
25933@table @code
25934@anchor{set auto-load off}
25935@kindex set auto-load off
25936@item set auto-load off
25937Globally disable loading of all auto-loaded files.
25938You may want to use this command with the @samp{-iex} option
25939(@pxref{Option -init-eval-command}) such as:
25940@smallexample
25941$ @kbd{gdb -iex "set auto-load off" untrusted-executable corefile}
25942@end smallexample
25943
25944Be aware that system init file (@pxref{System-wide configuration})
25945and init files from your home directory (@pxref{Home Directory Init File})
25946still get read (as they come from generally trusted directories).
25947To prevent @value{GDBN} from auto-loading even those init files, use the
25948@option{-nx} option (@pxref{Mode Options}), in addition to
25949@code{set auto-load no}.
25950
25951@anchor{show auto-load}
25952@kindex show auto-load
25953@item show auto-load
25954Show whether auto-loading of each specific @samp{auto-load} file(s) is enabled
25955or disabled.
25956
25957@smallexample
25958(gdb) show auto-load
25959gdb-scripts:  Auto-loading of canned sequences of commands scripts is on.
25960libthread-db:  Auto-loading of inferior specific libthread_db is on.
25961local-gdbinit:  Auto-loading of .gdbinit script from current directory
25962                is on.
25963python-scripts:  Auto-loading of Python scripts is on.
25964safe-path:  List of directories from which it is safe to auto-load files
25965            is $debugdir:$datadir/auto-load.
25966scripts-directory:  List of directories from which to load auto-loaded scripts
25967                    is $debugdir:$datadir/auto-load.
25968@end smallexample
25969
25970@anchor{info auto-load}
25971@kindex info auto-load
25972@item info auto-load
25973Print whether each specific @samp{auto-load} file(s) have been auto-loaded or
25974not.
25975
25976@smallexample
25977(gdb) info auto-load
25978gdb-scripts:
25979Loaded  Script
25980Yes     /home/user/gdb/gdb-gdb.gdb
25981libthread-db:  No auto-loaded libthread-db.
25982local-gdbinit:  Local .gdbinit file "/home/user/gdb/.gdbinit" has been
25983                loaded.
25984python-scripts:
25985Loaded  Script
25986Yes     /home/user/gdb/gdb-gdb.py
25987@end smallexample
25988@end table
25989
25990These are @value{GDBN} control commands for the auto-loading:
25991
25992@multitable @columnfractions .5 .5
25993@item @xref{set auto-load off}.
25994@tab Disable auto-loading globally.
25995@item @xref{show auto-load}.
25996@tab Show setting of all kinds of files.
25997@item @xref{info auto-load}.
25998@tab Show state of all kinds of files.
25999@item @xref{set auto-load gdb-scripts}.
26000@tab Control for @value{GDBN} command scripts.
26001@item @xref{show auto-load gdb-scripts}.
26002@tab Show setting of @value{GDBN} command scripts.
26003@item @xref{info auto-load gdb-scripts}.
26004@tab Show state of @value{GDBN} command scripts.
26005@item @xref{set auto-load python-scripts}.
26006@tab Control for @value{GDBN} Python scripts.
26007@item @xref{show auto-load python-scripts}.
26008@tab Show setting of @value{GDBN} Python scripts.
26009@item @xref{info auto-load python-scripts}.
26010@tab Show state of @value{GDBN} Python scripts.
26011@item @xref{set auto-load guile-scripts}.
26012@tab Control for @value{GDBN} Guile scripts.
26013@item @xref{show auto-load guile-scripts}.
26014@tab Show setting of @value{GDBN} Guile scripts.
26015@item @xref{info auto-load guile-scripts}.
26016@tab Show state of @value{GDBN} Guile scripts.
26017@item @xref{set auto-load scripts-directory}.
26018@tab Control for @value{GDBN} auto-loaded scripts location.
26019@item @xref{show auto-load scripts-directory}.
26020@tab Show @value{GDBN} auto-loaded scripts location.
26021@item @xref{add-auto-load-scripts-directory}.
26022@tab Add directory for auto-loaded scripts location list.
26023@item @xref{set auto-load local-gdbinit}.
26024@tab Control for init file in the current directory.
26025@item @xref{show auto-load local-gdbinit}.
26026@tab Show setting of init file in the current directory.
26027@item @xref{info auto-load local-gdbinit}.
26028@tab Show state of init file in the current directory.
26029@item @xref{set auto-load libthread-db}.
26030@tab Control for thread debugging library.
26031@item @xref{show auto-load libthread-db}.
26032@tab Show setting of thread debugging library.
26033@item @xref{info auto-load libthread-db}.
26034@tab Show state of thread debugging library.
26035@item @xref{set auto-load safe-path}.
26036@tab Control directories trusted for automatic loading.
26037@item @xref{show auto-load safe-path}.
26038@tab Show directories trusted for automatic loading.
26039@item @xref{add-auto-load-safe-path}.
26040@tab Add directory trusted for automatic loading.
26041@end multitable
26042
26043@node Init File in the Current Directory
26044@subsection Automatically loading init file in the current directory
26045@cindex auto-loading init file in the current directory
26046
26047By default, @value{GDBN} reads and executes the canned sequences of commands
26048from init file (if any) in the current working directory,
26049see @ref{Init File in the Current Directory during Startup}.
26050
26051Note that loading of this local @file{.gdbinit} file also requires accordingly
26052configured @code{auto-load safe-path} (@pxref{Auto-loading safe path}).
26053
26054@table @code
26055@anchor{set auto-load local-gdbinit}
26056@kindex set auto-load local-gdbinit
26057@item set auto-load local-gdbinit [on|off]
26058Enable or disable the auto-loading of canned sequences of commands
26059(@pxref{Sequences}) found in init file in the current directory.
26060
26061@anchor{show auto-load local-gdbinit}
26062@kindex show auto-load local-gdbinit
26063@item show auto-load local-gdbinit
26064Show whether auto-loading of canned sequences of commands from init file in the
26065current directory is enabled or disabled.
26066
26067@anchor{info auto-load local-gdbinit}
26068@kindex info auto-load local-gdbinit
26069@item info auto-load local-gdbinit
26070Print whether canned sequences of commands from init file in the
26071current directory have been auto-loaded.
26072@end table
26073
26074@node libthread_db.so.1 file
26075@subsection Automatically loading thread debugging library
26076@cindex auto-loading libthread_db.so.1
26077
26078This feature is currently present only on @sc{gnu}/Linux native hosts.
26079
26080@value{GDBN} reads in some cases thread debugging library from places specific
26081to the inferior (@pxref{set libthread-db-search-path}).
26082
26083The special @samp{libthread-db-search-path} entry @samp{$sdir} is processed
26084without checking this @samp{set auto-load libthread-db} switch as system
26085libraries have to be trusted in general.  In all other cases of
26086@samp{libthread-db-search-path} entries @value{GDBN} checks first if @samp{set
26087auto-load libthread-db} is enabled before trying to open such thread debugging
26088library.
26089
26090Note that loading of this debugging library also requires accordingly configured
26091@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
26092
26093@table @code
26094@anchor{set auto-load libthread-db}
26095@kindex set auto-load libthread-db
26096@item set auto-load libthread-db [on|off]
26097Enable or disable the auto-loading of inferior specific thread debugging library.
26098
26099@anchor{show auto-load libthread-db}
26100@kindex show auto-load libthread-db
26101@item show auto-load libthread-db
26102Show whether auto-loading of inferior specific thread debugging library is
26103enabled or disabled.
26104
26105@anchor{info auto-load libthread-db}
26106@kindex info auto-load libthread-db
26107@item info auto-load libthread-db
26108Print the list of all loaded inferior specific thread debugging libraries and
26109for each such library print list of inferior @var{pid}s using it.
26110@end table
26111
26112@node Auto-loading safe path
26113@subsection Security restriction for auto-loading
26114@cindex auto-loading safe-path
26115
26116As the files of inferior can come from untrusted source (such as submitted by
26117an application user) @value{GDBN} does not always load any files automatically.
26118@value{GDBN} provides the @samp{set auto-load safe-path} setting to list
26119directories trusted for loading files not explicitly requested by user.
26120Each directory can also be a shell wildcard pattern.
26121
26122If the path is not set properly you will see a warning and the file will not
26123get loaded:
26124
26125@smallexample
26126$ ./gdb -q ./gdb
26127Reading symbols from /home/user/gdb/gdb...
26128warning: File "/home/user/gdb/gdb-gdb.gdb" auto-loading has been
26129         declined by your `auto-load safe-path' set
26130         to "$debugdir:$datadir/auto-load".
26131warning: File "/home/user/gdb/gdb-gdb.py" auto-loading has been
26132         declined by your `auto-load safe-path' set
26133         to "$debugdir:$datadir/auto-load".
26134@end smallexample
26135
26136@noindent
26137To instruct @value{GDBN} to go ahead and use the init files anyway,
26138invoke @value{GDBN} like this:
26139
26140@smallexample
26141$ gdb -q -iex "set auto-load safe-path /home/user/gdb" ./gdb
26142@end smallexample
26143
26144The list of trusted directories is controlled by the following commands:
26145
26146@table @code
26147@anchor{set auto-load safe-path}
26148@kindex set auto-load safe-path
26149@item set auto-load safe-path @r{[}@var{directories}@r{]}
26150Set the list of directories (and their subdirectories) trusted for automatic
26151loading and execution of scripts.  You can also enter a specific trusted file.
26152Each directory can also be a shell wildcard pattern; wildcards do not match
26153directory separator - see @code{FNM_PATHNAME} for system function @code{fnmatch}
26154(@pxref{Wildcard Matching, fnmatch, , libc, GNU C Library Reference Manual}).
26155If you omit @var{directories}, @samp{auto-load safe-path} will be reset to
26156its default value as specified during @value{GDBN} compilation.
26157
26158The list of directories uses path separator (@samp{:} on GNU and Unix
26159systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
26160to the @env{PATH} environment variable.
26161
26162@anchor{show auto-load safe-path}
26163@kindex show auto-load safe-path
26164@item show auto-load safe-path
26165Show the list of directories trusted for automatic loading and execution of
26166scripts.
26167
26168@anchor{add-auto-load-safe-path}
26169@kindex add-auto-load-safe-path
26170@item add-auto-load-safe-path
26171Add an entry (or list of entries) to the list of directories trusted for
26172automatic loading and execution of scripts.  Multiple entries may be delimited
26173by the host platform path separator in use.
26174@end table
26175
26176This variable defaults to what @code{--with-auto-load-dir} has been configured
26177to (@pxref{with-auto-load-dir}).  @file{$debugdir} and @file{$datadir}
26178substitution applies the same as for @ref{set auto-load scripts-directory}.
26179The default @code{set auto-load safe-path} value can be also overriden by
26180@value{GDBN} configuration option @option{--with-auto-load-safe-path}.
26181
26182Setting this variable to @file{/} disables this security protection,
26183corresponding @value{GDBN} configuration option is
26184@option{--without-auto-load-safe-path}.
26185This variable is supposed to be set to the system directories writable by the
26186system superuser only.  Users can add their source directories in init files in
26187their home directories (@pxref{Home Directory Init File}).  See also deprecated
26188init file in the current directory
26189(@pxref{Init File in the Current Directory during Startup}).
26190
26191To force @value{GDBN} to load the files it declined to load in the previous
26192example, you could use one of the following ways:
26193
26194@table @asis
26195@item @file{~/.gdbinit}: @samp{add-auto-load-safe-path ~/src/gdb}
26196Specify this trusted directory (or a file) as additional component of the list.
26197You have to specify also any existing directories displayed by
26198by @samp{show auto-load safe-path} (such as @samp{/usr:/bin} in this example).
26199
26200@item @kbd{gdb -iex "set auto-load safe-path /usr:/bin:~/src/gdb" @dots{}}
26201Specify this directory as in the previous case but just for a single
26202@value{GDBN} session.
26203
26204@item @kbd{gdb -iex "set auto-load safe-path /" @dots{}}
26205Disable auto-loading safety for a single @value{GDBN} session.
26206This assumes all the files you debug during this @value{GDBN} session will come
26207from trusted sources.
26208
26209@item @kbd{./configure --without-auto-load-safe-path}
26210During compilation of @value{GDBN} you may disable any auto-loading safety.
26211This assumes all the files you will ever debug with this @value{GDBN} come from
26212trusted sources.
26213@end table
26214
26215On the other hand you can also explicitly forbid automatic files loading which
26216also suppresses any such warning messages:
26217
26218@table @asis
26219@item @kbd{gdb -iex "set auto-load no" @dots{}}
26220You can use @value{GDBN} command-line option for a single @value{GDBN} session.
26221
26222@item @file{~/.gdbinit}: @samp{set auto-load no}
26223Disable auto-loading globally for the user
26224(@pxref{Home Directory Init File}).  While it is improbable, you could also
26225use system init file instead (@pxref{System-wide configuration}).
26226@end table
26227
26228This setting applies to the file names as entered by user.  If no entry matches
26229@value{GDBN} tries as a last resort to also resolve all the file names into
26230their canonical form (typically resolving symbolic links) and compare the
26231entries again.  @value{GDBN} already canonicalizes most of the filenames on its
26232own before starting the comparison so a canonical form of directories is
26233recommended to be entered.
26234
26235@node Auto-loading verbose mode
26236@subsection Displaying files tried for auto-load
26237@cindex auto-loading verbose mode
26238
26239For better visibility of all the file locations where you can place scripts to
26240be auto-loaded with inferior --- or to protect yourself against accidental
26241execution of untrusted scripts --- @value{GDBN} provides a feature for printing
26242all the files attempted to be loaded.  Both existing and non-existing files may
26243be printed.
26244
26245For example the list of directories from which it is safe to auto-load files
26246(@pxref{Auto-loading safe path}) applies also to canonicalized filenames which
26247may not be too obvious while setting it up.
26248
26249@smallexample
26250(gdb) set debug auto-load on
26251(gdb) file ~/src/t/true
26252auto-load: Loading canned sequences of commands script "/tmp/true-gdb.gdb"
26253           for objfile "/tmp/true".
26254auto-load: Updating directories of "/usr:/opt".
26255auto-load: Using directory "/usr".
26256auto-load: Using directory "/opt".
26257warning: File "/tmp/true-gdb.gdb" auto-loading has been declined
26258         by your `auto-load safe-path' set to "/usr:/opt".
26259@end smallexample
26260
26261@table @code
26262@anchor{set debug auto-load}
26263@kindex set debug auto-load
26264@item set debug auto-load [on|off]
26265Set whether to print the filenames attempted to be auto-loaded.
26266
26267@anchor{show debug auto-load}
26268@kindex show debug auto-load
26269@item show debug auto-load
26270Show whether printing of the filenames attempted to be auto-loaded is turned
26271on or off.
26272@end table
26273
26274@node Messages/Warnings
26275@section Optional Warnings and Messages
26276
26277@cindex verbose operation
26278@cindex optional warnings
26279By default, @value{GDBN} is silent about its inner workings.  If you are
26280running on a slow machine, you may want to use the @code{set verbose}
26281command.  This makes @value{GDBN} tell you when it does a lengthy
26282internal operation, so you will not think it has crashed.
26283
26284Currently, the messages controlled by @code{set verbose} are those
26285which announce that the symbol table for a source file is being read;
26286see @code{symbol-file} in @ref{Files, ,Commands to Specify Files}.
26287
26288@table @code
26289@kindex set verbose
26290@item set verbose on
26291Enables @value{GDBN} output of certain informational messages.
26292
26293@item set verbose off
26294Disables @value{GDBN} output of certain informational messages.
26295
26296@kindex show verbose
26297@item show verbose
26298Displays whether @code{set verbose} is on or off.
26299@end table
26300
26301By default, if @value{GDBN} encounters bugs in the symbol table of an
26302object file, it is silent; but if you are debugging a compiler, you may
26303find this information useful (@pxref{Symbol Errors, ,Errors Reading
26304Symbol Files}).
26305
26306@table @code
26307
26308@kindex set complaints
26309@item set complaints @var{limit}
26310Permits @value{GDBN} to output @var{limit} complaints about each type of
26311unusual symbols before becoming silent about the problem.  Set
26312@var{limit} to zero to suppress all complaints; set it to a large number
26313to prevent complaints from being suppressed.
26314
26315@kindex show complaints
26316@item show complaints
26317Displays how many symbol complaints @value{GDBN} is permitted to produce.
26318
26319@end table
26320
26321@anchor{confirmation requests}
26322By default, @value{GDBN} is cautious, and asks what sometimes seems to be a
26323lot of stupid questions to confirm certain commands.  For example, if
26324you try to run a program which is already running:
26325
26326@smallexample
26327(@value{GDBP}) run
26328The program being debugged has been started already.
26329Start it from the beginning? (y or n)
26330@end smallexample
26331
26332If you are willing to unflinchingly face the consequences of your own
26333commands, you can disable this ``feature'':
26334
26335@table @code
26336
26337@kindex set confirm
26338@cindex flinching
26339@cindex confirmation
26340@cindex stupid questions
26341@item set confirm off
26342Disables confirmation requests.  Note that running @value{GDBN} with
26343the @option{--batch} option (@pxref{Mode Options, -batch}) also
26344automatically disables confirmation requests.
26345
26346@item set confirm on
26347Enables confirmation requests (the default).
26348
26349@kindex show confirm
26350@item show confirm
26351Displays state of confirmation requests.
26352
26353@end table
26354
26355@cindex command tracing
26356If you need to debug user-defined commands or sourced files you may find it
26357useful to enable @dfn{command tracing}.  In this mode each command will be
26358printed as it is executed, prefixed with one or more @samp{+} symbols, the
26359quantity denoting the call depth of each command.
26360
26361@table @code
26362@kindex set trace-commands
26363@cindex command scripts, debugging
26364@item set trace-commands on
26365Enable command tracing.
26366@item set trace-commands off
26367Disable command tracing.
26368@item show trace-commands
26369Display the current state of command tracing.
26370@end table
26371
26372@node Debugging Output
26373@section Optional Messages about Internal Happenings
26374@cindex optional debugging messages
26375
26376@value{GDBN} has commands that enable optional debugging messages from
26377various @value{GDBN} subsystems; normally these commands are of
26378interest to @value{GDBN} maintainers, or when reporting a bug.  This
26379section documents those commands.
26380
26381@table @code
26382@kindex set exec-done-display
26383@item set exec-done-display
26384Turns on or off the notification of asynchronous commands'
26385completion.  When on, @value{GDBN} will print a message when an
26386asynchronous command finishes its execution.  The default is off.
26387@kindex show exec-done-display
26388@item show exec-done-display
26389Displays the current setting of asynchronous command completion
26390notification.
26391@kindex set debug
26392@cindex ARM AArch64
26393@item set debug aarch64
26394Turns on or off display of debugging messages related to ARM AArch64.
26395The default is off.
26396@kindex show debug
26397@item show debug aarch64
26398Displays the current state of displaying debugging messages related to
26399ARM AArch64.
26400@cindex gdbarch debugging info
26401@cindex architecture debugging info
26402@item set debug arch
26403Turns on or off display of gdbarch debugging info.  The default is off
26404@item show debug arch
26405Displays the current state of displaying gdbarch debugging info.
26406@item set debug aix-solib
26407@cindex AIX shared library debugging
26408Control display of debugging messages from the AIX shared library
26409support module.  The default is off.
26410@item show debug aix-thread
26411Show the current state of displaying AIX shared library debugging messages.
26412@item set debug aix-thread
26413@cindex AIX threads
26414Display debugging messages about inner workings of the AIX thread
26415module.
26416@item show debug aix-thread
26417Show the current state of AIX thread debugging info display.
26418@item set debug check-physname
26419@cindex physname
26420Check the results of the ``physname'' computation.  When reading DWARF
26421debugging information for C@t{++}, @value{GDBN} attempts to compute
26422each entity's name.  @value{GDBN} can do this computation in two
26423different ways, depending on exactly what information is present.
26424When enabled, this setting causes @value{GDBN} to compute the names
26425both ways and display any discrepancies.
26426@item show debug check-physname
26427Show the current state of ``physname'' checking.
26428@item set debug coff-pe-read
26429@cindex COFF/PE exported symbols
26430Control display of debugging messages related to reading of COFF/PE
26431exported symbols.  The default is off.
26432@item show debug coff-pe-read
26433Displays the current state of displaying debugging messages related to
26434reading of COFF/PE exported symbols.
26435@item set debug dwarf-die
26436@cindex DWARF DIEs
26437Dump DWARF DIEs after they are read in.
26438The value is the number of nesting levels to print.
26439A value of zero turns off the display.
26440@item show debug dwarf-die
26441Show the current state of DWARF DIE debugging.
26442@item set debug dwarf-line
26443@cindex DWARF Line Tables
26444Turns on or off display of debugging messages related to reading
26445DWARF line tables.  The default is 0 (off).
26446A value of 1 provides basic information.
26447A value greater than 1 provides more verbose information.
26448@item show debug dwarf-line
26449Show the current state of DWARF line table debugging.
26450@item set debug dwarf-read
26451@cindex DWARF Reading
26452Turns on or off display of debugging messages related to reading
26453DWARF debug info.  The default is 0 (off).
26454A value of 1 provides basic information.
26455A value greater than 1 provides more verbose information.
26456@item show debug dwarf-read
26457Show the current state of DWARF reader debugging.
26458@item set debug displaced
26459@cindex displaced stepping debugging info
26460Turns on or off display of @value{GDBN} debugging info for the
26461displaced stepping support.  The default is off.
26462@item show debug displaced
26463Displays the current state of displaying @value{GDBN} debugging info
26464related to displaced stepping.
26465@item set debug event
26466@cindex event debugging info
26467Turns on or off display of @value{GDBN} event debugging info.  The
26468default is off.
26469@item show debug event
26470Displays the current state of displaying @value{GDBN} event debugging
26471info.
26472@item set debug expression
26473@cindex expression debugging info
26474Turns on or off display of debugging info about @value{GDBN}
26475expression parsing.  The default is off.
26476@item show debug expression
26477Displays the current state of displaying debugging info about
26478@value{GDBN} expression parsing.
26479@item set debug fbsd-lwp
26480@cindex FreeBSD LWP debug messages
26481Turns on or off debugging messages from the FreeBSD LWP debug support.
26482@item show debug fbsd-lwp
26483Show the current state of FreeBSD LWP debugging messages.
26484@item set debug fbsd-nat
26485@cindex FreeBSD native target debug messages
26486Turns on or off debugging messages from the FreeBSD native target.
26487@item show debug fbsd-nat
26488Show the current state of FreeBSD native target debugging messages.
26489@item set debug frame
26490@cindex frame debugging info
26491Turns on or off display of @value{GDBN} frame debugging info.  The
26492default is off.
26493@item show debug frame
26494Displays the current state of displaying @value{GDBN} frame debugging
26495info.
26496@item set debug gnu-nat
26497@cindex @sc{gnu}/Hurd debug messages
26498Turn on or off debugging messages from the @sc{gnu}/Hurd debug support.
26499@item show debug gnu-nat
26500Show the current state of @sc{gnu}/Hurd debugging messages.
26501@item set debug infrun
26502@cindex inferior debugging info
26503Turns on or off display of @value{GDBN} debugging info for running the inferior.
26504The default is off.  @file{infrun.c} contains GDB's runtime state machine used
26505for implementing operations such as single-stepping the inferior.
26506@item show debug infrun
26507Displays the current state of @value{GDBN} inferior debugging.
26508@item set debug jit
26509@cindex just-in-time compilation, debugging messages
26510Turn on or off debugging messages from JIT debug support.
26511@item show debug jit
26512Displays the current state of @value{GDBN} JIT debugging.
26513@item set debug lin-lwp
26514@cindex @sc{gnu}/Linux LWP debug messages
26515@cindex Linux lightweight processes
26516Turn on or off debugging messages from the Linux LWP debug support.
26517@item show debug lin-lwp
26518Show the current state of Linux LWP debugging messages.
26519@item set debug linux-namespaces
26520@cindex @sc{gnu}/Linux namespaces debug messages
26521Turn on or off debugging messages from the Linux namespaces debug support.
26522@item show debug linux-namespaces
26523Show the current state of Linux namespaces debugging messages.
26524@item set debug mach-o
26525@cindex Mach-O symbols processing
26526Control display of debugging messages related to Mach-O symbols
26527processing.  The default is off.
26528@item show debug mach-o
26529Displays the current state of displaying debugging messages related to
26530reading of COFF/PE exported symbols.
26531@item set debug notification
26532@cindex remote async notification debugging info
26533Turn on or off debugging messages about remote async notification.
26534The default is off.
26535@item show debug notification
26536Displays the current state of remote async notification debugging messages.
26537@item set debug observer
26538@cindex observer debugging info
26539Turns on or off display of @value{GDBN} observer debugging.  This
26540includes info such as the notification of observable events.
26541@item show debug observer
26542Displays the current state of observer debugging.
26543@item set debug overload
26544@cindex C@t{++} overload debugging info
26545Turns on or off display of @value{GDBN} C@t{++} overload debugging
26546info. This includes info such as ranking of functions, etc.  The default
26547is off.
26548@item show debug overload
26549Displays the current state of displaying @value{GDBN} C@t{++} overload
26550debugging info.
26551@cindex expression parser, debugging info
26552@cindex debug expression parser
26553@item set debug parser
26554Turns on or off the display of expression parser debugging output.
26555Internally, this sets the @code{yydebug} variable in the expression
26556parser.  @xref{Tracing, , Tracing Your Parser, bison, Bison}, for
26557details.  The default is off.
26558@item show debug parser
26559Show the current state of expression parser debugging.
26560@cindex packets, reporting on stdout
26561@cindex serial connections, debugging
26562@cindex debug remote protocol
26563@cindex remote protocol debugging
26564@cindex display remote packets
26565@item set debug remote
26566Turns on or off display of reports on all packets sent back and forth across
26567the serial line to the remote machine.  The info is printed on the
26568@value{GDBN} standard output stream. The default is off.
26569@item show debug remote
26570Displays the state of display of remote packets.
26571
26572@item set debug remote-packet-max-chars
26573Sets the maximum number of characters to display for each remote packet when
26574@code{set debug remote} is on.  This is useful to prevent @value{GDBN} from
26575displaying lengthy remote packets and polluting the console.
26576
26577The default value is @code{512}, which means @value{GDBN} will truncate each
26578remote packet after 512 bytes.
26579
26580Setting this option to @code{unlimited} will disable truncation and will output
26581the full length of the remote packets.
26582@item show debug remote-packet-max-chars
26583Displays the number of bytes to output for remote packet debugging.
26584
26585@item set debug separate-debug-file
26586Turns on or off display of debug output about separate debug file search.
26587@item show debug separate-debug-file
26588Displays the state of separate debug file search debug output.
26589
26590@item set debug serial
26591Turns on or off display of @value{GDBN} serial debugging info. The
26592default is off.
26593@item show debug serial
26594Displays the current state of displaying @value{GDBN} serial debugging
26595info.
26596@item set debug solib-frv
26597@cindex FR-V shared-library debugging
26598Turn on or off debugging messages for FR-V shared-library code.
26599@item show debug solib-frv
26600Display the current state of FR-V shared-library code debugging
26601messages.
26602@item set debug symbol-lookup
26603@cindex symbol lookup
26604Turns on or off display of debugging messages related to symbol lookup.
26605The default is 0 (off).
26606A value of 1 provides basic information.
26607A value greater than 1 provides more verbose information.
26608@item show debug symbol-lookup
26609Show the current state of symbol lookup debugging messages.
26610@item set debug symfile
26611@cindex symbol file functions
26612Turns on or off display of debugging messages related to symbol file functions.
26613The default is off.  @xref{Files}.
26614@item show debug symfile
26615Show the current state of symbol file debugging messages.
26616@item set debug symtab-create
26617@cindex symbol table creation
26618Turns on or off display of debugging messages related to symbol table creation.
26619The default is 0 (off).
26620A value of 1 provides basic information.
26621A value greater than 1 provides more verbose information.
26622@item show debug symtab-create
26623Show the current state of symbol table creation debugging.
26624@item set debug target
26625@cindex target debugging info
26626Turns on or off display of @value{GDBN} target debugging info. This info
26627includes what is going on at the target level of GDB, as it happens. The
26628default is 0.  Set it to 1 to track events, and to 2 to also track the
26629value of large memory transfers.
26630@item show debug target
26631Displays the current state of displaying @value{GDBN} target debugging
26632info.
26633@item set debug timestamp
26634@cindex timestamping debugging info
26635Turns on or off display of timestamps with @value{GDBN} debugging info.
26636When enabled, seconds and microseconds are displayed before each debugging
26637message.
26638@item show debug timestamp
26639Displays the current state of displaying timestamps with @value{GDBN}
26640debugging info.
26641@item set debug varobj
26642@cindex variable object debugging info
26643Turns on or off display of @value{GDBN} variable object debugging
26644info. The default is off.
26645@item show debug varobj
26646Displays the current state of displaying @value{GDBN} variable object
26647debugging info.
26648@item set debug xml
26649@cindex XML parser debugging
26650Turn on or off debugging messages for built-in XML parsers.
26651@item show debug xml
26652Displays the current state of XML debugging messages.
26653@end table
26654
26655@node Other Misc Settings
26656@section Other Miscellaneous Settings
26657@cindex miscellaneous settings
26658
26659@table @code
26660@kindex set interactive-mode
26661@item set interactive-mode
26662If @code{on}, forces @value{GDBN} to assume that GDB was started
26663in a terminal.  In practice, this means that @value{GDBN} should wait
26664for the user to answer queries generated by commands entered at
26665the command prompt.  If @code{off}, forces @value{GDBN} to operate
26666in the opposite mode, and it uses the default answers to all queries.
26667If @code{auto} (the default), @value{GDBN} tries to determine whether
26668its standard input is a terminal, and works in interactive-mode if it
26669is, non-interactively otherwise.
26670
26671In the vast majority of cases, the debugger should be able to guess
26672correctly which mode should be used.  But this setting can be useful
26673in certain specific cases, such as running a MinGW @value{GDBN}
26674inside a cygwin window.
26675
26676@kindex show interactive-mode
26677@item show interactive-mode
26678Displays whether the debugger is operating in interactive mode or not.
26679@end table
26680
26681@node Extending GDB
26682@chapter Extending @value{GDBN}
26683@cindex extending GDB
26684
26685@value{GDBN} provides several mechanisms for extension.
26686@value{GDBN} also provides the ability to automatically load
26687extensions when it reads a file for debugging.  This allows the
26688user to automatically customize @value{GDBN} for the program
26689being debugged.
26690
26691@menu
26692* Sequences::                Canned Sequences of @value{GDBN} Commands
26693* Python::                   Extending @value{GDBN} using Python
26694* Guile::                    Extending @value{GDBN} using Guile
26695* Auto-loading extensions::  Automatically loading extensions
26696* Multiple Extension Languages:: Working with multiple extension languages
26697* Aliases::                  Creating new spellings of existing commands
26698@end menu
26699
26700To facilitate the use of extension languages, @value{GDBN} is capable
26701of evaluating the contents of a file.  When doing so, @value{GDBN}
26702can recognize which extension language is being used by looking at
26703the filename extension.  Files with an unrecognized filename extension
26704are always treated as a @value{GDBN} Command Files.
26705@xref{Command Files,, Command files}.
26706
26707You can control how @value{GDBN} evaluates these files with the following
26708setting:
26709
26710@table @code
26711@kindex set script-extension
26712@kindex show script-extension
26713@item set script-extension off
26714All scripts are always evaluated as @value{GDBN} Command Files.
26715
26716@item set script-extension soft
26717The debugger determines the scripting language based on filename
26718extension.  If this scripting language is supported, @value{GDBN}
26719evaluates the script using that language.  Otherwise, it evaluates
26720the file as a @value{GDBN} Command File.
26721
26722@item set script-extension strict
26723The debugger determines the scripting language based on filename
26724extension, and evaluates the script using that language.  If the
26725language is not supported, then the evaluation fails.
26726
26727@item show script-extension
26728Display the current value of the @code{script-extension} option.
26729
26730@end table
26731
26732@ifset SYSTEM_GDBINIT_DIR
26733This setting is not used for files in the system-wide gdbinit directory.
26734Files in that directory must have an extension matching their language,
26735or have a @file{.gdb} extension to be interpreted as regular @value{GDBN}
26736commands.  @xref{Startup}.
26737@end ifset
26738
26739@node Sequences
26740@section Canned Sequences of Commands
26741
26742Aside from breakpoint commands (@pxref{Break Commands, ,Breakpoint
26743Command Lists}), @value{GDBN} provides two ways to store sequences of
26744commands for execution as a unit: user-defined commands and command
26745files.
26746
26747@menu
26748* Define::             How to define your own commands
26749* Hooks::              Hooks for user-defined commands
26750* Command Files::      How to write scripts of commands to be stored in a file
26751* Output::             Commands for controlled output
26752* Auto-loading sequences::  Controlling auto-loaded command files
26753@end menu
26754
26755@node Define
26756@subsection User-defined Commands
26757
26758@cindex user-defined command
26759@cindex arguments, to user-defined commands
26760A @dfn{user-defined command} is a sequence of @value{GDBN} commands to
26761which you assign a new name as a command.  This is done with the
26762@code{define} command.  User commands may accept an unlimited number of arguments
26763separated by whitespace.  Arguments are accessed within the user command
26764via @code{$arg0@dots{}$argN}.  A trivial example:
26765
26766@smallexample
26767define adder
26768  print $arg0 + $arg1 + $arg2
26769end
26770@end smallexample
26771
26772@noindent
26773To execute the command use:
26774
26775@smallexample
26776adder 1 2 3
26777@end smallexample
26778
26779@noindent
26780This defines the command @code{adder}, which prints the sum of
26781its three arguments.  Note the arguments are text substitutions, so they may
26782reference variables, use complex expressions, or even perform inferior
26783functions calls.
26784
26785@cindex argument count in user-defined commands
26786@cindex how many arguments (user-defined commands)
26787In addition, @code{$argc} may be used to find out how many arguments have
26788been passed.
26789
26790@smallexample
26791define adder
26792  if $argc == 2
26793    print $arg0 + $arg1
26794  end
26795  if $argc == 3
26796    print $arg0 + $arg1 + $arg2
26797  end
26798end
26799@end smallexample
26800
26801Combining with the @code{eval} command (@pxref{eval}) makes it easier
26802to process a variable number of arguments:
26803
26804@smallexample
26805define adder
26806  set $i = 0
26807  set $sum = 0
26808  while $i < $argc
26809    eval "set $sum = $sum + $arg%d", $i
26810    set $i = $i + 1
26811  end
26812  print $sum
26813end
26814@end smallexample
26815
26816@table @code
26817
26818@kindex define
26819@item define @var{commandname}
26820Define a command named @var{commandname}.  If there is already a command
26821by that name, you are asked to confirm that you want to redefine it.
26822The argument @var{commandname} may be a bare command name consisting of letters,
26823numbers, dashes, dots, and underscores.  It may also start with any
26824predefined or user-defined prefix command.
26825For example, @samp{define target my-target} creates
26826a user-defined @samp{target my-target} command.
26827
26828The definition of the command is made up of other @value{GDBN} command lines,
26829which are given following the @code{define} command.  The end of these
26830commands is marked by a line containing @code{end}.
26831
26832@kindex document
26833@kindex end@r{ (user-defined commands)}
26834@item document @var{commandname}
26835Document the user-defined command @var{commandname}, so that it can be
26836accessed by @code{help}.  The command @var{commandname} must already be
26837defined.  This command reads lines of documentation just as @code{define}
26838reads the lines of the command definition, ending with @code{end}.
26839After the @code{document} command is finished, @code{help} on command
26840@var{commandname} displays the documentation you have written.
26841
26842You may use the @code{document} command again to change the
26843documentation of a command.  Redefining the command with @code{define}
26844does not change the documentation.
26845
26846@kindex define-prefix
26847@item define-prefix @var{commandname}
26848Define or mark the command @var{commandname} as a user-defined prefix
26849command.  Once marked, @var{commandname} can be used as prefix command
26850by the  @code{define} command.
26851Note that @code{define-prefix} can be used with a not yet defined
26852@var{commandname}.  In such a case, @var{commandname} is defined as
26853an empty user-defined command.
26854In case you redefine a command that was marked as a user-defined
26855prefix command, the subcommands of the redefined command are kept
26856(and @value{GDBN} indicates so to the user).
26857
26858Example:
26859@example
26860(gdb) define-prefix abc
26861(gdb) define-prefix abc def
26862(gdb) define abc def
26863Type commands for definition of "abc def".
26864End with a line saying just "end".
26865>echo command initial def\n
26866>end
26867(gdb) define abc def ghi
26868Type commands for definition of "abc def ghi".
26869End with a line saying just "end".
26870>echo command ghi\n
26871>end
26872(gdb) define abc def
26873Keeping subcommands of prefix command "def".
26874Redefine command "def"? (y or n) y
26875Type commands for definition of "abc def".
26876End with a line saying just "end".
26877>echo command def\n
26878>end
26879(gdb) abc def ghi
26880command ghi
26881(gdb) abc def
26882command def
26883(gdb)
26884@end example
26885
26886@kindex dont-repeat
26887@cindex don't repeat command
26888@item dont-repeat
26889Used inside a user-defined command, this tells @value{GDBN} that this
26890command should not be repeated when the user hits @key{RET}
26891(@pxref{Command Syntax, repeat last command}).
26892
26893@kindex help user-defined
26894@item help user-defined
26895List all user-defined commands and all python commands defined in class
26896COMMAND_USER.  The first line of the documentation or docstring is
26897included (if any).
26898
26899@kindex show user
26900@item show user
26901@itemx show user @var{commandname}
26902Display the @value{GDBN} commands used to define @var{commandname} (but
26903not its documentation).  If no @var{commandname} is given, display the
26904definitions for all user-defined commands.
26905This does not work for user-defined python commands.
26906
26907@cindex infinite recursion in user-defined commands
26908@kindex show max-user-call-depth
26909@kindex set max-user-call-depth
26910@item show max-user-call-depth
26911@itemx set max-user-call-depth
26912The value of @code{max-user-call-depth} controls how many recursion
26913levels are allowed in user-defined commands before @value{GDBN} suspects an
26914infinite recursion and aborts the command.
26915This does not apply to user-defined python commands.
26916@end table
26917
26918In addition to the above commands, user-defined commands frequently
26919use control flow commands, described in @ref{Command Files}.
26920
26921When user-defined commands are executed, the
26922commands of the definition are not printed.  An error in any command
26923stops execution of the user-defined command.
26924
26925If used interactively, commands that would ask for confirmation proceed
26926without asking when used inside a user-defined command.  Many @value{GDBN}
26927commands that normally print messages to say what they are doing omit the
26928messages when used in a user-defined command.
26929
26930@node Hooks
26931@subsection User-defined Command Hooks
26932@cindex command hooks
26933@cindex hooks, for commands
26934@cindex hooks, pre-command
26935
26936@kindex hook
26937You may define @dfn{hooks}, which are a special kind of user-defined
26938command.  Whenever you run the command @samp{foo}, if the user-defined
26939command @samp{hook-foo} exists, it is executed (with no arguments)
26940before that command.
26941
26942@cindex hooks, post-command
26943@kindex hookpost
26944A hook may also be defined which is run after the command you executed.
26945Whenever you run the command @samp{foo}, if the user-defined command
26946@samp{hookpost-foo} exists, it is executed (with no arguments) after
26947that command.  Post-execution hooks may exist simultaneously with
26948pre-execution hooks, for the same command.
26949
26950It is valid for a hook to call the command which it hooks.  If this
26951occurs, the hook is not re-executed, thereby avoiding infinite recursion.
26952
26953@c It would be nice if hookpost could be passed a parameter indicating
26954@c if the command it hooks executed properly or not.  FIXME!
26955
26956@kindex stop@r{, a pseudo-command}
26957In addition, a pseudo-command, @samp{stop} exists.  Defining
26958(@samp{hook-stop}) makes the associated commands execute every time
26959execution stops in your program: before breakpoint commands are run,
26960displays are printed, or the stack frame is printed.
26961
26962For example, to ignore @code{SIGALRM} signals while
26963single-stepping, but treat them normally during normal execution,
26964you could define:
26965
26966@smallexample
26967define hook-stop
26968handle SIGALRM nopass
26969end
26970
26971define hook-run
26972handle SIGALRM pass
26973end
26974
26975define hook-continue
26976handle SIGALRM pass
26977end
26978@end smallexample
26979
26980As a further example, to hook at the beginning and end of the @code{echo}
26981command, and to add extra text to the beginning and end of the message,
26982you could define:
26983
26984@smallexample
26985define hook-echo
26986echo <<<---
26987end
26988
26989define hookpost-echo
26990echo --->>>\n
26991end
26992
26993(@value{GDBP}) echo Hello World
26994<<<---Hello World--->>>
26995(@value{GDBP})
26996
26997@end smallexample
26998
26999You can define a hook for any single-word command in @value{GDBN}, but
27000not for command aliases; you should define a hook for the basic command
27001name, e.g.@:  @code{backtrace} rather than @code{bt}.
27002@c FIXME!  So how does Joe User discover whether a command is an alias
27003@c or not?
27004You can hook a multi-word command by adding @code{hook-} or
27005@code{hookpost-} to the last word of the command, e.g.@:
27006@samp{define target hook-remote} to add a hook to @samp{target remote}.
27007
27008If an error occurs during the execution of your hook, execution of
27009@value{GDBN} commands stops and @value{GDBN} issues a prompt
27010(before the command that you actually typed had a chance to run).
27011
27012If you try to define a hook which does not match any known command, you
27013get a warning from the @code{define} command.
27014
27015@node Command Files
27016@subsection Command Files
27017
27018@cindex command files
27019@cindex scripting commands
27020A command file for @value{GDBN} is a text file made of lines that are
27021@value{GDBN} commands.  Comments (lines starting with @kbd{#}) may
27022also be included.  An empty line in a command file does nothing; it
27023does not mean to repeat the last command, as it would from the
27024terminal.
27025
27026You can request the execution of a command file with the @code{source}
27027command.  Note that the @code{source} command is also used to evaluate
27028scripts that are not Command Files.  The exact behavior can be configured
27029using the @code{script-extension} setting.
27030@xref{Extending GDB,, Extending GDB}.
27031
27032@table @code
27033@kindex source
27034@cindex execute commands from a file
27035@item source [-s] [-v] @var{filename}
27036Execute the command file @var{filename}.
27037@end table
27038
27039The lines in a command file are generally executed sequentially,
27040unless the order of execution is changed by one of the
27041@emph{flow-control commands} described below.  The commands are not
27042printed as they are executed.  An error in any command terminates
27043execution of the command file and control is returned to the console.
27044
27045@value{GDBN} first searches for @var{filename} in the current directory.
27046If the file is not found there, and @var{filename} does not specify a
27047directory, then @value{GDBN} also looks for the file on the source search path
27048(specified with the @samp{directory} command);
27049except that @file{$cdir} is not searched because the compilation directory
27050is not relevant to scripts.
27051
27052If @code{-s} is specified, then @value{GDBN} searches for @var{filename}
27053on the search path even if @var{filename} specifies a directory.
27054The search is done by appending @var{filename} to each element of the
27055search path.  So, for example, if @var{filename} is @file{mylib/myscript}
27056and the search path contains @file{/home/user} then @value{GDBN} will
27057look for the script @file{/home/user/mylib/myscript}.
27058The search is also done if @var{filename} is an absolute path.
27059For example, if @var{filename} is @file{/tmp/myscript} and
27060the search path contains @file{/home/user} then @value{GDBN} will
27061look for the script @file{/home/user/tmp/myscript}.
27062For DOS-like systems, if @var{filename} contains a drive specification,
27063it is stripped before concatenation.  For example, if @var{filename} is
27064@file{d:myscript} and the search path contains @file{c:/tmp} then @value{GDBN}
27065will look for the script @file{c:/tmp/myscript}.
27066
27067If @code{-v}, for verbose mode, is given then @value{GDBN} displays
27068each command as it is executed.  The option must be given before
27069@var{filename}, and is interpreted as part of the filename anywhere else.
27070
27071Commands that would ask for confirmation if used interactively proceed
27072without asking when used in a command file.  Many @value{GDBN} commands that
27073normally print messages to say what they are doing omit the messages
27074when called from command files.
27075
27076@value{GDBN} also accepts command input from standard input.  In this
27077mode, normal output goes to standard output and error output goes to
27078standard error.  Errors in a command file supplied on standard input do
27079not terminate execution of the command file---execution continues with
27080the next command.
27081
27082@smallexample
27083gdb < cmds > log 2>&1
27084@end smallexample
27085
27086(The syntax above will vary depending on the shell used.) This example
27087will execute commands from the file @file{cmds}. All output and errors
27088would be directed to @file{log}.
27089
27090Since commands stored on command files tend to be more general than
27091commands typed interactively, they frequently need to deal with
27092complicated situations, such as different or unexpected values of
27093variables and symbols, changes in how the program being debugged is
27094built, etc.  @value{GDBN} provides a set of flow-control commands to
27095deal with these complexities.  Using these commands, you can write
27096complex scripts that loop over data structures, execute commands
27097conditionally, etc.
27098
27099@table @code
27100@kindex if
27101@kindex else
27102@item if
27103@itemx else
27104This command allows to include in your script conditionally executed
27105commands. The @code{if} command takes a single argument, which is an
27106expression to evaluate.  It is followed by a series of commands that
27107are executed only if the expression is true (its value is nonzero).
27108There can then optionally be an @code{else} line, followed by a series
27109of commands that are only executed if the expression was false.  The
27110end of the list is marked by a line containing @code{end}.
27111
27112@kindex while
27113@item while
27114This command allows to write loops.  Its syntax is similar to
27115@code{if}: the command takes a single argument, which is an expression
27116to evaluate, and must be followed by the commands to execute, one per
27117line, terminated by an @code{end}.  These commands are called the
27118@dfn{body} of the loop.  The commands in the body of @code{while} are
27119executed repeatedly as long as the expression evaluates to true.
27120
27121@kindex loop_break
27122@item loop_break
27123This command exits the @code{while} loop in whose body it is included.
27124Execution of the script continues after that @code{while}s @code{end}
27125line.
27126
27127@kindex loop_continue
27128@item loop_continue
27129This command skips the execution of the rest of the body of commands
27130in the @code{while} loop in whose body it is included.  Execution
27131branches to the beginning of the @code{while} loop, where it evaluates
27132the controlling expression.
27133
27134@kindex end@r{ (if/else/while commands)}
27135@item end
27136Terminate the block of commands that are the body of @code{if},
27137@code{else}, or @code{while} flow-control commands.
27138@end table
27139
27140
27141@node Output
27142@subsection Commands for Controlled Output
27143
27144During the execution of a command file or a user-defined command, normal
27145@value{GDBN} output is suppressed; the only output that appears is what is
27146explicitly printed by the commands in the definition.  This section
27147describes three commands useful for generating exactly the output you
27148want.
27149
27150@table @code
27151@kindex echo
27152@item echo @var{text}
27153@c I do not consider backslash-space a standard C escape sequence
27154@c because it is not in ANSI.
27155Print @var{text}.  Nonprinting characters can be included in
27156@var{text} using C escape sequences, such as @samp{\n} to print a
27157newline.  @strong{No newline is printed unless you specify one.}
27158In addition to the standard C escape sequences, a backslash followed
27159by a space stands for a space.  This is useful for displaying a
27160string with spaces at the beginning or the end, since leading and
27161trailing spaces are otherwise trimmed from all arguments.
27162To print @samp{@w{ }and foo =@w{ }}, use the command
27163@samp{echo \@w{ }and foo = \@w{ }}.
27164
27165A backslash at the end of @var{text} can be used, as in C, to continue
27166the command onto subsequent lines.  For example,
27167
27168@smallexample
27169echo This is some text\n\
27170which is continued\n\
27171onto several lines.\n
27172@end smallexample
27173
27174produces the same output as
27175
27176@smallexample
27177echo This is some text\n
27178echo which is continued\n
27179echo onto several lines.\n
27180@end smallexample
27181
27182@kindex output
27183@item output @var{expression}
27184Print the value of @var{expression} and nothing but that value: no
27185newlines, no @samp{$@var{nn} = }.  The value is not entered in the
27186value history either.  @xref{Expressions, ,Expressions}, for more information
27187on expressions.
27188
27189@item output/@var{fmt} @var{expression}
27190Print the value of @var{expression} in format @var{fmt}.  You can use
27191the same formats as for @code{print}.  @xref{Output Formats,,Output
27192Formats}, for more information.
27193
27194@kindex printf
27195@item printf @var{template}, @var{expressions}@dots{}
27196Print the values of one or more @var{expressions} under the control of
27197the string @var{template}.  To print several values, make
27198@var{expressions} be a comma-separated list of individual expressions,
27199which may be either numbers or pointers.  Their values are printed as
27200specified by @var{template}, exactly as a C program would do by
27201executing the code below:
27202
27203@smallexample
27204printf (@var{template}, @var{expressions}@dots{});
27205@end smallexample
27206
27207As in @code{C} @code{printf}, ordinary characters in @var{template}
27208are printed verbatim, while @dfn{conversion specification} introduced
27209by the @samp{%} character cause subsequent @var{expressions} to be
27210evaluated, their values converted and formatted according to type and
27211style information encoded in the conversion specifications, and then
27212printed.
27213
27214For example, you can print two values in hex like this:
27215
27216@smallexample
27217printf "foo, bar-foo = 0x%x, 0x%x\n", foo, bar-foo
27218@end smallexample
27219
27220@code{printf} supports all the standard @code{C} conversion
27221specifications, including the flags and modifiers between the @samp{%}
27222character and the conversion letter, with the following exceptions:
27223
27224@itemize @bullet
27225@item
27226The argument-ordering modifiers, such as @samp{2$}, are not supported.
27227
27228@item
27229The modifier @samp{*} is not supported for specifying precision or
27230width.
27231
27232@item
27233The @samp{'} flag (for separation of digits into groups according to
27234@code{LC_NUMERIC'}) is not supported.
27235
27236@item
27237The type modifiers @samp{hh}, @samp{j}, @samp{t}, and @samp{z} are not
27238supported.
27239
27240@item
27241The conversion letter @samp{n} (as in @samp{%n}) is not supported.
27242
27243@item
27244The conversion letters @samp{a} and @samp{A} are not supported.
27245@end itemize
27246
27247@noindent
27248Note that the @samp{ll} type modifier is supported only if the
27249underlying @code{C} implementation used to build @value{GDBN} supports
27250the @code{long long int} type, and the @samp{L} type modifier is
27251supported only if @code{long double} type is available.
27252
27253As in @code{C}, @code{printf} supports simple backslash-escape
27254sequences, such as @code{\n}, @samp{\t}, @samp{\\}, @samp{\"},
27255@samp{\a}, and @samp{\f}, that consist of backslash followed by a
27256single character.  Octal and hexadecimal escape sequences are not
27257supported.
27258
27259Additionally, @code{printf} supports conversion specifications for DFP
27260(@dfn{Decimal Floating Point}) types using the following length modifiers
27261together with a floating point specifier.
27262letters:
27263
27264@itemize @bullet
27265@item
27266@samp{H} for printing @code{Decimal32} types.
27267
27268@item
27269@samp{D} for printing @code{Decimal64} types.
27270
27271@item
27272@samp{DD} for printing @code{Decimal128} types.
27273@end itemize
27274
27275If the underlying @code{C} implementation used to build @value{GDBN} has
27276support for the three length modifiers for DFP types, other modifiers
27277such as width and precision will also be available for @value{GDBN} to use.
27278
27279In case there is no such @code{C} support, no additional modifiers will be
27280available and the value will be printed in the standard way.
27281
27282Here's an example of printing DFP types using the above conversion letters:
27283@smallexample
27284printf "D32: %Hf - D64: %Df - D128: %DDf\n",1.2345df,1.2E10dd,1.2E1dl
27285@end smallexample
27286
27287@anchor{eval}
27288@kindex eval
27289@item eval @var{template}, @var{expressions}@dots{}
27290Convert the values of one or more @var{expressions} under the control of
27291the string @var{template} to a command line, and call it.
27292
27293@end table
27294
27295@node Auto-loading sequences
27296@subsection Controlling auto-loading native @value{GDBN} scripts
27297@cindex native script auto-loading
27298
27299When a new object file is read (for example, due to the @code{file}
27300command, or because the inferior has loaded a shared library),
27301@value{GDBN} will look for the command file @file{@var{objfile}-gdb.gdb}.
27302@xref{Auto-loading extensions}.
27303
27304Auto-loading can be enabled or disabled,
27305and the list of auto-loaded scripts can be printed.
27306
27307@table @code
27308@anchor{set auto-load gdb-scripts}
27309@kindex set auto-load gdb-scripts
27310@item set auto-load gdb-scripts [on|off]
27311Enable or disable the auto-loading of canned sequences of commands scripts.
27312
27313@anchor{show auto-load gdb-scripts}
27314@kindex show auto-load gdb-scripts
27315@item show auto-load gdb-scripts
27316Show whether auto-loading of canned sequences of commands scripts is enabled or
27317disabled.
27318
27319@anchor{info auto-load gdb-scripts}
27320@kindex info auto-load gdb-scripts
27321@cindex print list of auto-loaded canned sequences of commands scripts
27322@item info auto-load gdb-scripts [@var{regexp}]
27323Print the list of all canned sequences of commands scripts that @value{GDBN}
27324auto-loaded.
27325@end table
27326
27327If @var{regexp} is supplied only canned sequences of commands scripts with
27328matching names are printed.
27329
27330@c Python docs live in a separate file.
27331@include python.texi
27332
27333@c Guile docs live in a separate file.
27334@include guile.texi
27335
27336@node Auto-loading extensions
27337@section Auto-loading extensions
27338@cindex auto-loading extensions
27339
27340@value{GDBN} provides two mechanisms for automatically loading extensions
27341when a new object file is read (for example, due to the @code{file}
27342command, or because the inferior has loaded a shared library):
27343@file{@var{objfile}-gdb.@var{ext}} and the @code{.debug_gdb_scripts}
27344section of modern file formats like ELF.
27345
27346@menu
27347* objfile-gdb.ext file: objfile-gdbdotext file.  The @file{@var{objfile}-gdb.@var{ext}} file
27348* .debug_gdb_scripts section: dotdebug_gdb_scripts section.  The @code{.debug_gdb_scripts} section
27349* Which flavor to choose?::
27350@end menu
27351
27352The auto-loading feature is useful for supplying application-specific
27353debugging commands and features.
27354
27355Auto-loading can be enabled or disabled,
27356and the list of auto-loaded scripts can be printed.
27357See the @samp{auto-loading} section of each extension language
27358for more information.
27359For @value{GDBN} command files see @ref{Auto-loading sequences}.
27360For Python files see @ref{Python Auto-loading}.
27361
27362Note that loading of this script file also requires accordingly configured
27363@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27364
27365@node objfile-gdbdotext file
27366@subsection The @file{@var{objfile}-gdb.@var{ext}} file
27367@cindex @file{@var{objfile}-gdb.gdb}
27368@cindex @file{@var{objfile}-gdb.py}
27369@cindex @file{@var{objfile}-gdb.scm}
27370
27371When a new object file is read, @value{GDBN} looks for a file named
27372@file{@var{objfile}-gdb.@var{ext}} (we call it @var{script-name} below),
27373where @var{objfile} is the object file's name and
27374where @var{ext} is the file extension for the extension language:
27375
27376@table @code
27377@item @file{@var{objfile}-gdb.gdb}
27378GDB's own command language
27379@item @file{@var{objfile}-gdb.py}
27380Python
27381@item @file{@var{objfile}-gdb.scm}
27382Guile
27383@end table
27384
27385@var{script-name} is formed by ensuring that the file name of @var{objfile}
27386is absolute, following all symlinks, and resolving @code{.} and @code{..}
27387components, and appending the @file{-gdb.@var{ext}} suffix.
27388If this file exists and is readable, @value{GDBN} will evaluate it as a
27389script in the specified extension language.
27390
27391If this file does not exist, then @value{GDBN} will look for
27392@var{script-name} file in all of the directories as specified below.
27393(On MS-Windows/MS-DOS, the drive letter of the executable's leading
27394directories is converted to a one-letter subdirectory, i.e.@:
27395@file{d:/usr/bin/} is converted to @file{/d/usr/bin/}, because Windows
27396filesystems disallow colons in file names.)
27397
27398Note that loading of these files requires an accordingly configured
27399@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27400
27401For object files using @file{.exe} suffix @value{GDBN} tries to load first the
27402scripts normally according to its @file{.exe} filename.  But if no scripts are
27403found @value{GDBN} also tries script filenames matching the object file without
27404its @file{.exe} suffix.  This @file{.exe} stripping is case insensitive and it
27405is attempted on any platform.  This makes the script filenames compatible
27406between Unix and MS-Windows hosts.
27407
27408@table @code
27409@anchor{set auto-load scripts-directory}
27410@kindex set auto-load scripts-directory
27411@item set auto-load scripts-directory @r{[}@var{directories}@r{]}
27412Control @value{GDBN} auto-loaded scripts location.  Multiple directory entries
27413may be delimited by the host platform path separator in use
27414(@samp{:} on Unix, @samp{;} on MS-Windows and MS-DOS).
27415
27416Each entry here needs to be covered also by the security setting
27417@code{set auto-load safe-path} (@pxref{set auto-load safe-path}).
27418
27419@anchor{with-auto-load-dir}
27420This variable defaults to @file{$debugdir:$datadir/auto-load}.  The default
27421@code{set auto-load safe-path} value can be also overriden by @value{GDBN}
27422configuration option @option{--with-auto-load-dir}.
27423
27424Any reference to @file{$debugdir} will get replaced by
27425@var{debug-file-directory} value (@pxref{Separate Debug Files}) and any
27426reference to @file{$datadir} will get replaced by @var{data-directory} which is
27427determined at @value{GDBN} startup (@pxref{Data Files}).  @file{$debugdir} and
27428@file{$datadir} must be placed as a directory component --- either alone or
27429delimited by @file{/} or @file{\} directory separators, depending on the host
27430platform.
27431
27432The list of directories uses path separator (@samp{:} on GNU and Unix
27433systems, @samp{;} on MS-Windows and MS-DOS) to separate directories, similarly
27434to the @env{PATH} environment variable.
27435
27436@anchor{show auto-load scripts-directory}
27437@kindex show auto-load scripts-directory
27438@item show auto-load scripts-directory
27439Show @value{GDBN} auto-loaded scripts location.
27440
27441@anchor{add-auto-load-scripts-directory}
27442@kindex add-auto-load-scripts-directory
27443@item add-auto-load-scripts-directory @r{[}@var{directories}@dots{}@r{]}
27444Add an entry (or list of entries) to the list of auto-loaded scripts locations.
27445Multiple entries may be delimited by the host platform path separator in use.
27446@end table
27447
27448@value{GDBN} does not track which files it has already auto-loaded this way.
27449@value{GDBN} will load the associated script every time the corresponding
27450@var{objfile} is opened.
27451So your @file{-gdb.@var{ext}} file should be careful to avoid errors if it
27452is evaluated more than once.
27453
27454@node dotdebug_gdb_scripts section
27455@subsection The @code{.debug_gdb_scripts} section
27456@cindex @code{.debug_gdb_scripts} section
27457
27458For systems using file formats like ELF and COFF,
27459when @value{GDBN} loads a new object file
27460it will look for a special section named @code{.debug_gdb_scripts}.
27461If this section exists, its contents is a list of null-terminated entries
27462specifying scripts to load.  Each entry begins with a non-null prefix byte that
27463specifies the kind of entry, typically the extension language and whether the
27464script is in a file or inlined in @code{.debug_gdb_scripts}.
27465
27466The following entries are supported:
27467
27468@table @code
27469@item SECTION_SCRIPT_ID_PYTHON_FILE = 1
27470@item SECTION_SCRIPT_ID_SCHEME_FILE = 3
27471@item SECTION_SCRIPT_ID_PYTHON_TEXT = 4
27472@item SECTION_SCRIPT_ID_SCHEME_TEXT = 6
27473@end table
27474
27475@subsubsection Script File Entries
27476
27477If the entry specifies a file, @value{GDBN} will look for the file first
27478in the current directory and then along the source search path
27479(@pxref{Source Path, ,Specifying Source Directories}),
27480except that @file{$cdir} is not searched, since the compilation
27481directory is not relevant to scripts.
27482
27483File entries can be placed in section @code{.debug_gdb_scripts} with,
27484for example, this GCC macro for Python scripts.
27485
27486@example
27487/* Note: The "MS" section flags are to remove duplicates.  */
27488#define DEFINE_GDB_PY_SCRIPT(script_name) \
27489  asm("\
27490.pushsection \".debug_gdb_scripts\", \"MS\",@@progbits,1\n\
27491.byte 1 /* Python */\n\
27492.asciz \"" script_name "\"\n\
27493.popsection \n\
27494");
27495@end example
27496
27497@noindent
27498For Guile scripts, replace @code{.byte 1} with @code{.byte 3}.
27499Then one can reference the macro in a header or source file like this:
27500
27501@example
27502DEFINE_GDB_PY_SCRIPT ("my-app-scripts.py")
27503@end example
27504
27505The script name may include directories if desired.
27506
27507Note that loading of this script file also requires accordingly configured
27508@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27509
27510If the macro invocation is put in a header, any application or library
27511using this header will get a reference to the specified script,
27512and with the use of @code{"MS"} attributes on the section, the linker
27513will remove duplicates.
27514
27515@subsubsection Script Text Entries
27516
27517Script text entries allow to put the executable script in the entry
27518itself instead of loading it from a file.
27519The first line of the entry, everything after the prefix byte and up to
27520the first newline (@code{0xa}) character, is the script name, and must not
27521contain any kind of space character, e.g., spaces or tabs.
27522The rest of the entry, up to the trailing null byte, is the script to
27523execute in the specified language.  The name needs to be unique among
27524all script names, as @value{GDBN} executes each script only once based
27525on its name.
27526
27527Here is an example from file @file{py-section-script.c} in the @value{GDBN}
27528testsuite.
27529
27530@example
27531#include "symcat.h"
27532#include "gdb/section-scripts.h"
27533asm(
27534".pushsection \".debug_gdb_scripts\", \"MS\",@@progbits,1\n"
27535".byte " XSTRING (SECTION_SCRIPT_ID_PYTHON_TEXT) "\n"
27536".ascii \"gdb.inlined-script\\n\"\n"
27537".ascii \"class test_cmd (gdb.Command):\\n\"\n"
27538".ascii \"  def __init__ (self):\\n\"\n"
27539".ascii \"    super (test_cmd, self).__init__ ("
27540    "\\\"test-cmd\\\", gdb.COMMAND_OBSCURE)\\n\"\n"
27541".ascii \"  def invoke (self, arg, from_tty):\\n\"\n"
27542".ascii \"    print (\\\"test-cmd output, arg = %s\\\" % arg)\\n\"\n"
27543".ascii \"test_cmd ()\\n\"\n"
27544".byte 0\n"
27545".popsection\n"
27546);
27547@end example
27548
27549Loading of inlined scripts requires a properly configured
27550@code{auto-load safe-path} (@pxref{Auto-loading safe path}).
27551The path to specify in @code{auto-load safe-path} is the path of the file
27552containing the @code{.debug_gdb_scripts} section.
27553
27554@node Which flavor to choose?
27555@subsection Which flavor to choose?
27556
27557Given the multiple ways of auto-loading extensions, it might not always
27558be clear which one to choose.  This section provides some guidance.
27559
27560@noindent
27561Benefits of the @file{-gdb.@var{ext}} way:
27562
27563@itemize @bullet
27564@item
27565Can be used with file formats that don't support multiple sections.
27566
27567@item
27568Ease of finding scripts for public libraries.
27569
27570Scripts specified in the @code{.debug_gdb_scripts} section are searched for
27571in the source search path.
27572For publicly installed libraries, e.g., @file{libstdc++}, there typically
27573isn't a source directory in which to find the script.
27574
27575@item
27576Doesn't require source code additions.
27577@end itemize
27578
27579@noindent
27580Benefits of the @code{.debug_gdb_scripts} way:
27581
27582@itemize @bullet
27583@item
27584Works with static linking.
27585
27586Scripts for libraries done the @file{-gdb.@var{ext}} way require an objfile to
27587trigger their loading.  When an application is statically linked the only
27588objfile available is the executable, and it is cumbersome to attach all the
27589scripts from all the input libraries to the executable's
27590@file{-gdb.@var{ext}} script.
27591
27592@item
27593Works with classes that are entirely inlined.
27594
27595Some classes can be entirely inlined, and thus there may not be an associated
27596shared library to attach a @file{-gdb.@var{ext}} script to.
27597
27598@item
27599Scripts needn't be copied out of the source tree.
27600
27601In some circumstances, apps can be built out of large collections of internal
27602libraries, and the build infrastructure necessary to install the
27603@file{-gdb.@var{ext}} scripts in a place where @value{GDBN} can find them is
27604cumbersome.  It may be easier to specify the scripts in the
27605@code{.debug_gdb_scripts} section as relative paths, and add a path to the
27606top of the source tree to the source search path.
27607@end itemize
27608
27609@node Multiple Extension Languages
27610@section Multiple Extension Languages
27611
27612The Guile and Python extension languages do not share any state,
27613and generally do not interfere with each other.
27614There are some things to be aware of, however.
27615
27616@subsection Python comes first
27617
27618Python was @value{GDBN}'s first extension language, and to avoid breaking
27619existing behaviour Python comes first.  This is generally solved by the
27620``first one wins'' principle.  @value{GDBN} maintains a list of enabled
27621extension languages, and when it makes a call to an extension language,
27622(say to pretty-print a value), it tries each in turn until an extension
27623language indicates it has performed the request (e.g., has returned the
27624pretty-printed form of a value).
27625This extends to errors while performing such requests: If an error happens
27626while, for example, trying to pretty-print an object then the error is
27627reported and any following extension languages are not tried.
27628
27629@node Aliases
27630@section Creating new spellings of existing commands
27631@cindex aliases for commands
27632
27633It is often useful to define alternate spellings of existing commands.
27634For example, if a new @value{GDBN} command defined in Python has
27635a long name to type, it is handy to have an abbreviated version of it
27636that involves less typing.
27637
27638@value{GDBN} itself uses aliases.  For example @samp{s} is an alias
27639of the @samp{step} command even though it is otherwise an ambiguous
27640abbreviation of other commands like @samp{set} and @samp{show}.
27641
27642Aliases are also used to provide shortened or more common versions
27643of multi-word commands.  For example, @value{GDBN} provides the
27644@samp{tty} alias of the @samp{set inferior-tty} command.
27645
27646You can define a new alias with the @samp{alias} command.
27647
27648@table @code
27649
27650@kindex alias
27651@item alias [-a] [--] @var{ALIAS} = @var{COMMAND} [DEFAULT-ARGS...]
27652
27653@end table
27654
27655@var{ALIAS} specifies the name of the new alias.
27656Each word of @var{ALIAS} must consist of letters, numbers, dashes and
27657underscores.
27658
27659@var{COMMAND} specifies the name of an existing command
27660that is being aliased.
27661
27662@var{COMMAND} can also be the name of an existing alias.  In this case,
27663@var{COMMAND} cannot be an alias that has default arguments.
27664
27665The @samp{-a} option specifies that the new alias is an abbreviation
27666of the command.  Abbreviations are not used in command completion.
27667
27668The @samp{--} option specifies the end of options,
27669and is useful when @var{ALIAS} begins with a dash.
27670
27671You can specify @var{default-args} for your alias.
27672These @var{default-args} will be automatically added before the alias
27673arguments typed explicitly on the command line.
27674
27675For example, the below defines an alias @code{btfullall} that shows all local
27676variables and all frame arguments:
27677@smallexample
27678(@value{GDBP}) alias btfullall = backtrace -full -frame-arguments all
27679@end smallexample
27680
27681For more information about @var{default-args}, see @ref{Command aliases default args,
27682,Automatically prepend default arguments to user-defined aliases}.
27683
27684Here is a simple example showing how to make an abbreviation
27685of a command so that there is less to type.
27686Suppose you were tired of typing @samp{disas}, the current
27687shortest unambiguous abbreviation of the @samp{disassemble} command
27688and you wanted an even shorter version named @samp{di}.
27689The following will accomplish this.
27690
27691@smallexample
27692(gdb) alias -a di = disas
27693@end smallexample
27694
27695Note that aliases are different from user-defined commands.
27696With a user-defined command, you also need to write documentation
27697for it with the @samp{document} command.
27698An alias automatically picks up the documentation of the existing command.
27699
27700Here is an example where we make @samp{elms} an abbreviation of
27701@samp{elements} in the @samp{set print elements} command.
27702This is to show that you can make an abbreviation of any part
27703of a command.
27704
27705@smallexample
27706(gdb) alias -a set print elms = set print elements
27707(gdb) alias -a show print elms = show print elements
27708(gdb) set p elms 20
27709(gdb) show p elms
27710Limit on string chars or array elements to print is 200.
27711@end smallexample
27712
27713Note that if you are defining an alias of a @samp{set} command,
27714and you want to have an alias for the corresponding @samp{show}
27715command, then you need to define the latter separately.
27716
27717Unambiguously abbreviated commands are allowed in @var{COMMAND} and
27718@var{ALIAS}, just as they are normally.
27719
27720@smallexample
27721(gdb) alias -a set pr elms = set p ele
27722@end smallexample
27723
27724Finally, here is an example showing the creation of a one word
27725alias for a more complex command.
27726This creates alias @samp{spe} of the command @samp{set print elements}.
27727
27728@smallexample
27729(gdb) alias spe = set print elements
27730(gdb) spe 20
27731@end smallexample
27732
27733@node Interpreters
27734@chapter Command Interpreters
27735@cindex command interpreters
27736
27737@value{GDBN} supports multiple command interpreters, and some command
27738infrastructure to allow users or user interface writers to switch
27739between interpreters or run commands in other interpreters.
27740
27741@value{GDBN} currently supports two command interpreters, the console
27742interpreter (sometimes called the command-line interpreter or @sc{cli})
27743and the machine interface interpreter (or @sc{gdb/mi}).  This manual
27744describes both of these interfaces in great detail.
27745
27746By default, @value{GDBN} will start with the console interpreter.
27747However, the user may choose to start @value{GDBN} with another
27748interpreter by specifying the @option{-i} or @option{--interpreter}
27749startup options.  Defined interpreters include:
27750
27751@table @code
27752@item console
27753@cindex console interpreter
27754The traditional console or command-line interpreter.  This is the most often
27755used interpreter with @value{GDBN}. With no interpreter specified at runtime,
27756@value{GDBN} will use this interpreter.
27757
27758@item mi
27759@cindex mi interpreter
27760The newest @sc{gdb/mi} interface (currently @code{mi3}).  Used primarily
27761by programs wishing to use @value{GDBN} as a backend for a debugger GUI
27762or an IDE.  For more information, see @ref{GDB/MI, ,The @sc{gdb/mi}
27763Interface}.
27764
27765@item mi3
27766@cindex mi3 interpreter
27767The @sc{gdb/mi} interface introduced in @value{GDBN} 9.1.
27768
27769@item mi2
27770@cindex mi2 interpreter
27771The @sc{gdb/mi} interface introduced in @value{GDBN} 6.0.
27772
27773@item mi1
27774@cindex mi1 interpreter
27775The @sc{gdb/mi} interface introduced in @value{GDBN} 5.1.
27776
27777@end table
27778
27779@cindex invoke another interpreter
27780
27781@kindex interpreter-exec
27782You may execute commands in any interpreter from the current
27783interpreter using the appropriate command.  If you are running the
27784console interpreter, simply use the @code{interpreter-exec} command:
27785
27786@smallexample
27787interpreter-exec mi "-data-list-register-names"
27788@end smallexample
27789
27790@sc{gdb/mi} has a similar command, although it is only available in versions of
27791@value{GDBN} which support @sc{gdb/mi} version 2 (or greater).
27792
27793Note that @code{interpreter-exec} only changes the interpreter for the
27794duration of the specified command.  It does not change the interpreter
27795permanently.
27796
27797@cindex start a new independent interpreter
27798
27799Although you may only choose a single interpreter at startup, it is
27800possible to run an independent interpreter on a specified input/output
27801device (usually a tty).
27802
27803For example, consider a debugger GUI or IDE that wants to provide a
27804@value{GDBN} console view.  It may do so by embedding a terminal
27805emulator widget in its GUI, starting @value{GDBN} in the traditional
27806command-line mode with stdin/stdout/stderr redirected to that
27807terminal, and then creating an MI interpreter running on a specified
27808input/output device.  The console interpreter created by @value{GDBN}
27809at startup handles commands the user types in the terminal widget,
27810while the GUI controls and synchronizes state with @value{GDBN} using
27811the separate MI interpreter.
27812
27813To start a new secondary @dfn{user interface} running MI, use the
27814@code{new-ui} command:
27815
27816@kindex new-ui
27817@cindex new user interface
27818@smallexample
27819new-ui @var{interpreter} @var{tty}
27820@end smallexample
27821
27822The @var{interpreter} parameter specifies the interpreter to run.
27823This accepts the same values as the @code{interpreter-exec} command.
27824For example, @samp{console}, @samp{mi}, @samp{mi2}, etc.  The
27825@var{tty} parameter specifies the name of the bidirectional file the
27826interpreter uses for input/output, usually the name of a
27827pseudoterminal slave on Unix systems.  For example:
27828
27829@smallexample
27830(@value{GDBP}) new-ui mi /dev/pts/9
27831@end smallexample
27832
27833@noindent
27834runs an MI interpreter on @file{/dev/pts/9}.
27835
27836@node TUI
27837@chapter @value{GDBN} Text User Interface
27838@cindex TUI
27839@cindex Text User Interface
27840
27841@menu
27842* TUI Overview::                TUI overview
27843* TUI Keys::                    TUI key bindings
27844* TUI Single Key Mode::         TUI single key mode
27845* TUI Commands::                TUI-specific commands
27846* TUI Configuration::           TUI configuration variables
27847@end menu
27848
27849The @value{GDBN} Text User Interface (TUI) is a terminal
27850interface which uses the @code{curses} library to show the source
27851file, the assembly output, the program registers and @value{GDBN}
27852commands in separate text windows.  The TUI mode is supported only
27853on platforms where a suitable version of the @code{curses} library
27854is available.
27855
27856The TUI mode is enabled by default when you invoke @value{GDBN} as
27857@samp{@value{GDBP} -tui}.
27858You can also switch in and out of TUI mode while @value{GDBN} runs by
27859using various TUI commands and key bindings, such as @command{tui
27860enable} or @kbd{C-x C-a}.  @xref{TUI Commands, ,TUI Commands}, and
27861@ref{TUI Keys, ,TUI Key Bindings}.
27862
27863@node TUI Overview
27864@section TUI Overview
27865
27866In TUI mode, @value{GDBN} can display several text windows:
27867
27868@table @emph
27869@item command
27870This window is the @value{GDBN} command window with the @value{GDBN}
27871prompt and the @value{GDBN} output.  The @value{GDBN} input is still
27872managed using readline.
27873
27874@item source
27875The source window shows the source file of the program.  The current
27876line and active breakpoints are displayed in this window.
27877
27878@item assembly
27879The assembly window shows the disassembly output of the program.
27880
27881@item register
27882This window shows the processor registers.  Registers are highlighted
27883when their values change.
27884@end table
27885
27886The source and assembly windows show the current program position
27887by highlighting the current line and marking it with a @samp{>} marker.
27888Breakpoints are indicated with two markers.  The first marker
27889indicates the breakpoint type:
27890
27891@table @code
27892@item B
27893Breakpoint which was hit at least once.
27894
27895@item b
27896Breakpoint which was never hit.
27897
27898@item H
27899Hardware breakpoint which was hit at least once.
27900
27901@item h
27902Hardware breakpoint which was never hit.
27903@end table
27904
27905The second marker indicates whether the breakpoint is enabled or not:
27906
27907@table @code
27908@item +
27909Breakpoint is enabled.
27910
27911@item -
27912Breakpoint is disabled.
27913@end table
27914
27915The source, assembly and register windows are updated when the current
27916thread changes, when the frame changes, or when the program counter
27917changes.
27918
27919These windows are not all visible at the same time.  The command
27920window is always visible.  The others can be arranged in several
27921layouts:
27922
27923@itemize @bullet
27924@item
27925source only,
27926
27927@item
27928assembly only,
27929
27930@item
27931source and assembly,
27932
27933@item
27934source and registers, or
27935
27936@item
27937assembly and registers.
27938@end itemize
27939
27940These are the standard layouts, but other layouts can be defined.
27941
27942A status line above the command window shows the following information:
27943
27944@table @emph
27945@item target
27946Indicates the current @value{GDBN} target.
27947(@pxref{Targets, ,Specifying a Debugging Target}).
27948
27949@item process
27950Gives the current process or thread number.
27951When no process is being debugged, this field is set to @code{No process}.
27952
27953@item function
27954Gives the current function name for the selected frame.
27955The name is demangled if demangling is turned on (@pxref{Print Settings}).
27956When there is no symbol corresponding to the current program counter,
27957the string @code{??} is displayed.
27958
27959@item line
27960Indicates the current line number for the selected frame.
27961When the current line number is not known, the string @code{??} is displayed.
27962
27963@item pc
27964Indicates the current program counter address.
27965@end table
27966
27967@node TUI Keys
27968@section TUI Key Bindings
27969@cindex TUI key bindings
27970
27971The TUI installs several key bindings in the readline keymaps
27972@ifset SYSTEM_READLINE
27973(@pxref{Command Line Editing, , , rluserman, GNU Readline Library}).
27974@end ifset
27975@ifclear SYSTEM_READLINE
27976(@pxref{Command Line Editing}).
27977@end ifclear
27978The following key bindings are installed for both TUI mode and the
27979@value{GDBN} standard mode.
27980
27981@table @kbd
27982@kindex C-x C-a
27983@item C-x C-a
27984@kindex C-x a
27985@itemx C-x a
27986@kindex C-x A
27987@itemx C-x A
27988Enter or leave the TUI mode.  When leaving the TUI mode,
27989the curses window management stops and @value{GDBN} operates using
27990its standard mode, writing on the terminal directly.  When reentering
27991the TUI mode, control is given back to the curses windows.
27992The screen is then refreshed.
27993
27994This key binding uses the bindable Readline function
27995@code{tui-switch-mode}.
27996
27997@kindex C-x 1
27998@item C-x 1
27999Use a TUI layout with only one window.  The layout will
28000either be @samp{source} or @samp{assembly}.  When the TUI mode
28001is not active, it will switch to the TUI mode.
28002
28003Think of this key binding as the Emacs @kbd{C-x 1} binding.
28004
28005This key binding uses the bindable Readline function
28006@code{tui-delete-other-windows}.
28007
28008@kindex C-x 2
28009@item C-x 2
28010Use a TUI layout with at least two windows.  When the current
28011layout already has two windows, the next layout with two windows is used.
28012When a new layout is chosen, one window will always be common to the
28013previous layout and the new one.
28014
28015Think of it as the Emacs @kbd{C-x 2} binding.
28016
28017This key binding uses the bindable Readline function
28018@code{tui-change-windows}.
28019
28020@kindex C-x o
28021@item C-x o
28022Change the active window.  The TUI associates several key bindings
28023(like scrolling and arrow keys) with the active window.  This command
28024gives the focus to the next TUI window.
28025
28026Think of it as the Emacs @kbd{C-x o} binding.
28027
28028This key binding uses the bindable Readline function
28029@code{tui-other-window}.
28030
28031@kindex C-x s
28032@item C-x s
28033Switch in and out of the TUI SingleKey mode that binds single
28034keys to @value{GDBN} commands (@pxref{TUI Single Key Mode}).
28035
28036This key binding uses the bindable Readline function
28037@code{next-keymap}.
28038@end table
28039
28040The following key bindings only work in the TUI mode:
28041
28042@table @asis
28043@kindex PgUp
28044@item @key{PgUp}
28045Scroll the active window one page up.
28046
28047@kindex PgDn
28048@item @key{PgDn}
28049Scroll the active window one page down.
28050
28051@kindex Up
28052@item @key{Up}
28053Scroll the active window one line up.
28054
28055@kindex Down
28056@item @key{Down}
28057Scroll the active window one line down.
28058
28059@kindex Left
28060@item @key{Left}
28061Scroll the active window one column left.
28062
28063@kindex Right
28064@item @key{Right}
28065Scroll the active window one column right.
28066
28067@kindex C-L
28068@item @kbd{C-L}
28069Refresh the screen.
28070@end table
28071
28072Because the arrow keys scroll the active window in the TUI mode, they
28073are not available for their normal use by readline unless the command
28074window has the focus.  When another window is active, you must use
28075other readline key bindings such as @kbd{C-p}, @kbd{C-n}, @kbd{C-b}
28076and @kbd{C-f} to control the command window.
28077
28078@node TUI Single Key Mode
28079@section TUI Single Key Mode
28080@cindex TUI single key mode
28081
28082The TUI also provides a @dfn{SingleKey} mode, which binds several
28083frequently used @value{GDBN} commands to single keys.  Type @kbd{C-x s} to
28084switch into this mode, where the following key bindings are used:
28085
28086@table @kbd
28087@kindex c @r{(SingleKey TUI key)}
28088@item c
28089continue
28090
28091@kindex d @r{(SingleKey TUI key)}
28092@item d
28093down
28094
28095@kindex f @r{(SingleKey TUI key)}
28096@item f
28097finish
28098
28099@kindex n @r{(SingleKey TUI key)}
28100@item n
28101next
28102
28103@kindex o @r{(SingleKey TUI key)}
28104@item o
28105nexti.  The shortcut letter @samp{o} stands for ``step Over''.
28106
28107@kindex q @r{(SingleKey TUI key)}
28108@item q
28109exit the SingleKey mode.
28110
28111@kindex r @r{(SingleKey TUI key)}
28112@item r
28113run
28114
28115@kindex s @r{(SingleKey TUI key)}
28116@item s
28117step
28118
28119@kindex i @r{(SingleKey TUI key)}
28120@item i
28121stepi.  The shortcut letter @samp{i} stands for ``step Into''.
28122
28123@kindex u @r{(SingleKey TUI key)}
28124@item u
28125up
28126
28127@kindex v @r{(SingleKey TUI key)}
28128@item v
28129info locals
28130
28131@kindex w @r{(SingleKey TUI key)}
28132@item w
28133where
28134@end table
28135
28136Other keys temporarily switch to the @value{GDBN} command prompt.
28137The key that was pressed is inserted in the editing buffer so that
28138it is possible to type most @value{GDBN} commands without interaction
28139with the TUI SingleKey mode.  Once the command is entered the TUI
28140SingleKey mode is restored.  The only way to permanently leave
28141this mode is by typing @kbd{q} or @kbd{C-x s}.
28142
28143@cindex SingleKey keymap name
28144If @value{GDBN} was built with Readline 8.0 or later, the TUI
28145SingleKey keymap will be named @samp{SingleKey}.  This can be used in
28146@file{.inputrc} to add additional bindings to this keymap.
28147
28148@node TUI Commands
28149@section TUI-specific Commands
28150@cindex TUI commands
28151
28152The TUI has specific commands to control the text windows.
28153These commands are always available, even when @value{GDBN} is not in
28154the TUI mode.  When @value{GDBN} is in the standard mode, most
28155of these commands will automatically switch to the TUI mode.
28156
28157Note that if @value{GDBN}'s @code{stdout} is not connected to a
28158terminal, or @value{GDBN} has been started with the machine interface
28159interpreter (@pxref{GDB/MI, ,The @sc{gdb/mi} Interface}), most of
28160these commands will fail with an error, because it would not be
28161possible or desirable to enable curses window management.
28162
28163@table @code
28164@item tui enable
28165@kindex tui enable
28166Activate TUI mode.  The last active TUI window layout will be used if
28167TUI mode has previously been used in the current debugging session,
28168otherwise a default layout is used.
28169
28170@item tui disable
28171@kindex tui disable
28172Disable TUI mode, returning to the console interpreter.
28173
28174@item info win
28175@kindex info win
28176List and give the size of all displayed windows.
28177
28178@item tui new-layout @var{name} @var{window} @var{weight} @r{[}@var{window} @var{weight}@dots{}@r{]}
28179@kindex tui new-layout
28180Create a new TUI layout.  The new layout will be named @var{name}, and
28181can be accessed using the @code{layout} command (see below).
28182
28183Each @var{window} parameter is either the name of a window to display,
28184or a window description.  The windows will be displayed from top to
28185bottom in the order listed.
28186
28187The names of the windows are the same as the ones given to the
28188@code{focus} command (see below); additional, the @code{status}
28189window can be specified.  Note that, because it is of fixed height,
28190the weight assigned to the status window is of no importance.  It is
28191conventional to use @samp{0} here.
28192
28193A window description looks a bit like an invocation of @code{tui
28194new-layout}, and is of the form
28195@{@r{[}@code{-horizontal}@r{]}@var{window} @var{weight} @r{[}@var{window} @var{weight}@dots{}@r{]}@}.
28196
28197This specifies a sub-layout.  If @code{-horizontal} is given, the
28198windows in this description will be arranged side-by-side, rather than
28199top-to-bottom.
28200
28201Each @var{weight} is an integer.  It is the weight of this window
28202relative to all the other windows in the layout.  These numbers are
28203used to calculate how much of the screen is given to each window.
28204
28205For example:
28206
28207@example
28208(gdb) tui new-layout example src 1 regs 1 status 0 cmd 1
28209@end example
28210
28211Here, the new layout is called @samp{example}.  It shows the source
28212and register windows, followed by the status window, and then finally
28213the command window.  The non-status windows all have the same weight,
28214so the terminal will be split into three roughly equal sections.
28215
28216Here is a more complex example, showing a horizontal layout:
28217
28218@example
28219(gdb) tui new-layout example @{-horizontal src 1 asm 1@} 2 status 0 cmd 1
28220@end example
28221
28222This will result in side-by-side source and assembly windows; with the
28223status and command window being beneath these, filling the entire
28224width of the terminal.  Because they have weight 2, the source and
28225assembly windows will be twice the height of the command window.
28226
28227@item layout @var{name}
28228@kindex layout
28229Changes which TUI windows are displayed.  The @var{name} parameter
28230controls which layout is shown.  It can be either one of the built-in
28231layout names, or the name of a layout defined by the user using
28232@code{tui new-layout}.
28233
28234The built-in layouts are as follows:
28235
28236@table @code
28237@item next
28238Display the next layout.
28239
28240@item prev
28241Display the previous layout.
28242
28243@item src
28244Display the source and command windows.
28245
28246@item asm
28247Display the assembly and command windows.
28248
28249@item split
28250Display the source, assembly, and command windows.
28251
28252@item regs
28253When in @code{src} layout display the register, source, and command
28254windows.  When in @code{asm} or @code{split} layout display the
28255register, assembler, and command windows.
28256@end table
28257
28258@item focus @var{name}
28259@kindex focus
28260Changes which TUI window is currently active for scrolling.  The
28261@var{name} parameter can be any of the following:
28262
28263@table @code
28264@item next
28265Make the next window active for scrolling.
28266
28267@item prev
28268Make the previous window active for scrolling.
28269
28270@item src
28271Make the source window active for scrolling.
28272
28273@item asm
28274Make the assembly window active for scrolling.
28275
28276@item regs
28277Make the register window active for scrolling.
28278
28279@item cmd
28280Make the command window active for scrolling.
28281@end table
28282
28283@item refresh
28284@kindex refresh
28285Refresh the screen.  This is similar to typing @kbd{C-L}.
28286
28287@item tui reg @var{group}
28288@kindex tui reg
28289Changes the register group displayed in the tui register window to
28290@var{group}.  If the register window is not currently displayed this
28291command will cause the register window to be displayed.  The list of
28292register groups, as well as their order is target specific. The
28293following groups are available on most targets:
28294@table @code
28295@item next
28296Repeatedly selecting this group will cause the display to cycle
28297through all of the available register groups.
28298
28299@item prev
28300Repeatedly selecting this group will cause the display to cycle
28301through all of the available register groups in the reverse order to
28302@var{next}.
28303
28304@item general
28305Display the general registers.
28306@item float
28307Display the floating point registers.
28308@item system
28309Display the system registers.
28310@item vector
28311Display the vector registers.
28312@item all
28313Display all registers.
28314@end table
28315
28316@item update
28317@kindex update
28318Update the source window and the current execution point.
28319
28320@item winheight @var{name} +@var{count}
28321@itemx winheight @var{name} -@var{count}
28322@kindex winheight
28323Change the height of the window @var{name} by @var{count}
28324lines.  Positive counts increase the height, while negative counts
28325decrease it.  The @var{name} parameter can be one of @code{src} (the
28326source window), @code{cmd} (the command window), @code{asm} (the
28327disassembly window), or @code{regs} (the register display window).
28328@end table
28329
28330@node TUI Configuration
28331@section TUI Configuration Variables
28332@cindex TUI configuration variables
28333
28334Several configuration variables control the appearance of TUI windows.
28335
28336@table @code
28337@item set tui border-kind @var{kind}
28338@kindex set tui border-kind
28339Select the border appearance for the source, assembly and register windows.
28340The possible values are the following:
28341@table @code
28342@item space
28343Use a space character to draw the border.
28344
28345@item ascii
28346Use @sc{ascii} characters @samp{+}, @samp{-} and @samp{|} to draw the border.
28347
28348@item acs
28349Use the Alternate Character Set to draw the border.  The border is
28350drawn using character line graphics if the terminal supports them.
28351@end table
28352
28353@item set tui border-mode @var{mode}
28354@kindex set tui border-mode
28355@itemx set tui active-border-mode @var{mode}
28356@kindex set tui active-border-mode
28357Select the display attributes for the borders of the inactive windows
28358or the active window.  The @var{mode} can be one of the following:
28359@table @code
28360@item normal
28361Use normal attributes to display the border.
28362
28363@item standout
28364Use standout mode.
28365
28366@item reverse
28367Use reverse video mode.
28368
28369@item half
28370Use half bright mode.
28371
28372@item half-standout
28373Use half bright and standout mode.
28374
28375@item bold
28376Use extra bright or bold mode.
28377
28378@item bold-standout
28379Use extra bright or bold and standout mode.
28380@end table
28381
28382@item set tui tab-width @var{nchars}
28383@kindex set tui tab-width
28384@kindex tabset
28385Set the width of tab stops to be @var{nchars} characters.  This
28386setting affects the display of TAB characters in the source and
28387assembly windows.
28388
28389@item set tui compact-source @r{[}on@r{|}off@r{]}
28390@kindex set tui compact-source
28391Set whether the TUI source window is displayed in ``compact'' form.
28392The default display uses more space for line numbers and starts the
28393source text at the next tab stop; the compact display uses only as
28394much space as is needed for the line numbers in the current file, and
28395only a single space to separate the line numbers from the source.
28396@end table
28397
28398Note that the colors of the TUI borders can be controlled using the
28399appropriate @code{set style} commands.  @xref{Output Styling}.
28400
28401@node Emacs
28402@chapter Using @value{GDBN} under @sc{gnu} Emacs
28403
28404@cindex Emacs
28405@cindex @sc{gnu} Emacs
28406A special interface allows you to use @sc{gnu} Emacs to view (and
28407edit) the source files for the program you are debugging with
28408@value{GDBN}.
28409
28410To use this interface, use the command @kbd{M-x gdb} in Emacs.  Give the
28411executable file you want to debug as an argument.  This command starts
28412@value{GDBN} as a subprocess of Emacs, with input and output through a newly
28413created Emacs buffer.
28414@c (Do not use the @code{-tui} option to run @value{GDBN} from Emacs.)
28415
28416Running @value{GDBN} under Emacs can be just like running @value{GDBN} normally except for two
28417things:
28418
28419@itemize @bullet
28420@item
28421All ``terminal'' input and output goes through an Emacs buffer, called
28422the GUD buffer.
28423
28424This applies both to @value{GDBN} commands and their output, and to the input
28425and output done by the program you are debugging.
28426
28427This is useful because it means that you can copy the text of previous
28428commands and input them again; you can even use parts of the output
28429in this way.
28430
28431All the facilities of Emacs' Shell mode are available for interacting
28432with your program.  In particular, you can send signals the usual
28433way---for example, @kbd{C-c C-c} for an interrupt, @kbd{C-c C-z} for a
28434stop.
28435
28436@item
28437@value{GDBN} displays source code through Emacs.
28438
28439Each time @value{GDBN} displays a stack frame, Emacs automatically finds the
28440source file for that frame and puts an arrow (@samp{=>}) at the
28441left margin of the current line.  Emacs uses a separate buffer for
28442source display, and splits the screen to show both your @value{GDBN} session
28443and the source.
28444
28445Explicit @value{GDBN} @code{list} or search commands still produce output as
28446usual, but you probably have no reason to use them from Emacs.
28447@end itemize
28448
28449We call this @dfn{text command mode}.  Emacs 22.1, and later, also uses
28450a graphical mode, enabled by default, which provides further buffers
28451that can control the execution and describe the state of your program.
28452@xref{GDB Graphical Interface,,, Emacs, The @sc{gnu} Emacs Manual}.
28453
28454If you specify an absolute file name when prompted for the @kbd{M-x
28455gdb} argument, then Emacs sets your current working directory to where
28456your program resides.  If you only specify the file name, then Emacs
28457sets your current working directory to the directory associated
28458with the previous buffer.  In this case, @value{GDBN} may find your
28459program by searching your environment's @code{PATH} variable, but on
28460some operating systems it might not find the source.  So, although the
28461@value{GDBN} input and output session proceeds normally, the auxiliary
28462buffer does not display the current source and line of execution.
28463
28464The initial working directory of @value{GDBN} is printed on the top
28465line of the GUD buffer and this serves as a default for the commands
28466that specify files for @value{GDBN} to operate on.  @xref{Files,
28467,Commands to Specify Files}.
28468
28469By default, @kbd{M-x gdb} calls the program called @file{gdb}.  If you
28470need to call @value{GDBN} by a different name (for example, if you
28471keep several configurations around, with different names) you can
28472customize the Emacs variable @code{gud-gdb-command-name} to run the
28473one you want.
28474
28475In the GUD buffer, you can use these special Emacs commands in
28476addition to the standard Shell mode commands:
28477
28478@table @kbd
28479@item C-h m
28480Describe the features of Emacs' GUD Mode.
28481
28482@item C-c C-s
28483Execute to another source line, like the @value{GDBN} @code{step} command; also
28484update the display window to show the current file and location.
28485
28486@item C-c C-n
28487Execute to next source line in this function, skipping all function
28488calls, like the @value{GDBN} @code{next} command.  Then update the display window
28489to show the current file and location.
28490
28491@item C-c C-i
28492Execute one instruction, like the @value{GDBN} @code{stepi} command; update
28493display window accordingly.
28494
28495@item C-c C-f
28496Execute until exit from the selected stack frame, like the @value{GDBN}
28497@code{finish} command.
28498
28499@item C-c C-r
28500Continue execution of your program, like the @value{GDBN} @code{continue}
28501command.
28502
28503@item C-c <
28504Go up the number of frames indicated by the numeric argument
28505(@pxref{Arguments, , Numeric Arguments, Emacs, The @sc{gnu} Emacs Manual}),
28506like the @value{GDBN} @code{up} command.
28507
28508@item C-c >
28509Go down the number of frames indicated by the numeric argument, like the
28510@value{GDBN} @code{down} command.
28511@end table
28512
28513In any source file, the Emacs command @kbd{C-x @key{SPC}} (@code{gud-break})
28514tells @value{GDBN} to set a breakpoint on the source line point is on.
28515
28516In text command mode, if you type @kbd{M-x speedbar}, Emacs displays a
28517separate frame which shows a backtrace when the GUD buffer is current.
28518Move point to any frame in the stack and type @key{RET} to make it
28519become the current frame and display the associated source in the
28520source buffer.  Alternatively, click @kbd{Mouse-2} to make the
28521selected frame become the current one.  In graphical mode, the
28522speedbar displays watch expressions.
28523
28524If you accidentally delete the source-display buffer, an easy way to get
28525it back is to type the command @code{f} in the @value{GDBN} buffer, to
28526request a frame display; when you run under Emacs, this recreates
28527the source buffer if necessary to show you the context of the current
28528frame.
28529
28530The source files displayed in Emacs are in ordinary Emacs buffers
28531which are visiting the source files in the usual way.  You can edit
28532the files with these buffers if you wish; but keep in mind that @value{GDBN}
28533communicates with Emacs in terms of line numbers.  If you add or
28534delete lines from the text, the line numbers that @value{GDBN} knows cease
28535to correspond properly with the code.
28536
28537A more detailed description of Emacs' interaction with @value{GDBN} is
28538given in the Emacs manual (@pxref{Debuggers,,, Emacs, The @sc{gnu}
28539Emacs Manual}).
28540
28541@node GDB/MI
28542@chapter The @sc{gdb/mi} Interface
28543
28544@unnumberedsec Function and Purpose
28545
28546@cindex @sc{gdb/mi}, its purpose
28547@sc{gdb/mi} is a line based machine oriented text interface to
28548@value{GDBN} and is activated by specifying using the
28549@option{--interpreter} command line option (@pxref{Mode Options}).  It
28550is specifically intended to support the development of systems which
28551use the debugger as just one small component of a larger system.
28552
28553This chapter is a specification of the @sc{gdb/mi} interface.  It is written
28554in the form of a reference manual.
28555
28556Note that @sc{gdb/mi} is still under construction, so some of the
28557features described below are incomplete and subject to change
28558(@pxref{GDB/MI Development and Front Ends, , @sc{gdb/mi} Development and Front Ends}).
28559
28560@unnumberedsec Notation and Terminology
28561
28562@cindex notational conventions, for @sc{gdb/mi}
28563This chapter uses the following notation:
28564
28565@itemize @bullet
28566@item
28567@code{|} separates two alternatives.
28568
28569@item
28570@code{[ @var{something} ]} indicates that @var{something} is optional:
28571it may or may not be given.
28572
28573@item
28574@code{( @var{group} )*} means that @var{group} inside the parentheses
28575may repeat zero or more times.
28576
28577@item
28578@code{( @var{group} )+} means that @var{group} inside the parentheses
28579may repeat one or more times.
28580
28581@item
28582@code{"@var{string}"} means a literal @var{string}.
28583@end itemize
28584
28585@ignore
28586@heading Dependencies
28587@end ignore
28588
28589@menu
28590* GDB/MI General Design::
28591* GDB/MI Command Syntax::
28592* GDB/MI Compatibility with CLI::
28593* GDB/MI Development and Front Ends::
28594* GDB/MI Output Records::
28595* GDB/MI Simple Examples::
28596* GDB/MI Command Description Format::
28597* GDB/MI Breakpoint Commands::
28598* GDB/MI Catchpoint Commands::
28599* GDB/MI Program Context::
28600* GDB/MI Thread Commands::
28601* GDB/MI Ada Tasking Commands::
28602* GDB/MI Program Execution::
28603* GDB/MI Stack Manipulation::
28604* GDB/MI Variable Objects::
28605* GDB/MI Data Manipulation::
28606* GDB/MI Tracepoint Commands::
28607* GDB/MI Symbol Query::
28608* GDB/MI File Commands::
28609@ignore
28610* GDB/MI Kod Commands::
28611* GDB/MI Memory Overlay Commands::
28612* GDB/MI Signal Handling Commands::
28613@end ignore
28614* GDB/MI Target Manipulation::
28615* GDB/MI File Transfer Commands::
28616* GDB/MI Ada Exceptions Commands::
28617* GDB/MI Support Commands::
28618* GDB/MI Miscellaneous Commands::
28619@end menu
28620
28621@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28622@node GDB/MI General Design
28623@section @sc{gdb/mi} General Design
28624@cindex GDB/MI General Design
28625
28626Interaction of a @sc{GDB/MI} frontend with @value{GDBN} involves three
28627parts---commands sent to @value{GDBN}, responses to those commands
28628and notifications.  Each command results in exactly one response,
28629indicating either successful completion of the command, or an error.
28630For the commands that do not resume the target, the response contains the
28631requested information.  For the commands that resume the target, the
28632response only indicates whether the target was successfully resumed.
28633Notifications is the mechanism for reporting changes in the state of the
28634target, or in @value{GDBN} state, that cannot conveniently be associated with
28635a command and reported as part of that command response.
28636
28637The important examples of notifications are:
28638@itemize @bullet
28639
28640@item
28641Exec notifications.  These are used to report changes in
28642target state---when a target is resumed, or stopped.  It would not
28643be feasible to include this information in response of resuming
28644commands, because one resume commands can result in multiple events in
28645different threads.  Also, quite some time may pass before any event
28646happens in the target, while a frontend needs to know whether the resuming
28647command itself was successfully executed.
28648
28649@item
28650Console output, and status notifications.  Console output
28651notifications are used to report output of CLI commands, as well as
28652diagnostics for other commands.  Status notifications are used to
28653report the progress of a long-running operation.  Naturally, including
28654this information in command response would mean no output is produced
28655until the command is finished, which is undesirable.
28656
28657@item
28658General notifications.  Commands may have various side effects on
28659the @value{GDBN} or target state beyond their official purpose.  For example,
28660a command may change the selected thread.  Although such changes can
28661be included in command response, using notification allows for more
28662orthogonal frontend design.
28663
28664@end itemize
28665
28666There's no guarantee that whenever an MI command reports an error,
28667@value{GDBN} or the target are in any specific state, and especially,
28668the state is not reverted to the state before the MI command was
28669processed.  Therefore, whenever an MI command results in an error,
28670we recommend that the frontend refreshes all the information shown in
28671the user interface.
28672
28673
28674@menu
28675* Context management::
28676* Asynchronous and non-stop modes::
28677* Thread groups::
28678@end menu
28679
28680@node Context management
28681@subsection Context management
28682
28683@subsubsection Threads and Frames
28684
28685In most cases when @value{GDBN} accesses the target, this access is
28686done in context of a specific thread and frame (@pxref{Frames}).
28687Often, even when accessing global data, the target requires that a thread
28688be specified.  The CLI interface maintains the selected thread and frame,
28689and supplies them to target on each command.  This is convenient,
28690because a command line user would not want to specify that information
28691explicitly on each command, and because user interacts with
28692@value{GDBN} via a single terminal, so no confusion is possible as
28693to what thread and frame are the current ones.
28694
28695In the case of MI, the concept of selected thread and frame is less
28696useful.  First, a frontend can easily remember this information
28697itself.  Second, a graphical frontend can have more than one window,
28698each one used for debugging a different thread, and the frontend might
28699want to access additional threads for internal purposes.  This
28700increases the risk that by relying on implicitly selected thread, the
28701frontend may be operating on a wrong one.  Therefore, each MI command
28702should explicitly specify which thread and frame to operate on.  To
28703make it possible, each MI command accepts the @samp{--thread} and
28704@samp{--frame} options, the value to each is @value{GDBN} global
28705identifier for thread and frame to operate on.
28706
28707Usually, each top-level window in a frontend allows the user to select
28708a thread and a frame, and remembers the user selection for further
28709operations.  However, in some cases @value{GDBN} may suggest that the
28710current thread or frame be changed.  For example, when stopping on a
28711breakpoint it is reasonable to switch to the thread where breakpoint is
28712hit.  For another example, if the user issues the CLI @samp{thread} or
28713@samp{frame} commands via the frontend, it is desirable to change the
28714frontend's selection to the one specified by user.  @value{GDBN}
28715communicates the suggestion to change current thread and frame using the
28716@samp{=thread-selected} notification.
28717
28718Note that historically, MI shares the selected thread with CLI, so
28719frontends used the @code{-thread-select} to execute commands in the
28720right context.  However, getting this to work right is cumbersome.  The
28721simplest way is for frontend to emit @code{-thread-select} command
28722before every command.  This doubles the number of commands that need
28723to be sent.  The alternative approach is to suppress @code{-thread-select}
28724if the selected thread in @value{GDBN} is supposed to be identical to the
28725thread the frontend wants to operate on.  However, getting this
28726optimization right can be tricky.  In particular, if the frontend
28727sends several commands to @value{GDBN}, and one of the commands changes the
28728selected thread, then the behaviour of subsequent commands will
28729change.  So, a frontend should either wait for response from such
28730problematic commands, or explicitly add @code{-thread-select} for
28731all subsequent commands.  No frontend is known to do this exactly
28732right, so it is suggested to just always pass the @samp{--thread} and
28733@samp{--frame} options.
28734
28735@subsubsection Language
28736
28737The execution of several commands depends on which language is selected.
28738By default, the current language (@pxref{show language}) is used.
28739But for commands known to be language-sensitive, it is recommended
28740to use the @samp{--language} option.  This option takes one argument,
28741which is the name of the language to use while executing the command.
28742For instance:
28743
28744@smallexample
28745-data-evaluate-expression --language c "sizeof (void*)"
28746^done,value="4"
28747(gdb)
28748@end smallexample
28749
28750The valid language names are the same names accepted by the
28751@samp{set language} command (@pxref{Manually}), excluding @samp{auto},
28752@samp{local} or @samp{unknown}.
28753
28754@node Asynchronous and non-stop modes
28755@subsection Asynchronous command execution and non-stop mode
28756
28757On some targets, @value{GDBN} is capable of processing MI commands
28758even while the target is running.  This is called @dfn{asynchronous
28759command execution} (@pxref{Background Execution}).  The frontend may
28760specify a preference for asynchronous execution using the
28761@code{-gdb-set mi-async 1} command, which should be emitted before
28762either running the executable or attaching to the target.  After the
28763frontend has started the executable or attached to the target, it can
28764find if asynchronous execution is enabled using the
28765@code{-list-target-features} command.
28766
28767@table @code
28768@item -gdb-set mi-async on
28769@item -gdb-set mi-async off
28770Set whether MI is in asynchronous mode.
28771
28772When @code{off}, which is the default, MI execution commands (e.g.,
28773@code{-exec-continue}) are foreground commands, and @value{GDBN} waits
28774for the program to stop before processing further commands.
28775
28776When @code{on}, MI execution commands are background execution
28777commands (e.g., @code{-exec-continue} becomes the equivalent of the
28778@code{c&} CLI command), and so @value{GDBN} is capable of processing
28779MI commands even while the target is running.
28780
28781@item -gdb-show mi-async
28782Show whether MI asynchronous mode is enabled.
28783@end table
28784
28785Note: In @value{GDBN} version 7.7 and earlier, this option was called
28786@code{target-async} instead of @code{mi-async}, and it had the effect
28787of both putting MI in asynchronous mode and making CLI background
28788commands possible.  CLI background commands are now always possible
28789``out of the box'' if the target supports them.  The old spelling is
28790kept as a deprecated alias for backwards compatibility.
28791
28792Even if @value{GDBN} can accept a command while target is running,
28793many commands that access the target do not work when the target is
28794running.  Therefore, asynchronous command execution is most useful
28795when combined with non-stop mode (@pxref{Non-Stop Mode}).  Then,
28796it is possible to examine the state of one thread, while other threads
28797are running.
28798
28799When a given thread is running, MI commands that try to access the
28800target in the context of that thread may not work, or may work only on
28801some targets.  In particular, commands that try to operate on thread's
28802stack will not work, on any target.  Commands that read memory, or
28803modify breakpoints, may work or not work, depending on the target.  Note
28804that even commands that operate on global state, such as @code{print},
28805@code{set}, and breakpoint commands, still access the target in the
28806context of a specific thread,  so frontend should try to find a
28807stopped thread and perform the operation on that thread (using the
28808@samp{--thread} option).
28809
28810Which commands will work in the context of a running thread is
28811highly target dependent.  However, the two commands
28812@code{-exec-interrupt}, to stop a thread, and @code{-thread-info},
28813to find the state of a thread, will always work.
28814
28815@node Thread groups
28816@subsection Thread groups
28817@value{GDBN} may be used to debug several processes at the same time.
28818On some platforms, @value{GDBN} may support debugging of several
28819hardware systems, each one having several cores with several different
28820processes running on each core.  This section describes the MI
28821mechanism to support such debugging scenarios.
28822
28823The key observation is that regardless of the structure of the
28824target, MI can have a global list of threads, because most commands that
28825accept the @samp{--thread} option do not need to know what process that
28826thread belongs to.  Therefore, it is not necessary to introduce
28827neither additional @samp{--process} option, nor an notion of the
28828current process in the MI interface.  The only strictly new feature
28829that is required is the ability to find how the threads are grouped
28830into processes.
28831
28832To allow the user to discover such grouping, and to support arbitrary
28833hierarchy of machines/cores/processes, MI introduces the concept of a
28834@dfn{thread group}.  Thread group is a collection of threads and other
28835thread groups.  A thread group always has a string identifier, a type,
28836and may have additional attributes specific to the type.  A new
28837command, @code{-list-thread-groups}, returns the list of top-level
28838thread groups, which correspond to processes that @value{GDBN} is
28839debugging at the moment.  By passing an identifier of a thread group
28840to the @code{-list-thread-groups} command, it is possible to obtain
28841the members of specific thread group.
28842
28843To allow the user to easily discover processes, and other objects, he
28844wishes to debug, a concept of @dfn{available thread group} is
28845introduced.  Available thread group is an thread group that
28846@value{GDBN} is not debugging, but that can be attached to, using the
28847@code{-target-attach} command.  The list of available top-level thread
28848groups can be obtained using @samp{-list-thread-groups --available}.
28849In general, the content of a thread group may be only retrieved only
28850after attaching to that thread group.
28851
28852Thread groups are related to inferiors (@pxref{Inferiors Connections and
28853Programs}).  Each inferior corresponds to a thread group of a special
28854type @samp{process}, and some additional operations are permitted on
28855such thread groups.
28856
28857@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28858@node GDB/MI Command Syntax
28859@section @sc{gdb/mi} Command Syntax
28860
28861@menu
28862* GDB/MI Input Syntax::
28863* GDB/MI Output Syntax::
28864@end menu
28865
28866@node GDB/MI Input Syntax
28867@subsection @sc{gdb/mi} Input Syntax
28868
28869@cindex input syntax for @sc{gdb/mi}
28870@cindex @sc{gdb/mi}, input syntax
28871@table @code
28872@item @var{command} @expansion{}
28873@code{@var{cli-command} | @var{mi-command}}
28874
28875@item @var{cli-command} @expansion{}
28876@code{[ @var{token} ] @var{cli-command} @var{nl}}, where
28877@var{cli-command} is any existing @value{GDBN} CLI command.
28878
28879@item @var{mi-command} @expansion{}
28880@code{[ @var{token} ] "-" @var{operation} ( " " @var{option} )*
28881@code{[} " --" @code{]} ( " " @var{parameter} )* @var{nl}}
28882
28883@item @var{token} @expansion{}
28884"any sequence of digits"
28885
28886@item @var{option} @expansion{}
28887@code{"-" @var{parameter} [ " " @var{parameter} ]}
28888
28889@item @var{parameter} @expansion{}
28890@code{@var{non-blank-sequence} | @var{c-string}}
28891
28892@item @var{operation} @expansion{}
28893@emph{any of the operations described in this chapter}
28894
28895@item @var{non-blank-sequence} @expansion{}
28896@emph{anything, provided it doesn't contain special characters such as
28897"-", @var{nl}, """ and of course " "}
28898
28899@item @var{c-string} @expansion{}
28900@code{""" @var{seven-bit-iso-c-string-content} """}
28901
28902@item @var{nl} @expansion{}
28903@code{CR | CR-LF}
28904@end table
28905
28906@noindent
28907Notes:
28908
28909@itemize @bullet
28910@item
28911The CLI commands are still handled by the @sc{mi} interpreter; their
28912output is described below.
28913
28914@item
28915The @code{@var{token}}, when present, is passed back when the command
28916finishes.
28917
28918@item
28919Some @sc{mi} commands accept optional arguments as part of the parameter
28920list.  Each option is identified by a leading @samp{-} (dash) and may be
28921followed by an optional argument parameter.  Options occur first in the
28922parameter list and can be delimited from normal parameters using
28923@samp{--} (this is useful when some parameters begin with a dash).
28924@end itemize
28925
28926Pragmatics:
28927
28928@itemize @bullet
28929@item
28930We want easy access to the existing CLI syntax (for debugging).
28931
28932@item
28933We want it to be easy to spot a @sc{mi} operation.
28934@end itemize
28935
28936@node GDB/MI Output Syntax
28937@subsection @sc{gdb/mi} Output Syntax
28938
28939@cindex output syntax of @sc{gdb/mi}
28940@cindex @sc{gdb/mi}, output syntax
28941The output from @sc{gdb/mi} consists of zero or more out-of-band records
28942followed, optionally, by a single result record.  This result record
28943is for the most recent command.  The sequence of output records is
28944terminated by @samp{(gdb)}.
28945
28946If an input command was prefixed with a @code{@var{token}} then the
28947corresponding output for that command will also be prefixed by that same
28948@var{token}.
28949
28950@table @code
28951@item @var{output} @expansion{}
28952@code{( @var{out-of-band-record} )* [ @var{result-record} ] "(gdb)" @var{nl}}
28953
28954@item @var{result-record} @expansion{}
28955@code{ [ @var{token} ] "^" @var{result-class} ( "," @var{result} )* @var{nl}}
28956
28957@item @var{out-of-band-record} @expansion{}
28958@code{@var{async-record} | @var{stream-record}}
28959
28960@item @var{async-record} @expansion{}
28961@code{@var{exec-async-output} | @var{status-async-output} | @var{notify-async-output}}
28962
28963@item @var{exec-async-output} @expansion{}
28964@code{[ @var{token} ] "*" @var{async-output nl}}
28965
28966@item @var{status-async-output} @expansion{}
28967@code{[ @var{token} ] "+" @var{async-output nl}}
28968
28969@item @var{notify-async-output} @expansion{}
28970@code{[ @var{token} ] "=" @var{async-output nl}}
28971
28972@item @var{async-output} @expansion{}
28973@code{@var{async-class} ( "," @var{result} )*}
28974
28975@item @var{result-class} @expansion{}
28976@code{"done" | "running" | "connected" | "error" | "exit"}
28977
28978@item @var{async-class} @expansion{}
28979@code{"stopped" | @var{others}} (where @var{others} will be added
28980depending on the needs---this is still in development).
28981
28982@item @var{result} @expansion{}
28983@code{ @var{variable} "=" @var{value}}
28984
28985@item @var{variable} @expansion{}
28986@code{ @var{string} }
28987
28988@item @var{value} @expansion{}
28989@code{ @var{const} | @var{tuple} | @var{list} }
28990
28991@item @var{const} @expansion{}
28992@code{@var{c-string}}
28993
28994@item @var{tuple} @expansion{}
28995@code{ "@{@}" | "@{" @var{result} ( "," @var{result} )* "@}" }
28996
28997@item @var{list} @expansion{}
28998@code{ "[]" | "[" @var{value} ( "," @var{value} )* "]" | "["
28999@var{result} ( "," @var{result} )* "]" }
29000
29001@item @var{stream-record} @expansion{}
29002@code{@var{console-stream-output} | @var{target-stream-output} | @var{log-stream-output}}
29003
29004@item @var{console-stream-output} @expansion{}
29005@code{"~" @var{c-string nl}}
29006
29007@item @var{target-stream-output} @expansion{}
29008@code{"@@" @var{c-string nl}}
29009
29010@item @var{log-stream-output} @expansion{}
29011@code{"&" @var{c-string nl}}
29012
29013@item @var{nl} @expansion{}
29014@code{CR | CR-LF}
29015
29016@item @var{token} @expansion{}
29017@emph{any sequence of digits}.
29018@end table
29019
29020@noindent
29021Notes:
29022
29023@itemize @bullet
29024@item
29025All output sequences end in a single line containing a period.
29026
29027@item
29028The @code{@var{token}} is from the corresponding request.  Note that
29029for all async output, while the token is allowed by the grammar and
29030may be output by future versions of @value{GDBN} for select async
29031output messages, it is generally omitted.  Frontends should treat
29032all async output as reporting general changes in the state of the
29033target and there should be no need to associate async output to any
29034prior command.
29035
29036@item
29037@cindex status output in @sc{gdb/mi}
29038@var{status-async-output} contains on-going status information about the
29039progress of a slow operation.  It can be discarded.  All status output is
29040prefixed by @samp{+}.
29041
29042@item
29043@cindex async output in @sc{gdb/mi}
29044@var{exec-async-output} contains asynchronous state change on the target
29045(stopped, started, disappeared).  All async output is prefixed by
29046@samp{*}.
29047
29048@item
29049@cindex notify output in @sc{gdb/mi}
29050@var{notify-async-output} contains supplementary information that the
29051client should handle (e.g., a new breakpoint information).  All notify
29052output is prefixed by @samp{=}.
29053
29054@item
29055@cindex console output in @sc{gdb/mi}
29056@var{console-stream-output} is output that should be displayed as is in the
29057console.  It is the textual response to a CLI command.  All the console
29058output is prefixed by @samp{~}.
29059
29060@item
29061@cindex target output in @sc{gdb/mi}
29062@var{target-stream-output} is the output produced by the target program.
29063All the target output is prefixed by @samp{@@}.
29064
29065@item
29066@cindex log output in @sc{gdb/mi}
29067@var{log-stream-output} is output text coming from @value{GDBN}'s internals, for
29068instance messages that should be displayed as part of an error log.  All
29069the log output is prefixed by @samp{&}.
29070
29071@item
29072@cindex list output in @sc{gdb/mi}
29073New @sc{gdb/mi} commands should only output @var{lists} containing
29074@var{values}.
29075
29076
29077@end itemize
29078
29079@xref{GDB/MI Stream Records, , @sc{gdb/mi} Stream Records}, for more
29080details about the various output records.
29081
29082@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29083@node GDB/MI Compatibility with CLI
29084@section @sc{gdb/mi} Compatibility with CLI
29085
29086@cindex compatibility, @sc{gdb/mi} and CLI
29087@cindex @sc{gdb/mi}, compatibility with CLI
29088
29089For the developers convenience CLI commands can be entered directly,
29090but there may be some unexpected behaviour.  For example, commands
29091that query the user will behave as if the user replied yes, breakpoint
29092command lists are not executed and some CLI commands, such as
29093@code{if}, @code{when} and @code{define}, prompt for further input with
29094@samp{>}, which is not valid MI output.
29095
29096This feature may be removed at some stage in the future and it is
29097recommended that front ends use the @code{-interpreter-exec} command
29098(@pxref{-interpreter-exec}).
29099
29100@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29101@node GDB/MI Development and Front Ends
29102@section @sc{gdb/mi} Development and Front Ends
29103@cindex @sc{gdb/mi} development
29104
29105The application which takes the MI output and presents the state of the
29106program being debugged to the user is called a @dfn{front end}.
29107
29108Since @sc{gdb/mi} is used by a variety of front ends to @value{GDBN}, changes
29109to the MI interface may break existing usage.  This section describes how the
29110protocol changes and how to request previous version of the protocol when it
29111does.
29112
29113Some changes in MI need not break a carefully designed front end, and
29114for these the MI version will remain unchanged.  The following is a
29115list of changes that may occur within one level, so front ends should
29116parse MI output in a way that can handle them:
29117
29118@itemize @bullet
29119@item
29120New MI commands may be added.
29121
29122@item
29123New fields may be added to the output of any MI command.
29124
29125@item
29126The range of values for fields with specified values, e.g.,
29127@code{in_scope} (@pxref{-var-update}) may be extended.
29128
29129@c The format of field's content e.g type prefix, may change so parse it
29130@c   at your own risk.  Yes, in general?
29131
29132@c The order of fields may change?  Shouldn't really matter but it might
29133@c resolve inconsistencies.
29134@end itemize
29135
29136If the changes are likely to break front ends, the MI version level
29137will be increased by one.  The new versions of the MI protocol are not compatible
29138with the old versions.  Old versions of MI remain available, allowing front ends
29139to keep using them until they are modified to use the latest MI version.
29140
29141Since @code{--interpreter=mi} always points to the latest MI version, it is
29142recommended that front ends request a specific version of MI when launching
29143@value{GDBN} (e.g. @code{--interpreter=mi2}) to make sure they get an
29144interpreter with the MI version they expect.
29145
29146The following table gives a summary of the released versions of the MI
29147interface: the version number, the version of GDB in which it first appeared
29148and the breaking changes compared to the previous version.
29149
29150@multitable @columnfractions .05 .05 .9
29151@headitem MI version @tab GDB version @tab Breaking changes
29152
29153@item
29154@center 1
29155@tab
29156@center 5.1
29157@tab
29158None
29159
29160@item
29161@center 2
29162@tab
29163@center 6.0
29164@tab
29165
29166@itemize
29167@item
29168The @code{-environment-pwd}, @code{-environment-directory} and
29169@code{-environment-path} commands now returns values using the MI output
29170syntax, rather than CLI output syntax.
29171
29172@item
29173@code{-var-list-children}'s @code{children} result field is now a list, rather
29174than a tuple.
29175
29176@item
29177@code{-var-update}'s @code{changelist} result field is now a list, rather than
29178a tuple.
29179@end itemize
29180
29181@item
29182@center 3
29183@tab
29184@center 9.1
29185@tab
29186
29187@itemize
29188@item
29189The output of information about multi-location breakpoints has changed in the
29190responses to the @code{-break-insert} and @code{-break-info} commands, as well
29191as in the @code{=breakpoint-created} and @code{=breakpoint-modified} events.
29192The multiple locations are now placed in a @code{locations} field, whose value
29193is a list.
29194@end itemize
29195
29196@end multitable
29197
29198If your front end cannot yet migrate to a more recent version of the
29199MI protocol, you can nevertheless selectively enable specific features
29200available in those recent MI versions, using the following commands:
29201
29202@table @code
29203
29204@item -fix-multi-location-breakpoint-output
29205Use the output for multi-location breakpoints which was introduced by
29206MI 3, even when using MI versions 2 or 1.  This command has no
29207effect when using MI version 3 or later.
29208
29209@end table
29210
29211The best way to avoid unexpected changes in MI that might break your front
29212end is to make your project known to @value{GDBN} developers and
29213follow development on @email{gdb@@sourceware.org} and
29214@email{gdb-patches@@sourceware.org}.
29215@cindex mailing lists
29216
29217@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29218@node GDB/MI Output Records
29219@section @sc{gdb/mi} Output Records
29220
29221@menu
29222* GDB/MI Result Records::
29223* GDB/MI Stream Records::
29224* GDB/MI Async Records::
29225* GDB/MI Breakpoint Information::
29226* GDB/MI Frame Information::
29227* GDB/MI Thread Information::
29228* GDB/MI Ada Exception Information::
29229@end menu
29230
29231@node GDB/MI Result Records
29232@subsection @sc{gdb/mi} Result Records
29233
29234@cindex result records in @sc{gdb/mi}
29235@cindex @sc{gdb/mi}, result records
29236In addition to a number of out-of-band notifications, the response to a
29237@sc{gdb/mi} command includes one of the following result indications:
29238
29239@table @code
29240@findex ^done
29241@item "^done" [ "," @var{results} ]
29242The synchronous operation was successful, @code{@var{results}} are the return
29243values.
29244
29245@item "^running"
29246@findex ^running
29247This result record is equivalent to @samp{^done}.  Historically, it
29248was output instead of @samp{^done} if the command has resumed the
29249target.  This behaviour is maintained for backward compatibility, but
29250all frontends should treat @samp{^done} and @samp{^running}
29251identically and rely on the @samp{*running} output record to determine
29252which threads are resumed.
29253
29254@item "^connected"
29255@findex ^connected
29256@value{GDBN} has connected to a remote target.
29257
29258@item "^error" "," "msg=" @var{c-string} [ "," "code=" @var{c-string} ]
29259@findex ^error
29260The operation failed.  The @code{msg=@var{c-string}} variable contains
29261the corresponding error message.
29262
29263If present, the @code{code=@var{c-string}} variable provides an error
29264code on which consumers can rely on to detect the corresponding
29265error condition.  At present, only one error code is defined:
29266
29267@table @samp
29268@item "undefined-command"
29269Indicates that the command causing the error does not exist.
29270@end table
29271
29272@item "^exit"
29273@findex ^exit
29274@value{GDBN} has terminated.
29275
29276@end table
29277
29278@node GDB/MI Stream Records
29279@subsection @sc{gdb/mi} Stream Records
29280
29281@cindex @sc{gdb/mi}, stream records
29282@cindex stream records in @sc{gdb/mi}
29283@value{GDBN} internally maintains a number of output streams: the console, the
29284target, and the log.  The output intended for each of these streams is
29285funneled through the @sc{gdb/mi} interface using @dfn{stream records}.
29286
29287Each stream record begins with a unique @dfn{prefix character} which
29288identifies its stream (@pxref{GDB/MI Output Syntax, , @sc{gdb/mi} Output
29289Syntax}).  In addition to the prefix, each stream record contains a
29290@code{@var{string-output}}.  This is either raw text (with an implicit new
29291line) or a quoted C string (which does not contain an implicit newline).
29292
29293@table @code
29294@item "~" @var{string-output}
29295The console output stream contains text that should be displayed in the
29296CLI console window.  It contains the textual responses to CLI commands.
29297
29298@item "@@" @var{string-output}
29299The target output stream contains any textual output from the running
29300target.  This is only present when GDB's event loop is truly
29301asynchronous, which is currently only the case for remote targets.
29302
29303@item "&" @var{string-output}
29304The log stream contains debugging messages being produced by @value{GDBN}'s
29305internals.
29306@end table
29307
29308@node GDB/MI Async Records
29309@subsection @sc{gdb/mi} Async Records
29310
29311@cindex async records in @sc{gdb/mi}
29312@cindex @sc{gdb/mi}, async records
29313@dfn{Async} records are used to notify the @sc{gdb/mi} client of
29314additional changes that have occurred.  Those changes can either be a
29315consequence of @sc{gdb/mi} commands (e.g., a breakpoint modified) or a result of
29316target activity (e.g., target stopped).
29317
29318The following is the list of possible async records:
29319
29320@table @code
29321
29322@item *running,thread-id="@var{thread}"
29323The target is now running.  The @var{thread} field can be the global
29324thread ID of the thread that is now running, and it can be
29325@samp{all} if all threads are running.  The frontend should assume
29326that no interaction with a running thread is possible after this
29327notification is produced.  The frontend should not assume that this
29328notification is output only once for any command.  @value{GDBN} may
29329emit this notification several times, either for different threads,
29330because it cannot resume all threads together, or even for a single
29331thread, if the thread must be stepped though some code before letting
29332it run freely.
29333
29334@item *stopped,reason="@var{reason}",thread-id="@var{id}",stopped-threads="@var{stopped}",core="@var{core}"
29335The target has stopped.  The @var{reason} field can have one of the
29336following values:
29337
29338@table @code
29339@item breakpoint-hit
29340A breakpoint was reached.
29341@item watchpoint-trigger
29342A watchpoint was triggered.
29343@item read-watchpoint-trigger
29344A read watchpoint was triggered.
29345@item access-watchpoint-trigger
29346An access watchpoint was triggered.
29347@item function-finished
29348An -exec-finish or similar CLI command was accomplished.
29349@item location-reached
29350An -exec-until or similar CLI command was accomplished.
29351@item watchpoint-scope
29352A watchpoint has gone out of scope.
29353@item end-stepping-range
29354An -exec-next, -exec-next-instruction, -exec-step, -exec-step-instruction or
29355similar CLI command was accomplished.
29356@item exited-signalled
29357The inferior exited because of a signal.
29358@item exited
29359The inferior exited.
29360@item exited-normally
29361The inferior exited normally.
29362@item signal-received
29363A signal was received by the inferior.
29364@item solib-event
29365The inferior has stopped due to a library being loaded or unloaded.
29366This can happen when @code{stop-on-solib-events} (@pxref{Files}) is
29367set or when a @code{catch load} or @code{catch unload} catchpoint is
29368in use (@pxref{Set Catchpoints}).
29369@item fork
29370The inferior has forked.  This is reported when @code{catch fork}
29371(@pxref{Set Catchpoints}) has been used.
29372@item vfork
29373The inferior has vforked.  This is reported in when @code{catch vfork}
29374(@pxref{Set Catchpoints}) has been used.
29375@item syscall-entry
29376The inferior entered a system call.  This is reported when @code{catch
29377syscall} (@pxref{Set Catchpoints}) has been used.
29378@item syscall-return
29379The inferior returned from a system call.  This is reported when
29380@code{catch syscall} (@pxref{Set Catchpoints}) has been used.
29381@item exec
29382The inferior called @code{exec}.  This is reported when @code{catch exec}
29383(@pxref{Set Catchpoints}) has been used.
29384@end table
29385
29386The @var{id} field identifies the global thread ID of the thread
29387that directly caused the stop -- for example by hitting a breakpoint.
29388Depending on whether all-stop
29389mode is in effect (@pxref{All-Stop Mode}), @value{GDBN} may either
29390stop all threads, or only the thread that directly triggered the stop.
29391If all threads are stopped, the @var{stopped} field will have the
29392value of @code{"all"}.  Otherwise, the value of the @var{stopped}
29393field will be a list of thread identifiers.  Presently, this list will
29394always include a single thread, but frontend should be prepared to see
29395several threads in the list.  The @var{core} field reports the
29396processor core on which the stop event has happened.  This field may be absent
29397if such information is not available.
29398
29399@item =thread-group-added,id="@var{id}"
29400@itemx =thread-group-removed,id="@var{id}"
29401A thread group was either added or removed.  The @var{id} field
29402contains the @value{GDBN} identifier of the thread group.  When a thread
29403group is added, it generally might not be associated with a running
29404process.  When a thread group is removed, its id becomes invalid and
29405cannot be used in any way.
29406
29407@item =thread-group-started,id="@var{id}",pid="@var{pid}"
29408A thread group became associated with a running program,
29409either because the program was just started or the thread group
29410was attached to a program.  The @var{id} field contains the
29411@value{GDBN} identifier of the thread group.  The @var{pid} field
29412contains process identifier, specific to the operating system.
29413
29414@item =thread-group-exited,id="@var{id}"[,exit-code="@var{code}"]
29415A thread group is no longer associated with a running program,
29416either because the program has exited, or because it was detached
29417from.  The @var{id} field contains the @value{GDBN} identifier of the
29418thread group.  The @var{code} field is the exit code of the inferior; it exists
29419only when the inferior exited with some code.
29420
29421@item =thread-created,id="@var{id}",group-id="@var{gid}"
29422@itemx =thread-exited,id="@var{id}",group-id="@var{gid}"
29423A thread either was created, or has exited.  The @var{id} field
29424contains the global @value{GDBN} identifier of the thread.  The @var{gid}
29425field identifies the thread group this thread belongs to.
29426
29427@item =thread-selected,id="@var{id}"[,frame="@var{frame}"]
29428Informs that the selected thread or frame were changed.  This notification
29429is not emitted as result of the @code{-thread-select} or
29430@code{-stack-select-frame} commands, but is emitted whenever an MI command
29431that is not documented to change the selected thread and frame actually
29432changes them.  In particular, invoking, directly or indirectly
29433(via user-defined command), the CLI @code{thread} or @code{frame} commands,
29434will generate this notification.  Changing the thread or frame from another
29435user interface (see @ref{Interpreters}) will also generate this notification.
29436
29437The @var{frame} field is only present if the newly selected thread is
29438stopped.  See @ref{GDB/MI Frame Information} for the format of its value.
29439
29440We suggest that in response to this notification, front ends
29441highlight the selected thread and cause subsequent commands to apply to
29442that thread.
29443
29444@item =library-loaded,...
29445Reports that a new library file was loaded by the program.  This
29446notification has 5 fields---@var{id}, @var{target-name},
29447@var{host-name}, @var{symbols-loaded} and @var{ranges}.  The @var{id} field is an
29448opaque identifier of the library.  For remote debugging case,
29449@var{target-name} and @var{host-name} fields give the name of the
29450library file on the target, and on the host respectively.  For native
29451debugging, both those fields have the same value.  The
29452@var{symbols-loaded} field is emitted only for backward compatibility
29453and should not be relied on to convey any useful information.  The
29454@var{thread-group} field, if present, specifies the id of the thread
29455group in whose context the library was loaded.  If the field is
29456absent, it means the library was loaded in the context of all present
29457thread groups.  The @var{ranges} field specifies the ranges of addresses belonging
29458to this library.
29459
29460@item =library-unloaded,...
29461Reports that a library was unloaded by the program.  This notification
29462has 3 fields---@var{id}, @var{target-name} and @var{host-name} with
29463the same meaning as for the @code{=library-loaded} notification.
29464The @var{thread-group} field, if present, specifies the id of the
29465thread group in whose context the library was unloaded.  If the field is
29466absent, it means the library was unloaded in the context of all present
29467thread groups.
29468
29469@item =traceframe-changed,num=@var{tfnum},tracepoint=@var{tpnum}
29470@itemx =traceframe-changed,end
29471Reports that the trace frame was changed and its new number is
29472@var{tfnum}.  The number of the tracepoint associated with this trace
29473frame is @var{tpnum}.
29474
29475@item =tsv-created,name=@var{name},initial=@var{initial}
29476Reports that the new trace state variable @var{name} is created with
29477initial value @var{initial}.
29478
29479@item =tsv-deleted,name=@var{name}
29480@itemx =tsv-deleted
29481Reports that the trace state variable @var{name} is deleted or all
29482trace state variables are deleted.
29483
29484@item =tsv-modified,name=@var{name},initial=@var{initial}[,current=@var{current}]
29485Reports that the trace state variable @var{name} is modified with
29486the initial value @var{initial}. The current value @var{current} of
29487trace state variable is optional and is reported if the current
29488value of trace state variable is known.
29489
29490@item =breakpoint-created,bkpt=@{...@}
29491@itemx =breakpoint-modified,bkpt=@{...@}
29492@itemx =breakpoint-deleted,id=@var{number}
29493Reports that a breakpoint was created, modified, or deleted,
29494respectively.  Only user-visible breakpoints are reported to the MI
29495user.
29496
29497The @var{bkpt} argument is of the same form as returned by the various
29498breakpoint commands; @xref{GDB/MI Breakpoint Commands}.  The
29499@var{number} is the ordinal number of the breakpoint.
29500
29501Note that if a breakpoint is emitted in the result record of a
29502command, then it will not also be emitted in an async record.
29503
29504@item =record-started,thread-group="@var{id}",method="@var{method}"[,format="@var{format}"]
29505@itemx =record-stopped,thread-group="@var{id}"
29506Execution log recording was either started or stopped on an
29507inferior.  The @var{id} is the @value{GDBN} identifier of the thread
29508group corresponding to the affected inferior.
29509
29510The @var{method} field indicates the method used to record execution.  If the
29511method in use supports multiple recording formats, @var{format} will be present
29512and contain the currently used format.  @xref{Process Record and Replay},
29513for existing method and format values.
29514
29515@item =cmd-param-changed,param=@var{param},value=@var{value}
29516Reports that a parameter of the command @code{set @var{param}} is
29517changed to @var{value}.  In the multi-word @code{set} command,
29518the @var{param} is the whole parameter list to @code{set} command.
29519For example, In command @code{set check type on}, @var{param}
29520is @code{check type} and @var{value} is @code{on}.
29521
29522@item =memory-changed,thread-group=@var{id},addr=@var{addr},len=@var{len}[,type="code"]
29523Reports that bytes from @var{addr} to @var{data} + @var{len} were
29524written in an inferior.  The @var{id} is the identifier of the
29525thread group corresponding to the affected inferior.  The optional
29526@code{type="code"} part is reported if the memory written to holds
29527executable code.
29528@end table
29529
29530@node GDB/MI Breakpoint Information
29531@subsection @sc{gdb/mi} Breakpoint Information
29532
29533When @value{GDBN} reports information about a breakpoint, a
29534tracepoint, a watchpoint, or a catchpoint, it uses a tuple with the
29535following fields:
29536
29537@table @code
29538@item number
29539The breakpoint number.
29540
29541@item type
29542The type of the breakpoint.  For ordinary breakpoints this will be
29543@samp{breakpoint}, but many values are possible.
29544
29545@item catch-type
29546If the type of the breakpoint is @samp{catchpoint}, then this
29547indicates the exact type of catchpoint.
29548
29549@item disp
29550This is the breakpoint disposition---either @samp{del}, meaning that
29551the breakpoint will be deleted at the next stop, or @samp{keep},
29552meaning that the breakpoint will not be deleted.
29553
29554@item enabled
29555This indicates whether the breakpoint is enabled, in which case the
29556value is @samp{y}, or disabled, in which case the value is @samp{n}.
29557Note that this is not the same as the field @code{enable}.
29558
29559@item addr
29560The address of the breakpoint.  This may be a hexidecimal number,
29561giving the address; or the string @samp{<PENDING>}, for a pending
29562breakpoint; or the string @samp{<MULTIPLE>}, for a breakpoint with
29563multiple locations.  This field will not be present if no address can
29564be determined.  For example, a watchpoint does not have an address.
29565
29566@item addr_flags
29567Optional field containing any flags related to the address.  These flags are
29568architecture-dependent; see @ref{Architectures} for their meaning for a
29569particular CPU.
29570
29571@item func
29572If known, the function in which the breakpoint appears.
29573If not known, this field is not present.
29574
29575@item filename
29576The name of the source file which contains this function, if known.
29577If not known, this field is not present.
29578
29579@item fullname
29580The full file name of the source file which contains this function, if
29581known.  If not known, this field is not present.
29582
29583@item line
29584The line number at which this breakpoint appears, if known.
29585If not known, this field is not present.
29586
29587@item at
29588If the source file is not known, this field may be provided.  If
29589provided, this holds the address of the breakpoint, possibly followed
29590by a symbol name.
29591
29592@item pending
29593If this breakpoint is pending, this field is present and holds the
29594text used to set the breakpoint, as entered by the user.
29595
29596@item evaluated-by
29597Where this breakpoint's condition is evaluated, either @samp{host} or
29598@samp{target}.
29599
29600@item thread
29601If this is a thread-specific breakpoint, then this identifies the
29602thread in which the breakpoint can trigger.
29603
29604@item task
29605If this breakpoint is restricted to a particular Ada task, then this
29606field will hold the task identifier.
29607
29608@item cond
29609If the breakpoint is conditional, this is the condition expression.
29610
29611@item ignore
29612The ignore count of the breakpoint.
29613
29614@item enable
29615The enable count of the breakpoint.
29616
29617@item traceframe-usage
29618FIXME.
29619
29620@item static-tracepoint-marker-string-id
29621For a static tracepoint, the name of the static tracepoint marker.
29622
29623@item mask
29624For a masked watchpoint, this is the mask.
29625
29626@item pass
29627A tracepoint's pass count.
29628
29629@item original-location
29630The location of the breakpoint as originally specified by the user.
29631This field is optional.
29632
29633@item times
29634The number of times the breakpoint has been hit.
29635
29636@item installed
29637This field is only given for tracepoints.  This is either @samp{y},
29638meaning that the tracepoint is installed, or @samp{n}, meaning that it
29639is not.
29640
29641@item what
29642Some extra data, the exact contents of which are type-dependent.
29643
29644@item locations
29645This field is present if the breakpoint has multiple locations.  It is also
29646exceptionally present if the breakpoint is enabled and has a single, disabled
29647location.
29648
29649The value is a list of locations.  The format of a location is described below.
29650
29651@end table
29652
29653A location in a multi-location breakpoint is represented as a tuple with the
29654following fields:
29655
29656@table @code
29657
29658@item number
29659The location number as a dotted pair, like @samp{1.2}.  The first digit is the
29660number of the parent breakpoint.  The second digit is the number of the
29661location within that breakpoint.
29662
29663@item enabled
29664This indicates whether the location is enabled, in which case the
29665value is @samp{y}, or disabled, in which case the value is @samp{n}.
29666Note that this is not the same as the field @code{enable}.
29667
29668@item addr
29669The address of this location as an hexidecimal number.
29670
29671@item addr_flags
29672Optional field containing any flags related to the address.  These flags are
29673architecture-dependent; see @ref{Architectures} for their meaning for a
29674particular CPU.
29675
29676@item func
29677If known, the function in which the location appears.
29678If not known, this field is not present.
29679
29680@item file
29681The name of the source file which contains this location, if known.
29682If not known, this field is not present.
29683
29684@item fullname
29685The full file name of the source file which contains this location, if
29686known.  If not known, this field is not present.
29687
29688@item line
29689The line number at which this location appears, if known.
29690If not known, this field is not present.
29691
29692@item thread-groups
29693The thread groups this location is in.
29694
29695@end table
29696
29697For example, here is what the output of @code{-break-insert}
29698(@pxref{GDB/MI Breakpoint Commands}) might be:
29699
29700@smallexample
29701-> -break-insert main
29702<- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
29703    enabled="y",addr="0x08048564",func="main",file="myprog.c",
29704    fullname="/home/nickrob/myprog.c",line="68",thread-groups=["i1"],
29705    times="0"@}
29706<- (gdb)
29707@end smallexample
29708
29709@node GDB/MI Frame Information
29710@subsection @sc{gdb/mi} Frame Information
29711
29712Response from many MI commands includes an information about stack
29713frame.  This information is a tuple that may have the following
29714fields:
29715
29716@table @code
29717@item level
29718The level of the stack frame.  The innermost frame has the level of
29719zero.  This field is always present.
29720
29721@item func
29722The name of the function corresponding to the frame.  This field may
29723be absent if @value{GDBN} is unable to determine the function name.
29724
29725@item addr
29726The code address for the frame.  This field is always present.
29727
29728@item addr_flags
29729Optional field containing any flags related to the address.  These flags are
29730architecture-dependent; see @ref{Architectures} for their meaning for a
29731particular CPU.
29732
29733@item file
29734The name of the source files that correspond to the frame's code
29735address.  This field may be absent.
29736
29737@item line
29738The source line corresponding to the frames' code address.  This field
29739may be absent.
29740
29741@item from
29742The name of the binary file (either executable or shared library) the
29743corresponds to the frame's code address.  This field may be absent.
29744
29745@end table
29746
29747@node GDB/MI Thread Information
29748@subsection @sc{gdb/mi} Thread Information
29749
29750Whenever @value{GDBN} has to report an information about a thread, it
29751uses a tuple with the following fields.  The fields are always present unless
29752stated otherwise.
29753
29754@table @code
29755@item id
29756The global numeric id assigned to the thread by @value{GDBN}.
29757
29758@item target-id
29759The target-specific string identifying the thread.
29760
29761@item details
29762Additional information about the thread provided by the target.
29763It is supposed to be human-readable and not interpreted by the
29764frontend.  This field is optional.
29765
29766@item name
29767The name of the thread.  If the user specified a name using the
29768@code{thread name} command, then this name is given.  Otherwise, if
29769@value{GDBN} can extract the thread name from the target, then that
29770name is given.  If @value{GDBN} cannot find the thread name, then this
29771field is omitted.
29772
29773@item state
29774The execution state of the thread, either @samp{stopped} or @samp{running},
29775depending on whether the thread is presently running.
29776
29777@item frame
29778The stack frame currently executing in the thread.  This field is only present
29779if the thread is stopped.  Its format is documented in
29780@ref{GDB/MI Frame Information}.
29781
29782@item core
29783The value of this field is an integer number of the processor core the
29784thread was last seen on.  This field is optional.
29785@end table
29786
29787@node GDB/MI Ada Exception Information
29788@subsection @sc{gdb/mi} Ada Exception Information
29789
29790Whenever a @code{*stopped} record is emitted because the program
29791stopped after hitting an exception catchpoint (@pxref{Set Catchpoints}),
29792@value{GDBN} provides the name of the exception that was raised via
29793the @code{exception-name} field.  Also, for exceptions that were raised
29794with an exception message, @value{GDBN} provides that message via
29795the @code{exception-message} field.
29796
29797@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29798@node GDB/MI Simple Examples
29799@section Simple Examples of @sc{gdb/mi} Interaction
29800@cindex @sc{gdb/mi}, simple examples
29801
29802This subsection presents several simple examples of interaction using
29803the @sc{gdb/mi} interface.  In these examples, @samp{->} means that the
29804following line is passed to @sc{gdb/mi} as input, while @samp{<-} means
29805the output received from @sc{gdb/mi}.
29806
29807Note the line breaks shown in the examples are here only for
29808readability, they don't appear in the real output.
29809
29810@subheading Setting a Breakpoint
29811
29812Setting a breakpoint generates synchronous output which contains detailed
29813information of the breakpoint.
29814
29815@smallexample
29816-> -break-insert main
29817<- ^done,bkpt=@{number="1",type="breakpoint",disp="keep",
29818    enabled="y",addr="0x08048564",func="main",file="myprog.c",
29819    fullname="/home/nickrob/myprog.c",line="68",thread-groups=["i1"],
29820    times="0"@}
29821<- (gdb)
29822@end smallexample
29823
29824@subheading Program Execution
29825
29826Program execution generates asynchronous records and MI gives the
29827reason that execution stopped.
29828
29829@smallexample
29830-> -exec-run
29831<- ^running
29832<- (gdb)
29833<- *stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
29834   frame=@{addr="0x08048564",func="main",
29835   args=[@{name="argc",value="1"@},@{name="argv",value="0xbfc4d4d4"@}],
29836   file="myprog.c",fullname="/home/nickrob/myprog.c",line="68",
29837   arch="i386:x86_64"@}
29838<- (gdb)
29839-> -exec-continue
29840<- ^running
29841<- (gdb)
29842<- *stopped,reason="exited-normally"
29843<- (gdb)
29844@end smallexample
29845
29846@subheading Quitting @value{GDBN}
29847
29848Quitting @value{GDBN} just prints the result class @samp{^exit}.
29849
29850@smallexample
29851-> (gdb)
29852<- -gdb-exit
29853<- ^exit
29854@end smallexample
29855
29856Please note that @samp{^exit} is printed immediately, but it might
29857take some time for @value{GDBN} to actually exit.  During that time, @value{GDBN}
29858performs necessary cleanups, including killing programs being debugged
29859or disconnecting from debug hardware, so the frontend should wait till
29860@value{GDBN} exits and should only forcibly kill @value{GDBN} if it
29861fails to exit in reasonable time.
29862
29863@subheading A Bad Command
29864
29865Here's what happens if you pass a non-existent command:
29866
29867@smallexample
29868-> -rubbish
29869<- ^error,msg="Undefined MI command: rubbish"
29870<- (gdb)
29871@end smallexample
29872
29873
29874@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29875@node GDB/MI Command Description Format
29876@section @sc{gdb/mi} Command Description Format
29877
29878The remaining sections describe blocks of commands.  Each block of
29879commands is laid out in a fashion similar to this section.
29880
29881@subheading Motivation
29882
29883The motivation for this collection of commands.
29884
29885@subheading Introduction
29886
29887A brief introduction to this collection of commands as a whole.
29888
29889@subheading Commands
29890
29891For each command in the block, the following is described:
29892
29893@subsubheading Synopsis
29894
29895@smallexample
29896 -command @var{args}@dots{}
29897@end smallexample
29898
29899@subsubheading Result
29900
29901@subsubheading @value{GDBN} Command
29902
29903The corresponding @value{GDBN} CLI command(s), if any.
29904
29905@subsubheading Example
29906
29907Example(s) formatted for readability.  Some of the described commands  have
29908not been implemented yet and these are labeled N.A.@: (not available).
29909
29910
29911@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29912@node GDB/MI Breakpoint Commands
29913@section @sc{gdb/mi} Breakpoint Commands
29914
29915@cindex breakpoint commands for @sc{gdb/mi}
29916@cindex @sc{gdb/mi}, breakpoint commands
29917This section documents @sc{gdb/mi} commands for manipulating
29918breakpoints.
29919
29920@subheading The @code{-break-after} Command
29921@findex -break-after
29922
29923@subsubheading Synopsis
29924
29925@smallexample
29926 -break-after @var{number} @var{count}
29927@end smallexample
29928
29929The breakpoint number @var{number} is not in effect until it has been
29930hit @var{count} times.  To see how this is reflected in the output of
29931the @samp{-break-list} command, see the description of the
29932@samp{-break-list} command below.
29933
29934@subsubheading @value{GDBN} Command
29935
29936The corresponding @value{GDBN} command is @samp{ignore}.
29937
29938@subsubheading Example
29939
29940@smallexample
29941(gdb)
29942-break-insert main
29943^done,bkpt=@{number="1",type="breakpoint",disp="keep",
29944enabled="y",addr="0x000100d0",func="main",file="hello.c",
29945fullname="/home/foo/hello.c",line="5",thread-groups=["i1"],
29946times="0"@}
29947(gdb)
29948-break-after 1 3
29949~
29950^done
29951(gdb)
29952-break-list
29953^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
29954hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
29955@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
29956@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
29957@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
29958@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
29959@{width="40",alignment="2",col_name="what",colhdr="What"@}],
29960body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
29961addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
29962line="5",thread-groups=["i1"],times="0",ignore="3"@}]@}
29963(gdb)
29964@end smallexample
29965
29966@ignore
29967@subheading The @code{-break-catch} Command
29968@findex -break-catch
29969@end ignore
29970
29971@subheading The @code{-break-commands} Command
29972@findex -break-commands
29973
29974@subsubheading Synopsis
29975
29976@smallexample
29977 -break-commands @var{number} [ @var{command1} ... @var{commandN} ]
29978@end smallexample
29979
29980Specifies the CLI commands that should be executed when breakpoint
29981@var{number} is hit.  The parameters @var{command1} to @var{commandN}
29982are the commands.  If no command is specified, any previously-set
29983commands are cleared.  @xref{Break Commands}.  Typical use of this
29984functionality is tracing a program, that is, printing of values of
29985some variables whenever breakpoint is hit and then continuing.
29986
29987@subsubheading @value{GDBN} Command
29988
29989The corresponding @value{GDBN} command is @samp{commands}.
29990
29991@subsubheading Example
29992
29993@smallexample
29994(gdb)
29995-break-insert main
29996^done,bkpt=@{number="1",type="breakpoint",disp="keep",
29997enabled="y",addr="0x000100d0",func="main",file="hello.c",
29998fullname="/home/foo/hello.c",line="5",thread-groups=["i1"],
29999times="0"@}
30000(gdb)
30001-break-commands 1 "print v" "continue"
30002^done
30003(gdb)
30004@end smallexample
30005
30006@subheading The @code{-break-condition} Command
30007@findex -break-condition
30008
30009@subsubheading Synopsis
30010
30011@smallexample
30012 -break-condition @var{number} @var{expr}
30013@end smallexample
30014
30015Breakpoint @var{number} will stop the program only if the condition in
30016@var{expr} is true.  The condition becomes part of the
30017@samp{-break-list} output (see the description of the @samp{-break-list}
30018command below).
30019
30020@subsubheading @value{GDBN} Command
30021
30022The corresponding @value{GDBN} command is @samp{condition}.
30023
30024@subsubheading Example
30025
30026@smallexample
30027(gdb)
30028-break-condition 1 1
30029^done
30030(gdb)
30031-break-list
30032^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
30033hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30034@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30035@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30036@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30037@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30038@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30039body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30040addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
30041line="5",cond="1",thread-groups=["i1"],times="0",ignore="3"@}]@}
30042(gdb)
30043@end smallexample
30044
30045@subheading The @code{-break-delete} Command
30046@findex -break-delete
30047
30048@subsubheading Synopsis
30049
30050@smallexample
30051 -break-delete ( @var{breakpoint} )+
30052@end smallexample
30053
30054Delete the breakpoint(s) whose number(s) are specified in the argument
30055list.  This is obviously reflected in the breakpoint list.
30056
30057@subsubheading @value{GDBN} Command
30058
30059The corresponding @value{GDBN} command is @samp{delete}.
30060
30061@subsubheading Example
30062
30063@smallexample
30064(gdb)
30065-break-delete 1
30066^done
30067(gdb)
30068-break-list
30069^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
30070hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30071@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30072@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30073@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30074@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30075@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30076body=[]@}
30077(gdb)
30078@end smallexample
30079
30080@subheading The @code{-break-disable} Command
30081@findex -break-disable
30082
30083@subsubheading Synopsis
30084
30085@smallexample
30086 -break-disable ( @var{breakpoint} )+
30087@end smallexample
30088
30089Disable the named @var{breakpoint}(s).  The field @samp{enabled} in the
30090break list is now set to @samp{n} for the named @var{breakpoint}(s).
30091
30092@subsubheading @value{GDBN} Command
30093
30094The corresponding @value{GDBN} command is @samp{disable}.
30095
30096@subsubheading Example
30097
30098@smallexample
30099(gdb)
30100-break-disable 2
30101^done
30102(gdb)
30103-break-list
30104^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
30105hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30106@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30107@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30108@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30109@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30110@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30111body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="n",
30112addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
30113line="5",thread-groups=["i1"],times="0"@}]@}
30114(gdb)
30115@end smallexample
30116
30117@subheading The @code{-break-enable} Command
30118@findex -break-enable
30119
30120@subsubheading Synopsis
30121
30122@smallexample
30123 -break-enable ( @var{breakpoint} )+
30124@end smallexample
30125
30126Enable (previously disabled) @var{breakpoint}(s).
30127
30128@subsubheading @value{GDBN} Command
30129
30130The corresponding @value{GDBN} command is @samp{enable}.
30131
30132@subsubheading Example
30133
30134@smallexample
30135(gdb)
30136-break-enable 2
30137^done
30138(gdb)
30139-break-list
30140^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
30141hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30142@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30143@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30144@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30145@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30146@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30147body=[bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
30148addr="0x000100d0",func="main",file="hello.c",fullname="/home/foo/hello.c",
30149line="5",thread-groups=["i1"],times="0"@}]@}
30150(gdb)
30151@end smallexample
30152
30153@subheading The @code{-break-info} Command
30154@findex -break-info
30155
30156@subsubheading Synopsis
30157
30158@smallexample
30159 -break-info @var{breakpoint}
30160@end smallexample
30161
30162@c REDUNDANT???
30163Get information about a single breakpoint.
30164
30165The result is a table of breakpoints.  @xref{GDB/MI Breakpoint
30166Information}, for details on the format of each breakpoint in the
30167table.
30168
30169@subsubheading @value{GDBN} Command
30170
30171The corresponding @value{GDBN} command is @samp{info break @var{breakpoint}}.
30172
30173@subsubheading Example
30174N.A.
30175
30176@subheading The @code{-break-insert} Command
30177@findex -break-insert
30178@anchor{-break-insert}
30179
30180@subsubheading Synopsis
30181
30182@smallexample
30183 -break-insert [ -t ] [ -h ] [ -f ] [ -d ] [ -a ] [ --qualified ]
30184    [ -c @var{condition} ] [ -i @var{ignore-count} ]
30185    [ -p @var{thread-id} ] [ @var{location} ]
30186@end smallexample
30187
30188@noindent
30189If specified, @var{location}, can be one of:
30190
30191@table @var
30192@item linespec location
30193A linespec location.  @xref{Linespec Locations}.
30194
30195@item explicit location
30196An explicit location.  @sc{gdb/mi} explicit locations are
30197analogous to the CLI's explicit locations using the option names
30198listed below.  @xref{Explicit Locations}.
30199
30200@table @samp
30201@item --source @var{filename}
30202The source file name of the location.  This option requires the use
30203of either @samp{--function} or @samp{--line}.
30204
30205@item --function @var{function}
30206The name of a function or method.
30207
30208@item --label @var{label}
30209The name of a label.
30210
30211@item --line @var{lineoffset}
30212An absolute or relative line offset from the start of the location.
30213@end table
30214
30215@item address location
30216An address location, *@var{address}.  @xref{Address Locations}.
30217@end table
30218
30219@noindent
30220The possible optional parameters of this command are:
30221
30222@table @samp
30223@item -t
30224Insert a temporary breakpoint.
30225@item -h
30226Insert a hardware breakpoint.
30227@item -f
30228If @var{location} cannot be parsed (for example if it
30229refers to unknown files or functions), create a pending
30230breakpoint. Without this flag, @value{GDBN} will report
30231an error, and won't create a breakpoint, if @var{location}
30232cannot be parsed.
30233@item -d
30234Create a disabled breakpoint.
30235@item -a
30236Create a tracepoint.  @xref{Tracepoints}.  When this parameter
30237is used together with @samp{-h}, a fast tracepoint is created.
30238@item -c @var{condition}
30239Make the breakpoint conditional on @var{condition}.
30240@item -i @var{ignore-count}
30241Initialize the @var{ignore-count}.
30242@item -p @var{thread-id}
30243Restrict the breakpoint to the thread with the specified global
30244@var{thread-id}.
30245@item --qualified
30246This option makes @value{GDBN} interpret a function name specified as
30247a complete fully-qualified name.
30248@end table
30249
30250@subsubheading Result
30251
30252@xref{GDB/MI Breakpoint Information}, for details on the format of the
30253resulting breakpoint.
30254
30255Note: this format is open to change.
30256@c An out-of-band breakpoint instead of part of the result?
30257
30258@subsubheading @value{GDBN} Command
30259
30260The corresponding @value{GDBN} commands are @samp{break}, @samp{tbreak},
30261@samp{hbreak}, and @samp{thbreak}. @c and @samp{rbreak}.
30262
30263@subsubheading Example
30264
30265@smallexample
30266(gdb)
30267-break-insert main
30268^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",
30269fullname="/home/foo/recursive2.c,line="4",thread-groups=["i1"],
30270times="0"@}
30271(gdb)
30272-break-insert -t foo
30273^done,bkpt=@{number="2",addr="0x00010774",file="recursive2.c",
30274fullname="/home/foo/recursive2.c,line="11",thread-groups=["i1"],
30275times="0"@}
30276(gdb)
30277-break-list
30278^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30279hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30280@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30281@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30282@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30283@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30284@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30285body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30286addr="0x0001072c", func="main",file="recursive2.c",
30287fullname="/home/foo/recursive2.c,"line="4",thread-groups=["i1"],
30288times="0"@},
30289bkpt=@{number="2",type="breakpoint",disp="del",enabled="y",
30290addr="0x00010774",func="foo",file="recursive2.c",
30291fullname="/home/foo/recursive2.c",line="11",thread-groups=["i1"],
30292times="0"@}]@}
30293(gdb)
30294@c -break-insert -r foo.*
30295@c ~int foo(int, int);
30296@c ^done,bkpt=@{number="3",addr="0x00010774",file="recursive2.c,
30297@c "fullname="/home/foo/recursive2.c",line="11",thread-groups=["i1"],
30298@c times="0"@}
30299@c (gdb)
30300@end smallexample
30301
30302@subheading The @code{-dprintf-insert} Command
30303@findex -dprintf-insert
30304
30305@subsubheading Synopsis
30306
30307@smallexample
30308 -dprintf-insert [ -t ] [ -f ] [ -d ] [ --qualified ]
30309    [ -c @var{condition} ] [ -i @var{ignore-count} ]
30310    [ -p @var{thread-id} ] [ @var{location} ] [ @var{format} ]
30311    [ @var{argument} ]
30312@end smallexample
30313
30314@noindent
30315If supplied, @var{location} and @code{--qualified} may be specified
30316the same way as for the @code{-break-insert} command.
30317@xref{-break-insert}.
30318
30319The possible optional parameters of this command are:
30320
30321@table @samp
30322@item -t
30323Insert a temporary breakpoint.
30324@item -f
30325If @var{location} cannot be parsed (for example, if it
30326refers to unknown files or functions), create a pending
30327breakpoint.  Without this flag, @value{GDBN} will report
30328an error, and won't create a breakpoint, if @var{location}
30329cannot be parsed.
30330@item -d
30331Create a disabled breakpoint.
30332@item -c @var{condition}
30333Make the breakpoint conditional on @var{condition}.
30334@item -i @var{ignore-count}
30335Set the ignore count of the breakpoint (@pxref{Conditions, ignore count})
30336to @var{ignore-count}.
30337@item -p @var{thread-id}
30338Restrict the breakpoint to the thread with the specified global
30339@var{thread-id}.
30340@end table
30341
30342@subsubheading Result
30343
30344@xref{GDB/MI Breakpoint Information}, for details on the format of the
30345resulting breakpoint.
30346
30347@c An out-of-band breakpoint instead of part of the result?
30348
30349@subsubheading @value{GDBN} Command
30350
30351The corresponding @value{GDBN} command is @samp{dprintf}.
30352
30353@subsubheading Example
30354
30355@smallexample
30356(gdb)
303574-dprintf-insert foo "At foo entry\n"
303584^done,bkpt=@{number="1",type="dprintf",disp="keep",enabled="y",
30359addr="0x000000000040061b",func="foo",file="mi-dprintf.c",
30360fullname="mi-dprintf.c",line="25",thread-groups=["i1"],
30361times="0",script=@{"printf \"At foo entry\\n\"","continue"@},
30362original-location="foo"@}
30363(gdb)
303645-dprintf-insert 26 "arg=%d, g=%d\n" arg g
303655^done,bkpt=@{number="2",type="dprintf",disp="keep",enabled="y",
30366addr="0x000000000040062a",func="foo",file="mi-dprintf.c",
30367fullname="mi-dprintf.c",line="26",thread-groups=["i1"],
30368times="0",script=@{"printf \"arg=%d, g=%d\\n\", arg, g","continue"@},
30369original-location="mi-dprintf.c:26"@}
30370(gdb)
30371@end smallexample
30372
30373@subheading The @code{-break-list} Command
30374@findex -break-list
30375
30376@subsubheading Synopsis
30377
30378@smallexample
30379 -break-list
30380@end smallexample
30381
30382Displays the list of inserted breakpoints, showing the following fields:
30383
30384@table @samp
30385@item Number
30386number of the breakpoint
30387@item Type
30388type of the breakpoint: @samp{breakpoint} or @samp{watchpoint}
30389@item Disposition
30390should the breakpoint be deleted or disabled when it is hit: @samp{keep}
30391or @samp{nokeep}
30392@item Enabled
30393is the breakpoint enabled or no: @samp{y} or @samp{n}
30394@item Address
30395memory location at which the breakpoint is set
30396@item What
30397logical location of the breakpoint, expressed by function name, file
30398name, line number
30399@item Thread-groups
30400list of thread groups to which this breakpoint applies
30401@item Times
30402number of times the breakpoint has been hit
30403@end table
30404
30405If there are no breakpoints or watchpoints, the @code{BreakpointTable}
30406@code{body} field is an empty list.
30407
30408@subsubheading @value{GDBN} Command
30409
30410The corresponding @value{GDBN} command is @samp{info break}.
30411
30412@subsubheading Example
30413
30414@smallexample
30415(gdb)
30416-break-list
30417^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30418hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30419@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30420@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30421@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30422@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30423@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30424body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30425addr="0x000100d0",func="main",file="hello.c",line="5",thread-groups=["i1"],
30426times="0"@},
30427bkpt=@{number="2",type="breakpoint",disp="keep",enabled="y",
30428addr="0x00010114",func="foo",file="hello.c",fullname="/home/foo/hello.c",
30429line="13",thread-groups=["i1"],times="0"@}]@}
30430(gdb)
30431@end smallexample
30432
30433Here's an example of the result when there are no breakpoints:
30434
30435@smallexample
30436(gdb)
30437-break-list
30438^done,BreakpointTable=@{nr_rows="0",nr_cols="6",
30439hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30440@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30441@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30442@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30443@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30444@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30445body=[]@}
30446(gdb)
30447@end smallexample
30448
30449@subheading The @code{-break-passcount} Command
30450@findex -break-passcount
30451
30452@subsubheading Synopsis
30453
30454@smallexample
30455 -break-passcount @var{tracepoint-number} @var{passcount}
30456@end smallexample
30457
30458Set the passcount for tracepoint @var{tracepoint-number} to
30459@var{passcount}.  If the breakpoint referred to by @var{tracepoint-number}
30460is not a tracepoint, error is emitted.  This corresponds to CLI
30461command @samp{passcount}.
30462
30463@subheading The @code{-break-watch} Command
30464@findex -break-watch
30465
30466@subsubheading Synopsis
30467
30468@smallexample
30469 -break-watch [ -a | -r ]
30470@end smallexample
30471
30472Create a watchpoint.  With the @samp{-a} option it will create an
30473@dfn{access} watchpoint, i.e., a watchpoint that triggers either on a
30474read from or on a write to the memory location.  With the @samp{-r}
30475option, the watchpoint created is a @dfn{read} watchpoint, i.e., it will
30476trigger only when the memory location is accessed for reading.  Without
30477either of the options, the watchpoint created is a regular watchpoint,
30478i.e., it will trigger when the memory location is accessed for writing.
30479@xref{Set Watchpoints, , Setting Watchpoints}.
30480
30481Note that @samp{-break-list} will report a single list of watchpoints and
30482breakpoints inserted.
30483
30484@subsubheading @value{GDBN} Command
30485
30486The corresponding @value{GDBN} commands are @samp{watch}, @samp{awatch}, and
30487@samp{rwatch}.
30488
30489@subsubheading Example
30490
30491Setting a watchpoint on a variable in the @code{main} function:
30492
30493@smallexample
30494(gdb)
30495-break-watch x
30496^done,wpt=@{number="2",exp="x"@}
30497(gdb)
30498-exec-continue
30499^running
30500(gdb)
30501*stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="x"@},
30502value=@{old="-268439212",new="55"@},
30503frame=@{func="main",args=[],file="recursive2.c",
30504fullname="/home/foo/bar/recursive2.c",line="5",arch="i386:x86_64"@}
30505(gdb)
30506@end smallexample
30507
30508Setting a watchpoint on a variable local to a function.  @value{GDBN} will stop
30509the program execution twice: first for the variable changing value, then
30510for the watchpoint going out of scope.
30511
30512@smallexample
30513(gdb)
30514-break-watch C
30515^done,wpt=@{number="5",exp="C"@}
30516(gdb)
30517-exec-continue
30518^running
30519(gdb)
30520*stopped,reason="watchpoint-trigger",
30521wpt=@{number="5",exp="C"@},value=@{old="-276895068",new="3"@},
30522frame=@{func="callee4",args=[],
30523file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30524fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13",
30525arch="i386:x86_64"@}
30526(gdb)
30527-exec-continue
30528^running
30529(gdb)
30530*stopped,reason="watchpoint-scope",wpnum="5",
30531frame=@{func="callee3",args=[@{name="strarg",
30532value="0x11940 \"A string argument.\""@}],
30533file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30534fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
30535arch="i386:x86_64"@}
30536(gdb)
30537@end smallexample
30538
30539Listing breakpoints and watchpoints, at different points in the program
30540execution.  Note that once the watchpoint goes out of scope, it is
30541deleted.
30542
30543@smallexample
30544(gdb)
30545-break-watch C
30546^done,wpt=@{number="2",exp="C"@}
30547(gdb)
30548-break-list
30549^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30550hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30551@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30552@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30553@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30554@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30555@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30556body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30557addr="0x00010734",func="callee4",
30558file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30559fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c"line="8",thread-groups=["i1"],
30560times="1"@},
30561bkpt=@{number="2",type="watchpoint",disp="keep",
30562enabled="y",addr="",what="C",thread-groups=["i1"],times="0"@}]@}
30563(gdb)
30564-exec-continue
30565^running
30566(gdb)
30567*stopped,reason="watchpoint-trigger",wpt=@{number="2",exp="C"@},
30568value=@{old="-276895068",new="3"@},
30569frame=@{func="callee4",args=[],
30570file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30571fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="13",
30572arch="i386:x86_64"@}
30573(gdb)
30574-break-list
30575^done,BreakpointTable=@{nr_rows="2",nr_cols="6",
30576hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30577@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30578@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30579@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30580@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30581@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30582body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30583addr="0x00010734",func="callee4",
30584file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30585fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",thread-groups=["i1"],
30586times="1"@},
30587bkpt=@{number="2",type="watchpoint",disp="keep",
30588enabled="y",addr="",what="C",thread-groups=["i1"],times="-5"@}]@}
30589(gdb)
30590-exec-continue
30591^running
30592^done,reason="watchpoint-scope",wpnum="2",
30593frame=@{func="callee3",args=[@{name="strarg",
30594value="0x11940 \"A string argument.\""@}],
30595file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30596fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
30597arch="i386:x86_64"@}
30598(gdb)
30599-break-list
30600^done,BreakpointTable=@{nr_rows="1",nr_cols="6",
30601hdr=[@{width="3",alignment="-1",col_name="number",colhdr="Num"@},
30602@{width="14",alignment="-1",col_name="type",colhdr="Type"@},
30603@{width="4",alignment="-1",col_name="disp",colhdr="Disp"@},
30604@{width="3",alignment="-1",col_name="enabled",colhdr="Enb"@},
30605@{width="10",alignment="-1",col_name="addr",colhdr="Address"@},
30606@{width="40",alignment="2",col_name="what",colhdr="What"@}],
30607body=[bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
30608addr="0x00010734",func="callee4",
30609file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
30610fullname="/home/foo/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
30611thread-groups=["i1"],times="1"@}]@}
30612(gdb)
30613@end smallexample
30614
30615
30616@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30617@node GDB/MI Catchpoint Commands
30618@section @sc{gdb/mi} Catchpoint Commands
30619
30620This section documents @sc{gdb/mi} commands for manipulating
30621catchpoints.
30622
30623@menu
30624* Shared Library GDB/MI Catchpoint Commands::
30625* Ada Exception GDB/MI Catchpoint Commands::
30626* C++ Exception GDB/MI Catchpoint Commands::
30627@end menu
30628
30629@node Shared Library GDB/MI Catchpoint Commands
30630@subsection Shared Library @sc{gdb/mi} Catchpoints
30631
30632@subheading The @code{-catch-load} Command
30633@findex -catch-load
30634
30635@subsubheading Synopsis
30636
30637@smallexample
30638 -catch-load [ -t ] [ -d ] @var{regexp}
30639@end smallexample
30640
30641Add a catchpoint for library load events.  If the @samp{-t} option is used,
30642the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
30643Breakpoints}).  If the @samp{-d} option is used, the catchpoint is created
30644in a disabled state.  The @samp{regexp} argument is a regular
30645expression used to match the name of the loaded library.
30646
30647
30648@subsubheading @value{GDBN} Command
30649
30650The corresponding @value{GDBN} command is @samp{catch load}.
30651
30652@subsubheading Example
30653
30654@smallexample
30655-catch-load -t foo.so
30656^done,bkpt=@{number="1",type="catchpoint",disp="del",enabled="y",
30657what="load of library matching foo.so",catch-type="load",times="0"@}
30658(gdb)
30659@end smallexample
30660
30661
30662@subheading The @code{-catch-unload} Command
30663@findex -catch-unload
30664
30665@subsubheading Synopsis
30666
30667@smallexample
30668 -catch-unload [ -t ] [ -d ] @var{regexp}
30669@end smallexample
30670
30671Add a catchpoint for library unload events.  If the @samp{-t} option is
30672used, the catchpoint is a temporary one (@pxref{Set Breaks, ,Setting
30673Breakpoints}).  If the @samp{-d} option is used, the catchpoint is
30674created in a disabled state.  The @samp{regexp} argument is a regular
30675expression used to match the name of the unloaded library.
30676
30677@subsubheading @value{GDBN} Command
30678
30679The corresponding @value{GDBN} command is @samp{catch unload}.
30680
30681@subsubheading Example
30682
30683@smallexample
30684-catch-unload -d bar.so
30685^done,bkpt=@{number="2",type="catchpoint",disp="keep",enabled="n",
30686what="load of library matching bar.so",catch-type="unload",times="0"@}
30687(gdb)
30688@end smallexample
30689
30690@node Ada Exception GDB/MI Catchpoint Commands
30691@subsection Ada Exception @sc{gdb/mi} Catchpoints
30692
30693The following @sc{gdb/mi} commands can be used to create catchpoints
30694that stop the execution when Ada exceptions are being raised.
30695
30696@subheading The @code{-catch-assert} Command
30697@findex -catch-assert
30698
30699@subsubheading Synopsis
30700
30701@smallexample
30702 -catch-assert [ -c @var{condition}] [ -d ] [ -t ]
30703@end smallexample
30704
30705Add a catchpoint for failed Ada assertions.
30706
30707The possible optional parameters for this command are:
30708
30709@table @samp
30710@item -c @var{condition}
30711Make the catchpoint conditional on @var{condition}.
30712@item -d
30713Create a disabled catchpoint.
30714@item -t
30715Create a temporary catchpoint.
30716@end table
30717
30718@subsubheading @value{GDBN} Command
30719
30720The corresponding @value{GDBN} command is @samp{catch assert}.
30721
30722@subsubheading Example
30723
30724@smallexample
30725-catch-assert
30726^done,bkptno="5",bkpt=@{number="5",type="breakpoint",disp="keep",
30727enabled="y",addr="0x0000000000404888",what="failed Ada assertions",
30728thread-groups=["i1"],times="0",
30729original-location="__gnat_debug_raise_assert_failure"@}
30730(gdb)
30731@end smallexample
30732
30733@subheading The @code{-catch-exception} Command
30734@findex -catch-exception
30735
30736@subsubheading Synopsis
30737
30738@smallexample
30739 -catch-exception [ -c @var{condition}] [ -d ] [ -e @var{exception-name} ]
30740    [ -t ] [ -u ]
30741@end smallexample
30742
30743Add a catchpoint stopping when Ada exceptions are raised.
30744By default, the command stops the program when any Ada exception
30745gets raised.  But it is also possible, by using some of the
30746optional parameters described below, to create more selective
30747catchpoints.
30748
30749The possible optional parameters for this command are:
30750
30751@table @samp
30752@item -c @var{condition}
30753Make the catchpoint conditional on @var{condition}.
30754@item -d
30755Create a disabled catchpoint.
30756@item -e @var{exception-name}
30757Only stop when @var{exception-name} is raised.  This option cannot
30758be used combined with @samp{-u}.
30759@item -t
30760Create a temporary catchpoint.
30761@item -u
30762Stop only when an unhandled exception gets raised.  This option
30763cannot be used combined with @samp{-e}.
30764@end table
30765
30766@subsubheading @value{GDBN} Command
30767
30768The corresponding @value{GDBN} commands are @samp{catch exception}
30769and @samp{catch exception unhandled}.
30770
30771@subsubheading Example
30772
30773@smallexample
30774-catch-exception -e Program_Error
30775^done,bkptno="4",bkpt=@{number="4",type="breakpoint",disp="keep",
30776enabled="y",addr="0x0000000000404874",
30777what="`Program_Error' Ada exception", thread-groups=["i1"],
30778times="0",original-location="__gnat_debug_raise_exception"@}
30779(gdb)
30780@end smallexample
30781
30782@subheading The @code{-catch-handlers} Command
30783@findex -catch-handlers
30784
30785@subsubheading Synopsis
30786
30787@smallexample
30788 -catch-handlers [ -c @var{condition}] [ -d ] [ -e @var{exception-name} ]
30789    [ -t ]
30790@end smallexample
30791
30792Add a catchpoint stopping when Ada exceptions are handled.
30793By default, the command stops the program when any Ada exception
30794gets handled.  But it is also possible, by using some of the
30795optional parameters described below, to create more selective
30796catchpoints.
30797
30798The possible optional parameters for this command are:
30799
30800@table @samp
30801@item -c @var{condition}
30802Make the catchpoint conditional on @var{condition}.
30803@item -d
30804Create a disabled catchpoint.
30805@item -e @var{exception-name}
30806Only stop when @var{exception-name} is handled.
30807@item -t
30808Create a temporary catchpoint.
30809@end table
30810
30811@subsubheading @value{GDBN} Command
30812
30813The corresponding @value{GDBN} command is @samp{catch handlers}.
30814
30815@subsubheading Example
30816
30817@smallexample
30818-catch-handlers -e Constraint_Error
30819^done,bkptno="4",bkpt=@{number="4",type="breakpoint",disp="keep",
30820enabled="y",addr="0x0000000000402f68",
30821what="`Constraint_Error' Ada exception handlers",thread-groups=["i1"],
30822times="0",original-location="__gnat_begin_handler"@}
30823(gdb)
30824@end smallexample
30825
30826@node C++ Exception GDB/MI Catchpoint Commands
30827@subsection C@t{++} Exception @sc{gdb/mi} Catchpoints
30828
30829The following @sc{gdb/mi} commands can be used to create catchpoints
30830that stop the execution when C@t{++} exceptions are being throw, rethrown,
30831or caught.
30832
30833@subheading The @code{-catch-throw} Command
30834@findex -catch-throw
30835
30836@subsubheading Synopsis
30837
30838@smallexample
30839 -catch-throw [ -t ] [ -r @var{regexp}]
30840@end smallexample
30841
30842Stop when the debuggee throws a C@t{++} exception.  If @var{regexp} is
30843given, then only exceptions whose type matches the regular expression
30844will be caught.
30845
30846If @samp{-t} is given, then the catchpoint is enabled only for one
30847stop, the catchpoint is automatically deleted after stopping once for
30848the event.
30849
30850@subsubheading @value{GDBN} Command
30851
30852The corresponding @value{GDBN} commands are @samp{catch throw}
30853and @samp{tcatch throw} (@pxref{Set Catchpoints}).
30854
30855@subsubheading Example
30856
30857@smallexample
30858-catch-throw -r exception_type
30859^done,bkpt=@{number="1",type="catchpoint",disp="keep",enabled="y",
30860  what="exception throw",catch-type="throw",
30861  thread-groups=["i1"],
30862  regexp="exception_type",times="0"@}
30863(gdb)
30864-exec-run
30865^running
30866(gdb)
30867~"\n"
30868~"Catchpoint 1 (exception thrown), 0x00007ffff7ae00ed
30869  in __cxa_throw () from /lib64/libstdc++.so.6\n"
30870*stopped,bkptno="1",reason="breakpoint-hit",disp="keep",
30871  frame=@{addr="0x00007ffff7ae00ed",func="__cxa_throw",
30872  args=[],from="/lib64/libstdc++.so.6",arch="i386:x86-64"@},
30873  thread-id="1",stopped-threads="all",core="6"
30874(gdb)
30875@end smallexample
30876
30877@subheading The @code{-catch-rethrow} Command
30878@findex -catch-rethrow
30879
30880@subsubheading Synopsis
30881
30882@smallexample
30883 -catch-rethrow [ -t ] [ -r @var{regexp}]
30884@end smallexample
30885
30886Stop when a C@t{++} exception is re-thrown.  If @var{regexp} is given,
30887then only exceptions whose type matches the regular expression will be
30888caught.
30889
30890If @samp{-t} is given, then the catchpoint is enabled only for one
30891stop, the catchpoint is automatically deleted after the first event is
30892caught.
30893
30894@subsubheading @value{GDBN} Command
30895
30896The corresponding @value{GDBN} commands are @samp{catch rethrow}
30897and @samp{tcatch rethrow} (@pxref{Set Catchpoints}).
30898
30899@subsubheading Example
30900
30901@smallexample
30902-catch-rethrow -r exception_type
30903^done,bkpt=@{number="1",type="catchpoint",disp="keep",enabled="y",
30904  what="exception rethrow",catch-type="rethrow",
30905  thread-groups=["i1"],
30906  regexp="exception_type",times="0"@}
30907(gdb)
30908-exec-run
30909^running
30910(gdb)
30911~"\n"
30912~"Catchpoint 1 (exception rethrown), 0x00007ffff7ae00ed
30913  in __cxa_rethrow () from /lib64/libstdc++.so.6\n"
30914*stopped,bkptno="1",reason="breakpoint-hit",disp="keep",
30915  frame=@{addr="0x00007ffff7ae00ed",func="__cxa_rethrow",
30916  args=[],from="/lib64/libstdc++.so.6",arch="i386:x86-64"@},
30917  thread-id="1",stopped-threads="all",core="6"
30918(gdb)
30919@end smallexample
30920
30921@subheading The @code{-catch-catch} Command
30922@findex -catch-catch
30923
30924@subsubheading Synopsis
30925
30926@smallexample
30927 -catch-catch [ -t ] [ -r @var{regexp}]
30928@end smallexample
30929
30930Stop when the debuggee catches a C@t{++} exception.  If @var{regexp}
30931is given, then only exceptions whose type matches the regular
30932expression will be caught.
30933
30934If @samp{-t} is given, then the catchpoint is enabled only for one
30935stop, the catchpoint is automatically deleted after the first event is
30936caught.
30937
30938@subsubheading @value{GDBN} Command
30939
30940The corresponding @value{GDBN} commands are @samp{catch catch}
30941and @samp{tcatch catch} (@pxref{Set Catchpoints}).
30942
30943@subsubheading Example
30944
30945@smallexample
30946-catch-catch -r exception_type
30947^done,bkpt=@{number="1",type="catchpoint",disp="keep",enabled="y",
30948  what="exception catch",catch-type="catch",
30949  thread-groups=["i1"],
30950  regexp="exception_type",times="0"@}
30951(gdb)
30952-exec-run
30953^running
30954(gdb)
30955~"\n"
30956~"Catchpoint 1 (exception caught), 0x00007ffff7ae00ed
30957  in __cxa_begin_catch () from /lib64/libstdc++.so.6\n"
30958*stopped,bkptno="1",reason="breakpoint-hit",disp="keep",
30959  frame=@{addr="0x00007ffff7ae00ed",func="__cxa_begin_catch",
30960  args=[],from="/lib64/libstdc++.so.6",arch="i386:x86-64"@},
30961  thread-id="1",stopped-threads="all",core="6"
30962(gdb)
30963@end smallexample
30964
30965@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30966@node GDB/MI Program Context
30967@section @sc{gdb/mi}  Program Context
30968
30969@subheading The @code{-exec-arguments} Command
30970@findex -exec-arguments
30971
30972
30973@subsubheading Synopsis
30974
30975@smallexample
30976 -exec-arguments @var{args}
30977@end smallexample
30978
30979Set the inferior program arguments, to be used in the next
30980@samp{-exec-run}.
30981
30982@subsubheading @value{GDBN} Command
30983
30984The corresponding @value{GDBN} command is @samp{set args}.
30985
30986@subsubheading Example
30987
30988@smallexample
30989(gdb)
30990-exec-arguments -v word
30991^done
30992(gdb)
30993@end smallexample
30994
30995
30996@ignore
30997@subheading The @code{-exec-show-arguments} Command
30998@findex -exec-show-arguments
30999
31000@subsubheading Synopsis
31001
31002@smallexample
31003 -exec-show-arguments
31004@end smallexample
31005
31006Print the arguments of the program.
31007
31008@subsubheading @value{GDBN} Command
31009
31010The corresponding @value{GDBN} command is @samp{show args}.
31011
31012@subsubheading Example
31013N.A.
31014@end ignore
31015
31016
31017@subheading The @code{-environment-cd} Command
31018@findex -environment-cd
31019
31020@subsubheading Synopsis
31021
31022@smallexample
31023 -environment-cd @var{pathdir}
31024@end smallexample
31025
31026Set @value{GDBN}'s working directory.
31027
31028@subsubheading @value{GDBN} Command
31029
31030The corresponding @value{GDBN} command is @samp{cd}.
31031
31032@subsubheading Example
31033
31034@smallexample
31035(gdb)
31036-environment-cd /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
31037^done
31038(gdb)
31039@end smallexample
31040
31041
31042@subheading The @code{-environment-directory} Command
31043@findex -environment-directory
31044
31045@subsubheading Synopsis
31046
31047@smallexample
31048 -environment-directory [ -r ] [ @var{pathdir} ]+
31049@end smallexample
31050
31051Add directories @var{pathdir} to beginning of search path for source files.
31052If the @samp{-r} option is used, the search path is reset to the default
31053search path.  If directories @var{pathdir} are supplied in addition to the
31054@samp{-r} option, the search path is first reset and then addition
31055occurs as normal.
31056Multiple directories may be specified, separated by blanks.  Specifying
31057multiple directories in a single command
31058results in the directories added to the beginning of the
31059search path in the same order they were presented in the command.
31060If blanks are needed as
31061part of a directory name, double-quotes should be used around
31062the name.  In the command output, the path will show up separated
31063by the system directory-separator character.  The directory-separator
31064character must not be used
31065in any directory name.
31066If no directories are specified, the current search path is displayed.
31067
31068@subsubheading @value{GDBN} Command
31069
31070The corresponding @value{GDBN} command is @samp{dir}.
31071
31072@subsubheading Example
31073
31074@smallexample
31075(gdb)
31076-environment-directory /kwikemart/marge/ezannoni/flathead-dev/devo/gdb
31077^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
31078(gdb)
31079-environment-directory ""
31080^done,source-path="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb:$cdir:$cwd"
31081(gdb)
31082-environment-directory -r /home/jjohnstn/src/gdb /usr/src
31083^done,source-path="/home/jjohnstn/src/gdb:/usr/src:$cdir:$cwd"
31084(gdb)
31085-environment-directory -r
31086^done,source-path="$cdir:$cwd"
31087(gdb)
31088@end smallexample
31089
31090
31091@subheading The @code{-environment-path} Command
31092@findex -environment-path
31093
31094@subsubheading Synopsis
31095
31096@smallexample
31097 -environment-path [ -r ] [ @var{pathdir} ]+
31098@end smallexample
31099
31100Add directories @var{pathdir} to beginning of search path for object files.
31101If the @samp{-r} option is used, the search path is reset to the original
31102search path that existed at gdb start-up.  If directories @var{pathdir} are
31103supplied in addition to the
31104@samp{-r} option, the search path is first reset and then addition
31105occurs as normal.
31106Multiple directories may be specified, separated by blanks.  Specifying
31107multiple directories in a single command
31108results in the directories added to the beginning of the
31109search path in the same order they were presented in the command.
31110If blanks are needed as
31111part of a directory name, double-quotes should be used around
31112the name.  In the command output, the path will show up separated
31113by the system directory-separator character.  The directory-separator
31114character must not be used
31115in any directory name.
31116If no directories are specified, the current path is displayed.
31117
31118
31119@subsubheading @value{GDBN} Command
31120
31121The corresponding @value{GDBN} command is @samp{path}.
31122
31123@subsubheading Example
31124
31125@smallexample
31126(gdb)
31127-environment-path
31128^done,path="/usr/bin"
31129(gdb)
31130-environment-path /kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb /bin
31131^done,path="/kwikemart/marge/ezannoni/flathead-dev/ppc-eabi/gdb:/bin:/usr/bin"
31132(gdb)
31133-environment-path -r /usr/local/bin
31134^done,path="/usr/local/bin:/usr/bin"
31135(gdb)
31136@end smallexample
31137
31138
31139@subheading The @code{-environment-pwd} Command
31140@findex -environment-pwd
31141
31142@subsubheading Synopsis
31143
31144@smallexample
31145 -environment-pwd
31146@end smallexample
31147
31148Show the current working directory.
31149
31150@subsubheading @value{GDBN} Command
31151
31152The corresponding @value{GDBN} command is @samp{pwd}.
31153
31154@subsubheading Example
31155
31156@smallexample
31157(gdb)
31158-environment-pwd
31159^done,cwd="/kwikemart/marge/ezannoni/flathead-dev/devo/gdb"
31160(gdb)
31161@end smallexample
31162
31163@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31164@node GDB/MI Thread Commands
31165@section @sc{gdb/mi} Thread Commands
31166
31167
31168@subheading The @code{-thread-info} Command
31169@findex -thread-info
31170
31171@subsubheading Synopsis
31172
31173@smallexample
31174 -thread-info [ @var{thread-id} ]
31175@end smallexample
31176
31177Reports information about either a specific thread, if the
31178@var{thread-id} parameter is present, or about all threads.
31179@var{thread-id} is the thread's global thread ID.  When printing
31180information about all threads, also reports the global ID of the
31181current thread.
31182
31183@subsubheading @value{GDBN} Command
31184
31185The @samp{info thread} command prints the same information
31186about all threads.
31187
31188@subsubheading Result
31189
31190The result contains the following attributes:
31191
31192@table @samp
31193@item threads
31194A list of threads.  The format of the elements of the list is described in
31195@ref{GDB/MI Thread Information}.
31196
31197@item current-thread-id
31198The global id of the currently selected thread.  This field is omitted if there
31199is no selected thread (for example, when the selected inferior is not running,
31200and therefore has no threads) or if a @var{thread-id} argument was passed to
31201the command.
31202
31203@end table
31204
31205@subsubheading Example
31206
31207@smallexample
31208-thread-info
31209^done,threads=[
31210@{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
31211   frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",
31212           args=[]@},state="running"@},
31213@{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
31214   frame=@{level="0",addr="0x0804891f",func="foo",
31215           args=[@{name="i",value="10"@}],
31216           file="/tmp/a.c",fullname="/tmp/a.c",line="158",arch="i386:x86_64"@},
31217           state="running"@}],
31218current-thread-id="1"
31219(gdb)
31220@end smallexample
31221
31222@subheading The @code{-thread-list-ids} Command
31223@findex -thread-list-ids
31224
31225@subsubheading Synopsis
31226
31227@smallexample
31228 -thread-list-ids
31229@end smallexample
31230
31231Produces a list of the currently known global @value{GDBN} thread ids.
31232At the end of the list it also prints the total number of such
31233threads.
31234
31235This command is retained for historical reasons, the
31236@code{-thread-info} command should be used instead.
31237
31238@subsubheading @value{GDBN} Command
31239
31240Part of @samp{info threads} supplies the same information.
31241
31242@subsubheading Example
31243
31244@smallexample
31245(gdb)
31246-thread-list-ids
31247^done,thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
31248current-thread-id="1",number-of-threads="3"
31249(gdb)
31250@end smallexample
31251
31252
31253@subheading The @code{-thread-select} Command
31254@findex -thread-select
31255
31256@subsubheading Synopsis
31257
31258@smallexample
31259 -thread-select @var{thread-id}
31260@end smallexample
31261
31262Make thread with global thread number @var{thread-id} the current
31263thread.  It prints the number of the new current thread, and the
31264topmost frame for that thread.
31265
31266This command is deprecated in favor of explicitly using the
31267@samp{--thread} option to each command.
31268
31269@subsubheading @value{GDBN} Command
31270
31271The corresponding @value{GDBN} command is @samp{thread}.
31272
31273@subsubheading Example
31274
31275@smallexample
31276(gdb)
31277-exec-next
31278^running
31279(gdb)
31280*stopped,reason="end-stepping-range",thread-id="2",line="187",
31281file="../../../devo/gdb/testsuite/gdb.threads/linux-dp.c"
31282(gdb)
31283-thread-list-ids
31284^done,
31285thread-ids=@{thread-id="3",thread-id="2",thread-id="1"@},
31286number-of-threads="3"
31287(gdb)
31288-thread-select 3
31289^done,new-thread-id="3",
31290frame=@{level="0",func="vprintf",
31291args=[@{name="format",value="0x8048e9c \"%*s%c %d %c\\n\""@},
31292@{name="arg",value="0x2"@}],file="vprintf.c",line="31",arch="i386:x86_64"@}
31293(gdb)
31294@end smallexample
31295
31296@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31297@node GDB/MI Ada Tasking Commands
31298@section @sc{gdb/mi} Ada Tasking Commands
31299
31300@subheading The @code{-ada-task-info} Command
31301@findex -ada-task-info
31302
31303@subsubheading Synopsis
31304
31305@smallexample
31306 -ada-task-info [ @var{task-id} ]
31307@end smallexample
31308
31309Reports information about either a specific Ada task, if the
31310@var{task-id} parameter is present, or about all Ada tasks.
31311
31312@subsubheading @value{GDBN} Command
31313
31314The @samp{info tasks} command prints the same information
31315about all Ada tasks (@pxref{Ada Tasks}).
31316
31317@subsubheading Result
31318
31319The result is a table of Ada tasks.  The following columns are
31320defined for each Ada task:
31321
31322@table @samp
31323@item current
31324This field exists only for the current thread.  It has the value @samp{*}.
31325
31326@item id
31327The identifier that @value{GDBN} uses to refer to the Ada task.
31328
31329@item task-id
31330The identifier that the target uses to refer to the Ada task.
31331
31332@item thread-id
31333The global thread identifier of the thread corresponding to the Ada
31334task.
31335
31336This field should always exist, as Ada tasks are always implemented
31337on top of a thread.  But if @value{GDBN} cannot find this corresponding
31338thread for any reason, the field is omitted.
31339
31340@item parent-id
31341This field exists only when the task was created by another task.
31342In this case, it provides the ID of the parent task.
31343
31344@item priority
31345The base priority of the task.
31346
31347@item state
31348The current state of the task.  For a detailed description of the
31349possible states, see @ref{Ada Tasks}.
31350
31351@item name
31352The name of the task.
31353
31354@end table
31355
31356@subsubheading Example
31357
31358@smallexample
31359-ada-task-info
31360^done,tasks=@{nr_rows="3",nr_cols="8",
31361hdr=[@{width="1",alignment="-1",col_name="current",colhdr=""@},
31362@{width="3",alignment="1",col_name="id",colhdr="ID"@},
31363@{width="9",alignment="1",col_name="task-id",colhdr="TID"@},
31364@{width="4",alignment="1",col_name="thread-id",colhdr=""@},
31365@{width="4",alignment="1",col_name="parent-id",colhdr="P-ID"@},
31366@{width="3",alignment="1",col_name="priority",colhdr="Pri"@},
31367@{width="22",alignment="-1",col_name="state",colhdr="State"@},
31368@{width="1",alignment="2",col_name="name",colhdr="Name"@}],
31369body=[@{current="*",id="1",task-id="   644010",thread-id="1",priority="48",
31370state="Child Termination Wait",name="main_task"@}]@}
31371(gdb)
31372@end smallexample
31373
31374@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31375@node GDB/MI Program Execution
31376@section @sc{gdb/mi} Program Execution
31377
31378These are the asynchronous commands which generate the out-of-band
31379record @samp{*stopped}.  Currently @value{GDBN} only really executes
31380asynchronously with remote targets and this interaction is mimicked in
31381other cases.
31382
31383@subheading The @code{-exec-continue} Command
31384@findex -exec-continue
31385
31386@subsubheading Synopsis
31387
31388@smallexample
31389 -exec-continue [--reverse] [--all|--thread-group N]
31390@end smallexample
31391
31392Resumes the execution of the inferior program, which will continue
31393to execute until it reaches a debugger stop event.  If the
31394@samp{--reverse} option is specified, execution resumes in reverse until
31395it reaches a stop event.  Stop events may include
31396@itemize @bullet
31397@item
31398breakpoints or watchpoints
31399@item
31400signals or exceptions
31401@item
31402the end of the process (or its beginning under @samp{--reverse})
31403@item
31404the end or beginning of a replay log if one is being used.
31405@end itemize
31406In all-stop mode (@pxref{All-Stop
31407Mode}), may resume only one thread, or all threads, depending on the
31408value of the @samp{scheduler-locking} variable.  If @samp{--all} is
31409specified, all threads (in all inferiors) will be resumed.  The @samp{--all} option is
31410ignored in all-stop mode.  If the @samp{--thread-group} options is
31411specified, then all threads in that thread group are resumed.
31412
31413@subsubheading @value{GDBN} Command
31414
31415The corresponding @value{GDBN} corresponding is @samp{continue}.
31416
31417@subsubheading Example
31418
31419@smallexample
31420-exec-continue
31421^running
31422(gdb)
31423@@Hello world
31424*stopped,reason="breakpoint-hit",disp="keep",bkptno="2",frame=@{
31425func="foo",args=[],file="hello.c",fullname="/home/foo/bar/hello.c",
31426line="13",arch="i386:x86_64"@}
31427(gdb)
31428@end smallexample
31429
31430
31431@subheading The @code{-exec-finish} Command
31432@findex -exec-finish
31433
31434@subsubheading Synopsis
31435
31436@smallexample
31437 -exec-finish [--reverse]
31438@end smallexample
31439
31440Resumes the execution of the inferior program until the current
31441function is exited.  Displays the results returned by the function.
31442If the @samp{--reverse} option is specified, resumes the reverse
31443execution of the inferior program until the point where current
31444function was called.
31445
31446@subsubheading @value{GDBN} Command
31447
31448The corresponding @value{GDBN} command is @samp{finish}.
31449
31450@subsubheading Example
31451
31452Function returning @code{void}.
31453
31454@smallexample
31455-exec-finish
31456^running
31457(gdb)
31458@@hello from foo
31459*stopped,reason="function-finished",frame=@{func="main",args=[],
31460file="hello.c",fullname="/home/foo/bar/hello.c",line="7",arch="i386:x86_64"@}
31461(gdb)
31462@end smallexample
31463
31464Function returning other than @code{void}.  The name of the internal
31465@value{GDBN} variable storing the result is printed, together with the
31466value itself.
31467
31468@smallexample
31469-exec-finish
31470^running
31471(gdb)
31472*stopped,reason="function-finished",frame=@{addr="0x000107b0",func="foo",
31473args=[@{name="a",value="1"],@{name="b",value="9"@}@},
31474file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
31475arch="i386:x86_64"@},
31476gdb-result-var="$1",return-value="0"
31477(gdb)
31478@end smallexample
31479
31480
31481@subheading The @code{-exec-interrupt} Command
31482@findex -exec-interrupt
31483
31484@subsubheading Synopsis
31485
31486@smallexample
31487 -exec-interrupt [--all|--thread-group N]
31488@end smallexample
31489
31490Interrupts the background execution of the target.  Note how the token
31491associated with the stop message is the one for the execution command
31492that has been interrupted.  The token for the interrupt itself only
31493appears in the @samp{^done} output.  If the user is trying to
31494interrupt a non-running program, an error message will be printed.
31495
31496Note that when asynchronous execution is enabled, this command is
31497asynchronous just like other execution commands.  That is, first the
31498@samp{^done} response will be printed, and the target stop will be
31499reported after that using the @samp{*stopped} notification.
31500
31501In non-stop mode, only the context thread is interrupted by default.
31502All threads (in all inferiors) will be interrupted if the
31503@samp{--all}  option is specified.  If the @samp{--thread-group}
31504option is specified, all threads in that group will be interrupted.
31505
31506@subsubheading @value{GDBN} Command
31507
31508The corresponding @value{GDBN} command is @samp{interrupt}.
31509
31510@subsubheading Example
31511
31512@smallexample
31513(gdb)
31514111-exec-continue
31515111^running
31516
31517(gdb)
31518222-exec-interrupt
31519222^done
31520(gdb)
31521111*stopped,signal-name="SIGINT",signal-meaning="Interrupt",
31522frame=@{addr="0x00010140",func="foo",args=[],file="try.c",
31523fullname="/home/foo/bar/try.c",line="13",arch="i386:x86_64"@}
31524(gdb)
31525
31526(gdb)
31527-exec-interrupt
31528^error,msg="mi_cmd_exec_interrupt: Inferior not executing."
31529(gdb)
31530@end smallexample
31531
31532@subheading The @code{-exec-jump} Command
31533@findex -exec-jump
31534
31535@subsubheading Synopsis
31536
31537@smallexample
31538 -exec-jump @var{location}
31539@end smallexample
31540
31541Resumes execution of the inferior program at the location specified by
31542parameter.  @xref{Specify Location}, for a description of the
31543different forms of @var{location}.
31544
31545@subsubheading @value{GDBN} Command
31546
31547The corresponding @value{GDBN} command is @samp{jump}.
31548
31549@subsubheading Example
31550
31551@smallexample
31552-exec-jump foo.c:10
31553*running,thread-id="all"
31554^running
31555@end smallexample
31556
31557
31558@subheading The @code{-exec-next} Command
31559@findex -exec-next
31560
31561@subsubheading Synopsis
31562
31563@smallexample
31564 -exec-next [--reverse]
31565@end smallexample
31566
31567Resumes execution of the inferior program, stopping when the beginning
31568of the next source line is reached.
31569
31570If the @samp{--reverse} option is specified, resumes reverse execution
31571of the inferior program, stopping at the beginning of the previous
31572source line.  If you issue this command on the first line of a
31573function, it will take you back to the caller of that function, to the
31574source line where the function was called.
31575
31576
31577@subsubheading @value{GDBN} Command
31578
31579The corresponding @value{GDBN} command is @samp{next}.
31580
31581@subsubheading Example
31582
31583@smallexample
31584-exec-next
31585^running
31586(gdb)
31587*stopped,reason="end-stepping-range",line="8",file="hello.c"
31588(gdb)
31589@end smallexample
31590
31591
31592@subheading The @code{-exec-next-instruction} Command
31593@findex -exec-next-instruction
31594
31595@subsubheading Synopsis
31596
31597@smallexample
31598 -exec-next-instruction [--reverse]
31599@end smallexample
31600
31601Executes one machine instruction.  If the instruction is a function
31602call, continues until the function returns.  If the program stops at an
31603instruction in the middle of a source line, the address will be
31604printed as well.
31605
31606If the @samp{--reverse} option is specified, resumes reverse execution
31607of the inferior program, stopping at the previous instruction.  If the
31608previously executed instruction was a return from another function,
31609it will continue to execute in reverse until the call to that function
31610(from the current stack frame) is reached.
31611
31612@subsubheading @value{GDBN} Command
31613
31614The corresponding @value{GDBN} command is @samp{nexti}.
31615
31616@subsubheading Example
31617
31618@smallexample
31619(gdb)
31620-exec-next-instruction
31621^running
31622
31623(gdb)
31624*stopped,reason="end-stepping-range",
31625addr="0x000100d4",line="5",file="hello.c"
31626(gdb)
31627@end smallexample
31628
31629
31630@subheading The @code{-exec-return} Command
31631@findex -exec-return
31632
31633@subsubheading Synopsis
31634
31635@smallexample
31636 -exec-return
31637@end smallexample
31638
31639Makes current function return immediately.  Doesn't execute the inferior.
31640Displays the new current frame.
31641
31642@subsubheading @value{GDBN} Command
31643
31644The corresponding @value{GDBN} command is @samp{return}.
31645
31646@subsubheading Example
31647
31648@smallexample
31649(gdb)
31650200-break-insert callee4
31651200^done,bkpt=@{number="1",addr="0x00010734",
31652file="../../../devo/gdb/testsuite/gdb.mi/basics.c",line="8"@}
31653(gdb)
31654000-exec-run
31655000^running
31656(gdb)
31657000*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
31658frame=@{func="callee4",args=[],
31659file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31660fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
31661arch="i386:x86_64"@}
31662(gdb)
31663205-break-delete
31664205^done
31665(gdb)
31666111-exec-return
31667111^done,frame=@{level="0",func="callee3",
31668args=[@{name="strarg",
31669value="0x11940 \"A string argument.\""@}],
31670file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31671fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="18",
31672arch="i386:x86_64"@}
31673(gdb)
31674@end smallexample
31675
31676
31677@subheading The @code{-exec-run} Command
31678@findex -exec-run
31679
31680@subsubheading Synopsis
31681
31682@smallexample
31683 -exec-run [ --all | --thread-group N ] [ --start ]
31684@end smallexample
31685
31686Starts execution of the inferior from the beginning.  The inferior
31687executes until either a breakpoint is encountered or the program
31688exits.  In the latter case the output will include an exit code, if
31689the program has exited exceptionally.
31690
31691When neither the @samp{--all} nor the @samp{--thread-group} option
31692is specified, the current inferior is started.  If the
31693@samp{--thread-group} option is specified, it should refer to a thread
31694group of type @samp{process}, and that thread group will be started.
31695If the @samp{--all} option is specified, then all inferiors will be started.
31696
31697Using the @samp{--start} option instructs the debugger to stop
31698the execution at the start of the inferior's main subprogram,
31699following the same behavior as the @code{start} command
31700(@pxref{Starting}).
31701
31702@subsubheading @value{GDBN} Command
31703
31704The corresponding @value{GDBN} command is @samp{run}.
31705
31706@subsubheading Examples
31707
31708@smallexample
31709(gdb)
31710-break-insert main
31711^done,bkpt=@{number="1",addr="0x0001072c",file="recursive2.c",line="4"@}
31712(gdb)
31713-exec-run
31714^running
31715(gdb)
31716*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",
31717frame=@{func="main",args=[],file="recursive2.c",
31718fullname="/home/foo/bar/recursive2.c",line="4",arch="i386:x86_64"@}
31719(gdb)
31720@end smallexample
31721
31722@noindent
31723Program exited normally:
31724
31725@smallexample
31726(gdb)
31727-exec-run
31728^running
31729(gdb)
31730x = 55
31731*stopped,reason="exited-normally"
31732(gdb)
31733@end smallexample
31734
31735@noindent
31736Program exited exceptionally:
31737
31738@smallexample
31739(gdb)
31740-exec-run
31741^running
31742(gdb)
31743x = 55
31744*stopped,reason="exited",exit-code="01"
31745(gdb)
31746@end smallexample
31747
31748Another way the program can terminate is if it receives a signal such as
31749@code{SIGINT}.  In this case, @sc{gdb/mi} displays this:
31750
31751@smallexample
31752(gdb)
31753*stopped,reason="exited-signalled",signal-name="SIGINT",
31754signal-meaning="Interrupt"
31755@end smallexample
31756
31757
31758@c @subheading -exec-signal
31759
31760
31761@subheading The @code{-exec-step} Command
31762@findex -exec-step
31763
31764@subsubheading Synopsis
31765
31766@smallexample
31767 -exec-step [--reverse]
31768@end smallexample
31769
31770Resumes execution of the inferior program, stopping when the beginning
31771of the next source line is reached, if the next source line is not a
31772function call.  If it is, stop at the first instruction of the called
31773function.  If the @samp{--reverse} option is specified, resumes reverse
31774execution of the inferior program, stopping at the beginning of the
31775previously executed source line.
31776
31777@subsubheading @value{GDBN} Command
31778
31779The corresponding @value{GDBN} command is @samp{step}.
31780
31781@subsubheading Example
31782
31783Stepping into a function:
31784
31785@smallexample
31786-exec-step
31787^running
31788(gdb)
31789*stopped,reason="end-stepping-range",
31790frame=@{func="foo",args=[@{name="a",value="10"@},
31791@{name="b",value="0"@}],file="recursive2.c",
31792fullname="/home/foo/bar/recursive2.c",line="11",arch="i386:x86_64"@}
31793(gdb)
31794@end smallexample
31795
31796Regular stepping:
31797
31798@smallexample
31799-exec-step
31800^running
31801(gdb)
31802*stopped,reason="end-stepping-range",line="14",file="recursive2.c"
31803(gdb)
31804@end smallexample
31805
31806
31807@subheading The @code{-exec-step-instruction} Command
31808@findex -exec-step-instruction
31809
31810@subsubheading Synopsis
31811
31812@smallexample
31813 -exec-step-instruction [--reverse]
31814@end smallexample
31815
31816Resumes the inferior which executes one machine instruction.  If the
31817@samp{--reverse} option is specified, resumes reverse execution of the
31818inferior program, stopping at the previously executed instruction.
31819The output, once @value{GDBN} has stopped, will vary depending on
31820whether we have stopped in the middle of a source line or not.  In the
31821former case, the address at which the program stopped will be printed
31822as well.
31823
31824@subsubheading @value{GDBN} Command
31825
31826The corresponding @value{GDBN} command is @samp{stepi}.
31827
31828@subsubheading Example
31829
31830@smallexample
31831(gdb)
31832-exec-step-instruction
31833^running
31834
31835(gdb)
31836*stopped,reason="end-stepping-range",
31837frame=@{func="foo",args=[],file="try.c",
31838fullname="/home/foo/bar/try.c",line="10",arch="i386:x86_64"@}
31839(gdb)
31840-exec-step-instruction
31841^running
31842
31843(gdb)
31844*stopped,reason="end-stepping-range",
31845frame=@{addr="0x000100f4",func="foo",args=[],file="try.c",
31846fullname="/home/foo/bar/try.c",line="10",arch="i386:x86_64"@}
31847(gdb)
31848@end smallexample
31849
31850
31851@subheading The @code{-exec-until} Command
31852@findex -exec-until
31853
31854@subsubheading Synopsis
31855
31856@smallexample
31857 -exec-until [ @var{location} ]
31858@end smallexample
31859
31860Executes the inferior until the @var{location} specified in the
31861argument is reached.  If there is no argument, the inferior executes
31862until a source line greater than the current one is reached.  The
31863reason for stopping in this case will be @samp{location-reached}.
31864
31865@subsubheading @value{GDBN} Command
31866
31867The corresponding @value{GDBN} command is @samp{until}.
31868
31869@subsubheading Example
31870
31871@smallexample
31872(gdb)
31873-exec-until recursive2.c:6
31874^running
31875(gdb)
31876x = 55
31877*stopped,reason="location-reached",frame=@{func="main",args=[],
31878file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="6",
31879arch="i386:x86_64"@}
31880(gdb)
31881@end smallexample
31882
31883@ignore
31884@subheading -file-clear
31885Is this going away????
31886@end ignore
31887
31888@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31889@node GDB/MI Stack Manipulation
31890@section @sc{gdb/mi} Stack Manipulation Commands
31891
31892@subheading The @code{-enable-frame-filters} Command
31893@findex -enable-frame-filters
31894
31895@smallexample
31896-enable-frame-filters
31897@end smallexample
31898
31899@value{GDBN} allows Python-based frame filters to affect the output of
31900the MI commands relating to stack traces.  As there is no way to
31901implement this in a fully backward-compatible way, a front end must
31902request that this functionality be enabled.
31903
31904Once enabled, this feature cannot be disabled.
31905
31906Note that if Python support has not been compiled into @value{GDBN},
31907this command will still succeed (and do nothing).
31908
31909@subheading The @code{-stack-info-frame} Command
31910@findex -stack-info-frame
31911
31912@subsubheading Synopsis
31913
31914@smallexample
31915 -stack-info-frame
31916@end smallexample
31917
31918Get info on the selected frame.
31919
31920@subsubheading @value{GDBN} Command
31921
31922The corresponding @value{GDBN} command is @samp{info frame} or @samp{frame}
31923(without arguments).
31924
31925@subsubheading Example
31926
31927@smallexample
31928(gdb)
31929-stack-info-frame
31930^done,frame=@{level="1",addr="0x0001076c",func="callee3",
31931file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
31932fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17",
31933arch="i386:x86_64"@}
31934(gdb)
31935@end smallexample
31936
31937@subheading The @code{-stack-info-depth} Command
31938@findex -stack-info-depth
31939
31940@subsubheading Synopsis
31941
31942@smallexample
31943 -stack-info-depth [ @var{max-depth} ]
31944@end smallexample
31945
31946Return the depth of the stack.  If the integer argument @var{max-depth}
31947is specified, do not count beyond @var{max-depth} frames.
31948
31949@subsubheading @value{GDBN} Command
31950
31951There's no equivalent @value{GDBN} command.
31952
31953@subsubheading Example
31954
31955For a stack with frame levels 0 through 11:
31956
31957@smallexample
31958(gdb)
31959-stack-info-depth
31960^done,depth="12"
31961(gdb)
31962-stack-info-depth 4
31963^done,depth="4"
31964(gdb)
31965-stack-info-depth 12
31966^done,depth="12"
31967(gdb)
31968-stack-info-depth 11
31969^done,depth="11"
31970(gdb)
31971-stack-info-depth 13
31972^done,depth="12"
31973(gdb)
31974@end smallexample
31975
31976@anchor{-stack-list-arguments}
31977@subheading The @code{-stack-list-arguments} Command
31978@findex -stack-list-arguments
31979
31980@subsubheading Synopsis
31981
31982@smallexample
31983 -stack-list-arguments [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
31984    [ @var{low-frame} @var{high-frame} ]
31985@end smallexample
31986
31987Display a list of the arguments for the frames between @var{low-frame}
31988and @var{high-frame} (inclusive).  If @var{low-frame} and
31989@var{high-frame} are not provided, list the arguments for the whole
31990call stack.  If the two arguments are equal, show the single frame
31991at the corresponding level.  It is an error if @var{low-frame} is
31992larger than the actual number of frames.  On the other hand,
31993@var{high-frame} may be larger than the actual number of frames, in
31994which case only existing frames will be returned.
31995
31996If @var{print-values} is 0 or @code{--no-values}, print only the names of
31997the variables; if it is 1 or @code{--all-values}, print also their
31998values; and if it is 2 or @code{--simple-values}, print the name,
31999type and value for simple data types, and the name and type for arrays,
32000structures and unions.  If the option @code{--no-frame-filters} is
32001supplied, then Python frame filters will not be executed.
32002
32003If the @code{--skip-unavailable} option is specified, arguments that
32004are not available are not listed.  Partially available arguments
32005are still displayed, however.
32006
32007Use of this command to obtain arguments in a single frame is
32008deprecated in favor of the @samp{-stack-list-variables} command.
32009
32010@subsubheading @value{GDBN} Command
32011
32012@value{GDBN} does not have an equivalent command.  @code{gdbtk} has a
32013@samp{gdb_get_args} command which partially overlaps with the
32014functionality of @samp{-stack-list-arguments}.
32015
32016@subsubheading Example
32017
32018@smallexample
32019(gdb)
32020-stack-list-frames
32021^done,
32022stack=[
32023frame=@{level="0",addr="0x00010734",func="callee4",
32024file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
32025fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="8",
32026arch="i386:x86_64"@},
32027frame=@{level="1",addr="0x0001076c",func="callee3",
32028file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
32029fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="17",
32030arch="i386:x86_64"@},
32031frame=@{level="2",addr="0x0001078c",func="callee2",
32032file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
32033fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="22",
32034arch="i386:x86_64"@},
32035frame=@{level="3",addr="0x000107b4",func="callee1",
32036file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
32037fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="27",
32038arch="i386:x86_64"@},
32039frame=@{level="4",addr="0x000107e0",func="main",
32040file="../../../devo/gdb/testsuite/gdb.mi/basics.c",
32041fullname="/home/foo/bar/devo/gdb/testsuite/gdb.mi/basics.c",line="32",
32042arch="i386:x86_64"@}]
32043(gdb)
32044-stack-list-arguments 0
32045^done,
32046stack-args=[
32047frame=@{level="0",args=[]@},
32048frame=@{level="1",args=[name="strarg"]@},
32049frame=@{level="2",args=[name="intarg",name="strarg"]@},
32050frame=@{level="3",args=[name="intarg",name="strarg",name="fltarg"]@},
32051frame=@{level="4",args=[]@}]
32052(gdb)
32053-stack-list-arguments 1
32054^done,
32055stack-args=[
32056frame=@{level="0",args=[]@},
32057frame=@{level="1",
32058 args=[@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
32059frame=@{level="2",args=[
32060@{name="intarg",value="2"@},
32061@{name="strarg",value="0x11940 \"A string argument.\""@}]@},
32062@{frame=@{level="3",args=[
32063@{name="intarg",value="2"@},
32064@{name="strarg",value="0x11940 \"A string argument.\""@},
32065@{name="fltarg",value="3.5"@}]@},
32066frame=@{level="4",args=[]@}]
32067(gdb)
32068-stack-list-arguments 0 2 2
32069^done,stack-args=[frame=@{level="2",args=[name="intarg",name="strarg"]@}]
32070(gdb)
32071-stack-list-arguments 1 2 2
32072^done,stack-args=[frame=@{level="2",
32073args=[@{name="intarg",value="2"@},
32074@{name="strarg",value="0x11940 \"A string argument.\""@}]@}]
32075(gdb)
32076@end smallexample
32077
32078@c @subheading -stack-list-exception-handlers
32079
32080
32081@anchor{-stack-list-frames}
32082@subheading The @code{-stack-list-frames} Command
32083@findex -stack-list-frames
32084
32085@subsubheading Synopsis
32086
32087@smallexample
32088 -stack-list-frames [ --no-frame-filters @var{low-frame} @var{high-frame} ]
32089@end smallexample
32090
32091List the frames currently on the stack.  For each frame it displays the
32092following info:
32093
32094@table @samp
32095@item @var{level}
32096The frame number, 0 being the topmost frame, i.e., the innermost function.
32097@item @var{addr}
32098The @code{$pc} value for that frame.
32099@item @var{func}
32100Function name.
32101@item @var{file}
32102File name of the source file where the function lives.
32103@item @var{fullname}
32104The full file name of the source file where the function lives.
32105@item @var{line}
32106Line number corresponding to the @code{$pc}.
32107@item @var{from}
32108The shared library where this function is defined.  This is only given
32109if the frame's function is not known.
32110@item @var{arch}
32111Frame's architecture.
32112@end table
32113
32114If invoked without arguments, this command prints a backtrace for the
32115whole stack.  If given two integer arguments, it shows the frames whose
32116levels are between the two arguments (inclusive).  If the two arguments
32117are equal, it shows the single frame at the corresponding level.  It is
32118an error if @var{low-frame} is larger than the actual number of
32119frames.  On the other hand, @var{high-frame} may be larger than the
32120actual number of frames, in which case only existing frames will be
32121returned.  If the option @code{--no-frame-filters} is supplied, then
32122Python frame filters will not be executed.
32123
32124@subsubheading @value{GDBN} Command
32125
32126The corresponding @value{GDBN} commands are @samp{backtrace} and @samp{where}.
32127
32128@subsubheading Example
32129
32130Full stack backtrace:
32131
32132@smallexample
32133(gdb)
32134-stack-list-frames
32135^done,stack=
32136[frame=@{level="0",addr="0x0001076c",func="foo",
32137  file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="11",
32138  arch="i386:x86_64"@},
32139frame=@{level="1",addr="0x000107a4",func="foo",
32140  file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32141  arch="i386:x86_64"@},
32142frame=@{level="2",addr="0x000107a4",func="foo",
32143  file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32144  arch="i386:x86_64"@},
32145frame=@{level="3",addr="0x000107a4",func="foo",
32146  file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32147  arch="i386:x86_64"@},
32148frame=@{level="4",addr="0x000107a4",func="foo",
32149  file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32150  arch="i386:x86_64"@},
32151frame=@{level="5",addr="0x000107a4",func="foo",
32152  file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32153  arch="i386:x86_64"@},
32154frame=@{level="6",addr="0x000107a4",func="foo",
32155  file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32156  arch="i386:x86_64"@},
32157frame=@{level="7",addr="0x000107a4",func="foo",
32158  file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32159  arch="i386:x86_64"@},
32160frame=@{level="8",addr="0x000107a4",func="foo",
32161  file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32162  arch="i386:x86_64"@},
32163frame=@{level="9",addr="0x000107a4",func="foo",
32164  file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32165  arch="i386:x86_64"@},
32166frame=@{level="10",addr="0x000107a4",func="foo",
32167  file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32168  arch="i386:x86_64"@},
32169frame=@{level="11",addr="0x00010738",func="main",
32170  file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="4",
32171  arch="i386:x86_64"@}]
32172(gdb)
32173@end smallexample
32174
32175Show frames between @var{low_frame} and @var{high_frame}:
32176
32177@smallexample
32178(gdb)
32179-stack-list-frames 3 5
32180^done,stack=
32181[frame=@{level="3",addr="0x000107a4",func="foo",
32182  file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32183  arch="i386:x86_64"@},
32184frame=@{level="4",addr="0x000107a4",func="foo",
32185  file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32186  arch="i386:x86_64"@},
32187frame=@{level="5",addr="0x000107a4",func="foo",
32188  file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32189  arch="i386:x86_64"@}]
32190(gdb)
32191@end smallexample
32192
32193Show a single frame:
32194
32195@smallexample
32196(gdb)
32197-stack-list-frames 3 3
32198^done,stack=
32199[frame=@{level="3",addr="0x000107a4",func="foo",
32200  file="recursive2.c",fullname="/home/foo/bar/recursive2.c",line="14",
32201  arch="i386:x86_64"@}]
32202(gdb)
32203@end smallexample
32204
32205
32206@subheading The @code{-stack-list-locals} Command
32207@findex -stack-list-locals
32208@anchor{-stack-list-locals}
32209
32210@subsubheading Synopsis
32211
32212@smallexample
32213 -stack-list-locals [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
32214@end smallexample
32215
32216Display the local variable names for the selected frame.  If
32217@var{print-values} is 0 or @code{--no-values}, print only the names of
32218the variables; if it is 1 or @code{--all-values}, print also their
32219values; and if it is 2 or @code{--simple-values}, print the name,
32220type and value for simple data types, and the name and type for arrays,
32221structures and unions.  In this last case, a frontend can immediately
32222display the value of simple data types and create variable objects for
32223other data types when the user wishes to explore their values in
32224more detail.  If the option @code{--no-frame-filters} is supplied, then
32225Python frame filters will not be executed.
32226
32227If the @code{--skip-unavailable} option is specified, local variables
32228that are not available are not listed.  Partially available local
32229variables are still displayed, however.
32230
32231This command is deprecated in favor of the
32232@samp{-stack-list-variables} command.
32233
32234@subsubheading @value{GDBN} Command
32235
32236@samp{info locals} in @value{GDBN}, @samp{gdb_get_locals} in @code{gdbtk}.
32237
32238@subsubheading Example
32239
32240@smallexample
32241(gdb)
32242-stack-list-locals 0
32243^done,locals=[name="A",name="B",name="C"]
32244(gdb)
32245-stack-list-locals --all-values
32246^done,locals=[@{name="A",value="1"@},@{name="B",value="2"@},
32247  @{name="C",value="@{1, 2, 3@}"@}]
32248-stack-list-locals --simple-values
32249^done,locals=[@{name="A",type="int",value="1"@},
32250  @{name="B",type="int",value="2"@},@{name="C",type="int [3]"@}]
32251(gdb)
32252@end smallexample
32253
32254@anchor{-stack-list-variables}
32255@subheading The @code{-stack-list-variables} Command
32256@findex -stack-list-variables
32257
32258@subsubheading Synopsis
32259
32260@smallexample
32261 -stack-list-variables [ --no-frame-filters ] [ --skip-unavailable ] @var{print-values}
32262@end smallexample
32263
32264Display the names of local variables and function arguments for the selected frame.  If
32265@var{print-values} is 0 or @code{--no-values}, print only the names of
32266the variables; if it is 1 or @code{--all-values}, print also their
32267values; and if it is 2 or @code{--simple-values}, print the name,
32268type and value for simple data types, and the name and type for arrays,
32269structures and unions.  If the option @code{--no-frame-filters} is
32270supplied, then Python frame filters will not be executed.
32271
32272If the @code{--skip-unavailable} option is specified, local variables
32273and arguments that are not available are not listed.  Partially
32274available arguments and local variables are still displayed, however.
32275
32276@subsubheading Example
32277
32278@smallexample
32279(gdb)
32280-stack-list-variables --thread 1 --frame 0 --all-values
32281^done,variables=[@{name="x",value="11"@},@{name="s",value="@{a = 1, b = 2@}"@}]
32282(gdb)
32283@end smallexample
32284
32285
32286@subheading The @code{-stack-select-frame} Command
32287@findex -stack-select-frame
32288
32289@subsubheading Synopsis
32290
32291@smallexample
32292 -stack-select-frame @var{framenum}
32293@end smallexample
32294
32295Change the selected frame.  Select a different frame @var{framenum} on
32296the stack.
32297
32298This command in deprecated in favor of passing the @samp{--frame}
32299option to every command.
32300
32301@subsubheading @value{GDBN} Command
32302
32303The corresponding @value{GDBN} commands are @samp{frame}, @samp{up},
32304@samp{down}, @samp{select-frame}, @samp{up-silent}, and @samp{down-silent}.
32305
32306@subsubheading Example
32307
32308@smallexample
32309(gdb)
32310-stack-select-frame 2
32311^done
32312(gdb)
32313@end smallexample
32314
32315@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32316@node GDB/MI Variable Objects
32317@section @sc{gdb/mi} Variable Objects
32318
32319@ignore
32320
32321@subheading Motivation for Variable Objects in @sc{gdb/mi}
32322
32323For the implementation of a variable debugger window (locals, watched
32324expressions, etc.), we are proposing the adaptation of the existing code
32325used by @code{Insight}.
32326
32327The two main reasons for that are:
32328
32329@enumerate 1
32330@item
32331It has been proven in practice (it is already on its second generation).
32332
32333@item
32334It will shorten development time (needless to say how important it is
32335now).
32336@end enumerate
32337
32338The original interface was designed to be used by Tcl code, so it was
32339slightly changed so it could be used through @sc{gdb/mi}.  This section
32340describes the @sc{gdb/mi} operations that will be available and gives some
32341hints about their use.
32342
32343@emph{Note}: In addition to the set of operations described here, we
32344expect the @sc{gui} implementation of a variable window to require, at
32345least, the following operations:
32346
32347@itemize @bullet
32348@item @code{-gdb-show} @code{output-radix}
32349@item @code{-stack-list-arguments}
32350@item @code{-stack-list-locals}
32351@item @code{-stack-select-frame}
32352@end itemize
32353
32354@end ignore
32355
32356@subheading Introduction to Variable Objects
32357
32358@cindex variable objects in @sc{gdb/mi}
32359
32360Variable objects are "object-oriented" MI interface for examining and
32361changing values of expressions.  Unlike some other MI interfaces that
32362work with expressions, variable objects are specifically designed for
32363simple and efficient presentation in the frontend.  A variable object
32364is identified by string name.  When a variable object is created, the
32365frontend specifies the expression for that variable object.  The
32366expression can be a simple variable, or it can be an arbitrary complex
32367expression, and can even involve CPU registers.  After creating a
32368variable object, the frontend can invoke other variable object
32369operations---for example to obtain or change the value of a variable
32370object, or to change display format.
32371
32372Variable objects have hierarchical tree structure.  Any variable object
32373that corresponds to a composite type, such as structure in C, has
32374a number of child variable objects, for example corresponding to each
32375element of a structure.  A child variable object can itself have
32376children, recursively.  Recursion ends when we reach
32377leaf variable objects, which always have built-in types.  Child variable
32378objects are created only by explicit request, so if a frontend
32379is not interested in the children of a particular variable object, no
32380child will be created.
32381
32382For a leaf variable object it is possible to obtain its value as a
32383string, or set the value from a string.  String value can be also
32384obtained for a non-leaf variable object, but it's generally a string
32385that only indicates the type of the object, and does not list its
32386contents.  Assignment to a non-leaf variable object is not allowed.
32387
32388A frontend does not need to read the values of all variable objects each time
32389the program stops.  Instead, MI provides an update command that lists all
32390variable objects whose values has changed since the last update
32391operation.  This considerably reduces the amount of data that must
32392be transferred to the frontend.  As noted above, children variable
32393objects are created on demand, and only leaf variable objects have a
32394real value.  As result, gdb will read target memory only for leaf
32395variables that frontend has created.
32396
32397The automatic update is not always desirable.  For example, a frontend
32398might want to keep a value of some expression for future reference,
32399and never update it.  For another example,  fetching memory is
32400relatively slow for embedded targets, so a frontend might want
32401to disable automatic update for the variables that are either not
32402visible on the screen, or ``closed''.  This is possible using so
32403called ``frozen variable objects''.  Such variable objects are never
32404implicitly updated.
32405
32406Variable objects can be either @dfn{fixed} or @dfn{floating}.  For the
32407fixed variable object, the expression is parsed when the variable
32408object is created, including associating identifiers to specific
32409variables.  The meaning of expression never changes.  For a floating
32410variable object the values of variables whose names appear in the
32411expressions are re-evaluated every time in the context of the current
32412frame.  Consider this example:
32413
32414@smallexample
32415void do_work(...)
32416@{
32417        struct work_state state;
32418
32419        if (...)
32420           do_work(...);
32421@}
32422@end smallexample
32423
32424If a fixed variable object for the @code{state} variable is created in
32425this function, and we enter the recursive call, the variable
32426object will report the value of @code{state} in the top-level
32427@code{do_work} invocation.  On the other hand, a floating variable
32428object will report the value of @code{state} in the current frame.
32429
32430If an expression specified when creating a fixed variable object
32431refers to a local variable, the variable object becomes bound to the
32432thread and frame in which the variable object is created.  When such
32433variable object is updated, @value{GDBN} makes sure that the
32434thread/frame combination the variable object is bound to still exists,
32435and re-evaluates the variable object in context of that thread/frame.
32436
32437The following is the complete set of @sc{gdb/mi} operations defined to
32438access this functionality:
32439
32440@multitable @columnfractions .4 .6
32441@item @strong{Operation}
32442@tab @strong{Description}
32443
32444@item @code{-enable-pretty-printing}
32445@tab enable Python-based pretty-printing
32446@item @code{-var-create}
32447@tab create a variable object
32448@item @code{-var-delete}
32449@tab delete the variable object and/or its children
32450@item @code{-var-set-format}
32451@tab set the display format of this variable
32452@item @code{-var-show-format}
32453@tab show the display format of this variable
32454@item @code{-var-info-num-children}
32455@tab tells how many children this object has
32456@item @code{-var-list-children}
32457@tab return a list of the object's children
32458@item @code{-var-info-type}
32459@tab show the type of this variable object
32460@item @code{-var-info-expression}
32461@tab print parent-relative expression that this variable object represents
32462@item @code{-var-info-path-expression}
32463@tab print full expression that this variable object represents
32464@item @code{-var-show-attributes}
32465@tab is this variable editable? does it exist here?
32466@item @code{-var-evaluate-expression}
32467@tab get the value of this variable
32468@item @code{-var-assign}
32469@tab set the value of this variable
32470@item @code{-var-update}
32471@tab update the variable and its children
32472@item @code{-var-set-frozen}
32473@tab set frozenness attribute
32474@item @code{-var-set-update-range}
32475@tab set range of children to display on update
32476@end multitable
32477
32478In the next subsection we describe each operation in detail and suggest
32479how it can be used.
32480
32481@subheading Description And Use of Operations on Variable Objects
32482
32483@subheading The @code{-enable-pretty-printing} Command
32484@findex -enable-pretty-printing
32485
32486@smallexample
32487-enable-pretty-printing
32488@end smallexample
32489
32490@value{GDBN} allows Python-based visualizers to affect the output of the
32491MI variable object commands.  However, because there was no way to
32492implement this in a fully backward-compatible way, a front end must
32493request that this functionality be enabled.
32494
32495Once enabled, this feature cannot be disabled.
32496
32497Note that if Python support has not been compiled into @value{GDBN},
32498this command will still succeed (and do nothing).
32499
32500This feature is currently (as of @value{GDBN} 7.0) experimental, and
32501may work differently in future versions of @value{GDBN}.
32502
32503@subheading The @code{-var-create} Command
32504@findex -var-create
32505
32506@subsubheading Synopsis
32507
32508@smallexample
32509 -var-create @{@var{name} | "-"@}
32510    @{@var{frame-addr} | "*" | "@@"@} @var{expression}
32511@end smallexample
32512
32513This operation creates a variable object, which allows the monitoring of
32514a variable, the result of an expression, a memory cell or a CPU
32515register.
32516
32517The @var{name} parameter is the string by which the object can be
32518referenced.  It must be unique.  If @samp{-} is specified, the varobj
32519system will generate a string ``varNNNNNN'' automatically.  It will be
32520unique provided that one does not specify @var{name} of that format.
32521The command fails if a duplicate name is found.
32522
32523The frame under which the expression should be evaluated can be
32524specified by @var{frame-addr}.  A @samp{*} indicates that the current
32525frame should be used.  A @samp{@@} indicates that a floating variable
32526object must be created.
32527
32528@var{expression} is any expression valid on the current language set (must not
32529begin with a @samp{*}), or one of the following:
32530
32531@itemize @bullet
32532@item
32533@samp{*@var{addr}}, where @var{addr} is the address of a memory cell
32534
32535@item
32536@samp{*@var{addr}-@var{addr}} --- a memory address range (TBD)
32537
32538@item
32539@samp{$@var{regname}} --- a CPU register name
32540@end itemize
32541
32542@cindex dynamic varobj
32543A varobj's contents may be provided by a Python-based pretty-printer.  In this
32544case the varobj is known as a @dfn{dynamic varobj}.  Dynamic varobjs
32545have slightly different semantics in some cases.  If the
32546@code{-enable-pretty-printing} command is not sent, then @value{GDBN}
32547will never create a dynamic varobj.  This ensures backward
32548compatibility for existing clients.
32549
32550@subsubheading Result
32551
32552This operation returns attributes of the newly-created varobj.  These
32553are:
32554
32555@table @samp
32556@item name
32557The name of the varobj.
32558
32559@item numchild
32560The number of children of the varobj.  This number is not necessarily
32561reliable for a dynamic varobj.  Instead, you must examine the
32562@samp{has_more} attribute.
32563
32564@item value
32565The varobj's scalar value.  For a varobj whose type is some sort of
32566aggregate (e.g., a @code{struct}), or for a dynamic varobj, this value
32567will not be interesting.
32568
32569@item type
32570The varobj's type.  This is a string representation of the type, as
32571would be printed by the @value{GDBN} CLI.  If @samp{print object}
32572(@pxref{Print Settings, set print object}) is set to @code{on}, the
32573@emph{actual} (derived) type of the object is shown rather than the
32574@emph{declared} one.
32575
32576@item thread-id
32577If a variable object is bound to a specific thread, then this is the
32578thread's global identifier.
32579
32580@item has_more
32581For a dynamic varobj, this indicates whether there appear to be any
32582children available.  For a non-dynamic varobj, this will be 0.
32583
32584@item dynamic
32585This attribute will be present and have the value @samp{1} if the
32586varobj is a dynamic varobj.  If the varobj is not a dynamic varobj,
32587then this attribute will not be present.
32588
32589@item displayhint
32590A dynamic varobj can supply a display hint to the front end.  The
32591value comes directly from the Python pretty-printer object's
32592@code{display_hint} method.  @xref{Pretty Printing API}.
32593@end table
32594
32595Typical output will look like this:
32596
32597@smallexample
32598 name="@var{name}",numchild="@var{N}",type="@var{type}",thread-id="@var{M}",
32599  has_more="@var{has_more}"
32600@end smallexample
32601
32602
32603@subheading The @code{-var-delete} Command
32604@findex -var-delete
32605
32606@subsubheading Synopsis
32607
32608@smallexample
32609 -var-delete [ -c ] @var{name}
32610@end smallexample
32611
32612Deletes a previously created variable object and all of its children.
32613With the @samp{-c} option, just deletes the children.
32614
32615Returns an error if the object @var{name} is not found.
32616
32617
32618@subheading The @code{-var-set-format} Command
32619@findex -var-set-format
32620
32621@subsubheading Synopsis
32622
32623@smallexample
32624 -var-set-format @var{name} @var{format-spec}
32625@end smallexample
32626
32627Sets the output format for the value of the object @var{name} to be
32628@var{format-spec}.
32629
32630@anchor{-var-set-format}
32631The syntax for the @var{format-spec} is as follows:
32632
32633@smallexample
32634 @var{format-spec} @expansion{}
32635 @{binary | decimal | hexadecimal | octal | natural | zero-hexadecimal@}
32636@end smallexample
32637
32638The natural format is the default format choosen automatically
32639based on the variable type (like decimal for an @code{int}, hex
32640for pointers, etc.).
32641
32642The zero-hexadecimal format has a representation similar to hexadecimal
32643but with padding zeroes to the left of the value.  For example, a 32-bit
32644hexadecimal value of 0x1234 would be represented as 0x00001234 in the
32645zero-hexadecimal format.
32646
32647For a variable with children, the format is set only on the
32648variable itself, and the children are not affected.
32649
32650@subheading The @code{-var-show-format} Command
32651@findex -var-show-format
32652
32653@subsubheading Synopsis
32654
32655@smallexample
32656 -var-show-format @var{name}
32657@end smallexample
32658
32659Returns the format used to display the value of the object @var{name}.
32660
32661@smallexample
32662 @var{format} @expansion{}
32663 @var{format-spec}
32664@end smallexample
32665
32666
32667@subheading The @code{-var-info-num-children} Command
32668@findex -var-info-num-children
32669
32670@subsubheading Synopsis
32671
32672@smallexample
32673 -var-info-num-children @var{name}
32674@end smallexample
32675
32676Returns the number of children of a variable object @var{name}:
32677
32678@smallexample
32679 numchild=@var{n}
32680@end smallexample
32681
32682Note that this number is not completely reliable for a dynamic varobj.
32683It will return the current number of children, but more children may
32684be available.
32685
32686
32687@subheading The @code{-var-list-children} Command
32688@findex -var-list-children
32689
32690@subsubheading Synopsis
32691
32692@smallexample
32693 -var-list-children [@var{print-values}] @var{name} [@var{from} @var{to}]
32694@end smallexample
32695@anchor{-var-list-children}
32696
32697Return a list of the children of the specified variable object and
32698create variable objects for them, if they do not already exist.  With
32699a single argument or if @var{print-values} has a value of 0 or
32700@code{--no-values}, print only the names of the variables; if
32701@var{print-values} is 1 or @code{--all-values}, also print their
32702values; and if it is 2 or @code{--simple-values} print the name and
32703value for simple data types and just the name for arrays, structures
32704and unions.
32705
32706@var{from} and @var{to}, if specified, indicate the range of children
32707to report.  If @var{from} or @var{to} is less than zero, the range is
32708reset and all children will be reported.  Otherwise, children starting
32709at @var{from} (zero-based) and up to and excluding @var{to} will be
32710reported.
32711
32712If a child range is requested, it will only affect the current call to
32713@code{-var-list-children}, but not future calls to @code{-var-update}.
32714For this, you must instead use @code{-var-set-update-range}.  The
32715intent of this approach is to enable a front end to implement any
32716update approach it likes; for example, scrolling a view may cause the
32717front end to request more children with @code{-var-list-children}, and
32718then the front end could call @code{-var-set-update-range} with a
32719different range to ensure that future updates are restricted to just
32720the visible items.
32721
32722For each child the following results are returned:
32723
32724@table @var
32725
32726@item name
32727Name of the variable object created for this child.
32728
32729@item exp
32730The expression to be shown to the user by the front end to designate this child.
32731For example this may be the name of a structure member.
32732
32733For a dynamic varobj, this value cannot be used to form an
32734expression.  There is no way to do this at all with a dynamic varobj.
32735
32736For C/C@t{++} structures there are several pseudo children returned to
32737designate access qualifiers.  For these pseudo children @var{exp} is
32738@samp{public}, @samp{private}, or @samp{protected}.  In this case the
32739type and value are not present.
32740
32741A dynamic varobj will not report the access qualifying
32742pseudo-children, regardless of the language.  This information is not
32743available at all with a dynamic varobj.
32744
32745@item numchild
32746Number of children this child has.  For a dynamic varobj, this will be
327470.
32748
32749@item type
32750The type of the child.  If @samp{print object}
32751(@pxref{Print Settings, set print object}) is set to @code{on}, the
32752@emph{actual} (derived) type of the object is shown rather than the
32753@emph{declared} one.
32754
32755@item value
32756If values were requested, this is the value.
32757
32758@item thread-id
32759If this variable object is associated with a thread, this is the
32760thread's global thread id.  Otherwise this result is not present.
32761
32762@item frozen
32763If the variable object is frozen, this variable will be present with a value of 1.
32764
32765@item displayhint
32766A dynamic varobj can supply a display hint to the front end.  The
32767value comes directly from the Python pretty-printer object's
32768@code{display_hint} method.  @xref{Pretty Printing API}.
32769
32770@item dynamic
32771This attribute will be present and have the value @samp{1} if the
32772varobj is a dynamic varobj.  If the varobj is not a dynamic varobj,
32773then this attribute will not be present.
32774
32775@end table
32776
32777The result may have its own attributes:
32778
32779@table @samp
32780@item displayhint
32781A dynamic varobj can supply a display hint to the front end.  The
32782value comes directly from the Python pretty-printer object's
32783@code{display_hint} method.  @xref{Pretty Printing API}.
32784
32785@item has_more
32786This is an integer attribute which is nonzero if there are children
32787remaining after the end of the selected range.
32788@end table
32789
32790@subsubheading Example
32791
32792@smallexample
32793(gdb)
32794 -var-list-children n
32795 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
32796 numchild=@var{n},type=@var{type}@},@r{(repeats N times)}]
32797(gdb)
32798 -var-list-children --all-values n
32799 ^done,numchild=@var{n},children=[child=@{name=@var{name},exp=@var{exp},
32800 numchild=@var{n},value=@var{value},type=@var{type}@},@r{(repeats N times)}]
32801@end smallexample
32802
32803
32804@subheading The @code{-var-info-type} Command
32805@findex -var-info-type
32806
32807@subsubheading Synopsis
32808
32809@smallexample
32810 -var-info-type @var{name}
32811@end smallexample
32812
32813Returns the type of the specified variable @var{name}.  The type is
32814returned as a string in the same format as it is output by the
32815@value{GDBN} CLI:
32816
32817@smallexample
32818 type=@var{typename}
32819@end smallexample
32820
32821
32822@subheading The @code{-var-info-expression} Command
32823@findex -var-info-expression
32824
32825@subsubheading Synopsis
32826
32827@smallexample
32828 -var-info-expression @var{name}
32829@end smallexample
32830
32831Returns a string that is suitable for presenting this
32832variable object in user interface.  The string is generally
32833not valid expression in the current language, and cannot be evaluated.
32834
32835For example, if @code{a} is an array, and variable object
32836@code{A} was created for @code{a}, then we'll get this output:
32837
32838@smallexample
32839(gdb) -var-info-expression A.1
32840^done,lang="C",exp="1"
32841@end smallexample
32842
32843@noindent
32844Here, the value of @code{lang} is the language name, which can be
32845found in @ref{Supported Languages}.
32846
32847Note that the output of the @code{-var-list-children} command also
32848includes those expressions, so the @code{-var-info-expression} command
32849is of limited use.
32850
32851@subheading The @code{-var-info-path-expression} Command
32852@findex -var-info-path-expression
32853
32854@subsubheading Synopsis
32855
32856@smallexample
32857 -var-info-path-expression @var{name}
32858@end smallexample
32859
32860Returns an expression that can be evaluated in the current
32861context and will yield the same value that a variable object has.
32862Compare this with the @code{-var-info-expression} command, which
32863result can be used only for UI presentation.  Typical use of
32864the @code{-var-info-path-expression} command is creating a
32865watchpoint from a variable object.
32866
32867This command is currently not valid for children of a dynamic varobj,
32868and will give an error when invoked on one.
32869
32870For example, suppose @code{C} is a C@t{++} class, derived from class
32871@code{Base}, and that the @code{Base} class has a member called
32872@code{m_size}.  Assume a variable @code{c} is has the type of
32873@code{C} and a variable object @code{C} was created for variable
32874@code{c}.  Then, we'll get this output:
32875@smallexample
32876(gdb) -var-info-path-expression C.Base.public.m_size
32877^done,path_expr=((Base)c).m_size)
32878@end smallexample
32879
32880@subheading The @code{-var-show-attributes} Command
32881@findex -var-show-attributes
32882
32883@subsubheading Synopsis
32884
32885@smallexample
32886 -var-show-attributes @var{name}
32887@end smallexample
32888
32889List attributes of the specified variable object @var{name}:
32890
32891@smallexample
32892 status=@var{attr} [ ( ,@var{attr} )* ]
32893@end smallexample
32894
32895@noindent
32896where @var{attr} is @code{@{ @{ editable | noneditable @} | TBD @}}.
32897
32898@subheading The @code{-var-evaluate-expression} Command
32899@findex -var-evaluate-expression
32900
32901@subsubheading Synopsis
32902
32903@smallexample
32904 -var-evaluate-expression [-f @var{format-spec}] @var{name}
32905@end smallexample
32906
32907Evaluates the expression that is represented by the specified variable
32908object and returns its value as a string.  The format of the string
32909can be specified with the @samp{-f} option.  The possible values of
32910this option are the same as for @code{-var-set-format}
32911(@pxref{-var-set-format}).  If the @samp{-f} option is not specified,
32912the current display format will be used.  The current display format
32913can be changed using the @code{-var-set-format} command.
32914
32915@smallexample
32916 value=@var{value}
32917@end smallexample
32918
32919Note that one must invoke @code{-var-list-children} for a variable
32920before the value of a child variable can be evaluated.
32921
32922@subheading The @code{-var-assign} Command
32923@findex -var-assign
32924
32925@subsubheading Synopsis
32926
32927@smallexample
32928 -var-assign @var{name} @var{expression}
32929@end smallexample
32930
32931Assigns the value of @var{expression} to the variable object specified
32932by @var{name}.  The object must be @samp{editable}.  If the variable's
32933value is altered by the assign, the variable will show up in any
32934subsequent @code{-var-update} list.
32935
32936@subsubheading Example
32937
32938@smallexample
32939(gdb)
32940-var-assign var1 3
32941^done,value="3"
32942(gdb)
32943-var-update *
32944^done,changelist=[@{name="var1",in_scope="true",type_changed="false"@}]
32945(gdb)
32946@end smallexample
32947
32948@subheading The @code{-var-update} Command
32949@findex -var-update
32950
32951@subsubheading Synopsis
32952
32953@smallexample
32954 -var-update [@var{print-values}] @{@var{name} | "*"@}
32955@end smallexample
32956
32957Reevaluate the expressions corresponding to the variable object
32958@var{name} and all its direct and indirect children, and return the
32959list of variable objects whose values have changed; @var{name} must
32960be a root variable object.  Here, ``changed'' means that the result of
32961@code{-var-evaluate-expression} before and after the
32962@code{-var-update} is different.  If @samp{*} is used as the variable
32963object names, all existing variable objects are updated, except
32964for frozen ones (@pxref{-var-set-frozen}).  The option
32965@var{print-values} determines whether both names and values, or just
32966names are printed.  The possible values of this option are the same
32967as for @code{-var-list-children} (@pxref{-var-list-children}).  It is
32968recommended to use the @samp{--all-values} option, to reduce the
32969number of MI commands needed on each program stop.
32970
32971With the @samp{*} parameter, if a variable object is bound to a
32972currently running thread, it will not be updated, without any
32973diagnostic.
32974
32975If @code{-var-set-update-range} was previously used on a varobj, then
32976only the selected range of children will be reported.
32977
32978@code{-var-update} reports all the changed varobjs in a tuple named
32979@samp{changelist}.
32980
32981Each item in the change list is itself a tuple holding:
32982
32983@table @samp
32984@item name
32985The name of the varobj.
32986
32987@item value
32988If values were requested for this update, then this field will be
32989present and will hold the value of the varobj.
32990
32991@item in_scope
32992@anchor{-var-update}
32993This field is a string which may take one of three values:
32994
32995@table @code
32996@item "true"
32997The variable object's current value is valid.
32998
32999@item "false"
33000The variable object does not currently hold a valid value but it may
33001hold one in the future if its associated expression comes back into
33002scope.
33003
33004@item "invalid"
33005The variable object no longer holds a valid value.
33006This can occur when the executable file being debugged has changed,
33007either through recompilation or by using the @value{GDBN} @code{file}
33008command.  The front end should normally choose to delete these variable
33009objects.
33010@end table
33011
33012In the future new values may be added to this list so the front should
33013be prepared for this possibility.  @xref{GDB/MI Development and Front Ends, ,@sc{GDB/MI} Development and Front Ends}.
33014
33015@item type_changed
33016This is only present if the varobj is still valid.  If the type
33017changed, then this will be the string @samp{true}; otherwise it will
33018be @samp{false}.
33019
33020When a varobj's type changes, its children are also likely to have
33021become incorrect.  Therefore, the varobj's children are automatically
33022deleted when this attribute is @samp{true}.  Also, the varobj's update
33023range, when set using the @code{-var-set-update-range} command, is
33024unset.
33025
33026@item new_type
33027If the varobj's type changed, then this field will be present and will
33028hold the new type.
33029
33030@item new_num_children
33031For a dynamic varobj, if the number of children changed, or if the
33032type changed, this will be the new number of children.
33033
33034The @samp{numchild} field in other varobj responses is generally not
33035valid for a dynamic varobj -- it will show the number of children that
33036@value{GDBN} knows about, but because dynamic varobjs lazily
33037instantiate their children, this will not reflect the number of
33038children which may be available.
33039
33040The @samp{new_num_children} attribute only reports changes to the
33041number of children known by @value{GDBN}.  This is the only way to
33042detect whether an update has removed children (which necessarily can
33043only happen at the end of the update range).
33044
33045@item displayhint
33046The display hint, if any.
33047
33048@item has_more
33049This is an integer value, which will be 1 if there are more children
33050available outside the varobj's update range.
33051
33052@item dynamic
33053This attribute will be present and have the value @samp{1} if the
33054varobj is a dynamic varobj.  If the varobj is not a dynamic varobj,
33055then this attribute will not be present.
33056
33057@item new_children
33058If new children were added to a dynamic varobj within the selected
33059update range (as set by @code{-var-set-update-range}), then they will
33060be listed in this attribute.
33061@end table
33062
33063@subsubheading Example
33064
33065@smallexample
33066(gdb)
33067-var-assign var1 3
33068^done,value="3"
33069(gdb)
33070-var-update --all-values var1
33071^done,changelist=[@{name="var1",value="3",in_scope="true",
33072type_changed="false"@}]
33073(gdb)
33074@end smallexample
33075
33076@subheading The @code{-var-set-frozen} Command
33077@findex -var-set-frozen
33078@anchor{-var-set-frozen}
33079
33080@subsubheading Synopsis
33081
33082@smallexample
33083 -var-set-frozen @var{name} @var{flag}
33084@end smallexample
33085
33086Set the frozenness flag on the variable object @var{name}.  The
33087@var{flag} parameter should be either @samp{1} to make the variable
33088frozen or @samp{0} to make it unfrozen.  If a variable object is
33089frozen, then neither itself, nor any of its children, are
33090implicitly updated by @code{-var-update} of
33091a parent variable or by @code{-var-update *}.  Only
33092@code{-var-update} of the variable itself will update its value and
33093values of its children.  After a variable object is unfrozen, it is
33094implicitly updated by all subsequent @code{-var-update} operations.
33095Unfreezing a variable does not update it, only subsequent
33096@code{-var-update} does.
33097
33098@subsubheading Example
33099
33100@smallexample
33101(gdb)
33102-var-set-frozen V 1
33103^done
33104(gdb)
33105@end smallexample
33106
33107@subheading The @code{-var-set-update-range} command
33108@findex -var-set-update-range
33109@anchor{-var-set-update-range}
33110
33111@subsubheading Synopsis
33112
33113@smallexample
33114 -var-set-update-range @var{name} @var{from} @var{to}
33115@end smallexample
33116
33117Set the range of children to be returned by future invocations of
33118@code{-var-update}.
33119
33120@var{from} and @var{to} indicate the range of children to report.  If
33121@var{from} or @var{to} is less than zero, the range is reset and all
33122children will be reported.  Otherwise, children starting at @var{from}
33123(zero-based) and up to and excluding @var{to} will be reported.
33124
33125@subsubheading Example
33126
33127@smallexample
33128(gdb)
33129-var-set-update-range V 1 2
33130^done
33131@end smallexample
33132
33133@subheading The @code{-var-set-visualizer} command
33134@findex -var-set-visualizer
33135@anchor{-var-set-visualizer}
33136
33137@subsubheading Synopsis
33138
33139@smallexample
33140 -var-set-visualizer @var{name} @var{visualizer}
33141@end smallexample
33142
33143Set a visualizer for the variable object @var{name}.
33144
33145@var{visualizer} is the visualizer to use.  The special value
33146@samp{None} means to disable any visualizer in use.
33147
33148If not @samp{None}, @var{visualizer} must be a Python expression.
33149This expression must evaluate to a callable object which accepts a
33150single argument.  @value{GDBN} will call this object with the value of
33151the varobj @var{name} as an argument (this is done so that the same
33152Python pretty-printing code can be used for both the CLI and MI).
33153When called, this object must return an object which conforms to the
33154pretty-printing interface (@pxref{Pretty Printing API}).
33155
33156The pre-defined function @code{gdb.default_visualizer} may be used to
33157select a visualizer by following the built-in process
33158(@pxref{Selecting Pretty-Printers}).  This is done automatically when
33159a varobj is created, and so ordinarily is not needed.
33160
33161This feature is only available if Python support is enabled.  The MI
33162command @code{-list-features} (@pxref{GDB/MI Support Commands})
33163can be used to check this.
33164
33165@subsubheading Example
33166
33167Resetting the visualizer:
33168
33169@smallexample
33170(gdb)
33171-var-set-visualizer V None
33172^done
33173@end smallexample
33174
33175Reselecting the default (type-based) visualizer:
33176
33177@smallexample
33178(gdb)
33179-var-set-visualizer V gdb.default_visualizer
33180^done
33181@end smallexample
33182
33183Suppose @code{SomeClass} is a visualizer class.  A lambda expression
33184can be used to instantiate this class for a varobj:
33185
33186@smallexample
33187(gdb)
33188-var-set-visualizer V "lambda val: SomeClass()"
33189^done
33190@end smallexample
33191
33192@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33193@node GDB/MI Data Manipulation
33194@section @sc{gdb/mi} Data Manipulation
33195
33196@cindex data manipulation, in @sc{gdb/mi}
33197@cindex @sc{gdb/mi}, data manipulation
33198This section describes the @sc{gdb/mi} commands that manipulate data:
33199examine memory and registers, evaluate expressions, etc.
33200
33201For details about what an addressable memory unit is,
33202@pxref{addressable memory unit}.
33203
33204@c REMOVED FROM THE INTERFACE.
33205@c @subheading -data-assign
33206@c Change the value of a program variable. Plenty of side effects.
33207@c @subsubheading GDB Command
33208@c set variable
33209@c @subsubheading Example
33210@c N.A.
33211
33212@subheading The @code{-data-disassemble} Command
33213@findex -data-disassemble
33214
33215@subsubheading Synopsis
33216
33217@smallexample
33218 -data-disassemble
33219    [ -s @var{start-addr} -e @var{end-addr} ]
33220  | [ -a @var{addr} ]
33221  | [ -f @var{filename} -l @var{linenum} [ -n @var{lines} ] ]
33222  -- @var{mode}
33223@end smallexample
33224
33225@noindent
33226Where:
33227
33228@table @samp
33229@item @var{start-addr}
33230is the beginning address (or @code{$pc})
33231@item @var{end-addr}
33232is the end address
33233@item @var{addr}
33234is an address anywhere within (or the name of) the function to
33235disassemble.  If an address is specified, the whole function
33236surrounding that address will be disassembled.  If a name is
33237specified, the whole function with that name will be disassembled.
33238@item @var{filename}
33239is the name of the file to disassemble
33240@item @var{linenum}
33241is the line number to disassemble around
33242@item @var{lines}
33243is the number of disassembly lines to be produced.  If it is -1,
33244the whole function will be disassembled, in case no @var{end-addr} is
33245specified.  If @var{end-addr} is specified as a non-zero value, and
33246@var{lines} is lower than the number of disassembly lines between
33247@var{start-addr} and @var{end-addr}, only @var{lines} lines are
33248displayed; if @var{lines} is higher than the number of lines between
33249@var{start-addr} and @var{end-addr}, only the lines up to @var{end-addr}
33250are displayed.
33251@item @var{mode}
33252is one of:
33253@itemize @bullet
33254@item 0 disassembly only
33255@item 1 mixed source and disassembly (deprecated)
33256@item 2 disassembly with raw opcodes
33257@item 3 mixed source and disassembly with raw opcodes (deprecated)
33258@item 4 mixed source and disassembly
33259@item 5 mixed source and disassembly with raw opcodes
33260@end itemize
33261
33262Modes 1 and 3 are deprecated.  The output is ``source centric''
33263which hasn't proved useful in practice.
33264@xref{Machine Code}, for a discussion of the difference between
33265@code{/m} and @code{/s} output of the @code{disassemble} command.
33266@end table
33267
33268@subsubheading Result
33269
33270The result of the @code{-data-disassemble} command will be a list named
33271@samp{asm_insns}, the contents of this list depend on the @var{mode}
33272used with the @code{-data-disassemble} command.
33273
33274For modes 0 and 2 the @samp{asm_insns} list contains tuples with the
33275following fields:
33276
33277@table @code
33278@item address
33279The address at which this instruction was disassembled.
33280
33281@item func-name
33282The name of the function this instruction is within.
33283
33284@item offset
33285The decimal offset in bytes from the start of @samp{func-name}.
33286
33287@item inst
33288The text disassembly for this @samp{address}.
33289
33290@item opcodes
33291This field is only present for modes 2, 3 and 5.  This contains the raw opcode
33292bytes for the @samp{inst} field.
33293
33294@end table
33295
33296For modes 1, 3, 4 and 5 the @samp{asm_insns} list contains tuples named
33297@samp{src_and_asm_line}, each of which has the following fields:
33298
33299@table @code
33300@item line
33301The line number within @samp{file}.
33302
33303@item file
33304The file name from the compilation unit.  This might be an absolute
33305file name or a relative file name depending on the compile command
33306used.
33307
33308@item fullname
33309Absolute file name of @samp{file}.  It is converted to a canonical form
33310using the source file search path
33311(@pxref{Source Path, ,Specifying Source Directories})
33312and after resolving all the symbolic links.
33313
33314If the source file is not found this field will contain the path as
33315present in the debug information.
33316
33317@item line_asm_insn
33318This is a list of tuples containing the disassembly for @samp{line} in
33319@samp{file}.  The fields of each tuple are the same as for
33320@code{-data-disassemble} in @var{mode} 0 and 2, so @samp{address},
33321@samp{func-name}, @samp{offset}, @samp{inst}, and optionally
33322@samp{opcodes}.
33323
33324@end table
33325
33326Note that whatever included in the @samp{inst} field, is not
33327manipulated directly by @sc{gdb/mi}, i.e., it is not possible to
33328adjust its format.
33329
33330@subsubheading @value{GDBN} Command
33331
33332The corresponding @value{GDBN} command is @samp{disassemble}.
33333
33334@subsubheading Example
33335
33336Disassemble from the current value of @code{$pc} to @code{$pc + 20}:
33337
33338@smallexample
33339(gdb)
33340-data-disassemble -s $pc -e "$pc + 20" -- 0
33341^done,
33342asm_insns=[
33343@{address="0x000107c0",func-name="main",offset="4",
33344inst="mov  2, %o0"@},
33345@{address="0x000107c4",func-name="main",offset="8",
33346inst="sethi  %hi(0x11800), %o2"@},
33347@{address="0x000107c8",func-name="main",offset="12",
33348inst="or  %o2, 0x140, %o1\t! 0x11940 <_lib_version+8>"@},
33349@{address="0x000107cc",func-name="main",offset="16",
33350inst="sethi  %hi(0x11800), %o2"@},
33351@{address="0x000107d0",func-name="main",offset="20",
33352inst="or  %o2, 0x168, %o4\t! 0x11968 <_lib_version+48>"@}]
33353(gdb)
33354@end smallexample
33355
33356Disassemble the whole @code{main} function.  Line 32 is part of
33357@code{main}.
33358
33359@smallexample
33360-data-disassemble -f basics.c -l 32 -- 0
33361^done,asm_insns=[
33362@{address="0x000107bc",func-name="main",offset="0",
33363inst="save  %sp, -112, %sp"@},
33364@{address="0x000107c0",func-name="main",offset="4",
33365inst="mov   2, %o0"@},
33366@{address="0x000107c4",func-name="main",offset="8",
33367inst="sethi %hi(0x11800), %o2"@},
33368[@dots{}]
33369@{address="0x0001081c",func-name="main",offset="96",inst="ret "@},
33370@{address="0x00010820",func-name="main",offset="100",inst="restore "@}]
33371(gdb)
33372@end smallexample
33373
33374Disassemble 3 instructions from the start of @code{main}:
33375
33376@smallexample
33377(gdb)
33378-data-disassemble -f basics.c -l 32 -n 3 -- 0
33379^done,asm_insns=[
33380@{address="0x000107bc",func-name="main",offset="0",
33381inst="save  %sp, -112, %sp"@},
33382@{address="0x000107c0",func-name="main",offset="4",
33383inst="mov  2, %o0"@},
33384@{address="0x000107c4",func-name="main",offset="8",
33385inst="sethi  %hi(0x11800), %o2"@}]
33386(gdb)
33387@end smallexample
33388
33389Disassemble 3 instructions from the start of @code{main} in mixed mode:
33390
33391@smallexample
33392(gdb)
33393-data-disassemble -f basics.c -l 32 -n 3 -- 1
33394^done,asm_insns=[
33395src_and_asm_line=@{line="31",
33396file="../../../src/gdb/testsuite/gdb.mi/basics.c",
33397fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
33398line_asm_insn=[@{address="0x000107bc",
33399func-name="main",offset="0",inst="save  %sp, -112, %sp"@}]@},
33400src_and_asm_line=@{line="32",
33401file="../../../src/gdb/testsuite/gdb.mi/basics.c",
33402fullname="/absolute/path/to/src/gdb/testsuite/gdb.mi/basics.c",
33403line_asm_insn=[@{address="0x000107c0",
33404func-name="main",offset="4",inst="mov  2, %o0"@},
33405@{address="0x000107c4",func-name="main",offset="8",
33406inst="sethi  %hi(0x11800), %o2"@}]@}]
33407(gdb)
33408@end smallexample
33409
33410
33411@subheading The @code{-data-evaluate-expression} Command
33412@findex -data-evaluate-expression
33413
33414@subsubheading Synopsis
33415
33416@smallexample
33417 -data-evaluate-expression @var{expr}
33418@end smallexample
33419
33420Evaluate @var{expr} as an expression.  The expression could contain an
33421inferior function call.  The function call will execute synchronously.
33422If the expression contains spaces, it must be enclosed in double quotes.
33423
33424@subsubheading @value{GDBN} Command
33425
33426The corresponding @value{GDBN} commands are @samp{print}, @samp{output}, and
33427@samp{call}.  In @code{gdbtk} only, there's a corresponding
33428@samp{gdb_eval} command.
33429
33430@subsubheading Example
33431
33432In the following example, the numbers that precede the commands are the
33433@dfn{tokens} described in @ref{GDB/MI Command Syntax, ,@sc{gdb/mi}
33434Command Syntax}.  Notice how @sc{gdb/mi} returns the same tokens in its
33435output.
33436
33437@smallexample
33438211-data-evaluate-expression A
33439211^done,value="1"
33440(gdb)
33441311-data-evaluate-expression &A
33442311^done,value="0xefffeb7c"
33443(gdb)
33444411-data-evaluate-expression A+3
33445411^done,value="4"
33446(gdb)
33447511-data-evaluate-expression "A + 3"
33448511^done,value="4"
33449(gdb)
33450@end smallexample
33451
33452
33453@subheading The @code{-data-list-changed-registers} Command
33454@findex -data-list-changed-registers
33455
33456@subsubheading Synopsis
33457
33458@smallexample
33459 -data-list-changed-registers
33460@end smallexample
33461
33462Display a list of the registers that have changed.
33463
33464@subsubheading @value{GDBN} Command
33465
33466@value{GDBN} doesn't have a direct analog for this command; @code{gdbtk}
33467has the corresponding command @samp{gdb_changed_register_list}.
33468
33469@subsubheading Example
33470
33471On a PPC MBX board:
33472
33473@smallexample
33474(gdb)
33475-exec-continue
33476^running
33477
33478(gdb)
33479*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",frame=@{
33480func="main",args=[],file="try.c",fullname="/home/foo/bar/try.c",
33481line="5",arch="powerpc"@}
33482(gdb)
33483-data-list-changed-registers
33484^done,changed-registers=["0","1","2","4","5","6","7","8","9",
33485"10","11","13","14","15","16","17","18","19","20","21","22","23",
33486"24","25","26","27","28","30","31","64","65","66","67","69"]
33487(gdb)
33488@end smallexample
33489
33490
33491@subheading The @code{-data-list-register-names} Command
33492@findex -data-list-register-names
33493
33494@subsubheading Synopsis
33495
33496@smallexample
33497 -data-list-register-names [ ( @var{regno} )+ ]
33498@end smallexample
33499
33500Show a list of register names for the current target.  If no arguments
33501are given, it shows a list of the names of all the registers.  If
33502integer numbers are given as arguments, it will print a list of the
33503names of the registers corresponding to the arguments.  To ensure
33504consistency between a register name and its number, the output list may
33505include empty register names.
33506
33507@subsubheading @value{GDBN} Command
33508
33509@value{GDBN} does not have a command which corresponds to
33510@samp{-data-list-register-names}.  In @code{gdbtk} there is a
33511corresponding command @samp{gdb_regnames}.
33512
33513@subsubheading Example
33514
33515For the PPC MBX board:
33516@smallexample
33517(gdb)
33518-data-list-register-names
33519^done,register-names=["r0","r1","r2","r3","r4","r5","r6","r7",
33520"r8","r9","r10","r11","r12","r13","r14","r15","r16","r17","r18",
33521"r19","r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
33522"r30","r31","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9",
33523"f10","f11","f12","f13","f14","f15","f16","f17","f18","f19","f20",
33524"f21","f22","f23","f24","f25","f26","f27","f28","f29","f30","f31",
33525"", "pc","ps","cr","lr","ctr","xer"]
33526(gdb)
33527-data-list-register-names 1 2 3
33528^done,register-names=["r1","r2","r3"]
33529(gdb)
33530@end smallexample
33531
33532@subheading The @code{-data-list-register-values} Command
33533@findex -data-list-register-values
33534
33535@subsubheading Synopsis
33536
33537@smallexample
33538 -data-list-register-values
33539    [ @code{--skip-unavailable} ] @var{fmt} [ ( @var{regno} )*]
33540@end smallexample
33541
33542Display the registers' contents.  The format according to which the
33543registers' contents are to be returned is given by @var{fmt}, followed
33544by an optional list of numbers specifying the registers to display.  A
33545missing list of numbers indicates that the contents of all the
33546registers must be returned.  The @code{--skip-unavailable} option
33547indicates that only the available registers are to be returned.
33548
33549Allowed formats for @var{fmt} are:
33550
33551@table @code
33552@item x
33553Hexadecimal
33554@item o
33555Octal
33556@item t
33557Binary
33558@item d
33559Decimal
33560@item r
33561Raw
33562@item N
33563Natural
33564@end table
33565
33566@subsubheading @value{GDBN} Command
33567
33568The corresponding @value{GDBN} commands are @samp{info reg}, @samp{info
33569all-reg}, and (in @code{gdbtk}) @samp{gdb_fetch_registers}.
33570
33571@subsubheading Example
33572
33573For a PPC MBX board (note: line breaks are for readability only, they
33574don't appear in the actual output):
33575
33576@smallexample
33577(gdb)
33578-data-list-register-values r 64 65
33579^done,register-values=[@{number="64",value="0xfe00a300"@},
33580@{number="65",value="0x00029002"@}]
33581(gdb)
33582-data-list-register-values x
33583^done,register-values=[@{number="0",value="0xfe0043c8"@},
33584@{number="1",value="0x3fff88"@},@{number="2",value="0xfffffffe"@},
33585@{number="3",value="0x0"@},@{number="4",value="0xa"@},
33586@{number="5",value="0x3fff68"@},@{number="6",value="0x3fff58"@},
33587@{number="7",value="0xfe011e98"@},@{number="8",value="0x2"@},
33588@{number="9",value="0xfa202820"@},@{number="10",value="0xfa202808"@},
33589@{number="11",value="0x1"@},@{number="12",value="0x0"@},
33590@{number="13",value="0x4544"@},@{number="14",value="0xffdfffff"@},
33591@{number="15",value="0xffffffff"@},@{number="16",value="0xfffffeff"@},
33592@{number="17",value="0xefffffed"@},@{number="18",value="0xfffffffe"@},
33593@{number="19",value="0xffffffff"@},@{number="20",value="0xffffffff"@},
33594@{number="21",value="0xffffffff"@},@{number="22",value="0xfffffff7"@},
33595@{number="23",value="0xffffffff"@},@{number="24",value="0xffffffff"@},
33596@{number="25",value="0xffffffff"@},@{number="26",value="0xfffffffb"@},
33597@{number="27",value="0xffffffff"@},@{number="28",value="0xf7bfffff"@},
33598@{number="29",value="0x0"@},@{number="30",value="0xfe010000"@},
33599@{number="31",value="0x0"@},@{number="32",value="0x0"@},
33600@{number="33",value="0x0"@},@{number="34",value="0x0"@},
33601@{number="35",value="0x0"@},@{number="36",value="0x0"@},
33602@{number="37",value="0x0"@},@{number="38",value="0x0"@},
33603@{number="39",value="0x0"@},@{number="40",value="0x0"@},
33604@{number="41",value="0x0"@},@{number="42",value="0x0"@},
33605@{number="43",value="0x0"@},@{number="44",value="0x0"@},
33606@{number="45",value="0x0"@},@{number="46",value="0x0"@},
33607@{number="47",value="0x0"@},@{number="48",value="0x0"@},
33608@{number="49",value="0x0"@},@{number="50",value="0x0"@},
33609@{number="51",value="0x0"@},@{number="52",value="0x0"@},
33610@{number="53",value="0x0"@},@{number="54",value="0x0"@},
33611@{number="55",value="0x0"@},@{number="56",value="0x0"@},
33612@{number="57",value="0x0"@},@{number="58",value="0x0"@},
33613@{number="59",value="0x0"@},@{number="60",value="0x0"@},
33614@{number="61",value="0x0"@},@{number="62",value="0x0"@},
33615@{number="63",value="0x0"@},@{number="64",value="0xfe00a300"@},
33616@{number="65",value="0x29002"@},@{number="66",value="0x202f04b5"@},
33617@{number="67",value="0xfe0043b0"@},@{number="68",value="0xfe00b3e4"@},
33618@{number="69",value="0x20002b03"@}]
33619(gdb)
33620@end smallexample
33621
33622
33623@subheading The @code{-data-read-memory} Command
33624@findex -data-read-memory
33625
33626This command is deprecated, use @code{-data-read-memory-bytes} instead.
33627
33628@subsubheading Synopsis
33629
33630@smallexample
33631 -data-read-memory [ -o @var{byte-offset} ]
33632   @var{address} @var{word-format} @var{word-size}
33633   @var{nr-rows} @var{nr-cols} [ @var{aschar} ]
33634@end smallexample
33635
33636@noindent
33637where:
33638
33639@table @samp
33640@item @var{address}
33641An expression specifying the address of the first memory word to be
33642read.  Complex expressions containing embedded white space should be
33643quoted using the C convention.
33644
33645@item @var{word-format}
33646The format to be used to print the memory words.  The notation is the
33647same as for @value{GDBN}'s @code{print} command (@pxref{Output Formats,
33648,Output Formats}).
33649
33650@item @var{word-size}
33651The size of each memory word in bytes.
33652
33653@item @var{nr-rows}
33654The number of rows in the output table.
33655
33656@item @var{nr-cols}
33657The number of columns in the output table.
33658
33659@item @var{aschar}
33660If present, indicates that each row should include an @sc{ascii} dump.  The
33661value of @var{aschar} is used as a padding character when a byte is not a
33662member of the printable @sc{ascii} character set (printable @sc{ascii}
33663characters are those whose code is between 32 and 126, inclusively).
33664
33665@item @var{byte-offset}
33666An offset to add to the @var{address} before fetching memory.
33667@end table
33668
33669This command displays memory contents as a table of @var{nr-rows} by
33670@var{nr-cols} words, each word being @var{word-size} bytes.  In total,
33671@code{@var{nr-rows} * @var{nr-cols} * @var{word-size}} bytes are read
33672(returned as @samp{total-bytes}).  Should less than the requested number
33673of bytes be returned by the target, the missing words are identified
33674using @samp{N/A}.  The number of bytes read from the target is returned
33675in @samp{nr-bytes} and the starting address used to read memory in
33676@samp{addr}.
33677
33678The address of the next/previous row or page is available in
33679@samp{next-row} and @samp{prev-row}, @samp{next-page} and
33680@samp{prev-page}.
33681
33682@subsubheading @value{GDBN} Command
33683
33684The corresponding @value{GDBN} command is @samp{x}.  @code{gdbtk} has
33685@samp{gdb_get_mem} memory read command.
33686
33687@subsubheading Example
33688
33689Read six bytes of memory starting at @code{bytes+6} but then offset by
33690@code{-6} bytes.  Format as three rows of two columns.  One byte per
33691word.  Display each word in hex.
33692
33693@smallexample
33694(gdb)
336959-data-read-memory -o -6 -- bytes+6 x 1 3 2
336969^done,addr="0x00001390",nr-bytes="6",total-bytes="6",
33697next-row="0x00001396",prev-row="0x0000138e",next-page="0x00001396",
33698prev-page="0x0000138a",memory=[
33699@{addr="0x00001390",data=["0x00","0x01"]@},
33700@{addr="0x00001392",data=["0x02","0x03"]@},
33701@{addr="0x00001394",data=["0x04","0x05"]@}]
33702(gdb)
33703@end smallexample
33704
33705Read two bytes of memory starting at address @code{shorts + 64} and
33706display as a single word formatted in decimal.
33707
33708@smallexample
33709(gdb)
337105-data-read-memory shorts+64 d 2 1 1
337115^done,addr="0x00001510",nr-bytes="2",total-bytes="2",
33712next-row="0x00001512",prev-row="0x0000150e",
33713next-page="0x00001512",prev-page="0x0000150e",memory=[
33714@{addr="0x00001510",data=["128"]@}]
33715(gdb)
33716@end smallexample
33717
33718Read thirty two bytes of memory starting at @code{bytes+16} and format
33719as eight rows of four columns.  Include a string encoding with @samp{x}
33720used as the non-printable character.
33721
33722@smallexample
33723(gdb)
337244-data-read-memory bytes+16 x 1 8 4 x
337254^done,addr="0x000013a0",nr-bytes="32",total-bytes="32",
33726next-row="0x000013c0",prev-row="0x0000139c",
33727next-page="0x000013c0",prev-page="0x00001380",memory=[
33728@{addr="0x000013a0",data=["0x10","0x11","0x12","0x13"],ascii="xxxx"@},
33729@{addr="0x000013a4",data=["0x14","0x15","0x16","0x17"],ascii="xxxx"@},
33730@{addr="0x000013a8",data=["0x18","0x19","0x1a","0x1b"],ascii="xxxx"@},
33731@{addr="0x000013ac",data=["0x1c","0x1d","0x1e","0x1f"],ascii="xxxx"@},
33732@{addr="0x000013b0",data=["0x20","0x21","0x22","0x23"],ascii=" !\"#"@},
33733@{addr="0x000013b4",data=["0x24","0x25","0x26","0x27"],ascii="$%&'"@},
33734@{addr="0x000013b8",data=["0x28","0x29","0x2a","0x2b"],ascii="()*+"@},
33735@{addr="0x000013bc",data=["0x2c","0x2d","0x2e","0x2f"],ascii=",-./"@}]
33736(gdb)
33737@end smallexample
33738
33739@subheading The @code{-data-read-memory-bytes} Command
33740@findex -data-read-memory-bytes
33741
33742@subsubheading Synopsis
33743
33744@smallexample
33745 -data-read-memory-bytes [ -o @var{offset} ]
33746   @var{address} @var{count}
33747@end smallexample
33748
33749@noindent
33750where:
33751
33752@table @samp
33753@item @var{address}
33754An expression specifying the address of the first addressable memory unit
33755to be read.  Complex expressions containing embedded white space should be
33756quoted using the C convention.
33757
33758@item @var{count}
33759The number of addressable memory units to read.  This should be an integer
33760literal.
33761
33762@item @var{offset}
33763The offset relative to @var{address} at which to start reading.  This
33764should be an integer literal.  This option is provided so that a frontend
33765is not required to first evaluate address and then perform address
33766arithmetics itself.
33767
33768@end table
33769
33770This command attempts to read all accessible memory regions in the
33771specified range.  First, all regions marked as unreadable in the memory
33772map (if one is defined) will be skipped.  @xref{Memory Region
33773Attributes}.  Second, @value{GDBN} will attempt to read the remaining
33774regions.  For each one, if reading full region results in an errors,
33775@value{GDBN} will try to read a subset of the region.
33776
33777In general, every single memory unit in the region may be readable or not,
33778and the only way to read every readable unit is to try a read at
33779every address, which is not practical.   Therefore, @value{GDBN} will
33780attempt to read all accessible memory units at either beginning or the end
33781of the region, using a binary division scheme.  This heuristic works
33782well for reading across a memory map boundary.  Note that if a region
33783has a readable range that is neither at the beginning or the end,
33784@value{GDBN} will not read it.
33785
33786The result record (@pxref{GDB/MI Result Records}) that is output of
33787the command includes a field named @samp{memory} whose content is a
33788list of tuples.  Each tuple represent a successfully read memory block
33789and has the following fields:
33790
33791@table @code
33792@item begin
33793The start address of the memory block, as hexadecimal literal.
33794
33795@item end
33796The end address of the memory block, as hexadecimal literal.
33797
33798@item offset
33799The offset of the memory block, as hexadecimal literal, relative to
33800the start address passed to @code{-data-read-memory-bytes}.
33801
33802@item contents
33803The contents of the memory block, in hex.
33804
33805@end table
33806
33807
33808
33809@subsubheading @value{GDBN} Command
33810
33811The corresponding @value{GDBN} command is @samp{x}.
33812
33813@subsubheading Example
33814
33815@smallexample
33816(gdb)
33817-data-read-memory-bytes &a 10
33818^done,memory=[@{begin="0xbffff154",offset="0x00000000",
33819              end="0xbffff15e",
33820              contents="01000000020000000300"@}]
33821(gdb)
33822@end smallexample
33823
33824
33825@subheading The @code{-data-write-memory-bytes} Command
33826@findex -data-write-memory-bytes
33827
33828@subsubheading Synopsis
33829
33830@smallexample
33831 -data-write-memory-bytes @var{address} @var{contents}
33832 -data-write-memory-bytes @var{address} @var{contents} @r{[}@var{count}@r{]}
33833@end smallexample
33834
33835@noindent
33836where:
33837
33838@table @samp
33839@item @var{address}
33840An expression specifying the address of the first addressable memory unit
33841to be written.  Complex expressions containing embedded white space should
33842be quoted using the C convention.
33843
33844@item @var{contents}
33845The hex-encoded data to write.  It is an error if @var{contents} does
33846not represent an integral number of addressable memory units.
33847
33848@item @var{count}
33849Optional argument indicating the number of addressable memory units to be
33850written.  If @var{count} is greater than @var{contents}' length,
33851@value{GDBN} will repeatedly write @var{contents} until it fills
33852@var{count} memory units.
33853
33854@end table
33855
33856@subsubheading @value{GDBN} Command
33857
33858There's no corresponding @value{GDBN} command.
33859
33860@subsubheading Example
33861
33862@smallexample
33863(gdb)
33864-data-write-memory-bytes &a "aabbccdd"
33865^done
33866(gdb)
33867@end smallexample
33868
33869@smallexample
33870(gdb)
33871-data-write-memory-bytes &a "aabbccdd" 16e
33872^done
33873(gdb)
33874@end smallexample
33875
33876@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33877@node GDB/MI Tracepoint Commands
33878@section @sc{gdb/mi} Tracepoint Commands
33879
33880The commands defined in this section implement MI support for
33881tracepoints.  For detailed introduction, see @ref{Tracepoints}.
33882
33883@subheading The @code{-trace-find} Command
33884@findex -trace-find
33885
33886@subsubheading Synopsis
33887
33888@smallexample
33889 -trace-find @var{mode} [@var{parameters}@dots{}]
33890@end smallexample
33891
33892Find a trace frame using criteria defined by @var{mode} and
33893@var{parameters}.  The following table lists permissible
33894modes and their parameters.  For details of operation, see @ref{tfind}.
33895
33896@table @samp
33897
33898@item none
33899No parameters are required.  Stops examining trace frames.
33900
33901@item frame-number
33902An integer is required as parameter.  Selects tracepoint frame with
33903that index.
33904
33905@item tracepoint-number
33906An integer is required as parameter.  Finds next
33907trace frame that corresponds to tracepoint with the specified number.
33908
33909@item pc
33910An address is required as parameter.  Finds
33911next trace frame that corresponds to any tracepoint at the specified
33912address.
33913
33914@item pc-inside-range
33915Two addresses are required as parameters.  Finds next trace
33916frame that corresponds to a tracepoint at an address inside the
33917specified range.  Both bounds are considered to be inside the range.
33918
33919@item pc-outside-range
33920Two addresses are required as parameters.  Finds
33921next trace frame that corresponds to a tracepoint at an address outside
33922the specified range.  Both bounds are considered to be inside the range.
33923
33924@item line
33925Line specification is required as parameter.  @xref{Specify Location}.
33926Finds next trace frame that corresponds to a tracepoint at
33927the specified location.
33928
33929@end table
33930
33931If @samp{none} was passed as @var{mode}, the response does not
33932have fields.  Otherwise, the response may have the following fields:
33933
33934@table @samp
33935@item found
33936This field has either @samp{0} or @samp{1} as the value, depending
33937on whether a matching tracepoint was found.
33938
33939@item traceframe
33940The index of the found traceframe.  This field is present iff
33941the @samp{found} field has value of @samp{1}.
33942
33943@item tracepoint
33944The index of the found tracepoint.  This field is present iff
33945the @samp{found} field has value of @samp{1}.
33946
33947@item frame
33948The information about the frame corresponding to the found trace
33949frame.  This field is present only if a trace frame was found.
33950@xref{GDB/MI Frame Information}, for description of this field.
33951
33952@end table
33953
33954@subsubheading @value{GDBN} Command
33955
33956The corresponding @value{GDBN} command is @samp{tfind}.
33957
33958@subheading -trace-define-variable
33959@findex -trace-define-variable
33960
33961@subsubheading Synopsis
33962
33963@smallexample
33964 -trace-define-variable @var{name} [ @var{value} ]
33965@end smallexample
33966
33967Create trace variable @var{name} if it does not exist.  If
33968@var{value} is specified, sets the initial value of the specified
33969trace variable to that value.  Note that the @var{name} should start
33970with the @samp{$} character.
33971
33972@subsubheading @value{GDBN} Command
33973
33974The corresponding @value{GDBN} command is @samp{tvariable}.
33975
33976@subheading The @code{-trace-frame-collected} Command
33977@findex -trace-frame-collected
33978
33979@subsubheading Synopsis
33980
33981@smallexample
33982 -trace-frame-collected
33983    [--var-print-values @var{var_pval}]
33984    [--comp-print-values @var{comp_pval}]
33985    [--registers-format @var{regformat}]
33986    [--memory-contents]
33987@end smallexample
33988
33989This command returns the set of collected objects, register names,
33990trace state variable names, memory ranges and computed expressions
33991that have been collected at a particular trace frame.  The optional
33992parameters to the command affect the output format in different ways.
33993See the output description table below for more details.
33994
33995The reported names can be used in the normal manner to create
33996varobjs and inspect the objects themselves.  The items returned by
33997this command are categorized so that it is clear which is a variable,
33998which is a register, which is a trace state variable, which is a
33999memory range and which is a computed expression.
34000
34001For instance, if the actions were
34002@smallexample
34003collect myVar, myArray[myIndex], myObj.field, myPtr->field, myCount + 2
34004collect *(int*)0xaf02bef0@@40
34005@end smallexample
34006
34007@noindent
34008the object collected in its entirety would be @code{myVar}.  The
34009object @code{myArray} would be partially collected, because only the
34010element at index @code{myIndex} would be collected.  The remaining
34011objects would be computed expressions.
34012
34013An example output would be:
34014
34015@smallexample
34016(gdb)
34017-trace-frame-collected
34018^done,
34019  explicit-variables=[@{name="myVar",value="1"@}],
34020  computed-expressions=[@{name="myArray[myIndex]",value="0"@},
34021                        @{name="myObj.field",value="0"@},
34022                        @{name="myPtr->field",value="1"@},
34023                        @{name="myCount + 2",value="3"@},
34024                        @{name="$tvar1 + 1",value="43970027"@}],
34025  registers=[@{number="0",value="0x7fe2c6e79ec8"@},
34026             @{number="1",value="0x0"@},
34027             @{number="2",value="0x4"@},
34028             ...
34029             @{number="125",value="0x0"@}],
34030  tvars=[@{name="$tvar1",current="43970026"@}],
34031  memory=[@{address="0x0000000000602264",length="4"@},
34032          @{address="0x0000000000615bc0",length="4"@}]
34033(gdb)
34034@end smallexample
34035
34036Where:
34037
34038@table @code
34039@item explicit-variables
34040The set of objects that have been collected in their entirety (as
34041opposed to collecting just a few elements of an array or a few struct
34042members).  For each object, its name and value are printed.
34043The @code{--var-print-values} option affects how or whether the value
34044field is output.  If @var{var_pval} is 0, then print only the names;
34045if it is 1, print also their values; and if it is 2, print the name,
34046type and value for simple data types, and the name and type for
34047arrays, structures and unions.
34048
34049@item computed-expressions
34050The set of computed expressions that have been collected at the
34051current trace frame.  The @code{--comp-print-values} option affects
34052this set like the @code{--var-print-values} option affects the
34053@code{explicit-variables} set.  See above.
34054
34055@item registers
34056The registers that have been collected at the current trace frame.
34057For each register collected, the name and current value are returned.
34058The value is formatted according to the @code{--registers-format}
34059option.  See the @command{-data-list-register-values} command for a
34060list of the allowed formats.  The default is @samp{x}.
34061
34062@item tvars
34063The trace state variables that have been collected at the current
34064trace frame.  For each trace state variable collected, the name and
34065current value are returned.
34066
34067@item memory
34068The set of memory ranges that have been collected at the current trace
34069frame.  Its content is a list of tuples.  Each tuple represents a
34070collected memory range and has the following fields:
34071
34072@table @code
34073@item address
34074The start address of the memory range, as hexadecimal literal.
34075
34076@item length
34077The length of the memory range, as decimal literal.
34078
34079@item contents
34080The contents of the memory block, in hex.  This field is only present
34081if the @code{--memory-contents} option is specified.
34082
34083@end table
34084
34085@end table
34086
34087@subsubheading @value{GDBN} Command
34088
34089There is no corresponding @value{GDBN} command.
34090
34091@subsubheading Example
34092
34093@subheading -trace-list-variables
34094@findex -trace-list-variables
34095
34096@subsubheading Synopsis
34097
34098@smallexample
34099 -trace-list-variables
34100@end smallexample
34101
34102Return a table of all defined trace variables.  Each element of the
34103table has the following fields:
34104
34105@table @samp
34106@item name
34107The name of the trace variable.  This field is always present.
34108
34109@item initial
34110The initial value.  This is a 64-bit signed integer.  This
34111field is always present.
34112
34113@item current
34114The value the trace variable has at the moment.  This is a 64-bit
34115signed integer.  This field is absent iff current value is
34116not defined, for example if the trace was never run, or is
34117presently running.
34118
34119@end table
34120
34121@subsubheading @value{GDBN} Command
34122
34123The corresponding @value{GDBN} command is @samp{tvariables}.
34124
34125@subsubheading Example
34126
34127@smallexample
34128(gdb)
34129-trace-list-variables
34130^done,trace-variables=@{nr_rows="1",nr_cols="3",
34131hdr=[@{width="15",alignment="-1",col_name="name",colhdr="Name"@},
34132     @{width="11",alignment="-1",col_name="initial",colhdr="Initial"@},
34133     @{width="11",alignment="-1",col_name="current",colhdr="Current"@}],
34134body=[variable=@{name="$trace_timestamp",initial="0"@}
34135      variable=@{name="$foo",initial="10",current="15"@}]@}
34136(gdb)
34137@end smallexample
34138
34139@subheading -trace-save
34140@findex -trace-save
34141
34142@subsubheading Synopsis
34143
34144@smallexample
34145 -trace-save [ -r ] [ -ctf ] @var{filename}
34146@end smallexample
34147
34148Saves the collected trace data to @var{filename}.  Without the
34149@samp{-r} option, the data is downloaded from the target and saved
34150in a local file.  With the @samp{-r} option the target is asked
34151to perform the save.
34152
34153By default, this command will save the trace in the tfile format.  You can
34154supply the optional @samp{-ctf} argument to save it the CTF format. See
34155@ref{Trace Files} for more information about CTF.
34156
34157@subsubheading @value{GDBN} Command
34158
34159The corresponding @value{GDBN} command is @samp{tsave}.
34160
34161
34162@subheading -trace-start
34163@findex -trace-start
34164
34165@subsubheading Synopsis
34166
34167@smallexample
34168 -trace-start
34169@end smallexample
34170
34171Starts a tracing experiment.  The result of this command does not
34172have any fields.
34173
34174@subsubheading @value{GDBN} Command
34175
34176The corresponding @value{GDBN} command is @samp{tstart}.
34177
34178@subheading -trace-status
34179@findex -trace-status
34180
34181@subsubheading Synopsis
34182
34183@smallexample
34184 -trace-status
34185@end smallexample
34186
34187Obtains the status of a tracing experiment.  The result may include
34188the following fields:
34189
34190@table @samp
34191
34192@item supported
34193May have a value of either @samp{0}, when no tracing operations are
34194supported, @samp{1}, when all tracing operations are supported, or
34195@samp{file} when examining trace file.  In the latter case, examining
34196of trace frame is possible but new tracing experiement cannot be
34197started.  This field is always present.
34198
34199@item running
34200May have a value of either @samp{0} or @samp{1} depending on whether
34201tracing experiement is in progress on target.  This field is present
34202if @samp{supported} field is not @samp{0}.
34203
34204@item stop-reason
34205Report the reason why the tracing was stopped last time.  This field
34206may be absent iff tracing was never stopped on target yet.  The
34207value of @samp{request} means the tracing was stopped as result of
34208the @code{-trace-stop} command.  The value of @samp{overflow} means
34209the tracing buffer is full.  The value of @samp{disconnection} means
34210tracing was automatically stopped when @value{GDBN} has disconnected.
34211The value of @samp{passcount} means tracing was stopped when a
34212tracepoint was passed a maximal number of times for that tracepoint.
34213This field is present if @samp{supported} field is not @samp{0}.
34214
34215@item stopping-tracepoint
34216The number of tracepoint whose passcount as exceeded.  This field is
34217present iff the @samp{stop-reason} field has the value of
34218@samp{passcount}.
34219
34220@item frames
34221@itemx frames-created
34222The @samp{frames} field is a count of the total number of trace frames
34223in the trace buffer, while @samp{frames-created} is the total created
34224during the run, including ones that were discarded, such as when a
34225circular trace buffer filled up.  Both fields are optional.
34226
34227@item buffer-size
34228@itemx buffer-free
34229These fields tell the current size of the tracing buffer and the
34230remaining space.  These fields are optional.
34231
34232@item circular
34233The value of the circular trace buffer flag.  @code{1} means that the
34234trace buffer is circular and old trace frames will be discarded if
34235necessary to make room, @code{0} means that the trace buffer is linear
34236and may fill up.
34237
34238@item disconnected
34239The value of the disconnected tracing flag.  @code{1} means that
34240tracing will continue after @value{GDBN} disconnects, @code{0} means
34241that the trace run will stop.
34242
34243@item trace-file
34244The filename of the trace file being examined.  This field is
34245optional, and only present when examining a trace file.
34246
34247@end table
34248
34249@subsubheading @value{GDBN} Command
34250
34251The corresponding @value{GDBN} command is @samp{tstatus}.
34252
34253@subheading -trace-stop
34254@findex -trace-stop
34255
34256@subsubheading Synopsis
34257
34258@smallexample
34259 -trace-stop
34260@end smallexample
34261
34262Stops a tracing experiment.  The result of this command has the same
34263fields as @code{-trace-status}, except that the @samp{supported} and
34264@samp{running} fields are not output.
34265
34266@subsubheading @value{GDBN} Command
34267
34268The corresponding @value{GDBN} command is @samp{tstop}.
34269
34270
34271@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34272@node GDB/MI Symbol Query
34273@section @sc{gdb/mi} Symbol Query Commands
34274
34275
34276@ignore
34277@subheading The @code{-symbol-info-address} Command
34278@findex -symbol-info-address
34279
34280@subsubheading Synopsis
34281
34282@smallexample
34283 -symbol-info-address @var{symbol}
34284@end smallexample
34285
34286Describe where @var{symbol} is stored.
34287
34288@subsubheading @value{GDBN} Command
34289
34290The corresponding @value{GDBN} command is @samp{info address}.
34291
34292@subsubheading Example
34293N.A.
34294
34295
34296@subheading The @code{-symbol-info-file} Command
34297@findex -symbol-info-file
34298
34299@subsubheading Synopsis
34300
34301@smallexample
34302 -symbol-info-file
34303@end smallexample
34304
34305Show the file for the symbol.
34306
34307@subsubheading @value{GDBN} Command
34308
34309There's no equivalent @value{GDBN} command.  @code{gdbtk} has
34310@samp{gdb_find_file}.
34311
34312@subsubheading Example
34313N.A.
34314@end ignore
34315
34316@subheading The @code{-symbol-info-functions} Command
34317@findex -symbol-info-functions
34318@anchor{-symbol-info-functions}
34319
34320@subsubheading Synopsis
34321
34322@smallexample
34323 -symbol-info-functions [--include-nondebug]
34324                        [--type @var{type_regexp}]
34325                        [--name @var{name_regexp}]
34326                        [--max-results @var{limit}]
34327@end smallexample
34328
34329@noindent
34330Return a list containing the names and types for all global functions
34331taken from the debug information.  The functions are grouped by source
34332file, and shown with the line number on which each function is
34333defined.
34334
34335The @code{--include-nondebug} option causes the output to include
34336code symbols from the symbol table.
34337
34338The options @code{--type} and @code{--name} allow the symbols returned
34339to be filtered based on either the name of the function, or the type
34340signature of the function.
34341
34342The option @code{--max-results} restricts the command to return no
34343more than @var{limit} results.  If exactly @var{limit} results are
34344returned then there might be additional results available if a higher
34345limit is used.
34346
34347@subsubheading @value{GDBN} Command
34348
34349The corresponding @value{GDBN} command is @samp{info functions}.
34350
34351@subsubheading Example
34352@smallexample
34353@group
34354(gdb)
34355-symbol-info-functions
34356^done,symbols=
34357  @{debug=
34358    [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34359      fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34360      symbols=[@{line="36", name="f4", type="void (int *)",
34361                description="void f4(int *);"@},
34362               @{line="42", name="main", type="int ()",
34363                description="int main();"@},
34364               @{line="30", name="f1", type="my_int_t (int, int)",
34365                description="static my_int_t f1(int, int);"@}]@},
34366     @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34367      fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34368      symbols=[@{line="33", name="f2", type="float (another_float_t)",
34369                description="float f2(another_float_t);"@},
34370               @{line="39", name="f3", type="int (another_int_t)",
34371                description="int f3(another_int_t);"@},
34372               @{line="27", name="f1", type="another_float_t (int)",
34373                description="static another_float_t f1(int);"@}]@}]@}
34374@end group
34375@group
34376(gdb)
34377-symbol-info-functions --name f1
34378^done,symbols=
34379  @{debug=
34380    [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34381      fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34382      symbols=[@{line="30", name="f1", type="my_int_t (int, int)",
34383                description="static my_int_t f1(int, int);"@}]@},
34384     @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34385      fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34386      symbols=[@{line="27", name="f1", type="another_float_t (int)",
34387                description="static another_float_t f1(int);"@}]@}]@}
34388@end group
34389@group
34390(gdb)
34391-symbol-info-functions --type void
34392^done,symbols=
34393  @{debug=
34394    [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34395      fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34396      symbols=[@{line="36", name="f4", type="void (int *)",
34397                description="void f4(int *);"@}]@}]@}
34398@end group
34399@group
34400(gdb)
34401-symbol-info-functions --include-nondebug
34402^done,symbols=
34403  @{debug=
34404    [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34405      fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34406      symbols=[@{line="36", name="f4", type="void (int *)",
34407                description="void f4(int *);"@},
34408               @{line="42", name="main", type="int ()",
34409                description="int main();"@},
34410               @{line="30", name="f1", type="my_int_t (int, int)",
34411                description="static my_int_t f1(int, int);"@}]@},
34412     @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34413      fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34414      symbols=[@{line="33", name="f2", type="float (another_float_t)",
34415                description="float f2(another_float_t);"@},
34416               @{line="39", name="f3", type="int (another_int_t)",
34417                description="int f3(another_int_t);"@},
34418               @{line="27", name="f1", type="another_float_t (int)",
34419                description="static another_float_t f1(int);"@}]@}],
34420   nondebug=
34421    [@{address="0x0000000000400398",name="_init"@},
34422     @{address="0x00000000004003b0",name="_start"@},
34423      ...
34424    ]@}
34425@end group
34426@end smallexample
34427
34428@subheading The @code{-symbol-info-module-functions} Command
34429@findex -symbol-info-module-functions
34430@anchor{-symbol-info-module-functions}
34431
34432@subsubheading Synopsis
34433
34434@smallexample
34435 -symbol-info-module-functions [--module @var{module_regexp}]
34436                               [--name @var{name_regexp}]
34437                               [--type @var{type_regexp}]
34438@end smallexample
34439
34440@noindent
34441Return a list containing the names of all known functions within all
34442know Fortran modules.  The functions are grouped by source file and
34443containing module, and shown with the line number on which each
34444function is defined.
34445
34446The option @code{--module} only returns results for modules matching
34447@var{module_regexp}.  The option @code{--name} only returns functions
34448whose name matches @var{name_regexp}, and @code{--type} only returns
34449functions whose type matches @var{type_regexp}.
34450
34451@subsubheading @value{GDBN} Command
34452
34453The corresponding @value{GDBN} command is @samp{info module functions}.
34454
34455@subsubheading Example
34456
34457@smallexample
34458@group
34459(gdb)
34460-symbol-info-module-functions
34461^done,symbols=
34462  [@{module="mod1",
34463    files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34464            fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34465            symbols=[@{line="21",name="mod1::check_all",type="void (void)",
34466                      description="void mod1::check_all(void);"@}]@}]@},
34467    @{module="mod2",
34468     files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34469             fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34470             symbols=[@{line="30",name="mod2::check_var_i",type="void (void)",
34471                       description="void mod2::check_var_i(void);"@}]@}]@},
34472    @{module="mod3",
34473     files=[@{filename="/projec/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34474             fullname="/projec/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34475             symbols=[@{line="21",name="mod3::check_all",type="void (void)",
34476                       description="void mod3::check_all(void);"@},
34477                      @{line="27",name="mod3::check_mod2",type="void (void)",
34478                       description="void mod3::check_mod2(void);"@}]@}]@},
34479    @{module="modmany",
34480     files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34481             fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34482             symbols=[@{line="35",name="modmany::check_some",type="void (void)",
34483                       description="void modmany::check_some(void);"@}]@}]@},
34484    @{module="moduse",
34485     files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34486             fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34487             symbols=[@{line="44",name="moduse::check_all",type="void (void)",
34488                       description="void moduse::check_all(void);"@},
34489                      @{line="49",name="moduse::check_var_x",type="void (void)",
34490                       description="void moduse::check_var_x(void);"@}]@}]@}]
34491@end group
34492@end smallexample
34493
34494@subheading The @code{-symbol-info-module-variables} Command
34495@findex -symbol-info-module-variables
34496@anchor{-symbol-info-module-variables}
34497
34498@subsubheading Synopsis
34499
34500@smallexample
34501 -symbol-info-module-variables [--module @var{module_regexp}]
34502                               [--name @var{name_regexp}]
34503                               [--type @var{type_regexp}]
34504@end smallexample
34505
34506@noindent
34507Return a list containing the names of all known variables within all
34508know Fortran modules.  The variables are grouped by source file and
34509containing module, and shown with the line number on which each
34510variable is defined.
34511
34512The option @code{--module} only returns results for modules matching
34513@var{module_regexp}.  The option @code{--name} only returns variables
34514whose name matches @var{name_regexp}, and @code{--type} only returns
34515variables whose type matches @var{type_regexp}.
34516
34517@subsubheading @value{GDBN} Command
34518
34519The corresponding @value{GDBN} command is @samp{info module variables}.
34520
34521@subsubheading Example
34522
34523@smallexample
34524@group
34525(gdb)
34526-symbol-info-module-variables
34527^done,symbols=
34528  [@{module="mod1",
34529    files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34530            fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34531            symbols=[@{line="18",name="mod1::var_const",type="integer(kind=4)",
34532                      description="integer(kind=4) mod1::var_const;"@},
34533                     @{line="17",name="mod1::var_i",type="integer(kind=4)",
34534                      description="integer(kind=4) mod1::var_i;"@}]@}]@},
34535   @{module="mod2",
34536    files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34537            fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34538            symbols=[@{line="28",name="mod2::var_i",type="integer(kind=4)",
34539                      description="integer(kind=4) mod2::var_i;"@}]@}]@},
34540   @{module="mod3",
34541    files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34542            fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34543            symbols=[@{line="18",name="mod3::mod1",type="integer(kind=4)",
34544                      description="integer(kind=4) mod3::mod1;"@},
34545                     @{line="17",name="mod3::mod2",type="integer(kind=4)",
34546                      description="integer(kind=4) mod3::mod2;"@},
34547                     @{line="19",name="mod3::var_i",type="integer(kind=4)",
34548                      description="integer(kind=4) mod3::var_i;"@}]@}]@},
34549   @{module="modmany",
34550    files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34551            fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34552            symbols=[@{line="33",name="modmany::var_a",type="integer(kind=4)",
34553                      description="integer(kind=4) modmany::var_a;"@},
34554                     @{line="33",name="modmany::var_b",type="integer(kind=4)",
34555                      description="integer(kind=4) modmany::var_b;"@},
34556                     @{line="33",name="modmany::var_c",type="integer(kind=4)",
34557                      description="integer(kind=4) modmany::var_c;"@},
34558                     @{line="33",name="modmany::var_i",type="integer(kind=4)",
34559                      description="integer(kind=4) modmany::var_i;"@}]@}]@},
34560   @{module="moduse",
34561    files=[@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34562            fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34563            symbols=[@{line="42",name="moduse::var_x",type="integer(kind=4)",
34564                      description="integer(kind=4) moduse::var_x;"@},
34565                     @{line="42",name="moduse::var_y",type="integer(kind=4)",
34566                      description="integer(kind=4) moduse::var_y;"@}]@}]@}]
34567@end group
34568@end smallexample
34569
34570@subheading The @code{-symbol-info-modules} Command
34571@findex -symbol-info-modules
34572@anchor{-symbol-info-modules}
34573
34574@subsubheading Synopsis
34575
34576@smallexample
34577 -symbol-info-modules [--name @var{name_regexp}]
34578                      [--max-results @var{limit}]
34579
34580@end smallexample
34581
34582@noindent
34583Return a list containing the names of all known Fortran modules.  The
34584modules are grouped by source file, and shown with the line number on
34585which each modules is defined.
34586
34587The option @code{--name} allows the modules returned to be filtered
34588based the name of the module.
34589
34590The option @code{--max-results} restricts the command to return no
34591more than @var{limit} results.  If exactly @var{limit} results are
34592returned then there might be additional results available if a higher
34593limit is used.
34594
34595@subsubheading @value{GDBN} Command
34596
34597The corresponding @value{GDBN} command is @samp{info modules}.
34598
34599@subsubheading Example
34600@smallexample
34601@group
34602(gdb)
34603-symbol-info-modules
34604^done,symbols=
34605  @{debug=
34606    [@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34607      fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34608      symbols=[@{line="16",name="mod1"@},
34609               @{line="22",name="mod2"@}]@},
34610     @{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34611      fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34612      symbols=[@{line="16",name="mod3"@},
34613               @{line="22",name="modmany"@},
34614               @{line="26",name="moduse"@}]@}]@}
34615@end group
34616@group
34617(gdb)
34618-symbol-info-modules --name mod[123]
34619^done,symbols=
34620  @{debug=
34621    [@{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34622      fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules-2.f90",
34623      symbols=[@{line="16",name="mod1"@},
34624               @{line="22",name="mod2"@}]@},
34625     @{filename="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34626      fullname="/project/gdb/testsuite/gdb.mi/mi-fortran-modules.f90",
34627      symbols=[@{line="16",name="mod3"@}]@}]@}
34628@end group
34629@end smallexample
34630
34631@subheading The @code{-symbol-info-types} Command
34632@findex -symbol-info-types
34633@anchor{-symbol-info-types}
34634
34635@subsubheading Synopsis
34636
34637@smallexample
34638 -symbol-info-types [--name @var{name_regexp}]
34639                    [--max-results @var{limit}]
34640
34641@end smallexample
34642
34643@noindent
34644Return a list of all defined types.  The types are grouped by source
34645file, and shown with the line number on which each user defined type
34646is defined.  Some base types are not defined in the source code but
34647are added to the debug information by the compiler, for example
34648@code{int}, @code{float}, etc.; these types do not have an associated
34649line number.
34650
34651The option @code{--name} allows the list of types returned to be
34652filtered by name.
34653
34654The option @code{--max-results} restricts the command to return no
34655more than @var{limit} results.  If exactly @var{limit} results are
34656returned then there might be additional results available if a higher
34657limit is used.
34658
34659@subsubheading @value{GDBN} Command
34660
34661The corresponding @value{GDBN} command is @samp{info types}.
34662
34663@subsubheading Example
34664@smallexample
34665@group
34666(gdb)
34667-symbol-info-types
34668^done,symbols=
34669  @{debug=
34670     [@{filename="gdb.mi/mi-sym-info-1.c",
34671       fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34672       symbols=[@{name="float"@},
34673                @{name="int"@},
34674                @{line="27",name="typedef int my_int_t;"@}]@},
34675      @{filename="gdb.mi/mi-sym-info-2.c",
34676       fullname="/project/gdb.mi/mi-sym-info-2.c",
34677       symbols=[@{line="24",name="typedef float another_float_t;"@},
34678                @{line="23",name="typedef int another_int_t;"@},
34679                @{name="float"@},
34680                @{name="int"@}]@}]@}
34681@end group
34682@group
34683(gdb)
34684-symbol-info-types --name _int_
34685^done,symbols=
34686  @{debug=
34687     [@{filename="gdb.mi/mi-sym-info-1.c",
34688       fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34689       symbols=[@{line="27",name="typedef int my_int_t;"@}]@},
34690      @{filename="gdb.mi/mi-sym-info-2.c",
34691       fullname="/project/gdb.mi/mi-sym-info-2.c",
34692       symbols=[@{line="23",name="typedef int another_int_t;"@}]@}]@}
34693@end group
34694@end smallexample
34695
34696@subheading The @code{-symbol-info-variables} Command
34697@findex -symbol-info-variables
34698@anchor{-symbol-info-variables}
34699
34700@subsubheading Synopsis
34701
34702@smallexample
34703 -symbol-info-variables [--include-nondebug]
34704                        [--type @var{type_regexp}]
34705                        [--name @var{name_regexp}]
34706                        [--max-results @var{limit}]
34707
34708@end smallexample
34709
34710@noindent
34711Return a list containing the names and types for all global variables
34712taken from the debug information.  The variables are grouped by source
34713file, and shown with the line number on which each variable is
34714defined.
34715
34716The @code{--include-nondebug} option causes the output to include
34717data symbols from the symbol table.
34718
34719The options @code{--type} and @code{--name} allow the symbols returned
34720to be filtered based on either the name of the variable, or the type
34721of the variable.
34722
34723The option @code{--max-results} restricts the command to return no
34724more than @var{limit} results.  If exactly @var{limit} results are
34725returned then there might be additional results available if a higher
34726limit is used.
34727
34728@subsubheading @value{GDBN} Command
34729
34730The corresponding @value{GDBN} command is @samp{info variables}.
34731
34732@subsubheading Example
34733@smallexample
34734@group
34735(gdb)
34736-symbol-info-variables
34737^done,symbols=
34738  @{debug=
34739    [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34740      fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34741      symbols=[@{line="25",name="global_f1",type="float",
34742                description="static float global_f1;"@},
34743               @{line="24",name="global_i1",type="int",
34744                description="static int global_i1;"@}]@},
34745     @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34746      fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34747      symbols=[@{line="21",name="global_f2",type="int",
34748                description="int global_f2;"@},
34749               @{line="20",name="global_i2",type="int",
34750                description="int global_i2;"@},
34751               @{line="19",name="global_f1",type="float",
34752                description="static float global_f1;"@},
34753               @{line="18",name="global_i1",type="int",
34754                description="static int global_i1;"@}]@}]@}
34755@end group
34756@group
34757(gdb)
34758-symbol-info-variables --name f1
34759^done,symbols=
34760  @{debug=
34761    [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34762      fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34763      symbols=[@{line="25",name="global_f1",type="float",
34764                description="static float global_f1;"@}]@},
34765     @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34766      fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34767      symbols=[@{line="19",name="global_f1",type="float",
34768                description="static float global_f1;"@}]@}]@}
34769@end group
34770@group
34771(gdb)
34772-symbol-info-variables --type float
34773^done,symbols=
34774  @{debug=
34775    [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34776      fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34777      symbols=[@{line="25",name="global_f1",type="float",
34778                description="static float global_f1;"@}]@},
34779     @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34780      fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34781      symbols=[@{line="19",name="global_f1",type="float",
34782                description="static float global_f1;"@}]@}]@}
34783@end group
34784@group
34785(gdb)
34786-symbol-info-variables --include-nondebug
34787^done,symbols=
34788  @{debug=
34789    [@{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34790      fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-1.c",
34791      symbols=[@{line="25",name="global_f1",type="float",
34792                description="static float global_f1;"@},
34793               @{line="24",name="global_i1",type="int",
34794                description="static int global_i1;"@}]@},
34795     @{filename="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34796      fullname="/project/gdb/testsuite/gdb.mi/mi-sym-info-2.c",
34797      symbols=[@{line="21",name="global_f2",type="int",
34798                description="int global_f2;"@},
34799               @{line="20",name="global_i2",type="int",
34800                description="int global_i2;"@},
34801               @{line="19",name="global_f1",type="float",
34802                description="static float global_f1;"@},
34803               @{line="18",name="global_i1",type="int",
34804                description="static int global_i1;"@}]@}],
34805   nondebug=
34806    [@{address="0x00000000004005d0",name="_IO_stdin_used"@},
34807     @{address="0x00000000004005d8",name="__dso_handle"@}
34808      ...
34809    ]@}
34810@end group
34811@end smallexample
34812
34813@ignore
34814@subheading The @code{-symbol-info-line} Command
34815@findex -symbol-info-line
34816
34817@subsubheading Synopsis
34818
34819@smallexample
34820 -symbol-info-line
34821@end smallexample
34822
34823Show the core addresses of the code for a source line.
34824
34825@subsubheading @value{GDBN} Command
34826
34827The corresponding @value{GDBN} command is @samp{info line}.
34828@code{gdbtk} has the @samp{gdb_get_line} and @samp{gdb_get_file} commands.
34829
34830@subsubheading Example
34831N.A.
34832
34833
34834@subheading The @code{-symbol-info-symbol} Command
34835@findex -symbol-info-symbol
34836
34837@subsubheading Synopsis
34838
34839@smallexample
34840 -symbol-info-symbol @var{addr}
34841@end smallexample
34842
34843Describe what symbol is at location @var{addr}.
34844
34845@subsubheading @value{GDBN} Command
34846
34847The corresponding @value{GDBN} command is @samp{info symbol}.
34848
34849@subsubheading Example
34850N.A.
34851
34852
34853@subheading The @code{-symbol-list-functions} Command
34854@findex -symbol-list-functions
34855
34856@subsubheading Synopsis
34857
34858@smallexample
34859 -symbol-list-functions
34860@end smallexample
34861
34862List the functions in the executable.
34863
34864@subsubheading @value{GDBN} Command
34865
34866@samp{info functions} in @value{GDBN}, @samp{gdb_listfunc} and
34867@samp{gdb_search} in @code{gdbtk}.
34868
34869@subsubheading Example
34870N.A.
34871@end ignore
34872
34873
34874@subheading The @code{-symbol-list-lines} Command
34875@findex -symbol-list-lines
34876
34877@subsubheading Synopsis
34878
34879@smallexample
34880 -symbol-list-lines @var{filename}
34881@end smallexample
34882
34883Print the list of lines that contain code and their associated program
34884addresses for the given source filename.  The entries are sorted in
34885ascending PC order.
34886
34887@subsubheading @value{GDBN} Command
34888
34889There is no corresponding @value{GDBN} command.
34890
34891@subsubheading Example
34892@smallexample
34893(gdb)
34894-symbol-list-lines basics.c
34895^done,lines=[@{pc="0x08048554",line="7"@},@{pc="0x0804855a",line="8"@}]
34896(gdb)
34897@end smallexample
34898
34899
34900@ignore
34901@subheading The @code{-symbol-list-types} Command
34902@findex -symbol-list-types
34903
34904@subsubheading Synopsis
34905
34906@smallexample
34907 -symbol-list-types
34908@end smallexample
34909
34910List all the type names.
34911
34912@subsubheading @value{GDBN} Command
34913
34914The corresponding commands are @samp{info types} in @value{GDBN},
34915@samp{gdb_search} in @code{gdbtk}.
34916
34917@subsubheading Example
34918N.A.
34919
34920
34921@subheading The @code{-symbol-list-variables} Command
34922@findex -symbol-list-variables
34923
34924@subsubheading Synopsis
34925
34926@smallexample
34927 -symbol-list-variables
34928@end smallexample
34929
34930List all the global and static variable names.
34931
34932@subsubheading @value{GDBN} Command
34933
34934@samp{info variables} in @value{GDBN}, @samp{gdb_search} in @code{gdbtk}.
34935
34936@subsubheading Example
34937N.A.
34938
34939
34940@subheading The @code{-symbol-locate} Command
34941@findex -symbol-locate
34942
34943@subsubheading Synopsis
34944
34945@smallexample
34946 -symbol-locate
34947@end smallexample
34948
34949@subsubheading @value{GDBN} Command
34950
34951@samp{gdb_loc} in @code{gdbtk}.
34952
34953@subsubheading Example
34954N.A.
34955
34956
34957@subheading The @code{-symbol-type} Command
34958@findex -symbol-type
34959
34960@subsubheading Synopsis
34961
34962@smallexample
34963 -symbol-type @var{variable}
34964@end smallexample
34965
34966Show type of @var{variable}.
34967
34968@subsubheading @value{GDBN} Command
34969
34970The corresponding @value{GDBN} command is @samp{ptype}, @code{gdbtk} has
34971@samp{gdb_obj_variable}.
34972
34973@subsubheading Example
34974N.A.
34975@end ignore
34976
34977
34978@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34979@node GDB/MI File Commands
34980@section @sc{gdb/mi} File Commands
34981
34982This section describes the GDB/MI commands to specify executable file names
34983and to read in and obtain symbol table information.
34984
34985@subheading The @code{-file-exec-and-symbols} Command
34986@findex -file-exec-and-symbols
34987
34988@subsubheading Synopsis
34989
34990@smallexample
34991 -file-exec-and-symbols @var{file}
34992@end smallexample
34993
34994Specify the executable file to be debugged.  This file is the one from
34995which the symbol table is also read.  If no file is specified, the
34996command clears the executable and symbol information.  If breakpoints
34997are set when using this command with no arguments, @value{GDBN} will produce
34998error messages.  Otherwise, no output is produced, except a completion
34999notification.
35000
35001@subsubheading @value{GDBN} Command
35002
35003The corresponding @value{GDBN} command is @samp{file}.
35004
35005@subsubheading Example
35006
35007@smallexample
35008(gdb)
35009-file-exec-and-symbols /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
35010^done
35011(gdb)
35012@end smallexample
35013
35014
35015@subheading The @code{-file-exec-file} Command
35016@findex -file-exec-file
35017
35018@subsubheading Synopsis
35019
35020@smallexample
35021 -file-exec-file @var{file}
35022@end smallexample
35023
35024Specify the executable file to be debugged.  Unlike
35025@samp{-file-exec-and-symbols}, the symbol table is @emph{not} read
35026from this file.  If used without argument, @value{GDBN} clears the information
35027about the executable file.  No output is produced, except a completion
35028notification.
35029
35030@subsubheading @value{GDBN} Command
35031
35032The corresponding @value{GDBN} command is @samp{exec-file}.
35033
35034@subsubheading Example
35035
35036@smallexample
35037(gdb)
35038-file-exec-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
35039^done
35040(gdb)
35041@end smallexample
35042
35043
35044@ignore
35045@subheading The @code{-file-list-exec-sections} Command
35046@findex -file-list-exec-sections
35047
35048@subsubheading Synopsis
35049
35050@smallexample
35051 -file-list-exec-sections
35052@end smallexample
35053
35054List the sections of the current executable file.
35055
35056@subsubheading @value{GDBN} Command
35057
35058The @value{GDBN} command @samp{info file} shows, among the rest, the same
35059information as this command.  @code{gdbtk} has a corresponding command
35060@samp{gdb_load_info}.
35061
35062@subsubheading Example
35063N.A.
35064@end ignore
35065
35066
35067@subheading The @code{-file-list-exec-source-file} Command
35068@findex -file-list-exec-source-file
35069
35070@subsubheading Synopsis
35071
35072@smallexample
35073 -file-list-exec-source-file
35074@end smallexample
35075
35076List the line number, the current source file, and the absolute path
35077to the current source file for the current executable.  The macro
35078information field has a value of @samp{1} or @samp{0} depending on
35079whether or not the file includes preprocessor macro information.
35080
35081@subsubheading @value{GDBN} Command
35082
35083The @value{GDBN} equivalent is @samp{info source}
35084
35085@subsubheading Example
35086
35087@smallexample
35088(gdb)
35089123-file-list-exec-source-file
35090123^done,line="1",file="foo.c",fullname="/home/bar/foo.c,macro-info="1"
35091(gdb)
35092@end smallexample
35093
35094
35095@subheading The @code{-file-list-exec-source-files} Command
35096@findex -file-list-exec-source-files
35097
35098@subsubheading Synopsis
35099
35100@smallexample
35101 -file-list-exec-source-files
35102@end smallexample
35103
35104List the source files for the current executable.
35105
35106It will always output both the filename and fullname (absolute file
35107name) of a source file.
35108
35109@subsubheading @value{GDBN} Command
35110
35111The @value{GDBN} equivalent is @samp{info sources}.
35112@code{gdbtk} has an analogous command @samp{gdb_listfiles}.
35113
35114@subsubheading Example
35115@smallexample
35116(gdb)
35117-file-list-exec-source-files
35118^done,files=[
35119@{file=foo.c,fullname=/home/foo.c@},
35120@{file=/home/bar.c,fullname=/home/bar.c@},
35121@{file=gdb_could_not_find_fullpath.c@}]
35122(gdb)
35123@end smallexample
35124
35125@subheading The @code{-file-list-shared-libraries} Command
35126@findex -file-list-shared-libraries
35127
35128@subsubheading Synopsis
35129
35130@smallexample
35131 -file-list-shared-libraries [ @var{regexp} ]
35132@end smallexample
35133
35134List the shared libraries in the program.
35135With a regular expression @var{regexp}, only those libraries whose
35136names match @var{regexp} are listed.
35137
35138@subsubheading @value{GDBN} Command
35139
35140The corresponding @value{GDBN} command is @samp{info shared}.  The fields
35141have a similar meaning to the @code{=library-loaded} notification.
35142The @code{ranges} field specifies the multiple segments belonging to this
35143library.  Each range has the following fields:
35144
35145@table @samp
35146@item from
35147The address defining the inclusive lower bound of the segment.
35148@item to
35149The address defining the exclusive upper bound of the segment.
35150@end table
35151
35152@subsubheading Example
35153@smallexample
35154(gdb)
35155-file-list-exec-source-files
35156^done,shared-libraries=[
35157@{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"@}]@},
35158@{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"@}]@}]
35159(gdb)
35160@end smallexample
35161
35162
35163@ignore
35164@subheading The @code{-file-list-symbol-files} Command
35165@findex -file-list-symbol-files
35166
35167@subsubheading Synopsis
35168
35169@smallexample
35170 -file-list-symbol-files
35171@end smallexample
35172
35173List symbol files.
35174
35175@subsubheading @value{GDBN} Command
35176
35177The corresponding @value{GDBN} command is @samp{info file} (part of it).
35178
35179@subsubheading Example
35180N.A.
35181@end ignore
35182
35183
35184@subheading The @code{-file-symbol-file} Command
35185@findex -file-symbol-file
35186
35187@subsubheading Synopsis
35188
35189@smallexample
35190 -file-symbol-file @var{file}
35191@end smallexample
35192
35193Read symbol table info from the specified @var{file} argument.  When
35194used without arguments, clears @value{GDBN}'s symbol table info.  No output is
35195produced, except for a completion notification.
35196
35197@subsubheading @value{GDBN} Command
35198
35199The corresponding @value{GDBN} command is @samp{symbol-file}.
35200
35201@subsubheading Example
35202
35203@smallexample
35204(gdb)
35205-file-symbol-file /kwikemart/marge/ezannoni/TRUNK/mbx/hello.mbx
35206^done
35207(gdb)
35208@end smallexample
35209
35210@ignore
35211@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35212@node GDB/MI Memory Overlay Commands
35213@section @sc{gdb/mi} Memory Overlay Commands
35214
35215The memory overlay commands are not implemented.
35216
35217@c @subheading -overlay-auto
35218
35219@c @subheading -overlay-list-mapping-state
35220
35221@c @subheading -overlay-list-overlays
35222
35223@c @subheading -overlay-map
35224
35225@c @subheading -overlay-off
35226
35227@c @subheading -overlay-on
35228
35229@c @subheading -overlay-unmap
35230
35231@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35232@node GDB/MI Signal Handling Commands
35233@section @sc{gdb/mi} Signal Handling Commands
35234
35235Signal handling commands are not implemented.
35236
35237@c @subheading -signal-handle
35238
35239@c @subheading -signal-list-handle-actions
35240
35241@c @subheading -signal-list-signal-types
35242@end ignore
35243
35244
35245@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35246@node GDB/MI Target Manipulation
35247@section @sc{gdb/mi} Target Manipulation Commands
35248
35249
35250@subheading The @code{-target-attach} Command
35251@findex -target-attach
35252
35253@subsubheading Synopsis
35254
35255@smallexample
35256 -target-attach @var{pid} | @var{gid} | @var{file}
35257@end smallexample
35258
35259Attach to a process @var{pid} or a file @var{file} outside of
35260@value{GDBN}, or a thread group @var{gid}.  If attaching to a thread
35261group, the id previously returned by
35262@samp{-list-thread-groups --available} must be used.
35263
35264@subsubheading @value{GDBN} Command
35265
35266The corresponding @value{GDBN} command is @samp{attach}.
35267
35268@subsubheading Example
35269@smallexample
35270(gdb)
35271-target-attach 34
35272=thread-created,id="1"
35273*stopped,thread-id="1",frame=@{addr="0xb7f7e410",func="bar",args=[]@}
35274^done
35275(gdb)
35276@end smallexample
35277
35278@ignore
35279@subheading The @code{-target-compare-sections} Command
35280@findex -target-compare-sections
35281
35282@subsubheading Synopsis
35283
35284@smallexample
35285 -target-compare-sections [ @var{section} ]
35286@end smallexample
35287
35288Compare data of section @var{section} on target to the exec file.
35289Without the argument, all sections are compared.
35290
35291@subsubheading @value{GDBN} Command
35292
35293The @value{GDBN} equivalent is @samp{compare-sections}.
35294
35295@subsubheading Example
35296N.A.
35297@end ignore
35298
35299
35300@subheading The @code{-target-detach} Command
35301@findex -target-detach
35302
35303@subsubheading Synopsis
35304
35305@smallexample
35306 -target-detach [ @var{pid} | @var{gid} ]
35307@end smallexample
35308
35309Detach from the remote target which normally resumes its execution.
35310If either @var{pid} or @var{gid} is specified, detaches from either
35311the specified process, or specified thread group.  There's no output.
35312
35313@subsubheading @value{GDBN} Command
35314
35315The corresponding @value{GDBN} command is @samp{detach}.
35316
35317@subsubheading Example
35318
35319@smallexample
35320(gdb)
35321-target-detach
35322^done
35323(gdb)
35324@end smallexample
35325
35326
35327@subheading The @code{-target-disconnect} Command
35328@findex -target-disconnect
35329
35330@subsubheading Synopsis
35331
35332@smallexample
35333 -target-disconnect
35334@end smallexample
35335
35336Disconnect from the remote target.  There's no output and the target is
35337generally not resumed.
35338
35339@subsubheading @value{GDBN} Command
35340
35341The corresponding @value{GDBN} command is @samp{disconnect}.
35342
35343@subsubheading Example
35344
35345@smallexample
35346(gdb)
35347-target-disconnect
35348^done
35349(gdb)
35350@end smallexample
35351
35352
35353@subheading The @code{-target-download} Command
35354@findex -target-download
35355
35356@subsubheading Synopsis
35357
35358@smallexample
35359 -target-download
35360@end smallexample
35361
35362Loads the executable onto the remote target.
35363It prints out an update message every half second, which includes the fields:
35364
35365@table @samp
35366@item section
35367The name of the section.
35368@item section-sent
35369The size of what has been sent so far for that section.
35370@item section-size
35371The size of the section.
35372@item total-sent
35373The total size of what was sent so far (the current and the previous sections).
35374@item total-size
35375The size of the overall executable to download.
35376@end table
35377
35378@noindent
35379Each message is sent as status record (@pxref{GDB/MI Output Syntax, ,
35380@sc{gdb/mi} Output Syntax}).
35381
35382In addition, it prints the name and size of the sections, as they are
35383downloaded.  These messages include the following fields:
35384
35385@table @samp
35386@item section
35387The name of the section.
35388@item section-size
35389The size of the section.
35390@item total-size
35391The size of the overall executable to download.
35392@end table
35393
35394@noindent
35395At the end, a summary is printed.
35396
35397@subsubheading @value{GDBN} Command
35398
35399The corresponding @value{GDBN} command is @samp{load}.
35400
35401@subsubheading Example
35402
35403Note: each status message appears on a single line.  Here the messages
35404have been broken down so that they can fit onto a page.
35405
35406@smallexample
35407(gdb)
35408-target-download
35409+download,@{section=".text",section-size="6668",total-size="9880"@}
35410+download,@{section=".text",section-sent="512",section-size="6668",
35411total-sent="512",total-size="9880"@}
35412+download,@{section=".text",section-sent="1024",section-size="6668",
35413total-sent="1024",total-size="9880"@}
35414+download,@{section=".text",section-sent="1536",section-size="6668",
35415total-sent="1536",total-size="9880"@}
35416+download,@{section=".text",section-sent="2048",section-size="6668",
35417total-sent="2048",total-size="9880"@}
35418+download,@{section=".text",section-sent="2560",section-size="6668",
35419total-sent="2560",total-size="9880"@}
35420+download,@{section=".text",section-sent="3072",section-size="6668",
35421total-sent="3072",total-size="9880"@}
35422+download,@{section=".text",section-sent="3584",section-size="6668",
35423total-sent="3584",total-size="9880"@}
35424+download,@{section=".text",section-sent="4096",section-size="6668",
35425total-sent="4096",total-size="9880"@}
35426+download,@{section=".text",section-sent="4608",section-size="6668",
35427total-sent="4608",total-size="9880"@}
35428+download,@{section=".text",section-sent="5120",section-size="6668",
35429total-sent="5120",total-size="9880"@}
35430+download,@{section=".text",section-sent="5632",section-size="6668",
35431total-sent="5632",total-size="9880"@}
35432+download,@{section=".text",section-sent="6144",section-size="6668",
35433total-sent="6144",total-size="9880"@}
35434+download,@{section=".text",section-sent="6656",section-size="6668",
35435total-sent="6656",total-size="9880"@}
35436+download,@{section=".init",section-size="28",total-size="9880"@}
35437+download,@{section=".fini",section-size="28",total-size="9880"@}
35438+download,@{section=".data",section-size="3156",total-size="9880"@}
35439+download,@{section=".data",section-sent="512",section-size="3156",
35440total-sent="7236",total-size="9880"@}
35441+download,@{section=".data",section-sent="1024",section-size="3156",
35442total-sent="7748",total-size="9880"@}
35443+download,@{section=".data",section-sent="1536",section-size="3156",
35444total-sent="8260",total-size="9880"@}
35445+download,@{section=".data",section-sent="2048",section-size="3156",
35446total-sent="8772",total-size="9880"@}
35447+download,@{section=".data",section-sent="2560",section-size="3156",
35448total-sent="9284",total-size="9880"@}
35449+download,@{section=".data",section-sent="3072",section-size="3156",
35450total-sent="9796",total-size="9880"@}
35451^done,address="0x10004",load-size="9880",transfer-rate="6586",
35452write-rate="429"
35453(gdb)
35454@end smallexample
35455
35456
35457@ignore
35458@subheading The @code{-target-exec-status} Command
35459@findex -target-exec-status
35460
35461@subsubheading Synopsis
35462
35463@smallexample
35464 -target-exec-status
35465@end smallexample
35466
35467Provide information on the state of the target (whether it is running or
35468not, for instance).
35469
35470@subsubheading @value{GDBN} Command
35471
35472There's no equivalent @value{GDBN} command.
35473
35474@subsubheading Example
35475N.A.
35476
35477
35478@subheading The @code{-target-list-available-targets} Command
35479@findex -target-list-available-targets
35480
35481@subsubheading Synopsis
35482
35483@smallexample
35484 -target-list-available-targets
35485@end smallexample
35486
35487List the possible targets to connect to.
35488
35489@subsubheading @value{GDBN} Command
35490
35491The corresponding @value{GDBN} command is @samp{help target}.
35492
35493@subsubheading Example
35494N.A.
35495
35496
35497@subheading The @code{-target-list-current-targets} Command
35498@findex -target-list-current-targets
35499
35500@subsubheading Synopsis
35501
35502@smallexample
35503 -target-list-current-targets
35504@end smallexample
35505
35506Describe the current target.
35507
35508@subsubheading @value{GDBN} Command
35509
35510The corresponding information is printed by @samp{info file} (among
35511other things).
35512
35513@subsubheading Example
35514N.A.
35515
35516
35517@subheading The @code{-target-list-parameters} Command
35518@findex -target-list-parameters
35519
35520@subsubheading Synopsis
35521
35522@smallexample
35523 -target-list-parameters
35524@end smallexample
35525
35526@c ????
35527@end ignore
35528
35529@subsubheading @value{GDBN} Command
35530
35531No equivalent.
35532
35533@subsubheading Example
35534N.A.
35535
35536@subheading The @code{-target-flash-erase} Command
35537@findex -target-flash-erase
35538
35539@subsubheading Synopsis
35540
35541@smallexample
35542 -target-flash-erase
35543@end smallexample
35544
35545Erases all known flash memory regions on the target.
35546
35547The corresponding @value{GDBN} command is @samp{flash-erase}.
35548
35549The output is a list of flash regions that have been erased, with starting
35550addresses and memory region sizes.
35551
35552@smallexample
35553(gdb)
35554-target-flash-erase
35555^done,erased-regions=@{address="0x0",size="0x40000"@}
35556(gdb)
35557@end smallexample
35558
35559@subheading The @code{-target-select} Command
35560@findex -target-select
35561
35562@subsubheading Synopsis
35563
35564@smallexample
35565 -target-select @var{type} @var{parameters @dots{}}
35566@end smallexample
35567
35568Connect @value{GDBN} to the remote target.  This command takes two args:
35569
35570@table @samp
35571@item @var{type}
35572The type of target, for instance @samp{remote}, etc.
35573@item @var{parameters}
35574Device names, host names and the like.  @xref{Target Commands, ,
35575Commands for Managing Targets}, for more details.
35576@end table
35577
35578The output is a connection notification, followed by the address at
35579which the target program is, in the following form:
35580
35581@smallexample
35582^connected,addr="@var{address}",func="@var{function name}",
35583  args=[@var{arg list}]
35584@end smallexample
35585
35586@subsubheading @value{GDBN} Command
35587
35588The corresponding @value{GDBN} command is @samp{target}.
35589
35590@subsubheading Example
35591
35592@smallexample
35593(gdb)
35594-target-select remote /dev/ttya
35595^connected,addr="0xfe00a300",func="??",args=[]
35596(gdb)
35597@end smallexample
35598
35599@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35600@node GDB/MI File Transfer Commands
35601@section @sc{gdb/mi} File Transfer Commands
35602
35603
35604@subheading The @code{-target-file-put} Command
35605@findex -target-file-put
35606
35607@subsubheading Synopsis
35608
35609@smallexample
35610 -target-file-put @var{hostfile} @var{targetfile}
35611@end smallexample
35612
35613Copy file @var{hostfile} from the host system (the machine running
35614@value{GDBN}) to @var{targetfile} on the target system.
35615
35616@subsubheading @value{GDBN} Command
35617
35618The corresponding @value{GDBN} command is @samp{remote put}.
35619
35620@subsubheading Example
35621
35622@smallexample
35623(gdb)
35624-target-file-put localfile remotefile
35625^done
35626(gdb)
35627@end smallexample
35628
35629
35630@subheading The @code{-target-file-get} Command
35631@findex -target-file-get
35632
35633@subsubheading Synopsis
35634
35635@smallexample
35636 -target-file-get @var{targetfile} @var{hostfile}
35637@end smallexample
35638
35639Copy file @var{targetfile} from the target system to @var{hostfile}
35640on the host system.
35641
35642@subsubheading @value{GDBN} Command
35643
35644The corresponding @value{GDBN} command is @samp{remote get}.
35645
35646@subsubheading Example
35647
35648@smallexample
35649(gdb)
35650-target-file-get remotefile localfile
35651^done
35652(gdb)
35653@end smallexample
35654
35655
35656@subheading The @code{-target-file-delete} Command
35657@findex -target-file-delete
35658
35659@subsubheading Synopsis
35660
35661@smallexample
35662 -target-file-delete @var{targetfile}
35663@end smallexample
35664
35665Delete @var{targetfile} from the target system.
35666
35667@subsubheading @value{GDBN} Command
35668
35669The corresponding @value{GDBN} command is @samp{remote delete}.
35670
35671@subsubheading Example
35672
35673@smallexample
35674(gdb)
35675-target-file-delete remotefile
35676^done
35677(gdb)
35678@end smallexample
35679
35680
35681@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35682@node GDB/MI Ada Exceptions Commands
35683@section Ada Exceptions @sc{gdb/mi} Commands
35684
35685@subheading The @code{-info-ada-exceptions} Command
35686@findex -info-ada-exceptions
35687
35688@subsubheading Synopsis
35689
35690@smallexample
35691 -info-ada-exceptions [ @var{regexp}]
35692@end smallexample
35693
35694List all Ada exceptions defined within the program being debugged.
35695With a regular expression @var{regexp}, only those exceptions whose
35696names match @var{regexp} are listed.
35697
35698@subsubheading @value{GDBN} Command
35699
35700The corresponding @value{GDBN} command is @samp{info exceptions}.
35701
35702@subsubheading Result
35703
35704The result is a table of Ada exceptions.  The following columns are
35705defined for each exception:
35706
35707@table @samp
35708@item name
35709The name of the exception.
35710
35711@item address
35712The address of the exception.
35713
35714@end table
35715
35716@subsubheading Example
35717
35718@smallexample
35719-info-ada-exceptions aint
35720^done,ada-exceptions=@{nr_rows="2",nr_cols="2",
35721hdr=[@{width="1",alignment="-1",col_name="name",colhdr="Name"@},
35722@{width="1",alignment="-1",col_name="address",colhdr="Address"@}],
35723body=[@{name="constraint_error",address="0x0000000000613da0"@},
35724@{name="const.aint_global_e",address="0x0000000000613b00"@}]@}
35725@end smallexample
35726
35727@subheading Catching Ada Exceptions
35728
35729The commands describing how to ask @value{GDBN} to stop when a program
35730raises an exception are described at @ref{Ada Exception GDB/MI
35731Catchpoint Commands}.
35732
35733
35734@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35735@node GDB/MI Support Commands
35736@section @sc{gdb/mi} Support Commands
35737
35738Since new commands and features get regularly added to @sc{gdb/mi},
35739some commands are available to help front-ends query the debugger
35740about support for these capabilities.  Similarly, it is also possible
35741to query @value{GDBN} about target support of certain features.
35742
35743@subheading The @code{-info-gdb-mi-command} Command
35744@cindex @code{-info-gdb-mi-command}
35745@findex -info-gdb-mi-command
35746
35747@subsubheading Synopsis
35748
35749@smallexample
35750 -info-gdb-mi-command @var{cmd_name}
35751@end smallexample
35752
35753Query support for the @sc{gdb/mi} command named @var{cmd_name}.
35754
35755Note that the dash (@code{-}) starting all @sc{gdb/mi} commands
35756is technically not part of the command name (@pxref{GDB/MI Input
35757Syntax}), and thus should be omitted in @var{cmd_name}.  However,
35758for ease of use, this command also accepts the form with the leading
35759dash.
35760
35761@subsubheading @value{GDBN} Command
35762
35763There is no corresponding @value{GDBN} command.
35764
35765@subsubheading Result
35766
35767The result is a tuple.  There is currently only one field:
35768
35769@table @samp
35770@item exists
35771This field is equal to @code{"true"} if the @sc{gdb/mi} command exists,
35772@code{"false"} otherwise.
35773
35774@end table
35775
35776@subsubheading Example
35777
35778Here is an example where the @sc{gdb/mi} command does not exist:
35779
35780@smallexample
35781-info-gdb-mi-command unsupported-command
35782^done,command=@{exists="false"@}
35783@end smallexample
35784
35785@noindent
35786And here is an example where the @sc{gdb/mi} command is known
35787to the debugger:
35788
35789@smallexample
35790-info-gdb-mi-command symbol-list-lines
35791^done,command=@{exists="true"@}
35792@end smallexample
35793
35794@subheading The @code{-list-features} Command
35795@findex -list-features
35796@cindex supported @sc{gdb/mi} features, list
35797
35798Returns a list of particular features of the MI protocol that
35799this version of gdb implements.  A feature can be a command,
35800or a new field in an output of some command, or even an
35801important bugfix.  While a frontend can sometimes detect presence
35802of a feature at runtime, it is easier to perform detection at debugger
35803startup.
35804
35805The command returns a list of strings, with each string naming an
35806available feature.  Each returned string is just a name, it does not
35807have any internal structure.  The list of possible feature names
35808is given below.
35809
35810Example output:
35811
35812@smallexample
35813(gdb) -list-features
35814^done,result=["feature1","feature2"]
35815@end smallexample
35816
35817The current list of features is:
35818
35819@ftable @samp
35820@item frozen-varobjs
35821Indicates support for the @code{-var-set-frozen} command, as well
35822as possible presence of the @code{frozen} field in the output
35823of @code{-varobj-create}.
35824@item pending-breakpoints
35825Indicates support for the @option{-f} option to the @code{-break-insert}
35826command.
35827@item python
35828Indicates Python scripting support, Python-based
35829pretty-printing commands, and possible presence of the
35830@samp{display_hint} field in the output of @code{-var-list-children}
35831@item thread-info
35832Indicates support for the @code{-thread-info} command.
35833@item data-read-memory-bytes
35834Indicates support for the @code{-data-read-memory-bytes} and the
35835@code{-data-write-memory-bytes} commands.
35836@item breakpoint-notifications
35837Indicates that changes to breakpoints and breakpoints created via the
35838CLI will be announced via async records.
35839@item ada-task-info
35840Indicates support for the @code{-ada-task-info} command.
35841@item language-option
35842Indicates that all @sc{gdb/mi} commands accept the @option{--language}
35843option (@pxref{Context management}).
35844@item info-gdb-mi-command
35845Indicates support for the @code{-info-gdb-mi-command} command.
35846@item undefined-command-error-code
35847Indicates support for the "undefined-command" error code in error result
35848records, produced when trying to execute an undefined @sc{gdb/mi} command
35849(@pxref{GDB/MI Result Records}).
35850@item exec-run-start-option
35851Indicates that the @code{-exec-run} command supports the @option{--start}
35852option (@pxref{GDB/MI Program Execution}).
35853@item data-disassemble-a-option
35854Indicates that the @code{-data-disassemble} command supports the @option{-a}
35855option (@pxref{GDB/MI Data Manipulation}).
35856@end ftable
35857
35858@subheading The @code{-list-target-features} Command
35859@findex -list-target-features
35860
35861Returns a list of particular features that are supported by the
35862target.  Those features affect the permitted MI commands, but
35863unlike the features reported by the @code{-list-features} command, the
35864features depend on which target GDB is using at the moment.  Whenever
35865a target can change, due to commands such as @code{-target-select},
35866@code{-target-attach} or @code{-exec-run}, the list of target features
35867may change, and the frontend should obtain it again.
35868Example output:
35869
35870@smallexample
35871(gdb) -list-target-features
35872^done,result=["async"]
35873@end smallexample
35874
35875The current list of features is:
35876
35877@table @samp
35878@item async
35879Indicates that the target is capable of asynchronous command
35880execution, which means that @value{GDBN} will accept further commands
35881while the target is running.
35882
35883@item reverse
35884Indicates that the target is capable of reverse execution.
35885@xref{Reverse Execution}, for more information.
35886
35887@end table
35888
35889@c %%%%%%%%%%%%%%%%%%%%%%%%%%%% SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35890@node GDB/MI Miscellaneous Commands
35891@section Miscellaneous @sc{gdb/mi} Commands
35892
35893@c @subheading -gdb-complete
35894
35895@subheading The @code{-gdb-exit} Command
35896@findex -gdb-exit
35897
35898@subsubheading Synopsis
35899
35900@smallexample
35901 -gdb-exit
35902@end smallexample
35903
35904Exit @value{GDBN} immediately.
35905
35906@subsubheading @value{GDBN} Command
35907
35908Approximately corresponds to @samp{quit}.
35909
35910@subsubheading Example
35911
35912@smallexample
35913(gdb)
35914-gdb-exit
35915^exit
35916@end smallexample
35917
35918
35919@ignore
35920@subheading The @code{-exec-abort} Command
35921@findex -exec-abort
35922
35923@subsubheading Synopsis
35924
35925@smallexample
35926 -exec-abort
35927@end smallexample
35928
35929Kill the inferior running program.
35930
35931@subsubheading @value{GDBN} Command
35932
35933The corresponding @value{GDBN} command is @samp{kill}.
35934
35935@subsubheading Example
35936N.A.
35937@end ignore
35938
35939
35940@subheading The @code{-gdb-set} Command
35941@findex -gdb-set
35942
35943@subsubheading Synopsis
35944
35945@smallexample
35946 -gdb-set
35947@end smallexample
35948
35949Set an internal @value{GDBN} variable.
35950@c IS THIS A DOLLAR VARIABLE? OR SOMETHING LIKE ANNOTATE ?????
35951
35952@subsubheading @value{GDBN} Command
35953
35954The corresponding @value{GDBN} command is @samp{set}.
35955
35956@subsubheading Example
35957
35958@smallexample
35959(gdb)
35960-gdb-set $foo=3
35961^done
35962(gdb)
35963@end smallexample
35964
35965
35966@subheading The @code{-gdb-show} Command
35967@findex -gdb-show
35968
35969@subsubheading Synopsis
35970
35971@smallexample
35972 -gdb-show
35973@end smallexample
35974
35975Show the current value of a @value{GDBN} variable.
35976
35977@subsubheading @value{GDBN} Command
35978
35979The corresponding @value{GDBN} command is @samp{show}.
35980
35981@subsubheading Example
35982
35983@smallexample
35984(gdb)
35985-gdb-show annotate
35986^done,value="0"
35987(gdb)
35988@end smallexample
35989
35990@c @subheading -gdb-source
35991
35992
35993@subheading The @code{-gdb-version} Command
35994@findex -gdb-version
35995
35996@subsubheading Synopsis
35997
35998@smallexample
35999 -gdb-version
36000@end smallexample
36001
36002Show version information for @value{GDBN}.  Used mostly in testing.
36003
36004@subsubheading @value{GDBN} Command
36005
36006The @value{GDBN} equivalent is @samp{show version}.  @value{GDBN} by
36007default shows this information when you start an interactive session.
36008
36009@subsubheading Example
36010
36011@c This example modifies the actual output from GDB to avoid overfull
36012@c box in TeX.
36013@smallexample
36014(gdb)
36015-gdb-version
36016~GNU gdb 5.2.1
36017~Copyright 2000 Free Software Foundation, Inc.
36018~GDB is free software, covered by the GNU General Public License, and
36019~you are welcome to change it and/or distribute copies of it under
36020~ certain conditions.
36021~Type "show copying" to see the conditions.
36022~There is absolutely no warranty for GDB.  Type "show warranty" for
36023~ details.
36024~This GDB was configured as
36025 "--host=sparc-sun-solaris2.5.1 --target=ppc-eabi".
36026^done
36027(gdb)
36028@end smallexample
36029
36030@subheading The @code{-list-thread-groups} Command
36031@findex -list-thread-groups
36032
36033@subheading Synopsis
36034
36035@smallexample
36036-list-thread-groups [ --available ] [ --recurse 1 ] [ @var{group} ... ]
36037@end smallexample
36038
36039Lists thread groups (@pxref{Thread groups}).  When a single thread
36040group is passed as the argument, lists the children of that group.
36041When several thread group are passed, lists information about those
36042thread groups.  Without any parameters, lists information about all
36043top-level thread groups.
36044
36045Normally, thread groups that are being debugged are reported.
36046With the @samp{--available} option, @value{GDBN} reports thread groups
36047available on the target.
36048
36049The output of this command may have either a @samp{threads} result or
36050a @samp{groups} result.  The @samp{thread} result has a list of tuples
36051as value, with each tuple describing a thread (@pxref{GDB/MI Thread
36052Information}).  The @samp{groups} result has a list of tuples as value,
36053each tuple describing a thread group.  If top-level groups are
36054requested (that is, no parameter is passed), or when several groups
36055are passed, the output always has a @samp{groups} result.  The format
36056of the @samp{group} result is described below.
36057
36058To reduce the number of roundtrips it's possible to list thread groups
36059together with their children, by passing the @samp{--recurse} option
36060and the recursion depth.  Presently, only recursion depth of 1 is
36061permitted.  If this option is present, then every reported thread group
36062will also include its children, either as @samp{group} or
36063@samp{threads} field.
36064
36065In general, any combination of option and parameters is permitted, with
36066the following caveats:
36067
36068@itemize @bullet
36069@item
36070When a single thread group is passed, the output will typically
36071be the @samp{threads} result.  Because threads may not contain
36072anything, the @samp{recurse} option will be ignored.
36073
36074@item
36075When the @samp{--available} option is passed, limited information may
36076be available.  In particular, the list of threads of a process might
36077be inaccessible.  Further, specifying specific thread groups might
36078not give any performance advantage over listing all thread groups.
36079The frontend should assume that @samp{-list-thread-groups --available}
36080is always an expensive operation and cache the results.
36081
36082@end itemize
36083
36084The @samp{groups} result is a list of tuples, where each tuple may
36085have the following fields:
36086
36087@table @code
36088@item id
36089Identifier of the thread group.  This field is always present.
36090The identifier is an opaque string; frontends should not try to
36091convert it to an integer, even though it might look like one.
36092
36093@item type
36094The type of the thread group.  At present, only @samp{process} is a
36095valid type.
36096
36097@item pid
36098The target-specific process identifier.  This field is only present
36099for thread groups of type @samp{process} and only if the process exists.
36100
36101@item exit-code
36102The exit code of this group's last exited thread, formatted in octal.
36103This field is only present for thread groups of type @samp{process} and
36104only if the process is not running.
36105
36106@item num_children
36107The number of children this thread group has.  This field may be
36108absent for an available thread group.
36109
36110@item threads
36111This field has a list of tuples as value, each tuple describing a
36112thread.  It may be present if the @samp{--recurse} option is
36113specified, and it's actually possible to obtain the threads.
36114
36115@item cores
36116This field is a list of integers, each identifying a core that one
36117thread of the group is running on.  This field may be absent if
36118such information is not available.
36119
36120@item executable
36121The name of the executable file that corresponds to this thread group.
36122The field is only present for thread groups of type @samp{process},
36123and only if there is a corresponding executable file.
36124
36125@end table
36126
36127@subheading Example
36128
36129@smallexample
36130@value{GDBP}
36131-list-thread-groups
36132^done,groups=[@{id="17",type="process",pid="yyy",num_children="2"@}]
36133-list-thread-groups 17
36134^done,threads=[@{id="2",target-id="Thread 0xb7e14b90 (LWP 21257)",
36135   frame=@{level="0",addr="0xffffe410",func="__kernel_vsyscall",args=[]@},state="running"@},
36136@{id="1",target-id="Thread 0xb7e156b0 (LWP 21254)",
36137   frame=@{level="0",addr="0x0804891f",func="foo",args=[@{name="i",value="10"@}],
36138           file="/tmp/a.c",fullname="/tmp/a.c",line="158",arch="i386:x86_64"@},state="running"@}]]
36139-list-thread-groups --available
36140^done,groups=[@{id="17",type="process",pid="yyy",num_children="2",cores=[1,2]@}]
36141-list-thread-groups --available --recurse 1
36142 ^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
36143                threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
36144                         @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},..]
36145-list-thread-groups --available --recurse 1 17 18
36146^done,groups=[@{id="17", types="process",pid="yyy",num_children="2",cores=[1,2],
36147               threads=[@{id="1",target-id="Thread 0xb7e14b90",cores=[1]@},
36148                        @{id="2",target-id="Thread 0xb7e14b90",cores=[2]@}]@},...]
36149@end smallexample
36150
36151@subheading The @code{-info-os} Command
36152@findex -info-os
36153
36154@subsubheading Synopsis
36155
36156@smallexample
36157-info-os [ @var{type} ]
36158@end smallexample
36159
36160If no argument is supplied, the command returns a table of available
36161operating-system-specific information types.  If one of these types is
36162supplied as an argument @var{type}, then the command returns a table
36163of data of that type.
36164
36165The types of information available depend on the target operating
36166system.
36167
36168@subsubheading @value{GDBN} Command
36169
36170The corresponding @value{GDBN} command is @samp{info os}.
36171
36172@subsubheading Example
36173
36174When run on a @sc{gnu}/Linux system, the output will look something
36175like this:
36176
36177@smallexample
36178@value{GDBP}
36179-info-os
36180^done,OSDataTable=@{nr_rows="10",nr_cols="3",
36181hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="Type"@},
36182     @{width="10",alignment="-1",col_name="col1",colhdr="Description"@},
36183     @{width="10",alignment="-1",col_name="col2",colhdr="Title"@}],
36184body=[item=@{col0="cpus",col1="Listing of all cpus/cores on the system",
36185            col2="CPUs"@},
36186      item=@{col0="files",col1="Listing of all file descriptors",
36187            col2="File descriptors"@},
36188      item=@{col0="modules",col1="Listing of all loaded kernel modules",
36189            col2="Kernel modules"@},
36190      item=@{col0="msg",col1="Listing of all message queues",
36191            col2="Message queues"@},
36192      item=@{col0="processes",col1="Listing of all processes",
36193            col2="Processes"@},
36194      item=@{col0="procgroups",col1="Listing of all process groups",
36195            col2="Process groups"@},
36196      item=@{col0="semaphores",col1="Listing of all semaphores",
36197            col2="Semaphores"@},
36198      item=@{col0="shm",col1="Listing of all shared-memory regions",
36199            col2="Shared-memory regions"@},
36200      item=@{col0="sockets",col1="Listing of all internet-domain sockets",
36201            col2="Sockets"@},
36202      item=@{col0="threads",col1="Listing of all threads",
36203            col2="Threads"@}]
36204@value{GDBP}
36205-info-os processes
36206^done,OSDataTable=@{nr_rows="190",nr_cols="4",
36207hdr=[@{width="10",alignment="-1",col_name="col0",colhdr="pid"@},
36208     @{width="10",alignment="-1",col_name="col1",colhdr="user"@},
36209     @{width="10",alignment="-1",col_name="col2",colhdr="command"@},
36210     @{width="10",alignment="-1",col_name="col3",colhdr="cores"@}],
36211body=[item=@{col0="1",col1="root",col2="/sbin/init",col3="0"@},
36212      item=@{col0="2",col1="root",col2="[kthreadd]",col3="1"@},
36213      item=@{col0="3",col1="root",col2="[ksoftirqd/0]",col3="0"@},
36214      ...
36215      item=@{col0="26446",col1="stan",col2="bash",col3="0"@},
36216      item=@{col0="28152",col1="stan",col2="bash",col3="1"@}]@}
36217(gdb)
36218@end smallexample
36219
36220(Note that the MI output here includes a @code{"Title"} column that
36221does not appear in command-line @code{info os}; this column is useful
36222for MI clients that want to enumerate the types of data, such as in a
36223popup menu, but is needless clutter on the command line, and
36224@code{info os} omits it.)
36225
36226@subheading The @code{-add-inferior} Command
36227@findex -add-inferior
36228
36229@subheading Synopsis
36230
36231@smallexample
36232-add-inferior
36233@end smallexample
36234
36235Creates a new inferior (@pxref{Inferiors Connections and Programs}).  The created
36236inferior is not associated with any executable.  Such association may
36237be established with the @samp{-file-exec-and-symbols} command
36238(@pxref{GDB/MI File Commands}).  The command response has a single
36239field, @samp{inferior}, whose value is the identifier of the
36240thread group corresponding to the new inferior.
36241
36242@subheading Example
36243
36244@smallexample
36245@value{GDBP}
36246-add-inferior
36247^done,inferior="i3"
36248@end smallexample
36249
36250@subheading The @code{-interpreter-exec} Command
36251@findex -interpreter-exec
36252
36253@subheading Synopsis
36254
36255@smallexample
36256-interpreter-exec @var{interpreter} @var{command}
36257@end smallexample
36258@anchor{-interpreter-exec}
36259
36260Execute the specified @var{command} in the given @var{interpreter}.
36261
36262@subheading @value{GDBN} Command
36263
36264The corresponding @value{GDBN} command is @samp{interpreter-exec}.
36265
36266@subheading Example
36267
36268@smallexample
36269(gdb)
36270-interpreter-exec console "break main"
36271&"During symbol reading, couldn't parse type; debugger out of date?.\n"
36272&"During symbol reading, bad structure-type format.\n"
36273~"Breakpoint 1 at 0x8074fc6: file ../../src/gdb/main.c, line 743.\n"
36274^done
36275(gdb)
36276@end smallexample
36277
36278@subheading The @code{-inferior-tty-set} Command
36279@findex -inferior-tty-set
36280
36281@subheading Synopsis
36282
36283@smallexample
36284-inferior-tty-set /dev/pts/1
36285@end smallexample
36286
36287Set terminal for future runs of the program being debugged.
36288
36289@subheading @value{GDBN} Command
36290
36291The corresponding @value{GDBN} command is @samp{set inferior-tty} /dev/pts/1.
36292
36293@subheading Example
36294
36295@smallexample
36296(gdb)
36297-inferior-tty-set /dev/pts/1
36298^done
36299(gdb)
36300@end smallexample
36301
36302@subheading The @code{-inferior-tty-show} Command
36303@findex -inferior-tty-show
36304
36305@subheading Synopsis
36306
36307@smallexample
36308-inferior-tty-show
36309@end smallexample
36310
36311Show terminal for future runs of program being debugged.
36312
36313@subheading @value{GDBN} Command
36314
36315The corresponding @value{GDBN} command is @samp{show inferior-tty}.
36316
36317@subheading Example
36318
36319@smallexample
36320(gdb)
36321-inferior-tty-set /dev/pts/1
36322^done
36323(gdb)
36324-inferior-tty-show
36325^done,inferior_tty_terminal="/dev/pts/1"
36326(gdb)
36327@end smallexample
36328
36329@subheading The @code{-enable-timings} Command
36330@findex -enable-timings
36331
36332@subheading Synopsis
36333
36334@smallexample
36335-enable-timings [yes | no]
36336@end smallexample
36337
36338Toggle the printing of the wallclock, user and system times for an MI
36339command as a field in its output.  This command is to help frontend
36340developers optimize the performance of their code.  No argument is
36341equivalent to @samp{yes}.
36342
36343@subheading @value{GDBN} Command
36344
36345No equivalent.
36346
36347@subheading Example
36348
36349@smallexample
36350(gdb)
36351-enable-timings
36352^done
36353(gdb)
36354-break-insert main
36355^done,bkpt=@{number="1",type="breakpoint",disp="keep",enabled="y",
36356addr="0x080484ed",func="main",file="myprog.c",
36357fullname="/home/nickrob/myprog.c",line="73",thread-groups=["i1"],
36358times="0"@},
36359time=@{wallclock="0.05185",user="0.00800",system="0.00000"@}
36360(gdb)
36361-enable-timings no
36362^done
36363(gdb)
36364-exec-run
36365^running
36366(gdb)
36367*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",thread-id="0",
36368frame=@{addr="0x080484ed",func="main",args=[@{name="argc",value="1"@},
36369@{name="argv",value="0xbfb60364"@}],file="myprog.c",
36370fullname="/home/nickrob/myprog.c",line="73",arch="i386:x86_64"@}
36371(gdb)
36372@end smallexample
36373
36374@subheading The @code{-complete} Command
36375@findex -complete
36376
36377@subheading Synopsis
36378
36379@smallexample
36380-complete @var{command}
36381@end smallexample
36382
36383Show a list of completions for partially typed CLI @var{command}.
36384
36385This command is intended for @sc{gdb/mi} frontends that cannot use two separate
36386CLI and MI channels --- for example: because of lack of PTYs like on Windows or
36387because @value{GDBN} is used remotely via a SSH connection.
36388
36389@subheading Result
36390
36391The result consists of two or three fields:
36392
36393@table @samp
36394@item completion
36395This field contains the completed @var{command}.  If @var{command}
36396has no known completions, this field is omitted.
36397
36398@item matches
36399This field contains a (possibly empty) array of matches.  It is always present.
36400
36401@item max_completions_reached
36402This field contains @code{1} if number of known completions is above
36403@code{max-completions} limit (@pxref{Completion}), otherwise it contains
36404@code{0}.  It is always present.
36405
36406@end table
36407
36408@subheading @value{GDBN} Command
36409
36410The corresponding @value{GDBN} command is @samp{complete}.
36411
36412@subheading Example
36413
36414@smallexample
36415(gdb)
36416-complete br
36417^done,completion="break",
36418      matches=["break","break-range"],
36419      max_completions_reached="0"
36420(gdb)
36421-complete "b ma"
36422^done,completion="b ma",
36423      matches=["b madvise","b main"],max_completions_reached="0"
36424(gdb)
36425-complete "b push_b"
36426^done,completion="b push_back(",
36427      matches=[
36428       "b A::push_back(void*)",
36429       "b std::string::push_back(char)",
36430       "b std::vector<int, std::allocator<int> >::push_back(int&&)"],
36431      max_completions_reached="0"
36432(gdb)
36433-complete "nonexist"
36434^done,matches=[],max_completions_reached="0"
36435(gdb)
36436
36437@end smallexample
36438
36439@node Annotations
36440@chapter @value{GDBN} Annotations
36441
36442This chapter describes annotations in @value{GDBN}.  Annotations were
36443designed to interface @value{GDBN} to graphical user interfaces or other
36444similar programs which want to interact with @value{GDBN} at a
36445relatively high level.
36446
36447The annotation mechanism has largely been superseded by @sc{gdb/mi}
36448(@pxref{GDB/MI}).
36449
36450@ignore
36451This is Edition @value{EDITION}, @value{DATE}.
36452@end ignore
36453
36454@menu
36455* Annotations Overview::  What annotations are; the general syntax.
36456* Server Prefix::       Issuing a command without affecting user state.
36457* Prompting::           Annotations marking @value{GDBN}'s need for input.
36458* Errors::              Annotations for error messages.
36459* Invalidation::        Some annotations describe things now invalid.
36460* Annotations for Running::
36461                        Whether the program is running, how it stopped, etc.
36462* Source Annotations::  Annotations describing source code.
36463@end menu
36464
36465@node Annotations Overview
36466@section What is an Annotation?
36467@cindex annotations
36468
36469Annotations start with a newline character, two @samp{control-z}
36470characters, and the name of the annotation.  If there is no additional
36471information associated with this annotation, the name of the annotation
36472is followed immediately by a newline.  If there is additional
36473information, the name of the annotation is followed by a space, the
36474additional information, and a newline.  The additional information
36475cannot contain newline characters.
36476
36477Any output not beginning with a newline and two @samp{control-z}
36478characters denotes literal output from @value{GDBN}.  Currently there is
36479no need for @value{GDBN} to output a newline followed by two
36480@samp{control-z} characters, but if there was such a need, the
36481annotations could be extended with an @samp{escape} annotation which
36482means those three characters as output.
36483
36484The annotation @var{level}, which is specified using the
36485@option{--annotate} command line option (@pxref{Mode Options}), controls
36486how much information @value{GDBN} prints together with its prompt,
36487values of expressions, source lines, and other types of output.  Level 0
36488is for no annotations, level 1 is for use when @value{GDBN} is run as a
36489subprocess of @sc{gnu} Emacs, level 3 is the maximum annotation suitable
36490for programs that control @value{GDBN}, and level 2 annotations have
36491been made obsolete (@pxref{Limitations, , Limitations of the Annotation
36492Interface, annotate, GDB's Obsolete Annotations}).
36493
36494@table @code
36495@kindex set annotate
36496@item set annotate @var{level}
36497The @value{GDBN} command @code{set annotate} sets the level of
36498annotations to the specified @var{level}.
36499
36500@item show annotate
36501@kindex show annotate
36502Show the current annotation level.
36503@end table
36504
36505This chapter describes level 3 annotations.
36506
36507A simple example of starting up @value{GDBN} with annotations is:
36508
36509@smallexample
36510$ @kbd{gdb --annotate=3}
36511GNU gdb 6.0
36512Copyright 2003 Free Software Foundation, Inc.
36513GDB is free software, covered by the GNU General Public License,
36514and you are welcome to change it and/or distribute copies of it
36515under certain conditions.
36516Type "show copying" to see the conditions.
36517There is absolutely no warranty for GDB.  Type "show warranty"
36518for details.
36519This GDB was configured as "i386-pc-linux-gnu"
36520
36521^Z^Zpre-prompt
36522(@value{GDBP})
36523^Z^Zprompt
36524@kbd{quit}
36525
36526^Z^Zpost-prompt
36527$
36528@end smallexample
36529
36530Here @samp{quit} is input to @value{GDBN}; the rest is output from
36531@value{GDBN}.  The three lines beginning @samp{^Z^Z} (where @samp{^Z}
36532denotes a @samp{control-z} character) are annotations; the rest is
36533output from @value{GDBN}.
36534
36535@node Server Prefix
36536@section The Server Prefix
36537@cindex server prefix
36538
36539If you prefix a command with @samp{server } then it will not affect
36540the command history, nor will it affect @value{GDBN}'s notion of which
36541command to repeat if @key{RET} is pressed on a line by itself.  This
36542means that commands can be run behind a user's back by a front-end in
36543a transparent manner.
36544
36545The @code{server } prefix does not affect the recording of values into
36546the value history; to print a value without recording it into the
36547value history, use the @code{output} command instead of the
36548@code{print} command.
36549
36550Using this prefix also disables confirmation requests
36551(@pxref{confirmation requests}).
36552
36553@node Prompting
36554@section Annotation for @value{GDBN} Input
36555
36556@cindex annotations for prompts
36557When @value{GDBN} prompts for input, it annotates this fact so it is possible
36558to know when to send output, when the output from a given command is
36559over, etc.
36560
36561Different kinds of input each have a different @dfn{input type}.  Each
36562input type has three annotations: a @code{pre-} annotation, which
36563denotes the beginning of any prompt which is being output, a plain
36564annotation, which denotes the end of the prompt, and then a @code{post-}
36565annotation which denotes the end of any echo which may (or may not) be
36566associated with the input.  For example, the @code{prompt} input type
36567features the following annotations:
36568
36569@smallexample
36570^Z^Zpre-prompt
36571^Z^Zprompt
36572^Z^Zpost-prompt
36573@end smallexample
36574
36575The input types are
36576
36577@table @code
36578@findex pre-prompt annotation
36579@findex prompt annotation
36580@findex post-prompt annotation
36581@item prompt
36582When @value{GDBN} is prompting for a command (the main @value{GDBN} prompt).
36583
36584@findex pre-commands annotation
36585@findex commands annotation
36586@findex post-commands annotation
36587@item commands
36588When @value{GDBN} prompts for a set of commands, like in the @code{commands}
36589command.  The annotations are repeated for each command which is input.
36590
36591@findex pre-overload-choice annotation
36592@findex overload-choice annotation
36593@findex post-overload-choice annotation
36594@item overload-choice
36595When @value{GDBN} wants the user to select between various overloaded functions.
36596
36597@findex pre-query annotation
36598@findex query annotation
36599@findex post-query annotation
36600@item query
36601When @value{GDBN} wants the user to confirm a potentially dangerous operation.
36602
36603@findex pre-prompt-for-continue annotation
36604@findex prompt-for-continue annotation
36605@findex post-prompt-for-continue annotation
36606@item prompt-for-continue
36607When @value{GDBN} is asking the user to press return to continue.  Note: Don't
36608expect this to work well; instead use @code{set height 0} to disable
36609prompting.  This is because the counting of lines is buggy in the
36610presence of annotations.
36611@end table
36612
36613@node Errors
36614@section Errors
36615@cindex annotations for errors, warnings and interrupts
36616
36617@findex quit annotation
36618@smallexample
36619^Z^Zquit
36620@end smallexample
36621
36622This annotation occurs right before @value{GDBN} responds to an interrupt.
36623
36624@findex error annotation
36625@smallexample
36626^Z^Zerror
36627@end smallexample
36628
36629This annotation occurs right before @value{GDBN} responds to an error.
36630
36631Quit and error annotations indicate that any annotations which @value{GDBN} was
36632in the middle of may end abruptly.  For example, if a
36633@code{value-history-begin} annotation is followed by a @code{error}, one
36634cannot expect to receive the matching @code{value-history-end}.  One
36635cannot expect not to receive it either, however; an error annotation
36636does not necessarily mean that @value{GDBN} is immediately returning all the way
36637to the top level.
36638
36639@findex error-begin annotation
36640A quit or error annotation may be preceded by
36641
36642@smallexample
36643^Z^Zerror-begin
36644@end smallexample
36645
36646Any output between that and the quit or error annotation is the error
36647message.
36648
36649Warning messages are not yet annotated.
36650@c If we want to change that, need to fix warning(), type_error(),
36651@c range_error(), and possibly other places.
36652
36653@node Invalidation
36654@section Invalidation Notices
36655
36656@cindex annotations for invalidation messages
36657The following annotations say that certain pieces of state may have
36658changed.
36659
36660@table @code
36661@findex frames-invalid annotation
36662@item ^Z^Zframes-invalid
36663
36664The frames (for example, output from the @code{backtrace} command) may
36665have changed.
36666
36667@findex breakpoints-invalid annotation
36668@item ^Z^Zbreakpoints-invalid
36669
36670The breakpoints may have changed.  For example, the user just added or
36671deleted a breakpoint.
36672@end table
36673
36674@node Annotations for Running
36675@section Running the Program
36676@cindex annotations for running programs
36677
36678@findex starting annotation
36679@findex stopping annotation
36680When the program starts executing due to a @value{GDBN} command such as
36681@code{step} or @code{continue},
36682
36683@smallexample
36684^Z^Zstarting
36685@end smallexample
36686
36687is output.  When the program stops,
36688
36689@smallexample
36690^Z^Zstopped
36691@end smallexample
36692
36693is output.  Before the @code{stopped} annotation, a variety of
36694annotations describe how the program stopped.
36695
36696@table @code
36697@findex exited annotation
36698@item ^Z^Zexited @var{exit-status}
36699The program exited, and @var{exit-status} is the exit status (zero for
36700successful exit, otherwise nonzero).
36701
36702@findex signalled annotation
36703@findex signal-name annotation
36704@findex signal-name-end annotation
36705@findex signal-string annotation
36706@findex signal-string-end annotation
36707@item ^Z^Zsignalled
36708The program exited with a signal.  After the @code{^Z^Zsignalled}, the
36709annotation continues:
36710
36711@smallexample
36712@var{intro-text}
36713^Z^Zsignal-name
36714@var{name}
36715^Z^Zsignal-name-end
36716@var{middle-text}
36717^Z^Zsignal-string
36718@var{string}
36719^Z^Zsignal-string-end
36720@var{end-text}
36721@end smallexample
36722
36723@noindent
36724where @var{name} is the name of the signal, such as @code{SIGILL} or
36725@code{SIGSEGV}, and @var{string} is the explanation of the signal, such
36726as @code{Illegal Instruction} or @code{Segmentation fault}.  The arguments
36727@var{intro-text}, @var{middle-text}, and @var{end-text} are for the
36728user's benefit and have no particular format.
36729
36730@findex signal annotation
36731@item ^Z^Zsignal
36732The syntax of this annotation is just like @code{signalled}, but @value{GDBN} is
36733just saying that the program received the signal, not that it was
36734terminated with it.
36735
36736@findex breakpoint annotation
36737@item ^Z^Zbreakpoint @var{number}
36738The program hit breakpoint number @var{number}.
36739
36740@findex watchpoint annotation
36741@item ^Z^Zwatchpoint @var{number}
36742The program hit watchpoint number @var{number}.
36743@end table
36744
36745@node Source Annotations
36746@section Displaying Source
36747@cindex annotations for source display
36748
36749@findex source annotation
36750The following annotation is used instead of displaying source code:
36751
36752@smallexample
36753^Z^Zsource @var{filename}:@var{line}:@var{character}:@var{middle}:@var{addr}
36754@end smallexample
36755
36756where @var{filename} is an absolute file name indicating which source
36757file, @var{line} is the line number within that file (where 1 is the
36758first line in the file), @var{character} is the character position
36759within the file (where 0 is the first character in the file) (for most
36760debug formats this will necessarily point to the beginning of a line),
36761@var{middle} is @samp{middle} if @var{addr} is in the middle of the
36762line, or @samp{beg} if @var{addr} is at the beginning of the line, and
36763@var{addr} is the address in the target program associated with the
36764source which is being displayed.  The @var{addr} is in the form @samp{0x}
36765followed by one or more lowercase hex digits (note that this does not
36766depend on the language).
36767
36768@node JIT Interface
36769@chapter JIT Compilation Interface
36770@cindex just-in-time compilation
36771@cindex JIT compilation interface
36772
36773This chapter documents @value{GDBN}'s @dfn{just-in-time} (JIT) compilation
36774interface.  A JIT compiler is a program or library that generates native
36775executable code at runtime and executes it, usually in order to achieve good
36776performance while maintaining platform independence.
36777
36778Programs that use JIT compilation are normally difficult to debug because
36779portions of their code are generated at runtime, instead of being loaded from
36780object files, which is where @value{GDBN} normally finds the program's symbols
36781and debug information.  In order to debug programs that use JIT compilation,
36782@value{GDBN} has an interface that allows the program to register in-memory
36783symbol files with @value{GDBN} at runtime.
36784
36785If you are using @value{GDBN} to debug a program that uses this interface, then
36786it should work transparently so long as you have not stripped the binary.  If
36787you are developing a JIT compiler, then the interface is documented in the rest
36788of this chapter.  At this time, the only known client of this interface is the
36789LLVM JIT.
36790
36791Broadly speaking, the JIT interface mirrors the dynamic loader interface.  The
36792JIT compiler communicates with @value{GDBN} by writing data into a global
36793variable and calling a function at a well-known symbol.  When @value{GDBN}
36794attaches, it reads a linked list of symbol files from the global variable to
36795find existing code, and puts a breakpoint in the function so that it can find
36796out about additional code.
36797
36798@menu
36799* Declarations::                Relevant C struct declarations
36800* Registering Code::            Steps to register code
36801* Unregistering Code::          Steps to unregister code
36802* Custom Debug Info::           Emit debug information in a custom format
36803@end menu
36804
36805@node Declarations
36806@section JIT Declarations
36807
36808These are the relevant struct declarations that a C program should include to
36809implement the interface:
36810
36811@smallexample
36812typedef enum
36813@{
36814  JIT_NOACTION = 0,
36815  JIT_REGISTER_FN,
36816  JIT_UNREGISTER_FN
36817@} jit_actions_t;
36818
36819struct jit_code_entry
36820@{
36821  struct jit_code_entry *next_entry;
36822  struct jit_code_entry *prev_entry;
36823  const char *symfile_addr;
36824  uint64_t symfile_size;
36825@};
36826
36827struct jit_descriptor
36828@{
36829  uint32_t version;
36830  /* This type should be jit_actions_t, but we use uint32_t
36831     to be explicit about the bitwidth.  */
36832  uint32_t action_flag;
36833  struct jit_code_entry *relevant_entry;
36834  struct jit_code_entry *first_entry;
36835@};
36836
36837/* GDB puts a breakpoint in this function.  */
36838void __attribute__((noinline)) __jit_debug_register_code() @{ @};
36839
36840/* Make sure to specify the version statically, because the
36841   debugger may check the version before we can set it.  */
36842struct jit_descriptor __jit_debug_descriptor = @{ 1, 0, 0, 0 @};
36843@end smallexample
36844
36845If the JIT is multi-threaded, then it is important that the JIT synchronize any
36846modifications to this global data properly, which can easily be done by putting
36847a global mutex around modifications to these structures.
36848
36849@node Registering Code
36850@section Registering Code
36851
36852To register code with @value{GDBN}, the JIT should follow this protocol:
36853
36854@itemize @bullet
36855@item
36856Generate an object file in memory with symbols and other desired debug
36857information.  The file must include the virtual addresses of the sections.
36858
36859@item
36860Create a code entry for the file, which gives the start and size of the symbol
36861file.
36862
36863@item
36864Add it to the linked list in the JIT descriptor.
36865
36866@item
36867Point the relevant_entry field of the descriptor at the entry.
36868
36869@item
36870Set @code{action_flag} to @code{JIT_REGISTER} and call
36871@code{__jit_debug_register_code}.
36872@end itemize
36873
36874When @value{GDBN} is attached and the breakpoint fires, @value{GDBN} uses the
36875@code{relevant_entry} pointer so it doesn't have to walk the list looking for
36876new code.  However, the linked list must still be maintained in order to allow
36877@value{GDBN} to attach to a running process and still find the symbol files.
36878
36879@node Unregistering Code
36880@section Unregistering Code
36881
36882If code is freed, then the JIT should use the following protocol:
36883
36884@itemize @bullet
36885@item
36886Remove the code entry corresponding to the code from the linked list.
36887
36888@item
36889Point the @code{relevant_entry} field of the descriptor at the code entry.
36890
36891@item
36892Set @code{action_flag} to @code{JIT_UNREGISTER} and call
36893@code{__jit_debug_register_code}.
36894@end itemize
36895
36896If the JIT frees or recompiles code without unregistering it, then @value{GDBN}
36897and the JIT will leak the memory used for the associated symbol files.
36898
36899@node Custom Debug Info
36900@section Custom Debug Info
36901@cindex custom JIT debug info
36902@cindex JIT debug info reader
36903
36904Generating debug information in platform-native file formats (like ELF
36905or COFF) may be an overkill for JIT compilers; especially if all the
36906debug info is used for is displaying a meaningful backtrace.  The
36907issue can be resolved by having the JIT writers decide on a debug info
36908format and also provide a reader that parses the debug info generated
36909by the JIT compiler.  This section gives a brief overview on writing
36910such a parser.  More specific details can be found in the source file
36911@file{gdb/jit-reader.in}, which is also installed as a header at
36912@file{@var{includedir}/gdb/jit-reader.h} for easy inclusion.
36913
36914The reader is implemented as a shared object (so this functionality is
36915not available on platforms which don't allow loading shared objects at
36916runtime).  Two @value{GDBN} commands, @code{jit-reader-load} and
36917@code{jit-reader-unload} are provided, to be used to load and unload
36918the readers from a preconfigured directory.  Once loaded, the shared
36919object is used the parse the debug information emitted by the JIT
36920compiler.
36921
36922@menu
36923* Using JIT Debug Info Readers::       How to use supplied readers correctly
36924* Writing JIT Debug Info Readers::     Creating a debug-info reader
36925@end menu
36926
36927@node Using JIT Debug Info Readers
36928@subsection Using JIT Debug Info Readers
36929@kindex jit-reader-load
36930@kindex jit-reader-unload
36931
36932Readers can be loaded and unloaded using the @code{jit-reader-load}
36933and @code{jit-reader-unload} commands.
36934
36935@table @code
36936@item jit-reader-load @var{reader}
36937Load the JIT reader named @var{reader}, which is a shared
36938object specified as either an absolute or a relative file name.  In
36939the latter case, @value{GDBN} will try to load the reader from a
36940pre-configured directory, usually @file{@var{libdir}/gdb/} on a UNIX
36941system (here @var{libdir} is the system library directory, often
36942@file{/usr/local/lib}).
36943
36944Only one reader can be active at a time; trying to load a second
36945reader when one is already loaded will result in @value{GDBN}
36946reporting an error.  A new JIT reader can be loaded by first unloading
36947the current one using @code{jit-reader-unload} and then invoking
36948@code{jit-reader-load}.
36949
36950@item jit-reader-unload
36951Unload the currently loaded JIT reader.
36952
36953@end table
36954
36955@node Writing JIT Debug Info Readers
36956@subsection Writing JIT Debug Info Readers
36957@cindex writing JIT debug info readers
36958
36959As mentioned, a reader is essentially a shared object conforming to a
36960certain ABI.  This ABI is described in @file{jit-reader.h}.
36961
36962@file{jit-reader.h} defines the structures, macros and functions
36963required to write a reader.  It is installed (along with
36964@value{GDBN}), in @file{@var{includedir}/gdb} where @var{includedir} is
36965the system include directory.
36966
36967Readers need to be released under a GPL compatible license.  A reader
36968can be declared as released under such a license by placing the macro
36969@code{GDB_DECLARE_GPL_COMPATIBLE_READER} in a source file.
36970
36971The entry point for readers is the symbol @code{gdb_init_reader},
36972which is expected to be a function with the prototype
36973
36974@findex gdb_init_reader
36975@smallexample
36976extern struct gdb_reader_funcs *gdb_init_reader (void);
36977@end smallexample
36978
36979@cindex @code{struct gdb_reader_funcs}
36980
36981@code{struct gdb_reader_funcs} contains a set of pointers to callback
36982functions.  These functions are executed to read the debug info
36983generated by the JIT compiler (@code{read}), to unwind stack frames
36984(@code{unwind}) and to create canonical frame IDs
36985(@code{get_frame_id}).  It also has a callback that is called when the
36986reader is being unloaded (@code{destroy}).  The struct looks like this
36987
36988@smallexample
36989struct gdb_reader_funcs
36990@{
36991  /* Must be set to GDB_READER_INTERFACE_VERSION.  */
36992  int reader_version;
36993
36994  /* For use by the reader.  */
36995  void *priv_data;
36996
36997  gdb_read_debug_info *read;
36998  gdb_unwind_frame *unwind;
36999  gdb_get_frame_id *get_frame_id;
37000  gdb_destroy_reader *destroy;
37001@};
37002@end smallexample
37003
37004@cindex @code{struct gdb_symbol_callbacks}
37005@cindex @code{struct gdb_unwind_callbacks}
37006
37007The callbacks are provided with another set of callbacks by
37008@value{GDBN} to do their job.  For @code{read}, these callbacks are
37009passed in a @code{struct gdb_symbol_callbacks} and for @code{unwind}
37010and @code{get_frame_id}, in a @code{struct gdb_unwind_callbacks}.
37011@code{struct gdb_symbol_callbacks} has callbacks to create new object
37012files and new symbol tables inside those object files.  @code{struct
37013gdb_unwind_callbacks} has callbacks to read registers off the current
37014frame and to write out the values of the registers in the previous
37015frame.  Both have a callback (@code{target_read}) to read bytes off the
37016target's address space.
37017
37018@node In-Process Agent
37019@chapter In-Process Agent
37020@cindex debugging agent
37021The traditional debugging model is conceptually low-speed, but works fine,
37022because most bugs can be reproduced in debugging-mode execution.  However,
37023as multi-core or many-core processors are becoming mainstream, and
37024multi-threaded programs become more and more popular, there should be more
37025and more bugs that only manifest themselves at normal-mode execution, for
37026example, thread races, because debugger's interference with the program's
37027timing may conceal the bugs.  On the other hand, in some applications,
37028it is not feasible for the debugger to interrupt the program's execution
37029long enough for the developer to learn anything helpful about its behavior.
37030If the program's correctness depends on its real-time behavior, delays
37031introduced by a debugger might cause the program to fail, even when the
37032code itself is correct.  It is useful to be able to observe the program's
37033behavior without interrupting it.
37034
37035Therefore, traditional debugging model is too intrusive to reproduce
37036some bugs.  In order to reduce the interference with the program, we can
37037reduce the number of operations performed by debugger.  The
37038@dfn{In-Process Agent}, a shared library, is running within the same
37039process with inferior, and is able to perform some debugging operations
37040itself.  As a result, debugger is only involved when necessary, and
37041performance of debugging can be improved accordingly.  Note that
37042interference with program can be reduced but can't be removed completely,
37043because the in-process agent will still stop or slow down the program.
37044
37045The in-process agent can interpret and execute Agent Expressions
37046(@pxref{Agent Expressions}) during performing debugging operations.  The
37047agent expressions can be used for different purposes, such as collecting
37048data in tracepoints, and condition evaluation in breakpoints.
37049
37050@anchor{Control Agent}
37051You can control whether the in-process agent is used as an aid for
37052debugging with the following commands:
37053
37054@table @code
37055@kindex set agent on
37056@item set agent on
37057Causes the in-process agent to perform some operations on behalf of the
37058debugger.  Just which operations requested by the user will be done
37059by the in-process agent depends on the its capabilities.  For example,
37060if you request to evaluate breakpoint conditions in the in-process agent,
37061and the in-process agent has such capability as well, then breakpoint
37062conditions will be evaluated in the in-process agent.
37063
37064@kindex set agent off
37065@item set agent off
37066Disables execution of debugging operations by the in-process agent.  All
37067of the operations will be performed by @value{GDBN}.
37068
37069@kindex show agent
37070@item show agent
37071Display the current setting of execution of debugging operations by
37072the in-process agent.
37073@end table
37074
37075@menu
37076* In-Process Agent Protocol::
37077@end menu
37078
37079@node In-Process Agent Protocol
37080@section In-Process Agent Protocol
37081@cindex in-process agent protocol
37082
37083The in-process agent is able to communicate with both @value{GDBN} and
37084GDBserver (@pxref{In-Process Agent}).  This section documents the protocol
37085used for communications between @value{GDBN} or GDBserver and the IPA.
37086In general, @value{GDBN} or GDBserver sends commands
37087(@pxref{IPA Protocol Commands}) and data to in-process agent, and then
37088in-process agent replies back with the return result of the command, or
37089some other information.  The data sent to in-process agent is composed
37090of primitive data types, such as 4-byte or 8-byte type, and composite
37091types, which are called objects (@pxref{IPA Protocol Objects}).
37092
37093@menu
37094* IPA Protocol Objects::
37095* IPA Protocol Commands::
37096@end menu
37097
37098@node IPA Protocol Objects
37099@subsection IPA Protocol Objects
37100@cindex ipa protocol objects
37101
37102The commands sent to and results received from agent may contain some
37103complex data types called @dfn{objects}.
37104
37105The in-process agent is running on the same machine with @value{GDBN}
37106or GDBserver, so it doesn't have to handle as much differences between
37107two ends as remote protocol (@pxref{Remote Protocol}) tries to handle.
37108However, there are still some differences of two ends in two processes:
37109
37110@enumerate
37111@item
37112word size.  On some 64-bit machines, @value{GDBN} or GDBserver can be
37113compiled as a 64-bit executable, while in-process agent is a 32-bit one.
37114@item
37115ABI.  Some machines may have multiple types of ABI, @value{GDBN} or
37116GDBserver is compiled with one, and in-process agent is compiled with
37117the other one.
37118@end enumerate
37119
37120Here are the IPA Protocol Objects:
37121
37122@enumerate
37123@item
37124agent expression object.  It represents an agent expression
37125(@pxref{Agent Expressions}).
37126@anchor{agent expression object}
37127@item
37128tracepoint action object.  It represents a tracepoint action
37129(@pxref{Tracepoint Actions,,Tracepoint Action Lists}) to collect registers,
37130memory, static trace data and to evaluate expression.
37131@anchor{tracepoint action object}
37132@item
37133tracepoint object.  It represents a tracepoint (@pxref{Tracepoints}).
37134@anchor{tracepoint object}
37135
37136@end enumerate
37137
37138The following table describes important attributes of each IPA protocol
37139object:
37140
37141@multitable @columnfractions .30 .20 .50
37142@headitem Name @tab Size @tab Description
37143@item @emph{agent expression object} @tab @tab
37144@item length @tab 4 @tab length of bytes code
37145@item byte code @tab @var{length} @tab contents of byte code
37146@item @emph{tracepoint action for collecting memory} @tab @tab
37147@item 'M' @tab 1 @tab type of tracepoint action
37148@item addr @tab 8 @tab if @var{basereg} is @samp{-1}, @var{addr} is the
37149address of the lowest byte to collect, otherwise @var{addr} is the offset
37150of @var{basereg} for memory collecting.
37151@item len @tab 8 @tab length of memory for collecting
37152@item basereg @tab 4 @tab the register number containing the starting
37153memory address for collecting.
37154@item @emph{tracepoint action for collecting registers} @tab @tab
37155@item 'R' @tab 1 @tab type of tracepoint action
37156@item @emph{tracepoint action for collecting static trace data} @tab @tab
37157@item 'L' @tab 1 @tab type of tracepoint action
37158@item @emph{tracepoint action for expression evaluation} @tab @tab
37159@item 'X' @tab 1 @tab type of tracepoint action
37160@item agent expression @tab length of @tab @ref{agent expression object}
37161@item @emph{tracepoint object} @tab @tab
37162@item number @tab 4 @tab number of tracepoint
37163@item address @tab 8 @tab address of tracepoint inserted on
37164@item type @tab 4 @tab type of tracepoint
37165@item enabled @tab 1 @tab enable or disable of tracepoint
37166@item step_count @tab 8 @tab step
37167@item pass_count @tab 8 @tab pass
37168@item numactions @tab 4 @tab number of tracepoint actions
37169@item hit count @tab 8 @tab hit count
37170@item trace frame usage @tab 8 @tab trace frame usage
37171@item compiled_cond @tab 8 @tab compiled condition
37172@item orig_size @tab 8 @tab orig size
37173@item condition @tab 4 if condition is NULL otherwise length of
37174@ref{agent expression object}
37175@tab zero if condition is NULL, otherwise is
37176@ref{agent expression object}
37177@item actions @tab variable
37178@tab numactions number of @ref{tracepoint action object}
37179@end multitable
37180
37181@node IPA Protocol Commands
37182@subsection IPA Protocol Commands
37183@cindex ipa protocol commands
37184
37185The spaces in each command are delimiters to ease reading this commands
37186specification.  They don't exist in real commands.
37187
37188@table @samp
37189
37190@item FastTrace:@var{tracepoint_object} @var{gdb_jump_pad_head}
37191Installs a new fast tracepoint described by @var{tracepoint_object}
37192(@pxref{tracepoint object}).  The @var{gdb_jump_pad_head}, 8-byte long, is the
37193head of @dfn{jumppad}, which is used to jump to data collection routine
37194in IPA finally.
37195
37196Replies:
37197@table @samp
37198@item OK @var{target_address} @var{gdb_jump_pad_head} @var{fjump_size} @var{fjump}
37199@var{target_address} is address of tracepoint in the inferior.
37200The @var{gdb_jump_pad_head} is updated head of jumppad.  Both of
37201@var{target_address} and @var{gdb_jump_pad_head} are 8-byte long.
37202The @var{fjump} contains a sequence of instructions jump to jumppad entry.
37203The @var{fjump_size}, 4-byte long, is the size of @var{fjump}.
37204@item E @var{NN}
37205for an error
37206
37207@end table
37208
37209@item close
37210Closes the in-process agent.  This command is sent when @value{GDBN} or GDBserver
37211is about to kill inferiors.
37212
37213@item qTfSTM
37214@xref{qTfSTM}.
37215@item qTsSTM
37216@xref{qTsSTM}.
37217@item qTSTMat
37218@xref{qTSTMat}.
37219@item probe_marker_at:@var{address}
37220Asks in-process agent to probe the marker at @var{address}.
37221
37222Replies:
37223@table @samp
37224@item E @var{NN}
37225for an error
37226@end table
37227@item unprobe_marker_at:@var{address}
37228Asks in-process agent to unprobe the marker at @var{address}.
37229@end table
37230
37231@node GDB Bugs
37232@chapter Reporting Bugs in @value{GDBN}
37233@cindex bugs in @value{GDBN}
37234@cindex reporting bugs in @value{GDBN}
37235
37236Your bug reports play an essential role in making @value{GDBN} reliable.
37237
37238Reporting a bug may help you by bringing a solution to your problem, or it
37239may not.  But in any case the principal function of a bug report is to help
37240the entire community by making the next version of @value{GDBN} work better.  Bug
37241reports are your contribution to the maintenance of @value{GDBN}.
37242
37243In order for a bug report to serve its purpose, you must include the
37244information that enables us to fix the bug.
37245
37246@menu
37247* Bug Criteria::                Have you found a bug?
37248* Bug Reporting::               How to report bugs
37249@end menu
37250
37251@node Bug Criteria
37252@section Have You Found a Bug?
37253@cindex bug criteria
37254
37255If you are not sure whether you have found a bug, here are some guidelines:
37256
37257@itemize @bullet
37258@cindex fatal signal
37259@cindex debugger crash
37260@cindex crash of debugger
37261@item
37262If the debugger gets a fatal signal, for any input whatever, that is a
37263@value{GDBN} bug.  Reliable debuggers never crash.
37264
37265@cindex error on valid input
37266@item
37267If @value{GDBN} produces an error message for valid input, that is a
37268bug.  (Note that if you're cross debugging, the problem may also be
37269somewhere in the connection to the target.)
37270
37271@cindex invalid input
37272@item
37273If @value{GDBN} does not produce an error message for invalid input,
37274that is a bug.  However, you should note that your idea of
37275``invalid input'' might be our idea of ``an extension'' or ``support
37276for traditional practice''.
37277
37278@item
37279If you are an experienced user of debugging tools, your suggestions
37280for improvement of @value{GDBN} are welcome in any case.
37281@end itemize
37282
37283@node Bug Reporting
37284@section How to Report Bugs
37285@cindex bug reports
37286@cindex @value{GDBN} bugs, reporting
37287
37288A number of companies and individuals offer support for @sc{gnu} products.
37289If you obtained @value{GDBN} from a support organization, we recommend you
37290contact that organization first.
37291
37292You can find contact information for many support companies and
37293individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
37294distribution.
37295@c should add a web page ref...
37296
37297@ifset BUGURL
37298@ifset BUGURL_DEFAULT
37299In any event, we also recommend that you submit bug reports for
37300@value{GDBN}.  The preferred method is to submit them directly using
37301@uref{http://www.gnu.org/software/gdb/bugs/, @value{GDBN}'s Bugs web
37302page}.  Alternatively, the @email{bug-gdb@@gnu.org, e-mail gateway} can
37303be used.
37304
37305@strong{Do not send bug reports to @samp{info-gdb}, or to
37306@samp{help-gdb}, or to any newsgroups.}  Most users of @value{GDBN} do
37307not want to receive bug reports.  Those that do have arranged to receive
37308@samp{bug-gdb}.
37309
37310The mailing list @samp{bug-gdb} has a newsgroup @samp{gnu.gdb.bug} which
37311serves as a repeater.  The mailing list and the newsgroup carry exactly
37312the same messages.  Often people think of posting bug reports to the
37313newsgroup instead of mailing them.  This appears to work, but it has one
37314problem which can be crucial: a newsgroup posting often lacks a mail
37315path back to the sender.  Thus, if we need to ask for more information,
37316we may be unable to reach you.  For this reason, it is better to send
37317bug reports to the mailing list.
37318@end ifset
37319@ifclear BUGURL_DEFAULT
37320In any event, we also recommend that you submit bug reports for
37321@value{GDBN} to @value{BUGURL}.
37322@end ifclear
37323@end ifset
37324
37325The fundamental principle of reporting bugs usefully is this:
37326@strong{report all the facts}.  If you are not sure whether to state a
37327fact or leave it out, state it!
37328
37329Often people omit facts because they think they know what causes the
37330problem and assume that some details do not matter.  Thus, you might
37331assume that the name of the variable you use in an example does not matter.
37332Well, probably it does not, but one cannot be sure.  Perhaps the bug is a
37333stray memory reference which happens to fetch from the location where that
37334name is stored in memory; perhaps, if the name were different, the contents
37335of that location would fool the debugger into doing the right thing despite
37336the bug.  Play it safe and give a specific, complete example.  That is the
37337easiest thing for you to do, and the most helpful.
37338
37339Keep in mind that the purpose of a bug report is to enable us to fix the
37340bug.  It may be that the bug has been reported previously, but neither
37341you nor we can know that unless your bug report is complete and
37342self-contained.
37343
37344Sometimes people give a few sketchy facts and ask, ``Does this ring a
37345bell?''  Those bug reports are useless, and we urge everyone to
37346@emph{refuse to respond to them} except to chide the sender to report
37347bugs properly.
37348
37349To enable us to fix the bug, you should include all these things:
37350
37351@itemize @bullet
37352@item
37353The version of @value{GDBN}.  @value{GDBN} announces it if you start
37354with no arguments; you can also print it at any time using @code{show
37355version}.
37356
37357Without this, we will not know whether there is any point in looking for
37358the bug in the current version of @value{GDBN}.
37359
37360@item
37361The type of machine you are using, and the operating system name and
37362version number.
37363
37364@item
37365The details of the @value{GDBN} build-time configuration.
37366@value{GDBN} shows these details if you invoke it with the
37367@option{--configuration} command-line option, or if you type
37368@code{show configuration} at @value{GDBN}'s prompt.
37369
37370@item
37371What compiler (and its version) was used to compile @value{GDBN}---e.g.@:
37372``@value{GCC}--2.8.1''.
37373
37374@item
37375What compiler (and its version) was used to compile the program you are
37376debugging---e.g.@:  ``@value{GCC}--2.8.1'', or ``HP92453-01 A.10.32.03 HP
37377C Compiler''.  For @value{NGCC}, you can say @kbd{@value{GCC} --version}
37378to get this information; for other compilers, see the documentation for
37379those compilers.
37380
37381@item
37382The command arguments you gave the compiler to compile your example and
37383observe the bug.  For example, did you use @samp{-O}?  To guarantee
37384you will not omit something important, list them all.  A copy of the
37385Makefile (or the output from make) is sufficient.
37386
37387If we were to try to guess the arguments, we would probably guess wrong
37388and then we might not encounter the bug.
37389
37390@item
37391A complete input script, and all necessary source files, that will
37392reproduce the bug.
37393
37394@item
37395A description of what behavior you observe that you believe is
37396incorrect.  For example, ``It gets a fatal signal.''
37397
37398Of course, if the bug is that @value{GDBN} gets a fatal signal, then we
37399will certainly notice it.  But if the bug is incorrect output, we might
37400not notice unless it is glaringly wrong.  You might as well not give us
37401a chance to make a mistake.
37402
37403Even if the problem you experience is a fatal signal, you should still
37404say so explicitly.  Suppose something strange is going on, such as, your
37405copy of @value{GDBN} is out of synch, or you have encountered a bug in
37406the C library on your system.  (This has happened!)  Your copy might
37407crash and ours would not.  If you told us to expect a crash, then when
37408ours fails to crash, we would know that the bug was not happening for
37409us.  If you had not told us to expect a crash, then we would not be able
37410to draw any conclusion from our observations.
37411
37412@pindex script
37413@cindex recording a session script
37414To collect all this information, you can use a session recording program
37415such as @command{script}, which is available on many Unix systems.
37416Just run your @value{GDBN} session inside @command{script} and then
37417include the @file{typescript} file with your bug report.
37418
37419Another way to record a @value{GDBN} session is to run @value{GDBN}
37420inside Emacs and then save the entire buffer to a file.
37421
37422@item
37423If you wish to suggest changes to the @value{GDBN} source, send us context
37424diffs.  If you even discuss something in the @value{GDBN} source, refer to
37425it by context, not by line number.
37426
37427The line numbers in our development sources will not match those in your
37428sources.  Your line numbers would convey no useful information to us.
37429
37430@end itemize
37431
37432Here are some things that are not necessary:
37433
37434@itemize @bullet
37435@item
37436A description of the envelope of the bug.
37437
37438Often people who encounter a bug spend a lot of time investigating
37439which changes to the input file will make the bug go away and which
37440changes will not affect it.
37441
37442This is often time consuming and not very useful, because the way we
37443will find the bug is by running a single example under the debugger
37444with breakpoints, not by pure deduction from a series of examples.
37445We recommend that you save your time for something else.
37446
37447Of course, if you can find a simpler example to report @emph{instead}
37448of the original one, that is a convenience for us.  Errors in the
37449output will be easier to spot, running under the debugger will take
37450less time, and so on.
37451
37452However, simplification is not vital; if you do not want to do this,
37453report the bug anyway and send us the entire test case you used.
37454
37455@item
37456A patch for the bug.
37457
37458A patch for the bug does help us if it is a good one.  But do not omit
37459the necessary information, such as the test case, on the assumption that
37460a patch is all we need.  We might see problems with your patch and decide
37461to fix the problem another way, or we might not understand it at all.
37462
37463Sometimes with a program as complicated as @value{GDBN} it is very hard to
37464construct an example that will make the program follow a certain path
37465through the code.  If you do not send us the example, we will not be able
37466to construct one, so we will not be able to verify that the bug is fixed.
37467
37468And if we cannot understand what bug you are trying to fix, or why your
37469patch should be an improvement, we will not install it.  A test case will
37470help us to understand.
37471
37472@item
37473A guess about what the bug is or what it depends on.
37474
37475Such guesses are usually wrong.  Even we cannot guess right about such
37476things without first using the debugger to find the facts.
37477@end itemize
37478
37479@c The readline documentation is distributed with the readline code
37480@c and consists of the two following files:
37481@c     rluser.texi
37482@c     hsuser.texi
37483@c Use -I with makeinfo to point to the appropriate directory,
37484@c environment var TEXINPUTS with TeX.
37485@ifclear SYSTEM_READLINE
37486@include rluser.texi
37487@include hsuser.texi
37488@end ifclear
37489
37490@node In Memoriam
37491@appendix In Memoriam
37492
37493The @value{GDBN} project mourns the loss of the following long-time
37494contributors:
37495
37496@table @code
37497@item Fred Fish
37498Fred was a long-standing contributor to @value{GDBN} (1991-2006), and
37499to Free Software in general.  Outside of @value{GDBN}, he was known in
37500the Amiga world for his series of Fish Disks, and the GeekGadget project.
37501
37502@item Michael Snyder
37503Michael was one of the Global Maintainers of the @value{GDBN} project,
37504with contributions recorded as early as 1996, until 2011.  In addition
37505to his day to day participation, he was a large driving force behind
37506adding Reverse Debugging to @value{GDBN}.
37507@end table
37508
37509Beyond their technical contributions to the project, they were also
37510enjoyable members of the Free Software Community.  We will miss them.
37511
37512@node Formatting Documentation
37513@appendix Formatting Documentation
37514
37515@cindex @value{GDBN} reference card
37516@cindex reference card
37517The @value{GDBN} 4 release includes an already-formatted reference card, ready
37518for printing with PostScript or Ghostscript, in the @file{gdb}
37519subdirectory of the main source directory@footnote{In
37520@file{gdb-@value{GDBVN}/gdb/refcard.ps} of the version @value{GDBVN}
37521release.}.  If you can use PostScript or Ghostscript with your printer,
37522you can print the reference card immediately with @file{refcard.ps}.
37523
37524The release also includes the source for the reference card.  You
37525can format it, using @TeX{}, by typing:
37526
37527@smallexample
37528make refcard.dvi
37529@end smallexample
37530
37531The @value{GDBN} reference card is designed to print in @dfn{landscape}
37532mode on US ``letter'' size paper;
37533that is, on a sheet 11 inches wide by 8.5 inches
37534high.  You will need to specify this form of printing as an option to
37535your @sc{dvi} output program.
37536
37537@cindex documentation
37538
37539All the documentation for @value{GDBN} comes as part of the machine-readable
37540distribution.  The documentation is written in Texinfo format, which is
37541a documentation system that uses a single source file to produce both
37542on-line information and a printed manual.  You can use one of the Info
37543formatting commands to create the on-line version of the documentation
37544and @TeX{} (or @code{texi2roff}) to typeset the printed version.
37545
37546@value{GDBN} includes an already formatted copy of the on-line Info
37547version of this manual in the @file{gdb} subdirectory.  The main Info
37548file is @file{gdb-@value{GDBVN}/gdb/gdb.info}, and it refers to
37549subordinate files matching @samp{gdb.info*} in the same directory.  If
37550necessary, you can print out these files, or read them with any editor;
37551but they are easier to read using the @code{info} subsystem in @sc{gnu}
37552Emacs or the standalone @code{info} program, available as part of the
37553@sc{gnu} Texinfo distribution.
37554
37555If you want to format these Info files yourself, you need one of the
37556Info formatting programs, such as @code{texinfo-format-buffer} or
37557@code{makeinfo}.
37558
37559If you have @code{makeinfo} installed, and are in the top level
37560@value{GDBN} source directory (@file{gdb-@value{GDBVN}}, in the case of
37561version @value{GDBVN}), you can make the Info file by typing:
37562
37563@smallexample
37564cd gdb
37565make gdb.info
37566@end smallexample
37567
37568If you want to typeset and print copies of this manual, you need @TeX{},
37569a program to print its @sc{dvi} output files, and @file{texinfo.tex}, the
37570Texinfo definitions file.
37571
37572@TeX{} is a typesetting program; it does not print files directly, but
37573produces output files called @sc{dvi} files.  To print a typeset
37574document, you need a program to print @sc{dvi} files.  If your system
37575has @TeX{} installed, chances are it has such a program.  The precise
37576command to use depends on your system; @kbd{lpr -d} is common; another
37577(for PostScript devices) is @kbd{dvips}.  The @sc{dvi} print command may
37578require a file name without any extension or a @samp{.dvi} extension.
37579
37580@TeX{} also requires a macro definitions file called
37581@file{texinfo.tex}.  This file tells @TeX{} how to typeset a document
37582written in Texinfo format.  On its own, @TeX{} cannot either read or
37583typeset a Texinfo file.  @file{texinfo.tex} is distributed with GDB
37584and is located in the @file{gdb-@var{version-number}/texinfo}
37585directory.
37586
37587If you have @TeX{} and a @sc{dvi} printer program installed, you can
37588typeset and print this manual.  First switch to the @file{gdb}
37589subdirectory of the main source directory (for example, to
37590@file{gdb-@value{GDBVN}/gdb}) and type:
37591
37592@smallexample
37593make gdb.dvi
37594@end smallexample
37595
37596Then give @file{gdb.dvi} to your @sc{dvi} printing program.
37597
37598@node Installing GDB
37599@appendix Installing @value{GDBN}
37600@cindex installation
37601
37602@menu
37603* Requirements::                Requirements for building @value{GDBN}
37604* Running Configure::           Invoking the @value{GDBN} @file{configure} script
37605* Separate Objdir::             Compiling @value{GDBN} in another directory
37606* Config Names::                Specifying names for hosts and targets
37607* Configure Options::           Summary of options for configure
37608* System-wide configuration::   Having a system-wide init file
37609@end menu
37610
37611@node Requirements
37612@section Requirements for Building @value{GDBN}
37613@cindex building @value{GDBN}, requirements for
37614
37615Building @value{GDBN} requires various tools and packages to be available.
37616Other packages will be used only if they are found.
37617
37618@heading Tools/Packages Necessary for Building @value{GDBN}
37619@table @asis
37620@item C@t{++}11 compiler
37621@value{GDBN} is written in C@t{++}11.  It should be buildable with any
37622recent C@t{++}11 compiler, e.g.@: GCC.
37623
37624@item GNU make
37625@value{GDBN}'s build system relies on features only found in the GNU
37626make program.  Other variants of @code{make} will not work.
37627@end table
37628
37629@heading Tools/Packages Optional for Building @value{GDBN}
37630@table @asis
37631@item Expat
37632@anchor{Expat}
37633@value{GDBN} can use the Expat XML parsing library.  This library may be
37634included with your operating system distribution; if it is not, you
37635can get the latest version from @url{http://expat.sourceforge.net}.
37636The @file{configure} script will search for this library in several
37637standard locations; if it is installed in an unusual path, you can
37638use the @option{--with-libexpat-prefix} option to specify its location.
37639
37640Expat is used for:
37641
37642@itemize @bullet
37643@item
37644Remote protocol memory maps (@pxref{Memory Map Format})
37645@item
37646Target descriptions (@pxref{Target Descriptions})
37647@item
37648Remote shared library lists (@xref{Library List Format},
37649or alternatively @pxref{Library List Format for SVR4 Targets})
37650@item
37651MS-Windows shared libraries (@pxref{Shared Libraries})
37652@item
37653Traceframe info (@pxref{Traceframe Info Format})
37654@item
37655Branch trace (@pxref{Branch Trace Format},
37656@pxref{Branch Trace Configuration Format})
37657@end itemize
37658
37659@item Guile
37660@value{GDBN} can be scripted using GNU Guile.  @xref{Guile}.  By
37661default, @value{GDBN} will be compiled if the Guile libraries are
37662installed and are found by @file{configure}.  You can use the
37663@code{--with-guile} option to request Guile, and pass either the Guile
37664version number or the file name of the relevant @code{pkg-config}
37665program to choose a particular version of Guile.
37666
37667@item iconv
37668@value{GDBN}'s features related to character sets (@pxref{Character
37669Sets}) require a functioning @code{iconv} implementation.  If you are
37670on a GNU system, then this is provided by the GNU C Library.  Some
37671other systems also provide a working @code{iconv}.
37672
37673If @value{GDBN} is using the @code{iconv} program which is installed
37674in a non-standard place, you will need to tell @value{GDBN} where to
37675find it.  This is done with @option{--with-iconv-bin} which specifies
37676the directory that contains the @code{iconv} program.  This program is
37677run in order to make a list of the available character sets.
37678
37679On systems without @code{iconv}, you can install GNU Libiconv.  If
37680Libiconv is installed in a standard place, @value{GDBN} will
37681automatically use it if it is needed.  If you have previously
37682installed Libiconv in a non-standard place, you can use the
37683@option{--with-libiconv-prefix} option to @file{configure}.
37684
37685@value{GDBN}'s top-level @file{configure} and @file{Makefile} will
37686arrange to build Libiconv if a directory named @file{libiconv} appears
37687in the top-most source directory.  If Libiconv is built this way, and
37688if the operating system does not provide a suitable @code{iconv}
37689implementation, then the just-built library will automatically be used
37690by @value{GDBN}.  One easy way to set this up is to download GNU
37691Libiconv, unpack it inside the top-level directory of the @value{GDBN}
37692source tree, and then rename the directory holding the Libiconv source
37693code to @samp{libiconv}.
37694
37695@item lzma
37696@value{GDBN} can support debugging sections that are compressed with
37697the LZMA library.  @xref{MiniDebugInfo}.  If this library is not
37698included with your operating system, you can find it in the xz package
37699at @url{http://tukaani.org/xz/}.  If the LZMA library is available in
37700the usual place, then the @file{configure} script will use it
37701automatically.  If it is installed in an unusual path, you can use the
37702@option{--with-lzma-prefix} option to specify its location.
37703
37704@item MPFR
37705@anchor{MPFR}
37706@value{GDBN} can use the GNU MPFR multiple-precision floating-point
37707library.  This library may be included with your operating system
37708distribution; if it is not, you can get the latest version from
37709@url{http://www.mpfr.org}.  The @file{configure} script will search
37710for this library in several standard locations; if it is installed
37711in an unusual path, you can use the @option{--with-libmpfr-prefix}
37712option to specify its location.
37713
37714GNU MPFR is used to emulate target floating-point arithmetic during
37715expression evaluation when the target uses different floating-point
37716formats than the host.  If GNU MPFR it is not available, @value{GDBN}
37717will fall back to using host floating-point arithmetic.
37718
37719@item Python
37720@value{GDBN} can be scripted using Python language.  @xref{Python}.
37721By default, @value{GDBN} will be compiled if the Python libraries are
37722installed and are found by @file{configure}.  You can use the
37723@code{--with-python} option to request Python, and pass either the
37724file name of the relevant @code{python} executable, or the name of the
37725directory in which Python is installed, to choose a particular
37726installation of Python.
37727
37728@item zlib
37729@cindex compressed debug sections
37730@value{GDBN} will use the @samp{zlib} library, if available, to read
37731compressed debug sections.  Some linkers, such as GNU gold, are capable
37732of producing binaries with compressed debug sections.  If @value{GDBN}
37733is compiled with @samp{zlib}, it will be able to read the debug
37734information in such binaries.
37735
37736The @samp{zlib} library is likely included with your operating system
37737distribution; if it is not, you can get the latest version from
37738@url{http://zlib.net}.
37739@end table
37740
37741@node Running Configure
37742@section Invoking the @value{GDBN} @file{configure} Script
37743@cindex configuring @value{GDBN}
37744@value{GDBN} comes with a @file{configure} script that automates the process
37745of preparing @value{GDBN} for installation; you can then use @code{make} to
37746build the @code{gdb} program.
37747@iftex
37748@c irrelevant in info file; it's as current as the code it lives with.
37749@footnote{If you have a more recent version of @value{GDBN} than @value{GDBVN},
37750look at the @file{README} file in the sources; we may have improved the
37751installation procedures since publishing this manual.}
37752@end iftex
37753
37754The @value{GDBN} distribution includes all the source code you need for
37755@value{GDBN} in a single directory, whose name is usually composed by
37756appending the version number to @samp{gdb}.
37757
37758For example, the @value{GDBN} version @value{GDBVN} distribution is in the
37759@file{gdb-@value{GDBVN}} directory.  That directory contains:
37760
37761@table @code
37762@item gdb-@value{GDBVN}/configure @r{(and supporting files)}
37763script for configuring @value{GDBN} and all its supporting libraries
37764
37765@item gdb-@value{GDBVN}/gdb
37766the source specific to @value{GDBN} itself
37767
37768@item gdb-@value{GDBVN}/bfd
37769source for the Binary File Descriptor library
37770
37771@item gdb-@value{GDBVN}/include
37772@sc{gnu} include files
37773
37774@item gdb-@value{GDBVN}/libiberty
37775source for the @samp{-liberty} free software library
37776
37777@item gdb-@value{GDBVN}/opcodes
37778source for the library of opcode tables and disassemblers
37779
37780@item gdb-@value{GDBVN}/readline
37781source for the @sc{gnu} command-line interface
37782@end table
37783
37784There may be other subdirectories as well.
37785
37786The simplest way to configure and build @value{GDBN} is to run @file{configure}
37787from the @file{gdb-@var{version-number}} source directory, which in
37788this example is the @file{gdb-@value{GDBVN}} directory.
37789
37790First switch to the @file{gdb-@var{version-number}} source directory
37791if you are not already in it; then run @file{configure}.  Pass the
37792identifier for the platform on which @value{GDBN} will run as an
37793argument.
37794
37795For example:
37796
37797@smallexample
37798cd gdb-@value{GDBVN}
37799./configure
37800make
37801@end smallexample
37802
37803Running @samp{configure} and then running @code{make} builds the
37804included supporting libraries, then @code{gdb} itself.  The configured
37805source files, and the binaries, are left in the corresponding source
37806directories.
37807
37808@need 750
37809@file{configure} is a Bourne-shell (@code{/bin/sh}) script; if your
37810system does not recognize this automatically when you run a different
37811shell, you may need to run @code{sh} on it explicitly:
37812
37813@smallexample
37814sh configure
37815@end smallexample
37816
37817You should run the @file{configure} script from the top directory in the
37818source tree, the @file{gdb-@var{version-number}} directory.  If you run
37819@file{configure} from one of the subdirectories, you will configure only
37820that subdirectory.  That is usually not what you want.  In particular,
37821if you run the first @file{configure} from the @file{gdb} subdirectory
37822of the @file{gdb-@var{version-number}} directory, you will omit the
37823configuration of @file{bfd}, @file{readline}, and other sibling
37824directories of the @file{gdb} subdirectory.  This leads to build errors
37825about missing include files such as @file{bfd/bfd.h}.
37826
37827You can install @code{@value{GDBN}} anywhere.  The best way to do this
37828is to pass the @code{--prefix} option to @code{configure}, and then
37829install it with @code{make install}.
37830
37831@node Separate Objdir
37832@section Compiling @value{GDBN} in Another Directory
37833
37834If you want to run @value{GDBN} versions for several host or target machines,
37835you need a different @code{gdb} compiled for each combination of
37836host and target.  @file{configure} is designed to make this easy by
37837allowing you to generate each configuration in a separate subdirectory,
37838rather than in the source directory.  If your @code{make} program
37839handles the @samp{VPATH} feature (@sc{gnu} @code{make} does), running
37840@code{make} in each of these directories builds the @code{gdb}
37841program specified there.
37842
37843To build @code{gdb} in a separate directory, run @file{configure}
37844with the @samp{--srcdir} option to specify where to find the source.
37845(You also need to specify a path to find @file{configure}
37846itself from your working directory.  If the path to @file{configure}
37847would be the same as the argument to @samp{--srcdir}, you can leave out
37848the @samp{--srcdir} option; it is assumed.)
37849
37850For example, with version @value{GDBVN}, you can build @value{GDBN} in a
37851separate directory for a Sun 4 like this:
37852
37853@smallexample
37854@group
37855cd gdb-@value{GDBVN}
37856mkdir ../gdb-sun4
37857cd ../gdb-sun4
37858../gdb-@value{GDBVN}/configure
37859make
37860@end group
37861@end smallexample
37862
37863When @file{configure} builds a configuration using a remote source
37864directory, it creates a tree for the binaries with the same structure
37865(and using the same names) as the tree under the source directory.  In
37866the example, you'd find the Sun 4 library @file{libiberty.a} in the
37867directory @file{gdb-sun4/libiberty}, and @value{GDBN} itself in
37868@file{gdb-sun4/gdb}.
37869
37870Make sure that your path to the @file{configure} script has just one
37871instance of @file{gdb} in it.  If your path to @file{configure} looks
37872like @file{../gdb-@value{GDBVN}/gdb/configure}, you are configuring only
37873one subdirectory of @value{GDBN}, not the whole package.  This leads to
37874build errors about missing include files such as @file{bfd/bfd.h}.
37875
37876One popular reason to build several @value{GDBN} configurations in separate
37877directories is to configure @value{GDBN} for cross-compiling (where
37878@value{GDBN} runs on one machine---the @dfn{host}---while debugging
37879programs that run on another machine---the @dfn{target}).
37880You specify a cross-debugging target by
37881giving the @samp{--target=@var{target}} option to @file{configure}.
37882
37883When you run @code{make} to build a program or library, you must run
37884it in a configured directory---whatever directory you were in when you
37885called @file{configure} (or one of its subdirectories).
37886
37887The @code{Makefile} that @file{configure} generates in each source
37888directory also runs recursively.  If you type @code{make} in a source
37889directory such as @file{gdb-@value{GDBVN}} (or in a separate configured
37890directory configured with @samp{--srcdir=@var{dirname}/gdb-@value{GDBVN}}), you
37891will build all the required libraries, and then build GDB.
37892
37893When you have multiple hosts or targets configured in separate
37894directories, you can run @code{make} on them in parallel (for example,
37895if they are NFS-mounted on each of the hosts); they will not interfere
37896with each other.
37897
37898@node Config Names
37899@section Specifying Names for Hosts and Targets
37900
37901The specifications used for hosts and targets in the @file{configure}
37902script are based on a three-part naming scheme, but some short predefined
37903aliases are also supported.  The full naming scheme encodes three pieces
37904of information in the following pattern:
37905
37906@smallexample
37907@var{architecture}-@var{vendor}-@var{os}
37908@end smallexample
37909
37910For example, you can use the alias @code{sun4} as a @var{host} argument,
37911or as the value for @var{target} in a @code{--target=@var{target}}
37912option.  The equivalent full name is @samp{sparc-sun-sunos4}.
37913
37914The @file{configure} script accompanying @value{GDBN} does not provide
37915any query facility to list all supported host and target names or
37916aliases.  @file{configure} calls the Bourne shell script
37917@code{config.sub} to map abbreviations to full names; you can read the
37918script, if you wish, or you can use it to test your guesses on
37919abbreviations---for example:
37920
37921@smallexample
37922% sh config.sub i386-linux
37923i386-pc-linux-gnu
37924% sh config.sub alpha-linux
37925alpha-unknown-linux-gnu
37926% sh config.sub hp9k700
37927hppa1.1-hp-hpux
37928% sh config.sub sun4
37929sparc-sun-sunos4.1.1
37930% sh config.sub sun3
37931m68k-sun-sunos4.1.1
37932% sh config.sub i986v
37933Invalid configuration `i986v': machine `i986v' not recognized
37934@end smallexample
37935
37936@noindent
37937@code{config.sub} is also distributed in the @value{GDBN} source
37938directory (@file{gdb-@value{GDBVN}}, for version @value{GDBVN}).
37939
37940@node Configure Options
37941@section @file{configure} Options
37942
37943Here is a summary of the @file{configure} options and arguments that
37944are most often useful for building @value{GDBN}.  @file{configure}
37945also has several other options not listed here.  @inforef{Running
37946configure scripts,,autoconf.info}, for a full
37947explanation of @file{configure}.
37948
37949@smallexample
37950configure @r{[}--help@r{]}
37951          @r{[}--prefix=@var{dir}@r{]}
37952          @r{[}--exec-prefix=@var{dir}@r{]}
37953          @r{[}--srcdir=@var{dirname}@r{]}
37954          @r{[}--target=@var{target}@r{]}
37955@end smallexample
37956
37957@noindent
37958You may introduce options with a single @samp{-} rather than
37959@samp{--} if you prefer; but you may abbreviate option names if you use
37960@samp{--}.
37961
37962@table @code
37963@item --help
37964Display a quick summary of how to invoke @file{configure}.
37965
37966@item --prefix=@var{dir}
37967Configure the source to install programs and files under directory
37968@file{@var{dir}}.
37969
37970@item --exec-prefix=@var{dir}
37971Configure the source to install programs under directory
37972@file{@var{dir}}.
37973
37974@c avoid splitting the warning from the explanation:
37975@need 2000
37976@item --srcdir=@var{dirname}
37977Use this option to make configurations in directories separate from the
37978@value{GDBN} source directories.  Among other things, you can use this to
37979build (or maintain) several configurations simultaneously, in separate
37980directories.  @file{configure} writes configuration-specific files in
37981the current directory, but arranges for them to use the source in the
37982directory @var{dirname}.  @file{configure} creates directories under
37983the working directory in parallel to the source directories below
37984@var{dirname}.
37985
37986@item --target=@var{target}
37987Configure @value{GDBN} for cross-debugging programs running on the specified
37988@var{target}.  Without this option, @value{GDBN} is configured to debug
37989programs that run on the same machine (@var{host}) as @value{GDBN} itself.
37990
37991There is no convenient way to generate a list of all available
37992targets.  Also see the @code{--enable-targets} option, below.
37993@end table
37994
37995There are many other options that are specific to @value{GDBN}.  This
37996lists just the most common ones; there are some very specialized
37997options not described here.
37998
37999@table @code
38000@item --enable-targets=@r{[}@var{target}@r{]}@dots{}
38001@itemx --enable-targets=all
38002Configure @value{GDBN} for cross-debugging programs running on the
38003specified list of targets.  The special value @samp{all} configures
38004@value{GDBN} for debugging programs running on any target it supports.
38005
38006@item --with-gdb-datadir=@var{path}
38007Set the @value{GDBN}-specific data directory.  @value{GDBN} will look
38008here for certain supporting files or scripts.  This defaults to the
38009@file{gdb} subdirectory of @samp{datadir} (which can be set using
38010@code{--datadir}).
38011
38012@item --with-relocated-sources=@var{dir}
38013Sets up the default source path substitution rule so that directory
38014names recorded in debug information will be automatically adjusted for
38015any directory under @var{dir}.  @var{dir} should be a subdirectory of
38016@value{GDBN}'s configured prefix, the one mentioned in the
38017@code{--prefix} or @code{--exec-prefix} options to configure.  This
38018option is useful if GDB is supposed to be moved to a different place
38019after it is built.
38020
38021@item --enable-64-bit-bfd
38022Enable 64-bit support in BFD on 32-bit hosts.
38023
38024@item --disable-gdbmi
38025Build @value{GDBN} without the GDB/MI machine interface
38026(@pxref{GDB/MI}).
38027
38028@item --enable-tui
38029Build @value{GDBN} with the text-mode full-screen user interface
38030(TUI).  Requires a curses library (ncurses and cursesX are also
38031supported).
38032
38033@item --with-curses
38034Use the curses library instead of the termcap library, for text-mode
38035terminal operations.
38036
38037@item --with-debuginfod
38038Build @value{GDBN} with libdebuginfod, the debuginfod client library.
38039Used to automatically fetch source files and separate debug files from
38040debuginfod servers using the associated executable's build ID. Enabled
38041by default if libdebuginfod is installed and found at configure time.
38042debuginfod is packaged with elfutils, starting with version 0.178. You
38043can get the latest version from `https://sourceware.org/elfutils/'.
38044
38045@item --with-libunwind-ia64
38046Use the libunwind library for unwinding function call stack on ia64
38047target platforms.  See http://www.nongnu.org/libunwind/index.html for
38048details.
38049
38050@item --with-system-readline
38051Use the readline library installed on the host, rather than the
38052library supplied as part of @value{GDBN}.  Readline 7 or newer is
38053required; this is enforced by the build system.
38054
38055@item --with-system-zlib
38056Use the zlib library installed on the host, rather than the library
38057supplied as part of @value{GDBN}.
38058
38059@item --with-expat
38060Build @value{GDBN} with Expat, a library for XML parsing.  (Done by
38061default if libexpat is installed and found at configure time.)  This
38062library is used to read XML files supplied with @value{GDBN}.  If it
38063is unavailable, some features, such as remote protocol memory maps,
38064target descriptions, and shared library lists, that are based on XML
38065files, will not be available in @value{GDBN}.  If your host does not
38066have libexpat installed, you can get the latest version from
38067`http://expat.sourceforge.net'.
38068
38069@item --with-libiconv-prefix@r{[}=@var{dir}@r{]}
38070
38071Build @value{GDBN} with GNU libiconv, a character set encoding
38072conversion library.  This is not done by default, as on GNU systems
38073the @code{iconv} that is built in to the C library is sufficient.  If
38074your host does not have a working @code{iconv}, you can get the latest
38075version of GNU iconv from `https://www.gnu.org/software/libiconv/'.
38076
38077@value{GDBN}'s build system also supports building GNU libiconv as
38078part of the overall build.   @xref{Requirements}.
38079
38080@item --with-lzma
38081Build @value{GDBN} with LZMA, a compression library.  (Done by default
38082if liblzma is installed and found at configure time.)  LZMA is used by
38083@value{GDBN}'s "mini debuginfo" feature, which is only useful on
38084platforms using the ELF object file format.  If your host does not
38085have liblzma installed, you can get the latest version from
38086`https://tukaani.org/xz/'.
38087
38088@item --with-mpfr
38089Build @value{GDBN} with GNU MPFR, a library for multiple-precision
38090floating-point computation with correct rounding.  (Done by default if
38091GNU MPFR is installed and found at configure time.)  This library is
38092used to emulate target floating-point arithmetic during expression
38093evaluation when the target uses different floating-point formats than
38094the host.  If GNU MPFR is not available, @value{GDBN} will fall back
38095to using host floating-point arithmetic.  If your host does not have
38096GNU MPFR installed, you can get the latest version from
38097`http://www.mpfr.org'.
38098
38099@item --with-python@r{[}=@var{python}@r{]}
38100Build @value{GDBN} with Python scripting support.  (Done by default if
38101libpython is present and found at configure time.)  Python makes
38102@value{GDBN} scripting much more powerful than the restricted CLI
38103scripting language.  If your host does not have Python installed, you
38104can find it on `http://www.python.org/download/'.  The oldest version
38105of Python supported by GDB is 2.6.  The optional argument @var{python}
38106is used to find the Python headers and libraries.  It can be either
38107the name of a Python executable, or the name of the directory in which
38108Python is installed.
38109
38110@item --with-guile[=GUILE]'
38111Build @value{GDBN} with GNU Guile scripting support.  (Done by default
38112if libguile is present and found at configure time.)  If your host
38113does not have Guile installed, you can find it at
38114`https://www.gnu.org/software/guile/'.  The optional argument GUILE
38115can be a version number, which will cause @code{configure} to try to
38116use that version of Guile; or the file name of a @code{pkg-config}
38117executable, which will be queried to find the information needed to
38118compile and link against Guile.
38119
38120@item --without-included-regex
38121Don't use the regex library included with @value{GDBN} (as part of the
38122libiberty library).  This is the default on hosts with version 2 of
38123the GNU C library.
38124
38125@item --with-sysroot=@var{dir}
38126Use @var{dir} as the default system root directory for libraries whose
38127file names begin with @file{/lib}' or @file{/usr/lib'}.  (The value of
38128@var{dir} can be modified at run time by using the @command{set
38129sysroot} command.)  If @var{dir} is under the @value{GDBN} configured
38130prefix (set with @code{--prefix} or @code{--exec-prefix options}, the
38131default system root will be automatically adjusted if and when
38132@value{GDBN} is moved to a different location.
38133
38134@item --with-system-gdbinit=@var{file}
38135Configure @value{GDBN} to automatically load a system-wide init file.
38136@var{file} should be an absolute file name.  If @var{file} is in a
38137directory under the configured prefix, and @value{GDBN} is moved to
38138another location after being built, the location of the system-wide
38139init file will be adjusted accordingly.
38140
38141@item --with-system-gdbinit-dir=@var{directory}
38142Configure @value{GDBN} to automatically load init files from a
38143system-wide directory.  @var{directory} should be an absolute directory
38144name.  If @var{directory} is in a directory under the configured
38145prefix, and @value{GDBN} is moved to another location after being
38146built, the location of the system-wide init directory will be
38147adjusted accordingly.
38148
38149@item --enable-build-warnings
38150When building the @value{GDBN} sources, ask the compiler to warn about
38151any code which looks even vaguely suspicious.  It passes many
38152different warning flags, depending on the exact version of the
38153compiler you are using.
38154
38155@item --enable-werror
38156Treat compiler warnings as werrors.  It adds the @code{-Werror} flag
38157to the compiler, which will fail the compilation if the compiler
38158outputs any warning messages.
38159
38160@item --enable-ubsan
38161Enable the GCC undefined behavior sanitizer.  This is disabled by
38162default, but passing @code{--enable-ubsan=yes} or
38163@code{--enable-ubsan=auto} to @code{configure} will enable it.  The
38164undefined behavior sanitizer checks for C@t{++} undefined behavior.
38165It has a performance cost, so if you are looking at @value{GDBN}'s
38166performance, you should disable it.  The undefined behavior sanitizer
38167was first introduced in GCC 4.9.
38168@end table
38169
38170@node System-wide configuration
38171@section System-wide configuration and settings
38172@cindex system-wide init file
38173
38174@value{GDBN} can be configured to have a system-wide init file and a
38175system-wide init file directory; this file and files in that directory
38176(if they have a recognized file extension) will be read and executed at
38177startup (@pxref{Startup, , What @value{GDBN} does during startup}).
38178
38179Here are the corresponding configure options:
38180
38181@table @code
38182@item --with-system-gdbinit=@var{file}
38183Specify that the default location of the system-wide init file is
38184@var{file}.
38185@item --with-system-gdbinit-dir=@var{directory}
38186Specify that the default location of the system-wide init file directory
38187is @var{directory}.
38188@end table
38189
38190If @value{GDBN} has been configured with the option @option{--prefix=$prefix},
38191they may be subject to relocation.  Two possible cases:
38192
38193@itemize @bullet
38194@item
38195If the default location of this init file/directory contains @file{$prefix},
38196it will be subject to relocation.  Suppose that the configure options
38197are @option{--prefix=$prefix --with-system-gdbinit=$prefix/etc/gdbinit};
38198if @value{GDBN} is moved from @file{$prefix} to @file{$install}, the system
38199init file is looked for as @file{$install/etc/gdbinit} instead of
38200@file{$prefix/etc/gdbinit}.
38201
38202@item
38203By contrast, if the default location does not contain the prefix,
38204it will not be relocated.  E.g.@: if @value{GDBN} has been configured with
38205@option{--prefix=/usr/local --with-system-gdbinit=/usr/share/gdb/gdbinit},
38206then @value{GDBN} will always look for @file{/usr/share/gdb/gdbinit},
38207wherever @value{GDBN} is installed.
38208@end itemize
38209
38210If the configured location of the system-wide init file (as given by the
38211@option{--with-system-gdbinit} option at configure time) is in the
38212data-directory (as specified by @option{--with-gdb-datadir} at configure
38213time) or in one of its subdirectories, then @value{GDBN} will look for the
38214system-wide init file in the directory specified by the
38215@option{--data-directory} command-line option.
38216Note that the system-wide init file is only read once, during @value{GDBN}
38217initialization.  If the data-directory is changed after @value{GDBN} has
38218started with the @code{set data-directory} command, the file will not be
38219reread.
38220
38221This applies similarly to the system-wide directory specified in
38222@option{--with-system-gdbinit-dir}.
38223
38224Any supported scripting language can be used for these init files, as long
38225as the file extension matches the scripting language.  To be interpreted
38226as regular @value{GDBN} commands, the files needs to have a @file{.gdb}
38227extension.
38228
38229@menu
38230* System-wide Configuration Scripts::  Installed System-wide Configuration Scripts
38231@end menu
38232
38233@node System-wide Configuration Scripts
38234@subsection Installed System-wide Configuration Scripts
38235@cindex system-wide configuration scripts
38236
38237The @file{system-gdbinit} directory, located inside the data-directory
38238(as specified by @option{--with-gdb-datadir} at configure time) contains
38239a number of scripts which can be used as system-wide init files.  To
38240automatically source those scripts at startup, @value{GDBN} should be
38241configured with @option{--with-system-gdbinit}.  Otherwise, any user
38242should be able to source them by hand as needed.
38243
38244The following scripts are currently available:
38245@itemize @bullet
38246
38247@item @file{elinos.py}
38248@pindex elinos.py
38249@cindex ELinOS system-wide configuration script
38250This script is useful when debugging a program on an ELinOS target.
38251It takes advantage of the environment variables defined in a standard
38252ELinOS environment in order to determine the location of the system
38253shared libraries, and then sets the @samp{solib-absolute-prefix}
38254and @samp{solib-search-path} variables appropriately.
38255
38256@item @file{wrs-linux.py}
38257@pindex wrs-linux.py
38258@cindex Wind River Linux system-wide configuration script
38259This script is useful when debugging a program on a target running
38260Wind River Linux.  It expects the @env{ENV_PREFIX} to be set to
38261the host-side sysroot used by the target system.
38262
38263@end itemize
38264
38265@node Maintenance Commands
38266@appendix Maintenance Commands
38267@cindex maintenance commands
38268@cindex internal commands
38269
38270In addition to commands intended for @value{GDBN} users, @value{GDBN}
38271includes a number of commands intended for @value{GDBN} developers,
38272that are not documented elsewhere in this manual.  These commands are
38273provided here for reference.  (For commands that turn on debugging
38274messages, see @ref{Debugging Output}.)
38275
38276@table @code
38277@kindex maint agent
38278@kindex maint agent-eval
38279@item maint agent @r{[}-at @var{location}@r{,}@r{]} @var{expression}
38280@itemx maint agent-eval @r{[}-at @var{location}@r{,}@r{]} @var{expression}
38281Translate the given @var{expression} into remote agent bytecodes.
38282This command is useful for debugging the Agent Expression mechanism
38283(@pxref{Agent Expressions}).  The @samp{agent} version produces an
38284expression useful for data collection, such as by tracepoints, while
38285@samp{maint agent-eval} produces an expression that evaluates directly
38286to a result.  For instance, a collection expression for @code{globa +
38287globb} will include bytecodes to record four bytes of memory at each
38288of the addresses of @code{globa} and @code{globb}, while discarding
38289the result of the addition, while an evaluation expression will do the
38290addition and return the sum.
38291If @code{-at} is given, generate remote agent bytecode for @var{location}.
38292If not, generate remote agent bytecode for current frame PC address.
38293
38294@kindex maint agent-printf
38295@item maint agent-printf @var{format},@var{expr},...
38296Translate the given format string and list of argument expressions
38297into remote agent bytecodes and display them as a disassembled list.
38298This command is useful for debugging the agent version of dynamic
38299printf (@pxref{Dynamic Printf}).
38300
38301@kindex maint info breakpoints
38302@item @anchor{maint info breakpoints}maint info breakpoints
38303Using the same format as @samp{info breakpoints}, display both the
38304breakpoints you've set explicitly, and those @value{GDBN} is using for
38305internal purposes.  Internal breakpoints are shown with negative
38306breakpoint numbers.  The type column identifies what kind of breakpoint
38307is shown:
38308
38309@table @code
38310@item breakpoint
38311Normal, explicitly set breakpoint.
38312
38313@item watchpoint
38314Normal, explicitly set watchpoint.
38315
38316@item longjmp
38317Internal breakpoint, used to handle correctly stepping through
38318@code{longjmp} calls.
38319
38320@item longjmp resume
38321Internal breakpoint at the target of a @code{longjmp}.
38322
38323@item until
38324Temporary internal breakpoint used by the @value{GDBN} @code{until} command.
38325
38326@item finish
38327Temporary internal breakpoint used by the @value{GDBN} @code{finish} command.
38328
38329@item shlib events
38330Shared library events.
38331
38332@end table
38333
38334@kindex maint info btrace
38335@item maint info btrace
38336Pint information about raw branch tracing data.
38337
38338@kindex maint btrace packet-history
38339@item maint btrace packet-history
38340Print the raw branch trace packets that are used to compute the
38341execution history for the @samp{record btrace} command.  Both the
38342information and the format in which it is printed depend on the btrace
38343recording format.
38344
38345@table @code
38346@item bts
38347For the BTS recording format, print a list of blocks of sequential
38348code.  For each block, the following information is printed:
38349
38350@table @asis
38351@item Block number
38352Newer blocks have higher numbers.  The oldest block has number zero.
38353@item Lowest @samp{PC}
38354@item Highest @samp{PC}
38355@end table
38356
38357@item pt
38358For the Intel Processor Trace recording format, print a list of
38359Intel Processor Trace packets.  For each packet, the following
38360information is printed:
38361
38362@table @asis
38363@item Packet number
38364Newer packets have higher numbers.  The oldest packet has number zero.
38365@item Trace offset
38366The packet's offset in the trace stream.
38367@item Packet opcode and payload
38368@end table
38369@end table
38370
38371@kindex maint btrace clear-packet-history
38372@item maint btrace clear-packet-history
38373Discards the cached packet history printed by the @samp{maint btrace
38374packet-history} command.  The history will be computed again when
38375needed.
38376
38377@kindex maint btrace clear
38378@item maint btrace clear
38379Discard the branch trace data.  The data will be fetched anew and the
38380branch trace will be recomputed when needed.
38381
38382This implicitly truncates the branch trace to a single branch trace
38383buffer.  When updating branch trace incrementally, the branch trace
38384available to @value{GDBN} may be bigger than a single branch trace
38385buffer.
38386
38387@kindex maint set btrace pt skip-pad
38388@item maint set btrace pt skip-pad
38389@kindex maint show btrace pt skip-pad
38390@item maint show btrace pt skip-pad
38391Control whether @value{GDBN} will skip PAD packets when computing the
38392packet history.
38393
38394@kindex set displaced-stepping
38395@kindex show displaced-stepping
38396@cindex displaced stepping support
38397@cindex out-of-line single-stepping
38398@item set displaced-stepping
38399@itemx show displaced-stepping
38400Control whether or not @value{GDBN} will do @dfn{displaced stepping}
38401if the target supports it.  Displaced stepping is a way to single-step
38402over breakpoints without removing them from the inferior, by executing
38403an out-of-line copy of the instruction that was originally at the
38404breakpoint location.  It is also known as out-of-line single-stepping.
38405
38406@table @code
38407@item set displaced-stepping on
38408If the target architecture supports it, @value{GDBN} will use
38409displaced stepping to step over breakpoints.
38410
38411@item set displaced-stepping off
38412@value{GDBN} will not use displaced stepping to step over breakpoints,
38413even if such is supported by the target architecture.
38414
38415@cindex non-stop mode, and @samp{set displaced-stepping}
38416@item set displaced-stepping auto
38417This is the default mode.  @value{GDBN} will use displaced stepping
38418only if non-stop mode is active (@pxref{Non-Stop Mode}) and the target
38419architecture supports displaced stepping.
38420@end table
38421
38422@kindex maint check-psymtabs
38423@item maint check-psymtabs
38424Check the consistency of currently expanded psymtabs versus symtabs.
38425Use this to check, for example, whether a symbol is in one but not the other.
38426
38427@kindex maint check-symtabs
38428@item maint check-symtabs
38429Check the consistency of currently expanded symtabs.
38430
38431@kindex maint expand-symtabs
38432@item maint expand-symtabs [@var{regexp}]
38433Expand symbol tables.
38434If @var{regexp} is specified, only expand symbol tables for file
38435names matching @var{regexp}.
38436
38437@kindex maint set catch-demangler-crashes
38438@kindex maint show catch-demangler-crashes
38439@cindex demangler crashes
38440@item maint set catch-demangler-crashes [on|off]
38441@itemx maint show catch-demangler-crashes
38442Control whether @value{GDBN} should attempt to catch crashes in the
38443symbol name demangler.  The default is to attempt to catch crashes.
38444If enabled, the first time a crash is caught, a core file is created,
38445the offending symbol is displayed and the user is presented with the
38446option to terminate the current session.
38447
38448@kindex maint cplus first_component
38449@item maint cplus first_component @var{name}
38450Print the first C@t{++} class/namespace component of @var{name}.
38451
38452@kindex maint cplus namespace
38453@item maint cplus namespace
38454Print the list of possible C@t{++} namespaces.
38455
38456@kindex maint deprecate
38457@kindex maint undeprecate
38458@cindex deprecated commands
38459@item maint deprecate @var{command} @r{[}@var{replacement}@r{]}
38460@itemx maint undeprecate @var{command}
38461Deprecate or undeprecate the named @var{command}.  Deprecated commands
38462cause @value{GDBN} to issue a warning when you use them.  The optional
38463argument @var{replacement} says which newer command should be used in
38464favor of the deprecated one; if it is given, @value{GDBN} will mention
38465the replacement as part of the warning.
38466
38467@kindex maint dump-me
38468@item maint dump-me
38469@cindex @code{SIGQUIT} signal, dump core of @value{GDBN}
38470Cause a fatal signal in the debugger and force it to dump its core.
38471This is supported only on systems which support aborting a program
38472with the @code{SIGQUIT} signal.
38473
38474@kindex maint internal-error
38475@kindex maint internal-warning
38476@kindex maint demangler-warning
38477@cindex demangler crashes
38478@item maint internal-error @r{[}@var{message-text}@r{]}
38479@itemx maint internal-warning @r{[}@var{message-text}@r{]}
38480@itemx maint demangler-warning @r{[}@var{message-text}@r{]}
38481
38482Cause @value{GDBN} to call the internal function @code{internal_error},
38483@code{internal_warning} or @code{demangler_warning} and hence behave
38484as though an internal problem has been detected.  In addition to
38485reporting the internal problem, these functions give the user the
38486opportunity to either quit @value{GDBN} or (for @code{internal_error}
38487and @code{internal_warning}) create a core file of the current
38488@value{GDBN} session.
38489
38490These commands take an optional parameter @var{message-text} that is
38491used as the text of the error or warning message.
38492
38493Here's an example of using @code{internal-error}:
38494
38495@smallexample
38496(@value{GDBP}) @kbd{maint internal-error testing, 1, 2}
38497@dots{}/maint.c:121: internal-error: testing, 1, 2
38498A problem internal to GDB has been detected.  Further
38499debugging may prove unreliable.
38500Quit this debugging session? (y or n) @kbd{n}
38501Create a core file? (y or n) @kbd{n}
38502(@value{GDBP})
38503@end smallexample
38504
38505@cindex @value{GDBN} internal error
38506@cindex internal errors, control of @value{GDBN} behavior
38507@cindex demangler crashes
38508
38509@kindex maint set internal-error
38510@kindex maint show internal-error
38511@kindex maint set internal-warning
38512@kindex maint show internal-warning
38513@kindex maint set demangler-warning
38514@kindex maint show demangler-warning
38515@item maint set internal-error @var{action} [ask|yes|no]
38516@itemx maint show internal-error @var{action}
38517@itemx maint set internal-warning @var{action} [ask|yes|no]
38518@itemx maint show internal-warning @var{action}
38519@itemx maint set demangler-warning @var{action} [ask|yes|no]
38520@itemx maint show demangler-warning @var{action}
38521When @value{GDBN} reports an internal problem (error or warning) it
38522gives the user the opportunity to both quit @value{GDBN} and create a
38523core file of the current @value{GDBN} session.  These commands let you
38524override the default behaviour for each particular @var{action},
38525described in the table below.
38526
38527@table @samp
38528@item quit
38529You can specify that @value{GDBN} should always (yes) or never (no)
38530quit.  The default is to ask the user what to do.
38531
38532@item corefile
38533You can specify that @value{GDBN} should always (yes) or never (no)
38534create a core file.  The default is to ask the user what to do.  Note
38535that there is no @code{corefile} option for @code{demangler-warning}:
38536demangler warnings always create a core file and this cannot be
38537disabled.
38538@end table
38539
38540@kindex maint packet
38541@item maint packet @var{text}
38542If @value{GDBN} is talking to an inferior via the serial protocol,
38543then this command sends the string @var{text} to the inferior, and
38544displays the response packet.  @value{GDBN} supplies the initial
38545@samp{$} character, the terminating @samp{#} character, and the
38546checksum.
38547
38548@kindex maint print architecture
38549@item maint print architecture @r{[}@var{file}@r{]}
38550Print the entire architecture configuration.  The optional argument
38551@var{file} names the file where the output goes.
38552
38553@kindex maint print c-tdesc @r{[}@var{file}@r{]}
38554@item maint print c-tdesc
38555Print the target description (@pxref{Target Descriptions}) as
38556a C source file.  By default, the target description is for the current
38557target, but if the optional argument @var{file} is provided, that file
38558is used to produce the description.  The @var{file} should be an XML
38559document, of the form described in @ref{Target Description Format}.
38560The created source file is built into @value{GDBN} when @value{GDBN} is
38561built again.  This command is used by developers after they add or
38562modify XML target descriptions.
38563
38564@kindex maint print xml-tdesc
38565@item maint print xml-tdesc  @r{[}@var{file}@r{]}
38566Print the target description (@pxref{Target Descriptions}) as an XML
38567file.  By default print the target description for the current target,
38568but if the optional argument @var{file} is provided, then that file is
38569read in by GDB and then used to produce the description.  The
38570@var{file} should be an XML document, of the form described in
38571@ref{Target Description Format}.
38572
38573@kindex maint check xml-descriptions
38574@item maint check xml-descriptions @var{dir}
38575Check that the target descriptions dynamically created by @value{GDBN}
38576equal the descriptions created from XML files found in @var{dir}.
38577
38578@anchor{maint check libthread-db}
38579@kindex maint check libthread-db
38580@item maint check libthread-db
38581Run integrity checks on the current inferior's thread debugging
38582library.  This exercises all @code{libthread_db} functionality used by
38583@value{GDBN} on GNU/Linux systems, and by extension also exercises the
38584@code{proc_service} functions provided by @value{GDBN} that
38585@code{libthread_db} uses.  Note that parts of the test may be skipped
38586on some platforms when debugging core files.
38587
38588@kindex maint print core-file-backed-mappings
38589@cindex memory address space mappings
38590@item maint print core-file-backed-mappings
38591Print the file-backed mappings which were loaded from a core file note.
38592This output represents state internal to @value{GDBN} and should be
38593similar to the mappings displayed by the @code{info proc mappings}
38594command.
38595
38596@kindex maint print dummy-frames
38597@item maint print dummy-frames
38598Prints the contents of @value{GDBN}'s internal dummy-frame stack.
38599
38600@smallexample
38601(@value{GDBP}) @kbd{b add}
38602@dots{}
38603(@value{GDBP}) @kbd{print add(2,3)}
38604Breakpoint 2, add (a=2, b=3) at @dots{}
3860558	  return (a + b);
38606The program being debugged stopped while in a function called from GDB.
38607@dots{}
38608(@value{GDBP}) @kbd{maint print dummy-frames}
386090xa8206d8: id=@{stack=0xbfffe734,code=0xbfffe73f,!special@}, ptid=process 9353
38610(@value{GDBP})
38611@end smallexample
38612
38613Takes an optional file parameter.
38614
38615@kindex maint print registers
38616@kindex maint print raw-registers
38617@kindex maint print cooked-registers
38618@kindex maint print register-groups
38619@kindex maint print remote-registers
38620@item maint print registers @r{[}@var{file}@r{]}
38621@itemx maint print raw-registers @r{[}@var{file}@r{]}
38622@itemx maint print cooked-registers @r{[}@var{file}@r{]}
38623@itemx maint print register-groups @r{[}@var{file}@r{]}
38624@itemx maint print remote-registers @r{[}@var{file}@r{]}
38625Print @value{GDBN}'s internal register data structures.
38626
38627The command @code{maint print raw-registers} includes the contents of
38628the raw register cache; the command @code{maint print
38629cooked-registers} includes the (cooked) value of all registers,
38630including registers which aren't available on the target nor visible
38631to user; the command @code{maint print register-groups} includes the
38632groups that each register is a member of; and the command @code{maint
38633print remote-registers} includes the remote target's register numbers
38634and offsets in the `G' packets.
38635
38636These commands take an optional parameter, a file name to which to
38637write the information.
38638
38639@kindex maint print reggroups
38640@item maint print reggroups @r{[}@var{file}@r{]}
38641Print @value{GDBN}'s internal register group data structures.  The
38642optional argument @var{file} tells to what file to write the
38643information.
38644
38645The register groups info looks like this:
38646
38647@smallexample
38648(@value{GDBP}) @kbd{maint print reggroups}
38649 Group      Type
38650 general    user
38651 float      user
38652 all        user
38653 vector     user
38654 system     user
38655 save       internal
38656 restore    internal
38657@end smallexample
38658
38659@kindex flushregs
38660@item flushregs
38661This command forces @value{GDBN} to flush its internal register cache.
38662
38663@kindex maint print objfiles
38664@cindex info for known object files
38665@item maint print objfiles @r{[}@var{regexp}@r{]}
38666Print a dump of all known object files.
38667If @var{regexp} is specified, only print object files whose names
38668match @var{regexp}.  For each object file, this command prints its name,
38669address in memory, and all of its psymtabs and symtabs.
38670
38671@kindex maint print user-registers
38672@cindex user registers
38673@item maint print user-registers
38674List all currently available @dfn{user registers}.  User registers
38675typically provide alternate names for actual hardware registers.  They
38676include the four ``standard'' registers @code{$fp}, @code{$pc},
38677@code{$sp}, and @code{$ps}.  @xref{standard registers}.  User
38678registers can be used in expressions in the same way as the canonical
38679register names, but only the latter are listed by the @code{info
38680registers} and @code{maint print registers} commands.
38681
38682@kindex maint print section-scripts
38683@cindex info for known .debug_gdb_scripts-loaded scripts
38684@item maint print section-scripts [@var{regexp}]
38685Print a dump of scripts specified in the @code{.debug_gdb_section} section.
38686If @var{regexp} is specified, only print scripts loaded by object files
38687matching @var{regexp}.
38688For each script, this command prints its name as specified in the objfile,
38689and the full path if known.
38690@xref{dotdebug_gdb_scripts section}.
38691
38692@kindex maint print statistics
38693@cindex bcache statistics
38694@item maint print statistics
38695This command prints, for each object file in the program, various data
38696about that object file followed by the byte cache (@dfn{bcache})
38697statistics for the object file.  The objfile data includes the number
38698of minimal, partial, full, and stabs symbols, the number of types
38699defined by the objfile, the number of as yet unexpanded psym tables,
38700the number of line tables and string tables, and the amount of memory
38701used by the various tables.  The bcache statistics include the counts,
38702sizes, and counts of duplicates of all and unique objects, max,
38703average, and median entry size, total memory used and its overhead and
38704savings, and various measures of the hash table size and chain
38705lengths.
38706
38707@kindex maint print target-stack
38708@cindex target stack description
38709@item maint print target-stack
38710A @dfn{target} is an interface between the debugger and a particular
38711kind of file or process.  Targets can be stacked in @dfn{strata},
38712so that more than one target can potentially respond to a request.
38713In particular, memory accesses will walk down the stack of targets
38714until they find a target that is interested in handling that particular
38715address.
38716
38717This command prints a short description of each layer that was pushed on
38718the @dfn{target stack}, starting from the top layer down to the bottom one.
38719
38720@kindex maint print type
38721@cindex type chain of a data type
38722@item maint print type @var{expr}
38723Print the type chain for a type specified by @var{expr}.  The argument
38724can be either a type name or a symbol.  If it is a symbol, the type of
38725that symbol is described.  The type chain produced by this command is
38726a recursive definition of the data type as stored in @value{GDBN}'s
38727data structures, including its flags and contained types.
38728
38729@kindex maint selftest
38730@cindex self tests
38731@item maint selftest @r{[}@var{filter}@r{]}
38732Run any self tests that were compiled in to @value{GDBN}.  This will
38733print a message showing how many tests were run, and how many failed.
38734If a @var{filter} is passed, only the tests with @var{filter} in their
38735name will by ran.
38736
38737@kindex maint info selftests
38738@cindex self tests
38739@item maint info selftests
38740List the selftests compiled in to @value{GDBN}.
38741
38742@kindex maint set dwarf always-disassemble
38743@kindex maint show dwarf always-disassemble
38744@item maint set dwarf always-disassemble
38745@item maint show dwarf always-disassemble
38746Control the behavior of @code{info address} when using DWARF debugging
38747information.
38748
38749The default is @code{off}, which means that @value{GDBN} should try to
38750describe a variable's location in an easily readable format.  When
38751@code{on}, @value{GDBN} will instead display the DWARF location
38752expression in an assembly-like format.  Note that some locations are
38753too complex for @value{GDBN} to describe simply; in this case you will
38754always see the disassembly form.
38755
38756Here is an example of the resulting disassembly:
38757
38758@smallexample
38759(gdb) info addr argc
38760Symbol "argc" is a complex DWARF expression:
38761     1: DW_OP_fbreg 0
38762@end smallexample
38763
38764For more information on these expressions, see
38765@uref{http://www.dwarfstd.org/, the DWARF standard}.
38766
38767@kindex maint set dwarf max-cache-age
38768@kindex maint show dwarf max-cache-age
38769@item maint set dwarf max-cache-age
38770@itemx maint show dwarf max-cache-age
38771Control the DWARF compilation unit cache.
38772
38773@cindex DWARF compilation units cache
38774In object files with inter-compilation-unit references, such as those
38775produced by the GCC option @samp{-feliminate-dwarf2-dups}, the DWARF
38776reader needs to frequently refer to previously read compilation units.
38777This setting controls how long a compilation unit will remain in the
38778cache if it is not referenced.  A higher limit means that cached
38779compilation units will be stored in memory longer, and more total
38780memory will be used.  Setting it to zero disables caching, which will
38781slow down @value{GDBN} startup, but reduce memory consumption.
38782
38783@kindex maint set dwarf unwinders
38784@kindex maint show dwarf unwinders
38785@item maint set dwarf unwinders
38786@itemx maint show dwarf unwinders
38787Control use of the DWARF frame unwinders.
38788
38789@cindex DWARF frame unwinders
38790Many targets that support DWARF debugging use @value{GDBN}'s DWARF
38791frame unwinders to build the backtrace.  Many of these targets will
38792also have a second mechanism for building the backtrace for use in
38793cases where DWARF information is not available, this second mechanism
38794is often an analysis of a function's prologue.
38795
38796In order to extend testing coverage of the second level stack
38797unwinding mechanisms it is helpful to be able to disable the DWARF
38798stack unwinders, this can be done with this switch.
38799
38800In normal use of @value{GDBN} disabling the DWARF unwinders is not
38801advisable, there are cases that are better handled through DWARF than
38802prologue analysis, and the debug experience is likely to be better
38803with the DWARF frame unwinders enabled.
38804
38805If DWARF frame unwinders are not supported for a particular target
38806architecture, then enabling this flag does not cause them to be used.
38807
38808@kindex maint set worker-threads
38809@kindex maint show worker-threads
38810@item maint set worker-threads
38811@item maint show worker-threads
38812Control the number of worker threads that may be used by @value{GDBN}.
38813On capable hosts, @value{GDBN} may use multiple threads to speed up
38814certain CPU-intensive operations, such as demangling symbol names.
38815While the number of threads used by @value{GDBN} may vary, this
38816command can be used to set an upper bound on this number.  The default
38817is @code{unlimited}, which lets @value{GDBN} choose a reasonable
38818number.  Note that this only controls worker threads started by
38819@value{GDBN} itself; libraries used by @value{GDBN} may start threads
38820of their own.
38821
38822@kindex maint set profile
38823@kindex maint show profile
38824@cindex profiling GDB
38825@item maint set profile
38826@itemx maint show profile
38827Control profiling of @value{GDBN}.
38828
38829Profiling will be disabled until you use the @samp{maint set profile}
38830command to enable it.  When you enable profiling, the system will begin
38831collecting timing and execution count data; when you disable profiling or
38832exit @value{GDBN}, the results will be written to a log file.  Remember that
38833if you use profiling, @value{GDBN} will overwrite the profiling log file
38834(often called @file{gmon.out}).  If you have a record of important profiling
38835data in a @file{gmon.out} file, be sure to move it to a safe location.
38836
38837Configuring with @samp{--enable-profiling} arranges for @value{GDBN} to be
38838compiled with the @samp{-pg} compiler option.
38839
38840@kindex maint set show-debug-regs
38841@kindex maint show show-debug-regs
38842@cindex hardware debug registers
38843@item maint set show-debug-regs
38844@itemx maint show show-debug-regs
38845Control whether to show variables that mirror the hardware debug
38846registers.  Use @code{on} to enable, @code{off} to disable.  If
38847enabled, the debug registers values are shown when @value{GDBN} inserts or
38848removes a hardware breakpoint or watchpoint, and when the inferior
38849triggers a hardware-assisted breakpoint or watchpoint.
38850
38851@kindex maint set show-all-tib
38852@kindex maint show show-all-tib
38853@item maint set show-all-tib
38854@itemx maint show show-all-tib
38855Control whether to show all non zero areas within a 1k block starting
38856at thread local base, when using the @samp{info w32 thread-information-block}
38857command.
38858
38859@kindex maint set target-async
38860@kindex maint show target-async
38861@item maint set target-async
38862@itemx maint show target-async
38863This controls whether @value{GDBN} targets operate in synchronous or
38864asynchronous mode (@pxref{Background Execution}).  Normally the
38865default is asynchronous, if it is available; but this can be changed
38866to more easily debug problems occurring only in synchronous mode.
38867
38868@kindex maint set target-non-stop @var{mode} [on|off|auto]
38869@kindex maint show target-non-stop
38870@item maint set target-non-stop
38871@itemx maint show target-non-stop
38872
38873This controls whether @value{GDBN} targets always operate in non-stop
38874mode even if @code{set non-stop} is @code{off} (@pxref{Non-Stop
38875Mode}).  The default is @code{auto}, meaning non-stop mode is enabled
38876if supported by the target.
38877
38878@table @code
38879@item maint set target-non-stop auto
38880This is the default mode.  @value{GDBN} controls the target in
38881non-stop mode if the target supports it.
38882
38883@item maint set target-non-stop on
38884@value{GDBN} controls the target in non-stop mode even if the target
38885does not indicate support.
38886
38887@item maint set target-non-stop off
38888@value{GDBN} does not control the target in non-stop mode even if the
38889target supports it.
38890@end table
38891
38892@kindex maint set tui-resize-message
38893@kindex maint show tui-resize-message
38894@item maint set tui-resize-message
38895@item maint show tui-resize-message
38896Control whether @value{GDBN} displays a message each time the terminal
38897is resized when in TUI mode.  The default is @code{off}, which means
38898that @value{GDBN} is silent during resizes.  When @code{on},
38899@value{GDBN} will display a message after a resize is completed; the
38900message will include a number indicating how many times the terminal
38901has been resized.  This setting is intended for use by the test suite,
38902where it would otherwise be difficult to determine when a resize and
38903refresh has been completed.
38904
38905@kindex maint set per-command
38906@kindex maint show per-command
38907@item maint set per-command
38908@itemx maint show per-command
38909@cindex resources used by commands
38910
38911@value{GDBN} can display the resources used by each command.
38912This is useful in debugging performance problems.
38913
38914@table @code
38915@item maint set per-command space [on|off]
38916@itemx maint show per-command space
38917Enable or disable the printing of the memory used by GDB for each command.
38918If enabled, @value{GDBN} will display how much memory each command
38919took, following the command's own output.
38920This can also be requested by invoking @value{GDBN} with the
38921@option{--statistics} command-line switch (@pxref{Mode Options}).
38922
38923@item maint set per-command time [on|off]
38924@itemx maint show per-command time
38925Enable or disable the printing of the execution time of @value{GDBN}
38926for each command.
38927If enabled, @value{GDBN} will display how much time it
38928took to execute each command, following the command's own output.
38929Both CPU time and wallclock time are printed.
38930Printing both is useful when trying to determine whether the cost is
38931CPU or, e.g., disk/network latency.
38932Note that the CPU time printed is for @value{GDBN} only, it does not include
38933the execution time of the inferior because there's no mechanism currently
38934to compute how much time was spent by @value{GDBN} and how much time was
38935spent by the program been debugged.
38936This can also be requested by invoking @value{GDBN} with the
38937@option{--statistics} command-line switch (@pxref{Mode Options}).
38938
38939@item maint set per-command symtab [on|off]
38940@itemx maint show per-command symtab
38941Enable or disable the printing of basic symbol table statistics
38942for each command.
38943If enabled, @value{GDBN} will display the following information:
38944
38945@enumerate a
38946@item
38947number of symbol tables
38948@item
38949number of primary symbol tables
38950@item
38951number of blocks in the blockvector
38952@end enumerate
38953@end table
38954
38955@kindex maint set check-libthread-db
38956@kindex maint show check-libthread-db
38957@item maint set check-libthread-db [on|off]
38958@itemx maint show check-libthread-db
38959Control whether @value{GDBN} should run integrity checks on inferior
38960specific thread debugging libraries as they are loaded.  The default
38961is not to perform such checks.  If any check fails @value{GDBN} will
38962unload the library and continue searching for a suitable candidate as
38963described in @ref{set libthread-db-search-path}.  For more information
38964about the tests, see @ref{maint check libthread-db}.
38965
38966@kindex maint space
38967@cindex memory used by commands
38968@item maint space @var{value}
38969An alias for @code{maint set per-command space}.
38970A non-zero value enables it, zero disables it.
38971
38972@kindex maint time
38973@cindex time of command execution
38974@item maint time @var{value}
38975An alias for @code{maint set per-command time}.
38976A non-zero value enables it, zero disables it.
38977
38978@kindex maint translate-address
38979@item maint translate-address @r{[}@var{section}@r{]} @var{addr}
38980Find the symbol stored at the location specified by the address
38981@var{addr} and an optional section name @var{section}.  If found,
38982@value{GDBN} prints the name of the closest symbol and an offset from
38983the symbol's location to the specified address.  This is similar to
38984the @code{info address} command (@pxref{Symbols}), except that this
38985command also allows to find symbols in other sections.
38986
38987If section was not specified, the section in which the symbol was found
38988is also printed.  For dynamically linked executables, the name of
38989executable or shared library containing the symbol is printed as well.
38990
38991@kindex maint test-options
38992@item maint test-options require-delimiter
38993@itemx maint test-options unknown-is-error
38994@itemx maint test-options unknown-is-operand
38995These commands are used by the testsuite to validate the command
38996options framework.  The @code{require-delimiter} variant requires a
38997double-dash delimiter to indicate end of options.  The
38998@code{unknown-is-error} and @code{unknown-is-operand} do not.  The
38999@code{unknown-is-error} variant throws an error on unknown option,
39000while @code{unknown-is-operand} treats unknown options as the start of
39001the command's operands.  When run, the commands output the result of
39002the processed options.  When completed, the commands store the
39003internal result of completion in a variable exposed by the @code{maint
39004show test-options-completion-result} command.
39005
39006@kindex maint show test-options-completion-result
39007@item maint show test-options-completion-result
39008Shows the result of completing the @code{maint test-options}
39009subcommands.  This is used by the testsuite to validate completion
39010support in the command options framework.
39011
39012@kindex maint set test-settings
39013@kindex maint show test-settings
39014@item maint set test-settings @var{kind}
39015@itemx maint show test-settings @var{kind}
39016These are representative commands for each @var{kind} of setting type
39017@value{GDBN} supports.  They are used by the testsuite for exercising
39018the settings infrastructure.
39019
39020@kindex maint with
39021@item maint with @var{setting} [@var{value}] [-- @var{command}]
39022Like the @code{with} command, but works with @code{maintenance set}
39023variables.  This is used by the testsuite to exercise the @code{with}
39024command's infrastructure.
39025
39026@end table
39027
39028The following command is useful for non-interactive invocations of
39029@value{GDBN}, such as in the test suite.
39030
39031@table @code
39032@item set watchdog @var{nsec}
39033@kindex set watchdog
39034@cindex watchdog timer
39035@cindex timeout for commands
39036Set the maximum number of seconds @value{GDBN} will wait for the
39037target operation to finish.  If this time expires, @value{GDBN}
39038reports and error and the command is aborted.
39039
39040@item show watchdog
39041Show the current setting of the target wait timeout.
39042@end table
39043
39044@node Remote Protocol
39045@appendix @value{GDBN} Remote Serial Protocol
39046
39047@menu
39048* Overview::
39049* Packets::
39050* Stop Reply Packets::
39051* General Query Packets::
39052* Architecture-Specific Protocol Details::
39053* Tracepoint Packets::
39054* Host I/O Packets::
39055* Interrupts::
39056* Notification Packets::
39057* Remote Non-Stop::
39058* Packet Acknowledgment::
39059* Examples::
39060* File-I/O Remote Protocol Extension::
39061* Library List Format::
39062* Library List Format for SVR4 Targets::
39063* Memory Map Format::
39064* Thread List Format::
39065* Traceframe Info Format::
39066* Branch Trace Format::
39067* Branch Trace Configuration Format::
39068@end menu
39069
39070@node Overview
39071@section Overview
39072
39073There may be occasions when you need to know something about the
39074protocol---for example, if there is only one serial port to your target
39075machine, you might want your program to do something special if it
39076recognizes a packet meant for @value{GDBN}.
39077
39078In the examples below, @samp{->} and @samp{<-} are used to indicate
39079transmitted and received data, respectively.
39080
39081@cindex protocol, @value{GDBN} remote serial
39082@cindex serial protocol, @value{GDBN} remote
39083@cindex remote serial protocol
39084All @value{GDBN} commands and responses (other than acknowledgments
39085and notifications, see @ref{Notification Packets}) are sent as a
39086@var{packet}.  A @var{packet} is introduced with the character
39087@samp{$}, the actual @var{packet-data}, and the terminating character
39088@samp{#} followed by a two-digit @var{checksum}:
39089
39090@smallexample
39091@code{$}@var{packet-data}@code{#}@var{checksum}
39092@end smallexample
39093@noindent
39094
39095@cindex checksum, for @value{GDBN} remote
39096@noindent
39097The two-digit @var{checksum} is computed as the modulo 256 sum of all
39098characters between the leading @samp{$} and the trailing @samp{#} (an
39099eight bit unsigned checksum).
39100
39101Implementors should note that prior to @value{GDBN} 5.0 the protocol
39102specification also included an optional two-digit @var{sequence-id}:
39103
39104@smallexample
39105@code{$}@var{sequence-id}@code{:}@var{packet-data}@code{#}@var{checksum}
39106@end smallexample
39107
39108@cindex sequence-id, for @value{GDBN} remote
39109@noindent
39110That @var{sequence-id} was appended to the acknowledgment.  @value{GDBN}
39111has never output @var{sequence-id}s.  Stubs that handle packets added
39112since @value{GDBN} 5.0 must not accept @var{sequence-id}.
39113
39114When either the host or the target machine receives a packet, the first
39115response expected is an acknowledgment: either @samp{+} (to indicate
39116the package was received correctly) or @samp{-} (to request
39117retransmission):
39118
39119@smallexample
39120-> @code{$}@var{packet-data}@code{#}@var{checksum}
39121<- @code{+}
39122@end smallexample
39123@noindent
39124
39125The @samp{+}/@samp{-} acknowledgments can be disabled
39126once a connection is established.
39127@xref{Packet Acknowledgment}, for details.
39128
39129The host (@value{GDBN}) sends @var{command}s, and the target (the
39130debugging stub incorporated in your program) sends a @var{response}.  In
39131the case of step and continue @var{command}s, the response is only sent
39132when the operation has completed, and the target has again stopped all
39133threads in all attached processes.  This is the default all-stop mode
39134behavior, but the remote protocol also supports @value{GDBN}'s non-stop
39135execution mode; see @ref{Remote Non-Stop}, for details.
39136
39137@var{packet-data} consists of a sequence of characters with the
39138exception of @samp{#} and @samp{$} (see @samp{X} packet for additional
39139exceptions).
39140
39141@cindex remote protocol, field separator
39142Fields within the packet should be separated using @samp{,} @samp{;} or
39143@samp{:}.  Except where otherwise noted all numbers are represented in
39144@sc{hex} with leading zeros suppressed.
39145
39146Implementors should note that prior to @value{GDBN} 5.0, the character
39147@samp{:} could not appear as the third character in a packet (as it
39148would potentially conflict with the @var{sequence-id}).
39149
39150@cindex remote protocol, binary data
39151@anchor{Binary Data}
39152Binary data in most packets is encoded either as two hexadecimal
39153digits per byte of binary data.  This allowed the traditional remote
39154protocol to work over connections which were only seven-bit clean.
39155Some packets designed more recently assume an eight-bit clean
39156connection, and use a more efficient encoding to send and receive
39157binary data.
39158
39159The binary data representation uses @code{7d} (@sc{ascii} @samp{@}})
39160as an escape character.  Any escaped byte is transmitted as the escape
39161character followed by the original character XORed with @code{0x20}.
39162For example, the byte @code{0x7d} would be transmitted as the two
39163bytes @code{0x7d 0x5d}.  The bytes @code{0x23} (@sc{ascii} @samp{#}),
39164@code{0x24} (@sc{ascii} @samp{$}), and @code{0x7d} (@sc{ascii}
39165@samp{@}}) must always be escaped.  Responses sent by the stub
39166must also escape @code{0x2a} (@sc{ascii} @samp{*}), so that it
39167is not interpreted as the start of a run-length encoded sequence
39168(described next).
39169
39170Response @var{data} can be run-length encoded to save space.
39171Run-length encoding replaces runs of identical characters with one
39172instance of the repeated character, followed by a @samp{*} and a
39173repeat count.  The repeat count is itself sent encoded, to avoid
39174binary characters in @var{data}: a value of @var{n} is sent as
39175@code{@var{n}+29}.  For a repeat count greater or equal to 3, this
39176produces a printable @sc{ascii} character, e.g.@: a space (@sc{ascii}
39177code 32) for a repeat count of 3.  (This is because run-length
39178encoding starts to win for counts 3 or more.)  Thus, for example,
39179@samp{0* } is a run-length encoding of ``0000'': the space character
39180after @samp{*} means repeat the leading @code{0} @w{@code{32 - 29 =
391813}} more times.
39182
39183The printable characters @samp{#} and @samp{$} or with a numeric value
39184greater than 126 must not be used.  Runs of six repeats (@samp{#}) or
39185seven repeats (@samp{$}) can be expanded using a repeat count of only
39186five (@samp{"}).  For example, @samp{00000000} can be encoded as
39187@samp{0*"00}.
39188
39189The error response returned for some packets includes a two character
39190error number.  That number is not well defined.
39191
39192@cindex empty response, for unsupported packets
39193For any @var{command} not supported by the stub, an empty response
39194(@samp{$#00}) should be returned.  That way it is possible to extend the
39195protocol.  A newer @value{GDBN} can tell if a packet is supported based
39196on that response.
39197
39198At a minimum, a stub is required to support the @samp{?} command to
39199tell @value{GDBN} the reason for halting, @samp{g} and @samp{G}
39200commands for register access, and the @samp{m} and @samp{M} commands
39201for memory access.  Stubs that only control single-threaded targets
39202can implement run control with the @samp{c} (continue) command, and if
39203the target architecture supports hardware-assisted single-stepping,
39204the @samp{s} (step) command.  Stubs that support multi-threading
39205targets should support the @samp{vCont} command.  All other commands
39206are optional.
39207
39208@node Packets
39209@section Packets
39210
39211The following table provides a complete list of all currently defined
39212@var{command}s and their corresponding response @var{data}.
39213@xref{File-I/O Remote Protocol Extension}, for details about the File
39214I/O extension of the remote protocol.
39215
39216Each packet's description has a template showing the packet's overall
39217syntax, followed by an explanation of the packet's meaning.  We
39218include spaces in some of the templates for clarity; these are not
39219part of the packet's syntax.  No @value{GDBN} packet uses spaces to
39220separate its components.  For example, a template like @samp{foo
39221@var{bar} @var{baz}} describes a packet beginning with the three ASCII
39222bytes @samp{foo}, followed by a @var{bar}, followed directly by a
39223@var{baz}.  @value{GDBN} does not transmit a space character between the
39224@samp{foo} and the @var{bar}, or between the @var{bar} and the
39225@var{baz}.
39226
39227@cindex @var{thread-id}, in remote protocol
39228@anchor{thread-id syntax}
39229Several packets and replies include a @var{thread-id} field to identify
39230a thread.  Normally these are positive numbers with a target-specific
39231interpretation, formatted as big-endian hex strings.  A @var{thread-id}
39232can also be a literal @samp{-1} to indicate all threads, or @samp{0} to
39233pick any thread.
39234
39235In addition, the remote protocol supports a multiprocess feature in
39236which the @var{thread-id} syntax is extended to optionally include both
39237process and thread ID fields, as @samp{p@var{pid}.@var{tid}}.
39238The @var{pid} (process) and @var{tid} (thread) components each have the
39239format described above: a positive number with target-specific
39240interpretation formatted as a big-endian hex string, literal @samp{-1}
39241to indicate all processes or threads (respectively), or @samp{0} to
39242indicate an arbitrary process or thread.  Specifying just a process, as
39243@samp{p@var{pid}}, is equivalent to @samp{p@var{pid}.-1}.  It is an
39244error to specify all processes but a specific thread, such as
39245@samp{p-1.@var{tid}}.  Note that the @samp{p} prefix is @emph{not} used
39246for those packets and replies explicitly documented to include a process
39247ID, rather than a @var{thread-id}.
39248
39249The multiprocess @var{thread-id} syntax extensions are only used if both
39250@value{GDBN} and the stub report support for the @samp{multiprocess}
39251feature using @samp{qSupported}.  @xref{multiprocess extensions}, for
39252more information.
39253
39254Note that all packet forms beginning with an upper- or lower-case
39255letter, other than those described here, are reserved for future use.
39256
39257Here are the packet descriptions.
39258
39259@table @samp
39260
39261@item !
39262@cindex @samp{!} packet
39263@anchor{extended mode}
39264Enable extended mode.  In extended mode, the remote server is made
39265persistent.  The @samp{R} packet is used to restart the program being
39266debugged.
39267
39268Reply:
39269@table @samp
39270@item OK
39271The remote target both supports and has enabled extended mode.
39272@end table
39273
39274@item ?
39275@cindex @samp{?} packet
39276@anchor{? packet}
39277Indicate the reason the target halted.  The reply is the same as for
39278step and continue.  This packet has a special interpretation when the
39279target is in non-stop mode; see @ref{Remote Non-Stop}.
39280
39281Reply:
39282@xref{Stop Reply Packets}, for the reply specifications.
39283
39284@item A @var{arglen},@var{argnum},@var{arg},@dots{}
39285@cindex @samp{A} packet
39286Initialized @code{argv[]} array passed into program. @var{arglen}
39287specifies the number of bytes in the hex encoded byte stream
39288@var{arg}.  See @code{gdbserver} for more details.
39289
39290Reply:
39291@table @samp
39292@item OK
39293The arguments were set.
39294@item E @var{NN}
39295An error occurred.
39296@end table
39297
39298@item b @var{baud}
39299@cindex @samp{b} packet
39300(Don't use this packet; its behavior is not well-defined.)
39301Change the serial line speed to @var{baud}.
39302
39303JTC: @emph{When does the transport layer state change?  When it's
39304received, or after the ACK is transmitted.  In either case, there are
39305problems if the command or the acknowledgment packet is dropped.}
39306
39307Stan: @emph{If people really wanted to add something like this, and get
39308it working for the first time, they ought to modify ser-unix.c to send
39309some kind of out-of-band message to a specially-setup stub and have the
39310switch happen "in between" packets, so that from remote protocol's point
39311of view, nothing actually happened.}
39312
39313@item B @var{addr},@var{mode}
39314@cindex @samp{B} packet
39315Set (@var{mode} is @samp{S}) or clear (@var{mode} is @samp{C}) a
39316breakpoint at @var{addr}.
39317
39318Don't use this packet.  Use the @samp{Z} and @samp{z} packets instead
39319(@pxref{insert breakpoint or watchpoint packet}).
39320
39321@cindex @samp{bc} packet
39322@anchor{bc}
39323@item bc
39324Backward continue.  Execute the target system in reverse.  No parameter.
39325@xref{Reverse Execution}, for more information.
39326
39327Reply:
39328@xref{Stop Reply Packets}, for the reply specifications.
39329
39330@cindex @samp{bs} packet
39331@anchor{bs}
39332@item bs
39333Backward single step.  Execute one instruction in reverse.  No parameter.
39334@xref{Reverse Execution}, for more information.
39335
39336Reply:
39337@xref{Stop Reply Packets}, for the reply specifications.
39338
39339@item c @r{[}@var{addr}@r{]}
39340@cindex @samp{c} packet
39341Continue at @var{addr}, which is the address to resume.  If @var{addr}
39342is omitted, resume at current address.
39343
39344This packet is deprecated for multi-threading support.  @xref{vCont
39345packet}.
39346
39347Reply:
39348@xref{Stop Reply Packets}, for the reply specifications.
39349
39350@item C @var{sig}@r{[};@var{addr}@r{]}
39351@cindex @samp{C} packet
39352Continue with signal @var{sig} (hex signal number).  If
39353@samp{;@var{addr}} is omitted, resume at same address.
39354
39355This packet is deprecated for multi-threading support.  @xref{vCont
39356packet}.
39357
39358Reply:
39359@xref{Stop Reply Packets}, for the reply specifications.
39360
39361@item d
39362@cindex @samp{d} packet
39363Toggle debug flag.
39364
39365Don't use this packet; instead, define a general set packet
39366(@pxref{General Query Packets}).
39367
39368@item D
39369@itemx D;@var{pid}
39370@cindex @samp{D} packet
39371The first form of the packet is used to detach @value{GDBN} from the
39372remote system.  It is sent to the remote target
39373before @value{GDBN} disconnects via the @code{detach} command.
39374
39375The second form, including a process ID, is used when multiprocess
39376protocol extensions are enabled (@pxref{multiprocess extensions}), to
39377detach only a specific process.  The @var{pid} is specified as a
39378big-endian hex string.
39379
39380Reply:
39381@table @samp
39382@item OK
39383for success
39384@item E @var{NN}
39385for an error
39386@end table
39387
39388@item F @var{RC},@var{EE},@var{CF};@var{XX}
39389@cindex @samp{F} packet
39390A reply from @value{GDBN} to an @samp{F} packet sent by the target.
39391This is part of the File-I/O protocol extension.  @xref{File-I/O
39392Remote Protocol Extension}, for the specification.
39393
39394@item g
39395@anchor{read registers packet}
39396@cindex @samp{g} packet
39397Read general registers.
39398
39399Reply:
39400@table @samp
39401@item @var{XX@dots{}}
39402Each byte of register data is described by two hex digits.  The bytes
39403with the register are transmitted in target byte order.  The size of
39404each register and their position within the @samp{g} packet are
39405determined by the @value{GDBN} internal gdbarch functions
39406@code{DEPRECATED_REGISTER_RAW_SIZE} and @code{gdbarch_register_name}.
39407
39408When reading registers from a trace frame (@pxref{Analyze Collected
39409Data,,Using the Collected Data}), the stub may also return a string of
39410literal @samp{x}'s in place of the register data digits, to indicate
39411that the corresponding register has not been collected, thus its value
39412is unavailable.  For example, for an architecture with 4 registers of
394134 bytes each, the following reply indicates to @value{GDBN} that
39414registers 0 and 2 have not been collected, while registers 1 and 3
39415have been collected, and both have zero value:
39416
39417@smallexample
39418-> @code{g}
39419<- @code{xxxxxxxx00000000xxxxxxxx00000000}
39420@end smallexample
39421
39422@item E @var{NN}
39423for an error.
39424@end table
39425
39426@item G @var{XX@dots{}}
39427@cindex @samp{G} packet
39428Write general registers.  @xref{read registers packet}, for a
39429description of the @var{XX@dots{}} data.
39430
39431Reply:
39432@table @samp
39433@item OK
39434for success
39435@item E @var{NN}
39436for an error
39437@end table
39438
39439@item H @var{op} @var{thread-id}
39440@cindex @samp{H} packet
39441Set thread for subsequent operations (@samp{m}, @samp{M}, @samp{g},
39442@samp{G}, et.al.).  Depending on the operation to be performed, @var{op}
39443should be @samp{c} for step and continue operations (note that this
39444is deprecated, supporting the @samp{vCont} command is a better
39445option), and @samp{g} for other operations.  The thread designator
39446@var{thread-id} has the format and interpretation described in
39447@ref{thread-id syntax}.
39448
39449Reply:
39450@table @samp
39451@item OK
39452for success
39453@item E @var{NN}
39454for an error
39455@end table
39456
39457@c FIXME: JTC:
39458@c   'H': How restrictive (or permissive) is the thread model.  If a
39459@c        thread is selected and stopped, are other threads allowed
39460@c        to continue to execute?  As I mentioned above, I think the
39461@c        semantics of each command when a thread is selected must be
39462@c        described.  For example:
39463@c
39464@c        'g':    If the stub supports threads and a specific thread is
39465@c                selected, returns the register block from that thread;
39466@c                otherwise returns current registers.
39467@c
39468@c        'G'     If the stub supports threads and a specific thread is
39469@c                selected, sets the registers of the register block of
39470@c                that thread; otherwise sets current registers.
39471
39472@item i @r{[}@var{addr}@r{[},@var{nnn}@r{]]}
39473@anchor{cycle step packet}
39474@cindex @samp{i} packet
39475Step the remote target by a single clock cycle.  If @samp{,@var{nnn}} is
39476present, cycle step @var{nnn} cycles.  If @var{addr} is present, cycle
39477step starting at that address.
39478
39479@item I
39480@cindex @samp{I} packet
39481Signal, then cycle step.  @xref{step with signal packet}.  @xref{cycle
39482step packet}.
39483
39484@item k
39485@cindex @samp{k} packet
39486Kill request.
39487
39488The exact effect of this packet is not specified.
39489
39490For a bare-metal target, it may power cycle or reset the target
39491system.  For that reason, the @samp{k} packet has no reply.
39492
39493For a single-process target, it may kill that process if possible.
39494
39495A multiple-process target may choose to kill just one process, or all
39496that are under @value{GDBN}'s control.  For more precise control, use
39497the vKill packet (@pxref{vKill packet}).
39498
39499If the target system immediately closes the connection in response to
39500@samp{k}, @value{GDBN} does not consider the lack of packet
39501acknowledgment to be an error, and assumes the kill was successful.
39502
39503If connected using @kbd{target extended-remote}, and the target does
39504not close the connection in response to a kill request, @value{GDBN}
39505probes the target state as if a new connection was opened
39506(@pxref{? packet}).
39507
39508@item m @var{addr},@var{length}
39509@cindex @samp{m} packet
39510Read @var{length} addressable memory units starting at address @var{addr}
39511(@pxref{addressable memory unit}).  Note that @var{addr} may not be aligned to
39512any particular boundary.
39513
39514The stub need not use any particular size or alignment when gathering
39515data from memory for the response; even if @var{addr} is word-aligned
39516and @var{length} is a multiple of the word size, the stub is free to
39517use byte accesses, or not.  For this reason, this packet may not be
39518suitable for accessing memory-mapped I/O devices.
39519@cindex alignment of remote memory accesses
39520@cindex size of remote memory accesses
39521@cindex memory, alignment and size of remote accesses
39522
39523Reply:
39524@table @samp
39525@item @var{XX@dots{}}
39526Memory contents; each byte is transmitted as a two-digit hexadecimal number.
39527The reply may contain fewer addressable memory units than requested if the
39528server was able to read only part of the region of memory.
39529@item E @var{NN}
39530@var{NN} is errno
39531@end table
39532
39533@item M @var{addr},@var{length}:@var{XX@dots{}}
39534@cindex @samp{M} packet
39535Write @var{length} addressable memory units starting at address @var{addr}
39536(@pxref{addressable memory unit}).  The data is given by @var{XX@dots{}}; each
39537byte is transmitted as a two-digit hexadecimal number.
39538
39539Reply:
39540@table @samp
39541@item OK
39542for success
39543@item E @var{NN}
39544for an error (this includes the case where only part of the data was
39545written).
39546@end table
39547
39548@item p @var{n}
39549@cindex @samp{p} packet
39550Read the value of register @var{n}; @var{n} is in hex.
39551@xref{read registers packet}, for a description of how the returned
39552register value is encoded.
39553
39554Reply:
39555@table @samp
39556@item @var{XX@dots{}}
39557the register's value
39558@item E @var{NN}
39559for an error
39560@item @w{}
39561Indicating an unrecognized @var{query}.
39562@end table
39563
39564@item P @var{n@dots{}}=@var{r@dots{}}
39565@anchor{write register packet}
39566@cindex @samp{P} packet
39567Write register @var{n@dots{}} with value @var{r@dots{}}.  The register
39568number @var{n} is in hexadecimal, and @var{r@dots{}} contains two hex
39569digits for each byte in the register (target byte order).
39570
39571Reply:
39572@table @samp
39573@item OK
39574for success
39575@item E @var{NN}
39576for an error
39577@end table
39578
39579@item q @var{name} @var{params}@dots{}
39580@itemx Q @var{name} @var{params}@dots{}
39581@cindex @samp{q} packet
39582@cindex @samp{Q} packet
39583General query (@samp{q}) and set (@samp{Q}).  These packets are
39584described fully in @ref{General Query Packets}.
39585
39586@item r
39587@cindex @samp{r} packet
39588Reset the entire system.
39589
39590Don't use this packet; use the @samp{R} packet instead.
39591
39592@item R @var{XX}
39593@cindex @samp{R} packet
39594Restart the program being debugged.  The @var{XX}, while needed, is ignored.
39595This packet is only available in extended mode (@pxref{extended mode}).
39596
39597The @samp{R} packet has no reply.
39598
39599@item s @r{[}@var{addr}@r{]}
39600@cindex @samp{s} packet
39601Single step, resuming at @var{addr}.  If
39602@var{addr} is omitted, resume at same address.
39603
39604This packet is deprecated for multi-threading support.  @xref{vCont
39605packet}.
39606
39607Reply:
39608@xref{Stop Reply Packets}, for the reply specifications.
39609
39610@item S @var{sig}@r{[};@var{addr}@r{]}
39611@anchor{step with signal packet}
39612@cindex @samp{S} packet
39613Step with signal.  This is analogous to the @samp{C} packet, but
39614requests a single-step, rather than a normal resumption of execution.
39615
39616This packet is deprecated for multi-threading support.  @xref{vCont
39617packet}.
39618
39619Reply:
39620@xref{Stop Reply Packets}, for the reply specifications.
39621
39622@item t @var{addr}:@var{PP},@var{MM}
39623@cindex @samp{t} packet
39624Search backwards starting at address @var{addr} for a match with pattern
39625@var{PP} and mask @var{MM}, both of which are are 4 byte long.
39626There must be at least 3 digits in @var{addr}.
39627
39628@item T @var{thread-id}
39629@cindex @samp{T} packet
39630Find out if the thread @var{thread-id} is alive.  @xref{thread-id syntax}.
39631
39632Reply:
39633@table @samp
39634@item OK
39635thread is still alive
39636@item E @var{NN}
39637thread is dead
39638@end table
39639
39640@item v
39641Packets starting with @samp{v} are identified by a multi-letter name,
39642up to the first @samp{;} or @samp{?} (or the end of the packet).
39643
39644@item vAttach;@var{pid}
39645@cindex @samp{vAttach} packet
39646Attach to a new process with the specified process ID @var{pid}.
39647The process ID is a
39648hexadecimal integer identifying the process.  In all-stop mode, all
39649threads in the attached process are stopped; in non-stop mode, it may be
39650attached without being stopped if that is supported by the target.
39651
39652@c In non-stop mode, on a successful vAttach, the stub should set the
39653@c current thread to a thread of the newly-attached process.  After
39654@c attaching, GDB queries for the attached process's thread ID with qC.
39655@c Also note that, from a user perspective, whether or not the
39656@c target is stopped on attach in non-stop mode depends on whether you
39657@c use the foreground or background version of the attach command, not
39658@c on what vAttach does; GDB does the right thing with respect to either
39659@c stopping or restarting threads.
39660
39661This packet is only available in extended mode (@pxref{extended mode}).
39662
39663Reply:
39664@table @samp
39665@item E @var{nn}
39666for an error
39667@item @r{Any stop packet}
39668for success in all-stop mode (@pxref{Stop Reply Packets})
39669@item OK
39670for success in non-stop mode (@pxref{Remote Non-Stop})
39671@end table
39672
39673@item vCont@r{[};@var{action}@r{[}:@var{thread-id}@r{]]}@dots{}
39674@cindex @samp{vCont} packet
39675@anchor{vCont packet}
39676Resume the inferior, specifying different actions for each thread.
39677
39678For each inferior thread, the leftmost action with a matching
39679@var{thread-id} is applied.  Threads that don't match any action
39680remain in their current state.  Thread IDs are specified using the
39681syntax described in @ref{thread-id syntax}.  If multiprocess
39682extensions (@pxref{multiprocess extensions}) are supported, actions
39683can be specified to match all threads in a process by using the
39684@samp{p@var{pid}.-1} form of the @var{thread-id}.  An action with no
39685@var{thread-id} matches all threads.  Specifying no actions is an
39686error.
39687
39688Currently supported actions are:
39689
39690@table @samp
39691@item c
39692Continue.
39693@item C @var{sig}
39694Continue with signal @var{sig}.  The signal @var{sig} should be two hex digits.
39695@item s
39696Step.
39697@item S @var{sig}
39698Step with signal @var{sig}.  The signal @var{sig} should be two hex digits.
39699@item t
39700Stop.
39701@item r @var{start},@var{end}
39702Step once, and then keep stepping as long as the thread stops at
39703addresses between @var{start} (inclusive) and @var{end} (exclusive).
39704The remote stub reports a stop reply when either the thread goes out
39705of the range or is stopped due to an unrelated reason, such as hitting
39706a breakpoint.  @xref{range stepping}.
39707
39708If the range is empty (@var{start} == @var{end}), then the action
39709becomes equivalent to the @samp{s} action.  In other words,
39710single-step once, and report the stop (even if the stepped instruction
39711jumps to @var{start}).
39712
39713(A stop reply may be sent at any point even if the PC is still within
39714the stepping range; for example, it is valid to implement this packet
39715in a degenerate way as a single instruction step operation.)
39716
39717@end table
39718
39719The optional argument @var{addr} normally associated with the
39720@samp{c}, @samp{C}, @samp{s}, and @samp{S} packets is
39721not supported in @samp{vCont}.
39722
39723The @samp{t} action is only relevant in non-stop mode
39724(@pxref{Remote Non-Stop}) and may be ignored by the stub otherwise.
39725A stop reply should be generated for any affected thread not already stopped.
39726When a thread is stopped by means of a @samp{t} action,
39727the corresponding stop reply should indicate that the thread has stopped with
39728signal @samp{0}, regardless of whether the target uses some other signal
39729as an implementation detail.
39730
39731The server must ignore @samp{c}, @samp{C}, @samp{s}, @samp{S}, and
39732@samp{r} actions for threads that are already running.  Conversely,
39733the server must ignore @samp{t} actions for threads that are already
39734stopped.
39735
39736@emph{Note:} In non-stop mode, a thread is considered running until
39737@value{GDBN} acknowledges an asynchronous stop notification for it with
39738the @samp{vStopped} packet (@pxref{Remote Non-Stop}).
39739
39740The stub must support @samp{vCont} if it reports support for
39741multiprocess extensions (@pxref{multiprocess extensions}).
39742
39743Reply:
39744@xref{Stop Reply Packets}, for the reply specifications.
39745
39746@item vCont?
39747@cindex @samp{vCont?} packet
39748Request a list of actions supported by the @samp{vCont} packet.
39749
39750Reply:
39751@table @samp
39752@item vCont@r{[};@var{action}@dots{}@r{]}
39753The @samp{vCont} packet is supported.  Each @var{action} is a supported
39754command in the @samp{vCont} packet.
39755@item @w{}
39756The @samp{vCont} packet is not supported.
39757@end table
39758
39759@anchor{vCtrlC packet}
39760@item vCtrlC
39761@cindex @samp{vCtrlC} packet
39762Interrupt remote target as if a control-C was pressed on the remote
39763terminal.  This is the equivalent to reacting to the @code{^C}
39764(@samp{\003}, the control-C character) character in all-stop mode
39765while the target is running, except this works in non-stop mode.
39766@xref{interrupting remote targets}, for more info on the all-stop
39767variant.
39768
39769Reply:
39770@table @samp
39771@item E @var{nn}
39772for an error
39773@item OK
39774for success
39775@end table
39776
39777@item vFile:@var{operation}:@var{parameter}@dots{}
39778@cindex @samp{vFile} packet
39779Perform a file operation on the target system.  For details,
39780see @ref{Host I/O Packets}.
39781
39782@item vFlashErase:@var{addr},@var{length}
39783@cindex @samp{vFlashErase} packet
39784Direct the stub to erase @var{length} bytes of flash starting at
39785@var{addr}.  The region may enclose any number of flash blocks, but
39786its start and end must fall on block boundaries, as indicated by the
39787flash block size appearing in the memory map (@pxref{Memory Map
39788Format}).  @value{GDBN} groups flash memory programming operations
39789together, and sends a @samp{vFlashDone} request after each group; the
39790stub is allowed to delay erase operation until the @samp{vFlashDone}
39791packet is received.
39792
39793Reply:
39794@table @samp
39795@item OK
39796for success
39797@item E @var{NN}
39798for an error
39799@end table
39800
39801@item vFlashWrite:@var{addr}:@var{XX@dots{}}
39802@cindex @samp{vFlashWrite} packet
39803Direct the stub to write data to flash address @var{addr}.  The data
39804is passed in binary form using the same encoding as for the @samp{X}
39805packet (@pxref{Binary Data}).  The memory ranges specified by
39806@samp{vFlashWrite} packets preceding a @samp{vFlashDone} packet must
39807not overlap, and must appear in order of increasing addresses
39808(although @samp{vFlashErase} packets for higher addresses may already
39809have been received; the ordering is guaranteed only between
39810@samp{vFlashWrite} packets).  If a packet writes to an address that was
39811neither erased by a preceding @samp{vFlashErase} packet nor by some other
39812target-specific method, the results are unpredictable.
39813
39814
39815Reply:
39816@table @samp
39817@item OK
39818for success
39819@item E.memtype
39820for vFlashWrite addressing non-flash memory
39821@item E @var{NN}
39822for an error
39823@end table
39824
39825@item vFlashDone
39826@cindex @samp{vFlashDone} packet
39827Indicate to the stub that flash programming operation is finished.
39828The stub is permitted to delay or batch the effects of a group of
39829@samp{vFlashErase} and @samp{vFlashWrite} packets until a
39830@samp{vFlashDone} packet is received.  The contents of the affected
39831regions of flash memory are unpredictable until the @samp{vFlashDone}
39832request is completed.
39833
39834@item vKill;@var{pid}
39835@cindex @samp{vKill} packet
39836@anchor{vKill packet}
39837Kill the process with the specified process ID @var{pid}, which is a
39838hexadecimal integer identifying the process.  This packet is used in
39839preference to @samp{k} when multiprocess protocol extensions are
39840supported; see @ref{multiprocess extensions}.
39841
39842Reply:
39843@table @samp
39844@item E @var{nn}
39845for an error
39846@item OK
39847for success
39848@end table
39849
39850@item vMustReplyEmpty
39851@cindex @samp{vMustReplyEmpty} packet
39852The correct reply to an unknown @samp{v} packet is to return the empty
39853string, however, some older versions of @command{gdbserver} would
39854incorrectly return @samp{OK} for unknown @samp{v} packets.
39855
39856The @samp{vMustReplyEmpty} is used as a feature test to check how
39857@command{gdbserver} handles unknown packets, it is important that this
39858packet be handled in the same way as other unknown @samp{v} packets.
39859If this packet is handled differently to other unknown @samp{v}
39860packets then it is possible that @value{GDBN} may run into problems in
39861other areas, specifically around use of @samp{vFile:setfs:}.
39862
39863@item vRun;@var{filename}@r{[};@var{argument}@r{]}@dots{}
39864@cindex @samp{vRun} packet
39865Run the program @var{filename}, passing it each @var{argument} on its
39866command line.  The file and arguments are hex-encoded strings.  If
39867@var{filename} is an empty string, the stub may use a default program
39868(e.g.@: the last program run).  The program is created in the stopped
39869state.
39870
39871@c FIXME:  What about non-stop mode?
39872
39873This packet is only available in extended mode (@pxref{extended mode}).
39874
39875Reply:
39876@table @samp
39877@item E @var{nn}
39878for an error
39879@item @r{Any stop packet}
39880for success (@pxref{Stop Reply Packets})
39881@end table
39882
39883@item vStopped
39884@cindex @samp{vStopped} packet
39885@xref{Notification Packets}.
39886
39887@item X @var{addr},@var{length}:@var{XX@dots{}}
39888@anchor{X packet}
39889@cindex @samp{X} packet
39890Write data to memory, where the data is transmitted in binary.
39891Memory is specified by its address @var{addr} and number of addressable memory
39892units @var{length} (@pxref{addressable memory unit});
39893@samp{@var{XX}@dots{}} is binary data (@pxref{Binary Data}).
39894
39895Reply:
39896@table @samp
39897@item OK
39898for success
39899@item E @var{NN}
39900for an error
39901@end table
39902
39903@item z @var{type},@var{addr},@var{kind}
39904@itemx Z @var{type},@var{addr},@var{kind}
39905@anchor{insert breakpoint or watchpoint packet}
39906@cindex @samp{z} packet
39907@cindex @samp{Z} packets
39908Insert (@samp{Z}) or remove (@samp{z}) a @var{type} breakpoint or
39909watchpoint starting at address @var{address} of kind @var{kind}.
39910
39911Each breakpoint and watchpoint packet @var{type} is documented
39912separately.
39913
39914@emph{Implementation notes: A remote target shall return an empty string
39915for an unrecognized breakpoint or watchpoint packet @var{type}.  A
39916remote target shall support either both or neither of a given
39917@samp{Z@var{type}@dots{}} and @samp{z@var{type}@dots{}} packet pair.  To
39918avoid potential problems with duplicate packets, the operations should
39919be implemented in an idempotent way.}
39920
39921@item z0,@var{addr},@var{kind}
39922@itemx Z0,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}@r{[};cmds:@var{persist},@var{cmd_list}@dots{}@r{]}
39923@cindex @samp{z0} packet
39924@cindex @samp{Z0} packet
39925Insert (@samp{Z0}) or remove (@samp{z0}) a software breakpoint at address
39926@var{addr} of type @var{kind}.
39927
39928A software breakpoint is implemented by replacing the instruction at
39929@var{addr} with a software breakpoint or trap instruction.  The
39930@var{kind} is target-specific and typically indicates the size of the
39931breakpoint in bytes that should be inserted.  E.g., the @sc{arm} and
39932@sc{mips} can insert either a 2 or 4 byte breakpoint.  Some
39933architectures have additional meanings for @var{kind}
39934(@pxref{Architecture-Specific Protocol Details}); if no
39935architecture-specific value is being used, it should be @samp{0}.
39936@var{kind} is hex-encoded.  @var{cond_list} is an optional list of
39937conditional expressions in bytecode form that should be evaluated on
39938the target's side.  These are the conditions that should be taken into
39939consideration when deciding if the breakpoint trigger should be
39940reported back to @value{GDBN}.
39941
39942See also the @samp{swbreak} stop reason (@pxref{swbreak stop reason})
39943for how to best report a software breakpoint event to @value{GDBN}.
39944
39945The @var{cond_list} parameter is comprised of a series of expressions,
39946concatenated without separators. Each expression has the following form:
39947
39948@table @samp
39949
39950@item X @var{len},@var{expr}
39951@var{len} is the length of the bytecode expression and @var{expr} is the
39952actual conditional expression in bytecode form.
39953
39954@end table
39955
39956The optional @var{cmd_list} parameter introduces commands that may be
39957run on the target, rather than being reported back to @value{GDBN}.
39958The parameter starts with a numeric flag @var{persist}; if the flag is
39959nonzero, then the breakpoint may remain active and the commands
39960continue to be run even when @value{GDBN} disconnects from the target.
39961Following this flag is a series of expressions concatenated with no
39962separators.  Each expression has the following form:
39963
39964@table @samp
39965
39966@item X @var{len},@var{expr}
39967@var{len} is the length of the bytecode expression and @var{expr} is the
39968actual commands expression in bytecode form.
39969
39970@end table
39971
39972@emph{Implementation note: It is possible for a target to copy or move
39973code that contains software breakpoints (e.g., when implementing
39974overlays).  The behavior of this packet, in the presence of such a
39975target, is not defined.}
39976
39977Reply:
39978@table @samp
39979@item OK
39980success
39981@item @w{}
39982not supported
39983@item E @var{NN}
39984for an error
39985@end table
39986
39987@item z1,@var{addr},@var{kind}
39988@itemx Z1,@var{addr},@var{kind}@r{[};@var{cond_list}@dots{}@r{]}@r{[};cmds:@var{persist},@var{cmd_list}@dots{}@r{]}
39989@cindex @samp{z1} packet
39990@cindex @samp{Z1} packet
39991Insert (@samp{Z1}) or remove (@samp{z1}) a hardware breakpoint at
39992address @var{addr}.
39993
39994A hardware breakpoint is implemented using a mechanism that is not
39995dependent on being able to modify the target's memory.  The
39996@var{kind}, @var{cond_list}, and @var{cmd_list} arguments have the
39997same meaning as in @samp{Z0} packets.
39998
39999@emph{Implementation note: A hardware breakpoint is not affected by code
40000movement.}
40001
40002Reply:
40003@table @samp
40004@item OK
40005success
40006@item @w{}
40007not supported
40008@item E @var{NN}
40009for an error
40010@end table
40011
40012@item z2,@var{addr},@var{kind}
40013@itemx Z2,@var{addr},@var{kind}
40014@cindex @samp{z2} packet
40015@cindex @samp{Z2} packet
40016Insert (@samp{Z2}) or remove (@samp{z2}) a write watchpoint at @var{addr}.
40017The number of bytes to watch is specified by @var{kind}.
40018
40019Reply:
40020@table @samp
40021@item OK
40022success
40023@item @w{}
40024not supported
40025@item E @var{NN}
40026for an error
40027@end table
40028
40029@item z3,@var{addr},@var{kind}
40030@itemx Z3,@var{addr},@var{kind}
40031@cindex @samp{z3} packet
40032@cindex @samp{Z3} packet
40033Insert (@samp{Z3}) or remove (@samp{z3}) a read watchpoint at @var{addr}.
40034The number of bytes to watch is specified by @var{kind}.
40035
40036Reply:
40037@table @samp
40038@item OK
40039success
40040@item @w{}
40041not supported
40042@item E @var{NN}
40043for an error
40044@end table
40045
40046@item z4,@var{addr},@var{kind}
40047@itemx Z4,@var{addr},@var{kind}
40048@cindex @samp{z4} packet
40049@cindex @samp{Z4} packet
40050Insert (@samp{Z4}) or remove (@samp{z4}) an access watchpoint at @var{addr}.
40051The number of bytes to watch is specified by @var{kind}.
40052
40053Reply:
40054@table @samp
40055@item OK
40056success
40057@item @w{}
40058not supported
40059@item E @var{NN}
40060for an error
40061@end table
40062
40063@end table
40064
40065@node Stop Reply Packets
40066@section Stop Reply Packets
40067@cindex stop reply packets
40068
40069The @samp{C}, @samp{c}, @samp{S}, @samp{s}, @samp{vCont},
40070@samp{vAttach}, @samp{vRun}, @samp{vStopped}, and @samp{?} packets can
40071receive any of the below as a reply.  Except for @samp{?}
40072and @samp{vStopped}, that reply is only returned
40073when the target halts.  In the below the exact meaning of @dfn{signal
40074number} is defined by the header @file{include/gdb/signals.h} in the
40075@value{GDBN} source code.
40076
40077In non-stop mode, the server will simply reply @samp{OK} to commands
40078such as @samp{vCont}; any stop will be the subject of a future
40079notification.  @xref{Remote Non-Stop}.
40080
40081As in the description of request packets, we include spaces in the
40082reply templates for clarity; these are not part of the reply packet's
40083syntax.  No @value{GDBN} stop reply packet uses spaces to separate its
40084components.
40085
40086@table @samp
40087
40088@item S @var{AA}
40089The program received signal number @var{AA} (a two-digit hexadecimal
40090number).  This is equivalent to a @samp{T} response with no
40091@var{n}:@var{r} pairs.
40092
40093@item T @var{AA} @var{n1}:@var{r1};@var{n2}:@var{r2};@dots{}
40094@cindex @samp{T} packet reply
40095The program received signal number @var{AA} (a two-digit hexadecimal
40096number).  This is equivalent to an @samp{S} response, except that the
40097@samp{@var{n}:@var{r}} pairs can carry values of important registers
40098and other information directly in the stop reply packet, reducing
40099round-trip latency.  Single-step and breakpoint traps are reported
40100this way.  Each @samp{@var{n}:@var{r}} pair is interpreted as follows:
40101
40102@itemize @bullet
40103@item
40104If @var{n} is a hexadecimal number, it is a register number, and the
40105corresponding @var{r} gives that register's value.  The data @var{r} is a
40106series of bytes in target byte order, with each byte given by a
40107two-digit hex number.
40108
40109@item
40110If @var{n} is @samp{thread}, then @var{r} is the @var{thread-id} of
40111the stopped thread, as specified in @ref{thread-id syntax}.
40112
40113@item
40114If @var{n} is @samp{core}, then @var{r} is the hexadecimal number of
40115the core on which the stop event was detected.
40116
40117@item
40118If @var{n} is a recognized @dfn{stop reason}, it describes a more
40119specific event that stopped the target.  The currently defined stop
40120reasons are listed below.  The @var{aa} should be @samp{05}, the trap
40121signal.  At most one stop reason should be present.
40122
40123@item
40124Otherwise, @value{GDBN} should ignore this @samp{@var{n}:@var{r}} pair
40125and go on to the next; this allows us to extend the protocol in the
40126future.
40127@end itemize
40128
40129The currently defined stop reasons are:
40130
40131@table @samp
40132@item watch
40133@itemx rwatch
40134@itemx awatch
40135The packet indicates a watchpoint hit, and @var{r} is the data address, in
40136hex.
40137
40138@item syscall_entry
40139@itemx syscall_return
40140The packet indicates a syscall entry or return, and @var{r} is the
40141syscall number, in hex.
40142
40143@cindex shared library events, remote reply
40144@item library
40145The packet indicates that the loaded libraries have changed.
40146@value{GDBN} should use @samp{qXfer:libraries:read} to fetch a new
40147list of loaded libraries.  The @var{r} part is ignored.
40148
40149@cindex replay log events, remote reply
40150@item replaylog
40151The packet indicates that the target cannot continue replaying
40152logged execution events, because it has reached the end (or the
40153beginning when executing backward) of the log.  The value of @var{r}
40154will be either @samp{begin} or @samp{end}.  @xref{Reverse Execution},
40155for more information.
40156
40157@item swbreak
40158@anchor{swbreak stop reason}
40159The packet indicates a software breakpoint instruction was executed,
40160irrespective of whether it was @value{GDBN} that planted the
40161breakpoint or the breakpoint is hardcoded in the program.  The @var{r}
40162part must be left empty.
40163
40164On some architectures, such as x86, at the architecture level, when a
40165breakpoint instruction executes the program counter points at the
40166breakpoint address plus an offset.  On such targets, the stub is
40167responsible for adjusting the PC to point back at the breakpoint
40168address.
40169
40170This packet should not be sent by default; older @value{GDBN} versions
40171did not support it.  @value{GDBN} requests it, by supplying an
40172appropriate @samp{qSupported} feature (@pxref{qSupported}).  The
40173remote stub must also supply the appropriate @samp{qSupported} feature
40174indicating support.
40175
40176This packet is required for correct non-stop mode operation.
40177
40178@item hwbreak
40179The packet indicates the target stopped for a hardware breakpoint.
40180The @var{r} part must be left empty.
40181
40182The same remarks about @samp{qSupported} and non-stop mode above
40183apply.
40184
40185@cindex fork events, remote reply
40186@item fork
40187The packet indicates that @code{fork} was called, and @var{r}
40188is the thread ID of the new child process.  Refer to
40189@ref{thread-id syntax} for the format of the @var{thread-id}
40190field.  This packet is only applicable to targets that support
40191fork events.
40192
40193This packet should not be sent by default; older @value{GDBN} versions
40194did not support it.  @value{GDBN} requests it, by supplying an
40195appropriate @samp{qSupported} feature (@pxref{qSupported}).  The
40196remote stub must also supply the appropriate @samp{qSupported} feature
40197indicating support.
40198
40199@cindex vfork events, remote reply
40200@item vfork
40201The packet indicates that @code{vfork} was called, and @var{r}
40202is the thread ID of the new child process. Refer to
40203@ref{thread-id syntax} for the format of the @var{thread-id}
40204field.  This packet is only applicable to targets that support
40205vfork events.
40206
40207This packet should not be sent by default; older @value{GDBN} versions
40208did not support it.  @value{GDBN} requests it, by supplying an
40209appropriate @samp{qSupported} feature (@pxref{qSupported}).  The
40210remote stub must also supply the appropriate @samp{qSupported} feature
40211indicating support.
40212
40213@cindex vforkdone events, remote reply
40214@item vforkdone
40215The packet indicates that a child process created by a vfork
40216has either called @code{exec} or terminated, so that the
40217address spaces of the parent and child process are no longer
40218shared. The @var{r} part is ignored.  This packet is only
40219applicable to targets that support vforkdone events.
40220
40221This packet should not be sent by default; older @value{GDBN} versions
40222did not support it.  @value{GDBN} requests it, by supplying an
40223appropriate @samp{qSupported} feature (@pxref{qSupported}).  The
40224remote stub must also supply the appropriate @samp{qSupported} feature
40225indicating support.
40226
40227@cindex exec events, remote reply
40228@item exec
40229The packet indicates that @code{execve} was called, and @var{r}
40230is the absolute pathname of the file that was executed, in hex.
40231This packet is only applicable to targets that support exec events.
40232
40233This packet should not be sent by default; older @value{GDBN} versions
40234did not support it.  @value{GDBN} requests it, by supplying an
40235appropriate @samp{qSupported} feature (@pxref{qSupported}).  The
40236remote stub must also supply the appropriate @samp{qSupported} feature
40237indicating support.
40238
40239@cindex thread create event, remote reply
40240@anchor{thread create event}
40241@item create
40242The packet indicates that the thread was just created.  The new thread
40243is stopped until @value{GDBN} sets it running with a resumption packet
40244(@pxref{vCont packet}).  This packet should not be sent by default;
40245@value{GDBN} requests it with the @ref{QThreadEvents} packet.  See
40246also the @samp{w} (@pxref{thread exit event}) remote reply below.  The
40247@var{r} part is ignored.
40248
40249@end table
40250
40251@item W @var{AA}
40252@itemx W @var{AA} ; process:@var{pid}
40253The process exited, and @var{AA} is the exit status.  This is only
40254applicable to certain targets.
40255
40256The second form of the response, including the process ID of the
40257exited process, can be used only when @value{GDBN} has reported
40258support for multiprocess protocol extensions; see @ref{multiprocess
40259extensions}.  Both @var{AA} and @var{pid} are formatted as big-endian
40260hex strings.
40261
40262@item X @var{AA}
40263@itemx X @var{AA} ; process:@var{pid}
40264The process terminated with signal @var{AA}.
40265
40266The second form of the response, including the process ID of the
40267terminated process, can be used only when @value{GDBN} has reported
40268support for multiprocess protocol extensions; see @ref{multiprocess
40269extensions}.  Both @var{AA} and @var{pid} are formatted as big-endian
40270hex strings.
40271
40272@anchor{thread exit event}
40273@cindex thread exit event, remote reply
40274@item w @var{AA} ; @var{tid}
40275
40276The thread exited, and @var{AA} is the exit status.  This response
40277should not be sent by default; @value{GDBN} requests it with the
40278@ref{QThreadEvents} packet.  See also @ref{thread create event} above.
40279@var{AA} is formatted as a big-endian hex string.
40280
40281@item N
40282There are no resumed threads left in the target.  In other words, even
40283though the process is alive, the last resumed thread has exited.  For
40284example, say the target process has two threads: thread 1 and thread
402852.  The client leaves thread 1 stopped, and resumes thread 2, which
40286subsequently exits.  At this point, even though the process is still
40287alive, and thus no @samp{W} stop reply is sent, no thread is actually
40288executing either.  The @samp{N} stop reply thus informs the client
40289that it can stop waiting for stop replies.  This packet should not be
40290sent by default; older @value{GDBN} versions did not support it.
40291@value{GDBN} requests it, by supplying an appropriate
40292@samp{qSupported} feature (@pxref{qSupported}).  The remote stub must
40293also supply the appropriate @samp{qSupported} feature indicating
40294support.
40295
40296@item O @var{XX}@dots{}
40297@samp{@var{XX}@dots{}} is hex encoding of @sc{ascii} data, to be
40298written as the program's console output.  This can happen at any time
40299while the program is running and the debugger should continue to wait
40300for @samp{W}, @samp{T}, etc.  This reply is not permitted in non-stop mode.
40301
40302@item F @var{call-id},@var{parameter}@dots{}
40303@var{call-id} is the identifier which says which host system call should
40304be called.  This is just the name of the function.  Translation into the
40305correct system call is only applicable as it's defined in @value{GDBN}.
40306@xref{File-I/O Remote Protocol Extension}, for a list of implemented
40307system calls.
40308
40309@samp{@var{parameter}@dots{}} is a list of parameters as defined for
40310this very system call.
40311
40312The target replies with this packet when it expects @value{GDBN} to
40313call a host system call on behalf of the target.  @value{GDBN} replies
40314with an appropriate @samp{F} packet and keeps up waiting for the next
40315reply packet from the target.  The latest @samp{C}, @samp{c}, @samp{S}
40316or @samp{s} action is expected to be continued.  @xref{File-I/O Remote
40317Protocol Extension}, for more details.
40318
40319@end table
40320
40321@node General Query Packets
40322@section General Query Packets
40323@cindex remote query requests
40324
40325Packets starting with @samp{q} are @dfn{general query packets};
40326packets starting with @samp{Q} are @dfn{general set packets}.  General
40327query and set packets are a semi-unified form for retrieving and
40328sending information to and from the stub.
40329
40330The initial letter of a query or set packet is followed by a name
40331indicating what sort of thing the packet applies to.  For example,
40332@value{GDBN} may use a @samp{qSymbol} packet to exchange symbol
40333definitions with the stub.  These packet names follow some
40334conventions:
40335
40336@itemize @bullet
40337@item
40338The name must not contain commas, colons or semicolons.
40339@item
40340Most @value{GDBN} query and set packets have a leading upper case
40341letter.
40342@item
40343The names of custom vendor packets should use a company prefix, in
40344lower case, followed by a period.  For example, packets designed at
40345the Acme Corporation might begin with @samp{qacme.foo} (for querying
40346foos) or @samp{Qacme.bar} (for setting bars).
40347@end itemize
40348
40349The name of a query or set packet should be separated from any
40350parameters by a @samp{:}; the parameters themselves should be
40351separated by @samp{,} or @samp{;}.  Stubs must be careful to match the
40352full packet name, and check for a separator or the end of the packet,
40353in case two packet names share a common prefix.  New packets should not begin
40354with @samp{qC}, @samp{qP}, or @samp{qL}@footnote{The @samp{qP} and @samp{qL}
40355packets predate these conventions, and have arguments without any terminator
40356for the packet name; we suspect they are in widespread use in places that
40357are difficult to upgrade.  The @samp{qC} packet has no arguments, but some
40358existing stubs (e.g.@: RedBoot) are known to not check for the end of the
40359packet.}.
40360
40361Like the descriptions of the other packets, each description here
40362has a template showing the packet's overall syntax, followed by an
40363explanation of the packet's meaning.  We include spaces in some of the
40364templates for clarity; these are not part of the packet's syntax.  No
40365@value{GDBN} packet uses spaces to separate its components.
40366
40367Here are the currently defined query and set packets:
40368
40369@table @samp
40370
40371@item QAgent:1
40372@itemx QAgent:0
40373Turn on or off the agent as a helper to perform some debugging operations
40374delegated from @value{GDBN} (@pxref{Control Agent}).
40375
40376@item QAllow:@var{op}:@var{val}@dots{}
40377@cindex @samp{QAllow} packet
40378Specify which operations @value{GDBN} expects to request of the
40379target, as a semicolon-separated list of operation name and value
40380pairs.  Possible values for @var{op} include @samp{WriteReg},
40381@samp{WriteMem}, @samp{InsertBreak}, @samp{InsertTrace},
40382@samp{InsertFastTrace}, and @samp{Stop}. @var{val} is either 0,
40383indicating that @value{GDBN} will not request the operation, or 1,
40384indicating that it may.  (The target can then use this to set up its
40385own internals optimally, for instance if the debugger never expects to
40386insert breakpoints, it may not need to install its own trap handler.)
40387
40388@item qC
40389@cindex current thread, remote request
40390@cindex @samp{qC} packet
40391Return the current thread ID.
40392
40393Reply:
40394@table @samp
40395@item QC @var{thread-id}
40396Where @var{thread-id} is a thread ID as documented in
40397@ref{thread-id syntax}.
40398@item @r{(anything else)}
40399Any other reply implies the old thread ID.
40400@end table
40401
40402@item qCRC:@var{addr},@var{length}
40403@cindex CRC of memory block, remote request
40404@cindex @samp{qCRC} packet
40405@anchor{qCRC packet}
40406Compute the CRC checksum of a block of memory using CRC-32 defined in
40407IEEE 802.3.  The CRC is computed byte at a time, taking the most
40408significant bit of each byte first.  The initial pattern code
40409@code{0xffffffff} is used to ensure leading zeros affect the CRC.
40410
40411@emph{Note:} This is the same CRC used in validating separate debug
40412files (@pxref{Separate Debug Files, , Debugging Information in Separate
40413Files}).  However the algorithm is slightly different.  When validating
40414separate debug files, the CRC is computed taking the @emph{least}
40415significant bit of each byte first, and the final result is inverted to
40416detect trailing zeros.
40417
40418Reply:
40419@table @samp
40420@item E @var{NN}
40421An error (such as memory fault)
40422@item C @var{crc32}
40423The specified memory region's checksum is @var{crc32}.
40424@end table
40425
40426@item QDisableRandomization:@var{value}
40427@cindex disable address space randomization, remote request
40428@cindex @samp{QDisableRandomization} packet
40429Some target operating systems will randomize the virtual address space
40430of the inferior process as a security feature, but provide a feature
40431to disable such randomization, e.g.@: to allow for a more deterministic
40432debugging experience.  On such systems, this packet with a @var{value}
40433of 1 directs the target to disable address space randomization for
40434processes subsequently started via @samp{vRun} packets, while a packet
40435with a @var{value} of 0 tells the target to enable address space
40436randomization.
40437
40438This packet is only available in extended mode (@pxref{extended mode}).
40439
40440Reply:
40441@table @samp
40442@item OK
40443The request succeeded.
40444
40445@item E @var{nn}
40446An error occurred.  The error number @var{nn} is given as hex digits.
40447
40448@item @w{}
40449An empty reply indicates that @samp{QDisableRandomization} is not supported
40450by the stub.
40451@end table
40452
40453This packet is not probed by default; the remote stub must request it,
40454by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40455This should only be done on targets that actually support disabling
40456address space randomization.
40457
40458@item QStartupWithShell:@var{value}
40459@cindex startup with shell, remote request
40460@cindex @samp{QStartupWithShell} packet
40461On UNIX-like targets, it is possible to start the inferior using a
40462shell program.  This is the default behavior on both @value{GDBN} and
40463@command{gdbserver} (@pxref{set startup-with-shell}).  This packet is
40464used to inform @command{gdbserver} whether it should start the
40465inferior using a shell or not.
40466
40467If @var{value} is @samp{0}, @command{gdbserver} will not use a shell
40468to start the inferior.  If @var{value} is @samp{1},
40469@command{gdbserver} will use a shell to start the inferior.  All other
40470values are considered an error.
40471
40472This packet is only available in extended mode (@pxref{extended
40473mode}).
40474
40475Reply:
40476@table @samp
40477@item OK
40478The request succeeded.
40479
40480@item E @var{nn}
40481An error occurred.  The error number @var{nn} is given as hex digits.
40482@end table
40483
40484This packet is not probed by default; the remote stub must request it,
40485by supplying an appropriate @samp{qSupported} response
40486(@pxref{qSupported}).  This should only be done on targets that
40487actually support starting the inferior using a shell.
40488
40489Use of this packet is controlled by the @code{set startup-with-shell}
40490command; @pxref{set startup-with-shell}.
40491
40492@item QEnvironmentHexEncoded:@var{hex-value}
40493@anchor{QEnvironmentHexEncoded}
40494@cindex set environment variable, remote request
40495@cindex @samp{QEnvironmentHexEncoded} packet
40496On UNIX-like targets, it is possible to set environment variables that
40497will be passed to the inferior during the startup process.  This
40498packet is used to inform @command{gdbserver} of an environment
40499variable that has been defined by the user on @value{GDBN} (@pxref{set
40500environment}).
40501
40502The packet is composed by @var{hex-value}, an hex encoded
40503representation of the @var{name=value} format representing an
40504environment variable.  The name of the environment variable is
40505represented by @var{name}, and the value to be assigned to the
40506environment variable is represented by @var{value}.  If the variable
40507has no value (i.e., the value is @code{null}), then @var{value} will
40508not be present.
40509
40510This packet is only available in extended mode (@pxref{extended
40511mode}).
40512
40513Reply:
40514@table @samp
40515@item OK
40516The request succeeded.
40517@end table
40518
40519This packet is not probed by default; the remote stub must request it,
40520by supplying an appropriate @samp{qSupported} response
40521(@pxref{qSupported}).  This should only be done on targets that
40522actually support passing environment variables to the starting
40523inferior.
40524
40525This packet is related to the @code{set environment} command;
40526@pxref{set environment}.
40527
40528@item QEnvironmentUnset:@var{hex-value}
40529@anchor{QEnvironmentUnset}
40530@cindex unset environment variable, remote request
40531@cindex @samp{QEnvironmentUnset} packet
40532On UNIX-like targets, it is possible to unset environment variables
40533before starting the inferior in the remote target.  This packet is
40534used to inform @command{gdbserver} of an environment variable that has
40535been unset by the user on @value{GDBN} (@pxref{unset environment}).
40536
40537The packet is composed by @var{hex-value}, an hex encoded
40538representation of the name of the environment variable to be unset.
40539
40540This packet is only available in extended mode (@pxref{extended
40541mode}).
40542
40543Reply:
40544@table @samp
40545@item OK
40546The request succeeded.
40547@end table
40548
40549This packet is not probed by default; the remote stub must request it,
40550by supplying an appropriate @samp{qSupported} response
40551(@pxref{qSupported}).  This should only be done on targets that
40552actually support passing environment variables to the starting
40553inferior.
40554
40555This packet is related to the @code{unset environment} command;
40556@pxref{unset environment}.
40557
40558@item QEnvironmentReset
40559@anchor{QEnvironmentReset}
40560@cindex reset environment, remote request
40561@cindex @samp{QEnvironmentReset} packet
40562On UNIX-like targets, this packet is used to reset the state of
40563environment variables in the remote target before starting the
40564inferior.  In this context, reset means unsetting all environment
40565variables that were previously set by the user (i.e., were not
40566initially present in the environment).  It is sent to
40567@command{gdbserver} before the @samp{QEnvironmentHexEncoded}
40568(@pxref{QEnvironmentHexEncoded}) and the @samp{QEnvironmentUnset}
40569(@pxref{QEnvironmentUnset}) packets.
40570
40571This packet is only available in extended mode (@pxref{extended
40572mode}).
40573
40574Reply:
40575@table @samp
40576@item OK
40577The request succeeded.
40578@end table
40579
40580This packet is not probed by default; the remote stub must request it,
40581by supplying an appropriate @samp{qSupported} response
40582(@pxref{qSupported}).  This should only be done on targets that
40583actually support passing environment variables to the starting
40584inferior.
40585
40586@item QSetWorkingDir:@r{[}@var{directory}@r{]}
40587@anchor{QSetWorkingDir packet}
40588@cindex set working directory, remote request
40589@cindex @samp{QSetWorkingDir} packet
40590This packet is used to inform the remote server of the intended
40591current working directory for programs that are going to be executed.
40592
40593The packet is composed by @var{directory}, an hex encoded
40594representation of the directory that the remote inferior will use as
40595its current working directory.  If @var{directory} is an empty string,
40596the remote server should reset the inferior's current working
40597directory to its original, empty value.
40598
40599This packet is only available in extended mode (@pxref{extended
40600mode}).
40601
40602Reply:
40603@table @samp
40604@item OK
40605The request succeeded.
40606@end table
40607
40608@item qfThreadInfo
40609@itemx qsThreadInfo
40610@cindex list active threads, remote request
40611@cindex @samp{qfThreadInfo} packet
40612@cindex @samp{qsThreadInfo} packet
40613Obtain a list of all active thread IDs from the target (OS).  Since there
40614may be too many active threads to fit into one reply packet, this query
40615works iteratively: it may require more than one query/reply sequence to
40616obtain the entire list of threads.  The first query of the sequence will
40617be the @samp{qfThreadInfo} query; subsequent queries in the
40618sequence will be the @samp{qsThreadInfo} query.
40619
40620NOTE: This packet replaces the @samp{qL} query (see below).
40621
40622Reply:
40623@table @samp
40624@item m @var{thread-id}
40625A single thread ID
40626@item m @var{thread-id},@var{thread-id}@dots{}
40627a comma-separated list of thread IDs
40628@item l
40629(lower case letter @samp{L}) denotes end of list.
40630@end table
40631
40632In response to each query, the target will reply with a list of one or
40633more thread IDs, separated by commas.
40634@value{GDBN} will respond to each reply with a request for more thread
40635ids (using the @samp{qs} form of the query), until the target responds
40636with @samp{l} (lower-case ell, for @dfn{last}).
40637Refer to @ref{thread-id syntax}, for the format of the @var{thread-id}
40638fields.
40639
40640@emph{Note: @value{GDBN} will send the @code{qfThreadInfo} query during the
40641initial connection with the remote target, and the very first thread ID
40642mentioned in the reply will be stopped by @value{GDBN} in a subsequent
40643message.  Therefore, the stub should ensure that the first thread ID in
40644the @code{qfThreadInfo} reply is suitable for being stopped by @value{GDBN}.}
40645
40646@item qGetTLSAddr:@var{thread-id},@var{offset},@var{lm}
40647@cindex get thread-local storage address, remote request
40648@cindex @samp{qGetTLSAddr} packet
40649Fetch the address associated with thread local storage specified
40650by @var{thread-id}, @var{offset}, and @var{lm}.
40651
40652@var{thread-id} is the thread ID associated with the
40653thread for which to fetch the TLS address.  @xref{thread-id syntax}.
40654
40655@var{offset} is the (big endian, hex encoded) offset associated with the
40656thread local variable.  (This offset is obtained from the debug
40657information associated with the variable.)
40658
40659@var{lm} is the (big endian, hex encoded) OS/ABI-specific encoding of the
40660load module associated with the thread local storage.  For example,
40661a @sc{gnu}/Linux system will pass the link map address of the shared
40662object associated with the thread local storage under consideration.
40663Other operating environments may choose to represent the load module
40664differently, so the precise meaning of this parameter will vary.
40665
40666Reply:
40667@table @samp
40668@item @var{XX}@dots{}
40669Hex encoded (big endian) bytes representing the address of the thread
40670local storage requested.
40671
40672@item E @var{nn}
40673An error occurred.  The error number @var{nn} is given as hex digits.
40674
40675@item @w{}
40676An empty reply indicates that @samp{qGetTLSAddr} is not supported by the stub.
40677@end table
40678
40679@item qGetTIBAddr:@var{thread-id}
40680@cindex get thread information block address
40681@cindex @samp{qGetTIBAddr} packet
40682Fetch address of the Windows OS specific Thread Information Block.
40683
40684@var{thread-id} is the thread ID associated with the thread.
40685
40686Reply:
40687@table @samp
40688@item @var{XX}@dots{}
40689Hex encoded (big endian) bytes representing the linear address of the
40690thread information block.
40691
40692@item E @var{nn}
40693An error occured.  This means that either the thread was not found, or the
40694address could not be retrieved.
40695
40696@item @w{}
40697An empty reply indicates that @samp{qGetTIBAddr} is not supported by the stub.
40698@end table
40699
40700@item qL @var{startflag} @var{threadcount} @var{nextthread}
40701Obtain thread information from RTOS.  Where: @var{startflag} (one hex
40702digit) is one to indicate the first query and zero to indicate a
40703subsequent query; @var{threadcount} (two hex digits) is the maximum
40704number of threads the response packet can contain; and @var{nextthread}
40705(eight hex digits), for subsequent queries (@var{startflag} is zero), is
40706returned in the response as @var{argthread}.
40707
40708Don't use this packet; use the @samp{qfThreadInfo} query instead (see above).
40709
40710Reply:
40711@table @samp
40712@item qM @var{count} @var{done} @var{argthread} @var{thread}@dots{}
40713Where: @var{count} (two hex digits) is the number of threads being
40714returned; @var{done} (one hex digit) is zero to indicate more threads
40715and one indicates no further threads; @var{argthreadid} (eight hex
40716digits) is @var{nextthread} from the request packet; @var{thread}@dots{}
40717is a sequence of thread IDs, @var{threadid} (eight hex
40718digits), from the target.  See @code{remote.c:parse_threadlist_response()}.
40719@end table
40720
40721@item qOffsets
40722@cindex section offsets, remote request
40723@cindex @samp{qOffsets} packet
40724Get section offsets that the target used when relocating the downloaded
40725image.
40726
40727Reply:
40728@table @samp
40729@item Text=@var{xxx};Data=@var{yyy}@r{[};Bss=@var{zzz}@r{]}
40730Relocate the @code{Text} section by @var{xxx} from its original address.
40731Relocate the @code{Data} section by @var{yyy} from its original address.
40732If the object file format provides segment information (e.g.@: @sc{elf}
40733@samp{PT_LOAD} program headers), @value{GDBN} will relocate entire
40734segments by the supplied offsets.
40735
40736@emph{Note: while a @code{Bss} offset may be included in the response,
40737@value{GDBN} ignores this and instead applies the @code{Data} offset
40738to the @code{Bss} section.}
40739
40740@item TextSeg=@var{xxx}@r{[};DataSeg=@var{yyy}@r{]}
40741Relocate the first segment of the object file, which conventionally
40742contains program code, to a starting address of @var{xxx}.  If
40743@samp{DataSeg} is specified, relocate the second segment, which
40744conventionally contains modifiable data, to a starting address of
40745@var{yyy}.  @value{GDBN} will report an error if the object file
40746does not contain segment information, or does not contain at least
40747as many segments as mentioned in the reply.  Extra segments are
40748kept at fixed offsets relative to the last relocated segment.
40749@end table
40750
40751@item qP @var{mode} @var{thread-id}
40752@cindex thread information, remote request
40753@cindex @samp{qP} packet
40754Returns information on @var{thread-id}.  Where: @var{mode} is a hex
40755encoded 32 bit mode; @var{thread-id} is a thread ID
40756(@pxref{thread-id syntax}).
40757
40758Don't use this packet; use the @samp{qThreadExtraInfo} query instead
40759(see below).
40760
40761Reply: see @code{remote.c:remote_unpack_thread_info_response()}.
40762
40763@item QNonStop:1
40764@itemx QNonStop:0
40765@cindex non-stop mode, remote request
40766@cindex @samp{QNonStop} packet
40767@anchor{QNonStop}
40768Enter non-stop (@samp{QNonStop:1}) or all-stop (@samp{QNonStop:0}) mode.
40769@xref{Remote Non-Stop}, for more information.
40770
40771Reply:
40772@table @samp
40773@item OK
40774The request succeeded.
40775
40776@item E @var{nn}
40777An error occurred.  The error number @var{nn} is given as hex digits.
40778
40779@item @w{}
40780An empty reply indicates that @samp{QNonStop} is not supported by
40781the stub.
40782@end table
40783
40784This packet is not probed by default; the remote stub must request it,
40785by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40786Use of this packet is controlled by the @code{set non-stop} command;
40787@pxref{Non-Stop Mode}.
40788
40789@item QCatchSyscalls:1 @r{[};@var{sysno}@r{]}@dots{}
40790@itemx QCatchSyscalls:0
40791@cindex catch syscalls from inferior, remote request
40792@cindex @samp{QCatchSyscalls} packet
40793@anchor{QCatchSyscalls}
40794Enable (@samp{QCatchSyscalls:1}) or disable (@samp{QCatchSyscalls:0})
40795catching syscalls from the inferior process.
40796
40797For @samp{QCatchSyscalls:1}, each listed syscall @var{sysno} (encoded
40798in hex) should be reported to @value{GDBN}.  If no syscall @var{sysno}
40799is listed, every system call should be reported.
40800
40801Note that if a syscall not in the list is reported, @value{GDBN} will
40802still filter the event according to its own list from all corresponding
40803@code{catch syscall} commands.  However, it is more efficient to only
40804report the requested syscalls.
40805
40806Multiple @samp{QCatchSyscalls:1} packets do not combine; any earlier
40807@samp{QCatchSyscalls:1} list is completely replaced by the new list.
40808
40809If the inferior process execs, the state of @samp{QCatchSyscalls} is
40810kept for the new process too.  On targets where exec may affect syscall
40811numbers, for example with exec between 32 and 64-bit processes, the
40812client should send a new packet with the new syscall list.
40813
40814Reply:
40815@table @samp
40816@item OK
40817The request succeeded.
40818
40819@item E @var{nn}
40820An error occurred.  @var{nn} are hex digits.
40821
40822@item @w{}
40823An empty reply indicates that @samp{QCatchSyscalls} is not supported by
40824the stub.
40825@end table
40826
40827Use of this packet is controlled by the @code{set remote catch-syscalls}
40828command (@pxref{Remote Configuration, set remote catch-syscalls}).
40829This packet is not probed by default; the remote stub must request it,
40830by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40831
40832@item QPassSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
40833@cindex pass signals to inferior, remote request
40834@cindex @samp{QPassSignals} packet
40835@anchor{QPassSignals}
40836Each listed @var{signal} should be passed directly to the inferior process.
40837Signals are numbered identically to continue packets and stop replies
40838(@pxref{Stop Reply Packets}).  Each @var{signal} list item should be
40839strictly greater than the previous item.  These signals do not need to stop
40840the inferior, or be reported to @value{GDBN}.  All other signals should be
40841reported to @value{GDBN}.  Multiple @samp{QPassSignals} packets do not
40842combine; any earlier @samp{QPassSignals} list is completely replaced by the
40843new list.  This packet improves performance when using @samp{handle
40844@var{signal} nostop noprint pass}.
40845
40846Reply:
40847@table @samp
40848@item OK
40849The request succeeded.
40850
40851@item E @var{nn}
40852An error occurred.  The error number @var{nn} is given as hex digits.
40853
40854@item @w{}
40855An empty reply indicates that @samp{QPassSignals} is not supported by
40856the stub.
40857@end table
40858
40859Use of this packet is controlled by the @code{set remote pass-signals}
40860command (@pxref{Remote Configuration, set remote pass-signals}).
40861This packet is not probed by default; the remote stub must request it,
40862by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40863
40864@item QProgramSignals: @var{signal} @r{[};@var{signal}@r{]}@dots{}
40865@cindex signals the inferior may see, remote request
40866@cindex @samp{QProgramSignals} packet
40867@anchor{QProgramSignals}
40868Each listed @var{signal} may be delivered to the inferior process.
40869Others should be silently discarded.
40870
40871In some cases, the remote stub may need to decide whether to deliver a
40872signal to the program or not without @value{GDBN} involvement.  One
40873example of that is while detaching --- the program's threads may have
40874stopped for signals that haven't yet had a chance of being reported to
40875@value{GDBN}, and so the remote stub can use the signal list specified
40876by this packet to know whether to deliver or ignore those pending
40877signals.
40878
40879This does not influence whether to deliver a signal as requested by a
40880resumption packet (@pxref{vCont packet}).
40881
40882Signals are numbered identically to continue packets and stop replies
40883(@pxref{Stop Reply Packets}).  Each @var{signal} list item should be
40884strictly greater than the previous item.  Multiple
40885@samp{QProgramSignals} packets do not combine; any earlier
40886@samp{QProgramSignals} list is completely replaced by the new list.
40887
40888Reply:
40889@table @samp
40890@item OK
40891The request succeeded.
40892
40893@item E @var{nn}
40894An error occurred.  The error number @var{nn} is given as hex digits.
40895
40896@item @w{}
40897An empty reply indicates that @samp{QProgramSignals} is not supported
40898by the stub.
40899@end table
40900
40901Use of this packet is controlled by the @code{set remote program-signals}
40902command (@pxref{Remote Configuration, set remote program-signals}).
40903This packet is not probed by default; the remote stub must request it,
40904by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
40905
40906@anchor{QThreadEvents}
40907@item QThreadEvents:1
40908@itemx QThreadEvents:0
40909@cindex thread create/exit events, remote request
40910@cindex @samp{QThreadEvents} packet
40911
40912Enable (@samp{QThreadEvents:1}) or disable (@samp{QThreadEvents:0})
40913reporting of thread create and exit events.  @xref{thread create
40914event}, for the reply specifications.  For example, this is used in
40915non-stop mode when @value{GDBN} stops a set of threads and
40916synchronously waits for the their corresponding stop replies.  Without
40917exit events, if one of the threads exits, @value{GDBN} would hang
40918forever not knowing that it should no longer expect a stop for that
40919same thread.  @value{GDBN} does not enable this feature unless the
40920stub reports that it supports it by including @samp{QThreadEvents+} in
40921its @samp{qSupported} reply.
40922
40923Reply:
40924@table @samp
40925@item OK
40926The request succeeded.
40927
40928@item E @var{nn}
40929An error occurred.  The error number @var{nn} is given as hex digits.
40930
40931@item @w{}
40932An empty reply indicates that @samp{QThreadEvents} is not supported by
40933the stub.
40934@end table
40935
40936Use of this packet is controlled by the @code{set remote thread-events}
40937command (@pxref{Remote Configuration, set remote thread-events}).
40938
40939@item qRcmd,@var{command}
40940@cindex execute remote command, remote request
40941@cindex @samp{qRcmd} packet
40942@var{command} (hex encoded) is passed to the local interpreter for
40943execution.  Invalid commands should be reported using the output
40944string.  Before the final result packet, the target may also respond
40945with a number of intermediate @samp{O@var{output}} console output
40946packets.  @emph{Implementors should note that providing access to a
40947stubs's interpreter may have security implications}.
40948
40949Reply:
40950@table @samp
40951@item OK
40952A command response with no output.
40953@item @var{OUTPUT}
40954A command response with the hex encoded output string @var{OUTPUT}.
40955@item E @var{NN}
40956Indicate a badly formed request.
40957@item @w{}
40958An empty reply indicates that @samp{qRcmd} is not recognized.
40959@end table
40960
40961(Note that the @code{qRcmd} packet's name is separated from the
40962command by a @samp{,}, not a @samp{:}, contrary to the naming
40963conventions above.  Please don't use this packet as a model for new
40964packets.)
40965
40966@item qSearch:memory:@var{address};@var{length};@var{search-pattern}
40967@cindex searching memory, in remote debugging
40968@ifnotinfo
40969@cindex @samp{qSearch:memory} packet
40970@end ifnotinfo
40971@cindex @samp{qSearch memory} packet
40972@anchor{qSearch memory}
40973Search @var{length} bytes at @var{address} for @var{search-pattern}.
40974Both @var{address} and @var{length} are encoded in hex;
40975@var{search-pattern} is a sequence of bytes, also hex encoded.
40976
40977Reply:
40978@table @samp
40979@item 0
40980The pattern was not found.
40981@item 1,address
40982The pattern was found at @var{address}.
40983@item E @var{NN}
40984A badly formed request or an error was encountered while searching memory.
40985@item @w{}
40986An empty reply indicates that @samp{qSearch:memory} is not recognized.
40987@end table
40988
40989@item QStartNoAckMode
40990@cindex @samp{QStartNoAckMode} packet
40991@anchor{QStartNoAckMode}
40992Request that the remote stub disable the normal @samp{+}/@samp{-}
40993protocol acknowledgments (@pxref{Packet Acknowledgment}).
40994
40995Reply:
40996@table @samp
40997@item OK
40998The stub has switched to no-acknowledgment mode.
40999@value{GDBN} acknowledges this response,
41000but neither the stub nor @value{GDBN} shall send or expect further
41001@samp{+}/@samp{-} acknowledgments in the current connection.
41002@item @w{}
41003An empty reply indicates that the stub does not support no-acknowledgment mode.
41004@end table
41005
41006@item qSupported @r{[}:@var{gdbfeature} @r{[};@var{gdbfeature}@r{]}@dots{} @r{]}
41007@cindex supported packets, remote query
41008@cindex features of the remote protocol
41009@cindex @samp{qSupported} packet
41010@anchor{qSupported}
41011Tell the remote stub about features supported by @value{GDBN}, and
41012query the stub for features it supports.  This packet allows
41013@value{GDBN} and the remote stub to take advantage of each others'
41014features.  @samp{qSupported} also consolidates multiple feature probes
41015at startup, to improve @value{GDBN} performance---a single larger
41016packet performs better than multiple smaller probe packets on
41017high-latency links.  Some features may enable behavior which must not
41018be on by default, e.g.@: because it would confuse older clients or
41019stubs.  Other features may describe packets which could be
41020automatically probed for, but are not.  These features must be
41021reported before @value{GDBN} will use them.  This ``default
41022unsupported'' behavior is not appropriate for all packets, but it
41023helps to keep the initial connection time under control with new
41024versions of @value{GDBN} which support increasing numbers of packets.
41025
41026Reply:
41027@table @samp
41028@item @var{stubfeature} @r{[};@var{stubfeature}@r{]}@dots{}
41029The stub supports or does not support each returned @var{stubfeature},
41030depending on the form of each @var{stubfeature} (see below for the
41031possible forms).
41032@item @w{}
41033An empty reply indicates that @samp{qSupported} is not recognized,
41034or that no features needed to be reported to @value{GDBN}.
41035@end table
41036
41037The allowed forms for each feature (either a @var{gdbfeature} in the
41038@samp{qSupported} packet, or a @var{stubfeature} in the response)
41039are:
41040
41041@table @samp
41042@item @var{name}=@var{value}
41043The remote protocol feature @var{name} is supported, and associated
41044with the specified @var{value}.  The format of @var{value} depends
41045on the feature, but it must not include a semicolon.
41046@item @var{name}+
41047The remote protocol feature @var{name} is supported, and does not
41048need an associated value.
41049@item @var{name}-
41050The remote protocol feature @var{name} is not supported.
41051@item @var{name}?
41052The remote protocol feature @var{name} may be supported, and
41053@value{GDBN} should auto-detect support in some other way when it is
41054needed.  This form will not be used for @var{gdbfeature} notifications,
41055but may be used for @var{stubfeature} responses.
41056@end table
41057
41058Whenever the stub receives a @samp{qSupported} request, the
41059supplied set of @value{GDBN} features should override any previous
41060request.  This allows @value{GDBN} to put the stub in a known
41061state, even if the stub had previously been communicating with
41062a different version of @value{GDBN}.
41063
41064The following values of @var{gdbfeature} (for the packet sent by @value{GDBN})
41065are defined:
41066
41067@table @samp
41068@item multiprocess
41069This feature indicates whether @value{GDBN} supports multiprocess
41070extensions to the remote protocol.  @value{GDBN} does not use such
41071extensions unless the stub also reports that it supports them by
41072including @samp{multiprocess+} in its @samp{qSupported} reply.
41073@xref{multiprocess extensions}, for details.
41074
41075@item xmlRegisters
41076This feature indicates that @value{GDBN} supports the XML target
41077description.  If the stub sees @samp{xmlRegisters=} with target
41078specific strings separated by a comma, it will report register
41079description.
41080
41081@item qRelocInsn
41082This feature indicates whether @value{GDBN} supports the
41083@samp{qRelocInsn} packet (@pxref{Tracepoint Packets,,Relocate
41084instruction reply packet}).
41085
41086@item swbreak
41087This feature indicates whether @value{GDBN} supports the swbreak stop
41088reason in stop replies.  @xref{swbreak stop reason}, for details.
41089
41090@item hwbreak
41091This feature indicates whether @value{GDBN} supports the hwbreak stop
41092reason in stop replies.  @xref{swbreak stop reason}, for details.
41093
41094@item fork-events
41095This feature indicates whether @value{GDBN} supports fork event
41096extensions to the remote protocol.  @value{GDBN} does not use such
41097extensions unless the stub also reports that it supports them by
41098including @samp{fork-events+} in its @samp{qSupported} reply.
41099
41100@item vfork-events
41101This feature indicates whether @value{GDBN} supports vfork event
41102extensions to the remote protocol.  @value{GDBN} does not use such
41103extensions unless the stub also reports that it supports them by
41104including @samp{vfork-events+} in its @samp{qSupported} reply.
41105
41106@item exec-events
41107This feature indicates whether @value{GDBN} supports exec event
41108extensions to the remote protocol.  @value{GDBN} does not use such
41109extensions unless the stub also reports that it supports them by
41110including @samp{exec-events+} in its @samp{qSupported} reply.
41111
41112@item vContSupported
41113This feature indicates whether @value{GDBN} wants to know the
41114supported actions in the reply to @samp{vCont?} packet.
41115@end table
41116
41117Stubs should ignore any unknown values for
41118@var{gdbfeature}.  Any @value{GDBN} which sends a @samp{qSupported}
41119packet supports receiving packets of unlimited length (earlier
41120versions of @value{GDBN} may reject overly long responses).  Additional values
41121for @var{gdbfeature} may be defined in the future to let the stub take
41122advantage of new features in @value{GDBN}, e.g.@: incompatible
41123improvements in the remote protocol---the @samp{multiprocess} feature is
41124an example of such a feature.  The stub's reply should be independent
41125of the @var{gdbfeature} entries sent by @value{GDBN}; first @value{GDBN}
41126describes all the features it supports, and then the stub replies with
41127all the features it supports.
41128
41129Similarly, @value{GDBN} will silently ignore unrecognized stub feature
41130responses, as long as each response uses one of the standard forms.
41131
41132Some features are flags.  A stub which supports a flag feature
41133should respond with a @samp{+} form response.  Other features
41134require values, and the stub should respond with an @samp{=}
41135form response.
41136
41137Each feature has a default value, which @value{GDBN} will use if
41138@samp{qSupported} is not available or if the feature is not mentioned
41139in the @samp{qSupported} response.  The default values are fixed; a
41140stub is free to omit any feature responses that match the defaults.
41141
41142Not all features can be probed, but for those which can, the probing
41143mechanism is useful: in some cases, a stub's internal
41144architecture may not allow the protocol layer to know some information
41145about the underlying target in advance.  This is especially common in
41146stubs which may be configured for multiple targets.
41147
41148These are the currently defined stub features and their properties:
41149
41150@multitable @columnfractions 0.35 0.2 0.12 0.2
41151@c NOTE: The first row should be @headitem, but we do not yet require
41152@c a new enough version of Texinfo (4.7) to use @headitem.
41153@item Feature Name
41154@tab Value Required
41155@tab Default
41156@tab Probe Allowed
41157
41158@item @samp{PacketSize}
41159@tab Yes
41160@tab @samp{-}
41161@tab No
41162
41163@item @samp{qXfer:auxv:read}
41164@tab No
41165@tab @samp{-}
41166@tab Yes
41167
41168@item @samp{qXfer:btrace:read}
41169@tab No
41170@tab @samp{-}
41171@tab Yes
41172
41173@item @samp{qXfer:btrace-conf:read}
41174@tab No
41175@tab @samp{-}
41176@tab Yes
41177
41178@item @samp{qXfer:exec-file:read}
41179@tab No
41180@tab @samp{-}
41181@tab Yes
41182
41183@item @samp{qXfer:features:read}
41184@tab No
41185@tab @samp{-}
41186@tab Yes
41187
41188@item @samp{qXfer:libraries:read}
41189@tab No
41190@tab @samp{-}
41191@tab Yes
41192
41193@item @samp{qXfer:libraries-svr4:read}
41194@tab No
41195@tab @samp{-}
41196@tab Yes
41197
41198@item @samp{augmented-libraries-svr4-read}
41199@tab No
41200@tab @samp{-}
41201@tab No
41202
41203@item @samp{qXfer:memory-map:read}
41204@tab No
41205@tab @samp{-}
41206@tab Yes
41207
41208@item @samp{qXfer:sdata:read}
41209@tab No
41210@tab @samp{-}
41211@tab Yes
41212
41213@item @samp{qXfer:siginfo:read}
41214@tab No
41215@tab @samp{-}
41216@tab Yes
41217
41218@item @samp{qXfer:siginfo:write}
41219@tab No
41220@tab @samp{-}
41221@tab Yes
41222
41223@item @samp{qXfer:threads:read}
41224@tab No
41225@tab @samp{-}
41226@tab Yes
41227
41228@item @samp{qXfer:traceframe-info:read}
41229@tab No
41230@tab @samp{-}
41231@tab Yes
41232
41233@item @samp{qXfer:uib:read}
41234@tab No
41235@tab @samp{-}
41236@tab Yes
41237
41238@item @samp{qXfer:fdpic:read}
41239@tab No
41240@tab @samp{-}
41241@tab Yes
41242
41243@item @samp{Qbtrace:off}
41244@tab Yes
41245@tab @samp{-}
41246@tab Yes
41247
41248@item @samp{Qbtrace:bts}
41249@tab Yes
41250@tab @samp{-}
41251@tab Yes
41252
41253@item @samp{Qbtrace:pt}
41254@tab Yes
41255@tab @samp{-}
41256@tab Yes
41257
41258@item @samp{Qbtrace-conf:bts:size}
41259@tab Yes
41260@tab @samp{-}
41261@tab Yes
41262
41263@item @samp{Qbtrace-conf:pt:size}
41264@tab Yes
41265@tab @samp{-}
41266@tab Yes
41267
41268@item @samp{QNonStop}
41269@tab No
41270@tab @samp{-}
41271@tab Yes
41272
41273@item @samp{QCatchSyscalls}
41274@tab No
41275@tab @samp{-}
41276@tab Yes
41277
41278@item @samp{QPassSignals}
41279@tab No
41280@tab @samp{-}
41281@tab Yes
41282
41283@item @samp{QStartNoAckMode}
41284@tab No
41285@tab @samp{-}
41286@tab Yes
41287
41288@item @samp{multiprocess}
41289@tab No
41290@tab @samp{-}
41291@tab No
41292
41293@item @samp{ConditionalBreakpoints}
41294@tab No
41295@tab @samp{-}
41296@tab No
41297
41298@item @samp{ConditionalTracepoints}
41299@tab No
41300@tab @samp{-}
41301@tab No
41302
41303@item @samp{ReverseContinue}
41304@tab No
41305@tab @samp{-}
41306@tab No
41307
41308@item @samp{ReverseStep}
41309@tab No
41310@tab @samp{-}
41311@tab No
41312
41313@item @samp{TracepointSource}
41314@tab No
41315@tab @samp{-}
41316@tab No
41317
41318@item @samp{QAgent}
41319@tab No
41320@tab @samp{-}
41321@tab No
41322
41323@item @samp{QAllow}
41324@tab No
41325@tab @samp{-}
41326@tab No
41327
41328@item @samp{QDisableRandomization}
41329@tab No
41330@tab @samp{-}
41331@tab No
41332
41333@item @samp{EnableDisableTracepoints}
41334@tab No
41335@tab @samp{-}
41336@tab No
41337
41338@item @samp{QTBuffer:size}
41339@tab No
41340@tab @samp{-}
41341@tab No
41342
41343@item @samp{tracenz}
41344@tab No
41345@tab @samp{-}
41346@tab No
41347
41348@item @samp{BreakpointCommands}
41349@tab No
41350@tab @samp{-}
41351@tab No
41352
41353@item @samp{swbreak}
41354@tab No
41355@tab @samp{-}
41356@tab No
41357
41358@item @samp{hwbreak}
41359@tab No
41360@tab @samp{-}
41361@tab No
41362
41363@item @samp{fork-events}
41364@tab No
41365@tab @samp{-}
41366@tab No
41367
41368@item @samp{vfork-events}
41369@tab No
41370@tab @samp{-}
41371@tab No
41372
41373@item @samp{exec-events}
41374@tab No
41375@tab @samp{-}
41376@tab No
41377
41378@item @samp{QThreadEvents}
41379@tab No
41380@tab @samp{-}
41381@tab No
41382
41383@item @samp{no-resumed}
41384@tab No
41385@tab @samp{-}
41386@tab No
41387
41388@end multitable
41389
41390These are the currently defined stub features, in more detail:
41391
41392@table @samp
41393@cindex packet size, remote protocol
41394@item PacketSize=@var{bytes}
41395The remote stub can accept packets up to at least @var{bytes} in
41396length.  @value{GDBN} will send packets up to this size for bulk
41397transfers, and will never send larger packets.  This is a limit on the
41398data characters in the packet, including the frame and checksum.
41399There is no trailing NUL byte in a remote protocol packet; if the stub
41400stores packets in a NUL-terminated format, it should allow an extra
41401byte in its buffer for the NUL.  If this stub feature is not supported,
41402@value{GDBN} guesses based on the size of the @samp{g} packet response.
41403
41404@item qXfer:auxv:read
41405The remote stub understands the @samp{qXfer:auxv:read} packet
41406(@pxref{qXfer auxiliary vector read}).
41407
41408@item qXfer:btrace:read
41409The remote stub understands the @samp{qXfer:btrace:read}
41410packet (@pxref{qXfer btrace read}).
41411
41412@item qXfer:btrace-conf:read
41413The remote stub understands the @samp{qXfer:btrace-conf:read}
41414packet (@pxref{qXfer btrace-conf read}).
41415
41416@item qXfer:exec-file:read
41417The remote stub understands the @samp{qXfer:exec-file:read} packet
41418(@pxref{qXfer executable filename read}).
41419
41420@item qXfer:features:read
41421The remote stub understands the @samp{qXfer:features:read} packet
41422(@pxref{qXfer target description read}).
41423
41424@item qXfer:libraries:read
41425The remote stub understands the @samp{qXfer:libraries:read} packet
41426(@pxref{qXfer library list read}).
41427
41428@item qXfer:libraries-svr4:read
41429The remote stub understands the @samp{qXfer:libraries-svr4:read} packet
41430(@pxref{qXfer svr4 library list read}).
41431
41432@item augmented-libraries-svr4-read
41433The remote stub understands the augmented form of the
41434@samp{qXfer:libraries-svr4:read} packet
41435(@pxref{qXfer svr4 library list read}).
41436
41437@item qXfer:memory-map:read
41438The remote stub understands the @samp{qXfer:memory-map:read} packet
41439(@pxref{qXfer memory map read}).
41440
41441@item qXfer:sdata:read
41442The remote stub understands the @samp{qXfer:sdata:read} packet
41443(@pxref{qXfer sdata read}).
41444
41445@item qXfer:siginfo:read
41446The remote stub understands the @samp{qXfer:siginfo:read} packet
41447(@pxref{qXfer siginfo read}).
41448
41449@item qXfer:siginfo:write
41450The remote stub understands the @samp{qXfer:siginfo:write} packet
41451(@pxref{qXfer siginfo write}).
41452
41453@item qXfer:threads:read
41454The remote stub understands the @samp{qXfer:threads:read} packet
41455(@pxref{qXfer threads read}).
41456
41457@item qXfer:traceframe-info:read
41458The remote stub understands the @samp{qXfer:traceframe-info:read}
41459packet (@pxref{qXfer traceframe info read}).
41460
41461@item qXfer:uib:read
41462The remote stub understands the @samp{qXfer:uib:read}
41463packet (@pxref{qXfer unwind info block}).
41464
41465@item qXfer:fdpic:read
41466The remote stub understands the @samp{qXfer:fdpic:read}
41467packet (@pxref{qXfer fdpic loadmap read}).
41468
41469@item QNonStop
41470The remote stub understands the @samp{QNonStop} packet
41471(@pxref{QNonStop}).
41472
41473@item QCatchSyscalls
41474The remote stub understands the @samp{QCatchSyscalls} packet
41475(@pxref{QCatchSyscalls}).
41476
41477@item QPassSignals
41478The remote stub understands the @samp{QPassSignals} packet
41479(@pxref{QPassSignals}).
41480
41481@item QStartNoAckMode
41482The remote stub understands the @samp{QStartNoAckMode} packet and
41483prefers to operate in no-acknowledgment mode.  @xref{Packet Acknowledgment}.
41484
41485@item multiprocess
41486@anchor{multiprocess extensions}
41487@cindex multiprocess extensions, in remote protocol
41488The remote stub understands the multiprocess extensions to the remote
41489protocol syntax.  The multiprocess extensions affect the syntax of
41490thread IDs in both packets and replies (@pxref{thread-id syntax}), and
41491add process IDs to the @samp{D} packet and @samp{W} and @samp{X}
41492replies.  Note that reporting this feature indicates support for the
41493syntactic extensions only, not that the stub necessarily supports
41494debugging of more than one process at a time.  The stub must not use
41495multiprocess extensions in packet replies unless @value{GDBN} has also
41496indicated it supports them in its @samp{qSupported} request.
41497
41498@item qXfer:osdata:read
41499The remote stub understands the @samp{qXfer:osdata:read} packet
41500((@pxref{qXfer osdata read}).
41501
41502@item ConditionalBreakpoints
41503The target accepts and implements evaluation of conditional expressions
41504defined for breakpoints.  The target will only report breakpoint triggers
41505when such conditions are true (@pxref{Conditions, ,Break Conditions}).
41506
41507@item ConditionalTracepoints
41508The remote stub accepts and implements conditional expressions defined
41509for tracepoints (@pxref{Tracepoint Conditions}).
41510
41511@item ReverseContinue
41512The remote stub accepts and implements the reverse continue packet
41513(@pxref{bc}).
41514
41515@item ReverseStep
41516The remote stub accepts and implements the reverse step packet
41517(@pxref{bs}).
41518
41519@item TracepointSource
41520The remote stub understands the @samp{QTDPsrc} packet that supplies
41521the source form of tracepoint definitions.
41522
41523@item QAgent
41524The remote stub understands the @samp{QAgent} packet.
41525
41526@item QAllow
41527The remote stub understands the @samp{QAllow} packet.
41528
41529@item QDisableRandomization
41530The remote stub understands the @samp{QDisableRandomization} packet.
41531
41532@item StaticTracepoint
41533@cindex static tracepoints, in remote protocol
41534The remote stub supports static tracepoints.
41535
41536@item InstallInTrace
41537@anchor{install tracepoint in tracing}
41538The remote stub supports installing tracepoint in tracing.
41539
41540@item EnableDisableTracepoints
41541The remote stub supports the @samp{QTEnable} (@pxref{QTEnable}) and
41542@samp{QTDisable} (@pxref{QTDisable}) packets that allow tracepoints
41543to be enabled and disabled while a trace experiment is running.
41544
41545@item QTBuffer:size
41546The remote stub supports the @samp{QTBuffer:size} (@pxref{QTBuffer-size})
41547packet that allows to change the size of the trace buffer.
41548
41549@item tracenz
41550@cindex string tracing, in remote protocol
41551The remote stub supports the @samp{tracenz} bytecode for collecting strings.
41552See @ref{Bytecode Descriptions} for details about the bytecode.
41553
41554@item BreakpointCommands
41555@cindex breakpoint commands, in remote protocol
41556The remote stub supports running a breakpoint's command list itself,
41557rather than reporting the hit to @value{GDBN}.
41558
41559@item Qbtrace:off
41560The remote stub understands the @samp{Qbtrace:off} packet.
41561
41562@item Qbtrace:bts
41563The remote stub understands the @samp{Qbtrace:bts} packet.
41564
41565@item Qbtrace:pt
41566The remote stub understands the @samp{Qbtrace:pt} packet.
41567
41568@item Qbtrace-conf:bts:size
41569The remote stub understands the @samp{Qbtrace-conf:bts:size} packet.
41570
41571@item Qbtrace-conf:pt:size
41572The remote stub understands the @samp{Qbtrace-conf:pt:size} packet.
41573
41574@item swbreak
41575The remote stub reports the @samp{swbreak} stop reason for memory
41576breakpoints.
41577
41578@item hwbreak
41579The remote stub reports the @samp{hwbreak} stop reason for hardware
41580breakpoints.
41581
41582@item fork-events
41583The remote stub reports the @samp{fork} stop reason for fork events.
41584
41585@item vfork-events
41586The remote stub reports the @samp{vfork} stop reason for vfork events
41587and vforkdone events.
41588
41589@item exec-events
41590The remote stub reports the @samp{exec} stop reason for exec events.
41591
41592@item vContSupported
41593The remote stub reports the supported actions in the reply to
41594@samp{vCont?} packet.
41595
41596@item QThreadEvents
41597The remote stub understands the @samp{QThreadEvents} packet.
41598
41599@item no-resumed
41600The remote stub reports the @samp{N} stop reply.
41601
41602@end table
41603
41604@item qSymbol::
41605@cindex symbol lookup, remote request
41606@cindex @samp{qSymbol} packet
41607Notify the target that @value{GDBN} is prepared to serve symbol lookup
41608requests.  Accept requests from the target for the values of symbols.
41609
41610Reply:
41611@table @samp
41612@item OK
41613The target does not need to look up any (more) symbols.
41614@item qSymbol:@var{sym_name}
41615The target requests the value of symbol @var{sym_name} (hex encoded).
41616@value{GDBN} may provide the value by using the
41617@samp{qSymbol:@var{sym_value}:@var{sym_name}} message, described
41618below.
41619@end table
41620
41621@item qSymbol:@var{sym_value}:@var{sym_name}
41622Set the value of @var{sym_name} to @var{sym_value}.
41623
41624@var{sym_name} (hex encoded) is the name of a symbol whose value the
41625target has previously requested.
41626
41627@var{sym_value} (hex) is the value for symbol @var{sym_name}.  If
41628@value{GDBN} cannot supply a value for @var{sym_name}, then this field
41629will be empty.
41630
41631Reply:
41632@table @samp
41633@item OK
41634The target does not need to look up any (more) symbols.
41635@item qSymbol:@var{sym_name}
41636The target requests the value of a new symbol @var{sym_name} (hex
41637encoded).  @value{GDBN} will continue to supply the values of symbols
41638(if available), until the target ceases to request them.
41639@end table
41640
41641@item qTBuffer
41642@itemx QTBuffer
41643@itemx QTDisconnected
41644@itemx QTDP
41645@itemx QTDPsrc
41646@itemx QTDV
41647@itemx qTfP
41648@itemx qTfV
41649@itemx QTFrame
41650@itemx qTMinFTPILen
41651
41652@xref{Tracepoint Packets}.
41653
41654@item qThreadExtraInfo,@var{thread-id}
41655@cindex thread attributes info, remote request
41656@cindex @samp{qThreadExtraInfo} packet
41657Obtain from the target OS a printable string description of thread
41658attributes for the thread @var{thread-id}; see @ref{thread-id syntax},
41659for the forms of @var{thread-id}.  This
41660string may contain anything that the target OS thinks is interesting
41661for @value{GDBN} to tell the user about the thread.  The string is
41662displayed in @value{GDBN}'s @code{info threads} display.  Some
41663examples of possible thread extra info strings are @samp{Runnable}, or
41664@samp{Blocked on Mutex}.
41665
41666Reply:
41667@table @samp
41668@item @var{XX}@dots{}
41669Where @samp{@var{XX}@dots{}} is a hex encoding of @sc{ascii} data,
41670comprising the printable string containing the extra information about
41671the thread's attributes.
41672@end table
41673
41674(Note that the @code{qThreadExtraInfo} packet's name is separated from
41675the command by a @samp{,}, not a @samp{:}, contrary to the naming
41676conventions above.  Please don't use this packet as a model for new
41677packets.)
41678
41679@item QTNotes
41680@itemx qTP
41681@itemx QTSave
41682@itemx qTsP
41683@itemx qTsV
41684@itemx QTStart
41685@itemx QTStop
41686@itemx QTEnable
41687@itemx QTDisable
41688@itemx QTinit
41689@itemx QTro
41690@itemx qTStatus
41691@itemx qTV
41692@itemx qTfSTM
41693@itemx qTsSTM
41694@itemx qTSTMat
41695@xref{Tracepoint Packets}.
41696
41697@item qXfer:@var{object}:read:@var{annex}:@var{offset},@var{length}
41698@cindex read special object, remote request
41699@cindex @samp{qXfer} packet
41700@anchor{qXfer read}
41701Read uninterpreted bytes from the target's special data area
41702identified by the keyword @var{object}.  Request @var{length} bytes
41703starting at @var{offset} bytes into the data.  The content and
41704encoding of @var{annex} is specific to @var{object}; it can supply
41705additional details about what data to access.
41706
41707Reply:
41708@table @samp
41709@item m @var{data}
41710Data @var{data} (@pxref{Binary Data}) has been read from the
41711target.  There may be more data at a higher address (although
41712it is permitted to return @samp{m} even for the last valid
41713block of data, as long as at least one byte of data was read).
41714It is possible for @var{data} to have fewer bytes than the @var{length} in the
41715request.
41716
41717@item l @var{data}
41718Data @var{data} (@pxref{Binary Data}) has been read from the target.
41719There is no more data to be read.  It is possible for @var{data} to
41720have fewer bytes than the @var{length} in the request.
41721
41722@item l
41723The @var{offset} in the request is at the end of the data.
41724There is no more data to be read.
41725
41726@item E00
41727The request was malformed, or @var{annex} was invalid.
41728
41729@item E @var{nn}
41730The offset was invalid, or there was an error encountered reading the data.
41731The @var{nn} part is a hex-encoded @code{errno} value.
41732
41733@item @w{}
41734An empty reply indicates the @var{object} string was not recognized by
41735the stub, or that the object does not support reading.
41736@end table
41737
41738Here are the specific requests of this form defined so far.  All the
41739@samp{qXfer:@var{object}:read:@dots{}} requests use the same reply
41740formats, listed above.
41741
41742@table @samp
41743@item qXfer:auxv:read::@var{offset},@var{length}
41744@anchor{qXfer auxiliary vector read}
41745Access the target's @dfn{auxiliary vector}.  @xref{OS Information,
41746auxiliary vector}.  Note @var{annex} must be empty.
41747
41748This packet is not probed by default; the remote stub must request it,
41749by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41750
41751@item qXfer:btrace:read:@var{annex}:@var{offset},@var{length}
41752@anchor{qXfer btrace read}
41753
41754Return a description of the current branch trace.
41755@xref{Branch Trace Format}.  The annex part of the generic @samp{qXfer}
41756packet may have one of the following values:
41757
41758@table @code
41759@item all
41760Returns all available branch trace.
41761
41762@item new
41763Returns all available branch trace if the branch trace changed since
41764the last read request.
41765
41766@item delta
41767Returns the new branch trace since the last read request.  Adds a new
41768block to the end of the trace that begins at zero and ends at the source
41769location of the first branch in the trace buffer.  This extra block is
41770used to stitch traces together.
41771
41772If the trace buffer overflowed, returns an error indicating the overflow.
41773@end table
41774
41775This packet is not probed by default; the remote stub must request it
41776by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41777
41778@item qXfer:btrace-conf:read::@var{offset},@var{length}
41779@anchor{qXfer btrace-conf read}
41780
41781Return a description of the current branch trace configuration.
41782@xref{Branch Trace Configuration Format}.
41783
41784This packet is not probed by default; the remote stub must request it
41785by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41786
41787@item qXfer:exec-file:read:@var{annex}:@var{offset},@var{length}
41788@anchor{qXfer executable filename read}
41789Return the full absolute name of the file that was executed to create
41790a process running on the remote system.  The annex specifies the
41791numeric process ID of the process to query, encoded as a hexadecimal
41792number.  If the annex part is empty the remote stub should return the
41793filename corresponding to the currently executing process.
41794
41795This packet is not probed by default; the remote stub must request it,
41796by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41797
41798@item qXfer:features:read:@var{annex}:@var{offset},@var{length}
41799@anchor{qXfer target description read}
41800Access the @dfn{target description}.  @xref{Target Descriptions}.  The
41801annex specifies which XML document to access.  The main description is
41802always loaded from the @samp{target.xml} annex.
41803
41804This packet is not probed by default; the remote stub must request it,
41805by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41806
41807@item qXfer:libraries:read:@var{annex}:@var{offset},@var{length}
41808@anchor{qXfer library list read}
41809Access the target's list of loaded libraries.  @xref{Library List Format}.
41810The annex part of the generic @samp{qXfer} packet must be empty
41811(@pxref{qXfer read}).
41812
41813Targets which maintain a list of libraries in the program's memory do
41814not need to implement this packet; it is designed for platforms where
41815the operating system manages the list of loaded libraries.
41816
41817This packet is not probed by default; the remote stub must request it,
41818by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41819
41820@item qXfer:libraries-svr4:read:@var{annex}:@var{offset},@var{length}
41821@anchor{qXfer svr4 library list read}
41822Access the target's list of loaded libraries when the target is an SVR4
41823platform.  @xref{Library List Format for SVR4 Targets}.  The annex part
41824of the generic @samp{qXfer} packet must be empty unless the remote
41825stub indicated it supports the augmented form of this packet
41826by supplying an appropriate @samp{qSupported} response
41827(@pxref{qXfer read}, @ref{qSupported}).
41828
41829This packet is optional for better performance on SVR4 targets.
41830@value{GDBN} uses memory read packets to read the SVR4 library list otherwise.
41831
41832This packet is not probed by default; the remote stub must request it,
41833by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41834
41835If the remote stub indicates it supports the augmented form of this
41836packet then the annex part of the generic @samp{qXfer} packet may
41837contain a semicolon-separated list of @samp{@var{name}=@var{value}}
41838arguments.  The currently supported arguments are:
41839
41840@table @code
41841@item start=@var{address}
41842A hexadecimal number specifying the address of the @samp{struct
41843link_map} to start reading the library list from.  If unset or zero
41844then the first @samp{struct link_map} in the library list will be
41845chosen as the starting point.
41846
41847@item prev=@var{address}
41848A hexadecimal number specifying the address of the @samp{struct
41849link_map} immediately preceding the @samp{struct link_map}
41850specified by the @samp{start} argument.  If unset or zero then
41851the remote stub will expect that no @samp{struct link_map}
41852exists prior to the starting point.
41853
41854@end table
41855
41856Arguments that are not understood by the remote stub will be silently
41857ignored.
41858
41859@item qXfer:memory-map:read::@var{offset},@var{length}
41860@anchor{qXfer memory map read}
41861Access the target's @dfn{memory-map}.  @xref{Memory Map Format}.  The
41862annex part of the generic @samp{qXfer} packet must be empty
41863(@pxref{qXfer read}).
41864
41865This packet is not probed by default; the remote stub must request it,
41866by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41867
41868@item qXfer:sdata:read::@var{offset},@var{length}
41869@anchor{qXfer sdata read}
41870
41871Read contents of the extra collected static tracepoint marker
41872information.  The annex part of the generic @samp{qXfer} packet must
41873be empty (@pxref{qXfer read}).  @xref{Tracepoint Actions,,Tracepoint
41874Action Lists}.
41875
41876This packet is not probed by default; the remote stub must request it,
41877by supplying an appropriate @samp{qSupported} response
41878(@pxref{qSupported}).
41879
41880@item qXfer:siginfo:read::@var{offset},@var{length}
41881@anchor{qXfer siginfo read}
41882Read contents of the extra signal information on the target
41883system.  The annex part of the generic @samp{qXfer} packet must be
41884empty (@pxref{qXfer read}).
41885
41886This packet is not probed by default; the remote stub must request it,
41887by supplying an appropriate @samp{qSupported} response
41888(@pxref{qSupported}).
41889
41890@item qXfer:threads:read::@var{offset},@var{length}
41891@anchor{qXfer threads read}
41892Access the list of threads on target.  @xref{Thread List Format}.  The
41893annex part of the generic @samp{qXfer} packet must be empty
41894(@pxref{qXfer read}).
41895
41896This packet is not probed by default; the remote stub must request it,
41897by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41898
41899@item qXfer:traceframe-info:read::@var{offset},@var{length}
41900@anchor{qXfer traceframe info read}
41901
41902Return a description of the current traceframe's contents.
41903@xref{Traceframe Info Format}.  The annex part of the generic
41904@samp{qXfer} packet must be empty (@pxref{qXfer read}).
41905
41906This packet is not probed by default; the remote stub must request it,
41907by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41908
41909@item qXfer:uib:read:@var{pc}:@var{offset},@var{length}
41910@anchor{qXfer unwind info block}
41911
41912Return the unwind information block for @var{pc}.  This packet is used
41913on OpenVMS/ia64 to ask the kernel unwind information.
41914
41915This packet is not probed by default.
41916
41917@item qXfer:fdpic:read:@var{annex}:@var{offset},@var{length}
41918@anchor{qXfer fdpic loadmap read}
41919Read contents of @code{loadmap}s on the target system.  The
41920annex, either @samp{exec} or @samp{interp}, specifies which @code{loadmap},
41921executable @code{loadmap} or interpreter @code{loadmap} to read.
41922
41923This packet is not probed by default; the remote stub must request it,
41924by supplying an appropriate @samp{qSupported} response (@pxref{qSupported}).
41925
41926@item qXfer:osdata:read::@var{offset},@var{length}
41927@anchor{qXfer osdata read}
41928Access the target's @dfn{operating system information}.
41929@xref{Operating System Information}.
41930
41931@end table
41932
41933@item qXfer:@var{object}:write:@var{annex}:@var{offset}:@var{data}@dots{}
41934@cindex write data into object, remote request
41935@anchor{qXfer write}
41936Write uninterpreted bytes into the target's special data area
41937identified by the keyword @var{object}, starting at @var{offset} bytes
41938into the data.  The binary-encoded data (@pxref{Binary Data}) to be
41939written is given by @var{data}@dots{}.  The content and encoding of @var{annex}
41940is specific to @var{object}; it can supply additional details about what data
41941to access.
41942
41943Reply:
41944@table @samp
41945@item @var{nn}
41946@var{nn} (hex encoded) is the number of bytes written.
41947This may be fewer bytes than supplied in the request.
41948
41949@item E00
41950The request was malformed, or @var{annex} was invalid.
41951
41952@item E @var{nn}
41953The offset was invalid, or there was an error encountered writing the data.
41954The @var{nn} part is a hex-encoded @code{errno} value.
41955
41956@item @w{}
41957An empty reply indicates the @var{object} string was not
41958recognized by the stub, or that the object does not support writing.
41959@end table
41960
41961Here are the specific requests of this form defined so far.  All the
41962@samp{qXfer:@var{object}:write:@dots{}} requests use the same reply
41963formats, listed above.
41964
41965@table @samp
41966@item qXfer:siginfo:write::@var{offset}:@var{data}@dots{}
41967@anchor{qXfer siginfo write}
41968Write @var{data} to the extra signal information on the target system.
41969The annex part of the generic @samp{qXfer} packet must be
41970empty (@pxref{qXfer write}).
41971
41972This packet is not probed by default; the remote stub must request it,
41973by supplying an appropriate @samp{qSupported} response
41974(@pxref{qSupported}).
41975@end table
41976
41977@item qXfer:@var{object}:@var{operation}:@dots{}
41978Requests of this form may be added in the future.  When a stub does
41979not recognize the @var{object} keyword, or its support for
41980@var{object} does not recognize the @var{operation} keyword, the stub
41981must respond with an empty packet.
41982
41983@item qAttached:@var{pid}
41984@cindex query attached, remote request
41985@cindex @samp{qAttached} packet
41986Return an indication of whether the remote server attached to an
41987existing process or created a new process.  When the multiprocess
41988protocol extensions are supported (@pxref{multiprocess extensions}),
41989@var{pid} is an integer in hexadecimal format identifying the target
41990process.  Otherwise, @value{GDBN} will omit the @var{pid} field and
41991the query packet will be simplified as @samp{qAttached}.
41992
41993This query is used, for example, to know whether the remote process
41994should be detached or killed when a @value{GDBN} session is ended with
41995the @code{quit} command.
41996
41997Reply:
41998@table @samp
41999@item 1
42000The remote server attached to an existing process.
42001@item 0
42002The remote server created a new process.
42003@item E @var{NN}
42004A badly formed request or an error was encountered.
42005@end table
42006
42007@item Qbtrace:bts
42008Enable branch tracing for the current thread using Branch Trace Store.
42009
42010Reply:
42011@table @samp
42012@item OK
42013Branch tracing has been enabled.
42014@item E.errtext
42015A badly formed request or an error was encountered.
42016@end table
42017
42018@item Qbtrace:pt
42019Enable branch tracing for the current thread using Intel Processor Trace.
42020
42021Reply:
42022@table @samp
42023@item OK
42024Branch tracing has been enabled.
42025@item E.errtext
42026A badly formed request or an error was encountered.
42027@end table
42028
42029@item Qbtrace:off
42030Disable branch tracing for the current thread.
42031
42032Reply:
42033@table @samp
42034@item OK
42035Branch tracing has been disabled.
42036@item E.errtext
42037A badly formed request or an error was encountered.
42038@end table
42039
42040@item Qbtrace-conf:bts:size=@var{value}
42041Set the requested ring buffer size for new threads that use the
42042btrace recording method in bts format.
42043
42044Reply:
42045@table @samp
42046@item OK
42047The ring buffer size has been set.
42048@item E.errtext
42049A badly formed request or an error was encountered.
42050@end table
42051
42052@item Qbtrace-conf:pt:size=@var{value}
42053Set the requested ring buffer size for new threads that use the
42054btrace recording method in pt format.
42055
42056Reply:
42057@table @samp
42058@item OK
42059The ring buffer size has been set.
42060@item E.errtext
42061A badly formed request or an error was encountered.
42062@end table
42063
42064@end table
42065
42066@node Architecture-Specific Protocol Details
42067@section Architecture-Specific Protocol Details
42068
42069This section describes how the remote protocol is applied to specific
42070target architectures.  Also see @ref{Standard Target Features}, for
42071details of XML target descriptions for each architecture.
42072
42073@menu
42074* ARM-Specific Protocol Details::
42075* MIPS-Specific Protocol Details::
42076@end menu
42077
42078@node ARM-Specific Protocol Details
42079@subsection @acronym{ARM}-specific Protocol Details
42080
42081@menu
42082* ARM Breakpoint Kinds::
42083@end menu
42084
42085@node ARM Breakpoint Kinds
42086@subsubsection @acronym{ARM} Breakpoint Kinds
42087@cindex breakpoint kinds, @acronym{ARM}
42088
42089These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
42090
42091@table @r
42092
42093@item 2
4209416-bit Thumb mode breakpoint.
42095
42096@item 3
4209732-bit Thumb mode (Thumb-2) breakpoint.
42098
42099@item 4
4210032-bit @acronym{ARM} mode breakpoint.
42101
42102@end table
42103
42104@node MIPS-Specific Protocol Details
42105@subsection @acronym{MIPS}-specific Protocol Details
42106
42107@menu
42108* MIPS Register packet Format::
42109* MIPS Breakpoint Kinds::
42110@end menu
42111
42112@node MIPS Register packet Format
42113@subsubsection @acronym{MIPS} Register Packet Format
42114@cindex register packet format, @acronym{MIPS}
42115
42116The following @code{g}/@code{G} packets have previously been defined.
42117In the below, some thirty-two bit registers are transferred as
42118sixty-four bits.  Those registers should be zero/sign extended (which?)
42119to fill the space allocated.  Register bytes are transferred in target
42120byte order.  The two nibbles within a register byte are transferred
42121most-significant -- least-significant.
42122
42123@table @r
42124
42125@item MIPS32
42126All registers are transferred as thirty-two bit quantities in the order:
4212732 general-purpose; sr; lo; hi; bad; cause; pc; 32 floating-point
42128registers; fsr; fir; fp.
42129
42130@item MIPS64
42131All registers are transferred as sixty-four bit quantities (including
42132thirty-two bit registers such as @code{sr}).  The ordering is the same
42133as @code{MIPS32}.
42134
42135@end table
42136
42137@node MIPS Breakpoint Kinds
42138@subsubsection @acronym{MIPS} Breakpoint Kinds
42139@cindex breakpoint kinds, @acronym{MIPS}
42140
42141These breakpoint kinds are defined for the @samp{Z0} and @samp{Z1} packets.
42142
42143@table @r
42144
42145@item 2
4214616-bit @acronym{MIPS16} mode breakpoint.
42147
42148@item 3
4214916-bit @acronym{microMIPS} mode breakpoint.
42150
42151@item 4
4215232-bit standard @acronym{MIPS} mode breakpoint.
42153
42154@item 5
4215532-bit @acronym{microMIPS} mode breakpoint.
42156
42157@end table
42158
42159@node Tracepoint Packets
42160@section Tracepoint Packets
42161@cindex tracepoint packets
42162@cindex packets, tracepoint
42163
42164Here we describe the packets @value{GDBN} uses to implement
42165tracepoints (@pxref{Tracepoints}).
42166
42167@table @samp
42168
42169@item QTDP:@var{n}:@var{addr}:@var{ena}:@var{step}:@var{pass}[:F@var{flen}][:X@var{len},@var{bytes}]@r{[}-@r{]}
42170@cindex @samp{QTDP} packet
42171Create a new tracepoint, number @var{n}, at @var{addr}.  If @var{ena}
42172is @samp{E}, then the tracepoint is enabled; if it is @samp{D}, then
42173the tracepoint is disabled.  The @var{step} gives the tracepoint's step
42174count, and @var{pass} gives its pass count.  If an @samp{F} is present,
42175then the tracepoint is to be a fast tracepoint, and the @var{flen} is
42176the number of bytes that the target should copy elsewhere to make room
42177for the tracepoint.  If an @samp{X} is present, it introduces a
42178tracepoint condition, which consists of a hexadecimal length, followed
42179by a comma and hex-encoded bytes, in a manner similar to action
42180encodings as described below.  If the trailing @samp{-} is present,
42181further @samp{QTDP} packets will follow to specify this tracepoint's
42182actions.
42183
42184Replies:
42185@table @samp
42186@item OK
42187The packet was understood and carried out.
42188@item qRelocInsn
42189@xref{Tracepoint Packets,,Relocate instruction reply packet}.
42190@item  @w{}
42191The packet was not recognized.
42192@end table
42193
42194@item QTDP:-@var{n}:@var{addr}:@r{[}S@r{]}@var{action}@dots{}@r{[}-@r{]}
42195Define actions to be taken when a tracepoint is hit.  The @var{n} and
42196@var{addr} must be the same as in the initial @samp{QTDP} packet for
42197this tracepoint.  This packet may only be sent immediately after
42198another @samp{QTDP} packet that ended with a @samp{-}.  If the
42199trailing @samp{-} is present, further @samp{QTDP} packets will follow,
42200specifying more actions for this tracepoint.
42201
42202In the series of action packets for a given tracepoint, at most one
42203can have an @samp{S} before its first @var{action}.  If such a packet
42204is sent, it and the following packets define ``while-stepping''
42205actions.  Any prior packets define ordinary actions --- that is, those
42206taken when the tracepoint is first hit.  If no action packet has an
42207@samp{S}, then all the packets in the series specify ordinary
42208tracepoint actions.
42209
42210The @samp{@var{action}@dots{}} portion of the packet is a series of
42211actions, concatenated without separators.  Each action has one of the
42212following forms:
42213
42214@table @samp
42215
42216@item R @var{mask}
42217Collect the registers whose bits are set in @var{mask},
42218a hexadecimal number whose @var{i}'th bit is set if register number
42219@var{i} should be collected.  (The least significant bit is numbered
42220zero.)  Note that @var{mask} may be any number of digits long; it may
42221not fit in a 32-bit word.
42222
42223@item M @var{basereg},@var{offset},@var{len}
42224Collect @var{len} bytes of memory starting at the address in register
42225number @var{basereg}, plus @var{offset}.  If @var{basereg} is
42226@samp{-1}, then the range has a fixed address: @var{offset} is the
42227address of the lowest byte to collect.  The @var{basereg},
42228@var{offset}, and @var{len} parameters are all unsigned hexadecimal
42229values (the @samp{-1} value for @var{basereg} is a special case).
42230
42231@item X @var{len},@var{expr}
42232Evaluate @var{expr}, whose length is @var{len}, and collect memory as
42233it directs.  The agent expression @var{expr} is as described in
42234@ref{Agent Expressions}.  Each byte of the expression is encoded as a
42235two-digit hex number in the packet; @var{len} is the number of bytes
42236in the expression (and thus one-half the number of hex digits in the
42237packet).
42238
42239@end table
42240
42241Any number of actions may be packed together in a single @samp{QTDP}
42242packet, as long as the packet does not exceed the maximum packet
42243length (400 bytes, for many stubs).  There may be only one @samp{R}
42244action per tracepoint, and it must precede any @samp{M} or @samp{X}
42245actions.  Any registers referred to by @samp{M} and @samp{X} actions
42246must be collected by a preceding @samp{R} action.  (The
42247``while-stepping'' actions are treated as if they were attached to a
42248separate tracepoint, as far as these restrictions are concerned.)
42249
42250Replies:
42251@table @samp
42252@item OK
42253The packet was understood and carried out.
42254@item qRelocInsn
42255@xref{Tracepoint Packets,,Relocate instruction reply packet}.
42256@item  @w{}
42257The packet was not recognized.
42258@end table
42259
42260@item QTDPsrc:@var{n}:@var{addr}:@var{type}:@var{start}:@var{slen}:@var{bytes}
42261@cindex @samp{QTDPsrc} packet
42262Specify a source string of tracepoint @var{n} at address @var{addr}.
42263This is useful to get accurate reproduction of the tracepoints
42264originally downloaded at the beginning of the trace run.  The @var{type}
42265is the name of the tracepoint part, such as @samp{cond} for the
42266tracepoint's conditional expression (see below for a list of types), while
42267@var{bytes} is the string, encoded in hexadecimal.
42268
42269@var{start} is the offset of the @var{bytes} within the overall source
42270string, while @var{slen} is the total length of the source string.
42271This is intended for handling source strings that are longer than will
42272fit in a single packet.
42273@c Add detailed example when this info is moved into a dedicated
42274@c tracepoint descriptions section.
42275
42276The available string types are @samp{at} for the location,
42277@samp{cond} for the conditional, and @samp{cmd} for an action command.
42278@value{GDBN} sends a separate packet for each command in the action
42279list, in the same order in which the commands are stored in the list.
42280
42281The target does not need to do anything with source strings except
42282report them back as part of the replies to the @samp{qTfP}/@samp{qTsP}
42283query packets.
42284
42285Although this packet is optional, and @value{GDBN} will only send it
42286if the target replies with @samp{TracepointSource} @xref{General
42287Query Packets}, it makes both disconnected tracing and trace files
42288much easier to use.  Otherwise the user must be careful that the
42289tracepoints in effect while looking at trace frames are identical to
42290the ones in effect during the trace run; even a small discrepancy
42291could cause @samp{tdump} not to work, or a particular trace frame not
42292be found.
42293
42294@item QTDV:@var{n}:@var{value}:@var{builtin}:@var{name}
42295@cindex define trace state variable, remote request
42296@cindex @samp{QTDV} packet
42297Create a new trace state variable, number @var{n}, with an initial
42298value of @var{value}, which is a 64-bit signed integer.  Both @var{n}
42299and @var{value} are encoded as hexadecimal values. @value{GDBN} has
42300the option of not using this packet for initial values of zero; the
42301target should simply create the trace state variables as they are
42302mentioned in expressions.  The value @var{builtin} should be 1 (one)
42303if the trace state variable is builtin and 0 (zero) if it is not builtin.
42304@value{GDBN} only sets @var{builtin} to 1 if a previous @samp{qTfV} or
42305@samp{qTsV} packet had it set.  The contents of @var{name} is the
42306hex-encoded name (without the leading @samp{$}) of the trace state
42307variable.
42308
42309@item QTFrame:@var{n}
42310@cindex @samp{QTFrame} packet
42311Select the @var{n}'th tracepoint frame from the buffer, and use the
42312register and memory contents recorded there to answer subsequent
42313request packets from @value{GDBN}.
42314
42315A successful reply from the stub indicates that the stub has found the
42316requested frame.  The response is a series of parts, concatenated
42317without separators, describing the frame we selected.  Each part has
42318one of the following forms:
42319
42320@table @samp
42321@item F @var{f}
42322The selected frame is number @var{n} in the trace frame buffer;
42323@var{f} is a hexadecimal number.  If @var{f} is @samp{-1}, then there
42324was no frame matching the criteria in the request packet.
42325
42326@item T @var{t}
42327The selected trace frame records a hit of tracepoint number @var{t};
42328@var{t} is a hexadecimal number.
42329
42330@end table
42331
42332@item QTFrame:pc:@var{addr}
42333Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
42334currently selected frame whose PC is @var{addr};
42335@var{addr} is a hexadecimal number.
42336
42337@item QTFrame:tdp:@var{t}
42338Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
42339currently selected frame that is a hit of tracepoint @var{t}; @var{t}
42340is a hexadecimal number.
42341
42342@item QTFrame:range:@var{start}:@var{end}
42343Like @samp{QTFrame:@var{n}}, but select the first tracepoint frame after the
42344currently selected frame whose PC is between @var{start} (inclusive)
42345and @var{end} (inclusive); @var{start} and @var{end} are hexadecimal
42346numbers.
42347
42348@item QTFrame:outside:@var{start}:@var{end}
42349Like @samp{QTFrame:range:@var{start}:@var{end}}, but select the first
42350frame @emph{outside} the given range of addresses (exclusive).
42351
42352@item qTMinFTPILen
42353@cindex @samp{qTMinFTPILen} packet
42354This packet requests the minimum length of instruction at which a fast
42355tracepoint (@pxref{Set Tracepoints}) may be placed.  For instance, on
42356the 32-bit x86 architecture, it is possible to use a 4-byte jump, but
42357it depends on the target system being able to create trampolines in
42358the first 64K of memory, which might or might not be possible for that
42359system.  So the reply to this packet will be 4 if it is able to
42360arrange for that.
42361
42362Replies:
42363
42364@table @samp
42365@item 0
42366The minimum instruction length is currently unknown.
42367@item @var{length}
42368The minimum instruction length is @var{length}, where @var{length}
42369is a hexadecimal number greater or equal to 1.  A reply
42370of 1 means that a fast tracepoint may be placed on any instruction
42371regardless of size.
42372@item E
42373An error has occurred.
42374@item @w{}
42375An empty reply indicates that the request is not supported by the stub.
42376@end table
42377
42378@item QTStart
42379@cindex @samp{QTStart} packet
42380Begin the tracepoint experiment.  Begin collecting data from
42381tracepoint hits in the trace frame buffer.  This packet supports the
42382@samp{qRelocInsn} reply (@pxref{Tracepoint Packets,,Relocate
42383instruction reply packet}).
42384
42385@item QTStop
42386@cindex @samp{QTStop} packet
42387End the tracepoint experiment.  Stop collecting trace frames.
42388
42389@item QTEnable:@var{n}:@var{addr}
42390@anchor{QTEnable}
42391@cindex @samp{QTEnable} packet
42392Enable tracepoint @var{n} at address @var{addr} in a started tracepoint
42393experiment.  If the tracepoint was previously disabled, then collection
42394of data from it will resume.
42395
42396@item QTDisable:@var{n}:@var{addr}
42397@anchor{QTDisable}
42398@cindex @samp{QTDisable} packet
42399Disable tracepoint @var{n} at address @var{addr} in a started tracepoint
42400experiment.  No more data will be collected from the tracepoint unless
42401@samp{QTEnable:@var{n}:@var{addr}} is subsequently issued.
42402
42403@item QTinit
42404@cindex @samp{QTinit} packet
42405Clear the table of tracepoints, and empty the trace frame buffer.
42406
42407@item QTro:@var{start1},@var{end1}:@var{start2},@var{end2}:@dots{}
42408@cindex @samp{QTro} packet
42409Establish the given ranges of memory as ``transparent''.  The stub
42410will answer requests for these ranges from memory's current contents,
42411if they were not collected as part of the tracepoint hit.
42412
42413@value{GDBN} uses this to mark read-only regions of memory, like those
42414containing program code.  Since these areas never change, they should
42415still have the same contents they did when the tracepoint was hit, so
42416there's no reason for the stub to refuse to provide their contents.
42417
42418@item QTDisconnected:@var{value}
42419@cindex @samp{QTDisconnected} packet
42420Set the choice to what to do with the tracing run when @value{GDBN}
42421disconnects from the target.  A @var{value} of 1 directs the target to
42422continue the tracing run, while 0 tells the target to stop tracing if
42423@value{GDBN} is no longer in the picture.
42424
42425@item qTStatus
42426@cindex @samp{qTStatus} packet
42427Ask the stub if there is a trace experiment running right now.
42428
42429The reply has the form:
42430
42431@table @samp
42432
42433@item T@var{running}@r{[};@var{field}@r{]}@dots{}
42434@var{running} is a single digit @code{1} if the trace is presently
42435running, or @code{0} if not.  It is followed by semicolon-separated
42436optional fields that an agent may use to report additional status.
42437
42438@end table
42439
42440If the trace is not running, the agent may report any of several
42441explanations as one of the optional fields:
42442
42443@table @samp
42444
42445@item tnotrun:0
42446No trace has been run yet.
42447
42448@item tstop[:@var{text}]:0
42449The trace was stopped by a user-originated stop command.  The optional
42450@var{text} field is a user-supplied string supplied as part of the
42451stop command (for instance, an explanation of why the trace was
42452stopped manually).  It is hex-encoded.
42453
42454@item tfull:0
42455The trace stopped because the trace buffer filled up.
42456
42457@item tdisconnected:0
42458The trace stopped because @value{GDBN} disconnected from the target.
42459
42460@item tpasscount:@var{tpnum}
42461The trace stopped because tracepoint @var{tpnum} exceeded its pass count.
42462
42463@item terror:@var{text}:@var{tpnum}
42464The trace stopped because tracepoint @var{tpnum} had an error.  The
42465string @var{text} is available to describe the nature of the error
42466(for instance, a divide by zero in the condition expression); it
42467is hex encoded.
42468
42469@item tunknown:0
42470The trace stopped for some other reason.
42471
42472@end table
42473
42474Additional optional fields supply statistical and other information.
42475Although not required, they are extremely useful for users monitoring
42476the progress of a trace run.  If a trace has stopped, and these
42477numbers are reported, they must reflect the state of the just-stopped
42478trace.
42479
42480@table @samp
42481
42482@item tframes:@var{n}
42483The number of trace frames in the buffer.
42484
42485@item tcreated:@var{n}
42486The total number of trace frames created during the run. This may
42487be larger than the trace frame count, if the buffer is circular.
42488
42489@item tsize:@var{n}
42490The total size of the trace buffer, in bytes.
42491
42492@item tfree:@var{n}
42493The number of bytes still unused in the buffer.
42494
42495@item circular:@var{n}
42496The value of the circular trace buffer flag.  @code{1} means that the
42497trace buffer is circular and old trace frames will be discarded if
42498necessary to make room, @code{0} means that the trace buffer is linear
42499and may fill up.
42500
42501@item disconn:@var{n}
42502The value of the disconnected tracing flag.  @code{1} means that
42503tracing will continue after @value{GDBN} disconnects, @code{0} means
42504that the trace run will stop.
42505
42506@end table
42507
42508@item qTP:@var{tp}:@var{addr}
42509@cindex tracepoint status, remote request
42510@cindex @samp{qTP} packet
42511Ask the stub for the current state of tracepoint number @var{tp} at
42512address @var{addr}.
42513
42514Replies:
42515@table @samp
42516@item V@var{hits}:@var{usage}
42517The tracepoint has been hit @var{hits} times so far during the trace
42518run, and accounts for @var{usage} in the trace buffer.  Note that
42519@code{while-stepping} steps are not counted as separate hits, but the
42520steps' space consumption is added into the usage number.
42521
42522@end table
42523
42524@item qTV:@var{var}
42525@cindex trace state variable value, remote request
42526@cindex @samp{qTV} packet
42527Ask the stub for the value of the trace state variable number @var{var}.
42528
42529Replies:
42530@table @samp
42531@item V@var{value}
42532The value of the variable is @var{value}.  This will be the current
42533value of the variable if the user is examining a running target, or a
42534saved value if the variable was collected in the trace frame that the
42535user is looking at.  Note that multiple requests may result in
42536different reply values, such as when requesting values while the
42537program is running.
42538
42539@item U
42540The value of the variable is unknown.  This would occur, for example,
42541if the user is examining a trace frame in which the requested variable
42542was not collected.
42543@end table
42544
42545@item qTfP
42546@cindex @samp{qTfP} packet
42547@itemx qTsP
42548@cindex @samp{qTsP} packet
42549These packets request data about tracepoints that are being used by
42550the target.  @value{GDBN} sends @code{qTfP} to get the first piece
42551of data, and multiple @code{qTsP} to get additional pieces.  Replies
42552to these packets generally take the form of the @code{QTDP} packets
42553that define tracepoints. (FIXME add detailed syntax)
42554
42555@item qTfV
42556@cindex @samp{qTfV} packet
42557@itemx qTsV
42558@cindex @samp{qTsV} packet
42559These packets request data about trace state variables that are on the
42560target.  @value{GDBN} sends @code{qTfV} to get the first vari of data,
42561and multiple @code{qTsV} to get additional variables.  Replies to
42562these packets follow the syntax of the @code{QTDV} packets that define
42563trace state variables.
42564
42565@item qTfSTM
42566@itemx qTsSTM
42567@anchor{qTfSTM}
42568@anchor{qTsSTM}
42569@cindex @samp{qTfSTM} packet
42570@cindex @samp{qTsSTM} packet
42571These packets request data about static tracepoint markers that exist
42572in the target program.  @value{GDBN} sends @code{qTfSTM} to get the
42573first piece of data, and multiple @code{qTsSTM} to get additional
42574pieces.  Replies to these packets take the following form:
42575
42576Reply:
42577@table @samp
42578@item m @var{address}:@var{id}:@var{extra}
42579A single marker
42580@item m @var{address}:@var{id}:@var{extra},@var{address}:@var{id}:@var{extra}@dots{}
42581a comma-separated list of markers
42582@item l
42583(lower case letter @samp{L}) denotes end of list.
42584@item E @var{nn}
42585An error occurred.  The error number @var{nn} is given as hex digits.
42586@item @w{}
42587An empty reply indicates that the request is not supported by the
42588stub.
42589@end table
42590
42591The @var{address} is encoded in hex;
42592@var{id} and @var{extra} are strings encoded in hex.
42593
42594In response to each query, the target will reply with a list of one or
42595more markers, separated by commas.  @value{GDBN} will respond to each
42596reply with a request for more markers (using the @samp{qs} form of the
42597query), until the target responds with @samp{l} (lower-case ell, for
42598@dfn{last}).
42599
42600@item qTSTMat:@var{address}
42601@anchor{qTSTMat}
42602@cindex @samp{qTSTMat} packet
42603This packets requests data about static tracepoint markers in the
42604target program at @var{address}.  Replies to this packet follow the
42605syntax of the @samp{qTfSTM} and @code{qTsSTM} packets that list static
42606tracepoint markers.
42607
42608@item QTSave:@var{filename}
42609@cindex @samp{QTSave} packet
42610This packet directs the target to save trace data to the file name
42611@var{filename} in the target's filesystem.  The @var{filename} is encoded
42612as a hex string; the interpretation of the file name (relative vs
42613absolute, wild cards, etc) is up to the target.
42614
42615@item qTBuffer:@var{offset},@var{len}
42616@cindex @samp{qTBuffer} packet
42617Return up to @var{len} bytes of the current contents of trace buffer,
42618starting at @var{offset}.  The trace buffer is treated as if it were
42619a contiguous collection of traceframes, as per the trace file format.
42620The reply consists as many hex-encoded bytes as the target can deliver
42621in a packet; it is not an error to return fewer than were asked for.
42622A reply consisting of just @code{l} indicates that no bytes are
42623available.
42624
42625@item QTBuffer:circular:@var{value}
42626This packet directs the target to use a circular trace buffer if
42627@var{value} is 1, or a linear buffer if the value is 0.
42628
42629@item QTBuffer:size:@var{size}
42630@anchor{QTBuffer-size}
42631@cindex @samp{QTBuffer size} packet
42632This packet directs the target to make the trace buffer be of size
42633@var{size} if possible.  A value of @code{-1} tells the target to
42634use whatever size it prefers.
42635
42636@item QTNotes:@r{[}@var{type}:@var{text}@r{]}@r{[};@var{type}:@var{text}@r{]}@dots{}
42637@cindex @samp{QTNotes} packet
42638This packet adds optional textual notes to the trace run.  Allowable
42639types include @code{user}, @code{notes}, and @code{tstop}, the
42640@var{text} fields are arbitrary strings, hex-encoded.
42641
42642@end table
42643
42644@subsection Relocate instruction reply packet
42645When installing fast tracepoints in memory, the target may need to
42646relocate the instruction currently at the tracepoint address to a
42647different address in memory.  For most instructions, a simple copy is
42648enough, but, for example, call instructions that implicitly push the
42649return address on the stack, and relative branches or other
42650PC-relative instructions require offset adjustment, so that the effect
42651of executing the instruction at a different address is the same as if
42652it had executed in the original location.
42653
42654In response to several of the tracepoint packets, the target may also
42655respond with a number of intermediate @samp{qRelocInsn} request
42656packets before the final result packet, to have @value{GDBN} handle
42657this relocation operation.  If a packet supports this mechanism, its
42658documentation will explicitly say so.  See for example the above
42659descriptions for the @samp{QTStart} and @samp{QTDP} packets.  The
42660format of the request is:
42661
42662@table @samp
42663@item qRelocInsn:@var{from};@var{to}
42664
42665This requests @value{GDBN} to copy instruction at address @var{from}
42666to address @var{to}, possibly adjusted so that executing the
42667instruction at @var{to} has the same effect as executing it at
42668@var{from}.  @value{GDBN} writes the adjusted instruction to target
42669memory starting at @var{to}.
42670@end table
42671
42672Replies:
42673@table @samp
42674@item qRelocInsn:@var{adjusted_size}
42675Informs the stub the relocation is complete.  The @var{adjusted_size} is
42676the length in bytes of resulting relocated instruction sequence.
42677@item E @var{NN}
42678A badly formed request was detected, or an error was encountered while
42679relocating the instruction.
42680@end table
42681
42682@node Host I/O Packets
42683@section Host I/O Packets
42684@cindex Host I/O, remote protocol
42685@cindex file transfer, remote protocol
42686
42687The @dfn{Host I/O} packets allow @value{GDBN} to perform I/O
42688operations on the far side of a remote link.  For example, Host I/O is
42689used to upload and download files to a remote target with its own
42690filesystem.  Host I/O uses the same constant values and data structure
42691layout as the target-initiated File-I/O protocol.  However, the
42692Host I/O packets are structured differently.  The target-initiated
42693protocol relies on target memory to store parameters and buffers.
42694Host I/O requests are initiated by @value{GDBN}, and the
42695target's memory is not involved.  @xref{File-I/O Remote Protocol
42696Extension}, for more details on the target-initiated protocol.
42697
42698The Host I/O request packets all encode a single operation along with
42699its arguments.  They have this format:
42700
42701@table @samp
42702
42703@item vFile:@var{operation}: @var{parameter}@dots{}
42704@var{operation} is the name of the particular request; the target
42705should compare the entire packet name up to the second colon when checking
42706for a supported operation.  The format of @var{parameter} depends on
42707the operation.  Numbers are always passed in hexadecimal.  Negative
42708numbers have an explicit minus sign (i.e.@: two's complement is not
42709used).  Strings (e.g.@: filenames) are encoded as a series of
42710hexadecimal bytes.  The last argument to a system call may be a
42711buffer of escaped binary data (@pxref{Binary Data}).
42712
42713@end table
42714
42715The valid responses to Host I/O packets are:
42716
42717@table @samp
42718
42719@item F @var{result} [, @var{errno}] [; @var{attachment}]
42720@var{result} is the integer value returned by this operation, usually
42721non-negative for success and -1 for errors.  If an error has occured,
42722@var{errno} will be included in the result specifying a
42723value defined by the File-I/O protocol (@pxref{Errno Values}).  For
42724operations which return data, @var{attachment} supplies the data as a
42725binary buffer.  Binary buffers in response packets are escaped in the
42726normal way (@pxref{Binary Data}).  See the individual packet
42727documentation for the interpretation of @var{result} and
42728@var{attachment}.
42729
42730@item @w{}
42731An empty response indicates that this operation is not recognized.
42732
42733@end table
42734
42735These are the supported Host I/O operations:
42736
42737@table @samp
42738@item vFile:open: @var{filename}, @var{flags}, @var{mode}
42739Open a file at @var{filename} and return a file descriptor for it, or
42740return -1 if an error occurs.  The @var{filename} is a string,
42741@var{flags} is an integer indicating a mask of open flags
42742(@pxref{Open Flags}), and @var{mode} is an integer indicating a mask
42743of mode bits to use if the file is created (@pxref{mode_t Values}).
42744@xref{open}, for details of the open flags and mode values.
42745
42746@item vFile:close: @var{fd}
42747Close the open file corresponding to @var{fd} and return 0, or
42748-1 if an error occurs.
42749
42750@item vFile:pread: @var{fd}, @var{count}, @var{offset}
42751Read data from the open file corresponding to @var{fd}.  Up to
42752@var{count} bytes will be read from the file, starting at @var{offset}
42753relative to the start of the file.  The target may read fewer bytes;
42754common reasons include packet size limits and an end-of-file
42755condition.  The number of bytes read is returned.  Zero should only be
42756returned for a successful read at the end of the file, or if
42757@var{count} was zero.
42758
42759The data read should be returned as a binary attachment on success.
42760If zero bytes were read, the response should include an empty binary
42761attachment (i.e.@: a trailing semicolon).  The return value is the
42762number of target bytes read; the binary attachment may be longer if
42763some characters were escaped.
42764
42765@item vFile:pwrite: @var{fd}, @var{offset}, @var{data}
42766Write @var{data} (a binary buffer) to the open file corresponding
42767to @var{fd}.  Start the write at @var{offset} from the start of the
42768file.  Unlike many @code{write} system calls, there is no
42769separate @var{count} argument; the length of @var{data} in the
42770packet is used.  @samp{vFile:pwrite} returns the number of bytes written,
42771which may be shorter than the length of @var{data}, or -1 if an
42772error occurred.
42773
42774@item vFile:fstat: @var{fd}
42775Get information about the open file corresponding to @var{fd}.
42776On success the information is returned as a binary attachment
42777and the return value is the size of this attachment in bytes.
42778If an error occurs the return value is -1.  The format of the
42779returned binary attachment is as described in @ref{struct stat}.
42780
42781@item vFile:unlink: @var{filename}
42782Delete the file at @var{filename} on the target.  Return 0,
42783or -1 if an error occurs.  The @var{filename} is a string.
42784
42785@item vFile:readlink: @var{filename}
42786Read value of symbolic link @var{filename} on the target.  Return
42787the number of bytes read, or -1 if an error occurs.
42788
42789The data read should be returned as a binary attachment on success.
42790If zero bytes were read, the response should include an empty binary
42791attachment (i.e.@: a trailing semicolon).  The return value is the
42792number of target bytes read; the binary attachment may be longer if
42793some characters were escaped.
42794
42795@item vFile:setfs: @var{pid}
42796Select the filesystem on which @code{vFile} operations with
42797@var{filename} arguments will operate.  This is required for
42798@value{GDBN} to be able to access files on remote targets where
42799the remote stub does not share a common filesystem with the
42800inferior(s).
42801
42802If @var{pid} is nonzero, select the filesystem as seen by process
42803@var{pid}.  If @var{pid} is zero, select the filesystem as seen by
42804the remote stub.  Return 0 on success, or -1 if an error occurs.
42805If @code{vFile:setfs:} indicates success, the selected filesystem
42806remains selected until the next successful @code{vFile:setfs:}
42807operation.
42808
42809@end table
42810
42811@node Interrupts
42812@section Interrupts
42813@cindex interrupts (remote protocol)
42814@anchor{interrupting remote targets}
42815
42816In all-stop mode, when a program on the remote target is running,
42817@value{GDBN} may attempt to interrupt it by sending a @samp{Ctrl-C},
42818@code{BREAK} or a @code{BREAK} followed by @code{g}, control of which
42819is specified via @value{GDBN}'s @samp{interrupt-sequence}.
42820
42821The precise meaning of @code{BREAK} is defined by the transport
42822mechanism and may, in fact, be undefined.  @value{GDBN} does not
42823currently define a @code{BREAK} mechanism for any of the network
42824interfaces except for TCP, in which case @value{GDBN} sends the
42825@code{telnet} BREAK sequence.
42826
42827@samp{Ctrl-C}, on the other hand, is defined and implemented for all
42828transport mechanisms.  It is represented by sending the single byte
42829@code{0x03} without any of the usual packet overhead described in
42830the Overview section (@pxref{Overview}).  When a @code{0x03} byte is
42831transmitted as part of a packet, it is considered to be packet data
42832and does @emph{not} represent an interrupt.  E.g., an @samp{X} packet
42833(@pxref{X packet}), used for binary downloads, may include an unescaped
42834@code{0x03} as part of its packet.
42835
42836@code{BREAK} followed by @code{g} is also known as Magic SysRq g.
42837When Linux kernel receives this sequence from serial port,
42838it stops execution and connects to gdb.
42839
42840In non-stop mode, because packet resumptions are asynchronous
42841(@pxref{vCont packet}), @value{GDBN} is always free to send a remote
42842command to the remote stub, even when the target is running.  For that
42843reason, @value{GDBN} instead sends a regular packet (@pxref{vCtrlC
42844packet}) with the usual packet framing instead of the single byte
42845@code{0x03}.
42846
42847Stubs are not required to recognize these interrupt mechanisms and the
42848precise meaning associated with receipt of the interrupt is
42849implementation defined.  If the target supports debugging of multiple
42850threads and/or processes, it should attempt to interrupt all
42851currently-executing threads and processes.
42852If the stub is successful at interrupting the
42853running program, it should send one of the stop
42854reply packets (@pxref{Stop Reply Packets}) to @value{GDBN} as a result
42855of successfully stopping the program in all-stop mode, and a stop reply
42856for each stopped thread in non-stop mode.
42857Interrupts received while the
42858program is stopped are queued and the program will be interrupted when
42859it is resumed next time.
42860
42861@node Notification Packets
42862@section Notification Packets
42863@cindex notification packets
42864@cindex packets, notification
42865
42866The @value{GDBN} remote serial protocol includes @dfn{notifications},
42867packets that require no acknowledgment.  Both the GDB and the stub
42868may send notifications (although the only notifications defined at
42869present are sent by the stub).  Notifications carry information
42870without incurring the round-trip latency of an acknowledgment, and so
42871are useful for low-impact communications where occasional packet loss
42872is not a problem.
42873
42874A notification packet has the form @samp{% @var{data} #
42875@var{checksum}}, where @var{data} is the content of the notification,
42876and @var{checksum} is a checksum of @var{data}, computed and formatted
42877as for ordinary @value{GDBN} packets.  A notification's @var{data}
42878never contains @samp{$}, @samp{%} or @samp{#} characters.  Upon
42879receiving a notification, the recipient sends no @samp{+} or @samp{-}
42880to acknowledge the notification's receipt or to report its corruption.
42881
42882Every notification's @var{data} begins with a name, which contains no
42883colon characters, followed by a colon character.
42884
42885Recipients should silently ignore corrupted notifications and
42886notifications they do not understand.  Recipients should restart
42887timeout periods on receipt of a well-formed notification, whether or
42888not they understand it.
42889
42890Senders should only send the notifications described here when this
42891protocol description specifies that they are permitted.  In the
42892future, we may extend the protocol to permit existing notifications in
42893new contexts; this rule helps older senders avoid confusing newer
42894recipients.
42895
42896(Older versions of @value{GDBN} ignore bytes received until they see
42897the @samp{$} byte that begins an ordinary packet, so new stubs may
42898transmit notifications without fear of confusing older clients.  There
42899are no notifications defined for @value{GDBN} to send at the moment, but we
42900assume that most older stubs would ignore them, as well.)
42901
42902Each notification is comprised of three parts:
42903@table @samp
42904@item @var{name}:@var{event}
42905The notification packet is sent by the side that initiates the
42906exchange (currently, only the stub does that), with @var{event}
42907carrying the specific information about the notification, and
42908@var{name} specifying the name of the notification.
42909@item @var{ack}
42910The acknowledge sent by the other side, usually @value{GDBN}, to
42911acknowledge the exchange and request the event.
42912@end table
42913
42914The purpose of an asynchronous notification mechanism is to report to
42915@value{GDBN} that something interesting happened in the remote stub.
42916
42917The remote stub may send notification @var{name}:@var{event}
42918at any time, but @value{GDBN} acknowledges the notification when
42919appropriate.  The notification event is pending before @value{GDBN}
42920acknowledges.  Only one notification at a time may be pending; if
42921additional events occur before @value{GDBN} has acknowledged the
42922previous notification, they must be queued by the stub for later
42923synchronous transmission in response to @var{ack} packets from
42924@value{GDBN}.  Because the notification mechanism is unreliable,
42925the stub is permitted to resend a notification if it believes
42926@value{GDBN} may not have received it.
42927
42928Specifically, notifications may appear when @value{GDBN} is not
42929otherwise reading input from the stub, or when @value{GDBN} is
42930expecting to read a normal synchronous response or a
42931@samp{+}/@samp{-} acknowledgment to a packet it has sent.
42932Notification packets are distinct from any other communication from
42933the stub so there is no ambiguity.
42934
42935After receiving a notification, @value{GDBN} shall acknowledge it by
42936sending a @var{ack} packet as a regular, synchronous request to the
42937stub.  Such acknowledgment is not required to happen immediately, as
42938@value{GDBN} is permitted to send other, unrelated packets to the
42939stub first, which the stub should process normally.
42940
42941Upon receiving a @var{ack} packet, if the stub has other queued
42942events to report to @value{GDBN}, it shall respond by sending a
42943normal @var{event}.  @value{GDBN} shall then send another @var{ack}
42944packet to solicit further responses; again, it is permitted to send
42945other, unrelated packets as well which the stub should process
42946normally.
42947
42948If the stub receives a @var{ack} packet and there are no additional
42949@var{event} to report, the stub shall return an @samp{OK} response.
42950At this point, @value{GDBN} has finished processing a notification
42951and the stub has completed sending any queued events.  @value{GDBN}
42952won't accept any new notifications until the final @samp{OK} is
42953received .  If further notification events occur, the stub shall send
42954a new notification, @value{GDBN} shall accept the notification, and
42955the process shall be repeated.
42956
42957The process of asynchronous notification can be illustrated by the
42958following example:
42959@smallexample
42960<- @code{%Stop:T0505:98e7ffbf;04:4ce6ffbf;08:b1b6e54c;thread:p7526.7526;core:0;}
42961@code{...}
42962-> @code{vStopped}
42963<- @code{T0505:68f37db7;04:40f37db7;08:63850408;thread:p7526.7528;core:0;}
42964-> @code{vStopped}
42965<- @code{T0505:68e3fdb6;04:40e3fdb6;08:63850408;thread:p7526.7529;core:0;}
42966-> @code{vStopped}
42967<- @code{OK}
42968@end smallexample
42969
42970The following notifications are defined:
42971@multitable @columnfractions 0.12 0.12 0.38 0.38
42972
42973@item Notification
42974@tab Ack
42975@tab Event
42976@tab Description
42977
42978@item Stop
42979@tab vStopped
42980@tab @var{reply}.  The @var{reply} has the form of a stop reply, as
42981described in @ref{Stop Reply Packets}.  Refer to @ref{Remote Non-Stop},
42982for information on how these notifications are acknowledged by
42983@value{GDBN}.
42984@tab Report an asynchronous stop event in non-stop mode.
42985
42986@end multitable
42987
42988@node Remote Non-Stop
42989@section Remote Protocol Support for Non-Stop Mode
42990
42991@value{GDBN}'s remote protocol supports non-stop debugging of
42992multi-threaded programs, as described in @ref{Non-Stop Mode}.  If the stub
42993supports non-stop mode, it should report that to @value{GDBN} by including
42994@samp{QNonStop+} in its @samp{qSupported} response (@pxref{qSupported}).
42995
42996@value{GDBN} typically sends a @samp{QNonStop} packet only when
42997establishing a new connection with the stub.  Entering non-stop mode
42998does not alter the state of any currently-running threads, but targets
42999must stop all threads in any already-attached processes when entering
43000all-stop mode.  @value{GDBN} uses the @samp{?} packet as necessary to
43001probe the target state after a mode change.
43002
43003In non-stop mode, when an attached process encounters an event that
43004would otherwise be reported with a stop reply, it uses the
43005asynchronous notification mechanism (@pxref{Notification Packets}) to
43006inform @value{GDBN}.  In contrast to all-stop mode, where all threads
43007in all processes are stopped when a stop reply is sent, in non-stop
43008mode only the thread reporting the stop event is stopped.  That is,
43009when reporting a @samp{S} or @samp{T} response to indicate completion
43010of a step operation, hitting a breakpoint, or a fault, only the
43011affected thread is stopped; any other still-running threads continue
43012to run.  When reporting a @samp{W} or @samp{X} response, all running
43013threads belonging to other attached processes continue to run.
43014
43015In non-stop mode, the target shall respond to the @samp{?} packet as
43016follows.  First, any incomplete stop reply notification/@samp{vStopped}
43017sequence in progress is abandoned.  The target must begin a new
43018sequence reporting stop events for all stopped threads, whether or not
43019it has previously reported those events to @value{GDBN}.  The first
43020stop reply is sent as a synchronous reply to the @samp{?} packet, and
43021subsequent stop replies are sent as responses to @samp{vStopped} packets
43022using the mechanism described above.  The target must not send
43023asynchronous stop reply notifications until the sequence is complete.
43024If all threads are running when the target receives the @samp{?} packet,
43025or if the target is not attached to any process, it shall respond
43026@samp{OK}.
43027
43028If the stub supports non-stop mode, it should also support the
43029@samp{swbreak} stop reason if software breakpoints are supported, and
43030the @samp{hwbreak} stop reason if hardware breakpoints are supported
43031(@pxref{swbreak stop reason}).  This is because given the asynchronous
43032nature of non-stop mode, between the time a thread hits a breakpoint
43033and the time the event is finally processed by @value{GDBN}, the
43034breakpoint may have already been removed from the target.  Due to
43035this, @value{GDBN} needs to be able to tell whether a trap stop was
43036caused by a delayed breakpoint event, which should be ignored, as
43037opposed to a random trap signal, which should be reported to the user.
43038Note the @samp{swbreak} feature implies that the target is responsible
43039for adjusting the PC when a software breakpoint triggers, if
43040necessary, such as on the x86 architecture.
43041
43042@node Packet Acknowledgment
43043@section Packet Acknowledgment
43044
43045@cindex acknowledgment, for @value{GDBN} remote
43046@cindex packet acknowledgment, for @value{GDBN} remote
43047By default, when either the host or the target machine receives a packet,
43048the first response expected is an acknowledgment: either @samp{+} (to indicate
43049the package was received correctly) or @samp{-} (to request retransmission).
43050This mechanism allows the @value{GDBN} remote protocol to operate over
43051unreliable transport mechanisms, such as a serial line.
43052
43053In cases where the transport mechanism is itself reliable (such as a pipe or
43054TCP connection), the @samp{+}/@samp{-} acknowledgments are redundant.
43055It may be desirable to disable them in that case to reduce communication
43056overhead, or for other reasons.  This can be accomplished by means of the
43057@samp{QStartNoAckMode} packet; @pxref{QStartNoAckMode}.
43058
43059When in no-acknowledgment mode, neither the stub nor @value{GDBN} shall send or
43060expect @samp{+}/@samp{-} protocol acknowledgments.  The packet
43061and response format still includes the normal checksum, as described in
43062@ref{Overview}, but the checksum may be ignored by the receiver.
43063
43064If the stub supports @samp{QStartNoAckMode} and prefers to operate in
43065no-acknowledgment mode, it should report that to @value{GDBN}
43066by including @samp{QStartNoAckMode+} in its response to @samp{qSupported};
43067@pxref{qSupported}.
43068If @value{GDBN} also supports @samp{QStartNoAckMode} and it has not been
43069disabled via the @code{set remote noack-packet off} command
43070(@pxref{Remote Configuration}),
43071@value{GDBN} may then send a @samp{QStartNoAckMode} packet to the stub.
43072Only then may the stub actually turn off packet acknowledgments.
43073@value{GDBN} sends a final @samp{+} acknowledgment of the stub's @samp{OK}
43074response, which can be safely ignored by the stub.
43075
43076Note that @code{set remote noack-packet} command only affects negotiation
43077between @value{GDBN} and the stub when subsequent connections are made;
43078it does not affect the protocol acknowledgment state for any current
43079connection.
43080Since @samp{+}/@samp{-} acknowledgments are enabled by default when a
43081new connection is established,
43082there is also no protocol request to re-enable the acknowledgments
43083for the current connection, once disabled.
43084
43085@node Examples
43086@section Examples
43087
43088Example sequence of a target being re-started.  Notice how the restart
43089does not get any direct output:
43090
43091@smallexample
43092-> @code{R00}
43093<- @code{+}
43094@emph{target restarts}
43095-> @code{?}
43096<- @code{+}
43097<- @code{T001:1234123412341234}
43098-> @code{+}
43099@end smallexample
43100
43101Example sequence of a target being stepped by a single instruction:
43102
43103@smallexample
43104-> @code{G1445@dots{}}
43105<- @code{+}
43106-> @code{s}
43107<- @code{+}
43108@emph{time passes}
43109<- @code{T001:1234123412341234}
43110-> @code{+}
43111-> @code{g}
43112<- @code{+}
43113<- @code{1455@dots{}}
43114-> @code{+}
43115@end smallexample
43116
43117@node File-I/O Remote Protocol Extension
43118@section File-I/O Remote Protocol Extension
43119@cindex File-I/O remote protocol extension
43120
43121@menu
43122* File-I/O Overview::
43123* Protocol Basics::
43124* The F Request Packet::
43125* The F Reply Packet::
43126* The Ctrl-C Message::
43127* Console I/O::
43128* List of Supported Calls::
43129* Protocol-specific Representation of Datatypes::
43130* Constants::
43131* File-I/O Examples::
43132@end menu
43133
43134@node File-I/O Overview
43135@subsection File-I/O Overview
43136@cindex file-i/o overview
43137
43138The @dfn{File I/O remote protocol extension} (short: File-I/O) allows the
43139target to use the host's file system and console I/O to perform various
43140system calls.  System calls on the target system are translated into a
43141remote protocol packet to the host system, which then performs the needed
43142actions and returns a response packet to the target system.
43143This simulates file system operations even on targets that lack file systems.
43144
43145The protocol is defined to be independent of both the host and target systems.
43146It uses its own internal representation of datatypes and values.  Both
43147@value{GDBN} and the target's @value{GDBN} stub are responsible for
43148translating the system-dependent value representations into the internal
43149protocol representations when data is transmitted.
43150
43151The communication is synchronous.  A system call is possible only when
43152@value{GDBN} is waiting for a response from the @samp{C}, @samp{c}, @samp{S}
43153or @samp{s} packets.  While @value{GDBN} handles the request for a system call,
43154the target is stopped to allow deterministic access to the target's
43155memory.  Therefore File-I/O is not interruptible by target signals.  On
43156the other hand, it is possible to interrupt File-I/O by a user interrupt
43157(@samp{Ctrl-C}) within @value{GDBN}.
43158
43159The target's request to perform a host system call does not finish
43160the latest @samp{C}, @samp{c}, @samp{S} or @samp{s} action.  That means,
43161after finishing the system call, the target returns to continuing the
43162previous activity (continue, step).  No additional continue or step
43163request from @value{GDBN} is required.
43164
43165@smallexample
43166(@value{GDBP}) continue
43167  <- target requests 'system call X'
43168  target is stopped, @value{GDBN} executes system call
43169  -> @value{GDBN} returns result
43170  ... target continues, @value{GDBN} returns to wait for the target
43171  <- target hits breakpoint and sends a Txx packet
43172@end smallexample
43173
43174The protocol only supports I/O on the console and to regular files on
43175the host file system.  Character or block special devices, pipes,
43176named pipes, sockets or any other communication method on the host
43177system are not supported by this protocol.
43178
43179File I/O is not supported in non-stop mode.
43180
43181@node Protocol Basics
43182@subsection Protocol Basics
43183@cindex protocol basics, file-i/o
43184
43185The File-I/O protocol uses the @code{F} packet as the request as well
43186as reply packet.  Since a File-I/O system call can only occur when
43187@value{GDBN} is waiting for a response from the continuing or stepping target,
43188the File-I/O request is a reply that @value{GDBN} has to expect as a result
43189of a previous @samp{C}, @samp{c}, @samp{S} or @samp{s} packet.
43190This @code{F} packet contains all information needed to allow @value{GDBN}
43191to call the appropriate host system call:
43192
43193@itemize @bullet
43194@item
43195A unique identifier for the requested system call.
43196
43197@item
43198All parameters to the system call.  Pointers are given as addresses
43199in the target memory address space.  Pointers to strings are given as
43200pointer/length pair.  Numerical values are given as they are.
43201Numerical control flags are given in a protocol-specific representation.
43202
43203@end itemize
43204
43205At this point, @value{GDBN} has to perform the following actions.
43206
43207@itemize @bullet
43208@item
43209If the parameters include pointer values to data needed as input to a
43210system call, @value{GDBN} requests this data from the target with a
43211standard @code{m} packet request.  This additional communication has to be
43212expected by the target implementation and is handled as any other @code{m}
43213packet.
43214
43215@item
43216@value{GDBN} translates all value from protocol representation to host
43217representation as needed.  Datatypes are coerced into the host types.
43218
43219@item
43220@value{GDBN} calls the system call.
43221
43222@item
43223It then coerces datatypes back to protocol representation.
43224
43225@item
43226If the system call is expected to return data in buffer space specified
43227by pointer parameters to the call, the data is transmitted to the
43228target using a @code{M} or @code{X} packet.  This packet has to be expected
43229by the target implementation and is handled as any other @code{M} or @code{X}
43230packet.
43231
43232@end itemize
43233
43234Eventually @value{GDBN} replies with another @code{F} packet which contains all
43235necessary information for the target to continue.  This at least contains
43236
43237@itemize @bullet
43238@item
43239Return value.
43240
43241@item
43242@code{errno}, if has been changed by the system call.
43243
43244@item
43245``Ctrl-C'' flag.
43246
43247@end itemize
43248
43249After having done the needed type and value coercion, the target continues
43250the latest continue or step action.
43251
43252@node The F Request Packet
43253@subsection The @code{F} Request Packet
43254@cindex file-i/o request packet
43255@cindex @code{F} request packet
43256
43257The @code{F} request packet has the following format:
43258
43259@table @samp
43260@item F@var{call-id},@var{parameter@dots{}}
43261
43262@var{call-id} is the identifier to indicate the host system call to be called.
43263This is just the name of the function.
43264
43265@var{parameter@dots{}} are the parameters to the system call.
43266Parameters are hexadecimal integer values, either the actual values in case
43267of scalar datatypes, pointers to target buffer space in case of compound
43268datatypes and unspecified memory areas, or pointer/length pairs in case
43269of string parameters.  These are appended to the @var{call-id} as a
43270comma-delimited list.  All values are transmitted in ASCII
43271string representation, pointer/length pairs separated by a slash.
43272
43273@end table
43274
43275
43276
43277@node The F Reply Packet
43278@subsection The @code{F} Reply Packet
43279@cindex file-i/o reply packet
43280@cindex @code{F} reply packet
43281
43282The @code{F} reply packet has the following format:
43283
43284@table @samp
43285
43286@item F@var{retcode},@var{errno},@var{Ctrl-C flag};@var{call-specific attachment}
43287
43288@var{retcode} is the return code of the system call as hexadecimal value.
43289
43290@var{errno} is the @code{errno} set by the call, in protocol-specific
43291representation.
43292This parameter can be omitted if the call was successful.
43293
43294@var{Ctrl-C flag} is only sent if the user requested a break.  In this
43295case, @var{errno} must be sent as well, even if the call was successful.
43296The @var{Ctrl-C flag} itself consists of the character @samp{C}:
43297
43298@smallexample
43299F0,0,C
43300@end smallexample
43301
43302@noindent
43303or, if the call was interrupted before the host call has been performed:
43304
43305@smallexample
43306F-1,4,C
43307@end smallexample
43308
43309@noindent
43310assuming 4 is the protocol-specific representation of @code{EINTR}.
43311
43312@end table
43313
43314
43315@node The Ctrl-C Message
43316@subsection The @samp{Ctrl-C} Message
43317@cindex ctrl-c message, in file-i/o protocol
43318
43319If the @samp{Ctrl-C} flag is set in the @value{GDBN}
43320reply packet (@pxref{The F Reply Packet}),
43321the target should behave as if it had
43322gotten a break message.  The meaning for the target is ``system call
43323interrupted by @code{SIGINT}''.  Consequentially, the target should actually stop
43324(as with a break message) and return to @value{GDBN} with a @code{T02}
43325packet.
43326
43327It's important for the target to know in which
43328state the system call was interrupted.  There are two possible cases:
43329
43330@itemize @bullet
43331@item
43332The system call hasn't been performed on the host yet.
43333
43334@item
43335The system call on the host has been finished.
43336
43337@end itemize
43338
43339These two states can be distinguished by the target by the value of the
43340returned @code{errno}.  If it's the protocol representation of @code{EINTR}, the system
43341call hasn't been performed.  This is equivalent to the @code{EINTR} handling
43342on POSIX systems.  In any other case, the target may presume that the
43343system call has been finished --- successfully or not --- and should behave
43344as if the break message arrived right after the system call.
43345
43346@value{GDBN} must behave reliably.  If the system call has not been called
43347yet, @value{GDBN} may send the @code{F} reply immediately, setting @code{EINTR} as
43348@code{errno} in the packet.  If the system call on the host has been finished
43349before the user requests a break, the full action must be finished by
43350@value{GDBN}.  This requires sending @code{M} or @code{X} packets as necessary.
43351The @code{F} packet may only be sent when either nothing has happened
43352or the full action has been completed.
43353
43354@node Console I/O
43355@subsection Console I/O
43356@cindex console i/o as part of file-i/o
43357
43358By default and if not explicitly closed by the target system, the file
43359descriptors 0, 1 and 2 are connected to the @value{GDBN} console.  Output
43360on the @value{GDBN} console is handled as any other file output operation
43361(@code{write(1, @dots{})} or @code{write(2, @dots{})}).  Console input is handled
43362by @value{GDBN} so that after the target read request from file descriptor
433630 all following typing is buffered until either one of the following
43364conditions is met:
43365
43366@itemize @bullet
43367@item
43368The user types @kbd{Ctrl-c}.  The behaviour is as explained above, and the
43369@code{read}
43370system call is treated as finished.
43371
43372@item
43373The user presses @key{RET}.  This is treated as end of input with a trailing
43374newline.
43375
43376@item
43377The user types @kbd{Ctrl-d}.  This is treated as end of input.  No trailing
43378character (neither newline nor @samp{Ctrl-D}) is appended to the input.
43379
43380@end itemize
43381
43382If the user has typed more characters than fit in the buffer given to
43383the @code{read} call, the trailing characters are buffered in @value{GDBN} until
43384either another @code{read(0, @dots{})} is requested by the target, or debugging
43385is stopped at the user's request.
43386
43387
43388@node List of Supported Calls
43389@subsection List of Supported Calls
43390@cindex list of supported file-i/o calls
43391
43392@menu
43393* open::
43394* close::
43395* read::
43396* write::
43397* lseek::
43398* rename::
43399* unlink::
43400* stat/fstat::
43401* gettimeofday::
43402* isatty::
43403* system::
43404@end menu
43405
43406@node open
43407@unnumberedsubsubsec open
43408@cindex open, file-i/o system call
43409
43410@table @asis
43411@item Synopsis:
43412@smallexample
43413int open(const char *pathname, int flags);
43414int open(const char *pathname, int flags, mode_t mode);
43415@end smallexample
43416
43417@item Request:
43418@samp{Fopen,@var{pathptr}/@var{len},@var{flags},@var{mode}}
43419
43420@noindent
43421@var{flags} is the bitwise @code{OR} of the following values:
43422
43423@table @code
43424@item O_CREAT
43425If the file does not exist it will be created.  The host
43426rules apply as far as file ownership and time stamps
43427are concerned.
43428
43429@item O_EXCL
43430When used with @code{O_CREAT}, if the file already exists it is
43431an error and open() fails.
43432
43433@item O_TRUNC
43434If the file already exists and the open mode allows
43435writing (@code{O_RDWR} or @code{O_WRONLY} is given) it will be
43436truncated to zero length.
43437
43438@item O_APPEND
43439The file is opened in append mode.
43440
43441@item O_RDONLY
43442The file is opened for reading only.
43443
43444@item O_WRONLY
43445The file is opened for writing only.
43446
43447@item O_RDWR
43448The file is opened for reading and writing.
43449@end table
43450
43451@noindent
43452Other bits are silently ignored.
43453
43454
43455@noindent
43456@var{mode} is the bitwise @code{OR} of the following values:
43457
43458@table @code
43459@item S_IRUSR
43460User has read permission.
43461
43462@item S_IWUSR
43463User has write permission.
43464
43465@item S_IRGRP
43466Group has read permission.
43467
43468@item S_IWGRP
43469Group has write permission.
43470
43471@item S_IROTH
43472Others have read permission.
43473
43474@item S_IWOTH
43475Others have write permission.
43476@end table
43477
43478@noindent
43479Other bits are silently ignored.
43480
43481
43482@item Return value:
43483@code{open} returns the new file descriptor or -1 if an error
43484occurred.
43485
43486@item Errors:
43487
43488@table @code
43489@item EEXIST
43490@var{pathname} already exists and @code{O_CREAT} and @code{O_EXCL} were used.
43491
43492@item EISDIR
43493@var{pathname} refers to a directory.
43494
43495@item EACCES
43496The requested access is not allowed.
43497
43498@item ENAMETOOLONG
43499@var{pathname} was too long.
43500
43501@item ENOENT
43502A directory component in @var{pathname} does not exist.
43503
43504@item ENODEV
43505@var{pathname} refers to a device, pipe, named pipe or socket.
43506
43507@item EROFS
43508@var{pathname} refers to a file on a read-only filesystem and
43509write access was requested.
43510
43511@item EFAULT
43512@var{pathname} is an invalid pointer value.
43513
43514@item ENOSPC
43515No space on device to create the file.
43516
43517@item EMFILE
43518The process already has the maximum number of files open.
43519
43520@item ENFILE
43521The limit on the total number of files open on the system
43522has been reached.
43523
43524@item EINTR
43525The call was interrupted by the user.
43526@end table
43527
43528@end table
43529
43530@node close
43531@unnumberedsubsubsec close
43532@cindex close, file-i/o system call
43533
43534@table @asis
43535@item Synopsis:
43536@smallexample
43537int close(int fd);
43538@end smallexample
43539
43540@item Request:
43541@samp{Fclose,@var{fd}}
43542
43543@item Return value:
43544@code{close} returns zero on success, or -1 if an error occurred.
43545
43546@item Errors:
43547
43548@table @code
43549@item EBADF
43550@var{fd} isn't a valid open file descriptor.
43551
43552@item EINTR
43553The call was interrupted by the user.
43554@end table
43555
43556@end table
43557
43558@node read
43559@unnumberedsubsubsec read
43560@cindex read, file-i/o system call
43561
43562@table @asis
43563@item Synopsis:
43564@smallexample
43565int read(int fd, void *buf, unsigned int count);
43566@end smallexample
43567
43568@item Request:
43569@samp{Fread,@var{fd},@var{bufptr},@var{count}}
43570
43571@item Return value:
43572On success, the number of bytes read is returned.
43573Zero indicates end of file.  If count is zero, read
43574returns zero as well.  On error, -1 is returned.
43575
43576@item Errors:
43577
43578@table @code
43579@item EBADF
43580@var{fd} is not a valid file descriptor or is not open for
43581reading.
43582
43583@item EFAULT
43584@var{bufptr} is an invalid pointer value.
43585
43586@item EINTR
43587The call was interrupted by the user.
43588@end table
43589
43590@end table
43591
43592@node write
43593@unnumberedsubsubsec write
43594@cindex write, file-i/o system call
43595
43596@table @asis
43597@item Synopsis:
43598@smallexample
43599int write(int fd, const void *buf, unsigned int count);
43600@end smallexample
43601
43602@item Request:
43603@samp{Fwrite,@var{fd},@var{bufptr},@var{count}}
43604
43605@item Return value:
43606On success, the number of bytes written are returned.
43607Zero indicates nothing was written.  On error, -1
43608is returned.
43609
43610@item Errors:
43611
43612@table @code
43613@item EBADF
43614@var{fd} is not a valid file descriptor or is not open for
43615writing.
43616
43617@item EFAULT
43618@var{bufptr} is an invalid pointer value.
43619
43620@item EFBIG
43621An attempt was made to write a file that exceeds the
43622host-specific maximum file size allowed.
43623
43624@item ENOSPC
43625No space on device to write the data.
43626
43627@item EINTR
43628The call was interrupted by the user.
43629@end table
43630
43631@end table
43632
43633@node lseek
43634@unnumberedsubsubsec lseek
43635@cindex lseek, file-i/o system call
43636
43637@table @asis
43638@item Synopsis:
43639@smallexample
43640long lseek (int fd, long offset, int flag);
43641@end smallexample
43642
43643@item Request:
43644@samp{Flseek,@var{fd},@var{offset},@var{flag}}
43645
43646@var{flag} is one of:
43647
43648@table @code
43649@item SEEK_SET
43650The offset is set to @var{offset} bytes.
43651
43652@item SEEK_CUR
43653The offset is set to its current location plus @var{offset}
43654bytes.
43655
43656@item SEEK_END
43657The offset is set to the size of the file plus @var{offset}
43658bytes.
43659@end table
43660
43661@item Return value:
43662On success, the resulting unsigned offset in bytes from
43663the beginning of the file is returned.  Otherwise, a
43664value of -1 is returned.
43665
43666@item Errors:
43667
43668@table @code
43669@item EBADF
43670@var{fd} is not a valid open file descriptor.
43671
43672@item ESPIPE
43673@var{fd} is associated with the @value{GDBN} console.
43674
43675@item EINVAL
43676@var{flag} is not a proper value.
43677
43678@item EINTR
43679The call was interrupted by the user.
43680@end table
43681
43682@end table
43683
43684@node rename
43685@unnumberedsubsubsec rename
43686@cindex rename, file-i/o system call
43687
43688@table @asis
43689@item Synopsis:
43690@smallexample
43691int rename(const char *oldpath, const char *newpath);
43692@end smallexample
43693
43694@item Request:
43695@samp{Frename,@var{oldpathptr}/@var{len},@var{newpathptr}/@var{len}}
43696
43697@item Return value:
43698On success, zero is returned.  On error, -1 is returned.
43699
43700@item Errors:
43701
43702@table @code
43703@item EISDIR
43704@var{newpath} is an existing directory, but @var{oldpath} is not a
43705directory.
43706
43707@item EEXIST
43708@var{newpath} is a non-empty directory.
43709
43710@item EBUSY
43711@var{oldpath} or @var{newpath} is a directory that is in use by some
43712process.
43713
43714@item EINVAL
43715An attempt was made to make a directory a subdirectory
43716of itself.
43717
43718@item ENOTDIR
43719A  component used as a directory in @var{oldpath} or new
43720path is not a directory.  Or @var{oldpath} is a directory
43721and @var{newpath} exists but is not a directory.
43722
43723@item EFAULT
43724@var{oldpathptr} or @var{newpathptr} are invalid pointer values.
43725
43726@item EACCES
43727No access to the file or the path of the file.
43728
43729@item ENAMETOOLONG
43730
43731@var{oldpath} or @var{newpath} was too long.
43732
43733@item ENOENT
43734A directory component in @var{oldpath} or @var{newpath} does not exist.
43735
43736@item EROFS
43737The file is on a read-only filesystem.
43738
43739@item ENOSPC
43740The device containing the file has no room for the new
43741directory entry.
43742
43743@item EINTR
43744The call was interrupted by the user.
43745@end table
43746
43747@end table
43748
43749@node unlink
43750@unnumberedsubsubsec unlink
43751@cindex unlink, file-i/o system call
43752
43753@table @asis
43754@item Synopsis:
43755@smallexample
43756int unlink(const char *pathname);
43757@end smallexample
43758
43759@item Request:
43760@samp{Funlink,@var{pathnameptr}/@var{len}}
43761
43762@item Return value:
43763On success, zero is returned.  On error, -1 is returned.
43764
43765@item Errors:
43766
43767@table @code
43768@item EACCES
43769No access to the file or the path of the file.
43770
43771@item EPERM
43772The system does not allow unlinking of directories.
43773
43774@item EBUSY
43775The file @var{pathname} cannot be unlinked because it's
43776being used by another process.
43777
43778@item EFAULT
43779@var{pathnameptr} is an invalid pointer value.
43780
43781@item ENAMETOOLONG
43782@var{pathname} was too long.
43783
43784@item ENOENT
43785A directory component in @var{pathname} does not exist.
43786
43787@item ENOTDIR
43788A component of the path is not a directory.
43789
43790@item EROFS
43791The file is on a read-only filesystem.
43792
43793@item EINTR
43794The call was interrupted by the user.
43795@end table
43796
43797@end table
43798
43799@node stat/fstat
43800@unnumberedsubsubsec stat/fstat
43801@cindex fstat, file-i/o system call
43802@cindex stat, file-i/o system call
43803
43804@table @asis
43805@item Synopsis:
43806@smallexample
43807int stat(const char *pathname, struct stat *buf);
43808int fstat(int fd, struct stat *buf);
43809@end smallexample
43810
43811@item Request:
43812@samp{Fstat,@var{pathnameptr}/@var{len},@var{bufptr}}@*
43813@samp{Ffstat,@var{fd},@var{bufptr}}
43814
43815@item Return value:
43816On success, zero is returned.  On error, -1 is returned.
43817
43818@item Errors:
43819
43820@table @code
43821@item EBADF
43822@var{fd} is not a valid open file.
43823
43824@item ENOENT
43825A directory component in @var{pathname} does not exist or the
43826path is an empty string.
43827
43828@item ENOTDIR
43829A component of the path is not a directory.
43830
43831@item EFAULT
43832@var{pathnameptr} is an invalid pointer value.
43833
43834@item EACCES
43835No access to the file or the path of the file.
43836
43837@item ENAMETOOLONG
43838@var{pathname} was too long.
43839
43840@item EINTR
43841The call was interrupted by the user.
43842@end table
43843
43844@end table
43845
43846@node gettimeofday
43847@unnumberedsubsubsec gettimeofday
43848@cindex gettimeofday, file-i/o system call
43849
43850@table @asis
43851@item Synopsis:
43852@smallexample
43853int gettimeofday(struct timeval *tv, void *tz);
43854@end smallexample
43855
43856@item Request:
43857@samp{Fgettimeofday,@var{tvptr},@var{tzptr}}
43858
43859@item Return value:
43860On success, 0 is returned, -1 otherwise.
43861
43862@item Errors:
43863
43864@table @code
43865@item EINVAL
43866@var{tz} is a non-NULL pointer.
43867
43868@item EFAULT
43869@var{tvptr} and/or @var{tzptr} is an invalid pointer value.
43870@end table
43871
43872@end table
43873
43874@node isatty
43875@unnumberedsubsubsec isatty
43876@cindex isatty, file-i/o system call
43877
43878@table @asis
43879@item Synopsis:
43880@smallexample
43881int isatty(int fd);
43882@end smallexample
43883
43884@item Request:
43885@samp{Fisatty,@var{fd}}
43886
43887@item Return value:
43888Returns 1 if @var{fd} refers to the @value{GDBN} console, 0 otherwise.
43889
43890@item Errors:
43891
43892@table @code
43893@item EINTR
43894The call was interrupted by the user.
43895@end table
43896
43897@end table
43898
43899Note that the @code{isatty} call is treated as a special case: it returns
439001 to the target if the file descriptor is attached
43901to the @value{GDBN} console, 0 otherwise.  Implementing through system calls
43902would require implementing @code{ioctl} and would be more complex than
43903needed.
43904
43905
43906@node system
43907@unnumberedsubsubsec system
43908@cindex system, file-i/o system call
43909
43910@table @asis
43911@item Synopsis:
43912@smallexample
43913int system(const char *command);
43914@end smallexample
43915
43916@item Request:
43917@samp{Fsystem,@var{commandptr}/@var{len}}
43918
43919@item Return value:
43920If @var{len} is zero, the return value indicates whether a shell is
43921available.  A zero return value indicates a shell is not available.
43922For non-zero @var{len}, the value returned is -1 on error and the
43923return status of the command otherwise.  Only the exit status of the
43924command is returned, which is extracted from the host's @code{system}
43925return value by calling @code{WEXITSTATUS(retval)}.  In case
43926@file{/bin/sh} could not be executed, 127 is returned.
43927
43928@item Errors:
43929
43930@table @code
43931@item EINTR
43932The call was interrupted by the user.
43933@end table
43934
43935@end table
43936
43937@value{GDBN} takes over the full task of calling the necessary host calls
43938to perform the @code{system} call.  The return value of @code{system} on
43939the host is simplified before it's returned
43940to the target.  Any termination signal information from the child process
43941is discarded, and the return value consists
43942entirely of the exit status of the called command.
43943
43944Due to security concerns, the @code{system} call is by default refused
43945by @value{GDBN}.  The user has to allow this call explicitly with the
43946@code{set remote system-call-allowed 1} command.
43947
43948@table @code
43949@item set remote system-call-allowed
43950@kindex set remote system-call-allowed
43951Control whether to allow the @code{system} calls in the File I/O
43952protocol for the remote target.  The default is zero (disabled).
43953
43954@item show remote system-call-allowed
43955@kindex show remote system-call-allowed
43956Show whether the @code{system} calls are allowed in the File I/O
43957protocol.
43958@end table
43959
43960@node Protocol-specific Representation of Datatypes
43961@subsection Protocol-specific Representation of Datatypes
43962@cindex protocol-specific representation of datatypes, in file-i/o protocol
43963
43964@menu
43965* Integral Datatypes::
43966* Pointer Values::
43967* Memory Transfer::
43968* struct stat::
43969* struct timeval::
43970@end menu
43971
43972@node Integral Datatypes
43973@unnumberedsubsubsec Integral Datatypes
43974@cindex integral datatypes, in file-i/o protocol
43975
43976The integral datatypes used in the system calls are @code{int},
43977@code{unsigned int}, @code{long}, @code{unsigned long},
43978@code{mode_t}, and @code{time_t}.
43979
43980@code{int}, @code{unsigned int}, @code{mode_t} and @code{time_t} are
43981implemented as 32 bit values in this protocol.
43982
43983@code{long} and @code{unsigned long} are implemented as 64 bit types.
43984
43985@xref{Limits}, for corresponding MIN and MAX values (similar to those
43986in @file{limits.h}) to allow range checking on host and target.
43987
43988@code{time_t} datatypes are defined as seconds since the Epoch.
43989
43990All integral datatypes transferred as part of a memory read or write of a
43991structured datatype e.g.@: a @code{struct stat} have to be given in big endian
43992byte order.
43993
43994@node Pointer Values
43995@unnumberedsubsubsec Pointer Values
43996@cindex pointer values, in file-i/o protocol
43997
43998Pointers to target data are transmitted as they are.  An exception
43999is made for pointers to buffers for which the length isn't
44000transmitted as part of the function call, namely strings.  Strings
44001are transmitted as a pointer/length pair, both as hex values, e.g.@:
44002
44003@smallexample
44004@code{1aaf/12}
44005@end smallexample
44006
44007@noindent
44008which is a pointer to data of length 18 bytes at position 0x1aaf.
44009The length is defined as the full string length in bytes, including
44010the trailing null byte.  For example, the string @code{"hello world"}
44011at address 0x123456 is transmitted as
44012
44013@smallexample
44014@code{123456/d}
44015@end smallexample
44016
44017@node Memory Transfer
44018@unnumberedsubsubsec Memory Transfer
44019@cindex memory transfer, in file-i/o protocol
44020
44021Structured data which is transferred using a memory read or write (for
44022example, a @code{struct stat}) is expected to be in a protocol-specific format
44023with all scalar multibyte datatypes being big endian.  Translation to
44024this representation needs to be done both by the target before the @code{F}
44025packet is sent, and by @value{GDBN} before
44026it transfers memory to the target.  Transferred pointers to structured
44027data should point to the already-coerced data at any time.
44028
44029
44030@node struct stat
44031@unnumberedsubsubsec struct stat
44032@cindex struct stat, in file-i/o protocol
44033
44034The buffer of type @code{struct stat} used by the target and @value{GDBN}
44035is defined as follows:
44036
44037@smallexample
44038struct stat @{
44039    unsigned int  st_dev;      /* device */
44040    unsigned int  st_ino;      /* inode */
44041    mode_t        st_mode;     /* protection */
44042    unsigned int  st_nlink;    /* number of hard links */
44043    unsigned int  st_uid;      /* user ID of owner */
44044    unsigned int  st_gid;      /* group ID of owner */
44045    unsigned int  st_rdev;     /* device type (if inode device) */
44046    unsigned long st_size;     /* total size, in bytes */
44047    unsigned long st_blksize;  /* blocksize for filesystem I/O */
44048    unsigned long st_blocks;   /* number of blocks allocated */
44049    time_t        st_atime;    /* time of last access */
44050    time_t        st_mtime;    /* time of last modification */
44051    time_t        st_ctime;    /* time of last change */
44052@};
44053@end smallexample
44054
44055The integral datatypes conform to the definitions given in the
44056appropriate section (see @ref{Integral Datatypes}, for details) so this
44057structure is of size 64 bytes.
44058
44059The values of several fields have a restricted meaning and/or
44060range of values.
44061
44062@table @code
44063
44064@item st_dev
44065A value of 0 represents a file, 1 the console.
44066
44067@item st_ino
44068No valid meaning for the target.  Transmitted unchanged.
44069
44070@item st_mode
44071Valid mode bits are described in @ref{Constants}.  Any other
44072bits have currently no meaning for the target.
44073
44074@item st_uid
44075@itemx st_gid
44076@itemx st_rdev
44077No valid meaning for the target.  Transmitted unchanged.
44078
44079@item st_atime
44080@itemx st_mtime
44081@itemx st_ctime
44082These values have a host and file system dependent
44083accuracy.  Especially on Windows hosts, the file system may not
44084support exact timing values.
44085@end table
44086
44087The target gets a @code{struct stat} of the above representation and is
44088responsible for coercing it to the target representation before
44089continuing.
44090
44091Note that due to size differences between the host, target, and protocol
44092representations of @code{struct stat} members, these members could eventually
44093get truncated on the target.
44094
44095@node struct timeval
44096@unnumberedsubsubsec struct timeval
44097@cindex struct timeval, in file-i/o protocol
44098
44099The buffer of type @code{struct timeval} used by the File-I/O protocol
44100is defined as follows:
44101
44102@smallexample
44103struct timeval @{
44104    time_t tv_sec;  /* second */
44105    long   tv_usec; /* microsecond */
44106@};
44107@end smallexample
44108
44109The integral datatypes conform to the definitions given in the
44110appropriate section (see @ref{Integral Datatypes}, for details) so this
44111structure is of size 8 bytes.
44112
44113@node Constants
44114@subsection Constants
44115@cindex constants, in file-i/o protocol
44116
44117The following values are used for the constants inside of the
44118protocol.  @value{GDBN} and target are responsible for translating these
44119values before and after the call as needed.
44120
44121@menu
44122* Open Flags::
44123* mode_t Values::
44124* Errno Values::
44125* Lseek Flags::
44126* Limits::
44127@end menu
44128
44129@node Open Flags
44130@unnumberedsubsubsec Open Flags
44131@cindex open flags, in file-i/o protocol
44132
44133All values are given in hexadecimal representation.
44134
44135@smallexample
44136  O_RDONLY        0x0
44137  O_WRONLY        0x1
44138  O_RDWR          0x2
44139  O_APPEND        0x8
44140  O_CREAT       0x200
44141  O_TRUNC       0x400
44142  O_EXCL        0x800
44143@end smallexample
44144
44145@node mode_t Values
44146@unnumberedsubsubsec mode_t Values
44147@cindex mode_t values, in file-i/o protocol
44148
44149All values are given in octal representation.
44150
44151@smallexample
44152  S_IFREG       0100000
44153  S_IFDIR        040000
44154  S_IRUSR          0400
44155  S_IWUSR          0200
44156  S_IXUSR          0100
44157  S_IRGRP           040
44158  S_IWGRP           020
44159  S_IXGRP           010
44160  S_IROTH            04
44161  S_IWOTH            02
44162  S_IXOTH            01
44163@end smallexample
44164
44165@node Errno Values
44166@unnumberedsubsubsec Errno Values
44167@cindex errno values, in file-i/o protocol
44168
44169All values are given in decimal representation.
44170
44171@smallexample
44172  EPERM           1
44173  ENOENT          2
44174  EINTR           4
44175  EBADF           9
44176  EACCES         13
44177  EFAULT         14
44178  EBUSY          16
44179  EEXIST         17
44180  ENODEV         19
44181  ENOTDIR        20
44182  EISDIR         21
44183  EINVAL         22
44184  ENFILE         23
44185  EMFILE         24
44186  EFBIG          27
44187  ENOSPC         28
44188  ESPIPE         29
44189  EROFS          30
44190  ENAMETOOLONG   91
44191  EUNKNOWN       9999
44192@end smallexample
44193
44194  @code{EUNKNOWN} is used as a fallback error value if a host system returns
44195  any error value not in the list of supported error numbers.
44196
44197@node Lseek Flags
44198@unnumberedsubsubsec Lseek Flags
44199@cindex lseek flags, in file-i/o protocol
44200
44201@smallexample
44202  SEEK_SET      0
44203  SEEK_CUR      1
44204  SEEK_END      2
44205@end smallexample
44206
44207@node Limits
44208@unnumberedsubsubsec Limits
44209@cindex limits, in file-i/o protocol
44210
44211All values are given in decimal representation.
44212
44213@smallexample
44214  INT_MIN       -2147483648
44215  INT_MAX        2147483647
44216  UINT_MAX       4294967295
44217  LONG_MIN      -9223372036854775808
44218  LONG_MAX       9223372036854775807
44219  ULONG_MAX      18446744073709551615
44220@end smallexample
44221
44222@node File-I/O Examples
44223@subsection File-I/O Examples
44224@cindex file-i/o examples
44225
44226Example sequence of a write call, file descriptor 3, buffer is at target
44227address 0x1234, 6 bytes should be written:
44228
44229@smallexample
44230<- @code{Fwrite,3,1234,6}
44231@emph{request memory read from target}
44232-> @code{m1234,6}
44233<- XXXXXX
44234@emph{return "6 bytes written"}
44235-> @code{F6}
44236@end smallexample
44237
44238Example sequence of a read call, file descriptor 3, buffer is at target
44239address 0x1234, 6 bytes should be read:
44240
44241@smallexample
44242<- @code{Fread,3,1234,6}
44243@emph{request memory write to target}
44244-> @code{X1234,6:XXXXXX}
44245@emph{return "6 bytes read"}
44246-> @code{F6}
44247@end smallexample
44248
44249Example sequence of a read call, call fails on the host due to invalid
44250file descriptor (@code{EBADF}):
44251
44252@smallexample
44253<- @code{Fread,3,1234,6}
44254-> @code{F-1,9}
44255@end smallexample
44256
44257Example sequence of a read call, user presses @kbd{Ctrl-c} before syscall on
44258host is called:
44259
44260@smallexample
44261<- @code{Fread,3,1234,6}
44262-> @code{F-1,4,C}
44263<- @code{T02}
44264@end smallexample
44265
44266Example sequence of a read call, user presses @kbd{Ctrl-c} after syscall on
44267host is called:
44268
44269@smallexample
44270<- @code{Fread,3,1234,6}
44271-> @code{X1234,6:XXXXXX}
44272<- @code{T02}
44273@end smallexample
44274
44275@node Library List Format
44276@section Library List Format
44277@cindex library list format, remote protocol
44278
44279On some platforms, a dynamic loader (e.g.@: @file{ld.so}) runs in the
44280same process as your application to manage libraries.  In this case,
44281@value{GDBN} can use the loader's symbol table and normal memory
44282operations to maintain a list of shared libraries.  On other
44283platforms, the operating system manages loaded libraries.
44284@value{GDBN} can not retrieve the list of currently loaded libraries
44285through memory operations, so it uses the @samp{qXfer:libraries:read}
44286packet (@pxref{qXfer library list read}) instead.  The remote stub
44287queries the target's operating system and reports which libraries
44288are loaded.
44289
44290The @samp{qXfer:libraries:read} packet returns an XML document which
44291lists loaded libraries and their offsets.  Each library has an
44292associated name and one or more segment or section base addresses,
44293which report where the library was loaded in memory.
44294
44295For the common case of libraries that are fully linked binaries, the
44296library should have a list of segments.  If the target supports
44297dynamic linking of a relocatable object file, its library XML element
44298should instead include a list of allocated sections.  The segment or
44299section bases are start addresses, not relocation offsets; they do not
44300depend on the library's link-time base addresses.
44301
44302@value{GDBN} must be linked with the Expat library to support XML
44303library lists.  @xref{Expat}.
44304
44305A simple memory map, with one loaded library relocated by a single
44306offset, looks like this:
44307
44308@smallexample
44309<library-list>
44310  <library name="/lib/libc.so.6">
44311    <segment address="0x10000000"/>
44312  </library>
44313</library-list>
44314@end smallexample
44315
44316Another simple memory map, with one loaded library with three
44317allocated sections (.text, .data, .bss), looks like this:
44318
44319@smallexample
44320<library-list>
44321  <library name="sharedlib.o">
44322    <section address="0x10000000"/>
44323    <section address="0x20000000"/>
44324    <section address="0x30000000"/>
44325  </library>
44326</library-list>
44327@end smallexample
44328
44329The format of a library list is described by this DTD:
44330
44331@smallexample
44332<!-- library-list: Root element with versioning -->
44333<!ELEMENT library-list  (library)*>
44334<!ATTLIST library-list  version CDATA   #FIXED  "1.0">
44335<!ELEMENT library       (segment*, section*)>
44336<!ATTLIST library       name    CDATA   #REQUIRED>
44337<!ELEMENT segment       EMPTY>
44338<!ATTLIST segment       address CDATA   #REQUIRED>
44339<!ELEMENT section       EMPTY>
44340<!ATTLIST section       address CDATA   #REQUIRED>
44341@end smallexample
44342
44343In addition, segments and section descriptors cannot be mixed within a
44344single library element, and you must supply at least one segment or
44345section for each library.
44346
44347@node Library List Format for SVR4 Targets
44348@section Library List Format for SVR4 Targets
44349@cindex library list format, remote protocol
44350
44351On SVR4 platforms @value{GDBN} can use the symbol table of a dynamic loader
44352(e.g.@: @file{ld.so}) and normal memory operations to maintain a list of
44353shared libraries.  Still a special library list provided by this packet is
44354more efficient for the @value{GDBN} remote protocol.
44355
44356The @samp{qXfer:libraries-svr4:read} packet returns an XML document which lists
44357loaded libraries and their SVR4 linker parameters.  For each library on SVR4
44358target, the following parameters are reported:
44359
44360@itemize @minus
44361@item
44362@code{name}, the absolute file name from the @code{l_name} field of
44363@code{struct link_map}.
44364@item
44365@code{lm} with address of @code{struct link_map} used for TLS
44366(Thread Local Storage) access.
44367@item
44368@code{l_addr}, the displacement as read from the field @code{l_addr} of
44369@code{struct link_map}.  For prelinked libraries this is not an absolute
44370memory address.  It is a displacement of absolute memory address against
44371address the file was prelinked to during the library load.
44372@item
44373@code{l_ld}, which is memory address of the @code{PT_DYNAMIC} segment
44374@end itemize
44375
44376Additionally the single @code{main-lm} attribute specifies address of
44377@code{struct link_map} used for the main executable.  This parameter is used
44378for TLS access and its presence is optional.
44379
44380@value{GDBN} must be linked with the Expat library to support XML
44381SVR4 library lists.  @xref{Expat}.
44382
44383A simple memory map, with two loaded libraries (which do not use prelink),
44384looks like this:
44385
44386@smallexample
44387<library-list-svr4 version="1.0" main-lm="0xe4f8f8">
44388  <library name="/lib/ld-linux.so.2" lm="0xe4f51c" l_addr="0xe2d000"
44389           l_ld="0xe4eefc"/>
44390  <library name="/lib/libc.so.6" lm="0xe4fbe8" l_addr="0x154000"
44391           l_ld="0x152350"/>
44392</library-list-svr>
44393@end smallexample
44394
44395The format of an SVR4 library list is described by this DTD:
44396
44397@smallexample
44398<!-- library-list-svr4: Root element with versioning -->
44399<!ELEMENT library-list-svr4  (library)*>
44400<!ATTLIST library-list-svr4  version CDATA   #FIXED  "1.0">
44401<!ATTLIST library-list-svr4  main-lm CDATA   #IMPLIED>
44402<!ELEMENT library            EMPTY>
44403<!ATTLIST library            name    CDATA   #REQUIRED>
44404<!ATTLIST library            lm      CDATA   #REQUIRED>
44405<!ATTLIST library            l_addr  CDATA   #REQUIRED>
44406<!ATTLIST library            l_ld    CDATA   #REQUIRED>
44407@end smallexample
44408
44409@node Memory Map Format
44410@section Memory Map Format
44411@cindex memory map format
44412
44413To be able to write into flash memory, @value{GDBN} needs to obtain a
44414memory map from the target.  This section describes the format of the
44415memory map.
44416
44417The memory map is obtained using the @samp{qXfer:memory-map:read}
44418(@pxref{qXfer memory map read}) packet and is an XML document that
44419lists memory regions.
44420
44421@value{GDBN} must be linked with the Expat library to support XML
44422memory maps.  @xref{Expat}.
44423
44424The top-level structure of the document is shown below:
44425
44426@smallexample
44427<?xml version="1.0"?>
44428<!DOCTYPE memory-map
44429          PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
44430                 "http://sourceware.org/gdb/gdb-memory-map.dtd">
44431<memory-map>
44432    region...
44433</memory-map>
44434@end smallexample
44435
44436Each region can be either:
44437
44438@itemize
44439
44440@item
44441A region of RAM starting at @var{addr} and extending for @var{length}
44442bytes from there:
44443
44444@smallexample
44445<memory type="ram" start="@var{addr}" length="@var{length}"/>
44446@end smallexample
44447
44448
44449@item
44450A region of read-only memory:
44451
44452@smallexample
44453<memory type="rom" start="@var{addr}" length="@var{length}"/>
44454@end smallexample
44455
44456
44457@item
44458A region of flash memory, with erasure blocks @var{blocksize}
44459bytes in length:
44460
44461@smallexample
44462<memory type="flash" start="@var{addr}" length="@var{length}">
44463  <property name="blocksize">@var{blocksize}</property>
44464</memory>
44465@end smallexample
44466
44467@end itemize
44468
44469Regions must not overlap.  @value{GDBN} assumes that areas of memory not covered
44470by the memory map are RAM, and uses the ordinary @samp{M} and @samp{X}
44471packets to write to addresses in such ranges.
44472
44473The formal DTD for memory map format is given below:
44474
44475@smallexample
44476<!-- ................................................... -->
44477<!-- Memory Map XML DTD ................................ -->
44478<!-- File: memory-map.dtd .............................. -->
44479<!-- .................................... .............. -->
44480<!-- memory-map.dtd -->
44481<!-- memory-map: Root element with versioning -->
44482<!ELEMENT memory-map (memory)*>
44483<!ATTLIST memory-map    version CDATA   #FIXED  "1.0.0">
44484<!ELEMENT memory (property)*>
44485<!-- memory: Specifies a memory region,
44486             and its type, or device. -->
44487<!ATTLIST memory        type    (ram|rom|flash) #REQUIRED
44488                        start   CDATA   #REQUIRED
44489                        length  CDATA   #REQUIRED>
44490<!-- property: Generic attribute tag -->
44491<!ELEMENT property (#PCDATA | property)*>
44492<!ATTLIST property      name    (blocksize) #REQUIRED>
44493@end smallexample
44494
44495@node Thread List Format
44496@section Thread List Format
44497@cindex thread list format
44498
44499To efficiently update the list of threads and their attributes,
44500@value{GDBN} issues the @samp{qXfer:threads:read} packet
44501(@pxref{qXfer threads read}) and obtains the XML document with
44502the following structure:
44503
44504@smallexample
44505<?xml version="1.0"?>
44506<threads>
44507    <thread id="id" core="0" name="name">
44508    ... description ...
44509    </thread>
44510</threads>
44511@end smallexample
44512
44513Each @samp{thread} element must have the @samp{id} attribute that
44514identifies the thread (@pxref{thread-id syntax}).  The
44515@samp{core} attribute, if present, specifies which processor core
44516the thread was last executing on.  The @samp{name} attribute, if
44517present, specifies the human-readable name of the thread.  The content
44518of the of @samp{thread} element is interpreted as human-readable
44519auxiliary information.  The @samp{handle} attribute, if present,
44520is a hex encoded representation of the thread handle.
44521
44522
44523@node Traceframe Info Format
44524@section Traceframe Info Format
44525@cindex traceframe info format
44526
44527To be able to know which objects in the inferior can be examined when
44528inspecting a tracepoint hit, @value{GDBN} needs to obtain the list of
44529memory ranges, registers and trace state variables that have been
44530collected in a traceframe.
44531
44532This list is obtained using the @samp{qXfer:traceframe-info:read}
44533(@pxref{qXfer traceframe info read}) packet and is an XML document.
44534
44535@value{GDBN} must be linked with the Expat library to support XML
44536traceframe info discovery.  @xref{Expat}.
44537
44538The top-level structure of the document is shown below:
44539
44540@smallexample
44541<?xml version="1.0"?>
44542<!DOCTYPE traceframe-info
44543          PUBLIC "+//IDN gnu.org//DTD GDB Memory Map V1.0//EN"
44544                 "http://sourceware.org/gdb/gdb-traceframe-info.dtd">
44545<traceframe-info>
44546   block...
44547</traceframe-info>
44548@end smallexample
44549
44550Each traceframe block can be either:
44551
44552@itemize
44553
44554@item
44555A region of collected memory starting at @var{addr} and extending for
44556@var{length} bytes from there:
44557
44558@smallexample
44559<memory start="@var{addr}" length="@var{length}"/>
44560@end smallexample
44561
44562@item
44563A block indicating trace state variable numbered @var{number} has been
44564collected:
44565
44566@smallexample
44567<tvar id="@var{number}"/>
44568@end smallexample
44569
44570@end itemize
44571
44572The formal DTD for the traceframe info format is given below:
44573
44574@smallexample
44575<!ELEMENT traceframe-info  (memory | tvar)* >
44576<!ATTLIST traceframe-info  version CDATA   #FIXED  "1.0">
44577
44578<!ELEMENT memory        EMPTY>
44579<!ATTLIST memory        start   CDATA   #REQUIRED
44580                        length  CDATA   #REQUIRED>
44581<!ELEMENT tvar>
44582<!ATTLIST tvar          id      CDATA   #REQUIRED>
44583@end smallexample
44584
44585@node Branch Trace Format
44586@section Branch Trace Format
44587@cindex branch trace format
44588
44589In order to display the branch trace of an inferior thread,
44590@value{GDBN} needs to obtain the list of branches.  This list is
44591represented as list of sequential code blocks that are connected via
44592branches.  The code in each block has been executed sequentially.
44593
44594This list is obtained using the @samp{qXfer:btrace:read}
44595(@pxref{qXfer btrace read}) packet and is an XML document.
44596
44597@value{GDBN} must be linked with the Expat library to support XML
44598traceframe info discovery.  @xref{Expat}.
44599
44600The top-level structure of the document is shown below:
44601
44602@smallexample
44603<?xml version="1.0"?>
44604<!DOCTYPE btrace
44605          PUBLIC "+//IDN gnu.org//DTD GDB Branch Trace V1.0//EN"
44606                 "http://sourceware.org/gdb/gdb-btrace.dtd">
44607<btrace>
44608   block...
44609</btrace>
44610@end smallexample
44611
44612@itemize
44613
44614@item
44615A block of sequentially executed instructions starting at @var{begin}
44616and ending at @var{end}:
44617
44618@smallexample
44619<block begin="@var{begin}" end="@var{end}"/>
44620@end smallexample
44621
44622@end itemize
44623
44624The formal DTD for the branch trace format is given below:
44625
44626@smallexample
44627<!ELEMENT btrace  (block* | pt) >
44628<!ATTLIST btrace  version CDATA   #FIXED "1.0">
44629
44630<!ELEMENT block        EMPTY>
44631<!ATTLIST block        begin  CDATA   #REQUIRED
44632                       end    CDATA   #REQUIRED>
44633
44634<!ELEMENT pt (pt-config?, raw?)>
44635
44636<!ELEMENT pt-config (cpu?)>
44637
44638<!ELEMENT cpu EMPTY>
44639<!ATTLIST cpu vendor   CDATA #REQUIRED
44640              family   CDATA #REQUIRED
44641              model    CDATA #REQUIRED
44642              stepping CDATA #REQUIRED>
44643
44644<!ELEMENT raw (#PCDATA)>
44645@end smallexample
44646
44647@node Branch Trace Configuration Format
44648@section Branch Trace Configuration Format
44649@cindex branch trace configuration format
44650
44651For each inferior thread, @value{GDBN} can obtain the branch trace
44652configuration using the @samp{qXfer:btrace-conf:read}
44653(@pxref{qXfer btrace-conf read}) packet.
44654
44655The configuration describes the branch trace format and configuration
44656settings for that format.  The following information is described:
44657
44658@table @code
44659@item bts
44660This thread uses the @dfn{Branch Trace Store} (@acronym{BTS}) format.
44661@table @code
44662@item size
44663The size of the @acronym{BTS} ring buffer in bytes.
44664@end table
44665@item pt
44666This thread uses the @dfn{Intel Processor Trace} (@acronym{Intel
44667PT}) format.
44668@table @code
44669@item size
44670The size of the @acronym{Intel PT} ring buffer in bytes.
44671@end table
44672@end table
44673
44674@value{GDBN} must be linked with the Expat library to support XML
44675branch trace configuration discovery.  @xref{Expat}.
44676
44677The formal DTD for the branch trace configuration format is given below:
44678
44679@smallexample
44680<!ELEMENT btrace-conf	(bts?, pt?)>
44681<!ATTLIST btrace-conf	version	CDATA	#FIXED "1.0">
44682
44683<!ELEMENT bts	EMPTY>
44684<!ATTLIST bts	size	CDATA	#IMPLIED>
44685
44686<!ELEMENT pt	EMPTY>
44687<!ATTLIST pt	size	CDATA	#IMPLIED>
44688@end smallexample
44689
44690@include agentexpr.texi
44691
44692@node Target Descriptions
44693@appendix Target Descriptions
44694@cindex target descriptions
44695
44696One of the challenges of using @value{GDBN} to debug embedded systems
44697is that there are so many minor variants of each processor
44698architecture in use.  It is common practice for vendors to start with
44699a standard processor core --- ARM, PowerPC, or @acronym{MIPS}, for example ---
44700and then make changes to adapt it to a particular market niche.  Some
44701architectures have hundreds of variants, available from dozens of
44702vendors.  This leads to a number of problems:
44703
44704@itemize @bullet
44705@item
44706With so many different customized processors, it is difficult for
44707the @value{GDBN} maintainers to keep up with the changes.
44708@item
44709Since individual variants may have short lifetimes or limited
44710audiences, it may not be worthwhile to carry information about every
44711variant in the @value{GDBN} source tree.
44712@item
44713When @value{GDBN} does support the architecture of the embedded system
44714at hand, the task of finding the correct architecture name to give the
44715@command{set architecture} command can be error-prone.
44716@end itemize
44717
44718To address these problems, the @value{GDBN} remote protocol allows a
44719target system to not only identify itself to @value{GDBN}, but to
44720actually describe its own features.  This lets @value{GDBN} support
44721processor variants it has never seen before --- to the extent that the
44722descriptions are accurate, and that @value{GDBN} understands them.
44723
44724@value{GDBN} must be linked with the Expat library to support XML
44725target descriptions.  @xref{Expat}.
44726
44727@menu
44728* Retrieving Descriptions::         How descriptions are fetched from a target.
44729* Target Description Format::       The contents of a target description.
44730* Predefined Target Types::         Standard types available for target
44731                                    descriptions.
44732* Enum Target Types::               How to define enum target types.
44733* Standard Target Features::        Features @value{GDBN} knows about.
44734@end menu
44735
44736@node Retrieving Descriptions
44737@section Retrieving Descriptions
44738
44739Target descriptions can be read from the target automatically, or
44740specified by the user manually.  The default behavior is to read the
44741description from the target.  @value{GDBN} retrieves it via the remote
44742protocol using @samp{qXfer} requests (@pxref{General Query Packets,
44743qXfer}).  The @var{annex} in the @samp{qXfer} packet will be
44744@samp{target.xml}.  The contents of the @samp{target.xml} annex are an
44745XML document, of the form described in @ref{Target Description
44746Format}.
44747
44748Alternatively, you can specify a file to read for the target description.
44749If a file is set, the target will not be queried.  The commands to
44750specify a file are:
44751
44752@table @code
44753@cindex set tdesc filename
44754@item set tdesc filename @var{path}
44755Read the target description from @var{path}.
44756
44757@cindex unset tdesc filename
44758@item unset tdesc filename
44759Do not read the XML target description from a file.  @value{GDBN}
44760will use the description supplied by the current target.
44761
44762@cindex show tdesc filename
44763@item show tdesc filename
44764Show the filename to read for a target description, if any.
44765@end table
44766
44767
44768@node Target Description Format
44769@section Target Description Format
44770@cindex target descriptions, XML format
44771
44772A target description annex is an @uref{http://www.w3.org/XML/, XML}
44773document which complies with the Document Type Definition provided in
44774the @value{GDBN} sources in @file{gdb/features/gdb-target.dtd}.  This
44775means you can use generally available tools like @command{xmllint} to
44776check that your feature descriptions are well-formed and valid.
44777However, to help people unfamiliar with XML write descriptions for
44778their targets, we also describe the grammar here.
44779
44780Target descriptions can identify the architecture of the remote target
44781and (for some architectures) provide information about custom register
44782sets.  They can also identify the OS ABI of the remote target.
44783@value{GDBN} can use this information to autoconfigure for your
44784target, or to warn you if you connect to an unsupported target.
44785
44786Here is a simple target description:
44787
44788@smallexample
44789<target version="1.0">
44790  <architecture>i386:x86-64</architecture>
44791</target>
44792@end smallexample
44793
44794@noindent
44795This minimal description only says that the target uses
44796the x86-64 architecture.
44797
44798A target description has the following overall form, with [ ] marking
44799optional elements and @dots{} marking repeatable elements.  The elements
44800are explained further below.
44801
44802@smallexample
44803<?xml version="1.0"?>
44804<!DOCTYPE target SYSTEM "gdb-target.dtd">
44805<target version="1.0">
44806  @r{[}@var{architecture}@r{]}
44807  @r{[}@var{osabi}@r{]}
44808  @r{[}@var{compatible}@r{]}
44809  @r{[}@var{feature}@dots{}@r{]}
44810</target>
44811@end smallexample
44812
44813@noindent
44814The description is generally insensitive to whitespace and line
44815breaks, under the usual common-sense rules.  The XML version
44816declaration and document type declaration can generally be omitted
44817(@value{GDBN} does not require them), but specifying them may be
44818useful for XML validation tools.  The @samp{version} attribute for
44819@samp{<target>} may also be omitted, but we recommend
44820including it; if future versions of @value{GDBN} use an incompatible
44821revision of @file{gdb-target.dtd}, they will detect and report
44822the version mismatch.
44823
44824@subsection Inclusion
44825@cindex target descriptions, inclusion
44826@cindex XInclude
44827@ifnotinfo
44828@cindex <xi:include>
44829@end ifnotinfo
44830
44831It can sometimes be valuable to split a target description up into
44832several different annexes, either for organizational purposes, or to
44833share files between different possible target descriptions.  You can
44834divide a description into multiple files by replacing any element of
44835the target description with an inclusion directive of the form:
44836
44837@smallexample
44838<xi:include href="@var{document}"/>
44839@end smallexample
44840
44841@noindent
44842When @value{GDBN} encounters an element of this form, it will retrieve
44843the named XML @var{document}, and replace the inclusion directive with
44844the contents of that document.  If the current description was read
44845using @samp{qXfer}, then so will be the included document;
44846@var{document} will be interpreted as the name of an annex.  If the
44847current description was read from a file, @value{GDBN} will look for
44848@var{document} as a file in the same directory where it found the
44849original description.
44850
44851@subsection Architecture
44852@cindex <architecture>
44853
44854An @samp{<architecture>} element has this form:
44855
44856@smallexample
44857  <architecture>@var{arch}</architecture>
44858@end smallexample
44859
44860@var{arch} is one of the architectures from the set accepted by
44861@code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
44862
44863@subsection OS ABI
44864@cindex @code{<osabi>}
44865
44866This optional field was introduced in @value{GDBN} version 7.0.
44867Previous versions of @value{GDBN} ignore it.
44868
44869An @samp{<osabi>} element has this form:
44870
44871@smallexample
44872  <osabi>@var{abi-name}</osabi>
44873@end smallexample
44874
44875@var{abi-name} is an OS ABI name from the same selection accepted by
44876@w{@code{set osabi}} (@pxref{ABI, ,Configuring the Current ABI}).
44877
44878@subsection Compatible Architecture
44879@cindex @code{<compatible>}
44880
44881This optional field was introduced in @value{GDBN} version 7.0.
44882Previous versions of @value{GDBN} ignore it.
44883
44884A @samp{<compatible>} element has this form:
44885
44886@smallexample
44887  <compatible>@var{arch}</compatible>
44888@end smallexample
44889
44890@var{arch} is one of the architectures from the set accepted by
44891@code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
44892
44893A @samp{<compatible>} element is used to specify that the target
44894is able to run binaries in some other than the main target architecture
44895given by the @samp{<architecture>} element.  For example, on the
44896Cell Broadband Engine, the main architecture is @code{powerpc:common}
44897or @code{powerpc:common64}, but the system is able to run binaries
44898in the @code{spu} architecture as well.  The way to describe this
44899capability with @samp{<compatible>} is as follows:
44900
44901@smallexample
44902  <architecture>powerpc:common</architecture>
44903  <compatible>spu</compatible>
44904@end smallexample
44905
44906@subsection Features
44907@cindex <feature>
44908
44909Each @samp{<feature>} describes some logical portion of the target
44910system.  Features are currently used to describe available CPU
44911registers and the types of their contents.  A @samp{<feature>} element
44912has this form:
44913
44914@smallexample
44915<feature name="@var{name}">
44916  @r{[}@var{type}@dots{}@r{]}
44917  @var{reg}@dots{}
44918</feature>
44919@end smallexample
44920
44921@noindent
44922Each feature's name should be unique within the description.  The name
44923of a feature does not matter unless @value{GDBN} has some special
44924knowledge of the contents of that feature; if it does, the feature
44925should have its standard name.  @xref{Standard Target Features}.
44926
44927@subsection Types
44928
44929Any register's value is a collection of bits which @value{GDBN} must
44930interpret.  The default interpretation is a two's complement integer,
44931but other types can be requested by name in the register description.
44932Some predefined types are provided by @value{GDBN} (@pxref{Predefined
44933Target Types}), and the description can define additional composite
44934and enum types.
44935
44936Each type element must have an @samp{id} attribute, which gives
44937a unique (within the containing @samp{<feature>}) name to the type.
44938Types must be defined before they are used.
44939
44940@cindex <vector>
44941Some targets offer vector registers, which can be treated as arrays
44942of scalar elements.  These types are written as @samp{<vector>} elements,
44943specifying the array element type, @var{type}, and the number of elements,
44944@var{count}:
44945
44946@smallexample
44947<vector id="@var{id}" type="@var{type}" count="@var{count}"/>
44948@end smallexample
44949
44950@cindex <union>
44951If a register's value is usefully viewed in multiple ways, define it
44952with a union type containing the useful representations.  The
44953@samp{<union>} element contains one or more @samp{<field>} elements,
44954each of which has a @var{name} and a @var{type}:
44955
44956@smallexample
44957<union id="@var{id}">
44958  <field name="@var{name}" type="@var{type}"/>
44959  @dots{}
44960</union>
44961@end smallexample
44962
44963@cindex <struct>
44964@cindex <flags>
44965If a register's value is composed from several separate values, define
44966it with either a structure type or a flags type.
44967A flags type may only contain bitfields.
44968A structure type may either contain only bitfields or contain no bitfields.
44969If the value contains only bitfields, its total size in bytes must be
44970specified.
44971
44972Non-bitfield values have a @var{name} and @var{type}.
44973
44974@smallexample
44975<struct id="@var{id}">
44976  <field name="@var{name}" type="@var{type}"/>
44977  @dots{}
44978</struct>
44979@end smallexample
44980
44981Both @var{name} and @var{type} values are required.
44982No implicit padding is added.
44983
44984Bitfield values have a @var{name}, @var{start}, @var{end} and @var{type}.
44985
44986@smallexample
44987<struct id="@var{id}" size="@var{size}">
44988  <field name="@var{name}" start="@var{start}" end="@var{end}" type="@var{type}"/>
44989  @dots{}
44990</struct>
44991@end smallexample
44992
44993@smallexample
44994<flags id="@var{id}" size="@var{size}">
44995  <field name="@var{name}" start="@var{start}" end="@var{end}" type="@var{type}"/>
44996  @dots{}
44997</flags>
44998@end smallexample
44999
45000The @var{name} value is required.
45001Bitfield values may be named with the empty string, @samp{""},
45002in which case the field is ``filler'' and its value is not printed.
45003Not all bits need to be specified, so ``filler'' fields are optional.
45004
45005The @var{start} and @var{end} values are required, and @var{type}
45006is optional.
45007The field's @var{start} must be less than or equal to its @var{end},
45008and zero represents the least significant bit.
45009
45010The default value of @var{type} is @code{bool} for single bit fields,
45011and an unsigned integer otherwise.
45012
45013Which to choose?  Structures or flags?
45014
45015Registers defined with @samp{flags} have these advantages over
45016defining them with @samp{struct}:
45017
45018@itemize @bullet
45019@item
45020Arithmetic may be performed on them as if they were integers.
45021@item
45022They are printed in a more readable fashion.
45023@end itemize
45024
45025Registers defined with @samp{struct} have one advantage over
45026defining them with @samp{flags}:
45027
45028@itemize @bullet
45029@item
45030One can fetch individual fields like in @samp{C}.
45031
45032@smallexample
45033(gdb) print $my_struct_reg.field3
45034$1 = 42
45035@end smallexample
45036
45037@end itemize
45038
45039@subsection Registers
45040@cindex <reg>
45041
45042Each register is represented as an element with this form:
45043
45044@smallexample
45045<reg name="@var{name}"
45046     bitsize="@var{size}"
45047     @r{[}regnum="@var{num}"@r{]}
45048     @r{[}save-restore="@var{save-restore}"@r{]}
45049     @r{[}type="@var{type}"@r{]}
45050     @r{[}group="@var{group}"@r{]}/>
45051@end smallexample
45052
45053@noindent
45054The components are as follows:
45055
45056@table @var
45057
45058@item name
45059The register's name; it must be unique within the target description.
45060
45061@item bitsize
45062The register's size, in bits.
45063
45064@item regnum
45065The register's number.  If omitted, a register's number is one greater
45066than that of the previous register (either in the current feature or in
45067a preceding feature); the first register in the target description
45068defaults to zero.  This register number is used to read or write
45069the register; e.g.@: it is used in the remote @code{p} and @code{P}
45070packets, and registers appear in the @code{g} and @code{G} packets
45071in order of increasing register number.
45072
45073@item save-restore
45074Whether the register should be preserved across inferior function
45075calls; this must be either @code{yes} or @code{no}.  The default is
45076@code{yes}, which is appropriate for most registers except for
45077some system control registers; this is not related to the target's
45078ABI.
45079
45080@item type
45081The type of the register.  It may be a predefined type, a type
45082defined in the current feature, or one of the special types @code{int}
45083and @code{float}.  @code{int} is an integer type of the correct size
45084for @var{bitsize}, and @code{float} is a floating point type (in the
45085architecture's normal floating point format) of the correct size for
45086@var{bitsize}.  The default is @code{int}.
45087
45088@item group
45089The register group to which this register belongs.  It can be one of the
45090standard register groups @code{general}, @code{float}, @code{vector} or an
45091arbitrary string.  Group names should be limited to alphanumeric characters.
45092If a group name is made up of multiple words the words may be separated by
45093hyphens; e.g.@: @code{special-group} or @code{ultra-special-group}.  If no
45094@var{group} is specified, @value{GDBN} will not display the register in
45095@code{info registers}.
45096
45097@end table
45098
45099@node Predefined Target Types
45100@section Predefined Target Types
45101@cindex target descriptions, predefined types
45102
45103Type definitions in the self-description can build up composite types
45104from basic building blocks, but can not define fundamental types.  Instead,
45105standard identifiers are provided by @value{GDBN} for the fundamental
45106types.  The currently supported types are:
45107
45108@table @code
45109
45110@item bool
45111Boolean type, occupying a single bit.
45112
45113@item int8
45114@itemx int16
45115@itemx int24
45116@itemx int32
45117@itemx int64
45118@itemx int128
45119Signed integer types holding the specified number of bits.
45120
45121@item uint8
45122@itemx uint16
45123@itemx uint24
45124@itemx uint32
45125@itemx uint64
45126@itemx uint128
45127Unsigned integer types holding the specified number of bits.
45128
45129@item code_ptr
45130@itemx data_ptr
45131Pointers to unspecified code and data.  The program counter and
45132any dedicated return address register may be marked as code
45133pointers; printing a code pointer converts it into a symbolic
45134address.  The stack pointer and any dedicated address registers
45135may be marked as data pointers.
45136
45137@item ieee_single
45138Single precision IEEE floating point.
45139
45140@item ieee_double
45141Double precision IEEE floating point.
45142
45143@item arm_fpa_ext
45144The 12-byte extended precision format used by ARM FPA registers.
45145
45146@item i387_ext
45147The 10-byte extended precision format used by x87 registers.
45148
45149@item i386_eflags
4515032bit @sc{eflags} register used by x86.
45151
45152@item i386_mxcsr
4515332bit @sc{mxcsr} register used by x86.
45154
45155@end table
45156
45157@node Enum Target Types
45158@section Enum Target Types
45159@cindex target descriptions, enum types
45160
45161Enum target types are useful in @samp{struct} and @samp{flags}
45162register descriptions.  @xref{Target Description Format}.
45163
45164Enum types have a name, size and a list of name/value pairs.
45165
45166@smallexample
45167<enum id="@var{id}" size="@var{size}">
45168  <evalue name="@var{name}" value="@var{value}"/>
45169  @dots{}
45170</enum>
45171@end smallexample
45172
45173Enums must be defined before they are used.
45174
45175@smallexample
45176<enum id="levels_type" size="4">
45177  <evalue name="low" value="0"/>
45178  <evalue name="high" value="1"/>
45179</enum>
45180<flags id="flags_type" size="4">
45181  <field name="X" start="0"/>
45182  <field name="LEVEL" start="1" end="1" type="levels_type"/>
45183</flags>
45184<reg name="flags" bitsize="32" type="flags_type"/>
45185@end smallexample
45186
45187Given that description, a value of 3 for the @samp{flags} register
45188would be printed as:
45189
45190@smallexample
45191(gdb) info register flags
45192flags 0x3 [ X LEVEL=high ]
45193@end smallexample
45194
45195@node Standard Target Features
45196@section Standard Target Features
45197@cindex target descriptions, standard features
45198
45199A target description must contain either no registers or all the
45200target's registers.  If the description contains no registers, then
45201@value{GDBN} will assume a default register layout, selected based on
45202the architecture.  If the description contains any registers, the
45203default layout will not be used; the standard registers must be
45204described in the target description, in such a way that @value{GDBN}
45205can recognize them.
45206
45207This is accomplished by giving specific names to feature elements
45208which contain standard registers.  @value{GDBN} will look for features
45209with those names and verify that they contain the expected registers;
45210if any known feature is missing required registers, or if any required
45211feature is missing, @value{GDBN} will reject the target
45212description.  You can add additional registers to any of the
45213standard features --- @value{GDBN} will display them just as if
45214they were added to an unrecognized feature.
45215
45216This section lists the known features and their expected contents.
45217Sample XML documents for these features are included in the
45218@value{GDBN} source tree, in the directory @file{gdb/features}.
45219
45220Names recognized by @value{GDBN} should include the name of the
45221company or organization which selected the name, and the overall
45222architecture to which the feature applies; so e.g.@: the feature
45223containing ARM core registers is named @samp{org.gnu.gdb.arm.core}.
45224
45225The names of registers are not case sensitive for the purpose
45226of recognizing standard features, but @value{GDBN} will only display
45227registers using the capitalization used in the description.
45228
45229@menu
45230* AArch64 Features::
45231* ARC Features::
45232* ARM Features::
45233* i386 Features::
45234* MicroBlaze Features::
45235* MIPS Features::
45236* M68K Features::
45237* NDS32 Features::
45238* Nios II Features::
45239* OpenRISC 1000 Features::
45240* PowerPC Features::
45241* RISC-V Features::
45242* RX Features::
45243* S/390 and System z Features::
45244* Sparc Features::
45245* TIC6x Features::
45246@end menu
45247
45248
45249@node AArch64 Features
45250@subsection AArch64 Features
45251@cindex target descriptions, AArch64 features
45252
45253The @samp{org.gnu.gdb.aarch64.core} feature is required for AArch64
45254targets.  It should contain registers @samp{x0} through @samp{x30},
45255@samp{sp}, @samp{pc}, and @samp{cpsr}.
45256
45257The @samp{org.gnu.gdb.aarch64.fpu} feature is optional.  If present,
45258it should contain registers @samp{v0} through @samp{v31}, @samp{fpsr},
45259and @samp{fpcr}.
45260
45261The @samp{org.gnu.gdb.aarch64.sve} feature is optional.  If present,
45262it should contain registers @samp{z0} through @samp{z31}, @samp{p0}
45263through @samp{p15}, @samp{ffr} and @samp{vg}.
45264
45265The @samp{org.gnu.gdb.aarch64.pauth} feature is optional.  If present,
45266it should contain registers @samp{pauth_dmask} and @samp{pauth_cmask}.
45267
45268@node ARC Features
45269@subsection ARC Features
45270@cindex target descriptions, ARC Features
45271
45272ARC processors are so configurable that even core registers and their numbers
45273are not predetermined completely.  Moreover, @emph{flags} and @emph{PC}
45274registers, which are important to @value{GDBN}, are not ``core'' registers in
45275ARC.  Therefore, there are two features that their presence is mandatory:
45276@samp{org.gnu.gdb.arc.core} and @samp{org.gnu.gdb.arc.aux}.
45277
45278The @samp{org.gnu.gdb.arc.core} feature is required for all targets.  It must
45279contain registers:
45280
45281@itemize @minus
45282@item
45283@samp{r0} through @samp{r25} for normal register file targets.
45284@item
45285@samp{r0} through @samp{r3}, and @samp{r10} through @samp{r15} for reduced
45286register file targets.
45287@item
45288@samp{gp}, @samp{fp}, @samp{sp}, @samp{r30}@footnote{Not necessary for ARCv1.},
45289@samp{blink}, @samp{lp_count}, @samp{pcl}.
45290@end itemize
45291
45292In case of an ARCompact target (ARCv1 ISA), the @samp{org.gnu.gdb.arc.core}
45293feature may contain registers @samp{ilink1} and @samp{ilink2}.  While in case
45294of ARC EM and ARC HS targets (ARCv2 ISA), register @samp{ilink} may be present.
45295The difference between ARCv1 and ARCv2 is the naming of registers @emph{29th}
45296and @emph{30th}.  They are called @samp{ilink1} and @samp{ilink2} for ARCv1 and
45297are optional.  For ARCv2, they are called @samp{ilink} and @samp{r30} and only
45298@samp{ilink} is optional.  The optionality of @samp{ilink*} registers is
45299because of their inaccessibility during user space debugging sessions.
45300
45301Extension core registers @samp{r32} through @samp{r59} are optional and their
45302existence depends on the configuration.  When debugging GNU/Linux applications,
45303i.e.@: user space debugging, these core registers are not available.
45304
45305The @samp{org.gnu.gdb.arc.aux} feature is required for all ARC targets.  Here
45306is the list of registers pertinent to this feature:
45307
45308@itemize @minus
45309@item
45310mandatory: @samp{pc} and @samp{status32}.
45311@item
45312optional: @samp{lp_start}, @samp{lp_end}, and @samp{bta}.
45313@end itemize
45314
45315@node ARM Features
45316@subsection ARM Features
45317@cindex target descriptions, ARM features
45318
45319The @samp{org.gnu.gdb.arm.core} feature is required for non-M-profile
45320ARM targets.
45321It should contain registers @samp{r0} through @samp{r13}, @samp{sp},
45322@samp{lr}, @samp{pc}, and @samp{cpsr}.
45323
45324For M-profile targets (e.g. Cortex-M3), the @samp{org.gnu.gdb.arm.core}
45325feature is replaced by @samp{org.gnu.gdb.arm.m-profile}.  It should contain
45326registers @samp{r0} through @samp{r13}, @samp{sp}, @samp{lr}, @samp{pc},
45327and @samp{xpsr}.
45328
45329The @samp{org.gnu.gdb.arm.fpa} feature is optional.  If present, it
45330should contain registers @samp{f0} through @samp{f7} and @samp{fps}.
45331
45332The @samp{org.gnu.gdb.xscale.iwmmxt} feature is optional.  If present,
45333it should contain at least registers @samp{wR0} through @samp{wR15} and
45334@samp{wCGR0} through @samp{wCGR3}.  The @samp{wCID}, @samp{wCon},
45335@samp{wCSSF}, and @samp{wCASF} registers are optional.
45336
45337The @samp{org.gnu.gdb.arm.vfp} feature is optional.  If present, it
45338should contain at least registers @samp{d0} through @samp{d15}.  If
45339they are present, @samp{d16} through @samp{d31} should also be included.
45340@value{GDBN} will synthesize the single-precision registers from
45341halves of the double-precision registers.
45342
45343The @samp{org.gnu.gdb.arm.neon} feature is optional.  It does not
45344need to contain registers; it instructs @value{GDBN} to display the
45345VFP double-precision registers as vectors and to synthesize the
45346quad-precision registers from pairs of double-precision registers.
45347If this feature is present, @samp{org.gnu.gdb.arm.vfp} must also
45348be present and include 32 double-precision registers.
45349
45350@node i386 Features
45351@subsection i386 Features
45352@cindex target descriptions, i386 features
45353
45354The @samp{org.gnu.gdb.i386.core} feature is required for i386/amd64
45355targets.  It should describe the following registers:
45356
45357@itemize @minus
45358@item
45359@samp{eax} through @samp{edi} plus @samp{eip} for i386
45360@item
45361@samp{rax} through @samp{r15} plus @samp{rip} for amd64
45362@item
45363@samp{eflags}, @samp{cs}, @samp{ss}, @samp{ds}, @samp{es},
45364@samp{fs}, @samp{gs}
45365@item
45366@samp{st0} through @samp{st7}
45367@item
45368@samp{fctrl}, @samp{fstat}, @samp{ftag}, @samp{fiseg}, @samp{fioff},
45369@samp{foseg}, @samp{fooff} and @samp{fop}
45370@end itemize
45371
45372The register sets may be different, depending on the target.
45373
45374The @samp{org.gnu.gdb.i386.sse} feature is optional.  It should
45375describe registers:
45376
45377@itemize @minus
45378@item
45379@samp{xmm0} through @samp{xmm7} for i386
45380@item
45381@samp{xmm0} through @samp{xmm15} for amd64
45382@item
45383@samp{mxcsr}
45384@end itemize
45385
45386The @samp{org.gnu.gdb.i386.avx} feature is optional and requires the
45387@samp{org.gnu.gdb.i386.sse} feature.  It should
45388describe the upper 128 bits of @sc{ymm} registers:
45389
45390@itemize @minus
45391@item
45392@samp{ymm0h} through @samp{ymm7h} for i386
45393@item
45394@samp{ymm0h} through @samp{ymm15h} for amd64
45395@end itemize
45396
45397The @samp{org.gnu.gdb.i386.mpx} is an optional feature representing Intel
45398Memory Protection Extension (MPX).  It should describe the following registers:
45399
45400@itemize @minus
45401@item
45402@samp{bnd0raw} through @samp{bnd3raw} for i386 and amd64.
45403@item
45404@samp{bndcfgu} and @samp{bndstatus} for i386 and amd64.
45405@end itemize
45406
45407The @samp{org.gnu.gdb.i386.linux} feature is optional.  It should
45408describe a single register, @samp{orig_eax}.
45409
45410The @samp{org.gnu.gdb.i386.segments} feature is optional.  It should
45411describe two system registers: @samp{fs_base} and @samp{gs_base}.
45412
45413The @samp{org.gnu.gdb.i386.avx512} feature is optional and requires the
45414@samp{org.gnu.gdb.i386.avx} feature.  It should
45415describe additional @sc{xmm} registers:
45416
45417@itemize @minus
45418@item
45419@samp{xmm16h} through @samp{xmm31h}, only valid for amd64.
45420@end itemize
45421
45422It should describe the upper 128 bits of additional @sc{ymm} registers:
45423
45424@itemize @minus
45425@item
45426@samp{ymm16h} through @samp{ymm31h}, only valid for amd64.
45427@end itemize
45428
45429It should
45430describe the upper 256 bits of @sc{zmm} registers:
45431
45432@itemize @minus
45433@item
45434@samp{zmm0h} through @samp{zmm7h} for i386.
45435@item
45436@samp{zmm0h} through @samp{zmm15h} for amd64.
45437@end itemize
45438
45439It should
45440describe the additional @sc{zmm} registers:
45441
45442@itemize @minus
45443@item
45444@samp{zmm16h} through @samp{zmm31h}, only valid for amd64.
45445@end itemize
45446
45447The @samp{org.gnu.gdb.i386.pkeys} feature is optional.  It should
45448describe a single register, @samp{pkru}.  It is a 32-bit register
45449valid for i386 and amd64.
45450
45451@node MicroBlaze Features
45452@subsection MicroBlaze Features
45453@cindex target descriptions, MicroBlaze features
45454
45455The @samp{org.gnu.gdb.microblaze.core} feature is required for MicroBlaze
45456targets.  It should contain registers @samp{r0} through @samp{r31},
45457@samp{rpc}, @samp{rmsr}, @samp{rear}, @samp{resr}, @samp{rfsr}, @samp{rbtr},
45458@samp{rpvr}, @samp{rpvr1} through @samp{rpvr11}, @samp{redr}, @samp{rpid},
45459@samp{rzpr}, @samp{rtlbx}, @samp{rtlbsx}, @samp{rtlblo}, and @samp{rtlbhi}.
45460
45461The @samp{org.gnu.gdb.microblaze.stack-protect} feature is optional.
45462If present, it should contain registers @samp{rshr} and @samp{rslr}
45463
45464@node MIPS Features
45465@subsection @acronym{MIPS} Features
45466@cindex target descriptions, @acronym{MIPS} features
45467
45468The @samp{org.gnu.gdb.mips.cpu} feature is required for @acronym{MIPS} targets.
45469It should contain registers @samp{r0} through @samp{r31}, @samp{lo},
45470@samp{hi}, and @samp{pc}.  They may be 32-bit or 64-bit depending
45471on the target.
45472
45473The @samp{org.gnu.gdb.mips.cp0} feature is also required.  It should
45474contain at least the @samp{status}, @samp{badvaddr}, and @samp{cause}
45475registers.  They may be 32-bit or 64-bit depending on the target.
45476
45477The @samp{org.gnu.gdb.mips.fpu} feature is currently required, though
45478it may be optional in a future version of @value{GDBN}.  It should
45479contain registers @samp{f0} through @samp{f31}, @samp{fcsr}, and
45480@samp{fir}.  They may be 32-bit or 64-bit depending on the target.
45481
45482The @samp{org.gnu.gdb.mips.dsp} feature is optional.  It should
45483contain registers @samp{hi1} through @samp{hi3}, @samp{lo1} through
45484@samp{lo3}, and @samp{dspctl}.  The @samp{dspctl} register should
45485be 32-bit and the rest may be 32-bit or 64-bit depending on the target.
45486
45487The @samp{org.gnu.gdb.mips.linux} feature is optional.  It should
45488contain a single register, @samp{restart}, which is used by the
45489Linux kernel to control restartable syscalls.
45490
45491@node M68K Features
45492@subsection M68K Features
45493@cindex target descriptions, M68K features
45494
45495@table @code
45496@item @samp{org.gnu.gdb.m68k.core}
45497@itemx @samp{org.gnu.gdb.coldfire.core}
45498@itemx @samp{org.gnu.gdb.fido.core}
45499One of those features must be always present.
45500The feature that is present determines which flavor of m68k is
45501used.  The feature that is present should contain registers
45502@samp{d0} through @samp{d7}, @samp{a0} through @samp{a5}, @samp{fp},
45503@samp{sp}, @samp{ps} and @samp{pc}.
45504
45505@item @samp{org.gnu.gdb.coldfire.fp}
45506This feature is optional.  If present, it should contain registers
45507@samp{fp0} through @samp{fp7}, @samp{fpcontrol}, @samp{fpstatus} and
45508@samp{fpiaddr}.
45509
45510Note that, despite the fact that this feature's name says
45511@samp{coldfire}, it is used to describe any floating point registers.
45512The size of the registers must match the main m68k flavor; so, for
45513example, if the primary feature is reported as @samp{coldfire}, then
4551464-bit floating point registers are required.
45515@end table
45516
45517@node NDS32 Features
45518@subsection NDS32 Features
45519@cindex target descriptions, NDS32 features
45520
45521The @samp{org.gnu.gdb.nds32.core} feature is required for NDS32
45522targets.  It should contain at least registers @samp{r0} through
45523@samp{r10}, @samp{r15}, @samp{fp}, @samp{gp}, @samp{lp}, @samp{sp},
45524and @samp{pc}.
45525
45526The @samp{org.gnu.gdb.nds32.fpu} feature is optional.  If present,
45527it should contain 64-bit double-precision floating-point registers
45528@samp{fd0} through @emph{fdN}, which should be @samp{fd3}, @samp{fd7},
45529@samp{fd15}, or @samp{fd31} based on the FPU configuration implemented.
45530
45531@emph{Note:} The first sixteen 64-bit double-precision floating-point
45532registers are overlapped with the thirty-two 32-bit single-precision
45533floating-point registers.  The 32-bit single-precision registers, if
45534not being listed explicitly, will be synthesized from halves of the
45535overlapping 64-bit double-precision registers.  Listing 32-bit
45536single-precision registers explicitly is deprecated, and the
45537support to it could be totally removed some day.
45538
45539@node Nios II Features
45540@subsection Nios II Features
45541@cindex target descriptions, Nios II features
45542
45543The @samp{org.gnu.gdb.nios2.cpu} feature is required for Nios II
45544targets.  It should contain the 32 core registers (@samp{zero},
45545@samp{at}, @samp{r2} through @samp{r23}, @samp{et} through @samp{ra}),
45546@samp{pc}, and the 16 control registers (@samp{status} through
45547@samp{mpuacc}).
45548
45549@node OpenRISC 1000 Features
45550@subsection Openrisc 1000 Features
45551@cindex target descriptions, OpenRISC 1000 features
45552
45553The @samp{org.gnu.gdb.or1k.group0} feature is required for OpenRISC 1000
45554targets.  It should contain the 32 general purpose registers (@samp{r0}
45555through @samp{r31}), @samp{ppc}, @samp{npc} and @samp{sr}.
45556
45557@node PowerPC Features
45558@subsection PowerPC Features
45559@cindex target descriptions, PowerPC features
45560
45561The @samp{org.gnu.gdb.power.core} feature is required for PowerPC
45562targets.  It should contain registers @samp{r0} through @samp{r31},
45563@samp{pc}, @samp{msr}, @samp{cr}, @samp{lr}, @samp{ctr}, and
45564@samp{xer}.  They may be 32-bit or 64-bit depending on the target.
45565
45566The @samp{org.gnu.gdb.power.fpu} feature is optional.  It should
45567contain registers @samp{f0} through @samp{f31} and @samp{fpscr}.
45568
45569The @samp{org.gnu.gdb.power.altivec} feature is optional.  It should
45570contain registers @samp{vr0} through @samp{vr31}, @samp{vscr}, and
45571@samp{vrsave}.  @value{GDBN} will define pseudo-registers @samp{v0}
45572through @samp{v31} as aliases for the corresponding @samp{vrX}
45573registers.
45574
45575The @samp{org.gnu.gdb.power.vsx} feature is optional.  It should
45576contain registers @samp{vs0h} through @samp{vs31h}.  @value{GDBN} will
45577combine these registers with the floating point registers (@samp{f0}
45578through @samp{f31}) and the altivec registers (@samp{vr0} through
45579@samp{vr31}) to present the 128-bit wide registers @samp{vs0} through
45580@samp{vs63}, the set of vector-scalar registers for POWER7.
45581Therefore, this feature requires both @samp{org.gnu.gdb.power.fpu} and
45582@samp{org.gnu.gdb.power.altivec}.
45583
45584The @samp{org.gnu.gdb.power.spe} feature is optional.  It should
45585contain registers @samp{ev0h} through @samp{ev31h}, @samp{acc}, and
45586@samp{spefscr}.  SPE targets should provide 32-bit registers in
45587@samp{org.gnu.gdb.power.core} and provide the upper halves in
45588@samp{ev0h} through @samp{ev31h}.  @value{GDBN} will combine
45589these to present registers @samp{ev0} through @samp{ev31} to the
45590user.
45591
45592The @samp{org.gnu.gdb.power.ppr} feature is optional.  It should
45593contain the 64-bit register @samp{ppr}.
45594
45595The @samp{org.gnu.gdb.power.dscr} feature is optional.  It should
45596contain the 64-bit register @samp{dscr}.
45597
45598The @samp{org.gnu.gdb.power.tar} feature is optional.  It should
45599contain the 64-bit register @samp{tar}.
45600
45601The @samp{org.gnu.gdb.power.ebb} feature is optional.  It should
45602contain registers @samp{bescr}, @samp{ebbhr} and @samp{ebbrr}, all
4560364-bit wide.
45604
45605The @samp{org.gnu.gdb.power.linux.pmu} feature is optional.  It should
45606contain registers @samp{mmcr0}, @samp{mmcr2}, @samp{siar}, @samp{sdar}
45607and @samp{sier}, all 64-bit wide.  This is the subset of the isa 2.07
45608server PMU registers provided by @sc{gnu}/Linux.
45609
45610The @samp{org.gnu.gdb.power.htm.spr} feature is optional.  It should
45611contain registers @samp{tfhar}, @samp{texasr} and @samp{tfiar}, all
4561264-bit wide.
45613
45614The @samp{org.gnu.gdb.power.htm.core} feature is optional.  It should
45615contain the checkpointed general-purpose registers @samp{cr0} through
45616@samp{cr31}, as well as the checkpointed registers @samp{clr} and
45617@samp{cctr}.  These registers may all be either 32-bit or 64-bit
45618depending on the target.  It should also contain the checkpointed
45619registers @samp{ccr} and @samp{cxer}, which should both be 32-bit
45620wide.
45621
45622The @samp{org.gnu.gdb.power.htm.fpu} feature is optional.  It should
45623contain the checkpointed 64-bit floating-point registers @samp{cf0}
45624through @samp{cf31}, as well as the checkpointed 64-bit register
45625@samp{cfpscr}.
45626
45627The @samp{org.gnu.gdb.power.htm.altivec} feature is optional.  It
45628should contain the checkpointed altivec registers @samp{cvr0} through
45629@samp{cvr31}, all 128-bit wide.  It should also contain the
45630checkpointed registers @samp{cvscr} and @samp{cvrsave}, both 32-bit
45631wide.
45632
45633The @samp{org.gnu.gdb.power.htm.vsx} feature is optional.  It should
45634contain registers @samp{cvs0h} through @samp{cvs31h}.  @value{GDBN}
45635will combine these registers with the checkpointed floating point
45636registers (@samp{cf0} through @samp{cf31}) and the checkpointed
45637altivec registers (@samp{cvr0} through @samp{cvr31}) to present the
45638128-bit wide checkpointed vector-scalar registers @samp{cvs0} through
45639@samp{cvs63}.  Therefore, this feature requires both
45640@samp{org.gnu.gdb.power.htm.altivec} and
45641@samp{org.gnu.gdb.power.htm.fpu}.
45642
45643The @samp{org.gnu.gdb.power.htm.ppr} feature is optional.  It should
45644contain the 64-bit checkpointed register @samp{cppr}.
45645
45646The @samp{org.gnu.gdb.power.htm.dscr} feature is optional.  It should
45647contain the 64-bit checkpointed register @samp{cdscr}.
45648
45649The @samp{org.gnu.gdb.power.htm.tar} feature is optional.  It should
45650contain the 64-bit checkpointed register @samp{ctar}.
45651
45652
45653@node RISC-V Features
45654@subsection RISC-V Features
45655@cindex target descriptions, RISC-V Features
45656
45657The @samp{org.gnu.gdb.riscv.cpu} feature is required for RISC-V
45658targets.  It should contain the registers @samp{x0} through
45659@samp{x31}, and @samp{pc}.  Either the architectural names (@samp{x0},
45660@samp{x1}, etc) can be used, or the ABI names (@samp{zero}, @samp{ra},
45661etc).
45662
45663The @samp{org.gnu.gdb.riscv.fpu} feature is optional.  If present, it
45664should contain registers @samp{f0} through @samp{f31}, @samp{fflags},
45665@samp{frm}, and @samp{fcsr}.  As with the cpu feature, either the
45666architectural register names, or the ABI names can be used.
45667
45668The @samp{org.gnu.gdb.riscv.virtual} feature is optional.  If present,
45669it should contain registers that are not backed by real registers on
45670the target, but are instead virtual, where the register value is
45671derived from other target state.  In many ways these are like
45672@value{GDBN}s pseudo-registers, except implemented by the target.
45673Currently the only register expected in this set is the one byte
45674@samp{priv} register that contains the target's privilege level in the
45675least significant two bits.
45676
45677The @samp{org.gnu.gdb.riscv.csr} feature is optional.  If present, it
45678should contain all of the target's standard CSRs.  Standard CSRs are
45679those defined in the RISC-V specification documents.  There is some
45680overlap between this feature and the fpu feature; the @samp{fflags},
45681@samp{frm}, and @samp{fcsr} registers could be in either feature.  The
45682expectation is that these registers will be in the fpu feature if the
45683target has floating point hardware, but can be moved into the csr
45684feature if the target has the floating point control registers, but no
45685other floating point hardware.
45686
45687@node RX Features
45688@subsection RX Features
45689@cindex target descriptions, RX Features
45690
45691The @samp{org.gnu.gdb.rx.core} feature is required for RX
45692targets.  It should contain the registers @samp{r0} through
45693@samp{r15}, @samp{usp}, @samp{isp}, @samp{psw}, @samp{pc}, @samp{intb},
45694@samp{bpsw}, @samp{bpc}, @samp{fintv}, @samp{fpsw}, and @samp{acc}.
45695
45696@node S/390 and System z Features
45697@subsection S/390 and System z Features
45698@cindex target descriptions, S/390 features
45699@cindex target descriptions, System z features
45700
45701The @samp{org.gnu.gdb.s390.core} feature is required for S/390 and
45702System z targets.  It should contain the PSW and the 16 general
45703registers.  In particular, System z targets should provide the 64-bit
45704registers @samp{pswm}, @samp{pswa}, and @samp{r0} through @samp{r15}.
45705S/390 targets should provide the 32-bit versions of these registers.
45706A System z target that runs in 31-bit addressing mode should provide
4570732-bit versions of @samp{pswm} and @samp{pswa}, as well as the general
45708register's upper halves @samp{r0h} through @samp{r15h}, and their
45709lower halves @samp{r0l} through @samp{r15l}.
45710
45711The @samp{org.gnu.gdb.s390.fpr} feature is required.  It should
45712contain the 64-bit registers @samp{f0} through @samp{f15}, and
45713@samp{fpc}.
45714
45715The @samp{org.gnu.gdb.s390.acr} feature is required.  It should
45716contain the 32-bit registers @samp{acr0} through @samp{acr15}.
45717
45718The @samp{org.gnu.gdb.s390.linux} feature is optional.  It should
45719contain the register @samp{orig_r2}, which is 64-bit wide on System z
45720targets and 32-bit otherwise.  In addition, the feature may contain
45721the @samp{last_break} register, whose width depends on the addressing
45722mode, as well as the @samp{system_call} register, which is always
4572332-bit wide.
45724
45725The @samp{org.gnu.gdb.s390.tdb} feature is optional.  It should
45726contain the 64-bit registers @samp{tdb0}, @samp{tac}, @samp{tct},
45727@samp{atia}, and @samp{tr0} through @samp{tr15}.
45728
45729The @samp{org.gnu.gdb.s390.vx} feature is optional.  It should contain
4573064-bit wide registers @samp{v0l} through @samp{v15l}, which will be
45731combined by @value{GDBN} with the floating point registers @samp{f0}
45732through @samp{f15} to present the 128-bit wide vector registers
45733@samp{v0} through @samp{v15}.  In addition, this feature should
45734contain the 128-bit wide vector registers @samp{v16} through
45735@samp{v31}.
45736
45737The @samp{org.gnu.gdb.s390.gs} feature is optional.  It should contain
45738the 64-bit wide guarded-storage-control registers @samp{gsd},
45739@samp{gssm}, and @samp{gsepla}.
45740
45741The @samp{org.gnu.gdb.s390.gsbc} feature is optional.  It should contain
45742the 64-bit wide guarded-storage broadcast control registers
45743@samp{bc_gsd}, @samp{bc_gssm}, and @samp{bc_gsepla}.
45744
45745@node Sparc Features
45746@subsection Sparc Features
45747@cindex target descriptions, sparc32 features
45748@cindex target descriptions, sparc64 features
45749The @samp{org.gnu.gdb.sparc.cpu} feature is required for sparc32/sparc64
45750targets.  It should describe the following registers:
45751
45752@itemize @minus
45753@item
45754@samp{g0} through @samp{g7}
45755@item
45756@samp{o0} through @samp{o7}
45757@item
45758@samp{l0} through @samp{l7}
45759@item
45760@samp{i0} through @samp{i7}
45761@end itemize
45762
45763They may be 32-bit or 64-bit depending on the target.
45764
45765Also the @samp{org.gnu.gdb.sparc.fpu} feature is required for sparc32/sparc64
45766targets.  It should describe the following registers:
45767
45768@itemize @minus
45769@item
45770@samp{f0} through @samp{f31}
45771@item
45772@samp{f32} through @samp{f62} for sparc64
45773@end itemize
45774
45775The @samp{org.gnu.gdb.sparc.cp0} feature is required for sparc32/sparc64
45776targets.  It should describe the following registers:
45777
45778@itemize @minus
45779@item
45780@samp{y}, @samp{psr}, @samp{wim}, @samp{tbr}, @samp{pc}, @samp{npc},
45781@samp{fsr}, and @samp{csr} for sparc32
45782@item
45783@samp{pc}, @samp{npc}, @samp{state}, @samp{fsr}, @samp{fprs}, and @samp{y}
45784for sparc64
45785@end itemize
45786
45787@node TIC6x Features
45788@subsection TMS320C6x Features
45789@cindex target descriptions, TIC6x features
45790@cindex target descriptions, TMS320C6x features
45791The @samp{org.gnu.gdb.tic6x.core} feature is required for TMS320C6x
45792targets.  It should contain registers @samp{A0} through @samp{A15},
45793registers @samp{B0} through @samp{B15}, @samp{CSR} and @samp{PC}.
45794
45795The @samp{org.gnu.gdb.tic6x.gp} feature is optional.  It should
45796contain registers @samp{A16} through @samp{A31} and @samp{B16}
45797through @samp{B31}.
45798
45799The @samp{org.gnu.gdb.tic6x.c6xp} feature is optional.  It should
45800contain registers @samp{TSR}, @samp{ILC} and @samp{RILC}.
45801
45802@node Operating System Information
45803@appendix Operating System Information
45804@cindex operating system information
45805
45806@menu
45807* Process list::
45808@end menu
45809
45810Users of @value{GDBN} often wish to obtain information about the state of
45811the operating system running on the target---for example the list of
45812processes, or the list of open files.  This section describes the
45813mechanism that makes it possible.  This mechanism is similar to the
45814target features mechanism (@pxref{Target Descriptions}), but focuses
45815on a different aspect of target.
45816
45817Operating system information is retrieved from the target via the
45818remote protocol, using @samp{qXfer} requests (@pxref{qXfer osdata
45819read}).  The object name in the request should be @samp{osdata}, and
45820the @var{annex} identifies the data to be fetched.
45821
45822@node Process list
45823@appendixsection Process list
45824@cindex operating system information, process list
45825
45826When requesting the process list, the @var{annex} field in the
45827@samp{qXfer} request should be @samp{processes}.  The returned data is
45828an XML document.  The formal syntax of this document is defined in
45829@file{gdb/features/osdata.dtd}.
45830
45831An example document is:
45832
45833@smallexample
45834<?xml version="1.0"?>
45835<!DOCTYPE target SYSTEM "osdata.dtd">
45836<osdata type="processes">
45837  <item>
45838    <column name="pid">1</column>
45839    <column name="user">root</column>
45840    <column name="command">/sbin/init</column>
45841    <column name="cores">1,2,3</column>
45842  </item>
45843</osdata>
45844@end smallexample
45845
45846Each item should include a column whose name is @samp{pid}.  The value
45847of that column should identify the process on the target.  The
45848@samp{user} and @samp{command} columns are optional, and will be
45849displayed by @value{GDBN}.  The @samp{cores} column, if present,
45850should contain a comma-separated list of cores that this process
45851is running on.  Target may provide additional columns,
45852which @value{GDBN} currently ignores.
45853
45854@node Trace File Format
45855@appendix Trace File Format
45856@cindex trace file format
45857
45858The trace file comes in three parts: a header, a textual description
45859section, and a trace frame section with binary data.
45860
45861The header has the form @code{\x7fTRACE0\n}.  The first byte is
45862@code{0x7f} so as to indicate that the file contains binary data,
45863while the @code{0} is a version number that may have different values
45864in the future.
45865
45866The description section consists of multiple lines of @sc{ascii} text
45867separated by newline characters (@code{0xa}).  The lines may include a
45868variety of optional descriptive or context-setting information, such
45869as tracepoint definitions or register set size.  @value{GDBN} will
45870ignore any line that it does not recognize.  An empty line marks the end
45871of this section.
45872
45873@table @code
45874@item R @var{size}
45875Specifies the size of a register block in bytes.  This is equal to the
45876size of a @code{g} packet payload in the remote protocol.  @var{size}
45877is an ascii decimal number.  There should be only one such line in
45878a single trace file.
45879
45880@item status @var{status}
45881Trace status.  @var{status} has the same format as a @code{qTStatus}
45882remote packet reply.  There should be only one such line in a single trace
45883file.
45884
45885@item tp @var{payload}
45886Tracepoint definition.  The @var{payload} has the same format as
45887@code{qTfP}/@code{qTsP} remote packet reply payload.  A single tracepoint
45888may take multiple lines of definition, corresponding to the multiple
45889reply packets.
45890
45891@item tsv @var{payload}
45892Trace state variable definition.  The @var{payload} has the same format as
45893@code{qTfV}/@code{qTsV} remote packet reply payload.  A single variable
45894may take multiple lines of definition, corresponding to the multiple
45895reply packets.
45896
45897@item tdesc @var{payload}
45898Target description in XML format.  The @var{payload} is a single line of
45899the XML file.  All such lines should be concatenated together to get
45900the original XML file.  This file is in the same format as @code{qXfer}
45901@code{features} payload, and corresponds to the main @code{target.xml}
45902file.  Includes are not allowed.
45903
45904@end table
45905
45906The trace frame section consists of a number of consecutive frames.
45907Each frame begins with a two-byte tracepoint number, followed by a
45908four-byte size giving the amount of data in the frame.  The data in
45909the frame consists of a number of blocks, each introduced by a
45910character indicating its type (at least register, memory, and trace
45911state variable).  The data in this section is raw binary, not a
45912hexadecimal or other encoding; its endianness matches the target's
45913endianness.
45914
45915@c FIXME bi-arch may require endianness/arch info in description section
45916
45917@table @code
45918@item R @var{bytes}
45919Register block.  The number and ordering of bytes matches that of a
45920@code{g} packet in the remote protocol.  Note that these are the
45921actual bytes, in target order, not a hexadecimal encoding.
45922
45923@item M @var{address} @var{length} @var{bytes}...
45924Memory block.  This is a contiguous block of memory, at the 8-byte
45925address @var{address}, with a 2-byte length @var{length}, followed by
45926@var{length} bytes.
45927
45928@item V @var{number} @var{value}
45929Trace state variable block.  This records the 8-byte signed value
45930@var{value} of trace state variable numbered @var{number}.
45931
45932@end table
45933
45934Future enhancements of the trace file format may include additional types
45935of blocks.
45936
45937@node Index Section Format
45938@appendix @code{.gdb_index} section format
45939@cindex .gdb_index section format
45940@cindex index section format
45941
45942This section documents the index section that is created by @code{save
45943gdb-index} (@pxref{Index Files}).  The index section is
45944DWARF-specific; some knowledge of DWARF is assumed in this
45945description.
45946
45947The mapped index file format is designed to be directly
45948@code{mmap}able on any architecture.  In most cases, a datum is
45949represented using a little-endian 32-bit integer value, called an
45950@code{offset_type}.  Big endian machines must byte-swap the values
45951before using them.  Exceptions to this rule are noted.  The data is
45952laid out such that alignment is always respected.
45953
45954A mapped index consists of several areas, laid out in order.
45955
45956@enumerate
45957@item
45958The file header.  This is a sequence of values, of @code{offset_type}
45959unless otherwise noted:
45960
45961@enumerate
45962@item
45963The version number, currently 8.  Versions 1, 2 and 3 are obsolete.
45964Version 4 uses a different hashing function from versions 5 and 6.
45965Version 6 includes symbols for inlined functions, whereas versions 4
45966and 5 do not.  Version 7 adds attributes to the CU indices in the
45967symbol table.  Version 8 specifies that symbols from DWARF type units
45968(@samp{DW_TAG_type_unit}) refer to the type unit's symbol table and not the
45969compilation unit (@samp{DW_TAG_comp_unit}) using the type.
45970
45971@value{GDBN} will only read version 4, 5, or 6 indices
45972by specifying @code{set use-deprecated-index-sections on}.
45973GDB has a workaround for potentially broken version 7 indices so it is
45974currently not flagged as deprecated.
45975
45976@item
45977The offset, from the start of the file, of the CU list.
45978
45979@item
45980The offset, from the start of the file, of the types CU list.  Note
45981that this area can be empty, in which case this offset will be equal
45982to the next offset.
45983
45984@item
45985The offset, from the start of the file, of the address area.
45986
45987@item
45988The offset, from the start of the file, of the symbol table.
45989
45990@item
45991The offset, from the start of the file, of the constant pool.
45992@end enumerate
45993
45994@item
45995The CU list.  This is a sequence of pairs of 64-bit little-endian
45996values, sorted by the CU offset.  The first element in each pair is
45997the offset of a CU in the @code{.debug_info} section.  The second
45998element in each pair is the length of that CU.  References to a CU
45999elsewhere in the map are done using a CU index, which is just the
460000-based index into this table.  Note that if there are type CUs, then
46001conceptually CUs and type CUs form a single list for the purposes of
46002CU indices.
46003
46004@item
46005The types CU list.  This is a sequence of triplets of 64-bit
46006little-endian values.  In a triplet, the first value is the CU offset,
46007the second value is the type offset in the CU, and the third value is
46008the type signature.  The types CU list is not sorted.
46009
46010@item
46011The address area.  The address area consists of a sequence of address
46012entries.  Each address entry has three elements:
46013
46014@enumerate
46015@item
46016The low address.  This is a 64-bit little-endian value.
46017
46018@item
46019The high address.  This is a 64-bit little-endian value.  Like
46020@code{DW_AT_high_pc}, the value is one byte beyond the end.
46021
46022@item
46023The CU index.  This is an @code{offset_type} value.
46024@end enumerate
46025
46026@item
46027The symbol table.  This is an open-addressed hash table.  The size of
46028the hash table is always a power of 2.
46029
46030Each slot in the hash table consists of a pair of @code{offset_type}
46031values.  The first value is the offset of the symbol's name in the
46032constant pool.  The second value is the offset of the CU vector in the
46033constant pool.
46034
46035If both values are 0, then this slot in the hash table is empty.  This
46036is ok because while 0 is a valid constant pool index, it cannot be a
46037valid index for both a string and a CU vector.
46038
46039The hash value for a table entry is computed by applying an
46040iterative hash function to the symbol's name.  Starting with an
46041initial value of @code{r = 0}, each (unsigned) character @samp{c} in
46042the string is incorporated into the hash using the formula depending on the
46043index version:
46044
46045@table @asis
46046@item Version 4
46047The formula is @code{r = r * 67 + c - 113}.
46048
46049@item Versions 5 to 7
46050The formula is @code{r = r * 67 + tolower (c) - 113}.
46051@end table
46052
46053The terminating @samp{\0} is not incorporated into the hash.
46054
46055The step size used in the hash table is computed via
46056@code{((hash * 17) & (size - 1)) | 1}, where @samp{hash} is the hash
46057value, and @samp{size} is the size of the hash table.  The step size
46058is used to find the next candidate slot when handling a hash
46059collision.
46060
46061The names of C@t{++} symbols in the hash table are canonicalized.  We
46062don't currently have a simple description of the canonicalization
46063algorithm; if you intend to create new index sections, you must read
46064the code.
46065
46066@item
46067The constant pool.  This is simply a bunch of bytes.  It is organized
46068so that alignment is correct: CU vectors are stored first, followed by
46069strings.
46070
46071A CU vector in the constant pool is a sequence of @code{offset_type}
46072values.  The first value is the number of CU indices in the vector.
46073Each subsequent value is the index and symbol attributes of a CU in
46074the CU list.  This element in the hash table is used to indicate which
46075CUs define the symbol and how the symbol is used.
46076See below for the format of each CU index+attributes entry.
46077
46078A string in the constant pool is zero-terminated.
46079@end enumerate
46080
46081Attributes were added to CU index values in @code{.gdb_index} version 7.
46082If a symbol has multiple uses within a CU then there is one
46083CU index+attributes value for each use.
46084
46085The format of each CU index+attributes entry is as follows
46086(bit 0 = LSB):
46087
46088@table @asis
46089
46090@item Bits 0-23
46091This is the index of the CU in the CU list.
46092@item Bits 24-27
46093These bits are reserved for future purposes and must be zero.
46094@item Bits 28-30
46095The kind of the symbol in the CU.
46096
46097@table @asis
46098@item 0
46099This value is reserved and should not be used.
46100By reserving zero the full @code{offset_type} value is backwards compatible
46101with previous versions of the index.
46102@item 1
46103The symbol is a type.
46104@item 2
46105The symbol is a variable or an enum value.
46106@item 3
46107The symbol is a function.
46108@item 4
46109Any other kind of symbol.
46110@item 5,6,7
46111These values are reserved.
46112@end table
46113
46114@item Bit 31
46115This bit is zero if the value is global and one if it is static.
46116
46117The determination of whether a symbol is global or static is complicated.
46118The authorative reference is the file @file{dwarf2read.c} in
46119@value{GDBN} sources.
46120
46121@end table
46122
46123This pseudo-code describes the computation of a symbol's kind and
46124global/static attributes in the index.
46125
46126@smallexample
46127is_external = get_attribute (die, DW_AT_external);
46128language = get_attribute (cu_die, DW_AT_language);
46129switch (die->tag)
46130  @{
46131  case DW_TAG_typedef:
46132  case DW_TAG_base_type:
46133  case DW_TAG_subrange_type:
46134    kind = TYPE;
46135    is_static = 1;
46136    break;
46137  case DW_TAG_enumerator:
46138    kind = VARIABLE;
46139    is_static = language != CPLUS;
46140    break;
46141  case DW_TAG_subprogram:
46142    kind = FUNCTION;
46143    is_static = ! (is_external || language == ADA);
46144    break;
46145  case DW_TAG_constant:
46146    kind = VARIABLE;
46147    is_static = ! is_external;
46148    break;
46149  case DW_TAG_variable:
46150    kind = VARIABLE;
46151    is_static = ! is_external;
46152    break;
46153  case DW_TAG_namespace:
46154    kind = TYPE;
46155    is_static = 0;
46156    break;
46157  case DW_TAG_class_type:
46158  case DW_TAG_interface_type:
46159  case DW_TAG_structure_type:
46160  case DW_TAG_union_type:
46161  case DW_TAG_enumeration_type:
46162    kind = TYPE;
46163    is_static = language != CPLUS;
46164    break;
46165  default:
46166    assert (0);
46167  @}
46168@end smallexample
46169
46170@node Man Pages
46171@appendix Manual pages
46172@cindex Man pages
46173
46174@menu
46175* gdb man::                     The GNU Debugger man page
46176* gdbserver man::               Remote Server for the GNU Debugger man page
46177* gcore man::                   Generate a core file of a running program
46178* gdbinit man::                 gdbinit scripts
46179* gdb-add-index man::           Add index files to speed up GDB
46180@end menu
46181
46182@node gdb man
46183@heading gdb man
46184
46185@c man title gdb The GNU Debugger
46186
46187@c man begin SYNOPSIS gdb
46188gdb [@option{-help}] [@option{-nh}] [@option{-nx}] [@option{-q}]
46189[@option{-batch}] [@option{-cd=}@var{dir}] [@option{-f}]
46190[@option{-b}@w{ }@var{bps}]
46191    [@option{-tty=}@var{dev}] [@option{-s} @var{symfile}]
46192[@option{-e}@w{ }@var{prog}] [@option{-se}@w{ }@var{prog}]
46193[@option{-c}@w{ }@var{core}] [@option{-p}@w{ }@var{procID}]
46194    [@option{-x}@w{ }@var{cmds}] [@option{-d}@w{ }@var{dir}]
46195[@var{prog}|@var{prog} @var{procID}|@var{prog} @var{core}]
46196@c man end
46197
46198@c man begin DESCRIPTION gdb
46199The purpose of a debugger such as @value{GDBN} is to allow you to see what is
46200going on ``inside'' another program while it executes -- or what another
46201program was doing at the moment it crashed.
46202
46203@value{GDBN} can do four main kinds of things (plus other things in support of
46204these) to help you catch bugs in the act:
46205
46206@itemize @bullet
46207@item
46208Start your program, specifying anything that might affect its behavior.
46209
46210@item
46211Make your program stop on specified conditions.
46212
46213@item
46214Examine what has happened, when your program has stopped.
46215
46216@item
46217Change things in your program, so you can experiment with correcting the
46218effects of one bug and go on to learn about another.
46219@end itemize
46220
46221You can use @value{GDBN} to debug programs written in C, C@t{++}, Fortran and
46222Modula-2.
46223
46224@value{GDBN} is invoked with the shell command @code{gdb}.  Once started, it reads
46225commands from the terminal until you tell it to exit with the @value{GDBN}
46226command @code{quit}.  You can get online help from @value{GDBN} itself
46227by using the command @code{help}.
46228
46229You can run @code{gdb} with no arguments or options; but the most
46230usual way to start @value{GDBN} is with one argument or two, specifying an
46231executable program as the argument:
46232
46233@smallexample
46234gdb program
46235@end smallexample
46236
46237You can also start with both an executable program and a core file specified:
46238
46239@smallexample
46240gdb program core
46241@end smallexample
46242
46243You can, instead, specify a process ID as a second argument or use option
46244@code{-p}, if you want to debug a running process:
46245
46246@smallexample
46247gdb program 1234
46248gdb -p 1234
46249@end smallexample
46250
46251@noindent
46252would attach @value{GDBN} to process @code{1234}.  With option @option{-p} you
46253can omit the @var{program} filename.
46254
46255Here are some of the most frequently needed @value{GDBN} commands:
46256
46257@c pod2man highlights the right hand side of the @item lines.
46258@table @env
46259@item break [@var{file}:]@var{function}
46260Set a breakpoint at @var{function} (in @var{file}).
46261
46262@item run [@var{arglist}]
46263Start your program (with @var{arglist}, if specified).
46264
46265@item bt
46266Backtrace: display the program stack.
46267
46268@item print @var{expr}
46269Display the value of an expression.
46270
46271@item c
46272Continue running your program (after stopping, e.g. at a breakpoint).
46273
46274@item next
46275Execute next program line (after stopping); step @emph{over} any
46276function calls in the line.
46277
46278@item edit [@var{file}:]@var{function}
46279look at the program line where it is presently stopped.
46280
46281@item list [@var{file}:]@var{function}
46282type the text of the program in the vicinity of where it is presently stopped.
46283
46284@item step
46285Execute next program line (after stopping); step @emph{into} any
46286function calls in the line.
46287
46288@item help [@var{name}]
46289Show information about @value{GDBN} command @var{name}, or general information
46290about using @value{GDBN}.
46291
46292@item quit
46293Exit from @value{GDBN}.
46294@end table
46295
46296@ifset man
46297For full details on @value{GDBN},
46298see @cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46299by Richard M. Stallman and Roland H. Pesch.  The same text is available online
46300as the @code{gdb} entry in the @code{info} program.
46301@end ifset
46302@c man end
46303
46304@c man begin OPTIONS gdb
46305Any arguments other than options specify an executable
46306file and core file (or process ID); that is, the first argument
46307encountered with no
46308associated option flag is equivalent to a @option{-se} option, and the second,
46309if any, is equivalent to a @option{-c} option if it's the name of a file.
46310Many options have
46311both long and short forms; both are shown here.  The long forms are also
46312recognized if you truncate them, so long as enough of the option is
46313present to be unambiguous.  (If you prefer, you can flag option
46314arguments with @option{+} rather than @option{-}, though we illustrate the
46315more usual convention.)
46316
46317All the options and command line arguments you give are processed
46318in sequential order.  The order makes a difference when the @option{-x}
46319option is used.
46320
46321@table @env
46322@item -help
46323@itemx -h
46324List all options, with brief explanations.
46325
46326@item -symbols=@var{file}
46327@itemx -s @var{file}
46328Read symbol table from file @var{file}.
46329
46330@item -write
46331Enable writing into executable and core files.
46332
46333@item -exec=@var{file}
46334@itemx -e @var{file}
46335Use file @var{file} as the executable file to execute when
46336appropriate, and for examining pure data in conjunction with a core
46337dump.
46338
46339@item -se=@var{file}
46340Read symbol table from file @var{file} and use it as the executable
46341file.
46342
46343@item -core=@var{file}
46344@itemx -c @var{file}
46345Use file @var{file} as a core dump to examine.
46346
46347@item -command=@var{file}
46348@itemx -x @var{file}
46349Execute @value{GDBN} commands from file @var{file}.
46350
46351@item -ex @var{command}
46352Execute given @value{GDBN} @var{command}.
46353
46354@item -directory=@var{directory}
46355@itemx -d @var{directory}
46356Add @var{directory} to the path to search for source files.
46357
46358@item -nh
46359Do not execute commands from @file{~/.gdbinit}.
46360
46361@item -nx
46362@itemx -n
46363Do not execute commands from any @file{.gdbinit} initialization files.
46364
46365@item -quiet
46366@itemx -q
46367``Quiet''.  Do not print the introductory and copyright messages.  These
46368messages are also suppressed in batch mode.
46369
46370@item -batch
46371Run in batch mode.  Exit with status @code{0} after processing all the command
46372files specified with @option{-x} (and @file{.gdbinit}, if not inhibited).
46373Exit with nonzero status if an error occurs in executing the @value{GDBN}
46374commands in the command files.
46375
46376Batch mode may be useful for running @value{GDBN} as a filter, for example to
46377download and run a program on another computer; in order to make this
46378more useful, the message
46379
46380@smallexample
46381Program exited normally.
46382@end smallexample
46383
46384@noindent
46385(which is ordinarily issued whenever a program running under @value{GDBN} control
46386terminates) is not issued when running in batch mode.
46387
46388@item -cd=@var{directory}
46389Run @value{GDBN} using @var{directory} as its working directory,
46390instead of the current directory.
46391
46392@item -fullname
46393@itemx -f
46394Emacs sets this option when it runs @value{GDBN} as a subprocess.  It tells
46395@value{GDBN} to output the full file name and line number in a standard,
46396recognizable fashion each time a stack frame is displayed (which
46397includes each time the program stops).  This recognizable format looks
46398like two @samp{\032} characters, followed by the file name, line number
46399and character position separated by colons, and a newline.  The
46400Emacs-to-@value{GDBN} interface program uses the two @samp{\032}
46401characters as a signal to display the source code for the frame.
46402
46403@item -b @var{bps}
46404Set the line speed (baud rate or bits per second) of any serial
46405interface used by @value{GDBN} for remote debugging.
46406
46407@item -tty=@var{device}
46408Run using @var{device} for your program's standard input and output.
46409@end table
46410@c man end
46411
46412@c man begin SEEALSO gdb
46413@ifset man
46414The full documentation for @value{GDBN} is maintained as a Texinfo manual.
46415If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
46416documentation are properly installed at your site, the command
46417
46418@smallexample
46419info gdb
46420@end smallexample
46421
46422@noindent
46423should give you access to the complete manual.
46424
46425@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46426Richard M. Stallman and Roland H. Pesch, July 1991.
46427@end ifset
46428@c man end
46429
46430@node gdbserver man
46431@heading gdbserver man
46432
46433@c man title gdbserver Remote Server for the GNU Debugger
46434@format
46435@c man begin SYNOPSIS gdbserver
46436gdbserver @var{comm} @var{prog} [@var{args}@dots{}]
46437
46438gdbserver --attach @var{comm} @var{pid}
46439
46440gdbserver --multi @var{comm}
46441@c man end
46442@end format
46443
46444@c man begin DESCRIPTION gdbserver
46445@command{gdbserver} is a program that allows you to run @value{GDBN} on a different machine
46446than the one which is running the program being debugged.
46447
46448@ifclear man
46449@subheading Usage (server (target) side)
46450@end ifclear
46451@ifset man
46452Usage (server (target) side):
46453@end ifset
46454
46455First, you need to have a copy of the program you want to debug put onto
46456the target system.  The program can be stripped to save space if needed, as
46457@command{gdbserver} doesn't care about symbols.  All symbol handling is taken care of by
46458the @value{GDBN} running on the host system.
46459
46460To use the server, you log on to the target system, and run the @command{gdbserver}
46461program.  You must tell it (a) how to communicate with @value{GDBN}, (b) the name of
46462your program, and (c) its arguments.  The general syntax is:
46463
46464@smallexample
46465target> gdbserver @var{comm} @var{program} [@var{args} ...]
46466@end smallexample
46467
46468For example, using a serial port, you might say:
46469
46470@smallexample
46471@ifset man
46472@c @file would wrap it as F</dev/com1>.
46473target> gdbserver /dev/com1 emacs foo.txt
46474@end ifset
46475@ifclear man
46476target> gdbserver @file{/dev/com1} emacs foo.txt
46477@end ifclear
46478@end smallexample
46479
46480This tells @command{gdbserver} to debug emacs with an argument of foo.txt, and
46481to communicate with @value{GDBN} via @file{/dev/com1}.  @command{gdbserver} now
46482waits patiently for the host @value{GDBN} to communicate with it.
46483
46484To use a TCP connection, you could say:
46485
46486@smallexample
46487target> gdbserver host:2345 emacs foo.txt
46488@end smallexample
46489
46490This says pretty much the same thing as the last example, except that we are
46491going to communicate with the @code{host} @value{GDBN} via TCP.  The @code{host:2345} argument means
46492that we are expecting to see a TCP connection from @code{host} to local TCP port
464932345.  (Currently, the @code{host} part is ignored.)  You can choose any number you
46494want for the port number as long as it does not conflict with any existing TCP
46495ports on the target system.  This same port number must be used in the host
46496@value{GDBN}s @code{target remote} command, which will be described shortly.  Note that if
46497you chose a port number that conflicts with another service, @command{gdbserver} will
46498print an error message and exit.
46499
46500@command{gdbserver} can also attach to running programs.
46501This is accomplished via the @option{--attach} argument.  The syntax is:
46502
46503@smallexample
46504target> gdbserver --attach @var{comm} @var{pid}
46505@end smallexample
46506
46507@var{pid} is the process ID of a currently running process.  It isn't
46508necessary to point @command{gdbserver} at a binary for the running process.
46509
46510To start @code{gdbserver} without supplying an initial command to run
46511or process ID to attach, use the @option{--multi} command line option.
46512In such case you should connect using @kbd{target extended-remote} to start
46513the program you want to debug.
46514
46515@smallexample
46516target> gdbserver --multi @var{comm}
46517@end smallexample
46518
46519@ifclear man
46520@subheading Usage (host side)
46521@end ifclear
46522@ifset man
46523Usage (host side):
46524@end ifset
46525
46526You need an unstripped copy of the target program on your host system, since
46527@value{GDBN} needs to examine its symbol tables and such.  Start up @value{GDBN} as you normally
46528would, with the target program as the first argument.  (You may need to use the
46529@option{--baud} option if the serial line is running at anything except 9600 baud.)
46530That is @code{gdb TARGET-PROG}, or @code{gdb --baud BAUD TARGET-PROG}.  After that, the only
46531new command you need to know about is @code{target remote}
46532(or @code{target extended-remote}).  Its argument is either
46533a device name (usually a serial device, like @file{/dev/ttyb}), or a @code{HOST:PORT}
46534descriptor.  For example:
46535
46536@smallexample
46537@ifset man
46538@c @file would wrap it as F</dev/ttyb>.
46539(gdb) target remote /dev/ttyb
46540@end ifset
46541@ifclear man
46542(gdb) target remote @file{/dev/ttyb}
46543@end ifclear
46544@end smallexample
46545
46546@noindent
46547communicates with the server via serial line @file{/dev/ttyb}, and:
46548
46549@smallexample
46550(gdb) target remote the-target:2345
46551@end smallexample
46552
46553@noindent
46554communicates via a TCP connection to port 2345 on host `the-target', where
46555you previously started up @command{gdbserver} with the same port number.  Note that for
46556TCP connections, you must start up @command{gdbserver} prior to using the `target remote'
46557command, otherwise you may get an error that looks something like
46558`Connection refused'.
46559
46560@command{gdbserver} can also debug multiple inferiors at once,
46561described in
46562@ifset man
46563the @value{GDBN} manual in node @code{Inferiors Connections and Programs}
46564-- shell command @code{info -f gdb -n 'Inferiors Connections and Programs'}.
46565@end ifset
46566@ifclear man
46567@ref{Inferiors Connections and Programs}.
46568@end ifclear
46569In such case use the @code{extended-remote} @value{GDBN} command variant:
46570
46571@smallexample
46572(gdb) target extended-remote the-target:2345
46573@end smallexample
46574
46575The @command{gdbserver} option @option{--multi} may or may not be used in such
46576case.
46577@c man end
46578
46579@c man begin OPTIONS gdbserver
46580There are three different modes for invoking @command{gdbserver}:
46581
46582@itemize @bullet
46583
46584@item
46585Debug a specific program specified by its program name:
46586
46587@smallexample
46588gdbserver @var{comm} @var{prog} [@var{args}@dots{}]
46589@end smallexample
46590
46591The @var{comm} parameter specifies how should the server communicate
46592with @value{GDBN}; it is either a device name (to use a serial line),
46593a TCP port number (@code{:1234}), or @code{-} or @code{stdio} to use
46594stdin/stdout of @code{gdbserver}.  Specify the name of the program to
46595debug in @var{prog}.  Any remaining arguments will be passed to the
46596program verbatim.  When the program exits, @value{GDBN} will close the
46597connection, and @code{gdbserver} will exit.
46598
46599@item
46600Debug a specific program by specifying the process ID of a running
46601program:
46602
46603@smallexample
46604gdbserver --attach @var{comm} @var{pid}
46605@end smallexample
46606
46607The @var{comm} parameter is as described above.  Supply the process ID
46608of a running program in @var{pid}; @value{GDBN} will do everything
46609else.  Like with the previous mode, when the process @var{pid} exits,
46610@value{GDBN} will close the connection, and @code{gdbserver} will exit.
46611
46612@item
46613Multi-process mode -- debug more than one program/process:
46614
46615@smallexample
46616gdbserver --multi @var{comm}
46617@end smallexample
46618
46619In this mode, @value{GDBN} can instruct @command{gdbserver} which
46620command(s) to run.  Unlike the other 2 modes, @value{GDBN} will not
46621close the connection when a process being debugged exits, so you can
46622debug several processes in the same session.
46623@end itemize
46624
46625In each of the modes you may specify these options:
46626
46627@table @env
46628
46629@item --help
46630List all options, with brief explanations.
46631
46632@item --version
46633This option causes @command{gdbserver} to print its version number and exit.
46634
46635@item --attach
46636@command{gdbserver} will attach to a running program.  The syntax is:
46637
46638@smallexample
46639target> gdbserver --attach @var{comm} @var{pid}
46640@end smallexample
46641
46642@var{pid} is the process ID of a currently running process.  It isn't
46643necessary to point @command{gdbserver} at a binary for the running process.
46644
46645@item --multi
46646To start @code{gdbserver} without supplying an initial command to run
46647or process ID to attach, use this command line option.
46648Then you can connect using @kbd{target extended-remote} and start
46649the program you want to debug.  The syntax is:
46650
46651@smallexample
46652target> gdbserver --multi @var{comm}
46653@end smallexample
46654
46655@item --debug
46656Instruct @code{gdbserver} to display extra status information about the debugging
46657process.
46658This option is intended for @code{gdbserver} development and for bug reports to
46659the developers.
46660
46661@item --remote-debug
46662Instruct @code{gdbserver} to display remote protocol debug output.
46663This option is intended for @code{gdbserver} development and for bug reports to
46664the developers.
46665
46666@item --debug-file=@var{filename}
46667Instruct @code{gdbserver} to send any debug output to the given @var{filename}.
46668This option is intended for @code{gdbserver} development and for bug reports to
46669the developers.
46670
46671@item --debug-format=option1@r{[},option2,...@r{]}
46672Instruct @code{gdbserver} to include extra information in each line
46673of debugging output.
46674@xref{Other Command-Line Arguments for gdbserver}.
46675
46676@item --wrapper
46677Specify a wrapper to launch programs
46678for debugging.  The option should be followed by the name of the
46679wrapper, then any command-line arguments to pass to the wrapper, then
46680@kbd{--} indicating the end of the wrapper arguments.
46681
46682@item --once
46683By default, @command{gdbserver} keeps the listening TCP port open, so that
46684additional connections are possible.  However, if you start @code{gdbserver}
46685with the @option{--once} option, it will stop listening for any further
46686connection attempts after connecting to the first @value{GDBN} session.
46687
46688@c --disable-packet is not documented for users.
46689
46690@c --disable-randomization and --no-disable-randomization are superseded by
46691@c QDisableRandomization.
46692
46693@end table
46694@c man end
46695
46696@c man begin SEEALSO gdbserver
46697@ifset man
46698The full documentation for @value{GDBN} is maintained as a Texinfo manual.
46699If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
46700documentation are properly installed at your site, the command
46701
46702@smallexample
46703info gdb
46704@end smallexample
46705
46706should give you access to the complete manual.
46707
46708@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46709Richard M. Stallman and Roland H. Pesch, July 1991.
46710@end ifset
46711@c man end
46712
46713@node gcore man
46714@heading gcore
46715
46716@c man title gcore Generate a core file of a running program
46717
46718@format
46719@c man begin SYNOPSIS gcore
46720gcore [-a] [-o @var{prefix}] @var{pid1} [@var{pid2}...@var{pidN}]
46721@c man end
46722@end format
46723
46724@c man begin DESCRIPTION gcore
46725Generate core dumps of one or more running programs with process IDs
46726@var{pid1}, @var{pid2}, etc.  A core file produced by @command{gcore}
46727is equivalent to one produced by the kernel when the process crashes
46728(and when @kbd{ulimit -c} was used to set up an appropriate core dump
46729limit).  However, unlike after a crash, after @command{gcore} finishes
46730its job the program remains running without any change.
46731@c man end
46732
46733@c man begin OPTIONS gcore
46734@table @env
46735@item -a
46736Dump all memory mappings.  The actual effect of this option depends on
46737the Operating System.  On @sc{gnu}/Linux, it will disable
46738@code{use-coredump-filter} (@pxref{set use-coredump-filter}) and
46739enable @code{dump-excluded-mappings} (@pxref{set
46740dump-excluded-mappings}).
46741
46742@item -o @var{prefix}
46743The optional argument @var{prefix} specifies the prefix to be used
46744when composing the file names of the core dumps.  The file name is
46745composed as @file{@var{prefix}.@var{pid}}, where @var{pid} is the
46746process ID of the running program being analyzed by @command{gcore}.
46747If not specified, @var{prefix} defaults to @var{gcore}.
46748@end table
46749@c man end
46750
46751@c man begin SEEALSO gcore
46752@ifset man
46753The full documentation for @value{GDBN} is maintained as a Texinfo manual.
46754If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
46755documentation are properly installed at your site, the command
46756
46757@smallexample
46758info gdb
46759@end smallexample
46760
46761@noindent
46762should give you access to the complete manual.
46763
46764@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46765Richard M. Stallman and Roland H. Pesch, July 1991.
46766@end ifset
46767@c man end
46768
46769@node gdbinit man
46770@heading gdbinit
46771
46772@c man title gdbinit GDB initialization scripts
46773
46774@format
46775@c man begin SYNOPSIS gdbinit
46776@ifset SYSTEM_GDBINIT
46777@value{SYSTEM_GDBINIT}
46778@end ifset
46779
46780@ifset SYSTEM_GDBINIT_DIR
46781@value{SYSTEM_GDBINIT_DIR}/*
46782@end ifset
46783
46784~/.gdbinit
46785
46786./.gdbinit
46787@c man end
46788@end format
46789
46790@c man begin DESCRIPTION gdbinit
46791These files contain @value{GDBN} commands to automatically execute during
46792@value{GDBN} startup.  The lines of contents are canned sequences of commands,
46793described in
46794@ifset man
46795the @value{GDBN} manual in node @code{Sequences}
46796-- shell command @code{info -f gdb -n Sequences}.
46797@end ifset
46798@ifclear man
46799@ref{Sequences}.
46800@end ifclear
46801
46802Please read more in
46803@ifset man
46804the @value{GDBN} manual in node @code{Startup}
46805-- shell command @code{info -f gdb -n Startup}.
46806@end ifset
46807@ifclear man
46808@ref{Startup}.
46809@end ifclear
46810
46811@table @env
46812@ifset SYSTEM_GDBINIT
46813@item @value{SYSTEM_GDBINIT}
46814@end ifset
46815@ifclear SYSTEM_GDBINIT
46816@item (not enabled with @code{--with-system-gdbinit} during compilation)
46817@end ifclear
46818System-wide initialization file.  It is executed unless user specified
46819@value{GDBN} option @code{-nx} or @code{-n}.
46820See more in
46821@ifset man
46822the @value{GDBN} manual in node @code{System-wide configuration}
46823-- shell command @code{info -f gdb -n 'System-wide configuration'}.
46824@end ifset
46825@ifset SYSTEM_GDBINIT_DIR
46826@item @value{SYSTEM_GDBINIT_DIR}
46827@end ifset
46828@ifclear SYSTEM_GDBINIT_DIR
46829@item (not enabled with @code{--with-system-gdbinit-dir} during compilation)
46830@end ifclear
46831System-wide initialization directory.  All files in this directory are
46832executed on startup unless user specified @value{GDBN} option @code{-nx} or
46833@code{-n}, as long as they have a recognized file extension.
46834See more in
46835@ifset man
46836the @value{GDBN} manual in node @code{System-wide configuration}
46837-- shell command @code{info -f gdb -n 'System-wide configuration'}.
46838@end ifset
46839@ifclear man
46840@ref{System-wide configuration}.
46841@end ifclear
46842
46843@item ~/.gdbinit
46844User initialization file.  It is executed unless user specified
46845@value{GDBN} options @code{-nx}, @code{-n} or @code{-nh}.
46846
46847@item ./.gdbinit
46848Initialization file for current directory.  It may need to be enabled with
46849@value{GDBN} security command @code{set auto-load local-gdbinit}.
46850See more in
46851@ifset man
46852the @value{GDBN} manual in node @code{Init File in the Current Directory}
46853-- shell command @code{info -f gdb -n 'Init File in the Current Directory'}.
46854@end ifset
46855@ifclear man
46856@ref{Init File in the Current Directory}.
46857@end ifclear
46858@end table
46859@c man end
46860
46861@c man begin SEEALSO gdbinit
46862@ifset man
46863gdb(1), @code{info -f gdb -n Startup}
46864
46865The full documentation for @value{GDBN} is maintained as a Texinfo manual.
46866If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
46867documentation are properly installed at your site, the command
46868
46869@smallexample
46870info gdb
46871@end smallexample
46872
46873should give you access to the complete manual.
46874
46875@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46876Richard M. Stallman and Roland H. Pesch, July 1991.
46877@end ifset
46878@c man end
46879
46880@node gdb-add-index man
46881@heading gdb-add-index
46882@pindex gdb-add-index
46883@anchor{gdb-add-index}
46884
46885@c man title gdb-add-index Add index files to speed up GDB
46886
46887@c man begin SYNOPSIS gdb-add-index
46888gdb-add-index @var{filename}
46889@c man end
46890
46891@c man begin DESCRIPTION gdb-add-index
46892When @value{GDBN} finds a symbol file, it scans the symbols in the
46893file in order to construct an internal symbol table.  This lets most
46894@value{GDBN} operations work quickly--at the cost of a delay early on.
46895For large programs, this delay can be quite lengthy, so @value{GDBN}
46896provides a way to build an index, which speeds up startup.
46897
46898To determine whether a file contains such an index, use the command
46899@kbd{readelf -S filename}: the index is stored in a section named
46900@code{.gdb_index}.  The index file can only be produced on systems
46901which use ELF binaries and DWARF debug information (i.e., sections
46902named @code{.debug_*}).
46903
46904@command{gdb-add-index} uses @value{GDBN} and @command{objdump} found
46905in the @env{PATH} environment variable.  If you want to use different
46906versions of these programs, you can specify them through the
46907@env{GDB} and @env{OBJDUMP} environment variables.
46908
46909See more in
46910@ifset man
46911the @value{GDBN} manual in node @code{Index Files}
46912-- shell command @kbd{info -f gdb -n "Index Files"}.
46913@end ifset
46914@ifclear man
46915@ref{Index Files}.
46916@end ifclear
46917@c man end
46918
46919@c man begin SEEALSO gdb-add-index
46920@ifset man
46921The full documentation for @value{GDBN} is maintained as a Texinfo manual.
46922If the @code{info} and @code{gdb} programs and @value{GDBN}'s Texinfo
46923documentation are properly installed at your site, the command
46924
46925@smallexample
46926info gdb
46927@end smallexample
46928
46929should give you access to the complete manual.
46930
46931@cite{Using GDB: A Guide to the GNU Source-Level Debugger},
46932Richard M. Stallman and Roland H. Pesch, July 1991.
46933@end ifset
46934@c man end
46935
46936@include gpl.texi
46937
46938@node GNU Free Documentation License
46939@appendix GNU Free Documentation License
46940@include fdl.texi
46941
46942@node Concept Index
46943@unnumbered Concept Index
46944
46945@printindex cp
46946
46947@node Command and Variable Index
46948@unnumbered Command, Variable, and Function Index
46949
46950@printindex fn
46951
46952@tex
46953% I think something like @@colophon should be in texinfo.  In the
46954% meantime:
46955\long\def\colophon{\hbox to0pt{}\vfill
46956\centerline{The body of this manual is set in}
46957\centerline{\fontname\tenrm,}
46958\centerline{with headings in {\bf\fontname\tenbf}}
46959\centerline{and examples in {\tt\fontname\tentt}.}
46960\centerline{{\it\fontname\tenit\/},}
46961\centerline{{\bf\fontname\tenbf}, and}
46962\centerline{{\sl\fontname\tensl\/}}
46963\centerline{are used for emphasis.}\vfill}
46964\page\colophon
46965% Blame: doc@@cygnus.com, 1991.
46966@end tex
46967
46968@bye
46969